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