更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_errno.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_errno Error code
34 * @ingroup kernel
35 */
36
37#ifndef _LOS_ERRNO_H
38#define _LOS_ERRNO_H
39
40#include "los_typedef.h"
41
42#ifdef __cplusplus
43#if __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46#endif /* __cplusplus */
47
48/**
49 * @brief
50 * @verbatim
51 调用API接口时可能会出现错误,此时接口会返回对应的错误码,以便快速定位错误原因。
52
53 错误码是一个32位的无符号整型数,31~24位表示错误等级,23~16位表示错误码标志(当前该标志值为0),
54 15~8位代表错误码所属模块,7~0位表示错误码序号。
55
56 错误码中的错误等级
57 错误等级 数值 含义
58 NORMAL 0 提示
59 WARN 1 告警
60 ERR 2 严重
61 FATAL 3 致命
62
63 例如
64 #define LOS_ERRNO_TSK_NO_MEMORY LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x00)
65 #define LOS_ERRNO_OS_FATAL(MID, ERRNO) \
66 (LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
67 说明
68 LOS_ERRTYPE_FATAL:错误等级为FATAL,值为0x03000000 LOS_ERRNO_OS_ID:错误码标志,
69 值为0x000000 MID:所属模块,LOS_MOD_TSK的值为0x2 ERRNO:错误码序号
70 所以LOS_ERRNO_TSK_NO_MEMORY的值为0x03000200
71
72 错误码接管
73 有时只靠错误码不能快速准确的定位问题,为方便用户分析错误,错误处理模块支持
74 注册错误处理的钩子函数,发生错误时,用户可以调用LOS_ErrHandle接口以执行错误处理函数。
75 * @endverbatim
76 */
77
78
79/**
80 * @ingroup los_errno
81 * OS error code flag.
82 */
83#define LOS_ERRNO_OS_ID (0x00U << 16)
84
85/**
86 * @ingroup los_errno
87 * Define the error level as informative.
88 */
89#define LOS_ERRTYPE_NORMAL (0x00U << 24)
90
91/**
92 * @ingroup los_errno
93 * Define the error level as warning.
94 */
95#define LOS_ERRTYPE_WARN (0x01U << 24)
96
97/**
98 * @ingroup los_errno
99 * Define the error level as critical.
100 */
101#define LOS_ERRTYPE_ERROR (0x02U << 24)
102
103/**
104 * @ingroup los_errno
105 * Define the error level as fatal.
106 */
107#define LOS_ERRTYPE_FATAL (0x03U << 24)
108
109/**
110 * @ingroup los_errno
111 * Define fatal OS errors.
112 */
113#define LOS_ERRNO_OS_FATAL(MID, ERRNO) \
114 (LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
115
116/**
117 * @ingroup los_errno
118 * Define critical OS errors.
119 */
120#define LOS_ERRNO_OS_ERROR(MID, ERRNO) \
121 (LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
122
123/**
124 * @ingroup los_errno
125 * Define warning OS errors.
126 */
127#define LOS_ERRNO_OS_WARN(MID, ERRNO) \
128 (LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
129
130/**
131 * @ingroup los_errno
132 * Define informative OS errors.
133 */
134#define LOS_ERRNO_OS_NORMAL(MID, ERRNO) \
135 (LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(MID) << 8) | ((UINT32)(ERRNO)))
136
137#ifdef __cplusplus
138#if __cplusplus
139}
140#endif /* __cplusplus */
141#endif /* __cplusplus */
142
143#endif /* _LOS_ERRNO_H */