aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/atmega168/ATmegaBOOT_168.c
diff options
context:
space:
mode:
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
}