xref: /nrf52832-nimble/nordic/nrfx/drivers/include/nrfx_wdt.h (revision 150812a83cab50279bd772ef6db1bfaf255f2c5b)
1 /*
2  * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *    list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  *    contributors may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef NRFX_WDT_H__
33 #define NRFX_WDT_H__
34 
35 #include <nrfx.h>
36 #include <hal/nrf_wdt.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * @defgroup nrfx_wdt WDT driver
44  * @{
45  * @ingroup nrf_wdt
46  * @brief   Watchdog Timer (WDT) peripheral driver.
47  */
48 
49 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) || defined(__NRFX_DOXYGEN__)
50 /**
51  * @brief WDT instance interrupt priority configuration.
52  */
53     #define NRFX_WDT_IRQ_CONFIG .interrupt_priority = NRFX_WDT_CONFIG_IRQ_PRIORITY
54 #else
55     #define NRFX_WDT_IRQ_CONFIG
56 #endif
57 
58 /**@brief Struct for WDT initialization. */
59 typedef struct
60 {
61     nrf_wdt_behaviour_t    behaviour;          /**< WDT behaviour when CPU in sleep/halt mode. */
62     uint32_t               reload_value;       /**< WDT reload value in ms. */
63 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ) || defined(__NRFX_DOXYGEN__)
64     uint8_t                interrupt_priority; /**< WDT interrupt priority */
65 #endif
66 } nrfx_wdt_config_t;
67 
68 /**@brief WDT event handler function type. */
69 typedef void (*nrfx_wdt_event_handler_t)(void);
70 
71 /**@brief WDT channel id type. */
72 typedef nrf_wdt_rr_register_t nrfx_wdt_channel_id;
73 
74 #define NRFX_WDT_DEAFULT_CONFIG                                               \
75     {                                                                         \
76         .behaviour          = (nrf_wdt_behaviour_t)NRFX_WDT_CONFIG_BEHAVIOUR, \
77         .reload_value       = NRFX_WDT_CONFIG_RELOAD_VALUE,                   \
78         NRFX_WDT_IRQ_CONFIG                                                   \
79     }
80 /**
81  * @brief This function initializes watchdog.
82  *
83  * @param[in] p_config          Pointer to the structure with initial configuration.
84  * @param[in] wdt_event_handler Event handler provided by the user. Ignored when
85  *                              @ref NRFX_WDT_CONFIG_NO_IRQ option is enabled.
86  *
87  * @return    NRFX_SUCCESS on success, otherwise an error code.
88  */
89 nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,
90                          nrfx_wdt_event_handler_t  wdt_event_handler);
91 
92 /**
93  * @brief This function allocate watchdog channel.
94  *
95  * @note This function can not be called after nrfx_wdt_start(void).
96  *
97  * @param[out] p_channel_id      ID of granted channel.
98  *
99  * @return    NRFX_SUCCESS on success, otherwise an error code.
100  */
101 nrfx_err_t nrfx_wdt_channel_alloc(nrfx_wdt_channel_id * p_channel_id);
102 
103 /**
104  * @brief This function starts watchdog.
105  *
106  * @note After calling this function the watchdog is started, so the user needs to feed all allocated
107  *       watchdog channels to avoid reset. At least one watchdog channel has to be allocated.
108  */
109 void nrfx_wdt_enable(void);
110 
111 /**
112  * @brief This function feeds the watchdog.
113  *
114  * @details Function feeds all allocated watchdog channels.
115  */
116 void nrfx_wdt_feed(void);
117 
118 /**
119  * @brief This function feeds the invidual watchdog channel.
120  *
121  * @param[in] channel_id      ID of watchdog channel.
122  */
123 void nrfx_wdt_channel_feed(nrfx_wdt_channel_id channel_id);
124 
125 /**@brief Function for returning a requested task address for the wdt driver module.
126  *
127  * @param[in]  task                One of the peripheral tasks.
128  *
129  * @retval     Task address.
130  */
nrfx_wdt_ppi_task_addr(nrf_wdt_task_t task)131 __STATIC_INLINE uint32_t nrfx_wdt_ppi_task_addr(nrf_wdt_task_t task)
132 {
133     return nrf_wdt_task_address_get(task);
134 }
135 
136 /**@brief Function for returning a requested event address for the wdt driver module.
137  *
138  * @param[in]  event               One of the peripheral events.
139  *
140  * @retval     Event address
141  */
nrfx_wdt_ppi_event_addr(nrf_wdt_event_t event)142 __STATIC_INLINE uint32_t nrfx_wdt_ppi_event_addr(nrf_wdt_event_t event)
143 {
144     return nrf_wdt_event_address_get(event);
145 }
146 
147 
148 #if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
149 void nrfx_wdt_irq_handler(void);
150 #endif
151 
152 
153 /** @} */
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif
160 
161