zoukankan      html  css  js  c++  java
  • 【linux驱动分析】misc设备驱动

        misc设备驱动。又称混杂设备驱动。

    misc设备驱动共享一个设备驱动号MISC_MAJOR。它在includelinuxmajor.h中定义:

            #define MISC_MAJOR 10
    miscdevice的结构体例如以下,它在includelinuxmiscdevice.h中定义:
    struct  miscdevice {
     int  minor;
     const  char  *name;
     const  struct file_operations  *fops;
     struct  list_head  list;
     struct  device  *parent;
     struct  device  *this_device;
     const  char  *nodename;
     mode_t  mode;
    };
    misc设备驱动的注冊和注销时用这两个函数,他们也定义在includelinuxmiscdevice.h中:
    extern int misc_register(struct miscdevice * misc);
    extern int misc_deregister(struct miscdevice *misc);

    样例:
    再分配此设备号时,能够设为MISC_DYNAMIC_MINOR。这样会自己主动分配此设备号,如:
    static struct miscdevice misc = {
     .minor = MISC_DYNAMIC_MINOR,
     .name = DEVICE_NAME,
     .fops = &dev_fops,
    };
    以下的是file_operations结构体:
    static struct file_operations dev_fops = {
     .owner = THIS_MODULE,
     .unlocked_ioctl = sbc2440_leds_ioctl,
    };
    注冊和注销函数:
    static int __init dev_init(void)
    {
     int ret;
     …………

     ret = misc_register(&misc);
     printk (DEVICE_NAME" initialized ");
     return ret;
    }

    static void __exit dev_exit(void)
    {
     misc_deregister(&misc);
    }
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    C#使用BouncyCastle操作国密SM3
    Win10 2004种子
    Excel对比两列数据,找到重复项
    CentOS7 + frp远程访问内网Windows电脑
    Docker on Mac OS
    MySQL5.6中查询多边形包含点情况(ST_Contains、ST_Within)
    SQL查询表的所有字段名
    清除文本中Html的标签
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6925769.html
Copyright © 2011-2022 走看看