BeagleBone Black UART software FIFO size?

守給你的承諾、 提交于 2020-02-04 07:01:59

问题


I'm developing a custom application on the BeagleBone Black that has to use the UART capabilities of the device via the Debian Linux that runs on the BBB, for reading big chunks of data. For reading from the UART I'm opening one of the /dev/ttyO0, /dev/ttyO1, etc. devices with the open() function in nonblocking mode. And then I'm trying to read from this port with the read(2) function:

ssize_t read(int fd, void *buf, size_t count);

I would like to know what is the biggest reasonable number for the parameter count and how is it related to the UART's FIFO buffer?

In the AM335x technical reference manual (TI document spruh73p, page 4328, section 19.3.6) I can see that the HW buffer is 64 bytes long. But, as I suspect by using the read() function my program is not communicating directly with the hardware fifo buffer but it is reading from Linux' serial driver's software buffer (if there is such). Is this true? If yes, what is the size of the software fifo? Could somebody please enlighten this field for me?


回答1:


And then I'm trying to read from this port with the read(2) function

Rather than the "port", you are actually several layers removed from the hardware device, and reading from the system buffer of the serial terminal.

I would like to know what is the biggest reasonable number for the parameter count and how is it related to the UART's FIFO buffer?

First of all the count must be no larger than the user buffer provided.
For a blocking read(), you could probably make this count as large as any buffer you could allocate.
For a nonblocking read(), a count larger than the terminal receive buffer makes little sense.
Note that count is merely a request, and the read() syscall can return with less than the requested number of bytes.

The sizes of the UART FIFO and serial port driver buffers are irrelevant to any read() requests from userspace.
See Linux serial drivers.

... it is reading from Linux' serial driver's software buffer (if there is such). Is this true?

Almost.
The read() syscall from userspace fetches data from the terminal buffer.
The terminal driver is a higher-level driver than the serial port driver.

The terminal buffer has no direct connection to the UART FIFO.
If DMA is employed, then data is transferred from the UART FIFO to a DMA buffer.
If PIO is employed, then data is transferred from the UART FIFO to a driver buffer.
In either case the serial port driver eventually transfers the data to a tty flip buffer.
In non-interrupt mode, data from the tty flip buffer is transferred to the terminal/line-discipline buffer.
Again refer to Linux serial drivers.

If yes, what is the size of the software fifo?

The terminal receive buffer is typically 4096 bytes, although you could write your own line discipline with a different size, or redefine the macro.
From include/linux/tty.h in Linux kernel source:

#define N_TTY_BUF_SIZE 4096

The terminal driver is common to all architectures supported by Linux, so your BBB should have a terminal buffer of 4096 bytes.



来源:https://stackoverflow.com/questions/58650544/beaglebone-black-uart-software-fifo-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!