From 5f7a906b957d60c59aecbd30fa88c3bba8932894 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 16 Mar 2022 16:53:37 +0100 Subject: [PATCH 01/13] drivers/w5100: introduce setup with index --- drivers/include/net/netdev.h | 1 + drivers/include/w5100.h | 7 ++++++- drivers/w5100/w5100.c | 7 ++++++- sys/net/gnrc/netif/init_devs/auto_init_w5100.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 2595082d03..302cece11c 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -324,6 +324,7 @@ typedef enum { NETDEV_ETHOS, NETDEV_SLIPDEV, NETDEV_TAP, + NETDEV_W5100, /* add more if needed */ } netdev_type_t; /** @} */ diff --git a/drivers/include/w5100.h b/drivers/include/w5100.h index ce2e07887b..b4f505fe79 100644 --- a/drivers/include/w5100.h +++ b/drivers/include/w5100.h @@ -74,8 +74,13 @@ typedef struct { * * This function pre-initializes the netdev structure, saves the configuration * parameters and finally initializes the SPI bus and the used GPIO pins. + * + * @param [out] dev the 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. */ -void w5100_setup(w5100_t *dev, const w5100_params_t *params); +void w5100_setup(w5100_t *dev, const w5100_params_t *params, uint8_t index); #ifdef __cplusplus } diff --git a/drivers/w5100/w5100.c b/drivers/w5100/w5100.c index 19c3180dd3..3b13d6d446 100644 --- a/drivers/w5100/w5100.c +++ b/drivers/w5100/w5100.c @@ -110,8 +110,11 @@ static void extint(void *arg) netdev_trigger_event_isr(&dev->nd); } -void w5100_setup(w5100_t *dev, const w5100_params_t *params) +void w5100_setup(w5100_t *dev, const w5100_params_t *params, uint8_t index) { + assert(dev); + assert(params); + /* initialize netdev structure */ dev->nd.driver = &netdev_driver_w5100; dev->nd.event_callback = NULL; @@ -123,6 +126,8 @@ void w5100_setup(w5100_t *dev, const w5100_params_t *params) /* initialize the chip select pin and the external interrupt pin */ spi_init_cs(dev->p.spi, dev->p.cs); gpio_init_int(dev->p.evt, GPIO_IN, GPIO_FALLING, extint, dev); + + netdev_register(&dev->nd, NETDEV_W5100, index); } static int init(netdev_t *netdev) diff --git a/sys/net/gnrc/netif/init_devs/auto_init_w5100.c b/sys/net/gnrc/netif/init_devs/auto_init_w5100.c index 805142ef6f..7ea674c200 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_w5100.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_w5100.c @@ -55,7 +55,7 @@ void auto_init_w5100(void) LOG_DEBUG("[auto_init_netif] initializing w5100 #%u\n", i); /* setup netdev device */ - w5100_setup(&dev[i], &w5100_params[i]); + w5100_setup(&dev[i], &w5100_params[i], i); /* initialize netdev <-> gnrc adapter state */ gnrc_netif_ethernet_create(&_netif[i], stack[i], MAC_STACKSIZE, MAC_PRIO, "w5100", &dev[i].nd); From a2e5934ec904545d9e5e6eec4de7ee869b0280c1 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 16 Mar 2022 15:02:25 +0100 Subject: [PATCH 02/13] drivers/encx24j600: introduce setup function with index --- drivers/encx24j600/encx24j600.c | 4 +++- drivers/include/encx24j600.h | 4 +++- drivers/include/net/netdev.h | 1 + sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index 9cc8c36763..aec64fb6c9 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -81,13 +81,15 @@ static inline void unlock(encx24j600_t *dev) { spi_release(dev->spi); } -void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params) +void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params, uint8_t index) { dev->netdev.driver = &netdev_driver_encx24j600; dev->spi = params->spi; dev->cs = params->cs_pin; dev->int_pin = params->int_pin; dev->rx_next_ptr = RX_BUFFER_START; + + netdev_register(&dev->netdev, NETDEV_ENCX24J600, index); } static void encx24j600_isr(void *arg) diff --git a/drivers/include/encx24j600.h b/drivers/include/encx24j600.h index 396c207eb2..c1ac8ad740 100644 --- a/drivers/include/encx24j600.h +++ b/drivers/include/encx24j600.h @@ -59,8 +59,10 @@ typedef struct { * * @param[out] dev the 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. */ -void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params); +void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params, uint8_t index); #ifdef __cplusplus } diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 302cece11c..871139c069 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -325,6 +325,7 @@ typedef enum { NETDEV_SLIPDEV, NETDEV_TAP, NETDEV_W5100, + NETDEV_ENCX24J600, /* add more if needed */ } netdev_type_t; /** @} */ diff --git a/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c b/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c index 46e96925f9..8d8075e08a 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c @@ -58,7 +58,7 @@ void auto_init_encx24j600(void) LOG_DEBUG("[auto_init_netif] initializing encx24j600 #%u\n", i); /* setup netdev device */ - encx24j600_setup(&encx24j600[i], &encx24j600_params[i]); + encx24j600_setup(&encx24j600[i], &encx24j600_params[i], i); /* initialize netdev<->gnrc adapter state */ gnrc_netif_ethernet_create(&_netif[i], _netdev_eth_stack[i], ENCX24J600_MAC_STACKSIZE, From 48ae24b5450a2944a5a8a937b9945d53eec82904 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 16 Mar 2022 14:38:46 +0100 Subject: [PATCH 03/13] sys/test_utils: add netdev Ethernet minimal processing --- sys/Makefile | 3 + sys/Makefile.include | 4 + sys/include/test_utils/netdev_eth_minimal.h | 67 ++++++++++ sys/test_utils/Makefile.dep | 3 + sys/test_utils/netdev_eth_minimal/Makefile | 3 + .../netdev_eth_minimal/Makefile.dep | 6 + .../netdev_eth_minimal/netdev_eth_minimal.c | 110 ++++++++++++++++ .../netdev_eth_minimal_internal.h | 50 ++++++++ .../netdev_eth_minimal/shell_commands.c | 120 ++++++++++++++++++ 9 files changed, 366 insertions(+) create mode 100644 sys/include/test_utils/netdev_eth_minimal.h create mode 100644 sys/test_utils/netdev_eth_minimal/Makefile create mode 100644 sys/test_utils/netdev_eth_minimal/Makefile.dep create mode 100644 sys/test_utils/netdev_eth_minimal/netdev_eth_minimal.c create mode 100644 sys/test_utils/netdev_eth_minimal/netdev_eth_minimal_internal.h create mode 100644 sys/test_utils/netdev_eth_minimal/shell_commands.c diff --git a/sys/Makefile b/sys/Makefile index 2a008ed975..da2def6e24 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -188,6 +188,9 @@ endif ifneq (,$(filter test_utils_interactive_sync,$(USEMODULE))) DIRS += test_utils/interactive_sync endif +ifneq (,$(filter test_utils_netdev_eth_minimal,$(USEMODULE))) + DIRS += test_utils/netdev_eth_minimal +endif ifneq (,$(filter test_utils_result_output,$(USEMODULE))) DIRS += test_utils/result_output endif diff --git a/sys/Makefile.include b/sys/Makefile.include index 31e8c274e8..a2f6112d0d 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -151,3 +151,7 @@ ifneq (,$(filter usbus_dfu riotboot_reset,$(USEMODULE))) CFLAGS += -DCPU_RAM_BASE=$(RAM_START_ADDR) CFLAGS += -DCPU_RAM_SIZE=$(RAM_LEN) endif + +ifneq (,$(filter test_utils_netdev_eth_minimal,$(USEMODULE))) + CFLAGS += -DCONFIG_NETDEV_REGISTER_SIGNAL +endif diff --git a/sys/include/test_utils/netdev_eth_minimal.h b/sys/include/test_utils/netdev_eth_minimal.h new file mode 100644 index 0000000000..8f3df2e769 --- /dev/null +++ b/sys/include/test_utils/netdev_eth_minimal.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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. + */ + +/** + * @defgroup test_utils_netdev_eth_minimal Minimal netdev Ethernet device processing + * @ingroup sys + * + * @{ + * @file + * @brief Provides basic functionalities to interact with an Ethernet networking + * device which implements the @ref drivers_netdev_api. + * + * To use the functionalities, include the module `USEMODULE += test_utils_netdev_eth_minimal`. + * The test application should provide: + * - device initialization, via the implementation of @ref netdev_eth_minimal_init_devs + * - number of devices to test, via the definition of @ref NETDEV_ETH_MINIMAL_NUMOF in `init_dev.h` + * + * @author Leandro Lanzieri + */ + +#ifndef TEST_UTILS_NETDEV_ETH_MINIMAL_H +#define TEST_UTILS_NETDEV_ETH_MINIMAL_H + +#include "net/netdev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef DOXYGEN +/** + * @brief Maximum number of devices to handle. + * @note Should be provided by the application via `init_dev.h`. + */ +#define NETDEV_ETH_MINIMAL_NUMOF +#endif + +/** + * @brief Device-under-test initialization function. + * @note Should be implemented by the test application + * + * @param[in] cb Callback to be set to @ref netdev::event_callback + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb); + +/** + * @brief Initialize the module. + * + * @retval 0 on success + * @retval != 0 on error + */ +int netdev_eth_minimal_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_UTILS_NETDEV_ETH_MINIMAL_H */ +/** @} */ diff --git a/sys/test_utils/Makefile.dep b/sys/test_utils/Makefile.dep index bdf6400802..ad9c48b3c9 100644 --- a/sys/test_utils/Makefile.dep +++ b/sys/test_utils/Makefile.dep @@ -10,3 +10,6 @@ ifneq (,$(filter benchmark_udp,$(USEMODULE))) USEMODULE += sock_udp USEMODULE += xtimer endif +ifneq (,$(filter test_utils_netdev_eth_minimal,$(USEMODULE))) + include $(RIOTBASE)/sys/test_utils/netdev_eth_minimal/Makefile.dep +endif diff --git a/sys/test_utils/netdev_eth_minimal/Makefile b/sys/test_utils/netdev_eth_minimal/Makefile new file mode 100644 index 0000000000..4bf21b501c --- /dev/null +++ b/sys/test_utils/netdev_eth_minimal/Makefile @@ -0,0 +1,3 @@ +MODULE = test_utils_netdev_eth_minimal + +include $(RIOTBASE)/Makefile.base diff --git a/sys/test_utils/netdev_eth_minimal/Makefile.dep b/sys/test_utils/netdev_eth_minimal/Makefile.dep new file mode 100644 index 0000000000..15d82d0503 --- /dev/null +++ b/sys/test_utils/netdev_eth_minimal/Makefile.dep @@ -0,0 +1,6 @@ +USEMODULE += event +USEMODULE += event_thread +USEMODULE += l2util +USEMODULE += od +USEMODULE += od_string +USEMODULE += shell diff --git a/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal.c b/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal.c new file mode 100644 index 0000000000..60b3cd332a --- /dev/null +++ b/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal.c @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_eth_minimal + * @{ + * + * @file + * @brief Implementation of netdev Eth minimal test utility module + * + * @author Leandro Lanzieri + */ + +#include + +#include "event.h" +#include "event/thread.h" +#include "od.h" +#include "net/ethernet.h" +#include "net/ethernet/hdr.h" +#include "net/l2util.h" +#include "net/netdev.h" +#include "net/netdev/eth.h" +#include "test_utils/netdev_eth_minimal.h" +#include "netdev_eth_minimal_internal.h" + +/* provided by the test application */ +#include "init_dev.h" + +device_reg_entry_t _devices[NETDEV_ETH_MINIMAL_NUMOF]; +static uint8_t _buffer[ETHERNET_MAX_LEN]; +static char _addr_str[ETHERNET_ADDR_LEN * 3]; + +void _recv(netdev_t *dev) +{ + ssize_t data_len; + netdev_eth_rx_info_t rx_info = { 0 }; + ethernet_hdr_t *header = (ethernet_hdr_t *)_buffer; + uint8_t *payload = _buffer + sizeof(ethernet_hdr_t); + + putchar('\n'); + data_len = dev->driver->recv(dev, _buffer, sizeof(_buffer), &rx_info); + if (data_len < 0) { + return; + } + + l2util_addr_to_str(header->dst, ETHERNET_ADDR_LEN, _addr_str); + printf("Dest. addr.: %s\n", _addr_str); + + l2util_addr_to_str(header->src, ETHERNET_ADDR_LEN, _addr_str); + printf("Src. addr.: %s\n", _addr_str); + + data_len -= sizeof(ethernet_hdr_t); + printf("Payload (%u bytes): \n", (unsigned)data_len); + od_hex_dump(payload, data_len, 0); +} + +static void _isr_event_handler(event_t *event) +{ + /* recover the netdev from the event */ + device_reg_entry_t *netdev_event = container_of(event, device_reg_entry_t, event); + netdev_t *netdev = netdev_event->dev; + netdev->driver->isr(netdev); +} + +static void _event_cb(netdev_t *dev, netdev_event_t event) +{ + device_reg_entry_t *device = dev->context; + + switch (event) { + case NETDEV_EVENT_ISR: + event_post(EVENT_PRIO_HIGHEST, &device->event); + break; + + case NETDEV_EVENT_RX_COMPLETE: + _recv(dev); + break; + + default: + break; + } +} + +/* Implement netdev_register_signal hook to associate registered devices to specific event + * structures. + */ +void netdev_register_signal(struct netdev *dev, netdev_type_t type, uint8_t index) +{ + (void) type; + + if (index > NETDEV_ETH_MINIMAL_NUMOF) { + return; + } + printf("Device %d registered (type: %d)\n", index, type); + dev->context = &_devices[index]; + _devices[index].dev = dev; + _devices[index].event.handler = _isr_event_handler; +} + +int netdev_eth_minimal_init(void) +{ + return netdev_eth_minimal_init_devs(_event_cb); +} + +/** @} */ diff --git a/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal_internal.h b/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal_internal.h new file mode 100644 index 0000000000..22058a9211 --- /dev/null +++ b/sys/test_utils/netdev_eth_minimal/netdev_eth_minimal_internal.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_eth_minimal + * + * @{ + * @file + * @brief Internal definitions for the netdev_eth_minimal module + * + * @author Leandro Lanzieri + */ + +#ifndef NETDEV_ETH_MINIMAL_INTERNAL_H +#define NETDEV_ETH_MINIMAL_INTERNAL_H + +#include "net/netdev.h" +#include "event.h" +#include "init_dev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Registry entry to keep track of registered Ethernet network devices + * + * Each registered device has an associated event to serve its ISRs. + */ +typedef struct { + event_t event; /**< event to serve ISR */ + netdev_t *dev; /**< pointer to the device */ +} device_reg_entry_t; + +/** + * @brief Registry of Ethernet devices to serve ISRs. + */ +extern device_reg_entry_t _devices[NETDEV_ETH_MINIMAL_NUMOF]; + +#ifdef __cplusplus +} +#endif + +#endif /* NETDEV_ETH_MINIMAL_INTERNAL_H */ +/** @} */ diff --git a/sys/test_utils/netdev_eth_minimal/shell_commands.c b/sys/test_utils/netdev_eth_minimal/shell_commands.c new file mode 100644 index 0000000000..7e0cd5b590 --- /dev/null +++ b/sys/test_utils/netdev_eth_minimal/shell_commands.c @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 test_utils_netdev_eth_minimal + * @{ + * + * @file + * @brief Shell commands for netdev Eth minimal test utility module + * + * @author Leandro Lanzieri + */ + +#include +#include +#include + +#include "net/ethernet/hdr.h" +#include "net/ethertype.h" +#include "net/l2util.h" +#include "byteorder.h" +#include "shell.h" +#include "iolist.h" +#include "assert.h" +#include "netdev_eth_minimal_internal.h" +#include "init_dev.h" + +#define ENABLE_DEBUG 0 +#include "debug.h" + +int ifconfig_list(int idx) +{ + int res; + netdev_t *dev = _devices[idx].dev; + uint8_t addr[ETHERNET_ADDR_LEN]; + char addr_str[ETHERNET_ADDR_LEN * 3]; + + printf("Iface %3d HWaddr: ", idx); + res = dev->driver->get(dev, NETOPT_ADDRESS, addr, sizeof(addr)); + assert(res > 0); + l2util_addr_to_str(addr, ETHERNET_ADDR_LEN, addr_str); + printf("%s\n", addr_str); + + return 0; +} + +int cmd_ifconfig(int argc, char **argv) +{ + (void)argc; + (void)argv; + + for (unsigned int i = 0; i < NETDEV_ETH_MINIMAL_NUMOF; i++) { + ifconfig_list(i); + } + return 0; +} + +static int _print_txtsnd_usage(char *cmd) { + printf("usage: %s \n", cmd); + return 1; +} + +static int cmd_txtsnd(int argc, char **argv) +{ + ethernet_hdr_t header; + int res; + + if (4 != argc) { + return _print_txtsnd_usage(argv[0]); + } + + int iface = atoi(argv[1]); + if (iface < 0 || (unsigned)iface >= NETDEV_ETH_MINIMAL_NUMOF) { + printf("unknown interface %d\n", iface); + return _print_txtsnd_usage(argv[0]); + } + + /* build Ethernet header */ + res = l2util_addr_from_str(argv[2], header.dst); + if (!res) { + puts("Could not parse address"); + return _print_txtsnd_usage(argv[0]); + } + + netdev_t *dev = _devices[iface].dev; + if (!dev) { + return _print_txtsnd_usage(argv[0]); + } + + dev->driver->get(dev, NETOPT_ADDRESS, header.src, ETHERNET_ADDR_LEN); + header.type = byteorder_htons(ETHERTYPE_UNKNOWN); + + /* prepare iolists to send */ + iolist_t io_data = { 0 }; + io_data.iol_base = argv[3]; + io_data.iol_len = strlen(argv[3]); + + iolist_t io_header = { 0 }; + io_header.iol_base = &header; + io_header.iol_len = sizeof(ethernet_hdr_t); + io_header.iol_next = &io_data; + + /* send */ + res = dev->driver->send(dev, &io_header); + if (res < 0) { + puts("txtsnd: Could not send"); + return 1; + } + + puts("Successfully sent"); + return 0; +} + +SHELL_COMMAND(txtsnd, "Send an Ethernet frame", cmd_txtsnd); +SHELL_COMMAND(ifconfig, "List interfaces", cmd_ifconfig); From c6a48e77fb4f7628ef60c5950d212267826d68df Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:21:35 +0100 Subject: [PATCH 04/13] tests/driver_enc28j60: rewrite without GNRC --- tests/driver_enc28j60/Makefile | 28 +++++----------- tests/driver_enc28j60/Makefile.ci | 25 ++------------- tests/driver_enc28j60/init_dev.h | 45 ++++++++++++++++++++++++++ tests/driver_enc28j60/main.c | 53 +++++++++++++++++++++---------- 4 files changed, 93 insertions(+), 58 deletions(-) create mode 100644 tests/driver_enc28j60/init_dev.h diff --git a/tests/driver_enc28j60/Makefile b/tests/driver_enc28j60/Makefile index 0327bdd651..e74e0a313c 100644 --- a/tests/driver_enc28j60/Makefile +++ b/tests/driver_enc28j60/Makefile @@ -1,12 +1,9 @@ +INCLUDES += -I$(APPDIR) + include ../Makefile.tests_common -USEMODULE += auto_init_gnrc_netif +USEMODULE += test_utils_netdev_eth_minimal USEMODULE += enc28j60 -USEMODULE += gnrc_ipv6_router_default -USEMODULE += gnrc_icmpv6_echo -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps # set board specific peripheral configurations ifneq (,$(filter stm32f4discovery,$(BOARD))) @@ -14,20 +11,11 @@ ifneq (,$(filter stm32f4discovery,$(BOARD))) ENC_CS ?= GPIO_PIN\(PORT_B,12\) ENC_INT ?= GPIO_PIN\(PORT_B,11\) ENC_RST ?= GPIO_PIN\(PORT_B,10\) + # export SPI and pins + CFLAGS += -DENC28J60_PARAM_SPI=$(ENC_SPI) + CFLAGS += -DENC28J60_PARAM_CS=$(ENC_CS) + CFLAGS += -DENC28J60_PARAM_INT=$(ENC_INT) + CFLAGS += -DENC28J60_PARAM_RESET=$(ENC_RST) endif -# fallback: set SPI bus and pins to default values -ENC_SPI ?= SPI_DEV\(0\) -ENC_CS ?= GPIO_PIN\(0,0\) -ENC_INT ?= GPIO_PIN\(0,1\) -ENC_RST ?= GPIO_PIN\(0,2\) -# export SPI and pins -CFLAGS += -DENC28J60_PARAM_SPI=$(ENC_SPI) -CFLAGS += -DENC28J60_PARAM_CS=$(ENC_CS) -CFLAGS += -DENC28J60_PARAM_INT=$(ENC_INT) -CFLAGS += -DENC28J60_PARAM_RESET=$(ENC_RST) - -# make sure we read the local enc28j60 params file -CFLAGS += -I$(CURDIR) - include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_enc28j60/Makefile.ci b/tests/driver_enc28j60/Makefile.ci index f04a057ab7..19b770a624 100644 --- a/tests/driver_enc28j60/Makefile.ci +++ b/tests/driver_enc28j60/Makefile.ci @@ -1,35 +1,16 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ - atmega1284p \ atmega328p \ atmega328p-xplained-mini \ - atxmega-a3bu-xplained \ - bluepill-stm32f030c8 \ - derfmega128 \ - i-nucleo-lrwan1 \ - mega-xplained \ - microduino-corerf \ - msb-430 \ - msb-430h \ + esp8266-esp-12x \ + esp8266-olimex-mod \ + esp8266-sparkfun-thing \ nucleo-f031k6 \ - nucleo-f042k6 \ - nucleo-f303k8 \ - nucleo-f334r8 \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32l0538-disco \ - telosb \ - waspmote-pro \ - z1 \ - zigduino \ # diff --git a/tests/driver_enc28j60/init_dev.h b/tests/driver_enc28j60/init_dev.h new file mode 100644 index 0000000000..bff7138aab --- /dev/null +++ b/tests/driver_enc28j60/init_dev.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file ENC28J60 ethernet device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include + +#include "kernel_defines.h" +#include "net/netdev.h" + +#include "enc28j60.h" +#include "enc28j60_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ENC28J60_NUM ARRAY_SIZE(enc28j60_params) +#define NETDEV_ETH_MINIMAL_NUMOF ENC28J60_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_enc28j60/main.c b/tests/driver_enc28j60/main.c index e434dd75dc..23a04b2718 100644 --- a/tests/driver_enc28j60/main.c +++ b/tests/driver_enc28j60/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2022 HAW Hamburg * * 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 @@ -11,9 +11,9 @@ * @{ * * @file - * @brief Test application for the ENC28J60 Ethernet device driver + * @brief Test application for ENC28J60 ethernet device driver * - * @author Hauke Petersen + * @author Leandro Lanzieri * * @} */ @@ -21,26 +21,47 @@ #include #include "shell.h" -#include "msg.h" +#include "assert.h" +#include "enc28j60.h" +#include "enc28j60_params.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" -#define MAIN_QUEUE_SIZE (8U) -static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; +static enc28j60_t enc28j60[ENC28J60_NUM]; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + for (unsigned i = 0; i < ENC28J60_NUM; i++) { + netdev_t *device = &enc28j60[i].netdev; + + /* setup the specific driver */ + enc28j60_setup(&enc28j60[i], &enc28j60_params[i], i); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + } + + return 0; +} int main(void) { - /* we need a message queue for the thread running the shell in order to - * receive potentially fast incoming networking packets */ - msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); - puts("Test application for the enc28j60 driver\n"); - puts("This test just pulls in parts of the GNRC network stack, use the\n" - "provided shell commands (i.e. ifconfig, ping) to interact with\n" - "your enc28j60 device.\n"); + puts("Test application for ENC28J60 ethernet device driver"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); - /* start shell */ - puts("Starting the shell now..."); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); - /* should be never reached */ return 0; } From 99a974914ab4ff689a7c195bfae9c385bd78a64e Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:22:30 +0100 Subject: [PATCH 05/13] tests/driver_encx24j600: rewrite without GNRC --- tests/driver_encx24j600/Makefile | 15 ++------ tests/driver_encx24j600/Makefile.ci | 14 -------- tests/driver_encx24j600/init_dev.h | 45 ++++++++++++++++++++++++ tests/driver_encx24j600/main.c | 54 +++++++++++++++++++---------- 4 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 tests/driver_encx24j600/init_dev.h diff --git a/tests/driver_encx24j600/Makefile b/tests/driver_encx24j600/Makefile index 7b1feb5f01..78f10a0ec6 100644 --- a/tests/driver_encx24j600/Makefile +++ b/tests/driver_encx24j600/Makefile @@ -1,12 +1,9 @@ +INCLUDES += -I$(APPDIR) + include ../Makefile.tests_common -USEMODULE += auto_init_gnrc_netif +USEMODULE += test_utils_netdev_eth_minimal USEMODULE += encx24j600 -USEMODULE += gnrc_ipv6_router_default -USEMODULE += gnrc_icmpv6_echo -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps # set board specific peripheral configurations ifneq (,$(filter nucleo-f334r8,$(BOARD))) @@ -23,9 +20,3 @@ ifneq (,$(filter nucleo-f334r8,$(BOARD))) endif include $(RIOTBASE)/Makefile.include - -# lower pktbuf size -# Set GNRC_PKTBUF_SIZE via CFLAGS if not being set via Kconfig. -ifndef CONFIG_GNRC_PKTBUF_SIZE - CFLAGS += -DCONFIG_GNRC_PKTBUF_SIZE=2048 -endif diff --git a/tests/driver_encx24j600/Makefile.ci b/tests/driver_encx24j600/Makefile.ci index a7af604521..5afc390e20 100644 --- a/tests/driver_encx24j600/Makefile.ci +++ b/tests/driver_encx24j600/Makefile.ci @@ -1,27 +1,13 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ atmega328p \ atmega328p-xplained-mini \ - bluepill-stm32f030c8 \ - i-nucleo-lrwan1 \ - msb-430 \ - msb-430h \ nucleo-f031k6 \ - nucleo-f042k6 \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32l0538-disco \ - telosb \ - waspmote-pro \ - z1 \ # diff --git a/tests/driver_encx24j600/init_dev.h b/tests/driver_encx24j600/init_dev.h new file mode 100644 index 0000000000..cf1288efbc --- /dev/null +++ b/tests/driver_encx24j600/init_dev.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file ENCX24J600 ethernet device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include + +#include "kernel_defines.h" +#include "net/netdev.h" + +#include "encx24j600.h" +#include "encx24j600_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ENCX24J600_NUM ARRAY_SIZE(encx24j600_params) +#define NETDEV_ETH_MINIMAL_NUMOF ENCX24J600_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_encx24j600/main.c b/tests/driver_encx24j600/main.c index e880e3566c..6bb8005732 100644 --- a/tests/driver_encx24j600/main.c +++ b/tests/driver_encx24j600/main.c @@ -1,6 +1,5 @@ /* - * Copyright (C) 2015 Freie Universität Berlin - * 2016 Kaspar Schleiser + * Copyright (C) 2022 HAW Hamburg * * 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 @@ -12,10 +11,9 @@ * @{ * * @file - * @brief Test application for the ENCx26J600 Ethernet device driver + * @brief Test application for ENCX24J600 ethernet device driver * - * @author Hauke Petersen - * @author Kaspar Schleiser + * @author Leandro Lanzieri * * @} */ @@ -23,27 +21,47 @@ #include #include "shell.h" -#include "msg.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "encx24j600.h" +#include "encx24j600_params.h" -#define MAIN_QUEUE_SIZE (8U) -static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; +static encx24j600_t encx24j600[ENCX24J600_NUM]; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + for (unsigned i = 0; i < ENCX24J600_NUM; i++) { + netdev_t *device = &encx24j600[i].netdev; + + /* setup the specific driver */ + encx24j600_setup(&encx24j600[i], &encx24j600_params[i], i); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + } + + return 0; +} int main(void) { - /* we need a message queue for the thread running the shell in order to - * receive potentially fast incoming networking packets */ - msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("Test application for ENCX24J600 ethernet device driver"); - puts("Test application for the encx24j600 driver\n"); - puts("This test just pulls in parts of the GNRC network stack, use the\n" - "provided shell commands (i.e. ifconfig, ping) to interact with\n" - "your encx24j600 device.\n"); + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); - /* start shell */ - puts("Starting the shell now..."); char line_buf[SHELL_DEFAULT_BUFSIZE]; shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); - /* should be never reached */ return 0; } From b3c202cc8448cb5d7b6c3e6e3bf781b57615fada Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:28:49 +0100 Subject: [PATCH 06/13] tests/driver_dose: rewrite without GNRC --- tests/driver_dose/Makefile | 8 +++- tests/driver_dose/Makefile.ci | 17 --------- tests/driver_dose/init_dev.h | 45 +++++++++++++++++++++++ tests/driver_dose/main.c | 69 ++++++++++++++++++++++++++++++++++- 4 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 tests/driver_dose/init_dev.h mode change 120000 => 100644 tests/driver_dose/main.c diff --git a/tests/driver_dose/Makefile b/tests/driver_dose/Makefile index be934a0cab..c7d85636a1 100644 --- a/tests/driver_dose/Makefile +++ b/tests/driver_dose/Makefile @@ -1,3 +1,7 @@ +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_eth_minimal + # the driver to test USEMODULE += dose @@ -13,4 +17,6 @@ ifneq (,$(filter same54-xpro, $(BOARD))) USEMODULE += dose_watchdog endif -include ../driver_netdev_common/Makefile.netdev.mk +INCLUDES += -I$(APPDIR) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_dose/Makefile.ci b/tests/driver_dose/Makefile.ci index a98193f422..552883c80f 100644 --- a/tests/driver_dose/Makefile.ci +++ b/tests/driver_dose/Makefile.ci @@ -1,30 +1,13 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ - atxmega-a3bu-xplained \ atmega328p \ atmega328p-xplained-mini \ - bluepill-stm32f030c8 \ - i-nucleo-lrwan1 \ - msb-430 \ - msb-430h \ - nucleo-f030r8 \ nucleo-f031k6 \ nucleo-f042k6 \ - nucleo-f303k8 \ - nucleo-f334r8 \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ - stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32g0316-disco \ - stm32l0538-disco \ - waspmote-pro \ # diff --git a/tests/driver_dose/init_dev.h b/tests/driver_dose/init_dev.h new file mode 100644 index 0000000000..1aca9310b0 --- /dev/null +++ b/tests/driver_dose/init_dev.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file DOSE driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include + +#include "kernel_defines.h" +#include "net/netdev.h" + +#include "dose.h" +#include "dose_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define DOSE_NUM ARRAY_SIZE(dose_params) +#define NETDEV_ETH_MINIMAL_NUMOF DOSE_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_dose/main.c b/tests/driver_dose/main.c deleted file mode 120000 index a3f88db08e..0000000000 --- a/tests/driver_dose/main.c +++ /dev/null @@ -1 +0,0 @@ -../driver_netdev_common/main.c \ No newline at end of file diff --git a/tests/driver_dose/main.c b/tests/driver_dose/main.c new file mode 100644 index 0000000000..009f1882c5 --- /dev/null +++ b/tests/driver_dose/main.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for DOSE driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "dose.h" +#include "dose_params.h" + +static dose_t dose[DOSE_NUM]; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + for (unsigned i = 0; i < DOSE_NUM; i ++) { + netdev_t *device = &dose[i].netdev; + + /* setup the specific driver */ + dose_setup(&dose[i], &dose_params[i], i); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + } + + return 0; +} + + +int main(void) +{ + puts("Test application for DOSE driver"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 8ec32d5859dda29d04ee6648add97392738e0748 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:34:20 +0100 Subject: [PATCH 07/13] tests/driver_ethos: rewrite without GNRC --- tests/driver_ethos/Makefile | 12 ++++-- tests/driver_ethos/Makefile.ci | 16 -------- tests/driver_ethos/init_dev.h | 45 ++++++++++++++++++++++ tests/driver_ethos/main.c | 69 +++++++++++++++++++++++++++++++++- 4 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 tests/driver_ethos/init_dev.h mode change 120000 => 100644 tests/driver_ethos/main.c diff --git a/tests/driver_ethos/Makefile b/tests/driver_ethos/Makefile index 6317104acd..9c8446c567 100644 --- a/tests/driver_ethos/Makefile +++ b/tests/driver_ethos/Makefile @@ -1,4 +1,10 @@ -# the network driver to test -USEMODULE = ethos +include ../Makefile.tests_common -include ../driver_netdev_common/Makefile.netdev.mk +USEMODULE += test_utils_netdev_eth_minimal + +# the driver to test +USEMODULE += ethos + +INCLUDES += -I$(APPDIR) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_ethos/Makefile.ci b/tests/driver_ethos/Makefile.ci index 6d65e280ff..1d21bb5900 100644 --- a/tests/driver_ethos/Makefile.ci +++ b/tests/driver_ethos/Makefile.ci @@ -1,30 +1,14 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-duemilanove \ arduino-leonardo \ - arduino-mega2560 \ arduino-nano \ arduino-uno \ atmega328p \ atmega328p-xplained-mini \ - atxmega-a3bu-xplained \ - bluepill-stm32f030c8 \ - i-nucleo-lrwan1 \ - msb-430 \ - msb-430h \ - nucleo-f030r8 \ nucleo-f031k6 \ nucleo-f042k6 \ - nucleo-f303k8 \ - nucleo-f334r8 \ nucleo-l011k4 \ - nucleo-l031k6 \ - nucleo-l053r8 \ samd10-xmini \ - slstk3400a \ stk3200 \ stm32f030f4-demo \ - stm32f0discovery \ - stm32g0316-disco \ - stm32l0538-disco \ - waspmote-pro \ # diff --git a/tests/driver_ethos/init_dev.h b/tests/driver_ethos/init_dev.h new file mode 100644 index 0000000000..4f6f2a8e60 --- /dev/null +++ b/tests/driver_ethos/init_dev.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file ETHOS driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include + +#include "kernel_defines.h" +#include "net/netdev.h" + +#include "ethos.h" +#include "ethos_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ETHOS_NUM ARRAY_SIZE(ethos_params) +#define NETDEV_ETH_MINIMAL_NUMOF ETHOS_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_ethos/main.c b/tests/driver_ethos/main.c deleted file mode 120000 index a3f88db08e..0000000000 --- a/tests/driver_ethos/main.c +++ /dev/null @@ -1 +0,0 @@ -../driver_netdev_common/main.c \ No newline at end of file diff --git a/tests/driver_ethos/main.c b/tests/driver_ethos/main.c new file mode 100644 index 0000000000..a9658beccb --- /dev/null +++ b/tests/driver_ethos/main.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for ethernet-over-serial driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "ethos.h" +#include "ethos_params.h" + +static ethos_t ethos[ETHOS_NUM]; +static uint8_t inbuf[ETHOS_NUM][2048]; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + for (unsigned i = 0; i < ETHOS_NUM; i++) { + netdev_t *device = ðos[i].netdev; + + /* setup the specific driver */ + ethos_setup(ðos[i], ðos_params[i], i, inbuf[i], sizeof(inbuf[i])); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + } + + return 0; +} + +int main(void) +{ + puts("Test application for ETHOS driver"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 348bc9af82f8f420eb3e87790a21dac2c5bd54ad Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:37:46 +0100 Subject: [PATCH 08/13] tests/driver_w5100: rewrite without GNRC --- tests/driver_w5100/Makefile | 12 +++++-- tests/driver_w5100/init_dev.h | 45 +++++++++++++++++++++++ tests/driver_w5100/main.c | 68 ++++++++++++++++++++++++++++++++++- 3 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 tests/driver_w5100/init_dev.h mode change 120000 => 100644 tests/driver_w5100/main.c diff --git a/tests/driver_w5100/Makefile b/tests/driver_w5100/Makefile index 8f461962ae..9d8a2955d3 100644 --- a/tests/driver_w5100/Makefile +++ b/tests/driver_w5100/Makefile @@ -1,4 +1,10 @@ -# the driver to test -USEMODULE = w5100 +include ../Makefile.tests_common -include ../driver_netdev_common/Makefile.netdev.mk +USEMODULE += test_utils_netdev_eth_minimal + +# the driver to test +USEMODULE += w5100 + +INCLUDES += -I$(APPDIR) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_w5100/init_dev.h b/tests/driver_w5100/init_dev.h new file mode 100644 index 0000000000..f09e586c76 --- /dev/null +++ b/tests/driver_w5100/init_dev.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file W5100 ethernet device driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#include + +#include "kernel_defines.h" +#include "net/netdev.h" + +#include "w5100.h" +#include "w5100_params.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define W5100_NUM ARRAY_SIZE(w5100_params) +#define NETDEV_ETH_MINIMAL_NUMOF W5100_NUM + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_w5100/main.c b/tests/driver_w5100/main.c deleted file mode 120000 index a3f88db08e..0000000000 --- a/tests/driver_w5100/main.c +++ /dev/null @@ -1 +0,0 @@ -../driver_netdev_common/main.c \ No newline at end of file diff --git a/tests/driver_w5100/main.c b/tests/driver_w5100/main.c new file mode 100644 index 0000000000..b4665da2ed --- /dev/null +++ b/tests/driver_w5100/main.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for W5100 ethernet device driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "w5100.h" +#include "w5100_params.h" + +static w5100_t w5100[W5100_NUM]; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + for (unsigned i = 0; i < W5100_NUM; i++) { + netdev_t *device = &w5100[i].nd; + + /* setup the specific driver */ + w5100_setup(&w5100[i], &w5100_params[i], i); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + } + + return 0; +} + +int main(void) +{ + puts("Test application for W5100 ethernet device driver"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 5e41b5147089803f049d567fdfa677cf86025dce Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:50:21 +0100 Subject: [PATCH 09/13] tests: add ESP ethernet test --- tests/driver_esp_eth/Makefile | 14 +++++++ tests/driver_esp_eth/init_dev.h | 36 ++++++++++++++++++ tests/driver_esp_eth/main.c | 67 +++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/driver_esp_eth/Makefile create mode 100644 tests/driver_esp_eth/init_dev.h create mode 100644 tests/driver_esp_eth/main.c diff --git a/tests/driver_esp_eth/Makefile b/tests/driver_esp_eth/Makefile new file mode 100644 index 0000000000..3ccbdd287b --- /dev/null +++ b/tests/driver_esp_eth/Makefile @@ -0,0 +1,14 @@ +BOARD ?= esp32-ethernet-kit-v1_0 + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_eth_minimal + +# the driver to test +USEMODULE += esp_eth +FEATURES_REQUIRED += arch_esp32 +FEATURES_REQUIRED += periph_eth + +INCLUDES += -I$(APPDIR) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_esp_eth/init_dev.h b/tests/driver_esp_eth/init_dev.h new file mode 100644 index 0000000000..d7ef56a336 --- /dev/null +++ b/tests/driver_esp_eth/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file ESP ethernet peripheral + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define NETDEV_ETH_MINIMAL_NUMOF 1 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_esp_eth/main.c b/tests/driver_esp_eth/main.c new file mode 100644 index 0000000000..2545759162 --- /dev/null +++ b/tests/driver_esp_eth/main.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for ESP ethernet peripheral + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "net/netdev.h" +#include "esp_eth_netdev.h" +#include "esp_eth_params.h" + +extern void esp_eth_setup(esp_eth_netdev_t* dev); +extern esp_eth_netdev_t _esp_eth_dev; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + netdev_t *device = &_esp_eth_dev.netdev; + + /* setup the specific driver */ + esp_eth_setup(&_esp_eth_dev); + + /* set the application-provided callback */ + device->event_callback = cb; + + /* initialize the device driver */ + int res = device->driver->init(device); + assert(!res); + + return 0; +} + +int main(void) +{ + puts("Test application for ESP ethernet peripheral"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 4593746b70790727d81be9fd4470ea35087d87f8 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 15:36:44 +0100 Subject: [PATCH 10/13] tests: add SAM0 ethernet test --- tests/driver_sam0_eth/Makefile | 14 +++++++ tests/driver_sam0_eth/init_dev.h | 36 ++++++++++++++++++ tests/driver_sam0_eth/main.c | 64 ++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 tests/driver_sam0_eth/Makefile create mode 100644 tests/driver_sam0_eth/init_dev.h create mode 100644 tests/driver_sam0_eth/main.c diff --git a/tests/driver_sam0_eth/Makefile b/tests/driver_sam0_eth/Makefile new file mode 100644 index 0000000000..ebb16bb12c --- /dev/null +++ b/tests/driver_sam0_eth/Makefile @@ -0,0 +1,14 @@ +BOARD ?= same54-xpro + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_eth_minimal + +# the driver to test +USEMODULE += sam0_eth +FEATURES_REQUIRED += periph_eth +FEATURES_REQUIRED += cpu_samd5x # TODO: complete with other SAM0 CPUs that have ethernet + +INCLUDES += -I$(APPDIR) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_sam0_eth/init_dev.h b/tests/driver_sam0_eth/init_dev.h new file mode 100644 index 0000000000..0d3aa05347 --- /dev/null +++ b/tests/driver_sam0_eth/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file SAM0 ethernet peripheral + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define NETDEV_ETH_MINIMAL_NUMOF 1 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_sam0_eth/main.c b/tests/driver_sam0_eth/main.c new file mode 100644 index 0000000000..3de13066e5 --- /dev/null +++ b/tests/driver_sam0_eth/main.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for SAM0 ethernet peripheral + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "test_utils/netdev_eth_minimal.h" +#include "init_dev.h" +#include "assert.h" +#include "net/netdev.h" +#include "sam0_eth_netdev.h" + +static netdev_t sam0_eth; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + + /* setup the specific driver */ + sam0_eth_setup(&sam0_eth); + + /* set the application-provided callback */ + sam0_eth.event_callback = cb; + + /* initialize the device driver */ + int res = sam0_eth.driver->init(&sam0_eth); + assert(!res); + + return 0; +} + +int main(void) +{ + puts("Test application for SAM0 ethernet peripheral"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 32d8c864e7dceb63bf0c11dcdd3bf879ba1b8859 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 15:47:03 +0100 Subject: [PATCH 11/13] tests: add STM32 ethernet test --- tests/driver_stm32_eth/Makefile | 15 ++++++++ tests/driver_stm32_eth/init_dev.h | 36 ++++++++++++++++++ tests/driver_stm32_eth/main.c | 62 +++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 tests/driver_stm32_eth/Makefile create mode 100644 tests/driver_stm32_eth/init_dev.h create mode 100644 tests/driver_stm32_eth/main.c diff --git a/tests/driver_stm32_eth/Makefile b/tests/driver_stm32_eth/Makefile new file mode 100644 index 0000000000..9e7a707aef --- /dev/null +++ b/tests/driver_stm32_eth/Makefile @@ -0,0 +1,15 @@ +BOARD ?= nucleo-f207zg + +INCLUDES += -I$(APPDIR) + +include ../Makefile.tests_common + +USEMODULE += test_utils_netdev_eth_minimal + +# the driver to test +USEMODULE += stm32_eth + +FEATURES_REQUIRED += periph_eth +FEATURES_REQUIRED += cpu_stm32 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_stm32_eth/init_dev.h b/tests/driver_stm32_eth/init_dev.h new file mode 100644 index 0000000000..2ca59ccc61 --- /dev/null +++ b/tests/driver_stm32_eth/init_dev.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Device-specific test header file STM32 ethernet peripheral driver + * + * @author Leandro Lanzieri + */ +#ifndef INIT_DEV_H +#define INIT_DEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define NETDEV_ETH_MINIMAL_NUMOF 1 + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* INIT_DEV_H */ +/** @} */ diff --git a/tests/driver_stm32_eth/main.c b/tests/driver_stm32_eth/main.c new file mode 100644 index 0000000000..7556135911 --- /dev/null +++ b/tests/driver_stm32_eth/main.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2022 HAW Hamburg + * + * 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 tests + * @{ + * + * @file + * @brief Test application for STM32 ethernet peripheral driver + * + * @author Leandro Lanzieri + * + * @} + */ + +#include + +#include "shell.h" +#include "assert.h" +#include "stm32_eth.h" +#include "test_utils/netdev_eth_minimal.h" + +static netdev_t stm32_eth; + +int netdev_eth_minimal_init_devs(netdev_event_cb_t cb) { + + /* setup the specific driver */ + stm32_eth_netdev_setup(&stm32_eth); + + /* set the application-provided callback */ + stm32_eth.event_callback = cb; + + /* initialize the device driver */ + int res = stm32_eth.driver->init(&stm32_eth); + assert(!res); + + return 0; +} + +int main(void) +{ + puts("Test application for STM32 ethernet peripheral driver"); + + int res = netdev_eth_minimal_init(); + if (res) { + puts("Error initializing devices"); + return 1; + } + + /* start the shell */ + puts("Initialization successful - starting the shell now"); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 7cef002102fbab6aba3385001a66e57cebafd0c9 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Mon, 14 Mar 2022 17:01:25 +0100 Subject: [PATCH 12/13] tests/driver_netdev_common: add virtual board to test ETH drivers --- tests/driver_netdev_common/Makefile | 2 ++ .../netdev-ci-boards/nrf52840-ci-eth/Kconfig | 29 +++++++++++++++++++ .../netdev-ci-boards/nrf52840-ci-eth/Makefile | 6 ++++ .../nrf52840-ci-eth/Makefile.dep | 11 +++++++ .../nrf52840-ci-eth/Makefile.features | 1 + .../nrf52840-ci-eth/Makefile.include | 5 ++++ 6 files changed, 54 insertions(+) create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Kconfig create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.dep create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.features create mode 100644 tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.include diff --git a/tests/driver_netdev_common/Makefile b/tests/driver_netdev_common/Makefile index 7f543a461b..bef56e11cf 100644 --- a/tests/driver_netdev_common/Makefile +++ b/tests/driver_netdev_common/Makefile @@ -1,4 +1,6 @@ # use the default network interface for the board USEMODULE += netdev_default +EXTERNAL_BOARD_DIRS += $(CURDIR)/../external_board_dirs/netdev-ci-boards + include Makefile.netdev.mk diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Kconfig b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Kconfig new file mode 100644 index 0000000000..a1d646571a --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Kconfig @@ -0,0 +1,29 @@ +# Copyright (c) 2022 HAW Hamburg +# +# 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. + +config BOARD + default "nrf52840-ci-eth" if BOARD_NRF52840DK_CI_ETH + +config BOARD_NRF52840DK_CI_ETH + bool + default y + select BOARDS_COMMON_NRF52XXXDK + select CPU_MODEL_NRF52840XXAA + select HAS_PERIPH_PWM + select HAS_PERIPH_USBDEV + select HAS_VDD_LC_FILTER_REG0 + select HAVE_MTD_SPI_NOR + + # bring ethernet drivers + select HAVE_W5100 + select HAVE_ETHOS + select HAVE_DOSE + select HAVE_ENCX24J600 + select HAVE_ENC28J60 + + select MODULE_BOARDS_COMMON_NRF52XXXDK if TEST_KCONFIG + +source "$(RIOTBOARD)/common/nrf52xxxdk/Kconfig" diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile new file mode 100644 index 0000000000..790c1462f0 --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile @@ -0,0 +1,6 @@ +# This must be a different name than 'board' as it is implemented by 'nrf52840dk' +MODULE = board_nrf52840_ci_eth + +DIRS += $(RIOTBOARD)/nrf52840dk + +include $(RIOTBASE)/Makefile.base diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.dep b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.dep new file mode 100644 index 0000000000..8f3011282a --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.dep @@ -0,0 +1,11 @@ +USEMODULE += board_nrf52840_ci_eth + +ifneq (,$(filter netdev_default,$(USEMODULE))) + USEMODULE += w5100 + USEMODULE += ethos + USEMODULE += dose + USEMODULE += encx24j600 + USEMODULE += enc28j60 +endif + +include $(RIOTBOARD)/nrf52840dk/Makefile.dep diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.features b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.features new file mode 100644 index 0000000000..1ad8a41f85 --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.features @@ -0,0 +1 @@ +include $(RIOTBOARD)/nrf52840dk/Makefile.features diff --git a/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.include b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.include new file mode 100644 index 0000000000..0995024808 --- /dev/null +++ b/tests/external_board_dirs/netdev-ci-boards/nrf52840-ci-eth/Makefile.include @@ -0,0 +1,5 @@ +# We must duplicate the include done by $(RIOTBASE)/Makefile.include +# to also include the main board header +INCLUDES += $(addprefix -I,$(wildcard $(RIOTBOARD)/nrf52840dk/include)) + +include $(RIOTBOARD)/nrf52840dk/Makefile.include From 37908431a10a3f411e5c313143e6e0f2026d2915 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Tue, 22 Mar 2022 08:44:06 +0100 Subject: [PATCH 13/13] cpu/stm32/eth: call netdev register from the setup function --- cpu/stm32/periph/eth.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpu/stm32/periph/eth.c b/cpu/stm32/periph/eth.c index e715baf581..15c6d96b81 100644 --- a/cpu/stm32/periph/eth.c +++ b/cpu/stm32/periph/eth.c @@ -443,8 +443,6 @@ static int stm32_eth_init(netdev_t *netdev) | ETH_DMABMR_RDP_32Beat | ETH_DMABMR_PBL_32Beat | ETH_DMABMR_EDE; - netdev_register(netdev, NETDEV_STM32_ETH, 0); - eui48_t hwaddr; netdev_eui48_get(netdev, &hwaddr); stm32_eth_set_addr(hwaddr.uint8); @@ -719,4 +717,5 @@ void stm32_eth_netdev_setup(netdev_t *netdev) { stm32_eth_netdev = netdev; netdev->driver = &netdev_driver_stm32f4eth; + netdev_register(netdev, NETDEV_STM32_ETH, 0); }