Skip to content

Commit 28b7705

Browse files
committed
CPU stats: strip more when disabled
1 parent 2d6db33 commit 28b7705

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

platform/mbed_sleep_manager.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,26 @@
2525

2626
#include "hal/us_ticker_api.h"
2727
#include "hal/lp_ticker_api.h"
28+
#include "platform/mbed_wait_api.h"
2829

2930
#include <stdio.h>
3031

3132
#if DEVICE_SLEEP
3233

3334
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
3435
static uint16_t deep_sleep_lock = 0U;
36+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
3537
static us_timestamp_t sleep_time = 0;
3638
static us_timestamp_t deep_sleep_time = 0;
3739

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;
4041
#endif
4142

4243
static inline us_timestamp_t read_us(void)
4344
{
4445
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
4546
if (NULL == sleep_ticker) {
46-
sleep_ticker = (ticker_data_t *)get_lp_ticker_data();
47+
sleep_ticker = get_lp_ticker_data();
4748
}
4849
return ticker_read_us(sleep_ticker);
4950
#else
@@ -53,7 +54,11 @@ static inline us_timestamp_t read_us(void)
5354

5455
us_timestamp_t mbed_time_idle(void)
5556
{
57+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
5658
return (sleep_time + deep_sleep_time);
59+
#else
60+
return 0;
61+
#endif
5762
}
5863

5964
us_timestamp_t mbed_uptime(void)
@@ -63,12 +68,20 @@ us_timestamp_t mbed_uptime(void)
6368

6469
us_timestamp_t mbed_time_sleep(void)
6570
{
71+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
6672
return sleep_time;
73+
#else
74+
return 0;
75+
#endif
6776
}
6877

6978
us_timestamp_t mbed_time_deepsleep(void)
7079
{
80+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
7181
return deep_sleep_time;
82+
#else
83+
return 0;
84+
#endif
7285
}
7386

7487
#ifdef MBED_SLEEP_TRACING_ENABLED
@@ -211,27 +224,33 @@ void sleep_manager_sleep_auto(void)
211224
sleep_tracker_print_stats();
212225
#endif
213226
core_util_critical_section_enter();
227+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
214228
us_timestamp_t start = read_us();
215229
bool deep = false;
230+
#endif
216231

217232
// debug profile should keep debuggers attached, no deep sleep allowed
218233
#ifdef MBED_DEBUG
219234
hal_sleep();
220235
#else
221236
if (sleep_manager_can_deep_sleep()) {
237+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
222238
deep = true;
239+
#endif
223240
hal_deepsleep();
224241
} else {
225242
hal_sleep();
226243
}
227244
#endif
228245

246+
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
229247
us_timestamp_t end = read_us();
230248
if (true == deep) {
231249
deep_sleep_time += end - start;
232250
} else {
233251
sleep_time += end - start;
234252
}
253+
#endif
235254
core_util_critical_section_exit();
236255
}
237256

0 commit comments

Comments
 (0)