Partial revert of "[STM32Fxxx] Fix issue #816"

This is a partial revert of 07b841b and currently we are only reverting the
STM32F0xx family because new fix will be presented that's why we want to keep,
still the original solution only F1xx family (it will be fixed in future).

Change-Id: I147065299310c9fea499bf3ced8808a44699a1a1
pull/1913/head
Bartosz Szczepanski 2016-06-13 11:13:54 +02:00
parent 02bb0df4dc
commit 3222d07d35
1 changed files with 16 additions and 8 deletions

View File

@ -41,7 +41,6 @@ static int us_ticker_inited = 0;
volatile uint32_t SlaveCounter = 0;
volatile uint32_t oc_int_part = 0;
volatile uint16_t oc_rem_part = 0;
volatile uint16_t cnt_val = 0;
void set_compare(uint16_t count) {
TimMasterHandle.Instance = TIM_MST;
@ -59,15 +58,24 @@ void us_ticker_init(void) {
}
uint32_t us_ticker_read() {
uint32_t counter;
uint32_t counter, counter2;
if (!us_ticker_inited) us_ticker_init();
//Current value of TIM_MST->CNT is stored in cnt_val and is
//updated in interrupt context
// A situation might appear when Master overflows right after Slave is read and before the
// new (overflowed) value of Master is read. Which would make the code below consider the
// previous (incorrect) value of Slave and the new value of Master, which would return a
// value in the past. Avoid this by computing consecutive values of the timer until they
// are properly ordered.
counter = (uint32_t)(SlaveCounter << 16);
counter += cnt_val;
return counter;
counter += TIM_MST->CNT;
while (1) {
counter2 = (uint32_t)(SlaveCounter << 16);
counter2 += TIM_MST->CNT;
if (counter2 > counter) {
break;
}
counter = counter2;
}
return counter2;
}
void us_ticker_set_interrupt(timestamp_t timestamp) {