Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: make auto_init_ng_netif less board-dependant #2901

Merged
merged 4 commits into from
May 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions boards/iot-lab_M3/auto_init_ng_netif/netif_board.c

This file was deleted.

46 changes: 46 additions & 0 deletions boards/iot-lab_M3/include/ng_at86rf2xx_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <[email protected]>
*
* 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 <[email protected]>
*/

#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,
},
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@authmillenon Where does this store arrays in memory?

here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get's optimized out.

/** @} */

#ifdef __cplusplus
}
#endif
#endif /* NG_AT86RF2XX_PARAMS_H */
/** @} */
46 changes: 46 additions & 0 deletions boards/samr21-xpro/include/ng_at86rf2xx_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <[email protected]>
*
* 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 <[email protected]>
*/

#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 */
/** @} */
12 changes: 12 additions & 0 deletions drivers/include/ng_at86rf2xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions drivers/include/xbee.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions sys/auto_init/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ endif

DIRS += $(AUTO_INIT_MODULES)

ifneq (,$(filter auto_init_ng_netif,$(USEMODULE)))
DIRS += netif
endif

include $(RIOTBASE)/Makefile.base
13 changes: 0 additions & 13 deletions sys/auto_init/Makefile.include

This file was deleted.

16 changes: 14 additions & 2 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MODULE = auto_init_ng_netif

include $(RIOTBASE)/Makefile.base
69 changes: 69 additions & 0 deletions sys/auto_init/netif/auto_init_ng_at86rf2xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <[email protected]>
*
* 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 <[email protected]>
*/

#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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should go into the MAC implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the MAC implementation calls a driver's functions for e.g., send, receive, etc. So this is low-level driver dependent and will be different for different devices. That's why it is defined here. If defined by nomac, it would have to be a size that fits all drivers, making possible optimization impossible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, agreed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the ideal solution would be to compute this number by something like BASE_STACK + DRIVERS_STACK_NEEDS + MAC_LAYER_STACK_NEEDS, where the driver part is defined by the driver and the MAC part is defined by... you get the picture. The question is just if it is possible to define these numbers in a sensible way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... One day we need to find a procedure for finding stack sizes for all the little helper threads...

#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 */

/** @} */
71 changes: 71 additions & 0 deletions sys/auto_init/netif/auto_init_xbee.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2015 Kaspar Schleiser <[email protected]>
*
* 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 <[email protected]>
*/

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