+#define LOG_BUFFER 64
+uint16_t log_buffer[LOG_BUFFER] EEMEM;
+unsigned char log_buffer_count;
+uint16_t log_buffer2[LOG_BUFFER];
+volatile unsigned char stop = 0;
+
+static void inline init_log()
+{
+ debug_setstate(1);
+ log_buffer_count = 0;
+}
+
+static void log_word(uint16_t word) {
+ if (log_buffer_count >= LOG_BUFFER)
+ return;
+
+ // eeprom_write_word(&log_buffer[log_buffer_count], word);
+ log_buffer2[log_buffer_count] = word;
+ log_buffer_count++;
+
+ if (log_buffer_count == LOG_BUFFER) {
+ unsigned char i;
+ for (i=0; i < LOG_BUFFER; i++) {
+ eeprom_write_word(&log_buffer[i],
+ log_buffer2[i]);
+ }
+ debug_setstate(0x42);
+ }
+}
+
+/* ------------ Timer ----------- */
+
+volatile uint16_t jiffies = 0;
+
+static void inline init_tmr()
+{
+ TCCR0A = _BV(WGM00);
+ TCCR0B = _BV(CS02) | _BV(CS00); // 1 kHz
+ OCR0A = 12; // 100 Hz
+ TIMSK |= _BV(OCIE0A);
+ DDRA |= _BV( PA0 );
+
+ jiffies = 0;
+}
+
+static void inline tmr_handler()