Hi,
I am having a 324 byte,a 420 bytes of array stored in flash,now i am updating these array with 360 bytes. in fds_event_handler in the case FDS_EVT_WRITE i am reading flash again
static void fds_event_handler(fds_evt_t const * const p_fds_evt)
{
switch (p_fds_evt->id)
{
case FDS_EVT_INIT:
if (p_fds_evt->result != FDS_SUCCESS)
{
// Initialization failed.
}
break;
case FDS_EVT_WRITE:
if (p_fds_evt->result== FDS_SUCCESS)
{
read_from_flash();
write_flag = 1;
}
}
}
Ques: while reading i am getting last four or five rows values as zeros.
Suggestion: I am thinking that write event is not properly handled, means writing is not done properly.
Code for fds_read :
static ret_code_t fds_read(uint16_t record_read)
{
fds_flash_record_t flash_record;
fds_record_desc_t record_desc;
fds_find_token_t ftok ={0};//Important, make sure you zero init the ftok token
float *data;
uint32_t err_code;
if(PRINT_DEBUG)
{
NRF_LOG_PRINTF("Start searching... \r\n");
}
// Loop until all records with the given key and file ID have been found.
while (fds_record_find(FILE_ID, REC_KEY+record_read, &record_desc, &ftok) == FDS_SUCCESS)
{
printf("in read:\n");
err_code = fds_record_open(&record_desc, &flash_record);
if ( err_code != FDS_SUCCESS)
{
return err_code;
}
if(PRINT_DEBUG)
{
NRF_LOG_PRINTF("Found Record ID = %d reading record: %x,%d\r\n",record_desc.record_id,REC_KEY+record_read,record_read);
NRF_LOG_PRINTF("Data = ");
}
// Access the record through the flash_record structure.
data = (float *) flash_record.p_data;
int i=0;
for(int j=0; j<(flash_record.p_header->tl.length_words)/COLUMNS_FOR_MODEL;j++)
{
for(int k=0; k<COLUMNS_FOR_MODEL;k++,i++)
{
model[j][k] = data[i];
if(PRINT_DEBUG)
{
NRF_LOG_PRINTF("%f\t",model[j][k]);
}
}
}
update_model(model,record_read);
if(PRINT_DEBUG)
{
NRF_LOG_PRINTF("\r\n");
}
// Close the record when done.
err_code = fds_record_close(&record_desc);
if (err_code != FDS_SUCCESS)
{
return err_code;
}
return NRF_SUCCESS;
}
Code for fds_write:
static ret_code_t fds_write(float model_array[][3],uint16_t record_write,uint16_t size_of_model)
{
fds_find_token_t ftok
ftok.page=0;
ftok.p_addr=NULL;
fds_record_t record;
fds_record_desc_t record_desc;
fds_record_chunk_t record_chunk;
record_chunk.p_data = model_array;
record_chunk.length_words = size_of_model*3;
// Set up record.
record.file_id = FILE_ID;
record.key = REC_KEY+record_write;
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;
if(fds_record_find(FILE_ID, REC_KEY+record_write, &record_desc, &ftok) == FDS_SUCCESS)
{
fds_record_delete(&record_desc);
ret = fds_gc();
fds_record_update(&record_desc,&record);
}
NRF_LOG_PRINTF("%d\n",record_write);
return NRF_SUCCESS;
}
Using the same write code i am able to write into flash if i clear the flash first.and able to read also.
I just need that at run time Fds_write should update flash and fds_read able to read from flash properly after write and then other function should work.
Any help would be appreciated.