更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_sys.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_sys System time
34 * @ingroup kernel
35 */
36
37#ifndef _LOS_SYS_H
38#define _LOS_SYS_H
39
40#include "los_base.h"
41#include "los_hwi.h"
42#include "los_hw.h"
43
44#ifdef __cplusplus
45#if __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48#endif /* __cplusplus */
49/**
50 * @file los_sys.h
51 * @brief
52@verbatim
53基本概念
54 时间管理以系统时钟为基础,给应用程序提供所有和时间有关的服务。
55
56 系统时钟是由定时器/计数器产生的输出脉冲触发中断产生的,一般定义为整数或长整数。
57 输出脉冲的周期叫做一个“时钟滴答”。系统时钟也称为时标或者Tick。
58
59 用户以秒、毫秒为单位计时,而操作系统以Tick为单位计时,当用户需要对系统进行操作时,
60 例如任务挂起、延时等,此时需要时间管理模块对Tick和秒/毫秒进行转换。
61 时间管理模块提供时间转换、统计、延迟功能
62
63相关概念
64 Cycle
65 系统最小的计时单位。Cycle的时长由系统主时钟频率决定,系统主时钟频率就是每秒钟的Cycle数。
66
67 Tick
68 Tick是操作系统的基本时间单位,由用户配置的每秒Tick数决定。
69
70使用场景
71 用户需要了解当前系统运行的时间以及Tick与秒、毫秒之间的转换关系等。
72
73时间管理的典型开发流程
74 根据实际需求,在板级配置适配时确认是否使能LOSCFG_BASE_CORE_TICK_HW_TIME宏选择外部定时器,
75 并配置系统主时钟频率OS_SYS_CLOCK(单位Hz)。OS_SYS_CLOCK的默认值基于硬件平台配置。
76 通过make menuconfig配置LOSCFG_BASE_CORE_TICK_PER_SECOND。
77
78注意事项
79 时间管理不是单独的功能模块,依赖于OS_SYS_CLOCK和LOSCFG_BASE_CORE_TICK_PER_SECOND两个配置选项。
80 系统的Tick数在关中断的情况下不进行计数,故系统Tick数不能作为准确时间使用。
81
82@endverbatim
83 */
84
85
86/**
87 * @ingroup los_sys
88 * System time basic function error code: Null pointer.
89 *
90 * Value: 0x02000010
91 *
92 * Solution: Check whether the input parameter is null.
93 */
94#define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
95
96/**
97 * @ingroup los_sys
98 * System time basic function error code: Invalid system clock configuration.
99 *
100 * Value: 0x02000011
101 *
102 * Solution: Configure a valid system clock in los_config.h.
103 */
104#define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
105
106/**
107 * @ingroup los_sys
108 * System time basic function error code: This error code is not in use temporarily.
109 *
110 * Value: 0x02000012
111 *
112 * Solution: None.
113 */
114#define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
115
116/**
117 * @ingroup los_sys
118 * System time error code: This error code is not in use temporarily.
119 *
120 * Value: 0x02000013
121 *
122 * Solution: None.
123 */
124#define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
125
126/**
127 * @ingroup los_sys
128 * System time error code: This error code is not in use temporarily.
129 *
130 * Value: 0x02000014
131 *
132 * Solution: None.
133 */
134#define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
135
136/**
137 * @ingroup los_typedef
138 * system time structure.
139 */
140typedef struct tagSysTime {
141 UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */
142 UINT8 ucMonth; /**< value 1 - 12 */
143 UINT8 ucDay; /**< value 1 - 31 */
144 UINT8 ucHour; /**< value 0 - 23 */
145 UINT8 ucMinute; /**< value 0 - 59 */
146 UINT8 ucSecond; /**< value 0 - 59 */
147 UINT8 ucWeek; /**< value 0 - 6 */
149
150/**
151 * @ingroup los_sys
152 * @brief Obtain the number of Ticks.
153 *
154 * @par Description:
155 * This API is used to obtain the number of Ticks.
156 * @attention
157 * <ul>
158 * <li>None</li>
159 * </ul>
160 *
161 * @param None
162 *
163 * @retval UINT64 The number of Ticks.
164 * @par Dependency:
165 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
166 * @see None
167 */
168extern UINT64 LOS_TickCountGet(VOID);
169
170/**
171 * @ingroup los_sys
172 * @brief Obtain the number of cycles in one second.
173 *
174 * @par Description:
175 * This API is used to obtain the number of cycles in one second.
176 * @attention
177 * <ul>
178 * <li>None</li>
179 * </ul>
180 *
181 * @param None
182 *
183 * @retval UINT32 Number of cycles obtained in one second.
184 * @par Dependency:
185 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
186 * @see None
187 */
188extern UINT32 LOS_CyclePerTickGet(VOID);
189
190/**
191 * @ingroup los_sys
192 * @brief Convert Ticks to milliseconds.
193 *
194 * @par Description:
195 * This API is used to convert Ticks to milliseconds.
196 * @attention
197 * <ul>
198 * <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
199 * </ul>
200 *
201 * @param tick [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
202 *
203 * @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
204 * milliseconds.
205 * @par Dependency:
206 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
207 * @see LOS_MS2Tick
208 */
209extern UINT32 LOS_Tick2MS(UINT32 tick);
210
211/**
212 * @ingroup los_sys
213 * @brief Convert milliseconds to Ticks.
214 *
215 * @par Description:
216 * This API is used to convert milliseconds to Ticks.
217 * @attention
218 * <ul>
219 * <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
220 * converted because data possibly overflows.</li>
221 * </ul>
222 *
223 * @param millisec [IN] Number of milliseconds.
224 *
225 * @retval UINT32 Number of Ticks obtained through the conversion.
226 * @par Dependency:
227 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
228 * @see LOS_Tick2MS
229 */
230extern UINT32 LOS_MS2Tick(UINT32 millisec);
231
232#ifdef __cplusplus
233#if __cplusplus
234}
235#endif /* __cplusplus */
236#endif /* __cplusplus */
237
238#endif /* _LOS_SYS_H */
UINT32 LOS_Tick2MS(UINT32 tick)
Convert Ticks to milliseconds.
Definition: los_sys.c:115
UINT32 LOS_MS2Tick(UINT32 millisec)
Convert milliseconds to Ticks.
Definition: los_sys.c:101
UINT64 LOS_TickCountGet(VOID)
Obtain the number of Ticks.
Definition: los_sys.c:82
UINT32 LOS_CyclePerTickGet(VOID)
Obtain the number of cycles in one second.
Definition: los_sys.c:91
struct tagSysTime SYS_TIME_S
unsigned short UINT16
Definition: los_typedef.h:56
long unsigned int UINT64
Definition: los_typedef.h:66
unsigned char UINT8
Definition: los_typedef.h:55
unsigned int UINT32
Definition: los_typedef.h:57
UINT8 ucWeek
Definition: los_sys.h:147
UINT8 ucSecond
Definition: los_sys.h:146
UINT8 ucMonth
Definition: los_sys.h:142
UINT16 uwYear
Definition: los_sys.h:141
UINT8 ucMinute
Definition: los_sys.h:145
UINT8 ucHour
Definition: los_sys.h:144
UINT8 ucDay
Definition: los_sys.h:143