ll_sleep_timer.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file ll_sleep_timer.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of sleep timer LL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2023 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_SLP_TIMER SLP_TIMER
47  * @brief SLP_TIMER LL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef ___LL_SLEEP_TIMER_H__
53 #define ___LL_SLEEP_TIMER_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr5405.h"
61 
62 #if defined(SLP_TIMER0)
63 
64 /**
65  * @defgroup SLP_TIMER_LL_TIMER_MACRO Defines
66  * @{
67  */
68 
69 /* Exported constants --------------------------------------------------------*/
70 
71 /** @defgroup SLP_TIMER_LL_Exported_Constants SLP_TIMER Exported Constants
72  * @{
73  */
74 
75 
76 /** @defgroup SLP_TIMER_RUN_MODE Sleep Timer Run Mode
77  * @{
78  */
79 #define SLP_TIMER_CFG_CNT_SLP_ONLY (0x1U << SLP_TIMER_CFG_COUNT_MODE_POS)
80 #define SLP_TIMER_CFG_CNT_ANY_CONDITION (0x0U << SLP_TIMER_CFG_COUNT_MODE_POS)
81 #define SLP_TIMER_CFG_SINGLE_MODE (0x1U << SLP_TIMER_CFG_MODE_POS)
82 #define SLP_TIMER_CFG_AUTO_RELOAD (0x0U << SLP_TIMER_CFG_MODE_POS)
83 #define LL_SLEEP_TIMER_SINGLE_MODE_0 (SLP_TIMER_CFG_SINGLE_MODE | SLP_TIMER_CFG_CNT_SLP_ONLY)
84 #define LL_SLEEP_TIMER_SINGLE_MODE_1 (SLP_TIMER_CFG_SINGLE_MODE | SLP_TIMER_CFG_CNT_ANY_CONDITION)
85 #define LL_SLEEP_TIMER_AUTO_MODE (SLP_TIMER_CFG_AUTO_RELOAD | SLP_TIMER_CFG_CNT_ANY_CONDITION)
86 
87 /** @} */
88 
89 /** @} */
90 
91 /* Exported macro ------------------------------------------------------------*/
92 /** @defgroup SLP_TIMER_LL_Exported_Macros SLP_TIMER Exported Macros
93  * @{
94  */
95 
96 /** @defgroup SLP_TIMER_LL_EM_WRITE_READ Common write and read registers Macros
97  * @{
98  */
99 
100 /**
101  * @brief Write a value in SLP_TIMER register
102  * @param __instance__ SLP_TIMER instance
103  * @param __REG__ Register to be written
104  * @param __VALUE__ Value to be written in the register
105  * @retval None
106  */
107 #define LL_SLP_TIMER_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
108 
109 /**
110  * @brief Read a value in SLP_TIMER register
111  * @param __instance__ SLP_TIMER instance
112  * @param __REG__ Register to be read
113  * @retval Register value
114  */
115 #define LL_SLP_TIMER_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
116 
117 /** @} */
118 
119 /** @} */
120 
121 /** @} */
122 
123 
124 /* Exported functions --------------------------------------------------------*/
125 /** @defgroup SLP_TIMER_LL_DRIVER_FUNCTIONS Functions
126  * @{
127  */
128 
129 /** @defgroup SLP_TIMER_LL_EF_Configuration Configuration functions
130  * @{
131  */
132 
133 /**
134  * @brief Configure Sleep Timer Work mode and Start Sleep Timer.
135  *
136  * Register|BitsName
137  * --------|--------
138  * CFG0 | EN
139  * CFG0 | VAL_SET
140  * CFG_0 | MODE
141  * CFG_0 | COUNT_MODE
142  *
143  * @param SLP_TIMERx SLEEP TIMER instance
144  * @param mode SLEEP TIMER mode
145  * @retval None
146  */
147 __STATIC_INLINE void ll_sleep_timer_config_and_start(slp_timer_regs_t *SLP_TIMERx, uint32_t mode)
148 {
149  WRITE_REG(SLP_TIMERx->CFG, (SLP_TIMER_CFG_EN | SLP_TIMER_CFG_VAL_SET | SLP_TIMER_CFG_WEN | mode));
150 }
151 
152 /**
153  * @brief Enable sleep timer
154  *
155  * Register|BitsName
156  * --------|--------
157  * CFG0 | EN
158  *
159  * @param SLP_TIMERx SLEEP TIMER instance
160  * @retval None
161  */
162 __STATIC_INLINE void ll_sleep_timer_enable(slp_timer_regs_t *SLP_TIMERx)
163 {
164  MODIFY_REG(SLP_TIMERx->CFG, (SLP_TIMER_CFG_EN), (SLP_TIMER_CFG_EN | SLP_TIMER_CFG_WEN));
165 }
166 
167 /**
168  * @brief disable sleep timer
169  *
170  * Register|BitsName
171  * --------|--------
172  * CFG0 | EN
173  *
174  * @param SLP_TIMERx SLEEP TIMER instance
175  * @retval None
176  */
177 __STATIC_INLINE void ll_sleep_timer_disable(slp_timer_regs_t *SLP_TIMERx)
178 {
179  MODIFY_REG(SLP_TIMERx->CFG, (SLP_TIMER_CFG_EN), (SLP_TIMER_CFG_WEN));
180 }
181 
182 /**
183  * @brief enable sleep timer
184  *
185  * Register|BitsName
186  * --------|--------
187  * CFG0 | VAL_SET
188  *
189  * @param SLP_TIMERx SLEEP TIMER instance
190  * @retval None
191  */
192 __STATIC_INLINE void ll_sleep_timer_load_counter_value(slp_timer_regs_t *SLP_TIMERx)
193 {
194  MODIFY_REG(SLP_TIMERx->CFG, (SLP_TIMER_CFG_VAL_SET), (SLP_TIMER_CFG_VAL_SET | SLP_TIMER_CFG_WEN));
195 }
196 
197 /**
198  * @brief Set the Sleep Timer Work Mode.
199  *
200  * Register|BitsName
201  * --------|--------
202  * CFG_0 | MODE
203  * CFG_0 | COUNT_MODE
204  *
205  * @param SLP_TIMERx SLEEP TIMER instance
206  * @param mode This parameter can be one of the following values:
207  * @arg @ref LL_SLEEP_TIMER_SINGLE_MODE_0
208  * @arg @ref LL_SLEEP_TIMER_SINGLE_MODE_1
209  * @arg @ref LL_SLEEP_TIMER_AUTO_MODE
210  * @retval None
211  */
212 __STATIC_INLINE void ll_sleep_timer_set_mode(slp_timer_regs_t *SLP_TIMERx, uint32_t mode)
213 {
214  MODIFY_REG(SLP_TIMERx->CFG, (SLP_TIMER_CFG_MODE | SLP_TIMER_CFG_COUNT_MODE), (mode | SLP_TIMER_CFG_WEN));
215 }
216 
217 /**
218  * @brief Get the Sleep Timer Work Mode.
219  *
220  * Register|BitsName
221  * --------|--------
222  * CFG_0 | MODE
223  * CFG_0 | COUNT_MODE
224  *
225  * @param SLP_TIMERx SLEEP TIMER instance
226  * @retval Returned Value can be one of the following values:
227  * @arg @ref LL_SLEEP_TIMER_SINGLE_MODE_0
228  * @arg @ref LL_SLEEP_TIMER_SINGLE_MODE_1
229  * @arg @ref LL_SLEEP_TIMER_AUTO_MODE
230  */
231 __STATIC_INLINE uint32_t ll_sleep_timer_get_mode(slp_timer_regs_t *SLP_TIMERx)
232 {
233  return (uint32_t)(READ_BITS(SLP_TIMERx->CFG, (SLP_TIMER_CFG_MODE | SLP_TIMER_CFG_COUNT_MODE)));
234 }
235 
236 /**
237  * @brief check the sleep timer runing state.
238  *
239  * Register|BitsName
240  * --------|--------
241  * STAT | RUNNING
242  *
243  * @param SLP_TIMERx SLEEP TIMER instance
244  * @retval runing state of sleep timer (1 or 0).
245  */
246 __STATIC_INLINE uint32_t ll_sleep_timer_is_running(slp_timer_regs_t *SLP_TIMERx)
247 {
248  return (uint32_t)(READ_BITS(SLP_TIMERx->STAT, SLP_TIMER_STAT_RUNNING) == SLP_TIMER_STAT_RUNNING);
249 }
250 
251 /**
252  * @brief check the sleep timer busy state.
253  *
254  * Register|BitsName
255  * --------|--------
256  * STAT | BUSY
257  *
258  * @param SLP_TIMERx SLEEP TIMER instance
259  * @retval busy state of sleep timer (1 or 0).
260  */
261 __STATIC_INLINE uint32_t ll_sleep_timer_is_busy(slp_timer_regs_t *SLP_TIMERx)
262 {
263  return (uint32_t)(READ_BITS(SLP_TIMERx->STAT, SLP_TIMER_STAT_BUSY) == SLP_TIMER_STAT_BUSY);
264 }
265 
266 /**
267  * @brief check the sleep timer busy state.
268  *
269  * Register|BitsName
270  * --------|--------
271  * STAT | COUNTING
272  *
273  * @param SLP_TIMERx SLEEP TIMER instance
274  * @retval busy state of sleep timer (1 or 0).
275  */
276 __STATIC_INLINE uint32_t ll_sleep_timer_is_counting(slp_timer_regs_t *SLP_TIMERx)
277 {
278  return (uint32_t)(READ_BITS(SLP_TIMERx->STAT, SLP_TIMER_STAT_COUNTING) == SLP_TIMER_STAT_COUNTING);
279 }
280 
281 /**
282  * @brief Set the 32 bits reload value to register, which not real internal value.
283  *
284  * Register|BitsName
285  * --------|--------
286  * TIMER_W | VAL_SET
287  *
288  * @param SLP_TIMERx SLEEP TIMER instance
289  * @param value 32 bits count value loaded into the 32bit_timer
290  * @retval None
291  */
292 __STATIC_INLINE void ll_sleep_timer_set_counter_value(slp_timer_regs_t *SLP_TIMERx, uint32_t value)
293 {
294  WRITE_REG(SLP_TIMERx->TIMER_W, value);
295 }
296 
297 /**
298  * @brief Set the 32 bits reload value to register, which not real internal value.
299  *
300  * Register|BitsName
301  * --------|--------
302  * TIMER_W | VAL_SET
303  *
304  * @param SLP_TIMERx SLEEP TIMER instance
305  * @retval None
306  */
307 __STATIC_INLINE uint32_t ll_sleep_timer_get_counter_value(slp_timer_regs_t *SLP_TIMERx)
308 {
309  return (uint32_t)READ_REG(SLP_TIMERx->TIMER_W);
310 }
311 
312 /**
313  * @brief Get the current count value.
314 
315  *
316  * Register|BitsName
317  * --------|--------
318  * TIMER_R | VAL_READ
319  *
320  * @param SLP_TIMERx SLEEP TIMER instance
321  * @retval 32 bit SLEEP Timer Count Value
322  */
323 __STATIC_INLINE uint32_t ll_sleep_timer_get_counter_int_value(slp_timer_regs_t *SLP_TIMERx)
324 {
325  return (uint32_t)READ_REG(SLP_TIMERx->TIMER_R);
326 }
327 
328 /**
329  * @brief Clear the sleep timer interrupt status flag.
330  *
331  * Register|BitsName
332  * --------|--------
333  * INTSTAT | INTSTAT
334  *
335  * @retval None
336  */
337 __STATIC_INLINE void ll_sleep_timer_clear_flag_it(void)
338 {
339  WRITE_REG(AON_CTL->AON_SLP_EVENT, ~(AON_CTL_SLP_EVENT_SLP_TIMER));
340 }
341 
342 /** @} */
343 
344 /** @} */
345 
346 #endif /* SLP_TIMER */
347 
348 #ifdef __cplusplus
349 }
350 #endif
351 
352 #endif /* ___LL_SLEEP_TIMER_H__ */
353 
354 /** @} */
355 
356 /** @} */
357 
358 /** @} */
ll_sleep_timer_is_counting
__STATIC_INLINE uint32_t ll_sleep_timer_is_counting(slp_timer_regs_t *SLP_TIMERx)
check the sleep timer busy state.
Definition: ll_sleep_timer.h:276
gr5405.h
ll_sleep_timer_set_mode
__STATIC_INLINE void ll_sleep_timer_set_mode(slp_timer_regs_t *SLP_TIMERx, uint32_t mode)
Set the Sleep Timer Work Mode.
Definition: ll_sleep_timer.h:212
ll_sleep_timer_is_running
__STATIC_INLINE uint32_t ll_sleep_timer_is_running(slp_timer_regs_t *SLP_TIMERx)
check the sleep timer runing state.
Definition: ll_sleep_timer.h:246
AON_CTL
#define AON_CTL
Definition: gr5405.h:3
ll_sleep_timer_enable
__STATIC_INLINE void ll_sleep_timer_enable(slp_timer_regs_t *SLP_TIMERx)
Enable sleep timer.
Definition: ll_sleep_timer.h:162
ll_sleep_timer_set_counter_value
__STATIC_INLINE void ll_sleep_timer_set_counter_value(slp_timer_regs_t *SLP_TIMERx, uint32_t value)
Set the 32 bits reload value to register, which not real internal value.
Definition: ll_sleep_timer.h:292
ll_sleep_timer_config_and_start
__STATIC_INLINE void ll_sleep_timer_config_and_start(slp_timer_regs_t *SLP_TIMERx, uint32_t mode)
Configure Sleep Timer Work mode and Start Sleep Timer.
Definition: ll_sleep_timer.h:147
ll_sleep_timer_get_counter_value
__STATIC_INLINE uint32_t ll_sleep_timer_get_counter_value(slp_timer_regs_t *SLP_TIMERx)
Set the 32 bits reload value to register, which not real internal value.
Definition: ll_sleep_timer.h:307
ll_sleep_timer_load_counter_value
__STATIC_INLINE void ll_sleep_timer_load_counter_value(slp_timer_regs_t *SLP_TIMERx)
enable sleep timer
Definition: ll_sleep_timer.h:192
ll_sleep_timer_get_mode
__STATIC_INLINE uint32_t ll_sleep_timer_get_mode(slp_timer_regs_t *SLP_TIMERx)
Get the Sleep Timer Work Mode.
Definition: ll_sleep_timer.h:231
ll_sleep_timer_is_busy
__STATIC_INLINE uint32_t ll_sleep_timer_is_busy(slp_timer_regs_t *SLP_TIMERx)
check the sleep timer busy state.
Definition: ll_sleep_timer.h:261
ll_sleep_timer_get_counter_int_value
__STATIC_INLINE uint32_t ll_sleep_timer_get_counter_int_value(slp_timer_regs_t *SLP_TIMERx)
Get the current count value.
Definition: ll_sleep_timer.h:323
ll_sleep_timer_clear_flag_it
__STATIC_INLINE void ll_sleep_timer_clear_flag_it(void)
Clear the sleep timer interrupt status flag.
Definition: ll_sleep_timer.h:337
ll_sleep_timer_disable
__STATIC_INLINE void ll_sleep_timer_disable(slp_timer_regs_t *SLP_TIMERx)
disable sleep timer
Definition: ll_sleep_timer.h:177