Linux串口驱动编程.doc
《Linux串口驱动编程.doc》由会员分享,可在线阅读,更多相关《Linux串口驱动编程.doc(66页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Linux串口(serial、uart)驱动程序设计目录Linux串口(serial、uart)驱动程序设计2一、核心数据结构2二、串口驱动API6三、串口驱动例子9linux UART 串口驱动开发文档27概念阐述27一、老版本的串口驱动程序28二、目前的串口驱动程序29三、3个数据结构及其串口核心层API311、uart_driver312、uart_port323、uart_ops33四、uart_ops37五、注册串口终端40六、支持platform_driver43七、串口接收数据和发送数据流程451. 相关文件452. 数据收发47基于Linux2.6.22和s3c2440的串口驱
2、动简析-(1) 2013-11-21 15:56:3248基于Linux2.6.22和s3c2440的串口驱动简析-(2) 2013-11-21 15:58:4956Linux串口(serial、uart)驱动程序设计 分类: LINUX原文地址:Linux串口(serial、uart)驱动程序设计 作者:lingdxuyan 一、核心数据结构 串口驱动有3个核心数据结构,它们都定义在 1、uart_driver uart_driver包含了串口设备名、串口驱动名、主次设备号、串口控制台(可选)等信息,还封装了tty_driver(底层串口驱动无需关心tty_driver)。 struct u
3、art_driver struct module *owner; /* 拥有该uart_driver的模块,一般为THIS_MODULE */ const char *driver_name; /* 串口驱动名,串口设备文件名以驱动名为基础 */ const char *dev_name; /* 串口设备名 */ int major; /* 主设备号 */ int minor; /* 次设备号 */ int nr; /* 该uart_driver支持的串口个数(最大) */ struct console *cons; /* 其对应的console.若该uart_driver支持serial c
4、onsole,否则为NULL */ /* * 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; ; 2、uart_port uart_port用于描述串口端口的I/O端口或I/O内存地址、FIFO大小、端口类型、串口时钟等信息。实际上,一个uart_port实例对应一个串口设备 struct uart_port spinloc
5、k_t lock; /* 串口端口锁 */ unsigned int iobase; /* IO端口基地址 */ unsigned char _iomem *membase; /* IO内存基地址,经映射(如ioremap)后的IO内存虚拟基地址 */ unsigned int irq; /* 中断号 */ unsigned int uartclk; /* 串口时钟 */ unsigned int fifosize; /* 串口FIFO缓冲大小 */ unsigned char x_char; /* xon/xoff字符 */ unsigned char regshift; /* 寄存器位移
6、*/ unsigned char iotype; /* IO访问方式 */ unsigned char unused1; #define UPIO_PORT (0) /* IO端口 */ #define UPIO_HUB6 (1) #define UPIO_MEM (2) /* IO内存 */ #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 U
7、ART */ #define UPIO_RM9000 (7) /* RM9000 type IO */ unsigned int read_status_mask; /* 关心的Rx error status */ unsigned int ignore_status_mask;/* 忽略的Rx error status */ struct uart_info *info; /* pointer to parent info */ struct uart_icount icount; /* 计数器 */ struct console *cons; /* console结构体 */ #ifdef
8、 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)
9、#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_
10、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_D
11、EAD (_force upf_t) (1 30) #define UPF_IOREMAP (_force upf_t) (1 flags. These are _private_ to serial_core, and * are specific to this structure. They may be queried by low level drivers. */ #define UIF_CHECK_CD (_force uif_t) (1 25) #define UIF_CTS_FLOW (_force uif_t) (1 26) #define UIF_NORMAL_ACTIV
12、E (_force uif_t) (1 29) #define UIF_INITIALIZED (_force uif_t) (1 31) #define UIF_SUSPENDED (_force uif_t) (1 30) int blocked_open; struct tasklet_struct tlet; wait_queue_head_t open_wait; wait_queue_head_t delta_msr_wait; ; 3、uart_ops uart_ops涵盖了串口驱动可对串口设备进行的所有操作。 /* * This structure describes all
13、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 (*sto
14、p_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_por
15、t *, int ctl); /* 设置break信号 */ int (*startup)(struct uart_port *); /* 启动串口,应用程序打开串口设备文件时,该函数会被调用 */ void (*shutdown)(struct uart_port *); /* 关闭串口,应用程序关闭串口设备文件时,该函数会被调用 */ void (*set_termios)(struct uart_port *, struct ktermios *new, struct ktermios *old); /* 设置串口参数 */ void (*pm)(struct uart_port *,
16、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 *); /* 释放串口已申请的IO端口/IO内存资源,必要时还需iounmap */ int (*request_port)(struct uart_port *
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Linux 串口 驱动 编程
限制150内