设为首页 加入收藏

TOP

Linux serial构架分析及驱动开发(一)
2014-11-24 07:29:19 来源: 作者: 【 】 浏览:5
Tags:Linux serial 构架 分析 驱动 开发

serial core是构建在tty core之上的。注册一个串口驱动即在tty core层注册一个tty驱动。下面我们看看串口驱动中用到的两个最重要的数据机构 struct uart_driver 表示一个serial驱动,struct uart_port 表示一个串口端口。


struct uart_driver {
struct module *owner;
const char *driver_name; //驱动名称
const char *dev_name; //设备名基础
int major; //主设备号
int minor; //起始次设备号
int nr; //设备个数
struct console *cons; //关联的控制台


/*
* these are private; the low level driver should not
* touch these; they should be initialised to NULL
*/
struct uart_state *state; //串口驱动操作设备数组
struct tty_driver *tty_driver; //表征串口驱动的tty驱动
};


上面结构中struct uart_state *state指向驱动操作的串口设备相关数据结构,其中struct uart_port *port就是我们下面要介绍的描述串口设备的结构,struct uart_info *info 指向相关联的struct tty_struct 结构和数据发射时环形缓冲区struct circ_buf xmit,即串口打开时的描述信息。uart_info有两个成员在底层串口驱动会用到:xmit和tty。用户空间程序通过串口发送数据时,上层驱动将用户数据保存在xmit;而串口发送中断处理函数就是通过xmit获取到用户数据并将它们发送出去。串口接收中断处理函数需要通过tty将接收到的数据传递给行规则层。具体的成员分析我们在后面介绍具体的操作时再分析。


struct uart_port {
spinlock_t lock; /* port lock */ //串口端口锁
unsigned int iobase; /* in/out[bwl] */ //io端口基地址
unsigned char __iomem *membase; /* read/write[bwl] */ //io内存基地址,虚拟地址
unsigned int irq; /* irq number */ //中断号
unsigned int uartclk; /* base uart clock */ //串口时钟
unsigned int fifosize; /* tx fifo size */ //串口fifo缓冲大小
unsigned char x_char; /* xon/xoff char */ //xon/xoff字符
unsigned char regshift; /* reg offset shift */ //j寄存器移位
unsigned char iotype; /* io access style */ //io访问方式
unsigned char unused1;


#define UPIO_PORT (0) //端口
#define UPIO_HUB6 (1)
#define UPIO_MEM (2) //内存
#define UPIO_MEM32 (3)
#define UPIO_AU (4) /* Au1x00 type IO */
#define UPIO_TSI (5) /* Tsi108/109 type IO */
#define UPIO_DWAPB (6) /* DesignWare APB UART */
#define UPIO_RM9000 (7) /* RM9000 type IO */


unsigned int read_status_mask; /* driver specific */ //关心的rx error status
unsigned int ignore_status_mask; /* driver specific */ //忽略的rx error status


struct uart_info *info; /* pointer to parent info */
struct uart_icount icount; /* statistics */


struct console *cons; /* struct console, if any */
#ifdef CONFIG_SERIAL_CORE_CONSOLE
unsigned long sysrq; /* sysrq timeout */
#endif


upf_t flags;


#define UPF_FOURPORT ((__force upf_t) (1 << 1))
#define UPF_SAK ((__force upf_t) (1 << 2))
#define UPF_SPD_MASK ((__force upf_t) (0x1030))
#define UPF_SPD_HI ((__force upf_t) (0x0010))
#define UPF_SPD_VHI ((__force upf_t) (0x0020))
#define UPF_SPD_CUST ((__force upf_t) (0x0030))
#define UPF_SPD_SHI ((__force upf_t) (0x1000))
#define UPF_SPD_WARP ((__force upf_t) (0x1010))
#define UPF_SKIP_TEST ((__force upf_t) (1 << 6))
#define UPF_AUTO_IRQ ((__force upf_t) (1 << 7))
#define UPF_HARDPPS_CD ((__force upf_t) (1 << 11))
#define UPF_LOW_LATENCY ((__force upf_t) (1 << 13))
#define UPF_BUGGY_UART ((__force upf_t) (1 << 14))
#define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16))
#define UPF_CONS_FLOW ((__force upf_t) (1 << 23))
#define UPF_SHARE_IRQ ((__force upf_t) (1 << 24))
#define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28))
#define UPF_FIXED_PORT ((__force upf_t) (1 << 29))
#define UPF_DEAD ((__force upf_t) (1 << 30))
#define UPF_IOREMAP ((__force upf_t) (1 << 31))


#define UPF_CHANGE_MASK ((__force upf_t) (0x17fff))
#define UPF_USR_MASK ((__force upf_t) (UPF_SPD_MASK|UPF_LOW_LATENCY))


unsigned int mctrl; /* current modem ctrl settings */
unsign

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux tty core 源码分析 下一篇Python下调用json.dumps中文显示..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Java 并发工具类:提 (2025-12-25 20:25:44)
·Java面试技巧:如何 (2025-12-25 20:25:41)
·Java并发编程中的线 (2025-12-25 20:25:38)
·C 语言 - cppreferen (2025-12-25 19:50:27)
·《C 语言入门教程》 (2025-12-25 19:50:23)