David Kelly wrote:


The cleanest way to pull this off would be to lay a structure on the
memory-mapped device and allocate it in a named section. See
http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Variable- Attributes.html#Variable-Attributes

Then in the linking stage define the location of the FPGA something like
this in Makefile:

LDFLAGS= -Wl,-Map,[EMAIL PROTECTED] \
    -Wl,--section-start=.eeprom=0x00810001 \
    -Wl,--section-start=.fpga1=0x6000 \
    -Wl,--section-start=.hsa2d=0x7000 \
    -Wl,--section-start=.sram=0x2000

Just use the __attribute__ to tag variables as section .sram and the
compiler will find places for them if you don't care about the order.

... Depending on your definition of "cleanest way". ;-)

If the FPGA will be updating these memory locations indpendent of the code, then these will act a lot like processor registers. So, firstly, you'll want to make sure that these memory locations are marked as "volatile".

You can declare your variables similarly as registers are declared:

#include <stdint.h>
#define VARIABLE (*((volatile uint8_t *)0x1234))
...
VARIABLE = 0x01;
uint8_t foo = VARIABLE;

If you want to declare an array of uint8_t, then don't derefence the pointer in the definition:

#include <stdint.h>
#define VARIABLE ((volatile uint8_t *)0x1234)
...
VARIABLE[1] = 0x01;
uint8_t foo = VARIABLE[1];


HTH
Eric


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to