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