linux字符設備驅動初識

1.設備號申請

字符設備號申請和註銷函數
register_chrdev_region/alloc_chrdev_region
unregister_chrdev_region

2.字符設備註冊

字符設備添加函數
cdev_init/cdev_add/cdev_del

3.創建/dev設備文件

1.創建class結構,以便device_create使用,同時在/sys/class/添加設備目錄
class_create/class_destroy
2./dev/下添加設備目錄,相當於mknod命令
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) 
    #define CLASS_DEV_CREATE(class, devt, device, name) \ 
            device_create(class, device, devt, name) 
#else
    #define CLASS_DEV_CREATE(class, devt, device, name) \ 
            class_device_create(class, device, devt, name) 
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) 
    #define CLASS_DEV_DESTROY(class, devt) \ 
            device_destroy(class, devt) 
#else
    #define CLASS_DEV_DESTROY(class, devt) \ 
            class_device_destroy(class, devt)
#endif

4.創建設備屬性

在device_create創建的目錄下創建設備屬性,作爲屬性和函數的對應關係
device_create_file

5.平臺驅動註冊

platform_driver_register

6.平臺設備文件註冊

在/sys/platform/下注冊設備文件
platform_device_register
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章