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

+ 9
- 4
Marlin/temperature.cpp View File

21
 #include "Marlin.h"
21
 #include "Marlin.h"
22
 #include "ultralcd.h"
22
 #include "ultralcd.h"
23
 #include "temperature.h"
23
 #include "temperature.h"
24
-#include "watchdog.h"
25
 #include "language.h"
24
 #include "language.h"
26
-
27
 #include "Sd2PinMap.h"
25
 #include "Sd2PinMap.h"
28
 
26
 
27
+#if ENABLED(USE_WATCHDOG)
28
+  #include "watchdog.h"
29
+#endif
30
+
29
 //===========================================================================
31
 //===========================================================================
30
 //================================== macros =================================
32
 //================================== macros =================================
31
 //===========================================================================
33
 //===========================================================================
819
   #if HAS_FILAMENT_SENSOR
821
   #if HAS_FILAMENT_SENSOR
820
     filament_width_meas = analog2widthFil();
822
     filament_width_meas = analog2widthFil();
821
   #endif
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
   CRITICAL_SECTION_START;
830
   CRITICAL_SECTION_START;
826
   temp_meas_ready = false;
831
   temp_meas_ready = false;

+ 13
- 29
Marlin/watchdog.cpp View File

1
 #include "Marlin.h"
1
 #include "Marlin.h"
2
 
2
 
3
 #if ENABLED(USE_WATCHDOG)
3
 #if ENABLED(USE_WATCHDOG)
4
-#include <avr/wdt.h>
5
 
4
 
6
 #include "watchdog.h"
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
 void watchdog_init() {
8
 void watchdog_init() {
20
   #if ENABLED(WATCHDOG_RESET_MANUAL)
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
     wdt_reset();
12
     wdt_reset();
24
     _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
13
     _WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
25
     _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
14
     _WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
28
   #endif
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
 //=================================== ISR ===================================
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
 #if ENABLED(WATCHDOG_RESET_MANUAL)
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
 #define WATCHDOG_H
2
 #define WATCHDOG_H
3
 
3
 
4
 #include "Marlin.h"
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
 #endif
14
 #endif

Loading…
Cancel
Save