Skip to content

Commit d0b5ba6

Browse files
authored
Merge pull request #11522 from LMESTM/SysTtimer_Should_Let_DeepSleep_Happen
Sys timer should let deep sleep happen
2 parents 11a34ec + 9858b16 commit d0b5ba6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

platform/source/SysTimer.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,21 @@ void SysTimer<US_IN_TICK, IRQ>::set_wake_time(uint64_t at)
114114
_deep_sleep_locked = true;
115115
sleep_manager_lock_deep_sleep();
116116
}
117-
118-
/* If deep sleep is unlocked, and we have enough time, let's go for it */
117+
/* Consider whether we will need early or precise wake-up */
119118
if (MBED_CONF_TARGET_DEEP_SLEEP_LATENCY > 0 &&
120119
ticks_to_sleep > MBED_CONF_TARGET_DEEP_SLEEP_LATENCY &&
121-
sleep_manager_can_deep_sleep()) {
122-
/* Schedule the wake up interrupt early, allowing for the deep sleep latency */
120+
!_deep_sleep_locked) {
121+
/* If there is deep sleep latency, but we still have enough time,
122+
* and we haven't blocked deep sleep ourselves,
123+
* allow for that latency by requesting early wake-up.
124+
* Actual sleep may or may not be deep, depending on other actors.
125+
*/
123126
_wake_early = true;
124127
insert_absolute(wake_time - MBED_CONF_TARGET_DEEP_SLEEP_LATENCY * US_IN_TICK);
125128
} else {
126-
/* Otherwise, we'll set up for shallow sleep at the precise time.
127-
* To make absolutely sure it's shallow so we don't incur the latency,
128-
* take our own lock, to avoid a race on a thread unlocking it.
129+
/* Otherwise, set up to wake at the precise time.
130+
* If there is a deep sleep latency, ensure that we're holding the lock so the sleep
131+
* is shallow. (If there is no deep sleep latency, we're fine with it being deep).
129132
*/
130133
_wake_early = false;
131134
if (MBED_CONF_TARGET_DEEP_SLEEP_LATENCY > 0 && !_deep_sleep_locked) {

0 commit comments

Comments
 (0)