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.
This commit is contained in:
Tombula
2018-05-01 16:59:04 +02:00
committed by Mikael Falkvidd
parent 6c9be97fa3
commit 1c5853ce79
+17 -2
View File
@@ -141,8 +141,23 @@ void hwInternalSleep(uint32_t ms)
int8_t hwSleep(uint32_t ms)
{
hwInternalSleep(ms);
return MY_WAKE_UP_BY_TIMER;
// Return what woke the mcu.
// Default: no interrupt triggered, timer wake up
int8_t ret = MY_WAKE_UP_BY_TIMER;
if (ms > 0u) {
// sleep for defined time
hwInternalSleep(ms);
} else {
// sleep until ext interrupt triggered
hwPowerDown(WDTO_SLEEP_FOREVER);
}
if (interruptWakeUp()) {
ret = static_cast<int8_t>(_wokeUpByInterrupt);
}
// Clear woke-up-by-interrupt flag, so next sleeps won't return immediately.
_wokeUpByInterrupt = INVALID_INTERRUPT_NUM;
return ret;
}
int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms)