Skip to content
Snippets Groups Projects
Commit 9b664771 authored by Jonas's avatar Jonas
Browse files

adapted new auto-init process to kw2xrf driver

added kw2xrf to auto-init
parent bda9ef12
No related branches found
No related tags found
No related merge requests found
ifneq (,$(filter ng_netif,$(USEMODULE)))
USEMODULE += kw2xrf
USEMODULE += ng_nomac
endif
......@@ -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
......@@ -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
*/
......
/*
* 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 */
/** @} */
......@@ -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
......
......@@ -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
*/
......
......@@ -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 */
}
/*
* 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 */
/** @} */
......@@ -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
/*
* 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 */
/** @} */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment