Linux设备驱动编程---miscdevice杂类设备的使用方法

来源:互联网 发布:淘宝什么刀锋利 编辑:程序博客网 时间:2024/04/30 04:36
miscdev简称杂类设备
杂类设备就是对字符设备驱动做一个封装,方便简单
使用杂类设备封装字符设备需要包含的头文件:
#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);}

就是这么简单!!!^_^!!!
1 0
原创粉丝点击