wireless/ieee802154: Changes radio interface to match MAC callback design

This commit is contained in:
Anthony Merlino 2017-04-19 13:26:30 -04:00
parent 3950541136
commit 37e7c67373
3 changed files with 57 additions and 44 deletions

View File

@ -112,10 +112,7 @@ struct mrf24j40_txdesc_s
struct mrf24j40_radio_s
{
struct ieee802154_radio_s radio; /* The public device instance */
/* Reference to the bound upper layer via the phyif interface */
FAR struct ieee802154_phyif_s *phyif;
FAR struct ieee802154_radiocb_s *radiocb; /* Registered callbacks */
/* Low-level MCU-specific support */
@ -215,7 +212,7 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio,
/* Driver operations */
static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio,
FAR struct ieee802154_phyif_s *phyif);
FAR struct ieee802154_radiocb_s *radiocb);
static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd,
unsigned long arg);
static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio,
@ -250,12 +247,12 @@ static const struct ieee802154_radioops_s mrf24j40_devops =
****************************************************************************/
static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio,
FAR struct ieee802154_phyif_s *phyif)
FAR struct ieee802154_radiocb_s *radiocb)
{
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
DEBUGASSERT(dev != NULL);
dev->phyif = phyif;
dev->radiocb = radiocb;
return OK;
}
@ -335,9 +332,8 @@ static void mrf24j40_dopoll_csma(FAR void *arg)
{
/* need to somehow allow for a handle to be passed */
ret = dev->phyif->ops->poll_csma(dev->phyif,
&dev->csma_desc.pub,
&dev->tx_buf[0]);
ret = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub,
&dev->tx_buf[0]);
if (ret > 0)
{
/* Now the txdesc is in use */
@ -431,8 +427,8 @@ static void mrf24j40_dopoll_gts(FAR void *arg)
{
if (!dev->gts_desc[gts].busy)
{
ret = dev->phyif->ops->poll_gts(dev->phyif, &dev->gts_desc[gts].pub,
&dev->tx_buf[0]);
ret = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub,
&dev->tx_buf[0]);
if (ret > 0)
{
/* Now the txdesc is in use */

View File

@ -167,31 +167,20 @@ struct ieee802154_txdesc_s
/* TODO: Add slotting information for GTS transactions */
};
struct ieee802154_phyif_s; /* Forward Reference */
struct ieee802154_phyifops_s
struct ieee802154_radiocb_s
{
CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif,
CODE int (*poll_csma) (FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf);
CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif,
CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf);
};
struct ieee802154_phyif_s
{
FAR const struct ieee802154_phyifops_s *ops;
/* Driver-specific information */
FAR void * priv;
};
struct ieee802154_radio_s; /* Forward reference */
struct ieee802154_radioops_s
{
CODE int (*bind) (FAR struct ieee802154_radio_s *radio,
FAR struct ieee802154_phyif_s *phyif);
FAR struct ieee802154_radiocb_s *radiocb);
CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd,
unsigned long arg);
CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool state,

View File

@ -86,6 +86,12 @@ struct mac802154_unsec_mhr_s
} u;
};
struct mac802154_radiocb_s
{
struct ieee802154_radiocb_s cb;
FAR struct ieee802154_privmac_s *priv;
};
/* The privmac structure holds the internal state of the MAC and is the
* underlying represention of the opaque MACHANDLE. It contains storage for
* the IEEE802.15.4 MIB attributes.
@ -95,7 +101,7 @@ struct ieee802154_privmac_s
{
FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */
FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */
FAR struct ieee802154_phyif_s phyif; /* Interface to bind to radio */
FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */
sem_t exclsem; /* Support exclusive access */
@ -244,11 +250,11 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv);
/* IEEE 802.15.4 PHY Interface OPs */
static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif,
static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc,
FAR uint8_t *buf);
static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif,
static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc,
FAR uint8_t *buf);
@ -256,11 +262,6 @@ static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif,
* Private Data
****************************************************************************/
static const struct ieee802154_phyifops_s mac802154_phyifops =
{
mac802154_poll_csma,
mac802154_poll_gts
};
/****************************************************************************
* Private Functions
@ -351,6 +352,7 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv)
MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev)
{
FAR struct ieee802154_privmac_s *mac;
FAR struct ieee802154_radiocb_s *radiocb;
/* Allocate object */
@ -369,12 +371,17 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev)
mac802154_defaultmib(mac);
mac802154_applymib(mac);
mac->phyif.ops = &mac802154_phyifops;
mac->phyif.priv = mac;
/* Initialize the Radio callbacks */
/* Bind our PHY interface to the radio */
mac->radiocb.priv = mac;
radiodev->ops->bind(radiodev, &mac->phyif);
radiocb = &mac->radiocb.cb;
radiocb->poll_cmsa = mac802154_poll_csma;
radiocb->poll_gts = mac802154_poll_gts;
/* Bind our callback structure */
radiodev->ops->bind(radiodev, &mac->radiocb.cb);
return (MACHANDLE)mac;
}
@ -701,16 +708,18 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req)
/* Called from interrupt level or worker thread with interrupts disabled */
static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif,
static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc,
FAR uint8_t *buf)
{
FAR struct ieee802154_privmac_s *priv =
(FAR struct ieee802154_privmac_s *)&phyif->priv;
FAR struct mac802154_radiocb_s *cb =
(FAR struct mac802154_radiocb_s *)radiocb;
FAR struct ieee802154_privmac_s *priv;
FAR struct mac802154_trans_s *trans;
int ret = 0;
DEBUGASSERT(priv != 0);
DEBUGASSERT(cb != NULL && cb->priv != NULL);
priv = cb->priv;
/* Get exclusive access to the driver structure. We don't care about any
* signals so if we see one, just go back to trying to get access again.
@ -753,10 +762,29 @@ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif,
return ret;
}
static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif,
static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc,
FAR uint8_t *buf)
{
FAR struct mac802154_radiocb_s *cb =
(FAR struct mac802154_radiocb_s *)radiocb;
FAR struct ieee802154_privmac_s *priv;
FAR struct mac802154_trans_s *trans;
int ret = 0;
DEBUGASSERT(cb != NULL && cb->priv != NULL);
priv = cb->priv;
/* Get exclusive access to the driver structure. We don't care about any
* signals so if we see one, just go back to trying to get access again.
*/
while (mac802154_takesem(&priv->exclsem) != 0);
#warning Missing logic.
mac802154_givesem(&priv->exclsem);
return 0;
}