Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions drivers/watchdog/wdt_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/sys/math_extras.h>
#include <nrfx_wdt.h>
#include <zephyr/drivers/watchdog.h>
Expand All @@ -13,11 +14,18 @@
#include <zephyr/irq.h>
LOG_MODULE_REGISTER(wdt_nrfx);

#if !CONFIG_WDT_NRFX_NO_IRQ && NRF_WDT_HAS_STOP
#define WDT_NRFX_SYNC_STOP 1
#endif

struct wdt_nrfx_data {
wdt_callback_t m_callbacks[NRF_WDT_CHANNEL_NUMBER];
uint32_t m_timeout;
uint8_t m_allocated_channels;
bool enabled;
#if defined(WDT_NRFX_SYNC_STOP)
struct k_sem sync_stop;
#endif
};

struct wdt_nrfx_config {
Expand Down Expand Up @@ -73,6 +81,10 @@
return -EFAULT;
}

#if defined(WDT_NRFX_SYNC_STOP)
k_sem_take(&data->sync_stop, K_FOREVER);
#endif

nrfx_wdt_channels_free(&config->wdt);

for (channel_id = 0; channel_id < data->m_allocated_channels; channel_id++) {
Expand Down Expand Up @@ -170,11 +182,17 @@
static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_type,
uint32_t requests, void *p_context)
{
struct wdt_nrfx_data *data = dev->data;

#if defined(WDT_NRFX_SYNC_STOP)
if (event_type == NRF_WDT_EVENT_STOPPED) {
k_sem_give(&data->sync_stop);
}
#else
(void)event_type;
#endif
(void)p_context;

struct wdt_nrfx_data *data = dev->data;

while (requests) {
uint8_t i = u32_count_trailing_zeros(requests);

Expand Down Expand Up @@ -217,7 +235,11 @@
} \
return 0; \
} \
static struct wdt_nrfx_data wdt_##idx##_data; \
static struct wdt_nrfx_data wdt_##idx##_data = { \
IF_ENABLED(WDT_NRFX_SYNC_STOP, \
(.sync_stop = Z_SEM_INITIALIZER( \
wdt_##idx##_data.sync_stop, 0, 1),)) \
}; \
static const struct wdt_nrfx_config wdt_##idx##z_config = { \
.wdt = NRFX_WDT_INSTANCE(idx), \
}; \
Expand All @@ -228,7 +250,7 @@
&wdt_##idx##z_config, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&wdt_nrfx_driver_api)

Check notice on line 253 in drivers/watchdog/wdt_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/watchdog/wdt_nrfx.c:253 -#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; \ - WDT_NRFX_WDT_IRQ(idx); \ - err_code = nrfx_wdt_init(&config->wdt, \ - NULL, \ - IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) \ - ? NULL \ - : wdt_##idx##_event_handler, \ - NULL); \ - if (err_code != NRFX_SUCCESS) { \ - return -EBUSY; \ - } \ - return 0; \ - } \ - static struct wdt_nrfx_data wdt_##idx##_data = { \ - IF_ENABLED(WDT_NRFX_SYNC_STOP, \ - (.sync_stop = Z_SEM_INITIALIZER( \ - wdt_##idx##_data.sync_stop, 0, 1),)) \ - }; \ - 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) +#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; \ + WDT_NRFX_WDT_IRQ(idx); \ + err_code = nrfx_wdt_init( \ + &config->wdt, NULL, \ + IS_ENABLED(CONFIG_WDT_NRFX_NO_IRQ) ? NULL : wdt_##idx##_event_handler, \ + NULL); \ + if (err_code != NRFX_SUCCESS) { \ + return -EBUSY; \ + } \ + return 0; \ + } \ + static struct wdt_nrfx_data wdt_##idx##_data = { \ + IF_ENABLED(WDT_NRFX_SYNC_STOP, \ + (.sync_stop = Z_SEM_INITIALIZER(wdt_##idx##_data.sync_stop, 0, 1), ))}; \ + 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,
#ifdef CONFIG_HAS_HW_NRF_WDT0
WDT_NRFX_WDT_DEVICE(0);
#endif
Expand Down
Loading