]> www.fi.muni.cz Git - bike-lights.git/commitdiff
log reset reason
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 29 Aug 2012 10:46:24 +0000 (12:46 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 29 Aug 2012 10:46:24 +0000 (12:46 +0200)
logging.c

index 5c5beeb30848f4fd4895a10474cd56c93f705d39..0ade2010ffc61e19b1a52d65b13df2b06fae20a2 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -10,6 +10,7 @@ static unsigned char log_buffer_ee[LOG_BUFFER] EEMEM;
 static unsigned char log_buffer_count;
 static unsigned char log_buffer[LOG_BUFFER];
 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;
 
@@ -24,10 +25,13 @@ void log_init()
        unsigned char r_count;
 
        r_count = eeprom_read_byte(&reboot_count);
+       r_count >>= 4;
 
        if (r_count < 5) {
                r_count++;
-               eeprom_write_byte(&reboot_count, r_count);
+               eeprom_write_byte(&reboot_count,
+                       (r_count << 4) | (MCUSR & 0xF));
+               MCUSR = 0;
                can_write_eeprom = 1;
        } else {
                //eeprom_write_byte(&log_state, 0xFF);