mmap register access in C
Posted: Wed May 16, 2018 1:15 pm
Hi everyone,
I'm quite new to C-Programming and I'm trying to understand how the access to the RAM registers works in the PID-application.
In fpga_pid.c, the pointer to the register is set using mmap:
I have several questions:
1) Why is page_addr calculated this way? The &-operator seems to apply some mask but I don't see what it is used for (same question for the inversion of page_size in the calculation).
2) What is page_off?
3) In the RedPitaya Memory Map, all registers are said to have a 4 byte offset. How does this come into play when accessing the registers via mmap?
Any help would be greatly appreciated!
Best,
skywalker
I'm quite new to C-Programming and I'm trying to understand how the access to the RAM registers works in the PID-application.
In fpga_pid.c, the pointer to the register is set using mmap:
Code: Select all
g_pid_fd = open("/dev/mem", O_RDWR | O_SYNC);
page_addr = PID_BASE_ADDR & (~(page_size-1));
page_off = PID_BASE_ADDR - page_addr;
page_ptr = mmap(NULL, PID_BASE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, g_pid_fd, page_addr);
g_pid_reg = page_ptr + page_off;
1) Why is page_addr calculated this way? The &-operator seems to apply some mask but I don't see what it is used for (same question for the inversion of page_size in the calculation).
2) What is page_off?
3) In the RedPitaya Memory Map, all registers are said to have a 4 byte offset. How does this come into play when accessing the registers via mmap?
Any help would be greatly appreciated!
Best,
skywalker