Skip to content

Commit 4798a91

Browse files
author
Cruz Monrreal
authored
Merge pull request #8223 from c1728p9/deep_sleep_wakeup_fix
Improve RTOS behavior with deep sleep
2 parents d23d785 + 50316d0 commit 4798a91

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
@@ -93,6 +93,13 @@ uint32_t OS_Tick_GetInterval(void)
9393
static void default_idle_hook(void)
9494
{
9595
uint32_t ticks_to_sleep = osKernelSuspend();
96+
const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
97+
98+
if (block_deep_sleep) {
99+
sleep_manager_lock_deep_sleep();
100+
} else {
101+
ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
102+
}
96103
os_timer->suspend(ticks_to_sleep);
97104

98105
bool event_pending = false;
@@ -109,6 +116,11 @@ static void default_idle_hook(void)
109116
// Ensure interrupts get a chance to fire
110117
__ISB();
111118
}
119+
120+
if (block_deep_sleep) {
121+
sleep_manager_unlock_deep_sleep();
122+
}
123+
112124
osKernelResume(os_timer->resume());
113125
}
114126

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)