25
25
26
26
#include "hal/us_ticker_api.h"
27
27
#include "hal/lp_ticker_api.h"
28
+ #include "platform/mbed_wait_api.h"
28
29
29
30
#include <stdio.h>
30
31
31
32
#if DEVICE_SLEEP
32
33
33
34
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
34
35
static uint16_t deep_sleep_lock = 0U ;
36
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
35
37
static us_timestamp_t sleep_time = 0 ;
36
38
static us_timestamp_t deep_sleep_time = 0 ;
37
39
38
- #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
39
- static ticker_data_t * sleep_ticker = NULL ;
40
+ static const ticker_data_t * sleep_ticker = NULL ;
40
41
#endif
41
42
42
43
static inline us_timestamp_t read_us (void )
43
44
{
44
45
#if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
45
46
if (NULL == sleep_ticker ) {
46
- sleep_ticker = ( ticker_data_t * ) get_lp_ticker_data ();
47
+ sleep_ticker = get_lp_ticker_data ();
47
48
}
48
49
return ticker_read_us (sleep_ticker );
49
50
#else
@@ -53,7 +54,11 @@ static inline us_timestamp_t read_us(void)
53
54
54
55
us_timestamp_t mbed_time_idle (void )
55
56
{
57
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
56
58
return (sleep_time + deep_sleep_time );
59
+ #else
60
+ return 0 ;
61
+ #endif
57
62
}
58
63
59
64
us_timestamp_t mbed_uptime (void )
@@ -63,12 +68,20 @@ us_timestamp_t mbed_uptime(void)
63
68
64
69
us_timestamp_t mbed_time_sleep (void )
65
70
{
71
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
66
72
return sleep_time ;
73
+ #else
74
+ return 0 ;
75
+ #endif
67
76
}
68
77
69
78
us_timestamp_t mbed_time_deepsleep (void )
70
79
{
80
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
71
81
return deep_sleep_time ;
82
+ #else
83
+ return 0 ;
84
+ #endif
72
85
}
73
86
74
87
#ifdef MBED_SLEEP_TRACING_ENABLED
@@ -211,27 +224,33 @@ void sleep_manager_sleep_auto(void)
211
224
sleep_tracker_print_stats ();
212
225
#endif
213
226
core_util_critical_section_enter ();
227
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
214
228
us_timestamp_t start = read_us ();
215
229
bool deep = false;
230
+ #endif
216
231
217
232
// debug profile should keep debuggers attached, no deep sleep allowed
218
233
#ifdef MBED_DEBUG
219
234
hal_sleep ();
220
235
#else
221
236
if (sleep_manager_can_deep_sleep ()) {
237
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
222
238
deep = true;
239
+ #endif
223
240
hal_deepsleep ();
224
241
} else {
225
242
hal_sleep ();
226
243
}
227
244
#endif
228
245
246
+ #if defined(MBED_CPU_STATS_ENABLED ) && DEVICE_LPTICKER
229
247
us_timestamp_t end = read_us ();
230
248
if (true == deep ) {
231
249
deep_sleep_time += end - start ;
232
250
} else {
233
251
sleep_time += end - start ;
234
252
}
253
+ #endif
235
254
core_util_critical_section_exit ();
236
255
}
237
256
0 commit comments