I'm referring a document for writing reusable firmware, and code came with the book uses pointer arrays to map memory.
I'm little confused about memory mapping
From this post, If an 8 bit memory is mapped at 0X123, then I can use following
uint8_t volatile * p_reg = (uint8_t volatile *) 0x1234;
or
#define PORT 0X1234
uint8_t volatile * p_reg = (uint8_t volatile *) PORT;
or in case of pointer array
#define PORT 0X1234
uint8_t volatile * const portsout[NUM_PORTS] =
{
(uint8_t*)PORTB, ....,
};
I tried the code came with the book with atmega168 and this is what I had to do to map memory
uint8_t volatile * const portsout[NUM_PORTS] =
{
(uint8_t*)&PORTB, (uint8_t*)&PORTC, (uint8_t*)&PORTD,
};
PORTB is defined in the header file "avr/io.h" as this
#define PORTB _SFR_IO8 (0x05)
What I don't understand is the need of & in pointer array??
When I had compilation error when used lpc2148, I send a mail to the author and in his reply mail, he mentioned
Then it looks like your pointer arrays may not actually be pointers. For example:
(uint32_t*)&IOPIN0, (uint32_t*)&IOPIN1,
might actually be
(uint32_t*)IOPIN0, (uint32_t*)IOPIN1,
depending on how IOPIN0 and IOPIN1 are defined for your part
IOPIN0 macro for lpc2148 is
#define IOPIN0 (*((volatile unsigned long *) 0xE0028000))
I don't have much experience in C. I know if the macro refers to memory then I don't have to use & when defining pointer arrays. How to can I know if macro(eg: PORTB, IOPIN0) refers address or value??
SFR_IO8is and what it's doing to the value0x05.