Skip to content

Commit 8a6bb51

Browse files
authored
Merge pull request #20992 from benpicco/netdev_ieee802154_submac-new_api
drivers/netdev_ieee802154_submac: port to netdev_new_api
2 parents e0a6628 + ca35c7f commit 8a6bb51

File tree

7 files changed

+46
-19
lines changed

7 files changed

+46
-19
lines changed

drivers/include/net/netdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ typedef enum {
251251
* @brief ACK requested but not received
252252
*
253253
* @deprecated Issue an NETDEV_EVENT_TX_COMPLETE event instead and return
254-
* `-ECOMM` in netdev_driver_t::confirm_send. Via the `info`
254+
* `-EHOSTUNREACH` in netdev_driver_t::confirm_send. Via the `info`
255255
* parameter additional details about the error can be passed
256256
*/
257257
NETDEV_EVENT_TX_NOACK,

drivers/include/net/netdev/ieee802154_submac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
ieee802154_submac_t submac; /**< IEEE 802.15.4 SubMAC descriptor */
5151
ztimer_t ack_timer; /**< ztimer descriptor for the ACK timeout timer */
5252
int isr_flags; /**< netdev submac @ref NETDEV_EVENT_ISR flags */
53+
int bytes_tx; /**< size of the sent frame or tx error */
5354
int8_t retrans; /**< number of frame retransmissions of the last TX */
5455
bool dispatch; /**< whether an event should be dispatched or not */
5556
netdev_event_t ev; /**< event to be dispatched */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
USEMODULE += netdev_ieee802154
2+
USEMODULE += netdev_new_api
3+
USEMODULE += ieee802154
4+
USEMODULE += ieee802154_submac
5+
USEMODULE += ztimer_usec

drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static int _send(netdev_t *netdev, const iolist_t *pkt)
174174
* inside the TX Done callback */
175175
netdev_submac->ev = NETDEV_EVENT_TX_STARTED;
176176
}
177+
netdev_submac->bytes_tx = res;
177178
return res;
178179
}
179180

@@ -280,21 +281,14 @@ static void submac_tx_done(ieee802154_submac_t *submac, int status,
280281
}
281282

282283
netdev_submac->dispatch = true;
284+
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE;
283285

284286
switch (status) {
285-
case TX_STATUS_SUCCESS:
286-
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE;
287-
break;
288-
case TX_STATUS_FRAME_PENDING:
289-
netdev_submac->ev = NETDEV_EVENT_TX_COMPLETE_DATA_PENDING;
290-
break;
291287
case TX_STATUS_MEDIUM_BUSY:
292-
netdev_submac->ev = NETDEV_EVENT_TX_MEDIUM_BUSY;
288+
netdev_submac->bytes_tx = -EBUSY;
293289
break;
294290
case TX_STATUS_NO_ACK:
295-
netdev_submac->ev = NETDEV_EVENT_TX_NOACK;
296-
break;
297-
default:
291+
netdev_submac->bytes_tx = -EHOSTUNREACH;
298292
break;
299293
}
300294
}
@@ -377,6 +371,16 @@ static int _init(netdev_t *netdev)
377371
return 0;
378372
}
379373

374+
static int _confirm_send(netdev_t *netdev, void *info)
375+
{
376+
(void)info;
377+
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
378+
netdev_ieee802154_submac_t *netdev_submac = container_of(netdev_ieee802154,
379+
netdev_ieee802154_submac_t,
380+
dev);
381+
return netdev_submac->bytes_tx;
382+
}
383+
380384
int netdev_ieee802154_submac_init(netdev_ieee802154_submac_t *netdev_submac)
381385
{
382386
netdev_t *netdev = &netdev_submac->dev.netdev;
@@ -402,6 +406,7 @@ static const netdev_driver_t netdev_submac_driver = {
402406
.recv = _recv,
403407
.isr = _isr,
404408
.init = _init,
409+
.confirm_send = _confirm_send,
405410
};
406411

407412
/** @} */

pkg/openthread/contrib/netdev/openthread_netdev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) {
6767
recv_pkt(sInstance, dev);
6868
break;
6969
case NETDEV_EVENT_TX_COMPLETE:
70+
#ifndef MODULE_NETDEV_NEW_API
7071
case NETDEV_EVENT_TX_NOACK:
7172
case NETDEV_EVENT_TX_MEDIUM_BUSY:
73+
#endif
7274
DEBUG("openthread_netdev: Transmission of a packet\n");
7375
send_pkt(sInstance, dev, event);
7476
break;

pkg/openthread/contrib/platform_radio.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,27 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
172172
}
173173

174174
/* Called upon TX event */
175+
#ifdef MODULE_NETDEV_NEW_API
176+
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
177+
{
178+
(void)event;
179+
180+
assert(dev->driver->confirm_send);
181+
182+
int res = dev->driver->confirm_send(dev, NULL);
183+
DEBUG("openthread: confirm_send returned %d\n", res);
184+
185+
if (res > 0) {
186+
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
187+
} else if (res == -EBUSY) {
188+
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_CHANNEL_ACCESS_FAILURE);
189+
} else if (res == -EHOSTUNREACH) {
190+
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NO_ACK);
191+
} else {
192+
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_FAILED);
193+
}
194+
}
195+
#else
175196
void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
176197
{
177198
(void)dev;
@@ -198,6 +219,7 @@ void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
198219
break;
199220
}
200221
}
222+
#endif
201223

202224
/* OpenThread will call this for setting PAN ID */
203225
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)

sys/Makefile.dep

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ ifneq (,$(filter netdev_ieee802154,$(USEMODULE)))
150150
USEMODULE += random
151151
endif
152152

153-
ifneq (,$(filter netdev_ieee802154_submac,$(USEMODULE)))
154-
USEMODULE += netdev_ieee802154
155-
USEMODULE += netdev_legacy_api
156-
USEMODULE += ieee802154
157-
USEMODULE += ieee802154_submac
158-
USEMODULE += ztimer_usec
159-
endif
160-
161153
ifneq (,$(filter uhcpc,$(USEMODULE)))
162154
USEMODULE += posix_inet
163155
USEMODULE += ztimer_msec

0 commit comments

Comments
 (0)