gr55xx_ll_aon_wdt.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_ll_aon_wdt.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of AON 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_AON_WDT AON_WDT
47  * @brief AON_WDT LL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_AON_WDT_H__
53 #define __GR55XX_LL_AON_WDT_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61 
62 #if defined (AON)
63 
64 /* Exported functions --------------------------------------------------------*/
65 /** @defgroup AON_WDT_LL_DRIVER_FUNCTIONS Functions
66  * @{
67  */
68 
69 /** @defgroup AON_WDT_LL_EF_Configuration Configuration functions
70  * @{
71  */
72 
73 /**
74  * @brief Enable AON watchdog counter and interrupt event.
75  *
76  * \rst
77  * +----------------------+-----------------------------------+
78  * | Register | BitsName |
79  * +======================+===================================+
80  * | EXT_WKUP_CTL | WDT_EN |
81  * +----------------------+-----------------------------------+
82  * \endrst
83  *
84  * @retval None
85  */
86 __STATIC_INLINE void ll_aon_wdt_enable(void)
87 {
88  SET_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN);
89 }
90 
91 /**
92  * @brief Disable AON watchdog counter and interrupt event.
93  *
94  * \rst
95  * +----------------------+-----------------------------------+
96  * | Register | BitsName |
97  * +======================+===================================+
98  * | EXT_WKUP_CTL | WDT_EN |
99  * +----------------------+-----------------------------------+
100  * \endrst
101  *
102  * @retval None
103  */
104 __STATIC_INLINE void ll_aon_wdt_disable(void)
105 {
106  CLEAR_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN);
107 }
108 
109 /**
110  * @brief Check if the AON_WDT peripheral is enabled or disabled.
111  *
112  * \rst
113  * +----------------------+-----------------------------------+
114  * | Register | BitsName |
115  * +======================+===================================+
116  * | EXT_WKUP_CTL | WDT_EN |
117  * +----------------------+-----------------------------------+
118  * \endrst
119  *
120  * @retval State of bit (1 or 0).
121  */
122 __STATIC_INLINE uint32_t ll_aon_wdt_is_enabled(void)
123 {
124  return (READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN) == (AON_EXT_WKUP_CTL_WDT_EN));
125 }
126 
127 /**
128  * @brief Specify the AON WDT down-counter reload value.
129  *
130  * \rst
131  * +----------------------+-----------------------------------+
132  * | Register | BitsName |
133  * +======================+===================================+
134  * | TIMER_VALUE | TIMER_VALUE |
135  * +----------------------+-----------------------------------+
136  * \endrst
137  *
138  * @param counter Value for reload down-counter which should ranging between 0 ~ 0xFFFF_FFFF
139  * @retval None
140  */
141 __STATIC_INLINE void ll_aon_wdt_set_reload_counter(uint32_t counter)
142 {
143  WRITE_REG(AON->TIMER_VALUE, counter);
144 }
145 
146 /**
147  * @brief Reloads AON WDT counter.
148  * @note The value in TIMER_VALUE register will be reloaded into AON WDT down-counter
149  * after enable this bit, so ll_aon_wdt_set_reload_counter() should be called before
150  * every reload.
151  *
152  * \rst
153  * +----------------------+-----------------------------------+
154  * | Register | BitsName |
155  * +======================+===================================+
156  * | EXT_WKUP_CTL | WDT_RELOAD |
157  * +----------------------+-----------------------------------+
158  * \endrst
159  *
160  * @retval None
161  */
162 __STATIC_INLINE void ll_aon_wdt_reload_counter(void)
163 {
164  SET_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_RELOAD);
165 }
166 
167 /**
168  * @brief Read the AON WDT counter current value.
169  *
170  * \rst
171  * +----------------------+-----------------------------------+
172  * | Register | BitsName |
173  * +======================+===================================+
174  * | AON_PAD_CTL1 | AON_WDT_TIMER |
175  * +----------------------+-----------------------------------+
176  * \endrst
177  * TIMER_VAL | TIMER_VAL_READ
178  *
179  * @retval Value for current counter which should ranging between 0 ~ 0xFFFF_FFFF
180  */
181 __STATIC_INLINE uint32_t ll_aon_wdt_get_counter(void)
182 {
183  MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_AON_WDT);
184  return (uint32_t)READ_REG(AON->TIMER_VAL);
185 }
186 
187 /**
188  * @brief Specify the AON_WDT down-counter alarm value
189  * @note AON watchdog will generate an interrupt when it counts down to the
190  * alarm value to alram that it is almost expired.
191  *
192  * \rst
193  * +----------------------+-----------------------------------+
194  * | Register | BitsName |
195  * +======================+===================================+
196  * | EXT_WKUP_CTL | WDT_ALARM |
197  * +----------------------+-----------------------------------+
198  * \endrst
199  *
200  * @param counter Value between Min_Data=0 and Max_Data=0x1F
201  * @retval None
202  */
203 __STATIC_INLINE void ll_aon_wdt_set_alarm_counter(uint32_t counter)
204 {
205  MODIFY_REG(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_ALARM, (counter << AON_EXT_WKUP_CTL_WDT_ALARM_Pos) & AON_EXT_WKUP_CTL_WDT_ALARM);
206 }
207 
208 /**
209  * @brief Get the AON_WDT down-counter alarm value
210  *
211  * \rst
212  * +----------------------+-----------------------------------+
213  * | Register | BitsName |
214  * +======================+===================================+
215  * | EXT_WKUP_CTL | WDT_ALARM |
216  * +----------------------+-----------------------------------+
217  * \endrst
218  *
219  * @retval Value between Min_Data=0 and Max_Data=0x1F
220  */
221 __STATIC_INLINE uint32_t ll_aon_wdt_get_alarm_counter(void)
222 {
223  return (uint32_t)(READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_ALARM) >> AON_EXT_WKUP_CTL_WDT_ALARM_Pos);
224 }
225 
226 /** @} */
227 
228 /** @defgroup AON_WDT_LL_EF_FLAG_Management FLAG_Management
229  * @{
230  */
231 
232 /**
233  * @brief Indicate if the AON Watchdog Running Flag is set or not.
234  * @note This bit can be used to check if AON Watchdog is in running state.
235  *
236  * \rst
237  * +----------------------+-----------------------------------+
238  * | Register | BitsName |
239  * +======================+===================================+
240  * | EXT_WKUP_CTL | WDT_RUNNING |
241  * +----------------------+-----------------------------------+
242  * \endrst
243  *
244  * @retval State of bit (1 or 0).
245  */
246 __STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_running(void)
247 {
248  return (uint32_t)(READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_RUNNING) == (AON_EXT_WKUP_CTL_WDT_RUNNING));
249 }
250 
251 /**
252  * @brief Indicate if the AON WDT Reboot Event Flag is set or not.
253  * @note This bit is set by hardware when the counter has reached alarm value.
254  * It can be cleared by writing 0 to this bit.
255  *
256  * \rst
257  * +----------------------+-----------------------------------+
258  * | Register | BitsName |
259  * +======================+===================================+
260  * | SLP_EVENT | SLP_EVENT_WDT |
261  * +----------------------+-----------------------------------+
262  * \endrst
263  *
264  * @retval State of bit (1 or 0).
265  */
266 __STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_reboot(void)
267 {
268  return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_WDT_REBOOT) == AON_SLP_EVENT_WDT_REBOOT);
269 }
270 
271 /**
272  * @brief Clear Interrupt Status flag.
273  *
274  * \rst
275  * +----------------------+-----------------------------------+
276  * | Register | BitsName |
277  * +======================+===================================+
278  * | SLP_EVENT | SLP_EVENT_WDT |
279  * +----------------------+-----------------------------------+
280  * \endrst
281  *
282  * @retval None
283  */
284 __STATIC_INLINE void ll_aon_wdt_clear_flag_reboot(void)
285 {
286  WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_WDT_REBOOT);
287 }
288 
289 /** @} */
290 
291 /** @} */
292 
293 #endif /* AON_WDT */
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 
299 #endif /* __GR55XX_LL_AON_WDT_H__ */
300 
301 /** @} */
302 
303 /** @} */
304 
305 /** @} */
ll_aon_wdt_get_counter
__STATIC_INLINE uint32_t ll_aon_wdt_get_counter(void)
Read the AON WDT counter current value.
Definition: gr55xx_ll_aon_wdt.h:181
ll_aon_wdt_set_alarm_counter
__STATIC_INLINE void ll_aon_wdt_set_alarm_counter(uint32_t counter)
Specify the AON_WDT down-counter alarm value.
Definition: gr55xx_ll_aon_wdt.h:203
ll_aon_wdt_reload_counter
__STATIC_INLINE void ll_aon_wdt_reload_counter(void)
Reloads AON WDT counter.
Definition: gr55xx_ll_aon_wdt.h:162
ll_aon_wdt_is_enabled
__STATIC_INLINE uint32_t ll_aon_wdt_is_enabled(void)
Check if the AON_WDT peripheral is enabled or disabled.
Definition: gr55xx_ll_aon_wdt.h:122
ll_aon_wdt_clear_flag_reboot
__STATIC_INLINE void ll_aon_wdt_clear_flag_reboot(void)
Clear Interrupt Status flag.
Definition: gr55xx_ll_aon_wdt.h:284
ll_aon_wdt_is_active_flag_running
__STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_running(void)
Indicate if the AON Watchdog Running Flag is set or not.
Definition: gr55xx_ll_aon_wdt.h:246
ll_aon_wdt_enable
__STATIC_INLINE void ll_aon_wdt_enable(void)
Enable AON watchdog counter and interrupt event.
Definition: gr55xx_ll_aon_wdt.h:86
ll_aon_wdt_get_alarm_counter
__STATIC_INLINE uint32_t ll_aon_wdt_get_alarm_counter(void)
Get the AON_WDT down-counter alarm value.
Definition: gr55xx_ll_aon_wdt.h:221
ll_aon_wdt_set_reload_counter
__STATIC_INLINE void ll_aon_wdt_set_reload_counter(uint32_t counter)
Specify the AON WDT down-counter reload value.
Definition: gr55xx_ll_aon_wdt.h:141
ll_aon_wdt_disable
__STATIC_INLINE void ll_aon_wdt_disable(void)
Disable AON watchdog counter and interrupt event.
Definition: gr55xx_ll_aon_wdt.h:104
ll_aon_wdt_is_active_flag_reboot
__STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_reboot(void)
Indicate if the AON WDT Reboot Event Flag is set or not.
Definition: gr55xx_ll_aon_wdt.h:266