opentvc
time.h
1 #ifndef TIME_H
2 #define TIME_H
3 
4 #include <avr/io.h>
5 #include <avr/interrupt.h>
6 #include <util/atomic.h>
7 
8 
9 // the prescaler is set so that timer0 ticks every 64 clock cycles, and the
10 // the overflow handler is called every 256 ticks.
11 #define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
12 // the whole number of milliseconds per timer0 overflow
13 #define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
14 
15 // the fractional number of milliseconds per timer0 overflow. we shift right
16 // by three to fit these numbers into a byte. (for the clock speeds we care
17 // about - 8 and 16 MHz - this doesn't lose precision.)
18 #define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
19 #define FRACT_MAX (1000 >> 3)
20 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
21 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
22 
23 volatile unsigned long timer0_overflow_count = 0;
24 volatile unsigned long timer0_millis = 0;
25 
26 static unsigned char timer0_fract = 0;
27 volatile unsigned long m;
28 volatile unsigned long f;
29 
30 void init_micros(void);
31 unsigned long micros(void);
32 
33 #endif // TIME_H
void init_micros(void)
Definition: time.c:23
unsigned long micros(void)
Definition: time.c:31