Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: watchdog: nrfx: add synchronization after stop #83776

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

mstasiaknordic
Copy link
Contributor

@mstasiaknordic mstasiaknordic commented Jan 10, 2025

In order to ensure that watchdog channels are freed in proper driver state, synchronization in form of semaphore needs to be added after stopping. In no irq variant, it is already done on nrfx level. NRFY function can be replaced by NRFX one in the future.

@@ -73,6 +73,12 @@ static int wdt_nrf_disable(const struct device *dev)
return -EFAULT;
}

#if !CONFIG_WDT_NRFX_NO_IRQ
while (!nrfy_wdt_events_process(config->wdt.p_reg,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if CONFIG_WDT_NRFX_NO_IRQ is not set (default setting), nrfx WDT IRQ handler is installed and will execute once NRF_WDT_EVENT_STOPPED. NRF_WDT_EVENT_STOPPED will be cleared in IRQ context, so this busy loop might execute forever.

Instead of polling event, k_sem_take should be called here. Corresponding k_sem_give should be executed in wdt_event_handler upon reception on NRF_WDT_EVENT_STOPPED.

Also, not all nRF devices can stop WDT so this extra code in wdt_event_handler needs to be enclosed in #if NRFX_WDT_HAS_STOP

@nika-nordic
Copy link
Collaborator

@mstasiaknordic could you add Kconfig option to set CONFIG_WDT_NRFX_NO_IRQ? and ideally some WDT twister test variant to verify such configuration

@mstasiaknordic
Copy link
Contributor Author

@mstasiaknordic could you add Kconfig option to set CONFIG_WDT_NRFX_NO_IRQ? and ideally some WDT twister test variant to verify such configuration

Such Kconfig option already exists.

From what I see, all existing watchdog tests use callbacks, thus none of them would work with CONFIG_WDT_NRFX_NO_IRQ=y regardless of this PR.

nika-nordic
nika-nordic previously approved these changes Jan 13, 2025
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 stop_sync;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe sync_stop would be better? stop_sync could mean that it stops synchronizing, which is not true

In order to ensure that watchdog channels are freed in proper
driver state, synchronization in form of simple loop needs
to be added after stopping. In no irq variant, it is already done
on nrfx level. NRFY function can be replaced by NRFX one in
the future.

Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
@kartben kartben merged commit b578ffa into zephyrproject-rtos:main Jan 14, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants