Skip to content

Commit 50316d0

Browse files
committed
Improve RTOS behavior with deep sleep
Only deep sleep when the wakeup time is more than MBED_CONF_TARGET_DEEP_SLEEP_LATENCY ms in the future. This ensures that RTOS events are handled at the correct time. Note - when deep sleep is allow interrupt latency may still be as high as 10ms.
1 parent b18c819 commit 50316d0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

rtos/TARGET_CORTEX/mbed_rtx_idle.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ uint32_t OS_Tick_GetInterval (void) {
9090
static void default_idle_hook(void)
9191
{
9292
uint32_t ticks_to_sleep = osKernelSuspend();
93+
const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
94+
95+
if (block_deep_sleep) {
96+
sleep_manager_lock_deep_sleep();
97+
} else {
98+
ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
99+
}
93100
os_timer->suspend(ticks_to_sleep);
94101

95102
bool event_pending = false;
@@ -106,6 +113,11 @@ static void default_idle_hook(void)
106113
// Ensure interrupts get a chance to fire
107114
__ISB();
108115
}
116+
117+
if (block_deep_sleep) {
118+
sleep_manager_unlock_deep_sleep();
119+
}
120+
109121
osKernelResume(os_timer->resume());
110122
}
111123

targets/targets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
"help": "Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH",
2222
"value": null
2323
},
24+
"deep-sleep-latency": {
25+
"help": "Time in ms required to go to and wake up from deep sleep (max 10)",
26+
"value": 0
27+
},
2428
"boot-stack-size": {
2529
"help": "Define the boot stack size in bytes. This value must be a multiple of 8",
2630
"value": "0x1000"

0 commit comments

Comments
 (0)