nuclear@2: #include nuclear@2: #include nuclear@2: #include nuclear@2: #include "timer.h" nuclear@2: nuclear@2: #define PRESCL_256 4 nuclear@2: /* 256 ticks per interrupt, 256 clock divisor */ nuclear@2: #define TICKS_PER_SEC (F_CPU / 256 / 256) nuclear@2: nuclear@2: static volatile unsigned long ticks; nuclear@2: nuclear@2: void init_timer(void) nuclear@2: { nuclear@2: power_timer0_enable(); nuclear@2: nuclear@2: TCCR0A = 0; nuclear@2: TCCR0B = PRESCL_256; nuclear@2: nuclear@2: TIMSK0 |= (1 << TOIE0); /* enable ovf intr. */ nuclear@2: } nuclear@2: nuclear@2: void reset_timer(void) nuclear@2: { nuclear@2: ticks = 0; nuclear@2: } nuclear@2: nuclear@2: unsigned long get_msec(void) nuclear@2: { nuclear@2: return 1000 * ticks / TICKS_PER_SEC; nuclear@2: } nuclear@2: nuclear@2: ISR(TIMER0_OVF_vect) nuclear@2: { nuclear@2: ++ticks; nuclear@2: }