71 lines
1.9 KiB
C
71 lines
1.9 KiB
C
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/ide.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
/***************************************************************
|
|
Copyright © ALIENTEK Co., Ltd. 1998-2029. All rights reserved.
|
|
文件名 : chrdevbase.c
|
|
作者 : 正点原子
|
|
版本 : V1.0
|
|
描述 : chrdevbase驱动文件。
|
|
其他 : 无
|
|
论坛 : www.openedv.com
|
|
日志 : 初版V1.0 2020/12/26 正点原子创建
|
|
***************************************************************/
|
|
#define major_dev_id 80
|
|
#define dev_name "test_dev"
|
|
|
|
static char cache[1024];
|
|
static int tis_module_open(struct inode *inode, struct file *file)
|
|
{
|
|
printk("%s: module open\n", dev_name);
|
|
return 0;
|
|
}
|
|
|
|
static int tis_module_release(struct inode *inode, struct file *file)
|
|
{
|
|
printk("%s: module open\n", dev_name);
|
|
return 0;
|
|
}
|
|
static ssize_t tis_module_read(struct file *file, char __user *out, size_t size, loff_t *offt)
|
|
{
|
|
int ret = 0;
|
|
ret = copy_to_user(out, cache, size);
|
|
return 0;
|
|
}
|
|
static ssize_t tis_module_write(struct file *file, const char __user *in, size_t size, loff_t *offt)
|
|
{
|
|
int ret = 0;
|
|
ret = copy_from_user(cache, in, size);
|
|
if (ret == 0)
|
|
{
|
|
printk("user out : %s\n", cache);
|
|
}
|
|
return 0;
|
|
}
|
|
static struct file_operations tis_module_f = {
|
|
.owner = THIS_MODULE,
|
|
.write = tis_module_write,
|
|
.read = tis_module_read,
|
|
.open = tis_module_open,
|
|
.release = tis_module_release,
|
|
};
|
|
|
|
static int __init tis_module_init(void)
|
|
{
|
|
register_chrdev(major_dev_id, dev_name, &tis_module_f);
|
|
printk("module init\n");
|
|
|
|
return 0;
|
|
}
|
|
static void __exit tis_module_exit(void)
|
|
{
|
|
unregister_chrdev(major_dev_id, dev_name);
|
|
printk("module exit\n");
|
|
}
|
|
module_init(tis_module_init);
|
|
module_exit(tis_module_exit);
|
|
MODULE_LICENSE("GPL v3.0");
|
|
MODULE_AUTHOR("Chenyf"); |