Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/at86rf215: port to new netdev API #20672

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions drivers/at86rf215/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 0 additions & 1 deletion drivers/at86rf215/Makefile.include
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 1 addition & 38 deletions drivers/at86rf215/at86rf215.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
netdev_register(netdev, NETDEV_AT86RF215, index);
}

void at86rf215_setup(at86rf215_t *dev_09, at86rf215_t *dev_24, const at86rf215_params_t *params, uint8_t index)

Check warning on line 43 in drivers/at86rf215/at86rf215.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
{
/* configure the sub-GHz interface */
if (dev_09) {
Expand Down Expand Up @@ -85,7 +85,7 @@
#if CONFIG_AT86RF215_RPC_EN
| AT86RF215_OPT_RPC
#endif
;

Check warning on line 88 in drivers/at86rf215/at86rf215.c

View workflow job for this annotation

GitHub Actions / static-tests

semicolon is isolated from other tokens

/* apply the configuration */
at86rf215_reset(dev);
Expand Down Expand Up @@ -244,51 +244,14 @@
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;
Expand Down
27 changes: 25 additions & 2 deletions drivers/at86rf215/at86rf215_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
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,
Expand Down Expand Up @@ -179,6 +181,20 @@
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);
Expand Down Expand Up @@ -853,8 +869,13 @@

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;
Expand Down Expand Up @@ -995,7 +1016,9 @@
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 */
Expand Down Expand Up @@ -1128,7 +1151,7 @@
}

/* CCATX signals medium busy */
if ((dev->flags & AT86RF215_OPT_CCATX) && (rf_irq_mask & RF_IRQ_EDC) && (bb_irq_mask & BB_IRQ_TXFE)) {

Check warning on line 1154 in drivers/at86rf215/at86rf215_netdev.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
bb_irq_mask &= ~BB_IRQ_TXFE;
rf_irq_mask &= ~RF_IRQ_EDC;
_handle_edc(dev);
Expand Down
Loading