Skip to content

Commit

Permalink
Added support for low-power timers in mbed implementation
Browse files Browse the repository at this point in the history
Conditionally selected based on DEVICE_LOWPOWERTIMER
  • Loading branch information
geky committed Aug 6, 2016
1 parent 65d27b2 commit 1b1ed81
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions equeue_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@

#include <stdbool.h>
#include "mbed.h"
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos.h"
#endif


// Ticker operations
static class GlobalTicker {
class EqueueTicker {
public:
GlobalTicker() {
EqueueTicker() {
_tick = 0;
_timer.start();
_ticker.attach_us(this, &GlobalTicker::step, (1 << 16) * 1000);
_ticker.attach_us(this, &EqueueTicker::update, (1 << 16) * 1000);
};

void step() {
void update() {
_timer.reset();
_tick += 1 << 16;
}
Expand All @@ -38,12 +35,19 @@ static class GlobalTicker {

private:
unsigned _tick;
#ifdef DEVICE_LOWPOWERTIMER
LowPowerTimer _timer;
LowPowerTicker _ticker;
#else
Timer _timer;
Ticker _ticker;
} gticker;
#endif
};

static EqueueTicker equeue_ticker;

unsigned equeue_tick() {
return gticker.tick();
return equeue_ticker.tick();
}


Expand Down

0 comments on commit 1b1ed81

Please sign in to comment.