Hi all,
I have a simple memory mapped interface, and I would like to write through this values to two registers and then read them back. The following code example works fine:
volatile int *reg1 = (int *) 0x80000000;
volatile int *reg2 = (int *) 0x80000004;
*reg1 = 12; *reg2 = 23;
printf("reg1 = %i\n", *reg1);
printf("reg2 = %i\n", *reg2);
Instead of "hardcoding" the addresses, I would like the address to be put together from a base address and an offset. Using some preprocessor statements, I wanna have some defines
BEGIN UPDATE
#define WriteReg(BaseAddress, RegOffset, Data) \
*((volatile int *)((char*)BaseAddress + RegOffset)) = (unsigned int)(Data)
#define ReadReg(BaseAddress, RegOffset, Data) \
(unsigned int)(Data) = *((volatile int *)((char*)BaseAddress + RegOffset))
WriteReg((int *) 0x80000000, 0, 18);
WriteReg((int *) 0x80000000, 4, 29);
WriteReg((int *) 0x80000000, 4, res);
printf("Reg2 = %i\n", res);
WriteReg((int *) 0x80000000, 0, res);
printf("Reg1 = %i\n", res);
END UPDATE
The output is now in either case 1073804536, instead of 12 and 23, respectively. So I assume I must have done something horrible wrong with the pointers, anyone a comment how I can properly build up this address with a define statement?
Thanks a lot, Martin