summaryrefslogtreecommitdiff
path: root/avr/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/background.c')
-rw-r--r--avr/background.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/avr/background.c b/avr/background.c
new file mode 100644
index 0000000..0e1ca40
--- /dev/null
+++ b/avr/background.c
@@ -0,0 +1,56 @@
+#include "common.h"
+#include "background.h"
+
+
+#define BG_FUNC_MAX 5
+
+static struct {
+ bg_func fct;
+ int param;
+} func_tab[BG_FUNC_MAX];
+
+static int_fast8_t fcount;
+
+int bg_register(bg_func f, int initval)
+{
+ if (fcount < BG_FUNC_MAX) {
+ func_tab[fcount].fct = f;
+ func_tab[fcount].param = initval;
+ return ++fcount - 1;
+ }
+ return -1;
+}
+
+int bg_setstat(int handle, int val)
+{
+ if (handle < fcount) {
+ func_tab[handle].param = val;
+ return 1;
+ }
+
+ return 0;
+}
+
+
+int bg_getstat(int handle)
+{
+ if (handle < fcount) {
+ return func_tab[handle].param;
+ }
+ return 0;
+}
+
+
+void bg_shed(void)
+{
+ static int_fast8_t current;
+
+ if (func_tab[current].fct) {
+ int v = func_tab[current].fct(func_tab[current].param);
+ func_tab[current].param = v;
+ }
+ if (++current >= fcount)
+ current = 0;
+}
+
+