From 83e3c2eb782fb843d502f13f18342a645ee13c62 Mon Sep 17 00:00:00 2001 From: Lukasz Stepnicki Date: Mon, 22 Jul 2024 16:31:16 +0200 Subject: [PATCH] drivers: watchdog: nrfx wdt without IRQs Add config option to build nrfx wdt driver with NRFX_WDT_CONFIG_NO_IRQ enabled. Signed-off-by: Lukasz Stepnicki --- drivers/watchdog/Kconfig.nrfx | 7 ++++++- drivers/watchdog/wdt_nrfx.c | 18 +++++++++++++----- modules/hal_nordic/nrfx/nrfx_config.h | 3 +++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/Kconfig.nrfx b/drivers/watchdog/Kconfig.nrfx index 61f42d8ff31..d4deeda225c 100644 --- a/drivers/watchdog/Kconfig.nrfx +++ b/drivers/watchdog/Kconfig.nrfx @@ -16,6 +16,11 @@ config WDT_NRFX select NRFX_WDT130 if HAS_HW_NRF_WDT130 select NRFX_WDT131 if HAS_HW_NRF_WDT131 select NRFX_WDT132 if HAS_HW_NRF_WDT132 - help Enable support for nrfx WDT driver for nRF MCU series. + +config WDT_NRFX_NO_IRQ + bool "nRF WDT nrfx driver without IRQ enabled" + depends on WDT_NRFX + help + Disable use of WDT interrupt in driver. diff --git a/drivers/watchdog/wdt_nrfx.c b/drivers/watchdog/wdt_nrfx.c index 59de306f986..277d195f681 100644 --- a/drivers/watchdog/wdt_nrfx.c +++ b/drivers/watchdog/wdt_nrfx.c @@ -114,7 +114,8 @@ static int wdt_nrf_install_timeout(const struct device *dev, * the timeout) from range 0xF-0xFFFFFFFF given in 32768 Hz * clock ticks. This makes the allowed range of 0x1-0x07CFFFFF * in milliseconds. Check if the provided value is within - * this range. */ + * this range. + */ if ((cfg->window.max == 0U) || (cfg->window.max > 0x07CFFFFF)) { return -EINVAL; } @@ -186,23 +187,30 @@ static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_ty #define WDT(idx) DT_NODELABEL(wdt##idx) +#define WDT_NRFX_WDT_IRQ(idx) \ + COND_CODE_1(CONFIG_WDT_NRFX_NO_IRQ, \ + (), \ + (IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), priority), \ + nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0))) + #define WDT_NRFX_WDT_DEVICE(idx) \ static void wdt_##idx##_event_handler(nrf_wdt_event_t event_type, \ uint32_t requests, \ void *p_context) \ { \ - wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \ + wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \ requests, p_context); \ } \ static int wdt_##idx##_init(const struct device *dev) \ { \ const struct wdt_nrfx_config *config = dev->config; \ nrfx_err_t err_code; \ - IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), priority), \ - nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0); \ + WDT_NRFX_WDT_IRQ(idx); \ err_code = nrfx_wdt_init(&config->wdt, \ NULL, \ - wdt_##idx##_event_handler, \ + IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) \ + ? NULL \ + : wdt_##idx##_event_handler, \ NULL); \ if (err_code != NRFX_SUCCESS) { \ return -EBUSY; \ diff --git a/modules/hal_nordic/nrfx/nrfx_config.h b/modules/hal_nordic/nrfx/nrfx_config.h index 4b3979ff463..62770e9f698 100644 --- a/modules/hal_nordic/nrfx/nrfx_config.h +++ b/modules/hal_nordic/nrfx/nrfx_config.h @@ -835,6 +835,9 @@ #ifdef CONFIG_NRFX_WDT #define NRFX_WDT_ENABLED 1 #endif +#ifdef CONFIG_WDT_NRFX_NO_IRQ +#define NRFX_WDT_CONFIG_NO_IRQ 1 +#endif #ifdef CONFIG_NRFX_WDT_LOG #define NRFX_WDT_CONFIG_LOG_ENABLED 1 #endif