]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/tmr.c
firmware source moved into subdirectory
[bike-lights.git] / firmware / tmr.c
diff --git a/firmware/tmr.c b/firmware/tmr.c
new file mode 100644 (file)
index 0000000..5a44037
--- /dev/null
@@ -0,0 +1,33 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#include "lights.h"
+
+volatile uint16_t jiffies;
+#define PATTERN_DIV 5  // clk/10
+static unsigned char pattern_div;
+
+void init_tmr()
+{
+       TCCR0A = _BV(WGM00);
+       TCCR0B = _BV(CS02) | _BV(CS00); // CLK/1024 = 1 kHz
+       OCR0A = 10; // 100 Hz
+       TIMSK |= _BV(OCIE0A);
+
+       jiffies = 0;
+       pattern_div = PATTERN_DIV;
+}
+
+ISR(TIMER0_COMPA_vect)
+{
+       ++jiffies;
+
+       if (--pattern_div == 0) {
+               timer_check_buttons();
+               patterns_next_tick();
+               pattern_div = PATTERN_DIV;
+       }
+
+       timer_start_adcs();
+}
+