11bd4fe43Sopenharmony_ci/** 21bd4fe43Sopenharmony_ci* @file hi_time.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* Description: time APIs.CNcomment:时间接口描述CNend 181bd4fe43Sopenharmony_ci* @li System time of the hi_get_tick, hi_get_tick64, hi_get_milli_seconds, and hi_get_seconds operations. The system 191bd4fe43Sopenharmony_ci* time is calculated starting from kernel startup and cannot be modified through APIs. 201bd4fe43Sopenharmony_ciCNcomment:hi_get_tick, hi_get_tick64,hi_get_milli_seconds, hi_get_seconds操作的系统时间, 211bd4fe43Sopenharmony_ci系统时间从kernel启动开始计时,不可以通过接口进行修改。CNend 221bd4fe43Sopenharmony_ci* @li The hi_get_real_time and hi_set_real_time APIs are about real-time operations. The real time is calculated 231bd4fe43Sopenharmony_ci* starting from kernel startup and can be modified by hi_set_real_time.CNcomment:hi_get_real_time, 241bd4fe43Sopenharmony_cihi_set_real_time操作的是实时时间,实时时间从kernel启动开始计时,可以通过hi_set_real_time进行修改。CNend \n 251bd4fe43Sopenharmony_ci* Author: Hisilicon \n 261bd4fe43Sopenharmony_ci* Create: 2019-05-29 271bd4fe43Sopenharmony_ci*/ 281bd4fe43Sopenharmony_ci 291bd4fe43Sopenharmony_ci/** 301bd4fe43Sopenharmony_ci * @defgroup iot_time System Clock 311bd4fe43Sopenharmony_ci * @ingroup osa 321bd4fe43Sopenharmony_ci */ 331bd4fe43Sopenharmony_ci#ifndef __HI_TIME_H__ 341bd4fe43Sopenharmony_ci#define __HI_TIME_H__ 351bd4fe43Sopenharmony_ci#include <hi_types_base.h> 361bd4fe43Sopenharmony_ci 371bd4fe43Sopenharmony_ci/** 381bd4fe43Sopenharmony_ci* @ingroup iot_time 391bd4fe43Sopenharmony_ci* @brief Delay, in microseconds.CNcomment:延时,微秒级。CNend 401bd4fe43Sopenharmony_ci* 411bd4fe43Sopenharmony_ci* @par 描述: 421bd4fe43Sopenharmony_ci* Delay operation implemented by software based on the system clock, blocking the CPU. 431bd4fe43Sopenharmony_ciCNcomment:延时操作,阻塞CPU。CNend 441bd4fe43Sopenharmony_ci* 451bd4fe43Sopenharmony_ci* @attention This API cannot be used for a long time in an interrupt.CNcomment:不允许中断中使用。CNend 461bd4fe43Sopenharmony_ci* 471bd4fe43Sopenharmony_ci* @param us [IN] type #hi_u32,delay period (unit: microsecond). 481bd4fe43Sopenharmony_ciCNcomment:延时时间(单位:μs)。CNend 491bd4fe43Sopenharmony_ci* 501bd4fe43Sopenharmony_ci* @retval None 511bd4fe43Sopenharmony_ci* @par 依赖: 521bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 531bd4fe43Sopenharmony_ci* @see None 541bd4fe43Sopenharmony_ci*/ 551bd4fe43Sopenharmony_cihi_void hi_udelay(hi_u32 us); 561bd4fe43Sopenharmony_ci 571bd4fe43Sopenharmony_ci/** 581bd4fe43Sopenharmony_ci* @ingroup iot_time 591bd4fe43Sopenharmony_ci* @brief Obtains the tick value of the system (32-bit).CNcomment:获取系统tick值(32bit)。CNend 601bd4fe43Sopenharmony_ci* 611bd4fe43Sopenharmony_ci* @par 描述: 621bd4fe43Sopenharmony_ci* Obtains the tick value of the system (32-bit).CNcomment:获取系统tick值(32bit)。CNend 631bd4fe43Sopenharmony_ci* 641bd4fe43Sopenharmony_ci* @attention None 651bd4fe43Sopenharmony_ci* @param None 661bd4fe43Sopenharmony_ci* 671bd4fe43Sopenharmony_ci* @retval #hi_u32 Tick value of the system.CNcomment:系统tick值。CNend 681bd4fe43Sopenharmony_ci* @par 依赖: 691bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 701bd4fe43Sopenharmony_ci*/ 711bd4fe43Sopenharmony_cihi_u32 hi_get_tick(hi_void); 721bd4fe43Sopenharmony_ci 731bd4fe43Sopenharmony_ci/** 741bd4fe43Sopenharmony_ci* @ingroup iot_time 751bd4fe43Sopenharmony_ci* @brief Obtains the tick value of the system (64-bit).CNcomment:获取系统tick值(64bit)。CNend 761bd4fe43Sopenharmony_ci* 771bd4fe43Sopenharmony_ci* @par 描述: 781bd4fe43Sopenharmony_ci* Obtains the tick value of the system (64-bit).CNcomment:获取系统tick值(64bit)。CNend 791bd4fe43Sopenharmony_ci* 801bd4fe43Sopenharmony_ci* @attention The hi_mdm_time.h file must be included where the API is called. Otherwise, the API is considered not 811bd4fe43Sopenharmony_ci* declared, and the tick value is returned as an int type, resulting in a truncation error. 821bd4fe43Sopenharmony_ciCNcomment:该接口调用处必须包含头文件hi_time.h,否则按照未声明接口处理,会将tick值当做int类型返回,产生截断错误。CNend 831bd4fe43Sopenharmony_ci* @param None 841bd4fe43Sopenharmony_ci* 851bd4fe43Sopenharmony_ci* @retval #hi_u64 Tick value of the system.CNcomment:系统tick值。CNend 861bd4fe43Sopenharmony_ci* @par 依赖: 871bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 881bd4fe43Sopenharmony_ci*/ 891bd4fe43Sopenharmony_cihi_u64 hi_get_tick64(hi_void); 901bd4fe43Sopenharmony_ci 911bd4fe43Sopenharmony_ci/** 921bd4fe43Sopenharmony_ci* @ingroup iot_time 931bd4fe43Sopenharmony_ci* @brief Obtains the system time (unit: ms).CNcomment:获取系统时间(单位:ms)。CNend 941bd4fe43Sopenharmony_ci* 951bd4fe43Sopenharmony_ci* @par 描述: 961bd4fe43Sopenharmony_ci* Obtains the system time (unit: ms).CNcomment:获取系统时间(单位:ms)。CNend 971bd4fe43Sopenharmony_ci* 981bd4fe43Sopenharmony_ci* @attention None 991bd4fe43Sopenharmony_ci* @param None 1001bd4fe43Sopenharmony_ci* 1011bd4fe43Sopenharmony_ci* @retval #hi_u32 System time.CNcomment:系统时间。CNend 1021bd4fe43Sopenharmony_ci* @par 依赖: 1031bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1041bd4fe43Sopenharmony_ci*/ 1051bd4fe43Sopenharmony_cihi_u32 hi_get_milli_seconds(hi_void); 1061bd4fe43Sopenharmony_ci 1071bd4fe43Sopenharmony_ci/** 1081bd4fe43Sopenharmony_ci* @ingroup iot_time 1091bd4fe43Sopenharmony_ci* @brief Obtains the system time (unit: s).CNcomment:获取系统时间(单位:s)。CNend 1101bd4fe43Sopenharmony_ci* 1111bd4fe43Sopenharmony_ci* @par 描述: 1121bd4fe43Sopenharmony_ci* Obtains the system time (unit: s).CNcomment:获取系统时间(单位:s)。CNend 1131bd4fe43Sopenharmony_ci* 1141bd4fe43Sopenharmony_ci* @attention None 1151bd4fe43Sopenharmony_ci* @param None 1161bd4fe43Sopenharmony_ci* 1171bd4fe43Sopenharmony_ci* @retval #hi_u32 System time.CNcomment:系统时间。CNend 1181bd4fe43Sopenharmony_ci* @retval #HI_ERR_FAILURE failed to be obtained. CNcomment:获取时间失败。CNend 1191bd4fe43Sopenharmony_ci* @par 依赖: 1201bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1211bd4fe43Sopenharmony_ci*/ 1221bd4fe43Sopenharmony_cihi_u32 hi_get_seconds(hi_void); 1231bd4fe43Sopenharmony_ci 1241bd4fe43Sopenharmony_ci/** 1251bd4fe43Sopenharmony_ci* @ingroup iot_time 1261bd4fe43Sopenharmony_ci* @brief Obtains the system time (unit: us).CNcomment:获取系统时间(单位:us)。CNend 1271bd4fe43Sopenharmony_ci* 1281bd4fe43Sopenharmony_ci* @par 描述: 1291bd4fe43Sopenharmony_ci* Obtains the system time (unit: us).CNcomment:获取系统时间(单位:us)。CNend 1301bd4fe43Sopenharmony_ci* 1311bd4fe43Sopenharmony_ci* @attention None 1321bd4fe43Sopenharmony_ci* @param None 1331bd4fe43Sopenharmony_ci* 1341bd4fe43Sopenharmony_ci* @retval #hi_u64 System time.CNcomment:系统时间。CNend 1351bd4fe43Sopenharmony_ci* @retval #HI_ERR_FAILURE failed to be obtained. CNcomment:获取时间失败。CNend 1361bd4fe43Sopenharmony_ci* @par 依赖: 1371bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1381bd4fe43Sopenharmony_ci*/ 1391bd4fe43Sopenharmony_cihi_u64 hi_get_us(hi_void); 1401bd4fe43Sopenharmony_ci 1411bd4fe43Sopenharmony_ci/** 1421bd4fe43Sopenharmony_ci* @ingroup iot_time 1431bd4fe43Sopenharmony_ci* @brief Obtains the real time of the system (unit: s).CNcomment:获取系统实时时间(单位:s)。CNend 1441bd4fe43Sopenharmony_ci* 1451bd4fe43Sopenharmony_ci* @par 描述: 1461bd4fe43Sopenharmony_ci* Obtains the real time of the system (unit: s).CNcomment:获取系统实时时间(单位:s)。CNend 1471bd4fe43Sopenharmony_ci* 1481bd4fe43Sopenharmony_ci* @attention None 1491bd4fe43Sopenharmony_ci* @param None 1501bd4fe43Sopenharmony_ci* 1511bd4fe43Sopenharmony_ci* @retval #hi_u32 Real time of the system.CNcomment: 系统实时时间。CNend 1521bd4fe43Sopenharmony_ci* @retval #HI_ERR_FAILURE failed to be obtained. CNcomment:获取时间失败。CNend 1531bd4fe43Sopenharmony_ci* @par 依赖: 1541bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1551bd4fe43Sopenharmony_ci*/ 1561bd4fe43Sopenharmony_cihi_u32 hi_get_real_time(hi_void); 1571bd4fe43Sopenharmony_ci 1581bd4fe43Sopenharmony_ci/** 1591bd4fe43Sopenharmony_ci* @ingroup iot_time 1601bd4fe43Sopenharmony_ci* @brief Sets the real time of the system.CNcomment:设置系统实时时间。CNend 1611bd4fe43Sopenharmony_ci* 1621bd4fe43Sopenharmony_ci* @par 描述: 1631bd4fe43Sopenharmony_ci* Sets the real time of the system.CNcomment:设置系统实时时间。CNend 1641bd4fe43Sopenharmony_ci* 1651bd4fe43Sopenharmony_ci* @attention None 1661bd4fe43Sopenharmony_ci* @param seconds [IN] type #hi_u32,set the real time of the system to this value. 1671bd4fe43Sopenharmony_ciCNcomment:将系统实时时间设置为该值。CNend 1681bd4fe43Sopenharmony_ci* 1691bd4fe43Sopenharmony_ci* @retval #HI_ERR_SUCCESS Success. 1701bd4fe43Sopenharmony_ci* @retval #HI_ERR_FAILURE Failure. 1711bd4fe43Sopenharmony_ci* @par 依赖: 1721bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1731bd4fe43Sopenharmony_ci*/ 1741bd4fe43Sopenharmony_cihi_u32 hi_set_real_time(hi_u32 seconds); 1751bd4fe43Sopenharmony_ci 1761bd4fe43Sopenharmony_ciextern hi_void_callback g_tick_callback; 1771bd4fe43Sopenharmony_ci 1781bd4fe43Sopenharmony_ci/** 1791bd4fe43Sopenharmony_ci* @ingroup iot_time 1801bd4fe43Sopenharmony_ci* @brief Regiseter system tick callback.CNcomment:注册tick 中断响应回调函数。CNend 1811bd4fe43Sopenharmony_ci* 1821bd4fe43Sopenharmony_ci* @par 描述: 1831bd4fe43Sopenharmony_ci* Regiseter system tick callback, if callback is NULL, means cancel registration. 1841bd4fe43Sopenharmony_ciCNcomment:注册tick中断回调函数,如果回调函数为空,表示取消注册。CNend 1851bd4fe43Sopenharmony_ci* 1861bd4fe43Sopenharmony_ci* @attention 1871bd4fe43Sopenharmony_ci* @li cb should not excute in FLASH, must excute in RAM or ROM. u can specify BSP_RAM_TEXT_SECTION before func 1881bd4fe43Sopenharmony_cito set func excute in RAM. 1891bd4fe43Sopenharmony_ciCNcomment:回调函数不能在FLASH中运行,必须放置在RAM或ROM中,可以通过在 1901bd4fe43Sopenharmony_ci函数名前添加BSP_RAM_TEXT_SECTION 冠头指定函数在RAM中运行。CNend 1911bd4fe43Sopenharmony_ci* @param cb [IN] type #hi_void_callback, callback in tick interrupt.CNcomment:tick中断的回调函数。CNend 1921bd4fe43Sopenharmony_ci* 1931bd4fe43Sopenharmony_ci* @retval #None 1941bd4fe43Sopenharmony_ci* @par 依赖: 1951bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 1961bd4fe43Sopenharmony_ci*/ 1971bd4fe43Sopenharmony_cihi_void hi_tick_register_callback(hi_void_callback cb); 1981bd4fe43Sopenharmony_ci 1991bd4fe43Sopenharmony_ci/** 2001bd4fe43Sopenharmony_ci* @ingroup iot_time 2011bd4fe43Sopenharmony_ci* @brief Convert milliseconds to ticks CNcomment:将毫秒转换为ticks。CNend 2021bd4fe43Sopenharmony_ci* 2031bd4fe43Sopenharmony_ci* @par 描述: 2041bd4fe43Sopenharmony_ci* Convert milliseconds to ticks,ms is greater than 10ms, ticks = ms / 10, 2051bd4fe43Sopenharmony_ci* otherwise see parameter include0 description. 2061bd4fe43Sopenharmony_ciCNcomment: 将milliseconds换算为ticks,ms大于10ms,ticks=ms/10。CNend 2071bd4fe43Sopenharmony_ci* 2081bd4fe43Sopenharmony_ci* @attention None 2091bd4fe43Sopenharmony_ci* @param ms [IN] type #hi_u32, milliseconds. 2101bd4fe43Sopenharmony_ci* @param include0 [IN] type #hi_bool, ms is 0, if include0 is HI_TRUE, return 0 tick,otherwise return 1 tick. 2111bd4fe43Sopenharmony_ciCNcomment:入参ms为0时,如果include0为HI_TRUE,换算结果为0;否则换算结果为1。CNend 2121bd4fe43Sopenharmony_ci* 2131bd4fe43Sopenharmony_ci* @retval #hi_u32 ticks time.CNcomment:ticks时间数 CNend 2141bd4fe43Sopenharmony_ci* @par 依赖: 2151bd4fe43Sopenharmony_ci* @li hi_time.h:Describes system time APIs.CNcomment:文件包含系统时间相关接口。CNend 2161bd4fe43Sopenharmony_ci*/ 2171bd4fe43Sopenharmony_cihi_u32 hi_ms2systick (hi_u32 ms, hi_bool include0); 2181bd4fe43Sopenharmony_ci 2191bd4fe43Sopenharmony_ci#endif 220