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=d1f1b2300bfe7e05233481948947fea330130b77;hp=f0d7d9350f59abb301bf131c54414d6ffb44028b;hb=90ffd122f4387d18e8d7cf7d2a507c719409d4e5;hpb=210916486d18b3dc976c65c7b01b44bca446d856 diff --git a/firmware/tmr.c b/firmware/tmr.c index f0d7d93..d1f1b23 100644 --- a/firmware/tmr.c +++ b/firmware/tmr.c @@ -1,40 +1,29 @@ #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; + WDTCR = _BV(WDIE) | _BV(WDP1); // 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(); + 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(); }