mmap() function - Linux
I am trying to access specific memory locations and return the value at that location (read a status register). My code does not return the expected value when executed.
I am running this on a Linux 2.4.9 embedded computer.
My suspision is the data I am passing into the mmap() function is not correct.
This code compiled without errors.
The variable want_value is passed in as the address that I would like to view. The return value should be the data in that location.
Thank you for any suggestions.
unsigned long memory(unsigned long want_value)
unsigned long *data, ret;
fd = open("/dev/mem", O_RDWR | O_SYNC); //file descriptor
data = mmap(((unsigned long *)want_value), 4, PROT_READ, MAP_SHARED, fd, 0); // returns actual memory address
ret = *((unsigned long *)(data));
munmap (((unsigned long *)want_value), 4);