11bd4fe43Sopenharmony_ci/** 21bd4fe43Sopenharmony_ci * @file hi_timer.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. 161bd4fe43Sopenharmony_ci */ 171bd4fe43Sopenharmony_ci 181bd4fe43Sopenharmony_ci/** 191bd4fe43Sopenharmony_ci * @defgroup iot_systimer System Timer 201bd4fe43Sopenharmony_ci * @ingroup osa 211bd4fe43Sopenharmony_ci */ 221bd4fe43Sopenharmony_ci#ifndef __INTERFACE_ROM_HI_TIMER_H__ 231bd4fe43Sopenharmony_ci#define __INTERFACE_ROM_HI_TIMER_H__ 241bd4fe43Sopenharmony_ci#include <hi_types_base.h> 251bd4fe43Sopenharmony_ci 261bd4fe43Sopenharmony_ci 271bd4fe43Sopenharmony_ci/** 281bd4fe43Sopenharmony_ci * @ingroup iot_systimer 291bd4fe43Sopenharmony_ci * 301bd4fe43Sopenharmony_ci * Specifies the type of the timer to be created.CNcomment:用于设置所创建的定时器类型。CNend 311bd4fe43Sopenharmony_ci */ 321bd4fe43Sopenharmony_citypedef enum { 331bd4fe43Sopenharmony_ci HI_TIMER_TYPE_ONCE, /**< Single-period timer.CNcomment:表示单次定时器 CNend */ 341bd4fe43Sopenharmony_ci HI_TIMER_TYPE_PERIOD, /**< Periodic timer.CNcomment:表示周期定时器 CNend */ 351bd4fe43Sopenharmony_ci HI_TIMER_TYPE_MAX /**< Maximum value, which cannot be used.CNcomment:最大值,不可使用 CNend */ 361bd4fe43Sopenharmony_ci} hi_timer_type; 371bd4fe43Sopenharmony_ci 381bd4fe43Sopenharmony_ci/** 391bd4fe43Sopenharmony_ci* @ingroup iot_systimer 401bd4fe43Sopenharmony_ci* @brief Defines the type of the timer callback function.CNcomment:定义定时器回调函数的类型。CNend 411bd4fe43Sopenharmony_ci* 421bd4fe43Sopenharmony_ci* @par 描述: 431bd4fe43Sopenharmony_ci* Defines the type of the timer callback function.CNcomment:定义定时器回调函数的类型。CNend 441bd4fe43Sopenharmony_ci* 451bd4fe43Sopenharmony_ci* @attention None 461bd4fe43Sopenharmony_ci* @param data [IN] type #hi_u32,callback input parameter.CNcomment:回调入参。CNend 471bd4fe43Sopenharmony_ci* 481bd4fe43Sopenharmony_ci* @retval None 491bd4fe43Sopenharmony_ci* @par 依赖: 501bd4fe43Sopenharmony_ci* @li hi_timer.h:Describes the timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 511bd4fe43Sopenharmony_ci* @see hi_timer_start | hi_timer_stop 521bd4fe43Sopenharmony_ci*/ 531bd4fe43Sopenharmony_citypedef hi_void (*hi_timer_callback_f)(hi_u32 data); 541bd4fe43Sopenharmony_ci 551bd4fe43Sopenharmony_ci/** 561bd4fe43Sopenharmony_ci* @ingroup iot_systimer 571bd4fe43Sopenharmony_ci* @brief Creates the system timer.CNcomment:获取定时器句柄。CNend 581bd4fe43Sopenharmony_ci* 591bd4fe43Sopenharmony_ci* @par 描述: 601bd4fe43Sopenharmony_ci* Creates the system timer.CNcomment:获取高精定时器句柄。CNend 611bd4fe43Sopenharmony_ci* 621bd4fe43Sopenharmony_ci* @attention None 631bd4fe43Sopenharmony_ci* @param timer_handle [OUT] type #hi_u32*,handle.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_timer.h:Describes the timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 701bd4fe43Sopenharmony_ci* @see hi_timer_delete。 711bd4fe43Sopenharmony_ci*/ 721bd4fe43Sopenharmony_cihi_u32 hi_timer_create(hi_u32 *timer_handle); 731bd4fe43Sopenharmony_ci 741bd4fe43Sopenharmony_ci/** 751bd4fe43Sopenharmony_ci* @ingroup iot_systimer 761bd4fe43Sopenharmony_ci* @brief Starts the system timer.CNcomment:启动系统定时器。CNend 771bd4fe43Sopenharmony_ci* 781bd4fe43Sopenharmony_ci* @par 描述: 791bd4fe43Sopenharmony_ci* This API is used in the following scenarios:CNcomment:本API接口使用分为以下几个场景:CNend 801bd4fe43Sopenharmony_ci* @li If no timer is created, create and start a timer. 811bd4fe43Sopenharmony_ciCNcomment:如果未启动定时器,则直接启动。CNend 821bd4fe43Sopenharmony_ci* @li If the timer expires and is called again, start the timer directly. 831bd4fe43Sopenharmony_ciCNcomment:如果该定时器到期后调用,则直接启动定时器。CNend 841bd4fe43Sopenharmony_ci* @li If the timer does not expire, stop and restart the timer. 851bd4fe43Sopenharmony_ciCNcomment:如果定时器没有到期,则停止该定时器,重新启动定时器。CNend 861bd4fe43Sopenharmony_ci* 871bd4fe43Sopenharmony_ci* @attention This timer callback function is executed in the interrupt context. Therefore, the callback function should 881bd4fe43Sopenharmony_ci* be as simple as possible and the functions such as sleep and wait semaphores that trigger scheduling 891bd4fe43Sopenharmony_ci* cannot be used.CNcomment:本定时器回调函数执行于中断上下文,回调函数尽量简单,不能使用睡眠、 901bd4fe43Sopenharmony_ci等待信号量等引起调度的函数。CNend 911bd4fe43Sopenharmony_ci* 921bd4fe43Sopenharmony_ci* @param timer_handle [IN] type #hi_u32,handle.CNcomment:句柄。CNend 931bd4fe43Sopenharmony_ci* @param type [IN] type #hi_timer_type,timer type.CNcomment:定时器类型。CNend 941bd4fe43Sopenharmony_ci* @param expire [IN] type #hi_u32,timeout period of the timer (unit: ms). If this parameter is set to 0, 951bd4fe43Sopenharmony_ci* the default value is 10 ms.CNcomment:定时器超时时间(单位:ms)。配置为0时,默认为10ms。CNend 961bd4fe43Sopenharmony_ci* @param timer_func [IN] type #timer_proc_func,timer callback function.CNcomment:定时器回调函数。CNend 971bd4fe43Sopenharmony_ci* @param data [IN] type #hi_u32,callback input parameter.CNcomment:回调函数传参。CNend 981bd4fe43Sopenharmony_ci* 991bd4fe43Sopenharmony_ci* @retval #0 Success. 1001bd4fe43Sopenharmony_ci* @retval #Other Failure. For details, see hi_errno.h. 1011bd4fe43Sopenharmony_ci* 1021bd4fe43Sopenharmony_ci* @par 依赖: 1031bd4fe43Sopenharmony_ci* @li hi_timer.h:Describes the timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 1041bd4fe43Sopenharmony_ci* @see hi_timer_stop 1051bd4fe43Sopenharmony_ci*/ 1061bd4fe43Sopenharmony_cihi_u32 hi_timer_start(hi_u32 timer_handle, hi_timer_type type, hi_u32 expire, 1071bd4fe43Sopenharmony_ci hi_timer_callback_f timer_func, hi_u32 data); 1081bd4fe43Sopenharmony_ci 1091bd4fe43Sopenharmony_ci/** 1101bd4fe43Sopenharmony_ci* @ingroup iot_systimer 1111bd4fe43Sopenharmony_ci* @brief Stops the system timer.CNcomment:停止系统定时器。CNend 1121bd4fe43Sopenharmony_ci* 1131bd4fe43Sopenharmony_ci* @par 描述: 1141bd4fe43Sopenharmony_ci* Stops the system timer.CNcomment:停止系统定时器。CNend 1151bd4fe43Sopenharmony_ci* 1161bd4fe43Sopenharmony_ci* @attention This API only stops the timer and does not delete the timer.CNcomment:本接口仅停止定时器, 1171bd4fe43Sopenharmony_ci并不删除该定时器。CNend 1181bd4fe43Sopenharmony_ci* @param timer_handle [IN] type #hi_u32,handle.CNcomment:句柄。CNend 1191bd4fe43Sopenharmony_ci* 1201bd4fe43Sopenharmony_ci* @retval #0 Success. 1211bd4fe43Sopenharmony_ci* @retval #Other Failure. For details, see hi_errno.h. 1221bd4fe43Sopenharmony_ci* 1231bd4fe43Sopenharmony_ci* @par 依赖: 1241bd4fe43Sopenharmony_ci* @li hi_timer.h:Describes the timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 1251bd4fe43Sopenharmony_ci* @see hi_timer_start | hi_timer_delete 1261bd4fe43Sopenharmony_ci*/ 1271bd4fe43Sopenharmony_cihi_u32 hi_timer_stop(hi_u32 timer_handle); 1281bd4fe43Sopenharmony_ci 1291bd4fe43Sopenharmony_ci/** 1301bd4fe43Sopenharmony_ci* @ingroup iot_systimer 1311bd4fe43Sopenharmony_ci* @brief Deletes the timer.CNcomment:删除定时器。CNend 1321bd4fe43Sopenharmony_ci* 1331bd4fe43Sopenharmony_ci* @par 描述: 1341bd4fe43Sopenharmony_ci* Deletes the timer.CNcomment:删除定时器。CNend 1351bd4fe43Sopenharmony_ci* 1361bd4fe43Sopenharmony_ci* @attention 1371bd4fe43Sopenharmony_ci* @li If the timer does not expire, stop the timer before deleting it. 1381bd4fe43Sopenharmony_ciCNcomment:如果定时器未到期,则先停止该定时器再删除。CNend 1391bd4fe43Sopenharmony_ci* 1401bd4fe43Sopenharmony_ci* @param timer_handle [IN] type #hi_u32,handle.CNcomment:句柄。CNend 1411bd4fe43Sopenharmony_ci* 1421bd4fe43Sopenharmony_ci* @retval #0 Success. 1431bd4fe43Sopenharmony_ci* @retval #Other Failure. For details, see hi_errno.h. 1441bd4fe43Sopenharmony_ci* 1451bd4fe43Sopenharmony_ci* @par 依赖: 1461bd4fe43Sopenharmony_ci* @li hi_timer.h:Describes the timer APIs.CNcomment:文件用于描述定时器相关接口。CNend 1471bd4fe43Sopenharmony_ci* @see hi_timer_start | hi_timer_stop 1481bd4fe43Sopenharmony_ci*/ 1491bd4fe43Sopenharmony_cihi_u32 hi_timer_delete(hi_u32 timer_handle); 1501bd4fe43Sopenharmony_ci 1511bd4fe43Sopenharmony_ci#endif 152