11bd4fe43Sopenharmony_ci/**
21bd4fe43Sopenharmony_ci* @file hi_hrtimer.h
31bd4fe43Sopenharmony_ci*
41bd4fe43Sopenharmony_ci* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
51bd4fe43Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
61bd4fe43Sopenharmony_ci* you may not use this file except in compliance with the License.
71bd4fe43Sopenharmony_ci* You may obtain a copy of the License at
81bd4fe43Sopenharmony_ci*
91bd4fe43Sopenharmony_ci*     http://www.apache.org/licenses/LICENSE-2.0
101bd4fe43Sopenharmony_ci*
111bd4fe43Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software
121bd4fe43Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
131bd4fe43Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141bd4fe43Sopenharmony_ci* See the License for the specific language governing permissions and
151bd4fe43Sopenharmony_ci* limitations under the License.  \n
161bd4fe43Sopenharmony_ci*
171bd4fe43Sopenharmony_ci* Description: 1、In scenarios where the precision is not high, do not use hrtimer. Instead, use a system timer,
181bd4fe43Sopenharmony_ci*                 because each hrtimer startup, stop, and expiration may increase the error of other high-precision
191bd4fe43Sopenharmony_ci*                 timers in the queue. CNcomment:在精度要求不高的场景下,尽可能不要使用hrtimer,
201bd4fe43Sopenharmony_ci*                 应使用系统定时器替代,因为每次hrtimer的启动、停止、到期都可能会增加队列中其它
211bd4fe43Sopenharmony_ci*                 高精度定时器的误差;CNend
221bd4fe43Sopenharmony_ci*              2、The callback function of hrtimer is executed in the interrupt context, so you need to comply with
231bd4fe43Sopenharmony_ci*                 the programming precautions for the interrupt context.CNcomment:hrtimer的回调函数执行在中断上下文,
241bd4fe43Sopenharmony_ci*                 因此需要遵守中断上下文的编程注意事项。CNend   \n
251bd4fe43Sopenharmony_ci*/
261bd4fe43Sopenharmony_ci
271bd4fe43Sopenharmony_ci/**
281bd4fe43Sopenharmony_ci * @defgroup hrtimer High Resolution Timer
291bd4fe43Sopenharmony_ci * @ingroup drivers
301bd4fe43Sopenharmony_ci */
311bd4fe43Sopenharmony_ci#ifndef __HI_HRTIMER_H__
321bd4fe43Sopenharmony_ci#define __HI_HRTIMER_H__
331bd4fe43Sopenharmony_ci#include <hi_types_base.h>
341bd4fe43Sopenharmony_ci
351bd4fe43Sopenharmony_ci/**
361bd4fe43Sopenharmony_ci* @ingroup  hrtimer
371bd4fe43Sopenharmony_ci* @brief  High resolution timer callback function.CNcomment:高精度定时器回调函数。CNend
381bd4fe43Sopenharmony_ci*
391bd4fe43Sopenharmony_ci* @par 描述:
401bd4fe43Sopenharmony_ci*           High resolution timer callback function. When a high resolution timer expires, the high resolution timer
411bd4fe43Sopenharmony_ci*           module calls this function to notify the user.CNcomment:高精度定时器回调函数,当高精度定时器到期时,
421bd4fe43Sopenharmony_ci*           高精度定时器模块调用该函数通知使用者。CNend
431bd4fe43Sopenharmony_ci*
441bd4fe43Sopenharmony_ci* @attention None
451bd4fe43Sopenharmony_ci* @param  data [IN] type #hi_u32,Callback function parameter input when the user starts the timer.
461bd4fe43Sopenharmony_ciCNcomment:用户启动定时器时传入的回调函数参数。CNend
471bd4fe43Sopenharmony_ci*
481bd4fe43Sopenharmony_ci* @retval None
491bd4fe43Sopenharmony_ci* @par 依赖:
501bd4fe43Sopenharmony_ci*           @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend
511bd4fe43Sopenharmony_ci* @see  None
521bd4fe43Sopenharmony_ci*/
531bd4fe43Sopenharmony_citypedef hi_void(*hi_hrtimer_callback_f) (hi_u32 data);
541bd4fe43Sopenharmony_ci
551bd4fe43Sopenharmony_ci/**
561bd4fe43Sopenharmony_ci* @ingroup  hrtimer
571bd4fe43Sopenharmony_ci* @brief  Obtains the high resolution timer module handler.CNcomment:获取高精定时器句柄。CNend
581bd4fe43Sopenharmony_ci*
591bd4fe43Sopenharmony_ci* @par 描述:
601bd4fe43Sopenharmony_ci*           Obtains the high resolution timer module handler.CNcomment:获取高精定时器句柄。CNend
611bd4fe43Sopenharmony_ci*
621bd4fe43Sopenharmony_ci* @attention None
631bd4fe43Sopenharmony_ci* @param  timer_handle [OUT] type #hi_u32*,handler obtained. CNcomment:获取到的句柄。CNend
641bd4fe43Sopenharmony_ci*
651bd4fe43Sopenharmony_ci* @retval #0           Success.
661bd4fe43Sopenharmony_ci* @retval #Other       Failure. For details, see hi_errno.h
671bd4fe43Sopenharmony_ci*
681bd4fe43Sopenharmony_ci* @par 依赖:
691bd4fe43Sopenharmony_ci*           @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend
701bd4fe43Sopenharmony_ci*
711bd4fe43Sopenharmony_ci* @see  hi_hrtimer_delete。
721bd4fe43Sopenharmony_ci*/
731bd4fe43Sopenharmony_cihi_u32 hi_hrtimer_create(hi_u32 *timer_handle);
741bd4fe43Sopenharmony_ci
751bd4fe43Sopenharmony_ci/**
761bd4fe43Sopenharmony_ci* @ingroup  hrtimer
771bd4fe43Sopenharmony_ci* @brief  Delete the high resolution timer module handle.CNcomment:删除高精定时器句柄。CNend
781bd4fe43Sopenharmony_ci*
791bd4fe43Sopenharmony_ci* @par 描述:
801bd4fe43Sopenharmony_ci*           Delete the high resolution timer module handle.CNcomment:删除高精定时器句柄。CNend
811bd4fe43Sopenharmony_ci*
821bd4fe43Sopenharmony_ci* @attention None
831bd4fe43Sopenharmony_ci* @param  timer_handle [IN] type #hi_u32,Timer handle, which would be released.
841bd4fe43Sopenharmony_ciCNcomment:要释放的定时器句柄。CNend
851bd4fe43Sopenharmony_ci*
861bd4fe43Sopenharmony_ci* @retval #0           Success.
871bd4fe43Sopenharmony_ci* @retval #Other       Failure. For details, see hi_errno.h
881bd4fe43Sopenharmony_ci*
891bd4fe43Sopenharmony_ci* @par 依赖:
901bd4fe43Sopenharmony_ci*           @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend
911bd4fe43Sopenharmony_ci*
921bd4fe43Sopenharmony_ci* @see  hi_hrtimer_create。
931bd4fe43Sopenharmony_ci*/
941bd4fe43Sopenharmony_cihi_u32 hi_hrtimer_delete(hi_u32 timer_handle);
951bd4fe43Sopenharmony_ci/**
961bd4fe43Sopenharmony_ci* @ingroup  hrtimer
971bd4fe43Sopenharmony_ci* @brief  Starts a high resolution timer.CNcomment:启动高精度定时器。CNend
981bd4fe43Sopenharmony_ci*
991bd4fe43Sopenharmony_ci* @par 描述:
1001bd4fe43Sopenharmony_ci*           Starts the high resolution timer. If the timer has been started, the current timer is stopped and
1011bd4fe43Sopenharmony_ci*           restarted when this API is called.CNcomment:调用该接口启动高精度定时器,如果定时器已经启动,
1021bd4fe43Sopenharmony_ci调用该接口时会停止当前定时器重新启动。CNend
1031bd4fe43Sopenharmony_ci*
1041bd4fe43Sopenharmony_ci* @attention None
1051bd4fe43Sopenharmony_ci* @param  timer_handle [IN] type #hi_u32,Timer handle.CNcomment:定时器句柄。CNend
1061bd4fe43Sopenharmony_ci* @param  expire       [IN] type #hi_u32,Expiration time of the timer (unit: microsecond).When the clock is set to
1071bd4fe43Sopenharmony_ci24M,the maximum of the expiration time is 178s.When the clock is set to 40M,the maximum of the expiration time is 107s.
1081bd4fe43Sopenharmony_ciThe expiration time of the timer must be set to a value smaller than the maximum.
1091bd4fe43Sopenharmony_ciCNcomment:定时器超时时间(单位:μs)。24M时钟可设置的最大超时时间为178s,40M时钟可设置的最大超时时间为107s。
1101bd4fe43Sopenharmony_ci          超时时间必须设置为小于最大超时时间的值。CNend
1111bd4fe43Sopenharmony_ci* @param  hrtimer_func [IN] type #hi_hrtimer_callback_f,Callback function when the timer expires.
1121bd4fe43Sopenharmony_ciCNcomment:定时器到期回调函数。CNend
1131bd4fe43Sopenharmony_ci* @param  data         [IN] type #hi_u32,Input parameter of the timer callback function.
1141bd4fe43Sopenharmony_ciCNcomment:定时器回调函数的入参。CNend
1151bd4fe43Sopenharmony_ci*
1161bd4fe43Sopenharmony_ci* @retval #0           Success.
1171bd4fe43Sopenharmony_ci* @retval #Other       Failure. For details, see hi_errno.h
1181bd4fe43Sopenharmony_ci*
1191bd4fe43Sopenharmony_ci* @par 依赖:
1201bd4fe43Sopenharmony_ci*           @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend
1211bd4fe43Sopenharmony_ci* @see  hi_hrtimer_stop。
1221bd4fe43Sopenharmony_ci*/
1231bd4fe43Sopenharmony_cihi_u32 hi_hrtimer_start(hi_u32 timer_handle, hi_u32 expire, hi_hrtimer_callback_f hrtimer_func, hi_u32 data);
1241bd4fe43Sopenharmony_ci
1251bd4fe43Sopenharmony_ci/**
1261bd4fe43Sopenharmony_ci* @ingroup  hrtimer
1271bd4fe43Sopenharmony_ci* @brief  Stops a high resolution timer.CNcomment:停止高精度定时器。CNend
1281bd4fe43Sopenharmony_ci*
1291bd4fe43Sopenharmony_ci* @par 描述:
1301bd4fe43Sopenharmony_ci*           Stops a high resolution timer. If the timer is stopped when the API is called, no effect is achieved.
1311bd4fe43Sopenharmony_ciCNcomment:调用该接口停止高精度定时器,如果调用该接口时定时器已经停止,不会有任何效果。CNend
1321bd4fe43Sopenharmony_ci*
1331bd4fe43Sopenharmony_ci* @attention None
1341bd4fe43Sopenharmony_ci* @param  timer_handle [IN] type #hi_u32,Timer handle.CNcomment:定时器handle。CNend
1351bd4fe43Sopenharmony_ci*
1361bd4fe43Sopenharmony_ci* @retval #0           Success.
1371bd4fe43Sopenharmony_ci* @retval #Other       Failure. For details, see hi_errno.h
1381bd4fe43Sopenharmony_ci*
1391bd4fe43Sopenharmony_ci* @par 依赖:
1401bd4fe43Sopenharmony_ci*           @li hi_hrtimer.h:Describes timer APIs.CNcomment:文件用于描述定时器相关接口。CNend
1411bd4fe43Sopenharmony_ci* @see  hi_hrtimer_start。
1421bd4fe43Sopenharmony_ci*/
1431bd4fe43Sopenharmony_cihi_u32 hi_hrtimer_stop(hi_u32 timer_handle);
1441bd4fe43Sopenharmony_ci
1451bd4fe43Sopenharmony_ci#endif
146