zoukankan      html  css  js  c++  java
  • 字符设备驱动

    2.4内核

    static inline int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops)
    static inline void unregister_chrdev(unsigned int major, const char *name)

    2.6内核

    #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
    #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
    #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi)) //将主设备号和次设备号转换成dev_t类型
    
    int register_chrdev_region(dev_t from, unsigned count, const char *name) //注册设备号
    int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)
    void unregister_chrdev_region(dev_t from, unsigned count)
    
    struct cdev *cdev_alloc(void)
    void cdev_init(struct cdev *cdev, const struct file_operations *fops) //初始化
    int cdev_add(struct cdev *p, dev_t dev, unsigned count) //添加到内核
    void cdev_del(struct cdev *p) //删除

    手动创建设备节点

    # cat /proc/devices //查看主设备号
    # mknod /dev/设备名 c|b(c是字符设备,b是块设备) 主设备号 次设备号 //创建
    # rm /dev/char //删除

    借助class创建设备节点
    从linux内核2.6的某个版本之后,devfs不复存在,udev成为devfs的替代

    #define class_create(owner, name)
    void class_destroy(struct class *cls)
    struct device *device_create(struct class *class, struct device *parent, dev_t devt, void *drvdata, const char *fmt, ...)
    void device_destroy(struct class *class, dev_t devt)

    创建多个设备

    struct cdev *cdev;
    
    cdev = kzalloc(sizeof(struct cdev) * COUNT, GFP_KERNEL);
    for(i = 0; i < COUNT; i++)
    {
        cdev_init(&cdev[i], &fops);
        cdev_add(&cdev[i], dev+i, 1);
    }
    
    for(i = 0; i < COUNT; i++)
    {
        cdev_del(&cdev[i]);
    }
  • 相关阅读:
    POJ 3614 Sunscreen
    POJ 2431 Expedition
    如何解决inline-block元素的空白间距 css 完美解决
    li的inline-block出现间隙原因,解决方案
    基线baseline
    CSS IE Hack
    css实现页面文字不换行、自动换行、强制换行
    IE 常见bug
    IE haslayout 问题引起的常见 bug
    CSS Cross-Browser Inline-Block
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709802.html
Copyright © 2011-2022 走看看