Переглянути джерело

HAL support for 8s watchdog

Scott Lahteine 4 роки тому
джерело
коміт
4fe1adc383

+ 1
- 1
Marlin/src/HAL/DUE/watchdog.cpp Переглянути файл

36
   #if ENABLED(USE_WATCHDOG)
36
   #if ENABLED(USE_WATCHDOG)
37
 
37
 
38
     // 4 seconds timeout
38
     // 4 seconds timeout
39
-    uint32_t timeout = 4000;
39
+    uint32_t timeout = TERN(WATCHDOG_DURATION_8S, 8000, 4000);
40
 
40
 
41
     // Calculate timeout value in WDT counter ticks: This assumes
41
     // Calculate timeout value in WDT counter ticks: This assumes
42
     // the slow clock is running at 32.768 kHz watchdog
42
     // the slow clock is running at 32.768 kHz watchdog

+ 2
- 0
Marlin/src/HAL/ESP32/watchdog.cpp Переглянути файл

25
 
25
 
26
 #if ENABLED(USE_WATCHDOG)
26
 #if ENABLED(USE_WATCHDOG)
27
 
27
 
28
+#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
29
+
28
 #include "watchdog.h"
30
 #include "watchdog.h"
29
 
31
 
30
 void watchdogSetup() {
32
 void watchdogSetup() {

+ 2
- 0
Marlin/src/HAL/LINUX/watchdog.cpp Переглянути файл

27
 
27
 
28
 #include "watchdog.h"
28
 #include "watchdog.h"
29
 
29
 
30
+#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
31
+
30
 void watchdog_init() {}
32
 void watchdog_init() {}
31
 void HAL_watchdog_refresh() {}
33
 void HAL_watchdog_refresh() {}
32
 
34
 

+ 0
- 2
Marlin/src/HAL/LINUX/watchdog.h Переглянути файл

21
  */
21
  */
22
 #pragma once
22
 #pragma once
23
 
23
 
24
-#define WDT_TIMEOUT   4000000 // 4 second timeout
25
-
26
 void watchdog_init();
24
 void watchdog_init();
27
 void HAL_watchdog_refresh();
25
 void HAL_watchdog_refresh();

+ 3
- 1
Marlin/src/HAL/LPC1768/watchdog.cpp Переглянути файл

28
 #include <lpc17xx_wdt.h>
28
 #include <lpc17xx_wdt.h>
29
 #include "watchdog.h"
29
 #include "watchdog.h"
30
 
30
 
31
+#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
32
+
31
 void watchdog_init() {
33
 void watchdog_init() {
32
   #if ENABLED(WATCHDOG_RESET_MANUAL)
34
   #if ENABLED(WATCHDOG_RESET_MANUAL)
33
     // We enable the watchdog timer, but only for the interrupt.
35
     // We enable the watchdog timer, but only for the interrupt.
52
   #else
54
   #else
53
     WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
55
     WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
54
   #endif
56
   #endif
55
-  WDT_Start(WDT_TIMEOUT);
57
+  WDT_Start(WDT_TIMEOUT_US);
56
 }
58
 }
57
 
59
 
58
 void HAL_watchdog_refresh() {
60
 void HAL_watchdog_refresh() {

+ 0
- 2
Marlin/src/HAL/LPC1768/watchdog.h Переглянути файл

21
  */
21
  */
22
 #pragma once
22
 #pragma once
23
 
23
 
24
-#define WDT_TIMEOUT   4000000 // 4 second timeout
25
-
26
 void watchdog_init();
24
 void watchdog_init();
27
 void HAL_watchdog_refresh();
25
 void HAL_watchdog_refresh();
28
 
26
 

+ 18
- 16
Marlin/src/HAL/SAMD51/watchdog.cpp Переглянути файл

24
 
24
 
25
 #if ENABLED(USE_WATCHDOG)
25
 #if ENABLED(USE_WATCHDOG)
26
 
26
 
27
-  #include "watchdog.h"
27
+#include "watchdog.h"
28
 
28
 
29
-  void watchdog_init() {
30
-    // The low-power oscillator used by the WDT runs at 32,768 Hz with
31
-    // a 1:32 prescale, thus 1024 Hz, though probably not super precise.
29
+#define WDT_TIMEOUT_REG TERN(WATCHDOG_DURATION_8S, WDT_CONFIG_PER_CYC8192, WDT_CONFIG_PER_CYC4096) // 4 or 8 second timeout
32
 
30
 
33
-    // Setup WDT clocks
34
-    MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
35
-    MCLK->APBAMASK.bit.WDT_ = true;
36
-    OSC32KCTRL->OSCULP32K.bit.EN1K = true;      // Enable out 1K (this is what WDT uses)
31
+void watchdog_init() {
32
+  // The low-power oscillator used by the WDT runs at 32,768 Hz with
33
+  // a 1:32 prescale, thus 1024 Hz, though probably not super precise.
37
 
34
 
38
-    WDT->CTRLA.bit.ENABLE = false;              // Disable watchdog for config
39
-    SYNC(WDT->SYNCBUSY.bit.ENABLE);
35
+  // Setup WDT clocks
36
+  MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
37
+  MCLK->APBAMASK.bit.WDT_ = true;
38
+  OSC32KCTRL->OSCULP32K.bit.EN1K = true;      // Enable out 1K (this is what WDT uses)
40
 
39
 
41
-    WDT->INTENCLR.reg = WDT_INTENCLR_EW;        // Disable early warning interrupt
42
-    WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096;   // Set at least 4s period for chip reset
40
+  WDT->CTRLA.bit.ENABLE = false;              // Disable watchdog for config
41
+  SYNC(WDT->SYNCBUSY.bit.ENABLE);
43
 
42
 
44
-    HAL_watchdog_refresh();
43
+  WDT->INTENCLR.reg = WDT_INTENCLR_EW;        // Disable early warning interrupt
44
+  WDT->CONFIG.reg = WDT_TIMEOUT_REG;          // Set a 4s or 8s period for chip reset
45
 
45
 
46
-    WDT->CTRLA.reg = WDT_CTRLA_ENABLE;          // Start watchdog now in normal mode
47
-    SYNC(WDT->SYNCBUSY.bit.ENABLE);
48
-  }
46
+  HAL_watchdog_refresh();
47
+
48
+  WDT->CTRLA.reg = WDT_CTRLA_ENABLE;          // Start watchdog now in normal mode
49
+  SYNC(WDT->SYNCBUSY.bit.ENABLE);
50
+}
49
 
51
 
50
 #endif // USE_WATCHDOG
52
 #endif // USE_WATCHDOG
51
 
53
 

+ 17
- 14
Marlin/src/HAL/STM32/watchdog.cpp Переглянути файл

25
 
25
 
26
 #if ENABLED(USE_WATCHDOG)
26
 #if ENABLED(USE_WATCHDOG)
27
 
27
 
28
-  #include "../../inc/MarlinConfig.h"
28
+#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
29
 
29
 
30
-  #include "watchdog.h"
31
-  #include <IWatchdog.h>
30
+#include "../../inc/MarlinConfig.h"
32
 
31
 
33
-  void watchdog_init() {
34
-    #if DISABLED(DISABLE_WATCHDOG_INIT)
35
-      IWatchdog.begin(4000000); // 4 sec timeout
36
-    #endif
37
-  }
32
+#include "watchdog.h"
33
+#include <IWatchdog.h>
38
 
34
 
39
-  void HAL_watchdog_refresh() {
40
-    IWatchdog.reload();
41
-    #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
42
-      TOGGLE(LED_PIN);  // heartbeat indicator
43
-    #endif
44
-  }
35
+void watchdog_init() {
36
+  #if DISABLED(DISABLE_WATCHDOG_INIT)
37
+    IWatchdog.begin(WDT_TIMEOUT_US);
38
+  #endif
39
+}
40
+
41
+void HAL_watchdog_refresh() {
42
+  IWatchdog.reload();
43
+  #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
44
+    TOGGLE(LED_PIN);  // heartbeat indicator
45
+  #endif
46
+}
45
 
47
 
46
 #endif // USE_WATCHDOG
48
 #endif // USE_WATCHDOG
49
+
47
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
50
 #endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 7
- 0
Marlin/src/HAL/STM32F1/watchdog.cpp Переглянути файл

33
 #include <libmaple/iwdg.h>
33
 #include <libmaple/iwdg.h>
34
 #include "watchdog.h"
34
 #include "watchdog.h"
35
 
35
 
36
+/**
37
+ *  The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and
38
+ *  625 reload value (counts down to 0)
39
+ *  use 1250 for 8 seconds
40
+ */
41
+#define STM32F1_WD_RELOAD TERN(WATCHDOG_DURATION_8S, 1250, 625) // 4 or 8 second timeout
42
+
36
 void HAL_watchdog_refresh() {
43
 void HAL_watchdog_refresh() {
37
   #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
44
   #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
38
     TOGGLE(LED_PIN);  // heartbeat indicator
45
     TOGGLE(LED_PIN);  // heartbeat indicator

+ 0
- 7
Marlin/src/HAL/STM32F1/watchdog.h Переглянути файл

27
 
27
 
28
 #include <libmaple/iwdg.h>
28
 #include <libmaple/iwdg.h>
29
 
29
 
30
-/**
31
- *  The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and
32
- *  625 reload value (counts down to 0)
33
- *  use 1250 for 8 seconds
34
- */
35
-#define STM32F1_WD_RELOAD 625
36
-
37
 // Arduino STM32F1 core now has watchdog support
30
 // Arduino STM32F1 core now has watchdog support
38
 
31
 
39
 // Initialize watchdog with a 4 second countdown time
32
 // Initialize watchdog with a 4 second countdown time

+ 24
- 22
Marlin/src/HAL/STM32_F4_F7/watchdog.cpp Переглянути файл

25
 
25
 
26
 #if ENABLED(USE_WATCHDOG)
26
 #if ENABLED(USE_WATCHDOG)
27
 
27
 
28
-  #include "watchdog.h"
29
-
30
-  IWDG_HandleTypeDef hiwdg;
31
-
32
-  void watchdog_init() {
33
-    hiwdg.Instance = IWDG;
34
-    hiwdg.Init.Prescaler = IWDG_PRESCALER_32; //32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
35
-    hiwdg.Init.Reload = 4095;           //4095 counts = 4 seconds at 1024Hz
36
-    if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
37
-      //Error_Handler();
38
-    }
39
-    else {
40
-      #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
41
-        TOGGLE(LED_PIN);  // heartbeat indicator
42
-      #endif
43
-    }
28
+#include "watchdog.h"
29
+
30
+#define WDT_TIMEOUT_COUNT TERN(WATCHDOG_DURATION_8S, 8192, 4096) // 4 or 8 second timeout
31
+
32
+IWDG_HandleTypeDef hiwdg;
33
+
34
+void watchdog_init() {
35
+  hiwdg.Instance = IWDG;
36
+  hiwdg.Init.Prescaler = IWDG_PRESCALER_32; // 32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
37
+  hiwdg.Init.Reload = WDT_TIMEOUT_COUNT - 1;
38
+  if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
39
+    //Error_Handler();
40
+  }
41
+  else {
42
+    #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
43
+      TOGGLE(LED_PIN);  // heartbeat indicator
44
+    #endif
44
   }
45
   }
46
+}
45
 
47
 
46
-  void HAL_watchdog_refresh() {
47
-    /* Refresh IWDG: reload counter */
48
-    if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
49
-      /* Refresh Error */
50
-      //Error_Handler();
51
-    }
48
+void HAL_watchdog_refresh() {
49
+  /* Refresh IWDG: reload counter */
50
+  if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
51
+    /* Refresh Error */
52
+    //Error_Handler();
52
   }
53
   }
54
+}
53
 
55
 
54
 #endif // USE_WATCHDOG
56
 #endif // USE_WATCHDOG
55
 #endif // STM32GENERIC && (STM32F4 || STM32F7)
57
 #endif // STM32GENERIC && (STM32F4 || STM32F7)

+ 3
- 1
Marlin/src/HAL/TEENSY31_32/watchdog.cpp Переглянути файл

27
 
27
 
28
 #include "watchdog.h"
28
 #include "watchdog.h"
29
 
29
 
30
+#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
31
+
30
 void watchdog_init() {
32
 void watchdog_init() {
31
   WDOG_TOVALH = 0;
33
   WDOG_TOVALH = 0;
32
-  WDOG_TOVALL = 4000;
34
+  WDOG_TOVALL = WDT_TIMEOUT_MS;
33
   WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
35
   WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
34
 }
36
 }
35
 
37
 

+ 3
- 1
Marlin/src/HAL/TEENSY35_36/watchdog.cpp Переглянути файл

27
 
27
 
28
 #include "watchdog.h"
28
 #include "watchdog.h"
29
 
29
 
30
+#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
31
+
30
 void watchdog_init() {
32
 void watchdog_init() {
31
   WDOG_TOVALH = 0;
33
   WDOG_TOVALH = 0;
32
-  WDOG_TOVALL = 4000;
34
+  WDOG_TOVALL = WDT_TIMEOUT_MS;
33
   WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
35
   WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
34
 }
36
 }
35
 
37
 

+ 3
- 7
Marlin/src/HAL/TEENSY40_41/watchdog.cpp Переглянути файл

19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
  *
20
  *
21
  */
21
  */
22
+#ifdef __IMXRT1062__
22
 
23
 
23
 /**
24
 /**
24
  * HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
25
  * HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
25
  */
26
  */
26
 
27
 
27
-#ifdef __IMXRT1062__
28
-
29
 #include "../../inc/MarlinConfig.h"
28
 #include "../../inc/MarlinConfig.h"
30
 
29
 
31
 #if ENABLED(USE_WATCHDOG)
30
 #if ENABLED(USE_WATCHDOG)
32
 
31
 
33
 #include "watchdog.h"
32
 #include "watchdog.h"
34
 
33
 
35
-// 4 seconds timeout
36
-#define WDTO 4 //seconds
34
+#define WDT_TIMEOUT TERN(WATCHDOG_DURATION_8S, 8, 4) // 4 or 8 second timeout
37
 
35
 
38
-uint8_t timeoutval = (WDTO - 0.5f) / 0.5f;
36
+constexpr uint8_t timeoutval = (WDT_TIMEOUT - 0.5f) / 0.5f;
39
 
37
 
40
 void watchdog_init() {
38
 void watchdog_init() {
41
-
42
   CCM_CCGR3 |= CCM_CCGR3_WDOG1(3);  // enable WDOG1 clocks
39
   CCM_CCGR3 |= CCM_CCGR3_WDOG1(3);  // enable WDOG1 clocks
43
   WDOG1_WMCR = 0;                   // disable power down PDE
40
   WDOG1_WMCR = 0;                   // disable power down PDE
44
   WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
41
   WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
45
   WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
42
   WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
46
-
47
 }
43
 }
48
 
44
 
49
 void HAL_watchdog_refresh() {
45
 void HAL_watchdog_refresh() {

Завантаження…
Відмінити
Зберегти