]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/timer.c
Use timer 4 instead of 3 for systick (1ms).
[z180-stamp.git] / avr / timer.c
1 /*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7 #include "timer.h"
8 #include <avr/interrupt.h>
9 #include <util/atomic.h>
10 #include "time.h"
11
12 /* timer interrupt/overflow counter */
13 /* counts up every ms. */
14 static volatile
15 uint32_t timestamp;
16
17 /*
18 * 1000Hz timer interrupt generated by OC4A
19 */
20 ISR(TIMER4_COMPA_vect)
21 {
22 static int_fast8_t tick_10ms;
23 static int_fast8_t tick_1s;
24 int_fast8_t i, j;
25
26 extern void disk_timerproc(void);
27
28 OCR4A += F_CPU / 1000; /* 1000Hz interval */
29
30 timestamp++;
31
32 i = tick_10ms + 1;
33 if (i == 10) {
34 Stat |= S_10MS_TO;
35
36 /* Drive timer procedure of low level disk I/O module */
37 disk_timerproc();
38
39 j = tick_1s - 1;
40 if (j == 0) {
41 system_tick();
42 j = 100;
43 }
44 tick_1s = j;
45 i = 0;
46 }
47 tick_10ms = i;
48 }
49
50
51 /*--------------------------------------------------------------------------*/
52
53 uint32_t get_timer(uint32_t base)
54 {
55 uint32_t ret;
56 ATOMIC_BLOCK(ATOMIC_FORCEON)
57 {
58 ret = timestamp;
59 }
60 return ret - base;
61 }