Skip to content

Timer: remove hard-coded lp_ticker knowledge #10150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions drivers/Ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
}

// When low power ticker is in use, then do not disable deep sleep.
Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0), _lock_deepsleep(true)
Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0), _lock_deepsleep(!data->interface->runs_in_deep_sleep)
{
#if DEVICE_LPTICKER
_lock_deepsleep = (data != get_lp_ticker_data());
#endif
}

/** Attach a function to be called by the Ticker, specifying the interval in seconds
Expand Down
7 changes: 2 additions & 5 deletions drivers/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "hal/ticker_api.h"
#include "hal/us_ticker_api.h"
#include "platform/mbed_critical.h"
#include "hal/lp_ticker_api.h"

namespace mbed {

Expand All @@ -27,12 +26,10 @@ Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data(
reset();
}

Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data), _lock_deepsleep(true)
Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data),
_lock_deepsleep(!data->interface->runs_in_deep_sleep)
{
reset();
#if DEVICE_LPTICKER
_lock_deepsleep = (data != get_lp_ticker_data());
#endif
}

Timer::~Timer()
Expand Down
1 change: 1 addition & 0 deletions hal/mbed_lp_ticker_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static const ticker_interface_t lp_interface = {
.fire_interrupt = lp_ticker_fire_interrupt,
.get_info = lp_ticker_get_info,
.free = lp_ticker_free,
.runs_in_deep_sleep = true,
};

static const ticker_data_t lp_data = {
Expand Down
3 changes: 2 additions & 1 deletion hal/mbed_lp_ticker_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static const ticker_interface_t lp_interface = {
lp_ticker_wrapper_set_interrupt,
lp_ticker_wrapper_fire_interrupt,
lp_ticker_wrapper_free,
lp_ticker_wrapper_get_info
lp_ticker_wrapper_get_info,
true
};

void lp_ticker_wrapper_irq_handler(ticker_irq_handler_type handler)
Expand Down
1 change: 1 addition & 0 deletions hal/mbed_us_ticker_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const ticker_interface_t us_interface = {
.fire_interrupt = us_ticker_fire_interrupt,
.get_info = us_ticker_get_info,
.free = us_ticker_free,
.runs_in_deep_sleep = false,
};

static const ticker_data_t us_data = {
Expand Down
1 change: 1 addition & 0 deletions hal/ticker_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct {
void (*fire_interrupt)(void); /**< Fire interrupt right-away */
void (*free)(void); /**< Disable function */
const ticker_info_t *(*get_info)(void); /**< Return info about this ticker's implementation */
bool runs_in_deep_sleep; /**< Whether ticker operates in deep sleep */
} ticker_interface_t;

/** Ticker's event queue structure
Expand Down