@@ -34,6 +34,14 @@ extern "C" {
34
34
35
35
using namespace mbed ;
36
36
37
+ static const ticker_data_t *const cpu_usage_ticker = get_lp_ticker_data();
38
+ static uint32_t idle_time = 0 ;
39
+
40
+ extern uint32_t mbed_time_idle (void )
41
+ {
42
+ return idle_time;
43
+ }
44
+
37
45
#ifdef MBED_TICKLESS
38
46
39
47
#include " rtos/TARGET_CORTEX/SysTimer.h"
@@ -98,6 +106,7 @@ static void default_idle_hook(void)
98
106
uint32_t ticks_to_sleep = osKernelSuspend ();
99
107
os_timer->suspend (ticks_to_sleep);
100
108
109
+ uint32_t start = ticker_read_us (cpu_usage_ticker);
101
110
bool event_pending = false ;
102
111
while (!os_timer->suspend_time_passed () && !event_pending) {
103
112
@@ -113,6 +122,8 @@ static void default_idle_hook(void)
113
122
__ISB ();
114
123
}
115
124
osKernelResume (os_timer->resume ());
125
+ uint32_t end = ticker_read_us (cpu_usage_ticker);
126
+ idle_time += end - start;
116
127
}
117
128
118
129
#elif defined(FEATURE_UVISOR)
@@ -129,9 +140,12 @@ static void default_idle_hook(void)
129
140
{
130
141
// critical section to complete sleep with locked deepsleep
131
142
core_util_critical_section_enter ();
143
+ uint32_t start = ticker_read_us (cpu_usage_ticker);
132
144
sleep_manager_lock_deep_sleep ();
133
145
sleep ();
134
146
sleep_manager_unlock_deep_sleep ();
147
+ uint32_t end = ticker_read_us (cpu_usage_ticker);
148
+ idle_time += end - start;
135
149
core_util_critical_section_exit ();
136
150
}
137
151
0 commit comments