1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

Merge pull request #20992 from benpicco/netdev_ieee802154_submac-new_api

drivers/netdev_ieee802154_submac: port to netdev_new_api
This commit is contained in:
benpicco 2025-05-12 16:11:18 +00:00 committed by GitHub
commit 8a6bb51adb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 46 additions and 19 deletions

View File

@ -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,

View File

@ -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 */

View File

@ -0,0 +1,5 @@
USEMODULE += netdev_ieee802154
USEMODULE += netdev_new_api
USEMODULE += ieee802154
USEMODULE += ieee802154_submac
USEMODULE += ztimer_usec

View File

@ -174,6 +174,7 @@ static int _send(netdev_t *netdev, const iolist_t *pkt)
* inside the TX Done callback */
netdev_submac->ev = NETDEV_EVENT_TX_STARTED;
}
netdev_submac->bytes_tx = res;
return res;
}
@ -280,21 +281,14 @@ static void submac_tx_done(ieee802154_submac_t *submac, int status,
}
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;
}
}
@ -377,6 +371,16 @@ static int _init(netdev_t *netdev)
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;
@ -402,6 +406,7 @@ static const netdev_driver_t netdev_submac_driver = {
.recv = _recv,
.isr = _isr,
.init = _init,
.confirm_send = _confirm_send,
};
/** @} */

View File

@ -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;

View File

@ -172,6 +172,27 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
}
/* 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;
@ -198,6 +219,7 @@ void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
break;
}
}
#endif
/* OpenThread will call this for setting PAN ID */
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)

View File

@ -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