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));
43 void log_init() { log_init_common(); }
46 void log_byte(unsigned char byte)
51 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
52 buffer_ram[buffer_ram_ptr++] = byte;
54 if (buffer_ram_ptr >= LOG_RAM_BUF_SIZE)
59 void log_word(uint16_t word)
64 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
65 log_byte(word & 0xFF);
77 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
78 for (i = 0; i < buffer_ram_ptr; i++) {
79 eeprom_write_byte(&buffer_ee[buffer_ee_ptr++],
82 if (buffer_ee_ptr >= LOG_EE_BUF_SIZE) {