#include #include #include #include #include "hps.h" #include "stdint.h" #include /* The base address byte offset for the start of the ALT_LWFPGASLVS component. */ #define ALT_LWFPGASLVS_OFST 0xff200000 /* The base address byte offset for the start of the ALT_STM component. */ #define ALT_STM_OFST 0xfc000000 #define ALT_AXI_FPGASLVS_OFST (0xC0000000) // axi_master #define HW_REGS_BASE ( ALT_STM_OFST ) #define HW_REGS_SPAN ( 0x40000000 ) #define HW_REGS_MASK ( HW_REGS_SPAN - 1 ) #define CUSTOM_LOGIC_BASE 0x10000 //from qsys address space int main() { void *virtual_base; int fd, i; void *custom_logic_addr; if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { printf( "ERROR: could not open \"/dev/mem\"...\n" ); return( 1 ); } virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, ALT_AXI_FPGASLVS_OFST ); if( virtual_base == MAP_FAILED ) { printf( "ERROR: mmap() failed...\n" ); close( fd ); return( 1 ); } custom_logic_addr = virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + LED_PIO_BASE ) & ( unsigned long)( HW_REGS_MASK ) ); printf("My first register= %x",*(uint32_t *)custom_logic_addr); // to read from your logic *(uint32_t *)custom_logic_addr = 0xf; //writing to your logic // clean up our memory mapping and exit if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) { printf( "ERROR: munmap() failed...\n" ); close( fd ); return( 1 ); } close( fd ); return( 0 ); }