diff --git a/boards/pba-d-01-kw2x/Makefile.dep b/boards/pba-d-01-kw2x/Makefile.dep new file mode 100644 index 0000000000000000000000000000000000000000..898c1b251ac5cb2338d3bcb4de3e76272a2292e6 --- /dev/null +++ b/boards/pba-d-01-kw2x/Makefile.dep @@ -0,0 +1,4 @@ +ifneq (,$(filter ng_netif,$(USEMODULE))) + USEMODULE += kw2xrf + USEMODULE += ng_nomac +endif diff --git a/boards/pba-d-01-kw2x/Makefile.include b/boards/pba-d-01-kw2x/Makefile.include index 62c9a771e82eabd960b9dcd8fd7a0dbac24c3874..5f9a9ab6b3e217747862010b5e161762bef77f79 100644 --- a/boards/pba-d-01-kw2x/Makefile.include +++ b/boards/pba-d-01-kw2x/Makefile.include @@ -49,3 +49,4 @@ endif # export board specific includes to the global includes-listing export INCLUDES += -I$(RIOTBOARD)/$(BOARD)/include +include $(RIOTBOARD)/$(BOARD)/Makefile.dep diff --git a/boards/pba-d-01-kw2x/include/board.h b/boards/pba-d-01-kw2x/include/board.h index c984a1fd364ff6c01b1cc3488de339df1e42674e..a75a97f0ae91f5efd5dea5eedc4b7b4798481d27 100644 --- a/boards/pba-d-01-kw2x/include/board.h +++ b/boards/pba-d-01-kw2x/include/board.h @@ -90,6 +90,17 @@ extern "C" */ typedef uint8_t radio_packet_length_t; +/** +@name KW2XRF configuration +@{ +*/ +#define KW2XRF_SPI (SPI_1) +#define KW2XRF_CS (GPIO_24) +#define KW2XRF_INT (GPIO_23) +#define KW2XRF_SPI_SPEED (SPI_SPEED_10MHZ) +#define KW2XRF_SHARED_SPI 0 +/** @}*/ + /** * @brief Initialize board specific hardware, including clock, LEDs and std-IO */ diff --git a/boards/pba-d-01-kw2x/include/kw2xrf_params.h b/boards/pba-d-01-kw2x/include/kw2xrf_params.h new file mode 100644 index 0000000000000000000000000000000000000000..d0b9bd8813bc18f2711083ba8c47aa413f3beacd --- /dev/null +++ b/boards/pba-d-01-kw2x/include/kw2xrf_params.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * Copyright (C) 2014 PHYTEC Messtechnik GmbH + * + * 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_pba-d-01-kw2x + * @{ + * + * @file + * @brief kw2xrf board specific configuration + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + * @author Jonas Remmert <j.remmert@phytec.de> + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef KW2XRF_PARAMS_H +#define KW2XRF_PARAMS_H + +/** + * @name KW2XRF configuration + */ +static const kw2xrf_params_t kw2xrf_params[] = + { + { + .spi = KW2XRF_SPI, + .spi_speed = KW2XRF_SPI_SPEED, + .cs_pin = KW2XRF_CS, + .int_pin = KW2XRF_INT, + }, + }; +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* KW2XRF_PARAMS_H */ +/** @} */ diff --git a/boards/pba-d-01-kw2x/include/periph_conf.h b/boards/pba-d-01-kw2x/include/periph_conf.h index ad1ca46dec892b77f2f6b6e18a5e312cb6480e3a..da3b3e1177cb0b141f457085de91c09303610821 100644 --- a/boards/pba-d-01-kw2x/include/periph_conf.h +++ b/boards/pba-d-01-kw2x/include/periph_conf.h @@ -539,16 +539,6 @@ extern "C" /** @} */ -/** - * @name Radio configuration (kw2xrf) - * @{ - */ -#define KW2XRF_SHARED_SPI 0 -#define KW2XRF_SPI SPI_1 -#define KW2XRF_SPI_SPEED SPI_SPEED_10MHZ - -/** @} */ - #ifdef __cplusplus } #endif diff --git a/drivers/include/kw2xrf.h b/drivers/include/kw2xrf.h index 61313b5b497d51fab1c56e327152866c369546ca..8b61d0983f80c7de427310b830edcb3bd4949f03 100644 --- a/drivers/include/kw2xrf.h +++ b/drivers/include/kw2xrf.h @@ -134,6 +134,16 @@ typedef struct { int kw2xrf_init(kw2xrf_t *dev, spi_t spi, spi_speed_t spi_speed, gpio_t cs_pin, gpio_t int_pin); +/** + * @brief struct holding all params needed for device initialization + */ +typedef struct kw2xrf_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 */ +} kw2xrf_params_t; + /** * @brief Reference to the KW2XRF driver interface */ diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index fc287e2e48b9e4cd8926ebd3aecadbb968333c03..e655ec5262a51a72a9271c290537b9ed2de50871 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -321,5 +321,10 @@ void auto_init(void) auto_init_xbee(); #endif +#ifdef MODULE_KW2XRF + extern void auto_init_kw2xrf(void); + auto_init_kw2xrf(); +#endif + #endif /* MODULE_AUTO_INIT_NG_NETIF */ } diff --git a/sys/auto_init/netif/auto_init_kw2xrf.c b/sys/auto_init/netif/auto_init_kw2xrf.c new file mode 100644 index 0000000000000000000000000000000000000000..a2bd4e2de1b51196ec2cbf7fa27ec33e61caebf6 --- /dev/null +++ b/sys/auto_init/netif/auto_init_kw2xrf.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * Copyright (C) 2015 PHYTEC Messtechnik GmbH + * + * 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 kw2xrf network interfaces + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + * @author Jonas Remmert <j.remmert@phytec.de> + */ + +#ifdef MODULE_KW2XRF + +#include "board.h" +#include "net/ng_nomac.h" +#include "net/ng_netbase.h" + +#include "kw2xrf.h" +#include "kw2xrf_params.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +/** + * @brief Define stack parameters for the MAC layer thread + * @{ + */ +#define KW2XRF_MAC_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT) +#define KW2XRF_MAC_PRIO (PRIORITY_MAIN - 3) + +#define KW2XRF_NUM (sizeof(kw2xrf_params)/sizeof(kw2xrf_params[0])) + +static kw2xrf_t kw2xrf_devs[KW2XRF_NUM]; +static char _nomac_stacks[KW2XRF_MAC_STACKSIZE][KW2XRF_NUM]; + +void auto_init_kw2xrf(void) +{ + for (int i = 0; i < KW2XRF_NUM; i++) { + DEBUG("Initializing KW2xrf radio at SPI_%i\n", i); + const kw2xrf_params_t *p = &kw2xrf_params[i]; + + int res = kw2xrf_init(&kw2xrf_devs[i], + p->spi, + p->spi_speed, + p->cs_pin, + p->int_pin); + + if (res < 0) { + DEBUG("Error initializing KW2xrf radio device!"); + } + else { + ng_nomac_init(_nomac_stacks[i], + KW2XRF_MAC_STACKSIZE, KW2XRF_MAC_PRIO, + "kw2xrf", (ng_netdev_t *)&kw2xrf_devs[i]); + } + } +} +#endif /* MODULE_NG_KW2XRF */ + +/** @} */ diff --git a/tests/driver_kw2xrf/Makefile b/tests/driver_kw2xrf/Makefile index 67eef65e8d7ab663050eec968db8960a5573d094..055c70367059a5d407eb7bad737d53bc700fa2d7 100644 --- a/tests/driver_kw2xrf/Makefile +++ b/tests/driver_kw2xrf/Makefile @@ -6,23 +6,23 @@ FEATURES_REQUIRED = periph_spi periph_gpio BOARD_INSUFFICIENT_RAM := stm32f0discovery ifneq (,$(filter pba-d-01-kw2x,$(BOARD))) - export KWRF_SPI ?= SPI_1 - export KWRF_CS ?= GPIO_24 - export KWRF_INT ?= GPIO_23 - export KWRF_SPI_SPEED ?= SPI_SPEED_10MHZ - export KW2XRF_SHARED_SPI ?= 0 + DRIVER ?= kw2xrf + USE_BOARD_PARAMETERS:=true endif -USEMODULE += ng_netif -USEMODULE += ng_nomac -USEMODULE += ng_pktdump -USEMODULE += uart0 -USEMODULE += shell -USEMODULE += shell_commands -USEMODULE += ps -USEMODULE += kw2xrf +ifneq (,$(DRIVER)) + USEMODULE += $(DRIVER) +else + # default to kw2xrf + USEMODULE += kw2xrf +endif -CFLAGS += -DDEVELHELP +ifneq (true,$(USE_BOARD_PARAMETERS)) + # This adds . to include path so generic kw2xrf_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 (,$(KWRF_SHARED_SPI)) CFLAGS += -DKW2XRF_SHARED_SPI=$(DKW2XRF_SHARED_SPI) @@ -42,10 +42,23 @@ endif ifneq (,$(KWRF_INT)) CFLAGS += -DKWRF_INT=$(KWRF_INT) else - CFLAGS += -DKWRF_INT=GPIO_1 # set default + CFLAGS += -DKWRF_INT=GPIO_1 # set default endif ifneq (,$(KWRF_SPI_SPEED)) CFLAGS += -DKWRF_SPI_SPEED=$(KWRF_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_kw2xrf/auto_init_ng_netif/Makefile b/tests/driver_kw2xrf/auto_init_ng_netif/Makefile deleted file mode 100644 index 48422e909a47d7cd428d10fa73825060ccc8d8c2..0000000000000000000000000000000000000000 --- a/tests/driver_kw2xrf/auto_init_ng_netif/Makefile +++ /dev/null @@ -1 +0,0 @@ -include $(RIOTBASE)/Makefile.base diff --git a/tests/driver_kw2xrf/auto_init_ng_netif/netif_app.c b/tests/driver_kw2xrf/auto_init_ng_netif/netif_app.c deleted file mode 100644 index 3ffdbd65a241015473d0c7bf56af2835213cab92..0000000000000000000000000000000000000000 --- a/tests/driver_kw2xrf/auto_init_ng_netif/netif_app.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * Copyright (C) 2015 PHYTEC Messtechnik GmbH - * - * 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 KW2xRF network device driver - * - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - * @author Jonas Remmert <j.remmert@phytec.de> - * - * @} - */ - -#include <stdio.h> - -#include "kernel.h" -#include "kw2xrf.h" -#include "net/ng_nomac.h" -#include "net/ng_netbase.h" - -/* make sure the SPI port and the needed GPIO pins are defined */ -#ifndef KWRF_SPI -#error "SPI not defined" -#endif -#ifndef KWRF_CS -#error "Chip select pin not defined" -#endif -#ifndef KWRF_INT -#error "Interrupt pin not defined" -#endif -#ifndef KWRF_SPI_SPEED -#define KWRF_SPI_SPEED (SPI_SPEED_10MHZ) -#endif - -/** - * @brief MAC layer stack configuration - * @{ - */ -#define STACKSIZE (KERNEL_CONF_STACKSIZE_MAIN) -#define PRIO (0) -/** @} */ - -/** - * @brief Allocate the KW2XRF device descriptor - */ -static kw2xrf_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 KW2XRF device */ - printf("Initializing the KW2XRF radio at SPI_%i... \n", KWRF_SPI); - res = kw2xrf_init(&dev, KWRF_SPI, KWRF_SPI_SPEED, - KWRF_CS, KWRF_INT); - if (res < 0) { - puts("Error initializing KW2XRF 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, "kw2xrf", - (ng_netdev_t *)(&dev)); - if (iface <= KERNEL_PID_UNDEF) { - puts("Error initializing MAC layer"); - return; - } - -} diff --git a/tests/driver_kw2xrf/kw2xrf_params.h b/tests/driver_kw2xrf/kw2xrf_params.h new file mode 100644 index 0000000000000000000000000000000000000000..7251fd59a012f6319338a48b362bdabad3c572ac --- /dev/null +++ b/tests/driver_kw2xrf/kw2xrf_params.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de> + * Copyright (C) 2014 PHYTEC Messtechnik GmbH + * + * 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_kw2xrf + * @brief generic kw2xrf pin config + * + * Copyright (C) 2014 PHYTEC Messtechnik GmbH + * @{ + * @file + * + * @author Kaspar Schleiser <kaspar@schleiser.de> + * @author Jonas Remmert <j.remmert@phytec.de> + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef KW2XRF_PARAMS_H +#define KW2XRF_PARAMS_H + +/** + * @brief make sure the SPI port and the needed GPIO pins are defined + * @{ + */ +#ifndef KWRF_SPI +#error "SPI not defined" +#endif +#ifndef KWRF_CS +#error "Chip select pin not defined" +#endif +#ifndef KWRF_INT +#error "Interrupt pin not defined" +#endif +#ifndef KWRF_SPI_SPEED +#define KWRF_SPI_SPEED (SPI_SPEED_10MHZ) +#endif +/**@}*/ + +/** + * @name KW2XRF configuration + */ +static const kw2xrf_params_t kw2xrf_params[] = + { + { + .spi = KWRF_SPI, + .spi_speed = KWRF_SPI_SPEED, + .cs_pin = KWRF_CS, + .int_pin = KWRF_INT, + }, + }; +/** @} */ + +#ifdef __cplusplus +} +#endif +#endif /* KW2XRF_PARAMS_H */ +/** @} */