From a2e5934ec904545d9e5e6eec4de7ee869b0280c1 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Wed, 16 Mar 2022 15:02:25 +0100 Subject: [PATCH] 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,