2017-11-17 10:51:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Inria
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-06 10:32:32 +02:00
|
|
|
* @ingroup sys_auto_init_gnrc_netif
|
2017-11-17 10:51:00 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Auto initialization for SX1272/SX1276 LoRa interfaces
|
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*/
|
|
|
|
|
2020-10-21 15:58:33 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2017-11-17 10:51:00 +01:00
|
|
|
#include "log.h"
|
|
|
|
#include "board.h"
|
2019-03-07 17:13:43 +01:00
|
|
|
#include "net/gnrc/netif/lorawan_base.h"
|
2017-11-17 10:51:00 +01:00
|
|
|
#include "net/gnrc/netif/raw.h"
|
|
|
|
#include "net/gnrc.h"
|
2022-04-06 14:02:54 +02:00
|
|
|
#include "include/init_devs.h"
|
2017-11-17 10:51:00 +01:00
|
|
|
|
|
|
|
#include "sx127x.h"
|
|
|
|
#include "sx127x_params.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculate the number of configured SX127x devices
|
|
|
|
*/
|
2019-07-18 15:16:43 +02:00
|
|
|
#define SX127X_NUMOF ARRAY_SIZE(sx127x_params)
|
2017-11-17 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Define stack parameters for the MAC layer thread
|
|
|
|
*/
|
2022-04-06 14:02:54 +02:00
|
|
|
#define SX127X_STACKSIZE (GNRC_NETIF_STACKSIZE_DEFAULT)
|
2017-11-17 10:51:00 +01:00
|
|
|
#ifndef SX127X_PRIO
|
|
|
|
#define SX127X_PRIO (GNRC_NETIF_PRIO)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocate memory for device descriptors, stacks, and GNRC adaption
|
|
|
|
*/
|
|
|
|
static sx127x_t sx127x_devs[SX127X_NUMOF];
|
|
|
|
static char sx127x_stacks[SX127X_NUMOF][SX127X_STACKSIZE];
|
2019-12-19 19:23:15 +01:00
|
|
|
static gnrc_netif_t _netif[SX127X_NUMOF];
|
2017-11-17 10:51:00 +01:00
|
|
|
|
|
|
|
void auto_init_sx127x(void)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < SX127X_NUMOF; ++i) {
|
|
|
|
#if defined(MODULE_SX1272)
|
|
|
|
LOG_DEBUG("[auto_init_netif] initializing sx1272 #%u\n", i);
|
|
|
|
#else /* MODULE_SX1276 */
|
|
|
|
LOG_DEBUG("[auto_init_netif] initializing sx1276 #%u\n", i);
|
|
|
|
#endif
|
|
|
|
|
2020-12-01 11:38:17 +01:00
|
|
|
sx127x_setup(&sx127x_devs[i], &sx127x_params[i], i);
|
2020-05-05 17:45:48 +02:00
|
|
|
if (IS_USED(MODULE_GNRC_NETIF_LORAWAN)) {
|
|
|
|
/* Currently only one lora device is supported */
|
|
|
|
assert(SX127X_NUMOF == 1);
|
2019-03-07 17:13:43 +01:00
|
|
|
|
2020-05-05 17:45:48 +02:00
|
|
|
gnrc_netif_lorawan_create(&_netif[i], sx127x_stacks[i],
|
|
|
|
SX127X_STACKSIZE, SX127X_PRIO,
|
2021-06-22 15:52:45 +02:00
|
|
|
"sx127x", &sx127x_devs[i].netdev);
|
2020-05-05 17:45:48 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
gnrc_netif_raw_create(&_netif[i], sx127x_stacks[i],
|
|
|
|
SX127X_STACKSIZE, SX127X_PRIO,
|
2021-06-22 15:52:45 +02:00
|
|
|
"sx127x", &sx127x_devs[i].netdev);
|
2020-05-05 17:45:48 +02:00
|
|
|
}
|
2017-11-17 10:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/** @} */
|