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