| 
4 | 4 |  * SPDX-License-Identifier: Apache-2.0  | 
5 | 5 |  */  | 
6 | 6 | 
 
  | 
 | 7 | +#include <zephyr/kernel.h>  | 
7 | 8 | #include <zephyr/sys/math_extras.h>  | 
8 | 9 | #include <nrfx_wdt.h>  | 
9 | 10 | #include <zephyr/drivers/watchdog.h>  | 
 | 
13 | 14 | #include <zephyr/irq.h>  | 
14 | 15 | LOG_MODULE_REGISTER(wdt_nrfx);  | 
15 | 16 | 
 
  | 
 | 17 | +#if !CONFIG_WDT_NRFX_NO_IRQ && NRF_WDT_HAS_STOP  | 
 | 18 | +#define WDT_NRFX_SYNC_STOP 1  | 
 | 19 | +#endif  | 
 | 20 | + | 
16 | 21 | struct wdt_nrfx_data {  | 
17 | 22 | 	wdt_callback_t m_callbacks[NRF_WDT_CHANNEL_NUMBER];  | 
18 | 23 | 	uint32_t m_timeout;  | 
19 | 24 | 	uint8_t m_allocated_channels;  | 
20 | 25 | 	bool enabled;  | 
 | 26 | +#if defined(WDT_NRFX_SYNC_STOP)  | 
 | 27 | +	struct k_sem sync_stop;  | 
 | 28 | +#endif  | 
21 | 29 | };  | 
22 | 30 | 
 
  | 
23 | 31 | struct wdt_nrfx_config {  | 
@@ -73,6 +81,10 @@ static int wdt_nrf_disable(const struct device *dev)  | 
73 | 81 | 		return -EFAULT;  | 
74 | 82 | 	}  | 
75 | 83 | 
 
  | 
 | 84 | +#if defined(WDT_NRFX_SYNC_STOP)  | 
 | 85 | +	k_sem_take(&data->sync_stop, K_FOREVER);  | 
 | 86 | +#endif  | 
 | 87 | + | 
76 | 88 | 	nrfx_wdt_channels_free(&config->wdt);  | 
77 | 89 | 
 
  | 
78 | 90 | 	for (channel_id = 0; channel_id < data->m_allocated_channels; channel_id++) {  | 
@@ -170,11 +182,17 @@ static const struct wdt_driver_api wdt_nrfx_driver_api = {  | 
170 | 182 | static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_type,  | 
171 | 183 | 			      uint32_t requests, void *p_context)  | 
172 | 184 | {  | 
 | 185 | +	struct wdt_nrfx_data *data = dev->data;  | 
 | 186 | + | 
 | 187 | +#if defined(WDT_NRFX_SYNC_STOP)  | 
 | 188 | +	if (event_type == NRF_WDT_EVENT_STOPPED) {  | 
 | 189 | +		k_sem_give(&data->sync_stop);  | 
 | 190 | +	}  | 
 | 191 | +#else  | 
173 | 192 | 	(void)event_type;  | 
 | 193 | +#endif  | 
174 | 194 | 	(void)p_context;  | 
175 | 195 | 
 
  | 
176 |  | -	struct wdt_nrfx_data *data = dev->data;  | 
177 |  | - | 
178 | 196 | 	while (requests) {  | 
179 | 197 | 		uint8_t i = u32_count_trailing_zeros(requests);  | 
180 | 198 | 
 
  | 
@@ -217,7 +235,11 @@ static void wdt_event_handler(const struct device *dev, nrf_wdt_event_t event_ty  | 
217 | 235 | 		}							       \  | 
218 | 236 | 		return 0;						       \  | 
219 | 237 | 	}								       \  | 
220 |  | -	static struct wdt_nrfx_data wdt_##idx##_data;			       \  | 
 | 238 | +	static struct wdt_nrfx_data wdt_##idx##_data =	{		       \  | 
 | 239 | +		IF_ENABLED(WDT_NRFX_SYNC_STOP,				       \  | 
 | 240 | +			(.sync_stop = Z_SEM_INITIALIZER(		       \  | 
 | 241 | +				wdt_##idx##_data.sync_stop, 0, 1),))	       \  | 
 | 242 | +	};								       \  | 
221 | 243 | 	static const struct wdt_nrfx_config wdt_##idx##z_config = {	       \  | 
222 | 244 | 		.wdt = NRFX_WDT_INSTANCE(idx),				       \  | 
223 | 245 | 	};								       \  | 
 | 
0 commit comments