为系统处理器编写Linux设备驱动程序
发布时间:2016-01-24 19:31:23 所属栏目:Linux 来源:网络整理
导读:引 言 编写 Linux 设备驱动程序无疑是一项复杂的工作。本文将集中介绍非标准硬件的设备驱动程序编写,探讨硬件应用编程接口,并借用 Cirrus Logic EP9312 片上
其他类型设备驱动程序采用次要号码区分设备。 硬件接口函数在设备驱动器内即被静态定义,当设备注册时,由内核通过传递给操作系统的文档操作函数指针获得。指针列表定义如下: static struct file_operations ep93xx_ts_fops = { owner: THIS_MODULE, read: ep93xx_ts_read, write: ep93xx_ts_write, poll: ep93xx_ts_poll, open: ep93xx_ts_open, release: ep93xx_ts_release, fasync: ep93xx_ts_fasync, } 初始化触摸屏设备后,即需创建文档系统特殊文件,以便协助应用程序代码访问设备。创建 EP9312 触摸屏特殊文件的 mknod 命令如下: mknod /dev/misc/ep93xx_ts c 10 240 该步骤即可在根目录系统下的初始化文档初始化 Linux 时得到执行,也可在命令提示里实现手动操作。 以下是用户级应用代码的一个实例,通过文档系统特殊文件访问触摸屏设备: #define TS_DEV "/dev/misc/ep93xx_ts" int read_ts() { int fd, nbytes; short data[3]; fd = open("/dev/misc/ep93xx_ts", O_NONBLOCK); if ( fd < 0 ) { printf("Unable to open touch screen device %s!n", TS_DEV); exit(1); } nbytes = read(pd_fd, data, sizeof(data)); close(fd); if (nbytes != sizeof(data)) return 0; return 1; } (编辑:云计算网_泰州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |