avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Memory problem


From: David Kelly
Subject: Re: [avr-gcc-list] Memory problem
Date: Tue, 23 Jun 2009 08:22:59 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Jun 23, 2009 at 02:02:37AM -0700, Parthasaradhi Nayani wrote:
> --- On Tue, 6/23/09, Joerg Wunsch <address@hidden> wrote:
> 
> >The only method to not have the linker reorder your variables is to
> >just use a single variable (per memory section).? So, put some kind of
> >an "embracing" struct around all your variables you'd like to have in
> >a particular order, and you'll be done.
> 
> Thank you very much for your suggestion. In case I declare all the
> variables in a structure then accessing each variable will require
> using the structure name.variable name! However I would like to assign
> a memory to a variable also therefore can you suggest how I can do
> this? Thanks once again for your support.

Joerg listed two methods. One is that you declare one section per
variable and set the address in each section declaration. The second is
the observation that a struct counts as one variable and that the
contents of a struct are not reordered.

It wouldn't be a bad idea at all to put all your external flash
variables in a struct named flash if for no other reason than to remind
you they are in flash and require special treatment to write. No matter
you code "flash.variable" to access, the generated code is just the same
as had variable not been in a struct. OTOH if you use a pointer to the
flash struct, "flash->variable", then the code will grow unless the
compiler knows for certain that flash is constant.

Something like this might work for you:

typedef struct {
        uint8_t variable;
        uint16_t a, b, c, d;
        uint32_t e;
} FLASH_STRUCT;

#define flash_p ((FLASH_STRUCT *)(0x8000))


Then use flash_p->variable to access.

The con of this method is that that all accounting of flash use has to
be done manually by the code author.

-- 
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.




reply via email to

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