From 080d18c6d2b2ec7c0ee8cad53226b5131a9e45dc Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sat, 6 Sep 2008 22:17:58 +0000 Subject: Incorporating ladyada's watchdog timer changes into the bootloader source, but only compiling them in for the Pro and Pro Mini (since Nathan includes them in the bootloader he burns to the board). Added a WATCHDOG_MODS flag to the Makefile to specify that they should be included. Recompiled the pro .hex file to include them. --- bootloaders/atmega168/ATmegaBOOT_168.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'bootloaders/atmega168/ATmegaBOOT_168.c') diff --git a/bootloaders/atmega168/ATmegaBOOT_168.c b/bootloaders/atmega168/ATmegaBOOT_168.c index c542af1..7bbf24e 100755 --- a/bootloaders/atmega168/ATmegaBOOT_168.c +++ b/bootloaders/atmega168/ATmegaBOOT_168.c @@ -251,7 +251,19 @@ int main(void) uint8_t ch,ch2; uint16_t w; +#ifdef WATCHDOG_MODS + ch = MCUSR; + MCUSR = 0; + + WDTCSR |= _BV(WDCE) | _BV(WDE); + WDTCSR = 0; + + // 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 +#else asm volatile("nop\n\t"); +#endif /* set pin direction for bootloader pin and enable pullup */ /* for ATmega128, two pins need to be initialized */ @@ -445,6 +457,11 @@ int main(void) /* Leave programming mode */ else if(ch=='Q') { nothing_response(); +#ifdef WATCHDOG_MODS + // autoreset via watchdog (sneaky!) + WDTCSR = _BV(WDE); + while (1); // 16 ms +#endif } -- cgit v1.2.3-18-g5258