Skip to content

Commit 1c5853c

Browse files
Tombulamfalkvidd
authored andcommitted
Add sleep forever by sleep(0); (#1113)
For battery powered sensors which wake up by the RST Pin its useful to sleep the cpu forever. When using this command: sleep(INTERRUPT_NOT_DEFINED, MODE_NOT_DEFINED, 0, false); the code will be stripped down to hwSleep(0);. But this will not sleep the cpu forever.
1 parent 6c9be97 commit 1c5853c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

hal/architecture/AVR/MyHwAVR.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,23 @@ void hwInternalSleep(uint32_t ms)
141141

142142
int8_t hwSleep(uint32_t ms)
143143
{
144-
hwInternalSleep(ms);
145-
return MY_WAKE_UP_BY_TIMER;
144+
// Return what woke the mcu.
145+
// Default: no interrupt triggered, timer wake up
146+
int8_t ret = MY_WAKE_UP_BY_TIMER;
147+
if (ms > 0u) {
148+
// sleep for defined time
149+
hwInternalSleep(ms);
150+
} else {
151+
// sleep until ext interrupt triggered
152+
hwPowerDown(WDTO_SLEEP_FOREVER);
153+
}
154+
if (interruptWakeUp()) {
155+
ret = static_cast<int8_t>(_wokeUpByInterrupt);
156+
}
157+
// Clear woke-up-by-interrupt flag, so next sleeps won't return immediately.
158+
_wokeUpByInterrupt = INVALID_INTERRUPT_NUM;
159+
160+
return ret;
146161
}
147162

148163
int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms)

0 commit comments

Comments
 (0)