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);
/************************************************************************************
* Name: kl_pinirqattach
* Name: kl_gpioirqattach
*
* Description:
* 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
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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;
}
/****************************************************************************
+13 -12
View File
@@ -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 <gnutt@nuttx.org>
*
* 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
/************************************************************************************
+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 */
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);
}
+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);
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);
}
}
+5 -5
View File
@@ -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 <gnutt@nuttx.org>
*
* 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 */
+5 -5
View File
@@ -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 <gnutt@nuttx.org>
*
* 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 */