MRF24J40: Take advantage of new OS features for interrupt parameter passing.

This commit is contained in:
Gregory Nutt 2017-03-27 10:48:58 -06:00
parent b315f0d851
commit 3fbf59e2bc
3 changed files with 25 additions and 31 deletions

View File

@ -99,6 +99,7 @@ struct stm32_priv_s
{
struct mrf24j40_lower_s dev;
xcpt_t handler;
FAR void *arg;
uint32_t intcfg;
uint8_t spidev;
};
@ -117,9 +118,9 @@ struct stm32_priv_s
*/
static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
xcpt_t handler);
xcpt_t handler, FAR void *arg);
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower,
int state);
bool state);
static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv);
/****************************************************************************
@ -173,7 +174,7 @@ static struct stm32_priv_s g_mrf24j40_mb2_priv =
*/
static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
xcpt_t handler)
xcpt_t handler, FAR void *arg)
{
FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower;
@ -182,10 +183,12 @@ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
/* Just save the handler for use when the interrupt is enabled */
priv->handler = handler;
priv->arg = arg;
return OK;
}
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state)
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower,
bool state)
{
FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower;
@ -193,15 +196,15 @@ static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state
* has not yet been 'attached'
*/
DEBUGASSERT(priv != NULL && (priv->handler != NULL || state == 0));
DEBUGASSERT(priv != NULL && (priv->handler != NULL || !state));
/* Attach and enable, or detach and disable */
wlinfo("state:%d\n", state);
if (state != 0)
wlinfo("state:%d\n", (int)state);
if (state)
{
(void)stm32_gpiosetevent(priv->intcfg, true, true, true,
priv->handler, NULL);
priv->handler, priv->arg);
}
else
{

View File

@ -196,7 +196,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee,
static struct mrf24j40_radio_s g_mrf24j40_devices[1];
static const struct ieee802154_radioops_s mrf24j40_devops =
static const struct ieee802154_radioops_s mrf24j40_devops =
{
mrf24j40_setchannel, mrf24j40_getchannel,
mrf24j40_setpanid , mrf24j40_getpanid,
@ -1322,9 +1322,9 @@ static void mrf24j40_irqworker(FAR void *arg)
mrf24j40_irqwork_tx(dev);
}
/* Re-Enable GPIO interrupts */
/* Re-enable GPIO interrupts */
dev->lower->enable(dev->lower, TRUE);
dev->lower->enable(dev->lower, true);
}
/****************************************************************************
@ -1346,16 +1346,9 @@ static void mrf24j40_irqworker(FAR void *arg)
static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg)
{
/* To support multiple devices,
* retrieve the priv structure using the irq number
*
* REVISIT: This will not handler multiple MRF24J40 devices. The correct
* solutions is to pass the struct mrf24j40_radio_s in the call to
* irq_attach() as the third 'arg' parameter. That will be provided here
* and the correct instance can be obtained with a simply case of 'arg'.
*/
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg;
register FAR struct mrf24j40_radio_s *dev = &g_mrf24j40_devices[0];
DEBUGASSERT(dev != NULL);
/* In complex environments, we cannot do SPI transfers from the interrupt
* handler because semaphores are probably used to lock the SPI bus. In
@ -1371,7 +1364,7 @@ static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg)
* Interrupts are re-enabled in enc_irqworker() when the work is completed.
*/
dev->lower->enable(dev->lower, FALSE);
dev->lower->enable(dev->lower, false);
return work_queue(HPWORK, &dev->irqwork, mrf24j40_irqworker, (FAR void *)dev, 0);
}
@ -1403,13 +1396,9 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi,
dev = &g_mrf24j40_devices[0];
#endif
/* Attach irq.
*
* REVISIT: A third argument is required to pass the instance of 'lower'
* to the interrupt handler.
*/
/* Attach irq */
if (lower->attach(lower, mrf24j40_interrupt) != OK)
if (lower->attach(lower, mrf24j40_interrupt, dev) != OK)
{
#if 0
free(dev);
@ -1454,7 +1443,6 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi,
mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO);
dev->lower->enable(dev->lower, TRUE);
dev->lower->enable(dev->lower, true);
return &dev->ieee;
}

View File

@ -40,6 +40,8 @@
* Included files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <nuttx/arch.h>
/****************************************************************************
@ -62,8 +64,9 @@
struct mrf24j40_lower_s
{
int (*attach)(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler);
void (*enable)(FAR const struct mrf24j40_lower_s *lower, int state);
int (*attach)(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler,
FAR void *arg);
void (*enable)(FAR const struct mrf24j40_lower_s *lower, bool state);
};
#ifdef __cplusplus