diff --git a/boards/iot-lab_M3/auto_init_ng_netif/Makefile b/boards/iot-lab_M3/auto_init_ng_netif/Makefile deleted file mode 100644 index 48422e909a47d7cd428d10fa73825060ccc8d8c2..0000000000000000000000000000000000000000 --- a/boards/iot-lab_M3/auto_init_ng_netif/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/boards/iot-lab_M3/auto_init_ng_netif/netif_board.c b/boards/iot-lab_M3/auto_init_ng_netif/netif_board.c deleted file mode 100644 index b17b0ac6400a4254ba147e20b823e1443aa193ae..0000000000000000000000000000000000000000 --- a/boards/iot-lab_M3/auto_init_ng_netif/netif_board.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * 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 boards_iot-lab_M3 - * @{ - * - * @file - * @brief Network device initialization code - * - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - * - * @} - */ - -#include <stdio.h> - -#include "board.h" -#include "auto_init.h" -#include "ng_at86rf2xx.h" -#include "net/ng_nomac.h" -#include "net/ng_netbase.h" - -#define ENABLE_DEBUG (0) -#include "debug.h" - -/** - * @brief Define stack parameters for the MAC layer thread - * @{ - */ -#define MAC_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT) -#define MAC_PRIO (PRIORITY_MAIN - 3) -/** @} */ - -/** - * @brief Device descriptor for the Atmel radio - */ -static ng_at86rf2xx_t radio; - -/** - * @brief Stack for the MAC layer thread - */ -static char nomac_stack[MAC_STACKSIZE]; - - -void auto_init_ng_netif(void) -{ - /* initialize the radio */ - DEBUG("Initializing AT86RF231 radio\n"); - ng_at86rf2xx_init(&radio, AT86RF231_SPI, AT86RF231_SPI_CLK, - AT86RF231_CS, AT86RF231_INT, - AT86RF231_SLEEP, AT86RF231_RESET); - /* starting NOMAC */ - DEBUG("Starting the MAC layer\n"); - ng_nomac_init(nomac_stack, sizeof(nomac_stack), MAC_PRIO, "at86rf233", - (ng_netdev_t *)(&radio)); - DEBUG("Auto init of on-board radio complete\n"); -} diff --git a/boards/iot-lab_M3/include/ng_at86rf2xx_params.h b/boards/iot-lab_M3/include/ng_at86rf2xx_params.h new file mode 100644 index 0000000000000000000000000000000000000000..08d721527eb9e01b3ee5494b1f4f5c458aa4ded7 --- /dev/null +++ b/boards/iot-lab_M3/include/ng_at86rf2xx_params.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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 board_iot-lab_M3 + * @{ + * + * @file + * @brief at86rf231 board specific configuration + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + */ + +#ifndef NG_AT86RF2XX_PARAMS_H +#define NG_AT86RF2XX_PARAMS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name AT86RF231 configuration + */ +static const at86rf2xx_params_t at86rf2xx_params[] = + { + { + .spi = AT86RF231_SPI, + .spi_speed = AT86RF231_SPI_CLK, + .cs_pin = AT86RF231_CS, + .int_pin = AT86RF231_INT, + .sleep_pin = AT86RF231_SLEEP, + .reset_pin = AT86RF231_RESET, + }, + }; +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* NG_AT86RF2XX_PARAMS_H */ +/** @} */ diff --git a/boards/samr21-xpro/include/ng_at86rf2xx_params.h b/boards/samr21-xpro/include/ng_at86rf2xx_params.h new file mode 100644 index 0000000000000000000000000000000000000000..9a75c29ac24ad0aad5718a9550bce78ef81ba8a9 --- /dev/null +++ b/boards/samr21-xpro/include/ng_at86rf2xx_params.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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 board_samr21-xpro + * @{ + * + * @file + * @brief at86rf233 board specific configuration + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + */ + +#ifndef NG_AT86RF2XX_PARAMS_H +#define NG_AT86RF2XX_PARAMS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name AT86RF231 configuration + */ +static const at86rf2xx_params_t at86rf2xx_params[] = + { + { + .spi = NG_AT86RF233_SPI, + .spi_speed = NG_AT86RF233_SPI_CLK, + .cs_pin = NG_AT86RF233_CS, + .int_pin = NG_AT86RF233_INT, + .sleep_pin = NG_AT86RF233_SLEEP, + .reset_pin = NG_AT86RF233_RESET, + }, + }; +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* NG_AT86RF2XX_PARAMS_H */ +/** @} */ diff --git a/drivers/include/ng_at86rf2xx.h b/drivers/include/ng_at86rf2xx.h index 5b8b02c0419214730b6d2aea7d268537afa362ef..83bbbff5db18727c5e31d4f24253bb66f224046b 100644 --- a/drivers/include/ng_at86rf2xx.h +++ b/drivers/include/ng_at86rf2xx.h @@ -178,6 +178,18 @@ int ng_at86rf2xx_init(ng_at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed, gpio_t cs_pin, gpio_t int_pin, gpio_t sleep_pin, gpio_t reset_pin); +/** + * @brief struct holding all params needed for device initialization + */ +typedef struct at86rf2xx_params { + spi_t spi; /**< SPI bus the device is connected to */ + spi_speed_t spi_speed; /**< SPI speed to use */ + gpio_t cs_pin; /**< GPIO pin connected to chip select */ + gpio_t int_pin; /**< GPIO pin connected to the interrupt pin */ + gpio_t sleep_pin; /**< GPIO pin connected to the sleep pin */ + gpio_t reset_pin; /**< GPIO pin connected to the reset pin */ +} at86rf2xx_params_t; + /** * @brief Trigger a hardware reset and configure radio with default values * diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index a7ed09f13d560132dbf5130c3b0e7701e55bae04..b1b39b8c41d0d341fa334a018ee7c052700c6ca2 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -306,4 +306,12 @@ void auto_init(void) DEBUG("Auto init UDP module.\n"); ng_udp_init(); #endif + + + /* initialize network devices */ + +#ifdef MODULE_NG_AT86RF2XX + extern void auto_init_ng_at86rf2xx(void); + auto_init_ng_at86rf2xx(); +#endif } diff --git a/sys/auto_init/netif/auto_init_ng_at86rf2xx.c b/sys/auto_init/netif/auto_init_ng_at86rf2xx.c new file mode 100644 index 0000000000000000000000000000000000000000..0cd4cf72c5db62be1c97259d4288033cd1d9f6f9 --- /dev/null +++ b/sys/auto_init/netif/auto_init_ng_at86rf2xx.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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 auto_init_ng_netif + * @{ + * + * @file + * @brief Auto initialization for nx_at86rf2xx network interfaces + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + */ + +#ifdef MODULE_NG_AT86RF2XX + +#include "board.h" +#include "net/ng_nomac.h" +#include "net/ng_netbase.h" + +#include "ng_at86rf2xx.h" +#include "ng_at86rf2xx_params.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +/** + * @brief Define stack parameters for the MAC layer thread + * @{ + */ +#define AT86RF2XX_MAC_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT) +#define AT86RF2XX_MAC_PRIO (PRIORITY_MAIN - 3) + +#define AT86RF2XX_NUM (sizeof(at86rf2xx_params)/sizeof(at86rf2xx_params[0])) + +static ng_at86rf2xx_t ng_at86rf2xx_devs[AT86RF2XX_NUM]; +static char _nomac_stacks[AT86RF2XX_MAC_STACKSIZE][AT86RF2XX_NUM]; + +void auto_init_ng_at86rf2xx(void) +{ + for (int i = 0; i < AT86RF2XX_NUM; i++) { + DEBUG("Initializing AT86RF2xx radio at SPI_%i\n", i); + const at86rf2xx_params_t *p = &at86rf2xx_params[i]; + int res = ng_at86rf2xx_init(&ng_at86rf2xx_devs[i], + p->spi, + p->spi_speed, + p->cs_pin, + p->int_pin, + p->sleep_pin, + p->reset_pin); + + if (res < 0) { + DEBUG("Error initializing AT86RF2xx radio device!"); + } + else { + ng_nomac_init(_nomac_stacks[i], + AT86RF2XX_MAC_STACKSIZE, AT86RF2XX_MAC_PRIO, + "at86rfxx", (ng_netdev_t *)&ng_at86rf2xx_devs[i]); + } + } +} +#endif /* MODULE_NG_AT86RF2XX */ + +/** @} */ diff --git a/tests/driver_at86rf2xx/Makefile b/tests/driver_at86rf2xx/Makefile index 170e7dfd15bb38910e6621bd043d6b1964f96b3d..004b877c5a00c6a873b084633ea5603c70cb271e 100644 --- a/tests/driver_at86rf2xx/Makefile +++ b/tests/driver_at86rf2xx/Makefile @@ -7,47 +7,28 @@ BOARD_INSUFFICIENT_RAM := stm32f0discovery BOARD_BLACKLIST := nucleo-f334 # nucleo-f334: not enough GPIO pins defined -ifneq (,$(filter saml21-xpro,$(BOARD))) - DRIVER ?= ng_at86rf212b - export ATRF_SPI ?= SPI_0 - export ATRF_CS ?= EXT1_SPI_SS - export ATRF_INT ?= EXT1_P09 - export ATRF_RESET ?= EXT1_P07 - export ATRF_SLEEP ?= EXT1_P10 - export ATRF_SPI_SPEED ?= SPI_SPEED_1MHZ +ifneq (,$(filter samr21-xpro,$(BOARD))) + DRIVER ?= ng_at86rf233 + USE_BOARD_PARAMETERS:=true endif ifneq (,$(filter iot-lab_M3,$(BOARD))) DRIVER ?= ng_at86rf231 - export ATRF_SPI ?= SPI_0 - export ATRF_CS ?= GPIO_11 - export ATRF_INT ?= GPIO_12 - export ATRF_RESET ?= GPIO_13 - export ATRF_SLEEP ?= GPIO_14 -endif -ifneq (,$(filter samr21-xpro,$(BOARD))) - DRIVER ?= ng_at86rf233 - export ATRF_SPI ?= SPI_0 - export ATRF_CS ?= GPIO_4 - export ATRF_INT ?= GPIO_5 - export ATRF_RESET ?= GPIO_6 - export ATRF_SLEEP ?= GPIO_7 - export ATRF_SPI_SPEED ?= SPI_SPEED_1MHZ + USE_BOARD_PARAMETERS:=true endif ifneq (,$(DRIVER)) USEMODULE += $(DRIVER) else - USEMODULE += ng_at86rf231 # default to ng_at86rf231 + # default to ng_at86rf231 + USEMODULE += ng_at86rf231 endif -USEMODULE += ng_netif -USEMODULE += ng_nomac -USEMODULE += ng_pktdump -USEMODULE += uart0 -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps -CFLAGS += -DDEVELHELP +ifneq (true,$(USE_BOARD_PARAMETERS)) + # This adds . to include path so generic ng_at86rf2xx_params.h gets picked + # up. All boards actually having such a device on board should define + # USE_BOARD_PARAMETERS=true above to skip this step, as the board provides + # this header. + CFLAGS += -I$(CURDIR) ifneq (,$(ATRF_SPI)) CFLAGS += -DATRF_SPI=$(ATRF_SPI) @@ -78,4 +59,17 @@ ifneq (,$(ATRF_SPI_SPEED)) CFLAGS += -DATRF_SPI_SPEED=$(ATRF_SPI_SPEED) endif +endif # USE_BOARD_PARAMETERS=false + +USEMODULE += auto_init_ng_netif +USEMODULE += ng_netif +USEMODULE += ng_nomac +USEMODULE += ng_pktdump +USEMODULE += uart0 +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +CFLAGS += -DDEVELHELP + include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile b/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile deleted file mode 100644 index 48422e909a47d7cd428d10fa73825060ccc8d8c2..0000000000000000000000000000000000000000 --- a/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/tests/driver_at86rf2xx/auto_init_ng_netif/netif_app.c b/tests/driver_at86rf2xx/auto_init_ng_netif/netif_app.c deleted file mode 100644 index c22194775d3beb7af036ed7e1066a1059711db9a..0000000000000000000000000000000000000000 --- a/tests/driver_at86rf2xx/auto_init_ng_netif/netif_app.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * 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 AT86RF2xx network device driver - * - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - * - * @} - */ - -#include <stdio.h> - -#include "kernel.h" -#include "ng_at86rf2xx.h" -#include "net/ng_nomac.h" -#include "net/ng_netbase.h" - -/* make sure the SPI port and the needed GPIO pins are defined */ -#ifndef ATRF_SPI -#error "SPI not defined" -#endif -#ifndef ATRF_CS -#error "Chip select pin not defined" -#endif -#ifndef ATRF_INT -#error "Interrupt pin not defined" -#endif -#ifndef ATRF_SLEEP -#error "Sleep pin not defined" -#endif -#ifndef ATRF_RESET -#error "Reset pin not defined" -#endif -#ifndef ATRF_SPI_SPEED -#define ATRF_SPI_SPEED (SPI_SPEED_5MHZ) -#endif - -/** - * @brief MAC layer stack configuration - * @{ - */ -#define STACKSIZE (KERNEL_CONF_STACKSIZE_MAIN) -#define PRIO (0) -/** @} */ - -/** - * @brief Allocate the AT86RF2xx device descriptor - */ -static ng_at86rf2xx_t dev; - -/** - * @brief Stack for the nomac thread - */ -static char nomac_stack[STACKSIZE]; - - -void auto_init_ng_netif(void) -{ - kernel_pid_t iface; - int res; - - /* initialize the AT86RF2xx device */ - printf("Initializing the AT86RF2xx radio at SPI_%i... \n", ATRF_SPI); - res = ng_at86rf2xx_init(&dev, ATRF_SPI, ATRF_SPI_SPEED, - ATRF_CS, ATRF_INT, - ATRF_SLEEP, ATRF_RESET); - if (res < 0) { - puts("Error initializing AT86RF2xx radio device"); - return; - } - - /* start MAC layer */ - puts("Starting the NOMAC layer on top of the driver"); - iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIO, "at86rf2xx", - (ng_netdev_t *)(&dev)); - if (iface <= KERNEL_PID_UNDEF) { - puts("Error initializing MAC layer"); - return; - } - -} diff --git a/tests/driver_at86rf2xx/main.c b/tests/driver_at86rf2xx/main.c index 008b70c23ab6828836a275f4b2936ee039df064b..728887f3e819a6ea19eecdd8f42a659f71386a38 100644 --- a/tests/driver_at86rf2xx/main.c +++ b/tests/driver_at86rf2xx/main.c @@ -20,7 +20,6 @@ #include <stdio.h> - #include "shell.h" #include "shell_commands.h" #include "posix_io.h" diff --git a/tests/driver_at86rf2xx/ng_at86rf2xx_params.h b/tests/driver_at86rf2xx/ng_at86rf2xx_params.h new file mode 100644 index 0000000000000000000000000000000000000000..4eaf70222ff75d83f32333a0821b25f7262db502 --- /dev/null +++ b/tests/driver_at86rf2xx/ng_at86rf2xx_params.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * + * 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_at86rf2xx + * @brief generic at86rf231 pin config + * + * @{ + * @file + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NG_AT86RF2XX_PARAMS_H +#define NG_AT86RF2XX_PARAMS_H + +/** + * @brief make sure the SPI port and the needed GPIO pins are defined + * @{ + */ +#ifndef ATRF_SPI +#error "SPI not defined" +#endif +#ifndef ATRF_CS +#error "Chip select pin not defined" +#endif +#ifndef ATRF_INT +#error "Interrupt pin not defined" +#endif +#ifndef ATRF_SLEEP +#error "Sleep pin not defined" +#endif +#ifndef ATRF_RESET +#error "Reset pin not defined" +#endif +#ifndef ATRF_SPI_SPEED +#define ATRF_SPI_SPEED (SPI_SPEED_5MHZ) +#endif +/**@}*/ + +/** + * @name AT86RF231 configuration + */ +static const at86rf2xx_params_t at86rf2xx_params[] = + { + { + .spi = ATRF_SPI, + .spi_speed = ATRF_SPI_SPEED, + .cs_pin = ATRF_CS, + .int_pin = ATRF_INT, + .sleep_pin = ATRF_SLEEP, + .reset_pin = ATRF_RESET, + }, + }; +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* NG_AT86RF2XX_PARAMS_H */ +/** @} */