Browse Source

Fix watchdog in WATCHDOG_RESET_MANUAL mode AVR

AnHardt 7 years ago
parent
commit
c72a0610b4
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp

+ 10
- 4
Marlin/src/HAL/HAL_AVR/watchdog_AVR.cpp View File

42
     // Take care, as this requires the correct order of operation, with interrupts disabled.
42
     // Take care, as this requires the correct order of operation, with interrupts disabled.
43
     // See the datasheet of any AVR chip for details.
43
     // See the datasheet of any AVR chip for details.
44
     wdt_reset();
44
     wdt_reset();
45
+    cli();
45
     _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
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
   #else
51
   #else
48
-    wdt_enable(WDTO_NS);
52
+    wdt_enable(WDTO_NS); // The function handles the upper bit correct.
49
   #endif
53
   #endif
54
+  //delay(10000); // test it!
50
 }
55
 }
51
 
56
 
52
 //===========================================================================
57
 //===========================================================================
56
 // Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
61
 // Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
57
 #if ENABLED(WATCHDOG_RESET_MANUAL)
62
 #if ENABLED(WATCHDOG_RESET_MANUAL)
58
   ISR(WDT_vect) {
63
   ISR(WDT_vect) {
64
+    sei();  // With the interrupt driven serial we need to allow interrupts.
59
     SERIAL_ERROR_START();
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
     while (1); //wait for user or serial reset
68
     while (1); //wait for user or serial reset
63
   }
69
   }
64
 #endif // WATCHDOG_RESET_MANUAL
70
 #endif // WATCHDOG_RESET_MANUAL

Loading…
Cancel
Save