diff --git a/CHANGELOG.md b/CHANGELOG.md index a717934..82590ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,26 @@ 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). +## [UNRELEASED] - UNRELEASED + +### Changed + +- [service] Printing of certification mode enabling status is changed so that the print is more visible when enabled. The enabling status is always reported. + +## [v4.3.1] 2024-03-12 + +This version fix the 4.3.0 version. + +- LR-FHSS datarate decay certification test failing +- LR-FHSS hop_sequence_id must in range [0:nb_max_hop_sequence-1] to avoid buffer overflow +- FUOTA MPA (Multiple Package Access) multicast session not started when RMS commands are received through MPA package +- FUOTA MPA (Multiple Package Access) package answering to MultiPackBufferReq plus other packages commands in same downlink when it should not +- FUOTA MPA (Multiple Package Access) Coverity Overrun fix +- LBM Application with nRF52840 target, the RTC wrapping reset the device +- LBM Application with nFR52840 target, fix SPI HAL for radio sx126x and sx128x +- Class B resets when counter "smtc_modem_hal_get_time_in_100us" wraps (occurs after 4.9 days), this time base is no more used +- cloud DM DM_INFO_RXTIME payload do not report the correct duration since last received downlink + ## [v4.3.0] 2023-12-13 This version is based on feature branch v4.1.0 of the LoRa Basics Modem. @@ -13,46 +33,46 @@ Detailed Modem HAL changelog can be found [here](lbm_lib/smtc_modem_hal/CHANGELO ### Added -* [radio] Re-add support of lr1121 radio -* [service] Add Geolocation services and associated makefile option -* [service] Add a Store and Forward service and associated makefile option -* [service] Re-added the following optional LBM services: - * Device Management (DM) service and associated makefile option (related with LoRaCloud) - * Large File Upload (LFU) service and associated makefile option (related with LoRaCloud) - * Stream service and associated makefile option (related with LoRaCloud) - * Almanac Update service and associated makefile option (related with LoRaCloud) -* [general] Add a new folder `lbm_applications` that contains 3 specific implementation references on sereval MCU -* [general] Real Time OS compatibility (add hal function `smtc_modem_hal_user_lbm_irq`) -* [lr11xx-crypto] Re-add suspend/resume guard for lr11xx crypto access -* [makefile] Add `DEBUG_OPT` option to choose optimization in caseof DEBUG +- Re-add support of lr1121 radio + +- [Service] Add Geolocation services and associated makefile option +- [Service] Add a Store and Forward service and associated makefile option +- [Service] Re-Add Device Management (DM) service and associated makefile option(related with LoRaCloud) +- [Service] Re-Add Large File Upload (LFU) service and associated makefile option(related with LoRaCloud) +- [Service] Re-Add Stream service and associated makefile option(related with LoRaCloud) +- [Service] Re-Add Almanac Update service and associated makefile option(related with LoRaCloud) +- [general] Add a new folder `lbm_applications` that contains 3 specific implementation references on sereval MCU +- [general] Real Time OS compatibility (add hal function `smtc_modem_hal_user_lbm_irq`) +- [lr11xx-crypto] Re-add suspend/resume guard for lr11xx crypto access +- [makefile] Add `DEBUG_OPT` option to choose optimization in caseof DEBUG ### Fixed -* Issue [#12](https://github.com/Lora-net/SWL2001/issues/12): Correct ral_xxx_lr_fhss_get_hop_sequence_count prototype to return a ral_status_t and not the count -* Issue [#13](https://github.com/Lora-net/SWL2001/issues/13): Correct Firmware Management Protocol behavior issue -* Issue [#14](https://github.com/Lora-net/SWL2001/issues/14): Correct LoRaWAN packages parser missing default case in parser (Remote Multicast Setup V1 and V2, Firmware Management Protocol and Fragmented Data Block Transport V1 and V2 ) -* Issue [#19](https://github.com/Lora-net/SWL2001/issues/19): check all LoRaWAN packages answer overflows -* Issue [#20](https://github.com/Lora-net/SWL2001/issues/20): Index of the answer for McGroupStatusReq command is not fixed anymore -* Issue [#22](https://github.com/Lora-net/SWL2001/issues/22): In Remote Multicast Setup Package V1 and V2, check `lorawan_api_is_frequency_valid` and `lorawan_api_is_datarate_valid` return status according to `status_lorawan_t` enum and not boolean +- Issue [#12](https://github.com/Lora-net/SWL2001/issues/12): Correct ral_xxx_lr_fhss_get_hop_sequence_count prototype to return a ral_status_t and not the count +- Issue [#13](https://github.com/Lora-net/SWL2001/issues/13): Correct Firmware Management Protocol behavior issue +- Issue [#14](https://github.com/Lora-net/SWL2001/issues/14): Correct LoRaWAN packages parser missing default case in parser (Remote Multicast Setup V1 and V2, Firmware Management Protocol and Fragmented Data Block Transport V1 and V2 ) +- Issue [#19](https://github.com/Lora-net/SWL2001/issues/19): check all LoRaWAN packages answer overflows +- Issue [#20](https://github.com/Lora-net/SWL2001/issues/20): Index of the answer for McGroupStatusReq command is not fixed anymore +- Issue [#22](https://github.com/Lora-net/SWL2001/issues/22): In Remote Multicast Setup Package V1 and V2, check `lorawan_api_is_frequency_valid` and `lorawan_api_is_datarate_valid` return status according to `status_lorawan_t` enum and not boolean -* [LoRaWAN-context] In case there is no valid stack context in nvm, initialize Join Nonce to -1 so that it can accept first join accept with join nonce equal to 0 -* [LoRaWAN] Add api to configure Gen App Key (used for Remote Multicast Setup package) and do not use by default the App key +- [LoRaWAN-context] In case there is no valid stack context in nvm, initialize Join Nonce to -1 so that it can accept first join accept with join nonce equal to 0 +- [LoRaWAN] Add api to configure Gen App Key (used for Remote Multicast Setup package) and do not use by default the App key *[lorawan-package] Fix several issues encountered while executing the LoRa Alliance certification on FUOTA V2 related packages -* [modem-test] Fix issue that lead to modem panic in case a cw test is launched for too long -* [Duty-cycle] Fix issue where the duty-cycle was not fully disable when a region without duty-cycle constraint was initialized +- [modem-test] Fix issue that lead to modem panic in case a cw test is launched for too long +- [Duty-cycle] Fix issue where the duty-cycle was not fully disable when a region without duty-cycle constraint was initialized ### Changed -* [general] Change repository organization to ease readability. +- [general] Change repository organization to ease readability. Put all LoRa Basics Modem libraray related code in `lbm_lib` folder. Rename `utilities` folder into `lbm_examples` for generic Lora Basics Modem examples -* [lorawan-package] Change `lorawan_packages` folder organization to use a dedicated folder for each packages instead of fuota_v1 and fuota_V2 +- [lorawan-package] Change `lorawan_packages` folder organization to use a dedicated folder for each packages instead of fuota_v1 and fuota_V2 -* [lr11xx-driver] Update lr11xx radio driver to v2.4.0 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md)) -* [sx126x-driver] Update sx126x radio driver to v3.2.1 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md)) -* [sx128x-driver] Update sx128x radio driver to v1.0.0 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/sx128x_driver/CHANGELOG.md)) -* [makefile] Set all LBM features options to `no` by default -* [certification-service] Update certification service to support FUOTA certification +- [lr11xx-driver] Update lr11xx radio driver to v2.4.0 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md)) +- [sx126x-driver] Update sx126x radio driver to v3.2.1 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md)) +- [sx128x-driver] Update sx128x radio driver to v1.0.0 version ([CHANGELOG.md](lbm_lib/smtc_modem_core/radio_drivers/sx128x_driver/CHANGELOG.md)) +- [makefile] Set all LBM features options to `no` by default +- [certification-service] Update certification service to support FUOTA certification ## [v4.1.0] 2023-07-27 @@ -63,41 +83,41 @@ Detailed Modem HAL changelog can be found [here](smtc_modem_hal/CHANGELOG.md) ### Added -* [lorawan-stack] Add CSMA feature support, corresponding api functions and hw modem commands -* [lorawan-package] Add support of Firmware Management Protocol package that follows LoRaWAN® Specification TS006-1.0.0 -* [lorawan-package] Add support of Multi-Package Access Protocol package that follows LoRaWAN® Specification TS007-1.0.0 -* [lorawan-package] Add support of Remote Multicast Setup package that follows LoRaWAN® Specification TS005-2.0.0 -* [lorawan-package] Add support of Application Layer Clock Synchronization that follows LoRaWAN® Specification TS003-2.0.0 -* [lorawan-package] Add support of Fragmented Data Block Transport that follows LoRaWAN® Specification TS004-2.0.0 -* [radio] Add support for sx1272 and sx1276 radios for experimental use only -* [lbm makefile] Add RADIO in options.mk to choose which LoRaWAN regions should be built. -* [lbm makefile] Add missing options in `make help` output -* [utilities] Add an makefile option in `app_options.mk` `LBM_BUILD_OPTIONS` to allow updating any LBM lib build options -* [ral_lr11xx_bsp] Add lr11xx new bsp functions `ral_lr11xx_bsp_get_lora_cad_det_peak` and `ral_lr11xx_bsp_get_rx_boost_cfg` -* [ral_sx126x_bsp] Add sx126x new bsp functions `ral_sx126x_bsp_get_lora_cad_det_peak`, `ral_sx126x_bsp_get_rx_boost_cfg` and `ral_sx126x_bsp_get_trim_cap` -* [ral_sx128x_bsp] Add sx128x new bsp function `ral_sx128x_bsp_get_lora_cad_det_peak` +- [lorawan-stack] Add CSMA feature support, corresponding api functions and hw modem commands +- [lorawan-package] Add support of Firmware Management Protocol package that follows LoRaWAN® Specification TS006-1.0.0 +- [lorawan-package] Add support of Multi-Package Access Protocol package that follows LoRaWAN® Specification TS007-1.0.0 +- [lorawan-package] Add support of Remote Multicast Setup package that follows LoRaWAN® Specification TS005-2.0.0 +- [lorawan-package] Add support of Application Layer Clock Synchronization that follows LoRaWAN® Specification TS003-2.0.0 +- [lorawan-package] Add support of Fragmented Data Block Transport that follows LoRaWAN® Specification TS004-2.0.0 +- [radio] Add support for sx1272 and sx1276 radios for experimental use only +- [lbm makefile] Add RADIO in options.mk to choose which LoRaWAN regions should be built. +- [lbm makefile] Add missing options in `make help` output +- [utilities] Add an makefile option in `app_options.mk` `LBM_BUILD_OPTIONS` to allow updating any LBM lib build options +- [ral_lr11xx_bsp] Add lr11xx new bsp functions `ral_lr11xx_bsp_get_lora_cad_det_peak` and `ral_lr11xx_bsp_get_rx_boost_cfg` +- [ral_sx126x_bsp] Add sx126x new bsp functions `ral_sx126x_bsp_get_lora_cad_det_peak`, `ral_sx126x_bsp_get_rx_boost_cfg` and `ral_sx126x_bsp_get_trim_cap` +- [ral_sx128x_bsp] Add sx128x new bsp function `ral_sx128x_bsp_get_lora_cad_det_peak` ### Fixed -* [AU915/US915] Fix LoRaWAN Link Adr Request channel mask control case 5 missing impact of 500MHz bank -* [class b multicast] Avoid opening multicast ping slots when the session is stopped -* [LRFHSS] Correct tx done timestamp with known bit padding delay to avoid issue with following rx windows (principally seen on US and AU regions) -* [porting tool] Correct porting tool test test_get_time_in_ms to avoid mis-alignment in radio symbol timeout -* [exti example] In `modem_event_callback`, use stack_id value given by `smtc_modem_get_event` instead of fixed defined one -* [ALCSync] Fix ALCsync periodic request timing issue +- [AU915/US915] Fix LoRaWAN Link Adr Request channel mask control case 5 missing impact of 500MHz bank +- [class b multicast] Avoid opening multicast ping slots when the session is stopped +- [LRFHSS] Correct tx done timestamp with known bit padding delay to avoid issue with following rx windows (principally seen on US and AU regions) +- [porting tool] Correct porting tool test test_get_time_in_ms to avoid mis-alignment in radio symbol timeout +- [exti example] In `modem_event_callback`, use stack_id value given by `smtc_modem_get_event` instead of fixed defined one +- [ALCSync] Fix ALCsync periodic request timing issue ### Changed -* [lr11xx-driver] Update lr11xx radio driver to v2.3.0 version -* [sx126x-driver] Update sx126x radio driver to v2.2.0 version -* [radio-ral] Update ral to get cad specific features -* [Return codes] `smtc_modem_get_pin` and `smtc_modem_derive_keys` now return `SMTC_MODEM_RC_BUSY` in case modem is joining or joined (instead of SMTC_MODEM_RC_FAIL) +- [lr11xx-driver] Update lr11xx radio driver to v2.3.0 version +- [sx126x-driver] Update sx126x radio driver to v2.2.0 version +- [radio-ral] Update ral to get cad specific features +- [Return codes] `smtc_modem_get_pin` and `smtc_modem_derive_keys` now return `SMTC_MODEM_RC_BUSY` in case modem is joining or joined (instead of SMTC_MODEM_RC_FAIL) ## [v4.0.1] 2023-03-16 ### Fixed -* [utilities] fix incorrect location of `smtc_modem_is_irq_flag_pending()` check in exti example (shall be done before entering sleep) +- [utilities] fix incorrect location of `smtc_modem_is_irq_flag_pending()` check in exti example (shall be done before entering sleep) ## [v4.0.0] 2023-03-10 @@ -110,141 +130,141 @@ Detailed Modem HAL changelog can be found [here](smtc_modem_hal/CHANGELOG.md) ### Added -* [makefile]: add `options.mk` file that gathers all lbm build options +- [makefile]: add `options.mk` file that gathers all lbm build options ### Changed -* [behavior]: Under modem interruption (radio or timer), only the timestamp of the interruption is done (no radio or external peripheral access is done under irq). As a consequence the `smtc_modem_run_engine()` shall be called as soon as possible after any modem interruption (radio or timer) -* [makefile]: default Regional Parameters option is now RP2_103 (previous was RP2_101) -* [utilities]: - * add `app_options.mk` file that gathers all application build options - * [exti-example]: - * update example to send periodical uplinks - * in case compilation is done using `LR11XX_WITH_CREDENTIALS`, internal credentials won't be overridden - * add hardware modem example (folder [hw_modem](utilities/user_app/hw_modem) ) - * add porting tool example - * update smtc_hal_l4 code - * update radio_hal code - * update smtc_modem_hal.c code to be compliant with latest version of lbm +- [behavior]: Under modem interruption (radio or timer), only the timestamp of the interruption is done (no radio or external peripheral access is done under irq). As a consequence the `smtc_modem_run_engine()` shall be called as soon as possible after any modem interruption (radio or timer) +- [makefile]: default Regional Parameters option is now RP2_103 (previous was RP2_101) +- [utilities]: + - add `app_options.mk` file that gathers all application build options + - [exti-example]: + - update example to send periodical uplinks + - in case compilation is done using `LR11XX_WITH_CREDENTIALS`, internal credentials won't be overridden + - add hardware modem example (folder [hw_modem](utilities/user_app/hw_modem) ) + - add porting tool example + - update smtc_hal_l4 code + - update radio_hal code + - update smtc_modem_hal.c code to be compliant with latest version of lbm ### Fixed -* Correct size error in `smtc_secure_element_get_pin` -* [makefile] Remove ARM-specific flag from compilation flag -* [makefile] Correct `MCU_FLAGS` issue +- Correct size error in `smtc_secure_element_get_pin` +- [makefile] Remove ARM-specific flag from compilation flag +- [makefile] Correct `MCU_FLAGS` issue ## [v3.3.0] 2023-05-31 ### Added -* [general] Support of LR1121 radio (target: lr1121) -* [makefile] Provide a way to change any LBM define values in make command (use `EXTRAFLAGS` ) -* [utilities] Add a porting on NUCLEO-L073 board using LL drivers for minimal flash usage -* [utilities] Add a porting tool in main examples to help during mcu porting +- [general] Support of LR1121 radio (target: lr1121) +- [makefile] Provide a way to change any LBM define values in make command (use `EXTRAFLAGS` ) +- [utilities] Add a porting on NUCLEO-L073 board using LL drivers for minimal flash usage +- [utilities] Add a porting tool in main examples to help during mcu porting ### Changed -* [lr11xx_driver] Update to version `v2.3.0` -* [sx126x_driver] Update to version `v2.2.0` -* [makefile] Default Regional Parameters option is now RP2-1.0.3 LoRaWAN® Regional Parameters (previous was RP2-1.0.1) -* [utilities] Add response code assert in exti example -* [utilities] Remove temperature from exti example and replace it with 32b counter -* [utilities] Remove unused implementations and calls of uart4 related functions in smtc_hal_l4 -* [modem] Add randomness before any modem task that need to uplink something -* [alarm] Clamp alarm timer to 864000s ie 10 days -* [stack] Set minimal default reception window size to 16ms instead of 6 ms to avoid ping slots issue in FSK (can be changed be overriding `MIN_RX_WINDOW_DURATION_MS` define) +- [lr11xx_driver] Update to version `v2.3.0` +- [sx126x_driver] Update to version `v2.2.0` +- [makefile] Default Regional Parameters option is now RP2-1.0.3 LoRaWAN® Regional Parameters (previous was RP2-1.0.1) +- [utilities] Add response code assert in exti example +- [utilities] Remove temperature from exti example and replace it with 32b counter +- [utilities] Remove unused implementations and calls of uart4 related functions in smtc_hal_l4 +- [modem] Add randomness before any modem task that need to uplink something +- [alarm] Clamp alarm timer to 864000s ie 10 days +- [stack] Set minimal default reception window size to 16ms instead of 6 ms to avoid ping slots issue in FSK (can be changed be overriding `MIN_RX_WINDOW_DURATION_MS` define) ### Fixed -* Issue [#5](https://github.com/Lora-net/SWL2001/issues/5): Correct typo on MCU_FLAGS in makefile -* Issue [#6](https://github.com/Lora-net/SWL2001/issues/6): Example does not override EUI and Keys in case code is built with `CRYPTO=LR11XX_WITH_CREDENTIALS` -* Issue [#7](https://github.com/Lora-net/SWL2001/issues/7): Remove ARM-specific flag from common.mk -* Issue [#9](https://github.com/Lora-net/SWL2001/issues/9): Fix size error in smtc_secure_element_get_pin() -* [LBT] Fix lbt issue when tcxo startup delay is greater than default `RP_MARGIN_DELAY` value (8ms) -* [LRFHSS] Correct tx done timestamp with known bit padding delay to avoid issue with following rx windows (principally seen on US and AU regions) -* [AU915/US915] Fix LoRaWAN Link Adr Request issue (channel mask control case 5 missing impact on 500kHz bank) -* [utilities] In exti example, fix evaluation kit blue button missing pin in irq configuration +- Issue [#5](https://github.com/Lora-net/SWL2001/issues/5): Correct typo on MCU_FLAGS in makefile +- Issue [#6](https://github.com/Lora-net/SWL2001/issues/6): Example does not override EUI and Keys in case code is built with `CRYPTO=LR11XX_WITH_CREDENTIALS` +- Issue [#7](https://github.com/Lora-net/SWL2001/issues/7): Remove ARM-specific flag from common.mk +- Issue [#9](https://github.com/Lora-net/SWL2001/issues/9): Fix size error in smtc_secure_element_get_pin() +- [LBT] Fix lbt issue when tcxo startup delay is greater than default `RP_MARGIN_DELAY` value (8ms) +- [LRFHSS] Correct tx done timestamp with known bit padding delay to avoid issue with following rx windows (principally seen on US and AU regions) +- [AU915/US915] Fix LoRaWAN Link Adr Request issue (channel mask control case 5 missing impact on 500kHz bank) +- [utilities] In exti example, fix evaluation kit blue button missing pin in irq configuration ## [v3.2.4] 2022-08-23 ### Added -* AS923 group 4 Regional Parameters -* WW2G4 Regional Parameters for LoRaWAN protocol emulation -* Support of sx128x radio +- 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 +- [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 +- [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 -* AS923 (3 sub regions included), IN865, KR920, RU864, AU915 Regional Parameters -* Class B support -* Class B Multicast support (up to 4 sessions) -* Class C Multicast support (up to 4 sessions) -* LR-FHSS Support (enabled with compilation option: `RP_VERSION=RP2_103`) -* Support of SX1261 and SX1262 radios -* Added commands: - * New connectivity check function: smtc_modem_lorawan_get_lost_connection_counter - * Makefile: add Regional Parameters option to choose to compile the code for RP2_101 or RP2_103 - * [smtc_modem_hal]: - * `smtc_modem_hal_assert(expr)` macro - * `smtc_modem_hal_assert_fail()` function - * `smtc_modem_hal_get_time_in_100us()` function - * `smtc_modem_hal_get_radio_irq_timestamp_in_100us()` function - * In `SMTC_MODEM_EVENT_DOWNDATA` event status: added new class B reception windows, fpending bit status, reception frequency and datarate - * Middleware API for geolocation -* Add basic example to provide an easy start point on Nucleo L476 board +- AS923 (3 sub regions included), IN865, KR920, RU864, AU915 Regional Parameters +- Class B support +- Class B Multicast support (up to 4 sessions) +- Class C Multicast support (up to 4 sessions) +- LR-FHSS Support (enabled with compilation option: `RP_VERSION=RP2_103`) +- Support of SX1261 and SX1262 radios +- Added commands: + - New connectivity check function: smtc_modem_lorawan_get_lost_connection_counter + - Makefile: add Regional Parameters option to choose to compile the code for RP2_101 or RP2_103 + - [smtc_modem_hal]: + - `smtc_modem_hal_assert(expr)` macro + - `smtc_modem_hal_assert_fail()` function + - `smtc_modem_hal_get_time_in_100us()` function + - `smtc_modem_hal_get_radio_irq_timestamp_in_100us()` function + - In `SMTC_MODEM_EVENT_DOWNDATA` event status: added new class B reception windows, fpending bit status, reception frequency and datarate + - Middleware API for geolocation +- Add basic example to provide an easy start point on Nucleo L476 board ### Changed -* `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_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 -* An `ALMANAC_UPDATE` event is generated if "Almanac force update" is received. -* File upload size can be now up to 8k -* Remove -2dB default tx power offset (now it is 0) and manage EIRP to ERP conversion in LoRaWAN stack -* `smtc_modem_connection_timeout_get_thresholds`: Default internal value of `nb_of_uplinks_before_network_controlled` is now 0 (before was 255). Result: the mobile to static automatic switching service is now deactivated by default. +- `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_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 +- An `ALMANAC_UPDATE` event is generated if "Almanac force update" is received. +- File upload size can be now up to 8k +- Remove -2dB default tx power offset (now it is 0) and manage EIRP to ERP conversion in LoRaWAN stack +- `smtc_modem_connection_timeout_get_thresholds`: Default internal value of `nb_of_uplinks_before_network_controlled` is now 0 (before was 255). Result: the mobile to static automatic switching service is now deactivated by default. ### Fixed -* Corrected `Fcnt_down` msb management -* `smtc_modem_derive_keys` now takes user defined EUIs into account -* AU915: when dwell time was on, the returned max payload sizes were incorrect. This has been corrected -* Corrected bug in `smtc_modem_reset_charge` -* Internal join nonce value is now initialized to FFFFFF to avoid dropping the first join accept message +- Corrected `Fcnt_down` msb management +- `smtc_modem_derive_keys` now takes user defined EUIs into account +- AU915: when dwell time was on, the returned max payload sizes were incorrect. This has been corrected +- Corrected bug in `smtc_modem_reset_charge` +- Internal join nonce value is now initialized to FFFFFF to avoid dropping the first join accept message ## [v2.1.0] 2021-11-03 diff --git a/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.c b/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.c index f09cf8e..c35f8ef 100644 --- a/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.c +++ b/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.c @@ -216,15 +216,6 @@ uint32_t hal_rtc_get_time_s( void ) return rtc_get_calendar_time( &milliseconds ); } -uint32_t hal_rtc_get_time_100us( void ) -{ - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; - - seconds = rtc_get_calendar_time( &milliseconds_div_10 ); - - return seconds * 10000 + milliseconds_div_10; -} uint32_t hal_rtc_get_time_ms( void ) { uint32_t seconds = 0; diff --git a/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.h b/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.h index 72377de..8b70aa7 100644 --- a/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.h +++ b/lbm_applications/1_thread_x_on_stm32_u5/smtc_hal_u5/smtc_hal_rtc.h @@ -35,91 +35,81 @@ #define __RTC_UTILITIES_H__ #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -/* - * ----------------------------------------------------------------------------- - * --- DEPENDENCIES ------------------------------------------------------------ - */ - -#include // C99 types -#include // bool type -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC MACROS ----------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC CONSTANTS -------------------------------------------------------- - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC TYPES ------------------------------------------------------------ - */ - -/* - * ----------------------------------------------------------------------------- - * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- - */ - -/*! - * Initializes the MCU RTC peripheral - */ -void hal_rtc_init( void ); - -/*! - * Returns the current RTC time in seconds - * - * \remark Used for scheduling autonomous retransmissions (i.e: NbTrans), - * transmitting MAC answers, basically any delay without accurate time - * constraints. It is also used to measure the time spent inside the - * LoRaWAN process for the integrated failsafe. - * - * retval rtc_time_s Current RTC time in seconds - */ -uint32_t hal_rtc_get_time_s( void ); - -/*! - * Returns the current RTC time in milliseconds - * - * \remark Used to timestamp radio events (i.e: end of TX), will also be used - * for ClassB - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 49 days - */ -uint32_t hal_rtc_get_time_ms( void ); - - -/*! - * Returns the current RTC time in 0.1milliseconds - * - * \remark will also be used for d2d - * - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days - */ -uint32_t hal_rtc_get_time_100us( void ); - -/*! - * Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate - * an IRQ to wakeup the MCU. - * - * \param[IN] milliseconds Number of seconds before wakeup - */ -void hal_rtc_wakeup_timer_set_ms( const int32_t milliseconds ); - -/*! - * Stop the rtc wakeup timer - */ -void hal_rtc_wakeup_timer_stop( void ); + /* + * ----------------------------------------------------------------------------- + * --- DEPENDENCIES ------------------------------------------------------------ + */ + +#include // C99 types +#include // bool type + /* + * ----------------------------------------------------------------------------- + * --- PUBLIC MACROS ----------------------------------------------------------- + */ + + /* + * ----------------------------------------------------------------------------- + * --- PUBLIC CONSTANTS -------------------------------------------------------- + */ + + /* + * ----------------------------------------------------------------------------- + * --- PUBLIC TYPES ------------------------------------------------------------ + */ + + /* + * ----------------------------------------------------------------------------- + * --- PUBLIC FUNCTIONS PROTOTYPES --------------------------------------------- + */ + + /*! + * Initializes the MCU RTC peripheral + */ + void hal_rtc_init(void); + + /*! + * Returns the current RTC time in seconds + * + * \remark Used for scheduling autonomous retransmissions (i.e: NbTrans), + * transmitting MAC answers, basically any delay without accurate time + * constraints. It is also used to measure the time spent inside the + * LoRaWAN process for the integrated failsafe. + * + * retval rtc_time_s Current RTC time in seconds + */ + uint32_t hal_rtc_get_time_s(void); + + /*! + * Returns the current RTC time in milliseconds + * + * \remark Used to timestamp radio events (i.e: end of TX), will also be used + * for ClassB + * + * retval rtc_time_ms Current RTC time in milliseconds wraps every 49 days + */ + uint32_t hal_rtc_get_time_ms(void); + + /*! + * Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate + * an IRQ to wakeup the MCU. + * + * \param[IN] milliseconds Number of seconds before wakeup + */ + void hal_rtc_wakeup_timer_set_ms(const int32_t milliseconds); + + /*! + * Stop the rtc wakeup timer + */ + void hal_rtc_wakeup_timer_stop(void); #ifdef __cplusplus } #endif -#endif // __RTC_UTILITIES_H__ +#endif // __RTC_UTILITIES_H__ /* --- EOF ------------------------------------------------------------------ */ diff --git a/lbm_applications/1_thread_x_on_stm32_u5/smtc_modem_hal/smtc_modem_hal.c b/lbm_applications/1_thread_x_on_stm32_u5/smtc_modem_hal/smtc_modem_hal.c index 6d61ba6..8e80a58 100644 --- a/lbm_applications/1_thread_x_on_stm32_u5/smtc_modem_hal/smtc_modem_hal.c +++ b/lbm_applications/1_thread_x_on_stm32_u5/smtc_modem_hal/smtc_modem_hal.c @@ -134,10 +134,6 @@ uint32_t smtc_modem_hal_get_time_in_ms(void) return hal_rtc_get_time_ms(); } -uint32_t smtc_modem_hal_get_time_in_100us(void) -{ - return hal_rtc_get_time_100us(); -} void smtc_modem_hal_user_lbm_irq(void) { threadx_user_lbm_irq(); diff --git a/lbm_applications/2_porting_nrf_52840/README.md b/lbm_applications/2_porting_nrf_52840/README.md index 72d8293..014330d 100644 --- a/lbm_applications/2_porting_nrf_52840/README.md +++ b/lbm_applications/2_porting_nrf_52840/README.md @@ -1,4 +1,4 @@ -# Reference Implementation 2: Porting on Nordic NRF25840 Board +# Implementation reference 2: Porting on Nordic NRF52840 Board This folder contains implementations of LoRa Basics Modem on some MCU boards and some application examples. diff --git a/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c b/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c index b103ad2..a5bae82 100644 --- a/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c +++ b/lbm_applications/2_porting_nrf_52840/radio_hal/sx126x_hal.c @@ -104,14 +104,10 @@ sx126x_hal_status_t sx126x_hal_write( const void* context, const uint8_t* comman // Put NSS low to start spi transaction hal_gpio_set_value( RADIO_NSS, 0 ); - for( uint16_t i = 0; i < command_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, command[i] ); - } - for( uint16_t i = 0; i < data_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, data[i] ); - } + + hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 ); + hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 ); + // Put NSS high as the spi transaction is finished hal_gpio_set_value( RADIO_NSS, 1 ); @@ -135,13 +131,11 @@ sx126x_hal_status_t sx126x_hal_read( const void* context, const uint8_t* command // Put NSS low to start spi transaction hal_gpio_set_value( RADIO_NSS, 0 ); - for( uint16_t i = 0; i < command_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, command[i] ); - } - for( uint16_t i = 0; i < data_length; i++ ) + hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 ); + + if( data_length > 0 ) { - data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 ); + hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length ); } // Put NSS high as the spi transaction is finished hal_gpio_set_value( RADIO_NSS, 1 ); diff --git a/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c b/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c index 11d4b43..64846b6 100644 --- a/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c +++ b/lbm_applications/2_porting_nrf_52840/radio_hal/sx128x_hal.c @@ -103,14 +103,10 @@ sx128x_hal_status_t sx128x_hal_write( const void* context, const uint8_t* comman // Put NSS low to start spi transaction hal_gpio_set_value( RADIO_NSS, 0 ); - for( uint16_t i = 0; i < command_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, command[i] ); - } - for( uint16_t i = 0; i < data_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, data[i] ); - } + + hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 ); + hal_spi_in_out( RADIO_SPI_ID, data, data_length, NULL, 0 ); + // Put NSS high as the spi transaction is finished hal_gpio_set_value( RADIO_NSS, 1 ); @@ -134,14 +130,13 @@ sx128x_hal_status_t sx128x_hal_read( const void* context, const uint8_t* command // Put NSS low to start spi transaction hal_gpio_set_value( RADIO_NSS, 0 ); - for( uint16_t i = 0; i < command_length; i++ ) - { - hal_spi_in_out( RADIO_SPI_ID, command[i] ); - } - for( uint16_t i = 0; i < data_length; i++ ) + hal_spi_in_out( RADIO_SPI_ID, command, command_length, NULL, 0 ); + + if( data_length > 0 ) { - data[i] = hal_spi_in_out( RADIO_SPI_ID, 0 ); + hal_spi_in_out( RADIO_SPI_ID, 0, 0, data, data_length ); } + // Put NSS high as the spi transaction is finished hal_gpio_set_value( RADIO_NSS, 1 ); diff --git a/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.c b/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.c index 13ae14d..5048f78 100644 --- a/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.c +++ b/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.c @@ -99,7 +99,7 @@ void hal_rtc_init( void ) uint32_t hal_rtc_get_time_s( void ) { uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 ); - uint64_t tmp = ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) / + uint64_t tmp = ( ( uint64_t ) ( tmp_rtc ) + ( uint64_t ) ( ( 1ULL << 24 ) * ( uint64_t ) rtc_wrap_counter ) ) / NRFX_RTC_DEFAULT_CONFIG_FREQUENCY; return ( uint32_t ) tmp; } @@ -107,16 +107,9 @@ uint32_t hal_rtc_get_time_s( void ) uint32_t hal_rtc_get_time_ms( void ) { uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 ); - uint64_t tmp = ( ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) * 1000 ) / - NRFX_RTC_DEFAULT_CONFIG_FREQUENCY; - return ( uint32_t ) tmp; -} - -uint32_t hal_rtc_get_time_100us( void ) -{ - uint32_t tmp_rtc = nrf_drv_rtc_counter_get( &rtc1 ); - uint64_t tmp = ( ( ( uint64_t )( tmp_rtc ) + ( uint64_t )( ( 1 << 24 ) * rtc_wrap_counter ) ) * 10000 ) / - NRFX_RTC_DEFAULT_CONFIG_FREQUENCY; + uint64_t tmp = + ( ( ( uint64_t ) ( tmp_rtc ) + ( uint64_t ) ( ( 1ULL << 24 ) * ( uint64_t ) rtc_wrap_counter ) ) * 1000 ) / + NRFX_RTC_DEFAULT_CONFIG_FREQUENCY; return ( uint32_t ) tmp; } diff --git a/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.h b/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.h index 581e6b2..fc2d652 100644 --- a/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.h +++ b/lbm_applications/2_porting_nrf_52840/smtc_hal_nrf52840/smtc_hal_rtc.h @@ -101,16 +101,6 @@ uint32_t hal_rtc_get_time_s( void ); */ uint32_t hal_rtc_get_time_ms( void ); -/*! - * Returns the current RTC time in 0.1milliseconds - * - * \remark will also be used for d2d - * - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days - */ -uint32_t hal_rtc_get_time_100us( void ); - /*! * Starts the provided timer objet for the given time * diff --git a/lbm_applications/2_porting_nrf_52840/smtc_modem_hal/smtc_modem_hal.c b/lbm_applications/2_porting_nrf_52840/smtc_modem_hal/smtc_modem_hal.c index 7b0be0e..a3c4204 100644 --- a/lbm_applications/2_porting_nrf_52840/smtc_modem_hal/smtc_modem_hal.c +++ b/lbm_applications/2_porting_nrf_52840/smtc_modem_hal/smtc_modem_hal.c @@ -138,11 +138,6 @@ uint32_t smtc_modem_hal_get_time_in_ms( void ) return hal_rtc_get_time_ms( ); } -uint32_t smtc_modem_hal_get_time_in_100us( void ) -{ - return hal_rtc_get_time_100us( ); -} - /* ------------ Timer management ------------*/ void smtc_modem_hal_start_timer( const uint32_t milliseconds, void ( *callback )( void* context ), void* context ) diff --git a/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.c b/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.c index 85ae18b..bd68134 100644 --- a/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.c +++ b/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.c @@ -205,15 +205,6 @@ uint32_t hal_rtc_get_time_s( void ) return rtc_get_calendar_time( &milliseconds ); } -uint32_t hal_rtc_get_time_100us( void ) -{ - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; - - seconds = rtc_get_calendar_time( &milliseconds_div_10 ); - - return seconds * 10000 + milliseconds_div_10; -} uint32_t hal_rtc_get_time_ms( void ) { uint32_t seconds = 0; @@ -247,7 +238,7 @@ 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 * 10000 ) + ( ( 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 ) @@ -265,7 +256,7 @@ static uint32_t rtc_get_calendar_time( uint16_t* milliseconds_div_10 ) uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( ); - 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; diff --git a/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.h b/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.h index a7469c8..f38ac4d 100644 --- a/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.h +++ b/lbm_applications/3_geolocation_on_lora_edge/smtc_hal_l4/smtc_hal_rtc.h @@ -92,16 +92,6 @@ uint32_t hal_rtc_get_time_s( void ); */ uint32_t hal_rtc_get_time_ms( void ); -/*! - * Returns the current RTC time in 0.1milliseconds - * - * \remark will also be used for d2d - * - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days - */ -uint32_t hal_rtc_get_time_100us( void ); - /*! * Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate * an IRQ to wakeup the MCU. diff --git a/lbm_applications/3_geolocation_on_lora_edge/smtc_modem_hal/smtc_modem_hal.c b/lbm_applications/3_geolocation_on_lora_edge/smtc_modem_hal/smtc_modem_hal.c index 9501b98..55619be 100644 --- a/lbm_applications/3_geolocation_on_lora_edge/smtc_modem_hal/smtc_modem_hal.c +++ b/lbm_applications/3_geolocation_on_lora_edge/smtc_modem_hal/smtc_modem_hal.c @@ -135,11 +135,6 @@ uint32_t smtc_modem_hal_get_time_in_ms( void ) return hal_rtc_get_time_ms( ); } -uint32_t smtc_modem_hal_get_time_in_100us( void ) -{ - return hal_rtc_get_time_100us( ); -} - /* ------------ Timer management ------------*/ void smtc_modem_hal_start_timer( const uint32_t milliseconds, void ( *callback )( void* context ), void* context ) diff --git a/lbm_examples/hw_modem/cmd_parser.c b/lbm_examples/hw_modem/cmd_parser.c index e7a00f7..71d102c 100644 --- a/lbm_examples/hw_modem/cmd_parser.c +++ b/lbm_examples/hw_modem/cmd_parser.c @@ -264,6 +264,8 @@ static const uint8_t host_cmd_tab[CMD_MAX][HOST_CMD_TAB_IDX_COUNT] = { [CMD_WIFI_SET_PAYLOAD_FORMAT] = { 1, 1, 1 }, [CMD_LR11XX_RADIO_READ] = { 1, 0, 255 }, [CMD_LR11XX_RADIO_WRITE] = { 1, 0, 255 }, + [CMD_SET_RTC_OFFSET] ={1,4,4}, + #endif // ADD_APP_GEOLOCATION && STM32L476xx }; @@ -427,6 +429,7 @@ static const char* host_cmd_str[CMD_MAX] = { [CMD_WIFI_SET_PAYLOAD_FORMAT] = "CMD_MODEM_WIFI_SET_PAYLOAD_FORMAT", [CMD_LR11XX_RADIO_READ] = "CMD_LR11XX_RADIO_READ", [CMD_LR11XX_RADIO_WRITE] = "CMD_LR11XX_RADIO_WRITE", + [CMD_SET_RTC_OFFSET] = "CMD_SET_RTC_OFFSET", #endif // ADD_APP_GEOLOCATION && STM32L476xx }; @@ -1020,6 +1023,17 @@ cmd_parse_status_t parse_cmd( cmd_input_t* cmd_input, cmd_response_t* cmd_output } break; } + case CMD_SET_RTC_OFFSET : + { + uint32_t rtc_offset = 0; + rtc_offset |= cmd_input->buffer[0] << 24; + rtc_offset |= cmd_input->buffer[1] << 16; + rtc_offset |= cmd_input->buffer[2] << 8; + rtc_offset |= cmd_input->buffer[3]; + SMTC_HAL_TRACE_PRINTF (" change rtc offset to test wrapping with value = %x\n",rtc_offset); + smtc_modem_hal_set_offset_to_test_wrapping( rtc_offset ); + break; + } case CMD_TEST: { cmd_tst_input_t cmd_tst_input; diff --git a/lbm_examples/hw_modem/cmd_parser.h b/lbm_examples/hw_modem/cmd_parser.h index 2d55974..fd33593 100644 --- a/lbm_examples/hw_modem/cmd_parser.h +++ b/lbm_examples/hw_modem/cmd_parser.h @@ -196,6 +196,7 @@ typedef enum host_cmd_id_e CMD_LR11XX_RADIO_READ = 0x90, CMD_LR11XX_RADIO_WRITE = 0x91, #endif // ADD_APP_GEOLOCATION && STM32L476xx + CMD_SET_RTC_OFFSET =0x92, CMD_MAX } host_cmd_id_t; diff --git a/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.c b/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.c index 8fd6129..b741a64 100644 --- a/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.c +++ b/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.c @@ -123,7 +123,7 @@ * ----------------------------------------------------------------------------- * --- PRIVATE TYPES ----------------------------------------------------------- */ - +static uint32_t offset_to_test_wrapping = 0; /* * ----------------------------------------------------------------------------- * --- PRIVATE VARIABLES ------------------------------------------------------- @@ -133,7 +133,7 @@ * ----------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- */ - +static uint32_t rtc_get_offset_to_test_wrapping (void); /*! * Converts time in ms to time in wake up timer ticks * Assuming WUCKSEL[2:0] = 000: RTCCLK/16 clock is selected @@ -225,15 +225,6 @@ uint32_t hal_rtc_get_time_s( void ) return rtc_get_calendar_time( &milliseconds ); } -uint32_t hal_rtc_get_time_100us( void ) -{ - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; - - seconds = rtc_get_calendar_time( &milliseconds_div_10 ); - - return seconds * 10000 + milliseconds_div_10; -} uint32_t hal_rtc_get_time_ms( void ) { uint32_t seconds = 0; @@ -283,7 +274,10 @@ void hal_rtc_wakeup_timer_stop( void ) LL_RTC_DisableIT_WUT( RTC ); LL_RTC_WAKEUP_Disable( RTC ); } - +void hal_rtc_set_offset_to_test_wrapping( uint32_t offset ) +{ + offset_to_test_wrapping = offset; +} /* * ----------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- @@ -294,7 +288,7 @@ 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 * 10000 ) + ( ( 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 ) @@ -310,9 +304,9 @@ static uint32_t rtc_get_calendar_time( uint16_t* milliseconds_div_10 ) { uint32_t ticks; - uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( ); + uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( ) + ( uint64_t) ((( uint64_t)rtc_get_offset_to_test_wrapping()) << N_PREDIV_S ); - 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; @@ -339,20 +333,20 @@ static uint64_t rtc_get_timestamp_in_ticks( void ) sub_seconds = LL_RTC_TIME_GetSubSecond( RTC ); // Get the DR register (Date) - uint32_t dr_val = ( uint32_t )( RTC->DR & RTC_DR_RESERVED_MASK ); + uint32_t dr_val = ( uint32_t ) ( RTC->DR & RTC_DR_RESERVED_MASK ); // Fill the data with the read parameters - year = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( ( dr_val & ( RTC_DR_YT | RTC_DR_YU ) ) >> 16U ) ); - month = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( ( dr_val & ( RTC_DR_MT | RTC_DR_MU ) ) >> 8U ) ); - date = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( dr_val & ( RTC_DR_DT | RTC_DR_DU ) ) ); + year = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( ( dr_val & ( RTC_DR_YT | RTC_DR_YU ) ) >> 16U ) ); + month = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( ( dr_val & ( RTC_DR_MT | RTC_DR_MU ) ) >> 8U ) ); + date = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( dr_val & ( RTC_DR_DT | RTC_DR_DU ) ) ); // Get the TR register (Time) - uint32_t tr_val = ( uint32_t )( RTC->TR & RTC_TR_RESERVED_MASK ); + uint32_t tr_val = ( uint32_t ) ( RTC->TR & RTC_TR_RESERVED_MASK ); // Fill the data with the read parameters - hours = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( ( tr_val & ( RTC_TR_HT | RTC_TR_HU ) ) >> 16U ) ); - minutes = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( ( tr_val & ( RTC_TR_MNT | RTC_TR_MNU ) ) >> 8U ) ); - seconds = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t )( tr_val & ( RTC_TR_ST | RTC_TR_SU ) ) ); + hours = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( ( tr_val & ( RTC_TR_HT | RTC_TR_HU ) ) >> 16U ) ); + minutes = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( ( tr_val & ( RTC_TR_MNT | RTC_TR_MNU ) ) >> 8U ) ); + seconds = __LL_RTC_CONVERT_BCD2BIN( ( uint8_t ) ( tr_val & ( RTC_TR_ST | RTC_TR_SU ) ) ); } while( ssr != RTC->SSR ); @@ -388,5 +382,8 @@ void RTC_IRQHandler( void ) LL_EXTI_ClearFlag_0_31( LL_EXTI_LINE_20 ); } } - +static uint32_t rtc_get_offset_to_test_wrapping (void) +{ + return offset_to_test_wrapping ; +} /* --- EOF ------------------------------------------------------------------ */ diff --git a/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.h b/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.h index 72377de..9b17f7d 100644 --- a/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.h +++ b/lbm_examples/smtc_hal_l0_LL/smtc_hal_rtc.h @@ -92,17 +92,6 @@ uint32_t hal_rtc_get_time_s( void ); */ uint32_t hal_rtc_get_time_ms( void ); - -/*! - * Returns the current RTC time in 0.1milliseconds - * - * \remark will also be used for d2d - * - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days - */ -uint32_t hal_rtc_get_time_100us( void ); - /*! * Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate * an IRQ to wakeup the MCU. @@ -116,6 +105,10 @@ void hal_rtc_wakeup_timer_set_ms( const int32_t milliseconds ); */ void hal_rtc_wakeup_timer_stop( void ); +/*! + * hal to test wrapping + */ +void hal_rtc_set_offset_to_test_wrapping( const uint32_t offset ); #ifdef __cplusplus } #endif diff --git a/lbm_examples/smtc_hal_l4/smtc_hal_rtc.c b/lbm_examples/smtc_hal_l4/smtc_hal_rtc.c index 85ae18b..0f1e77b 100644 --- a/lbm_examples/smtc_hal_l4/smtc_hal_rtc.c +++ b/lbm_examples/smtc_hal_l4/smtc_hal_rtc.c @@ -114,7 +114,7 @@ */ static RTC_HandleTypeDef hal_rtc_handle; - +static uint32_t offset_to_test_wrapping = 0; /* * ----------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- @@ -153,6 +153,12 @@ static uint32_t rtc_get_calendar_time( uint16_t* milliseconds ); */ static uint64_t rtc_get_timestamp_in_ticks( void ); +/*! + * Get current offset + * + * + */ +static uint32_t rtc_get_offset_to_test_wrapping (void); /* * ----------------------------------------------------------------------------- * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- @@ -205,15 +211,6 @@ uint32_t hal_rtc_get_time_s( void ) return rtc_get_calendar_time( &milliseconds ); } -uint32_t hal_rtc_get_time_100us( void ) -{ - uint32_t seconds = 0; - uint16_t milliseconds_div_10 = 0; - - seconds = rtc_get_calendar_time( &milliseconds_div_10 ); - - return seconds * 10000 + milliseconds_div_10; -} uint32_t hal_rtc_get_time_ms( void ) { uint32_t seconds = 0; @@ -236,6 +233,10 @@ void hal_rtc_wakeup_timer_stop( void ) { HAL_RTCEx_DeactivateWakeUpTimer( &hal_rtc_handle ); } +void hal_rtc_set_offset_to_test_wrapping( uint32_t offset ) +{ + offset_to_test_wrapping = offset; +} /* * ----------------------------------------------------------------------------- @@ -247,7 +248,7 @@ 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 * 10000 ) + ( ( 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 ) @@ -262,10 +263,10 @@ static uint32_t rtc_ms_2_wakeup_timer_tick( const uint32_t milliseconds ) static uint32_t rtc_get_calendar_time( uint16_t* milliseconds_div_10 ) { uint32_t ticks; + + uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( ) + ( uint64_t) ((( uint64_t)rtc_get_offset_to_test_wrapping()) << N_PREDIV_S ); - uint64_t timestamp_in_ticks = rtc_get_timestamp_in_ticks( ); - - 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; @@ -331,5 +332,9 @@ void HAL_RTC_MspDeInit( RTC_HandleTypeDef* rtc_handle ) __HAL_RCC_RTC_DISABLE( ); HAL_NVIC_DisableIRQ( RTC_WKUP_IRQn ); } +static uint32_t rtc_get_offset_to_test_wrapping (void) +{ + return offset_to_test_wrapping ; +} /* --- EOF ------------------------------------------------------------------ */ diff --git a/lbm_examples/smtc_hal_l4/smtc_hal_rtc.h b/lbm_examples/smtc_hal_l4/smtc_hal_rtc.h index a7469c8..9b17f7d 100644 --- a/lbm_examples/smtc_hal_l4/smtc_hal_rtc.h +++ b/lbm_examples/smtc_hal_l4/smtc_hal_rtc.h @@ -92,16 +92,6 @@ uint32_t hal_rtc_get_time_s( void ); */ uint32_t hal_rtc_get_time_ms( void ); -/*! - * Returns the current RTC time in 0.1milliseconds - * - * \remark will also be used for d2d - * - * - * retval rtc_time_ms Current RTC time in milliseconds wraps every 4.9 days - */ -uint32_t hal_rtc_get_time_100us( void ); - /*! * Sets the rtc wakeup timer for milliseconds parameter. The RTC will generate * an IRQ to wakeup the MCU. @@ -115,6 +105,10 @@ void hal_rtc_wakeup_timer_set_ms( const int32_t milliseconds ); */ void hal_rtc_wakeup_timer_stop( void ); +/*! + * hal to test wrapping + */ +void hal_rtc_set_offset_to_test_wrapping( const uint32_t offset ); #ifdef __cplusplus } #endif diff --git a/lbm_examples/smtc_modem_hal/smtc_modem_hal.c b/lbm_examples/smtc_modem_hal/smtc_modem_hal.c index f9f49e2..d9f9f04 100644 --- a/lbm_examples/smtc_modem_hal/smtc_modem_hal.c +++ b/lbm_examples/smtc_modem_hal/smtc_modem_hal.c @@ -157,11 +157,10 @@ uint32_t smtc_modem_hal_get_time_in_ms( void ) return hal_rtc_get_time_ms( ); } -uint32_t smtc_modem_hal_get_time_in_100us( void ) +void smtc_modem_hal_set_offset_to_test_wrapping( const uint32_t offset_to_test_wrapping ) { - return hal_rtc_get_time_100us( ); + hal_rtc_set_offset_to_test_wrapping( offset_to_test_wrapping ); } - /* ------------ Timer management ------------*/ void smtc_modem_hal_start_timer( const uint32_t milliseconds, void ( *callback )( void* context ), void* context ) diff --git a/lbm_lib/README.md b/lbm_lib/README.md index 9c9a44a..f07d5ad 100644 --- a/lbm_lib/README.md +++ b/lbm_lib/README.md @@ -35,7 +35,7 @@ Facilitates porting with the following required MCU hardware resources: - 1 HW timer. - 1 SPI interface. - - Minimum 40KB of FLASH memory allowing an end-device to run in Class A mode for a single region; each additional region adds 1.5KB. + - Minimum 40 KB of FLASH is required to operate in Class A with a single region (EX:EU868). Each additional region adds approximately 1.5 KB. - Minimum 6KB of RAM memory. - 48B of non-volatile memory to store LoRaWAN and modem context. Up to 512B of non-volatile memory if a software-emulated secure-element is used. @@ -85,6 +85,7 @@ For example, to build LoRa Basics Modem for an STM32L4 MCU the following MCU_FLA ### Regions Support for one or more of the following regions can be selected at compile time: + - AS_923 - AS923MHz ISM Band. Group selection is performed at runtime through the API. - AU_915 - AU915-928MHz ISM Band. - CN_470 - CN470-510MHz Band. @@ -198,6 +199,7 @@ Before initiating a join procedure, set LoRaWAN parameters using the following f Once parameters are set, start joining a LoRaWAN network by calling `smtc_modem_join_network()`. The user is informed of the procedure's progress via two events: + - `SMTC_MODEM_EVENT_JOINED`: Join accept received; the join procedure is complete. - `SMTC_MODEM_EVENT_JOINFAIL`: Nothing received after the join request; the join procedure continues. @@ -235,6 +237,7 @@ Once connected to a LoRaWAN network, configure parameters: - Number of transmissions for each unconfirmed uplink with `smtc_modem_set_nb_trans()` Retrieve information about the connection: + - Duty cycle limitation status with `smtc_modem_get_duty_cycle_status()` - Maximum size of the next uplink with `smtc_modem_get_next_tx_max_payload()` - Available datarates with `smtc_modem_get_enabled_datarates()` @@ -284,6 +287,7 @@ To change the ping slot periodicity (default is 7, meaning a ping slot every 128 Up to 4 multicast groups can be configured by calling `smtc_modem_multicast_set_grp_config()` with the following parameters for each group to be configured: + - Group ID - Address - Network session key @@ -294,6 +298,7 @@ To retrieve the group address of a specific group ID, use `smtc_modem_multicast_ #### LoRaWAN Multicast in Class B In Class B mode, when multicast groups are configured, initiate each session by calling `smtc_modem_multicast_class_b_start_session()` with the following parameters: + - Group ID - Frequency - Datarate @@ -306,11 +311,11 @@ To halt all Class B multicast sessions, use `smtc_modem_multicast_class_b_stop_a #### LoRaWAN Multicast in Class C In Class C mode, when multicast groups are configured, initiate each session with `smtc_modem_multicast_class_c_start_session()` and provide: + - Group ID - Frequency - Datarate - Class C multicast downlinks are available by fetching downlink data with `smtc_modem_get_downlink_data()` after the event `SMTC_MODEM_EVENT_DOWNDATA` triggered. The window metadata value with `SMTC_MODEM_DL_WINDOW_RXC_MC_GRPx`(x being the multicast group ID). It is possible to read back the status of the current session by calling `smtc_modem_multicast_class_c_get_session_status()`. A multicast session can be stopped by calling `smtc_modem_multicast_class_c_stop_session()`. @@ -329,6 +334,7 @@ Initiate LoRaWAN-specific Mac requests with `smtc_modem_trig_lorawan_mac_request Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_LINK_CHECK` bit mask to generate a LoRaWAN Link Check Request uplink. Transmission status is available through the `SMTC_MODEM_EVENT_LINK_CHECK` event: + - `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network. - `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Valid answer received; data can be fetched using `smtc_modem_get_lorawan_link_check_data()`. @@ -336,6 +342,7 @@ Transmission status is available through the `SMTC_MODEM_EVENT_LINK_CHECK` event Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_DEVICE_TIME` bit mask to generate a LoRaWAN Device Time Request uplink. Transmission status is available through the `SMTC_MODEM_EVENT_LORAWAN_MAC_TIME` event: + - `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network. - `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Valid answer received; time can be fetched using `smtc_modem_get_lorawan_mac_time()`. @@ -343,6 +350,7 @@ Transmission status is available through the `SMTC_MODEM_EVENT_LORAWAN_MAC_TIME` Use `smtc_modem_trig_lorawan_mac_request()` with the `SMTC_MODEM_LORAWAN_MAC_REQ_PING_SLOT_INFO` bit mask to generate a LoRaWAN Ping Slot Info Request uplink. Transmission status is available through the `SMTC_MODEM_EVENT_CLASS_B_PING_SLOT_INFO` event: + - `SMTC_MODEM_EVENT_MAC_REQUEST_NOT_ANSWERED`: No answer received from the network. - `SMTC_MODEM_EVENT_MAC_REQUEST_ANSWERED`: Network acknowledged the request. @@ -397,6 +405,7 @@ To activate it during project compilation, set the `LBM_FUOTA` flag to `yes` and Multi-Package Access is not automaticaly added to compilation even if `LBM_FUOTA` flag is set to `yes`. User shall set `LBM_FUOTA_ENABLE_MPA` to yes to use it. Additionally, provide the following compilation fields: + - `FUOTA_MAXIMUM_NB_OF_FRAGMENTS` - `FUOTA_MAXIMUM_SIZE_OF_FRAGMENTS` - `FUOTA_MAXIMUM_FRAG_REDUNDANCY` @@ -406,6 +415,7 @@ Class B, Class C, multicast, and the previously mentioned packages are automatic #### Prerequisites before starting a FUOTA session Two essential functions must be implemented for the FUOTA service: + - `smtc_modem_hal_context_store` for the `CONTEXT_FUOTA` parameter - `smtc_modem_hal_context_restore` function @@ -441,6 +451,7 @@ When all Class C multicast sessions are completed, the stack remains in Class C The process is similar to that described for Class C with the exception that Class B activation process will generate some dedicated events (see Class B section for details). In normal operation, the user should receive the following events successively: + - `SMTC_MODEM_EVENT_NEW_MULTICAST_SESSION_CLASS_B` - `SMTC_MODEM_EVENT_LORAWAN_FUOTA_DONE` - `SMTC_MODEM_EVENT_NO_MORE_MULTICAST_SESSION_CLASS_B` @@ -449,6 +460,7 @@ In normal operation, the user should receive the following events successively: The user can stream data, allowing LoRa Basics™ Modem to handle maximum transmission size limits. Before initiating a stream, the user must set several parameters using `smtc_modem_stream_init()`: + - LoRaWAN FPort - Encryption mode - Redundancy ratio @@ -462,6 +474,7 @@ The event `SMTC_MODEM_EVENT_STREAM_DONE` is triggered when the last byte of the Empower your application with the Large File Upload service in LoRa Basics Modem, allowing you to transmit files of up to 8180 bytes seamlessly, with the modem managing maximum transmission size limits. Before initiating a file upload, set the required parameters by invoking `smtc_modem_file_upload_init()`: + - Application index - Encryption mode - File to be sent and its size @@ -470,6 +483,7 @@ Before initiating a file upload, set the required parameters by invoking `smtc_m Once configured, commence the transfer with `smtc_modem_file_upload_start()`. If needed, the transfer can be aborted using `smtc_modem_file_upload_reset()`. The event `SMTC_MODEM_EVENT_UPLOAD_DONE` is triggered when: + - The LoRa Cloud Modem & Geolocation Services acknowledges the reception with a dedicated downlink message (status set to `SMTC_MODEM_EVENT_UPLOAD_DONE_SUCCESSFUL`) - No acknowledgment is received after the last upload (status set to `SMTC_MODEM_EVENT_UPLOAD_DONE_ABORTED`) @@ -481,6 +495,7 @@ The event `SMTC_MODEM_EVENT_UPLOAD_DONE` is triggered when: The device management service allows sending periodic information reports. Enable this service using `smtc_modem_dm_enable()`. Before initiating a periodic information report, set various parameters (order does not matter): + - LoRaWAN FPort, with `smtc_modem_dm_set_fport()` - Fields to be reported, with `smtc_modem_dm_set_periodic_info_fields()` - (Optional) User data to be reported, with `smtc_modem_dm_set_user_data()` - useful only if `SMTC_MODEM_DM_FIELD_APP_STATUS` is part of the user_data parameter given to `smtc_modem_dm_set_periodic_info_fields()` @@ -491,6 +506,7 @@ Request a device management information report, distinct from periodic reports, #### Downlink requests The cloud service may send requests to the modem on the device management port. Four kinds of requests can be received: + - **Reset request**: Requests a reset (a `SMTC_MODEM_EVENT_RESET` event will be triggered once the modem resets) - **Rejoin**: Asks the modem to leave and rejoin the network (a new `SMTC_MODEM_EVENT_JOINED` or `SMTC_MODEM_EVENT_JOINFAIL` will be triggered afterward) - **Mute**: ask the modem to mute itself permanently or during a specified number of days (a `SMTC_MODEM_EVENT_MUTE` event is triggered) @@ -532,6 +548,7 @@ In the provided example on the STM32L4 MCU (under the lbm_examples folder), LPTI - [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 datarates are not accurate. - [charge] Values returned by `smtc_modem_get_charge()` for sx127x radios are not accurate. +- [charge] Values returned by `smtc_modem_get_charge()` do not count CSMA and LBT power consumption. - [LBT-CSMA] Avoid combining LBT and CSMA features, as doing so may result in unpredictable stack behavior. - [modem-status] The joining bit status is exclusively set during the LoRaWAN join transaction (i.e., TX/RX1/RX2) and remains unset between join attempts. - [file upload] DAS may encounter difficulties reconstructing small files (less than 13 bytes) when the modem operates in the US915 region and utilizes DR0 data rate. diff --git a/lbm_lib/lora_basics_modem_version.h b/lbm_lib/lora_basics_modem_version.h index 6ea175e..46a906a 100644 --- a/lbm_lib/lora_basics_modem_version.h +++ b/lbm_lib/lora_basics_modem_version.h @@ -57,7 +57,7 @@ extern "C" { */ #define LORA_BASICS_MODEM_FW_VERSION_MAJOR 4 #define LORA_BASICS_MODEM_FW_VERSION_MINOR 3 -#define LORA_BASICS_MODEM_FW_VERSION_PATCH 0 +#define LORA_BASICS_MODEM_FW_VERSION_PATCH 1 /* * ----------------------------------------------------------------------------- diff --git a/lbm_lib/smtc_modem_core/lorawan_packages/lorawan_certification/lorawan_certification.c b/lbm_lib/smtc_modem_core/lorawan_packages/lorawan_certification/lorawan_certification.c index 225015f..eac8b7b 100644 --- a/lbm_lib/smtc_modem_core/lorawan_packages/lorawan_certification/lorawan_certification.c +++ b/lbm_lib/smtc_modem_core/lorawan_packages/lorawan_certification/lorawan_certification.c @@ -225,8 +225,16 @@ void lorawan_certification_services_init( uint8_t* service_id, uint8_t task_id, ctx->stack_id = CURRENT_STACK; ctx->enabled = lorawan_api_modem_certification_is_enabled( CURRENT_STACK ); - SMTC_MODEM_HAL_TRACE_INFO( "LoRaWAN Certification is %s on stack %d \n", - ( ctx->enabled == true ? "enabled" : "disabled" ), ctx->stack_id ); + if( ctx->enabled == true ) + { + SMTC_MODEM_HAL_TRACE_WARNING( "***********************************************\n" ); + SMTC_MODEM_HAL_TRACE_WARNING( " LoRaWAN CERTIFICATION is ENABLED on stack %d\n", ctx->stack_id ); + SMTC_MODEM_HAL_TRACE_WARNING( "***********************************************\n" ); + } + else + { + SMTC_MODEM_HAL_TRACE_PRINTF( "LoRaWAN Certification is disabled on stack %d\n", ctx->stack_id ); + } lorawan_certification_init( ctx ); diff --git a/lbm_lib/smtc_modem_core/lorawan_packages/multi_package_access/lorawan_mpa_package.c b/lbm_lib/smtc_modem_core/lorawan_packages/multi_package_access/lorawan_mpa_package.c index f9b6727..145ab21 100644 --- a/lbm_lib/smtc_modem_core/lorawan_packages/multi_package_access/lorawan_mpa_package.c +++ b/lbm_lib/smtc_modem_core/lorawan_packages/multi_package_access/lorawan_mpa_package.c @@ -179,6 +179,7 @@ typedef enum mpa_multi_pack_buffer_req_status_e { MPA_MULTI_PACK_BUFFER_REQ_NOT_RCV = 0x00, MPA_MULTI_PACK_BUFFER_REQ_OK = 0x01, + MPA_MULTI_PACK_BUFFER_REQ_PENDING = 0x02, MPA_MULTI_PACK_BUFFER_REQ_ERROR = 0xFF, } mpa_multi_pack_buffer_req_status_t; @@ -199,7 +200,9 @@ typedef struct lorawan_mpa_package_s mpa_multi_pack_buffer_req_status_t mpa_multi_pack_buffer_req_status; uint8_t start_byte; uint8_t stop_byte; - + uint8_t start_byte_pending; + uint8_t stop_byte_pending; + uint8_t nb_cmd_parsed; } lorawan_mpa_package_ctx_t; /* ----------------------------------------------------------------------------- @@ -546,8 +549,9 @@ static mpa_status_t mpa_package_parser( lorawan_mpa_package_ctx_t* ctx, uint8_t* uint8_t mpa_package_rx_buffer_index = 0; uint8_t ans_index = 0; - uint8_t pkg_id_tmp; - uint8_t pkg_id_tmp_previous = MPA_ID; + uint8_t pkg_id_tmp; + uint8_t pkg_id_tmp_previous = MPA_ID; + mpa_multi_pack_buffer_req_status_t mpa_multi_pack_buffer_req_status_bkp = ctx->mpa_multi_pack_buffer_req_status; *increment_event = false; @@ -555,6 +559,8 @@ static mpa_status_t mpa_package_parser( lorawan_mpa_package_ctx_t* ctx, uint8_t* SMTC_MODEM_HAL_TRACE_ARRAY( "MPA rcv buff", mpa_package_rx_buffer, mpa_package_rx_buffer_length ); + ctx->nb_cmd_parsed = 0; + while( ( mpa_package_rx_buffer_length - MPA_TOKEN_SIZE ) > mpa_package_rx_buffer_index ) { if( ( mpa_package_rx_buffer[mpa_package_rx_buffer_index] & 0x80 ) == 0x0 ) @@ -577,6 +583,8 @@ static mpa_status_t mpa_package_parser( lorawan_mpa_package_ctx_t* ctx, uint8_t* return MPA_STATUS_ERROR; } + ctx->nb_cmd_parsed++; + if( mpa_service_push_payload_to_targeted_package[pkg_id_tmp & 0x7F]( ctx->stack_id, &mpa_package_rx_buffer[mpa_package_rx_buffer_index], &nb_bytes_read_payload_in, rx_window, tmp_tx_ans, &payload_out_length, sizeof( tmp_tx_ans ), rx_timestamp_ms ) == false ) @@ -585,7 +593,8 @@ static mpa_status_t mpa_package_parser( lorawan_mpa_package_ctx_t* ctx, uint8_t* } // Copy temp answer payload only if mpa_tx_payload_ans is not yet full - if( ( ans_index + payload_out_length ) <= sizeof( ctx->mpa_tx_payload_ans ) ) + if( ( ( ans_index + payload_out_length ) < sizeof( ctx->mpa_tx_payload_ans ) ) && + ( payload_out_length <= sizeof( tmp_tx_ans ) ) ) { memcpy( &ctx->mpa_tx_payload_ans[ans_index], tmp_tx_ans, payload_out_length ); // Copy all answers ans_index += payload_out_length; @@ -595,6 +604,21 @@ static mpa_status_t mpa_package_parser( lorawan_mpa_package_ctx_t* ctx, uint8_t* mpa_package_rx_buffer_index += nb_bytes_read_payload_in; } + if( ctx->mpa_multi_pack_buffer_req_status == MPA_MULTI_PACK_BUFFER_REQ_PENDING ) + { + if( ctx->nb_cmd_parsed == 1 ) + { // MultiPackBufferReq is the only command present + ctx->mpa_multi_pack_buffer_req_status = MPA_MULTI_PACK_BUFFER_REQ_OK; + ctx->start_byte = ctx->start_byte_pending; + ctx->stop_byte = ctx->stop_byte_pending; + } + else + { // Ignore downlink + ctx->mpa_multi_pack_buffer_req_status = mpa_multi_pack_buffer_req_status_bkp; + return MPA_STATUS_OK; + } + } + if( ctx->mpa_multi_pack_buffer_req_status == MPA_MULTI_PACK_BUFFER_REQ_NOT_RCV ) { ctx->token = mpa_package_rx_buffer[mpa_package_rx_buffer_length - 1] & 0x03; @@ -664,7 +688,7 @@ static bool mpa_package_parser_internal( uint8_t stack_id, uint8_t* payload_in, SMTC_MODEM_HAL_TRACE_WARNING( "MPA CiD 0x%02x\n", payload_in[mpa_package_rx_buffer_index] ); uint8_t cmd_id = payload_in[mpa_package_rx_buffer_index]; - if( cmd_id > sizeof( mpa_req_cmd_size ) ) + if( cmd_id >= sizeof( mpa_req_cmd_size ) ) { return false; } @@ -697,32 +721,26 @@ static bool mpa_package_parser_internal( uint8_t stack_id, uint8_t* payload_in, break; } case MPA_MULTI_PACK_BUFFER_REQ: { - uint8_t start_byte = payload_in[mpa_package_rx_buffer_index + 1]; - uint8_t stop_byte = payload_in[mpa_package_rx_buffer_index + 2]; + ctx->start_byte_pending = payload_in[mpa_package_rx_buffer_index + 1]; + ctx->stop_byte_pending = payload_in[mpa_package_rx_buffer_index + 2]; - ctx->mpa_multi_pack_buffer_req_status = MPA_MULTI_PACK_BUFFER_REQ_OK; + ctx->mpa_multi_pack_buffer_req_status = MPA_MULTI_PACK_BUFFER_REQ_PENDING; // Start byte is greater than the payload answer - if( start_byte > ( ctx->mpa_tx_payload_ans_size - 1 ) ) + if( ctx->start_byte_pending > ( ctx->mpa_tx_payload_ans_size - 1 ) ) { ctx->mpa_multi_pack_buffer_req_status = MPA_MULTI_PACK_BUFFER_REQ_ERROR; } // Stop byte is smaller than the start byte - if( stop_byte < start_byte ) + if( ctx->stop_byte_pending < ctx->start_byte_pending ) { ctx->mpa_multi_pack_buffer_req_status = MPA_MULTI_PACK_BUFFER_REQ_ERROR; } - if( stop_byte > MPA_SIZE_ANS_MAX - MPA_FRAG_HDR_SIZE - MPA_TOKEN_SIZE ) - { - stop_byte = MPA_SIZE_ANS_MAX - MPA_FRAG_HDR_SIZE - MPA_TOKEN_SIZE; - } - - if( ctx->mpa_multi_pack_buffer_req_status == MPA_MULTI_PACK_BUFFER_REQ_OK ) + if( ctx->stop_byte_pending > MPA_SIZE_ANS_MAX - MPA_FRAG_HDR_SIZE - MPA_TOKEN_SIZE ) { - ctx->start_byte = start_byte; - ctx->stop_byte = stop_byte; + ctx->stop_byte_pending = MPA_SIZE_ANS_MAX - MPA_FRAG_HDR_SIZE - MPA_TOKEN_SIZE; } break; } diff --git a/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v1.0.0/lorawan_remote_multicast_setup_package_v1.0.0.c b/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v1.0.0/lorawan_remote_multicast_setup_package_v1.0.0.c index a50d126..ef06d35 100644 --- a/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v1.0.0/lorawan_remote_multicast_setup_package_v1.0.0.c +++ b/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v1.0.0/lorawan_remote_multicast_setup_package_v1.0.0.c @@ -763,6 +763,8 @@ bool lorawan_remote_multicast_setup_mpa_injector( uint8_t stack_id, uint8_t* pay SMTC_MODEM_HAL_PANIC_ON_FAILURE( ctx->remote_multicast_tx_payload_ans_size <= max_payload_out_length ); *payload_out_length = ctx->remote_multicast_tx_payload_ans_size; memcpy( payload_out, ctx->remote_multicast_tx_payload_ans, ctx->remote_multicast_tx_payload_ans_size ); + + lorawan_remote_multicast_setup_add_task( ctx, 0 ); return true; } else diff --git a/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v2.0.0/lorawan_remote_multicast_setup_package_v2.0.0.c b/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v2.0.0/lorawan_remote_multicast_setup_package_v2.0.0.c index b6fdc88..b9cc5af 100644 --- a/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v2.0.0/lorawan_remote_multicast_setup_package_v2.0.0.c +++ b/lbm_lib/smtc_modem_core/lorawan_packages/remote_multicast_setup/v2.0.0/lorawan_remote_multicast_setup_package_v2.0.0.c @@ -762,6 +762,8 @@ bool lorawan_remote_multicast_setup_mpa_injector( uint8_t stack_id, uint8_t* pay SMTC_MODEM_HAL_PANIC_ON_FAILURE( ctx->remote_multicast_tx_payload_ans_size <= max_payload_out_length ); *payload_out_length = ctx->remote_multicast_tx_payload_ans_size; memcpy( payload_out, ctx->remote_multicast_tx_payload_ans, ctx->remote_multicast_tx_payload_ans_size ); + + lorawan_remote_multicast_setup_add_task( ctx, 0 ); return true; } else @@ -965,7 +967,7 @@ static remote_multicast_setup_status_t remote_multicast_setup_package_parser( // reset time out to force stop class c in case of class c is already started multicast_group_params[mc_grp_id].params.time_out = 0; ctx->launch_class_c[mc_grp_id] = - false; // don't reset ctx->stop_class_c, let do it by the task enqueu by the supervisor + false; // don't reset ctx->stop_class_c, let do it by the task enqueue by the supervisor if( ctx->stop_class_c[mc_grp_id] == true ) { lorawan_api_multicast_c_stop_session( mc_grp_id, stack_id ); diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c b/lbm_lib/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c index d84b08f..e46460a 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c @@ -497,7 +497,8 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac ) SMTC_MODEM_HAL_PANIC_ON_FAILURE( ral_lr_fhss_get_hop_sequence_count( &lr1_mac->rp->radio->ral, &lr_fhss_param.ral_lr_fhss_params, &nb_max_hop_sequence ) == RAL_STATUS_OK ); - lr_fhss_param.hop_sequence_id = smtc_modem_hal_get_random_nb_in_range( 0, ( uint32_t ) nb_max_hop_sequence ); + lr_fhss_param.hop_sequence_id = + smtc_modem_hal_get_random_nb_in_range( 0, ( uint32_t ) nb_max_hop_sequence - 1 ); lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.modulation_type = LR_FHSS_V1_MODULATION_TYPE_GMSK_488; lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.cr = tx_cr; lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.grid = smtc_real_lr_fhss_get_grid( lr1_mac->real ); diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c index 6efc07b..1dd1d5a 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c @@ -212,11 +212,8 @@ static bool is_valid_beacon( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t timesta */ #define TIME_MS_TO_BEACON_SYMB( N ) \ ( MIN( MAX( ( N / BEACON_SYMB_DURATION_MS( ) ), MIN_BEACON_WINDOW_SYMB ), MAX_BEACON_WINDOW_SYMB( ) ) ) -/** - * @brief compute the dpll phase with a resultion of 1ms - */ -#define DPLL_PHASE_MS( ) lr1_beacon_obj->dpll_phase_100us / 10 +#define DPLL_PHASE_MS( ) lr1_beacon_obj->dpll_phase /* * ----------------------------------------------------------------------------- * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- @@ -237,7 +234,7 @@ void smtc_beacon_sniff_init( smtc_lr1_beacon_t* lr1_beacon_obj, smtc_ping_slot_t lr1_beacon_obj->beacon_statistics.beacon_state = BEACON_UNLOCK; lr1_beacon_obj->push_callback = push_callback; lr1_beacon_obj->push_context = &( lr1_mac->rx_down_data ); - lr1_beacon_obj->dpll_frequency_100us = BEACON_PERIOD_MS * 10; + lr1_beacon_obj->dpll_frequency = BEACON_PERIOD_MS; lr1_beacon_obj->listen_beacon_rate = NUMBER_OF_STACKS; rp_release_hook( lr1_beacon_obj->rp, lr1_beacon_obj->beacon_sniff_id_rp ); @@ -299,14 +296,14 @@ smtc_class_b_beacon_t smtc_beacon_sniff_start( smtc_lr1_beacon_t* lr1_beacon_obj return SMTC_CLASS_B_BEACON_NOT_TIME_SYNC; } // init the digital pll phase to the closest gps epoch time multiple of BEACON_PERIOD_S. time is provided by the - // stack with the device time request cmd. The format of the dpll_phase_100us isn't expressed in gps_epoch_time unit - // but convert into the internal rtc millisecond counter. As a consequence dpll_phase_100us will contain the time of + // stack with the device time request cmd. The format of the dpll_phase isn't expressed in gps_epoch_time unit + // but convert into the internal rtc millisecond counter. As a consequence dpll_phase will contain the time of // the next target beacon time (in the internal rtc millisecond format) uint32_t pll_phase_temp; pll_phase_temp = 1000 * ( BEACON_PERIOD_S - ( seconds_since_epoch % BEACON_PERIOD_S ) ); pll_phase_temp += rtc; pll_phase_temp -= fractional_second; - lr1_beacon_obj->dpll_phase_100us = pll_phase_temp * 10; // dpll phase in 100us resolution + lr1_beacon_obj->dpll_phase = pll_phase_temp; lr1_beacon_obj->beacon_open_rx_nb_symb = MAX_BEACON_WINDOW_SYMB( ); lr1_beacon_obj->started = true; lr1mac_core_convert_rtc_to_gps_epoch_time( lr1_beacon_obj->lr1_mac, pll_phase_temp, &seconds_since_epoch, @@ -317,8 +314,8 @@ smtc_class_b_beacon_t smtc_beacon_sniff_start( smtc_lr1_beacon_t* lr1_beacon_obj fractional_second ); // launch beacon radio sniff beacon_rp_request( lr1_beacon_obj ); - SMTC_MODEM_HAL_TRACE_PRINTF( "Next beacon in %u ms at %u\n", DPLL_PHASE_MS( ) - rtc, - lr1_beacon_obj->dpll_phase_100us ); + SMTC_MODEM_HAL_TRACE_PRINTF( "Next beacon in %u ms at %u\n", lr1_beacon_obj->dpll_phase - rtc, + lr1_beacon_obj->dpll_phase ); return SMTC_CLASS_B_BEACON_OK; } @@ -395,7 +392,7 @@ void smtc_beacon_sniff_launch_callback_for_rp( void* rp_void ) 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 - while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) + while( ( int32_t ) ( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { } smtc_modem_hal_start_radio_tcxo( ); @@ -416,10 +413,10 @@ void smtc_beacon_sniff_rp_callback( smtc_lr1_beacon_t* lr1_beacon_obj ) uint32_t beacon_epoch_time = 0; // assuming that the radio hw latency between the end of the packet and the timestamp of the rx packet is about // 1/2 symbol - uint32_t timestamp = lr1_beacon_obj->rp->irq_timestamp_100us[lr1_beacon_obj->beacon_sniff_id_rp] - - ( ( BEACON_SYMB_DURATION_US( ) >> 1 ) / 100 ); + uint32_t timestamp = lr1_beacon_obj->rp->irq_timestamp_ms[lr1_beacon_obj->beacon_sniff_id_rp] - + ( ( BEACON_SYMB_DURATION_MS( ) ) >> 1 ); - SMTC_MODEM_HAL_TRACE_PRINTF( " beacon_timestamp_us = %u us\n", timestamp * 100 ); + SMTC_MODEM_HAL_TRACE_PRINTF( " beacon_timestamp = %u ms\n", timestamp ); lr1_beacon_obj->is_valid_beacon = false; if( rp_status == RP_STATUS_RX_PACKET ) @@ -433,7 +430,7 @@ void smtc_beacon_sniff_rp_callback( smtc_lr1_beacon_t* lr1_beacon_obj ) update_beacon_pll( lr1_beacon_obj, timestamp ); update_beacon_state( lr1_beacon_obj ); - compute_beacon_metadata( lr1_beacon_obj, timestamp / 10, beacon_epoch_time ); + compute_beacon_metadata( lr1_beacon_obj, timestamp, beacon_epoch_time ); update_beacon_rx_nb_symb( lr1_beacon_obj, DPLL_PHASE_MS( ) ); beacon_debug_print( lr1_beacon_obj ); @@ -442,9 +439,8 @@ void smtc_beacon_sniff_rp_callback( smtc_lr1_beacon_t* lr1_beacon_obj ) if( ( lr1_beacon_obj->beacon_statistics.beacon_state == BEACON_LOCK ) && ( lr1_beacon_obj->lr1_mac->ping_slot_info_user_req == USER_MAC_REQ_ACKED ) ) { - uint32_t current_beacon_phase_100us = - ( lr1_beacon_obj->dpll_phase_100us - lr1_beacon_obj->dpll_frequency_100us ); - smtc_ping_slot_init_after_beacon( lr1_beacon_obj->ping_slot_obj, current_beacon_phase_100us, DPLL_PHASE_MS( ), + uint32_t current_beacon_phase = ( lr1_beacon_obj->dpll_phase - lr1_beacon_obj->dpll_frequency ); + smtc_ping_slot_init_after_beacon( lr1_beacon_obj->ping_slot_obj, current_beacon_phase, DPLL_PHASE_MS( ), BEACON_RESERVED_MS, BEACON_GUARD_MS, lr1_beacon_obj->beacon_epoch_time ); smtc_ping_slot_start( lr1_beacon_obj->ping_slot_obj ); @@ -648,39 +644,38 @@ static void update_beacon_pll( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t times { if( lr1_beacon_obj->beacon_statistics.beacon_state == BEACON_UNLOCK ) { - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( - "time error on first beacon = %d (100us resolution) \n", - timestamp - lr1_beacon_obj->dpll_phase_100us - 10 * lr1_beacon_obj->beacon_toa ); - lr1_beacon_obj->dpll_frequency_100us = BEACON_PERIOD_MS * 10; + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "time error on first beacon = %u (1ms resolution) \n", + timestamp - lr1_beacon_obj->dpll_phase - lr1_beacon_obj->beacon_toa ); + lr1_beacon_obj->dpll_frequency = BEACON_PERIOD_MS; lr1_beacon_obj->dpll_error = 0; lr1_beacon_obj->dpll_error_wo_filtering = 0; lr1_beacon_obj->dpll_error_sum = 0; - lr1_beacon_obj->dpll_phase_100us = timestamp - 10 * lr1_beacon_obj->beacon_toa; + lr1_beacon_obj->dpll_phase = timestamp - lr1_beacon_obj->beacon_toa; } if( lr1_beacon_obj->beacon_statistics.beacon_state == BEACON_LOCK ) { lr1_beacon_obj->dpll_error_wo_filtering = - timestamp - lr1_beacon_obj->dpll_phase_100us - ( 10 * lr1_beacon_obj->beacon_toa ); + timestamp - lr1_beacon_obj->dpll_phase - ( lr1_beacon_obj->beacon_toa ); lr1_beacon_obj->dpll_error = ( BEACON_PLL_PHASE_GAIN_MUL * lr1_beacon_obj->dpll_error + lr1_beacon_obj->dpll_error_wo_filtering ) / BEACON_PLL_PHASE_GAIN_DIV; lr1_beacon_obj->dpll_error_sum += lr1_beacon_obj->dpll_error; if( lr1_beacon_obj->dpll_error_sum > BEACON_PLL_FREQUENCY_GAIN ) { - lr1_beacon_obj->dpll_frequency_100us++; + lr1_beacon_obj->dpll_frequency++; lr1_beacon_obj->dpll_error_sum = 0; } if( lr1_beacon_obj->dpll_error_sum < ( BEACON_PLL_FREQUENCY_GAIN * ( -1 ) ) ) { - lr1_beacon_obj->dpll_frequency_100us--; + lr1_beacon_obj->dpll_frequency--; lr1_beacon_obj->dpll_error_sum = 0; } } } - lr1_beacon_obj->dpll_phase_100us += - ( lr1_beacon_obj->dpll_frequency_100us ) + ( ( ABS( lr1_beacon_obj->dpll_error ) > 100 ) - ? ( 100 * SIGN( lr1_beacon_obj->dpll_error ) ) - : lr1_beacon_obj->dpll_error ); + lr1_beacon_obj->dpll_phase += + ( lr1_beacon_obj->dpll_frequency ) + ( ( ABS( lr1_beacon_obj->dpll_error ) > 10 ) + ? ( 10 * SIGN( lr1_beacon_obj->dpll_error ) ) + : lr1_beacon_obj->dpll_error ); } static void update_beacon_state( smtc_lr1_beacon_t* lr1_beacon_obj ) { @@ -714,19 +709,19 @@ static void beacon_debug_print( smtc_lr1_beacon_t* lr1_beacon_obj ) lr1_beacon_obj->beacon_buffer_length ); } - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "--> PLL INFO ppl_phase =%d, pll_error_100us= %d pll_frequency_100us = %d \n", - lr1_beacon_obj->dpll_phase_100us, lr1_beacon_obj->dpll_error, - lr1_beacon_obj->dpll_frequency_100us ); - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "\n********************\n" ); - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( - "-->BEACON STATUS \n received = %d\n missed = %d\n received_consecutively = %d\n lost_consecutively " - "=%d\n four_last_beacon_rx_statistic = %d\n" - " next beacon rx_nb_symb = %d\n", + SMTC_MODEM_HAL_TRACE_PRINTF( "--> PLL INFO ppl_phase =%u, pll_error= %u pll_frequency = %u \n", + lr1_beacon_obj->dpll_phase, lr1_beacon_obj->dpll_error, + lr1_beacon_obj->dpll_frequency ); + SMTC_MODEM_HAL_TRACE_PRINTF( "\n********************\n" ); + SMTC_MODEM_HAL_TRACE_PRINTF( + "-->BEACON STATUS \n received = %u\n missed = %u\n received_consecutively = %u\n lost_consecutively " + "=%u\n four_last_beacon_rx_statistic = %u\n" + " next beacon rx_nb_symb = %u\n", lr1_beacon_obj->beacon_statistics.nb_beacon_received, lr1_beacon_obj->beacon_statistics.nb_beacon_missed, lr1_beacon_obj->beacon_statistics.last_beacon_received_consecutively, lr1_beacon_obj->beacon_statistics.last_beacon_lost_consecutively, lr1_beacon_obj->beacon_statistics.four_last_beacon_rx_statistic, lr1_beacon_obj->beacon_open_rx_nb_symb ); - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "********************\n " ); + SMTC_MODEM_HAL_TRACE_PRINTF( "********************\n " ); } static void update_beacon_rx_nb_symb( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t target_time ) { @@ -739,7 +734,7 @@ static void update_beacon_rx_nb_symb( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_ uint32_t rx_timeout_symb_in_ms_tmp; // unused for beacon uint32_t rx_timeout_symb_locked_in_ms_tmp; SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( - "rx delay = %d ms\n", target_time - lr1_beacon_obj->beacon_statistics.last_beacon_received_timestamp ); + "rx delay = %u ms\n", target_time - lr1_beacon_obj->beacon_statistics.last_beacon_received_timestamp ); smtc_real_get_rx_window_parameters( lr1_beacon_obj->lr1_mac->real, BEACON_DATA_RATE( ), ( target_time - lr1_beacon_obj->beacon_statistics.last_beacon_received_timestamp ), @@ -750,7 +745,7 @@ static void update_beacon_rx_nb_symb( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_ { lr1_beacon_obj->beacon_open_rx_nb_symb = MIN( lr1_beacon_obj->beacon_open_rx_nb_symb + - ( ( uint32_t )( 4 - lr1_beacon_obj->beacon_statistics.four_last_beacon_rx_statistic ) * + ( ( uint32_t ) ( 4 - lr1_beacon_obj->beacon_statistics.four_last_beacon_rx_statistic ) * lr1_beacon_obj->beacon_open_rx_nb_symb ), TIME_MS_TO_BEACON_SYMB( MAX_BEACON_WINDOW_MS ) ); } @@ -770,13 +765,12 @@ static bool is_valid_beacon( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t timesta uint32_t seconds_since_epoch; uint32_t fractional_second; uint32_t beacon_epoch_time = smtc_decode_beacon_epoch_time( lr1_beacon_obj->beacon_buffer, GET_BEACON_SF( ) ); - bool status = - lr1mac_core_convert_rtc_to_gps_epoch_time( lr1_beacon_obj->lr1_mac, timestamp / 10 - lr1_beacon_obj->beacon_toa, - &seconds_since_epoch, &fractional_second ); + bool status = lr1mac_core_convert_rtc_to_gps_epoch_time( + lr1_beacon_obj->lr1_mac, timestamp - lr1_beacon_obj->beacon_toa, &seconds_since_epoch, &fractional_second ); if( status == true ) { int32_t check_time = ( beacon_epoch_time - seconds_since_epoch ) * 1000 - fractional_second; - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " beacon_time - network time = %d ms\n", check_time ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " beacon_time - network time = %u ms\n", check_time ); if( ( uint32_t ) ABS( check_time ) < MAX_BEACON_WINDOW_MS ) { return true; diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.h b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.h index a35cb55..bccf97a 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.h +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.h @@ -103,7 +103,7 @@ extern "C" { * @brief to track the Beacon it is implemented a digital (Phase Locked Loop), the BEACON_PLL_FREQUENCY_GAIN allow to * adjust the pll gain of the frequency loop. By reducing this value it increases the gain of frequency loop */ -#define BEACON_PLL_FREQUENCY_GAIN ( 32 ) +#define BEACON_PLL_FREQUENCY_GAIN ( 32) /** * @brief to track the Beacon it is implemented a digital pll, the phase loop gain of the pll is defined as : * BEACON_PLL_PHASE_GAIN_MUL/BEACON_PLL_PHASE_GAIN_DIV @@ -186,8 +186,8 @@ typedef struct smtc_lr1_beacon_s int32_t dpll_error_wo_filtering; //!< the internal digital pll phase error without filtering int32_t dpll_error; //!< the internal digital pll phase error after low pass filter int32_t dpll_error_sum; //!< the cumulative digital pll phase error after low pass filter - uint32_t dpll_frequency_100us; //!< the digital pll frequency with a 0.1ms resolution - uint32_t dpll_phase_100us; //!< the digital pll phase with a 0.1ms resolution + uint32_t dpll_frequency; //!< the digital pll frequency with a 0.1ms resolution + uint32_t dpll_phase; //!< the digital pll phase with a 0.1ms resolution uint8_t listen_beacon_rate; //!< default value : DEFAULT_LISTEN_BEACON_RATE, referred to the explanation of this //!< default value to understood this parameter diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c index 616022b..15a9fe7 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c @@ -230,13 +230,11 @@ void smtc_ping_slot_init_after_beacon( smtc_ping_slot_t* ping_slot_obj, uint32_t ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_period = 1 << ( 5 + ping_slot_obj->rx_session_param[i]->ping_slot_periodicity ); - ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time_100us = + ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time = smtc_ping_slot_compute_first_slot( beacon_timestamp, beacon_reserved_ms, beacon_epoch_time, ping_slot_obj->rx_session_param[i]->dev_addr, ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_period, ping_slot_obj->lr1_mac->stack_id ); - ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time = - ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time_100us / 10; } } } @@ -252,13 +250,6 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj ) SMTC_MODEM_HAL_PANIC( "ping_slot_obj bad initialization \n" ); } - if( lr1mac_core_is_time_valid( ping_slot_obj->lr1_mac ) == false ) - { - smtc_ping_slot_stop( ping_slot_obj ); - SMTC_MODEM_HAL_TRACE_WARNING( "Ping Slot not started, time sync is not valid\n" ); - return; - } - if( ping_slot_obj->lr1_mac->ping_slot_info_user_req != USER_MAC_REQ_ACKED ) { smtc_ping_slot_stop( ping_slot_obj ); @@ -427,8 +418,6 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj ) &rx_offset_ms_tmp ); rp_task.start_time_ms = RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time + rx_offset_ms_tmp + ( RX_BEACON_TIMESTAMP_ERROR >> 1 ); - rp_task.start_time_100us = RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time_100us + - rx_offset_ms_tmp * 10 + ( RX_BEACON_TIMESTAMP_ERROR >> 1 ) * 10; rp_task.duration_time_ms = smtc_ping_slot_get_duration_timeout_ms( ping_slot_obj, RX_SESSION_PARAM_CURRENT->rx_window_symb, RX_SESSION_PARAM_CURRENT->rx_data_rate ); @@ -458,7 +447,7 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj ) RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time, &ping_slot_seconds_since_epoch, &ping_slot_fractional_second ); - SMTC_MODEM_HAL_TRACE_PRINTF( "ping_slot_obj(%u) devaddr:%x START at %d (%u.%u), freq:%u, dr:%d, PingNb:%d\n", + SMTC_MODEM_HAL_TRACE_PRINTF( "ping_slot_obj(%u) devaddr:%x START at %u (%u.%u), freq:%u, dr:%u, PingNb:%u\n", ping_slot_obj->lr1_mac->stack_id, RX_SESSION_PARAM_CURRENT->dev_addr, RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time, ping_slot_seconds_since_epoch, ping_slot_fractional_second, ping_slot_freq, @@ -483,7 +472,7 @@ void smtc_ping_slot_rp_callback( smtc_ping_slot_t* ping_slot_obj ) // by the rp) if( rp_status == RP_STATUS_TASK_ABORTED ) { - SMTC_MODEM_HAL_TRACE_PRINTF( "--> ping slot abort %d\n", ping_slot_obj->rx_session_index ); + SMTC_MODEM_HAL_TRACE_PRINTF( "--> ping slot abort %u\n", ping_slot_obj->rx_session_index ); uint32_t tmp = 0; if( RX_SESSION_PARAM_CURRENT->enabled == true ) { @@ -493,7 +482,7 @@ void smtc_ping_slot_rp_callback( smtc_ping_slot_t* ping_slot_obj ) smtc_ping_slot_compute_next_ping_offset_time( ping_slot_obj, RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time + tmp ); } - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "--> %d\n", rp_status ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "--> %u\n", rp_status ); } if( ping_slot_obj->enabled == true ) @@ -538,7 +527,7 @@ void smtc_ping_slot_mac_rp_callback( smtc_ping_slot_t* ping_slot_obj ) RX_DOWN_DATA.rx_payload_size = ( uint8_t ) ping_slot_obj->rp->rx_payload_size[from_hook_id]; SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( - "payload size receive = %u, snr = %d , rssi = %d\n", RX_DOWN_DATA.rx_payload_size, + "payload size receive = %u, snr = %u , rssi = %u\n", RX_DOWN_DATA.rx_payload_size, ping_slot_obj->rp->radio_params[from_hook_id].rx.lora_pkt_status.snr_pkt_in_db, ping_slot_obj->rp->radio_params[from_hook_id].rx.lora_pkt_status.rssi_pkt_in_dbm ); @@ -551,7 +540,7 @@ void smtc_ping_slot_mac_rp_callback( smtc_ping_slot_t* ping_slot_obj ) { ping_slot_obj->valid_rx_packet = smtc_ping_slot_mac_rx_frame_decode( ping_slot_obj ); - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Receive a downlink RXB for Hook Id = %d\n", from_hook_id ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Receive a downlink RXB for Hook Id = %u\n", from_hook_id ); if( ping_slot_obj->valid_rx_packet == USER_RX_PACKET ) { @@ -589,7 +578,7 @@ void smtc_ping_slot_mac_rp_callback( smtc_ping_slot_t* ping_slot_obj ) } } -uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_100us, uint32_t beacon_reserved_ms, +uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_ms, uint32_t beacon_reserved_ms, uint32_t beacon_epoch_time, uint32_t dev_addr, uint16_t ping_period, uint8_t stack_id ) { @@ -600,8 +589,8 @@ uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_100us, SMTC_MODEM_HAL_PANIC( "Crypto error while getting class B rand number for ping slot offset computation" ); } - uint32_t ret = ( beacon_time_received_100us + 10 * beacon_reserved_ms + - ( ( rand[0] + ( rand[1] << 8 ) ) % ping_period ) * 300 ); + uint32_t ret = + ( beacon_time_received_ms + beacon_reserved_ms + ( ( rand[0] + ( rand[1] << 8 ) ) % ping_period ) * 30 ); return ret; } @@ -756,7 +745,7 @@ static int smtc_ping_slot_mac_downlink_check( smtc_ping_slot_t* ping_slot_obj ) if( RX_SESSION_PARAM_CURRENT->dev_addr != dev_addr_tmp ) { status += ERRORLORAWAN; - SMTC_MODEM_HAL_TRACE_PRINTF( "class B[%d] BAD DevAddr=0x%x instead of 0x%x \n", + SMTC_MODEM_HAL_TRACE_PRINTF( "class B[%u] BAD DevAddr=0x%x instead of 0x%x \n", ping_slot_obj->rx_session_index, dev_addr_tmp, RX_SESSION_PARAM_CURRENT->dev_addr ); } @@ -789,8 +778,6 @@ static void smtc_ping_slot_compute_next_ping_offset_time( smtc_ping_slot_t* ping ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_number--; ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time += ( ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_period * 30 ); - ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time_100us += - ( ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_period * 300 ); } } } @@ -812,7 +799,7 @@ static void smtc_ping_slot_search_closest_ping_offset_time( smtc_ping_slot_t* pi { ping_slot_obj->rx_session_index = i; - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Ping Slot session %d enabled", i ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Ping Slot session %u enabled", i ); SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "--> offset %u, init\n", RX_SESSION_PARAM[i]->ping_slot_parameters.ping_offset_time ); break; @@ -839,7 +826,7 @@ static void smtc_ping_slot_search_closest_ping_offset_time( smtc_ping_slot_t* pi // Search Ping Slot for each enabled session if( RX_SESSION_PARAM[i]->enabled == true ) { - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Ping Slot session %d enabled", i ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Ping Slot session %u enabled", i ); SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "--> offset %u, ", RX_SESSION_PARAM[i]->ping_slot_parameters.ping_offset_time ); @@ -847,13 +834,13 @@ static void smtc_ping_slot_search_closest_ping_offset_time( smtc_ping_slot_t* pi if( ( ( int32_t ) ( RX_SESSION_PARAM[i]->ping_slot_parameters.ping_offset_time - timestamp_rtc ) < 0 ) && ( RX_SESSION_PARAM[i]->ping_slot_parameters.ping_number == 0 ) ) { - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " no more ping slot for session %d\n", i ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " no more ping slot for session %u\n", i ); continue; } if( ( int32_t ) ( ping_slot_obj->rx_session_param[i]->ping_slot_parameters.ping_offset_time - ( ping_slot_obj->next_beacon_timestamp - ping_slot_obj->beacon_guard_ms ) ) >= 0 ) { - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " no more ping slot for session (guard) %d\n", i ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " no more ping slot for session (guard) %u\n", i ); continue; } @@ -1033,7 +1020,7 @@ static rx_packet_type_t smtc_ping_slot_mac_rx_frame_decode( smtc_ping_slot_t* pi if( status == OKLORAWAN ) { RX_SESSION_PARAM_CURRENT->fcnt_dwn = fcnt_dwn_stack_tmp; - SMTC_MODEM_HAL_TRACE_WARNING_DEBUG( " fcnt_tmp = %d\n ", RX_SESSION_PARAM_CURRENT->fcnt_dwn ); + SMTC_MODEM_HAL_TRACE_WARNING_DEBUG( " fcnt_tmp = %u\n ", RX_SESSION_PARAM_CURRENT->fcnt_dwn ); ping_slot_obj->lr1_mac->fcnt_dwn = ping_slot_obj->rx_session_param[RX_SESSION_UNICAST]->fcnt_dwn; // Set FPending bit in metadata @@ -1123,7 +1110,7 @@ static rx_packet_type_t smtc_ping_slot_mac_rx_frame_decode( smtc_ping_slot_t* pi ping_slot_obj->rx_major = rx_major; } - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " RxB rx_packet_type = %d \n", rx_packet_type ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( " RxB rx_packet_type = %u \n", rx_packet_type ); return ( rx_packet_type ); } @@ -1186,7 +1173,7 @@ static uint32_t smtc_ping_slot_compute_downlink_toa( lr1_stack_mac_t* lr1_mac, u SMTC_MODEM_HAL_PANIC( "TX MODULATION NOT SUPPORTED\n" ); } - SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Toa = %d\n", toa ); + SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "Toa = %u\n", toa ); return toa; } @@ -1199,7 +1186,7 @@ static void ping_slot_mac_rx_lora_launch_callback_for_rp( void* rp_void ) 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 - while( ( int32_t ) ( rp->tasks[id].start_time_100us - smtc_modem_hal_get_time_in_100us( ) ) > 0 ) + while( ( int32_t ) ( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 ) { } smtc_modem_hal_start_radio_tcxo( ); diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.h b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.h index 9fa9aec..535e3d7 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.h +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.h @@ -208,7 +208,7 @@ void smtc_ping_slot_mac_rp_callback( smtc_ping_slot_t* ping_slot_obj ); * @return uint32_t */ -uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_100us, uint32_t beacon_reserved_ms, +uint32_t smtc_ping_slot_compute_first_slot( uint32_t beacon_time_received_ms, uint32_t beacon_reserved_ms, uint32_t beacon_epoch_time, uint32_t dev_addr, uint16_t ping_period, uint8_t stack_id ); diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_defs.h b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_defs.h index 37bf426..1f1fb32 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_defs.h +++ b/lbm_lib/smtc_modem_core/lr1mac/src/lr1mac_defs.h @@ -447,7 +447,6 @@ typedef struct smtc_ping_slot_parameters_e uint16_t ping_period; // Period of the end-device receiver wake-up expressed in number of slots: uint8_t ping_number; // Number of ping slot in a beacon window uint32_t ping_offset_time; - uint32_t ping_offset_time_100us; } smtc_ping_slot_parameters_t; typedef struct lr1mac_rx_session_param_s diff --git a/lbm_lib/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c b/lbm_lib/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c index 2103d19..a54583a 100644 --- a/lbm_lib/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c +++ b/lbm_lib/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c @@ -1192,8 +1192,12 @@ void smtc_real_decrement_dr( smtc_real_t* real, dr_strategy_t adr_mode_select, u if( *tx_data_rate_adr != smtc_real_get_min_tx_channel_dr( real ) ) { - *tx_data_rate_adr = smtc_real_decrement_dr_simulation( real, *tx_data_rate_adr ); - return; + uint8_t dr_tmp = smtc_real_decrement_dr_simulation( real, *tx_data_rate_adr ); + if( *tx_data_rate_adr != dr_tmp ) + { + *tx_data_rate_adr = dr_tmp; + return; + } } // nb_trans must set to 1 and all default channels re-enabled diff --git a/lbm_lib/smtc_modem_core/modem_services/cloud_dm_package/cloud_dm_package.c b/lbm_lib/smtc_modem_core/modem_services/cloud_dm_package/cloud_dm_package.c index 2705e9a..15a355d 100644 --- a/lbm_lib/smtc_modem_core/modem_services/cloud_dm_package/cloud_dm_package.c +++ b/lbm_lib/smtc_modem_core/modem_services/cloud_dm_package/cloud_dm_package.c @@ -965,18 +965,8 @@ static uint8_t cloud_dm_service_downlink_handler( lr1_stack_mac_down_data_t* rx_ { ctx->lorawan_last_rssi_get = rx_down_data->rx_metadata.rx_rssi; ctx->lorawan_last_snr_get = rx_down_data->rx_metadata.rx_snr; + ctx->last_dl_timestamp_s = rx_down_data->rx_metadata.timestamp_ms / 1000; - uint32_t tmp_timestamp_s = rx_down_data->rx_metadata.timestamp_ms / 1000; - uint32_t rtc_s = smtc_modem_hal_get_time_in_s( ); - - if( rtc_s >= tmp_timestamp_s ) - { - ctx->last_dl_timestamp_s = rtc_s - tmp_timestamp_s; - } - else - { - ctx->last_dl_timestamp_s = ( uint32_t ) ( ~0 ) - tmp_timestamp_s + rtc_s; - } if( rx_down_data->rx_metadata.is_a_join_accept == true ) { // Update flag to know it is the first dm after join that shall be sent next @@ -1454,9 +1444,20 @@ static bool dm_status_payload( cloud_dm_t* ctx, uint8_t stack_id, uint8_t* dm_up } break; case DM_INFO_RXTIME: { - uint32_t time = ( smtc_modem_hal_get_time_in_s( ) - ctx->last_dl_timestamp_s ) / 3600; - *p_tmp = time & 0xFF; - *( p_tmp + 1 ) = time >> 8; + uint32_t time_h = 0; + uint32_t rtc_s = smtc_modem_hal_get_time_in_s( ); + + if( rtc_s >= ctx->last_dl_timestamp_s ) + { + time_h = ( rtc_s - ctx->last_dl_timestamp_s ) / 3600; + } + else + { + time_h = ( uint32_t ) ( ~0UL ) - ctx->last_dl_timestamp_s + rtc_s; + } + + *p_tmp = time_h & 0xFF; + *( p_tmp + 1 ) = time_h >> 8; } break; case DM_INFO_FIRMWARE: { diff --git a/lbm_lib/smtc_modem_core/modem_services/store_and_forward/store_and_forward_flash.h b/lbm_lib/smtc_modem_core/modem_services/store_and_forward/store_and_forward_flash.h index 73b12e6..142fbfa 100644 --- a/lbm_lib/smtc_modem_core/modem_services/store_and_forward/store_and_forward_flash.h +++ b/lbm_lib/smtc_modem_core/modem_services/store_and_forward/store_and_forward_flash.h @@ -114,7 +114,7 @@ store_and_forward_flash_rc_t store_and_forward_flash_set_state( uint8_t store_and_forward_flash_state_t enabled ); /** - * @brief Get the state of the store and foarward service + * @brief Get the state of the store and forward service * * @param [in] stack_id Stack identifier * @return store_and_forward_flash_state_t diff --git a/lbm_lib/smtc_modem_core/modem_utilities/modem_core.c b/lbm_lib/smtc_modem_core/modem_utilities/modem_core.c index 0874d5e..7fbb32a 100644 --- a/lbm_lib/smtc_modem_core/modem_utilities/modem_core.c +++ b/lbm_lib/smtc_modem_core/modem_utilities/modem_core.c @@ -116,6 +116,7 @@ struct uint8_t fifo_buffer[FIFO_LORAWAN_SIZE]; uint8_t ( *downlink_services_callback[NUMBER_OF_SERVICES + NUMBER_OF_LORAWAN_MANAGEMENT_TASKS] )( lr1_stack_mac_down_data_t* rx_down_data ); + uint32_t modem_reset_counter; } modem_ctx_light; #define modem_dwn_pkt modem_ctx_light.modem_dwn_pkt @@ -126,13 +127,8 @@ struct #define fifo_ctrl_obj modem_ctx_light.fifo_ctrl_obj #define fifo_buffer modem_ctx_light.fifo_buffer #define downlink_services_callback modem_ctx_light.downlink_services_callback +#define modem_reset_counter modem_ctx_light.modem_reset_counter -struct -{ - uint32_t modem_reset_counter; -} smtc_modem_ctx; - -#define modem_reset_counter smtc_modem_ctx.modem_reset_counter /* * ----------------------------------------------------------------------------- * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- diff --git a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.c b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.c index 8761c2b..1677305 100644 --- a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.c +++ b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.c @@ -238,8 +238,8 @@ rp_hook_status_t rp_attach_new_radio( radio_planner_t* rp, const ralf_t* radio, SMTC_MODEM_HAL_PANIC( ); return RP_HOOK_STATUS_ID_ERROR; } - if( ( radio == - rp->radio_target_attached_to_this_hook[hook_id] ) ) // radio shall not be the same radio as the initial one + if( radio == + rp->radio_target_attached_to_this_hook[hook_id] ) // radio shall not be the same radio as the initial one { SMTC_MODEM_HAL_PANIC( ); return RP_HOOK_STATUS_ID_ERROR; @@ -388,7 +388,6 @@ rp_hook_status_t rp_task_abort( radio_planner_t* rp, const uint8_t hook_id ) #endif rp->radio_irq_flag = true; // Fake soft IRQ to call user callback - rp->irq_timestamp_100us[rp->radio_task_id] = smtc_modem_hal_get_time_in_100us( ); rp->irq_timestamp_ms[rp->radio_task_id] = smtc_modem_hal_get_time_in_ms( ); smtc_modem_hal_user_lbm_irq( ); } @@ -1211,7 +1210,6 @@ void rp_radio_irq_callback( void* obj ) { radio_planner_t* rp = ( ( radio_planner_t* ) obj ); rp->radio_irq_flag = true; - rp->irq_timestamp_100us[rp->radio_task_id] = smtc_modem_hal_get_time_in_100us( ); rp->irq_timestamp_ms[rp->radio_task_id] = smtc_modem_hal_get_time_in_ms( ); smtc_modem_hal_user_lbm_irq( ); } diff --git a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.h b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.h index 50cc08b..1207b89 100644 --- a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.h +++ b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner.h @@ -72,28 +72,27 @@ extern "C" { */ typedef struct radio_planner_s { - rp_task_t priority_task; - rp_radio_params_t radio_params[RP_NB_HOOKS]; - rp_task_t tasks[RP_NB_HOOKS]; - uint8_t* payload[RP_NB_HOOKS]; - uint16_t rx_payload_size[RP_NB_HOOKS]; - uint16_t payload_buffer_size[RP_NB_HOOKS]; - uint8_t rankings[RP_NB_HOOKS]; - void* hooks[RP_NB_HOOKS]; - rp_status_t status[RP_NB_HOOKS]; - ral_irq_t raw_radio_irq[RP_NB_HOOKS]; - uint32_t irq_timestamp_ms[RP_NB_HOOKS]; - uint32_t irq_timestamp_100us[RP_NB_HOOKS]; - rp_stats_t stats; - uint8_t hook_to_execute; - uint32_t hook_to_execute_time_ms; - uint8_t radio_task_id; - uint32_t timer_value; - uint8_t timer_hook_id; - bool radio_irq_flag; - bool timer_irq_flag; - uint32_t disable_failsafe; - void ( *hook_callbacks[RP_NB_HOOKS] )( void* ); + rp_task_t priority_task; + rp_radio_params_t radio_params[RP_NB_HOOKS]; + rp_task_t tasks[RP_NB_HOOKS]; + uint8_t* payload[RP_NB_HOOKS]; + uint16_t rx_payload_size[RP_NB_HOOKS]; + uint16_t payload_buffer_size[RP_NB_HOOKS]; + uint8_t rankings[RP_NB_HOOKS]; + void* hooks[RP_NB_HOOKS]; + rp_status_t status[RP_NB_HOOKS]; + ral_irq_t raw_radio_irq[RP_NB_HOOKS]; + uint32_t irq_timestamp_ms[RP_NB_HOOKS]; + rp_stats_t stats; + uint8_t hook_to_execute; + uint32_t hook_to_execute_time_ms; + uint8_t radio_task_id; + uint32_t timer_value; + uint8_t timer_hook_id; + bool radio_irq_flag; + bool timer_irq_flag; + uint32_t disable_failsafe; + void ( *hook_callbacks[RP_NB_HOOKS] )( void* ); rp_next_state_status_t next_state_status; const ralf_t* radio; const ralf_t* radio_target_attached_to_this_hook[RP_NB_HOOKS]; diff --git a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner_types.h b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner_types.h index 74196e2..97c77df 100644 --- a/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner_types.h +++ b/lbm_lib/smtc_modem_core/radio_planner/src/radio_planner_types.h @@ -228,7 +228,6 @@ typedef struct rp_task_s rp_task_states_t state; // absolute Ms uint32_t start_time_ms; - uint32_t start_time_100us; // Have to keep the initial start time to be able to switch asap task to // schedule task after long period uint32_t start_time_init_ms; diff --git a/lbm_lib/smtc_modem_hal/smtc_modem_hal.h b/lbm_lib/smtc_modem_hal/smtc_modem_hal.h index f610650..b9a0e76 100644 --- a/lbm_lib/smtc_modem_hal/smtc_modem_hal.h +++ b/lbm_lib/smtc_modem_hal/smtc_modem_hal.h @@ -153,13 +153,13 @@ uint32_t smtc_modem_hal_get_time_in_s( void ); uint32_t smtc_modem_hal_get_time_in_ms( void ); /** - * @brief Returns the current time in 0.1 milliseconds + * @brief set an offset into the rtc ounter * - * @remark Used for class B ping slot openings. + * @remark Used for debug purpose such as wrapping issue. * - * @return uint32_t Current time in 100µs (wraps every 4,9 days) + * @return */ -uint32_t smtc_modem_hal_get_time_in_100us( void ); +void smtc_modem_hal_set_offset_to_test_wrapping( const uint32_t offset_to_test_wrapping ); /* ------------ Timer management ------------*/