linux tty驱动名称,Linux下TTY驱动程序分析
1、tty设备
有串口、usb转串口、调制解调器(传统的WinModem类设备)等。Linux-tty驱动程序的核心紧挨在标准字符设备驱动层之下,并体统了一系列的功能,作为接口被终端类型设备使用。内核负责控制通过tty设备的数据流,并且格式化这些数据。为了控制数据流,有许多不同的线路规程(line discipline)可以虚拟地“插入”任何的tty设备上,这由不同的tty线路规程驱动程序实现。tty线路规程的作用是使用特殊的方法,把从用户或者硬件那里接受的数据格式化。这种格式化通常使用一些协议来完成转换,比如PPP或者是蓝牙Bluetooth。
2、tty架构图分析
用户空间主要是通过设备文件同tty_core交互。tty_core根据用空间操作的类型再选择跟line discipline和tty_driver交互。例如设置硬件的ioctl指令就直接交给tty_driver处理。Read和write操作就会交给 line discipline处理。Line discipline是线路规程的意思。正如它的名字一样,它表示的是这条终端”线程”的输入与输出规范设置.主要用来进行输入/输出数据的预处理。处理之后。就会将数据交给tty_driver。Tty_driver就是终端对应的驱动了。它将字符转换成终端可以理解的字串,再将其传给终端设备。
值得注意的是,这个架构没有为tty_driver提供read操作。也就是说tty_core 和line discipline都没有办法从tty_driver里直接读终端信息。这是因为tty_driver对应的hardware并不一定是输入数据和输出 数据的共同负载者。例如控制终端,输出设备是显示器。输入设备是键盘。基于这样的原理。在line discipline中有一个输入缓存区。并提供了一个名叫receive_buf()的接口函数。对应的终端设备只要调用line discipine的receiver_buf函数,将数据写入到输入缓存区就可以了。
如果一个设备同时是输入设备又是输出设备。那在设备的中断处理中调用receive_buf()将数据写入即可。
3、核心结构体
#include
struct tty_driver {
intmagic;/*幻数,通常被设置为TTY_DRIVER_MAGIC。在alloc_tty_driver函数中被初始化*/
struct kref kref;/* Reference management */
struct cdev cdev;
struct module*owner;/*驱动模块的所有者*/
const char*driver_name;/*驱动程序的名称,在/proc/tty和sysfs中使用*/
const char*name;/*驱动节点的名字*/
intname_base;/*为穿件设备名字而使用的开始编号*/
intmajor;/*驱动程序的主设备号*/
intminor_start;/*驱动程序使用的最小次设备号*/
intminor_num;/* number of *possible* devices */
intnum;/*可以分配给驱动程序次设备号的个数*/
shorttype;/* type of tty driver */
shortsubtype;/* subtype of tty driver */
struct ktermios init_termios; /*当被创建时,含有初始值的termios结构*/
intflags;/*驱动程序标志位*/
struct proc_dir_entry *proc_entry; /*驱动程序的/proc入口结构体*/
struct tty_driver *other; /*指向tty从属设备驱动程序的指针*/
/*
* Pointer to the tty data structures
*/
struct tty_struct **ttys;
struct ktermios **termios;
struct ktermios **termios_locked;
void *driver_state;
/*
* Driver methods
*/
const struct tty_operations *ops;
struct list_head tty_drivers;
};
#include
struct tty_operations {
struct tty_struct * (*lookup)(struct tty_driver *driver,
struct inode *inode, int idx);
int (*install)(struct tty_driver *driver, struct tty_struct *tty);
void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
int (*open)(struct tty_struct * tty, struct file * filp);/*open函数*/
void (*close)(struct tty_struct * tty, struct file * filp);/*close函数*/
void (*shutdown)(struct tty_struct *tty);
void (*cleanup)(struct tty_struct *tty);
int (*write)(struct tty_struct * tty,
const unsigned char *buf, int count);/*write函数*/
int (*put_char)(struct tty_struct *tty, unsigned char ch);/*单字符写入函数*/
void (*flush_chars)(struct tty_struct *tty);
int (*write_room)(struct tty_struct *tty);/*检测缓冲区的剩余空间*/
int (*chars_in_buffer)(struct tty_struct *tty);/*检测包含数据的缓冲区数量*/
int (*ioctl)(struct tty_struct *tty,
unsigned int cmd, unsigned long arg);/*当设备节点的调用ioctl(2)时,该函数被tty核心调用*/
long (*compat_ioctl)(struct tty_struct *tty,
unsigned int cmd, unsigned long arg);
void (*set_termios)(struct tty_struct *tty, struct ktermios * old);/*改变设备的termios设置*/
void (*throttle)(struct tty_struct * tty);/*当tty核心的输入缓冲区满的时候,调用该函数。
tty驱动程序将试图通知设备,不要再发送更多的字符。*/
void (*unthrottle)(struct tty_struct * tty);/*当tty核心的输入缓冲区被清空是,调用该函数,使能其接受更多的数据*/
void (*stop)(struct tty_struct *tty);/*tty驱动程序将停止向设备发送数据*/
void (*start)(struct tty_struct *tty);/*恢复数据的传送*/
void (*hangup)(struct tty_struct *tty);/*当tty驱动程序挂起tty设备时,调用该函数。此时对任何特定硬件的操作应当被挂起*/
int (*break_ctl)(struct tty_struct *tty, int state);/*中断连接控制函数*/
void (*flush_buffer)(struct tty_struct *tty);/*刷新缓冲区,并丢失里面的数据*/
void (*set_ldisc)(struct tty_struct *tty);/*设置线路规程的函数*/
void (*wait_until_sent)(struct tty_struct *tty, int timeout);/*向硬件发送数据*/
void (*send_xchar)(struct tty_struct *tty, char ch);/*发送X类型的字符函数。要发送的字符放在ch变量中*/
int (*tiocmget)(struct tty_struct *tty);/*获得特定tty设备当前的线路设置*/
int (*tiocmset)(struct tty_struct *tty,
unsigned int set, unsigned int clear);/*为特定的tty设备设置当前线路*/
int (*resize)(struct tty_struct *tty, struct winsize *ws);
int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
int (*get_icount)(struct tty_struct *tty,
struct serial_icounter_struct *icount);
#ifdef CONFIG_CONSOLE_POLL
int (*poll_init)(struct tty_driver *driver, int line, char *options);
int (*poll_get_char)(struct tty_driver *driver, int line);
void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endif
const struct file_operations *proc_fops;
};
linux tty驱动名称,Linux下TTY驱动程序分析相关推荐
- 从入门到精通ARM(4412)-Linux内核驱动编程【下】-李志勇-专题视频课程
从入门到精通ARM(4412)-Linux内核驱动编程[下]-247人已学习 课程介绍 嵌入式绝对是当前IT领域最炙手可热的话题了.其主要应用领域涵盖与人类相关的各行各业: * 消费电 ...
- linux设备驱动模型-linux驱动开发第5部分-朱有鹏-专题视频课程
linux设备驱动模型-linux驱动开发第5部分-4285人已学习 课程介绍 本课程是linux驱动开发的第5个课程,主要内容是linux的设备驱动模型,包括总线.类.设备.驱动等概 ...
- Linux设备驱动---OMAP3630 Linux I2C总线驱动分析(1)
原文地址:http://blog.csdn.net/kellycan/article/details/6394737 1 Linux I2C驱动架构 Linux下I2C驱动的架构图如下: 图1.1 L ...
- 【翻译】【linux设备驱动】linux地址类型
[翻译][linux设备驱动]linux地址类型 Linux中使用的地址类型列表: 用户虚拟地址(User virtual addresses) 用户空间程序可见的普通地址.用户虚拟地址的长度为32位 ...
- linux蜂鸣器驱动指令,linux蜂鸣器驱动 蜂鸣器--LINUX.doc
linux蜂鸣器驱动 蜂鸣器--LINUX 导读:就爱阅读网友为您分享以下"蜂鸣器--LINUX"的资讯,希望对您有所帮助,感谢您对92的支持! //mux = 1/16 tcfg ...
- linux+网卡驱动社区,Linux下如何确定网卡所使用的驱动程序
有些时候你可能想知道某个Linux系统的网卡正在使用什么驱动程序,下面简单介绍下如何解决这个问题. 1. 无论是集成网卡还是独立的网卡,都必须通过某种方式连接到PCI总线上,这样的话,必定有有一个代号 ...
- linux网卡驱动 pdf,Linux下网卡驱动程序.pdf
zekairecv 于 2015-10-04 00:58:57发表: 谢谢 weilee1 于 2015-04-19 17:41:05发表: 看看 雪语阑风 于 2014-12-04 11:03:39 ...
- linux显卡驱动mxm,linux下我的FX5200显卡驱动安装
linux下我的FX5200显卡驱动安装 发布时间:2008-09-20 16:42:33来源:红联作者:Keiboc 一.为什么要装驱动 一般情况下,只要你下载了LINUX的最新发行版本,比如Fed ...
- Linux下触摸屏驱动程序分析
[摘要: 本文以 linux 3.5--Exynos4412仄台,剖析 触摸屏 驱动焦点内容.Linux下触摸屏驱动(以ft5x06_ts为例)须要懂得以下学问: 1. I2C协定 2. Exynos ...
最新文章
- bzoj2618 [Cqoi2006]凸多边形
- python点的作用-Python中*和**的作用(课堂小结)
- java12小时制的时间转换为24小时制
- day1 -- Python变量、注释、格式化输出字符串、input、if、while、for
- 微信小游戏凭什么拿走开发者 70% 的日流水?
- php日程 增删改查,使用Fullcalendar管理日程事件(增删改查拖放)
- 原码,反码,补码的表示范围总结
- Spark创建临时视图
- XAMPP最详细的安装及使用教程
- 【python】43_用pygame制作乌龟吃鱼游戏
- linux libodbc.so.1,关于C#:Testprintenv:加载共享库时出错:libodbc.so.1:无法打开共享对象文件...
- 文章-编程需要知道多少数学知识?
- R语言可视化——熵曲线
- 服务器win10系统开机慢,三种方法教你解决Win10系统开机慢,爱纯净官网
- 像“毒液”一样的粘液机器人火了,能取出体内异物,穿过1.5mm细缝无压力!...
- opencascade 0xXXXXXXXX处最可能的异常: 0xC0000005: 写入位置 0x00000014 时发生访问冲突
- python公开课乐博学院_当我学完 Python ,我学会了些什么【乐搏TestPRO】
- 由preempt_disable的实现想到的
- vi和vt的区别小窍门_十大vi技巧和窍门
- 计算机毕业设计PHP+安卓电影院售票管理APP论文(源码+程序+lw+远程调试)