一个小程序 控制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