]> cloudbase.mooo.com Git - z180-stamp.git/blame_incremental - avr/background.c
Merge branch 'master' into cmdline_edit
[z180-stamp.git] / avr / background.c
... / ...
CommitLineData
1/*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include "common.h"
8#include "background.h"
9
10
11#define BG_FUNC_MAX 5
12
13static struct {
14 bg_func fct;
15 int param;
16} func_tab[BG_FUNC_MAX];
17
18static int_fast8_t fcount;
19
20int bg_register(bg_func f, int initval)
21{
22 if (fcount < BG_FUNC_MAX) {
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;
34 return 1;
35 }
36
37 return 0;
38}
39
40
41int bg_getstat(int handle)
42{
43 if (handle < fcount) {
44 return func_tab[handle].param;
45 }
46 return 0;
47}
48
49
50void bg_shed(void)
51{
52 static int_fast8_t current;
53
54 if (func_tab[current].fct) {
55 int v = func_tab[current].fct(func_tab[current].param);
56 func_tab[current].param = v;
57 }
58 if (++current >= fcount)
59 current = 0;
60}