免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1179 | 回复: 0
打印 上一主题 下一主题

ads7843 驱动程序分析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-25 16:13 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP