Skip to content

Commit

Permalink
Merge pull request #16761 from benpicco/pkg/lwip/init_devs
Browse files Browse the repository at this point in the history
pkg/lwip: add auto-init for DOSE & at86rf215, cc2538_rf
  • Loading branch information
benpicco authored Aug 24, 2021
2 parents 3d0e550 + 5b83475 commit 16f7c94
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/lwip/init_devs/auto_init_at86rf215.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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 at86rf215 network interfaces
*
* @author Benjamin Valentin <[email protected]>
* @author Erik Ekman <[email protected]>
*/

#include "at86rf215.h"
#include "at86rf215_params.h"

#include "lwip_init_devs.h"

#define ENABLE_DEBUG 0
#include "debug.h"

#define USED_BANDS (IS_USED(MODULE_AT86RF215_SUBGHZ) + IS_USED(MODULE_AT86RF215_24GHZ))
#define NETIF_AT86RF215_NUMOF ARRAY_SIZE(at86rf215_params)

static struct netif netif[NETIF_AT86RF215_NUMOF * USED_BANDS];
static at86rf215_t at86rf215_devs[NETIF_AT86RF215_NUMOF * USED_BANDS];

static void auto_init_at86rf215(void)
{
unsigned i = 0;
for (unsigned j = 0; j < NETIF_AT86RF215_NUMOF;j++) {

at86rf215_t *dev_09 = NULL;
at86rf215_t *dev_24 = NULL;
struct netif *netif_09 = NULL;
struct netif *netif_24 = NULL;

if (IS_USED(MODULE_AT86RF215_SUBGHZ)) {
dev_09 = &at86rf215_devs[i];
netif_09 = &netif[i];
++i;
}

if (IS_USED(MODULE_AT86RF215_24GHZ)) {
dev_24 = &at86rf215_devs[i];
netif_24 = &netif[i];
++i;
}

at86rf215_setup(dev_09, dev_24, &at86rf215_params[j], j);

if (dev_09) {
if (lwip_add_6lowpan(netif_09, &dev_09->netdev.netdev) == NULL) {
DEBUG("Could not add sub-GHz at86rf215 device #%u\n", j);
}
}
if (dev_24) {
if (lwip_add_6lowpan(netif_24, &dev_24->netdev.netdev) == NULL) {
DEBUG("Could not add 2.4-GHz at86rf215 device #%u\n", j);
}
}
}
}

LWIP_INIT_6LOWPAN_NETIF(auto_init_at86rf215);
/** @} */
45 changes: 45 additions & 0 deletions pkg/lwip/init_devs/auto_init_cc2538_rf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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 cc2538 network interfaces
*
* @author Benjamin Valentin <[email protected]>
* @author Erik Ekman <[email protected]>
*/

#include "cc2538_rf.h"
#include "net/netdev/ieee802154_submac.h"

#include "lwip_init_devs.h"

#define ENABLE_DEBUG 0
#include "debug.h"

static struct netif netif;
static netdev_ieee802154_submac_t cc2538_rf_netdev;

static void auto_init_cc2538_rf(void)
{
netdev_register(&cc2538_rf_netdev.dev.netdev, NETDEV_CC2538, 0);
netdev_ieee802154_submac_init(&cc2538_rf_netdev);
cc2538_rf_hal_setup(&cc2538_rf_netdev.submac.dev);

cc2538_init();

if (lwip_add_6lowpan(&netif, &cc2538_rf_netdev.dev.netdev) == NULL) {
DEBUG("Could not add CC2538 device\n");
}
}

LWIP_INIT_6LOWPAN_NETIF(auto_init_cc2538_rf);
/** @} */
44 changes: 44 additions & 0 deletions pkg/lwip/init_devs/auto_init_dose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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 DOSE network interfaces
*
* @author Benjamin Valentin <[email protected]>
* @author Erik Ekman <[email protected]>
*/

#include "dose.h"
#include "dose_params.h"

#include "lwip_init_devs.h"

#define ENABLE_DEBUG 0
#include "debug.h"

#define NETIF_DOSE_NUMOF ARRAY_SIZE(dose_params)

static struct netif netif[NETIF_DOSE_NUMOF];
static dose_t dose_devs[NETIF_DOSE_NUMOF];

static void auto_init_dose(void)
{
for (unsigned i = 0; i < NETIF_DOSE_NUMOF; i++) {
dose_setup(&dose_devs[i], &dose_params[i], i);
if (lwip_add_ethernet(&netif[i], &dose_devs[i].netdev) == NULL) {
DEBUG("Could not add DOSE device #%u\n", i);
}
}
}

LWIP_INIT_ETH_NETIF(auto_init_dose);
/** @} */

0 comments on commit 16f7c94

Please sign in to comment.