Hi,
As i wrote in the topic, after calling pstorage_update I would like to check if the data was stored correctly. Can I call another pstorage_update in pstorage callback, if the data was corrupted?
For now the callback looks like this, but I can't make it work properly if I simulate an error:
void PStorage_SerialNumberRetVal_Handler(pstorage_handle_t * handle, uint8_t op_code, uint32_t result, uint8_t * p_data, uint32_t data_len)
{
switch(op_code)
{
case PSTORAGE_UPDATE_OP_CODE:
if (result == NRF_SUCCESS) // Check if the data were correctly flashed
{
// The max stored data lenght is for eventLog == sizeof(deviceState.eventlog_data)
uint8_t temp[8]={0}; // The table where I store loaded data from flash to validate them
uint8_t p_dataCheck[8] = {0}; //The table where I copy the data which were just stored in flash (for debug)
for(uint8_t i=0; i<8; i++)
{
p_dataCheck[i] = p_data[i]; // Copy the data which were just stored, for debug
}
pstorage_load(temp, handle, data_len, 0); // Read the data from flash
// Check if the data is correct
for(uint8_t i=0; i<data_len; i++)
{
if(p_dataCheck[i] != temp[i]) // If the data was corrupted
{
// return an error in order to try flashing the data again
pstorage_update(handle, p_dataCheck, data_len, 0);
for(uint16_t i=0; i<30000;i++) // Wait until the operation was completed
{}
break;
}
}
}
else
{
// Store operation failed.
}
// Source memory can now be reused or freed.
break;
default:
break;
}
}