Skip to content

Commit 766b306

Browse files
lstnlrlubos
authored andcommitted
[nrf fromlist] 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 <[email protected]> Upstream PR: zephyrproject-rtos/zephyr#76174
1 parent 64796d7 commit 766b306

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

drivers/watchdog/Kconfig.nrfx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ config WDT_NRFX
1919

2020
help
2121
Enable support for nrfx WDT driver for nRF MCU series.
22+
23+
config WDT_NRFX_NO_IRQ
24+
bool "nRF WDT nrfx driver without IRQ enabled"
25+
depends on WDT_NRFX
26+
27+
help
28+
Disable use of WDT interrupt in driver.

drivers/watchdog/wdt_nrfx.c

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ static int wdt_nrf_install_timeout(const struct device *dev,
107107
* the timeout) from range 0xF-0xFFFFFFFF given in 32768 Hz
108108
* clock ticks. This makes the allowed range of 0x1-0x07CFFFFF
109109
* in milliseconds. Check if the provided value is within
110-
* this range. */
110+
* this range.
111+
*/
111112
if ((cfg->window.max == 0U) || (cfg->window.max > 0x07CFFFFF)) {
112113
return -EINVAL;
113114
}
@@ -155,6 +156,7 @@ static const struct wdt_driver_api wdt_nrfx_driver_api = {
155156
.feed = wdt_nrf_feed,
156157
};
157158

159+
#if !defined(CONFIG_WDT_NRFX_NO_IRQ)
158160
static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_type,
159161
uint32_t requests, void *p_context)
160162
{
@@ -172,45 +174,47 @@ static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_ty
172174
requests &= ~BIT(i);
173175
}
174176
}
177+
#endif
175178

176179
#define WDT(idx) DT_NODELABEL(wdt##idx)
177180

178-
#define WDT_NRFX_WDT_DEVICE(idx) \
179-
static void wdt_##idx##_event_handler(nrf_wdt_event_t event_type, \
180-
uint32_t requests, \
181-
void *p_context) \
182-
{ \
183-
wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \
184-
requests, p_context); \
185-
} \
186-
static int wdt_##idx##_init(const struct device *dev) \
187-
{ \
188-
const struct wdt_nrfx_config *config = dev->config; \
189-
nrfx_err_t err_code; \
190-
IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), priority), \
191-
nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0); \
192-
err_code = nrfx_wdt_init(&config->wdt, \
193-
NULL, \
194-
wdt_##idx##_event_handler, \
195-
NULL); \
196-
if (err_code != NRFX_SUCCESS) { \
197-
return -EBUSY; \
198-
} \
199-
return 0; \
200-
} \
201-
static struct wdt_nrfx_data wdt_##idx##_data = { \
202-
.m_timeout = 0, \
203-
.m_allocated_channels = 0, \
204-
}; \
205-
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
206-
.wdt = NRFX_WDT_INSTANCE(idx), \
207-
}; \
208-
DEVICE_DT_DEFINE(WDT(idx), \
209-
wdt_##idx##_init, \
210-
NULL, \
211-
&wdt_##idx##_data, \
212-
&wdt_##idx##z_config, \
213-
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
181+
#define WDT_NRFX_WDT_DEVICE(idx) \
182+
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), ( \
183+
static void wdt_##idx##_event_handler(nrf_wdt_event_t event_type, \
184+
uint32_t requests, \
185+
void *p_context) \
186+
{ \
187+
wdt_event_handler(DEVICE_DT_GET(WDT(idx)), event_type, \
188+
requests, p_context); \
189+
} \
190+
), ()) \
191+
static int wdt_##idx##_init(const struct device *dev) \
192+
{ \
193+
const struct wdt_nrfx_config *config = dev->config; \
194+
nrfx_err_t err_code; \
195+
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), ( \
196+
IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), \
197+
priority), nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0);), ()) \
198+
err_code = nrfx_wdt_init(&config->wdt, \
199+
NULL, \
200+
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), \
201+
(wdt_##idx##_event_handler,), (NULL,)) \
202+
NULL); \
203+
if (err_code != NRFX_SUCCESS) { \
204+
return -EBUSY; \
205+
} \
206+
return 0; \
207+
} \
208+
static struct wdt_nrfx_data wdt_##idx##_data; \
209+
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
210+
.wdt = NRFX_WDT_INSTANCE(idx), \
211+
}; \
212+
DEVICE_DT_DEFINE(WDT(idx), \
213+
wdt_##idx##_init, \
214+
NULL, \
215+
&wdt_##idx##_data, \
216+
&wdt_##idx##z_config, \
217+
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
214218
&wdt_nrfx_driver_api)
215219

216220
#ifdef CONFIG_HAS_HW_NRF_WDT0

modules/hal_nordic/nrfx/nrfx_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@
813813
#ifdef CONFIG_NRFX_WDT
814814
#define NRFX_WDT_ENABLED 1
815815
#endif
816+
#ifdef CONFIG_WDT_NRFX_NO_IRQ
817+
#define NRFX_WDT_CONFIG_NO_IRQ 1
818+
#endif
816819
#ifdef CONFIG_NRFX_WDT_LOG
817820
#define NRFX_WDT_CONFIG_LOG_ENABLED 1
818821
#endif

0 commit comments

Comments
 (0)