]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/timer.c
VT100/ANSI parser
[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>
d684c216
L
7#include "timer.h"
8
9/* timer interrupt/overflow counter */
289c3252
L
10/* counts up every ms. */
11static volatile
12uint32_t timestamp;
d684c216
L
13
14/*---------------------------------------------------------*/
41d36f28 15/* 1000Hz timer interrupt generated by OC3A */
d684c216
L
16/*---------------------------------------------------------*/
17
41d36f28 18ISR(TIMER3_COMPA_vect)
d684c216
L
19{
20 static int_fast8_t tick_10ms;
21 int_fast8_t i;
22
7f552300 23 extern void disk_timerproc(void);
d684c216
L
24
25 timestamp++;
26
27 i = tick_10ms + 1;
28 if (i == 10) {
29 i = 0;
30 Stat |= S_10MS_TO;
68e463ad 31
d684c216 32 /* Drive timer procedure of low level disk I/O module */
7f552300 33 disk_timerproc();
d684c216
L
34 }
35 tick_10ms = i;
d684c216
L
36}
37
38
d684c216
L
39/*--------------------------------------------------------------------------*/
40
68e463ad 41#if 0
d684c216
L
42void 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}
68e463ad 55#endif
d684c216 56
289c3252
L
57/*--------------------------------------------------------------------------*/
58
d684c216
L
59uint32_t get_timer(uint32_t base)
60{
61 uint32_t ret;
d684c216
L
62 ATOMIC_BLOCK(ATOMIC_FORCEON)
63 {
64 ret = timestamp;
65 }
66 return ret - base;
67}