X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Ftmr.c;h=7a31f19e486e2ab5edd720d36f5ea88255e273e5;hp=37b240b5d65245898722036d00f740ad322b1350;hb=65c3ad96cf307c3b77b36e6f6a2af5201c213a3c;hpb=6193f6a3200efa660bbbe406e317fe7fa0473de0 diff --git a/firmware/tmr.c b/firmware/tmr.c index 37b240b..7a31f19 100644 --- a/firmware/tmr.c +++ b/firmware/tmr.c @@ -1,42 +1,33 @@ #include #include +#include #include "lights.h" volatile uint16_t jiffies; -#define PATTERN_DIV 10 // clk/10 -static unsigned char pattern_div; void init_tmr() { - TCCR0A = _BV(WGM00); - TCCR0B = _BV(CS02) | _BV(CS00); // CLK/1024 = 1 kHz - OCR0A = 5; // 200 Hz - TIMSK |= _BV(OCIE0A); - - jiffies = 0; - pattern_div = PATTERN_DIV; + wdt_enable(WDTO_60MS); + WDTCR |= _BV(WDIE); // interrupt mode, 64 ms } void susp_tmr() { - TCCR0A = TCCR0B = 0; - TIMSK &= ~_BV(OCIE0A); - TIFR = 0; + wdt_disable(); } -ISR(TIMER0_COMPA_vect) -{ +ISR(WDT_vect) { ++jiffies; - pwm_timer(); + timer_check_buttons(); + patterns_next_tick(); + pwm_disable_if_not_needed(); + timer_start_slow_adcs(); - if (--pattern_div == 0) { - timer_check_buttons(); - patterns_next_tick(); - pattern_div = PATTERN_DIV; - } + if ((jiffies & 0x7FF) == 0) + ambient_log_min_max(); - timer_start_adcs(); + WDTCR |= _BV(WDIE); // avoid WDT reset next time }