mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 22:13:52 +01:00
drivers: adapt ng_at86rf2xx to new auto_init_ng_netif scheme
This commit is contained in:
parent
e655137d72
commit
3c00ff0c9b
@ -1 +0,0 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
@ -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");
|
||||
}
|
||||
46
boards/iot-lab_M3/include/ng_at86rf2xx_params.h
Normal file
46
boards/iot-lab_M3/include/ng_at86rf2xx_params.h
Normal file
@ -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 */
|
||||
/** @} */
|
||||
46
boards/samr21-xpro/include/ng_at86rf2xx_params.h
Normal file
46
boards/samr21-xpro/include/ng_at86rf2xx_params.h
Normal file
@ -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
|
||||
*
|
||||
|
||||
@ -306,4 +306,12 @@ void auto_init(void)
|
||||
DEBUG("Auto init UDP module.\n");
|
||||
ng_udp_init();
|
||||
#endif
|
||||
|
||||
|
||||
/* initialize network devices */
|
||||
|
||||
#ifdef MODULE_NG_AT86RF2XX
|
||||
extern void auto_init_ng_at86rf2xx(void);
|
||||
auto_init_ng_at86rf2xx();
|
||||
#endif
|
||||
}
|
||||
|
||||
69
sys/auto_init/netif/auto_init_ng_at86rf2xx.c
Normal file
69
sys/auto_init/netif/auto_init_ng_at86rf2xx.c
Normal file
@ -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 */
|
||||
|
||||
/** @} */
|
||||
@ -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"
|
||||
|
||||
70
tests/driver_at86rf2xx/ng_at86rf2xx_params.h
Normal file
70
tests/driver_at86rf2xx/ng_at86rf2xx_params.h
Normal file
@ -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 */
|
||||
/** @} */
|
||||
Loading…
x
Reference in New Issue
Block a user