Merge pull request #2901 from kaspar030/fix_auto_init_netif

network: make auto_init_ng_netif less board-dependant
dev/timer
Kaspar Schleiser 8 years ago
commit 895b629630

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

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

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

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

@ -155,6 +155,18 @@ extern const ng_netdev_driver_t xbee_driver;
int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
gpio_t sleep_pin, gpio_t status_pin);
/**
* @brief auto_init struct holding Xbee device initalization params
*/
typedef struct xbee_params {
uart_t uart; /**< UART interfaced the device is connected to */
uint32_t baudrate; /**< baudrate to use */
gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin
set to GPIO_NUMOF if not used */
gpio_t status_pin; /**< GPIO pin that is connected to the STATUS pin
set to GPIO_NUMOF if not used */
} xbee_params_t;
#ifdef __cplusplus
}
#endif

@ -1,6 +1,3 @@
ifneq (,$(filter auto_init,$(USEMODULE)))
include $(RIOTBASE)/sys/auto_init/Makefile.include
endif
ifneq (,$(filter nomac,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/net/include
endif

@ -8,4 +8,8 @@ endif
DIRS += $(AUTO_INIT_MODULES)
ifneq (,$(filter auto_init_ng_netif,$(USEMODULE)))
DIRS += netif
endif
include $(RIOTBASE)/Makefile.base

@ -1,13 +0,0 @@
# 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

@ -306,8 +306,20 @@ void auto_init(void)
DEBUG("Auto init UDP module.\n");
ng_udp_init();
#endif
/* initialize network devices */
#ifdef MODULE_AUTO_INIT_NG_NETIF
DEBUG("Auto init network interfaces.\n");
auto_init_ng_netif();
#ifdef MODULE_NG_AT86RF2XX
extern void auto_init_ng_at86rf2xx(void);
auto_init_ng_at86rf2xx();
#endif
#ifdef MODULE_XBEE
extern void auto_init_xbee(void);
auto_init_xbee();
#endif
#endif /* MODULE_AUTO_INIT_NG_NETIF */
}

@ -1 +1,3 @@
MODULE = auto_init_ng_netif
include $(RIOTBASE)/Makefile.base

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

@ -0,0 +1,71 @@
/*
* 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 XBee network interfaces
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifdef MODULE_XBEE
#include "board.h"
#include "net/ng_nomac.h"
#include "net/ng_netbase.h"
#include "xbee.h"
#include "xbee_params.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
#define XBEE_NUM (sizeof(xbee_params)/sizeof(xbee_params_t))
static xbee_t xbee_devs[XBEE_NUM];
/**
* @brief Define stack parameters for the MAC layer thread
* @{
*/
#define XBEE_MAC_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
#define XBEE_MAC_PRIO (PRIORITY_MAIN - 3)
/**
* @brief Stacks for the MAC layer threads
*/
static char _nomac_stacks[XBEE_MAC_STACKSIZE][XBEE_NUM];
void auto_init_xbee(void)
{
for (int i = 0; i < XBEE_NUM; i++) {
DEBUG("Initializing XBee radio at UART_%i\n", i);
const xbee_params_t *p = &xbee_params[i];
int res = xbee_init(&xbee_devs[i],
p->uart,
p->baudrate,
p->sleep_pin,
p->status_pin);
if (res < 0) {
DEBUG("Error initializing XBee radio device!");
}
else {
ng_nomac_init(_nomac_stacks[i],
XBEE_MAC_STACKSIZE, XBEE_MAC_PRIO, "xbee",
(ng_netdev_t *)&xbee_devs[i]);
}
}
}
#endif /* MODULE_XBEE */
/** @} */

@ -49,22 +49,6 @@ 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

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

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

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

@ -20,7 +20,6 @@
#include <stdio.h>
#include "shell.h"
#include "shell_commands.h"
#include "posix_io.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 */
/** @} */

@ -18,6 +18,7 @@ endif
USEMODULE += xbee
USEMODULE += ng_netif
USEMODULE += auto_init_ng_netif
USEMODULE += ng_nomac
USEMODULE += ng_pktdump
USEMODULE += shell
@ -30,4 +31,9 @@ else
CFLAGS += -DXBEE_UART=UART_0
endif
# add current directory to the include path. Putting it in CFLAGS will make
# it go to the beginning, before the standard includes.
# That way xbee_params.h get's included and auto configuration can pick it up.
CFLAGS += -I$(CURDIR)
include $(RIOTBASE)/Makefile.include

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

@ -1,77 +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 Xbee device initialization
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#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;
}
}

@ -0,0 +1,38 @@
/*
* 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
* @{
*
* @file
* @brief xbee driver parameters example, used by auto_init_ng_netif
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef XBEE_PARAMS_H
#define XBEE_PARAMS_H
#ifdef __cplusplus
extern "C" {
#endif
static xbee_params_t xbee_params[] = {
{ .uart = XBEE_UART,
.baudrate = 9600U,
.sleep_pin = GPIO_NUMOF,
.status_pin = GPIO_NUMOF
},
};
#ifdef __cplusplus
}
#endif
#endif /* XBEE_PARAMS_H */
/** @} */
Loading…
Cancel
Save