gr55xx_ll_wdt.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_wdt.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of WDT LL 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 LL_DRIVER LL Driver
43 * @{
44 */
45
46 /** @defgroup LL_WDT WDT
47 * @brief WDT LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_WDT_H__
53 #define __GR55XX_LL_WDT_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61
62 #if defined (WDT)
63
64 /**
65 * @defgroup WDT_LL_MACRO Defines
66 * @{
67 */
68
69 /* Private constants ---------------------------------------------------------*/
70 /** @defgroup WDT_LL_Private_Constants WDT Private Constants
71 * @{
72 */
73
74 /** @defgroup WDT_LL_PC_WR_ACCESS Write Access Defines
75 * @{
76 */
77 #define LL_WDT_LOCK_WR_ACCESS_ENABLE 0x1ACCE551 /**< WDT LOCK Write Access Enable */
78 #define LL_WDT_LOCK_WR_ACCESS_DISABLE (~0x1ACCE551) /**< WDT LOCK Write Access Disable */
79 /** @} */
80
81 /** @} */
82
83 /* Exported macro ------------------------------------------------------------*/
84 /** @defgroup WDT_LL_Exported_Macros WDT Exported Macros
85 * @{
86 */
87
88 /** @defgroup WDT_LL_EM_WRITE_READ Common Write and read registers Macros
89 * @{
90 */
91
92 /**
93 * @brief Write a value in WDT register
94 * @param __instance__ WDT instance
95 * @param __REG__ Register to be written
96 * @param __VALUE__ Value to be written in the register
97 * @retval None
98 */
99 #define LL_WDT_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
100
101 /**
102 * @brief Read a value in WDT register
103 * @param __instance__ WDT instance
104 * @param __REG__ Register to be read
105 * @retval Register value
106 */
107 #define LL_WDT_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
108 /** @} */
109
110 /** @} */
111
112 /** @} */
113
114 /* Exported functions --------------------------------------------------------*/
115 /** @defgroup WDT_LL_DRIVER_FUNCTIONS Functions
116 * @{
117 */
118
119 /** @defgroup WDT_LL_EF_Configuration Configuration functions
120 * @{
121 */
122
123 /**
124 * @brief Enable write access to WDT_LOAD, WDT_CTRL and WDT_INTCLR registers.
125 *
126 * \rst
127 * +----------------------+-----------------------------------+
128 * | Register | BitsName |
129 * +======================+===================================+
130 * | LOCK | ENRW |
131 * +----------------------+-----------------------------------+
132 * \endrst
133 *
134 * @param WDTx WDT instance
135 * @retval None
136 */
137 __STATIC_INLINE void ll_wdt_enable_write_access(wdt_regs_t *WDTx)
138 {
139 WRITE_REG(WDTx->LOCK, LL_WDT_LOCK_WR_ACCESS_ENABLE);
140 }
141
142 /**
143 * @brief Disable write access to WDT_LOAD, WDT_CTRL and WDT_INTCLR registers.
144 *
145 * \rst
146 * +----------------------+-----------------------------------+
147 * | Register | BitsName |
148 * +======================+===================================+
149 * | LOCK | ENRW |
150 * +----------------------+-----------------------------------+
151 * \endrst
152 *
153 * @param WDTx WDT instance
154 * @retval None
155 */
156 __STATIC_INLINE void ll_wdt_disable_write_access(wdt_regs_t *WDTx)
157 {
158 WRITE_REG(WDTx->LOCK, LL_WDT_LOCK_WR_ACCESS_DISABLE);
159 }
160
161 /**
162 * @brief Enable watchdog counter and interrupt event.
163 *
164 * \rst
165 * +----------------------+-----------------------------------+
166 * | Register | BitsName |
167 * +======================+===================================+
168 * | CTRL | INTEN |
169 * +----------------------+-----------------------------------+
170 * \endrst
171 *
172 * @param WDTx WDT instance.
173 * @retval None
174 */
175 __STATIC_INLINE void ll_wdt_enable(wdt_regs_t *WDTx)
176 {
177 SET_BITS(WDTx->CTRL, WDT_CTRL_INTEN);
178 }
179
180 /**
181 * @brief Disable watchdog counter and interrupt event.
182 *
183 * \rst
184 * +----------------------+-----------------------------------+
185 * | Register | BitsName |
186 * +======================+===================================+
187 * | CTRL | INTEN |
188 * +----------------------+-----------------------------------+
189 * \endrst
190 *
191 * @param WDTx WDT instance.
192 * @retval None
193 */
194 __STATIC_INLINE void ll_wdt_disable(wdt_regs_t *WDTx)
195 {
196 CLEAR_BITS(WDTx->CTRL, WDT_CTRL_INTEN);
197 }
198
199 /**
200 * @brief Check if the WDT peripheral is enabled or disabled.
201 *
202 * \rst
203 * +----------------------+-----------------------------------+
204 * | Register | BitsName |
205 * +======================+===================================+
206 * | CTRL | INTEN |
207 * +----------------------+-----------------------------------+
208 * \endrst
209 *
210 * @param WDTx WDT instance.
211 * @retval State of bit (1 or 0).
212 */
213 __STATIC_INLINE uint32_t ll_wdt_is_enabled(wdt_regs_t *WDTx)
214 {
215 return (READ_BITS(WDTx->CTRL, WDT_CTRL_INTEN) == (WDT_CTRL_INTEN));
216 }
217
218 /**
219 * @brief Enable reset output.
220 * @note RSTEN acts as a mask for the reset output.
221 *
222 * \rst
223 * +----------------------+-----------------------------------+
224 * | Register | BitsName |
225 * +======================+===================================+
226 * | CTRL | RSTEN |
227 * +----------------------+-----------------------------------+
228 * \endrst
229 *
230 * @param WDTx WDT instance.
231 * @retval None
232 */
233 __STATIC_INLINE void ll_wdt_enable_reset(wdt_regs_t *WDTx)
234 {
235 SET_BITS(WDTx->CTRL, WDT_CTRL_RSTEN);
236 }
237
238 /**
239 * @brief Disable reset output.
240 *
241 * \rst
242 * +----------------------+-----------------------------------+
243 * | Register | BitsName |
244 * +======================+===================================+
245 * | CTRL | RSTEN |
246 * +----------------------+-----------------------------------+
247 * \endrst
248 *
249 * @param WDTx WDT instance.
250 * @retval None
251 */
252 __STATIC_INLINE void ll_wdt_disable_reset(wdt_regs_t *WDTx)
253 {
254 CLEAR_BITS(WDTx->CTRL, WDT_CTRL_RSTEN);
255 }
256
257 /**
258 * @brief Check if the WDT reset is enabled or disabled.
259 *
260 * \rst
261 * +----------------------+-----------------------------------+
262 * | Register | BitsName |
263 * +======================+===================================+
264 * | CTRL | RSTEN |
265 * +----------------------+-----------------------------------+
266 * \endrst
267 *
268 * @param WDTx WDT instance.
269 * @retval State of bit (1 or 0).
270 */
271 __STATIC_INLINE uint32_t ll_wdt_is_enabled_reset(wdt_regs_t *WDTx)
272 {
273 return (READ_BITS(WDTx->CTRL, WDT_CTRL_RSTEN) == (WDT_CTRL_RSTEN));
274 }
275
276 /**
277 * @brief Specify the WDT down-counter reload value.
278 *
279 * \rst
280 * +----------------------+-----------------------------------+
281 * | Register | BitsName |
282 * +======================+===================================+
283 * | LOAD | LOAD |
284 * +----------------------+-----------------------------------+
285 * \endrst
286 *
287 * @param WDTx WDT instance
288 * @param counter Value range between Min_Data=0 and Max_Data=0xFFFFFFFF
289 * @retval None
290 */
291 __STATIC_INLINE void ll_wdt_set_counter_load(wdt_regs_t *WDTx, uint32_t counter)
292 {
293 WRITE_REG(WDTx->LOAD, counter);
294 }
295
296 /**
297 * @brief Get the specified WDT down-counter reload value.
298 *
299 * \rst
300 * +----------------------+-----------------------------------+
301 * | Register | BitsName |
302 * +======================+===================================+
303 * | LOAD | LOAD |
304 * +----------------------+-----------------------------------+
305 * \endrst
306 *
307 * @param WDTx WDT instance
308 * @retval Value range between Min_Data=0 and Max_Data=0x0FFF
309 */
310 __STATIC_INLINE uint32_t ll_wdt_get_counter_load(wdt_regs_t *WDTx)
311 {
312 return (uint32_t)(READ_REG(WDTx->LOAD));
313 }
314
315 /**
316 * @brief Get current value of the specified WDT decrementing down-counter.
317 *
318 * \rst
319 * +----------------------+-----------------------------------+
320 * | Register | BitsName |
321 * +======================+===================================+
322 * | VALUE | VALUE |
323 * +----------------------+-----------------------------------+
324 * \endrst
325 *
326 * @param WDTx WDT instance
327 * @retval Value range between Min_Data=0 and Max_Data=0x0FFF
328 */
329 __STATIC_INLINE uint32_t ll_wdt_get_counter_value(wdt_regs_t *WDTx)
330 {
331 return (uint32_t)(READ_REG(WDTx->VALUE));
332 }
333
334 /**
335 * @brief Reloads WDT counter with value defined in the reload register
336 *
337 * \rst
338 * +----------------------+-----------------------------------+
339 * | Register | BitsName |
340 * +======================+===================================+
341 * | INTCLR | INTCLR |
342 * +----------------------+-----------------------------------+
343 * \endrst
344 *
345 * @param WDTx WDT instance
346 * @retval None
347 */
348 __STATIC_INLINE void ll_wdt_reload_counter(wdt_regs_t *WDTx)
349 {
350 WRITE_REG(WDTx->INTCLR, WDT_INTCLR);
351 }
352
353 /** @} */
354
355 /** @defgroup WDT_LL_EF_FLAG_Management FLAG_Management
356 * @{
357 */
358
359 /**
360 * @brief Indicate if the WDT Interrupt Flag is set or not.
361 * @note This bit is set by hardware when the counter has reached 0. It can
362 * be cleared by software by writing any value to the INTCLR Register.
363 *
364 * \rst
365 * +----------------------+-----------------------------------+
366 * | Register | BitsName |
367 * +======================+===================================+
368 * | MIS | INTSTAT |
369 * +----------------------+-----------------------------------+
370 * \endrst
371 *
372 * @param WDTx WDT instance.
373 * @retval State of bit (1 or 0).
374 */
375 __STATIC_INLINE uint32_t ll_wdt_is_active_flag_it(wdt_regs_t *WDTx)
376 {
377 return (READ_BITS(WDTx->MIS, WDT_MIS_INTSTAT) == (WDT_MIS_INTSTAT));
378 }
379
380 /**
381 * @brief Clear Interrupt Status flag.
382 *
383 * \rst
384 * +----------------------+-----------------------------------+
385 * | Register | BitsName |
386 * +======================+===================================+
387 * | INTCLR | INTCLR |
388 * +----------------------+-----------------------------------+
389 * \endrst
390 *
391 * @param WDTx WDT instance.
392 * @retval None
393 */
394 __STATIC_INLINE void ll_wdt_clear_flag_it(wdt_regs_t *WDTx)
395 {
396 WRITE_REG(WDTx->INTCLR, WDT_INTCLR);
397 }
398
399 /** @} */
400
401 /** @} */
402
403 #endif /* WDT */
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif /* __GR55XX_LL_WDT_H__ */
410
411 /** @} */
412
413 /** @} */
414
415 /** @} */
ll_wdt_set_counter_load
__STATIC_INLINE void ll_wdt_set_counter_load(wdt_regs_t *WDTx, uint32_t counter)
Specify the WDT down-counter reload value.
Definition: gr55xx_ll_wdt.h:291
ll_wdt_enable_reset
__STATIC_INLINE void ll_wdt_enable_reset(wdt_regs_t *WDTx)
Enable reset output.
Definition: gr55xx_ll_wdt.h:233
ll_wdt_enable
__STATIC_INLINE void ll_wdt_enable(wdt_regs_t *WDTx)
Enable watchdog counter and interrupt event.
Definition: gr55xx_ll_wdt.h:175
ll_wdt_is_enabled
__STATIC_INLINE uint32_t ll_wdt_is_enabled(wdt_regs_t *WDTx)
Check if the WDT peripheral is enabled or disabled.
Definition: gr55xx_ll_wdt.h:213
ll_wdt_disable_reset
__STATIC_INLINE void ll_wdt_disable_reset(wdt_regs_t *WDTx)
Disable reset output.
Definition: gr55xx_ll_wdt.h:252
ll_wdt_get_counter_value
__STATIC_INLINE uint32_t ll_wdt_get_counter_value(wdt_regs_t *WDTx)
Get current value of the specified WDT decrementing down-counter.
Definition: gr55xx_ll_wdt.h:329
ll_wdt_disable_write_access
__STATIC_INLINE void ll_wdt_disable_write_access(wdt_regs_t *WDTx)
Disable write access to WDT_LOAD, WDT_CTRL and WDT_INTCLR registers.
Definition: gr55xx_ll_wdt.h:156
ll_wdt_is_active_flag_it
__STATIC_INLINE uint32_t ll_wdt_is_active_flag_it(wdt_regs_t *WDTx)
Indicate if the WDT Interrupt Flag is set or not.
Definition: gr55xx_ll_wdt.h:375
ll_wdt_clear_flag_it
__STATIC_INLINE void ll_wdt_clear_flag_it(wdt_regs_t *WDTx)
Clear Interrupt Status flag.
Definition: gr55xx_ll_wdt.h:394
ll_wdt_get_counter_load
__STATIC_INLINE uint32_t ll_wdt_get_counter_load(wdt_regs_t *WDTx)
Get the specified WDT down-counter reload value.
Definition: gr55xx_ll_wdt.h:310
ll_wdt_is_enabled_reset
__STATIC_INLINE uint32_t ll_wdt_is_enabled_reset(wdt_regs_t *WDTx)
Check if the WDT reset is enabled or disabled.
Definition: gr55xx_ll_wdt.h:271
ll_wdt_disable
__STATIC_INLINE void ll_wdt_disable(wdt_regs_t *WDTx)
Disable watchdog counter and interrupt event.
Definition: gr55xx_ll_wdt.h:194
LL_WDT_LOCK_WR_ACCESS_ENABLE
#define LL_WDT_LOCK_WR_ACCESS_ENABLE
WDT LOCK Write Access Enable
Definition: gr55xx_ll_wdt.h:77
ll_wdt_enable_write_access
__STATIC_INLINE void ll_wdt_enable_write_access(wdt_regs_t *WDTx)
Enable write access to WDT_LOAD, WDT_CTRL and WDT_INTCLR registers.
Definition: gr55xx_ll_wdt.h:137
ll_wdt_reload_counter
__STATIC_INLINE void ll_wdt_reload_counter(wdt_regs_t *WDTx)
Reloads WDT counter with value defined in the reload register.
Definition: gr55xx_ll_wdt.h:348
LL_WDT_LOCK_WR_ACCESS_DISABLE
#define LL_WDT_LOCK_WR_ACCESS_DISABLE
WDT LOCK Write Access Disable.
Definition: gr55xx_ll_wdt.h:78