linux 设备驱动之tty_operaions数据结构介绍

tty_operations 结构包含所有的函数回调, 可以被一个 tty 驱动设置和被 tty 核心调
用. 当前, 所有包含在这个结构中的的函数指针也在 tty_driver 结构中, 但是会很快被
只有一个这个结构的实例来替代.
int (*open)(struct tty_struct * tty, struct file * filp);
open 函数.
void (*close)(struct tty_struct * tty, struct file * filp);
close 函数.
int (*write)(struct tty_struct * tty, const unsigned char *buf, int count);
write 函数.
void (*put_char)(struct tty_struct *tty, unsigned char ch);
单字节写函数. 这个函数被 tty 核心调用当单个字节被写入设备. 如果一个 tty
驱动没有定义这个函数, write 函数被调用来替代, 当 tty 核心想发送一个单个
字节

void (*flush_chars)(struct tty_struct *tty);
void (*wait_until_sent)(struct tty_struct *tty, int timeout);
刷新数据到硬件的函数.
int (*write_room)(struct tty_struct *tty);
指示多少缓冲空闲的函数.
int (*chars_in_buffer)(struct tty_struct *tty);
指示多少缓冲满数据的函数.
int (*ioctl)(struct tty_struct *tty, struct file * file, unsigned int cmd,
unsigned long arg);
ioctl 函数. 这个函数被 tty 核心调用, 当 ioctl(2)在设备节点上被调用时.
void (*set_termios)(struct tty_struct *tty, struct termios * old);
set_termios 函数. 这个函数被 tty 核心调用, 当设备的 termios 设置已被改变
时.
void (*throttle)(struct tty_struct * tty);
void (*unthrottle)(struct tty_struct * tty);
void (*stop)(struct tty_struct *tty);
void (*start)(struct tty_struct *tty);
数据抑制函数. 这些函数用来帮助控制 tty 核心的输入缓存. 这个抑制函数被调
用当 tty 核心的输入缓冲满. tty 驱动应当试图通知设备不应当发送字符给它.
unthrottle 函数被调用当 tty 核心的输入缓冲已被清空, 并且它现在可以接收更
多数据. tty 驱动应当接着通知设备可以接收数据. stop 和 start 函数非常象
throttle 和 unthrottle 函数, 但是它们表示 tty 驱动应当停止发送数据给设备
以及以后恢复发送数据.
void (*hangup)(struct tty_struct *tty);
挂起函数. 这个函数被调用当 tty 驱动应当挂起 tty 设备. 任何需要做的特殊的
硬件操作应当在此时发生.
void (*break_ctl)(struct tty_struct *tty, int state);
线路中断控制函数. 这个函数被调用当这个 tty 驱动要打开或关闭线路的 BREAK
状态在 RS-232 端口上. 如果状态设为 -1, BREAK 状态应当打开. 如果状态设为
0, BREAK 状态应当关闭. 如果这个函数由 tty 驱动实现, tty 核心将处理
TCSBRK, TCSBRKP, TIOCSBRK, 和 TIOCCBRK ioctl. 否则, 这些 ioctls 被发送给
驱动 ioctl 函数.

void (*flush_buffer)(struct tty_struct *tty);
刷新缓冲和丢失任何剩下的数据.
void (*set_ldisc)(struct tty_struct *tty);
设置线路规程的函数. 这个函数被调用当 tty 核心已改变这个 tty 驱动的线路规
程. 这个函数通常不用并且不应当被一个驱动定义.
void (*send_xchar)(struct tty_struct *tty, char ch);
发送 X-类型 字符 的函数. 这个函数用来发送一个高优先级 XON 或者 XOFF 字符
给 tty 设备. 要被发送的字符在 ch 变量中指定.
int (*read_proc)(char *page, char **start, off_t off, int count, int *eof,
void *data);
int (*write_proc)(struct file *file, const char *buffer, unsigned long count,
void *data);
/proc 读和写函数.
int (*tiocmget)(struct tty_struct *tty, struct file *file);
获得当前的特定 tty 设备的线路设置. 如果从 tty 设备成功获取到, 应当返回这
个值给调用者.
int (*tiocmset)(struct tty_struct *tty, struct file *file, unsigned int set,
unsigned int clear);
设置当前的特定 tty 设备的线路设置. set 和 clear 包含了去设置或者清除的不
同的线路设置.

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一叶知秋yyds

分享是一种美德,感谢金主打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值