Forum Discussion
Altera_Forum
Honored Contributor
16 years agoAlthough the external component is 8 bits, most likely it was interfaced to the avalon bus as a 32-bit component. Thus every register address to your component actually occupies 4 addresses on the Avalon bus. So, if your component has two register addresses (0 and 1), these would correspond to "MY_INTERFACE_BASE" and "MY_INTERFACE_BASE + 4". This is exactly what the pointer arithmetic does in the code you gave:
alt_u32* p1 = (alt_u32*) MY_INTERFACE_BASE;
alt_u32* p2 = ((alt_u32*) MY_INTERFACE_BASE) + 1; Adding one to an "alt_u32*" actually adds 4. This results in two pointers pointing to the two registers of your component. Jake