[beagleboard] Accessing memory in user space

Hi,

I am working on beagle board, i am accessing memory(0x49056034) from user space

int fd = open("/dev/mem", O_RDWR);
if (fd < 0)
{
printf(“Could not open file\n”);
return;
}
eink_conregp = (volatile EINK_CONREG *) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE,
MAP_PRIVATE,fd, 0x49056000);
if (eink_conregp == MAP_FAILED)
{
printf(“Mapping failed\n”);
close(fd);
return;
}
printf(“Address of eink_conreg %x\n”,eink_conreg);
i am getting the address for 0x49056000
eink_conregp = eink_conregp + 0x34;
printf(“Address of eink_conreg %x\n”,eink_conreg);
I am not able to add this 0x34, i am getting some 0xe0

Please let me know what i am doing is wrong? I want access 0x49056034 memory location of beagle board.

How is eink_conregp declared? I assume it's declared as "volatile
EINK_CONREG *eink_conregp".

When you add an integer to a pointer, C always multiplies the integer
by the size of the object pointed to. So the expression "eink_conregp
+ 0x34" adds 0x34 is *eink_conregp is a byte, or 0x68 if *eink_conregp
is a short, or 0xD0 if *eink_conregp is a long. I don't know where
you'd get 0xE0.

You may need something like: "eink_conregp + (0x34 / sizeof
(*eink_conregp))" to get the address you want.

In general, when accessing device registers it's good to create a
struct which matches the register layout of the device rather than
adding explicit constants.

Hope this helps,
John