串口驱动详解

一、概念
在linux系统中,tty设备是一种字符型设备。Linux中主要包含控制台、串行端口、伪终端等3类终端设备。
(1)串行终端(/dev/ttySACn)
(2)控制终端(/dev/ttyn,/dev/console),其中在微处理器中通过串口实现空格终端,如:console=ttySAC0。
(3)伪终端(/dev/pty),如:ctrl+alt+f1…f7,打开伪终端。

二、TTY驱动程序调用关系
TTY驱动程序相关的文件在目录/driver/char与/driver/ttyn下。TTY的层次结构包括TTY应用层、TTY核心层、TTY驱动层。其中TTY应用层是把应用层数据发送到TTY核心层;TTY核心层通过线路规划(line discipline)将数据传递给相应的TTY驱动层;TTY驱动层则把数据发给硬件。下图为TTY驱动程序调用关系图:
在这里插入图片描述
三、TTY核心数据结构及使用介绍
TTY驱动程序核心结构体:tty_driver
struct tty_driver {
int magic; /* magic number for this structure /
struct kref kref; /
Reference management */
struct cdev **cdevs;
struct module *owner;
const char *driver_name;
const char name;
int name_base; /
offset of printed name /
int major; /
major device number /
int minor_start; /
start of minor device number /
unsigned int num; /
number of devices allocated /
short type; /
type of tty driver /
short subtype; /
subtype of tty driver /
struct ktermios init_termios; /
Initial termios /
unsigned long flags; /
tty driver flags */
struct proc_dir_entry proc_entry; / /proc fs entry */
struct tty_driver other; / only used for the PTY driver /
/

* Pointer to the tty data structures
*/
struct tty_struct **ttys;
struct tty_port **ports;
struct ktermios **termios;
void driver_state;
/

* Driver methods
*/
const struct tty_operations *ops;
struct list_head tty_drivers;
} ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值