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,7 +102,7 @@ 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
@@ -108,15 +113,15 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
108
113
*
109
114
*/
110
115
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 ) {
113
118
sleep_manager_lock_deep_sleep ();
114
119
}
115
120
_function = func;
116
121
setup (t);
117
122
}
118
123
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
120
125
*
121
126
* @param obj pointer to the object to call the member function on
122
127
* @param method pointer to the member function to be called
@@ -148,6 +153,7 @@ class Ticker : public TimerEvent, private NonCopyable<Ticker> {
148
153
protected:
149
154
us_timestamp_t _delay; /* *< Time delay (in microseconds) for re-setting the multi-shot callback. */
150
155
Callback<void ()> _function; /* *< Callback. */
156
+ bool _lock_deepsleep; /* *< Flag which indicates if deep-sleep should be disabled. */
151
157
};
152
158
153
159
} // namespace mbed
0 commit comments