lorawan: update LoRaMac-node and move CMakeLists.txt to the main repo

Update the LoRaMac-node library to the last stable release and fix
the Zephyr glue code to match it. Move CMakeLists.txt to the main
Zephyr repository to simplify loramac-node module maintenance.

Signed-off-by: Ilya Tagunov <tagunil@gmail.com>
This commit is contained in:
Ilya Tagunov 2021-06-03 01:54:54 +03:00 committed by Carles Cufí
commit 05957b66cb
9 changed files with 149 additions and 23 deletions

View file

@ -12,7 +12,6 @@ DT_COMPAT_SEMTECH_SX1262 := semtech,sx1262
menuconfig LORA_SX12XX menuconfig LORA_SX12XX
bool "Semtech SX-series driver" bool "Semtech SX-series driver"
select HAS_SEMTECH_RADIO_DRIVERS select HAS_SEMTECH_RADIO_DRIVERS
select HAS_SEMTECH_LORAMAC
depends on SPI depends on SPI
help help
Enable LoRa driver for Semtech SX12xx. Enable LoRa driver for Semtech SX12xx.

View file

@ -443,6 +443,11 @@ void SX126xWakeup(void)
dev_data.mode = MODE_STDBY_RC; dev_data.mode = MODE_STDBY_RC;
} }
uint32_t SX126xGetDio1PinState(void)
{
return gpio_pin_get(dev_data.dio1, GPIO_DIO1_PIN) > 0 ? 1U : 0U;
}
static void sx126x_dio1_irq_work_handler(struct k_work *work) static void sx126x_dio1_irq_work_handler(struct k_work *work)
{ {
LOG_DBG("Processing DIO1 interrupt"); LOG_DBG("Processing DIO1 interrupt");

View file

@ -31,6 +31,7 @@ LOG_MODULE_REGISTER(sx127x, CONFIG_LORA_LOG_LEVEL);
#define SX127xWriteBuffer SX1272WriteBuffer #define SX127xWriteBuffer SX1272WriteBuffer
#define SX127xReadBuffer SX1272ReadBuffer #define SX127xReadBuffer SX1272ReadBuffer
#define SX127xSetRfTxPower SX1272SetRfTxPower #define SX127xSetRfTxPower SX1272SetRfTxPower
#define SX127xGetDio1PinState SX1272GetDio1PinState
#define SX127xInit SX1272Init #define SX127xInit SX1272Init
#define SX127xGetStatus SX1272GetStatus #define SX127xGetStatus SX1272GetStatus
#define SX127xSetModem SX1272SetModem #define SX127xSetModem SX1272SetModem
@ -67,6 +68,7 @@ LOG_MODULE_REGISTER(sx127x, CONFIG_LORA_LOG_LEVEL);
#define SX127xWriteBuffer SX1276WriteBuffer #define SX127xWriteBuffer SX1276WriteBuffer
#define SX127xReadBuffer SX1276ReadBuffer #define SX127xReadBuffer SX1276ReadBuffer
#define SX127xSetRfTxPower SX1276SetRfTxPower #define SX127xSetRfTxPower SX1276SetRfTxPower
#define SX127xGetDio1PinState SX1276GetDio1PinState
#define SX127xInit SX1276Init #define SX127xInit SX1276Init
#define SX127xGetStatus SX1276GetStatus #define SX127xGetStatus SX1276GetStatus
#define SX127xSetModem SX1276SetModem #define SX127xSetModem SX1276SetModem
@ -160,6 +162,9 @@ struct sx127x_dio {
}; };
/* Helper macro that UTIL_LISTIFY can use and produces an element with comma */ /* Helper macro that UTIL_LISTIFY can use and produces an element with comma */
#define SX127X_DIO_GPIO_LEN(inst) \
DT_INST_PROP_LEN(inst, dio_gpios)
#define SX127X_DIO_GPIO_ELEM(idx, inst) \ #define SX127X_DIO_GPIO_ELEM(idx, inst) \
{ \ { \
DT_INST_GPIO_LABEL_BY_IDX(inst, dio_gpios, idx), \ DT_INST_GPIO_LABEL_BY_IDX(inst, dio_gpios, idx), \
@ -168,7 +173,7 @@ struct sx127x_dio {
}, },
#define SX127X_DIO_GPIO_INIT(n) \ #define SX127X_DIO_GPIO_INIT(n) \
UTIL_LISTIFY(DT_INST_PROP_LEN(n, dio_gpios), SX127X_DIO_GPIO_ELEM, n) UTIL_LISTIFY(SX127X_DIO_GPIO_LEN(n), SX127X_DIO_GPIO_ELEM, n)
static const struct sx127x_dio sx127x_dios[] = { SX127X_DIO_GPIO_INIT(0) }; static const struct sx127x_dio sx127x_dios[] = { SX127X_DIO_GPIO_INIT(0) };
@ -427,7 +432,7 @@ int sx127x_write(uint8_t reg_addr, uint8_t *data, uint8_t len)
return sx127x_transceive(reg_addr | BIT(7), true, data, len); return sx127x_transceive(reg_addr | BIT(7), true, data, len);
} }
void SX127xWriteBuffer(uint16_t addr, uint8_t *buffer, uint8_t size) void SX127xWriteBuffer(uint32_t addr, uint8_t *buffer, uint8_t size)
{ {
int ret; int ret;
@ -437,7 +442,7 @@ void SX127xWriteBuffer(uint16_t addr, uint8_t *buffer, uint8_t size)
} }
} }
void SX127xReadBuffer(uint16_t addr, uint8_t *buffer, uint8_t size) void SX127xReadBuffer(uint32_t addr, uint8_t *buffer, uint8_t size)
{ {
int ret; int ret;
@ -511,6 +516,17 @@ void SX127xSetRfTxPower(int8_t power)
} }
} }
uint32_t SX127xGetDio1PinState(void)
{
#if SX127X_DIO_GPIO_LEN(0) >= 2
if (gpio_pin_get(dev_data.dio_dev[1], sx127x_dios[1].pin) > 0) {
return 1U;
}
#endif
return 0U;
}
/* Initialize Radio driver callbacks */ /* Initialize Radio driver callbacks */
const struct Radio_s Radio = { const struct Radio_s Radio = {
.Init = SX127xInit, .Init = SX127xInit,

View file

@ -17,7 +17,6 @@ source "modules/Kconfig.eos_s3"
source "modules/Kconfig.imx" source "modules/Kconfig.imx"
source "modules/Kconfig.infineon" source "modules/Kconfig.infineon"
source "modules/Kconfig.libmetal" source "modules/Kconfig.libmetal"
source "modules/Kconfig.loramac-node"
source "modules/Kconfig.mcux" source "modules/Kconfig.mcux"
source "modules/Kconfig.microchip" source "modules/Kconfig.microchip"
source "modules/Kconfig.nuvoton" source "modules/Kconfig.nuvoton"
@ -62,6 +61,9 @@ comment "Nanopb module not available."
comment "Lz4 module not available." comment "Lz4 module not available."
depends on !ZEPHYR_LZ4_MODULE depends on !ZEPHYR_LZ4_MODULE
comment "loramac-node module not available."
depends on !ZEPHYR_LORAMAC_NODE_MODULE
# This ensures that symbols are available in Kconfig for dependency checking # This ensures that symbols are available in Kconfig for dependency checking
# and referencing, while keeping the settings themselves unavailable when the # and referencing, while keeping the settings themselves unavailable when the
# modules are not present in the workspace # modules are not present in the workspace

View file

@ -0,0 +1,91 @@
if(${CONFIG_HAS_SEMTECH_RADIO_DRIVERS})
set(ZEPHYR_CURRENT_LIBRARY loramac-node)
zephyr_library_include_directories(
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/boards
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/system
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio
)
zephyr_library_sources(
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/boards/mcu/utilities.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/system/systime.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/system/timer.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/system/delay.c
)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX1272
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx1272/sx1272.c
)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX1276
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx1276/sx1276.c
)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SX126X
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/sx126x.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/radio/sx126x/radio.c
)
if(${CONFIG_HAS_SEMTECH_LORAMAC})
zephyr_library_include_directories(
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region
)
endif()
zephyr_library_compile_definitions_ifdef(CONFIG_HAS_SEMTECH_SOFT_SE SOFT_SE)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_SOFT_SE
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/peripherals/soft-se/aes.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/peripherals/soft-se/cmac.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/peripherals/soft-se/soft-se.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/peripherals/soft-se/soft-se-hal.c
)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_LORAMAC
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMac.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacAdr.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacClassB.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacCommands.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacConfirmQueue.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacCrypto.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacParser.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacSerializer.c
)
zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_LORAMAC
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/Region.c
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionCommon.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_EU868
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionEU868.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_US915
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionUS915.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_CN779
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionCN779.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_EU433
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionEU433.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_AU915
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionAU915.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_AS923
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionAS923.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_CN470
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionCN470.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_KR920
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionKR920.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_IN865
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionIN865.c
)
zephyr_library_sources_ifdef(CONFIG_LORAMAC_REGION_RU864
${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/region/RegionRU864.c
)
endif()

View file

@ -4,16 +4,8 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
config HAS_SEMTECH_LORAMAC config ZEPHYR_LORAMAC_NODE_MODULE
bool "Semtech LoRaMac Stack" bool
help
This option enables the use of Semtech's LoRaMac stack
config HAS_SEMTECH_SOFT_SE
bool "Semtech Secure Element software implementation"
help
This option enables the use of Semtech's Secure Element
software implementation
config HAS_SEMTECH_RADIO_DRIVERS config HAS_SEMTECH_RADIO_DRIVERS
bool "Semtech LoRa Radio Drivers" bool "Semtech LoRa Radio Drivers"
@ -31,3 +23,16 @@ config HAS_SEMTECH_SX1276
config HAS_SEMTECH_SX126X config HAS_SEMTECH_SX126X
bool bool
depends on HAS_SEMTECH_RADIO_DRIVERS depends on HAS_SEMTECH_RADIO_DRIVERS
config HAS_SEMTECH_LORAMAC
bool "Semtech LoRaMac Stack"
depends on HAS_SEMTECH_RADIO_DRIVERS
help
This option enables the use of Semtech's LoRaMac stack
config HAS_SEMTECH_SOFT_SE
bool "Semtech Secure Element software implementation"
depends on HAS_SEMTECH_LORAMAC
help
This option enables the use of Semtech's Secure Element
software implementation

View file

@ -12,6 +12,7 @@
#include "lw_priv.h" #include "lw_priv.h"
#include <LoRaMac.h> #include <LoRaMac.h>
#include <Region.h>
BUILD_ASSERT(!IS_ENABLED(CONFIG_LORAMAC_REGION_UNKNOWN), BUILD_ASSERT(!IS_ENABLED(CONFIG_LORAMAC_REGION_UNKNOWN),
"Unknown region specified for LoRaWAN in Kconfig"); "Unknown region specified for LoRaWAN in Kconfig");
@ -59,7 +60,6 @@ K_MUTEX_DEFINE(lorawan_send_mutex);
*/ */
static enum lorawan_datarate default_datarate; static enum lorawan_datarate default_datarate;
static enum lorawan_datarate current_datarate; static enum lorawan_datarate current_datarate;
static uint8_t lorawan_conf_msg_tries = 1;
static bool lorawan_adr_enable; static bool lorawan_adr_enable;
static sys_slist_t dl_callbacks; static sys_slist_t dl_callbacks;
@ -75,6 +75,11 @@ static LoRaMacEventInfoStatus_t last_mlme_indication_status;
static uint8_t (*getBatteryLevelUser)(void); static uint8_t (*getBatteryLevelUser)(void);
static void (*dr_change_cb)(enum lorawan_datarate dr); static void (*dr_change_cb)(enum lorawan_datarate dr);
void BoardGetUniqueId(uint8_t *id)
{
/* Do not change the default value */
}
static uint8_t getBatteryLevelLocal(void) static uint8_t getBatteryLevelLocal(void)
{ {
if (getBatteryLevelUser != NULL) { if (getBatteryLevelUser != NULL) {
@ -205,6 +210,7 @@ static LoRaMacStatus_t lorawan_join_otaa(
mlme_req.Type = MLME_JOIN; mlme_req.Type = MLME_JOIN;
mlme_req.Req.Join.Datarate = default_datarate; mlme_req.Req.Join.Datarate = default_datarate;
mlme_req.Req.Join.NetworkActivation = ACTIVATION_TYPE_OTAA;
mib_req.Type = MIB_DEV_EUI; mib_req.Type = MIB_DEV_EUI;
mib_req.Param.DevEui = join_cfg->dev_eui; mib_req.Param.DevEui = join_cfg->dev_eui;
@ -431,7 +437,13 @@ void lorawan_enable_adr(bool enable)
int lorawan_set_conf_msg_tries(uint8_t tries) int lorawan_set_conf_msg_tries(uint8_t tries)
{ {
lorawan_conf_msg_tries = tries; MibRequestConfirm_t mib_req;
mib_req.Type = MIB_CHANNELS_NB_TRANS;
mib_req.Param.ChannelsNbTrans = tries;
if (LoRaMacMibSetRequestConfirm(&mib_req) != LORAMAC_STATUS_OK) {
return -EINVAL;
}
return 0; return 0;
} }
@ -473,7 +485,6 @@ int lorawan_send(uint8_t port, uint8_t *data, uint8_t len, uint8_t flags)
mcpsReq.Req.Confirmed.fPort = port; mcpsReq.Req.Confirmed.fPort = port;
mcpsReq.Req.Confirmed.fBuffer = data; mcpsReq.Req.Confirmed.fBuffer = data;
mcpsReq.Req.Confirmed.fBufferSize = len; mcpsReq.Req.Confirmed.fBufferSize = len;
mcpsReq.Req.Confirmed.NbTrials = lorawan_conf_msg_tries;
mcpsReq.Req.Confirmed.Datarate = current_datarate; mcpsReq.Req.Confirmed.Datarate = current_datarate;
} else { } else {
/* default message type */ /* default message type */
@ -577,7 +588,7 @@ static int lorawan_init(const struct device *dev)
macPrimitives.MacMlmeIndication = MlmeIndication; macPrimitives.MacMlmeIndication = MlmeIndication;
macCallbacks.GetBatteryLevel = getBatteryLevelLocal; macCallbacks.GetBatteryLevel = getBatteryLevelLocal;
macCallbacks.GetTemperatureLevel = NULL; macCallbacks.GetTemperatureLevel = NULL;
macCallbacks.NvmContextChange = NULL; macCallbacks.NvmDataChange = NULL;
macCallbacks.MacProcessNotify = OnMacProcessNotify; macCallbacks.MacProcessNotify = OnMacProcessNotify;
status = LoRaMacInitialization(&macPrimitives, &macCallbacks, status = LoRaMacInitialization(&macPrimitives, &macCallbacks,

View file

@ -61,8 +61,6 @@ static const char *const eventinfo2str[] = {
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = "Downlink repeated", [LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = "Downlink repeated",
[LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR] = [LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR] =
"Tx DR payload size error", "Tx DR payload size error",
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS] =
"Downlink too many frames loss",
[LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL] = "Address fail", [LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL] = "Address fail",
[LORAMAC_EVENT_INFO_STATUS_MIC_FAIL] = "MIC fail", [LORAMAC_EVENT_INFO_STATUS_MIC_FAIL] = "MIC fail",
[LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = "Multicast fail", [LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = "Multicast fail",
@ -131,7 +129,6 @@ static const int eventinfo2errno[] = {
[LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL] = -EINVAL, [LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL] = -EINVAL,
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = -ECONNRESET, [LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = -ECONNRESET,
[LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR] = -EMSGSIZE, [LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR] = -EMSGSIZE,
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS] = -ECONNRESET,
[LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL] = -EACCES, [LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL] = -EACCES,
[LORAMAC_EVENT_INFO_STATUS_MIC_FAIL] = -EACCES, [LORAMAC_EVENT_INFO_STATUS_MIC_FAIL] = -EACCES,
[LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = -EINVAL, [LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = -EINVAL,

View file

@ -106,7 +106,7 @@ manifest:
revision: 6010f0523cbc75f551d9256cf782f173177acdef revision: 6010f0523cbc75f551d9256cf782f173177acdef
path: modules/lib/open-amp path: modules/lib/open-amp
- name: loramac-node - name: loramac-node
revision: 0a5dfdbc00d6c8bd1ea3acb76941521d09aa3eff revision: 12019623bbad9eb54fe51066847a7cbd4b4eac57
path: modules/lib/loramac-node path: modules/lib/loramac-node
- name: openthread - name: openthread
revision: f460532d4afa5d49feba241e5dc31c56123d31a8 revision: f460532d4afa5d49feba241e5dc31c56123d31a8