[patch] handle watchdog resets in arduino bootldr

hello all,

i originally posted this to the arduino developers mailing list, but as i
am not subscribed to it, the mail sat around waiting for moderator
approval which unfortunately never came (maybe this can be fixed as
well?). i am hence placing this here, hoping that someone might pick
it up for 1.0 :wink:

when a watchdog reset occurs, the watchdog timer stays enabled (as
described on p.52 of the atmega 168 datasheet) - and this leads to the
watchdog resetting again and again in the bootloader, requiring a hard
powerdown by the user.

the current ATmegaBOOT_168.c now has the WATCHDOG_MODS part from the
lilypad bootloader - but i think whether or not that is being used
(skipping the bootloader code early on after a watchdog reset), the
watchdog registers should be cleared anyway.

the attached patch is against 0013, but it should still apply with
some offset to the latest (0017) source

kind regards,
gohai

diff -u orig/ATmegaBOOT_168.c new/ATmegaBOOT_168.c
--- orig/ATmegaBOOT_168.c       Fri Feb  6 12:56:00 2009
+++ new/ATmegaBOOT_168.c        Wed Mar  4 14:08:31 2009
@@ -258,13 +258,12 @@
       uint8_t ch,ch2;
       uint16_t w;

-#ifdef WATCHDOG_MODS
       ch = MCUSR;
       MCUSR = 0;

       WDTCSR |= _BV(WDCE) | _BV(WDE);
       WDTCSR = 0;
-
+#ifdef WATCHDOG_MODS
       // Check if the WDT was used to reset, in which case we dont
bootload and skip straight to the code. woot.
       if (! (ch &  _BV(EXTRF))) // if its a not an external reset...
               app_start();  // skip bootloader

kind regards,
gohai

Can you post this to the Google Code issues list: Google Code Archive - Long-term storage for Google Code Project Hosting.?