[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] specific SRAM locations.

From: Ned Konz
Subject: Re: [avr-gcc-list] specific SRAM locations.
Date: Sat, 8 Apr 2006 23:20:43 -0700

On Apr 8, 2006, at 1:56 PM, Dave Lamont wrote:

I need to allocate specific SRAM locations to some global variables. The quantities in these reserved SRAM locations are passed from the microprocessor back to a

My previous compiler allowed me to specify as follows

int sat_bearing @0x180;


struct x {int a;
            char c;
            } alfa @0x185;

That's not Standard C, but there are at least three ways that I can think of that you can do this:

* Do what the avr-libc folks do, and make the name a #define for an anonymous object (what in C++ would be referred to as a "reference"):

#define sat_bearing (*(int *)(void*)(0x180))
#define alfa (*(struct x*)(void*)(0x185))

then you can say things like:

sat_bearing = 30;
alfa.c = 'f';

* Use a custom linker script that specifies these locations explicitly, and use an "extern" statement in C:

alfa = 0x800185;
sat_bearing = 0x800180;

extern int sat_bearing;
extern struct x alfa;

* use a custom linker script that names the interesting sections and use the GDB attribute((__section__)) on the variables. I forget the exact syntax for this, but you basically just have fixed-address sections (defined inside the SECTION directive in your linker definition file) that you then use to refer to from C:

int sat_bearing __attribute__((__section__=myAttribute));

Ned Konz
MetaMagix embedded consulting

reply via email to

[Prev in Thread] Current Thread [Next in Thread]