使用mmap读写硬件寄存器,读入和写出的相同地址,数据不..
各位大虾门好。我遇到一个问题,问题如下:使用mmap读写硬件寄存器,读入和写出的相同地址,数据不同,请大虾门知道,我的测试程序代码如下:#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define PINMUX_ADDR 0x01C14000
int main(int argc,char **argv)
{
char *FPGA_PIN_base;
int data=0x1F0F0F0F;
int fd;
fd = open("/dev/mem",O_RDWR|O_SYNC); //鎵撳紑mem鏂囦欢锛岃闂洿鎺ュ湴鍧€
if(fd == -1)
{
printf("ERROR OF OPEN mem!\n");
exit(-1);
}
printf("OPEN the mem!\n");
////////////////////////////////////////////////////////////////////////////////////////////
FPGA_PIN_base=(char *)mmap(0,1024,PROT_READ|PROT_WRITE,MAP_SHARED,fd,PINMUX_ADDR);
printf("FPGA_PIN=0x%x.PINMUX=0x%x\n",FPGA_PIN_base,data);
///////////////////////////////////////////////////////////////////////////////////////////////////
data = *(volatile unsigned int *)(FPGA_PIN_base+0x134);
printf("FPGA_PIN=0x%x.PINMUX5=0x%x\n",FPGA_PIN_base+0x134,data);
printf("FPGA_PIN=0x%x.PINMUX5=0x%x\n",FPGA_PIN_base+0x134,*(volatile unsigned int *)(FPGA_PIN_base+0x134));
*(volatile unsigned int *)(FPGA_PIN_base+0x134)=0x23; //PINMUX5 0x01C14000+0x134=0x01C14134
data = *(volatile unsigned int *)(FPGA_PIN_base+0x134);
printf("FPGA_PIN=0x%x.PINMUX5=0x%x\n",FPGA_PIN_base+0x134,data);
printf("FPGA_PIN=0x%x.PINMUX5=0x%x\n",FPGA_PIN_base+0x134,*(volatile unsigned int *)(FPGA_PIN_base+0x134));
return 0;
}
页:
[1]