在Linux驱动中把无法归类的五花八门的设备定义为混杂设备(用miscdevice结构体表述)。miscdevice共享一个主设备号MISC_MAJOR(即10),但次设备号不同。 所有的miscdevice设备形成了一个链表,对设备访问时内核根据次设备号查找对应的miscdevice设备,然后调用其file_operations结构中注册的文件操作接口进行操作。 在内核中用struct miscdevice表示miscdevice设备,然后调用其file_operations结构中注册的文件操作接口进行操作。miscdevice的API实现在drivers/char/misc.c中。
一、混杂设备介绍
1. miscdevice结构体
struct miscdevice { int minor; //次设备号 const char *name; //设备的名称 const struct file_operations *fops; //文件操作 struct list_head list; //misc_list的链表头 struct device *parent; //父设备(Linux设备模型中的东东了,哈哈) struct device *this_device; //当前设备,是device_create的返回值,下边会看到 }; |
2. misc子系统初始化函数
|
下边是register_chrdev函数的实现:
|
来看看这个设备的操作函数的集合:
|
可以看到这里只有一个打开函数,用户打开miscdevice设备是通过主设备号对应的打开函数,在这个函数中找到次设备号对应的相应的具体设备的open函数。它的实现如下:
|
3. misc子注册函数
并且会自动生成设备节点
|



现代雷达系统的信号设计
5962-89541022A

BFR340T






京公网安备 11010802033920号