Skip to content

Commit c70bdcd

Browse files
committed
Handle compression errors in a recoverable way
In case of errors during compression, we now clear the incoming ring buffer to allow flash logging to continue at the next iteration.
1 parent 292bdbe commit c70bdcd

File tree

1 file changed

+9
-8
lines changed
  • firmware/nRF51/tag-proximity/src

1 file changed

+9
-8
lines changed

firmware/nRF51/tag-proximity/src/log.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ static void flash_log_block_commit(void)
196196
void flash_log_write(uint8_t flush_buf)
197197
{
198198
uint8_t *my_head = buf_head;
199-
uint8_t *tail_copy = buf_tail;
200199
uint16_t chunk_size;
201200

202201
HSE_sink_res sres = 0;
@@ -245,12 +244,12 @@ void flash_log_write(uint8_t flush_buf)
245244
buf_tail -= BUF_SIZE;
246245
}
247246

248-
/* on error, bail out and revert buffer tail to original position */
247+
/* on error, clear the ring buffer and exit */
249248
if (pres < 0 || sres < 0)
250249
{
251250
log_compression_error++;
252251
status_flags |= ERROR_LOG_COMPRESS;
253-
buf_tail = tail_copy;
252+
buf_tail = my_head;
254253
return;
255254
}
256255

@@ -261,12 +260,12 @@ void flash_log_write(uint8_t flush_buf)
261260
/* signal encoder that we are done */
262261
fres = heatshrink_encoder_finish(&hse);
263262

264-
/* on error, bail out and revert buffer tail to original position */
263+
/* on error, clear the ring buffer and exit */
265264
if (fres < 0)
266265
{
267266
log_compression_error++;
268267
status_flags |= ERROR_LOG_COMPRESS;
269-
buf_tail = tail_copy;
268+
buf_tail = my_head;
270269
return;
271270
}
272271

@@ -282,22 +281,24 @@ void flash_log_write(uint8_t flush_buf)
282281

283282
/* update block length */
284283
LogBlock.env.len += poll_sz;
284+
285+
/* on block buffer overflow, clear the ring buffer and exit */
285286
if (LogBlock.env.len >= LOG_BLOCK_DATA_SIZE)
286287
{
287288
log_compression_error++;
288289
status_flags |= ERROR_LOG_COMPRESS;
289-
buf_tail = tail_copy;
290+
buf_tail = my_head;
290291
return;
291292
}
292293
} while (pres == HSER_POLL_MORE);
293294
}
294295

295-
/* on error, bail out and revert buffer tail to original position */
296+
/* on error, clear the ring buffer and exit */
296297
if (pres < 0)
297298
{
298299
log_compression_error++;
299300
status_flags |= ERROR_LOG_COMPRESS;
300-
buf_tail = tail_copy;
301+
buf_tail = my_head;
301302
return;
302303
}
303304

0 commit comments

Comments
 (0)