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 * Register|BitsName
77 * --------|--------
78 * EXT_WKUP_CTL | WDT_EN
79 *
80 * @retval None
81 */
82 __STATIC_INLINE void ll_aon_wdt_enable(void)
83 {
84 SET_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN);
85 }
86
87 /**
88 * @brief Disable AON watchdog counter and interrupt event.
89 *
90 * Register|BitsName
91 * --------|--------
92 * EXT_WKUP_CTL | WDT_EN
93 *
94 * @retval None
95 */
96 __STATIC_INLINE void ll_aon_wdt_disable(void)
97 {
98 CLEAR_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN);
99 }
100
101 /**
102 * @brief Check if the AON_WDT peripheral is enabled or disabled.
103 *
104 * Register|BitsName
105 * --------|--------
106 * EXT_WKUP_CTL | WDT_EN
107 *
108 * @retval State of bit (1 or 0).
109 */
110 __STATIC_INLINE uint32_t ll_aon_wdt_is_enabled(void)
111 {
112 return (READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_EN) == (AON_EXT_WKUP_CTL_WDT_EN));
113 }
114
115 /**
116 * @brief Specify the AON WDT down-counter reload value.
117 *
118 * Register|BitsName
119 * --------|--------
120 * TIMER_VALUE | TIMER_VALUE
121 *
122 * @param counter Value for reload down-counter which should ranging between 0 ~ 0xFFFF_FFFF
123 * @retval None
124 */
125 __STATIC_INLINE void ll_aon_wdt_set_reload_counter(uint32_t counter)
126 {
127 WRITE_REG(AON->TIMER_VALUE, counter);
128 }
129
130 /**
131 * @brief Reloads AON WDT counter.
132 * @note The value in TIMER_VALUE register will be reloaded into AON WDT down-counter
133 * after enable this bit, so ll_aon_wdt_set_reload_counter() should be called before
134 * every reload.
135 *
136 * Register|BitsName
137 * --------|--------
138 * EXT_WKUP_CTL | WDT_RELOAD
139 *
140 * @retval None
141 */
142 __STATIC_INLINE void ll_aon_wdt_reload_counter(void)
143 {
144 SET_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_RELOAD);
145 }
146
147 /**
148 * @brief Read the AON WDT counter current value.
149 *
150 * Register|BitsName
151 * --------|--------
152 * AON_PAD_CTL1 | AON_WDT_TIMER
153 * TIMER_VAL | TIMER_VAL_READ
154 *
155 * @retval Value for current counter which should ranging between 0 ~ 0xFFFF_FFFF
156 */
157 __STATIC_INLINE uint32_t ll_aon_wdt_get_counter(void)
158 {
159 MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_AON_WDT);
160 return (uint32_t)READ_REG(AON->TIMER_VAL);
161 }
162
163 /**
164 * @brief Specify the AON_WDT down-counter alarm value
165 * @note AON watchdog will generate an interrupt when it counts down to the
166 * alarm value to alram that it is almost expired.
167 *
168 * Register|BitsName
169 * --------|--------
170 * EXT_WKUP_CTL | WDT_ALARM
171 *
172 * @param counter Value between Min_Data=0 and Max_Data=0x1F
173 * @retval None
174 */
175 __STATIC_INLINE void ll_aon_wdt_set_alarm_counter(uint32_t counter)
176 {
177 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);
178 }
179
180 /**
181 * @brief Get the AON_WDT down-counter alarm value
182 *
183 * Register|BitsName
184 * --------|--------
185 * EXT_WKUP_CTL | WDT_ALARM
186 *
187 * @retval Value between Min_Data=0 and Max_Data=0x1F
188 */
189 __STATIC_INLINE uint32_t ll_aon_wdt_get_alarm_counter(void)
190 {
191 return (uint32_t)(READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_ALARM) >> AON_EXT_WKUP_CTL_WDT_ALARM_Pos);
192 }
193
194 /** @} */
195
196 /** @defgroup AON_WDT_LL_EF_FLAG_Management FLAG_Management
197 * @{
198 */
199
200 /**
201 * @brief Indicate if the AON Watchdog Running Flag is set or not.
202 * @note This bit can be used to check if AON Watchdog is in running state.
203 *
204 * Register|BitsName
205 * --------|--------
206 * EXT_WKUP_CTL | WDT_RUNNING
207 *
208 * @retval State of bit (1 or 0).
209 */
210 __STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_running(void)
211 {
212 return (uint32_t)(READ_BITS(AON->EXT_WKUP_CTL, AON_EXT_WKUP_CTL_WDT_RUNNING) == (AON_EXT_WKUP_CTL_WDT_RUNNING));
213 }
214
215 /**
216 * @brief Indicate if the AON WDT Reboot Event Flag is set or not.
217 * @note This bit is set by hardware when the counter has reached alarm value.
218 * It can be cleared by writing 0 to this bit.
219 *
220 * Register|BitsName
221 * --------|--------
222 * SLP_EVENT | SLP_EVENT_WDT
223 *
224 * @retval State of bit (1 or 0).
225 */
226 __STATIC_INLINE uint32_t ll_aon_wdt_is_active_flag_reboot(void)
227 {
228 return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_WDT_REBOOT) == AON_SLP_EVENT_WDT_REBOOT);
229 }
230
231 /**
232 * @brief Clear Interrupt Status flag.
233 *
234 * Register|BitsName
235 * --------|--------
236 * SLP_EVENT| SLP_EVENT_WDT
237 *
238 * @retval None
239 */
240 __STATIC_INLINE void ll_aon_wdt_clear_flag_reboot(void)
241 {
242 WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_WDT_REBOOT);
243 }
244
245 /** @} */
246
247 /** @} */
248
249 #endif /* AON_WDT */
250
251 #ifdef __cplusplus
252 }
253 #endif
254
255 #endif /* __GR55XX_LL_AON_WDT_H__ */
256
257 /** @} */
258
259 /** @} */
260
261 /** @} */
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:157
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:175
ll_aon_wdt_reload_counter
__STATIC_INLINE void ll_aon_wdt_reload_counter(void)
Reloads AON WDT counter.
Definition: gr55xx_ll_aon_wdt.h:142
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:110
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:240
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:210
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:82
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:189
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:125
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:96
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:226