From de79edb352b002d239980c822430bffa45a78549 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Thu, 3 Mar 2022 14:10:33 +0100 Subject: [PATCH] drivers/encx24j600: define default parameters --- dist/tools/doccheck/exclude_patterns | 4 ++ .../encx24j600/include/encx24j600_params.h | 62 +++++++++++++++++++ .../netif/init_devs/auto_init_encx24j600.c | 41 +++++++----- tests/driver_encx24j600/Makefile | 17 ++--- 4 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 drivers/encx24j600/include/encx24j600_params.h diff --git a/dist/tools/doccheck/exclude_patterns b/dist/tools/doccheck/exclude_patterns index cb824d30a3..261b5044d4 100644 --- a/dist/tools/doccheck/exclude_patterns +++ b/dist/tools/doccheck/exclude_patterns @@ -14887,3 +14887,7 @@ pkg/lvgl7/include/lvgl_riot_conf\.h:[0-9]+: warning: Member LV_TICK_CUSTOM \(mac pkg/lvgl7/include/lvgl_riot_conf\.h:[0-9]+: warning: Member LV_TICK_CUSTOM_INCLUDE \(macro definition\) of file lvgl_riot_conf\.h is not documented\. pkg/lvgl7/include/lvgl_riot_conf\.h:[0-9]+: warning: Member LV_TICK_CUSTOM_SYS_TIME_EXPR \(macro definition\) of file lvgl_riot_conf\.h is not documented\. pkg/lvgl7/include/lvgl_riot_conf\.h:[0-9]+: warning: Member lv_coord_t \(typedef\) of file lvgl_riot_conf\.h is not documented\. +drivers/encx24j600/include/encx24j600_params\.h:[0-9]+: warning: Member ENCX24J600_PARAM_SPI \(macro definition\) of file encx24j600_params\.h is not documented\. +drivers/encx24j600/include/encx24j600_params\.h:[0-9]+: warning: Member ENCX24J600_PARAM_CS \(macro definition\) of file encx24j600_params\.h is not documented\. +drivers/encx24j600/include/encx24j600_params\.h:[0-9]+: warning: Member ENCX24J600_PARAM_INT \(macro definition\) of file encx24j600_params\.h is not documented\. +drivers/encx24j600/include/encx24j600_params\.h:[0-9]+: warning: Member ENCX24J600_PARAMS \(macro definition\) of file encx24j600_params\.h is not documented\. diff --git a/drivers/encx24j600/include/encx24j600_params.h b/drivers/encx24j600/include/encx24j600_params.h new file mode 100644 index 0000000000..4603926c19 --- /dev/null +++ b/drivers/encx24j600/include/encx24j600_params.h @@ -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 drivers_encx24j600 + * @{ + * + * @file + * @brief Default configuration for the ENCX24J600 Ethernet driver + * + * @author Leandro Lanzieri + */ + +#ifndef ENCX24J600_PARAMS_H +#define ENCX24J600_PARAMS_H + +#include "encx24j600.h" +#include "board.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Set default configuration parameters for the ENCX24J600 driver + * @{ + */ +#ifndef ENCX24J600_PARAM_SPI +#define ENCX24J600_PARAM_SPI (SPI_DEV(0)) +#endif +#ifndef ENCX24J600_PARAM_CS +#define ENCX24J600_PARAM_CS (GPIO_PIN(0, 0)) +#endif +#ifndef ENCX24J600_PARAM_INT +#define ENCX24J600_PARAM_INT (GPIO_PIN(0, 1)) +#endif + +#ifndef ENCX24J600_PARAMS +#define ENCX24J600_PARAMS { .spi = ENCX24J600_PARAM_SPI, \ + .cs_pin = ENCX24J600_PARAM_CS, \ + .int_pin = ENCX24J600_PARAM_INT } +#endif +/** @} */ + +/** + * @brief ENCX24J600 configuration + */ +static const encx24j600_params_t encx24j600_params[] = { + ENCX24J600_PARAMS +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ENCX24J600_PARAMS_H */ +/** @} */ 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 f7660468d6..46e96925f9 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_encx24j600.c @@ -20,11 +20,9 @@ #include "log.h" #include "debug.h" #include "encx24j600.h" +#include "encx24j600_params.h" #include "net/gnrc/netif/ethernet.h" -static encx24j600_t encx24j600; -static gnrc_netif_t _netif; - /** * @brief Define stack parameters for the MAC layer thread * @{ @@ -34,25 +32,38 @@ static gnrc_netif_t _netif; #define ENCX24J600_MAC_PRIO (GNRC_NETIF_PRIO) #endif +/** + * @brief Find out how many of these devices are present + */ +#define ENCX24J600_NUM ARRAY_SIZE(encx24j600_params) + +/** + * @brief Allocate device descriptors. + */ +static encx24j600_t encx24j600[ENCX24J600_NUM]; + +/** + * @brief Allocate GNRC interfaces. + */ +static gnrc_netif_t _netif[ENCX24J600_NUM]; + /** * @brief Stacks for the MAC layer threads */ -static char _netdev_eth_stack[ENCX24J600_MAC_STACKSIZE]; +static char _netdev_eth_stack[ENCX24J600_NUM][ENCX24J600_MAC_STACKSIZE]; void auto_init_encx24j600(void) { - LOG_DEBUG("[auto_init_netif] initializing encx24j600 #0\n"); + for (unsigned i = 0; i < ENCX24J600_NUM; i++) { + LOG_DEBUG("[auto_init_netif] initializing encx24j600 #%u\n", i); - /* setup netdev device */ - encx24j600_params_t p; - p.spi = ENCX24J600_SPI; - p.cs_pin = ENCX24J600_CS; - p.int_pin = ENCX24J600_INT; - encx24j600_setup(&encx24j600, &p); + /* setup netdev device */ + encx24j600_setup(&encx24j600[i], &encx24j600_params[i]); - /* initialize netdev<->gnrc adapter state */ - gnrc_netif_ethernet_create(&_netif, _netdev_eth_stack, ENCX24J600_MAC_STACKSIZE, - ENCX24J600_MAC_PRIO, "encx24j600", - &encx24j600.netdev); + /* initialize netdev<->gnrc adapter state */ + gnrc_netif_ethernet_create(&_netif[i], _netdev_eth_stack[i], ENCX24J600_MAC_STACKSIZE, + ENCX24J600_MAC_PRIO, "encx24j600", + &encx24j600[i].netdev); + } } /** @} */ diff --git a/tests/driver_encx24j600/Makefile b/tests/driver_encx24j600/Makefile index 119699d83b..7b1feb5f01 100644 --- a/tests/driver_encx24j600/Makefile +++ b/tests/driver_encx24j600/Makefile @@ -15,20 +15,13 @@ ifneq (,$(filter nucleo-f334r8,$(BOARD))) ENC_SPI ?= SPI_DEV\(0\) ENC_CS ?= GPIO_PIN\(PORT_C,10\) ENC_INT ?= GPIO_PIN\(PORT_D,2\) + + # export SPI and pins + CFLAGS += -DENCX24J600_SPI=$(ENC_SPI) + CFLAGS += -DENCX24J600_CS=$(ENC_CS) + CFLAGS += -DENCX24J600_INT=$(ENC_INT) 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\) -# export SPI and pins -CFLAGS += -DENCX24J600_SPI=$(ENC_SPI) -CFLAGS += -DENCX24J600_CS=$(ENC_CS) -CFLAGS += -DENCX24J600_INT=$(ENC_INT) - -# make sure we read the local encx24j600 params file -CFLAGS += -I$(CURDIR) - include $(RIOTBASE)/Makefile.include # lower pktbuf size