ed int timeout; /* character-based timeout */
unsigned int type; /* port type */
const struct uart_ops *ops; //具体端口的相关操作函数
unsigned int custom_divisor;
unsigned int line; /* port index */
resource_size_t mapbase; /* for ioremap */ //io内存物理地址
struct device *dev; /* parent device */
unsigned char hub6; /* this should be in the 8250 driver */
unsigned char suspended;
unsigned char unused[2]; //允许串口收发字符标志
void *private_data; /* generic platform data pointer */
};
uart_iconut为串口信息计数器,包含了发送字符计数、接收字符计数等。在串口的发送中断处理函数和接收中断处理函数中,我们需要管理这些计数。
struct uart_icount {
__u32 cts;
__u32 dsr;
__u32 rng;
__u32 dcd;
__u32 rx; //接收字符数
__u32 tx; //发送字符数
__u32 frame; //错误帧计数
__u32 overrun; //rx fifo溢出计数
__u32 parity; //帧校验错误计数
__u32 brk; //break计数
__u32 buf_overrun;
};
对于实现一个串口驱动,主要的工作量就是实现struct uart_ops *ops中的各个操作函数。
* This structure describes all the operations that can be
* done on the physical hardware.
*/
struct uart_ops {
unsigned int (*tx_empty)(struct uart_port *); //串口tx FIFO缓存是否为空
void (*set_mctrl)(struct uart_port *, unsigned int mctrl); //设置串口modem控制
unsigned int (*get_mctrl)(struct uart_port *); //获得串口的modem控制
void (*stop_tx)(struct uart_port *); //停止串口发送
void (*start_tx)(struct uart_port *); //使能串口发送
void (*send_xchar)(struct uart_port *, char ch); //发送xchar
void (*stop_rx)(struct uart_port *); //禁止串口接收
void (*enable_ms)(struct uart_port *); //使能modem状态信号
void (*break_ctl)(struct uart_port *, int ctl); //设置break信号
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 *); //设置线路规程
void (*pm)(struct uart_port *, unsigned int state,
unsigned int oldstate); //电源管理
int (*set_wake)(struct uart_port *, unsigned int state);
/*
* Return a string describing the type of the port
*/
const char *(*type)(struct uart_port *);
/*
* Release IO and memory resources used by the port.
* This includes iounmap if necessary.
*/
void (*release_port)(struct uart_port *);
/*
* Request IO and memory resources used by the port.
* This includes iomapping the port if necessary.
*/
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
};