【问题标题】:How does a serial driver get attached with a tty port串行驱动程序如何与 tty 端口连接
【发布时间】:2020-08-25 06:48:05
【问题描述】:

我在这里查看 Linux 示例 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 中手动配置?

【问题讨论】:

  • 您已经从“Linux 驱动程序开发”一书中找到了一个示例。在询问示例的含义之前,您是否阅读过这本书?
  • @Tsyvarev 我知道 sn-p 来自 LDD Book,是的,我读过这本书。在书中找不到答案。
  • 有趣的是,您作为代码 sn-p 放在这里的函数没有回答您的问题。
  • @0andriy 是的,只是想展示数据是如何从串行驱动程序发送到 tty 端口的。但是,是的,它没有回答我的问题。我还查看了其余的代码,也找不到太多内容。
  • 那么,阅读 tiny_init() 没有帮助?

标签: linux-kernel serial-port linux-device-driver uart tty


【解决方案1】:

在用户空间中,tty 被视为文件。所以在这个例子中,打开的文件描述符是 uart 端口 https://github.com/guu1/serial-communitation-rs232

因为来自用户空间中使用的 termios 函数,他们在手册页中说

termios 函数描述了一个通用的终端接口,它是 用于控制异步通信端口。

我不熟悉设备驱动程序,但从我所看到的情况来看,您似乎不是使用 open() 和 write() 之类的函数来发送和接收数据,而是使用 uart_core.h、uart_ops 指针中的函数

引用自:https://www.linuxjournal.com/article/6331

此结构中更有趣的变量之一是 struct uart_ops 指针,它定义了串行内核用来回调特定端口串行驱动程序的函数列表。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多