From 2467c84634925b712385365d667045fd9a40de97 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 11 Jun 2021 10:51:34 +0200 Subject: [PATCH 1/2] drivers/ethos: enable multiple instances --- drivers/ethos/Makefile.include | 2 + drivers/ethos/ethos.c | 8 +-- drivers/ethos/include/ethos_params.h | 49 +++++++++++++++++++ drivers/include/ethos.h | 9 ++-- .../gnrc/netif/init_devs/auto_init_ethos.c | 30 ++++++------ 5 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 drivers/ethos/Makefile.include create mode 100644 drivers/ethos/include/ethos_params.h diff --git a/drivers/ethos/Makefile.include b/drivers/ethos/Makefile.include new file mode 100644 index 0000000000..a078cd774b --- /dev/null +++ b/drivers/ethos/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE_INCLUDES_ethos := $(LAST_MAKEFILEDIR)/include +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_ethos) diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index 1230af2617..fa129ca401 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -53,9 +53,11 @@ static const netdev_driver_t netdev_driver_ethos; static const uint8_t _esc_esc[] = {ETHOS_ESC_CHAR, (ETHOS_ESC_CHAR ^ 0x20)}; static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x20)}; - -void ethos_setup(ethos_t *dev, const ethos_params_t *params) +void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx, + void *inbuf, size_t inbuf_size) { + (void)idx; + dev->netdev.driver = &netdev_driver_ethos; dev->uart = params->uart; dev->state = WAIT_FRAMESTART; @@ -64,7 +66,7 @@ void ethos_setup(ethos_t *dev, const ethos_params_t *params) dev->last_framesize = 0; dev->accept_new = true; - tsrb_init(&dev->inbuf, params->buf, params->bufsize); + tsrb_init(&dev->inbuf, inbuf, inbuf_size); mutex_init(&dev->out_mutex); luid_get_eui48((eui48_t *) &dev->mac_addr); diff --git a/drivers/ethos/include/ethos_params.h b/drivers/ethos/include/ethos_params.h new file mode 100644 index 0000000000..3474149817 --- /dev/null +++ b/drivers/ethos/include/ethos_params.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Kaspar Schleiser + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_ethos + * @{ + * + * @file + * @brief Default configuration for the ethos device driver + * + * @author Kaspar Schleiser + */ +#ifndef ETHOS_PARAMS_H +#define ETHOS_PARAMS_H + +#include "board.h" +#include "ethos.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef ETHOS_PARAMS +#define ETHOS_PARAMS { .uart = ETHOS_UART, \ + .baudrate = ETHOS_BAUDRATE } +#endif +/** @} */ + +/** + * @brief ethos configuration + * + * The first element in this array will be used to multiplex stdio if + * `stdio_ethos` is included. + */ +static const ethos_params_t ethos_params[] = { + ETHOS_PARAMS +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ETHOS_PARAMS_H */ +/** @} */ diff --git a/drivers/include/ethos.h b/drivers/include/ethos.h index 9b39b5b4ab..6a36f8e3e9 100644 --- a/drivers/include/ethos.h +++ b/drivers/include/ethos.h @@ -102,8 +102,6 @@ typedef struct { typedef struct { uart_t uart; /**< UART device to use */ uint32_t baudrate; /**< baudrate to UART device */ - uint8_t *buf; /**< buffer for incoming packets */ - size_t bufsize; /**< size of ethos_params_t::buf */ } ethos_params_t; /** @@ -117,8 +115,13 @@ typedef struct { * * @param[out] dev handle of the device to initialize * @param[in] params parameters for device initialization + * @param[in] index Index of @p params in a global parameter struct array. + * If initialized manually, pass a unique identifier instead. + * @param[in] inbuf buffer to store a received frame in + * @param[in] inbuf_size size of the receive buffer */ -void ethos_setup(ethos_t *dev, const ethos_params_t *params); +void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t index, + void *inbuf, size_t inbuf_size); /** * @brief Send frame over serial port using ethos' framing diff --git a/sys/net/gnrc/netif/init_devs/auto_init_ethos.c b/sys/net/gnrc/netif/init_devs/auto_init_ethos.c index adaf636b2f..79e4fe64ca 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_ethos.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_ethos.c @@ -20,15 +20,18 @@ #include "log.h" #include "debug.h" #include "ethos.h" +#include "ethos_params.h" #include "periph/uart.h" #include "net/gnrc/netif/ethernet.h" +#define ETHOS_NUM ARRAY_SIZE(ethos_params) + /** * @brief global ethos object, used by stdio_uart */ -ethos_t ethos; +ethos_t ethos[ETHOS_NUM]; -static gnrc_netif_t _netif; +static gnrc_netif_t _netif[ETHOS_NUM]; /** * @brief Define stack parameters for the MAC layer thread @@ -42,24 +45,21 @@ static gnrc_netif_t _netif; /** * @brief Stacks for the MAC layer threads */ -static char _netdev_eth_stack[ETHOS_MAC_STACKSIZE]; +static char _netdev_eth_stack[ETHOS_NUM][ETHOS_MAC_STACKSIZE]; -static uint8_t _inbuf[2048]; +static uint8_t _inbuf[ETHOS_NUM][2048]; void auto_init_ethos(void) { - LOG_DEBUG("[auto_init_netif] initializing ethos #0\n"); + for (unsigned i = 0; i < ETHOS_NUM; ++i) { + LOG_DEBUG("[auto_init_netif] initializing ethos #%u\n", i); - /* setup netdev device */ - ethos_params_t p; - p.uart = ETHOS_UART; - p.baudrate = ETHOS_BAUDRATE; - p.buf = _inbuf; - p.bufsize = sizeof(_inbuf); - ethos_setup(ðos, &p); + /* setup netdev device */ + ethos_setup(ðos[i], ðos_params[i], i, _inbuf[i], sizeof(_inbuf[i])); - /* initialize netdev<->gnrc adapter state */ - gnrc_netif_ethernet_create(&_netif, _netdev_eth_stack, ETHOS_MAC_STACKSIZE, - ETHOS_MAC_PRIO, "ethos", (netdev_t *)ðos); + /* initialize netdev<->gnrc adapter state */ + gnrc_netif_ethernet_create(&_netif[i], _netdev_eth_stack[i], ETHOS_MAC_STACKSIZE, + ETHOS_MAC_PRIO, "ethos", (netdev_t *)ðos[i]); + } } /** @} */ From 9a548b834f2a49ceca049d7a85bfeb747e86aef6 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 11 Jun 2021 10:56:03 +0200 Subject: [PATCH 2/2] drivers/ethos: register with nedev --- drivers/ethos/ethos.c | 7 +++---- drivers/include/net/netdev.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index fa129ca401..630ee54526 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -26,11 +26,11 @@ #include "periph/uart.h" #include "tsrb.h" #include "irq.h" -#include "luid.h" #include "net/netdev.h" #include "net/netdev/eth.h" #include "net/eui64.h" +#include "net/eui_provider.h" #include "net/ethernet.h" #ifdef USE_ETHOS_FOR_STDIO @@ -56,8 +56,6 @@ static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx, void *inbuf, size_t inbuf_size) { - (void)idx; - dev->netdev.driver = &netdev_driver_ethos; dev->uart = params->uart; dev->state = WAIT_FRAMESTART; @@ -69,7 +67,8 @@ void ethos_setup(ethos_t *dev, const ethos_params_t *params, uint8_t idx, tsrb_init(&dev->inbuf, inbuf, inbuf_size); mutex_init(&dev->out_mutex); - luid_get_eui48((eui48_t *) &dev->mac_addr); + netdev_register(&dev->netdev, NETDEV_ETHOS, idx); + netdev_eui48_get(&dev->netdev, (eui48_t *)&dev->mac_addr); uart_init(params->uart, params->baudrate, ethos_isr, (void*)dev); diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 0f0a7903ba..0ad72e32f4 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -320,6 +320,7 @@ typedef enum { NETDEV_SOCKET_ZEP, NETDEV_SX126X, NETDEV_CC2420, + NETDEV_ETHOS, /* add more if needed */ } netdev_type_t; /** @} */