#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
+#include <avr/wdt.h>
#include "lights.h"
susp_buttons();
}
-void power_down()
+void power_down(unsigned char err)
{
hw_suspend();
do {
+ if (err)
+ gpio_set(0, 1);
+
// G'night
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
int main(void)
{
- init_log();
+ unsigned char mcusr_save;
+
+ // disable the WDT if running
+ wdt_reset();
+ mcusr_save = MCUSR;
+ MCUSR = 0;
+ wdt_disable();
+
+ if (mcusr_save & _BV(WDRF)) // was watchdog reset?
+ gpio_set(0, 1);
+
+ init_log(mcusr_save);
power_usi_disable(); // Once for lifetime
ACSRA |= _BV(ACD); // disable analog comparator
log_set_state(3);
hw_setup();
- power_down();
+ power_down(mcusr_save & _BV(WDRF));
sei();
#if 1