X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/4bc81323e51ac138e733c14eeb6f283ae706e904..a11e60da10b1065dfcf57bb742670b74784703e2:/avr/background.c?ds=sidebyside diff --git a/avr/background.c b/avr/background.c index 37e4b02..9c8b5a6 100644 --- a/avr/background.c +++ b/avr/background.c @@ -1,18 +1,48 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #include "common.h" #include "background.h" #define BG_FUNC_MAX 5 -static bg_func func_tab[BG_FUNC_MAX]; +static struct { + bg_func fct; + int param; +} func_tab[BG_FUNC_MAX]; + static int_fast8_t fcount; -int bg_register(bg_func f) +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 (fcount < BG_FUNC_MAX) { - func_tab[fcount++] = f; + 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; } @@ -20,12 +50,11 @@ int bg_register(bg_func f) void bg_shed(void) { static int_fast8_t current; - - if (func_tab[current]) { - func_tab[current](0); + + 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; } - -