• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #ifndef __HI_DEBUG_H__
20 #define __HI_DEBUG_H__
21 
22 #ifndef __KERNEL__
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <assert.h>
26 #endif
27 
28 #include "hi_type.h"
29 #include "hi_common.h"
30 
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif /* __cplusplus */
36 
37 #define _EX__FILE_LINE(fxx, lxx) "[File]:" fxx"\n[Line]:"#lxx"\n[Info]:"
38 #define EX__FILE_LINE(fxx, lxx) _EX__FILE_LINE(fxx, lxx)
39 #define __FILE_LINE__ EX__FILE_LINE(__FILE__, __LINE__)
40 
41 #define HI_DBG_EMERG      0   /* system is unusable                   */
42 #define HI_DBG_ALERT      1   /* action must be taken immediately     */
43 #define HI_DBG_CRIT       2   /* critical conditions                  */
44 #define HI_DBG_ERR        3   /* error conditions                     */
45 #define HI_DBG_WARN       4   /* warning conditions                   */
46 #define HI_DBG_NOTICE     5   /* normal but significant condition     */
47 #define HI_DBG_INFO       6   /* informational                        */
48 #define HI_DBG_DEBUG      7   /* debug-level messages                 */
49 
50 typedef struct hiLOG_LEVEL_CONF_S {
51     MOD_ID_E  enModId;
52     HI_S32    s32Level;
53     HI_CHAR   cModName[16];
54 } LOG_LEVEL_CONF_S;
55 
56 #ifndef __KERNEL__
57 
58 /* For User Mode : HI_PRINT, HI_ASSERT, HI_TRACE */
59 #define HI_PRINT      (hi_void)printf
60 
61 /* #ifdef HI_DEBUG */
62 #ifdef CONFIG_HI_LOG_TRACE_SUPPORT
63     /* Using samples:   HI_ASSERT(x>y); */
64     #define HI_ASSERT(expr)               \
65     do {                                   \
66         if (!(expr)) {                    \
67             (hi_void)printf("\nASSERT at:\n"       \
68                    "  >Function : %s\n"   \
69                    "  >Line No. : %d\n"   \
70                    "  >Condition: %s\n",  __FUNCTION__, __LINE__, #expr); \
71             assert(0); \
72         } \
73     } while (0)
74 
75     /* Using samples:
76      * HI_TRACE(HI_DBG_DEBUG, HI_ID_CMPI, "Test %d, %s\n", 12, "Test");
77      */
78     #define HI_TRACE(level, enModId, fmt...) \
79         do {                                 \
80             if (level <= HI_DBG_ERR)         \
81                 (hi_void)fprintf(stderr, ##fmt);       \
82         } while (0)
83 
84 #else
85     #define HI_ASSERT(expr)
86     #define HI_TRACE(level, enModId, fmt...)
87 #endif
88 
89 #else
90 
91 /* For Linux Kernel : HI_PRINT, HI_ASSERT, HI_TRACE */
92 #define HI_PRINT      (hi_void)osal_printk
93 
94 int HI_LOG(HI_S32 level, MOD_ID_E enModId, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
95 
96 /* #ifdef HI_DEBUG */
97 #ifdef CONFIG_HI_LOG_TRACE_SUPPORT
98     /* Using samples:   HI_ASSERT(x>y); */
99     #define HI_ASSERT(expr)               \
100     do {                                   \
101         if (!(expr)) {                    \
102             osal_panic("\nASSERT at:\n"   \
103                   "  >Function : %s\n"    \
104                   "  >Line No. : %d\n"    \
105                   "  >Condition: %s\n",   __FUNCTION__, __LINE__, #expr); \
106         } \
107     } while (0)
108 
109     /* Using samples:
110      * HI_TRACE(HI_DBG_DEBUG, HI_ID_CMPI, "Test %d, %s\n", 12, "Test");
111      */
112     #define HI_TRACE (hi_void)HI_LOG
113 #else
114     #define HI_ASSERT(expr)
115     #define HI_TRACE(level, enModId, fmt...)
116 #endif
117 
118 #endif /* end of __KERNEL__ */
119 
120 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_EMERG)
121 #define HI_EMERG_TRACE(mod, fmt...) HI_TRACE(HI_DBG_EMERG, mod, fmt)
122 #else
123 #define HI_EMERG_TRACE(mod, fmt...)
124 #endif
125 
126 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_ALERT)
127 #define HI_ALERT_TRACE(mod, fmt...) HI_TRACE(HI_DBG_ALERT, mod, fmt)
128 #else
129 #define HI_ALERT_TRACE(mod, fmt...)
130 #endif
131 
132 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_CRIT)
133 #define HI_CRIT_TRACE(mod, fmt...) HI_TRACE(HI_DBG_CRIT, mod, fmt)
134 #else
135 #define HI_CRIT_TRACE(mod, fmt...)
136 #endif
137 
138 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_ERR)
139 #define HI_ERR_TRACE(mod, fmt...) HI_TRACE(HI_DBG_ERR, mod, fmt)
140 #else
141 #define HI_ERR_TRACE(mod, fmt...)
142 #endif
143 
144 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_WARN)
145 #define HI_WARN_TRACE(mod, fmt...) HI_TRACE(HI_DBG_WARN, mod, fmt)
146 #else
147 #define HI_WARN_TRACE(mod, fmt...)
148 #endif
149 
150 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_NOTICE)
151 #define HI_NOTICE_TRACE(mod, fmt...) HI_TRACE(HI_DBG_NOTICE, mod, fmt)
152 #else
153 #define HI_NOTICE_TRACE(mod, fmt...)
154 #endif
155 
156 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_INFO)
157 #define HI_INFO_TRACE(mod, fmt...) HI_TRACE(HI_DBG_INFO, mod, fmt)
158 #else
159 #define HI_INFO_TRACE(mod, fmt...)
160 #endif
161 
162 #if (CONFIG_HI_LOG_TRACE_LEVEL >= HI_DBG_DEBUG)
163 #define HI_DEBUG_TRACE(mod, fmt...) HI_TRACE(HI_DBG_DEBUG, mod, fmt)
164 #else
165 #define HI_DEBUG_TRACE(mod, fmt...)
166 #endif
167 
168 
169 #ifdef __cplusplus
170 #if __cplusplus
171 }
172 #endif
173 #endif /* __cplusplus */
174 
175 #endif /* __HI_DEBUG_H__ */
176 
177