]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | */ | |
3 | ||
4 | #include "common.h" | |
5 | #include <avr/interrupt.h> | |
6 | #include <util/atomic.h> | |
7 | #include "time.h" | |
8 | #include "timer.h" | |
9 | ||
10 | /* timer interrupt/overflow counter */ | |
11 | /* counts up every ms. */ | |
12 | static volatile | |
13 | uint32_t timestamp; | |
14 | ||
15 | /*---------------------------------------------------------*/ | |
16 | /* 1000Hz timer interrupt generated by OC3A */ | |
17 | /*---------------------------------------------------------*/ | |
18 | ||
19 | ISR(TIMER3_COMPA_vect) | |
20 | { | |
21 | static int_fast8_t tick_10ms; | |
22 | static int_fast8_t tick_1s; | |
23 | int_fast8_t i, j; | |
24 | ||
25 | extern void disk_timerproc(void); | |
26 | ||
27 | timestamp++; | |
28 | ||
29 | i = tick_10ms + 1; | |
30 | if (i == 10) { | |
31 | Stat |= S_10MS_TO; | |
32 | ||
33 | /* Drive timer procedure of low level disk I/O module */ | |
34 | disk_timerproc(); | |
35 | ||
36 | j = tick_1s - 1; | |
37 | if (j == 0) { | |
38 | system_tick(); | |
39 | j = 100; | |
40 | } | |
41 | tick_1s = j; | |
42 | i = 0; | |
43 | } | |
44 | tick_10ms = i; | |
45 | } | |
46 | ||
47 | ||
48 | /*--------------------------------------------------------------------------*/ | |
49 | ||
50 | #if 0 | |
51 | void timer_setup(void) | |
52 | { | |
53 | ||
54 | /* Clock */ | |
55 | CLKPR = _BV(CLKPCE); | |
56 | CLKPR = 0; | |
57 | ||
58 | /* Timer */ | |
59 | ||
60 | OCR1A = F_CPU / 1000 - 1; // Timer1: 1000Hz interval (OC1A) | |
61 | TCCR1B = 0b00001001; | |
62 | TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt | |
63 | } | |
64 | #endif | |
65 | ||
66 | /*--------------------------------------------------------------------------*/ | |
67 | ||
68 | uint32_t get_timer(uint32_t base) | |
69 | { | |
70 | uint32_t ret; | |
71 | ATOMIC_BLOCK(ATOMIC_FORCEON) | |
72 | { | |
73 | ret = timestamp; | |
74 | } | |
75 | return ret - base; | |
76 | } |