diff options
Diffstat (limited to 'bootloaders/diskloader/src')
-rw-r--r-- | bootloaders/diskloader/src/DiskLoader.cpp | 18 | ||||
-rw-r--r-- | bootloaders/diskloader/src/USBCore.cpp | 4 |
2 files changed, 17 insertions, 5 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 (;;) + ; +} diff --git a/bootloaders/diskloader/src/USBCore.cpp b/bootloaders/diskloader/src/USBCore.cpp index 208121e..0467e46 100644 --- a/bootloaders/diskloader/src/USBCore.cpp +++ b/bootloaders/diskloader/src/USBCore.cpp @@ -34,7 +34,7 @@ u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */ u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */ -void Reboot(); +void Reset(); //================================================================== //================================================================== @@ -500,7 +500,7 @@ int USBGetChar() } if (!--_timeout) { - Reboot(); // USB not connected, run firmware + Reset(); } _delay_us(100); // stretch out the bootloader period to about 5 seconds after enumeration |