A pointer to one structure (or int, float, or something else) is essentially a pointer to an array of them. The pointer type provides the sizeof () value for writing the array, and thus allows you to work with pointer arithmetic.
So with a struct buffer you can just do
static struct buffer * const myFIFO = (struct buffer *) 0x40000
and then just access myFIFO as an array
for (size_t i = 0; i < maxPackets; ++i) { buffer[i].someField = initialValue1; buffer[i].someOtherField = 42; }
It works as you expect.
What you cannot do (using the pure C standard) declares an array at a specific address like this:
struct buffer myFIFO[23] @ 0x400000;
However, your compiler may have extensions to enable this. Many built-in compilers do (after all, often how they declare memory-mapped device registers), but they will be different for each compiler provider and, possibly, for each chip, as this is a vendor extension.
GCC allows you to use it for AVR processors through an attribute, for example
volatile int porta __attribute__((address (0x600)));
But he does not support it for ARM.
kdopen
source share