[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?
From: |
David Kelly |
Subject: |
Re: [avr-gcc-list] Initilizing complex const arrays : syntax ? |
Date: |
Sun, 18 Sep 2005 08:12:23 -0500 |
On Sep 18, 2005, at 3:07 AM, Anton Erasmus wrote:
The problem with this using avr-gcc, is that the data is stored in
RAM,
and not in FLASH. This makes the use of these sorts of structures much
more problematical. In order to access any data in flash using avr-
gcc,
one needs in essence to get a pointer that points to the specific data
one wants to read.
*Could* do it that way but there is no point in making extra
pointers. This way requires special handling to pull the data out of
the structure, PSTR(), or use the _P functions in avr-libc. Of what I
have seen avr-gcc reads data out of progmem exactly as efficiently as
from RAM. May be wait states involved but thats splitting hairs.
#include <avr/pgmspace.h>
//data type for one engine parameter
struct param {
char desc[12];
char unit[4];
char format[6];
};
struct param __ATTR_PROGMEM__ param_list[] = {
{ "Engine Spd", "RPM", "%4d" },
{ "Coolant Tmp", " °C", "%3.1f" },
{ "Turbo Pres.", "Bar", "%2.1" },
{ "", "", "" },
};
void main(void)
{
while(1) {
}
}
Above built and disassembly verified with the Makefile I sent Vincent
a while back.
One surprise to watch out for, avr-gcc will stuff the array to
capacity and silently drop the automatic \0 if it doesn't fit.
Because we are not storing pointers in the structure but actually
stuffing the data into fixed size arrays, NULL wasn't an appropriate
termination "string." In the above param[n].dest[0] == 0 for n = 3.
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.
- [avr-gcc-list] Initilizing complex const arrays : syntax ?, Vincent Trouilliez, 2005/09/17
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Royce Pereira, 2005/09/17
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Jesper Hansen, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Anton Erasmus, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Jesper Hansen, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Anton Erasmus, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Vincent Trouilliez, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Jesper Hansen, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, David Kelly, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Vincent Trouilliez, 2005/09/18
- Re: [avr-gcc-list] Initilizing complex const arrays : syntax ?, Vincent Trouilliez, 2005/09/18