Forum Discussion
Altera_Forum
Honored Contributor
10 years agoSebar, this is a most correct and easier way to map peripherials.
Note the differences with the project i sent you //LWAXI# define LWAXI_FPGASLAVES_OFST ( 0xFF200000 ) //BASE ADDRES HPS2FPGA LIGHTWEIGHT_AXI# define LWAXI_SPAN ( 0x00200000 ) //IS 2MB WIDE volatile unsigned long *DIPSWITCH_address=NULL; //AXI //#define AXI_FPGASLAVES_OFST ( 0xC0000000 ) //BASE ADDRES HPS2FPGA AXI INTERFACE //#define AXI_SPAN ( 0x3C000000 ) //IS 960MB WIDE int main(int argc, char **argv) { void *LWAXI_virtual_base; //void *AXI_virtual_base; int fd; // Open the kernel driver to memory if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { perror( "dev/mem" ); return( 1 ); } //Map the physical address of the LIGHTHPS2FPGA AXI INTERFACE from start to end LWAXI_virtual_base = mmap( NULL, LWAXI_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, LWAXI_FPGASLAVES_OFST ); //MAP ERROR if( LWAXI_virtual_base == MAP_FAILED ) { perror( "mmap" ); close( fd ); return( 1 ); } //Map the DIPSWITHCHES PIO DIPSWITCH_address = LWAXI_virtual_base + ( ( unsigned long ) ( DIPSWITCH_BASE) ); alt_read_word(DIPSWITCH_address); // UNMAP LIGHTWEIGHT HPS2FPGA AXI if( munmap( LWAXI_virtual_base, LWAXI_SPAN ) != 0 ) { perror( "munmap" ); close( fd ); return( 1 ); } close( fd ); return( 0 ); } but the best way to do this is in a final application is to make a driver https://zhehaomao.com/blog/fpga/2013/12/29/sockit-4.html