Skip to content

Commit

Permalink
[nrf fromlist] drivers: watchdog: nrfx wdt without IRQs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lstnl authored and rlubos committed Aug 6, 2024
1 parent 64796d7 commit 766b306
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
7 changes: 7 additions & 0 deletions drivers/watchdog/Kconfig.nrfx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ config WDT_NRFX

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.
78 changes: 41 additions & 37 deletions drivers/watchdog/wdt_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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;
}
Expand Down Expand Up @@ -155,6 +156,7 @@ static const struct wdt_driver_api wdt_nrfx_driver_api = {
.feed = wdt_nrf_feed,
};

#if !defined(CONFIG_WDT_NRFX_NO_IRQ)
static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_type,
uint32_t requests, void *p_context)
{
Expand All @@ -172,45 +174,47 @@ static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_ty
requests &= ~BIT(i);
}
}
#endif

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

#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, \
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); \
err_code = nrfx_wdt_init(&config->wdt, \
NULL, \
wdt_##idx##_event_handler, \
NULL); \
if (err_code != NRFX_SUCCESS) { \
return -EBUSY; \
} \
return 0; \
} \
static struct wdt_nrfx_data wdt_##idx##_data = { \
.m_timeout = 0, \
.m_allocated_channels = 0, \
}; \
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
.wdt = NRFX_WDT_INSTANCE(idx), \
}; \
DEVICE_DT_DEFINE(WDT(idx), \
wdt_##idx##_init, \
NULL, \
&wdt_##idx##_data, \
&wdt_##idx##z_config, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
#define WDT_NRFX_WDT_DEVICE(idx) \
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), ( \
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, \
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; \
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), ( \
IRQ_CONNECT(DT_IRQN(WDT(idx)), DT_IRQ(WDT(idx), \
priority), nrfx_isr, nrfx_wdt_##idx##_irq_handler, 0);), ()) \
err_code = nrfx_wdt_init(&config->wdt, \
NULL, \
COND_CODE_0(IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ), \
(wdt_##idx##_event_handler,), (NULL,)) \
NULL); \
if (err_code != NRFX_SUCCESS) { \
return -EBUSY; \
} \
return 0; \
} \
static struct wdt_nrfx_data wdt_##idx##_data; \
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
.wdt = NRFX_WDT_INSTANCE(idx), \
}; \
DEVICE_DT_DEFINE(WDT(idx), \
wdt_##idx##_init, \
NULL, \
&wdt_##idx##_data, \
&wdt_##idx##z_config, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&wdt_nrfx_driver_api)

#ifdef CONFIG_HAS_HW_NRF_WDT0
Expand Down
3 changes: 3 additions & 0 deletions modules/hal_nordic/nrfx/nrfx_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,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
Expand Down

0 comments on commit 766b306

Please sign in to comment.