diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2008-09-06 22:17:58 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2008-09-06 22:17:58 +0000 |
commit | 080d18c6d2b2ec7c0ee8cad53226b5131a9e45dc (patch) | |
tree | 5ac0bddd2bceb049b45c8a8c3ba151e2541cee08 /bootloaders/atmega168/ATmegaBOOT_168.c | |
parent | 2ed2ee36e7c51f63ecf1391bf62fcd65ad35caa5 (diff) |
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.
Diffstat (limited to 'bootloaders/atmega168/ATmegaBOOT_168.c')
-rwxr-xr-x | bootloaders/atmega168/ATmegaBOOT_168.c | 17 |
1 files changed, 17 insertions, 0 deletions
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
}
|