diff --git a/arch/arm/src/kl/kl_gpio.h b/arch/arm/src/kl/kl_gpio.h index c04fed1be53..4a81acd27e4 100644 --- a/arch/arm/src/kl/kl_gpio.h +++ b/arch/arm/src/kl/kl_gpio.h @@ -355,7 +355,7 @@ void kl_gpiowrite(uint32_t pinset, bool value); bool kl_gpioread(uint32_t pinset); /************************************************************************************ - * Name: kl_pinirqattach + * Name: kl_gpioirqattach * * Description: * Attach a pin interrupt handler. The normal initalization sequence is: diff --git a/arch/arm/src/kl/kl_gpioirq.c b/arch/arm/src/kl/kl_gpioirq.c index 70eacfc457b..f7c3c2ae57c 100644 --- a/arch/arm/src/kl/kl_gpioirq.c +++ b/arch/arm/src/kl/kl_gpioirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kl/kl_gpioirq.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/arch/mips/src/pic32mx/pic32mx-gpioirq.c b/arch/mips/src/pic32mx/pic32mx-gpioirq.c index ce96403da8c..2565c1bf375 100644 --- a/arch/mips/src/pic32mx/pic32mx-gpioirq.c +++ b/arch/mips/src/pic32mx/pic32mx-gpioirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/pic32mx/pic32mx-gpio.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,23 +52,21 @@ #ifdef CONFIG_PIC32MX_GPIOIRQ -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ -/**************************************************************************** - * Public Data - ****************************************************************************/ +struct g_cnisrs_s +{ + xcpt_t handler; /* Entery hander entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; /**************************************************************************** * Private Data ****************************************************************************/ -static xcpt_t g_cnisrs[IOPORT_NUMCN]; +static struct g_cnisrs_s g_cnisrs[IOPORT_NUMCN]; /**************************************************************************** * Private Functions @@ -113,11 +111,14 @@ static int pic32mx_cninterrupt(int irq, FAR void *context) { /* Is this one attached */ - if (g_cnisrs[i]) + if (g_cnisrs[i].handler != NULL) { + xcpt_t handler = irstab[i].handler; + void *arg = irstab[i].arg; + /* Call the attached handler */ - status = g_cnisrs[i](irq, context); + status = handler(irq, context, arg); /* Keep track of the status of the last handler that failed */ @@ -125,6 +126,7 @@ static int pic32mx_cninterrupt(int irq, FAR void *context) { ret = status; } + } } /* Clear the pending interrupt */ @@ -189,21 +191,21 @@ void pic32mx_gpioirqinitialize(void) * In that case, all attached handlers will be called. Each handler must * maintain state and determine if the unlying GPIO input value changed. * - * Parameters: - * - pinset: GPIO pin configuration - * - cn: The change notification number associated with the pin. - * - handler: Interrupt handler (may be NULL to detach) + * Input Parameters: + * pinset - GPIO pin configuration + * cn - The change notification number associated with the pin. + * handler - Interrupt handler (may be NULL to detach) + * arg - The argument that accompanies the interrupt * - * Returns: - * The previous value of the interrupt handler function pointer. This - * value may, for example, be used to restore the previous handler when - * multiple handlers are used. + * Returned Value: + * Zero (OK) is returned on success. A negated error value is returned on + * any failure to indicate the nature of the failure. * ****************************************************************************/ -xcpt_t pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler) +int pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler, + void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; DEBUGASSERT(cn < IOPORT_NUMCN); @@ -215,7 +217,6 @@ xcpt_t pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler) /* Get the previously attached handler as the return value */ flags = enter_critical_section(); - oldhandler = g_cnisrs[cn]; /* Are we attaching or detaching? */ @@ -250,11 +251,12 @@ xcpt_t pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler) /* Set the new handler (perhaps NULLifying the current handler) */ - g_cnisrs[cn] = handler; + g_cnisrs[cn].handler = handler; + g_cnisrs[cn].arg = arg; leave_critical_section(flags); } - return oldhandler; + return OK; } /**************************************************************************** diff --git a/arch/mips/src/pic32mx/pic32mx.h b/arch/mips/src/pic32mx/pic32mx.h index c2dccffab9d..69f3d18653a 100644 --- a/arch/mips/src/pic32mx/pic32mx.h +++ b/arch/mips/src/pic32mx/pic32mx.h @@ -1,7 +1,7 @@ /************************************************************************************ * arch/mips/src/pic32mx/pic32mx.h * - * Copyright (C) 2011-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -324,22 +324,23 @@ void pic32mx_gpioirqinitialize(void); * case, all attached handlers will be called. Each handler must maintain state * and determine if the underlying GPIO input value changed. * - * Parameters: - * - pinset: GPIO pin configuration - * - cn: The change notification number associated with the pin - * - handler: Interrupt handler (may be NULL to detach) + * Input Parameters: + * pinset - GPIO pin configuration + * cn - The change notification number associated with the pin. + * handler - Interrupt handler (may be NULL to detach) + * arg - The argument that accompanies the interrupt * - * Returns: - * The previous value of the interrupt handler function pointer. This value may, - * for example, be used to restore the previous handler when multiple handlers are - * used. + * Returned Value: + * Zero (OK) is returned on success. A negated error value is returned on + * any failure to indicate the nature of the failure. * - ************************************************************************************/ + ****************************************************************************/ #ifdef CONFIG_PIC32MX_GPIOIRQ -xcpt_t pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler); +int pic32mx_gpioattach(uint32_t pinset, unsigned int cn, xcpt_t handler, + void *arg); #else -# define pic32mx_gpioattach(p,f) (NULL) +# define pic32mx_gpioattach(p,c,h,a) (NULL) #endif /************************************************************************************ diff --git a/configs/freedom-kl25z/src/kl_adxl345.c b/configs/freedom-kl25z/src/kl_adxl345.c index 3560e3d7fa1..7213fcccfa7 100644 --- a/configs/freedom-kl25z/src/kl_adxl345.c +++ b/configs/freedom-kl25z/src/kl_adxl345.c @@ -211,14 +211,14 @@ static void adxl345_enable(FAR struct adxl345_config_s *state, bool enable) /* Configure the interrupt using the SAVED handler */ kl_configgpio(GPIO_ADXL345_INT1); - (void)kl_gpioirqattach(GPIO_ADXL345_INT1, adxl345_interrupt); + (void)kl_gpioirqattach(GPIO_ADXL345_INT1, adxl345_interrupt, NULL); kl_gpioirqenable(GPIO_ADXL345_INT1); } else { /* Configure the interrupt with a NULL handler to disable it */ - (void)kl_gpioirqattach(GPIO_ADXL345_INT1, NULL); + (void)kl_gpioirqattach(GPIO_ADXL345_INT1, NULL, NULL); kl_gpioirqdisable(GPIO_ADXL345_INT1); } diff --git a/configs/freedom-kl25z/src/kl_wifi.c b/configs/freedom-kl25z/src/kl_wifi.c index 0bf17b1c8a0..0f1810da37b 100644 --- a/configs/freedom-kl25z/src/kl_wifi.c +++ b/configs/freedom-kl25z/src/kl_wifi.c @@ -211,12 +211,12 @@ static void wl_enable_irq(FAR struct cc3000_config_s *state, bool enable) iinfo("enable:%d\n", enable); if (enable) { - (void)kl_gpioirqattach(GPIO_WIFI_INT, priv->handler); + (void)kl_gpioirqattach(GPIO_WIFI_INT, priv->handler, priv->arg); kl_gpioirqenable(GPIO_WIFI_INT); } else { - (void)kl_gpioirqattach(GPIO_WIFI_INT, NULL); + (void)kl_gpioirqattach(GPIO_WIFI_INT, NULL, NULL); kl_gpioirqdisable(GPIO_WIFI_INT); } } diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 8de2633e2f6..85cc49fe917 100644 --- a/configs/sure-pic32mx/src/pic32mx_buttons.c +++ b/configs/sure-pic32mx/src/pic32mx_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sure-pic32mx/src/pic32mx_buttons.c * - * Copyright (C) 2011, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -208,19 +208,19 @@ uint8_t board_buttons(void) #ifdef CONFIG_ARCH_IRQBUTTONS xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = OK; if (id < NUM_BUTTONS) { pic32mx_gpioirqdisable(g_buttoncn[id]); - oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); - if (irqhandler != NULL) + ret = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler, arg); + if (ret >= 0) { pic32mx_gpioirqenable(g_buttoncn[id]); } } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index dec8fe416eb..de9e16e542a 100644 --- a/configs/ubw32/src/pic32_buttons.c +++ b/configs/ubw32/src/pic32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/ubw32/src/pic32_buttons.c * - * Copyright (C) 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -183,19 +183,19 @@ uint8_t board_buttons(void) #ifdef CONFIG_ARCH_IRQBUTTONS xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = OK; if (id < NUM_BUTTONS) { pic32mx_gpioirqdisable(g_buttoncn[id]); - oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); - if (irqhandler) + ret = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler, arg); + if (ret >= 0) { pic32mx_gpioirqenable(g_buttoncn[id]); } } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */