Ive been trying to use the mmap() function as I used to do in C but I can
t manage to make it work.
The code below was implemented in C, but when I transfer it to C++ it simply gives me a segmentation error when I try to write something to the lw_pio_ptr like ~*lw_pio_ptr=0xFFFF~
printf("DE0-SoC Demo - FPGA + SoC \n");
void *virtual_base;
int fd;
void *lw_pio_ptr;
if((fd = open( "/dev/mem", ( O_RDWR | O_SYNC ))) == -1 ){
printf(" Error: couldn't open dev/mem \n");
return 1;
}
printf("/dev/mem opened. \n");
virtual_base = mmap( NULL, HW_REGS_SPAN, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, HW_REGS_BASE );
if( virtual_base == MAP_FAILED ){
printf(" Error: mmap() has failed... \n");
close(fd);
return 1;
}
lw_pio_ptr = virtual_base + ((unsigned long)(ALT_LWFPGASLVS_OFST + PIO_FPGA2HPS_LW_BASE) & (unsigned long)( HW_REGS_MASK ));
Also, the code in C++ I can`t just do this expression as in C. In C++ I have to cast the virtual_base pointer to a (unsigned long *).
"`lw_pio_ptr = virtual_base + ((unsigned long)(ALT_LWFPGASLVS_OFST + PIO_FPGA2HPS_LW_BASE) & (unsigned long)( HW_REGS_MASK ));"`
Does someone know how to fix it?
Thank you!