- 论坛徽章:
- 0
|
ads7843 驱动程序分析
本文将从驱动程序的机制和策略两方面分析:机制包括驱动程序的框架和硬件的控制,
策略主要是中断的处理和缓冲区的使用,这两种方法在 驱动的设计中经常用到 。
1. 框架
大部分驱动程序操作设计到三个重要的数据结构:file_operation,file,inode;
static struct file_operations ads7843_fops = {
owner: THIS_MODULE,
open: ads7843_ts_open,
read: ads7843_ts_read,
release: ads7843_ts_release,
#ifdef USE_ASYNC
fasync: ads7843_ts_fasync,
#endif
poll: ads7843_ts_poll,
};
(1)open ,read 读写和打开设备
(2)poll:unsigned (*poll)(struct file*,struct poll_table_struct *);
查询某个文件描述符的读取河写入是否会阻塞。
常用于需要使用多个输入输出流而又不阻塞其中任何一个的应用中。
poll_wait(filp, &(tsdev.wq), wait);
poll_wait(struct file *filp, wait_queue_head_t *, poll_table *);
文件描述符 等待队列 轮讯表
功能:向轮讯表中加入一个等待队列
返回一个可以指示读写的位掩码,通常一个可读设备返回 POLLIN | POLLRDNORM;
可写设备返回 POLLOUT | POLLRDNORM;
static unsigned int ads7843_ts_poll(struct file *filp, struct poll_table_struct *wait)
{
poll_wait(filp, &(tsdev.wq), wait);
return (tsdev.head == tsdev.tail) ? 0 : (POLLIN | POLLRDNORM);
}
(3) int (*fasync) (int ,struct file *,int );异步通知通知设备FASYNC标志发生了变化;
static int ads7843_ts_fasync(int fd, struct file *filp, int mode)
{
return fasync_helper(fd, filp, mode, &(tsdev.aq));
}
(4) release:
int (*release) (struct inode *inode, struct file *filp);当file结构被释放时,调用;
这里有两个非常重要的调用就是异步和轮询机制,将在驱动程序的策略中分析。
框架的另一部分就是模块的初始化和注销
module_init(ads7843_ts_init);
module_exit(ads7843_ts_exit);
static int __init ads7843_ts_init(void)
{
int ret;
tsEvent = tsEvent_dummy;
ret = register_chrdev(0, DEVICE_NAME, &ads7843_fops);
if (ret
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/78225/showart_1224794.html |
|