Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdint.h>
- #include <sys/mman.h>
- // Mapping to reserved DDR3 mmeory: 196MB / 0xC400000
- #define HW_REGS_BASE ( 196*1024*1024 )
- // mapping address range 1MB
- #define HW_REGS_SPAN ( 0x100000 )
- #define HW_REGS_MASK ( HW_REGS_SPAN - 1 )
- void HexDump( unsigned char * buffer, int bytes)
- {
- int i;
- for(i=0; i<bytes; i++)
- {
- if(i%16 == 0)
- printf("\n [%04X] " , i);
- printf("%02X " , buffer[i]);
- }
- printf( "\n");
- }
- int main() {
- void *virtual_base;
- int fd;
- // Broj bajta koje zelim da mapiram na fizicki adresni prostor i broj
- // njih koje cu posle ispisati
- int bytes_to_map = 4;
- int bytes_to_dump = 4;
- // map the address space for the LED registers into user space so we can interact with them.
- // we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span
- if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
- printf( "ERROR: could not open \"/ dev/mem \"...\n" );
- return(1);
- }
- printf( "mapping DDR3 offset from 0x%X, range = 0x%X. \r\n" , HW_REGS_BASE, HW_REGS_SPAN);
- //virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );
- virtual_base = mmap( NULL, bytes_to_map, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );
- if( virtual_base == MAP_FAILED ) {
- printf( "ERROR: mmap() failed...\n" );
- close( fd );
- return(1);
- }
- //HexDump(virtual_base, 0x40);
- // Okej ovde mu kazem ispisi mi 8 bajta od ovih gore 16 koje si mapirao
- // pocev od HW_REGS_BASE
- HexDump(virtual_base, bytes_to_dump);
- // clean up our memory mapping and exit
- // if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) {
- // Ovde unmap odradim kako bi virtuelne adrese vratio kernelu na raspolaganje.
- if( munmap( virtual_base, bytes_to_map ) != 0 ) {
- printf( "ERROR: munmap() failed...\n" );
- close( fd );
- return(1);
- }
- close( fd );
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement