blob: 87dcbc673ca8a0e9a605d04bc67d76e821e22edc (
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
|
#define HAVE_TICK
static union {
uint32_t u32;
uint8_t u8[4];
} systick = { .u32 = 0 };
ISR(TIMER1_COMPA_vect)
{
systick.u32++;
}
static void uart_puttick(void)
{
uint16_t frac = TCNT1;
_uart_putch('@');
uart_puthex(systick.u8[3]);
uart_puthex(systick.u8[2]);
uart_puthex(systick.u8[1]);
uart_puthex(systick.u8[0]);
_uart_putch('.');
uart_puthex16(frac);
_uart_putch(' ');
}
static void tick_init(void)
{
TCCR1A = 0;
TCCR1B = (1 << WGM12) | (1 << CS12) | (0 << CS11) | (0 << CS10); // 8 MHz / 256 = 31250 Hz
asm volatile ("" ::: "memory");
TCNT1 = 0;
OCR1A = 31249; // 1 Hz
asm volatile ("" ::: "memory");
TIFR1 = (1 << OCF1A);
TIMSK1 = (1 << OCIE1A);
}
|