gr55xx_ll_tim.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_ll_tim.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of 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_TIMER TIMER
47 * @brief TIMER LL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55XX_LL_TIMER_H__
53 #define __GR55XX_LL_TIMER_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx.h"
61
62 #if defined (TIMER0) || defined (TIMER1)
63
64 /** @defgroup TIMER_LL_STRUCTURES Structures
65 * @{
66 */
67
68 /* Exported types ------------------------------------------------------------*/
69 /** @defgroup TIMER_LL_ES_INIT TIMER Exported init structures
70 * @{
71 */
72
73 /**
74 * @brief LL TIMER init Structure definition
75 */
76 typedef struct _ll_timer_init_t
77 {
78 uint32_t auto_reload; /**< Specifies the auto reload value to be loaded into the active
79 Auto-Reload Register at the next update event.
80 This parameter must be a number between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF.
81 Some timer instances may support 32 bits counters. In that case this parameter must be a number between 0x0000 and 0xFFFFFFFF.
82
83 This feature can be modified afterwards using unitary function @ref ll_timer_set_auto_reload().*/
84 } ll_timer_init_t;
85 /** @} */
86
87 /** @} */
88
89 /**
90 * @defgroup TIMER_LL_TIMER_MACRO Defines
91 * @{
92 */
93
94 /* Exported constants --------------------------------------------------------*/
95 /** @defgroup TIMER_LL_Exported_Constants TIMER Exported Constants
96 * @{
97 */
98
99 /** @defgroup TIMER_LL_EC_DEFAULT_CONFIG InitStrcut default configuartion
100 * @{
101 */
102 /**
103 * @brief LL TIMER InitStrcut default configuartion
104 */
105 #define TIMER_DEFAULT_CONFIG \
106 { \
107 .auto_reload = SystemCoreClock - 1, \
108 }
109 /** @} */
110
111 /** @} */
112
113 /* Exported macro ------------------------------------------------------------*/
114 /** @defgroup TIMER_LL_Exported_Macros TIMER Exported Macros
115 * @{
116 */
117
118 /** @defgroup TIMER_LL_EM_WRITE_READ Common Write and read registers Macros
119 * @{
120 */
121
122 /**
123 * @brief Write a value in TIMER register
124 * @param __instance__ TIMER instance
125 * @param __REG__ Register to be written
126 * @param __VALUE__ Value to be written in the register
127 * @retval None
128 */
129 #define LL_TIMER_WriteReg(__instance__, __REG__, __VALUE__) WRITE_REG(__instance__->__REG__, (__VALUE__))
130
131 /**
132 * @brief Read a value in TIMER register
133 * @param __instance__ TIMER instance
134 * @param __REG__ Register to be read
135 * @retval Register value
136 */
137 #define LL_TIMER_ReadReg(__instance__, __REG__) READ_REG(__instance__->__REG__)
138
139 /** @} */
140
141 /** @} */
142
143 /** @} */
144
145 /* Exported functions --------------------------------------------------------*/
146 /** @defgroup TIMER_LL_DRIVER_FUNCTIONS Functions
147 * @{
148 */
149
150 /** @defgroup TIMER_LL_EF_Configuration Configuration functions
151 * @{
152 */
153
154 /**
155 * @brief Enable timer counter.
156 *
157 * Register|BitsName
158 * --------|--------
159 * CTRL | EN
160 *
161 * @param TIMERx Timer instance
162 * @retval None
163 */
164 __STATIC_INLINE void ll_timer_enable_counter(timer_regs_t *TIMERx)
165 {
166 SET_BITS(TIMERx->CTRL, TIMER_CTRL_EN);
167 }
168
169 /**
170 * @brief Disable timer counter.
171 *
172 * Register|BitsName
173 * --------|--------
174 * CTRL | EN
175 *
176 * @param TIMERx Timer instance
177 * @retval None
178 */
179 __STATIC_INLINE void ll_timer_disable_counter(timer_regs_t *TIMERx)
180 {
181 CLEAR_BITS(TIMERx->CTRL, TIMER_CTRL_EN);
182 }
183
184 /**
185 * @brief Indicate whether the timer counter is enabled.
186 *
187 * Register|BitsName
188 * --------|--------
189 * CTRL | EN
190 *
191 * @param TIMERx Timer instance
192 * @retval State of bit (1 or 0).
193 */
194 __STATIC_INLINE uint32_t ll_timer_is_enabled_counter(timer_regs_t *TIMERx)
195 {
196 return (READ_BITS(TIMERx->CTRL, TIMER_CTRL_EN) == (TIMER_CTRL_EN));
197 }
198
199 /**
200 * @brief Set the counter value.
201 *
202 * Register|BitsName
203 * --------|--------
204 * VALUE | VALUE
205 *
206 * @param TIMERx Timer instance
207 * @param counter Counter value (between Min_Data=0 and Max_Data=0xFFFFFFFF)
208 * @retval None
209 */
210 __STATIC_INLINE void ll_timer_set_counter(timer_regs_t *TIMERx, uint32_t counter)
211 {
212 WRITE_REG(TIMERx->VALUE, counter);
213 }
214
215 /**
216 * @brief Get the counter value.
217 *
218 * Register|BitsName
219 * --------|--------
220 * VALUE | VALUE
221 *
222 * @param TIMERx Timer instance
223 * @retval Counter value (between Min_Data=0 and Max_Data=0xFFFFFFFF)
224 */
225 __STATIC_INLINE uint32_t ll_timer_get_counter(timer_regs_t *TIMERx)
226 {
227 return (uint32_t)(READ_REG(TIMERx->VALUE));
228 }
229
230 /**
231 * @brief Set the auto-reload value.
232 * @note The counter is blocked while the auto-reload value is null.
233 *
234 * Register|BitsName
235 * --------|--------
236 * RELOAD | RELOAD
237 *
238 * @param TIMERx Timer instance
239 * @param auto_reload between Min_Data=0 and Max_Data=0xFFFFFFFF
240 * @retval None
241 */
242 __STATIC_INLINE void ll_timer_set_auto_reload(timer_regs_t *TIMERx, uint32_t auto_reload)
243 {
244 WRITE_REG(TIMERx->RELOAD, auto_reload);
245 }
246
247 /**
248 * @brief Get the auto-reload value.
249 *
250 * Register|BitsName
251 * --------|--------
252 * RELOAD | RELOAD
253 *
254 * @param TIMERx Timer instance
255 * @retval Auto-reload value
256 */
257 __STATIC_INLINE uint32_t ll_timer_get_auto_reload(timer_regs_t *TIMERx)
258 {
259 return (uint32_t)(READ_REG(TIMERx->RELOAD));
260 }
261
262 /** @} */
263
264 /** @defgroup TIM_LL_EF_IT_Management IT_Management
265 * @{
266 */
267
268 /**
269 * @brief Enable timer interrupt.
270 *
271 * Register|BitsName
272 * --------|--------
273 * CTRL | INTEN
274 *
275 * @param TIMERx Timer instance
276 * @retval None
277 */
278 __STATIC_INLINE void ll_timer_enable_it(timer_regs_t *TIMERx)
279 {
280 SET_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN);
281 }
282
283 /**
284 * @brief Disable timer interrput.
285 *
286 * Register|BitsName
287 * --------|--------
288 * CTRL | INTEN
289 *
290 * @param TIMERx Timer instance
291 * @retval None
292 */
293 __STATIC_INLINE void ll_timer_disable_it(timer_regs_t *TIMERx)
294 {
295 CLEAR_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN);
296 }
297
298 /**
299 * @brief Indicate whether the timer interrput is enabled.
300 *
301 * Register|BitsName
302 * --------|--------
303 * CTRL | INTEN
304 *
305 * @param TIMERx Timer instance
306 * @retval State of bit (1 or 0).
307 */
308 __STATIC_INLINE uint32_t ll_timer_is_enabled_it(timer_regs_t *TIMERx)
309 {
310 return (READ_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN) == (TIMER_CTRL_INTEN));
311 }
312
313 /** @} */
314
315 /** @defgroup TIM_LL_EF_FLAG_Management FLAG_Management
316 * @{
317 */
318
319 /**
320 * @brief Clear the interrupt flag (INTSTAT).
321 *
322 * Register|BitsName
323 * --------|--------
324 * INTSTAT | INTSTAT
325 *
326 * @param TIMERx Timer instance
327 * @retval None
328 */
329 __STATIC_INLINE void ll_timer_clear_flag_it(timer_regs_t *TIMERx)
330 {
331 WRITE_REG(TIMERx->INTSTAT, TIMER_INT_STAT);
332 }
333
334 /**
335 * @brief Indicate whether interrupt flag (INTSTAT) is set (interrupt is pending).
336 *
337 * Register|BitsName
338 * --------|--------
339 * INTSTAT | INTSTAT
340 *
341 * @param TIMERx Timer instance
342 * @retval State of bit (1 or 0).
343 */
344 __STATIC_INLINE uint32_t ll_timer_is_active_flag_it(timer_regs_t *TIMERx)
345 {
346 return (READ_BITS(TIMERx->INTSTAT, TIMER_INT_STAT) == (TIMER_INT_STAT));
347 }
348
349 /** @} */
350
351 /** @defgroup TIM_LL_Init Initialization and de-initialization functions
352 * @{
353 */
354
355 /**
356 * @brief De-initialize TIMER registers (Registers restored to their default values).
357 * @param TIMERx TIMER instance
358 * @retval An error_status_t enumeration value:
359 * - SUCCESS: TIMER registers are de-initialized
360 * - ERROR: TIMER registers are not de-initialized
361 */
362 error_status_t ll_timer_deinit(timer_regs_t *TIMERx);
363
364 /**
365 * @brief Initialize TIMER registers according to the specified
366 * parameters in TIMER_InitStruct.
367 * @param TIMERx TIMER instance
368 * @param p_timer_init Pointer to a ll_timer_init_t structure that contains the configuration
369 * information for the specified TIM peripheral.
370 * @retval An error_status_t enumeration value:
371 * - SUCCESS: TIMER registers are initialized according to p_timer_init content
372 * - ERROR: Problem occurred during TIMER Registers initialization
373 */
374 error_status_t ll_timer_init(timer_regs_t *TIMERx, ll_timer_init_t *p_timer_init);
375
376 /**
377 * @brief Set each field of a @ref ll_timer_init_t type structure to default value.
378 * @param p_timer_init Pointer to a @ref ll_timer_init_t structure
379 * whose fields will be set to default values.
380 * @retval None
381 */
382 void ll_timer_struct_init(ll_timer_init_t *p_timer_init);
383
384 /** @} */
385
386 /** @} */
387
388 #endif /* TIMER0 || TIMER1 */
389
390 #ifdef __cplusplus
391 }
392 #endif
393
394 #endif /* __GR55XX_LL_TIMER_H__ */
395
396 /** @} */
397
398 /** @} */
399
400 /** @} */
ll_timer_enable_counter
__STATIC_INLINE void ll_timer_enable_counter(timer_regs_t *TIMERx)
Enable timer counter.
Definition: gr55xx_ll_tim.h:164
ll_timer_init
error_status_t ll_timer_init(timer_regs_t *TIMERx, ll_timer_init_t *p_timer_init)
Initialize TIMER registers according to the specified parameters in TIMER_InitStruct.
ll_timer_disable_counter
__STATIC_INLINE void ll_timer_disable_counter(timer_regs_t *TIMERx)
Disable timer counter.
Definition: gr55xx_ll_tim.h:179
ll_timer_set_counter
__STATIC_INLINE void ll_timer_set_counter(timer_regs_t *TIMERx, uint32_t counter)
Set the counter value.
Definition: gr55xx_ll_tim.h:210
ll_timer_enable_it
__STATIC_INLINE void ll_timer_enable_it(timer_regs_t *TIMERx)
Enable timer interrupt.
Definition: gr55xx_ll_tim.h:278
ll_timer_clear_flag_it
__STATIC_INLINE void ll_timer_clear_flag_it(timer_regs_t *TIMERx)
Clear the interrupt flag (INTSTAT).
Definition: gr55xx_ll_tim.h:329
ll_timer_is_enabled_counter
__STATIC_INLINE uint32_t ll_timer_is_enabled_counter(timer_regs_t *TIMERx)
Indicate whether the timer counter is enabled.
Definition: gr55xx_ll_tim.h:194
ll_timer_deinit
error_status_t ll_timer_deinit(timer_regs_t *TIMERx)
De-initialize TIMER registers (Registers restored to their default values).
_ll_timer_init_t
LL TIMER init Structure definition.
Definition: gr55xx_ll_tim.h:77
ll_timer_get_counter
__STATIC_INLINE uint32_t ll_timer_get_counter(timer_regs_t *TIMERx)
Get the counter value.
Definition: gr55xx_ll_tim.h:225
ll_timer_struct_init
void ll_timer_struct_init(ll_timer_init_t *p_timer_init)
Set each field of a ll_timer_init_t type structure to default value.
_ll_timer_init_t::auto_reload
uint32_t auto_reload
Specifies the auto reload value to be loaded into the active Auto-Reload Register at the next update ...
Definition: gr55xx_ll_tim.h:78
ll_timer_set_auto_reload
__STATIC_INLINE void ll_timer_set_auto_reload(timer_regs_t *TIMERx, uint32_t auto_reload)
Set the auto-reload value.
Definition: gr55xx_ll_tim.h:242
ll_timer_get_auto_reload
__STATIC_INLINE uint32_t ll_timer_get_auto_reload(timer_regs_t *TIMERx)
Get the auto-reload value.
Definition: gr55xx_ll_tim.h:257
ll_timer_is_active_flag_it
__STATIC_INLINE uint32_t ll_timer_is_active_flag_it(timer_regs_t *TIMERx)
Indicate whether interrupt flag (INTSTAT) is set (interrupt is pending).
Definition: gr55xx_ll_tim.h:344
ll_timer_init_t
struct _ll_timer_init_t ll_timer_init_t
LL TIMER init Structure definition.
ll_timer_is_enabled_it
__STATIC_INLINE uint32_t ll_timer_is_enabled_it(timer_regs_t *TIMERx)
Indicate whether the timer interrput is enabled.
Definition: gr55xx_ll_tim.h:308
ll_timer_disable_it
__STATIC_INLINE void ll_timer_disable_it(timer_regs_t *TIMERx)
Disable timer interrput.
Definition: gr55xx_ll_tim.h:293