#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include "gpio.h"
struct gpio_params gmm;
int gpid =-1;
void main(int argc,char *argv[])
{
char filename[20];
int i,k;
gpid = open("/dev/gpio", O_RDWR);
if (!gpid)
{
printf("GPIO initial fail
");
}
gmm.ctrl_pin = 0xc0; // choose GPIO7 pin
gmm.data_direct = 0xc0; //set as output pin
if(ioctl(gpid, GPIO_SET_DATA_DIRECT,&gmm))
printf("GPIO_SET_DATA_DIRECT failed
");
for(i=0;i<10;i++)
{
gmm.data_out = i%2==0?0x80:0x40;
if(ioctl(gpid, GPIO_SET_DATA_OUTPUT,&gmm))
printf("GPIO_SET_DATA_OUTPUT failed
");
printf("%d
",i);
usleep(500000);
}
close(gpid);
return ;
}
//gpio.h
#define _GM8180_Platform
struct gpio_params {
u_int group;
u_int ctrl_pin;
u_int data_out;
u_int data_in;
u_int int_clear;
u_int data_direct;
u_int int_enable;
u_int int_trigger;
u_int int_both;
u_int int_riseneg;
} gpio_params;
//Modify By Ken.Hsieh
#ifdef _GM8120_Platform
#define GPIO_SET_DATA_OUTPUT 3
#define GPIO_READ_DATA_INPUT 4
#define GPIO_SET_DATA_DIRECT 5
#define GPIO_SET_INT 6
#define GPIO_SET_INT_FUNC 7
#define GPIO_CLEAR_INT 8
#endif
#ifdef _GM8180_Platform
#define IOC_MAGIC 'g'
#define GPIO_SET_DATA_OUTPUT _IOWR(IOC_MAGIC, 8, gpio_params)
#define GPIO_READ_DATA_INPUT _IOWR(IOC_MAGIC, 9, gpio_params)
#define GPIO_SET_DATA_DIRECT _IOWR(IOC_MAGIC, 10, gpio_params)
#define GPIO_SET_INT_FUNC _IOWR(IOC_MAGIC, 11, gpio_params)
#define GPIO_SET_INT _IOWR(IOC_MAGIC, 12, gpio_params)
#define GPIO_CLEAR_INT _IOWR(IOC_MAGIC, 13, gpio_params)
#endif
//makefile
LINUX_SRC := /usr/src/arm-linux-2.6/linux-2.6.14-fa
CC = arm-linux-gcc
STRIP =arm-linux-strip
INCLUDE = -I$(LINUX_SRC)/include/
INCLUDE += -I/usr/src/arm-linux-2.6/module/GPIO
TARGET1=gpio
all:
$(CC) $(INCLUDE) gpio.c -o $(TARGET1)
$(STRIP) $(TARGET1)
clean:
rm -f gpio
版权声明:本文为博主原创文章,未经博主允许不得转载。