gr55xx_ll_calendar.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_calendar.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of CALENDAR 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_CALENDAR CALENDAR
47 * @brief CALENDAR LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_CALENDAR_H__
53 #define __GR55XX_LL_CALENDAR_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61
62 #if defined(AON)
63
64 /**
65 * @defgroup CALENDAR_LL_MACRO Defines
66 * @{
67 */
68 /* Exported constants --------------------------------------------------------*/
69 /** @defgroup CALENDAR_LL_Exported_Constants CALENDAR Exported Constants
70 * @{
71 */
72
73 /** @defgroup CALENDAR_LL_EC_CLOCK_DIV Clock divider
74 * @{
75 */
76 #define LL_CALENDAR_DIV_NONE ((uint32_t)0x00U) /**< Select RTC clock */
77 #define LL_CALENDAR_DIV_32 ((uint32_t)0x01U << AON_CALENDAR_TIMER_CTL_CLK_SEL_Pos) /**< Select 1/32 divider */
78 #define LL_CALENDAR_DIV_64 ((uint32_t)0x02U << AON_CALENDAR_TIMER_CTL_CLK_SEL_Pos) /**< Select 1/64 divider */
79 #define LL_CALENDAR_DIV_128 ((uint32_t)0x03U << AON_CALENDAR_TIMER_CTL_CLK_SEL_Pos) /**< Select 1/128 divider */
80 #define LL_CALENDAR_DIV_256 ((uint32_t)0x04U << AON_CALENDAR_TIMER_CTL_CLK_SEL_Pos) /**< Select 1/256 divider */
81 #define LL_CALENDAR_NO_CLOCK ((uint32_t)0x05U << AON_CALENDAR_TIMER_CTL_CLK_SEL_Pos) /**< Select no clock */
82 /** @} */
83
84 /** @} */
85 /** @} */
86
87 /* Exported functions --------------------------------------------------------*/
88 /** @defgroup CALENDAR_LL_DRIVER_FUNCTIONS Functions
89 * @{
90 */
91
92 /** @defgroup CALENDAR_LL_EF_Configuration Configuration functions
93 * @{
94 */
95
96 /**
97 * @brief Enable calendar counter.
98 *
99 * Register|BitsName
100 * --------|--------
101 * CALENDAR_TIMER_CTL | EN
102 *
103 * @retval None
104 */
105 __STATIC_INLINE void ll_calendar_enable(void)
106 {
107 SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN);
108 }
109
110 /**
111 * @brief Disable calendar counter.
112 *
113 * Register|BitsName
114 * --------|--------
115 * CALENDAR_TIMER_CTL | EN
116 *
117 * @retval None
118 */
119 __STATIC_INLINE void ll_calendar_disable(void)
120 {
121 CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN);
122 }
123
124 /**
125 * @brief Check if the CALENDAR peripheral is enabled or disabled.
126 *
127 * Register|BitsName
128 * --------|--------
129 * CALENDAR_TIMER_CTL | EN
130 *
131 * @retval State of bit (1 or 0).
132 */
133 __STATIC_INLINE uint32_t ll_calendar_is_enabled(void)
134 {
135 return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN) == (AON_CALENDAR_TIMER_CTL_EN));
136 }
137
138 /**
139 * @brief Reloads CALENDAR counter.
140 *
141 * Register|BitsName
142 * --------|--------
143 * CALENDAR_TIMER_CTL | VAL_LOAD
144 * TIMER_VALUE | TIMER_VALUE
145 *
146 * @retval None
147 */
148 __STATIC_INLINE void ll_calendar_reload_counter(uint32_t counter)
149 {
150 WRITE_REG(AON->TIMER_VALUE, counter);
151 SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_VAL_LOAD);
152 }
153
154 /**
155 * @brief Reloads CALENDAR alarm.
156 *
157 * Register|BitsName
158 * --------|--------
159 * CALENDAR_TIMER_CTL | ALARM_VAL_LOAD
160 * TIMER_VALUE | TIMER_VALUE
161 *
162 * @retval None
163 */
164 __STATIC_INLINE void ll_calendar_reload_alarm(uint32_t alarm)
165 {
166 WRITE_REG(AON->TIMER_VALUE, alarm);
167 SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_VAL_LOAD);
168 }
169
170 /**
171 * @brief Read the CALENDAR counter current value.
172 *
173 * Register|BitsName
174 * --------|--------
175 * AON_PAD_CTL1 | CAL_TIMER
176 * TIMER_VAL | TIMER_VAL_READ
177 *
178 * @retval Value for current counter which should ranging between 0 ~ 0xFFFF_FFFF
179 */
180 __STATIC_INLINE uint32_t ll_calendar_get_counter(void)
181 {
182 GLOBAL_EXCEPTION_DISABLE();
183 MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_CAL_TIMER);
184 GLOBAL_EXCEPTION_ENABLE();
185 return (uint32_t)READ_REG(AON->TIMER_VAL);
186 }
187
188 /**
189 * @brief Read the CALENDAR counter alarm value.
190 *
191 * Register|BitsName
192 * --------|--------
193 * AON_PAD_CTL1 | CAL_ALARM
194 * TIMER_VAL | TIMER_VAL_READ
195 *
196 * @retval Value for current alarm which should ranging between 0 ~ 0xFFFF_FFFF
197 */
198 __STATIC_INLINE uint32_t ll_calendar_get_alarm(void)
199 {
200 GLOBAL_EXCEPTION_DISABLE();
201 MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_CAL_ALARM);
202 GLOBAL_EXCEPTION_ENABLE();
203 return (uint32_t)READ_REG(AON->TIMER_VAL);
204 }
205
206 /**
207 * @brief Get the CALENDAR wrap-around value.
208 * @note The value should be read multiple times until get the same value in at least two reads.
209 *
210 * Register|BitsName
211 * --------|--------
212 * CALENDAR_TIMER_CTL | WRAP_CNT
213 *
214 * @retval Value between Min_Data=0 and Max_Data=0xF
215 */
216 __STATIC_INLINE uint32_t ll_calendar_get_wrapcnt(void)
217 {
218 return (uint32_t)(READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_CNT) >> AON_CALENDAR_TIMER_CTL_WRAP_CNT_Pos);
219 }
220
221 /**
222 * @brief Select the CALENDAR clock divider.
223 *
224 * Register|BitsName
225 * --------|--------
226 * CALENDAR_TIMER_CTL | CLK_SEL
227 *
228 * @param div This parameter can be one of the following values:
229 * @arg @ref LL_CALENDAR_DIV_NONE
230 * @arg @ref LL_CALENDAR_DIV_32
231 * @arg @ref LL_CALENDAR_DIV_64
232 * @arg @ref LL_CALENDAR_DIV_128
233 * @arg @ref LL_CALENDAR_DIV_256
234 * @arg @ref LL_CALENDAR_NO_CLOCK
235 * @retval None
236 */
237 __STATIC_INLINE void ll_calendar_set_clock_div(uint32_t div)
238 {
239 MODIFY_REG(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_CLK_SEL, div);
240 }
241
242 /**
243 * @brief Enable calendar alarm interrupt.
244 *
245 * Register|BitsName
246 * --------|--------
247 * CALENDAR_TIMER_CTL | ALARM_INT_EN
248 *
249 * @retval None
250 */
251 __STATIC_INLINE void ll_calendar_it_enable_alarm(void)
252 {
253 SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN);
254 }
255
256 /**
257 * @brief Disable calendar alarm interrupt.
258 *
259 * Register|BitsName
260 * --------|--------
261 * CALENDAR_TIMER_CTL | ALARM_INT_EN
262 *
263 * @retval None
264 */
265 __STATIC_INLINE void ll_calendar_it_disable_alarm(void)
266 {
267 CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN);
268 }
269
270 /**
271 * @brief Check if the CALENDAR alarm interrupt is enabled or disabled.
272 *
273 * Register|BitsName
274 * --------|--------
275 * CALENDAR_TIMER_CTL | ALARM_INT_EN
276 *
277 * @retval State of bit (1 or 0).
278 */
279 __STATIC_INLINE uint32_t ll_calendar_it_is_enabled_alarm(void)
280 {
281 return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN) == (AON_CALENDAR_TIMER_CTL_ALARM_INT_EN));
282 }
283
284 /**
285 * @brief Enable calendar wrap interrupt.
286 *
287 * Register|BitsName
288 * --------|--------
289 * CALENDAR_TIMER_CTL | WRAP_INT_EN
290 *
291 * @retval None
292 */
293 __STATIC_INLINE void ll_calendar_it_enable_wrap(void)
294 {
295 SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN);
296 }
297
298 /**
299 * @brief Disable calendar warp interrupt.
300 *
301 * Register|BitsName
302 * --------|--------
303 * CALENDAR_TIMER_CTL | WRAP_INT_EN
304 *
305 * @retval None
306 */
307 __STATIC_INLINE void ll_calendar_it_disable_wrap(void)
308 {
309 CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN);
310 }
311
312 /**
313 * @brief Check if the CALENDAR wrap interrupt is enabled or disabled.
314 *
315 * Register|BitsName
316 * --------|--------
317 * CALENDAR_TIMER_CTL | WRAP_INT_EN
318 *
319 * @retval State of bit (1 or 0).
320 */
321 __STATIC_INLINE uint32_t ll_calendar_it_is_enabled_wrap(void)
322 {
323 return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN) == (AON_CALENDAR_TIMER_CTL_WRAP_INT_EN));
324 }
325
326 /** @} */
327
328 /** @defgroup CALENDAR_LL_EF_FLAG_Management FLAG_Management
329 * @{
330 */
331
332 /**
333 * @brief Indicate if the CALENDAR alarm event flag is set or not.
334 * @note This bit is set by hardware when the counter has reached alarm value.
335 * It can be cleared by writing 0 to this bit.
336 *
337 * Register|BitsName
338 * --------|--------
339 * SLP_EVENT | CALENDAR_TIMER_ALARM
340 *
341 * @retval State of bit (1 or 0).
342 */
343 __STATIC_INLINE uint32_t ll_calendar_is_active_flag_alarm(void)
344 {
345 return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_CALENDAR_TIMER_ALARM) == AON_SLP_EVENT_CALENDAR_TIMER_ALARM);
346 }
347
348 /**
349 * @brief Indicate if the CALENDAR wrap event flag is set or not.
350 * @note This bit is set by hardware when the counter has overflow.
351 * It can be cleared by writing 0 to this bit.
352 *
353 * Register|BitsName
354 * --------|--------
355 * SLP_EVENT | CALENDAR_TIMER_WRAP
356 *
357 * @retval State of bit (1 or 0).
358 */
359 __STATIC_INLINE uint32_t ll_calendar_is_active_flag_wrap(void)
360 {
361 return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_CALENDAR_TIMER_WRAP) == AON_SLP_EVENT_CALENDAR_TIMER_WRAP);
362 }
363
364 /**
365 * @brief Clear calendar alarm interrupt flag.
366 *
367 * Register|BitsName
368 * --------|--------
369 * SLP_EVENT| CALENDAR_TIMER_ALARM
370 *
371 * @retval None
372 */
373 __STATIC_INLINE void ll_calendar_clear_flag_alarm(void)
374 {
375 GLOBAL_EXCEPTION_DISABLE();
376 WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_CALENDAR_TIMER_ALARM);
377 GLOBAL_EXCEPTION_ENABLE();
378 }
379
380 /**
381 * @brief Clear calendar wrap interrupt flag.
382 *
383 * Register|BitsName
384 * --------|--------
385 * SLP_EVENT| CALENDAR_TIMER_WRAP
386 *
387 * @retval None
388 */
389 __STATIC_INLINE void ll_calendar_clear_flag_wrap(void)
390 {
391 GLOBAL_EXCEPTION_DISABLE();
392 WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_CALENDAR_TIMER_WRAP);
393 GLOBAL_EXCEPTION_ENABLE();
394 }
395
396 /** @} */
397
398 /** @} */
399
400 #endif /* CALENDAR */
401
402 #ifdef __cplusplus
403 }
404 #endif
405
406 #endif /* __GR55XX_LL_CALENDAR_H__ */
407
408 /** @} */
409
410 /** @} */
411
412 /** @} */
ll_calendar_is_enabled
__STATIC_INLINE uint32_t ll_calendar_is_enabled(void)
Check if the CALENDAR peripheral is enabled or disabled.
Definition: gr55xx_ll_calendar.h:133
ll_calendar_get_alarm
__STATIC_INLINE uint32_t ll_calendar_get_alarm(void)
Read the CALENDAR counter alarm value.
Definition: gr55xx_ll_calendar.h:198
ll_calendar_clear_flag_alarm
__STATIC_INLINE void ll_calendar_clear_flag_alarm(void)
Clear calendar alarm interrupt flag.
Definition: gr55xx_ll_calendar.h:373
ll_calendar_reload_counter
__STATIC_INLINE void ll_calendar_reload_counter(uint32_t counter)
Reloads CALENDAR counter.
Definition: gr55xx_ll_calendar.h:148
ll_calendar_is_active_flag_wrap
__STATIC_INLINE uint32_t ll_calendar_is_active_flag_wrap(void)
Indicate if the CALENDAR wrap event flag is set or not.
Definition: gr55xx_ll_calendar.h:359
ll_calendar_it_enable_alarm
__STATIC_INLINE void ll_calendar_it_enable_alarm(void)
Enable calendar alarm interrupt.
Definition: gr55xx_ll_calendar.h:251
ll_calendar_it_enable_wrap
__STATIC_INLINE void ll_calendar_it_enable_wrap(void)
Enable calendar wrap interrupt.
Definition: gr55xx_ll_calendar.h:293
ll_calendar_clear_flag_wrap
__STATIC_INLINE void ll_calendar_clear_flag_wrap(void)
Clear calendar wrap interrupt flag.
Definition: gr55xx_ll_calendar.h:389
ll_calendar_it_is_enabled_alarm
__STATIC_INLINE uint32_t ll_calendar_it_is_enabled_alarm(void)
Check if the CALENDAR alarm interrupt is enabled or disabled.
Definition: gr55xx_ll_calendar.h:279
ll_calendar_disable
__STATIC_INLINE void ll_calendar_disable(void)
Disable calendar counter.
Definition: gr55xx_ll_calendar.h:119
ll_calendar_enable
__STATIC_INLINE void ll_calendar_enable(void)
Enable calendar counter.
Definition: gr55xx_ll_calendar.h:105
ll_calendar_is_active_flag_alarm
__STATIC_INLINE uint32_t ll_calendar_is_active_flag_alarm(void)
Indicate if the CALENDAR alarm event flag is set or not.
Definition: gr55xx_ll_calendar.h:343
ll_calendar_set_clock_div
__STATIC_INLINE void ll_calendar_set_clock_div(uint32_t div)
Select the CALENDAR clock divider.
Definition: gr55xx_ll_calendar.h:237
ll_calendar_reload_alarm
__STATIC_INLINE void ll_calendar_reload_alarm(uint32_t alarm)
Reloads CALENDAR alarm.
Definition: gr55xx_ll_calendar.h:164
ll_calendar_get_wrapcnt
__STATIC_INLINE uint32_t ll_calendar_get_wrapcnt(void)
Get the CALENDAR wrap-around value.
Definition: gr55xx_ll_calendar.h:216
ll_calendar_it_disable_alarm
__STATIC_INLINE void ll_calendar_it_disable_alarm(void)
Disable calendar alarm interrupt.
Definition: gr55xx_ll_calendar.h:265
ll_calendar_it_disable_wrap
__STATIC_INLINE void ll_calendar_it_disable_wrap(void)
Disable calendar warp interrupt.
Definition: gr55xx_ll_calendar.h:307
ll_calendar_get_counter
__STATIC_INLINE uint32_t ll_calendar_get_counter(void)
Read the CALENDAR counter current value.
Definition: gr55xx_ll_calendar.h:180
ll_calendar_it_is_enabled_wrap
__STATIC_INLINE uint32_t ll_calendar_it_is_enabled_wrap(void)
Check if the CALENDAR wrap interrupt is enabled or disabled.
Definition: gr55xx_ll_calendar.h:321