1 /** 2 * @file hi_hrtimer.h 3 * 4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. \n 16 * 17 * Description: 1、In scenarios where the precision is not high, do not use hrtimer. Instead, use a system timer, 18 * because each hrtimer startup, stop, and expiration may increase the error of other high-precision 19 * timers in the queue. CNcomment:在精度要求不高的场景下,尽可能不要使用hrtimer, 20 * 应使用系统定时器替代,因为每次hrtimer的启动、停止、到期都可能会增加队列中其它 21 * 高精度定时器的误差;CNend 22 * 2、The callback function of hrtimer is executed in the interrupt context, so you need to comply with 23 * the programming precautions for the interrupt context.CNcomment:hrtimer的回调函数执行在中断上下文, 24 * 因此需要遵守中断上下文的编程注意事项。CNend \n 25 */ 26 27 /** 28 * @defgroup hrtimer High Resolution Timer 29 * @ingroup drivers 30 */ 31 #ifndef __HI_HRTIMER_H__ 32 #define __HI_HRTIMER_H__ 33 #include <hi_types_base.h> 34 35 /** 36 * @ingroup hrtimer 37 * @brief High resolution timer callback function.CNcomment:高精度定时器回调函数。CNend 38 * 39 * @par 描述: 40 * High resolution timer callback function. When a high resolution timer expires, the high resolution timer 41 * module calls this function to notify the user.CNcomment:高精度定时器回调函数,当高精度定时器到期时, 42 * 高精度定时器模块调用该函数通知使用者。CNend 43 * 44 * @attention None 45 * @param data [IN] type #hi_u32,Callback function parameter input when the user starts the timer. 46 CNcomment:用户启动定时器时传入的回调函数参数。CNend 47 * 48 * @retval None 49 * @par 依赖: 50 * @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 51 * @see None 52 */ 53 typedef hi_void(*hi_hrtimer_callback_f) (hi_u32 data); 54 55 /** 56 * @ingroup hrtimer 57 * @brief Obtains the high resolution timer module handler.CNcomment:获取高精定时器句柄。CNend 58 * 59 * @par 描述: 60 * Obtains the high resolution timer module handler.CNcomment:获取高精定时器句柄。CNend 61 * 62 * @attention None 63 * @param timer_handle [OUT] type #hi_u32*,handler obtained. CNcomment:获取到的句柄。CNend 64 * 65 * @retval #0 Success. 66 * @retval #Other Failure. For details, see hi_errno.h 67 * 68 * @par 依赖: 69 * @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 70 * 71 * @see hi_hrtimer_delete。 72 */ 73 hi_u32 hi_hrtimer_create(hi_u32 *timer_handle); 74 75 /** 76 * @ingroup hrtimer 77 * @brief Delete the high resolution timer module handle.CNcomment:删除高精定时器句柄。CNend 78 * 79 * @par 描述: 80 * Delete the high resolution timer module handle.CNcomment:删除高精定时器句柄。CNend 81 * 82 * @attention None 83 * @param timer_handle [IN] type #hi_u32,Timer handle, which would be released. 84 CNcomment:要释放的定时器句柄。CNend 85 * 86 * @retval #0 Success. 87 * @retval #Other Failure. For details, see hi_errno.h 88 * 89 * @par 依赖: 90 * @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 91 * 92 * @see hi_hrtimer_create。 93 */ 94 hi_u32 hi_hrtimer_delete(hi_u32 timer_handle); 95 /** 96 * @ingroup hrtimer 97 * @brief Starts a high resolution timer.CNcomment:启动高精度定时器。CNend 98 * 99 * @par 描述: 100 * Starts the high resolution timer. If the timer has been started, the current timer is stopped and 101 * restarted when this API is called.CNcomment:调用该接口启动高精度定时器,如果定时器已经启动, 102 调用该接口时会停止当前定时器重新启动。CNend 103 * 104 * @attention None 105 * @param timer_handle [IN] type #hi_u32,Timer handle.CNcomment:定时器句柄。CNend 106 * @param expire [IN] type #hi_u32,Expiration time of the timer (unit: microsecond).When the clock is set to 107 24M,the maximum of the expiration time is 178s.When the clock is set to 40M,the maximum of the expiration time is 107s. 108 The expiration time of the timer must be set to a value smaller than the maximum. 109 CNcomment:定时器超时时间(单位:μs)。24M时钟可设置的最大超时时间为178s,40M时钟可设置的最大超时时间为107s。 110 超时时间必须设置为小于最大超时时间的值。CNend 111 * @param hrtimer_func [IN] type #hi_hrtimer_callback_f,Callback function when the timer expires. 112 CNcomment:定时器到期回调函数。CNend 113 * @param data [IN] type #hi_u32,Input parameter of the timer callback function. 114 CNcomment:定时器回调函数的入参。CNend 115 * 116 * @retval #0 Success. 117 * @retval #Other Failure. For details, see hi_errno.h 118 * 119 * @par 依赖: 120 * @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 121 * @see hi_hrtimer_stop。 122 */ 123 hi_u32 hi_hrtimer_start(hi_u32 timer_handle, hi_u32 expire, hi_hrtimer_callback_f hrtimer_func, hi_u32 data); 124 125 /** 126 * @ingroup hrtimer 127 * @brief Stops a high resolution timer.CNcomment:停止高精度定时器。CNend 128 * 129 * @par 描述: 130 * Stops a high resolution timer. If the timer is stopped when the API is called, no effect is achieved. 131 CNcomment:调用该接口停止高精度定时器,如果调用该接口时定时器已经停止,不会有任何效果。CNend 132 * 133 * @attention None 134 * @param timer_handle [IN] type #hi_u32,Timer handle.CNcomment:定时器handle。CNend 135 * 136 * @retval #0 Success. 137 * @retval #Other Failure. For details, see hi_errno.h 138 * 139 * @par 依赖: 140 * @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 141 * @see hi_hrtimer_start。 142 */ 143 hi_u32 hi_hrtimer_stop(hi_u32 timer_handle); 144 145 #endif 146