]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/background.c
Integrate fatfs. Add some sd card test commands.
[z180-stamp.git] / avr / background.c
CommitLineData
72f58822
L
1#include "common.h"
2#include "background.h"
3
4
5#define BG_FUNC_MAX 5
6
89adce76
L
7static struct {
8 bg_func fct;
9 int param;
10} func_tab[BG_FUNC_MAX];
11
72f58822
L
12static int_fast8_t fcount;
13
89adce76 14int bg_register(bg_func f, int initval)
72f58822
L
15{
16 if (fcount < BG_FUNC_MAX) {
89adce76
L
17 func_tab[fcount].fct = f;
18 func_tab[fcount].param = initval;
19 return ++fcount - 1;
20 }
21 return -1;
22}
23
24int bg_setstat(int handle, int val)
25{
26 if (handle < fcount) {
27 func_tab[handle].param = val;
72f58822
L
28 return 1;
29 }
89adce76
L
30
31 return 0;
32}
33
34
35int bg_getstat(int handle)
36{
37 if (handle < fcount) {
38 return func_tab[handle].param;
39 }
72f58822
L
40 return 0;
41}
42
43
44void bg_shed(void)
45{
46 static int_fast8_t current;
47
89adce76
L
48 if (func_tab[current].fct) {
49 int v = func_tab[current].fct(func_tab[current].param);
50 func_tab[current].param = v;
72f58822
L
51 }
52 if (++current >= fcount)
53 current = 0;
54}
55
56