]> www.fi.muni.cz Git - bike-lights.git/blob - firmware/tmr.c
tmr.c: combine watchdog IRQ and watchdog reset
[bike-lights.git] / firmware / tmr.c
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3 #include <avr/wdt.h>
4
5 #include "lights.h"
6
7 volatile uint16_t jiffies;
8
9 void init_tmr()
10 {
11         wdt_enable(WDTO_60MS);
12         WDTCR |= _BV(WDIE); // interrupt mode, 64 ms
13 }
14
15 void susp_tmr()
16 {
17         wdt_disable();
18 }
19
20 ISR(WDT_vect) {
21         ++jiffies;
22
23         timer_check_buttons();
24         patterns_next_tick();
25         timer_start_slow_adcs();
26
27         if ((jiffies & 0x7FF) == 0)
28                 ambient_log_min_max();
29
30         WDTCR |= _BV(WDIE); // avoid WDT reset next time
31 }
32