From 867beae83602d29bbac59b8fbae340c945b3a58b Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 20:48:38 +0200 Subject: [PATCH 1/7] make: added missing deps for ng_nomac and ng_netif --- Makefile.dep | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile.dep b/Makefile.dep index f33348d89..378b8d943 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -48,6 +48,14 @@ ifneq (,$(filter sixlowpan,$(USEMODULE))) USEMODULE += vtimer endif +ifneq (,$(filter ng_netif,$(USEMODULE))) + USEMODULE += ng_netbase +endif + +ifneq (,$(filter ng_nomac,$(USEMODULE))) + USEMODULE += ng_netbase +endif + ifneq (,$(filter ng_sixlowpan_frag,$(USEMODULE))) USEMODULE += ng_sixlowpan USEMODULE += vtimer From 56cce1957801a866657ce3fb732e49119fd863f1 Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 20:50:18 +0200 Subject: [PATCH 2/7] make: added APPDIR as environment variable --- Makefile.include | 5 ++++- Makefile.vars | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index 7235312eb..8a543ba0a 100644 --- a/Makefile.include +++ b/Makefile.include @@ -16,7 +16,10 @@ RIOTPROJECT := $(abspath $(RIOTPROJECT)) # Path to the current directory relative to the git root BUILDRELPATH ?= $(shell git rev-parse --show-prefix) -BINDIRBASE ?= $(CURDIR)/bin +APPDIR ?= $(CURDIR) +APPDIR := $(abspath $(APPDIR))/ + +BINDIRBASE ?= $(APPDIR)/bin BINDIRBASE := $(abspath $(BINDIRBASE)) BINDIR ?= $(BINDIRBASE)/$(BOARD) diff --git a/Makefile.vars b/Makefile.vars index ab69f06e7..49fca3116 100644 --- a/Makefile.vars +++ b/Makefile.vars @@ -19,6 +19,7 @@ export RIOTBOARD # For third party BOARDs this folder is the base of export RIOTPROJECT # Top level git root of the project being built, or PWD if not a git repository export BINDIRBASE # This is the folder where the application should be built in. For each BOARD a different subfolder is used. export BINDIR # This is the folder where the application should be built in. +export APPDIR # The base folder containing the application export PREFIX # The prefix of the toolchain commands, e.g. "arm-non-eabi-" or "msp430-". export CC # The C compiler to use. From a4358bfdeea19f34bd459a83e9027d72b25bf204 Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 21:17:07 +0200 Subject: [PATCH 3/7] sys/auto-init: added mechanism to init network ifs --- sys/Makefile.include | 3 +++ sys/auto_init/Makefile | 2 ++ sys/auto_init/Makefile.include | 13 +++++++++++++ sys/auto_init/auto_init.c | 5 +++++ sys/include/auto_init.h | 22 +++++++++++++++++++++- 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 sys/auto_init/Makefile.include diff --git a/sys/Makefile.include b/sys/Makefile.include index ee40a88f8..ca3bce155 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -1,3 +1,6 @@ +ifneq (,$(filter auto_init,$(USEMODULE))) + include $(RIOTBASE)/sys/auto_init/Makefile.include +endif ifneq (,$(filter nomac,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include endif diff --git a/sys/auto_init/Makefile b/sys/auto_init/Makefile index 6579f361b..68b09798d 100644 --- a/sys/auto_init/Makefile +++ b/sys/auto_init/Makefile @@ -6,4 +6,6 @@ ifneq (,$(filter nomac,$(USEMODULE))) INCLUDES += -I$(RIOTBASE)/sys/net/include/ endif +DIRS += $(AUTO_INIT_MODULES) + include $(RIOTBASE)/Makefile.base diff --git a/sys/auto_init/Makefile.include b/sys/auto_init/Makefile.include new file mode 100644 index 000000000..6a8683366 --- /dev/null +++ b/sys/auto_init/Makefile.include @@ -0,0 +1,13 @@ +# try to find the ng_netif auto init implementation in the application or in +# the board, respectively. If it is not found, nothing is called. +ifneq (,$(filter ng_netif,$(USEMODULE))) + ifneq (,$(wildcard $(APPDIR)/auto_init_ng_netif/*)) + export AUTO_INIT_MODULES += $(APPDIR)/auto_init_ng_netif + export USEMODULE += auto_init_ng_netif + else + ifneq (,$(wildcard $(RIOTBOARD)/$(BOARD)/auto_init_ng_netif/*)) + export AUTO_INIT_MODULES += $(RIOTBOARD)/$(BOARD)/auto_init_ng_netif + export USEMODULE += auto_init_ng_netif + endif + endif +endif diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 4e9010538..c45879dd5 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -12,6 +12,7 @@ * @file auto_init_c * @brief initializes any used module that has a trivial init function * @author Oliver Hahm + * @author Hauke Petersen * @} */ #include @@ -304,4 +305,8 @@ void auto_init(void) DEBUG("Auto init UDP module.\n"); ng_udp_init(); #endif +#ifdef MODULE_AUTO_INIT_NG_NETIF + DEBUG("Auto init network interfaces.\n"); + auto_init_ng_netif(); +#endif } diff --git a/sys/include/auto_init.h b/sys/include/auto_init.h index 93d4d30a8..d27e608b3 100644 --- a/sys/include/auto_init.h +++ b/sys/include/auto_init.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Freie Universität Berlin + * Copyright (C) 2010,2015 Freie Universität Berlin * Copyright (C) 2010 Kaspar Schleiser * Copyright (C) 2013 INRIA * @@ -27,6 +27,10 @@ * @{ * * @file auto_init.h + * + * @author Kaspar Schleiser + * @author Oliver Hahm + * @author Hauke Petersen */ #ifndef AUTO_INIT_H @@ -45,6 +49,22 @@ extern "C" { */ void auto_init(void); +/** + * @brief Initialize network interfaces and register them with ng_netif + * + * This function must be implemented in the board or in the application, + * in a subfolder that must be named auto_init_ng_netif + * This function is called under two conditions: + * 1. the ng_netif module is used (USEMODULE contains ng_netif) + * 2. the board or the application contains a subfolder called + * auto_init_ng_netif + * If the board and the application both contain the mentioned subfolder, + * the contents from the applications subfolder have a higher priority + * and will be compiled and linked, while the board's subfolder is then + * ignored. + */ +void auto_init_ng_netif(void); + #ifdef __cplusplus } #endif From 10615f863e3f4d1513ab340c16bf68a379f818f0 Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 21:29:02 +0200 Subject: [PATCH 4/7] board/iot-lab: added network interface init --- boards/iot-lab_M3/Makefile.dep | 5 ++ boards/iot-lab_M3/auto_init_ng_netif/Makefile | 1 + .../auto_init_ng_netif/netif_board.c | 63 +++++++++++++++++++ boards/iot-lab_M3/include/board.h | 1 + 4 files changed, 70 insertions(+) create mode 100644 boards/iot-lab_M3/auto_init_ng_netif/Makefile create mode 100644 boards/iot-lab_M3/auto_init_ng_netif/netif_board.c diff --git a/boards/iot-lab_M3/Makefile.dep b/boards/iot-lab_M3/Makefile.dep index ab5c150ef..42bad1251 100644 --- a/boards/iot-lab_M3/Makefile.dep +++ b/boards/iot-lab_M3/Makefile.dep @@ -4,3 +4,8 @@ ifneq (,$(filter defaulttransceiver,$(USEMODULE))) USEMODULE += transceiver endif endif + +ifneq (,$(filter ng_netif,$(USEMODULE))) + USEMODULE += ng_at86rf231 + USEMODULE += ng_nomac +endif diff --git a/boards/iot-lab_M3/auto_init_ng_netif/Makefile b/boards/iot-lab_M3/auto_init_ng_netif/Makefile new file mode 100644 index 000000000..48422e909 --- /dev/null +++ b/boards/iot-lab_M3/auto_init_ng_netif/Makefile @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..b17b0ac64 --- /dev/null +++ b/boards/iot-lab_M3/auto_init_ng_netif/netif_board.c @@ -0,0 +1,63 @@ +/* + * 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 + * + * @} + */ + +#include + +#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/board.h b/boards/iot-lab_M3/include/board.h index afc8ea856..e119c22c4 100644 --- a/boards/iot-lab_M3/include/board.h +++ b/boards/iot-lab_M3/include/board.h @@ -68,6 +68,7 @@ extern "C" { #define AT86RF231_INT GPIO_12 #define AT86RF231_RESET GPIO_13 #define AT86RF231_SLEEP GPIO_14 +#define AT86RF231_SPI_CLK SPI_SPEED_5MHZ /** @} */ /** From 43f8a04c41b8a8bb69bba45c3adbf0839a5b6143 Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 21:45:56 +0200 Subject: [PATCH 5/7] boards/samr21-xpro: added init of network interfaces --- boards/samr21-xpro/Makefile.dep | 5 ++ .../samr21-xpro/auto_init_ng_netif/Makefile | 1 + .../auto_init_ng_netif/netif_board.c | 62 +++++++++++++++++++ boards/samr21-xpro/include/board.h | 15 ++++- 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 boards/samr21-xpro/auto_init_ng_netif/Makefile create mode 100644 boards/samr21-xpro/auto_init_ng_netif/netif_board.c diff --git a/boards/samr21-xpro/Makefile.dep b/boards/samr21-xpro/Makefile.dep index ab5c150ef..2521ad441 100644 --- a/boards/samr21-xpro/Makefile.dep +++ b/boards/samr21-xpro/Makefile.dep @@ -4,3 +4,8 @@ ifneq (,$(filter defaulttransceiver,$(USEMODULE))) USEMODULE += transceiver endif endif + +ifneq (,$(filter ng_netif,$(USEMODULE))) + USEMODULE += ng_at86rf233 + USEMODULE += ng_nomac +endif diff --git a/boards/samr21-xpro/auto_init_ng_netif/Makefile b/boards/samr21-xpro/auto_init_ng_netif/Makefile new file mode 100644 index 000000000..48422e909 --- /dev/null +++ b/boards/samr21-xpro/auto_init_ng_netif/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/boards/samr21-xpro/auto_init_ng_netif/netif_board.c b/boards/samr21-xpro/auto_init_ng_netif/netif_board.c new file mode 100644 index 000000000..4bcb41e7f --- /dev/null +++ b/boards/samr21-xpro/auto_init_ng_netif/netif_board.c @@ -0,0 +1,62 @@ +/* + * 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_samr21-xpro + * @{ + * + * @file + * @brief Network device initialization code + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#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 AT86RF233 radio\n"); + ng_at86rf2xx_init(&radio, NG_AT86RF233_SPI, NG_AT86RF233_SPI_CLK, + NG_AT86RF233_CS, NG_AT86RF233_INT, + NG_AT86RF233_SLEEP, NG_AT86RF233_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/samr21-xpro/include/board.h b/boards/samr21-xpro/include/board.h index cfaa4a75a..fa073b140 100644 --- a/boards/samr21-xpro/include/board.h +++ b/boards/samr21-xpro/include/board.h @@ -37,6 +37,18 @@ extern "C" { */ #define HW_TIMER TIMER_1 +/** +* @name NG_AT86RF233 configuration +* @{ +*/ +#define NG_AT86RF233_SPI (SPI_0) +#define NG_AT86RF233_CS (GPIO_4) +#define NG_AT86RF233_INT (GPIO_5) +#define NG_AT86RF233_RESET (GPIO_6) +#define NG_AT86RF233_SLEEP (GPIO_7) +#define NG_AT86RF233_SPI_CLK (SPI_SPEED_1MHZ) +/** @}*/ + /** * @name AT86RF231 config * @{ @@ -48,7 +60,8 @@ extern "C" { #define AT86RF231_SLEEP GPIO_7 #define AT86RF231_SPI_SPEED SPI_SPEED_1MHZ -/** @}*/ +/** @} */ + /** * @name Define UART device and baudrate for stdio * @{ From 8e0d4ab4633e5a7ee2f3190b25d50aba4c9c2ea6 Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 22:02:15 +0200 Subject: [PATCH 6/7] tests/driver_xbee: adjusted to interface auto_init --- tests/driver_xbee/Makefile | 2 +- tests/driver_xbee/auto_init_ng_netif/Makefile | 1 + .../auto_init_ng_netif/netif_app.c | 77 +++++++++++++++++++ tests/driver_xbee/main.c | 45 ----------- 4 files changed, 79 insertions(+), 46 deletions(-) create mode 100644 tests/driver_xbee/auto_init_ng_netif/Makefile create mode 100644 tests/driver_xbee/auto_init_ng_netif/netif_app.c diff --git a/tests/driver_xbee/Makefile b/tests/driver_xbee/Makefile index aee00ccf7..936c49016 100644 --- a/tests/driver_xbee/Makefile +++ b/tests/driver_xbee/Makefile @@ -17,7 +17,7 @@ ifneq (,$(filter nucleo-f091,$(BOARD))) endif USEMODULE += xbee -USEMODULE += ng_netbase +USEMODULE += ng_netif USEMODULE += ng_nomac USEMODULE += ng_pktdump USEMODULE += shell diff --git a/tests/driver_xbee/auto_init_ng_netif/Makefile b/tests/driver_xbee/auto_init_ng_netif/Makefile new file mode 100644 index 000000000..48422e909 --- /dev/null +++ b/tests/driver_xbee/auto_init_ng_netif/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/tests/driver_xbee/auto_init_ng_netif/netif_app.c b/tests/driver_xbee/auto_init_ng_netif/netif_app.c new file mode 100644 index 000000000..c78bccc21 --- /dev/null +++ b/tests/driver_xbee/auto_init_ng_netif/netif_app.c @@ -0,0 +1,77 @@ +/* + * 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 Xbee device initialization + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "kernel.h" +#include "xbee.h" +#include "net/ng_nomac.h" +#include "net/ng_netbase.h" + +/* make sure an UART to device is defined in the Makefile */ +#ifndef XBEE_UART +#error "XBEE_UART not defined" +#endif + +/** + * @brief This is the default baudrate the Xbee modules are programmed to + * when you buy them + */ +#define XBEE_BAUDRATE (9600U) + +/** + * @brief MAC layer stack configuration + * @{ + */ +#define STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT) +#define PRIO (0) +/** @} */ + +/** + * @brief The Xbee device descriptor + */ +static xbee_t dev; + +/** + * @brief Stack for the nomac thread + */ +static char nomac_stack[STACKSIZE]; + + +void auto_init_ng_netif(void) +{ + int res; + kernel_pid_t iface; + + /* setup Xbee device */ + printf("Initializing the Xbee S1 device UART_%i... \n", XBEE_UART); + res = xbee_init(&dev, XBEE_UART, XBEE_BAUDRATE, GPIO_NUMOF, GPIO_NUMOF); + if (res < 0) { + puts("Error initializing xbee device driver"); + return; + } + /* start MAC layer */ + iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIO, "xbee", + (ng_netdev_t *)(&dev)); + if (iface <= KERNEL_PID_UNDEF) { + puts("Error initializing MAC layer"); + return; + } +} diff --git a/tests/driver_xbee/main.c b/tests/driver_xbee/main.c index 5f53d6833..a0429ab0f 100644 --- a/tests/driver_xbee/main.c +++ b/tests/driver_xbee/main.c @@ -20,41 +20,16 @@ #include -#include "board.h" -#include "kernel.h" #include "shell.h" #include "shell_commands.h" -#include "xbee.h" #include "net/ng_netbase.h" -#include "net/ng_nomac.h" #include "net/ng_pktdump.h" -/* make sure an UART to device is defined in the Makefile */ -#ifndef XBEE_UART -#error "XBEE_UART not defined" -#endif - -/** - * @brief This is the default baudrate the Xbee modules are programmed to - * when you buy them - */ -#define XBEE_BAUDRATE (9600U) - /** * @brief Buffer size used by the shell */ #define SHELL_BUFSIZE (64U) -/** - * @brief The Xbee device descriptor - */ -static xbee_t dev; - -/** - * @brief Stack for the nomac thread - */ -static char nomac_stack[KERNEL_CONF_STACKSIZE_DEFAULT]; - /** * @brief Read chars from STDIO */ @@ -76,16 +51,10 @@ void shell_put(int c) */ int main(void) { - kernel_pid_t iface; - int res; shell_t shell; ng_netreg_entry_t dump; puts("Xbee S1 device driver test"); - printf("Initializing the Xbee S1 device UART_%i... \n", XBEE_UART); - - /* initialize network module(s) */ - ng_netif_init(); /* initialize and register pktdump */ dump.pid = ng_pktdump_getpid(); @@ -96,20 +65,6 @@ int main(void) dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &dump); - /* setup Xbee device */ - res = xbee_init(&dev, XBEE_UART, XBEE_BAUDRATE, GPIO_NUMOF, GPIO_NUMOF); - if (res < 0) { - puts("Error initializing xbee device driver"); - return -1; - } - /* start MAC layer */ - iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIORITY_MAIN - 3, - "xbee_l2", (ng_netdev_t *)&dev); - if (iface <= KERNEL_PID_UNDEF) { - puts("Error initializing MAC layer"); - return -1; - } - /* start the shell */ puts("Initialization OK, starting shell now"); shell_init(&shell, NULL, SHELL_BUFSIZE, shell_read, shell_put); From 2187b5caa9c21a11823917f871bdff98790f8cee Mon Sep 17 00:00:00 2001 From: haukepetersen Date: Wed, 29 Apr 2015 22:12:45 +0200 Subject: [PATCH 7/7] tests/driver_at86rf2xx: adjusted netif auto init --- tests/driver_at86rf2xx/Makefile | 2 +- .../auto_init_ng_netif/Makefile | 1 + .../auto_init_ng_netif/netif_app.c | 91 +++++++++++++++++++ tests/driver_at86rf2xx/main.c | 59 +----------- 4 files changed, 95 insertions(+), 58 deletions(-) create mode 100644 tests/driver_at86rf2xx/auto_init_ng_netif/Makefile create mode 100644 tests/driver_at86rf2xx/auto_init_ng_netif/netif_app.c diff --git a/tests/driver_at86rf2xx/Makefile b/tests/driver_at86rf2xx/Makefile index 096cb934e..170e7dfd1 100644 --- a/tests/driver_at86rf2xx/Makefile +++ b/tests/driver_at86rf2xx/Makefile @@ -39,7 +39,7 @@ ifneq (,$(DRIVER)) else USEMODULE += ng_at86rf231 # default to ng_at86rf231 endif -USEMODULE += ng_netbase +USEMODULE += ng_netif USEMODULE += ng_nomac USEMODULE += ng_pktdump USEMODULE += uart0 diff --git a/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile b/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile new file mode 100644 index 000000000..48422e909 --- /dev/null +++ b/tests/driver_at86rf2xx/auto_init_ng_netif/Makefile @@ -0,0 +1 @@ +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 new file mode 100644 index 000000000..c22194775 --- /dev/null +++ b/tests/driver_at86rf2xx/auto_init_ng_netif/netif_app.c @@ -0,0 +1,91 @@ +/* + * 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 + * + * @} + */ + +#include + +#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 6be3c879b..008b70c23 100644 --- a/tests/driver_at86rf2xx/main.c +++ b/tests/driver_at86rf2xx/main.c @@ -20,52 +20,19 @@ #include -#include "board.h" -#include "kernel.h" + #include "shell.h" #include "shell_commands.h" #include "posix_io.h" #include "board_uart0.h" -#include "ng_at86rf2xx.h" -#include "net/ng_netbase.h" -#include "net/ng_nomac.h" #include "net/ng_pktdump.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 +#include "net/ng_netbase.h" /** * @brief Buffer size used by the shell */ #define SHELL_BUFSIZE (64U) -/** - * @brief Allocate the AT86RF2xx device descriptor - */ -static ng_at86rf2xx_t dev; - -/** - * @brief Stack for the nomac thread - */ -static char nomac_stack[KERNEL_CONF_STACKSIZE_MAIN]; - /** * @brief Read chars from STDIO */ @@ -89,13 +56,10 @@ void shell_put(int c) */ int main(void) { - kernel_pid_t iface; - int res; shell_t shell; ng_netreg_entry_t dump; puts("AT86RF2xx device driver test"); - printf("Initializing the radio at SPI_%i... \n", ATRF_SPI); /* register the pktdump thread */ puts("Register the packet dump thread for NG_NETTYPE_UNDEF packets"); @@ -103,25 +67,6 @@ int main(void) dump.demux_ctx = NG_NETREG_DEMUX_CTX_ALL; ng_netreg_register(NG_NETTYPE_UNDEF, &dump); - /* initialize the AT86RF2xx device */ - puts("Initialize the AT86RF2xx radio device"); - 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 -1; - } - - /* start MAC layer */ - puts("Starting the NOMAC layer on top of the driver"); - iface = ng_nomac_init(nomac_stack, sizeof(nomac_stack), PRIORITY_MAIN - 3, - "at86rf2xx", (ng_netdev_t *)&dev); - if (iface <= KERNEL_PID_UNDEF) { - puts("Error initializing MAC layer"); - return -1; - } - /* start the shell */ puts("Initialization successful - starting the shell now"); (void) posix_open(uart0_handler_pid, 0);