#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<sys/mman.h>
#include<fcntl.h>
#include <asm/page.h>
#define GPIO_CTL_BASE 0x56000000
#define rGPBCON 0x10
#define rGPBDAT 0x14
#define rGPBUP 0x18
#define rGPGCON 0x60
#define rGPGDAT 0x64
#define rGPGUP 0x68
unsigned int *GPBCON,*GPBDAT,*GPBUP,*GPGCON,*GPGDAT,*GPGUP;
void power(int data)
{
if(data)
{
*(volatile unsigned int *)GPGDAT |= 1<<3;
}
else
{
*(volatile unsigned int *)GPGDAT &= ~(1<<3);
}
}
int main(int argc, char** argv)
{
int gpio_fd, ip=0, i=0;
unsigned char *gpio_map;
gpio_map = NULL;
GPBCON = NULL;
GPBDAT = NULL;
GPBUP = NULL;
gpio_fd =open("/dev/mem",O_RDWR);
if (gpio_fd == -1)
{
printf("can't open /dev/mem.\n");
return ;
}
GPBCON = (volatile unsigned int *) (gpio_map+rGPBCON);
GPBDAT = (volatile unsigned int *) (gpio_map+rGPBDAT);
GPBUP = (volatile unsigned int *) (gpio_map+rGPBUP);
GPGCON = (volatile unsigned int *) (gpio_map+rGPGCON);
GPGDAT = (volatile unsigned int *)(gpio_map+rGPGDAT);
GPGUP = (volatile unsigned int*)(gpio_map+rGPGUP);
//*(volatile unsigned int *)GPBCON=0x154000;
//*(volatile unsigned int *)GPBUP=0x7ff;
//初始化io
*(volatile unsigned int *)GPBCON |= 1<<6;
*(volatile unsigned int *)GPBCON &= ~(1<<7);
*(volatile unsigned int *)GPBDAT |= 1<<3;
sleep(1);
*(volatile unsigned int *)GPBDAT &= ~(1<<3);
sleep(1);
*(volatile unsigned int *)GPBDAT |= 1<<3;
//*(volatile unsigned int *)GPGDAT=0x7ff;
//while(1)
//{
//printf("gpgdat==0x%x\n",*(volatile unsigned int *)GPGDAT);
//sleep(1);
//}
//power(0);
m unmap (0, 0xbc);
if (gpio_fd != 0x0)
{
close(gpio_fd);
}
printf("GPIO Control Test end\n");
#include <stdlib.h>
#include <math.h>
#include<sys/mman.h>
#include<fcntl.h>
#include <asm/page.h>
#define GPIO_CTL_BASE 0x56000000
#define rGPBCON 0x10
#define rGPBDAT 0x14
#define rGPBUP 0x18
#define rGPGCON 0x60
#define rGPGDAT 0x64
#define rGPGUP 0x68
unsigned int *GPBCON,*GPBDAT,*GPBUP,*GPGCON,*GPGDAT,*GPGUP;
void power(int data)
{
if(data)
{
*(volatile unsigned int *)GPGDAT |= 1<<3;
}
else
{
*(volatile unsigned int *)GPGDAT &= ~(1<<3);
}
}
int main(int argc, char** argv)
{
int gpio_fd, ip=0, i=0;
unsigned char *gpio_map;
gpio_map = NULL;
GPBCON = NULL;
GPBDAT = NULL;
GPBUP = NULL;
gpio_fd =open("/dev/mem",O_RDWR);
if (gpio_fd == -1)
{
printf("can't open /dev/mem.\n");
return ;
}
gpio_map = (unsigned char *)mmap(0, 0xbc,PROT_READ | PROT_WRITE, MAP_SHARED,\ gpio_fd, GPIO_CTL_BASE);
printf("gpio_map===%d\n",gpio_map);GPBCON = (volatile unsigned int *) (gpio_map+rGPBCON);
GPBDAT = (volatile unsigned int *) (gpio_map+rGPBDAT);
GPBUP = (volatile unsigned int *) (gpio_map+rGPBUP);
GPGCON = (volatile unsigned int *) (gpio_map+rGPGCON);
GPGDAT = (volatile unsigned int *)(gpio_map+rGPGDAT);
GPGUP = (volatile unsigned int*)(gpio_map+rGPGUP);
//*(volatile unsigned int *)GPBCON=0x154000;
//*(volatile unsigned int *)GPBUP=0x7ff;
//初始化io
*(volatile unsigned int *)GPBCON |= 1<<6;
*(volatile unsigned int *)GPBCON &= ~(1<<7);
*(volatile unsigned int *)GPBDAT |= 1<<3;
sleep(1);
*(volatile unsigned int *)GPBDAT &= ~(1<<3);
sleep(1);
*(volatile unsigned int *)GPBDAT |= 1<<3;
//*(volatile unsigned int *)GPGDAT=0x7ff;
//while(1)
//{
//printf("gpgdat==0x%x\n",*(volatile unsigned int *)GPGDAT);
//sleep(1);
//}
//power(0);
m unmap (0, 0xbc);
if (gpio_fd != 0x0)
{
close(gpio_fd);
}
printf("GPIO Control Test end\n");