From d8affca746655b89ac2528b3b42f49b929409790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Sat, 3 Apr 2021 18:07:37 +0200 Subject: [PATCH] drivers/cc110x: add weak function cc1xxx_eui_get() --- drivers/cc110x/cc110x_netdev.c | 9 +++------ drivers/cc110x/include/cc110x_netdev.h | 2 ++ drivers/cc110x/include/cc110x_params.h | 8 -------- drivers/cc1xxx_common/gnrc_netif_cc1xxx.c | 10 ++++++++++ drivers/include/cc110x.h | 13 +------------ drivers/include/cc1xxx_common.h | 11 +++++++++++ 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/cc110x/cc110x_netdev.c b/drivers/cc110x/cc110x_netdev.c index e56753358e..c896efbb18 100644 --- a/drivers/cc110x/cc110x_netdev.c +++ b/drivers/cc110x/cc110x_netdev.c @@ -24,7 +24,6 @@ #include "assert.h" #include "iolist.h" #include "irq.h" -#include "luid.h" #include "mutex.h" #include "net/eui64.h" #include "net/netdev.h" @@ -310,13 +309,11 @@ static int cc110x_init(netdev_t *netdev) return -EIO; } - /* Setup the layer 2 address, but do not accept CC110X_L2ADDR_AUTO (which + /* Setup the layer 2 address, but do not accept CC1XXX_BCAST_ADDR (which * has the value 0x00 and is used for broadcast) */ - dev->addr = dev->params.l2addr; - while (dev->addr == CC110X_L2ADDR_AUTO) { - luid_get(&dev->addr, 1); - } + cc1xxx_eui_get(&dev->netdev, &dev->addr); + assert(dev->addr != CC1XXX_BCAST_ADDR); cc110x_write(dev, CC110X_REG_ADDR, dev->addr); /* Setup interrupt on GDO0 */ diff --git a/drivers/cc110x/include/cc110x_netdev.h b/drivers/cc110x/include/cc110x_netdev.h index bb0a22e6be..6da372e9fc 100644 --- a/drivers/cc110x/include/cc110x_netdev.h +++ b/drivers/cc110x/include/cc110x_netdev.h @@ -19,6 +19,8 @@ #ifndef CC110X_NETDEV_H #define CC110X_NETDEV_H +#include "net/netdev.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/drivers/cc110x/include/cc110x_params.h b/drivers/cc110x/include/cc110x_params.h index f322bc5419..d5e787cbbe 100644 --- a/drivers/cc110x/include/cc110x_params.h +++ b/drivers/cc110x/include/cc110x_params.h @@ -52,13 +52,6 @@ extern "C" { #define CC110X_PARAM_SPI_CLOCK SPI_CLK_5MHZ /**< SPI clock frequence to use */ #endif -#ifndef CC110X_PARAM_L2ADDR -/** - * @brief L2 address configure when the driver is initialized - */ -#define CC110X_PARAM_L2ADDR CC110X_L2ADDR_AUTO -#endif - #ifndef CC110X_PARAM_PATABLE /** * @brief PA table to use @@ -97,7 +90,6 @@ extern "C" { .cs = CC110X_PARAM_CS, \ .gdo0 = CC110X_PARAM_GDO0, \ .gdo2 = CC110X_PARAM_GDO2, \ - .l2addr = CC110X_PARAM_L2ADDR, \ .patable = CC110X_PARAM_PATABLE, \ .config = CC110X_PARAM_CONFIG, \ .channels = CC110X_PARAM_CHANNELS, \ diff --git a/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c b/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c index 3e6ea15bb5..f2b6d12f76 100644 --- a/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c +++ b/drivers/cc1xxx_common/gnrc_netif_cc1xxx.c @@ -26,6 +26,7 @@ #include "assert.h" #include "net/gnrc.h" +#include "luid.h" #include "cc1xxx_common.h" #define ENABLE_DEBUG 0 @@ -172,3 +173,12 @@ int gnrc_netif_cc1xxx_create(gnrc_netif_t *netif, char *stack, int stacksize, return gnrc_netif_create(netif, stack, stacksize, priority, name, dev, &cc1xxx_netif_ops); } + +void __attribute__((weak)) cc1xxx_eui_get(const netdev_t *netdev, uint8_t *eui) +{ + (void)netdev; + do { + luid_get(eui, 1); + } + while (*eui == CC1XXX_BCAST_ADDR); +} diff --git a/drivers/include/cc110x.h b/drivers/include/cc110x.h index 845b279c0a..0405739ad9 100644 --- a/drivers/include/cc110x.h +++ b/drivers/include/cc110x.h @@ -91,7 +91,7 @@ * Please note that the layer 2 address by default is derived from the CPU ID. * Due to the birthday paradox with only 20 devices the probability of a * collision is already bigger than 50%. Thus, manual address assignment is - * supported by defining `C110X_PARAM_L2ADDR`. + * supported by providing an implementation of @ref cc1xxx_eui_get. * * * Base Band, Data Rate, Channel Bandwidth and Channel Map Configuration @@ -225,12 +225,6 @@ extern "C" { */ #define CC110X_MAX_CHANNELS 8 -/** - * @brief Special value to indicate that layer 2 address should be derived - * from the CPU-ID - */ -#define CC110X_L2ADDR_AUTO 0x00 - /** * @brief Default protocol for data that is coming in */ @@ -470,11 +464,6 @@ typedef struct { spi_cs_t cs; /**< GPIO pin connected to chip select */ gpio_t gdo0; /**< GPIO pin connected to GDO0 */ gpio_t gdo2; /**< GPIO pin connected to GDO2 */ - /** - * @brief Layer-2 address to use or `CC110X_L2ADDR_AUTO` to derive it from - * the CPU ID - */ - uint8_t l2addr; } cc110x_params_t; /** diff --git a/drivers/include/cc1xxx_common.h b/drivers/include/cc1xxx_common.h index 47eab5faee..815554bb71 100644 --- a/drivers/include/cc1xxx_common.h +++ b/drivers/include/cc1xxx_common.h @@ -130,6 +130,17 @@ typedef struct netdev_radio_rx_info cc1xxx_rx_info_t; int gnrc_netif_cc1xxx_create(gnrc_netif_t *netif, char *stack, int stacksize, char priority, char *name, netdev_t *dev); +/** + * @brief Retrieve a unique layer-2 address for a cc1xxx instance + * + * @note This function has __attribute__((weak)) so you can override this, e.g. + * to construct an address. By default @ref luid_get is used. + * + * @param[in] dev The device descriptor of the transceiver + * @param[out] eui Destination to write the address to + */ +void cc1xxx_eui_get(const netdev_t *dev, uint8_t *eui); + #ifdef __cplusplus } #endif