summaryrefslogtreecommitdiff
path: root/avr/timer.c
blob: e15a55bde51648b5aac2ec85296a130fa0b0dc88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 */


#include "common.h"

//#include <avr/power.h>
//#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/atomic.h>

//#include <stdio.h>


#include "timer.h"

/* timer interrupt/overflow counter */
volatile uint32_t timestamp;


/*---------------------------------------------------------*/
/* 1000Hz timer interrupt generated by OC3A                */
/*---------------------------------------------------------*/

ISR(TIMER3_COMPA_vect)
{
	static int_fast8_t tick_10ms;
	int_fast8_t i;


	timestamp++;

	i = tick_10ms + 1;
	if (i == 10) {
		i = 0;
		Stat |= S_10MS_TO;

		/* Drive timer procedure of low level disk I/O module */
		//disk_timerproc();
	}
	tick_10ms = i;

}



/*--------------------------------------------------------------------------*/

#if 0

void do_10ms(void)
{
		if (to_counter)
			to_counter--;
}

#endif

/*--------------------------------------------------------------------------*/


#if 0
void timer_setup(void)
{

	/* Clock */
	CLKPR = _BV(CLKPCE);
	CLKPR = 0;

	/* Timer */

	OCR1A = F_CPU / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
	TCCR1B = 0b00001001;
	TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
}
#endif

uint32_t get_timer(uint32_t base)
{
	uint32_t ret;

	ATOMIC_BLOCK(ATOMIC_FORCEON)
	{
		ret = timestamp;
	}
	return ret - base;
}