Skip to content

Commit bb61b42

Browse files
Merge pull request ARMmbed#5148 from mprse/fix_enable_deepsleep_for_lp_timer
Enable deepsleep for LowPowerXXX objects
2 parents f7cca5b + 10ee2fa commit bb61b42

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

drivers/Ticker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ namespace mbed {
2525
void Ticker::detach() {
2626
core_util_critical_section_enter();
2727
remove();
28-
// unlocked only if we were attached (we locked it)
29-
if (_function) {
28+
// unlocked only if we were attached (we locked it) and this is not low power ticker
29+
if(_function && _lock_deepsleep) {
3030
sleep_manager_unlock_deep_sleep();
3131
}
32+
3233
_function = 0;
3334
core_util_critical_section_exit();
3435
}

drivers/Ticker.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
#include "platform/mbed_toolchain.h"
2222
#include "platform/NonCopyable.h"
2323
#include "platform/mbed_sleep.h"
24+
#include "hal/lp_ticker_api.h"
2425

2526
namespace mbed {
2627
/** \addtogroup drivers */
2728

2829
/** A Ticker is used to call a function at a recurring interval
2930
*
30-
* You can use as many seperate Ticker objects as you require.
31+
* You can use as many separate Ticker objects as you require.
3132
*
3233
* @note Synchronization level: Interrupt safe
3334
*
@@ -64,14 +65,18 @@ namespace mbed {
6465
class Ticker : public TimerEvent, private NonCopyable<Ticker> {
6566

6667
public:
67-
Ticker() : TimerEvent(), _function(0) {
68+
Ticker() : TimerEvent(), _function(0), _lock_deepsleep(true) {
6869
}
6970

70-
Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0) {
71+
// When low power ticker is in use, then do not disable deep-sleep.
72+
Ticker(const ticker_data_t *data) : TimerEvent(data), _function(0), _lock_deepsleep(true) {
7173
data->interface->init();
74+
#if DEVICE_LOWPOWERTIMER
75+
_lock_deepsleep = (data != get_lp_ticker_data());
76+
#endif
7277
}
7378

74-
/** Attach a function to be called by the Ticker, specifiying the interval in seconds
79+
/** Attach a function to be called by the Ticker, specifying the interval in seconds
7580
*
7681
* @param func pointer to the function to be called
7782
* @param t the time between calls in seconds
@@ -80,7 +85,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
8085
attach_us(func, t * 1000000.0f);
8186
}
8287

83-
/** Attach a member function to be called by the Ticker, specifiying the interval in seconds
88+
/** Attach a member function to be called by the Ticker, specifying the interval in seconds
8489
*
8590
* @param obj pointer to the object to call the member function on
8691
* @param method pointer to the member function to be called
@@ -97,7 +102,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
97102
attach(callback(obj, method), t);
98103
}
99104

100-
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
105+
/** Attach a function to be called by the Ticker, specifying the interval in micro-seconds
101106
*
102107
* @param func pointer to the function to be called
103108
* @param t the time between calls in micro-seconds
@@ -108,15 +113,15 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
108113
*
109114
*/
110115
void attach_us(Callback<void()> func, us_timestamp_t t) {
111-
// lock only for the initial callback setup
112-
if (!_function) {
116+
// lock only for the initial callback setup and this is not low power ticker
117+
if(!_function && _lock_deepsleep) {
113118
sleep_manager_lock_deep_sleep();
114119
}
115120
_function = func;
116121
setup(t);
117122
}
118123

119-
/** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
124+
/** Attach a member function to be called by the Ticker, specifying the interval in micro-seconds
120125
*
121126
* @param obj pointer to the object to call the member function on
122127
* @param method pointer to the member function to be called
@@ -148,6 +153,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
148153
protected:
149154
us_timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
150155
Callback<void()> _function; /**< Callback. */
156+
bool _lock_deepsleep; /**< Flag which indicates if deep-sleep should be disabled. */
151157
};
152158

153159
} // namespace mbed

drivers/Timer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@
1717
#include "hal/ticker_api.h"
1818
#include "hal/us_ticker_api.h"
1919
#include "platform/mbed_critical.h"
20+
#include "hal/lp_ticker_api.h"
2021

2122
namespace mbed {
2223

23-
Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()) {
24+
Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()), _lock_deepsleep(true) {
2425
reset();
2526
}
2627

27-
Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data) {
28+
Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data), _lock_deepsleep(true) {
2829
reset();
30+
#if DEVICE_LOWPOWERTIMER
31+
_lock_deepsleep = (data != get_lp_ticker_data());
32+
#endif
2933
}
3034

3135
Timer::~Timer() {
@@ -40,7 +44,9 @@ Timer::~Timer() {
4044
void Timer::start() {
4145
core_util_critical_section_enter();
4246
if (!_running) {
43-
sleep_manager_lock_deep_sleep();
47+
if(_lock_deepsleep) {
48+
sleep_manager_lock_deep_sleep();
49+
}
4450
_start = ticker_read_us(_ticker_data);
4551
_running = 1;
4652
}
@@ -51,7 +57,9 @@ void Timer::stop() {
5157
core_util_critical_section_enter();
5258
_time += slicetime();
5359
if (_running) {
54-
sleep_manager_unlock_deep_sleep();
60+
if(_lock_deepsleep) {
61+
sleep_manager_unlock_deep_sleep();
62+
}
5563
}
5664
_running = 0;
5765
core_util_critical_section_exit();

drivers/Timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Timer : private NonCopyable<Timer> {
101101
us_timestamp_t _start; // the start time of the latest slice
102102
us_timestamp_t _time; // any accumulated time from previous slices
103103
const ticker_data_t *_ticker_data;
104+
bool _lock_deepsleep; // flag which indicates if deep-sleep should be disabled
104105
};
105106

106107
} // namespace mbed

0 commit comments

Comments
 (0)