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