Skip to content

drivers/netdev_ieee802154_submac: port to netdev_new_api #20992

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

Merged
merged 3 commits into from
May 12, 2025
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
2 changes: 1 addition & 1 deletion drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ typedef enum {
* @brief ACK requested but not received
*
* @deprecated Issue an NETDEV_EVENT_TX_COMPLETE event instead and return
* `-ECOMM` in netdev_driver_t::confirm_send. Via the `info`
* `-EHOSTUNREACH` in netdev_driver_t::confirm_send. Via the `info`
* parameter additional details about the error can be passed
*/
NETDEV_EVENT_TX_NOACK,
Expand Down
1 change: 1 addition & 0 deletions drivers/include/net/netdev/ieee802154_submac.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct {
ieee802154_submac_t submac; /**< IEEE 802.15.4 SubMAC descriptor */
ztimer_t ack_timer; /**< ztimer descriptor for the ACK timeout timer */
int isr_flags; /**< netdev submac @ref NETDEV_EVENT_ISR flags */
int bytes_tx; /**< size of the sent frame or tx error */
int8_t retrans; /**< number of frame retransmissions of the last TX */
bool dispatch; /**< whether an event should be dispatched or not */
netdev_event_t ev; /**< event to be dispatched */
Expand Down
5 changes: 5 additions & 0 deletions drivers/netdev_ieee802154_submac/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USEMODULE += netdev_ieee802154
USEMODULE += netdev_new_api
USEMODULE += ieee802154
USEMODULE += ieee802154_submac
USEMODULE += ztimer_usec
25 changes: 15 additions & 10 deletions drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
{
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
netdev_ieee802154_submac_t *netdev_submac = container_of(netdev_ieee802154, netdev_ieee802154_submac_t, dev);

Check warning on line 46 in drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
ieee802154_submac_t *submac = &netdev_submac->submac;

switch (opt) {
Expand Down Expand Up @@ -174,6 +174,7 @@
* inside the TX Done callback */
netdev_submac->ev = NETDEV_EVENT_TX_STARTED;
}
netdev_submac->bytes_tx = res;
return res;
}

Expand Down Expand Up @@ -280,21 +281,14 @@
}

netdev_submac->dispatch = true;
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE;

switch (status) {
case TX_STATUS_SUCCESS:
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE;
break;
case TX_STATUS_FRAME_PENDING:
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE_DATA_PENDING;
break;
case TX_STATUS_MEDIUM_BUSY:
netdev_submac->ev = NETDEV_EVENT_TX_MEDIUM_BUSY;
netdev_submac->bytes_tx = -EBUSY;
break;
case TX_STATUS_NO_ACK:
netdev_submac->ev = NETDEV_EVENT_TX_NOACK;
break;
default:
netdev_submac->bytes_tx = -EHOSTUNREACH;
break;
}
}
Expand Down Expand Up @@ -377,6 +371,16 @@
return 0;
}

static int _confirm_send(netdev_t *netdev, void *info)
{
(void)info;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
netdev_ieee802154_submac_t *netdev_submac = container_of(netdev_ieee802154,
netdev_ieee802154_submac_t,
dev);
return netdev_submac->bytes_tx;
}

int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac)
{
netdev_t *netdev = &netdev_submac->dev.netdev;
Expand All @@ -402,6 +406,7 @@
.recv = _recv,
.isr = _isr,
.init = _init,
.confirm_send = _confirm_send,
};

/** @} */
2 changes: 2 additions & 0 deletions pkg/openthread/contrib/netdev/openthread_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) {
recv_pkt(sInstance, dev);
break;
case NETDEV_EVENT_TX_COMPLETE:
#ifndef MODULE_NETDEV_NEW_API
case NETDEV_EVENT_TX_NOACK:
case NETDEV_EVENT_TX_MEDIUM_BUSY:
#endif
DEBUG("openthread_netdev: Transmission of a packet\n");
send_pkt(sInstance, dev, event);
break;
Expand Down
22 changes: 22 additions & 0 deletions pkg/openthread/contrib/platform_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,31 @@
}

/* Tell OpenThread that receive has finished */
otPlatRadioReceiveDone(aInstance, res > 0 ? &sReceiveFrame : NULL, res > 0 ? OT_ERROR_NONE : OT_ERROR_ABORT);

Check warning on line 171 in pkg/openthread/contrib/platform_radio.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
}

/* Called upon TX event */
#ifdef MODULE_NETDEV_NEW_API
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
{
(void)event;

assert(dev->driver->confirm_send);

int res = dev->driver->confirm_send(dev, NULL);
DEBUG("openthread: confirm_send returned %d\n", res);

if (res > 0) {
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
} else if (res == -EBUSY) {
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_CHANNEL_ACCESS_FAILURE);
} else if (res == -EHOSTUNREACH) {
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NO_ACK);
} else {
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_FAILED);
}
}
#else
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
{
(void)dev;
Expand All @@ -198,6 +219,7 @@
break;
}
}
#endif

/* OpenThread will call this for setting PAN ID */
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
Expand Down
8 changes: 0 additions & 8 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ ifneq (,$(filter netdev_ieee802154,$(USEMODULE)))
USEMODULE += random
endif

ifneq (,$(filter netdev_ieee802154_submac,$(USEMODULE)))
USEMODULE += netdev_ieee802154
USEMODULE += netdev_legacy_api
USEMODULE += ieee802154
USEMODULE += ieee802154_submac
USEMODULE += ztimer_usec
endif

ifneq (,$(filter uhcpc,$(USEMODULE)))
USEMODULE += posix_inet
USEMODULE += ztimer_msec
Expand Down
Loading