From c1e79c84d0cce7d82dd756f1a6a72a7d8d50d1e8 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 15 May 2024 17:23:52 +0200 Subject: [PATCH] drivers/at86rf215: port to new netdev API --- drivers/at86rf215/Makefile.dep | 8 +----- drivers/at86rf215/Makefile.include | 1 - drivers/at86rf215/at86rf215.c | 39 +--------------------------- drivers/at86rf215/at86rf215_netdev.c | 27 +++++++++++++++++-- 4 files changed, 27 insertions(+), 48 deletions(-) diff --git a/drivers/at86rf215/Makefile.dep b/drivers/at86rf215/Makefile.dep index 132a617595..9552ff9a46 100644 --- a/drivers/at86rf215/Makefile.dep +++ b/drivers/at86rf215/Makefile.dep @@ -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 diff --git a/drivers/at86rf215/Makefile.include b/drivers/at86rf215/Makefile.include index 0373011237..e04cf3edd2 100644 --- a/drivers/at86rf215/Makefile.include +++ b/drivers/at86rf215/Makefile.include @@ -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) diff --git a/drivers/at86rf215/at86rf215.c b/drivers/at86rf215/at86rf215.c index 2497c724dd..9df5cda50b 100644 --- a/drivers/at86rf215/at86rf215.c +++ b/drivers/at86rf215/at86rf215.c @@ -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; diff --git a/drivers/at86rf215/at86rf215_netdev.c b/drivers/at86rf215/at86rf215_netdev.c index 5e0baf8754..72d2d5127b 100644 --- a/drivers/at86rf215/at86rf215_netdev.c +++ b/drivers/at86rf215/at86rf215_netdev.c @@ -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 */