Mbed for VNG board

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Dec 09 14:45:08 2014 +0000
Revision:
431:255afbe6270c
Parent:
340:28d1f895c6fe
Synchronized with git revision ea49132428ba76f828a3398a05088186c036de90

Full URL: https://github.com/mbedmicro/mbed/commit/ea49132428ba76f828a3398a05088186c036de90/

Fix IAR serial fgets fgetc

Taken from PR #770:
setbuf(_file, NULL), and std::setvbuf(_file,NULL,_IONBF,NULL) should both give an unbuffered stream (the data is directly written to the input buffer). IAR sets a buffer anyway of size 512 bytes for these calls. Calling setvbuff(_file,buf,_IONBF,NULL) with a buffer that is not a NULL pointer sets the buffer to size one. Which means that as soon as a char is read it is written to the real buffer. If people are interested in looking at this further they can look at the files under ARM/src/dlib: fgets.c, fflush.c, xfrpep.c and xfwprep.c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 340:28d1f895c6fe 1 /* mbed Microcontroller Library
mbed_official 340:28d1f895c6fe 2 * Copyright (c) 2014, STMicroelectronics
mbed_official 340:28d1f895c6fe 3 * All rights reserved.
mbed_official 340:28d1f895c6fe 4 *
mbed_official 340:28d1f895c6fe 5 * Redistribution and use in source and binary forms, with or without
mbed_official 340:28d1f895c6fe 6 * modification, are permitted provided that the following conditions are met:
mbed_official 340:28d1f895c6fe 7 *
mbed_official 340:28d1f895c6fe 8 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 340:28d1f895c6fe 9 * this list of conditions and the following disclaimer.
mbed_official 340:28d1f895c6fe 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 340:28d1f895c6fe 11 * this list of conditions and the following disclaimer in the documentation
mbed_official 340:28d1f895c6fe 12 * and/or other materials provided with the distribution.
mbed_official 340:28d1f895c6fe 13 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 340:28d1f895c6fe 14 * may be used to endorse or promote products derived from this software
mbed_official 340:28d1f895c6fe 15 * without specific prior written permission.
mbed_official 340:28d1f895c6fe 16 *
mbed_official 340:28d1f895c6fe 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 340:28d1f895c6fe 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 340:28d1f895c6fe 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 340:28d1f895c6fe 20 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 340:28d1f895c6fe 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 340:28d1f895c6fe 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 340:28d1f895c6fe 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 340:28d1f895c6fe 24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 340:28d1f895c6fe 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 340:28d1f895c6fe 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 340:28d1f895c6fe 27 */
mbed_official 340:28d1f895c6fe 28 #include <stddef.h>
mbed_official 340:28d1f895c6fe 29 #include "us_ticker_api.h"
mbed_official 340:28d1f895c6fe 30 #include "PeripheralNames.h"
mbed_official 340:28d1f895c6fe 31
mbed_official 340:28d1f895c6fe 32 // 32-bit timer selection
mbed_official 431:255afbe6270c 33 #define TIM_MST TIM2
mbed_official 340:28d1f895c6fe 34
mbed_official 340:28d1f895c6fe 35 static TIM_HandleTypeDef TimMasterHandle;
mbed_official 340:28d1f895c6fe 36 static int us_ticker_inited = 0;
mbed_official 340:28d1f895c6fe 37
mbed_official 340:28d1f895c6fe 38 void us_ticker_init(void)
mbed_official 340:28d1f895c6fe 39 {
mbed_official 340:28d1f895c6fe 40 if (us_ticker_inited) return;
mbed_official 340:28d1f895c6fe 41 us_ticker_inited = 1;
mbed_official 340:28d1f895c6fe 42
mbed_official 431:255afbe6270c 43 TimMasterHandle.Instance = TIM_MST;
mbed_official 340:28d1f895c6fe 44
mbed_official 431:255afbe6270c 45 HAL_InitTick(0); // The passed value is not used
mbed_official 340:28d1f895c6fe 46 }
mbed_official 340:28d1f895c6fe 47
mbed_official 340:28d1f895c6fe 48 uint32_t us_ticker_read()
mbed_official 340:28d1f895c6fe 49 {
mbed_official 340:28d1f895c6fe 50 if (!us_ticker_inited) us_ticker_init();
mbed_official 340:28d1f895c6fe 51 return TIM_MST->CNT;
mbed_official 340:28d1f895c6fe 52 }
mbed_official 340:28d1f895c6fe 53
mbed_official 340:28d1f895c6fe 54 void us_ticker_set_interrupt(timestamp_t timestamp)
mbed_official 340:28d1f895c6fe 55 {
mbed_official 340:28d1f895c6fe 56 // Set new output compare value
mbed_official 340:28d1f895c6fe 57 __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
mbed_official 340:28d1f895c6fe 58 // Enable IT
mbed_official 340:28d1f895c6fe 59 __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 340:28d1f895c6fe 60 }
mbed_official 340:28d1f895c6fe 61
mbed_official 340:28d1f895c6fe 62 void us_ticker_disable_interrupt(void)
mbed_official 340:28d1f895c6fe 63 {
mbed_official 340:28d1f895c6fe 64 __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 340:28d1f895c6fe 65 }
mbed_official 340:28d1f895c6fe 66
mbed_official 340:28d1f895c6fe 67 void us_ticker_clear_interrupt(void)
mbed_official 340:28d1f895c6fe 68 {
mbed_official 340:28d1f895c6fe 69 __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
mbed_official 340:28d1f895c6fe 70 }