驱动编写

一,设备注册,首先要将设备添加到虚拟平台总线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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值