#include #include #include #include #include #include #include #include #include "hps_0.h" // The start address and length of the Lightweight bridge #define HPS_TO_FPGA_LW_BASE 0xFF200000 #define HPS_TO_FPGA_LW_SPAN 0x0020000 int main(int argc, char **argv) { void * lw_bridge_map = 0; int devmem_fd = 0; int result = 0; // Open up the /dev/mem device (aka, RAM) devmem_fd = open("/dev/mem", O_RDWR | O_SYNC); if(devmem_fd < 0) { perror("devmem open"); exit(EXIT_FAILURE); } // mmap() the entire address space of the Lightweight bridge so we can access our custom module lw_bridge_map = (uint32_t*)mmap(NULL, HPS_TO_FPGA_LW_SPAN, PROT_READ|PROT_WRITE, MAP_SHARED, devmem_fd, HPS_TO_FPGA_LW_BASE); if(lw_bridge_map == MAP_FAILED) { perror("devmem mmap"); close(devmem_fd); exit(EXIT_FAILURE); } volatile uint32_t* memory_avalon = (volatile uint32_t*) (lw_bridge_map + MEMORY_AVALON_0_BASE); // MEMORY_AVALON_0_BASE resolves to 0x0 if(argc >= 3){ // first get the address from the cmd line uint32_t addr = atoi(argv[2]); // then check if the user wants to read or write to if(strcmp(argv[1], "read") == 0){ // determine absolute address of selected register volatile uint32_t* r = (volatile uint32_t*) (memory_avalon + addr); // read content of selected register uint32_t data = *r; printf("reg[%x]=0x%08x(%d)\n", addr, data, data); }else if(strcmp(argv[1], "write") == 0){ if(argc >= 4){ // get data from the cmd line uint32_t data = atoi(argv[3]); // write data into selected register *(memory_avalon + addr) = data; printf("Wrote (%u) @ (%x)\n", data, addr); } } } // dump the whole memory (which is 16 x 32 bit) // MEMORY_AVALON_0_SPAN resolves to 64 for(uint32_t i = 0; i < MEMORY_AVALON_0_SPAN >> 2; i++){ volatile uint32_t* r = (volatile uint32_t*) (memory_avalon + i); uint32_t data = *r; printf("memory_avalon[%x]=0x%08x(%d)\n", i, data, data); } // Unmap everything and close the /dev/mem file descriptor result = munmap(lw_bridge_map, HPS_TO_FPGA_LW_SPAN); if(result < 0) { perror("devmem munmap"); close(devmem_fd); exit(EXIT_FAILURE); } close(devmem_fd); exit(EXIT_SUCCESS); }