From 6548dd4a56902a088f0798ec3f3ff1411a06245d Mon Sep 17 00:00:00 2001 From: cinsights Date: Thu, 15 Apr 2021 13:30:03 +0000 Subject: [PATCH] RP WDGv1 WIP git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14192 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.c | 15 ++++++--------- os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.h | 8 +++++++- os/hal/ports/RP/RP2040/rp_registry.h | 4 ++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.c b/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.c index 3bbcb84b6..b3c3dff22 100644 --- a/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.c +++ b/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.c @@ -63,6 +63,9 @@ void wdg_lld_init(void) { WDGD1.state = WDG_STOP; WDGD1.wdg = WATCHDOG; +#if WDG_HAS_STORAGE + WDGD1.scratch = SCRATCH; +#endif WDGD1.wdg->CRTL &= ~WATCHDOG_CTRL_ENABLE; } @@ -77,21 +80,15 @@ void wdg_lld_start(WDGDriver *wdgp) { /* Set the time. */ uint32_t time = wdgp->wdg->config.rlr; - if (time == 0U) { - time = 50; - } - /* Due to a silicon bug (see errata RP2040-E1) WDG counts down on each edge. */ - time = (time == 0U) ? (50 * 2 * 1000) : (time * 2 * 1000); + /* Due to a silicon bug (see errata RP2040-E1) WDG counts down at each edge. */ + time = ((time == 0U) ? 50 : time) * 2 * 1000; /* Set ceiling if greater than count capability. */ if (time > WATCHDOG_CTRL_TIME) { time = WATCHDOG_CTRL_TIME; } - /* Save the reload count. */ - wdgp->wdg->rlr = time; - /* Set the initial interval, state, control bits and enable WDG. */ wdgp->wdg->LOAD = time; wdgp->state = WDG_READY; @@ -122,7 +119,7 @@ void wdg_lld_stop(WDGDriver *wdgp) { */ void wdg_lld_reset(WDGDriver * wdgp) { - wdgp->wdg->LOAD = wdgp->rlr; + wdgp->wdg->LOAD = wdgp->wdg->config.rlr; } #endif /* HAL_USE_WDG */ diff --git a/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.h b/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.h index 7dea8b603..5ba0f8578 100644 --- a/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.h +++ b/os/hal/ports/RP/LLD/WDGv1/hal_wdg_lld.h @@ -94,7 +94,13 @@ struct WDGDriver { /** * @brief Pointer to the WATCHDOG registers block. */ - WATCHDOG_TypeDef *wdg; + WATCHDOG_TypeDef *wdg; + /** + * @brief Pointer to the WATCHDOG scratch storage. + */ +#if WDG_HAS_STORAGE + uint8_t *scratch; +#endif }; /*===========================================================================*/ diff --git a/os/hal/ports/RP/RP2040/rp_registry.h b/os/hal/ports/RP/RP2040/rp_registry.h index 7995f033e..1cf96f73e 100644 --- a/os/hal/ports/RP/RP2040/rp_registry.h +++ b/os/hal/ports/RP/RP2040/rp_registry.h @@ -52,6 +52,10 @@ /* RTC attributes.*/ #define RP_HAS_RTC TRUE +/* WDG attributes.*/ +#define RP_HAS_WDG TRUE +#define RP_WDG_STORAGE_SIZE 32U + /** @} */ #endif /* RP_REGISTRY_H */