Merged in merlin17/nuttx/ieee802154 (pull request #325)
Ieee802154 Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
commit
eec8fd452e
@ -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 */
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -101,10 +101,10 @@ struct mac802154dev_callback_s
|
||||
/* This holds the information visible to the MAC layer */
|
||||
|
||||
struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */
|
||||
FAR struct mac802154_devwrapper_s *mc_priv; /* Our priv data */
|
||||
FAR struct mac802154_chardevice_s *mc_priv; /* Our priv data */
|
||||
};
|
||||
|
||||
struct mac802154_devwrapper_s
|
||||
struct mac802154_chardevice_s
|
||||
{
|
||||
MACHANDLE md_mac; /* Saved binding to the mac layer */
|
||||
struct mac802154dev_callback_s md_cb; /* Callback information */
|
||||
@ -150,7 +150,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
|
||||
|
||||
/* MAC callback helpers */
|
||||
|
||||
static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev,
|
||||
static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev,
|
||||
FAR struct ieee802154_data_conf_s *conf);
|
||||
|
||||
/****************************************************************************
|
||||
@ -212,7 +212,7 @@ static inline int mac802154dev_takesem(sem_t *sem)
|
||||
static int mac802154dev_open(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
FAR struct mac802154dev_open_s *opriv;
|
||||
int ret;
|
||||
|
||||
@ -269,7 +269,7 @@ errout_with_sem:
|
||||
static int mac802154dev_close(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
FAR struct mac802154dev_open_s *opriv;
|
||||
FAR struct mac802154dev_open_s *curr;
|
||||
FAR struct mac802154dev_open_s *prev;
|
||||
@ -281,7 +281,7 @@ static int mac802154dev_close(FAR struct file *filep)
|
||||
opriv = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
DEBUGASSERT(inode->i_private);
|
||||
dev = (FAR struct mac802154_devwrapper_s *)inode->i_private;
|
||||
dev = (FAR struct mac802154_chardevice_s *)inode->i_private;
|
||||
|
||||
/* Handle an improbable race conditions with the following atomic test
|
||||
* and set.
|
||||
@ -361,13 +361,13 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t len)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(filep && filep->f_inode);
|
||||
inode = filep->f_inode;
|
||||
DEBUGASSERT(inode->i_private);
|
||||
dev = (FAR struct mac802154_devwrapper_s *)inode->i_private;
|
||||
dev = (FAR struct mac802154_chardevice_s *)inode->i_private;
|
||||
|
||||
/* Check to make sure that the buffer is big enough to hold at least one
|
||||
* packet.
|
||||
@ -408,7 +408,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t len)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
FAR struct ieee802154_data_req_s *req;
|
||||
struct mac802154dev_dwait_s dwait;
|
||||
int ret;
|
||||
@ -416,7 +416,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
|
||||
DEBUGASSERT(filep && filep->f_inode);
|
||||
inode = filep->f_inode;
|
||||
DEBUGASSERT(inode->i_private);
|
||||
dev = (FAR struct mac802154_devwrapper_s *)inode->i_private;
|
||||
dev = (FAR struct mac802154_chardevice_s *)inode->i_private;
|
||||
|
||||
/* Check to make sure that the buffer is big enough to hold at least one
|
||||
* packet. */
|
||||
@ -460,7 +460,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
|
||||
dev->md_dwait = &dwait;
|
||||
|
||||
mac802154dev_givesem(&dev->md_exclsem);
|
||||
|
||||
}
|
||||
|
||||
/* Pass the request to the MAC layer */
|
||||
@ -473,7 +472,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
if (!(filep->f_oflags & O_NONBLOCK))
|
||||
{
|
||||
/* Wait for the DATA.confirm callback to be called for our handle */
|
||||
@ -509,14 +507,14 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_priv != NULL &&
|
||||
filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
DEBUGASSERT(inode->i_private);
|
||||
dev = (FAR struct mac802154_devwrapper_s *)inode->i_private;
|
||||
dev = (FAR struct mac802154_chardevice_s *)inode->i_private;
|
||||
|
||||
/* Get exclusive access to the driver structure */
|
||||
|
||||
@ -599,7 +597,7 @@ static void mac802154dev_mlme_notify(FAR struct ieee802154_maccb_s *maccb,
|
||||
{
|
||||
FAR struct mac802154dev_callback_s *cb =
|
||||
(FAR struct mac802154dev_callback_s *)maccb;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
|
||||
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
|
||||
dev = cb->mc_priv;
|
||||
@ -618,7 +616,7 @@ static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb,
|
||||
{
|
||||
FAR struct mac802154dev_callback_s *cb =
|
||||
(FAR struct mac802154dev_callback_s *)maccb;
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
|
||||
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
|
||||
dev = cb->mc_priv;
|
||||
@ -635,7 +633,7 @@ static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb,
|
||||
}
|
||||
}
|
||||
|
||||
static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev,
|
||||
static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev,
|
||||
FAR struct ieee802154_data_conf_s *conf)
|
||||
{
|
||||
FAR struct mac802154dev_dwait_s *curr;
|
||||
@ -722,12 +720,12 @@ static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev,
|
||||
|
||||
int mac802154dev_register(MACHANDLE mac, int minor)
|
||||
{
|
||||
FAR struct mac802154_devwrapper_s *dev;
|
||||
FAR struct mac802154_chardevice_s *dev;
|
||||
FAR struct ieee802154_maccb_s *maccb;
|
||||
char devname[DEVNAME_FMTLEN];
|
||||
int ret;
|
||||
|
||||
dev = kmm_zalloc(sizeof(struct mac802154_devwrapper_s));
|
||||
dev = kmm_zalloc(sizeof(struct mac802154_chardevice_s));
|
||||
if (!dev)
|
||||
{
|
||||
wlerr("ERROR: Failed to allocate device structure\n");
|
||||
|
Loading…
Reference in New Issue
Block a user