Browse Source

Clean up watchdog impl.

Scott Lahteine 9 years ago
parent
commit
b4af4441c5
4 changed files with 38 additions and 45 deletions
  1. 9
    2
      Marlin/Marlin_main.cpp
  2. 9
    4
      Marlin/temperature.cpp
  3. 13
    29
      Marlin/watchdog.cpp
  4. 7
    10
      Marlin/watchdog.h

+ 9
- 2
Marlin/Marlin_main.cpp View File

@@ -45,13 +45,16 @@
45 45
 #include "stepper.h"
46 46
 #include "temperature.h"
47 47
 #include "cardreader.h"
48
-#include "watchdog.h"
49 48
 #include "configuration_store.h"
50 49
 #include "language.h"
51 50
 #include "pins_arduino.h"
52 51
 #include "math.h"
53 52
 #include "buzzer.h"
54 53
 
54
+#if ENABLED(USE_WATCHDOG)
55
+  #include "watchdog.h"
56
+#endif
57
+
55 58
 #if ENABLED(BLINKM)
56 59
   #include "blinkm.h"
57 60
   #include "Wire.h"
@@ -681,7 +684,11 @@ void setup() {
681 684
 
682 685
   tp_init();    // Initialize temperature loop
683 686
   plan_init();  // Initialize planner;
684
-  watchdog_init();
687
+
688
+  #if ENABLED(USE_WATCHDOG)
689
+    watchdog_init();
690
+  #endif
691
+
685 692
   st_init();    // Initialize stepper, this enables interrupts!
686 693
   setup_photpin();
687 694
   servo_init();

+ 9
- 4
Marlin/temperature.cpp View File

@@ -21,11 +21,13 @@
21 21
 #include "Marlin.h"
22 22
 #include "ultralcd.h"
23 23
 #include "temperature.h"
24
-#include "watchdog.h"
25 24
 #include "language.h"
26
-
27 25
 #include "Sd2PinMap.h"
28 26
 
27
+#if ENABLED(USE_WATCHDOG)
28
+  #include "watchdog.h"
29
+#endif
30
+
29 31
 //===========================================================================
30 32
 //================================== macros =================================
31 33
 //===========================================================================
@@ -819,8 +821,11 @@ static void updateTemperaturesFromRawValues() {
819 821
   #if HAS_FILAMENT_SENSOR
820 822
     filament_width_meas = analog2widthFil();
821 823
   #endif
822
-  //Reset the watchdog after we know we have a temperature measurement.
823
-  watchdog_reset();
824
+
825
+  #if ENABLED(USE_WATCHDOG)
826
+    // Reset the watchdog after we know we have a temperature measurement.
827
+    watchdog_reset();
828
+  #endif
824 829
 
825 830
   CRITICAL_SECTION_START;
826 831
   temp_meas_ready = false;

+ 13
- 29
Marlin/watchdog.cpp View File

@@ -1,25 +1,14 @@
1 1
 #include "Marlin.h"
2 2
 
3 3
 #if ENABLED(USE_WATCHDOG)
4
-#include <avr/wdt.h>
5 4
 
6 5
 #include "watchdog.h"
7
-#include "ultralcd.h"
8 6
 
9
-//===========================================================================
10
-//============================ private variables ============================
11
-//===========================================================================
12
-
13
-//===========================================================================
14
-//================================ functions ================================
15
-//===========================================================================
16
-
17
-
18
-/// intialise watch dog with a 4 sec interrupt time
7
+// Initialize watchdog with a 4 sec interrupt time
19 8
 void watchdog_init() {
20 9
   #if ENABLED(WATCHDOG_RESET_MANUAL)
21
-    //We enable the watchdog timer, but only for the interrupt.
22
-    //Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
10
+    // We enable the watchdog timer, but only for the interrupt.
11
+    // Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
23 12
     wdt_reset();
24 13
     _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
25 14
     _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
@@ -28,23 +17,18 @@ void watchdog_init() {
28 17
   #endif
29 18
 }
30 19
 
31
-/// reset watchdog. MUST be called every 1s after init or avr will reset.
32
-void watchdog_reset() {
33
-  wdt_reset();
34
-}
35
-
36 20
 //===========================================================================
37 21
 //=================================== ISR ===================================
38 22
 //===========================================================================
39 23
 
40
-//Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled.
24
+// Watchdog timer interrupt, called if main program blocks >1sec and manual reset is enabled.
41 25
 #if ENABLED(WATCHDOG_RESET_MANUAL)
42
-ISR(WDT_vect) {
43
-  SERIAL_ERROR_START;
44
-  SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
45
-  kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display
46
-  while (1); //wait for user or serial reset
47
-}
48
-#endif//RESET_MANUAL
49
-
50
-#endif//USE_WATCHDOG
26
+  ISR(WDT_vect) {
27
+    SERIAL_ERROR_START;
28
+    SERIAL_ERRORLNPGM("Something is wrong, please turn off the printer.");
29
+    kill(PSTR("ERR:Please Reset")); //kill blocks //16 characters so it fits on a 16x2 display
30
+    while (1); //wait for user or serial reset
31
+  }
32
+#endif //WATCHDOG_RESET_MANUAL
33
+
34
+#endif //USE_WATCHDOG

+ 7
- 10
Marlin/watchdog.h View File

@@ -2,16 +2,13 @@
2 2
 #define WATCHDOG_H
3 3
 
4 4
 #include "Marlin.h"
5
+#include <avr/wdt.h>
5 6
 
6
-#if ENABLED(USE_WATCHDOG)
7
-  // initialize watch dog with a 1 sec interrupt time
8
-  void watchdog_init();
9
-  // pad the dog/reset watchdog. MUST be called at least every second after the first watchdog_init or AVR will go into emergency procedures..
10
-  void watchdog_reset();
11
-#else
12
-  //If we do not have a watchdog, then we can have empty functions which are optimized away.
13
-  FORCE_INLINE void watchdog_init() {};
14
-  FORCE_INLINE void watchdog_reset() {};
15
-#endif
7
+// Initialize watchdog with a 4 second interrupt time
8
+void watchdog_init();
9
+
10
+// Reset watchdog. MUST be called at least every 4 seconds after the
11
+// first watchdog_init or AVR will go into emergency procedures.
12
+inline void watchdog_reset() { wdt_reset(); }
16 13
 
17 14
 #endif

Loading…
Cancel
Save