我在这里查看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中手动配置的吗?
在用户空间中,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指针,该指针定义了一系列函数,串行核心使用这些函数来调用特定于端口的串行驱动程序。
希望这会有所帮助