miscdev简称杂类设备
杂类设备就是对字符设备驱动做一个封装,方便简单
使用杂类设备封装字符设备需要包含的头文件:
#include <linux/miscdevice.h>
(1)杂类设备的数据结构:
(2)杂类设备注册和解除注册相关函数
(3)如何使用?
下面的这个xxx_fops就是字符设备操作的文件操作结构体
首先定义一个杂类设备结构体并初始化:
在初始化函数
在注销函数
就是这么简单!!!^_^!!!
杂类设备就是对字符设备驱动做一个封装,方便简单
使用杂类设备封装字符设备需要包含的头文件:
#include <linux/miscdevice.h>
(1)杂类设备的数据结构:
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;
};
(2)杂类设备注册和解除注册相关函数
int misc_register(struct miscdevice * misc);
int misc_deregister(struct miscdevice *misc);
(3)如何使用?
下面的这个xxx_fops就是字符设备操作的文件操作结构体
static struct file_operations xxx_fops = {
.owner = THIS_MODEULE ,
.read = ...,
....
};
首先定义一个杂类设备结构体并初始化:
static struct misedevice xxx_dev = {
.minor = xxx, //对应设备的次设备号
.name = xxx, //对应设备的设备名称
.fops = &xxx_fops , //文件指针
} ;
在初始化函数
static int __init xxx_init(void)
{
//注册杂类设备
misc_register(&xxx_dev);
}
在注销函数
static void __exit xxx_exit(void)
{
//注销杂类设备
misc_deregister(&xxx_dev);
}
就是这么简单!!!^_^!!!