--- embedtools/src/butz.c 2014/02/08 16:48:36 1.1.2.4 +++ embedtools/src/butz.c 2017/06/28 15:19:32 1.3 @@ -1,9 +1,55 @@ +/************************************************************************* + * (C) 2014 AITNET - Sofia/Bulgaria - + * by Michael Pounov + * + * $Author: misho $ + * $Id: butz.c,v 1.3 2017/06/28 15:19:32 misho Exp $ + * + ************************************************************************* +The ELWIX and AITNET software is distributed under the following +terms: + +All of the documentation and software included in the ELWIX and AITNET +Releases is copyrighted by ELWIX - Sofia/Bulgaria + +Copyright 2004 - 2017 + by Michael Pounov . All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: +This product includes software developed by Michael Pounov +ELWIX - Embedded LightWeight unIX and its contributors. +4. Neither the name of AITNET nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. +*/ #include "global.h" cfg_root_t cfg; sched_root_task_t *root; -int Kill, gpio, maxpins, defact, resbut, led = -1; +volatile intptr_t Kill; +int gpio, flg, maxpins, defact, resbut, led = -1; extern char compiled[], compiledby[], compilehost[]; char szCfgName[PATH_MAX] = BUTZ_CFG; char szDevName[PATH_MAX] = _PATH_DEVGPIOC"0"; @@ -76,6 +122,8 @@ sigHandler(sched_task_t *task) EERROR(EINVAL, "Undefined signal %lu!", TASK_VAL(task)); break; } + + schedSignalSelf(task); taskExit(task, NULL); } @@ -97,6 +145,7 @@ execReset(sched_task_t *task) _exit(127); } + flg ^= flg; taskExit(task, NULL); } @@ -118,6 +167,7 @@ execDefault(sched_task_t *task) _exit(127); } + flg ^= flg; taskExit(task, NULL); } @@ -126,14 +176,7 @@ butReset(sched_task_t *task) { struct timespec ts = { 1, 0 }; struct gpio_req req; - static int flg = 0; - /* toggle led pin */ - if (led != -1) { - req.gp_pin = led; - if (ioctl(gpio, GPIOTOGGLE, &req) == -1) - ESYSERR(0); - } /* check reset button */ req.gp_pin = resbut; if (ioctl(gpio, GPIOGET, &req) == -1) { @@ -141,16 +184,24 @@ butReset(sched_task_t *task) goto end; } /* switch on */ - if (!req.gp_value) + if (flg != -1 && !req.gp_value) if (++flg == 1) schedSuspend(TASK_ROOT(task), execReset, NULL, flg, NULL, 0); if (defact && flg >= defact) { schedCancelby(TASK_ROOT(task), taskSUSPEND, CRITERIA_CALL, execReset, NULL); schedEvent(TASK_ROOT(task), execDefault, NULL, flg, NULL, 0); + flg = -1; goto end; } - if (flg && req.gp_value) + if (flg > 0 && req.gp_value) schedResumeby(TASK_ROOT(task), CRITERIA_ID, (void*) 1); + + /* toggle led pin */ + if (flg != -1 && led != -1) { + req.gp_pin = led; + if (ioctl(gpio, GPIOTOGGLE, &req) == -1) + ESYSERR(0); + } end: schedTimer(TASK_ROOT(task), TASK_FUNC(task), TASK_ARG(task), ts, TASK_DATA(task), TASK_DATLEN(task));