您当前的位置: 首页 > 
  • 4浏览

    0关注

    417博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

第一章:JNI的简单使用(5)-加载内核驱动

江南才尽,年少无知! 发布时间:2019-02-01 13:11:42 ,浏览量:4

上一节我们介绍 了andriod软件层怎么调用C程序,以及C库的编译与加载,实现了应用层和底层连系的关键部分,接下来,把内核驱动部分编写完成,该章节就结束了,假定你已经看过之前的博文。

LED驱动加载

相信大家看到这里已经有了一定linux驱动的基础,简单驱动不做介绍,可另行查阅其他资料,创建C文件leds_drv.c,代码如下:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static const int led1_gpio = (32*0 + 8*1 + 4);
static const int led2_gpio = (32*0 + 8*1 + 0);

static int gec3399_leds_open(struct inode *inode, struct file *file)
{
	return 0;
}

static long gec3399_leds_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
	//printk("cmd = %u    arg = %lu\n",cmd,arg);
	switch(cmd)
	{
		case 0:	switch(arg)
				{
					case 0: gpio_set_value(led1_gpio,0); break;
					case 1:	gpio_set_value(led1_gpio,1); break;
				}break;
		
		case 1: switch(arg)
				{
					case 0: gpio_set_value(led2_gpio,0); break;
					case 1:	gpio_set_value(led2_gpio,1); break;			
				}break;
	}
	return 0;
}

static int gec3399_leds_release(struct inode *inode, struct file *file)
{
	return 0;
}

static const struct file_operations gec3399_leds_fops = {
	.owner = THIS_MODULE,
	.open = gec3399_leds_open,
	.unlocked_ioctl = gec3399_leds_ioctl,
	.release = gec3399_leds_release,
}; 

static struct miscdevice gec3399_leds_misc = {
	.minor = MISC_DYNAMIC_MINOR,
	.fops = &gec3399_leds_fops,
	.name   = "leds_drv",	
}; 

static int __init gec3399_leds_init(void)
{
    int ret;
	ret =  misc_register(&gec3399_leds_misc);   //注册字符设备
	if(ret             
关注
打赏
1592542134
查看更多评论
0.0417s