can have unexpected wake (depending on how app is coded), so in case of using SLEEP_FOREVER parameter calling powerDown() the function should disable the watchdog (just in case, and it does not hurt because this is exactly what we want to do)
if (period == SLEEP_FOREVER)
{
// we don't want to be waked by the watchdog, so be
// sure to disable it by changing the config
// This has been tried and works
WDTCSR = _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
// but may be just following also
// wdt_disable();
}
else
{
wdt_enable(period);
WDTCSR |= (1 << WDIE);
}
If for any reason (for example the application start/stop playing with watchdog while not in sleep mode) then a call to
can have unexpected wake (depending on how app is coded), so in case of using
SLEEP_FOREVER
parameter callingpowerDown()
the function should disable the watchdog (just in case, and it does not hurt because this is exactly what we want to do)should becomes something like that