FUART & UART TRAFFIC CONTROL USAGE


1. Fuart Traffic Control Process


1.1. HW Connection


1.2. Parameters Description

  • RTS

    Require To Send. The send request is an output signal used to indicate that the device is ready to receive data. Active low, indicating that the device can receive data.

  • CTS

    Clear To Send. Allows to send input signals, used to determine whether data can be sent to the other side. Active low, indicating that the device can send data to the other side.


1.3. Traffic Control Method

If our side processes the data stream (receives data from the other side), set RTS to low; if the CTS pin of the other side device is low level, data can be sent.

If our side does not process the data stream (does not receive data from the other side), set RTS to high; if the CTS pin of the other side device is high, stop sending data and wait for the pin of CTS to change.


1.4. FUART Test Method

1.4.1. Kernel Verify RTS CTS Process

  • modify infinity6e.dtsi

  • modify infinity6e-padmux.dtsi add

1.4.2. Build Kernel

Burn the kernel to flash

Reboot

Enter the shell (Please verify whether the four pids of the group can be individually controlled to pull high/low)

  1. / #    ls /dev/ttyS2

  2. / #    stty -F /dev/ttyS2 ispeed 115200 ospeed 115200 cs8

  3. / #    cd mnt/

  4. /mnt #   ./enable_rtscts (APP, used to enable traffic control, please copy Code and compile by yourself)

  5. / #     /customer/riu_r 103c 6e (Check if it is set to mode1)

    BANK:0x103C 16bit-offset 0x6E

    0x0010

  6. / #    /customer/riu_r 1102 8(查看rts cts enable)

    BANK:0x1102 16bit-offset 0x08

    0x0022

  7. enable RTS CTS, use LA to check PAD_FUART_CTS and PAD_FUART_RTS

    PAD_FUART_CTS = 1

    PAD_FUART_RTS = 0(正确值)

  8. connect PAD_FUART_RX and PAD_FUART_TX to PC

    / #  echo aaaaaaaa > /dev/ttyS2

    At this time, the serial port tool on the PC did not receive any data.

    Ground PAD_FUART_CTS, the PC serial port tool log is as follows:

    CTS verified successfully.

  9. / #     cat dev/ttyS2 &

  10. / #     /customer/riu_r 1102 2

    BANK:0x1102 16bit-offset 0x02

    0x0005

  11. / #    /customer/riu_w 1102 2 0 (disabled fuart and interrupted reception, the data received by tx will not be read, after fifo full, RTS will be set to 1)

    BANK:0x1102 16bit-offset 0x02

    0x0000

  12. Use serial port tool to send 30byte data to fuart

  13. use LA to check PAD_FUART_RTS

    PAD_FUART_RTS = 1(Correct value)

  14. / #      /customer/riu_w 1102 2 5(enable fuart and interrupted reception, after the data of fifo is read, RTS is set to 0)

    BANK:0x1102 16bit-offset 0x02

    0x0005

  15. use LA to check PAD_FUART_RTS

    PAD_FUART_RTS = 0(Correct value)

    The PC serial port tool log is as follows:

    RTS verified successfully.

1.4.3. Code

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
int enable_rtscts(int fd)
{
    struct termios options;
    if ( tcgetattr( fd,&options) != 0)
    {
        perror("SetupSerial 1");
        return -1;
    }
    options.c_cflag |= CRTSCTS;
    tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
    if (tcsetattr(fd,TCSANOW,&options) != 0)
    {
        perror("SetupSerial 3");
        return -1;
    }
    return 0;
}

int main(int argc, char **argv)
{
    int fd;
    fd = open("/dev/ttyS2",O_RDWR|O_NOCTTY|O_NDELAY);
    if (fd <= 0){
        printf("Can't Open Serial Port!\n");
        return -1;
        }
    if(enable_rtscts(fd)== -1)
    {
        printf("Set Parity Error\n");
        exit(1);
    }
    printf("enable rts cts\n");
    close(fd);
    return 0;
}

1.5. Note

  1. Confirm that the pin is configured with Fuart

  2. kernel\arch\arm\boot\dts\infinity2m-ssc011a-s01a-padmux-display.dtsi :

    <PAD_FUART_RX PINMUX_FOR_FUART_MODE_1 MDRV_PUSE_FUART_RX>,  
    <PAD_FUART_TX PINMUX_FOR_FUART_MODE_1 MDRV_PUSE_FUART_TX>,  
    <PAD_FUART_CTS PINMUX_FOR_FUART_MODE_1 MDRV_PUSE_FUART_CTS>,  
    <PAD_FUART_RTS PINMUX_FOR_FUART_MODE_1 MDRV_PUSE_FUART_RTS>,
    
  3. kernel\arch\arm\boot\dts\infinity2m-ssc011a-s01a-padmux-display.dtsi :

    fuart: uart2@1F220400 {
        compatible = "sstar,uart";
        reg = <0x1F220400 0x100>, <0x1F220600 0x100>;
        interrupts = <GIC_SPI INT_IRQ_FUART IRQ_TYPE_LEVEL_HIGH>, <GIC_SPI INT_IRQ_URDMA IRQ_TYPE_LEVEL_HIGH>;
        clocks = <&CLK_fuart>;
        dma = <0>;
        sctp_enable = <1>;//rts cts enable is 1
        //pad = <PAD_FUART_RX>;//fuart mode2
        pad = <PAD_FUART_CTS>;//fuart mode 1
        tolerance = <2>;
        status = "ok";
    };
    
  4. Confirm that the software has enabled cts/rts, if not, the default value is high.

  5. If you want to ensure that ssd20x is in an acceptable state, use the command: cat /dev/ttyS2 &. If the ttyS2 device is not always turned on, the interrupt status of Fuart will be automatically cleared. Obtain register[101e 2]==0x0000; the normal value is 0x0005.


2. Connect To RS Chip, Half-duplex Communication

  1. connection method

    RS485 is the master-salver mode, mater is the initiator, and salmon is the responder. There is only one device in the network sending data, and the others are in the monitoring state.

    The main process is as follows, all actions need to wait for the master to notify.

    When Host/Master sends data to RS485, first pull R/D high, after sending, pull R/D low, Host/Master enters the monitoring state and waits for slaver's response.

    To avoid delay, the pin that controls the slave's sending and receiving needs to be placed in the uart driver. Click to check the solution.

  2. How to use APP layer

    struct serial_rs485 rs485conf;
    
    memset(&rs485conf,0,sizeof(rs485conf));
    
    rs485conf.padding[0] = 17;   //Control the gpio index sent and received by slaver
    rs485conf.delay_rts_after_send = 2000;  // The delay time required to send the last byte, unit: us
    rs485conf.flags |= SER_RS485_RTS_ON_SEND; //Pull up gpio before sending, and open SER_RS485_RTS_AFTER_SEND means pulling up after sending
    rs485conf.flags |= SER_RS485_ENABLED; // Enable the 485 mode of this serial port, disabled by default
    ioctl(iHandle, TIOCSRS485, &rs485conf);