summaryrefslogtreecommitdiff
path: root/avr/background.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/background.c')
-rw-r--r--avr/background.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/avr/background.c b/avr/background.c
new file mode 100644
index 0000000..37e4b02
--- /dev/null
+++ b/avr/background.c
@@ -0,0 +1,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;
+}
+
+