4 #include <avr/eeprom.h>
9 static unsigned char log_buffer_ee[LOG_BUFFER] EEMEM;
10 static unsigned char log_buffer_count;
11 static unsigned char log_buffer[LOG_BUFFER];
12 static unsigned char log_state EEMEM;
13 /* Upper 4 bits are reset count, lower 4 bits are reset reason from MCUSR */
14 static unsigned char reboot_count EEMEM = 0;
15 static unsigned char can_write_eeprom = 0;
16 static uint16_t flushed_end;
18 void log_set_state(unsigned char val)
21 eeprom_write_byte(&log_state, val);
26 unsigned char r_count;
28 r_count = eeprom_read_byte(&reboot_count);
33 eeprom_write_byte(&reboot_count,
34 (r_count << 4) | (MCUSR & 0xF));
38 //eeprom_write_byte(&log_state, 0xFF);
47 void log_byte(unsigned char byte) {
48 if (log_buffer_count >= LOG_BUFFER)
51 // eeprom_write_word(&log_buffer[log_buffer_count], word);
52 log_buffer[log_buffer_count++] = byte;
54 if (log_buffer_count == LOG_BUFFER)
58 void log_word(uint16_t word) {
59 log_byte(word & 0xFF);
66 if (!can_write_eeprom)
69 for (i=flushed_end; i < log_buffer_count; i++) {
70 eeprom_write_byte(&log_buffer_ee[i],
76 if (flushed_end == LOG_BUFFER)