aboutsummaryrefslogtreecommitdiff
path: root/bootloaders/diskloader/src/DiskLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bootloaders/diskloader/src/DiskLoader.cpp')
-rw-r--r--bootloaders/diskloader/src/DiskLoader.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/bootloaders/diskloader/src/DiskLoader.cpp b/bootloaders/diskloader/src/DiskLoader.cpp
index 6580618..09f59a7 100644
--- a/bootloaders/diskloader/src/DiskLoader.cpp
+++ b/bootloaders/diskloader/src/DiskLoader.cpp
@@ -56,7 +56,7 @@ void Program(u8 ep, u16 page, u8 count)
boot_rww_enable ();
}
-
+void StartSketch();
int USBGetChar();
#define getch USBGetChar
@@ -111,10 +111,15 @@ int main(void) __attribute__ ((naked));
// STK500v1 main loop, very similar to optiboot in protocol and implementation
int main()
{
+ uint8_t MCUSR_state = MCUSR; // store the reason for the reset
+ MCUSR &= ~(1 << WDRF); // must clear the watchdog reset flag before disabling and reenabling WDT
wdt_disable();
TXLED0;
RXLED0;
- LED0;
+ LED0;
+ if (MCUSR_state & (1<<WDRF) && (pgm_read_word(0) != -1)) {
+ StartSketch(); // if the reset was caused by WDT and if a sketch is already present then run the sketch instead of the bootloader
+ }
BOARD_INIT();
USBInit();
@@ -225,7 +230,7 @@ void LEDPulse()
LED1;
}
-void Reboot()
+void StartSketch()
{
TXLED0; // switch off the RX and TX LEDs before starting the user sketch
RXLED0;
@@ -237,3 +242,10 @@ void Reboot()
"ijmp\n"
::);
}
+
+void Reset()
+{
+ wdt_enable(WDTO_15MS);
+ for (;;)
+ ;
+}