• 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_PANIC,
78      EXC_STACKOVERFLOW,
79      EXC_INTERRUPT,
80      EXC_TYPE_END
81  } EXC_TYPE;
82  
83  typedef VOID (*ExcHookFn)(EXC_TYPE excType);
84  
85  VOID OsExcHookRegister(ExcHookFn excHookFn);
86  
87  VOID OsDoExcHook(EXC_TYPE excType);
88  
89  #define LOG_EMG_LEVEL       0
90  
91  #define LOG_COMMON_LEVEL    (LOG_EMG_LEVEL + 1)
92  
93  #define LOG_ERR_LEVEL       (LOG_COMMON_LEVEL + 1)
94  
95  #define LOG_WARN_LEVEL      (LOG_ERR_LEVEL + 1)
96  
97  #define LOG_INFO_LEVEL      (LOG_WARN_LEVEL + 1)
98  
99  #define LOG_DEBUG_LEVEL     (LOG_INFO_LEVEL + 1)
100  
101  #ifndef PRINT_LEVEL
102  #define PRINT_LEVEL         LOG_ERR_LEVEL
103  #endif
104  
105  typedef enum {
106      LOG_MODULE_KERNEL,
107      LOG_MODULE_FS,
108      LOS_MODULE_OTHERS
109  } LogModuleType;
110  
111  /**
112   * @ingroup los_printf
113   * @brief Format and print data.
114   *
115   * @par Description:
116   * Print argument(s) according to fmt.
117   *
118   * @attention
119   * <ul>
120   * <li>None</li>
121   * </ul>
122   *
123   * @param type  [IN] Type LogModuleType indicates the log type.
124   * @param level [IN] Type LogLevel indicates the log level.
125   * @param fmt   [IN] Type char* controls the output as in C printf.
126   *
127   * @retval None
128   * @par Dependency:
129   * <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
130   * @see LOS_Printf
131   */
132  #if (LOSCFG_KERNEL_PRINTF == 1)
133  extern INT32 printf(const CHAR *fmt, ...);
134  extern INT32 OsLogLevelCheck(INT32 level);
135  #define LOS_Printf(type, level, fmt, args...)   do { \
136      if (!OsLogLevelCheck(level)) {                   \
137          printf(fmt, ##args);                         \
138      }                                                \
139  } while (0)
140  #elif (LOSCFG_KERNEL_PRINTF == 0)
141  #define LOS_Printf(type, level, fmt, args...)
142  #else
143  extern VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...);
144  #define LOS_Printf HalConsoleOutput
145  #endif
146  
147  #define PRINT_DEBUG(fmt, args...)    LOS_Printf(LOG_MODULE_KERNEL, LOG_DEBUG_LEVEL, fmt, ##args)
148  #define PRINT_INFO(fmt, args...)     LOS_Printf(LOG_MODULE_KERNEL, LOG_INFO_LEVEL, fmt, ##args)
149  #define PRINT_WARN(fmt, args...)     LOS_Printf(LOG_MODULE_KERNEL, LOG_WARN_LEVEL, fmt, ##args)
150  #define PRINT_ERR(fmt, args...)      LOS_Printf(LOG_MODULE_KERNEL, LOG_ERR_LEVEL, fmt, ##args)
151  #define PRINTK(fmt, args...)         LOS_Printf(LOG_MODULE_KERNEL, LOG_COMMON_LEVEL, fmt, ##args)
152  #define PRINT_EMG(fmt, args...)      LOS_Printf(LOG_MODULE_KERNEL, LOG_EMG_LEVEL, fmt, ##args)
153  
154  #if PRINT_LEVEL < LOG_ERR_LEVEL
155  #define LOS_ASSERT(judge)
156  #else
157  #define LOS_ASSERT(judge)                                                          \
158      do {                                                                           \
159          if ((judge) == 0) {                                                        \
160              OsDoExcHook(EXC_ASSERT);                                               \
161              (VOID)LOS_IntLock();                                                   \
162              PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
163              while (1) { }                                                          \
164          }                                                                          \
165      } while (0)
166  #endif
167  
168  typedef VOID (*BACK_TRACE_HOOK)(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
169  extern VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook);
170  extern VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
171  
172  #ifdef __cplusplus
173  #if __cplusplus
174  }
175  #endif /* __cplusplus */
176  #endif /* __cplusplus */
177  
178  #endif /* _LOS_PRINTF_H */
179