增加调试打印输出

This commit is contained in:
2026-07-19 01:18:33 +08:00
parent f72d08328f
commit 1669cd216d
8 changed files with 196 additions and 87 deletions

84
Drivers/BSP/dbg_log.h Normal file
View File

@@ -0,0 +1,84 @@
/*
* 模块名称Unified Debug Logging
* 模块功能:提供统一的调试输出宏,支持 DEBUG / INFO / ERROR 三级日志控制
* 参考 FlashDB FDB_DEBUG/FDB_INFO 设计模式
* 使用方法:
* 1. 在 dbg_cfg.h 中定义 DBG_ENABLE总开关和 DBG_DEBUG_ENABLEDEBUG 级别)
* 2. 每个 .c 文件在包含本文件前定义 DBG_TAG
* #define DBG_TAG "[CH395]"
* #include "dbg_log.h"
* 适用平台:所有 BSP 驱动
*/
#ifndef __DBG_LOG_H
#define __DBG_LOG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "dbg_cfg.h"
/*
* 总开关DBG_ENABLE
* 定义 → 输出 DBG_ERROR / DBG_INFO若 DBG_DEBUG_ENABLE 也定义则输出 DBG_DEBUG
* 不定义 → 所有输出宏为空操作release 版本)
* 在 net_config.h 或编译器预定义中控制
*/
#ifdef DBG_ENABLE
/*
* 可重定向的打印函数,用户可在编译选项或 net_config.h 中预定义
* #define DBG_PRINT(...) my_printf(__VA_ARGS__)
*/
#ifndef DBG_PRINT
#define DBG_PRINT(...) printf(__VA_ARGS__)
#endif
/*
* 模块标签默认值,每个 .c 文件应在包含本文件前定义 DBG_TAG
* #define DBG_TAG "[CH395]"
*/
#ifndef DBG_TAG
#define DBG_TAG ""
#endif
/*
* DBG_ERROR - 错误输出,受 DBG_ENABLE 控制
*/
#define DBG_ERROR(fmt, ...) do { \
DBG_PRINT("[ERR]" DBG_TAG " " fmt "\r\n", ##__VA_ARGS__); \
} while(0)
/*
* DBG_INFO - 信息输出,受 DBG_ENABLE 控制
*/
#define DBG_INFO(fmt, ...) do { \
DBG_PRINT(DBG_TAG " " fmt "\r\n", ##__VA_ARGS__); \
} while(0)
/*
* DBG_DEBUG - 调试输出,需 DBG_ENABLE + DBG_DEBUG_ENABLE 同时定义
*/
#ifdef DBG_DEBUG_ENABLE
#define DBG_DEBUG(fmt, ...) do { \
DBG_PRINT(DBG_TAG "(%s:%d) " fmt "\r\n", __func__, __LINE__, ##__VA_ARGS__); \
} while(0)
#else
#define DBG_DEBUG(fmt, ...)
#endif
#else /* DBG_ENABLE not defined — all debug output disabled */
#define DBG_ERROR(fmt, ...)
#define DBG_INFO(fmt, ...)
#define DBG_DEBUG(fmt, ...)
#endif /* DBG_ENABLE */
#ifdef __cplusplus
}
#endif
#endif /* __DBG_LOG_H */