I have written two methods to read and write value from fds.I get FDS_EVT_WRITE call back with p_fds_evt->result=!= FDS_SUCCESS
but when i try to read it after that it gives me value 0 always.
Here is program that i have used
void fds_write(uint32_t file_id,uint32_t record_key,int32_t value){
fds_gc();
int32_t m_deadbeef = value;
/* printf ("record key : = %d",record_key);
printf ("file id : = %d",file_id);
printf ("value : = %d",m_deadbeef);*/
static char const m_hello[] = "Hello, world!";
fds_record_t record;
fds_record_desc_t record_desc;
fds_find_token_t ftok={};
// Set up record.
record.file_id = FILE_ID;
record.key = record_key;
record.data.p_data = &m_deadbeef;
record.data.length_words = 1; // one word is four bytes.
ret_code_t rc;
if(fds_record_find(FILE_ID, record_key, &record_desc, &ftok) == FDS_SUCCESS){
rc = fds_record_update(&record_desc, &record);
printf("\nupdate\n");
}else{
rc = fds_record_write(&record_desc, &record);
printf("\nwriting\n");
}
if (rc == FDS_SUCCESS)
{
// SEGGER_RTT_printf(0,"s");
}
else{
printf("\n problem in writing\n");
}
}
int fds_read(uint32_t file_id,uint32_t record_key){
fds_gc();
fds_flash_record_t flash_record2;
fds_record_desc_t record_desc2;
fds_find_token_t ftok2={};
//uint32_t *data;
int8_t *data;
uint32_t err_code;
// Loop until all records with the given key and file ID have been found.
while (fds_record_find_in_file(file_id, &record_desc2, &ftok2) == FDS_SUCCESS)
{
err_code = fds_record_open(&record_desc2, &flash_record2);
if ( err_code != FDS_SUCCESS)
{
printf("error in opening file");
}
printf("Found Record ID for %d = %d \r\n",record_key,record_desc2.record_id);
data = (char *) flash_record2.p_data;
printf("\n DATA PRINTING \n");
for(int k=0;k<=sizeof(data);k++){
printf( "%d --> %d ,",k, data[k]);
}
for (uint8_t i=0;i<flash_record2.p_header->length_words;i++)
{
printf("0x%8x",data[i]);
}
printf("\r\n");
// Access the record through the flash_record structure.
// Close the record when done.
err_code = fds_record_close(&record_desc2);
if (err_code != FDS_SUCCESS)
{
printf("error in closing file");
}
}
//return(data[0]);
return(data[0]);
}