From 4b31fe20df48507495e271ab4e6b44f238a54610 Mon Sep 17 00:00:00 2001 From: jfbblue0922 Date: Thu, 11 May 2023 16:06:28 +0900 Subject: [PATCH] AP_HAL_ChibiOS: support external watchdog gpio Co-authored-by: Randy Mackay optional support to toggle GPIO pin at 10hz --- libraries/AP_HAL_ChibiOS/Scheduler.cpp | 15 +++++++++++++++ libraries/AP_HAL_ChibiOS/Scheduler.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/Scheduler.cpp b/libraries/AP_HAL_ChibiOS/Scheduler.cpp index a30a1da492..99b1ad0e9b 100644 --- a/libraries/AP_HAL_ChibiOS/Scheduler.cpp +++ b/libraries/AP_HAL_ChibiOS/Scheduler.cpp @@ -764,8 +764,23 @@ void Scheduler::watchdog_pat(void) { stm32_watchdog_pat(); last_watchdog_pat_ms = AP_HAL::millis(); +#if defined(HAL_GPIO_PIN_EXT_WDOG) + ext_watchdog_pat(last_watchdog_pat_ms); +#endif } +#if defined(HAL_GPIO_PIN_EXT_WDOG) +// toggle the external watchdog gpio pin +void Scheduler::ext_watchdog_pat(uint32_t now_ms) +{ + // toggle watchdog GPIO every WDI_OUT_INTERVAL_TIME_MS + if ((now_ms - last_ext_watchdog_ms) >= EXT_WDOG_INTERVAL_MS) { + palToggleLine(HAL_GPIO_PIN_EXT_WDOG); + last_ext_watchdog_ms = now_ms; + } +} +#endif + #if CH_DBG_ENABLE_STACK_CHECK == TRUE /* check we have enough stack free on all threads and the ISR stack diff --git a/libraries/AP_HAL_ChibiOS/Scheduler.h b/libraries/AP_HAL_ChibiOS/Scheduler.h index 2a7187e86c..b46b26f7af 100644 --- a/libraries/AP_HAL_ChibiOS/Scheduler.h +++ b/libraries/AP_HAL_ChibiOS/Scheduler.h @@ -193,5 +193,11 @@ private: // check for free stack space void check_stack_free(void); + +#if defined(HAL_GPIO_PIN_EXT_WDOG) + // external watchdog GPIO support + void ext_watchdog_pat(uint32_t now_ms); + uint32_t last_ext_watchdog_ms; +#endif }; #endif