1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2022 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_errno Error code 34 * @ingroup kernel 35 */ 36 37 #ifndef _LOS_ERRNO_H 38 #define _LOS_ERRNO_H 39 #include "los_compiler.h" 40 #ifdef __cplusplus 41 #if __cplusplus 42 extern "C" { 43 #endif /* __cplusplus */ 44 #endif /* __cplusplus */ 45 46 47 /** 48 * @ingroup los_errno 49 * OS error code flag. 50 */ 51 #define LOS_ERRNO_OS_ID ((UINT32)0x00 << 16) 52 53 /** 54 * @ingroup los_errno 55 * Define the error level as informative. 56 */ 57 #define LOS_ERRTYPE_NORMAL ((UINT32)0x00 << 24) 58 59 /** 60 * @ingroup los_errno 61 * Define the error level as warning. 62 */ 63 #define LOS_ERRTYPE_WARN ((UINT32)0x01 << 24) 64 65 /** 66 * @ingroup los_errno 67 * Define the error level as critical. 68 */ 69 #define LOS_ERRTYPE_ERROR ((UINT32)0x02 << 24) 70 71 /** 72 * @ingroup los_errno 73 * Define the error level as fatal. 74 */ 75 #define LOS_ERRTYPE_FATAL ((UINT32)0x03 << 24) 76 77 /** 78 * @ingroup los_errno 79 * Define fatal OS errors. 80 */ 81 #define LOS_ERRNO_OS_FATAL(moduleID, errno) \ 82 (LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno)) 83 84 /** 85 * @ingroup los_errno 86 * Define critical OS errors. 87 */ 88 #define LOS_ERRNO_OS_ERROR(moduleID, errno) \ 89 (LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno)) 90 91 /** 92 * @ingroup los_errno 93 * Define warning OS errors. 94 */ 95 #define LOS_ERRNO_OS_WARN(moduleID, errno) \ 96 (LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno)) 97 98 /** 99 * @ingroup los_errno 100 * Define informative OS errors. 101 */ 102 #define LOS_ERRNO_OS_NORMAL(moduleID, errno) \ 103 (LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno)) 104 105 /** 106 * @ingroup los_err 107 * @brief Define the pointer to the error handling function. 108 * 109 * @par Description: 110 * This API is used to define the pointer to the error handling function. 111 * @attention 112 * <ul> 113 * <li>None.</li> 114 * </ul> 115 * 116 * @param fileName [IN] Log file that stores error information. 117 * @param lineNo [IN] Line number of the erroneous line. 118 * @param errorNo [IN] Error code. 119 * @param paraLen [IN] Length of the input parameter pPara. 120 * @param para [IN] User label of the error. 121 * 122 * @retval None. 123 * @par Dependency: 124 * <ul><li>los_err.h: the header file that contains the API declaration.</li></ul> 125 * @see None. 126 */ 127 typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName, 128 UINT32 lineNo, /**< Line number of the erroneous line. */ 129 UINT32 errorNo, /**< Error code. */ 130 UINT32 paraLen, /**< Length of the input parameter pPara. */ 131 VOID *para); 132 133 /** 134 * @ingroup los_err 135 * @brief Error handling function. 136 * 137 * @par Description: 138 * This API is used to perform different operations according to error types. 139 * @attention 140 * <ul> 141 * <li>None</li> 142 * </ul> 143 * 144 * @param fileName [IN] Log file that stores error information. 145 * @param lineNo [IN] Line number of the erroneous line which should not be OS_ERR_MAGIC_WORD. 146 * @param errorNo [IN] Error code. 147 * @param paraLen [IN] Length of the input parameter pPara. 148 * @param para [IN] User label of the error. 149 * 150 * @retval LOS_OK The error is successfully processed. 151 * @par Dependency: 152 * <ul><li>los_err.h: the header file that contains the API declaration.</li></ul> 153 * @see None 154 */ 155 extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo, 156 UINT32 errorNo, UINT32 paraLen, 157 VOID *para); 158 159 /** 160 * @ingroup los_err 161 * Error handling function structure. 162 */ 163 typedef struct tagUserErrFunc { 164 LOS_ERRORHANDLE_FUNC pfnHook; /**< Hook function for error handling. */ 165 } UserErrFunc; 166 167 168 enum LOS_MODULE_ID { 169 LOS_MOD_SYS = 0x0, 170 LOS_MOD_MEM = 0x1, 171 LOS_MOD_TSK = 0x2, 172 LOS_MOD_SWTMR = 0x3, 173 LOS_MOD_TICK = 0x4, 174 LOS_MOD_MSG = 0x5, 175 LOS_MOD_QUE = 0x6, 176 LOS_MOD_SEM = 0x7, 177 LOS_MOD_MBOX = 0x8, 178 LOS_MOD_HWI = 0x9, 179 LOS_MOD_HWWDG = 0xa, 180 LOS_MOD_CACHE = 0xb, 181 LOS_MOD_HWTMR = 0xc, 182 LOS_MOD_MMU = 0xd, 183 184 LOS_MOD_LOG = 0xe, 185 LOS_MOD_ERR = 0xf, 186 187 LOS_MOD_EXC = 0x10, 188 LOS_MOD_CSTK = 0x11, 189 190 LOS_MOD_MPU = 0x12, 191 LOS_MOD_NMHWI = 0x13, 192 LOS_MOD_TRACE = 0x14, 193 LOS_MOD_IPC = 0x18, 194 LOS_MOD_TIMER = 0x1a, 195 LOS_MOD_EVENT = 0x1c, 196 LOS_MOD_MUX = 0X1d, 197 LOS_MOD_CPUP = 0x1e, 198 LOS_MOD_HOOK = 0x1f, 199 LOS_MOD_PM = 0x20, 200 LOS_MOD_LMK = 0x21, 201 LOS_MOD_SHELL = 0x31, 202 LOS_MOD_SIGNAL = 0x32, 203 LOS_MOD_BUTT 204 }; 205 206 /** 207 * @ingroup los_err 208 * Define the error magic word. 209 */ 210 #define OS_ERR_MAGIC_WORD 0xa1b2c3f8 211 212 /** 213 * @ingroup los_err 214 * @brief Error handling macro capable of returning error codes. 215 * 216 * @par Description: 217 * This API is used to call the error handling function by using an error code and return the same error code. 218 * @attention 219 * <ul> 220 * <li>None.</li> 221 * </ul> 222 * 223 * @param errNo [IN] Error code. 224 * 225 * @retval errNo 226 * @par Dependency: 227 * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul> 228 * @see None. 229 */ 230 #define OS_RETURN_ERROR(errNo) \ 231 do { \ 232 (VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \ 233 return (errNo); \ 234 } while (0) 235 236 /** 237 * @ingroup los_err 238 * @brief Error handling macro capable of returning error codes. 239 * 240 * @par Description: 241 * This API is used to call the error handling function by using an error code and the line number of the erroneous line, 242 and return the same error code. 243 * @attention 244 * <ul> 245 * <li>None.</li> 246 * </ul> 247 * 248 * @param errLine [IN] Line number of the erroneous line. 249 * @param errNo [IN] Error code. 250 * 251 * @retval errNo 252 * @par Dependency: 253 * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul> 254 * @see None. 255 */ 256 #define OS_RETURN_ERROR_P2(errLine, errNo) \ 257 do { \ 258 (VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \ 259 return (errNo); \ 260 } while (0) 261 262 /** 263 * @ingroup los_err 264 * @brief Macro for jumping to error handler. 265 * 266 * @par Description: 267 * This API is used to call the error handling function by using an error code. 268 * @attention 269 * <ul> 270 * <li>None.</li> 271 * </ul> 272 * 273 * @param errorNo [IN] Error code. 274 * 275 * @retval None. 276 * @par Dependency: 277 * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul> 278 * @see None. 279 */ 280 #define OS_GOTO_ERR_HANDLER(errorNo) \ 281 do { \ 282 errNo = (errorNo); \ 283 errLine = OS_ERR_MAGIC_WORD; \ 284 goto ERR_HANDLER; \ 285 } while (0) 286 287 288 #ifdef __cplusplus 289 #if __cplusplus 290 } 291 #endif /* __cplusplus */ 292 #endif /* __cplusplus */ 293 294 #endif /* _LOS_ERRNO_H */ 295