安信可(云知声蜂鸟US516P6)SDK开发学习---printf打印函数底层putchar

安信可(云知声蜂鸟US516P6)SDK学习

__attribute__((used))
int putchar(int c)
{
    
    
    if(IsSwUartActedAsUARTFlag)
    {
    
    
        if((unsigned char)c == '\n')
        {
    
    
            const char lfca[2] = "\r\n";
            SwUartSend((unsigned char*)lfca, 2);
        }
        else
        {
    
    
            SwUartSend((unsigned char*)&c, 1);
        }
    }
    else
    {
    
    
    	if (c == '\n')
    	{
    
    
    		UARTS_SendByte(DebugPrintPort, '\r');
    		UARTS_SendByte(DebugPrintPort, '\n');
    	}
    	else
    	{
    
    
    		UARTS_SendByte(DebugPrintPort, (uint8_t)c);
    	}
    }

	return c;
}

EnableSwUartAsUART 函数定义如下

uint8_t IsSwUartActedAsUARTFlag = 0;
void EnableSwUartAsUART(uint8_t EnableFlag)
{
    
    
	IsSwUartActedAsUARTFlag = EnableFlag;
}

//This is used as dummy function in case that appilcation dont define this function.
__attribute__((weak))
void SwUartSend(unsigned char* Buf, unsigned int BufLen)
{
    
    

}

猜你喜欢

转载自blog.csdn.net/xushx_bigbear/article/details/130874518
今日推荐