• 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 /**@defgroup los_debug
33  * @ingroup kernel
34  */
35 
36 #ifndef _LOS_DEBUG_H
37 #define _LOS_DEBUG_H
38 
39 #include "los_config.h"
40 #include "los_compiler.h"
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 #endif /* __cplusplus */
47 
48 #if (LOSCFG_PLATFORM_EXC == 1)
49 enum MemMangType {
50     MEM_MANG_MEMBOX,
51     MEM_MANG_MEMORY,
52     MEM_MANG_EMPTY
53 };
54 
55 typedef struct {
56     UINT32 type;
57     UINT32 startAddr;
58     UINT32 size;
59     VOID *blkAddrArray;
60 } MemInfo;
61 
62 typedef struct {
63     enum MemMangType type;
64     UINT32 startAddr;
65     UINT32 size;
66     UINT32 free;
67     UINT32 blockSize;
68     UINT32 errorAddr;
69     UINT32 errorLen;
70     UINT32 errorOwner;
71 } MemInfoCB;
72 #endif
73 
74 typedef enum {
75     EXC_REBOOT,
76     EXC_ASSERT,
77     EXC_STACKOVERFLOW,
78     EXC_INTERRUPT,
79     EXC_TYPE_END
80 } EXC_TYPE;
81 
82 typedef VOID (*ExcHookFn)(EXC_TYPE excType);
83 
84 VOID OsExcHookRegister(ExcHookFn excHookFn);
85 
86 VOID OsDoExcHook(EXC_TYPE excType);
87 
88 #define LOG_EMG_LEVEL       0
89 
90 #define LOG_COMMON_LEVEL    (LOG_EMG_LEVEL + 1)
91 
92 #define LOG_ERR_LEVEL       (LOG_COMMON_LEVEL + 1)
93 
94 #define LOG_WARN_LEVEL      (LOG_ERR_LEVEL + 1)
95 
96 #define LOG_INFO_LEVEL      (LOG_WARN_LEVEL + 1)
97 
98 #define LOG_DEBUG_LEVEL     (LOG_INFO_LEVEL + 1)
99 
100 #ifndef PRINT_LEVEL
101 #define PRINT_LEVEL         LOG_ERR_LEVEL
102 #endif
103 
104 typedef enum {
105     LOG_MODULE_KERNEL,
106     LOG_MODULE_FS,
107     LOS_MODULE_OTHERS
108 } LogModuleType;
109 
110 /**
111  * @ingroup los_printf
112  * @brief Format and print data.
113  *
114  * @par Description:
115  * Print argument(s) according to fmt.
116  *
117  * @attention
118  * <ul>
119  * <li>None</li>
120  * </ul>
121  *
122  * @param type  [IN] Type LogModuleType indicates the log type.
123  * @param level [IN] Type LogLevel indicates the log level.
124  * @param fmt   [IN] Type char* controls the output as in C printf.
125  *
126  * @retval None
127  * @par Dependency:
128  * <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
129  * @see LOS_Printf
130  */
131 #if (LOSCFG_KERNEL_PRINTF == 1)
132 extern INT32 printf(const CHAR *fmt, ...);
133 extern INT32 OsLogLevelCheck(INT32 level);
134 #define LOS_Printf(type, level, fmt, args...)   do { \
135     if (!OsLogLevelCheck(level)) {                   \
136         printf(fmt, ##args);                         \
137     }                                                \
138 } while (0)
139 #elif (LOSCFG_KERNEL_PRINTF == 0)
140 #define LOS_Printf(type, level, fmt, args...)
141 #else
142 extern VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...);
143 #define LOS_Printf HalConsoleOutput
144 #endif
145 
146 #define PRINT_DEBUG(fmt, args...)    LOS_Printf(LOG_MODULE_KERNEL, LOG_DEBUG_LEVEL, fmt, ##args)
147 #define PRINT_INFO(fmt, args...)     LOS_Printf(LOG_MODULE_KERNEL, LOG_INFO_LEVEL, fmt, ##args)
148 #define PRINT_WARN(fmt, args...)     LOS_Printf(LOG_MODULE_KERNEL, LOG_WARN_LEVEL, fmt, ##args)
149 #define PRINT_ERR(fmt, args...)      LOS_Printf(LOG_MODULE_KERNEL, LOG_ERR_LEVEL, fmt, ##args)
150 #define PRINTK(fmt, args...)         LOS_Printf(LOG_MODULE_KERNEL, LOG_COMMON_LEVEL, fmt, ##args)
151 #define PRINT_EMG(fmt, args...)      LOS_Printf(LOG_MODULE_KERNEL, LOG_EMG_LEVEL, fmt, ##args)
152 
153 #if PRINT_LEVEL < LOG_ERR_LEVEL
154 #define LOS_ASSERT(judge)
155 #else
156 #define LOS_ASSERT(judge)                                                          \
157     do {                                                                           \
158         if ((judge) == 0) {                                                        \
159             OsDoExcHook(EXC_ASSERT);                                               \
160             (VOID)LOS_IntLock();                                                   \
161             PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
162             while (1) { }                                                          \
163         }                                                                          \
164     } while (0)
165 #endif
166 
167 typedef VOID (*BACK_TRACE_HOOK)(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
168 extern VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook);
169 extern VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
170 
171 #ifdef __cplusplus
172 #if __cplusplus
173 }
174 #endif /* __cplusplus */
175 #endif /* __cplusplus */
176 
177 #endif /* _LOS_PRINTF_H */
178