/* * * Copyright (c) 2012-2021 Shenshu Technologies Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #ifndef __DBG_H__ #define __DBG_H__ #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* __cplusplus */ #if defined(DEBUG) #define dbg_assert(expression) assert(expression) #else #define dbg_assert(expression) ((void)0) #endif #define LOG_LEVEL_NORMAL 0 #define LOG_LEVEL_FATAL 1 #define LOG_LEVEL_ERROR 2 #define LOG_LEVEL_WARN 3 #define LOG_LEVEL_INFO 4 #define LOG_LEVEL_DEBUG 5 #define LOG_LEVEL_DEBUG1 6 #define LOG_LEVEL_DEBUG2 7 #define LOG_LEVEL_ALL 10 #define LOG_LEVEL_NONE 0 #define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO #define LOG_LEVEL_MINI LOG_LEVEL_ERROR #define LOG_LEVEL_MAX LOG_LEVEL_ALL /*g_log_queue is a Global Var, now defined at message.c and declare at dbg.h, it you use this log functions outside, you can declare your owner "g_log_queue"*/ #ifdef LOGQUEUE #define log_create(level, msglen) bsp_log_create(&g_log_queue, level, msglen) #define log_setlevel(level) (g_log_queue.uc_min_level = level) #define log_getlevel() (g_log_queue.uc_min_level) #define log_destroy() bsp_log_destroy(&g_log_queue) #define mk_str(exp) # exp #define mk_marco_to_str(exp) mk_str(exp) #define LINENUMBER mk_marco_to_str(__LINE__) #define ATTACHINFO "{"__FILE__ ":" LINENUMBER "}" #define write_log_normal(args...) \ log_msg(&g_log_queue, LOG_LEVEL_NORMAL, args) #define write_log_info(args...) \ log_msg(&g_log_queue, LOG_LEVEL_INFO, args) #define write_log_fatal(args...) \ log_msg(&g_log_queue, LOG_LEVEL_FATAL, args) #define write_log_error(args...) \ log_msg(&g_log_queue, LOG_LEVEL_ERROR, args) #define write_log_warn(args...) \ log_msg(&g_log_queue, LOG_LEVEL_WARN, args) #define write_log_debug(args...) \ log_msg(&g_log_queue, LOG_LEVEL_DEBUG, ATTACHINFO args) #define write_log_debug1(args...) \ log_msg(&g_log_queue, LOG_LEVEL_DEBUG1, ATTACHINFO args) #define write_log_debug2(args...) \ log_msg(&g_log_queue, LOG_LEVEL_DEBUG2, ATTACHINFO args) #define write_log(i_level, args...) \ log_msg(&g_log_queue, i_level, args) #else #define log_create(level, msglen) #define log_setlevel(level) #define log_getlevel() (0) #define log_destroy() #define write_log_normal(args...) #define write_log_info(args...) #define write_log_fatal(args...) #define write_log_error(args...) #define write_log_warn(args...) #define write_log_debug(args...) #define write_log_debug1(args...) #define write_log_debug2(args...) #define write_log(args...) #endif void hexdump(FILE *stream, const void *src, size_t len, size_t width); void hexdump2(FILE *stream, const void *src, size_t len, size_t width); #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */ #endif /* __DBG_H__ */