Merge pull request #2891 from haukepetersen/ng_autoinit_netif
sys/auto_init: added mechanism for initialization of network devicesdev/timer
commit
ec018b261f
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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_samr21-xpro
|
||||
* @{
|
||||
*
|
||||
* @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 AT86RF233 radio\n");
|
||||
ng_at86rf2xx_init(&radio, NG_AT86RF233_SPI, NG_AT86RF233_SPI_CLK,
|
||||
NG_AT86RF233_CS, NG_AT86RF233_INT,
|
||||
NG_AT86RF233_SLEEP, NG_AT86RF233_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,13 @@
|
||||
# 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
|
@ -0,0 +1 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue