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