Skip to content

Commit

Permalink
pkg/lwip: Move at86rf2xx to netif auto init
Browse files Browse the repository at this point in the history
  • Loading branch information
yarrick committed Aug 20, 2021
1 parent fff95fc commit 1897b57
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
26 changes: 2 additions & 24 deletions pkg/lwip/contrib/lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
#include "lwip/netifapi.h"
#include "netif/lowpan6.h"

#ifdef MODULE_AT86RF2XX
#include "at86rf2xx.h"
#include "at86rf2xx_params.h"
#endif

#ifdef MODULE_SOCKET_ZEP
#include "socket_zep.h"
#include "socket_zep_params.h"
Expand All @@ -46,11 +41,7 @@
#define ENABLE_DEBUG 0
#include "debug.h"

#ifdef MODULE_AT86RF2XX
#define LWIP_NETIF_NUMOF ARRAY_SIZE(at86rf2xx_params)
#endif

#ifdef MODULE_SOCKET_ZEP /* is mutual exclusive with above ifdef */
#ifdef MODULE_SOCKET_ZEP
#define LWIP_NETIF_NUMOF ARRAY_SIZE(socket_zep_params)
#endif

Expand All @@ -63,10 +54,6 @@
static struct netif netif[LWIP_NETIF_NUMOF];
#endif

#ifdef MODULE_AT86RF2XX
static at86rf2xx_t at86rf2xx_devs[LWIP_NETIF_NUMOF];
#endif

#ifdef MODULE_SOCKET_ZEP
static socket_zep_t socket_zep_devs[LWIP_NETIF_NUMOF];
#endif
Expand All @@ -80,16 +67,7 @@ void lwip_bootstrap(void)
lwip_netif_init_devs();
/* TODO: do for every eligible netdev */
#ifdef LWIP_NETIF_NUMOF
#if defined(MODULE_AT86RF2XX)
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
at86rf2xx_setup(&at86rf2xx_devs[i], &at86rf2xx_params[i], i);
if (netif_add_noaddr(&netif[i], &at86rf2xx_devs[i].netdev.netdev, lwip_netdev_init,
tcpip_6lowpan_input) == NULL) {
DEBUG("Could not add at86rf2xx device\n");
return;
}
}
#elif defined(MODULE_SOCKET_ZEP)
#if defined(MODULE_SOCKET_ZEP)
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
socket_zep_setup(&socket_zep_devs[i], &socket_zep_params[i], i);
if (netif_add_noaddr(&netif[i], &socket_zep_devs[i].netdev.netdev, lwip_netdev_init,
Expand Down
43 changes: 43 additions & 0 deletions pkg/lwip/init_devs/auto_init_at86rf2xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 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 sys_auto_init_lwip_netif
* @{
*
* @file
* @brief Auto initialization for at86rf2xx network interfaces
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Erik Ekman <eekman@google.com>
*/

#include "at86rf2xx.h"
#include "at86rf2xx_params.h"

#include "lwip_init_devs.h"

#define ENABLE_DEBUG 0
#include "debug.h"

#define NETIF_AT86RF2XX_NUMOF ARRAY_SIZE(at86rf2xx_params)

static struct netif netif[NETIF_AT86RF2XX_NUMOF];
static at86rf2xx_t at86rf2xx_devs[NETIF_AT86RF2XX_NUMOF];

void auto_init_at86rf2xx(void)
{
for (unsigned i = 0; i < NETIF_AT86RF2XX_NUMOF; i++) {
at86rf2xx_setup(&at86rf2xx_devs[i], &at86rf2xx_params[i], i);
if (lwip_add_6lowpan(&netif[i], &at86rf2xx_devs[i].netdev.netdev) == NULL) {
DEBUG("Could not add at86rf2xx device\n");
return;
}
}
}
/** @} */
5 changes: 5 additions & 0 deletions pkg/lwip/init_devs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ void lwip_netif_init_devs(void)
/* 6LoWPAN interfaces
* ------------------ */

if (IS_USED(MODULE_AT86RF2XX)) {
extern void auto_init_at86rf2xx(void);
auto_init_at86rf2xx();
}

if (IS_USED(MODULE_MRF24J40)) {
extern void auto_init_mrf24j40(void);
auto_init_mrf24j40();
Expand Down

0 comments on commit 1897b57

Please sign in to comment.