diff --git a/sys/net/gnrc/netif/init_devs/auto_init_sx126x.c b/sys/net/gnrc/netif/init_devs/auto_init_sx126x.c new file mode 100644 index 0000000000..b680a6848d --- /dev/null +++ b/sys/net/gnrc/netif/init_devs/auto_init_sx126x.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 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. + * + */ + +/** + * @ingroup sys_auto_init_gnrc_netif + * @{ + * + * @file + * @brief Auto initialization for SX1261/2 LoRa interfaces + * + * @author Alexandre Abadie + */ + +#include + +#include "log.h" +#include "board.h" +#include "net/gnrc/netif/lorawan_base.h" +#include "net/gnrc/netif/raw.h" +#include "net/gnrc.h" + +#include "sx126x.h" +#include "sx126x_params.h" + +/** + * @brief Calculate the number of configured SX126X devices + */ +#define SX126X_NUMOF ARRAY_SIZE(sx126x_params) + +/** + * @brief Define stack parameters for the MAC layer thread + */ +#define SX126X_STACKSIZE (THREAD_STACKSIZE_DEFAULT) +#ifndef SX126X_PRIO +#define SX126X_PRIO (GNRC_NETIF_PRIO) +#endif + +/** + * @brief Allocate memory for device descriptors, stacks, and GNRC adaption + */ +static sx126x_t sx126x_devs[SX126X_NUMOF]; +static char sx126x_stacks[SX126X_NUMOF][SX126X_STACKSIZE]; +static gnrc_netif_t _netif[SX126X_NUMOF]; + +void auto_init_sx126x(void) +{ + for (unsigned i = 0; i < SX126X_NUMOF; ++i) { + LOG_DEBUG("[auto_init_netif] initializing sx126x #%u\n", i); + sx126x_setup(&sx126x_devs[i], &sx126x_params[i], i); + if (IS_USED(MODULE_GNRC_NETIF_LORAWAN)) { + /* Currently only one lora device is supported */ + assert(SX126X_NUMOF == 1); + + gnrc_netif_lorawan_create(&_netif[i], sx126x_stacks[i], + SX126X_STACKSIZE, SX126X_PRIO, + "sx126x", (netdev_t *)&sx126x_devs[i]); + } + else { + gnrc_netif_raw_create(&_netif[i], sx126x_stacks[i], + SX126X_STACKSIZE, SX126X_PRIO, + "sx126x", (netdev_t *)&sx126x_devs[i]); + } + } +} +/** @} */ diff --git a/sys/net/gnrc/netif/init_devs/init.c b/sys/net/gnrc/netif/init_devs/init.c index e164d6263c..f567120ac6 100644 --- a/sys/net/gnrc/netif/init_devs/init.c +++ b/sys/net/gnrc/netif/init_devs/init.c @@ -166,4 +166,9 @@ void gnrc_netif_init_devs(void) extern void auto_init_nrf802154(void); auto_init_nrf802154(); } + + if (IS_USED(MODULE_SX126X)) { + extern void auto_init_sx126x(void); + auto_init_sx126x(); + } }