Skip to content

Commit

Permalink
lorawan: update LoRaMac-node and move CMakeLists.txt to the main repo
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tagunil authored and carlescufi committed Jun 18, 2021
1 parent d456684 commit 05957b6
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 23 deletions.
1 change: 0 additions & 1 deletion drivers/lora/Kconfig.sx12xx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ DT_COMPAT_SEMTECH_SX1262 := semtech,sx1262
menuconfig LORA_SX12XX
bool "Semtech SX-series driver"
select HAS_SEMTECH_RADIO_DRIVERS
select HAS_SEMTECH_LORAMAC
depends on SPI
help
Enable LoRa driver for Semtech SX12xx.
Expand Down
5 changes: 5 additions & 0 deletions drivers/lora/sx126x.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ void SX126xWakeup(void)
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)
{
LOG_DBG("Processing DIO1 interrupt");
Expand Down
22 changes: 19 additions & 3 deletions drivers/lora/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ LOG_MODULE_REGISTER(sx127x, CONFIG_LORA_LOG_LEVEL);
#define SX127xWriteBuffer SX1272WriteBuffer
#define SX127xReadBuffer SX1272ReadBuffer
#define SX127xSetRfTxPower SX1272SetRfTxPower
#define SX127xGetDio1PinState SX1272GetDio1PinState
#define SX127xInit SX1272Init
#define SX127xGetStatus SX1272GetStatus
#define SX127xSetModem SX1272SetModem
Expand Down Expand Up @@ -67,6 +68,7 @@ LOG_MODULE_REGISTER(sx127x, CONFIG_LORA_LOG_LEVEL);
#define SX127xWriteBuffer SX1276WriteBuffer
#define SX127xReadBuffer SX1276ReadBuffer
#define SX127xSetRfTxPower SX1276SetRfTxPower
#define SX127xGetDio1PinState SX1276GetDio1PinState
#define SX127xInit SX1276Init
#define SX127xGetStatus SX1276GetStatus
#define SX127xSetModem SX1276SetModem
Expand Down Expand Up @@ -160,6 +162,9 @@ struct sx127x_dio {
};

/* 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) \
{ \
DT_INST_GPIO_LABEL_BY_IDX(inst, dio_gpios, idx), \
Expand All @@ -168,7 +173,7 @@ struct sx127x_dio {
},

#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) };

Expand Down Expand Up @@ -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);
}

void SX127xWriteBuffer(uint16_t addr, uint8_t *buffer, uint8_t size)
void SX127xWriteBuffer(uint32_t addr, uint8_t *buffer, uint8_t size)
{
int ret;

Expand All @@ -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;

Expand Down Expand Up @@ -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 */
const struct Radio_s Radio = {
.Init = SX127xInit,
Expand Down
4 changes: 3 additions & 1 deletion modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ source "modules/Kconfig.eos_s3"
source "modules/Kconfig.imx"
source "modules/Kconfig.infineon"
source "modules/Kconfig.libmetal"
source "modules/Kconfig.loramac-node"
source "modules/Kconfig.mcux"
source "modules/Kconfig.microchip"
source "modules/Kconfig.nuvoton"
Expand Down Expand Up @@ -62,6 +61,9 @@ comment "Nanopb module not available."
comment "Lz4 module not available."
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
# and referencing, while keeping the settings themselves unavailable when the
# modules are not present in the workspace
Expand Down
91 changes: 91 additions & 0 deletions modules/loramac-node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 15 additions & 10 deletions modules/Kconfig.loramac-node → modules/loramac-node/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@
# SPDX-License-Identifier: Apache-2.0
#

config HAS_SEMTECH_LORAMAC
bool "Semtech LoRaMac Stack"
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 ZEPHYR_LORAMAC_NODE_MODULE
bool

config HAS_SEMTECH_RADIO_DRIVERS
bool "Semtech LoRa Radio Drivers"
Expand All @@ -31,3 +23,16 @@ config HAS_SEMTECH_SX1276
config HAS_SEMTECH_SX126X
bool
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
19 changes: 15 additions & 4 deletions subsys/lorawan/lorawan.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lw_priv.h"

#include <LoRaMac.h>
#include <Region.h>

BUILD_ASSERT(!IS_ENABLED(CONFIG_LORAMAC_REGION_UNKNOWN),
"Unknown region specified for LoRaWAN in Kconfig");
Expand Down Expand Up @@ -59,7 +60,6 @@ K_MUTEX_DEFINE(lorawan_send_mutex);
*/
static enum lorawan_datarate default_datarate;
static enum lorawan_datarate current_datarate;
static uint8_t lorawan_conf_msg_tries = 1;
static bool lorawan_adr_enable;

static sys_slist_t dl_callbacks;
Expand All @@ -75,6 +75,11 @@ static LoRaMacEventInfoStatus_t last_mlme_indication_status;
static uint8_t (*getBatteryLevelUser)(void);
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)
{
if (getBatteryLevelUser != NULL) {
Expand Down Expand Up @@ -205,6 +210,7 @@ static LoRaMacStatus_t lorawan_join_otaa(

mlme_req.Type = MLME_JOIN;
mlme_req.Req.Join.Datarate = default_datarate;
mlme_req.Req.Join.NetworkActivation = ACTIVATION_TYPE_OTAA;

mib_req.Type = MIB_DEV_EUI;
mib_req.Param.DevEui = join_cfg->dev_eui;
Expand Down Expand Up @@ -431,7 +437,13 @@ void lorawan_enable_adr(bool enable)

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;
}
Expand Down Expand Up @@ -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.fBuffer = data;
mcpsReq.Req.Confirmed.fBufferSize = len;
mcpsReq.Req.Confirmed.NbTrials = lorawan_conf_msg_tries;
mcpsReq.Req.Confirmed.Datarate = current_datarate;
} else {
/* default message type */
Expand Down Expand Up @@ -577,7 +588,7 @@ static int lorawan_init(const struct device *dev)
macPrimitives.MacMlmeIndication = MlmeIndication;
macCallbacks.GetBatteryLevel = getBatteryLevelLocal;
macCallbacks.GetTemperatureLevel = NULL;
macCallbacks.NvmContextChange = NULL;
macCallbacks.NvmDataChange = NULL;
macCallbacks.MacProcessNotify = OnMacProcessNotify;

status = LoRaMacInitialization(&macPrimitives, &macCallbacks,
Expand Down
3 changes: 0 additions & 3 deletions subsys/lorawan/lw_priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ static const char *const eventinfo2str[] = {
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = "Downlink repeated",
[LORAMAC_EVENT_INFO_STATUS_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_MIC_FAIL] = "MIC fail",
[LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = "Multicast fail",
Expand Down Expand Up @@ -131,7 +129,6 @@ static const int eventinfo2errno[] = {
[LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL] = -EINVAL,
[LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED] = -ECONNRESET,
[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_MIC_FAIL] = -EACCES,
[LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL] = -EINVAL,
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ manifest:
revision: 6010f0523cbc75f551d9256cf782f173177acdef
path: modules/lib/open-amp
- name: loramac-node
revision: 0a5dfdbc00d6c8bd1ea3acb76941521d09aa3eff
revision: 12019623bbad9eb54fe51066847a7cbd4b4eac57
path: modules/lib/loramac-node
- name: openthread
revision: f460532d4afa5d49feba241e5dc31c56123d31a8
Expand Down

0 comments on commit 05957b6

Please sign in to comment.