I am having a very hard time figuring out how to solve the following problem. I am on an embedded system with very little memory and want to minimize memory usage.
Pointers have always confused the heck out of me and will always do.
I have a whole bunch of defines for register addresses:
#define GPIO_PORTA_BASE (*((volatile unsigned long *)0x40004000))
#define GPIO_PORTB_BASE (*((volatile unsigned long *)0x40005000))
//etc..
These registers are direct accessible. e.g:
GPIO_PORT_BASE &= 0x01;
What I need is an array that contains the above registers so that I can easily map them to an index. e.g:
not_sure_what_to_declare_the array_as port_base_array[] {
GPIO_PORTA_BASE,
GPIO_PORTB_BASE,
//etc
}
What I need to end up being able to do is something like this:
volatile unsigned long *reg;
*reg_a = port_base_array[0];
reg_a &=0x1;
I am using gcc to compile my code for arm cortex m3.
Any insight would be appreciated.
I don’t know why @Etienne deleted his answer, but it contained the essential information: The address is cast to
volatile unsigned long *. That’s what you need an array of.We need to take the address again (
&GPIO_PORTA_BASE), since the macro automatically dereferences them. Access as: