]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/tmr.c
firmware source moved into subdirectory
[bike-lights.git] / firmware / tmr.c
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3
4 #include "lights.h"
5
6 volatile uint16_t jiffies;
7 #define PATTERN_DIV 5   // clk/10
8 static unsigned char pattern_div;
9
10 void init_tmr()
11 {
12         TCCR0A = _BV(WGM00);
13         TCCR0B = _BV(CS02) | _BV(CS00); // CLK/1024 = 1 kHz
14         OCR0A = 10; // 100 Hz
15         TIMSK |= _BV(OCIE0A);
16
17         jiffies = 0;
18         pattern_div = PATTERN_DIV;
19 }
20
21 ISR(TIMER0_COMPA_vect)
22 {
23         ++jiffies;
24
25         if (--pattern_div == 0) {
26                 timer_check_buttons();
27                 patterns_next_tick();
28                 pattern_div = PATTERN_DIV;
29         }
30
31         timer_start_adcs();
32 }
33