From 4db795a97ff9bf1d859b797242df8f4564231f82 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Wed, 29 Aug 2012 17:08:51 +0200 Subject: [PATCH] logging: allow multiple flushes --- logging.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/logging.c b/logging.c index 0ade201..05716bf 100644 --- a/logging.c +++ b/logging.c @@ -13,6 +13,7 @@ static unsigned char log_state EEMEM; /* Upper 4 bits are reset count, lower 4 bits are reset reason from MCUSR */ static unsigned char reboot_count EEMEM = 0; static unsigned char can_write_eeprom = 0; +static uint16_t flushed_end; void log_set_state(unsigned char val) { @@ -40,6 +41,7 @@ void log_init() log_set_state(1); log_buffer_count = 0; + flushed_end = 0; } void log_byte(unsigned char byte) { @@ -61,16 +63,18 @@ void log_word(uint16_t word) { void log_flush() { unsigned char i; - log_buffer_count = LOG_BUFFER; - if (!can_write_eeprom) return; - for (i=0; i < LOG_BUFFER; i++) { + for (i=flushed_end; i < log_buffer_count; i++) { eeprom_write_byte(&log_buffer_ee[i], log_buffer[i]); } - log_set_state(0x42); + + flushed_end = i; + + if (flushed_end == LOG_BUFFER) + log_set_state(0x42); } #endif -- 2.39.3