• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2015-2018. All rights reserved.
3  * Description: System time
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
9  * of conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  * --------------------------------------------------------------------------- */
26 
27 /**
28  * @defgroup los_sys System time
29  * @ingroup kernel
30  */
31 
32 #ifndef _LOS_SYS_H
33 #define _LOS_SYS_H
34 
35 #include "los_base.h"
36 
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 #endif /* __cplusplus */
42 
43 /**
44  * @ingroup los_sys
45  * System time basic function error code: Null pointer.
46  *
47  * Value: 0x02000010
48  *
49  * Solution: Check whether the input parameter is null.
50  */
51 #define LOS_ERRNO_SYS_PTR_NULL                 LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10)
52 
53 /**
54  * @ingroup los_sys
55  * System time basic function error code: Invalid system clock configuration.
56  *
57  * Value: 0x02000011
58  *
59  * Solution: Configure a valid system clock in los_config.h.
60  */
61 #define LOS_ERRNO_SYS_CLOCK_INVALID            LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11)
62 
63 /**
64  * @ingroup los_sys
65  * System time basic function error code: This error code is not in use temporarily.
66  *
67  * Value: 0x02000012
68  *
69  * Solution: None.
70  */
71 #define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12)
72 
73 /**
74  * @ingroup los_sys
75  * System time error code: This error code is not in use temporarily.
76  *
77  * Value: 0x02000013
78  *
79  * Solution: None.
80  */
81 #define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13)
82 
83 /**
84  * @ingroup los_sys
85  * System time error code: This error code is not in use temporarily.
86  *
87  * Value: 0x02000014
88  *
89  * Solution: None.
90  */
91 #define LOS_ERRNO_SYS_HOOK_IS_FULL             LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14)
92 
93 /**
94  * @ingroup los_typedef
95  * system time structure.
96  */
97 typedef struct tagSysTime {
98     UINT16  uwYear;    /**< value 1970 ~ 2038 or 1970 ~ 2100 */
99     UINT8   ucMonth;   /**< value 1 - 12 */
100     UINT8   ucDay;     /**< value 1 - 31 */
101     UINT8   ucHour;    /**< value 0 - 23 */
102     UINT8   ucMinute;  /**< value 0 - 59 */
103     UINT8   ucSecond;  /**< value 0 - 59 */
104     UINT8   ucWeek;    /**< value 0 - 6  */
105 } SYS_TIME_S;
106 
107 /**
108  * @ingroup los_sys
109  * @brief Obtain the number of Ticks.
110  *
111  * @par Description:
112  * This API is used to obtain the number of Ticks.
113  * @attention
114  * <ul>
115  * <li>None</li>
116  * </ul>
117  *
118  * @param  None
119  *
120  * @retval UINT64 The number of Ticks.
121  * @par Dependency:
122  * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
123  * @see None
124  */
125 extern UINT64 LOS_TickCountGet(VOID);
126 
127 /**
128  * @ingroup los_sys
129  * @brief Obtain the number of cycles in one second.
130  *
131  * @par Description:
132  * This API is used to obtain the number of cycles in one second.
133  * @attention
134  * <ul>
135  * <li>None</li>
136  * </ul>
137  *
138  * @param  None
139  *
140  * @retval UINT32 Number of cycles obtained in one second.
141  * @par Dependency:
142  * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
143  * @see None
144  */
145 extern UINT32 LOS_CyclePerTickGet(VOID);
146 
147 /**
148  * @ingroup los_sys
149  * @brief Convert Ticks to milliseconds.
150  *
151  * @par Description:
152  * This API is used to convert Ticks to milliseconds.
153  * @attention
154  * <ul>
155  * <li>The number of milliseconds obtained through the conversion is 32-bit.</li>
156  * </ul>
157  *
158  * @param  ticks  [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK).
159  *
160  * @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to
161  * milliseconds.
162  * @par  Dependency:
163  * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
164  * @see LOS_MS2Tick
165  */
166 extern UINT32 LOS_Tick2MS(UINT32 ticks);
167 
168 /**
169  * @ingroup los_sys
170  * @brief Convert milliseconds to Ticks.
171  *
172  * @par Description:
173  * This API is used to convert milliseconds to Ticks.
174  * @attention
175  * <ul>
176  * <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be
177  * converted because data possibly overflows.</li>
178  * </ul>
179  *
180  * @param  millisec  [IN] Number of milliseconds.
181  *
182  * @retval UINT32 Number of Ticks obtained through the conversion.
183  * @par Dependency:
184  * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul>
185  * @see LOS_Tick2MS
186  */
187 extern UINT32 LOS_MS2Tick(UINT32 millisec);
188 
189 #ifdef __cplusplus
190 #if __cplusplus
191 }
192 #endif /* __cplusplus */
193 #endif /* __cplusplus */
194 
195 #endif /* _LOS_SYS_H */
196