43 #if NRFX_CHECK(NRFX_WDT_ENABLED)
46 #define NRFX_LOG_MODULE WDT
50 static nrfx_drv_state_t m_state;
53 static uint8_t m_alloc_index;
55 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
57 static nrfx_wdt_event_handler_t m_wdt_event_handler;
60 void nrfx_wdt_irq_handler(
void)
62 if (nrf_wdt_event_check(NRF_WDT_EVENT_TIMEOUT))
64 m_wdt_event_handler();
65 nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT);
71 nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t
const * p_config,
72 nrfx_wdt_event_handler_t wdt_event_handler)
74 NRFX_ASSERT(p_config);
77 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
78 NRFX_ASSERT(wdt_event_handler != NULL);
79 m_wdt_event_handler = wdt_event_handler;
81 NRFX_ASSERT(wdt_event_handler == NULL);
82 (void)wdt_event_handler;
84 if (m_state == NRFX_DRV_STATE_UNINITIALIZED)
86 m_state = NRFX_DRV_STATE_INITIALIZED;
90 err_code = NRFX_ERROR_INVALID_STATE;
91 NRFX_LOG_WARNING(
"Function: %s, error code: %s.",
93 NRFX_LOG_ERROR_STRING_GET(err_code));
96 if((((uint64_t) p_config->reload_value * 32768) / 1000) >
99 return NRF_ERROR_INVALID_PARAM;
101 nrf_wdt_behaviour_set(p_config->behaviour);
103 nrf_wdt_reload_value_set(((uint64_t) p_config->reload_value * 32768) / 1000);
105 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
106 NRFX_IRQ_PRIORITY_SET(WDT_IRQn, p_config->interrupt_priority);
107 NRFX_IRQ_ENABLE(WDT_IRQn);
110 err_code = NRFX_SUCCESS;
111 NRFX_LOG_INFO(
"Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code));
116 void nrfx_wdt_enable(
void)
118 NRFX_ASSERT(m_alloc_index != 0);
119 NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED);
120 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
121 nrf_wdt_int_enable(NRF_WDT_INT_TIMEOUT_MASK);
123 nrf_wdt_task_trigger(NRF_WDT_TASK_START);
124 m_state = NRFX_DRV_STATE_POWERED_ON;
125 NRFX_LOG_INFO(
"Enabled.");
129 void nrfx_wdt_feed(
void)
131 NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON);
132 for (uint8_t i = 0; i < m_alloc_index; i++)
134 nrf_wdt_reload_request_set((nrf_wdt_rr_register_t)(NRF_WDT_RR0 + i));
138 nrfx_err_t nrfx_wdt_channel_alloc(nrfx_wdt_channel_id * p_channel_id)
141 NRFX_ASSERT(p_channel_id);
142 NRFX_ASSERT(m_state == NRFX_DRV_STATE_INITIALIZED);
144 NRFX_CRITICAL_SECTION_ENTER();
145 if (m_alloc_index < NRF_WDT_CHANNEL_NUMBER)
147 *p_channel_id = (nrfx_wdt_channel_id)(NRF_WDT_RR0 + m_alloc_index);
149 nrf_wdt_reload_request_enable(*p_channel_id);
150 result = NRFX_SUCCESS;
154 result = NRFX_ERROR_NO_MEM;
156 NRFX_CRITICAL_SECTION_EXIT();
157 NRFX_LOG_INFO(
"Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(result));
161 void nrfx_wdt_channel_feed(nrfx_wdt_channel_id channel_id)
163 NRFX_ASSERT(m_state == NRFX_DRV_STATE_POWERED_ON);
164 nrf_wdt_reload_request_set(channel_id);