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

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

Re: [avr-gcc-list] Structs in program memory.


From: Douglas Dotson
Subject: Re: [avr-gcc-list] Structs in program memory.
Date: Mon, 26 Apr 2004 15:57:21 -0700 (PDT)

Christian,

Thanks for the info. Too bad it isn't a bit more
seamless. Would be nice to be able to switch back
and forth from RAM to PROGMEM without rewriting 
code. I guess I can accomplish that using macros,
but that's kind of ugly.

Doug

--- Christian Ludlam <address@hidden> wrote:
> On 26 Apr Douglas Dotson wrote:
> 
> > Might work. I have a table-drive user interface
> > that requires lots of initialize structs. The only
> > thing I worry about is that the size of the tables
> > may eventually exceed the available EEPROM space.
> > I'd rather just put them in program memory and
> > that way I don't have to worry about hitting the
> > wall someday. They are never modified on the fly
> > so program memory seems more appropriate.
> 
> There's no problem with putting them in program
> memory, just declare them
> with the progmem attribute, ie
> 
> #include <avr/pgmspace.h>
> 
> struct foo bar PROGMEM = 
> {
>     1; 2; 3;  
> };
> 
> 
> Reading them is slightly trickier since you can't do
> this:
> 
>     value = bar.one;
>     
> instead, you need to do
>  
>     value = pgm_read_byte(&bar.one);
> 
> 
> Another thing to remember is that you can't
> initialise with literal strings
> intended for program memory, you have to define them
> separately, ie
> 
> static const char string[] PROGMEM = "Hello,
> World!";
> 
> struct baz bar PROGMEM =
> {
>     1; 2; string; 
> };
> 
> and not
> 
> struct baz bar PROGMEM = 
> {
>     1; 2; "Hello, World!";
> };
> 
> 
> I wrote a menu system using this a while ago, so
> it's perfectly doable.
> There's probably more information on doing this in
> the FAQ, and certainly in
> the avr-libc manual.
> 
> 
> HTH,
> 
> -- 
> Christian Ludlam
> address@hidden
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

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