aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/atmega168/ATmegaBOOT_168.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2008-09-06 22:17:58 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2008-09-06 22:17:58 +0000
commit080d18c6d2b2ec7c0ee8cad53226b5131a9e45dc (patch)
tree5ac0bddd2bceb049b45c8a8c3ba151e2541cee08 /bootloaders/atmega168/ATmegaBOOT_168.c
parent2ed2ee36e7c51f63ecf1391bf62fcd65ad35caa5 (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-xbootloaders/atmega168/ATmegaBOOT_168.c17
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
}