This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

串口接收底层接口原型



如题,在追踪串口中断接收字符接口UART_getc()    到底层,其调用的是 typedef int32_t     (*UART_ReadPollingFxn)    (UART_Handle handle, void *buffer, size_t size);函数指针,但是该原型我并没有检索到,这个函数的具体实现,想要看下,是否在函数内部会将从串口接收的0x0D字符自动转换为0x0A,从而导致上层接收到的字符被意外改变?   如果该函数接口内部并没有进行该操作,那么请问,在初始化该UART Console中,哪项参数可能会造成此现象发生!?

  • 我在C:\ti\AM335x SDK 5.03\pdk_am335x_1_0_14\packages\ti\drv\pm\examples\utils\uartStdio.c找到UARTGetc函数,有ascii码转换后输出,您可以查看一下源代码。
  • Hi Shine:
             我按照你的提示又重新找了遍,发现你说的这个接口是在uartStdio,c中有实现:如下

    uint8_t UARTGetc(void)
    {
        return (UARTCharGet(gUartBaseAddr));
    }

    static int8_t UARTCharGet(uint32_t baseAdd)
    {
        uint32_t lcrRegValue = 0;
        int8_t   retVal      = 0;
        /* Switching to Register Operational Mode of operation. */
        lcrRegValue = UARTRegConfigModeEnable(baseAdd, UART_REG_OPERATIONAL_MODE);
        /* Waits indefinitely until a byte arrives in the RX FIFO(or RHR). */
        while ((uint32_t) UART_LSR_RX_FIFO_E_RX_FIFO_E_VALUE_0 ==
               (HW_RD_REG32(baseAdd + UART_LSR) &
                UART_LSR_RX_FIFO_E_MASK))
        {
            /* Do nothing - Busy wait */
        }
        retVal = (int8_t) HW_RD_REG32(baseAdd + UART_RHR);
        /* Restoring the value of LCR. */
        HW_WR_REG32(baseAdd + UART_LCR, lcrRegValue);
        return retVal;
    }
    发现在该函数中并没有涉及对接收到的字符的处理,我之所以确定是接收到的字符被改变是通过单步调试,在确定发送端发出字符为0x0D不被发送端改变(这里我使用俩个串口设备互相检测)的前提下,通过我所提到的调用接口UART_getc内部单步调试查看接收到的字符确实变为0x0A.