]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/background.c
cli.c bugfix: Comment only lines are not an error.
[z180-stamp.git] / avr / background.c
CommitLineData
35edb766
L
1/*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
72f58822
L
7#include "common.h"
8#include "background.h"
9
10
11#define BG_FUNC_MAX 5
12
35edb766 13static struct {
89adce76
L
14 bg_func fct;
15 int param;
16} func_tab[BG_FUNC_MAX];
17
72f58822
L
18static int_fast8_t fcount;
19
89adce76 20int bg_register(bg_func f, int initval)
72f58822 21{
35edb766 22 if (fcount < BG_FUNC_MAX) {
89adce76
L
23 func_tab[fcount].fct = f;
24 func_tab[fcount].param = initval;
25 return ++fcount - 1;
26 }
27 return -1;
28}
29
30int bg_setstat(int handle, int val)
31{
32 if (handle < fcount) {
33 func_tab[handle].param = val;
72f58822
L
34 return 1;
35 }
35edb766 36
89adce76
L
37 return 0;
38}
39
40
41int bg_getstat(int handle)
42{
43 if (handle < fcount) {
44 return func_tab[handle].param;
45 }
72f58822
L
46 return 0;
47}
48
49
50void bg_shed(void)
51{
52 static int_fast8_t current;
35edb766 53
89adce76
L
54 if (func_tab[current].fct) {
55 int v = func_tab[current].fct(func_tab[current].param);
56 func_tab[current].param = v;
72f58822
L
57 }
58 if (++current >= fcount)
59 current = 0;
60}