#include
#include
#include
#include
#include
#include
#define GPIO_BASE_V 0x1000F000 //物理地址
/* 虚拟地址 */
#define GPIO_DBCLK_DIV_V (GPIO_BASE_V+0X000) /* 去毛刺采用时钟分频比配置寄存器 */
#define GPIO_PORTA_DIR_V (GPIO_BASE_V+0X004) /* A组端口输入输出方向配置寄存器 */
#define GPIO_PORTA_SEL_V (GPIO_BASE_V+0X008) /* A组端口通用用途选择配置寄存器 */
#define GPIO_PORTA_INCTL_V (GPIO_BASE_V+0X00C) /* A组端口通用用途输入时类型配置寄存器 */
#define GPIO_PORTA_INTRCTL_V (GPIO_BASE_V+0X010) /* A组端口中断触发类型配置寄存器 */
#define GPIO_PORTA_INTRCLR_V (GPIO_BASE_V+0X014) /* A组端口通用用途中断清除配置寄存器 */
#define GPIO_PORTA_DATA_V (GPIO_BASE_V+0X018) /* A组端口通用用途数据配置寄存器 */
int main(int argc,char *argv[])
{
int fd=-1;
if((fd=open("/dev/mem",O_RDWR|O_SYNC))==-1)
{
printf("mmap error!\n");
return(-1);
}
unsigned char * map_base=(unsigned char * )mmap(0,0xff,PROT_READ|PROT_WRITE,MAP_SHARED,fd,GPIO_BASE_V);
if(map_base==NULL)
{
printf("mmap error!\n");
return -1;
}
*(volatile unsigned char*)(map_base+0X0008) |= (0x1<<6); //作为通用用途
*(volatile unsigned long*)(map_base+0X0004) &= ~(0x1<<6 );//输出
*(volatile unsigned long*)(map_base+0X0018) &= ~(0x1<<6 );//初始输出拉低
while(1){
*(volatile unsigned long*)(map_base+0X0018)|= 0x1<<6;
sleep(1);
*(volatile unsigned long*)(map_base+0X0018)&= ~0x1<<6;
sleep(1);
}
close(fd);
munmap(map_base,0xff);//解除映射关系
}
阅读(1902) | 评论(0) | 转发(0) |