From 8d052b21f39344a543c15e29d76dfab2cc9eb709 Mon Sep 17 00:00:00 2001 From: rbaquero Date: Fri, 9 Sep 2022 14:11:58 -0500 Subject: [PATCH] Release v3.2.4 --- CHANGELOG.md | 39 +- Makefile | 118 +-- README.md | 36 +- lora_basics_modem_version.h | 4 +- makefiles/common.mk | 93 ++- makefiles/cortex_m4.mk | 12 - makefiles/regions.mk | 4 +- makefiles/sx126x.mk | 9 +- smtc_modem_api/doxygen.config | 1 - smtc_modem_api/smtc_modem_api.h | 3 +- .../device_management_defs.h | 30 +- .../device_management/dm_downlink.c | 88 +- .../device_management/modem_context.c | 411 +++++---- .../device_management/modem_context.h | 64 +- smtc_modem_core/lorawan_api/lorawan_api.c | 214 +++-- smtc_modem_core/lorawan_api/lorawan_api.h | 683 +++++++-------- .../lr1mac/src/lr1_stack_mac_layer.c | 165 ++-- .../lr1mac/src/lr1_stack_mac_layer.h | 47 +- .../src/lr1mac_class_b/smtc_beacon_sniff.c | 3 +- .../lr1mac/src/lr1mac_class_b/smtc_d2d.c | 4 +- .../src/lr1mac_class_b/smtc_ping_slot.c | 18 +- .../src/lr1mac_class_c/lr1mac_class_c.c | 13 +- smtc_modem_core/lr1mac/src/lr1mac_core.c | 58 +- smtc_modem_core/lr1mac/src/lr1mac_core.h | 19 +- smtc_modem_core/lr1mac/src/lr1mac_defs.h | 72 +- .../lr1mac/src/services/smtc_lbt.c | 13 +- .../lr1mac/src/smtc_real/src/region_as_923.c | 1 - .../src/smtc_real/src/region_as_923_defs.h | 6 - .../lr1mac/src/smtc_real/src/region_au_915.c | 1 - .../src/smtc_real/src/region_au_915_defs.h | 10 +- .../lr1mac/src/smtc_real/src/region_cn_470.c | 1 - .../src/smtc_real/src/region_cn_470_defs.h | 5 - .../src/smtc_real/src/region_cn_470_rp_1_0.c | 1 - .../smtc_real/src/region_cn_470_rp_1_0_defs.h | 5 - .../lr1mac/src/smtc_real/src/region_eu_868.c | 1 - .../src/smtc_real/src/region_eu_868_defs.h | 5 - .../lr1mac/src/smtc_real/src/region_in_865.c | 1 - .../src/smtc_real/src/region_in_865_defs.h | 5 - .../lr1mac/src/smtc_real/src/region_kr_920.c | 1 - .../src/smtc_real/src/region_kr_920_defs.h | 5 - .../lr1mac/src/smtc_real/src/region_ru_864.c | 1 - .../src/smtc_real/src/region_ru_864_defs.h | 5 - .../lr1mac/src/smtc_real/src/region_us_915.c | 1 - .../src/smtc_real/src/region_us_915_defs.h | 7 +- .../lr1mac/src/smtc_real/src/region_ww2g4.c | 23 +- .../src/smtc_real/src/region_ww2g4_defs.h | 5 - .../lr1mac/src/smtc_real/src/smtc_real.c | 13 +- .../lr1mac/src/smtc_real/src/smtc_real_defs.h | 2 - .../modem_config/smtc_modem_hal_dbg_trace.h | 12 +- smtc_modem_core/modem_core/smtc_modem.c | 388 +++++++-- smtc_modem_core/modem_core/smtc_modem_test.c | 154 ++-- .../fragmentation/frag_decoder.c | 1 + .../fragmentation/fragmented_data_block.c | 2 +- .../modem_services/smtc_clock_sync.c | 34 +- .../modem_services/smtc_clock_sync.h | 2 +- .../modem_services/smtc_modem_services_hal.c | 14 +- .../modem_supervisor/modem_supervisor.c | 196 +++-- .../modem_supervisor/modem_supervisor.h | 44 +- .../radio_drivers/lr11xx_driver/CHANGELOG.md | 6 + .../radio_drivers/lr11xx_driver/LICENSE.txt | 5 +- .../lr11xx_driver/src/lr11xx_driver_version.h | 2 +- .../lr11xx_driver/src/lr11xx_radio.c | 16 +- .../lr11xx_driver/src/lr11xx_radio_types.h | 28 +- .../radio_drivers/sx126x_driver/CHANGELOG.md | 7 + .../sx126x_driver/src/lr_fhss_mac.c | 12 +- .../radio_drivers/sx126x_driver/src/sx126x.c | 13 + .../radio_drivers/sx126x_driver/src/sx126x.h | 35 + .../sx126x_driver/src/sx126x_regs.h | 14 + .../radio_planner/src/radio_planner.c | 110 +-- .../radio_planner/src/radio_planner.h | 1 + .../src/radio_planner_hook_id_defs.h | 30 +- .../radio_planner/src/radio_planner_types.h | 7 +- .../smtc_modem_crypto/smtc_modem_crypto.c | 40 + .../smtc_modem_crypto/smtc_modem_crypto.h | 12 + .../src/file_upload/file_upload.c | 9 +- smtc_modem_core/smtc_ral/src/ral_defs.h | 15 +- smtc_modem_core/smtc_ral/src/ral_lr11xx.c | 76 +- utilities/Makefile | 30 +- utilities/makefiles/board_L476.mk | 4 +- utilities/makefiles/common.mk | 10 +- utilities/makefiles/lr11xx.mk | 3 +- utilities/makefiles/sx126x.mk | 8 + .../mcu_drivers/core/stm32l476rgtx_flash.ld | 26 +- .../user_app/radio_hal/lr11xx_pa_pwr_cfg.c | 777 ------------------ .../user_app/radio_hal/lr11xx_pa_pwr_cfg.h | 666 +++++++++++++++ utilities/user_app/radio_hal/ral_lr11xx_bsp.c | 306 ++++--- utilities/user_app/radio_hal/ral_sx126x_bsp.c | 28 +- .../radio_hal/smtc_board_pa_pwr_cfg.h | 97 --- .../user_app/smtc_hal_l4/smtc_hal_dbg_trace.h | 2 +- utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c | 25 +- 90 files changed, 3179 insertions(+), 2414 deletions(-) delete mode 100644 makefiles/cortex_m4.mk delete mode 100644 utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.c create mode 100644 utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.h delete mode 100644 utilities/user_app/radio_hal/smtc_board_pa_pwr_cfg.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 1042070..c6fb7f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,43 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v3.2.4] 2022-08-23 + +### Added + +* AS923 group 4 Regional Parameters +* WW2G4 Regional Parameters for LoRaWAN protocol emulation +* Support of sx128x radio + +### Changed + +* [lr11xx_driver] Update to version `v2.1.1` +* [sx126x_driver] Update to version `v2.1.0` +* [makefile] remove ARM Cortex option from makefile to make LoRa Basics Modem completely agnostic from the MCU. Makefile shall be called with a new MCU_FLAGS option containing all core options +* [makefile] Align built target directory with crypto compilation options +* [utility/example] Update PA configuration process in `ral_lr11xx_bsp_get_tx_cfg` function. +* [utility/example] Update `stm32l476rgtx_flash.ld` files to fix stack start and stop address +* [utility/example] Remove `ral_lr11xx_bsp_get_rssi_calibration_table` workaround as the lr11xx driver was fixed +* [utility/example] Fix `hal_rtc_get_time_ms` so that it returns a full range value +* Clock Sync Service with ALC Sync source can generate events: + * SMTC_MODEM_EVENT_TIME_VALID_BUT_NOT_SYNC +* Clock Sync Service with DeviceTimeReq source can generate events: + * SMTC_MODEM_EVENT_TIME_VALID_BUT_NOT_SYNC + * SMTC_MODEM_EVENT_TIME_NOT_VALID + +### Fixed + +* [LFU] LoRa Basics Modem now rejects properly files with a size between 8181 and 8192 bytes +* [LFU] Fix issue regarding encryption of files with size higher than 4080 bytes +* [RP] Fix issue on radio interruption timestamp +* [LBT] On lr11xx targets, correct outdated LBT pre-hook issue +* [LBT] Remove log print when uplinking on fsk to avoid adding delay on scheduled tasks +* [LBT] Moved log print after enqueued the sniffing task in Radio Planer to avoid to add a delays +* [ADR] In case a MAC command `link_adr_req` with a new channel mask is received, it is now accepted if the custom datarate profile is enabled and configured with the highest datarate of the corresponding region +* [LFU/Stream] In case of reception of rejoin request from DAS, reset LFU and stream services properly +*[ClockSyncService/MAC] Fixed an issue where the Clock Synchronization Service was not reloaded when DeviceTimeAns was not received +*[DeviceTimeReq/MAC] Fixed an issue where the GPS epoch time became invalid if DeviceTimeAns not received + ## [v3.1.7] 2022-04-22 ### Added @@ -31,7 +68,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), * `smtc_modem_set_crystal_error` renamed to `smtc_modem_set_crystal_error_ppm` and now takes real ppm (previously was ppt) * `smtc_modem_get_stack_state`: Added a new stack state `SMTC_MODEM_STACK_STATE_TX_WAIT` when stack is between retransmissions * `smtc_modem_time_trigger_sync_request` function does not take `sync_service` parameter anymore, now it will use the current enabled time synchronization service -* [smtc_modem_hal]: +* [smtc_modem_hal]: * `smtc_modem_hal_irq_is_radio_irq_pending()` function has been replaced with `smtc_modem_hal_radio_irq_clear_pending()`. Now modem only asks to clear radio pending irq * LR1110 driver was renamed to LR11xx driver and now also supports LR1120 radio * Updated to latest version of SX126x and LR11xx driver diff --git a/Makefile b/Makefile index 76b975f..37f8bec 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,7 @@ TARGET_ROOT = basic_modem BYPASS=no -PERF_TEST=no - -# Crypto management -CRYPTO ?= SOFT +PERF_TEST?=no # Compile with coverage analysis support COVERAGE ?= no @@ -35,6 +32,34 @@ LOG_MEM ?= yes # Tranceiver RADIO ?= nc +#MCU - Must be provided by user +MCU_FLAGS =? nc + +#----------------------------------------------------------------------------- +# Internal LBM features management +#----------------------------------------------------------------------------- + +# Middleware advanced access +MIDDLEWARE?= no + +# Crypto management +CRYPTO ?= SOFT + +# D2D feature +ADD_D2D ?= no + +# Multicast feature +ADD_MULTICAST ?= yes + +# Stream feature +ADD_SMTC_STREAM ?= yes + +# File Upload feature +ADD_SMTC_FILE_UPLOAD ?= yes + +# ALCSYNC feature +ADD_SMTC_ALC_SYNC ?= yes + # Trace prints MODEM_TRACE ?= yes MODEM_DEEP_TRACE ?= no @@ -42,60 +67,50 @@ MODEM_DEEP_TRACE ?= no # GNSS USE_GNSS ?= yes -# TB bypass -BYPASS_JOIN_DUTY_CYCLE?= no - -# Middleware advanced access -MIDDLEWARE?= no - -ifeq ($(MODEM_APP),HW_MODEM) -override BYPASS_JOIN_DUTY_CYCLE = yes -endif #----------------------------------------------------------------------------- # default action: print help #----------------------------------------------------------------------------- help: - $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 sx1261 sx1262") + $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 sx1261 sx1262 sx1268") $(call echo_help, "") $(call echo_help_b, "-------------------------------- Clean -------------------------------------") - $(call echo_help, " * make clean_ : clean basic_modem for a given target") - $(call echo_help, " * make clean_all : clean all") + $(call echo_help, " * make clean_ : clean basic_modem for a given target") + $(call echo_help, " * make clean_all : clean all") $(call echo_help, "") $(call echo_help_b, "----------------------------- Compilation ----------------------------------") - $(call echo_help, " * make basic_modem_ : build basic_modem on a given target") - $(call echo_help, " * make all : build all targets") + $(call echo_help, " * make basic_modem_ MCU_FLAGS=xxx : build basic_modem on a given target with chosen mcu flags") + $(call echo_help, " * MCU_FLAGS are mandatory. Ex for stm32l4:") + $(call echo_help, " * MCU_FLAGS=\"-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard\"") $(call echo_help, "") $(call echo_help_b, "---------------------- Optional build parameters ---------------------------") - $(call echo_help, " * REGION=xxx : choose which region should be compiled (default: all)") - $(call echo_help, " * Combinations also work (i.e. REGION=EU_868,US_915 )") - $(call echo_help, " * - AS_923") - $(call echo_help, " * - AU_915") - $(call echo_help, " * - CN_470") - $(call echo_help, " * - CN_470_RP_1_0") - $(call echo_help, " * - EU_868") - $(call echo_help, " * - IN_865") - $(call echo_help, " * - KR_920") - $(call echo_help, " * - RU_864") - $(call echo_help, " * - US_915") - $(call echo_help, " * - WW_2G4 (to be used only for lr1120 and sx128x targets)") - $(call echo_help, " * RP_VERSION=xxx : choose wich regional paramerter version should be compiled (default: RP2_101) ") - $(call echo_help, " * - RP2_101") - $(call echo_help, " * - RP2_103 (LR-FHSS support)") - $(call echo_help, " * CRYPTO=xxx : choose which crypto should be compiled (default: SOFT)") - $(call echo_help, " * - SOFT") - $(call echo_help, " * - LR11XX (only for lr1110 and lr1120 targets)") - $(call echo_help, " * - LR11XX_WITH_CREDENTIALS (only for lr1110 and lr1120 targets)") - $(call echo_help, " * MODEM_TRACE=yes/no : choose to enable or disable modem trace print (default: trace is ON)") - $(call echo_help, " * USE_GNSS=yes/no : only for lr1110 and lr1120 targets: choose to enable or disable use of gnss (default: gnss is ON)") - $(call echo_help, " * MIDDLEWARE=yes : build target for middleware advanced access") + $(call echo_help, " * REGION=xxx : choose which region should be compiled (default: all)") + $(call echo_help, " * Combinations also work (i.e. REGION=EU_868,US_915 )") + $(call echo_help, " * - AS_923") + $(call echo_help, " * - AU_915") + $(call echo_help, " * - CN_470") + $(call echo_help, " * - CN_470_RP_1_0") + $(call echo_help, " * - EU_868") + $(call echo_help, " * - IN_865") + $(call echo_help, " * - KR_920") + $(call echo_help, " * - RU_864") + $(call echo_help, " * - US_915") + $(call echo_help, " * - WW_2G4 (to be used only for lr1120 and sx128x targets)") + $(call echo_help, " * RP_VERSION=xxx : choose wich regional paramerter version should be compiled (default: RP2_101) ") + $(call echo_help, " * - RP2_101") + $(call echo_help, " * - RP2_103 (LR-FHSS support)") + $(call echo_help, " * CRYPTO=xxx : choose which crypto should be compiled (default: SOFT)") + $(call echo_help, " * - SOFT") + $(call echo_help, " * - LR11XX (only for lr1110 and lr1120 targets)") + $(call echo_help, " * - LR11XX_WITH_CREDENTIALS (only for lr1110 and lr1120 targets)") + $(call echo_help, " * MODEM_TRACE=yes/no : choose to enable or disable modem trace print (default: yes)") + $(call echo_help, " * USE_GNSS=yes/no : only for lr1110 and lr1120 targets: choose to enable or disable use of gnss (default: yes)") + $(call echo_help, " * MIDDLEWARE=yes/no : build target for middleware advanced access (default: no)") $(call echo_help_b, "-------------------- Optional makefile parameters --------------------------") - $(call echo_help, " * MULTITHREAD=no : Disable multithreaded build") - $(call echo_help, " * COVERAGE=xxx : build target with coverage instrumentation for specific subsystems:") - $(call echo_help, " * - RADIO") - $(call echo_help, " * - MODEM") - $(call echo_help, " * VERBOSE=yes : Increase build verbosity") - $(call echo_help, " * SIZE=yes : Display size for all objects") + $(call echo_help, " * DEBUG=yes/no : Change opt to O0 and add -g* options for debugging (default: no)") + $(call echo_help, " * MULTITHREAD=yes/no : Multithreaded build (default: yes)") + $(call echo_help, " * VERBOSE=yes/no : Increase build verbosity (default: no)") + $(call echo_help, " * SIZE=yes/no : Display size for all objects (default: no)") @@ -118,6 +133,10 @@ ifeq ($(RADIO),sx1262) -include makefiles/sx126x.mk endif +ifeq ($(RADIO),sx1268) +-include makefiles/sx126x.mk +endif + ifeq ($(RADIO),sx128x) -include makefiles/sx128x.mk endif @@ -125,7 +144,7 @@ endif #----------------------------------------------------------------------------- -include makefiles/common.mk -.PHONY: clean_all all help +.PHONY: clean_all all help .PHONY: FORCE FORCE: @@ -152,6 +171,9 @@ clean_sx1261: clean_sx1262: $(MAKE) clean_target RADIO=sx1262 +clean_sx1268: + $(MAKE) clean_target RADIO=sx1268 + #----------------------------------------------------------------------------- # Compilation #----------------------------------------------------------------------------- @@ -170,3 +192,5 @@ basic_modem_sx1261: basic_modem_sx1262: $(MAKE) basic_modem RADIO=sx1262 $(MTHREAD_FLAG) +basic_modem_sx1268: + $(MAKE) basic_modem RADIO=sx1268 $(MTHREAD_FLAG) diff --git a/README.md b/README.md index fc84e07..9f8ae55 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ LoRa Basics Modem supports the following LoRaWAN regions: * RU_864 * US_915 +LoRa Basics Modem supports an emulation of LoRaWAN protocol for the 2.4GHz global ISM band (WW2G4) + ### LoRaWAN regional parameters Default regional parameters version supported by LoRa Basics Modem is rp2-1.0.1. It is possible to switch to rp2-1.0.3 at compile time. @@ -60,42 +62,26 @@ The Hardware Abstraction Layer of LoRa Basics Modem is defined in the `smtc_mode LoRa Basics Modem supports the following transceivers: * LR1110 with firmware 0x0307. +* LR1120 with firmware 0x0101 * SX1261 * SX1262 +* SX1280 +* SX1281 ## Known Limitations -* [LFU] In case LoRa Basics Modem is acting in US915 region with datarate DR0, files smaller than 13 bytes are not properly sent and cannot be econstructed on LoRa Cloud side -* [LFU] LoRa Basics Modem does not reject files with a size between 8181 and 8192 bytes while they cannot be sent properly -* [LFU] Enabling encryption on a file with a size larger than 4080 bytes will prevent this file from being properly decrypted. Recommendation is to not use encryption for files with a size larger than 4080 bytes. +* [LFU] In case LoRa Basics Modem is acting in US915 region with datarate DR0, files smaller than 13 bytes are not properly sent and cannot be reconstructed on LoRa Cloud side * [charge] Values returned by `smtc_modem_get_charge()` for regions CN470 and CN470_RP1 are not accurate * [charge] Values returned by `smtc_modem_get_charge()` for the LR-FHSS based datarate are not accurate -* [LBT] On LR1110 target, sometimes the LBT pre-hook can be outdated and aborted which leads to no uplink issued (this is due to a radio reset called before starting LBT operation which adds the LR1110 boot delay before any LBT actions) - as workaround, the call to `ral_init()` can be removed from `smtc_modem_core/lr1mac/src/services/smtc_lbt.c` -* [ADR] When a MAC command `link_adr_req` with a new channel mask is received, it is rejected if the custom datarate profile is enabled and configured with the highest datarate of the corresponding region - as a workaround, make sure there is at least one datarate different from the highest possible one in the custom ADR list - -In [the simple application example](/utilities/user_app/), the implementation of [smtc_modem_hal_get_time_in_ms](/utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c) does not cover the full scale of the 32-bit counter and will wrap earlier than expected. As a consequence, LoRa Basics Modem may reset after the wrapping time around 4.9 days. Find below a correct implementation: - -```c -uint32_t hal_rtc_get_time_ms( void ) -{ - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; - - seconds = rtc_get_calendar_time( &milliseconds_div_10 ); - - return seconds * 1000 + ( milliseconds_div_10 / 10 ); -} -``` - -This workaround requires the following modification to be applied in the radio planner source code - [radio_planner.c, line 423](/smtc_modem_core/radio_planner/src/radio_planner.c): - -rp->irq_timestamp_ms[rp->radio_task_id] = rp_hal_get_time_in_ms( ); +* [multicast_class_b] Starting a class B multicast session with frequency equal to 0 will always return SMTC_MODEM_RC_INVALID even in the case lbm is acting in regions with frequency hopping beacon +* [LBT] In case LBT is used (by user's choice or imposed by regional parameters) and if TCXO start time is greater than default RP_MARGIN_DELAY value (8ms), uplinks will never be sent. + Workaround: At makefile level define RP_MARGIN_DELAY value to `TCXO start time + 3ms`. The consequence is that before rx1 and rx2 windows opening the mcu will be running and waiting during extra time. ## Disclaimer -This software has been extensively tested when targeting LR1110 / SX1261 / SX1262 for LoRaWAN regions mentioned in [this paragraph](#lorawan-region). For all other combinations of features this software shall be considered an Engineering Sample. +This software has been extensively tested when targeting LR1110 / LR1120 / SX1261 / SX1262 / SX1280 / SX1281 for LoRaWAN regions mentioned in [this paragraph](#lorawan-region). For all other combinations of features this software shall be considered an Engineering Sample. -All customers wanting to leverage LoRa Basics Modem for 2.4GHz running with SX1280 transceiver must still refer to the [release v1.0.1](https://github.com/lorabasics/lorabasicsmodem/releases/tag/v1.0.1) for which Semtech provides technical customer support. +Modem trace prints can only be used for debug purpose and shall be deactivated for production release. ### Disclaimer for Engineering Samples diff --git a/lora_basics_modem_version.h b/lora_basics_modem_version.h index 85f9d43..7fd50ff 100644 --- a/lora_basics_modem_version.h +++ b/lora_basics_modem_version.h @@ -56,8 +56,8 @@ extern "C" { * --- PUBLIC TYPES ------------------------------------------------------------ */ #define LORA_BASICS_MODEM_FW_VERSION_MAJOR 3 -#define LORA_BASICS_MODEM_FW_VERSION_MINOR 1 -#define LORA_BASICS_MODEM_FW_VERSION_PATCH 7 +#define LORA_BASICS_MODEM_FW_VERSION_MINOR 2 +#define LORA_BASICS_MODEM_FW_VERSION_PATCH 4 /* * ----------------------------------------------------------------------------- diff --git a/makefiles/common.mk b/makefiles/common.mk index 0fc0770..15bb2c5 100644 --- a/makefiles/common.mk +++ b/makefiles/common.mk @@ -79,26 +79,31 @@ endif ifeq ($(RADIO),lr1110) ifeq ($(CRYPTO),LR11XX) -TARGET_MODEM := $(TARGET_MODEM)_hw_crypto -BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_hw_crypto +TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto +BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto endif # LR11XX ifeq ($(CRYPTO),LR11XX_WITH_CREDENTIALS) -TARGET_MODEM := $(TARGET_MODEM)_hw_crypto -BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_hw_crypto +TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto_with_cred +BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto_with_cred endif # LR11XX_WITH_CREDENTIALS endif # lr1110 ifeq ($(RADIO),lr1120) ifeq ($(CRYPTO),LR11XX) -TARGET_MODEM := $(TARGET_MODEM)_hw_crypto -BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_hw_crypto +TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto +BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto endif # LR11XX ifeq ($(CRYPTO),LR11XX_WITH_CREDENTIALS) -TARGET_MODEM := $(TARGET_MODEM)_hw_crypto -BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_hw_crypto +TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto_with_cred +BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto_with_cred endif # LR11XX_WITH_CREDENTIALS endif # lr1120 +ifeq ($(MIDDLEWARE),yes) +TARGET_MODEM := $(TARGET_MODEM)_middleware +BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_middleware +endif + ifeq ($(MODEM_TRACE), yes) TARGET_MODEM := $(TARGET_MODEM)_trace BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)/trace @@ -229,11 +234,6 @@ COMMON_C_DEFS += \ -DPERF_TEST_ENABLED endif -ifeq ($(BYPASS_JOIN_DUTY_CYCLE),yes) -COMMON_C_DEFS += \ - -DTEST_BYPASS_JOIN_DUTY_CYCLE -endif - ifeq ($(MIDDLEWARE),yes) COMMON_C_DEFS += \ -DTASK_EXTENDED_1 \ @@ -241,7 +241,33 @@ COMMON_C_DEFS += \ -DENABLE_FAST_CLOCK_SYNC endif -CFLAGS += -fno-builtin $(MCU) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)" +ifeq ($(ADD_D2D),yes) +COMMON_C_DEFS += \ + -DSMTC_D2D +endif + +ifeq ($(ADD_MULTICAST),yes) +COMMON_C_DEFS += \ + -DSMTC_MULTICAST +endif + +ifeq ($(ADD_SMTC_STREAM),yes) +COMMON_C_DEFS += \ + -DADD_SMTC_STREAM +endif + +ifeq ($(ADD_SMTC_FILE_UPLOAD),yes) +COMMON_C_DEFS += \ + -DADD_SMTC_FILE_UPLOAD +endif + +ifeq ($(ADD_SMTC_ALC_SYNC),yes) +COMMON_C_DEFS += \ + -DADD_SMTC_ALC_SYNC +endif + + +CFLAGS += -fno-builtin $(MCU_FLAGS) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)" CFLAGS += -falign-functions=4 CFLAGS += -std=c17 @@ -266,29 +292,52 @@ SMTC_MODEM_CORE_C_SOURCES += \ smtc_modem_core/modem_services/fifo_ctrl.c\ smtc_modem_core/modem_services/modem_utilities.c \ smtc_modem_core/modem_services/smtc_modem_services_hal.c\ - smtc_modem_core/modem_services/smtc_clock_sync.c\ smtc_modem_core/modem_services/lorawan_certification.c\ smtc_modem_core/modem_supervisor/modem_supervisor.c +ifeq ($(ADD_SMTC_ALC_SYNC),yes) +SMTC_MODEM_CORE_C_SOURCES += \ + smtc_modem_core/modem_services/smtc_clock_sync.c +endif + +ifeq ($(ADD_SMTC_STREAM),yes) SMTC_MODEM_SERVICES_C_SOURCES += \ smtc_modem_core/smtc_modem_services/src/stream/stream.c\ - smtc_modem_core/smtc_modem_services/src/stream/rose.c\ - smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c\ - smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c\ + smtc_modem_core/smtc_modem_services/src/stream/rose.c +endif + +ifeq ($(ADD_SMTC_FILE_UPLOAD),yes) +SMTC_MODEM_SERVICES_C_SOURCES += \ + smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c +endif + +ifeq ($(ADD_SMTC_ALC_SYNC),yes) +SMTC_MODEM_SERVICES_C_SOURCES += \ + smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c +endif + LR1MAC_C_SOURCES += \ smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c\ smtc_modem_core/lr1mac/src/lr1mac_core.c\ smtc_modem_core/lr1mac/src/lr1mac_utilities.c\ smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c\ - smtc_modem_core/lr1mac/src/services/smtc_d2d.c\ smtc_modem_core/lr1mac/src/services/smtc_duty_cycle.c\ smtc_modem_core/lr1mac/src/services/smtc_lbt.c\ - smtc_modem_core/lr1mac/src/services/smtc_multicast.c\ smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c\ smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c\ smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c +ifeq ($(ADD_D2D),yes) +LR1MAC_C_SOURCES += \ + smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c +endif + +ifeq ($(ADD_MULTICAST),yes) +LR1MAC_C_SOURCES += \ + smtc_modem_core/lr1mac/src/services/smtc_multicast.c +endif + SMTC_MODEM_CRYPTO_C_SOURCES += \ smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.c @@ -326,6 +375,8 @@ COMMON_C_INCLUDES += \ -Ismtc_modem_core/lr1mac/src/smtc_real/src\ -Ismtc_modem_hal + + #----------------------------------------------------------------------------- # Gather everything #----------------------------------------------------------------------------- @@ -378,7 +429,7 @@ vpath %.cpp $(sort $(dir $(CPP_SOURCES))) #----------------------------------------------------------------------------- basic_modem: ifeq ($(RADIO),nc) - $(call echo_error,"No radio selected! Please specified the target radio using RADIO=sx128x or RADIO=sx1261 or RADIO=sx1262 or RADIO=lr1110") + $(call echo_error,"No radio selected! Please specified the target radio using RADIO=radio_name option") else $(MAKE) basic_modem_build endif diff --git a/makefiles/cortex_m4.mk b/makefiles/cortex_m4.mk deleted file mode 100644 index ccc28ed..0000000 --- a/makefiles/cortex_m4.mk +++ /dev/null @@ -1,12 +0,0 @@ -#----------------------------------------------------------------------------- -# Compilation flags -#----------------------------------------------------------------------------- - -# Default MCU compilation flags -CPU = -mcpu=cortex-m4 -FPU = -mfpu=fpv4-sp-d16 -FLOAT-ABI = -mfloat-abi=hard - -# If MCU is defined in caller Makefile, use it instead -MCU ?= $(CPU) -mthumb $(FPU) $(FLOAT-ABI) - diff --git a/makefiles/regions.mk b/makefiles/regions.mk index c2c4fd4..b4db64e 100644 --- a/makefiles/regions.mk +++ b/makefiles/regions.mk @@ -129,7 +129,9 @@ MODEM_C_DEFS += -DREGION_US_915 endif ifeq ($(REGION_WW_2G4), yes) LR1MAC_C_SOURCES += smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c -MODEM_C_DEFS += -DREGION_WW2G4 +MODEM_C_DEFS += \ + -DREGION_WW2G4\ + -DWW2G4_SINGLE_DATARATE endif diff --git a/makefiles/sx126x.mk b/makefiles/sx126x.mk index 0a5a111..a82cd46 100644 --- a/makefiles/sx126x.mk +++ b/makefiles/sx126x.mk @@ -7,7 +7,9 @@ endif ifeq ($(RADIO),sx1262) TARGET = sx1262 endif - +ifeq ($(RADIO),sx1268) +TARGET = sx1268 +endif RADIO_DRIVER_C_SOURCES += \ smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.c\ @@ -46,3 +48,8 @@ ifeq ($(RADIO),sx1262) MODEM_C_DEFS += \ -DSX1262 endif + +ifeq ($(RADIO),sx1268) +MODEM_C_DEFS += \ + -DSX1268 +endif diff --git a/smtc_modem_api/doxygen.config b/smtc_modem_api/doxygen.config index 059473e..85fc6dc 100644 --- a/smtc_modem_api/doxygen.config +++ b/smtc_modem_api/doxygen.config @@ -2492,4 +2492,3 @@ GENERATE_LEGEND = YES # This tag requires that the tag HAVE_DOT is set to YES. DOT_CLEANUP = YES - diff --git a/smtc_modem_api/smtc_modem_api.h b/smtc_modem_api/smtc_modem_api.h index f392b50..c092b91 100644 --- a/smtc_modem_api/smtc_modem_api.h +++ b/smtc_modem_api/smtc_modem_api.h @@ -269,6 +269,7 @@ typedef enum smtc_modem_region_e SMTC_MODEM_REGION_KR_920 = 10, SMTC_MODEM_REGION_RU_864 = 11, SMTC_MODEM_REGION_CN_470_RP_1_0 = 12, + SMTC_MODEM_REGION_AS_923_GRP4 = 13, } smtc_modem_region_t; /** @@ -1456,7 +1457,7 @@ smtc_modem_return_code_t smtc_modem_request_empty_uplink( uint8_t stack_id, bool * * @return Modem return code as defined in @ref smtc_modem_return_code_t * @retval SMTC_MODEM_RC_OK Command executed without errors - * @retval SMTC_MODEM_RC_INVALID \p file_length is equal to 0 or greater than 8192 bytes, or \p file is NULL + * @retval SMTC_MODEM_RC_INVALID \p file_length is equal to 0 or greater than 8180 bytes, or \p file is NULL * @retval SMTC_MODEM_RC_BUSY Modem is currently in test mode, or a file upload is already ongoing * @retval SMTC_MODEM_RC_INVALID_STACK_ID Invalid \p stack_id */ diff --git a/smtc_modem_core/device_management/device_management_defs.h b/smtc_modem_core/device_management/device_management_defs.h index 6529148..d6b9186 100644 --- a/smtc_modem_core/device_management/device_management_defs.h +++ b/smtc_modem_core/device_management/device_management_defs.h @@ -67,18 +67,24 @@ extern "C" { */ typedef enum dm_opcode_e { - DM_RESET = 0x00, //!< reset modem or application MCU - DM_FUOTA = 0x01, //!< FUOTA firmware update chunk - DM_FILE_DONE = 0x02, //!< file upload complete + DM_RESET = 0x00, //!< reset modem or application MCU + DM_FUOTA = 0x01, //!< FUOTA firmware update chunk +#if defined( ADD_SMTC_FILE_UPLOAD ) + DM_FILE_DONE = 0x02, //!< file upload complete +#endif // ADD_SMTC_FILE_UPLOAD DM_GET_INFO = 0x03, //!< get info fields DM_SET_CONF = 0x04, //!< set config field DM_REJOIN = 0x05, //!< rejoin network DM_MUTE = 0x06, //!< permanently disable/enable modem DM_SET_DM_INFO = 0x07, //!< set list of default info fields - DM_STREAM = 0x08, //!< set data stream parameters - DM_ALC_SYNC = 0x09, //!< application layer clock sync data - DM_ALM_UPDATE = 0x0A, //!< almanac update, short, long, full updates - DM_ALM_DBG = 0x0B, //!< almanac debug +#if defined( ADD_SMTC_STREAM ) + DM_STREAM = 0x08, //!< set data stream parameters +#endif // ADD_SMTC_STREAM + DM_ALC_SYNC = 0x09, //!< application layer clock sync data + DM_ALM_UPDATE = 0x0A, //!< almanac update, short, long, full updates +#if !defined( DISABLE_ALMANAC_DBG_OPCODE ) + DM_ALM_DBG = 0x0B, //!< almanac debug +#endif // !DISABLE_ALMANAC_DBG_OPCODE DM_SOLV_UPDATE = 0x0C, //!< assistance position, xtal update DM_ALM_FUPDATE = 0x0D, //!< Force almanac update, short, long, full updates DM_CMD_MAX //!< number of elements @@ -225,6 +231,7 @@ typedef enum modem_upload_state_e MODEM_UPLOAD_FINISHED //!< The upload process is finished } modem_upload_state_t; +#if defined( ADD_SMTC_STREAM ) /** * @brief Modem stream state * @@ -236,6 +243,7 @@ typedef enum modem_stream_status_e MODEM_STREAM_INIT, MODEM_STREAM_DATA_PENDING, } modem_stream_status_t; +#endif // ADD_SMTC_STREAM /** * @brief RF Output definition @@ -259,11 +267,11 @@ typedef enum modem_status_offset_e { MODEM_STATUS_OFFSET_BROWNOUT = 0, //!< reset after brownout MODEM_STATUS_OFFSET_CRASH = 1, //!< reset after panic - MODEM_STATUS_OFFSET_MUTE = 2, //!< device is muted - MODEM_STATUS_OFFSET_JOINED = 3, //!< device has joined network + MODEM_STATUS_OFFSET_MUTE = 2, //!< modem is muted + MODEM_STATUS_OFFSET_JOINED = 3, //!< modem has joined network MODEM_STATUS_OFFSET_SUSPEND = 4, //!< radio operations suspended (low power) MODEM_STATUS_OFFSET_UPLOAD = 5, //!< file upload in progress - MODEM_STATUS_OFFSET_JOINING = 6, //!< device is trying to join the network + MODEM_STATUS_OFFSET_JOINING = 6, //!< modem is trying to join the network MODEM_STATUS_OFFSET_STREAMING = 7 //!< streaming in progress } modem_status_offset_t; @@ -318,6 +326,7 @@ typedef enum dm_interval_unit_e DM_INTERVAL_UNIT_MIN = 3 //!< Interval in minute(s) } dm_interval_unit_t; +#if defined( ADD_SMTC_STREAM ) /** * @brief Modem stream structure * @@ -329,6 +338,7 @@ typedef struct modem_stream_s modem_stream_status_t state; bool encryption; } modem_stream_t; +#endif // ADD_SMTC_STREAM /** * @brief Downlink message structure diff --git a/smtc_modem_core/device_management/dm_downlink.c b/smtc_modem_core/device_management/dm_downlink.c index 7a48abe..b3d7427 100644 --- a/smtc_modem_core/device_management/dm_downlink.c +++ b/smtc_modem_core/device_management/dm_downlink.c @@ -55,13 +55,18 @@ #include "gnss_ctrl_api.h" #endif // LR1110_MODEM_E && _MODEM_E_GNSS_ENABLE -#if defined( LR11XX_TRANSCEIVER ) +#if defined( LR11XX_TRANSCEIVER ) || defined( LR1110_MODEM_E ) #include "smtc_basic_modem_lr11xx_api_extension.h" -#if defined( ENABLE_MODEM_GNSS_FEATURE ) +#endif // LR11XX_TRANSCEIVER || LR1110_MODEM_E + +#if defined( ENABLE_MODEM_GNSS_FEATURE ) && defined( LR11XX_TRANSCEIVER ) #include "almanac_update.h" #include "lr11xx_gnss.h" -#endif // ENABLE_MODEM_GNSS_FEATURE -#endif // LR11XX_TRANSCEIVER +#endif // ENABLE_MODEM_GNSS_FEATURE && LR11XX_TRANSCEIVER + +#if defined( LR1110_MODEM_E ) +#include "smtc_modem_e_api_extension.h" +#endif // LR1110_MODEM_E extern smtc_modem_services_t smtc_modem_services_ctx; @@ -91,31 +96,50 @@ extern smtc_modem_services_t smtc_modem_services_ctx; #if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON static const char* dm_cmd_str[DM_CMD_MAX] = { - [DM_RESET] = "RESET", // - [DM_FUOTA] = "FUOTA", // - [DM_FILE_DONE] = "FILE_DONE", // - [DM_GET_INFO] = "GET_INFO", // - [DM_SET_CONF] = "SET_CONF", // - [DM_REJOIN] = "REJOIN", // - [DM_MUTE] = "MUTE", // - [DM_SET_DM_INFO] = "SET_DM_INFO", // - [DM_STREAM] = "STREAM", // - [DM_ALC_SYNC] = "ALC_SYNC", // - [DM_ALM_UPDATE] = "ALM_UPDATE", // - [DM_ALM_DBG] = "ALM_DEBUG", // + [DM_RESET] = "RESET", // + [DM_FUOTA] = "FUOTA", // +#if defined( ADD_SMTC_FILE_UPLOAD ) + [DM_FILE_DONE] = "FILE_DONE", // +#endif // ADD_SMTC_FILE_UPLOAD + [DM_GET_INFO] = "GET_INFO", // + [DM_SET_CONF] = "SET_CONF", // + [DM_REJOIN] = "REJOIN", // + [DM_MUTE] = "MUTE", // + [DM_SET_DM_INFO] = "SET_DM_INFO", // +#if defined( ADD_SMTC_STREAM ) + [DM_STREAM] = "STREAM", // +#endif // ADD_SMTC_STREAM + [DM_ALC_SYNC] = "ALC_SYNC", // + [DM_ALM_UPDATE] = "ALM_UPDATE", // +#if !defined( DISABLE_ALMANAC_DBG_OPCODE ) + [DM_ALM_DBG] = "ALM_DEBUG", // +#endif //! DISABLE_ALMANAC_DBG_OPCODE [DM_SOLV_UPDATE] = "SOLVER_UPDATE", // [DM_ALM_FUPDATE] = "ALM_FUPDATE", // }; #endif static const uint8_t dm_cmd_len[DM_CMD_MAX][2] = { // CMD = {min, max} - [DM_RESET] = { 3, 3 }, [DM_FUOTA] = { 1, 255 }, - [DM_FILE_DONE] = { 1, 1 }, [DM_GET_INFO] = { 1, 255 }, - [DM_SET_CONF] = { 2, 255 }, [DM_REJOIN] = { 2, 2 }, - [DM_MUTE] = { 1, 1 }, [DM_SET_DM_INFO] = { 1, DM_INFO_MAX }, - [DM_STREAM] = { 1, 255 }, [DM_ALC_SYNC] = { 1, 255 }, - [DM_ALM_UPDATE] = { 1, 255 }, [DM_ALM_DBG] = { 1, 255 }, - [DM_SOLV_UPDATE] = { 1, 255 }, [DM_ALM_FUPDATE] = { 1, 255 } + [DM_RESET] = { 3, 3 }, + [DM_FUOTA] = { 1, 255 }, +#if defined( ADD_SMTC_FILE_UPLOAD ) + [DM_FILE_DONE] = { 1, 1 }, +#endif // ADD_SMTC_FILE_UPLOAD + [DM_GET_INFO] = { 1, 255 }, + [DM_SET_CONF] = { 2, 255 }, + [DM_REJOIN] = { 2, 2 }, + [DM_MUTE] = { 1, 1 }, + [DM_SET_DM_INFO] = { 1, DM_INFO_MAX }, +#if defined( ADD_SMTC_STREAM ) + [DM_STREAM] = { 1, 255 }, +#endif // ADD_SMTC_STREAM + [DM_ALC_SYNC] = { 1, 255 }, + [DM_ALM_UPDATE] = { 1, 255 }, +#if !defined( DISABLE_ALMANAC_DBG_OPCODE ) + [DM_ALM_DBG] = { 1, 255 }, +#endif // !DISABLE_ALMANAC_DBG_OPCODE + [DM_SOLV_UPDATE] = { 1, 255 }, + [DM_ALM_FUPDATE] = { 1, 255 } }; /* @@ -202,6 +226,7 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) case DM_FUOTA: // Not supported yet break; +#if defined( ADD_SMTC_FILE_UPLOAD ) case DM_FILE_DONE: SMTC_MODEM_HAL_TRACE_WARNING( "DM_FILE_DONE donwlink\n" ); @@ -227,6 +252,7 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) modem_supervisor_remove_task( FILE_UPLOAD_TASK ); } break; +#endif // ADD_SMTC_FILE_UPLOAD case DM_GET_INFO: if( set_dm_info( cmd_input->buffer, cmd_input->buffer_len, DM_INFO_NOW ) != DM_OK ) { @@ -258,8 +284,9 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) ret = DM_ERROR; break; } - set_modem_status_modem_joined( false ); - lorawan_api_join_status_clear( ); + // Leave network + modem_leave( ); + // Add a new join task modem_supervisor_add_task_join( ); break; } @@ -279,6 +306,7 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) } break; +#if defined( ADD_SMTC_STREAM ) case DM_STREAM: if( stream_process_dn_frame( &( smtc_modem_services_ctx.stream_ROSE_ctx ), cmd_input->buffer, cmd_input->buffer_len ) != STREAM_OK ) @@ -286,6 +314,8 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) ret = DM_ERROR; } break; +#endif // ADD_SMTC_STREAM +#if defined( ADD_SMTC_ALC_SYNC ) case DM_ALC_SYNC: { uint8_t alc_sync_status = alc_sync_parser( &( smtc_modem_services_ctx.alc_sync_ctx ), cmd_input->buffer, cmd_input->buffer_len ); @@ -340,6 +370,8 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) } } break; +#endif // ADD_SMTC_ALC_SYNC + case DM_ALM_UPDATE: { #if defined( LR1110_MODEM_E ) && defined( _MODEM_E_GNSS_ENABLE ) if( Gnss_push_almanac_update( cmd_input->buffer, cmd_input->buffer_len, 0 ) != GNSS_CMD_OK ) @@ -412,13 +444,14 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) } break; } +#if !defined( DISABLE_ALMANAC_DBG_OPCODE ) case DM_ALM_DBG: { #if defined( LR1110_MODEM_E ) && defined( _MODEM_E_GNSS_ENABLE ) // Is DM set time request (not used in soft modem) uint32_t gps_time_s = is_set_time_request( cmd_input->buffer, cmd_input->buffer_len ); if( gps_time_s ) { - modem_set_time( gps_time_s ); + smtc_modem_set_time( gps_time_s ); } if( Gnss_push_dbg_request( cmd_input->buffer, cmd_input->buffer_len ) != GNSS_CMD_OK ) { @@ -433,10 +466,11 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input ) } #elif defined( LR11XX_TRANSCEIVER ) && defined( ENABLE_MODEM_GNSS_FEATURE ) // Not supported on Basic Modem with LR11XX tranceiver - ret = DM_ERROR; + ret = DM_ERROR; #endif ret = DM_ERROR; } +#endif // !DISABLE_ALMANAC_DBG_OPCODE break; case DM_SOLV_UPDATE: { #if defined( LR1110_MODEM_E ) && defined( _MODEM_E_GNSS_ENABLE ) diff --git a/smtc_modem_core/device_management/modem_context.c b/smtc_modem_core/device_management/modem_context.c index eb17f46..66a287d 100644 --- a/smtc_modem_core/device_management/modem_context.c +++ b/smtc_modem_core/device_management/modem_context.c @@ -62,15 +62,13 @@ #endif //_MODEM_E_GNSS_ENABLE #endif // LR1110_MODEM_E -#if defined( LR11XX_TRANSCEIVER ) -#if defined( ENABLE_MODEM_GNSS_FEATURE ) +#if defined( LR11XX_TRANSCEIVER ) && defined( ENABLE_MODEM_GNSS_FEATURE ) #include "almanac_update.h" -#endif // ENABLE_MODEM_GNSS_FEATURE +#endif // LR11XX_TRANSCEIVER && ENABLE_MODEM_GNSS_FEATURE + #if defined( USE_LR11XX_CE ) #include "lr11xx_system.h" #endif // USE_LR11XX_CE -#endif // LR11XX_TRANSCEIVER - /* * ----------------------------------------------------------------------------- * --- PRIVATE MACROS----------------------------------------------------------- @@ -103,23 +101,29 @@ typedef struct modem_context_nvm_idx_s } modem_context_nvm_t; #if !defined( LR1110_MODEM_E ) -static int16_t modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID; -static uint32_t modem_appkey_crc = 0; -static uint8_t modem_status = 0; -static uint8_t modem_dm_interval = DEFAULT_DM_REPORTING_INTERVAL; -static uint8_t modem_dm_port = DEFAULT_DM_PORT; -static uint8_t modem_frag_port = DEFAULT_FRAG_PORT; -static uint8_t modem_appstatus[8] = { 0 }; -static smtc_modem_class_t modem_dm_class = SMTC_MODEM_CLASS_A; -static modem_suspend_status_t is_modem_suspend = MODEM_NOT_SUSPEND; -static uint32_t modem_start_time = 0; -static uint8_t modem_dm_upload_sctr = 0; -static modem_upload_state_t modem_upload_state = MODEM_UPLOAD_NOT_INIT; -static modem_stream_t modem_stream_state = { // +static int16_t modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID; +static uint32_t modem_appkey_crc = 0; +static uint8_t modem_status = 0; +static uint8_t modem_dm_interval = DEFAULT_DM_REPORTING_INTERVAL; +static uint8_t modem_dm_port = DEFAULT_DM_PORT; +#if defined( ADD_SMTC_PATCH_UPDATE ) +static uint8_t modem_frag_port = DEFAULT_FRAG_PORT; +#endif // ADD_SMTC_PATCH_UPDATE +static uint8_t modem_appstatus[8] = { 0 }; +static smtc_modem_class_t modem_dm_class = SMTC_MODEM_CLASS_A; +static modem_suspend_status_t is_modem_suspend = MODEM_NOT_SUSPEND; +static uint32_t modem_start_time = 0; +#if defined( ADD_SMTC_FILE_UPLOAD ) +static uint8_t modem_dm_upload_sctr = 0; +static modem_upload_state_t modem_upload_state = MODEM_UPLOAD_NOT_INIT; +#endif // ADD_SMTC_FILE_UPLOAD +#if defined( ADD_SMTC_STREAM ) +static modem_stream_t modem_stream_state = { // .port = DEFAULT_DM_PORT, // .state = MODEM_STREAM_NOT_INIT, // .encryption = false }; +#endif // ADD_SMTC_STREAM static uint32_t dm_info_bitfield_periodic = DEFAULT_DM_REPORTING_FIELDS; // context for periodic GetInfo static uint32_t dm_info_bitfield_now = 0; // User GetInfo static uint8_t tag_number = 0; @@ -142,20 +146,22 @@ static rf_output_t modem_rf_output = MODEM_RFO_LP_L static uint8_t duty_cycle_disabled_by_host = false; static uint32_t crc_fw; static smtc_modem_adr_profile_t modem_adr_profile; -static uint32_t modem_upload_avgdelay; -static uint16_t nb_adr_mobile_timeout; -static bool is_modem_in_test_mode = false; -static int8_t rx_pathloss_db = 0; -static int8_t tx_power_offset_db = 0; -static radio_planner_t* modem_rp = NULL; -static modem_power_config_t power_config_lut[POWER_CONFIG_LUT_SIZE]; -static modem_context_class_b_d2d_t class_b_d2d_ctx; +#if defined( ADD_SMTC_FILE_UPLOAD ) +static uint32_t modem_upload_avgdelay; +#endif // ADD_SMTC_FILE_UPLOAD +static uint16_t nb_adr_mobile_timeout; +static bool is_modem_in_test_mode = false; +static int8_t rx_pathloss_db = 0; +static int8_t tx_power_offset_db = 0; +static radio_planner_t* modem_rp = NULL; +static modem_power_config_t power_config_lut[POWER_CONFIG_LUT_SIZE]; +#if defined( SMTC_D2D ) +static modem_context_class_b_d2d_t class_b_d2d_ctx; +#endif // SMTC_D2D static void ( *modem_lbm_notification_extended_1_callback )( void ); static void ( *modem_lbm_notification_extended_2_callback )( void ); -#if defined( LR11XX_TRANSCEIVER ) static const void* modem_radio_ctx; // use to save lr11xx user radio context needed to perform direct access to radio // withing modem code (almanac update, crypto) -#endif // LR11XX_TRANSCEIVER #else struct @@ -165,14 +171,21 @@ struct uint8_t modem_status; uint8_t modem_dm_interval; uint8_t modem_dm_port; +#if defined( ADD_SMTC_PATCH_UPDATE ) uint8_t modem_frag_port; +#endif // ADD_SMTC_PATCH_UPDATE uint8_t modem_appstatus[8]; smtc_modem_class_t modem_dm_class; modem_suspend_status_t is_modem_suspend; uint32_t modem_start_time; +#if defined( ADD_SMTC_FILE_UPLOAD ) uint8_t modem_dm_upload_sctr; modem_upload_state_t modem_upload_state; + uint32_t modem_upload_avgdelay; +#endif // ADD_SMTC_FILE_UPLOAD +#if defined( ADD_SMTC_STREAM ) modem_stream_t modem_stream_state; +#endif // ADD_SMTC_STREAM uint32_t dm_info_bitfield_periodic; // context for periodic GetInfo uint32_t dm_info_bitfield_now; // User GetInfo uint8_t tag_number; @@ -195,62 +208,75 @@ struct uint8_t duty_cycle_disabled_by_host; uint32_t crc_fw; smtc_modem_adr_profile_t modem_adr_profile; - uint32_t modem_upload_avgdelay; uint16_t nb_adr_mobile_timeout; bool is_modem_in_test_mode; int8_t rx_pathloss_db; int8_t tx_power_offset_db; radio_planner_t* modem_rp; modem_power_config_t power_config_lut[POWER_CONFIG_LUT_SIZE]; +#if defined( ADD_D2D ) modem_context_class_b_d2d_t class_b_d2d_ctx; +#endif // ADD_D2D void ( *modem_lbm_notification_extended_1_callback )( void ); void ( *modem_lbm_notification_extended_2_callback )( void ); + const void* modem_radio_ctx; } modem_ctx_context; // clang-format off -#define modem_appkey_status modem_ctx_context.modem_appkey_status -#define modem_appkey_crc modem_ctx_context.modem_appkey_crc -#define modem_status modem_ctx_context.modem_status -#define modem_dm_interval modem_ctx_context.modem_dm_interval -#define modem_dm_port modem_ctx_context.modem_dm_port -#define modem_frag_port modem_ctx_context.modem_frag_port -#define modem_appstatus modem_ctx_context.modem_appstatus -#define modem_dm_class modem_ctx_context.modem_dm_class -#define is_modem_suspend modem_ctx_context.is_modem_suspend -#define modem_start_time modem_ctx_context.modem_start_time -#define modem_dm_upload_sctr modem_ctx_context.modem_dm_upload_sctr -#define modem_upload_state modem_ctx_context.modem_upload_state -#define modem_stream_state modem_ctx_context.modem_stream_state -#define dm_info_bitfield_periodic modem_ctx_context.dm_info_bitfield_periodic -#define dm_info_bitfield_now modem_ctx_context.dm_info_bitfield_now -#define tag_number modem_ctx_context.tag_number -#define tag_number_now modem_ctx_context.tag_number_now -#define number_of_muted_day modem_ctx_context.number_of_muted_day -#define dm_pending_dl modem_ctx_context.dm_pending_dl -#define user_alarm modem_ctx_context.user_alarm -#define asynchronous_msgnumber modem_ctx_context.asynchronous_msgnumber -#define modem_event_count modem_ctx_context.modem_event_count -#define modem_event_status modem_ctx_context.modem_event_status -#define asynch_msg modem_ctx_context.asynch_msg -#define modem_dwn_pkt modem_ctx_context.modem_dwn_pkt -#define is_modem_reset_requested modem_ctx_context.is_modem_reset_requested -#define is_modem_charge_loaded modem_ctx_context.is_modem_charge_loaded -#define modem_charge_offset modem_ctx_context.modem_charge_offset -#define start_time_was_set modem_ctx_context.start_time_was_set -#define user_define_charge_counter modem_ctx_context.user_define_charge_counter -#define charge_counter_to_send modem_ctx_context.charge_counter_to_send -#define modem_rf_output modem_ctx_context.modem_rf_output -#define duty_cycle_disabled_by_host modem_ctx_context.duty_cycle_disabled_by_host -#define crc_fw modem_ctx_context.crc_fw -#define modem_adr_profile modem_ctx_context.modem_adr_profile -#define modem_upload_avgdelay modem_ctx_context.modem_upload_avgdelay -#define nb_adr_mobile_timeout modem_ctx_context.nb_adr_mobile_timeout -#define is_modem_in_test_mode modem_ctx_context.is_modem_in_test_mode -#define rx_pathloss_db modem_ctx_context.rx_pathloss_db -#define tx_power_offset_db modem_ctx_context.tx_power_offset_db -#define modem_rp modem_ctx_context.modem_rp -#define power_config_lut modem_ctx_context.power_config_lut -#define class_b_d2d_ctx modem_ctx_context.class_b_d2d_ctx +#define modem_appkey_status modem_ctx_context.modem_appkey_status +#define modem_appkey_crc modem_ctx_context.modem_appkey_crc +#define modem_status modem_ctx_context.modem_status +#define modem_dm_interval modem_ctx_context.modem_dm_interval +#define modem_dm_port modem_ctx_context.modem_dm_port +#if defined( ADD_SMTC_PATCH_UPDATE ) +#define modem_frag_port modem_ctx_context.modem_frag_port +#endif // ADD_SMTC_PATCH_UPDATE +#define modem_appstatus modem_ctx_context.modem_appstatus +#define modem_dm_class modem_ctx_context.modem_dm_class +#define is_modem_suspend modem_ctx_context.is_modem_suspend +#define modem_start_time modem_ctx_context.modem_start_time +#if defined( ADD_SMTC_FILE_UPLOAD ) +#define modem_dm_upload_sctr modem_ctx_context.modem_dm_upload_sctr +#define modem_upload_state modem_ctx_context.modem_upload_state +#endif // ADD_SMTC_FILE_UPLOAD +#if defined( ADD_SMTC_STREAM ) +#define modem_stream_state modem_ctx_context.modem_stream_state +#endif // ADD_SMTC_STREAM +#define dm_info_bitfield_periodic modem_ctx_context.dm_info_bitfield_periodic +#define dm_info_bitfield_now modem_ctx_context.dm_info_bitfield_now +#define tag_number modem_ctx_context.tag_number +#define tag_number_now modem_ctx_context.tag_number_now +#define number_of_muted_day modem_ctx_context.number_of_muted_day +#define dm_pending_dl modem_ctx_context.dm_pending_dl +#define user_alarm modem_ctx_context.user_alarm +#define asynchronous_msgnumber modem_ctx_context.asynchronous_msgnumber +#define modem_event_count modem_ctx_context.modem_event_count +#define modem_event_status modem_ctx_context.modem_event_status +#define asynch_msg modem_ctx_context.asynch_msg +#define modem_dwn_pkt modem_ctx_context.modem_dwn_pkt +#define is_modem_reset_requested modem_ctx_context.is_modem_reset_requested +#define is_modem_charge_loaded modem_ctx_context.is_modem_charge_loaded +#define modem_charge_offset modem_ctx_context.modem_charge_offset +#define start_time_was_set modem_ctx_context.start_time_was_set +#define user_define_charge_counter modem_ctx_context.user_define_charge_counter +#define charge_counter_to_send modem_ctx_context.charge_counter_to_send +#define modem_rf_output modem_ctx_context.modem_rf_output +#define duty_cycle_disabled_by_host modem_ctx_context.duty_cycle_disabled_by_host +#define crc_fw modem_ctx_context.crc_fw +#define modem_adr_profile modem_ctx_context.modem_adr_profile +#if defined ( ADD_SMTC_FILE_UPLOAD ) +#define modem_upload_avgdelay modem_ctx_context.modem_upload_avgdelay +#endif // ADD_SMTC_FILE_UPLOAD +#define nb_adr_mobile_timeout modem_ctx_context.nb_adr_mobile_timeout +#define is_modem_in_test_mode modem_ctx_context.is_modem_in_test_mode +#define rx_pathloss_db modem_ctx_context.rx_pathloss_db +#define tx_power_offset_db modem_ctx_context.tx_power_offset_db +#define modem_rp modem_ctx_context.modem_rp +#define power_config_lut modem_ctx_context.power_config_lut +#define class_b_d2d_ctx modem_ctx_context.class_b_d2d_ctx +#define modem_lbm_notification_extended_1_callback modem_ctx_context.modem_lbm_notification_extended_1_callback +#define modem_lbm_notification_extended_2_callback modem_ctx_context.modem_lbm_notification_extended_2_callback +#define modem_radio_ctx modem_ctx_context.modem_radio_ctx // clang-format on #endif @@ -264,9 +290,11 @@ static const uint8_t dm_info_field_sz[DM_INFO_MAX] = { [DM_INFO_CRASHLOG] = 0, // (variable-length, send as last field or in separate frame) [DM_INFO_UPLOAD] = 0, // (variable-length, not sent periodically) [DM_INFO_RSTCOUNT] = 2, [DM_INFO_DEVEUI] = 8, [DM_INFO_RFU_1] = 2, [DM_INFO_SESSION] = 2, - [DM_INFO_CHIPEUI] = 8, + [DM_INFO_CHIPEUI] = 8, +#if defined( ADD_SMTC_STREAM ) [DM_INFO_STREAM] = 0, // (variable-length, not sent periodically) [DM_INFO_STREAMPAR] = 2, [DM_INFO_APPSTATUS] = 8, +#endif // ADD_SMTC_STREAM [DM_INFO_ALCSYNC] = 0, // (variable-length, not sent periodically) [DM_INFO_ALMSTATUS] = 7 }; @@ -332,45 +360,53 @@ static dm_cmd_length_valid_t check_dm_status_max_size( uint32_t info_requested, void modem_context_init( ) { - modem_status = 0; - modem_dm_interval = DEFAULT_DM_REPORTING_INTERVAL; - modem_dm_port = DEFAULT_DM_PORT; - modem_frag_port = DEFAULT_FRAG_PORT; - modem_dm_class = SMTC_MODEM_CLASS_A; - is_modem_suspend = MODEM_NOT_SUSPEND; - modem_start_time = 0; - modem_dm_upload_sctr = 0; - modem_upload_state = MODEM_UPLOAD_NOT_INIT; + modem_status = 0; + modem_dm_interval = DEFAULT_DM_REPORTING_INTERVAL; + modem_dm_port = DEFAULT_DM_PORT; +#if defined( ADD_SMTC_PATCH_UPDATE ) + modem_frag_port = DEFAULT_FRAG_PORT; +#endif // ADD_SMTC_PATCH_UPDATE + modem_dm_class = SMTC_MODEM_CLASS_A; + is_modem_suspend = MODEM_NOT_SUSPEND; + modem_start_time = 0; +#if defined( ADD_SMTC_FILE_UPLOAD ) + modem_dm_upload_sctr = 0; + modem_upload_state = MODEM_UPLOAD_NOT_INIT; +#endif // ADD_SMTC_FILE_UPLOAD +#if defined( ADD_SMTC_STREAM ) modem_stream_state.port = DEFAULT_DM_PORT; modem_stream_state.state = MODEM_STREAM_NOT_INIT; modem_stream_state.encryption = false; - dm_info_bitfield_periodic = DEFAULT_DM_REPORTING_FIELDS; // context for periodic GetInfo - dm_info_bitfield_now = 0; // User GetInfo - tag_number = 0; - tag_number_now = 0; - number_of_muted_day = 0; - dm_pending_dl.up_count = 0; - dm_pending_dl.up_delay = 0; - user_alarm = 0; - asynchronous_msgnumber = 0; - is_modem_reset_requested = false; - is_modem_charge_loaded = false; - modem_charge_offset = 0; - start_time_was_set = false; - user_define_charge_counter = 0; - charge_counter_to_send = CHARGE_COUNTER_MODEM; - modem_rf_output = MODEM_RFO_LP_LF; - duty_cycle_disabled_by_host = false; - crc_fw = compute_crc_fw( ); - modem_adr_profile = SMTC_MODEM_ADR_PROFILE_NETWORK_CONTROLLED; - modem_upload_avgdelay = 0; - nb_adr_mobile_timeout = DEFAULT_ADR_MOBILE_MODE_TIMEOUT; - is_modem_in_test_mode = false; - rx_pathloss_db = 0; - tx_power_offset_db = 0; - modem_rp = NULL; - modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID; - modem_appkey_crc = 0; +#endif // ADD_SMTC_STREAM + dm_info_bitfield_periodic = DEFAULT_DM_REPORTING_FIELDS; // context for periodic GetInfo + dm_info_bitfield_now = 0; // User GetInfo + tag_number = 0; + tag_number_now = 0; + number_of_muted_day = 0; + dm_pending_dl.up_count = 0; + dm_pending_dl.up_delay = 0; + user_alarm = 0; + asynchronous_msgnumber = 0; + is_modem_reset_requested = false; + is_modem_charge_loaded = false; + modem_charge_offset = 0; + start_time_was_set = false; + user_define_charge_counter = 0; + charge_counter_to_send = CHARGE_COUNTER_MODEM; + modem_rf_output = MODEM_RFO_LP_LF; + duty_cycle_disabled_by_host = false; + crc_fw = compute_crc_fw( ); + modem_adr_profile = SMTC_MODEM_ADR_PROFILE_NETWORK_CONTROLLED; +#if defined( ADD_SMTC_FILE_UPLOAD ) + modem_upload_avgdelay = 0; +#endif // ADD_SMTC_FILE_UPLOAD + nb_adr_mobile_timeout = DEFAULT_ADR_MOBILE_MODE_TIMEOUT; + is_modem_in_test_mode = false; + rx_pathloss_db = 0; + tx_power_offset_db = 0; + modem_rp = NULL; + modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID; + modem_appkey_crc = 0; memset( modem_appstatus, 0, 8 ); memset( modem_event_count, 0, MODEM_NUMBER_OF_EVENTS ); memset( modem_event_status, 0, MODEM_NUMBER_OF_EVENTS ); @@ -378,7 +414,9 @@ void modem_context_init( ) memset( &modem_dwn_pkt, 0, sizeof( modem_downlink_msg_t ) ); // init power config tab to 0x80 as it corresponds to an expected power of 128dbm, value that is never reached memset( power_config_lut, 0x80, POWER_CONFIG_LUT_SIZE * sizeof( modem_power_config_t ) ); +#if defined( ADD_D2D ) memset( &class_b_d2d_ctx, 0, sizeof( modem_context_class_b_d2d_t ) ); +#endif // ADD_D2D } void modem_event_init( void ) @@ -556,6 +594,7 @@ uint8_t get_modem_dm_port( void ) return ( modem_dm_port ); } +#if defined( ADD_SMTC_PATCH_UPDATE ) dm_rc_t set_modem_frag_port( uint8_t port ) { SMTC_MODEM_HAL_TRACE_ERROR( "set_modem_frag_port not implemented\n" ); @@ -566,6 +605,7 @@ uint8_t get_modem_frag_port( void ) { return ( modem_frag_port ); } +#endif // ADD_SMTC_PATCH_UPDATE smtc_modem_adr_profile_t get_modem_adr_profile( void ) { @@ -593,7 +633,7 @@ modem_join_state_t get_join_state( void ) { joinstate = MODEM_JOIN_ONGOING; } - else if( lorawan_api_isjoined( ) == NOT_JOINED ) + else if( lorawan_api_isjoined( ) != JOINED ) { joinstate = MODEM_NOT_JOINED; } @@ -683,6 +723,7 @@ void modem_supervisor_add_task_crash_log( uint32_t next_execute ) modem_supervisor_add_task( &task_dm ); } +#if defined( ADD_SMTC_ALC_SYNC ) void modem_supervisor_add_task_clock_sync_time_req( uint32_t next_execute ) { smodem_task task_dm; @@ -728,6 +769,7 @@ void modem_supervisor_add_task_alc_sync_ans( uint32_t next_execute ) modem_supervisor_add_task( &task_dm ); } } +#endif // ADD_SMTC_ALC_SYNC void modem_supervisor_add_task_alm_dbg_ans( uint32_t next_execute ) { @@ -778,6 +820,7 @@ void modem_supervisor_add_task_frag( uint32_t next_execute ) } } +#if defined( ADD_SMTC_STREAM ) void modem_supervisor_add_task_stream( void ) { // Modem supervisor copy everything, @@ -796,7 +839,9 @@ void modem_supervisor_add_task_stream( void ) // stream task is now on going: set modem status accordingly set_modem_status_streaming( true ); } +#endif // ADD_SMTC_STREAM +#if defined( ADD_SMTC_FILE_UPLOAD ) void modem_supervisor_add_task_file_upload( uint32_t delay_in_s ) { smodem_task upload_task; @@ -807,6 +852,7 @@ void modem_supervisor_add_task_file_upload( uint32_t delay_in_s ) modem_supervisor_add_task( &upload_task ); } +#endif // ADD_SMTC_FILE_UPLOAD void modem_supervisor_add_task_link_check_req( uint32_t delay_in_s ) { @@ -847,18 +893,6 @@ void modem_supervisor_add_task_ping_slot_info_req( uint32_t delay_in_s ) } } -/*! - * \brief return the modem status - * \remark - * \param [IN] void - * \param [OUT] modem status bit 6 : streaming in progress - * bit 5 : file upload in progress - * bit 4 : radio suspend - * bit 3 : modem join - * bit 2 : modem mute - * bit 1 : reset after panic - * bit 0 : reset after brownout - * */ uint8_t get_modem_status( void ) { // If the stack is no more join, the modem status was not aware of the disconnection @@ -1296,7 +1330,7 @@ bool dm_status_payload( uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_l } break; case DM_INFO_FIRMWARE: { -#if defined( LR1110_MODEM_E ) +#if defined( LR1110_MODEM_E ) && defined( ADD_SMTC_PATCH_UPDATE ) // return the crc value of fuota dedicated for test have to be // re implement when fuota availble *( p_tmp + 0 ) = crc_fw & 0xFF; @@ -1309,7 +1343,7 @@ bool dm_status_payload( uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_l *( p_tmp + 7 ) = ( frag_get_nb_frag_received( ) >> 8 ) & 0xFF; #else memset( p_tmp, 0, 8 ); // TODO remove this -#endif // LR1110_MODEM_E +#endif // LR1110_MODEM_E && ADD_SMTC_PATCH_UPDATE } break; case DM_INFO_ADRMODE: @@ -1365,10 +1399,12 @@ bool dm_status_payload( uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_l memcpy1_r( p_tmp, p_tmp_chip_eui, 8 ); break; } +#if defined( ADD_SMTC_STREAM ) case DM_INFO_STREAMPAR: *p_tmp = modem_get_stream_port( ); *( p_tmp + 1 ) = modem_get_stream_encryption( ); break; +#endif // ADD_SMTC_STREAM case DM_INFO_APPSTATUS: get_modem_appstatus( p_tmp ); break; @@ -1399,7 +1435,7 @@ bool dm_status_payload( uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_l *dm_uplink_message_len = p - dm_uplink_message; return pending; } -#if defined( LR1110_MODEM_E ) +#if defined( LR1110_MODEM_E ) && defined( ADD_SMTC_PATCH_UPDATE ) void dm_frag_uplink_payload( uint8_t max_payload_length, uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_len ) { frag_set_max_length_up_payload( max_payload_length ); @@ -1408,7 +1444,7 @@ void dm_frag_uplink_payload( uint8_t max_payload_length, uint8_t* dm_uplink_mess frag_get_tx_buffer( &dm_uplink_message[0], dm_uplink_message_len ); } -#endif // LR1110_MODEM_E +#endif // LR1110_MODEM_E && ADD_SMTC_PATCH_UPDATE #if defined( LR1110_MODEM_E ) && defined( _MODEM_E_GNSS_ENABLE ) void dm_alm_dbg_uplink_payload( uint8_t max_payload_length, uint8_t* dm_uplink_message, uint8_t* dm_uplink_message_len ) @@ -1582,7 +1618,7 @@ void set_modem_downlink_frame( uint8_t* data, uint8_t data_length, lr1mac_down_m SMTC_MODEM_HAL_TRACE_ARRAY( "Downlink frame ", modem_dwn_pkt.data, modem_dwn_pkt.length ); SMTC_MODEM_HAL_TRACE_PRINTF( "DL Port = %d , ", modem_dwn_pkt.port ); SMTC_MODEM_HAL_TRACE_PRINTF( "DL SNR = %d , DL RSSI = %d , ", modem_dwn_pkt.snr, modem_dwn_pkt.rssi ); - SMTC_MODEM_HAL_TRACE_PRINTF( "DL Freq = %d , DL DR = %d , ", modem_dwn_pkt.frequency_hz, modem_dwn_pkt.datarate ); + SMTC_MODEM_HAL_TRACE_PRINTF( "DL Freq = %lu , DL DR = %d , ", modem_dwn_pkt.frequency_hz, modem_dwn_pkt.datarate ); SMTC_MODEM_HAL_TRACE_PRINTF( "DL Fpending Bit = %d \n", modem_dwn_pkt.fpending_bit ); } void get_modem_downlink_frame( modem_downlink_msg_t* modem_dwn_in ) @@ -1651,8 +1687,11 @@ void modem_load_context( void ) modem_appkey_status = ctx.appkey_crc_status; modem_appkey_crc = ctx.appkey_crc; - SMTC_MODEM_HAL_TRACE_PRINTF( "Modem Load Config :\n Port = %d \n Upload_sctr = %d\n", modem_dm_port, - modem_dm_upload_sctr ); + SMTC_MODEM_HAL_TRACE_PRINTF( "Modem Load Config :\n Port = %d\n", modem_dm_port ); + +#if defined( ADD_SMTC_FILE_UPLOAD ) + SMTC_MODEM_HAL_TRACE_PRINTF( "Upload_sctr = %d\n", modem_dm_upload_sctr ); +#endif // ADD_SMTC_FILE_UPLOAD } else { @@ -1680,11 +1719,7 @@ void modem_context_factory_reset( void ) SMTC_MODEM_HAL_TRACE_INFO( "modem_context_factory_reset done\n" ); } -uint8_t modem_context_get_dm_upload_sctr( void ) -{ - return ( modem_dm_upload_sctr & 0xf ); -} - +#if defined( ADD_SMTC_FILE_UPLOAD ) uint8_t modem_context_compute_and_get_next_dm_upload_sctr( void ) { // take current and add 1 then mask to fit 4bits length (overflow is implicitely managed) @@ -1701,7 +1736,9 @@ void modem_set_upload_state( modem_upload_state_t upload_state ) { modem_upload_state = upload_state; } +#endif // ADD_SMTC_FILE_UPLOAD +#if defined( ADD_SMTC_STREAM ) modem_stream_status_t modem_get_stream_state( void ) { return ( modem_stream_state.state ); @@ -1731,6 +1768,7 @@ void modem_set_stream_encryption( bool enc ) { modem_stream_state.encryption = enc; } +#endif // ADD_SMTC_STREAM void modem_set_dm_info_bitfield_periodic( uint32_t value ) { @@ -1852,41 +1890,56 @@ void modem_context_empty_callback( void* ctx ) // SMTC_MODEM_HAL_TRACE_ERROR( " empty call back \n" ); } -bool modem_context_suspend_radio_access( rp_task_types_t type ) +#if !defined( LR1110_MODEM_E ) +bool modem_context_suspend_user_radio_access( rp_task_types_t type ) { rp_radio_params_t fake_radio_params = { 0 }; rp_task_t rp_task = { - .hook_id = RP_HOOK_ID_SUSPEND, - .launch_task_callbacks = modem_context_empty_callback, + .hook_id = RP_HOOK_ID_USER_SUSPEND, + .launch_task_callbacks = modem_context_empty_callback, /* called when the task starts */ .duration_time_ms = 20000, .state = RP_TASK_STATE_SCHEDULE, .type = type, .schedule_task_low_priority = false, .start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 4, }; - - // First disable modem irq to secure radio access - smtc_modem_hal_disable_modem_irq( ); - rp_hook_status_t status = rp_task_enqueue( modem_rp, &rp_task, NULL, 0, &fake_radio_params ); return ( status == RP_HOOK_STATUS_OK ) ? true : false; } -bool modem_context_suspend_user_radio_access( rp_task_types_t type ) +bool modem_context_resume_user_radio_access( void ) +{ + bool status = true; + + if( rp_task_abort( modem_rp, RP_HOOK_ID_USER_SUSPEND ) != RP_HOOK_STATUS_OK ) + { + SMTC_MODEM_HAL_TRACE_ERROR( "Fail to abort hook\n" ); + status = false; + } + + return status; +} +#endif // !LR1110_MODEM_E + +bool modem_context_suspend_radio_access( rp_task_types_t type ) { rp_radio_params_t fake_radio_params = { 0 }; rp_task_t rp_task = { - .hook_id = RP_HOOK_ID_USER_SUSPEND, - .launch_task_callbacks = modem_context_empty_callback, /* called when the task starts */ + .hook_id = RP_HOOK_ID_SUSPEND, + .launch_task_callbacks = modem_context_empty_callback, .duration_time_ms = 20000, .state = RP_TASK_STATE_SCHEDULE, .type = type, .schedule_task_low_priority = false, .start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 4, }; + + // First disable modem irq to secure radio access + smtc_modem_hal_disable_modem_irq( ); + rp_hook_status_t status = rp_task_enqueue( modem_rp, &rp_task, NULL, 0, &fake_radio_params ); return ( status == RP_HOOK_STATUS_OK ) ? true : false; @@ -1908,19 +1961,6 @@ bool modem_context_resume_radio_access( void ) return status; } -bool modem_context_resume_user_radio_access( void ) -{ - bool status = true; - - if( rp_task_abort( modem_rp, RP_HOOK_ID_USER_SUSPEND ) != RP_HOOK_STATUS_OK ) - { - SMTC_MODEM_HAL_TRACE_ERROR( "Fail to abort hook\n" ); - status = false; - } - - return status; -} - void modem_context_set_power_config_lut( uint8_t config[30] ) { // save raw buff into power lut @@ -1939,10 +1979,11 @@ modem_power_config_t* modem_context_get_power_config_lut( void ) return power_config_lut; } -void modem_context_set_appkey( const uint8_t app_key[16] ) +modem_ctx_rc_t modem_context_set_appkey( const uint8_t app_key[16] ) { + modem_ctx_rc_t rc = MODEM_CTX_RC_SUCCESS; // To prevent too much flash access first check crc on key in case of Hardware Secure element -#if defined( LR1110_MODEM_E ) || defined( USE_LR11XX_CE ) +#if( defined( LR1110_MODEM_E ) && defined( USE_LR11XX_CE ) ) || defined( USE_LR11XX_CE ) uint32_t new_crc = crc( app_key, 16 ); if( ( modem_appkey_status == MODEM_APPKEY_CRC_STATUS_INVALID ) || ( modem_appkey_crc != new_crc ) ) @@ -1950,14 +1991,23 @@ void modem_context_set_appkey( const uint8_t app_key[16] ) modem_appkey_crc = new_crc; modem_appkey_status = MODEM_APPKEY_CRC_STATUS_VALID; - lorawan_api_set_appkey( app_key ); - // Store appkey crc and status - modem_store_context( ); + if( lorawan_api_set_appkey( app_key ) != OKLORAWAN ) + { + rc = MODEM_CTX_RC_ERROR; + } + else + { + // Store appkey crc and status + modem_store_context( ); + } } #else - lorawan_api_set_appkey( app_key ); - + if( lorawan_api_set_appkey( app_key ) != OKLORAWAN ) + { + rc = MODEM_CTX_RC_ERROR; + } #endif + return rc; } void modem_context_appkey_is_derived( void ) @@ -1976,7 +2026,6 @@ void modem_context_set_network_type( bool network_type ) lorawan_api_set_network_type( network_type ); } -#if defined( LR11XX_TRANSCEIVER ) const void* modem_context_get_modem_radio_ctx( void ) { return modem_radio_ctx; @@ -1986,8 +2035,8 @@ void modem_context_set_modem_radio_ctx( const void* radio_ctx ) { modem_radio_ctx = radio_ctx; } -#endif // LR11XX_TRANSCEIVER +#if defined( ADD_D2D ) void modem_context_set_class_b_d2d_last_metadata( uint8_t mc_grp_id, bool tx_done, uint8_t nb_trans_not_send ) { class_b_d2d_ctx.tx_done = tx_done; @@ -2010,6 +2059,8 @@ void modem_context_get_class_b_d2d_last_metadata( modem_context_class_b_d2d_t* c { memcpy( class_b_d2d, &class_b_d2d_ctx, sizeof( modem_context_class_b_d2d_t ) ); } +#endif // ADD_D2D + void modem_set_extended_callback( func_callback callback, uint8_t extended_uplink_id ) { if( extended_uplink_id == 1 ) @@ -2040,4 +2091,32 @@ func_callback modem_get_extended_callback( uint8_t extended_uplink_id ) return NULL; } } + +void modem_leave( void ) +{ + // Set joined/joining status to false + set_modem_status_modem_joined( false ); + lorawan_api_join_status_clear( ); + set_modem_status_joining( false ); + + // Disable properly class B and class C + lorawan_api_class_b_enabled( false ); + lorawan_api_class_c_enabled( false ); + +#if defined( ADD_SMTC_FILE_UPLOAD ) + // Stop and reset file upload service + set_modem_status_file_upload( false ); + modem_set_upload_state( MODEM_UPLOAD_NOT_INIT ); +#endif // ADD_SMTC_FILE_UPLOAD + +#if defined( ADD_SMTC_STREAM ) + // Stop and reset stream service + set_modem_status_streaming( false ); + modem_set_stream_state( MODEM_STREAM_NOT_INIT ); +#endif // ADD_SMTC_STREAM + + // re init task to retrieve a clean env (and clear all ongoing tasks) + modem_supervisor_init_task( ); +} + /* --- EOF ------------------------------------------------------------------ */ diff --git a/smtc_modem_core/device_management/modem_context.h b/smtc_modem_core/device_management/modem_context.h index 938bce8..7dd1b81 100644 --- a/smtc_modem_core/device_management/modem_context.h +++ b/smtc_modem_core/device_management/modem_context.h @@ -71,12 +71,6 @@ extern "C" { #define MODEM_NUMBER_OF_EVENTS 0x19 // number of possible events in modem -typedef enum charge_counter_value_e -{ - CHARGE_COUNTER_MODEM = 0, - CHARGE_COUNTER_USER_DEFINE = 1, -} charge_counter_value_t; - /* * ----------------------------------------------------------------------------- * --- PUBLIC TYPES ------------------------------------------------------------ @@ -99,6 +93,22 @@ typedef struct power_config_e } modem_power_config_t; typedef void ( *func_callback )( void ); + +typedef enum charge_counter_value_e +{ + CHARGE_COUNTER_MODEM = 0, + CHARGE_COUNTER_USER_DEFINE = 1, +} charge_counter_value_t; + +/** + * @brief Modem context return code + */ +typedef enum modem_ctx_rc_s +{ + MODEM_CTX_RC_SUCCESS, + MODEM_CTX_RC_ERROR, +} modem_ctx_rc_t; + /* * ----------------------------------------------------------------------------- * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- @@ -378,13 +388,15 @@ int8_t get_modem_temp( void ); /*! * \brief return the modem status * \remark - * \retval uint8_t bit 5 : file upload in progress - * bit 4 : radio suspend - * bit 3 : modem join - * bit 2 : modem mute + * \retval uint8_t bit 0 : reset after brownout * bit 1 : reset after panic - * bit 0 : reset after brownout - * */ + * bit 2 : modem is muted + * bit 3 : modem is joined + * bit 4 : modem radio communication is suspended + * bit 5 : file upload in progress + * bit 6 : modem is trying to join the network + * bit 7 : streaming in progress + */ uint8_t get_modem_status( void ); /*! @@ -719,18 +731,22 @@ void modem_supervisor_add_task_modem_mute( void ); */ void modem_supervisor_add_task_retrieve_dl( uint32_t next_execute ); +#if defined( ADD_SMTC_STREAM ) /*! * \brief add a stream task in scheduler * \remark */ void modem_supervisor_add_task_stream( void ); +#endif // ADD_SMTC_STREAM +#if defined( ADD_SMTC_FILE_UPLOAD ) /** * @brief add a file upload task in scheduler * * @param [in] delay_in_s The delay in s before task is launched */ void modem_supervisor_add_task_file_upload( uint32_t delay_in_s ); +#endif // ADD_SMTC_FILE_UPLOAD /*! * \brief add a fragmented data block task in scheduler @@ -806,6 +822,7 @@ void modem_load_context( void ); */ void modem_context_factory_reset( void ); +#if defined( ADD_SMTC_STREAM ) /*! * \brief get the stream state * \param [in] void @@ -847,12 +864,7 @@ void modem_set_stream_port( uint8_t port ); * \param [out] void */ void modem_set_stream_encryption( bool enc ); - -/*! - * \brief get the upload session counter variable - * \retval return session_counter value - */ -uint8_t modem_context_get_dm_upload_sctr( void ); +#endif // ADD_SMTC_STREAM /** * @brief compute the next session counter value and return it @@ -1079,9 +1091,10 @@ modem_power_config_t* modem_context_get_power_config_lut( void ); /** * @brief Check appkey crc and status. And set them if required * - * @param app_key App key + * @param [in] app_key Key buffer + * @return modem_ctx_rc_t */ -void modem_context_set_appkey( const uint8_t app_key[16] ); +modem_ctx_rc_t modem_context_set_appkey( const uint8_t app_key[16] ); /** * @brief Update appkey_crc status to invalid. (because appkey is no longer know) @@ -1104,7 +1117,6 @@ bool modem_context_get_network_type( void ); */ void modem_context_set_network_type( bool network_type ); -#if defined( LR11XX_TRANSCEIVER ) /** * @brief get modem radio context * @@ -1119,8 +1131,6 @@ const void* modem_context_get_modem_radio_ctx( void ); */ void modem_context_set_modem_radio_ctx( const void* radio_ctx ); -#endif // LR11XX_TRANSCEIVER - /** * @brief Set D2D metadata in modem context * @@ -1150,6 +1160,14 @@ void modem_set_extended_callback( func_callback, uint8_t extended_uplink_id ); * @param [out ] callback provided by the middleware layer , lbm have to call it once the extended tx is finished */ func_callback modem_get_extended_callback( uint8_t extended_uplink_id ); + +/** + * @brief Take action for leaving the network + * + */ +void modem_leave( void ); + + #ifdef __cplusplus } #endif diff --git a/smtc_modem_core/lorawan_api/lorawan_api.c b/smtc_modem_core/lorawan_api/lorawan_api.c index ab8f1b9..c15c71e 100644 --- a/smtc_modem_core/lorawan_api/lorawan_api.c +++ b/smtc_modem_core/lorawan_api/lorawan_api.c @@ -64,16 +64,20 @@ static struct { - lr1_stack_mac_t lr1_mac_obj; - smtc_real_t real; - smtc_lbt_t lbt_obj; - smtc_dtc_t duty_cycle_obj; - lr1mac_class_c_t class_c_obj; - fifo_ctrl_t fifo_ctrl_obj; - smtc_lr1_beacon_t lr1_beacon_obj; - smtc_ping_slot_t ping_slot_obj; - smtc_multicast_t multicast_obj; - smtc_class_b_d2d_t class_b_d2d_obj; + lr1_stack_mac_t lr1_mac_obj; + smtc_real_t real; + smtc_lbt_t lbt_obj; + smtc_dtc_t duty_cycle_obj; + lr1mac_class_c_t class_c_obj; + fifo_ctrl_t fifo_ctrl_obj; + smtc_lr1_beacon_t lr1_beacon_obj; + smtc_ping_slot_t ping_slot_obj; +#if defined( SMTC_MULTICAST ) + smtc_multicast_t multicast_obj; +#endif +#if defined( SMTC_D2D ) + smtc_class_b_d2d_t class_b_d2d_obj; +#endif lorawan_certification_t lorawan_certif_obj; } lr1mac_core_context; @@ -96,25 +100,14 @@ static void lorawan_api_class_a_downlink_callback( lr1_stack_mac_t* lr1_mac_obje static void lorawan_api_class_c_downlink_callback( lr1mac_class_c_t* class_c_object ); static void lorawan_api_class_b_downlink_callback( smtc_ping_slot_t* class_b_object ); static void lorawan_api_class_b_beacon_callback( smtc_lr1_beacon_t* class_b_beacon_object ); +#if defined( SMTC_D2D ) static void lorawan_api_class_b_d2d_tx_event_callback( smtc_class_b_d2d_t* class_b_d2d_object ); - -void lorawan_rp_callback_api( radio_planner_t* rp ) -{ - rp_radio_irq_callback( rp ); -} +#endif void lorawan_api_init( radio_planner_t* rp ) { smtc_real_region_types_t smtc_real_region_types = SMTC_REAL_REGION_UNKNOWN; -#if defined SX128X - // default region for sx128x projects is 2G4 -#if defined( REGION_WW2G4 ) - smtc_real_region_types = SMTC_REAL_REGION_WW2G4; -#else -#error "Please select supported region" -#endif -#elif defined LR11XX || defined SX126X -// default region for subgig projects is EU_868, then others.. depends of Makefile + #if defined( REGION_EU_868 ) smtc_real_region_types = SMTC_REAL_REGION_EU_868; #elif defined( REGION_US_915 ) @@ -133,9 +126,10 @@ void lorawan_api_init( radio_planner_t* rp ) smtc_real_region_types = SMTC_REAL_REGION_KR_920; #elif defined( REGION_RU_864 ) smtc_real_region_types = SMTC_REAL_REGION_RU_864; +#elif defined( REGION_WW2G4 ) + smtc_real_region_types = SMTC_REAL_REGION_WW2G4; #else #error "Please select supported region" -#endif #endif // init lr1mac core @@ -144,6 +138,7 @@ void lorawan_api_init( radio_planner_t* rp ) fifo_ctrl_init( &fifo_ctrl_obj, fifo_buffer, FIFO_LORAWAN_SIZE ); +#if defined( SMTC_MULTICAST ) smtc_multicast_init( &multicast_obj ); lr1mac_class_c_init( &class_c_obj, &lr1_mac_obj, &multicast_obj, rp, RP_HOOK_ID_CLASS_C, @@ -152,12 +147,22 @@ void lorawan_api_init( radio_planner_t* rp ) smtc_ping_slot_init( &ping_slot_obj, &lr1_mac_obj, &multicast_obj, rp, RP_HOOK_ID_CLASS_B_PING_SLOT, ( void ( * )( void* ) ) smtc_ping_slot_mac_rp_callback, &ping_slot_obj, ( void ( * )( void* ) ) lorawan_api_class_b_downlink_callback, &ping_slot_obj ); +#else + lr1mac_class_c_init( &class_c_obj, &lr1_mac_obj, NULL, rp, RP_HOOK_ID_CLASS_C, + ( void ( * )( void* ) ) lr1mac_class_c_mac_rp_callback, &class_c_obj, + ( void ( * )( void* ) ) lorawan_api_class_c_downlink_callback, &class_c_obj ); + smtc_ping_slot_init( &ping_slot_obj, &lr1_mac_obj, NULL, rp, RP_HOOK_ID_CLASS_B_PING_SLOT, + ( void ( * )( void* ) ) smtc_ping_slot_mac_rp_callback, &ping_slot_obj, + ( void ( * )( void* ) ) lorawan_api_class_b_downlink_callback, &ping_slot_obj ); +#endif smtc_beacon_sniff_init( &lr1_beacon_obj, &ping_slot_obj, &lr1_mac_obj, rp, RP_HOOK_ID_CLASS_B_BEACON, ( void ( * )( void* ) ) lorawan_api_class_b_beacon_callback, &lr1_beacon_obj ); +#if defined( SMTC_D2D ) smtc_class_b_d2d_init( &class_b_d2d_obj, &ping_slot_obj, RP_HOOK_ID_CLASS_B_D2D, ( void ( * )( void* ) ) lorawan_api_class_b_d2d_tx_event_callback, &class_b_d2d_obj ); +#endif lorawan_certification_init( &lorawan_certif_obj ); } @@ -236,6 +241,7 @@ void lorawan_api_class_b_beacon_callback( smtc_lr1_beacon_t* class_b_beacon_obje } } +#if defined( SMTC_D2D ) void lorawan_api_class_b_d2d_tx_event_callback( smtc_class_b_d2d_t* class_b_d2d_object ) { // All transmission(s) performed set to true @@ -244,6 +250,7 @@ void lorawan_api_class_b_d2d_tx_event_callback( smtc_class_b_d2d_t* class_b_d2d_ modem_context_set_class_b_d2d_last_metadata( class_b_d2d_object->multi_cast_group_id, tx_done, class_b_d2d_object->nb_trans_cnt ); } +#endif smtc_real_region_types_t lorawan_api_get_region( void ) { @@ -255,17 +262,17 @@ status_lorawan_t lorawan_api_set_region( smtc_real_region_types_t region_type ) return lr1mac_core_set_region( &lr1_mac_obj, region_type ); } -status_lorawan_t lorawan_api_payload_send( uint8_t fPort, bool fport_enabled, const uint8_t* dataIn, - const uint8_t sizeIn, uint8_t PacketType, uint32_t TargetTimeMS ) +status_lorawan_t lorawan_api_payload_send( uint8_t fport, bool fport_enabled, const uint8_t* data, uint8_t data_len, + uint8_t packet_type, uint32_t target_time_ms ) { - return lr1mac_core_payload_send( &lr1_mac_obj, fPort, fport_enabled, dataIn, sizeIn, PacketType, TargetTimeMS ); + return lr1mac_core_payload_send( &lr1_mac_obj, fport, fport_enabled, data, data_len, packet_type, target_time_ms ); } -status_lorawan_t lorawan_api_payload_send_at_time( uint8_t fPort, bool fport_enabled, const uint8_t* dataIn, - const uint8_t sizeIn, uint8_t PacketType, uint32_t TargetTimeMS ) +status_lorawan_t lorawan_api_payload_send_at_time( uint8_t fport, bool fport_enabled, const uint8_t* data, + uint8_t data_len, uint8_t packet_type, uint32_t target_time_ms ) { - return lr1mac_core_payload_send_at_time( &lr1_mac_obj, fPort, fport_enabled, dataIn, sizeIn, PacketType, - TargetTimeMS ); + return lr1mac_core_payload_send_at_time( &lr1_mac_obj, fport, fport_enabled, data, data_len, packet_type, + target_time_ms ); } status_lorawan_t lorawan_api_send_stack_cid_req( cid_from_device_t cid_req ) @@ -288,9 +295,9 @@ void lorawan_api_join_status_clear( void ) lr1mac_core_join_status_clear( &lr1_mac_obj ); } -status_lorawan_t lorawan_api_dr_strategy_set( dr_strategy_t adrModeSelect ) +status_lorawan_t lorawan_api_dr_strategy_set( dr_strategy_t dr_strategy ) { - return ( lr1mac_core_dr_strategy_set( &lr1_mac_obj, adrModeSelect ) ); + return ( lr1mac_core_dr_strategy_set( &lr1_mac_obj, dr_strategy ) ); } dr_strategy_t lorawan_api_dr_strategy_get( void ) @@ -298,14 +305,14 @@ dr_strategy_t lorawan_api_dr_strategy_get( void ) return lr1mac_core_dr_strategy_get( &lr1_mac_obj ); } -void lorawan_api_dr_custom_set( uint32_t* DataRateCustom ) +void lorawan_api_dr_custom_set( uint32_t* custom_dr ) { - lr1mac_core_dr_custom_set( &lr1_mac_obj, DataRateCustom ); + lr1mac_core_dr_custom_set( &lr1_mac_obj, custom_dr ); } -lr1mac_states_t lorawan_api_process( user_rx_packet_type_t* AvailableRxPacket ) +lr1mac_states_t lorawan_api_process( void ) { - return lr1mac_core_process( &lr1_mac_obj, AvailableRxPacket ); + return lr1mac_core_process( &lr1_mac_obj ); } void lorawan_api_context_load( void ) @@ -328,13 +335,6 @@ int16_t lorawan_api_last_rssi_get( void ) return lr1mac_core_last_rssi_get( &lr1_mac_obj ); } -void lorawan_api_set_default_key( uint8_t default_app_key[16], uint8_t default_dev_eui[8], uint8_t default_join_eui[8] ) -{ - lorawan_api_set_deveui( default_dev_eui ); - lorawan_api_set_joineui( default_join_eui ); - lorawan_api_set_appkey( default_app_key ); -} - void lorawan_api_factory_reset( void ) { lr1mac_core_factory_reset( &lr1_mac_obj ); @@ -360,32 +360,61 @@ uint32_t lorawan_api_devaddr_get( void ) return lr1mac_core_devaddr_get( &lr1_mac_obj ); } -void lorawan_api_get_deveui( uint8_t* DevEui ) +status_lorawan_t lorawan_api_get_deveui( uint8_t* dev_eui ) { - smtc_secure_element_get_deveui( DevEui ); + status_lorawan_t rc = OKLORAWAN; + + if( smtc_secure_element_get_deveui( dev_eui ) != SMTC_SE_RC_SUCCESS ) + { + rc = ERRORLORAWAN; + } + return rc; } -void lorawan_api_set_deveui( const uint8_t* dev_eui ) +status_lorawan_t lorawan_api_set_deveui( const uint8_t* dev_eui ) { - smtc_secure_element_set_deveui( dev_eui ); + status_lorawan_t rc = OKLORAWAN; + + if( smtc_secure_element_set_deveui( dev_eui ) != SMTC_SE_RC_SUCCESS ) + { + rc = ERRORLORAWAN; + } + return rc; } -void lorawan_api_set_appkey( const uint8_t* app_key ) +status_lorawan_t lorawan_api_set_appkey( const uint8_t* app_key ) { // in lorawan 1.0.x SMTC_SE_NWK_KEY is for APP_KEY - smtc_modem_crypto_set_key( SMTC_SE_NWK_KEY, app_key ); + if( smtc_modem_crypto_set_key( SMTC_SE_NWK_KEY, app_key ) != SMTC_MODEM_CRYPTO_RC_SUCCESS ) + { + return ERRORLORAWAN; + } // in lorawan 1.0.x SMTC_SE_APP_KEY is for GEN_APP_KEY(useful in case of multicast features) - smtc_modem_crypto_set_key( SMTC_SE_APP_KEY, app_key ); + if( smtc_modem_crypto_set_key( SMTC_SE_APP_KEY, app_key ) != SMTC_MODEM_CRYPTO_RC_SUCCESS ) + { + return ERRORLORAWAN; + } + return OKLORAWAN; } -void lorawan_api_get_joineui( uint8_t* join_eui ) +status_lorawan_t lorawan_api_get_joineui( uint8_t* join_eui ) { - smtc_secure_element_get_joineui( join_eui ); + status_lorawan_t rc = OKLORAWAN; + if( smtc_secure_element_get_joineui( join_eui ) != SMTC_SE_RC_SUCCESS ) + { + rc = ERRORLORAWAN; + } + return rc; } -void lorawan_api_set_joineui( const uint8_t* join_eui ) +status_lorawan_t lorawan_api_set_joineui( const uint8_t* join_eui ) { - smtc_secure_element_set_joineui( join_eui ); + status_lorawan_t rc = OKLORAWAN; + if( smtc_secure_element_set_joineui( join_eui ) != SMTC_SE_RC_SUCCESS ) + { + rc = ERRORLORAWAN; + } + return rc; } uint8_t lorawan_api_next_power_get( void ) @@ -448,9 +477,9 @@ int32_t lorawan_api_next_free_duty_cycle_ms_get( void ) return lr1mac_core_next_free_duty_cycle_ms_get( &lr1_mac_obj ); } -status_lorawan_t lorawan_api_duty_cycle_enable_set( smtc_dtc_enablement_type_t enable ) +status_lorawan_t lorawan_api_duty_cycle_enable_set( smtc_dtc_enablement_type_t dtc_type ) { - if( smtc_duty_cycle_enable_set( lr1_mac_obj.dtc_obj, enable ) == true ) + if( smtc_duty_cycle_enable_set( lr1_mac_obj.dtc_obj, dtc_type ) == true ) { return OKLORAWAN; } @@ -498,70 +527,118 @@ lorawan_multicast_rc_t lorawan_api_multicast_set_group_session_keys( uint8_t const uint8_t mc_ntw_skey[LORAWAN_KEY_SIZE], const uint8_t mc_app_skey[LORAWAN_KEY_SIZE] ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_multicast_set_group_keys( &multicast_obj, mc_group_id, mc_ntw_skey, mc_app_skey ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_set_group_address( uint8_t mc_group_id, uint32_t mc_group_address ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_multicast_set_group_address( &multicast_obj, mc_group_id, mc_group_address ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_get_group_address( uint8_t mc_group_id, uint32_t* mc_group_address ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_multicast_get_group_address( &multicast_obj, mc_group_id, mc_group_address ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_get_running_status( uint8_t mc_group_id, bool* session_running ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_multicast_get_running_status( &multicast_obj, mc_group_id, session_running ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_c_get_session_status( uint8_t mc_group_id, bool* is_session_started, uint32_t* freq, uint8_t* dr ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) lr1mac_class_c_multicast_get_session_status( &class_c_obj, mc_group_id, is_session_started, freq, dr ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_c_start_session( uint8_t mc_group_id, uint32_t freq, uint8_t dr ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) lr1mac_class_c_multicast_start_session( &class_c_obj, mc_group_id, freq, dr ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_c_stop_session( uint8_t mc_group_id ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) lr1mac_class_c_multicast_stop_session( &class_c_obj, mc_group_id ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_c_stop_all_sessions( void ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) lr1mac_class_c_multicast_stop_all_sessions( &class_c_obj ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_b_get_session_status( uint8_t mc_group_id, bool* is_session_started, bool* waiting_beacon_to_start, uint32_t* freq, uint8_t* dr, uint8_t* ping_slot_periodicity ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_ping_slot_multicast_b_get_session_status( &ping_slot_obj, mc_group_id, is_session_started, waiting_beacon_to_start, freq, dr, ping_slot_periodicity ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_b_start_session( uint8_t mc_group_id, uint32_t freq, uint8_t dr, uint8_t ping_slot_periodicity ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_ping_slot_multicast_b_start_session( &ping_slot_obj, mc_group_id, freq, dr, ping_slot_periodicity ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_b_stop_session( uint8_t mc_group_id ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_ping_slot_multicast_b_stop_session( &ping_slot_obj, mc_group_id ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } lorawan_multicast_rc_t lorawan_api_multicast_b_stop_all_sessions( void ) { +#if defined( SMTC_MULTICAST ) return ( lorawan_multicast_rc_t ) smtc_ping_slot_multicast_b_stop_all_sessions( &ping_slot_obj ); +#else + return LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED; +#endif } uint8_t lorawan_api_rx_ack_bit_get( void ) @@ -745,6 +822,11 @@ bool lorawan_api_is_time_valid( void ) return lr1mac_core_is_time_valid( &lr1_mac_obj ); } +uint32_t lorawan_api_get_timestamp_last_device_time_ans_s( void ) +{ + return lr1mac_core_get_timestamp_last_device_time_ans_s( &lr1_mac_obj ); +} + uint32_t lorawan_api_get_time_left_connection_lost( void ) { return lr1mac_core_get_time_left_connection_lost( &lr1_mac_obj ); @@ -792,7 +874,7 @@ void lorawan_api_lbt_set_state( bool enable ) smtc_lbt_set_state( &lbt_obj, enable ); } -bool lorawan_api_get_state( void ) +bool lorawan_api_lbt_get_state( void ) { return smtc_lbt_get_state( &lbt_obj ); } @@ -878,15 +960,29 @@ smtc_class_b_d2d_status_t lorawan_api_class_b_d2d_request_tx( rx_session_type_t uint16_t nb_ping_slot_tries, uint8_t* ping_slots_mask, uint8_t ping_slots_mask_size ) { +#if defined( SMTC_D2D ) return smtc_class_b_d2d_request_tx( &class_b_d2d_obj, multi_cast_group_id, fport, priority, payload, payload_size, nb_rep, nb_ping_slot_tries, ping_slots_mask, ping_slots_mask_size ); +#else + return SMTC_CLASS_B_D2D_ERROR; +#endif } uint8_t lorawan_api_class_b_d2d_next_max_payload_length_get( rx_session_type_t multi_cast_group_id ) { +#if defined( SMTC_D2D ) return smtc_class_b_d2d_next_max_payload_length_get( &class_b_d2d_obj, multi_cast_group_id ); +#else + return 0; +#endif } +#if defined( LR1110_MODEM_E ) +void lorawan_rp_callback_api( radio_planner_t* rp ) +{ + rp_radio_irq_callback( rp ); +} +#endif // LR1110_MODEM_E /* * ----------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- diff --git a/smtc_modem_core/lorawan_api/lorawan_api.h b/smtc_modem_core/lorawan_api/lorawan_api.h index 20b7742..0f802da 100644 --- a/smtc_modem_core/lorawan_api/lorawan_api.h +++ b/smtc_modem_core/lorawan_api/lorawan_api.h @@ -84,6 +84,7 @@ typedef enum lorawan_multicast_rc_e LORAWAN_MC_RC_ERROR_PARAM, LORAWAN_MC_RC_ERROR_INCOMPATIBLE_SESSION, LORAWAN_MC_RC_ERROR_CLASS_NOT_ENABLED, + LORAWAN_MC_RC_ERROR_NOT_IMPLEMENTED, } lorawan_multicast_rc_t; /* @@ -91,147 +92,149 @@ typedef enum lorawan_multicast_rc_e * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- */ -/*! - * \brief Init the LoRaWAN stack +/** + * @brief Init the LoRaWAN stack + * + * @param [in] rp Pointer on radio planner object */ void lorawan_api_init( radio_planner_t* rp ); -/*! - * \brief - */ -void lorawan_rp_callback_api( radio_planner_t* rp ); - -/*! - * \brief Set the LoRaWAN regional parameters - * \param [out] smtc_real_region_types_t* Region +/** + * @brief Get the current LoRaWAN region + * + * @return smtc_real_region_types_t Current region */ smtc_real_region_types_t lorawan_api_get_region( void ); -/*! - * \brief Set the LoRaWAN regional parameters - * \param [in] smtc_real_region_types_t Region +/** + * @brief Set the current LoRaWAN region + * + * @param [in] region_type LoRaWAN region + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_set_region( smtc_real_region_types_t region_type ); -/*! - * \brief Sends an uplink when it's possible - * \param [in] uint8_t fPort Uplink Fport - * \param [in] bool fport_enabled Fport present or not - * \param [in] const uint8_t* dataInFport User Payload - * \param [in] const uint8_t sizeIn User Payload Size - * \param [in] const uint8_t PacketType User Packet Type : UNCONF_DATA_UP, CONF_DATA_UP, - * \param [in] uint32_t TargetTimeMs RTC time when the packet must be sent - * \return status_lorawan_t - */ -status_lorawan_t lorawan_api_payload_send( uint8_t fPort, bool fport_enabled, const uint8_t* dataIn, - const uint8_t sizeIn, uint8_t PacketType, uint32_t TargetTimeMs ); - -/*! - * \brief Sends an uplink at time - * \param [in] uint8_t fPort Uplink Fport - * \param [in] bool fport_enabled Fport present or not - * \param [in] const uint8_t* dataInFport User Payload - * \param [in] const uint8_t sizeIn User Payload Size - * \param [in] const uint8_t PacketType User Packet Type : UNCONF_DATA_UP, CONF_DATA_UP, - * \param [in] uint32_t TargetTimeMs RTC time when the packet must be sent - * \return status_lorawan_t +/** + * @brief Sends an uplink as soon as possible at a chosen time + * + * @param [in] fport Uplink port + * @param [in] fport_enabled Fport present or not + * @param [in] data User payload + * @param [in] data_len User payload length + * @param [in] packet_type User packet type : UNCONF_DATA_UP, CONF_DATA_UP, + * @param [in] target_time_ms RTC time when the packet should be sent + * @return status_lorawan_t The status of the operation */ -status_lorawan_t lorawan_api_payload_send_at_time( uint8_t fPort, bool fport_enabled, const uint8_t* dataIn, - const uint8_t sizeIn, uint8_t PacketType, uint32_t TargetTimeMs ); +status_lorawan_t lorawan_api_payload_send( uint8_t fport, bool fport_enabled, const uint8_t* data, uint8_t data_len, + uint8_t packet_type, uint32_t target_time_ms ); /** * @brief * - * @param [in] cid_req Command ID request by the User LINK_CHECK_REQ or DEVICE_TIME_REQ + * @param [in] fport Uplink port + * @param [in] fport_enabled Fport present or not + * @param [in] data User payload + * @param [in] data_len User payload length + * @param [in] packet_type User packet type : UNCONF_DATA_UP, CONF_DATA_UP, + * @param [in] target_time_ms RTC time when the packet shall be sent + * @return status_lorawan_t The status of the operation + */ +status_lorawan_t lorawan_api_payload_send_at_time( uint8_t fport, bool fport_enabled, const uint8_t* data, + uint8_t data_len, uint8_t packet_type, uint32_t target_time_ms ); + +/** + * @brief Send a LoRaWAN cid request + * + * @param [in] cid_req Command ID request by the User LINK_CHECK_REQ or DEVICE_TIME_REQ + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_send_stack_cid_req( cid_from_device_t cid_req ); -/*! - * \brief to Send a Join request - * \param [] None - * \return status_lorawan_t +/** + * @brief Send a join request + * + * @param [in] target_time_ms + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_join( uint32_t target_time_ms ); -/*! - * \brief Returns the join state - * \param [] None - * \param [out] Returns the join state NOT_JOINED: the device is joined to a network - * JOINED: the device is not connected - * Always returns JOINED for ABP devices +/** + * @brief Returns the join status + * + * @return join_status_t the join status. NOT_JOINED: the device is not connected + * JOINING: the device is trying to join + * JOINED: the device is joined to a network + * */ join_status_t lorawan_api_isjoined( void ); -/*! - * \brief Rreset the join status to NotJoined - * \param [] None - * \param [out] None +/** + * @brief Clear the join status (reset to NOT_JOINED) + * */ void lorawan_api_join_status_clear( void ); -/*! - * \brief SetDataRateStrategy of the devices - * \remark Refered to the dedicated chapter in Wiki page for detailed explanation about - * implemented data rate choice (distribution data rate). - * \remark The current implementation support 4 different dataRate Strategy : - * STATIC_ADR_MODE for static Devices with ADR managed by the Network - * MOBILE_LONGRANGE_DR_DISTRIBUTION for Mobile Devices with strong Long range requirement - * MOBILE_LOWPER_DR_DISTRIBUTION for Mobile Devices with strong Low power requirement - * JOIN_DR_DISTRIBUTION Dedicated for Join requests - * - * \param [in] dr_strategy_t DataRate Mode (describe above) - * \param [out] None - */ -status_lorawan_t lorawan_api_dr_strategy_set( dr_strategy_t adrModeSelect ); -dr_strategy_t lorawan_api_dr_strategy_get( void ); -void lorawan_api_dr_custom_set( uint32_t* DataRateCustom ); +/** + * @brief Set datarate strategy + * @remark The current implementation support 4 different dataRate Strategy : + * STATIC_ADR_MODE for static Devices with ADR managed by the Network + * MOBILE_LONGRANGE_DR_DISTRIBUTION for Mobile Devices with strong Long range requirement + * MOBILE_LOWPER_DR_DISTRIBUTION for Mobile Devices with strong Low power requirement + * USER_DR_DISTRIBUTION User datarate distribution (can be defined with @ref lorawan_api_dr_custom_set) + * JOIN_DR_DISTRIBUTION Dedicated for Join requests + * @param [in] dr_strategy Datarate strategy (describe above) + * @return status_lorawan_t The status of the operation + */ +status_lorawan_t lorawan_api_dr_strategy_set( dr_strategy_t dr_strategy ); -/*! - * \brief Runs the MAC layer state machine. - * Must be called periodically by the application. Not timing critical. Can be interrupted. - * \remark Not timing critical. Can be interrupted. +/** + * @brief Get the current datarate strategy * - * \param [in] AvailableRxPacket * Return if an applicative packet is available - * \param [out] lr1mac_states_t return the lorawan state machine state + * @return dr_strategy_t Current datatate strategy */ -lr1mac_states_t lorawan_api_process( user_rx_packet_type_t* AvailableRxPacket ); +dr_strategy_t lorawan_api_dr_strategy_get( void ); -/*! - * \brief Return the state of the Radio - * \param [in] none - * \param [out] return the state of the radio (Not yet finalized will be replace by an enum) +/** + * @brief Set user custom datarate + * + * @param [in] custom_dr Custom datarate */ -uint8_t lorawan_api_GetRadioState( void ); +void lorawan_api_dr_custom_set( uint32_t* custom_dr ); -/*! - * \brief Reload the LoraWAN context saved in the flash - * \param [in] none - * \param [out] none +/** + * @brief Runs the MAC layer state machine. Must be called periodically by the application. Not timing critical. Can be + * interrupted. + * + * @return lr1mac_states_t return the lorawan state machine state + */ +lr1mac_states_t lorawan_api_process( void ); + +/** + * @brief Reload the LoraWAN context saved in the flash */ void lorawan_api_context_load( void ); -/*! - * \brief Save The LoraWAN context in the flash - * \param [in] none - * \param [out] none + +/** + * @brief Save The LoraWAN context in the flash */ void lorawan_api_context_save( void ); -/*! - * \brief Get the snr of the last user receive packet - * \param [in] none - * \param [out] Int 16 last snr + +/** + * @brief Get the snr of the last user receive packet + * + * @return int16_t last snr */ int16_t lorawan_api_last_snr_get( void ); -/*! - * \brief Get the snr of the last user receive packet - * \param [in] none - * \param [out] Int 16 last snr + +/** + * @brief Get the snr of the last user receive packet + * + * @return int16_t last rssi */ int16_t lorawan_api_last_rssi_get( void ); -/*! - * \brief Reload the factory Config in the LoraWAN Stack - * \param [in] none - * \param [out] none +/** + * @brief Reload the factory Config in the LoraWAN Stack */ void lorawan_api_factory_reset( void ); @@ -249,195 +252,191 @@ lr1mac_activation_mode_t lorawan_api_get_activation_mode( void ); */ void lorawan_api_set_activation_mode( lr1mac_activation_mode_t activation_mode ); -/*! - * \brief Return the Max payload length allowed for the next transmit - * \remark DataRate + FOPTS + region dependant ( ) - * \remark In any case if user set a too long payload, the send method will answer by an error status - * \param [in] none - * \param [out] Return max payload length for next Transmission +/** + * @brief Return the Max payload length allowed for the next transmit + * @remark DataRate + FOPTS + region dependant ( ) + * @remark In any case if user set a too long payload, the send method will answer by an error status + * + * @return uint32_t The max payload allowed */ uint32_t lorawan_api_next_max_payload_length_get( void ); -/*! - * \brief Return the DevAddr of the device - * \param [in] none - * \param [out] return DevAddr +/** + * @brief Return the DevAddr of the device + * + * @return uint32_t The devaddr */ uint32_t lorawan_api_devaddr_get( void ); /** * @brief Get the DevEUI of the device * - * @param [out] DevEui The Device EUI + * @param [out] dev_eui The Device EUI + * @return status_lorawan_t The status of the operation */ -void lorawan_api_get_deveui( uint8_t* DevEui ); +status_lorawan_t lorawan_api_get_deveui( uint8_t* dev_eui ); /** * @brief Set the DevEUI of the device * - * @param [in] DevEui The Device EUI + * @param [in] dev_eui The Device EUI + * @return status_lorawan_t The status of the operation */ -void lorawan_api_set_deveui( const uint8_t* DevEui ); +status_lorawan_t lorawan_api_set_deveui( const uint8_t* dev_eui ); /** * @brief Set the AppKey of the device * - * @param [in] AppKey The LoRaWan 1.0.x application Key + * @param [in] app_key The LoRaWan 1.0.x application Key + * @return status_lorawan_t The status of the operation */ -void lorawan_api_set_appkey( const uint8_t* AppKey ); +status_lorawan_t lorawan_api_set_appkey( const uint8_t* app_key ); /** * @brief Get the join_eui of the device * * @param [out] join_eui The current Join EUI + * @return status_lorawan_t The status of the operation */ -void lorawan_api_get_joineui( uint8_t* join_eui ); +status_lorawan_t lorawan_api_get_joineui( uint8_t* join_eui ); /** * @brief Set the join_eui of the device * * @param [in] join_eui The Join EUI + * @return status_lorawan_t The status of the operation */ -void lorawan_api_set_joineui( const uint8_t* join_eui ); +status_lorawan_t lorawan_api_set_joineui( const uint8_t* join_eui ); -/*! - * \brief Return the next transmission power - * \remark - * \param [in] none - * \param [out] return the next transmission power +/** + * @brief Return the next transmission power + * + * @return uint8_t the next transmission power */ uint8_t lorawan_api_next_power_get( void ); -/*! - * \brief Return the returns the next data rate - * \remark - * \param [in] none - * \param [out] return the next transmission power +/** + * @brief Return the returns the next datarate + * + * @return uint8_t the next datarate */ uint8_t lorawan_api_next_dr_get( void ); -/*! - * \brief Return the returns the next Tx Frequency - * \remark - * \param [in] none - * \param [out] return the next transmission power +/** + * @brief Return the returns the next Tx Frequency + * + * @return uint32_t the next transmission frequency */ - uint32_t lorawan_api_next_frequency_get( void ); -/*! - * \brief Return the returns the max data rate of all enabled channels - * \remark - * \param [in] none - * \param [out] return the max data rate +/** + * @brief Return the returns the max datarate of all enabled channels + * + * @return uint8_t the max data rate */ uint8_t lorawan_api_max_tx_dr_get( void ); -/*! - * \brief Return the returns the min data rate of all enabled channels - * \remark - * \param [in] none - * \param [out] return the min data rate + +/** + * @brief Return the returns the min datarate of all enabled channels + * + * @return uint8_t the min data rate */ uint8_t lorawan_api_min_tx_dr_get( void ); -/*! - * \brief Return the returns the current data rate mask of all enabled channels - * \remark - * \param [IN] none - * \param [OUT] return the mask data rate +/** + * @brief Return the returns the current data rate mask of all enabled channels + * + * @return uint16_t the mask data rate */ uint16_t lorawan_api_mask_tx_dr_channel_up_dwell_time_check( void ); -/*! - * \brief returns the current state of the MAC layer. - * \remark If the MAC is not in the idle state, the user cannot call any methods except the LoraWanProcess() - * method and the GetLorawanProcessState() method - * \param [in] none - * \param [out] return the next transmission power +/** + * @brief returns the current state of the MAC layer. + * @remark If the MAC is not in the idle state, the user cannot call any methods except the lorawan_api_process() + * and the lorawan_api_state_get() functions + * + * @return lr1mac_states_t THe current state of the stack */ lr1mac_states_t lorawan_api_state_get( void ); -/*! - * \brief returns the number of reset - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief returns the number of reset + * + * @return uint16_t the number of resets */ uint16_t lorawan_api_nb_reset_get( void ); -/*! - * \brief returns the last devnonce - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief returns the last devnonce + * + * @return uint16_t the last devnonce */ uint16_t lorawan_api_devnonce_get( void ); -/*! - * \brief returns the Rx window used by the downlink - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief returns the reception window used by the downlink + * + * @return receive_win_t Reception window */ receive_win_t lorawan_api_rx_window_get( void ); -/*! - * \brief returns the min time to perform a new join request - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief returns the min time to perform a new join request + * + * @return uint32_t The time before a new join request can be issued */ uint32_t lorawan_api_next_join_time_second_get( void ); -/*! - * \brief when > 0, returns the min time to perform a new uplink request - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief when > 0, returns the min time to perform a new uplink request + * + * @return int32_t Miniam time before the stack is able to perform a new uplink */ int32_t lorawan_api_next_free_duty_cycle_ms_get( void ); -/*! - * \brief Enable / disable the dutycycle - * \remark - * \param [in] smtc_dtc_enablement_type_t enable - * \param [out] status_lorawan_t + +/** + * @brief Enable / disable the dutycycle + * + * @param [in] dtc_type Duty cycle type as described in @ref smtc_dtc_enablement_type_t + * @return status_lorawan_t The status of the operation */ -status_lorawan_t lorawan_api_duty_cycle_enable_set( smtc_dtc_enablement_type_t enable ); +status_lorawan_t lorawan_api_duty_cycle_enable_set( smtc_dtc_enablement_type_t dtc_type ); + /** * @brief Get status Enable / disable dutycycle * * @return smtc_dtc_enablement_type_t */ smtc_dtc_enablement_type_t lorawan_api_duty_cycle_enable_get( void ); -/*! - * \brief return the last uplink frame counter - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief return the last uplink frame counter + * + * @return uint32_t Last frame counter */ uint32_t lorawan_api_fcnt_up_get( void ); -/*! - * \brief Get the LoRaWAN hook ID in radio planner - * \remark - * \param [in] none - * \param [out] return + +/** + * @brief Get the LoRaWAN radio planner hook ID + * + * @return uint8_t The used hook it */ uint8_t lorawan_api_rp_hook_id_get( void ); -/*! - * \brief Enable/disable class C - * \remark - * \param [in] uint8_t - * \param [out] none +/** + * @brief Enable/disable class C + * + * @param [in] enable true to enable, false to disable */ void lorawan_api_class_c_enabled( bool enable ); -/*! - * \brief Start class C - * \remark - * \param [in] uint8_t - * \param [out] none + +/** + * @brief Start class C */ void lorawan_api_class_c_start( void ); -/*! - * \brief Stop class C - * \remark - * \param [in] uint8_t - * \param [out] none + +/** + * @brief Stop class C */ void lorawan_api_class_c_stop( void ); @@ -522,7 +521,7 @@ lorawan_multicast_rc_t lorawan_api_multicast_c_stop_all_sessions( void ); /** * @brief Get the status of a class B multicast session * - * @param [in] mc_group_id The multicast group id + * @param [in] mc_group_id The multicast group id * @param [out] is_session_started Boolean to indicate if session is active * @param [out] waiting_beacon_to_start Boolean to indicate if session is waiting for beacon * @param [out] freq The session Rx frequency @@ -620,60 +619,62 @@ void lorawan_api_reset_no_rx_packet_in_mobile_mode_cnt( void ); */ uint16_t lorawan_api_get_current_no_rx_packet_cnt( void ); -/*! - * \brief Set the status of the Modem LoRaWAN certification - * \remark To authorized LoRaWAN certification in modem - * \param [in] uint8_t true/false - * \param [out] return +/** + * @brief Certification: Set the status of the Modem LoRaWAN certification + * @remark To authorized LoRaWAN certification in modem + * + * @param [in] enable true to enable, false to disable */ void lorawan_api_modem_certification_set( uint8_t enable ); -/*! - * \brief Get the status of the LoRaWAN certification - * \remark Is enabled by the Test Tool - * \param [in] none - * \param [out] return uint8_t +/** + * @brief Certification: Get the status of the LoRaWAN certification + * @remark Is enabled by the Test Tool + * + * @return true if enabled + * @return false if disabled */ bool lorawan_api_certification_is_enabled( void ); /** - * @brief Build Class B Beacon Status Indication frame + * @brief Certification: Build Class B Beacon Status Indication frame * - * @param beacon_buffer - * @param beacon_buffer_length - * @param tx_buffer - * @param tx_buffer_length - * @param rssi - * @param snr - * @param beacon_dr - * @param beacon_freq + * @param [in] beacon_buffer Beacon buffer + * @param [in] beacon_buffer_length Length of the buffer + * @param [out] tx_buffer Uplink buffer + * @param [out] tx_buffer_length Uplink buffer length + * @param [in] rssi Beacon rssi + * @param [in] snr Beacon snr + * @param [in] beacon_dr Beacon datarate + * @param [in] beacon_freq Beacon frequency */ void lorawan_api_certification_build_beacon_rx_status_ind( uint8_t* beacon_buffer, uint8_t beacon_buffer_length, uint8_t* tx_buffer, uint8_t* tx_buffer_length, int8_t rssi, int8_t snr, uint8_t beacon_dr, uint32_t beacon_freq ); -/*! - * \brief Get the status of the Modem LoRaWAN certification - * \remark Is certification is authorized in modem - * \param [in] none - * \param [out] return uint8_t + +/** + * @brief Certification: Get the status of the Modem LoRaWAN certification + * @remark Is certification is authorized in modem + * + * @return uint8_t Modem LoRaWAN certification status */ uint8_t lorawan_api_modem_certification_is_enabled( void ); /** - * @brief Get the requested class bu the certification mode + * @brief Certification: Get the requested class of the certification mode * - * @return lorawan_certification_class_t + * @return lorawan_certification_class_t the requested class */ lorawan_certification_class_t lorawan_api_certification_get_requested_class( void ); /** - * @brief call LoRaWAN Certification state machine + * @brief Certification: call LoRaWAN Certification state machine * - * @param rx_buffer - * @param rx_buffer_length - * @param tx_buffer - * @param tx_buffer_length - * @param tx_fport + * @param [in] rx_buffer Reception buffer + * @param [in] rx_buffer_length Reception buffer length + * @param [out] tx_buffer Uplink buffer + * @param [out] tx_buffer_length Uplink buffer length + * @param [out] tx_fport Uplink fport * @return lorawan_certification_parser_ret_t */ lorawan_certification_parser_ret_t lorawan_api_certification( uint8_t* rx_buffer, uint8_t rx_buffer_length, @@ -681,14 +682,14 @@ lorawan_certification_parser_ret_t lorawan_api_certification( uint8_t* rx_buffer uint8_t* tx_fport ); /** - * @brief + * @brief Certification: get uplink periodicity * - * @return uint16_t + * @return uint16_t uplink periodicity */ uint16_t lorawan_api_certification_get_ul_periodicity( void ); /** - * @brief + * @brief Certification: Get frame type * * @return true * @return false @@ -696,16 +697,16 @@ uint16_t lorawan_api_certification_get_ul_periodicity( void ); bool lorawan_api_certification_get_frame_type( void ); /** - * @brief Get the CW configuration requested by the TCL + * @brief Certification: Get the CW configuration requested by the TCL * - * @param timeout_s - * @param frequency - * @param tx_power + * @param [out] timeout_s Timeout for CW + * @param [out] frequency CW frequency + * @param [out] tx_power CW power */ void lorawan_api_certification_get_cw_config( uint16_t* timeout_s, uint32_t* frequency, int8_t* tx_power ); /** - * @brief Get if the CW was requested by the TCL + * @brief Certification: Get if the CW was requested by the TCL * * @return true * @return false @@ -713,57 +714,49 @@ void lorawan_api_certification_get_cw_config( uint16_t* timeout_s, uint32_t* fre bool lorawan_api_certification_is_cw_running( void ); /** - * @brief Set CW as stopped + * @brief Certification: Set CW as stopped * */ void lorawan_api_certification_cw_set_as_stopped( void ); /** - * @brief Get the status of beacon rx status indication control + * @brief Certification: Get the status of beacon rx status indication control * * @return true * @return false */ bool lorawan_api_certification_get_beacon_rx_status_ind_ctrl( void ); -/*! - * \brief Api to choose the lorawan key in case of a crc error - * \remark a crc error is present at the first start - * \param [in] device key - * \param [out] none - */ -void lorawan_api_set_default_key( uint8_t default_app_key[16], uint8_t default_dev_eui[8], - uint8_t default_join_eui[8] ); - -/*! - * \brief return true if stack receive a link adr request - * \remark reset the flag automatically each time the upper layer call this function - * \param [in] void - * \param [out] bool +/** + * @brief return true if stack receive a link adr request + * @remark reset the flag automatically each time the upper layer call this function + * + * @return true + * @return false */ bool lorawan_api_available_link_adr_get( void ); -/*! - * \brief return the current stack obj - * \remark - * \param [in] void - * \param [out] lr1_stack_mac_t* +/** + * @brief return the current stack obj + * + * @return lr1_stack_mac_t* the pointer on stack */ lr1_stack_mac_t* lorawan_api_stack_mac_get( void ); /** - * @brief + * @brief Get the stack fifo pointer * - * @return fifo_ctrl_t* + * @return fifo_ctrl_t* The pointer of the fifo */ fifo_ctrl_t* lorawan_api_get_fifo_obj( void ); /** - * @brief set network type + * @brief Set network type * - * @param network_type true : public, false : private + * @param [in] network_type true : public, false : private */ void lorawan_api_set_network_type( bool network_type ); + /** * @brief get network type * @@ -772,31 +765,33 @@ void lorawan_api_set_network_type( bool network_type ); */ bool lorawan_api_get_network_type( void ); -/*! - * @brief lr1_stack_nb_trans_get - * @remark - * @return nb_trans +/** + * @brief Get current nb trans value + * + * @return uint8_t nb trans value */ uint8_t lorawan_api_nb_trans_get( void ); -/*! - * @brief lorawan_api_nb_trans_set - * @remark - * @param nb_trans have to be smaller than 16 - * @return status_lorawan_t +/** + * @brief Set nb trans value + * @remark Nb trans have to be smaller than 16 + * + * @param [in] nb_trans nb trans value + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_nb_trans_set( uint8_t nb_trans ); /** - * @brief get the current crystal error + * @brief Get the current crystal error * + * @return uint32_t Crystal error */ uint32_t lorawan_api_get_crystal_error( void ); /** - * @brief set the crystal error + * @brief Set the crystal error * - * @param crystal_error + * @param [in] crystal_error Crystal error */ void lorawan_api_set_crystal_error( uint32_t crystal_error ); @@ -815,11 +810,11 @@ lr1mac_version_t lorawan_api_get_spec_version( void ); lr1mac_version_t lorawan_api_get_regional_parameters_version( void ); /** - * @brief Get Network Time + * @brief Convert RTC to GPS epoch time * - * @param rtc_ms - * @param seconds_since_epoch - * @param fractional_second + * @param [in] rtc_ms rtc time + * @param [out] seconds_since_epoch Number of seconds since epoch + * @param [out] fractional_second Fractional second * @return true Time is valid * @return false Time is not valid */ @@ -834,6 +829,13 @@ bool lorawan_api_convert_rtc_to_gps_epoch_time( uint32_t rtc_ms, uint32_t* secon */ bool lorawan_api_is_time_valid( void ); +/** + * @brief + * + * @return uint32_t last timestamp when clock is received + */ +uint32_t lorawan_api_get_timestamp_last_device_time_ans_s( void ); + /** * @brief Get the left delais before to concider device time no more valid * @@ -844,7 +846,9 @@ uint32_t lorawan_api_get_time_left_connection_lost( void ); /** * @brief Configure the callback for the stack when will received the network time sync * - * @param device_time_callback + * @param [in] device_time_callback callback that will be called in case a device time answer happened + * @param [in] context context of the callback + * @param [in] rx_timestamp_s */ void lorawan_api_set_device_time_callback( void ( *device_time_callback )( void* context, uint32_t rx_timestamp_s ), void* context, uint32_t rx_timestamp_s ); @@ -852,8 +856,8 @@ void lorawan_api_set_device_time_callback( void ( *device_time_callback )( void* /** * @brief Set delay in seconds to concider time no more valid if no time sync received * - * @param delay_s - * @return status_lorawan_t + * @param [in] delay_s + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_set_device_time_invalid_delay_s( uint32_t delay_s ); @@ -867,34 +871,34 @@ uint32_t lorawan_api_get_device_time_invalid_delay_s( void ); /** * @brief Get the Margin and the Gateway count returned by the LinkCheckAns mac command * - * @param [out] margin - * @param [out] gw_cnt - * @return status_lorawan_t + * @param [out] margin The demodulation margin + * @param [out] gw_cnt The gateway count + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_get_link_check_ans( uint8_t* margin, uint8_t* gw_cnt ); /** * @brief Get Device Time Request status * - * @return status_lorawan_t + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_get_device_time_req_status( void ); /** * @brief Set the LBT parameters * - * @param [in] listen_duration_ms duration of the listen task - * @param [in] threshold_dbm threshold in dbm to decide if the channel is free or busy - * @param [in] bw_hz bandwith in hertz to listen a channel + * @param [in] listen_duration_ms duration of the listen task + * @param [in] threshold_dbm threshold in dbm to decide if the channel is free or busy + * @param [in] bw_hz bandwith in hertz to listen a channel */ void lorawan_api_lbt_set_parameters( uint32_t listen_duration_ms, int16_t threshold_dbm, uint32_t bw_hz ); /** * @brief Get the configured lbt parameters * - * @param [out] listen_duration_ms duration of the listen task - * @param [out] threshold_dbm threshold in dbm - * @param [out] bw_hz bandwith in hertz + * @param [out] listen_duration_ms duration of the listen task + * @param [out] threshold_dbm threshold in dbm + * @param [out] bw_hz bandwith in hertz */ void lorawan_api_lbt_get_parameters( uint32_t* listen_duration_ms, int16_t* threshold_dbm, uint32_t* bw_hz ); @@ -911,46 +915,44 @@ void lorawan_api_lbt_set_state( bool enable ); * @return true if service is currently enabled * @return false if service is currently disabled */ -bool lorawan_api_get_state( void ); +bool lorawan_api_lbt_get_state( void ); /** * @brief Enable the class B * - * @param enable + * @param [in] enable true to enable class B, false to disable */ void lorawan_api_class_b_enabled( bool enable ); /** * @brief start beacon sniffing - * */ void lorawan_api_beacon_sniff_start( void ); /** * @brief stop beacon sniffing - * */ void lorawan_api_beacon_sniff_stop( void ); /** * @brief Get the beacon metadata * - * @param beacon_metadata + * @param [out] beacon_metadata The beacon metadata */ void lorawan_api_beacon_get_metadata( smtc_beacon_metadata_t* beacon_metadata ); /** * @brief Get Ping Slot Info Request status * - * @return status_lorawan_t + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_get_ping_slot_info_req_status( void ); /** * @brief Set the ping-slot periodicity as described in Link layer specification [TS001] * - * @param ping_slot_periodicity - * @return status_lorawan_t + * @param [in] ping_slot_periodicity Ping slot periodicity + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_set_ping_slot_periodicity( uint8_t ping_slot_periodicity ); @@ -970,11 +972,11 @@ uint8_t lorawan_api_get_ping_slot_periodicity( void ); bool lorawan_api_get_class_b_status( void ); /** - * @brief Convert LoRaWAN Datarate to SF and bandwidth + * @brief Convert LoRaWAN Datarate to SF and bandwidth * - * @param in_dr - * @param out_sf - * @param out_bw + * @param [in] in_dr Datarate + * @param [out] out_sf Corresponding SF + * @param [out] out_bw Corresponding bandwith */ void lorawan_api_lora_dr_to_sf_bw( uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw ); @@ -996,40 +998,40 @@ bool lorawan_api_get_status_push_network_downlink_to_user( void ); /** * @brief Set status of push network downlink (mac commands, beacon, ..) to the user * - * @param enable + * @param [in] enable */ void lorawan_api_set_status_push_network_downlink_to_user( bool enable ); /** * @brief Set the ADR ACK limit and ADR ACK delay regarding the ADR fallback in case no downlink are received * - * @param adr_ack_limit Accepted value: ( adr_ack_limit > 1 ) && ( adr_ack_limit < 128 ) - * @param adr_ack_delay Accepted value: ( adr_ack_delay > 1 ) && ( adr_ack_delay < 128 ) - * @return status_lorawan_t + * @param [in] adr_ack_limit Accepted value: ( adr_ack_limit > 1 ) && ( adr_ack_limit < 128 ) + * @param [in] adr_ack_delay Accepted value: ( adr_ack_delay > 1 ) && ( adr_ack_delay < 128 ) + * @return status_lorawan_t The status of the operation */ status_lorawan_t lorawan_api_set_adr_ack_limit_delay( uint8_t adr_ack_limit, uint8_t adr_ack_delay ); /** - * @brief Get the ADR ACK limit and ADR ACK delay configured regarding the ADR fallback in case no downlink are - * received + * @brief Get the ADR ACK limit and ADR ACK delay configured regarding the ADR fallback in case no downlink are received * - * @param adr_ack_limit - * @param adr_ack_delay + * @param [out] adr_ack_limit the configured adr ack limit + * @param [out] adr_ack_delay the configured adr ack delay */ void lorawan_api_get_adr_ack_limit_delay( uint8_t* adr_ack_limit, uint8_t* adr_ack_delay ); /** * @brief Device To Device Reques Tx * - * @param multi_cast_group_id - * @param fport - * @param priority - * @param payload - * @param payload_size - * @param nb_rep - * @param nb_ping_slot_tries - * @param ping_slots_mask - * @param ping_slots_mask_size + * @param [in] multi_cast_group_id The multicast group identifier + * @param [in] fport The LoRaWAN FPort on which the uplink is done + * @param [in] priority The priority of the D2D uplink + * @param [in] payload The data to be sent + * @param [in] payload_size The number of bytes from payload to be sent + * @param [in] nb_rep The number of repetitions for the D2D uplink + * @param [in] nb_ping_slot_tries The number of ping slot tries before stop + * @param [in] ping_slots_mask The mask defining autorised ping slots for this uplink (shall be in line with + * current ping slot periodicity) + * @param [in] ping_slots_mask_size The mask size * @return smtc_class_b_d2d_status_t */ smtc_class_b_d2d_status_t lorawan_api_class_b_d2d_request_tx( rx_session_type_t multi_cast_group_id, uint8_t fport, @@ -1041,11 +1043,18 @@ smtc_class_b_d2d_status_t lorawan_api_class_b_d2d_request_tx( rx_session_type_t /** * @brief Get the next max payload length for multicast class B session * - * @param multi_cast_group_id - * @return uint8_t + * @param [in] multi_cast_group_id The group ID + * @return uint8_t The next max payload length */ uint8_t lorawan_api_class_b_d2d_next_max_payload_length_get( rx_session_type_t multi_cast_group_id ); +/** + * @brief Direct call to radio planner irq callback + * + * @param [in] rp Radio Planner pointer + */ +void lorawan_rp_callback_api( radio_planner_t* rp ); + #ifdef __cplusplus } #endif diff --git a/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c b/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c index 50d3993..49ec228 100644 --- a/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c +++ b/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c @@ -106,38 +106,34 @@ static status_lorawan_t ping_slot_info_ans_parser( lr1_stack_mac_t* lr1_mac ); void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t activation_mode, smtc_real_region_types_t region ) { - lr1_mac->tx_major_bits = LORAWANR1; - lr1_mac->radio_process_state = RADIOSTATE_IDLE; - lr1_mac->next_time_to_join_seconds = 0; - lr1_mac->join_status = NOT_JOINED; - lr1_mac->type_of_ans_to_send = NOFRAME_TOSEND; - lr1_mac->activation_mode = activation_mode; - lr1_mac->nb_trans = 1; - lr1_mac->available_app_packet = NO_LORA_RXPACKET_AVAILABLE; - lr1_mac->real->region_type = region; - lr1_mac->is_lorawan_modem_certification_enabled = false; - lr1_mac->isr_tx_done_radio_timestamp = 0; - lr1_mac->dev_nonce = 0; - lr1_mac->nb_of_reset = 0; - lr1_mac->adr_mode_select = STATIC_ADR_MODE; - lr1_mac->adr_mode_select_tmp = STATIC_ADR_MODE; - lr1_mac->adr_custom[0] = BSP_USER_DR_DISTRIBUTION_PARAMETERS; - lr1_mac->adr_custom[1] = 0; - lr1_mac->current_win = RX1; - lr1_mac->seconds_since_epoch = 0; - lr1_mac->fractional_second = 0; - lr1_mac->timestamp_last_device_time_ans_s = 0; - lr1_mac->timestamp_tx_done_device_time_req_ms = 0; - lr1_mac->device_time_callback = NULL; - lr1_mac->device_time_callback_context = NULL; + lr1_mac->tx_major_bits = LORAWANR1; + lr1_mac->radio_process_state = RADIOSTATE_IDLE; + lr1_mac->next_time_to_join_seconds = 0; + lr1_mac->join_status = NOT_JOINED; + lr1_mac->type_of_ans_to_send = NOFRAME_TOSEND; + lr1_mac->activation_mode = activation_mode; + lr1_mac->nb_trans = 1; + lr1_mac->available_app_packet = NO_LORA_RXPACKET_AVAILABLE; + lr1_mac->real->region_type = region; + lr1_mac->is_lorawan_modem_certification_enabled = false; + lr1_mac->isr_tx_done_radio_timestamp = 0; + lr1_mac->dev_nonce = 0; + lr1_mac->nb_of_reset = 0; + lr1_mac->adr_mode_select = STATIC_ADR_MODE; + lr1_mac->adr_mode_select_tmp = STATIC_ADR_MODE; + lr1_mac->adr_custom[0] = BSP_USER_DR_DISTRIBUTION_PARAMETERS; + lr1_mac->adr_custom[1] = 0; + lr1_mac->current_win = RX1; + lr1_mac->seconds_since_epoch = 0; + lr1_mac->fractional_second = 0; + lr1_mac->timestamp_last_device_time_ans_s = 0; + lr1_mac->timestamp_tx_done_device_time_req_ms = 0; + lr1_mac->timestamp_tx_done_device_time_req_ms_tmp = 0; + lr1_mac->device_time_callback = NULL; + lr1_mac->device_time_callback_context = NULL; memset( lr1_mac->fine_tune_board_setting_delay_ms, 0, sizeof( lr1_mac->fine_tune_board_setting_delay_ms ) ); memset( lr1_mac->join_nonce, 0xFF, sizeof( lr1_mac->join_nonce ) ); -#if defined( PERF_TEST_ENABLED ) - // bypass join process to allow perf testbench to trigger some modem send tx commands - lr1_mac->join_status = JOINED; -#endif - lr1_stack_mac_session_init( lr1_mac ); } @@ -177,23 +173,33 @@ void lr1_stack_mac_session_init( lr1_stack_mac_t* lr1_mac ) void lr1_stack_mac_tx_frame_build( lr1_stack_mac_t* lr1_mac ) { + uint8_t tx_fopts_length = 0; + if( lr1_mac->tx_fport != PORTNWK ) + { + tx_fopts_length = lr1_mac->tx_fopts_current_length; + } + lr1_mac->tx_fctrl = ( lr1_mac->adr_enable << 7 ) + ( lr1_mac->adr_ack_req << 6 ) + ( lr1_mac->tx_ack_bit << 5 ) + - ( lr1_mac->tx_class_b_bit << 4 ) + ( lr1_mac->tx_fopts_current_length & 0x0F ); + ( lr1_mac->tx_class_b_bit << 4 ) + ( tx_fopts_length & 0x0F ); lr1_mac->tx_ack_bit = 0; mac_header_set( lr1_mac ); frame_header_set( lr1_mac ); - lr1_mac->tx_payload_size = - lr1_mac->app_payload_size + FHDROFFSET + lr1_mac->tx_fport_present + lr1_mac->tx_fopts_current_length; + lr1_mac->tx_payload_size = lr1_mac->app_payload_size + FHDROFFSET + lr1_mac->tx_fport_present + tx_fopts_length; } void lr1_stack_mac_tx_frame_encrypt( lr1_stack_mac_t* lr1_mac ) { + uint8_t tx_fopts_length = 0; + if( lr1_mac->tx_fport != PORTNWK ) + { + tx_fopts_length = lr1_mac->tx_fopts_current_length; + } + if( smtc_modem_crypto_payload_encrypt( - &lr1_mac->tx_payload[FHDROFFSET + lr1_mac->tx_fport_present + lr1_mac->tx_fopts_current_length], - lr1_mac->app_payload_size, ( lr1_mac->tx_fport == PORTNWK ) ? SMTC_SE_NWK_S_ENC_KEY : SMTC_SE_APP_S_KEY, - lr1_mac->dev_addr, UP_LINK, lr1_mac->fcnt_up, - &lr1_mac->tx_payload[FHDROFFSET + lr1_mac->tx_fport_present + lr1_mac->tx_fopts_current_length] ) != + &lr1_mac->tx_payload[FHDROFFSET + lr1_mac->tx_fport_present + tx_fopts_length], lr1_mac->app_payload_size, + ( lr1_mac->tx_fport == PORTNWK ) ? SMTC_SE_NWK_S_ENC_KEY : SMTC_SE_APP_S_KEY, lr1_mac->dev_addr, UP_LINK, + lr1_mac->fcnt_up, &lr1_mac->tx_payload[FHDROFFSET + lr1_mac->tx_fport_present + tx_fopts_length] ) != SMTC_MODEM_CRYPTO_RC_SUCCESS ) { smtc_modem_hal_lr1mac_panic( "Crypto error during payload encryption\n" ); @@ -210,14 +216,14 @@ void lr1_stack_mac_tx_frame_encrypt( lr1_stack_mac_t* lr1_mac ) void lr1_stack_mac_tx_radio_free_lbt( lr1_stack_mac_t* lr1_mac ) { lr1_mac->radio_process_state = RADIOSTATE_TX_ON; - lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + RP_MARGIN_DELAY; + lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + lr1_mac->rp->margin_delay; lr1_mac->send_at_time = true; lr1_stack_mac_tx_radio_start( lr1_mac ); } void lr1_stack_mac_radio_busy_lbt( lr1_stack_mac_t* lr1_mac ) { lr1_mac->radio_process_state = RADIOSTATE_IDLE; - lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + RP_MARGIN_DELAY; + lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + lr1_mac->rp->margin_delay; smtc_real_get_next_channel( lr1_mac ); } void lr1_stack_mac_radio_abort_lbt( lr1_stack_mac_t* lr1_mac ) @@ -228,16 +234,18 @@ void lr1_stack_mac_tx_lora_launch_callback_for_rp( void* rp_void ) { radio_planner_t* rp = ( radio_planner_t* ) rp_void; uint8_t id = rp->radio_task_id; - smtc_modem_hal_start_radio_tcxo( ); + smtc_modem_hal_assert( ralf_setup_lora( rp->radio, &rp->radio_params[id].tx.lora ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_TX_DONE ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_pkt_payload( &( rp->radio->ral ), rp->payload[id], rp->payload_size[id] ) == RAL_STATUS_OK ); - // Wait the exact time + // Wait the exact expected time (ie target - tcxo startup delay) while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { // Do nothing } + // At this time only tcxo startup delay is remaining + smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ral_set_tx( &( rp->radio->ral ) ) == RAL_STATUS_OK ); rp_stats_set_tx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) ); } @@ -246,16 +254,17 @@ void lr1_stack_mac_tx_gfsk_launch_callback_for_rp( void* rp_void ) { radio_planner_t* rp = ( radio_planner_t* ) rp_void; uint8_t id = rp->radio_task_id; - smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ralf_setup_gfsk( rp->radio, &rp->radio_params[id].tx.gfsk ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_TX_DONE ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_pkt_payload( &( rp->radio->ral ), rp->payload[id], rp->payload_size[id] ) == RAL_STATUS_OK ); - // Wait the exact time + // Wait the exact expected time (ie target - tcxo startup delay) while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { } + // At this time only tcxo startup delay is remaining + smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ral_set_tx( &( rp->radio->ral ) ) == RAL_STATUS_OK ); rp_stats_set_tx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) ); } @@ -264,7 +273,6 @@ void lr1_stack_mac_tx_lr_fhss_launch_callback_for_rp( void* rp_void ) { radio_planner_t* rp = ( radio_planner_t* ) rp_void; uint8_t id = rp->radio_task_id; - smtc_modem_hal_start_radio_tcxo( ); // Initialize LR-FHSS smtc_modem_hal_assert( @@ -279,11 +287,13 @@ void lr1_stack_mac_tx_lr_fhss_launch_callback_for_rp( void* rp_void ) ( ral_lr_fhss_memory_state_t ) rp->radio_params[id].lr_fhss_state, rp->radio_params[id].tx.lr_fhss.hop_sequence_id, rp->payload[id], rp->payload_size[id] ) == RAL_STATUS_OK ); - // Wait the exact time + // Wait the exact expected time (ie target - tcxo startup delay) while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { // Do nothing } + // At this time only tcxo startup delay is remaining + smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ral_set_tx( &( rp->radio->ral ) ) == RAL_STATUS_OK ); rp_stats_set_tx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) ); } @@ -292,15 +302,17 @@ void lr1_stack_mac_rx_lora_launch_callback_for_rp( void* rp_void ) { radio_planner_t* rp = ( radio_planner_t* ) rp_void; uint8_t id = rp->radio_task_id; - smtc_modem_hal_start_radio_tcxo( ); + smtc_modem_hal_assert( ralf_setup_lora( rp->radio, &rp->radio_params[id].rx.lora ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_RX_DONE | RAL_IRQ_RX_TIMEOUT | RAL_IRQ_RX_HDR_ERROR | RAL_IRQ_RX_CRC_ERROR ) == RAL_STATUS_OK ); - // Wait the exact time + // Wait the exact expected time (ie target - tcxo startup delay) while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { } + // At this time only tcxo startup delay is remaining + smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ral_set_rx( &( rp->radio->ral ), rp->radio_params[id].rx.timeout_in_ms ) == RAL_STATUS_OK ); rp_stats_set_rx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) ); } @@ -309,14 +321,16 @@ void lr1_stack_mac_rx_gfsk_launch_callback_for_rp( void* rp_void ) { radio_planner_t* rp = ( radio_planner_t* ) rp_void; uint8_t id = rp->radio_task_id; - smtc_modem_hal_start_radio_tcxo( ); + smtc_modem_hal_assert( ralf_setup_gfsk( rp->radio, &rp->radio_params[id].rx.gfsk ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_RX_DONE | RAL_IRQ_RX_TIMEOUT | RAL_IRQ_RX_CRC_ERROR ) == RAL_STATUS_OK ); - // Wait the exact time + // Wait the exact expected time (ie target - tcxo startup delay) while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { } + // At this time only tcxo startup delay is remaining + smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_assert( ral_set_rx( &( rp->radio->ral ), rp->radio_params[id].rx.timeout_in_ms ) == RAL_STATUS_OK ); rp_stats_set_rx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) ); } @@ -399,7 +413,6 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac ) toa = ral_get_gfsk_time_on_air_in_ms( ( &lr1_mac->rp->radio->ral ), ( &gfsk_param.pkt_params ), ( &gfsk_param.mod_params ) ); - SMTC_MODEM_HAL_TRACE_PRINTF( " TxFrequency = %d, FSK\n", lr1_mac->tx_frequency ); rp_task.type = RP_TASK_TYPE_TX_FSK; rp_task.launch_task_callbacks = lr1_stack_mac_tx_gfsk_launch_callback_for_rp; } @@ -449,7 +462,7 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac ) } rp_task.hook_id = my_hook_id; rp_task.duration_time_ms = toa; - rp_task.start_time_ms = lr1_mac->rtc_target_timer_ms; + rp_task.start_time_ms = lr1_mac->rtc_target_timer_ms - smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ); if( lr1_mac->send_at_time == true ) { lr1_mac->send_at_time = false; // reinit the flag @@ -742,7 +755,6 @@ void lr1_stack_mac_rx_timer_configure( lr1_stack_mac_t* lr1_mac, const rx_win_ty uint8_t sf; lr1mac_bandwidth_t bw; uint8_t kbitrate; - uint32_t board_delay; modulation_type_t rx_modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, lr1_mac->rx_data_rate ); @@ -760,8 +772,9 @@ void lr1_stack_mac_rx_timer_configure( lr1_stack_mac_t* lr1_mac, const rx_win_ty smtc_modem_hal_lr1mac_panic( "MODULATION NOT SUPPORTED\n" ); } - board_delay = smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + smtc_modem_hal_get_board_delay_ms( ); - uint32_t board_delay_ms = board_delay + lr1_mac->fine_tune_board_setting_delay_ms[lr1_mac->rx_data_rate]; + uint32_t board_delay_ms = smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + + +smtc_modem_hal_get_board_delay_ms( ) + + lr1_mac->fine_tune_board_setting_delay_ms[lr1_mac->rx_data_rate]; smtc_real_get_rx_window_parameters( lr1_mac, lr1_mac->rx_data_rate, delay_ms, &lr1_mac->rx_window_symb, &lr1_mac->rx_timeout_symb_in_ms, &lr1_mac->rx_timeout_ms, 0 ); @@ -835,7 +848,11 @@ rx_packet_type_t lr1_stack_mac_rx_frame_decode( lr1_stack_mac_t* lr1_mac ) // Case : the receive packet is not a JoinResponse //********************************************************************** uint16_t fcnt_dwn_tmp = 0; - fcnt_dwn_stack_tmp = lr1_mac->fcnt_dwn; +#if defined( PERF_TEST_ENABLED ) + fcnt_dwn_stack_tmp = 0; +#else + fcnt_dwn_stack_tmp = lr1_mac->fcnt_dwn; +#endif status += lr1mac_rx_fhdr_extract( lr1_mac->rx_payload, lr1_mac->rx_payload_size, &( lr1_mac->rx_fopts_length ), &fcnt_dwn_tmp, lr1_mac->dev_addr, &( lr1_mac->rx_metadata.rx_fport ), &( lr1_mac->rx_payload_empty ), &( lr1_mac->rx_fctrl ), lr1_mac->rx_fopts ); @@ -1004,8 +1021,8 @@ void lr1_stack_mac_update_tx_done( lr1_stack_mac_t* lr1_mac ) if( lr1_mac->device_time_user_req == USER_MAC_REQ_REQUESTED ) { - lr1_mac->device_time_user_req = USER_MAC_REQ_SENT; - lr1_mac->timestamp_tx_done_device_time_req_ms = lr1_mac->isr_tx_done_radio_timestamp; + lr1_mac->device_time_user_req = USER_MAC_REQ_SENT; + lr1_mac->timestamp_tx_done_device_time_req_ms_tmp = lr1_mac->isr_tx_done_radio_timestamp; } if( lr1_mac->ping_slot_info_user_req == USER_MAC_REQ_REQUESTED ) @@ -1020,7 +1037,7 @@ void lr1_stack_mac_update( lr1_stack_mac_t* lr1_mac ) lr1_mac->adr_ack_delay = lr1_mac->adr_ack_delay_init; lr1_mac->type_of_ans_to_send = NOFRAME_TOSEND; - if( lr1_mac->join_status == NOT_JOINED ) + if( lr1_mac->join_status == JOINING ) { // get current timestamp to check which duty cycle will be applied uint32_t current_time_s = smtc_modem_hal_get_time_in_s( ); @@ -1046,6 +1063,9 @@ void lr1_stack_mac_update( lr1_stack_mac_t* lr1_mac ) lr1_mac->next_time_to_join_seconds = current_time_s + ( lr1_stack_toa_get( lr1_mac ) ) * 10; // ts=cur_ts+(toa_s*10000) = cur_ts + (toa_ms / 1000) * 10000 = cur_ts + toa_ms*10 } + + // Now join status can be set as not joined + lr1_mac->join_status = NOT_JOINED; } if( lr1_mac->adr_ack_cnt >= lr1_mac->adr_ack_limit ) @@ -1227,8 +1247,9 @@ status_lorawan_t lr1_stack_mac_cmd_parse( lr1_stack_mac_t* lr1_mac ) { if( device_time_ans_parser( lr1_mac ) == OKLORAWAN ) { - lr1_mac->device_time_user_req = USER_MAC_REQ_ACKED; - lr1_mac->timestamp_last_device_time_ans_s = smtc_modem_hal_get_time_in_s( ); + lr1_mac->device_time_user_req = USER_MAC_REQ_ACKED; + lr1_mac->timestamp_tx_done_device_time_req_ms = lr1_mac->timestamp_tx_done_device_time_req_ms_tmp; + lr1_mac->timestamp_last_device_time_ans_s = smtc_modem_hal_get_time_in_s( ); if( lr1_mac->device_time_callback != NULL ) { lr1_mac->device_time_callback( lr1_mac->device_time_callback_context, @@ -1281,7 +1302,11 @@ void lr1_stack_mac_join_request_build( lr1_stack_mac_t* lr1_mac ) SMTC_MODEM_HAL_TRACE_ARRAY( "JoinEUI", join_eui, 8 ); if( lr1_mac->dev_nonce < 0xFFFF ) { +#if defined( PERF_TEST_ENABLED ) + lr1_mac->dev_nonce = 0; +#else lr1_mac->dev_nonce += 1; +#endif } SMTC_MODEM_HAL_TRACE_PRINTF( "DevNonce 0x%x\n", lr1_mac->dev_nonce ); lr1_mac->tx_mtype = JOIN_REQUEST; @@ -1317,6 +1342,12 @@ status_lorawan_t lr1_stack_mac_join_accept( lr1_stack_mac_t* lr1_mac ) memcpy1( join_nonce, &lr1_mac->rx_payload[1], 6 ); +#if defined( PERF_TEST_ENABLED ) + lr1_mac->join_nonce[0] = 0; + lr1_mac->join_nonce[1] = 0; + lr1_mac->join_nonce[2] = 0; +#endif + join_nonce_prev = lr1_mac->join_nonce[0]; join_nonce_prev |= lr1_mac->join_nonce[1] << 8; join_nonce_prev |= lr1_mac->join_nonce[2] << 16; @@ -1570,13 +1601,21 @@ static void frame_header_set( lr1_stack_mac_t* lr1_mac ) lr1_mac->tx_payload[5] = lr1_mac->tx_fctrl; lr1_mac->tx_payload[6] = ( uint8_t )( ( lr1_mac->fcnt_up & 0x000000FF ) ); lr1_mac->tx_payload[7] = ( uint8_t )( ( lr1_mac->fcnt_up & 0x0000FF00 ) >> 8 ); - for( int i = 0; i < lr1_mac->tx_fopts_current_length; i++ ) + + if( lr1_mac->tx_fport == PORTNWK ) { - lr1_mac->tx_payload[8 + i] = lr1_mac->tx_fopts_current_data[i]; + lr1_mac->tx_payload[8] = lr1_mac->tx_fport; } - if( lr1_mac->tx_fport_present == true ) + else { - lr1_mac->tx_payload[8 + lr1_mac->tx_fopts_current_length] = lr1_mac->tx_fport; + for( int i = 0; i < lr1_mac->tx_fopts_current_length; i++ ) + { + lr1_mac->tx_payload[8 + i] = lr1_mac->tx_fopts_current_data[i]; + } + if( lr1_mac->tx_fport_present == true ) + { + lr1_mac->tx_payload[8 + lr1_mac->tx_fopts_current_length] = lr1_mac->tx_fport; + } } } diff --git a/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h b/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h index 6c60438..406c825 100644 --- a/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h +++ b/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h @@ -69,12 +69,11 @@ typedef struct lr1_stack_mac_s /*******************************************/ /* Update by Link ADR command */ /*******************************************/ - uint8_t tx_data_rate; - uint8_t tx_data_rate_adr; - int8_t tx_power; - uint16_t channel_mask; - uint8_t nb_trans; - uint8_t nb_trans_cpt; + uint8_t tx_data_rate; + uint8_t tx_data_rate_adr; + int8_t tx_power; + uint8_t nb_trans; + uint8_t nb_trans_cpt; /********************************************/ /* Update by RxParamaSetupRequest */ /********************************************/ @@ -109,24 +108,24 @@ typedef struct lr1_stack_mac_s lr1mac_activation_mode_t activation_mode; // LoRaWan Mac Data for uplink - uint8_t tx_fport; - bool tx_fport_present; - uint8_t tx_mtype; - uint8_t tx_major_bits; - uint8_t tx_fctrl; - uint8_t tx_ack_bit; - uint8_t tx_class_b_bit; - uint8_t app_payload_size; - uint8_t tx_payload_size; - uint8_t tx_payload[255]; - uint8_t tx_fopts_length; - uint8_t tx_fopts_data[DEVICE_MAC_PAYLOAD_MAX_SIZE]; - uint8_t tx_fopts_lengthsticky; - uint8_t tx_fopts_datasticky[15]; - uint8_t tx_fopts_current_length; - uint8_t tx_fopts_current_data[15]; + uint8_t tx_fport; + bool tx_fport_present; + lr1mac_layer_param_t tx_mtype; + uint8_t tx_major_bits; + uint8_t tx_fctrl; + uint8_t tx_ack_bit; + uint8_t tx_class_b_bit; + uint8_t app_payload_size; + uint8_t tx_payload_size; + uint8_t tx_payload[255]; + uint8_t tx_fopts_length; + uint8_t tx_fopts_data[DEVICE_MAC_PAYLOAD_MAX_SIZE]; + uint8_t tx_fopts_lengthsticky; + uint8_t tx_fopts_datasticky[15]; + uint8_t tx_fopts_current_length; + uint8_t tx_fopts_current_data[15]; // LoRaWan Mac Data for downlink - uint8_t rx_ftype; + lr1mac_layer_param_t rx_ftype; uint8_t rx_major; uint8_t rx_fctrl; uint8_t rx_ack_bit; @@ -196,7 +195,6 @@ typedef struct lr1_stack_mac_s int16_t fine_tune_board_setting_delay_ms[16]; int32_t rx_offset_ms; uint32_t timestamp_failsafe; - uint32_t dev_addr_isr; uint8_t type_of_ans_to_send; uint8_t nwk_payload_index; lr1mac_states_t lr1mac_state; @@ -214,6 +212,7 @@ typedef struct lr1_stack_mac_s uint32_t seconds_since_epoch; uint32_t fractional_second; uint32_t timestamp_tx_done_device_time_req_ms; + uint32_t timestamp_tx_done_device_time_req_ms_tmp; uint32_t timestamp_last_device_time_ans_s; void ( *device_time_callback )( void*, uint32_t ); void* device_time_callback_context; diff --git a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c index fb8f9a0..e926bce 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c +++ b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c @@ -267,7 +267,8 @@ void smtc_beacon_sniff_stop( smtc_lr1_beacon_t* lr1_beacon_obj ) smtc_class_b_beacon_t smtc_beacon_sniff_start( smtc_lr1_beacon_t* lr1_beacon_obj ) { - uint32_t rtc = smtc_modem_hal_get_time_in_ms( ) + 1000; // +1000 to let time for rp enqueue task in case of abort task + uint32_t rtc = + smtc_modem_hal_get_time_in_ms( ) + 1000; // +1000 to let time for rp enqueue task in case of abort task uint32_t seconds_since_epoch = 0; uint32_t fractional_second = 0; uint8_t beacon_id; diff --git a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c index 25bfb66..4d3cd41 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c +++ b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c @@ -355,8 +355,8 @@ static void class_b_d2d_rp_request( smtc_class_b_d2d_t* class_b_d2d_obj ) // Enqueue this tx inside , start time is given by the ping slot object itself and // corrected using preambule length rp_task_t rp_task = { 0 }; - rp_task.type = RP_TASK_TYPE_CAD; // in the radioplanner task is a special case in rp, radio config in case of - // negative cad can be launched without enqueued a new rp task + rp_task.type = RP_TASK_TYPE_CAD_TO_TX; // in the radioplanner task is a special case in rp, radio config in case of + // negative cad can be launched without enqueued a new rp task rp_task.hook_id = class_b_d2d_obj->classb_d2d_id_rp; rp_task.state = RP_TASK_STATE_SCHEDULE; // get the rp param set by the ping slot object itself diff --git a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c index db77d67..22a860f 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c +++ b/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c @@ -170,10 +170,14 @@ void smtc_ping_slot_init( smtc_ping_slot_t* ping_slot_obj, lr1_stack_mac_t* lr1_ ping_slot_obj->rx_session_param[RX_SESSION_UNICAST] = &ping_slot_obj->rx_session_param_unicast; ping_slot_obj->d2d_callback = NULL; - // start to 1 because index 0 is set with lorawan class A value - for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ ) + + if( multicast_obj != NULL ) { - ping_slot_obj->rx_session_param[i + 1] = &multicast_obj->rx_session_param[i]; + // start to 1 because index 0 is set with lorawan class A value + for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ ) + { + ping_slot_obj->rx_session_param[i + 1] = &multicast_obj->rx_session_param[i]; + } } } @@ -184,7 +188,9 @@ void smtc_ping_slot_stop( smtc_ping_slot_t* ping_slot_obj ) return; } ping_slot_obj->enabled = false; +#if defined( SMTC_MULTICAST ) smtc_ping_slot_multicast_b_stop_all_sessions( ping_slot_obj ); +#endif rp_task_abort( ping_slot_obj->rp, ping_slot_obj->ping_slot_id4rp ); // Sent empty uplink at the upper layer to inform Network that class B is disabled @@ -267,7 +273,6 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj ) uint32_t rx_timeout_symb_locked_in_ms_tmp; rp_task_t rp_task = { 0 }; int32_t rx_offset_ms_tmp; - int8_t board_delay_ms; rp_hook_status_t rp_status; do @@ -405,7 +410,8 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj ) rp_task.hook_id = ping_slot_obj->ping_slot_id4rp; rp_task.state = RP_TASK_STATE_SCHEDULE; rp_task.schedule_task_low_priority = true; - board_delay_ms = smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + smtc_modem_hal_get_board_delay_ms( ); + int8_t board_delay_ms = + smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + smtc_modem_hal_get_board_delay_ms( ); smtc_real_get_rx_start_time_offset_ms( ping_slot_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate, board_delay_ms, RX_SESSION_PARAM_CURRENT->rx_window_symb, &rx_offset_ms_tmp ); @@ -573,6 +579,7 @@ uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_100us, return ret; } +#if defined( SMTC_MULTICAST ) smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_start_session( smtc_ping_slot_t* ping_slot_obj, uint8_t mc_group_id, uint32_t freq, uint8_t dr, uint8_t ping_slot_periodicity ) @@ -671,6 +678,7 @@ smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_get_session_status( smtc_p return SMTC_MC_RC_OK; } +#endif /* * ----------------------------------------------------------------------------- diff --git a/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c b/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c index b993693..93402de 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c +++ b/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c @@ -119,10 +119,13 @@ void lr1mac_class_c_init( lr1mac_class_c_t* class_c_obj, lr1_stack_mac_t* lr1_ma class_c_obj->rx_session_param[RX_SESSION_UNICAST] = &class_c_obj->rx_session_param_unicast; - // start to 1 because index 0 is set with lorawan class A value - for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ ) + if( multicast_obj != NULL ) { - class_c_obj->rx_session_param[i + 1] = &multicast_obj->rx_session_param[i]; + // start to 1 because index 0 is set with lorawan class A value + for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ ) + { + class_c_obj->rx_session_param[i + 1] = &multicast_obj->rx_session_param[i]; + } } rp_release_hook( class_c_obj->rp, class_c_obj->class_c_id4rp ); @@ -147,7 +150,9 @@ void lr1mac_class_c_stop( lr1mac_class_c_t* class_c_obj ) return; } class_c_obj->started = false; +#if defined( SMTC_MULTICAST ) lr1mac_class_c_multicast_stop_all_sessions( class_c_obj ); +#endif rp_task_abort( class_c_obj->rp, class_c_obj->class_c_id4rp ); class_c_obj->rx_metadata.rx_window = RECEIVE_NONE; } @@ -382,6 +387,7 @@ void lr1mac_class_c_mac_rp_callback( lr1mac_class_c_t* class_c_obj ) } } +#if defined( SMTC_MULTICAST ) smtc_multicast_config_rc_t lr1mac_class_c_multicast_start_session( lr1mac_class_c_t* class_c_obj, uint8_t mc_group_id, uint32_t freq, uint8_t dr ) { @@ -544,6 +550,7 @@ smtc_multicast_config_rc_t lr1mac_class_c_multicast_get_session_status( lr1mac_c return SMTC_MC_RC_OK; } +#endif /* * ----------------------------------------------------------------------------- diff --git a/smtc_modem_core/lr1mac/src/lr1mac_core.c b/smtc_modem_core/lr1mac/src/lr1mac_core.c index 3ace97e..eb55678 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_core.c +++ b/smtc_modem_core/lr1mac/src/lr1mac_core.c @@ -86,7 +86,7 @@ static const char* smtc_name_lr_fhss_cr[] = { "CR 5/6", "CR 2/3", "CR 1/2", "CR static uint32_t failsafe_timstamp_get( lr1_stack_mac_t* lr1_mac_obj ); static rp_status_t rp_status_get( lr1_stack_mac_t* lr1_mac_obj ); static void copy_user_payload( lr1_stack_mac_t* lr1_mac_obj, const uint8_t* data_in, const uint8_t size_in ); -static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj, user_rx_packet_type_t* available_rx_packet ); +static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj ); static void save_devnonce_rst( const lr1_stack_mac_t* lr1_mac_obj ); static void load_devnonce_reset( lr1_stack_mac_t* lr1_mac_obj ); static void try_recover_nvm( lr1_stack_mac_t* lr1_mac_obj ); @@ -179,16 +179,15 @@ void lr1mac_core_init( lr1_stack_mac_t* lr1_mac_obj, smtc_real_t* real, smtc_lbt /* LoraWanProcess Method */ /***********************************************************************************************/ -lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packet_type_t* available_rx_packet ) +lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj ) { uint8_t myhook_id; rp_hook_get_id( lr1_mac_obj->rp, ( void* ) ( ( lr1_mac_obj ) ), &myhook_id ); - *available_rx_packet = NO_LORA_RXPACKET_AVAILABLE; #if !defined( TEST_BYPASS_JOIN_DUTY_CYCLE ) if( lr1mac_core_certification_get( lr1_mac_obj ) == false ) { - if( ( lr1_mac_joined_status_get( lr1_mac_obj ) == NOT_JOINED ) && + if( ( lr1_mac_joined_status_get( lr1_mac_obj ) == JOINING ) && ( ( int32_t )( lr1_mac_obj->next_time_to_join_seconds - smtc_modem_hal_get_time_in_s( ) ) > 0 ) ) { SMTC_MODEM_HAL_TRACE_PRINTF( "TOO SOON TO JOIN time is %d time target is : %d\n", @@ -207,7 +206,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packe } if( lr1_mac_obj->radio_process_state == RADIOSTATE_ABORTED_BY_RP ) { - lr1mac_mac_update( lr1_mac_obj, available_rx_packet ); + lr1mac_mac_update( lr1_mac_obj ); } switch( lr1_mac_obj->lr1mac_state ) @@ -267,8 +266,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packe if( smtc_lbt_get_state( lr1_mac_obj->lbt_obj ) == true ) { smtc_lbt_listen_channel( ( lr1_mac_obj->lbt_obj ), lr1_mac_obj->tx_frequency, lr1_mac_obj->send_at_time, - lr1_mac_obj->rtc_target_timer_ms - RP_MARGIN_DELAY, - lr1_stack_toa_get( lr1_mac_obj ) ); + lr1_mac_obj->rtc_target_timer_ms, lr1_stack_toa_get( lr1_mac_obj ) ); } else { @@ -284,7 +282,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packe ( lr1_mac_obj->rp->stats.tx_last_toa_ms[myhook_id] << lr1_mac_obj->max_duty_cycle_index ) - lr1_mac_obj->rp->stats.tx_last_toa_ms[myhook_id]; - if( lr1_mac_obj->join_status == NOT_JOINED ) + if( lr1_mac_obj->join_status == JOINING ) { // save devnonce after the end of TX save_devnonce_rst( lr1_mac_obj ); @@ -321,7 +319,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packe else { DBG_PRINT_WITH_LINE( "Receive a Valid downlink RX1 for Hook Id = %d", myhook_id ); - lr1mac_mac_update( lr1_mac_obj, available_rx_packet ); + lr1mac_mac_update( lr1_mac_obj ); } } else @@ -356,7 +354,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packe { DBG_PRINT_WITH_LINE( "RX2 Timeout for Hook Id = %d", myhook_id ); } - lr1mac_mac_update( lr1_mac_obj, available_rx_packet ); + lr1mac_mac_update( lr1_mac_obj ); } break; @@ -401,7 +399,7 @@ status_lorawan_t lr1mac_core_join( lr1_stack_mac_t* lr1_mac_obj, uint32_t target uint32_t current_timestamp = smtc_modem_hal_get_time_in_s( ); lr1_mac_obj->timestamp_failsafe = current_timestamp; lr1_mac_obj->rtc_target_timer_ms = target_time_ms; - lr1_mac_obj->join_status = NOT_JOINED; + lr1_mac_obj->join_status = JOINING; smtc_real_init( lr1_mac_obj ); @@ -452,6 +450,7 @@ void lr1mac_core_join_status_clear( lr1_stack_mac_t* lr1_mac_obj ) lr1_mac_obj->join_status = NOT_JOINED; lr1mac_core_abort( lr1_mac_obj ); smtc_real_init_join_snapshot_channel_mask( lr1_mac_obj ); + lr1_mac_obj->retry_join_cpt = 0; } /**************************************************/ @@ -469,11 +468,13 @@ status_lorawan_t lr1mac_core_send_stack_cid_req( lr1_stack_mac_t* lr1_mac_obj, c ( lr1_mac_obj->device_time_user_req != USER_MAC_REQ_REQUESTED ) && ( lr1_mac_obj->ping_slot_info_user_req != USER_MAC_REQ_REQUESTED ) ) + { if( lr1_mac_obj->tx_fopts_current_length > 0 ) { size_in += lr1_mac_obj->tx_fopts_current_length; - memcpy1( data_in, lr1_mac_obj->tx_fopts_datasticky, lr1_mac_obj->tx_fopts_current_length ); + memcpy1( data_in, lr1_mac_obj->tx_fopts_current_data, lr1_mac_obj->tx_fopts_current_length ); } + } switch( cid_req ) { @@ -514,7 +515,7 @@ status_lorawan_t lr1mac_core_send_stack_cid_req( lr1_stack_mac_t* lr1_mac_obj, c } status_lorawan_t lr1mac_core_payload_send_at_time( lr1_stack_mac_t* lr1_mac_obj, uint8_t fport, bool fport_enabled, - const uint8_t* data_in, const uint8_t size_in, uint8_t packet_type, + const uint8_t* data_in, uint8_t size_in, uint8_t packet_type, uint32_t target_time_ms ) { status_lorawan_t status = @@ -529,9 +530,14 @@ status_lorawan_t lr1mac_core_payload_send_at_time( lr1_stack_mac_t* lr1_mac_obj, } status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t fport, bool fport_enabled, - const uint8_t* data_in, const uint8_t size_in, uint8_t packet_type, + const uint8_t* data_in, uint8_t size_in, uint8_t packet_type, uint32_t target_time_ms ) { + if( fport_enabled == false ) + { + size_in = 0; + } + status_lorawan_t status = smtc_real_is_payload_size_valid( lr1_mac_obj, lr1_mac_obj->tx_data_rate, size_in, lr1_mac_obj->uplink_dwell_time ); if( status == ERRORLORAWAN ) @@ -546,7 +552,7 @@ status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t } if( lr1mac_core_get_activation_mode( lr1_mac_obj ) == ACTIVATION_MODE_OTAA ) { - if( lr1_mac_obj->join_status == NOT_JOINED ) + if( lr1_mac_obj->join_status != JOINED ) { SMTC_MODEM_HAL_TRACE_ERROR( "OTAA DEVICE NOT JOINED YET\n" ); return ERRORLORAWAN; @@ -956,6 +962,11 @@ bool lr1mac_core_is_time_valid( lr1_stack_mac_t* lr1_mac_obj ) return false; } +uint32_t lr1mac_core_get_timestamp_last_device_time_ans_s( lr1_stack_mac_t* lr1_mac_obj ) +{ + return lr1_mac_obj->timestamp_last_device_time_ans_s; +} + uint32_t lr1mac_core_get_time_left_connection_lost( lr1_stack_mac_t* lr1_mac_obj ) { uint32_t rtc_s = smtc_modem_hal_get_time_in_s( ); @@ -1108,9 +1119,14 @@ void lr1mac_core_get_adr_ack_limit_delay( lr1_stack_mac_t* lr1_mac_obj, uint8_t* static void copy_user_payload( lr1_stack_mac_t* lr1_mac_obj, const uint8_t* data_in, const uint8_t size_in ) { - memcpy1( - &( lr1_mac_obj->tx_payload[FHDROFFSET + lr1_mac_obj->tx_fport_present + lr1_mac_obj->tx_fopts_current_length] ), - data_in, size_in ); + uint8_t tx_fopts_length = 0; + if( lr1_mac_obj->tx_fport != PORTNWK ) + { + tx_fopts_length = lr1_mac_obj->tx_fopts_current_length; + } + + memcpy1( &( lr1_mac_obj->tx_payload[FHDROFFSET + lr1_mac_obj->tx_fport_present + tx_fopts_length] ), data_in, + size_in ); } static uint32_t failsafe_timstamp_get( lr1_stack_mac_t* lr1_mac_obj ) @@ -1132,7 +1148,7 @@ void lr1mac_core_abort( lr1_stack_mac_t* lr1_mac_obj ) rp_task_abort( lr1_mac_obj->rp, lr1_mac_obj->stack_id4rp ); } -static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj, user_rx_packet_type_t* available_rx_packet ) +static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj ) { lr1_mac_obj->radio_process_state = RADIOSTATE_IDLE; @@ -1156,7 +1172,6 @@ static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj, user_rx_packet_type lr1_stack_mac_cmd_parse( lr1_mac_obj ); } lr1_stack_mac_update( lr1_mac_obj ); - *available_rx_packet = lr1_mac_obj->available_app_packet; /// If those MAC commands are not acked, set as not requested /// if( lr1_mac_obj->link_check_user_req == USER_MAC_REQ_SENT ) @@ -1219,6 +1234,9 @@ static void save_devnonce_rst( const lr1_stack_mac_t* lr1_mac_obj ) ctx.crc = lr1mac_utilities_crc( ( uint8_t* ) &ctx, sizeof( ctx ) - 4 ); smtc_modem_hal_context_store( CONTEXT_DEVNONCE, ( uint8_t* ) &ctx, sizeof( ctx ) ); + // dummy context reading to ensure context store is done before exiting the function + lr1_counter_context_t dummy_context = { 0 }; + smtc_modem_hal_context_restore( CONTEXT_DEVNONCE, ( uint8_t* ) &dummy_context, sizeof( dummy_context ) ); } static void load_devnonce_reset( lr1_stack_mac_t* lr1_mac_obj ) diff --git a/smtc_modem_core/lr1mac/src/lr1mac_core.h b/smtc_modem_core/lr1mac/src/lr1mac_core.h index 9a53ae2..4fdfe19 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_core.h +++ b/smtc_modem_core/lr1mac/src/lr1mac_core.h @@ -136,10 +136,9 @@ void lr1mac_core_dr_custom_set( lr1_stack_mac_t* lr1_mac_obj, uint32_t* datarate * @remark Must be called periodically by the application. Not timing critical. Can be interrupted. * * @param lr1_mac_obj - * @param [out] AvailableRxPacket Return if an applicative packet is available * @return lr1mac_states_t return the lorawan state machine state */ -lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj, user_rx_packet_type_t* AvailableRxPacket ); +lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj ); /** * @brief Reload the LoraWAN context saved in the flash @@ -292,8 +291,8 @@ join_status_t lr1_mac_joined_status_get( lr1_stack_mac_t* lr1_mac_obj ); * @return status_lorawan_t */ status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t fPort, bool fport_enabled, - const uint8_t* dataIn, const uint8_t sizeIn, uint8_t PacketType, - uint32_t target_time_ms ); + const uint8_t* dataIn, uint8_t sizeIn, uint8_t PacketType, + uint32_t target_time_ms ); /** * @brief Send an uplink payload at the target time @@ -308,8 +307,8 @@ status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t * @return status_lorawan_t */ status_lorawan_t lr1mac_core_payload_send_at_time( lr1_stack_mac_t* lr1_mac_obj, uint8_t fport, bool fport_enabled, - const uint8_t* data_in, const uint8_t size_in, uint8_t packet_type, - uint32_t target_time_ms ); + const uint8_t* data_in, uint8_t size_in, uint8_t packet_type, + uint32_t target_time_ms ); /** * @brief Send a device mac command request to the network @@ -532,6 +531,14 @@ bool lr1mac_core_convert_rtc_to_gps_epoch_time( lr1_stack_mac_t* lr1_mac_obj, ui */ bool lr1mac_core_is_time_valid( lr1_stack_mac_t* lr1_mac_obj ); +/** + * @brief + * + * @param lr1_mac_obj + * @return uint32_t + */ +uint32_t lr1mac_core_get_timestamp_last_device_time_ans_s( lr1_stack_mac_t* lr1_mac_obj ); + /** * @brief Get the left delais before to concider device time no more valid * diff --git a/smtc_modem_core/lr1mac/src/lr1mac_defs.h b/smtc_modem_core/lr1mac/src/lr1mac_defs.h index f430819..e9b5cbe 100644 --- a/smtc_modem_core/lr1mac/src/lr1mac_defs.h +++ b/smtc_modem_core/lr1mac/src/lr1mac_defs.h @@ -168,14 +168,6 @@ typedef enum lr1mac_radio_state_e RADIOSTATE_RX_FINISHED, RADIOSTATE_ABORTED_BY_RP, } lr1mac_radio_state_t; - -typedef enum lr1mac_tx_status_e -{ - TX_BEGIN, - TX_ABORTED_DUTY_CYCLE, - TX_ABORTED_BY_RP, // lbt or anything else - TX_OK, -} lr1mac_tx_status_t; /********************************************************************************/ /* LoraWan Mac Layer Parameters */ /********************************************************************************/ @@ -292,12 +284,6 @@ enum CHANNEL_ENABLED, }; -typedef enum valid_channel_e -{ - UNVALID_CHANNEL, - VALID_CHANNEL, -} valid_channel_t; - // User Config for Adr Mode select typedef enum dr_strategy_e { @@ -352,13 +338,12 @@ typedef enum user_rx_packet_type_e { NO_LORA_RXPACKET_AVAILABLE, LORA_RX_PACKET_AVAILABLE, - MULTI_CAST_G0_RX_PACKET_AVAILABLE, - MULTI_CAST_G1_RX_PACKET_AVAILABLE, } user_rx_packet_type_t; typedef enum join_status_e { NOT_JOINED, + JOINING, JOINED, } join_status_t; @@ -377,24 +362,6 @@ typedef enum modulation_type_e LR_FHSS, } modulation_type_t; -typedef enum crc_mode_e -{ - CRC_YES, - CRC_NO -} crc_mode_t; - -typedef enum iq_mode_e -{ - IQ_NORMAL, - IQ_INVERTED -} iq_mode_t; - -typedef enum header_mode_e -{ - IMPLICIT_HEADER, - EXPLICIT_HEADER -} header_mode_t; - /** * @brief Rx Session type enum * @@ -402,10 +369,12 @@ typedef enum header_mode_e typedef enum rx_session_type_e { RX_SESSION_UNICAST, +#if defined( SMTC_MULTICAST ) || defined( SMTC_D2D ) RX_SESSION_MULTICAST_G0, RX_SESSION_MULTICAST_G1, RX_SESSION_MULTICAST_G2, RX_SESSION_MULTICAST_G3, +#endif RX_SESSION_COUNT, } rx_session_type_t; @@ -430,23 +399,24 @@ typedef enum smtc_multicast_fpending_bit_prioritization_e /********************************************************************************/ typedef enum receive_win_s { - RECEIVE_NONE, - RECEIVE_ON_RX1, - RECEIVE_ON_RX2, - RECEIVE_ON_RXC, - RECEIVE_ON_RXC_MC_GRP0, - RECEIVE_ON_RXC_MC_GRP1, - RECEIVE_ON_RXC_MC_GRP2, - RECEIVE_ON_RXC_MC_GRP3, - RECEIVE_ON_RXB, - RECEIVE_ON_RXB_MC_GRP0, - RECEIVE_ON_RXB_MC_GRP1, - RECEIVE_ON_RXB_MC_GRP2, - RECEIVE_ON_RXB_MC_GRP3, - RECEIVE_ON_RXBEACON, - // deprecated RECEIVE_NACK = 0x40, - // deprecated RECEIVE_ACK_ON_RX1 = 0x81, - // deprecated RECEIVE_ACK_ON_RX2 = 0x82, + RECEIVE_NONE = 0, + RECEIVE_ON_RX1 = 1, + RECEIVE_ON_RX2 = 2, + RECEIVE_ON_RXC = 3, +#if defined( SMTC_MULTICAST ) + RECEIVE_ON_RXC_MC_GRP0 = 4, + RECEIVE_ON_RXC_MC_GRP1 = 5, + RECEIVE_ON_RXC_MC_GRP2 = 6, + RECEIVE_ON_RXC_MC_GRP3 = 7, +#endif + RECEIVE_ON_RXB = 8, +#if defined( SMTC_MULTICAST ) + RECEIVE_ON_RXB_MC_GRP0 = 9, + RECEIVE_ON_RXB_MC_GRP1 = 10, + RECEIVE_ON_RXB_MC_GRP2 = 11, + RECEIVE_ON_RXB_MC_GRP3 = 12, +#endif + RECEIVE_ON_RXBEACON = 13, } receive_win_t; typedef struct lr1mac_down_metadata_s diff --git a/smtc_modem_core/lr1mac/src/services/smtc_lbt.c b/smtc_modem_core/lr1mac/src/services/smtc_lbt.c index c849a55..314595a 100644 --- a/smtc_modem_core/lr1mac/src/services/smtc_lbt.c +++ b/smtc_modem_core/lr1mac/src/services/smtc_lbt.c @@ -103,7 +103,6 @@ void smtc_lbt_launch_callback_for_rp( void* rp_void ) uint8_t id = rp->radio_task_id; int16_t rssi_tmp; smtc_modem_hal_start_radio_tcxo( ); - ral_init( &( rp->radio->ral ) ); smtc_modem_hal_assert( ral_set_pkt_type( &( rp->radio->ral ), rp->radio_params[id].pkt_type ) == RAL_STATUS_OK ); smtc_modem_hal_assert( ral_set_rf_freq( &( rp->radio->ral ), rp->radio_params[id].rx.gfsk.rf_freq_in_hz ) == RAL_STATUS_OK ); @@ -175,7 +174,8 @@ void smtc_lbt_listen_channel( smtc_lbt_t* lbt_obj, uint32_t freq, bool is_at_tim rp_task.duration_time_ms = lbt_obj->listen_duration_ms + tx_duration_ms; rp_task.type = RP_TASK_TYPE_LBT; rp_task.launch_task_callbacks = smtc_lbt_launch_callback_for_rp; - rp_task.start_time_ms = target_time_ms - lbt_obj->listen_duration_ms; + rp_task.start_time_ms = + target_time_ms - lbt_obj->listen_duration_ms - smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ); if( is_at_time == true ) { rp_task.state = RP_TASK_STATE_SCHEDULE; @@ -184,13 +184,18 @@ void smtc_lbt_listen_channel( smtc_lbt_t* lbt_obj, uint32_t freq, bool is_at_tim { rp_task.state = RP_TASK_STATE_ASAP; } - SMTC_MODEM_HAL_TRACE_PRINTF( " Listen Frequency = %u during %d ms \n", freq, - lbt_obj->listen_duration_ms - LAP_OF_TIME_TO_GET_A_RSSI_VALID ); + if( rp_task_enqueue( lbt_obj->rp, &rp_task, NULL, 0, &radio_params ) != RP_HOOK_STATUS_OK ) { SMTC_MODEM_HAL_TRACE_PRINTF( "Radio planner hook %d is busy \n", my_hook_id ); } + else + { + SMTC_MODEM_HAL_TRACE_PRINTF( " Listen Frequency = %u during %d ms \n", freq, + lbt_obj->listen_duration_ms - LAP_OF_TIME_TO_GET_A_RSSI_VALID ); + } } + void smtc_lbt_rp_callback( smtc_lbt_t* lbt_obj ) { uint32_t tcurrent_ms; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c index cc9a4b5..baf31db 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c @@ -148,7 +148,6 @@ void region_as_923_config( lr1_stack_mac_t* lr1_mac, uint8_t group_id ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_AS_923; const_lbt_bw_hz = LBT_BW_HZ_AS_923; const_max_payload_m = &M_as_923[0][0]; - const_max_payload_n = &N_as_923[0][0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AS_923[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AS_923[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h index 896b283..2451463 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h @@ -215,12 +215,6 @@ static const uint32_t datarates_to_bandwidths_as_923[] = { BW125, BW125, BW125, static const uint8_t M_as_923[2][8] = { { 59, 59, 123, 123, 250, 250, 250, 250 }, // [0][dr] dwell time Off { 0, 0, 19, 61, 133, 250, 250, 250 } }; // [1][dr] dwell time On -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_as_923[2][8] = { { 51, 51, 115, 115, 242, 242, 242, 242 }, // [0][dr] dwell time Off - { 0, 0, 11, 53, 125, 242, 242, 242 } }; // [1][dr] dwell time On - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c index a812547..f5ed945 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c @@ -134,7 +134,6 @@ void region_au_915_config( lr1_stack_mac_t* lr1_mac ) const_dtc_supported = DTC_SUPPORTED_AU_915; const_lbt_supported = LBT_SUPPORTED_AU_915; const_max_payload_m = &M_au_915[0][0]; - const_max_payload_n = &N_au_915[0][0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AU_915[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AU_915[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h index 87a3d7f..5f458bc 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h @@ -60,7 +60,7 @@ extern "C" { #define JOIN_ACCEPT_DELAY1_AU_915 (5) // define in seconds #define JOIN_ACCEPT_DELAY2_AU_915 (6) // define in seconds #define RECEIVE_DELAY1_AU_915 (1) // define in seconds -#if defined( LR11XX ) || defined( SX1262 ) +#if defined( LR11XX ) || defined( SX1262 ) || defined( SX1268 ) // This value must be the MIN of MAX supported by the region and the radio, region is 30dBm but radio is 22dBm ERP (+2 to EIRP) #define TX_POWER_EIRP_AU_915 (24) // define in dbm #else @@ -232,14 +232,6 @@ static const uint8_t M_au_915[2][16] = { { 0, 0, 19, 61, 133, 250, 250, 58, 61, 137, 250, 250, 250, 250, 0, 0 } // [1][dr] dwell time On }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_au_915[2][16] = { - { 51, 51, 51, 115, 242, 242, 242, 50, 53, 129, 242, 242, 242, 242, 0, 0 }, // [0][dr] dwell time Off - { 0, 0, 11, 53, 125, 242, 242, 50, 53, 129, 242, 242, 242, 242, 0, 0 } // [1][dr] dwell time On -}; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c index 7de8675..7b571e1 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c @@ -131,7 +131,6 @@ void region_cn_470_config( lr1_stack_mac_t* lr1_mac ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470; const_lbt_bw_hz = LBT_BW_HZ_CN_470; const_max_payload_m = &M_cn_470[0]; - const_max_payload_n = &N_cn_470[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h index 0d7bd11..061bae5 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h @@ -262,11 +262,6 @@ static const uint32_t datarates_to_bandwidths_cn_470[] = { BW125, BW125, BW125, */ static const uint8_t M_cn_470[8] = { 0, 31, 94, 192, 250, 250, 250, 250 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_cn_470[8] = { 0, 23, 86, 184, 242, 242, 242, 242 }; - /** * Mobile long range datarate distribution * DR0: 0%, // DR0 Not allowed in CN470 diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c index 731695e..5b22903 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c @@ -124,7 +124,6 @@ void region_cn_470_rp_1_0_config( lr1_stack_mac_t* lr1_mac ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470_RP_1_0; const_lbt_bw_hz = LBT_BW_HZ_CN_470_RP_1_0; const_max_payload_m = &M_cn_470_rp_1_0[0]; - const_max_payload_n = &N_cn_470_rp_1_0[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470_RP_1_0[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470_RP_1_0[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h index a99d742..e7e28bb 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h @@ -167,11 +167,6 @@ static const uint32_t datarates_to_bandwidths_cn_470_rp_1_0[] = { BW125, BW125, */ static const uint8_t M_cn_470_rp_1_0[] = { 59, 59, 59, 123, 250, 250 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_cn_470_rp_1_0[] = { 51, 51, 51, 115, 242, 242 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c index a57dd6a..28387fc 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c @@ -125,7 +125,6 @@ void region_eu_868_config( lr1_stack_mac_t* lr1_mac ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_EU_868; const_lbt_bw_hz = LBT_BW_HZ_EU_868; const_max_payload_m = &M_eu_868[0]; - const_max_payload_n = &N_eu_868[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_EU_868[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_EU_868[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h index 8b312b1..98377a5 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h @@ -238,11 +238,6 @@ static const uint32_t datarates_to_lr_fhss_cr_eu_868[NUMBER_OF_TX_DR_EU_868] = { */ static const uint8_t M_eu_868[12] = { 59, 59, 59, 123, 250, 250, 250, 250, 58, 123, 58, 123 }; -/** - * Payload max size table definition in bytes without FHDROFFSET - */ -static const uint8_t N_eu_868[12] = { 51, 51, 51, 115, 242, 242, 242, 242, 50, 115, 50, 115 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c index b67c29b..ec68707 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c @@ -118,7 +118,6 @@ void region_in_865_config( lr1_stack_mac_t* lr1_mac ) const_dtc_supported = DTC_SUPPORTED_IN_865; const_lbt_supported = LBT_SUPPORTED_IN_865; const_max_payload_m = &M_in_865[0]; - const_max_payload_n = &N_in_865[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_IN_865[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_IN_865[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h index 9944654..3698fab 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h @@ -182,11 +182,6 @@ static const uint32_t datarates_to_bandwidths_in_865[] = { BW125, BW125, BW125, */ static const uint8_t M_in_865[8] = { 59, 59, 59, 123, 250, 250, 250, 250 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_in_865[8] = { 51, 51, 51, 115, 242, 242, 242, 242 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c index fd64b72..5b7b1ed 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c @@ -121,7 +121,6 @@ void region_kr_920_config( lr1_stack_mac_t* lr1_mac ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_KR_920; const_lbt_bw_hz = LBT_BW_HZ_KR_920; const_max_payload_m = &M_kr_920[0]; - const_max_payload_n = &N_kr_920[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_KR_920[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_KR_920[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h index 2fe339b..8cfe3dc 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h @@ -173,11 +173,6 @@ static const uint32_t datarates_to_bandwidths_kr_920[] = { BW125, BW125, BW125, */ static const uint8_t M_kr_920[6] = { 59, 59, 59, 123, 250, 250 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_kr_920[6] = { 51, 51, 51, 115, 242, 242 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c index 3b2327d..ccc79fa 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c @@ -124,7 +124,6 @@ void region_ru_864_config( lr1_stack_mac_t* lr1_mac ) const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_RU_864; const_lbt_bw_hz = LBT_BW_HZ_RU_864; const_max_payload_m = &M_ru_864[0]; - const_max_payload_n = &N_ru_864[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_RU_864[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_RU_864[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h index 472f72b..71f2835 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h @@ -190,11 +190,6 @@ static const uint32_t datarates_to_bandwidths_ru_864[] = { BW125, BW125, BW125, */ static const uint8_t M_ru_864[8] = { 59, 59, 59, 123, 250, 250, 250, 250 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_ru_864[8] = { 51, 51, 51, 115, 242, 242, 242, 242 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c index 982dcc2..8b0ffb8 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c @@ -133,7 +133,6 @@ void region_us_915_config( lr1_stack_mac_t* lr1_mac ) const_dtc_supported = DTC_SUPPORTED_US_915; const_lbt_supported = LBT_SUPPORTED_US_915; const_max_payload_m = &M_us_915[0]; - const_max_payload_n = &N_us_915[0]; const_coding_rate = RAL_LORA_CR_4_5; const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_US_915[0]; const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_US_915[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h index 0e41ee8..1d47292 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h @@ -60,7 +60,7 @@ extern "C" { #define JOIN_ACCEPT_DELAY1_US_915 (5) // define in seconds #define JOIN_ACCEPT_DELAY2_US_915 (6) // define in seconds #define RECEIVE_DELAY1_US_915 (1) // define in seconds -#if defined( LR11XX ) || defined( SX1262 ) +#if defined( LR11XX ) || defined( SX1262 ) || defined( SX1268 ) // This value must be the MIN of MAX supported by the region and the radio, region is 30dBm but radio is 22dBm ERP (+2 to EIRP) #define TX_POWER_EIRP_US_915 (24) // define in dbm #else @@ -224,11 +224,6 @@ static const uint32_t datarates_to_lr_fhss_cr_us_915[NUMBER_OF_TX_DR_US_915] = { */ static const uint8_t M_us_915[] = { 19, 61, 133, 250, 250, 58, 133, 0, 61, 137, 250, 250, 250, 250, 0, 0 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_us_915[] = { 11, 53, 125, 242, 242, 50, 125, 0, 53, 129, 242, 242, 242, 242, 0, 0 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c index e6dcf38..e371e3a 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c @@ -117,16 +117,21 @@ void region_ww2g4_config( lr1_stack_mac_t* lr1_mac ) const_dtc_supported = DTC_SUPPORTED_WW2G4; const_lbt_supported = LBT_SUPPORTED_WW2G4; const_max_payload_m = &M_ww2g4[0]; - const_max_payload_n = &N_ww2g4[0]; const_coding_rate = RAL_LORA_CR_LI_4_8; - const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_WW2G4[0]; - const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_WW2G4[0]; - const_join_dr_distri = &JOIN_DR_DISTRIBUTION_WW2G4[0]; - const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0]; - const_cf_list_type_supported = CF_LIST_SUPPORTED_WW2G4; - const_beacon_dr = BEACON_DR_WW2G4; - const_beacon_frequency = BEACON_FREQ_WW2G4; - const_ping_slot_frequency = PING_SLOT_FREQ_WW2G4; +#if defined( WW2G4_SINGLE_DATARATE ) + const_join_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0]; + const_mobile_lowpower_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0]; + const_mobile_longrange_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0]; +#else + const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_WW2G4[0]; + const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_WW2G4[0]; + const_join_dr_distri = &JOIN_DR_DISTRIBUTION_WW2G4[0]; +#endif + const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0]; + const_cf_list_type_supported = CF_LIST_SUPPORTED_WW2G4; + const_beacon_dr = BEACON_DR_WW2G4; + const_beacon_frequency = BEACON_FREQ_WW2G4; + const_ping_slot_frequency = PING_SLOT_FREQ_WW2G4; real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0]; real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0]; diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h index 5046b84..9251ad6 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h @@ -179,11 +179,6 @@ static const uint32_t datarates_to_bandwidths_ww2g4[] = { BW800, BW800, BW800, B */ static const uint8_t M_ww2g4[8] = { 59, 123, 228, 228, 228, 228, 228, 228 }; -/** - * Payload max size table definition in bytes - */ -static const uint8_t N_ww2g4[8] = { 51, 115, 220, 220, 220, 220, 220, 220 }; - /** * Mobile long range datarate distribution * DR0: 20%, diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c b/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c index 85580f4..a14a463 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c @@ -1525,11 +1525,11 @@ status_lorawan_t smtc_real_is_payload_size_valid( lr1_stack_mac_t* lr1_mac, uint #endif status_lorawan_t status = - ( ( size + lr1_mac->tx_fopts_current_length ) > const_max_payload_n[index] ) ? ERRORLORAWAN : OKLORAWAN; + ( ( size + lr1_mac->tx_fopts_current_length ) > ( const_max_payload_m[index] - 8 ) ) ? ERRORLORAWAN : OKLORAWAN; if( status == ERRORLORAWAN ) { SMTC_MODEM_HAL_TRACE_PRINTF( "Invalid size (data:%d + FOpts:%d) > %d for dr: %d\n", size, - lr1_mac->tx_fopts_current_length, const_max_payload_n[index], dr ); + lr1_mac->tx_fopts_current_length, ( const_max_payload_m[index] - 8 ), dr ); } return ( status ); } @@ -2069,7 +2069,7 @@ status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_ { if( SMTC_GET_BIT8( unwrapped_channel_mask_ctx, i ) == CHANNEL_ENABLED ) { - for( uint8_t dr = const_min_tx_dr; dr < const_max_tx_dr; dr++ ) + for( uint8_t dr = const_min_tx_dr; dr <= const_max_tx_dr; dr++ ) { if( SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[i], dr ) == 1 ) { @@ -2845,10 +2845,9 @@ void smtc_real_get_rx_window_parameters( lr1_stack_mac_t* lr1_mac, uint8_t datar min_rx_symb_duration_ms += 2; } - *rx_timeout_symb_in_ms = MAX( ( ( ( ( rx_delay_ms * 2 * lr1_mac->crystal_error ) / 1000 ) + - ( MIN_RX_WINDOW_SYMB * tsymbol_us ) ) / - 1000 ), - min_rx_symb_duration_ms ); + *rx_timeout_symb_in_ms = MAX( + ( ( ( ( rx_delay_ms * 2 * lr1_mac->crystal_error ) / 1000 ) + ( MIN_RX_WINDOW_SYMB * tsymbol_us ) ) / 1000 ), + min_rx_symb_duration_ms ); *rx_window_symb = MIN( MAX( ( ( *rx_timeout_symb_in_ms * 1000 ) / tsymbol_us ), MIN_RX_WINDOW_SYMB ), MAX_RX_WINDOW_SYMB ); diff --git a/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h b/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h index 779f2f2..e57d762 100644 --- a/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h +++ b/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h @@ -275,7 +275,6 @@ typedef struct smtc_real_const_s int16_t const_lbt_threshold_dbm; uint32_t const_lbt_bw_hz; const uint8_t* const_max_payload_m; - const uint8_t* const_max_payload_n; ral_lora_cr_t const_coding_rate; uint8_t const_dtc_number_of_band; const uint16_t* const_dtc_by_band; @@ -328,7 +327,6 @@ typedef struct smtc_real_const_s #define const_lbt_threshold_dbm lr1_mac->real->real_const.const_lbt_threshold_dbm #define const_lbt_bw_hz lr1_mac->real->real_const.const_lbt_bw_hz #define const_max_payload_m lr1_mac->real->real_const.const_max_payload_m -#define const_max_payload_n lr1_mac->real->real_const.const_max_payload_n #define const_coding_rate lr1_mac->real->real_const.const_coding_rate #define const_dtc_number_of_band lr1_mac->real->real_const.const_dtc_number_of_band #define const_dtc_by_band lr1_mac->real->real_const.const_dtc_by_band diff --git a/smtc_modem_core/modem_config/smtc_modem_hal_dbg_trace.h b/smtc_modem_core/modem_config/smtc_modem_hal_dbg_trace.h index e4574b1..008d641 100644 --- a/smtc_modem_core/modem_config/smtc_modem_hal_dbg_trace.h +++ b/smtc_modem_core/modem_config/smtc_modem_hal_dbg_trace.h @@ -102,7 +102,7 @@ extern "C" { #define MODEM_HAL_DBG_TRACE_COLOR_DEFAULT "" #endif -#if ( MODEM_HAL_DBG_TRACE ) && !defined (PERF_TEST_ENABLED) +#if ( MODEM_HAL_DBG_TRACE ) #define SMTC_MODEM_HAL_TRACE_PRINTF( ... ) smtc_modem_hal_print_trace ( __VA_ARGS__ ) @@ -184,7 +184,7 @@ extern "C" { #define SMTC_MODEM_HAL_TRACE_ERROR_DEBUG( ... ) #define SMTC_MODEM_HAL_TRACE_ARRAY_DEBUG( msg, array, len ) #define SMTC_MODEM_HAL_TRACE_PACKARRAY_DEBUG( ... ) - #endif + #endif #else //Trace default definitions @@ -208,14 +208,6 @@ extern "C" { #define SMTC_MODEM_HAL_TRACE_PACKARRAY_DEBUG( ... ) #endif -#if defined (PERF_TEST_ENABLED) - #define SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( ... ) smtc_modem_hal_print_trace ( __VA_ARGS__ ) -#else - #define SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( ... ) -#endif - - - #if ( MODEM_HAL_DBG_TRACE_RP == MODEM_HAL_FEATURE_ON ) #define SMTC_MODEM_HAL_RP_TRACE_MSG( msg ) \ do \ diff --git a/smtc_modem_core/modem_core/smtc_modem.c b/smtc_modem_core/modem_core/smtc_modem.c index 388002c..c749471 100644 --- a/smtc_modem_core/modem_core/smtc_modem.c +++ b/smtc_modem_core/modem_core/smtc_modem.c @@ -49,9 +49,19 @@ #include "modem_context.h" #include "smtc_real_defs.h" #include "lorawan_api.h" + +#if defined( ADD_SMTC_ALC_SYNC ) #include "alc_sync.h" +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_FILE_UPLOAD ) #include "file_upload.h" +#endif // ADD_SMTC_FILE_UPLOAD + +#if defined( ADD_SMTC_STREAM ) #include "stream.h" +#endif // ADD_SMTC_STREAM + #include "radio_planner.h" #include "ral.h" #include "smtc_modem_utilities.h" @@ -61,10 +71,12 @@ #include "ralf.h" #if defined( LR1110_MODEM_E ) -#include "smtc_modem_e_api_extension.h" +// #include "smtc_modem_e_api_extension.h" // TODO GDG I removed but what about this ? +#include "smtc_basic_modem_lr11xx_api_extension.h" #include "smtc_rtc_compensation.h" #include "pool_mem.h" -#include "smtc_crypto_se.h" +#include "smtc_modem_e_internal_utilities.h" +// #include "smtc_crypto_se.h" // TODO GDG I removed but what about this ? #if defined( _MODEM_E_WIFI_ENABLE ) #include "wifi_ctrl_api.h" #endif // _MODEM_E_WIFI_ENABLE @@ -73,12 +85,13 @@ #endif //_MODEM_E_GNSS_ENABLE #endif // LR1110_MODEM_E -#if defined( LR11XX_TRANSCEIVER ) +#if defined( LR11XX_TRANSCEIVER ) || defined( LR1110_MODEM_E ) #include "smtc_basic_modem_lr11xx_api_extension.h" +#endif // LR11XX_TRANSCEIVER || LR1110_MODEM_E + #if defined( USE_LR11XX_CE ) #include "lr11xx_system.h" #endif // USE_LR11XX_CE -#endif // LR11XX_TRANSCEIVER /* * ----------------------------------------------------------------------------- @@ -107,7 +120,15 @@ * --- PRIVATE CONSTANTS ------------------------------------------------------- */ -#define MAX_CRYSTAL_ERROR 10 +#if !defined( LR1110_MODEM_E ) +#define MODEM_FW_VERSION_MAJOR LORA_BASICS_MODEM_FW_VERSION_MAJOR +#define MODEM_FW_VERSION_MINOR LORA_BASICS_MODEM_FW_VERSION_MINOR +#define MODEM_FW_VERSION_PATCH LORA_BASICS_MODEM_FW_VERSION_PATCH +#else +#define MODEM_FW_VERSION_MAJOR 1 +#define MODEM_FW_VERSION_MINOR 1 +#define MODEM_FW_VERSION_PATCH 8 +#endif /* * ----------------------------------------------------------------------------- @@ -145,7 +166,8 @@ static bool stream_bypass_enabled = false; #else // !defined( LR1110_MODEM_E ) uint8_t modem_buffer[242]; -struct +#if defined( ADD_SMTC_FILE_UPLOAD ) +static struct { uint32_t* upload_pdata; uint32_t upload_size; @@ -162,10 +184,32 @@ struct #define stream_bypass_enabled modem_api_context.stream_bypass_enabled #endif // LORAWAN_BYPASS_ENABLED // clang-format on +#endif // ADD_SMTC_FILE_UPLOAD radio_planner_t modem_radio_planner; smtc_modem_services_t smtc_modem_services_ctx; +// user_radio_access +struct +{ + // LBT configuration status + bool lbt_config_available; + rp_status_t user_radio_irq_status; + uint32_t user_radio_irq_timestamp; + uint16_t spare; +#if !defined( LR1110_MODEM_E ) + void ( *user_end_task_callback_0 )( smtc_modem_rp_status_t* status ); + void ( *user_end_task_callback_1 )( smtc_modem_rp_status_t* status ); + void ( *user_end_task_callback_2 )( smtc_modem_rp_status_t* status ); +#endif // !LR1110_MODEM_E +} smtc_modem_ctx; + +#define lbt_config_available smtc_modem_ctx.lbt_config_available +#define user_radio_irq_status smtc_modem_ctx.user_radio_irq_status +#define user_radio_irq_timestamp smtc_modem_ctx.user_radio_irq_timestamp +#define user_end_task_callback_0 smtc_modem_ctx.user_end_task_callback_0 +#define user_end_task_callback_1 smtc_modem_ctx.user_end_task_callback_1 +#define user_end_task_callback_2 smtc_modem_ctx.user_end_task_callback_2 #endif // !defined( LR1110_MODEM_E ) /* @@ -193,9 +237,11 @@ smtc_modem_rp_radio_status_t convert_rp_to_user_radio_access_rp_s void empty_callback( void* ctx ); void user_radio_access_callback( void* ctx ); +#if !defined( LR1110_MODEM_E ) void callback_rp_user_radio_access_0( void* ctx ); void callback_rp_user_radio_access_1( void* ctx ); void callback_rp_user_radio_access_2( void* ctx ); +#endif // !LR1110_MODEM_E /* * ----------------------------------------------------------------------------- @@ -217,10 +263,8 @@ void smtc_modem_init( const ralf_t* radio, void ( *callback_event )( void ) ) ral_init( &( radio->ral ) ); ral_set_sleep( &( radio->ral ), true ); -#if defined( LR11XX_TRANSCEIVER ) // Save modem radio context in case of direct access to radio by the modem modem_context_set_modem_radio_ctx( radio->ral.context ); -#endif // LR11XX_TRANSCEIVER // init radio planner and attach corresponding radio irq rp_init( &modem_radio_planner, radio ); @@ -232,10 +276,11 @@ void smtc_modem_init( const ralf_t* radio, void ( *callback_event )( void ) ) // init modem supervisor #if defined( LR1110_MODEM_E ) - smtc_rtc_compensation_init( &modem_radio_planner, RTC_CLK_COMPENSATION_ID_RP ); + smtc_rtc_compensation_init( &modem_radio_planner, RP_HOOK_ID_RTC_COMPENSATION ); #endif rp_hook_init( &modem_radio_planner, RP_HOOK_ID_SUSPEND, ( void ( * )( void* ) )( empty_callback ), &modem_radio_planner ); +#if !defined( LR1110_MODEM_E ) rp_hook_init( &modem_radio_planner, RP_HOOK_ID_USER_SUSPEND, ( void ( * )( void* ) )( user_radio_access_callback ), &modem_radio_planner ); /* user_radio_access_callback called when interrupt occurs */ rp_hook_init( &modem_radio_planner, RP_HOOK_ID_USER_SUSPEND_0, @@ -244,6 +289,7 @@ void smtc_modem_init( const ralf_t* radio, void ( *callback_event )( void ) ) ( void ( * )( void* ) )( callback_rp_user_radio_access_1 ), &modem_radio_planner ); rp_hook_init( &modem_radio_planner, RP_HOOK_ID_USER_SUSPEND_2, ( void ( * )( void* ) )( callback_rp_user_radio_access_2 ), &modem_radio_planner ); +#endif // !LR1110_MODEM_E modem_supervisor_init( callback_event, &modem_radio_planner, &smtc_modem_services_ctx ); smtc_secure_element_init( ); } @@ -319,10 +365,12 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_ event->event_data.downdata.datarate = metadata.rx_datarate; break; } +#if defined( ADD_SMTC_FILE_UPLOAD ) case SMTC_MODEM_EVENT_UPLOADDONE: event->event_data.uploaddone.status = ( smtc_modem_event_uploaddone_status_t ) get_modem_event_status( event->event_type ); break; +#endif // ADD_SMTC_FILE_UPLOAD case SMTC_MODEM_EVENT_TXDONE: event->event_data.txdone.status = ( smtc_modem_event_txdone_status_t ) get_modem_event_status( event->event_type ); @@ -362,15 +410,17 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_ //{ // POOL_MEM.WIFI_MEM.Pool_mem.Buffer_tx.EventModem[i]=(i%255); //} - *data_length = size; - memcpy( data, ( uint8_t* ) ( &( POOL_MEM.WIFI_MEM.Pool_mem.Buffer_tx.EventModem[0] ) + 4 ), *data_length ); + event->event_data.wifi_event_status.data_length = size; + memcpy( event->event_data.wifi_event_status.data, + ( uint8_t* ) ( &( POOL_MEM.WIFI_MEM.Pool_mem.Buffer_tx.EventModem[0] ) + 4 ), size ); } break; #endif #if defined( _MODEM_E_GNSS_ENABLE ) && defined( LR1110_MODEM_E ) case SMTC_MODEM_EVENT_GNSS: { - *data_length = GnssGetSize( ); - memcpy( data, ( uint8_t* ) &( POOL_MEM.GNSS_MEM.Buf_data[0] ), *data_length ); + uint16_t size = GnssGetSize( ); + event->event_data.gnss_event_status.data_length = size; + memcpy( event->event_data.gnss_event_status.data, ( uint8_t* ) &( POOL_MEM.GNSS_MEM.Buf_data[0] ), size ); } break; #endif @@ -382,6 +432,7 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_ event->event_data.class_b_status.status = ( smtc_modem_event_class_b_status_t ) get_modem_event_status( event->event_type ); break; +#if defined( ADD_D2D ) case SMTC_MODEM_EVENT_D2D_CLASS_B_TX_DONE: { modem_context_class_b_d2d_t class_b_d2d; modem_context_get_class_b_d2d_last_metadata( &class_b_d2d ); @@ -391,6 +442,7 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_ ( smtc_modem_d2d_class_b_tx_done_status_t ) get_modem_event_status( event->event_type ); break; } +#endif // ADD_D2D case SMTC_MODEM_EVENT_MIDDLEWARE_1: case SMTC_MODEM_EVENT_MIDDLEWARE_2: case SMTC_MODEM_EVENT_MIDDLEWARE_3: @@ -398,7 +450,9 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_ break; case SMTC_MODEM_EVENT_ALARM: case SMTC_MODEM_EVENT_JOINED: +#if defined( ADD_SMTC_STREAM ) case SMTC_MODEM_EVENT_STREAMDONE: +#endif // ADD_SMTC_STREAM case SMTC_MODEM_EVENT_JOINFAIL: case SMTC_MODEM_EVENT_TIMEOUT_ADR_CHANGED: case SMTC_MODEM_EVENT_NEW_LINK_ADR: @@ -422,9 +476,9 @@ smtc_modem_return_code_t smtc_modem_get_modem_version( smtc_modem_version_t* fir RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( firmware_version ); - firmware_version->major = LORA_BASICS_MODEM_FW_VERSION_MAJOR; - firmware_version->minor = LORA_BASICS_MODEM_FW_VERSION_MINOR; - firmware_version->patch = LORA_BASICS_MODEM_FW_VERSION_PATCH; + firmware_version->major = MODEM_FW_VERSION_MAJOR; + firmware_version->minor = MODEM_FW_VERSION_MINOR; + firmware_version->patch = MODEM_FW_VERSION_PATCH; return SMTC_MODEM_RC_OK; } @@ -525,6 +579,7 @@ smtc_modem_return_code_t smtc_modem_set_tx_power_offset_db( uint8_t stack_id, in smtc_modem_return_code_t smtc_modem_time_start_sync_service( uint8_t stack_id, smtc_modem_time_sync_service_t sync_service ) { +#if defined( ADD_SMTC_ALC_SYNC ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -558,10 +613,14 @@ smtc_modem_return_code_t smtc_modem_time_start_sync_service( uint8_t } return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_stop_sync_service( uint8_t stack_id ) { +#if defined( ADD_SMTC_ALC_SYNC ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -582,6 +641,9 @@ smtc_modem_return_code_t smtc_modem_time_stop_sync_service( uint8_t stack_id ) return_code = SMTC_MODEM_RC_FAIL; } return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_get_time( uint32_t* gps_time_s, uint32_t* gps_fractional_s ) @@ -592,6 +654,7 @@ smtc_modem_return_code_t smtc_modem_get_time( uint32_t* gps_time_s, uint32_t* gp smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; +#if defined( ADD_SMTC_ALC_SYNC ) if( clock_sync_is_time_valid( &( smtc_modem_services_ctx.clock_sync_ctx ) ) == true ) { clock_sync_get_gps_time_second( &( smtc_modem_services_ctx.clock_sync_ctx ), gps_time_s, gps_fractional_s ); @@ -603,11 +666,25 @@ smtc_modem_return_code_t smtc_modem_get_time( uint32_t* gps_time_s, uint32_t* gp return_code = SMTC_MODEM_RC_NO_TIME; } +#else // ADD_SMTC_ALC_SYNC + if( lorawan_api_convert_rtc_to_gps_epoch_time( smtc_modem_hal_get_time_in_ms( ), gps_time_s, gps_fractional_s ) == + true ) + { + return_code = SMTC_MODEM_RC_OK; + } + else + { + *gps_time_s = 0; + *gps_fractional_s = 0; + return_code = SMTC_MODEM_RC_NO_TIME; + } +#endif // ADD_SMTC_ALC_SYNC return return_code; } smtc_modem_return_code_t smtc_modem_time_set_alcsync_fport( uint8_t clock_sync_fport ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; @@ -617,10 +694,14 @@ smtc_modem_return_code_t smtc_modem_time_set_alcsync_fport( uint8_t clock_sync_f } return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_trigger_sync_request( uint8_t stack_id ) { +#if defined( ADD_SMTC_ALC_SYNC ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -642,10 +723,15 @@ smtc_modem_return_code_t smtc_modem_time_trigger_sync_request( uint8_t stack_id } return return_code; +#else // ADD_SMTC_ALC_SYNC + modem_supervisor_add_task_device_time_req( 1 ); + return SMTC_MODEM_RC_OK; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_get_alcsync_fport( uint8_t* clock_sync_port ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( clock_sync_port ); @@ -653,10 +739,14 @@ smtc_modem_return_code_t smtc_modem_time_get_alcsync_fport( uint8_t* clock_sync_ *clock_sync_port = clock_sync_get_alcsync_port( &( smtc_modem_services_ctx.clock_sync_ctx ) ); return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_set_sync_interval_s( uint32_t sync_interval_s ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; @@ -668,19 +758,27 @@ smtc_modem_return_code_t smtc_modem_time_set_sync_interval_s( uint32_t sync_inte } return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_get_sync_interval_s( uint32_t* sync_interval_s ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( sync_interval_s ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; *sync_interval_s = clock_sync_get_interval_second( &( smtc_modem_services_ctx.clock_sync_ctx ) ); return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_set_sync_invalid_delay_s( uint32_t sync_invalid_delay_s ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; @@ -691,6 +789,14 @@ smtc_modem_return_code_t smtc_modem_time_set_sync_invalid_delay_s( uint32_t sync } return return_code; +#else // ADD_SMTC_ALC_SYNC + + if( lorawan_api_set_device_time_invalid_delay_s( sync_invalid_delay_s ) != OKLORAWAN ) + { + return SMTC_MODEM_RC_FAIL; + } + return SMTC_MODEM_RC_OK; +#endif // ADD_SMTC_ALC_SYNC } smtc_modem_return_code_t smtc_modem_time_get_sync_invalid_delay_s( uint32_t* sync_invalid_delay_s ) @@ -699,7 +805,13 @@ smtc_modem_return_code_t smtc_modem_time_get_sync_invalid_delay_s( uint32_t* syn RETURN_INVALID_IF_NULL( sync_invalid_delay_s ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; + +#if defined( ADD_SMTC_ALC_SYNC ) *sync_invalid_delay_s = clock_sync_get_invalid_time_delay_s( &( smtc_modem_services_ctx.clock_sync_ctx ) ); +#else // ADD_SMTC_ALC_SYNC + *sync_invalid_delay_s = lorawan_api_get_device_time_invalid_delay_s( ); +#endif // ADD_SMTC_ALC_SYNC + return return_code; } @@ -765,7 +877,11 @@ smtc_modem_return_code_t smtc_modem_get_joineui( uint8_t stack_id, uint8_t joine RETURN_INVALID_IF_NULL( joineui ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - lorawan_api_get_joineui( joineui ); + + if( lorawan_api_get_joineui( joineui ) != OKLORAWAN ) + { + return_code = SMTC_MODEM_RC_FAIL; + } return return_code; } @@ -777,14 +893,18 @@ smtc_modem_return_code_t smtc_modem_set_joineui( uint8_t stack_id, const uint8_t smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - if( get_join_state( ) != MODEM_NOT_JOINED ) // the modem have to be leave from the network to modify the key + // Check join status: the modem shall not be joined to modify the joineui + if( get_join_state( ) != MODEM_NOT_JOINED ) { return_code = SMTC_MODEM_RC_BUSY; SMTC_MODEM_HAL_TRACE_ERROR( "%s call but the device is already join\n", __func__ ); } else { - lorawan_api_set_joineui( joineui ); + if( lorawan_api_set_joineui( joineui ) != OKLORAWAN ) + { + return_code = SMTC_MODEM_RC_FAIL; + } } return return_code; @@ -797,7 +917,11 @@ smtc_modem_return_code_t smtc_modem_get_deveui( uint8_t stack_id, uint8_t deveui RETURN_INVALID_IF_NULL( deveui ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - lorawan_api_get_deveui( deveui ); + + if( lorawan_api_get_deveui( deveui ) != OKLORAWAN ) + { + return_code = SMTC_MODEM_RC_FAIL; + } return return_code; } @@ -808,14 +932,19 @@ smtc_modem_return_code_t smtc_modem_set_deveui( uint8_t stack_id, const uint8_t RETURN_INVALID_IF_NULL( deveui ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - if( get_join_state( ) != MODEM_NOT_JOINED ) // the modem have to be leave from the network to modify the key + + // Check join status: the modem shall not be joined to modify the deveui + if( get_join_state( ) != MODEM_NOT_JOINED ) { return_code = SMTC_MODEM_RC_BUSY; SMTC_MODEM_HAL_TRACE_ERROR( "%s call but the device is already join\n", __func__ ); } else { - lorawan_api_set_deveui( deveui ); + if( lorawan_api_set_deveui( deveui ) != OKLORAWAN ) + { + return_code = SMTC_MODEM_RC_FAIL; + } } return return_code; } @@ -827,14 +956,19 @@ smtc_modem_return_code_t smtc_modem_set_nwkkey( uint8_t stack_id, const uint8_t RETURN_INVALID_IF_NULL( nwkkey ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - if( get_join_state( ) != MODEM_NOT_JOINED ) // the modem have to be leave from the network to modify the key + + // Check join status: the modem shall not be joined to modify the key + if( get_join_state( ) != MODEM_NOT_JOINED ) { return_code = SMTC_MODEM_RC_BUSY; SMTC_MODEM_HAL_TRACE_ERROR( "%s call but the device is already join\n", __func__ ); } else { - modem_context_set_appkey( nwkkey ); + if( modem_context_set_appkey( nwkkey ) != MODEM_CTX_RC_SUCCESS ) + { + return_code = SMTC_MODEM_RC_FAIL; + } } return return_code; } @@ -863,12 +997,20 @@ smtc_modem_return_code_t smtc_modem_set_class( uint8_t stack_id, smtc_modem_clas break; } case SMTC_MODEM_CLASS_B: { +#if defined( ADD_SMTC_ALC_SYNC ) if( clock_sync_is_time_valid( &( smtc_modem_services_ctx.clock_sync_ctx ) ) == false ) { SMTC_MODEM_HAL_TRACE_ERROR( "set to class b is refused : modem is not time synced" ); return ( SMTC_MODEM_RC_FAIL ); } +#else // ADD_SMTC_ALC_SYNC + if( lorawan_api_is_time_valid( ) == false ) + { + SMTC_MODEM_HAL_TRACE_ERROR( "set to class b is refused : modem is not time synced" ); + return ( SMTC_MODEM_RC_FAIL ); + } +#endif // ADD_SMTC_ALC_SYNC if( get_join_state( ) != MODEM_JOINED ) { SMTC_MODEM_HAL_TRACE_ERROR( "set to class b is refused : modem is not joined" ); @@ -896,6 +1038,7 @@ smtc_modem_return_code_t smtc_modem_multicast_set_grp_config( uint8_t stack_id, const uint8_t mc_nwk_skey[SMTC_MODEM_KEY_LENGTH], const uint8_t mc_app_skey[SMTC_MODEM_KEY_LENGTH] ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( mc_nwk_skey ); @@ -926,11 +1069,15 @@ smtc_modem_return_code_t smtc_modem_multicast_set_grp_config( uint8_t stack_id, break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_get_grp_config( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id, uint32_t* mc_grp_addr ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( mc_grp_addr ); @@ -951,11 +1098,15 @@ smtc_modem_return_code_t smtc_modem_multicast_get_grp_config( uint8_t stack_id, break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_c_start_session( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id, uint32_t freq, uint8_t dr ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -983,6 +1134,9 @@ smtc_modem_return_code_t smtc_modem_multicast_class_c_start_session( uint8_t sta break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_c_get_session_status( uint8_t stack_id, @@ -990,6 +1144,7 @@ smtc_modem_return_code_t smtc_modem_multicast_class_c_get_session_status( uint8_ bool* is_session_started, uint32_t* freq, uint8_t* dr ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( is_session_started ); @@ -1012,10 +1167,14 @@ smtc_modem_return_code_t smtc_modem_multicast_class_c_get_session_status( uint8_ break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_c_stop_session( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1035,10 +1194,14 @@ smtc_modem_return_code_t smtc_modem_multicast_class_c_stop_session( uint8_t stac break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_c_stop_all_sessions( uint8_t stack_id ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1055,12 +1218,16 @@ smtc_modem_return_code_t smtc_modem_multicast_class_c_stop_all_sessions( uint8_t break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_b_start_session( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id, uint32_t freq, uint8_t dr, smtc_modem_class_b_ping_slot_periodicity_t ping_slot_periodicity ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1088,6 +1255,9 @@ smtc_modem_return_code_t smtc_modem_multicast_class_b_start_session( break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_b_get_session_status( @@ -1095,6 +1265,7 @@ smtc_modem_return_code_t smtc_modem_multicast_class_b_get_session_status( uint32_t* freq, uint8_t* dr, smtc_modem_class_b_ping_slot_periodicity_t* ping_slot_periodicity ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( is_session_started ); @@ -1120,10 +1291,14 @@ smtc_modem_return_code_t smtc_modem_multicast_class_b_get_session_status( break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_b_stop_session( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1143,10 +1318,14 @@ smtc_modem_return_code_t smtc_modem_multicast_class_b_stop_session( uint8_t stac break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_multicast_class_b_stop_all_sessions( uint8_t stack_id ) { +#if defined( SMTC_MULTICAST ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1163,6 +1342,9 @@ smtc_modem_return_code_t smtc_modem_multicast_class_b_stop_all_sessions( uint8_t break; } return modem_rc; +#else // SMTC_MULTICAST + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST } smtc_modem_return_code_t smtc_modem_get_region( uint8_t stack_id, smtc_modem_region_t* region ) @@ -1181,18 +1363,6 @@ smtc_modem_return_code_t smtc_modem_set_region( uint8_t stack_id, smtc_modem_reg UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); -#if !defined( SX128X ) && !defined( LR1120 ) - if( region == SMTC_MODEM_REGION_WW2G4 ) - { - return SMTC_MODEM_RC_FAIL; - } -#elif defined( SX128X ) - if( region != SMTC_MODEM_REGION_WW2G4 ) - { - return SMTC_MODEM_RC_FAIL; - } -#endif - if( get_join_state( ) != MODEM_NOT_JOINED ) { SMTC_MODEM_HAL_TRACE_ERROR( "%s call but the device is already join\n", __func__ ); @@ -1446,22 +1616,9 @@ smtc_modem_return_code_t smtc_modem_leave_network( uint8_t stack_id ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); - smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; - - set_modem_status_modem_joined( false ); - lorawan_api_join_status_clear( ); - set_modem_status_joining( false ); + modem_leave( ); - lorawan_api_class_b_enabled( false ); - lorawan_api_class_c_enabled( false ); - - // set stream and file upload status to false - set_modem_status_file_upload( false ); - set_modem_status_streaming( false ); - - // re init task to retrieve a clean env - modem_supervisor_init_task( ); - return return_code; + return SMTC_MODEM_RC_OK; } smtc_modem_return_code_t smtc_modem_suspend_radio_communications( bool suspend ) @@ -1603,6 +1760,7 @@ smtc_modem_return_code_t smtc_modem_file_upload_init( uint8_t stack_id, uint8_t const uint8_t* file, uint16_t file_length, uint32_t average_delay_s ) { +#if defined( ADD_SMTC_FILE_UPLOAD ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1647,10 +1805,14 @@ smtc_modem_return_code_t smtc_modem_file_upload_init( uint8_t stack_id, uint8_t modem_set_upload_state( MODEM_UPLOAD_INIT_AND_FILLED ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_FILE_UPLOAD + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_FILE_UPLOAD } smtc_modem_return_code_t smtc_modem_file_upload_start( uint8_t stack_id ) { +#if defined( ADD_SMTC_FILE_UPLOAD ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1680,10 +1842,14 @@ smtc_modem_return_code_t smtc_modem_file_upload_start( uint8_t stack_id ) set_modem_status_file_upload( true ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_FILE_UPLOAD + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_FILE_UPLOAD } smtc_modem_return_code_t smtc_modem_file_upload_reset( uint8_t stack_id ) { +#if defined( ADD_SMTC_FILE_UPLOAD ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1700,12 +1866,16 @@ smtc_modem_return_code_t smtc_modem_file_upload_reset( uint8_t stack_id ) set_modem_status_file_upload( false ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_FILE_UPLOAD + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_FILE_UPLOAD } smtc_modem_return_code_t smtc_modem_stream_init( uint8_t stack_id, uint8_t fport, smtc_modem_stream_cipher_mode_t cipher_mode, uint8_t redundancy_ratio_percent ) { +#if defined( ADD_SMTC_STREAM ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -1756,10 +1926,14 @@ smtc_modem_return_code_t smtc_modem_stream_init( uint8_t stack_id, uint8_t fport modem_set_stream_state( MODEM_STREAM_INIT ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_STREAM + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_STREAM } smtc_modem_return_code_t smtc_modem_stream_add_data( uint8_t stack_id, const uint8_t* data, uint8_t len ) { +#if defined( ADD_SMTC_STREAM ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( data ); @@ -1812,10 +1986,14 @@ smtc_modem_return_code_t smtc_modem_stream_add_data( uint8_t stack_id, const uin SMTC_MODEM_HAL_TRACE_INFO( "STREAM_SEND [OK]\n" ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_STREAM + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_STREAM } smtc_modem_return_code_t smtc_modem_stream_status( uint8_t stack_id, uint16_t* pending, uint16_t* free ) { +#if defined( ADD_SMTC_STREAM ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( pending ); @@ -1828,6 +2006,9 @@ smtc_modem_return_code_t smtc_modem_stream_status( uint8_t stack_id, uint16_t* p stream_status( &( smtc_modem_services_ctx.stream_ROSE_ctx ), pending, free ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_STREAM + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_STREAM } #ifdef LORAWAN_BYPASS_ENABLED @@ -1983,6 +2164,7 @@ smtc_modem_return_code_t smtc_modem_get_duty_cycle_status( int32_t* duty_cycle_s smtc_modem_return_code_t smtc_modem_rp_abort_user_radio_access_task( uint8_t user_task_id ) { +#if !defined( LR1110_MODEM_E ) rp_hook_status_t status = RP_HOOK_STATUS_ID_ERROR; switch( user_task_id ) { @@ -2000,10 +2182,14 @@ smtc_modem_return_code_t smtc_modem_rp_abort_user_radio_access_task( uint8_t use break; } return ( status == RP_HOOK_STATUS_OK ) ? SMTC_MODEM_RC_OK : SMTC_MODEM_RC_FAIL; +#else // !LR1110_MODEM_E + return SMTC_MODEM_RC_FAIL; +#endif // !LR1110_MODEM_E } smtc_modem_return_code_t smtc_modem_rp_add_user_radio_access_task( smtc_modem_rp_task_t* rp_task ) { +#if !defined( LR1110_MODEM_E ) RETURN_BUSY_IF_TEST_MODE( ); rp_radio_params_t fake_radio_params = { 0 }; @@ -2038,10 +2224,14 @@ smtc_modem_return_code_t smtc_modem_rp_add_user_radio_access_task( smtc_modem_rp rp_hook_status_t status = rp_task_enqueue( &modem_radio_planner, &rp_task_tmp, NULL, 0, &fake_radio_params ); return ( status == RP_HOOK_STATUS_OK ) ? SMTC_MODEM_RC_OK : SMTC_MODEM_RC_FAIL; +#else // !LR1110_MODEM_E + return SMTC_MODEM_RC_FAIL; +#endif // !LR1110_MODEM_E } smtc_modem_return_code_t smtc_modem_suspend_before_user_radio_access( void ) { +#if !defined( LR1110_MODEM_E ) RETURN_BUSY_IF_TEST_MODE( ); // Put modem in suspended mode to prevent scheduler to be called @@ -2052,10 +2242,14 @@ smtc_modem_return_code_t smtc_modem_suspend_before_user_radio_access( void ) // Protect radio access with a suspension of all other task in radio planner (put an infinite empty task) return ( modem_context_suspend_user_radio_access( RP_TASK_TYPE_NONE ) == true ) ? SMTC_MODEM_RC_OK : SMTC_MODEM_RC_FAIL; +#else // !LR1110_MODEM_E + return SMTC_MODEM_RC_FAIL; +#endif // !LR1110_MODEM_E } smtc_modem_return_code_t smtc_modem_resume_after_user_radio_access( void ) { +#if !defined( LR1110_MODEM_E ) RETURN_BUSY_IF_TEST_MODE( ); SMTC_MODEM_HAL_TRACE_PRINTF( "Resume modem user radio access\n" ); @@ -2067,6 +2261,9 @@ smtc_modem_return_code_t smtc_modem_resume_after_user_radio_access( void ) smtc_modem_suspend_radio_communications( false ); return SMTC_MODEM_RC_OK; +#else // !LR1110_MODEM_E + return SMTC_MODEM_RC_FAIL; +#endif // !LR1110_MODEM_E } smtc_modem_return_code_t smtc_modem_get_stack_state( uint8_t stack_id, smtc_modem_stack_state_t* stack_state ) @@ -2171,7 +2368,7 @@ smtc_modem_return_code_t smtc_modem_lbt_get_state( uint8_t stack_id, bool* enabl RETURN_BUSY_IF_TEST_MODE( ); RETURN_INVALID_IF_NULL( enabled ); - *enabled = lorawan_api_get_state( ); + *enabled = lorawan_api_lbt_get_state( ); return SMTC_MODEM_RC_OK; } @@ -2284,6 +2481,7 @@ smtc_modem_return_code_t smtc_modem_d2d_class_b_request_uplink( uint8_t stack_id uint8_t fport, const uint8_t* payload, uint8_t payload_length ) { +#if defined( SMTC_MULTICAST ) && defined( SMTC_D2D ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); @@ -2321,11 +2519,15 @@ smtc_modem_return_code_t smtc_modem_d2d_class_b_request_uplink( uint8_t stack_id break; } return modem_rc; +#else // SMTC_MULTICAST && SMTC_D2D + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST && SMTC_D2D } smtc_modem_return_code_t smtc_modem_d2d_class_b_get_tx_max_payload( uint8_t stack_id, smtc_modem_mc_grp_id_t mc_grp_id, uint8_t* tx_max_payload_size ) { +#if defined( SMTC_MULTICAST ) && defined( SMTC_D2D ) *tx_max_payload_size = 0; UNUSED( stack_id ); @@ -2357,6 +2559,9 @@ smtc_modem_return_code_t smtc_modem_d2d_class_b_get_tx_max_payload( uint8_t stac break; } return modem_rc; +#else // SMTC_MULTICAST && SMTC_D2D + return SMTC_MODEM_RC_FAIL; +#endif // SMTC_MULTICAST && SMTC_D2D } smtc_modem_return_code_t smtc_modem_get_network_frame_pending_status( @@ -2406,8 +2611,16 @@ smtc_modem_return_code_t smtc_modem_get_pin( uint8_t stack_id, uint8_t chip_pin[ #if defined( USE_LR11XX_CE ) lr11xx_system_uid_t deveui; lr11xx_system_join_eui_t joineui; - lorawan_api_get_deveui( ( uint8_t* ) deveui ); - lorawan_api_get_joineui( ( uint8_t* ) joineui ); + + if( lorawan_api_get_deveui( ( uint8_t* ) deveui ) != OKLORAWAN ) + { + return SMTC_MODEM_RC_FAIL; + } + + if( lorawan_api_get_joineui( ( uint8_t* ) joineui ) != OKLORAWAN ) + { + return SMTC_MODEM_RC_FAIL; + } // lr11xx operation needed: suspend modem radio access to secure this direct access modem_context_suspend_radio_access( RP_TASK_TYPE_NONE ); @@ -2474,8 +2687,15 @@ smtc_modem_return_code_t smtc_modem_derive_keys( uint8_t stack_id ) lr11xx_system_join_eui_t joineui; lr11xx_system_pin_t pin; - lorawan_api_get_deveui( ( uint8_t* ) deveui ); - lorawan_api_get_joineui( ( uint8_t* ) joineui ); + if( lorawan_api_get_deveui( ( uint8_t* ) deveui ) != OKLORAWAN ) + { + return SMTC_MODEM_RC_FAIL; + } + + if( lorawan_api_get_joineui( ( uint8_t* ) joineui ) != OKLORAWAN ) + { + return SMTC_MODEM_RC_FAIL; + } // lr11xx operation needed: suspend modem radio access to secure this direct access modem_context_suspend_radio_access( RP_TASK_TYPE_NONE ); @@ -2496,18 +2716,6 @@ smtc_modem_return_code_t smtc_modem_derive_keys( uint8_t stack_id ) return SMTC_MODEM_RC_FAIL; } return SMTC_MODEM_RC_OK; -#elif defined( LR1110_MODEM_E ) - uint8_t deveui[8]; - uint8_t appeui[8]; - lorawan_api_get_deveui( deveui ); - lorawan_api_get_joineui( appeui ); - - if( smtc_crypto_se_derive_keys( deveui, appeui ) == 0 ) - { - modem_context_appkey_is_derived( ); - return SMTC_MODEM_RC_OK; - } - return SMTC_MODEM_RC_FAIL; #else return SMTC_MODEM_RC_FAIL; #endif @@ -2517,29 +2725,28 @@ smtc_modem_return_code_t smtc_modem_derive_keys( uint8_t stack_id ) #if defined( LR1110_MODEM_E ) smtc_modem_return_code_t smtc_modem_stream_get_redundancy_ratio( uint8_t stack_id, uint8_t* stream_rr ) { +#if defined( ADD_SMTC_STREAM ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); *stream_rr = stream_get_rr( &( smtc_modem_services_ctx.stream_ROSE_ctx ) ); return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_STREAM + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_STREAM } smtc_modem_return_code_t smtc_modem_stream_set_redundancy_ratio( uint8_t stack_id, uint8_t redundancy_ratio_percent ) { +#if defined( ADD_SMTC_STREAM ) UNUSED( stack_id ); RETURN_BUSY_IF_TEST_MODE( ); stream_set_rr( &( smtc_modem_services_ctx.stream_ROSE_ctx ), redundancy_ratio_percent ); return SMTC_MODEM_RC_OK; -} - -smtc_modem_return_code_t smtc_modem_set_default_key( uint8_t default_app_key[16], uint8_t default_dev_eui[8], - uint8_t default_join_eui[8] ) -{ - RETURN_BUSY_IF_TEST_MODE( ); - - lorawan_api_set_default_key( default_app_key, default_dev_eui, default_join_eui ); - return SMTC_MODEM_RC_OK; +#else // ADD_SMTC_STREAM + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_STREAM } smtc_modem_return_code_t smtc_modem_list_regions( uint8_t* region_list, uint8_t* nb_region ) @@ -2566,30 +2773,39 @@ smtc_modem_return_code_t smtc_modem_set_rf_output( rf_output_t rf_output ) return return_code; } -smtc_modem_return_code_t smtc_modem_time_available( ) +smtc_modem_return_code_t smtc_modem_time_available( void ) { RETURN_BUSY_IF_TEST_MODE( ); - smtc_modem_return_code_t return_code = SMTC_MODEM_RC_INVALID; - uint32_t gps_time_s = 0; - uint32_t fractional_second = 0; + smtc_modem_return_code_t return_code = SMTC_MODEM_RC_NO_TIME; - if( clock_sync_get_gps_time_second( &( smtc_modem_services_ctx.clock_sync_ctx ), &gps_time_s, - &fractional_second ) == true ) +#if defined( ADD_SMTC_ALC_SYNC ) + if( clock_sync_is_time_valid( &( smtc_modem_services_ctx.clock_sync_ctx ) ) == true ) + { + return_code = SMTC_MODEM_RC_OK; + } +#else // ADD_SMTC_ALC_SYNC + if( lorawan_api_is_time_valid( ) == true ) { return_code = SMTC_MODEM_RC_OK; } +#endif // ADD_SMTC_ALC_SYNC + return return_code; } smtc_modem_return_code_t smtc_modem_set_time( uint32_t gps_time_s ) { +#if defined( ADD_SMTC_ALC_SYNC ) RETURN_BUSY_IF_TEST_MODE( ); smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK; clock_sync_set_gps_time( &( smtc_modem_services_ctx.clock_sync_ctx ), gps_time_s ); return return_code; +#else // ADD_SMTC_ALC_SYNC + return SMTC_MODEM_RC_FAIL; +#endif // ADD_SMTC_ALC_SYNC } void empty_task_launch_callback_for_rp( void* rp_void ) { @@ -2599,7 +2815,7 @@ void empty_task_launch_callback_for_rp( void* rp_void ) SMTC_MODEM_HAL_TRACE_PRINTF( "launch task empty\n" ); } -void modem_suspend_rp( e_sniff_mode_t sniff_mode ) +void smtc_modem_suspend_rp( e_sniff_mode_t sniff_mode ) { rp_radio_params_t fake_radio_params = { 0 }; rp_task_t rp_task = { 0 }; @@ -2638,7 +2854,7 @@ void modem_suspend_rp( e_sniff_mode_t sniff_mode ) rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 4; rp_task_enqueue( &modem_radio_planner, &rp_task, fake_payload, fake_payload_size, &fake_radio_params ); } -void modem_resume_rp( void ) +void smtc_modem_resume_rp( void ) { SMTC_MODEM_HAL_TRACE_PRINTF( "Resume rp\n" ); rp_task_abort( &modem_radio_planner, 0 ); @@ -2928,6 +3144,7 @@ void user_radio_access_callback( void* ctx ) } } +#if !defined( LR1110_MODEM_E ) void callback_rp_user_radio_access_0( void* ctx ) { radio_planner_t* rp = ( radio_planner_t* ) ctx; @@ -2996,5 +3213,6 @@ void callback_rp_user_radio_access_2( void* ctx ) user_end_task_callback_2( &modem_rp_status ); } } +#endif // !LR1110_MODEM_E /* --- EOF ------------------------------------------------------------------ */ diff --git a/smtc_modem_core/modem_core/smtc_modem_test.c b/smtc_modem_core/modem_core/smtc_modem_test.c index 9834e45..8156ccd 100644 --- a/smtc_modem_core/modem_core/smtc_modem_test.c +++ b/smtc_modem_core/modem_core/smtc_modem_test.c @@ -139,16 +139,14 @@ static const uint32_t modem_test_bw_helper[SMTC_MODEM_TEST_BW_COUNT] = { */ typedef struct modem_test_context { - radio_planner_t* rp; //!< Radio planner instance - rp_radio_params_t radio_params; //!< Radio parameters - lr1_stack_mac_t* lr1_mac_obj; //!< Lorawan lr1mac instance - uint8_t hook_id; //!< Lorawan lr1mac hook id used for test - uint8_t rx_payload[255]; //!< Received buffer - uint8_t tx_payload[255]; //!< Uplink buffer - int16_t rssi; //!< Placeholder for mean rssi - bool rssi_ready; //!< True when rssi mean test is finished - uint32_t total_rx_packets; //!< Number of received packet - bool random_payload; //!< True in case of random payload + radio_planner_t* rp; //!< Radio planner instance + lr1_stack_mac_t* lr1_mac_obj; //!< Lorawan lr1mac instance + uint8_t hook_id; //!< Lorawan lr1mac hook id used for test + uint8_t tx_rx_payload[255]; //!< Transmit/Received buffer + int16_t rssi; //!< Placeholder for mean rssi + bool rssi_ready; //!< True when rssi mean test is finished + uint32_t total_rx_packets; //!< Number of received packet + bool random_payload; //!< True in case of random payload } modem_test_context_t; /* @@ -186,12 +184,6 @@ void modem_test_tx_callback( modem_test_context_t* context ); */ void modem_test_rx_callback( modem_test_context_t* context ); -/*! - * \brief Callback for test rssi - * \retval [out] context* - modem_test_context_t - */ -void modem_test_rssi_task_callback( modem_test_context_t* context ); - /*! * \brief Callback to configure Tx Continues Wave by Radio Planner * \retval [in] rp_void* - radio planner context @@ -302,8 +294,12 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l return SMTC_MODEM_RC_INVALID; } + rp_task_t rp_task = { 0 }; rp_radio_params_t rp_radio_params = { 0 }; + rp_task.hook_id = modem_test_context.hook_id; + rp_task.state = RP_TASK_STATE_ASAP; + if( sf == SMTC_MODEM_TEST_FSK ) // FSK { ralf_params_gfsk_t gfsk_param; @@ -332,6 +328,12 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l SMTC_MODEM_HAL_TRACE_PRINTF( "GFSK Tx - Freq:%d, Power:%d, length:%u\n", frequency_hz, tx_power_dbm, payload_length ); + + rp_task.type = RP_TASK_TYPE_TX_FSK; + rp_task.launch_task_callbacks = lr1_stack_mac_tx_gfsk_launch_callback_for_rp; + rp_task.duration_time_ms = ral_get_gfsk_time_on_air_in_ms( &( modem_test_context.rp->radio->ral ), + &( rp_radio_params.tx.gfsk.pkt_params ), + &( rp_radio_params.tx.gfsk.mod_params ) ); } else // LoRa { @@ -359,6 +361,12 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l SMTC_MODEM_HAL_TRACE_PRINTF( "LoRa Tx - Freq:%u, Power:%d, sf:%u, bw:%u, cr:%u, length:%u\n", frequency_hz, tx_power_dbm, rp_radio_params.tx.lora.mod_params.sf, lora_param.mod_params.bw, lora_param.mod_params.cr, payload_length ); + + rp_task.type = RP_TASK_TYPE_TX_LORA; + rp_task.launch_task_callbacks = lr1_stack_mac_tx_lora_launch_callback_for_rp; + rp_task.duration_time_ms = ral_get_lora_time_on_air_in_ms( &( modem_test_context.rp->radio->ral ), + &( rp_radio_params.tx.lora.pkt_params ), + &( rp_radio_params.tx.lora.mod_params ) ); } if( smtc_modem_test_nop( ) != SMTC_MODEM_RC_OK ) @@ -366,7 +374,6 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l return SMTC_MODEM_RC_FAIL; } - modem_test_context.radio_params = rp_radio_params; if( continuous_tx == false ) // single tx { rp_release_hook( modem_test_context.rp, modem_test_context.hook_id ); @@ -379,19 +386,29 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l rp_hook_init( modem_test_context.rp, modem_test_context.hook_id, ( void ( * )( void* ) )( modem_test_tx_callback ), &modem_test_context ); } + if( payload == NULL ) { // user payload is NULL=> generate a random before at next step modem_test_context.random_payload = true; + for( uint8_t i = 0; i < payload_length; i++ ) + { + modem_test_context.tx_rx_payload[i] = ( smtc_modem_hal_get_random_nb( ) % 256 ); + } } else { modem_test_context.random_payload = false; // save tx payload in context - memcpy( modem_test_context.tx_payload, payload, payload_length ); + memcpy( modem_test_context.tx_rx_payload, payload, payload_length ); } - // call once the callback to start first operation - modem_test_tx_callback( &modem_test_context ); + + rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 20; + + // Enqueue task in radio planner + rp_task_enqueue( modem_test_context.rp, &rp_task, modem_test_context.tx_rx_payload, payload_length, + &rp_radio_params ); + return SMTC_MODEM_RC_OK; } @@ -480,8 +497,13 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s rp_radio_params_t rp_radio_params = { 0 }; rp_radio_params.rx.timeout_in_ms = RAL_RX_TIMEOUT_CONTINUOUS_MODE; + rp_task_t rp_task = { 0 }; + rp_task.hook_id = modem_test_context.hook_id; + rp_task.state = RP_TASK_STATE_ASAP; + if( sf == 0 ) // FSK { + // Radio config for FSK ralf_params_gfsk_t gfsk_param; memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) ); @@ -506,9 +528,14 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s rp_radio_params.rx.gfsk = gfsk_param; SMTC_MODEM_HAL_TRACE_PRINTF( "GFSK Rx - Freq:%d\n", frequency_hz ); + + // Radio planner task config + rp_task.type = RP_TASK_TYPE_RX_FSK; + rp_task.launch_task_callbacks = lr1_stack_mac_rx_gfsk_launch_callback_for_rp; } else // LoRa { + // Radio config for LoRa ralf_params_lora_t lora_param; memset( &lora_param, 0, sizeof( ralf_params_lora_t ) ); @@ -533,6 +560,10 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s SMTC_MODEM_HAL_TRACE_PRINTF( "LoRa Rx - Freq:%u, sf:%u, bw:%u, cr:%u\n", frequency_hz, rp_radio_params.rx.lora.mod_params.sf, bw, cr ); + + // Radio planner task config + rp_task.type = RP_TASK_TYPE_RX_LORA; + rp_task.launch_task_callbacks = lr1_stack_mac_rx_lora_launch_callback_for_rp; } if( smtc_modem_test_nop( ) != SMTC_MODEM_RC_OK ) @@ -540,11 +571,15 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s return SMTC_MODEM_RC_FAIL; } - modem_test_context.radio_params = rp_radio_params; rp_release_hook( modem_test_context.rp, modem_test_context.hook_id ); rp_hook_init( modem_test_context.rp, modem_test_context.hook_id, ( void ( * )( void* ) )( modem_test_rx_callback ), &modem_test_context ); - modem_test_rx_callback( &modem_test_context ); + + rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 20; + rp_task.duration_time_ms = 2000; // toa; + + rp_task_enqueue( modem_test_context.rp, &rp_task, modem_test_context.tx_rx_payload, 255, &rp_radio_params ); + return SMTC_MODEM_RC_OK; } @@ -590,9 +625,9 @@ smtc_modem_return_code_t smtc_modem_test_rssi( uint32_t frequency_hz, smtc_modem modem_test_context.rssi_ready = false; smtc_lbt_init( modem_test_context.lr1_mac_obj->lbt_obj, modem_test_context.lr1_mac_obj->rp, RP_HOOK_ID_LBT, - ( void ( * )( void* ) ) modem_test_compute_rssi_callback, ( void* ) ( &modem_test_context ), - ( void ( * )( void* ) ) modem_test_compute_rssi_callback, ( void* ) ( &modem_test_context ), - ( void ( * )( void* ) ) modem_test_compute_rssi_callback, ( void* ) ( &modem_test_context ) ); + ( void ( * )( void* ) ) modem_test_compute_rssi_callback, &modem_test_context, + ( void ( * )( void* ) ) modem_test_compute_rssi_callback, &modem_test_context, + ( void ( * )( void* ) ) modem_test_compute_rssi_callback, &modem_test_context ); smtc_lbt_set_parameters( modem_test_context.lr1_mac_obj->lbt_obj, time_ms, 50, bw_tmp ); smtc_lbt_set_state( modem_test_context.lr1_mac_obj->lbt_obj, true ); smtc_lbt_listen_channel( modem_test_context.lr1_mac_obj->lbt_obj, frequency_hz, 0, smtc_modem_hal_get_time_in_ms( ), @@ -741,15 +776,14 @@ void modem_test_empty_callback( modem_test_context_t* context ) void modem_test_compute_rssi_callback( modem_test_context_t* context ) { - float rssi_mean = ( ( float ) modem_test_context.lr1_mac_obj->lbt_obj->rssi_accu ) / + float rssi_mean = ( ( float ) context->lr1_mac_obj->lbt_obj->rssi_accu ) / modem_test_context.lr1_mac_obj->lbt_obj->rssi_nb_of_meas; - modem_test_context.rssi = ( int16_t )( rssi_mean ); - modem_test_context.total_rx_packets = modem_test_context.lr1_mac_obj->lbt_obj->rssi_nb_of_meas; - modem_test_context.rssi_ready = true; + context->rssi = ( int16_t )( rssi_mean ); + context->total_rx_packets = context->lr1_mac_obj->lbt_obj->rssi_nb_of_meas; + context->rssi_ready = true; - SMTC_MODEM_HAL_TRACE_PRINTF( "rssi_accu: %d, cnt:%d --> rssi: %d dBm\n", - modem_test_context.lr1_mac_obj->lbt_obj->rssi_accu, - modem_test_context.lr1_mac_obj->lbt_obj->rssi_nb_of_meas, modem_test_context.rssi ); + SMTC_MODEM_HAL_TRACE_PRINTF( "rssi_accu: %d, cnt:%d --> rssi: %d dBm\n", context->lr1_mac_obj->lbt_obj->rssi_accu, + context->lr1_mac_obj->lbt_obj->rssi_nb_of_meas, context->rssi ); } void modem_test_tx_callback( modem_test_context_t* context ) @@ -763,30 +797,29 @@ void modem_test_tx_callback( modem_test_context_t* context ) } rp_task_t rp_task = { 0 }; - rp_radio_params_t radio_params = context->radio_params; - rp_task.hook_id = context->hook_id; rp_task.state = RP_TASK_STATE_ASAP; - rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 2; + rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 20; + + rp_radio_params_t radio_params = context->rp->radio_params[context->hook_id]; - if( context->radio_params.pkt_type == RAL_PKT_TYPE_LORA ) + if( radio_params.pkt_type == RAL_PKT_TYPE_LORA ) { rp_task.type = RP_TASK_TYPE_TX_LORA; rp_task.launch_task_callbacks = lr1_stack_mac_tx_lora_launch_callback_for_rp; if( context->random_payload == true ) { - for( uint8_t i = 0; i < context->radio_params.tx.lora.pkt_params.pld_len_in_bytes; i++ ) + for( uint8_t i = 0; i < radio_params.tx.lora.pkt_params.pld_len_in_bytes; i++ ) { - context->tx_payload[i] = ( smtc_modem_hal_get_random_nb( ) % 256 ); + context->tx_rx_payload[i] = ( smtc_modem_hal_get_random_nb( ) % 256 ); } } - rp_task.duration_time_ms = - ral_get_lora_time_on_air_in_ms( &( context->rp->radio->ral ), &( context->radio_params.tx.lora.pkt_params ), - &( context->radio_params.tx.lora.mod_params ) ); + rp_task.duration_time_ms = ral_get_lora_time_on_air_in_ms( + &( context->rp->radio->ral ), &( radio_params.tx.lora.pkt_params ), &( radio_params.tx.lora.mod_params ) ); - rp_task_enqueue( context->rp, &rp_task, context->tx_payload, - context->radio_params.tx.lora.pkt_params.pld_len_in_bytes, &radio_params ); + rp_task_enqueue( context->rp, &rp_task, context->tx_rx_payload, + radio_params.tx.lora.pkt_params.pld_len_in_bytes, &radio_params ); } else { @@ -795,25 +828,23 @@ void modem_test_tx_callback( modem_test_context_t* context ) if( context->random_payload == true ) { - for( uint8_t i = 0; i < context->radio_params.tx.gfsk.pkt_params.pld_len_in_bytes; i++ ) + for( uint8_t i = 0; i < radio_params.tx.gfsk.pkt_params.pld_len_in_bytes; i++ ) { - context->tx_payload[i] = ( smtc_modem_hal_get_random_nb( ) % 256 ); + context->tx_rx_payload[i] = ( smtc_modem_hal_get_random_nb( ) % 256 ); } } - rp_task.duration_time_ms = - ral_get_gfsk_time_on_air_in_ms( &( context->rp->radio->ral ), &( context->radio_params.tx.gfsk.pkt_params ), - &( context->radio_params.tx.gfsk.mod_params ) ); + rp_task.duration_time_ms = ral_get_gfsk_time_on_air_in_ms( + &( context->rp->radio->ral ), &( radio_params.tx.gfsk.pkt_params ), &( radio_params.tx.gfsk.mod_params ) ); - rp_task_enqueue( context->rp, &rp_task, context->tx_payload, - context->radio_params.tx.gfsk.pkt_params.pld_len_in_bytes, &radio_params ); + rp_task_enqueue( context->rp, &rp_task, context->tx_rx_payload, + radio_params.tx.gfsk.pkt_params.pld_len_in_bytes, &radio_params ); } } void modem_test_rx_callback( modem_test_context_t* context ) { smtc_modem_hal_reload_wdog( ); - rp_status_t rp_status = context->rp->status[context->hook_id]; if( rp_status == RP_STATUS_RX_PACKET ) @@ -825,36 +856,37 @@ void modem_test_rx_callback( modem_test_context_t* context ) uint32_t irq_timestamp_ms = context->rp->irq_timestamp_ms[context->hook_id]; SMTC_MODEM_HAL_TRACE_PRINTF( "t: %d, rp_status %u, snr: %d, rssi: %d\n", irq_timestamp_ms, rp_status, snr, rssi ); - SMTC_MODEM_HAL_TRACE_ARRAY( "rx_payload", context->rx_payload, context->rp->payload_size[context->hook_id] ); + SMTC_MODEM_HAL_TRACE_ARRAY( "rx_payload", context->tx_rx_payload, context->rp->payload_size[context->hook_id] ); #endif } else if( rp_status == RP_STATUS_TASK_ABORTED ) { - SMTC_MODEM_HAL_TRACE_PRINTF( " modem_test_tx_callback ABORTED\n" ); + SMTC_MODEM_HAL_TRACE_PRINTF( " modem_test_rx_callback ABORTED\n" ); return; } - rp_task_t rp_task = { 0 }; - rp_radio_params_t radio_params = context->radio_params; + rp_task_t rp_task = { 0 }; rp_task.hook_id = context->hook_id; rp_task.state = RP_TASK_STATE_ASAP; - rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 2; + rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 20; rp_task.duration_time_ms = 2000; // toa; - if( context->radio_params.pkt_type == RAL_PKT_TYPE_LORA ) + rp_radio_params_t radio_params = context->rp->radio_params[context->hook_id]; + + if( radio_params.pkt_type == RAL_PKT_TYPE_LORA ) { rp_task.type = RP_TASK_TYPE_RX_LORA; rp_task.launch_task_callbacks = lr1_stack_mac_rx_lora_launch_callback_for_rp; - rp_task_enqueue( context->rp, &rp_task, context->rx_payload, - context->radio_params.rx.lora.pkt_params.pld_len_in_bytes, &radio_params ); + rp_task_enqueue( context->rp, &rp_task, context->tx_rx_payload, + radio_params.rx.lora.pkt_params.pld_len_in_bytes, &radio_params ); } else { rp_task.type = RP_TASK_TYPE_RX_FSK; rp_task.launch_task_callbacks = lr1_stack_mac_rx_gfsk_launch_callback_for_rp; - rp_task_enqueue( context->rp, &rp_task, context->rx_payload, - context->radio_params.rx.gfsk.pkt_params.pld_len_in_bytes, &radio_params ); + rp_task_enqueue( context->rp, &rp_task, context->tx_rx_payload, + radio_params.rx.gfsk.pkt_params.pld_len_in_bytes, &radio_params ); } } diff --git a/smtc_modem_core/modem_services/fragmentation/frag_decoder.c b/smtc_modem_core/modem_services/fragmentation/frag_decoder.c index 6a7e064..84f9a64 100644 --- a/smtc_modem_core/modem_services/fragmentation/frag_decoder.c +++ b/smtc_modem_core/modem_services/fragmentation/frag_decoder.c @@ -40,6 +40,7 @@ #include "frag_decoder.h" #include "smtc_modem_hal.h" #include "nvmcu_hal.h" +#include "smtc_modem_hal_dbg_trace.h" #if defined( TEST ) #define STATIC diff --git a/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c b/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c index 76bd127..3496f6b 100644 --- a/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c +++ b/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c @@ -41,7 +41,6 @@ #include "gpio.h" #include "radio_ctrl.h" -#include "fragmented_data_block.h" #include "frag_decoder.h" #include "smtc_modem_hal.h" #include "aes.h" @@ -50,6 +49,7 @@ #include "modem_utilities.h" // for crc fw #include "patch_upd.h" #include "pool_mem.h" +#include "smtc_modem_hal_dbg_trace.h" #include "fragmented_data_block.h" /* diff --git a/smtc_modem_core/modem_services/smtc_clock_sync.c b/smtc_modem_core/modem_services/smtc_clock_sync.c index 441aab3..8b0dc86 100644 --- a/smtc_modem_core/modem_services/smtc_clock_sync.c +++ b/smtc_modem_core/modem_services/smtc_clock_sync.c @@ -105,7 +105,7 @@ void clock_sync_init( clock_sync_ctx_t* ctx, alc_sync_ctx_t* alc_ctx ) ctx->alc_ctx = alc_ctx; - lorawan_api_set_device_time_callback( ( void ( * )( void*, uint32_t ) ) clock_sync_callback, ctx, 0 ); + // lorawan_api_set_device_time_callback( ( void ( * )( void*, uint32_t ) ) clock_sync_callback, ctx, 0 ); } void clock_sync_set_enabled( clock_sync_ctx_t* ctx, bool enable, clock_sync_service_t sync_service ) @@ -147,7 +147,7 @@ void clock_sync_callback( clock_sync_ctx_t* ctx, uint32_t rx_timestamp_s ) if( ctx->sync_service_type == CLOCK_SYNC_MAC ) { - ctx->timestamp_last_correction_s = rx_timestamp_s; + ctx->timestamp_last_correction_s = lorawan_api_get_timestamp_last_device_time_ans_s( ); ctx->sync_status = CLOCK_SYNC_NETWORK_SYNC_DONE; } @@ -186,6 +186,19 @@ void clock_sync_callback( clock_sync_ctx_t* ctx, uint32_t rx_timestamp_s ) { increment_asynchronous_msgnumber( SMTC_MODEM_EVENT_TIME, SMTC_MODEM_EVENT_TIME_VALID_BUT_NOT_SYNC ); } + else + { + increment_asynchronous_msgnumber( SMTC_MODEM_EVENT_TIME, SMTC_MODEM_EVENT_TIME_VALID ); + } + } + else + { + smtc_modem_event_time_status_t time_updated_status = SMTC_MODEM_EVENT_TIME_VALID_BUT_NOT_SYNC; + if( lorawan_api_get_device_time_req_status( ) == OKLORAWAN ) + { + time_updated_status = SMTC_MODEM_EVENT_TIME_VALID; + } + increment_asynchronous_msgnumber( SMTC_MODEM_EVENT_TIME, time_updated_status ); } if( clock_sync_get_interval_second( ctx ) > 0 ) @@ -297,7 +310,22 @@ bool clock_sync_is_time_valid( clock_sync_ctx_t* ctx ) if( ctx->sync_service_type == CLOCK_SYNC_MAC ) { - b_ret = lorawan_api_is_time_valid( ); + if( ctx->sync_status == CLOCK_SYNC_MANUAL_SYNC ) + { + uint32_t rtc_s = smtc_modem_hal_get_time_in_s( ); + + if( ( ctx->timestamp_last_correction_s != 0 ) && + ( ( int32_t )( rtc_s - ctx->timestamp_last_correction_s - + lorawan_api_get_device_time_invalid_delay_s( ) ) < 0 ) ) + { + b_ret = true; + } + b_ret = false; + } + else + { + b_ret = lorawan_api_is_time_valid( ); + } } else { diff --git a/smtc_modem_core/modem_services/smtc_clock_sync.h b/smtc_modem_core/modem_services/smtc_clock_sync.h index 3a29d2d..8bcce3e 100644 --- a/smtc_modem_core/modem_services/smtc_clock_sync.h +++ b/smtc_modem_core/modem_services/smtc_clock_sync.h @@ -52,7 +52,7 @@ extern "C" { * --- PUBLIC MACROS ----------------------------------------------------------- */ -#define CLOCK_SYNC_GPS_EPOCH_CONVERT +// #define CLOCK_SYNC_GPS_EPOCH_CONVERT /* * ----------------------------------------------------------------------------- * --- PUBLIC CONSTANTS -------------------------------------------------------- diff --git a/smtc_modem_core/modem_services/smtc_modem_services_hal.c b/smtc_modem_core/modem_services/smtc_modem_services_hal.c index 193e042..c3a52cc 100644 --- a/smtc_modem_core/modem_services/smtc_modem_services_hal.c +++ b/smtc_modem_core/modem_services/smtc_modem_services_hal.c @@ -83,16 +83,12 @@ void smtc_modem_services_aes_encrypt( const uint8_t* raw_buffer, uint16_t size, uint8_t aes_ctr_nonce[14], uint8_t* enc_buffer ) { - uint32_t address = ( uint32_t )( aes_ctr_nonce[6] ) | ( uint32_t )( aes_ctr_nonce[7] << 8 ) | - ( uint32_t )( aes_ctr_nonce[8] << 16 ) | ( uint32_t )( aes_ctr_nonce[9] << 24 ); - uint8_t dir = aes_ctr_nonce[5]; - uint32_t sequence_counter = ( uint32_t )( aes_ctr_nonce[10] ) | ( uint32_t )( aes_ctr_nonce[11] << 8 ) | - ( uint32_t )( aes_ctr_nonce[12] << 16 ) | ( uint32_t )( aes_ctr_nonce[13] << 24 ); - // lora_crypto_payload_encrypt( raw_buffer, size, key, address, dir, sequence_counter, enc_buffer ); - // Modem crypto lib can be used here - smtc_modem_crypto_payload_encrypt( raw_buffer, size, SMTC_SE_APP_S_KEY, address, dir, sequence_counter, - enc_buffer ); + if( smtc_modem_crypto_service_encrypt( raw_buffer, size, aes_ctr_nonce, enc_buffer ) != + SMTC_MODEM_CRYPTO_RC_SUCCESS ) + { + smtc_modem_hal_mcu_panic( "Encryption of lfu failed\n" ); + } } uint32_t smtc_modem_services_get_time_s( void ) diff --git a/smtc_modem_core/modem_supervisor/modem_supervisor.c b/smtc_modem_core/modem_supervisor/modem_supervisor.c index e8d012d..636d784 100644 --- a/smtc_modem_core/modem_supervisor/modem_supervisor.c +++ b/smtc_modem_core/modem_supervisor/modem_supervisor.c @@ -57,8 +57,14 @@ #include "smtc_secure_element.h" // services +#if defined( ADD_SMTC_FILE_UPLOAD ) #include "file_upload.h" +#endif // ADD_SMTC_FILE_UPLOAD + +#if defined( ADD_SMTC_STREAM ) #include "stream.h" +#endif // ADD_SMTC_STREAM + #include "alc_sync.h" #include "smtc_clock_sync.h" @@ -93,19 +99,27 @@ */ #if !defined( LR1110_MODEM_E ) -static lr1mac_states_t LpState = LWPSTATE_IDLE; -static stask_manager task_manager; -static user_rx_packet_type_t AvailableRxPacket = NO_LORA_RXPACKET_AVAILABLE; -static bool is_pending_dm_status_payload_periodic = false; -static bool is_pending_dm_status_payload_now = false; -static bool is_first_dm_after_join = true; -static bool send_task_update_needed = false; - -static void ( *app_callback )( void ) = NULL; -static alc_sync_ctx_t* alc_sync_context = NULL; -static clock_sync_ctx_t* clock_sync_context = NULL; -static rose_t* ROSE = NULL; -static file_upload_t* file_upload_context = NULL; +static lr1mac_states_t LpState = LWPSTATE_IDLE; +static stask_manager task_manager; +static bool is_pending_dm_status_payload_periodic = false; +static bool is_pending_dm_status_payload_now = false; +static bool is_first_dm_after_join = true; +static bool send_task_update_needed = false; + +static void ( *app_callback )( void ) = NULL; + +#if defined( ADD_SMTC_ALC_SYNC ) +static alc_sync_ctx_t* alc_sync_context = NULL; +static clock_sync_ctx_t* clock_sync_context = NULL; +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) +static rose_t* ROSE = NULL; +#endif // ADD_SMTC_STREAM +#if defined( ADD_SMTC_FILE_UPLOAD ) + +static file_upload_t* file_upload_context = NULL; +#endif // ADD_SMTC_FILE_UPLOAD // Used for LoRaWAN Certification static uint8_t user_payload_length = 10; @@ -119,18 +133,26 @@ static bool class_b_bit = false; struct { - lr1mac_states_t LpState; - stask_manager task_manager; - user_rx_packet_type_t AvailableRxPacket; - bool is_pending_dm_status_payload_periodic; - bool is_pending_dm_status_payload_now; - bool is_first_dm_after_join; - bool send_task_update_needed; + lr1mac_states_t LpState; + stask_manager task_manager; + bool is_pending_dm_status_payload_periodic; + bool is_pending_dm_status_payload_now; + bool is_first_dm_after_join; + bool send_task_update_needed; void ( *app_callback )( void ); + +#if defined( ADD_SMTC_ALC_SYNC ) alc_sync_ctx_t* alc_sync_context; clock_sync_ctx_t* clock_sync_context; +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) rose_t* ROSE; +#endif // ADD_SMTC_STREAM + +#if defined( ADD_SMTC_FILE_UPLOAD ) file_upload_t* file_upload_context; +#endif // ADD_SMTC_FILE_UPLOAD // Used for LoRaWAN Certification uint8_t user_payload_length; @@ -145,16 +167,24 @@ struct // clang-format off #define LpState modem_supervisor_context.LpState #define task_manager modem_supervisor_context.task_manager -#define AvailableRxPacket modem_supervisor_context.AvailableRxPacket #define is_pending_dm_status_payload_periodic modem_supervisor_context.is_pending_dm_status_payload_periodic #define is_pending_dm_status_payload_now modem_supervisor_context.is_pending_dm_status_payload_now #define is_first_dm_after_join modem_supervisor_context.is_first_dm_after_join #define send_task_update_needed modem_supervisor_context.send_task_update_needed #define app_callback modem_supervisor_context.app_callback + +#if defined( ADD_SMTC_ALC_SYNC ) #define alc_sync_context modem_supervisor_context.alc_sync_context #define clock_sync_context modem_supervisor_context.clock_sync_context +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) #define ROSE modem_supervisor_context.ROSE +#endif // ADD_SMTC_STREAM + +#if defined( ADD_SMTC_FILE_UPLOAD ) #define file_upload_context modem_supervisor_context.file_upload_context +#endif // ADD_SMTC_FILE_UPLOAD // Used for LoRaWAN Certification #define user_payload_length modem_supervisor_context.user_payload_length @@ -192,16 +222,24 @@ void modem_supervisor_init( void ( *callback )( void ), radio_planner_t* rp, smtc_modem_services_t* smtc_modem_services_ctx ) { LpState = LWPSTATE_IDLE; - AvailableRxPacket = NO_LORA_RXPACKET_AVAILABLE; is_pending_dm_status_payload_periodic = true; // Set to true to send at least the first DM after Join is_pending_dm_status_payload_now = false; is_first_dm_after_join = true; send_task_update_needed = false; app_callback = callback; - alc_sync_context = &( smtc_modem_services_ctx->alc_sync_ctx ); - clock_sync_context = &( smtc_modem_services_ctx->clock_sync_ctx ); - ROSE = &( smtc_modem_services_ctx->stream_ROSE_ctx ); - file_upload_context = &( smtc_modem_services_ctx->file_upload_ctx ); + +#if defined( ADD_SMTC_ALC_SYNC ) + alc_sync_context = &( smtc_modem_services_ctx->alc_sync_ctx ); + clock_sync_context = &( smtc_modem_services_ctx->clock_sync_ctx ); +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) + ROSE = &( smtc_modem_services_ctx->stream_ROSE_ctx ); +#endif // ADD_SMTC_STREAM + +#if defined( ADD_SMTC_FILE_UPLOAD ) + file_upload_context = &( smtc_modem_services_ctx->file_upload_ctx ); +#endif // ADD_SMTC_FILE_UPLOAD // Used for LoRaWAN Certification user_payload_length = 10; @@ -211,21 +249,22 @@ void modem_supervisor_init( void ( *callback )( void ), radio_planner_t* rp, class_b_bit = false; lorawan_api_init( rp ); - lorawan_api_dr_strategy_set( STATIC_ADR_MODE ); -#if !defined( PERF_TEST_ENABLED ) - // do not clear join status that was set to joined to allow perf testbench to trigger some modem send tx commands lorawan_api_join_status_clear( ); -#endif + modem_context_init( ); modem_event_init( ); modem_supervisor_init_task( ); modem_load_context( ); + +#if defined( ADD_SMTC_ALC_SYNC ) alc_sync_init( alc_sync_context ); clock_sync_init( clock_sync_context, alc_sync_context ); -#if defined( LR1110_MODEM_E ) +#endif // ADD_SMTC_ALC_SYNC + +#if defined( LR1110_MODEM_E ) && defined( ADD_SMTC_PATCH_UPDATE ) frag_init( ); -#endif // LR1110_MODEM_E +#endif // LR1110_MODEM_E && ADD_SMTC_PATCH_UPDATE set_modem_start_time_s( smtc_modem_hal_get_time_in_s( ) ); @@ -344,9 +383,6 @@ void modem_supervisor_launch_task( task_id_t id ) break; } - case SEND_AT_TIME_TASK: - break; - case DM_TASK: if( get_join_state( ) == MODEM_JOINED ) { @@ -468,6 +504,7 @@ void modem_supervisor_launch_task( task_id_t id ) } } break; +#if defined( ADD_SMTC_FILE_UPLOAD ) case FILE_UPLOAD_TASK: { int32_t file_upload_chunk_size = 0; uint8_t file_upload_chunk_payload[242] = { 0 }; @@ -502,6 +539,9 @@ void modem_supervisor_launch_task( task_id_t id ) break; } +#endif // ADD_SMTC_FILE_UPLOAD + +#if defined( ADD_SMTC_STREAM ) case STREAM_TASK: { uint8_t stream_payload[242] = { 0 }; uint8_t fragment_size; @@ -548,6 +588,7 @@ void modem_supervisor_launch_task( task_id_t id ) } break; } +#endif // ADD_SMTC_STREAM case MUTE_TASK: { if( get_modem_muted( ) == MODEM_TEMPORARY_MUTE ) { @@ -560,12 +601,12 @@ void modem_supervisor_launch_task( task_id_t id ) get_dm_retrieve_pending_dl( &retrieve ); if( retrieve.up_count > 0 ) { - send_status = lorawan_api_payload_send( - get_modem_dm_port( ), true, task_manager.modem_task[id].dataIn, task_manager.modem_task[id].sizeIn, - task_manager.modem_task[id].PacketType, smtc_modem_hal_get_time_in_ms( ) + MODEM_TASK_DELAY_MS ); + send_status = lorawan_api_payload_send( 0, false, NULL, 0, UNCONF_DATA_UP, + smtc_modem_hal_get_time_in_ms( ) + MODEM_TASK_DELAY_MS ); } break; } +#if defined( ADD_SMTC_ALC_SYNC ) case CLOCK_SYNC_TIME_REQ_TASK: { if( lorawan_api_modem_certification_is_enabled( ) == true ) { @@ -616,6 +657,7 @@ void modem_supervisor_launch_task( task_id_t id ) } break; } +#endif // ADD_SMTC_ALC_SYNC case LINK_CHECK_REQ_TASK: lorawan_api_send_stack_cid_req( LINK_CHECK_REQ ); break; @@ -627,7 +669,7 @@ void modem_supervisor_launch_task( task_id_t id ) SMTC_MODEM_HAL_TRACE_WARNING( "PING SLOT REQUEST\n" ); lorawan_api_send_stack_cid_req( PING_SLOT_INFO_REQ ); break; -#if defined( LR1110_MODEM_E ) +#if defined( LR1110_MODEM_E ) && defined( ADD_SMTC_PATCH_UPDATE ) case FRAG_TASK: { uint8_t max_payload = lorawan_api_next_max_payload_length_get( ); @@ -644,7 +686,7 @@ void modem_supervisor_launch_task( task_id_t id ) } break; } -#endif // LR1110_MODEM_E +#endif // LR1110_MODEM_E && ADD_SMTC_PATCH_UPDATE case USER_TASK: { send_status = lorawan_api_payload_send( get_modem_dm_port( ), true, task_manager.modem_task[id].dataIn, task_manager.modem_task[id].sizeIn, @@ -699,6 +741,7 @@ void modem_supervisor_update_task( task_id_t id ) // reset dm tag number to prevent using wrong id modem_context_reset_dm_tag_number( ); +#if defined( ADD_SMTC_ALC_SYNC ) // If clock sync service activated => initiate a new request if( clock_sync_is_enabled( clock_sync_context ) == true ) { @@ -706,6 +749,7 @@ void modem_supervisor_update_task( task_id_t id ) smtc_modem_hal_get_random_nb_in_range( 0, 5 ) ); clock_sync_reset_nb_time_req( clock_sync_context ); } +#endif // ADD_SMTC_ALC_SYNC if( smtc_modem_hal_get_crashlog_status( ) == true ) { modem_supervisor_add_task_crash_log( DM_PERIOD_AFTER_JOIN + 30 + @@ -764,6 +808,7 @@ void modem_supervisor_update_task( task_id_t id ) case SEND_TASK_EXTENDED_2: ( modem_get_extended_callback( 2 ) )( ); break; +#if defined( ADD_SMTC_FILE_UPLOAD ) case FILE_UPLOAD_TASK: { modem_upload_state_t modem_upload_state = modem_get_upload_state( ); if( modem_upload_state == MODEM_UPLOAD_ON_GOING ) @@ -784,6 +829,9 @@ void modem_supervisor_update_task( task_id_t id ) } break; } +#endif // ADD_SMTC_FILE_UPLOAD + +#if defined( ADD_SMTC_STREAM ) case STREAM_TASK: { // SMTC_MODEM_HAL_TRACE_MSG( "Supervisor update STREAM_TASK\n" ); if( stream_data_pending( ROSE ) ) @@ -798,6 +846,7 @@ void modem_supervisor_update_task( task_id_t id ) } break; } +#endif // ADD_SMTC_STREAM case MUTE_TASK: { if( get_modem_muted( ) == MODEM_TEMPORARY_MUTE ) { @@ -815,35 +864,26 @@ void modem_supervisor_update_task( task_id_t id ) break; } +#if defined( ADD_SMTC_ALC_SYNC ) case CLOCK_SYNC_TIME_REQ_TASK: { + clock_sync_callback( clock_sync_context, 0 ); // TODO change 0 + if( clock_sync_context->sync_service_type == CLOCK_SYNC_ALC ) { - clock_sync_callback( clock_sync_context, 0 ); // TODO change 0 - } - else - { - if( clock_sync_is_done( clock_sync_context ) ) + // Answer with time sync not received, create a new downlink opportunities + if( clock_sync_is_time_valid( clock_sync_context ) == false ) { - if( clock_sync_is_time_valid( clock_sync_context ) == true ) + dm_dl_opportunities_config_t retrieve; + get_dm_retrieve_pending_dl( &retrieve ); + if( retrieve.up_count == 0 ) { - increment_asynchronous_msgnumber( SMTC_MODEM_EVENT_TIME, SMTC_MODEM_EVENT_TIME_VALID ); + retrieve.up_delay = smtc_modem_hal_get_random_nb_in_range( 3, 8 ); + set_dm_retrieve_pending_dl( 1, retrieve.up_delay ); + modem_supervisor_add_task_retrieve_dl( retrieve.up_delay ); } } } - // Answer with time sync not received, create a new downlink opportunities - if( clock_sync_is_time_valid( clock_sync_context ) == false ) - { - dm_dl_opportunities_config_t retrieve; - get_dm_retrieve_pending_dl( &retrieve ); - if( retrieve.up_count == 0 ) - { - retrieve.up_delay = smtc_modem_hal_get_random_nb_in_range( 3, 8 ); - set_dm_retrieve_pending_dl( 1, retrieve.up_delay ); - modem_supervisor_add_task_retrieve_dl( retrieve.up_delay ); - } - } - break; } case ALC_SYNC_ANS_TASK: @@ -852,6 +892,7 @@ void modem_supervisor_update_task( task_id_t id ) modem_supervisor_add_task_alc_sync_ans( smtc_modem_hal_get_random_nb_in_range( 128, 150 ) ); } break; +#endif // ADD_SMTC_ALC_SYNC case LINK_CHECK_REQ_TASK: { uint8_t margin; @@ -900,7 +941,6 @@ void modem_supervisor_update_task( task_id_t id ) default: break; } - AvailableRxPacket = NO_LORA_RXPACKET_AVAILABLE; } uint32_t modem_supervisor_scheduler( void ) @@ -1002,14 +1042,7 @@ uint32_t modem_supervisor_engine( void ) if( ( LpState != LWPSTATE_IDLE ) && ( LpState != LWPSTATE_ERROR ) && ( LpState != LWPSTATE_INVALID ) ) { - LpState = lorawan_api_process( &AvailableRxPacket ); - if( ( AvailableRxPacket != NO_LORA_RXPACKET_AVAILABLE ) && ( LpState == LWPSTATE_TX_WAIT ) ) - { // there is an applicative downlink and a nwk frame to send so lr1mac is in the state tx wait - if( task_manager.next_task_id != IDLE_TASK ) - { - // modem_supervisor_update_downlink_frame( ); - } - } + LpState = lorawan_api_process( ); return ( CALL_LR1MAC_PERIOD_MS ); } @@ -1147,6 +1180,7 @@ uint8_t modem_supervisor_update_downlink_frame( uint8_t* data, uint8_t data_leng { dm_downlink( dwnframe.data, dwnframe.length ); } +#if defined( ADD_SMTC_ALC_SYNC ) else if( dwnframe.port == clock_sync_get_alcsync_port( clock_sync_context ) ) { if( ( metadata->rx_window == RECEIVE_ON_RX1 ) || ( metadata->rx_window == RECEIVE_ON_RX2 ) || @@ -1203,7 +1237,9 @@ uint8_t modem_supervisor_update_downlink_frame( uint8_t* data, uint8_t data_leng } } } -#if defined( LR1110_MODEM_E ) +#endif // ADD_SMTC_ALC_SYNC + +#if defined( LR1110_MODEM_E ) && defined( ADD_SMTC_PATCH_UPDATE ) else if( dwnframe.port == get_modem_frag_port( ) ) { int8_t frag_status = frag_parser( dwnframe.data, dwnframe.length ); @@ -1221,7 +1257,7 @@ uint8_t modem_supervisor_update_downlink_frame( uint8_t* data, uint8_t data_leng // Nothing to do } } -#endif // LR1110_MODEM_E +#endif // LR1110_MODEM_E && ADD_SMTC_PATCH_UPDATE else { return 1; @@ -1342,18 +1378,20 @@ static void certification_event_handler( void ) break; } break; - +#if defined( ADD_SMTC_FILE_UPLOAD ) case SMTC_MODEM_EVENT_UPLOADDONE: break; - +#endif // ADD_SMTC_FILE_UPLOAD case SMTC_MODEM_EVENT_SETCONF: break; case SMTC_MODEM_EVENT_MUTE: break; +#if defined( ADD_SMTC_STREAM ) case SMTC_MODEM_EVENT_STREAMDONE: break; +#endif // ADD_SMTC_STREAM case SMTC_MODEM_EVENT_JOINFAIL: SMTC_MODEM_HAL_TRACE_WARNING( "Join failed \n" ); @@ -1370,7 +1408,11 @@ static void certification_event_handler( void ) if( lorawan_api_certification_get_requested_class( ) == LORAWAN_CERTIFICATION_CLASS_B ) { if( ( lorawan_api_get_ping_slot_info_req_status( ) == OKLORAWAN ) && +#if defined( ADD_SMTC_ALC_SYNC ) ( clock_sync_is_time_valid( clock_sync_context ) == true ) ) +#else // ADD_SMTC_ALC_SYNC + ( lorawan_api_is_time_valid( ) == true ) ) +#endif // ADD_SMTC_ALC_SYNC { SMTC_MODEM_HAL_TRACE_PRINTF( "Certif enable classB\n" ); lorawan_api_class_b_enabled( true ); @@ -1378,7 +1420,11 @@ static void certification_event_handler( void ) else { SMTC_MODEM_HAL_TRACE_PRINTF( "Certif classB could not be enabled\n" ); +#if defined( ADD_SMTC_ALC_SYNC ) if( clock_sync_is_time_valid( clock_sync_context ) == false ) +#else // ADD_SMTC_ALC_SYNC + if( lorawan_api_is_time_valid( ) == false ) +#endif // ADD_SMTC_ALC_SYNC { modem_supervisor_add_task_device_time_req( 1 ); } @@ -1441,7 +1487,11 @@ static void certification_event_handler( void ) { lorawan_api_class_c_enabled( false ); +#if defined( ADD_SMTC_ALC_SYNC ) if( clock_sync_is_time_valid( clock_sync_context ) == false ) +#else // ADD_SMTC_ALC_SYNC + if( lorawan_api_is_time_valid( ) == false ) +#endif // ADD_SMTC_ALC_SYNC { modem_supervisor_add_task_device_time_req( 0 ); // modem_supervisor_add_task_clock_sync_time_req( 0 ); diff --git a/smtc_modem_core/modem_supervisor/modem_supervisor.h b/smtc_modem_core/modem_supervisor/modem_supervisor.h index 53ca30e..991509d 100644 --- a/smtc_modem_core/modem_supervisor/modem_supervisor.h +++ b/smtc_modem_core/modem_supervisor/modem_supervisor.h @@ -44,11 +44,20 @@ extern "C" { * --- DEPENDENCIES ------------------------------------------------------------ */ #include "radio_planner.h" -#include "alc_sync.h" +#include "lr1_stack_mac_layer.h" + +#if defined( ADD_SMTC_ALC_SYNC ) #include "smtc_clock_sync.h" +#include "alc_sync.h" +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) #include "stream.h" +#endif // ADD_SMTC_STREAM + +#if defined( ADD_SMTC_FILE_UPLOAD ) #include "file_upload.h" -#include "lr1_stack_mac_layer.h" +#endif // ADD_SMTC_FILE_UPLOAD /* * ----------------------------------------------------------------------------- @@ -72,18 +81,23 @@ extern "C" { */ typedef enum { - SEND_TASK, //!< task managed by the application such as sensor uplink for example - SEND_AT_TIME_TASK, //!< not used - JOIN_TASK, //!< task managed by the modem itself to join a network - DM_TASK, //!< task managed by the modem itself to report periodically status - DM_TASK_NOW, //!< task managed by the modem when requested by the host or the cloud to report status + SEND_TASK, //!< task managed by the application such as sensor uplink for example + JOIN_TASK, //!< task managed by the modem itself to join a network + DM_TASK, //!< task managed by the modem itself to report periodically status + DM_TASK_NOW, //!< task managed by the modem when requested by the host or the cloud to report status +#if defined( ADD_SMTC_FILE_UPLOAD ) FILE_UPLOAD_TASK, //!< task initiate by the application layer but manage by the modem itself to transfer "big file" +#endif // ADD_SMTC_FILE_UPLOAD IDLE_TASK, //!< mean no more active task schedule MUTE_TASK, //!< task managed by the modem to un-mute the modem RETRIEVE_DL_TASK, //!< task managed by the modem to create downlink opportunities +#if defined( ADD_SMTC_STREAM ) STREAM_TASK, //!< task initiated by the application layer, but managed by the modem itself to transfer long streams +#endif // ADD_SMTC_STREAM +#if defined( ADD_SMTC_ALC_SYNC ) CLOCK_SYNC_TIME_REQ_TASK, //!< task managed by the modem to launch Application Layer Clock Synchronisation ALC_SYNC_ANS_TASK, //!< task managed by the modem to launch Application Layer Clock Synchronisation answer +#endif // ADD_SMTC_ALC_SYNC FRAG_TASK, //!< task managed by the modem to launch Fragmented Data Block uplink USER_TASK, //!< task manage by the modem to launch a user callback (use also for wifi and gnss tasks) DM_ALM_DBG_ANS, //!< task managed by the modem to launch almanac debug answer @@ -91,8 +105,8 @@ typedef enum LINK_CHECK_REQ_TASK, //!< task managed by the modem to launch a Network Link Check Request DEVICE_TIME_REQ_TASK, //!< task managed by the modem to launch a Network Device Time Request synchronisation PING_SLOT_INFO_REQ_TASK, //!< task managed by the modem to launch a Network Ping Slot Info Request for class B - SEND_TASK_EXTENDED_1, //!< task managed by the application dedicated for middleware gnss/wifi - SEND_TASK_EXTENDED_2, //!< task managed by the application dedicated for middleware gnss/wifi + SEND_TASK_EXTENDED_1, //!< task managed by the application dedicated for middleware gnss/wifi + SEND_TASK_EXTENDED_2, //!< task managed by the application dedicated for middleware gnss/wifi NUMBER_OF_TASKS //!< number of tasks } task_id_t; @@ -156,10 +170,18 @@ typedef struct stask_manager typedef struct smtc_modem_services_s { +#if defined( ADD_SMTC_ALC_SYNC ) alc_sync_ctx_t alc_sync_ctx; clock_sync_ctx_t clock_sync_ctx; - rose_t stream_ROSE_ctx; - file_upload_t file_upload_ctx; +#endif // ADD_SMTC_ALC_SYNC + +#if defined( ADD_SMTC_STREAM ) + rose_t stream_ROSE_ctx; +#endif // ADD_SMTC_STREAM + +#if defined( ADD_SMTC_FILE_UPLOAD ) + file_upload_t file_upload_ctx; +#endif // ADD_SMTC_FILE_UPLOAD } smtc_modem_services_t; /* * ----------------------------------------------------------------------------- diff --git a/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md b/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md index 072dcef..3b86d88 100644 --- a/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md +++ b/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.1.1] 2022-04-06 + +### Fixed + +* [radio] Order of the parameters in `lr11xx_radio_set_rssi_calibration()` function + ## [v2.1.0] 2022-03-28 ### Added diff --git a/smtc_modem_core/radio_drivers/lr11xx_driver/LICENSE.txt b/smtc_modem_core/radio_drivers/lr11xx_driver/LICENSE.txt index 55bf268..292ef9b 100644 --- a/smtc_modem_core/radio_drivers/lr11xx_driver/LICENSE.txt +++ b/smtc_modem_core/radio_drivers/lr11xx_driver/LICENSE.txt @@ -1,5 +1,8 @@ +License for the code produced by Semtech contained in this project +------------------------------------------------------------------ + The Clear BSD License -Copyright Semtech Corporation 2021. All rights reserved. +Copyright Semtech Corporation 2022. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer diff --git a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h index aba3e22..24e06e4 100644 --- a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h +++ b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h @@ -56,7 +56,7 @@ extern "C" { #define LR11XX_DRIVER_VERSION_MAJOR 2 #define LR11XX_DRIVER_VERSION_MINOR 1 -#define LR11XX_DRIVER_VERSION_PATCH 0 +#define LR11XX_DRIVER_VERSION_PATCH 1 /* * ----------------------------------------------------------------------------- diff --git a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c index 4210945..e191510 100644 --- a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c +++ b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c @@ -806,17 +806,17 @@ lr11xx_status_t lr11xx_radio_set_rssi_calibration( const void* const uint8_t cbuffer[LR11XX_RADIO_SET_RSSI_CALIBRATION_LENGTH] = { ( uint8_t ) ( LR11XX_RADIO_SET_RSSI_CALIBRATION_OC >> 8 ), ( uint8_t ) ( LR11XX_RADIO_SET_RSSI_CALIBRATION_OC >> 0 ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g11 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g10 & 0x0F ) ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g9 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g8 & 0x0F ) ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g7 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g6 & 0x0F ) ), ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g5 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g4 & 0x0F ) ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13hp6 & 0x0F ) << 4 ) + - ( rssi_cal_table->gain_tune.g13hp5 & 0x0F ) ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13hp4 & 0x0F ) << 4 ) + - ( rssi_cal_table->gain_tune.g13hp3 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g7 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g6 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g9 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g8 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g11 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g10 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g12 & 0x0F ) ), ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13hp2 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g13hp1 & 0x0F ) ), - ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13 & 0x0F ) << 4 ) + ( rssi_cal_table->gain_tune.g12 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13hp4 & 0x0F ) << 4 ) + + ( rssi_cal_table->gain_tune.g13hp3 & 0x0F ) ), + ( uint8_t ) ( ( ( rssi_cal_table->gain_tune.g13hp6 & 0x0F ) << 4 ) + + ( rssi_cal_table->gain_tune.g13hp5 & 0x0F ) ), ( uint8_t ) ( rssi_cal_table->gain_tune.g13hp7 & 0x0F ), ( uint8_t ) ( rssi_cal_table->gain_offset >> 8 ), ( uint8_t ) ( rssi_cal_table->gain_offset >> 0 ), diff --git a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h index ed1820e..6f5c58d 100644 --- a/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h +++ b/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h @@ -537,22 +537,22 @@ typedef struct lr11xx_radio_rssi_calibration_table_s { struct { - uint8_t g11; - uint8_t g10; - uint8_t g9; - uint8_t g8; - uint8_t g7; - uint8_t g6; - uint8_t g5; uint8_t g4; - uint8_t g13hp6; - uint8_t g13hp5; - uint8_t g13hp4; - uint8_t g13hp3; - uint8_t g13hp2; - uint8_t g13hp1; - uint8_t g13; + uint8_t g5; + uint8_t g6; + uint8_t g7; + uint8_t g8; + uint8_t g9; + uint8_t g10; + uint8_t g11; uint8_t g12; + uint8_t g13; + uint8_t g13hp1; + uint8_t g13hp2; + uint8_t g13hp3; + uint8_t g13hp4; + uint8_t g13hp5; + uint8_t g13hp6; uint8_t g13hp7; } gain_tune; //!< Used to set gain tune value for RSSI calibration diff --git a/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md b/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md index 719c508..bdf66e9 100644 --- a/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md +++ b/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.1.0] - 2022-05-18 + +### Added + +- `sx126x_set_gfsk_pkt_address()` function - configure both GFSK node and brodcast filtering addresses +- `sx126x_handle_rx_done()` function - perform all requested actions when the chip leaves the Rx mode + ## [2.0.1] - 2021-11-23 ### Added diff --git a/smtc_modem_core/radio_drivers/sx126x_driver/src/lr_fhss_mac.c b/smtc_modem_core/radio_drivers/sx126x_driver/src/lr_fhss_mac.c index c22fdbb..e81e474 100644 --- a/smtc_modem_core/radio_drivers/sx126x_driver/src/lr_fhss_mac.c +++ b/smtc_modem_core/radio_drivers/sx126x_driver/src/lr_fhss_mac.c @@ -91,8 +91,8 @@ STATIC const uint8_t lr_fhss_viterbi_1_3_table[64][2] = { /** @brief used for 1/2 rate viterbi encoding */ STATIC const uint8_t lr_fhss_viterbi_1_2_table[16][2] = { { 0, 3 }, { 1, 2 }, { 2, 1 }, { 3, 0 }, { 2, 1 }, { 3, 0 }, - { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 }, - { 1, 2 }, { 0, 3 }, { 3, 0 }, { 2, 1 } }; + { 0, 3 }, { 1, 2 }, { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 }, + { 1, 2 }, { 0, 3 }, { 3, 0 }, { 2, 1 } }; /** @brief used header interleaving */ STATIC const uint8_t lr_fhss_header_interleaver_minus_one[80] = { @@ -329,11 +329,7 @@ void lr_fhss_process_parameters( const lr_fhss_v1_params_t* params, uint16_t pay digest->nb_bits = lr_fhss_get_bit_and_hop_count( params, payload_length, &digest->nb_hops ); digest->nb_bytes = ( digest->nb_bits + 8 - 1 ) / 8; - if( params->enable_hopping ) - { - digest->nb_hops = digest->nb_hops; - } - else + if( params->enable_hopping == false ) { digest->nb_hops = 1; } @@ -774,7 +770,7 @@ STATIC uint16_t lr_fhss_payload_interleaving( const uint8_t* data_in, uint16_t d lr_fhss_set_bit_in_byte_vector( data_out, 0 + out_row_index, 0 ); // guard bits lr_fhss_set_bit_in_byte_vector( data_out, 1 + out_row_index, 0 ); // guard bits - for( uint32_t j = 0; j < in_row_width; j++ ) + for( int32_t j = 0; j < in_row_width; j++ ) { lr_fhss_set_bit_in_byte_vector( data_out, j + 2 + out_row_index, lr_fhss_extract_bit_in_byte_vector( data_in, pos ) ); // guard bit diff --git a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.c b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.c index 70ba038..b1aec4d 100644 --- a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.c +++ b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.c @@ -731,6 +731,14 @@ sx126x_status_t sx126x_set_lora_pkt_params( const void* context, const sx126x_pk return status; } +sx126x_status_t sx126x_set_gfsk_pkt_address( const void* context, const uint8_t node_address, + const uint8_t broadcast_address ) +{ + const uint8_t addresses[2] = { node_address, broadcast_address }; + + return sx126x_write_register( context, SX126X_REG_GFSK_NODE_ADDRESS, addresses, 2 ); +} + sx126x_status_t sx126x_set_cad_params( const void* context, const sx126x_cad_params_t* params ) { const uint8_t buf[SX126X_SIZE_SET_CAD_PARAMS] = { @@ -1231,6 +1239,11 @@ uint32_t sx126x_convert_timeout_in_ms_to_rtc_step( uint32_t timeout_in_ms ) return ( uint32_t )( timeout_in_ms * ( SX126X_RTC_FREQ_IN_HZ / 1000 ) ); } +sx126x_status_t sx126x_handle_rx_done( const void* context ) +{ + return sx126x_stop_rtc( context ); +} + // // Registers access // diff --git a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.h b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.h index 99765a7..887bfc8 100644 --- a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.h +++ b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x.h @@ -89,6 +89,11 @@ extern "C" { */ #define SX126X_OCP_PARAM_VALUE_140_MA 0x38 +/** + * @brief XTA and XTB trimming capacitor default value after the chip entered @ref SX126X_STANDBY_CFG_XOSC mode + */ +#define SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC 0x12 + /** * @brief Maximum value for parameter nb_of_symbs in @ref sx126x_set_lora_symb_nb_timeout */ @@ -717,6 +722,8 @@ sx126x_status_t sx126x_set_tx_with_timeout_in_rtc_step( const void* context, con * | ----------------------| --------------------------------------------------------------------------------------| * | SX126X_RX_SINGLE_MODE | Single: the chip stays in RX mode until a reception occurs, then switch to standby RC | * + * @remark Refer to @ref sx126x_handle_rx_done + * * @param [in] context Chip implementation context * @param [in] timeout_in_ms The timeout configuration in millisecond for Rx operation * @@ -745,6 +752,8 @@ sx126x_status_t sx126x_set_rx( const void* context, const uint32_t timeout_in_ms * | SX126X_RX_SINGLE_MODE | Single: the chip stays in RX mode until a reception occurs, then switch to standby RC | * | SX126X_RX_CONTINUOUS | Continuous: the chip stays in RX mode even after reception of a packet | * + * @remark Refer to @ref sx126x_handle_rx_done + * * @param [in] context Chip implementation context * @param [in] timeout_in_rtc_step The timeout configuration for Rx operation * @@ -1178,6 +1187,20 @@ sx126x_status_t sx126x_set_gfsk_pkt_params( const void* context, const sx126x_pk */ sx126x_status_t sx126x_set_lora_pkt_params( const void* context, const sx126x_pkt_params_lora_t* params ); +/*! + * @brief Set the Node and Broadcast address used for GFSK + * + * This setting is used only when filtering is enabled. + * + * @param [in] context Chip implementation context + * @param [in] node_address The node address used as filter + * @param [in] broadcast_address The broadcast address used as filter + * + * @returns Operation status + */ +sx126x_status_t sx126x_set_gfsk_pkt_address( const void* context, const uint8_t node_address, + const uint8_t broadcast_address ); + /** * @brief Set the parameters for CAD operation * @@ -1452,6 +1475,18 @@ uint32_t sx126x_convert_freq_in_hz_to_pll_step( uint32_t freq_in_hz ); */ uint32_t sx126x_convert_timeout_in_ms_to_rtc_step( uint32_t timeout_in_ms ); +/** + * @brief Generic finalizing function after reception + * + * @remark This function can be called after any reception sequence and must be called after any reception with timeout + * active sequence. + * + * @param [in] context Chip implementation context + * + * @returns Operation status + */ +sx126x_status_t sx126x_handle_rx_done( const void* context ); + // // Registers access // diff --git a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_regs.h b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_regs.h index 6fce177..1022016 100644 --- a/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_regs.h +++ b/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_regs.h @@ -202,6 +202,20 @@ */ #define SX126X_REG_RETENTION_LIST_BASE_ADDRESS 0x029F +/** + * @brief GFSK node address + * + * @remark Reset value is 0x00 + */ +#define SX126X_REG_GFSK_NODE_ADDRESS 0x06CD + +/** + * @brief GFSK broadcast address + * + * @remark Reset value is 0x00 + */ +#define SX126X_REG_GFSK_BROADCAST_ADDRESS 0x06CE + /* * ----------------------------------------------------------------------------- * --- PUBLIC TYPES ------------------------------------------------------------ diff --git a/smtc_modem_core/radio_planner/src/radio_planner.c b/smtc_modem_core/radio_planner/src/radio_planner.c index 5bdca42..0115f8d 100644 --- a/smtc_modem_core/radio_planner/src/radio_planner.c +++ b/smtc_modem_core/radio_planner/src/radio_planner.c @@ -39,31 +39,6 @@ #include -// -// Private planner variable declaration -// -#if defined( PERF_TEST_ENABLED ) - -#if !defined( LR1110_MODEM_E ) -static uint32_t tx_done_count = 0; -static uint32_t rx_done_count = 0; -static uint32_t rx_timeout_count = 0; -#else -struct -{ - uint32_t tx_done_count; - uint32_t rx_done_count; - uint32_t rx_timeout_count; -} rp_ctx; - -// clang-format off -#define tx_done_count rp_ctx.tx_done_count -#define rx_done_count rp_ctx.rx_done_count -#define rx_timeout_count rp_ctx.rx_timeout_count -// clang-format on -#endif -#endif - // // Private planner utilities declaration // @@ -237,12 +212,7 @@ void rp_init( radio_planner_t* rp, const ralf_t* radio ) rp_stats_init( &rp->stats ); rp->next_state_status = RP_STATUS_NO_MORE_TASK_SCHEDULE; - -#if defined( PERF_TEST_ENABLED ) - tx_done_count = 0; - rx_done_count = 0; - rx_timeout_count = 0; -#endif + rp->margin_delay = RP_MARGIN_DELAY; } rp_hook_status_t rp_hook_init( radio_planner_t* rp, const uint8_t id, void ( *callback )( void* context ), void* hook ) @@ -420,7 +390,7 @@ void rp_radio_irq( radio_planner_t* rp ) uint32_t irq_timestamp_100us = rp_hal_get_radio_irq_timestamp_in_100us( ); rp->irq_timestamp_100us[rp->radio_task_id] = irq_timestamp_100us; - rp->irq_timestamp_ms[rp->radio_task_id] = irq_timestamp_100us / 10; + rp->irq_timestamp_ms[rp->radio_task_id] = rp_hal_get_time_in_ms( ); SMTC_MODEM_HAL_RP_TRACE_PRINTF( " RP: INFO - Radio IRQ received for hook #%u\n", rp->radio_task_id ); rp_irq_get_status( rp, rp->radio_task_id ); @@ -428,7 +398,18 @@ void rp_radio_irq( radio_planner_t* rp ) { return; } - if( rp->status[rp->radio_task_id] == RP_STATUS_CAD_NEGATIVE ) + + // Tx can be performed only if no activity detected on channel + if( ( rp->status[rp->radio_task_id] == RP_STATUS_CAD_NEGATIVE ) && + ( rp->tasks[rp->radio_task_id].type == RP_TASK_TYPE_CAD_TO_TX ) ) + { + rp_hook_callback( rp, rp->radio_task_id ); + return; + } + + // Rx can be performed if activity detected on channel + if( ( rp->status[rp->radio_task_id] == RP_STATUS_CAD_POSITIVE ) && + ( rp->tasks[rp->radio_task_id].type == RP_TASK_TYPE_CAD_TO_RX ) ) { rp_hook_callback( rp, rp->radio_task_id ); return; @@ -508,7 +489,7 @@ static void rp_task_update_time( radio_planner_t* rp, uint32_t now ) ( rp->tasks[rp->radio_task_id].type == RP_TASK_TYPE_RX_FSK ) ) ) { rp->tasks[rp->radio_task_id].duration_time_ms = - now + RP_MARGIN_DELAY + 2 - rp->tasks[rp->radio_task_id].start_time_ms; + now + rp->margin_delay + 2 - rp->tasks[rp->radio_task_id].start_time_ms; SMTC_MODEM_HAL_RP_TRACE_PRINTF( " RP: Extended duration of radio task #%u time to %lu ms\n", rp->radio_task_id, now ); } @@ -529,13 +510,8 @@ static void rp_task_arbiter( radio_planner_t* rp, const char* caller_func_name ) " RP: Arbiter has been called by %s and priority-task #%d, timer hook #%d, delay %d, now %d\n ", caller_func_name, rp->priority_task.hook_id, rp->timer_hook_id, delay, now ); - // Case where the high priority task is in the future - if( delay > RP_MARGIN_DELAY ) - { // The high priority task is in the future - SMTC_MODEM_HAL_RP_TRACE_PRINTF( " RP: High priority task is in the future\n" ); - } // Case where the high priority task is in the past, error case - else if( delay < 0 ) + if( delay < 0 ) { // The high priority task is in the past, error case if( rp->priority_task.state != RP_TASK_STATE_RUNNING ) { @@ -545,6 +521,11 @@ static void rp_task_arbiter( radio_planner_t* rp, const char* caller_func_name ) rp->tasks[rp->priority_task.hook_id].state = RP_TASK_STATE_ABORTED; } } + // Case where the high priority task is in the future + else if( ( uint32_t ) delay > rp->margin_delay ) + { // The high priority task is in the future + SMTC_MODEM_HAL_RP_TRACE_PRINTF( " RP: High priority task is in the future\n" ); + } // Case where the high priority task is now else { @@ -583,15 +564,17 @@ static void rp_task_arbiter( radio_planner_t* rp, const char* caller_func_name ) // Timer has expired on a not priority task => Have to abort this task int32_t tmp = ( int32_t )( rp->tasks[rp->timer_hook_id].start_time_ms - now ); - if( ( tmp > 0 ) && ( tmp < RP_MARGIN_DELAY ) && ( rp->next_state_status == RP_STATUS_HAVE_TO_SET_TIMER ) && - ( rp->timer_hook_id != rp->priority_task.hook_id ) && - ( rp->tasks[rp->timer_hook_id].state == RP_TASK_STATE_SCHEDULE ) ) + if( tmp > 0 ) { - SMTC_MODEM_HAL_TRACE_WARNING( " RP: Aborted task with hook #%u - not a priority task\n ", - rp->timer_hook_id ); - rp->tasks[rp->timer_hook_id].state = RP_TASK_STATE_ABORTED; + if( ( ( uint32_t ) tmp < rp->margin_delay ) && ( rp->next_state_status == RP_STATUS_HAVE_TO_SET_TIMER ) && + ( rp->timer_hook_id != rp->priority_task.hook_id ) && + ( rp->tasks[rp->timer_hook_id].state == RP_TASK_STATE_SCHEDULE ) ) + { + SMTC_MODEM_HAL_TRACE_WARNING( " RP: Aborted task with hook #%u - not a priority task\n ", + rp->timer_hook_id ); + rp->tasks[rp->timer_hook_id].state = RP_TASK_STATE_ABORTED; + } } - // Execute the garbage collection if the radio isn't running if( rp->tasks[rp->radio_task_id].state != RP_TASK_STATE_RUNNING ) { @@ -603,9 +586,9 @@ static void rp_task_arbiter( radio_planner_t* rp, const char* caller_func_name ) if( rp->next_state_status == RP_STATUS_HAVE_TO_SET_TIMER ) { - if( rp->timer_value > RP_MARGIN_DELAY ) + if( rp->timer_value > rp->margin_delay ) { - rp_set_alarm( rp, rp->timer_value - RP_MARGIN_DELAY ); + rp_set_alarm( rp, rp->timer_value - rp->margin_delay ); } else { @@ -646,30 +629,15 @@ static void rp_irq_get_status( radio_planner_t* rp, const uint8_t hook_id ) &rp->radio_params[hook_id].tx.lr_fhss.ral_lr_fhss_params, NULL ) == RAL_STATUS_OK ); } -#if defined( PERF_TEST_ENABLED ) - tx_done_count++; - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "RADIO IRQ: TX DONE\n" ); - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "tx_done_count:%lu\n", tx_done_count ); -#endif } else if( ( ( radio_irq & RAL_IRQ_RX_HDR_ERROR ) == RAL_IRQ_RX_HDR_ERROR ) || ( ( radio_irq & RAL_IRQ_RX_CRC_ERROR ) == RAL_IRQ_RX_CRC_ERROR ) ) { rp->status[hook_id] = RP_STATUS_RX_CRC_ERROR; -#if defined( PERF_TEST_ENABLED ) - rx_timeout_count++; - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "RADIO IRQ: HDR_ERROR or CRC_ERROR : %d\n", radio_irq ); - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "rx_timeout_count:%lu\n", rx_timeout_count ); -#endif } else if( ( radio_irq & RAL_IRQ_RX_TIMEOUT ) == RAL_IRQ_RX_TIMEOUT ) { rp->status[hook_id] = RP_STATUS_RX_TIMEOUT; -#if defined( PERF_TEST_ENABLED ) - rx_timeout_count++; - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "RADIO IRQ: RX_TIMEOUT\n" ); - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "rx_timeout_count:%lu\n", rx_timeout_count ); -#endif } else if( ( radio_irq & RAL_IRQ_RX_DONE ) == RAL_IRQ_RX_DONE ) { @@ -680,11 +648,6 @@ static void rp_irq_get_status( radio_planner_t* rp, const uint8_t hook_id ) smtc_modem_hal_mcu_panic( ); return; } -#if defined( PERF_TEST_ENABLED ) - rx_done_count++; - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "RADIO IRQ: RX_DONE\n" ); - SMTC_MODEM_HAL_PERF_TEST_TRACE_PRINTF( "rx_done_count:%lu\n", rx_done_count ); -#endif } else if( ( radio_irq & RAL_IRQ_CAD_OK ) == RAL_IRQ_CAD_OK ) { @@ -877,7 +840,7 @@ rp_hook_status_t rp_get_pkt_payload( radio_planner_t* rp, const rp_task_t* task smtc_modem_hal_assert( ral_get_pkt_payload( &( rp->radio->ral ), rp->payload_size[id], rp->payload[id], &rp->payload_size[id] ) == RAL_STATUS_OK ); - if( task->type == RP_TASK_TYPE_RX_LORA ) + if( ( task->type == RP_TASK_TYPE_RX_LORA ) || ( task->type == RP_TASK_TYPE_CAD_TO_RX ) ) { rp->radio_params[id].pkt_type = RAL_PKT_TYPE_LORA; status = RP_HOOK_STATUS_OK; @@ -980,9 +943,16 @@ static void rp_task_print( const radio_planner_t* rp, const rp_task_t* task ) break; case RP_TASK_TYPE_TX_LR_FHSS: SMTC_MODEM_HAL_RP_TRACE_PRINTF( " TASK_TX_LR_FHSS " ); + break; case RP_TASK_TYPE_CAD: SMTC_MODEM_HAL_RP_TRACE_PRINTF( " TASK_CAD " ); break; + case RP_TASK_TYPE_CAD_TO_TX: + SMTC_MODEM_HAL_RP_TRACE_PRINTF( " TASK_CAD_TO_TX " ); + break; + case RP_TASK_TYPE_CAD_TO_RX: + SMTC_MODEM_HAL_RP_TRACE_PRINTF( " TASK_CAD_TO_RX " ); + break; case RP_TASK_TYPE_NONE: case RP_TASK_TYPE_GNSS_SNIFF: case RP_TASK_TYPE_WIFI_SNIFF: diff --git a/smtc_modem_core/radio_planner/src/radio_planner.h b/smtc_modem_core/radio_planner/src/radio_planner.h index 72dd6b6..9864cae 100644 --- a/smtc_modem_core/radio_planner/src/radio_planner.h +++ b/smtc_modem_core/radio_planner/src/radio_planner.h @@ -95,6 +95,7 @@ typedef struct radio_planner_s void ( *hook_callbacks[RP_NB_HOOKS] )( void* ); rp_next_state_status_t next_state_status; const ralf_t* radio; + uint32_t margin_delay; } radio_planner_t; /* diff --git a/smtc_modem_core/radio_planner/src/radio_planner_hook_id_defs.h b/smtc_modem_core/radio_planner/src/radio_planner_hook_id_defs.h index 051408d..e38037d 100644 --- a/smtc_modem_core/radio_planner/src/radio_planner_hook_id_defs.h +++ b/smtc_modem_core/radio_planner/src/radio_planner_hook_id_defs.h @@ -58,18 +58,24 @@ extern "C" { #ifndef RP_HOOK_ID_REDEFINE enum RP_HOOK_ID_DEF { - RP_HOOK_ID_USER_SUSPEND = 0, - RP_HOOK_ID_USER_SUSPEND_0 = 1, - RP_HOOK_ID_SUSPEND = 2, - RP_HOOK_ID_LR1MAC_STACK = 3, - RP_HOOK_ID_LBT = 4, - RP_HOOK_ID_RTC_COMPENSATION = 5, - RP_HOOK_ID_CLASS_B_BEACON = 6, - RP_HOOK_ID_CLASS_B_D2D = 7, - RP_HOOK_ID_CLASS_B_PING_SLOT = 8, - RP_HOOK_ID_USER_SUSPEND_1 = 9, - RP_HOOK_ID_USER_SUSPEND_2 = 10, - RP_HOOK_ID_CLASS_C = 11, +#if !defined( LR1110_MODEM_E ) + RP_HOOK_ID_USER_SUSPEND = 0, + RP_HOOK_ID_USER_SUSPEND_0, +#endif // !LR1110_MODEM_E + RP_HOOK_ID_SUSPEND, + RP_HOOK_ID_LR1MAC_STACK, + RP_HOOK_ID_LBT, + RP_HOOK_ID_RTC_COMPENSATION, + RP_HOOK_ID_CLASS_B_BEACON, +#if defined( SMTC_D2D ) + RP_HOOK_ID_CLASS_B_D2D, +#endif // SMTC_D2D + RP_HOOK_ID_CLASS_B_PING_SLOT, + RP_HOOK_ID_USER_SUSPEND_1, +#if !defined( LR1110_MODEM_E ) + RP_HOOK_ID_USER_SUSPEND_2, +#endif // !LR1110_MODEM_E + RP_HOOK_ID_CLASS_C, RP_HOOK_ID_MAX }; #endif diff --git a/smtc_modem_core/radio_planner/src/radio_planner_types.h b/smtc_modem_core/radio_planner/src/radio_planner_types.h index edac40a..c0c55ae 100644 --- a/smtc_modem_core/radio_planner/src/radio_planner_types.h +++ b/smtc_modem_core/radio_planner/src/radio_planner_types.h @@ -83,9 +83,7 @@ extern "C" { #define RP_SOMETHING_TO_DO 1 /*! - * - * for 8 ms : 5MS FOR WAKE UP (2MS) + CONFIG TIMER (3MS FIX !) + 3 ms interrupt - * routine + * for 8 ms : 5MS FOR WAKE UP (2MS) + CONFIG TIMER (3MS FIX !) + 3 ms interrupt routine */ #ifndef RP_MARGIN_DELAY #define RP_MARGIN_DELAY 8 @@ -154,6 +152,8 @@ typedef enum rp_task_types_e RP_TASK_TYPE_TX_FSK, RP_TASK_TYPE_TX_LR_FHSS, RP_TASK_TYPE_CAD, + RP_TASK_TYPE_CAD_TO_TX, + RP_TASK_TYPE_CAD_TO_RX, RP_TASK_TYPE_GNSS_SNIFF, RP_TASK_TYPE_WIFI_SNIFF, RP_TASK_TYPE_GNSS_RSSI, @@ -236,7 +236,6 @@ typedef enum rp_hook_status_e * */ - #ifdef __cplusplus } #endif diff --git a/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.c b/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.c index 3896295..da97890 100644 --- a/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.c +++ b/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.c @@ -455,6 +455,46 @@ smtc_modem_crypto_return_code_t smtc_modem_crypto_get_class_b_rand( uint32_t bea return SMTC_MODEM_CRYPTO_RC_SUCCESS; } +smtc_modem_crypto_return_code_t smtc_modem_crypto_service_encrypt( const uint8_t* clear_buff, uint16_t len, + uint8_t nonce[14], uint8_t* enc_buff ) +{ + if( ( clear_buff == 0 ) || ( enc_buff == 0 ) ) + { + return SMTC_MODEM_CRYPTO_RC_ERROR_NPE; + } + + uint16_t index = 0; + uint16_t ctr = 1; + uint8_t s_block[16] = { 0 }; + uint8_t a_block[16] = { 0 }; + int16_t local_size = len; + + // first copy the 14 bytes of nonce into a_block first 14 bytes + memcpy( a_block, nonce, 14 ); + + while( local_size > 0 ) + { + a_block[15] = ctr & 0xFF; + a_block[14] = ( ctr >> 8 ) & 0xFF; + + ctr++; + + if( smtc_secure_element_aes_encrypt( a_block, 16, SMTC_SE_APP_S_KEY, s_block ) != SMTC_SE_RC_SUCCESS ) + { + return SMTC_MODEM_CRYPTO_RC_ERROR_SECURE_ELEMENT; + } + + for( uint8_t i = 0; i < ( ( local_size > 16 ) ? 16 : local_size ); i++ ) + { + enc_buff[index + i] = clear_buff[index + i] ^ s_block[i]; + } + local_size -= 16; + index += 16; + } + + return SMTC_MODEM_CRYPTO_RC_SUCCESS; +} + /* *----------------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DEFINITIONS ------------------------------------------------ diff --git a/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.h b/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.h index 30faf24..cf0b3e9 100644 --- a/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.h +++ b/smtc_modem_core/smtc_modem_crypto/smtc_modem_crypto.h @@ -250,6 +250,18 @@ smtc_modem_crypto_return_code_t smtc_modem_crypto_derive_multicast_session_keys( smtc_modem_crypto_return_code_t smtc_modem_crypto_get_class_b_rand( uint32_t beacon_epoch_time, uint32_t dev_addr, uint8_t rand[16] ); +/** + * @brief Encryption function for modem services (LFU and Stream) + * + * @param [in] clear_buff Clear buffer + * @param [in] len Buffer length + * @param [in] nonce Nonce to be used + * @param [out] enc_buff Encrypted buffer + * @return smtc_modem_crypto_return_code_t + */ +smtc_modem_crypto_return_code_t smtc_modem_crypto_service_encrypt( const uint8_t* clear_buff, uint16_t len, + uint8_t nonce[14], uint8_t* enc_buff ); + #ifdef __cplusplus } #endif diff --git a/smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c b/smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c index 716f32d..b5ec324 100644 --- a/smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c +++ b/smtc_modem_core/smtc_modem_services/src/file_upload/file_upload.c @@ -84,9 +84,9 @@ // Length of filedone frame #define FILE_UPLOAD_FILEDONE_FRAME_LENGTH ( 1 ) -// File upload maximum size - Can be modified to enlarge file upload max accepted size +// File upload maximum size #ifndef FILE_UPLOAD_MAX_SIZE -#define FILE_UPLOAD_MAX_SIZE ( 8 * 1024 ) +#define FILE_UPLOAD_MAX_SIZE ( ( 8 * 1024 ) - FILE_UPLOAD_HEADER_SIZE ) #endif // number of words per chunk @@ -132,10 +132,7 @@ file_upload_return_code_t file_upload_init( file_upload_t* file_upload, uint32_t { if( file_len > FILE_UPLOAD_MAX_SIZE ) { - LOG_ERROR( - "FileUpload is too large (%d > %d ) - Modify FILE_UPLOAD_MAX_SIZE to enlarge file upload buffer in case " - "you have enough ram \n", - file_len, FILE_UPLOAD_MAX_SIZE ); + LOG_ERROR( "FileUpload is too large (%d > %d )\n", file_len, FILE_UPLOAD_MAX_SIZE ); return FILE_UPLOAD_ERROR; } uint16_t sz_tmp = file_len + FILE_UPLOAD_HEADER_SIZE; diff --git a/smtc_modem_core/smtc_ral/src/ral_defs.h b/smtc_modem_core/smtc_ral/src/ral_defs.h index 29b5e2d..dbe70b7 100644 --- a/smtc_modem_core/smtc_ral/src/ral_defs.h +++ b/smtc_modem_core/smtc_ral/src/ral_defs.h @@ -242,17 +242,14 @@ enum ral_rx_status_gfsk_e }; /*! - * \brief GFSK Header Type configurations + * @brief GFSK Header Type configurations * - * This parameter indicates whether or not the payload length is sent and read - * over the air. + * This parameter indicates whether or not the payload length is sent and read over the air. * - * If the payload length is known beforehand by both transmitter and receiver, - * therefore there is no need to send it over the air. Otherwise, setting this - * parameter to LR1110_RADIO_GFSK_PKT_VAR_LEN will make the modem to - * automatically prepand a byte containing the payload length to the the payload - * on transmitter side. On receiver side, this first byte is read to set the - * payload length to read. + * If the payload length is known beforehand by both transmitter and receiver, therefore there is no need to send it + * over the air and the parameter can be set to RAL_GFSK_PKT_FIX_LEN. Otherwise, setting this parameter to + * RAL_GFSK_PKT_VAR_LEN will make the modem to automatically prepend a byte containing the payload length to the payload + * on transmitter side. On receiver side, this first byte is read to set the payload length to read. * * This configuration is only available for GFSK packet types. */ diff --git a/smtc_modem_core/smtc_ral/src/ral_lr11xx.c b/smtc_modem_core/smtc_ral/src/ral_lr11xx.c index f278a63..c9dce8c 100644 --- a/smtc_modem_core/smtc_ral/src/ral_lr11xx.c +++ b/smtc_modem_core/smtc_ral/src/ral_lr11xx.c @@ -62,8 +62,12 @@ #define LR11XX_HP_MIN_OUTPUT_POWER -9 #define LR11XX_HP_MAX_OUTPUT_POWER 22 +#define LR11XX_HF_MIN_OUTPUT_POWER -17 +#define LR11XX_HF_MAX_OUTPUT_POWER 13 + #define LR11XX_LP_CONVERT_TABLE_INDEX_OFFSET 17 #define LR11XX_HP_CONVERT_TABLE_INDEX_OFFSET 9 +#define LR11XX_HF_CONVERT_TABLE_INDEX_OFFSET 17 static const uint32_t ral_lr11xx_convert_tx_dbm_to_ua_reg_mode_dcdc_lp_vreg[] = { 10820, // -17 dBm @@ -207,6 +211,40 @@ static const uint32_t ral_lr11xx_convert_tx_dbm_to_ua_reg_mode_ldo_hp_vbat[] = { 116530, // 22 dBm }; +static const uint32_t ral_lr11xx_convert_tx_dbm_to_ua_reg_mode_dcdc_hf_vreg[] = { + 11800, // -17 dBm + 11800, // -16 dBm + 11900, // -15 dBm + 12020, // -14 dBm + 12120, // -13 dBm + 12230, // -12 dBm + 12390, // -11 dBm + 12540, // -10 dBm + 12740, // -9 dBm + 12960, // -8 dBm + 13150, // -7 dBm + 13460, // -6 dBm + 13770, // -5 dBm + 14070, // -4 dBm + 14460, // -3 dBm + 15030, // -2 dBm + 15440, // -1 dBm + 16030, // 0 dBm + 16980, // 1 dBm + 17590, // 2 dBm + 18270, // 3 dBm + 19060, // 4 dBm + 19900, // 5 dBm + 20740, // 6 dBm + 21610, // 7 dBm + 22400, // 8 dBm + 23370, // 9 dBm + 24860, // 10 dBm + 26410, // 11 dBm + 26430, // 12 dBm + 27890, // 13 dBm +}; + // TODO: check values #define LR11XX_GFSK_RX_CONSUMPTION_DCDC 5400 #define LR11XX_GFSK_RX_BOOSTED_CONSUMPTION_DCDC 7500 @@ -324,7 +362,7 @@ static void ral_lr11xx_convert_lr_fhss_params_from_ral( const ral_lr_fhss_params bool ral_lr11xx_handles_part( const char* part_number ) { - return strcmp( "lr11xx", part_number ) == 0; + return ( strcmp( "lr1110", part_number ) == 0 ) || ( strcmp( "lr1120", part_number ) == 0 ); } ral_status_t ral_lr11xx_reset( const void* context ) @@ -1093,6 +1131,39 @@ ral_status_t ral_lr11xx_get_tx_consumption_in_ua( const void* context, const int return RAL_STATUS_UNSUPPORTED_FEATURE; } } + else if( tx_cfg_output_params.pa_cfg.pa_sel == LR11XX_RADIO_PA_SEL_HF ) + { + if( tx_cfg_output_params.pa_cfg.pa_reg_supply == LR11XX_RADIO_PA_REG_SUPPLY_VREG ) + { + uint8_t index = 0; + + if( tx_cfg_output_params.chip_output_pwr_in_dbm_expected > LR11XX_HF_MAX_OUTPUT_POWER ) + { + index = LR11XX_HF_MAX_OUTPUT_POWER + LR11XX_HF_CONVERT_TABLE_INDEX_OFFSET; + } + else if( tx_cfg_output_params.chip_output_pwr_in_dbm_expected < LR11XX_HF_MIN_OUTPUT_POWER ) + { + index = LR11XX_HF_MIN_OUTPUT_POWER + LR11XX_HF_CONVERT_TABLE_INDEX_OFFSET; + } + else + { + index = tx_cfg_output_params.chip_output_pwr_in_dbm_expected + LR11XX_HF_CONVERT_TABLE_INDEX_OFFSET; + } + + if( radio_reg_mode == LR11XX_SYSTEM_REG_MODE_DCDC ) + { + *pwr_consumption_in_ua = ral_lr11xx_convert_tx_dbm_to_ua_reg_mode_dcdc_hf_vreg[index]; + } + else + { + return RAL_STATUS_UNSUPPORTED_FEATURE; + } + } + else + { + return RAL_STATUS_UNSUPPORTED_FEATURE; + } + } else { return RAL_STATUS_UNKNOWN_VALUE; @@ -1643,7 +1714,8 @@ static ral_status_t ral_lr11xx_convert_lora_cad_params_from_ral( const ral_lora_ } } - radio_lora_cad_params->cad_timeout = ral_lora_cad_params->cad_timeout_in_ms; + radio_lora_cad_params->cad_timeout = + lr11xx_radio_convert_time_in_ms_to_rtc_step( ral_lora_cad_params->cad_timeout_in_ms ); return RAL_STATUS_OK; } diff --git a/utilities/Makefile b/utilities/Makefile index 205cc39..e271aa6 100644 --- a/utilities/Makefile +++ b/utilities/Makefile @@ -14,19 +14,12 @@ APPBUILD_ROOT = build # Prefix for all binaries names APPTARGET_ROOT = app -BYPASS=no - -PERF_TEST=no - # CRYPTO Management CRYPTO ?= SOFT # Compile for debugging DEBUG ?= no -# Compile with coverage analysis support -COVERAGE ?= no - # Use multithreaded build (make -j) MULTITHREAD ?= yes @@ -57,7 +50,7 @@ USE_GNSS ?= yes # default action: print help #----------------------------------------------------------------------------- help: - $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 sx1261 sx1262") + $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 sx1261 sx1262 sx1268") $(call echo_help, "") $(call echo_help_b, "-------------------------------- Clean -------------------------------------") $(call echo_help, " * make clean_ : clean basic_modem app and lib for a given target") @@ -122,6 +115,10 @@ ifeq ($(RADIO),sx1262) -include makefiles/sx126x.mk endif +ifeq ($(RADIO),sx1268) +-include makefiles/sx126x.mk +endif + ifeq ($(RADIO),sx128x) -include makefiles/sx128x.mk endif @@ -129,7 +126,7 @@ endif #----------------------------------------------------------------------------- -include makefiles/common.mk -.PHONY: clean_all all help +.PHONY: clean_all all help .PHONY: FORCE FORCE: @@ -155,6 +152,10 @@ clean_sx1262: $(MAKE) -C $(LORA_BASICS_MODEM) clean_sx1262 $(MTHREAD_FLAG) $(MAKE) clean_target RADIO=sx1262 $(MTHREAD_FLAG) +clean_sx1268: + $(MAKE) -C $(LORA_BASICS_MODEM) clean_sx1268 $(MTHREAD_FLAG) + $(MAKE) clean_target RADIO=sx1268 $(MTHREAD_FLAG) + clean_sx128x: $(MAKE) -C $(LORA_BASICS_MODEM) clean_sx128x $(MTHREAD_FLAG) $(MAKE) clean_target RADIO=sx128x $(MTHREAD_FLAG) @@ -210,6 +211,17 @@ ifneq ($(DRIVE),nc) $(MAKE) flash RADIO=sx1262 endif +#-- SX1268 ------------------------------------------------------------------- +sx1268: + $(MAKE) example RADIO=sx1268 $(MTHREAD_FLAG) + +full_sx1268: + $(MAKE) clean_sx1268 + $(MAKE) sx1268 $(MTHREAD_FLAG) +ifneq ($(DRIVE),nc) + $(MAKE) flash RADIO=sx1268 +endif + #-- SX128x ------------------------------------------------------------------- sx128x: $(MAKE) example RADIO=sx128x $(MTHREAD_FLAG) diff --git a/utilities/makefiles/board_L476.mk b/utilities/makefiles/board_L476.mk index 7bf7803..be7aa00 100644 --- a/utilities/makefiles/board_L476.mk +++ b/utilities/makefiles/board_L476.mk @@ -6,7 +6,9 @@ #----------------------------------------------------------------------------- # Compilation flags #----------------------------------------------------------------------------- --include $(LORA_BASICS_MODEM)/makefiles/cortex_m4.mk + +#MCU compilation flags +MCU_FLAGS ?= -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard BOARD_C_DEFS = \ -DUSE_HAL_DRIVER \ diff --git a/utilities/makefiles/common.mk b/utilities/makefiles/common.mk index 47fded3..a9b6522 100644 --- a/utilities/makefiles/common.mk +++ b/utilities/makefiles/common.mk @@ -216,7 +216,7 @@ COMMON_C_DEFS += \ -DPERF_TEST_ENABLED endif -CFLAGS += -fno-builtin $(MCU) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)" +CFLAGS += -fno-builtin $(MCU_FLAGS) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)" CFLAGS += -falign-functions=4 CFLAGS += -std=c17 @@ -228,7 +228,7 @@ LIBS += -lstdc++ -lsupc++ -lm -lc -lnosys LIBDIR = -LDFLAGS += $(MCU) +LDFLAGS += $(MCU_FLAGS) LDFLAGS += --specs=nano.specs LDFLAGS += --specs=nosys.specs LDFLAGS += -T$(BOARD_LDSCRIPT) $(LIBDIR) $(LIBS) $(COVERAGE_LDFLAGS) @@ -303,7 +303,7 @@ vpath %.c $(sort $(dir $(C_SOURCES))) #----------------------------------------------------------------------------- example: ifeq ($(RADIO),nc) - $(call echo_error,"No radio selected! Please specified the target radio using RADIO=sx128x or RADIO=sx1261 or RADIO=sx1262 or RADIO=lr1110 or RADIO=lr1120") + $(call echo_error,"No radio selected! Please specified the target radio using RADIO=radio_name option") else $(MAKE) example_build endif @@ -352,7 +352,7 @@ endif .PHONY: $(BASIC_MODEM_LIB) $(BASIC_MODEM_LIB): - $(MAKE) -C $(LORA_BASICS_MODEM) basic_modem $(MTHREAD_FLAG) + $(MAKE) -C $(LORA_BASICS_MODEM) basic_modem MCU_FLAGS="$(MCU_FLAGS)" $(MTHREAD_FLAG) $(BUILD_DIR_MODEM)/$(TARGET_MODEM).elf: $(OBJECTS) Makefile $(BASIC_MODEM_LIB) $(call build,'CC',$@) @@ -447,7 +447,7 @@ endif sudo mount -t drvfs ${DRIVE}: /mnt/${DRIVE} cp $(BUILD_DIR_MODEM)/$(TARGET_MODEM).bin /mnt/${DRIVE}/ ; sudo umount /mnt/${DRIVE} else - $(call warn,"No radio selected! Please specified the target radio using RADIO=sx128x or RADIO=sx1261 or RADIO=sx1262 or RADIO=lr1110 or RADIO=lr1120") + $(call warn,"No radio selected! Please specified the target radio using RADIO=radio_name option") endif else $(call echo_error,"No Drive letter specified: please use compiling option: DRIVE=your_drive_letter") diff --git a/utilities/makefiles/lr11xx.mk b/utilities/makefiles/lr11xx.mk index ecda814..2e35ec5 100644 --- a/utilities/makefiles/lr11xx.mk +++ b/utilities/makefiles/lr11xx.mk @@ -19,8 +19,7 @@ endif RADIO_HAL_C_SOURCES += \ user_app/radio_hal/lr11xx_hal.c\ - user_app/radio_hal/ral_lr11xx_bsp.c\ - user_app/radio_hal/lr11xx_pa_pwr_cfg.c + user_app/radio_hal/ral_lr11xx_bsp.c #----------------------------------------------------------------------------- # Includes diff --git a/utilities/makefiles/sx126x.mk b/utilities/makefiles/sx126x.mk index c08632e..483f1fc 100644 --- a/utilities/makefiles/sx126x.mk +++ b/utilities/makefiles/sx126x.mk @@ -7,6 +7,9 @@ endif ifeq ($(RADIO),sx1262) TARGET = sx1262 endif +ifeq ($(RADIO),sx1268) +TARGET = sx1268 +endif #----------------------------------------------------------------------------- # Common sources @@ -38,3 +41,8 @@ ifeq ($(RADIO),sx1262) MODEM_C_DEFS += \ -DSX1262 endif + +ifeq ($(RADIO),sx1268) +MODEM_C_DEFS += \ + -DSX1268 +endif diff --git a/utilities/user_app/mcu_drivers/core/stm32l476rgtx_flash.ld b/utilities/user_app/mcu_drivers/core/stm32l476rgtx_flash.ld index 4d8c5d2..fb7466a 100644 --- a/utilities/user_app/mcu_drivers/core/stm32l476rgtx_flash.ld +++ b/utilities/user_app/mcu_drivers/core/stm32l476rgtx_flash.ld @@ -106,8 +106,8 @@ SECTIONS . = ALIGN(8); } >FLASH - .ARM.extab : - { + .ARM.extab : + { . = ALIGN(8); *(.ARM.extab* .gnu.linkonce.armextab.*) . = ALIGN(8); @@ -128,7 +128,7 @@ SECTIONS PROVIDE_HIDDEN (__preinit_array_end = .); . = ALIGN(8); } >FLASH - + .init_array : { . = ALIGN(8); @@ -152,7 +152,7 @@ SECTIONS _sidata = LOADADDR(.data); /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : + .data : { . = ALIGN(8); _sdata = .; /* create a global symbol at data start */ @@ -179,7 +179,7 @@ SECTIONS _egcov = . ; } >RAM */ - + /* Uninitialized data section */ . = ALIGN(4); .bss : @@ -224,13 +224,13 @@ SECTIONS .stack : { - . = ALIGN(8); - _estack = . ; - __stack_end__ = _estack; - . = . + _Min_Stack_Size; - . = ALIGN(8); - _sstack = . ; - __stack_start__ = _sstack; + . = ALIGN(8); + _sstack = .; + __stack_start__ = _sstack; + stack_size = _estack - ABSOLUTE(_sstack); + . = . + MAX(_Min_Stack_Size, stack_size); + . = ALIGN(8); + __stack_end__ = .; } >RAM2 /* User_heap_stack section, used to check that there is enough RAM left */ @@ -246,7 +246,7 @@ SECTIONS } >RAM */ - + /* Remove information from the standard libraries */ /DISCARD/ : diff --git a/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.c b/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.c deleted file mode 100644 index 6c0d874..0000000 --- a/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.c +++ /dev/null @@ -1,777 +0,0 @@ -/*! - * @file lr11xx_pa_pwr_cfg.c - * - * @brief lr11xx power amplifier configuration - * - * The Clear BSD License - * Copyright Semtech Corporation 2022. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Semtech corporation nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY - * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * ----------------------------------------------------------------------------- - * --- DEPENDENCIES ------------------------------------------------------------ - */ - -#include -#include "smtc_board_pa_pwr_cfg.h" - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE MACROS----------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE CONSTANTS ------------------------------------------------------- - */ - -#define LR1120MB1DXS_SUBGHZ_FREQ_MIN 150000000 -#define LR1120MB1DXS_SUBGHZ_FREQ_MAX 960000000 - -#define LR1120MB1DXS_2GHZ_FREQ_MIN 2000000000 -#define LR1120MB1DXS_2GHZ_FREQ_MAX 2100000000 - -#define LR1120MB1DXS_2_4GHZ_FREQ_MIN 2400000000 -#define LR1120MB1DXS_2_4GHZ_FREQ_MAX 2500000000 - -#define LR1120MB1DXS_MIN_PWR -17 -#define LR1120MB1DXS_MAX_PWR 22 - -#define LR1120MB1DXS_MIN_PWR_PA_HF -18 -#define LR1120MB1DXS_MAX_PWR_PA_HF 13 - -// PA config table -const smtc_board_pa_pwr_cfg_t pa_cfg_table[LR1120MB1DXS_MAX_PWR - LR1120MB1DXS_MIN_PWR + 1] = { - { // Expected output power = -17dBm - .power = -15, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -16dBm - .power = -14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -15dBm - .power = -13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -14dBm - .power = -12, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -13dBm - .power = -11, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -12dBm - .power = -9, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -11dBm - .power = -8, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -10dBm - .power = -7, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -9dBm - .power = -6, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -8dBm - .power = -5, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -7dBm - .power = -4, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -6dBm - .power = -3, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -5dBm - .power = -2, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -4dBm - .power = -1, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -3dBm - .power = 0, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -2dBm - .power = 1, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -1dBm - .power = 2, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 0dBm - .power = 3, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 1dBm - .power = 3, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x01, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 2dBm - .power = 4, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x01, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 3dBm - .power = 7, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 4dBm - .power = 8, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 5dBm - .power = 9, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 6dBm - .power = 10, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 7dBm - .power = 12, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 8dBm - .power = 13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 9dBm - .power = 14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 10dBm - .power = 13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x01, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 11dBm - .power = 13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x02, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 12dBm - .power = 14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x02, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 13dBm - .power = 14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x03, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 14dBm - .power = 14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 15dBm - .power = 14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_LP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x07, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 16dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x01, - .pa_hp_sel = 0x04, - }, - }, - { // Expected output power = 17dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x02, - .pa_hp_sel = 0x04, - }, - }, - { // Expected output power = 18dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x01, - .pa_hp_sel = 0x06, - }, - }, - { // Expected output power = 19dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x03, - .pa_hp_sel = 0x05, - }, - }, - { // Expected output power = 20dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x03, - .pa_hp_sel = 0x07, - }, - }, - { // Expected output power = 21dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x06, - }, - }, - { // Expected output power = 22dBm - .power = 22, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HP, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x07, - }, - }, -}; - -const smtc_board_pa_pwr_cfg_t pa_hf_cfg_table[LR1120MB1DXS_MAX_PWR_PA_HF - LR1120MB1DXS_MIN_PWR_PA_HF + 1] = { - { // Expected output power = -18dBm - .power = -18, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -17dBm - .power = -18, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -16dBm - .power = -17, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -15dBm - .power = -16, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -14dBm - .power = -15, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -13dBm - .power = -14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -12dBm - .power = -14, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -11dBm - .power = -12, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -10dBm - .power = -10, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -9dBm - .power = -9, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -8dBm - .power = -8, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -7dBm - .power = -7, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -6dBm - .power = -6, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -5dBm - .power = -5, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -4dBm - .power = -4, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -3dBm - .power = -3, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -2dBm - .power = -2, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x03, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = -1dBm - .power = -1, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 0dBm - .power = 0, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 1dBm - .power = 1, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 2dBm - .power = 2, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 3dBm - .power = 4, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 4dBm - .power = 5, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 5dBm - .power = 6, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 6dBm - .power = 7, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 7dBm - .power = 8, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 8dBm - .power = 9, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 9dBm - .power = 10, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 10dBm - .power = 11, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 11dBm - .power = 12, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x03, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 12dBm - .power = 13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x04, - .pa_hp_sel = 0x00, - }, - }, - { // Expected output power = 13dBm - .power = 13, - .pa_config = { - .pa_sel = LR11XX_RADIO_PA_SEL_HF, - .pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG, - .pa_duty_cycle = 0x00, - .pa_hp_sel = 0x00, - }, - }, -}; - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE TYPES ----------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE VARIABLES ------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC VARIABLES -------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- - */ -const smtc_board_pa_pwr_cfg_t* smtc_board_get_pa_pwr_cfg( const uint32_t rf_freq_in_hz, - int8_t expected_output_pwr_in_dbm ) -{ - if( ( LR1120MB1DXS_SUBGHZ_FREQ_MIN <= rf_freq_in_hz ) && ( rf_freq_in_hz <= LR1120MB1DXS_SUBGHZ_FREQ_MAX ) ) - { - if( ( LR1120MB1DXS_MIN_PWR <= expected_output_pwr_in_dbm ) && - ( expected_output_pwr_in_dbm <= LR1120MB1DXS_MAX_PWR ) ) - { - return &( pa_cfg_table[expected_output_pwr_in_dbm - LR1120MB1DXS_MIN_PWR] ); - } - } - else if( ( ( LR1120MB1DXS_2GHZ_FREQ_MIN <= rf_freq_in_hz ) && ( rf_freq_in_hz <= LR1120MB1DXS_2GHZ_FREQ_MAX ) ) || - ( ( LR1120MB1DXS_2_4GHZ_FREQ_MIN <= rf_freq_in_hz ) && - ( rf_freq_in_hz <= LR1120MB1DXS_2_4GHZ_FREQ_MAX ) ) ) - { - if( ( LR1120MB1DXS_MIN_PWR_PA_HF <= expected_output_pwr_in_dbm ) && - ( expected_output_pwr_in_dbm <= LR1120MB1DXS_MAX_PWR_PA_HF ) ) - { - return &( pa_hf_cfg_table[expected_output_pwr_in_dbm - LR1120MB1DXS_MIN_PWR_PA_HF] ); - } - } - - return NULL; -} - -/* - * ----------------------------------------------------------------------------- - * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- - */ - -/* --- EOF ------------------------------------------------------------------ */ diff --git a/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.h b/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.h new file mode 100644 index 0000000..66b1e2f --- /dev/null +++ b/utilities/user_app/radio_hal/lr11xx_pa_pwr_cfg.h @@ -0,0 +1,666 @@ +/*! + * @file lr11xx_pa_pwr_cfg.h + * + * @brief lr11xx power amplifier configuration. + * + * The Clear BSD License + * Copyright Semtech Corporation 2022. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted (subject to the limitations in the disclaimer + * below) provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Semtech corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY + * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LR11XX_PA_PWR_CFG_H +#define LR11XX_PA_PWR_CFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * ----------------------------------------------------------------------------- + * --- DEPENDENCIES ------------------------------------------------------------ + */ + +/* + * ----------------------------------------------------------------------------- + * --- PUBLIC MACROS ----------------------------------------------------------- + */ + +/* + * ----------------------------------------------------------------------------- + * --- PUBLIC CONSTANTS -------------------------------------------------------- + */ + +#define LR11XX_PA_LP_LF_CFG_TABLE \ + { \ + { \ + /* Expected output power = -17dBm */ \ + .power = -15, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -16dBm */ \ + .power = -14, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -15dBm */ \ + .power = -13, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -14dBm */ \ + .power = -12, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -13dBm */ \ + .power = -11, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -12dBm */ \ + .power = -9, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -11dBm */ \ + .power = -8, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -10dBm */ \ + .power = -7, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -9dBm */ \ + .power = -6, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -8dBm */ \ + .power = -5, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -7dBm */ \ + .power = -4, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -6dBm */ \ + .power = -3, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -5dBm */ \ + .power = -2, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -4dBm */ \ + .power = -1, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -3dBm */ \ + .power = 0, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -2dBm */ \ + .power = 1, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -1dBm */ \ + .power = 2, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 0dBm */ \ + .power = 3, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 1dBm */ \ + .power = 3, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 2dBm */ \ + .power = 4, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 3dBm */ \ + .power = 7, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 4dBm */ \ + .power = 8, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 5dBm */ \ + .power = 9, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 6dBm */ \ + .power = 10, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 7dBm */ \ + .power = 12, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 8dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 9dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 10dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 11dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 12dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 13dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 14dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 15dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x07, \ + .pa_hp_sel = 0x00, \ + }, \ + } + +#define LR11XX_PA_HP_LF_CFG_TABLE \ + { \ + { \ + /* Expected output power = -9dBm */ \ + .power = 9, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -8dBm */ \ + .power = 10, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -7dBm */ \ + .power = 11, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -6dBm */ \ + .power = 12, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -5dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -4dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -3dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -2dBm */ \ + .power = 17, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -1dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 0dBm */ \ + .power = 12, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 1dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 2dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 3dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 4dBm */ \ + .power = 15, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x02, \ + }, \ + { \ + /* Expected output power = 5dBm */ \ + .power = 15, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 6dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x02, \ + }, \ + { \ + /* Expected output power = 7dBm */ \ + .power = 14, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x03, \ + }, \ + { \ + /* Expected output power = 8dBm */ \ + .power = 17, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x02, \ + }, \ + { \ + /* Expected output power = 9dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 10dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 11dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 12dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x01, \ + }, \ + { \ + /* Expected output power = 13dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x03, \ + }, \ + { \ + /* Expected output power = 14dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x03, \ + }, \ + { \ + /* Expected output power = 15dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x02, \ + }, \ + { \ + /* Expected output power = 16dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x04, \ + }, \ + { \ + /* Expected output power = 17dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x02, \ + .pa_hp_sel = 0x04, \ + }, \ + { \ + /* Expected output power = 18dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x01, \ + .pa_hp_sel = 0x06, \ + }, \ + { \ + /* Expected output power = 19dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x05, \ + }, \ + { \ + /* Expected output power = 20dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x07, \ + }, \ + { \ + /* Expected output power = 21dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x06, \ + }, \ + { \ + /* Expected output power = 22dBm */ \ + .power = 22, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x07, \ + }, \ + } + +#define LR11XX_PA_HF_CFG_TABLE \ + { \ + { \ + /*Expected output power = -18dBm */ \ + .power = -18, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -17dBm */ \ + .power = -18, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -16dBm */ \ + .power = -17, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -15dBm */ \ + .power = -16, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -14dBm */ \ + .power = -15, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -13dBm */ \ + .power = -14, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -12dBm */ \ + .power = -14, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -11dBm */ \ + .power = -12, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -10dBm */ \ + .power = -10, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -9dBm */ \ + .power = -9, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -8dBm */ \ + .power = -8, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -7dBm */ \ + .power = -7, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -6dBm */ \ + .power = -6, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -5dBm */ \ + .power = -5, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -4dBm */ \ + .power = -4, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -3dBm */ \ + .power = -3, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -2dBm */ \ + .power = -2, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = -1dBm */ \ + .power = -1, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 0dBm */ \ + .power = 0, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 1dBm */ \ + .power = 1, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 2dBm */ \ + .power = 2, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 3dBm */ \ + .power = 4, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 4dBm */ \ + .power = 5, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 5dBm */ \ + .power = 6, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 6dBm */ \ + .power = 7, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 7dBm */ \ + .power = 8, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 8dBm */ \ + .power = 9, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 9dBm */ \ + .power = 10, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 10dBm */ \ + .power = 11, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 11dBm */ \ + .power = 12, \ + .pa_duty_cycle = 0x03, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 12dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x04, \ + .pa_hp_sel = 0x00, \ + }, \ + { \ + /* Expected output power = 13dBm */ \ + .power = 13, \ + .pa_duty_cycle = 0x00, \ + .pa_hp_sel = 0x00, \ + }, \ + } + +/* + * ----------------------------------------------------------------------------- + * --- PUBLIC TYPES ------------------------------------------------------------ + */ + +/* + * ----------------------------------------------------------------------------- + * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- + */ + +#ifdef __cplusplus +} +#endif + +#endif // LR11XX_PA_PWR_CFG_H + +/* --- EOF ------------------------------------------------------------------ */ diff --git a/utilities/user_app/radio_hal/ral_lr11xx_bsp.c b/utilities/user_app/radio_hal/ral_lr11xx_bsp.c index 7443711..85db761 100644 --- a/utilities/user_app/radio_hal/ral_lr11xx_bsp.c +++ b/utilities/user_app/radio_hal/ral_lr11xx_bsp.c @@ -41,7 +41,7 @@ #include // bool type #include "ral_lr11xx_bsp.h" -#include "smtc_board_pa_pwr_cfg.h" +#include "lr11xx_pa_pwr_cfg.h" #include "smtc_hal_mcu.h" #include "smtc_modem_api.h" @@ -52,14 +52,45 @@ /* * ----------------------------------------------------------------------------- - * --- PRIVATE CONSTANTS ------------------------------------------------------- + * --- PRIVATE TYPES ----------------------------------------------------------- */ +typedef enum lr11xx_pa_type_s +{ + LR11XX_WITH_LF_LP_PA, + LR11XX_WITH_LF_HP_PA, + LR11XX_WITH_LF_LP_HP_PA, + LR11XX_WITH_HF_PA, +} lr11xx_pa_type_t; + +typedef struct lr11xx_pa_pwr_cfg_s +{ + int8_t power; + uint8_t pa_duty_cycle; + uint8_t pa_hp_sel; +} lr11xx_pa_pwr_cfg_t; + /* * ----------------------------------------------------------------------------- - * --- PRIVATE TYPES ----------------------------------------------------------- + * --- PRIVATE CONSTANTS ------------------------------------------------------- */ +#define LR11XX_PWR_VREG_VBAT_SWITCH 8 + +#define LR11XX_MIN_PWR_LP_LF -17 +#define LR11XX_MAX_PWR_LP_LF 15 + +#define LR11XX_MIN_PWR_HP_LF -9 +#define LR11XX_MAX_PWR_HP_LF 22 + +#define LR11XX_MIN_PWR_PA_HF -18 +#define LR11XX_MAX_PWR_PA_HF 13 + +const lr11xx_pa_pwr_cfg_t pa_lp_cfg_table[LR11XX_MAX_PWR_LP_LF - LR11XX_MIN_PWR_LP_LF + 1] = LR11XX_PA_LP_LF_CFG_TABLE; +const lr11xx_pa_pwr_cfg_t pa_hp_cfg_table[LR11XX_MAX_PWR_HP_LF - LR11XX_MIN_PWR_HP_LF + 1] = LR11XX_PA_HP_LF_CFG_TABLE; + +const lr11xx_pa_pwr_cfg_t pa_hf_cfg_table[LR11XX_MAX_PWR_PA_HF - LR11XX_MIN_PWR_PA_HF + 1] = LR11XX_PA_HF_CFG_TABLE; + /* * ----------------------------------------------------------------------------- * --- PRIVATE VARIABLES ------------------------------------------------------- @@ -70,6 +101,16 @@ * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- */ +/** + * @brief Get the tx output param configuration given the type of power amplifier and expected output power + * + * @param [in] pa_type Power Amplifier type + * @param [in] expected_output_pwr_in_dbm TX output power in dBm + * @param [out] output_params The tx config output params + */ +void lr11xx_get_tx_cfg( lr11xx_pa_type_t pa_type, int8_t expected_output_pwr_in_dbm, + ral_lr11xx_bsp_tx_cfg_output_params_t* output_params ); + /* * ----------------------------------------------------------------------------- * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- @@ -103,54 +144,21 @@ void ral_lr11xx_bsp_get_tx_cfg( const void* context, const ral_lr11xx_bsp_tx_cfg int16_t power = input_params->system_output_pwr_in_dbm + modem_tx_offset; - // check frequency band first + lr11xx_pa_type_t pa_type; + + // check frequency band first to choose LF of HF PA if( input_params->freq_in_hz >= 2400000000 ) { - // Modem is acting in 2g4 band: use HF PA - // Check power boundaries for HF PA: The output power must be in range [ -18 , +13 ] dBm - if( power < -18 ) - { - power = -18; - } - else if( power > 13 ) - { - power = 13; - } + pa_type = LR11XX_WITH_HF_PA; } else { - // Modem is acting in subgig band: use LP/HP PA - // Check power boundaries for LP/HP PA: The output power must be in range [ -17 , +22 ] dBm - if( power < -17 ) - { - power = -17; - } - else if( power > 22 ) - { - power = 22; - } - } - // get the pa configuration given the frequency and expected output power - const smtc_board_pa_pwr_cfg_t* pa_pwr_cfg = smtc_board_get_pa_pwr_cfg( input_params->freq_in_hz, ( int8_t ) power ); - - if( pa_pwr_cfg == NULL ) - { - SMTC_HAL_TRACE_ERROR( "Invalid target frequency or power level\n" ); - while( true ) - { - } + // Modem is acting in subgig band: use LP/HP PA (both LP and HP are connected on lr11xx evk board) + pa_type = LR11XX_WITH_LF_LP_HP_PA; } - // Fill the output_params structure - output_params->pa_cfg.pa_duty_cycle = pa_pwr_cfg->pa_config.pa_duty_cycle; - output_params->pa_cfg.pa_hp_sel = pa_pwr_cfg->pa_config.pa_hp_sel; - output_params->pa_cfg.pa_reg_supply = pa_pwr_cfg->pa_config.pa_reg_supply; - output_params->pa_cfg.pa_sel = pa_pwr_cfg->pa_config.pa_sel; - - output_params->chip_output_pwr_in_dbm_configured = pa_pwr_cfg->power; - output_params->chip_output_pwr_in_dbm_expected = ( int8_t ) power; - - output_params->pa_ramp_time = LR11XX_RADIO_RAMP_48_US; + // call the configuration function + lr11xx_get_tx_cfg( pa_type, power, output_params ); } void ral_lr11xx_bsp_get_reg_mode( const void* context, lr11xx_system_reg_mode_t* reg_mode ) @@ -181,75 +189,185 @@ void ral_lr11xx_bsp_get_crc_state( const void* context, bool* crc_is_activated ) void ral_lr11xx_bsp_get_rssi_calibration_table( const void* context, const uint32_t freq_in_hz, lr11xx_radio_rssi_calibration_table_t* rssi_calibration_table ) { - // Workaround for lr11xx_driver v2.1.0 that contains a bug in command bytes management - // rssi_calibration_table structure members are not written in good order during spi transaction - // g4 gain value has to be put in g10, g5 in g11, g6 in g8, g7 in g9, g8 in g6, g9 in g7, g10 in g4, g11 in g5, g12 - // in g13hp5, g13 in g13hp6, g13hp1 in g13hp3, g13hp2 in g13hp4, g13hp3 in g13hp1, g13hp4 in g13hp2, g13hp5 in g12, - // g13hp6 in g13 - if( freq_in_hz <= 600000000 ) { rssi_calibration_table->gain_offset = 0; - rssi_calibration_table->gain_tune.g10 = 12; - rssi_calibration_table->gain_tune.g11 = 12; - rssi_calibration_table->gain_tune.g8 = 14; - rssi_calibration_table->gain_tune.g9 = 0; - rssi_calibration_table->gain_tune.g6 = 1; - rssi_calibration_table->gain_tune.g7 = 3; - rssi_calibration_table->gain_tune.g4 = 4; - rssi_calibration_table->gain_tune.g5 = 4; - rssi_calibration_table->gain_tune.g13hp5 = 3; - rssi_calibration_table->gain_tune.g13hp6 = 6; - rssi_calibration_table->gain_tune.g13hp3 = 6; - rssi_calibration_table->gain_tune.g13hp4 = 6; + rssi_calibration_table->gain_tune.g4 = 12; + rssi_calibration_table->gain_tune.g5 = 12; + rssi_calibration_table->gain_tune.g6 = 14; + rssi_calibration_table->gain_tune.g7 = 0; + rssi_calibration_table->gain_tune.g8 = 1; + rssi_calibration_table->gain_tune.g9 = 3; + rssi_calibration_table->gain_tune.g10 = 4; + rssi_calibration_table->gain_tune.g11 = 4; + rssi_calibration_table->gain_tune.g12 = 3; + rssi_calibration_table->gain_tune.g13 = 6; rssi_calibration_table->gain_tune.g13hp1 = 6; rssi_calibration_table->gain_tune.g13hp2 = 6; - rssi_calibration_table->gain_tune.g12 = 6; - rssi_calibration_table->gain_tune.g13 = 6; + rssi_calibration_table->gain_tune.g13hp3 = 6; + rssi_calibration_table->gain_tune.g13hp4 = 6; + rssi_calibration_table->gain_tune.g13hp5 = 6; + rssi_calibration_table->gain_tune.g13hp6 = 6; rssi_calibration_table->gain_tune.g13hp7 = 6; } else if( ( 600000000 <= freq_in_hz ) && ( freq_in_hz <= 2000000000 ) ) { rssi_calibration_table->gain_offset = 0; - rssi_calibration_table->gain_tune.g10 = 2; - rssi_calibration_table->gain_tune.g11 = 2; - rssi_calibration_table->gain_tune.g8 = 2; - rssi_calibration_table->gain_tune.g9 = 3; - rssi_calibration_table->gain_tune.g6 = 3; - rssi_calibration_table->gain_tune.g7 = 4; - rssi_calibration_table->gain_tune.g4 = 5; - rssi_calibration_table->gain_tune.g5 = 4; - rssi_calibration_table->gain_tune.g13hp5 = 4; - rssi_calibration_table->gain_tune.g13hp6 = 6; - rssi_calibration_table->gain_tune.g13hp3 = 5; - rssi_calibration_table->gain_tune.g13hp4 = 5; - rssi_calibration_table->gain_tune.g13hp1 = 6; - rssi_calibration_table->gain_tune.g13hp2 = 6; - rssi_calibration_table->gain_tune.g12 = 6; - rssi_calibration_table->gain_tune.g13 = 7; + rssi_calibration_table->gain_tune.g4 = 2; + rssi_calibration_table->gain_tune.g5 = 2; + rssi_calibration_table->gain_tune.g6 = 2; + rssi_calibration_table->gain_tune.g7 = 3; + rssi_calibration_table->gain_tune.g8 = 3; + rssi_calibration_table->gain_tune.g9 = 4; + rssi_calibration_table->gain_tune.g10 = 5; + rssi_calibration_table->gain_tune.g11 = 4; + rssi_calibration_table->gain_tune.g12 = 4; + rssi_calibration_table->gain_tune.g13 = 6; + rssi_calibration_table->gain_tune.g13hp1 = 5; + rssi_calibration_table->gain_tune.g13hp2 = 5; + rssi_calibration_table->gain_tune.g13hp3 = 6; + rssi_calibration_table->gain_tune.g13hp4 = 6; + rssi_calibration_table->gain_tune.g13hp5 = 6; + rssi_calibration_table->gain_tune.g13hp6 = 7; rssi_calibration_table->gain_tune.g13hp7 = 6; } else // freq_in_hz > 2000000000 { rssi_calibration_table->gain_offset = 2030; - rssi_calibration_table->gain_tune.g10 = 6; - rssi_calibration_table->gain_tune.g11 = 7; - rssi_calibration_table->gain_tune.g8 = 6; - rssi_calibration_table->gain_tune.g9 = 4; - rssi_calibration_table->gain_tune.g6 = 3; + rssi_calibration_table->gain_tune.g4 = 6; + rssi_calibration_table->gain_tune.g5 = 7; + rssi_calibration_table->gain_tune.g6 = 6; rssi_calibration_table->gain_tune.g7 = 4; - rssi_calibration_table->gain_tune.g4 = 14; - rssi_calibration_table->gain_tune.g5 = 12; - rssi_calibration_table->gain_tune.g13hp5 = 14; - rssi_calibration_table->gain_tune.g13hp6 = 12; - rssi_calibration_table->gain_tune.g13hp3 = 12; - rssi_calibration_table->gain_tune.g13hp4 = 12; + rssi_calibration_table->gain_tune.g8 = 3; + rssi_calibration_table->gain_tune.g9 = 4; + rssi_calibration_table->gain_tune.g10 = 14; + rssi_calibration_table->gain_tune.g11 = 12; + rssi_calibration_table->gain_tune.g12 = 14; + rssi_calibration_table->gain_tune.g13 = 12; rssi_calibration_table->gain_tune.g13hp1 = 12; - rssi_calibration_table->gain_tune.g13hp2 = 8; - rssi_calibration_table->gain_tune.g12 = 8; - rssi_calibration_table->gain_tune.g13 = 9; + rssi_calibration_table->gain_tune.g13hp2 = 12; + rssi_calibration_table->gain_tune.g13hp3 = 12; + rssi_calibration_table->gain_tune.g13hp4 = 8; + rssi_calibration_table->gain_tune.g13hp5 = 8; + rssi_calibration_table->gain_tune.g13hp6 = 9; rssi_calibration_table->gain_tune.g13hp7 = 9; } } +/* + * ----------------------------------------------------------------------------- + * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- + */ + +void lr11xx_get_tx_cfg( lr11xx_pa_type_t pa_type, int8_t expected_output_pwr_in_dbm, + ral_lr11xx_bsp_tx_cfg_output_params_t* output_params ) +{ + int8_t power = expected_output_pwr_in_dbm; + + // Ramp time is the same for any config + output_params->pa_ramp_time = LR11XX_RADIO_RAMP_48_US; + + switch( pa_type ) + { + case LR11XX_WITH_LF_LP_PA: + { + // Check power boundaries for LP LF PA: The output power must be in range [ -17 , +15 ] dBm + if( power < LR11XX_MIN_PWR_LP_LF ) + { + power = LR11XX_MIN_PWR_LP_LF; + } + else if( power > LR11XX_MAX_PWR_LP_LF ) + { + power = LR11XX_MAX_PWR_LP_LF; + } + output_params->pa_cfg.pa_sel = LR11XX_RADIO_PA_SEL_LP; + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG; + output_params->pa_cfg.pa_duty_cycle = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].pa_duty_cycle; + output_params->pa_cfg.pa_hp_sel = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].pa_hp_sel; + output_params->chip_output_pwr_in_dbm_configured = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].power; + output_params->chip_output_pwr_in_dbm_expected = power; + break; + } + case LR11XX_WITH_LF_HP_PA: + { + // Check power boundaries for HP LF PA: The output power must be in range [ -9 , +22 ] dBm + if( power < LR11XX_MIN_PWR_HP_LF ) + { + power = LR11XX_MIN_PWR_HP_LF; + } + else if( power > LR11XX_MAX_PWR_HP_LF ) + { + power = LR11XX_MAX_PWR_HP_LF; + } + output_params->pa_cfg.pa_sel = LR11XX_RADIO_PA_SEL_HP; + output_params->chip_output_pwr_in_dbm_expected = power; + + if( power <= LR11XX_PWR_VREG_VBAT_SWITCH ) + { + // For powers below 8dBm use regulated supply for HP PA for a better efficiency. + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG; + } + else + { + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT; + } + + output_params->pa_cfg.pa_duty_cycle = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].pa_duty_cycle; + output_params->pa_cfg.pa_hp_sel = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].pa_hp_sel; + output_params->chip_output_pwr_in_dbm_configured = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].power; + break; + } + case LR11XX_WITH_LF_LP_HP_PA: + { + // Check power boundaries for LP/HP LF PA: The output power must be in range [ -17 , +22 ] dBm + if( power < LR11XX_MIN_PWR_LP_LF ) + { + power = LR11XX_MIN_PWR_LP_LF; + } + else if( power > LR11XX_MAX_PWR_HP_LF ) + { + power = LR11XX_MAX_PWR_HP_LF; + } + output_params->chip_output_pwr_in_dbm_expected = power; + + if( power <= LR11XX_MAX_PWR_LP_LF ) + { + output_params->pa_cfg.pa_sel = LR11XX_RADIO_PA_SEL_LP; + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG; + output_params->pa_cfg.pa_duty_cycle = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].pa_duty_cycle; + output_params->pa_cfg.pa_hp_sel = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].pa_hp_sel; + output_params->chip_output_pwr_in_dbm_configured = pa_lp_cfg_table[power - LR11XX_MIN_PWR_LP_LF].power; + } + else + { + output_params->pa_cfg.pa_sel = LR11XX_RADIO_PA_SEL_HP; + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VBAT; + output_params->pa_cfg.pa_duty_cycle = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].pa_duty_cycle; + output_params->pa_cfg.pa_hp_sel = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].pa_hp_sel; + output_params->chip_output_pwr_in_dbm_configured = pa_hp_cfg_table[power - LR11XX_MIN_PWR_HP_LF].power; + } + break; + } + case LR11XX_WITH_HF_PA: + { + // Check power boundaries for HF PA: The output power must be in range [ -18 , +13 ] dBm + if( power < LR11XX_MIN_PWR_PA_HF ) + { + power = LR11XX_MIN_PWR_PA_HF; + } + else if( power > LR11XX_MAX_PWR_PA_HF ) + { + power = LR11XX_MAX_PWR_PA_HF; + } + output_params->pa_cfg.pa_sel = LR11XX_RADIO_PA_SEL_HF; + output_params->pa_cfg.pa_reg_supply = LR11XX_RADIO_PA_REG_SUPPLY_VREG; + output_params->pa_cfg.pa_duty_cycle = pa_hf_cfg_table[power - LR11XX_MIN_PWR_PA_HF].pa_duty_cycle; + output_params->pa_cfg.pa_hp_sel = pa_hf_cfg_table[power - LR11XX_MIN_PWR_PA_HF].pa_hp_sel; + output_params->chip_output_pwr_in_dbm_configured = pa_hf_cfg_table[power - LR11XX_MIN_PWR_PA_HF].power; + output_params->chip_output_pwr_in_dbm_expected = power; + break; + } + } +} + /* --- EOF ------------------------------------------------------------------ */ diff --git a/utilities/user_app/radio_hal/ral_sx126x_bsp.c b/utilities/user_app/radio_hal/ral_sx126x_bsp.c index be98c4c..907fa3f 100644 --- a/utilities/user_app/radio_hal/ral_sx126x_bsp.c +++ b/utilities/user_app/radio_hal/ral_sx126x_bsp.c @@ -99,9 +99,9 @@ void ral_sx126x_bsp_get_tx_cfg( const void* context, const ral_sx126x_bsp_tx_cfg int16_t power = input_params->system_output_pwr_in_dbm + modem_tx_offset; output_params->pa_ramp_time = SX126X_RAMP_40_US; - output_params->pa_cfg.pa_lut = 0x01; // reserved value, same for sx1261 and sx1262 + output_params->pa_cfg.pa_lut = 0x01; // reserved value, same for sx1261 sx1262 and sx1268 -#if defined( SX1262 ) +#if defined( SX1262 ) || defined( SX1268 ) // Clamp power if needed if( power > 22 ) @@ -112,23 +112,11 @@ void ral_sx126x_bsp_get_tx_cfg( const void* context, const ral_sx126x_bsp_tx_cfg { power = -9; } - if( power == 22 ) - { - output_params->pa_cfg.device_sel = 0x00; // select SX1262 device - output_params->pa_cfg.hp_max = 0x07; // to achieve 22dBm - output_params->pa_cfg.pa_duty_cycle = 0x04; - output_params->chip_output_pwr_in_dbm_configured = 22; - output_params->chip_output_pwr_in_dbm_expected = 22; - } - else - { - output_params->pa_cfg.device_sel = 0x00; // select SX1262 device - output_params->pa_cfg.hp_max = 0x07; // to achieve 22dBm - output_params->pa_cfg.pa_duty_cycle = 0x04; - output_params->chip_output_pwr_in_dbm_configured = ( int8_t ) power; - output_params->chip_output_pwr_in_dbm_expected = ( int8_t ) power; - } - + output_params->pa_cfg.device_sel = 0x00; // select SX1262/SX1268 device + output_params->pa_cfg.hp_max = 0x07; // to achieve 22dBm + output_params->pa_cfg.pa_duty_cycle = 0x04; + output_params->chip_output_pwr_in_dbm_configured = ( int8_t ) power; + output_params->chip_output_pwr_in_dbm_expected = ( int8_t ) power; #else // Clamp power if needed if( power > 15 ) @@ -172,7 +160,7 @@ void ral_sx126x_bsp_get_tx_cfg( const void* context, const ral_sx126x_bsp_tx_cfg void ral_sx126x_bsp_get_xosc_cfg( const void* context, bool* tcxo_is_radio_controlled, sx126x_tcxo_ctrl_voltages_t* supply_voltage, uint32_t* startup_time_in_tick ) { - // No tcxo on Basic Modem sx1261 and sx1262 reference boards + // No tcxo on Basic Modem sx1261,sx1262 or sx1268 reference boards *tcxo_is_radio_controlled = false; } diff --git a/utilities/user_app/radio_hal/smtc_board_pa_pwr_cfg.h b/utilities/user_app/radio_hal/smtc_board_pa_pwr_cfg.h deleted file mode 100644 index 9d7da0e..0000000 --- a/utilities/user_app/radio_hal/smtc_board_pa_pwr_cfg.h +++ /dev/null @@ -1,97 +0,0 @@ -/*! - * @file smtc_board_pa_pwr_cfg.h - * - * @brief lr11xx power amplifier configuration. - * - * The Clear BSD License - * Copyright Semtech Corporation 2022. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the disclaimer - * below) provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Semtech corporation nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY - * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SMTC_BOARD_PA_PWR_CFG_H -#define SMTC_BOARD_PA_PWR_CFG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * ----------------------------------------------------------------------------- - * --- DEPENDENCIES ------------------------------------------------------------ - */ - -#include "smtc_hal_trace.h" - -#include // C99 types -#include // bool type -#include "lr11xx_radio_types.h" -#include "lr11xx_system_types.h" - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC MACROS ----------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC CONSTANTS -------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC TYPES ------------------------------------------------------------ - */ - -typedef struct smtc_board_pa_pwr_cfg_s -{ - int8_t power; - lr11xx_radio_pa_cfg_t pa_config; -} smtc_board_pa_pwr_cfg_t; - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- - */ - -/*! - * @brief Get the power amplifier configuration given a RF frequency and output power - * - * @param [in] rf_freq_in_hz RF frequence in Hz - * @param [in] expected_output_pwr_in_dbm TX output power in dBm - * - * @returns Pointer to a structure holding the expected configuration. - * Can be NULL if no configuration found for given arguments. - */ -const smtc_board_pa_pwr_cfg_t* smtc_board_get_pa_pwr_cfg( uint32_t rf_freq_in_hz, - int8_t expected_output_pwr_in_dbm ); - -#ifdef __cplusplus -} -#endif - -#endif // SMTC_BOARD_PA_PWR_CFG_H - -/* --- EOF ------------------------------------------------------------------ */ diff --git a/utilities/user_app/smtc_hal_l4/smtc_hal_dbg_trace.h b/utilities/user_app/smtc_hal_l4/smtc_hal_dbg_trace.h index 19e304c..f2b42ed 100644 --- a/utilities/user_app/smtc_hal_l4/smtc_hal_dbg_trace.h +++ b/utilities/user_app/smtc_hal_l4/smtc_hal_dbg_trace.h @@ -97,7 +97,7 @@ extern "C" { #define HAL_DBG_TRACE_COLOR_DEFAULT "" #endif -#if ( HAL_DBG_TRACE ) && !defined (PERF_TEST_ENABLED) +#if ( HAL_DBG_TRACE ) #define SMTC_HAL_TRACE_PRINTF( ... ) hal_trace_print_var ( __VA_ARGS__ ) diff --git a/utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c b/utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c index 991c9af..1c06767 100644 --- a/utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c +++ b/utilities/user_app/smtc_hal_l4/smtc_hal_rtc.c @@ -160,12 +160,12 @@ static uint32_t rtc_set_time_ref_in_ticks( void ); static uint32_t rtc_ms_2_wakeup_timer_tick( const uint32_t milliseconds ); /*! - * Converts time in ticks to time in ms + * Converts time in ticks to time in 100 us * * \param[IN] ticks Time in timer ticks - * \retval milliseconds Time in milliseconds + * \retval milliseconds Time in 100 us */ -static uint32_t rtc_tick_2_ms( const uint32_t tick ); +static uint32_t rtc_tick_2_100us( const uint32_t tick ); /*! * Get the elapsed time in seconds and milliseconds since RTC initialization @@ -239,8 +239,8 @@ uint32_t hal_rtc_get_time_s( void ) uint32_t hal_rtc_get_time_100us( void ) { - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; + uint32_t seconds = 0; + uint16_t milliseconds_div_10 = 0; seconds = rtc_get_calendar_time( &milliseconds_div_10 ); @@ -248,7 +248,12 @@ uint32_t hal_rtc_get_time_100us( void ) } uint32_t hal_rtc_get_time_ms( void ) { - return (hal_rtc_get_time_100us( ) / 10); + uint32_t seconds = 0; + uint16_t milliseconds_div_10 = 0; + + seconds = rtc_get_calendar_time( &milliseconds_div_10 ); + + return seconds * 1000 + ( milliseconds_div_10 / 10 ); } void hal_rtc_wakeup_timer_set_ms( const int32_t milliseconds ) @@ -283,12 +288,12 @@ static uint32_t rtc_set_time_ref_in_ticks( void ) return bsp_rtc.context.time_ref_in_ticks; } -static uint32_t rtc_tick_2_ms( const uint32_t tick ) +static uint32_t rtc_tick_2_100us( const uint32_t tick ) { uint32_t seconds = tick >> N_PREDIV_S; uint32_t local_tick = tick & PREDIV_S; - return ( uint32_t ) ( ( seconds * 1000 ) + ( ( local_tick * 10000 ) >> N_PREDIV_S ) ); + return ( uint32_t )( ( seconds * 10000 ) + ( ( local_tick * 10000 ) >> N_PREDIV_S ) ); } static uint32_t rtc_ms_2_wakeup_timer_tick( const uint32_t milliseconds ) @@ -308,11 +313,11 @@ static uint32_t rtc_get_calendar_time( uint16_t* milliseconds_div_10 ) uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( &date, &time ); - uint32_t seconds = ( uint32_t ) ( timestamp_in_ticks >> N_PREDIV_S ); + uint32_t seconds = ( uint32_t )( timestamp_in_ticks >> N_PREDIV_S ); ticks = ( uint32_t ) timestamp_in_ticks & PREDIV_S; - *milliseconds_div_10 = rtc_tick_2_ms( ticks ); + *milliseconds_div_10 = rtc_tick_2_100us( ticks ); return seconds; }