• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_LOG_H__
20 #define __HI_LOG_H__
21 #include <linux/version.h>
22 #include "hi_type.h"
23 #include "hi_module.h"
24 
25 #define __HI_DEBUG_H__
26 
27 #if defined(HI_LOG_SUPPORT) && (0 == HI_LOG_SUPPORT)
28 #undef HI_DEBUG
29 
30 #define HI_PANIC(fmt...) \
31     do {                 \
32     } while (0)
33 
34 #define HI_PRINT(fmt...) \
35     do {                 \
36     } while (0)
37 #else
38 #define HI_DEBUG
39 
40 #ifdef __OS_LINUX__
41 #ifdef __KERNEL__
42 #include <linux/printk.h>
43 #define HI_PRINT printk
44 #else
45 #include <stdio.h>
46 #define HI_PRINT printf
47 #endif /* end of __KERNEL__ */
48 #else  /* __OS_ECOS__ */
49 #define HI_PRINT printf
50 #endif /* end of __OS_LINUX__ */
51 
52 #ifdef __KERNEL__
53 #define HI_PANIC printk
54 #else
55 #define HI_PANIC printf
56 #endif
57 
58 #endif
59 
60 #ifdef __cplusplus
61 #if __cplusplus
62 extern "C" {
63 #endif
64 #endif /* __cplusplus */
65 
66 /*************************** Structure Definition ****************************/
67 /* \addtogroup     HI_DEBUG */
68 /* @{ */ /* <!-- [HI_DEBUG] */
69 
70 /* Default level of the output debugging information */
71 /* CNcomment: 默认的调试信息输出级别 */
72 #define HI_LOG_LEVEL_DEFAULT HI_LOG_LEVEL_NOTICE
73 
74 /* Level of the output debugging information */
75 /* CNcomment: 调试信息输出级别 */
76 typedef enum HI_LOG_LEVEL_E {
77     /* <fatal error. it indicates that a critical problem occurs in the system. */
78     /* therefore, you must pay attention to it. */
79     HI_LOG_LEVEL_FATAL = 0,
80     /* <CNcomment: 致命错误, 此类错误需要特别关注,一般出现此类错误代表系统出现了重大问题 */
81     /* <Major error. It indicates that a major problem occurs in the system and the system cannot run. */
82     HI_LOG_LEVEL_ERROR = 1,
83     /* <CNcomment: 一般错误, 一般出现此类错误代表系统出现了比较大的问题,不能再正常运行 */
84     /* <Warning. It indicates that a minor problem occurs in the system, but the system still can run properly. */
85     HI_LOG_LEVEL_WARNING = 2,
86     /* <CNcomment: 告警信息, 一般出现此类信息代表系统可能出现问题,但是还能继续运行 */
87     /* <Notice. It indicates that a normal but significant condition in the system, */
88     /* but the system still can run properly. */
89     HI_LOG_LEVEL_NOTICE = 3,
90     /* <CNcomment: 正常但重要的信息, 一般出现在系统的关键路径调用上 */
91     /* <Message. It is used to prompt users. Users can open the message when locating problems. */
92     /* It is recommended to disable this message in general. */
93     HI_LOG_LEVEL_INFO = 4,
94     /* <CNcomment: 提示信息, 一般是为提醒用户而输出,在定位问题的时候可以打开,一般情况下建议关闭 */
95     /* <Debug. It is used to prompt developers. Developers can open the message when locating problems. */
96     /* It is recommended to disable this message in general. */
97     HI_LOG_LEVEL_DBG = 5,
98     /* <CNcomment: 提示信息, 一般是为开发人员调试问题而设定的打印级别,一般情况下建议关闭 */
99     /* <Verbose. It is used to prompt developers. Developers can open the message when locating problems. */
100     /* It is recommended to disable this message in general. */
101     HI_LOG_LEVEL_VERBOSE = 6,
102 
103     HI_LOG_LEVEL_BUTT
104 } HI_LOG_LEVEL_E;
105 
106 /* Just only for fatal level print.   */ /* CNcomment: 为了打印致命信息而制定的宏打印级别 */
107 #define HI_TRACE_LEVEL_FATAL (0)
108 /* Just only for error level print.   */ /* CNcomment: 为了打印错误信息而制定的宏打印级别 */
109 #define HI_TRACE_LEVEL_ERROR (1)
110 /* Just only for warning level print. */ /* CNcomment: 为了打印警告信息而制定的宏打印级别 */
111 #define HI_TRACE_LEVEL_WARN (2)
112 /* Just only for notice level print.  */ /* CNcomment: 为了打印注意信息而制定的宏打印级别 */
113 #define HI_TRACE_LEVEL_NOTICE (3)
114 /* Just only for info level print.    */ /* CNcomment: 为了打印信息级别而制定的宏打印级别 */
115 #define HI_TRACE_LEVEL_INFO (4)
116 /* Just only for debug level print.   */ /* CNcomment: 为了打印调试信息而制定的宏打印级别 */
117 #define HI_TRACE_LEVEL_DBG (5)
118 /* Just only for verbose level print. */ /* CNcomment: 为了打印冗长的调试信息而制定的宏打印级别 */
119 #define HI_TRACE_LEVEL_VERBOSE (6)
120 
121 /* Just only debug output,MUST BE NOT calling it. */
122 /* CNcomment: 调试输出信息接口,不推荐直接调用此接口 */
123 extern hi_void hi_log_out(hi_u32 level, HI_MOD_ID_E enModId,
124                          hi_u8 *p_func_name, hi_u32 line_num, const char *format, ...);
125 extern hi_void hi_log_out(hi_u32 level, HI_MOD_ID_E enModId,
126 		                         hi_u8 *p_func_name, hi_u32 line_num, const char *format, ...);
127 extern hi_u32 log_get_time_ms(void);
128 
129 #ifdef HI_DEBUG
130 
131 #ifndef LOG_D_MODULE_ID
132 #define LOG_D_MODULE_ID HI_ID_SYS
133 #endif
134 
135 #ifndef HI_LOG_LEVEL
136 #define HI_LOG_LEVEL (HI_TRACE_LEVEL_DBG)
137 #endif
138 
139 #ifdef __KERNEL__
140 #if !defined(CFG_HI_USER_DRV)
141 #define HI_TRACE(level, module_id, fmt...)                                 \
142     do {                                                                   \
143         hi_log_out(level, module_id, (hi_u8 *)__FUNCTION__, __LINE__, fmt); \
144     } while (0)
145 #else
146 #define HI_TRACE(level, module_id, fmt...) \
147     do { \
148         if (level <= HI_TRACE_LEVEL_ERROR) { \
149             printk(fmt); \
150         } \
151     } while (0)
152 #endif
153 #else
154 #define HI_TRACE(level, module_id, fmt...)                                 \
155     do {                                                                   \
156         hi_log_out(level, module_id, (hi_u8 *)__FUNCTION__, __LINE__, fmt); \
157     } while (0)
158 #endif
159 #define HI_ASSERT(expr)                                                                                               \
160     do {                                                                                                              \
161         if (!(expr)) {                                                                                                \
162             HI_PANIC("\nASSERT failed at:\n  >File name: %s\n  >Function : %s\n  >Line No. : %d\n  >Condition: %s\n", \
163                 __FILE__, __FUNCTION__, __LINE__, #expr);                                                             \
164         }                                                                                                             \
165     } while (0)
166 
167 #define HI_ASSERT_RET(expr)                                    \
168     do {                                                       \
169         if (!(expr)) {                                         \
170             HI_PRINT("\n<%s %d>: ASSERT Failure{" #expr "}\n", \
171                 __FUNCTION__, __LINE__);                       \
172             return HI_FAILURE;                                 \
173         }                                                      \
174     } while (0)
175 
176 /* Supported for debug output to serial/network/u-disk. */
177 /* CNcomment: 各个模块需要调用以下宏进行输出调试信息、可输出到串口、网口、U盘存储等 */
178 /* Just only reserve the fatal level output. */
179 /* CNcomment: 仅仅保留致命的调试信息 */
180 #if (HI_LOG_LEVEL == HI_TRACE_LEVEL_FATAL)
181 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
182 #define HI_LOG_ERR(fmt...)
183 #define HI_LOG_WARN(fmt...)
184 #define HI_LOG_NOTICE(fmt...)
185 #define HI_LOG_INFO(fmt...)
186 #define HI_LOG_DBG(fmt...)
187 #define HI_LOG_VERBOSE(fmt...)
188 /* Just only reserve the fatal/error level output. */
189 /* CNcomment: 仅仅保留致命的和错误级别的调试信息 */
190 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_ERROR)
191 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
192 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
193 #define HI_LOG_WARN(fmt...)
194 #define HI_LOG_NOTICE(fmt...)
195 #define HI_LOG_INFO(fmt...)
196 #define HI_LOG_DBG(fmt...)
197 #define HI_LOG_VERBOSE(fmt...)
198 /* Just only reserve the fatal/error/warning level output. */
199 /* CNcomment: 仅仅保留致命的、错误的、警告级别的调试信息 */
200 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_WARN)
201 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
202 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
203 #define HI_LOG_WARN(fmt...)  HI_TRACE(HI_TRACE_LEVEL_WARN, LOG_D_MODULE_ID, fmt)
204 #define HI_LOG_NOTICE(fmt...)
205 #define HI_LOG_INFO(fmt...)
206 #define HI_LOG_DBG(fmt...)
207 #define HI_LOG_VERBOSE(fmt...)
208 /* Just only reserve the fatal/error/warning/note level output. */
209 /* CNcomment: 仅仅保留致命的、错误的、警告和注意级别的调试信息 */
210 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_NOTICE)
211 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
212 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
213 #define HI_LOG_WARN(fmt...)  HI_TRACE(HI_TRACE_LEVEL_WARN, LOG_D_MODULE_ID, fmt)
214 #define HI_LOG_NOTICE(fmt...)  HI_TRACE(HI_TRACE_LEVEL_NOTICE, LOG_D_MODULE_ID, fmt)
215 #define HI_LOG_INFO(fmt...)
216 #define HI_LOG_DBG(fmt...)
217 #define HI_LOG_VERBOSE(fmt...)
218 /* Just only reserve the fatal/error/warning/info level output. */
219 /* CNcomment: 仅仅保留致命的、错误的、警告和信息级别的调试信息 */
220 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_INFO)
221 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
222 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
223 #define HI_LOG_WARN(fmt...)  HI_TRACE(HI_TRACE_LEVEL_WARN, LOG_D_MODULE_ID, fmt)
224 #define HI_LOG_NOTICE(fmt...)  HI_TRACE(HI_TRACE_LEVEL_NOTICE, LOG_D_MODULE_ID, fmt)
225 #define HI_LOG_INFO(fmt...)   HI_TRACE(HI_TRACE_LEVEL_INFO, LOG_D_MODULE_ID, fmt)
226 #define HI_LOG_DBG(fmt...)
227 #define HI_LOG_VERBOSE(fmt...)
228 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_DBG)
229 /* Reserve all the levels output. */
230 /* CNcomment: 保留所有级别调试信息 */
231 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
232 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
233 #define HI_LOG_WARN(fmt...)  HI_TRACE(HI_TRACE_LEVEL_WARN, LOG_D_MODULE_ID, fmt)
234 #define HI_LOG_NOTICE(fmt...)  HI_TRACE(HI_TRACE_LEVEL_NOTICE, LOG_D_MODULE_ID, fmt)
235 #define HI_LOG_INFO(fmt...)   HI_TRACE(HI_TRACE_LEVEL_INFO, LOG_D_MODULE_ID, fmt)
236 #define HI_LOG_DBG(fmt...)    HI_TRACE(HI_TRACE_LEVEL_DBG, LOG_D_MODULE_ID, fmt)
237 #define HI_LOG_VERBOSE(fmt...)
238 #elif (HI_LOG_LEVEL == HI_TRACE_LEVEL_VERBOSE)
239 /* Reserve all the levels output. */
240 /* CNcomment: 保留所有级别调试信息 */
241 #define HI_LOG_FATAL(fmt...)  HI_TRACE(HI_TRACE_LEVEL_FATAL, LOG_D_MODULE_ID, fmt)
242 #define HI_LOG_ERR(fmt...)   HI_TRACE(HI_TRACE_LEVEL_ERROR, LOG_D_MODULE_ID, fmt)
243 #define HI_LOG_WARN(fmt...)  HI_TRACE(HI_TRACE_LEVEL_WARN, LOG_D_MODULE_ID, fmt)
244 #define HI_LOG_NOTICE(fmt...)  HI_TRACE(HI_TRACE_LEVEL_NOTICE, LOG_D_MODULE_ID, fmt)
245 #define HI_LOG_INFO(fmt...)   HI_TRACE(HI_TRACE_LEVEL_INFO, LOG_D_MODULE_ID, fmt)
246 #define HI_LOG_DBG(fmt...)    HI_TRACE(HI_TRACE_LEVEL_DBG, LOG_D_MODULE_ID, fmt)
247 #define HI_LOG_VERBOSE(fmt...) HI_TRACE(HI_TRACE_LEVEL_VERBOSE, LOG_D_MODULE_ID, fmt)
248 
249 #endif
250 
251 /* Only for debug, forbidden to modify and upload */
252 /* CNcomment: 仅供调试使用,禁止打开上传 */
253 #ifdef HI_KEY_PRINT_OUT
254 #define HI_KEY_PRINT(module_id, fmt...)
255 #define HI_KEY_PRINT_HEX(module_id, str, addr, len) \
256 #else
257 #define HI_KEY_PRINT(module_id, fmt...)
258 #define HI_KEY_PRINT_HEX(module_id, str, addr, len)
259 #endif
260 
261 #else
262 #define HI_LOG_FATAL(fmt...)
263 #define HI_LOG_ERR(fmt...)
264 #define HI_LOG_WARN(fmt...)
265 #define HI_LOG_NOTICE(fmt...)
266 #define HI_LOG_INFO(fmt...)
267 #define HI_LOG_DBG(fmt...)
268 #define HI_LOG_VERBOSE(fmt...)
269 
270 #define HI_KEY_PRINT(module_id, fmt...)
271 #define HI_KEY_PRINT_HEX(module_id, str, addr, len)
272 
273 #define HI_ASSERT(expr)
274 #define HI_ASSERT_RET(expr)
275 #endif /* endif HI_DEBUG */
276 
277 #define HI_CHECK_SEC_FUNC(ret)              \
278         do {                                                      \
279             errno_t err_ret = (ret);                       \
280             if (err_ret != EOK) {                          \
281                 HI_LOG_ERR("secure func call error\n"); \
282             }                                                        \
283         } while (0)
284 
285 /* @} */ /* <!-- ==== Structure Definition End ==== */
286 #define hi_notice_func_enter() HI_LOG_NOTICE(" ===>[Enter]\n")
287 #define hi_notice_func_exit()  HI_LOG_NOTICE(" <===[Exit]\n")
288 #define hi_notice_func_trace() HI_LOG_NOTICE(" =TRACE=\n")
289 
290 #define hi_info_func_enter() HI_LOG_INFO(" ===>[Enter]\n")
291 #define hi_info_func_exit()  HI_LOG_INFO(" <===[Exit]\n")
292 #define hi_info_func_trace() HI_LOG_INFO(" =TRACE=\n")
293 
294 #define hi_dbg_func_enter() HI_LOG_DBG(" ===>[Enter]\n")
295 #define hi_dbg_func_exit()  HI_LOG_DBG(" <===[Exit]\n")
296 #define hi_dbg_func_trace() HI_LOG_DBG(" =TRACE=\n")
297 
298 /* Function trace log for user input low frequency counts */
299 /* CNcomment: 用于输入降频打印的次数 */
300 #define hi_dbg_func_trace_low_freq_cnt(freq)                                    \
301     do {                                                                    \
302         static unsigned int freqtimes = 0;                                  \
303         if (0 == (freqtimes % (unsigned int)freq)) {                        \
304             HI_LOG_DBG(" =TRACE Freq=%d,freqtimes=%d=\n", freq, freqtimes); \
305         }                                                                   \
306         freqtimes++;                                                        \
307     } while (0)
308 
309 /* function trace log for user add extra print log as need */
310 /* CNcomment: 用户根据需求增加额外的打印 */
311 /* need use hi_func_trace_low_freq_cnt_end at the same time, to repesent the addtional prints is the end */
312 /* CNcomment: 需要同时使用hi_func_trace_low_freq_cnt_end,表明额外增加的打印截止 */
313 #define hi_func_trace_low_freq_cnt_begin(freq)            \
314     do {                                             \
315         static unsigned int freqtimes = 0;           \
316         if (0 == (freqtimes % (unsigned int)freq)) { \
317             do {                                     \
318         } while (0)
319 
320 #define hi_func_trace_low_freq_cnt_end() \
321     }                               \
322     freqtimes++;                    \
323     }                               \
324     while (0)
325 
326 /* Function trace log for user input low frequency time */
327 /* CNcomment: 用于输入降频打印的时间 */
328 #define hi_dbg_func_trace_low_freq_time(time)                                     \
329     do {                                                                      \
330         static hi_u32 last_time = 0;                                        \
331         hi_u32 curr_time;                                                   \
332         curr_time = log_get_time_ms();                                         \
333         if (time <= (curr_time - last_time)) {                            \
334             HI_LOG_DBG(" =TRACE freq=%d,freqtimes=%d=\n", time, curr_time); \
335             last_time = curr_time;                                        \
336         }                                                                     \
337     } while (0)
338 
339 /* function trace log for user add extra print log as need */
340 /* CNcomment: 用户根据需求增加额外的打印 */
341 /* need use hi_func_trace_low_freq_time_end at the same time, to repesent the addtional prints is the end */
342 /* CNcomment: 需要同时使用hi_func_trace_low_freq_time_end,表明额外增加的打印截止 */
343 #define hi_func_trace_low_freq_time_begin(time)         \
344     do {                                           \
345         static hi_u32 last_time = 0;             \
346         hi_u32 curr_time;                        \
347         curr_time = log_get_time_ms();              \
348         if (time <= (curr_time - last_time)) { \
349             do {                                   \
350         } while (0)
351 
352 #define hi_func_trace_low_freq_time_end() \
353     last_time = curr_time;       \
354     }                                \
355     }                                \
356     while (0)
357 
358 /* function trace log, strictly prohibited to expand */
359 #define hi_err_print_err_code(err_code) HI_LOG_ERR("Error Code: [0x%08X]\n", err_code)
360 
361 /* function trace log, print the called function name when function is error */
362 #define hi_err_print_call_fun_err(func, err_code) HI_LOG_ERR("Call %s Failed, Error Code: [0x%08X]\n", #func, err_code)
363 
364 /* Function trace log, print the pointer name when pointer is null */
365 #define hi_err_print_null_pointer(val) HI_LOG_ERR("%s = %p,  Null Pointer!\n", #val, val)
366 
367 /* used for displaying more detailed error information */
368 #define hi_err_print_s32(val)         HI_LOG_ERR("%s = %d\n", #val, val)
369 #define hi_err_print_u32(val)         HI_LOG_ERR("%s = %u\n", #val, val)
370 #define hi_err_print_s64(val)         HI_LOG_ERR("%s = %lld\n", #val, val)
371 #define hi_err_print_u64(val)         HI_LOG_ERR("%s = %llu\n", #val, val)
372 #define hi_err_print_h32(val)         HI_LOG_ERR("%s = 0x%08X\n", #val, val)
373 #define hi_err_print_h64(val)         HI_LOG_ERR("%s = 0x%016llX\n", #val, val)
374 #define hi_err_print_str(val)         HI_LOG_ERR("%s = %s\n", #val, val)
375 #define hi_err_print_void(val)        HI_LOG_ERR("%s = %p\n", #val, val)
376 #define hi_err_print_float(val)       HI_LOG_ERR("%s = %f\n", #val, val)
377 #define hi_err_print_info(val)        HI_LOG_ERR("<%s>\n", val)
378 #define hi_err_print_bool(val)        HI_LOG_ERR("%s = %s\n", #val, val ? "True" : "False")
379 #define hi_err_printstr(val, length) \
380     do {                                                                                          \
381         if (strlen(val) > length) {                                                               \
382             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
383         } else {                                                                                  \
384             hi_err_print_str(val);                                                                 \
385         }                                                                                         \
386     } while (0)
387 
388 /* used for displaying more detailed warning information */
389 #define hi_warn_print_s32(val)         HI_LOG_WARN("%s = %d\n", #val, val)
390 #define hi_warn_print_u32(val)         HI_LOG_WARN("%s = %u\n", #val, val)
391 #define hi_warn_print_s64(val)         HI_LOG_WARN("%s = %lld\n", #val, val)
392 #define hi_warn_print_u64(val)         HI_LOG_WARN("%s = %llu\n", #val, val)
393 #define hi_warn_print_h32(val)         HI_LOG_WARN("%s = 0x%08X\n", #val, val)
394 #define hi_warn_print_h64(val)         HI_LOG_WARN("%s = 0x%016llX\n", #val, val)
395 #define hi_warn_print_str(val)         HI_LOG_WARN("%s = %s\n", #val, val)
396 #define hi_warn_print_void(val)        HI_LOG_WARN("%s = %p\n", #val, val)
397 #define hi_warn_print_float(val)       HI_LOG_WARN("%s = %f\n", #val, val)
398 #define hi_warn_print_info(val)        HI_LOG_WARN("<%s>\n", val)
399 #define hi_warn_print_bool(val)        HI_LOG_WARN("%s = %s\n", #val, val ? "True" : "False")
400 #define hi_warn_printstr(val, length) \
401     do {                                                                                          \
402         if (strlen(val) > length) {                                                               \
403             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
404         } else {                                                                                  \
405             hi_warn_print_str(val);                                                                \
406         }                                                                                         \
407     } while (0)
408 
409 /* used for displaying normal but significant information */
410 #define hi_notice_print_s32(val)         HI_LOG_NOTICE("%s = %d\n", #val, val)
411 #define hi_notice_print_u32(val)         HI_LOG_NOTICE("%s = %u\n", #val, val)
412 #define hi_notice_print_s64(val)         HI_LOG_NOTICE("%s = %lld\n", #val, val)
413 #define hi_notice_print_u64(val)         HI_LOG_NOTICE("%s = %llu\n", #val, val)
414 #define hi_notice_print_h32(val)         HI_LOG_NOTICE("%s = 0x%08X\n", #val, val)
415 #define hi_notice_print_h64(val)         HI_LOG_NOTICE("%s = 0x%016llX\n", #val, val)
416 #define hi_notice_print_str(val)         HI_LOG_NOTICE("%s = %s\n", #val, val)
417 #define hi_notice_print_void(val)        HI_LOG_NOTICE("%s = %p\n", #val, val)
418 #define hi_notice_print_float(val)       HI_LOG_NOTICE("%s = %f\n", #val, val)
419 #define hi_notice_print_info(val)        HI_LOG_NOTICE("<%s>\n", val)
420 #define hi_notice_print_bool(val)        HI_LOG_NOTICE("%s = %s\n", #val, val ? "True" : "False")
421 #define hi_notice_printstr(val, length) \
422     do {                                                                                          \
423         if (strlen(val) > length) {                                                               \
424             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
425         } else {                                                                                  \
426             hi_notice_print_str(val);                                                              \
427         }                                                                                         \
428     } while (0)
429 
430 /* only used for key info, can be expanded as needed */
431 #define hi_info_print_s32(val)         HI_LOG_INFO("%s = %d\n", #val, val)
432 #define hi_info_print_u32(val)         HI_LOG_INFO("%s = %u\n", #val, val)
433 #define hi_info_print_s64(val)         HI_LOG_INFO("%s = %lld\n", #val, val)
434 #define hi_info_print_u64(val)         HI_LOG_INFO("%s = %llu\n", #val, val)
435 #define hi_info_print_h32(val)         HI_LOG_INFO("%s = 0x%08X\n", #val, val)
436 #define hi_info_print_h64(val)         HI_LOG_INFO("%s = 0x%016llX\n", #val, val)
437 #define hi_info_print_str(val)         HI_LOG_INFO("%s = %s\n", #val, val)
438 #define hi_info_print_void(val)        HI_LOG_INFO("%s = %p\n", #val, val)
439 #define hi_info_print_float(val)       HI_LOG_INFO("%s = %f\n", #val, val)
440 #define hi_info_print_info(val)        HI_LOG_INFO("<%s>\n", val)
441 #define hi_info_print_bool(val)        HI_LOG_INFO("%s = %s\n", #val, val ? "True" : "False")
442 #define hi_info_printstr(val, length) \
443     do {                                                                                          \
444         if (strlen(val) > length) {                                                               \
445             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
446         } else {                                                                                  \
447             hi_info_print_str(val);                                                                \
448         }                                                                                         \
449     } while (0)
450 
451 /** only used for self debug, can be expanded as needed */
452 #define hi_dbg_print_s32(val)         HI_LOG_DBG("%s = %d\n", #val, val)
453 #define hi_dbg_print_u32(val)         HI_LOG_DBG("%s = %u\n", #val, val)
454 #define hi_dbg_print_s64(val)         HI_LOG_DBG("%s = %lld\n", #val, val)
455 #define hi_dbg_print_u64(val)         HI_LOG_DBG("%s = %llu\n", #val, val)
456 #define hi_dbg_print_h32(val)         HI_LOG_DBG("%s = 0x%08X\n", #val, val)
457 #define hi_dbg_print_h64(val)         HI_LOG_DBG("%s = 0x%016llX\n", #val, val)
458 #define hi_dbg_print_str(val)         HI_LOG_DBG("%s = %s\n", #val, val)
459 #define hi_dbg_print_void(val)        HI_LOG_DBG("%s = %p\n", #val, val)
460 #define hi_dbg_print_float(val)       HI_LOG_DBG("%s = %f\n", #val, val)
461 #define hi_dbg_print_info(val)        HI_LOG_DBG("<%s>\n", val)
462 #define hi_dbg_print_bool(val)        HI_LOG_DBG("%s = %s\n", #val, val ? "True" : "False")
463 #define hi_dbg_printstr(val, length) \
464     do {                                                                                          \
465         if (strlen(val) > length) {                                                               \
466             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
467         } else {                                                                                  \
468             hi_dbg_print_str(val);                                                                 \
469         }                                                                                         \
470     } while (0)
471 
472 /** only used for self debug, can be expanded as needed */
473 #define hi_verbose_print_s32(val)         HI_LOG_VERBOSE("%s = %d\n", #val, val)
474 #define hi_verbose_print_u32(val)         HI_LOG_VERBOSE("%s = %u\n", #val, val)
475 #define hi_verbose_print_s64(val)         HI_LOG_VERBOSE("%s = %lld\n", #val, val)
476 #define hi_verbose_print_u64(val)         HI_LOG_VERBOSE("%s = %llu\n", #val, val)
477 #define hi_verbose_print_h32(val)         HI_LOG_VERBOSE("%s = 0x%08X\n", #val, val)
478 #define hi_verbose_print_h64(val)         HI_LOG_VERBOSE("%s = 0x%016llX\n", #val, val)
479 #define hi_verbose_print_str(val)         HI_LOG_VERBOSE("%s = %s\n", #val, val)
480 #define hi_verbose_print_void(val)        HI_LOG_VERBOSE("%s = %p\n", #val, val)
481 #define hi_verbose_print_float(val)       HI_LOG_VERBOSE("%s = %f\n", #val, val)
482 #define hi_verbose_print_info(val)        HI_LOG_VERBOSE("<%s>\n", val)
483 #define hi_verbose_print_bool(val)        HI_LOG_VERBOSE("%s = %s\n", #val, val ? "True" : "False")
484 #define hi_verbose_printstr(val, length) \
485     do {                                                                                          \
486         if (strlen(val) > length) {                                                               \
487             HI_LOG_ERR("The length of the string is greater than the size of the buff itself\n"); \
488         } else {                                                                                  \
489             hi_verbose_print_str(val);                                                             \
490         }                                                                                         \
491     } while (0)
492 
493 #define hi_log_print_block(pu8_datablock, length) \
494     do { \
495         hi_u32 u32ii = 0; \
496         hi_char aci_out_str[64] = {0}; \
497         hi_char *pci_buffer = (hi_char *)(pu8_datablock); \
498         errno_t _sec_errno; \
499         HI_PRINT(" %s\n", #pu8_datablock); \
500         for (u32ii = 0; u32ii < (length); u32ii++) { \
501             if ((u32ii % 16 == 0) && (u32ii != 0)) { \
502                 HI_PRINT("%s\n", aci_out_str); \
503                 _sec_errno = memset_s(aci_out_str, sizeof(aci_out_str), 0x00, sizeof(aci_out_str)); \
504                 if (_sec_errno != EOK) { \
505                     HI_LOG_ERR("hi_log_print_block memset_s failed!\n"); \
506                 } \
507             } \
508             _sec_errno = snprintf_s(&aci_out_str[(u32ii % 16) * 3], (64 - (u32ii % 16) * 3), \
509                                     4, " %02X", pci_buffer[u32ii]); \
510             if (_sec_errno < 0) { \
511                 HI_LOG_ERR("hi_log_print_block snprintf_s failed!\n"); \
512             } \
513         } \
514         if ((u32ii % 16 != 0) && (u32ii != 0)) { \
515             HI_PRINT("%s\n", aci_out_str); \
516             _sec_errno = memset_s(aci_out_str, sizeof(aci_out_str), 0x00, sizeof(aci_out_str)); \
517             if (_sec_errno != EOK) { \
518                 HI_LOG_ERR("hi_log_print_block memset_s failed!\n"); \
519             } \
520         } \
521     } while (0)
522 
523 #define MKSTR(exp)        # exp
524 #define MKMARCOTOSTR(exp) MKSTR(exp)
525 #define VERSION_STRING    ("SDK_VERSION:[" MKMARCOTOSTR(SDK_VERSION) "] Build Time:[" __DATE__ ", " __TIME__ "]")
526 
527 #ifdef __cplusplus
528 #if __cplusplus
529 }
530 #endif
531 #endif /* __cplusplus */
532 
533 #endif /* __HI_LOG_H__ */
534 
535