Skip to content

Commit eacc276

Browse files
committed
equeue: added config option which tells equeue_mbed.cpp if it shall use LowPowerTimer, LowPowerTimeout and LowPowerTicker instead of Timer/Timeout/Ticker.
This way, on SiLabs boards the low power sleep states will be used when using event queue.
1 parent 20d93bf commit eacc276

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

events/equeue/equeue_mbed.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,36 @@
2323
#include <stdbool.h>
2424
#include "mbed.h"
2525

26+
#if MBED_CONF_EVENTS_USE_LOWPOWER_TIMER_TICKER
27+
#define AliasTimer LowPowerTimer
28+
#define AliasTicker LowPowerTicker
29+
#define AliasTimeout LowPowerTimeout
30+
#else
31+
#define AliasTimer Timer
32+
#define AliasTicker Ticker
33+
#define AliasTimeout Timeout
34+
#endif
2635

2736
// Ticker operations
2837
static bool equeue_tick_inited = false;
2938
static volatile unsigned equeue_minutes = 0;
3039
static unsigned equeue_timer[
31-
(sizeof(Timer)+sizeof(unsigned)-1)/sizeof(unsigned)];
40+
(sizeof(AliasTimer)+sizeof(unsigned)-1)/sizeof(unsigned)];
3241
static unsigned equeue_ticker[
33-
(sizeof(Ticker)+sizeof(unsigned)-1)/sizeof(unsigned)];
42+
(sizeof(AliasTicker)+sizeof(unsigned)-1)/sizeof(unsigned)];
3443

3544
static void equeue_tick_update() {
36-
equeue_minutes += reinterpret_cast<Timer*>(equeue_timer)->read_ms();
37-
reinterpret_cast<Timer*>(equeue_timer)->reset();
45+
equeue_minutes += reinterpret_cast<AliasTimer*>(equeue_timer)->read_ms();
46+
reinterpret_cast<AliasTimer*>(equeue_timer)->reset();
3847
}
3948

4049
static void equeue_tick_init() {
41-
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(Timer),
50+
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(AliasTimer),
4251
"The equeue_timer buffer must fit the class Timer");
43-
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker),
52+
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(AliasTicker),
4453
"The equeue_ticker buffer must fit the class Ticker");
45-
Timer *timer = new (equeue_timer) Timer;
46-
Ticker *ticker = new (equeue_ticker) Ticker;
54+
AliasTimer *timer = new (equeue_timer) AliasTimer;
55+
AliasTicker *ticker = new (equeue_ticker) AliasTicker;
4756

4857
equeue_minutes = 0;
4958
timer->start();
@@ -62,7 +71,7 @@ unsigned equeue_tick() {
6271

6372
do {
6473
minutes = equeue_minutes;
65-
ms = reinterpret_cast<Timer*>(equeue_timer)->read_ms();
74+
ms = reinterpret_cast<AliasTimer*>(equeue_timer)->read_ms();
6675
} while (minutes != equeue_minutes);
6776

6877
return minutes + ms;
@@ -132,7 +141,7 @@ static void equeue_sema_timeout(equeue_sema_t *s) {
132141

133142
bool equeue_sema_wait(equeue_sema_t *s, int ms) {
134143
int signal = 0;
135-
Timeout timeout;
144+
AliasTimeout timeout;
136145
if (ms == 0) {
137146
return false;
138147
} else if (ms > 0) {

events/mbed_lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"shared-highprio-eventsize": {
2222
"help": "Event buffer size (bytes) for shared high-priority event queue",
2323
"value": 256
24-
}
24+
},
25+
"use-lowpower-timer-ticker": 0
2526
}
2627
}

0 commit comments

Comments
 (0)