驱动编写

来源:互联网 发布:人民大学 数据库系统 编辑:程序博客网 时间:2024/04/29 04:00

一,设备注册,首先要将设备添加到虚拟平台总线platform

1,include/linux/platform_device.h打开"platform_device"所在文件

对以上两件结构体实例化是在平台文件arch/arm/mach-exynos/mach-itop4412.c,里头要修改两段语句

2,在menuconfig里添加选项

vim drivers/char/Kconfig在里头添加一段脚本

3,ls /sys/devices/platform/可以虚拟总线上查看到注册设备

二,驱动注册platform_driver_register/platform_driver_unregister

1,include/linux/platform_device.h打开"platform_driver"

入口:module_init(hello_init)->platform_driver_register(&hello_driver)->hello_driver.hello_probe()
就实现了模块对platform_driver的调用
出口:hello_driver.hello_remove()->platform_driver_unregister(&hello_driver)->module_exit(hello_init)

三,生成设备节点(杂项设备节点)

1,vim include/linux/miscdevice.h有misc_register()/misc_deregister(),并有miscdevice结构体

在platform_driver.probe函数里调用misc_register()来实现miscdevice结构的调用,实例化这个结构体。

miscdevice结构里有一个const struct file_operations *fops结构体,它在include/linux/fs.h里面,包含它然后实现相关函数功能。

然后ls /dev/就可以看见这个设备节点了。

四,实现驱动const struct file_operations *fops的成员函数

1,<sys/types.h> <sys/stat.h> <fcntl.h> <unistd.h> <sys/ioctl.h>

就可以使用open/close/ioctl等函数对设备节点进行操作。

*************************************************************

*************************************************************

*************************************************************

*************************************************************

以上是对杂项设备的注册与驱动的介绍

*************************************************************

*************************************************************

*************************************************************

一,



 

0 0
原创粉丝点击