-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.c
More file actions
34 lines (30 loc) · 725 Bytes
/
timer.c
File metadata and controls
34 lines (30 loc) · 725 Bytes
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
#include "timer.h"
#include "auxiliary.h"
#include <avr/io.h>
#include <avr/interrupt.h>
void TIMER_init()
{
/* set up timer 0 to no prescale */
TCCR0A = 0x00;
TCCR0B = 0x01;
TIMSK0 = _BV(TOIE0);
}
#include "main.h"
static struct timer_fast_handler tmr_fhandlers[] = {
};
void MAIN_timer_handler();
static struct timer_handler tmr_handlers[] = {
{.callback = MAIN_timer_handler, .cnt_max = 1000}
};
ISR(TIMER0_OVF_vect)
{
for (unsigned i = 0; i < ARR_SZ(tmr_fhandlers); ++i)
(*tmr_fhandlers[i].callback)();
for (unsigned i = 0; i < ARR_SZ(tmr_handlers); ++i) {
++tmr_handlers[i].cnt;
if (tmr_handlers[i].cnt > tmr_handlers[i].cnt_max) {
tmr_handlers[i].cnt = 0;
(*tmr_handlers[i].callback)();
}
}
}