arm LED驱动小程序 可以通过modprobe 加载ko文件

这篇博客介绍了如何使用C语言编写一个ARM系统上的驱动程序,实现通过ioctl系统调用来控制GPIO口的LED灯开关。测试程序可用于加载ko文件,实现硬件的直接交互。
摘要由CSDN通过智能技术生成

一个小程序 控制LED灯的开光 系统调用ioctl读写操作GPIO口

C 驱动程序如下       

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/input.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <asm/gpio.h>
#include <plat/gpio-cfg.h>

#define LED_ON	0x100001
#define LED_OFF	0x100002

//软件私有结构体
struct led_private {
	int major;
	struct class *cls;
	struct cdev led_cdev;
	void *gpio_base; //寄存器的起始虚拟地址
};

static struct led_private *pled = NULL;

static int led_open(struct inode *inode,
						struct file *file)
{
	/*1.获取内存信息*/
	struct led_private *pledp = 
			container_of(inode->i_cdev,
					struct led_private,
					led_cdev);
	unsigned l
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值