int misc_register(struct miscdevice * misc);
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;
};
=============================================
drv_read()
{
}
drv_write()
{
}
drv_open()
{
}
drv_release()
{
}
static const struct file_operations fops = {
.read = drv_read,
.write = drv_write,
.open = drv_open,
.release = drv_release,
};
static struct miscdevice miscdev = {
.minor = 0,
.name = "demo_misc",
.fops = &fops,
};
int init(void)
{
return misc_register(&miscdev);
}
void exit(void)
{
misc_deregister(&miscdev);
}
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;
};
=============================================
drv_read()
{
}
drv_write()
{
}
drv_open()
{
}
drv_release()
{
}
static const struct file_operations fops = {
.read = drv_read,
.write = drv_write,
.open = drv_open,
.release = drv_release,
};
static struct miscdevice miscdev = {
.minor = 0,
.name = "demo_misc",
.fops = &fops,
};
int init(void)
{
return misc_register(&miscdev);
}
void exit(void)
{
misc_deregister(&miscdev);
}
本文介绍了一个简单的Linux杂项设备驱动实现案例,包括如何定义杂项设备结构体、注册及注销流程,并展示了基本的文件操作函数如读写、打开和释放等。

1万+

被折叠的 条评论
为什么被折叠?



