]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/timer.c
67b4a491018ee2d02507956f57274d8eec93dcf7
[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
29 timestamp++;
30
31 i = tick_10ms + 1;
32 if (i == 10) {
33 i = 0;
34 Stat |= S_10MS_TO;
35
36 /* Drive timer procedure of low level disk I/O module */
37 //disk_timerproc();
38 }
39 tick_10ms = i;
40
41 }
42
43
44
45 /*--------------------------------------------------------------------------*/
46
47 #if 0
48
49 void do_10ms(void)
50 {
51 if (to_counter)
52 to_counter--;
53 }
54
55 #endif
56
57 /*--------------------------------------------------------------------------*/
58
59
60 #if 0
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 }
74 #endif
75
76 uint32_t get_timer(uint32_t base)
77 {
78 uint32_t ret;
79
80 ATOMIC_BLOCK(ATOMIC_FORCEON)
81 {
82 ret = timestamp;
83 }
84 return ret - base;
85 }
86