1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #20993 from benpicco/netdev_new_api-enhance

gnrc_netif: netdev_new_api implies TX end irq, no need to check it
This commit is contained in:
Marian Buschsieweke 2024-11-17 08:45:19 +00:00 committed by GitHub
commit 51f969d655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 14 deletions

View File

@ -325,7 +325,6 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
case NETOPT_RX_START_IRQ: case NETOPT_RX_START_IRQ:
case NETOPT_TX_START_IRQ: case NETOPT_TX_START_IRQ:
case NETOPT_TX_END_IRQ:
*((netopt_enable_t *)val) = NETOPT_ENABLE; *((netopt_enable_t *)val) = NETOPT_ENABLE;
return sizeof(netopt_enable_t); return sizeof(netopt_enable_t);
@ -859,7 +858,7 @@ static void _enable_tx2rx(at86rf215_t *dev)
at86rf215_reg_write(dev, dev->BBC->RG_AMCS, amcs); at86rf215_reg_write(dev, dev->BBC->RG_AMCS, amcs);
} }
static void _tx_end(at86rf215_t *dev, netdev_event_t event) static void _tx_end(at86rf215_t *dev)
{ {
netdev_t *netdev = &dev->netdev.netdev; netdev_t *netdev = &dev->netdev.netdev;
@ -871,11 +870,6 @@ static void _tx_end(at86rf215_t *dev, netdev_event_t event)
at86rf215_tx_done(dev); 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) { if (netdev->event_callback) {
netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE);
} }
@ -884,6 +878,14 @@ static void _tx_end(at86rf215_t *dev, netdev_event_t event)
dev->state = AT86RF215_STATE_IDLE; dev->state = AT86RF215_STATE_IDLE;
} }
static void __tx_end_timeout(at86rf215_t *dev)
{
/* signal error to confirm_send */
dev->tx_frame_len = (int16_t)-EHOSTUNREACH;
_tx_end(dev);
}
static void _ack_timeout_cb(void* arg) { static void _ack_timeout_cb(void* arg) {
at86rf215_t *dev = arg; at86rf215_t *dev = arg;
netdev_t *netdev = &dev->netdev.netdev; netdev_t *netdev = &dev->netdev.netdev;
@ -975,7 +977,7 @@ static void _handle_ack_timeout(at86rf215_t *dev)
at86rf215_rf_cmd(dev, CMD_RF_TXPREP); at86rf215_rf_cmd(dev, CMD_RF_TXPREP);
} else { } else {
/* no retransmissions left */ /* no retransmissions left */
_tx_end(dev, NETDEV_EVENT_TX_NOACK); __tx_end_timeout(dev);
} }
} }
@ -1234,7 +1236,7 @@ static void _isr(netdev_t *netdev)
dev->state = AT86RF215_STATE_TX_WAIT_ACK; dev->state = AT86RF215_STATE_TX_WAIT_ACK;
_start_ack_timer(dev); _start_ack_timer(dev);
} else { } else {
_tx_end(dev, NETDEV_EVENT_TX_COMPLETE); _tx_end(dev);
} }
break; break;
@ -1255,7 +1257,7 @@ static void _isr(netdev_t *netdev)
if (_ack_frame_received(dev)) { if (_ack_frame_received(dev)) {
timeout = 0; timeout = 0;
xtimer_remove(&dev->timer); xtimer_remove(&dev->timer);
_tx_end(dev, NETDEV_EVENT_TX_COMPLETE); _tx_end(dev);
at86rf215_rf_cmd(dev, CMD_RF_RX); at86rf215_rf_cmd(dev, CMD_RF_RX);
break; break;
} }

View File

@ -238,6 +238,7 @@ typedef enum {
NETDEV_EVENT_RX_COMPLETE, /**< finished receiving a frame */ NETDEV_EVENT_RX_COMPLETE, /**< finished receiving a frame */
NETDEV_EVENT_TX_STARTED, /**< started to transfer a frame */ NETDEV_EVENT_TX_STARTED, /**< started to transfer a frame */
NETDEV_EVENT_TX_COMPLETE, /**< transfer frame complete */ NETDEV_EVENT_TX_COMPLETE, /**< transfer frame complete */
#if IS_USED(MODULE_NETDEV_LEGACY_API) || DOXYGEN
/** /**
* @brief transfer frame complete and data pending flag * @brief transfer frame complete and data pending flag
* *
@ -261,6 +262,7 @@ typedef enum {
* `-EBUSY` in netdev_driver_t::confirm_send. * `-EBUSY` in netdev_driver_t::confirm_send.
*/ */
NETDEV_EVENT_TX_MEDIUM_BUSY, NETDEV_EVENT_TX_MEDIUM_BUSY,
#endif
NETDEV_EVENT_LINK_UP, /**< link established */ NETDEV_EVENT_LINK_UP, /**< link established */
NETDEV_EVENT_LINK_DOWN, /**< link gone */ NETDEV_EVENT_LINK_DOWN, /**< link gone */
NETDEV_EVENT_TX_TIMEOUT, /**< timeout when sending */ NETDEV_EVENT_TX_TIMEOUT, /**< timeout when sending */

View File

@ -51,7 +51,7 @@
#include "debug.h" #include "debug.h"
static void _update_l2addr_from_dev(gnrc_netif_t *netif); static void _update_l2addr_from_dev(gnrc_netif_t *netif);
static void _check_netdev_capabilities(netdev_t *dev); static void _check_netdev_capabilities(netdev_t *dev, bool legacy);
static void *_gnrc_netif_thread(void *args); static void *_gnrc_netif_thread(void *args);
static void _event_cb(netdev_t *dev, netdev_event_t event); static void _event_cb(netdev_t *dev, netdev_event_t event);
@ -1491,11 +1491,15 @@ static void _init_from_device(gnrc_netif_t *netif)
_update_l2addr_from_dev(netif); _update_l2addr_from_dev(netif);
} }
static void _check_netdev_capabilities(netdev_t *dev) static void _check_netdev_capabilities(netdev_t *dev, bool legacy)
{ {
/* Check whether RX- and TX-complete interrupts are supported by the driver */ /* Check whether RX- and TX-complete interrupts are supported by the driver */
if (IS_ACTIVE(DEVELHELP)) { if (IS_ACTIVE(DEVELHELP)) {
if (IS_USED(MODULE_NETSTATS_L2) || IS_USED(MODULE_GNRC_NETIF_PKTQ)) { if (IS_USED(MODULE_NETSTATS_L2) || IS_USED(MODULE_GNRC_NETIF_PKTQ)) {
if (!legacy) {
/* new API implies TX end event */
return;
}
netopt_enable_t enable = NETOPT_ENABLE; netopt_enable_t enable = NETOPT_ENABLE;
int res = dev->driver->get(dev, NETOPT_TX_END_IRQ, &enable, sizeof(enable)); int res = dev->driver->get(dev, NETOPT_TX_END_IRQ, &enable, sizeof(enable));
if ((res != sizeof(enable)) || (enable != NETOPT_ENABLE)) { if ((res != sizeof(enable)) || (enable != NETOPT_ENABLE)) {
@ -1640,7 +1644,7 @@ int gnrc_netif_default_init(gnrc_netif_t *netif)
return res; return res;
} }
netif_register(&netif->netif); netif_register(&netif->netif);
_check_netdev_capabilities(dev); _check_netdev_capabilities(dev, gnrc_netif_netdev_legacy_api(netif));
_init_from_device(netif); _init_from_device(netif);
#ifdef DEVELHELP #ifdef DEVELHELP
_test_options(netif); _test_options(netif);

View File

@ -177,6 +177,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
puts("Tx complete"); puts("Tx complete");
break; break;
#if IS_USED(MODULE_NETDEV_LEGACY_API)
case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING: case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING:
puts("Tx complete (with pending data)"); puts("Tx complete (with pending data)");
break; break;
@ -188,7 +189,7 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
case NETDEV_EVENT_TX_NOACK: case NETDEV_EVENT_TX_NOACK:
puts("No ACK"); puts("No ACK");
break; break;
#endif
default: default:
printf("Event: %d\n", event); printf("Event: %d\n", event);
break; break;