diff --git a/arch/arm/src/kinetis/kinetis.h b/arch/arm/src/kinetis/kinetis.h index f70f69a0e16..a2bf6ddf7da 100644 --- a/arch/arm/src/kinetis/kinetis.h +++ b/arch/arm/src/kinetis/kinetis.h @@ -568,19 +568,17 @@ void kinetis_pinirqinitialize(void); * 3. Call kinetis_pinirqenable() to enable interrupts on the pin. * * Parameters: - * pinset - Pin configuration - * pinisr -:wq -:wq: Pin interrupt service routine - * arg:r - And argument that will be provided to the interrupt service routine. + * pinset - Pin configuration + * pinisr - Pin interrupt service routine + * arg - An argument that will be provided to the interrupt service routine. * * Return Value: - * 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. + * Zero (OK) is returned on success; a negated errno value is returned on any + * failure to indicate the nature of the failure. * ************************************************************************************/ -xcpt_t kinetis_pinirqattach(uint32_t pinset, xcpt_t pinisr, void *arg); +int kinetis_pinirqattach(uint32_t pinset, xcpt_t pinisr, void *arg); /************************************************************************************ * Name: kinetis_pinirqenable diff --git a/arch/arm/src/kinetis/kinetis_pinirq.c b/arch/arm/src/kinetis/kinetis_pinirq.c index c8adac1f0aa..bf1b2af6ba3 100644 --- a/arch/arm/src/kinetis/kinetis_pinirq.c +++ b/arch/arm/src/kinetis/kinetis_pinirq.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/kinetis/kinetis_pinirq.c * - * Copyright (C) 2011, 2013, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -262,21 +262,20 @@ void kinetis_pinirqinitialize(void) * 3. Call kinetis_pinirqenable() to enable interrupts on the pin. * * Parameters: - * - pinset: Pin configuration - * - pinisr: Pin interrupt service routine + * pinset - Pin configuration + * pinisr - Pin interrupt service routine + * arg - An argument that will be provided to the interrupt service routine. * * Returns: - * The previous value of the interrupt handler function pointer. This - * value may, for example, be used to restore the previous handler whe - * multiple handlers are used. + * Zero (OK) is returned on success; a negated errno value is returned on any + * failure to indicate the nature of the failure. * - ****************************************************************************/ + ************************************************************************************/ -xcpt_t kinetis_pinirqattach(uint32_t pinset, xcpt_t pinisr, void *arg) +int kinetis_pinirqattach(uint32_t pinset, xcpt_t pinisr, void *arg) { #ifdef HAVE_PORTINTS struct kinetis_pinirq_s *isrtab; - xcpt_t oldisr; irqstate_t flags; unsigned int port; unsigned int pin; @@ -331,16 +330,15 @@ xcpt_t kinetis_pinirqattach(uint32_t pinset, xcpt_t pinisr, void *arg) /* Get the old PIN ISR and set the new PIN ISR */ - oldisr = isrtab[pin].handler; isrtab[pin].handler = pinisr; isrtab[pin].arg = arg; /* And return the old PIN isr address */ leave_critical_section(flags); - return oldisr; + return OK; #else - return NULL; + return -ENOSYS; #endif /* HAVE_PORTINTS */ } diff --git a/arch/arm/src/kl/kl_gpio.h b/arch/arm/src/kl/kl_gpio.h index 0024e676086..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: @@ -368,15 +368,15 @@ bool kl_gpioread(uint32_t pinset); * Parameters: * - pinset: Pin configuration * - pinisr: Pin interrupt service routine + * - pinarg: The argument that will accompany the pin 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. + * Zero (OK) is returned on success; On any failure, a negated errno value is + * returned to indicate the nature of the failure. * ************************************************************************************/ -xcpt_t kl_gpioirqattach(uint32_t pinset, xcpt_t pinisr); +int kl_gpioirqattach(uint32_t pinset, xcpt_t pinisr, void *pinarg); /************************************************************************************ * Name: kl_gpioirqenable diff --git a/arch/arm/src/kl/kl_gpioirq.c b/arch/arm/src/kl/kl_gpioirq.c index 7db288321fe..38f30c0870f 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 @@ -68,7 +68,7 @@ #endif #if defined(CONFIG_KL_PORTBINTS) || defined(CONFIG_KL_PORTCINTS) || \ - defined(CONFIG_KL_PORTEINTS) + defined(CONFIG_KL_PORTEINTS) # error Kinetis KL25 only supports interrupt on PORTA or PORTD #endif @@ -76,6 +76,12 @@ * Private Types ****************************************************************************/ +struct g_portisrs_s +{ + xcpt_t handler; /* Interrupt handler entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -87,11 +93,11 @@ */ #ifdef CONFIG_KL_PORTAINTS -static xcpt_t g_portaisrs[32]; +static struct g_portisrs_s g_portaisrs[32]; #endif #ifdef CONFIG_KL_PORTDINTS -static xcpt_t g_portdisrs[32]; +static struct g_portisrs_s g_portdisrs[32]; #endif /**************************************************************************** @@ -131,11 +137,14 @@ static int kl_portinterrupt(int irq, FAR void *context, * interrupt handler for the pin. */ - if (isrtab[i]) + if (isrtab[i].handler != NULL) { + xcpt_t handler = irstab[i].handler; + void *arg = irstab[i].arg; + /* There is a registered interrupt handler... invoke it */ - (void)isrtab[i](irq, context); + (void)handler(irq, context, arg); } /* Writing a one to the ISFR register will clear the pending @@ -219,20 +228,20 @@ void kl_gpioirqinitialize(void) * Parameters: * - pinset: Pin configuration * - pinisr: Pin interrupt service routine + * - pinarg: The argument that will accompany the pin 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. + * Returns: + * Zero (OK) is returned on success; On any failure, a negated errno value is + * returned to indicate the nature of the failure. * - ****************************************************************************/ + ************************************************************************************/ -xcpt_t kl_gpioirqattach(uint32_t pinset, xcpt_t pinisr) +int kl_gpioirqattach(uint32_t pinset, xcpt_t pinisr, void *pinarg) { #ifdef HAVE_PORTINTS - xcpt_t *isrtab; - xcpt_t oldisr; - irqstate_t flags; + struct g_portisrs_s *isrtab; + irqstate_t flags; unsigned int port; unsigned int pin; @@ -271,16 +280,16 @@ xcpt_t kl_gpioirqattach(uint32_t pinset, xcpt_t pinisr) /* Get the old PIN ISR and set the new PIN ISR */ - oldisr = isrtab[pin]; - isrtab[pin] = pinisr; + isrtab[pin].handler = pinisr; + isrtab[pin].arg = pinarg; /* And return the old PIN isr address */ leave_critical_section(flags); - return oldisr; + return OK; #else - return NULL; + return -ENOSYS; #endif /* HAVE_PORTINTS */ } diff --git a/arch/arm/src/stm32/chip/stm32f33xxx_vectors.h b/arch/arm/src/stm32/chip/stm32f33xxx_vectors.h index 277cd4e6f85..cd1077a5e21 100644 --- a/arch/arm/src/stm32/chip/stm32f33xxx_vectors.h +++ b/arch/arm/src/stm32/chip/stm32f33xxx_vectors.h @@ -102,7 +102,7 @@ VECTOR(stm32_usart3, STM32_IRQ_USART3) /* 39: USART3 global or EXTI Line VECTOR(stm32_exti1510, STM32_IRQ_EXTI1510) /* 40: EXTI Line[15:10] interrupts */ VECTOR(stm32_rtcalrm, STM32_IRQ_RTCALRM) /* 41: RTC alarm through EXTI line interrupt */ -UNUSED(STM32_IRQ_RESERVED42) /* 42: Reserved*/ +UNUSED(STM32_IRQ_RESERVED42) /* 42: Reserved */ UNUSED(STM32_IRQ_RESERVED43) /* 43: Reserved */ UNUSED(STM32_IRQ_RESERVED44) /* 44: Reserved */ UNUSED(STM32_IRQ_RESERVED45) /* 45: Reserved */ @@ -113,7 +113,7 @@ UNUSED(STM32_IRQ_RESERVED49) /* 49: Reserved */ UNUSED(STM32_IRQ_RESERVED50) /* 50: Reserved */ UNUSED(STM32_IRQ_RESERVED51) /* 51: Reserved */ -UNUSED(STM32_IRQ_RESERVED51) /* 52: Reserved*/ +UNUSED(STM32_IRQ_RESERVED51) /* 52: Reserved */ UNUSED(STM32_IRQ_RESERVED52) /* 53: Reserved */ VECTOR(stm32_dac1, STM32_IRQ_DAC1) /* 54: TIM6 global or DAC1 underrun interrupts */ VECTOR(stm32_dac2, STM32_IRQ_DAC2) /* 55: TIM7 global or DAC2 underrun interrupt */ diff --git a/arch/arm/src/stm32/stm32_eth.c b/arch/arm/src/stm32/stm32_eth.c index ac19abc52d4..d7806f88293 100644 --- a/arch/arm/src/stm32/stm32_eth.c +++ b/arch/arm/src/stm32/stm32_eth.c @@ -583,7 +583,8 @@ struct stm32_ethmac_s uint8_t fduplex : 1; /* Full (vs. half) duplex */ WDOG_ID txpoll; /* TX poll timer */ WDOG_ID txtimeout; /* TX timeout timer */ - struct work_s work; /* For deferring work to the work queue */ + struct work_s irqwork; /* For deferring interrupt work to the work queue */ + struct work_s pollwork; /* For deferring poll work to the work queue */ /* This holds the information visible to the NuttX network */ @@ -1933,27 +1934,6 @@ static void stm32_txdone(FAR struct stm32_ethmac_s *priv) wd_cancel(priv->txtimeout); - /* Check if the poll timer is running. If it is not, then start it - * now. There is a race condition here: We may test the time - * remaining on the poll timer and determine that it is still running, - * but then the timer expires immiately. That should not be problem, - * however, the poll timer is queued processing should be in the work - * queue and should execute immediately after we complete the TX poll. - * Inefficient, but not fatal. - */ - - delay = wd_gettime(priv->txpoll); - if (delay <= 0) - { - /* The poll timer is not running .. restart it. This is necessary - * to avoid certain race conditions where the polling sequence can - * be interrupted. - */ - - (void)wd_start(priv->txpoll, STM32_WDDELAY, stm32_poll_expiry, - 1, priv); - } - /* And disable further TX interrupts. */ stm32_disableint(priv, ETH_DMAINT_TI); @@ -2117,13 +2097,9 @@ static int stm32_interrupt(int irq, FAR void *context, FAR void *arg) wd_cancel(priv->txtimeout); } - /* Cancel any pending poll work */ - - work_cancel(ETHWORK, &priv->work); - /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->work, stm32_interrupt_work, priv, 0); + work_queue(ETHWORK, &priv->irqwork, stm32_interrupt_work, priv, 0); } return OK; @@ -2196,15 +2172,15 @@ static void stm32_txtimeout_expiry(int argc, uint32_t arg, ...) up_disable_irq(STM32_IRQ_ETH); - /* Cancel any pending poll or interrupt work. This will have no effect - * on work that has already been started. + /* Cancel any pending interrupt work. This will have no effect on work that + * has already been started. */ - work_cancel(ETHWORK, &priv->work); + work_cancel(ETHWORK, &priv->irqwork); /* Schedule to perform the TX timeout processing on the worker thread. */ - work_queue(ETHWORK, &priv->work, stm32_txtimeout_work, priv, 0); + work_queue(ETHWORK, &priv->irqwork, stm32_txtimeout_work, priv, 0); } /**************************************************************************** @@ -2305,11 +2281,11 @@ static void stm32_poll_expiry(int argc, uint32_t arg, ...) * pending interrupt actions. */ - if (work_available(&priv->work)) + if (work_available(&priv->pollwork)) { /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->work, stm32_poll_work, priv, 0); + work_queue(ETHWORK, &priv->pollwork, stm32_poll_work, priv, 0); } else { @@ -2487,11 +2463,11 @@ static int stm32_txavail(struct net_driver_s *dev) * availability action. */ - if (work_available(&priv->work)) + if (work_available(&priv->pollwork)) { /* Schedule to serialize the poll on the worker thread. */ - work_queue(ETHWORK, &priv->work, stm32_txavail_work, priv, 0); + work_queue(ETHWORK, &priv->pollwork, stm32_txavail_work, priv, 0); } return OK; diff --git a/arch/arm/src/stm32/stm32_exti.h b/arch/arm/src/stm32/stm32_exti.h index 3a395abe372..9ac20798df2 100644 --- a/arch/arm/src/stm32/stm32_exti.h +++ b/arch/arm/src/stm32/stm32_exti.h @@ -72,22 +72,21 @@ extern "C" * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: gpio pin configuration * - rising/falling edge: enables * - event: generate event when set * - func: when non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ************************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /************************************************************************************ * Name: stm32_exti_alarm @@ -95,22 +94,21 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, * Description: * Sets/clears EXTI alarm interrupt. * - * Parameters: + * Input Parameters: * - rising/falling edge: enables interrupt on rising/falling edges * - event: generate event when set * - func: when non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ************************************************************************************/ #ifdef CONFIG_RTC_ALARM -xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, xcpt_t func, - void *arg); +int stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, xcpt_t func, + void *arg); #endif #undef EXTERN diff --git a/arch/arm/src/stm32/stm32_exti_alarm.c b/arch/arm/src/stm32/stm32_exti_alarm.c index 67902e11c8e..12000d26af5 100644 --- a/arch/arm/src/stm32/stm32_exti_alarm.c +++ b/arch/arm/src/stm32/stm32_exti_alarm.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32_exti_alarm.c * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Diego Sanchez * @@ -109,20 +109,16 @@ static int stm32_exti_alarm_isr(int irq, void *context, FAR void *arg) * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ -xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg) +int stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg) { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_alarm_callback; g_alarm_callback = func; g_callback_arg = arg; @@ -158,5 +154,5 @@ xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, /* Return the old IRQ handler */ - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32/stm32_exti_gpio.c b/arch/arm/src/stm32/stm32_exti_gpio.c index 5945c35e5c9..663c0416b85 100644 --- a/arch/arm/src/stm32/stm32_exti_gpio.c +++ b/arch/arm/src/stm32/stm32_exti_gpio.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32_exti_gpio.c * - * Copyright (C) 2009, 2011-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved. * Author: Gregory Nutt * Uros Platise @@ -250,7 +250,7 @@ static int stm32_exti1510_isr(int irq, void *context, void *arg) * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: GPIO pin configuration * - risingedge: Enables interrupt on rising edges * - fallingedge: Enables interrupt on falling edges @@ -258,22 +258,20 @@ static int stm32_exti1510_isr(int irq, void *context, void *arg) * - func: When non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg) +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg) { FAR struct gpio_callback_s *shared_cbs; uint32_t pin = pinset & GPIO_PIN_MASK; uint32_t exti = STM32_EXTI_BIT(pin); int irq; xcpt_t handler; - xcpt_t oldhandler = NULL; int nshared; int i; @@ -324,7 +322,6 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_gpio_callbacks[pin].callback; g_gpio_callbacks[pin].callback = func; g_gpio_callbacks[pin].arg = arg; @@ -384,7 +381,5 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, func ? 0 : exti, func ? exti : 0); - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32/stm32_exti_pwr.c b/arch/arm/src/stm32/stm32_exti_pwr.c index 81cad7b5008..5ab6138ac4b 100644 --- a/arch/arm/src/stm32/stm32_exti_pwr.c +++ b/arch/arm/src/stm32/stm32_exti_pwr.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32_exti_pwr.c * - * Copyright (C) 2009, 2011-2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Haltian Ltd. All rights reserved. * Authors: Gregory Nutt * Dmitry Nikolaev @@ -115,20 +115,16 @@ static int stm32_exti_pvd_isr(int irq, void *context, FAR void *arg) * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg) +int stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg) { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_pvd_callback; g_pvd_callback = func; g_callback_arg = arg; @@ -162,7 +158,5 @@ xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, func ? 0 : EXTI_PVD_LINE, func ? EXTI_PVD_LINE : 0); - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32/stm32_exti_pwr.h b/arch/arm/src/stm32/stm32_exti_pwr.h index 26be9bb0ef6..c4841dffebe 100644 --- a/arch/arm/src/stm32/stm32_exti_pwr.h +++ b/arch/arm/src/stm32/stm32_exti_pwr.h @@ -60,13 +60,12 @@ * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg); +int stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); #endif /* STM32_EXTI_PWR_H_ */ diff --git a/arch/arm/src/stm32/stm32_gpio.h b/arch/arm/src/stm32/stm32_gpio.h index 06e09efc2b2..0385d1e9519 100644 --- a/arch/arm/src/stm32/stm32_gpio.h +++ b/arch/arm/src/stm32/stm32_gpio.h @@ -432,7 +432,7 @@ EXTERN const uint32_t g_gpiobase[STM32_NGPIO_PORTS]; * function, it must be unconfigured with stm32_unconfiggpio() with * the same cfgset first before it can be set to non-alternative function. * - * Returns: + * Returned Value: * OK on success * ERROR on invalid port, or when pin is locked as ALT function. * @@ -453,7 +453,7 @@ int stm32_configgpio(uint32_t cfgset); * operate in PWM mode could produce excessive on-board currents and trigger * over-current/alarm function. * - * Returns: + * Returned Value: * OK on success * ERROR on invalid port * @@ -487,22 +487,21 @@ bool stm32_gpioread(uint32_t pinset); * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: gpio pin configuration * - rising/falling edge: enables * - event: generate event when set * - func: when non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ************************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /************************************************************************************ * Function: stm32_dumpgpio diff --git a/arch/arm/src/stm32/stm32_sdio.c b/arch/arm/src/stm32/stm32_sdio.c index 5b7f92887c8..01d533ba704 100644 --- a/arch/arm/src/stm32/stm32_sdio.c +++ b/arch/arm/src/stm32/stm32_sdio.c @@ -668,16 +668,16 @@ static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask, /* Arm the SDIO_D Ready and install Isr */ - stm32_gpiosetevent(pinset, true, false, false, - stm32_rdyinterrupt, priv); + (void)stm32_gpiosetevent(pinset, true, false, false, + stm32_rdyinterrupt, priv); } /* Disarm SDIO_D ready */ if ((wkupevent & SDIOWAIT_WRCOMPLETE) != 0) { - stm32_gpiosetevent(GPIO_SDIO_D0, false, false, false, - NULL, NULL); + (void)stm32_gpiosetevent(GPIO_SDIO_D0, false, false, false, + NULL, NULL); stm32_configgpio(GPIO_SDIO_D0); } #endif diff --git a/arch/arm/src/stm32/stm32f40xxx_rtcc.c b/arch/arm/src/stm32/stm32f40xxx_rtcc.c index aa16b5fc9e6..4e8cfc773be 100644 --- a/arch/arm/src/stm32/stm32f40xxx_rtcc.c +++ b/arch/arm/src/stm32/stm32f40xxx_rtcc.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32/stm32f40xxx_rtcc.c * - * Copyright (C) 2012-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Modified: Neil Hancock * @@ -847,7 +847,7 @@ static inline void rtc_enable_alarm(void) * 3. Configure the RTC to generate RTC alarms (Alarm A or Alarm B). */ - stm32_exti_alarm(true, false, true, stm32_rtc_alarm_handler, NULL); + (void)stm32_exti_alarm(true, false, true, stm32_rtc_alarm_handler, NULL); g_alarm_enabled = true; } } diff --git a/arch/arm/src/stm32f7/stm32_exti.h b/arch/arm/src/stm32f7/stm32_exti.h index 03c621f7b6b..f9b1f2eaa0c 100644 --- a/arch/arm/src/stm32f7/stm32_exti.h +++ b/arch/arm/src/stm32f7/stm32_exti.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32f7/stm32_exti.h * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -72,7 +72,7 @@ extern "C" * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: GPIO pin configuration * - risingedge: Enables interrupt on rising edges * - fallingedge: Enables interrupt on falling edges @@ -80,15 +80,14 @@ extern "C" * - func: When non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * - ****************************************************************************/ + ************************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /**************************************************************************** * Name: stm32_exti_alarm @@ -96,23 +95,22 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, * Description: * Sets/clears EXTI alarm interrupt. * - * Parameters: + * Input Parameters: * - risingedge: Enables interrupt on rising edges * - fallingedge: Enables interrupt on falling edges * - event: Generate event when set * - func: When non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ #ifdef CONFIG_RTC_ALARM -xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg); +int stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); #endif #undef EXTERN diff --git a/arch/arm/src/stm32f7/stm32_exti_alarm.c b/arch/arm/src/stm32f7/stm32_exti_alarm.c index 363166cfec0..9fd90d76185 100644 --- a/arch/arm/src/stm32f7/stm32_exti_alarm.c +++ b/arch/arm/src/stm32f7/stm32_exti_alarm.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32f7/stm32_exti_alarm.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * This file derives from similar logic for the STM32 F1: @@ -57,10 +57,6 @@ #include "stm32_gpio.h" #include "stm32_exti.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -121,20 +117,16 @@ static int stm32_exti_alarm_isr(int irq, void *context, FAR void *arg) * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ -xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg) +int stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg) { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_alarm_callback; g_alarm_callback = func; g_callback_arg = arg; @@ -170,5 +162,5 @@ xcpt_t stm32_exti_alarm(bool risingedge, bool fallingedge, bool event, /* Return the old IRQ handler */ - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32f7/stm32_exti_gpio.c b/arch/arm/src/stm32f7/stm32_exti_gpio.c index 22efc0bf419..e3880545159 100644 --- a/arch/arm/src/stm32f7/stm32_exti_gpio.c +++ b/arch/arm/src/stm32f7/stm32_exti_gpio.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32f7/stm32_exti_gpio.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Based on EXTI GPIO logic from the Cortex-M3/4 which includes contributions @@ -262,7 +262,7 @@ static int stm32_exti1510_isr(int irq, void *context, void *arg) * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: GPIO pin configuration * - risingedge: Enables interrupt on rising edges * - fallingedge: Enables interrupt on falling edges @@ -270,22 +270,20 @@ static int stm32_exti1510_isr(int irq, void *context, void *arg) * - func: When non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg) +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg) { struct gpio_callback_s *shared_cbs; uint32_t pin = pinset & GPIO_PIN_MASK; uint32_t exti = STM32_EXTI_BIT(pin); int irq; xcpt_t handler; - xcpt_t oldhandler = NULL; int nshared; int i; @@ -336,7 +334,6 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_gpio_callbacks[pin].callback; g_gpio_callbacks[pin].callback = func; g_gpio_callbacks[pin].arg = arg; @@ -396,9 +393,7 @@ xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, func ? 0 : exti, func ? exti : 0); - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } #endif /* CONFIG_STM32F7_STM32F74XX || CONFIG_STM32F7_STM32F75XX */ diff --git a/arch/arm/src/stm32f7/stm32_exti_pwr.c b/arch/arm/src/stm32f7/stm32_exti_pwr.c index 54239c777ad..09d064e930e 100644 --- a/arch/arm/src/stm32f7/stm32_exti_pwr.c +++ b/arch/arm/src/stm32f7/stm32_exti_pwr.c @@ -123,20 +123,16 @@ static int stm32_exti_pvd_isr(int irq, void *context, void *arg) * - func: when non-NULL, generate 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg) +int stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_pvd_callback; g_pvd_callback = func; g_callback_arg = arg; @@ -170,7 +166,5 @@ xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, func ? 0 : EXTI_PVD_LINE, func ? EXTI_PVD_LINE : 0); - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32f7/stm32_exti_pwr.h b/arch/arm/src/stm32f7/stm32_exti_pwr.h index 521e7a7b2a7..67e22d05ff8 100644 --- a/arch/arm/src/stm32f7/stm32_exti_pwr.h +++ b/arch/arm/src/stm32f7/stm32_exti_pwr.h @@ -61,13 +61,12 @@ * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg); +int stm32_exti_pvd(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); #endif /* __ARCH_ARM_SRC_STM32F7_STM32_EXTI_PWR_H */ diff --git a/arch/arm/src/stm32f7/stm32_gpio.h b/arch/arm/src/stm32f7/stm32_gpio.h index 70bb15897a4..35b7fc39d25 100644 --- a/arch/arm/src/stm32f7/stm32_gpio.h +++ b/arch/arm/src/stm32f7/stm32_gpio.h @@ -266,7 +266,7 @@ EXTERN const uint32_t g_gpiobase[STM32F7_NGPIO]; * function, it must be unconfigured with stm32_unconfiggpio() with * the same cfgset first before it can be set to non-alternative function. * - * Returns: + * Returned Value: * OK on success * ERROR on invalid port, or when pin is locked as ALT function. * @@ -287,7 +287,7 @@ int stm32_configgpio(uint32_t cfgset); * operate in PWM mode could produce excessive on-board currents and trigger * over-current/alarm function. * - * Returns: + * Returned Value: * OK on success * ERROR on invalid port * @@ -321,7 +321,7 @@ bool stm32_gpioread(uint32_t pinset); * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: + * Input Parameters: * - pinset: GPIO pin configuration * - risingedge: Enables interrupt on rising edges * - fallingedge: Enables interrupt on falling edges @@ -329,15 +329,14 @@ bool stm32_gpioread(uint32_t pinset); * - func: When non-NULL, generate interrupt * - arg: Argument passed to the interrupt callback * - * 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) on success; a negated errno value on failure indicating the + * nature of the failure. * - ****************************************************************************/ + ************************************************************************************/ -xcpt_t stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /************************************************************************************ * Function: stm32_dumpgpio diff --git a/arch/arm/src/stm32f7/stm32_rtc.c b/arch/arm/src/stm32f7/stm32_rtc.c index 5445c01de97..8a21ec41fea 100644 --- a/arch/arm/src/stm32f7/stm32_rtc.c +++ b/arch/arm/src/stm32f7/stm32_rtc.c @@ -1037,7 +1037,7 @@ int up_rtc_initialize(void) * 3. Configure the RTC to generate RTC alarms (Alarm A or Alarm B). */ - stm32_exti_alarm(true, false, true, stm32_rtc_alarm_handler); + (void)stm32_exti_alarm(true, false, true, stm32_rtc_alarm_handler, NULL); rtc_dumpregs("After InitExtiAlarm"); #else rtc_dumpregs("After Initialization"); diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c index df02d4fb0e6..fee9b7600fe 100644 --- a/arch/arm/src/stm32f7/stm32_sdmmc.c +++ b/arch/arm/src/stm32f7/stm32_sdmmc.c @@ -846,16 +846,16 @@ static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask, /* Arm the SDMMC_D Ready and install Isr */ - stm32_gpiosetevent(pinset, true, false, false, - priv->wrchandler, priv); + (void)stm32_gpiosetevent(pinset, true, false, false, + priv->wrchandler, priv); } /* Disarm SDMMC_D ready */ if ((wkupevent & SDIOWAIT_WRCOMPLETE) != 0) { - stm32_gpiosetevent(priv->d0_gpio, false, false, false, - NULL, NULL); + (void)stm32_gpiosetevent(priv->d0_gpio, false, false, false, + NULL, NULL); stm32_configgpio(priv->d0_gpio); } #endif diff --git a/arch/arm/src/stm32l4/stm32l4_exti.h b/arch/arm/src/stm32l4/stm32l4_exti.h index d090ea7d483..2f57229ea21 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti.h +++ b/arch/arm/src/stm32l4/stm32l4_exti.h @@ -72,22 +72,22 @@ extern "C" * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: - * - pinset: gpio pin configuration - * - rising/falling edge: enables - * - event: generate event when set - * - func: when non-NULL, generate interrupt - * - arg: Argument passed to the interrupt callback + * Input Parameters: + * pinset - GPIO pin configuration + * risingedge - Enables interrupt on rising edges + * fallingedge - Enables interrupt on falling edges + * event - Generate event when set + * func - When non-NULL, generate interrupt + * arg - Argument passed to the interrupt callback * - * 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, otherwise a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ -xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /**************************************************************************** * Name: stm32l4_exti_alarm @@ -102,15 +102,14 @@ xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ #ifdef CONFIG_RTC_ALARM -xcpt_t stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg); +int stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); #endif /**************************************************************************** @@ -127,15 +126,14 @@ xcpt_t stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_STM32L4_COMP -xcpt_t stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); #endif #undef EXTERN diff --git a/arch/arm/src/stm32l4/stm32l4_exti_alarm.c b/arch/arm/src/stm32l4/stm32l4_exti_alarm.c index af0dac1bd93..d4fbfd6c039 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti_alarm.c +++ b/arch/arm/src/stm32l4/stm32l4_exti_alarm.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/stm32l4/stm32l4_exti_alarm.c * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Diego Sanchez * dev@ziggurat29.com (adaptation to stm32l4) @@ -109,20 +109,16 @@ static int stm32l4_exti_alarm_isr(int irq, void *context, FAR void *arg) * - func: when non-NULL, generate 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. + * Zero (OK) on success; a negated errno value on failure indicating the + * nature of the failure. * ****************************************************************************/ -xcpt_t stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg) +int stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg) { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_alarm_callback; g_alarm_callback = func; g_callback_arg = arg; @@ -158,5 +154,5 @@ xcpt_t stm32l4_exti_alarm(bool risingedge, bool fallingedge, bool event, /* Return the old IRQ handler */ - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32l4/stm32l4_exti_comp.c b/arch/arm/src/stm32l4/stm32l4_exti_comp.c index 7c508a11668..a1295b6970b 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti_comp.c +++ b/arch/arm/src/stm32l4/stm32l4_exti_comp.c @@ -129,16 +129,14 @@ static int stm32l4_exti_comp_isr(int irq, void *context) * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg) +int stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg) { - xcpt_t oldhandler; irqstate_t flags; uint32_t ln = g_comp_lines[cmp]; @@ -152,7 +150,7 @@ xcpt_t stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, if (func != NULL) { - irq_attach(STM32L4_IRQ_COMP, stm32l4_exti_comp_isr); + irq_attach(STM32L4_IRQ_COMP, stm32l4_exti_comp_isr, NULL); up_enable_irq(STM32L4_IRQ_COMP); } else @@ -172,15 +170,11 @@ xcpt_t stm32l4_exti_comp(int cmp, bool risingedge, bool fallingedge, /* Get the previous IRQ handler and save the new IRQ handler. */ - oldhandler = g_comp_handlers[cmp].callback; g_comp_handlers[cmp].callback = func; g_comp_handlers[cmp].arg = arg; /* Leave the critical section */ leave_critical_section(flags); - - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32l4/stm32l4_exti_gpio.c b/arch/arm/src/stm32l4/stm32l4_exti_gpio.c index e0eeabe529f..4a23c936320 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti_gpio.c +++ b/arch/arm/src/stm32l4/stm32l4_exti_gpio.c @@ -61,8 +61,8 @@ struct gpio_callback_s { - xcpt_t callback; - void *arg; + xcpt_t callback; /* Callback entry point */ + void *arg; /* The argument that accompanies the callback */ }; /**************************************************************************** @@ -249,23 +249,25 @@ static int stm32l4_exti1510_isr(int irq, void *context, FAR void *arg) * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: - * - pinset: GPIO pin configuration - * - risingedge: Enables interrupt on rising edges - * - fallingedge: Enables interrupt on falling edges - * - event: Generate event when set - * - func: When non-NULL, generate interrupt - * - arg: Argument passed to the interrupt callback + * Description: + * Sets/clears GPIO based event and interrupt triggers. * - * 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. + * Input Parameters: + * pinset - GPIO pin configuration + * risingedge - Enables interrupt on rising edges + * fallingedge - Enables interrupt on falling edges + * event - Generate event when set + * func - When non-NULL, generate interrupt + * arg - Argument passed to the interrupt callback * - ****************************************************************************/ + * Returned Value: + * Zero (OK) is returned on success, otherwise a negated errno value is returned + * to indicate the nature of the failure. + * + ************************************************************************************/ -xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg) +int stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg) { struct gpio_callback_s *shared_cbs; uint32_t pin = pinset & GPIO_PIN_MASK; @@ -323,7 +325,6 @@ xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_gpio_handlers[pin].callback; g_gpio_handlers[pin].callback = func; g_gpio_handlers[pin].arg = arg; @@ -385,5 +386,5 @@ xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, /* Return the old IRQ handler */ - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32l4/stm32l4_exti_pwr.c b/arch/arm/src/stm32l4/stm32l4_exti_pwr.c index 62c1dcfa572..ab19f6f3cb9 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti_pwr.c +++ b/arch/arm/src/stm32l4/stm32l4_exti_pwr.c @@ -114,20 +114,16 @@ static int stm32l4_exti_pvd_isr(int irq, void *context, FAR void *arg) * - func: when non-NULL, generate 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32l4_exti_pvd(bool risingedge, bool fallingedge, bool event, +int stm32l4_exti_pvd(bool risingedge, bool fallingedge, bool event, xcpt_t func, void *arg) { - xcpt_t oldhandler; - /* Get the previous GPIO IRQ handler; Save the new IRQ handler. */ - oldhandler = g_pvd_callback; g_pvd_callback = func; g_callback_arg = arg; @@ -161,7 +157,5 @@ xcpt_t stm32l4_exti_pvd(bool risingedge, bool fallingedge, bool event, func ? 0 : EXTI1_PVD_LINE, func ? EXTI1_PVD_LINE : 0); - /* Return the old IRQ handler */ - - return oldhandler; + return OK; } diff --git a/arch/arm/src/stm32l4/stm32l4_exti_pwr.h b/arch/arm/src/stm32l4/stm32l4_exti_pwr.h index 109da434588..27e584779b9 100644 --- a/arch/arm/src/stm32l4/stm32l4_exti_pwr.h +++ b/arch/arm/src/stm32l4/stm32l4_exti_pwr.h @@ -60,13 +60,12 @@ * - arg: Argument passed to the interrupt callback * * 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. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ -xcpt_t stm32l4_exti_pvd(bool risingedge, bool fallingedge, bool event, - xcpt_t func, void *arg); +int stm32l4_exti_pvd(bool risingedge, bool fallingedge, bool event, + xcpt_t func, void *arg); #endif /* STM32L4_EXTI_PWR_H_ */ diff --git a/arch/arm/src/stm32l4/stm32l4_gpio.h b/arch/arm/src/stm32l4/stm32l4_gpio.h index 17ce32162fb..5d4f74d58dc 100644 --- a/arch/arm/src/stm32l4/stm32l4_gpio.h +++ b/arch/arm/src/stm32l4/stm32l4_gpio.h @@ -326,22 +326,22 @@ bool stm32l4_gpioread(uint32_t pinset); * Description: * Sets/clears GPIO based event and interrupt triggers. * - * Parameters: - * - pinset: gpio pin configuration - * - rising/falling edge: enables - * - event: generate event when set - * - func: when non-NULL, generate interrupt - * - arg: Argument passed to the interrupt callback + * Input Parameters: + * pinset - GPIO pin configuration + * risingedge - Enables interrupt on rising edges + * fallingedge - Enables interrupt on falling edges + * event - Generate event when set + * func - When non-NULL, generate interrupt + * arg - Argument passed to the interrupt callback * - * 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, otherwise a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ -xcpt_t stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, - bool event, xcpt_t func, void *arg); +int stm32l4_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, + bool event, xcpt_t func, void *arg); /************************************************************************************ * Function: stm32l4_dumpgpio diff --git a/arch/arm/src/stm32l4/stm32l4_rtcc.c b/arch/arm/src/stm32l4/stm32l4_rtcc.c index 0d2627123be..a0221240f78 100644 --- a/arch/arm/src/stm32l4/stm32l4_rtcc.c +++ b/arch/arm/src/stm32l4/stm32l4_rtcc.c @@ -801,7 +801,7 @@ static inline void rtc_enable_alarm(void) * 3. Configure the RTC to generate RTC alarms (Alarm A or Alarm B). */ - stm32l4_exti_alarm(true, false, true, stm32l4_rtc_alarm_handler, NULL); + (void)stm32l4_exti_alarm(true, false, true, stm32l4_rtc_alarm_handler, NULL); g_alarm_enabled = true; } } diff --git a/arch/arm/src/tiva/tiva_gpio.h b/arch/arm/src/tiva/tiva_gpio.h index a20dccc15f0..54b12cf37ba 100644 --- a/arch/arm/src/tiva/tiva_gpio.h +++ b/arch/arm/src/tiva/tiva_gpio.h @@ -1,7 +1,7 @@ /**************************************************************************** * arch/arm/src/tiva/tiva_gpio.h * - * Copyright (C) 2009-2010, 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2010, 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * With modifications from Calvin Maguranis @@ -412,15 +412,19 @@ int weak_function tiva_gpioirqinitialize(void); * Name: tiva_gpioirqattach * * Description: - * Attach a GPIO interrupt to the provided 'isr' + * Attach in GPIO interrupt to the provided 'isr'. If isr==NULL, then the + * irq_unexpected_isr handler is assigned and the pin's interrupt mask is + * disabled to stop further interrupts. Otherwise, the new isr is linked + * and the pin's interrupt mask is set. * - * Returns: - * oldhandler - the old interrupt handler assigned to this pin. + * Returned Value: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * return to indicate the nature of the failure. * ****************************************************************************/ -xcpt_t tiva_gpioirqattach(uint32_t pinset, xcpt_t isr); -# define tiva_gpioirqdetach(pinset) tiva_gpioirqattach(pinset, NULL) +int tiva_gpioirqattach(uint32_t pinset, xcpt_t isr, void *arg); +# define tiva_gpioirqdetach(p) tiva_gpioirqattach((p),NULL,NULL) /**************************************************************************** * Name: tiva_gpioportirqattach diff --git a/arch/arm/src/tiva/tiva_gpioirq.c b/arch/arm/src/tiva/tiva_gpioirq.c index f8279d6f382..6e4a8228df5 100644 --- a/arch/arm/src/tiva/tiva_gpioirq.c +++ b/arch/arm/src/tiva/tiva_gpioirq.c @@ -66,17 +66,23 @@ #define TIVA_NIRQ_PINS (TIVA_NPORTS * TIVA_NPINS) #define TIVA_GPIO_IRQ_IDX(port,pin) ((port*TIVA_NPINS)+(pin)) +/**************************************************************************** + * Private types + ****************************************************************************/ + +struct gpio_handler_s +{ + xcpt_t isr; /* Interrupt service routine entry point */ + void *arg; /* The argument that accompanies the interrupt */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ /* A table of handlers for each GPIO port interrupt */ -static FAR xcpt_t g_gpioportirqvector[TIVA_NIRQ_PINS]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ +static struct gpio_handler_s g_gpioportirqvector[TIVA_NIRQ_PINS]; /**************************************************************************** * Private Functions @@ -303,12 +309,13 @@ static int tiva_gpioporthandler(uint8_t port, void *context) { if (((mis >> pin) & 1) != 0) { - gpioinfo("port=%d pin=%d irq=%p index=%d\n", - port, pin, - g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pin)], - TIVA_GPIO_IRQ_IDX(port, pin)); + int index = TIVA_GPIO_IRQ_IDX(port, pin); + FAR struct gpio_handler_s *handler = &g_gpioportirqvector[index]; - g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pin)](irq, context, NULL); + gpioinfo("port=%d pin=%d isr=%p arg=%p index=%d\n", + port, pin, handler->isr, handler->arg, index); + + handler->isr(irq, context, handler->arg); } } } @@ -557,7 +564,8 @@ int tiva_gpioirqinitialize(void) for (i = 0; i < TIVA_NIRQ_PINS; ++i) { - g_gpioportirqvector[i] = irq_unexpected_isr; + g_gpioportirqvector[i].isr = irq_unexpected_isr; + g_gpioportirqvector[i].arg = NULL; } gpioinfo("tiva_gpioirqinitialize isr=%d/%d irq_unexpected_isr=%p\n", @@ -665,28 +673,26 @@ int tiva_gpioirqinitialize(void) * and the pin's interrupt mask is set. * * Returns: - * oldhandler - the old interrupt handler assigned to this pin. + * Zero (OK) is returned on success. Otherwise a negated errno value is + * return to indicate the nature of the failure. * ****************************************************************************/ -xcpt_t tiva_gpioirqattach(uint32_t pinset, xcpt_t isr) +int tiva_gpioirqattach(uint32_t pinset, xcpt_t isr, void *arg) { + FAR stuct gpio_handler_s *handler; irqstate_t flags; - xcpt_t oldhandler = NULL; uint8_t port = (pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT; uint8_t pinno = (pinset & GPIO_PIN_MASK); uint8_t pin = 1 << pinno; + int index; - /* assign per-pin interrupt handlers */ + /* Assign per-pin interrupt handlers */ if (port < TIVA_NPORTS) { flags = enter_critical_section(); - /* store the older handler to return */ - - oldhandler = g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pinno)]; - /* If the new ISR is NULL, then the ISR is being detached. * In this case, disable the ISR and direct any interrupts * to the unexpected interrupt handler. @@ -695,21 +701,24 @@ xcpt_t tiva_gpioirqattach(uint32_t pinset, xcpt_t isr) gpioinfo("assign port=%d pin=%d function=%p to idx=%d\n", port, pinno, isr, TIVA_GPIO_IRQ_IDX(port, pinno)); + handler = &g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pinno)]; if (isr == NULL) { tiva_gpioirqdisable(port, pin); - g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pinno)] = irq_unexpected_isr; + handler->isr = irq_unexpected_isr; + handler->arg = NULL; } else { - g_gpioportirqvector[TIVA_GPIO_IRQ_IDX(port, pinno)] = isr; + handler->isr = isr; + handler->arg = arg; tiva_gpioirqenable(port, pin); } leave_critical_section(flags); } - return oldhandler; + return OK; } /**************************************************************************** diff --git a/arch/arm/src/tiva/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c_ethernet.c index f689028a9a3..6a6bc2d4eda 100644 --- a/arch/arm/src/tiva/tm4c_ethernet.c +++ b/arch/arm/src/tiva/tm4c_ethernet.c @@ -629,6 +629,7 @@ struct tiva_ethmac_s struct work_s work; /* For deferring work to the work queue */ #ifdef CONFIG_TIVA_PHY_INTERRUPTS xcpt_t handler; /* Attached PHY interrupt handler */ + void *arg; /* Argument that accompanies the interrupt */ #endif /* This holds the information visible to the NuttX network */ @@ -2165,9 +2166,9 @@ static int tiva_interrupt(int irq, FAR void *context, FAR void *arg) /* Dispatch to the registered handler */ - if (priv->handler) + if (priv->handler != NULL) { - (void)priv->handler(irq, context, arg); + (void)priv->handler(irq, context, priv->arg); } } #endif @@ -4254,23 +4255,22 @@ void up_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_TIVA_PHY_INTERRUPTS -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { struct tiva_ethmac_s *priv; irqstate_t flags; - xcpt_t oldhandler; DEBUGASSERT(intf); ninfo("%s: handler=%p\n", intf, handler); @@ -4290,10 +4290,10 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ + /* Save the new interrupt handler information */ - oldhandler = priv->handler; priv->handler = handler; + priv->arg = arg; /* Return with the interrupt disabled in any case */ @@ -4306,10 +4306,8 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) *enable = handler ? tiva_phy_intenable : NULL; } - /* Return the old handler (so that it can be restored) */ - leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_TIVA_PHY_INTERRUPTS */ diff --git a/arch/avr/src/at32uc3/at32uc3.h b/arch/avr/src/at32uc3/at32uc3.h index 47ecb3ad033..4fc12171ed4 100644 --- a/arch/avr/src/at32uc3/at32uc3.h +++ b/arch/avr/src/at32uc3/at32uc3.h @@ -296,7 +296,7 @@ void weak_function gpio_irqinitialize(void); ****************************************************************************/ #ifdef CONFIG_AVR32_GPIOIRQ -int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr); +int gpio_irqattach(int irq, xcpt_t handler, void *arg); #endif /**************************************************************************** diff --git a/arch/avr/src/at32uc3/at32uc3_gpioirq.c b/arch/avr/src/at32uc3/at32uc3_gpioirq.c index f525edd4451..66e82476554 100644 --- a/arch/avr/src/at32uc3/at32uc3_gpioirq.c +++ b/arch/avr/src/at32uc3/at32uc3_gpioirq.c @@ -57,20 +57,22 @@ #ifdef CONFIG_AVR32_GPIOIRQ /**************************************************************************** - * Pre-processor Definitions + * Private Types ****************************************************************************/ +struct g_gpiohandler_s +{ + xcpt_t handler; /* Interrupt handler entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; + /**************************************************************************** * Private Data ****************************************************************************/ /* A table of handlers for each GPIO interrupt */ -static FAR xcpt_t g_gpiohandler[NR_GPIO_IRQS]; - -/**************************************************************************** - * Public Data - ****************************************************************************/ +static struct g_gpiohandler_s g_gpiohandler[NR_GPIO_IRQS]; /**************************************************************************** * Private Functions @@ -221,10 +223,10 @@ static void gpio_porthandler(uint32_t regbase, int irqbase, uint32_t irqset, voi /* Dispatch handling for this pin */ - xcpt_t handler = g_gpiohandler[irq]; - if (handler) + xcpt_t handler = g_gpiohandler[irq].handler; + if (handler != NULL) { - handler(irq, context); + handler(irq, contex, g_gpiohandler[irq].arg); } else { @@ -304,7 +306,8 @@ void gpio_irqinitialize(void) for (i = 0; i < NR_GPIO_IRQS; i++) { - g_gpiohandler[i] = irq_unexpected_isr; + g_gpiohandler[i].handler = irq_unexpected_isr; + g_gpiohandler[i].arg = NULL; } /* Then attach the GPIO interrupt handlers */ @@ -325,7 +328,7 @@ void gpio_irqinitialize(void) * ****************************************************************************/ -int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr) +int gpio_irqattach(int irq, xcpt_t handler, void *arg) { irqstate_t flags; int ret = -EINVAL; @@ -338,25 +341,23 @@ int gpio_irqattach(int irq, xcpt_t newisr, xcpt_t *oldisr) */ flags = enter_critical_section(); - if (newisr == NULL) + if (handler == NULL) { gpio_irqdisable(irq); - newisr = irq_unexpected_isr; + + handler = irq_unexpected_isr; + arg = NULL; } - /* Return the old ISR (in case the caller ever wants to restore it) */ + /* Save the new ISR in the table. */ - if (oldisr) - { - *oldisr = g_gpiohandler[irq]; - } + g_gpiohandler[irq].handler = handler; + g_gpiohandler[irq].arg = arg; - /* Then save the new ISR in the table. */ - - g_gpiohandler[irq] = newisr; leave_critical_section(flags); ret = OK; } + return ret; } diff --git a/arch/mips/src/pic32mx/pic32mx-gpioirq.c b/arch/mips/src/pic32mx/pic32mx-gpioirq.c index ce96403da8c..9000618c7f6 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; /* Interrupt handler 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..a2de82ed5aa 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) (0) #endif /************************************************************************************ diff --git a/arch/mips/src/pic32mz/pic32mz-gpio.h b/arch/mips/src/pic32mz/pic32mz-gpio.h index d2c6389a992..17e6e6add61 100644 --- a/arch/mips/src/pic32mz/pic32mz-gpio.h +++ b/arch/mips/src/pic32mz/pic32mz-gpio.h @@ -199,22 +199,20 @@ void pic32mz_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) + * pinset - GPIO pin configuration + * 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_PIC32MZ_GPIOIRQ -xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler); +int pic32mz_gpioattach(uint32_t pinset, xcpt_t handler, void *arg); #else -# define pic32mz_gpioattach(p,f) (NULL) +# define pic32mz_gpioattach(p,h,a) (0) #endif /************************************************************************************ diff --git a/arch/mips/src/pic32mz/pic32mz-gpioirq.c b/arch/mips/src/pic32mz/pic32mz-gpioirq.c index 8e3106cc206..ed6d3cdf459 100644 --- a/arch/mips/src/pic32mz/pic32mz-gpioirq.c +++ b/arch/mips/src/pic32mz/pic32mz-gpioirq.c @@ -78,9 +78,15 @@ static int pic32mz_cninterrupt(int irq, FAR void *context, FAR void *arg); * Public Data ****************************************************************************/ +struct ioport_handler_s +{ + xcpt_t entry; /* Interrupt handler entry point */ + void *arg; /* The argument that accompanies the interrupt handler */ +}; + struct ioport_level2_s { - xcpt_t handler[16]; + struct ioport_handler_s handler[16]; }; /**************************************************************************** @@ -260,12 +266,12 @@ static int pic32mz_cninterrupt(int irq, FAR void *context, FAR void *arg) { /* Yes.. Has the user attached a handler? */ - handler = handlers->handler[i]; + handler = handlers->handler[i].entry; if (handler) { /* Yes.. call the attached handler */ - status = handler(irq, context); + status = handler(irq, context, handlers->handler[i].arg); /* Keep track of the status of the last handler that * failed. @@ -365,22 +371,21 @@ void pic32mz_gpioirqinitialize(void) * In that 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 - * - pin: The change notification number associated with the pin. - * - handler: Interrupt handler (may be NULL to detach) + * Input Parameters: + * pinset - GPIO pin configuration + * 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 pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) +#ifdef CONFIG_PIC32MZ_GPIOIRQ +int pic32mz_gpioattach(uint32_t pinset, xcpt_t handler, void *arg) { struct ioport_level2_s *handlers; - xcpt_t oldhandler = NULL; irqstate_t flags; uintptr_t base; int ioport; @@ -415,7 +420,6 @@ xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) /* Get the previously attached handler as the return value */ flags = enter_critical_section(); - oldhandler = handlers->handler[pin]; /* Are we attaching or detaching? */ @@ -467,12 +471,13 @@ xcpt_t pic32mz_gpioattach(pinset_t pinset, xcpt_t handler) /* Set the new handler (perhaps NULLifying the current handler) */ - handlers->handler[pin] = handler; + handlers->handler[pin].entry = handler; + handlers->handler[pin].arg = arg; leave_critical_section(flags); } } - return oldhandler; + return OK; } /**************************************************************************** diff --git a/configs/avr32dev1/src/avr32_buttons.c b/configs/avr32dev1/src/avr32_buttons.c index 228a43098a9..72191bb5855 100644 --- a/configs/avr32dev1/src/avr32_buttons.c +++ b/configs/avr32dev1/src/avr32_buttons.c @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -69,28 +70,26 @@ #if defined(CONFIG_AVR32_GPIOIRQ) && defined(CONFIG_ARCH_IRQBUTTONS) && \ (defined(CONFIG_AVR32DEV_BUTTON1_IRQ) || defined(CONFIG_AVR32DEV_BUTTON2_IRQ)) -static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, void *arg) +static int board_button_irqx(int irq, xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler; - /* Attach the handler */ - gpio_irqattach(irq, irqhandler, &oldhandler); - - /* Enable/disable the interrupt */ - - if (irqhandler) + int ret = gpio_irqattach(irq, irqhandler, &oldhandler, arg); + if (ret >= 0) { - gpio_irqenable(irq); - } - else - { - gpio_irqdisable(irq); + /* Enable/disable the interrupt */ + + if (irqhandler != NULL) + { + gpio_irqenable(irq); + } + else + { + gpio_irqdisable(irq); + } } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -143,8 +142,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -156,25 +154,29 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_AVR32_GPIOIRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { + int ret; + #ifdef CONFIG_AVR32DEV_BUTTON1_IRQ if (id == BUTTON1) { - return board_button_irqx(GPIO_BUTTON1_IRQ, irqhandler, arg); + ret = board_button_irqx(GPIO_BUTTON1_IRQ, irqhandler, arg); } else #endif #ifdef CONFIG_AVR32DEV_BUTTON2_IRQ if (id == BUTTON2) { - return board_button_irqx(GPIO_BUTTON2_IRQ, irqhandler, arg); + ret = board_button_irqx(GPIO_BUTTON2_IRQ, irqhandler, arg); } else #endif { - return NULL; + ret = -EINVAL; } + + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/bambino-200e/src/lpc43_buttons.c b/configs/bambino-200e/src/lpc43_buttons.c index dbaf33d1b53..8aaeac3c95c 100644 --- a/configs/bambino-200e/src/lpc43_buttons.c +++ b/configs/bambino-200e/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/bambino-200e/src/lpc43_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Alan Carvalho de Assis acassis@gmail.com [nuttx] * @@ -66,13 +66,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = BAMBINO_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -161,8 +155,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -172,9 +165,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -182,11 +174,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -200,7 +187,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -210,10 +197,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + return OK; } #endif diff --git a/configs/cc3200-launchpad/include/board.h b/configs/cc3200-launchpad/include/board.h index 53e0a80f399..540eb03190b 100644 --- a/configs/cc3200-launchpad/include/board.h +++ b/configs/cc3200-launchpad/include/board.h @@ -192,60 +192,5 @@ void tiva_boardinitialize(void); -/************************************************************************************ - * Name: up_buttoninit - * - * Description: - * up_buttoninit() must be called to initialize button resources. After that, - * up_buttons() may be called to collect the current state of all buttons or - * up_irqbutton() may be called to register button interrupt handlers. - * - ************************************************************************************/ - -#ifdef CONFIG_ARCH_BUTTONS -void up_buttoninit(void); - -/************************************************************************************ - * Name: up_buttons - * - * Description: - * up_buttoninit() must be called to initialize button resources. After that, - * up_buttons() may be called to collect the current state of all buttons. - * - * After up_buttoninit() has been called, up_buttons() may be called to collect - * the state of all buttons. up_buttons() returns an 8-bit bit set with each bit - * associated with a button. See the BOARD_BUTTON_*_BIT and BOARD_JOYSTICK_*_BIT - * definitions above for the meaning of each bit. - * - ************************************************************************************/ - -uint8_t up_buttons(void); - -/************************************************************************************ - * Button support. - * - * Description: - * up_buttoninit() must be called to initialize button resources. After that, - * up_irqbutton() may be called to register button interrupt handlers. - * - * up_irqbutton() may be called to register an interrupt handler that will be called - * when a button is depressed or released. The ID value is a button enumeration - * value that uniquely identifies a button resource. See the BOARD_BUTTON_* and - * BOARD_JOYSTICK_* definitions in above for the meaning of enumeration values - * The previous interrupt handler address is returned (so that it may restored, if - * so desired). - * - * Note that up_irqbutton() also enables button interrupts. Button interrupts - * will remain enabled after the interrupt handler is attached. Interrupts may - * be disabled (and detached) by calling up_irqbutton with irqhandler equal to - * NULL. - * - ************************************************************************************/ - -#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_TIVA_GPIO_IRQS) -xcpt_t up_irqbutton(int id, xcpt_t irqhandler); -#endif -#endif /* CONFIG_ARCH_BUTTONS */ - #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_CC3200_LAUNCHPAD_INCLUDE_BOARD_H */ diff --git a/configs/cloudctrl/src/stm32_buttons.c b/configs/cloudctrl/src/stm32_buttons.c index 5766e8ca331..b62dbeb719c 100644 --- a/configs/cloudctrl/src/stm32_buttons.c +++ b/configs/cloudctrl/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/cloudctrl/src/stm32_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 * Darcy Gong * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -151,27 +152,25 @@ uint8_t board_buttons(void) * board_button_irq() may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See - * the - * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of - * enumeration value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of + * enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/cloudctrl/src/stm32_usb.c b/configs/cloudctrl/src/stm32_usb.c index a1e889feb15..955377a5dd8 100644 --- a/configs/cloudctrl/src/stm32_usb.c +++ b/configs/cloudctrl/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/cloudctrl/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Darcy Gong * @@ -274,16 +274,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return NULL; + return -ENOSYS; } #endif diff --git a/configs/dk-tm4c129x/src/tm4c_buttons.c b/configs/dk-tm4c129x/src/tm4c_buttons.c index 69b1766a116..9d22ec36176 100644 --- a/configs/dk-tm4c129x/src/tm4c_buttons.c +++ b/configs/dk-tm4c129x/src/tm4c_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -144,18 +145,16 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_TIVA_GPIOP_IRQS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { static xcpt_t handler = NULL; - xcpt_t oldhandler = handler; irqstate_t flags; - int ret; + int ret = -EINVAL; /* Interrupts are supported only on ports P and Q and, hence, only on button SW4 */ @@ -175,7 +174,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if (irqhandler) { - ret = irq_attach(IRQ_SW4, irqhandler, NULL); + ret = irq_attach(IRQ_SW4, irqhandler, arg); if (ret == OK) { handler = irqhandler; @@ -186,7 +185,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) leave_critical_section(flags); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/ea3131/src/lpc31_usbhost.c b/configs/ea3131/src/lpc31_usbhost.c index a1b86a759ff..fe16aa16378 100644 --- a/configs/ea3131/src/lpc31_usbhost.c +++ b/configs/ea3131/src/lpc31_usbhost.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/ea3131/src/lpc31_usbhost.c * - * Copyright (C) 2013, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -82,12 +82,6 @@ static struct usbhost_connection_s *g_ehciconn; -/* Overcurrent interrupt handler */ - -#if 0 /* Not yet implemented */ -static xcpt_t g_ochandler; -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -292,16 +286,16 @@ void lpc31_usbhost_vbusdrive(int rhport, bool enable) * * Input parameter: * handler - New overcurrent interrupt handler + * arg - The argument that will accompany the interrupt * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) returned on success; a negated errno value is returned on failure. * ************************************************************************************/ #if 0 /* Not ready yet */ -xcpt_t lpc31_setup_overcurrent(xcpt_t handler) +int lpc31_setup_overcurrent(xcpt_t handler, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the @@ -310,18 +304,11 @@ xcpt_t lpc31_setup_overcurrent(xcpt_t handler) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_ochandler; - g_ochandler = handler; - /* Configure the interrupt */ #warning Missing logic - /* Return the old button handler (so that it can be restored) */ - leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* 0 */ diff --git a/configs/fire-stm32v2/src/stm32_buttons.c b/configs/fire-stm32v2/src/stm32_buttons.c index aac98c1973a..d2dd07cd8ef 100644 --- a/configs/fire-stm32v2/src/stm32_buttons.c +++ b/configs/fire-stm32v2/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/fire-stm32v2/src/stm32_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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -128,15 +129,15 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See * the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of - * enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * enumeration values. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { uint16_t gpio; + int ret; if (id == BUTTON_KEY1) { @@ -148,7 +149,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } return stm32_gpiosetevent(gpio, true, true, true, irqhandler, arg); diff --git a/configs/freedom-k64f/src/k64_buttons.c b/configs/freedom-k64f/src/k64_buttons.c index 659b55497b5..0c9f22e8c86 100644 --- a/configs/freedom-k64f/src/k64_buttons.c +++ b/configs/freedom-k64f/src/k64_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -127,16 +128,15 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler; uint32_t pinset; + int ret; /* Map the button id to the GPIO bit set. */ @@ -150,7 +150,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -159,12 +159,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - oldhandler = knetis_pinirqattach(pinset, irqhandler); + ret = kinetis_pinirqattach(pinset, irqhandler); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pindmaenable(pinset); + } - kinetis_pindmaenable(pinset); - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/freedom-k64f/src/k64_sdhc.c b/configs/freedom-k64f/src/k64_sdhc.c index d9a25eb19b8..9efec40ce9d 100644 --- a/configs/freedom-k64f/src/k64_sdhc.c +++ b/configs/freedom-k64f/src/k64_sdhc.c @@ -169,7 +169,7 @@ int k64_sdhc_initialize(void) /* Attached the card detect interrupt (but don't enable it yet) */ - kinetis_pinirqattach(GPIO_SD_CARDDETECT, k64_cdinterrupt, NULL); + (void)kinetis_pinirqattach(GPIO_SD_CARDDETECT, k64_cdinterrupt, NULL); /* Configure the write protect GPIO -- None */ diff --git a/configs/freedom-k66f/src/k66_buttons.c b/configs/freedom-k66f/src/k66_buttons.c index caa7da5bad7..966f742ead6 100644 --- a/configs/freedom-k66f/src/k66_buttons.c +++ b/configs/freedom-k66f/src/k66_buttons.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -131,15 +132,13 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler; uint32_t pinset; /* Map the button id to the GPIO bit set. */ @@ -154,7 +153,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -163,12 +162,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - oldhandler = kinetis_pinirqattach(pinset, irqhandler, NULL); + ret = kinetis_pinirqattach(pinset, irqhandler, NULL); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pinirqenable(pinset); + } - kinetis_pinirqenable(pinset); - return oldhandler; + return NULL; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/freedom-k66f/src/k66_sdhc.c b/configs/freedom-k66f/src/k66_sdhc.c index b89c9e93da9..ac2ac2dce57 100644 --- a/configs/freedom-k66f/src/k66_sdhc.c +++ b/configs/freedom-k66f/src/k66_sdhc.c @@ -170,7 +170,7 @@ int k66_sdhc_initialize(void) /* Attached the card detect interrupt (but don't enable it yet) */ - kinetis_pinirqattach(GPIO_SD_CARDDETECT, k66_cdinterrupt, NULL); + (void)kinetis_pinirqattach(GPIO_SD_CARDDETECT, k66_cdinterrupt, NULL); /* Configure the write protect GPIO -- None */ 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/hymini-stm32v/src/stm32_appinit.c b/configs/hymini-stm32v/src/stm32_appinit.c index 2697adcb213..2e1d99f7422 100644 --- a/configs/hymini-stm32v/src/stm32_appinit.c +++ b/configs/hymini-stm32v/src/stm32_appinit.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/hymini-stm32v/src/stm32_appinit.c * - * Copyright (C) 2009, 2011, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -182,7 +182,7 @@ int board_app_initialize(uintptr_t arg) /* Register an interrupt handler for the card detect pin */ - stm32_gpiosetevent(GPIO_SD_CD, true, true, true, nsh_cdinterrupt, NULL); + (void)stm32_gpiosetevent(GPIO_SD_CD, true, true, true, nsh_cdinterrupt, NULL); /* Mount the SDIO-based MMC/SD block driver */ diff --git a/configs/hymini-stm32v/src/stm32_buttons.c b/configs/hymini-stm32v/src/stm32_buttons.c index 578b2fa5b43..d92be06ab9d 100644 --- a/configs/hymini-stm32v/src/stm32_buttons.c +++ b/configs/hymini-stm32v/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/hymini-stm32v/src/stm32_buttons.c * - * Copyright (C) 2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -69,39 +70,44 @@ ****************************************************************************/ void board_button_initialize(void) - { - stm32_configgpio(GPIO_BTN_KEYA); - stm32_configgpio(GPIO_BTN_KEYB); - } +{ + stm32_configgpio(GPIO_BTN_KEYA); + stm32_configgpio(GPIO_BTN_KEYB); +} /**************************************************************************** * Name: board_buttons ****************************************************************************/ uint8_t board_buttons(void) - { - uint8_t ret = 0; - bool pinValue; +{ + uint8_t ret = 0; + bool pinValue; - /* Check that state of each key */ + /* Check that state of each key */ - /* Pin is pulled up */ - pinValue = stm32_gpioread(GPIO_BTN_KEYA); - if (!pinValue) - { - // Button pressed - ret = 1 << BUTTON_KEYA; - } + /* Pin is pulled up */ - /* Pin is pulled down */ - pinValue = stm32_gpioread(GPIO_BTN_KEYB); - if (pinValue) - { - // Button pressed - ret |= 1 << BUTTON_KEYB; - } - return ret; - } + pinValue = stm32_gpioread(GPIO_BTN_KEYA); + if (!pinValue) + { + /* Button pressed */ + + ret = 1 << BUTTON_KEYA; + } + + /* Pin is pulled down */ + + pinValue = stm32_gpioread(GPIO_BTN_KEYB); + if (pinValue) + { + /* Button pressed */ + + ret |= 1 << BUTTON_KEYB; + } + + return ret; +} /**************************************************************************** * Button support. @@ -122,28 +128,27 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See * the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) - { - xcpt_t oldhandler = NULL; - uint32_t pinset = GPIO_BTN_KEYA; +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +{ + uint32_t pinset = GPIO_BTN_KEYA; + int ret = -EINVAL; - if (id == 1) - { - pinset = GPIO_BTN_KEYB; - } - if (id < 2) - { - oldhandler = stm32_gpiosetevent(pinset, true, true, true, - irqhandler, arg); - } + if (id == 1) + { + pinset = GPIO_BTN_KEYB; + } - return oldhandler; - } + if (id < 2) + { + ret = stm32_gpiosetevent(pinset, true, true, true, irqhandler, arg); + } + + return ret; +} #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/hymini-stm32v/src/stm32_ts.c b/configs/hymini-stm32v/src/stm32_ts.c index e8889571d2b..781eafc9f15 100644 --- a/configs/hymini-stm32v/src/stm32_ts.c +++ b/configs/hymini-stm32v/src/stm32_ts.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/hymini-stm32v/src/stm32_ts.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Laurent Latil * @@ -93,25 +93,29 @@ static xcpt_t tc_isr; ************************************************************************************/ /* Attach the ADS7843E interrupt handler to the GPIO interrupt */ + static int hymini_ts_irq_attach(FAR struct ads7843e_config_s *state, xcpt_t isr) { iinfo("hymini_ts_irq_attach\n"); tc_isr = isr; - stm32_gpiosetevent(GPIO_TS_IRQ, true, true, true, isr, NULL); + (void)stm32_gpiosetevent(GPIO_TS_IRQ, true, true, true, isr, NULL); return OK; } /* Enable or disable the GPIO interrupt */ + static void hymini_ts_irq_enable(FAR struct ads7843e_config_s *state, - bool enable) + bool enable) { iinfo("%d\n", enable); - stm32_gpiosetevent(GPIO_TS_IRQ, true, true, true, enable ? tc_isr : NULL, NULL); + (void)stm32_gpiosetevent(GPIO_TS_IRQ, true, true, true, + enable ? tc_isr : NULL, NULL); } /* Acknowledge/clear any pending GPIO interrupt */ + static void hymini_ts_irq_clear(FAR struct ads7843e_config_s *state) { // FIXME Nothing to do ? diff --git a/configs/kwikstik-k40/src/k40_appinit.c b/configs/kwikstik-k40/src/k40_appinit.c index a336d96e473..790a094551f 100644 --- a/configs/kwikstik-k40/src/k40_appinit.c +++ b/configs/kwikstik-k40/src/k40_appinit.c @@ -217,7 +217,7 @@ int board_app_initialize(uintptr_t arg) /* Attached the card detect interrupt (but don't enable it yet) */ kinetis_pinconfig(GPIO_SD_CARDDETECT); - kinetis_pinirqattach(GPIO_SD_CARDDETECT, kinetis_cdinterrupt, NULL); + (void)kinetis_pinirqattach(GPIO_SD_CARDDETECT, kinetis_cdinterrupt, NULL); /* Mount the SDHC-based MMC/SD block driver */ /* First, get an instance of the SDHC interface */ diff --git a/configs/kwikstik-k40/src/k40_buttons.c b/configs/kwikstik-k40/src/k40_buttons.c index 3fff4a2333f..7057ab1bd83 100644 --- a/configs/kwikstik-k40/src/k40_buttons.c +++ b/configs/kwikstik-k40/src/k40_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/kwikstik-k40/src/k40_buttons.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,17 +100,16 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. * See the BUTTON_* and JOYSTICK_* definitions in board.h for the meaning - * of enumeration value. The previous interrupt handler address is - * returned (so that it may be restored, if so desired). + * of enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* The KwikStik-K40 board has no standard GPIO contact buttons */ - return NULL; + return -EINVAL; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/launchxl-tms57004/src/tms570_buttons.c b/configs/launchxl-tms57004/src/tms570_buttons.c index 68c8231926c..c0f307d2feb 100644 --- a/configs/launchxl-tms57004/src/tms570_buttons.c +++ b/configs/launchxl-tms57004/src/tms570_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/tms570_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -84,10 +85,9 @@ static xcpt_t g_irq_button; ****************************************************************************/ #ifdef HAVE_IRQBUTTONS -static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gio_pinset_t pinset, int irq, + xcpt_t irqhandler, xcpt_t *store, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -98,7 +98,6 @@ static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, /* Get the old button interrupt handler and save the new one */ - oldhandler = *store; *store = irqhandler; /* Are we attaching or detaching? */ @@ -123,7 +122,7 @@ static xcpt_t board_button_irqx(gio_pinset_t pinset, int irq, /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return OK; } #endif @@ -171,8 +170,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GIOIRQ must be selected to enable the @@ -183,7 +181,7 @@ uint8_t board_buttons(void) * ****************************************************************************/ -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef HAVE_IRQBUTTONS if (id == BUTTON_GIOA7) @@ -193,8 +191,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } #endif - return NULL; - + return -EINVAL; } #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/lincoln60/src/lpc17_buttons.c b/configs/lincoln60/src/lpc17_buttons.c index 5764415e4e1..bcee2e34f0f 100644 --- a/configs/lincoln60/src/lpc17_buttons.c +++ b/configs/lincoln60/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lincoln60/src/lpc17_buttons.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -69,13 +69,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LINCOLN60_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -168,8 +162,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -179,9 +172,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -189,11 +181,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -207,7 +194,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -217,9 +204,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/lpc4330-xplorer/src/lpc43_buttons.c b/configs/lpc4330-xplorer/src/lpc43_buttons.c index 33431b6f0ab..0d0f5db695c 100644 --- a/configs/lpc4330-xplorer/src/lpc43_buttons.c +++ b/configs/lpc4330-xplorer/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lpc4330-xplorer/src/lpc43_buttons.c * - * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -68,13 +68,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LPC4330_XPLORER_BUT1 }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -167,8 +161,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -178,9 +171,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -188,11 +180,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -206,7 +193,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -216,9 +203,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/lpc4357-evb/src/lpc43_buttons.c b/configs/lpc4357-evb/src/lpc43_buttons.c index feeab979a06..c62229d35c5 100644 --- a/configs/lpc4357-evb/src/lpc43_buttons.c +++ b/configs/lpc4357-evb/src/lpc43_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/lpc4357-evb/src/board_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -68,13 +69,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = { }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -173,8 +168,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -184,22 +178,17 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC43_GPIO_IRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #if 0 /* Not yet implemented */ - xcpt_t oldhandler = NULL; irqstate_t flags; + int ret = -EINVAL; int irq; /* Verify that the button ID is within range */ if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -213,7 +202,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -223,12 +212,14 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); + ret = OK; } - return oldhandler; + return ret; #else - return NULL; + return -ENOSYS; #endif /* Not yet implemented */ } #endif diff --git a/configs/mikroe-stm32f4/src/stm32_usb.c b/configs/mikroe-stm32f4/src/stm32_usb.c index 44321bd7d36..8047a631fd3 100644 --- a/configs/mikroe-stm32f4/src/stm32_usb.c +++ b/configs/mikroe-stm32f4/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/mikroe_stm32f4/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -273,16 +273,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/nucleo-144/src/stm32_buttons.c b/configs/nucleo-144/src/stm32_buttons.c index 7745758cb9d..ea520e84731 100644 --- a/configs/nucleo-144/src/stm32_buttons.c +++ b/configs/nucleo-144/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-144/src/stm32_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David Sidrane * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -99,23 +100,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { - oldhandler = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-144/src/stm32_sdio.c b/configs/nucleo-144/src/stm32_sdio.c index 0a79f9258dc..9b1de7415fe 100644 --- a/configs/nucleo-144/src/stm32_sdio.c +++ b/configs/nucleo-144/src/stm32_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/nucleo-144/src/stm32_sdio.c * - * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -132,8 +132,8 @@ int stm32_sdio_initialize(void) /* Register an interrupt handler for the card detect pin */ - stm32_gpiosetevent(GPIO_SDMMC1_NCD, true, true, true, - stm32_ncd_interrupt, NULL); + (void)stm32_gpiosetevent(GPIO_SDMMC1_NCD, true, true, true, + stm32_ncd_interrupt, NULL); #endif /* Mount the SDIO-based MMC/SD block driver */ diff --git a/configs/nucleo-144/src/stm32_usb.c b/configs/nucleo-144/src/stm32_usb.c index a1a2059176d..597570ae183 100644 --- a/configs/nucleo-144/src/stm32_usb.c +++ b/configs/nucleo-144/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs//nucleo-144/src/stm32_usb.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * David Sidrane * @@ -295,16 +295,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/nucleo-f303re/src/stm32_buttons.c b/configs/nucleo-f303re/src/stm32_buttons.c index f5dcc7224f2..65b046b819e 100644 --- a/configs/nucleo-f303re/src/stm32_buttons.c +++ b/configs/nucleo-f303re/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f303re/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved. * Authors: Gregory Nutt * Paul Alexander Patience @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -52,22 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -120,23 +105,22 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of the - * enumeration value. The previous interrupt handler address is returned - * (so that it may be restored, if so desired). + * enumeration value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { - oldhandler = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif diff --git a/configs/nucleo-f4x1re/src/stm32_buttons.c b/configs/nucleo-f4x1re/src/stm32_buttons.c index c93b03d21a9..ab019d2a5c3 100644 --- a/configs/nucleo-f4x1re/src/stm32_buttons.c +++ b/configs/nucleo-f4x1re/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f4x1re/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -117,23 +106,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { - oldhandler = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-f4x1re/src/stm32_io.c b/configs/nucleo-f4x1re/src/stm32_io.c index ba190495454..0fc399662ae 100644 --- a/configs/nucleo-f4x1re/src/stm32_io.c +++ b/configs/nucleo-f4x1re/src/stm32_io.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-f4x1re/src/stm32_io.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 @@ -40,6 +40,7 @@ #include #include +#include #include #include "chip/stm32_tim.h" @@ -48,18 +49,6 @@ #ifndef CONFIG_CC3000_PROBES -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -176,23 +165,21 @@ void up_write_outputs(int id, bool bits) * ****************************************************************************/ -xcpt_t up_irqio(int id, xcpt_t irqhandler) +int up_irqio(int id, xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id == 0) { - oldhandler = stm32_gpiosetevent(GPIO_D14, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_D14, true, true, true, irqhandler, arg); } else if (id == 1) { - oldhandler = stm32_gpiosetevent(GPIO_D15, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_D15, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif /* CONFIG_CC3000_PROBES */ diff --git a/configs/nucleo-l476rg/src/stm32_buttons.c b/configs/nucleo-l476rg/src/stm32_buttons.c index 63a96d7a92c..7da458ffb3c 100644 --- a/configs/nucleo-l476rg/src/stm32_buttons.c +++ b/configs/nucleo-l476rg/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-l476rg/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -117,23 +106,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { - oldhandler = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-l476rg/src/stm32_io.c b/configs/nucleo-l476rg/src/stm32_io.c index d6468c5d053..59e356d401a 100644 --- a/configs/nucleo-l476rg/src/stm32_io.c +++ b/configs/nucleo-l476rg/src/stm32_io.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/nucleo-l476rg/src/stm32_io.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 @@ -40,6 +40,7 @@ #include #include +#include #include #include "chip/stm32l4_tim.h" @@ -48,18 +49,6 @@ #ifndef CONFIG_CC3000_PROBES -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -176,23 +165,21 @@ void up_write_outputs(int id, bool bits) * ****************************************************************************/ -xcpt_t up_irqio(int id, xcpt_t irqhandler) +int up_irqio(int id, xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id == 0) { - oldhandler = stm32_gpiosetevent(GPIO_D14, true, true, true, - irqhandler, NULL); + ret = stm32_gpiosetevent(GPIO_D14, true, true, true, irqhandler, arg); } else if (id == 1) { - oldhandler = stm32_gpiosetevent(GPIO_D15, true, true, true, - irqhandler, NULL); + ret = stm32_gpiosetevent(GPIO_D15, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif /* CONFIG_CC3000_PROBES */ diff --git a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c index 10c0df1ae00..e2bcba1a58f 100644 --- a/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c +++ b/configs/olimex-efm32g880f128-stk/src/efm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-efm32g880f128-stk/src/efm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -75,9 +75,6 @@ ****************************************************************************/ #if defined(CONFIG_EFM32_GPIO_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -#if 0 /* REVISIT -- See comments in board_button_irq() */ -static xcpt_t g_button_handlers[NUM_BUTTONS]; -#endif static const uint8_t g_button_irqs[NUM_BUTTONS]; #endif @@ -154,8 +151,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_EFM32_GPIO_IRQ must be selected to enable the @@ -168,10 +164,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_EFM32_GPIO_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; - if (id >=0 && id < NUM_BUTTONS) { irqstate_t flags; @@ -182,19 +176,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get/set the old button handler - * - * REVISIT: Keeping copies of the hander in RAM seems wasteful - * since the OS already has this information internally. - */ - -#if 0 /* REVISIT */ - oldhandler = g_button_handlers[id]; - g_button_handlers[id] = irqhandler; -#else - oldhandler = NULL; -#endif - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -205,7 +186,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Attach and enable the interrupt */ - (void)irq_attach(g_button_irqs[id], irqhandler, NULL); + (void)irq_attach(g_button_irqs[id], irqhandler, arg); efm32_gpioirqenable(g_button_irqs[id]); } else @@ -221,7 +202,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return OK; } #endif diff --git a/configs/olimex-lpc-h3131/include/board.h b/configs/olimex-lpc-h3131/include/board.h index 395eddee2be..f9952ab740d 100644 --- a/configs/olimex-lpc-h3131/include/board.h +++ b/configs/olimex-lpc-h3131/include/board.h @@ -1,7 +1,7 @@ /************************************************************************************ * configs/olimex-lpc-h3131/include/board.h * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -187,14 +187,15 @@ void lpc31_boardinitialize(void); * * Input parameter: * handler - New overcurrent interrupt handler + * arg - The argument that will accompany the interrupt * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) returned on success; a negated errno value is returned on failure. * ************************************************************************************/ #if 0 /* Not ready yet */ -xcpt_t lpc31_setup_overcurrent(xcpt_t handler); +int lpc31_setup_overcurrent(xcpt_t handler, void *arg); #endif #endif /* __ASSEMBLY__ */ diff --git a/configs/olimex-lpc-h3131/src/lpc31_usbhost.c b/configs/olimex-lpc-h3131/src/lpc31_usbhost.c index a52f94d4582..18b865b7dbe 100644 --- a/configs/olimex-lpc-h3131/src/lpc31_usbhost.c +++ b/configs/olimex-lpc-h3131/src/lpc31_usbhost.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/olimex-lpc-h3131/src/lpc31_usbhost.c * - * Copyright (C) 2013, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -293,16 +293,16 @@ void lpc31_usbhost_vbusdrive(int rhport, bool enable) * * Input parameter: * handler - New overcurrent interrupt handler + * arg - The argument that will accompany the interrupt * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) returned on success; a negated errno value is returned on failure. * ************************************************************************************/ #if 0 /* Not ready yet */ -xcpt_t lpc31_setup_overcurrent(xcpt_t handler) +int lpc31_setup_overcurrent(xcpt_t handler, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the @@ -311,16 +311,9 @@ xcpt_t lpc31_setup_overcurrent(xcpt_t handler) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_ochandler; - g_ochandler = handler; - /* Configure the interrupt */ #warning Missing logic - /* Return the old button handler (so that it can be restored) */ - leave_critical_section(flags); return oldhandler; } diff --git a/configs/olimex-lpc1766stk/src/lpc17_buttons.c b/configs/olimex-lpc1766stk/src/lpc17_buttons.c index 3b541d94024..37326a82773 100644 --- a/configs/olimex-lpc1766stk/src/lpc17_buttons.c +++ b/configs/olimex-lpc1766stk/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-lpc1766stk/src/lpc17_buttons.c * - * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,13 +70,7 @@ static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] = LPC1766STK_UP, LPC1766STK_DOWN, LPC1766STK_LEFT, LPC1766STK_RIGHT }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -171,8 +165,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -182,9 +175,8 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; int irq; @@ -192,11 +184,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) if ((unsigned)id < BOARD_NUM_BUTTONS) { - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Disable interrupts until we are done */ flags = enter_critical_section(); @@ -210,7 +197,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -220,9 +207,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) up_disable_irq(irq); (void)irq_detach(irq); } + leave_critical_section(flags); } - return oldhandler; + + return OK; } #endif diff --git a/configs/olimex-stm32-e407/src/stm32_buttons.c b/configs/olimex-stm32-e407/src/stm32_buttons.c index 32681e5e2d9..870b1ff8a98 100644 --- a/configs/olimex-stm32-e407/src/stm32_buttons.c +++ b/configs/olimex-stm32-e407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-e407/src/stm32_buttons.c * - * Copyright (C) 2014-2016 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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -50,7 +51,7 @@ #ifdef CONFIG_ARCH_BUTTONS /**************************************************************************** - * Private Functions + * Private Data ****************************************************************************/ /* Pin configuration for each Olimex-STM32-H405 button. This array is @@ -127,25 +128,24 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = - stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-e407/src/stm32_usb.c b/configs/olimex-stm32-e407/src/stm32_usb.c index 55df883ba8d..f59dc54486b 100644 --- a/configs/olimex-stm32-e407/src/stm32_usb.c +++ b/configs/olimex-stm32-e407/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f4discovery/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015-2916 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -302,16 +302,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/olimex-stm32-h405/src/stm32_buttons.c b/configs/olimex-stm32-h405/src/stm32_buttons.c index 03092eaece8..c3b6aa92fee 100644 --- a/configs/olimex-stm32-h405/src/stm32_buttons.c +++ b/configs/olimex-stm32-h405/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-h405/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each Olimex-STM32-H405 button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -135,25 +128,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-h407/src/stm32_buttons.c b/configs/olimex-stm32-h407/src/stm32_buttons.c index da8c5657654..ed33810dd47 100644 --- a/configs/olimex-stm32-h407/src/stm32_buttons.c +++ b/configs/olimex-stm32-h407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-h407/src/stm32_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -50,7 +51,7 @@ #ifdef CONFIG_ARCH_BUTTONS /**************************************************************************** - * Private Functions + * Private Data ****************************************************************************/ /* Pin configuration for each Olimex-STM32-H405 button. This array is indexed by @@ -127,25 +128,24 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-h407/src/stm32_sdio.c b/configs/olimex-stm32-h407/src/stm32_sdio.c index f87e76c741e..5745ba5bd82 100644 --- a/configs/olimex-stm32-h407/src/stm32_sdio.c +++ b/configs/olimex-stm32-h407/src/stm32_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/olimex-stm32_h407/src/stm32_sdio.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -128,8 +128,8 @@ int stm32_sdio_initialize(void) /* Register an interrupt handler for the card detect pin */ - stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, - stm32_ncd_interrupt, NULL); + (void)stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, + stm32_ncd_interrupt, NULL); #endif /* Mount the SDIO-based MMC/SD block driver */ diff --git a/configs/olimex-stm32-h407/src/stm32_usb.c b/configs/olimex-stm32-h407/src/stm32_usb.c index 10cb1c16d46..a5148f1e578 100644 --- a/configs/olimex-stm32-h407/src/stm32_usb.c +++ b/configs/olimex-stm32-h407/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/olimex-stm32-h407/src/stm32_usbdev.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -280,16 +280,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameters: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * - * Returned Value: - * Old overcurrent interrupt handler + * Returned value: + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGHS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGHS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/olimex-stm32-p207/src/stm32_buttons.c b/configs/olimex-stm32-p207/src/stm32_buttons.c index 17c0cc50ff4..0002098298f 100644 --- a/configs/olimex-stm32-p207/src/stm32_buttons.c +++ b/configs/olimex-stm32-p207/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-p207/src/stm32_buttons.c * - * 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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM32F4 Discovery button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -171,25 +164,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-p207/src/stm32_usb.c b/configs/olimex-stm32-p207/src/stm32_usb.c index 9996da8b7fe..fdef1532dc0 100644 --- a/configs/olimex-stm32-p207/src/stm32_usb.c +++ b/configs/olimex-stm32-p207/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/olimex-stm32-p207/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -238,16 +238,18 @@ int stm32_usbhost_initialize(void) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/olimex-stm32-p407/src/stm32_buttons.c b/configs/olimex-stm32-p407/src/stm32_buttons.c index ab07a2ed1e9..6add698e0fa 100644 --- a/configs/olimex-stm32-p407/src/stm32_buttons.c +++ b/configs/olimex-stm32-p407/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-stm32-p407/src/stm32_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -52,7 +53,7 @@ #ifdef CONFIG_ARCH_BUTTONS /**************************************************************************** - * Private Functions + * Private Data ****************************************************************************/ /* Pin configuration for each STM32F4 Discovery button. This array is indexed by @@ -165,25 +166,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/olimex-stm32-p407/src/stm32_usb.c b/configs/olimex-stm32-p407/src/stm32_usb.c index 4c3799e3af0..aee3ecf5916 100644 --- a/configs/olimex-stm32-p407/src/stm32_usb.c +++ b/configs/olimex-stm32-p407/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/olimex-stm32-p407/src/stm32_usb.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -238,16 +238,18 @@ int stm32_usbhost_setup(void) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/olimexino-stm32/src/stm32_buttons.c b/configs/olimexino-stm32/src/stm32_buttons.c index 55021c3a948..971bdb79f22 100644 --- a/configs/olimexino-stm32/src/stm32_buttons.c +++ b/configs/olimexino-stm32/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimexino-stm32/src/stm32_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * David_s5 * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -50,21 +51,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ + /**************************************************************************** * Button support. * @@ -80,8 +70,7 @@ * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * value. * ****************************************************************************/ @@ -127,25 +116,24 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id == IRQBUTTON) { - oldhandler = stm32_gpiosetevent(BUTTON_BOOT0n, true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(BUTTON_BOOT0n, true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/open1788/src/lpc17_buttons.c b/configs/open1788/src/lpc17_buttons.c index c9313525524..e7a7cf88517 100644 --- a/configs/open1788/src/lpc17_buttons.c +++ b/configs/open1788/src/lpc17_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/open1788/src/lpc17_buttons.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -89,13 +90,7 @@ static const lpc17_pinset_t g_buttoncfg[BOARD_NUM_BUTTONS] = GPIO_JOY_B, GPIO_JOY_C, GPIO_JOY_D, GPIO_JOY_CTR }; -/* This array defines all of the interrupt handlers current attached to - * button events. - */ - #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS]; - /* This array provides the mapping from button ID numbers to button IRQ * numbers. */ @@ -189,8 +184,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning - * of enumeration values. The previous interrupt handler address is returned - * (so that it may restored, if so desired). + * of enumeration values. * * Note that board_button_irq() also enables button interrupts. Button * interrupts will remain enabled after the interrupt handler is attached. @@ -200,10 +194,10 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_LPC17_GPIOIRQ) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; irqstate_t flags; + int ret = -EINVAL; int irq; /* Verify that the button ID is within range */ @@ -221,11 +215,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Return the current button handler and set the new interrupt handler */ - - oldhandler = g_buttonisr[id]; - g_buttonisr[id] = irqhandler; - /* Configure the interrupt. Either attach and enable the new * interrupt or disable and detach the old interrupt handler. */ @@ -234,7 +223,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { /* Attach then enable the new interrupt handler */ - (void)irq_attach(irq, irqhandler, NULL); + (void)irq_attach(irq, irqhandler, arg); up_enable_irq(irq); } else @@ -247,9 +236,11 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) leave_critical_section(flags); } + + ret = OK; } - return oldhandler; + return ret; } #endif diff --git a/configs/pcduino-a10/src/a1x_buttons.c b/configs/pcduino-a10/src/a1x_buttons.c index 2cc53b81d6b..a690ae866dc 100644 --- a/configs/pcduino-a10/src/a1x_buttons.c +++ b/configs/pcduino-a10/src/a1x_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/pcduino-a10/src/a1x_buttons.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -52,22 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_ARCH_IRQBUTTONS -static xcpt_t g_irqbutton[BOARD_NBUTTONS]; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,8 +95,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_ARCH_IRQBUTTONS must be selected to enable the @@ -120,9 +104,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id < BOARD_NBUTTONS) { @@ -134,22 +118,17 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irqbutton[id]; - g_irqbutton[id] = irqhandler; - /* Configure the interrupt */ a1x_pioirq(xxx); - (void)irq_attach(xxx, irqhandler, NULL); + (void)irq_attach(xxx, irqhandler, arg); a1x_pioirqenable(xxx); leave_critical_section(flags); + + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/pic32mz-starterkit/src/pic32mz_buttons.c b/configs/pic32mz-starterkit/src/pic32mz_buttons.c index d5e06bd3104..a51ca05f08d 100644 --- a/configs/pic32mz-starterkit/src/pic32mz_buttons.c +++ b/configs/pic32mz-starterkit/src/pic32mz_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/pic32mz-starterkit/src/pic32mz_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -146,28 +147,27 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef CONFIG_PIC32MZ_GPIOIRQ_PORTB - xcpt_t oldhandler = NULL; + int ret = OK; if ((unsigned)id < NUM_BUTTONS) { /* Perform the attach/detach operation */ - oldhandler = pic32mz_gpioattach(g_buttons[id], irqhandler); + ret = pic32mz_gpioattach(g_buttons[id], irqhandler, arg); /* The interrupt is now disabled. Are we attaching or detaching from * button interrupt? */ - if (irqhandler) + if (ret >= 0) { /* Attaching... enable button interrupts now */ @@ -175,9 +175,9 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } } - return oldhandler; + return ret; #else - return NULL; + return -ENOSYS; #endif } #endif diff --git a/configs/sam3u-ek/src/sam_buttons.c b/configs/sam3u-ek/src/sam_buttons.c index 6bfdf269d54..520f05e1a54 100644 --- a/configs/sam3u-ek/src/sam_buttons.c +++ b/configs/sam3u-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam3u-ek/src/up_leds.c * - * Copyright (C) 2010, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,19 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqbutton1; -static xcpt_t g_irqbutton2; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -79,10 +67,9 @@ static xcpt_t g_irqbutton2; ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler, + void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -91,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -115,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -170,8 +149,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -183,21 +161,19 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { if (id == BUTTON1) { - return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, - irqhandler, &g_irqbutton1, arg); + return board_button_irqx(GPIO_BUTTON1, IRQ_BUTTON1, irqhandler, arg); } else if (id == BUTTON2) { - return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, - irqhandler, &g_irqbutton2, arg); + return board_button_irqx(GPIO_BUTTON2, IRQ_BUTTON2, irqhandler, arg); } else { - return NULL; + return -EINVAL; } } #endif diff --git a/configs/sam4e-ek/src/sam_buttons.c b/configs/sam4e-ek/src/sam_buttons.c index 23851d10832..d9fbabeb6d8 100644 --- a/configs/sam4e-ek/src/sam_buttons.c +++ b/configs/sam4e-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,21 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irq_scrollup; -static xcpt_t g_irq_scrolldown; -static xcpt_t g_irq_waku; -static xcpt_t g_irq_tamp; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -81,10 +67,9 @@ static xcpt_t g_irq_tamp; ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler, + void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -93,11 +78,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -117,10 +97,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -176,8 +153,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -189,28 +165,24 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { switch (id) { case BUTTON_SCROLLUP: - return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, - irqhandler, &g_irq_scrollup, arg); + return board_button_irqx(GPIO_SCROLLUP, IRQ_SCROLLUP, irqhandler, arg); case BUTTON_SCROLLDOWN: - return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, - irqhandler, &g_irq_scrolldown, arg); + return board_button_irqx(GPIO_SCROLLDWN, IRQ_SCROLLDWN, irqhandler, arg); case BUTTON_WAKU: - return board_button_irqx(GPIO_WAKU, IRQ_WAKU, - irqhandler, &g_irq_waku, arg); + return board_button_irqx(GPIO_WAKU, IRQ_WAKU, irqhandler, arg); case BUTTON_TAMP: - return board_button_irqx(GPIO_TAMP, IRQ_TAMP, - irqhandler, &g_irq_tamp, arg); + return board_button_irqx(GPIO_TAMP, IRQ_TAMP, irqhandler, arg); default: - return NULL; + return -EINVAL; } } #endif diff --git a/configs/sam4e-ek/src/sam_ethernet.c b/configs/sam4e-ek/src/sam_ethernet.c index c59e395e94f..7b41e6b6220 100644 --- a/configs/sam4e-ek/src/sam_ethernet.c +++ b/configs/sam4e-ek/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sam4e-ek/src/sam_ethernet.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 @@ -83,14 +83,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAM34_GPIOD_IRQ -static xcpt_t g_emac_handler; -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -184,23 +176,21 @@ void weak_function sam_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAM34_GPIOD_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; gpio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -213,7 +203,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAM34_EMAC_DEVNAME) == 0) { phyinfo("Select EMAC\n"); - phandler = &g_emac_handler; pinset = GPIO_PHY_IRQ; irq = SAM_PHY_IRQ; enabler = sam_emac_phy_enable; @@ -230,11 +219,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -243,7 +227,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_gpioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -266,7 +250,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAM34_GPIOD_IRQ */ diff --git a/configs/sam4l-xplained/src/sam_buttons.c b/configs/sam4l-xplained/src/sam_buttons.c index 9095bd820b5..619f7d658ba 100644 --- a/configs/sam4l-xplained/src/sam_buttons.c +++ b/configs/sam4l-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4l-xplained/src/sam_buttons.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -53,18 +53,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -111,8 +99,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -124,9 +111,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -138,11 +125,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *g_irqsw0; - *g_irqsw0 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -150,7 +132,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_gpioirqenable(IRQ_SW0); } else @@ -162,11 +144,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sam4s-xplained-pro/src/sam_buttons.c b/configs/sam4s-xplained-pro/src/sam_buttons.c index 0a4f057dd8a..daae49b89e6 100644 --- a/configs/sam4s-xplained-pro/src/sam_buttons.c +++ b/configs/sam4s-xplained-pro/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4s-xplained-pro/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Bob Doiron * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -54,20 +55,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static xcpt_t g_irqsw0; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,8 +97,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -123,9 +109,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -137,11 +123,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irqsw0; - g_irqsw0 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -149,7 +130,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_gpioirqenable(IRQ_SW0); } else @@ -161,11 +142,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return ret; } #endif diff --git a/configs/sam4s-xplained/src/sam_buttons.c b/configs/sam4s-xplained/src/sam_buttons.c index 4ce25925927..940f97edae5 100644 --- a/configs/sam4s-xplained/src/sam_buttons.c +++ b/configs/sam4s-xplained/src/sam_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqbp2; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,8 +96,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -124,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAM34_GPIOA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_BP2) { @@ -138,11 +122,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *g_irqbp2; - *g_irqbp2 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -150,7 +129,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_gpioirq(GPIO_BP2); - (void)irq_attach(IRQ_BP2, irqhandler, NULL); + (void)irq_attach(IRQ_BP2, irqhandler, arg); sam_gpioirqenable(IRQ_BP2); } else @@ -162,11 +141,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sama5d2-xult/src/sam_buttons.c b/configs/sama5d2-xult/src/sam_buttons.c index 3dd77011814..c93fa6b904e 100644 --- a/configs/sama5d2-xult/src/sam_buttons.c +++ b/configs/sama5d2-xult/src/sam_buttons.c @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -64,22 +65,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -122,8 +107,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the @@ -133,9 +117,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOB_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -147,11 +131,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -159,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_BTN_USER); - (void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); + (void)irq_attach(IRQ_BTN_USER, irqhandler, arg); sam_pioirqenable(IRQ_BTN_USER); } else @@ -171,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sama5d3-xplained/src/sam_buttons.c b/configs/sama5d3-xplained/src/sam_buttons.c index b2d0af924ea..b7fd8245567 100644 --- a/configs/sama5d3-xplained/src/sam_buttons.c +++ b/configs/sama5d3-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d3-xplained/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -68,22 +69,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -126,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the @@ -137,9 +121,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -151,11 +135,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -163,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_USER); - (void)irq_attach(IRQ_USER1, irqhandler, NULL); + (void)irq_attach(IRQ_USER1, irqhandler, arg); sam_pioirqenable(IRQ_USER1); } else @@ -173,14 +152,12 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) sam_pioirqdisable(IRQ_USER1); (void)irq_detach(IRQ_USER1); } - /* Configure the interrupt */ leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sama5d3-xplained/src/sam_ethernet.c b/configs/sama5d3-xplained/src/sam_ethernet.c index bad7d48b92a..501acac39fe 100644 --- a/configs/sama5d3-xplained/src/sam_ethernet.c +++ b/configs/sama5d3-xplained/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sama5d3-xplained/src/sam_ethernet.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 @@ -93,19 +93,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAMA5_PIOE_IRQ -#ifdef CONFIG_SAMA5_EMACA -static xcpt_t g_emac_handler; -#endif -#ifdef CONFIG_SAMA5_GMAC -static xcpt_t g_gmac_handler; -#endif -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -255,23 +242,21 @@ void weak_function sam_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAMA5_PIOE_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; pio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -290,7 +275,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_EMAC_DEVNAME) == 0) { phyinfo("Select EMAC\n"); - phandler = &g_emac_handler; pinset = PIO_INT_ETH1; irq = IRQ_INT_ETH1; enabler = sam_emac_phy_enable; @@ -301,7 +285,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_GMAC_DEVNAME) == 0) { phyinfo("Select GMAC\n"); - phandler = &g_gmac_handler; pinset = PIO_INT_ETH0; irq = IRQ_INT_ETH0; enabler = sam_gmac_phy_enable; @@ -319,11 +302,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -332,7 +310,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_pioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -355,7 +333,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAMA5_PIOE_IRQ */ diff --git a/configs/sama5d3x-ek/src/sam_buttons.c b/configs/sama5d3x-ek/src/sam_buttons.c index d9ea68baa42..5b7ccc9b908 100644 --- a/configs/sama5d3x-ek/src/sam_buttons.c +++ b/configs/sama5d3x-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d3x-ek/src/sam_buttons.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -68,22 +69,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -126,8 +111,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the @@ -137,9 +121,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER1) { @@ -151,11 +135,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -163,7 +142,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_USER1); - (void)irq_attach(IRQ_USER1, irqhandler, NULL); + (void)irq_attach(IRQ_USER1, irqhandler, arg); sam_pioirqenable(IRQ_USER1); } else @@ -175,11 +154,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sama5d3x-ek/src/sam_ethernet.c b/configs/sama5d3x-ek/src/sam_ethernet.c index 9dd45b9c62e..5121a03ff4f 100644 --- a/configs/sama5d3x-ek/src/sam_ethernet.c +++ b/configs/sama5d3x-ek/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sama5d3x-ek/src/sam_ethernet.c * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -93,19 +93,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAMA5_PIOE_IRQ -#ifdef CONFIG_SAMA5_EMACA -static xcpt_t g_emac_handler; -#endif -#ifdef CONFIG_SAMA5_GMAC -static xcpt_t g_gmac_handler; -#endif -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -255,23 +242,21 @@ void weak_function sam_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAMA5_PIOE_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; pio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -290,7 +275,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_EMAC_DEVNAME) == 0) { phyinfo("Select EMAC\n"); - phandler = &g_emac_handler; pinset = PIO_INT_ETH1; irq = IRQ_INT_ETH1; enabler = sam_emac_phy_enable; @@ -301,7 +285,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_GMAC_DEVNAME) == 0) { phyinfo("Select GMAC\n"); - phandler = &g_gmac_handler; pinset = PIO_INT_ETH0; irq = IRQ_INT_ETH0; enabler = sam_gmac_phy_enable; @@ -319,11 +302,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -332,7 +310,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_pioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -355,7 +333,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAMA5_PIOE_IRQ */ diff --git a/configs/sama5d4-ek/src/sam_buttons.c b/configs/sama5d4-ek/src/sam_buttons.c index b0fa42ecde3..5696d96de5b 100644 --- a/configs/sama5d4-ek/src/sam_buttons.c +++ b/configs/sama5d4-ek/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sama5d4-ek/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -64,22 +65,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irquser1; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -122,8 +107,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_SAMA5_PIO_IRQ must be selected to enable the @@ -133,9 +117,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_SAMA5_PIOE_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_USER) { @@ -147,11 +131,6 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = g_irquser1; - g_irquser1 = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -159,7 +138,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure the interrupt */ sam_pioirq(PIO_BTN_USER); - (void)irq_attach(IRQ_BTN_USER, irqhandler, NULL); + (void)irq_attach(IRQ_BTN_USER, irqhandler, arg); sam_pioirqenable(IRQ_BTN_USER); } else @@ -171,11 +150,10 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/sama5d4-ek/src/sam_ethernet.c b/configs/sama5d4-ek/src/sam_ethernet.c index 9231e227585..15cce4d2e13 100644 --- a/configs/sama5d4-ek/src/sam_ethernet.c +++ b/configs/sama5d4-ek/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sama5d4-ek/src/sam_ethernet.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 @@ -93,19 +93,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAMA5_PIOE_IRQ -#ifdef CONFIG_SAMA5_EMAC0 -static xcpt_t g_emac0_handler; -#endif -#ifdef CONFIG_SAMA5_EMAC1 -static xcpt_t g_emac1_handler; -#endif -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -224,23 +211,21 @@ void weak_function sam_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAMA5_PIOE_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; pio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -259,7 +244,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_EMAC0_DEVNAME) == 0) { phyinfo("Select EMAC0\n"); - phandler = &g_emac0_handler; pinset = PIO_INT_ETH0; irq = IRQ_INT_ETH0; enabler = sam_emac0_phy_enable; @@ -270,7 +254,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMA5_EMAC1_DEVNAME) == 0) { phyinfo("Select EMAC1\n"); - phandler = &g_emac1_handler; pinset = PIO_INT_ETH1; irq = IRQ_INT_ETH1; enabler = sam_emac1_phy_enable; @@ -288,11 +271,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -301,7 +279,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_pioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -324,7 +302,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAMA5_PIOE_IRQ */ diff --git a/configs/samd20-xplained/src/sam_buttons.c b/configs/samd20-xplained/src/sam_buttons.c index 5edeb965d8a..88c24aced7a 100644 --- a/configs/samd20-xplained/src/sam_buttons.c +++ b/configs/samd20-xplained/src/sam_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,8 +96,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the @@ -124,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -138,20 +122,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *g_irqsw0; - *g_irqsw0 = irqhandler; - /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); - leave_critical_section(flags); - } - /* Return the old button handler (so that it can be restored) */ + leave_critical_section(flags); + ret = OK; + } return oldhandler; } diff --git a/configs/samd21-xplained/src/sam_buttons.c b/configs/samd21-xplained/src/sam_buttons.c index cb5806f748a..aa19ddc008b 100644 --- a/configs/samd21-xplained/src/sam_buttons.c +++ b/configs/samd21-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/samd21-xplained/src/sam_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,8 +96,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the @@ -124,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -138,22 +122,17 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *g_irqsw0; - *g_irqsw0 = irqhandler; - /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); + leave_critical_section(flags); + ret = OK; } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/same70-xplained/src/sam_buttons.c b/configs/same70-xplained/src/sam_buttons.c index 251cf113c0e..669a6d3bfe4 100644 --- a/configs/same70-xplained/src/sam_buttons.c +++ b/configs/same70-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -59,20 +60,11 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Private Data - ****************************************************************************/ - #ifdef CONFIG_ARCH_IRQBUTTONS - -#define HAVE_IRQBUTTONS 1 -#ifndef CONFIG_SAMV7_GPIOA_IRQ -# undef HAVE_IRQBUTTONS -#endif - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_irq_sw0; -#endif +# define HAVE_IRQBUTTONS 1 +# ifndef CONFIG_SAMV7_GPIOA_IRQ +# undef HAVE_IRQBUTTONS +# endif #endif /**************************************************************************** @@ -88,10 +80,9 @@ static xcpt_t g_irq_sw0; ****************************************************************************/ #ifdef HAVE_IRQBUTTONS -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, + xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -100,11 +91,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -124,10 +110,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -175,8 +158,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -188,17 +170,16 @@ uint8_t board_buttons(void) ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef HAVE_IRQBUTTONS if (id == BUTTON_SW0) { - return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); + return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg); } #endif - return NULL; - + return -EINVAL; } #endif diff --git a/configs/same70-xplained/src/sam_ethernet.c b/configs/same70-xplained/src/sam_ethernet.c index ecf61bdf731..053003fe11b 100644 --- a/configs/same70-xplained/src/sam_ethernet.c +++ b/configs/same70-xplained/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/same70-xplained/src/sam_ethernet.c * - * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,14 +89,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_emac0_handler; -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -288,23 +280,21 @@ int sam_emac0_setmac(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAMV7_GPIOA_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; gpio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -317,7 +307,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) if (strcmp(intf, SAMV7_EMAC0_DEVNAME) == 0) { phyinfo("Select EMAC0\n"); - phandler = &g_emac0_handler; pinset = GPIO_EMAC0_INT; irq = IRQ_EMAC0_INT; enabler = sam_emac0_phy_enable; @@ -334,11 +323,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -347,7 +331,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_gpioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -370,7 +354,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAMV7_GPIOA_IRQ */ diff --git a/configs/saml21-xplained/src/sam_buttons.c b/configs/saml21-xplained/src/sam_buttons.c index 303a95a084f..437c4d7ec85 100644 --- a/configs/saml21-xplained/src/sam_buttons.c +++ b/configs/saml21-xplained/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/saml21-xplained/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -53,22 +54,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -static xcpt_t g_irqsw0; -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -111,8 +96,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address isreturned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_PORTIRQ must be selected to enable the @@ -124,9 +108,9 @@ uint8_t board_buttons(void) ****************************************************************************/ #if defined(CONFIG_PORTA_IRQ) && defined(CONFIG_ARCH_IRQBUTTONS) -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == BUTTON_SW0) { @@ -138,22 +122,19 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *g_irqsw0; - *g_irqsw0 = irqhandler; - /* Configure the interrupt */ sam_portirq(IRQ_SW0); - (void)irq_attach(IRQ_SW0, irqhandler, NULL); + (void)irq_attach(IRQ_SW0, irqhandler, arg); sam_portirqenable(IRQ_SW0); + leave_critical_section(flags); + ret = OK; } /* Return the old button handler (so that it can be restored) */ - return oldhandler; + return ret; } #endif diff --git a/configs/samv71-xult/src/sam_buttons.c b/configs/samv71-xult/src/sam_buttons.c index 7e2ecd1b404..7c9a98b52cd 100644 --- a/configs/samv71-xult/src/sam_buttons.c +++ b/configs/samv71-xult/src/sam_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/sam4e-ek/src/sam_buttons.c * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -64,18 +65,10 @@ ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS - -#define HAVE_IRQBUTTONS 1 -#if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ) -# undef HAVE_IRQBUTTONS -#endif - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_irq_sw0; -#endif -#ifdef CONFIG_SAMV7_GPIOB_IRQ -static xcpt_t g_irq_sw1; -#endif +# define HAVE_IRQBUTTONS 1 +# if !defined(CONFIG_SAMV7_GPIOA_IRQ) && !defined(CONFIG_SAMV7_GPIOB_IRQ) +# undef HAVE_IRQBUTTONS +# endif #endif /**************************************************************************** @@ -91,10 +84,9 @@ static xcpt_t g_irq_sw1; ****************************************************************************/ #ifdef HAVE_IRQBUTTONS -static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, - xcpt_t irqhandler, xcpt_t *store, void *arg) +static int board_button_irqx(gpio_pinset_t pinset, int irq, xcpt_t irqhandler, + void *arg) { - xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the following @@ -103,11 +95,6 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, flags = enter_critical_section(); - /* Get the old button interrupt handler and save the new one */ - - oldhandler = *store; - *store = irqhandler; - /* Are we attaching or detaching? */ if (irqhandler != NULL) @@ -127,10 +114,7 @@ static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq, } leave_critical_section(flags); - - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return OK; } #endif @@ -195,8 +179,7 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * * Configuration Notes: * Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the @@ -208,7 +191,7 @@ uint8_t board_buttons(void) ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef HAVE_IRQBUTTONS @@ -216,21 +199,21 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #ifdef CONFIG_SAMV7_GPIOA_IRQ case BUTTON_SW0: - return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, &g_irq_sw0, arg); + return board_button_irqx(GPIO_SW0, IRQ_SW0, irqhandler, arg); #endif #ifdef CONFIG_SAMV7_GPIOB_IRQ case BUTTON_SW1: - return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, &g_irq_sw1, arg); + return board_button_irqx(GPIO_SW1, IRQ_SW1, irqhandler, arg); #endif default: - return NULL; + return -EINVAL; } #else - return NULL; + return -ENOSYS; #endif } diff --git a/configs/samv71-xult/src/sam_ethernet.c b/configs/samv71-xult/src/sam_ethernet.c index 247c7258244..c08097eaee1 100644 --- a/configs/samv71-xult/src/sam_ethernet.c +++ b/configs/samv71-xult/src/sam_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/samv71-xult/src/sam_ethernet.c * - * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -89,14 +89,6 @@ # define phyinfo(x...) #endif -/************************************************************************************ - * Private Data - ************************************************************************************/ - -#ifdef CONFIG_SAMV7_GPIOA_IRQ -static xcpt_t g_emac0_handler; -#endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -292,23 +284,21 @@ int sam_emac0_setmac(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_SAMV7_GPIOA_IRQ -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { irqstate_t flags; - xcpt_t *phandler; - xcpt_t oldhandler; gpio_pinset_t pinset; phy_enable_t enabler; int irq; @@ -322,7 +312,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) { phyinfo("Select EMAC0\n"); - phandler = &g_emac0_handler; pinset = GPIO_EMAC0_INT; irq = IRQ_EMAC0_INT; enabler = sam_emac0_phy_enable; @@ -339,11 +328,6 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) flags = enter_critical_section(); - /* Get the old interrupt handler and save the new one */ - - oldhandler = *phandler; - *phandler = handler; - /* Configure the interrupt */ if (handler) @@ -352,7 +336,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) sam_gpioirq(pinset); phyinfo("Attach IRQ%d\n", irq); - (void)irq_attach(irq, handler, NULL); + (void)irq_attach(irq, handler, arg); } else { @@ -375,7 +359,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); - return oldhandler; + return OK; } #endif /* CONFIG_SAMV7_GPIOA_IRQ */ diff --git a/configs/shenzhou/src/stm32_buttons.c b/configs/shenzhou/src/stm32_buttons.c index 2d90fafcc16..515cad297f1 100644 --- a/configs/shenzhou/src/stm32_buttons.c +++ b/configs/shenzhou/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/shenzhou/src/stm32_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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,13 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ + /* Pin configuration for each Shenzhou button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -65,10 +63,6 @@ static const uint32_t g_buttons[NUM_BUTTONS] = GPIO_BTN_USERKEY2, GPIO_BTN_USERKEY, GPIO_BTN_TAMPER, GPIO_BTN_WAKEUP }; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -150,24 +144,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/shenzhou/src/stm32_usb.c b/configs/shenzhou/src/stm32_usb.c index b63a64c0538..5baddf4d016 100644 --- a/configs/shenzhou/src/stm32_usb.c +++ b/configs/shenzhou/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/shenzhou/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -273,16 +273,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return NULL; + return -ENOSYS; } #endif diff --git a/configs/spark/src/stm32_buttons.c b/configs/spark/src/stm32_buttons.c index d38a868cc59..e41463d6c9f 100644 --- a/configs/spark/src/stm32_buttons.c +++ b/configs/spark/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/spark/src/stm32_buttons.c * - * Copyright (C) 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,6 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -114,24 +103,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id == BUTTON_USER) { - oldhandler = stm32_gpiosetevent(GPIO_BTN, true, true, true, irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/spark/src/stm32_io.c b/configs/spark/src/stm32_io.c index 5730abe689d..b6601c1ac61 100644 --- a/configs/spark/src/stm32_io.c +++ b/configs/spark/src/stm32_io.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/spark/src/stm32_io.c * - * Copyright (C) 2011-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -175,23 +175,21 @@ void up_write_outputs(int id, bool bits) * ****************************************************************************/ -xcpt_t up_irqio(int id, xcpt_t irqhandler) +int up_irqio(int id, xcpt_t irqhandler, void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id == 0) { - oldhandler = stm32_gpiosetevent(GPIO_D0, true, true, true, - irqhandler, NULL); + ret = stm32_gpiosetevent(GPIO_D0, true, true, true, irqhandler, arg); } else if (id == 1) { - oldhandler = stm32_gpiosetevent(GPIO_D1, true, true, true, - irqhandler, NULL); + ret = stm32_gpiosetevent(GPIO_D1, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif /* CONFIG_CC3000_PROBES */ diff --git a/configs/stm3210e-eval/README.txt b/configs/stm3210e-eval/README.txt index f249c3284d6..62b78a4a9ad 100644 --- a/configs/stm3210e-eval/README.txt +++ b/configs/stm3210e-eval/README.txt @@ -365,7 +365,7 @@ Temperature Sensor More complex temperature sensor operations are also available. See the IOCTL commands enumerated in include/nuttx/sensors/lm75.h. Also read the - escriptions of the stm32_lm75initialize() and stm32_lm75attach() + descriptions of the stm32_lm75initialize() and stm32_lm75attach() interfaces in the arch/board/board.h file (sames as configs/stm3210e-eval/include/board.h). diff --git a/configs/stm3210e-eval/include/board.h b/configs/stm3210e-eval/include/board.h index 087b762bc2c..d5f9c13f381 100644 --- a/configs/stm3210e-eval/include/board.h +++ b/configs/stm3210e-eval/include/board.h @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm3210e-eval/include/board.h * - * Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -289,14 +289,15 @@ int stm32_lm75initialize(FAR const char *devpath); * * Input parameters: * irqhandler - the LM-75 interrupt handler + * arg - The argument that will accompany the interrupt * * Returned Value: - * The previous LM-75 interrupt handler + * Zero (OK) returned on success; a negated errno value is returned on failure. * ************************************************************************************/ #if defined(CONFIG_I2C) && defined(CONFIG_I2C_LM75) && defined(CONFIG_STM32_I2C1) -xcpt_t stm32_lm75attach(xcpt_t irqhandler); +int stm32_lm75attach(xcpt_t irqhandler, void *arg); #endif #undef EXTERN diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index a2dc1c6cf7e..043535444c8 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm3210e-eval/src/stm32_buttons.c * - * Copyright (C) 2009, 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -155,25 +156,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm3210e-eval/src/stm32_lm75.c b/configs/stm3210e-eval/src/stm32_lm75.c index a238bf7d637..959dd6731c6 100644 --- a/configs/stm3210e-eval/src/stm32_lm75.c +++ b/configs/stm3210e-eval/src/stm32_lm75.c @@ -106,15 +106,17 @@ int stm32_lm75initialize(FAR const char *devpath) * * Input parameters: * irqhandler - the LM-75 interrupt handler + * arg - The argument that will accompany the interrupt * * Returned Value: - * The previous LM-75 interrupt handler + * Zero (OK) returned on success; a negated errno value is returned on failure. * ************************************************************************************/ -xcpt_t stm32_lm75attach(xcpt_t irqhandler) +int stm32_lm75attach(xcpt_t irqhandler, void *arg) { - return stm32_gpiosetevent(GPIO_LM75_OSINT, true, true, true, irqhandler, NULL); + (void)stm32_gpiosetevent(GPIO_LM75_OSINT, true, true, true, irqhandler, arg); + return OK; } #endif /* CONFIG_I2C && CONFIG_I2C_LM75 && CONFIG_STM32_I2C1 */ diff --git a/configs/stm3220g-eval/src/stm32_buttons.c b/configs/stm3220g-eval/src/stm32_buttons.c index ec5428eb069..115fea249ea 100644 --- a/configs/stm3220g-eval/src/stm32_buttons.c +++ b/configs/stm3220g-eval/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm3220g-eval/src/stm32_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 @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM3210E-EVAL button. This array is indexed by * the BUTTON_* and JOYSTICK_* definitions in board.h */ @@ -151,25 +144,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm3220g-eval/src/stm32_usb.c b/configs/stm3220g-eval/src/stm32_usb.c index 371daed38ad..33809073c84 100644 --- a/configs/stm3220g-eval/src/stm32_usb.c +++ b/configs/stm3220g-eval/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm3220g-eval/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -273,16 +273,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/stm3240g-eval/src/stm32_buttons.c b/configs/stm3240g-eval/src/stm32_buttons.c index db034d5a4e3..a20c03f16ae 100644 --- a/configs/stm3240g-eval/src/stm32_buttons.c +++ b/configs/stm3240g-eval/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm3240g-eval/src/stm32_buttons.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -151,25 +152,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm3240g-eval/src/stm32_usb.c b/configs/stm3240g-eval/src/stm32_usb.c index 7c5494a501b..27846d9cf66 100644 --- a/configs/stm3240g-eval/src/stm32_usb.c +++ b/configs/stm3240g-eval/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm3240g-eval/src/stm32_usbdev.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -273,16 +273,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/stm32_tiny/src/stm32_wireless.c b/configs/stm32_tiny/src/stm32_wireless.c index ef3fc3f54cb..a08e48a65ab 100644 --- a/configs/stm32_tiny/src/stm32_wireless.c +++ b/configs/stm32_tiny/src/stm32_wireless.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32_tiny/src/stm32_wireless.c * - * Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2013, 2017 Gregory Nutt. All rights reserved. * Author: Laurent Latil * * Redistribution and use in source and binary forms, with or without @@ -83,7 +83,7 @@ static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) _info("Attach IRQ\n"); g_isr = isr; g_arg = arg; - stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); + (void)stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); return OK; } diff --git a/configs/stm32butterfly2/src/stm32_mmcsd.c b/configs/stm32butterfly2/src/stm32_mmcsd.c index d045d05c710..a244a5b5ff6 100644 --- a/configs/stm32butterfly2/src/stm32_mmcsd.c +++ b/configs/stm32butterfly2/src/stm32_mmcsd.c @@ -1,7 +1,7 @@ /***************************************************************************** * configs/stm32butterfly2/src/stm32_mmcsd.c * - * Copyright (C) 2016 Michał Łyszczek. All rights reserved. + * Copyright (C) 2016-2017 Michał Łyszczek. All rights reserved. * Author: Michał Łyszczek * * Redistribution and use in source and binary forms, with or without @@ -196,7 +196,7 @@ int stm32_mmcsd_initialize(int minor) return rv; } - stm32_gpiosetevent(GPIO_SD_CD, true, true, true, stm32_cd, NULL); + (void)stm32_gpiosetevent(GPIO_SD_CD, true, true, true, stm32_cd, NULL); sem_init(&g_cdsem, 0, 0); pthread_attr_init(&pattr); diff --git a/configs/stm32f103-minimum/README.txt b/configs/stm32f103-minimum/README.txt index 6b2db769398..82f9f33ce89 100644 --- a/configs/stm32f103-minimum/README.txt +++ b/configs/stm32f103-minimum/README.txt @@ -13,6 +13,8 @@ Contents - Timer Inputs/Outputs - Using 128KiB of Flash instead of 64KiB - Quadrature Encoder + - SDCard support + - USB Console support - STM32F103 Minimum - specific Configuration Options - Configurations @@ -305,6 +307,48 @@ SDCard support: PA5, MOSI to PA7 and MISO to PA6. Note: some chinese boards use MOSO instead of MISO. +USB Console support: +==================== + + The STM32F103C8 has a USB Device controller, then we can use NuttX support + to USB Device. We can the console over USB enabling these options: + + System Type ---> + STM32 Peripheral Support ---> + [*] USB Device + + It will enable: CONFIG_STM32_USB=y + + Board Selection ---> + -*- Enable boardctl() interface + [*] Enable USB device controls + + It will enable: CONFIG_BOARDCTL_USBDEVCTRL=y + + Device Drivers ---> + -*- USB Device Driver Support ---> + [*] USB Modem (CDC/ACM) support ---> + + It will enable: CONFIG_CDCACM=y and many default options. + + Device Drivers ---> + -*- USB Device Driver Support ---> + [*] USB Modem (CDC/ACM) support ---> + [*] CDC/ACM console device + + It will enable: CONFIG_CDCACM_CONSOLE=y + + Device Drivers ---> + [*] Serial Driver Support ---> + Serial console (No serial console) ---> + (X) No serial console + + It will enable: CONFIG_NO_SERIAL_CONSOLE=y + + After flashing the firmware in the board, unplug and plug it in the computer + and it will create a /dev/ttyACM0 device in the Linux. Use minicom with this + device to get access to NuttX NSH console (press Enter three times to start) + STM32F103 Minimum - specific Configuration Options ================================================== diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile index 387e2bfe6a3..5e937a4ac0e 100644 --- a/configs/stm32f103-minimum/src/Makefile +++ b/configs/stm32f103-minimum/src/Makefile @@ -89,4 +89,8 @@ ifeq ($(CONFIG_WL_NRF24L01),y) CSRCS += stm32_wireless.c endif +ifeq ($(CONFIG_USBDEV),y) +CSRCS += stm32_usbdev.c +endif + include $(TOPDIR)/configs/Board.mk diff --git a/configs/stm32f103-minimum/src/stm32_buttons.c b/configs/stm32f103-minimum/src/stm32_buttons.c index 96fd053eef3..ebca1469f1d 100644 --- a/configs/stm32f103-minimum/src/stm32_buttons.c +++ b/configs/stm32f103-minimum/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f103-minimum/src/stm32_buttons.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -146,25 +147,24 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value is * a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, + arg); } - return oldhandler; + return ret; } #endif diff --git a/configs/stm32f103-minimum/src/stm32_usbdev.c b/configs/stm32f103-minimum/src/stm32_usbdev.c index ecbd707fb76..92fc01f095d 100644 --- a/configs/stm32f103-minimum/src/stm32_usbdev.c +++ b/configs/stm32f103-minimum/src/stm32_usbdev.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f103-minimum/src/stm32_usbdev.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * Laurent Latil * @@ -60,7 +60,7 @@ * Name: stm32_usbinitialize * * Description: - * Called to setup USB-related GPIO pins for the Hy-Mini STM32v board. + * Called to setup USB-related GPIO pins for the STM32F103 Minimum board. * ************************************************************************************/ diff --git a/configs/stm32f103-minimum/src/stm32_wireless.c b/configs/stm32f103-minimum/src/stm32_wireless.c index e5d7c21073d..c3ddcff7848 100644 --- a/configs/stm32f103-minimum/src/stm32_wireless.c +++ b/configs/stm32f103-minimum/src/stm32_wireless.c @@ -85,7 +85,7 @@ static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) winfo("Attach IRQ\n"); g_isr = isr; g_arg = arg; - stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); + (void)stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); return OK; } diff --git a/configs/stm32f3discovery/src/stm32_buttons.c b/configs/stm32f3discovery/src/stm32_buttons.c index f15c22f8a9c..f89fd207a3b 100644 --- a/configs/stm32f3discovery/src/stm32_buttons.c +++ b/configs/stm32f3discovery/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f3discovery/src/stm32_buttons.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM32F3Discovery button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -146,25 +139,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32f429i-disco/src/stm32_buttons.c b/configs/stm32f429i-disco/src/stm32_buttons.c index 396b8750546..a6ffed5433d 100644 --- a/configs/stm32f429i-disco/src/stm32_buttons.c +++ b/configs/stm32f429i-disco/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f429i-disco/src/stm32_buttons.c * - * Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM32F4 Discovery button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -146,25 +139,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32f429i-disco/src/stm32_l3gd20.c b/configs/stm32f429i-disco/src/stm32_l3gd20.c index 1d6dd2cc2d5..4cdc0a896e0 100644 --- a/configs/stm32f429i-disco/src/stm32_l3gd20.c +++ b/configs/stm32f429i-disco/src/stm32_l3gd20.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f429i-disco/src/stm32_l3gd20.c * - * Copyright (C) Gregory Nutt. All rights reserved. + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Mateusz Szafoni * * Redistribution and use in source and binary forms, with or without @@ -85,9 +85,9 @@ static struct l3gd20_config_s g_l3gd20_config = * ****************************************************************************/ -static int l3gd20_attach(FAR struct l3gd20_config_s * cfg, xcpt_t irq) +static int l3gd20_attach(FAR struct l3gd20_config_s *cfg, xcpt_t irq) { - stm32_gpiosetevent(GPIO_L3GD20_DREADY, true, false, true, irq, NULL); + return stm32_gpiosetevent(GPIO_L3GD20_DREADY, true, false, true, irq, NULL); } /**************************************************************************** diff --git a/configs/stm32f429i-disco/src/stm32_usb.c b/configs/stm32f429i-disco/src/stm32_usb.c index 3daa643edca..33718f15344 100644 --- a/configs/stm32f429i-disco/src/stm32_usb.c +++ b/configs/stm32f429i-disco/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f429i-disco/src/stm32_usbdev.c * - * Copyright (C) 2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -279,16 +279,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameters: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * - * Returned Value: - * Old overcurrent interrupt handler + * Returned value: + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGHS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGHS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/stm32f4discovery/src/stm32_buttons.c b/configs/stm32f4discovery/src/stm32_buttons.c index 5143fd8eca0..449001f13ad 100644 --- a/configs/stm32f4discovery/src/stm32_buttons.c +++ b/configs/stm32f4discovery/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f4discovery/src/stm32_buttons.c * - * Copyright (C) 2011-2012, 2014=2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM32F4 Discovery button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -146,25 +139,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32f4discovery/src/stm32_ethernet.c b/configs/stm32f4discovery/src/stm32_ethernet.c index 0cc23c60167..fcd6d6c2149 100644 --- a/configs/stm32f4discovery/src/stm32_ethernet.c +++ b/configs/stm32f4discovery/src/stm32_ethernet.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f4discovery/src/stm32_ethernet.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -94,6 +94,7 @@ #ifdef HAVE_NETMONITOR static xcpt_t g_ethmac_handler; +static void *g_ethmac_arg; #endif /************************************************************************************ @@ -113,7 +114,7 @@ static void stm32_emac0_phy_enable(bool enable) /* Attach and enable GPIO interrupt (and event) on the falling edge */ (void)stm32_gpiosetevent(GPIO_EMAC_NINT, false, true, true, - g_ethmac_handler, NULL); + g_ethmac_handler, g_ethmac_arg); } else { @@ -203,22 +204,21 @@ void weak_function stm32_netinitialize(void) * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef HAVE_NETMONITOR -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable) { phy_enable_t enabler; - xcpt_t oldhandler; irqstate_t flags; ninfo("%s: handler=%p\n", intf, handler); @@ -226,13 +226,13 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) DEBUGASSERT(intf); - flags = enter_critical_section(); - oldhandler = g_ethmac_handler; + flags = enter_critical_section(); if (strcmp(intf, STM32_ETHMAC_DEVNAME) == 0) { phyinfo("Select ETHMAC\n"); g_ethmac_handler = handler; + g_ethmac_arg = arg; enabler = stm32_emac0_phy_enable; } else @@ -247,7 +247,7 @@ xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) } leave_critical_section(flags); - return oldhandler; + return OK; } #endif diff --git a/configs/stm32f4discovery/src/stm32_pmbuttons.c b/configs/stm32f4discovery/src/stm32_pmbuttons.c index 6b974ea38b6..a60e7f67995 100644 --- a/configs/stm32f4discovery/src/stm32_pmbuttons.c +++ b/configs/stm32f4discovery/src/stm32_pmbuttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f4discovery/src/stm32_pm_buttons.c * - * Copyright (C) 2012, 2015-2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015-2017 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Diego Sanchez * @@ -130,14 +130,7 @@ void stm32_pm_buttons(void) board_button_initialize(); #ifdef CONFIG_ARCH_IRQBUTTONS - xcpt_t oldhandler = board_button_irq(0, button_handler, NULL); - - if (oldhandler != NULL) - { - _warn("WARNING: oldhandler:%p is not NULL! " - "Button events may be lost or aliased!\n", - oldhandler); - } + (void)board_button_irq(0, button_handler, NULL); #endif } diff --git a/configs/stm32f4discovery/src/stm32_sdio.c b/configs/stm32f4discovery/src/stm32_sdio.c index f4f5ba50243..75e87866d65 100644 --- a/configs/stm32f4discovery/src/stm32_sdio.c +++ b/configs/stm32f4discovery/src/stm32_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/stm32f4discovery/src/stm32_sdio.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 @@ -128,8 +128,8 @@ int stm32_sdio_initialize(void) /* Register an interrupt handler for the card detect pin */ - stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, - stm32_ncd_interrupt, NULL); + (void)stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, + stm32_ncd_interrupt, NULL); #endif /* Mount the SDIO-based MMC/SD block driver */ diff --git a/configs/stm32f4discovery/src/stm32_usb.c b/configs/stm32f4discovery/src/stm32_usb.c index f6571406540..c929c1bfe2c 100644 --- a/configs/stm32f4discovery/src/stm32_usb.c +++ b/configs/stm32f4discovery/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f4discovery/src/stm32_usb.c * - * Copyright (C) 2012-2013, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -302,16 +302,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/stm32f746-ws/src/stm32_sdmmc.c b/configs/stm32f746-ws/src/stm32_sdmmc.c index dce13b291da..daca5a160ff 100644 --- a/configs/stm32f746-ws/src/stm32_sdmmc.c +++ b/configs/stm32f746-ws/src/stm32_sdmmc.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/stm32f746-ws/src/stm32_sdmmc.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -126,8 +126,8 @@ int stm32_sdio_initialize(void) /* Register an interrupt handler for the card detect pin */ - stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, - stm32_ncd_interrupt, NULL); + (void)stm32_gpiosetevent(GPIO_SDIO_NCD, true, true, true, + stm32_ncd_interrupt, NULL); #endif /* Mount the SDIO-based MMC/SD block driver */ diff --git a/configs/stm32f746-ws/src/stm32_usb.c b/configs/stm32f746-ws/src/stm32_usb.c index 84f782c5ef9..a2985140b32 100644 --- a/configs/stm32f746-ws/src/stm32_usb.c +++ b/configs/stm32f746-ws/src/stm32_usb.c @@ -1,7 +1,7 @@ /************************************************************************************ * configs/stm32f4discovery/src/stm32_usb.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -305,16 +305,18 @@ void stm32_usbhost_vbusdrive(int iface, bool enable) * * Input Parameter: * handler - New overcurrent interrupt handler + * arg - The argument provided for the interrupt handler * * Returned value: - * Old overcurrent interrupt handler + * Zero (OK) is returned on success. Otherwise, a negated errno value is returned + * to indicate the nature of the failure. * ************************************************************************************/ #ifdef CONFIG_USBHOST -xcpt_t stm32_setup_overcurrent(xcpt_t handler) +int stm32_setup_overcurrent(xcpt_t handler, void *arg) { - return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, arg); } #endif diff --git a/configs/stm32f746g-disco/src/stm32_buttons.c b/configs/stm32f746g-disco/src/stm32_buttons.c index 43051e49604..ec08616aa6c 100644 --- a/configs/stm32f746g-disco/src/stm32_buttons.c +++ b/configs/stm32f746g-disco/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32f746g-disco/src/stm32_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ #include +#include + #include #include @@ -98,15 +100,15 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { #warning Missing logic + return -ENOSYS; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32l476-mdk/src/stm32_buttons.c b/configs/stm32l476-mdk/src/stm32_buttons.c index 7dfc0469418..955cba926d3 100644 --- a/configs/stm32l476-mdk/src/stm32_buttons.c +++ b/configs/stm32l476-mdk/src/stm32_buttons.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -144,23 +145,22 @@ uint8_t board_buttons(void) * will be called when a button is depressed or released. The ID value * is a button enumeration value that uniquely identifies a button resource. * See the BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it - * may be restored, if so desired). + * value. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32l4_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32l4_gpiosetevent(g_buttons[id], true, true, true, + irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32l476vg-disco/src/stm32_buttons.c b/configs/stm32l476vg-disco/src/stm32_buttons.c index 7fc0c09d8a9..23983182735 100644 --- a/configs/stm32l476vg-disco/src/stm32_buttons.c +++ b/configs/stm32l476vg-disco/src/stm32_buttons.c @@ -244,19 +244,13 @@ void board_button_initialize(void) { stm32l4_configgpio(g_buttons[i]); - /* It's not clear if this is correct; I think so, but then there are - * conflicts with the 'buttons' sample app. - */ + /* It's not clear if this is correct; I think so, but then there are + * conflicts with the 'buttons' sample app. + */ #if 0 #ifdef CONFIG_ARCH_IRQBUTTONS - xcpt_t oldhandler = board_button_irq(i, button_handler); - if (oldhandler != NULL) - { - warn("WARNING: oldhandler:%p is not NULL! " - "Button events may be lost or aliased!\n", - oldhandler); - } + (void)board_button_irq(i, button_handler); #endif #endif } @@ -319,25 +313,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32l4_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32l4_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32l476vg-disco/src/stm32_usb.c b/configs/stm32l476vg-disco/src/stm32_usb.c index 0b08a9264d2..0f51871e1ac 100644 --- a/configs/stm32l476vg-disco/src/stm32_usb.c +++ b/configs/stm32l476vg-disco/src/stm32_usb.c @@ -311,7 +311,8 @@ void stm32l4_usbhost_vbusdrive(int iface, bool enable) #ifdef CONFIG_USBHOST xcpt_t stm32l4_setup_overcurrent(xcpt_t handler) { - return stm32l4_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + (void)stm32l4_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler, NULL); + return NULL; } #endif diff --git a/configs/stm32ldiscovery/src/stm32_buttons.c b/configs/stm32ldiscovery/src/stm32_buttons.c index b703bf8d2de..f599b0c8517 100644 --- a/configs/stm32ldiscovery/src/stm32_buttons.c +++ b/configs/stm32ldiscovery/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32ldiscovery/src/board_buttons.c * - * Copyright (C) 2013-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,18 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /* Pin configuration for each STM32F3Discovery button. This array is indexed by * the BUTTON_* definitions in board.h */ @@ -146,25 +139,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/stm32vldiscovery/src/stm32_buttons.c b/configs/stm32vldiscovery/src/stm32_buttons.c index 63be9ee2a17..259cfee756e 100644 --- a/configs/stm32vldiscovery/src/stm32_buttons.c +++ b/configs/stm32vldiscovery/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/stm32vldiscovery/src/stm32_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 * Freddie Chopin * @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -101,22 +102,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; if (id == 0) { - oldhandler = stm32_gpiosetevent(GPIO_BTN_0, true, true, true, irqhandler, arg); + ret = stm32_gpiosetevent(GPIO_BTN_0, true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/sure-pic32mx/src/pic32mx_buttons.c b/configs/sure-pic32mx/src/pic32mx_buttons.c index 8de2633e2f6..6c378dd0a6f 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 @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -192,8 +193,7 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * * Interrupts are automatically enabled when the button handler is attached and * automatically disabled when the button handler is detached. @@ -206,21 +206,21 @@ uint8_t board_buttons(void) ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; 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/tm4c123g-launchpad/src/tm4c_buttons.c b/configs/tm4c123g-launchpad/src/tm4c_buttons.c index a151bce0caf..a61c7e9c78d 100644 --- a/configs/tm4c123g-launchpad/src/tm4c_buttons.c +++ b/configs/tm4c123g-launchpad/src/tm4c_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/tm4c123g-launchpad/src/tm4c_buttons.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Bradley Noyes * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ #include +#include + #include #include #include @@ -143,16 +145,15 @@ uint8_t board_buttons(void) * Description: * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is one - * of the BUTTON* definitions provided above. The previous interrupt - * handler address is returned (so that it may restored, if so desired). + * of the BUTTON* definitions provided above. * ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; - uint32_t pinset= 0; + uint32_t pinset = 0; + int ret; /* Determine which switch to set the irq handler for */ @@ -167,23 +168,21 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) break; default: - return NULL; + return -EINVAL; } /* Are we attaching or detaching? */ if (irqhandler != NULL) { - oldhandler = tiva_gpioirqattach(pinset, irqhandler); + ret = tiva_gpioirqattach(pinset, irqhandler, arg); } else { - oldhandler = tiva_gpioirqdetach(pinset); + ret = tiva_gpioirqdetach(pinset); } - /* Return the old button handler (so that it can be restored) */ - - return oldhandler; + return ret; } #endif diff --git a/configs/twr-k60n512/src/k60_appinit.c b/configs/twr-k60n512/src/k60_appinit.c index dcf7183d0bc..4bbbaee8ddb 100644 --- a/configs/twr-k60n512/src/k60_appinit.c +++ b/configs/twr-k60n512/src/k60_appinit.c @@ -224,7 +224,7 @@ int board_app_initialize(uintptr_t arg) /* Attached the card detect interrupt (but don't enable it yet) */ kinetis_pinconfig(GPIO_SD_CARDDETECT); - kinetis_pinirqattach(GPIO_SD_CARDDETECT, kinetis_cdinterrupt, NULL); + (void)kinetis_pinirqattach(GPIO_SD_CARDDETECT, kinetis_cdinterrupt, NULL); /* Configure the write protect GPIO */ diff --git a/configs/twr-k60n512/src/k60_buttons.c b/configs/twr-k60n512/src/k60_buttons.c index 6a936935da1..a952f64828d 100644 --- a/configs/twr-k60n512/src/k60_buttons.c +++ b/configs/twr-k60n512/src/k60_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/twr-k60n512/src/k60_buttons.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -128,15 +129,13 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler; uint32_t pinset; /* Map the button id to the GPIO bit set. */ @@ -151,7 +150,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) } else { - return NULL; + return -EINVAL; } /* The button has already been configured as an interrupting input (by @@ -160,12 +159,15 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) * Attach the new button handler. */ - oldhandler = knetis_pinirqattach(pinset, irqhandler); + ret = kinetis_pinirqattach(pinset, irqhandler, arg); + if (ret >= 0) + { + /* Then make sure that interrupts are enabled on the pin */ - /* Then make sure that interrupts are enabled on the pin */ + kinetis_pindmaenable(pinset); + } - kinetis_pindmaenable(pinset); - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/twr-k64f120m/src/k64_sdhc.c b/configs/twr-k64f120m/src/k64_sdhc.c index 36896e410d5..f7d4d1edff1 100644 --- a/configs/twr-k64f120m/src/k64_sdhc.c +++ b/configs/twr-k64f120m/src/k64_sdhc.c @@ -166,7 +166,7 @@ int k64_sdhc_initialize(void) /* Attached the card detect interrupt (but don't enable it yet) */ - kinetis_pinirqattach(GPIO_SD_CARDDETECT, k64_cdinterrupt, NULL); + (void)kinetis_pinirqattach(GPIO_SD_CARDDETECT, k64_cdinterrupt, NULL); /* Configure the write protect GPIO -- None */ diff --git a/configs/ubw32/src/pic32_buttons.c b/configs/ubw32/src/pic32_buttons.c index dec8fe416eb..f612e1eea4b 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 @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -166,9 +167,7 @@ uint8_t board_buttons(void) * board_button_irq() may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the - * BUTTON_* definitions in board.h for the meaning of enumeration value. The - * previous interrupt handler address is returned (so that it may restored, if - * so desired). + * BUTTON_* definitions in board.h for the meaning of enumeration value. * * Interrupts are automatically enabled when the button handler is attached and * automatically disabled when the button handler is detached. @@ -181,21 +180,21 @@ uint8_t board_buttons(void) ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; 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 */ diff --git a/configs/viewtool-stm32f107/src/stm32_buttons.c b/configs/viewtool-stm32f107/src/stm32_buttons.c index 97b02d1c5c3..9039e72e091 100644 --- a/configs/viewtool-stm32f107/src/stm32_buttons.c +++ b/configs/viewtool-stm32f107/src/stm32_buttons.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/viewtool-stm32f107/src/stm32_buttons.c * - * Copyright (C) 2013, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2014-2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -49,13 +50,10 @@ #ifdef CONFIG_ARCH_BUTTONS -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ + /* Pin configuration for each STM3210E-EVAL button. This array is indexed by * the BUTTON_* and JOYSTICK_* definitions in board.h */ @@ -65,10 +63,6 @@ static const uint32_t g_buttons[NUM_BUTTONS] = GPIO_SW2, GPIO_SW3, GPIO_SW4 }; -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -146,25 +140,23 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t oldhandler = NULL; + int ret = -EINVAL; /* The following should be atomic */ if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON) { - oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, - irqhandler, arg); + ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg); } - return oldhandler; + return ret; } #endif #endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/zkit-arm-1769/src/lpc17_buttons.c b/configs/zkit-arm-1769/src/lpc17_buttons.c index 24d60216938..6c984650323 100644 --- a/configs/zkit-arm-1769/src/lpc17_buttons.c +++ b/configs/zkit-arm-1769/src/lpc17_buttons.c @@ -6,7 +6,7 @@ * * Based on configs/stm3210e-eval/src/board_buttons.c * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -76,10 +76,6 @@ static const uint16_t g_buttons[BOARD_NUM_BUTTONS] = ZKITARM_KEY1, ZKITARM_KEY2, ZKITARM_KEY3, ZKITARM_KEY4, ZKITARM_KEY5 }; -/* Old KEY5 interrupt handler */ - -static xcpt_t g_oldhandler; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -154,27 +150,21 @@ uint8_t board_buttons(void) * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. See the * BUTTON_* and JOYSTICK_* definitions in board.h for the meaning of enumeration - * value. The previous interrupt handler address is returned (so that it may - * restored, if so desired). + * value. * ************************************************************************************/ #if defined CONFIG_ARCH_IRQBUTTONS && CONFIG_LPC17_GPIOIRQ -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) { - xcpt_t rethandler = NULL; irqstate_t flags; - int ret; + int ret = -EINVAL; /* Interrupts are supported on KEY5 only */ if (id == BOARD_BUTTON_5) { - /* Return the previous value of the interrupt handler */ - flags = enter_critical_section(); - rethandler = g_oldhandler; - g_oldhandler = irqhandler; /* Attach or detach the interrupt handler for KEY5. */ @@ -186,7 +176,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Attach the new interrupt handler and enable the interrupt */ - ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, NULL); + ret = irq_attach(ZKITARM_KEY5_IRQ, irqhandler, arg); if (ret == OK) { up_enable_irq(ZKITARM_KEY5_IRQ); @@ -202,13 +192,13 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) /* Configure KEY5 as a non-interrupting input */ lpc17_configgpio(ZKITARM_KEY5); - + ret = OK; } leave_critical_section(flags); } - return rethandler; + return ret; } #endif diff --git a/drivers/net/phy_notify.c b/drivers/net/phy_notify.c index 2b552d620de..bb179ca0a9b 100644 --- a/drivers/net/phy_notify.c +++ b/drivers/net/phy_notify.c @@ -102,7 +102,6 @@ struct phy_notify_s { bool assigned; uint8_t signo; - uint8_t index; #ifdef CONFIG_NETDEV_MULTINIC char intf[CONFIG_PHY_NOTIFICATION_MAXINTFLEN+1]; #endif @@ -115,17 +114,11 @@ struct phy_notify_s * Private Function Prototypes ****************************************************************************/ -static int phy_handler(FAR struct phy_notify_s *client); -static int phy_handler_0(int irq, FAR void *context, FAR void *arg); -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 1 -static int phy_handler_1(int irq, FAR void *context, FAR void *arg); -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 2 -static int phy_handler_2(int irq, FAR void *context, FAR void *arg); -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 3 -static int phy_handler_3(int irq, FAR void *context, FAR void *arg); -#endif -#endif -#endif +static void phy_semtake(void); +static FAR struct phy_notify_s *phy_find_unassigned(void); +static FAR struct phy_notify_s *phy_find_assigned(FAR const char *intf, + pid_t pid); +static int phy_handler(int irq, FAR void *context, FAR void *arg); /**************************************************************************** * Private Data @@ -138,22 +131,6 @@ static sem_t g_notify_clients_sem = SEM_INITIALIZER(1); static struct phy_notify_s g_notify_clients[CONFIG_PHY_NOTIFICATION_NCLIENTS]; -/* Handler addresses accessed with the same index as g_notify_clients[] */ - -static const xcpt_t g_notify_handler[CONFIG_PHY_NOTIFICATION_NCLIENTS] = -{ - phy_handler_0 -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 1 - , phy_handler_1 -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 2 - , phy_handler_2 -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 3 - , phy_handler_3 -#endif -#endif -#endif -}; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -197,7 +174,6 @@ static FAR struct phy_notify_s *phy_find_unassigned(void) client->assigned = true; client->signo = 0; - client->index = i; #ifdef CONFIG_NETDEV_MULTINIC client->intf[0] = '\0'; #endif @@ -258,16 +234,16 @@ static FAR struct phy_notify_s *phy_find_assigned(FAR const char *intf, * Name: phy_handler ****************************************************************************/ -static int phy_handler(FAR struct phy_notify_s *client) +static int phy_handler(int irq, FAR void *context, FAR void *arg) { + FAR struct phy_notify_s *client = (FAR struct phy_notify_s *)arg; #ifdef CONFIG_CAN_PASS_STRUCTS union sigval value; #endif int ret; - DEBUGASSERT(client && client->assigned && client->enable); - phyinfo("Entry client %d, signalling PID=%d with signal %d\n", - client->index, client->pid, client->signo); + DEBUGASSERT(client != NULL && client->assigned && client->enable); + phyinfo("Signalling PID=%d with signal %d\n", client->pid, client->signo); /* Disable further interrupts */ @@ -294,36 +270,6 @@ static int phy_handler(FAR struct phy_notify_s *client) return OK; } -/**************************************************************************** - * Name: phy_handler_0, phy_handler_1, ... - ****************************************************************************/ - -static int phy_handler_0(int irq, FAR void *context, FAR void *arg) -{ - return phy_handler(&g_notify_clients[0]); -} - -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 1 -static int phy_handler_1(int irq, FAR void *context, FAR void *arg) -{ - return phy_handler(&g_notify_clients[1]); -} -#endif - -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 2 -static int phy_handler_2(int irq, FAR void *context, FAR void *arg) -{ - return phy_handler(&g_notify_clients[2]); -} -#endif - -#if CONFIG_PHY_NOTIFICATION_NCLIENTS > 3 -static int phy_handler_3(int irq, FAR void *context, FAR void *arg) -{ - return phy_handler(&g_notify_clients[3]); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -358,6 +304,8 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, FAR void *arg) { FAR struct phy_notify_s *client; + int ret = OK; + DEBUGASSERT(intf); ninfo("%s: PID=%d signo=%d arg=%p\n", intf, pid, signo, arg); @@ -403,14 +351,14 @@ int phy_notify_subscribe(FAR const char *intf, pid_t pid, int signo, /* Attach/re-attach the PHY interrupt */ - (void)arch_phy_irq(intf, g_notify_handler[client->index], &client->enable); + ret = arch_phy_irq(intf, phy_handler, client, &client->enable); } /* Enable/re-enable the PH interrupt */ DEBUGASSERT(client->enable); client->enable(true); - return OK; + return ret; } /**************************************************************************** diff --git a/drivers/wireless/cc1101.c b/drivers/wireless/cc1101.c index e42fe085728..e9ce3805c5d 100644 --- a/drivers/wireless/cc1101.c +++ b/drivers/wireless/cc1101.c @@ -585,11 +585,10 @@ struct cc1101_dev_s *cc1101_init(struct spi_dev_s *spi, uint8_t isrpin, cc1101_setgdo(dev, dev->isrpin, CC1101_GDO_SYNC); - /* Bind to external interrupt line */ - - /* depends on STM32: TODO: Make that config within pinset and - * provide general gpio interface - * stm32_gpiosetevent(pinset, false, true, true, cc1101_eventcb); + /* Configure to receive interrupts on the external GPIO interrupt line. + * + * REVISIT: There is no MCU-independent way to do this in this + * context. */ return dev; @@ -599,8 +598,11 @@ int cc1101_deinit(struct cc1101_dev_s *dev) { ASSERT(dev); - /* Release interrupt */ - /* stm32_gpiosetevent(pinset, false, false, false, NULL); */ + /* Release the external GPIO interrupt + * + * REVISIT: There is no MCU-independent way to do this in this + * context. + */ /* Power down chip */ diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 82b3086092b..ce72c82c902 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -2082,10 +2082,6 @@ size_t up_check_intstack_remain(void); #endif #endif -/**************************************************************************** - * Board-specific button interfaces exported by the board-specific logic - ****************************************************************************/ - /**************************************************************************** * Name: up_rtc_initialize * @@ -2251,19 +2247,19 @@ int up_rtc_settime(FAR const struct timespec *tp); * asserts an interrupt. Must reside in OS space, but can * signal tasks in user space. A value of NULL can be passed * in order to detach and disable the PHY interrupt. + * arg - The argument that will accompany the interrupt * enable - A function pointer that be unsed to enable or disable the * PHY interrupt. * * Returned Value: - * The previous PHY interrupt handler address is returned. This allows you - * to temporarily replace an interrupt handler, then restore the original - * interrupt handler. NULL is returned if there is was not handler in - * place when the call was made. + * Zero (OK) returned on success; a negated errno value is returned on + * failure. * ****************************************************************************/ #ifdef CONFIG_ARCH_PHY_INTERRUPT -xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable); +int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg, + phy_enable_t *enable); #endif /**************************************************************************** diff --git a/include/nuttx/board.h b/include/nuttx/board.h index 633ea9c6839..cd08aceddd0 100644 --- a/include/nuttx/board.h +++ b/include/nuttx/board.h @@ -603,8 +603,6 @@ uint8_t board_buttons(void); * This function may be called to register an interrupt handler that will * be called when a button is depressed or released. The ID value is a * button enumeration value that uniquely identifies a button resource. - * The previous interrupt handler address is returned (so that it may - * restored, if so desired). * * NOTE: This interface may or may not be supported by board-specific * logic. If the board supports any button interfaces, then @@ -614,7 +612,7 @@ uint8_t board_buttons(void); ****************************************************************************/ #ifdef CONFIG_ARCH_IRQBUTTONS -xcpt_t board_button_irq(int id, xcpt_t irqhandler, FAR void *arg); +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg); #endif /**************************************************************************** diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index 05f2c88af73..5b3a461b53b 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -107,7 +107,6 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) irqstate_t flags; systime_t starttick; sigset_t set; - struct siginfo value; int errval; #ifdef CONFIG_DEBUG_ASSERTIONS /* Warning avoidance */ int ret; @@ -141,9 +140,9 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) /* nanosleep is a simple application of sigtimedwait. */ #ifdef CONFIG_DEBUG_ASSERTIONS /* Warning avoidance */ - ret = sigtimedwait(&set, &value, rqtp); + ret = sigtimedwait(&set, NULL, rqtp); #else - (void)sigtimedwait(&set, &value, rqtp); + (void)sigtimedwait(&set, NULL, rqtp); #endif /* sigtimedwait() cannot succeed. It should always return error with diff --git a/sched/signal/sig_pause.c b/sched/signal/sig_pause.c index 5a83f1a735b..62b90c2935c 100644 --- a/sched/signal/sig_pause.c +++ b/sched/signal/sig_pause.c @@ -74,7 +74,6 @@ int pause(void) { - struct siginfo value; sigset_t set; int ret; @@ -93,7 +92,7 @@ int pause(void) * meaning that some unblocked signal was caught. */ - ret = sigwaitinfo(&set, &value); + ret = sigwaitinfo(&set, NULL); leave_cancellation_point(); return ret; } diff --git a/sched/signal/sig_timedwait.c b/sched/signal/sig_timedwait.c index dcbc892fd97..40cf8b55e6a 100644 --- a/sched/signal/sig_timedwait.c +++ b/sched/signal/sig_timedwait.c @@ -171,9 +171,9 @@ static void sig_timeout(int argc, wdparm_t itcb) * empty message queue. * * Parameters: - * set - The pending signal set. - * info - The returned value - * timeout - The amount of time to wait + * set - The pending signal set. + * info - The returned value (may be NULL). + * timeout - The amount of time to wait (may be NULL) * * Return Value: * Signal number that cause the wait to be terminated, otherwise -1 (ERROR) @@ -229,7 +229,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, /* Return the signal info to the caller if so requested */ - if (info) + if (info != NULL) { memcpy(info, &sigpend->info, sizeof(struct siginfo)); } @@ -254,7 +254,7 @@ int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info, /* Check if we should wait for the timeout */ - if (timeout) + if (timeout != NULL) { /* Convert the timespec to system clock ticks, making sure that * the resulting delay is greater than or equal to the requested