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