microbit: Patch to HF Ticker implementaiton to reduce glitching on wait_ms()

Updated ticker implementation to:

 - Ensure initialisation of overflowount variable to zero (was previously undefined)

  - Update internal counter 'read' operation to handle overflow conditions
differently. Instead of re-implementing the overflow handler in the 'read'
operation, it now leaves this to a single code path in the ISR. Instead, the
code is simply made aware of overflows and handles this as a local event. This
prevents the possibility of duplicate increments to overflowCount (which
appeared to occur under testing, especially when the mbed wait_ms busy-wait function is used).
This commit is contained in:
Joe Finney 2016-04-07 10:30:48 +01:00
parent 4618870501
commit 1a8031daf8
1 changed files with 6 additions and 6 deletions

View File

@ -47,7 +47,7 @@
#define MICROSECONDS_TO_TMR1_UNITS(MICROS) MICROS
static bool us_ticker_inited = false;
static volatile uint32_t overflowCount; /**< The number of times the 24-bit TMR1 counter has overflowed. */
static volatile uint32_t overflowCount = 0; /**< The number of times the 24-bit TMR1 counter has overflowed. */
static volatile bool us_ticker_callbackPending = false;
static uint32_t us_ticker_callbackTimestamp;
@ -141,14 +141,14 @@ void tmr1_stop(void)
*/
static inline uint64_t tmr1_getCounter64(void)
{
if (NRF_TIMER1->EVENTS_COMPARE[3]) {
overflowCount++;
NRF_TIMER1->EVENTS_COMPARE[3] = 0;
}
int o = 0;
NRF_TIMER1->TASKS_CAPTURE[2] = 1;
return ((uint64_t)overflowCount << 16) | (NRF_TIMER1->CC[2] & MAX_TMR1_COUNTER_VAL);
if (NRF_TIMER1->EVENTS_COMPARE[3])
o++;
return (((uint64_t)(overflowCount+o)) << 16) | (NRF_TIMER1->CC[2] & MAX_TMR1_COUNTER_VAL);
}
/**