1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * 15 * Description: Provides HAL drv timer \n 16 * 17 * History: \n 18 * 2022-06-02, Create file. \n 19 */ 20 #ifndef HAL_DRV_TIMER_H 21 #define HAL_DRV_TIMER_H 22 23 #include <stdint.h> 24 #include "errcode.h" 25 #include "timer_porting.h" 26 27 #ifdef __cplusplus 28 #if __cplusplus 29 extern "C" { 30 #endif /* __cplusplus */ 31 #endif /* __cplusplus */ 32 33 /** 34 * @defgroup drivers_hal_timer_api Timer 35 * @ingroup drivers_hal_timer 36 * @{ 37 */ 38 39 /** 40 * @if Eng 41 * @brief Callback of timer. 42 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 43 * @else 44 * @brief Timer的回调函数。 45 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 46 * @endif 47 */ 48 typedef void (*hal_timer_callback_t)(timer_index_t index); 49 50 /** 51 * @if Eng 52 * @brief HAL timer init interface. 53 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 54 * @param [in] callback Callback of timer. 55 * @retval ERRCODE_SUCC Success. 56 * @retval Other Failure. For details, see @ref errcode_t 57 * @else 58 * @brief HAL层Timer的初始化接口。 59 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 60 * @param [in] callback Timer的回调函数。 61 * @retval ERRCODE_SUCC 成功。 62 * @retval Other 失败,参考 @ref errcode_t 。 63 * @endif 64 */ 65 errcode_t hal_timer_init(timer_index_t index, hal_timer_callback_t callback); 66 67 /** 68 * @if Eng 69 * @brief HAL timer deinit interface. 70 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 71 * @else 72 * @brief HAL层Timer的去初始化接口。 73 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 74 * @endif 75 */ 76 void hal_timer_deinit(timer_index_t index); 77 78 /** 79 * @if Eng 80 * @brief HAL timer start the load count of hardware timer interface. 81 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 82 * @else 83 * @brief HAL层启动硬件定时器计数的接口。 84 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 85 * @endif 86 */ 87 void hal_timer_start(timer_index_t index); 88 89 /** 90 * @if Eng 91 * @brief HAL timer stop the load count of hardware timer interface. 92 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 93 * @else 94 * @brief HAL层停止硬件定时器计数的接口。 95 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 96 * @endif 97 */ 98 void hal_timer_stop(timer_index_t index); 99 100 /** 101 * @if Eng 102 * @brief HAL timer set the load count of hardware timer interface. 103 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 104 * @param [in] delay_count Time for load count. 105 * @else 106 * @brief HAL层设置硬件计时器计数的接口。 107 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 108 * @param [in] delay_count 计时的时间。 109 * @endif 110 */ 111 void hal_timer_config_load(timer_index_t index, uint64_t delay_count); 112 113 /** 114 * @if Eng 115 * @brief HAL timer get the current value of hardware timer interface. 116 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 117 * @return Timer load count. 118 * @else 119 * @brief HAL层获取硬件当前计时器剩余计数的接口。 120 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 121 * @return Timer计数值。 122 * @endif 123 */ 124 uint64_t hal_timer_get_current_value(timer_index_t index); 125 126 /** 127 * @if Eng 128 * @brief Init the timer which will set the base address of registers. 129 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 130 * @retval ERRCODE_SUCC Success. 131 * @retval Other Failure. For details, see @ref errcode_t. 132 * @else 133 * @brief 初始化Timer,设置寄存器的基地址。 134 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 135 * @retval ERRCODE_SUCC 成功。 136 * @retval Other 失败,参考 @ref errcode_t 。 137 * @endif 138 */ 139 errcode_t hal_timer_regs_init(timer_index_t index); 140 141 /** 142 * @if Eng 143 * @brief Deinit the hal_drv_timer which will clear the base address of registers has been 144 * set by @ref hal_timer_regs_init. 145 * @param [in] index Index of the hardware timer. For detail, see @ref timer_index_t. 146 * @else 147 * @brief 去初始化,然后清除在 @ref hal_timer_regs_init 中设置的寄存器地址。 148 * @param [in] index 硬件定时器索引值,参考 @ref timer_index_t 。 149 * @endif 150 */ 151 void hal_timer_regs_deinit(timer_index_t index); 152 153 /** 154 * @} 155 */ 156 157 #ifdef __cplusplus 158 #if __cplusplus 159 } 160 #endif /* __cplusplus */ 161 #endif /* __cplusplus */ 162 163 #endif 164