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