[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Access to array of struct in flash
From: |
Daniel Williamson |
Subject: |
RE: [avr-gcc-list] Access to array of struct in flash |
Date: |
Wed, 30 Jul 2003 16:03:51 +0100 |
I've been using these Defined functions for reading memory, It is then as
simple as calling PRG_RDW(&ps->min) to pull out a word from flash.
there's also PRG_RDL for Longs.
I can't remember where they were from it was either this list or AVR FREAKS.
However, they do work and that's good enough for me. Shame they are not
included in the gcc package.
hope this helps.
Dan
-----Original Message-----
From: address@hidden
[mailto:address@hidden Behalf Of address@hidden
Sent: 30 July 2003 14:46
To: avr-gcc-list
Subject: [avr-gcc-list] Access to array of struct in flash
Hello all,
I have a question on how convert C code.
In the past I have written a lot of functions with heavy use of array of
structure to do the job. The target CPU was Motorola 683XX.
All arrays were constat.
The code look like
...
struct mystruct
{
char* msg;
short Min;
short Max;
short default;
void (*pfunction)( short i );
.....
};
...
const struct mystruct example[ ] =
{
"Value 1", 10, 500, 100, Control,
"Value 2", 50, 2500, 50, Control,
"Value 3", 10, 500, 100, Control,
"Value 4", 10, 500, 100, Control,
...
};
...
const struct mystruct * ps = example;
...
if( ps->msg != NULL )
DisplayMessage( ps->msg );
...
if( ( value < ps->Min )||( value > ps->Max ) )
value = ps->default;
...
if( ps->pfunction != NULL )
( ps->pfunction )( index );
...
and so on.
Now I'm porting this code to AVR ATmega128.
I'have converted some functions in this way:
...
const struct mystruct PROGMEM example[ ] =
{
"Value 1", 10, 500, 100, Control,
"Value 2", 50, 2500, 50, Control,
"Value 3", 10, 500, 100, Control,
"Value 4", 10, 500, 100, Control,
...
};
...
typedefs unsigned short word;
word GetPRGWord( word add )
{
word w = PRG_RDB( add );
w += ( PRG_RDB( ++add ) << 8 );
return w;
}
....
const struct mystruct * ps = example;
word msg = GetPRGWord( (word)&ps->msg );
if( (void*)msg != NULL )
DisplayMessage( (char*)msg );
word Min = GetPRGWord( (word)&ps->Min );
word Max = GetPRGWord( (word)&ps->Max );
word default = GetPRGWord( (word)&ps->default );
...
if( ( value < Min )||( value > Max ) )
value = default;
...
word pfunction = GetPRGWord( (word)&ps->pfunction );
if( (void*)pfunction != NULL )
( ( void(*)( short ) ) pfunction )( index );
...
and so on.
The converted functions work, but it is not good; and the conversion takes
a lot of time and can introduce errors.
How is possible to convert the code is a simpler and better way, reducing to
minimum the modification of original code ?
Thanks in advance
Patrizio Zelotti
address@hidden
_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list
prg_rd_wlp.h
Description: Binary data