1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

pkg/lwip: Add 6lowpan helper, do auto init for mrf24j40

This commit is contained in:
Erik Ekman 2021-08-14 18:46:17 +02:00
parent cdc8c35e13
commit fff95fc882
4 changed files with 73 additions and 23 deletions

View File

@ -27,11 +27,6 @@
#include "at86rf2xx_params.h"
#endif
#ifdef MODULE_MRF24J40
#include "mrf24j40.h"
#include "mrf24j40_params.h"
#endif
#ifdef MODULE_SOCKET_ZEP
#include "socket_zep.h"
#include "socket_zep_params.h"
@ -55,10 +50,6 @@
#define LWIP_NETIF_NUMOF ARRAY_SIZE(at86rf2xx_params)
#endif
#ifdef MODULE_MRF24J40 /* is mutual exclusive with above ifdef */
#define LWIP_NETIF_NUMOF ARRAY_SIZE(mrf24j40_params)
#endif
#ifdef MODULE_SOCKET_ZEP /* is mutual exclusive with above ifdef */
#define LWIP_NETIF_NUMOF ARRAY_SIZE(socket_zep_params)
#endif
@ -76,10 +67,6 @@ static struct netif netif[LWIP_NETIF_NUMOF];
static at86rf2xx_t at86rf2xx_devs[LWIP_NETIF_NUMOF];
#endif
#ifdef MODULE_MRF24J40
static mrf24j40_t mrf24j40_devs[LWIP_NETIF_NUMOF];
#endif
#ifdef MODULE_SOCKET_ZEP
static socket_zep_t socket_zep_devs[LWIP_NETIF_NUMOF];
#endif
@ -93,16 +80,7 @@ void lwip_bootstrap(void)
lwip_netif_init_devs();
/* TODO: do for every eligible netdev */
#ifdef LWIP_NETIF_NUMOF
#ifdef MODULE_MRF24J40
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
mrf24j40_setup(&mrf24j40_devs[i], &mrf24j40_params[i], i);
if (netif_add_noaddr(&netif[i], &mrf24j40_devs[i].netdev.netdev, lwip_netdev_init,
tcpip_6lowpan_input) == NULL) {
DEBUG("Could not add mrf24j40 device\n");
return;
}
}
#elif defined(MODULE_AT86RF2XX)
#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,

View File

@ -40,6 +40,16 @@ void lwip_netif_init_devs(void);
*/
struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state);
/**
* @brief Adds a 6LoWPAN netif using the supplied netdev.
*
* @param netif pointer to the interface to be added
* @param state pointer to the netdev for the interface
*
* The netif will be set up using the `lwip_netdev_init` helper.
*/
struct netif *lwip_add_6lowpan(struct netif *netif, netdev_t *state);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2017 Neo Nenaco <neo@nenaco.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 sys_auto_init_lwip_netif
* @{
*
* @file
* @brief Auto initialization for MRF24J40 network interfaces
*
* @author Neo Nenaco <neo@nenaco.de>
* @author Erik Ekman <eekman@google.com>
*/
#include "mrf24j40.h"
#include "mrf24j40_params.h"
#include "lwip_init_devs.h"
#define ENABLE_DEBUG 0
#include "debug.h"
#define NETIF_MRF24J40_NUMOF ARRAY_SIZE(mrf24j40_params)
static struct netif netif[NETIF_MRF24J40_NUMOF];
static mrf24j40_t mrf24j40_devs[NETIF_MRF24J40_NUMOF];
void auto_init_mrf24j40(void)
{
for (unsigned i = 0; i < NETIF_MRF24J40_NUMOF; i++) {
mrf24j40_setup(&mrf24j40_devs[i], &mrf24j40_params[i], i);
if (lwip_add_6lowpan(&netif[i], &mrf24j40_devs[i].netdev.netdev) == NULL) {
DEBUG("Could not add mrf24j40 device\n");
return;
}
}
}
/** @} */

View File

@ -17,13 +17,18 @@
#include "kernel_defines.h"
#include "lwip_init_devs.h"
#include "lwip/tcpip.h"
#include "lwip/netif/netdev.h"
#include "netif/lowpan6.h"
/**
* @brief Initializes network interfaces
*/
void lwip_netif_init_devs(void)
{
/* Ethernet interfaces
* ------------------- */
if (IS_USED(MODULE_ATWINC15X0)) {
extern void auto_init_atwinc15x0(void);
auto_init_atwinc15x0();
@ -58,6 +63,14 @@ void lwip_netif_init_devs(void)
extern void auto_init_netdev_tap(void);
auto_init_netdev_tap();
}
/* 6LoWPAN interfaces
* ------------------ */
if (IS_USED(MODULE_MRF24J40)) {
extern void auto_init_mrf24j40(void);
auto_init_mrf24j40();
}
}
struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state)
@ -70,4 +83,9 @@ struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state)
return _if;
}
struct netif *lwip_add_6lowpan(struct netif *netif, netdev_t *state)
{
return netif_add_noaddr(netif, state, lwip_netdev_init, tcpip_6lowpan_input);
}
/**@}*/