Linux--字符设备驱动结构框图

来源:互联网 发布:网络交友诈骗案例 编辑:程序博客网 时间:2024/05/14 10:32

其中cdev结构体用于描述一个字符设备,其定义如下:

struct cdev {

struct kobject kobj;

struct module *owner;

const struct file_operations *ops;

struct list_head list;

dev_t  dev;      //设备号

unsigned int count;

};


cdev_init()函数用于初始化cdev成员,建立cdev和file_operations之间的链接;

register_chrdev_region()和alloc_chrdev_region()函数向系统申请设备号。

__init xxx_init()用于设备驱动模块加载函数,其中一般有cdev_init函数,和注册字符设备号,调用register_chrdev_region()。

__exit  xxx_exit()用于设备驱动模块卸载函数。其中调用unregister_chrdev_egion()//释放占用的设备号。cdev_del//注销设备。

0 0