您的位置:首页 > 其它

展讯平台如何调试之打LOG--串口log

2012-04-04 18:27 387 查看
接上一篇,因为当时项目急,可以用了也没去研究,现在省出来点玩DOTA的时间记录一下,就说那个串口输出函数吧,各种宏,他感觉那样好,其实更不好理解,我们可以尝试把宏替代进去就形成了这么一个函数。

#define   TF_STACK_LIMIT		    0x10000
#define   SIO_TX_EMPTY(s)    	    ((s) & 0xFF00)
#define   WAIT_FIFO_EMPTY        \
{                                      \
while( SIO_TX_EMPTY(*(volatile uint32*)(0x8400000c)));\
}
LOCAL void WriteCharToUART(char c)
{
while ((((*(volatile uint32*)0x8400000c) >> 8 )&0xFF) >= 32 ) {};

*(volatile uint32*)0x84000000 = c;
}
LOCAL void TF_SendMsgOut(char * buf, int size)
{
while (size --)
{
WriteCharToUART(*(buf++));
}

WriteCharToUART('\r');
WriteCharToUART('\n');
}
PUBLIC void TF_UartTrace(
const char *x_format, ...)
{
char       format_str[256];
va_list    args;
int        nBuf;

WAIT_FIFO_EMPTY

memset (format_str,0,256);

va_start(args, x_format);\
nBuf = vsprintf(format_str, x_format, args);\
/* was there an error? */\
/* Was the expanded string too long? */\
va_end(args);\
/* Send message to serial buffer! */ \
TF_SendMsgOut(format_str, nBuf + 1);

WAIT_FIFO_EMPTY
}


嗯,这样就舒坦多了。其实这样就是标C里面的printf函数,其关键无非就是va_list、va_start、va_end!

关于这组被包含在stdarg.h头里面的函数,在网上已经传栏了,我也不过多阐述了!其实,在网上我看到别人写的类如此的函数可以贴出来。

http://www.cnblogs.com/rainduck/archive/2010/11/10/1873417.html

这样就是自己写的printf函数!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: