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 46 extern "C" { 47 #endif /* __cplusplus */ 48 #endif /* __cplusplus */ 49 50 /** 51 * @ingroup los_sys 52 * System time basic function error code: Null pointer. 53 * 54 * Value: 0x02000010 55 * 56 * Solution: Check whether the input parameter is null. 57 */ 58 #define LOS_ERRNO_SYS_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x10) 59 60 /** 61 * @ingroup los_sys 62 * System time basic function error code: Invalid system clock configuration. 63 * 64 * Value: 0x02000011 65 * 66 * Solution: Configure a valid system clock in los_config.h. 67 */ 68 #define LOS_ERRNO_SYS_CLOCK_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x11) 69 70 /** 71 * @ingroup los_sys 72 * System time basic function error code: This error code is not in use temporarily. 73 * 74 * Value: 0x02000012 75 * 76 * Solution: None. 77 */ 78 #define LOS_ERRNO_SYS_MAXNUMOFCORES_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x12) 79 80 /** 81 * @ingroup los_sys 82 * System time error code: This error code is not in use temporarily. 83 * 84 * Value: 0x02000013 85 * 86 * Solution: None. 87 */ 88 #define LOS_ERRNO_SYS_PERIERRCOREID_IS_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x13) 89 90 /** 91 * @ingroup los_sys 92 * System time error code: This error code is not in use temporarily. 93 * 94 * Value: 0x02000014 95 * 96 * Solution: None. 97 */ 98 #define LOS_ERRNO_SYS_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_SYS, 0x14) 99 100 /** 101 * @ingroup los_typedef 102 * system time structure. 103 */ 104 typedef struct tagSysTime { 105 UINT16 uwYear; /**< value 1970 ~ 2038 or 1970 ~ 2100 */ 106 UINT8 ucMonth; /**< value 1 - 12 */ 107 UINT8 ucDay; /**< value 1 - 31 */ 108 UINT8 ucHour; /**< value 0 - 23 */ 109 UINT8 ucMinute; /**< value 0 - 59 */ 110 UINT8 ucSecond; /**< value 0 - 59 */ 111 UINT8 ucWeek; /**< value 0 - 6 */ 112 } SYS_TIME_S; 113 114 /** 115 * @ingroup los_sys 116 * @brief Obtain the number of Ticks. 117 * 118 * @par Description: 119 * This API is used to obtain the number of Ticks. 120 * @attention 121 * <ul> 122 * <li>None</li> 123 * </ul> 124 * 125 * @param None 126 * 127 * @retval UINT64 The number of Ticks. 128 * @par Dependency: 129 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul> 130 * @see None 131 */ 132 extern UINT64 LOS_TickCountGet(VOID); 133 134 /** 135 * @ingroup los_sys 136 * @brief Obtain the number of cycles in one second. 137 * 138 * @par Description: 139 * This API is used to obtain the number of cycles in one second. 140 * @attention 141 * <ul> 142 * <li>None</li> 143 * </ul> 144 * 145 * @param None 146 * 147 * @retval UINT32 Number of cycles obtained in one second. 148 * @par Dependency: 149 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul> 150 * @see None 151 */ 152 extern UINT32 LOS_CyclePerTickGet(VOID); 153 154 /** 155 * @ingroup los_sys 156 * @brief Convert Ticks to milliseconds. 157 * 158 * @par Description: 159 * This API is used to convert Ticks to milliseconds. 160 * @attention 161 * <ul> 162 * <li>The number of milliseconds obtained through the conversion is 32-bit.</li> 163 * </ul> 164 * 165 * @param tick [IN] Number of Ticks. The value range is (0,OS_SYS_CLOCK). 166 * 167 * @retval UINT32 Number of milliseconds obtained through the conversion. Ticks are successfully converted to 168 * milliseconds. 169 * @par Dependency: 170 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul> 171 * @see LOS_MS2Tick 172 */ 173 extern UINT32 LOS_Tick2MS(UINT32 tick); 174 175 /** 176 * @ingroup los_sys 177 * @brief Convert milliseconds to Ticks. 178 * 179 * @par Description: 180 * This API is used to convert milliseconds to Ticks. 181 * @attention 182 * <ul> 183 * <li>If the parameter passed in is equal to 0xFFFFFFFF, the retval is 0xFFFFFFFF. Pay attention to the value to be 184 * converted because data possibly overflows.</li> 185 * </ul> 186 * 187 * @param millisec [IN] Number of milliseconds. 188 * 189 * @retval UINT32 Number of Ticks obtained through the conversion. 190 * @par Dependency: 191 * <ul><li>los_sys.h: the header file that contains the API declaration.</li></ul> 192 * @see LOS_Tick2MS 193 */ 194 extern UINT32 LOS_MS2Tick(UINT32 millisec); 195 196 #ifdef __cplusplus 197 #if __cplusplus 198 } 199 #endif /* __cplusplus */ 200 #endif /* __cplusplus */ 201 202 #endif /* _LOS_SYS_H */ 203