gr55xx_ll_sleep_timer.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_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) 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_SLP_TIMER Sleep Timer
47 * @brief Sleep Timer LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_LL_SLEEP_TIMER_H__
53 #define __GR55xx_LL_SLEEP_TIMER_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61
62 #if defined (AON_CTL)
63
64 /** @defgroup LL_SLP_TIMER_MACRO Defines
65 * @{
66 */
67
68 /** @defgroup LL_SLP_TIMER_Exported_Constants Exported Constants
69 * @{
70 */
71
72 /** @defgroup LL_SLP_TIMER_CFG_0_MODE Sleep Timer Mode
73 * @{
74 */
75 #define SLP_TIMER_CFG0_CNT_SLP_ONLY (0x1U << SLP_TIMER_CFG0_COUNT_MODE_Pos)
76 #define SLP_TIMER_CFG0_CNT_ANY_CONDITION (0x0U << SLP_TIMER_CFG0_COUNT_MODE_Pos)
77 #define SLP_TIMER_CFG0_SINGLE_MODE (0x1U << SLP_TIMER_CFG0_MODE_Pos)
78 #define SLP_TIMER_CFG0_AUTO_RELOAD (0x0U << SLP_TIMER_CFG0_MODE_Pos)
79 #define LL_SLEEP_TIMER_SINGLE_MODE_0 (SLP_TIMER_CFG0_SINGLE_MODE | SLP_TIMER_CFG0_CNT_SLP_ONLY)
80 #define LL_SLEEP_TIMER_SINGLE_MODE_1 (SLP_TIMER_CFG0_SINGLE_MODE | SLP_TIMER_CFG0_CNT_ANY_CONDITION)
81 #define LL_SLEEP_TIMER_AUTO_MODE (SLP_TIMER_CFG0_AUTO_RELOAD | SLP_TIMER_CFG0_CNT_ANY_CONDITION)
82 /** @} */
83 /** @defgroup LL_SLP_TIMER_CLK_SEL Sleep Timer clock select defines
84 * @{
85 */
86 #define LL_SLEEP_TIMER_CLK_SEL_RNG_OSC (0x0U << SLP_TIMER_CLK_SEL_Pos)
87 #define LL_SLEEP_TIMER_CLK_SEL_XO (0x1U << SLP_TIMER_CLK_SEL_Pos)
88 #define LL_SLEEP_TIMER_CLK_SEL_RNG2_OSC (0x2U << SLP_TIMER_CLK_SEL_Pos)
89 #define LL_SLEEP_TIMER_CLK_SEL_RTC_OSC (0x3U << SLP_TIMER_CLK_SEL_Pos)
90 /** @} */
91
92 /** @} */
93
94 /** @} */
95
96 /* Exported functions --------------------------------------------------------*/
97 /** @defgroup LL_SLP_TIMER_DRIVER_FUNCTIONS Functions
98 * @{
99 */
100
101 /**
102 * @brief Set the Sleep Timer clock
103 *
104 * Register|BitsName
105 * --------|--------
106 * SLP_TIMER_CLK | slp_timer_clk_sel
107 * @param value This parameter can be a one of the following values:
108 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RNG_OSC
109 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_XO
110 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RNG2_OSC
111 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RTC_OSC
112 * @retval None
113 */
114 __STATIC_INLINE void ll_sleep_timer_set_clk(uint32_t value)
115 {
116 MODIFY_REG(SLP_TIMER->CLK, SLP_TIMER_CLK_SEL, value);
117 }
118
119 /**
120 * @brief Get the Sleep Timer clock
121 *
122 * Register|BitsName
123 * --------|--------
124 * SLP_TIMER_CLK | slp_timer_clk_sel
125 * @retval Sleep Timer clock source,the value can be the one of the following:
126 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RNG_OSC
127 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_XO
128 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RNG2_OSC
129 * @arg @ref LL_SLEEP_TIMER_CLK_SEL_RTC_OSC
130 */
131 __STATIC_INLINE uint32_t ll_sleep_timer_get_clk(void)
132 {
133 return (READ_BITS(SLP_TIMER->CLK, SLP_TIMER_CLK_SEL));
134 }
135
136 /**
137 * @brief Set the 32 bits Sleep Timer Value to WakeUp the MCU from DeepSleep Mode.
138 *
139 * Register|BitsName
140 * --------|--------
141 * SLP_TIMER_VAL_W | AON_CTL_SLP_TIMER_VAL_W_32B
142 *
143 * @param value 32 bits count value loaded into the 32bit_timer
144 * @retval None
145 */
146 __STATIC_FORCEINLINE void ll_sleep_timer_set_value(uint32_t value)
147 {
148 WRITE_REG(SLP_TIMER->TIMER_W, value);
149 }
150
151 /**
152 * @brief Get the 32 bit Sleep Timer Value to WakeUp the MCU from DeepSleep Mode.
153 *
154 * Register|BitsName
155 * --------|--------
156 * SLP_TIMER_VAL_W | AON_CTL_SLP_TIMER_VAL_W_32B
157 *
158 * @retval 32 bit AON Timer Count Value
159 */
160 __STATIC_INLINE uint32_t ll_sleep_timer_get_value(void)
161 {
162 return READ_REG(SLP_TIMER->TIMER_W);
163 }
164
165 /**
166 * @brief Get the real internal value of the sleep timer.
167 *
168 * Register|BitsName
169 * --------|--------
170 * SLP_TIMER_VAL_R | AON_CTL_SLP_TIMER_VAL_R_32B
171 *
172 * @retval 32 bit sleep Timer Count Value
173 */
174 __STATIC_FORCEINLINE uint32_t ll_sleep_timer_get_read_value(void)
175 {
176 return READ_REG(SLP_TIMER->TIMER_R);
177 }
178
179 /**
180 * @brief check the sleep timer runing state.
181 *
182 * Register|BitsName
183 * --------|--------
184 * SLP_TIMER_STS | AON_CTL_SLP_TIMER_STAT_STATUS
185 *
186 * @retval runing state of sleep timer (1 or 0).
187 */
188 __STATIC_INLINE uint32_t ll_sleep_timer_is_runing(void)
189 {
190 return (uint32_t)(READ_BITS(SLP_TIMER->STAT, SLP_TIMER_STAT_STAT) == SLP_TIMER_STAT_STAT);
191 }
192
193 /**
194 * @brief check the sleep timer busy state.
195 *
196 * Register|BitsName
197 * --------|--------
198 * SLP_TIMER_STS | AON_CTL_SLP_TIMER_STAT_BUSY
199 *
200 * @retval busy state of sleep timer (1 or 0).
201 */
202 __STATIC_FORCEINLINE uint32_t ll_sleep_timer_is_busy(void)
203 {
204 return (uint32_t)(READ_BITS(SLP_TIMER->STAT, SLP_TIMER_STAT_BUSY) == SLP_TIMER_STAT_BUSY);
205 }
206
207 /**
208 * @brief Set the Sleep Timer Work Mode.
209 *
210 * Register|BitsName
211 * --------|--------
212 * SLP_TIMER_CFG_0 | AON_CTL_SLP_TIMER_CFG_0_MODE
213 *
214 * @param mode of Sleep Timer work
215 * @retval None
216 */
217 __STATIC_FORCEINLINE void ll_sleep_timer_set_mode(uint32_t mode)
218 {
219 WRITE_REG(SLP_TIMER->CFG0, SLP_TIMER_CFG0_EN | SLP_TIMER_CFG0_VAL_SET | mode | SLP_TIMER_CFG0_CFG);
220 }
221 /**
222 * @brief disable sleep timer
223 *
224 * Register|BitsName
225 * --------|--------
226 * SLP_TIMER_CFG_0 | AON_TIMER_SLEEP_TIMER_CFG0_EN
227 *
228 * @retval None
229 */
230 __STATIC_FORCEINLINE void ll_sleep_timer_disable(void)
231 {
232 MODIFY_REG(SLP_TIMER->CFG0, SLP_TIMER_CFG0_EN, SLP_TIMER_CFG0_CFG);
233 }
234
235 /**
236 * @brief clear wake up event by sleep timer
237 *
238 * Register|BitsName
239 * --------|--------
240 * AON_SLP_EVENT | AON_CTL_SLP_EVENT_TIMER
241 *
242 * @retval None
243 */
244 __STATIC_INLINE void ll_sleep_timer_clear_sleep_event(void)
245 {
246 WRITE_REG(AON_CTL->AON_SLP_EVENT, ~AON_CTL_SLP_EVENT_SLP_TIMER);
247 }
248
249 /** @} */
250
251 #endif /* defined(AON_CTL) */
252
253 #ifdef __cplusplus
254 }
255 #endif
256
257 #endif /* __GR55xx_LL_SLEEP_TIMER_H__ */
258
259 /** @} */
260
261 /** @} */
262
263 /** @} */