[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Structs in program memory.
From: |
Christian Ludlam |
Subject: |
Re: [avr-gcc-list] Structs in program memory. |
Date: |
Mon, 26 Apr 2004 22:16:25 +0100 |
User-agent: |
Messenger-Pro/1.00c (MsgServe/1.00a) (RISC-OS/5.05) POPstar/2.05 |
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] Structs in program memory., Douglas Dotson, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., E. Weddington, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., Douglas Dotson, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory.,
Christian Ludlam <=
- Re: [avr-gcc-list] Structs in program memory., Douglas Dotson, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., E. Weddington, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., Douglas Dotson, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., Christian Ludlam, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., Douglas Dotson, 2004/04/26
- Re: [avr-gcc-list] Structs in program memory., Joerg Wunsch, 2004/04/27
- Re: [avr-gcc-list] Structs in program memory., E. Weddington, 2004/04/27
- Re: [avr-gcc-list] Structs in program memory., Svein E. Seldal, 2004/04/27
- Re: [avr-gcc-list] Structs in program memory., E. Weddington, 2004/04/27
- Re: [avr-gcc-list] Structs in program memory., Artur Lipowski, 2004/04/28