avr-chat
[Top][All Lists]
Advanced

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

[avr-chat] Array of sctructs in flash - getting the address of an elemen


From: Bob von Knobloch
Subject: [avr-chat] Array of sctructs in flash - getting the address of an element
Date: Mon, 10 Sep 2012 15:16:12 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100520 SUSE/3.0.5 Thunderbird/3.0.5

Hi,

I am working on a simple menu system which consists of an array of
struct containing command name,  a pointer to a function and an
information string:

struct ctl
    {
    char cmdname[10];
    void* func;
    char cmdhelp[];
    } menu[]    PROGMEM =   {
{"?",       welcome,    "                        help\n"},
{"dump",    hexdump,    " src [addr]          Dump memory\n"},
{"ihex",    ihexload,   "                     Download hex file\n"},
};

This array is in program memory.
To access an element (e.g. cmdname in the second element) I need it's
address (as I can only use pgm_read_byte(addr) to access it).
so far I have not been able to extract the address of such an element using:

pgm_read_byte(&menu[1].cmdname[0]);

The zero'th element works OK (it is the name of the array), but
subsequent array indexes are incorrect (a number of bytes wrong).

The third element of the struct is not dimensioned and is set by the
length of the strings, is this preventing the compiler from calculating
the correct address?

Normally the access systems to such elements are over arrow or dot
methods, but Harvard architecture prevents this.

Would appreciate any thoughts.

Cheers,

Bob

-- 
The Sun is out, the sky is blue. It's time to drive the MR2.



reply via email to

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