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

#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(
);
    WriteCharToUART(
);
}
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头里面的函数,在网上已经传栏了,我也不过多阐述了!其实,在网上我看到别人写的类如此的函数可以贴出来。


这样就是自己写的printf函数!
经验分享 程序员 微信小程序 职场和发展