几乎串口操作的所有功能都由drivers/tty/serial/serial_core.c
来实现。如果你想以不同的方式做到这一点然后从include/linux/serial_core.h
struct uart_ops {
unsigned int (*tx_empty)(struct uart_port *);
void (*set_mctrl)(struct uart_port *, unsigned int mctrl);
unsigned int (*get_mctrl)(struct uart_port *);
void (*stop_tx)(struct uart_port *);
void (*start_tx)(struct uart_port *);
void (*send_xchar)(struct uart_port *, char ch);
void (*stop_rx)(struct uart_port *);
void (*enable_ms)(struct uart_port *);
void (*break_ctl)(struct uart_port *, int ctl);
int (*startup)(struct uart_port *);
void (*shutdown)(struct uart_port *);
void (*flush_buffer)(struct uart_port *);
void (*set_termios)(struct uart_port *, struct ktermios *new,
struct ktermios *old);
void (*set_ldisc)(struct uart_port *, int new);
void (*pm)(struct uart_port *, unsigned int state,
unsigned int oldstate);
int (*set_wake)(struct uart_port *, unsigned int state);
const char * (*type)(struct uart_port *);
void (*release_port)(struct uart_port *);
int (*request_port)(struct uart_port *);
void (*config_port)(struct uart_port *, int);
int (*verify_port)(struct uart_port *, struct serial_struct *);
int (*ioctl)(struct uart_port *, unsigned int, unsigned long);
#ifdef CONFIG_CONSOLE_POLL
void (*poll_put_char)(struct uart_port *, unsigned char);
int (*poll_get_char)(struct uart_port *);
#endif
};
提供自己的功能uart_ops
在你的情况,你需要实现set_termios功能。另外,请查看uart_get_divisor()
了解如何设置波特率。
你能告诉你的目标是什么吗?我很确定内核已经有一个串口驱动程序供你使用,请在include/linux/serial_core.h中查找函数来使用它,也许'include/linux/serio.h'如果你想写一个设备驱动程序使用串口 – Raber
感谢您的回复。我的意图是编写一个内核模块,它将以每秒gpio中断115200波特率读取和写入串行端口。为此,我想从我的内核模块设置波特率和一些tty参数。再次感谢 – hussain
hussain,你在这个功能上有什么进展吗? – Fakebear