diff --git a/configs/fire-stm32v2/src/stm32_enc28j60.c b/configs/fire-stm32v2/src/stm32_enc28j60.c index 9ac4040e4b..89625b6eb7 100644 --- a/configs/fire-stm32v2/src/stm32_enc28j60.c +++ b/configs/fire-stm32v2/src/stm32_enc28j60.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/fire-stm32v2/src/stm32_enc28j60.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -106,13 +106,15 @@ struct stm32_lower_s { const struct enc_lower_s lower; /* Low-level MCU interface */ xcpt_t handler; /* ENC28J60 interrupt handler */ + FAR void *arg; /* Argument that accompanies the interrupt */ }; /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler); +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg); static void up_enable(FAR const struct enc_lower_s *lower); static void up_disable(FAR const struct enc_lower_s *lower); @@ -134,6 +136,7 @@ static struct stm32_lower_s g_enclower = .disable = up_disable }, .handler = NULL, + .arg = NULL }; /**************************************************************************** @@ -144,13 +147,15 @@ static struct stm32_lower_s g_enclower = * Name: struct enc_lower_s methods ****************************************************************************/ -static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler) +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg) { FAR struct stm32_lower_s *priv = (FAR struct stm32_lower_s *)lower; /* Just save the handler for use when the interrupt is enabled */ priv->handler = handler; + priv->arg = arg; return OK; } @@ -160,9 +165,14 @@ static void up_enable(FAR const struct enc_lower_s *lower) DEBUGASSERT(priv->handler); (void)stm32_gpiosetevent(GPIO_ENC28J60_INTR, false, true, true, - priv->handler, NULL); + priv->handler, priv->arg); } +/* REVISIT: Since the interrupt is completely torn down, not just disabled, + * in interrupt requests that occurs while the interrupt is disabled will be + * lost. + */ + static void up_disable(FAR const struct enc_lower_s *lower) { (void)stm32_gpiosetevent(GPIO_ENC28J60_INTR, false, true, true, diff --git a/configs/olimex-strp711/src/str71_enc28j60.c b/configs/olimex-strp711/src/str71_enc28j60.c index 5b40eb1357..d45b392c7f 100644 --- a/configs/olimex-strp711/src/str71_enc28j60.c +++ b/configs/olimex-strp711/src/str71_enc28j60.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/olimex-strp711/src/str71_enc28j60.c * - * Copyright (C) 2010, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -154,7 +154,8 @@ * Private Function Prototypes ****************************************************************************/ -static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler); +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg); static void up_enable(FAR const struct enc_lower_s *lower); static void up_disable(FAR const struct enc_lower_s *lower); @@ -182,9 +183,10 @@ static const struct enc_lower_s g_enclower = * Name: struct enc_lower_s methods ****************************************************************************/ -static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler) +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg) { - return irq_attach(ENC28J60_IRQ, handler, NULL); + return irq_attach(ENC28J60_IRQ, handler, arg); } static void up_enable(FAR const struct enc_lower_s *lower) diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index a719f43d7a..23c4c77067 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1833,7 +1833,10 @@ static void enc_irqworker(FAR void *arg) static int enc_interrupt(int irq, FAR void *context, FAR void *arg) { - register FAR struct enc_driver_s *priv = &g_enc28j60[0]; + FAR struct enc_driver_s *priv; + + DEBUGASSERT(arg != NULL); + priv = (FAR struct enc_driver_s *)arg; /* In complex environments, we cannot do SPI transfers from the interrupt * handler because semaphores are probably used to lock the SPI bus. In @@ -2648,7 +2651,7 @@ int enc_initialize(FAR struct spi_dev_s *spi, /* Attach the interrupt to the driver (but don't enable it yet) */ - if (lower->attach(lower, enc_interrupt)) + if (lower->attach(lower, enc_interrupt, priv) < 0) { /* We could not attach the ISR to the interrupt */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 58633d307a..5c2b590e2e 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -1,6 +1,7 @@ /**************************************************************************** * drivers/net/encx24j600.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2013-2014 UVC Ingenieure. All rights reserved. * Author: Max Holtzberg * @@ -1976,7 +1977,7 @@ static void enc_irqworker(FAR void *arg) static int enc_interrupt(int irq, FAR void *context, FAR void *arg) { - FAR struct enc_driver_s *priv = &g_encx24j600[0]; + FAR struct enc_driver_s *priv; DEBUGASSERT(arg != NULL); priv = (FAR struct enc_driver_s *)arg; diff --git a/include/nuttx/net/enc28j60.h b/include/nuttx/net/enc28j60.h index 78b394ec9f..f2fed8052d 100644 --- a/include/nuttx/net/enc28j60.h +++ b/include/nuttx/net/enc28j60.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/enc28j60.h * - * Copyright (C) 2010, 2012, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012, 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -86,7 +86,8 @@ struct enc_lower_s { - int (*attach)(FAR const struct enc_lower_s *lower, xcpt_t handler); + int (*attach)(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg); void (*enable)(FAR const struct enc_lower_s *lower); void (*disable)(FAR const struct enc_lower_s *lower); }; diff --git a/include/nuttx/net/encx24j600.h b/include/nuttx/net/encx24j600.h index 2d1b055005..16b9de747f 100644 --- a/include/nuttx/net/encx24j600.h +++ b/include/nuttx/net/encx24j600.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/net/encx24j600.h * - * 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