From 6539cd5f7348a6861c287516f6be9df2a02cfd3b Mon Sep 17 00:00:00 2001 From: Celine Buret Date: Thu, 30 Sep 2010 16:22:06 +0200 Subject: cleo/app/mgrd: handle sc button as a gpio interrupt, refs #1878 --- cleopatre/application/managerd/inc/managerd.h | 1 + .../application/managerd/inc/simple_connect.h | 41 ++++--- cleopatre/application/managerd/src/managerd.c | 26 ++-- .../application/managerd/src/simple_connect.c | 133 ++++++++++----------- 4 files changed, 108 insertions(+), 93 deletions(-) (limited to 'cleopatre/application/managerd') diff --git a/cleopatre/application/managerd/inc/managerd.h b/cleopatre/application/managerd/inc/managerd.h index d18e16a946..324dba7453 100644 --- a/cleopatre/application/managerd/inc/managerd.h +++ b/cleopatre/application/managerd/inc/managerd.h @@ -43,6 +43,7 @@ struct managerd_ctx { struct sockaddr_nl mme_snl; uint8_t br_mac_addr[ETH_ALEN]; union gpio_info sc_gpio; + union gpio_info sc_it; union gpio_info led_gpio; int is_sc_available; }; diff --git a/cleopatre/application/managerd/inc/simple_connect.h b/cleopatre/application/managerd/inc/simple_connect.h index 106c2b55fb..c291eeb0d9 100644 --- a/cleopatre/application/managerd/inc/simple_connect.h +++ b/cleopatre/application/managerd/inc/simple_connect.h @@ -2,12 +2,12 @@ * cleopatre/application/managerd/inc/simple_connect.h * * (C) Copyright 2009 SPiDCOM Technologies - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -24,36 +24,45 @@ #include "managerd.h" /** GPIO number for SC button and it associated LED */ -#define SC_BUT_GPIO_NUM 1 -#define SC_LED_GPIO_NUM 2 +#define SC_BUT_GPIO_NUM 1 +#define SC_LED_GPIO_NUM 2 /** name of the gpio device */ -#define GPIO_DEVICE_NAME "/dev/gpio" - -#define SC_BUTTON_ON 0 -#define SC_BUTTON_OFF 1 +#define GPIO_DEVICE_NAME "/dev/gpio" /** * Simple Connect detection event. * - * \param ctx managerd context. - * \return error code. + * \param ctx managerd context + * \return error code + */ +int +simple_connect_event (struct managerd_ctx *ctx); + +/** + * Simple Connect reset event. + * + * \param ctx managerd context + * \return error code */ -int simple_connect_event(struct managerd_ctx *ctx); +int +simple_connect_reset (struct managerd_ctx *ctx); /** * Open and set GPIO direction. * - * \param ctx managerd context. - * \return error code. + * \param ctx managerd context + * \return error code */ -int simple_connect_init(struct managerd_ctx *ctx); +int +simple_connect_init (struct managerd_ctx *ctx); /** * Close gpio device. * - * \param ctx managerd context. + * \param ctx managerd context */ -void simple_connect_uninit(struct managerd_ctx *ctx); +void +simple_connect_uninit (struct managerd_ctx *ctx); #endif /* SIMPLE_CONNECT_H */ diff --git a/cleopatre/application/managerd/src/managerd.c b/cleopatre/application/managerd/src/managerd.c index 31ae831f34..42bb6dfd78 100644 --- a/cleopatre/application/managerd/src/managerd.c +++ b/cleopatre/application/managerd/src/managerd.c @@ -2,12 +2,12 @@ * cleopatre/application/managerd/src/managerd.c * * (C) Copyright 2009 SPiDCOM Technologies - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -59,7 +59,7 @@ static int managerd_process(struct managerd_ctx *ctx) while(1) { - fd_set readfds; + fd_set readfds, exceptfds; struct timeval timeout; int result; @@ -67,12 +67,14 @@ static int managerd_process(struct managerd_ctx *ctx) timeout.tv_sec = WAIT_TOUT; timeout.tv_usec = 0; FD_ZERO(&readfds); + FD_ZERO (&exceptfds); FD_SET(ctx->sock_br, &readfds); FD_SET(ctx->sock_lo, &readfds); FD_SET (ctx->sock_mme, &readfds); + FD_SET (ctx->gpio_fd, &exceptfds); //Select - result = select(ctx->sock_br + 3, &readfds, NULL, NULL, &timeout); + result = select (ctx->gpio_fd + 1, &readfds, NULL, &exceptfds, &timeout); /* Select error */ if (0 > result) @@ -90,13 +92,9 @@ static int managerd_process(struct managerd_ctx *ctx) return -1; } } - else if(0 == result) + else if (0 == result) { - //No reception coming, take time to manage simple connect - if(0 > simple_connect_event(ctx)) - break; - else - continue; + /* No reception coming */ } else if (FD_ISSET (ctx->sock_br, &readfds) || FD_ISSET (ctx->sock_lo, &readfds)) @@ -137,6 +135,14 @@ static int managerd_process(struct managerd_ctx *ctx) break; } } + else if (FD_ISSET (ctx->gpio_fd, &exceptfds)) + { + /* Manage simple connect */ + if (0 > simple_connect_event (ctx)) + break; + else + continue; + } } //Freeing buffer diff --git a/cleopatre/application/managerd/src/simple_connect.c b/cleopatre/application/managerd/src/simple_connect.c index 485768304f..e5f5a0edc8 100644 --- a/cleopatre/application/managerd/src/simple_connect.c +++ b/cleopatre/application/managerd/src/simple_connect.c @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ - #include #include #include @@ -26,63 +25,37 @@ #include #include #include +#include +#include "nvram.h" #include "../../linux/gpio.h" #include "libspid.h" #include "simple_connect.h" -/** Previous sc button gpio value */ -static int previous_sc_button_value = SC_BUTTON_OFF; - /** * Simple Connect detection event. * - * \param ctx managerd context. - * \return error code. + * \param ctx managerd context + * \return error code */ -int simple_connect_event(struct managerd_ctx *ctx) +int +simple_connect_event (struct managerd_ctx *ctx) { - if(!ctx->is_sc_available) + if (!ctx->is_sc_available) return 0; - //Read SC button GPIO - if(0 > ioctl(ctx->gpio_fd, GPIOIOC_GETVALUE, (unsigned long*)&ctx->sc_gpio)) - { - syslog(LOG_WARNING, "cannot call ioctl for SC gpio (%s)", strerror(errno)); - return -1; - } + /* Write SC button GPIO status */ + libspid_config_write_item (LIBSPID_HPAV_INFO_PATH, + LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, + "yes"); - //if SC button stay on between to events, SC button is really on - if(previous_sc_button_value != ctx->sc_gpio.gpioval.val) + /* plc daemon needs to be informed */ + if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(), + LIBSPID_HPAV_INFO_PATH)) { - if(SC_BUTTON_ON == ctx->sc_gpio.gpioval.val) - { - libspid_config_write_item(LIBSPID_HPAV_INFO_PATH, LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, "yes"); - - /* plc daemon needs to be informed */ - if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(), - LIBSPID_HPAV_INFO_PATH)) - { - syslog (LOG_WARNING, "libspid system file update warn failed"); - return -1; - } - } - else - { - libspid_config_write_item(LIBSPID_HPAV_INFO_PATH, LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, "no"); - - /* plc daemon needs to be informed */ - if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(), - LIBSPID_HPAV_INFO_PATH)) - { - syslog (LOG_WARNING, "libspid system file update warn failed"); - return -1; - } - } - - //Store GPIO value for next passage - previous_sc_button_value = ctx->sc_gpio.gpioval.val; + syslog (LOG_WARNING, "libspid system file update warn failed"); + return -1; } return 0; @@ -91,44 +64,58 @@ int simple_connect_event(struct managerd_ctx *ctx) /** * Open and set GPIO direction. * - * \param ctx managerd context. - * \return error code. + * \param ctx managerd context + * \return error code */ -int simple_connect_init(struct managerd_ctx *ctx) +int +simple_connect_init (struct managerd_ctx *ctx) { - //Check arguments - assert(ctx != NULL); + /* Check arguments */ + assert (ctx != NULL); - //Set GPIO info for SC button + /* Set GPIO info for SC button */ ctx->sc_gpio.gpiodir.num = SC_BUT_GPIO_NUM; - ctx->sc_gpio.gpiodir.dir = 0; //Input + ctx->sc_gpio.gpiodir.dir = SPC300_GPIO_DIRECTION_INPUT; + + /* Set GPIO info for SC button interruption */ + ctx->sc_it.gpioit.enable = 1; + ctx->sc_it.gpioit.mask = (1 << SC_BUT_GPIO_NUM); - //Set GPIO info for SC LED + /* Set GPIO info for SC LED */ ctx->led_gpio.gpiodir.num = SC_LED_GPIO_NUM; - ctx->led_gpio.gpiodir.dir = 1; //Output + ctx->led_gpio.gpiodir.dir = SPC300_GPIO_DIRECTION_OUTPUT; ctx->led_gpio.gpiodir.val = 0; - //Open GPIO device - if(0 > (ctx->gpio_fd=open("/dev/gpio",O_RDWR))) + /* Open GPIO device */ + if (0 > (ctx->gpio_fd = open (GPIO_DEVICE_NAME, O_RDWR))) { - syslog(LOG_WARNING, "cannot open gpio device (%s)", strerror(errno)); + syslog (LOG_WARNING, "cannot open gpio device (%s)", strerror (errno)); return -1; } - //Set gpio direction for Simple Connect - if(0 > (ioctl(ctx->gpio_fd, GPIOIOC_SETDIRECTION, (unsigned long*)&ctx->sc_gpio))) + /* Set gpio direction for Simple Connect */ + if (0 > ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION, + (unsigned long *) &ctx->sc_gpio)) { - syslog(LOG_WARNING, "cannot call ioctl for SC gpio (%s)", strerror(errno)); + syslog (LOG_WARNING, "cannot call ioctl for SC gpio (%s)", strerror (errno)); } else { ctx->is_sc_available = 1; } - //Set gpio direction for LED - if(0 > (ioctl(ctx->gpio_fd, GPIOIOC_SETDIRECTION, (unsigned long*)&ctx->led_gpio))) + /* Set gpio direction for LED */ + if (0 > (ioctl (ctx->gpio_fd, GPIOIOC_SETDIRECTION, + (unsigned long*)&ctx->led_gpio))) { - syslog(LOG_WARNING, "cannot call ioctl for LED gpio (%s)", strerror(errno)); + syslog (LOG_WARNING, "cannot call ioctl for LED gpio (%s)", strerror (errno)); + } + + /* Set GPIO interrupt for SC button */ + if (0 > ioctl (ctx->gpio_fd, GPIOIOC_SETIT, + (unsigned long *) &ctx->sc_it)) + { + syslog (LOG_WARNING, "cannot call ioctl for SC interruption (%s)", strerror (errno)); } return 0; @@ -137,14 +124,26 @@ int simple_connect_init(struct managerd_ctx *ctx) /** * Close gpio device. * - * \param ctx managerd context. + * \param ctx managerd context */ -void simple_connect_uninit(struct managerd_ctx *ctx) +void +simple_connect_uninit (struct managerd_ctx *ctx) { - //Check arguments - assert(ctx != NULL); + /* Check arguments */ + assert (ctx != NULL); + + /* Reet GPIO info for SC button interruption */ + ctx->sc_it.gpioit.enable = 0; + ctx->sc_it.gpioit.mask = 0; + + /* Reset GPIO interrupt for SC button */ + if (0 > ioctl (ctx->gpio_fd, GPIOIOC_SETIT, + (unsigned long *) &ctx->sc_it)) + { + syslog (LOG_WARNING, "cannot call ioctl for SC interruption (%s)", strerror (errno)); + } - //Close GPIO device - close(ctx->gpio_fd); + /* Close GPIO device */ + close (ctx->gpio_fd); } -- cgit v1.2.3