BeagleBone Black UART 软件 FIFO 大小?

BeagleBone Black UART software FIFO size?

我正在 BeagleBone Black 上开发自定义应用程序,它必须通过在 BBB 上运行的 Debian Linux 使用设备的 UART 功能,以读取大块数据。为了从 UART 读取,我打开了 /dev/ttyO0、/dev/ttyO1 等设备之一 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);

我想知道参数count的最大合理数是多少,它与UART的FIFO缓冲区有什么关系?

在AM335x技术参考手册(TI文档spruh73p,第4328页,第19.3.6节)中我可以看到HW缓冲区是64字节长。但是,正如我怀疑的那样,通过使用 read() 函数,我的程序没有直接与硬件 fifo 缓冲区通信,而是从 Linux' 串行驱动程序的软件缓冲区(如果有的话)中读取。这是真的?如果是,软件 fifo 的大小是多少?有人可以为我开导这个领域吗?

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

而不是"port",你实际上是从硬件设备上去掉几层,从串口终端的系统缓冲区读取。

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?

首先 count 不能大于提供的用户缓冲区。
对于阻塞 read(),您可以使此 count 与您可以分配的任何缓冲区一样大。
对于非阻塞 read(),比终端接收缓冲区大的 count 毫无意义。
请注意,count 只是一个请求,read() 系统调用可以 return 少于请求的字节数。

UART FIFO 和串行端口驱动程序缓冲区的大小与来自用户空间的任何 read() 请求无关。
参见 Linux serial drivers

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

差不多。
来自用户空间的 read() 系统调用从终端缓冲区获取数据。
终端驱动是比串口驱动更高级的驱动。

终端缓冲区与 UART FIFO 没有直接连接。
如果使用 DMA,则数据从 UART FIFO 传输到 DMA 缓冲区。
如果使用 PIO,则数据从 UART FIFO 传输到驱动程序缓冲区。
在任何一种情况下,串行端口驱动程序最终都会将数据传输到 tty 翻转缓冲区。
在非中断模式下,数据从 tty 翻转缓冲区传输到 terminal/line-discipline 缓冲区。
再次参考Linux serial drivers

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

终端接收缓冲区通常为 4096 字节,但您可以编写自己的具有不同大小的行规程,或重新定义宏。
来自 Linux 内核源代码中的 include/linux/tty.h

#define N_TTY_BUF_SIZE 4096

Linux 支持的所有体系结构都通用终端驱动程序,因此您的 BBB 应具有 4096 字节的终端缓冲区。