|
@@ -42,11 +42,16 @@ void watchdog_init() {
|
42
|
42
|
// Take care, as this requires the correct order of operation, with interrupts disabled.
|
43
|
43
|
// See the datasheet of any AVR chip for details.
|
44
|
44
|
wdt_reset();
|
|
45
|
+ cli();
|
45
|
46
|
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
|
46
|
|
- _WD_CONTROL_REG = _BV(WDIE) | WDTO_NS;
|
|
47
|
+ _WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
|
|
48
|
+ // So worked for up to WDTO_2S
|
|
49
|
+ sei();
|
|
50
|
+ wdt_reset();
|
47
|
51
|
#else
|
48
|
|
- wdt_enable(WDTO_NS);
|
|
52
|
+ wdt_enable(WDTO_NS); // The function handles the upper bit correct.
|
49
|
53
|
#endif
|
|
54
|
+ //delay(10000); // test it!
|
50
|
55
|
}
|
51
|
56
|
|
52
|
57
|
//===========================================================================
|
|
@@ -56,9 +61,10 @@ void watchdog_init() {
|
56
|
61
|
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
|
57
|
62
|
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
58
|
63
|
ISR(WDT_vect) {
|
|
64
|
+ sei(); // With the interrupt driven serial we need to allow interrupts.
|
59
|
65
|
SERIAL_ERROR_START();
|
60
|
|
- SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
|
61
|
|
- kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display
|
|
66
|
+ SERIAL_ERRORLNPGM("Watchdog barked, please turn off the printer.");
|
|
67
|
+ kill(PSTR("ERR:Watchdog")); //kill blocks //up to 16 characters so it fits on a 16x2 display
|
62
|
68
|
while (1); //wait for user or serial reset
|
63
|
69
|
}
|
64
|
70
|
#endif // WATCHDOG_RESET_MANUAL
|