0

我正在尝试使用 FIFO 寄存器创建一个 UART_read 函数,但我无法理解它是如何工作的。我知道它允许我每次读取获得更多字符,因此这意味着读取将中断处理器的次数更少,但是在启用它之后我该如何使用它呢?我在任何地方都找不到例子。我目前的功能是:

unsigned char UART_read(void){
 unsigned int buf;
 while( ( ( inb(UART_LSR + UART) ) & UART_LSR_DR ) == 0 ){
         schedule();
 }
 buf = inb(UART);
 return (char)buf;
}
4

2 回答 2

2

I can direct you to two sources of information; the UART data sheets and Linux serial driver (drivers/tty/serial/8250/ directory within the Linux kernel source tree, and within that primarily the 8250.c source file).

One such UART data sheet is provided by Texas Instruments at http://www.ti.com/lit/gpn/ns16c552

In Chapter 9 it has, in my opinion, a pretty good description of the FIFO mode operation. Basically, there are two types of interrupts for received data; one for when the amount of unread data in the receive fifo has reached a set threshold level (typically should be less than the FIFO size, to allow the OS some time to read the received characters before more data arrives), and another for the case when there's some data, but not enough to raise the "buffer full" alert sitting in the FIFO for some time. This latter is to let the OS pick up received single characters in a reasonable time.

When the OS receives these interrupts, it then typically should read as many characters from the FIFO as it can (using a status register bit to indicate whether there still is more data to read).

Similarly, when transmitting, the OS can write to the transmit FIFO until it receives an indication that the FIFO is full. The UART will later on generate an interrupt to tell that the transmit FIFO has some amount of room (again configurable) available.

Note though, that if you're writing your code as userspace code in Linux (i.e. as a regular application), you can't receive interrupts. On the other hand, if you're writing a driver of your own, you have to make sure it's your driver that claims the UART you're interacting with, instead of the default 8250.c UART driver.

于 2013-05-12T18:50:37.163 回答
0

这取决于您的注册手册,

通常,一个 FIFO 寄存器是 32 位长,但只有一些低位可用或有意义。

因此,您可以通过设置 32 位长 FIFO 中有多少位可用或有意义来获得更多字符。应该有一些地方可以设置它。

于 2013-05-12T15:41:09.773 回答