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