【发布时间】: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