12.2.8 触摸屏设备驱动的轮询与异步通知
在触摸屏设备驱动中,通过s3c2410_ts_poll()函数实现了轮询接口,这个函数的实现非常简单。它将等待队列添加到poll_table,当缓冲区有数据时,返回资源可读取标志,否则返回0,如代码清单12.26所示。
代码清单12.26 触摸屏设备驱动的poll()函数
1 static unsigned int s3c2410_ts_poll(struct file *filp, struct poll_table_struct *wait)
2 {
3 poll_wait(filp, &(tsdev.wq), wait);//添加等待队列到poll_table
4 return (tsdev.head == tsdev.tail) ? 0 : (POLLIN | POLLRDNORM);
5 }
|
而为了实现触摸屏设备驱动对应用程序的异步通知,设备驱动中要实现s3c2410_ts_fasync()函数,这个函数与第9章给出的模板完全一样,如代码清单12.27所示。
代码清单12.27 触摸屏设备驱动的fasync()函数
1 #ifdef USE_ASYNC
2 static int s3c2410_ts_fasync(int fd, struct file *filp, int mode)
3 {
4 return fasync_helper(fd, filp, mode, &(tsdev.aq));
5 }
6 #endif
|
| 回书目 上一节 下一节 |