串行驱动程序如何连接到 tty 端口

串行驱动程序如何连接到 tty 端口

我在这里查看 Linus 示例 UART 驱动程序代码

https://github.com/martinezjavier/ldd3/blob/master/tty/tiny_serial.c

下面是 UART 驱动程序将数据发送到 tty 端口的代码片段

static void tiny_timer(unsigned long data)
{
    struct uart_port *port;
    struct tty_struct *tty;
    struct tty_port *tty_port;


    port = (struct uart_port *)data;
    if (!port)
        return;
    if (!port->state)
        return;
    tty = port->state->port.tty;
    if (!tty)
        return;

    tty_port = tty->port;

    /* add one character to the tty port */
    /* this doesn't actually push the data through unless tty->low_latency is set */
    tty_insert_flip_char(tty_port, TINY_DATA_CHARACTER, 0);

    tty_flip_buffer_push(tty_port);

    /* resubmit the timer again */
    timer->expires = jiffies + DELAY_TIME;
    add_timer(timer);

    /* see if we have any data to transmit */
    tiny_tx_chars(port);
}

但是,查看代码,我不清楚的是 UART 端口和 tty 端口之间的耦合是如何建立的。 Linux 中需要手动配置吗?

相关内容