From 13010d76cae38f32d88e39bb7a2dbb88d8b2fb56 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Mon, 15 Sep 2025 10:44:06 +0200 Subject: [PATCH] drivers/ethos: implement netdev API async This changes the behavior of the netdev implementation to match what async drivers do. The current implementation is synchronous, but that can be fixed once an async UART API is available. In any case, we rather should not complicate testing of the network stack by having network devices come in different flavors. --- drivers/ethos/ethos.c | 23 ++++++++++++++--------- drivers/include/ethos.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index 2982bbbd87e0..2a60dbf40895 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -278,14 +278,14 @@ void ethos_send_frame(ethos_t *dev, const uint8_t *data, size_t len, unsigned fr static int _send(netdev_t *netdev, const iolist_t *iolist) { - ethos_t * dev = (ethos_t *) netdev; - (void)dev; + ethos_t * dev = container_of(netdev, ethos_t, netdev); /* count total packet length */ size_t pktlen = iolist_count_total(iolist); /* lock line in order to prevent multiple writes */ mutex_lock(&dev->out_mutex); + dev->tx_result = -EAGAIN; /* send start-frame-delimiter */ uint8_t frame_delim = ETHOS_FRAME_DELIMITER; @@ -302,9 +302,11 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) uart_write(dev->uart, &frame_delim, 1); + dev->tx_result = (int)pktlen; mutex_unlock(&dev->out_mutex); - return pktlen; + netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); + return 0; } static void _get_mac_addr(netdev_t *encdev, uint8_t* buf) @@ -356,8 +358,8 @@ unsigned ethos_unstuff_readbyte(uint8_t *buf, uint8_t byte, bool *escaped, uint8 static int _recv(netdev_t *netdev, void *buf, size_t len, void* info) { - (void) info; - ethos_t * dev = (ethos_t *) netdev; + (void)info; + ethos_t * dev = container_of(netdev, ethos_t, netdev); int res = 0; if (buf) { @@ -417,7 +419,10 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void* info) res = (int)tsrb_avail(&dev->inbuf); } } - return res; + + dev->tx_result = res; + netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); + return 0; } static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len) @@ -442,11 +447,11 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len) return res; } -static int _confirm_send(netdev_t *dev, void *info) +static int _confirm_send(netdev_t *netdev, void *info) { - (void)dev; (void)info; - return -EOPNOTSUPP; + ethos_t * dev = container_of(netdev, ethos_t, netdev); + return dev->tx_result; } /* netdev interface */ diff --git a/drivers/include/ethos.h b/drivers/include/ethos.h index 3e53a46a975a..4bba55bd2386 100644 --- a/drivers/include/ethos.h +++ b/drivers/include/ethos.h @@ -116,6 +116,7 @@ typedef struct { line_state_t state; /**< Line status variable */ unsigned frametype; /**< type of currently incoming frame */ mutex_t out_mutex; /**< mutex used for locking concurrent sends */ + int tx_result; /**< result to report in confirm_send() */ } ethos_t; /**