4 #include <avr/eeprom.h>
5 #include <util/atomic.h>
9 static unsigned char buffer_ee[LOG_EE_BUF_SIZE] EEMEM;
10 static unsigned char buffer_ram[LOG_RAM_BUF_SIZE];
12 static unsigned char buffer_ram_ptr, buffer_ee_ptr;
13 static unsigned char log_enabled = 0;
15 static void inline log_init_common()
22 #ifdef LOG_RATELIMIT_BOOTCOUNT
23 static unsigned char reboot_count EEMEM;
27 unsigned char r_count;
29 r_count = eeprom_read_byte(&reboot_count);
32 if (r_count < LOG_RATELIMIT_BOOTCOUNT) {
34 eeprom_write_byte(&reboot_count,
35 (r_count << 4) | (MCUSR & 0xF));
40 void log_init() { log_init_common(); }
43 void log_byte(unsigned char byte)
48 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
49 buffer_ram[buffer_ram_ptr++] = byte;
51 if (buffer_ram_ptr >= LOG_RAM_BUF_SIZE)
56 void log_word(uint16_t word)
61 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
62 log_byte(word & 0xFF);
74 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
75 for (i = 0; i < buffer_ram_ptr; i++) {
76 eeprom_write_byte(&buffer_ee[buffer_ee_ptr++],
79 if (buffer_ee_ptr >= LOG_EE_BUF_SIZE) {