linux内核代码uart设置fifo
时间: 2023-08-06 17:10:14 浏览: 284
在 Linux 内核中,串口通信的 FIFO 模式可以通过设置串口的 `flags` 字段实现。具体地,以下是设置 FIFO 模式的步骤:
1. 在串口设备的数据结构中,定义一个 `flags` 字段,用于保存串口的属性标志。
```c
struct uart_port {
/* ... */
unsigned int flags;
/* ... */
};
```
2. 在 `uart_add_one_port()` 函数中,初始化串口的 `flags` 字段。设置 `UART_FIFOS_ENABLE` 标志表示需要启用 FIFO 模式。
```c
static int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
{
/* ... */
port->flags = UPF_BOOT_AUTOCONF;
port->type = drv->type;
port->iotype = drv->iotype;
port->fifosize = drv->fifosize;
port->line = i;
port->ops = &drv->ops;
/* Enable FIFO mode */
if (drv->flags & UART_DRIVER_FICTION) {
port->flags |= UART_FIFOS_ENABLE;
}
/* ... */
}
```
3. 在串口的驱动程序实现中,根据 `flags` 中是否启用了 FIFO 模式,来进行相应的操作。以下是一个示例代码:
```c
static void my_uart_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old)
{
/* ... */
/* Check if FIFO mode is enabled */
if (port->flags & UART_FIFOS_ENABLE) {
/* Set the FIFO trigger level to 1/8 */
writel(UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_8,
port->membase + UART_FCR);
}
/* ... */
}
```
在上述代码中,我们首先检查了 `flags` 字段中是否启用了 FIFO 模式。如果是,我们就将 FIFO 触发级别设置为 1/8,并启用 FIFO 模式。
阅读全文
相关推荐















