mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/at86rf215: port to new netdev API
This commit is contained in:
parent
1f5e2c7214
commit
c1e79c84d0
@ -24,13 +24,7 @@ FEATURES_REQUIRED += periph_gpio
|
||||
FEATURES_REQUIRED += periph_gpio_irq
|
||||
FEATURES_REQUIRED += periph_spi
|
||||
|
||||
ifneq (,$(filter gnrc,$(USEMODULE)))
|
||||
ifeq (,$(filter gnrc_netif_pktq,$(USEMODULE)))
|
||||
DEFAULT_MODULE += at86rf215_blocking_send
|
||||
endif
|
||||
endif
|
||||
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += ieee802154
|
||||
USEMODULE += netdev_ieee802154
|
||||
USEMODULE += netdev_legacy_api
|
||||
USEMODULE += netdev_new_api
|
||||
|
@ -1,7 +1,6 @@
|
||||
PSEUDOMODULES += at86rf215_batmon
|
||||
PSEUDOMODULES += at86rf215_subghz
|
||||
PSEUDOMODULES += at86rf215_24ghz
|
||||
PSEUDOMODULES += at86rf215_blocking_send
|
||||
|
||||
USEMODULE_INCLUDES_at86rf215 := $(LAST_MAKEFILEDIR)/include
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_at86rf215)
|
||||
|
@ -244,51 +244,14 @@ static bool _tx_ongoing(at86rf215_t *dev)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* As there is no packet queue in RIOT we have to block in send()
|
||||
* when the device is busy sending a previous frame.
|
||||
*
|
||||
* Since both _send() and _isr() are running in the same thread
|
||||
* we have to service radio events while waiting in order to
|
||||
* advance the previous transmission.
|
||||
*/
|
||||
static void _block_while_busy(at86rf215_t *dev)
|
||||
{
|
||||
gpio_irq_disable(dev->params.int_pin);
|
||||
|
||||
do {
|
||||
if (gpio_read(dev->params.int_pin) || dev->timeout) {
|
||||
at86rf215_driver.isr(&dev->netdev.netdev);
|
||||
}
|
||||
/* allow the other interface to process events */
|
||||
thread_yield();
|
||||
} while (_tx_ongoing(dev));
|
||||
|
||||
gpio_irq_enable(dev->params.int_pin);
|
||||
}
|
||||
|
||||
static void at86rf215_block_while_busy(at86rf215_t *dev)
|
||||
{
|
||||
if (!IS_ACTIVE(MODULE_AT86RF215_BLOCKING_SEND)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_tx_ongoing(dev)) {
|
||||
DEBUG("[at86rf215] Block while TXing\n");
|
||||
_block_while_busy(dev);
|
||||
}
|
||||
}
|
||||
|
||||
int at86rf215_tx_prepare(at86rf215_t *dev)
|
||||
{
|
||||
if (dev->state == AT86RF215_STATE_SLEEP) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
if (!IS_ACTIVE(MODULE_AT86RF215_BLOCKING_SEND) && _tx_ongoing(dev)) {
|
||||
if (_tx_ongoing(dev)) {
|
||||
return -EBUSY;
|
||||
} else {
|
||||
at86rf215_block_while_busy(dev);
|
||||
}
|
||||
|
||||
dev->tx_frame_len = IEEE802154_FCS_LEN;
|
||||
|
@ -45,9 +45,11 @@ static int _init(netdev_t *netdev);
|
||||
static void _isr(netdev_t *netdev);
|
||||
static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len);
|
||||
static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len);
|
||||
static int _confirm_send(netdev_t *netdev, void *info);
|
||||
|
||||
const netdev_driver_t at86rf215_driver = {
|
||||
.send = _send,
|
||||
.confirm_send = _confirm_send,
|
||||
.recv = _recv,
|
||||
.init = _init,
|
||||
.isr = _isr,
|
||||
@ -179,6 +181,20 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
static int _confirm_send(netdev_t *netdev, void *info)
|
||||
{
|
||||
(void)info;
|
||||
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
|
||||
at86rf215_t *dev = container_of(netdev_ieee802154, at86rf215_t, netdev);
|
||||
|
||||
if (dev->flags & AT86RF215_OPT_TX_PENDING) {
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
return (int16_t)dev->tx_frame_len;
|
||||
}
|
||||
|
||||
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
{
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
|
||||
@ -853,8 +869,13 @@ static void _tx_end(at86rf215_t *dev, netdev_event_t event)
|
||||
|
||||
at86rf215_tx_done(dev);
|
||||
|
||||
if (event == NETDEV_EVENT_TX_NOACK) {
|
||||
/* signal error to confirm_send */
|
||||
dev->tx_frame_len = (int16_t)-EIO;
|
||||
}
|
||||
|
||||
if (netdev->event_callback) {
|
||||
netdev->event_callback(netdev, event);
|
||||
netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
|
||||
}
|
||||
|
||||
dev->timeout = 0;
|
||||
@ -995,7 +1016,9 @@ static void _handle_edc(at86rf215_t *dev)
|
||||
at86rf215_enable_rpc(dev);
|
||||
at86rf215_tx_done(dev);
|
||||
|
||||
netdev->event_callback(netdev, NETDEV_EVENT_TX_MEDIUM_BUSY);
|
||||
/* signal error to confirm_send */
|
||||
dev->tx_frame_len = (int16_t)-EBUSY;
|
||||
netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
|
||||
|
||||
DEBUG("CSMA give up");
|
||||
/* radio is still in RX mode, tx_done sets IDLE state */
|
||||
|
Loading…
Reference in New Issue
Block a user