tty函数(国外英文资料).doc

  1. 1、本文档共14页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
tty函数(国外英文资料)

tty函数 打开和关闭 打开函数被TTY核心调用,当一个用户对这个TTY驱动被分配的设备节点调用开放时。TTY核心使用一个指向分配给这个设备的tty_struct结构的指针调用它,还用一个文件指针。这个开放成员必须被一个TTY驱动为它能正确工作而设置;否则,- enodev被返回给用户当调用开放时。 当调用这个开放函数,TTY驱动被期望或者保存一些传递给它的tty_struct变量中的数据,或者保存一个可以基于端口次编号来引用的静态数组中的数据。这是有必要的,所以TTY驱动知道哪个设备在被引用当以后的接近,写,和其他函数被调用时。 tiny_tty驱动保存一个指针在TTY结构中,如同下面代码所见到: 静态变量tiny_open(struct tty_struct * tty,文件结构文件) { 结构tiny_serial *小; 结构timer_list *定时器; 指数; / *初始化指针以防某事失败/ TTY - driver_data = null; / *串行对象这个tty指针相关的/ 指数= TTY -索引; 小= tiny_table [索引]; 如果(微= NULL) { *第一次访问这个设备,让我们创建它* 小= kmalloc(sizeof(*小),gfp_kernel); 如果(!小) 返回enomem; init_mutex(小- SEM); 小- open_count = 0; 小定时器= null; tiny_table [索引] =小; } 下降(和微)SEM; / *拯救我们的结构在tty结构*/ TTY - driver_data =小; 小- TTY = TTY; 在这个代码中,tiny_serial结构被保存在TTY结构中。这允许tiny_write,tiny_write_room,和tiny_close函数来获取tiny_serial结构和正确操作它。 tiny_serial结构定义为: 结构tiny_serial { 结构tty_struct * tty;/*指向TTY这个设备*/ 国际open_count;/*次数这个端口已经打开*/ 结构信号量; 结构timer_list *定时器; }; 如同我们已见到的, The open_count variable is initialized to 0 in the open port of open for the first time in the call. This is a typical reference count, because a TTY driver open and close may function on the same equipment repeatedly calls to multiple processes to read and write data. For the correct handling of all things, one must keep this the port is open or close the count; the driving increment and decrement this count in the open use. When opening is opened for the first time, any necessary hardware initialization and memory allocation can be done. The last time when the port is closed, shut down any hardware and memory necessary cleaning can be done. The rest of the tiny_open function shows how to track the number of times the device is turned on: ++tiny-open_count; If (tiny-open_count = 1) { This is the first time this * port is opened * / Do any hardware initialization needed here / * * / The open function must return, or a negative error number, if something happens to prevent successful opening, or a 0 to indicate success The close function poin

文档评论(0)

f8r9t5c + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8000054077000003

1亿VIP精品文档

相关文档