Skip to content

Commit ca08b58

Browse files
committed
Allow to separately specify block full threshold & compression chunk size
1 parent ef8553b commit ca08b58

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

firmware/nRF51/tag-proximity/inc/log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/* compression */
3535
#define FLASH_LOG_COMPRESSION 1
3636
#define COMPRESS_CHUNK_SIZE 256
37+
#define BLOCK_SPACE_MIN 256
3738

3839
/* flash storage */
3940
#define BLOCK_PAGES 8

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int flash_log_write(uint8_t flush_buf)
207207
/* proceed until there is data in the ring buffer
208208
and there is space in the block buffer */
209209
while ( (BUF_LEN(my_head,buf_tail) > 0) &&
210-
(LOG_BLOCK_DATA_SIZE - LogBlock.env.len > COMPRESS_CHUNK_SIZE) )
210+
(LOG_BLOCK_DATA_SIZE - LogBlock.env.len > BLOCK_SPACE_MIN) )
211211
{
212212
/* set the size of the next _contiguous_ chunk to compress */
213213
if (buf_tail < my_head)
@@ -226,6 +226,11 @@ static int flash_log_write(uint8_t flush_buf)
226226
if (sres < 0)
227227
goto cleanup;
228228

229+
/* advance tail of ring buffer */
230+
buf_tail += sink_sz;
231+
if (buf_tail >= buffer+BUF_SIZE)
232+
buf_tail -= BUF_SIZE;
233+
229234
/* pull out the compressed stream */
230235
do {
231236
pres = heatshrink_encoder_poll(
@@ -240,16 +245,11 @@ static int flash_log_write(uint8_t flush_buf)
240245
/* handle encoder error */
241246
if (pres < 0)
242247
goto cleanup;
243-
244-
/* advance tail of ring buffer */
245-
buf_tail += sink_sz;
246-
if (buf_tail >= buffer+BUF_SIZE)
247-
buf_tail -= BUF_SIZE;
248248
}
249249

250250
/* if block buffer is almost full, or if we are flushing the ring buffer,
251251
flush the encoder and commit compressed data to flash memory */
252-
if ( (LOG_BLOCK_DATA_SIZE - LogBlock.env.len <= COMPRESS_CHUNK_SIZE ) || flush_buf )
252+
if ( (LOG_BLOCK_DATA_SIZE - LogBlock.env.len <= BLOCK_SPACE_MIN ) || flush_buf )
253253
{
254254
/* signal encoder that we are done */
255255
fres = heatshrink_encoder_finish(&hse);

0 commit comments

Comments
 (0)