Skip to content

Commit d979c59

Browse files
committed
Make event queue use RTOS tick count
Event queue was using its own Timer or LowPowerTimer objects to derive millisecond tick counts. This is unnecessary in RTOS builds, where the RTOS is maintaining a tick count. It also makes more sense to use the actual RTOS tick count, as the values are being used to compute tick timeouts for RTOS calls. Computing these RTOS tick delays with a separate timer could conceivably lead to rounding errors. Fixes: #5378
1 parent 42d77ec commit d979c59

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

events/equeue/equeue_mbed.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
#include <stdbool.h>
2424
#include "mbed.h"
2525

26+
// Ticker operations
27+
#if MBED_CONF_RTOS_PRESENT
28+
29+
unsigned equeue_tick() {
30+
return osKernelGetTickCount();
31+
}
32+
33+
#else
34+
2635
#if MBED_CONF_EVENTS_USE_LOWPOWER_TIMER_TICKER
2736
#define ALIAS_TIMER LowPowerTimer
2837
#define ALIAS_TICKER LowPowerTicker
@@ -33,7 +42,6 @@
3342
#define ALIAS_TIMEOUT Timeout
3443
#endif
3544

36-
// Ticker operations
3745
static bool equeue_tick_inited = false;
3846
static volatile unsigned equeue_minutes = 0;
3947
static unsigned equeue_timer[
@@ -77,6 +85,7 @@ unsigned equeue_tick() {
7785
return minutes + ms;
7886
}
7987

88+
#endif
8089

8190
// Mutex operations
8291
int equeue_mutex_create(equeue_mutex_t *m) { return 0; }

events/mbed_lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"value": 256
2424
},
2525
"use-lowpower-timer-ticker": {
26-
"help": "Enable use of low power timer and ticker classes. May reduce the accuracy of the event queue.",
26+
"help": "Enable use of low power timer and ticker classes in non-RTOS builds. May reduce the accuracy of the event queue. In RTOS builds, the RTOS tick count is used, and this configuration option has no effect.",
2727
"value": 0
2828
}
2929
}

0 commit comments

Comments
 (0)