更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_tick.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/**
33 * @defgroup los_tick Tick
34 * @ingroup kernel
35 */
36
37#ifndef _LOS_TICK_H
38#define _LOS_TICK_H
39
40#include "los_err.h"
41#include "los_errno.h"
42#include "hal_timer.h"
43
44#ifdef __cplusplus
45#if __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48#endif /* __cplusplus */
49
50/**
51 * @ingroup los_tick
52 * Tick error code: The Tick configuration is incorrect.
53 *
54 * Value: 0x02000400
55 *
56 * Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND system time configuration modules
57 * in Los_config.h.
58 */ //无效的系统Tick配置
59#define LOS_ERRNO_TICK_CFG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x00)
60
61/**
62 * @ingroup los_tick
63 * Tick error code: This error code is not in use temporarily.
64 *
65 * Value: 0x02000401
66 *
67 * Solution: None.
68 */
69#define LOS_ERRNO_TICK_NO_HWTIMER LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x01)
70
71/**
72 * @ingroup los_tick
73 * Tick error code: The number of Ticks is too small.
74 *
75 * Value: 0x02000402
76 *
77 * Solution: Change values of the OS_SYS_CLOCK and LOSCFG_BASE_CORE_TICK_PER_SECOND system time configuration modules
78 * according to the SysTick_Config function.
79 */
80#define LOS_ERRNO_TICK_PER_SEC_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TICK, 0x02)
81
82/**
83 * @ingroup los_config
84 * system clock
85 */
86extern UINT32 g_sysClock; //系统主时钟
87
88/**
89 * @ingroup los_config
90 * ticks per second
91 */
92extern UINT32 g_tickPerSecond; //每秒TICK数
93
94/**
95 * @ingroup los_tick
96 * @brief Obtain system cycle count.
97 *
98 * @par Description:
99 * This API is used to obtain system cycle count.
100 *
101 * @attention
102 * <ul>
103 * <li> This count is determined by the tick source.</li>
104 * </ul>
105 *
106 * @param puwCntHi [OUT] Type #UINT32 Pointer to the higher 32bit of cycles to be obtained.
107 * @param puwCntLo [OUT] Type #UINT32 Pointer to the lower 32bit of cycles to be obtained.
108 *
109 * @retval None.
110 *
111 * @par Dependency:
112 * <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
113 * @see
114 */ //获取自系统启动以来的Cycle数
115extern VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo);
116
117/**
118 * @ingroup los_tick
119 * @brief Obtain system time in nanoseconds.
120 *
121 * @par Description:
122 * This API is used to obtain system time in nanoseconds.
123 *
124 * @attention None.
125 *
126 * @param None.
127 *
128 * @retval #UINT64 system time in nanoseconds.
129 *
130 * @par Dependency:
131 * <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
132 * @see
133 */ //获取自系统启动以来的纳秒数
134extern UINT64 LOS_CurrNanosec(VOID);
135
136/**
137 * @ingroup los_tick
138 * @brief spinning-delay in microsecond (us).
139 *
140 * @par Description:
141 * This API is used to delay in microsecond.
142 *
143 * @attention None.
144 *
145 * @param #UINT32 microsecond needs to delay.
146 *
147 * @retval None.
148 *
149 * @par Dependency:
150 * <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
151 * @see
152 */ //以us为单位的忙等,但可以被优先级更高的任务抢占
153extern VOID LOS_Udelay(UINT32 usecs);
154
155/**
156 * @ingroup los_tick
157 * @brief spinning-delay in millisecond (ms).
158 *
159 * @par Description:
160 * This API is used to delay in millisecond.
161 *
162 * @attention None.
163 *
164 * @param #UINT32 millisecond needs to delay.
165 *
166 * @retval None.
167 *
168 * @par Dependency:
169 * <ul><li>los_tick.h: the header file that contains the API declaration.</li></ul>
170 * @see
171 */ //以ms为单位的忙等,但可以被优先级更高的任务抢占
172extern VOID LOS_Mdelay(UINT32 usecs);
173
174#ifdef __cplusplus
175#if __cplusplus
176}
177#endif /* __cplusplus */
178#endif /* __cplusplus */
179
180#endif /* _LOS_TICK_H */
UINT32 g_tickPerSecond
每秒Tick数,鸿蒙默认是每秒100次,即:10ms
Definition: los_tick.c:41
UINT32 g_sysClock
系统时钟,是绝大部分部件工作的时钟源,也是其他所有外设的时钟的来源
Definition: los_tick.c:40
VOID LOS_GetCpuCycle(UINT32 *puwCntHi, UINT32 *puwCntLo)
Obtain system cycle count.
Definition: los_hw_tick.c:54
VOID LOS_Udelay(UINT32 usecs)
spinning-delay in microsecond (us).
Definition: los_hw_tick.c:68
UINT64 LOS_CurrNanosec(VOID)
Obtain system time in nanoseconds.
Definition: los_hw_tick.c:62
VOID LOS_Mdelay(UINT32 usecs)
spinning-delay in millisecond (ms).
Definition: los_hw_tick.c:73
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned int UINT32
Definition: los_typedef.h:57