------在android模拟器和开发板上进行测试驱动模块
第一步添加逻辑功能部分代码
1.添加建立文件部分代码,添加后的hello.c的代码如下:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <asm/uaccess.h>
#define DEVICE_NAME "myfirstdriver"//定义设备文件
static struct file_operations dev_fops =
{.owner=THIS_MODULE};
static struct miscdevice misc =
{.minor=MISC_DYNAMIC_MINOR, .name=DEVICE_NAME, .fops=&dev_fops};
//linnux驱动的装载函数
static int __init hello_drive_init(void)
{
int ret;
ret = misc_register(&misc);//注册设备文件
printk("hello drive init\n");
return 0;
}
//linux驱动的卸载函数
static void __exit hello_drive_exit(void)
{
misc_deregister(&m