21
21
#include " platform/mbed_toolchain.h"
22
22
#include " platform/NonCopyable.h"
23
23
#include " platform/mbed_sleep.h"
24
+ #include " hal/lp_ticker_api.h"
24
25
25
26
namespace mbed {
26
27
/* * \addtogroup drivers */
27
28
28
29
/* * A Ticker is used to call a function at a recurring interval
29
30
*
30
- * You can use as many seperate Ticker objects as you require.
31
+ * You can use as many separate Ticker objects as you require.
31
32
*
32
33
* @note Synchronization level: Interrupt safe
33
34
*
@@ -64,14 +65,18 @@ namespace mbed {
64
65
class Ticker : public TimerEvent , private NonCopyable <Ticker> {
65
66
66
67
public:
67
- Ticker () : TimerEvent(), _function(0 ) {
68
+ Ticker () : TimerEvent(), _function(0 ), _lock_deepsleep( true ) {
68
69
}
69
70
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 ) {
71
73
data->interface ->init ();
74
+ #if DEVICE_LOWPOWERTIMER
75
+ _lock_deepsleep = (data != get_lp_ticker_data ());
76
+ #endif
72
77
}
73
78
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
75
80
*
76
81
* @param func pointer to the function to be called
77
82
* @param t the time between calls in seconds
@@ -80,7 +85,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
80
85
attach_us (func, t * 1000000 .0f );
81
86
}
82
87
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
84
89
*
85
90
* @param obj pointer to the object to call the member function on
86
91
* @param method pointer to the member function to be called
@@ -97,21 +102,21 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
97
102
attach (callback (obj, method), t);
98
103
}
99
104
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
101
106
*
102
107
* @param func pointer to the function to be called
103
108
* @param t the time between calls in micro-seconds
104
109
*/
105
110
void attach_us (Callback<void ()> func, us_timestamp_t t) {
106
- // lock only for the initial callback setup
107
- if (!_function) {
111
+ // lock only for the initial callback setup and this is not low power ticker
112
+ if (!_function && _lock_deepsleep ) {
108
113
sleep_manager_lock_deep_sleep ();
109
114
}
110
115
_function = func;
111
116
setup (t);
112
117
}
113
118
114
- /* * Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
119
+ /* * Attach a member function to be called by the Ticker, specifying the interval in micro-seconds
115
120
*
116
121
* @param obj pointer to the object to call the member function on
117
122
* @param method pointer to the member function to be called
@@ -143,6 +148,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
143
148
protected:
144
149
us_timestamp_t _delay; /* *< Time delay (in microseconds) for re-setting the multi-shot callback. */
145
150
Callback<void ()> _function; /* *< Callback. */
151
+ bool _lock_deepsleep; /* *< Flag which indicates if deep-sleep should be disabled. */
146
152
};
147
153
148
154
} // namespace mbed
0 commit comments