Skip to content

Commit e88f431

Browse files
c1728p9Deepika
authored andcommitted
Add API to get idle time
Add the API to get time sleeping. This is in preparation for CPU usage support.
1 parent 8be2e34 commit e88f431

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

rtos/TARGET_CORTEX/mbed_rtx_idle.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ extern "C" {
3434

3535
using namespace mbed;
3636

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+
3745
#ifdef MBED_TICKLESS
3846

3947
#include "rtos/TARGET_CORTEX/SysTimer.h"
@@ -98,6 +106,7 @@ static void default_idle_hook(void)
98106
uint32_t ticks_to_sleep = osKernelSuspend();
99107
os_timer->suspend(ticks_to_sleep);
100108

109+
uint32_t start = ticker_read_us(cpu_usage_ticker);
101110
bool event_pending = false;
102111
while (!os_timer->suspend_time_passed() && !event_pending) {
103112

@@ -113,6 +122,8 @@ static void default_idle_hook(void)
113122
__ISB();
114123
}
115124
osKernelResume(os_timer->resume());
125+
uint32_t end = ticker_read_us(cpu_usage_ticker);
126+
idle_time += end - start;
116127
}
117128

118129
#elif defined(FEATURE_UVISOR)
@@ -129,9 +140,12 @@ static void default_idle_hook(void)
129140
{
130141
// critical section to complete sleep with locked deepsleep
131142
core_util_critical_section_enter();
143+
uint32_t start = ticker_read_us(cpu_usage_ticker);
132144
sleep_manager_lock_deep_sleep();
133145
sleep();
134146
sleep_manager_unlock_deep_sleep();
147+
uint32_t end = ticker_read_us(cpu_usage_ticker);
148+
idle_time += end - start;
135149
core_util_critical_section_exit();
136150
}
137151

0 commit comments

Comments
 (0)