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  * \rst
100  * +----------------------+-----------------------------------+
101  * | Register | BitsName |
102  * +======================+===================================+
103  * | CALENDAR_TIMER_CTL | EN |
104  * +----------------------+-----------------------------------+
105  * \endrst
106  *
107  * @retval None
108  */
109 __STATIC_INLINE void ll_calendar_enable(void)
110 {
111  SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN);
112 }
113 
114 /**
115  * @brief Disable calendar counter.
116  *
117  * \rst
118  * +----------------------+-----------------------------------+
119  * | Register | BitsName |
120  * +======================+===================================+
121  * | CALENDAR_TIMER_CTL | EN |
122  * +----------------------+-----------------------------------+
123  * \endrst
124  *
125  * @retval None
126  */
127 __STATIC_INLINE void ll_calendar_disable(void)
128 {
129  CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN);
130 }
131 
132 /**
133  * @brief Check if the CALENDAR peripheral is enabled or disabled.
134  *
135  * \rst
136  * +----------------------+-----------------------------------+
137  * | Register | BitsName |
138  * +======================+===================================+
139  * | CALENDAR_TIMER_CTL | EN |
140  * +----------------------+-----------------------------------+
141  * \endrst
142  *
143  * @retval State of bit (1 or 0).
144  */
145 __STATIC_INLINE uint32_t ll_calendar_is_enabled(void)
146 {
147  return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_EN) == (AON_CALENDAR_TIMER_CTL_EN));
148 }
149 
150 /**
151  * @brief Reloads CALENDAR counter.
152  *
153  * \rst
154  * +----------------------+-----------------------------------+
155  * | Register | BitsName |
156  * +======================+===================================+
157  * | CALENDAR_TIMER_CTL | VAL_LOAD |
158  * +----------------------+-----------------------------------+
159  * \endrst
160  * TIMER_VALUE | TIMER_VALUE
161  *
162  * @retval None
163  */
164 __STATIC_INLINE void ll_calendar_reload_counter(uint32_t counter)
165 {
166  WRITE_REG(AON->TIMER_VALUE, counter);
167  SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_VAL_LOAD);
168 }
169 
170 /**
171  * @brief Reloads CALENDAR alarm.
172  *
173  * \rst
174  * +----------------------+-----------------------------------+
175  * | Register | BitsName |
176  * +======================+===================================+
177  * | CALENDAR_TIMER_CTL | ALARM_VAL_LOAD |
178  * +----------------------+-----------------------------------+
179  * \endrst
180  * TIMER_VALUE | TIMER_VALUE
181  *
182  * @retval None
183  */
184 __STATIC_INLINE void ll_calendar_reload_alarm(uint32_t alarm)
185 {
186  WRITE_REG(AON->TIMER_VALUE, alarm);
187  SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_VAL_LOAD);
188 }
189 
190 /**
191  * @brief Read the CALENDAR counter current value.
192  *
193  * \rst
194  * +----------------------+-----------------------------------+
195  * | Register | BitsName |
196  * +======================+===================================+
197  * | AON_PAD_CTL1 | CAL_TIMER |
198  * +----------------------+-----------------------------------+
199  * \endrst
200  * TIMER_VAL | TIMER_VAL_READ
201  *
202  * @retval Value for current counter which should ranging between 0 ~ 0xFFFF_FFFF
203  */
204 __STATIC_INLINE uint32_t ll_calendar_get_counter(void)
205 {
206  GLOBAL_EXCEPTION_DISABLE();
207  MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_CAL_TIMER);
208  GLOBAL_EXCEPTION_ENABLE();
209  return (uint32_t)READ_REG(AON->TIMER_VAL);
210 }
211 
212 /**
213  * @brief Read the CALENDAR counter alarm value.
214  *
215  * \rst
216  * +----------------------+-----------------------------------+
217  * | Register | BitsName |
218  * +======================+===================================+
219  * | AON_PAD_CTL1 | CAL_ALARM |
220  * +----------------------+-----------------------------------+
221  * \endrst
222  * TIMER_VAL | TIMER_VAL_READ
223  *
224  * @retval Value for current alarm which should ranging between 0 ~ 0xFFFF_FFFF
225  */
226 __STATIC_INLINE uint32_t ll_calendar_get_alarm(void)
227 {
228  GLOBAL_EXCEPTION_DISABLE();
229  MODIFY_REG(AON->AON_PAD_CTL1, AON_PAD_CTL1_TIMER_READ_SEL, AON_PAD_CTL1_TIMER_READ_SEL_CAL_ALARM);
230  GLOBAL_EXCEPTION_ENABLE();
231  return (uint32_t)READ_REG(AON->TIMER_VAL);
232 }
233 
234 /**
235  * @brief Get the CALENDAR wrap-around value.
236  * @note The value should be read multiple times until get the same value in at least two reads.
237  *
238  * \rst
239  * +----------------------+-----------------------------------+
240  * | Register | BitsName |
241  * +======================+===================================+
242  * | CALENDAR_TIMER_CTL | WRAP_CNT |
243  * +----------------------+-----------------------------------+
244  * \endrst
245  *
246  * @retval Value between Min_Data=0 and Max_Data=0xF
247  */
248 __STATIC_INLINE uint32_t ll_calendar_get_wrapcnt(void)
249 {
250  return (uint32_t)(READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_CNT) >> AON_CALENDAR_TIMER_CTL_WRAP_CNT_Pos);
251 }
252 
253 /**
254  * @brief Select the CALENDAR clock divider.
255  *
256  * \rst
257  * +----------------------+-----------------------------------+
258  * | Register | BitsName |
259  * +======================+===================================+
260  * | CALENDAR_TIMER_CTL | CLK_SEL |
261  * +----------------------+-----------------------------------+
262  * \endrst
263  *
264  * @param div This parameter can be one of the following values:
265  * @arg @ref LL_CALENDAR_DIV_NONE
266  * @arg @ref LL_CALENDAR_DIV_32
267  * @arg @ref LL_CALENDAR_DIV_64
268  * @arg @ref LL_CALENDAR_DIV_128
269  * @arg @ref LL_CALENDAR_DIV_256
270  * @arg @ref LL_CALENDAR_NO_CLOCK
271  * @retval None
272  */
273 __STATIC_INLINE void ll_calendar_set_clock_div(uint32_t div)
274 {
275  MODIFY_REG(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_CLK_SEL, div);
276 }
277 
278 /**
279  * @brief Enable calendar alarm interrupt.
280  *
281  * \rst
282  * +----------------------+-----------------------------------+
283  * | Register | BitsName |
284  * +======================+===================================+
285  * | CALENDAR_TIMER_CTL | ALARM_INT_EN |
286  * +----------------------+-----------------------------------+
287  * \endrst
288  *
289  * @retval None
290  */
291 __STATIC_INLINE void ll_calendar_it_enable_alarm(void)
292 {
293  SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN);
294 }
295 
296 /**
297  * @brief Disable calendar alarm interrupt.
298  *
299  * \rst
300  * +----------------------+-----------------------------------+
301  * | Register | BitsName |
302  * +======================+===================================+
303  * | CALENDAR_TIMER_CTL | ALARM_INT_EN |
304  * +----------------------+-----------------------------------+
305  * \endrst
306  *
307  * @retval None
308  */
309 __STATIC_INLINE void ll_calendar_it_disable_alarm(void)
310 {
311  CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN);
312 }
313 
314 /**
315  * @brief Check if the CALENDAR alarm interrupt is enabled or disabled.
316  *
317  * \rst
318  * +----------------------+-----------------------------------+
319  * | Register | BitsName |
320  * +======================+===================================+
321  * | CALENDAR_TIMER_CTL | ALARM_INT_EN |
322  * +----------------------+-----------------------------------+
323  * \endrst
324  *
325  * @retval State of bit (1 or 0).
326  */
327 __STATIC_INLINE uint32_t ll_calendar_it_is_enabled_alarm(void)
328 {
329  return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_ALARM_INT_EN) == (AON_CALENDAR_TIMER_CTL_ALARM_INT_EN));
330 }
331 
332 /**
333  * @brief Enable calendar wrap interrupt.
334  *
335  * \rst
336  * +----------------------+-----------------------------------+
337  * | Register | BitsName |
338  * +======================+===================================+
339  * | CALENDAR_TIMER_CTL | WRAP_INT_EN |
340  * +----------------------+-----------------------------------+
341  * \endrst
342  *
343  * @retval None
344  */
345 __STATIC_INLINE void ll_calendar_it_enable_wrap(void)
346 {
347  SET_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN);
348 }
349 
350 /**
351  * @brief Disable calendar warp interrupt.
352  *
353  * \rst
354  * +----------------------+-----------------------------------+
355  * | Register | BitsName |
356  * +======================+===================================+
357  * | CALENDAR_TIMER_CTL | WRAP_INT_EN |
358  * +----------------------+-----------------------------------+
359  * \endrst
360  *
361  * @retval None
362  */
363 __STATIC_INLINE void ll_calendar_it_disable_wrap(void)
364 {
365  CLEAR_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN);
366 }
367 
368 /**
369  * @brief Check if the CALENDAR wrap interrupt is enabled or disabled.
370  *
371  * \rst
372  * +----------------------+-----------------------------------+
373  * | Register | BitsName |
374  * +======================+===================================+
375  * | CALENDAR_TIMER_CTL | WRAP_INT_EN |
376  * +----------------------+-----------------------------------+
377  * \endrst
378  *
379  * @retval State of bit (1 or 0).
380  */
381 __STATIC_INLINE uint32_t ll_calendar_it_is_enabled_wrap(void)
382 {
383  return (READ_BITS(AON->CALENDAR_TIMER_CTL, AON_CALENDAR_TIMER_CTL_WRAP_INT_EN) == (AON_CALENDAR_TIMER_CTL_WRAP_INT_EN));
384 }
385 
386 /** @} */
387 
388 /** @defgroup CALENDAR_LL_EF_FLAG_Management FLAG_Management
389  * @{
390  */
391 
392 /**
393  * @brief Indicate if the CALENDAR alarm event flag is set or not.
394  * @note This bit is set by hardware when the counter has reached alarm value.
395  * It can be cleared by writing 0 to this bit.
396  *
397  * \rst
398  * +----------------------+-----------------------------------+
399  * | Register | BitsName |
400  * +======================+===================================+
401  * | SLP_EVENT | CALENDAR_TIMER_ALARM |
402  * +----------------------+-----------------------------------+
403  * \endrst
404  *
405  * @retval State of bit (1 or 0).
406  */
407 __STATIC_INLINE uint32_t ll_calendar_is_active_flag_alarm(void)
408 {
409  return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_CALENDAR_TIMER_ALARM) == AON_SLP_EVENT_CALENDAR_TIMER_ALARM);
410 }
411 
412 /**
413  * @brief Indicate if the CALENDAR wrap event flag is set or not.
414  * @note This bit is set by hardware when the counter has overflow.
415  * It can be cleared by writing 0 to this bit.
416  *
417  * \rst
418  * +----------------------+-----------------------------------+
419  * | Register | BitsName |
420  * +======================+===================================+
421  * | SLP_EVENT | CALENDAR_TIMER_WRAP |
422  * +----------------------+-----------------------------------+
423  * \endrst
424  *
425  * @retval State of bit (1 or 0).
426  */
427 __STATIC_INLINE uint32_t ll_calendar_is_active_flag_wrap(void)
428 {
429  return (uint32_t)(READ_BITS(AON->SLP_EVENT, AON_SLP_EVENT_CALENDAR_TIMER_WRAP) == AON_SLP_EVENT_CALENDAR_TIMER_WRAP);
430 }
431 
432 /**
433  * @brief Clear calendar alarm interrupt flag.
434  *
435  * \rst
436  * +----------------------+-----------------------------------+
437  * | Register | BitsName |
438  * +======================+===================================+
439  * | SLP_EVENT | CALENDAR_TIMER_ALARM |
440  * +----------------------+-----------------------------------+
441  * \endrst
442  *
443  * @retval None
444  */
445 __STATIC_INLINE void ll_calendar_clear_flag_alarm(void)
446 {
447  GLOBAL_EXCEPTION_DISABLE();
448  WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_CALENDAR_TIMER_ALARM);
449  GLOBAL_EXCEPTION_ENABLE();
450 }
451 
452 /**
453  * @brief Clear calendar wrap interrupt flag.
454  *
455  * \rst
456  * +----------------------+-----------------------------------+
457  * | Register | BitsName |
458  * +======================+===================================+
459  * | SLP_EVENT | CALENDAR_TIMER_WRAP |
460  * +----------------------+-----------------------------------+
461  * \endrst
462  *
463  * @retval None
464  */
465 __STATIC_INLINE void ll_calendar_clear_flag_wrap(void)
466 {
467  GLOBAL_EXCEPTION_DISABLE();
468  WRITE_REG(AON->SLP_EVENT, ~AON_SLP_EVENT_CALENDAR_TIMER_WRAP);
469  GLOBAL_EXCEPTION_ENABLE();
470 }
471 
472 /** @} */
473 
474 /** @} */
475 
476 #endif /* CALENDAR */
477 
478 #ifdef __cplusplus
479 }
480 #endif
481 
482 #endif /* __GR55XX_LL_CALENDAR_H__ */
483 
484 /** @} */
485 
486 /** @} */
487 
488 /** @} */
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:145
ll_calendar_get_alarm
__STATIC_INLINE uint32_t ll_calendar_get_alarm(void)
Read the CALENDAR counter alarm value.
Definition: gr55xx_ll_calendar.h:226
ll_calendar_clear_flag_alarm
__STATIC_INLINE void ll_calendar_clear_flag_alarm(void)
Clear calendar alarm interrupt flag.
Definition: gr55xx_ll_calendar.h:445
ll_calendar_reload_counter
__STATIC_INLINE void ll_calendar_reload_counter(uint32_t counter)
Reloads CALENDAR counter.
Definition: gr55xx_ll_calendar.h:164
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:427
ll_calendar_it_enable_alarm
__STATIC_INLINE void ll_calendar_it_enable_alarm(void)
Enable calendar alarm interrupt.
Definition: gr55xx_ll_calendar.h:291
ll_calendar_it_enable_wrap
__STATIC_INLINE void ll_calendar_it_enable_wrap(void)
Enable calendar wrap interrupt.
Definition: gr55xx_ll_calendar.h:345
ll_calendar_clear_flag_wrap
__STATIC_INLINE void ll_calendar_clear_flag_wrap(void)
Clear calendar wrap interrupt flag.
Definition: gr55xx_ll_calendar.h:465
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:327
ll_calendar_disable
__STATIC_INLINE void ll_calendar_disable(void)
Disable calendar counter.
Definition: gr55xx_ll_calendar.h:127
ll_calendar_enable
__STATIC_INLINE void ll_calendar_enable(void)
Enable calendar counter.
Definition: gr55xx_ll_calendar.h:109
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:407
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:273
ll_calendar_reload_alarm
__STATIC_INLINE void ll_calendar_reload_alarm(uint32_t alarm)
Reloads CALENDAR alarm.
Definition: gr55xx_ll_calendar.h:184
ll_calendar_get_wrapcnt
__STATIC_INLINE uint32_t ll_calendar_get_wrapcnt(void)
Get the CALENDAR wrap-around value.
Definition: gr55xx_ll_calendar.h:248
ll_calendar_it_disable_alarm
__STATIC_INLINE void ll_calendar_it_disable_alarm(void)
Disable calendar alarm interrupt.
Definition: gr55xx_ll_calendar.h:309
ll_calendar_it_disable_wrap
__STATIC_INLINE void ll_calendar_it_disable_wrap(void)
Disable calendar warp interrupt.
Definition: gr55xx_ll_calendar.h:363
ll_calendar_get_counter
__STATIC_INLINE uint32_t ll_calendar_get_counter(void)
Read the CALENDAR counter current value.
Definition: gr55xx_ll_calendar.h:204
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:381