关于移植过程中,存在大量LCD log(不定形参...)等调试属性函数宏定义到printf

来源:互联网 发布:入骨相思知不知小说 编辑:程序博客网 时间:2024/05/22 06:54

嵌入式开发过程中,遇到移植第三方协议栈,有时存在大量LCD log等调试属性函数。我们希望保存原生的调试输出信息,通过对LCDlog等调试功能进行printf重新宏定义。

在第三方程序存在大量的调试属性函数,如: 

#define  LCD_UsrLog(format, ...)    
  #define  LCD_ErrLog(format, ...)    

在没有相应的LCD硬件支持,但我们希望保存这些调试输出信息,而不是重新去编写调试信息。


此时,我们可以重新宏定义到printf(format, ...),调试输出信息打印到串口调试软件。

宏定义如下:(##:但应用过程中不存在不定形参...时,消除“,”的错误)

  #define  LCD_UsrLog(format, ...)    printf(format, ##__VA_ARGS__)
  #define  LCD_ErrLog(format, ...)    printf("ERROR: "); printf(format, ##__VA_ARGS__)

实现调试信息打印到串口调试软件上。


附:

MDK hlep文档:

#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)void Variadic_Macros_0(){     debug ("a test string is printed out along with %x %x %x\n", 12, 14, 20);}
IAR help文档:

#define MYSEG "YYY"
#define X(str) __no_alloc_str(str @ MYSEG)
extern void dbg_printf(unsigned long fmt, ...);
#define DBGPRINTF(fmt, ...) dbg_printf(X(fmt), __VA_ARGS__)
void 
foo(int i, double d)
{
 
 
DBGPRINTF("The value of i is: %d, the value of d is: %f", i,d);
}

0 0
原创粉丝点击