This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

External Array of Structure

Dear All,
I am using LPC2138 with LCD display and key pad, program down loader via URAT.
I have program and big chunk of messages stored in Array of Structure. Till now, I manage to compile whole thing and program and system works fine.
Now these messages to change in field so, I need to separate them, code and Message. I have two questions
1. How to define the structure ( data is not part of code) so that compiler/linker do not give problem and system can work as usual.
2. How to create the binary file of these message to copy in Flash.

I am thinking to program the message bin file after the end of program, using IAP routine of boot loader, the 1st page of Bin will details of each array to read at power up and init the variable to access these messages.

Thanks in advance.

  • From Net, I able to find the solution, it works for structure to defined in program but data are not part of program.
    /* eemap.h */
    struct CFG
    { char c; int i; long l; double d;};

    struct CAL
    { int scale; int offset; int slope;};

    struct LOG_ENTRY
    { long time; long meas;};

    typedef struct EE_MAP
    { struct CFG cfg; struct CAL cal; struct LOG_ENTRY log[1024];}EE_MAP;

    #define EE_ADDR_CFG(mbr) (offsetof(EE_MAP, cfg) + offsetof(struct CFG, mbr))
    #define EE_ADDR_CAL(mbr) (offsetof(EE_MAP, cal) + offsetof(struct CAL, mbr))
    #define EE_ADDR_LOG() (offsetof(EE_MAP, log))
    #define EE_ADDR_LOG_ENTRY(i) (EE_ADDR_LOG() + ((i) * sizeof(struct LOG_ENTRY)))

    Now to create the bin file to use, I have idea like this, which is C++ program which have complete data and save them in bin file which can be send to MCU on USB/UART to store in SPI flash or internal flash which is not program. while using them, either it can be copied in internal RAM or read in functions where it used directly.

    #include <fstream.h>
    #include <string.h>

    struct EE_MAP EE_DATA =
    { // Init data as per need
    } int main ( )
    { ofstream fout ; fout.open("Saving", ios :: out | ios :: binary) ; // open output file if(!fout) { cout << "File can't be opened \n" ; return 1; } fout.write((char *) & EE_DATA, sizeof(EE_MAP)) ; // write to file fout.close() ; // close connection // read it back now ifstream fin ; fin.open("Saving", ios :: out | ios :: binary) ; // open input file fin.read((char *) & EE_DATA, sizeof(EE_MAP)) ; // read structure fin.close( );
    }

    Any comments, please let me know or any better way. Just I am also looking what will be overhead of padding for my application with respect to without padding.

    Regards