I call the following function to delete old FDS records before I write a new record. It works well if I have only one old record. But when there are multiple records, it stops the application. RTT viewer shows it has gone through fds_record_delete() for each record, but only the oldest one is deleted. RTT viewer also prints fatal error, but my breakpoint in app_error.c is not called.
Here is the RTT viewer printout:
0> APP:INFO:Deleted record ID: 8
0> APP:INFO:Deleted record ID: 9
0> APP:INFO:Deleted record ID: 10
0> APP:INFO:Deleted record ID: 11
0> APP:INFO:Deleted record ID: 12
0> APP_ERROR:ERROR:Fatal
Here is the code:
static ret_code_t fds_test_find_and_delete (void)
{
#define FILE_ID 0x1111
#define REC_KEY 0x2222
fds_record_desc_t record_desc;
fds_find_token_t ftok;
ftok.page=0;
ftok.p_addr=NULL;
// Loop and find records with same ID and rec key and mark them as deleted.
while (fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok) == FDS_SUCCESS)
{
fds_record_delete(&record_desc);
NRF_LOG_INFO("Deleted record ID: %d \r\n",record_desc.record_id);
}
// call the garbage collector to empty them
ret_code_t ret = fds_gc();
if (ret != FDS_SUCCESS)
{
return ret;
}
return NRF_SUCCESS;
}
Another question is I see record ID counts up every time I write a new one. The old ID is not reused even the record is deleted. Is there an up limit for the count? What will happen if it counts to the limit?