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 * \rst
158 * +----------------------+-----------------------------------+
159 * | Register | BitsName |
160 * +======================+===================================+
161 * | CTRL | EN |
162 * +----------------------+-----------------------------------+
163 * \endrst
164 *
165 * @param TIMERx Timer instance
166 * @retval None
167 */
168 __STATIC_INLINE void ll_timer_enable_counter(timer_regs_t *TIMERx)
169 {
170 SET_BITS(TIMERx->CTRL, TIMER_CTRL_EN);
171 }
172
173 /**
174 * @brief Disable timer counter.
175 *
176 * \rst
177 * +----------------------+-----------------------------------+
178 * | Register | BitsName |
179 * +======================+===================================+
180 * | CTRL | EN |
181 * +----------------------+-----------------------------------+
182 * \endrst
183 *
184 * @param TIMERx Timer instance
185 * @retval None
186 */
187 __STATIC_INLINE void ll_timer_disable_counter(timer_regs_t *TIMERx)
188 {
189 CLEAR_BITS(TIMERx->CTRL, TIMER_CTRL_EN);
190 }
191
192 /**
193 * @brief Indicate whether the timer counter is enabled.
194 *
195 * \rst
196 * +----------------------+-----------------------------------+
197 * | Register | BitsName |
198 * +======================+===================================+
199 * | CTRL | EN |
200 * +----------------------+-----------------------------------+
201 * \endrst
202 *
203 * @param TIMERx Timer instance
204 * @retval State of bit (1 or 0).
205 */
206 __STATIC_INLINE uint32_t ll_timer_is_enabled_counter(timer_regs_t *TIMERx)
207 {
208 return (READ_BITS(TIMERx->CTRL, TIMER_CTRL_EN) == (TIMER_CTRL_EN));
209 }
210
211 /**
212 * @brief Set the counter value.
213 *
214 * \rst
215 * +----------------------+-----------------------------------+
216 * | Register | BitsName |
217 * +======================+===================================+
218 * | VALUE | VALUE |
219 * +----------------------+-----------------------------------+
220 * \endrst
221 *
222 * @param TIMERx Timer instance
223 * @param counter Counter value (between Min_Data=0 and Max_Data=0xFFFFFFFF)
224 * @retval None
225 */
226 __STATIC_INLINE void ll_timer_set_counter(timer_regs_t *TIMERx, uint32_t counter)
227 {
228 WRITE_REG(TIMERx->VALUE, counter);
229 }
230
231 /**
232 * @brief Get the counter value.
233 *
234 * \rst
235 * +----------------------+-----------------------------------+
236 * | Register | BitsName |
237 * +======================+===================================+
238 * | VALUE | VALUE |
239 * +----------------------+-----------------------------------+
240 * \endrst
241 *
242 * @param TIMERx Timer instance
243 * @retval Counter value (between Min_Data=0 and Max_Data=0xFFFFFFFF)
244 */
245 __STATIC_INLINE uint32_t ll_timer_get_counter(timer_regs_t *TIMERx)
246 {
247 return (uint32_t)(READ_REG(TIMERx->VALUE));
248 }
249
250 /**
251 * @brief Set the auto-reload value.
252 * @note The counter is blocked while the auto-reload value is null.
253 *
254 * \rst
255 * +----------------------+-----------------------------------+
256 * | Register | BitsName |
257 * +======================+===================================+
258 * | RELOAD | RELOAD |
259 * +----------------------+-----------------------------------+
260 * \endrst
261 *
262 * @param TIMERx Timer instance
263 * @param auto_reload between Min_Data=0 and Max_Data=0xFFFFFFFF
264 * @retval None
265 */
266 __STATIC_INLINE void ll_timer_set_auto_reload(timer_regs_t *TIMERx, uint32_t auto_reload)
267 {
268 WRITE_REG(TIMERx->RELOAD, auto_reload);
269 }
270
271 /**
272 * @brief Get the auto-reload value.
273 *
274 * \rst
275 * +----------------------+-----------------------------------+
276 * | Register | BitsName |
277 * +======================+===================================+
278 * | RELOAD | RELOAD |
279 * +----------------------+-----------------------------------+
280 * \endrst
281 *
282 * @param TIMERx Timer instance
283 * @retval Auto-reload value
284 */
285 __STATIC_INLINE uint32_t ll_timer_get_auto_reload(timer_regs_t *TIMERx)
286 {
287 return (uint32_t)(READ_REG(TIMERx->RELOAD));
288 }
289
290 /** @} */
291
292 /** @defgroup TIM_LL_EF_IT_Management IT_Management
293 * @{
294 */
295
296 /**
297 * @brief Enable timer interrupt.
298 *
299 * \rst
300 * +----------------------+-----------------------------------+
301 * | Register | BitsName |
302 * +======================+===================================+
303 * | CTRL | INTEN |
304 * +----------------------+-----------------------------------+
305 * \endrst
306 *
307 * @param TIMERx Timer instance
308 * @retval None
309 */
310 __STATIC_INLINE void ll_timer_enable_it(timer_regs_t *TIMERx)
311 {
312 SET_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN);
313 }
314
315 /**
316 * @brief Disable timer interrput.
317 *
318 * \rst
319 * +----------------------+-----------------------------------+
320 * | Register | BitsName |
321 * +======================+===================================+
322 * | CTRL | INTEN |
323 * +----------------------+-----------------------------------+
324 * \endrst
325 *
326 * @param TIMERx Timer instance
327 * @retval None
328 */
329 __STATIC_INLINE void ll_timer_disable_it(timer_regs_t *TIMERx)
330 {
331 CLEAR_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN);
332 }
333
334 /**
335 * @brief Indicate whether the timer interrput is enabled.
336 *
337 * \rst
338 * +----------------------+-----------------------------------+
339 * | Register | BitsName |
340 * +======================+===================================+
341 * | CTRL | INTEN |
342 * +----------------------+-----------------------------------+
343 * \endrst
344 *
345 * @param TIMERx Timer instance
346 * @retval State of bit (1 or 0).
347 */
348 __STATIC_INLINE uint32_t ll_timer_is_enabled_it(timer_regs_t *TIMERx)
349 {
350 return (READ_BITS(TIMERx->CTRL, TIMER_CTRL_INTEN) == (TIMER_CTRL_INTEN));
351 }
352
353 /** @} */
354
355 /** @defgroup TIM_LL_EF_FLAG_Management FLAG_Management
356 * @{
357 */
358
359 /**
360 * @brief Clear the interrupt flag (INTSTAT).
361 *
362 * \rst
363 * +----------------------+-----------------------------------+
364 * | Register | BitsName |
365 * +======================+===================================+
366 * | INTSTAT | INTSTAT |
367 * +----------------------+-----------------------------------+
368 * \endrst
369 *
370 * @param TIMERx Timer instance
371 * @retval None
372 */
373 __STATIC_INLINE void ll_timer_clear_flag_it(timer_regs_t *TIMERx)
374 {
375 WRITE_REG(TIMERx->INTSTAT, TIMER_INT_STAT);
376 }
377
378 /**
379 * @brief Indicate whether interrupt flag (INTSTAT) is set (interrupt is pending).
380 *
381 * \rst
382 * +----------------------+-----------------------------------+
383 * | Register | BitsName |
384 * +======================+===================================+
385 * | INTSTAT | INTSTAT |
386 * +----------------------+-----------------------------------+
387 * \endrst
388 *
389 * @param TIMERx Timer instance
390 * @retval State of bit (1 or 0).
391 */
392 __STATIC_INLINE uint32_t ll_timer_is_active_flag_it(timer_regs_t *TIMERx)
393 {
394 return (READ_BITS(TIMERx->INTSTAT, TIMER_INT_STAT) == (TIMER_INT_STAT));
395 }
396
397 /** @} */
398
399 /** @defgroup TIM_LL_Init Initialization and de-initialization functions
400 * @{
401 */
402
403 /**
404 * @brief De-initialize TIMER registers (Registers restored to their default values).
405 * @param TIMERx TIMER instance
406 * @retval An error_status_t enumeration value:
407 * - SUCCESS: TIMER registers are de-initialized
408 * - ERROR: TIMER registers are not de-initialized
409 */
410 error_status_t ll_timer_deinit(timer_regs_t *TIMERx);
411
412 /**
413 * @brief Initialize TIMER registers according to the specified
414 * parameters in TIMER_InitStruct.
415 * @param TIMERx TIMER instance
416 * @param p_timer_init Pointer to a ll_timer_init_t structure that contains the configuration
417 * information for the specified TIM peripheral.
418 * @retval An error_status_t enumeration value:
419 * - SUCCESS: TIMER registers are initialized according to p_timer_init content
420 * - ERROR: Problem occurred during TIMER Registers initialization
421 */
422 error_status_t ll_timer_init(timer_regs_t *TIMERx, ll_timer_init_t *p_timer_init);
423
424 /**
425 * @brief Set each field of a @ref ll_timer_init_t type structure to default value.
426 * @param p_timer_init Pointer to a @ref ll_timer_init_t structure
427 * whose fields will be set to default values.
428 * @retval None
429 */
430 void ll_timer_struct_init(ll_timer_init_t *p_timer_init);
431
432 /** @} */
433
434 /** @} */
435
436 #endif /* TIMER0 || TIMER1 */
437
438 #ifdef __cplusplus
439 }
440 #endif
441
442 #endif /* __GR55XX_LL_TIMER_H__ */
443
444 /** @} */
445
446 /** @} */
447
448 /** @} */
ll_timer_enable_counter
__STATIC_INLINE void ll_timer_enable_counter(timer_regs_t *TIMERx)
Enable timer counter.
Definition: gr55xx_ll_tim.h:168
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:187
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:226
ll_timer_enable_it
__STATIC_INLINE void ll_timer_enable_it(timer_regs_t *TIMERx)
Enable timer interrupt.
Definition: gr55xx_ll_tim.h:310
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:373
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:206
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:245
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
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:266
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:285
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:392
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:348
ll_timer_disable_it
__STATIC_INLINE void ll_timer_disable_it(timer_regs_t *TIMERx)
Disable timer interrput.
Definition: gr55xx_ll_tim.h:329