• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 
107 
108 /**
109  * @ingroup los_err
110  * @brief Define the pointer to the error handling function.
111  *
112  * @par Description:
113  * This API is used to define the pointer to the error handling function.
114  * @attention
115  * <ul>
116  * <li>None.</li>
117  * </ul>
118  *
119  * @param  fileName  [IN] Log file that stores error information.
120  * @param  lineNo    [IN] Line number of the erroneous line.
121  * @param  errorNo   [IN] Error code.
122  * @param  paraLen   [IN] Length of the input parameter pPara.
123  * @param  para      [IN] User label of the error.
124  *
125  * @retval None.
126  * @par Dependency:
127  * <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
128  * @see None.
129  */
130 typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR    *fileName,
131                                      UINT32   lineNo,     /**< Line number of the erroneous line. */
132                                      UINT32   errorNo,    /**< Error code. */
133                                      UINT32   paraLen,    /**< Length of the input parameter pPara. */
134                                      VOID    *para);
135 
136 /**
137  * @ingroup los_err
138  * @brief Error handling function.
139  *
140  * @par Description:
141  * This API is used to perform different operations according to error types.
142  * @attention
143  * <ul>
144  * <li>None</li>
145  * </ul>
146  *
147  * @param  fileName  [IN] Log file that stores error information.
148  * @param  lineNo    [IN] Line number of the erroneous line which should not be OS_ERR_MAGIC_WORD.
149  * @param  errorNo   [IN] Error code.
150  * @param  paraLen   [IN] Length of the input parameter pPara.
151  * @param  para      [IN] User label of the error.
152  *
153  * @retval LOS_OK The error is successfully processed.
154  * @par Dependency:
155  * <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
156  * @see None
157  */
158 extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo,
159                             UINT32 errorNo, UINT32 paraLen,
160                             VOID *para);
161 
162 /**
163  * @ingroup los_err
164  * Error handling function structure.
165  */
166 typedef struct tagUserErrFunc {
167     LOS_ERRORHANDLE_FUNC  pfnHook;  /**< Hook function for error handling. */
168 } UserErrFunc;
169 
170 
171 enum LOS_MODULE_ID {
172     LOS_MOD_SYS              = 0x0,
173     LOS_MOD_MEM              = 0x1,
174     LOS_MOD_TSK              = 0x2,
175     LOS_MOD_SWTMR            = 0x3,
176     LOS_MOD_TICK             = 0x4,
177     LOS_MOD_MSG              = 0x5,
178     LOS_MOD_QUE              = 0x6,
179     LOS_MOD_SEM              = 0x7,
180     LOS_MOD_MBOX             = 0x8,
181     LOS_MOD_HWI              = 0x9,
182     LOS_MOD_HWWDG            = 0xa,
183     LOS_MOD_CACHE            = 0xb,
184     LOS_MOD_HWTMR            = 0xc,
185     LOS_MOD_MMU              = 0xd,
186 
187     LOS_MOD_LOG              = 0xe,
188     LOS_MOD_ERR              = 0xf,
189 
190     LOS_MOD_EXC              = 0x10,
191     LOS_MOD_CSTK             = 0x11,
192 
193     LOS_MOD_MPU              = 0x12,
194     LOS_MOD_NMHWI            = 0x13,
195     LOS_MOD_TRACE            = 0x14,
196     LOS_MOD_IPC              = 0x18,
197     LOS_MOD_TIMER            = 0x1a,
198     LOS_MOD_EVENT            = 0x1c,
199     LOS_MOD_MUX              = 0X1d,
200     LOS_MOD_CPUP             = 0x1e,
201     LOS_MOD_HOOK             = 0x1f,
202     LOS_MOD_PM               = 0x20,
203     LOS_MOD_LMK              = 0x21,
204     LOS_MOD_SHELL            = 0x31,
205     LOS_MOD_SIGNAL           = 0x32,
206     LOS_MOD_BUTT
207 };
208 
209 /**
210  * @ingroup los_err
211  * Define the error magic word.
212  */
213 #define OS_ERR_MAGIC_WORD           0xa1b2c3f8
214 
215 /**
216  * @ingroup los_err
217  * @brief Error handling macro capable of returning error codes.
218  *
219  * @par Description:
220  * This API is used to call the error handling function by using an error code and return the same error code.
221  * @attention
222  * <ul>
223  * <li>None.</li>
224  * </ul>
225  *
226  * @param  errNo   [IN] Error code.
227  *
228  * @retval errNo
229  * @par Dependency:
230  * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
231  * @see None.
232  */
233 #define OS_RETURN_ERROR(errNo) \
234     do { \
235         (VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \
236         return (errNo); \
237     } while (0)
238 
239 /**
240  * @ingroup los_err
241  * @brief Error handling macro capable of returning error codes.
242  *
243  * @par Description:
244  * This API is used to call the error handling function by using an error code and the line number of the erroneous line,
245    and return the same error code.
246  * @attention
247  * <ul>
248  * <li>None.</li>
249  * </ul>
250  *
251  * @param  errLine   [IN] Line number of the erroneous line.
252  * @param  errNo     [IN] Error code.
253  *
254  * @retval errNo
255  * @par Dependency:
256  * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
257  * @see None.
258  */
259 #define OS_RETURN_ERROR_P2(errLine, errNo) \
260     do { \
261         (VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \
262         return (errNo); \
263     } while (0)
264 
265 /**
266  * @ingroup los_err
267  * @brief Macro for jumping to error handler.
268  *
269  * @par Description:
270  * This API is used to call the error handling function by using an error code.
271  * @attention
272  * <ul>
273  * <li>None.</li>
274  * </ul>
275  *
276  * @param  errorNo   [IN] Error code.
277  *
278  * @retval None.
279  * @par Dependency:
280  * <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
281  * @see None.
282  */
283 #define OS_GOTO_ERR_HANDLER(errorNo) \
284     do { \
285         errNo    = (errorNo); \
286         errLine  = OS_ERR_MAGIC_WORD; \
287         goto ERR_HANDLER; \
288     } while (0)
289 
290 
291 #ifdef __cplusplus
292 #if __cplusplus
293 }
294 #endif /* __cplusplus */
295 #endif /* __cplusplus */
296 
297 #endif /* _LOS_ERRNO_H */
298