gr55xx_hal_tim.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_tim.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of TIMER HAL 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 HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_TIMER TIMER
47 * @brief TIM HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_TIMER_H__
53 #define __GR55xx_HAL_TIMER_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_hal_def.h"
61 #include "gr55xx_ll_tim.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_TIMER_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /** @defgroup HAL_TIMER_state HAL TIMER state
69 * @{
70 */
71
72 /**
73 * @brief HAL TIMER State Enumerations definition
74 */
75 typedef enum
76 {
77 HAL_TIMER_STATE_RESET = 0x00, /**< Peripheral not yet initialized or disabled */
78 HAL_TIMER_STATE_READY = 0x01, /**< Peripheral Initialized and ready for use */
79 HAL_TIMER_STATE_BUSY = 0x02, /**< An internal process is ongoing */
80 HAL_TIMER_STATE_ERROR = 0x04 /**< Reception process is ongoing */
81 } hal_timer_state_t;
82 /** @} */
83
84 /** @} */
85
86 /** @addtogroup HAL_TIMER_STRUCTURES Structures
87 * @{
88 */
89
90 /** @defgroup TIMER_Configuration TIMER Configuration
91 * @{
92 */
93
94 /**
95 * @brief TIMER init Structure definition
96 */
97 typedef struct _timer_init
98 {
99 uint32_t auto_reload; /**< Specifies the auto-reload value. */
100
101 } timer_init_t;
102
103 /** @} */
104
105 /** @defgroup TIMER_handle TIMER handle
106 * @{
107 */
108
109 /**
110 * @brief TIMER handle Structure definition
111 */
112 typedef struct _timer_handle
113 {
114 timer_regs_t *p_instance; /**< Register base address */
115
116 timer_init_t init; /**< TIMER Base required parameters */
117
118 __IO hal_lock_t lock; /**< Locking object */
119
120 __IO hal_timer_state_t state; /**< TIMER operation state */
121
122 } timer_handle_t;
123 /** @} */
124
125 /** @} */
126
127 /** @addtogroup HAL_TIMER_CALLBACK_STRUCTURES Callback Structures
128 * @{
129 */
130
131 /** @defgroup TIMER_Callback TIMER Callback
132 * @{
133 */
134
135 /**
136 * @brief HAL_TIMER Callback function definition
137 */
138
139 typedef struct _hal_timer_base_callback
140 {
141 void (*timer_msp_init)(timer_handle_t *p_timer); /**< TIMER init MSP callback */
142 void (*timer_msp_deinit)(timer_handle_t *p_timer); /**< TIMER de-init MSP callback */
143 void (*timer_period_elapsed_callback)(timer_handle_t *p_timer); /**< TIMER period elapsed callback */
144 } hal_timer_base_callback_t;
145
146 /** @} */
147
148 /** @} */
149
150 /**
151 * @defgroup HAL_TIMER_MACRO Defines
152 * @{
153 */
154
155 /* Exported macro ------------------------------------------------------------*/
156 /** @defgroup TIMER_Exported_Macros TIMER Exported Macros
157 * @{
158 */
159
160 /** @brief Reset TIMER handle states.
161 * @param __HANDLE__ TIMER handle.
162 * @retval None
163 */
164 #define __HAL_TIMER_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_TIMER_STATE_RESET)
165
166 /** @brief Enable the specified TIMER peripheral.
167 * @param __HANDLE__ Specifies the TIMER Handle.
168 * @retval None
169 */
170 #define __HAL_TIMER_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, TIMER_CTRL_EN)
171
172 /** @brief Disable the specified TIMER peripheral.
173 * @param __HANDLE__ Specifies the TIMER Handle.
174 * @retval None
175 */
176 #define __HAL_TIMER_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, TIMER_CTRL_EN)
177
178 /** @brief Enable the TIMER interrupt.
179 * @param __HANDLE__ Specifies the TIMER Handle.
180 * @retval None
181 */
182 #define __HAL_TIMER_ENABLE_IT(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CTRL, TIMER_CTRL_INTEN)
183
184 /** @brief Disable the TIMER interrupt.
185 * @param __HANDLE__ Specifies the TIMER Handle.
186 * @retval None
187 */
188 #define __HAL_TIMER_DISABLE_IT(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CTRL, TIMER_CTRL_INTEN)
189
190 /** @brief Check whether the TIMER interrupt has occurred or not.
191 * @param __HANDLE__ Specifies the TIMER Handle.
192 * @retval The new state of TIMER interrupt (SET or RESET).
193 */
194 #define __HAL_TIMER_GET_FLAG_IT(__HANDLE__) ll_timer_is_active_flag_it(__HANDLE__->p_instance)
195
196 /** @brief Clear the TIMER interrupt flag.
197 * @param __HANDLE__ Specifies the TIMER Handle.
198 * @retval None
199 */
200 #define __HAL_TIMER_CLEAR_FLAG_IT(__HANDLE__) ll_timer_clear_flag_it(__HANDLE__->p_instance)
201
202 /** @} */
203
204 /** @} */
205
206 /* Exported functions --------------------------------------------------------*/
207 /** @addtogroup HAL_TIMER_DRIVER_FUNCTIONS Functions
208 * @{
209 */
210
211 /** @addtogroup TIMER_Exported_Functions_Group1 Initialization and de-initialization functions
212 * @brief Initialization and de-initialization functions
213 *
214 * @verbatim
215 ===============================================================================
216 ##### Initialization and de-initialization functions #####
217 ===============================================================================
218 [..]
219 This section provides functions allowing to:
220 (+) Initialize and configure the TIMER.
221 (+) De-initialize the TIMER.
222 (+) Start the Timer.
223 (+) Stop the Timer.
224 (+) Start the Timer and enable interrupt.
225 (+) Stop the Timer and disable interrupt.
226
227 @endverbatim
228 * @{
229 */
230
231 /**
232 ****************************************************************************************
233 * @brief Initialize the TIMER according to the specified parameters
234 * in the timer_init_t and initialize the associated handle.
235 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
236 * information for the specified TIMER module.
237 * @retval ::HAL_OK: Operation is OK.
238 * @retval ::HAL_ERROR: Parameter error or operation not supported.
239 * @retval ::HAL_BUSY: Driver is busy.
240 * @retval ::HAL_TIMEOUT: Timeout occurred.
241 ****************************************************************************************
242 */
243 hal_status_t hal_timer_base_init(timer_handle_t *p_timer);
244
245 /**
246 ****************************************************************************************
247 * @brief De-initialize the TIMER peripheral.
248 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
249 * information for the specified TIMER module.
250 * @retval ::HAL_OK: Operation is OK.
251 * @retval ::HAL_ERROR: Parameter error or operation not supported.
252 * @retval ::HAL_BUSY: Driver is busy.
253 * @retval ::HAL_TIMEOUT: Timeout occurred.
254 ****************************************************************************************
255 */
256 hal_status_t hal_timer_base_deinit(timer_handle_t *p_timer);
257
258 /**
259 ****************************************************************************************
260 * @brief Initialize the TIMER MSP.
261 * @note This function should not be modified. When the callback is needed,
262 * the hal_timer_base_msp_init could be implemented in the user file.
263 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
264 * information for the specified TIMER module.
265 ****************************************************************************************
266 */
267 void hal_timer_base_msp_init(timer_handle_t *p_timer);
268
269 /**
270 ****************************************************************************************
271 * @brief De-initialize the TIMER MSP.
272 * @note This function should not be modified. When the callback is needed,
273 * the hal_timer_base_msp_deinit could be implemented in the user file.
274 * @param[in] p_timer: Pointer to a TIM handle which contains the configuration
275 * information for the specified TIMER module.
276 ****************************************************************************************
277 */
278 void hal_timer_base_msp_deinit(timer_handle_t *p_timer);
279
280 /**
281 ****************************************************************************************
282 * @brief Starts the TIMER counter.
283 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
284 * information for the specified TIMER module.
285 * @retval ::HAL_OK: Operation is OK.
286 * @retval ::HAL_ERROR: Parameter error or operation not supported.
287 * @retval ::HAL_BUSY: Driver is busy.
288 * @retval ::HAL_TIMEOUT: Timeout occurred.
289 ****************************************************************************************
290 */
291 hal_status_t hal_timer_base_start(timer_handle_t *p_timer);
292
293 /**
294 ****************************************************************************************
295 * @brief Stops the TIMER counter.
296 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
297 * information for the specified TIMER module.
298 * @retval ::HAL_OK: Operation is OK.
299 * @retval ::HAL_ERROR: Parameter error or operation not supported.
300 * @retval ::HAL_BUSY: Driver is busy.
301 * @retval ::HAL_TIMEOUT: Timeout occurred.
302 ****************************************************************************************
303 */
304 hal_status_t hal_timer_base_stop(timer_handle_t *p_timer);
305
306 /**
307 ****************************************************************************************
308 * @brief Starts the TIMER counter in interrupt mode.
309 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
310 * information for the specified TIMER module.
311 * @retval ::HAL_OK: Operation is OK.
312 * @retval ::HAL_ERROR: Parameter error or operation not supported.
313 * @retval ::HAL_BUSY: Driver is busy.
314 * @retval ::HAL_TIMEOUT: Timeout occurred.
315 ****************************************************************************************
316 */
317 hal_status_t hal_timer_base_start_it(timer_handle_t *p_timer);
318
319 /**
320 ****************************************************************************************
321 * @brief Stops the TIMER counter in interrupt mode.
322 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
323 * information for the specified TIMER module.
324 * @retval ::HAL_OK: Operation is OK.
325 * @retval ::HAL_ERROR: Parameter error or operation not supported.
326 * @retval ::HAL_BUSY: Driver is busy.
327 * @retval ::HAL_TIMEOUT: Timeout occurred.
328 ****************************************************************************************
329 */
330 hal_status_t hal_timer_base_stop_it(timer_handle_t *p_timer);
331
332 /** @} */
333
334 /** @addtogroup TIMER_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
335 * @brief IRQ Handler and Callbacks functions
336 * @{
337 */
338
339 /**
340 ****************************************************************************************
341 * @brief Handle TIMER interrupt request.
342 * @param[in] p_timer: TIMER handle.
343 ****************************************************************************************
344 */
345 void hal_timer_irq_handler(timer_handle_t *p_timer);
346
347 /**
348 ****************************************************************************************
349 * @brief Period elapsed callback in non-blocking mode.
350 * @note This function should not be modified. When the callback is needed,
351 the hal_timer_period_elapsed_callback can be implemented in the user file.
352 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
353 * information for the specified TIMER module.
354 ****************************************************************************************
355 */
356 void hal_timer_period_elapsed_callback(timer_handle_t *p_timer);
357
358 /** @} */
359
360 /** @addtogroup TIMER_Exported_Functions_Group2 Peripheral Control and State functions
361 * @brief TIMER Peripheral State functions
362 *
363 @verbatim
364 ==============================================================================
365 ##### Peripheral Control and State functions #####
366 ==============================================================================
367 [..]
368 This subsection provides functions allowing to :
369 (+) Return the TIMER handle state.
370 (+) Configure the TIMER.
371
372 @endverbatim
373 * @{
374 */
375
376 /**
377 ****************************************************************************************
378 * @brief Return the TIMER handle state.
379 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
380 * information for the specified TIMER module.
381 * @retval ::HAL_TIMER_STATE_RESET: Peripheral not yet initialized or disabled.
382 * @retval ::HAL_TIMER_STATE_READY: Peripheral Initialized and ready for use.
383 * @retval ::HAL_TIMER_STATE_BUSY: An internal process is ongoing.
384 * @retval ::HAL_TIMER_STATE_ERROR: Reception process is ongoing.
385 ****************************************************************************************
386 */
387 hal_timer_state_t hal_timer_get_state(timer_handle_t *p_timer);
388
389 /**
390 ****************************************************************************************
391 * @brief TIMER configuration
392 * @param[in] p_timer: Pointer to a TIMER handle which contains the configuration
393 * information for the specified TIMER module.
394 * @param[in] p_structure: The TIMER configuration structure
395 * @retval ::HAL_OK: Operation is OK.
396 * @retval ::HAL_ERROR: Parameter error or operation not supported.
397 * @retval ::HAL_BUSY: Driver is busy.
398 * @retval ::HAL_TIMEOUT: Timeout occurred.
399 ****************************************************************************************
400 */
401 hal_status_t hal_timer_set_config(timer_handle_t *p_timer, timer_init_t *p_structure);
402
403 /** @} */
404
405 /** @} */
406
407 #ifdef __cplusplus
408 }
409 #endif
410
411 #endif /* __GR55xx_HAL_TIMER_H__ */
412
413 /** @} */
414
415 /** @} */
416
417 /** @} */
hal_timer_base_stop
hal_status_t hal_timer_base_stop(timer_handle_t *p_timer)
Stops the TIMER counter.
hal_timer_base_msp_init
void hal_timer_base_msp_init(timer_handle_t *p_timer)
Initialize the TIMER MSP.
gr55xx_ll_tim.h
Header file containing functions prototypes of TIMER LL library.
hal_timer_base_init
hal_status_t hal_timer_base_init(timer_handle_t *p_timer)
Initialize the TIMER according to the specified parameters in the timer_init_t and initialize the ass...
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
timer_handle_t
struct _timer_handle timer_handle_t
TIMER handle Structure definition.
HAL_TIMER_STATE_BUSY
@ HAL_TIMER_STATE_BUSY
An internal process is ongoing
Definition: gr55xx_hal_tim.h:79
_timer_handle::p_instance
timer_regs_t * p_instance
Register base address
Definition: gr55xx_hal_tim.h:114
hal_timer_base_start_it
hal_status_t hal_timer_base_start_it(timer_handle_t *p_timer)
Starts the TIMER counter in interrupt mode.
hal_timer_base_stop_it
hal_status_t hal_timer_base_stop_it(timer_handle_t *p_timer)
Stops the TIMER counter in interrupt mode.
HAL_TIMER_STATE_RESET
@ HAL_TIMER_STATE_RESET
Peripheral not yet initialized or disabled
Definition: gr55xx_hal_tim.h:77
HAL_TIMER_STATE_READY
@ HAL_TIMER_STATE_READY
Peripheral Initialized and ready for use
Definition: gr55xx_hal_tim.h:78
hal_timer_base_start
hal_status_t hal_timer_base_start(timer_handle_t *p_timer)
Starts the TIMER counter.
_hal_timer_base_callback
HAL_TIMER Callback function definition.
Definition: gr55xx_hal_tim.h:140
_timer_handle::state
__IO hal_timer_state_t state
TIMER operation state
Definition: gr55xx_hal_tim.h:120
_timer_init
TIMER init Structure definition.
Definition: gr55xx_hal_tim.h:98
_timer_handle::lock
__IO hal_lock_t lock
Locking object
Definition: gr55xx_hal_tim.h:118
_timer_init::auto_reload
uint32_t auto_reload
Specifies the auto-reload value.
Definition: gr55xx_hal_tim.h:99
HAL_TIMER_STATE_ERROR
@ HAL_TIMER_STATE_ERROR
Reception process is ongoing
Definition: gr55xx_hal_tim.h:80
hal_timer_set_config
hal_status_t hal_timer_set_config(timer_handle_t *p_timer, timer_init_t *p_structure)
TIMER configuration.
_hal_timer_base_callback::timer_msp_deinit
void(* timer_msp_deinit)(timer_handle_t *p_timer)
TIMER de-init MSP callback
Definition: gr55xx_hal_tim.h:142
hal_timer_base_callback_t
struct _hal_timer_base_callback hal_timer_base_callback_t
HAL_TIMER Callback function definition.
_hal_timer_base_callback::timer_period_elapsed_callback
void(* timer_period_elapsed_callback)(timer_handle_t *p_timer)
TIMER period elapsed callback
Definition: gr55xx_hal_tim.h:143
_timer_handle::init
timer_init_t init
TIMER Base required parameters.
Definition: gr55xx_hal_tim.h:116
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_timer_irq_handler
void hal_timer_irq_handler(timer_handle_t *p_timer)
Handle TIMER interrupt request.
_timer_handle
TIMER handle Structure definition.
Definition: gr55xx_hal_tim.h:113
hal_timer_period_elapsed_callback
void hal_timer_period_elapsed_callback(timer_handle_t *p_timer)
Period elapsed callback in non-blocking mode.
hal_timer_base_deinit
hal_status_t hal_timer_base_deinit(timer_handle_t *p_timer)
De-initialize the TIMER peripheral.
timer_init_t
struct _timer_init timer_init_t
TIMER init Structure definition.
hal_timer_state_t
hal_timer_state_t
HAL TIMER State Enumerations definition.
Definition: gr55xx_hal_tim.h:76
hal_timer_get_state
hal_timer_state_t hal_timer_get_state(timer_handle_t *p_timer)
Return the TIMER handle state.
hal_timer_base_msp_deinit
void hal_timer_base_msp_deinit(timer_handle_t *p_timer)
De-initialize the TIMER MSP.
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_hal_timer_base_callback::timer_msp_init
void(* timer_msp_init)(timer_handle_t *p_timer)
TIMER init MSP callback
Definition: gr55xx_hal_tim.h:141