Lancaster University's (short term!) clone of mbed-src for micro:bit. This is a copy of the github branch https://github.com/lancaster-university/mbed-classic

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Fri Apr 08 01:05:59 2016 +0100
Parent:
638:976bf2debae2
Child:
640:0bc7942c2877
Commit message:
Synchronized with git rev 1a8031da
Author: Joe Finney
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).

Changed in this revision

targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c	Thu Apr 07 01:03:23 2016 +0100
+++ b/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/us_ticker.c	Fri Apr 08 01:05:59 2016 +0100
@@ -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 @@
  */
 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);
 }
 
 /**