Copy Flash Param to structure in RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy Flash Param to structure in RAM

488 Views
DavidoBG
Contributor II

Hello,

I use  MC9S08QE8 and i reseved the first page like zone that contains parameters values.

Today,  at the start up i fill my structure (in RAM) to reading each octet Flash zone with Flash Module (see follow)

 

for(i=0;i<NbSegment;i++)
    {
       
        ParamCalibration.ValZ[i] =flash_read(CoefZ1+(i*2))<<8;
        ParamCalibration.ValZ[i] +=flash_read(CoefZ1+(i*2)+1);
       
        ParamCalibration.ValG[i] =flash_read(CoefG1+(i*2))<<8;
        ParamCalibration.ValG[i] +=flash_read(CoefG1+(i*2)+1);
       
        ParamCalibration.SegConvertPression[i] =flash_read(CoefSegCP+(i*2))<<8;
        ParamCalibration.SegConvertPression[i] +=flash_read(CoefSegCP+(i*2)+1);
       
         
    }

 

char flash_read(unsigned int address)
{
  unsigned char *pointer;
  pointer = (char*) address;
  return (*pointer);
}

 

But my structure is big and i would like if a specific code it is possible to fill my structure with one or two instruction of the kind:

struct{

byte param1

long param2

int param3

} MyStruct;

MyStruct = @0xE000;

 

Thanks a lot

David

Labels (1)
0 Kudos
Reply
1 Reply

388 Views
kef
Specialist I

I'm not sure if I understood your request. Do you want to initialize MyStruct from MyStruct at 0xE000? If so then you may

 

define MyStruct type to reduce some typing

 

typedef struct{

   byte param1;

   long param2;

   int param3;

} MyStructT;

 

Define MyStruct

 

MyStructT MyStruct;

 

Initialize MyStruct from data at 0xE000:

 

f()

{

   MyStruct = *(MyStructT*)0xE000;

}

 

0 Kudos
Reply