• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  ****************************************************************************************
3  *
4  * @file    gr55xx_hal_dual_tim.h
5  * @author  BLE Driver Team
6  * @brief   Header file containing functions prototypes of DUAL 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_DUAL_TIMER DUAL TIMER
47   * @brief DUAL TIM HAL module driver.
48   * @{
49   */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_DUAL_TIMER_H__
53 #define __GR55xx_HAL_DUAL_TIMER_H__
54 
55 /* Includes ------------------------------------------------------------------*/
56 #include "gr55xx_hal_def.h"
57 #include "gr55xx_ll_dual_tim.h"
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_DUAL_TIMER_ENUMERATIONS Enumerations
65   * @{
66   */
67 
68 /** @defgroup HAL_DUAL_TIMER_state HAL DUAL TIM state
69   * @{
70   */
71 
72 /**
73   * @brief  HAL DUAL TIMER State Enumerations definition
74   */
75 typedef enum {
76     HAL_DUAL_TIMER_STATE_RESET             = 0x00,    /**< Peripheral not yet initialized or disabled  */
77     HAL_DUAL_TIMER_STATE_READY             = 0x01,    /**< Peripheral Initialized and ready for use    */
78     HAL_DUAL_TIMER_STATE_BUSY              = 0x02,    /**< An internal process is ongoing              */
79     HAL_DUAL_TIMER_STATE_ERROR             = 0x04     /**< Reception process is ongoing                */
80 } hal_dual_timer_state_t;
81 /** @} */
82 
83 /** @} */
84 
85 /** @addtogroup HAL_DUAL_TIMER_STRUCTURES Structures
86   * @{
87   */
88 
89 /** @defgroup DUAL_TIMER_Configuration DUAL TIMER Configuration
90   * @{
91   */
92 
93 /**
94   * @brief DUAL TIMER init Structure definition
95   */
96 typedef struct _dual_timer_init {
97     uint32_t prescaler;     /**< Specifies the prescaler value used to divide the DUAL_TIMER clock.
98                                  This parameter can be a value of @ref DUAL_TIMER_Prescaler_Div */
99 
100     uint32_t counter_mode;  /**< Specifies the counter mode.
101                                  This parameter can be a value of @ref DUAL_TIMER_Counter_Mode */
102 
103     uint32_t auto_reload;   /**< Specifies the auto-reload value. */
104 } dual_timer_init_t;
105 
106 /** @} */
107 
108 /** @defgroup DUAL_TIMER_handle DUAL TIMER handle
109   * @{
110   */
111 
112 /**
113   * @brief DUAL_TIMER handle Structure definition
114   */
115 typedef struct _dual_timer_handle {
116     dual_timer_regs_t              *p_instance;     /**< Register base address               */
117 
118     dual_timer_init_t              init;          /**< DUAL_TIMER Base required parameters   */
119 
120     __IO hal_lock_t                lock;          /**< Locking object                      */
121 
122     __IO hal_dual_timer_state_t    state;         /**< DUAL_TIMER operation state            */
123 } dual_timer_handle_t;
124 /** @} */
125 
126 /** @} */
127 
128 /** @addtogroup HAL_DUAL_TIMER_CALLBACK_STRUCTURES Callback Structures
129   * @{
130   */
131 
132 /** @defgroup HAL_DUAL_TIMER_Callback Callback
133   * @{
134   */
135 
136 /**
137   * @brief HAL_DUAL_TIMER Callback function definition
138   */
139 
140 typedef struct _hal_dual_timer_callback {
141     void (*dual_timer_msp_init)(dual_timer_handle_t *p_dual_timer);                 /**< DUAL_TIMER init MSP
142                                                                                          callback */
143     void (*dual_timer_msp_deinit)(dual_timer_handle_t *p_dual_timer);               /**< DUAL_TIMER de-init MSP
144                                                                                          callback */
145     void (*dual_timer_period_elapsed_callback)(dual_timer_handle_t *p_dual_timer);  /**< DUAL_TIMER period elapsed
146                                                                                          callback */
147 } hal_dual_timer_callback_t;
148 /** @} */
149 
150 /** @} */
151 
152 /**
153   * @defgroup  HAL_DUAL_TIMER_MACRO Defines
154   * @{
155   */
156 
157 /* Exported constants --------------------------------------------------------*/
158 /** @defgroup DUAL_TIMER_Exported_Constants DUAL TIMER Exported Constants
159   * @{
160   */
161 
162 /** @defgroup DUAL_TIMER_Prescaler_Div DUAL TIMER Prescaler Division
163   * @{
164   */
165 #define DUAL_TIMER_PRESCALER_DIV0         LL_DUAL_TIMER_PRESCALER_DIV0      /**< 0 stage of prescale,
166                                                                                  clock is divided by 1. */
167 #define DUAL_TIMER_PRESCALER_DIV16        LL_DUAL_TIMER_PRESCALER_DIV16     /**< 4 stages of prescale,
168                                                                                  clock is divided by 16. */
169 #define DUAL_TIMER_PRESCALER_DIV256       LL_DUAL_TIMER_PRESCALER_DIV256    /**< 8 stages of prescale,
170                                                                                  clock is divided by 256. */
171 /** @} */
172 
173 /** @defgroup DUAL_TIMER_Counter_Mode DUAL TIMER Counter Mode
174   * @{
175   */
176 #define DUAL_TIMER_COUNTERMODE_LOOP       0x00000000U                     /**< DUAL TIMER Loop mode.*/
177 #define DUAL_TIMER_COUNTERMODE_ONESHOT    DUAL_TIMER_CTRL_ONESHOT           /**< DUAL TIMER One-shot mode. */
178 /** @} */
179 
180 /** @} */
181 
182 /* Exported macro ------------------------------------------------------------*/
183 /** @defgroup DUAL_TIMER_Exported_Macros DUAL TIMER Exported Macros
184   * @{
185   */
186 
187 /** @brief  Reset DUAL TIMER handle states.
188   * @param  __HANDLE__ DUAL TIMER handle.
189   * @retval None
190   */
191 #define __HAL_DUAL_TIMER_RESET_HANDLE_STATE(__HANDLE__)               ((__HANDLE__)->state = HAL_DUAL_TIMER_STATE_RESET)
192 
193 /** @brief  Enable the specified DUAL TIMER peripheral.
194   * @param  __HANDLE__ Specifies the DUAL TIMER Handle.
195   * @retval None
196   */
197 #define __HAL_DUAL_TIMER_ENABLE(__HANDLE__)                 SET_BITS((__HANDLE__)->p_instance->CTRL, DUAL_TIMER_CTRL_EN)
198 
199 /** @brief  Disable the specified DUAL TIMER peripheral.
200   * @param  __HANDLE__ Specifies the DUAL TIMER Handle.
201   * @retval None
202   */
203 #define __HAL_DUAL_TIMER_DISABLE(__HANDLE__)              CLEAR_BITS((__HANDLE__)->p_instance->CTRL, DUAL_TIMER_CTRL_EN)
204 
205 /** @brief  Enable the DUAL TIMER interrupt.
206   * @param  __HANDLE__ Specifies the DUAL TIM Handle.
207   * @retval None
208   */
209 #define __HAL_DUAL_TIMER_ENABLE_IT(__HANDLE__)           SET_BITS((__HANDLE__)->p_instance->CTRL, DUAL_TIMER_CTRL_INTEN)
210 
211 /** @brief  Disable the DUAL TIMER interrupt.
212   * @param  __HANDLE__ Specifies the DUAL TIM Handle.
213   * @retval None
214   */
215 #define __HAL_DUAL_TIMER_DISABLE_IT(__HANDLE__)        CLEAR_BITS((__HANDLE__)->p_instance->CTRL, DUAL_TIMER_CTRL_INTEN)
216 
217 /** @brief  Check whether the DUAL TIMER interrupt has occurred or not.
218   * @param  __HANDLE__ Specifies the DUAL TIMER Handle.
219   * @retval The new state of DUAL TIMER interrupt (SET or RESET).
220   */
221 #define __HAL_DUAL_TIMER_GET_FLAG_IT(__HANDLE__)               ll_dual_timer_is_active_flag_it((__HANDLE__)->p_instance)
222 
223 /** @brief  Clear the DUAL TIMER interrupt flag.
224   * @param  __HANDLE__ Specifies the DUAL TIMER Handle.
225   * @retval None.
226   */
227 #define __HAL_DUAL_TIMER_CLEAR_FLAG_IT(__HANDLE__)                 ll_dual_timer_clear_flag_it((__HANDLE__)->p_instance)
228 
229 /** @} */
230 
231 /* Private macros ------------------------------------------------------------*/
232 /** @defgroup DUAL_TIMER_Private_Macros DUAL TIMER Private Macros
233   * @{
234   */
235 
236 /** @brief  Check if DUAL TIMER prescaler is valid.
237   * @param  __PRESCALER__ DUAL TIMER prescaler.
238   * @retval SET (__PRESCALER__ is valid) or RESET (__PRESCALER__ is invalid)
239   */
240 #define IS_DUAL_TIMER_PRESCALER(__PRESCALER__)                     (((__PRESCALER__) == DUAL_TIMER_PRESCALER_DIV0)  || \
241                                                                     ((__PRESCALER__) == DUAL_TIMER_PRESCALER_DIV16) || \
242                                                                     ((__PRESCALER__) == DUAL_TIMER_PRESCALER_DIV256))
243 
244 /** @brief  Check if DUAL TIMER counter mode is valid.
245   * @param  __MODE__ DUAL TIMER counter mode.
246   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
247   */
248 #define IS_DUAL_TIMER_COUNTERMODE(__MODE__)                        (((__MODE__) == DUAL_TIMER_COUNTERMODE_LOOP)  || \
249                                                                     ((__MODE__) == DUAL_TIMER_COUNTERMODE_ONESHOT))
250 /** @} */
251 
252 /** @} */
253 
254 /* Exported functions --------------------------------------------------------*/
255 /** @addtogroup HAL_DUAL_TIMER_DRIVER_FUNCTIONS Functions
256   * @{
257   */
258 
259 /** @addtogroup DUAL_TIMER_Exported_Functions_Group1 Initialization and de-initialization functions
260   * @brief    Initialization and de-initialization functions
261   *
262   * @verbatim
263 ===============================================================================
264             ##### Initialization and de-initialization functions #####
265  ===============================================================================
266     [..]
267         This section provides functions allowing to:
268         (+) Initialize and configure the DUAL TIMER.
269         (+) De-initialize the DUAL TIMER.
270         (+) Start the Timer.
271         (+) Stop the Timer.
272         (+) Start the Timer and enable interrupt.
273         (+) Stop the Timer and disable interrupt.
274 
275 @endverbatim
276   * @{
277   */
278 
279 /**
280  ****************************************************************************************
281  * @brief  Initialize the DUAL TIMER according to the specified parameters
282  *         in the dual_timer_init_t and initialize the associated handle.
283  *
284  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
285  *                           for the specified DUAL TIMER.
286  *
287  * @retval ::HAL_OK: Operation is OK.
288  * @retval ::HAL_ERROR: Parameter error or operation not supported.
289  * @retval ::HAL_BUSY: Driver is busy.
290  * @retval ::HAL_TIMEOUT: Timeout occurred.
291  ****************************************************************************************
292  */
293 hal_status_t hal_dual_timer_base_init(dual_timer_handle_t *p_dual_timer);
294 
295 /**
296  ****************************************************************************************
297  * @brief  De-initialize the DUAL TIMER peripheral.
298  *
299  * @param[in]  p_dual_timer: Pointer to a DUAL_TIM handle which contains the configuration information
300  *                           for the specified DUAL TIMER.
301  *
302  * @retval ::HAL_OK: Operation is OK.
303  * @retval ::HAL_ERROR: Parameter error or operation not supported.
304  * @retval ::HAL_BUSY: Driver is busy.
305  * @retval ::HAL_TIMEOUT: Timeout occurred.
306  ****************************************************************************************
307  */
308 hal_status_t hal_dual_timer_base_deinit(dual_timer_handle_t *p_dual_timer);
309 
310 /**
311  ****************************************************************************************
312  * @brief Initialize the DUAL TIMER MSP.
313  *
314  * @note  This function should not be modified. When the callback is needed,
315  *         the hal_dual_timer_base_msp_init could be implemented in the user file
316  *
317  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
318  *                           for the specified DUAL TIMER.
319  ****************************************************************************************
320  */
321 void hal_dual_timer_base_msp_init(dual_timer_handle_t *p_dual_timer);
322 
323 /**
324  ****************************************************************************************
325  * @brief De-initialize the DUAL TIMER MSP.
326  *
327  * @note  This function should not be modified. When the callback is needed,
328  *         the hal_dual_timer_base_msp_deinit could be implemented in the user file
329  *
330  * @param[in]  p_dual_timer: Pointer to a DUAL_TIM handle which contains the configuration information
331  *                           for the specified DUAL TIMER.
332  ****************************************************************************************
333  */
334 void hal_dual_timer_base_msp_deinit(dual_timer_handle_t *p_dual_timer);
335 
336 /**
337  ****************************************************************************************
338  * @brief  Starts the DUAL TIMER counter.
339  *
340  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
341  *                           for the specified DUAL TIMER.
342  *
343  * @retval ::HAL_OK: Operation is OK.
344  * @retval ::HAL_ERROR: Parameter error or operation not supported.
345  * @retval ::HAL_BUSY: Driver is busy.
346  * @retval ::HAL_TIMEOUT: Timeout occurred.
347  ****************************************************************************************
348  */
349 hal_status_t hal_dual_timer_base_start(dual_timer_handle_t *p_dual_timer);
350 
351 /**
352  ****************************************************************************************
353  * @brief  Stops the DUAL TIMER counter.
354  *
355  * @param[in]  p_dual_timer: Pointer to a DUAL_TIM handle which contains the configuration information
356  *                           for the specified DUAL TIMER.
357  *
358  * @retval ::HAL_OK: Operation is OK.
359  * @retval ::HAL_ERROR: Parameter error or operation not supported.
360  * @retval ::HAL_BUSY: Driver is busy.
361  * @retval ::HAL_TIMEOUT: Timeout occurred.
362  ****************************************************************************************
363  */
364 hal_status_t hal_dual_timer_base_stop(dual_timer_handle_t *p_dual_timer);
365 
366 /**
367  ****************************************************************************************
368  * @brief  Starts the DUAL TIMER counter in interrupt mode.
369  *
370  * @param[in]  p_dual_timer: Pointer to a DUAL_TIM handle which contains the configuration information
371  *                           for the specified DUAL TIMER.
372  *
373  * @retval ::HAL_OK: Operation is OK.
374  * @retval ::HAL_ERROR: Parameter error or operation not supported.
375  * @retval ::HAL_BUSY: Driver is busy.
376  * @retval ::HAL_TIMEOUT: Timeout occurred.
377  ****************************************************************************************
378  */
379 hal_status_t hal_dual_timer_base_start_it(dual_timer_handle_t *p_dual_timer);
380 
381 /**
382  ****************************************************************************************
383  * @brief  Stops the DUAL TIMER counter in interrupt mode.
384  *
385  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
386  *                           for the specified DUAL TIMER.
387  *
388  * @retval ::HAL_OK: Operation is OK.
389  * @retval ::HAL_ERROR: Parameter error or operation not supported.
390  * @retval ::HAL_BUSY: Driver is busy.
391  * @retval ::HAL_TIMEOUT: Timeout occurred.
392  ****************************************************************************************
393  */
394 hal_status_t hal_dual_timer_base_stop_it(dual_timer_handle_t *p_dual_timer);
395 
396 /** @} */
397 
398 /** @addtogroup DUAL_TIMER_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
399   * @brief    IRQ Handler and Callbacks functions
400  * @{
401  */
402 
403 /**
404  ****************************************************************************************
405  * @brief Handle DUAL TIMER interrupt request.
406  *
407  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
408  *                           for the specified DUAL TIMER.
409  ****************************************************************************************
410  */
411 void hal_dual_timer_irq_handler(dual_timer_handle_t *p_dual_timer);
412 
413 /**
414  ****************************************************************************************
415  * @brief  Period elapsed callback in non-blocking mode.
416  *
417  * @note   This function should not be modified. When the callback is needed,
418  *          the hal_dual_timer_period_elapsed_callback can be implemented in the user file.
419  *
420  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
421  *                           for the specified DUAL TIMER.
422  ****************************************************************************************
423  */
424 void hal_dual_timer_period_elapsed_callback(dual_timer_handle_t *p_dual_timer);
425 
426 /** @} */
427 
428 /** @addtogroup DUAL_TIMER_Exported_Functions_Group2 Peripheral Control and State functions
429  *  @brief   DUAL TIMER Peripheral State functions
430  *
431 @verbatim
432   ==============================================================================
433             ##### Peripheral Control and State functions #####
434   ==============================================================================
435     [..]
436     This subsection provides functions allowing to :
437       (+) Return the DUAL TIMER handle state.
438       (+) Configure the DUAL TIMER.
439 
440 @endverbatim
441   * @{
442   */
443 
444 /**
445  ****************************************************************************************
446  * @brief  Return the DUAL TIMER handle state.
447  *
448  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
449  *                           for the specified DUAL TIMER.
450  *
451  * @retval ::HAL_DUAL_TIMER_STATE_RESET: Peripheral not yet initialized or disabled.
452  * @retval ::HAL_DUAL_TIMER_STATE_READY: Peripheral Initialized and ready for use.
453  * @retval ::HAL_DUAL_TIMER_STATE_BUSY: An internal process is ongoing.
454  * @retval ::HAL_DUAL_TIMER_STATE_ERROR: Reception process is ongoing.
455  ****************************************************************************************
456  */
457 hal_dual_timer_state_t hal_dual_timer_get_state(dual_timer_handle_t *p_dual_timer);
458 
459 /**
460  ****************************************************************************************
461  * @brief  DUAL TIMER configuration
462  *
463  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
464  *                           for the specified DUAL TIMER.
465  * @param[in]  p_structure: The DUAL TIMER configuration structure
466  *
467  * @retval ::HAL_OK: Operation is OK.
468  * @retval ::HAL_ERROR: Parameter error or operation not supported.
469  * @retval ::HAL_BUSY: Driver is busy.
470  * @retval ::HAL_TIMEOUT: Timeout occurred.
471  ****************************************************************************************
472  */
473 hal_status_t hal_dual_timer_set_config(dual_timer_handle_t *p_dual_timer, dual_timer_init_t *p_structure);
474 
475 /**
476  ****************************************************************************************
477  * @brief  DUAL TIMER set background reload value
478  *         The background reload value contains the value from which the counter is to decrement.
479  *         This is the value used to reload the counter when Periodic mode is enabled, and the current count reaches 0.
480  *         The difference is that writes to background reload value do not cause the counter to immediately restart
481  *         from the new value.
482  * @param[in]  p_dual_timer: Pointer to a DUAL_TIMER handle which contains the configuration information
483  *                           for the specified DUAL TIMER.
484  * @param[in]  reload_value: Background reload value
485  *
486  * @retval ::HAL_OK: Operation is OK.
487  * @retval ::HAL_ERROR: Parameter error or operation not supported.
488  * @retval ::HAL_BUSY: Driver is busy.
489  ****************************************************************************************
490  */
491 hal_status_t hal_dual_timer_set_background_reload(dual_timer_handle_t *p_dual_timer, uint32_t reload_value);
492 
493 /** @} */
494 
495 /** @} */
496 
497 #ifdef __cplusplus
498 }
499 #endif
500 
501 #endif /* __GR55xx_HAL_DUAL_TIMER_H__ */
502 
503 /** @} */
504 
505 /** @} */
506 
507 /** @} */
508