1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #2983 from jfischer-phytec-iot/pr@kw2x-rf-autoinit

boards/pba-d-01-kw2x: add network interface auto init
This commit is contained in:
Johann Fischer 2015-05-20 10:00:23 +02:00
commit b0e73b9a8c
12 changed files with 240 additions and 112 deletions

View File

@ -0,0 +1,4 @@
ifneq (,$(filter ng_netif,$(USEMODULE)))
USEMODULE += kw2xrf
USEMODULE += ng_nomac
endif

View File

@ -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

View File

@ -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
*/

View File

@ -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 */
/** @} */

View File

@ -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

View File

@ -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
*/

View File

@ -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 */
}

View File

@ -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 */
/** @} */

View File

@ -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

View File

@ -1 +0,0 @@
include $(RIOTBASE)/Makefile.base

View File

@ -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;
}
}

View File

@ -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 */
/** @} */