Browse Source

Watchdog cleanup (#15283)

Scott Lahteine 5 years ago
parent
commit
139b7196a0
No account linked to committer's email address

+ 6
- 0
Marlin/src/HAL/HAL.h View File

@@ -24,3 +24,9 @@
24 24
 #include "platforms.h"
25 25
 
26 26
 #include HAL_PATH(.,HAL.h)
27
+
28
+inline void watchdog_refresh() {
29
+  #if ENABLED(USE_WATCHDOG)
30
+    HAL_watchdog_refresh();
31
+  #endif
32
+}

+ 1
- 1
Marlin/src/HAL/HAL_AVR/watchdog.h View File

@@ -28,4 +28,4 @@ void watchdog_init();
28 28
 
29 29
 // Reset watchdog. MUST be called at least every 4 seconds after the
30 30
 // first watchdog_init or AVR will go into emergency procedures.
31
-inline void watchdog_reset() { wdt_reset(); }
31
+inline void HAL_watchdog_refresh() { wdt_reset(); }

+ 1
- 1
Marlin/src/HAL/HAL_DUE/watchdog.h View File

@@ -30,4 +30,4 @@ void watchdog_init();
30 30
 
31 31
 // Reset watchdog. MUST be called at least every 4 seconds after the
32 32
 // first watchdog_init or AVR will go into emergency procedures.
33
-inline void watchdog_reset() { watchdogReset(); }
33
+inline void HAL_watchdog_refresh() { watchdogReset(); }

+ 1
- 1
Marlin/src/HAL/HAL_ESP32/watchdog.h View File

@@ -25,4 +25,4 @@
25 25
 void watchdog_init();
26 26
 
27 27
 // Reset watchdog.
28
-inline void watchdog_reset() { }
28
+inline void HAL_watchdog_refresh() { }

+ 4
- 0
Marlin/src/HAL/HAL_LINUX/HAL.h View File

@@ -97,6 +97,10 @@ void HAL_adc_enable_channel(int pin);
97 97
 void HAL_adc_start_conversion(const uint8_t adc_pin);
98 98
 uint16_t HAL_adc_get_result();
99 99
 
100
+// Reset source
101
+inline void HAL_clear_reset_source(void) {}
102
+inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
103
+
100 104
 /* ---------------- Delay in cycles */
101 105
 FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
102 106
   Clock::delayCycles(x);

+ 2
- 12
Marlin/src/HAL/HAL_LINUX/watchdog.cpp View File

@@ -29,18 +29,8 @@
29 29
 #include "watchdog.h"
30 30
 
31 31
 void watchdog_init() {}
32
+void HAL_watchdog_refresh() {}
32 33
 
33
-void HAL_clear_reset_source() {}
34
-
35
-uint8_t HAL_get_reset_source() {
36
-  return RST_POWER_ON;
37
-}
38
-
39
-void watchdog_reset() {}
40
-
41
-#else
42
-  void HAL_clear_reset_source() {}
43
-  uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
44
-#endif // USE_WATCHDOG
34
+#endif
45 35
 
46 36
 #endif // __PLAT_LINUX__

+ 1
- 3
Marlin/src/HAL/HAL_LINUX/watchdog.h View File

@@ -24,6 +24,4 @@
24 24
 #define WDT_TIMEOUT   4000000 // 4 second timeout
25 25
 
26 26
 void watchdog_init();
27
-void watchdog_reset();
28
-void HAL_clear_reset_source();
29
-uint8_t HAL_get_reset_source();
27
+void HAL_watchdog_refresh();

+ 17
- 0
Marlin/src/HAL/HAL_LPC1768/HAL.cpp View File

@@ -26,6 +26,10 @@
26 26
 #include "../shared/Delay.h"
27 27
 #include "../../../gcode/parser.h"
28 28
 
29
+#if ENABLED(USE_WATCHDOG)
30
+  #include "watchdog.h"
31
+#endif
32
+
29 33
 // U8glib required functions
30 34
 extern "C" void u8g_xMicroDelay(uint16_t val) {
31 35
   DELAY_US(val);
@@ -65,4 +69,17 @@ void flashFirmware(int16_t value) {
65 69
   NVIC_SystemReset();
66 70
 }
67 71
 
72
+void HAL_clear_reset_source(void) {
73
+  #if ENABLED(USE_WATCHDOG)
74
+    watchdog_clear_timeout_flag();
75
+  #endif
76
+}
77
+
78
+uint8_t HAL_get_reset_source(void) {
79
+  #if ENABLED(USE_WATCHDOG)
80
+    if (watchdog_timed_out()) return RST_WATCHDOG;
81
+  #endif
82
+  return RST_POWER_ON;
83
+}
84
+
68 85
 #endif // TARGET_LPC1768

+ 4
- 0
Marlin/src/HAL/HAL_LPC1768/HAL.h View File

@@ -164,3 +164,7 @@ void set_pwm_frequency(const pin_t pin, int f_desired);
164 164
  *  Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
165 165
  */
166 166
 void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
167
+
168
+// Reset source
169
+void HAL_clear_reset_source(void);
170
+uint8_t HAL_get_reset_source(void);

+ 4
- 16
Marlin/src/HAL/HAL_LPC1768/watchdog.cpp View File

@@ -56,28 +56,16 @@ void watchdog_init() {
56 56
   WDT_Start(WDT_TIMEOUT);
57 57
 }
58 58
 
59
-void HAL_clear_reset_source() {
60
-  WDT_ClrTimeOutFlag();
61
-}
62
-
63
-uint8_t HAL_get_reset_source() {
64
-  if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
65
-  return RST_POWER_ON;
66
-}
67
-
68
-void watchdog_reset() {
59
+void HAL_watchdog_refresh() {
69 60
   WDT_Feed();
70 61
   #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
71 62
     TOGGLE(LED_PIN);  // heartbeat indicator
72 63
   #endif
73 64
 }
74 65
 
75
-#else
76
-
77
-void watchdog_init() {}
78
-void watchdog_reset() {}
79
-void HAL_clear_reset_source() {}
80
-uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
66
+// Timeout state
67
+bool watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
68
+void watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
81 69
 
82 70
 #endif // USE_WATCHDOG
83 71
 

+ 4
- 3
Marlin/src/HAL/HAL_LPC1768/watchdog.h View File

@@ -24,6 +24,7 @@
24 24
 #define WDT_TIMEOUT   4000000 // 4 second timeout
25 25
 
26 26
 void watchdog_init();
27
-void watchdog_reset();
28
-void HAL_clear_reset_source();
29
-uint8_t HAL_get_reset_source();
27
+void HAL_watchdog_refresh();
28
+
29
+bool watchdog_timed_out();
30
+void watchdog_clear_timeout_flag();

+ 1
- 1
Marlin/src/HAL/HAL_SAMD51/watchdog.cpp View File

@@ -42,7 +42,7 @@
42 42
     WDT->INTENCLR.reg = WDT_INTENCLR_EW;        // Disable early warning interrupt
43 43
     WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096;   // Set at least 4s period for chip reset
44 44
 
45
-    watchdog_reset();
45
+    HAL_watchdog_refresh();
46 46
 
47 47
     WDT->CTRLA.reg = WDT_CTRLA_ENABLE;          // Start watchdog now in normal mode
48 48
     SYNC(WDT->SYNCBUSY.bit.ENABLE);

+ 1
- 1
Marlin/src/HAL/HAL_SAMD51/watchdog.h View File

@@ -25,7 +25,7 @@ void watchdog_init();
25 25
 
26 26
 // Reset watchdog. MUST be called at least every 4 seconds after the
27 27
 // first watchdog_init or SAMD will go into emergency procedures.
28
-inline void watchdog_reset() {
28
+inline void HAL_watchdog_refresh() {
29 29
   SYNC(WDT->SYNCBUSY.bit.CLEAR);        // Test first if previous is 'ongoing' to save time waiting for command execution
30 30
   WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
31 31
 }

+ 1
- 1
Marlin/src/HAL/HAL_STM32/watchdog.cpp View File

@@ -33,7 +33,7 @@
33 33
 
34 34
   void watchdog_init() { IWatchdog.begin(4000000); } // 4 sec timeout
35 35
 
36
-  void watchdog_reset() {
36
+  void HAL_watchdog_refresh() {
37 37
     IWatchdog.reload();
38 38
     #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
39 39
       TOGGLE(LED_PIN);  // heartbeat indicator

+ 1
- 1
Marlin/src/HAL/HAL_STM32/watchdog.h View File

@@ -22,4 +22,4 @@
22 22
 #pragma once
23 23
 
24 24
 void watchdog_init();
25
-void watchdog_reset();
25
+void HAL_watchdog_refresh();

+ 1
- 1
Marlin/src/HAL/HAL_STM32F1/watchdog.cpp View File

@@ -33,7 +33,7 @@
33 33
 #include <libmaple/iwdg.h>
34 34
 #include "watchdog.h"
35 35
 
36
-void watchdog_reset() {
36
+void HAL_watchdog_refresh() {
37 37
   #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
38 38
     TOGGLE(LED_PIN);  // heartbeat indicator
39 39
   #endif

+ 1
- 1
Marlin/src/HAL/HAL_STM32F1/watchdog.h View File

@@ -41,4 +41,4 @@ void watchdog_init();
41 41
 
42 42
 // Reset watchdog. MUST be called at least every 4 seconds after the
43 43
 // first watchdog_init or STM32F1 will reset.
44
-void watchdog_reset();
44
+void HAL_watchdog_refresh();

+ 1
- 1
Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.cpp View File

@@ -44,7 +44,7 @@
44 44
     }
45 45
   }
46 46
 
47
-  void watchdog_reset() {
47
+  void HAL_watchdog_refresh() {
48 48
     /* Refresh IWDG: reload counter */
49 49
     if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
50 50
       /* Refresh Error */

+ 1
- 1
Marlin/src/HAL/HAL_STM32_F4_F7/watchdog.h View File

@@ -24,4 +24,4 @@
24 24
 extern IWDG_HandleTypeDef hiwdg;
25 25
 
26 26
 void watchdog_init();
27
-void watchdog_reset();
27
+void HAL_watchdog_refresh();

+ 1
- 1
Marlin/src/HAL/HAL_TEENSY31_32/watchdog.h View File

@@ -27,7 +27,7 @@
27 27
 
28 28
 void watchdog_init();
29 29
 
30
-inline void watchdog_reset() {
30
+inline void HAL_watchdog_refresh() {
31 31
   // Watchdog refresh sequence
32 32
   WDOG_REFRESH = 0xA602;
33 33
   WDOG_REFRESH = 0xB480;

+ 1
- 1
Marlin/src/HAL/HAL_TEENSY35_36/watchdog.h View File

@@ -23,7 +23,7 @@
23 23
 
24 24
 void watchdog_init();
25 25
 
26
-inline void watchdog_reset() {
26
+inline void HAL_watchdog_refresh() {
27 27
   // Watchdog refresh sequence
28 28
   WDOG_REFRESH = 0xA602;
29 29
   WDOG_REFRESH = 0xB480;

+ 3
- 15
Marlin/src/Marlin.cpp View File

@@ -801,29 +801,17 @@ void minkill(const bool steppers_off/*=false*/) {
801 801
   #if HAS_KILL
802 802
 
803 803
     // Wait for kill to be released
804
-    while (!READ(KILL_PIN)) {
805
-      #if ENABLED(USE_WATCHDOG)
806
-        watchdog_reset();
807
-      #endif
808
-    }
804
+    while (!READ(KILL_PIN)) watchdog_refresh();
809 805
 
810 806
     // Wait for kill to be pressed
811
-    while (READ(KILL_PIN)) {
812
-      #if ENABLED(USE_WATCHDOG)
813
-        watchdog_reset();
814
-      #endif
815
-    }
807
+    while (READ(KILL_PIN)) watchdog_refresh();
816 808
 
817 809
     void (*resetFunc)() = 0;  // Declare resetFunc() at address 0
818 810
     resetFunc();                  // Jump to address 0
819 811
 
820 812
   #else // !HAS_KILL
821 813
 
822
-    for (;;) {
823
-      #if ENABLED(USE_WATCHDOG)
824
-        watchdog_reset();
825
-      #endif
826
-    } // Wait for reset
814
+    for (;;) watchdog_refresh(); // Wait for reset
827 815
 
828 816
   #endif // !HAS_KILL
829 817
 }

+ 5
- 11
Marlin/src/gcode/config/M43.cpp View File

@@ -50,12 +50,6 @@
50 50
   #define GET_PIN_MAP_PIN_M43(Q) GET_PIN_MAP_PIN(Q)
51 51
 #endif
52 52
 
53
-inline void _watchdog_reset() {
54
-  #if ENABLED(USE_WATCHDOG)
55
-    watchdog_reset();
56
-  #endif
57
-}
58
-
59 53
 inline void toggle_pins() {
60 54
   const bool ignore_protection = parser.boolval('I');
61 55
   const int repeat = parser.intval('R', 1),
@@ -71,7 +65,7 @@ inline void toggle_pins() {
71 65
       SERIAL_EOL();
72 66
     }
73 67
     else {
74
-      _watchdog_reset();
68
+      watchdog_refresh();
75 69
       report_pin_state_extended(pin, ignore_protection, true, "Pulsing   ");
76 70
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
77 71
         if (pin == TEENSY_E2) {
@@ -95,10 +89,10 @@ inline void toggle_pins() {
95 89
       {
96 90
         pinMode(pin, OUTPUT);
97 91
         for (int16_t j = 0; j < repeat; j++) {
98
-          _watchdog_reset(); extDigitalWrite(pin, 0); safe_delay(wait);
99
-          _watchdog_reset(); extDigitalWrite(pin, 1); safe_delay(wait);
100
-          _watchdog_reset(); extDigitalWrite(pin, 0); safe_delay(wait);
101
-          _watchdog_reset();
92
+          watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
93
+          watchdog_refresh(); extDigitalWrite(pin, 1); safe_delay(wait);
94
+          watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
95
+          watchdog_refresh();
102 96
         }
103 97
       }
104 98
     }

+ 1
- 1
Marlin/src/gcode/feature/L6470/M916-918.cpp View File

@@ -258,7 +258,7 @@ void GcodeSuite::M917() {
258 258
         }
259 259
         DEBUG_ECHOLNPGM(".");
260 260
         reset_stepper_timeout(); // reset_stepper_timeout to keep steppers powered
261
-        watchdog_reset();   // beat the dog
261
+        watchdog_refresh();
262 262
         safe_delay(5000);
263 263
         status_composite_temp = 0;
264 264
         for (j = 0; j < driver_count; j++) {

+ 3
- 5
Marlin/src/module/temperature.cpp View File

@@ -1000,7 +1000,7 @@ void Temperature::manage_heater() {
1000 1000
 
1001 1001
   #if EARLY_WATCHDOG
1002 1002
     // If thermal manager is still not running, make sure to at least reset the watchdog!
1003
-    if (!inited) return watchdog_reset();
1003
+    if (!inited) return watchdog_refresh();
1004 1004
   #endif
1005 1005
 
1006 1006
   #if BOTH(PROBING_HEATERS_OFF, BED_LIMIT_SWITCHING)
@@ -1518,10 +1518,8 @@ void Temperature::updateTemperaturesFromRawValues() {
1518 1518
     filwidth.update_measured_mm();
1519 1519
   #endif
1520 1520
 
1521
-  #if ENABLED(USE_WATCHDOG)
1522
-    // Reset the watchdog after we know we have a temperature measurement.
1523
-    watchdog_reset();
1524
-  #endif
1521
+  // Reset the watchdog on good temperature measurement
1522
+  watchdog_refresh();
1525 1523
 
1526 1524
   temp_meas_ready = false;
1527 1525
 }

+ 4
- 17
Marlin/src/sd/Sd2Card.cpp View File

@@ -234,11 +234,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
234 234
   const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
235 235
   uint32_t arg;
236 236
 
237
-  // If init takes more than 4s it could trigger
238
-  // watchdog leading to a reboot loop.
239
-  #if ENABLED(USE_WATCHDOG)
240
-    watchdog_reset();
241
-  #endif
237
+  watchdog_refresh(); // In case init takes too long
242 238
 
243 239
   // Set pin modes
244 240
   extDigitalWrite(chipSelectPin_, HIGH);  // For some CPUs pinMode can write the wrong data so init desired data value first
@@ -252,10 +248,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
252 248
   // Must supply min of 74 clock cycles with CS high.
253 249
   for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
254 250
 
255
-  // Initialization can cause the watchdog to timeout, so reinit it here
256
-  #if ENABLED(USE_WATCHDOG)
257
-    watchdog_reset();
258
-  #endif
251
+  watchdog_refresh(); // In case init takes too long
259 252
 
260 253
   // Command to go idle in SPI mode
261 254
   while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
@@ -269,10 +262,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
269 262
     crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
270 263
   #endif
271 264
 
272
-  // Initialization can cause the watchdog to timeout, so reinit it here
273
-  #if ENABLED(USE_WATCHDOG)
274
-    watchdog_reset();
275
-  #endif
265
+  watchdog_refresh(); // In case init takes too long
276 266
 
277 267
   // check SD version
278 268
   for (;;) {
@@ -294,10 +284,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
294 284
     }
295 285
   }
296 286
 
297
-  // Initialization can cause the watchdog to timeout, so reinit it here
298
-  #if ENABLED(USE_WATCHDOG)
299
-    watchdog_reset();
300
-  #endif
287
+  watchdog_refresh(); // In case init takes too long
301 288
 
302 289
   // Initialize card and send host supports SDHC if SD2
303 290
   arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;

+ 1
- 0
buildroot/share/tests/megaatmega2560-tests View File

@@ -25,6 +25,7 @@ opt_set TEMP_SENSOR_1 1
25 25
 opt_set TEMP_SENSOR_BED 2
26 26
 opt_set GRID_MAX_POINTS_X 16
27 27
 opt_set FANMUX0_PIN 53
28
+opt_disable USE_WATCHDOG
28 29
 opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \
29 30
            PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING \
30 31
            EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \

+ 1
- 1
platformio.ini View File

@@ -591,7 +591,7 @@ monitor_speed     = 250000
591 591
 #
592 592
 [env:linux_native]
593 593
 platform        = native
594
-build_flags     = -D__PLAT_LINUX__ -std=gnu++17 -ggdb -g -lrt -lpthread -D__MARLIN_FIRMWARE__
594
+build_flags     = -D__PLAT_LINUX__ -std=gnu++17 -ggdb -g -lrt -lpthread -D__MARLIN_FIRMWARE__ -Wno-expansion-to-defined
595 595
 src_build_flags = -Wall -IMarlin/src/HAL/HAL_LINUX/include
596 596
 build_unflags   = -Wall
597 597
 lib_ldf_mode    = off

Loading…
Cancel
Save