Timer 16bit: Remove volatile variables. This solved many fails with MBED_24 test.

pull/3213/head
bcostm 2016-11-04 13:48:18 +01:00
parent f8e18cdde4
commit 777692cc16
1 changed files with 4 additions and 8 deletions

View File

@ -67,10 +67,8 @@ uint32_t us_ticker_read() {
if (!us_ticker_inited) us_ticker_init();
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
#if defined(TARGET_STM32L0)
volatile uint16_t cntH_old, cntH, cntL;
uint16_t cntH_old, cntH, cntL;
do {
// For some reason on L0xx series we need to read and clear the
// overflow flag which give extra time to propelry handle possible
@ -83,25 +81,23 @@ uint32_t us_ticker_read() {
cntH_old += 1;
}
cntL = TIM_MST->CNT;
cntH = SlaveCounter;
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
cntH += 1;
}
} while(cntH_old != cntH);
// Glue the upper and lower part together to get a 32 bit timer
counter = (uint32_t)(cntH << 16 | cntL);
return (uint32_t)(cntH << 16 | cntL);
#else
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp
#endif
if (tim_it_update == 1) {
return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler()
}
else {
return counter; // Otherwise return the time stamp calculated here
}
#endif
}
void us_ticker_set_interrupt(timestamp_t timestamp) {