Part Number: DRA72
Tool/software: Linux
Hi,
mmap gpio7, read reg fail.
the source file:
/**********************************************************************
**
** ���: api_mmap.c
** ��Ȩ����: (c) 2016-2017 ���������ţ���������˾
** �����: mmap api
**
***********************************************************************
** ����ʷ��¼
**=====================================================================
**| ���� | ���� | ��
**=====================================================================
**| 2017/06/15 | ��ѧ�� | ������һ�汾
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#define BASE_ADDR 0x48051000
#define GPIO_CTRL 0x130
#define GPIO_OE 0x134 //0 = Output enabled ; 1 = Output disabled
#define GPIO_DATAIN 0x138
#define GPIO_DATAOUT 0x13C
#define GPIO_SETDATAOUT 0x194
#define GPIO7_3 1<<3
#define GPIO7_4 1<<4
void _writel(void *addr, unsigned int val)
{
*((volatile unsigned int *)addr) = val;
}
unsigned int _readl(void *addr)
{
return *((volatile unsigned int *)addr);
}
int main()
{
int fd_mem;
unsigned char *map_addr = NULL;
if((fd_mem = open("/dev/mem", O_RDWR | O_NDELAY))<0)
{
perror("open mem");
return -1;
}
map_addr = mmap(NULL, 512, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, BASE_ADDR);
if(map_addr == NULL)
{
perror("mmap");
return -1;
}
printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<%p\n",map_addr);
printf("1GPIO_OE:0x%x",_readl(map_addr+GPIO_OE));
//_writel(map_addr+GPIO_OE, _readl(map_addr+GPIO_OE) & ~(GPIO7_3 | GPIO7_4));
//printf("2GPIO_OE:0x%x",_readl(map_addr+GPIO_OE));
return 0;
}
the fail:
Regards,
Cesar

