Skip to content

Commit

Permalink
Merge pull request #8223 from c1728p9/deep_sleep_wakeup_fix
Browse files Browse the repository at this point in the history
Improve RTOS behavior with deep sleep
  • Loading branch information
Cruz Monrreal authored Oct 27, 2018
2 parents d23d785 + 50316d0 commit 4798a91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rtos/TARGET_CORTEX/mbed_rtx_idle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ uint32_t OS_Tick_GetInterval(void)
static void default_idle_hook(void)
{
uint32_t ticks_to_sleep = osKernelSuspend();
const bool block_deep_sleep = ticks_to_sleep <= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;

if (block_deep_sleep) {
sleep_manager_lock_deep_sleep();
} else {
ticks_to_sleep -= MBED_CONF_TARGET_DEEP_SLEEP_LATENCY;
}
os_timer->suspend(ticks_to_sleep);

bool event_pending = false;
Expand All @@ -109,6 +116,11 @@ static void default_idle_hook(void)
// Ensure interrupts get a chance to fire
__ISB();
}

if (block_deep_sleep) {
sleep_manager_unlock_deep_sleep();
}

osKernelResume(os_timer->resume());
}

Expand Down
4 changes: 4 additions & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"help": "Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH",
"value": null
},
"deep-sleep-latency": {
"help": "Time in ms required to go to and wake up from deep sleep (max 10)",
"value": 0
},
"boot-stack-size": {
"help": "Define the boot stack size in bytes. This value must be a multiple of 8",
"value": "0x1000"
Expand Down

0 comments on commit 4798a91

Please sign in to comment.