Hello -
If you have the address where you wrote the data you can dereference a pointer to the data.
eg.
myInteger = *((int *)0x00104000);
Here's some contrived examples...
Example 1
Code:
// Assumes the following prototype
void WriteFlash( void *src_, void *dst_, unsigned int len_ );
void foo( void )
{
int myInteger = 10000;
// Store the integer into flash at address 0x00104000
WriteFlash( &myInteger,
(void *)0x00104000,
sizeof( int ) );
// Verify that the ram copy matches the flash copy
if( myInteger == *((int *)0x00104000) )
{
// ...
}
}
Example 2 (struct's)
Code:
// Assumes the following prototype
void WriteFlash( void *src_, void *dst_, unsigned int len_ );
typedef struct
{
bool isConfigured;
float setPoint;
unsigned int counter;
}ParameterStruct;
const ParameterStruct *pFlashParamsAddr = (ParameterStruct *)0x00104000;
static ParameterStruct ramcopyParams;
void foo( void )
{
// Initialize ram struct
ramcopyParams.isConfigured = true;
ramcopyParams.setPoint = 10.25f;
ramcopyParams.counter = 10000;
// Write all params to flash
WriteFlash( &ramcopyParams,
pFlashParamsAddr,
sizeof( ParameterStruct ) );
// Verify that the ram copy matches the flash copy
if( ramcopyParams.isConfigured == pFlashParamsAddr->isConfigured )
{
// ...
}
if( ramcopyParams.setPoint == pFlashParamsAddr->setPoint )
{
// ...
}
if( ramcopyParams.counter == pFlashParamsAddr->counter )
{
// ...
}
}
Example 3
Code:
// Assumes the following prototype
void WriteFlash( void *src_, void *dst_, sizeof len_ );
// Flash addresses for parameters
const bool *pFlashIsConfigured = (bool *)0x00104000;
const float *pFlashSetPoint = (float *)(0x00104000 + 1);
const unsigned int *pFlashCounter = (unsigned int *)(0x00104000 + 1 + 4);
static bool isConfigured;
static float setPoint;
static unsigned int counter;
void foo( void )
{
// Initialize parameters
isConfigured = true;
setPoint = 10.25f;
counter = 10000;
// Write parameters to flash
WriteFlash( &isConfigured,
pFlashIsConfigured,
sizeof( bool ) );
WriteFlash( &setPoint,
pFlashSetPoint,
sizeof( float ) );
WriteFlash( &counter,
pFlashCounter,
sizeof( unsigned int ) );
// Compare the ram copies to the stored flash copies
if( isConfigured == *pFlashIsConfigured )
{
// ...
}
if( setPoint == *pFlashSetPoint )
{
// ...
}
if( counter == *pFlashCounter )
{
// ...
}
}
Note: You will want to reserve a block of flash for your parameters via your linker definition file.
My pref is the struct with a data integrity value, I also like to get the address from the linker instead of hard coding it into the source...
Regards,