gr55xx_hal_wdt.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_wdt.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of WDT HAL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_WDT WDT
47 * @brief WDT HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_WDT_H__
53 #define __GR55xx_HAL_WDT_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_wdt.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_WDT_STRUCTURES Structures
65 * @{
66 */
67
68 /** @defgroup WDT_Configuration WDT Configuration
69 * @{
70 */
71
72 /**
73 * @brief WDT init structure definition
74 */
75 typedef struct _wdt_init
76 {
77 uint32_t counter; /**< Specifies the WDT free-running downcounter value.
78 This parameter can be a number ranging between 0x0U and 0xFFFFFFFFU. */
79
80 uint32_t reset_mode ; /**< Specifies if WDT Reset output is enable or not.
81 When RESET Mode is enabled, WDT will generate an interrupt
82 on first timeout. If interrupt has not been cleared before the second
83 timeout, WDT will then request a SoC Reset.
84
85 This parameter can be a value of @ref WDT_RESET_Mode. */
86
87 } wdt_init_t;
88
89 /** @} */
90
91 /** @defgroup WDT_handle WDT handle
92 * @{
93 */
94
95 /**
96 * @brief WDT handle Structure definition
97 */
98 typedef struct _wdt_handle
99 {
100 wdt_regs_t *p_instance; /**< Register base address */
101
102 wdt_init_t init; /**< WDT required parameters */
103
104 hal_lock_t lock; /**< WDT locking object */
105
106 } wdt_handle_t;
107
108 /** @} */
109
110 /** @} */
111
112 /** @addtogroup HAL_WDT_CALLBACK_STRUCTURES Callback Structures
113 * @{
114 */
115
116 /** @defgroup HAL_WDT_Callback Callback
117 * @{
118 */
119
120 /**
121 * @brief HAL_WDT Callback function definition
122 */
123
124 typedef struct _hal_wdt_callback
125 {
126 void (*wdt_msp_init)(wdt_handle_t *p_wdt); /**< WDT init MSP callback */
127 void (*wdt_msp_deinit)(wdt_handle_t *p_wdt); /**< WDT de-init MSP callback */
128 void (*wdt_period_elapsed_callback)(wdt_handle_t *p_wdt); /**< WDT count complete callback */
129 } hal_wdt_callback_t;
130
131 /** @} */
132
133 /** @} */
134
135 /**
136 * @defgroup HAL_WDT_MACRO Defines
137 * @{
138 */
139
140 /* Exported constants --------------------------------------------------------*/
141 /** @defgroup WDT_Exported_Constants WDT Exported Constants
142 * @{
143 */
144
145 /** @defgroup WDT_RESET_Mode WDT Reset Mode
146 * @{
147 */
148 #define WDT_RESET_DISABLE (0x00000000U) /**< Reset ouput disable */
149 #define WDT_RESET_ENABLE (0x00000001U) /**< Reset output enable */
150 /** @} */
151
152 /** @} */
153
154 /* Private macros ------------------------------------------------------------*/
155 /** @defgroup WDT_Private_Macros WDT Private Macros
156 * @{
157 */
158
159 /**
160 * @brief Check if the WDT reset mode is valid.
161 * @param __MODE__ WDT reset mode.
162 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
163 */
164 #define IS_WDT_RESET_MODE(__MODE__) (((__MODE__) == WDT_RESET_ENABLE) || \
165 ((__MODE__) == WDT_RESET_DISABLE))
166 /** @} */
167
168 /** @} */
169
170 /* Exported functions --------------------------------------------------------*/
171 /** @addtogroup HAL_WDT_DRIVER_FUNCTIONS Functions
172 * @{
173 */
174
175 /** @addtogroup WDT_Exported_Functions_Group1 Initialization and de-initialization functions
176 * @brief Initialization and de-initialization functions.
177 *
178 @verbatim
179 ==============================================================================
180 ##### Initialization and de-initialization functions #####
181 ==============================================================================
182 [..]
183 This section provides functions allowing to:
184 (+) Initialize and start the WDT according to the specified parameters
185 in the wdt_init_t of associated handle.
186 (+) Initialize the WDT MSP.
187
188 @endverbatim
189 * @{
190 */
191
192 /**
193 ****************************************************************************************
194 * @brief Initialize the WDT according to the specified
195 * parameters in the wdt_init_t of associated handle.
196 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
197 * information for the specified WDT module.
198 * @retval ::HAL_OK: Operation is OK.
199 * @retval ::HAL_ERROR: Parameter error or operation not supported.
200 * @retval ::HAL_BUSY: Driver is busy.
201 * @retval ::HAL_TIMEOUT: Timeout occurred.
202 ****************************************************************************************
203 */
204 hal_status_t hal_wdt_init(wdt_handle_t *p_wdt);
205
206 /**
207 ****************************************************************************************
208 * @brief De-initialize the WDT peripheral.
209 * @param[in] p_wdt: WDT handle.
210 * @retval ::HAL_OK: Operation is OK.
211 * @retval ::HAL_ERROR: Parameter error or operation not supported.
212 * @retval ::HAL_BUSY: Driver is busy.
213 * @retval ::HAL_TIMEOUT: Timeout occurred.
214 ****************************************************************************************
215 */
216 hal_status_t hal_wdt_deinit(wdt_handle_t *p_wdt);
217
218 /**
219 ****************************************************************************************
220 * @brief Initialize the WDT MSP.
221 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
222 * information for the specified WDT module.
223 * @note When rewriting this function in a user file, this mechanism may be added
224 * to avoid multiple initialization when hal_wdt_init function is called
225 * again to change parameters.
226 ****************************************************************************************
227 */
228 void hal_wdt_msp_init(wdt_handle_t *p_wdt);
229
230 /**
231 ****************************************************************************************
232 * @brief De-initialize the WDT MSP.
233 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
234 * information for the specified WDT module.
235 * @note When rewriting this function in a user file, this mechanism may be added
236 * to avoid multiple initialization when hal_wdt_init function is called
237 * again to change parameters.
238 ****************************************************************************************
239 */
240 void hal_wdt_msp_deinit(wdt_handle_t *p_wdt);
241
242 /** @} */
243
244 /** @addtogroup WDT_Exported_Functions_Group2 IO operation functions
245 * @brief IO operation functions
246 *
247 @verbatim
248 ==============================================================================
249 ##### IO operation functions #####
250 ==============================================================================
251 [..]
252 This section provides functions allowing to:
253 (+) Refresh the WDT.
254 (+) Handle WDT interrupt request and associated function callback.
255
256 @endverbatim
257 * @{
258 */
259
260 /**
261 ****************************************************************************************
262 * @brief Refresh the WDT.
263 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
264 * information for the specified WDT module.
265 * @retval ::HAL_OK: Operation is OK.
266 * @retval ::HAL_ERROR: Parameter error or operation not supported.
267 * @retval ::HAL_BUSY: Driver is busy.
268 * @retval ::HAL_TIMEOUT: Timeout occurred.
269 ****************************************************************************************
270 */
271 hal_status_t hal_wdt_refresh(wdt_handle_t *p_wdt);
272
273 /** @} */
274
275
276 /** @addtogroup WDT_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
277 * @brief IRQ Handler and Callbacks functions
278 * @{
279 */
280
281 /**
282 ****************************************************************************************
283 * @brief Handle WDT interrupt request.
284 * @note The Count Complete can be used if specific safety operations
285 * or data logging must be performed before the actual reset is generated.
286 * When RESET Mode is enabled, WDT will generate an interrupt on first timeout.
287 * If interrupt has not been cleared before the second timeout, WDT will then
288 * request a SoC Reset.
289 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
290 * information for the specified WDT module.
291 ****************************************************************************************
292 */
293 void hal_wdt_irq_handler(wdt_handle_t *p_wdt);
294
295 /**
296 ****************************************************************************************
297 * @brief WDT count complete(counter reaches to 0) callback.
298 * @note In RESET mode, NVIC interrupt of WDT can be disabled in
299 * hal_wdt_period_elapsed_callback() to make sure this callback
300 * be called once only.
301 * This function should not be modified. When the callback is needed,
302 * the hal_wdt_count_cplt_callback can be implemented in the user file.
303 * @param[in] p_wdt: Pointer to a WDT handle which contains the configuration
304 * information for the specified WDT module.
305 ****************************************************************************************
306 */
307 void hal_wdt_period_elapsed_callback(wdt_handle_t *p_wdt);
308
309 /** @} */
310
311 /** @} */
312
313 #ifdef __cplusplus
314 }
315 #endif
316
317 #endif /* __GR55xx_HAL_WDT_H__ */
318
319 /** @} */
320
321 /** @} */
322
323 /** @} */
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
_hal_wdt_callback
HAL_WDT Callback function definition.
Definition: gr55xx_hal_wdt.h:125
hal_wdt_deinit
hal_status_t hal_wdt_deinit(wdt_handle_t *p_wdt)
De-initialize the WDT peripheral.
hal_wdt_callback_t
struct _hal_wdt_callback hal_wdt_callback_t
HAL_WDT Callback function definition.
hal_wdt_period_elapsed_callback
void hal_wdt_period_elapsed_callback(wdt_handle_t *p_wdt)
WDT count complete(counter reaches to 0) callback.
hal_wdt_msp_init
void hal_wdt_msp_init(wdt_handle_t *p_wdt)
Initialize the WDT MSP.
hal_wdt_irq_handler
void hal_wdt_irq_handler(wdt_handle_t *p_wdt)
Handle WDT interrupt request.
wdt_handle_t
struct _wdt_handle wdt_handle_t
WDT handle Structure definition.
wdt_init_t
struct _wdt_init wdt_init_t
WDT init structure definition.
_hal_wdt_callback::wdt_msp_deinit
void(* wdt_msp_deinit)(wdt_handle_t *p_wdt)
WDT de-init MSP callback
Definition: gr55xx_hal_wdt.h:127
hal_wdt_msp_deinit
void hal_wdt_msp_deinit(wdt_handle_t *p_wdt)
De-initialize the WDT MSP.
_wdt_handle::p_instance
wdt_regs_t * p_instance
Register base address
Definition: gr55xx_hal_wdt.h:100
_wdt_handle::lock
hal_lock_t lock
WDT locking object
Definition: gr55xx_hal_wdt.h:104
hal_wdt_init
hal_status_t hal_wdt_init(wdt_handle_t *p_wdt)
Initialize the WDT according to the specified parameters in the wdt_init_t of associated handle.
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_wdt_handle
WDT handle Structure definition.
Definition: gr55xx_hal_wdt.h:99
gr55xx_ll_wdt.h
Header file containing functions prototypes of WDT LL library.
hal_wdt_refresh
hal_status_t hal_wdt_refresh(wdt_handle_t *p_wdt)
Refresh the WDT.
_wdt_init::reset_mode
uint32_t reset_mode
Specifies if WDT Reset output is enable or not.
Definition: gr55xx_hal_wdt.h:80
_hal_wdt_callback::wdt_msp_init
void(* wdt_msp_init)(wdt_handle_t *p_wdt)
WDT init MSP callback
Definition: gr55xx_hal_wdt.h:126
_wdt_handle::init
wdt_init_t init
WDT required parameters
Definition: gr55xx_hal_wdt.h:102
_wdt_init::counter
uint32_t counter
Specifies the WDT free-running downcounter value.
Definition: gr55xx_hal_wdt.h:77
_wdt_init
WDT init structure definition.
Definition: gr55xx_hal_wdt.h:76
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_hal_wdt_callback::wdt_period_elapsed_callback
void(* wdt_period_elapsed_callback)(wdt_handle_t *p_wdt)
WDT count complete callback
Definition: gr55xx_hal_wdt.h:128