Merge pull request #2901 from kaspar030/fix_auto_init_netif
network: make auto_init_ng_netif less board-dependantdev/timer
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 */
|
||||
/** @} */
|
@ -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
|
@ -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 */
|
||||
/** @} */
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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 */
|
||||
/** @} */
|
@ -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…
Reference in New Issue