Procházet zdrojové kódy

Fix watchdog in WATCHDOG_RESET_MANUAL mode AVR

AnHardt před 6 roky
rodič
revize
dcd7949544
1 změnil soubory, kde provedl 10 přidání a 4 odebrání
  1. 10
    4
      Marlin/watchdog.cpp

+ 10
- 4
Marlin/watchdog.cpp Zobrazit soubor

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

Loading…
Zrušit
Uložit