Watchdog cleanup (#15283)

This commit is contained in:
Scott Lahteine
2019-09-29 17:57:29 -05:00
committed by GitHub
parent 24706aedbd
commit 139b7196a0
28 changed files with 73 additions and 97 deletions

View File

@ -24,3 +24,9 @@
#include "platforms.h"
#include HAL_PATH(.,HAL.h)
inline void watchdog_refresh() {
#if ENABLED(USE_WATCHDOG)
HAL_watchdog_refresh();
#endif
}

View File

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

View File

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

View File

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

View File

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

View File

@ -29,18 +29,8 @@
#include "watchdog.h"
void watchdog_init() {}
void HAL_watchdog_refresh() {}
void HAL_clear_reset_source() {}
uint8_t HAL_get_reset_source() {
return RST_POWER_ON;
}
void watchdog_reset() {}
#else
void HAL_clear_reset_source() {}
uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
#endif // USE_WATCHDOG
#endif
#endif // __PLAT_LINUX__

View File

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

View File

@ -26,6 +26,10 @@
#include "../shared/Delay.h"
#include "../../../gcode/parser.h"
#if ENABLED(USE_WATCHDOG)
#include "watchdog.h"
#endif
// U8glib required functions
extern "C" void u8g_xMicroDelay(uint16_t val) {
DELAY_US(val);
@ -65,4 +69,17 @@ void flashFirmware(int16_t value) {
NVIC_SystemReset();
}
void HAL_clear_reset_source(void) {
#if ENABLED(USE_WATCHDOG)
watchdog_clear_timeout_flag();
#endif
}
uint8_t HAL_get_reset_source(void) {
#if ENABLED(USE_WATCHDOG)
if (watchdog_timed_out()) return RST_WATCHDOG;
#endif
return RST_POWER_ON;
}
#endif // TARGET_LPC1768

View File

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

View File

@ -56,28 +56,16 @@ void watchdog_init() {
WDT_Start(WDT_TIMEOUT);
}
void HAL_clear_reset_source() {
WDT_ClrTimeOutFlag();
}
uint8_t HAL_get_reset_source() {
if (TEST(WDT_ReadTimeOutFlag(), 0)) return RST_WATCHDOG;
return RST_POWER_ON;
}
void watchdog_reset() {
void HAL_watchdog_refresh() {
WDT_Feed();
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heartbeat indicator
#endif
}
#else
void watchdog_init() {}
void watchdog_reset() {}
void HAL_clear_reset_source() {}
uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
// Timeout state
bool watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
void watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
#endif // USE_WATCHDOG

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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