src-avr: Trap accidental restart
authorKeith Packard <keithp@keithp.com>
Wed, 18 May 2011 07:17:04 +0000 (00:17 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 18 May 2011 07:17:04 +0000 (00:17 -0700)
Use the LED output pin to notice when avr-demo accidentally restarts
and print out an error message in that case.

Signed-off-by: Keith Packard <keithp@keithp.com>
src-avr/ao_demo.c
src-avr/ao_led.c

index cb7ad7864bd5a1fa0497775b6231b2e4f4389952..d905cec6cec3e212dd150b841d11425541ee8ded 100644 (file)
@@ -35,10 +35,11 @@ main(void)
        ao_clock_init();
 
        ao_serial_init();
+
+       ao_led_init(LEDS_AVAILABLE);
        ao_stdio_init();
        printf ("stdio initialized\n");
 //     ao_debug_init();
-       ao_led_init(LEDS_AVAILABLE);
        ao_timer_init();
        ao_cmd_init();
        ao_usb_init();
index 0e69ee3a2c222c2f508fa9e8b6784e53954ec8d6..5183140b252110fa53e9d0ca279acdf5a16d1879 100644 (file)
@@ -63,6 +63,10 @@ ao_led_init(uint8_t enable)
 {
        ao_led_enable = enable;
 #ifdef AVR
+       if ((LED_DDR & enable)) {
+               printf ("oops! restarted\n");
+               ao_panic(AO_PANIC_REBOOT);
+       }
        LED_PORT &= ~enable;
        LED_DDR |= enable;
 #else