歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 驅動編寫

驅動編寫

日期:2017/3/3 12:42:49   编辑:Linux技術

一,設備注冊,首先要將設備添加到虛擬平台總線platform1,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_unregister1,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等函數對設備節點進行操作。

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

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

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

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

以上是對雜項設備的注冊與驅動的介紹

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

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

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

一,

Copyright © Linux教程網 All Rights Reserved