gr533x_ll_sleep_timer.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_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 __GR533x_LL_SLEEP_TIMER_H__
53 #define __GR533x_LL_SLEEP_TIMER_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x.h"
61
62 #if defined(AON_CTL)
63
64 /** @defgroup AON_CTL_SLP_TIMER_CFG_0_MODE Sleep Timer Mode
65 * @{
66 */
67 #define SLP_TIMER_CFG0_CNT_SLP_ONLY (0x1U << SLP_TIMER_CFG0_COUNT_MODE_Pos) /**< Sleep_timer cnt slp onlt mode */
68 #define SLP_TIMER_CFG0_CNT_ANY_CONDITION (0x0U << SLP_TIMER_CFG0_COUNT_MODE_Pos) /**< Sleep_timer cnt any condition mode */
69 #define SLP_TIMER_CFG0_SINGLE_MODE (0x1U << SLP_TIMER_CFG0_MODE_Pos) /**< Sleep_timer single mode */
70 #define SLP_TIMER_CFG0_AUTO_RELOAD (0x0U << SLP_TIMER_CFG0_MODE_Pos) /**< Sleep_timer auto reload mode */
71 #define LL_SLEEP_TIMER_SINGLE_MODE_0 (SLP_TIMER_CFG0_SINGLE_MODE | SLP_TIMER_CFG0_CNT_SLP_ONLY) /**< Sleep_timer single mode 0 */
72 #define LL_SLEEP_TIMER_SINGLE_MODE_1 (SLP_TIMER_CFG0_SINGLE_MODE | SLP_TIMER_CFG0_CNT_ANY_CONDITION) /**< Sleep_timer single mode 1 */
73 #define LL_SLEEP_TIMER_AUTO_MODE (SLP_TIMER_CFG0_AUTO_RELOAD | SLP_TIMER_CFG0_CNT_ANY_CONDITION) /**< Sleep_timer auto mode */
74
75 /** @} */
76
77 /* Exported functions --------------------------------------------------------*/
78 /** @defgroup SLEEP_TIMER_LL_DRIVER_FUNCTIONS Functions
79 * @{
80 */
81
82 /**
83 * @brief Set the 32 bits Sleep Timer Value to WakeUp the MCU from DeepSleep Mode.
84 *
85 * Register|BitsName
86 * --------|--------
87 * SLP_TIMER_VAL_W | AON_CTL_SLP_TIMER_VAL_W_32B
88 *
89 * @param value 32 bits count value loaded into the 32bit_timer
90 * @retval None
91 */
92 __STATIC_INLINE void ll_sleep_timer_set_value(uint32_t value)
93 {
94 WRITE_REG(SLP_TIMER->TIMER_W, value);
95 }
96
97 /**
98 * @brief Get the 32 bit Sleep Timer Value to WakeUp the MCU from DeepSleep Mode.
99 *
100 * Register|BitsName
101 * --------|--------
102 * SLP_TIMER_VAL_W | AON_CTL_SLP_TIMER_VAL_W_32B
103 *
104 * @retval 32 bit AON Timer Count Value
105 */
106 __STATIC_INLINE uint32_t ll_sleep_timer_get_value(void)
107 {
108 return READ_REG(SLP_TIMER->TIMER_W);
109 }
110
111 /**
112 * @brief Get the real internal value of the sleep timer.
113 *
114 * Register|BitsName
115 * --------|--------
116 * SLP_TIMER_VAL_R | AON_CTL_SLP_TIMER_VAL_R_32B
117 *
118 * @retval 32 bit sleep Timer Count Value
119 */
120 __STATIC_INLINE uint32_t ll_sleep_timer_get_read_value(void)
121 {
122 return READ_REG(SLP_TIMER->TIMER_R);
123 }
124
125 /**
126 * @brief check the sleep timer runing state.
127 *
128 * Register|BitsName
129 * --------|--------
130 * SLP_TIMER_STS | AON_CTL_SLP_TIMER_STAT_STATUS
131 *
132 * @retval runing state of sleep timer (1 or 0).
133 */
134 __STATIC_INLINE uint32_t ll_sleep_timer_is_runing(void)
135 {
136 return (uint32_t)(READ_BITS(SLP_TIMER->STAT, SLP_TIMER_STAT_STAT) == SLP_TIMER_STAT_STAT);
137 }
138
139 /**
140 * @brief check the sleep timer busy state.
141 *
142 * Register|BitsName
143 * --------|--------
144 * SLP_TIMER_STS | AON_CTL_SLP_TIMER_STAT_BUSY
145 *
146 * @retval busy state of sleep timer (1 or 0).
147 */
148 __STATIC_INLINE uint32_t ll_sleep_timer_is_busy(void)
149 {
150 return (uint32_t)(READ_BITS(SLP_TIMER->STAT, SLP_TIMER_STAT_BUSY) == SLP_TIMER_STAT_BUSY);
151 }
152
153 /**
154 * @brief Set the Sleep Timer Work Mode.
155 *
156 * Register|BitsName
157 * --------|--------
158 * SLP_TIMER_CFG_0 | AON_CTL_SLP_TIMER_CFG_0_MODE
159 *
160 * @param mode of Sleep Timer work
161 * @retval None
162 */
163 __STATIC_INLINE void ll_sleep_timer_set_mode(uint32_t mode)
164 {
165 WRITE_REG(SLP_TIMER->CFG0, SLP_TIMER_CFG0_EN | SLP_TIMER_CFG0_VAL_SET | mode | SLP_TIMER_CFG0_CFG);
166 }
167 /**
168 * @brief disable sleep timer
169 *
170 * Register|BitsName
171 * --------|--------
172 * SLP_TIMER_CFG_0 | AON_TIMER_SLEEP_TIMER_CFG0_EN
173 *
174 * @retval None
175 */
176 __STATIC_INLINE void ll_sleep_timer_disable(void)
177 {
178 MODIFY_REG(SLP_TIMER->CFG0, SLP_TIMER_CFG0_EN, SLP_TIMER_CFG0_CFG);
179 }
180
181 /**
182 * @brief clear wake up event by sleep timer
183 *
184 * Register|BitsName
185 * --------|--------
186 * AON_SLP_EVENT | AON_CTL_SLP_EVENT_TIMER
187 *
188 * @retval None
189 */
190 __STATIC_INLINE void ll_sleep_timer_clear_sleep_event(void)
191 {
192 WRITE_REG(AON_CTL->AON_SLP_EVENT, ~AON_CTL_SLP_EVENT_SLP_TIMER);
193 }
194
195 /** @} */
196
197 #endif /* defined(AON_CTL) */
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* __GR533x_LL_SLEEP_TIMER_H__ */
204
205 /** @} */
206
207 /** @} */
208
209 /** @} */