mirror of
https://github.com/Optiboot/optiboot.git
synced 2025-08-19 09:02:05 +03:00
Add code and comment about resetting watchdog.
Which is needed if the bootloader will be invoked by the sketch as a service ('J' command.)
This commit is contained in:
@@ -78,6 +78,16 @@ void printReset(const char *label, uint8_t resetFlags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
#if 1
|
||||||
|
/*
|
||||||
|
* if we're going to allow the bootloader to be called as a service ('j" command),
|
||||||
|
* then we need to disable the WDT when the sketch starts. Essentially, there is no
|
||||||
|
* way to tell a watchdog that occurs during the sketch from the watchdog that will
|
||||||
|
* re-start the sketch when the bootloader is called from the application.
|
||||||
|
*/
|
||||||
|
MCUSR = ~(1 << WDRF); // allow us to disable WD
|
||||||
|
wdt_disable();
|
||||||
|
#endif
|
||||||
Serial.begin(9600); // Initialize serial port
|
Serial.begin(9600); // Initialize serial port
|
||||||
|
|
||||||
Serial.println(F("Reset flag test\n"));
|
Serial.println(F("Reset flag test\n"));
|
||||||
@@ -98,7 +108,7 @@ void loop() {
|
|||||||
printReset("\nNew MCUSR content: 0x", MCUSR);
|
printReset("\nNew MCUSR content: 0x", MCUSR);
|
||||||
} else
|
} else
|
||||||
switch (ch & ~('a' - 'A')) {
|
switch (ch & ~('a' - 'A')) {
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS);
|
||||||
while (1); // To prevent the loop to start again before WDT resets the board
|
while (1); // To prevent the loop to start again before WDT resets the board
|
||||||
@@ -115,7 +125,7 @@ void loop() {
|
|||||||
Serial.print(F("\nPower down not supported on this CPU\n"));
|
Serial.print(F("\nPower down not supported on this CPU\n"));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'J':
|
case 'J':
|
||||||
/* Figure out where the bootloader starts. */
|
/* Figure out where the bootloader starts. */
|
||||||
#if FLASHEND > 140000
|
#if FLASHEND > 140000
|
||||||
|
Reference in New Issue
Block a user