PIC32MX: Pin IRQ logic no longer returns the xcpt_t oldhandler. There value is useless and dangerous after the recent changes to interrupt argument passing.

This commit is contained in:
Gregory Nutt
2017-03-02 12:10:05 -06:00
parent edbc0eaace
commit 1564b384e1
8 changed files with 55 additions and 52 deletions
+1 -1
View File
@@ -355,7 +355,7 @@ void kl_gpiowrite(uint32_t pinset, bool value);
bool kl_gpioread(uint32_t pinset); bool kl_gpioread(uint32_t pinset);
/************************************************************************************ /************************************************************************************
* Name: kl_pinirqattach * Name: kl_gpioirqattach
* *
* Description: * Description:
* Attach a pin interrupt handler. The normal initalization sequence is: * Attach a pin interrupt handler. The normal initalization sequence is:
+1 -1
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/arm/src/kl/kl_gpioirq.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
+26 -24
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* arch/mips/src/pic32mx/pic32mx-gpio.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -52,23 +52,21 @@
#ifdef CONFIG_PIC32MX_GPIOIRQ #ifdef CONFIG_PIC32MX_GPIOIRQ
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
/**************************************************************************** struct g_cnisrs_s
* Public Data {
****************************************************************************/ xcpt_t handler; /* Entery hander entry point */
void *arg; /* The argument that accompanies the interrupt handler */
};
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static xcpt_t g_cnisrs[IOPORT_NUMCN]; static struct g_cnisrs_s g_cnisrs[IOPORT_NUMCN];
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@@ -113,11 +111,14 @@ static int pic32mx_cninterrupt(int irq, FAR void *context)
{ {
/* Is this one attached */ /* 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 */ /* 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 */ /* Keep track of the status of the last handler that failed */
@@ -126,6 +127,7 @@ static int pic32mx_cninterrupt(int irq, FAR void *context)
ret = status; ret = status;
} }
} }
}
/* Clear the pending interrupt */ /* Clear the pending interrupt */
@@ -189,21 +191,21 @@ void pic32mx_gpioirqinitialize(void)
* In that case, all attached handlers will be called. Each handler must * In that case, all attached handlers will be called. Each handler must
* maintain state and determine if the unlying GPIO input value changed. * maintain state and determine if the unlying GPIO input value changed.
* *
* Parameters: * Input Parameters:
* - pinset: GPIO pin configuration * pinset - GPIO pin configuration
* - cn: The change notification number associated with the pin. * cn - The change notification number associated with the pin.
* - handler: Interrupt handler (may be NULL to detach) * handler - Interrupt handler (may be NULL to detach)
* arg - The argument that accompanies the interrupt
* *
* Returns: * Returned Value:
* The previous value of the interrupt handler function pointer. This * Zero (OK) is returned on success. A negated error value is returned on
* value may, for example, be used to restore the previous handler when * any failure to indicate the nature of the failure.
* multiple handlers are used.
* *
****************************************************************************/ ****************************************************************************/
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; irqstate_t flags;
DEBUGASSERT(cn < IOPORT_NUMCN); 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 */ /* Get the previously attached handler as the return value */
flags = enter_critical_section(); flags = enter_critical_section();
oldhandler = g_cnisrs[cn];
/* Are we attaching or detaching? */ /* 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) */ /* 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); leave_critical_section(flags);
} }
return oldhandler; return OK;
} }
/**************************************************************************** /****************************************************************************
+13 -12
View File
@@ -1,7 +1,7 @@
/************************************************************************************ /************************************************************************************
* arch/mips/src/pic32mx/pic32mx.h * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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 * case, all attached handlers will be called. Each handler must maintain state
* and determine if the underlying GPIO input value changed. * and determine if the underlying GPIO input value changed.
* *
* Parameters: * Input Parameters:
* - pinset: GPIO pin configuration * pinset - GPIO pin configuration
* - cn: The change notification number associated with the pin * cn - The change notification number associated with the pin.
* - handler: Interrupt handler (may be NULL to detach) * handler - Interrupt handler (may be NULL to detach)
* arg - The argument that accompanies the interrupt
* *
* Returns: * Returned Value:
* The previous value of the interrupt handler function pointer. This value may, * Zero (OK) is returned on success. A negated error value is returned on
* for example, be used to restore the previous handler when multiple handlers are * any failure to indicate the nature of the failure.
* used.
* *
************************************************************************************/ ****************************************************************************/
#ifdef CONFIG_PIC32MX_GPIOIRQ #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 #else
# define pic32mx_gpioattach(p,f) (NULL) # define pic32mx_gpioattach(p,c,h,a) (NULL)
#endif #endif
/************************************************************************************ /************************************************************************************
+2 -2
View File
@@ -211,14 +211,14 @@ static void adxl345_enable(FAR struct adxl345_config_s *state, bool enable)
/* Configure the interrupt using the SAVED handler */ /* Configure the interrupt using the SAVED handler */
kl_configgpio(GPIO_ADXL345_INT1); 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); kl_gpioirqenable(GPIO_ADXL345_INT1);
} }
else else
{ {
/* Configure the interrupt with a NULL handler to disable it */ /* 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); kl_gpioirqdisable(GPIO_ADXL345_INT1);
} }
+2 -2
View File
@@ -211,12 +211,12 @@ static void wl_enable_irq(FAR struct cc3000_config_s *state, bool enable)
iinfo("enable:%d\n", enable); iinfo("enable:%d\n", enable);
if (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); kl_gpioirqenable(GPIO_WIFI_INT);
} }
else else
{ {
(void)kl_gpioirqattach(GPIO_WIFI_INT, NULL); (void)kl_gpioirqattach(GPIO_WIFI_INT, NULL, NULL);
kl_gpioirqdisable(GPIO_WIFI_INT); kl_gpioirqdisable(GPIO_WIFI_INT);
} }
} }
+5 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/sure-pic32mx/src/pic32mx_buttons.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -208,19 +208,19 @@ uint8_t board_buttons(void)
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = OK;
if (id < NUM_BUTTONS) if (id < NUM_BUTTONS)
{ {
pic32mx_gpioirqdisable(g_buttoncn[id]); pic32mx_gpioirqdisable(g_buttoncn[id]);
oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); ret = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler, arg);
if (irqhandler != NULL) if (ret >= 0)
{ {
pic32mx_gpioirqenable(g_buttoncn[id]); pic32mx_gpioirqenable(g_buttoncn[id]);
} }
} }
return oldhandler; return ret;
} }
#endif #endif
#endif /* CONFIG_ARCH_BUTTONS */ #endif /* CONFIG_ARCH_BUTTONS */
+5 -5
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/ubw32/src/pic32_buttons.c * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -183,19 +183,19 @@ uint8_t board_buttons(void)
#ifdef CONFIG_ARCH_IRQBUTTONS #ifdef CONFIG_ARCH_IRQBUTTONS
xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
{ {
xcpt_t oldhandler = NULL; int ret = OK;
if (id < NUM_BUTTONS) if (id < NUM_BUTTONS)
{ {
pic32mx_gpioirqdisable(g_buttoncn[id]); pic32mx_gpioirqdisable(g_buttoncn[id]);
oldhandler = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler); ret = pic32mx_gpioattach(g_buttonset[id], g_buttoncn[id], irqhandler, arg);
if (irqhandler) if (ret >= 0)
{ {
pic32mx_gpioirqenable(g_buttoncn[id]); pic32mx_gpioirqenable(g_buttoncn[id]);
} }
} }
return oldhandler; return ret;
} }
#endif #endif
#endif /* CONFIG_ARCH_BUTTONS */ #endif /* CONFIG_ARCH_BUTTONS */