2 #include <avr/interrupt.h>
5 #define BIT(n) (1<<(n))
7 static TimerCallback *timer_callback;
9 void timer_init(uint16_t freq_p, uint8_t freq_q)
11 uint32_t period = F_CPU*freq_q/freq_p;
18 else if(period<0x80000)
23 else if(period<0x400000)
25 cs = BIT(CS11) | BIT(CS10);
28 else if(period<0x1000000)
35 cs = BIT(CS12) | BIT(CS10);
41 TCCR1B = BIT(WGM12) | cs;
46 void timer_set_callback(TimerCallback *cb)
49 TIMSK1 |= BIT(OCIE1A);
52 ISR(TIMER1_COMPA_vect)