簡體   English   中英

如何更改 linux 串口的系統緩沖區大小?

[英]How to change the size of the system buffer in linux for uart?

請告訴我,我正在橙色 pizero 單板計算機上基於 arabian linux 制作一個 uart 記錄器,結果如下代碼,但我無法解決問題。 如果我傳輸大文本文件,我會丟失信息,文本中幾百個字節的順序會消失。 我的假設與系統緩沖區溢出有關,但我無法弄清楚如何使用 ioctl() 系統調用來增加它。 傳輸速率為 921600。

我的代碼-

struct termios2 SerialPortSettings;

ioctl(fd_uart,TCGETS2,&SerialPortSettings); 

SerialPortSettings.c_cflag &= ~CBAUD;    //Remove current baud rate
SerialPortSettings.c_cflag |= BOTHER;    //Allow custom baud rate using int input
SerialPortSettings.c_ispeed = 921600;    //Set the input baud rate
SerialPortSettings.c_ospeed = 921600;    //Set the output baud rate
//tcgetattr(fd_uart, &SerialPortSettings); /* Get the current attributes of the Serial port */
/* Setting the Baud rate */
// cfsetispeed(&SerialPortSettings,921600); /* Set Read  Speed as 921600                       */
// cfsetospeed(&SerialPortSettings,921600); /* Set Write Speed as 921600                       

/* 8N1 Mode */
SerialPortSettings.c_cflag &= ~PARENB;    //Disables the Parity Enable bit(PARENB),So No Parity   
SerialPortSettings.c_cflag &= ~CSTOPB;   /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE;    /* Clears the mask for setting the data size             */
SerialPortSettings.c_cflag |=  CS8;      /* Set the data bits = 8                                 */


SerialPortSettings.c_cflag &= ~CRTSCTS;       /* No Hardware flow Control                         */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines       */ 

SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY);          /* Disable XON/XOFF flow control both i/p and o/p */
SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ISIG | ECHOE| IGNCR);  /* Non Cannonical mode                            */

//SerialPortSettings.c_lflag = 0;
SerialPortSettings.c_oflag &= ~OPOST;/*No Output Processing*/

// ioctl(fd_uart, TIOCINQ, 8000);

// ioctl(fd_uart, TIOCOUTQ, 8000);

// serial_struct serinfo;
// memset(&serinfo, 0, sizeof(serinfo));
// ioctl(device_handler, TIOCGSERIAL, &serinfo);
// serinfo.xmit_fifo_size;

// /* Setting Time outs */
SerialPortSettings.c_cc[VMIN] =  0;
SerialPortSettings.c_cc[VTIME] = 0;


// serial_struct serinfo;
// memset(&serinfo, 0, sizeof(serinfo));
// ioctl(device_handler, TIOCGSERIAL, &serinfo);
// serinfo.xmit_fifo_size;

tcflush(fd_uart, TCIOFLUSH);   /* Discards old data in the rx buffer*/

//tcsetattr(fd_uart, TCSANOW, &SerialPortSettings);
if((ioctl(fd_uart, TCSETS2, &SerialPortSettings)) != 0) /* Set the attributes to the termios structure*/
    printf("\n  ERROR ! in Setting attributes\n");
else{
    printf("  BaudRate = 921600 \n  StopBits = 1 \n  Parity   = none \n");
}

非規范模式

在非規范模式下,緩沖區固定為 4096 個字符。 這是在文檔之后,請參閱man termioshttps://elixir.bootlin.com/linux/latest/source/drivers/tty/n_tty.c#L1583 kernel 設置就像這里的https://elixir.bootlin.com/linux/latest/source/include/linux/tty.h#L247

如何更改 linux 串口的系統緩沖區大小?

用更大的緩沖區值重新編譯 kernel。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM