summaryrefslogtreecommitdiff
path: root/avr/background.c
blob: 37e4b02c12b9eaa50d42bce39844436bdd9f09d6 (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
#include "common.h"
#include "background.h"


#define BG_FUNC_MAX 5

static bg_func func_tab[BG_FUNC_MAX];
static int_fast8_t fcount;

int bg_register(bg_func f)
{
	if (fcount < BG_FUNC_MAX) { 
		func_tab[fcount++] = f;
		return 1;
	}
	return 0;
}


void bg_shed(void)
{
	static int_fast8_t current;
	
	if (func_tab[current]) {
		func_tab[current](0);
	}
	if (++current >= fcount)
		current = 0;
}