diff --git a/arch/arm/src/tiva/tm4c_ethernet.c b/arch/arm/src/tiva/tm4c_ethernet.c index f689028a9a..6a6bc2d4ed 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/configs/sam4e-ek/src/sam_ethernet.c b/configs/sam4e-ek/src/sam_ethernet.c index c59e395e94..7b41e6b622 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/sama5d3-xplained/src/sam_ethernet.c b/configs/sama5d3-xplained/src/sam_ethernet.c index bad7d48b92..501acac39f 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_ethernet.c b/configs/sama5d3x-ek/src/sam_ethernet.c index 9dd45b9c62..5121a03ff4 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_ethernet.c b/configs/sama5d4-ek/src/sam_ethernet.c index 9231e22758..15cce4d2e1 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/same70-xplained/src/sam_ethernet.c b/configs/same70-xplained/src/sam_ethernet.c index ecf61bdf73..053003fe11 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/samv71-xult/src/sam_ethernet.c b/configs/samv71-xult/src/sam_ethernet.c index 247c725824..c08097eaee 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/stm32f4discovery/src/stm32_ethernet.c b/configs/stm32f4discovery/src/stm32_ethernet.c index 0cc23c6016..fcd6d6c214 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/drivers/net/phy_notify.c b/drivers/net/phy_notify.c index 2b552d620d..bb179ca0a9 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/include/nuttx/arch.h b/include/nuttx/arch.h index a0cc691e41..ce72c82c90 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -2247,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 /****************************************************************************