ST / ST_Events-old

Dependents:   HelloWorld_CCA01M1 HelloWorld_CCA02M1 CI-data-logger-server HelloWorld_CCA02M1 ... more

This is a fork of the events subdirectory of https://github.com/ARMmbed/mbed-os.

Note, you must import this library with import name: events!!!

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Wed Feb 15 10:04:11 2017 -0600
Parent:
13:93ea03db7d46
Child:
17:26f21b1871a7
Commit message:
events: Added better handling of desynchronized timers in platform layer

An odd bug (c0951c9) in the NCS36510 ticker code caused the timer/ticker
classes to become desynchronized. Updated the handling to not assume the
timers are perfectly in synch. This will increase the event's tolerance of
less robust platforms.

Changed in this revision

equeue/equeue_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/equeue/equeue_mbed.cpp	Mon Jan 09 19:28:33 2017 -0600
+++ b/equeue/equeue_mbed.cpp	Wed Feb 15 10:04:11 2017 -0600
@@ -26,15 +26,15 @@
 
 // Ticker operations
 static bool equeue_tick_inited = false;
-static unsigned equeue_minutes = 0;
+static volatile unsigned equeue_minutes = 0;
 static unsigned equeue_timer[
         (sizeof(Timer)+sizeof(unsigned)-1)/sizeof(unsigned)];
 static unsigned equeue_ticker[
         (sizeof(Ticker)+sizeof(unsigned)-1)/sizeof(unsigned)];
 
 static void equeue_tick_update() {
+    equeue_minutes += reinterpret_cast<Timer*>(equeue_timer)->read_ms();
     reinterpret_cast<Timer*>(equeue_timer)->reset();
-    equeue_minutes += 1;
 }
 
 static void equeue_tick_init() {
@@ -48,7 +48,7 @@
     equeue_minutes = 0;
     reinterpret_cast<Timer*>(equeue_timer)->start();
     reinterpret_cast<Ticker*>(equeue_ticker)
-            ->attach_us(equeue_tick_update, (1 << 16)*1000);
+            ->attach_us(equeue_tick_update, 1000 << 16);
 
     equeue_tick_inited = true;
 }
@@ -58,8 +58,15 @@
         equeue_tick_init();
     }
 
-    unsigned equeue_ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
-    return (equeue_minutes << 16) + equeue_ms;
+    unsigned minutes;
+    unsigned ms;
+
+    do {
+        minutes = equeue_minutes;
+        ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
+    } while (minutes != equeue_minutes);
+
+    return minutes + ms;
 }