diff --git a/CHANGELOG.md b/CHANGELOG.md
index 214ca5c..261ad86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,17 @@ 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).
+## [1.3.0] - 2023-06-12
+
+### changed
+
+- [gnss_middleware] Update to V2.1.0, see [Changelog](geolocation_middleware/CHANGELOG.md).
+- [lora_basics_modem] Update to V2.1.0, see [Changelog](lora_basics_modem/lora_basics_modem/CHANGELOG.md).
+- [geolocation_gnss] Application code update according to geolocation middleware v2.1.0 and LoRa Basics Modem v3.3.0.
+- [geolocation_gnss_wifi] Application code update according to geolocation middleware v2.1.0 and LoRa Basics Modem v3.3.0.
+- [geolocation_wifi] Application code update according to geolocation middleware v2.1.0 and LoRa Basics Modem v3.3.0.
+- [tracker_application] Application code update according to geolocation middleware v2.1.0 and LoRa Basics Modem v3.3.0. see [Changelog](apps/demonstrations/tracker_application/CHANGELOG.md).
+
## [1.2.0] - 2023-01-23
### changed
diff --git a/README.md b/README.md
index b06057a..7af4942 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ Here is the different components changelogs and current version included in this
| Geolocation - Wi-Fi | Perform Wi-Fi scans and send results over LoRaWAN using Wi-Fi middleware | [README](apps/examples/geolocation_wifi/README.md) |
| Geolocation - GNSS & Wi-Fi | Perform GNSS and Wi-Fi scans and send results over LoRaWAN using geolocation middlewares | [README](apps/examples/geolocation_gnss_wifi/README.md) |
| Full almanac update | Perform a full almanac update | [README](apps/examples/full_almanac_update/README.md) |
+| TX/RX continuous | Generate a TX/RX continuous thanks to the test mode | [README](apps/examples/tx_rx_continuous/README.md) |
## Configuration
diff --git a/apps/demonstrations/tracker_application/CHANGELOG.md b/apps/demonstrations/tracker_application/CHANGELOG.md
index 2951723..2641e91 100644
--- a/apps/demonstrations/tracker_application/CHANGELOG.md
+++ b/apps/demonstrations/tracker_application/CHANGELOG.md
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [2.3.0] - 2023-06-12
+
+### Change
+- Application code update according to geolocation middleware v2.1.0. see [Geolocation middleware Changelog](../../../geolocation_middleware/CHANGELOG.md).
+
+### Change
+- Uptate LoRa Basics Modem version from 3.2.4 to 3.3.0
+
## [2.2.0] - 2023-01-23
### Change
diff --git a/apps/demonstrations/tracker_application/MDK-ARM/tracker_application.uvprojx b/apps/demonstrations/tracker_application/MDK-ARM/tracker_application.uvprojx
index 8777d99..b67f4a0 100644
--- a/apps/demonstrations/tracker_application/MDK-ARM/tracker_application.uvprojx
+++ b/apps/demonstrations/tracker_application/MDK-ARM/tracker_application.uvprojx
@@ -1355,11 +1355,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
@@ -2896,11 +2891,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
diff --git a/apps/demonstrations/tracker_application/bin/manifest.json b/apps/demonstrations/tracker_application/bin/manifest.json
index 71b4533..a6c0c23 100644
--- a/apps/demonstrations/tracker_application/bin/manifest.json
+++ b/apps/demonstrations/tracker_application/bin/manifest.json
@@ -1,9 +1,9 @@
{"lr1110_transceiver": {
- "version": "03.07",
- "url": "https://api.github.com/repos/Lora-net/radio_firmware_images/contents/lr1110/transceiver/lr1110_transceiver_0307.h",
- "hash": "638a2630f5b1725fcb78a34ef10467d0"},
+ "version": "03.08",
+ "url": "https://api.github.com/repos/Lora-net/radio_firmware_images/contents/lr1110/transceiver/lr1110_transceiver_0308.h",
+ "hash": "b6528986d0448b56d9282fe3bc0e678e"},
"lbm_app": {
- "version": "2.02.00",
+ "version": "2.03.00",
"url": "https://api.github.com/repos/Lora-net/SWSD004/contents/apps/demonstrations/tracker_application/bin/tracker_application.bin",
- "hash": "e0c17421f67580d853373c76a9fb0986"}
+ "hash": "025107862d0af581f0ea8b26f466eaf4"}
}
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application.bin b/apps/demonstrations/tracker_application/bin/tracker_application.bin
old mode 100644
new mode 100755
index 00dc1d0..792bb19
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application.bin and b/apps/demonstrations/tracker_application/bin/tracker_application.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp1.bin b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp1.bin
old mode 100644
new mode 100755
index 084a5cb..aac9fce
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp1.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp1.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp2.bin b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp2.bin
old mode 100644
new mode 100755
index ef4a907..6bb985e
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp2.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp2.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp3.bin b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp3.bin
old mode 100644
new mode 100755
index 5bcca54..45fd2ba
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp3.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_as923_grp3.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_au915.bin b/apps/demonstrations/tracker_application/bin/tracker_application_au915.bin
old mode 100644
new mode 100755
index 8cf48d5..1e961b7
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_au915.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_au915.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_eu868.bin b/apps/demonstrations/tracker_application/bin/tracker_application_eu868.bin
old mode 100644
new mode 100755
index 00dc1d0..792bb19
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_eu868.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_eu868.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_in865.bin b/apps/demonstrations/tracker_application/bin/tracker_application_in865.bin
old mode 100644
new mode 100755
index e07a3ff..1577223
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_in865.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_in865.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_japan.bin b/apps/demonstrations/tracker_application/bin/tracker_application_japan.bin
old mode 100644
new mode 100755
index d1bf96b..94090cb
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_japan.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_japan.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_kr920.bin b/apps/demonstrations/tracker_application/bin/tracker_application_kr920.bin
old mode 100644
new mode 100755
index 3c28921..8b4f5e5
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_kr920.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_kr920.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_ru864.bin b/apps/demonstrations/tracker_application/bin/tracker_application_ru864.bin
old mode 100644
new mode 100755
index af910c8..24916ac
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_ru864.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_ru864.bin differ
diff --git a/apps/demonstrations/tracker_application/bin/tracker_application_us915.bin b/apps/demonstrations/tracker_application/bin/tracker_application_us915.bin
old mode 100644
new mode 100755
index 4b20323..20c4f9e
Binary files a/apps/demonstrations/tracker_application/bin/tracker_application_us915.bin and b/apps/demonstrations/tracker_application/bin/tracker_application_us915.bin differ
diff --git a/apps/demonstrations/tracker_application/main_tracker_application.c b/apps/demonstrations/tracker_application/main_tracker_application.c
index b5bcb8f..966094c 100644
--- a/apps/demonstrations/tracker_application/main_tracker_application.c
+++ b/apps/demonstrations/tracker_application/main_tracker_application.c
@@ -1130,9 +1130,7 @@ static void on_middleware_gnss_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "GNSS middleware event - TERMINATED\n" );
gnss_mw_get_event_data_terminated( &tracker_ctx.gnss_mw_event_data );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", tracker_ctx.gnss_mw_event_data.nb_scans_sent );
- HAL_DBG_TRACE_PRINTF( "-- aiding position check sent: %d\n",
- tracker_ctx.gnss_mw_event_data.aiding_position_check_sent );
+ gnss_mw_display_terminated_results( &tracker_ctx.gnss_mw_event_data );
ASSERT_SMTC_MODEM_RC( smtc_modem_get_duty_cycle_status( &duty_cycle_status_ms ) );
HAL_DBG_TRACE_PRINTF( "Remaining duty cycle %d ms\n", duty_cycle_status_ms );
@@ -1264,7 +1262,7 @@ static void on_middleware_wifi_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "Wi-Fi middleware event - TERMINATED\n" );
wifi_mw_get_event_data_terminated( &tracker_ctx.wifi_nb_scan_sent );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", tracker_ctx.wifi_nb_scan_sent.nb_scans_sent );
+ wifi_mw_display_terminated_results( &tracker_ctx.wifi_nb_scan_sent );
ASSERT_SMTC_MODEM_RC( smtc_modem_get_duty_cycle_status( &duty_cycle_status_ms ) );
HAL_DBG_TRACE_PRINTF( "Remaining duty cycle %d ms\n", duty_cycle_status_ms );
diff --git a/apps/demonstrations/tracker_application/main_tracker_application.h b/apps/demonstrations/tracker_application/main_tracker_application.h
index 59fea09..2842eab 100644
--- a/apps/demonstrations/tracker_application/main_tracker_application.h
+++ b/apps/demonstrations/tracker_application/main_tracker_application.h
@@ -113,8 +113,8 @@ extern "C" {
* @brief Defines the application firmware version
*/
#define TRACKER_MAJOR_APP_VERSION 2
-#define TRACKER_MINOR_APP_VERSION 2
-#define TRACKER_SUB_MINOR_APP_VERSION 0
+#define TRACKER_MINOR_APP_VERSION 3
+#define TRACKER_SUB_MINOR_APP_VERSION 0
#define TRACKER_PCB_HW_NUMBER 595
#define TRACKER_MAJOR_PCB_HW_VERSION 1
@@ -123,7 +123,7 @@ extern "C" {
/**
* @brief LR11XX radio firmware
*/
-#define LR11XX_FW_VERSION 0x0307
+#define LR11XX_FW_VERSION 0x0308
/*!
* @brief Time during which a LED is turned on when a TX or RX event occurs, in [ms]
diff --git a/apps/demonstrations/tracker_application/makefile/Makefile b/apps/demonstrations/tracker_application/makefile/Makefile
index fcb4033..205c0d3 100644
--- a/apps/demonstrations/tracker_application/makefile/Makefile
+++ b/apps/demonstrations/tracker_application/makefile/Makefile
@@ -72,7 +72,6 @@ C_SOURCES += \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_helpers.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_queue.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_middleware.c \
-$(TOP_DIR)/geolocation_middleware/gnss/src/lr11xx_driver_extension.c \
$(TOP_DIR)/geolocation_middleware/wifi/src/wifi_middleware.c \
$(TOP_DIR)/geolocation_middleware/wifi/src/wifi_helpers.c \
$(TOP_DIR)/geolocation_middleware/common/mw_common.c \
@@ -128,7 +127,7 @@ C_INCLUDES += \
-I$(TOP_DIR)/geolocation_middleware/wifi/src \
-I$(TOP_DIR)/geolocation_middleware/gnss/src \
-I$(TOP_DIR)/geolocation_middleware/bsp \
--I$(TOP_DIR)/geolocation_middleware/common
+-I$(TOP_DIR)/geolocation_middleware/common
# Add the macro debug trace definition
ifeq ($(MIDDLEWARE_TRACE),yes)
diff --git a/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.c b/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.c
index d9feca7..6b1dae3 100644
--- a/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.c
+++ b/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.c
@@ -722,29 +722,50 @@ void tracker_store_gnss_in_internal_log( const gnss_mw_event_data_scan_done_t* g
else
{
uint32_t timestamp = apps_modem_common_get_utc_time( );
- if( tracker_ctx.gnss_antenna_sel == GNSS_PCB_ANTENNA )
+
+ if( gnss_scan_results->aiding_position_check_size != 0 )
{
- scan_buf[index++] = TAG_GNSS_PCB;
+ scan_buf[index++] = TAG_APC_MSG;
+
+ scan_buf[index++] = GNSS_TIMESTAMP_LEN + gnss_scan_results->aiding_position_check_size;
+
+ /* Scan Timestamp */
+ scan_buf[index++] = timestamp;
+ scan_buf[index++] = timestamp >> 8;
+ scan_buf[index++] = timestamp >> 16;
+ scan_buf[index++] = timestamp >> 24;
+
+ memcpy( &scan_buf[index], gnss_scan_results->aiding_position_check_msg,
+ gnss_scan_results->aiding_position_check_size );
+ index += gnss_scan_results->aiding_position_check_size;
}
else
{
- scan_buf[index++] = TAG_GNSS_PATCH;
- }
+ if( tracker_ctx.gnss_antenna_sel == GNSS_PCB_ANTENNA )
+ {
+ scan_buf[index++] = TAG_GNSS_PCB;
+ }
+ else
+ {
+ scan_buf[index++] = TAG_GNSS_PATCH;
+ }
- scan_buf[index++] =
- GNSS_TOKEN_LEN + GNSS_NB_SAT_LEN + GNSS_TIMESTAMP_LEN + GNSS_LAST_SCAN_IN_GROUP_LEN + GNSS_PROFILE_LEN;
- /* Scan Timestamp */
- scan_buf[index++] = timestamp;
- scan_buf[index++] = timestamp >> 8;
- scan_buf[index++] = timestamp >> 16;
- scan_buf[index++] = timestamp >> 24;
- scan_buf[index++] = 0; // Set the token to 0 when no sv detected
- scan_buf[index++] = 0; // 0 SV detected
- scan_buf[index++] = 1; // set a default GNSS mode
- scan_buf[index++] = gnss_scan_results->context.mode;
+ scan_buf[index++] = GNSS_TOKEN_LEN + GNSS_NB_SAT_LEN + GNSS_TIMESTAMP_LEN +
+ GNSS_LAST_SCAN_IN_GROUP_LEN + GNSS_PROFILE_LEN;
+ /* Scan Timestamp */
+ scan_buf[index++] = timestamp;
+ scan_buf[index++] = timestamp >> 8;
+ scan_buf[index++] = timestamp >> 16;
+ scan_buf[index++] = timestamp >> 24;
+ scan_buf[index++] = 0; // Set the token to 0 when no sv detected
+ scan_buf[index++] = 0; // 0 SV detected
+ scan_buf[index++] = 1; // set a default GNSS mode
+ scan_buf[index++] = gnss_scan_results->context.mode;
+ }
nb_variable_elements++;
}
+
tracker_store_internal_log( scan_buf, nb_variable_elements, index );
}
}
@@ -830,6 +851,28 @@ void tracker_restore_internal_log( void )
}
break;
}
+ case TAG_APC_MSG:
+ {
+ /* Scan Timestamp */
+ scan_timestamp = get_uint32_from_array_at_index_and_inc( scan_buf, &scan_buf_index );
+ memcpy( &epoch_time, localtime( &scan_timestamp ), sizeof( struct tm ) );
+
+ uint16_t apc_len = len - GNSS_TIMESTAMP_LEN;
+
+ /* Display Raw NAV Message*/
+ HAL_DBG_TRACE_PRINTF( "[%d-%d-%d %d:%d:%d.000] ", epoch_time.tm_year + 1900, epoch_time.tm_mon + 1,
+ epoch_time.tm_mday, epoch_time.tm_hour, epoch_time.tm_min, epoch_time.tm_sec );
+ HAL_DBG_TRACE_PRINTF( "[%d - %d] ", job_counter, tag_element );
+
+ for( uint8_t i = 0; i < apc_len; i++ )
+ {
+ HAL_DBG_TRACE_PRINTF( "%02X", scan_buf[scan_buf_index++] );
+ }
+
+ HAL_DBG_TRACE_PRINTF( "\n" );
+
+ break;
+ }
case TAG_WIFI:
{
int8_t wifi_rssi;
@@ -2570,6 +2613,8 @@ static void tracker_get_one_scan_from_internal_log( uint16_t scan_number, uint8_
tag_element = scan_buf[scan_buf_index++]; // get the element
len = scan_buf[scan_buf_index++]; // get the size element
+ HAL_DBG_TRACE_PRINTF( "tag_element %d len %d\n", tag_element, len );
+
switch( tag_element )
{
case TAG_GNSS_PATCH:
@@ -2614,6 +2659,33 @@ static void tracker_get_one_scan_from_internal_log( uint16_t scan_number, uint8_
break;
}
+ case TAG_APC_MSG:
+ {
+ HAL_DBG_TRACE_PRINTF( "Restore APC\n" );
+ /* Scan Timestamp */
+ scan_timestamp = get_uint32_from_array_at_index_and_inc( scan_buf, &scan_buf_index );
+ memcpy( &epoch_time, localtime( &scan_timestamp ), sizeof( struct tm ) );
+
+ uint16_t apc_len = len - GNSS_TIMESTAMP_LEN;
+
+ /* Display Raw NAV Message*/
+ *buffer_len += snprintf( ( char* ) ( out_buffer + *buffer_len ), out_buffer_len - *buffer_len,
+ "[%d-%d-%d %d:%d:%d.000] ", epoch_time.tm_year + 1900, epoch_time.tm_mon + 1,
+ epoch_time.tm_mday, epoch_time.tm_hour, epoch_time.tm_min, epoch_time.tm_sec );
+
+ *buffer_len += snprintf( ( char* ) ( out_buffer + *buffer_len ), out_buffer_len - *buffer_len,
+ "[%ld - %d] ", job_counter, tag_element );
+
+ for( uint16_t i = 0; i < apc_len; i++ )
+ {
+ *buffer_len += snprintf( ( char* ) ( out_buffer + *buffer_len ), out_buffer_len - *buffer_len, "%02X",
+ scan_buf[scan_buf_index++] );
+ }
+
+ *buffer_len += snprintf( ( char* ) ( out_buffer + *buffer_len ), out_buffer_len - *buffer_len, "\r\n" );
+
+ break;
+ }
case TAG_WIFI:
{
int8_t wifi_rssi;
diff --git a/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.h b/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.h
index a593e83..6dd2749 100644
--- a/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.h
+++ b/apps/demonstrations/tracker_application/tracker_utility/tracker_utility.h
@@ -64,6 +64,7 @@ extern "C" {
#define TAG_GNSS_PATCH 0x02
#define TAG_WIFI 0x03
#define TAG_NEXT_SCAN 0x04
+#define TAG_APC_MSG 0x05
/* Internal Log Len */
#define WIFI_SINGLE_BEACON_LEN 0x08
diff --git a/apps/examples/full_almanac_update/get_full_almanac.py b/apps/examples/full_almanac_update/get_full_almanac.py
index 75789f9..88e5334 100644
--- a/apps/examples/full_almanac_update/get_full_almanac.py
+++ b/apps/examples/full_almanac_update/get_full_almanac.py
@@ -37,6 +37,10 @@
def main():
+ # The optional GPS timestamp for specific almanac date. The following website
+ # can convert an UTC time to a GPS timestamp: https://www.gw-openscience.org/gps/
+ toa_default = ""
+
# The file in which the almanac will be written to
filename_default = "almanac.h"
parser = ArgumentParser(
@@ -51,14 +55,25 @@ def main():
help="file that will contain the results",
default=filename_default,
)
+ parser.add_argument(
+ "-g",
+ "--gpstime",
+ help="GPS time reference to be used for generating the almanac header (can be omitted to get latest almanac)",
+ default=toa_default,
+ )
args = parser.parse_args()
mgs_token = args.mgs_token
filename = args.output_file
+ toa = args.gpstime
# Build request URL
- url = "https://mgs.loracloud.com/api/v1/almanac/full"
- print("Requesting latest full almanac image available...")
+ if not toa:
+ url = "https://mgs.loracloud.com/api/v1/almanac/full"
+ print("Requesting latest full almanac image available...")
+ else:
+ url = "https://mgs.loracloud.com/api/v1/almanac/full?toa=" + toa
+ print("Requesting full almanac image for GPS time " + toa + "...")
# HTTP request to MGS
my_header = {"Authorization": mgs_token}
@@ -82,6 +97,8 @@ def main():
"/* This file has been auto-generated by the get_full_almanac.py script */\n\n"
)
file_header += '#include "lr11xx_gnss.h"\n\n'
+ if toa:
+ file_header += "/* Almanac image for GPS time " + toa + " */\n"
with open(filename, "w") as f:
f.write(file_header + my_almanac_in_hex + "\n")
diff --git a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_cred_crypto.uvprojx b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_cred_crypto.uvprojx
index 7bea792..0e65d8c 100644
--- a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_cred_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_cred_crypto.uvprojx
@@ -1258,11 +1258,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2596,11 +2591,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3883,11 +3873,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_crypto.uvprojx b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_crypto.uvprojx
index bf8cd16..73dabcb 100644
--- a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_LR_crypto.uvprojx
@@ -1258,11 +1258,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2596,11 +2591,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3883,11 +3873,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -5221,11 +5206,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_soft_crypto.uvprojx b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_soft_crypto.uvprojx
index e824832..61fe5f1 100644
--- a/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_soft_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss/MDK-ARM/lbm_example_geolocation_gnss_soft_crypto.uvprojx
@@ -1268,11 +1268,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2616,11 +2611,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3913,11 +3903,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -5261,11 +5246,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss/main_geolocation_gnss.c b/apps/examples/geolocation_gnss/main_geolocation_gnss.c
index a265056..f61da49 100644
--- a/apps/examples/geolocation_gnss/main_geolocation_gnss.c
+++ b/apps/examples/geolocation_gnss/main_geolocation_gnss.c
@@ -72,9 +72,9 @@
/**
* @brief LR11XX radio firmware
*/
-#define LR1110_FW_VERSION 0x0307
+#define LR1110_FW_VERSION 0x0308
#define LR1110_FW_TYPE 0x01
-#define LR1120_FW_VERSION 0x0101
+#define LR1120_FW_VERSION 0x0102
#define LR1120_FW_TYPE 0x02
/**
@@ -450,10 +450,7 @@ static void on_middleware_gnss_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "GNSS middleware event - TERMINATED\n" );
gnss_mw_get_event_data_terminated( &event_data );
- HAL_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", event_data.nb_scans_sent );
- HAL_DBG_TRACE_PRINTF( "-- aiding position check sent: %d\n", event_data.aiding_position_check_sent );
- HAL_DBG_TRACE_PRINTF( "-- indoor detected: %d\n", event_data.indoor_detected );
+ gnss_mw_display_terminated_results( &event_data );
}
if( gnss_mw_has_event( pending_events, GNSS_MW_EVENT_SCAN_CANCELLED ) )
diff --git a/apps/examples/geolocation_gnss/makefile/Makefile b/apps/examples/geolocation_gnss/makefile/Makefile
index 595ef47..088ba1f 100644
--- a/apps/examples/geolocation_gnss/makefile/Makefile
+++ b/apps/examples/geolocation_gnss/makefile/Makefile
@@ -68,7 +68,6 @@ BUILD_DIR = ./build
C_SOURCES += \
../main_$(APP).c \
$(TOP_DIR)/geolocation_middleware/common/mw_common.c \
-$(TOP_DIR)/geolocation_middleware/gnss/src/lr11xx_driver_extension.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_helpers.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_queue.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_middleware.c \
diff --git a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_cred_crypto.uvprojx b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_cred_crypto.uvprojx
index e263b4a..692f2e8 100644
--- a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_cred_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_cred_crypto.uvprojx
@@ -1258,11 +1258,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2606,11 +2601,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3903,11 +3893,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -5251,11 +5236,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_crypto.uvprojx b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_crypto.uvprojx
index a78dfd5..e054e44 100644
--- a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_LR_crypto.uvprojx
@@ -1258,11 +1258,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2606,11 +2601,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3903,11 +3893,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -5251,11 +5236,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_soft_crypto.uvprojx b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_soft_crypto.uvprojx
index a93e52d..cb66e67 100644
--- a/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_soft_crypto.uvprojx
+++ b/apps/examples/geolocation_gnss_wifi/MDK-ARM/lbm_example_geolocation_gnss_wifi_soft_crypto.uvprojx
@@ -1268,11 +1268,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -2626,11 +2621,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -3933,11 +3923,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
@@ -5291,11 +5276,6 @@
1
..\..\..\..\geolocation_middleware\gnss\src\gnss_queue.c
-
- lr11xx_driver_extension.c
- 1
- ..\..\..\..\geolocation_middleware\gnss\src\lr11xx_driver_extension.c
-
mw_common.c
1
diff --git a/apps/examples/geolocation_gnss_wifi/main_geolocation_gnss_wifi.c b/apps/examples/geolocation_gnss_wifi/main_geolocation_gnss_wifi.c
index 1f1f631..7b70041 100644
--- a/apps/examples/geolocation_gnss_wifi/main_geolocation_gnss_wifi.c
+++ b/apps/examples/geolocation_gnss_wifi/main_geolocation_gnss_wifi.c
@@ -79,9 +79,9 @@
/**
* @brief LR11XX radio firmware
*/
-#define LR1110_FW_VERSION 0x0307
+#define LR1110_FW_VERSION 0x0308
#define LR1110_FW_TYPE 0x01
-#define LR1120_FW_VERSION 0x0101
+#define LR1120_FW_VERSION 0x0102
#define LR1120_FW_TYPE 0x02
/**
@@ -108,6 +108,11 @@
*/
#define APP_TIMER_KEEP_ALIVE ( 30 )
+/**
+ * @brief The delay before a Wi-Fi scan when a DM request is sent
+ */
+#define WIFI_SCAN_DELAY_S ( 60 )
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE TYPES -----------------------------------------------------------
@@ -133,6 +138,11 @@ static ralf_t* modem_radio;
*/
static wifi_mw_event_data_scan_done_t wifi_results;
+/*!
+ * @brief Wi-Fi scan delay after GNSS scan
+ */
+static uint32_t wifi_scan_delay = 0;
+
/*!
* @brief First time sync status for application startup
*/
@@ -459,6 +469,9 @@ static void on_middleware_gnss_event( uint8_t pending_events )
{
uint8_t dm_almanac_status = SMTC_MODEM_DM_FIELD_ALMANAC_STATUS;
ASSERT_SMTC_MODEM_RC( smtc_modem_dm_request_single_uplink( &dm_almanac_status, 1 ) );
+
+ /* Delay next wifi scan to avoid collision with almanac status request */
+ wifi_scan_delay = WIFI_SCAN_DELAY_S;
}
}
@@ -471,10 +484,7 @@ static void on_middleware_gnss_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "GNSS middleware event - TERMINATED\n" );
gnss_mw_get_event_data_terminated( &event_data );
- HAL_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", event_data.nb_scans_sent );
- HAL_DBG_TRACE_PRINTF( "-- aiding position check sent: %d\n", event_data.aiding_position_check_sent );
- HAL_DBG_TRACE_PRINTF( "-- indoor detected: %d\n", event_data.indoor_detected );
+ gnss_mw_display_terminated_results( &event_data );
}
if( gnss_mw_has_event( pending_events, GNSS_MW_EVENT_SCAN_CANCELLED ) )
@@ -486,6 +496,9 @@ static void on_middleware_gnss_event( uint8_t pending_events )
{
HAL_DBG_TRACE_ERROR( "GNSS middleware event - ERROR NO TIME\n" );
ASSERT_SMTC_MODEM_RC( smtc_modem_time_trigger_sync_request( stack_id ) );
+
+ /* Delay next wifi scan to avoid collision with time sync request */
+ wifi_scan_delay = WIFI_SCAN_DELAY_S;
}
if( gnss_mw_has_event( pending_events, GNSS_MW_EVENT_ERROR_ALMANAC_UPDATE ) )
@@ -493,6 +506,9 @@ static void on_middleware_gnss_event( uint8_t pending_events )
HAL_DBG_TRACE_ERROR( "GNSS middleware event - ALMANAC UPDATE REQUIRED\n" );
uint8_t dm_almanac_status = SMTC_MODEM_DM_FIELD_ALMANAC_STATUS;
ASSERT_SMTC_MODEM_RC( smtc_modem_dm_request_single_uplink( &dm_almanac_status, 1 ) );
+
+ /* Delay next wifi scan to avoid collision with almanac status request */
+ wifi_scan_delay = WIFI_SCAN_DELAY_S;
}
if( gnss_mw_has_event( pending_events, GNSS_MW_EVENT_ERROR_NO_AIDING_POSITION ) )
@@ -521,11 +537,12 @@ static void on_middleware_gnss_event( uint8_t pending_events )
gnss_mw_has_event( pending_events, GNSS_MW_EVENT_ERROR_UNKNOWN ) ||
gnss_mw_has_event( pending_events, GNSS_MW_EVENT_SCAN_CANCELLED ) )
{
- wifi_rc = wifi_mw_scan_start( 0 );
+ wifi_rc = wifi_mw_scan_start( wifi_scan_delay );
if( wifi_rc != MW_RC_OK )
{
HAL_DBG_TRACE_ERROR( "Failed to start WiFi scan\n" );
}
+ wifi_scan_delay = 0;
}
gnss_mw_clear_pending_events( );
@@ -552,8 +569,7 @@ static void on_middleware_wifi_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "Wi-Fi middleware event - TERMINATED\n" );
wifi_mw_get_event_data_terminated( &event_data );
- HAL_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", event_data.nb_scans_sent );
+ wifi_mw_display_terminated_results( &event_data );
}
if( wifi_mw_has_event( pending_events, WIFI_MW_EVENT_SCAN_CANCELLED ) )
diff --git a/apps/examples/geolocation_gnss_wifi/makefile/Makefile b/apps/examples/geolocation_gnss_wifi/makefile/Makefile
index a58a7ed..62f54b1 100644
--- a/apps/examples/geolocation_gnss_wifi/makefile/Makefile
+++ b/apps/examples/geolocation_gnss_wifi/makefile/Makefile
@@ -68,7 +68,6 @@ BUILD_DIR = ./build
C_SOURCES += \
../main_$(APP).c \
$(TOP_DIR)/geolocation_middleware/common/mw_common.c \
-$(TOP_DIR)/geolocation_middleware/gnss/src/lr11xx_driver_extension.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_helpers.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_queue.c \
$(TOP_DIR)/geolocation_middleware/gnss/src/gnss_middleware.c \
diff --git a/apps/examples/geolocation_wifi/main_geolocation_wifi.c b/apps/examples/geolocation_wifi/main_geolocation_wifi.c
index d0c2b61..12eddef 100644
--- a/apps/examples/geolocation_wifi/main_geolocation_wifi.c
+++ b/apps/examples/geolocation_wifi/main_geolocation_wifi.c
@@ -73,9 +73,9 @@
/**
* @brief LR11XX radio firmware
*/
-#define LR1110_FW_VERSION 0x0307
+#define LR1110_FW_VERSION 0x0308
#define LR1110_FW_TYPE 0x01
-#define LR1120_FW_VERSION 0x0101
+#define LR1120_FW_VERSION 0x0102
#define LR1120_FW_TYPE 0x02
/*
@@ -324,8 +324,7 @@ static void on_middleware_wifi_event( uint8_t pending_events )
HAL_DBG_TRACE_INFO( "Wi-Fi middleware event - TERMINATED\n" );
wifi_mw_get_event_data_terminated( &event_data );
- HAL_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
- HAL_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", event_data.nb_scans_sent );
+ wifi_mw_display_terminated_results( &event_data );
}
if( wifi_mw_has_event( pending_events, WIFI_MW_EVENT_SCAN_CANCELLED ) )
diff --git a/geolocation_middleware/.clang-format b/geolocation_middleware/.clang-format
new file mode 100644
index 0000000..e259ec1
--- /dev/null
+++ b/geolocation_middleware/.clang-format
@@ -0,0 +1,88 @@
+---
+Language: Cpp
+# BasedOnStyle: Google
+AccessModifierOffset: -1
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: true
+AlignConsecutiveDeclarations: true
+AlignEscapedNewlinesLeft: true
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+ColumnLimit: 120
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeCategories:
+ - Regex: '^<.*\.h>'
+ Priority: 1
+ - Regex: '^<.*'
+ Priority: 2
+ - Regex: '.*'
+ Priority: 3
+IndentCaseLabels: false
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: false
+SpaceAfterCStyleCast: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: Never
+SpaceInEmptyParentheses: true
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: true
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: true
+SpacesInParentheses: true
+SpacesInSquareBrackets: false
+Standard: Auto
+TabWidth: 4
+UseTab: Never
+...
diff --git a/geolocation_middleware/CHANGELOG.md b/geolocation_middleware/CHANGELOG.md
index 0000ba3..4d08975 100644
--- a/geolocation_middleware/CHANGELOG.md
+++ b/geolocation_middleware/CHANGELOG.md
@@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v2.1.0] 2023-06-20
+
+This release comes with the latest release of LR11xx transceiver (LR1110:0x308, LR1110:0x102), which fixes an issue when generating GNSS NAV messages with dopplers enabled but in the mode '7 dopplers max'.
+Now that this issue is fixed, we can enable the dopplers in all modes, to improve aiding position update in general case.
+
+This release also provides few bugfixes as described below, and comes with a minor API changes in the public types for SCAN_DONE and TERMINATED events data.
+
+### Changed
+
+* [gnss_middleware]: Enabled dopplers (7 max) in NAV messages for all scan modes (autonomous, assisted, assisted_for_aiding_position).
+* [gnss_middleware]: Reduced stack memory usage
+* [gnss_middleware]: Changed `gnss_mw_event_data_scan_done_t` to include APC message payload and size. So that those messages can be handled by the use
+application when send_bypass mode is selected.
+* [gnss_middleware]: Moved `indoor_detected` status from `gnss_mw_event_data_terminated_t` to `gnss_mw_event_data_scan_done_t`, as it relates to a scan status.
+* [gnss_middleware]: Bugfix: Do not send APC messages over the air when send_bypass mode is selected.
+* [gnss_middleware]: Bugfix: In function `smtc_gnss_get_doppler_error()`, doppler error is not computed if there is no space vehicles (among detected ones) with almanac age 0 at all.
+* [gnss_middleware]: Removed lr11xx_driver_extension.h/c files as functions have been released with the LR11xx driver coming with LBM release v3.3.x.
+* [gnss_middleware]: Almanacs are considered to be updated when age is greater or equal to 6 months for GPS and 8 months for Beidou.
+* [gnss_middleware]: Added a new API function to print TERMINATED event info: `gnss_mw_display_terminated_results()`.
+* [wifi_middleware]: Reduced stack memory usage
+* [wifi_middleware]: Added a new API function to print TERMINATED event info: `wifi_mw_display_terminated_results()`.
+
## [v2.0.0] 2023-01-20
This release comes along with the new `GNSS NAV-Group Protocol Specification` from LoRaCloud `Modem and Geolocation Services`, and aims to simplify end-to-end integration by removing the need for an Application Server to handle the GNSS middleware logic.
diff --git a/geolocation_middleware/doc/geolocationMiddleware.rst b/geolocation_middleware/doc/geolocationMiddleware.rst
index a181e9d..d2496d9 100644
--- a/geolocation_middleware/doc/geolocationMiddleware.rst
+++ b/geolocation_middleware/doc/geolocationMiddleware.rst
@@ -39,13 +39,13 @@ The user application just has to program when the next scan needs to be launched
GNSS middleware
---------------
+The GNSS middleware implements the `LoRa Edge GNSS-NG (NAV-Group) positioning protocol `_ specified by LoRaCloud.
+
.. _GNSS scan group:
Scan group (GNSS Nav-Group)
+++++++++++++++++++++++++++
-------- TODO: add link to GNSS Nav-Group description of LoRaCloud --------
-
In order to get the best accuracy from GNSS scan results, it is recommended to use the **multiframe** feature of the solver.
In this context, a scan group is a group of scan results (NAV messages) to be used together to solve a position.
@@ -126,7 +126,7 @@ Internal choices
In order to reach an acceptable trade-off for performances, power consumption and simplicity, some parameters have been set in the middleware, and are not configurable from the API.
* A maximum of 10 Space Vehicles detected per NAV message: allow good accuracy while still being able to transmit a complete NAV message in 1 uplink (49 bytes when dopplers are enabled).
-* LR1110 scan parameters: dopplers are enabled only for autonomous scans or for aiding position update scans, so that the doppler solver can be used to get an assistance position update from LoRaCloud.
+* LR1110 scan parameters: dopplers are always enabled in NAV messages, to maximize the chances to to get an assistance position update from LoRaCloud, using the doppler solver.
* A scan group is valid as soon as there is a valid scan in the group (with a valid NAV message).
Some clarification about what is a valid scan group, a valid scan or a valid NAV message:
@@ -192,7 +192,7 @@ There are some prerequisites necessary to have a functional GNSS scan, and to ge
* **time**: a valid time must be provided (ALC Sync, network clock sync...). The Modem clock sync feature from LBM is used.
* **almanac**: the Almanac written in the LR11xx flash memory must be as up-to-date as possible. It can either be be fully updated at once, or incrementally updated through LoRaCloud Modem & Geolocation Services. The Modem almanac update feature from LBM is used.
-* **assistance position**: an assistance position must be provided to the middleware, either as a user defined assistance position, or by forwarding the downlink coming from the solver.
+* **assistance position**: an assistance position must be provided to the middleware, either as a user defined assistance position, or by forwarding downlinks coming from LoRaCloud.
* **downlinks**: downlinks received by the user application on the port used by GNSS middleware should be transmitted to the middleware using the ``gnss_mw_handle_downlink()`` API function. It is important in order to receive an aiding position update from LoRaCloud.
.. _GNSS scan results payload format:
@@ -211,12 +211,12 @@ The format is the following:
+---------------------+--------+------------------+--------------------+
| scan group last NAV | RFU | scan group token | NAV message |
+=====================+========+==================+====================+
- | 1 bit | 2 bits | 5 bits | 36 or 47 bytes max |
+ | 1 bit | 2 bits | 5 bits | 47 bytes max |
+---------------------+--------+------------------+--------------------+
* scan group last NAV: indicates that this scan is the last of a scan group.
* scan group token: it is the identifier of the current scan group. It is used to group the NAV message which should be used as a multiframe solving request.
-* NAV message: it is the GNSS scan result returned by the LR11xx radio. The actual size depends on the number of Space Vehicle detected by the scan, and if dopplers are enabled or not. For assisted scans, the maximum size is 49 bytes if dopplers are enabled, and 36 bytes otherwise.
+* NAV message: it is the GNSS scan result returned by the LR11xx radio. The actual size depends on the number of Space Vehicle detected by the scan.
The maximum size of the complete payload has been kept under 51 bytes to match with the maximum payload size allowed by the LoRaWAN Regional Parameters for most regions (there are few exceptions like DR0 of the US915 region which therefore cannot be used).
@@ -225,7 +225,7 @@ The maximum size of the complete payload has been kept under 51 bytes to match w
Aiding Position Check (APC) payload format
++++++++++++++++++++++++++++++++++++++++++
-When a scan group completes with no NAV message generated, the middleware will try to check if it is because the device is indoor (with an autonomous scan), or maybe because the current assistance position is too wrong to allow the assisted scan to detect anything.
+When a scan group completes with no NAV message generated, the middleware will try to check if it is because the device is indoor (with an autonomous scan), or because the current assistance position is too wrong to allow the assisted scan to detect anything.
If it is not indoor, the middleware will send an Aiding Position Check (APC) message to LoRaCloud, to allow LoRaCloud to compare the current aiding position configured in the end-device, with any history or context it may have to check (Wi-Fi fix, network position...).
There are 2 possible formats for APC messages:
@@ -264,7 +264,7 @@ The best performances for GNSS geolocation is achieved by using the "assisted sc
There are 2 ways to provide this assistance position:
* an assistance position is given by the user at application startup.
-* no assistance position is given by the user, so the middleware starts with an "autonomous scan" and rely on the solver and the application server to return an assistance position with an applicative downlink based on the autonomous can result.
+* no assistance position is given by the user, so the middleware starts with an "autonomous scan" and rely on the solver and the application server to return an assistance position with an applicative downlink based on the autonomous scan result.
Note: When using autonomous scan, the sensitivity is not optimal. A better sky view is required to detect Space Vehicles compared to assisted scan.
So it is recommended, if possible, to set an assistance position (as accurate as possible) at startup.
@@ -324,7 +324,7 @@ Refer to the ``gnss/src/gnss_middleware.h`` file.
Wi-Fi middleware
----------------
-The Wi-Fi middleware implements the `LoRa Edge Wi-Fi positioning protocol` specified by LoRaCloud.
+The Wi-Fi middleware implements the `LoRa Edge Wi-Fi positioning protocol `_ specified by LoRaCloud.
Contrary to the GNSS middleware, there is no scan group concept in the Wi-Fi middleware, and no multiframe solving.
A Wi-Fi scan will simply return the list of Access Points MAC address that have been detected (and optionally RSSI), and will be sent to the solver within one uplink message.
@@ -410,8 +410,6 @@ Scan results payload format
The format of the payload is described by the `LoRa Edge Wi-Fi positioning protocol` of LoRaCloud.
-https://www.loracloud.com/documentation/modem_services?url=mdmsvc.html#lr1110-wifi-positioning-protocol
-
There are 2 formats possible, that the user can choose:
* `WIFI_MW_PAYLOAD_MAC`: contains only the MAC addresses of the detected Access Points
diff --git a/geolocation_middleware/gnss/src/gnss_helpers.c b/geolocation_middleware/gnss/src/gnss_helpers.c
index e6e0359..b6ee9f5 100644
--- a/geolocation_middleware/gnss/src/gnss_helpers.c
+++ b/geolocation_middleware/gnss/src/gnss_helpers.c
@@ -51,8 +51,6 @@
#include "lr11xx_system.h"
#include "lr11xx_gnss.h"
-#include "lr11xx_driver_extension.h"
-
/*
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
@@ -92,16 +90,52 @@
* --- PRIVATE CONSTANTS -------------------------------------------------------
*/
+/**
+ * @brief The maximum number of visible satellite for 1 constellation
+ */
+#define GNSS_NB_VISIBLE_SVS_PER_CONSTELLATION_MAX ( 12 )
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE TYPES -----------------------------------------------------------
*/
+/**
+ * @brief Doppler offset between detected and visible satellite
+ */
+typedef struct doppler_offset_s
+{
+ lr11xx_gnss_satellite_id_t satellite_id; //!< SV ID
+ int16_t doppler_offset; //!< SV doppler offset in Hz
+ int16_t doppler_error; //!< SV doppler error - step of 125Hz (almanac age)
+} doppler_offset_t;
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE VARIABLES -------------------------------------------------------
*/
+/**
+ * @brief Array to store current visible satellites for GPS constellation
+ */
+static lr11xx_gnss_visible_satellite_t visible_svs_gps[GNSS_NB_VISIBLE_SVS_PER_CONSTELLATION_MAX];
+
+/**
+ * @brief Array to store current visible satellites for BEIDOU constellation
+ */
+static lr11xx_gnss_visible_satellite_t visible_svs_beidou[GNSS_NB_VISIBLE_SVS_PER_CONSTELLATION_MAX];
+
+/**
+ * @brief Offsets of doppler between theoretical visible satellites and detected satellites
+ */
+static doppler_offset_t doppler_offsets[GNSS_NB_SVS_MAX];
+
+/**
+ * @brief Offsets storage for median calculation
+ */
+static int doppler_offsets_for_median_size;
+static int doppler_offsets_for_median[GNSS_NB_SVS_MAX];
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
@@ -299,29 +333,24 @@ smtc_gnss_get_results_return_code_t smtc_gnss_get_results( const void* radio_con
const lr11xx_gnss_message_host_status_t status_code_raw = ( lr11xx_gnss_message_host_status_t ) results[1];
switch( status_code_raw )
{
- case LR11XX_GNSS_HOST_NO_TIME:
- {
+ case LR11XX_GNSS_HOST_NO_TIME: {
MW_DBG_TRACE_ERROR( "GNSS error: NO TIME\n" );
return SMTC_GNSS_GET_RESULTS_ERROR_NO_TIME;
}
- case LR11XX_GNSS_HOST_NO_SATELLITE_DETECTED:
- {
+ case LR11XX_GNSS_HOST_NO_SATELLITE_DETECTED: {
MW_DBG_TRACE_INFO( "GNSS error: NO SATELLITE\n" );
*no_sv_detected = true;
return SMTC_GNSS_GET_RESULTS_NO_ERROR; /* not an error */
}
- case LR11XX_GNSS_HOST_ALMANAC_IN_FLASH_TOO_OLD:
- {
+ case LR11XX_GNSS_HOST_ALMANAC_IN_FLASH_TOO_OLD: {
MW_DBG_TRACE_ERROR( "GNSS error: ALMANAC TOO OLD\n" );
return SMTC_GNSS_GET_RESULTS_ERROR_ALMANAC;
}
- case LR11XX_GNSS_HOST_NOT_ENOUGH_SV_DETECTED_TO_BUILD_A_NAV_MESSAGE:
- {
+ case LR11XX_GNSS_HOST_NOT_ENOUGH_SV_DETECTED_TO_BUILD_A_NAV_MESSAGE: {
MW_DBG_TRACE_INFO( "GNSS error: NOT ENOUGH SVs TO BUILD A NAV MESSAGE\n" );
return SMTC_GNSS_GET_RESULTS_NO_ERROR; /* not an error */
}
- default:
- {
+ default: {
MW_DBG_TRACE_ERROR( "GNSS error: UNKNOWN ERROR CODE: 0x%02X\n", status_code_raw );
return SMTC_GNSS_GET_RESULTS_ERROR_UNKNOWN;
}
@@ -393,11 +422,13 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
const lr11xx_gnss_constellation_mask_t constellations,
bool* almanacs_update_required )
{
- lr11xx_status_t status;
- uint8_t nb_visible_gps_satellites, nb_visible_beidou_satellites;
- lr11xx_gnss_visible_satellite_t visible_gps[12];
- lr11xx_gnss_visible_satellite_t visible_beidou[12];
- uint8_t nb_almanac_old = 0;
+ lr11xx_status_t status;
+ uint8_t nb_visible_gps_satellites = 0, nb_visible_beidou_satellites = 0;
+ uint8_t nb_almanac_old = 0;
+
+ /* Initialize work variables */
+ memset( visible_svs_gps, 0, sizeof visible_svs_gps );
+ memset( visible_svs_beidou, 0, sizeof visible_svs_beidou );
/* Initialize output status */
*almanacs_update_required = false;
@@ -413,26 +444,29 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
return false;
}
- status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_gps_satellites, visible_gps );
+ status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_gps_satellites, visible_svs_gps );
if( status != LR11XX_STATUS_OK )
{
MW_DBG_TRACE_ERROR( "Failed to get visible GPS satellites info\n" );
return false;
}
+ /* Debug prints */
+#if GNSS_HELPERS_DBG_TRACE == GNSS_HELPERS_FEATURE_ON
GNSS_HELPERS_TRACE_PRINTF( "\nVisible GPS satellites: %u\n", nb_visible_gps_satellites );
GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
- for( int i = 0; i < nb_visible_gps_satellites; i++ )
+ for( uint8_t i = 0; i < nb_visible_gps_satellites; i++ )
{
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_gps[i].satellite_id, visible_gps[i].doppler,
- visible_gps[i].doppler_error );
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_svs_gps[i].satellite_id,
+ visible_svs_gps[i].doppler, visible_svs_gps[i].doppler_error );
}
+#endif
/* Get the ratio of visible GPS SVs which have almanacs up-to-date */
- for( int i = 0; i < nb_visible_gps_satellites; i++ )
+ for( uint8_t i = 0; i < nb_visible_gps_satellites; i++ )
{
- if( visible_gps[i].doppler_error > 250 ) /* almanac age more than 6 months old (125Hz = 3months) */
+ if( visible_svs_gps[i].doppler_error >= 250 ) /* almanac age more than 6 months old (125Hz = 3months) */
{
nb_almanac_old += 1;
}
@@ -450,26 +484,29 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
return false;
}
- status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_beidou_satellites, visible_beidou );
+ status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_beidou_satellites, visible_svs_beidou );
if( status != LR11XX_STATUS_OK )
{
MW_DBG_TRACE_ERROR( "Failed to get visible BEIDOU satellites info\n" );
return false;
}
+ /* Debug prints */
+#if GNSS_HELPERS_DBG_TRACE == GNSS_HELPERS_FEATURE_ON
GNSS_HELPERS_TRACE_PRINTF( "\nVisible BEIDOU satellites: %u\n", nb_visible_beidou_satellites );
GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
- for( int i = 0; i < nb_visible_beidou_satellites; i++ )
+ for( uint8_t i = 0; i < nb_visible_beidou_satellites; i++ )
{
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_beidou[i].satellite_id,
- visible_beidou[i].doppler, visible_beidou[i].doppler_error );
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_svs_beidou[i].satellite_id,
+ visible_svs_beidou[i].doppler, visible_svs_beidou[i].doppler_error );
}
+#endif
/* Get the ratio of visible BEIDOU SVs which have almanacs up-to-date */
- for( int i = 0; i < nb_visible_beidou_satellites; i++ )
+ for( uint8_t i = 0; i < nb_visible_beidou_satellites; i++ )
{
- if( visible_beidou[i].doppler_error > 250 ) /* almanac age more than 8 months old (125Hz = 4months) */
+ if( visible_svs_beidou[i].doppler_error >= 250 ) /* almanac age more than 8 months old (125Hz = 4months) */
{
nb_almanac_old += 1;
}
@@ -477,18 +514,23 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
}
/* Percentage of almanac updated among visible SVs */
- uint16_t almanacs_updated_status =
- 100 - ( nb_almanac_old * 100 / ( nb_visible_gps_satellites + nb_visible_beidou_satellites ) );
+ uint16_t almanacs_updated_status;
+ if( ( nb_visible_gps_satellites == 0 ) && ( nb_visible_beidou_satellites == 0 ) )
+ {
+ MW_DBG_TRACE_ERROR( "no visible satellites for GPS and Beidou, should not happen\n" );
+ return false;
+ }
+ else
+ {
+ almanacs_updated_status =
+ 100 - ( nb_almanac_old * 100 / ( nb_visible_gps_satellites + nb_visible_beidou_satellites ) );
+ }
/* at least 70% of visible SVs with up-to-date almanacs are necessary to trust doppler error detection */
if( almanacs_updated_status < 70 )
{
*almanacs_update_required = true;
}
- else
- {
- *almanacs_update_required = false;
- }
GNSS_HELPERS_TRACE_PRINTF( "Almanac update status: %u%% (update_required:%d)\n", almanacs_updated_status,
*almanacs_update_required );
@@ -496,32 +538,20 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
return true;
}
-bool smtc_gnss_get_doppler_error_from_nav( const uint8_t* nav )
-{
- uint8_t bit = GETBIT( nav[0], 4 );
- return ( bool ) bit;
-}
-
bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date,
const lr11xx_gnss_solver_assistance_position_t* assistance_position,
const lr11xx_gnss_constellation_mask_t constellations, const uint8_t nb_detected_sv,
const lr11xx_gnss_detected_satellite_t* detected_sv_info, bool* doppler_error )
{
- lr11xx_status_t status;
- uint8_t nb_visible_gps_satellites, nb_visible_beidou_satellites;
- lr11xx_gnss_visible_satellite_t visible_gps[12];
- lr11xx_gnss_visible_satellite_t visible_beidou[12];
-
- typedef struct doppler_offset_s
- {
- lr11xx_gnss_satellite_id_t id;
- int16_t doppler_offset;
- int16_t almanac_age;
- } doppler_offset_t;
- doppler_offset_t doppler_offsets[GNSS_NB_SVS_MAX] = { 0 }; /* doppler offsets of detected SVs */
+ lr11xx_status_t status;
+ uint8_t nb_visible_gps_satellites, nb_visible_beidou_satellites;
- int doppler_offsets_for_median_size = 0;
- int doppler_offsets_for_median[GNSS_NB_SVS_MAX] = { 0 };
+ /* Initialize work variables */
+ doppler_offsets_for_median_size = 0;
+ memset( doppler_offsets_for_median, 0, sizeof doppler_offsets_for_median );
+ memset( doppler_offsets, 0, sizeof doppler_offsets );
+ memset( visible_svs_gps, 0, sizeof visible_svs_gps );
+ memset( visible_svs_beidou, 0, sizeof visible_svs_beidou );
/* Initialize output status */
*doppler_error = false;
@@ -540,7 +570,7 @@ bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date
return false;
}
- status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_gps_satellites, visible_gps );
+ status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_gps_satellites, visible_svs_gps );
if( status != LR11XX_STATUS_OK )
{
MW_DBG_TRACE_ERROR( "Failed to get visible GPS satellites info\n" );
@@ -559,7 +589,7 @@ bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date
return false;
}
- status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_beidou_satellites, visible_beidou );
+ status = lr11xx_gnss_get_visible_satellites( radio_context, nb_visible_beidou_satellites, visible_svs_beidou );
if( status != LR11XX_STATUS_OK )
{
MW_DBG_TRACE_ERROR( "Failed to get visible BEIDOU satellites info\n" );
@@ -568,21 +598,21 @@ bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date
}
/* Compute the offset between the detected doppler and the theoretical doppler of visible SVs */
- for( int j = 0; j < nb_detected_sv; j++ )
+ for( uint8_t j = 0; j < nb_detected_sv; j++ )
{
/* GPS satellites */
if( constellations & LR11XX_GNSS_GPS_MASK )
{
- for( int k = 0; k < nb_visible_gps_satellites; k++ )
+ for( uint8_t k = 0; k < nb_visible_gps_satellites; k++ )
{
- if( detected_sv_info[j].satellite_id == visible_gps[k].satellite_id )
+ if( detected_sv_info[j].satellite_id == visible_svs_gps[k].satellite_id )
{
- doppler_offsets[j].id = detected_sv_info[j].satellite_id;
- doppler_offsets[j].doppler_offset = detected_sv_info[j].doppler - visible_gps[k].doppler;
- doppler_offsets[j].almanac_age = visible_gps[k].doppler_error;
+ doppler_offsets[j].satellite_id = detected_sv_info[j].satellite_id;
+ doppler_offsets[j].doppler_offset = detected_sv_info[j].doppler - visible_svs_gps[k].doppler;
+ doppler_offsets[j].doppler_error = visible_svs_gps[k].doppler_error;
/* Add doppler_offset to median calculation, if almanac is up-to-date */
- if( doppler_offsets[j].almanac_age == 0 )
+ if( doppler_offsets[j].doppler_error == 0 )
{
doppler_offsets_for_median[doppler_offsets_for_median_size] =
( int ) doppler_offsets[j].doppler_offset;
@@ -594,16 +624,16 @@ bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date
/* BEIDOU satellites */
if( constellations & LR11XX_GNSS_BEIDOU_MASK )
{
- for( int k = 0; k < nb_visible_beidou_satellites; k++ )
+ for( uint8_t k = 0; k < nb_visible_beidou_satellites; k++ )
{
- if( detected_sv_info[j].satellite_id == visible_beidou[k].satellite_id )
+ if( detected_sv_info[j].satellite_id == visible_svs_beidou[k].satellite_id )
{
- doppler_offsets[j].id = detected_sv_info[j].satellite_id;
- doppler_offsets[j].doppler_offset = detected_sv_info[j].doppler - visible_beidou[k].doppler;
- doppler_offsets[j].almanac_age = visible_beidou[k].doppler_error;
+ doppler_offsets[j].satellite_id = detected_sv_info[j].satellite_id;
+ doppler_offsets[j].doppler_offset = detected_sv_info[j].doppler - visible_svs_beidou[k].doppler;
+ doppler_offsets[j].doppler_error = visible_svs_beidou[k].doppler_error;
/* Add doppler_offset to median calculation, if almanac is up-to-date */
- if( doppler_offsets[j].almanac_age == 0 )
+ if( doppler_offsets[j].doppler_error == 0 )
{
doppler_offsets_for_median[doppler_offsets_for_median_size] =
( int ) doppler_offsets[j].doppler_offset;
@@ -614,104 +644,114 @@ bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date
}
}
- /* Compute the median doppler offset of SVs with updated almanacs */
- int median_offset = median( doppler_offsets_for_median_size, doppler_offsets_for_median );
-
- /* Debug prints: TODO: add flag to disable/enable */
- GNSS_HELPERS_TRACE_PRINTF( "\nDetected satellites: %u\n", nb_detected_sv );
- GNSS_HELPERS_TRACE_PRINTF( "id | doppler | cnr\n" );
- GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
- for( int i = 0; i < nb_detected_sv; i++ )
+ if( doppler_offsets_for_median_size > 0 )
{
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", detected_sv_info[i].satellite_id,
- detected_sv_info[i].doppler, detected_sv_info[i].cnr );
- }
+ /* Compute the median doppler offset of SVs with updated almanacs */
+ int median_offset = median( doppler_offsets_for_median_size, doppler_offsets_for_median );
- if( constellations & LR11XX_GNSS_GPS_MASK )
- {
- GNSS_HELPERS_TRACE_PRINTF( "\nVisible GPS satellites: %u\n", nb_visible_gps_satellites );
- GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
+ /* Debug prints */
+#if GNSS_HELPERS_DBG_TRACE == GNSS_HELPERS_FEATURE_ON
+ GNSS_HELPERS_TRACE_PRINTF( "\nDetected satellites: %u\n", nb_detected_sv );
+ GNSS_HELPERS_TRACE_PRINTF( "id | doppler | cnr\n" );
GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
- for( int i = 0; i < nb_visible_gps_satellites; i++ )
+ for( uint8_t i = 0; i < nb_detected_sv; i++ )
{
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_gps[i].satellite_id, visible_gps[i].doppler,
- visible_gps[i].doppler_error );
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", detected_sv_info[i].satellite_id,
+ detected_sv_info[i].doppler, detected_sv_info[i].cnr );
}
- }
- if( constellations & LR11XX_GNSS_BEIDOU_MASK )
- {
- GNSS_HELPERS_TRACE_PRINTF( "\nVisible BEIDOU satellites: %u\n", nb_visible_beidou_satellites );
- GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
- GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
- for( int i = 0; i < nb_visible_beidou_satellites; i++ )
+ if( constellations & LR11XX_GNSS_GPS_MASK )
{
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_beidou[i].satellite_id,
- visible_beidou[i].doppler, visible_beidou[i].doppler_error );
+ GNSS_HELPERS_TRACE_PRINTF( "\nVisible GPS satellites: %u\n", nb_visible_gps_satellites );
+ GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
+ GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
+ for( uint8_t i = 0; i < nb_visible_gps_satellites; i++ )
+ {
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_svs_gps[i].satellite_id,
+ visible_svs_gps[i].doppler, visible_svs_gps[i].doppler_error );
+ }
}
- }
- /* Get the current frequency search space configuration to determine threshold for acceptable doppler offset */
- lr11xx_gnss_freq_search_space_t freq_search_space;
- int16_t offset_threshold;
- status = lr11xx_gnss_read_freq_search_space( radio_context, &freq_search_space );
- if( status != LR11XX_STATUS_OK )
- {
- MW_DBG_TRACE_ERROR( "Failed to read current freq search space\n" );
- return false;
- }
- switch( freq_search_space )
- {
- case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_250_HZ:
- offset_threshold = 250;
- break;
- case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_500_HZ:
- offset_threshold = 500;
- break;
- case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_1_KHZ:
- offset_threshold = 1000;
- break;
- case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_2_KHZ:
- offset_threshold = 2000;
- break;
- default:
- MW_DBG_TRACE_ERROR( "Unknown freq search space - %d\n", freq_search_space );
- return false;
- }
+ if( constellations & LR11XX_GNSS_BEIDOU_MASK )
+ {
+ GNSS_HELPERS_TRACE_PRINTF( "\nVisible BEIDOU satellites: %u\n", nb_visible_beidou_satellites );
+ GNSS_HELPERS_TRACE_PRINTF( "id | doppler | almanac_age \n" );
+ GNSS_HELPERS_TRACE_PRINTF( "----|------------|--------------\n" );
+ for( uint8_t i = 0; i < nb_visible_beidou_satellites; i++ )
+ {
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d\n", visible_svs_beidou[i].satellite_id,
+ visible_svs_beidou[i].doppler, visible_svs_beidou[i].doppler_error );
+ }
+ }
+#endif
- /* Check if there is at least 1 SV with doppler error (with almanac up-to-date) */
- int16_t offset_from_median;
- bool doppler_error_sv;
- bool doppler_error_ignored;
- GNSS_HELPERS_TRACE_PRINTF( "\nDoppler offsets (median=%d):\n", median_offset );
- GNSS_HELPERS_TRACE_PRINTF( "id | offset | off-median | doppler_err\n" );
- GNSS_HELPERS_TRACE_PRINTF( "----|------------|------------|------------\n" );
- for( int i = 0; i < nb_detected_sv; i++ )
- {
- offset_from_median = ABS( ( int16_t )( doppler_offsets[i].doppler_offset - median_offset ) );
- doppler_error_sv = ( offset_from_median > offset_threshold ) ? true : false;
- doppler_error_ignored = ( doppler_offsets[i].almanac_age > 250 )
- ? true
- : false; /* If almanac is too old for this SV, ignore doppler detected */
- if( doppler_error_ignored == true )
+ /* Get the current frequency search space configuration to determine threshold for acceptable doppler offset */
+ lr11xx_gnss_freq_search_space_t freq_search_space;
+ int16_t offset_threshold;
+ status = lr11xx_gnss_read_freq_search_space( radio_context, &freq_search_space );
+ if( status != LR11XX_STATUS_OK )
+ {
+ MW_DBG_TRACE_ERROR( "Failed to read current freq search space\n" );
+ return false;
+ }
+ switch( freq_search_space )
+ {
+ case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_250_HZ:
+ offset_threshold = 250;
+ break;
+ case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_500_HZ:
+ offset_threshold = 500;
+ break;
+ case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_1_KHZ:
+ offset_threshold = 1000;
+ break;
+ case LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_2_KHZ:
+ offset_threshold = 2000;
+ break;
+ default:
+ MW_DBG_TRACE_ERROR( "Unknown freq search space - %d\n", freq_search_space );
+ return false;
+ }
+
+ /* Check if there is at least 1 SV with doppler error (with almanac up-to-date) */
+ int16_t offset_from_median;
+ bool doppler_error_sv;
+ bool doppler_error_ignored;
+ GNSS_HELPERS_TRACE_PRINTF( "\nDoppler offsets (median=%d):\n", median_offset );
+ GNSS_HELPERS_TRACE_PRINTF( "id | offset | off-median | doppler_err\n" );
+ GNSS_HELPERS_TRACE_PRINTF( "----|------------|------------|------------\n" );
+ for( uint8_t i = 0; i < nb_detected_sv; i++ )
{
- doppler_error_sv = false;
+ offset_from_median = ABS( ( int16_t )( doppler_offsets[i].doppler_offset - median_offset ) );
+ doppler_error_sv = ( offset_from_median > offset_threshold ) ? true : false;
+ doppler_error_ignored = ( doppler_offsets[i].doppler_error > 250 )
+ ? true
+ : false; /* If almanac is too old for this SV, ignore doppler detected */
+ if( doppler_error_ignored == true )
+ {
+ doppler_error_sv = false;
+ }
+ GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d | %d %s\n", doppler_offsets[i].satellite_id,
+ doppler_offsets[i].doppler_offset, offset_from_median, doppler_error_sv,
+ ( doppler_error_ignored == true ) ? "(IGNORED)" : "" );
+
+ if( doppler_error_sv == true )
+ {
+ /* Return doppler error status */
+ *doppler_error = true;
+ /* TODO: break here if don't want to have details for all SVs */
+ }
}
- GNSS_HELPERS_TRACE_PRINTF( "%-3u | %-10d | %-10d | %d %s\n", doppler_offsets[i].id,
- doppler_offsets[i].doppler_offset, offset_from_median, doppler_error_sv,
- ( doppler_error_ignored == true ) ? "(IGNORED)" : "" );
- if( doppler_error_sv == true )
+ if( *doppler_error == true )
{
- /* Return doppler error status */
- *doppler_error = true;
- /* TODO: break here if don't want to have details for all SVs */
+ MW_DBG_TRACE_WARNING( "Doppler error detected\n" );
}
}
-
- if( *doppler_error == true )
+ else
{
- MW_DBG_TRACE_WARNING( "Doppler error detected\n" );
+ MW_DBG_TRACE_WARNING( "No almanac up-to-date to check for doppler error\n" );
+ /* TODO: this could be a feedback to application to send an ALMANAC_STATUS DM */
}
return true;
@@ -908,14 +948,15 @@ static int median( int n, int x[] )
{
int temp;
int i, j;
- // the following two loops sort the array x in ascending order
+
+ /* sort the array x in ascending order */
for( i = 0; i < n - 1; i++ )
{
for( j = i + 1; j < n; j++ )
{
if( x[j] < x[i] )
{
- // swap elements
+ /* swap elements */
temp = x[i];
x[i] = x[j];
x[j] = temp;
@@ -925,12 +966,12 @@ static int median( int n, int x[] )
if( n % 2 == 0 )
{
- // if there is an even number of elements, return mean of the two elements in the middle
+ /* if there is an even number of elements, return mean of the two elements in the middle */
return ( ( x[n / 2] + x[n / 2 - 1] ) / 2 );
}
else
{
- // else return the element in the middle
+ /* else return the element in the middle */
return x[n / 2];
}
}
diff --git a/geolocation_middleware/gnss/src/gnss_helpers.h b/geolocation_middleware/gnss/src/gnss_helpers.h
index 6f2fb5d..39ca2bd 100644
--- a/geolocation_middleware/gnss/src/gnss_helpers.h
+++ b/geolocation_middleware/gnss/src/gnss_helpers.h
@@ -167,7 +167,14 @@ bool smtc_gnss_get_sv_info( const void* radio_context, const uint8_t sv_info_max
lr11xx_gnss_detected_satellite_t* sv_info );
/*!
- * @brief TODO
+ * @brief Check almanac update status for visible satellites
+ *
+ * @param [in] radio_context Chip implementation context
+ * @param [in] date Current GPS time
+ * @param [in] assistance_position Current aiding position
+ * @param [in] constellations GNSS constellations to be checked
+ * @param [out] almanacs_update_required Boolean that indicates if at least 70% of visible satellites have their almanac
+ * not too old (less than 6 months for GPS, less that 8 months for Beidou).
*/
bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint32_t date,
const lr11xx_gnss_solver_assistance_position_t* assistance_position,
@@ -175,12 +182,16 @@ bool smtc_gnss_get_almanac_update_status( const void* radio_context, const uint3
bool* almanacs_update_required );
/*!
- * @brief TODO
- */
-bool smtc_gnss_get_doppler_error_from_nav( const uint8_t* nav );
-
-/*!
- * @brief TODO
+ * @brief Compute doppler error on detected satellites to detect aiding position error (to be used only of almanacs are
+ * not too old).
+ *
+ * @param [in] radio_context Chip implementation context
+ * @param [in] date Current GPS time
+ * @param [in] assistance_position Current aiding position
+ * @param [in] constellations GNSS constellations to be checked
+ * @param [in] nb_detected_sv Number of detected satellites
+ * @param [in] detected_sv_info Detected satellites information
+ * @param [out] doppler_error Boolean that indicates if doppler error has been detected.
*/
bool smtc_gnss_get_doppler_error( const void* radio_context, const uint32_t date,
const lr11xx_gnss_solver_assistance_position_t* assistance_position,
diff --git a/geolocation_middleware/gnss/src/gnss_helpers_defs.h b/geolocation_middleware/gnss/src/gnss_helpers_defs.h
index 70d1f1c..5967b86 100644
--- a/geolocation_middleware/gnss/src/gnss_helpers_defs.h
+++ b/geolocation_middleware/gnss/src/gnss_helpers_defs.h
@@ -56,6 +56,8 @@ extern "C" {
/*!
* @brief Maximal number of Space Vehicles to search during a GNSS scan
+ * @note Autonomous scan: NAV2: 10 SV + 7 dopplers => 44 bytes
+ * @note Assisted scan: NAV2: 10 SV + 7 dopplers => 47 bytes
*/
#define GNSS_NB_SVS_MAX ( 10 )
diff --git a/geolocation_middleware/gnss/src/gnss_middleware.c b/geolocation_middleware/gnss/src/gnss_middleware.c
index 7aca013..9e7e61a 100644
--- a/geolocation_middleware/gnss/src/gnss_middleware.c
+++ b/geolocation_middleware/gnss/src/gnss_middleware.c
@@ -118,12 +118,12 @@
#define SMTC_MODEM_EXTENDED_UPLINK_ID_GNSS 1
/**
- * @brief TODO
+ * @brief GNSS latitude scaling factor
*/
#define LR11XX_GNSS_SCALING_LATITUDE 90
/**
- * @brief TODO
+ * @brief GNSS longitude scaling factor
*/
#define LR11XX_GNSS_SCALING_LONGITUDE 180
@@ -154,7 +154,7 @@ typedef struct
} gnss_mw_mode_desc_t;
/**
- * @brief TODO
+ * @brief The list of possible scan types
*/
typedef enum
{
@@ -207,7 +207,7 @@ static bool solver_aiding_position_update_received = false;
static uint8_t solver_aiding_position_update[SOLVER_AIDING_POSITION_SIZE];
/*!
- * @brief TODO
+ * @brief The current scan type selected
*/
static gnss_mw_scan_type_t current_scan_type = GNSS_MW_SCAN_TYPE_AUTONOMOUS;
@@ -253,6 +253,8 @@ static uint8_t lorawan_port = GNSS_DEFAULT_UPLINK_PORT;
*/
static bool scan_aggregate = false;
+static int nb_scan_aggregate = 0;
+
/*!
* @brief Indicates sequence to "scan & send" or "scan only" mode
*/
@@ -276,22 +278,32 @@ static bool task_running = false;
static gnss_mw_scan_context_t lr11xx_scan_context;
/*!
- * @brief TODO
+ * @brief The current Aiding Position Check (APC) message
*/
static uint8_t aid_pos_check_buffer[5 + GNSS_RESULT_SIZE_MAX_MODE3] = { 0 }; /* | TAG | 0x00 | LAT/LON | NAV | */
/*!
- * @brief TODO
+ * @brief The size of the current Aiding Position Check (APC) message
+ */
+static uint8_t aid_pos_check_size;
+
+/*!
+ * @brief Statistics variables
*/
static uint8_t stat_nb_scans_sent_within_current_scan_group = 0;
static bool stat_aiding_position_check_sent = false;
static bool stat_indoor_detected = false;
/*!
- * @brief TODO
+ * @brief Flag to indicate if an autonomous scan for indoor check was launched
*/
static bool autonomous_scan_for_indoor_check = false;
+/*!
+ * @brief GNSS scan results storage
+ */
+static gnss_scan_t scan_results;
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
@@ -307,7 +319,7 @@ static bool autonomous_scan_for_indoor_check = false;
static smtc_modem_return_code_t gnss_mw_scan_next( uint32_t delay_s );
/*!
- * @brief TODO
+ * @brief Get next scan delay
*/
static uint32_t gnss_mw_get_next_scan_delay( void );
@@ -332,11 +344,11 @@ static void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status );
* update if necessary.
*
* @param [in] current_assistance_position The current aiding position configured
+ * @param [in] scan The scan result to be appended with APC message (if any)
*
- * @return a boolean set to true for success, false otherwise
*/
-static bool gnss_mw_send_aiding_position_check_request(
- const lr11xx_gnss_solver_assistance_position_t* current_assistance_position, gnss_scan_t* scan );
+static void gnss_mw_prepare_apc_msg( const lr11xx_gnss_solver_assistance_position_t* current_assistance_position,
+ gnss_scan_t* scan );
/*!
* @brief Callback called by the LBM when the uplink has been sent. Pop the next result ot be sent until the scan group
@@ -454,6 +466,9 @@ mw_return_code_t gnss_mw_scan_start( gnss_mw_mode_t mode, uint32_t start_delay )
stat_aiding_position_check_sent = false;
stat_indoor_detected = false;
+ /* Reset APC message */
+ aid_pos_check_size = 0;
+
/* Switch back to assisted if previous scan was for aiding position request */
if( current_scan_type == GNSS_MW_SCAN_TYPE_ASSISTED_FOR_AIDING_POSITION )
{
@@ -584,6 +599,9 @@ mw_return_code_t gnss_mw_get_event_data_scan_done( gnss_mw_event_data_scan_done_
data->context.aiding_position_longitude = lr11xx_scan_context.aiding_position_longitude;
data->context.almanac_crc = lr11xx_scan_context.almanac_crc;
data->context.almanac_update_required = lr11xx_scan_context.almanac_update_required;
+ data->indoor_detected = stat_indoor_detected;
+ data->aiding_position_check_size = aid_pos_check_size;
+ data->aiding_position_check_msg = aid_pos_check_buffer;
return MW_RC_OK;
}
@@ -610,7 +628,10 @@ void gnss_mw_set_constellations( gnss_mw_constellation_t constellations )
}
}
-void gnss_mw_set_port( uint8_t port ) { lorawan_port = port; }
+void gnss_mw_set_port( uint8_t port )
+{
+ lorawan_port = port;
+}
void gnss_mw_scan_aggregate( bool aggregate )
{
@@ -618,6 +639,11 @@ void gnss_mw_scan_aggregate( bool aggregate )
/* Set scan aggregation current mode */
scan_aggregate = aggregate;
+
+ if( aggregate == false )
+ {
+ nb_scan_aggregate = 0;
+ }
}
void gnss_mw_send_bypass( bool no_send )
@@ -663,6 +689,26 @@ void gnss_mw_display_results( const gnss_mw_event_data_scan_done_t* data )
}
MW_DBG_TRACE_PRINTF( "-- almanac CRC: 0X%08X\n", data->context.almanac_crc );
MW_DBG_TRACE_PRINTF( "-- almanac update required: %d\n", data->context.almanac_update_required );
+ MW_DBG_TRACE_PRINTF( "-- indoor detected: %d\n", data->indoor_detected );
+ if( data->aiding_position_check_size > 0 )
+ {
+ MW_DBG_TRACE_PRINTF( "-- APC (%u): ", data->aiding_position_check_size );
+ for( i = 0; i < data->aiding_position_check_size; i++ )
+ {
+ MW_DBG_TRACE_PRINTF( "%02X", data->aiding_position_check_msg[i] );
+ }
+ MW_DBG_TRACE_PRINTF( "\n" );
+ }
+ }
+}
+
+void gnss_mw_display_terminated_results( const gnss_mw_event_data_terminated_t* data )
+{
+ if( data != NULL )
+ {
+ MW_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
+ MW_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", data->nb_scans_sent );
+ MW_DBG_TRACE_PRINTF( "-- APC message sent: %d\n", data->aiding_position_check_sent );
}
}
@@ -678,7 +724,6 @@ mw_return_code_t gnss_mw_get_event_data_terminated( gnss_mw_event_data_terminate
{
data->nb_scans_sent = stat_nb_scans_sent_within_current_scan_group;
data->aiding_position_check_sent = stat_aiding_position_check_sent;
- data->indoor_detected = stat_indoor_detected;
return MW_RC_OK;
}
else
@@ -688,7 +733,10 @@ mw_return_code_t gnss_mw_get_event_data_terminated( gnss_mw_event_data_terminate
}
}
-void gnss_mw_clear_pending_events( void ) { pending_events = 0; }
+void gnss_mw_clear_pending_events( void )
+{
+ pending_events = 0;
+}
mw_return_code_t gnss_mw_handle_downlink( uint8_t port, const uint8_t* payload, uint8_t size )
{
@@ -834,24 +882,20 @@ static void gnss_mw_scan_rp_task_launch( void* context )
case GNSS_MW_SCAN_TYPE_AUTONOMOUS:
scan_params.assisted = false;
scan_params.freq_search_space = LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_250_HZ; /* not used */
- scan_params.input_parameters = LR11XX_GNSS_RESULTS_DOPPLER_MASK +
- LR11XX_GNSS_RESULTS_DOPPLER_ENABLE_MASK; /* 14 dopplers max, no bit change */
- scan_params.nb_svs_max =
- 9; /* NAV2: 9 SV + 9 dopplers => 44 bytes (reduce nb SV to keep space for APC message)*/
+ scan_params.input_parameters = LR11XX_GNSS_RESULTS_DOPPLER_ENABLE_MASK; /* 7 dopplers max, no bit change */
+ scan_params.nb_svs_max = GNSS_NB_SVS_MAX;
break;
case GNSS_MW_SCAN_TYPE_ASSISTED:
scan_params.assisted = true;
scan_params.freq_search_space = LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_250_HZ;
- scan_params.input_parameters = 0; /* no dopplers, no bit change */
+ scan_params.input_parameters = LR11XX_GNSS_RESULTS_DOPPLER_ENABLE_MASK; /* 7 dopplers max, no bit change */
scan_params.nb_svs_max = GNSS_NB_SVS_MAX;
break;
case GNSS_MW_SCAN_TYPE_ASSISTED_FOR_AIDING_POSITION:
scan_params.assisted = true;
scan_params.freq_search_space = LR11XX_GNSS_FREQUENCY_SEARCH_SPACE_2_KHZ;
- scan_params.input_parameters = LR11XX_GNSS_RESULTS_DOPPLER_MASK +
- LR11XX_GNSS_RESULTS_DOPPLER_ENABLE_MASK; /* 14 dopplers max, no bit change */
- scan_params.nb_svs_max =
- 9; /* NAV2: 9 SV + 9 dopplers => 47 bytes (reduce nb SV to keep payload under 50 bytes) */
+ scan_params.input_parameters = LR11XX_GNSS_RESULTS_DOPPLER_ENABLE_MASK; /* 7 dopplers max, no bit change */
+ scan_params.nb_svs_max = GNSS_NB_SVS_MAX;
break;
default:
break;
@@ -961,7 +1005,6 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
}
else if( irq_status == SMTC_RP_RADIO_GNSS_SCAN_DONE )
{
- gnss_scan_t scan_results = { 0 };
smtc_gnss_get_results_return_code_t scan_results_rc;
bool scan_results_no_sv = false;
bool doppler_error = false;
@@ -972,6 +1015,7 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
current_assistance_position.longitude = lr11xx_scan_context.aiding_position_longitude;
/* Get scan results from LR1110 */
+ memset( &scan_results, 0, sizeof scan_results );
scan_results.timestamp = mw_get_gps_time( );
scan_results_rc =
smtc_gnss_get_results( modem_radio_ctx->ral.context, GNSS_RESULT_SIZE_MAX_MODE3, &scan_results.results_size,
@@ -997,14 +1041,34 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
{
/* If NO SATELLITES has been detected, we consider the device is indoor */
stat_indoor_detected = true;
+ gnss_mw_send_event( GNSS_MW_EVENT_SCAN_DONE );
gnss_mw_send_event( GNSS_MW_EVENT_TERMINATED );
}
else
{
- /* The autonomous scan detected some SVs but not enough to generate a NAV, so send an aiding
- * position check uplink */
- stat_aiding_position_check_sent = true;
- gnss_mw_send_aiding_position_check_request( ¤t_assistance_position, &scan_results );
+ /* Prepare APC message */
+ gnss_mw_prepare_apc_msg( ¤t_assistance_position, &scan_results );
+
+ /* Send an event to application for scan results */
+ gnss_mw_send_event( GNSS_MW_EVENT_SCAN_DONE );
+
+ if( send_bypass == true )
+ {
+ /* Send an event to application to notify for completion */
+ gnss_mw_send_event( GNSS_MW_EVENT_TERMINATED );
+ }
+ else
+ {
+ /* Send uplink */
+ if( gnss_mw_send_frame( aid_pos_check_buffer, aid_pos_check_size, lorawan_port ) == false )
+ {
+ MW_DBG_TRACE_ERROR( "Failed to send uplink for APC frame\n" );
+ }
+ else
+ {
+ stat_aiding_position_check_sent = true;
+ }
+ }
}
}
else
@@ -1024,10 +1088,9 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
if( ( scan_results.detected_svs > 0 ) && ( current_scan_type != GNSS_MW_SCAN_TYPE_AUTONOMOUS ) &&
( lr11xx_scan_context.almanac_update_required == false ) )
{
- smtc_gnss_get_doppler_error(
- modem_radio_ctx->ral.context, lr11xx_scan_context.gps_time, ¤t_assistance_position,
- current_constellations, scan_results.detected_svs, scan_results.info_svs,
- &doppler_error ); /* TODO: need to add constellations to scan context */
+ smtc_gnss_get_doppler_error( modem_radio_ctx->ral.context, lr11xx_scan_context.gps_time,
+ ¤t_assistance_position, current_constellations,
+ scan_results.detected_svs, scan_results.info_svs, &doppler_error );
}
if( ( doppler_error == true ) &&
@@ -1065,8 +1128,27 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
}
else
{
- /* All scans in the group have been completed, send an event to application */
- gnss_mw_send_event( GNSS_MW_EVENT_SCAN_DONE );
+ /* Increment scan group token if valid and not aggregated */
+ if( gnss_scan_group_queue_is_valid( &gnss_scan_group_queue ) )
+ {
+ if( scan_aggregate == false )
+ {
+ gnss_scan_group_queue_increment_token( &gnss_scan_group_queue );
+ }
+ else
+ {
+ /* Increment token for the first group of the aggregated groups */
+ if( nb_scan_aggregate == 0 )
+ {
+ gnss_scan_group_queue_increment_token( &gnss_scan_group_queue );
+ nb_scan_aggregate += 1;
+ }
+ }
+ }
+ else
+ {
+ MW_DBG_TRACE_PRINTF( "Scan group is not valid, do not increment token\n" );
+ }
/* Send results */
/* static variables because there is no copy done by LBM for extended send API */
@@ -1081,11 +1163,12 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
* position check */
autonomous_scan_for_indoor_check = true;
MW_ASSERT_SMTC_MODEM_RC( gnss_mw_scan_next( 0 ) );
- /* TODO: if current scan was an autonomous one, we could avoid this last one for indoor
- * check */
}
else
{
+ /* All scans in the group have been completed, send an event to application */
+ gnss_mw_send_event( GNSS_MW_EVENT_SCAN_DONE );
+
/* Check if "no send "mode" is configured */
if( send_bypass == true )
{
@@ -1152,14 +1235,14 @@ void gnss_mw_scan_rp_task_done( smtc_modem_rp_status_t* status )
mw_radio_set_sleep( modem_radio_ctx->ral.context );
}
-static bool gnss_mw_send_aiding_position_check_request(
- const lr11xx_gnss_solver_assistance_position_t* current_assistance_position, gnss_scan_t* scan )
+static void gnss_mw_prepare_apc_msg( const lr11xx_gnss_solver_assistance_position_t* current_assistance_position,
+ gnss_scan_t* scan )
{
- bool success = false;
const int16_t latitude = ( ( current_assistance_position->latitude * 2048 ) / LR11XX_GNSS_SCALING_LATITUDE );
const int16_t longitude = ( ( current_assistance_position->longitude * 2048 ) / LR11XX_GNSS_SCALING_LONGITUDE );
- /* Prepare buffer for request */
+ /* Prepare buffer for APC message */
+ aid_pos_check_size = 5;
/* | TAG (8b) | 0x00 | LatLSB (8b) | LonLSB (4b) LatMSB (4b) | LonMSB (8b) | */
aid_pos_check_buffer[0] = ( scan->detected_svs > 0 ) ? 0x01 : 0x00; /* TAG */
aid_pos_check_buffer[1] = 0x00; /* Extension marker */
@@ -1175,19 +1258,8 @@ static bool gnss_mw_send_aiding_position_check_request(
/* The number of SV max has been limited for autonomous scan in order to keep the complete buffer below 51 bytes
*/
memcpy( &aid_pos_check_buffer[5], &( scan->results_buffer[GNSS_SCAN_METADATA_SIZE] ), scan->results_size );
+ aid_pos_check_size += scan->results_size;
}
-
- /* Send uplink */
- if( gnss_mw_send_frame( aid_pos_check_buffer, 5 + scan->results_size, lorawan_port ) == true )
- {
- success = true;
- }
- else
- {
- MW_DBG_TRACE_ERROR( "Failed to send aiding position request uplink frame\n" );
- }
-
- return success;
}
static void gnss_mw_tx_done_callback( void )
@@ -1271,15 +1343,6 @@ static void gnss_mw_send_event( gnss_mw_event_type_t event_type )
task_running = false;
}
- /* Increment the token on SCAN_DONE if the scan group is valid (and no aggregate) */
- if( event_type == GNSS_MW_EVENT_SCAN_DONE )
- {
- if( ( scan_aggregate == false ) && ( gnss_scan_group_queue_is_valid( &gnss_scan_group_queue ) ) )
- {
- gnss_scan_group_queue_increment_token( &gnss_scan_group_queue );
- }
- }
-
/* Send the event to the application */
pending_events = pending_events | ( 1 << event_type );
MW_ASSERT_SMTC_MODEM_RC( smtc_modem_increment_event_middleware( SMTC_MODEM_EVENT_MIDDLEWARE_1, pending_events ) );
diff --git a/geolocation_middleware/gnss/src/gnss_middleware.h b/geolocation_middleware/gnss/src/gnss_middleware.h
index 4a5593a..7b143e5 100644
--- a/geolocation_middleware/gnss/src/gnss_middleware.h
+++ b/geolocation_middleware/gnss/src/gnss_middleware.h
@@ -153,6 +153,9 @@ typedef struct
gnss_mw_event_data_scan_desc_t scans[GNSS_SCAN_GROUP_SIZE_MAX]; //!< Descriptions of all scan results
uint32_t power_consumption_uah; //!< Power consumption induced by this scan group
gnss_mw_scan_context_t context; //!< Configuration context used for this scan
+ bool indoor_detected; //!< Indicates if an indoor detection occurred (in case aiding position check was enabled)
+ uint8_t* aiding_position_check_msg; //!< APC message buffer
+ uint8_t aiding_position_check_size; //!< APC message buffer size in bytes
} gnss_mw_event_data_scan_done_t;
/**
@@ -161,8 +164,7 @@ typedef struct
typedef struct
{
uint8_t nb_scans_sent; //!< Number of scans which have been sent over the air
- bool aiding_position_check_sent; //!< Indicates if an aiding position check uplink has been sent
- bool indoor_detected; //!< Indicates if an indoor detection occurred (in case aiding position check was enabled)
+ bool aiding_position_check_sent; //!< Indicates if an APC message has been sent over the air
} gnss_mw_event_data_terminated_t;
/*
@@ -312,6 +314,13 @@ void gnss_mw_send_bypass( bool no_send );
*/
void gnss_mw_display_results( const gnss_mw_event_data_scan_done_t* data );
+/**
+ * @brief Print the results of the GNSS_MW_EVENT_TERMINATED event
+ *
+ * @param [in] data Sequence results to be printed on the console
+ */
+void gnss_mw_display_terminated_results( const gnss_mw_event_data_terminated_t* data );
+
/**
* @brief Parse downlink message, and handle it if it targets the GNSS middleware.
*
diff --git a/geolocation_middleware/gnss/src/gnss_version.h b/geolocation_middleware/gnss/src/gnss_version.h
index 61021ad..8b7b092 100644
--- a/geolocation_middleware/gnss/src/gnss_version.h
+++ b/geolocation_middleware/gnss/src/gnss_version.h
@@ -56,7 +56,7 @@ extern "C" {
* --- PUBLIC TYPES ------------------------------------------------------------
*/
#define GNSS_MW_VERSION_MAJOR 2
-#define GNSS_MW_VERSION_MINOR 0
+#define GNSS_MW_VERSION_MINOR 1
#define GNSS_MW_VERSION_PATCH 0
/*
diff --git a/geolocation_middleware/gnss/src/lr11xx_driver_extension.c b/geolocation_middleware/gnss/src/lr11xx_driver_extension.c
deleted file mode 100644
index baa7689..0000000
--- a/geolocation_middleware/gnss/src/lr11xx_driver_extension.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*!
- * @file lr11xx_driver_extension.c
- *
- * @brief driver extension implementation for LR11XX
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-
-#include "lr11xx_hal.h"
-#include "lr11xx_driver_extension.h"
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE MACROS-----------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE CONSTANTS -------------------------------------------------------
- */
-
-#define LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH ( 2 + 1 )
-#define LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH ( 2 )
-#define LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH ( 2 + 9 )
-#define LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH ( 2 )
-
-#define LR11XX_GNSS_SCALING_LATITUDE 90
-#define LR11XX_GNSS_SCALING_LONGITUDE 180
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE TYPES -----------------------------------------------------------
- */
-
-/*!
- * @brief Operating codes for GNSS-related operations
- */
-enum
-{
- LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC = 0x0404, //!< Set the frequency search space
- LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC = 0x0405, //!< Read the frequency search space
- LR11XX_GNSS_GET_SV_VISIBLE_OC = 0x041F, //!< Get the number of visible SV from a date and a position
- LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC = 0x0420, //!< Get visible SV ID and corresponding doppler value
-};
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE VARIABLES -------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
- */
-
-lr11xx_status_t lr11xx_gnss_set_freq_search_space( const void* radio,
- const lr11xx_gnss_freq_search_space_t freq_search_space )
-{
- const uint8_t cbuffer[LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH] = {
- ( uint8_t )( LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC >> 8 ),
- ( uint8_t )( LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC >> 0 ),
- ( uint8_t ) freq_search_space,
- };
-
- return ( lr11xx_status_t ) lr11xx_hal_write( radio, cbuffer, LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH, 0, 0 );
-}
-
-lr11xx_status_t lr11xx_gnss_read_freq_search_space( const void* radio,
- lr11xx_gnss_freq_search_space_t* freq_search_space )
-{
- const uint8_t cbuffer[LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH] = {
- ( uint8_t )( LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC >> 8 ),
- ( uint8_t )( LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC >> 0 ),
- };
-
- return ( lr11xx_status_t ) lr11xx_hal_read( radio, cbuffer, LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH,
- ( uint8_t* ) freq_search_space, sizeof( uint8_t ) );
-}
-
-lr11xx_status_t lr11xx_gnss_get_nb_visible_satellites(
- const void* context, const lr11xx_gnss_date_t date,
- const lr11xx_gnss_solver_assistance_position_t* assistance_position,
- const lr11xx_gnss_constellation_t constellation, uint8_t* nb_visible_sv )
-{
- const int16_t latitude = ( ( assistance_position->latitude * 2048 ) / LR11XX_GNSS_SCALING_LATITUDE );
- const int16_t longitude = ( ( assistance_position->longitude * 2048 ) / LR11XX_GNSS_SCALING_LONGITUDE );
- const uint8_t cbuffer[LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH] = {
- ( uint8_t )( LR11XX_GNSS_GET_SV_VISIBLE_OC >> 8 ),
- ( uint8_t )( LR11XX_GNSS_GET_SV_VISIBLE_OC >> 0 ),
- ( uint8_t )( date >> 24 ),
- ( uint8_t )( date >> 16 ),
- ( uint8_t )( date >> 8 ),
- ( uint8_t )( date >> 0 ),
- ( uint8_t )( latitude >> 8 ),
- ( uint8_t )( latitude >> 0 ),
- ( uint8_t )( longitude >> 8 ),
- ( uint8_t )( longitude >> 0 ),
- ( uint8_t )( constellation - 1 ),
- };
-
- return ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer, LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH, nb_visible_sv,
- 1 );
-}
-
-lr11xx_status_t lr11xx_gnss_get_visible_satellites( const void* context, const uint8_t nb_visible_satellites,
- lr11xx_gnss_visible_satellite_t* visible_satellite_id_doppler )
-{
- uint8_t result_buffer[12 * 5] = { 0 };
- const uint16_t read_size = nb_visible_satellites * 5;
-
- const uint8_t cbuffer[LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH] = {
- ( uint8_t )( LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC >> 8 ),
- ( uint8_t )( LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC >> 0 ),
- };
-
- const lr11xx_hal_status_t hal_status =
- lr11xx_hal_read( context, cbuffer, LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH, result_buffer, read_size );
-
- if( hal_status == LR11XX_HAL_STATUS_OK )
- {
- for( uint8_t index_satellite = 0; index_satellite < nb_visible_satellites; index_satellite++ )
- {
- const uint16_t local_result_buffer_index = index_satellite * 5;
- lr11xx_gnss_visible_satellite_t* local_satellite_result = &visible_satellite_id_doppler[index_satellite];
-
- local_satellite_result->satellite_id = result_buffer[local_result_buffer_index];
- local_satellite_result->doppler = ( int16_t )( ( result_buffer[local_result_buffer_index + 1] << 8 ) +
- ( result_buffer[local_result_buffer_index + 2] << 0 ) );
- local_satellite_result->doppler_error =
- ( int16_t )( ( result_buffer[local_result_buffer_index + 3] << 8 ) +
- ( result_buffer[local_result_buffer_index + 4] << 0 ) );
- }
- }
-
- return ( lr11xx_status_t ) hal_status;
-}
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
- */
-
-/* --- EOF ------------------------------------------------------------------ */
\ No newline at end of file
diff --git a/geolocation_middleware/gnss/src/lr11xx_driver_extension.h b/geolocation_middleware/gnss/src/lr11xx_driver_extension.h
deleted file mode 100644
index c81b114..0000000
--- a/geolocation_middleware/gnss/src/lr11xx_driver_extension.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*!
- * @file lr11xx_driver_extension.h
- *
- * @brief driver extension for LR11XX
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef LR11XX_DRIVER_EXTENSION_H
-#define LR11XX_DRIVER_EXTENSION_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-
-#include "lr11xx_types.h"
-#include "lr11xx_gnss_types.h"
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC MACROS -----------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC CONSTANTS --------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC TYPES ------------------------------------------------------------
- */
-
-/*!
- * @brief Structure for information about visible SV
- */
-typedef struct lr11xx_gnss_visible_satellite_s
-{
- lr11xx_gnss_satellite_id_t satellite_id; //!< SV ID
- int16_t doppler; //!< SV doppler in Hz
- int16_t doppler_error; //!< SV doppler error - step of 125Hz
-} lr11xx_gnss_visible_satellite_t;
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
- */
-
-/*!
- * @brief Function to read the frequency search space around the Doppler frequency
- *
- * @param [in] radio Radio abstraction
- * @param [out] freq_search_space Frequency search space configuration read from the chip
- *
- * @returns Operation status
- */
-lr11xx_status_t lr11xx_gnss_read_freq_search_space( const void* radio,
- lr11xx_gnss_freq_search_space_t* freq_search_space );
-
-/*!
- * @brief Function to set the frequency search space around the Doppler frequency
- *
- * @param [in] radio Radio abstraction
- * @param [in] freq_search_space Frequency search space configuration to be applied
- *
- * @returns Operation status
- */
-lr11xx_status_t lr11xx_gnss_set_freq_search_space( const void* radio,
- const lr11xx_gnss_freq_search_space_t freq_search_space );
-
-/**
- * @brief Return the theoretical number of visible satellites based on the given parameters.
- *
- * @param [in] context Chip implementation context
- * @param [in] date The actual date of scan. Its format is the number of seconds elapsed since January the 6th 1980
- * 00:00:00 with leap seconds included.
- * @param [in] assistance_position, latitude 12 bits and longitude 12 bits
- * @param [in] constellation Bit mask of the constellations to use. See @ref lr11xx_gnss_constellation_t for
- * the possible values
- * @param [out] nb_visible_sv thoeretical number of visible satellites
- *
- * @returns Operation status
- */
-lr11xx_status_t lr11xx_gnss_get_nb_visible_satellites(
- const void* context, const lr11xx_gnss_date_t date,
- const lr11xx_gnss_solver_assistance_position_t* assistance_position,
- const lr11xx_gnss_constellation_t constellation, uint8_t* nb_visible_sv );
-
-/**
- * @brief Return the doppler information of theoretical visible satellites, this function shall be called after
- * lr11xx_gnss_get_nb_visible_satellites function.
- *
- * @param [in] context Chip implementation context
- * @param [in] nb_visible_satellites number of visible satellites returned by lr11xx_gnss_get_nb_visible_satellites
- * function,
- * @param [out] visible_satellite_id_doppler Doppler information of each satellite.
- *
- * @returns Operation status
- */
-lr11xx_status_t lr11xx_gnss_get_visible_satellites( const void* context, const uint8_t nb_visible_satellites,
- lr11xx_gnss_visible_satellite_t* visible_satellite_id_doppler );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // LR11XX_DRIVER_EXTENSION_H
-
-/* --- EOF ------------------------------------------------------------------ */
\ No newline at end of file
diff --git a/geolocation_middleware/wifi/src/wifi_helpers.c b/geolocation_middleware/wifi/src/wifi_helpers.c
index ac03443..c1553ba 100644
--- a/geolocation_middleware/wifi/src/wifi_helpers.c
+++ b/geolocation_middleware/wifi/src/wifi_helpers.c
@@ -74,6 +74,8 @@ static wifi_settings_t settings = { 0 };
* --- PRIVATE VARIABLES -------------------------------------------------------
*/
+static lr11xx_wifi_basic_complete_result_t wifi_results_mac_addr[WIFI_MAX_RESULTS];
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
@@ -141,11 +143,12 @@ void smtc_wifi_scan_ended( void )
bool smtc_wifi_get_results( const void* radio_context, wifi_scan_all_result_t* wifi_results )
{
- lr11xx_wifi_basic_complete_result_t wifi_results_mac_addr[WIFI_MAX_RESULTS] = { 0 };
- uint8_t nb_results;
- uint8_t max_nb_results;
- uint8_t result_index = 0;
- lr11xx_status_t status = LR11XX_STATUS_OK;
+ uint8_t nb_results;
+ uint8_t max_nb_results;
+ uint8_t result_index = 0;
+ lr11xx_status_t status = LR11XX_STATUS_OK;
+
+ memset( wifi_results_mac_addr, 0, sizeof wifi_results_mac_addr );
status = lr11xx_wifi_get_nb_results( radio_context, &nb_results );
if( status != LR11XX_STATUS_OK )
diff --git a/geolocation_middleware/wifi/src/wifi_middleware.c b/geolocation_middleware/wifi/src/wifi_middleware.c
index 7f5d72b..ef0e073 100644
--- a/geolocation_middleware/wifi/src/wifi_middleware.c
+++ b/geolocation_middleware/wifi/src/wifi_middleware.c
@@ -436,7 +436,10 @@ mw_return_code_t wifi_mw_get_event_data_scan_done( wifi_mw_event_data_scan_done_
}
}
-void wifi_mw_set_port( uint8_t port ) { lorawan_port = port; }
+void wifi_mw_set_port( uint8_t port )
+{
+ lorawan_port = port;
+}
void wifi_mw_send_bypass( bool no_send )
{
@@ -446,7 +449,10 @@ void wifi_mw_send_bypass( bool no_send )
send_bypass = no_send;
}
-void wifi_mw_set_payload_format( wifi_mw_payload_format_t format ) { payload_format = format; }
+void wifi_mw_set_payload_format( wifi_mw_payload_format_t format )
+{
+ payload_format = format;
+}
void wifi_mw_display_results( const wifi_mw_event_data_scan_done_t* data )
{
@@ -500,7 +506,19 @@ mw_return_code_t wifi_mw_get_event_data_terminated( wifi_mw_event_data_terminate
}
}
-void wifi_mw_clear_pending_events( void ) { pending_events = 0; }
+void wifi_mw_display_terminated_results( const wifi_mw_event_data_terminated_t* data )
+{
+ if( data != NULL )
+ {
+ MW_DBG_TRACE_PRINTF( "TERMINATED info:\n" );
+ MW_DBG_TRACE_PRINTF( "-- number of scans sent: %u\n", data->nb_scans_sent );
+ }
+}
+
+void wifi_mw_clear_pending_events( void )
+{
+ pending_events = 0;
+}
/*
* -----------------------------------------------------------------------------
@@ -687,7 +705,10 @@ static bool wifi_mw_send_results( void )
return true;
}
-static void wifi_mw_reset_results( void ) { memset( &wifi_results, 0, sizeof wifi_results ); }
+static void wifi_mw_reset_results( void )
+{
+ memset( &wifi_results, 0, sizeof wifi_results );
+}
static void wifi_mw_tx_done_callback( void )
{
diff --git a/geolocation_middleware/wifi/src/wifi_middleware.h b/geolocation_middleware/wifi/src/wifi_middleware.h
index 8c31122..de9b517 100644
--- a/geolocation_middleware/wifi/src/wifi_middleware.h
+++ b/geolocation_middleware/wifi/src/wifi_middleware.h
@@ -225,6 +225,13 @@ void wifi_mw_set_payload_format( wifi_mw_payload_format_t format );
*/
void wifi_mw_display_results( const wifi_mw_event_data_scan_done_t* data );
+/**
+ * @brief Print the results of the WIFI_MW_EVENT_TERMINATED event
+ *
+ * @param [in] data Sequence results to be printed on the console
+ */
+void wifi_mw_display_terminated_results( const wifi_mw_event_data_terminated_t* data );
+
#ifdef __cplusplus
}
#endif
diff --git a/geolocation_middleware/wifi/src/wifi_version.h b/geolocation_middleware/wifi/src/wifi_version.h
index 929a111..7937640 100644
--- a/geolocation_middleware/wifi/src/wifi_version.h
+++ b/geolocation_middleware/wifi/src/wifi_version.h
@@ -56,7 +56,7 @@ extern "C" {
* --- PUBLIC TYPES ------------------------------------------------------------
*/
#define WIFI_MW_VERSION_MAJOR 2
-#define WIFI_MW_VERSION_MINOR 0
+#define WIFI_MW_VERSION_MINOR 1
#define WIFI_MW_VERSION_PATCH 0
/*
diff --git a/lora_basics_modem/lora_basics_modem/CHANGELOG.md b/lora_basics_modem/lora_basics_modem/CHANGELOG.md
index c6fb7f4..5580907 100644
--- a/lora_basics_modem/lora_basics_modem/CHANGELOG.md
+++ b/lora_basics_modem/lora_basics_modem/CHANGELOG.md
@@ -4,6 +4,38 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v3.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
+
+### 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)
+
+### 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
+
## [v3.2.4] 2022-08-23
### Added
@@ -38,8 +70,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* [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
+* [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
diff --git a/lora_basics_modem/lora_basics_modem/Makefile b/lora_basics_modem/lora_basics_modem/Makefile
old mode 100644
new mode 100755
index 37f8bec..d6ad748
--- a/lora_basics_modem/lora_basics_modem/Makefile
+++ b/lora_basics_modem/lora_basics_modem/Makefile
@@ -33,7 +33,7 @@ LOG_MEM ?= yes
RADIO ?= nc
#MCU - Must be provided by user
-MCU_FLAGS =? nc
+MCU_FLAGS ?= nc
#-----------------------------------------------------------------------------
# Internal LBM features management
@@ -72,7 +72,7 @@ USE_GNSS ?= yes
# default action: print help
#-----------------------------------------------------------------------------
help:
- $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 sx1261 sx1262 sx1268")
+ $(call echo_help_b, "Available TARGETs: sx128x lr1110 lr1120 lr1121 sx1261 sx1262 sx1268")
$(call echo_help, "")
$(call echo_help_b, "-------------------------------- Clean -------------------------------------")
$(call echo_help, " * make clean_ : clean basic_modem for a given target")
@@ -81,7 +81,7 @@ help:
$(call echo_help_b, "----------------------------- Compilation ----------------------------------")
$(call echo_help, " * make basic_modem_ MCU_FLAGS=xxx : build basic_modem on a given target with chosen mcu flags")
$(call echo_help, " * MCU_FLAGS are mandatory. Ex for stm32l4:")
- $(call echo_help, " * MCU_FLAGS=\"-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard\"")
+ $(call echo_help, " * MCU_FLAGS=\"-mcpu=cortex-m4 -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard\"")
$(call echo_help, "")
$(call echo_help_b, "---------------------- Optional build parameters ---------------------------")
$(call echo_help, " * REGION=xxx : choose which region should be compiled (default: all)")
@@ -96,7 +96,7 @@ help:
$(call echo_help, " * - RU_864")
$(call echo_help, " * - US_915")
$(call echo_help, " * - WW_2G4 (to be used only for lr1120 and sx128x targets)")
- $(call echo_help, " * RP_VERSION=xxx : choose wich regional paramerter version should be compiled (default: RP2_101) ")
+ $(call echo_help, " * RP_VERSION=xxx : choose wich regional paramerter version should be compiled (default: RP2_103) ")
$(call echo_help, " * - RP2_101")
$(call echo_help, " * - RP2_103 (LR-FHSS support)")
$(call echo_help, " * CRYPTO=xxx : choose which crypto should be compiled (default: SOFT)")
@@ -125,6 +125,10 @@ ifeq ($(RADIO),lr1120)
-include makefiles/lr11xx.mk
endif
+ifeq ($(RADIO),lr1121)
+-include makefiles/lr11xx.mk
+endif
+
ifeq ($(RADIO),sx1261)
-include makefiles/sx126x.mk
endif
@@ -148,7 +152,7 @@ endif
.PHONY: FORCE
FORCE:
-all: basic_modem_sx128x basic_modem_lr1110 basic_modem_lr1120 basic_modem_sx1261 basic_modem_sx1262
+all: basic_modem_sx128x basic_modem_lr1110 basic_modem_lr1120 basic_modem_lr1121 basic_modem_sx1261 basic_modem_sx1262
#-----------------------------------------------------------------------------
# Clean
@@ -165,6 +169,9 @@ clean_lr1110:
clean_lr1120:
$(MAKE) clean_target RADIO=lr1120
+clean_lr1121:
+ $(MAKE) clean_target RADIO=lr1121
+
clean_sx1261:
$(MAKE) clean_target RADIO=sx1261
@@ -186,6 +193,9 @@ basic_modem_lr1110:
basic_modem_lr1120:
$(MAKE) basic_modem RADIO=lr1120 $(MTHREAD_FLAG)
+basic_modem_lr1121:
+ $(MAKE) basic_modem RADIO=lr1121 $(MTHREAD_FLAG)
+
basic_modem_sx1261:
$(MAKE) basic_modem RADIO=sx1261 $(MTHREAD_FLAG)
diff --git a/lora_basics_modem/lora_basics_modem/README.md b/lora_basics_modem/lora_basics_modem/README.md
index 2ce4358..2bdfaf5 100644
--- a/lora_basics_modem/lora_basics_modem/README.md
+++ b/lora_basics_modem/lora_basics_modem/README.md
@@ -10,7 +10,7 @@ The LoRaWAN version that is currently implemented in LoRa Basics Modem is v1.0.4
LoRa Basics Modem supports the following LoRaWAN regions:
-* AS_923 (AS923-1, AS923-2, AS923-3)
+* AS_923 (AS923-1, AS923-2, AS923-3, AS923-4)
* AU_915
* CN_470
* CN_470_RP_1_0
@@ -24,7 +24,7 @@ LoRa Basics Modem supports an emulation of LoRaWAN protocol for the 2.4GHz globa
### LoRaWAN regional parameters
-Default regional parameters version supported by LoRa Basics Modem is rp2-1.0.1. It is possible to switch to rp2-1.0.3 at compile time.
+Default regional parameters version supported by LoRa Basics Modem is rp2-1.0.3. It is possible to switch back to rp2-1.0.1 at compile time.
### LoRaWAN class
@@ -41,7 +41,7 @@ LoRa Basics Modem supports the following services:
* Large files upload
* ROSE Streaming
* Application-Layer Clock synchronization
-* Almanac Update
+* Almanac Update for LoRa Edge
## LoRa Basics Modem API
@@ -61,8 +61,9 @@ The Hardware Abstraction Layer of LoRa Basics Modem is defined in the `smtc_mode
LoRa Basics Modem supports the following transceivers:
-* LR1110 with firmware 0x0307.
-* LR1120 with firmware 0x0101
+* LR1110 with firmware 0x0308.
+* LR1120 with firmware 0x0102
+* LR1121 with firmware 0x0102
* SX1261
* SX1262
* SX1280
@@ -73,10 +74,11 @@ LoRa Basics Modem supports the following transceivers:
* [LFU] In case LoRa Basics Modem is acting in US915 region with datarate DR0, files smaller than 13 bytes are not properly sent and cannot be reconstructed on LoRa Cloud side
* [charge] Values returned by `smtc_modem_get_charge()` for regions CN470 and CN470_RP1 are not accurate
* [charge] Values returned by `smtc_modem_get_charge()` for the LR-FHSS based datarate are not accurate
+* [time] In case ALC_SYNC time service is used, when a valid time is received, the generated `SMTC_MODEM_EVENT_TIME` event will show a ghost missed event.
## Disclaimer
-This software has been extensively tested when targeting LR1110 / LR1120 / SX1261 / SX1262 / SX1280 / SX1281 for LoRaWAN regions mentioned in [this paragraph](#lorawan-region). For all other combinations of features this software shall be considered an Engineering Sample.
+This software has been extensively tested when targeting LR1110 / LR1120 / LR1121 / SX1261 / SX1262 / SX1280 / SX1281 for LoRaWAN regions mentioned in [this paragraph](#lorawan-region). For all other combinations of features this software shall be considered an Engineering Sample.
Modem trace prints can only be used for debug purpose and shall be deactivated for production release.
diff --git a/lora_basics_modem/lora_basics_modem/lora_basics_modem_version.h b/lora_basics_modem/lora_basics_modem/lora_basics_modem_version.h
index 7fd50ff..a2323b7 100644
--- a/lora_basics_modem/lora_basics_modem/lora_basics_modem_version.h
+++ b/lora_basics_modem/lora_basics_modem/lora_basics_modem_version.h
@@ -56,8 +56,8 @@ extern "C" {
* --- PUBLIC TYPES ------------------------------------------------------------
*/
#define LORA_BASICS_MODEM_FW_VERSION_MAJOR 3
-#define LORA_BASICS_MODEM_FW_VERSION_MINOR 2
-#define LORA_BASICS_MODEM_FW_VERSION_PATCH 4
+#define LORA_BASICS_MODEM_FW_VERSION_MINOR 3
+#define LORA_BASICS_MODEM_FW_VERSION_PATCH 0
/*
* -----------------------------------------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/makefiles/common.mk b/lora_basics_modem/lora_basics_modem/makefiles/common.mk
index 15bb2c5..7200c0c 100644
--- a/lora_basics_modem/lora_basics_modem/makefiles/common.mk
+++ b/lora_basics_modem/lora_basics_modem/makefiles/common.mk
@@ -99,6 +99,17 @@ BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto_with_cred
endif # LR11XX_WITH_CREDENTIALS
endif # lr1120
+ifeq ($(RADIO),lr1121)
+ifeq ($(CRYPTO),LR11XX)
+TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto
+BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto
+endif # LR11XX
+ifeq ($(CRYPTO),LR11XX_WITH_CREDENTIALS)
+TARGET_MODEM := $(TARGET_MODEM)_lr11xx_crypto_with_cred
+BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_lr11xx_crypto_with_cred
+endif # LR11XX_WITH_CREDENTIALS
+endif # lr1121
+
ifeq ($(MIDDLEWARE),yes)
TARGET_MODEM := $(TARGET_MODEM)_middleware
BUILD_DIR_MODEM := $(BUILD_DIR_MODEM)_middleware
@@ -178,7 +189,6 @@ WFLAG += \
-Wno-unused-parameter \
-Wpedantic \
-fomit-frame-pointer \
- -mabi=aapcs \
-fno-unroll-loops \
-ffast-math \
-ftree-vectorize \
@@ -266,8 +276,9 @@ COMMON_C_DEFS += \
-DADD_SMTC_ALC_SYNC
endif
+EXTRAFLAGS ?=
-CFLAGS += -fno-builtin $(MCU_FLAGS) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)"
+CFLAGS += -fno-builtin $(MCU_FLAGS) $(BOARD_C_DEFS) $(COMMON_C_DEFS) $(MODEM_C_DEFS) $(EXTRAFLAGS) $(BOARD_C_INCLUDES) $(COMMON_C_INCLUDES) $(MODEM_C_INCLUDES) $(OPT) $(WFLAG) -MMD -MP -MF"$(@:%.o=%.d)"
CFLAGS += -falign-functions=4
CFLAGS += -std=c17
diff --git a/lora_basics_modem/lora_basics_modem/makefiles/lr11xx.mk b/lora_basics_modem/lora_basics_modem/makefiles/lr11xx.mk
index 23a702f..b3cefdc 100644
--- a/lora_basics_modem/lora_basics_modem/makefiles/lr11xx.mk
+++ b/lora_basics_modem/lora_basics_modem/makefiles/lr11xx.mk
@@ -7,17 +7,25 @@ endif
ifeq ($(RADIO),lr1120)
TARGET = lr1120
endif
-
+ifeq ($(RADIO),lr1121)
+TARGET = lr1121
+endif
#-----------------------------------------------------------------------------
# Common sources
#-----------------------------------------------------------------------------
-ifeq ($(USE_GNSS),yes)
-SMTC_MODEM_SERVICES_C_SOURCES += \
- smtc_modem_core/smtc_modem_services/src/almanac_update/almanac_update.c
-endif
-
+ifeq ($(RADIO),lr1121)
+USE_GNSS=no
+RADIO_DRIVER_C_SOURCES += \
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_bootloader.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system.c\
+ smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.c
+else
RADIO_DRIVER_C_SOURCES += \
smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_bootloader.c\
smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c\
@@ -31,6 +39,11 @@ ifeq ($(USE_GNSS),yes)
RADIO_DRIVER_C_SOURCES += \
smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.c
endif
+ifeq ($(USE_GNSS),yes)
+SMTC_MODEM_SERVICES_C_SOURCES += \
+ smtc_modem_core/smtc_modem_services/src/almanac_update/almanac_update.c
+endif
+endif
SMTC_RAL_C_SOURCES += \
smtc_modem_core/smtc_ral/src/ral_lr11xx.c
@@ -82,12 +95,8 @@ endif # soft_crypto
#-----------------------------------------------------------------------------
MODEM_C_DEFS += \
-DLR11XX\
- -DLR11XX_TRANSCEIVER
-
-ifeq ($(RADIO),lr1120)
-MODEM_C_DEFS += \
- -DLR1120
-endif
+ -DLR11XX_TRANSCEIVER\
+ -DLR11XX_DISABLE_WARNINGS
ifeq ($(CRYPTO),LR11XX)
MODEM_C_DEFS += \
diff --git a/lora_basics_modem/lora_basics_modem/makefiles/regions.mk b/lora_basics_modem/lora_basics_modem/makefiles/regions.mk
index b4db64e..6719a08 100644
--- a/lora_basics_modem/lora_basics_modem/makefiles/regions.mk
+++ b/lora_basics_modem/lora_basics_modem/makefiles/regions.mk
@@ -37,7 +37,7 @@ endif # REGION
#-----------------------------------------------------------------------------
ifndef RP_VERSION
-MODEM_C_DEFS += -DRP2_101
+MODEM_C_DEFS += -DRP2_103
endif
ifeq ($(RP_VERSION),RP2_103)
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_api/doxygen.config b/lora_basics_modem/lora_basics_modem/smtc_modem_api/doxygen.config
deleted file mode 100644
index 85fc6dc..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_api/doxygen.config
+++ /dev/null
@@ -1,2494 +0,0 @@
-# Doxyfile 1.8.13
-
-# This file describes the settings to be used by the documentation system
-# doxygen (www.doxygen.org) for a project.
-#
-# All text after a double hash (##) is considered a comment and is placed in
-# front of the TAG it is preceding.
-#
-# All text after a single hash (#) is considered a comment and will be ignored.
-# The format is:
-# TAG = value [value, ...]
-# For lists, items can also be appended using:
-# TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (\" \").
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-
-# This tag specifies the encoding used for all characters in the config file
-# that follow. The default is UTF-8 which is also the encoding used for all text
-# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
-# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv
-# for the list of possible encodings.
-# The default value is: UTF-8.
-
-DOXYFILE_ENCODING = UTF-8
-
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
-# double-quotes, unless you are using Doxywizard) that should identify the
-# project for which the documentation is generated. This name is used in the
-# title of most generated pages and in a few other places.
-# The default value is: My Project.
-
-PROJECT_NAME = "SMTC Modem API"
-
-# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
-# could be handy for archiving the generated documentation or if some version
-# control system is used.
-
-PROJECT_NUMBER =
-
-# Using the PROJECT_BRIEF tag one can provide an optional one line description
-# for a project that appears at the top of each page and should give viewer a
-# quick idea about the purpose of the project. Keep the description short.
-
-PROJECT_BRIEF = "Generic Modem API description"
-
-# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
-# in the documentation. The maximum height of the logo should not exceed 55
-# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
-# the logo to the output directory.
-
-PROJECT_LOGO =
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
-# into which the generated documentation will be written. If a relative path is
-# entered, it will be relative to the location where doxygen was started. If
-# left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = build_doc
-
-# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
-# directories (in 2 levels) under the output directory of each output format and
-# will distribute the generated files over these directories. Enabling this
-# option can be useful when feeding doxygen a huge amount of source files, where
-# putting all generated files in the same directory would otherwise causes
-# performance problems for the file system.
-# The default value is: NO.
-
-CREATE_SUBDIRS = NO
-
-# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
-# characters to appear in the names of generated files. If set to NO, non-ASCII
-# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
-# U+3044.
-# The default value is: NO.
-
-ALLOW_UNICODE_NAMES = NO
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all constant output in the proper language.
-# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
-# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
-# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
-# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
-# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
-# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
-# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
-# Ukrainian and Vietnamese.
-# The default value is: English.
-
-OUTPUT_LANGUAGE = English
-
-# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
-# descriptions after the members that are listed in the file and class
-# documentation (similar to Javadoc). Set to NO to disable this.
-# The default value is: YES.
-
-BRIEF_MEMBER_DESC = YES
-
-# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
-# description of a member or function before the detailed description
-#
-# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-# The default value is: YES.
-
-REPEAT_BRIEF = YES
-
-# This tag implements a quasi-intelligent brief description abbreviator that is
-# used to form the text in various listings. Each string in this list, if found
-# as the leading text of the brief description, will be stripped from the text
-# and the result, after processing the whole list, is used as the annotated
-# text. Otherwise, the brief description is used as-is. If left blank, the
-# following values are used ($name is automatically replaced with the name of
-# the entity):The $name class, The $name widget, The $name file, is, provides,
-# specifies, contains, represents, a, an and the.
-
-ABBREVIATE_BRIEF = "The $name class" \
- "The $name widget" \
- "The $name file" \
- is \
- provides \
- specifies \
- contains \
- represents \
- a \
- an \
- the
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# doxygen will generate a detailed section even if there is only a brief
-# description.
-# The default value is: NO.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
-# inherited members of a class in the documentation of that class as if those
-# members were ordinary class members. Constructors, destructors and assignment
-# operators of the base classes will not be shown.
-# The default value is: NO.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
-# before files name in the file list and in the header files. If set to NO the
-# shortest path that makes the file name unique will be used
-# The default value is: YES.
-
-FULL_PATH_NAMES = YES
-
-# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
-# Stripping is only done if one of the specified strings matches the left-hand
-# part of the path. The tag can be used to show relative paths in the file list.
-# If left blank the directory from which doxygen is run is used as the path to
-# strip.
-#
-# Note that you can specify absolute paths here, but also relative paths, which
-# will be relative from the directory where doxygen is started.
-# This tag requires that the tag FULL_PATH_NAMES is set to YES.
-
-STRIP_FROM_PATH =
-
-# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
-# path mentioned in the documentation of a class, which tells the reader which
-# header file to include in order to use a class. If left blank only the name of
-# the header file containing the class definition is used. Otherwise one should
-# specify the list of include paths that are normally passed to the compiler
-# using the -I flag.
-
-STRIP_FROM_INC_PATH =
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
-# less readable) file names. This can be useful is your file systems doesn't
-# support long names like on DOS, Mac, or CD-ROM.
-# The default value is: NO.
-
-SHORT_NAMES = NO
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
-# first line (until the first dot) of a Javadoc-style comment as the brief
-# description. If set to NO, the Javadoc-style will behave just like regular Qt-
-# style comments (thus requiring an explicit @brief command for a brief
-# description.)
-# The default value is: NO.
-
-JAVADOC_AUTOBRIEF = NO
-
-# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
-# line (until the first dot) of a Qt-style comment as the brief description. If
-# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
-# requiring an explicit \brief command for a brief description.)
-# The default value is: NO.
-
-QT_AUTOBRIEF = NO
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
-# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
-# a brief description. This used to be the default behavior. The new default is
-# to treat a multi-line C++ comment block as a detailed description. Set this
-# tag to YES if you prefer the old behavior instead.
-#
-# Note that setting this tag to YES also means that rational rose comments are
-# not recognized any more.
-# The default value is: NO.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
-# documentation from any documented member that it re-implements.
-# The default value is: YES.
-
-INHERIT_DOCS = YES
-
-# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
-# page for each member. If set to NO, the documentation of a member will be part
-# of the file/class/namespace that contains it.
-# The default value is: NO.
-
-SEPARATE_MEMBER_PAGES = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
-# uses this value to replace tabs by spaces in code fragments.
-# Minimum value: 1, maximum value: 16, default value: 4.
-
-TAB_SIZE = 4
-
-# This tag can be used to specify a number of aliases that act as commands in
-# the documentation. An alias has the form:
-# name=value
-# For example adding
-# "sideeffect=@par Side Effects:\n"
-# will allow you to put the command \sideeffect (or @sideeffect) in the
-# documentation, which will result in a user-defined paragraph with heading
-# "Side Effects:". You can put \n's in the value part of an alias to insert
-# newlines.
-
-ALIASES =
-
-# This tag can be used to specify a number of word-keyword mappings (TCL only).
-# A mapping has the form "name=value". For example adding "class=itcl::class"
-# will allow you to use the command class in the itcl::class meaning.
-
-TCL_SUBST =
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
-# only. Doxygen will then generate output that is more tailored for C. For
-# instance, some of the names that are used will be different. The list of all
-# members will be omitted, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
-# Python sources only. Doxygen will then generate output that is more tailored
-# for that language. For instance, namespaces will be presented as packages,
-# qualified scopes will look different, etc.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_JAVA = NO
-
-# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
-# sources. Doxygen will then generate output that is tailored for Fortran.
-# The default value is: NO.
-
-OPTIMIZE_FOR_FORTRAN = NO
-
-# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
-# sources. Doxygen will then generate output that is tailored for VHDL.
-# The default value is: NO.
-
-OPTIMIZE_OUTPUT_VHDL = NO
-
-# Doxygen selects the parser to use depending on the extension of the files it
-# parses. With this tag you can assign which parser to use for a given
-# extension. Doxygen has a built-in mapping, but you can override or extend it
-# using this tag. The format is ext=language, where ext is a file extension, and
-# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
-# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:
-# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:
-# Fortran. In the later case the parser tries to guess whether the code is fixed
-# or free formatted code, this is the default for Fortran type files), VHDL. For
-# instance to make doxygen treat .inc files as Fortran files (default is PHP),
-# and .f files as C (default is Fortran), use: inc=Fortran f=C.
-#
-# Note: For files without extension you can use no_extension as a placeholder.
-#
-# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
-# the files are not read by doxygen.
-
-EXTENSION_MAPPING =
-
-# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
-# according to the Markdown format, which allows for more readable
-# documentation. See http://daringfireball.net/projects/markdown/ for details.
-# The output of markdown processing is further processed by doxygen, so you can
-# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
-# case of backward compatibilities issues.
-# The default value is: YES.
-
-MARKDOWN_SUPPORT = YES
-
-# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
-# to that level are automatically included in the table of contents, even if
-# they do not have an id attribute.
-# Note: This feature currently applies only to Markdown headings.
-# Minimum value: 0, maximum value: 99, default value: 0.
-# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
-
-TOC_INCLUDE_HEADINGS = 0
-
-# When enabled doxygen tries to link words that correspond to documented
-# classes, or namespaces to their corresponding documentation. Such a link can
-# be prevented in individual cases by putting a % sign in front of the word or
-# globally by setting AUTOLINK_SUPPORT to NO.
-# The default value is: YES.
-
-AUTOLINK_SUPPORT = YES
-
-# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
-# to include (a tag file for) the STL sources as input, then you should set this
-# tag to YES in order to let doxygen match functions declarations and
-# definitions whose arguments contain STL classes (e.g. func(std::string);
-# versus func(std::string) {}). This also make the inheritance and collaboration
-# diagrams that involve STL classes more complete and accurate.
-# The default value is: NO.
-
-BUILTIN_STL_SUPPORT = NO
-
-# If you use Microsoft's C++/CLI language, you should set this option to YES to
-# enable parsing support.
-# The default value is: NO.
-
-CPP_CLI_SUPPORT = NO
-
-# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
-# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen
-# will parse them like normal C++ but will assume all classes use public instead
-# of private inheritance when no explicit protection keyword is present.
-# The default value is: NO.
-
-SIP_SUPPORT = NO
-
-# For Microsoft's IDL there are propget and propput attributes to indicate
-# getter and setter methods for a property. Setting this option to YES will make
-# doxygen to replace the get and set methods by a property in the documentation.
-# This will only work if the methods are indeed getting or setting a simple
-# type. If this is not the case, or you want to show the methods anyway, you
-# should set this option to NO.
-# The default value is: YES.
-
-IDL_PROPERTY_SUPPORT = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-# The default value is: NO.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# If one adds a struct or class to a group and this option is enabled, then also
-# any nested class or struct is added to the same group. By default this option
-# is disabled and one has to add nested compounds explicitly via \ingroup.
-# The default value is: NO.
-
-GROUP_NESTED_COMPOUNDS = NO
-
-# Set the SUBGROUPING tag to YES to allow class member groups of the same type
-# (for instance a group of public functions) to be put as a subgroup of that
-# type (e.g. under the Public Functions section). Set it to NO to prevent
-# subgrouping. Alternatively, this can be done per class using the
-# \nosubgrouping command.
-# The default value is: YES.
-
-SUBGROUPING = YES
-
-# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
-# are shown inside the group in which they are included (e.g. using \ingroup)
-# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
-# and RTF).
-#
-# Note that this feature does not work in combination with
-# SEPARATE_MEMBER_PAGES.
-# The default value is: NO.
-
-INLINE_GROUPED_CLASSES = NO
-
-# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
-# with only public data fields or simple typedef fields will be shown inline in
-# the documentation of the scope in which they are defined (i.e. file,
-# namespace, or group documentation), provided this scope is documented. If set
-# to NO, structs, classes, and unions are shown on a separate page (for HTML and
-# Man pages) or section (for LaTeX and RTF).
-# The default value is: NO.
-
-INLINE_SIMPLE_STRUCTS = NO
-
-# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
-# enum is documented as struct, union, or enum with the name of the typedef. So
-# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
-# with name TypeT. When disabled the typedef will appear as a member of a file,
-# namespace, or class. And the struct will be named TypeS. This can typically be
-# useful for C code in case the coding convention dictates that all compound
-# types are typedef'ed and only the typedef is referenced, never the tag name.
-# The default value is: NO.
-
-TYPEDEF_HIDES_STRUCT = NO
-
-# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
-# cache is used to resolve symbols given their name and scope. Since this can be
-# an expensive process and often the same symbol appears multiple times in the
-# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
-# doxygen will become slower. If the cache is too large, memory is wasted. The
-# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
-# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
-# symbols. At the end of a run doxygen will report the cache usage and suggest
-# the optimal cache size from a speed point of view.
-# Minimum value: 0, maximum value: 9, default value: 0.
-
-LOOKUP_CACHE_SIZE = 0
-
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-
-# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
-# documentation are documented, even if no documentation was available. Private
-# class members and static file members will be hidden unless the
-# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
-# Note: This will also disable the warnings about undocumented members that are
-# normally produced when WARNINGS is set to YES.
-# The default value is: NO.
-
-EXTRACT_ALL = NO
-
-# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
-# be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PRIVATE = NO
-
-# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
-# scope will be included in the documentation.
-# The default value is: NO.
-
-EXTRACT_PACKAGE = NO
-
-# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
-# included in the documentation.
-# The default value is: NO.
-
-EXTRACT_STATIC = NO
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
-# locally in source files will be included in the documentation. If set to NO,
-# only classes defined in header files are included. Does not have any effect
-# for Java sources.
-# The default value is: YES.
-
-EXTRACT_LOCAL_CLASSES = YES
-
-# This flag is only useful for Objective-C code. If set to YES, local methods,
-# which are defined in the implementation section but not in the interface are
-# included in the documentation. If set to NO, only methods in the interface are
-# included.
-# The default value is: NO.
-
-EXTRACT_LOCAL_METHODS = NO
-
-# If this flag is set to YES, the members of anonymous namespaces will be
-# extracted and appear in the documentation as a namespace called
-# 'anonymous_namespace{file}', where file will be replaced with the base name of
-# the file that contains the anonymous namespace. By default anonymous namespace
-# are hidden.
-# The default value is: NO.
-
-EXTRACT_ANON_NSPACES = NO
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
-# undocumented members inside documented classes or files. If set to NO these
-# members will be included in the various overviews, but no documentation
-# section is generated. This option has no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy. If set
-# to NO, these classes will be included in the various overviews. This option
-# has no effect if EXTRACT_ALL is enabled.
-# The default value is: NO.
-
-HIDE_UNDOC_CLASSES = NO
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
-# (class|struct|union) declarations. If set to NO, these declarations will be
-# included in the documentation.
-# The default value is: NO.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
-# documentation blocks found inside the body of a function. If set to NO, these
-# blocks will be appended to the function's detailed documentation block.
-# The default value is: NO.
-
-HIDE_IN_BODY_DOCS = NO
-
-# The INTERNAL_DOCS tag determines if documentation that is typed after a
-# \internal command is included. If the tag is set to NO then the documentation
-# will be excluded. Set it to YES to include the internal documentation.
-# The default value is: NO.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
-# names in lower-case letters. If set to YES, upper-case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# and Mac users are advised to set this option to NO.
-# The default value is: system dependent.
-
-CASE_SENSE_NAMES = YES
-
-# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
-# their full class and namespace scopes in the documentation. If set to YES, the
-# scope will be hidden.
-# The default value is: NO.
-
-HIDE_SCOPE_NAMES = NO
-
-# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
-# append additional text to a page's title, such as Class Reference. If set to
-# YES the compound reference will be hidden.
-# The default value is: NO.
-
-HIDE_COMPOUND_REFERENCE= NO
-
-# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
-# the files that are included by a file in the documentation of that file.
-# The default value is: YES.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
-# grouped member an include statement to the documentation, telling the reader
-# which file to include in order to use the member.
-# The default value is: NO.
-
-SHOW_GROUPED_MEMB_INC = NO
-
-# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
-# files with double quotes in the documentation rather than with sharp brackets.
-# The default value is: NO.
-
-FORCE_LOCAL_INCLUDES = NO
-
-# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
-# documentation for inline members.
-# The default value is: YES.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
-# (detailed) documentation of file and class members alphabetically by member
-# name. If set to NO, the members will appear in declaration order.
-# The default value is: YES.
-
-SORT_MEMBER_DOCS = YES
-
-# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
-# descriptions of file, namespace and class members alphabetically by member
-# name. If set to NO, the members will appear in declaration order. Note that
-# this will also influence the order of the classes in the class list.
-# The default value is: NO.
-
-SORT_BRIEF_DOCS = NO
-
-# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
-# (brief and detailed) documentation of class members so that constructors and
-# destructors are listed first. If set to NO the constructors will appear in the
-# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
-# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
-# member documentation.
-# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
-# detailed member documentation.
-# The default value is: NO.
-
-SORT_MEMBERS_CTORS_1ST = NO
-
-# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
-# of group names into alphabetical order. If set to NO the group names will
-# appear in their defined order.
-# The default value is: NO.
-
-SORT_GROUP_NAMES = NO
-
-# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
-# fully-qualified names, including namespaces. If set to NO, the class list will
-# be sorted only by class name, not including the namespace part.
-# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
-# Note: This option applies only to the class list, not to the alphabetical
-# list.
-# The default value is: NO.
-
-SORT_BY_SCOPE_NAME = NO
-
-# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
-# type resolution of all parameters of a function it will reject a match between
-# the prototype and the implementation of a member function even if there is
-# only one candidate or it is obvious which candidate to choose by doing a
-# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
-# accept a match between prototype and implementation in such cases.
-# The default value is: NO.
-
-STRICT_PROTO_MATCHING = NO
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
-# list. This list is created by putting \todo commands in the documentation.
-# The default value is: YES.
-
-GENERATE_TODOLIST = YES
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
-# list. This list is created by putting \test commands in the documentation.
-# The default value is: YES.
-
-GENERATE_TESTLIST = YES
-
-# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
-# list. This list is created by putting \bug commands in the documentation.
-# The default value is: YES.
-
-GENERATE_BUGLIST = YES
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
-# the deprecated list. This list is created by putting \deprecated commands in
-# the documentation.
-# The default value is: YES.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# The ENABLED_SECTIONS tag can be used to enable conditional documentation
-# sections, marked by \if ... \endif and \cond
-# ... \endcond blocks.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
-# initial value of a variable or macro / define can have for it to appear in the
-# documentation. If the initializer consists of more lines than specified here
-# it will be hidden. Use a value of 0 to hide initializers completely. The
-# appearance of the value of individual variables and macros / defines can be
-# controlled using \showinitializer or \hideinitializer command in the
-# documentation regardless of this setting.
-# Minimum value: 0, maximum value: 10000, default value: 30.
-
-MAX_INITIALIZER_LINES = 30
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
-# the bottom of the documentation of classes and structs. If set to YES, the
-# list will mention the files that were used to generate the documentation.
-# The default value is: YES.
-
-SHOW_USED_FILES = YES
-
-# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
-# will remove the Files entry from the Quick Index and from the Folder Tree View
-# (if specified).
-# The default value is: YES.
-
-SHOW_FILES = YES
-
-# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
-# page. This will remove the Namespaces entry from the Quick Index and from the
-# Folder Tree View (if specified).
-# The default value is: YES.
-
-SHOW_NAMESPACES = YES
-
-# The FILE_VERSION_FILTER tag can be used to specify a program or script that
-# doxygen should invoke to get the current version for each file (typically from
-# the version control system). Doxygen will invoke the program by executing (via
-# popen()) the command command input-file, where command is the value of the
-# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
-# by doxygen. Whatever the program writes to standard output is used as the file
-# version. For an example see the documentation.
-
-FILE_VERSION_FILTER =
-
-# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
-# by doxygen. The layout file controls the global structure of the generated
-# output files in an output format independent way. To create the layout file
-# that represents doxygen's defaults, run doxygen with the -l option. You can
-# optionally specify a file name after the option, if omitted DoxygenLayout.xml
-# will be used as the name of the layout file.
-#
-# Note that if you run doxygen from a directory containing a file called
-# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
-# tag is left empty.
-
-LAYOUT_FILE =
-
-# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
-# the reference definitions. This must be a list of .bib files. The .bib
-# extension is automatically appended if omitted. This requires the bibtex tool
-# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
-# For LaTeX the style of the bibliography can be controlled using
-# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
-# search path. See also \cite for info how to create references.
-
-CITE_BIB_FILES =
-
-#---------------------------------------------------------------------------
-# Configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated to
-# standard output by doxygen. If QUIET is set to YES this implies that the
-# messages are off.
-# The default value is: NO.
-
-QUIET = NO
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
-# this implies that the warnings are on.
-#
-# Tip: Turn warnings on while writing the documentation.
-# The default value is: YES.
-
-WARNINGS = YES
-
-# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
-# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
-# will automatically be disabled.
-# The default value is: YES.
-
-WARN_IF_UNDOCUMENTED = YES
-
-# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
-# potential errors in the documentation, such as not documenting some parameters
-# in a documented function, or documenting parameters that don't exist or using
-# markup commands wrongly.
-# The default value is: YES.
-
-WARN_IF_DOC_ERROR = YES
-
-# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
-# are documented, but have no documentation for their parameters or return
-# value. If set to NO, doxygen will only warn about wrong or incomplete
-# parameter documentation, but not about the absence of documentation.
-# The default value is: NO.
-
-WARN_NO_PARAMDOC = NO
-
-# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
-# a warning is encountered.
-# The default value is: NO.
-
-WARN_AS_ERROR = NO
-
-# The WARN_FORMAT tag determines the format of the warning messages that doxygen
-# can produce. The string should contain the $file, $line, and $text tags, which
-# will be replaced by the file and line number from which the warning originated
-# and the warning text. Optionally the format may contain $version, which will
-# be replaced by the version of the file (if it could be obtained via
-# FILE_VERSION_FILTER)
-# The default value is: $file:$line: $text.
-
-WARN_FORMAT = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning and error
-# messages should be written. If left blank the output is written to standard
-# error (stderr).
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag is used to specify the files and/or directories that contain
-# documented source files. You may enter file names like myfile.cpp or
-# directories like /usr/src/myproject. Separate the files or directories with
-# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
-# Note: If this tag is empty the current directory is searched.
-
-INPUT = ./
-
-# This tag can be used to specify the character encoding of the source files
-# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
-# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
-# documentation (see: http://www.gnu.org/software/libiconv) for the list of
-# possible encodings.
-# The default value is: UTF-8.
-
-INPUT_ENCODING = UTF-8
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
-# *.h) to filter out the source-files in the directories.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# read by doxygen.
-#
-# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
-# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
-# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
-# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
-# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf.
-
-FILE_PATTERNS = *.c \
- *.cc \
- *.cxx \
- *.cpp \
- *.c++ \
- *.java \
- *.ii \
- *.ixx \
- *.ipp \
- *.i++ \
- *.inl \
- *.idl \
- *.ddl \
- *.odl \
- *.h \
- *.hh \
- *.hxx \
- *.hpp \
- *.h++ \
- *.cs \
- *.d \
- *.php \
- *.php4 \
- *.php5 \
- *.phtml \
- *.inc \
- *.m \
- *.markdown \
- *.md \
- *.mm \
- *.dox \
- *.py \
- *.pyw \
- *.f90 \
- *.f95 \
- *.f03 \
- *.f08 \
- *.f \
- *.for \
- *.tcl \
- *.vhd \
- *.vhdl \
- *.ucf \
- *.qsf
-
-# The RECURSIVE tag can be used to specify whether or not subdirectories should
-# be searched for input files as well.
-# The default value is: NO.
-
-RECURSIVE = NO
-
-# The EXCLUDE tag can be used to specify files and/or directories that should be
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-#
-# Note that relative paths are relative to the directory from which doxygen is
-# run.
-
-EXCLUDE =
-
-# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
-# directories that are symbolic links (a Unix file system feature) are excluded
-# from the input.
-# The default value is: NO.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories for example use the pattern */test/*
-
-EXCLUDE_PATTERNS =
-
-# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
-# (namespaces, classes, functions, etc.) that should be excluded from the
-# output. The symbol name can be a fully qualified name, a word, or if the
-# wildcard * is used, a substring. Examples: ANamespace, AClass,
-# AClass::ANamespace, ANamespace::*Test
-#
-# Note that the wildcards are matched against the file with absolute path, so to
-# exclude all test directories use the pattern */test/*
-
-EXCLUDE_SYMBOLS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or directories
-# that contain example code fragments that are included (see the \include
-# command).
-
-EXAMPLE_PATH =
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
-# *.h) to filter out the source-files in the directories. If left blank all
-# files are included.
-
-EXAMPLE_PATTERNS = *
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude commands
-# irrespective of the value of the RECURSIVE tag.
-# The default value is: NO.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or directories
-# that contain images that are to be included in the documentation (see the
-# \image command).
-
-IMAGE_PATH =
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command:
-#
-#
-#
-# where is the value of the INPUT_FILTER tag, and is the
-# name of an input file. Doxygen will then use the output that the filter
-# program writes to standard output. If FILTER_PATTERNS is specified, this tag
-# will be ignored.
-#
-# Note that the filter must not add or remove lines; it is applied before the
-# code is scanned, but not when the output code is generated. If lines are added
-# or removed, the anchors will not be placed correctly.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# properly processed by doxygen.
-
-INPUT_FILTER =
-
-# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
-# basis. Doxygen will compare the file name with each pattern and apply the
-# filter if there is a match. The filters are a list of the form: pattern=filter
-# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
-# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
-# patterns match the file name, INPUT_FILTER is applied.
-#
-# Note that for custom extensions or not directly supported extensions you also
-# need to set EXTENSION_MAPPING for the extension otherwise the files are not
-# properly processed by doxygen.
-
-FILTER_PATTERNS =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER) will also be used to filter the input files that are used for
-# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
-# The default value is: NO.
-
-FILTER_SOURCE_FILES = NO
-
-# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
-# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
-# it is also possible to disable source filtering for a specific pattern using
-# *.ext= (so without naming a filter).
-# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
-
-FILTER_SOURCE_PATTERNS =
-
-# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
-# is part of the input, its contents will be placed on the main page
-# (index.html). This can be useful if you have a project on for instance GitHub
-# and want to reuse the introduction page also for the doxygen output.
-
-USE_MDFILE_AS_MAINPAGE =
-
-#---------------------------------------------------------------------------
-# Configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
-# generated. Documented entities will be cross-referenced with these sources.
-#
-# Note: To get rid of all source code in the generated output, make sure that
-# also VERBATIM_HEADERS is set to NO.
-# The default value is: NO.
-
-SOURCE_BROWSER = NO
-
-# Setting the INLINE_SOURCES tag to YES will include the body of functions,
-# classes and enums directly into the documentation.
-# The default value is: NO.
-
-INLINE_SOURCES = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
-# special comment blocks from generated source code fragments. Normal C, C++ and
-# Fortran comments will always remain visible.
-# The default value is: YES.
-
-STRIP_CODE_COMMENTS = YES
-
-# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
-# function all documented functions referencing it will be listed.
-# The default value is: NO.
-
-REFERENCED_BY_RELATION = NO
-
-# If the REFERENCES_RELATION tag is set to YES then for each documented function
-# all documented entities called/used by that function will be listed.
-# The default value is: NO.
-
-REFERENCES_RELATION = NO
-
-# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
-# to YES then the hyperlinks from functions in REFERENCES_RELATION and
-# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
-# link to the documentation.
-# The default value is: YES.
-
-REFERENCES_LINK_SOURCE = YES
-
-# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
-# source code will show a tooltip with additional information such as prototype,
-# brief description and links to the definition and documentation. Since this
-# will make the HTML file larger and loading of large files a bit slower, you
-# can opt to disable this feature.
-# The default value is: YES.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-SOURCE_TOOLTIPS = YES
-
-# If the USE_HTAGS tag is set to YES then the references to source code will
-# point to the HTML generated by the htags(1) tool instead of doxygen built-in
-# source browser. The htags tool is part of GNU's global source tagging system
-# (see http://www.gnu.org/software/global/global.html). You will need version
-# 4.8.6 or higher.
-#
-# To use it do the following:
-# - Install the latest version of global
-# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
-# - Make sure the INPUT points to the root of the source tree
-# - Run doxygen as normal
-#
-# Doxygen will invoke htags (and that will in turn invoke gtags), so these
-# tools must be available from the command line (i.e. in the search path).
-#
-# The result: instead of the source browser generated by doxygen, the links to
-# source code will now point to the output of htags.
-# The default value is: NO.
-# This tag requires that the tag SOURCE_BROWSER is set to YES.
-
-USE_HTAGS = NO
-
-# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
-# verbatim copy of the header file for each class for which an include is
-# specified. Set to NO to disable this.
-# See also: Section \class.
-# The default value is: YES.
-
-VERBATIM_HEADERS = YES
-
-# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
-# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the
-# cost of reduced performance. This can be particularly helpful with template
-# rich C++ code for which doxygen's built-in parser lacks the necessary type
-# information.
-# Note: The availability of this option depends on whether or not doxygen was
-# generated with the -Duse-libclang=ON option for CMake.
-# The default value is: NO.
-
-CLANG_ASSISTED_PARSING = NO
-
-# If clang assisted parsing is enabled you can provide the compiler with command
-# line options that you would normally use when invoking the compiler. Note that
-# the include paths will already be set by doxygen for the files and directories
-# specified with INPUT and INCLUDE_PATH.
-# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
-
-CLANG_OPTIONS =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
-# compounds will be generated. Enable this if the project contains a lot of
-# classes, structs, unions or interfaces.
-# The default value is: YES.
-
-ALPHABETICAL_INDEX = YES
-
-# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
-# which the alphabetical index list will be split.
-# Minimum value: 1, maximum value: 20, default value: 5.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all classes will
-# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
-# can be used to specify a prefix (or a list of prefixes) that should be ignored
-# while generating the index headers.
-# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
-# The default value is: YES.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_OUTPUT = html
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
-# generated HTML page (for example: .htm, .php, .asp).
-# The default value is: .html.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
-# each generated HTML page. If the tag is left blank doxygen will generate a
-# standard header.
-#
-# To get valid HTML the header file that includes any scripts and style sheets
-# that doxygen needs, which is dependent on the configuration options used (e.g.
-# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
-# default header using
-# doxygen -w html new_header.html new_footer.html new_stylesheet.css
-# YourConfigFile
-# and then modify the file new_header.html. See also section "Doxygen usage"
-# for information on how to generate the default header that doxygen normally
-# uses.
-# Note: The header is subject to change so you typically have to regenerate the
-# default header when upgrading to a newer version of doxygen. For a description
-# of the possible markers and block names see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_HEADER =
-
-# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
-# generated HTML page. If the tag is left blank doxygen will generate a standard
-# footer. See HTML_HEADER for more information on how to generate a default
-# footer and what special commands can be used inside the footer. See also
-# section "Doxygen usage" for information on how to generate the default footer
-# that doxygen normally uses.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_FOOTER =
-
-# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
-# sheet that is used by each HTML page. It can be used to fine-tune the look of
-# the HTML output. If left blank doxygen will generate a default style sheet.
-# See also section "Doxygen usage" for information on how to generate the style
-# sheet that doxygen normally uses.
-# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
-# it is more robust and this tag (HTML_STYLESHEET) will in the future become
-# obsolete.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_STYLESHEET =
-
-# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
-# cascading style sheets that are included after the standard style sheets
-# created by doxygen. Using this option one can overrule certain style aspects.
-# This is preferred over using HTML_STYLESHEET since it does not replace the
-# standard style sheet and is therefore more robust against future updates.
-# Doxygen will copy the style sheet files to the output directory.
-# Note: The order of the extra style sheet files is of importance (e.g. the last
-# style sheet in the list overrules the setting of the previous ones in the
-# list). For an example see the documentation.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_STYLESHEET =
-
-# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the HTML output directory. Note
-# that these files will be copied to the base HTML output directory. Use the
-# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
-# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
-# files will be copied as-is; there are no commands or markers available.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_EXTRA_FILES =
-
-# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
-# will adjust the colors in the style sheet and background images according to
-# this color. Hue is specified as an angle on a colorwheel, see
-# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
-# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
-# purple, and 360 is red again.
-# Minimum value: 0, maximum value: 359, default value: 220.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_HUE = 220
-
-# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
-# in the HTML output. For a value of 0 the output will use grayscales only. A
-# value of 255 will produce the most vivid colors.
-# Minimum value: 0, maximum value: 255, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_SAT = 100
-
-# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
-# luminance component of the colors in the HTML output. Values below 100
-# gradually make the output lighter, whereas values above 100 make the output
-# darker. The value divided by 100 is the actual gamma applied, so 80 represents
-# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
-# change the gamma.
-# Minimum value: 40, maximum value: 240, default value: 80.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_COLORSTYLE_GAMMA = 80
-
-# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
-# page will contain the date and time when the page was generated. Setting this
-# to YES can help to show when doxygen was last run and thus if the
-# documentation is up to date.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_TIMESTAMP = NO
-
-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
-# documentation will contain sections that can be hidden and shown after the
-# page has loaded.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_DYNAMIC_SECTIONS = NO
-
-# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
-# shown in the various tree structured indices initially; the user can expand
-# and collapse entries dynamically later on. Doxygen will expand the tree to
-# such a level that at most the specified number of entries are visible (unless
-# a fully collapsed tree already exceeds this amount). So setting the number of
-# entries 1 will produce a full collapsed tree by default. 0 is a special value
-# representing an infinite number of entries and will result in a full expanded
-# tree by default.
-# Minimum value: 0, maximum value: 9999, default value: 100.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-HTML_INDEX_NUM_ENTRIES = 100
-
-# If the GENERATE_DOCSET tag is set to YES, additional index files will be
-# generated that can be used as input for Apple's Xcode 3 integrated development
-# environment (see: http://developer.apple.com/tools/xcode/), introduced with
-# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
-# Makefile in the HTML output directory. Running make will produce the docset in
-# that directory and running make install will install the docset in
-# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
-# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
-# for more information.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_DOCSET = NO
-
-# This tag determines the name of the docset feed. A documentation feed provides
-# an umbrella under which multiple documentation sets from a single provider
-# (such as a company or product suite) can be grouped.
-# The default value is: Doxygen generated docs.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_FEEDNAME = "Doxygen generated docs"
-
-# This tag specifies a string that should uniquely identify the documentation
-# set bundle. This should be a reverse domain-name style string, e.g.
-# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_BUNDLE_ID = org.doxygen.Project
-
-# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
-# the documentation publisher. This should be a reverse domain-name style
-# string, e.g. com.mycompany.MyDocSet.documentation.
-# The default value is: org.doxygen.Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_ID = org.doxygen.Publisher
-
-# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
-# The default value is: Publisher.
-# This tag requires that the tag GENERATE_DOCSET is set to YES.
-
-DOCSET_PUBLISHER_NAME = Publisher
-
-# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
-# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
-# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
-# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
-# Windows.
-#
-# The HTML Help Workshop contains a compiler that can convert all HTML output
-# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
-# files are now used as the Windows 98 help format, and will replace the old
-# Windows help format (.hlp) on all Windows platforms in the future. Compressed
-# HTML files also contain an index, a table of contents, and you can search for
-# words in the documentation. The HTML workshop also contains a viewer for
-# compressed HTML files.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_HTMLHELP = NO
-
-# The CHM_FILE tag can be used to specify the file name of the resulting .chm
-# file. You can add a path in front of the file if the result should not be
-# written to the html output directory.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_FILE =
-
-# The HHC_LOCATION tag can be used to specify the location (absolute path
-# including file name) of the HTML help compiler (hhc.exe). If non-empty,
-# doxygen will try to run the HTML help compiler on the generated index.hhp.
-# The file has to be specified with full path.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-HHC_LOCATION =
-
-# The GENERATE_CHI flag controls if a separate .chi index file is generated
-# (YES) or that it should be included in the master .chm file (NO).
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-GENERATE_CHI = NO
-
-# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
-# and project file content.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-CHM_INDEX_ENCODING =
-
-# The BINARY_TOC flag controls whether a binary table of contents is generated
-# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
-# enables the Previous and Next buttons.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members to
-# the table of contents of the HTML help documentation and to the tree view.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
-
-TOC_EXPAND = NO
-
-# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
-# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
-# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
-# (.qch) of the generated HTML documentation.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_QHP = NO
-
-# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
-# the file name of the resulting .qch file. The path specified is relative to
-# the HTML output folder.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QCH_FILE =
-
-# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
-# Project output. For more information please see Qt Help Project / Namespace
-# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_NAMESPACE = org.doxygen.Project
-
-# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
-# Help Project output. For more information please see Qt Help Project / Virtual
-# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
-# folders).
-# The default value is: doc.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_VIRTUAL_FOLDER = doc
-
-# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
-# filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_NAME =
-
-# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
-# custom filter to add. For more information please see Qt Help Project / Custom
-# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
-# filters).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_CUST_FILTER_ATTRS =
-
-# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
-# project's filter section matches. Qt Help Project / Filter Attributes (see:
-# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHP_SECT_FILTER_ATTRS =
-
-# The QHG_LOCATION tag can be used to specify the location of Qt's
-# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
-# generated .qhp file.
-# This tag requires that the tag GENERATE_QHP is set to YES.
-
-QHG_LOCATION =
-
-# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
-# generated, together with the HTML files, they form an Eclipse help plugin. To
-# install this plugin and make it available under the help contents menu in
-# Eclipse, the contents of the directory containing the HTML and XML files needs
-# to be copied into the plugins directory of eclipse. The name of the directory
-# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
-# After copying Eclipse needs to be restarted before the help appears.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_ECLIPSEHELP = NO
-
-# A unique identifier for the Eclipse help plugin. When installing the plugin
-# the directory name containing the HTML and XML files should also have this
-# name. Each documentation set should have its own identifier.
-# The default value is: org.doxygen.Project.
-# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
-
-ECLIPSE_DOC_ID = org.doxygen.Project
-
-# If you want full control over the layout of the generated HTML pages it might
-# be necessary to disable the index and replace it with your own. The
-# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
-# of each HTML page. A value of NO enables the index and the value YES disables
-# it. Since the tabs in the index contain the same information as the navigation
-# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-DISABLE_INDEX = NO
-
-# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
-# structure should be generated to display hierarchical information. If the tag
-# value is set to YES, a side panel will be generated containing a tree-like
-# index structure (just like the one that is generated for HTML Help). For this
-# to work a browser that supports JavaScript, DHTML, CSS and frames is required
-# (i.e. any modern browser). Windows users are probably better off using the
-# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
-# further fine-tune the look of the index. As an example, the default style
-# sheet generated by doxygen has an example that shows how to put an image at
-# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
-# the same information as the tab index, you could consider setting
-# DISABLE_INDEX to YES when enabling this option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-GENERATE_TREEVIEW = NO
-
-# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
-# doxygen will group on one line in the generated HTML documentation.
-#
-# Note that a value of 0 will completely suppress the enum values from appearing
-# in the overview section.
-# Minimum value: 0, maximum value: 20, default value: 4.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-ENUM_VALUES_PER_LINE = 4
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
-# to set the initial width (in pixels) of the frame in which the tree is shown.
-# Minimum value: 0, maximum value: 1500, default value: 250.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-TREEVIEW_WIDTH = 250
-
-# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
-# external symbols imported via tag files in a separate window.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-EXT_LINKS_IN_WINDOW = NO
-
-# Use this tag to change the font size of LaTeX formulas included as images in
-# the HTML documentation. When you change the font size after a successful
-# doxygen run you need to manually remove any form_*.png images from the HTML
-# output directory to force them to be regenerated.
-# Minimum value: 8, maximum value: 50, default value: 10.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_FONTSIZE = 10
-
-# Use the FORMULA_TRANPARENT tag to determine whether or not the images
-# generated for formulas are transparent PNGs. Transparent PNGs are not
-# supported properly for IE 6.0, but are supported on all modern browsers.
-#
-# Note that when changing this option you need to delete any form_*.png files in
-# the HTML output directory before the changes have effect.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-FORMULA_TRANSPARENT = YES
-
-# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
-# http://www.mathjax.org) which uses client side Javascript for the rendering
-# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
-# installed or if you want to formulas look prettier in the HTML output. When
-# enabled you may also need to install MathJax separately and configure the path
-# to it using the MATHJAX_RELPATH option.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-USE_MATHJAX = NO
-
-# When MathJax is enabled you can set the default output format to be used for
-# the MathJax output. See the MathJax site (see:
-# http://docs.mathjax.org/en/latest/output.html) for more details.
-# Possible values are: HTML-CSS (which is slower, but has the best
-# compatibility), NativeMML (i.e. MathML) and SVG.
-# The default value is: HTML-CSS.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_FORMAT = HTML-CSS
-
-# When MathJax is enabled you need to specify the location relative to the HTML
-# output directory using the MATHJAX_RELPATH option. The destination directory
-# should contain the MathJax.js script. For instance, if the mathjax directory
-# is located at the same level as the HTML output directory, then
-# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
-# Content Delivery Network so you can quickly see the result without installing
-# MathJax. However, it is strongly recommended to install a local copy of
-# MathJax from http://www.mathjax.org before deployment.
-# The default value is: http://cdn.mathjax.org/mathjax/latest.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
-
-# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
-# extension names that should be enabled during MathJax rendering. For example
-# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_EXTENSIONS =
-
-# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
-# of code that will be used on startup of the MathJax code. See the MathJax site
-# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
-# example see the documentation.
-# This tag requires that the tag USE_MATHJAX is set to YES.
-
-MATHJAX_CODEFILE =
-
-# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
-# the HTML output. The underlying search engine uses javascript and DHTML and
-# should work on any modern browser. Note that when using HTML help
-# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
-# there is already a search function so this one should typically be disabled.
-# For large projects the javascript based search engine can be slow, then
-# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
-# search using the keyboard; to jump to the search box use + S
-# (what the is depends on the OS and browser, but it is typically
-# , /, or both). Inside the search box use the to jump into the search results window, the results can be navigated
-# using the . Press to select an item or to cancel
-# the search. The filter options can be selected when the cursor is inside the
-# search box by pressing +. Also here use the
-# to select a filter and or to activate or cancel the filter
-# option.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_HTML is set to YES.
-
-SEARCHENGINE = YES
-
-# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
-# implemented using a web server instead of a web client using Javascript. There
-# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
-# setting. When disabled, doxygen will generate a PHP script for searching and
-# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
-# and searching needs to be provided by external tools. See the section
-# "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SERVER_BASED_SEARCH = NO
-
-# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
-# script for searching. Instead the search results are written to an XML file
-# which needs to be processed by an external indexer. Doxygen will invoke an
-# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
-# search results.
-#
-# Doxygen ships with an example indexer (doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/).
-#
-# See the section "External Indexing and Searching" for details.
-# The default value is: NO.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH = NO
-
-# The SEARCHENGINE_URL should point to a search engine hosted by a web server
-# which will return the search results when EXTERNAL_SEARCH is enabled.
-#
-# Doxygen ships with an example indexer (doxyindexer) and search engine
-# (doxysearch.cgi) which are based on the open source search engine library
-# Xapian (see: http://xapian.org/). See the section "External Indexing and
-# Searching" for details.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHENGINE_URL =
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
-# search data is written to a file for indexing by an external tool. With the
-# SEARCHDATA_FILE tag the name of this file can be specified.
-# The default file is: searchdata.xml.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-SEARCHDATA_FILE = searchdata.xml
-
-# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
-# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
-# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
-# projects and redirect the results back to the right project.
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTERNAL_SEARCH_ID =
-
-# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
-# projects other than the one defined by this configuration file, but that are
-# all added to the same external search index. Each project needs to have a
-# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
-# to a relative location where the documentation can be found. The format is:
-# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
-# This tag requires that the tag SEARCHENGINE is set to YES.
-
-EXTRA_SEARCH_MAPPINGS =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
-# The default value is: YES.
-
-GENERATE_LATEX = YES
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: latex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_OUTPUT = latex
-
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
-# invoked.
-#
-# Note that when enabling USE_PDFLATEX this option is only used for generating
-# bitmaps for formulas in the HTML output, but not in the Makefile that is
-# written to the output directory.
-# The default file is: latex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_CMD_NAME = latex
-
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
-# index for LaTeX.
-# The default file is: makeindex.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-MAKEINDEX_CMD_NAME = makeindex
-
-# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
-# documents. This may be useful for small projects and may help to save some
-# trees in general.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-COMPACT_LATEX = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used by the
-# printer.
-# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
-# 14 inches) and executive (7.25 x 10.5 inches).
-# The default value is: a4.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-PAPER_TYPE = a4
-
-# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
-# that should be included in the LaTeX output. The package can be specified just
-# by its name or with the correct syntax as to be used with the LaTeX
-# \usepackage command. To get the times font for instance you can specify :
-# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
-# To use the option intlimits with the amsmath package you can specify:
-# EXTRA_PACKAGES=[intlimits]{amsmath}
-# If left blank no extra packages will be included.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-EXTRA_PACKAGES =
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
-# generated LaTeX document. The header should contain everything until the first
-# chapter. If it is left blank doxygen will generate a standard header. See
-# section "Doxygen usage" for information on how to let doxygen write the
-# default header to a separate file.
-#
-# Note: Only use a user-defined header if you know what you are doing! The
-# following commands have a special meaning inside the header: $title,
-# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
-# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
-# string, for the replacement values of the other commands the user is referred
-# to HTML_HEADER.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_HEADER =
-
-# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
-# generated LaTeX document. The footer should contain everything after the last
-# chapter. If it is left blank doxygen will generate a standard footer. See
-# LATEX_HEADER for more information on how to generate a default footer and what
-# special commands can be used inside the footer.
-#
-# Note: Only use a user-defined footer if you know what you are doing!
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_FOOTER =
-
-# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
-# LaTeX style sheets that are included after the standard style sheets created
-# by doxygen. Using this option one can overrule certain style aspects. Doxygen
-# will copy the style sheet files to the output directory.
-# Note: The order of the extra style sheet files is of importance (e.g. the last
-# style sheet in the list overrules the setting of the previous ones in the
-# list).
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_EXTRA_STYLESHEET =
-
-# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
-# other source files which should be copied to the LATEX_OUTPUT output
-# directory. Note that the files will be copied as-is; there are no commands or
-# markers available.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_EXTRA_FILES =
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
-# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
-# contain links (just like the HTML output) instead of page references. This
-# makes the output suitable for online browsing using a PDF viewer.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-PDF_HYPERLINKS = YES
-
-# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
-# the PDF file directly from the LaTeX files. Set this option to YES, to get a
-# higher quality PDF documentation.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-USE_PDFLATEX = YES
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
-# command to the generated LaTeX files. This will instruct LaTeX to keep running
-# if errors occur, instead of asking the user for help. This option is also used
-# when generating formulas in HTML.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_BATCHMODE = NO
-
-# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
-# index chapters (such as File Index, Compound Index, etc.) in the output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_HIDE_INDICES = NO
-
-# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
-# code with syntax highlighting in the LaTeX output.
-#
-# Note that which sources are shown also depends on other settings such as
-# SOURCE_BROWSER.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_SOURCE_CODE = NO
-
-# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
-# bibliography, e.g. plainnat, or ieeetr. See
-# http://en.wikipedia.org/wiki/BibTeX and \cite for more info.
-# The default value is: plain.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_BIB_STYLE = plain
-
-# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
-# page will contain the date and time when the page was generated. Setting this
-# to NO can help when comparing the output of multiple runs.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_LATEX is set to YES.
-
-LATEX_TIMESTAMP = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
-# RTF output is optimized for Word 97 and may not look too pretty with other RTF
-# readers/editors.
-# The default value is: NO.
-
-GENERATE_RTF = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: rtf.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_OUTPUT = rtf
-
-# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
-# documents. This may be useful for small projects and may help to save some
-# trees in general.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-COMPACT_RTF = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
-# contain hyperlink fields. The RTF file will contain links (just like the HTML
-# output) instead of page references. This makes the output suitable for online
-# browsing using Word or some other Word compatible readers that support those
-# fields.
-#
-# Note: WordPad (write) and others do not support links.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_HYPERLINKS = NO
-
-# Load stylesheet definitions from file. Syntax is similar to doxygen's config
-# file, i.e. a series of assignments. You only have to provide replacements,
-# missing definitions are set to their default value.
-#
-# See also section "Doxygen usage" for information on how to generate the
-# default style sheet that doxygen normally uses.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_STYLESHEET_FILE =
-
-# Set optional variables used in the generation of an RTF document. Syntax is
-# similar to doxygen's config file. A template extensions file can be generated
-# using doxygen -e rtf extensionFile.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_EXTENSIONS_FILE =
-
-# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
-# with syntax highlighting in the RTF output.
-#
-# Note that which sources are shown also depends on other settings such as
-# SOURCE_BROWSER.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_RTF is set to YES.
-
-RTF_SOURCE_CODE = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
-# classes and files.
-# The default value is: NO.
-
-GENERATE_MAN = NO
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it. A directory man3 will be created inside the directory specified by
-# MAN_OUTPUT.
-# The default directory is: man.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_OUTPUT = man
-
-# The MAN_EXTENSION tag determines the extension that is added to the generated
-# man pages. In case the manual section does not start with a number, the number
-# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
-# optional.
-# The default value is: .3.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_EXTENSION = .3
-
-# The MAN_SUBDIR tag determines the name of the directory created within
-# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
-# MAN_EXTENSION with the initial . removed.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_SUBDIR =
-
-# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
-# will generate one additional man file for each entity documented in the real
-# man page(s). These additional files only source the real man page, but without
-# them the man command would be unable to find the correct page.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_MAN is set to YES.
-
-MAN_LINKS = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
-# captures the structure of the code including all documentation.
-# The default value is: NO.
-
-GENERATE_XML = NO
-
-# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
-# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
-# it.
-# The default directory is: xml.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_OUTPUT = xml
-
-# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
-# listings (including syntax highlighting and cross-referencing information) to
-# the XML output. Note that enabling this will significantly increase the size
-# of the XML output.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_XML is set to YES.
-
-XML_PROGRAMLISTING = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to the DOCBOOK output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
-# that can be used to generate PDF.
-# The default value is: NO.
-
-GENERATE_DOCBOOK = NO
-
-# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
-# front of it.
-# The default directory is: docbook.
-# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
-
-DOCBOOK_OUTPUT = docbook
-
-# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
-# program listings (including syntax highlighting and cross-referencing
-# information) to the DOCBOOK output. Note that enabling this will significantly
-# increase the size of the DOCBOOK output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
-
-DOCBOOK_PROGRAMLISTING = NO
-
-#---------------------------------------------------------------------------
-# Configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
-# AutoGen Definitions (see http://autogen.sf.net) file that captures the
-# structure of the code including all documentation. Note that this feature is
-# still experimental and incomplete at the moment.
-# The default value is: NO.
-
-GENERATE_AUTOGEN_DEF = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
-# file that captures the structure of the code including all documentation.
-#
-# Note that this feature is still experimental and incomplete at the moment.
-# The default value is: NO.
-
-GENERATE_PERLMOD = NO
-
-# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
-# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
-# output from the Perl module output.
-# The default value is: NO.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_LATEX = NO
-
-# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
-# formatted so it can be parsed by a human reader. This is useful if you want to
-# understand what is going on. On the other hand, if this tag is set to NO, the
-# size of the Perl module output will be much smaller and Perl will parse it
-# just the same.
-# The default value is: YES.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_PRETTY = YES
-
-# The names of the make variables in the generated doxyrules.make file are
-# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
-# so different doxyrules.make files included by the same Makefile don't
-# overwrite each other's variables.
-# This tag requires that the tag GENERATE_PERLMOD is set to YES.
-
-PERLMOD_MAKEVAR_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
-# C-preprocessor directives found in the sources and include files.
-# The default value is: YES.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
-# in the source code. If set to NO, only conditional compilation will be
-# performed. Macro expansion can be done in a controlled way by setting
-# EXPAND_ONLY_PREDEF to YES.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-MACRO_EXPANSION = NO
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
-# the macro expansion is limited to the macros specified with the PREDEFINED and
-# EXPAND_AS_DEFINED tags.
-# The default value is: NO.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_ONLY_PREDEF = NO
-
-# If the SEARCH_INCLUDES tag is set to YES, the include files in the
-# INCLUDE_PATH will be searched if a #include is found.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by the
-# preprocessor.
-# This tag requires that the tag SEARCH_INCLUDES is set to YES.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will be
-# used.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that are
-# defined before the preprocessor is started (similar to the -D option of e.g.
-# gcc). The argument of the tag is a list of macros of the form: name or
-# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
-# is assumed. To prevent a macro definition from being undefined via #undef or
-# recursively expanded use the := operator instead of the = operator.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-PREDEFINED =
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
-# tag can be used to specify a list of macro names that should be expanded. The
-# macro definition that is found in the sources will be used. Use the PREDEFINED
-# tag if you want to use a different macro definition that overrules the
-# definition found in the source code.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-EXPAND_AS_DEFINED =
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
-# remove all references to function-like macros that are alone on a line, have
-# an all uppercase name, and do not end with a semicolon. Such function macros
-# are typically used for boiler-plate code, and will confuse the parser if not
-# removed.
-# The default value is: YES.
-# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration options related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES tag can be used to specify one or more tag files. For each tag
-# file the location of the external documentation should be added. The format of
-# a tag file without this location is as follows:
-# TAGFILES = file1 file2 ...
-# Adding location for the tag files is done as follows:
-# TAGFILES = file1=loc1 "file2 = loc2" ...
-# where loc1 and loc2 can be relative or absolute paths or URLs. See the
-# section "Linking to external documentation" for more information about the use
-# of tag files.
-# Note: Each tag file must have a unique name (where the name does NOT include
-# the path). If a tag file is not located in the directory in which doxygen is
-# run, you must also specify the path to the tagfile here.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
-# tag file that is based on the input files it reads. See section "Linking to
-# external documentation" for more information about the usage of tag files.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
-# the class index. If set to NO, only the inherited external classes will be
-# listed.
-# The default value is: NO.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will be
-# listed.
-# The default value is: YES.
-
-EXTERNAL_GROUPS = YES
-
-# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
-# the related pages index. If set to NO, only the current project's pages will
-# be listed.
-# The default value is: YES.
-
-EXTERNAL_PAGES = YES
-
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of 'which perl').
-# The default file (with absolute path) is: /usr/bin/perl.
-
-PERL_PATH = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
-# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
-# NO turns the diagrams off. Note that this option also works with HAVE_DOT
-# disabled, but it is recommended to install and use dot, since it yields more
-# powerful graphs.
-# The default value is: YES.
-
-CLASS_DIAGRAMS = YES
-
-# You can define message sequence charts within doxygen comments using the \msc
-# command. Doxygen will then run the mscgen tool (see:
-# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
-# documentation. The MSCGEN_PATH tag allows you to specify the directory where
-# the mscgen tool resides. If left empty the tool is assumed to be found in the
-# default search path.
-
-MSCGEN_PATH =
-
-# You can include diagrams made with dia in doxygen documentation. Doxygen will
-# then run dia to produce the diagram and insert it in the documentation. The
-# DIA_PATH tag allows you to specify the directory where the dia binary resides.
-# If left empty dia is assumed to be found in the default search path.
-
-DIA_PATH =
-
-# If set to YES the inheritance and collaboration graphs will hide inheritance
-# and usage relations if the target is undocumented or is not a class.
-# The default value is: YES.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz (see:
-# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
-# Bell Labs. The other options in this section have no effect if this option is
-# set to NO
-# The default value is: YES.
-
-HAVE_DOT = YES
-
-# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
-# to run in parallel. When set to 0 doxygen will base this on the number of
-# processors available in the system. You can set it explicitly to a value
-# larger than 0 to get control over the balance between CPU load and processing
-# speed.
-# Minimum value: 0, maximum value: 32, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_NUM_THREADS = 0
-
-# When you want a differently looking font in the dot files that doxygen
-# generates you can specify the font name using DOT_FONTNAME. You need to make
-# sure dot is able to find the font, which can be done by putting it in a
-# standard location or by setting the DOTFONTPATH environment variable or by
-# setting DOT_FONTPATH to the directory containing the font.
-# The default value is: Helvetica.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTNAME = Helvetica
-
-# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
-# dot graphs.
-# Minimum value: 4, maximum value: 24, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTSIZE = 10
-
-# By default doxygen will tell dot to use the default font as specified with
-# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
-# the path where dot can find it using this tag.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_FONTPATH =
-
-# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
-# each documented class showing the direct and indirect inheritance relations.
-# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CLASS_GRAPH = YES
-
-# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
-# graph for each documented class showing the direct and indirect implementation
-# dependencies (inheritance, containment, and class references variables) of the
-# class with other documented classes.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-COLLABORATION_GRAPH = YES
-
-# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
-# groups, showing the direct groups dependencies.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GROUP_GRAPHS = YES
-
-# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
-# collaboration diagrams in a style similar to the OMG's Unified Modeling
-# Language.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LOOK = NO
-
-# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
-# class node. If there are many fields or methods and many nodes the graph may
-# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
-# number of items for each type to make the size more manageable. Set this to 0
-# for no limit. Note that the threshold may be exceeded by 50% before the limit
-# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
-# but if the number exceeds 15, the total amount of fields shown is limited to
-# 10.
-# Minimum value: 0, maximum value: 100, default value: 10.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-UML_LIMIT_NUM_FIELDS = 10
-
-# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
-# collaboration graphs will show the relations between templates and their
-# instances.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-TEMPLATE_RELATIONS = NO
-
-# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
-# YES then doxygen will generate a graph for each documented file showing the
-# direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDE_GRAPH = YES
-
-# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
-# set to YES then doxygen will generate a graph for each documented file showing
-# the direct and indirect include dependencies of the file with other documented
-# files.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INCLUDED_BY_GRAPH = YES
-
-# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable call graphs for selected
-# functions only using the \callgraph command. Disabling a call graph can be
-# accomplished by means of the command \hidecallgraph.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALL_GRAPH = NO
-
-# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
-# dependency graph for every global function or class method.
-#
-# Note that enabling this option will significantly increase the time of a run.
-# So in most cases it will be better to enable caller graphs for selected
-# functions only using the \callergraph command. Disabling a caller graph can be
-# accomplished by means of the command \hidecallergraph.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-CALLER_GRAPH = NO
-
-# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
-# hierarchy of all classes instead of a textual one.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GRAPHICAL_HIERARCHY = YES
-
-# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
-# dependencies a directory has on other directories in a graphical way. The
-# dependency relations are determined by the #include relations between the
-# files in the directories.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DIRECTORY_GRAPH = YES
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot. For an explanation of the image formats see the section
-# output formats in the documentation of the dot tool (Graphviz (see:
-# http://www.graphviz.org/)).
-# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
-# to make the SVG files visible in IE 9+ (other browsers do not have this
-# requirement).
-# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd,
-# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo,
-# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo,
-# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
-# png:gdiplus:gdiplus.
-# The default value is: png.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_IMAGE_FORMAT = png
-
-# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
-# enable generation of interactive SVG images that allow zooming and panning.
-#
-# Note that this requires a modern browser other than Internet Explorer. Tested
-# and working are Firefox, Chrome, Safari, and Opera.
-# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
-# the SVG files visible. Older versions of IE do not have SVG support.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-INTERACTIVE_SVG = NO
-
-# The DOT_PATH tag can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found in the path.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_PATH =
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the \dotfile
-# command).
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOTFILE_DIRS =
-
-# The MSCFILE_DIRS tag can be used to specify one or more directories that
-# contain msc files that are included in the documentation (see the \mscfile
-# command).
-
-MSCFILE_DIRS =
-
-# The DIAFILE_DIRS tag can be used to specify one or more directories that
-# contain dia files that are included in the documentation (see the \diafile
-# command).
-
-DIAFILE_DIRS =
-
-# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
-# path where java can find the plantuml.jar file. If left blank, it is assumed
-# PlantUML is not used or called during a preprocessing step. Doxygen will
-# generate a warning when it encounters a \startuml command in this case and
-# will not generate output for the diagram.
-
-PLANTUML_JAR_PATH =
-
-# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
-# configuration file for plantuml.
-
-PLANTUML_CFG_FILE =
-
-# When using plantuml, the specified paths are searched for files specified by
-# the !include statement in a plantuml block.
-
-PLANTUML_INCLUDE_PATH =
-
-# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
-# that will be shown in the graph. If the number of nodes in a graph becomes
-# larger than this value, doxygen will truncate the graph, which is visualized
-# by representing a node as a red box. Note that doxygen if the number of direct
-# children of the root node in a graph is already larger than
-# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
-# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
-# Minimum value: 0, maximum value: 10000, default value: 50.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_GRAPH_MAX_NODES = 50
-
-# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
-# generated by dot. A depth value of 3 means that only nodes reachable from the
-# root by following a path via at most 3 edges will be shown. Nodes that lay
-# further from the root node will be omitted. Note that setting this option to 1
-# or 2 may greatly reduce the computation time needed for large code bases. Also
-# note that the size of a graph can be further restricted by
-# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
-# Minimum value: 0, maximum value: 1000, default value: 0.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-MAX_DOT_GRAPH_DEPTH = 0
-
-# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
-# background. This is disabled by default, because dot on Windows does not seem
-# to support this out of the box.
-#
-# Warning: Depending on the platform used, enabling this option may lead to
-# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
-# read).
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_TRANSPARENT = NO
-
-# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
-# files in one run (i.e. multiple -o and -T options on the command line). This
-# makes dot run faster, but since only newer versions of dot (>1.8.10) support
-# this, this feature is disabled by default.
-# The default value is: NO.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_MULTI_TARGETS = NO
-
-# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
-# explaining the meaning of the various boxes and arrows in the dot generated
-# graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-GENERATE_LEGEND = YES
-
-# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
-# files that are used to generate the various graphs.
-# The default value is: YES.
-# This tag requires that the tag HAVE_DOT is set to YES.
-
-DOT_CLEANUP = YES
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_api.h b/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_api.h
index c092b91..90d6b42 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_api.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_api.h
@@ -668,7 +668,7 @@ smtc_modem_return_code_t smtc_modem_get_tx_power_offset_db( uint8_t stack_id, in
*
* @return Modem return code as defined in @ref smtc_modem_return_code_t
* @retval SMTC_MODEM_RC_OK Command executed without errors
- * @retval SMTC_MODEM_RC_INVALID \p tx_pwr_offset_db is out of range
+ * @retval SMTC_MODEM_RC_INVALID \p tx_pwr_offset_db is out of [-30:30] range
* @retval SMTC_MODEM_RC_BUSY Modem is currently in test mode
* @retval SMTC_MODEM_RC_INVALID_STACK_ID Invalid \p stack_id
*/
@@ -720,7 +720,6 @@ smtc_modem_return_code_t smtc_modem_get_time( uint32_t* gps_time_s, uint32_t* gp
* @brief Trigger a single uplink requesting time using current enabled time synchronization service
*
* @param [in] stack_id Stack identifier
- * @param [in] sync_service Time synchronization service to use
*
* @return Modem return code as defined in @ref smtc_modem_return_code_t
* @retval SMTC_MODEM_RC_OK Command executed without errors
@@ -828,7 +827,7 @@ smtc_modem_return_code_t smtc_modem_time_get_sync_invalid_delay_s( uint32_t* syn
smtc_modem_return_code_t smtc_modem_get_status( uint8_t stack_id, smtc_modem_status_mask_t* status_mask );
/**
- * @brief Set and start the alarm timer
+ * @brief Set and start the alarm timer (up to 864000s ie 10 days)
*
* @remark When the timer expires, an alarm event is generated
*
@@ -836,6 +835,7 @@ smtc_modem_return_code_t smtc_modem_get_status( uint8_t stack_id, smtc_modem_sta
*
* @return Modem return code as defined in @ref smtc_modem_return_code_t
* @retval SMTC_MODEM_RC_OK Command executed without errors
+ * @retval SMTC_MODEM_RC_INVALID \p alarm_timer_in_s exceed max value of 864000s (10 days)
* @retval SMTC_MODEM_RC_BUSY Modem is currently in test mode
*/
smtc_modem_return_code_t smtc_modem_alarm_start_timer( uint32_t alarm_timer_in_s );
@@ -1681,7 +1681,7 @@ smtc_modem_return_code_t smtc_modem_get_duty_cycle_status( int32_t* duty_cycle_s
smtc_modem_return_code_t smtc_modem_get_stack_state( uint8_t stack_id, smtc_modem_stack_state_t* stack_state );
/**
- * @brief Configure LoRaWAN network type to private or public
+ * @brief Configure LoRaWAN network type to private or public (default: public)
*
* @param [in] stack_id Stack identifier
* @param [in] network_type Configuration to be applied (true: public network / false: private network)
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_test_api.h b/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_test_api.h
index 46ebb21..a197a07 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_test_api.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_api/smtc_modem_test_api.h
@@ -239,7 +239,7 @@ smtc_modem_return_code_t smtc_modem_test_radio_reset( void );
/**
* @brief Enable / disable the applicative dutycycle
- * @remark
+ * @remark This function can be called regardless of test mode state
*
* @param [in] status 0: disable, 1: enable
*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/README.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/README.md
deleted file mode 100644
index a6997cc..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/README.md
+++ /dev/null
@@ -1,17 +0,0 @@
-This is the soft modem core code that can be embedded in several top projects.
-
-In this repository you will find 5 subfolders:
-* device_management:
-Functions and helpers that handle downlink from LoraCloud and all that is related with the soft modem context
-
-* lorawan_api:
-Soft layer that is used to abstract the LoRaWAN stack that is used below
-
-* modem_services:
-All services supported by the modem and the LoRaCloud (file upload, streaming, alc_sync)
-
-* modem_supervisor:
-The soft modem task scheduler
-
-* test_modem:
-Here is handled the soft modem test mode
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/dm_downlink.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/dm_downlink.c
index b3d7427..1797a6a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/dm_downlink.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/dm_downlink.c
@@ -259,7 +259,6 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input )
ret = DM_ERROR;
break;
}
- modem_supervisor_add_task_dm_status_now( );
break;
case DM_SET_CONF:
if( dm_set_conf( ( dm_info_field_t ) cmd_input->buffer[0], cmd_input->buffer + 1, cmd_input->buffer_len - 1 ) !=
@@ -275,12 +274,7 @@ dm_rc_t dm_parse_cmd( dm_cmd_msg_t* cmd_input )
if( lorawan_api_devnonce_get( ) != dev_nonce )
{
uint8_t dm_fields_payload[1] = { DM_INFO_SESSION };
- dm_rc_t return_code = set_dm_info( dm_fields_payload, 1, DM_INFO_NOW );
- if( return_code == DM_OK )
- {
- modem_supervisor_add_task_dm_status_now( );
- }
-
+ set_dm_info( dm_fields_payload, 1, DM_INFO_NOW );
ret = DM_ERROR;
break;
}
@@ -546,11 +540,7 @@ static dm_rc_t dm_reset( dm_reset_code_t reset_code, uint16_t reset_session )
else
{
uint8_t dm_fields_payload[1] = { DM_INFO_RSTCOUNT };
- dm_rc_t return_code = set_dm_info( dm_fields_payload, 1, DM_INFO_NOW );
- if( return_code == DM_OK )
- {
- modem_supervisor_add_task_dm_status_now( );
- }
+ set_dm_info( dm_fields_payload, 1, DM_INFO_NOW );
ret = DM_ERROR;
SMTC_MODEM_HAL_TRACE_ERROR( "invalid DM reset session code\n" );
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/modem_context.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/modem_context.c
index 66a287d..d5163ea 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/modem_context.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/device_management/modem_context.c
@@ -214,9 +214,9 @@ struct
int8_t tx_power_offset_db;
radio_planner_t* modem_rp;
modem_power_config_t power_config_lut[POWER_CONFIG_LUT_SIZE];
-#if defined( ADD_D2D )
+#if defined( SMTC_D2D )
modem_context_class_b_d2d_t class_b_d2d_ctx;
-#endif // ADD_D2D
+#endif // SMTC_D2D
void ( *modem_lbm_notification_extended_1_callback )( void );
void ( *modem_lbm_notification_extended_2_callback )( void );
const void* modem_radio_ctx;
@@ -238,6 +238,7 @@ struct
#if defined( ADD_SMTC_FILE_UPLOAD )
#define modem_dm_upload_sctr modem_ctx_context.modem_dm_upload_sctr
#define modem_upload_state modem_ctx_context.modem_upload_state
+#define modem_upload_avgdelay modem_ctx_context.modem_upload_avgdelay
#endif // ADD_SMTC_FILE_UPLOAD
#if defined( ADD_SMTC_STREAM )
#define modem_stream_state modem_ctx_context.modem_stream_state
@@ -264,9 +265,6 @@ struct
#define duty_cycle_disabled_by_host modem_ctx_context.duty_cycle_disabled_by_host
#define crc_fw modem_ctx_context.crc_fw
#define modem_adr_profile modem_ctx_context.modem_adr_profile
-#if defined ( ADD_SMTC_FILE_UPLOAD )
-#define modem_upload_avgdelay modem_ctx_context.modem_upload_avgdelay
-#endif // ADD_SMTC_FILE_UPLOAD
#define nb_adr_mobile_timeout modem_ctx_context.nb_adr_mobile_timeout
#define is_modem_in_test_mode modem_ctx_context.is_modem_in_test_mode
#define rx_pathloss_db modem_ctx_context.rx_pathloss_db
@@ -370,8 +368,9 @@ void modem_context_init( )
is_modem_suspend = MODEM_NOT_SUSPEND;
modem_start_time = 0;
#if defined( ADD_SMTC_FILE_UPLOAD )
- modem_dm_upload_sctr = 0;
- modem_upload_state = MODEM_UPLOAD_NOT_INIT;
+ modem_dm_upload_sctr = 0;
+ modem_upload_state = MODEM_UPLOAD_NOT_INIT;
+ modem_upload_avgdelay = 0;
#endif // ADD_SMTC_FILE_UPLOAD
#if defined( ADD_SMTC_STREAM )
modem_stream_state.port = DEFAULT_DM_PORT;
@@ -397,16 +396,13 @@ void modem_context_init( )
duty_cycle_disabled_by_host = false;
crc_fw = compute_crc_fw( );
modem_adr_profile = SMTC_MODEM_ADR_PROFILE_NETWORK_CONTROLLED;
-#if defined( ADD_SMTC_FILE_UPLOAD )
- modem_upload_avgdelay = 0;
-#endif // ADD_SMTC_FILE_UPLOAD
- nb_adr_mobile_timeout = DEFAULT_ADR_MOBILE_MODE_TIMEOUT;
- is_modem_in_test_mode = false;
- rx_pathloss_db = 0;
- tx_power_offset_db = 0;
- modem_rp = NULL;
- modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID;
- modem_appkey_crc = 0;
+ nb_adr_mobile_timeout = DEFAULT_ADR_MOBILE_MODE_TIMEOUT;
+ is_modem_in_test_mode = false;
+ rx_pathloss_db = 0;
+ tx_power_offset_db = 0;
+ modem_rp = NULL;
+ modem_appkey_status = MODEM_APPKEY_CRC_STATUS_INVALID;
+ modem_appkey_crc = 0;
memset( modem_appstatus, 0, 8 );
memset( modem_event_count, 0, MODEM_NUMBER_OF_EVENTS );
memset( modem_event_status, 0, MODEM_NUMBER_OF_EVENTS );
@@ -414,9 +410,9 @@ void modem_context_init( )
memset( &modem_dwn_pkt, 0, sizeof( modem_downlink_msg_t ) );
// init power config tab to 0x80 as it corresponds to an expected power of 128dbm, value that is never reached
memset( power_config_lut, 0x80, POWER_CONFIG_LUT_SIZE * sizeof( modem_power_config_t ) );
-#if defined( ADD_D2D )
+#if defined( SMTC_D2D )
memset( &class_b_d2d_ctx, 0, sizeof( modem_context_class_b_d2d_t ) );
-#endif // ADD_D2D
+#endif // SMTC_D2D
}
void modem_event_init( void )
@@ -488,7 +484,7 @@ uint8_t get_asynchronous_msgnumber( void )
void increment_asynchronous_msgnumber( uint8_t event_type, uint8_t status )
{
// Next condition should never append because only one asynch msg by type of message
- if( asynchronous_msgnumber > MODEM_NUMBER_OF_EVENTS )
+ if( asynchronous_msgnumber >= MODEM_NUMBER_OF_EVENTS )
{
SMTC_MODEM_HAL_TRACE_ERROR( " Modem reach the max number of asynch message\n" );
return;
@@ -497,8 +493,8 @@ void increment_asynchronous_msgnumber( uint8_t event_type, uint8_t status )
tmp = get_modem_event_count( event_type );
if( tmp == 0 )
{
- asynchronous_msgnumber++;
asynch_msg[asynchronous_msgnumber] = event_type;
+ asynchronous_msgnumber++;
}
increment_modem_event_count_and_status( event_type, status );
@@ -506,7 +502,11 @@ void increment_asynchronous_msgnumber( uint8_t event_type, uint8_t status )
uint8_t get_last_msg_event( void )
{
- return asynch_msg[asynchronous_msgnumber];
+ if( asynchronous_msgnumber > 0 )
+ {
+ return asynch_msg[asynchronous_msgnumber - 1];
+ }
+ return 0xFF;
}
uint32_t get_modem_uptime_s( void )
@@ -656,9 +656,9 @@ void get_modem_appstatus( uint8_t* app_status )
void modem_supervisor_add_task_join( void )
{
- smodem_task task_join;
- task_join.id = JOIN_TASK;
- task_join.priority = TASK_HIGH_PRIORITY;
+ smodem_task task_join = { 0 };
+ task_join.id = JOIN_TASK;
+ task_join.priority = TASK_HIGH_PRIORITY;
uint32_t current_time_s = smtc_modem_hal_get_time_in_s( );
@@ -691,7 +691,7 @@ void modem_supervisor_add_task_join( void )
void modem_supervisor_add_task_dm_status( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = DM_TASK;
task_dm.priority = TASK_LOW_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -704,7 +704,7 @@ void modem_supervisor_add_task_dm_status( uint32_t next_execute )
void modem_supervisor_add_task_dm_status_now( void )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = DM_TASK_NOW;
task_dm.priority = TASK_LOW_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -714,7 +714,7 @@ void modem_supervisor_add_task_dm_status_now( void )
}
void modem_supervisor_add_task_crash_log( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = CRASH_LOG_TASK;
task_dm.priority = TASK_LOW_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -726,7 +726,7 @@ void modem_supervisor_add_task_crash_log( uint32_t next_execute )
#if defined( ADD_SMTC_ALC_SYNC )
void modem_supervisor_add_task_clock_sync_time_req( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = CLOCK_SYNC_TIME_REQ_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -759,7 +759,7 @@ bool modem_supervisor_is_clock_sync_running( void )
void modem_supervisor_add_task_alc_sync_ans( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = ALC_SYNC_ANS_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -773,7 +773,7 @@ void modem_supervisor_add_task_alc_sync_ans( uint32_t next_execute )
void modem_supervisor_add_task_alm_dbg_ans( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = DM_ALM_DBG_ANS;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -786,7 +786,7 @@ void modem_supervisor_add_task_alm_dbg_ans( uint32_t next_execute )
void modem_supervisor_add_task_modem_mute( void )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = MUTE_TASK;
task_dm.priority = TASK_MEDIUM_HIGH_PRIORITY;
task_dm.time_to_execute_s = smtc_modem_hal_get_time_in_s( ) + 86400; // Every 24h
@@ -795,7 +795,7 @@ void modem_supervisor_add_task_modem_mute( void )
void modem_supervisor_add_task_retrieve_dl( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = RETRIEVE_DL_TASK;
task_dm.priority = TASK_LOW_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -809,7 +809,7 @@ void modem_supervisor_add_task_retrieve_dl( uint32_t next_execute )
void modem_supervisor_add_task_frag( uint32_t next_execute )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = FRAG_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -825,7 +825,7 @@ void modem_supervisor_add_task_stream( void )
{
// Modem supervisor copy everything,
// so this is safe even when it is going to be invalidated.
- smodem_task stream_task;
+ smodem_task stream_task = { 0 };
stream_task.id = STREAM_TASK;
stream_task.time_to_execute_s = smtc_modem_hal_get_time_in_s( ) + smtc_modem_hal_get_random_nb_in_range( 1, 3 );
@@ -844,7 +844,7 @@ void modem_supervisor_add_task_stream( void )
#if defined( ADD_SMTC_FILE_UPLOAD )
void modem_supervisor_add_task_file_upload( uint32_t delay_in_s )
{
- smodem_task upload_task;
+ smodem_task upload_task = { 0 };
upload_task.id = FILE_UPLOAD_TASK;
upload_task.priority = TASK_HIGH_PRIORITY;
@@ -856,7 +856,7 @@ void modem_supervisor_add_task_file_upload( uint32_t delay_in_s )
void modem_supervisor_add_task_link_check_req( uint32_t delay_in_s )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = LINK_CHECK_REQ_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -869,7 +869,7 @@ void modem_supervisor_add_task_link_check_req( uint32_t delay_in_s )
void modem_supervisor_add_task_device_time_req( uint32_t delay_in_s )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = DEVICE_TIME_REQ_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -882,7 +882,7 @@ void modem_supervisor_add_task_device_time_req( uint32_t delay_in_s )
void modem_supervisor_add_task_ping_slot_info_req( uint32_t delay_in_s )
{
- smodem_task task_dm;
+ smodem_task task_dm = { 0 };
task_dm.id = PING_SLOT_INFO_REQ_TASK;
task_dm.priority = TASK_HIGH_PRIORITY;
task_dm.PacketType = UNCONF_DATA_UP;
@@ -1189,6 +1189,16 @@ dm_rc_t set_dm_info( const uint8_t* requested_info_list, uint8_t len, dm_info_ra
ret = DM_ERROR;
SMTC_MODEM_HAL_TRACE_ERROR( "invalid DM info code (0x%02x)\n", requested_info_list[i] );
}
+// In case geoloc is not available, check if DM_INFO_ALMSTATUS is requested and return an error if yes
+#if !defined( ENABLE_MODEM_GNSS_FEATURE )
+ if( requested_info_list[i] == DM_INFO_ALMSTATUS )
+ {
+ ret = DM_ERROR;
+ SMTC_MODEM_HAL_TRACE_ERROR(
+ "invalid DM info code: SMTC_MODEM_DM_FIELD_ALMANAC_STATUS is not allowed on chip without gnss "
+ "features\n" );
+ }
+#endif
}
if( ret == DM_OK )
{
@@ -1199,6 +1209,11 @@ dm_rc_t set_dm_info( const uint8_t* requested_info_list, uint8_t len, dm_info_ra
if( flag == DM_INFO_NOW )
{
modem_supervisor_add_task_crash_log( 0 );
+ if( len == 1 )
+ {
+ // only crash log is requested return directly here to avoid sending another empty message
+ return DM_OK;
+ }
}
else
{
@@ -1215,7 +1230,8 @@ dm_rc_t set_dm_info( const uint8_t* requested_info_list, uint8_t len, dm_info_ra
{
dm_info_bitfield_now = info_req;
tag_number_now = 0; // Reset tag_number used by dm_status_payload to
- // start a report from beginning
+ // start a report from beginning
+ modem_supervisor_add_task_dm_status_now( );
}
else
{
@@ -1713,7 +1729,7 @@ void modem_context_factory_reset( void )
smtc_modem_hal_context_store( CONTEXT_MODEM, ( uint8_t* ) &ctx, sizeof( ctx ) );
// dummy context reading to ensure context store is done before exiting the function
- smtc_modem_hal_context_restore( CONTEXT_LR1MAC, ( uint8_t* ) &ctx, sizeof( ctx ) );
+ smtc_modem_hal_context_restore( CONTEXT_MODEM, ( uint8_t* ) &ctx, sizeof( ctx ) );
is_modem_reset_requested = true;
SMTC_MODEM_HAL_TRACE_INFO( "modem_context_factory_reset done\n" );
@@ -2036,7 +2052,7 @@ void modem_context_set_modem_radio_ctx( const void* radio_ctx )
modem_radio_ctx = radio_ctx;
}
-#if defined( ADD_D2D )
+#if defined( SMTC_D2D )
void modem_context_set_class_b_d2d_last_metadata( uint8_t mc_grp_id, bool tx_done, uint8_t nb_trans_not_send )
{
class_b_d2d_ctx.tx_done = tx_done;
@@ -2059,7 +2075,7 @@ void modem_context_get_class_b_d2d_last_metadata( modem_context_class_b_d2d_t* c
{
memcpy( class_b_d2d, &class_b_d2d_ctx, sizeof( modem_context_class_b_d2d_t ) );
}
-#endif // ADD_D2D
+#endif // SMTC_D2D
void modem_set_extended_callback( func_callback callback, uint8_t extended_uplink_id )
{
@@ -2094,6 +2110,9 @@ func_callback modem_get_extended_callback( uint8_t extended_uplink_id )
void modem_leave( void )
{
+ // reset all tasks to retrieve a clean env (and clear all ongoing tasks)
+ modem_supervisor_init_task( );
+
// Set joined/joining status to false
set_modem_status_modem_joined( false );
lorawan_api_join_status_clear( );
@@ -2114,9 +2133,6 @@ void modem_leave( void )
set_modem_status_streaming( false );
modem_set_stream_state( MODEM_STREAM_NOT_INIT );
#endif // ADD_SMTC_STREAM
-
- // re init task to retrieve a clean env (and clear all ongoing tasks)
- modem_supervisor_init_task( );
}
/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.c
index c15c71e..39d141d 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.c
@@ -65,7 +65,7 @@
static struct
{
lr1_stack_mac_t lr1_mac_obj;
- smtc_real_t real;
+ smtc_real_t real_obj;
smtc_lbt_t lbt_obj;
smtc_dtc_t duty_cycle_obj;
lr1mac_class_c_t class_c_obj;
@@ -86,7 +86,7 @@ uint8_t fifo_buffer[FIFO_LORAWAN_SIZE];
#define lr1_mac_obj lr1mac_core_context.lr1_mac_obj
#define lbt_obj lr1mac_core_context.lbt_obj
-#define real lr1mac_core_context.real
+#define real_obj lr1mac_core_context.real_obj
#define duty_cycle_obj lr1mac_core_context.duty_cycle_obj
#define class_c_obj lr1mac_core_context.class_c_obj
#define fifo_ctrl_obj lr1mac_core_context.fifo_ctrl_obj
@@ -106,34 +106,8 @@ static void lorawan_api_class_b_d2d_tx_event_callback( smtc_class_b_d2d_t* class
void lorawan_api_init( radio_planner_t* rp )
{
- smtc_real_region_types_t smtc_real_region_types = SMTC_REAL_REGION_UNKNOWN;
-
-#if defined( REGION_EU_868 )
- smtc_real_region_types = SMTC_REAL_REGION_EU_868;
-#elif defined( REGION_US_915 )
- smtc_real_region_types = SMTC_REAL_REGION_US_915;
-#elif defined( REGION_AU_915 )
- smtc_real_region_types = SMTC_REAL_REGION_AU_915;
-#elif defined( REGION_CN_470 )
- smtc_real_region_types = SMTC_REAL_REGION_CN_470;
-#elif defined( REGION_CN_470_RP_1_0 )
- smtc_real_region_types = SMTC_REAL_REGION_CN_470_RP_1_0;
-#elif defined( REGION_AS_923 )
- smtc_real_region_types = SMTC_REAL_REGION_AS_923;
-#elif defined( REGION_IN_865 )
- smtc_real_region_types = SMTC_REAL_REGION_IN_865;
-#elif defined( REGION_KR_920 )
- smtc_real_region_types = SMTC_REAL_REGION_KR_920;
-#elif defined( REGION_RU_864 )
- smtc_real_region_types = SMTC_REAL_REGION_RU_864;
-#elif defined( REGION_WW2G4 )
- smtc_real_region_types = SMTC_REAL_REGION_WW2G4;
-#else
-#error "Please select supported region"
-#endif
-
// init lr1mac core
- lr1mac_core_init( &lr1_mac_obj, &real, &lbt_obj, &duty_cycle_obj, rp, ACTIVATION_MODE_OTAA, smtc_real_region_types,
+ lr1mac_core_init( &lr1_mac_obj, &real_obj, &lbt_obj, &duty_cycle_obj, rp, ACTIVATION_MODE_OTAA,
( void ( * )( void* ) ) lorawan_api_class_a_downlink_callback, &lr1_mac_obj );
fifo_ctrl_init( &fifo_ctrl_obj, fifo_buffer, FIFO_LORAWAN_SIZE );
@@ -434,17 +408,17 @@ uint32_t lorawan_api_next_frequency_get( void )
uint8_t lorawan_api_max_tx_dr_get( void )
{
- return smtc_real_get_max_tx_channel_dr( &lr1_mac_obj );
+ return smtc_real_get_max_tx_channel_dr( lr1_mac_obj.real );
}
uint16_t lorawan_api_mask_tx_dr_channel_up_dwell_time_check( void )
{
- return smtc_real_mask_tx_dr_channel_up_dwell_time_check( &lr1_mac_obj );
+ return smtc_real_mask_tx_dr_channel_up_dwell_time_check( lr1_mac_obj.real );
}
uint8_t lorawan_api_min_tx_dr_get( void )
{
- return smtc_real_get_min_tx_channel_dr( &lr1_mac_obj );
+ return smtc_real_get_min_tx_channel_dr( lr1_mac_obj.real );
}
lr1mac_states_t lorawan_api_state_get( void )
@@ -770,15 +744,15 @@ fifo_ctrl_t* lorawan_api_get_fifo_obj( void )
void lorawan_api_set_network_type( bool network_type )
{
- uint8_t sync_word = ( network_type == true ) ? smtc_real_get_public_sync_word( &lr1_mac_obj )
- : smtc_real_get_private_sync_word( &lr1_mac_obj );
+ uint8_t sync_word = ( network_type == true ) ? smtc_real_get_public_sync_word( lr1_mac_obj.real )
+ : smtc_real_get_private_sync_word( lr1_mac_obj.real );
- smtc_real_set_sync_word( &lr1_mac_obj, sync_word );
+ smtc_real_set_sync_word( lr1_mac_obj.real, sync_word );
}
bool lorawan_api_get_network_type( void )
{
- uint8_t sync_word = smtc_real_get_sync_word( &lr1_mac_obj );
- return ( ( sync_word == smtc_real_get_public_sync_word( &lr1_mac_obj ) ) ? true : false );
+ uint8_t sync_word = smtc_real_get_sync_word( lr1_mac_obj.real );
+ return ( ( sync_word == smtc_real_get_public_sync_word( lr1_mac_obj.real ) ) ? true : false );
}
uint8_t lorawan_api_nb_trans_get( void )
@@ -832,13 +806,6 @@ uint32_t lorawan_api_get_time_left_connection_lost( void )
return lr1mac_core_get_time_left_connection_lost( &lr1_mac_obj );
}
-void lorawan_api_set_device_time_callback( void ( *device_time_callback )( void* context, uint32_t rx_timestamp_s ),
- void* context, uint32_t rx_timestamp_s )
-{
- lr1mac_core_set_device_time_callback( &lr1_mac_obj, ( void ( * )( void*, uint32_t ) ) device_time_callback, context,
- rx_timestamp_s );
-}
-
status_lorawan_t lorawan_api_set_device_time_invalid_delay_s( uint32_t delay_s )
{
return lr1_mac_core_set_device_time_invalid_delay_s( &lr1_mac_obj, delay_s );
@@ -926,12 +893,12 @@ bool lorawan_api_get_class_b_status( void )
void lorawan_api_lora_dr_to_sf_bw( uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw )
{
- smtc_real_lora_dr_to_sf_bw( &lr1_mac_obj, in_dr, out_sf, out_bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac_obj.real, in_dr, out_sf, out_bw );
}
uint8_t lorawan_api_get_frequency_factor( void )
{
- return smtc_real_get_frequency_factor( &lr1_mac_obj );
+ return smtc_real_get_frequency_factor( lr1_mac_obj.real );
}
bool lorawan_api_get_status_push_network_downlink_to_user( void )
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.h
index 0f802da..200fc3e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lorawan_api/lorawan_api.h
@@ -843,16 +843,6 @@ uint32_t lorawan_api_get_timestamp_last_device_time_ans_s( void );
*/
uint32_t lorawan_api_get_time_left_connection_lost( void );
-/**
- * @brief Configure the callback for the stack when will received the network time sync
- *
- * @param [in] device_time_callback callback that will be called in case a device time answer happened
- * @param [in] context context of the callback
- * @param [in] rx_timestamp_s
- */
-void lorawan_api_set_device_time_callback( void ( *device_time_callback )( void* context, uint32_t rx_timestamp_s ),
- void* context, uint32_t rx_timestamp_s );
-
/**
* @brief Set delay in seconds to concider time no more valid if no time sync received
*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/license.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/license.md
deleted file mode 100644
index 5c52fa9..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/license.md
+++ /dev/null
@@ -1,25 +0,0 @@
---- Revised BSD License ---
-Copyright (c) 2020, SEMTECH CORPORATION
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the Semtech corporation nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/lr1mac_config.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/lr1mac_config.h
index 20da44f..3377a62 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/lr1mac_config.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/lr1mac_config.h
@@ -72,7 +72,7 @@ extern "C" {
// The Lorawan context is stored in memory with a period equal to FLASH_UPDATE_PERIOD packets transmitted
#define BSP_USER_NUMBER_OF_RETRANSMISSION 1
-// Only used in case of user defined darate distribution strategy refereed to doc that explain this value
+// Only used in case of user defined datarate distribution strategy refereed to doc that explain this value
#define BSP_USER_DR_DISTRIBUTION_PARAMETERS 0x10000000
/*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c
index 49ec228..980827e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.c
@@ -54,6 +54,7 @@
* -----------------------------------------------------------------------------
* --- PRIVATE TYPES -----------------------------------------------------------
*/
+#define real_const lr1_mac->real->real_const
/*
*-----------------------------------------------------------------------------------
@@ -103,8 +104,7 @@ static status_lorawan_t ping_slot_info_ans_parser( lr1_stack_mac_t* lr1_mac );
*--- PUBLIC FUNCTION DEFINITIONS ---------------------------------------------------
*/
-void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t activation_mode,
- smtc_real_region_types_t region )
+void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t activation_mode )
{
lr1_mac->tx_major_bits = LORAWANR1;
lr1_mac->radio_process_state = RADIOSTATE_IDLE;
@@ -114,7 +114,6 @@ void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t acti
lr1_mac->activation_mode = activation_mode;
lr1_mac->nb_trans = 1;
lr1_mac->available_app_packet = NO_LORA_RXPACKET_AVAILABLE;
- lr1_mac->real->region_type = region;
lr1_mac->is_lorawan_modem_certification_enabled = false;
lr1_mac->isr_tx_done_radio_timestamp = 0;
lr1_mac->dev_nonce = 0;
@@ -129,8 +128,6 @@ void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t acti
lr1_mac->timestamp_last_device_time_ans_s = 0;
lr1_mac->timestamp_tx_done_device_time_req_ms = 0;
lr1_mac->timestamp_tx_done_device_time_req_ms_tmp = 0;
- lr1_mac->device_time_callback = NULL;
- lr1_mac->device_time_callback_context = NULL;
memset( lr1_mac->fine_tune_board_setting_delay_ms, 0, sizeof( lr1_mac->fine_tune_board_setting_delay_ms ) );
memset( lr1_mac->join_nonce, 0xFF, sizeof( lr1_mac->join_nonce ) );
@@ -164,6 +161,59 @@ void lr1_stack_mac_session_init( lr1_stack_mac_t* lr1_mac )
lr1_mac->tx_class_b_bit = 0;
}
+void lr1_stack_mac_region_init( lr1_stack_mac_t* lr1_mac, smtc_real_region_types_t region_type )
+{
+ smtc_real_init( lr1_mac->real, region_type );
+
+ // Init duty-cycle object
+ smtc_duty_cycle_init( lr1_mac->dtc_obj );
+ if( real_const.const_dtc_supported == true )
+ {
+ // Configure duty-cycle object
+ for( int i = 0; i < real_const.const_dtc_number_of_band; i++ )
+ {
+ smtc_duty_cycle_config( lr1_mac->dtc_obj, real_const.const_dtc_number_of_band, i,
+ real_const.const_dtc_by_band[i],
+ real_const.const_dtc_frequency_range_by_band[2 * i],
+ real_const.const_dtc_frequency_range_by_band[( 2 * i ) + 1] );
+ }
+ }
+ smtc_duty_cycle_enable_set( lr1_mac->dtc_obj, real_const.const_dtc_supported );
+
+ // Listen Before talk initialization
+ smtc_lbt_init( lr1_mac->lbt_obj, lr1_mac->rp, RP_HOOK_ID_LBT,
+ ( void ( * )( void* ) ) lr1_stack_mac_tx_radio_free_lbt, lr1_mac,
+ ( void ( * )( void* ) ) lr1_stack_mac_radio_busy_lbt, lr1_mac,
+ ( void ( * )( void* ) ) lr1_stack_mac_radio_abort_lbt, lr1_mac );
+
+ if( real_const.const_lbt_supported == true )
+ {
+ smtc_lbt_set_parameters( lr1_mac->lbt_obj, smtc_real_get_lbt_duration_ms( lr1_mac->real ),
+ smtc_real_get_lbt_threshold_dbm( lr1_mac->real ),
+ smtc_real_get_lbt_bw_hz( lr1_mac->real ) );
+ smtc_lbt_set_state( lr1_mac->lbt_obj, true );
+ }
+}
+
+void lr1_stack_mac_region_config( lr1_stack_mac_t* lr1_mac )
+{
+ smtc_real_config( lr1_mac->real );
+ lr1_mac->rx2_frequency = real_const.const_rx2_freq;
+ lr1_mac->tx_power = real_const.const_tx_power_dbm;
+ lr1_mac->max_erp_dbm = real_const.const_tx_power_dbm;
+ lr1_mac->rx1_dr_offset = 0;
+ lr1_mac->rx2_data_rate = real_const.const_rx2_dr_init;
+ lr1_mac->rx1_delay_s = real_const.const_received_delay1;
+ lr1_mac->tx_data_rate_adr = real_const.const_min_tx_dr_limit;
+
+ // If 0 the beacon of the region is used, else this freq is used even if the beacon must be hopping
+ lr1_mac->beacon_freq_hz = 0;
+
+ lr1_mac->ping_slot_dr = real_const.const_beacon_dr;
+ lr1_mac->ping_slot_periodicity_req = SMTC_REAL_PING_SLOT_PERIODICITY_DEFAULT;
+ SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "smtc_real_init done\n" );
+}
+
/**************************************************************************************************/
/* build lorawan frame */
/* encrypt lorawan frame */
@@ -216,15 +266,18 @@ void lr1_stack_mac_tx_frame_encrypt( lr1_stack_mac_t* lr1_mac )
void lr1_stack_mac_tx_radio_free_lbt( lr1_stack_mac_t* lr1_mac )
{
lr1_mac->radio_process_state = RADIOSTATE_TX_ON;
- lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + lr1_mac->rp->margin_delay;
- lr1_mac->send_at_time = true;
+ lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + lr1_mac->rp->margin_delay +
+ smtc_modem_hal_get_radio_tcxo_startup_delay_ms( );
+ lr1_mac->send_at_time = true;
+
lr1_stack_mac_tx_radio_start( lr1_mac );
}
void lr1_stack_mac_radio_busy_lbt( lr1_stack_mac_t* lr1_mac )
{
lr1_mac->radio_process_state = RADIOSTATE_IDLE;
lr1_mac->rtc_target_timer_ms = smtc_modem_hal_get_time_in_ms( ) + lr1_mac->rp->margin_delay;
- smtc_real_get_next_channel( lr1_mac );
+ smtc_real_get_next_channel( lr1_mac->real, lr1_mac->dtc_obj, lr1_mac->tx_data_rate, &lr1_mac->tx_frequency,
+ &lr1_mac->rx1_frequency );
}
void lr1_stack_mac_radio_abort_lbt( lr1_stack_mac_t* lr1_mac )
{
@@ -342,32 +395,33 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac )
uint32_t toa = 0;
modulation_type_t tx_modulation_type =
- smtc_real_get_modulation_type_from_datarate( lr1_mac, lr1_mac->tx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( lr1_mac->real, lr1_mac->tx_data_rate );
if( tx_modulation_type == LORA )
{
uint8_t tx_sf;
lr1mac_bandwidth_t tx_bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
lora_param.rf_freq_in_hz = lr1_mac->tx_frequency;
- lora_param.sync_word = smtc_real_get_sync_word( lr1_mac );
+ lora_param.sync_word = smtc_real_get_sync_word( lr1_mac->real );
lora_param.output_pwr_in_dbm = smtc_real_clamp_output_power_eirp_vs_freq_and_dr(
- lr1_mac, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
+ lr1_mac->real, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
lora_param.mod_params.sf = ( ral_lora_sf_t ) tx_sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) tx_bw;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac->real );
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
- lora_param.pkt_params.preamble_len_in_symb = smtc_real_get_preamble_len( lr1_mac, lora_param.mod_params.sf );
- lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
- lora_param.pkt_params.pld_len_in_bytes = lr1_mac->tx_payload_size;
- lora_param.pkt_params.crc_is_on = true;
- lora_param.pkt_params.invert_iq_is_on = false;
+ lora_param.pkt_params.preamble_len_in_symb =
+ smtc_real_get_preamble_len( lr1_mac->real, lora_param.mod_params.sf );
+ lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
+ lora_param.pkt_params.pld_len_in_bytes = lr1_mac->tx_payload_size;
+ lora_param.pkt_params.crc_is_on = true;
+ lora_param.pkt_params.invert_iq_is_on = false;
radio_params.pkt_type = RAL_PKT_TYPE_LORA;
radio_params.tx.lora = lora_param;
@@ -381,7 +435,7 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac )
else if( tx_modulation_type == FSK )
{
uint8_t tx_bitrate;
- smtc_real_fsk_dr_to_bitrate( lr1_mac, lr1_mac->tx_data_rate, &tx_bitrate );
+ smtc_real_fsk_dr_to_bitrate( lr1_mac->real, lr1_mac->tx_data_rate, &tx_bitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
@@ -391,9 +445,9 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac )
gfsk_param.crc_seed = GFSK_CRC_SEED;
gfsk_param.crc_polynomial = GFSK_CRC_POLYNOMIAL;
gfsk_param.rf_freq_in_hz = lr1_mac->tx_frequency;
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac );
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac->real );
gfsk_param.output_pwr_in_dbm = smtc_real_clamp_output_power_eirp_vs_freq_and_dr(
- lr1_mac, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
+ lr1_mac->real, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
gfsk_param.pkt_params.header_type = RAL_GFSK_PKT_VAR_LEN;
gfsk_param.pkt_params.pld_len_in_bytes = lr1_mac->tx_payload_size;
@@ -420,25 +474,25 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac )
{
lr_fhss_v1_cr_t tx_cr;
lr_fhss_v1_bw_t tx_bw;
- smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac, lr1_mac->tx_data_rate, &tx_cr, &tx_bw );
+ smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac->real, lr1_mac->tx_data_rate, &tx_cr, &tx_bw );
ralf_params_lr_fhss_t lr_fhss_param;
memset( &lr_fhss_param, 0, sizeof( ralf_params_lr_fhss_t ) );
lr_fhss_param.output_pwr_in_dbm = smtc_real_clamp_output_power_eirp_vs_freq_and_dr(
- lr1_mac, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
+ lr1_mac->real, lr1_mac->tx_power, lr1_mac->tx_frequency, lr1_mac->tx_data_rate );
uint32_t nb_max_hop_sequence =
ral_lr_fhss_get_hop_sequence_count( &lr1_mac->rp->radio->ral, &lr_fhss_param.ral_lr_fhss_params );
lr_fhss_param.hop_sequence_id = smtc_modem_hal_get_random_nb_in_range( 0, nb_max_hop_sequence );
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 );
+ lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.grid = smtc_real_lr_fhss_get_grid( lr1_mac->real );
lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.enable_hopping = true;
lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.bw = tx_bw;
lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.header_count = smtc_real_lr_fhss_get_header_count( tx_cr );
- lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.sync_word = smtc_real_get_lr_fhss_sync_word( lr1_mac );
- lr_fhss_param.ral_lr_fhss_params.center_frequency_in_hz = lr1_mac->tx_frequency;
- lr_fhss_param.ral_lr_fhss_params.device_offset = 0;
+ lr_fhss_param.ral_lr_fhss_params.lr_fhss_params.sync_word = smtc_real_get_lr_fhss_sync_word( lr1_mac->real );
+ lr_fhss_param.ral_lr_fhss_params.center_frequency_in_hz = lr1_mac->tx_frequency;
+ lr_fhss_param.ral_lr_fhss_params.device_offset = 0;
radio_params.tx.lr_fhss = lr_fhss_param;
@@ -462,9 +516,10 @@ void lr1_stack_mac_tx_radio_start( lr1_stack_mac_t* lr1_mac )
}
rp_task.hook_id = my_hook_id;
rp_task.duration_time_ms = toa;
- rp_task.start_time_ms = lr1_mac->rtc_target_timer_ms - smtc_modem_hal_get_radio_tcxo_startup_delay_ms( );
+ rp_task.start_time_ms = lr1_mac->rtc_target_timer_ms;
if( lr1_mac->send_at_time == true )
{
+ rp_task.start_time_ms -= smtc_modem_hal_get_radio_tcxo_startup_delay_ms( );
lr1_mac->send_at_time = false; // reinit the flag
rp_task.state = RP_TASK_STATE_SCHEDULE;
}
@@ -485,7 +540,7 @@ void lr1_stack_mac_rx_radio_start( lr1_stack_mac_t* lr1_mac, const rx_win_type_t
{
uint32_t rx_frequency = 0;
uint8_t rx_datarate = lr1_mac->rx_data_rate;
- modulation_type_t rx_modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, rx_datarate );
+ modulation_type_t rx_modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac->real, rx_datarate );
rp_radio_params_t radio_params = { 0 };
lr1_mac->current_win = type;
@@ -507,25 +562,26 @@ void lr1_stack_mac_rx_radio_start( lr1_stack_mac_t* lr1_mac, const rx_win_type_t
{
uint8_t rx_sf;
lr1mac_bandwidth_t rx_bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, rx_datarate, &rx_sf, &rx_bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, rx_datarate, &rx_sf, &rx_bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
- lora_param.sync_word = smtc_real_get_sync_word( lr1_mac );
+ lora_param.sync_word = smtc_real_get_sync_word( lr1_mac->real );
lora_param.symb_nb_timeout = lr1_mac->rx_window_symb;
lora_param.rf_freq_in_hz = rx_frequency;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac->real );
lora_param.mod_params.sf = ( ral_lora_sf_t ) rx_sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) rx_bw;
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
- lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
- lora_param.pkt_params.pld_len_in_bytes = 255;
- lora_param.pkt_params.crc_is_on = false;
- lora_param.pkt_params.invert_iq_is_on = true;
- lora_param.pkt_params.preamble_len_in_symb = smtc_real_get_preamble_len( lr1_mac, lora_param.mod_params.sf );
+ lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
+ lora_param.pkt_params.pld_len_in_bytes = 255;
+ lora_param.pkt_params.crc_is_on = false;
+ lora_param.pkt_params.invert_iq_is_on = true;
+ lora_param.pkt_params.preamble_len_in_symb =
+ smtc_real_get_preamble_len( lr1_mac->real, lora_param.mod_params.sf );
radio_params.pkt_type = RAL_PKT_TYPE_LORA;
radio_params.rx.lora = lora_param;
@@ -534,13 +590,13 @@ void lr1_stack_mac_rx_radio_start( lr1_stack_mac_t* lr1_mac, const rx_win_type_t
else if( rx_modulation_type == FSK )
{
uint8_t rx_bitrate;
- smtc_real_fsk_dr_to_bitrate( lr1_mac, rx_datarate, &rx_bitrate );
+ smtc_real_fsk_dr_to_bitrate( lr1_mac->real, rx_datarate, &rx_bitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
gfsk_param.rf_freq_in_hz = rx_frequency;
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac );
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac->real );
gfsk_param.dc_free_is_on = true;
gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
gfsk_param.crc_seed = GFSK_CRC_SEED;
@@ -595,7 +651,7 @@ void lr1_stack_mac_rx_radio_start( lr1_stack_mac_t* lr1_mac, const rx_win_type_t
SMTC_MODEM_HAL_TRACE_PRINTF(
" %s LoRa at %u ms: freq:%u, SF%u, %s, sync word = 0x%02x\n", smtc_name_rx_windows[type],
time_to_start, radio_params.rx.lora.rf_freq_in_hz, radio_params.rx.lora.mod_params.sf,
- smtc_name_bw[radio_params.rx.lora.mod_params.bw], smtc_real_get_sync_word( lr1_mac ) );
+ smtc_name_bw[radio_params.rx.lora.mod_params.bw], smtc_real_get_sync_word( lr1_mac->real ) );
}
else
{
@@ -730,16 +786,17 @@ void lr1_stack_mac_rx_timer_configure( lr1_stack_mac_t* lr1_mac, const rx_win_ty
bool is_type_ok = true;
uint32_t delay_ms;
- smtc_real_set_rx_config( lr1_mac, type );
-
switch( type )
{
case RX1:
delay_ms = lr1_mac->rx1_delay_s;
+ lr1_mac->rx_data_rate =
+ smtc_real_get_rx1_datarate_config( lr1_mac->real, lr1_mac->tx_data_rate, lr1_mac->rx1_dr_offset );
break;
case RX2:
- delay_ms = lr1_mac->rx1_delay_s + 1;
+ delay_ms = lr1_mac->rx1_delay_s + 1;
+ lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
break;
default:
@@ -757,15 +814,15 @@ void lr1_stack_mac_rx_timer_configure( lr1_stack_mac_t* lr1_mac, const rx_win_ty
uint8_t kbitrate;
modulation_type_t rx_modulation_type =
- smtc_real_get_modulation_type_from_datarate( lr1_mac, lr1_mac->rx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( lr1_mac->real, lr1_mac->rx_data_rate );
if( rx_modulation_type == LORA )
{
- smtc_real_lora_dr_to_sf_bw( lr1_mac, lr1_mac->rx_data_rate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, lr1_mac->rx_data_rate, &sf, &bw );
}
else if( rx_modulation_type == FSK )
{
- smtc_real_fsk_dr_to_bitrate( lr1_mac, lr1_mac->rx_data_rate, &kbitrate );
+ smtc_real_fsk_dr_to_bitrate( lr1_mac->real, lr1_mac->rx_data_rate, &kbitrate );
}
else
{
@@ -776,10 +833,11 @@ void lr1_stack_mac_rx_timer_configure( lr1_stack_mac_t* lr1_mac, const rx_win_ty
+smtc_modem_hal_get_board_delay_ms( ) +
lr1_mac->fine_tune_board_setting_delay_ms[lr1_mac->rx_data_rate];
- smtc_real_get_rx_window_parameters( lr1_mac, lr1_mac->rx_data_rate, delay_ms, &lr1_mac->rx_window_symb,
- &lr1_mac->rx_timeout_symb_in_ms, &lr1_mac->rx_timeout_ms, 0 );
- smtc_real_get_rx_start_time_offset_ms( lr1_mac, lr1_mac->rx_data_rate, board_delay_ms, lr1_mac->rx_window_symb,
- &lr1_mac->rx_offset_ms );
+ smtc_real_get_rx_window_parameters( lr1_mac->real, lr1_mac->rx_data_rate, delay_ms, &lr1_mac->rx_window_symb,
+ &lr1_mac->rx_timeout_symb_in_ms, &lr1_mac->rx_timeout_ms, 0,
+ lr1_mac->crystal_error );
+ smtc_real_get_rx_start_time_offset_ms( lr1_mac->real, lr1_mac->rx_data_rate, board_delay_ms,
+ lr1_mac->rx_window_symb, &lr1_mac->rx_offset_ms );
SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG(
"rx_offset_ms:%d, rx_timeout_symb_in_ms:%d, rx_window_symb: %d, board_delay_ms:%d\n", lr1_mac->rx_offset_ms,
@@ -1095,17 +1153,19 @@ void lr1_stack_mac_update( lr1_stack_mac_t* lr1_mac )
// In case of retransmission, if the packet is too long for the next DR, don't decrease the DR
if( lr1_mac->type_of_ans_to_send == USRFRAME_TORETRANSMIT )
{
- uint8_t dr_tmp = smtc_real_decrement_dr_simulation( lr1_mac );
- if( smtc_real_is_payload_size_valid( lr1_mac, dr_tmp, lr1_mac->app_payload_size,
- lr1_mac->uplink_dwell_time ) == OKLORAWAN )
+ uint8_t dr_tmp = smtc_real_decrement_dr_simulation( lr1_mac->real, lr1_mac->tx_data_rate_adr );
+ if( smtc_real_is_payload_size_valid( lr1_mac->real, dr_tmp, lr1_mac->app_payload_size, UP_LINK,
+ lr1_mac->tx_fopts_current_length ) == OKLORAWAN )
{
- smtc_real_decrement_dr( lr1_mac );
+ smtc_real_decrement_dr( lr1_mac->real, lr1_mac->adr_mode_select, &lr1_mac->tx_data_rate_adr,
+ &lr1_mac->tx_power, &lr1_mac->nb_trans );
lr1_mac->adr_ack_cnt = lr1_mac->adr_ack_limit;
}
}
else
{
- smtc_real_decrement_dr( lr1_mac );
+ smtc_real_decrement_dr( lr1_mac->real, lr1_mac->adr_mode_select, &lr1_mac->tx_data_rate_adr,
+ &lr1_mac->tx_power, &lr1_mac->nb_trans );
lr1_mac->adr_ack_cnt = lr1_mac->adr_ack_limit;
}
}
@@ -1136,7 +1196,10 @@ void lr1_stack_mac_update( lr1_stack_mac_t* lr1_mac )
{
if( lr1_mac->type_of_ans_to_send != USRFRAME_TORETRANSMIT )
{
- status_lorawan_t status = smtc_real_get_next_dr( lr1_mac );
+ status_lorawan_t status =
+ smtc_real_get_next_tx_dr( lr1_mac->real, lr1_mac->join_status, &lr1_mac->adr_mode_select,
+ &lr1_mac->tx_data_rate, lr1_mac->tx_data_rate_adr, &lr1_mac->adr_enable );
+
if( status == ERRORLORAWAN )
{
smtc_modem_hal_mcu_panic( " Data Rate incompatible with channel mask\n" );
@@ -1148,14 +1211,12 @@ void lr1_stack_mac_update( lr1_stack_mac_t* lr1_mac )
case NOFRAME_TOSEND:
break;
case NWKFRAME_TOSEND:
- if( smtc_real_is_payload_size_valid( lr1_mac, lr1_mac->tx_data_rate, lr1_mac->nwk_ans_size,
-
- lr1_mac->uplink_dwell_time ) != OKLORAWAN )
+ if( smtc_real_is_payload_size_valid( lr1_mac->real, lr1_mac->tx_data_rate, lr1_mac->nwk_ans_size, UP_LINK,
+ lr1_mac->tx_fopts_current_length ) != OKLORAWAN )
{
lr1_mac->nwk_ans_size = lr1_stack_mac_cmd_ans_cut(
lr1_mac->nwk_ans, lr1_mac->nwk_ans_size,
- smtc_real_get_max_payload_size( lr1_mac, lr1_mac->tx_data_rate, lr1_mac->uplink_dwell_time ) -
- FHDROFFSET );
+ smtc_real_get_max_payload_size( lr1_mac->real, lr1_mac->tx_data_rate, UP_LINK ) - FHDROFFSET );
}
lr1_mac->tx_fport_present = true;
memcpy1( &lr1_mac->tx_payload[FHDROFFSET + lr1_mac->tx_fport_present], lr1_mac->nwk_ans,
@@ -1193,11 +1254,7 @@ status_lorawan_t lr1_stack_mac_cmd_parse( lr1_stack_mac_t* lr1_mac )
switch( cmd_identifier )
{
case LINK_CHECK_ANS:
- if( lr1_mac->link_check_user_req == USER_MAC_REQ_SENT )
- {
- lr1_mac->link_check_user_req = USER_MAC_REQ_ACKED;
- link_check_parser( lr1_mac );
- }
+ link_check_parser( lr1_mac );
break;
case LINK_ADR_REQ: {
@@ -1243,32 +1300,19 @@ status_lorawan_t lr1_stack_mac_cmd_parse( lr1_stack_mac_t* lr1_mac )
break;
case DEVICE_TIME_ANS: {
- if( lr1_mac->device_time_user_req == USER_MAC_REQ_SENT )
+ if( device_time_ans_parser( lr1_mac ) == OKLORAWAN )
{
- if( device_time_ans_parser( lr1_mac ) == OKLORAWAN )
- {
- lr1_mac->device_time_user_req = USER_MAC_REQ_ACKED;
- lr1_mac->timestamp_tx_done_device_time_req_ms = lr1_mac->timestamp_tx_done_device_time_req_ms_tmp;
- lr1_mac->timestamp_last_device_time_ans_s = smtc_modem_hal_get_time_in_s( );
- if( lr1_mac->device_time_callback != NULL )
- {
- lr1_mac->device_time_callback( lr1_mac->device_time_callback_context,
- lr1_mac->timestamp_last_device_time_ans_s );
- }
- }
+ lr1_mac->timestamp_tx_done_device_time_req_ms = lr1_mac->timestamp_tx_done_device_time_req_ms_tmp;
+ lr1_mac->timestamp_last_device_time_ans_s = smtc_modem_hal_get_time_in_s( );
}
break;
}
// Class B
case PING_SLOT_INFO_ANS: {
- if( lr1_mac->ping_slot_info_user_req == USER_MAC_REQ_SENT )
+ if( ping_slot_info_ans_parser( lr1_mac ) == OKLORAWAN )
{
- if( ping_slot_info_ans_parser( lr1_mac ) == OKLORAWAN )
- {
- lr1_mac->ping_slot_periodicity_ans = lr1_mac->ping_slot_periodicity_req;
- lr1_mac->ping_slot_info_user_req = USER_MAC_REQ_ACKED;
- }
+ lr1_mac->ping_slot_periodicity_ans = lr1_mac->ping_slot_periodicity_req;
}
break;
}
@@ -1365,6 +1409,9 @@ status_lorawan_t lr1_stack_mac_join_accept( lr1_stack_mac_t* lr1_mac )
memcpy1( lr1_mac->join_nonce, join_nonce, 6 );
smtc_modem_crypto_derive_skeys( &join_nonce[0], &join_nonce[3], lr1_mac->dev_nonce );
+ lr1_stack_mac_session_init( lr1_mac );
+ smtc_real_config_session( lr1_mac->real );
+
if( lr1_mac->rx_payload_size > 13 ) // MIC has been removed (17 bytes - 4 bytes MIC)
{ // cflist are presents
for( i = 0; i < 16; i++ )
@@ -1372,11 +1419,11 @@ status_lorawan_t lr1_stack_mac_join_accept( lr1_stack_mac_t* lr1_mac )
lr1_mac->cf_list[i] = lr1_mac->rx_payload[13 + i];
}
- smtc_real_update_cflist( lr1_mac );
+ smtc_real_update_cflist( lr1_mac->real, lr1_mac->cf_list );
}
else
{
- smtc_real_init_after_join_snapshot_channel_mask( lr1_mac );
+ smtc_real_init_after_join_snapshot_channel_mask( lr1_mac->real, lr1_mac->tx_data_rate, lr1_mac->tx_frequency );
}
lr1_mac->dev_addr = ( lr1_mac->rx_payload[7] + ( lr1_mac->rx_payload[8] << 8 ) + ( lr1_mac->rx_payload[9] << 16 ) +
@@ -1389,13 +1436,13 @@ status_lorawan_t lr1_stack_mac_join_accept( lr1_stack_mac_t* lr1_mac )
lr1_mac->rx1_delay_s = 1; // Lorawan standart define 0 such as a delay of 1
}
- if( smtc_real_is_rx1_dr_offset_valid( lr1_mac, lr1_mac->rx1_dr_offset ) != OKLORAWAN )
+ if( smtc_real_is_rx1_dr_offset_valid( lr1_mac->real, lr1_mac->rx1_dr_offset ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_WARNING( "JoinAccept invalid Rx1DrOffset %d\n", lr1_mac->rx1_dr_offset );
return ERRORLORAWAN;
}
- if( smtc_real_is_rx_dr_valid( lr1_mac, lr1_mac->rx2_data_rate ) != OKLORAWAN )
+ if( smtc_real_is_rx_dr_valid( lr1_mac->real, lr1_mac->rx2_data_rate ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_WARNING( "JoinAccept invalid Rx2Datarate %d\n", lr1_mac->rx2_data_rate );
return ERRORLORAWAN;
@@ -1403,9 +1450,6 @@ status_lorawan_t lr1_stack_mac_join_accept( lr1_stack_mac_t* lr1_mac )
lr1_mac->join_status = JOINED;
- lr1_stack_mac_session_init( lr1_mac );
- smtc_real_init_session( lr1_mac );
-
SMTC_MODEM_HAL_TRACE_PRINTF( " DevAddr= %x\n", lr1_mac->dev_addr );
SMTC_MODEM_HAL_TRACE_PRINTF( " MacRx1DataRateOffset= %d\n", lr1_mac->rx1_dr_offset );
SMTC_MODEM_HAL_TRACE_PRINTF( " MacRx2DataRate= %d\n", lr1_mac->rx2_data_rate );
@@ -1450,27 +1494,28 @@ uint32_t lr1_stack_toa_get( lr1_stack_mac_t* lr1_mac )
uint32_t toa = 0;
modulation_type_t tx_modulation_type =
- smtc_real_get_modulation_type_from_datarate( lr1_mac, lr1_mac->tx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( lr1_mac->real, lr1_mac->tx_data_rate );
if( tx_modulation_type == LORA )
{
uint8_t tx_sf;
lr1mac_bandwidth_t tx_bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
lora_param.mod_params.sf = ( ral_lora_sf_t ) tx_sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) tx_bw;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac->real );
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
- lora_param.pkt_params.crc_is_on = true;
- lora_param.pkt_params.invert_iq_is_on = false;
- lora_param.pkt_params.pld_len_in_bytes = lr1_mac->tx_payload_size;
- lora_param.pkt_params.preamble_len_in_symb = smtc_real_get_preamble_len( lr1_mac, lora_param.mod_params.sf );
- lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
+ lora_param.pkt_params.crc_is_on = true;
+ lora_param.pkt_params.invert_iq_is_on = false;
+ lora_param.pkt_params.pld_len_in_bytes = lr1_mac->tx_payload_size;
+ lora_param.pkt_params.preamble_len_in_symb =
+ smtc_real_get_preamble_len( lr1_mac->real, lora_param.mod_params.sf );
+ lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
toa = ral_get_lora_time_on_air_in_ms( ( &lr1_mac->rp->radio->ral ), ( &lora_param.pkt_params ),
( &lora_param.mod_params ) );
@@ -1478,13 +1523,13 @@ uint32_t lr1_stack_toa_get( lr1_stack_mac_t* lr1_mac )
else if( tx_modulation_type == FSK )
{
uint8_t tx_bitrate;
- smtc_real_fsk_dr_to_bitrate( lr1_mac, lr1_mac->tx_data_rate, &tx_bitrate );
+ smtc_real_fsk_dr_to_bitrate( lr1_mac->real, lr1_mac->tx_data_rate, &tx_bitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
gfsk_param.rf_freq_in_hz = lr1_mac->tx_frequency;
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac );
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( lr1_mac->real );
gfsk_param.dc_free_is_on = true;
gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
gfsk_param.crc_seed = GFSK_CRC_SEED;
@@ -1506,7 +1551,7 @@ uint32_t lr1_stack_toa_get( lr1_stack_mac_t* lr1_mac )
{
lr_fhss_v1_cr_t tx_cr;
lr_fhss_v1_bw_t tx_bw;
- smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac, lr1_mac->tx_data_rate, &tx_cr, &tx_bw );
+ smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac->real, lr1_mac->tx_data_rate, &tx_cr, &tx_bw );
ralf_params_lr_fhss_t lr_fhss_param;
memset( &lr_fhss_param, 0, sizeof( ralf_params_lr_fhss_t ) );
@@ -1629,12 +1674,15 @@ static void link_check_parser( lr1_stack_mac_t* lr1_mac )
lr1_mac->nwk_payload_size = 0;
return;
}
- SMTC_MODEM_HAL_TRACE_PRINTF( " Margin = %d, GwCnt = %d\n", lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1],
- lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
-
- lr1_mac->link_check_margin = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
- lr1_mac->link_check_gw_cnt = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2];
+ if( lr1_mac->link_check_user_req == USER_MAC_REQ_SENT )
+ {
+ lr1_mac->link_check_user_req = USER_MAC_REQ_ACKED;
+ SMTC_MODEM_HAL_TRACE_PRINTF( " Margin = %d, GwCnt = %d\n", lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1],
+ lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
+ lr1_mac->link_check_margin = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
+ lr1_mac->link_check_gw_cnt = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2];
+ }
lr1_mac->nwk_payload_index += LINK_CHECK_ANS_SIZE;
}
@@ -1668,7 +1716,7 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
for( uint8_t i = 0; i < nb_link_adr_req; i++ )
{
- SMTC_MODEM_HAL_TRACE_PRINTF( "%u/%u - Cmd link_adr_parser = %02x %02x %02x %02x\n", i, nb_link_adr_req,
+ SMTC_MODEM_HAL_TRACE_PRINTF( "%u/%u - Cmd link_adr_parser = %02x %02x %02x %02x\n", i + 1, nb_link_adr_req,
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + ( i * LINK_ADR_REQ_SIZE ) + 1],
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + ( i * LINK_ADR_REQ_SIZE ) + 2],
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + ( i * LINK_ADR_REQ_SIZE ) + 3],
@@ -1676,6 +1724,8 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
}
uint8_t status_ans = 0x7; // initialised for ans answer ok
+ status_channel_t status_channel = OKCHANNEL;
+
// Check channel mask
for( uint8_t i = 0; i < nb_link_adr_req; i++ )
{
@@ -1685,16 +1735,23 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
uint8_t ch_mask_cntl_temp =
( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + ( i * LINK_ADR_REQ_SIZE ) + 4] & 0x70 ) >> 4;
- SMTC_MODEM_HAL_TRACE_PRINTF( "%u - MULTIPLE LINK ADR REQ , channel mask = 0x%x , ChMAstCntl = 0x%x\n", i,
+ SMTC_MODEM_HAL_TRACE_PRINTF( "%u - LINK ADR REQ , channel mask = 0x%x , ChMAstCntl = 0x%x\n", i + 1,
channel_mask_temp, ch_mask_cntl_temp );
- if( smtc_real_build_channel_mask( lr1_mac, ch_mask_cntl_temp, channel_mask_temp ) == ERROR_CHANNEL_CNTL )
+ status_channel = smtc_real_build_channel_mask( lr1_mac->real, ch_mask_cntl_temp, channel_mask_temp );
+ if( status_channel == ERROR_CHANNEL_CNTL )
{ // Test ChannelCNTL not defined
status_ans &= 0x6;
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID CHANNEL CNTL\n" );
}
}
+ if( status_channel == ERROR_CHANNEL_MASK )
+ {
+ status_ans &= 0x6;
+ SMTC_MODEM_HAL_TRACE_WARNING( "INVALID CHANNEL MASK\n" );
+ }
+
// At This point global temporary channel mask is built and validated
if( lr1_mac->adr_mode_select != STATIC_ADR_MODE )
{
@@ -1702,16 +1759,16 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
// 1 is really tested
{
// check if new proposal channel mask is compatible with our mobile distribution
- if( smtc_real_is_channel_mask_for_mobile_mode( lr1_mac ) == ERRORLORAWAN )
+ if( smtc_real_is_channel_mask_for_mobile_mode( lr1_mac->real ) == ERRORLORAWAN )
{
- status_ans = 0x0; // reject the cmd because even if the channel mask is valid it is not compatible with
- // our current adr distribution
+ status_ans = 0x0; // reject the cmd because even if the channel mask is valid it is not compatible
+ // with our current adr distribution
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID CHANNEL MASK in Mobile Mode\n" );
}
else
{
// new channel mask is acceptable :
- smtc_real_set_channel_mask( lr1_mac );
+ smtc_real_set_channel_mask( lr1_mac->real );
// set this flag at true to notify upper layer that end device has received a valid link adr
lr1_mac->available_link_adr = true;
status_ans = 0x1; // Only the ChMask could be acked, other parameters are discarded
@@ -1734,7 +1791,7 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
// If datarate requested is 0x0F, ignore the value
if( dr_tmp != 0x0F )
{
- if( smtc_real_is_tx_dr_acceptable( lr1_mac, dr_tmp, true ) == ERRORLORAWAN )
+ if( smtc_real_is_tx_dr_acceptable( lr1_mac->real, dr_tmp, true ) == ERRORLORAWAN )
{ // Test Channelmask enables a not defined channel
status_ans &= 0x5;
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID DATARATE\n" );
@@ -1748,7 +1805,7 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
// If power id is 0x0F, ignore the value
if( tx_power_tmp != 0x0F )
{
- if( smtc_real_is_tx_power_valid( lr1_mac, tx_power_tmp ) == ERRORLORAWAN )
+ if( smtc_real_is_tx_power_valid( lr1_mac->real, tx_power_tmp ) == ERRORLORAWAN )
{ // Test tx power
status_ans &= 0x3;
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID TXPOWER\n" );
@@ -1762,11 +1819,11 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
// Update the mac parameters if case of no error
if( status_ans == 0x7 )
{
- smtc_real_set_channel_mask( lr1_mac );
+ smtc_real_set_channel_mask( lr1_mac->real );
// If power id is 0x0F, ignore the value
if( tx_power_tmp != 0x0F )
{
- smtc_real_set_power( lr1_mac, tx_power_tmp );
+ lr1_mac->tx_power = smtc_real_convert_power_cmd( lr1_mac->real, tx_power_tmp, lr1_mac->max_erp_dbm );
}
lr1_mac->nb_trans = ( nb_trans_tmp == 0 ) ? 1 : nb_trans_tmp;
// If datarate requested is 0x0F, ignore the value
@@ -1786,12 +1843,16 @@ static void link_adr_parser( lr1_stack_mac_t* lr1_mac, uint8_t nb_link_adr_req )
// Prepare repeated Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- for( uint8_t i = 0; i < nb_link_adr_req; i++ )
+ if( ( lr1_mac->tx_fopts_length + ( nb_link_adr_req * LINK_ADR_ANS_SIZE ) ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + ( i * LINK_ADR_ANS_SIZE )] = LINK_ADR_ANS; // copy Cid
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + ( i * LINK_ADR_ANS_SIZE ) + 1] = status_ans;
+ for( uint8_t i = 0; i < nb_link_adr_req; i++ )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + ( i * LINK_ADR_ANS_SIZE )] =
+ LINK_ADR_ANS; // copy Cid
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + ( i * LINK_ADR_ANS_SIZE ) + 1] = status_ans;
+ }
+ lr1_mac->tx_fopts_length += ( nb_link_adr_req * LINK_ADR_ANS_SIZE );
}
- lr1_mac->tx_fopts_length += ( nb_link_adr_req * LINK_ADR_ANS_SIZE );
}
}
@@ -1815,7 +1876,7 @@ static void rx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
// Valid Rx1DrOffset And Prepare Ans
uint8_t rx1_dr_offset_temp = ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x70 ) >> 4;
- if( smtc_real_is_rx1_dr_offset_valid( lr1_mac, rx1_dr_offset_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_rx1_dr_offset_valid( lr1_mac->real, rx1_dr_offset_temp ) == ERRORLORAWAN )
{
status_ans &= 0x6;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID RX1DROFFSET\n" );
@@ -1823,7 +1884,7 @@ static void rx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
// Valid MacRx2Dr And Prepare Ans
uint8_t rx2_dr_temp = ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x0F );
- if( smtc_real_is_rx_dr_valid( lr1_mac, rx2_dr_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_rx_dr_valid( lr1_mac->real, rx2_dr_temp ) == ERRORLORAWAN )
{
status_ans &= 0x5;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID RX2DR\n" );
@@ -1831,9 +1892,9 @@ static void rx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
// Valid MacRx2Frequency And Prepare Ans
uint32_t rx2_frequency_temp =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
+ smtc_real_decode_freq_from_buf( lr1_mac->real, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
- if( smtc_real_is_frequency_valid( lr1_mac, rx2_frequency_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_frequency_valid( lr1_mac->real, rx2_frequency_temp ) == ERRORLORAWAN )
{
status_ans &= 0x3;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID RX2 FREQUENCY\n" );
@@ -1855,9 +1916,12 @@ static void rx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = RXPARRAM_SETUP_ANS;
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
- lr1_mac->tx_fopts_length += RXPARRAM_SETUP_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + RXPARRAM_SETUP_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = RXPARRAM_SETUP_ANS;
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
+ lr1_mac->tx_fopts_length += RXPARRAM_SETUP_ANS_SIZE;
+ }
if( ( lr1_mac->tx_fopts_lengthsticky + RXPARRAM_SETUP_ANS_SIZE ) <= 15 ) // Max byte in sticky command
{
@@ -1886,8 +1950,11 @@ static void duty_cycle_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DUTY_CYCLE_ANS; // copy Cid
- lr1_mac->tx_fopts_length += DUTY_CYCLE_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + DUTY_CYCLE_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DUTY_CYCLE_ANS; // copy Cid
+ lr1_mac->tx_fopts_length += DUTY_CYCLE_ANS_SIZE;
+ }
}
}
/**********************************************************************************************************************/
@@ -1909,11 +1976,15 @@ static void dev_status_parser( lr1_stack_mac_t* lr1_mac )
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DEV_STATUS_ANS; // copy Cid
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = smtc_modem_hal_get_battery_level( );
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 2] =
- ( lr1_mac->rp->radio_params[my_hook_id].rx.lora_pkt_status.snr_pkt_in_db ) & 0x3F;
- lr1_mac->tx_fopts_length += DEV_STATUS_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + DEV_STATUS_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DEV_STATUS_ANS; // copy Cid
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = smtc_modem_hal_get_battery_level( );
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 2] =
+ ( lr1_mac->rp->radio_params[my_hook_id].rx.lora_pkt_status.snr_pkt_in_db ) & 0x3F;
+
+ lr1_mac->tx_fopts_length += DEV_STATUS_ANS_SIZE;
+ }
}
}
/**********************************************************************************************************************/
@@ -1932,7 +2003,7 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3],
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] );
- if( !smtc_real_is_new_channel_req_supported( lr1_mac ) )
+ if( !smtc_real_is_new_channel_req_supported( lr1_mac->real ) )
{
SMTC_MODEM_HAL_TRACE_WARNING( "NewChannelReq is not supported for this region\n" );
lr1_mac->nwk_payload_index += NEW_CHANNEL_REQ_SIZE;
@@ -1943,7 +2014,7 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
// Valid Channel Index
uint8_t channel_index_temp = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
- if( smtc_real_is_channel_index_valid( lr1_mac, channel_index_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_channel_index_valid( lr1_mac->real, channel_index_temp ) == ERRORLORAWAN )
{
status_ans &= 0x0;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID CHANNEL INDEX\n" );
@@ -1951,8 +2022,8 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
// Valid Frequency
uint32_t frequency_temp =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
- if( smtc_real_is_nwk_received_tx_frequency_valid( lr1_mac, frequency_temp ) == ERRORLORAWAN )
+ smtc_real_decode_freq_from_buf( lr1_mac->real, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
+ if( smtc_real_is_nwk_received_tx_frequency_valid( lr1_mac->real, frequency_temp ) == ERRORLORAWAN )
{
status_ans &= 0x2;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID FREQUENCY\n" );
@@ -1960,14 +2031,14 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
// Valid DRMIN/MAX
uint8_t dr_range_min_temp = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] & 0xF;
- if( smtc_real_is_tx_dr_valid( lr1_mac, dr_range_min_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_tx_dr_valid( lr1_mac->real, dr_range_min_temp ) == ERRORLORAWAN )
{
status_ans &= 0x1;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID DR MIN\n" );
}
uint8_t dr_range_max_temp = ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] & 0xF0 ) >> 4;
- if( smtc_real_is_tx_dr_valid( lr1_mac, dr_range_max_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_tx_dr_valid( lr1_mac->real, dr_range_max_temp ) == ERRORLORAWAN )
{
status_ans &= 0x1;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID DR MAX\n" );
@@ -1982,20 +2053,20 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
// Update the mac parameters if there is no error
if( status_ans == 0x3 )
{
- smtc_real_set_tx_frequency_channel( lr1_mac, frequency_temp, channel_index_temp );
- smtc_real_set_rx1_frequency_channel( lr1_mac, frequency_temp, channel_index_temp );
+ smtc_real_set_tx_frequency_channel( lr1_mac->real, frequency_temp, channel_index_temp );
+ smtc_real_set_rx1_frequency_channel( lr1_mac->real, frequency_temp, channel_index_temp );
- smtc_real_set_channel_dr( lr1_mac, channel_index_temp, dr_range_min_temp, dr_range_max_temp );
+ smtc_real_set_channel_dr( lr1_mac->real, channel_index_temp, dr_range_min_temp, dr_range_max_temp );
if( frequency_temp == 0 )
{
- smtc_real_set_channel_enabled( lr1_mac, CHANNEL_DISABLED, channel_index_temp );
+ smtc_real_set_channel_enabled( lr1_mac->real, CHANNEL_DISABLED, channel_index_temp );
}
else
{
- smtc_real_set_channel_enabled( lr1_mac, CHANNEL_ENABLED, channel_index_temp );
+ smtc_real_set_channel_enabled( lr1_mac->real, CHANNEL_ENABLED, channel_index_temp );
}
SMTC_MODEM_HAL_TRACE_PRINTF( "MacTxFrequency [ %d ] = %d, DrMin = %d, DrMax = %d\n", channel_index_temp,
- smtc_real_get_tx_channel_frequency( lr1_mac, channel_index_temp ),
+ smtc_real_get_tx_channel_frequency( lr1_mac->real, channel_index_temp ),
dr_range_min_temp, dr_range_max_temp );
}
@@ -2004,9 +2075,12 @@ static void new_channel_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = NEW_CHANNEL_ANS; // copy Cid
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
- lr1_mac->tx_fopts_length += NEW_CHANNEL_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + NEW_CHANNEL_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = NEW_CHANNEL_ANS; // copy Cid
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
+ lr1_mac->tx_fopts_length += NEW_CHANNEL_ANS_SIZE;
+ }
}
}
/*********************************************************************************************************************/
@@ -2034,8 +2108,11 @@ static void rx_timing_setup_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = RXTIMING_SETUP_ANS;
- lr1_mac->tx_fopts_length += RXTIMING_SETUP_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + RXTIMING_SETUP_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = RXTIMING_SETUP_ANS;
+ lr1_mac->tx_fopts_length += RXTIMING_SETUP_ANS_SIZE;
+ }
if( ( lr1_mac->tx_fopts_lengthsticky + RXTIMING_SETUP_ANS_SIZE ) <= 15 ) // Max byte in sticky command
{
@@ -2060,7 +2137,7 @@ static void tx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
SMTC_MODEM_HAL_TRACE_PRINTF( "Cmd tx_param_setup_parser = %x\n",
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] );
- if( !smtc_real_is_tx_param_setup_req_supported( lr1_mac ) == true )
+ if( !smtc_real_is_tx_param_setup_req_supported( lr1_mac->real ) == true )
{
SMTC_MODEM_HAL_TRACE_WARNING( "TxParamSetupReq is not supported for this region\n" );
lr1_mac->nwk_payload_index += TXPARAM_SETUP_REQ_SIZE;
@@ -2070,17 +2147,24 @@ static void tx_param_setup_parser( lr1_stack_mac_t* lr1_mac )
uint8_t max_erp_dbm_tmp =
smtc_real_max_eirp_dbm_from_idx[( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x0F )] - 2;
- lr1_mac->max_erp_dbm = ( max_erp_dbm_tmp > const_tx_power_dbm ) ? const_tx_power_dbm : max_erp_dbm_tmp;
- lr1_mac->uplink_dwell_time = ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x10 ) >> 4;
- lr1_mac->downlink_dwell_time = ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x20 ) >> 5;
+ lr1_mac->max_erp_dbm =
+ ( max_erp_dbm_tmp > real_const.const_tx_power_dbm ) ? real_const.const_tx_power_dbm : max_erp_dbm_tmp;
+ smtc_real_set_uplink_dwell_time( lr1_mac->real,
+ ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x10 ) >> 4 );
+
+ smtc_real_set_downlink_dwell_time( lr1_mac->real,
+ ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] & 0x20 ) >> 5 );
lr1_mac->nwk_payload_index += TXPARAM_SETUP_REQ_SIZE;
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = TXPARAM_SETUP_ANS;
- lr1_mac->tx_fopts_length += TXPARAM_SETUP_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + TXPARAM_SETUP_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = TXPARAM_SETUP_ANS;
+ lr1_mac->tx_fopts_length += TXPARAM_SETUP_ANS_SIZE;
+ }
if( ( lr1_mac->tx_fopts_lengthsticky + TXPARAM_SETUP_ANS_SIZE ) <= 15 ) // Max byte in sticky command
{
@@ -2107,7 +2191,7 @@ static void dl_channel_parser( lr1_stack_mac_t* lr1_mac )
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3],
lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4] );
- if( !smtc_real_is_new_channel_req_supported( lr1_mac ) )
+ if( !smtc_real_is_new_channel_req_supported( lr1_mac->real ) )
{
SMTC_MODEM_HAL_TRACE_WARNING( "DlChannelReq is not supported for this region\n" );
lr1_mac->nwk_payload_index += DL_CHANNEL_REQ_SIZE;
@@ -2118,15 +2202,15 @@ static void dl_channel_parser( lr1_stack_mac_t* lr1_mac )
// Valid Channel Index
uint8_t channel_index_temp = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
- if( smtc_real_get_tx_channel_frequency( lr1_mac, channel_index_temp ) == 0 )
+ if( smtc_real_get_tx_channel_frequency( lr1_mac->real, channel_index_temp ) == 0 )
{
status_ans &= 0x1;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID CHANNEL INDEX\n" );
}
// Valid Frequency
uint32_t frequency_temp =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
- if( smtc_real_is_frequency_valid( lr1_mac, frequency_temp ) == ERRORLORAWAN )
+ smtc_real_decode_freq_from_buf( lr1_mac->real, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] );
+ if( smtc_real_is_frequency_valid( lr1_mac->real, frequency_temp ) == ERRORLORAWAN )
{
status_ans &= 0x2;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID FREQUENCY\n" );
@@ -2135,12 +2219,12 @@ static void dl_channel_parser( lr1_stack_mac_t* lr1_mac )
// Update the mac parameters if case of no error
if( status_ans == 0x3 )
{
- if( smtc_real_set_rx1_frequency_channel( lr1_mac, frequency_temp, channel_index_temp ) != OKLORAWAN )
+ if( smtc_real_set_rx1_frequency_channel( lr1_mac->real, frequency_temp, channel_index_temp ) != OKLORAWAN )
{
status_ans = 0;
}
SMTC_MODEM_HAL_TRACE_PRINTF( "MacRx1Frequency [ %u ] = %d\n", channel_index_temp,
- smtc_real_get_rx1_channel_frequency( lr1_mac, channel_index_temp ) );
+ smtc_real_get_rx1_channel_frequency( lr1_mac->real, channel_index_temp ) );
}
lr1_mac->nwk_payload_index += DL_CHANNEL_REQ_SIZE;
@@ -2148,9 +2232,12 @@ static void dl_channel_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DL_CHANNEL_ANS;
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
- lr1_mac->tx_fopts_length += DL_CHANNEL_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + DL_CHANNEL_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = DL_CHANNEL_ANS;
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
+ lr1_mac->tx_fopts_length += DL_CHANNEL_ANS_SIZE;
+ }
if( ( lr1_mac->tx_fopts_lengthsticky + DL_CHANNEL_ANS_SIZE ) <= 15 ) // Max byte in sticky command
{
@@ -2163,8 +2250,7 @@ static void dl_channel_parser( lr1_stack_mac_t* lr1_mac )
status_lorawan_t lr1mac_rx_payload_max_size_check( lr1_stack_mac_t* lr1_mac, uint8_t size, uint8_t rx_datarate )
{
- uint8_t size_max =
- smtc_real_get_max_payload_size( lr1_mac, rx_datarate, lr1_mac->downlink_dwell_time ) + 1 + 4; // + MHDR + CRC
+ uint8_t size_max = smtc_real_get_max_payload_size( lr1_mac->real, rx_datarate, DOWN_LINK ) + 1 + 4; // + MHDR + CRC
if( size > size_max )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "size (%d)> size_max (%d)", size, size_max );
@@ -2180,29 +2266,39 @@ status_lorawan_t lr1mac_rx_payload_max_size_check( lr1_stack_mac_t* lr1_mac, uin
static status_lorawan_t device_time_ans_parser( lr1_stack_mac_t* lr1_mac )
{
+ status_lorawan_t ret = OKLORAWAN;
if( lr1_mac->nwk_payload_index + DEVICE_TIME_ANS_SIZE > lr1_mac->nwk_payload_size )
{
lr1_mac->nwk_payload_size = 0;
return ERRORLORAWAN;
}
- SMTC_MODEM_HAL_TRACE_PRINTF(
- "Cmd device_time_ans_parser = %x %x %x %x %x\n", lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1],
- lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3],
- lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] );
+ if( lr1_mac->device_time_user_req == USER_MAC_REQ_SENT )
+ {
+ lr1_mac->device_time_user_req = USER_MAC_REQ_ACKED;
- lr1_mac->seconds_since_epoch = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
- lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] << 8 );
- lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3] << 16 );
- lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4] << 24 );
+ SMTC_MODEM_HAL_TRACE_PRINTF(
+ "Cmd device_time_ans_parser = %x %x %x %x %x\n", lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1],
+ lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2], lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3],
+ lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4],
+ lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] );
- lr1_mac->fractional_second = ( uint32_t )( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] * 1000 ) >> 8;
+ lr1_mac->seconds_since_epoch = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1];
+ lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 2] << 8 );
+ lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 3] << 16 );
+ lr1_mac->seconds_since_epoch |= ( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4] << 24 );
- SMTC_MODEM_HAL_TRACE_PRINTF( "SecondsSinceEpoch %u, FractionalSecond %u\n", lr1_mac->seconds_since_epoch,
- lr1_mac->fractional_second );
+ lr1_mac->fractional_second = ( uint32_t )( lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 5] * 1000 ) >> 8;
+ SMTC_MODEM_HAL_TRACE_PRINTF( "SecondsSinceEpoch %u, FractionalSecond %u\n", lr1_mac->seconds_since_epoch,
+ lr1_mac->fractional_second );
+ }
+ else
+ {
+ ret = ERRORLORAWAN;
+ }
lr1_mac->nwk_payload_index += DEVICE_TIME_ANS_SIZE;
- return OKLORAWAN;
+ return ret;
}
/*********************************************************************************************************************/
@@ -2226,12 +2322,12 @@ static void beacon_freq_req_parser( lr1_stack_mac_t* lr1_mac )
// Valid Frequency
uint32_t frequency_temp =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] );
+ smtc_real_decode_freq_from_buf( lr1_mac->real, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] );
// A frequency of 0 instructs the end-device that it SHALL use the default frequency plan
if( frequency_temp != 0 )
{
- if( smtc_real_is_frequency_valid( lr1_mac, frequency_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_frequency_valid( lr1_mac->real, frequency_temp ) == ERRORLORAWAN )
{
status_ans &= 0x0;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID BEACON FREQUENCY\n" );
@@ -2242,10 +2338,11 @@ static void beacon_freq_req_parser( lr1_stack_mac_t* lr1_mac )
if( status_ans == 0x1 )
{
lr1_mac->beacon_freq_hz = frequency_temp;
- SMTC_MODEM_HAL_TRACE_PRINTF( "MacBeaconFrequency %d\n", ( lr1_mac->beacon_freq_hz != 0 )
- ? lr1_mac->beacon_freq_hz
- : smtc_real_get_beacon_frequency(
- lr1_mac, smtc_modem_hal_get_time_in_ms( ) ) );
+ SMTC_MODEM_HAL_TRACE_PRINTF(
+ "MacBeaconFrequency %d\n",
+ ( lr1_mac->beacon_freq_hz != 0 )
+ ? lr1_mac->beacon_freq_hz
+ : smtc_real_get_beacon_frequency( lr1_mac->real, smtc_modem_hal_get_time_in_ms( ) ) );
}
lr1_mac->nwk_payload_index += BEACON_FREQ_REQ_SIZE;
@@ -2253,9 +2350,12 @@ static void beacon_freq_req_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = BEACON_FREQ_ANS; // copy Cid
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
- lr1_mac->tx_fopts_length += BEACON_FREQ_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + BEACON_FREQ_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = BEACON_FREQ_ANS; // copy Cid
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
+ lr1_mac->tx_fopts_length += BEACON_FREQ_ANS_SIZE;
+ }
}
}
@@ -2279,12 +2379,12 @@ static void ping_slot_channel_req_parser( lr1_stack_mac_t* lr1_mac )
// Valid Frequency And Prepare Ans
uint32_t frequency_temp =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] );
+ smtc_real_decode_freq_from_buf( lr1_mac->real, &lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 1] );
// A frequency of 0 instructs the end-device that it SHALL use the default frequency plan
if( frequency_temp != 0 )
{
- if( smtc_real_is_frequency_valid( lr1_mac, frequency_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_frequency_valid( lr1_mac->real, frequency_temp ) == ERRORLORAWAN )
{
status_ans &= 0x2;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID PING SLOT FREQUENCY\n" );
@@ -2293,7 +2393,7 @@ static void ping_slot_channel_req_parser( lr1_stack_mac_t* lr1_mac )
// Valid Datarate And Prepare Ans
uint8_t dr_temp = lr1_mac->nwk_payload[lr1_mac->nwk_payload_index + 4] & 0x0F;
- if( smtc_real_is_rx_dr_valid( lr1_mac, dr_temp ) == ERRORLORAWAN )
+ if( smtc_real_is_rx_dr_valid( lr1_mac->real, dr_temp ) == ERRORLORAWAN )
{
status_ans &= 0x01;
SMTC_MODEM_HAL_TRACE_MSG( "INVALID PING SLOT DR\n" );
@@ -2314,9 +2414,12 @@ static void ping_slot_channel_req_parser( lr1_stack_mac_t* lr1_mac )
// Prepare Ans
if( lr1_mac->nwk_payload_index <= lr1_mac->nwk_payload_size )
{
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = PING_SLOT_CHANNEL_ANS;
- lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
- lr1_mac->tx_fopts_length += PING_SLOT_CHANNEL_ANS_SIZE;
+ if( ( lr1_mac->tx_fopts_length + PING_SLOT_CHANNEL_ANS_SIZE ) <= DEVICE_MAC_PAYLOAD_MAX_SIZE )
+ {
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length] = PING_SLOT_CHANNEL_ANS;
+ lr1_mac->tx_fopts_data[lr1_mac->tx_fopts_length + 1] = status_ans;
+ lr1_mac->tx_fopts_length += PING_SLOT_CHANNEL_ANS_SIZE;
+ }
if( ( lr1_mac->tx_fopts_lengthsticky + PING_SLOT_CHANNEL_ANS_SIZE ) <= 15 ) // Max byte in sticky command
{
@@ -2334,15 +2437,25 @@ static void ping_slot_channel_req_parser( lr1_stack_mac_t* lr1_mac )
static status_lorawan_t ping_slot_info_ans_parser( lr1_stack_mac_t* lr1_mac )
{
+ status_lorawan_t ret = OKLORAWAN;
if( lr1_mac->nwk_payload_index + PING_SLOT_INFO_ANS_SIZE > lr1_mac->nwk_payload_size )
{
lr1_mac->nwk_payload_size = 0;
return ERRORLORAWAN;
}
- SMTC_MODEM_HAL_TRACE_PRINTF( " PingSlotInfoAns\n" );
+ if( lr1_mac->ping_slot_info_user_req == USER_MAC_REQ_SENT )
+ {
+ lr1_mac->ping_slot_info_user_req = USER_MAC_REQ_ACKED;
+ SMTC_MODEM_HAL_TRACE_PRINTF( " PingSlotInfoAns\n" );
+ }
+ else
+ {
+ ret = ERRORLORAWAN;
+ }
+
lr1_mac->nwk_payload_index += PING_SLOT_INFO_ANS_SIZE;
- return OKLORAWAN;
+ return ret;
}
/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h
index 406c825..4e3861c 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1_stack_mac_layer.h
@@ -46,9 +46,16 @@ extern "C" {
#include "radio_planner.h"
#include "smtc_duty_cycle.h"
#include "smtc_lbt.h"
-#define MIN_RX_WINDOW_SYMB 6 // open rx window at least 6 symbols
-#define MAX_RX_WINDOW_SYMB 255 // open rx window at max 225 symbol hardware limitation
-#define MIN_RX_WINDOW_DURATION_MS 6 // open rx window at least 6ms
+
+#ifndef MIN_RX_WINDOW_SYMB
+#define MIN_RX_WINDOW_SYMB 6 // open rx window at least 6 symbols
+#endif
+
+#define MAX_RX_WINDOW_SYMB 248 // open rx window at max 248 symbol hardware limitation
+
+#ifndef MIN_RX_WINDOW_DURATION_MS
+#define MIN_RX_WINDOW_DURATION_MS 16 // open rx window at least 6ms
+#endif
/*
*-----------------------------------------------------------------------------------
* --- PUBLIC TYPES -----------------------------------------------------------------
@@ -93,8 +100,6 @@ typedef struct lr1_stack_mac_s
/* Update by TxParamSetupReq command */
/********************************************/
uint8_t max_erp_dbm;
- bool uplink_dwell_time;
- bool downlink_dwell_time;
/********************************************/
/* Update by DutyCycleReq command */
/********************************************/
@@ -162,7 +167,7 @@ typedef struct lr1_stack_mac_s
uint8_t adr_ack_limit;
uint8_t adr_ack_delay;
uint8_t adr_ack_req;
- uint8_t adr_enable;
+ bool adr_enable;
dr_strategy_t adr_mode_select;
dr_strategy_t adr_mode_select_tmp;
uint32_t adr_custom[2];
@@ -178,7 +183,7 @@ typedef struct lr1_stack_mac_s
uint32_t tx_frequency;
uint32_t rx1_frequency;
uint8_t rx_data_rate;
- uint8_t sync_word;
+ uint8_t sync_word; // TODO does it useful , it's on the real
rx_win_type_t current_win;
// initially implemented in phy layer
@@ -214,8 +219,6 @@ typedef struct lr1_stack_mac_s
uint32_t timestamp_tx_done_device_time_req_ms;
uint32_t timestamp_tx_done_device_time_req_ms_tmp;
uint32_t timestamp_last_device_time_ans_s;
- void ( *device_time_callback )( void*, uint32_t );
- void* device_time_callback_context;
uint32_t device_time_invalid_delay_s;
// MAC command requested by user
@@ -246,15 +249,35 @@ typedef struct lr1_stack_mac_s
* @param [in] activation_mode Type of activation used (ABP or OTAA)
* @param [in] region Chosen region
*/
-void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t activation_mode,
- smtc_real_region_types_t region );
+void lr1_stack_mac_init( lr1_stack_mac_t* lr1_mac, lr1mac_activation_mode_t activation_mode );
/*!
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
+
+/**
+ * @brief
+ *
+ * @param lr1_mac
+ */
void lr1_stack_mac_session_init( lr1_stack_mac_t* lr1_mac );
+
+/**
+ * @brief
+ *
+ * @param lr1_mac
+ */
+void lr1_stack_mac_region_init( lr1_stack_mac_t* lr1_mac, smtc_real_region_types_t region_type );
+
+/**
+ * @brief
+ *
+ * @param lr1_mac
+ */
+void lr1_stack_mac_region_config( lr1_stack_mac_t* lr1_mac );
+
/*!
* \brief
* \remark
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c
index e926bce..945ec4a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_beacon_sniff.c
@@ -167,12 +167,13 @@ static bool is_valid_beacon( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t timesta
/**
* @brief Compute the beacon datarate
*/
-#define BEACON_DATA_RATE( ) smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac )
+#define BEACON_DATA_RATE( ) smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac->real )
/**
* @brief Compute the beacon duration in us
*/
-#define BEACON_SYMB_DURATION_US( ) smtc_real_get_symbol_duration_us( lr1_beacon_obj->lr1_mac, BEACON_DATA_RATE( ) )
+#define BEACON_SYMB_DURATION_US( ) \
+ smtc_real_get_symbol_duration_us( lr1_beacon_obj->lr1_mac->real, BEACON_DATA_RATE( ) )
/**
* @brief Compute the beacon duration in ms
*/
@@ -182,27 +183,28 @@ static bool is_valid_beacon( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_t timesta
* @brief Compute the beacon spreading factor
*/
#define GET_BEACON_SF( ) \
- ( ral_lora_sf_t ) get_beacon_sf( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac ) )
+ ( ral_lora_sf_t ) get_beacon_sf( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac->real ) )
/**
* @brief Compute the beacon bandwith
*/
#define GET_BEACON_BW( ) \
- ( ral_lora_bw_t ) get_beacon_bw( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac ) )
+ ( ral_lora_bw_t ) get_beacon_bw( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac->real ) )
/**
* @brief Compute the beacon payload length in bytes
*/
#define GET_BEACON_LENGTH_BYTES( ) \
- get_beacon_length( get_beacon_sf( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac ) ) )
+ get_beacon_length( \
+ get_beacon_sf( lr1_beacon_obj->lr1_mac, smtc_real_get_beacon_dr( lr1_beacon_obj->lr1_mac->real ) ) )
/**
* @brief Compute the beacon frequency in hertz
*/
#define GET_BEACON_FREQUENCY( ) \
- smtc_real_get_beacon_frequency( lr1_beacon_obj->lr1_mac, lr1_beacon_obj->beacon_epoch_time )
+ smtc_real_get_beacon_frequency( lr1_beacon_obj->lr1_mac->real, lr1_beacon_obj->beacon_epoch_time )
/**
- * @brief use to compute the rx windows size of a beacon defined in ms , this value is clamp at 255 symbols which is the
- * maximum allowed value in the semtech radio
+ * @brief use to compute the rx windows size of a beacon defined in ms , this value is clamp at MAX_RX_WINDOW_SYMB
+ * symbols which is the maximum allowed value in the Semtech radio
*/
-#define MAX_BEACON_WINDOW_SYMB( ) MIN( MAX_BEACON_WINDOW_MS / BEACON_SYMB_DURATION_MS( ), 255 )
+#define MAX_BEACON_WINDOW_SYMB( ) MIN( MAX_BEACON_WINDOW_MS / BEACON_SYMB_DURATION_MS( ), MAX_RX_WINDOW_SYMB )
/**
* @brief return the duration in ms of a beacon duration initally defined in number of symbols
*/
@@ -330,8 +332,8 @@ void beacon_rp_request( smtc_lr1_beacon_t* lr1_beacon_obj )
rp_radio_params_t rp_radio_params = { 0 };
rp_radio_params.pkt_type = RAL_PKT_TYPE_LORA;
lora_param.symb_nb_timeout = lr1_beacon_obj->beacon_open_rx_nb_symb;
- lora_param.sync_word = smtc_real_get_sync_word( lr1_beacon_obj->lr1_mac );
- lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_beacon_obj->lr1_mac );
+ lora_param.sync_word = smtc_real_get_sync_word( lr1_beacon_obj->lr1_mac->real );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_beacon_obj->lr1_mac->real );
lora_param.pkt_params.header_type = RAL_LORA_PKT_IMPLICIT;
lora_param.pkt_params.pld_len_in_bytes = GET_BEACON_LENGTH_BYTES( );
lora_param.pkt_params.crc_is_on = false;
@@ -361,7 +363,6 @@ void smtc_beacon_sniff_launch_callback_for_rp( void* rp_void )
rp_task_abort( rp, id );
return;
}
- smtc_modem_hal_start_radio_tcxo( );
smtc_modem_hal_assert( ralf_setup_lora( rp->radio, &rp->radio_params[id].rx.lora ) == RAL_STATUS_OK );
smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_RX_DONE | RAL_IRQ_RX_TIMEOUT |
RAL_IRQ_RX_HDR_ERROR |
@@ -370,6 +371,8 @@ void smtc_beacon_sniff_launch_callback_for_rp( void* rp_void )
while( ( int32_t )( rp->tasks[id].start_time_ms - smtc_modem_hal_get_time_in_ms( ) ) > 0 )
{
}
+ smtc_modem_hal_start_radio_tcxo( );
+
smtc_modem_hal_assert( ral_set_rx( &( rp->radio->ral ), rp->radio_params[id].rx.timeout_in_ms ) == RAL_STATUS_OK );
rp_stats_set_rx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) );
}
@@ -516,14 +519,14 @@ static uint8_t get_beacon_sf( lr1_stack_mac_t* lr1_mac, uint8_t beacon_datarate
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, beacon_datarate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, beacon_datarate, &sf, &bw );
return sf;
}
static lr1mac_bandwidth_t get_beacon_bw( lr1_stack_mac_t* lr1_mac, uint8_t beacon_datarate )
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, beacon_datarate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, beacon_datarate, &sf, &bw );
return bw;
}
@@ -705,9 +708,10 @@ static void update_beacon_rx_nb_symb( smtc_lr1_beacon_t* lr1_beacon_obj, uint32_
SMTC_MODEM_HAL_TRACE_PRINTF( "rx delay = %d ms\n",
target_time - lr1_beacon_obj->beacon_metadata.last_beacon_received_timestamp );
smtc_real_get_rx_window_parameters(
- lr1_beacon_obj->lr1_mac, BEACON_DATA_RATE( ),
+ lr1_beacon_obj->lr1_mac->real, BEACON_DATA_RATE( ),
( target_time - lr1_beacon_obj->beacon_metadata.last_beacon_received_timestamp ),
- &lr1_beacon_obj->beacon_open_rx_nb_symb, &rx_timeout_symb_in_ms_tmp, &rx_timeout_symb_locked_in_ms_tmp, 0 );
+ &lr1_beacon_obj->beacon_open_rx_nb_symb, &rx_timeout_symb_in_ms_tmp, &rx_timeout_symb_locked_in_ms_tmp, 0,
+ lr1_beacon_obj->lr1_mac->crystal_error );
// in case of beacon has not been YET received 4 times consecutively it enlarge the rx windows.
if( lr1_beacon_obj->beacon_metadata.last_beacon_lost_consecutively == 0 )
{
@@ -723,7 +727,7 @@ static uint32_t compute_start_time( smtc_lr1_beacon_t* lr1_beacon_obj )
{
int8_t board_delay_ms = smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + smtc_modem_hal_get_board_delay_ms( );
int32_t rx_offset_ms;
- smtc_real_get_rx_start_time_offset_ms( lr1_beacon_obj->lr1_mac, BEACON_DATA_RATE( ), board_delay_ms,
+ smtc_real_get_rx_start_time_offset_ms( lr1_beacon_obj->lr1_mac->real, BEACON_DATA_RATE( ), board_delay_ms,
lr1_beacon_obj->beacon_open_rx_nb_symb, &rx_offset_ms );
return ( DPLL_PHASE_MS( ) + rx_offset_ms );
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c
index 4d3cd41..5f38dc3 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_d2d.c
@@ -54,7 +54,7 @@
#define LR1MAC class_b_d2d_obj->ping_slot_obj->lr1_mac
#define RP class_b_d2d_obj->ping_slot_obj->rp
-#define MULTICAST_SYMB_DURATION_US smtc_real_get_symbol_duration_us( LR1MAC, MULTICAST_OBJ->rx_data_rate )
+#define MULTICAST_SYMB_DURATION_US smtc_real_get_symbol_duration_us( LR1MAC->real, MULTICAST_OBJ->rx_data_rate )
#define MULTICAST_SYMB_DURATION_MS \
( ( ( MULTICAST_SYMB_DURATION_US / 1000UL ) == 0 ) ? 1 : ( MULTICAST_SYMB_DURATION_US / 1000UL ) )
#define MAX_TX_PREAMBLE_DURATION_MS 1000UL
@@ -132,8 +132,8 @@ smtc_class_b_d2d_status_t smtc_class_b_d2d_request_tx( smtc_class_b_d2d_t* class
}
status_lorawan_t status = smtc_real_is_payload_size_valid(
- LR1MAC, class_b_d2d_obj->ping_slot_obj->rx_session_param[multi_cast_group_id]->rx_data_rate, payload_size,
- LR1MAC->uplink_dwell_time );
+ LR1MAC->real, class_b_d2d_obj->ping_slot_obj->rx_session_param[multi_cast_group_id]->rx_data_rate, payload_size,
+ UP_LINK, LR1MAC->tx_fopts_current_length );
if( status == ERRORLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( "PAYLOAD SIZE TOO HIGH\n" );
@@ -194,7 +194,7 @@ uint8_t smtc_class_b_d2d_next_max_payload_length_get( smtc_class_b_d2d_t* class_
{
return 0;
}
- return ( smtc_real_get_max_payload_size( LR1MAC, MULTICAST_OBJ->rx_data_rate, LR1MAC->uplink_dwell_time ) - 8 );
+ return ( smtc_real_get_max_payload_size( LR1MAC->real, MULTICAST_OBJ->rx_data_rate, UP_LINK ) - 8 );
}
status_lorawan_t smtc_class_b_d2d_fcnt_down( void* ping_slot_obj_void, uint32_t* fcnt_dwn_stack_tmp, uint32_t mic_in )
@@ -204,7 +204,7 @@ status_lorawan_t smtc_class_b_d2d_fcnt_down( void* ping_slot_obj_void, uint32_t*
uint32_t fractional_second;
uint32_t fcnt_tmp;
status_lorawan_t status = lr1mac_core_convert_rtc_to_gps_epoch_time(
- ping_slot_obj->lr1_mac, smtc_modem_hal_get_time_in_ms( ), &seconds_since_epoch, &fractional_second );
+ ping_slot_obj->lr1_mac, smtc_modem_hal_get_time_in_ms( ), &seconds_since_epoch, &fractional_second );
// number of virtually beacon since 5 jan 1980
uint32_t number_of_beacon_period_since_gps_epoch = seconds_since_epoch >> 7;
@@ -330,16 +330,16 @@ static void class_b_d2d_rp_request( smtc_class_b_d2d_t* class_b_d2d_obj )
lr1mac_bandwidth_t tx_bw;
uint32_t toa;
rp_radio_params_t radio_params = { 0 };
- smtc_real_lora_dr_to_sf_bw( LR1MAC, MULTICAST_OBJ->rx_data_rate, &tx_sf, &tx_bw );
+ smtc_real_lora_dr_to_sf_bw( LR1MAC->real, MULTICAST_OBJ->rx_data_rate, &tx_sf, &tx_bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
lora_param.rf_freq_in_hz = MULTICAST_OBJ->rx_frequency;
- lora_param.sync_word = smtc_real_get_sync_word( LR1MAC );
+ lora_param.sync_word = smtc_real_get_sync_word( LR1MAC->real );
lora_param.output_pwr_in_dbm = smtc_real_clamp_output_power_eirp_vs_freq_and_dr(
- LR1MAC, LR1MAC->tx_power, MULTICAST_OBJ->rx_frequency, MULTICAST_OBJ->rx_data_rate );
+ LR1MAC->real, LR1MAC->tx_power, MULTICAST_OBJ->rx_frequency, MULTICAST_OBJ->rx_data_rate );
lora_param.mod_params.sf = ( ral_lora_sf_t ) tx_sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) tx_bw;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( LR1MAC );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( LR1MAC->real );
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
lora_param.pkt_params.preamble_len_in_symb = preamble_length_symb;
@@ -395,11 +395,11 @@ static void class_b_d2d_launch_callback_for_rp( void* rp_void )
uint8_t sf;
lr1mac_bandwidth_t bw;
modulation_type_t modulation_type =
- smtc_real_get_modulation_type_from_datarate( LR1MAC, MULTICAST_OBJ->rx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( LR1MAC->real, MULTICAST_OBJ->rx_data_rate );
if( modulation_type == LORA )
{
- smtc_real_lora_dr_to_sf_bw( LR1MAC, MULTICAST_OBJ->rx_data_rate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( LR1MAC->real, MULTICAST_OBJ->rx_data_rate, &sf, &bw );
ral_lora_cad_params_t cad_params = { .cad_symb_nb = RAL_LORA_CAD_04_SYMB,
.cad_det_peak_in_symb = class_b_d2d_get_cad_det_peak_4_symb( sf, bw ),
@@ -499,7 +499,7 @@ static uint32_t class_b_d2d_get_fcnt_down( smtc_class_b_d2d_t* class_b_d2d_obj )
static void class_b_d2d_cad_to_tx( smtc_class_b_d2d_t* class_b_d2d_obj )
{
modulation_type_t modulation_type =
- smtc_real_get_modulation_type_from_datarate( LR1MAC, MULTICAST_OBJ->rx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( LR1MAC->real, MULTICAST_OBJ->rx_data_rate );
uint8_t id = class_b_d2d_obj->ping_slot_obj->rp->radio_task_id;
if( modulation_type == LORA )
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c
index 22a860f..106fa38 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_b/smtc_ping_slot.c
@@ -294,7 +294,7 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj )
( ping_slot_obj->lr1_mac->ping_slot_freq_hz != 0 )
? ping_slot_obj->lr1_mac->ping_slot_freq_hz
: smtc_real_get_ping_slot_frequency(
- ping_slot_obj->lr1_mac, ping_slot_seconds_since_epoch,
+ ping_slot_obj->lr1_mac->real, ping_slot_seconds_since_epoch,
ping_slot_obj->rx_session_param[RX_SESSION_UNICAST]->dev_addr );
ping_slot_obj->rx_session_param[RX_SESSION_UNICAST]->rx_data_rate = ping_slot_obj->lr1_mac->ping_slot_dr;
@@ -326,31 +326,33 @@ 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 );
- ping_slot_freq = ( RX_SESSION_PARAM_CURRENT->rx_frequency != 0 )
- ? RX_SESSION_PARAM_CURRENT->rx_frequency
- : smtc_real_get_ping_slot_frequency( ping_slot_obj->lr1_mac, ping_slot_seconds_since_epoch,
- RX_SESSION_PARAM_CURRENT->dev_addr );
+ ping_slot_freq =
+ ( RX_SESSION_PARAM_CURRENT->rx_frequency != 0 )
+ ? RX_SESSION_PARAM_CURRENT->rx_frequency
+ : smtc_real_get_ping_slot_frequency( ping_slot_obj->lr1_mac->real, ping_slot_seconds_since_epoch,
+ RX_SESSION_PARAM_CURRENT->dev_addr );
ping_slot_dr = RX_SESSION_PARAM_CURRENT->rx_data_rate;
- modulation_type = smtc_real_get_modulation_type_from_datarate( ping_slot_obj->lr1_mac, ping_slot_dr );
+ modulation_type = smtc_real_get_modulation_type_from_datarate( ping_slot_obj->lr1_mac->real, ping_slot_dr );
- smtc_real_get_rx_window_parameters( ping_slot_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate,
+ smtc_real_get_rx_window_parameters( ping_slot_obj->lr1_mac->real, RX_SESSION_PARAM_CURRENT->rx_data_rate,
( RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time -
ping_slot_obj->last_valid_rx_beacon_ms ),
&RX_SESSION_PARAM_CURRENT->rx_window_symb, &rx_timeout_symb_in_ms_tmp,
- &rx_timeout_symb_locked_in_ms_tmp, RX_BEACON_TIMESTAMP_ERROR );
+ &rx_timeout_symb_locked_in_ms_tmp, RX_BEACON_TIMESTAMP_ERROR,
+ ping_slot_obj->lr1_mac->crystal_error );
if( modulation_type == LORA )
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( ping_slot_obj->lr1_mac, ping_slot_dr, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( ping_slot_obj->lr1_mac->real, ping_slot_dr, &sf, &bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
- lora_param.sync_word = smtc_real_get_sync_word( ping_slot_obj->lr1_mac );
+ lora_param.sync_word = smtc_real_get_sync_word( ping_slot_obj->lr1_mac->real );
lora_param.symb_nb_timeout = RX_SESSION_PARAM_CURRENT->rx_window_symb;
lora_param.rf_freq_in_hz = ping_slot_freq;
@@ -360,7 +362,7 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj )
lora_param.pkt_params.invert_iq_is_on = true;
lora_param.pkt_params.preamble_len_in_symb = 255;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( ping_slot_obj->lr1_mac );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( ping_slot_obj->lr1_mac->real );
lora_param.mod_params.sf = ( ral_lora_sf_t ) sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) bw;
@@ -374,12 +376,12 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj )
{
SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "MODULATION FSK\n" );
uint8_t kbitrate;
- smtc_real_fsk_dr_to_bitrate( ping_slot_obj->lr1_mac, ping_slot_dr, &kbitrate );
+ smtc_real_fsk_dr_to_bitrate( ping_slot_obj->lr1_mac->real, ping_slot_dr, &kbitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( ping_slot_obj->lr1_mac );
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( ping_slot_obj->lr1_mac->real );
gfsk_param.dc_free_is_on = true;
gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
gfsk_param.crc_seed = GFSK_CRC_SEED;
@@ -412,7 +414,7 @@ void smtc_ping_slot_start( smtc_ping_slot_t* ping_slot_obj )
rp_task.schedule_task_low_priority = true;
int8_t board_delay_ms =
smtc_modem_hal_get_radio_tcxo_startup_delay_ms( ) + smtc_modem_hal_get_board_delay_ms( );
- smtc_real_get_rx_start_time_offset_ms( ping_slot_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate,
+ smtc_real_get_rx_start_time_offset_ms( ping_slot_obj->lr1_mac->real, RX_SESSION_PARAM_CURRENT->rx_data_rate,
board_delay_ms, RX_SESSION_PARAM_CURRENT->rx_window_symb,
&rx_offset_ms_tmp );
rp_task.start_time_ms = RX_SESSION_PARAM_CURRENT->ping_slot_parameters.ping_offset_time + rx_offset_ms_tmp +
@@ -603,9 +605,21 @@ smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_start_session( smtc_ping_s
return SMTC_MC_RC_ERROR_BUSY;
}
- // Check if frequency and datarate are acceptable
- if( ( smtc_real_is_frequency_valid( ping_slot_obj->lr1_mac, freq ) != OKLORAWAN ) ||
- ( smtc_real_is_rx_dr_valid( ping_slot_obj->lr1_mac, dr ) != OKLORAWAN ) )
+ // Check if freq = 0 is acceptable
+ if( ( freq == 0 ) && !smtc_real_is_beacon_hopping( ping_slot_obj->lr1_mac->real ) )
+ {
+ // freq = 0 is only acceptable in regions in which beacon is freq hopping
+ return SMTC_MC_RC_ERROR_PARAM;
+ }
+
+ // Check if non null frequency is acceptable
+ if( ( freq != 0 ) && ( smtc_real_is_frequency_valid( ping_slot_obj->lr1_mac->real, freq ) != OKLORAWAN ) )
+ {
+ return SMTC_MC_RC_ERROR_PARAM;
+ }
+
+ // Check if datarate is acceptable
+ if( ( smtc_real_is_rx_dr_valid( ping_slot_obj->lr1_mac->real, dr ) != OKLORAWAN ) )
{
return SMTC_MC_RC_ERROR_PARAM;
}
@@ -637,6 +651,11 @@ smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_stop_session( smtc_ping_sl
ping_slot_obj->rx_session_param[mc_group_id + 1]->enabled = false;
ping_slot_obj->rx_session_param[mc_group_id + 1]->waiting_beacon_to_start = false;
+ if( ping_slot_obj->rx_session_index == ( mc_group_id + 1 ) )
+ {
+ rp_task_abort( ping_slot_obj->rp, ping_slot_obj->ping_slot_id4rp );
+ }
+
// Reset frequency and datarate to their not init values
ping_slot_obj->rx_session_param[mc_group_id + 1]->rx_frequency = 0;
ping_slot_obj->rx_session_param[mc_group_id + 1]->rx_data_rate = LR1MAC_MC_NO_DATARATE;
@@ -646,17 +665,18 @@ smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_stop_session( smtc_ping_sl
smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_stop_all_sessions( smtc_ping_slot_t* ping_slot_obj )
{
+ smtc_multicast_config_rc_t status = SMTC_MC_RC_OK;
+
for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ )
{
- // Set the enable bit to false to indicate that the session is stopped
- ping_slot_obj->rx_session_param[i + 1]->enabled = false;
- ping_slot_obj->rx_session_param[i + 1]->waiting_beacon_to_start = false;
- // Reset frequency and datarate to their not init values
- ping_slot_obj->rx_session_param[i + 1]->rx_frequency = 0;
- ping_slot_obj->rx_session_param[i + 1]->rx_data_rate = LR1MAC_MC_NO_DATARATE;
+ status = smtc_ping_slot_multicast_b_stop_session( ping_slot_obj, i );
+ if( status != SMTC_MC_RC_OK )
+ {
+ break;
+ }
}
- return SMTC_MC_RC_OK;
+ return status;
}
smtc_multicast_config_rc_t smtc_ping_slot_multicast_b_get_session_status( smtc_ping_slot_t* ping_slot_obj,
@@ -1080,7 +1100,7 @@ static uint32_t smtc_ping_slot_get_duration_timeout_ms( smtc_ping_slot_t* ping_s
uint8_t datarate )
{
uint32_t time_symb_ms =
- ( nb_rx_window_symb * smtc_real_get_symbol_duration_us( ping_slot_obj->lr1_mac, datarate ) ) / 1000;
+ ( nb_rx_window_symb * smtc_real_get_symbol_duration_us( ping_slot_obj->lr1_mac->real, datarate ) ) / 1000;
return ( ( time_symb_ms < 1 ) ? 1 : time_symb_ms );
}
@@ -1088,24 +1108,25 @@ static uint32_t smtc_ping_slot_compute_downlink_toa( lr1_stack_mac_t* lr1_mac, u
{
uint32_t toa = 0;
- modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, datarate );
+ modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac->real, datarate );
if( modulation_type == LORA )
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, datarate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac->real, datarate, &sf, &bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
- lora_param.mod_params.sf = ( ral_lora_sf_t ) sf;
- lora_param.mod_params.bw = ( ral_lora_bw_t ) bw;
- lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac );
- lora_param.pkt_params.preamble_len_in_symb = smtc_real_get_preamble_len( lr1_mac, lora_param.mod_params.sf );
- lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
- lora_param.pkt_params.pld_len_in_bytes = payload_size;
- lora_param.pkt_params.crc_is_on = false;
+ lora_param.mod_params.sf = ( ral_lora_sf_t ) sf;
+ lora_param.mod_params.bw = ( ral_lora_bw_t ) bw;
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( lr1_mac->real );
+ lora_param.pkt_params.preamble_len_in_symb =
+ smtc_real_get_preamble_len( lr1_mac->real, lora_param.mod_params.sf );
+ lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
+ lora_param.pkt_params.pld_len_in_bytes = payload_size;
+ lora_param.pkt_params.crc_is_on = false;
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
toa = ral_get_lora_time_on_air_in_ms( ( &lr1_mac->rp->radio->ral ), ( &lora_param.pkt_params ),
@@ -1114,7 +1135,7 @@ static uint32_t smtc_ping_slot_compute_downlink_toa( lr1_stack_mac_t* lr1_mac, u
else if( modulation_type == FSK )
{
uint8_t bitrate;
- smtc_real_fsk_dr_to_bitrate( lr1_mac, datarate, &bitrate );
+ smtc_real_fsk_dr_to_bitrate( lr1_mac->real, datarate, &bitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
@@ -1141,7 +1162,6 @@ static void ping_slot_mac_rx_lora_launch_callback_for_rp( void* rp_void )
{
radio_planner_t* rp = ( radio_planner_t* ) rp_void;
uint8_t id = rp->radio_task_id;
- smtc_modem_hal_start_radio_tcxo( );
smtc_modem_hal_assert( ralf_setup_lora( rp->radio, &rp->radio_params[id].rx.lora ) == RAL_STATUS_OK );
smtc_modem_hal_assert( ral_set_dio_irq_params( &( rp->radio->ral ), RAL_IRQ_RX_DONE | RAL_IRQ_RX_TIMEOUT |
RAL_IRQ_RX_HDR_ERROR |
@@ -1150,6 +1170,7 @@ static void ping_slot_mac_rx_lora_launch_callback_for_rp( void* rp_void )
while( ( int32_t )( rp->tasks[id].start_time_100us - smtc_modem_hal_get_time_in_100us( ) ) > 0 )
{
}
+ smtc_modem_hal_start_radio_tcxo( );
smtc_modem_hal_assert( ral_set_rx( &( rp->radio->ral ), rp->radio_params[id].rx.timeout_in_ms ) == RAL_STATUS_OK );
rp_stats_set_rx_timestamp( &rp->stats, smtc_modem_hal_get_time_in_ms( ) );
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c
index 93402de..eccc695 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_class_c/lr1mac_class_c.c
@@ -201,19 +201,19 @@ void lr1mac_class_c_launch( lr1mac_class_c_t* class_c_obj )
rp_radio_params_t rp_radio_params = { 0 };
rp_radio_params.rx.timeout_in_ms = 120000;
- modulation_type_t modulation_type =
- smtc_real_get_modulation_type_from_datarate( class_c_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate );
+ modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate(
+ class_c_obj->lr1_mac->real, RX_SESSION_PARAM_CURRENT->rx_data_rate );
if( modulation_type == LORA )
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( class_c_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( class_c_obj->lr1_mac->real, RX_SESSION_PARAM_CURRENT->rx_data_rate, &sf, &bw );
ralf_params_lora_t lora_param;
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
- lora_param.sync_word = smtc_real_get_sync_word( class_c_obj->lr1_mac );
+ lora_param.sync_word = smtc_real_get_sync_word( class_c_obj->lr1_mac->real );
lora_param.symb_nb_timeout = 0;
lora_param.rf_freq_in_hz = RX_SESSION_PARAM_CURRENT->rx_frequency;
@@ -222,9 +222,9 @@ void lr1mac_class_c_launch( lr1mac_class_c_t* class_c_obj )
lora_param.pkt_params.crc_is_on = false;
lora_param.pkt_params.invert_iq_is_on = true;
lora_param.pkt_params.preamble_len_in_symb =
- smtc_real_get_preamble_len( class_c_obj->lr1_mac, lora_param.mod_params.sf );
+ smtc_real_get_preamble_len( class_c_obj->lr1_mac->real, lora_param.mod_params.sf );
- lora_param.mod_params.cr = smtc_real_get_coding_rate( class_c_obj->lr1_mac );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( class_c_obj->lr1_mac->real );
lora_param.mod_params.sf = ( ral_lora_sf_t ) sf;
lora_param.mod_params.bw = ( ral_lora_bw_t ) bw;
lora_param.mod_params.ldro = ral_compute_lora_ldro( lora_param.mod_params.sf, lora_param.mod_params.bw );
@@ -236,11 +236,11 @@ void lr1mac_class_c_launch( lr1mac_class_c_t* class_c_obj )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "MODULATION FSK\n" );
uint8_t kbitrate;
- smtc_real_fsk_dr_to_bitrate( class_c_obj->lr1_mac, RX_SESSION_PARAM_CURRENT->rx_data_rate, &kbitrate );
+ smtc_real_fsk_dr_to_bitrate( class_c_obj->lr1_mac->real, RX_SESSION_PARAM_CURRENT->rx_data_rate, &kbitrate );
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( class_c_obj->lr1_mac );
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( class_c_obj->lr1_mac->real );
gfsk_param.dc_free_is_on = true;
gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
gfsk_param.crc_seed = GFSK_CRC_SEED;
@@ -410,8 +410,8 @@ smtc_multicast_config_rc_t lr1mac_class_c_multicast_start_session( lr1mac_class_
}
// Check if frequency and datarate are acceptable
- if( ( smtc_real_is_frequency_valid( class_c_obj->lr1_mac, freq ) != OKLORAWAN ) ||
- ( smtc_real_is_rx_dr_valid( class_c_obj->lr1_mac, dr ) != OKLORAWAN ) )
+ if( ( smtc_real_is_frequency_valid( class_c_obj->lr1_mac->real, freq ) != OKLORAWAN ) ||
+ ( smtc_real_is_rx_dr_valid( class_c_obj->lr1_mac->real, dr ) != OKLORAWAN ) )
{
return SMTC_MC_RC_ERROR_PARAM;
}
@@ -507,31 +507,17 @@ smtc_multicast_config_rc_t lr1mac_class_c_multicast_stop_session( lr1mac_class_c
smtc_multicast_config_rc_t lr1mac_class_c_multicast_stop_all_sessions( lr1mac_class_c_t* class_c_obj )
{
- uint8_t active_sessions = 0;
+ smtc_multicast_config_rc_t status = SMTC_MC_RC_OK;
for( uint8_t i = 0; i < LR1MAC_MC_NUMBER_OF_SESSION; i++ )
{
- if( class_c_obj->rx_session_param[i + 1]->enabled == true )
+ status = lr1mac_class_c_multicast_stop_session( class_c_obj, i );
+ if( status != SMTC_MC_RC_OK )
{
- // Set the enable bit to false to indicate that the session is stopped
- class_c_obj->rx_session_param[i + 1]->enabled = false;
- // Reset frequency and datarate to their not init values
- class_c_obj->rx_session_param[i + 1]->rx_frequency = 0;
- class_c_obj->rx_session_param[i + 1]->rx_data_rate = LR1MAC_MC_NO_DATARATE;
- // Increment the counter of active sessions
- active_sessions++;
+ break;
}
}
-
- if( active_sessions != 0 )
- {
- // As there is no more multicast sessions enabled => restart unicast session
- // a new rx c with unicast param task will be enqueue automatically if class C is still active
- class_c_obj->rx_session_param[RX_SESSION_UNICAST]->enabled = true;
- // Abort current continuous reception for multicast sessions
- rp_task_abort( class_c_obj->rp, class_c_obj->class_c_id4rp );
- }
- return SMTC_MC_RC_OK;
+ return status;
}
smtc_multicast_config_rc_t lr1mac_class_c_multicast_get_session_status( lr1mac_class_c_t* class_c_obj,
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.c
index eb55678..10a6797 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.c
@@ -96,9 +96,8 @@ static void try_recover_nvm( lr1_stack_mac_t* lr1_mac_obj );
*/
void lr1mac_core_init( lr1_stack_mac_t* lr1_mac_obj, smtc_real_t* real, smtc_lbt_t* lbt_obj, smtc_dtc_t* dtc_obj,
- radio_planner_t* rp, lr1mac_activation_mode_t activation_mode,
- smtc_real_region_types_t smtc_real_region_types, void ( *push_callback )( void* push_context ),
- void* push_context )
+ radio_planner_t* rp, lr1mac_activation_mode_t activation_mode,
+ void ( *push_callback )( void* push_context ), void* push_context )
{
memset( lr1_mac_obj, 0, sizeof( lr1_stack_mac_t ) );
@@ -114,7 +113,8 @@ void lr1mac_core_init( lr1_stack_mac_t* lr1_mac_obj, smtc_real_t* real, smtc_lbt
lr1_mac_obj->push_context = push_context;
lr1_mac_obj->crystal_error = BSP_CRYSTAL_ERROR;
lr1_mac_obj->device_time_invalid_delay_s = LR1MAC_DEVICE_TIME_DELAY_TO_BE_NO_SYNC;
- lr1_stack_mac_init( lr1_mac_obj, activation_mode, smtc_real_region_types );
+
+ lr1_stack_mac_init( lr1_mac_obj, activation_mode );
status_lorawan_t status = lr1mac_core_context_load( lr1_mac_obj );
@@ -148,31 +148,30 @@ void lr1mac_core_init( lr1_stack_mac_t* lr1_mac_obj, smtc_real_t* real, smtc_lbt
lr1mac_core_context_save( lr1_mac_obj );
}
- load_devnonce_reset( lr1_mac_obj );
- lr1_mac_obj->nb_of_reset += 1; // increment reset counter when lr1mac_core_init is called, reset is saved when
- // devnonce is save (after a tx join)
- SMTC_MODEM_HAL_TRACE_PRINTF( " DevNonce = %d\n", lr1_mac_obj->dev_nonce );
- SMTC_MODEM_HAL_TRACE_PRINTF( " JoinNonce = 0x%02x %02x %02x, NetID = 0x%02x %02x %02x\n",
- lr1_mac_obj->join_nonce[0], lr1_mac_obj->join_nonce[1], lr1_mac_obj->join_nonce[2],
- lr1_mac_obj->join_nonce[3], lr1_mac_obj->join_nonce[4], lr1_mac_obj->join_nonce[5] );
- SMTC_MODEM_HAL_TRACE_PRINTF( " NbOfReset = %d\n", lr1_mac_obj->nb_of_reset );
- SMTC_MODEM_HAL_TRACE_PRINTF( " Region = %s\n", smtc_real_region_list_str[lr1_mac_obj->real->region_type] );
-
lr1_mac_obj->rp = rp;
lr1_mac_obj->no_rx_packet_reset_threshold = LR1MAC_NO_RX_PACKET_RESET_THRESHOLD;
rp_hook_init( lr1_mac_obj->rp, lr1_mac_obj->stack_id4rp, ( void ( * )( void* ) )( lr1_stack_mac_rp_callback ),
( lr1_mac_obj ) );
SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "rp_hook_init done\n" );
- smtc_real_config( lr1_mac_obj );
- SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "smtc_real_config done\n" );
- smtc_real_init( lr1_mac_obj );
- SMTC_MODEM_HAL_TRACE_PRINTF_DEBUG( "smtc_real_init done\n" );
+ lr1_stack_mac_region_init( lr1_mac_obj, lr1_mac_obj->real->region_type );
+ lr1_stack_mac_region_config( lr1_mac_obj );
+
+ load_devnonce_reset( lr1_mac_obj );
// Initialize here adr_ack_limit_init and adr_ack_delay_init which are real dependant and must be updated after the
// real is initialized and not reinit after the join accept
- lr1_mac_obj->adr_ack_limit_init = smtc_real_get_adr_ack_limit( lr1_mac_obj );
- lr1_mac_obj->adr_ack_delay_init = smtc_real_get_adr_ack_delay( lr1_mac_obj );
+ lr1_mac_obj->adr_ack_limit_init = smtc_real_get_adr_ack_limit( lr1_mac_obj->real );
+ lr1_mac_obj->adr_ack_delay_init = smtc_real_get_adr_ack_delay( lr1_mac_obj->real );
+
+ lr1_mac_obj->nb_of_reset += 1; // increment reset counter when lr1mac_core_init is called, reset is saved when
+ // devnonce is save (after a tx join)
+ SMTC_MODEM_HAL_TRACE_PRINTF( " DevNonce = %d\n", lr1_mac_obj->dev_nonce );
+ SMTC_MODEM_HAL_TRACE_PRINTF( " JoinNonce = 0x%02x %02x %02x, NetID = 0x%02x %02x %02x\n",
+ lr1_mac_obj->join_nonce[0], lr1_mac_obj->join_nonce[1], lr1_mac_obj->join_nonce[2],
+ lr1_mac_obj->join_nonce[3], lr1_mac_obj->join_nonce[4], lr1_mac_obj->join_nonce[5] );
+ SMTC_MODEM_HAL_TRACE_PRINTF( " NbOfReset = %d\n", lr1_mac_obj->nb_of_reset );
+ SMTC_MODEM_HAL_TRACE_PRINTF( " Region = %s\n", smtc_real_region_list_str[lr1_mac_obj->real->region_type] );
}
/***********************************************************************************************/
@@ -227,15 +226,15 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj )
lr1_mac_obj->radio_process_state = RADIOSTATE_PENDING;
DBG_PRINT_WITH_LINE( "Send Payload HOOK ID = %d", myhook_id );
-#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
modulation_type_t tx_modulation_type =
- smtc_real_get_modulation_type_from_datarate( lr1_mac_obj, lr1_mac_obj->tx_data_rate );
+ smtc_real_get_modulation_type_from_datarate( lr1_mac_obj->real, lr1_mac_obj->tx_data_rate );
+#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
if( tx_modulation_type == LORA )
{
uint8_t tx_sf;
lr1mac_bandwidth_t tx_bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac_obj, lr1_mac_obj->tx_data_rate, &tx_sf, &tx_bw );
+ smtc_real_lora_dr_to_sf_bw( lr1_mac_obj->real, lr1_mac_obj->tx_data_rate, &tx_sf, &tx_bw );
SMTC_MODEM_HAL_TRACE_PRINTF(
" Tx LoRa at %u ms: freq:%u, SF%u, %s, len %u bytes %d dBm, fcnt_up %d, toa = %d\n",
@@ -254,7 +253,7 @@ lr1mac_states_t lr1mac_core_process( lr1_stack_mac_t* lr1_mac_obj )
{
lr_fhss_v1_cr_t tx_cr;
lr_fhss_v1_bw_t tx_bw;
- smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac_obj, lr1_mac_obj->tx_data_rate, &tx_cr, &tx_bw );
+ smtc_real_lr_fhss_dr_to_cr_bw( lr1_mac_obj->real, lr1_mac_obj->tx_data_rate, &tx_cr, &tx_bw );
SMTC_MODEM_HAL_TRACE_PRINTF(
" Tx LR FHSS at %u ms: freq:%u, DR%u (%s, %s Hz), len %u bytes, %d dBm, fcnt_up %d, toa = %d\n",
lr1_mac_obj->rtc_target_timer_ms, lr1_mac_obj->tx_frequency, lr1_mac_obj->tx_data_rate,
@@ -393,7 +392,7 @@ status_lorawan_t lr1mac_core_join( lr1_stack_mac_t* lr1_mac_obj, uint32_t target
}
if( lr1mac_core_get_activation_mode( lr1_mac_obj ) == ACTIVATION_MODE_ABP )
{
- SMTC_MODEM_HAL_TRACE_ERROR( "ABP DEVICE CAN'T PROCCED A JOIN REQUEST\n" );
+ SMTC_MODEM_HAL_TRACE_ERROR( "ABP DEVICE CAN'T PROCEED A JOIN REQUEST\n" );
return ERRORLORAWAN;
}
uint32_t current_timestamp = smtc_modem_hal_get_time_in_s( );
@@ -401,7 +400,7 @@ status_lorawan_t lr1mac_core_join( lr1_stack_mac_t* lr1_mac_obj, uint32_t target
lr1_mac_obj->rtc_target_timer_ms = target_time_ms;
lr1_mac_obj->join_status = JOINING;
- smtc_real_init( lr1_mac_obj );
+ lr1_stack_mac_region_config( lr1_mac_obj );
// check adr mode to see if it is already set in join DR and it is the first join try or if adr was set to other DR
if( ( lr1_mac_obj->adr_mode_select != JOIN_DR_DISTRIBUTION ) ||
@@ -409,19 +408,23 @@ status_lorawan_t lr1mac_core_join( lr1_stack_mac_t* lr1_mac_obj, uint32_t target
{
// if it is the case force dr distribution to join
lr1_mac_obj->adr_mode_select_tmp = lr1_mac_obj->adr_mode_select;
- smtc_real_set_dr_distribution( lr1_mac_obj, JOIN_DR_DISTRIBUTION );
+ smtc_real_set_dr_distribution( lr1_mac_obj->real, JOIN_DR_DISTRIBUTION, &lr1_mac_obj->nb_trans,
+ lr1_mac_obj->adr_custom );
lr1_mac_obj->adr_mode_select = JOIN_DR_DISTRIBUTION;
}
- smtc_real_get_next_dr( lr1_mac_obj );
+ smtc_real_get_next_tx_dr( lr1_mac_obj->real, lr1_mac_obj->join_status, &lr1_mac_obj->adr_mode_select,
+ &lr1_mac_obj->tx_data_rate, lr1_mac_obj->tx_data_rate_adr, &lr1_mac_obj->adr_enable );
smtc_duty_cycle_update( lr1_mac_obj->dtc_obj );
- if( smtc_real_get_join_next_channel( lr1_mac_obj ) != OKLORAWAN )
+ if( smtc_real_get_join_next_channel( lr1_mac_obj->real, lr1_mac_obj->dtc_obj, &lr1_mac_obj->tx_data_rate,
+ &lr1_mac_obj->tx_frequency, &lr1_mac_obj->rx1_frequency,
+ &lr1_mac_obj->rx2_frequency ) != OKLORAWAN )
{
return ERRORLORAWAN;
}
lr1_stack_mac_join_request_build( lr1_mac_obj );
- lr1_mac_obj->rx1_delay_s = smtc_real_get_rx1_join_delay( lr1_mac_obj );
- lr1_mac_obj->rx2_data_rate = smtc_real_get_rx2_join_dr( lr1_mac_obj );
+ lr1_mac_obj->rx1_delay_s = smtc_real_get_rx1_join_delay( lr1_mac_obj->real );
+ lr1_mac_obj->rx2_data_rate = smtc_real_get_rx2_join_dr( lr1_mac_obj->real );
// check if it first join try
if( lr1_mac_obj->retry_join_cpt == 0 )
@@ -449,7 +452,7 @@ void lr1mac_core_join_status_clear( lr1_stack_mac_t* lr1_mac_obj )
{
lr1_mac_obj->join_status = NOT_JOINED;
lr1mac_core_abort( lr1_mac_obj );
- smtc_real_init_join_snapshot_channel_mask( lr1_mac_obj );
+ smtc_real_init_join_snapshot_channel_mask( lr1_mac_obj->real );
lr1_mac_obj->retry_join_cpt = 0;
}
@@ -538,8 +541,8 @@ status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t
size_in = 0;
}
- status_lorawan_t status = smtc_real_is_payload_size_valid( lr1_mac_obj, lr1_mac_obj->tx_data_rate, size_in,
- lr1_mac_obj->uplink_dwell_time );
+ status_lorawan_t status = smtc_real_is_payload_size_valid( lr1_mac_obj->real, lr1_mac_obj->tx_data_rate, size_in,
+ UP_LINK, lr1_mac_obj->tx_fopts_current_length );
if( status == ERRORLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( "PAYLOAD SIZE TOO HIGH\n" );
@@ -565,7 +568,8 @@ status_lorawan_t lr1mac_core_payload_send( lr1_stack_mac_t* lr1_mac_obj, uint8_t
}
// Decrement duty cycle before check the available DTC
smtc_duty_cycle_update( lr1_mac_obj->dtc_obj );
- if( smtc_real_get_next_channel( lr1_mac_obj ) != OKLORAWAN )
+ if( smtc_real_get_next_channel( lr1_mac_obj->real, lr1_mac_obj->dtc_obj, lr1_mac_obj->tx_data_rate,
+ &lr1_mac_obj->tx_frequency, &lr1_mac_obj->rx1_frequency ) != OKLORAWAN )
{
return ERRORLORAWAN;
}
@@ -610,21 +614,26 @@ status_lorawan_t lr1mac_core_dr_strategy_set( lr1_stack_mac_t* lr1_mac_obj, dr_s
if( adr_mode_select == STATIC_ADR_MODE )
{
- lr1_mac_obj->tx_data_rate_adr = smtc_real_get_min_tx_channel_dr( lr1_mac_obj );
+ lr1_mac_obj->tx_data_rate_adr = smtc_real_get_min_tx_channel_dr( lr1_mac_obj->real );
}
else
{
- lr1_mac_obj->tx_power = smtc_real_get_default_max_eirp( lr1_mac_obj );
+ lr1_mac_obj->tx_power = smtc_real_get_default_max_eirp( lr1_mac_obj->real );
}
- smtc_real_set_dr_distribution( lr1_mac_obj, adr_mode_select );
- status = smtc_real_get_next_dr( lr1_mac_obj );
+ smtc_real_set_dr_distribution( lr1_mac_obj->real, adr_mode_select, &lr1_mac_obj->nb_trans,
+ lr1_mac_obj->adr_custom );
+ status =
+ smtc_real_get_next_tx_dr( lr1_mac_obj->real, lr1_mac_obj->join_status, &lr1_mac_obj->adr_mode_select,
+ &lr1_mac_obj->tx_data_rate, lr1_mac_obj->tx_data_rate_adr, &lr1_mac_obj->adr_enable );
if( status == ERRORLORAWAN ) // new adr profile no compatible with channel mask, retreive old adr profile
{
lr1_mac_obj->adr_mode_select = adr_mode_select_cpy;
- smtc_real_set_dr_distribution( lr1_mac_obj, adr_mode_select_cpy );
- smtc_real_get_next_dr( lr1_mac_obj );
+ smtc_real_set_dr_distribution( lr1_mac_obj->real, adr_mode_select_cpy, &lr1_mac_obj->nb_trans,
+ lr1_mac_obj->adr_custom );
+ smtc_real_get_next_tx_dr( lr1_mac_obj->real, lr1_mac_obj->join_status, &lr1_mac_obj->adr_mode_select,
+ &lr1_mac_obj->tx_data_rate, lr1_mac_obj->tx_data_rate_adr, &lr1_mac_obj->adr_enable );
}
return ( status );
}
@@ -701,7 +710,7 @@ void lr1mac_core_context_save( lr1_stack_mac_t* lr1_mac_obj )
/**************************************************/
uint32_t lr1mac_core_next_max_payload_length_get( lr1_stack_mac_t* lr1_mac_obj )
{
- return ( smtc_real_get_max_payload_size( lr1_mac_obj, lr1_mac_obj->tx_data_rate, lr1_mac_obj->uplink_dwell_time ) -
+ return ( smtc_real_get_max_payload_size( lr1_mac_obj->real, lr1_mac_obj->tx_data_rate, UP_LINK ) -
lr1_mac_obj->tx_fopts_current_length - FHDROFFSET );
}
@@ -813,9 +822,10 @@ int32_t lr1mac_core_next_free_duty_cycle_ms_get( lr1_stack_mac_t* lr1_mac_obj )
int32_t region_dtc = 0;
int32_t nwk_dtc = lr1_stack_network_next_free_duty_cycle_ms_get( lr1_mac_obj );
- if( smtc_real_is_dtc_supported( lr1_mac_obj ) == true )
+ if( smtc_real_is_dtc_supported( lr1_mac_obj->real ) == true )
{
- if( smtc_real_get_current_enabled_frequency_list( lr1_mac_obj, &number_of_freq, freq_list, max_size ) == true )
+ if( smtc_real_get_current_enabled_frequency_list( lr1_mac_obj->real, &number_of_freq, freq_list, max_size ) ==
+ true )
{
region_dtc = smtc_duty_cycle_get_next_free_time_ms( lr1_mac_obj->dtc_obj, number_of_freq, freq_list );
}
@@ -851,10 +861,10 @@ status_lorawan_t lr1mac_core_set_region( lr1_stack_mac_t* lr1_mac_obj, smtc_real
{
if( smtc_real_is_supported_region( region_type ) == SMTC_REAL_STATUS_OK )
{
- lr1_mac_obj->real->region_type = region_type;
+ lr1_stack_mac_region_init( lr1_mac_obj, region_type );
+ lr1_stack_mac_region_config( lr1_mac_obj );
lr1mac_core_context_save( lr1_mac_obj );
- smtc_real_config( lr1_mac_obj );
- smtc_real_init( lr1_mac_obj );
+
// After a region change a new join should happen, reset join counter
lr1_mac_obj->retry_join_cpt = 0;
return OKLORAWAN;
@@ -990,17 +1000,6 @@ uint32_t lr1mac_core_get_time_left_connection_lost( lr1_stack_mac_t* lr1_mac_obj
return ( time_left_connection_lost );
}
-void lr1mac_core_set_device_time_callback( lr1_stack_mac_t* lr1_mac_obj,
- void ( *device_time_callback )( void* context, uint32_t rx_timestamp_s ),
- void* context, uint32_t rx_timestamp_s )
-{
- if( device_time_callback != NULL )
- {
- lr1_mac_obj->device_time_callback = device_time_callback;
- lr1_mac_obj->device_time_callback_context = context;
- }
-}
-
status_lorawan_t lr1_mac_core_set_device_time_invalid_delay_s( lr1_stack_mac_t* lr1_mac_obj, uint32_t delay_s )
{
if( delay_s > LR1MAC_DEVICE_TIME_DELAY_TO_BE_NO_SYNC )
@@ -1145,6 +1144,7 @@ void lr1mac_core_abort( lr1_stack_mac_t* lr1_mac_obj )
lr1_mac_obj->type_of_ans_to_send = NOFRAME_TOSEND;
lr1_mac_obj->rx_metadata.rx_window = RECEIVE_NONE;
lr1_mac_obj->nb_trans_cpt = 1;
+ lr1_mac_obj->lr1mac_state = LWPSTATE_IDLE;
rp_task_abort( lr1_mac_obj->rp, lr1_mac_obj->stack_id4rp );
}
@@ -1159,7 +1159,8 @@ static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj )
{
//@note because datarate Distribution has been changed during join
lr1_mac_obj->adr_mode_select = lr1_mac_obj->adr_mode_select_tmp;
- smtc_real_set_dr_distribution( lr1_mac_obj, lr1_mac_obj->adr_mode_select_tmp );
+ smtc_real_set_dr_distribution( lr1_mac_obj->real, lr1_mac_obj->adr_mode_select_tmp, &lr1_mac_obj->nb_trans,
+ lr1_mac_obj->adr_custom );
save_devnonce_rst( lr1_mac_obj );
}
else
@@ -1200,7 +1201,8 @@ static void lr1mac_mac_update( lr1_stack_mac_t* lr1_mac_obj )
{ // @note ack send during the next tx|| ( packet.IsFrameToSend == USERACK_TOSEND ) ) {
// Decrement duty cycle before check the available DTC
smtc_duty_cycle_update( lr1_mac_obj->dtc_obj );
- if( smtc_real_get_next_channel( lr1_mac_obj ) != OKLORAWAN )
+ if( smtc_real_get_next_channel( lr1_mac_obj->real, lr1_mac_obj->dtc_obj, lr1_mac_obj->tx_data_rate,
+ &lr1_mac_obj->tx_frequency, &lr1_mac_obj->rx1_frequency ) != OKLORAWAN )
{
lr1_mac_obj->lr1mac_state = LWPSTATE_IDLE;
if( lr1_mac_obj->type_of_ans_to_send == USRFRAME_TORETRANSMIT )
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.h
index 4fdfe19..429f830 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_core.h
@@ -58,14 +58,12 @@
* @param dtc_obj // Duty cycle object
* @param rp // Radio Planner object
* @param otaa_abp_conf // Activation mode, only OTAA is supported
- * @param smtc_real_region_types // Contains the regions type (EU868, US915, ...)
* @param push_callback // Callback to push received downlink
* @param push_context // Context concerning the downlink
*/
void lr1mac_core_init( lr1_stack_mac_t* lr1_mac_obj, smtc_real_t* real, smtc_lbt_t* lbt_obj, smtc_dtc_t* dtc_obj,
- radio_planner_t* rp, lr1mac_activation_mode_t otaa_abp_conf,
- smtc_real_region_types_t smtc_real_region_types, void ( *push_callback )( void* push_context ),
- void* push_context );
+ radio_planner_t* rp, lr1mac_activation_mode_t otaa_abp_conf,
+ void ( *push_callback )( void* push_context ), void* push_context );
/**
* \brief Sends an uplink
@@ -547,16 +545,6 @@ uint32_t lr1mac_core_get_timestamp_last_device_time_ans_s( lr1_stack_mac_t* lr1_
*/
uint32_t lr1mac_core_get_time_left_connection_lost( lr1_stack_mac_t* lr1_mac_obj );
-/**
- * @brief Set the callback called when a network DeviceTimeAns is received
- *
- * @param lr1_mac_obj
- * @param device_time_callback
- */
-void lr1mac_core_set_device_time_callback( lr1_stack_mac_t* lr1_mac_obj,
- void ( *device_time_callback )( void* context, uint32_t rx_timestamp_s ),
- void* context, uint32_t rx_timestamp_s );
-
/**
* @brief Set delay in seconds to concider time no more valid if no time sync received
*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_defs.h
index e9b5cbe..f452017 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_defs.h
@@ -124,9 +124,7 @@ extern "C" {
// if there were no rx packet before the last LR1MAC_NO_RX_PACKET_RESET_THRESHOLD tx packets the lr1mac goes in panic
#define LR1MAC_NO_RX_PACKET_RESET_THRESHOLD (2400)
-// Frame direction definition for up/down link communications
-#define UP_LINK 0
-#define DOWN_LINK 1
+
// #define MAX_FCNT_GAP 16384
@@ -142,6 +140,13 @@ extern "C" {
* --- PUBLIC TYPES ----------------------------------------------------------------
*/
+// Frame direction definition for up/down link communications
+typedef enum direction_frame_e
+{
+ UP_LINK = 0,
+ DOWN_LINK = 1
+} direction_frame_t;
+
typedef enum lr1mac_states_e
{
LWPSTATE_IDLE,
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_utilities.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_utilities.c
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_utilities.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/lr1mac_utilities.h
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/services/smtc_lbt.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/services/smtc_lbt.c
index 314595a..36f95bc 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/services/smtc_lbt.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/services/smtc_lbt.c
@@ -174,15 +174,17 @@ void smtc_lbt_listen_channel( smtc_lbt_t* lbt_obj, uint32_t freq, bool is_at_tim
rp_task.duration_time_ms = lbt_obj->listen_duration_ms + tx_duration_ms;
rp_task.type = RP_TASK_TYPE_LBT;
rp_task.launch_task_callbacks = smtc_lbt_launch_callback_for_rp;
- rp_task.start_time_ms =
- target_time_ms - lbt_obj->listen_duration_ms - smtc_modem_hal_get_radio_tcxo_startup_delay_ms( );
if( is_at_time == true )
{
+ rp_task.start_time_ms =
+ target_time_ms - lbt_obj->listen_duration_ms - smtc_modem_hal_get_radio_tcxo_startup_delay_ms( );
rp_task.state = RP_TASK_STATE_SCHEDULE;
}
else
{
- rp_task.state = RP_TASK_STATE_ASAP;
+ rp_task.start_time_ms = target_time_ms;
+ rp_task.state = RP_TASK_STATE_ASAP;
+ rp_task.state = RP_TASK_STATE_ASAP;
}
if( rp_task_enqueue( lbt_obj->rp, &rp_task, NULL, 0, &radio_params ) != RP_HOOK_STATUS_OK )
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c
index baf31db..51f7bf0 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.c
@@ -48,15 +48,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.as923.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.as923.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.as923.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.as923.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.as923.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.as923.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.as923.unwrapped_channel_mask
+#define tx_frequency_channel real->region.as923.tx_frequency_channel
+#define rx1_frequency_channel real->region.as923.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.as923.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.as923.channel_index_enabled
+#define dr_distribution_init real->region.as923.dr_distribution_init
+#define dr_distribution real->region.as923.dr_distribution
+#define unwrapped_channel_mask real->region.as923.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -82,81 +83,83 @@
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_as_923_config( lr1_stack_mac_t* lr1_mac, uint8_t group_id )
+void region_as_923_init( smtc_real_t* real, uint8_t group_id )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_AS_923;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_AS_923;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_AS_923;
- const_number_of_channel_bank = BANK_MAX_AS923;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_AS_923;
- const_received_delay1 = RECEIVE_DELAY1_AS_923;
- const_tx_power_dbm = TX_POWER_EIRP_AS_923 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_AS_923;
- const_adr_ack_limit = ADR_ACK_LIMIT_AS_923;
- const_adr_ack_delay = ADR_ACK_DELAY_AS_923;
- const_datarate_backoff = &datarate_backoff_as_923[0][0];
- const_ack_timeout = ACK_TIMEOUT_AS_923;
- const_frequency_factor = FREQUENCY_FACTOR_AS_923;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_AS_923;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_AS_923;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_AS_923;
+ real_const.const_number_of_channel_bank = BANK_MAX_AS923;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_AS_923;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_AS_923;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_AS_923 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_AS_923;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_AS_923;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_AS_923;
+ real_const.const_datarate_offsets = &datarate_offsets_as_923[0][0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_as_923[0][0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_AS_923;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_AS_923;
switch( group_id )
{
case 1: // AS923 groupe 1
- const_frequency_offset_hz = FREQOFFSET_GRP1_AS_923 * const_frequency_factor;
- const_freq_min = FREQMIN_GRP1_AS_923;
- const_freq_max = FREQMAX_GRP1_AS_923;
+ real_const.const_frequency_offset_hz = FREQOFFSET_GRP1_AS_923 * real_const.const_frequency_factor;
+ real_const.const_freq_min = FREQMIN_GRP1_AS_923;
+ real_const.const_freq_max = FREQMAX_GRP1_AS_923;
break;
case 2: // AS923 groupe 2
- const_frequency_offset_hz = FREQOFFSET_GRP2_AS_923 * const_frequency_factor;
- const_freq_min = FREQMIN_GRP2_AS_923;
- const_freq_max = FREQMAX_GRP2_AS_923;
+ real_const.const_frequency_offset_hz = FREQOFFSET_GRP2_AS_923 * real_const.const_frequency_factor;
+ real_const.const_freq_min = FREQMIN_GRP2_AS_923;
+ real_const.const_freq_max = FREQMAX_GRP2_AS_923;
break;
case 3: // AS923 groupe 3
- const_frequency_offset_hz = FREQOFFSET_GRP3_AS_923 * const_frequency_factor;
- const_freq_min = FREQMIN_GRP3_AS_923;
- const_freq_max = FREQMAX_GRP3_AS_923;
+ real_const.const_frequency_offset_hz = FREQOFFSET_GRP3_AS_923 * real_const.const_frequency_factor;
+ real_const.const_freq_min = FREQMIN_GRP3_AS_923;
+ real_const.const_freq_max = FREQMAX_GRP3_AS_923;
break;
case 4: // AS923 groupe 4
- const_frequency_offset_hz = FREQOFFSET_GRP4_AS_923 * const_frequency_factor;
- const_freq_min = FREQMIN_GRP4_AS_923;
- const_freq_max = FREQMAX_GRP4_AS_923;
+ real_const.const_frequency_offset_hz = FREQOFFSET_GRP4_AS_923 * real_const.const_frequency_factor;
+ real_const.const_freq_min = FREQMIN_GRP4_AS_923;
+ real_const.const_freq_max = FREQMAX_GRP4_AS_923;
break;
default:
smtc_modem_hal_lr1mac_panic( );
break;
}
- const_rx2_freq = RX2_FREQ_AS_923 + const_frequency_offset_hz;
-
- const_rx2_dr_init = RX2DR_INIT_AS_923;
- const_sync_word_private = SYNC_WORD_PRIVATE_AS_923;
- const_sync_word_public = SYNC_WORD_PUBLIC_AS_923;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_AS_923;
- const_min_tx_dr = MIN_DR_AS_923;
- const_max_tx_dr = MAX_DR_AS_923;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_AS_923;
- const_min_rx_dr = MIN_DR_AS_923;
- const_max_rx_dr = MAX_DR_AS_923;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_AS_923;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_AS_923;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_AS_923;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_AS_923;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_AS_923;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_AS_923;
- const_dtc_supported = DTC_SUPPORTED_AS_923;
- const_lbt_supported = LBT_SUPPORTED_AS_923;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_AS_923;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_AS_923;
- const_lbt_bw_hz = LBT_BW_HZ_AS_923;
- const_max_payload_m = &M_as_923[0][0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AS_923[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AS_923[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_AS_923[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_AS_923[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_AS_923;
- const_beacon_dr = BEACON_DR_AS_923;
- const_beacon_frequency = BEACON_FREQ_AS_923 + const_frequency_offset_hz;
- const_ping_slot_frequency = PING_SLOT_FREQ_AS_923 + const_frequency_offset_hz;
+ real_const.const_rx2_freq = RX2_FREQ_AS_923 + real_const.const_frequency_offset_hz;
+
+ real_const.const_rx2_dr_init = RX2DR_INIT_AS_923;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_AS_923;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_AS_923;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_AS_923;
+ real_const.const_min_tx_dr = MIN_DR_AS_923;
+ real_const.const_max_tx_dr = MAX_DR_AS_923;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_AS_923;
+ real_const.const_min_rx_dr = MIN_DR_AS_923;
+ real_const.const_max_rx_dr = MAX_DR_AS_923;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_AS_923;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_AS_923;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_AS_923;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_AS_923;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_AS_923;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_AS_923;
+ real_const.const_dtc_supported = DTC_SUPPORTED_AS_923;
+ real_const.const_lbt_supported = LBT_SUPPORTED_AS_923;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_AS_923;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_AS_923;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_AS_923;
+ real_const.const_max_payload_m = &M_as_923[0][0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AS_923[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AS_923[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_AS_923[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_AS_923[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_AS_923;
+ real_const.const_beacon_dr = BEACON_DR_AS_923;
+ real_const.const_beacon_frequency = BEACON_FREQ_AS_923 + real_const.const_frequency_offset_hz;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_AS_923 + real_const.const_frequency_offset_hz;
+ real_const.const_uplink_dwell_time = UPLINK_DWELL_TIME_AS_923;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -166,52 +169,51 @@ void region_as_923_config( lr1_stack_mac_t* lr1_mac, uint8_t group_id )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_as_923_init( lr1_stack_mac_t* lr1_mac )
+void region_as_923_config( smtc_real_t* real )
{
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
tx_frequency_channel[i] = 0;
rx1_frequency_channel[i] = 0;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
- tx_frequency_channel[i] = default_freq_as_923[i] + const_frequency_offset_hz;
- rx1_frequency_channel[i] = default_freq_as_923[i] + const_frequency_offset_hz;
+ tx_frequency_channel[i] = default_freq_as_923[i] + real_const.const_frequency_offset_hz;
+ rx1_frequency_channel[i] = default_freq_as_923[i] + real_const.const_frequency_offset_hz;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
}
- // Enable uplink Dwell Time for AS923
- lr1_mac->uplink_dwell_time = 1;
-
// Enable all unwrapped channels
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_AS923 );
}
-status_lorawan_t region_as_923_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_as_923_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_as_923_get_next_channel( lr1_mac );
+ return region_as_923_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_as_923_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_as_923_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_AS_923];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -227,56 +229,20 @@ status_lorawan_t region_as_923_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
return ERRORLORAWAN;
}
- else
- {
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
- }
- return OKLORAWAN;
-}
-void region_as_923_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- if( lr1_mac->downlink_dwell_time == false )
- {
- lr1_mac->rx_data_rate = datarate_offsets_dwell_time_0_as_923[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else
- {
- lr1_mac->rx_data_rate = datarate_offsets_dwell_time_1_as_923[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_as_923_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_AS923 );
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
+ return OKLORAWAN;
}
-status_channel_t region_as_923_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_as_923_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -285,7 +251,7 @@ status_channel_t region_as_923_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -302,7 +268,7 @@ status_channel_t region_as_923_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
break;
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_AS923 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.h
index b03e89b..3109f45 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923.h
@@ -71,7 +71,7 @@ extern "C" {
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/
-void region_as_923_config( lr1_stack_mac_t* lr1_mac, uint8_t group_id );
+void region_as_923_init( smtc_real_t* real, uint8_t group_id );
/**
* \brief
@@ -79,49 +79,37 @@ void region_as_923_config( lr1_stack_mac_t* lr1_mac, uint8_t group_id );
* \param [IN] none
* \param [OUT] return
*/
-void region_as_923_init( lr1_stack_mac_t* lr1_mac );
+void region_as_923_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_as_923_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_as_923_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_as_923_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_as_923_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_as_923_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_channel_t region_as_923_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_as_923_set_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_channel_t region_as_923_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_as_923_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_as_923_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h
index 2451463..8153758 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_as_923_defs.h
@@ -97,6 +97,7 @@ extern "C" {
#define LBT_THRESHOLD_DBM_AS_923 (int16_t)(-80)
#define LBT_BW_HZ_AS_923 (200000)
#define CF_LIST_SUPPORTED_AS_923 (CF_LIST_FREQ)
+#define UPLINK_DWELL_TIME_AS_923 (true)
// Class B
#define BEACON_FREQ_AS_923 (923400000) // Hz
@@ -144,34 +145,32 @@ static const uint32_t default_freq_as_923[] = { 923200000, 923400000 };
/**
* Up/Down link data rates offset definition when no dwell time limitation
+ * [dwell time][dr][dr_offset]
*/
-static const uint8_t datarate_offsets_dwell_time_0_as_923[8][8] = {
- { 0, 0, 0, 0, 0, 0, 1, 2 }, // DR 0
- { 1, 0, 0, 0, 0, 0, 2, 3 }, // DR 1
- { 2, 1, 0, 0, 0, 0, 3, 4 }, // DR 2
- { 3, 2, 1, 0, 0, 0, 4, 5 }, // DR 3
- { 4, 3, 2, 1, 0, 0, 5, 6 }, // DR 4
- { 5, 4, 3, 2, 1, 0, 6, 7 }, // DR 5
- { 6, 5, 4, 3, 2, 1, 7, 7 }, // DR 6
- { 7, 6, 5, 4, 3, 2, 7, 7 }, // DR 7
-};
+static const uint8_t datarate_offsets_as_923[2][8][8] = { { // dwell time Off
+ { 0, 0, 0, 0, 0, 0, 1, 2 }, // DR 0
+ { 1, 0, 0, 0, 0, 0, 2, 3 }, // DR 1
+ { 2, 1, 0, 0, 0, 0, 3, 4 }, // DR 2
+ { 3, 2, 1, 0, 0, 0, 4, 5 }, // DR 3
+ { 4, 3, 2, 1, 0, 0, 5, 6 }, // DR 4
+ { 5, 4, 3, 2, 1, 0, 6, 7 }, // DR 5
+ { 6, 5, 4, 3, 2, 1, 7, 7 }, // DR 6
+ { 7, 6, 5, 4, 3, 2, 7, 7 } }, // DR 7
-/**
- * Up/Down link data rates offset definition when dwell time limitation
- */
-static const uint8_t datarate_offsets_dwell_time_1_as_923[8][8] = {
- { 2, 2, 2, 2, 2, 2, 2, 2 }, // DR 0
- { 2, 2, 2, 2, 2, 2, 2, 3 }, // DR 1
- { 2, 2, 2, 2, 2, 2, 3, 4 }, // DR 2
- { 3, 2, 2, 2, 2, 2, 4, 5 }, // DR 3
- { 4, 3, 2, 2, 2, 2, 5, 6 }, // DR 4
- { 5, 4, 3, 2, 2, 2, 6, 7 }, // DR 5
- { 6, 5, 4, 3, 2, 2, 7, 7 }, // DR 6
- { 7, 6, 5, 4, 3, 2, 7, 7 }, // DR 7
-};
+ {
+ // dwell time On
+ { 2, 2, 2, 2, 2, 2, 2, 2 }, // DR 0
+ { 2, 2, 2, 2, 2, 2, 2, 3 }, // DR 1
+ { 2, 2, 2, 2, 2, 2, 3, 4 }, // DR 2
+ { 3, 2, 2, 2, 2, 2, 4, 5 }, // DR 3
+ { 4, 3, 2, 2, 2, 2, 5, 6 }, // DR 4
+ { 5, 4, 3, 2, 2, 2, 6, 7 }, // DR 5
+ { 6, 5, 4, 3, 2, 2, 7, 7 }, // DR 6
+ { 7, 6, 5, 4, 3, 2, 7, 7 }, // DR 7}
+ } };
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_as_923[2][8] = { {
@@ -197,8 +196,10 @@ static const uint8_t datarate_backoff_as_923[2][8] = { {
6 // DR7 -> DR6
} };
-static const uint8_t NUMBER_RX1_DR_OFFSET_AS_923 =
- sizeof( datarate_offsets_dwell_time_1_as_923[0] ) / sizeof( datarate_offsets_dwell_time_1_as_923[0][0] );
+static const uint8_t NUMBER_RX1_DR_OFFSET_AS_923 = sizeof( datarate_offsets_as_923[0] ) /
+ sizeof( datarate_offsets_as_923[0][0] ) /
+ sizeof( datarate_offsets_as_923[0][0][0] );
+
/**
* Data rates table definition
*/
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c
index f5ed945..69a99d2 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.c
@@ -49,17 +49,18 @@
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define dr_bitfield_tx_channel lr1_mac->real->region.au915.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.au915.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.au915.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.au915.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.au915.unwrapped_channel_mask
-#define first_ch_mask_received lr1_mac->real->region.au915.first_ch_mask_received
+#define dr_bitfield_tx_channel real->region.au915.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.au915.channel_index_enabled
+#define dr_distribution_init real->region.au915.dr_distribution_init
+#define dr_distribution real->region.au915.dr_distribution
+#define unwrapped_channel_mask real->region.au915.unwrapped_channel_mask
+#define first_ch_mask_received real->region.au915.first_ch_mask_received
-#define snapshot_channel_tx_mask lr1_mac->real->region.au915.snapshot_channel_tx_mask
-#define snapshot_bank_tx_mask lr1_mac->real->region.au915.snapshot_bank_tx_mask
+#define snapshot_channel_tx_mask real->region.au915.snapshot_channel_tx_mask
+#define snapshot_bank_tx_mask real->region.au915.snapshot_bank_tx_mask
/*
* -----------------------------------------------------------------------------
@@ -91,56 +92,58 @@ typedef enum ch_mask_after_join_e
/**
* @brief init Channel mask after the join accept
*
- * @param lr1_mac
+ * @param real
*/
-static void region_au_915_channel_mask_set_after_join( lr1_stack_mac_t* lr1_mac );
+static void region_au_915_channel_mask_set_after_join( smtc_real_t* real );
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_au_915_config( lr1_stack_mac_t* lr1_mac )
+void region_au_915_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_AU_915;
- const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_AU_915;
- const_number_of_channel_bank = BANK_MAX_AU915;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_AU_915;
- const_received_delay1 = RECEIVE_DELAY1_AU_915;
- const_tx_power_dbm = TX_POWER_EIRP_AU_915 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_AU_915;
- const_adr_ack_limit = ADR_ACK_LIMIT_AU_915;
- const_adr_ack_delay = ADR_ACK_DELAY_AU_915;
- const_datarate_backoff = &datarate_backoff_au_915[0][0];
- const_ack_timeout = ACK_TIMEOUT_AU_915;
- const_freq_min = FREQMIN_AU_915;
- const_freq_max = FREQMAX_AU_915;
- const_rx2_freq = RX2_FREQ_AU_915;
- const_frequency_factor = FREQUENCY_FACTOR_AU_915;
- const_rx2_dr_init = RX2DR_INIT_AU_915;
- const_sync_word_private = SYNC_WORD_PRIVATE_AU_915;
- const_sync_word_public = SYNC_WORD_PUBLIC_AU_915;
- const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_AU_915;
- const_min_tx_dr = MIN_TX_DR_AU_915;
- const_max_tx_dr = MAX_TX_DR_AU_915;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_AU_915;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_AU_915;
- const_min_rx_dr = MIN_RX_DR_AU_915;
- const_max_rx_dr = MAX_RX_DR_AU_915;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_AU_915;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_AU_915;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_AU_915;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_AU_923;
- const_dtc_supported = DTC_SUPPORTED_AU_915;
- const_lbt_supported = LBT_SUPPORTED_AU_915;
- const_max_payload_m = &M_au_915[0][0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AU_915[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AU_915[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_AU_915[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_AU_915[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_AU_915;
- const_beacon_dr = BEACON_DR_AU_915;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_AU_915;
+ real_const.const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_AU_915;
+ real_const.const_number_of_channel_bank = BANK_MAX_AU915;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_AU_915;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_AU_915;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_AU_915 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_AU_915;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_AU_915;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_AU_915;
+ real_const.const_datarate_offsets = &datarate_offsets_au_915[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_au_915[0][0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_AU_915;
+ real_const.const_freq_min = FREQMIN_AU_915;
+ real_const.const_freq_max = FREQMAX_AU_915;
+ real_const.const_rx2_freq = RX2_FREQ_AU_915;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_AU_915;
+ real_const.const_rx2_dr_init = RX2DR_INIT_AU_915;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_AU_915;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_AU_915;
+ real_const.const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_AU_915;
+ real_const.const_min_tx_dr = MIN_TX_DR_AU_915;
+ real_const.const_max_tx_dr = MAX_TX_DR_AU_915;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_AU_915;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_AU_915;
+ real_const.const_min_rx_dr = MIN_RX_DR_AU_915;
+ real_const.const_max_rx_dr = MAX_RX_DR_AU_915;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_AU_915;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_AU_915;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_AU_915;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_AU_923;
+ real_const.const_dtc_supported = DTC_SUPPORTED_AU_915;
+ real_const.const_lbt_supported = LBT_SUPPORTED_AU_915;
+ real_const.const_max_payload_m = &M_au_915[0][0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_AU_915[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_AU_915[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_AU_915[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_AU_915[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_AU_915;
+ real_const.const_beacon_dr = BEACON_DR_AU_915;
+ real_const.const_uplink_dwell_time = UPLINK_DWELL_TIME_AU_915;
real_ctx.tx_frequency_channel_ctx = NULL;
real_ctx.rx1_frequency_channel_ctx = NULL;
@@ -150,8 +153,8 @@ void region_au_915_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 0, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 0, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
// Enable all channels
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_AU915 );
@@ -160,7 +163,7 @@ void region_au_915_config( lr1_stack_mac_t* lr1_mac )
snapshot_bank_tx_mask = 0;
}
-void region_au_915_init( lr1_stack_mac_t* lr1_mac )
+void region_au_915_config( smtc_real_t* real )
{
// Tx 125 kHz channels
for( uint8_t i = 0; i < NUMBER_OF_TX_CHANNEL_AU_915 - 8; i++ )
@@ -171,7 +174,7 @@ void region_au_915_init( lr1_stack_mac_t* lr1_mac )
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_125_BIT_FIELD_AU_915;
SMTC_MODEM_HAL_TRACE_PRINTF( "TX - idx:%u, freq: %d, dr: 0x%x,\n%s", i,
- region_au_915_get_tx_frequency_channel( lr1_mac, i ), dr_bitfield_tx_channel[i],
+ region_au_915_get_tx_frequency_channel( real, i ), dr_bitfield_tx_channel[i],
( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
// Tx 500 kHz channels
@@ -182,7 +185,7 @@ void region_au_915_init( lr1_stack_mac_t* lr1_mac )
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_500_BIT_FIELD_AU_915;
SMTC_MODEM_HAL_TRACE_PRINTF( "TX - idx:%u, freq: %d, dr: 0x%x,\n%s", i,
- region_au_915_get_tx_frequency_channel( lr1_mac, i ), dr_bitfield_tx_channel[i],
+ region_au_915_get_tx_frequency_channel( real, i ), dr_bitfield_tx_channel[i],
( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
@@ -190,19 +193,19 @@ void region_au_915_init( lr1_stack_mac_t* lr1_mac )
for( uint8_t i = 0; i < NUMBER_OF_RX_CHANNEL_AU_915; i++ )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "RX - idx:%u, freq: %d, dr_min: %u, dr_max: %u\n%s", i,
- region_au_915_get_rx1_frequency_channel( lr1_mac, i ), MIN_RX_DR_AU_915,
+ region_au_915_get_rx1_frequency_channel( real, i ), MIN_RX_DR_AU_915,
MAX_RX_DR_AU_915, ( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#endif
first_ch_mask_received = ch_mask_after_join_init;
- // Enable uplink Dwell Time for AU915
- lr1_mac->uplink_dwell_time = 1;
+ // // Enable uplink Dwell Time for AU915
+ // lr1_mac->uplink_dwell_time = 1;
}
-status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, uint8_t dr,
- bool is_ch_mask_from_link_adr )
+status_lorawan_t region_au_915_is_acceptable_tx_dr( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr,
+ bool uplink_dwell_time )
{
status_lorawan_t status = ERRORLORAWAN;
uint8_t number_channels_125_enabled = 0;
@@ -210,7 +213,7 @@ status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
uint8_t* ch_mask_to_check = ( is_ch_mask_from_link_adr == true ) ? unwrapped_channel_mask : channel_index_enabled;
// 125 kHz channels
- for( uint8_t i = 0; i < const_number_of_tx_channel - 8; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel - 8; i++ )
{
if( SMTC_GET_BIT8( ch_mask_to_check, i ) == CHANNEL_ENABLED )
{
@@ -222,7 +225,7 @@ status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
}
}
// 500 kHz channels
- for( uint8_t i = const_number_of_tx_channel - 8; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = real_const.const_number_of_tx_channel - 8; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( ch_mask_to_check, i ) == CHANNEL_ENABLED )
{
@@ -243,9 +246,9 @@ status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
}
}
- if( lr1_mac->uplink_dwell_time == true )
+ if( uplink_dwell_time == true )
{
- if( dr < const_min_tx_dr_limit )
+ if( dr < real_const.const_min_tx_dr_limit )
{
status = ERRORLORAWAN;
}
@@ -258,7 +261,8 @@ status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
return ( status );
}
-status_lorawan_t region_au_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_au_915_get_join_next_channel( smtc_real_t* real, uint8_t* out_tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
au_915_channels_bank_t bank_tmp_cnt = 0;
uint8_t active_channel_nb;
@@ -279,23 +283,11 @@ status_lorawan_t region_au_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
active_channel_nb = 0;
for( uint8_t i = snapshot_bank_tx_mask * 8; i < ( ( snapshot_bank_tx_mask * 8 ) + 8 ); i++ )
{
- if( snapshot_bank_tx_mask == BANK_8_500_AU915 )
+ if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
+ ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
{
- if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
- {
- active_channel_index[active_channel_nb] = i;
- active_channel_nb++;
- }
- }
- else
- {
- if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
- {
- active_channel_index[active_channel_nb] = i;
- active_channel_nb++;
- }
+ active_channel_index[active_channel_nb] = i;
+ active_channel_nb++;
}
}
snapshot_bank_tx_mask++;
@@ -333,15 +325,15 @@ status_lorawan_t region_au_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
if( snapshot_bank_tx_mask > BANK_8_500_AU915 )
{
- lr1_mac->tx_data_rate = DR6;
+ *out_tx_data_rate = DR6;
}
else
{
- lr1_mac->tx_data_rate = DR2;
+ *out_tx_data_rate = DR2;
}
- lr1_mac->tx_frequency = region_au_915_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_au_915_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_au_915_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_au_915_get_rx1_frequency_channel( real, channel_idx );
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
SMTC_MODEM_HAL_TRACE_PRINTF( "snapshot channel 125 tx mask\n" );
@@ -362,7 +354,8 @@ status_lorawan_t region_au_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
return OKLORAWAN;
}
-status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_au_915_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
// if all channels were used, reset the snapshots
if( ( SMTC_ARE_CLR_BYTE8( snapshot_channel_tx_mask, BANK_8_500_AU915 ) == true ) &&
@@ -383,15 +376,15 @@ status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
( snapshot_channel_tx_mask[BANK_8_500_AU915] == 0 ) ) &&
( first_ch_mask_received == ch_mask_after_join_56ch ) )
{
- memset1( unwrapped_channel_mask, 0xFF, const_number_of_channel_bank );
- region_au_915_set_channel_mask( lr1_mac );
+ memset1( unwrapped_channel_mask, 0xFF, real_const.const_number_of_channel_bank );
+ region_au_915_set_channel_mask( real );
}
if( ( ( SMTC_ARE_CLR_BYTE8( snapshot_channel_tx_mask, BANK_8_500_AU915 ) == true ) ||
( snapshot_channel_tx_mask[BANK_8_500_AU915] == 0 ) ) &&
( first_ch_mask_received <= ch_mask_after_join_8ch ) )
{
- region_au_915_init_after_join_snapshot_channel_mask( lr1_mac );
+ region_au_915_init_after_join_snapshot_channel_mask( real, tx_data_rate, *out_tx_frequency );
}
uint8_t active_channel_nb = 0;
@@ -400,7 +393,7 @@ status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
{
if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 ) )
+ ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 ) )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -423,8 +416,8 @@ status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
// Mask the channel used, to be remove for the next selection
SMTC_PUT_BIT8( snapshot_channel_tx_mask, channel_idx, CHANNEL_DISABLED );
- lr1_mac->tx_frequency = region_au_915_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_au_915_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_au_915_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_au_915_get_rx1_frequency_channel( real, channel_idx );
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
SMTC_MODEM_HAL_TRACE_PRINTF( "snapshot channel 125 tx mask\n" );
@@ -444,35 +437,21 @@ status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
return OKLORAWAN;
}
-void region_au_915_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_au_915[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_au_915_set_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_au_915_set_channel_mask( smtc_real_t* real )
{
- region_au_915_channel_mask_set_after_join( lr1_mac );
+ region_au_915_channel_mask_set_after_join( real );
first_ch_mask_received = ch_mask_after_join_full;
}
-void region_au_915_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_au_915_init_join_snapshot_channel_mask( smtc_real_t* real )
{
memset1( snapshot_channel_tx_mask, 0xFF, BANK_MAX_AU915 );
snapshot_bank_tx_mask = 0;
}
-void region_au_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_au_915_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t tx_frequency )
{
au_915_channels_bank_t ch_mask_block = 0;
@@ -483,7 +462,7 @@ void region_au_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
uint8_t tx_sf;
lr1mac_bandwidth_t tx_bw;
- region_au_915_lora_dr_to_sf_bw( lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
+ region_au_915_lora_dr_to_sf_bw( tx_data_rate, &tx_sf, &tx_bw );
/**
* Important remark:
@@ -500,13 +479,13 @@ void region_au_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
{
// Search the corresponding block of channels used by the last Tx frequency
ch_mask_block = ( au_915_channels_bank_t )(
- ( lr1_mac->tx_frequency - DEFAULT_TX_FREQ_125_START_AU_915 ) /
+ ( tx_frequency - DEFAULT_TX_FREQ_125_START_AU_915 ) /
( ( DEFAULT_TX_STEP_125_AU_915 << 3 ) ) ); // 1600000 = 8 ch * 200000 MHz, the gap in each block
}
else if( tx_bw == BW500 )
{
ch_mask_block = ( au_915_channels_bank_t )(
- ( ( lr1_mac->tx_frequency - DEFAULT_TX_FREQ_500_START_AU_915 ) / DEFAULT_TX_STEP_500_AU_915 ) % 8 );
+ ( ( tx_frequency - DEFAULT_TX_FREQ_500_START_AU_915 ) / DEFAULT_TX_STEP_500_AU_915 ) % 8 );
}
else
{
@@ -545,11 +524,10 @@ void region_au_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
}
// Apply computed channel mask after join
- region_au_915_channel_mask_set_after_join( lr1_mac );
+ region_au_915_channel_mask_set_after_join( real );
}
-status_channel_t region_au_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_au_915_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
SMTC_MODEM_HAL_TRACE_PRINTF( "ChCtrl = 0x%u, ChMask = 0x%04x\n", channel_mask_cntl, channel_mask );
@@ -574,10 +552,12 @@ status_channel_t region_au_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
if( ( ( channel_mask >> i ) & 0x01 ) == CHANNEL_ENABLED )
{
unwrapped_channel_mask[i] = 0xFF;
+ SMTC_PUT_BIT8( &unwrapped_channel_mask[BANK_8_500_AU915], i, CHANNEL_ENABLED );
}
else
{
unwrapped_channel_mask[i] = 0x00;
+ SMTC_PUT_BIT8( &unwrapped_channel_mask[BANK_8_500_AU915], i, CHANNEL_DISABLED );
}
}
@@ -604,10 +584,10 @@ status_channel_t region_au_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
}
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) &&
- ( region_au_915_get_tx_frequency_channel( lr1_mac, i ) == 0 ) )
+ ( region_au_915_get_tx_frequency_channel( real, i ) == 0 ) )
{
status = ERROR_CHANNEL_MASK; // this status is used only for the last multiple link adr req
break; // break for loop
@@ -633,7 +613,7 @@ status_channel_t region_au_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
return ( status );
}
-void region_au_915_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void region_au_915_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
// Tx 125 kHz channels
for( uint8_t i = 0; i < NUMBER_OF_TX_CHANNEL_AU_915 - 8; i++ )
@@ -692,11 +672,11 @@ void region_au_915_lr_fhss_dr_to_cr_bw( uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
}
}
-uint32_t region_au_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_au_915_get_tx_frequency_channel( smtc_real_t* real, uint8_t index )
{
uint32_t freq = 0;
// 500KHz channels
- if( index >= const_number_of_tx_channel - 8 )
+ if( index >= real_const.const_number_of_tx_channel - 8 )
{
freq = DEFAULT_TX_FREQ_500_START_AU_915 + ( ( index % 8 ) * DEFAULT_TX_STEP_500_AU_915 );
}
@@ -708,19 +688,18 @@ uint32_t region_au_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8
return freq;
}
-uint32_t region_au_915_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_au_915_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index )
{
return ( DEFAULT_RX_FREQ_500_START_AU_915 + ( ( index % 8 ) * DEFAULT_RX_STEP_500_AU_915 ) );
}
-uint32_t region_au_915_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s )
+uint32_t region_au_915_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s )
{
uint8_t index = ( uint32_t )( floorf( gps_time_s / 128 ) ) % 8;
return ( BEACON_FREQ_START_AU_915 + ( index * BEACON_STEP_AU_915 ) );
}
-uint32_t region_au_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr )
+uint32_t region_au_915_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr )
{
uint8_t index = ( dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) ) % 8;
return ( PING_SLOT_FREQ_START_AU_915 + ( index * PING_SLOT_STEP_AU_915 ) );
@@ -730,7 +709,7 @@ uint32_t region_au_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
*/
-static void region_au_915_channel_mask_set_after_join( lr1_stack_mac_t* lr1_mac )
+static void region_au_915_channel_mask_set_after_join( smtc_real_t* real )
{
// Copy all unwrapped channels in channel enable and in snapshot
memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_AU915 );
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.h
index 88bab6b..dfa6098 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915.h
@@ -76,78 +76,74 @@ extern "C" {
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_config( lr1_stack_mac_t* lr1_mac );
+void region_au_915_init( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_init( lr1_stack_mac_t* lr1_mac );
+void region_au_915_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_au_915_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_au_915_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_au_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_au_915_get_join_next_channel( smtc_real_t* real, uint8_t* out_tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+void region_au_915_set_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_au_915_init_join_snapshot_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_au_915_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t tx_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+status_channel_t region_au_915_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_channel_t region_au_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+void region_au_915_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_au_915_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_lorawan_t region_au_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, uint8_t dr,
- bool is_ch_mask_from_link_adr );
+status_lorawan_t region_au_915_is_acceptable_tx_dr( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr,
+ bool uplink_dwell_time );
/**
* @brief Get the corresponding RF modulation from a Datarate
@@ -181,34 +177,33 @@ void region_au_915_lr_fhss_dr_to_cr_bw( uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_au_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_au_915_get_tx_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_au_915_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_au_915_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* @brief Get the beacon frequency corresponding to a gps_time
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @return uint32_t
*/
-uint32_t region_au_915_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s );
+uint32_t region_au_915_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s );
/**
* @brief Get the ping slot frequency corresponding to a gps_time and Dev Address
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @param dev_addr
* @return uint32_t
*/
-uint32_t region_au_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr );
+uint32_t region_au_915_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr );
#ifdef __cplusplus
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h
index 5f458bc..4fed3be 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_au_915_defs.h
@@ -108,6 +108,8 @@ extern "C" {
#define DTC_SUPPORTED_AU_915 (false)
#define LBT_SUPPORTED_AU_915 (false)
+#define UPLINK_DWELL_TIME_AU_915 (true)
+
#define CF_LIST_SUPPORTED_AU_915 (CF_LIST_CH_MASK)
#define DEFAULT_TX_FREQ_125_START_AU_915 (915200000) // Hz
@@ -184,7 +186,7 @@ static const uint8_t datarate_offsets_au_915[8][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_au_915[2][8] = { {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c
index 7b571e1..f2c6ff8 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.c
@@ -47,15 +47,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define dr_bitfield_tx_channel lr1_mac->real->region.cn470.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.cn470.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.cn470.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.cn470.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.cn470.unwrapped_channel_mask
-#define activated_by_join_channel lr1_mac->real->region.cn470.activated_by_join_channel
-#define activated_channel_plan lr1_mac->real->region.cn470.activated_channel_plan
+#define dr_bitfield_tx_channel real->region.cn470.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.cn470.channel_index_enabled
+#define dr_distribution_init real->region.cn470.dr_distribution_init
+#define dr_distribution real->region.cn470.dr_distribution
+#define unwrapped_channel_mask real->region.cn470.unwrapped_channel_mask
+#define activated_by_join_channel real->region.cn470.activated_by_join_channel
+#define activated_channel_plan real->region.cn470.activated_channel_plan
/*
* -----------------------------------------------------------------------------
@@ -94,50 +95,51 @@ static const char* smtc_real_channel_plan_cn470_str[] = {
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_cn_470_config( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_CN_470;
- const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_CN_470;
- const_number_of_channel_bank = BANK_MAX_CN470;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_CN_470;
- const_received_delay1 = RECEIVE_DELAY1_CN_470;
- const_tx_power_dbm = TX_POWER_EIRP_CN_470 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_CN_470;
- const_adr_ack_limit = ADR_ACK_LIMIT_CN_470;
- const_adr_ack_delay = ADR_ACK_DELAY_CN_470;
- const_datarate_backoff = &datarate_backoff_cn_470[0];
- const_ack_timeout = ACK_TIMEOUT_CN_470;
- const_freq_min = FREQMIN_CN_470;
- const_freq_max = FREQMAX_CN_470;
- const_frequency_factor = FREQUENCY_FACTOR_CN_470;
- const_rx2_dr_init = RX2DR_INIT_CN_470;
- const_sync_word_private = SYNC_WORD_PRIVATE_CN_470;
- const_sync_word_public = SYNC_WORD_PUBLIC_CN_470;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_CN_470;
- const_min_tx_dr = MIN_TX_DR_CN_470;
- const_max_tx_dr = MAX_TX_DR_CN_470;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_CN_470;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_CN_470;
- const_min_rx_dr = MIN_RX_DR_CN_470;
- const_max_rx_dr = MAX_RX_DR_CN_470;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_CN_470;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_CN_470;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_CN_470;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_CN_470;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_CN_470;
- const_dtc_supported = DTC_SUPPORTED_CN_470;
- const_lbt_supported = LBT_SUPPORTED_CN_470;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_CN_470;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470;
- const_lbt_bw_hz = LBT_BW_HZ_CN_470;
- const_max_payload_m = &M_cn_470[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_CN_470[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_CN_470[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_CN_470;
- const_beacon_dr = BEACON_DR_CN_470;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_CN_470;
+ real_const.const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_CN_470;
+ real_const.const_number_of_channel_bank = BANK_MAX_CN470;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_CN_470;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_CN_470;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_CN_470 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_CN_470;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_CN_470;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_CN_470;
+ real_const.const_datarate_offsets = &datarate_offsets_cn_470[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_cn_470[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_CN_470;
+ real_const.const_freq_min = FREQMIN_CN_470;
+ real_const.const_freq_max = FREQMAX_CN_470;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_CN_470;
+ real_const.const_rx2_dr_init = RX2DR_INIT_CN_470;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_CN_470;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_CN_470;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_CN_470;
+ real_const.const_min_tx_dr = MIN_TX_DR_CN_470;
+ real_const.const_max_tx_dr = MAX_TX_DR_CN_470;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_CN_470;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_CN_470;
+ real_const.const_min_rx_dr = MIN_RX_DR_CN_470;
+ real_const.const_max_rx_dr = MAX_RX_DR_CN_470;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_CN_470;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_CN_470;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_CN_470;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_CN_470;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_CN_470;
+ real_const.const_dtc_supported = DTC_SUPPORTED_CN_470;
+ real_const.const_lbt_supported = LBT_SUPPORTED_CN_470;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_CN_470;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_CN_470;
+ real_const.const_max_payload_m = &M_cn_470[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_CN_470[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_CN_470[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_CN_470;
+ real_const.const_beacon_dr = BEACON_DR_CN_470;
real_ctx.tx_frequency_channel_ctx = NULL;
real_ctx.rx1_frequency_channel_ctx = NULL;
@@ -147,19 +149,19 @@ void region_cn_470_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 0, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 0, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
// Enable all unwrapped channels
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_CN470 );
}
-void region_cn_470_init( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_config( smtc_real_t* real )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
uint8_t err = true;
#endif
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
dr_bitfield_tx_channel[i] = 0;
@@ -174,12 +176,12 @@ void region_cn_470_init( lr1_stack_mac_t* lr1_mac )
err = false;
#endif
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
SMTC_MODEM_HAL_TRACE_PRINTF(
"join: idx:%u, TxFreq: %d, Rx1freq: %d, MaskDrRx1: 0x%x, freqRx2: %d, DrRx2: 0x%x\n%s", i,
common_join_channel_cn_470[i][0], common_join_channel_cn_470[i][1], dr_bitfield_tx_channel[i],
- common_join_channel_cn_470[i][2], const_rx2_dr_init, ( ( i % 8 ) == 7 ) ? "---\n" : "" );
+ common_join_channel_cn_470[i][2], real_const.const_rx2_dr_init, ( ( i % 8 ) == 7 ) ? "---\n" : "" );
#if defined( HYBRID_CN470_MONO_CHANNEL )
}
#endif
@@ -192,7 +194,7 @@ void region_cn_470_init( lr1_stack_mac_t* lr1_mac )
#endif
}
-void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_config_session( smtc_real_t* real )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "Plan %s\n", smtc_real_channel_plan_cn470_str[activated_channel_plan] );
@@ -203,28 +205,28 @@ void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac )
{
case CN_470_20MHZ_A:
case CN_470_20MHZ_B:
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_20MHZ_CN_470;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_20MHZ_CN_470;
#if defined( HYBRID_CN470_MONO_CHANNEL )
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
dr_bitfield_tx_channel[i] = 0;
}
#endif
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
- if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( lr1_mac, i ) )
+ if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( real, i ) )
{
err = false;
#endif
SMTC_MODEM_HAL_TRACE_PRINTF( "idx:%u, TxFreq: %d, RxFreq: %d, dr: 0x%x,\n%s", i,
- region_cn_470_get_tx_frequency_channel( lr1_mac, i ),
- region_cn_470_get_rx1_frequency_channel( lr1_mac, i ),
+ region_cn_470_get_tx_frequency_channel( real, i ),
+ region_cn_470_get_rx1_frequency_channel( real, i ),
dr_bitfield_tx_channel[i], ( ( i % 8 ) == 7 ) ? "---\n" : "" );
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
#if defined( HYBRID_CN470_MONO_CHANNEL )
}
#endif
@@ -232,27 +234,27 @@ void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac )
break;
case CN_470_26MHZ_A:
case CN_470_26MHZ_B:
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_26MHZ_CN_470;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_26MHZ_CN_470;
#if defined( HYBRID_CN470_MONO_CHANNEL )
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
dr_bitfield_tx_channel[i] = 0;
}
#endif
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
- if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( lr1_mac, i ) )
+ if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( real, i ) )
{
err = false;
#endif
SMTC_MODEM_HAL_TRACE_PRINTF( "idx:%u, TxFreq: %d, dr: 0x%x,\n%s", i,
- region_cn_470_get_tx_frequency_channel( lr1_mac, i ),
+ region_cn_470_get_tx_frequency_channel( real, i ),
dr_bitfield_tx_channel[i], ( ( i % 8 ) == 7 ) ? "---\n" : "" );
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
#if defined( HYBRID_CN470_MONO_CHANNEL )
}
#endif
@@ -262,11 +264,11 @@ void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac )
for( uint8_t i = 0; i < NUMBER_OF_RX_CHANNEL_26MHZ_CN_470; i++ )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
- if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( lr1_mac, i ) )
+ if( freq_tx_cn470_mono_channel_mhz == region_cn_470_get_tx_frequency_channel( real, i ) )
{
#endif
SMTC_MODEM_HAL_TRACE_PRINTF( "idx:%u, RxFreq: %d, dr: 0x%x,\n%s", i,
- region_cn_470_get_rx1_frequency_channel( lr1_mac, i ),
+ region_cn_470_get_rx1_frequency_channel( real, i ),
dr_bitfield_tx_channel[i], ( ( i % 8 ) == 7 ) ? "---\n" : "" );
#if defined( HYBRID_CN470_MONO_CHANNEL )
}
@@ -287,18 +289,20 @@ void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac )
#endif
}
-status_lorawan_t region_cn_470_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_cn_470_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency,
+ uint32_t* out_rx2_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_TX_CHANNEL_CN_470];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
// Channel must be enabled and frequency not 0
if( ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) &&
( common_join_channel_cn_470[i][0] != 0 ) )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -314,7 +318,7 @@ status_lorawan_t region_cn_470_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -322,26 +326,27 @@ status_lorawan_t region_cn_470_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
}
else
{
- lr1_mac->tx_frequency = common_join_channel_cn_470[channel_idx][0]; // [i][0] Tx
- lr1_mac->rx1_frequency = common_join_channel_cn_470[channel_idx][1]; // [i][1] Rx1
- lr1_mac->rx2_frequency = common_join_channel_cn_470[channel_idx][2]; // [i][2] Rx2
+ *out_tx_frequency = common_join_channel_cn_470[channel_idx][0]; // [i][0] Tx
+ *out_rx1_frequency = common_join_channel_cn_470[channel_idx][1]; // [i][1] Rx1
+ *out_rx2_frequency = common_join_channel_cn_470[channel_idx][2]; // [i][2] Rx2
activated_by_join_channel = channel_idx;
- activated_channel_plan = region_cn_470_get_corresponding_plan( lr1_mac, channel_idx );
+ activated_channel_plan = region_cn_470_get_corresponding_plan( real, channel_idx );
}
return OKLORAWAN;
}
-status_lorawan_t region_cn_470_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_cn_470_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_TX_CHANNEL_CN_470];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -357,7 +362,7 @@ status_lorawan_t region_cn_470_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -365,13 +370,13 @@ status_lorawan_t region_cn_470_get_next_channel( lr1_stack_mac_t* lr1_mac )
}
else
{
- lr1_mac->tx_frequency = region_cn_470_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_cn_470_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_cn_470_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_cn_470_get_rx1_frequency_channel( real, channel_idx );
}
return OKLORAWAN;
}
-uint8_t region_cn_470_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
+uint8_t region_cn_470_get_number_of_chmask_in_cflist( smtc_real_t* real )
{
if( ( activated_channel_plan == CN_470_20MHZ_A ) || ( activated_channel_plan == CN_470_20MHZ_B ) )
{
@@ -383,37 +388,7 @@ uint8_t region_cn_470_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
}
}
-void region_cn_470_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_cn_470[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-
-void region_cn_470_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_CN470 );
-
- SMTC_MODEM_HAL_TRACE_MSG( "Ch Mask\n" );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-status_channel_t region_cn_470_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_cn_470_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
SMTC_MODEM_HAL_TRACE_PRINTF( "ChCtrl = 0x%u, ChMask = 0x%04x\n", channel_mask_cntl, channel_mask );
@@ -425,10 +400,10 @@ status_channel_t region_cn_470_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) &&
- ( region_cn_470_get_tx_frequency_channel( lr1_mac, i ) == 0 ) )
+ ( region_cn_470_get_tx_frequency_channel( real, i ) == 0 ) )
{
status = ERROR_CHANNEL_MASK; // this status is used only for the last multiple link adr req
break; // break for loop
@@ -442,10 +417,10 @@ status_channel_t region_cn_470_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) &&
- ( region_cn_470_get_tx_frequency_channel( lr1_mac, i ) == 0 ) )
+ ( region_cn_470_get_tx_frequency_channel( real, i ) == 0 ) )
{
status = ERROR_CHANNEL_MASK; // this status is used only for the last multiple link adr req
break; // break for loop
@@ -519,12 +494,12 @@ status_channel_t region_cn_470_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
return ( status );
}
-void region_cn_470_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
- region_cn_470_init_session( lr1_mac );
+ region_cn_470_config_session( real );
#else
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_BIT_FIELD_CN_470;
@@ -574,7 +549,7 @@ void region_cn_470_fsk_dr_to_bitrate( uint8_t in_dr, uint8_t* out_bitrate )
}
}
-uint32_t region_cn_470_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_cn_470_get_tx_frequency_channel( smtc_real_t* real, uint8_t index )
{
uint32_t freq = 0;
switch( activated_channel_plan )
@@ -616,7 +591,7 @@ uint32_t region_cn_470_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8
return freq;
}
-uint32_t region_cn_470_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_cn_470_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index )
{
uint32_t freq = 0;
switch( activated_channel_plan )
@@ -656,8 +631,7 @@ uint32_t region_cn_470_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint
return freq;
}
-channel_plan_type_cn470_t region_cn_470_get_corresponding_plan( lr1_stack_mac_t* lr1_mac,
- uint8_t common_join_channel_index )
+channel_plan_type_cn470_t region_cn_470_get_corresponding_plan( smtc_real_t* real, uint8_t common_join_channel_index )
{
channel_plan_type_cn470_t plan = CN_470_20MHZ_A;
@@ -684,7 +658,7 @@ channel_plan_type_cn470_t region_cn_470_get_corresponding_plan( lr1_stack_mac_t*
return plan;
}
-uint32_t region_cn_470_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s )
+uint32_t region_cn_470_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s )
{
uint8_t index = 0;
uint32_t freq = 0;
@@ -692,7 +666,7 @@ uint32_t region_cn_470_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac
{
case CN_470_20MHZ_A:
index = ( activated_by_join_channel * 8 ) + ( uint32_t )( floorf( gps_time_s / 128 ) ) % 8;
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
+ freq = region_cn_470_get_rx1_frequency_channel( real, index );
break;
case CN_470_20MHZ_B:
if( activated_by_join_channel == 8 )
@@ -707,7 +681,7 @@ uint32_t region_cn_470_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac
{
smtc_modem_hal_lr1mac_panic( "invalid join channel" );
}
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
+ freq = region_cn_470_get_rx1_frequency_channel( real, index );
break;
case CN_470_26MHZ_A:
freq = 494900000;
@@ -722,8 +696,7 @@ uint32_t region_cn_470_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac
return freq;
}
-uint32_t region_cn_470_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr )
+uint32_t region_cn_470_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr )
{
uint8_t index = 0;
uint32_t freq = 0;
@@ -731,24 +704,22 @@ uint32_t region_cn_470_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_
{
case CN_470_20MHZ_A:
index = ( activated_by_join_channel * 8 ) + dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) % 8;
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
+ freq = region_cn_470_get_rx1_frequency_channel( real, index );
break;
case CN_470_20MHZ_B:
if( activated_by_join_channel == 8 )
{
index = ( dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) ) % 32;
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
}
else if( activated_by_join_channel == 9 )
{
index = 32 + ( dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) ) % 32;
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
}
else
{
smtc_modem_hal_lr1mac_panic( "invalid join channel" );
}
- freq = region_cn_470_get_rx1_frequency_channel( lr1_mac, index );
+ freq = region_cn_470_get_rx1_frequency_channel( real, index );
break;
case CN_470_26MHZ_A:
freq = 494900000;
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.h
index dbee276..c7c2bb3 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470.h
@@ -77,70 +77,59 @@ extern "C" {
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_config( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_init( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_init( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_init_session( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_config_session( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint8_t region_cn_470_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac );
+uint8_t region_cn_470_get_number_of_chmask_in_cflist( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_cn_470_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_cn_470_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_cn_470_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_cn_470_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency,
+ uint32_t* out_rx2_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_channel_t region_cn_470_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_set_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_channel_t region_cn_470_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_cn_470_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
@@ -173,44 +162,42 @@ void region_cn_470_fsk_dr_to_bitrate( uint8_t in_dr, uint8_t* out_bitrate );
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_cn_470_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_cn_470_get_tx_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_cn_470_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_cn_470_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @param common_join_channel_index
* @return channel_plan_type_cn470_t
*/
-channel_plan_type_cn470_t region_cn_470_get_corresponding_plan( lr1_stack_mac_t* lr1_mac,
- uint8_t common_join_channel_index );
+channel_plan_type_cn470_t region_cn_470_get_corresponding_plan( smtc_real_t* real, uint8_t common_join_channel_index );
/**
* @brief Get the beacon frequency
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @return uint32_t
*/
-uint32_t region_cn_470_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s );
+uint32_t region_cn_470_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s );
/**
* @brief Get the ping slot frequency
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @param dev_addr
* @return uint32_t
*/
-uint32_t region_cn_470_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr );
+uint32_t region_cn_470_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr );
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h
index 061bae5..26e3a13 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_defs.h
@@ -230,7 +230,7 @@ static const uint8_t datarate_offsets_cn_470[8][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_cn_470[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c
index 5b22903..2fe3853 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.c
@@ -47,15 +47,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define dr_bitfield_tx_channel lr1_mac->real->region.cn470_rp_1_0.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.cn470_rp_1_0.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.cn470_rp_1_0.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.cn470_rp_1_0.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.cn470_rp_1_0.unwrapped_channel_mask
+#define dr_bitfield_tx_channel real->region.cn470_rp_1_0.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.cn470_rp_1_0.channel_index_enabled
+#define dr_distribution_init real->region.cn470_rp_1_0.dr_distribution_init
+#define dr_distribution real->region.cn470_rp_1_0.dr_distribution
+#define unwrapped_channel_mask real->region.cn470_rp_1_0.unwrapped_channel_mask
-#define snapshot_bank_tx_mask lr1_mac->real->region.cn470_rp_1_0.snapshot_bank_tx_mask
+#define snapshot_bank_tx_mask real->region.cn470_rp_1_0.snapshot_bank_tx_mask
// Private region_cn_470_rp_1_0 utilities declaration
//
@@ -86,51 +87,52 @@ uint32_t freq_tx_cn470_mono_channel_mhz = 471100000;
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_cn_470_rp_1_0_config( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_rp_1_0_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_CN_470_RP_1_0;
- const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_CN_470_RP_1_0;
- const_number_of_channel_bank = BANK_MAX_CN470_RP_1_0;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_CN_470_RP_1_0;
- const_received_delay1 = RECEIVE_DELAY1_CN_470_RP_1_0;
- const_tx_power_dbm = TX_POWER_EIRP_CN_470_RP_1_0 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_CN_470_RP_1_0;
- const_adr_ack_limit = ADR_ACK_LIMIT_CN_470_RP_1_0;
- const_adr_ack_delay = ADR_ACK_DELAY_CN_470_RP_1_0;
- const_datarate_backoff = &datarate_backoff_cn_470_rp_1_0[0];
- const_ack_timeout = ACK_TIMEOUT_CN_470_RP_1_0;
- const_freq_min = FREQMIN_CN_470_RP_1_0;
- const_freq_max = FREQMAX_CN_470_RP_1_0;
- const_rx2_freq = RX2_FREQ_CN_470_RP_1_0;
- const_frequency_factor = FREQUENCY_FACTOR_CN_470_RP_1_0;
- const_rx2_dr_init = RX2DR_INIT_CN_470_RP_1_0;
- const_sync_word_private = SYNC_WORD_PRIVATE_CN_470_RP_1_0;
- const_sync_word_public = SYNC_WORD_PUBLIC_CN_470_RP_1_0;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_CN_470_RP_1_0;
- const_min_tx_dr = MIN_TX_DR_CN_470_RP_1_0;
- const_max_tx_dr = MAX_TX_DR_CN_470_RP_1_0;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_CN_470_RP_1_0;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_CN_470_RP_1_0;
- const_min_rx_dr = MIN_RX_DR_CN_470_RP_1_0;
- const_max_rx_dr = MAX_RX_DR_CN_470_RP_1_0;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_CN_470_RP_1_0;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_CN_470_RP_1_0;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_CN_470_RP_1_0;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_CN_470_RP_1_0;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_CN_470_RP_1_0;
- const_dtc_supported = DTC_SUPPORTED_CN_470_RP_1_0;
- const_lbt_supported = LBT_SUPPORTED_CN_470_RP_1_0;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_CN_470_RP_1_0;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470_RP_1_0;
- const_lbt_bw_hz = LBT_BW_HZ_CN_470_RP_1_0;
- const_max_payload_m = &M_cn_470_rp_1_0[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470_RP_1_0[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470_RP_1_0[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_CN_470_RP_1_0[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_CN_470_RP_1_0[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_CN_470_RP_1_0;
- const_beacon_dr = BEACON_DR_CN_470_RP_1_0;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_CN_470_RP_1_0;
+ real_const.const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_CN_470_RP_1_0;
+ real_const.const_number_of_channel_bank = BANK_MAX_CN470_RP_1_0;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_CN_470_RP_1_0;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_CN_470_RP_1_0;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_CN_470_RP_1_0 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_CN_470_RP_1_0;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_CN_470_RP_1_0;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_CN_470_RP_1_0;
+ real_const.const_datarate_offsets = &datarate_offsets_cn_470_rp_1_0[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_cn_470_rp_1_0[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_CN_470_RP_1_0;
+ real_const.const_freq_min = FREQMIN_CN_470_RP_1_0;
+ real_const.const_freq_max = FREQMAX_CN_470_RP_1_0;
+ real_const.const_rx2_freq = RX2_FREQ_CN_470_RP_1_0;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_CN_470_RP_1_0;
+ real_const.const_rx2_dr_init = RX2DR_INIT_CN_470_RP_1_0;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_CN_470_RP_1_0;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_CN_470_RP_1_0;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_CN_470_RP_1_0;
+ real_const.const_min_tx_dr = MIN_TX_DR_CN_470_RP_1_0;
+ real_const.const_max_tx_dr = MAX_TX_DR_CN_470_RP_1_0;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_CN_470_RP_1_0;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_CN_470_RP_1_0;
+ real_const.const_min_rx_dr = MIN_RX_DR_CN_470_RP_1_0;
+ real_const.const_max_rx_dr = MAX_RX_DR_CN_470_RP_1_0;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_CN_470_RP_1_0;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_CN_470_RP_1_0;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_dtc_supported = DTC_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_lbt_supported = LBT_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_CN_470_RP_1_0;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_CN_470_RP_1_0;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_CN_470_RP_1_0;
+ real_const.const_max_payload_m = &M_cn_470_rp_1_0[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_CN_470_RP_1_0[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_CN_470_RP_1_0[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_CN_470_RP_1_0[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_CN_470_RP_1_0[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_CN_470_RP_1_0;
+ real_const.const_beacon_dr = BEACON_DR_CN_470_RP_1_0;
real_ctx.tx_frequency_channel_ctx = NULL;
real_ctx.rx1_frequency_channel_ctx = NULL;
@@ -140,8 +142,8 @@ void region_cn_470_rp_1_0_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 0, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 0, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
// Enable all unwrapped channels
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_CN470_RP_1_0 );
@@ -149,41 +151,41 @@ void region_cn_470_rp_1_0_config( lr1_stack_mac_t* lr1_mac )
snapshot_bank_tx_mask = BANK_0_125_CN470_RP_1_0;
}
-void region_cn_470_rp_1_0_init( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_rp_1_0_config( smtc_real_t* real )
{
// Tx 125 kHz channels
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
// Enable default datarate
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
SMTC_MODEM_HAL_TRACE_PRINTF( "TX - idx:%u, freq: %d, dr: 0x%x,\n%s", i,
- region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, i ),
+ region_cn_470_rp_1_0_get_tx_frequency_channel( real, i ),
dr_bitfield_tx_channel[i], ( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
// Rx 500 kHz channels
- for( uint8_t i = 0; i < const_number_of_rx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_rx_channel; i++ )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "RX - idx:%u, freq: %d, dr_min: %u, dr_max: %u\n%s", i,
- region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, i ),
- MIN_RX_DR_CN_470_RP_1_0, MAX_RX_DR_CN_470_RP_1_0,
- ( ( i % 8 ) == 7 ) ? "---\n" : "" );
+ region_cn_470_rp_1_0_get_rx1_frequency_channel( real, i ), MIN_RX_DR_CN_470_RP_1_0,
+ MAX_RX_DR_CN_470_RP_1_0, ( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#endif
}
-status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
uint8_t err = true;
uint8_t ch_index_mono = 0;
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
- if( freq_tx_cn470_mono_channel_mhz == region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, i ) )
+ if( freq_tx_cn470_mono_channel_mhz == region_cn_470_rp_1_0_get_tx_frequency_channel( real, i ) )
{
err = false;
ch_index_mono = i;
@@ -194,8 +196,8 @@ status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( lr1_stack_mac_t* lr
{
smtc_modem_hal_lr1mac_panic( );
}
- lr1_mac->tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, ch_index_mono );
- lr1_mac->rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, ch_index_mono );
+ *out_tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( real, ch_index_mono );
+ *out_rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( real, ch_index_mono );
return OKLORAWAN;
#endif
@@ -214,7 +216,7 @@ status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( lr1_stack_mac_t* lr
for( uint8_t i = snapshot_bank_tx_mask * 8; i < ( ( snapshot_bank_tx_mask * 8 ) + 8 ); i++ )
{
if( ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 ) )
+ ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 ) )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -236,28 +238,29 @@ status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( lr1_stack_mac_t* lr
temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
return ERRORLORAWAN;
}
- lr1_mac->tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( real, channel_idx );
return OKLORAWAN;
}
-status_lorawan_t region_cn_470_rp_1_0_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_cn_470_rp_1_0_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
#if defined( HYBRID_CN470_MONO_CHANNEL )
uint8_t err = true;
uint8_t ch_index_mono = 0;
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
- if( freq_tx_cn470_mono_channel_mhz == region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, i ) )
+ if( freq_tx_cn470_mono_channel_mhz == region_cn_470_rp_1_0_get_tx_frequency_channel( real, i ) )
{
err = false;
ch_index_mono = i;
@@ -268,19 +271,19 @@ status_lorawan_t region_cn_470_rp_1_0_get_next_channel( lr1_stack_mac_t* lr1_mac
{
smtc_modem_hal_lr1mac_panic( );
}
- lr1_mac->tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, ch_index_mono );
- lr1_mac->rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, ch_index_mono );
+ *out_tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( real, ch_index_mono );
+ *out_rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( real, ch_index_mono );
return OKLORAWAN;
#endif
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_TX_CHANNEL_CN_470_RP_1_0];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -296,7 +299,7 @@ status_lorawan_t region_cn_470_rp_1_0_get_next_channel( lr1_stack_mac_t* lr1_mac
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -304,47 +307,18 @@ status_lorawan_t region_cn_470_rp_1_0_get_next_channel( lr1_stack_mac_t* lr1_mac
}
else
{
- lr1_mac->tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_cn_470_rp_1_0_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_cn_470_rp_1_0_get_rx1_frequency_channel( real, channel_idx );
}
return OKLORAWAN;
}
-uint8_t region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
+uint8_t region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( smtc_real_t* real )
{
return 6;
}
-void region_cn_470_rp_1_0_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_cn_470_rp_1_0[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-
-void region_cn_470_rp_1_0_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_CN470_RP_1_0 );
-
- SMTC_MODEM_HAL_TRACE_MSG( "Ch Mask\n" );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-status_channel_t region_cn_470_rp_1_0_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
+status_channel_t region_cn_470_rp_1_0_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl,
uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
@@ -361,10 +335,10 @@ status_channel_t region_cn_470_rp_1_0_build_channel_mask( lr1_stack_mac_t* lr1_m
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) &&
- ( region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, i ) == 0 ) )
+ ( region_cn_470_rp_1_0_get_tx_frequency_channel( real, i ) == 0 ) )
{
status = ERROR_CHANNEL_MASK; // this status is used only for the last multiple link adr req
break; // break for loop
@@ -397,9 +371,9 @@ status_channel_t region_cn_470_rp_1_0_build_channel_mask( lr1_stack_mac_t* lr1_m
return ( status );
}
-void region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_BIT_FIELD_CN_470_RP_1_0;
@@ -432,24 +406,24 @@ void region_cn_470_rp_1_0_lora_dr_to_sf_bw( uint8_t in_dr, uint8_t* out_sf, lr1m
}
}
-uint32_t region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_cn_470_rp_1_0_get_tx_frequency_channel( smtc_real_t* real, uint8_t index )
{
return ( DEFAULT_TX_FREQ_CN_470_RP_1_0 + ( index * DEFAULT_TX_STEP_CN_470_RP_1_0 ) );
}
-uint32_t region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_cn_470_rp_1_0_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index )
{
return ( DEFAULT_RX_FREQ_CN_470_RP_1_0 +
( ( index % NUMBER_OF_RX_CHANNEL_CN_470_RP_1_0 ) * DEFAULT_RX_STEP_CN_470_RP_1_0 ) );
}
-uint32_t region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s )
+uint32_t region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s )
{
uint8_t index = ( uint32_t )( floorf( gps_time_s / 128 ) ) % 8;
return ( BEACON_FREQ_START_CN_470_RP_1_0 + ( ( index % 8 ) * BEACON_STEP_CN_470_RP_1_0 ) );
}
-uint32_t region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
+uint32_t region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s,
uint32_t dev_addr )
{
uint8_t index = ( dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) ) % 8;
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.h
index 143bb47..a0dbdb1 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0.h
@@ -77,71 +77,58 @@ extern "C" {
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_rp_1_0_config( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_rp_1_0_init( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_rp_1_0_init( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_rp_1_0_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_rp_1_0_init_session( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_rp_1_0_init_session( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint8_t region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac );
+uint8_t region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_cn_470_rp_1_0_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_cn_470_rp_1_0_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_cn_470_rp_1_0_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_rp_1_0_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_channel_t region_cn_470_rp_1_0_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_cn_470_rp_1_0_set_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_channel_t region_cn_470_rp_1_0_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl,
- uint16_t ChMask );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
@@ -165,33 +152,33 @@ void region_cn_470_rp_1_0_lora_dr_to_sf_bw( uint8_t in_dr, uint8_t* out_sf, lr1m
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_cn_470_rp_1_0_get_tx_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_cn_470_rp_1_0_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* @brief Get the beacon frequency corresponding to a gps_time
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @return uint32_t
*/
-uint32_t region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s );
+uint32_t region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s );
/**
* @brief Get the beacon frequency corresponding to a gps_time and Dev Address
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @param dev_addr
* @return uint32_t
*/
-uint32_t region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
+uint32_t region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s,
uint32_t dev_addr );
#ifdef __cplusplus
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h
index e7e28bb..f35df27 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_cn_470_rp_1_0_defs.h
@@ -136,7 +136,7 @@ static const uint8_t datarate_offsets_cn_470_rp_1_0[8][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_cn_470_rp_1_0[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c
index 28387fc..bccb477 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.c
@@ -48,15 +48,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.eu868.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.eu868.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.eu868.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.eu868.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.eu868.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.eu868.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.eu868.unwrapped_channel_mask
+#define tx_frequency_channel real->region.eu868.tx_frequency_channel
+#define rx1_frequency_channel real->region.eu868.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.eu868.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.eu868.channel_index_enabled
+#define dr_distribution_init real->region.eu868.dr_distribution_init
+#define dr_distribution real->region.eu868.dr_distribution
+#define unwrapped_channel_mask real->region.eu868.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -83,57 +84,59 @@
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_eu_868_config( lr1_stack_mac_t* lr1_mac )
+void region_eu_868_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_EU_868;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_EU_868;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_EU_868;
- const_number_of_channel_bank = BANK_MAX_EU868;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_EU_868;
- const_received_delay1 = RECEIVE_DELAY1_EU_868;
- const_tx_power_dbm = TX_POWER_EIRP_EU_868 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_EU_868;
- const_adr_ack_limit = ADR_ACK_LIMIT_EU_868;
- const_adr_ack_delay = ADR_ACK_DELAY_EU_868;
- const_datarate_backoff = &datarate_backoff_eu_868[0];
- const_ack_timeout = ACK_TIMEOUT_EU_868;
- const_freq_min = FREQMIN_EU_868;
- const_freq_max = FREQMAX_EU_868;
- const_rx2_freq = RX2_FREQ_EU_868;
- const_frequency_factor = FREQUENCY_FACTOR_EU_868;
- const_rx2_dr_init = RX2DR_INIT_EU_868;
- const_sync_word_private = SYNC_WORD_PRIVATE_EU_868;
- const_sync_word_public = SYNC_WORD_PUBLIC_EU_868;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_EU_868;
- const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_EU_868;
- const_min_tx_dr = MIN_TX_DR_EU_868;
- const_max_tx_dr = MAX_TX_DR_EU_868;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_EU_868;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_EU_868;
- const_min_rx_dr = MIN_RX_DR_EU_868;
- const_max_rx_dr = MAX_RX_DR_EU_868;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_EU_868;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_EU_868;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_EU_868;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_EU_868;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_EU_868;
- const_dtc_supported = DTC_SUPPORTED_EU_868;
- const_dtc_number_of_band = BAND_EU868_MAX;
- const_dtc_by_band = &duty_cycle_by_band_eu_868[0];
- const_lbt_supported = LBT_SUPPORTED_EU_868;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_EU_868;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_EU_868;
- const_lbt_bw_hz = LBT_BW_HZ_EU_868;
- const_max_payload_m = &M_eu_868[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_EU_868[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_EU_868[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_EU_868[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_EU_868[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_EU_868;
- const_beacon_dr = BEACON_DR_EU_868;
- const_beacon_frequency = BEACON_FREQ_EU_868;
- const_ping_slot_frequency = PING_SLOT_FREQ_EU_868;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_EU_868;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_EU_868;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_EU_868;
+ real_const.const_number_of_channel_bank = BANK_MAX_EU868;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_EU_868;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_EU_868;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_EU_868 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_EU_868;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_EU_868;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_EU_868;
+ real_const.const_datarate_offsets = &datarate_offsets_eu_868[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_eu_868[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_EU_868;
+ real_const.const_freq_min = FREQMIN_EU_868;
+ real_const.const_freq_max = FREQMAX_EU_868;
+ real_const.const_rx2_freq = RX2_FREQ_EU_868;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_EU_868;
+ real_const.const_rx2_dr_init = RX2DR_INIT_EU_868;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_EU_868;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_EU_868;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_EU_868;
+ real_const.const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_EU_868;
+ real_const.const_min_tx_dr = MIN_TX_DR_EU_868;
+ real_const.const_max_tx_dr = MAX_TX_DR_EU_868;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_EU_868;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_EU_868;
+ real_const.const_min_rx_dr = MIN_RX_DR_EU_868;
+ real_const.const_max_rx_dr = MAX_RX_DR_EU_868;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_EU_868;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_EU_868;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_EU_868;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_EU_868;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_EU_868;
+ real_const.const_dtc_supported = DTC_SUPPORTED_EU_868;
+ real_const.const_dtc_number_of_band = BAND_EU868_MAX;
+ real_const.const_dtc_by_band = &duty_cycle_by_band_eu_868[0];
+ real_const.const_dtc_frequency_range_by_band = &frequency_range_by_band_eu_868[0][0],
+ real_const.const_lbt_supported = LBT_SUPPORTED_EU_868;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_EU_868;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_EU_868;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_EU_868;
+ real_const.const_max_payload_m = &M_eu_868[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_EU_868[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_EU_868[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_EU_868[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_EU_868[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_EU_868;
+ real_const.const_beacon_dr = BEACON_DR_EU_868;
+ real_const.const_beacon_frequency = BEACON_FREQ_EU_868;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_EU_868;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -143,31 +146,24 @@ void region_eu_868_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
-
- // Configure duty-cycle object
- for( int i = 0; i < const_dtc_number_of_band; i++ )
- {
- smtc_duty_cycle_config( lr1_mac->dtc_obj, const_dtc_number_of_band, i, duty_cycle_by_band_eu_868[i],
- frequency_range_by_band_eu_868[i][0], frequency_range_by_band_eu_868[i][1] );
- }
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_eu_868_init( lr1_stack_mac_t* lr1_mac )
+void region_eu_868_config( smtc_real_t* real )
{
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
tx_frequency_channel[i] = 0;
rx1_frequency_channel[i] = 0;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
tx_frequency_channel[i] = default_freq_eu_868[i];
rx1_frequency_channel[i] = default_freq_eu_868[i];
@@ -178,22 +174,24 @@ void region_eu_868_init( lr1_stack_mac_t* lr1_mac )
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_EU868 );
}
-status_lorawan_t region_eu_868_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_eu_868_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_eu_868_get_next_channel( lr1_mac );
+ return region_eu_868_get_next_channel( real, dtc_obj, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_eu_868_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_eu_868_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_EU_868];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( ( smtc_duty_cycle_is_channel_free( lr1_mac->dtc_obj, tx_frequency_channel[i] ) == true ) &&
- ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 ) )
+ if( ( smtc_duty_cycle_is_channel_free( dtc_obj, tx_frequency_channel[i] ) == true ) &&
+ ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 ) )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -209,49 +207,20 @@ status_lorawan_t region_eu_868_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
return ERRORLORAWAN;
}
- else
- {
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
- }
- return OKLORAWAN;
-}
-void region_eu_868_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_eu_868[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_eu_868_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_EU868 );
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
+ return OKLORAWAN;
}
-status_channel_t region_eu_868_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_eu_868_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -261,7 +230,7 @@ status_channel_t region_eu_868_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -281,7 +250,7 @@ status_channel_t region_eu_868_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
// The device SHOULD enable all currently defined channels independently of the ChMask field value.
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_EU868 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.h
index 0516c80..ee0a2f9 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868.h
@@ -72,60 +72,47 @@ extern "C" {
*/
/**
- * @brief Congigure the region with default value and pointers
+ * @brief Initialize the region with default value and pointers
*
- * @param lr1_mac
+ * @param real
*/
-void region_eu_868_config( lr1_stack_mac_t* lr1_mac );
+void region_eu_868_init( smtc_real_t* real );
/**
- * @brief Initialize the regional boot parameter
+ * @brief Configure the regional boot parameter
* @remark must be called before each join request
*
- * @param lr1_mac
+ * @param real
*/
-void region_eu_868_init( lr1_stack_mac_t* lr1_mac );
+void region_eu_868_config( smtc_real_t* real );
/**
* @brief Get the next channel for the future uplink
*
- * @param lr1_mac
+ * @param real
* @return status_lorawan_t
*/
-status_lorawan_t region_eu_868_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_eu_868_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* @brief Get the next channel for the future join request
*
- * @param lr1_mac
+ * @param real
* @return status_lorawan_t
*/
-status_lorawan_t region_eu_868_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
-
-/**
- * @brief Set the datarate for Rx1 and Rx2
- *
- * @param lr1_mac
- * @param type
- */
-void region_eu_868_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
-
-/**
- * @brief Set the channel mask received by the LinkADRReq
- *
- * @param lr1_mac
- */
-void region_eu_868_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_eu_868_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* @brief Decrypt and build the Channel Mask from multiple atomic LinkADRReq
*
- * @param lr1_mac
+ * @param real
* @param ChMaskCntl
* @param ChMask
* @return status_channel_t
*/
-status_channel_t region_eu_868_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+status_channel_t region_eu_868_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* @brief Get the corresponding RF modulation from a Datarate
@@ -147,7 +134,7 @@ void region_eu_868_lora_dr_to_sf_bw( uint8_t in_dr, uint8_t* out_sf, lr1mac_band
/**
* @brief Convert LoRaWAN Datarate to FSK bitrate
*
- * @param lr1_mac
+ * @param real
* @param in_dr
* @param out_bitrate
*/
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h
index 98377a5..cdf60b8 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_eu_868_defs.h
@@ -178,7 +178,7 @@ static const uint8_t datarate_offsets_eu_868[12][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_eu_868[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c
index ec68707..27703f3 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.c
@@ -47,15 +47,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.in865.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.in865.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.in865.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.in865.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.in865.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.in865.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.in865.unwrapped_channel_mask
+#define tx_frequency_channel real->region.in865.tx_frequency_channel
+#define rx1_frequency_channel real->region.in865.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.in865.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.in865.channel_index_enabled
+#define dr_distribution_init real->region.in865.dr_distribution_init
+#define dr_distribution real->region.in865.dr_distribution
+#define unwrapped_channel_mask real->region.in865.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -82,51 +83,52 @@
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_in_865_config( lr1_stack_mac_t* lr1_mac )
+void region_in_865_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_IN_865;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_IN_865;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_IN_865;
- const_number_of_channel_bank = BANK_MAX_IN865;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_IN_865;
- const_received_delay1 = RECEIVE_DELAY1_IN_865;
- const_tx_power_dbm = TX_POWER_EIRP_IN_865 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_IN_865;
- const_adr_ack_limit = ADR_ACK_LIMIT_IN_865;
- const_adr_ack_delay = ADR_ACK_DELAY_IN_865;
- const_datarate_backoff = &datarate_backoff_in_865[0];
- const_ack_timeout = ACK_TIMEOUT_IN_865;
- const_frequency_factor = FREQUENCY_FACTOR_IN_865;
- const_freq_min = FREQMIN_IN_865;
- const_freq_max = FREQMAX_IN_865;
- const_rx2_freq = RX2_FREQ_IN_865;
- const_rx2_dr_init = RX2DR_INIT_IN_865;
- const_sync_word_private = SYNC_WORD_PRIVATE_IN_865;
- const_sync_word_public = SYNC_WORD_PUBLIC_IN_865;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_IN_865;
- const_min_tx_dr = MIN_DR_IN_865;
- const_max_tx_dr = MAX_DR_IN_865;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_IN_865;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_IN_865;
- const_min_rx_dr = MIN_DR_IN_865;
- const_max_rx_dr = MAX_DR_IN_865;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_IN_865;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_IN_865;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_IN_865;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_IN_865;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_IN_865;
- const_dtc_supported = DTC_SUPPORTED_IN_865;
- const_lbt_supported = LBT_SUPPORTED_IN_865;
- const_max_payload_m = &M_in_865[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_IN_865[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_IN_865[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_IN_865[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_IN_865[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_IN_865;
- const_beacon_dr = BEACON_DR_IN_865;
- const_beacon_frequency = BEACON_FREQ_IN_865;
- const_ping_slot_frequency = PING_SLOT_FREQ_IN_865;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_IN_865;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_IN_865;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_IN_865;
+ real_const.const_number_of_channel_bank = BANK_MAX_IN865;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_IN_865;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_IN_865;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_IN_865 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_IN_865;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_IN_865;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_IN_865;
+ real_const.const_datarate_offsets = &datarate_offsets_in_865[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_in_865[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_IN_865;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_IN_865;
+ real_const.const_freq_min = FREQMIN_IN_865;
+ real_const.const_freq_max = FREQMAX_IN_865;
+ real_const.const_rx2_freq = RX2_FREQ_IN_865;
+ real_const.const_rx2_dr_init = RX2DR_INIT_IN_865;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_IN_865;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_IN_865;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_IN_865;
+ real_const.const_min_tx_dr = MIN_DR_IN_865;
+ real_const.const_max_tx_dr = MAX_DR_IN_865;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_IN_865;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_IN_865;
+ real_const.const_min_rx_dr = MIN_DR_IN_865;
+ real_const.const_max_rx_dr = MAX_DR_IN_865;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_IN_865;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_IN_865;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_IN_865;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_IN_865;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_IN_865;
+ real_const.const_dtc_supported = DTC_SUPPORTED_IN_865;
+ real_const.const_lbt_supported = LBT_SUPPORTED_IN_865;
+ real_const.const_max_payload_m = &M_in_865[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_IN_865[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_IN_865[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_IN_865[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_IN_865[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_IN_865;
+ real_const.const_beacon_dr = BEACON_DR_IN_865;
+ real_const.const_beacon_frequency = BEACON_FREQ_IN_865;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_IN_865;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -136,24 +138,24 @@ void region_in_865_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_in_865_init( lr1_stack_mac_t* lr1_mac )
+void region_in_865_config( smtc_real_t* real )
{
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
tx_frequency_channel[i] = 0;
rx1_frequency_channel[i] = 0;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
tx_frequency_channel[i] = default_freq_in_865[i];
rx1_frequency_channel[i] = default_freq_in_865[i];
@@ -164,27 +166,29 @@ void region_in_865_init( lr1_stack_mac_t* lr1_mac )
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_IN865 );
}
-void region_in_865_init_session( lr1_stack_mac_t* lr1_mac )
+void region_in_865_init_session( smtc_real_t* real )
{
// Not used for IN865
return;
}
-status_lorawan_t region_in_865_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_in_865_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_in_865_get_next_channel( lr1_mac );
+ return region_in_865_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_in_865_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_in_865_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_IN_865];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -200,7 +204,7 @@ status_lorawan_t region_in_865_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -208,41 +212,13 @@ status_lorawan_t region_in_865_get_next_channel( lr1_stack_mac_t* lr1_mac )
}
else
{
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
}
return OKLORAWAN;
}
-void region_in_865_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_in_865[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_in_865_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_IN865 );
-
- for( uint8_t i = 0; i < NUMBER_OF_CHANNEL_IN_865; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-status_channel_t region_in_865_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_in_865_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -251,7 +227,7 @@ status_channel_t region_in_865_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -268,7 +244,7 @@ status_channel_t region_in_865_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
break;
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_IN865 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.h
index 3a6e43e..9681a08 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865.h
@@ -71,7 +71,7 @@ extern "C" {
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/
-void region_in_865_config( lr1_stack_mac_t* lr1_mac );
+void region_in_865_init( smtc_real_t* real );
/**
* \brief
@@ -79,56 +79,44 @@ void region_in_865_config( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void region_in_865_init( lr1_stack_mac_t* lr1_mac );
+void region_in_865_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_in_865_init_session( lr1_stack_mac_t* lr1_mac );
+void region_in_865_init_session( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_in_865_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_in_865_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_in_865_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_in_865_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_in_865_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_channel_t region_in_865_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_in_865_set_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_channel_t region_in_865_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_in_865_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_in_865_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h
index 3698fab..02750a6 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_in_865_defs.h
@@ -150,7 +150,7 @@ static const uint8_t datarate_offsets_in_865[8][8] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_in_865[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c
index 5b7b1ed..0b51bc1 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.c
@@ -48,15 +48,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.kr920.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.kr920.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.kr920.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.kr920.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.kr920.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.kr920.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.kr920.unwrapped_channel_mask
+#define tx_frequency_channel real->region.kr920.tx_frequency_channel
+#define rx1_frequency_channel real->region.kr920.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.kr920.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.kr920.channel_index_enabled
+#define dr_distribution_init real->region.kr920.dr_distribution_init
+#define dr_distribution real->region.kr920.dr_distribution
+#define unwrapped_channel_mask real->region.kr920.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -82,54 +83,55 @@
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_kr_920_config( lr1_stack_mac_t* lr1_mac )
+void region_kr_920_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_KR_920;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_KR_920;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_KR_920;
- const_number_of_channel_bank = BANK_MAX_KR920;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_KR_920;
- const_received_delay1 = RECEIVE_DELAY1_KR_920;
- const_tx_power_dbm = TX_POWER_EIRP_KR_920 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_KR_920;
- const_adr_ack_limit = ADR_ACK_LIMIT_KR_920;
- const_adr_ack_delay = ADR_ACK_DELAY_KR_920;
- const_datarate_backoff = &datarate_backoff_kr_920[0];
- const_ack_timeout = ACK_TIMEOUT_KR_920;
- const_frequency_factor = FREQUENCY_FACTOR_KR_920;
- const_freq_min = FREQMIN_KR_920;
- const_freq_max = FREQMAX_KR_920;
- const_rx2_freq = RX2_FREQ_KR_920;
- const_rx2_dr_init = RX2DR_INIT_KR_920;
- const_sync_word_private = SYNC_WORD_PRIVATE_KR_920;
- const_sync_word_public = SYNC_WORD_PUBLIC_KR_920;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_KR_920;
- const_min_tx_dr = MIN_DR_KR_920;
- const_max_tx_dr = MAX_DR_KR_920;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_KR_920;
- const_min_rx_dr = MIN_DR_KR_920;
- const_max_rx_dr = MAX_DR_KR_920;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_KR_920;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_KR_920;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_KR_920;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_KR_920;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_KR_920;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_KR_920;
- const_dtc_supported = DTC_SUPPORTED_KR_920;
- const_lbt_supported = LBT_SUPPORTED_KR_920;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_KR_920;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_KR_920;
- const_lbt_bw_hz = LBT_BW_HZ_KR_920;
- const_max_payload_m = &M_kr_920[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_KR_920[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_KR_920[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_KR_920[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_KR_920[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_KR_920;
- const_beacon_dr = BEACON_DR_KR_920;
- const_beacon_frequency = BEACON_FREQ_KR_920;
- const_ping_slot_frequency = PING_SLOT_FREQ_KR_920;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_KR_920;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_KR_920;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_KR_920;
+ real_const.const_number_of_channel_bank = BANK_MAX_KR920;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_KR_920;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_KR_920;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_KR_920 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_KR_920;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_KR_920;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_KR_920;
+ real_const.const_datarate_offsets = &datarate_offsets_kr_920[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_kr_920[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_KR_920;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_KR_920;
+ real_const.const_freq_min = FREQMIN_KR_920;
+ real_const.const_freq_max = FREQMAX_KR_920;
+ real_const.const_rx2_freq = RX2_FREQ_KR_920;
+ real_const.const_rx2_dr_init = RX2DR_INIT_KR_920;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_KR_920;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_KR_920;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_KR_920;
+ real_const.const_min_tx_dr = MIN_DR_KR_920;
+ real_const.const_max_tx_dr = MAX_DR_KR_920;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_KR_920;
+ real_const.const_min_rx_dr = MIN_DR_KR_920;
+ real_const.const_max_rx_dr = MAX_DR_KR_920;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_KR_920;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_KR_920;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_KR_920;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_KR_920;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_KR_920;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_KR_920;
+ real_const.const_dtc_supported = DTC_SUPPORTED_KR_920;
+ real_const.const_lbt_supported = LBT_SUPPORTED_KR_920;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_KR_920;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_KR_920;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_KR_920;
+ real_const.const_max_payload_m = &M_kr_920[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_KR_920[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_KR_920[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_KR_920[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_KR_920[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_KR_920;
+ real_const.const_beacon_dr = BEACON_DR_KR_920;
+ real_const.const_beacon_frequency = BEACON_FREQ_KR_920;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_KR_920;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -139,24 +141,24 @@ void region_kr_920_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_kr_920_init( lr1_stack_mac_t* lr1_mac )
+void region_kr_920_config( smtc_real_t* real )
{
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
tx_frequency_channel[i] = 0;
rx1_frequency_channel[i] = 0;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
tx_frequency_channel[i] = default_freq_kr_920[i];
rx1_frequency_channel[i] = default_freq_kr_920[i];
@@ -167,27 +169,29 @@ void region_kr_920_init( lr1_stack_mac_t* lr1_mac )
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_KR920 );
}
-void region_kr_920_init_session( lr1_stack_mac_t* lr1_mac )
+void region_kr_920_init_session( smtc_real_t* real )
{
// Not used for KR920
return;
}
-status_lorawan_t region_kr_920_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_kr_920_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_kr_920_get_next_channel( lr1_mac );
+ return region_kr_920_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_kr_920_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_kr_920_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_KR_920];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -203,7 +207,7 @@ status_lorawan_t region_kr_920_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -211,52 +215,24 @@ status_lorawan_t region_kr_920_get_next_channel( lr1_stack_mac_t* lr1_mac )
}
else
{
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
}
return OKLORAWAN;
}
-void region_kr_920_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_kr_920[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_kr_920_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_KR920 );
-
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-void region_kr_920_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_kr_920_init_join_snapshot_channel_mask( smtc_real_t* real )
{
// Not useful for KR920
return;
}
-void region_kr_920_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_kr_920_init_after_join_snapshot_channel_mask( smtc_real_t* real )
{
// Not useful for KR920
return;
}
-status_channel_t region_kr_920_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_kr_920_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -265,7 +241,7 @@ status_channel_t region_kr_920_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -282,7 +258,7 @@ status_channel_t region_kr_920_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
break;
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_KR920 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.h
index 8aaeab7..d25acdb 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920.h
@@ -71,7 +71,7 @@ extern "C" {
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
*/
-void region_kr_920_config( lr1_stack_mac_t* lr1_mac );
+void region_kr_920_init( smtc_real_t* real );
/**
* \brief
@@ -79,63 +79,51 @@ void region_kr_920_config( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void region_kr_920_init( lr1_stack_mac_t* lr1_mac );
+void region_kr_920_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_kr_920_init_session( lr1_stack_mac_t* lr1_mac );
+void region_kr_920_init_session( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_kr_920_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_kr_920_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_kr_920_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_kr_920_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_kr_920_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+void region_kr_920_init_join_snapshot_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_kr_920_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_kr_920_init_after_join_snapshot_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_kr_920_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_kr_920_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_channel_t region_kr_920_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+status_channel_t region_kr_920_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* @brief Get the corresponding RF modulation from a Datarate
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h
index 8cfe3dc..d21451a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_kr_920_defs.h
@@ -144,7 +144,7 @@ static const uint8_t datarate_offsets_kr_920[6][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_kr_920[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c
index ccc79fa..d2e9dff 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.c
@@ -48,15 +48,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.ru864.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.ru864.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.ru864.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.ru864.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.ru864.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.ru864.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.ru864.unwrapped_channel_mask
+#define tx_frequency_channel real->region.ru864.tx_frequency_channel
+#define rx1_frequency_channel real->region.ru864.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.ru864.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.ru864.channel_index_enabled
+#define dr_distribution_init real->region.ru864.dr_distribution_init
+#define dr_distribution real->region.ru864.dr_distribution
+#define unwrapped_channel_mask real->region.ru864.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -83,56 +84,58 @@
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_ru_864_config( lr1_stack_mac_t* lr1_mac )
+void region_ru_864_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_RU_864;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_RU_864;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_RU_864;
- const_number_of_channel_bank = BANK_MAX_RU864;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_RU_864;
- const_received_delay1 = RECEIVE_DELAY1_RU_864;
- const_tx_power_dbm = TX_POWER_EIRP_RU_864 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_RU_864;
- const_adr_ack_limit = ADR_ACK_LIMIT_RU_864;
- const_adr_ack_delay = ADR_ACK_DELAY_RU_864;
- const_datarate_backoff = &datarate_backoff_ru_864[0];
- const_ack_timeout = ACK_TIMEOUT_RU_864;
- const_freq_min = FREQMIN_RU_864;
- const_freq_max = FREQMAX_RU_864;
- const_rx2_freq = RX2_FREQ_RU_864;
- const_frequency_factor = FREQUENCY_FACTOR_RU_864;
- const_rx2_dr_init = RX2DR_INIT_RU_864;
- const_sync_word_private = SYNC_WORD_PRIVATE_RU_864;
- const_sync_word_public = SYNC_WORD_PUBLIC_RU_864;
- const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_RU_864;
- const_min_tx_dr = MIN_DR_RU_864;
- const_max_tx_dr = MAX_DR_RU_864;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_RU_864;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_RU_864;
- const_min_rx_dr = MIN_DR_RU_864;
- const_max_rx_dr = MAX_DR_RU_864;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_RU_864;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_RU_864;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_RU_864;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_RU_864;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_RU_864;
- const_dtc_supported = DTC_SUPPORTED_RU_864;
- const_dtc_number_of_band = BAND_RU864_MAX;
- const_dtc_by_band = &duty_cycle_by_band_ru_864[0];
- const_lbt_supported = LBT_SUPPORTED_RU_864;
- const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_RU_864;
- const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_RU_864;
- const_lbt_bw_hz = LBT_BW_HZ_RU_864;
- const_max_payload_m = &M_ru_864[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_RU_864[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_RU_864[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_RU_864[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_RU_864[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_RU_864;
- const_beacon_dr = BEACON_DR_RU_864;
- const_beacon_frequency = BEACON_FREQ_RU_864;
- const_ping_slot_frequency = PING_SLOT_FREQ_RU_864;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_RU_864;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_RU_864;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_RU_864;
+ real_const.const_number_of_channel_bank = BANK_MAX_RU864;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_RU_864;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_RU_864;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_RU_864 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_RU_864;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_RU_864;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_RU_864;
+ real_const.const_datarate_offsets = &datarate_offsets_ru_864[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_ru_864[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_RU_864;
+ real_const.const_freq_min = FREQMIN_RU_864;
+ real_const.const_freq_max = FREQMAX_RU_864;
+ real_const.const_rx2_freq = RX2_FREQ_RU_864;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_RU_864;
+ real_const.const_rx2_dr_init = RX2DR_INIT_RU_864;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_RU_864;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_RU_864;
+ real_const.const_sync_word_gfsk = ( uint8_t* ) SYNC_WORD_GFSK_RU_864;
+ real_const.const_min_tx_dr = MIN_DR_RU_864;
+ real_const.const_max_tx_dr = MAX_DR_RU_864;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_RU_864;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_RU_864;
+ real_const.const_min_rx_dr = MIN_DR_RU_864;
+ real_const.const_max_rx_dr = MAX_DR_RU_864;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_RU_864;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_RU_864;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_RU_864;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_RU_864;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_RU_864;
+ real_const.const_dtc_supported = DTC_SUPPORTED_RU_864;
+ real_const.const_dtc_number_of_band = BAND_RU864_MAX;
+ real_const.const_dtc_by_band = &duty_cycle_by_band_ru_864[0];
+ real_const.const_dtc_frequency_range_by_band = &frequency_range_by_band_ru_864[0][0],
+ real_const.const_lbt_supported = LBT_SUPPORTED_RU_864;
+ real_const.const_lbt_sniff_duration_ms = LBT_SNIFF_DURATION_MS_RU_864;
+ real_const.const_lbt_threshold_dbm = LBT_THRESHOLD_DBM_RU_864;
+ real_const.const_lbt_bw_hz = LBT_BW_HZ_RU_864;
+ real_const.const_max_payload_m = &M_ru_864[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_RU_864[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_RU_864[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_RU_864[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_RU_864[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_RU_864;
+ real_const.const_beacon_dr = BEACON_DR_RU_864;
+ real_const.const_beacon_frequency = BEACON_FREQ_RU_864;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_RU_864;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -142,31 +145,24 @@ void region_ru_864_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
-
- // Configure duty-cycle object
- for( int i = 0; i < const_dtc_number_of_band; i++ )
- {
- smtc_duty_cycle_config( lr1_mac->dtc_obj, const_dtc_number_of_band, i, duty_cycle_by_band_ru_864[i],
- frequency_range_by_band_ru_864[i][0], frequency_range_by_band_ru_864[i][1] );
- }
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_ru_864_init( lr1_stack_mac_t* lr1_mac )
+void region_ru_864_config( smtc_real_t* real )
{
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
tx_frequency_channel[i] = 0;
rx1_frequency_channel[i] = 0;
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
tx_frequency_channel[i] = default_freq_ru_864[i];
rx1_frequency_channel[i] = default_freq_ru_864[i];
@@ -177,22 +173,24 @@ void region_ru_864_init( lr1_stack_mac_t* lr1_mac )
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_RU864 );
}
-status_lorawan_t region_ru_864_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_ru_864_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_ru_864_get_next_channel( lr1_mac );
+ return region_ru_864_get_next_channel( real, dtc_obj, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_ru_864_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_ru_864_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_RU_864];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( ( smtc_duty_cycle_is_channel_free( lr1_mac->dtc_obj, tx_frequency_channel[i] ) == true ) &&
- ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 ) )
+ if( ( smtc_duty_cycle_is_channel_free( dtc_obj, tx_frequency_channel[i] ) == true ) &&
+ ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 ) )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -208,7 +206,7 @@ status_lorawan_t region_ru_864_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
@@ -216,41 +214,13 @@ status_lorawan_t region_ru_864_get_next_channel( lr1_stack_mac_t* lr1_mac )
}
else
{
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
}
return OKLORAWAN;
}
-void region_ru_864_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_ru_864[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_ru_864_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_RU864 );
-
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-status_channel_t region_ru_864_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_ru_864_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -259,7 +229,7 @@ status_channel_t region_ru_864_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -276,7 +246,7 @@ status_channel_t region_ru_864_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
break;
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_RU864 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.h
index d7c75df..aba9bf0 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864.h
@@ -72,61 +72,49 @@ extern "C" {
*/
/**
- * @brief Congigure the region with default value and pointers
+ * @brief Initialize the region with default value and pointers
*
- * @param lr1_mac
+ * @param real
*/
-void region_ru_864_config( lr1_stack_mac_t* lr1_mac );
+void region_ru_864_init( smtc_real_t* real );
/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_ru_864_init( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_lorawan_t region_ru_864_get_next_channel( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
+ * \brief Configure the region
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_ru_864_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+void region_ru_864_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ru_864_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_lorawan_t region_ru_864_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ru_864_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_ru_864_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_channel_t region_ru_864_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+status_channel_t region_ru_864_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ru_864_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_ru_864_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h
index 71f2835..da5f1b9 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ru_864_defs.h
@@ -158,7 +158,7 @@ static const uint8_t datarate_offsets_ru_864[8][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_ru_864[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c
index 8b0ffb8..38286a8 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.c
@@ -48,17 +48,18 @@
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define dr_bitfield_tx_channel lr1_mac->real->region.us915.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.us915.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.us915.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.us915.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.us915.unwrapped_channel_mask
-#define first_ch_mask_received lr1_mac->real->region.us915.first_ch_mask_received
+#define dr_bitfield_tx_channel real->region.us915.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.us915.channel_index_enabled
+#define dr_distribution_init real->region.us915.dr_distribution_init
+#define dr_distribution real->region.us915.dr_distribution
+#define unwrapped_channel_mask real->region.us915.unwrapped_channel_mask
+#define first_ch_mask_received real->region.us915.first_ch_mask_received
-#define snapshot_channel_tx_mask lr1_mac->real->region.us915.snapshot_channel_tx_mask
-#define snapshot_bank_tx_mask lr1_mac->real->region.us915.snapshot_bank_tx_mask
+#define snapshot_channel_tx_mask real->region.us915.snapshot_channel_tx_mask
+#define snapshot_bank_tx_mask real->region.us915.snapshot_bank_tx_mask
/*
* -----------------------------------------------------------------------------
@@ -90,56 +91,57 @@ typedef enum ch_mask_after_join_e
/**
* @brief init Channel mask after the join accept
*
- * @param lr1_mac
+ * @param real
*/
-static void region_us_915_channel_mask_set_after_join( lr1_stack_mac_t* lr1_mac );
+static void region_us_915_channel_mask_set_after_join( smtc_real_t* real );
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_us_915_config( lr1_stack_mac_t* lr1_mac )
+void region_us_915_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_US_915;
- const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_US_915;
- const_number_of_channel_bank = BANK_MAX_US915;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_US_915;
- const_received_delay1 = RECEIVE_DELAY1_US_915;
- const_tx_power_dbm = TX_POWER_EIRP_US_915 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_US_915;
- const_adr_ack_limit = ADR_ACK_LIMIT_US_915;
- const_adr_ack_delay = ADR_ACK_DELAY_US_915;
- const_datarate_backoff = &datarate_backoff_us_915[0];
- const_ack_timeout = ACK_TIMEOUT_US_915;
- const_freq_min = FREQMIN_US_915;
- const_freq_max = FREQMAX_US_915;
- const_rx2_freq = RX2_FREQ_US_915;
- const_frequency_factor = FREQUENCY_FACTOR_US_915;
- const_rx2_dr_init = RX2DR_INIT_US_915;
- const_sync_word_private = SYNC_WORD_PRIVATE_US_915;
- const_sync_word_public = SYNC_WORD_PUBLIC_US_915;
- const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_US_915;
- const_min_tx_dr = MIN_TX_DR_US_915;
- const_max_tx_dr = MAX_TX_DR_US_915;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_US_915;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_US_915;
- const_min_rx_dr = MIN_RX_DR_US_915;
- const_max_rx_dr = MAX_RX_DR_US_915;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_US_915;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_US_915;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_US_915;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_US_915;
- const_dtc_supported = DTC_SUPPORTED_US_915;
- const_lbt_supported = LBT_SUPPORTED_US_915;
- const_max_payload_m = &M_us_915[0];
- const_coding_rate = RAL_LORA_CR_4_5;
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_US_915[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_US_915[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_US_915[0];
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_US_915[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_US_915;
- const_beacon_dr = BEACON_DR_US_915;
+ real_const.const_number_of_tx_channel = NUMBER_OF_TX_CHANNEL_US_915;
+ real_const.const_number_of_rx_channel = NUMBER_OF_RX_CHANNEL_US_915;
+ real_const.const_number_of_channel_bank = BANK_MAX_US915;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_US_915;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_US_915;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_US_915 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_US_915;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_US_915;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_US_915;
+ real_const.const_datarate_offsets = &datarate_offsets_us_915[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_us_915[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_US_915;
+ real_const.const_freq_min = FREQMIN_US_915;
+ real_const.const_freq_max = FREQMAX_US_915;
+ real_const.const_rx2_freq = RX2_FREQ_US_915;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_US_915;
+ real_const.const_rx2_dr_init = RX2DR_INIT_US_915;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_US_915;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_US_915;
+ real_const.const_sync_word_lr_fhss = ( uint8_t* ) SYNC_WORD_LR_FHSS_US_915;
+ real_const.const_min_tx_dr = MIN_TX_DR_US_915;
+ real_const.const_max_tx_dr = MAX_TX_DR_US_915;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_US_915;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_US_915;
+ real_const.const_min_rx_dr = MIN_RX_DR_US_915;
+ real_const.const_max_rx_dr = MAX_RX_DR_US_915;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_US_915;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_US_915;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_US_915;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_US_915;
+ real_const.const_dtc_supported = DTC_SUPPORTED_US_915;
+ real_const.const_lbt_supported = LBT_SUPPORTED_US_915;
+ real_const.const_max_payload_m = &M_us_915[0];
+ real_const.const_coding_rate = RAL_LORA_CR_4_5;
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_US_915[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_US_915[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_US_915[0];
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_US_915[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_US_915;
+ real_const.const_beacon_dr = BEACON_DR_US_915;
real_ctx.tx_frequency_channel_ctx = NULL;
real_ctx.rx1_frequency_channel_ctx = NULL;
@@ -149,8 +151,8 @@ void region_us_915_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 0, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 0, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
// Enable all channels
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_US915 );
@@ -159,7 +161,7 @@ void region_us_915_config( lr1_stack_mac_t* lr1_mac )
snapshot_bank_tx_mask = 0;
}
-void region_us_915_init( lr1_stack_mac_t* lr1_mac )
+void region_us_915_config( smtc_real_t* real )
{
// Tx 125 kHz channels
for( uint8_t i = 0; i < NUMBER_OF_TX_CHANNEL_US_915 - 8; i++ )
@@ -170,7 +172,7 @@ void region_us_915_init( lr1_stack_mac_t* lr1_mac )
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_125_BIT_FIELD_US_915;
SMTC_MODEM_HAL_TRACE_PRINTF( "TX - idx:%u, freq: %d, dr: 0x%x,\n%s", i,
- region_us_915_get_tx_frequency_channel( lr1_mac, i ), dr_bitfield_tx_channel[i],
+ region_us_915_get_tx_frequency_channel( real, i ), dr_bitfield_tx_channel[i],
( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
// Tx 500 kHz channels
@@ -181,7 +183,7 @@ void region_us_915_init( lr1_stack_mac_t* lr1_mac )
dr_bitfield_tx_channel[i] = DEFAULT_TX_DR_500_BIT_FIELD_US_915;
SMTC_MODEM_HAL_TRACE_PRINTF( "TX - idx:%u, freq: %d, dr: 0x%x,\n%s", i,
- region_us_915_get_tx_frequency_channel( lr1_mac, i ), dr_bitfield_tx_channel[i],
+ region_us_915_get_tx_frequency_channel( real, i ), dr_bitfield_tx_channel[i],
( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
@@ -189,7 +191,7 @@ void region_us_915_init( lr1_stack_mac_t* lr1_mac )
for( uint8_t i = 0; i < NUMBER_OF_RX_CHANNEL_US_915; i++ )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "RX - idx:%u, freq: %d, dr_min: %u, dr_max: %u\n%s", i,
- region_us_915_get_rx1_frequency_channel( lr1_mac, i ), MIN_RX_DR_US_915,
+ region_us_915_get_rx1_frequency_channel( real, i ), MIN_RX_DR_US_915,
MAX_RX_DR_US_915, ( ( i % 8 ) == 7 ) ? "---\n" : "" );
}
#endif
@@ -197,8 +199,7 @@ void region_us_915_init( lr1_stack_mac_t* lr1_mac )
first_ch_mask_received = ch_mask_after_join_init;
}
-status_lorawan_t region_us_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, uint8_t dr,
- bool is_ch_mask_from_link_adr )
+status_lorawan_t region_us_915_is_acceptable_tx_dr( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr )
{
status_lorawan_t status = ERRORLORAWAN;
uint8_t number_channels_125_enabled = 0;
@@ -206,7 +207,7 @@ status_lorawan_t region_us_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
uint8_t* ch_mask_to_check = ( is_ch_mask_from_link_adr == true ) ? unwrapped_channel_mask : channel_index_enabled;
// 125 kHz channels
- for( uint8_t i = 0; i < const_number_of_tx_channel - 8; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel - 8; i++ )
{
if( SMTC_GET_BIT8( ch_mask_to_check, i ) == CHANNEL_ENABLED )
{
@@ -246,7 +247,8 @@ status_lorawan_t region_us_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, ui
return ( status );
}
-status_lorawan_t region_us_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_us_915_get_join_next_channel( smtc_real_t* real, uint8_t* out_tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
us_915_channels_bank_t bank_tmp_cnt = 0;
uint8_t active_channel_nb;
@@ -267,23 +269,11 @@ status_lorawan_t region_us_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
active_channel_nb = 0;
for( uint8_t i = snapshot_bank_tx_mask * 8; i < ( ( snapshot_bank_tx_mask * 8 ) + 8 ); i++ )
{
- if( snapshot_bank_tx_mask == BANK_8_500_US915 )
+ if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
+ ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
{
- if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
- {
- active_channel_index[active_channel_nb] = i;
- active_channel_nb++;
- }
- }
- else
- {
- if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) )
- {
- active_channel_index[active_channel_nb] = i;
- active_channel_nb++;
- }
+ active_channel_index[active_channel_nb] = i;
+ active_channel_nb++;
}
}
snapshot_bank_tx_mask++;
@@ -320,15 +310,15 @@ status_lorawan_t region_us_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
SMTC_PUT_BIT8( snapshot_channel_tx_mask, channel_idx, CHANNEL_DISABLED );
if( snapshot_bank_tx_mask > BANK_8_500_US915 )
{
- lr1_mac->tx_data_rate = DR4;
+ *out_tx_data_rate = DR4;
}
else
{
- lr1_mac->tx_data_rate = DR0;
+ *out_tx_data_rate = DR0;
}
- lr1_mac->tx_frequency = region_us_915_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_us_915_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_us_915_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_us_915_get_rx1_frequency_channel( real, channel_idx );
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
SMTC_MODEM_HAL_TRACE_PRINTF( "snapshot channel 125 tx mask\n" );
@@ -349,7 +339,8 @@ status_lorawan_t region_us_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
return OKLORAWAN;
}
-status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_us_915_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
// if all channels were used -> reset the 500Kz snapshots
if( ( SMTC_ARE_CLR_BYTE8( snapshot_channel_tx_mask, BANK_8_500_US915 ) == true ) &&
@@ -373,8 +364,8 @@ status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
( snapshot_channel_tx_mask[BANK_8_500_US915] == 0 ) ) &&
( first_ch_mask_received == ch_mask_after_join_56ch ) )
{
- memset1( unwrapped_channel_mask, 0xFF, const_number_of_channel_bank );
- region_us_915_set_channel_mask( lr1_mac );
+ memset1( unwrapped_channel_mask, 0xFF, real_const.const_number_of_channel_bank );
+ region_us_915_set_channel_mask( real );
}
// If (all 125KHz channels OR all 500Khz channels) were used in 8 channels phases without received a ChMash
@@ -383,7 +374,7 @@ status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
( snapshot_channel_tx_mask[BANK_8_500_US915] == 0 ) ) &&
( first_ch_mask_received <= ch_mask_after_join_8ch ) )
{
- region_us_915_init_after_join_snapshot_channel_mask( lr1_mac );
+ region_us_915_init_after_join_snapshot_channel_mask( real, tx_data_rate, *out_tx_frequency );
}
// Seach all active channels and put in array to be randomly select
@@ -393,7 +384,7 @@ status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
{
if( ( SMTC_GET_BIT8( snapshot_channel_tx_mask, i ) == CHANNEL_ENABLED ) &&
( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED ) &&
- ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 ) )
+ ( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 ) )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -417,8 +408,8 @@ status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
// Mask the channel used, to be remove for the next selection
SMTC_PUT_BIT8( snapshot_channel_tx_mask, channel_idx, CHANNEL_DISABLED );
- lr1_mac->tx_frequency = region_us_915_get_tx_frequency_channel( lr1_mac, channel_idx );
- lr1_mac->rx1_frequency = region_us_915_get_rx1_frequency_channel( lr1_mac, channel_idx );
+ *out_tx_frequency = region_us_915_get_tx_frequency_channel( real, channel_idx );
+ *out_rx1_frequency = region_us_915_get_rx1_frequency_channel( real, channel_idx );
#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
SMTC_MODEM_HAL_TRACE_PRINTF( "snapshot channel 125 tx mask\n" );
@@ -438,35 +429,21 @@ status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac )
return OKLORAWAN;
}
-void region_us_915_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_us_915[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_us_915_set_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_us_915_set_channel_mask( smtc_real_t* real )
{
- region_us_915_channel_mask_set_after_join( lr1_mac );
+ region_us_915_channel_mask_set_after_join( real );
first_ch_mask_received = ch_mask_after_join_full;
}
-void region_us_915_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_us_915_init_join_snapshot_channel_mask( smtc_real_t* real )
{
memset1( snapshot_channel_tx_mask, 0xFF, BANK_MAX_US915 );
snapshot_bank_tx_mask = 0;
}
-void region_us_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void region_us_915_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t tx_frequency )
{
us_915_channels_bank_t ch_mask_block = 0;
@@ -477,7 +454,7 @@ void region_us_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
uint8_t tx_sf;
lr1mac_bandwidth_t tx_bw;
- region_us_915_lora_dr_to_sf_bw( lr1_mac->tx_data_rate, &tx_sf, &tx_bw );
+ region_us_915_lora_dr_to_sf_bw( tx_data_rate, &tx_sf, &tx_bw );
/**
* Important remark:
@@ -494,14 +471,14 @@ void region_us_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
{
// Search the corresponding block of channels used by the last Tx frequency
ch_mask_block = ( us_915_channels_bank_t )(
- ( lr1_mac->tx_frequency - DEFAULT_TX_FREQ_125_START_US_915 ) /
+ ( tx_frequency - DEFAULT_TX_FREQ_125_START_US_915 ) /
( DEFAULT_TX_STEP_125_US_915 << 3 ) ); // 1600000 = 8 ch * 200000 MHz, the gap in each block
}
else if( tx_bw == BW500 )
{
// Search the corresponding channel used by the last Tx frequency in block of 500Khz channels
ch_mask_block = ( us_915_channels_bank_t )(
- ( ( lr1_mac->tx_frequency - DEFAULT_TX_FREQ_500_START_US_915 ) / DEFAULT_TX_STEP_500_US_915 ) % 8 );
+ ( ( tx_frequency - DEFAULT_TX_FREQ_500_START_US_915 ) / DEFAULT_TX_STEP_500_US_915 ) % 8 );
}
else
{
@@ -540,11 +517,10 @@ void region_us_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_m
}
// Apply computed channel mask after join
- region_us_915_channel_mask_set_after_join( lr1_mac );
+ region_us_915_channel_mask_set_after_join( real );
}
-status_channel_t region_us_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_us_915_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
SMTC_MODEM_HAL_TRACE_PRINTF( "ChCtrl = 0x%u, ChMask = 0x%04x\n", channel_mask_cntl, channel_mask );
@@ -569,10 +545,12 @@ status_channel_t region_us_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
if( ( ( channel_mask >> i ) & 0x01 ) == CHANNEL_ENABLED )
{
unwrapped_channel_mask[i] = 0xFF;
+ SMTC_PUT_BIT8( &unwrapped_channel_mask[BANK_8_500_US915], i, CHANNEL_ENABLED );
}
else
{
unwrapped_channel_mask[i] = 0x00;
+ SMTC_PUT_BIT8( &unwrapped_channel_mask[BANK_8_500_US915], i, CHANNEL_DISABLED );
}
}
@@ -599,10 +577,10 @@ status_channel_t region_us_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
}
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) &&
- ( region_us_915_get_tx_frequency_channel( lr1_mac, i ) == 0 ) )
+ ( region_us_915_get_tx_frequency_channel( real, i ) == 0 ) )
{
status = ERROR_CHANNEL_MASK; // this status is used only for the last multiple link adr req
break; // break for loop
@@ -628,7 +606,7 @@ status_channel_t region_us_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uin
return ( status );
}
-void region_us_915_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void region_us_915_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
// Tx 125 kHz channels
for( uint8_t i = 0; i < NUMBER_OF_TX_CHANNEL_US_915 - 8; i++ )
@@ -687,11 +665,11 @@ void region_us_915_lr_fhss_dr_to_cr_bw( uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
}
}
-uint32_t region_us_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_us_915_get_tx_frequency_channel( smtc_real_t* real, uint8_t index )
{
uint32_t freq = 0;
// 500KHz channels
- if( index >= const_number_of_tx_channel - 8 )
+ if( index >= real_const.const_number_of_tx_channel - 8 )
{
freq = DEFAULT_TX_FREQ_500_START_US_915 + ( ( index % 8 ) * DEFAULT_TX_STEP_500_US_915 );
}
@@ -703,20 +681,19 @@ uint32_t region_us_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8
return freq;
}
-uint32_t region_us_915_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index )
+uint32_t region_us_915_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index )
{
return ( DEFAULT_RX_FREQ_500_START_US_915 +
( ( index % NUMBER_OF_RX_CHANNEL_US_915 ) * DEFAULT_RX_STEP_500_US_915 ) );
}
-uint32_t region_us_915_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s )
+uint32_t region_us_915_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s )
{
uint8_t index = ( uint32_t )( floorf( gps_time_s / 128 ) ) % 8;
return ( BEACON_FREQ_START_US_915 + ( index * BEACON_STEP_US_915 ) );
}
-uint32_t region_us_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr )
+uint32_t region_us_915_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr )
{
uint8_t index = ( dev_addr + ( uint32_t )( floorf( gps_time_s / 128 ) ) ) % 8;
return ( PING_SLOT_FREQ_START_US_915 + ( index * PING_SLOT_STEP_US_915 ) );
@@ -727,7 +704,7 @@ uint32_t region_us_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
*/
-static void region_us_915_channel_mask_set_after_join( lr1_stack_mac_t* lr1_mac )
+static void region_us_915_channel_mask_set_after_join( smtc_real_t* real )
{
// Copy all unwrapped channels in channel enable and in snapshot
memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_US915 );
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.h
index ff75733..2aedf94 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915.h
@@ -72,82 +72,77 @@ extern "C" {
*/
/**
- * @brief Congigure the region with default value and pointers
+ * @brief Initialize the region with default value and pointers
*
- * @param lr1_mac
+ * @param real
*/
-void region_us_915_config( lr1_stack_mac_t* lr1_mac );
+void region_us_915_init( smtc_real_t* real );
/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_us_915_init( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
+ * \brief Configure the region
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_us_915_get_next_channel( lr1_stack_mac_t* lr1_mac );
+void region_us_915_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_us_915_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_us_915_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_us_915_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_lorawan_t region_us_915_get_join_next_channel( smtc_real_t* real, uint8_t* out_tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_us_915_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_us_915_set_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_us_915_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_us_915_init_join_snapshot_channel_mask( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_us_915_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+void region_us_915_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t tx_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_channel_t region_us_915_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+status_channel_t region_us_915_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_us_915_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_us_915_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_us_915_is_acceptable_tx_dr( lr1_stack_mac_t* lr1_mac, uint8_t dr,
- bool is_ch_mask_from_link_adr );
+status_lorawan_t region_us_915_is_acceptable_tx_dr( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr );
/**
* @brief Get the corresponding RF modulation from a Datarate
@@ -181,34 +176,33 @@ void region_us_915_lr_fhss_dr_to_cr_bw( uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_us_915_get_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_us_915_get_tx_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint32_t region_us_915_get_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t region_us_915_get_rx1_frequency_channel( smtc_real_t* real, uint8_t index );
/**
* @brief Get the beacon frequency corresponding to a gps_time
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @return uint32_t
*/
-uint32_t region_us_915_get_rx_beacon_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s );
+uint32_t region_us_915_get_rx_beacon_frequency_channel( smtc_real_t* real, uint32_t gps_time_s );
/**
* @brief Get the ping slot frequency corresponding to a gps_time and Dev Address
*
- * @param lr1_mac
+ * @param real
* @param gps_time_s
* @param dev_addr
* @return uint32_t
*/
-uint32_t region_us_915_get_rx_ping_slot_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s,
- uint32_t dev_addr );
+uint32_t region_us_915_get_rx_ping_slot_frequency_channel( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr );
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h
index 1d47292..8aecd9e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_us_915_defs.h
@@ -185,7 +185,7 @@ static const uint8_t datarate_offsets_us_915[7][4] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_us_915[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c
index e371e3a..c0cc6ab 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.c
@@ -47,15 +47,16 @@
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define real_ctx lr1_mac->real->real_ctx
+#define real_ctx real->real_ctx
+#define real_const real->real_const
-#define tx_frequency_channel lr1_mac->real->region.ww2g4.tx_frequency_channel
-#define rx1_frequency_channel lr1_mac->real->region.ww2g4.rx1_frequency_channel
-#define dr_bitfield_tx_channel lr1_mac->real->region.ww2g4.dr_bitfield_tx_channel
-#define channel_index_enabled lr1_mac->real->region.ww2g4.channel_index_enabled
-#define dr_distribution_init lr1_mac->real->region.ww2g4.dr_distribution_init
-#define dr_distribution lr1_mac->real->region.ww2g4.dr_distribution
-#define unwrapped_channel_mask lr1_mac->real->region.ww2g4.unwrapped_channel_mask
+#define tx_frequency_channel real->region.ww2g4.tx_frequency_channel
+#define rx1_frequency_channel real->region.ww2g4.rx1_frequency_channel
+#define dr_bitfield_tx_channel real->region.ww2g4.dr_bitfield_tx_channel
+#define channel_index_enabled real->region.ww2g4.channel_index_enabled
+#define dr_distribution_init real->region.ww2g4.dr_distribution_init
+#define dr_distribution real->region.ww2g4.dr_distribution
+#define unwrapped_channel_mask real->region.ww2g4.unwrapped_channel_mask
/*
* -----------------------------------------------------------------------------
@@ -82,56 +83,57 @@
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
-void region_ww2g4_config( lr1_stack_mac_t* lr1_mac )
+void region_ww2g4_init( smtc_real_t* real )
{
- const_number_of_tx_channel = NUMBER_OF_CHANNEL_WW2G4;
- const_number_of_rx_channel = NUMBER_OF_CHANNEL_WW2G4;
- const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_WW2G4;
- const_number_of_channel_bank = BANK_MAX_WW2G4;
- const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_WW2G4;
- const_received_delay1 = RECEIVE_DELAY1_WW2G4;
- const_tx_power_dbm = TX_POWER_EIRP_WW2G4 - 2; // EIRP to ERP
- const_max_tx_power_idx = MAX_TX_POWER_IDX_WW2G4;
- const_adr_ack_limit = ADR_ACK_LIMIT_WW2G4;
- const_adr_ack_delay = ADR_ACK_DELAY_WW2G4;
- const_datarate_backoff = &datarate_backoff_ww2g4[0];
- const_ack_timeout = ACK_TIMEOUT_WW2G4;
- const_freq_min = FREQMIN_WW2G4;
- const_freq_max = FREQMAX_WW2G4;
- const_rx2_freq = RX2_FREQ_WW2G4;
- const_frequency_factor = FREQUENCY_FACTOR_WW2G4;
- const_rx2_dr_init = RX2DR_INIT_WW2G4;
- const_sync_word_private = SYNC_WORD_PRIVATE_WW2G4;
- const_sync_word_public = SYNC_WORD_PUBLIC_WW2G4;
- const_min_tx_dr = MIN_DR_WW2G4;
- const_max_tx_dr = MAX_DR_WW2G4;
- const_min_tx_dr_limit = MIN_TX_DR_LIMIT_WW2G4;
- const_min_rx_dr = MIN_DR_WW2G4;
- const_max_rx_dr = MAX_DR_WW2G4;
- const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_WW2G4;
- const_dr_bitfield = DR_BITFIELD_SUPPORTED_WW2G4;
- const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_WW2G4;
- const_number_of_tx_dr = NUMBER_OF_TX_DR_WW2G4;
- const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_WW2G4;
- const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_WW2G4;
- const_dtc_supported = DTC_SUPPORTED_WW2G4;
- const_lbt_supported = LBT_SUPPORTED_WW2G4;
- const_max_payload_m = &M_ww2g4[0];
- const_coding_rate = RAL_LORA_CR_LI_4_8;
+ real_const.const_number_of_tx_channel = NUMBER_OF_CHANNEL_WW2G4;
+ real_const.const_number_of_rx_channel = NUMBER_OF_CHANNEL_WW2G4;
+ real_const.const_number_of_boot_tx_channel = NUMBER_OF_BOOT_TX_CHANNEL_WW2G4;
+ real_const.const_number_of_channel_bank = BANK_MAX_WW2G4;
+ real_const.const_join_accept_delay1 = JOIN_ACCEPT_DELAY1_WW2G4;
+ real_const.const_received_delay1 = RECEIVE_DELAY1_WW2G4;
+ real_const.const_tx_power_dbm = TX_POWER_EIRP_WW2G4 - 2; // EIRP to ERP
+ real_const.const_max_tx_power_idx = MAX_TX_POWER_IDX_WW2G4;
+ real_const.const_adr_ack_limit = ADR_ACK_LIMIT_WW2G4;
+ real_const.const_adr_ack_delay = ADR_ACK_DELAY_WW2G4;
+ real_const.const_datarate_offsets = &datarate_offsets_ww2g4[0][0];
+ real_const.const_datarate_backoff = &datarate_backoff_ww2g4[0];
+ real_const.const_ack_timeout = ACK_TIMEOUT_WW2G4;
+ real_const.const_freq_min = FREQMIN_WW2G4;
+ real_const.const_freq_max = FREQMAX_WW2G4;
+ real_const.const_rx2_freq = RX2_FREQ_WW2G4;
+ real_const.const_frequency_factor = FREQUENCY_FACTOR_WW2G4;
+ real_const.const_rx2_dr_init = RX2DR_INIT_WW2G4;
+ real_const.const_sync_word_private = SYNC_WORD_PRIVATE_WW2G4;
+ real_const.const_sync_word_public = SYNC_WORD_PUBLIC_WW2G4;
+ real_const.const_min_tx_dr = MIN_DR_WW2G4;
+ real_const.const_max_tx_dr = MAX_DR_WW2G4;
+ real_const.const_min_tx_dr_limit = MIN_TX_DR_LIMIT_WW2G4;
+ real_const.const_min_rx_dr = MIN_DR_WW2G4;
+ real_const.const_max_rx_dr = MAX_DR_WW2G4;
+ real_const.const_number_rx1_dr_offset = NUMBER_RX1_DR_OFFSET_WW2G4;
+ real_const.const_dr_bitfield = DR_BITFIELD_SUPPORTED_WW2G4;
+ real_const.const_default_tx_dr_bit_field = DEFAULT_TX_DR_BIT_FIELD_WW2G4;
+ real_const.const_number_of_tx_dr = NUMBER_OF_TX_DR_WW2G4;
+ real_const.const_tx_param_setup_req_supported = TX_PARAM_SETUP_REQ_SUPPORTED_WW2G4;
+ real_const.const_new_channel_req_supported = NEW_CHANNEL_REQ_SUPPORTED_WW2G4;
+ real_const.const_dtc_supported = DTC_SUPPORTED_WW2G4;
+ real_const.const_lbt_supported = LBT_SUPPORTED_WW2G4;
+ real_const.const_max_payload_m = &M_ww2g4[0];
+ real_const.const_coding_rate = RAL_LORA_CR_LI_4_8;
#if defined( WW2G4_SINGLE_DATARATE )
- const_join_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
- const_mobile_lowpower_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
- const_mobile_longrange_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_join_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_mobile_lowpower_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_mobile_longrange_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
#else
- const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_WW2G4[0];
- const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_WW2G4[0];
- const_join_dr_distri = &JOIN_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_mobile_longrange_dr_distri = &MOBILE_LONGRANGE_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_mobile_lowpower_dr_distri = &MOBILE_LOWPER_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_join_dr_distri = &JOIN_DR_DISTRIBUTION_WW2G4[0];
#endif
- const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
- const_cf_list_type_supported = CF_LIST_SUPPORTED_WW2G4;
- const_beacon_dr = BEACON_DR_WW2G4;
- const_beacon_frequency = BEACON_FREQ_WW2G4;
- const_ping_slot_frequency = PING_SLOT_FREQ_WW2G4;
+ real_const.const_default_dr_distri = &DEFAULT_DR_DISTRIBUTION_WW2G4[0];
+ real_const.const_cf_list_type_supported = CF_LIST_SUPPORTED_WW2G4;
+ real_const.const_beacon_dr = BEACON_DR_WW2G4;
+ real_const.const_beacon_frequency = BEACON_FREQ_WW2G4;
+ real_const.const_ping_slot_frequency = PING_SLOT_FREQ_WW2G4;
real_ctx.tx_frequency_channel_ctx = &tx_frequency_channel[0];
real_ctx.rx1_frequency_channel_ctx = &rx1_frequency_channel[0];
@@ -141,11 +143,11 @@ void region_ww2g4_config( lr1_stack_mac_t* lr1_mac )
real_ctx.dr_distribution_init_ctx = &dr_distribution_init[0];
real_ctx.dr_distribution_ctx = &dr_distribution[0];
- memset1( dr_distribution_init, 1, const_number_of_tx_dr );
- memset1( dr_distribution, 0, const_number_of_tx_dr );
+ memset1( dr_distribution_init, 1, real_const.const_number_of_tx_dr );
+ memset1( dr_distribution, 0, real_const.const_number_of_tx_dr );
}
-void region_ww2g4_init( lr1_stack_mac_t* lr1_mac )
+void region_ww2g4_config( smtc_real_t* real )
{
for( uint8_t i = 0; i < NUMBER_OF_CHANNEL_WW2G4; i++ )
{
@@ -154,11 +156,11 @@ void region_ww2g4_init( lr1_stack_mac_t* lr1_mac )
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_DISABLED );
// Enable default datarate for all channels
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
// Set Tx/Rx default Freq and enable channels
- for( uint8_t i = 0; i < const_number_of_boot_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_boot_tx_channel; i++ )
{
tx_frequency_channel[i] = default_freq_ww2g4[i];
rx1_frequency_channel[i] = default_freq_ww2g4[i];
@@ -169,21 +171,23 @@ void region_ww2g4_init( lr1_stack_mac_t* lr1_mac )
memset1( &unwrapped_channel_mask[0], 0xFF, BANK_MAX_WW2G4 );
}
-status_lorawan_t region_ww2g4_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_ww2g4_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- return region_ww2g4_get_next_channel( lr1_mac );
+ return region_ww2g4_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
-status_lorawan_t region_ww2g4_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t region_ww2g4_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency )
{
uint8_t active_channel_nb = 0;
uint8_t active_channel_index[NUMBER_OF_CHANNEL_WW2G4];
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_ENABLED )
{
- if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], lr1_mac->tx_data_rate ) == 1 )
+ if( SMTC_GET_BIT16( &dr_bitfield_tx_channel[i], tx_data_rate ) == 1 )
{
active_channel_index[active_channel_nb] = i;
active_channel_nb++;
@@ -198,48 +202,20 @@ status_lorawan_t region_ww2g4_get_next_channel( lr1_stack_mac_t* lr1_mac )
uint8_t temp = ( smtc_modem_hal_get_random_nb_in_range( 0, ( active_channel_nb - 1 ) ) ) % active_channel_nb;
uint8_t channel_idx = 0;
channel_idx = active_channel_index[temp];
- if( channel_idx >= const_number_of_tx_channel )
+ if( channel_idx >= real_const.const_number_of_tx_channel )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "INVALID CHANNEL active channel = %d and random channel = %d \n",
active_channel_nb, temp );
return ERRORLORAWAN;
}
- lr1_mac->tx_frequency = tx_frequency_channel[channel_idx];
- lr1_mac->rx1_frequency = rx1_frequency_channel[channel_idx];
+ *out_tx_frequency = tx_frequency_channel[channel_idx];
+ *out_rx1_frequency = rx1_frequency_channel[channel_idx];
return OKLORAWAN;
}
-void region_ww2g4_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
-{
- if( type == RX1 )
- {
- lr1_mac->rx_data_rate = datarate_offsets_ww2g4[lr1_mac->tx_data_rate][lr1_mac->rx1_dr_offset];
- }
- else if( type == RX2 )
- {
- lr1_mac->rx_data_rate = lr1_mac->rx2_data_rate;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "INVALID RX TYPE \n" );
- }
-}
-void region_ww2g4_set_channel_mask( lr1_stack_mac_t* lr1_mac )
-{
- // Copy all unwrapped channels in channel enable
- memcpy1( channel_index_enabled, unwrapped_channel_mask, BANK_MAX_WW2G4 );
-
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
- {
- SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled, i ) );
- }
- SMTC_MODEM_HAL_TRACE_MSG( " \n" );
-}
-
-status_channel_t region_ww2g4_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t channel_mask_cntl,
- uint16_t channel_mask )
+status_channel_t region_ww2g4_build_channel_mask( smtc_real_t* real, uint8_t channel_mask_cntl, uint16_t channel_mask )
{
status_channel_t status = OKCHANNEL;
switch( channel_mask_cntl )
@@ -248,7 +224,7 @@ status_channel_t region_ww2g4_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint
memcpy1( unwrapped_channel_mask + ( channel_mask_cntl * 2 ), ( uint8_t* ) &channel_mask, 2 );
// Check if all enabled channels has a valid frequency
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( unwrapped_channel_mask, i ) == CHANNEL_ENABLED ) && ( tx_frequency_channel[i] == 0 ) )
{
@@ -266,7 +242,7 @@ status_channel_t region_ww2g4_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint
break;
case 6:
memset1( unwrapped_channel_mask, 0x00, BANK_MAX_WW2G4 );
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( tx_frequency_channel[i] > 0 )
{
@@ -287,14 +263,14 @@ status_channel_t region_ww2g4_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint
return ( status );
}
-void region_ww2g4_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void region_ww2g4_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( tx_frequency_channel[i] != 0 ) && ( SMTC_GET_BIT8( channel_index_enabled, i ) == CHANNEL_DISABLED ) )
{
SMTC_PUT_BIT8( channel_index_enabled, i, CHANNEL_ENABLED );
- dr_bitfield_tx_channel[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel[i] = real_const.const_default_tx_dr_bit_field;
}
}
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.h
index c9cef43..66416b8 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4.h
@@ -72,67 +72,55 @@ extern "C" {
*/
/**
- * @brief Congigure the region with default value and pointers
+ * @brief Initialize the region with default value and pointers
*
- * @param lr1_mac
+ * @param real
*/
-void region_ww2g4_config( lr1_stack_mac_t* lr1_mac );
+void region_ww2g4_init( smtc_real_t* real );
/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-void region_ww2g4_init( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
- * \remark
- * \param [IN] none
- * \param [OUT] return
- */
-status_lorawan_t region_ww2g4_get_next_channel( lr1_stack_mac_t* lr1_mac );
-/**
- * \brief
+ * \brief Configure the region
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t region_ww2g4_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+void region_ww2g4_config( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ww2g4_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+status_lorawan_t region_ww2g4_get_next_channel( smtc_real_t* real, uint8_t tx_data_rate, uint32_t* out_tx_frequency,
+ uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ww2g4_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t region_ww2g4_get_join_next_channel( smtc_real_t* real, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-status_channel_t region_ww2g4_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ChMaskCntl, uint16_t ChMask );
+status_channel_t region_ww2g4_build_channel_mask( smtc_real_t* real, uint8_t ChMaskCntl, uint16_t ChMask );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-void region_ww2g4_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void region_ww2g4_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* \brief
* \remark
* \param [IN] none
* \param [OUT] return
*/
-uint8_t region_ww2g4_get_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint8_t region_ww2g4_get_channel_enabled( smtc_real_t* real, uint8_t index );
/**
* @brief Get the corresponding RF modulation from a Datarate
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h
index 9251ad6..448a368 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/region_ww2g4_defs.h
@@ -147,7 +147,7 @@ static const uint8_t datarate_offsets_ww2g4[8][6] = {
};
/**
- * @brief uplink darate backoff
+ * @brief uplink datarate backoff
*
*/
static const uint8_t datarate_backoff_ww2g4[] = {
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c
index a14a463..ac685b2 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.c
@@ -81,14 +81,22 @@
#error "Unknown region selected..."
#endif
-#define tx_frequency_channel_ctx lr1_mac->real->real_ctx.tx_frequency_channel_ctx
-#define rx1_frequency_channel_ctx lr1_mac->real->real_ctx.rx1_frequency_channel_ctx
-#define channel_index_enabled_ctx lr1_mac->real->real_ctx.channel_index_enabled_ctx
-#define unwrapped_channel_mask_ctx lr1_mac->real->real_ctx.unwrapped_channel_mask_ctx
-#define dr_bitfield_tx_channel_ctx lr1_mac->real->real_ctx.dr_bitfield_tx_channel_ctx
-#define dr_distribution_init_ctx lr1_mac->real->real_ctx.dr_distribution_init_ctx
-#define dr_distribution_ctx lr1_mac->real->real_ctx.dr_distribution_ctx
-#define sync_word_ctx lr1_mac->real->real_ctx.sync_word_ctx
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE MACROS-----------------------------------------------------------
+ */
+#define real_ctx real->real_ctx
+#define real_const real->real_const
+
+#define tx_frequency_channel_ctx real_ctx.tx_frequency_channel_ctx
+#define rx1_frequency_channel_ctx real_ctx.rx1_frequency_channel_ctx
+#define channel_index_enabled_ctx real_ctx.channel_index_enabled_ctx
+#define unwrapped_channel_mask_ctx real_ctx.unwrapped_channel_mask_ctx
+#define dr_bitfield_tx_channel_ctx real_ctx.dr_bitfield_tx_channel_ctx
+#define dr_distribution_init_ctx real_ctx.dr_distribution_init_ctx
+#define dr_distribution_ctx real_ctx.dr_distribution_ctx
+#define uplink_dwell_time_ctx real_ctx.uplink_dwell_time_ctx
+#define downlink_dwell_time_ctx real_ctx.downlink_dwell_time_ctx
smtc_real_status_t smtc_real_is_supported_region( smtc_real_region_types_t region_type )
{
@@ -104,87 +112,90 @@ smtc_real_status_t smtc_real_is_supported_region( smtc_real_region_types_t regio
return SMTC_REAL_STATUS_UNSUPPORTED_FEATURE;
}
-void smtc_real_config( lr1_stack_mac_t* lr1_mac )
+void smtc_real_init( smtc_real_t* real, smtc_real_region_types_t region_type )
{
- // Init duty-cycle object
- smtc_duty_cycle_init( lr1_mac->dtc_obj );
+ if( smtc_real_is_supported_region( region_type ) != SMTC_REAL_STATUS_OK )
+ {
+ smtc_modem_hal_lr1mac_panic( );
+ }
+ real->region_type = region_type;
- // Init all const_xxx to 0
- memset( &( lr1_mac->real->real_const ), 0, sizeof( smtc_real_const_t ) );
+ // Init all real_const.const_xxx to 0
+ memset( &( real_const ), 0, sizeof( smtc_real_const_t ) );
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
- region_ww2g4_config( lr1_mac );
+ region_ww2g4_init( real );
break;
}
#endif
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
- region_eu_868_config( lr1_mac );
+ region_eu_868_init( real );
break;
}
#endif
#if defined( REGION_AS_923 )
case SMTC_REAL_REGION_AS_923: {
- region_as_923_config( lr1_mac, 1 );
+ region_as_923_init( real, 1 );
break;
}
case SMTC_REAL_REGION_AS_923_GRP2: {
- region_as_923_config( lr1_mac, 2 );
+ region_as_923_init( real, 2 );
break;
}
case SMTC_REAL_REGION_AS_923_GRP3: {
- region_as_923_config( lr1_mac, 3 );
+ region_as_923_init( real, 3 );
break;
}
#if defined( RP2_103 )
case SMTC_REAL_REGION_AS_923_GRP4: {
- region_as_923_config( lr1_mac, 4 );
+ region_as_923_init( real, 4 );
break;
}
#endif
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- region_us_915_config( lr1_mac );
+ region_us_915_init( real );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- region_au_915_config( lr1_mac );
+ region_au_915_init( real );
break;
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- region_cn_470_config( lr1_mac );
+ region_cn_470_init( real );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- region_cn_470_rp_1_0_config( lr1_mac );
+ region_cn_470_rp_1_0_init( real );
break;
}
#endif
#if defined( REGION_IN_865 )
case SMTC_REAL_REGION_IN_865: {
- region_in_865_config( lr1_mac );
+ region_in_865_init( real );
break;
}
#endif
#if defined( REGION_KR_920 )
case SMTC_REAL_REGION_KR_920: {
- region_kr_920_config( lr1_mac );
+ region_kr_920_init( real );
break;
}
#endif
#if defined( REGION_RU_864 )
case SMTC_REAL_REGION_RU_864: {
- region_ru_864_config( lr1_mac );
+ region_ru_864_init( real );
break;
}
#endif
@@ -192,52 +203,23 @@ void smtc_real_config( lr1_stack_mac_t* lr1_mac )
smtc_modem_hal_lr1mac_panic( );
break;
}
- smtc_lbt_init( lr1_mac->lbt_obj, lr1_mac->rp, RP_HOOK_ID_LBT,
- ( void ( * )( void* ) ) lr1_stack_mac_tx_radio_free_lbt, lr1_mac,
- ( void ( * )( void* ) ) lr1_stack_mac_radio_busy_lbt, lr1_mac,
- ( void ( * )( void* ) ) lr1_stack_mac_radio_abort_lbt, lr1_mac );
- if( const_lbt_supported == true )
- {
- smtc_lbt_set_parameters( lr1_mac->lbt_obj, smtc_real_get_lbt_duration_ms( lr1_mac ),
- smtc_real_get_lbt_threshold_dbm( lr1_mac ), smtc_real_get_lbt_bw_hz( lr1_mac ) );
- smtc_lbt_set_state( lr1_mac->lbt_obj, true );
- }
- smtc_duty_cycle_enable_set( lr1_mac->dtc_obj, const_dtc_supported );
-
- sync_word_ctx = const_sync_word_public;
+ real_ctx.sync_word_ctx = real_const.const_sync_word_public;
}
-void smtc_real_init( lr1_stack_mac_t* lr1_mac )
+void smtc_real_config( smtc_real_t* real )
{
- lr1_mac->rx2_frequency = const_rx2_freq;
- lr1_mac->tx_power = const_tx_power_dbm;
- lr1_mac->max_erp_dbm = const_tx_power_dbm;
- lr1_mac->rx1_dr_offset = 0;
- lr1_mac->rx2_data_rate = const_rx2_dr_init;
- lr1_mac->rx1_delay_s = const_received_delay1;
- lr1_mac->tx_data_rate_adr = const_min_tx_dr_limit;
-
- lr1_mac->uplink_dwell_time = 0;
- lr1_mac->downlink_dwell_time = 0;
-
- // If 0 the beacon of the region is used, else this freq is used even if the beacon must be hopping
- lr1_mac->beacon_freq_hz = 0;
-
- lr1_mac->ping_slot_dr = const_beacon_dr;
- lr1_mac->ping_slot_periodicity_req = SMTC_REAL_PING_SLOT_PERIODICITY_DEFAULT;
-
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
- region_ww2g4_init( lr1_mac );
+ region_ww2g4_config( real );
break;
}
#endif
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
- region_eu_868_init( lr1_mac );
+ region_eu_868_config( real );
break;
}
#endif
@@ -249,49 +231,49 @@ void smtc_real_init( lr1_stack_mac_t* lr1_mac )
case SMTC_REAL_REGION_AS_923_GRP4:
#endif
{
- region_as_923_init( lr1_mac );
+ region_as_923_config( real );
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- region_us_915_init( lr1_mac );
+ region_us_915_config( real );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- region_au_915_init( lr1_mac );
+ region_au_915_config( real );
break;
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- region_cn_470_init( lr1_mac );
+ region_cn_470_config( real );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- region_cn_470_rp_1_0_init( lr1_mac );
+ region_cn_470_rp_1_0_config( real );
break;
}
#endif
#if defined( REGION_IN_865 )
case SMTC_REAL_REGION_IN_865: {
- region_in_865_init( lr1_mac );
+ region_in_865_config( real );
break;
}
#endif
#if defined( REGION_KR_920 )
case SMTC_REAL_REGION_KR_920: {
- region_kr_920_init( lr1_mac );
+ region_kr_920_config( real );
break;
}
#endif
#if defined( REGION_RU_864 )
case SMTC_REAL_REGION_RU_864: {
- region_ru_864_init( lr1_mac );
+ region_ru_864_config( real );
break;
}
#endif
@@ -299,11 +281,14 @@ void smtc_real_init( lr1_stack_mac_t* lr1_mac )
smtc_modem_hal_lr1mac_panic( );
break;
}
+
+ uplink_dwell_time_ctx = real_const.const_uplink_dwell_time;
+ downlink_dwell_time_ctx = false;
}
-void smtc_real_init_session( lr1_stack_mac_t* lr1_mac )
+void smtc_real_config_session( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -343,7 +328,7 @@ void smtc_real_init_session( lr1_stack_mac_t* lr1_mac )
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- region_cn_470_init_session( lr1_mac );
+ region_cn_470_config_session( real );
break;
}
#endif
@@ -359,130 +344,134 @@ void smtc_real_init_session( lr1_stack_mac_t* lr1_mac )
}
}
-void smtc_real_set_dr_distribution( lr1_stack_mac_t* lr1_mac, uint8_t adr_mode )
+void smtc_real_set_dr_distribution( smtc_real_t* real, uint8_t adr_mode, uint8_t* out_nb_trans, uint32_t* adr_custom )
{
switch( adr_mode )
{
case MOBILE_LONGRANGE_DR_DISTRIBUTION:
#if !defined( HYBRID_CN470_MONO_CHANNEL )
- memcpy( dr_distribution_init_ctx, const_mobile_longrange_dr_distri, const_number_of_tx_dr );
- memcpy( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
- lr1_mac->nb_trans = 3;
+ memcpy( dr_distribution_init_ctx, real_const.const_mobile_longrange_dr_distri,
+ real_const.const_number_of_tx_dr );
+ memcpy( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
+ *out_nb_trans = 3;
break;
#endif
case MOBILE_LOWPER_DR_DISTRIBUTION:
#if !defined( HYBRID_CN470_MONO_CHANNEL )
- memcpy( dr_distribution_init_ctx, const_mobile_lowpower_dr_distri, const_number_of_tx_dr );
- memcpy( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
- lr1_mac->nb_trans = 3;
+ memcpy( dr_distribution_init_ctx, real_const.const_mobile_lowpower_dr_distri,
+ real_const.const_number_of_tx_dr );
+ memcpy( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
+ *out_nb_trans = 3;
break;
#endif
case JOIN_DR_DISTRIBUTION:
#if !defined( HYBRID_CN470_MONO_CHANNEL )
- memcpy( dr_distribution_init_ctx, const_join_dr_distri, const_number_of_tx_dr );
- memcpy( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
- lr1_mac->nb_trans = 1;
+ memcpy( dr_distribution_init_ctx, real_const.const_join_dr_distri, real_const.const_number_of_tx_dr );
+ memcpy( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
+ *out_nb_trans = 1;
break;
#endif
case USER_DR_DISTRIBUTION:
- for( uint8_t i = 0; i < const_number_of_tx_dr; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_dr; i++ )
{
if( i < 8 )
- dr_distribution_init_ctx[i] = ( lr1_mac->adr_custom[0] >> ( ( 7 - i ) * 4 ) ) & 0x0F;
+ dr_distribution_init_ctx[i] = ( adr_custom[0] >> ( ( 7 - i ) * 4 ) ) & 0x0F;
else
{
uint8_t tmpi = i % 8;
- dr_distribution_init_ctx[i] = ( lr1_mac->adr_custom[1] >> ( ( 7 - tmpi ) * 4 ) ) & 0x0F;
+ dr_distribution_init_ctx[i] = ( adr_custom[1] >> ( ( 7 - tmpi ) * 4 ) ) & 0x0F;
}
}
- memcpy( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
- lr1_mac->nb_trans = BSP_USER_NUMBER_OF_RETRANSMISSION;
+ memcpy( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
+ *out_nb_trans = BSP_USER_NUMBER_OF_RETRANSMISSION;
break;
default:
- memcpy( dr_distribution_init_ctx, const_default_dr_distri, const_number_of_tx_dr );
- memcpy( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
- lr1_mac->nb_trans = 1;
+ memcpy( dr_distribution_init_ctx, real_const.const_default_dr_distri, real_const.const_number_of_tx_dr );
+ memcpy( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
+ *out_nb_trans = 1;
break;
}
}
-status_lorawan_t smtc_real_get_next_dr( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t smtc_real_get_next_tx_dr( smtc_real_t* real, join_status_t join_status, dr_strategy_t* adr_mode_select,
+ uint8_t* tx_data_rate, uint8_t tx_data_rate_adr, bool* adr_enable )
{
for( int j = 0; j < 224; j++ ) // return error after 224 trials
{
- if( ( lr1_mac->adr_mode_select == STATIC_ADR_MODE ) && ( lr1_mac->join_status == JOINED ) )
+ if( ( *adr_mode_select == STATIC_ADR_MODE ) && ( join_status == JOINED ) )
{
- if( lr1_mac->uplink_dwell_time == true )
+ if( uplink_dwell_time_ctx == true )
{
- lr1_mac->tx_data_rate = ( lr1_mac->tx_data_rate_adr < const_min_tx_dr_limit )
- ? const_min_tx_dr_limit
- : lr1_mac->tx_data_rate_adr;
+ *tx_data_rate = ( tx_data_rate_adr < real_const.const_min_tx_dr_limit )
+ ? real_const.const_min_tx_dr_limit
+ : tx_data_rate_adr;
}
else
{
- lr1_mac->tx_data_rate = lr1_mac->tx_data_rate_adr;
+ *tx_data_rate = tx_data_rate_adr;
}
- lr1_mac->adr_enable = 1;
+ *adr_enable = 1;
}
else
{
uint8_t distri_sum = 0;
- for( uint8_t i = 0; i < const_number_of_tx_dr; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_dr; i++ )
{
distri_sum += dr_distribution_ctx[i];
}
if( distri_sum == 0 )
{
- memcpy1( dr_distribution_ctx, dr_distribution_init_ctx, const_number_of_tx_dr );
+ memcpy1( dr_distribution_ctx, dr_distribution_init_ctx, real_const.const_number_of_tx_dr );
}
// Watchdog protection and dr_distribution_ctx is checked in for loop few line above
uint8_t new_dr = 0;
do
{
- new_dr = ( smtc_modem_hal_get_random_nb_in_range( const_min_tx_dr, const_max_tx_dr ) %
- ( const_max_tx_dr + 1 ) );
+ new_dr =
+ ( smtc_modem_hal_get_random_nb_in_range( real_const.const_min_tx_dr, real_const.const_max_tx_dr ) %
+ ( real_const.const_max_tx_dr + 1 ) );
} while( dr_distribution_ctx[new_dr] == 0 );
- lr1_mac->tx_data_rate = new_dr;
+ *tx_data_rate = new_dr;
dr_distribution_ctx[new_dr]--;
- lr1_mac->adr_enable = 0;
+ *adr_enable = 0;
}
- lr1_mac->tx_data_rate = ( lr1_mac->tx_data_rate > const_max_tx_dr ) ? const_max_tx_dr : lr1_mac->tx_data_rate;
+ *tx_data_rate = ( *tx_data_rate > real_const.const_max_tx_dr ) ? real_const.const_max_tx_dr : *tx_data_rate;
- uint16_t dr_tmp = smtc_real_mask_tx_dr_channel_up_dwell_time_check( lr1_mac );
- if( SMTC_GET_BIT16( &dr_tmp, lr1_mac->tx_data_rate ) == 1 )
+ uint16_t dr_tmp = smtc_real_mask_tx_dr_channel_up_dwell_time_check( real );
+ if( SMTC_GET_BIT16( &dr_tmp, *tx_data_rate ) == 1 )
{
return OKLORAWAN;
}
}
// No valid custom ADR found, force ADR to network controlled
- lr1_mac->adr_mode_select = STATIC_ADR_MODE;
- if( lr1_mac->uplink_dwell_time == true )
+ *adr_mode_select = STATIC_ADR_MODE;
+ if( uplink_dwell_time_ctx == true )
{
- lr1_mac->tx_data_rate =
- ( lr1_mac->tx_data_rate_adr < const_min_tx_dr_limit ) ? const_min_tx_dr_limit : lr1_mac->tx_data_rate_adr;
+ *tx_data_rate = ( tx_data_rate_adr < real_const.const_min_tx_dr_limit ) ? real_const.const_min_tx_dr_limit
+ : tx_data_rate_adr;
}
else
{
- lr1_mac->tx_data_rate = lr1_mac->tx_data_rate_adr;
+ *tx_data_rate = tx_data_rate_adr;
}
- lr1_mac->adr_enable = 1;
+ *adr_enable = 1;
return OKLORAWAN;
}
-cf_list_type_t smtc_real_cf_list_type_supported( lr1_stack_mac_t* lr1_mac )
+cf_list_type_t smtc_real_cf_list_type_supported( smtc_real_t* real )
{
- return ( const_cf_list_type_supported );
+ return ( real_const.const_cf_list_type_supported );
}
-status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t smtc_real_update_cflist( smtc_real_t* real, uint8_t* cf_list )
{
status_lorawan_t status = OKLORAWAN;
- cf_list_type_t cf_list_type = lr1_mac->cf_list[15];
+ cf_list_type_t cf_list_type = cf_list[15];
- if( smtc_real_cf_list_type_supported( lr1_mac ) != cf_list_type )
+ if( smtc_real_cf_list_type_supported( real ) != cf_list_type )
{
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID CFList type for this region (%d)\n", cf_list_type );
status = ERRORLORAWAN;
@@ -495,43 +484,46 @@ status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac )
case CF_LIST_FREQ: {
for( uint8_t i = 0; i < 5; i++ )
{
- tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i] =
- smtc_real_decode_freq_from_buf( lr1_mac, &lr1_mac->cf_list[0 + ( 3 * i )] );
- rx1_frequency_channel_ctx[const_number_of_boot_tx_channel + i] =
- tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i];
+ tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] =
+ smtc_real_decode_freq_from_buf( real, &cf_list[0 + ( 3 * i )] );
+ rx1_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] =
+ tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i];
if( smtc_real_is_nwk_received_tx_frequency_valid(
- lr1_mac, tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i] ) == OKLORAWAN &&
- tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i] != 0 )
+ real, tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] ) == OKLORAWAN &&
+ tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] != 0 )
{
// Enable default datarate for all added channels
- dr_bitfield_tx_channel_ctx[const_number_of_boot_tx_channel + i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel_ctx[real_const.const_number_of_boot_tx_channel + i] =
+ real_const.const_default_tx_dr_bit_field;
// Enable Channel
- SMTC_PUT_BIT8( channel_index_enabled_ctx, ( const_number_of_boot_tx_channel + i ),
+ SMTC_PUT_BIT8( channel_index_enabled_ctx, ( real_const.const_number_of_boot_tx_channel + i ),
CHANNEL_ENABLED );
- SMTC_MODEM_HAL_TRACE_PRINTF( "MacTxFrequency [%d] = %d \n", i,
- tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i] );
+ SMTC_MODEM_HAL_TRACE_PRINTF(
+ "MacTxFrequency [%d] = %d \n", i,
+ tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] );
SMTC_MODEM_HAL_TRACE_PRINTF( "MacDataRateChannel [%d] = ", i );
for( uint8_t dr = 0; dr < 16; dr++ )
{
SMTC_MODEM_HAL_TRACE_PRINTF(
" %d",
- SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[const_number_of_boot_tx_channel + i], dr ) );
+ SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[real_const.const_number_of_boot_tx_channel + i],
+ dr ) );
}
SMTC_MODEM_HAL_TRACE_PRINTF( " \n" );
- SMTC_MODEM_HAL_TRACE_PRINTF(
- "MacChannelIndexEnabled [%d] = %d \n", i,
- SMTC_GET_BIT8( channel_index_enabled_ctx, ( const_number_of_boot_tx_channel + i ) ) );
+ SMTC_MODEM_HAL_TRACE_PRINTF( "MacChannelIndexEnabled [%d] = %d \n", i,
+ SMTC_GET_BIT8( channel_index_enabled_ctx,
+ ( real_const.const_number_of_boot_tx_channel + i ) ) );
}
else
{
- tx_frequency_channel_ctx[const_number_of_boot_tx_channel + i] = 0;
- rx1_frequency_channel_ctx[const_number_of_boot_tx_channel + i] = 0;
- SMTC_PUT_BIT8( channel_index_enabled_ctx, ( const_number_of_boot_tx_channel + i ),
+ tx_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] = 0;
+ rx1_frequency_channel_ctx[real_const.const_number_of_boot_tx_channel + i] = 0;
+ SMTC_PUT_BIT8( channel_index_enabled_ctx, ( real_const.const_number_of_boot_tx_channel + i ),
CHANNEL_DISABLED );
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID TX FREQUENCY IN CFLIST OR CFLIST EMPTY \n" );
@@ -540,16 +532,16 @@ status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac )
}
break;
case CF_LIST_CH_MASK: {
- uint8_t ch_mash_i = smtc_real_get_number_of_chmask_in_cflist( lr1_mac );
+ uint8_t ch_mash_i = smtc_real_get_number_of_chmask_in_cflist( real );
status_channel_t channel_status = OKCHANNEL;
uint16_t channel_mask;
- smtc_real_init_channel_mask( lr1_mac );
+ smtc_real_init_channel_mask( real );
for( uint8_t i = 0; i < ch_mash_i; i++ )
{
- channel_mask = lr1_mac->cf_list[0 + ( 2 * i )] + ( lr1_mac->cf_list[1 + ( 2 * i )] << 8 );
- channel_status = smtc_real_build_channel_mask( lr1_mac, i, channel_mask );
+ channel_mask = cf_list[0 + ( 2 * i )] + ( cf_list[1 + ( 2 * i )] << 8 );
+ channel_status = smtc_real_build_channel_mask( real, i, channel_mask );
if( channel_status == ERROR_CHANNEL_CNTL )
{ // Test ChannelCNTL not defined
@@ -565,7 +557,7 @@ status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac )
}
if( channel_status == OKCHANNEL )
{
- smtc_real_set_channel_mask( lr1_mac );
+ smtc_real_set_channel_mask( real );
}
break;
}
@@ -578,9 +570,9 @@ status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac )
return status;
}
-uint8_t smtc_real_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_number_of_chmask_in_cflist( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -624,12 +616,12 @@ uint8_t smtc_real_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_number_of_chmask_in_cflist( lr1_mac );
+ return region_cn_470_get_number_of_chmask_in_cflist( real );
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( lr1_mac );
+ return region_cn_470_rp_1_0_get_number_of_chmask_in_cflist( real );
}
#endif
default:
@@ -639,18 +631,19 @@ uint8_t smtc_real_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac )
return ERRORLORAWAN; // never reach => avoid warning
}
-status_lorawan_t smtc_real_get_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t smtc_real_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
- return region_ww2g4_get_next_channel( lr1_mac );
+ return region_ww2g4_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
- return region_eu_868_get_next_channel( lr1_mac );
+ return region_eu_868_get_next_channel( real, dtc_obj, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_AS_923 )
@@ -661,42 +654,42 @@ status_lorawan_t smtc_real_get_next_channel( lr1_stack_mac_t* lr1_mac )
case SMTC_REAL_REGION_AS_923_GRP4:
#endif
{
- return region_as_923_get_next_channel( lr1_mac );
+ return region_as_923_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_next_channel( lr1_mac );
+ return region_us_915_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_next_channel( lr1_mac );
+ return region_au_915_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_next_channel( lr1_mac );
+ return region_cn_470_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_next_channel( lr1_mac );
+ return region_cn_470_rp_1_0_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_IN_865 )
case SMTC_REAL_REGION_IN_865: {
- return region_in_865_get_next_channel( lr1_mac );
+ return region_in_865_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_KR_920 )
case SMTC_REAL_REGION_KR_920: {
- return region_kr_920_get_next_channel( lr1_mac );
+ return region_kr_920_get_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_RU_864 )
case SMTC_REAL_REGION_RU_864: {
- return region_ru_864_get_next_channel( lr1_mac );
+ return region_ru_864_get_next_channel( real, dtc_obj, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
default:
@@ -706,18 +699,20 @@ status_lorawan_t smtc_real_get_next_channel( lr1_stack_mac_t* lr1_mac )
return ERRORLORAWAN; // never reach => avoid warning
}
-status_lorawan_t smtc_real_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
+status_lorawan_t smtc_real_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t* tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency,
+ uint32_t* out_rx2_frequency )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
- return region_ww2g4_get_join_next_channel( lr1_mac );
+ return region_ww2g4_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
- return region_eu_868_get_join_next_channel( lr1_mac );
+ return region_eu_868_get_join_next_channel( real, dtc_obj, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_AS_923 )
@@ -728,42 +723,43 @@ status_lorawan_t smtc_real_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
case SMTC_REAL_REGION_AS_923_GRP4:
#endif
{
- return region_as_923_get_join_next_channel( lr1_mac );
+ return region_as_923_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_join_next_channel( lr1_mac );
+ return region_us_915_get_join_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_join_next_channel( lr1_mac );
+ return region_au_915_get_join_next_channel( real, tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_join_next_channel( lr1_mac );
+ return region_cn_470_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency,
+ out_rx2_frequency );
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_join_next_channel( lr1_mac );
+ return region_cn_470_rp_1_0_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_IN_865 )
case SMTC_REAL_REGION_IN_865: {
- return region_in_865_get_join_next_channel( lr1_mac );
+ return region_in_865_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_KR_920 )
case SMTC_REAL_REGION_KR_920: {
- return region_kr_920_get_join_next_channel( lr1_mac );
+ return region_kr_920_get_join_next_channel( real, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
#if defined( REGION_RU_864 )
case SMTC_REAL_REGION_RU_864: {
- return region_ru_864_get_join_next_channel( lr1_mac );
+ return region_ru_864_get_join_next_channel( real, dtc_obj, *tx_data_rate, out_tx_frequency, out_rx1_frequency );
}
#endif
default:
@@ -773,111 +769,50 @@ status_lorawan_t smtc_real_get_join_next_channel( lr1_stack_mac_t* lr1_mac )
return ERRORLORAWAN; // never reach => avoid warning
}
-void smtc_real_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type )
+uint8_t smtc_real_get_rx1_datarate_config( smtc_real_t* real, uint8_t tx_data_rate, uint8_t rx1_dr_offset )
{
- switch( lr1_mac->real->region_type )
- {
-#if defined( REGION_WW2G4 )
- case SMTC_REAL_REGION_WW2G4: {
- region_ww2g4_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_EU_868 )
- case SMTC_REAL_REGION_EU_868: {
- region_eu_868_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
+ uint8_t max = real_const.const_number_of_tx_dr * real_const.const_number_rx1_dr_offset;
+ uint8_t index = ( tx_data_rate * real_const.const_number_rx1_dr_offset ) + rx1_dr_offset;
+
+ ;
#if defined( REGION_AS_923 )
- case SMTC_REAL_REGION_AS_923:
- case SMTC_REAL_REGION_AS_923_GRP2:
- case SMTC_REAL_REGION_AS_923_GRP3:
-#if defined( RP2_103 )
- case SMTC_REAL_REGION_AS_923_GRP4:
-#endif
+ if( real->region_type == SMTC_REAL_REGION_AS_923 )
{
- region_as_923_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_US_915 )
- case SMTC_REAL_REGION_US_915: {
- region_us_915_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_AU_915 )
- case SMTC_REAL_REGION_AU_915: {
- region_au_915_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_CN_470 )
- case SMTC_REAL_REGION_CN_470: {
- region_cn_470_set_rx_config( lr1_mac, type );
- break;
+ max *= ( downlink_dwell_time_ctx + 1 );
+ index += ( downlink_dwell_time_ctx * real_const.const_number_of_tx_dr * real_const.const_number_rx1_dr_offset );
}
#endif
-#if defined( REGION_CN_470_RP_1_0 )
- case SMTC_REAL_REGION_CN_470_RP_1_0: {
- region_cn_470_rp_1_0_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_IN_865 )
- case SMTC_REAL_REGION_IN_865: {
- region_in_865_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_KR_920 )
- case SMTC_REAL_REGION_KR_920: {
- region_kr_920_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
-#if defined( REGION_RU_864 )
- case SMTC_REAL_REGION_RU_864: {
- region_ru_864_set_rx_config( lr1_mac, type );
- break;
- }
-#endif
- default:
+
+ if( index >= max )
+ {
smtc_modem_hal_lr1mac_panic( );
- break;
}
+ return real_const.const_datarate_offsets[index];
}
-void smtc_real_set_power( lr1_stack_mac_t* lr1_mac, uint8_t power_cmd )
+int8_t smtc_real_convert_power_cmd( smtc_real_t* real, uint8_t power_cmd, uint8_t max_erp_dbm )
{
- if( power_cmd > const_max_tx_power_idx )
+ if( power_cmd > real_const.const_max_tx_power_idx )
{
- lr1_mac->tx_power = lr1_mac->max_erp_dbm;
+ return max_erp_dbm;
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID %d \n", power_cmd );
}
else
{
- int8_t pwr_tmp = lr1_mac->max_erp_dbm - ( 2 * power_cmd );
- lr1_mac->tx_power = ( pwr_tmp < 0 ) ? 0 : pwr_tmp;
+ int8_t pwr_tmp = max_erp_dbm - ( 2 * power_cmd );
+ return ( pwr_tmp < 0 ) ? 0 : pwr_tmp;
}
}
-void smtc_real_set_channel_mask( lr1_stack_mac_t* lr1_mac )
+void smtc_real_set_channel_mask( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
- case SMTC_REAL_REGION_WW2G4: {
- region_ww2g4_set_channel_mask( lr1_mac );
- break;
- }
+ case SMTC_REAL_REGION_WW2G4:
#endif
#if defined( REGION_EU_868 )
- case SMTC_REAL_REGION_EU_868: {
- region_eu_868_set_channel_mask( lr1_mac );
- break;
- }
+ case SMTC_REAL_REGION_EU_868:
#endif
#if defined( REGION_AS_923 )
case SMTC_REAL_REGION_AS_923:
@@ -886,67 +821,64 @@ void smtc_real_set_channel_mask( lr1_stack_mac_t* lr1_mac )
#if defined( RP2_103 )
case SMTC_REAL_REGION_AS_923_GRP4:
#endif
- {
- region_as_923_set_channel_mask( lr1_mac );
- break;
- }
-#endif
-#if defined( REGION_US_915 )
- case SMTC_REAL_REGION_US_915: {
- region_us_915_set_channel_mask( lr1_mac );
- break;
- }
-#endif
-#if defined( REGION_AU_915 )
- case SMTC_REAL_REGION_AU_915: {
- region_au_915_set_channel_mask( lr1_mac );
- break;
- }
#endif
#if defined( REGION_CN_470 )
- case SMTC_REAL_REGION_CN_470: {
- region_cn_470_set_channel_mask( lr1_mac );
- break;
- }
+ case SMTC_REAL_REGION_CN_470:
#endif
#if defined( REGION_CN_470_RP_1_0 )
- case SMTC_REAL_REGION_CN_470_RP_1_0: {
- region_cn_470_rp_1_0_set_channel_mask( lr1_mac );
- break;
- }
+ case SMTC_REAL_REGION_CN_470_RP_1_0:
#endif
#if defined( REGION_IN_865 )
- case SMTC_REAL_REGION_IN_865: {
- region_in_865_set_channel_mask( lr1_mac );
- break;
- }
+ case SMTC_REAL_REGION_IN_865:
#endif
#if defined( REGION_KR_920 )
- case SMTC_REAL_REGION_KR_920: {
- region_kr_920_set_channel_mask( lr1_mac );
+ case SMTC_REAL_REGION_KR_920:
+#endif
+#if defined( REGION_RU_864 )
+ case SMTC_REAL_REGION_RU_864:
+#endif
+
+#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( RP2_103 ) || \
+ defined( REGION_CN_470 ) || defined( REGION_CN_470_RP_1_0 ) || defined( REGION_IN_865 ) || \
+ defined( REGION_KR_920 ) || defined( REGION_RU_864 )
+ // Copy all unwrapped channels in channel enable
+ memcpy1( channel_index_enabled_ctx, unwrapped_channel_mask_ctx, real_const.const_number_of_channel_bank );
+
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
+ {
+ SMTC_MODEM_HAL_TRACE_PRINTF( " %d ", SMTC_GET_BIT8( channel_index_enabled_ctx, i ) );
+ }
+ SMTC_MODEM_HAL_TRACE_MSG( " \n" );
+ break;
+#endif
+
+#if defined( REGION_US_915 )
+ case SMTC_REAL_REGION_US_915: {
+ region_us_915_set_channel_mask( real );
break;
}
#endif
-#if defined( REGION_RU_864 )
- case SMTC_REAL_REGION_RU_864: {
- region_ru_864_set_channel_mask( lr1_mac );
+#if defined( REGION_AU_915 )
+ case SMTC_REAL_REGION_AU_915: {
+ region_au_915_set_channel_mask( real );
break;
}
#endif
+
default:
smtc_modem_hal_lr1mac_panic( );
break;
}
}
-void smtc_real_init_channel_mask( lr1_stack_mac_t* lr1_mac )
+void smtc_real_init_channel_mask( smtc_real_t* real )
{
- memset1( unwrapped_channel_mask_ctx, 0xFF, const_number_of_channel_bank );
+ memset1( unwrapped_channel_mask_ctx, 0xFF, real_const.const_number_of_channel_bank );
}
-void smtc_real_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void smtc_real_init_join_snapshot_channel_mask( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -987,13 +919,13 @@ void smtc_real_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- region_us_915_init_join_snapshot_channel_mask( lr1_mac );
+ region_us_915_init_join_snapshot_channel_mask( real );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- region_au_915_init_join_snapshot_channel_mask( lr1_mac );
+ region_au_915_init_join_snapshot_channel_mask( real );
break;
}
#endif
@@ -1003,9 +935,9 @@ void smtc_real_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
}
}
-void smtc_real_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
+void smtc_real_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate, uint32_t tx_frequency )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1046,13 +978,13 @@ void smtc_real_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- region_us_915_init_after_join_snapshot_channel_mask( lr1_mac );
+ region_us_915_init_after_join_snapshot_channel_mask( real, tx_data_rate, tx_frequency );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- region_au_915_init_after_join_snapshot_channel_mask( lr1_mac );
+ region_au_915_init_after_join_snapshot_channel_mask( real, tx_data_rate, tx_frequency );
break;
}
#endif
@@ -1062,18 +994,18 @@ void smtc_real_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
}
}
-status_channel_t smtc_real_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ch_mask_cntl, uint16_t ch_mask )
+status_channel_t smtc_real_build_channel_mask( smtc_real_t* real, uint8_t ch_mask_cntl, uint16_t ch_mask )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
- return region_ww2g4_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_ww2g4_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
- return region_eu_868_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_eu_868_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_AS_923 )
@@ -1084,42 +1016,42 @@ status_channel_t smtc_real_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t
case SMTC_REAL_REGION_AS_923_GRP4:
#endif
{
- return region_as_923_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_as_923_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_us_915_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_au_915_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_cn_470_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_cn_470_rp_1_0_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_IN_865 )
case SMTC_REAL_REGION_IN_865: {
- return region_in_865_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_in_865_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_KR_920 )
case SMTC_REAL_REGION_KR_920: {
- return region_kr_920_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_kr_920_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
#if defined( REGION_RU_864 )
case SMTC_REAL_REGION_RU_864: {
- return region_ru_864_build_channel_mask( lr1_mac, ch_mask_cntl, ch_mask );
+ return region_ru_864_build_channel_mask( real, ch_mask_cntl, ch_mask );
}
#endif
default:
@@ -1129,22 +1061,22 @@ status_channel_t smtc_real_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t
return ERROR_CHANNEL; // never reach => avoid warning
}
-uint8_t smtc_real_decrement_dr_simulation( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_decrement_dr_simulation( smtc_real_t* real, uint8_t tx_data_rate_adr )
{
bool is_valid_dr = false;
- uint8_t data_rate_simulation = lr1_mac->tx_data_rate_adr;
+ uint8_t data_rate_simulation = tx_data_rate_adr;
- // while( ( data_rate_simulation > const_min_tx_dr ) && ( is_valid_dr == 0 ) )
- while( data_rate_simulation > const_min_tx_dr )
+ // while( ( data_rate_simulation > real_const.const_min_tx_dr ) && ( is_valid_dr == 0 ) )
+ while( data_rate_simulation > real_const.const_min_tx_dr )
{
- uint8_t index = ( lr1_mac->uplink_dwell_time * const_number_of_tx_dr ) + data_rate_simulation;
- if( index > ( const_max_tx_dr * ( lr1_mac->uplink_dwell_time + 1 ) ) )
+ uint8_t index = ( uplink_dwell_time_ctx * real_const.const_number_of_tx_dr ) + data_rate_simulation;
+ if( index > ( real_const.const_max_tx_dr * ( uplink_dwell_time_ctx + 1 ) ) )
{
smtc_modem_hal_lr1mac_panic( );
}
- data_rate_simulation = const_datarate_backoff[index];
+ data_rate_simulation = real_const.const_datarate_backoff[index];
- if( smtc_real_is_tx_dr_acceptable( lr1_mac, data_rate_simulation, false ) == OKLORAWAN )
+ if( smtc_real_is_tx_dr_acceptable( real, data_rate_simulation, false ) == OKLORAWAN )
{
is_valid_dr = true;
break;
@@ -1154,44 +1086,45 @@ uint8_t smtc_real_decrement_dr_simulation( lr1_stack_mac_t* lr1_mac )
// no lower valid DR found
if( is_valid_dr == false )
{
- return lr1_mac->tx_data_rate_adr;
+ return tx_data_rate_adr;
}
return data_rate_simulation;
}
-void smtc_real_decrement_dr( lr1_stack_mac_t* lr1_mac )
+void smtc_real_decrement_dr( smtc_real_t* real, dr_strategy_t adr_mode_select, uint8_t* tx_data_rate_adr,
+ int8_t* tx_power, uint8_t* nb_trans )
{
- if( lr1_mac->adr_mode_select != STATIC_ADR_MODE )
+ if( adr_mode_select != STATIC_ADR_MODE )
{
return;
}
- if( lr1_mac->tx_power < const_tx_power_dbm )
+ if( *tx_power < real_const.const_tx_power_dbm )
{
- lr1_mac->tx_power = const_tx_power_dbm;
+ *tx_power = real_const.const_tx_power_dbm;
return;
}
- if( lr1_mac->tx_data_rate_adr != smtc_real_get_min_tx_channel_dr( lr1_mac ) )
+ if( *tx_data_rate_adr != smtc_real_get_min_tx_channel_dr( real ) )
{
- lr1_mac->tx_data_rate_adr = smtc_real_decrement_dr_simulation( lr1_mac );
+ *tx_data_rate_adr = smtc_real_decrement_dr_simulation( real, *tx_data_rate_adr );
return;
}
// nb_trans must set to 1 and all default channels re-enabled
- lr1_mac->nb_trans = 1;
+ *nb_trans = 1;
// reach this step only if tx_dr = MinDr => enable default channel
- smtc_real_enable_all_channels_with_valid_freq( lr1_mac );
+ smtc_real_enable_all_channels_with_valid_freq( real );
// When all channels are available, lower datarate could be present in case where only DR6 and DR7 was present
// previously
- lr1_mac->tx_data_rate_adr = smtc_real_decrement_dr_simulation( lr1_mac );
+ *tx_data_rate_adr = smtc_real_decrement_dr_simulation( real, *tx_data_rate_adr );
}
-void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
+void smtc_real_enable_all_channels_with_valid_freq( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1219,13 +1152,13 @@ void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
{
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( tx_frequency_channel_ctx[i] != 0 ) &&
( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_DISABLED ) )
{
SMTC_PUT_BIT8( channel_index_enabled_ctx, i, CHANNEL_ENABLED );
- dr_bitfield_tx_channel_ctx[i] = const_default_tx_dr_bit_field;
+ dr_bitfield_tx_channel_ctx[i] = real_const.const_default_tx_dr_bit_field;
}
}
break;
@@ -1233,25 +1166,25 @@ void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- region_cn_470_enable_all_channels_with_valid_freq( lr1_mac );
+ region_cn_470_enable_all_channels_with_valid_freq( real );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( lr1_mac );
+ region_cn_470_rp_1_0_enable_all_channels_with_valid_freq( real );
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- region_us_915_enable_all_channels_with_valid_freq( lr1_mac );
+ region_us_915_enable_all_channels_with_valid_freq( real );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- region_au_915_enable_all_channels_with_valid_freq( lr1_mac );
+ region_au_915_enable_all_channels_with_valid_freq( real );
break;
}
#endif
@@ -1261,10 +1194,10 @@ void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac )
}
}
-status_lorawan_t smtc_real_is_rx1_dr_offset_valid( lr1_stack_mac_t* lr1_mac, uint8_t rx1_dr_offset )
+status_lorawan_t smtc_real_is_rx1_dr_offset_valid( smtc_real_t* real, uint8_t rx1_dr_offset )
{
status_lorawan_t status = OKLORAWAN;
- if( rx1_dr_offset >= const_number_rx1_dr_offset )
+ if( rx1_dr_offset >= real_const.const_number_rx1_dr_offset )
{
status = ERRORLORAWAN;
SMTC_MODEM_HAL_TRACE_MSG( "RECEIVE AN INVALID RX1 DR OFFSET \n" );
@@ -1272,11 +1205,11 @@ status_lorawan_t smtc_real_is_rx1_dr_offset_valid( lr1_stack_mac_t* lr1_mac, uin
return ( status );
}
-status_lorawan_t smtc_real_is_rx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr )
+status_lorawan_t smtc_real_is_rx_dr_valid( smtc_real_t* real, uint8_t dr )
{
- if( ( dr >= const_min_rx_dr ) && ( dr <= const_max_rx_dr ) )
+ if( ( dr >= real_const.const_min_rx_dr ) && ( dr <= real_const.const_max_rx_dr ) )
{
- if( SMTC_GET_BIT16( &const_dr_bitfield, dr ) == 1 )
+ if( SMTC_GET_BIT16( &real_const.const_dr_bitfield, dr ) == 1 )
{
return ( OKLORAWAN );
}
@@ -1286,11 +1219,11 @@ status_lorawan_t smtc_real_is_rx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr
return ( ERRORLORAWAN );
}
-status_lorawan_t smtc_real_is_tx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr )
+status_lorawan_t smtc_real_is_tx_dr_valid( smtc_real_t* real, uint8_t dr )
{
- if( ( dr >= const_min_tx_dr ) && ( dr <= const_max_tx_dr ) )
+ if( ( dr >= real_const.const_min_tx_dr ) && ( dr <= real_const.const_max_tx_dr ) )
{
- if( SMTC_GET_BIT16( &const_dr_bitfield, dr ) == 1 )
+ if( SMTC_GET_BIT16( &real_const.const_dr_bitfield, dr ) == 1 )
{
return ( OKLORAWAN );
}
@@ -1300,9 +1233,9 @@ status_lorawan_t smtc_real_is_tx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr
return ( ERRORLORAWAN );
}
-status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_t dr, bool is_ch_mask_from_link_adr )
+status_lorawan_t smtc_real_is_tx_dr_acceptable( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1340,15 +1273,15 @@ status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_
uint8_t* ch_mask_to_check =
( is_ch_mask_from_link_adr == true ) ? unwrapped_channel_mask_ctx : channel_index_enabled_ctx;
- if( lr1_mac->uplink_dwell_time == true )
+ if( uplink_dwell_time_ctx == true )
{
- if( dr < const_min_tx_dr_limit )
+ if( dr < real_const.const_min_tx_dr_limit )
{
return ERRORLORAWAN;
}
}
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( ch_mask_to_check, i ) == CHANNEL_ENABLED )
{
@@ -1366,11 +1299,11 @@ status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915:
- return region_us_915_is_acceptable_tx_dr( lr1_mac, dr, is_ch_mask_from_link_adr );
+ return region_us_915_is_acceptable_tx_dr( real, dr, is_ch_mask_from_link_adr );
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915:
- return region_au_915_is_acceptable_tx_dr( lr1_mac, dr, is_ch_mask_from_link_adr );
+ return region_au_915_is_acceptable_tx_dr( real, dr, is_ch_mask_from_link_adr, uplink_dwell_time_ctx );
#endif
default:
smtc_modem_hal_lr1mac_panic( );
@@ -1379,9 +1312,9 @@ status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_
return ERRORLORAWAN; // never reach => avoid warning
}
-status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_t frequency )
+status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( smtc_real_t* real, uint32_t frequency )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1414,7 +1347,7 @@ status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( lr1_stack_mac_t*
{
return ( status );
}
- status = smtc_real_is_frequency_valid( lr1_mac, frequency );
+ status = smtc_real_is_frequency_valid( real, frequency );
return ( status );
}
#endif
@@ -1442,9 +1375,9 @@ status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( lr1_stack_mac_t*
return ERRORLORAWAN; // never reach => avoid warning
}
-status_lorawan_t smtc_real_is_channel_index_valid( lr1_stack_mac_t* lr1_mac, uint8_t channel_index )
+status_lorawan_t smtc_real_is_channel_index_valid( smtc_real_t* real, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1473,7 +1406,8 @@ status_lorawan_t smtc_real_is_channel_index_valid( lr1_stack_mac_t* lr1_mac, uin
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
{
status_lorawan_t status = OKLORAWAN;
- if( ( channel_index < const_number_of_boot_tx_channel ) || ( channel_index >= const_number_of_tx_channel ) )
+ if( ( channel_index < real_const.const_number_of_boot_tx_channel ) ||
+ ( channel_index >= real_const.const_number_of_tx_channel ) )
{
status = ERRORLORAWAN;
SMTC_MODEM_HAL_TRACE_WARNING( "RECEIVE AN INVALID Channel Index Cmd = %d\n", channel_index );
@@ -1506,37 +1440,39 @@ status_lorawan_t smtc_real_is_channel_index_valid( lr1_stack_mac_t* lr1_mac, uin
return ERRORLORAWAN; // never reach => avoid warning
}
-status_lorawan_t smtc_real_is_payload_size_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr, uint8_t size,
- uint8_t dwell_time_enabled )
+status_lorawan_t smtc_real_is_payload_size_valid( smtc_real_t* real, uint8_t dr, uint8_t size,
+ direction_frame_t direction_frame, uint8_t tx_fopts_current_length )
{
- if( ( const_tx_param_setup_req_supported == false ) && ( dwell_time_enabled != 0 ) )
+ bool dwell_time_enabled = ( direction_frame == UP_LINK ) ? uplink_dwell_time_ctx : downlink_dwell_time_ctx;
+ if( ( real_const.const_tx_param_setup_req_supported == false ) && ( dwell_time_enabled != 0 ) )
{
smtc_modem_hal_lr1mac_panic( );
}
- uint8_t index = ( dwell_time_enabled * const_number_of_tx_dr ) + dr;
+ uint8_t index = ( dwell_time_enabled * real_const.const_number_of_tx_dr ) + dr;
#if defined( REGION_AU_915 )
- if( lr1_mac->real->region_type == SMTC_REAL_REGION_AU_915 )
+ if( real->region_type == SMTC_REAL_REGION_AU_915 )
{
// *2 because the array contains Tx and Rx datarate
- index = ( dwell_time_enabled * const_number_of_tx_dr * 2 ) + dr;
+ index = ( dwell_time_enabled * real_const.const_number_of_tx_dr * 2 ) + dr;
}
#endif
- status_lorawan_t status =
- ( ( size + lr1_mac->tx_fopts_current_length ) > ( const_max_payload_m[index] - 8 ) ) ? ERRORLORAWAN : OKLORAWAN;
+ status_lorawan_t status = ( ( size + tx_fopts_current_length ) > ( real_const.const_max_payload_m[index] - 8 ) )
+ ? ERRORLORAWAN
+ : OKLORAWAN;
if( status == ERRORLORAWAN )
{
SMTC_MODEM_HAL_TRACE_PRINTF( "Invalid size (data:%d + FOpts:%d) > %d for dr: %d\n", size,
- lr1_mac->tx_fopts_current_length, ( const_max_payload_m[index] - 8 ), dr );
+ tx_fopts_current_length, ( real_const.const_max_payload_m[index] - 8 ), dr );
}
return ( status );
}
-void smtc_real_set_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t tx_freq, uint8_t channel_index )
+void smtc_real_set_tx_frequency_channel( smtc_real_t* real, uint32_t tx_freq, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1563,7 +1499,7 @@ void smtc_real_set_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t tx_f
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_tx_channel )
+ if( channel_index >= real_const.const_number_of_tx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1597,10 +1533,9 @@ void smtc_real_set_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t tx_f
}
}
-status_lorawan_t smtc_real_set_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t rx_freq,
- uint8_t channel_index )
+status_lorawan_t smtc_real_set_rx1_frequency_channel( smtc_real_t* real, uint32_t rx_freq, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1627,7 +1562,7 @@ status_lorawan_t smtc_real_set_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac,
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_rx_channel )
+ if( channel_index >= real_const.const_number_of_rx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1664,9 +1599,9 @@ status_lorawan_t smtc_real_set_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac,
return ERRORLORAWAN; // never reach => avoid warning
}
-void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index, uint8_t dr_min, uint8_t dr_max )
+void smtc_real_set_channel_dr( smtc_real_t* real, uint8_t channel_index, uint8_t dr_min, uint8_t dr_max )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1693,7 +1628,7 @@ void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index,
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_tx_channel )
+ if( channel_index >= real_const.const_number_of_tx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1702,7 +1637,7 @@ void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index,
dr_bitfield_tx_channel_ctx[channel_index] = 0;
for( uint8_t i = dr_min; i <= dr_max; i++ )
{
- uint8_t tmp_dr = SMTC_GET_BIT16( &const_dr_bitfield, i );
+ uint8_t tmp_dr = SMTC_GET_BIT16( &real_const.const_dr_bitfield, i );
SMTC_PUT_BIT16( &dr_bitfield_tx_channel_ctx[channel_index], i, tmp_dr );
}
}
@@ -1732,9 +1667,9 @@ void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index,
}
}
-void smtc_real_set_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t enable, uint8_t channel_index )
+void smtc_real_set_channel_enabled( smtc_real_t* real, uint8_t enable, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1761,7 +1696,7 @@ void smtc_real_set_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t enable, ui
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_tx_channel )
+ if( channel_index >= real_const.const_number_of_tx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1795,9 +1730,9 @@ void smtc_real_set_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t enable, ui
}
}
-uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t channel_index )
+uint32_t smtc_real_get_tx_channel_frequency( smtc_real_t* real, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1824,7 +1759,7 @@ uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t c
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_tx_channel )
+ if( channel_index >= real_const.const_number_of_tx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1833,25 +1768,25 @@ uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t c
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_tx_frequency_channel( lr1_mac, channel_index );
+ return region_cn_470_get_tx_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_tx_frequency_channel( lr1_mac, channel_index );
+ return region_cn_470_rp_1_0_get_tx_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_tx_frequency_channel( lr1_mac, channel_index );
+ return region_us_915_get_tx_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_tx_frequency_channel( lr1_mac, channel_index );
+ return region_au_915_get_tx_frequency_channel( real, channel_index );
break;
}
#endif
@@ -1862,9 +1797,9 @@ uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t c
return ERRORLORAWAN; // never reach => avoid warning
}
-uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t channel_index )
+uint32_t smtc_real_get_rx1_channel_frequency( smtc_real_t* real, uint8_t channel_index )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -1891,7 +1826,7 @@ uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t
#endif
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_KR_920 ) || defined( REGION_RU_864 )
- if( channel_index >= const_number_of_rx_channel )
+ if( channel_index >= real_const.const_number_of_rx_channel )
{
smtc_modem_hal_lr1mac_panic( );
}
@@ -1900,25 +1835,25 @@ uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_rx1_frequency_channel( lr1_mac, channel_index );
+ return region_cn_470_get_rx1_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_rx1_frequency_channel( lr1_mac, channel_index );
+ return region_cn_470_rp_1_0_get_rx1_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_rx1_frequency_channel( lr1_mac, channel_index );
+ return region_us_915_get_rx1_frequency_channel( real, channel_index );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_rx1_frequency_channel( lr1_mac, channel_index );
+ return region_au_915_get_rx1_frequency_channel( real, channel_index );
break;
}
#endif
@@ -1929,14 +1864,14 @@ uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t
return ERRORLORAWAN; // never reach => avoid warning
}
-uint8_t smtc_real_get_min_tx_channel_dr( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_min_tx_channel_dr( smtc_real_t* real )
{
- uint8_t min_dr = const_max_tx_dr; // start with the max dr and search a dr inferior
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ uint8_t min_dr = real_const.const_max_tx_dr; // start with the max dr and search a dr inferior
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_ENABLED ) )
{
- for( uint8_t dr = const_min_tx_dr; dr <= const_max_tx_dr; dr++ )
+ for( uint8_t dr = real_const.const_min_tx_dr; dr <= real_const.const_max_tx_dr; dr++ )
{
if( ( SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[i], dr ) == 1 ) && ( min_dr > dr ) )
{
@@ -1944,29 +1879,29 @@ uint8_t smtc_real_get_min_tx_channel_dr( lr1_stack_mac_t* lr1_mac )
}
}
- if( min_dr == const_min_tx_dr )
+ if( min_dr == real_const.const_min_tx_dr )
{
break; // DR found is the smallest
}
}
}
- if( lr1_mac->uplink_dwell_time == true )
+ if( uplink_dwell_time_ctx == true )
{
- min_dr = MAX( min_dr, const_min_tx_dr_limit );
+ min_dr = MAX( min_dr, real_const.const_min_tx_dr_limit );
}
return ( min_dr );
}
-uint8_t smtc_real_get_max_tx_channel_dr( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_max_tx_channel_dr( smtc_real_t* real )
{
- uint8_t max_dr = const_min_tx_dr; // start with the min dr and search a dr superior
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ uint8_t max_dr = real_const.const_min_tx_dr; // start with the min dr and search a dr superior
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( ( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_ENABLED ) )
{
- for( uint8_t dr = 0; dr <= const_max_tx_dr; dr++ )
+ for( uint8_t dr = 0; dr <= real_const.const_max_tx_dr; dr++ )
{
if( ( SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[i], dr ) == 1 ) && ( max_dr < dr ) )
{
@@ -1974,7 +1909,7 @@ uint8_t smtc_real_get_max_tx_channel_dr( lr1_stack_mac_t* lr1_mac )
}
}
- if( max_dr == const_max_tx_dr )
+ if( max_dr == real_const.const_max_tx_dr )
{
break; // DR found is the bigest
}
@@ -1984,10 +1919,10 @@ uint8_t smtc_real_get_max_tx_channel_dr( lr1_stack_mac_t* lr1_mac )
return ( max_dr );
}
-uint16_t smtc_real_mask_tx_dr_channel( lr1_stack_mac_t* lr1_mac )
+uint16_t smtc_real_mask_tx_dr_channel( smtc_real_t* real )
{
uint16_t dr_mask = 0;
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_ENABLED )
{
@@ -1998,12 +1933,12 @@ uint16_t smtc_real_mask_tx_dr_channel( lr1_stack_mac_t* lr1_mac )
return dr_mask;
}
-uint16_t smtc_real_mask_tx_dr_channel_up_dwell_time_check( lr1_stack_mac_t* lr1_mac )
+uint16_t smtc_real_mask_tx_dr_channel_up_dwell_time_check( smtc_real_t* real )
{
- uint16_t dr_mask = smtc_real_mask_tx_dr_channel( lr1_mac );
- if( lr1_mac->uplink_dwell_time == true )
+ uint16_t dr_mask = smtc_real_mask_tx_dr_channel( real );
+ if( uplink_dwell_time_ctx == true )
{
- for( uint8_t i = 0; i < const_min_tx_dr_limit; i++ )
+ for( uint8_t i = 0; i < real_const.const_min_tx_dr_limit; i++ )
{
SMTC_PUT_BIT16( &dr_mask, i, false );
}
@@ -2012,9 +1947,9 @@ uint16_t smtc_real_mask_tx_dr_channel_up_dwell_time_check( lr1_stack_mac_t* lr1_
return dr_mask;
}
-uint8_t smtc_real_get_preamble_len( const lr1_stack_mac_t* lr1_mac, uint8_t sf )
+uint8_t smtc_real_get_preamble_len( const smtc_real_t* real, uint8_t sf )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
@@ -2035,14 +1970,14 @@ uint8_t smtc_real_get_preamble_len( const lr1_stack_mac_t* lr1_mac, uint8_t sf )
}
}
-status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_t* lr1_mac )
+status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const smtc_real_t* real )
{
status_lorawan_t status = ERRORLORAWAN;
- uint8_t min_mobile_dr = const_min_tx_dr;
- uint8_t max_mobile_dr = const_max_tx_dr;
+ uint8_t min_mobile_dr = real_const.const_min_tx_dr;
+ uint8_t max_mobile_dr = real_const.const_max_tx_dr;
// search min datarate init
- for( int i = 0; i < const_number_of_tx_dr; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_dr; i++ )
{
if( dr_distribution_init_ctx[i] > 0 )
{
@@ -2050,13 +1985,13 @@ status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_
break;
}
}
- if( lr1_mac->uplink_dwell_time == true )
+ if( uplink_dwell_time_ctx == true )
{
- min_mobile_dr = MAX( min_mobile_dr, const_min_tx_dr_limit );
+ min_mobile_dr = MAX( min_mobile_dr, real_const.const_min_tx_dr_limit );
}
// search max datarate init
- for( int i = const_number_of_tx_dr - 1; i <= 0; i-- )
+ for( int i = real_const.const_number_of_tx_dr - 1; i <= 0; i-- )
{
if( dr_distribution_init_ctx[i] > 0 )
{
@@ -2065,11 +2000,11 @@ status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_
}
}
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( unwrapped_channel_mask_ctx, i ) == CHANNEL_ENABLED )
{
- for( uint8_t dr = const_min_tx_dr; dr <= const_max_tx_dr; dr++ )
+ for( uint8_t dr = real_const.const_min_tx_dr; dr <= real_const.const_max_tx_dr; dr++ )
{
if( SMTC_GET_BIT16( &dr_bitfield_tx_channel_ctx[i], dr ) == 1 )
{
@@ -2085,9 +2020,9 @@ status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_
return ( status );
}
-modulation_type_t smtc_real_get_modulation_type_from_datarate( lr1_stack_mac_t* lr1_mac, uint8_t datarate )
+modulation_type_t smtc_real_get_modulation_type_from_datarate( smtc_real_t* real, uint8_t datarate )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
@@ -2161,9 +2096,9 @@ modulation_type_t smtc_real_get_modulation_type_from_datarate( lr1_stack_mac_t*
}
return 0; // never reach => avoid warning
}
-void smtc_real_lora_dr_to_sf_bw( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw )
+void smtc_real_lora_dr_to_sf_bw( smtc_real_t* real, uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4: {
@@ -2237,9 +2172,9 @@ void smtc_real_lora_dr_to_sf_bw( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8_
}
}
-void smtc_real_fsk_dr_to_bitrate( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8_t* out_bitrate )
+void smtc_real_fsk_dr_to_bitrate( smtc_real_t* real, uint8_t in_dr, uint8_t* out_bitrate )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
@@ -2283,10 +2218,9 @@ void smtc_real_fsk_dr_to_bitrate( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8
}
}
-void smtc_real_lr_fhss_dr_to_cr_bw( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
- lr_fhss_v1_bw_t* out_bw )
+void smtc_real_lr_fhss_dr_to_cr_bw( smtc_real_t* real, uint8_t in_dr, lr_fhss_v1_cr_t* out_cr, lr_fhss_v1_bw_t* out_bw )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
@@ -2327,9 +2261,9 @@ lr_fhss_hc_t smtc_real_lr_fhss_get_header_count( lr_fhss_v1_cr_t in_cr )
return 0;
}
-lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( lr1_stack_mac_t* lr1_mac )
+lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( smtc_real_t* real )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_EU_868 )
case SMTC_REAL_REGION_EU_868: {
@@ -2356,11 +2290,11 @@ lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( lr1_stack_mac_t* lr1_mac )
return -1; // never reach => avoid warning
}
-uint8_t smtc_real_get_number_of_enabled_channels_for_a_datarate( lr1_stack_mac_t* lr1_mac, uint8_t datarate )
+uint8_t smtc_real_get_number_of_enabled_channels_for_a_datarate( smtc_real_t* real, uint8_t datarate )
{
uint8_t channel_counter = 0;
- for( uint8_t i = 0; i < const_number_of_tx_channel; i++ )
+ for( uint8_t i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_ENABLED )
{
@@ -2373,10 +2307,10 @@ uint8_t smtc_real_get_number_of_enabled_channels_for_a_datarate( lr1_stack_mac_t
return channel_counter;
}
-int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( lr1_stack_mac_t* lr1_mac, int8_t tx_power,
- uint32_t tx_frequency, uint8_t datarate )
+int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( smtc_real_t* real, int8_t tx_power, uint32_t tx_frequency,
+ uint8_t datarate )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -2422,7 +2356,7 @@ int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( lr1_stack_mac_t* lr1_ma
{
return MIN( tx_power, 26 );
}
- else if( smtc_real_get_number_of_enabled_channels_for_a_datarate( lr1_mac, datarate ) < 50 )
+ else if( smtc_real_get_number_of_enabled_channels_for_a_datarate( real, datarate ) < 50 )
{
return MIN( tx_power, 21 );
}
@@ -2451,15 +2385,15 @@ int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( lr1_stack_mac_t* lr1_ma
return 0; // never reach => avoid warning
}
-uint8_t smtc_real_get_current_enabled_frequency_list( lr1_stack_mac_t* lr1_mac, uint8_t* number_of_freq,
- uint32_t* freq_list, uint8_t max_size )
+uint8_t smtc_real_get_current_enabled_frequency_list( smtc_real_t* real, uint8_t* number_of_freq, uint32_t* freq_list,
+ uint8_t max_size )
{
*number_of_freq = 0;
- if( max_size < const_number_of_tx_channel )
+ if( max_size < real_const.const_number_of_tx_channel )
{
return false;
}
- for( int i = 0; i < const_number_of_tx_channel; i++ )
+ for( int i = 0; i < real_const.const_number_of_tx_channel; i++ )
{
if( SMTC_GET_BIT8( channel_index_enabled_ctx, i ) == CHANNEL_ENABLED )
{
@@ -2473,156 +2407,218 @@ uint8_t smtc_real_get_current_enabled_frequency_list( lr1_stack_mac_t* lr1_mac,
/*************************************************************************/
/* Const init in region */
/*************************************************************************/
-bool smtc_real_is_tx_param_setup_req_supported( lr1_stack_mac_t* lr1_mac )
+bool smtc_real_is_tx_param_setup_req_supported( smtc_real_t* real )
{
- return ( const_tx_param_setup_req_supported );
+ return ( real_const.const_tx_param_setup_req_supported );
}
-bool smtc_real_is_new_channel_req_supported( lr1_stack_mac_t* lr1_mac )
+bool smtc_real_is_new_channel_req_supported( smtc_real_t* real )
{
- return ( const_new_channel_req_supported );
+ return ( real_const.const_new_channel_req_supported );
}
-uint8_t smtc_real_get_rx1_join_delay( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_rx1_join_delay( smtc_real_t* real )
{
- return ( const_join_accept_delay1 );
+ return ( real_const.const_join_accept_delay1 );
}
-uint8_t smtc_real_get_rx2_join_dr( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_rx2_join_dr( smtc_real_t* real )
{
- return ( const_rx2_dr_init );
+ return ( real_const.const_rx2_dr_init );
}
-uint8_t smtc_real_get_frequency_factor( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_frequency_factor( smtc_real_t* real )
{
- return ( const_frequency_factor );
+ return ( real_const.const_frequency_factor );
}
-ral_lora_cr_t smtc_real_get_coding_rate( lr1_stack_mac_t* lr1_mac )
+ral_lora_cr_t smtc_real_get_coding_rate( smtc_real_t* real )
{
- return ( const_coding_rate );
+ return ( real_const.const_coding_rate );
}
-uint8_t smtc_real_get_adr_ack_delay( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_adr_ack_delay( smtc_real_t* real )
{
- return ( const_adr_ack_delay );
+ return ( real_const.const_adr_ack_delay );
}
-uint8_t smtc_real_get_adr_ack_limit( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_adr_ack_limit( smtc_real_t* real )
{
- return ( const_adr_ack_limit );
+ return ( real_const.const_adr_ack_limit );
}
-uint8_t smtc_real_get_public_sync_word( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_public_sync_word( smtc_real_t* real )
{
- return ( const_sync_word_public );
+ return ( real_const.const_sync_word_public );
}
-uint8_t smtc_real_get_private_sync_word( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_private_sync_word( smtc_real_t* real )
{
- return ( const_sync_word_private );
+ return ( real_const.const_sync_word_private );
}
-uint8_t smtc_real_get_sync_word( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_sync_word( smtc_real_t* real )
{
- return ( sync_word_ctx );
+ return ( real_ctx.sync_word_ctx );
}
-void smtc_real_set_sync_word( lr1_stack_mac_t* lr1_mac, uint8_t sync_word )
+void smtc_real_set_sync_word( smtc_real_t* real, uint8_t sync_word )
{
- sync_word_ctx = sync_word;
+ real_ctx.sync_word_ctx = sync_word;
}
-uint8_t* smtc_real_get_gfsk_sync_word( lr1_stack_mac_t* lr1_mac )
+uint8_t* smtc_real_get_gfsk_sync_word( smtc_real_t* real )
{
#if defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_CN_470 ) || \
defined( REGION_CN_470_RP_1_0 ) || defined( REGION_IN_865 ) || defined( REGION_RU_864 )
- return ( uint8_t* ) const_sync_word_gfsk;
+ return ( uint8_t* ) real_const.const_sync_word_gfsk;
#endif
smtc_modem_hal_lr1mac_panic( );
return 0; // never reach => avoid warning
}
-uint8_t* smtc_real_get_lr_fhss_sync_word( lr1_stack_mac_t* lr1_mac )
+uint8_t* smtc_real_get_lr_fhss_sync_word( smtc_real_t* real )
{
#if defined( REGION_EU_868 ) || defined( REGION_AU_915 ) || defined( REGION_US_915 )
- return ( uint8_t* ) const_sync_word_lr_fhss;
+ return ( uint8_t* ) real_const.const_sync_word_lr_fhss;
#endif
smtc_modem_hal_lr1mac_panic( );
return 0; // never reach => avoid warning
}
-bool smtc_real_is_dtc_supported( const lr1_stack_mac_t* lr1_mac )
+bool smtc_real_is_dtc_supported( const smtc_real_t* real )
{
- return const_dtc_supported;
+ return real_const.const_dtc_supported;
}
-bool smtc_real_is_lbt_supported( const lr1_stack_mac_t* lr1_mac )
+bool smtc_real_is_lbt_supported( const smtc_real_t* real )
{
- return const_lbt_supported;
+ return real_const.const_lbt_supported;
}
-uint32_t smtc_real_get_lbt_duration_ms( const lr1_stack_mac_t* lr1_mac )
+uint32_t smtc_real_get_lbt_duration_ms( const smtc_real_t* real )
{
- if( const_lbt_supported == true )
+ if( real_const.const_lbt_supported == true )
{
- return const_lbt_sniff_duration_ms;
+ return real_const.const_lbt_sniff_duration_ms;
}
smtc_modem_hal_lr1mac_panic( );
return 0; // never reach => avoid warning
}
-int16_t smtc_real_get_lbt_threshold_dbm( const lr1_stack_mac_t* lr1_mac )
+int16_t smtc_real_get_lbt_threshold_dbm( const smtc_real_t* real )
{
- if( const_lbt_supported == true )
+ if( real_const.const_lbt_supported == true )
{
- return const_lbt_threshold_dbm;
+ return real_const.const_lbt_threshold_dbm;
}
smtc_modem_hal_lr1mac_panic( );
return 0; // never reach => avoid warning
}
-uint32_t smtc_real_get_lbt_bw_hz( const lr1_stack_mac_t* lr1_mac )
+uint32_t smtc_real_get_lbt_bw_hz( const smtc_real_t* real )
{
- if( const_lbt_supported == true )
+ if( real_const.const_lbt_supported == true )
{
- return const_lbt_bw_hz;
+ return real_const.const_lbt_bw_hz;
}
smtc_modem_hal_lr1mac_panic( );
return 0; // never reach => avoid warning
}
-uint8_t smtc_real_get_max_payload_size( lr1_stack_mac_t* lr1_mac, uint8_t dr, uint8_t dwell_time_enabled )
+uint8_t smtc_real_get_max_payload_size( smtc_real_t* real, uint8_t dr, direction_frame_t direction_frame )
{
- if( ( const_tx_param_setup_req_supported == false ) && ( dwell_time_enabled != 0 ) )
+ bool dwell_time_enabled = ( direction_frame == UP_LINK ) ? uplink_dwell_time_ctx : downlink_dwell_time_ctx;
+
+ if( ( real_const.const_tx_param_setup_req_supported == false ) && ( dwell_time_enabled != 0 ) )
{
smtc_modem_hal_lr1mac_panic( );
}
- uint8_t index = ( dwell_time_enabled * const_number_of_tx_dr ) + dr;
+ uint8_t index = ( dwell_time_enabled * real_const.const_number_of_tx_dr ) + dr;
#if defined( REGION_AU_915 )
- if( lr1_mac->real->region_type == SMTC_REAL_REGION_AU_915 )
+ if( real->region_type == SMTC_REAL_REGION_AU_915 )
{
// *2 because the array contains Tx and Rx datarate
- index = ( dwell_time_enabled * const_number_of_tx_dr * 2 ) + dr;
+ index = ( dwell_time_enabled * real_const.const_number_of_tx_dr * 2 ) + dr;
}
#endif
- return ( const_max_payload_m[index] );
+ return ( real_const.const_max_payload_m[index] );
+}
+
+uint8_t smtc_real_get_default_max_eirp( smtc_real_t* real )
+{
+ return ( real_const.const_tx_power_dbm );
}
-uint8_t smtc_real_get_default_max_eirp( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_beacon_dr( smtc_real_t* real )
{
- return ( const_tx_power_dbm );
+ return ( real_const.const_beacon_dr );
}
-uint8_t smtc_real_get_beacon_dr( lr1_stack_mac_t* lr1_mac )
+bool smtc_real_is_beacon_hopping( smtc_real_t* real )
{
- return ( const_beacon_dr );
+ switch( real->region_type )
+ {
+#if defined( REGION_WW2G4 )
+ case SMTC_REAL_REGION_WW2G4:
+#endif
+#if defined( REGION_EU_868 )
+ case SMTC_REAL_REGION_EU_868:
+#endif
+#if defined( REGION_AS_923 )
+ case SMTC_REAL_REGION_AS_923:
+ case SMTC_REAL_REGION_AS_923_GRP2:
+ case SMTC_REAL_REGION_AS_923_GRP3:
+#if defined( RP2_103 )
+ case SMTC_REAL_REGION_AS_923_GRP4:
+#endif
+#endif
+#if defined( REGION_IN_865 )
+ case SMTC_REAL_REGION_IN_865:
+#endif
+#if defined( REGION_RU_864 )
+ case SMTC_REAL_REGION_RU_864:
+#endif
+#if defined( REGION_KR_920 )
+ case SMTC_REAL_REGION_KR_920:
+#endif
+#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
+ defined( REGION_RU_864 ) || defined( SMTC_REAL_REGION_KR_920 )
+ {
+ return false;
+ break;
+ }
+#endif
+
+#if defined( REGION_US_915 )
+ case SMTC_REAL_REGION_US_915:
+#endif
+#if defined( REGION_AU_915 )
+ case SMTC_REAL_REGION_AU_915:
+#endif
+#if defined( REGION_CN_470 )
+ case SMTC_REAL_REGION_CN_470:
+#endif
+#if defined( REGION_CN_470_RP_1_0 )
+ case SMTC_REAL_REGION_CN_470_RP_1_0:
+#endif
+#if defined( REGION_US_915 ) || defined( REGION_AU_915 ) || defined( REGION_CN_470 ) || defined( REGION_CN_470_RP_1_0 )
+ {
+ return true;
+ break;
+ }
+#endif
+ default:
+ smtc_modem_hal_lr1mac_panic( );
+ break;
+ }
+ return 0; // never reach => avoid warning
}
-uint32_t smtc_real_get_beacon_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s )
+uint32_t smtc_real_get_beacon_frequency( smtc_real_t* real, uint32_t gps_time_s )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -2650,32 +2646,32 @@ uint32_t smtc_real_get_beacon_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_RU_864 ) || defined( SMTC_REAL_REGION_KR_920 )
{
- return const_beacon_frequency;
+ return real_const.const_beacon_frequency;
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_rx_beacon_frequency_channel( lr1_mac, gps_time_s );
+ return region_us_915_get_rx_beacon_frequency_channel( real, gps_time_s );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_rx_beacon_frequency_channel( lr1_mac, gps_time_s );
+ return region_au_915_get_rx_beacon_frequency_channel( real, gps_time_s );
break;
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_rx_beacon_frequency_channel( lr1_mac, gps_time_s );
+ return region_cn_470_get_rx_beacon_frequency_channel( real, gps_time_s );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( lr1_mac, gps_time_s );
+ return region_cn_470_rp_1_0_get_rx_beacon_frequency_channel( real, gps_time_s );
break;
}
#endif
@@ -2686,9 +2682,9 @@ uint32_t smtc_real_get_beacon_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_
return 0; // never reach => avoid warning
}
-uint32_t smtc_real_get_ping_slot_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s, uint32_t dev_addr )
+uint32_t smtc_real_get_ping_slot_frequency( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr )
{
- switch( lr1_mac->real->region_type )
+ switch( real->region_type )
{
#if defined( REGION_WW2G4 )
case SMTC_REAL_REGION_WW2G4:
@@ -2716,32 +2712,32 @@ uint32_t smtc_real_get_ping_slot_frequency( lr1_stack_mac_t* lr1_mac, uint32_t g
#if defined( REGION_WW2G4 ) || defined( REGION_EU_868 ) || defined( REGION_AS_923 ) || defined( REGION_IN_865 ) || \
defined( REGION_RU_864 ) || defined( SMTC_REAL_REGION_KR_920 )
{
- return const_ping_slot_frequency;
+ return real_const.const_ping_slot_frequency;
break;
}
#endif
#if defined( REGION_US_915 )
case SMTC_REAL_REGION_US_915: {
- return region_us_915_get_rx_ping_slot_frequency_channel( lr1_mac, gps_time_s, dev_addr );
+ return region_us_915_get_rx_ping_slot_frequency_channel( real, gps_time_s, dev_addr );
break;
}
#endif
#if defined( REGION_AU_915 )
case SMTC_REAL_REGION_AU_915: {
- return region_au_915_get_rx_ping_slot_frequency_channel( lr1_mac, gps_time_s, dev_addr );
+ return region_au_915_get_rx_ping_slot_frequency_channel( real, gps_time_s, dev_addr );
break;
}
#endif
#if defined( REGION_CN_470 )
case SMTC_REAL_REGION_CN_470: {
- return region_cn_470_get_rx_ping_slot_frequency_channel( lr1_mac, gps_time_s, dev_addr );
+ return region_cn_470_get_rx_ping_slot_frequency_channel( real, gps_time_s, dev_addr );
break;
}
#endif
#if defined( REGION_CN_470_RP_1_0 )
case SMTC_REAL_REGION_CN_470_RP_1_0: {
- return region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( lr1_mac, gps_time_s, dev_addr );
+ return region_cn_470_rp_1_0_get_rx_ping_slot_frequency_channel( real, gps_time_s, dev_addr );
break;
}
#endif
@@ -2752,22 +2748,32 @@ uint32_t smtc_real_get_ping_slot_frequency( lr1_stack_mac_t* lr1_mac, uint32_t g
return 0; // never reach => avoid warning
}
-uint8_t smtc_real_get_ping_slot_datarate( lr1_stack_mac_t* lr1_mac )
+uint8_t smtc_real_get_ping_slot_datarate( smtc_real_t* real )
+{
+ return real_const.const_beacon_dr; // Return the default ping slot datarate, it's the same for beacon and ping-slot
+}
+
+void smtc_real_set_uplink_dwell_time( smtc_real_t* real, bool dwell_time )
+{
+ uplink_dwell_time_ctx = dwell_time;
+}
+
+void smtc_real_set_downlink_dwell_time( smtc_real_t* real, bool dwell_time )
{
- return const_beacon_dr; // Return the default ping slot datarate, it's the same for beacon and ping-slot
+ downlink_dwell_time_ctx = dwell_time;
}
-uint32_t smtc_real_decode_freq_from_buf( lr1_stack_mac_t* lr1_mac, uint8_t freq_buf[3] )
+uint32_t smtc_real_decode_freq_from_buf( smtc_real_t* real, uint8_t freq_buf[3] )
{
uint32_t freq = ( freq_buf[0] ) + ( freq_buf[1] << 8 ) + ( freq_buf[2] << 16 );
- freq *= const_frequency_factor;
+ freq *= real_const.const_frequency_factor;
return freq;
}
-status_lorawan_t smtc_real_is_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_t frequency )
+status_lorawan_t smtc_real_is_frequency_valid( smtc_real_t* real, uint32_t frequency )
{
status_lorawan_t status = OKLORAWAN;
- if( ( frequency > const_freq_max ) || ( frequency < const_freq_min ) )
+ if( ( frequency > real_const.const_freq_max ) || ( frequency < real_const.const_freq_min ) )
{
status = ERRORLORAWAN;
SMTC_MODEM_HAL_TRACE_WARNING( "INVALID FREQUENCY = %d\n", frequency );
@@ -2775,10 +2781,10 @@ status_lorawan_t smtc_real_is_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_
return ( status );
}
-status_lorawan_t smtc_real_is_tx_power_valid( lr1_stack_mac_t* lr1_mac, uint8_t power )
+status_lorawan_t smtc_real_is_tx_power_valid( smtc_real_t* real, uint8_t power )
{
status_lorawan_t status = OKLORAWAN;
- if( ( power > const_max_tx_power_idx ) )
+ if( ( power > real_const.const_max_tx_power_idx ) )
{
status = ERRORLORAWAN;
SMTC_MODEM_HAL_TRACE_WARNING( "RECEIVE AN INVALID Power Cmd = %d\n", power );
@@ -2794,15 +2800,15 @@ lr1mac_version_t smtc_real_get_regional_parameters_version( void )
return version;
}
-uint32_t smtc_real_get_symbol_duration_us( lr1_stack_mac_t* lr1_mac, uint8_t datarate )
+uint32_t smtc_real_get_symbol_duration_us( smtc_real_t* real, uint8_t datarate )
{
- modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, datarate );
+ modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( real, datarate );
uint32_t bw_temp = 125;
if( modulation_type == LORA )
{
uint8_t sf;
lr1mac_bandwidth_t bw;
- smtc_real_lora_dr_to_sf_bw( lr1_mac, datarate, &sf, &bw );
+ smtc_real_lora_dr_to_sf_bw( real, datarate, &sf, &bw );
// Use lr1mac_utilities_get_symb_time_us
switch( bw )
{
@@ -2827,33 +2833,34 @@ uint32_t smtc_real_get_symbol_duration_us( lr1_stack_mac_t* lr1_mac, uint8_t dat
else
{
uint8_t kbitrate;
- smtc_real_fsk_dr_to_bitrate( lr1_mac, datarate, &kbitrate );
+ smtc_real_fsk_dr_to_bitrate( real, datarate, &kbitrate );
return ( 8000 / ( kbitrate ) ); // 1 symbol equals 1 byte
}
}
-void smtc_real_get_rx_window_parameters( lr1_stack_mac_t* lr1_mac, uint8_t datarate, uint32_t rx_delay_ms,
+void smtc_real_get_rx_window_parameters( smtc_real_t* real, uint8_t datarate, uint32_t rx_delay_ms,
uint16_t* rx_window_symb, uint32_t* rx_timeout_symb_in_ms,
- uint32_t* rx_timeout_preamble_locked_in_ms, uint8_t rx_done_incertitude )
+ uint32_t* rx_timeout_preamble_locked_in_ms, uint8_t rx_done_incertitude,
+ uint32_t crystal_error )
{
- uint32_t tsymbol_us = smtc_real_get_symbol_duration_us( lr1_mac, datarate );
+ uint32_t tsymbol_us = smtc_real_get_symbol_duration_us( real, datarate );
uint32_t min_rx_symb_duration_ms = MIN_RX_WINDOW_DURATION_MS + rx_done_incertitude;
- modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, datarate );
+ modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( real, datarate );
if( modulation_type == FSK )
{
min_rx_symb_duration_ms += 2;
}
- *rx_timeout_symb_in_ms = MAX(
- ( ( ( ( rx_delay_ms * 2 * lr1_mac->crystal_error ) / 1000 ) + ( MIN_RX_WINDOW_SYMB * tsymbol_us ) ) / 1000 ),
- min_rx_symb_duration_ms );
+ *rx_timeout_symb_in_ms =
+ MAX( ( ( ( ( rx_delay_ms * 2 * crystal_error ) / 1000 ) + ( MIN_RX_WINDOW_SYMB * tsymbol_us ) ) / 1000 ),
+ min_rx_symb_duration_ms );
*rx_window_symb =
MIN( MAX( ( ( *rx_timeout_symb_in_ms * 1000 ) / tsymbol_us ), MIN_RX_WINDOW_SYMB ), MAX_RX_WINDOW_SYMB );
// Because the hardware allows an even number of symbols
- if( ( *rx_window_symb % 2 ) == 1 ) //
+ if( ( ( *rx_window_symb % 2 ) == 1 ) && ( *rx_window_symb != MAX_RX_WINDOW_SYMB ) ) //
{
*rx_window_symb = *rx_window_symb + 1;
}
@@ -2870,11 +2877,11 @@ void smtc_real_get_rx_window_parameters( lr1_stack_mac_t* lr1_mac, uint8_t datar
#endif
}
-void smtc_real_get_rx_start_time_offset_ms( lr1_stack_mac_t* lr1_mac, uint8_t datarate, int8_t board_delay_ms,
+void smtc_real_get_rx_start_time_offset_ms( smtc_real_t* real, uint8_t datarate, int8_t board_delay_ms,
uint16_t rx_window_symb, int32_t* rx_offset_ms )
{
- modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( lr1_mac, datarate );
- int32_t tsymbol_us = ( int32_t ) smtc_real_get_symbol_duration_us( lr1_mac, datarate );
+ modulation_type_t modulation_type = smtc_real_get_modulation_type_from_datarate( real, datarate );
+ int32_t tsymbol_us = ( int32_t ) smtc_real_get_symbol_duration_us( real, datarate );
if( modulation_type == FSK )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.h
index 8756ba4..d03aae0 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real.h
@@ -65,7 +65,7 @@ smtc_real_status_t smtc_real_is_supported_region( smtc_real_region_types_t regio
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_config( lr1_stack_mac_t* lr1_mac );
+void smtc_real_init( smtc_real_t* real, smtc_real_region_types_t region_type );
/**
* \brief
@@ -73,7 +73,7 @@ void smtc_real_config( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_init( lr1_stack_mac_t* lr1_mac );
+void smtc_real_config( smtc_real_t* real );
/**
* \brief
@@ -81,7 +81,7 @@ void smtc_real_init( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_init_session( lr1_stack_mac_t* lr1_mac );
+void smtc_real_config_session( smtc_real_t* real );
/**
* \brief
@@ -89,7 +89,7 @@ void smtc_real_init_session( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_dr_distribution( lr1_stack_mac_t* lr1_mac, uint8_t adr_mode );
+void smtc_real_set_dr_distribution( smtc_real_t* real, uint8_t adr_mode, uint8_t* out_nb_trans, uint32_t* adr_custom );
/**
* \brief
@@ -97,7 +97,8 @@ void smtc_real_set_dr_distribution( lr1_stack_mac_t* lr1_mac, uint8_t adr_mode )
* \param [IN] none
* \param [OUT] status_lorawan_t
*/
-status_lorawan_t smtc_real_get_next_dr( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t smtc_real_get_next_tx_dr( smtc_real_t* real, join_status_t join_status, dr_strategy_t* adr_mode_select,
+ uint8_t* tx_data_rate, uint8_t tx_data_rate_adr, bool* adr_enable );
/**
* \brief
@@ -105,7 +106,7 @@ status_lorawan_t smtc_real_get_next_dr( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] status_lorawan_t
*/
-uint16_t smtc_real_mask_tx_dr_channel( lr1_stack_mac_t* lr1_mac );
+uint16_t smtc_real_mask_tx_dr_channel( smtc_real_t* real );
/**
* \brief
@@ -113,15 +114,15 @@ uint16_t smtc_real_mask_tx_dr_channel( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] status_lorawan_t
*/
-uint16_t smtc_real_mask_tx_dr_channel_up_dwell_time_check( lr1_stack_mac_t* lr1_mac );
+uint16_t smtc_real_mask_tx_dr_channel_up_dwell_time_check( smtc_real_t* real );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @return cf_list_type_t
*/
-cf_list_type_t smtc_real_cf_list_type_supported( lr1_stack_mac_t* lr1_mac );
+cf_list_type_t smtc_real_cf_list_type_supported( smtc_real_t* real );
/**
* \brief
@@ -129,7 +130,7 @@ cf_list_type_t smtc_real_cf_list_type_supported( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t smtc_real_update_cflist( smtc_real_t* real, uint8_t* cf_list );
/**
* \brief
@@ -137,7 +138,7 @@ status_lorawan_t smtc_real_update_cflist( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_number_of_chmask_in_cflist( smtc_real_t* real );
/**
* \brief
@@ -145,7 +146,8 @@ uint8_t smtc_real_get_number_of_chmask_in_cflist( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_get_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t smtc_real_get_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency );
/**
* \brief
@@ -153,7 +155,9 @@ status_lorawan_t smtc_real_get_next_channel( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
+status_lorawan_t smtc_real_get_join_next_channel( smtc_real_t* real, smtc_dtc_t* dtc_obj, uint8_t* tx_data_rate,
+ uint32_t* out_tx_frequency, uint32_t* out_rx1_frequency,
+ uint32_t* out_rx2_frequency );
/**
* \brief
@@ -161,7 +165,7 @@ status_lorawan_t smtc_real_get_join_next_channel( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
+uint8_t smtc_real_get_rx1_datarate_config( smtc_real_t* real, uint8_t tx_data_rate, uint8_t rx1_dr_offset );
/**
* \brief
@@ -169,7 +173,7 @@ void smtc_real_set_rx_config( lr1_stack_mac_t* lr1_mac, rx_win_type_t type );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_power( lr1_stack_mac_t* lr1_mac, uint8_t power_cmd );
+int8_t smtc_real_convert_power_cmd( smtc_real_t* real, uint8_t power_cmd, uint8_t max_erp_dbm );
/**
* \brief
@@ -177,7 +181,7 @@ void smtc_real_set_power( lr1_stack_mac_t* lr1_mac, uint8_t power_cmd );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_channel_mask( lr1_stack_mac_t* lr1_mac );
+void smtc_real_set_channel_mask( smtc_real_t* real );
/**
* \brief
@@ -185,7 +189,7 @@ void smtc_real_set_channel_mask( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_init_channel_mask( lr1_stack_mac_t* lr1_mac );
+void smtc_real_init_channel_mask( smtc_real_t* real );
/**
* \brief
@@ -193,7 +197,7 @@ void smtc_real_init_channel_mask( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+void smtc_real_init_join_snapshot_channel_mask( smtc_real_t* real );
/**
* \brief
@@ -201,7 +205,7 @@ void smtc_real_init_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac );
+void smtc_real_init_after_join_snapshot_channel_mask( smtc_real_t* real, uint8_t tx_data_rate, uint32_t tx_frequency );
/**
* \brief
@@ -209,7 +213,7 @@ void smtc_real_init_after_join_snapshot_channel_mask( lr1_stack_mac_t* lr1_mac )
* \param [IN] none
* \param [OUT] return
*/
-status_channel_t smtc_real_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t ch_mask_cntl, uint16_t ch_mask );
+status_channel_t smtc_real_build_channel_mask( smtc_real_t* real, uint8_t ch_mask_cntl, uint16_t ch_mask );
/**
* \brief
@@ -217,7 +221,7 @@ status_channel_t smtc_real_build_channel_mask( lr1_stack_mac_t* lr1_mac, uint8_t
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_decrement_dr_simulation( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_decrement_dr_simulation( smtc_real_t* real, uint8_t tx_data_rate_adr );
/**
* \brief
@@ -225,7 +229,8 @@ uint8_t smtc_real_decrement_dr_simulation( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_decrement_dr( lr1_stack_mac_t* lr1_mac );
+void smtc_real_decrement_dr( smtc_real_t* real, dr_strategy_t adr_mode_select, uint8_t* tx_data_rate_adr,
+ int8_t* tx_power, uint8_t* nb_trans );
/**
* \brief
@@ -233,7 +238,7 @@ void smtc_real_decrement_dr( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
+void smtc_real_enable_all_channels_with_valid_freq( smtc_real_t* real );
/**
* \brief
@@ -241,7 +246,7 @@ void smtc_real_enable_all_channels_with_valid_freq( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_rx1_dr_offset_valid( lr1_stack_mac_t* lr1_mac, uint8_t rx1_dr_offset );
+status_lorawan_t smtc_real_is_rx1_dr_offset_valid( smtc_real_t* real, uint8_t rx1_dr_offset );
/**
* \brief
@@ -249,7 +254,7 @@ status_lorawan_t smtc_real_is_rx1_dr_offset_valid( lr1_stack_mac_t* lr1_mac, uin
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_rx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr );
+status_lorawan_t smtc_real_is_rx_dr_valid( smtc_real_t* real, uint8_t dr );
/**
* \brief
@@ -257,7 +262,7 @@ status_lorawan_t smtc_real_is_rx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_tx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr );
+status_lorawan_t smtc_real_is_tx_dr_valid( smtc_real_t* real, uint8_t dr );
/**
* \brief
@@ -265,7 +270,7 @@ status_lorawan_t smtc_real_is_tx_dr_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_t dr, bool is_ch_mask_from_link_adr );
+status_lorawan_t smtc_real_is_tx_dr_acceptable( smtc_real_t* real, uint8_t dr, bool is_ch_mask_from_link_adr );
/**
* \brief
@@ -273,7 +278,7 @@ status_lorawan_t smtc_real_is_tx_dr_acceptable( lr1_stack_mac_t* lr1_mac, uint8_
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_t frequency );
+status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( smtc_real_t* real, uint32_t frequency );
/**
* \brief
@@ -281,7 +286,7 @@ status_lorawan_t smtc_real_is_nwk_received_tx_frequency_valid( lr1_stack_mac_t*
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_channel_index_valid( lr1_stack_mac_t* lr1_mac, uint8_t channel_index );
+status_lorawan_t smtc_real_is_channel_index_valid( smtc_real_t* real, uint8_t channel_index );
/**
* \brief
@@ -289,8 +294,8 @@ status_lorawan_t smtc_real_is_channel_index_valid( lr1_stack_mac_t* lr1_mac, uin
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_payload_size_valid( lr1_stack_mac_t* lr1_mac, uint8_t dr, uint8_t size,
- uint8_t dwell_time_enabled );
+status_lorawan_t smtc_real_is_payload_size_valid( smtc_real_t* real, uint8_t dr, uint8_t size,
+ direction_frame_t direction_frame, uint8_t tx_fopts_current_length );
/**
* \brief
@@ -298,7 +303,7 @@ status_lorawan_t smtc_real_is_payload_size_valid( lr1_stack_mac_t* lr1_mac, uint
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t tx_freq, uint8_t index );
+void smtc_real_set_tx_frequency_channel( smtc_real_t* real, uint32_t tx_freq, uint8_t index );
/**
* \brief
@@ -306,7 +311,7 @@ void smtc_real_set_tx_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t tx_f
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_set_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac, uint32_t rx_freq, uint8_t index );
+status_lorawan_t smtc_real_set_rx1_frequency_channel( smtc_real_t* real, uint32_t rx_freq, uint8_t index );
/**
* \brief
@@ -314,7 +319,7 @@ status_lorawan_t smtc_real_set_rx1_frequency_channel( lr1_stack_mac_t* lr1_mac,
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index, uint8_t dr_min, uint8_t dr_max );
+void smtc_real_set_channel_dr( smtc_real_t* real, uint8_t channel_index, uint8_t dr_min, uint8_t dr_max );
/**
* \brief
@@ -322,7 +327,7 @@ void smtc_real_set_channel_dr( lr1_stack_mac_t* lr1_mac, uint8_t channel_index,
* \param [IN] none
* \param [OUT] return
*/
-void smtc_real_set_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t enable, uint8_t channel_index );
+void smtc_real_set_channel_enabled( smtc_real_t* real, uint8_t enable, uint8_t channel_index );
/**
* \brief
@@ -330,7 +335,7 @@ void smtc_real_set_channel_enabled( lr1_stack_mac_t* lr1_mac, uint8_t enable, ui
* \param [IN] none
* \param [OUT] return
*/
-uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t smtc_real_get_tx_channel_frequency( smtc_real_t* real, uint8_t index );
/**
* \brief
@@ -338,7 +343,7 @@ uint32_t smtc_real_get_tx_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t i
* \param [IN] none
* \param [OUT] return
*/
-uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t index );
+uint32_t smtc_real_get_rx1_channel_frequency( smtc_real_t* real, uint8_t index );
/**
* \brief
@@ -346,7 +351,7 @@ uint32_t smtc_real_get_rx1_channel_frequency( lr1_stack_mac_t* lr1_mac, uint8_t
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_min_tx_channel_dr( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_min_tx_channel_dr( smtc_real_t* real );
/**
* \brief
@@ -354,7 +359,7 @@ uint8_t smtc_real_get_min_tx_channel_dr( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_max_tx_channel_dr( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_max_tx_channel_dr( smtc_real_t* real );
/**
* \brief
@@ -363,7 +368,7 @@ uint8_t smtc_real_get_max_tx_channel_dr( lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-uint8_t smtc_real_get_preamble_len( const lr1_stack_mac_t* lr1_mac, uint8_t sf );
+uint8_t smtc_real_get_preamble_len( const smtc_real_t* real, uint8_t sf );
/**
* \brief
@@ -372,7 +377,7 @@ uint8_t smtc_real_get_preamble_len( const lr1_stack_mac_t* lr1_mac, uint8_t sf )
* \param [OUT] return
*
*/
-status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_t* lr1_mac );
+status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const smtc_real_t* real );
/*************************************************************************/
/* Const init in region */
@@ -385,7 +390,7 @@ status_lorawan_t smtc_real_is_channel_mask_for_mobile_mode( const lr1_stack_mac_
* \param [OUT] return
*
*/
-bool smtc_real_is_tx_param_setup_req_supported( lr1_stack_mac_t* lr1_mac );
+bool smtc_real_is_tx_param_setup_req_supported( smtc_real_t* real );
/**
* \brief
@@ -394,7 +399,7 @@ bool smtc_real_is_tx_param_setup_req_supported( lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-bool smtc_real_is_new_channel_req_supported( lr1_stack_mac_t* lr1_mac );
+bool smtc_real_is_new_channel_req_supported( smtc_real_t* real );
/**
* \brief
@@ -402,7 +407,7 @@ bool smtc_real_is_new_channel_req_supported( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_rx1_join_delay( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_rx1_join_delay( smtc_real_t* real );
/**
* \brief
@@ -410,7 +415,7 @@ uint8_t smtc_real_get_rx1_join_delay( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_rx2_join_dr( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_rx2_join_dr( smtc_real_t* real );
/**
* \brief
@@ -418,7 +423,7 @@ uint8_t smtc_real_get_rx2_join_dr( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_frequency_factor( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_frequency_factor( smtc_real_t* real );
/**
* \brief
@@ -427,7 +432,7 @@ uint8_t smtc_real_get_frequency_factor( lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-ral_lora_cr_t smtc_real_get_coding_rate( lr1_stack_mac_t* lr1_mac );
+ral_lora_cr_t smtc_real_get_coding_rate( smtc_real_t* real );
/**
* \brief
@@ -435,7 +440,7 @@ ral_lora_cr_t smtc_real_get_coding_rate( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_adr_ack_delay( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_adr_ack_delay( smtc_real_t* real );
/**
* \brief
@@ -443,23 +448,23 @@ uint8_t smtc_real_get_adr_ack_delay( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_adr_ack_limit( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_adr_ack_limit( smtc_real_t* real );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @return uint8_t
*/
-uint8_t smtc_real_get_public_sync_word( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_public_sync_word( smtc_real_t* real );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @return uint8_t
*/
-uint8_t smtc_real_get_private_sync_word( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_private_sync_word( smtc_real_t* real );
/**
* \brief
@@ -467,15 +472,15 @@ uint8_t smtc_real_get_private_sync_word( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_sync_word( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_sync_word( smtc_real_t* real );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @param sync_word
*/
-void smtc_real_set_sync_word( lr1_stack_mac_t* lr1_mac, uint8_t sync_word );
+void smtc_real_set_sync_word( smtc_real_t* real, uint8_t sync_word );
/**
* \brief
@@ -483,7 +488,7 @@ void smtc_real_set_sync_word( lr1_stack_mac_t* lr1_mac, uint8_t sync_word );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t* smtc_real_get_gfsk_sync_word( lr1_stack_mac_t* lr1_mac );
+uint8_t* smtc_real_get_gfsk_sync_word( smtc_real_t* real );
/**
* \brief
@@ -491,7 +496,7 @@ uint8_t* smtc_real_get_gfsk_sync_word( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t* smtc_real_get_lr_fhss_sync_word( lr1_stack_mac_t* lr1_mac );
+uint8_t* smtc_real_get_lr_fhss_sync_word( smtc_real_t* real );
/**
* \brief
@@ -499,7 +504,7 @@ uint8_t* smtc_real_get_lr_fhss_sync_word( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_max_payload_size( lr1_stack_mac_t* lr1_mac, uint8_t dr, uint8_t dwell_time_enabled );
+uint8_t smtc_real_get_max_payload_size( smtc_real_t* real, uint8_t dr, direction_frame_t direction_frame );
/**
* \brief
@@ -507,7 +512,7 @@ uint8_t smtc_real_get_max_payload_size( lr1_stack_mac_t* lr1_mac, uint8_t dr, ui
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_default_max_eirp( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_default_max_eirp( smtc_real_t* real );
/**
* \brief
@@ -515,7 +520,17 @@ uint8_t smtc_real_get_default_max_eirp( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint8_t smtc_real_get_beacon_dr( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_beacon_dr( smtc_real_t* real );
+
+/**
+ * @brief Check if in current region beacon hops in frequency
+ * @remark use to check validity of freq 0 in class B multicast session
+ *
+ * @param [in] real
+ * @return true
+ * @return false
+ */
+bool smtc_real_is_beacon_hopping( smtc_real_t* real );
/**
* \brief
@@ -523,7 +538,7 @@ uint8_t smtc_real_get_beacon_dr( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint32_t smtc_real_get_beacon_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s );
+uint32_t smtc_real_get_beacon_frequency( smtc_real_t* real, uint32_t gps_time_s );
/**
* \brief
@@ -531,15 +546,31 @@ uint32_t smtc_real_get_beacon_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_
* \param [IN] none
* \param [OUT] return
*/
-uint32_t smtc_real_get_ping_slot_frequency( lr1_stack_mac_t* lr1_mac, uint32_t gps_time_s, uint32_t dev_addr );
+uint32_t smtc_real_get_ping_slot_frequency( smtc_real_t* real, uint32_t gps_time_s, uint32_t dev_addr );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @return uint8_t
*/
-uint8_t smtc_real_get_ping_slot_datarate( lr1_stack_mac_t* lr1_mac );
+uint8_t smtc_real_get_ping_slot_datarate( smtc_real_t* real );
+
+/**
+ * @brief
+ *
+ * @param real
+ * @param dwell_time
+ */
+void smtc_real_set_uplink_dwell_time( smtc_real_t* real, bool dwell_time );
+
+/**
+ * @brief
+ *
+ * @param real
+ * @param dwell_time
+ */
+void smtc_real_set_downlink_dwell_time( smtc_real_t* real, bool dwell_time );
/**
* \brief
@@ -547,7 +578,7 @@ uint8_t smtc_real_get_ping_slot_datarate( lr1_stack_mac_t* lr1_mac );
* \param [IN] none
* \param [OUT] return
*/
-uint32_t smtc_real_decode_freq_from_buf( lr1_stack_mac_t* lr1_mac, uint8_t freq_buf[3] );
+uint32_t smtc_real_decode_freq_from_buf( smtc_real_t* real, uint8_t freq_buf[3] );
/**
* \brief
@@ -555,7 +586,7 @@ uint32_t smtc_real_decode_freq_from_buf( lr1_stack_mac_t* lr1_mac, uint8_t freq_
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_t frequency );
+status_lorawan_t smtc_real_is_frequency_valid( smtc_real_t* real, uint32_t frequency );
/**
* \brief
@@ -563,7 +594,7 @@ status_lorawan_t smtc_real_is_frequency_valid( lr1_stack_mac_t* lr1_mac, uint32_
* \param [IN] none
* \param [OUT] return
*/
-status_lorawan_t smtc_real_is_tx_power_valid( lr1_stack_mac_t* lr1_mac, uint8_t power );
+status_lorawan_t smtc_real_is_tx_power_valid( smtc_real_t* real, uint8_t power );
/**
* \brief
@@ -572,7 +603,7 @@ status_lorawan_t smtc_real_is_tx_power_valid( lr1_stack_mac_t* lr1_mac, uint8_t
* \param [OUT] return
*
*/
-bool smtc_real_is_dtc_supported( const lr1_stack_mac_t* lr1_mac );
+bool smtc_real_is_dtc_supported( const smtc_real_t* real );
/**
* \brief
@@ -581,7 +612,7 @@ bool smtc_real_is_dtc_supported( const lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-bool smtc_real_is_lbt_supported( const lr1_stack_mac_t* lr1_mac );
+bool smtc_real_is_lbt_supported( const smtc_real_t* real );
/**
* \brief
@@ -590,7 +621,7 @@ bool smtc_real_is_lbt_supported( const lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-uint32_t smtc_real_get_lbt_duration_ms( const lr1_stack_mac_t* lr1_mac );
+uint32_t smtc_real_get_lbt_duration_ms( const smtc_real_t* real );
/**
* \brief
@@ -599,7 +630,7 @@ uint32_t smtc_real_get_lbt_duration_ms( const lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-int16_t smtc_real_get_lbt_threshold_dbm( const lr1_stack_mac_t* lr1_mac );
+int16_t smtc_real_get_lbt_threshold_dbm( const smtc_real_t* real );
/**
* \brief
@@ -608,51 +639,51 @@ int16_t smtc_real_get_lbt_threshold_dbm( const lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-uint32_t smtc_real_get_lbt_bw_hz( const lr1_stack_mac_t* lr1_mac );
+uint32_t smtc_real_get_lbt_bw_hz( const smtc_real_t* real );
/**
* @brief Get the corresponding RF modulation from a Datarate
*
- * @param lr1_mac
+ * @param real
* @param datarate
* @return modulation_type_t
*/
-modulation_type_t smtc_real_get_modulation_type_from_datarate( lr1_stack_mac_t* lr1_mac, uint8_t datarate );
+modulation_type_t smtc_real_get_modulation_type_from_datarate( smtc_real_t* real, uint8_t datarate );
/**
* @brief Convert LoRaWAN Datarate to LoRa SF and BW
*
- * @param lr1_mac
+ * @param real
* @param in_dr
* @param out_sf
* @param out_bw
*/
-void smtc_real_lora_dr_to_sf_bw( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw );
+void smtc_real_lora_dr_to_sf_bw( smtc_real_t* real, uint8_t in_dr, uint8_t* out_sf, lr1mac_bandwidth_t* out_bw );
/**
* @brief Convert LoRaWAN Datarate to FSK bitrate
*
- * @param lr1_mac
+ * @param real
* @param in_dr
* @param out_bitrate
*/
-void smtc_real_fsk_dr_to_bitrate( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, uint8_t* out_bitrate );
+void smtc_real_fsk_dr_to_bitrate( smtc_real_t* real, uint8_t in_dr, uint8_t* out_bitrate );
/**
* @brief Convert LoRaWAN Datarate to LR-FHSS CR and BW
*
- * @param lr1_mac
+ * @param real
* @param in_dr
* @param out_cr
* @param out_bw
*/
-void smtc_real_lr_fhss_dr_to_cr_bw( lr1_stack_mac_t* lr1_mac, uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
+void smtc_real_lr_fhss_dr_to_cr_bw( smtc_real_t* real, uint8_t in_dr, lr_fhss_v1_cr_t* out_cr,
lr_fhss_v1_bw_t* out_bw );
/**
* @brief Get LR-FHSS header count from LR-FHSS CR
*
- * @param lr1_mac
+ * @param real
* @param in_cr
* @return lr_fhss_hc_t
*/
@@ -661,11 +692,11 @@ lr_fhss_hc_t smtc_real_lr_fhss_get_header_count( lr_fhss_v1_cr_t in_cr );
/**
* @brief Get LR-FHSS grid
*
- * @param lr1_mac
+ * @param real
* @return lr_fhss_v1_grid_t
*
*/
-lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( lr1_stack_mac_t* lr1_mac );
+lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( smtc_real_t* real );
/*!
* \brief
@@ -674,25 +705,25 @@ lr_fhss_v1_grid_t smtc_real_lr_fhss_get_grid( lr1_stack_mac_t* lr1_mac );
* \param [OUT] return
*
*/
-int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( lr1_stack_mac_t* lr1_mac, int8_t tx_power,
- uint32_t tx_frequency, uint8_t datarate );
+int8_t smtc_real_clamp_output_power_eirp_vs_freq_and_dr( smtc_real_t* real, int8_t tx_power, uint32_t tx_frequency,
+ uint8_t datarate );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @param number_of_freq
* @param freq_list
* @param max_size
* @return uint8_t
*/
-uint8_t smtc_real_get_current_enabled_frequency_list( lr1_stack_mac_t* lr1_mac, uint8_t* number_of_freq,
- uint32_t* freq_list, uint8_t max_size );
+uint8_t smtc_real_get_current_enabled_frequency_list( smtc_real_t* real, uint8_t* number_of_freq, uint32_t* freq_list,
+ uint8_t max_size );
/**
* @brief
*
- * @param lr1_mac
+ * @param real
* @return lr1mac_version_t
*/
lr1mac_version_t smtc_real_get_regional_parameters_version( void );
@@ -703,7 +734,7 @@ lr1mac_version_t smtc_real_get_regional_parameters_version( void );
* @param
* @return
*/
-uint32_t smtc_real_get_symbol_duration_us( lr1_stack_mac_t* lr1_mac, uint8_t datarate );
+uint32_t smtc_real_get_symbol_duration_us( smtc_real_t* real, uint8_t datarate );
/**
* @brief
@@ -711,9 +742,10 @@ uint32_t smtc_real_get_symbol_duration_us( lr1_stack_mac_t* lr1_mac, uint8_t dat
* @param
* @return
*/
-void smtc_real_get_rx_window_parameters( lr1_stack_mac_t* lr1_mac, uint8_t datarate, uint32_t rx_delay_ms,
+void smtc_real_get_rx_window_parameters( smtc_real_t* real, uint8_t datarate, uint32_t rx_delay_ms,
uint16_t* rx_window_symb, uint32_t* rx_timeout_symb_in_ms,
- uint32_t* rx_timeout_preamble_locked_in_ms, uint8_t rx_done_incertitude );
+ uint32_t* rx_timeout_preamble_locked_in_ms, uint8_t rx_done_incertitude,
+ uint32_t crystal_error );
/**
* @brief
*
@@ -721,7 +753,7 @@ void smtc_real_get_rx_window_parameters( lr1_stack_mac_t* lr1_mac, uint8_t datar
* @return
*/
-void smtc_real_get_rx_start_time_offset_ms( lr1_stack_mac_t* lr1_mac, uint8_t datarate, int8_t board_delay_ms,
+void smtc_real_get_rx_start_time_offset_ms( smtc_real_t* real, uint8_t datarate, int8_t board_delay_ms,
uint16_t rx_window_symb, int32_t* rx_offset_ms );
#ifdef __cplusplus
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h
index e57d762..892ff72 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/lr1mac/src/smtc_real/src/smtc_real_defs.h
@@ -232,6 +232,8 @@ typedef struct smtc_real_ctx_s
uint8_t* dr_distribution_init_ctx;
uint8_t* dr_distribution_ctx;
uint8_t sync_word_ctx;
+ bool uplink_dwell_time_ctx;
+ bool downlink_dwell_time_ctx;
} smtc_real_ctx_t;
typedef struct smtc_real_const_s
@@ -246,6 +248,7 @@ typedef struct smtc_real_const_s
uint8_t const_max_tx_power_idx;
uint8_t const_adr_ack_limit;
uint8_t const_adr_ack_delay;
+ const uint8_t* const_datarate_offsets;
const uint8_t* const_datarate_backoff;
uint8_t const_ack_timeout;
uint32_t const_freq_min;
@@ -278,6 +281,7 @@ typedef struct smtc_real_const_s
ral_lora_cr_t const_coding_rate;
uint8_t const_dtc_number_of_band;
const uint16_t* const_dtc_by_band;
+ const uint32_t* const_dtc_frequency_range_by_band;
const uint8_t* const_mobile_longrange_dr_distri;
const uint8_t* const_mobile_lowpower_dr_distri;
const uint8_t* const_join_dr_distri;
@@ -286,59 +290,9 @@ typedef struct smtc_real_const_s
uint8_t const_beacon_dr;
uint32_t const_beacon_frequency;
uint32_t const_ping_slot_frequency;
+ bool const_uplink_dwell_time;
} smtc_real_const_t;
-#define const_number_of_tx_channel lr1_mac->real->real_const.const_number_of_tx_channel
-#define const_number_of_rx_channel lr1_mac->real->real_const.const_number_of_rx_channel
-#define const_number_of_boot_tx_channel lr1_mac->real->real_const.const_number_of_boot_tx_channel
-#define const_number_of_channel_bank lr1_mac->real->real_const.const_number_of_channel_bank
-#define const_join_accept_delay1 lr1_mac->real->real_const.const_join_accept_delay1
-#define const_received_delay1 lr1_mac->real->real_const.const_received_delay1
-#define const_tx_power_dbm lr1_mac->real->real_const.const_tx_power_dbm
-#define const_max_tx_power_idx lr1_mac->real->real_const.const_max_tx_power_idx
-#define const_adr_ack_limit lr1_mac->real->real_const.const_adr_ack_limit
-#define const_adr_ack_delay lr1_mac->real->real_const.const_adr_ack_delay
-#define const_datarate_backoff lr1_mac->real->real_const.const_datarate_backoff
-#define const_ack_timeout lr1_mac->real->real_const.const_ack_timeout
-#define const_freq_min lr1_mac->real->real_const.const_freq_min
-#define const_freq_max lr1_mac->real->real_const.const_freq_max
-#define const_rx2_freq lr1_mac->real->real_const.const_rx2_freq
-#define const_frequency_factor lr1_mac->real->real_const.const_frequency_factor
-#define const_frequency_offset_hz lr1_mac->real->real_const.const_frequency_offset_hz
-#define const_rx2_dr_init lr1_mac->real->real_const.const_rx2_dr_init
-#define const_sync_word_public lr1_mac->real->real_const.const_sync_word_public
-#define const_sync_word_private lr1_mac->real->real_const.const_sync_word_private
-#define const_sync_word_gfsk lr1_mac->real->real_const.const_sync_word_gfsk
-#define const_sync_word_lr_fhss lr1_mac->real->real_const.const_sync_word_lr_fhss
-#define const_min_tx_dr lr1_mac->real->real_const.const_min_tx_dr
-#define const_min_tx_dr_limit lr1_mac->real->real_const.const_min_tx_dr_limit
-#define const_min_rx_dr lr1_mac->real->real_const.const_min_rx_dr
-#define const_max_tx_dr lr1_mac->real->real_const.const_max_tx_dr
-#define const_max_rx_dr lr1_mac->real->real_const.const_max_rx_dr
-#define const_dr_bitfield lr1_mac->real->real_const.const_dr_bitfield
-#define const_default_tx_dr_bit_field lr1_mac->real->real_const.const_default_tx_dr_bit_field
-#define const_number_of_tx_dr lr1_mac->real->real_const.const_number_of_tx_dr
-#define const_number_rx1_dr_offset lr1_mac->real->real_const.const_number_rx1_dr_offset
-#define const_tx_param_setup_req_supported lr1_mac->real->real_const.const_tx_param_setup_req_supported
-#define const_new_channel_req_supported lr1_mac->real->real_const.const_new_channel_req_supported
-#define const_dtc_supported lr1_mac->real->real_const.const_dtc_supported
-#define const_lbt_supported lr1_mac->real->real_const.const_lbt_supported
-#define const_lbt_sniff_duration_ms lr1_mac->real->real_const.const_lbt_sniff_duration_ms
-#define const_lbt_threshold_dbm lr1_mac->real->real_const.const_lbt_threshold_dbm
-#define const_lbt_bw_hz lr1_mac->real->real_const.const_lbt_bw_hz
-#define const_max_payload_m lr1_mac->real->real_const.const_max_payload_m
-#define const_coding_rate lr1_mac->real->real_const.const_coding_rate
-#define const_dtc_number_of_band lr1_mac->real->real_const.const_dtc_number_of_band
-#define const_dtc_by_band lr1_mac->real->real_const.const_dtc_by_band
-#define const_mobile_longrange_dr_distri lr1_mac->real->real_const.const_mobile_longrange_dr_distri
-#define const_mobile_lowpower_dr_distri lr1_mac->real->real_const.const_mobile_lowpower_dr_distri
-#define const_join_dr_distri lr1_mac->real->real_const.const_join_dr_distri
-#define const_default_dr_distri lr1_mac->real->real_const.const_default_dr_distri
-#define const_cf_list_type_supported lr1_mac->real->real_const.const_cf_list_type_supported
-#define const_beacon_dr lr1_mac->real->real_const.const_beacon_dr
-#define const_beacon_frequency lr1_mac->real->real_const.const_beacon_frequency
-#define const_ping_slot_frequency lr1_mac->real->real_const.const_ping_slot_frequency
-
typedef struct smtc_real_s
{
smtc_real_region_types_t region_type;
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem.c
index c749471..c2ec772 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem.c
@@ -130,6 +130,12 @@
#define MODEM_FW_VERSION_PATCH 8
#endif
+#define MODEM_MAX_ALARM_VALUE_S ( 864000 ) // 10 days in seconds
+
+/**
+ * @brief Maximum payload size in byte of LoRaWAN payload
+ */
+#define SMTC_MODEM_MAX_LORAWAN_PAYLOAD_LENGTH 242
/*
* -----------------------------------------------------------------------------
* --- PRIVATE TYPES -----------------------------------------------------------
@@ -432,7 +438,7 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_
event->event_data.class_b_status.status =
( smtc_modem_event_class_b_status_t ) get_modem_event_status( event->event_type );
break;
-#if defined( ADD_D2D )
+#if defined( SMTC_D2D )
case SMTC_MODEM_EVENT_D2D_CLASS_B_TX_DONE: {
modem_context_class_b_d2d_t class_b_d2d;
modem_context_get_class_b_d2d_last_metadata( &class_b_d2d );
@@ -442,7 +448,7 @@ smtc_modem_return_code_t smtc_modem_get_event( smtc_modem_event_t* event, uint8_
( smtc_modem_d2d_class_b_tx_done_status_t ) get_modem_event_status( event->event_type );
break;
}
-#endif // ADD_D2D
+#endif // SMTC_D2D
case SMTC_MODEM_EVENT_MIDDLEWARE_1:
case SMTC_MODEM_EVENT_MIDDLEWARE_2:
case SMTC_MODEM_EVENT_MIDDLEWARE_3:
@@ -829,10 +835,13 @@ smtc_modem_return_code_t smtc_modem_get_status( uint8_t stack_id, smtc_modem_sta
smtc_modem_return_code_t smtc_modem_alarm_start_timer( uint32_t alarm_s )
{
RETURN_BUSY_IF_TEST_MODE( );
+ if( alarm_s > MODEM_MAX_ALARM_VALUE_S )
+ {
+ return SMTC_MODEM_RC_INVALID;
+ }
- smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK;
modem_set_user_alarm( ( alarm_s > 0 ) ? ( smtc_modem_hal_get_time_in_s( ) + alarm_s ) : 0 );
- return return_code;
+ return SMTC_MODEM_RC_OK;
}
smtc_modem_return_code_t smtc_modem_alarm_clear_timer( void )
@@ -1549,10 +1558,6 @@ smtc_modem_return_code_t smtc_modem_dm_request_single_uplink( const uint8_t* dm_
else
{
return_code = smtc_modem_set_dm_status_with_rate( dm_fields_payload, dm_field_length, DM_INFO_NOW );
- if( return_code == SMTC_MODEM_RC_OK )
- {
- modem_supervisor_add_task_dm_status_now( );
- }
}
return return_code;
}
@@ -2941,7 +2946,7 @@ static bool is_modem_connected( )
static smtc_modem_return_code_t smtc_modem_send_empty_tx( uint8_t f_port, bool f_port_present, bool confirmed )
{
smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK;
- smodem_task task_send;
+ smodem_task task_send = { 0 };
if( is_modem_connected( ) == false )
{
@@ -2976,13 +2981,16 @@ static smtc_modem_return_code_t smtc_modem_send_tx( uint8_t f_port, bool confirm
uint8_t payload_length, bool emergency, uint8_t tx_buffer_id )
{
smtc_modem_return_code_t return_code = SMTC_MODEM_RC_OK;
- smodem_task task_send;
+ smodem_task task_send = { 0 };
if( is_modem_connected( ) == false )
{
return_code = SMTC_MODEM_RC_FAIL;
}
-
+ else if( payload_length > SMTC_MODEM_MAX_LORAWAN_PAYLOAD_LENGTH )
+ {
+ return_code = SMTC_MODEM_RC_INVALID;
+ }
else if( ( ( ( f_port == 0 ) || ( f_port >= 224 ) ) && !lorawan_api_modem_certification_is_enabled( ) ) ||
( f_port == get_modem_dm_port( ) ) )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem_test.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem_test.c
index 8156ccd..96d1188 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem_test.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_core/smtc_modem_test.c
@@ -273,7 +273,7 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l
SMTC_MODEM_HAL_TRACE_WARNING( "TEST FUNCTION CANNOT BE CALLED: NOT IN TEST MODE\n" );
return SMTC_MODEM_RC_INVALID;
}
- if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj, frequency_hz ) != OKLORAWAN )
+ if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj->real, frequency_hz ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( "Invalid Frequency %d\n", frequency_hz );
return SMTC_MODEM_RC_INVALID;
@@ -305,15 +305,15 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
- gfsk_param.rf_freq_in_hz = frequency_hz;
- gfsk_param.output_pwr_in_dbm = tx_power_dbm;
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( modem_test_context.lr1_mac_obj );
- gfsk_param.dc_free_is_on = true;
- gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
- gfsk_param.crc_seed = GFSK_CRC_SEED;
- gfsk_param.crc_polynomial = GFSK_CRC_POLYNOMIAL;
- gfsk_param.pkt_params.header_type = RAL_GFSK_PKT_VAR_LEN;
- gfsk_param.pkt_params.pld_len_in_bytes = payload_length;
+ gfsk_param.rf_freq_in_hz = frequency_hz;
+ gfsk_param.output_pwr_in_dbm = tx_power_dbm;
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( modem_test_context.lr1_mac_obj->real );
+ gfsk_param.dc_free_is_on = true;
+ gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
+ gfsk_param.crc_seed = GFSK_CRC_SEED;
+ gfsk_param.crc_polynomial = GFSK_CRC_POLYNOMIAL;
+ gfsk_param.pkt_params.header_type = RAL_GFSK_PKT_VAR_LEN;
+ gfsk_param.pkt_params.pld_len_in_bytes = payload_length;
gfsk_param.pkt_params.preamble_len_in_bits = 40;
gfsk_param.pkt_params.sync_word_len_in_bits = 24;
gfsk_param.pkt_params.dc_free = RAL_GFSK_DC_FREE_WHITENING;
@@ -342,7 +342,7 @@ smtc_modem_return_code_t smtc_modem_test_tx( uint8_t* payload, uint8_t payload_l
lora_param.rf_freq_in_hz = frequency_hz;
lora_param.output_pwr_in_dbm = tx_power_dbm;
- lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj );
+ lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj->real );
lora_param.pkt_params.preamble_len_in_symb = preamble_size;
lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
@@ -419,7 +419,7 @@ smtc_modem_return_code_t smtc_modem_test_tx_cw( uint32_t frequency_hz, int8_t tx
SMTC_MODEM_HAL_TRACE_WARNING( "TEST FUNCTION CANNOT BE CALLED: NOT IN TEST MODE\n" );
return SMTC_MODEM_RC_INVALID;
}
- if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj, frequency_hz ) != OKLORAWAN )
+ if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj->real, frequency_hz ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( "Invalid Frequency %d\n", frequency_hz );
return SMTC_MODEM_RC_INVALID;
@@ -436,10 +436,17 @@ smtc_modem_return_code_t smtc_modem_test_tx_cw( uint32_t frequency_hz, int8_t tx
#elif defined( SX126X )
lora_param.mod_params.bw = RAL_LORA_BW_125_KHZ;
#elif defined( LR11XX )
- lora_param.mod_params.bw = RAL_LORA_BW_125_KHZ;
+ if( frequency_hz >= 2400000000 )
+ {
+ lora_param.mod_params.bw = RAL_LORA_BW_800_KHZ;
+ }
+ else
+ {
+ lora_param.mod_params.bw = RAL_LORA_BW_125_KHZ;
+ }
#endif
- lora_param.mod_params.cr = smtc_real_get_coding_rate( modem_test_context.lr1_mac_obj );
- lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj );
+ lora_param.mod_params.cr = smtc_real_get_coding_rate( modem_test_context.lr1_mac_obj->real );
+ lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj->real );
rp_radio_params_t radio_params = { 0 };
radio_params.pkt_type = RAL_PKT_TYPE_LORA;
@@ -450,7 +457,7 @@ smtc_modem_return_code_t smtc_modem_test_tx_cw( uint32_t frequency_hz, int8_t tx
rp_task.state = RP_TASK_STATE_ASAP;
rp_task.start_time_ms = smtc_modem_hal_get_time_in_ms( ) + 2;
rp_task.duration_time_ms = 2000; // toa;
- rp_task.type = RP_TASK_TYPE_RX_LORA;
+ rp_task.type = RP_TASK_TYPE_TX_LORA;
rp_task.launch_task_callbacks = test_mode_cw_callback_for_rp;
if( rp_task_enqueue( modem_test_context.rp, &rp_task, NULL, 0, &radio_params ) != RP_HOOK_STATUS_OK )
@@ -470,7 +477,7 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s
SMTC_MODEM_HAL_TRACE_WARNING( "TEST FUNCTION CANNOT BE CALLED: NOT IN TEST MODE\n" );
return SMTC_MODEM_RC_INVALID;
}
- if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj, frequency_hz ) != OKLORAWAN )
+ if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj->real, frequency_hz ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( "Invalid Frequency %u\n", frequency_hz );
return SMTC_MODEM_RC_INVALID;
@@ -507,14 +514,14 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s
ralf_params_gfsk_t gfsk_param;
memset( &gfsk_param, 0, sizeof( ralf_params_gfsk_t ) );
- gfsk_param.rf_freq_in_hz = frequency_hz;
- gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( modem_test_context.lr1_mac_obj );
- gfsk_param.dc_free_is_on = true;
- gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
- gfsk_param.crc_seed = GFSK_CRC_SEED;
- gfsk_param.crc_polynomial = GFSK_CRC_POLYNOMIAL;
- gfsk_param.pkt_params.header_type = RAL_GFSK_PKT_VAR_LEN;
- gfsk_param.pkt_params.pld_len_in_bytes = 255;
+ gfsk_param.rf_freq_in_hz = frequency_hz;
+ gfsk_param.sync_word = smtc_real_get_gfsk_sync_word( modem_test_context.lr1_mac_obj->real );
+ gfsk_param.dc_free_is_on = true;
+ gfsk_param.whitening_seed = GFSK_WHITENING_SEED;
+ gfsk_param.crc_seed = GFSK_CRC_SEED;
+ gfsk_param.crc_polynomial = GFSK_CRC_POLYNOMIAL;
+ gfsk_param.pkt_params.header_type = RAL_GFSK_PKT_VAR_LEN;
+ gfsk_param.pkt_params.pld_len_in_bytes = 255;
gfsk_param.pkt_params.preamble_len_in_bits = 40;
gfsk_param.pkt_params.sync_word_len_in_bits = 24;
gfsk_param.pkt_params.dc_free = RAL_GFSK_DC_FREE_WHITENING;
@@ -540,11 +547,11 @@ smtc_modem_return_code_t smtc_modem_test_rx_continuous( uint32_t frequency_hz, s
memset( &lora_param, 0, sizeof( ralf_params_lora_t ) );
lora_param.rf_freq_in_hz = frequency_hz;
- lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj );
+ lora_param.sync_word = smtc_real_get_sync_word( modem_test_context.lr1_mac_obj->real );
lora_param.symb_nb_timeout = 0;
lora_param.pkt_params.preamble_len_in_symb =
- smtc_real_get_preamble_len( modem_test_context.lr1_mac_obj, modem_test_sf_convert[sf] );
+ smtc_real_get_preamble_len( modem_test_context.lr1_mac_obj->real, modem_test_sf_convert[sf] );
lora_param.pkt_params.header_type = RAL_LORA_PKT_EXPLICIT;
lora_param.pkt_params.pld_len_in_bytes = 255;
lora_param.pkt_params.crc_is_on = false;
@@ -601,7 +608,7 @@ smtc_modem_return_code_t smtc_modem_test_rssi( uint32_t frequency_hz, smtc_modem
SMTC_MODEM_HAL_TRACE_WARNING( "TEST FUNCTION CANNOT BE CALLED: NOT IN TEST MODE\n" );
return SMTC_MODEM_RC_INVALID;
}
- if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj, frequency_hz ) != OKLORAWAN )
+ if( smtc_real_is_frequency_valid( modem_test_context.lr1_mac_obj->real, frequency_hz ) != OKLORAWAN )
{
SMTC_MODEM_HAL_TRACE_ERROR( " Invalid Frequency %d\n", frequency_hz );
return SMTC_MODEM_RC_INVALID;
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.c
index 6599346..24a5ccf 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.c
@@ -1,289 +1,289 @@
-/*!
- * \file fifo_ctrl.c
- *
- * \brief
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-#include // C99 types
-#include // bool type
-#include
-
-#include "fifo_ctrl.h"
-#include "smtc_modem_hal.h"
-#include "smtc_modem_hal_dbg_trace.h"
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE CONSTANTS -------------------------------------------------------
- */
-
-#define LEN_DATA_SIZE ( 2 )
-#define LEN_METADATA_SIZE ( 1 )
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE TYPES -----------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE VARIABLES -------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
- */
-static fifo_return_status_t ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
- const void* metadata, const uint8_t metadata_len );
-
-static fifo_return_status_t ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
- const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
- const uint8_t metadata_buffer_size );
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
- */
-
-void fifo_ctrl_init( fifo_ctrl_t* ctrl, uint8_t* buffer, const uint16_t buffer_size )
-{
- ctrl->buffer = buffer;
- ctrl->buffer_size = buffer_size;
- fifo_ctrl_clear( ctrl );
-}
-
-void fifo_ctrl_clear( fifo_ctrl_t* ctrl )
-{
- ctrl->read_offset = 0;
- ctrl->write_offset = 0;
- ctrl->nb_element = 0;
- ctrl->write_cnt = 0;
- ctrl->read_cnt = 0;
- ctrl->drop_cnt = 0;
- ctrl->free_space = ctrl->buffer_size;
-}
-
-void fifo_ctrl_print_stat( const fifo_ctrl_t* ctrl )
-{
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "----------------------------------\n" );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "fifo_ctrl_print_stat\n" );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Buffer size : %d\n", ctrl->buffer_size );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Current elt : %d\n", ctrl->nb_element );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Free space : %d\n", ctrl->free_space );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Write : %d\n", ctrl->write_cnt );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Read : %d\n", ctrl->read_cnt - ctrl->drop_cnt );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Drop : %d\n", ctrl->drop_cnt );
- SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "----------------------------------\n" );
-}
-
-uint16_t fifo_ctrl_get_nb_elt( const fifo_ctrl_t* ctrl )
-{
- return ctrl->nb_element;
-}
-
-uint16_t fifo_ctrl_get_free_space( const fifo_ctrl_t* ctrl )
-{
- return ctrl->free_space;
-}
-
-fifo_return_status_t fifo_ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
- const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
- const uint8_t metadata_buffer_size )
-{
- smtc_modem_hal_disable_modem_irq( );
- fifo_return_status_t ret =
- ctrl_get( ctrl, buffer, data_len, data_buffer_size, metadata, metadata_len, metadata_buffer_size );
- smtc_modem_hal_enable_modem_irq( );
-
- return ret;
-}
-
-fifo_return_status_t fifo_ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
- const void* metadata, const uint8_t metadata_len )
-{
- smtc_modem_hal_disable_modem_irq( );
- fifo_return_status_t ret = ctrl_set( ctrl, buffer, buffer_len, metadata, metadata_len );
- smtc_modem_hal_enable_modem_irq( );
- return ret;
-}
-
-static fifo_return_status_t ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
- const void* metadata, const uint8_t metadata_len )
-{
- uint16_t total_write_len = LEN_DATA_SIZE + LEN_METADATA_SIZE + metadata_len + buffer_len;
-
- if( total_write_len > ctrl->buffer_size )
- {
- return FIFO_STATUS_BUFFER_TOO_SMALL;
- }
-
- while( ctrl->free_space < total_write_len )
- {
- // Not enough free space --> Remove oldest
- ctrl_get( ctrl, NULL, NULL, 0, NULL, NULL, 0 );
- ctrl->drop_cnt += 1;
- }
-
- // Write data length - 2 bytes MSB first
- ctrl->buffer[ctrl->write_offset] = ( uint8_t )( buffer_len >> 8 );
- ctrl->write_offset += 1;
- ctrl->write_offset %= ctrl->buffer_size;
- ctrl->buffer[ctrl->write_offset] = ( uint8_t )( buffer_len );
- ctrl->write_offset += 1;
- ctrl->write_offset %= ctrl->buffer_size;
-
- // Write metadata length
- ctrl->buffer[ctrl->write_offset] = metadata_len;
- ctrl->write_offset += 1;
- ctrl->write_offset %= ctrl->buffer_size;
-
- // Write metadata
- if( metadata_len != 0 )
- {
- if( ( ctrl->write_offset + metadata_len ) > ctrl->buffer_size )
- {
- memcpy( ctrl->buffer + ctrl->write_offset, ( uint8_t* ) metadata, ctrl->buffer_size - ctrl->write_offset );
- memcpy( ctrl->buffer, ( uint8_t* ) metadata + ctrl->buffer_size - ctrl->write_offset,
- metadata_len - ( ctrl->buffer_size - ctrl->write_offset ) );
- }
- else
- {
- memcpy( ctrl->buffer + ctrl->write_offset, ( uint8_t* ) metadata, metadata_len );
- }
- ctrl->write_offset += metadata_len;
- ctrl->write_offset %= ctrl->buffer_size;
- }
-
- // Write data
- if( buffer_len != 0 )
- {
- if( ( ctrl->write_offset + buffer_len ) > ctrl->buffer_size )
- {
- memcpy( ctrl->buffer + ctrl->write_offset, buffer, ctrl->buffer_size - ctrl->write_offset );
- memcpy( ctrl->buffer, buffer + ctrl->buffer_size - ctrl->write_offset,
- buffer_len - ( ctrl->buffer_size - ctrl->write_offset ) );
- }
- else
- {
- memcpy( ctrl->buffer + ctrl->write_offset, buffer, buffer_len );
- }
-
- ctrl->write_offset += buffer_len;
- ctrl->write_offset %= ctrl->buffer_size;
- }
-
- ctrl->free_space -= total_write_len;
- ctrl->nb_element += 1;
- ctrl->write_cnt += 1;
-
- return FIFO_STATUS_OK;
-}
-
-static fifo_return_status_t ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
- const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
- const uint8_t metadata_buffer_size )
-{
- if( ctrl->nb_element == 0 )
- {
- return FIFO_STATUS_BUFFER_EMPTY;
- }
-
- // Read data & metadata size (read_offset update is done later if input param are ok)
- uint16_t read_data_len = ( ( uint16_t ) ctrl->buffer[ctrl->read_offset] ) << 8;
- read_data_len += ( ( uint16_t ) ctrl->buffer[( ctrl->read_offset + 1 ) % ctrl->buffer_size] );
- uint8_t read_metadata_len = ctrl->buffer[( ctrl->read_offset + 2 ) % ctrl->buffer_size];
-
- // Buffer & metadata are NULL --> drop old message --> don't check/update size of buffer
- if( ( buffer != NULL ) && ( metadata != NULL ) )
- {
- if( ( data_len == NULL ) || ( metadata_len == NULL ) )
- {
- return FIFO_STATUS_PARAM_ERROR;
- }
-
- // Buffer length are ok -> save length infos
- *data_len = read_data_len;
- *metadata_len = read_metadata_len;
-
- if( ( read_data_len > data_buffer_size ) || ( read_metadata_len > metadata_buffer_size ) )
- {
- return FIFO_STATUS_BUFFER_TOO_SMALL;
- }
- }
-
- // Update read offset (only if there is no error)
- ctrl->read_offset += ( LEN_DATA_SIZE + LEN_METADATA_SIZE );
- ctrl->read_offset %= ctrl->buffer_size;
-
- // Copy metadata (if required)
- if( ( metadata != NULL ) && ( read_metadata_len != 0 ) )
- {
- if( ( ctrl->read_offset + read_metadata_len ) > ctrl->buffer_size )
- {
- memcpy( ( uint8_t* ) metadata, ctrl->buffer + ctrl->read_offset, ctrl->buffer_size - ctrl->read_offset );
- memcpy( ( uint8_t* ) metadata + ctrl->buffer_size - ctrl->read_offset, ctrl->buffer,
- read_metadata_len - ( ctrl->buffer_size - ctrl->read_offset ) );
- }
- else
- {
- memcpy( ( uint8_t* ) metadata, ctrl->buffer + ctrl->read_offset, read_metadata_len );
- }
- }
- ctrl->read_offset += read_metadata_len;
- ctrl->read_offset %= ctrl->buffer_size;
-
- // Copy data (if required)
- if( ( buffer != NULL ) && ( read_data_len != 0 ) )
- {
- if( ( ctrl->read_offset + read_data_len ) > ctrl->buffer_size )
- {
- memcpy( buffer, ctrl->buffer + ctrl->read_offset, ctrl->buffer_size - ctrl->read_offset );
- memcpy( buffer + ctrl->buffer_size - ctrl->read_offset, ctrl->buffer,
- read_data_len - ( ctrl->buffer_size - ctrl->read_offset ) );
- }
- else
- {
- memcpy( buffer, ctrl->buffer + ctrl->read_offset, read_data_len );
- }
- }
- ctrl->read_offset += read_data_len;
- ctrl->read_offset %= ctrl->buffer_size;
-
- ctrl->free_space += ( LEN_DATA_SIZE + LEN_METADATA_SIZE + read_metadata_len + read_data_len );
- ctrl->nb_element -= 1;
- ctrl->read_cnt += 1;
-
- return FIFO_STATUS_OK;
-}
+/*!
+ * \file fifo_ctrl.c
+ *
+ * \brief
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2021. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+#include // C99 types
+#include // bool type
+#include
+
+#include "fifo_ctrl.h"
+#include "smtc_modem_hal.h"
+#include "smtc_modem_hal_dbg_trace.h"
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE CONSTANTS -------------------------------------------------------
+ */
+
+#define LEN_DATA_SIZE ( 2 )
+#define LEN_METADATA_SIZE ( 1 )
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE TYPES -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE VARIABLES -------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
+ */
+static fifo_return_status_t ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
+ const void* metadata, const uint8_t metadata_len );
+
+static fifo_return_status_t ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
+ const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
+ const uint8_t metadata_buffer_size );
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
+ */
+
+void fifo_ctrl_init( fifo_ctrl_t* ctrl, uint8_t* buffer, const uint16_t buffer_size )
+{
+ ctrl->buffer = buffer;
+ ctrl->buffer_size = buffer_size;
+ fifo_ctrl_clear( ctrl );
+}
+
+void fifo_ctrl_clear( fifo_ctrl_t* ctrl )
+{
+ ctrl->read_offset = 0;
+ ctrl->write_offset = 0;
+ ctrl->nb_element = 0;
+ ctrl->write_cnt = 0;
+ ctrl->read_cnt = 0;
+ ctrl->drop_cnt = 0;
+ ctrl->free_space = ctrl->buffer_size;
+}
+
+void fifo_ctrl_print_stat( const fifo_ctrl_t* ctrl )
+{
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "----------------------------------\n" );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "fifo_ctrl_print_stat\n" );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Buffer size : %d\n", ctrl->buffer_size );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Current elt : %d\n", ctrl->nb_element );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Free space : %d\n", ctrl->free_space );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Write : %d\n", ctrl->write_cnt );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Read : %d\n", ctrl->read_cnt - ctrl->drop_cnt );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "Drop : %d\n", ctrl->drop_cnt );
+ SMTC_MODEM_HAL_TRACE_INFO_DEBUG( "----------------------------------\n" );
+}
+
+uint16_t fifo_ctrl_get_nb_elt( const fifo_ctrl_t* ctrl )
+{
+ return ctrl->nb_element;
+}
+
+uint16_t fifo_ctrl_get_free_space( const fifo_ctrl_t* ctrl )
+{
+ return ctrl->free_space;
+}
+
+fifo_return_status_t fifo_ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
+ const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
+ const uint8_t metadata_buffer_size )
+{
+ smtc_modem_hal_disable_modem_irq( );
+ fifo_return_status_t ret =
+ ctrl_get( ctrl, buffer, data_len, data_buffer_size, metadata, metadata_len, metadata_buffer_size );
+ smtc_modem_hal_enable_modem_irq( );
+
+ return ret;
+}
+
+fifo_return_status_t fifo_ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
+ const void* metadata, const uint8_t metadata_len )
+{
+ smtc_modem_hal_disable_modem_irq( );
+ fifo_return_status_t ret = ctrl_set( ctrl, buffer, buffer_len, metadata, metadata_len );
+ smtc_modem_hal_enable_modem_irq( );
+ return ret;
+}
+
+static fifo_return_status_t ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
+ const void* metadata, const uint8_t metadata_len )
+{
+ uint16_t total_write_len = LEN_DATA_SIZE + LEN_METADATA_SIZE + metadata_len + buffer_len;
+
+ if( total_write_len > ctrl->buffer_size )
+ {
+ return FIFO_STATUS_BUFFER_TOO_SMALL;
+ }
+
+ while( ctrl->free_space < total_write_len )
+ {
+ // Not enough free space --> Remove oldest
+ ctrl_get( ctrl, NULL, NULL, 0, NULL, NULL, 0 );
+ ctrl->drop_cnt += 1;
+ }
+
+ // Write data length - 2 bytes MSB first
+ ctrl->buffer[ctrl->write_offset] = ( uint8_t )( buffer_len >> 8 );
+ ctrl->write_offset += 1;
+ ctrl->write_offset %= ctrl->buffer_size;
+ ctrl->buffer[ctrl->write_offset] = ( uint8_t )( buffer_len );
+ ctrl->write_offset += 1;
+ ctrl->write_offset %= ctrl->buffer_size;
+
+ // Write metadata length
+ ctrl->buffer[ctrl->write_offset] = metadata_len;
+ ctrl->write_offset += 1;
+ ctrl->write_offset %= ctrl->buffer_size;
+
+ // Write metadata
+ if( metadata_len != 0 )
+ {
+ if( ( ctrl->write_offset + metadata_len ) > ctrl->buffer_size )
+ {
+ memcpy( ctrl->buffer + ctrl->write_offset, ( uint8_t* ) metadata, ctrl->buffer_size - ctrl->write_offset );
+ memcpy( ctrl->buffer, ( uint8_t* ) metadata + ctrl->buffer_size - ctrl->write_offset,
+ metadata_len - ( ctrl->buffer_size - ctrl->write_offset ) );
+ }
+ else
+ {
+ memcpy( ctrl->buffer + ctrl->write_offset, ( uint8_t* ) metadata, metadata_len );
+ }
+ ctrl->write_offset += metadata_len;
+ ctrl->write_offset %= ctrl->buffer_size;
+ }
+
+ // Write data
+ if( buffer_len != 0 )
+ {
+ if( ( ctrl->write_offset + buffer_len ) > ctrl->buffer_size )
+ {
+ memcpy( ctrl->buffer + ctrl->write_offset, buffer, ctrl->buffer_size - ctrl->write_offset );
+ memcpy( ctrl->buffer, buffer + ctrl->buffer_size - ctrl->write_offset,
+ buffer_len - ( ctrl->buffer_size - ctrl->write_offset ) );
+ }
+ else
+ {
+ memcpy( ctrl->buffer + ctrl->write_offset, buffer, buffer_len );
+ }
+
+ ctrl->write_offset += buffer_len;
+ ctrl->write_offset %= ctrl->buffer_size;
+ }
+
+ ctrl->free_space -= total_write_len;
+ ctrl->nb_element += 1;
+ ctrl->write_cnt += 1;
+
+ return FIFO_STATUS_OK;
+}
+
+static fifo_return_status_t ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
+ const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
+ const uint8_t metadata_buffer_size )
+{
+ if( ctrl->nb_element == 0 )
+ {
+ return FIFO_STATUS_BUFFER_EMPTY;
+ }
+
+ // Read data & metadata size (read_offset update is done later if input param are ok)
+ uint16_t read_data_len = ( ( uint16_t ) ctrl->buffer[ctrl->read_offset] ) << 8;
+ read_data_len += ( ( uint16_t ) ctrl->buffer[( ctrl->read_offset + 1 ) % ctrl->buffer_size] );
+ uint8_t read_metadata_len = ctrl->buffer[( ctrl->read_offset + 2 ) % ctrl->buffer_size];
+
+ // Buffer & metadata are NULL --> drop old message --> don't check/update size of buffer
+ if( ( buffer != NULL ) && ( metadata != NULL ) )
+ {
+ if( ( data_len == NULL ) || ( metadata_len == NULL ) )
+ {
+ return FIFO_STATUS_PARAM_ERROR;
+ }
+
+ // Buffer length are ok -> save length infos
+ *data_len = read_data_len;
+ *metadata_len = read_metadata_len;
+
+ if( ( read_data_len > data_buffer_size ) || ( read_metadata_len > metadata_buffer_size ) )
+ {
+ return FIFO_STATUS_BUFFER_TOO_SMALL;
+ }
+ }
+
+ // Update read offset (only if there is no error)
+ ctrl->read_offset += ( LEN_DATA_SIZE + LEN_METADATA_SIZE );
+ ctrl->read_offset %= ctrl->buffer_size;
+
+ // Copy metadata (if required)
+ if( ( metadata != NULL ) && ( read_metadata_len != 0 ) )
+ {
+ if( ( ctrl->read_offset + read_metadata_len ) > ctrl->buffer_size )
+ {
+ memcpy( ( uint8_t* ) metadata, ctrl->buffer + ctrl->read_offset, ctrl->buffer_size - ctrl->read_offset );
+ memcpy( ( uint8_t* ) metadata + ctrl->buffer_size - ctrl->read_offset, ctrl->buffer,
+ read_metadata_len - ( ctrl->buffer_size - ctrl->read_offset ) );
+ }
+ else
+ {
+ memcpy( ( uint8_t* ) metadata, ctrl->buffer + ctrl->read_offset, read_metadata_len );
+ }
+ }
+ ctrl->read_offset += read_metadata_len;
+ ctrl->read_offset %= ctrl->buffer_size;
+
+ // Copy data (if required)
+ if( ( buffer != NULL ) && ( read_data_len != 0 ) )
+ {
+ if( ( ctrl->read_offset + read_data_len ) > ctrl->buffer_size )
+ {
+ memcpy( buffer, ctrl->buffer + ctrl->read_offset, ctrl->buffer_size - ctrl->read_offset );
+ memcpy( buffer + ctrl->buffer_size - ctrl->read_offset, ctrl->buffer,
+ read_data_len - ( ctrl->buffer_size - ctrl->read_offset ) );
+ }
+ else
+ {
+ memcpy( buffer, ctrl->buffer + ctrl->read_offset, read_data_len );
+ }
+ }
+ ctrl->read_offset += read_data_len;
+ ctrl->read_offset %= ctrl->buffer_size;
+
+ ctrl->free_space += ( LEN_DATA_SIZE + LEN_METADATA_SIZE + read_metadata_len + read_data_len );
+ ctrl->nb_element -= 1;
+ ctrl->read_cnt += 1;
+
+ return FIFO_STATUS_OK;
+}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.h
index 974c429..69f1f29 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fifo_ctrl.h
@@ -1,170 +1,170 @@
-/*!
- * \file fifo_ctrl.h
- *
- * \brief FIFO manager
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __FIFO_CTRL_H__
-#define __FIFO_CTRL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-#include // C99 types
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC MACROS -----------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC CONSTANTS --------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC TYPES ------------------------------------------------------------
- */
-
-// Return status fo get/set function
-typedef enum fifo_return_status_e
-{
- FIFO_STATUS_OK, // Return is OK
- FIFO_STATUS_PARAM_ERROR, // Only for get function
- FIFO_STATUS_BUFFER_EMPTY, // Only for get function
- FIFO_STATUS_BUFFER_TOO_SMALL, // For get: not enough space in buffer to read data from fifo
- // For set: fifo is not big enough to save data + metadata
-} fifo_return_status_t;
-
-// Internal structure to manage fifo - don't modify it
-typedef struct fifo_ctrl_s
-{
- uint8_t* buffer;
- uint16_t buffer_size;
- uint16_t read_offset;
- uint16_t write_offset;
- uint16_t free_space;
- uint16_t nb_element;
-
- // Stat
- uint32_t write_cnt;
- uint32_t read_cnt;
- uint32_t drop_cnt;
-} fifo_ctrl_t;
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
- */
-
-/**
- * @brief Init the fifo
- *
- * @param ctrl Fifo manager
- * @param buffer Buffer to link to the fifo manager
- * @param buffer_size Buffer size
- * @param metadata_size Size of metadata that will be provide with each message
- */
-void fifo_ctrl_init( fifo_ctrl_t* ctrl, uint8_t* buffer, const uint16_t buffer_size );
-
-/**
- * @brief Reset fifo manager (all datas & metadatas will be lost)
- *
- * @param ctrl Fifo to reset
- */
-void fifo_ctrl_clear( fifo_ctrl_t* ctrl );
-
-/**
- * @brief Display stat of the fifo (free space, nb element, drop counter, ....)
- *
- * @param ctrl
- */
-void fifo_ctrl_print_stat( const fifo_ctrl_t* ctrl );
-
-/**
- * @brief Return number of message stored in the fifo
- *
- * @param ctrl fifo manager
- * @return uint16_t number of messages in the fifo
- */
-uint16_t fifo_ctrl_get_nb_elt( const fifo_ctrl_t* ctrl );
-
-/**
- * @brief Return free space of the fifo
- * Free space is use to store Size, metadata and data, not only data
- * @param ctrl fifo manager
- * @return uint16_t bytes available
- */
-uint16_t fifo_ctrl_get_free_space( const fifo_ctrl_t* ctrl );
-
-/**
- * @brief Read oldest element in fifo
- *
- * @param ctrl fifo manager
- * @param buffer buffer to save data
- * @param data_len length of read data
- * @param data_buffer_size size of buffer
- * @param metadata pointer to save metadata
- * @param metadata_len length of metadata
- * @param metadata_buffer_size size of metadata buffer
- * @return fifo_return_status_t return status
- */
-fifo_return_status_t fifo_ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
- const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
- const uint8_t metadata_buffer_size );
-
-/**
- * @brief Save a new element in the fifo
- * If there is not enough free space, the oldest element will be removed
- *
- * @param ctrl fifo manager
- * @param buffer buffer to save
- * @param buffer_len size of buffer
- * @param metadata metadata to save
- * @param metadata_len length of metadata
- * @return fifo_return_status_t return status
- */
-fifo_return_status_t fifo_ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
- const void* metadata, const uint8_t metadata_len );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __FIFO_CTRL_H__
-
-/* --- EOF ------------------------------------------------------------------ */
+/*!
+ * \file fifo_ctrl.h
+ *
+ * \brief FIFO manager
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2021. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __FIFO_CTRL_H__
+#define __FIFO_CTRL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+#include // C99 types
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC MACROS -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC CONSTANTS --------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC TYPES ------------------------------------------------------------
+ */
+
+// Return status fo get/set function
+typedef enum fifo_return_status_e
+{
+ FIFO_STATUS_OK, // Return is OK
+ FIFO_STATUS_PARAM_ERROR, // Only for get function
+ FIFO_STATUS_BUFFER_EMPTY, // Only for get function
+ FIFO_STATUS_BUFFER_TOO_SMALL, // For get: not enough space in buffer to read data from fifo
+ // For set: fifo is not big enough to save data + metadata
+} fifo_return_status_t;
+
+// Internal structure to manage fifo - don't modify it
+typedef struct fifo_ctrl_s
+{
+ uint8_t* buffer;
+ uint16_t buffer_size;
+ uint16_t read_offset;
+ uint16_t write_offset;
+ uint16_t free_space;
+ uint16_t nb_element;
+
+ // Stat
+ uint32_t write_cnt;
+ uint32_t read_cnt;
+ uint32_t drop_cnt;
+} fifo_ctrl_t;
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
+ */
+
+/**
+ * @brief Init the fifo
+ *
+ * @param ctrl Fifo manager
+ * @param buffer Buffer to link to the fifo manager
+ * @param buffer_size Buffer size
+ * @param metadata_size Size of metadata that will be provide with each message
+ */
+void fifo_ctrl_init( fifo_ctrl_t* ctrl, uint8_t* buffer, const uint16_t buffer_size );
+
+/**
+ * @brief Reset fifo manager (all datas & metadatas will be lost)
+ *
+ * @param ctrl Fifo to reset
+ */
+void fifo_ctrl_clear( fifo_ctrl_t* ctrl );
+
+/**
+ * @brief Display stat of the fifo (free space, nb element, drop counter, ....)
+ *
+ * @param ctrl
+ */
+void fifo_ctrl_print_stat( const fifo_ctrl_t* ctrl );
+
+/**
+ * @brief Return number of message stored in the fifo
+ *
+ * @param ctrl fifo manager
+ * @return uint16_t number of messages in the fifo
+ */
+uint16_t fifo_ctrl_get_nb_elt( const fifo_ctrl_t* ctrl );
+
+/**
+ * @brief Return free space of the fifo
+ * Free space is use to store Size, metadata and data, not only data
+ * @param ctrl fifo manager
+ * @return uint16_t bytes available
+ */
+uint16_t fifo_ctrl_get_free_space( const fifo_ctrl_t* ctrl );
+
+/**
+ * @brief Read oldest element in fifo
+ *
+ * @param ctrl fifo manager
+ * @param buffer buffer to save data
+ * @param data_len length of read data
+ * @param data_buffer_size size of buffer
+ * @param metadata pointer to save metadata
+ * @param metadata_len length of metadata
+ * @param metadata_buffer_size size of metadata buffer
+ * @return fifo_return_status_t return status
+ */
+fifo_return_status_t fifo_ctrl_get( fifo_ctrl_t* ctrl, uint8_t* buffer, uint16_t* data_len,
+ const uint16_t data_buffer_size, void* metadata, uint8_t* metadata_len,
+ const uint8_t metadata_buffer_size );
+
+/**
+ * @brief Save a new element in the fifo
+ * If there is not enough free space, the oldest element will be removed
+ *
+ * @param ctrl fifo manager
+ * @param buffer buffer to save
+ * @param buffer_len size of buffer
+ * @param metadata metadata to save
+ * @param metadata_len length of metadata
+ * @return fifo_return_status_t return status
+ */
+fifo_return_status_t fifo_ctrl_set( fifo_ctrl_t* ctrl, const uint8_t* buffer, const uint16_t buffer_len,
+ const void* metadata, const uint8_t metadata_len );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __FIFO_CTRL_H__
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.c
deleted file mode 100644
index 84f9a64..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.c
+++ /dev/null
@@ -1,915 +0,0 @@
-/*!
- * \file FragDecoder.h
- *
- * \brief Implements the LoRa-Alliance fragmentation decoder
- * Specification:
- * https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include
-#include
-#include "lr1mac_utilities.h"
-#include "frag_decoder.h"
-#include "smtc_modem_hal.h"
-#include "nvmcu_hal.h"
-#include "smtc_modem_hal_dbg_trace.h"
-
-#if defined( TEST )
-#define STATIC
-#else
-#define STATIC static
-#endif
-
-/*
- *=============================================================================
- * Fragmentation decoder algorithm utilities
- *=============================================================================
- */
-
-/*
- * L = FRAG_MAX_SIZE
- * M = FRAG_MAX_NB
- * R = FRAG_MAX_FRAME_LOSS
- *
- *
- * Global
- * MatrixM2B [R][R/8] little parity matrix
- * FragNbMissingIndex [M] Fragment i is the Nth missing
- * S[R/8]
- *
- * Local
- * matrixRow [M/8] Ci in the paper
- * matrixDataTemp [L] Coded fragment, Si in the paper
- * dataTempVector [R/8] Line of MatrixM2B
- * dataTempVector2 [R/8] Line of MatrixM2B
- *
- */
-
-#if defined( UNIT_TEST_DBG )
-#define PARITY_LINE_PRINT( name, array, start, cols ) \
- { \
- SMTC_MODEM_HAL_TRACE_PRINTF( "%s\t", name ); \
- for( size_t _j = start; _j < ( start + cols ); _j++ ) \
- { \
- uint8_t elem = GetParity( _j, ( array ) ); \
- if( elem == 0 ) \
- SMTC_MODEM_HAL_TRACE_PRINTF( ". " ); \
- else \
- SMTC_MODEM_HAL_TRACE_PRINTF( "x " ); \
- } \
- SMTC_MODEM_HAL_TRACE_PRINTF( " \n" ); \
- }
-
-#define PARITY_ARRAY_PRINT( name, array, rows, cols ) \
- { \
- SMTC_MODEM_HAL_TRACE_PRINTF( "\n%s\n", name ); \
- uint8_t tmp[16]; \
- for( size_t _i = 0; _i < ( rows ); _i++ ) \
- { \
- FragExtractLineFromBinaryMatrix( tmp, _i, ( cols ) ); \
- PARITY_LINE_PRINT( "", tmp, 0, ( cols ) ); \
- } \
- SMTC_MODEM_HAL_TRACE_PRINTF( " \n" ); \
- }
-
-#define MISSING_PRINT_LINE( array, cols ) \
- { \
- SMTC_MODEM_HAL_TRACE_PRINTF( "Missing\t" ); \
- for( size_t _j = 0; _j < ( cols ); _j++ ) \
- { \
- if( array[_j] ) \
- SMTC_MODEM_HAL_TRACE_PRINTF( "%02d ", array[_j] ); \
- else \
- SMTC_MODEM_HAL_TRACE_PRINTF( " . ", array[_j] ); \
- } \
- SMTC_MODEM_HAL_TRACE_PRINTF( " \n" ); \
- }
-
-#define DATA_PRINT_FRAG( name, array, cols ) \
- { \
- SMTC_MODEM_HAL_TRACE_PRINTF( "%s\t", name ); \
- for( size_t _j = 0; _j < ( cols ); _j++ ) \
- { \
- SMTC_MODEM_HAL_TRACE_PRINTF( "0x%02x ", array[_j] ); \
- } \
- SMTC_MODEM_HAL_TRACE_PRINTF( " \n" ); \
- }
-#else
-#define PARITY_LINE_PRINT( ... )
-#define PARITY_ARRAY_PRINT( ... )
-#define MISSING_PRINT_LINE( ... )
-#define DATA_PRINT_FRAG( ... )
-#endif // TEST
-
-// This computes the number of bytes needed to store N bits.
-#define BITARRAY_BYTES( N ) ( ( ( N ) + 7 ) >> 3 )
-
-typedef struct
-{
- FragDecoderCallbacks_t* Callbacks;
- uint16_t FragNb;
- uint8_t FragSize;
-
- uint32_t M2BLine;
-
- /*
- * This is the "little" parity matrix, which is used to compute the linear combinations
- * between the uncoded fragments and the redundant ones.
- *
- * This stores a triangular superior matrix. The "PushLine" and "ExtractLine" functions
- * manage the compression and bit layout.
- * We will store at most L*(L+1)/2 bits, with L the maximum number of missing fragments
- * that we can tolerate.
- *
- * NbElems = FRAG_MAX_FRAME_LOSS * (FRAG_MAX_FRAME_LOSS + 1) / 2
- *
- * // (N+7)/8 is the correct floor function for 8 bits/byte
- * NbBytes = (NbElems + 7) >> 3
- *
- */
-#define M2B_NB_ELEM ( FRAG_MAX_FRAME_LOSS * ( FRAG_MAX_FRAME_LOSS + 1 ) >> 1 )
-#define M2B_STORAGE_SIZE ( BITARRAY_BYTES( M2B_NB_ELEM ) )
- uint8_t MatrixM2B[M2B_STORAGE_SIZE];
-
- /*
- * BitArray containing if fragment {I} is missing or not.
- * This is used to quickly check if a fragment is missing or not.
- * We could trade memory consumption with computation time by
- * iterating through FragMissingIndex every time we want to check
- * if a fragment is missing or not. The gain is small though (32 bytes for 256 fragments)
- */
-#define MISSING_STORAGE_SIZE ( BITARRAY_BYTES( FRAG_MAX_NB ) )
- uint8_t FragMissing[MISSING_STORAGE_SIZE];
-
- /*
- * Array containing Status.FragNbLost elements.
- * When we discover that a fragment is missing, we store its fragCounter (0-indexed)
- * at the Nth position in this array.
- * I.e. if fragments #4 and #7 are missing (1-indexed), the content is [3, 6]
- * Type is a uint16_t because we might have more than 255 uncoded fragments.
- * We could also remove this if we do an exhaustive search through FragMissing, by keeping count
- * of the real index and the number of missing bits set to 1.
- */
- uint16_t FragMissingIndex[FRAG_MAX_FRAME_LOSS];
-
- uint8_t S[BITARRAY_BYTES( FRAG_MAX_FRAME_LOSS )];
-
- FragDecoderStatus_t Status;
-} FragDecoder_t;
-
-/*!
- * \brief Sets a row from source into file destination
- *
- * \param [IN] src Source buffer pointer
- * \param [IN] row Destination index of the row to be copied
- * \param [IN] size Source number of bytes to be copied
- */
-static void SetRow( uint8_t* src, uint16_t row, uint16_t size );
-/*!
- * \brief Gets a row from source and stores it into file destination
- *
- * \param [IN] src Source buffer pointer
- * \param [IN] row Source index of the row to be copied
- * \param [IN] size Source number of bytes to be copied
- */
-static void GetRow( uint8_t* src, uint16_t row, uint16_t size );
-
-/*!
- * \brief Gets the parity value from a given row of the parity matrix
- *
- * \param [IN] index The index of the row to be computed
- * \param [IN] matrixRow Pointer to the parity matrix (parity bit array)
- *
- * \retval parity Parity value at the given index
- */
-STATIC uint8_t GetParity( uint16_t index, uint8_t* matrixRow );
-
-/*!
- * \brief Sets the parity value on the given row of the parity matrix
- *
- * \param [IN] index The index of the row to be computed
- * \param [IN/OUT] matrixRow Pointer to the parity matrix.
- * \param [IN] parity The parity value to be set in the parity matrix
- */
-STATIC void SetParity( uint16_t index, uint8_t* matrixRow, uint8_t parity );
-
-/*!
- * \brief Check if the provided value is a power of 2
- *
- * \param [IN] x Value to be tested
- *
- * \retval status Return true if frame is a power of two
- */
-static bool IsPowerOfTwo( uint32_t x );
-
-/*!
- * \brief XOrs two data lines
- *
- * \param [IN] line1 1st Data line to be XORed
- * \param [IN] line2 2nd Data line to be XORed
- * \param [IN] size Number of elements in line1
- *
- * \param [OUT] result XOR( line1, line2 ) result stored in line1
- */
-static void XorDataLine( uint8_t* line1, uint8_t* line2, int32_t size );
-
-/*!
- * \brief XORs two parity lines
- *
- * \param [IN] line1 1st Parity line to be XORed
- * \param [IN] line2 2nd Parity line to be XORed
- * \param [IN] size Number of elements in line1
- *
- * \param [OUT] result XOR( line1, line2 ) result stored in line1
- */
-static void XorParityLine( uint8_t* line1, uint8_t* line2, int32_t size );
-
-/*!
- * \brief Generates a pseudo random number : PRBS23
- *
- * \param [IN] value The input of the PRBS23 generator
- *
- * \retval nextValue Returns the next pseudo random number
- */
-static int32_t FragPrbs23( int32_t value );
-
-/*!
- * \brief Gets and fills the parity matrix
- *
- * \param [IN] n Fragment N
- * \param [IN] m Fragment number
- * \param [OUT] matrixRow Parity matrix
- */
-STATIC void FragGetParityMatrixRow( int32_t n, int32_t m, uint8_t* matrixRow );
-
-/*!
- * \brief Finds the index of the first one in a bit array
- *
- * \param [IN] bitArray Pointer to the bit array
- * \param [IN] size Bit array size
- * \retval index The index of the first 1 in the bit array
- */
-static uint16_t BitArrayFindFirstOne( uint8_t* bitArray, uint16_t size );
-
-/*!
- * \brief Checks if the provided bit array only contains zeros
- *
- * \param [IN] bitArray Pointer to the bit array
- * \param [IN] size Bit array size
- * \retval isAllZeros [0: Contains ones, 1: Contains all zeros]
- */
-static uint8_t BitArrayIsAllZeros( uint8_t* bitArray, uint16_t size );
-
-/*!
- * \brief Finds & marks missing fragments
- *
- * \param [IN] counter Current fragment counter
- * \param [OUT] FragDecoder.FragMissing[] array is updated in place
- * \param [OUT] FragDecoder.FragNbMissingIndex[] array is updated in place
- */
-static void FragFindMissingFrags( uint16_t counter );
-
-/*!
- * \brief Finds the index (frag counter) of the x th missing frag
- *
- * \param [IN] x x th missing frag
- *
- * \retval counter The counter value associated to the x th missing frag
- */
-static uint16_t FragFindMissingIndex( uint16_t x );
-
-/*!
- * \brief Find the index of missing fragment x in the small table
- *
- * \param [IN] fragCounter Number of the missing fragment (1-indexed)
- *
- * \retval index The index of the missing fragment in the small matrix. (0-indexed)
- * If the index is not found, FRAG_MAX_FRAME_LOSS is returned
- * to indicate an error, and the caller should check this condition.
- */
-static uint16_t FragFindMissing( uint16_t fragCounter );
-
-/*!
- * \brief Extacts a row from the M2B binary matrix and expands it to a bitArray
- *
- * \param [IN] bitArray Pointer to the bit array
- * \param [IN] rowIndex Matrix row index Max FRAG_MAX_FRAME_LOSS
- * \param [IN] bitsInRow Number of bits in one row. Max FRAG_MAX_FRAME_LOSS
- */
-STATIC void FragExtractLineFromBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow );
-
-/*!
- * \brief Collapses and Pushs a row of a bit array to the M2B matrix
- *
- * \param [IN] bitArray Pointer to the bit array
- * \param [IN] rowIndex Matrix row index Max FRAG_MAX_FRAME_LOSS
- * \param [IN] bitsInRow Number of bits in one row. Max FRAG_MAX_FRAME_LOSS
- */
-STATIC void FragPushLineToBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow );
-
-/*
- *=============================================================================
- * Fragmentation decoder algorithm
- *=============================================================================
- */
-
-static FragDecoder_t FragDecoder;
-
-int32_t FragDecoderInit( uint16_t fragNb, uint8_t fragSize, FragDecoderCallbacks_t* callbacks )
-{
- if( !callbacks || !callbacks->FragDecoderWrite || !callbacks->FragDecoderRead )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FRAG No callback defined!\n" );
- return FRAG_SESSION_ERROR;
- }
-
- if( fragNb > FRAG_MAX_NB || fragSize > FRAG_MAX_SIZE )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FRAG fragNb > %d || fragSize > %d\n", FRAG_MAX_NB, FRAG_MAX_SIZE );
- return FRAG_SESSION_BADSIZE;
- }
-
- FragDecoder.Callbacks = callbacks;
- FragDecoder.FragNb = fragNb; // FragNb = FRAG_MAX_SIZE
- FragDecoder.FragSize = fragSize; // number of byte on a row
- FragDecoder.Status.FragNbRx = 0;
- FragDecoder.Status.FragNbLastRx = 0;
- FragDecoder.Status.FragNbLost = 0;
- FragDecoder.M2BLine = 0;
-
- // Initialize missing fragments index array
- for( uint16_t i = 0; i < FRAG_MAX_FRAME_LOSS; i++ )
- {
- FragDecoder.FragMissingIndex[i] = 0;
- }
- for( size_t i = 0; i < MISSING_STORAGE_SIZE; i++ )
- {
- FragDecoder.FragMissing[i] = 0;
- }
-
- // Initialize parity matrix
- for( uint32_t i = 0; i < BITARRAY_BYTES( FRAG_MAX_FRAME_LOSS ); i++ )
- {
- FragDecoder.S[i] = 0;
- }
-
- for( uint32_t i = 0; i < M2B_STORAGE_SIZE; i++ )
- {
- FragDecoder.MatrixM2B[i] = 0xFF;
- }
-
- SMTC_MODEM_HAL_TRACE_INFO( "Missing %3d bytes\n", MISSING_STORAGE_SIZE );
- SMTC_MODEM_HAL_TRACE_INFO( "MIndex %3d bytes\n", FRAG_MAX_FRAME_LOSS );
- SMTC_MODEM_HAL_TRACE_INFO( "M2B %3d bytes\n", M2B_STORAGE_SIZE );
-
- // Initialize final uncoded data buffer ( FRAG_MAX_NB * FRAG_MAX_SIZE )
- // erase Delta update storage pages
- for( uint16_t page = 109; page < 124; page++ )
- {
- if( FlashErasePage( page, 0 ) != 1 )
- {
- SMTC_MODEM_HAL_TRACE_INFO( "Erase error page %d:\n", page );
- return FRAG_SESSION_MEM_ERROR;
- }
- }
- FragDecoder.Status.FragNbLost = 0;
- FragDecoder.Status.FragNbLastRx = 0;
-
- SMTC_MODEM_HAL_TRACE_INFO( "FragDecoderInit %d %d\n", FragDecoder.FragNb, FragDecoder.FragSize );
- return FRAG_SESSION_OK;
-}
-
-uint32_t FragDecoderGetMaxFileSize( void )
-{
- return FRAG_MAX_NB * FRAG_MAX_SIZE;
-}
-
-FragDecoderSessionStatus_t FragDecoderProcess( uint16_t fragCounter, uint8_t* rawData )
-{
- uint16_t firstOneInRow = 0;
- int32_t first = 0;
- int32_t noInfo = 0;
-
- uint8_t matrixRow[( FRAG_MAX_NB >> 3 ) + 1];
- uint8_t matrixDataTemp[FRAG_MAX_SIZE];
- uint8_t dataTempVector[( FRAG_MAX_FRAME_LOSS >> 3 ) + 1];
- uint8_t dataTempVector2[( FRAG_MAX_FRAME_LOSS >> 3 ) + 1];
-
- memset1( matrixRow, 0, ( FRAG_MAX_NB >> 3 ) + 1 );
- memset1( matrixDataTemp, 0, FRAG_MAX_SIZE );
- memset1( dataTempVector, 0, ( FRAG_MAX_FRAME_LOSS >> 3 ) + 1 );
- memset1( dataTempVector2, 0, ( FRAG_MAX_FRAME_LOSS >> 3 ) + 1 );
-
- SMTC_MODEM_HAL_TRACE_INFO( "FragProcess cnt %d nb_frag %d frag_size %d\n", fragCounter, FragDecoder.FragNb,
- FragDecoder.FragSize );
-
- if( rawData == NULL )
- {
- return FRAG_SESSION_ERROR;
- }
-
- if( fragCounter < 1 )
- {
- return FRAG_SESSION_ERROR;
- }
-
- // This stores the number of really received fragments. Not used in the algorithm,
- // only in debug messages.
- FragDecoder.Status.FragNbRx += 1;
-
- if( fragCounter <= FragDecoder.Status.FragNbLastRx )
- {
- return FRAG_SESSION_ONGOING; // Drop frame out of order
- }
-
- // The M (FragNb) first packets aren't encoded or in other words they are
- // encoded with the unitary matrix
- if( fragCounter <= FragDecoder.FragNb )
- {
- SMTC_MODEM_HAL_TRACE_INFO( "Frame %d not encoded - directly store it and keep going\n", fragCounter );
-
- // The M first frame are not encoded store them
- SetRow( rawData, fragCounter - 1, FragDecoder.FragSize );
-
- SetParity( fragCounter - 1, FragDecoder.FragMissing, 0 );
-
- // Update the FragDecoder.FragMissing with the lost frames since the last Rx
- FragFindMissingFrags( fragCounter );
-
- if( fragCounter == FragDecoder.FragNb && FragDecoder.Status.FragNbLost == 0 )
- {
- // the case : all the M(FragNb) first rows have been transmitted with no error
- SMTC_MODEM_HAL_TRACE_INFO( "[OK] All uncoded fragments have been received - no need to continue\n" );
- return FRAG_SESSION_OK;
- }
-
- return FRAG_SESSION_ONGOING;
- }
-
- // In case of the end of true data is missing
- FragFindMissingFrags( fragCounter );
-
- // It will be impossible to reconstruct the original data
- if( FragDecoder.Status.FragNbLost > FRAG_MAX_FRAME_LOSS )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "Lost too many fragments\n" );
- FragDecoder.Status.MatrixError = 1;
- return FRAG_SESSION_ABORT;
- }
-
- // At this point we receive encoded frames and the number of lost frames is well known
- FragGetParityMatrixRow( fragCounter, FragDecoder.FragNb, matrixRow );
- SMTC_MODEM_HAL_TRACE_INFO( "Get parity matrix row %d\n", fragCounter );
- PARITY_LINE_PRINT( "matrixRow", matrixRow, 0, FragDecoder.FragNb );
-
- SMTC_MODEM_HAL_TRACE_INFO( "Checking if this fragments brings interesting information\n" );
- DATA_PRINT_FRAG( "Raw", rawData, FragDecoder.FragSize );
- for( int32_t i = 0; i < FragDecoder.FragNb; i++ )
- {
- if( GetParity( i, matrixRow ) == 1 ) // This fragment brings potentially new data for missing frag i
- {
- if( GetParity( i, FragDecoder.FragMissing ) == 0 ) // Nope, already received
- {
- SetParity( i, matrixRow, 0 );
- GetRow( matrixDataTemp, i, FragDecoder.FragSize );
- XorDataLine( rawData, matrixDataTemp, FragDecoder.FragSize );
- SMTC_MODEM_HAL_TRACE_INFO( "Fragment %d already received\n", i + 1 );
- DATA_PRINT_FRAG( "XOR", rawData, FragDecoder.FragSize );
- }
- else // New unknown data, store it somewhere
- {
- // Fill the "little" boolean matrix m2b
- // - Fragment {fragCounter} can give information on fragment {i}.
- // - Fragment {i} is the {n}th missing, we need to find n
- // Warning, we need to give the real fragCounter (1-indexed)
- uint16_t nth = FragFindMissing( i + 1 );
- if( nth >= FRAG_MAX_FRAME_LOSS )
- {
- // We didn't find it, maybe we have too many frames lost?
- // We panic, because this should really not happen
- // and means we have a deeper source of errors.
- smtc_modem_hal_mcu_panic( "Could not find missing fragment %d in FragMissingIndex\n", i + 1 );
- }
-
- // - We store that this fragment {fragCounter} can retrieve data for the {n}th in dataTempVector
- SMTC_MODEM_HAL_TRACE_INFO(
- "Fragment %d could bring new data for fragment %d (missing #%d) (total %d)\n", fragCounter, i + 1,
- nth, FragDecoder.Status.FragNbLost );
- SMTC_MODEM_HAL_TRACE_INFO( "SetParity for missing %d\n", nth );
-
- SetParity( nth, dataTempVector, 1 );
- if( first == 0 )
- {
- // Used to tell that we received at least one useful redundant fragment
- first = 1;
- }
- }
- }
- }
- PARITY_LINE_PRINT( "matrixRow", matrixRow, 0, FragDecoder.FragNb );
-
- PARITY_LINE_PRINT( "dataTempVector", dataTempVector, 0, FRAG_MAX_FRAME_LOSS );
- firstOneInRow = BitArrayFindFirstOne( dataTempVector, FragDecoder.Status.FragNbLost );
-
- SMTC_MODEM_HAL_TRACE_INFO( "first %d firstOneInRow %d\n", first, firstOneInRow + 1 );
-
- if( first > 0 )
- {
- int32_t li;
- int32_t lj;
-
- // Manage a new line in MatrixM2B
- PARITY_LINE_PRINT( "S", FragDecoder.S, 0, FRAG_MAX_FRAME_LOSS );
- while( GetParity( firstOneInRow, FragDecoder.S ) == 1 )
- {
- // Row already diagonalized exist & ( FragDecoder.MatrixM2B[firstOneInRow][0] )
- FragExtractLineFromBinaryMatrix( dataTempVector2, firstOneInRow, FragDecoder.Status.FragNbLost );
- PARITY_LINE_PRINT( "dataTempVector2", dataTempVector2, 0, FragDecoder.Status.FragNbLost );
- XorParityLine( dataTempVector, dataTempVector2, FragDecoder.Status.FragNbLost );
-
- // Have to store it in the mi th position of the missing frag
- li = FragFindMissingIndex( firstOneInRow );
- GetRow( matrixDataTemp, li, FragDecoder.FragSize );
- XorDataLine( rawData, matrixDataTemp, FragDecoder.FragSize );
- DATA_PRINT_FRAG( "XOR2", rawData, FragDecoder.FragSize );
- if( BitArrayIsAllZeros( dataTempVector, FragDecoder.Status.FragNbLost ) )
- {
- noInfo = 1;
- break;
- }
- firstOneInRow = BitArrayFindFirstOne( dataTempVector, FragDecoder.Status.FragNbLost );
- }
-
- if( noInfo == 0 )
- {
- // Store the raw data into the final file, to retrieve later
- FragPushLineToBinaryMatrix( dataTempVector, firstOneInRow, FragDecoder.Status.FragNbLost );
- li = FragFindMissingIndex( firstOneInRow );
- SMTC_MODEM_HAL_TRACE_INFO( "SetRow %d (fragment %d)\n", li, li + 1 );
- SetRow( rawData, li, FragDecoder.FragSize );
- SetParity( firstOneInRow, FragDecoder.S, 1 );
- FragDecoder.M2BLine++;
- DATA_PRINT_FRAG( "SAVE", rawData, FragDecoder.FragSize );
- }
-
- if( FragDecoder.M2BLine == FragDecoder.Status.FragNbLost )
- {
- // Then last step diagonalized
- // Step 5 from the paper
- if( FragDecoder.Status.FragNbLost > 1 )
- {
- int32_t i, j;
-
- for( i = ( FragDecoder.Status.FragNbLost - 2 ); i >= 0; i-- )
- {
- li = FragFindMissingIndex( i );
- GetRow( matrixDataTemp, li, FragDecoder.FragSize );
- for( j = ( FragDecoder.Status.FragNbLost - 1 ); j > i; j-- )
- {
- FragExtractLineFromBinaryMatrix( dataTempVector2, i, FragDecoder.Status.FragNbLost );
- FragExtractLineFromBinaryMatrix( dataTempVector, j, FragDecoder.Status.FragNbLost );
- if( GetParity( j, dataTempVector2 ) == 1 )
- {
- XorParityLine( dataTempVector2, dataTempVector, FragDecoder.Status.FragNbLost );
-
- lj = FragFindMissingIndex( j );
-
- GetRow( rawData, lj, FragDecoder.FragSize );
- XorDataLine( matrixDataTemp, rawData, FragDecoder.FragSize );
- }
- }
- SetRow( matrixDataTemp, li, FragDecoder.FragSize );
- }
- }
-
- SMTC_MODEM_HAL_TRACE_INFO( "Session reconstructed, FragNbLost %d\n", FragDecoder.Status.FragNbLost );
- return FRAG_SESSION_OK;
- }
- }
-
- SMTC_MODEM_HAL_TRACE_INFO( "No new information -- return FRAG_SESSION_ONGOING\n" );
- return FRAG_SESSION_ONGOING;
-}
-
-FragDecoderStatus_t FragDecoderGetStatus( void )
-{
- return FragDecoder.Status;
-}
-
-uint32_t FragDecoderFileSize( void )
-{
- uint32_t size = FragDecoder.FragNb * FragDecoder.FragSize;
- SMTC_MODEM_HAL_TRACE_INFO( "FileSize NB %d Size %d total %d\n", FragDecoder.FragNb, FragDecoder.FragSize, size );
- return size;
-}
-
-/*
- *=============================================================================
- * Fragmentation decoder algorithm utilities
- *=============================================================================
- */
-
-static void SetRow( uint8_t* src, uint16_t row, uint16_t size )
-{
- if( ( FragDecoder.Callbacks != NULL ) && ( FragDecoder.Callbacks->FragDecoderWrite != NULL ) )
- {
- FragDecoder.Callbacks->FragDecoderWrite( row * size, src, size );
- }
-}
-
-static void GetRow( uint8_t* dst, uint16_t row, uint16_t size )
-{
- if( ( FragDecoder.Callbacks != NULL ) && ( FragDecoder.Callbacks->FragDecoderRead != NULL ) )
- {
- FragDecoder.Callbacks->FragDecoderRead( row * size, dst, size );
- }
-}
-
-STATIC uint8_t GetParity( uint16_t index, uint8_t* matrixRow )
-{
- uint8_t parity;
- parity = matrixRow[index >> 3];
- parity = ( parity >> ( 7 - ( index % 8 ) ) ) & 0x01;
- return parity;
-}
-
-STATIC void SetParity( uint16_t index, uint8_t* matrixRow, uint8_t parity )
-{
- uint8_t mask = 0xFF - ( 1 << ( 7 - ( index % 8 ) ) );
- parity = parity << ( 7 - ( index % 8 ) );
- matrixRow[index >> 3] = ( matrixRow[index >> 3] & mask ) + parity;
-}
-
-static bool IsPowerOfTwo( uint32_t x )
-{
- uint8_t sumBit = 0;
-
- for( uint8_t i = 0; i < 32; i++ )
- {
- sumBit += ( x & ( 1 << i ) ) >> i;
- }
- if( sumBit == 1 )
- {
- return true;
- }
- return false;
-}
-
-static void XorDataLine( uint8_t* line1, uint8_t* line2, int32_t size )
-{
- for( int32_t i = 0; i < size; i++ )
- {
- line1[i] = line1[i] ^ line2[i];
- }
-}
-
-static void XorParityLine( uint8_t* line1, uint8_t* line2, int32_t size )
-{
- for( int32_t i = 0; i < size; i++ )
- {
- SetParity( i, line1, ( GetParity( i, line1 ) ^ GetParity( i, line2 ) ) );
- }
-}
-
-static int32_t FragPrbs23( int32_t value )
-{
- int32_t b0 = value & 0x01;
- int32_t b1 = ( value & 0x20 ) >> 5;
- return ( value >> 1 ) + ( ( b0 ^ b1 ) << 22 );
- ;
-}
-
-STATIC void FragGetParityMatrixRow( int32_t n, int32_t m, uint8_t* matrixRow )
-{
- int32_t mTemp;
- int32_t x;
- int32_t nbCoeff = 0;
- int32_t r;
-
- if( IsPowerOfTwo( m ) != false )
- {
- mTemp = 1;
- }
- else
- {
- mTemp = 0;
- }
-
- x = 1 + ( 1001 * n );
- for( uint32_t i = 0; i < ( ( m >> 3 ) + 1 ); i++ )
- {
- matrixRow[i] = 0;
- }
- while( nbCoeff < ( m >> 1 ) )
- {
- r = 1 << 16;
- while( r >= m )
- {
- x = FragPrbs23( x );
- r = x % ( m + mTemp );
- }
- if( GetParity( r, matrixRow ) == 0 )
- {
- SetParity( r, matrixRow, 1 );
- nbCoeff += 1;
- }
- }
-}
-
-static uint16_t BitArrayFindFirstOne( uint8_t* bitArray, uint16_t size )
-{
- for( uint16_t i = 0; i < size; i++ )
- {
- if( GetParity( i, bitArray ) == 1 )
- {
- return i;
- }
- }
- return 0;
-}
-
-static uint8_t BitArrayIsAllZeros( uint8_t* bitArray, uint16_t size )
-{
- for( uint16_t i = 0; i < size; i++ )
- {
- if( GetParity( i, bitArray ) == 1 )
- {
- return 0;
- }
- }
- return 1;
-}
-
-/*!
- * \brief Finds & marks missing fragments
- *
- * \param [IN] counter Current fragment counter
- * \param [OUT] FragDecoder.FragNbMissingIndex[] array is updated in place
- */
-static void FragFindMissingFrags( uint16_t counter )
-{
- int32_t i;
- for( i = FragDecoder.Status.FragNbLastRx; i < ( counter - 1 ); i++ )
- {
- if( i < FragDecoder.FragNb )
- {
- SMTC_MODEM_HAL_TRACE_INFO( "Fragment %d is missing, store it at index %d\n", i + 1, i );
- SetParity( i, FragDecoder.FragMissing, 1 );
- // Nth missing fragment is number i+1 (we keep the 0-indexed value)
- FragDecoder.FragMissingIndex[FragDecoder.Status.FragNbLost] = i;
- FragDecoder.Status.FragNbLost++;
- }
- }
- if( i < FragDecoder.FragNb )
- {
- FragDecoder.Status.FragNbLastRx = counter;
- }
- else
- {
- FragDecoder.Status.FragNbLastRx = FragDecoder.FragNb + 1;
- }
- SMTC_MODEM_HAL_TRACE_INFO( "RECEIVED : %5d / %5d Fragments\r\n", FragDecoder.Status.FragNbRx,
- FragDecoder.FragNb );
- SMTC_MODEM_HAL_TRACE_INFO( " %5d / %5d Bytes\r\n", FragDecoder.Status.FragNbRx * FragDecoder.FragSize,
- FragDecoder.FragNb * FragDecoder.FragSize );
- SMTC_MODEM_HAL_TRACE_INFO( "LOST : %7d Fragments\r\n\r\n", FragDecoder.Status.FragNbLost );
-}
-
-/*!
- * \brief Finds the index (frag counter) of the x th missing frag
- *
- * \param [IN] x x th missing frag. Max FRAG_MAX_FRAME_LOSS
- *
- * \retval counter The counter value associated to the x th missing frag
- */
-static uint16_t FragFindMissingIndex( uint16_t x )
-{
- SMTC_MODEM_HAL_TRACE_INFO( "FragFindMissingIndex x %d -> %d\n", x, FragDecoder.FragMissingIndex[x] );
- return FragDecoder.FragMissingIndex[x];
-}
-
-/*!
- * \brief Find the index of missing fragment x in the small table
- *
- * \param [IN] fragCounter Number of the missing fragment (1-indexed)
- *
- * \retval index The index of the missing fragment in the small matrix. (0-indexed)
- * If the index is not found, FRAG_MAX_FRAME_LOSS is returned
- * to indicate an error, and the caller should check this condition.
- */
-static uint16_t FragFindMissing( uint16_t fragCounter )
-{
- for( uint16_t i = 0; i < FragDecoder.Status.FragNbLost; i++ )
- {
- if( FragDecoder.FragMissingIndex[i] == fragCounter - 1 )
- {
- return i;
- }
- }
- return FRAG_MAX_FRAME_LOSS;
-}
-
-/*!
- * \brief Extacts a row from the binary matrix and expands it to a bitArray
- * Only extracts the triangular sup part of the matrix. So all bits left
- * of the triangle are 0.
- *
- * \param [OUT] bitArray Pointer to the bit array
- * \param [IN] rowIndex Matrix row index Max FRAG_MAX_FRAME_LOSS
- * \param [IN] bitsInRow Number of bits in one row. Max FRAG_MAX_FRAME_LOSS
- */
-STATIC void FragExtractLineFromBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow )
-{
- uint32_t findByte = 0;
- uint32_t findBitInByte = 0;
-
- if( rowIndex > 0 )
- {
- findByte = ( rowIndex * bitsInRow - ( ( rowIndex * ( rowIndex - 1 ) ) >> 1 ) ) >> 3;
- findBitInByte = ( rowIndex * bitsInRow - ( ( rowIndex * ( rowIndex - 1 ) ) >> 1 ) ) % 8;
- }
- if( rowIndex > 0 )
- {
- for( uint16_t i = 0; i < rowIndex; i++ )
- {
- SetParity( i, bitArray, 0 );
- }
- }
- for( uint16_t i = rowIndex; i < bitsInRow; i++ )
- {
- SetParity( i, bitArray, ( FragDecoder.MatrixM2B[findByte] >> ( 7 - findBitInByte ) ) & 0x01 );
-
- findBitInByte++;
- if( findBitInByte == 8 )
- {
- findBitInByte = 0;
- findByte++;
- }
- }
-}
-
-/*!
- * \brief Collapses and Pushs a row of a bit array to the matrix
- * Only store the triangular sup part of the matrix. All bits left of the triangle are ignored
- *
- * \param [IN] bitArray Pointer to the bit array
- * \param [IN] rowIndex Matrix row index. Max FRAG_MAX_FRAME_LOSS
- * \param [IN] bitsInRow Number of bits in one row. Max FRAG_MAX_FRAME_LOSS
- */
-STATIC void FragPushLineToBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow )
-{
- uint32_t findByte = 0;
- uint32_t findBitInByte = 0;
-
- if( rowIndex > 0 )
- {
- findByte = ( rowIndex * bitsInRow - ( ( rowIndex * ( rowIndex - 1 ) ) >> 1 ) ) >> 3;
- findBitInByte = ( rowIndex * bitsInRow - ( ( rowIndex * ( rowIndex - 1 ) ) >> 1 ) ) % 8;
- }
- SMTC_MODEM_HAL_TRACE_PRINTF( "PushLine row %d nb_bits %d | findByte %d bitInByte %d\n", rowIndex, bitsInRow,
- findByte, findBitInByte );
-
- for( uint16_t i = rowIndex; i < bitsInRow; i++ )
- {
- if( GetParity( i, bitArray ) == 0 )
- {
- FragDecoder.MatrixM2B[findByte] =
- FragDecoder.MatrixM2B[findByte] & ( 0xFF - ( 1 << ( 7 - findBitInByte ) ) );
- }
- findBitInByte++;
- if( findBitInByte == 8 )
- {
- findBitInByte = 0;
- findByte++;
- }
- }
- PARITY_ARRAY_PRINT( "M2B", FragDecoder.MatrixM2B, bitsInRow, bitsInRow );
-}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.h
deleted file mode 100644
index e1eb512..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/frag_decoder.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*!
- * \file FragDecoder.h
- *
- * \brief Implements the LoRa-Alliance fragmentation decoder
- * Specification:
- * https://lora-alliance.org/sites/default/files/2018-09/fragmented_data_block_transport_v1.0.0.pdf
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef __FRAG_DECODER_H__
-#define __FRAG_DECODER_H__
-
-#include
-#include
-
-/*
- * The following parameters have an impact on the memory footprint.
- * The major contributors are the parity matrix and missing fragment index.
- *
- * Heap size >= FRAG_MAX_FRAME_LOSS * (FRAG_MAX_FRAME_LOSS + 1) / 2 / 8
- * + 2 * FRAG_MAX_FRAME_LOSS
- * + FRAG_MAX_NB / 8
- *
- * Stack size >= FRAG_MAX_NB
- */
-
-/*!
- * Maximum number of uncoded fragment that can be handled.
- *
- * \remark This parameter has an impact on the heap memory footprint.
- * It defines the size of the bitarray of missing fragments.
- */
-#define FRAG_MAX_NB 150
-
-/*!
- * Maximum fragment size that can be handled.
- *
- * \remark This parameter has a slight impact on the stack memory footprint,
- * as a buffer of this size is necessary for the decoding computation.
- */
-#define FRAG_MAX_SIZE 200
-
-/*!
- * Maximum number of uncoded fragments that can be lost.
- * This determines the resistance of the algorithm wrt. packet loss
- *
- * \remark This parameter has an impact on the heap memory footprint.
- * It defines the size of the parity matrix and of the missing fragment index array.
- */
-#define FRAG_MAX_FRAME_LOSS 64
-
-/*!
- * \brief This return code indicates the state of the session
- */
-typedef enum
-{
- FRAG_SESSION_OK = 0,
- FRAG_SESSION_ONGOING,
- FRAG_SESSION_ERROR,
- FRAG_SESSION_BADSIZE,
- FRAG_SESSION_ABORT,
- FRAG_SESSION_MEM_ERROR,
-} FragDecoderSessionStatus_t;
-
-/*!
- * \brief This stores the current session statistics
- */
-typedef struct sFragDecoderStatus
-{
- uint16_t FragNbRx;
- uint16_t FragNbLost;
- uint16_t FragNbLastRx;
- uint8_t MatrixError;
-} FragDecoderStatus_t;
-
-/*!
- * \brief The callbacks are used to read/write fragments in the final data block memory.
- * This allows the client code to use Flash memory as the destination.
- */
-typedef struct sFragDecoderCallbacks
-{
- /*!
- * Writes `data` buffer of `size` starting at address `addr`
- *
- * \param [IN] addr Address start index to write to.
- * \param [IN] data Data buffer to be written.
- * \param [IN] size Size of data buffer to be written.
- *
- * \retval status Write operation status [0: Success, -1 Fail]
- */
- int8_t ( *FragDecoderWrite )( uint32_t addr, uint8_t* data, uint32_t size );
- /*!
- * Reads `data` buffer of `size` starting at address `addr`
- *
- * \param [IN] addr Address start index to read from.
- * \param [OUT] data Data buffer to be read.
- * \param [IN] size Size of data buffer to be read.
- *
- * \retval status Read operation status [0: Success, -1 Fail]
- */
- int8_t ( *FragDecoderRead )( uint32_t addr, uint8_t* data, uint32_t size );
-} FragDecoderCallbacks_t;
-
-/*!
- * \brief Initializes the fragmentation decoder
- *
- * \param [IN] fragNb Number of expected fragments (without redundancy packets)
- * \param [IN] fragSize Size of a fragment
- * \param [IN] callbacks Pointer to the Write/Read functions.
- */
-int32_t FragDecoderInit( uint16_t fragNb, uint8_t fragSize, FragDecoderCallbacks_t* callbacks );
-/*!
- * \brief Gets the maximum file size that can be received
- *
- * \retval size FileSize
- */
-uint32_t FragDecoderGetMaxFileSize( void );
-
-/*!
- * \brief Gets the current file size that is configured in the decoding session
- *
- * \retval size FileSize
- */
-uint32_t FragDecoderFileSize( void );
-
-/*!
- * \brief Function to decode and reconstruct the binary file
- * Called for each receive frame
- *
- * \param [IN] fragCounter Fragment counter [1..(FragDecoder.FragNb + FragDecoder.Redundancy)]
- * \param [IN] rawData Pointer to the fragment to be processed (length = FragDecoder.FragSize)
- * \param [OUT] nbLost Number of non-coded packets lost
- *
- * \retval status Process status.
- */
-FragDecoderSessionStatus_t FragDecoderProcess( uint16_t fragCounter, uint8_t* rawData );
-
-/*!
- * \brief Gets the current fragmentation status
- *
- * \retval status Fragmentation decoder status
- */
-FragDecoderStatus_t FragDecoderGetStatus( void );
-
-#if defined( TEST )
-// This is only accessible during unit testing.
-
-/*!
- * \brief Gets the parity matrix row for fragment N (M non-coded fragments)
- *
- * \param [IN] n Current fragCounter
- * \param [IN] m Number of non-coded fragments
- * \param [OUT] matrixRow Destination array
- */
-void FragGetParityMatrixRow( int32_t n, int32_t m, uint8_t* matrixRow );
-
-/*!
- * \brief Gets the binary triangular-sup matrix row from M2B
- *
- * \param [OUT] bitArray Destination array
- * \param [IN] rowIndex Index of the requested row
- * \param [IN] bitsInRow Size of the matrix
- */
-void FragExtractLineFromBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow );
-
-/*!
- * \brief Store the binary triangular-sup matrix row to M2B
- *
- * \param [OUT] bitArray Source array
- * \param [IN] rowIndex Index of the requested row
- * \param [IN] bitsInRow Size of the matrix
- */
-void FragPushLineToBinaryMatrix( uint8_t* bitArray, uint16_t rowIndex, uint16_t bitsInRow );
-
-/*!
- * \brief Gets the bit stored in a binary array
- *
- * \param [IN] index Index of the requested bit
- * \param [IN] matrixRow Source array
- */
-uint8_t GetParity( uint16_t index, uint8_t* matrixRow );
-
-/*!
- * \brief Sets the bit stored in a binary array
- *
- * \param [IN] index Index of the requested bit
- * \param [IN] matrixRow Destination array
- */
-void SetParity( uint16_t index, uint8_t* matrixRow, uint8_t parity );
-#endif
-
-#endif // __FRAG_DECODER_H__
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c
deleted file mode 100644
index 3496f6b..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.c
+++ /dev/null
@@ -1,1423 +0,0 @@
-/*!
- * \file fragmented_data_block.c
- *
- * \brief LoRaWAN Fragmented Data Block Transport protocol
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-#include // C99 types
-#include // bool type
-
-#include "gpio.h"
-#include "radio_ctrl.h"
-#include "frag_decoder.h"
-#include "smtc_modem_hal.h"
-#include "aes.h"
-#include "cmac.h"
-#include "nvmcu_hal.h"
-#include "modem_utilities.h" // for crc fw
-#include "patch_upd.h"
-#include "pool_mem.h"
-#include "smtc_modem_hal_dbg_trace.h"
-#include "fragmented_data_block.h"
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE MACROS ----------------------------------------------------------
- */
-
-/*
- * Allow access to internal functions in unit tests
- */
-#if defined( TEST )
-#define STATIC
-#else
-#define STATIC static
-#endif
-
-/*!
- * \brief Returns the minimum value between a and b
- *
- * \param [IN] a 1st value
- * \param [IN] b 2nd value
- * \retval minValue Minimum value
- */
-#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
-
-/*!
- * \brief Get a particular bit value from a byte
- *
- * \param [IN] b Any byte from which we want a bit value
- * \param [IN] p Position of the bit in the byte [0..7]
- * \param [IN] n Number of bits we want to get
- * \retval The value corresponding the requested bits
- */
-#define TAKE_N_BITS_FROM( b, p, n ) ( ( ( b ) >> ( p ) ) & ( ( 1 << ( n ) ) - 1 ) )
-
-// Return byte b from value v
-#define BYTE( v, b ) ( ( ( v ) >> ( 8 * ( b ) ) ) & 0xFF )
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE TYPES -----------------------------------------------------------
- */
-
-typedef struct s_frag_session_status_req
-{
- uint8_t frag_index;
- uint8_t participants;
-} s_frag_session_status_req_t;
-
-struct s_frag_session
-{
- uint8_t frag_index;
- uint8_t mc_group_bit_mask;
-};
-
-struct s_control
-{
- uint8_t ack_reception;
- uint8_t frag_algo;
- uint8_t block_ack_delay;
-};
-
-typedef enum target_type
-{
- TARGET_MODEM = 0,
- TARGET_HOST = 0x01000000
-} e_target_type_t;
-
-typedef enum descriptor_error
-{
- DESCRIPTOR_ERROR,
- DESCRIPTOR_OK
-} e_descriptor_error_t;
-
-typedef struct s_frag_session_setup_req
-{
- struct s_frag_session frag_session;
- uint16_t nb_frag;
- uint8_t frag_size;
- struct s_control control;
- uint8_t padding;
- uint32_t descriptor;
- uint16_t session_cnt;
- uint32_t mic;
-} s_frag_session_setup_req_t;
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE CONSTANTS -------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE VARIABLES -------------------------------------------------------
- */
-
-#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
-static const char* frag_cmd_str[FRAG_CMD_MAX] = {
- [FRAG_CMD_PACKAGE_VERSION] = "PACKAGE_VERSION",
- [FRAG_CMD_FRAG_SESSION_STATUS] = "FRAG_SESSION_STATUS",
- [FRAG_CMD_FRAG_SESSION_SETUP] = "FRAG_SESSION_SETUP",
- [FRAG_CMD_FRAG_SESSION_DELETE] = "FRAG_SESSION_DELETE",
- [FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED] = "FRAG_DATA_BLOCK_RECEIVED",
- [FRAG_CMD_FRAG_DATA_FRAGMENT] = "FRAG_DATA_FRAGMENT",
-};
-#endif
-
-// TODO Change this to put it in flash
-// Memory to hold the full reconstructed data block
-// static uint8_t frag_data_buffer[FRAG_DATA_BLOCK_SIZE_MAX];
-#define FRAG_MIC_BLOCK_SIZE 16
-#define FRAG_MIC_BUFFER_SIZE 128
-#define FRAG_MIC_B0_HEADER 0x49
-
-static uint8_t frag_tx_payload[FRAG_UPLINK_LENGTH_MAX];
-static e_file_error_t check_received_patch( void );
-struct
-{
- // Uplink buffer
- uint8_t frag_tx_payload_index;
- uint8_t frag_max_length_up_payload;
-
- // Pending requests
- uint8_t frag_req_status[FRAG_UPLINK_REQ_MAX];
- uint8_t frag_req_status_num;
- s_frag_session_status_req_t frag_session_status_req;
- s_frag_session_setup_req_t frag_session_setup_req;
- uint8_t frag_session_delete_req;
-
- // Current fragmentation status
- bool is_frag_session_exist;
- bool is_data_block_reconstructed;
- bool is_data_block_mic_success;
- bool is_data_block_sign_success;
- bool is_data_block_crc_fw_success;
- bool is_defrag_memory_exceeded;
- bool is_session_aborted; // lost too many fragments for decoder to recover
- bool is_ack_reception_done; // The server has confirmed the ack_reception
- uint16_t nb_frag_uncoded_received;
- uint16_t nb_frag_coded_received;
- uint16_t nb_frag_ignored;
- int32_t session_cnt_prev; // TODO: to be stored in flash ??
-} frag_context;
-
-#define frag_tx_payload_index frag_context.frag_tx_payload_index
-#define frag_max_length_up_payload frag_context.frag_max_length_up_payload
-
-#define frag_req_status frag_context.frag_req_status
-#define frag_req_status_num frag_context.frag_req_status_num
-#define frag_session_status_req frag_context.frag_session_status_req
-#define frag_session_setup_req frag_context.frag_session_setup_req
-#define frag_session_delete_req frag_context.frag_session_delete_req
-
-#define is_frag_session_exist frag_context.is_frag_session_exist
-#define is_data_block_reconstructed frag_context.is_data_block_reconstructed
-#define is_data_block_mic_success frag_context.is_data_block_mic_success
-#define is_data_block_sign_success frag_context.is_data_block_sign_success
-#define is_data_block_crc_fw_success frag_context.is_data_block_crc_fw_success
-#define is_defrag_memory_exceeded frag_context.is_defrag_memory_exceeded
-#define is_session_aborted frag_context.is_session_aborted
-#define is_ack_reception_done frag_context.is_ack_reception_done
-#define nb_frag_uncoded_received frag_context.nb_frag_uncoded_received
-#define nb_frag_coded_received frag_context.nb_frag_coded_received
-#define nb_frag_ignored frag_context.nb_frag_ignored
-#define session_cnt_prev frag_context.session_cnt_prev
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
- */
-
-/*!
- * \brief initialise the session variables
- *
- *
- * \param [IN] void
- */
-void frag_context_reset( void )
-{
- is_data_block_reconstructed = false;
- is_data_block_mic_success = false;
- is_data_block_sign_success = false;
- is_data_block_crc_fw_success = false;
- is_defrag_memory_exceeded = false;
- is_ack_reception_done = false;
- nb_frag_uncoded_received = 0;
- nb_frag_coded_received = 0;
-}
-
-/*!
- * \brief Write fragment to memory, callback for frag_decoder
- *
- * Writes `data` buffer of `size` starting at address `addr`
- *
- * \param [IN] addr Address start index to write to.
- * \param [IN] data Data buffer to be written.
- * \param [IN] size Size of data buffer to be written.
- *
- * \retval status Write operation status [0: Success, -1 Fail]
- */
-int8_t frag_decoder_write_fl( uint32_t addr, uint8_t* data, uint32_t size )
-{
- uint32_t target_address = FLASH_DELTA_UPDATE + addr;
-
- if( data == NULL )
- {
- return -1;
- }
- if( target_address < FLASH_DELTA_UPDATE )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash write error address out of limit:%x\n", target_address );
- return -1;
- }
-
- // Check that it fits
- if( target_address + size >= FLASH_DELTA_UPDATE + FRAG_DATA_BLOCK_SIZE_MAX )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash write error address out of limit:%x\n", target_address + size );
- return -1;
- }
-
- // write
- DEBUG_PRINT( DBG_NOTE, "Flash write addr:%x,data:%x,size:%d\n", target_address, *data, size );
-
- target_address = ( target_address - FLASH_BASE );
- uint8_t page_start = target_address >> 11;
- uint32_t* copy_page = POOL_MEM.StartOfPoolMem;
- DEBUG_PRINT( DBG_NOTE, "page is %d\n", page_start );
- memcpy( ( uint8_t* ) copy_page, ( uint8_t* ) ( ( page_start << 11 ) + FLASH_BASE ), 4096 );
- DEBUG_PRINT( DBG_NOTE, "page is %d\n", page_start );
- memcpy( ( uint8_t* ) copy_page + ( target_address - ( page_start << 11 ) ), data, size );
- FlashErasePage( page_start, MainFlash );
- FlashErasePage( page_start + 1, MainFlash );
- if( FlashWrite( ( page_start << 11 ) >> 2, copy_page, 1024, 0, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash write error:%x\n", target_address );
- return -1;
- }
- return 0;
-}
-
-/*!
- * \brief Read fragment from memory, callback for frag_decoder
- *
- * Reads `data` buffer of `size` starting at address `addr`
- *
- * \param [IN] addr Address start index to read from.
- * \param [IN] data Data buffer to be read.
- * \param [IN] size Size of data buffer to be read.
- *
- * \retval status Read operation status [0: Success, -1 Fail]
- */
-int8_t frag_decoder_read_fl( uint32_t addr, uint8_t* data, uint32_t size )
-{
- void* rc;
- // uint32_t flashStartAddr;
-
- uint32_t target_address = FLASH_DELTA_UPDATE + addr;
- // flashStartAddr = target_address;
-
- if( data == NULL )
- {
- return -1;
- }
- if( target_address < FLASH_DELTA_UPDATE )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash read error address out of limit:%x\n", target_address );
- return -1;
- }
-
- // Check that it fits
- if( target_address + size >= FLASH_DELTA_UPDATE + FRAG_DATA_BLOCK_SIZE_MAX )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash read error address out of limit:%x\n", target_address + size );
- return -1;
- }
- // DEBUG_PRINT(DBG_FATAL,"Flash read addr:%x,size:%d\n",target_address,size);
- rc = memcpy( data, ( uint8_t* ) target_address, size );
- if( rc != NULL )
- {
- DEBUG_PRINT( DBG_FATAL, "Flash read [0]:%x,[1]:%x,[2]:%x,[3]:%x\n", data[0], data[1], data[2], data[3] );
- return 0; // Success
- }
-
- // data = (uint8_t*)target_address;
- DEBUG_PRINT( DBG_FATAL, "Flash read [0]:%x,[1]:%x,[2]:%x,[3]:%x\n", data[0], data[1], data[2], data[3] );
- return -1;
-}
-
-// Callback structure passed to frag_decoder
-static FragDecoderCallbacks_t frag_decoder_callbacks = {
- .FragDecoderWrite = frag_decoder_write_fl,
- .FragDecoderRead = frag_decoder_read_fl,
-};
-
-void frag_session_print( void )
-{
-#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
- SMTC_MODEM_HAL_TRACE_INFO( "------ Current Frag Session context -------\n" );
- SMTC_MODEM_HAL_TRACE_INFO( " session exist: %d\n", is_frag_session_exist );
- SMTC_MODEM_HAL_TRACE_INFO( " reconstructed: %d\n", is_data_block_reconstructed );
- SMTC_MODEM_HAL_TRACE_INFO( " MIC success: %d\n", is_data_block_mic_success );
- SMTC_MODEM_HAL_TRACE_INFO( " SIGN success: %d\n", is_data_block_sign_success );
- SMTC_MODEM_HAL_TRACE_INFO( " CRC_FW success: %d\n", is_data_block_crc_fw_success );
- SMTC_MODEM_HAL_TRACE_INFO( " Memory Exceeded: %d\n", is_defrag_memory_exceeded );
- SMTC_MODEM_HAL_TRACE_INFO( " nb frag received: %u (uncoded:%u, coded:%u, ignored:%u)\n",
- nb_frag_uncoded_received + nb_frag_coded_received, nb_frag_uncoded_received,
- nb_frag_coded_received, nb_frag_ignored );
- SMTC_MODEM_HAL_TRACE_INFO( " previous session cnt: %d\n", session_cnt_prev );
- if( is_frag_session_exist == true )
- {
- SMTC_MODEM_HAL_TRACE_INFO( "------ Current Frag Session Setup request ------\n" );
- SMTC_MODEM_HAL_TRACE_INFO( " frag_session.frag_index: %u\n", frag_session_setup_req.frag_session.frag_index );
- SMTC_MODEM_HAL_TRACE_INFO( " frag_session.mc_group_bit_mask: %u\n",
- frag_session_setup_req.frag_session.mc_group_bit_mask );
- SMTC_MODEM_HAL_TRACE_INFO( " nb_frag: %u\n", frag_session_setup_req.nb_frag );
- SMTC_MODEM_HAL_TRACE_INFO( " frag_size: %u\n", frag_session_setup_req.frag_size );
- SMTC_MODEM_HAL_TRACE_INFO( " control.ack_reception: %u\n", frag_session_setup_req.control.ack_reception );
- SMTC_MODEM_HAL_TRACE_INFO( " control.frag_algo: %u\n", frag_session_setup_req.control.frag_algo );
- SMTC_MODEM_HAL_TRACE_INFO( " control.block_ack_delay: %u\n", frag_session_setup_req.control.block_ack_delay );
- SMTC_MODEM_HAL_TRACE_INFO( " padding: %u\n", frag_session_setup_req.padding );
- SMTC_MODEM_HAL_TRACE_INFO( " descriptor: 0x%x\n", frag_session_setup_req.descriptor );
- SMTC_MODEM_HAL_TRACE_INFO( " session_cnt: %u\n", frag_session_setup_req.session_cnt );
- SMTC_MODEM_HAL_TRACE_INFO( " mic: 0x%x\n", frag_session_setup_req.mic );
- SMTC_MODEM_HAL_TRACE_INFO( "-----------------------------------\n" );
- }
-#endif
-}
-
-static inline bool is_frag_tx_buffer_not_full( uint8_t cmd_size )
-{
- return ( ( frag_tx_payload_index + cmd_size ) <= MIN( FRAG_UPLINK_LENGTH_MAX, frag_max_length_up_payload )
- ? true
- : false );
-}
-
-static void frag_decode_session_status_req( uint8_t* buffer )
-{
- frag_session_status_req.frag_index = TAKE_N_BITS_FROM( buffer[0], 1, 2 );
- frag_session_status_req.participants = TAKE_N_BITS_FROM( buffer[0], 0, 1 );
-}
-
-static void frag_decode_session_setup_req( uint8_t* buffer )
-{
- // byte 0
- frag_session_setup_req.frag_session.frag_index = TAKE_N_BITS_FROM( buffer[0], 4, 2 );
- frag_session_setup_req.frag_session.mc_group_bit_mask = TAKE_N_BITS_FROM( buffer[0], 0, 4 );
-
- // bytes 1, 2
- frag_session_setup_req.nb_frag = ( buffer[2] << 8 ) | buffer[1];
-
- // byte 3
- frag_session_setup_req.frag_size = buffer[3];
-
- // byte 4
- frag_session_setup_req.control.ack_reception = TAKE_N_BITS_FROM( buffer[4], 6, 1 );
- frag_session_setup_req.control.frag_algo = TAKE_N_BITS_FROM( buffer[4], 3, 3 );
- frag_session_setup_req.control.block_ack_delay = TAKE_N_BITS_FROM( buffer[4], 0, 3 );
-
- // byte 5
- frag_session_setup_req.padding = buffer[5];
-
- // bytes 6, 7, 8, 9
- frag_session_setup_req.descriptor =
- ( buffer[9] << 24 ) | ( buffer[8] << 16 ) | ( buffer[7] << 8 ) | ( buffer[6] << 0 );
-
- // bytes 10, 11
- frag_session_setup_req.session_cnt = ( buffer[11] << 8 ) | buffer[10];
-
- // bytes 12, 13, 14, 15
- frag_session_setup_req.mic =
- ( buffer[15] << 24 ) | ( buffer[14] << 16 ) | ( buffer[13] << 8 ) | ( buffer[12] << 0 );
-}
-
-static void frag_decode_session_delete_req( uint8_t* buffer )
-{
- // byte 0
- frag_session_delete_req = buffer[0] & 0x03;
-}
-
-static void frag_decode_data_block_received_ans( uint8_t* buffer )
-{
- if( TAKE_N_BITS_FROM( buffer[0], 0, 2 ) != 0 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragReceivedDataBlockAns: invalid FragIndex\n" );
- return;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_INFO( "FragReceivedDataBlockAns: AckReception has been received by the server\n" );
- is_ack_reception_done = true;
- }
-}
-
-#define FRAG_MIC_BLOCK_SIZE 16
-#define FRAG_MIC_BUFFER_SIZE 128
-#define FRAG_MIC_B0_HEADER 0x49
-
-STATIC e_frag_error_t frag_compute_datablock_key( uint8_t* key )
-{
- memset( key, 0, 16 );
- return FRAG_OK;
-}
-
-/*
- * Compute the MIC for the FragmentedDataBlock session.
- * We suppose that:
- * - all fields are little-endian
- * - devaddr is 0x00000000
- * - key is {0}[16]
- */
-STATIC e_frag_error_t frag_compute_mic( s_frag_session_setup_req_t session, uint32_t* mic )
-{
- AES_CMAC_CTX aes_cmac_ctx;
- uint8_t buffer[FRAG_MIC_BUFFER_SIZE];
- uint8_t micB0[FRAG_MIC_BLOCK_SIZE] = { 0 };
- uint8_t cmac[FRAG_MIC_BLOCK_SIZE] = { 0 };
- uint8_t data_block_int_key[16];
-
- /*
- * Use a static NULL address because the DAS does not know the unicast device address.
- * We should use lr1mac_core_devaddr_get() to comply with the LoRa Alliance paper.
- */
- uint32_t devaddr = 0;
-
- uint32_t file_size = ( session.nb_frag * session.frag_size ) - session.padding;
- uint8_t padding = file_size % FRAG_MIC_BLOCK_SIZE;
-
- /* Get the Data Block Integrity Key */
- if( frag_compute_datablock_key( data_block_int_key ) != FRAG_OK )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "frag_compute_mic: failed to get Data Block Integrity key\n" );
- return FRAG_ERROR;
- }
-
- SMTC_MODEM_HAL_TRACE_INFO( "MIC cnt %x index %x desc %x devaddr %x size %x\n", session.session_cnt,
- session.frag_session.frag_index, session.descriptor, devaddr, file_size );
-
- micB0[0] = FRAG_MIC_B0_HEADER;
-
- /* LoRaWAN uses a little endian representation */
- micB0[1] = BYTE( session.session_cnt, 0 );
- micB0[2] = BYTE( session.session_cnt, 1 );
-
- micB0[3] = session.frag_session.frag_index;
-
- micB0[4] = BYTE( session.descriptor, 0 );
- micB0[5] = BYTE( session.descriptor, 1 );
- micB0[6] = BYTE( session.descriptor, 2 );
- micB0[7] = BYTE( session.descriptor, 3 );
-
- micB0[8] = BYTE( devaddr, 0 );
- micB0[9] = BYTE( devaddr, 1 );
- micB0[10] = BYTE( devaddr, 2 );
- micB0[11] = BYTE( devaddr, 3 );
-
- micB0[12] = BYTE( file_size, 0 );
- micB0[13] = BYTE( file_size, 1 );
- micB0[14] = BYTE( file_size, 2 );
- micB0[15] = BYTE( file_size, 3 );
-
- AES_CMAC_Init( &aes_cmac_ctx );
- AES_CMAC_SetKey( &aes_cmac_ctx, data_block_int_key );
- AES_CMAC_Update( &aes_cmac_ctx, micB0, FRAG_MIC_BLOCK_SIZE );
-
- // The file might be in flash, so we have to copy it to a temporary buffer
- // to do the CMAC computation, which requires the buffer to be in RAM
-
- for( uint32_t addr = 0; addr < file_size; addr += FRAG_MIC_BUFFER_SIZE )
- {
- uint32_t len = MIN( FRAG_MIC_BUFFER_SIZE, file_size - addr );
- frag_decoder_read_fl( addr, buffer, len );
- for( int i = 0; i < len; i++ )
- DEBUG_PRINT( DBG_FATAL, "%x,", buffer[i] );
- DEBUG_PRINT( DBG_FATAL, " \n" );
- AES_CMAC_Update( &aes_cmac_ctx, buffer, len );
- }
- memset( buffer, 0, padding );
-
- AES_CMAC_Update( &aes_cmac_ctx, buffer, padding );
- AES_CMAC_Final( cmac, &aes_cmac_ctx );
-
- *mic = cmac[3] << 24 | cmac[2] << 16 | cmac[1] << 8 | cmac[0];
- return FRAG_OK;
-}
-
-STATIC int8_t frag_process_data_fragment( uint8_t* buffer, uint8_t buffer_len )
-{
- uint8_t frag_index; // session
- uint16_t frag_n; // index of the coded fragment
- FragDecoderSessionStatus_t rc; // FragDecoder return code
-
- if( is_frag_session_exist == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "DataFragment: no frag session on-going\n" );
- return FRAG_INVALID;
- }
-
- if( ( buffer_len - 2 ) != frag_session_setup_req.frag_size )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "DataFragment: wrong fragment size (exp:%u, got:%u)\n",
- frag_session_setup_req.frag_size, buffer_len - 2 );
- return FRAG_BADSIZE;
- }
-
- // Parse Index&N
- frag_index = TAKE_N_BITS_FROM( buffer[1], 6, 2 );
- frag_n = ( TAKE_N_BITS_FROM( buffer[1], 0, 6 ) << 8 ) | buffer[0];
-
- if( frag_index != 0 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "DataFragment: FragIndex unsupported\n" );
- return FRAG_INVALID;
- }
-
- if( frag_n < 1 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "DataFragment: N must be >= 1 \n" );
- return FRAG_INVALID;
- }
-
- if( frag_n <= frag_session_setup_req.nb_frag )
- {
- nb_frag_uncoded_received += 1;
- }
- if( frag_n > frag_session_setup_req.nb_frag )
- {
- nb_frag_coded_received += 1;
- }
- if( is_data_block_reconstructed )
- {
- // We don't need to process more fragments
- nb_frag_ignored += 1;
-
- frag_session_print( );
- return FRAG_OK;
- }
- if( is_session_aborted )
- {
- // We don't need to process more fragments
- nb_frag_ignored += 1;
- frag_session_print( );
- return FRAG_OK;
- }
-
- // The decoder rejects 'old' fragments, if their frag_n precede the latest received.
- rc = FragDecoderProcess( frag_n, &buffer[2] );
- SMTC_MODEM_HAL_TRACE_PRINTF( "Fragment %d FragDecoderProcess rc %d\n", frag_n, rc );
- if( rc == FRAG_SESSION_OK )
- {
- SMTC_MODEM_HAL_TRACE_INFO( "SUCCESS: FragDecoder reconstructed the full data, no need for more fragments\n" );
- // This means the decoder received enough fragments and reconstructed the data.
- // rc contains the number of missing frames
- is_data_block_reconstructed = true;
- // BlockReceived message should be sent automatically, if needed, now that reconstructed is True
-
- uint32_t mic;
- frag_compute_mic( frag_session_setup_req, &mic );
- is_data_block_mic_success = ( frag_session_setup_req.mic == mic );
- SMTC_MODEM_HAL_TRACE_INFO( "MIC setup %x | computed %x [%s]\n", frag_session_setup_req.mic, mic,
- is_data_block_mic_success ? " OK " : "FAIL" );
- }
- else
- {
- // This means that the decoder generated an error, or is ongoing wihout
- // any means to reconstruct the original data yet
- switch( rc )
- {
- case FRAG_SESSION_ONGOING:
- // All is well, decoder is waiting for additional fragments
- SMTC_MODEM_HAL_TRACE_INFO( "FRAG: Waiting for more fragments\n" );
- break;
- case FRAG_SESSION_ABORT:
- // Lost too many fragments
- SMTC_MODEM_HAL_TRACE_ERROR( "FRAG: Lost too many fragments to be able to reconstruct\n" );
- is_session_aborted = true;
- break;
- case FRAG_SESSION_ERROR:
- // Invalid frag number
- SMTC_MODEM_HAL_TRACE_WARNING( "FRAG: Invalid packet number\n" );
- break;
- default:
- break;
- }
- }
-
- frag_session_print( );
-
- return FRAG_OK;
-}
-
-e_descriptor_error_t frag_session_parse_descriptor( uint32_t descriptor )
-{
- // this function check if the target is modem and check the validity of the current fw
- // return 1 if check is valid
- if( ( descriptor & 0x01000000 ) == TARGET_HOST )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( " ERROR parsing descriptor : Bad target \n" );
- return DESCRIPTOR_ERROR;
- }
- uint32_t crctmp = compute_crc_fw( ) & 0x00FFFFFF;
- uint32_t crc_descriptor = descriptor & 0x00FFFFFF;
-
- if( crctmp != crc_descriptor )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( " ERROR parsing descriptor : Bad crc fw crc fw = %x crc descriptor = %x \n",
- crctmp, crc_descriptor );
- return DESCRIPTOR_ERROR;
- }
- return DESCRIPTOR_OK;
-}
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
- */
-
-void frag_init( void )
-{
- // Initialize requests holding variables
- frag_req_status_num = 0;
- memset( frag_req_status, 0, sizeof frag_req_status );
- memset( &frag_session_status_req, 0, sizeof( struct s_frag_session_status_req ) );
- memset( &frag_session_setup_req, 0, sizeof( struct s_frag_session_setup_req ) );
- frag_session_delete_req = 0;
-
- // Initialize uplink buffer context
- frag_tx_payload_index = 0;
- frag_max_length_up_payload = FRAG_UPLINK_LENGTH_MAX;
-
- // Initialize fragmentation session context variables
- is_frag_session_exist = false;
- is_data_block_reconstructed = false;
- is_data_block_mic_success = false;
- is_data_block_sign_success = false;
- is_data_block_crc_fw_success = false;
- is_defrag_memory_exceeded = false;
- is_ack_reception_done = false;
- is_session_aborted = false;
- nb_frag_uncoded_received = 0;
- nb_frag_coded_received = 0;
- nb_frag_ignored = 0;
- session_cnt_prev = -1;
-}
-
-// Returns the number of commands handled, or FRAG_CMD_ERROR
-int8_t frag_parser( uint8_t* frag_buffer, uint8_t frag_buffer_len )
-{
- uint8_t frag_rx_buffer_index = 0;
- // bao add
- uint8_t nb_cmd = 0;
- uint8_t nb_cmd_package_version = 0; // FRAG_CMD_PACKAGE_VERSION = 0;
- uint8_t nb_cmd_frag_session_status = 0; // FRAG_CMD_FRAG_SESSION_STATUS = 0;
- uint8_t nb_cmd_frag_session_setup = 0; // FRAG_CMD_FRAG_SESSION_SETUP = 0;
- uint8_t nb_cmd_frag_session_delete = 0; // FRAG_CMD_FRAG_SESSION_DELETE = 0;
- uint8_t nb_cmd_frag_data_block_received = 0; // FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED = 0;
- // -----------
- // Reset answer buffer index
- frag_tx_payload_index = 0;
- frag_req_status_num = 0;
-
- if( frag_buffer == NULL )
- {
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- if( frag_buffer_len < FRAG_DOWNLINK_HEADER_LENGTH )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "Fragmentation Downlink must contain at least 1 byte\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- while( ( frag_buffer_len > frag_rx_buffer_index ) && ( nb_cmd < 2 ) )
- {
-#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
- if( frag_buffer[frag_rx_buffer_index] < FRAG_CMD_MAX )
- SMTC_MODEM_HAL_TRACE_INFO( "FRAG_CMD_%s (0x%x)\n", frag_cmd_str[frag_buffer[frag_rx_buffer_index]],
- frag_buffer[frag_rx_buffer_index] );
-#endif
-
- switch( frag_buffer[frag_rx_buffer_index] )
- {
- case FRAG_CMD_PACKAGE_VERSION: // REQ
- if( nb_cmd_package_version == 0 )
- {
- if( ( frag_rx_buffer_index + FRAG_PACKAGE_VERSION_REQ_SIZE ) <= frag_buffer_len )
- {
- frag_req_status[frag_req_status_num++] = FRAG_CMD_PACKAGE_VERSION;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size (FRAG_CMD_PACKAGE_VERSION)\n" );
- }
- frag_rx_buffer_index += FRAG_PACKAGE_VERSION_REQ_SIZE;
- nb_cmd++;
- nb_cmd_package_version++;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: double CMD PACKET VERSION, aborting\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
- // if( ( frag_rx_buffer_index + FRAG_PACKAGE_VERSION_REQ_SIZE ) <= frag_buffer_len )
- // {
- // frag_req_status[frag_req_status_num++] = FRAG_CMD_PACKAGE_VERSION;
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size (FRAG_CMD_PACKAGE_VERSION)\n" );
- // }
- // frag_rx_buffer_index += FRAG_PACKAGE_VERSION_REQ_SIZE;
- break;
-
- case FRAG_CMD_FRAG_SESSION_STATUS: // REQ
- if( nb_cmd_frag_session_status == 0 )
- {
- if( ( frag_rx_buffer_index + FRAG_SESSION_STATUS_REQ_SIZE ) <= frag_buffer_len )
- {
- frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_STATUS;
- frag_decode_session_status_req( &frag_buffer[frag_rx_buffer_index + 1] );
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR(
- "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_STATUS)\n" );
- }
- frag_rx_buffer_index += FRAG_SESSION_STATUS_REQ_SIZE;
- nb_cmd++;
- nb_cmd_frag_session_status++;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: double CMD FRAG SESSION STATUS, aborting\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
- // if( ( frag_rx_buffer_index + FRAG_SESSION_STATUS_REQ_SIZE ) <= frag_buffer_len )
- // {
- // frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_STATUS;
- // frag_decode_session_status_req( &frag_buffer[frag_rx_buffer_index + 1] );
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_STATUS)\n"
- // );
- // }
- // frag_rx_buffer_index += FRAG_SESSION_STATUS_REQ_SIZE;
- break;
-
- case FRAG_CMD_FRAG_SESSION_SETUP: // REQ
-
- if( nb_cmd_frag_session_setup == 0 )
- {
- if( ( frag_rx_buffer_index + FRAG_SESSION_SETUP_REQ_SIZE ) <= frag_buffer_len )
- {
- frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_SETUP;
- frag_decode_session_setup_req( &frag_buffer[frag_rx_buffer_index + 1] );
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR(
- "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_SETUP)\n" );
- }
- frag_rx_buffer_index += FRAG_SESSION_SETUP_REQ_SIZE;
- nb_cmd++;
- nb_cmd_frag_session_setup++;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: double CMD FRAG SESSION SETUP, aborting\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- // if( ( frag_rx_buffer_index + FRAG_SESSION_SETUP_REQ_SIZE ) <= frag_buffer_len )
- // {
- // frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_SETUP;
- // frag_decode_session_setup_req( &frag_buffer[frag_rx_buffer_index + 1] );
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_SETUP)\n"
- // );
- // }
- // frag_rx_buffer_index += FRAG_SESSION_SETUP_REQ_SIZE;
- break;
-
- case FRAG_CMD_FRAG_SESSION_DELETE: // REQ
-
- if( nb_cmd_frag_session_delete == 0 )
- {
- if( ( frag_rx_buffer_index + FRAG_SESSION_DELETE_REQ_SIZE ) <= frag_buffer_len )
- {
- frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_DELETE;
- frag_decode_session_delete_req( &frag_buffer[frag_rx_buffer_index + 1] );
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR(
- "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_DELETE)\n" );
- }
- frag_rx_buffer_index += FRAG_SESSION_DELETE_REQ_SIZE;
- nb_cmd++;
- nb_cmd_frag_session_delete++;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: double CMD FRAG SESSION DELETE, aborting\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- // if( ( frag_rx_buffer_index + FRAG_SESSION_DELETE_REQ_SIZE ) <= frag_buffer_len )
- // {
- // frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_SESSION_DELETE;
- // frag_decode_session_delete_req( &frag_buffer[frag_rx_buffer_index + 1] );
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_SESSION_DELETE)\n"
- // );
- // }
- // frag_rx_buffer_index += FRAG_SESSION_DELETE_REQ_SIZE;
- break;
-
- case FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED: // ANS
-
- if( nb_cmd_frag_data_block_received == 0 )
- {
- if( ( frag_rx_buffer_index + FRAG_DATA_BLOCK_RECEIVED_ANS_SIZE ) <= frag_buffer_len )
- {
- frag_decode_data_block_received_ans( &frag_buffer[frag_rx_buffer_index + 1] );
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR(
- "Fragmented Data Block payload bad size (FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED)\n" );
- }
- frag_rx_buffer_index += FRAG_DATA_BLOCK_RECEIVED_ANS_SIZE;
- nb_cmd++;
- nb_cmd_frag_data_block_received++;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: double CMD FRAG DATA BLOCK RECEIVED, aborting\n" );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- // if( ( frag_rx_buffer_index + FRAG_DATA_BLOCK_RECEIVED_ANS_SIZE ) <= frag_buffer_len )
- // {
- // frag_decode_data_block_received_ans( &frag_buffer[frag_rx_buffer_index + 1] );
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_ERROR( "Fragmented Data Block payload bad size
- // (FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED)\n"
- // );
- // }
- // frag_rx_buffer_index += FRAG_DATA_BLOCK_RECEIVED_ANS_SIZE;
- break;
-
- case FRAG_CMD_FRAG_DATA_FRAGMENT: // CANNOT BE APPENDED WITH OTHER REQUEST MESSAGES
-
- if( ( frag_rx_buffer_index == 0 ) && ( frag_buffer_len == frag_session_setup_req.frag_size + 3 ) )
- {
- frag_process_data_fragment( &frag_buffer[frag_rx_buffer_index + 1], frag_buffer_len - 1 );
- if( ( is_data_block_reconstructed == true ) &&
- ( frag_session_setup_req.control.ack_reception == 0x01 ) && ( is_ack_reception_done == false ) )
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "Preparing BLOCK_RECEIVED\n" );
- // at this point we will verify the received file , ancm
- if( check_received_patch( ) > 0 )
- {
- SMTC_MODEM_HAL_TRACE_WARNING( "file is valid!!\n" );
- frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED;
- }
- else
- SMTC_MODEM_HAL_TRACE_WARNING( "file is not valid!!\n" );
- // create the uplink with data block received for das aknownledge
- frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED;
- }
- else
- {
- frag_req_status_num = 0;
- }
- frag_rx_buffer_index += frag_buffer_len;
- nb_cmd++;
- break;
- }
- else
- {
- SMTC_MODEM_HAL_TRACE_ERROR(
- "ERROR: wrong data frag command size or mix with other cmd, size = ((0x%x)), aborting\n",
- frag_buffer_len );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
- // frag_process_data_fragment( &frag_buffer[frag_rx_buffer_index + 1], frag_buffer_len - 1 );
- // if( ( is_data_block_reconstructed == true ) && ( frag_session_setup_req.control.ack_reception == 0x01 )
- // &&
- // ( is_ack_reception_done == false ) )
- // {
- // SMTC_MODEM_HAL_TRACE_WARNING( "Preparing BLOCK_RECEIVED\n" );
- // if( is_data_block_mic_success == true )
- // {
- // // at this point we will verify the received file , ancm
- // if( check_received_patch( ) > 0 )
- // {
- // // code never reach because jump to bootloader 2
- // SMTC_MODEM_HAL_TRACE_WARNING( "file is valid!!\n" );
- // }
- // else
- // {
- // SMTC_MODEM_HAL_TRACE_WARNING( "file is not valid!!\n" );
- // }
- // }
- // // create the uplink with data block received for das aknownledge
- // frag_req_status[frag_req_status_num++] = FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED;
- // }
- // else
- // {
- // frag_req_status_num = 0;
- // }
- // frag_rx_buffer_index += frag_buffer_len;
- // break;
-
- default:
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: wrong frag command (0x%x), aborting\n",
- frag_buffer[frag_rx_buffer_index] );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
- }
-
- // if the parsed index != equal to the frag buffer, the packet length is wrong
- if( frag_rx_buffer_index != frag_buffer_len )
- {
- frag_req_status_num = 0;
- SMTC_MODEM_HAL_TRACE_ERROR(
- "ERROR: the downlink length is not correct, parse fails, frag_rx_buffer_index= ((0x%x)), frag_buffer_len= "
- "((0x%x)), nb_cmd= ((0x%x)), aborting\n",
- frag_rx_buffer_index, frag_buffer_len, nb_cmd );
- return ( int8_t ) FRAG_CMD_ERROR;
- }
-
-#if MODEM_HAL_DBG_TRACE == MODEM_HAL_FEATURE_ON
- SMTC_MODEM_HAL_TRACE_ARRAY( "FRAG_REQ_STATUS", frag_req_status, frag_req_status_num );
-#endif
-
- return ( int8_t ) frag_req_status_num;
-}
-
-void frag_set_max_length_up_payload( uint8_t max_payload )
-{
- frag_max_length_up_payload = max_payload;
-}
-
-void frag_construct_uplink_payload( void )
-{
- int i;
-
- for( i = 0; i < frag_req_status_num; i++ )
- {
- switch( frag_req_status[i] )
- {
- case FRAG_CMD_PACKAGE_VERSION:
- frag_construct_package_version_answer( );
- break;
- case FRAG_CMD_FRAG_SESSION_STATUS:
- frag_construct_frag_session_status_answer( );
- break;
- case FRAG_CMD_FRAG_SESSION_SETUP:
- frag_construct_frag_session_setup_answer( );
- break;
- case FRAG_CMD_FRAG_SESSION_DELETE:
- frag_construct_frag_session_delete_answer( );
- break;
- case FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED:
- frag_construct_data_block_received_request( );
- break;
- default:
- SMTC_MODEM_HAL_TRACE_ERROR( "ERROR: wrong command in freq_req_status[], SHOULD NOT HAPPEN !!\n" );
- break;
- }
- }
-
- // All commands should be answered now. If some could not due to max payload length exceeded
- // it is truncated, and the server will need to reiterate the request which has not been answered.
- frag_req_status_num = 0;
-}
-
-void frag_construct_package_version_answer( void )
-{
- SMTC_MODEM_HAL_TRACE_INFO( "=> running %s\n", __FUNCTION__ );
-
- if( is_frag_tx_buffer_not_full( FRAG_PACKAGE_VERSION_ANS_SIZE ) == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "frag_tx_payload buffer is full, skip this request\n" );
- return;
- }
-
- frag_tx_payload[frag_tx_payload_index++] = FRAG_CMD_PACKAGE_VERSION;
- frag_tx_payload[frag_tx_payload_index++] = FRAG_PACKAGE_IDENTIFIER;
- frag_tx_payload[frag_tx_payload_index++] = FRAG_PACKAGE_VERSION;
-}
-
-void frag_construct_frag_session_status_answer( void )
-{
- uint8_t status = 0x00;
- uint16_t received_index = 0x00;
- uint8_t missing_frag = 0x00;
-
- SMTC_MODEM_HAL_TRACE_INFO( "=> running %s\n", __FUNCTION__ );
-
- if( is_frag_tx_buffer_not_full( FRAG_SESSION_STATUS_ANS_SIZE ) == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionStatus: frag_tx_payload buffer is full, skip this request\n" );
- return;
- }
-
- if( ( frag_session_status_req.frag_index > 0 ) || ( is_frag_session_exist == false ) )
- {
- // Session does not exist
- status = ( 1 << FRAG_SESSION_STATUS_NO_SESSION );
- }
- else // Session exists
- {
- // Do we have to answer this request ?
- if( ( frag_session_status_req.participants == 0 ) &&
- ( nb_frag_uncoded_received == frag_session_setup_req.nb_frag ) )
- {
- // The request targets only the receivers still missing fragments
- SMTC_MODEM_HAL_TRACE_ERROR( "Ignoring FragSessionStatusReq, all uncoded fragments have been received\n" );
- return;
- }
-
- // Set status field
- if( ( is_data_block_reconstructed == true ) && ( is_data_block_mic_success == false ) )
- {
- status |= ( 1 << FRAG_SESSION_STATUS_MIC_ERROR );
- }
- if( ( is_data_block_reconstructed == true ) && ( is_data_block_sign_success == false ) )
- {
- status |= ( 1 << FRAG_SESSION_STATUS_SIGN_ERROR );
- }
- if( ( is_data_block_reconstructed == true ) && ( is_data_block_crc_fw_success == false ) )
- {
- status |= ( 1 << FRAG_SESSION_STATUS_CRC_FW_ERROR );
- }
- if( is_defrag_memory_exceeded == true )
- {
- status |= ( 1 << FRAG_SESSION_STATUS_MEMORY_ERROR );
- }
-
- // Set Received&index field
- received_index =
- ( ( nb_frag_uncoded_received + nb_frag_coded_received ) & 0x3FFF ); // Only FragIndex 0 is supported
-
- // Set MissingFrag field
- if( is_data_block_reconstructed == false )
- {
- missing_frag = ( ( frag_session_setup_req.nb_frag - nb_frag_uncoded_received ) > 255 )
- ? 255
- : ( uint8_t )( frag_session_setup_req.nb_frag - nb_frag_uncoded_received );
- }
- else
- {
- missing_frag = 0;
- }
- }
-
- frag_tx_payload[frag_tx_payload_index++] = FRAG_CMD_FRAG_SESSION_STATUS;
- frag_tx_payload[frag_tx_payload_index++] = status;
-
- if( ( status & ( 1 << FRAG_SESSION_STATUS_NO_SESSION ) ) == 0 )
- {
- // A session exists, adding Received&Index and MissingFrag status information
- frag_tx_payload[frag_tx_payload_index++] = ( uint8_t )( ( received_index >> 0 ) & 0xFF );
- frag_tx_payload[frag_tx_payload_index++] = ( uint8_t )( ( received_index >> 8 ) & 0xFF );
- frag_tx_payload[frag_tx_payload_index++] = missing_frag;
- }
-}
-
-void frag_construct_frag_session_setup_answer( void )
-{
- int32_t rc; // FragDecoder return code
- uint8_t frag_session_setup_ans = 0x0;
-
- uint32_t tmp;
-
- SMTC_MODEM_HAL_TRACE_INFO( "=> running %s\n", __FUNCTION__ );
-
- if( is_frag_tx_buffer_not_full( FRAG_SESSION_SETUP_ANS_SIZE ) == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: frag_tx_payload buffer is full, skip this request\n" );
- return;
- }
-
- // Set the FragIndex bits for the answer
- frag_session_setup_ans = ( frag_session_setup_req.frag_session.frag_index << 6 ) & 0xC0;
-
- //
- // Section 1: check if the session setup request is valid (do not update context in this section)
- //
-
- // Check if FragIndex for next session is valid (MUST be 0)
- if( frag_session_setup_req.frag_session.frag_index != 0 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: FragIndex unsupported\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_INDEX_UNSUPPORTED );
- }
- // frag_session_setup_req.frag_session.mc_group_bit_mask is ignored, only unicast supported
-
- // Check NbFrag range (2^14 - 1)
- if( frag_session_setup_req.nb_frag > 16383 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: NbFrag invalid\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_NO_MEMORY );
- }
-
- // Check if there is enough memory to store all the fragments (data_block_size = NbFrag * FragSize - Padding)
- tmp = frag_session_setup_req.nb_frag * frag_session_setup_req.frag_size;
- if( tmp - frag_session_setup_req.padding > FRAG_DATA_BLOCK_SIZE_MAX )
- // if( frag_session_setup_req.nb_frag * frag_session_setup_req.frag_size - frag_session_setup_req.padding >
- // FRAG_DATA_BLOCK_SIZE_MAX )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: Not enough memory\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_NO_MEMORY );
- }
-
- if( frag_session_setup_req.control.frag_algo != 0 )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: FragAlgo unsupported\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_ALGO_UNSUPPORTED );
- }
- // Parse the descriptor
- e_descriptor_error_t descriptor_status = frag_session_parse_descriptor( frag_session_setup_req.descriptor );
- if( descriptor_status == DESCRIPTOR_ERROR )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: descriptor unsupported\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_WRONG_DESCRIPTOR );
- }
-
- // Check frag session counter
- if( session_cnt_prev >= ( int32_t )( frag_session_setup_req.session_cnt ) )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionSetup: SessionCnt replay\n" );
- frag_session_setup_ans |= ( 1 << FRAG_SESSION_SETUP_SESSIONCNT_REPLAY );
- }
-
- // MIC: nothing to do with it for now
-
- //
- // Section 2: If the session is valid, set the frag context
- //
-
- // If session setup request is valid
- if( TAKE_N_BITS_FROM( frag_session_setup_ans, 0, 5 ) == 0 ) // no error bit set
- {
- if( is_frag_session_exist == true )
- {
- // If there is already an existing session, abort the current one, reset context
- SMTC_MODEM_HAL_TRACE_ERROR( "TODO: Current fragmentation session SHALL BE reset\n" );
- frag_context_reset( );
- // ... ?
- }
- else
- {
- is_frag_session_exist = true;
- }
-
- // Set the frag session context variables
- // BlockAckDelay is ignored, not used for Unicast
- // Store the new Session Cnt
- session_cnt_prev = frag_session_setup_req.session_cnt;
-
- // Initialize underlying frag_decoder
-
- rc = FragDecoderInit( frag_session_setup_req.nb_frag, frag_session_setup_req.frag_size,
- &frag_decoder_callbacks );
- switch( rc )
- {
- case FRAG_SESSION_ERROR:
- frag_session_setup_ans |= ( 1 << 1 ); // Not enough memory (bit 1)
- break;
- case FRAG_SESSION_BADSIZE:
- frag_session_setup_ans |= ( 1 << 1 ); // Not enough memory (bit 1)
- break;
- }
- }
-
- frag_session_print( );
-
- frag_tx_payload[frag_tx_payload_index++] = FRAG_CMD_FRAG_SESSION_SETUP;
- frag_tx_payload[frag_tx_payload_index++] = frag_session_setup_ans;
-}
-
-void frag_construct_frag_session_delete_answer( void )
-{
- uint8_t frag_session_delete_ans = 0x0;
-
- SMTC_MODEM_HAL_TRACE_INFO( "=> running %s\n", __FUNCTION__ );
-
- if( is_frag_tx_buffer_not_full( FRAG_SESSION_DELETE_ANS_SIZE ) == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionDelete: frag_tx_payload buffer is full, skip this request\n" );
- return;
- }
-
- // Set FragIndex
- frag_session_delete_ans |= frag_session_delete_req;
-
- // Set error if any
- if( ( frag_session_delete_req != 0 ) || ( is_frag_session_exist == false ) )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "FragSessionDelete: Session does not exist\n" );
- frag_session_delete_ans |= ( 1 << FRAG_SESSION_DELETE_NO_SESSION );
- }
- else
- {
- // Actually delete the session
- is_frag_session_exist = false;
-
- // Reset session context
- frag_context_reset( );
- }
-
- frag_session_print( );
-
- frag_tx_payload[frag_tx_payload_index++] = FRAG_CMD_FRAG_SESSION_DELETE;
- frag_tx_payload[frag_tx_payload_index++] = frag_session_delete_ans;
-}
-
-void frag_construct_data_block_received_request( void )
-{
- uint8_t status = 0x00; // Only FragIndex == 0 supported
-
- SMTC_MODEM_HAL_TRACE_INFO( "=> running %s\n", __FUNCTION__ );
-
- if( is_frag_tx_buffer_not_full( FRAG_DATA_BLOCK_RECEIVED_REQ_SIZE ) == false )
- {
- SMTC_MODEM_HAL_TRACE_ERROR( "ReceivedDataBlock: frag_tx_payload buffer is full, skip this request\n" );
- return;
- }
-
- if( is_data_block_mic_success == false )
- {
- status |= ( 1 << FRAG_RECEIVED_DATA_BLOCK_MIC_ERROR );
- }
- if( is_data_block_sign_success == false )
- {
- status |= ( 1 << FRAG_RECEIVED_DATA_BLOC_SIGN_ERROR );
- }
- if( is_data_block_crc_fw_success == false )
- {
- status |= ( 1 << FRAG_RECEIVED_DATA_BLOC_CRC_FW_ERROR );
- }
-
- frag_tx_payload[frag_tx_payload_index++] = FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED;
- frag_tx_payload[frag_tx_payload_index++] = status;
-}
-
-e_frag_error_t frag_get_tx_buffer( uint8_t* tx_buffer_out, uint8_t* tx_buffer_length_out )
-{
- if( tx_buffer_length_out == NULL )
- {
- return FRAG_INVALID;
- }
- if( tx_buffer_out == NULL )
- {
- *tx_buffer_length_out = 0;
- return FRAG_INVALID;
- }
- if( *tx_buffer_length_out < frag_tx_payload_index )
- {
- *tx_buffer_length_out = 0;
- return FRAG_BADSIZE;
- }
-
- memcpy( tx_buffer_out, frag_tx_payload, frag_tx_payload_index );
- *tx_buffer_length_out = frag_tx_payload_index;
- frag_tx_payload_index = 0; // Reset tx index after data reached
- frag_max_length_up_payload = FRAG_UPLINK_LENGTH_MAX; // Reinit the max length authorized
- return FRAG_OK;
-}
-
-bool frag_uplink_pending( void )
-{
- return frag_tx_payload_index > 0;
-}
-
-static e_file_error_t check_received_patch( void )
-{
- uint8_t sign_ok = 0;
- DELTA_PARTITION_HEADER* delta_header = ( DELTA_PARTITION_HEADER* ) UPDT_FIRM_HEADER;
- uint32_t magicword = delta_header->upd_fw_crc;
- // uint32_t delta_size = delta_header->upd_size;
- if( magicword == 0x35CA139A )
- {
- sign_ok = VerifySignature( );
- DEBUG_PRINT( DBG_INFO, "VerifySignature %d\n", sign_ok );
- }
- else
- {
- sign_ok = CheckAesHash( );
- }
- is_data_block_sign_success = ( sign_ok == 1 ) ? true : false;
- if( compute_crc_fw( ) == delta_header->ref_crc_descriptor )
- {
- is_data_block_crc_fw_success = true;
- DEBUG_PRINT( DBG_INFO, "verified crc_fw ok\n" );
- }
- else
- {
- is_data_block_crc_fw_success = false;
- DEBUG_PRINT( DBG_INFO, "verified crc_fw fail\n" );
- }
- DEBUG_PRINT( DBG_INFO, "verified = %d\n", sign_ok );
-
- if( ( sign_ok == 1 ) && ( is_data_block_crc_fw_success == true ) )
- {
- DEBUG_PRINT( DBG_INFO, "Format EE\n" );
- xEEformat( );
-
- DEBUG_PRINT( DBG_INFO, "Reset to BL2\n" );
- // perform a reboot to bootloader2
- // Before reboot, need to go to standbyRC mode
- SetStandbyRc( );
-
- P_PMU->scratch1.reg32 &= ~( ( uint32_t )( STAY_IN_BOOT_MSK | STAY_IN_BOOT2_MSK ) );
- P_PMU->scratch1.reg32 |= STAY_IN_BOOT2_MSK;
- // To be sure everything is correctly rebooted, use system reset for bootloader reset
- // But first reset GPIO for correct busy and GPIO restart.
- InitGPIO( );
-
- // CER-561 avoid eol poping in bootloader, where pmu irq handler is not implemented
- // smtc_modem_hal_reset_mcu( );
- memset( ( uint8_t* ) 0x00800000, 0, 16384 ); // Clear the Retention RAM
-
- P_PMU->interruptMask.reg32 = 0;
- P_CCU->rstCtrl.fields.sysRst = 1;
- return FILE_OK;
- }
- else
- {
- DEBUG_PRINT( DBG_INFO, "No valid Update found!!\n" );
- smtc_modem_hal_mcu_panic( );
- return FILE_INVALID;
- }
-}
-
-uint16_t frag_get_nb_frag_received( void )
-{
- return nb_frag_uncoded_received + nb_frag_coded_received;
-}
-uint16_t frag_get_nb_frag( void )
-{
- return frag_session_setup_req.nb_frag;
-}
-uint16_t frag_get_session_counter( void )
-{
- return ( ( session_cnt_prev == -1 ) ? 0xFFFF : ( uint16_t )( session_cnt_prev & 0xFFFF ) );
-}
-
-// uint32_t frag_get_data_buffer( uint8_t** data )
-// {
-// if( data == NULL )
-// {
-// return 0;
-// }
-// *data = frag_data_buffer;
-// return frag_session_setup_req.frag_size * frag_session_setup_req.nb_frag;
-// }
-
-/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.h
deleted file mode 100644
index ab495b4..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/fragmented_data_block.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/*!
- * \file fragmented_data_block.h
- *
- * \brief LoRaWAN Fragmented Data Block Transport protocol
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __FRAGMENTED_DATA_BLOCK_H__
-#define __FRAGMENTED_DATA_BLOCK_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-
-#include // C99 types
-
-/*
- * -----------------------------------------------------------------------------
- * --- PRIVATE MACROS-----------------------------------------------------------
- */
-
-#define FRAG_PACKAGE_IDENTIFIER ( 3 )
-#define FRAG_PACKAGE_VERSION ( 2 )
-
-#define FRAG_DOWNLINK_HEADER_LENGTH ( 1 )
-
-// Answer message sizes (with header)
-#define FRAG_PACKAGE_VERSION_ANS_SIZE ( 3 )
-#define FRAG_SESSION_STATUS_ANS_SIZE ( 5 )
-#define FRAG_SESSION_SETUP_ANS_SIZE ( 2 )
-#define FRAG_SESSION_DELETE_ANS_SIZE ( 2 )
-#define FRAG_DATA_BLOCK_RECEIVED_ANS_SIZE ( 2 )
-
-// Request message sizes (with header)
-#define FRAG_PACKAGE_VERSION_REQ_SIZE ( 1 )
-#define FRAG_SESSION_STATUS_REQ_SIZE ( 2 )
-#define FRAG_SESSION_SETUP_REQ_SIZE ( 17 )
-#define FRAG_SESSION_DELETE_REQ_SIZE ( 2 )
-#define FRAG_DATA_BLOCK_RECEIVED_REQ_SIZE ( 2 )
-
-// An uplink may contain several commands (5 max). The maximum uplink length is as follows:
-// - PackageVersionAns : 2 bytes + cmd
-// - FragSessionStatusAns : 4 bytes + cmd
-// - FragSessionSetupAns : 1 byte + cmd
-// - FragSessionDeleteAns : 1 byte + cmd
-// - FragDataBlockReceivedReq : 1 byte + cmd
-#define FRAG_UPLINK_LENGTH_MAX \
- ( FRAG_PACKAGE_VERSION_ANS_SIZE + FRAG_SESSION_STATUS_ANS_SIZE + FRAG_SESSION_SETUP_ANS_SIZE + \
- FRAG_SESSION_DELETE_ANS_SIZE + FRAG_DATA_BLOCK_RECEIVED_REQ_SIZE )
-
-#define FRAG_UPLINK_REQ_MAX ( 5 ) // Maximum 5 requests per message (same request cannot be repeated)
-
-// Bits of frag session status
-#define FRAG_SESSION_STATUS_MEMORY_ERROR 0
-#define FRAG_SESSION_STATUS_MIC_ERROR 1
-#define FRAG_SESSION_STATUS_NO_SESSION 2
-#define FRAG_SESSION_STATUS_SIGN_ERROR 6
-#define FRAG_SESSION_STATUS_CRC_FW_ERROR 7
-
-// Bits of frag session setup answer
-#define FRAG_SESSION_SETUP_ALGO_UNSUPPORTED 0
-#define FRAG_SESSION_SETUP_NO_MEMORY 1
-#define FRAG_SESSION_SETUP_INDEX_UNSUPPORTED 2
-#define FRAG_SESSION_SETUP_WRONG_DESCRIPTOR 3
-#define FRAG_SESSION_SETUP_SESSIONCNT_REPLAY 4
-
-// Bits of frag session delete answer
-#define FRAG_SESSION_DELETE_NO_SESSION 2
-
-// Bits of data block received request
-#define FRAG_RECEIVED_DATA_BLOCK_MIC_ERROR 2
-#define FRAG_RECEIVED_DATA_BLOC_SIGN_ERROR 6
-#define FRAG_RECEIVED_DATA_BLOC_CRC_FW_ERROR 7
-
-#define FRAG_DATA_BLOCK_SIZE_MAX ( 30 * 1024 ) // Target 30KB: TODO refine actual space available for defrag
-#define FLASH_BASE ( uint32_t ) 0x80000
-#define FLASH_DELTA_UPDATE ( uint32_t ) 0xB6800
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC TYPES ------------------------------------------------------------
- */
-
-typedef enum frag_cmd_length_valid
-{
- FRAG_CMD_LENGTH_VALID, //!< The length of the command is valid
- FRAG_CMD_LENGTH_NOT_VALID, //!< The length of the command is not valid
- FRAG_CMD_NOT_VALID, //!< The command is not valid
-} e_frag_cmd_length_valid;
-
-typedef enum frag_error
-{
- FRAG_BADSIZE = -2,
- FRAG_INVALID = -1,
- FRAG_ERROR = 0,
- FRAG_OK
-} e_frag_error_t;
-
-typedef enum file_error
-{
- FILE_BADSIZE = -2,
- FILE_INVALID = -1,
- FILE_ERROR = 0,
- FILE_OK
-} e_file_error_t;
-
-typedef enum frag_cmd
-{
- FRAG_CMD_PACKAGE_VERSION = 0x00,
- FRAG_CMD_FRAG_SESSION_STATUS = 0x01,
- FRAG_CMD_FRAG_SESSION_SETUP = 0x02,
- FRAG_CMD_FRAG_SESSION_DELETE = 0x03,
- FRAG_CMD_FRAG_DATA_BLOCK_RECEIVED = 0x04,
- FRAG_CMD_FRAG_DATA_FRAGMENT = 0x08,
- FRAG_CMD_MAX, //!< Number of elements
- FRAG_CMD_ERROR = 0x80, //!< Used when the command is unknown
-} e_frag_cmd_t;
-
-typedef struct frag_cmd_input
-{
- e_frag_cmd_t cmd_name; //!< command name
- uint8_t* buffer; //!< command data
- uint8_t buffer_len; //!< command data length in byte(s)
-} s_frag_cmd_input_t;
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
- */
-
-void frag_init( void );
-
-int8_t frag_parser( uint8_t* frag_buffer, uint8_t frag_buffer_len );
-
-void frag_construct_package_version_answer( void );
-void frag_construct_frag_session_status_answer( void );
-void frag_construct_frag_session_setup_answer( void );
-void frag_construct_frag_session_delete_answer( void );
-void frag_construct_data_block_received_request( void );
-
-void frag_construct_uplink_payload( void );
-
-e_frag_error_t frag_get_tx_buffer( uint8_t* tx_buffer_out, uint8_t* tx_buffer_length_out );
-void frag_set_max_length_up_payload( uint8_t max_payload );
-bool frag_uplink_pending( void );
-// uint32_t frag_get_data_buffer( uint8_t** data );
-uint16_t frag_get_nb_frag_received( void );
-uint16_t frag_get_nb_frag( void );
-uint16_t frag_get_session_counter( void );
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __FRAGMENTED_DATA_BLOCK_H__
-
-/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.c
deleted file mode 100644
index 85db221..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/**
- * @file patch_upd.c
- *
- * @brief Patch update sources
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include // C99 types
-#include // bool type
-#include
-#include "patch_upd.h"
-#include "core.h"
-#include "crypto.h"
-#include "nvmcu_hal.h"
-// #include "debug.h"
-
-static const uint8_t PubKey[40] = { 0x7b, 0x5e, 0x8f, 0x4f, 0x5b, 0xdc, 0xc2, 0xc8, 0x7a, 0x5d, 0x85, 0xce, 0xc7, 0x91,
- 0x5d, 0xa9, 0x9d, 0xe6, 0x7b, 0xf2, 0x6b, 0x1e, 0x50, 0x3b, 0x0f, 0x2e, 0x07, 0x9f,
- 0xb2, 0xd8, 0x53, 0x3e, 0xc0, 0x7c, 0x79, 0xa2, 0x82, 0x7e, 0x59, 0x13 };
-
-static const uint32_t RomBootFuncAddr_200f[] = { ROM_0F_FLASH_ECC_SECP160R1_ADDR, ROM_0F_ECC_VERIFY_ADDR };
-
-static const uint32_t RomBootFuncAddr_2010[] = { ROM_10_FLASH_ECC_SECP160R1_ADDR, ROM_10_ECC_VERIFY_ADDR };
-
-static uint32_t GetPage( uint32_t Addr )
-{
- uint32_t page = 0;
-
- page = ( Addr - FLASH_BASE ) / FLASH_PAGE_SIZE;
- return page;
-}
-int8_t xEEformat( void )
-{
- uint8_t values[4];
- uint8_t sign[16];
- uint32_t target_address = EEPROM_SIM_BASE;
- uint32_t page_addr = EEPROM_SIM_BASE;
-
- uint32_t page_idx = GetPage( page_addr );
- if( FlashErasePage( page_idx, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_INFO, "Erase page %d error\n", page_addr );
- return _ERR;
- }
-
- memcpy( sign, XTERNAL_EE_SIGNATURE, 16 );
- // for(i=0; i<16; i++){
- // DEBUG_PRINT(DBG_INFO, "sign_ee[%d]:%x\n",i,sign[i]);
- // }
-
- target_address = ( target_address - FLASH_BASE );
- if( FlashWrite( target_address >> 2, ( _Unaligned uint32_t* ) &sign[0], 16 / 4, 0, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_FATAL, "EEflash temp write error:%x\n", target_address );
- return _ERR;
- }
-
- values[0] = 1;
- values[1] = 0;
- values[2] = 0;
- values[3] = 0;
- target_address = EEPROM_NEW_DELTA;
- target_address = ( target_address - FLASH_BASE );
- if( FlashWrite( target_address >> 2, ( _Unaligned uint32_t* ) &values[0], 4 / 4, 0, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_FATAL, "EE_flash temp write error:%x\n", target_address );
- return _ERR;
- }
- return _OK;
-}
-
-int8_t xEEcheck( void )
-{
- uint8_t sign[16];
- memset( sign, 0, 16 );
- uint8_t i;
- _Unaligned uint32_t* memAdrPtr;
- uint32_t dataLen;
- uint8_t* mem8AdrPtr;
- _Unaligned uint16_t* mem16AdrPtr;
-
- memAdrPtr = ( uint32_t* ) EEPROM_SIM_BASE;
- dataLen = 16; // size of eeprom sign
- mem16AdrPtr = ( uint16_t* ) memAdrPtr;
- for( i = 0; i < ( dataLen / 2 ); i++ )
- {
- *( uint16_t* ) &sign[i * 2] = *mem16AdrPtr++;
- }
- if( ( i * 2 ) < dataLen )
- {
- mem8AdrPtr = ( uint8_t* ) mem16AdrPtr;
- sign[i * 2] = *mem8AdrPtr;
- }
- if( memcmp( XTERNAL_EE_SIGNATURE, sign, 16 ) != 0 )
- {
- return _ERR;
- }
- DEBUG_PRINT( DBG_INFO, "SIM EEPROM is OK\n" ); // delta test
- return _OK;
-}
-
-int8_t EE_setDeltaUpdateInfo( uint32_t value )
-{
- uint8_t info[4];
- uint16_t i;
- uint32_t target_address;
- uint8_t temp[20];
- _Unaligned uint32_t* memAdrPtr;
- uint32_t dataLen;
- uint8_t* mem8AdrPtr;
- _Unaligned uint16_t* mem16AdrPtr;
-
- memAdrPtr = ( uint32_t* ) EEPROM_SIM_BASE;
- dataLen = 20;
- mem16AdrPtr = ( uint16_t* ) memAdrPtr;
- for( i = 0; i < ( dataLen / 2 ); i++ )
- {
- *( uint16_t* ) &temp[i * 2] = *mem16AdrPtr++;
- }
- if( ( i * 2 ) < dataLen )
- {
- mem8AdrPtr = ( uint8_t* ) mem16AdrPtr;
- temp[i * 2] = *mem8AdrPtr;
- }
- info[0] = ( uint8_t ) value;
- info[1] = ( uint8_t )( ( value & 0x0000FF00 ) >> 8 );
- info[2] = ( uint8_t )( ( value & 0x00FF0000 ) >> 16 );
- info[3] = ( uint8_t )( ( value & 0xFF000000 ) >> 24 );
- for( i = 0; i < 4; i++ )
- {
- DEBUG_PRINT( DBG_INFO, "setInfo[%d]:%x\n", i, info[i] );
- temp[i + 16] = info[i];
- }
- target_address = EEPROM_SIM_BASE;
- uint32_t page_idx = GetPage( target_address );
-
- DEBUG_PRINT( DBG_INFO, "Erase page %d \n", page_idx ); // delta test
- if( FlashErasePage( page_idx, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_FATAL, "Erase page %d error\n", page_idx );
- return _ERR;
- }
- DEBUG_PRINT( DBG_INFO, "EE_flash temp write:%x\n", target_address ); // delta test
- target_address = ( target_address - FLASH_BASE );
- if( FlashWrite( target_address >> 2, ( _Unaligned uint32_t* ) &temp[0], 2048 / 4, 0, MainFlash ) != 1 )
- {
- DEBUG_PRINT( DBG_FATAL, "EE_flash temp write error:%x\n", target_address );
- return _ERR;
- }
-
- return 0;
-}
-
-uint32_t CalcFwAes128CheckSum( )
-{
- // uint32_t* flash;
- uint32_t flashStartAddr;
- uint32_t len;
- uint32_t mic;
-
- DEBUG_PRINT( DBG_INFO, "Calc CMAC...\n" );
-
- EnableCrypto( );
-
- if( CryptoWriteKey32( CRYPTO_AppSKey_IDX, ( uint32_t[] ){ 0, 0, 0, 0 } ) != 0 )
- {
- DEBUG_PRINT( DBG_ERROR, "CryptoWriteKey failed\n" );
- DisableCrypto( );
- return 0;
- }
-
- flashStartAddr = ( uint32_t ) UPDT_FIRM_HEADER;
- DELTA_PARTITION_HEADER* delta_header = ( DELTA_PARTITION_HEADER* ) UPDT_FIRM_HEADER;
- len = delta_header->upd_crc;
- len = len >> 2;
- // DEBUG_PRINT(DBG_INFO, "data: %x\n",*flash++ );
- // flash = (uint32_t*)flashStartAddr; // for test
- // len = *flash;
- // DEBUG_PRINT(DBG_INFO, "flash:%x,Len: 0x%x\n", *flash++,len);
- // DEBUG_PRINT(DBG_INFO, "Len: 0x%x\n", len);
- if( len > DELTA_WORD_SIZE )
- {
- DEBUG_PRINT( DBG_ERROR, "Reading length of flash failed\n" );
- DisableCrypto( );
- return 0;
- }
- if( CryptoMic32( ( uint32_t* ) flashStartAddr, len / 4, CRYPTO_AppSKey_IDX, 1, &mic, 0 ) != 0 )
- {
- DEBUG_PRINT( DBG_ERROR, "CryptoComputeMic failed\n" );
- DisableCrypto( );
- return 0;
- }
-
- DisableCrypto( );
- return len;
-}
-
-uint8_t CheckAesHash( )
-{
- uint8_t verified = 1;
-
- uint32_t* flash;
- uint32_t flashStartAddr;
- uint32_t len;
-
- DEBUG_PRINT( DBG_INFO, "Check Aes hash\n" ); // for delta test
- flashStartAddr = ( uint32_t ) UPDT_FIRM_HEADER;
- len = CalcFwAes128CheckSum( );
- if( len == 0 )
- {
- return 0;
- }
- flash = ( uint32_t* ) flashStartAddr + len;
- // check all 128bits in register aes data_out
- if( ( P_CRYPTO->dataBufferOut0.reg32 != *flash++ ) || ( P_CRYPTO->dataBufferOut1.reg32 != *flash++ ) ||
- ( P_CRYPTO->dataBufferOut2.reg32 != *flash++ ) || ( P_CRYPTO->dataBufferOut3.reg32 != *flash ) )
- {
- DEBUG_PRINT( DBG_ERROR, "CryptoComputeMic on flash failed\n" );
- verified = 0;
- }
- return verified;
-}
-
-uint8_t VerifySignature( )
-{
- // signature algorithm:
- // 1) Calculate e = HASH ( m ), where HASH is a cryptographic hash function (AES-128 in our case with key=000000)
- // 2) calculate the signature of the hash e with the private key with ECDSA
- // 3) store signature in the flash after the fw
-
- // verify agorithm :
- // 1) Calculate e = HASH ( m ), where HASH is a cryptographic hash function (AES-128 in our case with key=000000)
- // 2) Check the stored signature with the public key
-
- // not whole flash: only between 0 and stop addr in flash + stop addr (just after irq vectors in flash)
- // 2) encrypted hash is stored just after stop addr (aes hash )
- // encrypt the flash hash with ecc asymetric algo the hash (paded with zeros if needed) with the public key
- // stored in the rom.
- // 3) encrypted hash from the flash == with the calculated one
-
- // DEBUG_PRINT(DBG_INFO, "verify sign\n");
- uint32_t* flash;
- uint32_t flashStartAddr;
- uint32_t len;
- uint32_t* versionAddr;
- // int ver_res;
- DEBUG_PRINT( DBG_INFO, "Check Signature\n" ); // for delta test
- flashStartAddr = ( uint32_t ) UPDT_FIRM_HEADER;
- len = CalcFwAes128CheckSum( );
- if( len == 0 )
- {
- return 0;
- }
-
- uint8_t hash[16];
- _Unaligned uint32_t* ptr = ( uint32_t* ) &hash[0];
- *ptr++ = Swap32( P_CRYPTO->dataBufferOut0.reg32 );
- *ptr++ = Swap32( P_CRYPTO->dataBufferOut1.reg32 );
- *ptr++ = Swap32( P_CRYPTO->dataBufferOut2.reg32 );
- *ptr = Swap32( P_CRYPTO->dataBufferOut3.reg32 );
-
- flash = ( uint32_t* ) flashStartAddr + len;
- versionAddr = ( uint32_t* ) 0x00007FCC;
- RomuECC_secp160r1* f;
- RomuECC_verify* verify_f;
-
- if( Swap32( *versionAddr ) == 0x2010ffff )
- {
- DEBUG_PRINT( DBG_INFO, "2010 version:%x\n", Swap32( *versionAddr ) );
- f = ( RomuECC_secp160r1* ) RomBootFuncAddr_2010[ROM_FLASH_ECC_SECP160R1_IDX];
- verify_f = ( RomuECC_verify* ) RomBootFuncAddr_2010[ROM_ECC_VERIFY_IDX];
- }
- else
- {
- DEBUG_PRINT( DBG_INFO, "200f version:%x\n", Swap32( *versionAddr ) );
- f = ( RomuECC_secp160r1* ) RomBootFuncAddr_200f[ROM_FLASH_ECC_SECP160R1_IDX];
- verify_f = ( RomuECC_verify* ) RomBootFuncAddr_200f[ROM_ECC_VERIFY_IDX];
- }
- //#ifdef USE_secp160r1
- uECC_Curve res;
- // RomuECC_secp160r1* f = (RomuECC_secp160r1*)0x00003c1c;
- res = f( );
- // RomuECC_verify* verify_f =(RomuECC_verify*)0x00003c24;
- return verify_f( PubKey, hash, 16, ( uint8_t* ) flash, res );
- // #endif
-
- // return 0;
-}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.h
deleted file mode 100644
index 2537d20..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/fragmentation/patch_upd.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * @file patch_upd.h
- *
- * @brief Patch update api
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef PATCH_UPD
-#define PATCH_UPD
-
-#include
-#include "..\cervin_trx_fw\src\applications\bootloader\src\bootloader.h"
-#include "..\cervin_trx_fw\src\applications\bootloader\src\ecc.h"
-
-#define ROM_FLASH_ECC_SECP160R1_IDX 0
-#define ROM_ECC_VERIFY_IDX 1
-// 200f
-// #define ROM_0F_10_FLASH_WRITE_ADDR 0x00000930
-// #define ROM_0F_10_FLASH_PAGE_ERASE_ADDR 0x000007d4
-#define ROM_0F_FLASH_ECC_SECP160R1_ADDR 0x00003b4c
-#define ROM_0F_ECC_VERIFY_ADDR 0x00003b54
-
-// 2010
-#define ROM_10_FLASH_ECC_SECP160R1_ADDR 0x00003c1c
-#define ROM_10_ECC_VERIFY_ADDR 0x00003c24
-
-#define FLASH_BASE ( uint32_t ) 0x80000 // start of main app
-#define FLASH_PAGE_SIZE ( ( uint32_t ) 0x800 )
-// -- eeprom simulate memory map --
-#define XTERNAL_EE_SIGNATURE "[SEMTECH_SX126L]"
-#define EEPROM_SIM_BASE ( uint32_t ) 0xBE000
-#define EEPROM_NEW_DELTA ( uint32_t ) 0xBE010
-#define _OK 0
-#define _ERR 1
-
-#define PACKED __attribute__( ( packed ) )
-#define DELTA_WORD_SIZE 0x00007800 // 30Kb
-#define UPDT_FIRM_HEADER ( uint32_t ) 0xB6800
-
-typedef struct delta_partition_header
-{
- uint32_t upd_crc; // the crc of the actual update binary
- uint32_t upd_size; // the size of actual update binary
- uint32_t upd_fw_crc;
- uint32_t upd_fw_size;
- uint32_t ref_crc_descriptor;
- uint8_t type;
- uint8_t rfu1;
- uint8_t rfu2;
- uint8_t rfu3;
-} PACKED DELTA_PARTITION_HEADER;
-
-typedef uECC_Curve RomuECC_secp160r1( void );
-typedef int RomuECC_verify( const uint8_t* public_key, const uint8_t* message_hash, unsigned hash_size,
- const uint8_t* signature, uECC_Curve curve );
-
-extern uint8_t CheckAesHash( );
-extern uint8_t VerifySignature( );
-extern int8_t xEEcheck( void );
-extern int8_t xEEformat( void );
-extern int8_t EE_setDeltaUpdateInfo( uint32_t value );
-
-#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.c
index f2dbb5c..3ea0b3f 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.c
@@ -1,61 +1,61 @@
-/*!
- * \file modem_utilities.c
- *
- * \brief utilities for modem
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "modem_utilities.h"
-
-uint32_t crc( const uint8_t* buf, int len )
-{
- uint32_t crc = 0xFFFFFFFF;
- while( len-- > 0 )
- {
- crc = crc ^ *buf++;
- for( int i = 0; i < 8; i++ )
- {
- uint32_t mask = -( crc & 1 );
- crc = ( crc >> 1 ) ^ ( 0xEDB88320 & mask );
- }
- }
- return ~crc;
-}
-uint32_t compute_crc_fw( void )
-{
-#if defined( LR1110_MODEM_E )
- uint32_t crctmp =
- crc( ( uint8_t* ) ( START_FLASH_ADRESS ),
- ( *( uint32_t* ) FLASH_PROG_LEN ) * 4 ); // prog length in word is store in start_fw_flash_address
- return crctmp;
-#else
- return 0;
-#endif // LR1110_MODEM_E
+/*!
+ * \file modem_utilities.c
+ *
+ * \brief utilities for modem
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2021. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "modem_utilities.h"
+
+uint32_t crc( const uint8_t* buf, int len )
+{
+ uint32_t crc = 0xFFFFFFFF;
+ while( len-- > 0 )
+ {
+ crc = crc ^ *buf++;
+ for( int i = 0; i < 8; i++ )
+ {
+ uint32_t mask = -( crc & 1 );
+ crc = ( crc >> 1 ) ^ ( 0xEDB88320 & mask );
+ }
+ }
+ return ~crc;
+}
+uint32_t compute_crc_fw( void )
+{
+#if defined( LR1110_MODEM_E )
+ uint32_t crctmp =
+ crc( ( uint8_t* ) ( START_FLASH_ADRESS ),
+ ( *( uint32_t* ) FLASH_PROG_LEN ) * 4 ); // prog length in word is store in start_fw_flash_address
+ return crctmp;
+#else
+ return 0;
+#endif // LR1110_MODEM_E
}
\ No newline at end of file
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.h
index 10c3f2c..461500b 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/modem_utilities.h
@@ -1,78 +1,78 @@
-/*!
- * \file modem_utilities.h
- *
- * \brief utilities for modem
- *
- * The Clear BSD License
- * Copyright Semtech Corporation 2021. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted (subject to the limitations in the disclaimer
- * below) provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
- * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
- * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __MODEM_UTILITIES_H__
-#define __MODEM_UTILITIES_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-#include // C99 types
-#include // bool type
-
-#include "lr1mac_defs.h"
-
-#if defined( LR1110_MODEM_E )
-#define START_FLASH_ADRESS ( uint32_t )( BASE_ADDR )
-#define FLASH_PROG_LEN ( uint32_t )( BASE_ADDR + 0xF4 ) // Address where is located the prog len
-#endif // LR1110_MODEM_E
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
- */
-
-/*!
- * \brief Compute crc
- * \remark
- *
- * \param [in] buf* - input buffer
- * \param [in] len* - input buffer length
- * \retval [out] crc - computed crc
- */
-uint32_t crc( const uint8_t* buf, int len );
-uint8_t crc8( const uint8_t* data, int length );
-uint32_t compute_crc_fw( void );
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __MODEM_UTILITIES_H__
-
-/* --- EOF ------------------------------------------------------------------ */
+/*!
+ * \file modem_utilities.h
+ *
+ * \brief utilities for modem
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2021. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEM_UTILITIES_H__
+#define __MODEM_UTILITIES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+#include // C99 types
+#include // bool type
+
+#include "lr1mac_defs.h"
+
+#if defined( LR1110_MODEM_E )
+#define START_FLASH_ADRESS ( uint32_t )( BASE_ADDR )
+#define FLASH_PROG_LEN ( uint32_t )( BASE_ADDR + 0xF4 ) // Address where is located the prog len
+#endif // LR1110_MODEM_E
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
+ */
+
+/*!
+ * \brief Compute crc
+ * \remark
+ *
+ * \param [in] buf* - input buffer
+ * \param [in] len* - input buffer length
+ * \retval [out] crc - computed crc
+ */
+uint32_t crc( const uint8_t* buf, int len );
+uint8_t crc8( const uint8_t* data, int length );
+uint32_t compute_crc_fw( void );
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __MODEM_UTILITIES_H__
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/smtc_clock_sync.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/smtc_clock_sync.c
index 8b0dc86..cbee856 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/smtc_clock_sync.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_services/smtc_clock_sync.c
@@ -104,8 +104,6 @@ void clock_sync_init( clock_sync_ctx_t* ctx, alc_sync_ctx_t* alc_ctx )
ctx->fractional_second = 0;
ctx->alc_ctx = alc_ctx;
-
- // lorawan_api_set_device_time_callback( ( void ( * )( void*, uint32_t ) ) clock_sync_callback, ctx, 0 );
}
void clock_sync_set_enabled( clock_sync_ctx_t* ctx, bool enable, clock_sync_service_t sync_service )
@@ -320,7 +318,10 @@ bool clock_sync_is_time_valid( clock_sync_ctx_t* ctx )
{
b_ret = true;
}
- b_ret = false;
+ else
+ {
+ b_ret = false;
+ }
}
else
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.c
index 636d784..daf7aae 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.c
@@ -74,9 +74,26 @@
#include "fragmented_data_block.h"
#endif // LR1110_MODEM_E
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE CONSTANTS -------------------------------------------------------
+ */
+#define DM_PERIOD_AFTER_JOIN 0
+#define MODEM_MAX_TIME 0x1FFFFF
+#define MODEM_MAX_TIME 0x1FFFFF
+#define CALL_LR1MAC_PERIOD_MS 400
+#define MODEM_MAX_ALARM_S 0x7FFFFFFF
+
+#ifndef MODEM_MIN_RANDOM_DELAY_MS
+#define MODEM_MIN_RANDOM_DELAY_MS 200
+#endif
+
+#ifndef MODEM_MAX_RANDOM_DELAY_MS
+#define MODEM_MAX_RANDOM_DELAY_MS 3000
+#endif
/*
*-----------------------------------------------------------------------------------
- * --- PUBLIC MACROS ----------------------------------------------------------------
+ * --- PRIVATE MACROS ----------------------------------------------------------------
*/
/*!
@@ -93,6 +110,12 @@
*/
#define ABS( N ) ( ( N < 0 ) ? ( -N ) : ( N ) )
+/**
+ * @brief Macro for modem task random delay calculation
+ */
+#define MODEM_TASK_DELAY_MS \
+ ( smtc_modem_hal_get_random_nb_in_range( MODEM_MIN_RANDOM_DELAY_MS, MODEM_MAX_RANDOM_DELAY_MS ) )
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE VARIABLES -------------------------------------------------------
@@ -1030,7 +1053,11 @@ uint32_t modem_supervisor_engine( void )
increment_asynchronous_msgnumber( SMTC_MODEM_EVENT_ALARM, 0 );
modem_set_user_alarm( 0 );
user_alarm_in_seconds = MODEM_MAX_ALARM_S;
- if( *app_callback != NULL )
+ if( lorawan_api_modem_certification_is_enabled( ) == true )
+ {
+ certification_event_handler( );
+ }
+ else if( *app_callback != NULL )
{
app_callback( );
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.h
index 991509d..4155c1f 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/modem_supervisor/modem_supervisor.h
@@ -64,12 +64,6 @@ extern "C" {
* --- PUBLIC CONSTANTS --------------------------------------------------------
*/
-#define DM_PERIOD_AFTER_JOIN 0
-#define MODEM_TASK_DELAY_MS 200
-#define MODEM_MAX_TIME 0x1FFFFF
-#define CALL_LR1MAC_PERIOD_MS 400
-#define MODEM_MAX_ALARM_S 0x7FFFFFFF
-
/*
* -----------------------------------------------------------------------------
* --- PUBLIC TYPES ------------------------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md
index 3b86d88..6c62e3c 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/CHANGELOG.md
@@ -4,6 +4,34 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v2.3.0] 2023-05-10
+
+### Added
+
+* [radio] `lr11xx_radio_set_lora_sync_timeout_with_mantissa_exponent()` function
+* [radio] `LR11XX_RADIO_PKT_TYPE_BPSK` packet type, with `lr11xx_radio_set_bpsk_pkt_params` and `lr11xx_radio_set_bpsk_mod_params` functions
+* [GNSS] `lr11xx_gnss_apply_mixer_cfg_workaround()` function
+* [GNSS] Add function `lr11xx_gnss_read_gnss_rssi_test` to read RSSI on GNSS path
+* [GNSS] Add function `lr11xx_gnss_read_freq_search_space`
+* [GNSS] Add function `lr11xx_gnss_set_freq_search_space`
+* [GNSS] Add function `lr11xx_gnss_get_nb_visible_satellites`
+* [GNSS] Add function `lr11xx_gnss_get_visible_satellites`
+* [GNSS] add structure `lr11xx_gnss_visible_satellite_t` to support `lr11xx_gnss_get_visible_satellites` function
+* [lr-fhss] Add function `lr11xx_lr_fhss_get_bit_delay_in_us` to compute the delay between the last LR-FHSS bit sent and the TX done interrupt
+* [radio] Add function `lr11xx_radio_set_lr_fhss_sync_word` to configure the LR-FHSS syncword
+* [radio] Add function `lr11xx_radio_set_lr_fhss_mod_params` to configure the LR-FHSS modulation parameters
+* [radio] Add helper function `lr11xx_radio_convert_nb_symb_to_mant_exp` to convert a number of symbols into mantissa/exponent representation
+* [crypto] Add functions `lr11xx_crypto_check_encrypted_firmware_image` and `lr11xx_crypto_get_check_encrypted_firmware_image_result`; and helper function `lr11xx_crypto_check_encrypted_firmware_image_full` to check suitability of encrypted firmware image prior to actual flashing
+* [ranging] Add `lr11xx_ranging_*` functions as part of new ranging component `lr11xx_ranging`
+
+### Changed
+
+* [GNSS] Call to `lr11xx_gnss_apply_mixer_cfg_workaround()` in `lr11xx_gnss_scan_autonomous()` and `lr11xx_gnss_scan_assisted()` (can be removed by defining `LR11XX_DISABLE_MIXER_CFG_WORKAROUND`)
+* [system] Field `type` of `lr11xx_system_version_t` is now an enumerated type named `lr11xx_system_version_type_t`
+* [system] Add IRQ raised on LoRa symbol received over-the-air
+* [radio] `lr11xx_radio_set_lora_sync_timeout` takes argument `nb_symbol` as `uint16_t`
+* [regmem] `lr11xx_regmem_write_regmem32` and `lr11xx_regmem_read_regmem32` test the number of words to write/read before actually requesting the chip, and raise an error status if it is higher than 64
+
## [v2.1.1] 2022-04-06
### Fixed
@@ -19,8 +47,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* [radio] `LR11XX_RADIO_LORA_BW_200`, `LR11XX_RADIO_LORA_BW_400` and `LR11XX_RADIO_LORA_BW_800` entries to `lr11xx_radio_lora_bw_t`
* [radio] `LR11XX_RADIO_GFSK_PKT_VAR_LEN_SX128X_COMP` entry in `lr11xx_radio_gfsk_pkt_len_modes_t` to support compatibility with SX128x
* [radio] `LR11XX_RADIO_GFSK_DC_FREE_WHITENING_SX128X_COMP` entry in `lr11xx_radio_gfsk_dc_free_t` to support compatibility with SX128x
-* [GNSS] `lr1110_gnss_get_consumption` function
-* [Wi-Fi] `lr1110_wifi_get_consumption` function
+* [GNSS] `lr11xx_gnss_get_consumption` function
+* [Wi-Fi] `lr11xx_wifi_get_consumption` function
* [Wi-Fi] `lr11xx_wifi_are_scan_mode_result_format_compatible` function
### Changed
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/README.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/README.md
index 05629c5..7d92871 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/README.md
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/README.md
@@ -13,6 +13,7 @@ The driver is split in several components:
- Wi-Fi Passive Scanning
- GNSS Scan Scanning
- Crypto engine
+- Ranging
### Bootloader
@@ -42,6 +43,10 @@ This component is used to configure and initiate the acquisition of GNSS signals
This component is used to set and derive keys in the internal keychain and perform cryptographic operations with the integrated hardware accelerator.
+### Ranging
+
+This component is used to configure and operate the device's LoRa Ranging feature.
+
## Structure
Each component is based on different files:
@@ -81,7 +86,7 @@ The workaround is to reset the bit 30 in the register `0x00F30054` when the chip
This workaround does not solve the case where `LR11XX_RADIO_MODE_SLEEP` is configured with `lr11xx_radio_auto_tx_rx` and the chip is set to Rx mode. This is dues to the fact that the workaround cannot be applied before the subsequent transmission, automatically launched by the chip after waking up from sleep mode with retention.
-#### Implementation 1
+#### Implementation 1: systematic call by the driver
The first implementation - enabled by default in the driver - adds an implicit call updating the parameter to each function that could set the chip in transmission - directly or not -:
@@ -94,8 +99,47 @@ This implementation can be disabled by defining the macro `LR11XX_DISABLE_HIGH_A
The main advantage of this implementation is that it is transparent to the user who only needs to update the driver without changing its application. The main drawback is that the implicit call is done systematically even when not required.
-#### Implementation 2
+#### Implementation 2: user-handled call
The second method requires the user to explicitly call the function `lr11xx_radio_apply_high_acp_workaround` when the chip wakes up from sleep mode with retention (note: to ease the implementation, it can be called when the chip wakes up from any sleep mode).
This method requires the macro `LR11XX_DISABLE_HIGH_ACP_WORKAROUND` to be defined so the implementation 1 of the workaround (enabled by default) is disabled.
+
+### Mixer configuration
+
+#### Description
+
+The following firmware versions are affected:
+
+- LR1120 firmware 0x0101
+
+When the chip ends a reception in the 2.4 GHz band, a parameter is not reconfigured properly. This misconfiguration will prevent a subsequent GNSS scan from working properly.
+
+It is important to note that if the chip enters one of the following state between the reception in the 2.4GHz band and the GNSS scan, the parameter is properly reconfigured and the limitation does not appear:
+
+- sleep mode (with or without retention)
+- Wi-Fi scan
+- Reception in the sub-GHz band
+
+### Workaround
+
+The workaround is to set the bit 4 in the register `0x00F30024` when the chip ends a reception in the 2.4GHz band before launching a GNSS scan.
+
+This workaround is not needed when using any LR1110 firmware version. Nevertheless, it does not prevent a LR1110 from working properly if the workaround is not deactivated.
+
+#### Implementation 1: systematic call by the driver
+
+The first implementation - enabled by default in the driver - adds an implicit call updating the parameter to each function that could set the chip in GNSS scan mode:
+
+- `lr11xx_gnss_scan_autonomous`
+- `lr11xx_gnss_scan_assisted`
+
+This implementation can be disabled by defining the macro `LR11XX_DISABLE_MIXER_CFG_WORKAROUND`. This disabling will be useful when, in the future, a new firmware integrating a fix is released and does not require the workaround anymore.
+
+The main advantage of this implementation is that it is transparent to the user who only needs to update the driver without changing its application. The main drawback is that the implicit call is done systematically even when not required.
+
+#### Implementation 2: user-handled call
+
+The second method requires the user to explicitly call the function `lr11xx_gnss_apply_mixer_cfg_workaround` when the chip ends a reception in the 2.4GHz if a GNSS scan is planned after, without going through one of the states specified in the description of this limitation.
+
+This method requires the macro `LR11XX_DISABLE_MIXER_CFG_WORKAROUND` to be defined so the implementation 1 of the workaround (enabled by default) is disabled.
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c
index 9d4128a..3ff69a5 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.c
@@ -50,6 +50,9 @@
* --- PRIVATE CONSTANTS -------------------------------------------------------
*/
+#define LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32 ( 64 )
+#define LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT8 ( LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32 * 4 )
+
#define LR11XX_CRYPTO_SELECT_CMD_LENGTH ( 2 + 1 )
#define LR11XX_CRYPTO_SET_KEY_CMD_LENGTH ( 2 + 17 )
#define LR11XX_CRYPTO_DERIVE_KEY_CMD_LENGTH ( 2 + 18 )
@@ -62,6 +65,8 @@
#define LR11XX_CRYPTO_RESTORE_FROM_FLASH_CMD_LENGTH ( 2 )
#define LR11XX_CRYPTO_SET_PARAMETER_CMD_LENGTH ( 2 + 1 + 4 )
#define LR11XX_CRYPTO_GET_PARAMETER_CMD_LENGTH ( 2 + 1 )
+#define LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_CMD_LENGTH ( 2 + 4 )
+#define LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_CMD_LENGTH ( 2 )
/*
* -----------------------------------------------------------------------------
@@ -73,19 +78,21 @@
*/
enum
{
- LR11XX_CRYPTO_SELECT_OC = 0x0500,
- LR11XX_CRYPTO_SET_KEY_OC = 0x0502,
- LR11XX_CRYPTO_DERIVE_KEY_OC = 0x0503,
- LR11XX_CRYPTO_PROCESS_JOIN_ACCEPT_OC = 0x0504,
- LR11XX_CRYPTO_COMPUTE_AES_CMAC_OC = 0x0505,
- LR11XX_CRYPTO_VERIFY_AES_CMAC_OC = 0x0506,
- LR11XX_CRYPTO_ENCRYPT_AES_01_OC = 0x0507,
- LR11XX_CRYPTO_ENCRYPT_AES_OC = 0x0508,
- LR11XX_CRYPTO_DECRYPT_AES_OC = 0x0509,
- LR11XX_CRYPTO_STORE_TO_FLASH_OC = 0x050A,
- LR11XX_CRYPTO_RESTORE_FROM_FLASH_OC = 0x050B,
- LR11XX_CRYPTO_SET_PARAMETER_OC = 0x050D,
- LR11XX_CRYPTO_GET_PARAMETER_OC = 0x050E,
+ LR11XX_CRYPTO_SELECT_OC = 0x0500,
+ LR11XX_CRYPTO_SET_KEY_OC = 0x0502,
+ LR11XX_CRYPTO_DERIVE_KEY_OC = 0x0503,
+ LR11XX_CRYPTO_PROCESS_JOIN_ACCEPT_OC = 0x0504,
+ LR11XX_CRYPTO_COMPUTE_AES_CMAC_OC = 0x0505,
+ LR11XX_CRYPTO_VERIFY_AES_CMAC_OC = 0x0506,
+ LR11XX_CRYPTO_ENCRYPT_AES_01_OC = 0x0507,
+ LR11XX_CRYPTO_ENCRYPT_AES_OC = 0x0508,
+ LR11XX_CRYPTO_DECRYPT_AES_OC = 0x0509,
+ LR11XX_CRYPTO_STORE_TO_FLASH_OC = 0x050A,
+ LR11XX_CRYPTO_RESTORE_FROM_FLASH_OC = 0x050B,
+ LR11XX_CRYPTO_SET_PARAMETER_OC = 0x050D,
+ LR11XX_CRYPTO_GET_PARAMETER_OC = 0x050E,
+ LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_OC = 0x050F,
+ LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_OC = 0x0510,
};
/*
@@ -113,6 +120,15 @@ enum
static void lr11xx_crypto_fill_cbuffer_opcode_key_data( uint8_t* cbuffer, uint16_t opcode, uint8_t key_id,
const uint8_t* data, uint16_t length );
+/*!
+ * @brief Returns the minimum of the operand given as parameter and the maximum allowed block size
+ *
+ * @param [in] operand Size to compare
+ *
+ * @returns Minimum between operand and @ref LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32
+ */
+static uint8_t lr11xx_crypto_get_min_from_operand_and_max_block_size( uint32_t operand );
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
@@ -469,6 +485,76 @@ lr11xx_status_t lr11xx_crypto_get_parameter( const void* context, lr11xx_crypto_
return ( lr11xx_status_t ) hal_status;
}
+lr11xx_status_t lr11xx_crypto_check_encrypted_firmware_image( const void* context, const uint32_t offset_in_byte,
+ const uint32_t* data, const uint8_t length_in_word )
+{
+ const uint8_t cbuffer[LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_OC >> 0 ),
+ ( uint8_t ) ( offset_in_byte >> 24 ),
+ ( uint8_t ) ( offset_in_byte >> 16 ),
+ ( uint8_t ) ( offset_in_byte >> 8 ),
+ ( uint8_t ) ( offset_in_byte >> 0 ),
+ };
+
+ uint8_t cdata[256] = { 0 };
+ for( uint8_t index = 0; index < length_in_word; index++ )
+ {
+ uint8_t* cdata_local = &cdata[index * sizeof( uint32_t )];
+
+ cdata_local[0] = ( uint8_t ) ( data[index] >> 24 );
+ cdata_local[1] = ( uint8_t ) ( data[index] >> 16 );
+ cdata_local[2] = ( uint8_t ) ( data[index] >> 8 );
+ cdata_local[3] = ( uint8_t ) ( data[index] >> 0 );
+ }
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_CRYPTO_CHECK_ENCRYPTED_FW_IMAGE_CMD_LENGTH,
+ cdata, length_in_word * sizeof( uint32_t ) );
+}
+
+lr11xx_status_t lr11xx_crypto_check_encrypted_firmware_image_full( const void* context, const uint32_t offset_in_byte,
+ const uint32_t* buffer,
+ const uint32_t length_in_word )
+{
+ uint32_t remaining_length = length_in_word;
+ uint32_t local_offset = offset_in_byte;
+ uint32_t loop = 0;
+
+ while( remaining_length != 0 )
+ {
+ const lr11xx_status_t status = lr11xx_crypto_check_encrypted_firmware_image(
+ context, local_offset, buffer + loop * LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32,
+ lr11xx_crypto_get_min_from_operand_and_max_block_size( remaining_length ) );
+
+ if( status != LR11XX_STATUS_OK )
+ {
+ return status;
+ }
+
+ local_offset += LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT8;
+ remaining_length = ( remaining_length < LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32 )
+ ? 0
+ : ( remaining_length - LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32 );
+
+ loop++;
+ }
+
+ return LR11XX_STATUS_OK;
+}
+
+lr11xx_status_t lr11xx_crypto_get_check_encrypted_firmware_image_result( const void* context,
+ bool* is_encrypted_fw_image_ok )
+{
+ const uint8_t cbuffer[LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_OC >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer,
+ LR11XX_CRYPTO_GET_CHECK_ENCRYPTED_FW_IMAGE_RESULT_CMD_LENGTH,
+ ( uint8_t* ) is_encrypted_fw_image_ok, 1 );
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
@@ -488,4 +574,16 @@ static void lr11xx_crypto_fill_cbuffer_opcode_key_data( uint8_t* cbuffer, uint16
}
}
+uint8_t lr11xx_crypto_get_min_from_operand_and_max_block_size( uint32_t operand )
+{
+ if( operand > LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32 )
+ {
+ return LR11XX_CRYPTO_FW_IMAGE_DATA_MAX_LENGTH_UINT32;
+ }
+ else
+ {
+ return ( uint8_t ) operand; // Downcast done on purpose given that the value is smaller than 64
+ }
+}
+
/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.h
index 1d6528c..759e737 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_crypto_engine.h
@@ -44,6 +44,7 @@ extern "C" {
* --- DEPENDENCIES ------------------------------------------------------------
*/
+#include
#include "lr11xx_crypto_engine_types.h"
#include "lr11xx_types.h"
@@ -88,9 +89,9 @@ lr11xx_status_t lr11xx_crypto_select( const void* context, const lr11xx_crypto_e
* @param [in] key_id The identifier of the key to be set
* @param [in] key The key to be set
*
- * @see lr11xx_crypto_derive_key
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_derive_key
*/
lr11xx_status_t lr11xx_crypto_set_key( const void* context, lr11xx_crypto_status_t* status, const uint8_t key_id,
const lr11xx_crypto_key_t key );
@@ -105,9 +106,9 @@ lr11xx_status_t lr11xx_crypto_set_key( const void* context, lr11xx_crypto_status
* lr11xx_crypto_store_to_flash
* @param [in] nonce The nonce to be used to perform the derivation
*
- * @see lr11xx_crypto_set_key
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_set_key
*/
lr11xx_status_t lr11xx_crypto_derive_key( const void* context, lr11xx_crypto_status_t* status, const uint8_t src_key_id,
const uint8_t dest_key_id, const lr11xx_crypto_nonce_t nonce );
@@ -143,9 +144,9 @@ lr11xx_status_t lr11xx_crypto_process_join_accept( const void* context, lr11xx_c
* @param [in] length The length in bytes of the data to compute
* @param [out] mic Placeholder for the computed MIC (first 4 bytes of the AES-CMAC)
*
- * @see lr11xx_crypto_verify_aes_cmac
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_verify_aes_cmac
*/
lr11xx_status_t lr11xx_crypto_compute_aes_cmac( const void* context, lr11xx_crypto_status_t* status,
const uint8_t key_id, const uint8_t* data, const uint16_t length,
@@ -161,9 +162,9 @@ lr11xx_status_t lr11xx_crypto_compute_aes_cmac( const void* context, lr11xx_cryp
* @param [in] length The length in bytes of the data to compute
* @param [in] mic The MIC value (first 4 bytes of the CMAC) use for comparison
*
- * @see lr11xx_crypto_compute_aes_cmac
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_compute_aes_cmac
*/
lr11xx_status_t lr11xx_crypto_verify_aes_cmac( const void* context, lr11xx_crypto_status_t* status,
const uint8_t key_id, const uint8_t* data, const uint16_t length,
@@ -180,9 +181,9 @@ lr11xx_status_t lr11xx_crypto_verify_aes_cmac( const void* context, lr11xx_crypt
* @param [out] result A pointer to a data buffer that will be filled with the encrypted data. Values of this buffer are
* meaningful if and only if the return status is LR11XX_CRYPTO_STATUS_SUCCESS
*
- * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
*/
lr11xx_status_t lr11xx_crypto_aes_encrypt_01( const void* context, lr11xx_crypto_status_t* status, const uint8_t key_id,
const uint8_t* data, const uint16_t length, uint8_t* result );
@@ -198,9 +199,9 @@ lr11xx_status_t lr11xx_crypto_aes_encrypt_01( const void* context, lr11xx_crypto
* @param [out] result A pointer to a data buffer that will be filled with the encrypted data. Values of this buffer are
* meaningful if and only if the return status is LR11XX_CRYPTO_STATUS_SUCCESS
*
- * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
*/
lr11xx_status_t lr11xx_crypto_aes_encrypt( const void* context, lr11xx_crypto_status_t* status, const uint8_t key_id,
const uint8_t* data, const uint16_t length, uint8_t* result );
@@ -216,9 +217,9 @@ lr11xx_status_t lr11xx_crypto_aes_encrypt( const void* context, lr11xx_crypto_st
* @param [out] result A pointer to a data buffer that will be filled with the decrypted data. Values of this buffer are
* meaningful if and only if the return status is LR11XX_CRYPTO_STATUS_SUCCESS
*
- * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_set_key, lr11xx_crypto_derive_key
*/
lr11xx_status_t lr11xx_crypto_aes_decrypt( const void* context, lr11xx_crypto_status_t* status, const uint8_t key_id,
const uint8_t* data, const uint16_t length, uint8_t* result );
@@ -229,9 +230,9 @@ lr11xx_status_t lr11xx_crypto_aes_decrypt( const void* context, lr11xx_crypto_st
* @param [in] context Chip implementation context
* @param [out] status The status returned by the execution of this cryptographic function
*
- * @see lr11xx_crypto_restore_from_flash
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_restore_from_flash
*/
lr11xx_status_t lr11xx_crypto_store_to_flash( const void* context, lr11xx_crypto_status_t* status );
@@ -241,9 +242,9 @@ lr11xx_status_t lr11xx_crypto_store_to_flash( const void* context, lr11xx_crypto
* @param [in] context Chip implementation context
* @param [out] status The status returned by the execution of this cryptographic function
*
- * @see lr11xx_crypto_store_to_flash
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_store_to_flash
*/
lr11xx_status_t lr11xx_crypto_restore_from_flash( const void* context, lr11xx_crypto_status_t* status );
@@ -258,9 +259,9 @@ lr11xx_status_t lr11xx_crypto_restore_from_flash( const void* context, lr11xx_cr
* @param [in] param_id The identifier of the parameter to be set
* @param [in] parameter The parameter to be set
*
- * @see lr11xx_crypto_get_parameter
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_get_parameter
*/
lr11xx_status_t lr11xx_crypto_set_parameter( const void* context, lr11xx_crypto_status_t* status,
const uint8_t param_id, const lr11xx_crypto_param_t parameter );
@@ -276,13 +277,62 @@ lr11xx_status_t lr11xx_crypto_set_parameter( const void* context, lr11xx_crypto_
* @param [in] param_id The identifier of the parameter to get
* @param [out] parameter The placeholder to store the parameter
*
- * @see lr11xx_crypto_set_parameter
- *
* @returns Operation status
+ *
+ * @see lr11xx_crypto_set_parameter
*/
lr11xx_status_t lr11xx_crypto_get_parameter( const void* context, lr11xx_crypto_status_t* status,
const uint8_t param_id, lr11xx_crypto_param_t parameter );
+/*!
+ * @brief Check if an encrypted firmware image is suitable for the transceiver on which the check is done
+ *
+ * @remark The result can be read by calling @ref lr11xx_crypto_get_check_encrypted_firmware_image_result
+ *
+ * @remark A user checks the suitability of a firmware image by calling this function with 64-word long chunk of data
+ * sent in-order (except for the last one that can be shorter).
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] offset_in_byte Offset of data buffer in firmware image - has to be a multiple of 4
+ * @param [in] data Buffer holding the encrypted content. Its size in words must be at least length
+ * @param [in] length_in_word Number of words (i.e. 4 bytes) in the buffer to transfer. This value must be in the range
+ * [0:64]
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_crypto_check_encrypted_firmware_image( const void* context, const uint32_t offset_in_byte,
+ const uint32_t* data, const uint8_t length_in_word );
+
+/*!
+ * @brief Check if an encrypted firmware image is suitable for the transceiver on which the check is done
+ *
+ * @remark The result can be read by calling @ref lr11xx_crypto_get_check_encrypted_firmware_image_result
+ *
+ * @remark This function is developed on top of @ref lr11xx_crypto_check_encrypted_firmware_image and takes care of the
+ * whole firmware image transfer
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] offset_in_byte Offset of data buffer in firmware image - has to be a multiple of 4
+ * @param [in] data Buffer holding the encrypted content. Its size in words must be at least length
+ * @param [in] length_in_word Number of words (i.e. 4 bytes) in the buffer to transfer
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_crypto_check_encrypted_firmware_image_full( const void* context, const uint32_t offset_in_byte,
+ const uint32_t* data,
+ const uint32_t length_in_word );
+
+/*!
+ * @brief Get the result of the encrypted firmware image check
+ *
+ * @param [in] context Chip implementation context
+ * @param [out] is_encrypted_fw_image_ok Result of the encrypted firmware image check
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_crypto_get_check_encrypted_firmware_image_result( const void* context,
+ bool* is_encrypted_fw_image_ok );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_module.cmake b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_module.cmake
index 6c7bf17..fdc1d6b 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_module.cmake
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_module.cmake
@@ -38,6 +38,7 @@ set(LR11XX_DRIVER_MODULE_C_SOURCES
${CMAKE_CURRENT_LIST_DIR}/lr11xx_lr_fhss.c
${CMAKE_CURRENT_LIST_DIR}/lr11xx_radio.c
${CMAKE_CURRENT_LIST_DIR}/lr11xx_radio_timings.c
+ ${CMAKE_CURRENT_LIST_DIR}/lr11xx_ranging.c
${CMAKE_CURRENT_LIST_DIR}/lr11xx_regmem.c
${CMAKE_CURRENT_LIST_DIR}/lr11xx_system.c
${CMAKE_CURRENT_LIST_DIR}/lr11xx_wifi.c
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h
index 24e06e4..e39d56b 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_driver_version.h
@@ -55,8 +55,8 @@ extern "C" {
*/
#define LR11XX_DRIVER_VERSION_MAJOR 2
-#define LR11XX_DRIVER_VERSION_MINOR 1
-#define LR11XX_DRIVER_VERSION_PATCH 1
+#define LR11XX_DRIVER_VERSION_MINOR 2
+#define LR11XX_DRIVER_VERSION_PATCH 0
/*
* -----------------------------------------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.c
index c9368f3..317ed32 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.c
@@ -47,15 +47,29 @@
* --- PRIVATE MACROS-----------------------------------------------------------
*/
+/**
+ * @brief Management of the mixer configuration workaround - only LR1120 firmware 0x0101 is impacted
+ *
+ * @remark This workaround can be deactived when using any LR1110 firmware version
+ */
+#ifdef LR11XX_DISABLE_MIXER_CFG_WORKAROUND
+#define LR11XX_GNSS_APPLY_MIXER_CFG_WORKAROUND( context ) LR11XX_STATUS_OK
+#else
+#define LR11XX_GNSS_APPLY_MIXER_CFG_WORKAROUND( context ) lr11xx_gnss_apply_mixer_cfg_workaround( context )
+#endif
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE CONSTANTS -------------------------------------------------------
*/
+#define LR11XX_GNSS_READ_GNSS_RSSI_TEST_CMD_LENGTH ( 2 + 2 )
#define LR11XX_GNSS_SET_CONSTELLATION_CMD_LENGTH ( 2 + 1 )
#define LR11XX_GNSS_READ_CONSTELLATION_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_SET_ALMANAC_UPDATE_CMD_LENGTH ( 2 + 1 )
#define LR11XX_GNSS_READ_ALMANAC_UPDATE_CMD_LENGTH ( 2 )
+#define LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH ( 2 + 1 )
+#define LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_READ_FW_VERSION_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_READ_SUPPORTED_CONSTELLATION_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_SET_SCAN_MODE_CMD_LENGTH ( 2 + 1 )
@@ -73,7 +87,10 @@
#define LR11XX_GNSS_SCAN_GET_TIMINGS_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_GET_NB_SV_SATELLITES_CMD_LENGTH ( 2 )
#define LR11XX_GNSS_GET_SV_SATELLITES_CMD_LENGTH ( 2 )
+#define LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH ( 2 + 9 )
+#define LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH ( 2 )
+#define LR11XX_GNSS_READ_GNSS_RSSI_TEST_READ_RBUFFER_LENGTH ( 2 )
#define LR11XX_GNSS_ALMANAC_READ_RBUFFER_LENGTH ( 6 )
#define LR11XX_GNSS_ALMANAC_DATE_LENGTH ( 2 )
#define LR11XX_GNSS_ALMANAC_UPDATE_MAX_NB_OF_BLOCKS \
@@ -115,10 +132,13 @@
*/
enum
{
+ LR11XX_GNSS_READ_GNSS_RSSI_TEST_OC = 0x0222,
LR11XX_GNSS_SET_CONSTELLATION_OC = 0x0400, //!< Set the constellation to use
LR11XX_GNSS_READ_CONSTELLATION_OC = 0x0401, //!< Read the used constellations
LR11XX_GNSS_SET_ALMANAC_UPDATE_OC = 0x0402, //!< Set almanac update configuration
LR11XX_GNSS_READ_ALMANAC_UPDATE_OC = 0x0403, //!< Read the almanac update configuration
+ LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC = 0x0404, //!< Set the frequency search space
+ LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC = 0x0405, //!< Read the frequency search space
LR11XX_GNSS_READ_FW_VERSION_OC = 0x0406, //!< Read the firmware version
LR11XX_GNSS_READ_SUPPORTED_CONSTELLATION_OC = 0x0407, //!< Read the supported constellations
LR11XX_GNSS_SET_SCAN_MODE_OC = 0x0408, //!< Define single or double capture
@@ -136,6 +156,8 @@ enum
LR11XX_GNSS_GET_NB_SATELLITES_OC = 0x0417, //!< Get the number of satellites detected during a scan
LR11XX_GNSS_GET_SATELLITES_OC = 0x0418, //!< Get the list of satellites detected during a scan
LR11XX_GNSS_GET_TIMINGS_OC = 0x0419, //!< Get the time spent in signal acquisition and analysis
+ LR11XX_GNSS_GET_SV_VISIBLE_OC = 0x041F, //!< Get the number of visible SV from a date and a position
+ LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC = 0x0420, //!< Get visible SV ID and corresponding doppler value
};
/*
@@ -410,6 +432,30 @@ lr11xx_status_t lr11xx_gnss_read_almanac_update( const void*
constellations_to_update, sizeof( *constellations_to_update ) );
}
+lr11xx_status_t lr11xx_gnss_set_freq_search_space( const void* radio,
+ const lr11xx_gnss_freq_search_space_t freq_search_space )
+{
+ const uint8_t cbuffer[LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_OC >> 0 ),
+ ( uint8_t ) freq_search_space,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( radio, cbuffer, LR11XX_GNSS_SET_FREQ_SEARCH_SPACE_CMD_LENGTH, 0, 0 );
+}
+
+lr11xx_status_t lr11xx_gnss_read_freq_search_space( const void* radio,
+ lr11xx_gnss_freq_search_space_t* freq_search_space )
+{
+ const uint8_t cbuffer[LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_OC >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_read( radio, cbuffer, LR11XX_GNSS_READ_FREQ_SEARCH_SPACE_CMD_LENGTH,
+ ( uint8_t* ) freq_search_space, sizeof( uint8_t ) );
+}
+
lr11xx_status_t lr11xx_gnss_read_firmware_version( const void* context, lr11xx_gnss_version_t* version )
{
const uint8_t cbuffer[LR11XX_GNSS_READ_FW_VERSION_CMD_LENGTH] = {
@@ -453,38 +499,70 @@ lr11xx_status_t lr11xx_gnss_scan_autonomous( const void* context, const lr11xx_g
const lr11xx_gnss_search_mode_t effort_mode,
const uint8_t gnss_input_parameters, const uint8_t nb_sat )
{
- const uint8_t cbuffer[LR11XX_GNSS_SCAN_AUTONOMOUS_CMD_LENGTH] = {
- ( uint8_t ) ( LR11XX_GNSS_SCAN_AUTONOMOUS_OC >> 8 ),
- ( uint8_t ) ( LR11XX_GNSS_SCAN_AUTONOMOUS_OC >> 0 ),
- ( uint8_t ) ( date >> 24 ),
- ( uint8_t ) ( date >> 16 ),
- ( uint8_t ) ( date >> 8 ),
- ( uint8_t ) ( date >> 0 ),
- ( uint8_t ) effort_mode,
- gnss_input_parameters,
- nb_sat,
+ lr11xx_status_t status = LR11XX_STATUS_ERROR;
+ const uint8_t cbuffer[LR11XX_GNSS_SCAN_AUTONOMOUS_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_SCAN_AUTONOMOUS_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_SCAN_AUTONOMOUS_OC >> 0 ),
+ ( uint8_t ) ( date >> 24 ),
+ ( uint8_t ) ( date >> 16 ),
+ ( uint8_t ) ( date >> 8 ),
+ ( uint8_t ) ( date >> 0 ),
+ ( uint8_t ) effort_mode,
+ gnss_input_parameters,
+ nb_sat,
};
- return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_GNSS_SCAN_AUTONOMOUS_CMD_LENGTH, 0, 0 );
+ do
+ {
+ status = LR11XX_GNSS_APPLY_MIXER_CFG_WORKAROUND( context );
+ if( status != LR11XX_STATUS_OK )
+ {
+ break;
+ }
+
+ status = ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_GNSS_SCAN_AUTONOMOUS_CMD_LENGTH, 0, 0 );
+ if( status != LR11XX_STATUS_OK )
+ {
+ break;
+ }
+ } while( 0 );
+
+ return status;
}
lr11xx_status_t lr11xx_gnss_scan_assisted( const void* context, const lr11xx_gnss_date_t date,
const lr11xx_gnss_search_mode_t effort_mode,
const uint8_t gnss_input_parameters, const uint8_t nb_sat )
{
- const uint8_t cbuffer[LR11XX_GNSS_SCAN_ASSISTED_CMD_LENGTH] = {
- ( uint8_t ) ( LR11XX_GNSS_SCAN_ASSISTED_OC >> 8 ),
- ( uint8_t ) ( LR11XX_GNSS_SCAN_ASSISTED_OC >> 0 ),
- ( uint8_t ) ( date >> 24 ),
- ( uint8_t ) ( date >> 16 ),
- ( uint8_t ) ( date >> 8 ),
- ( uint8_t ) ( date >> 0 ),
- ( uint8_t ) effort_mode,
- gnss_input_parameters,
- nb_sat,
+ lr11xx_status_t status = LR11XX_STATUS_ERROR;
+ const uint8_t cbuffer[LR11XX_GNSS_SCAN_ASSISTED_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_SCAN_ASSISTED_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_SCAN_ASSISTED_OC >> 0 ),
+ ( uint8_t ) ( date >> 24 ),
+ ( uint8_t ) ( date >> 16 ),
+ ( uint8_t ) ( date >> 8 ),
+ ( uint8_t ) ( date >> 0 ),
+ ( uint8_t ) effort_mode,
+ gnss_input_parameters,
+ nb_sat,
};
- return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_GNSS_SCAN_ASSISTED_CMD_LENGTH, 0, 0 );
+ do
+ {
+ status = LR11XX_GNSS_APPLY_MIXER_CFG_WORKAROUND( context );
+ if( status != LR11XX_STATUS_OK )
+ {
+ break;
+ }
+
+ status = ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_GNSS_SCAN_ASSISTED_CMD_LENGTH, 0, 0 );
+ if( status != LR11XX_STATUS_OK )
+ {
+ break;
+ }
+ } while( 0 );
+
+ return status;
}
lr11xx_status_t lr11xx_gnss_set_assistance_position(
@@ -594,6 +672,27 @@ lr11xx_status_t lr11xx_gnss_get_detected_satellites(
return ( lr11xx_status_t ) hal_status;
}
+lr11xx_status_t lr11xx_gnss_read_gnss_rssi_test( const void* context, int8_t* rssi_gnss_dbm )
+{
+ const uint8_t gnss_rssi_path_test = 0x09;
+ const uint8_t cbuffer[LR11XX_GNSS_READ_GNSS_RSSI_TEST_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_READ_GNSS_RSSI_TEST_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_READ_GNSS_RSSI_TEST_OC >> 0 ),
+ gnss_rssi_path_test,
+ 0,
+ };
+
+ uint8_t rssi_gnss_raw[LR11XX_GNSS_READ_GNSS_RSSI_TEST_READ_RBUFFER_LENGTH] = { 0 };
+ const lr11xx_hal_status_t hal_status =
+ lr11xx_hal_read( context, cbuffer, LR11XX_GNSS_READ_GNSS_RSSI_TEST_CMD_LENGTH, rssi_gnss_raw,
+ LR11XX_GNSS_READ_GNSS_RSSI_TEST_READ_RBUFFER_LENGTH );
+ if( hal_status == LR11XX_HAL_STATUS_OK )
+ {
+ *rssi_gnss_dbm = rssi_gnss_raw[1];
+ }
+ return ( lr11xx_status_t ) hal_status;
+}
+
lr11xx_status_t lr11xx_gnss_parse_context_status_buffer(
const lr11xx_gnss_context_status_bytestream_t context_status_bytestream,
lr11xx_gnss_context_status_t* context_status )
@@ -716,6 +815,69 @@ uint32_t lr11xx_gnss_get_consumption( lr11xx_system_reg_mode_t regulator, lr11xx
return gnss_scan_consumption_uah;
}
+lr11xx_status_t lr11xx_gnss_apply_mixer_cfg_workaround( const void* context )
+{
+ return lr11xx_regmem_write_regmem32_mask( context, 0x00F30024, 1 << 4, 1 << 4 );
+}
+
+lr11xx_status_t lr11xx_gnss_get_nb_visible_satellites(
+ const void* context, const lr11xx_gnss_date_t date,
+ const lr11xx_gnss_solver_assistance_position_t* assistance_position,
+ const lr11xx_gnss_constellation_t constellation, uint8_t* nb_visible_sv )
+{
+ const int16_t latitude = ( ( assistance_position->latitude * 2048 ) / LR11XX_GNSS_SCALING_LATITUDE );
+ const int16_t longitude = ( ( assistance_position->longitude * 2048 ) / LR11XX_GNSS_SCALING_LONGITUDE );
+ const uint8_t cbuffer[LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_GET_SV_VISIBLE_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_GET_SV_VISIBLE_OC >> 0 ),
+ ( uint8_t ) ( date >> 24 ),
+ ( uint8_t ) ( date >> 16 ),
+ ( uint8_t ) ( date >> 8 ),
+ ( uint8_t ) ( date >> 0 ),
+ ( uint8_t ) ( latitude >> 8 ),
+ ( uint8_t ) ( latitude >> 0 ),
+ ( uint8_t ) ( longitude >> 8 ),
+ ( uint8_t ) ( longitude >> 0 ),
+ ( uint8_t ) ( constellation - 1 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer, LR11XX_GNSS_GET_SV_VISIBLE_CMD_LENGTH, nb_visible_sv,
+ 1 );
+}
+
+lr11xx_status_t lr11xx_gnss_get_visible_satellites( const void* context, const uint8_t nb_visible_satellites,
+ lr11xx_gnss_visible_satellite_t* visible_satellite_id_doppler )
+{
+ uint8_t result_buffer[12 * 5] = { 0 };
+ const uint16_t read_size = nb_visible_satellites * 5;
+
+ const uint8_t cbuffer[LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_OC >> 0 ),
+ };
+
+ const lr11xx_hal_status_t hal_status =
+ lr11xx_hal_read( context, cbuffer, LR11XX_GNSS_GET_SV_VISIBLE_DOPPLER_CMD_LENGTH, result_buffer, read_size );
+
+ if( hal_status == LR11XX_HAL_STATUS_OK )
+ {
+ for( uint8_t index_satellite = 0; index_satellite < nb_visible_satellites; index_satellite++ )
+ {
+ const uint16_t local_result_buffer_index = index_satellite * 5;
+ lr11xx_gnss_visible_satellite_t* local_satellite_result = &visible_satellite_id_doppler[index_satellite];
+
+ local_satellite_result->satellite_id = result_buffer[local_result_buffer_index];
+ local_satellite_result->doppler = ( int16_t ) ( ( result_buffer[local_result_buffer_index + 1] << 8 ) +
+ ( result_buffer[local_result_buffer_index + 2] << 0 ) );
+ local_satellite_result->doppler_error =
+ ( int16_t ) ( ( result_buffer[local_result_buffer_index + 3] << 8 ) +
+ ( result_buffer[local_result_buffer_index + 4] << 0 ) );
+ }
+ }
+
+ return ( lr11xx_status_t ) hal_status;
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h
index ebd54ef..c49f7e9 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss.h
@@ -136,6 +136,28 @@ lr11xx_status_t lr11xx_gnss_almanac_update( const void* context, const uint8_t*
lr11xx_status_t lr11xx_gnss_read_almanac( const void* context,
lr11xx_gnss_almanac_full_read_bytestream_t almanac_bytestream );
+/*!
+ * @brief Function to read the frequency search space around the Doppler frequency
+ *
+ * @param [in] radio Radio abstraction
+ * @param [out] freq_search_space Frequency search space configuration read from the chip
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_read_freq_search_space( const void* radio,
+ lr11xx_gnss_freq_search_space_t* freq_search_space );
+
+/*!
+ * @brief Function to set the frequency search space around the Doppler frequency
+ *
+ * @param [in] radio Radio abstraction
+ * @param [in] freq_search_space Frequency search space configuration to be applied
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_set_freq_search_space( const void* radio,
+ const lr11xx_gnss_freq_search_space_t freq_search_space );
+
/*!
* @brief Get almanac age for a satellite
*
@@ -159,12 +181,44 @@ lr11xx_status_t lr11xx_gnss_get_almanac_age_for_satellite( const void* context,
*/
lr11xx_status_t lr11xx_gnss_push_solver_msg( const void* context, const uint8_t* payload, const uint16_t payload_size );
+/**
+ * @brief Return the theoretical number of visible satellites based on the given parameters.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] date The actual date of scan. Its format is the number of seconds elapsed since January the 6th 1980
+ * 00:00:00 with leap seconds included.
+ * @param [in] assistance_position, latitude 12 bits and longitude 12 bits
+ * @param [in] constellation Bit mask of the constellations to use. See @ref lr11xx_gnss_constellation_t for
+ * the possible values
+ * @param [out] nb_visible_sv theoretical number of visible satellites
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_get_nb_visible_satellites(
+ const void* context, const lr11xx_gnss_date_t date,
+ const lr11xx_gnss_solver_assistance_position_t* assistance_position,
+ const lr11xx_gnss_constellation_t constellation, uint8_t* nb_visible_sv );
+
+/**
+ * @brief Return the theoretical doppler information of theoretical visible satellites, this function shall be called
+ * after lr11xx_gnss_get_nb_visible_satellites function.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] nb_visible_satellites number of visible satellites returned by lr11xx_gnss_get_nb_visible_satellites
+ * function,
+ * @param [out] visible_satellite_id_doppler Doppler information of each satellite.
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_get_visible_satellites( const void* context, const uint8_t nb_visible_satellites,
+ lr11xx_gnss_visible_satellite_t* visible_satellite_id_doppler );
+
/*!
* @brief Activate the GNSS scan constellation
*
* @param [in] context Chip implementation context
- * @param [in] constellation_mask Bit mask of the constellations to use. See @ref lr11xx_gnss_constellation_t for the
- * possible values
+ * @param [in] constellation_mask Bit mask of the constellations to use. See @ref lr11xx_gnss_constellation_t for
+ * the possible values
*
* @returns Operation status
*
@@ -241,7 +295,7 @@ lr11xx_status_t lr11xx_gnss_read_supported_constellations( const void*
*
* @returns Operation status
*
- * @ref lr11xx_gnss_scan_mode_t
+ * @see lr11xx_gnss_scan_mode_t
*/
lr11xx_status_t lr11xx_gnss_set_scan_mode( const void* context, const lr11xx_gnss_scan_mode_t scan_mode );
@@ -285,9 +339,9 @@ lr11xx_status_t lr11xx_gnss_scan_assisted( const void* context, const lr11xx_gns
* @param [in] context Chip implementation context
* @param [in] assistance_position, latitude 12 bits and longitude 12 bits
*
- * @ref See lr11xx_gnss_solver_assistance_position_t
- *
* @returns Operation status
+ *
+ * @see lr11xx_gnss_solver_assistance_position_t
*/
lr11xx_status_t lr11xx_gnss_set_assistance_position(
const void* context, const lr11xx_gnss_solver_assistance_position_t* assistance_position );
@@ -301,9 +355,9 @@ lr11xx_status_t lr11xx_gnss_set_assistance_position(
* @param [in] context Chip implementation context
* @param [in] assistance_position, latitude 12 bits and longitude 12 bits
*
- * @ref See lr11xx_gnss_solver_assistance_position_t
- *
* @returns Operation status
+ *
+ * @see lr11xx_gnss_solver_assistance_position_t
*/
lr11xx_status_t lr11xx_gnss_read_assistance_position( const void* context,
lr11xx_gnss_solver_assistance_position_t* assistance_position );
@@ -363,6 +417,18 @@ lr11xx_status_t lr11xx_gnss_get_detected_satellites(
const void* context, const uint8_t nb_detected_satellites,
lr11xx_gnss_detected_satellite_t* detected_satellite_id_snr_doppler );
+/*!
+ * @brief Read RSSI on GNSS path
+ *
+ * This is a test function to read RSSI on GNSS path.
+ *
+ * @param [in] context Chip implementation context
+ * @param [out] rssi_gnss_dbm RSSI read on GNSS path in dbm
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_read_gnss_rssi_test( const void* context, int8_t* rssi_gnss_dbm );
+
/**
* @brief Parse a raw buffer of context status
*
@@ -428,6 +494,18 @@ uint16_t lr11xx_gnss_compute_almanac_age( uint16_t almanac_date,
uint32_t lr11xx_gnss_get_consumption( lr11xx_system_reg_mode_t regulator, lr11xx_gnss_timings_t timings,
lr11xx_gnss_constellation_mask_t constellations_used );
+/*!
+ * @brief Apply the workaround for the mixer configuration issue - only LR1120 chip is impacted
+ *
+ * @remark This function is always called when calling @ref lr11xx_gnss_scan_autonomous or @ref
+ * lr11xx_gnss_scan_assisted unless the macro LR11XX_DISABLE_MIXER_CFG_WORKAROUND is defined.
+ *
+ * @param [in] context Chip implementation context
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_gnss_apply_mixer_cfg_workaround( const void* context );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss_types.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss_types.h
index 8473525..561b2ce 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss_types.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_gnss_types.h
@@ -298,6 +298,16 @@ typedef struct lr11xx_gnss_context_status_s
lr11xx_gnss_freq_search_space_t freq_search_space;
} lr11xx_gnss_context_status_t;
+/*!
+ * @brief Structure for information about visible SV
+ */
+typedef struct lr11xx_gnss_visible_satellite_s
+{
+ lr11xx_gnss_satellite_id_t satellite_id; //!< SV ID
+ int16_t doppler; //!< SV doppler in Hz
+ int16_t doppler_error; //!< SV doppler error - step of 125Hz
+} lr11xx_gnss_visible_satellite_t;
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.c
index cfdac8d..7aac7a4 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.c
@@ -46,17 +46,11 @@
* --- PRIVATE MACROS-----------------------------------------------------------
*/
-#define LR11XX_LR_FHSS_PKT_TYPE_LR_FHSS ( 0x04 )
-#define LR_FHSS_BITRATE_IN_256_BPS_STEPS ( 125000 )
-#define LR11XX_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH ( 2 + 5 )
#define LR11XX_LR_FHSS_BUILD_FRAME_LENGTH ( 2 + 9 )
-#define LR11XX_LR_FHSS_SET_SYNC_WORD_LENGTH ( 2 + 0 )
-#define LR11XX_LR_FHSS_SET_MODULATION_PARAM_DIVIDE_BITRATE_BY_256 ( 0x80000000 )
#define LR11XX_LR_FHSS_HEADER_BITS ( 114 )
#define LR11XX_LR_FHSS_FRAG_BITS ( 48 )
#define LR11XX_LR_FHSS_BLOCK_PREAMBLE_BITS ( 2 )
#define LR11XX_LR_FHSS_BLOCK_BITS ( LR11XX_LR_FHSS_FRAG_BITS + LR11XX_LR_FHSS_BLOCK_PREAMBLE_BITS )
-#define LR11XX_LR_FHSS_SYNCWORD_LENGTH ( 4 )
/*
* -----------------------------------------------------------------------------
@@ -73,9 +67,7 @@
*/
enum
{
- LR11XX_LR_FHSS_SET_MODULATION_PARAM_OC = 0x020F,
- LR11XX_LR_FHSS_BUILD_FRAME_OC = 0x022C,
- LR11XX_LR_FHSS_SET_SYNC_WORD_OC = 0x022D,
+ LR11XX_LR_FHSS_BUILD_FRAME_OC = 0x022C,
};
/*!
@@ -87,23 +79,6 @@ typedef enum
LR11XX_LR_FHSS_HOPPING_ENABLE = 0x01,
} lr11xx_lr_fhss_hopping_configuration_t;
-/*!
- * @brief Pulse shape configurations
- */
-typedef enum
-{
- LR11XX_LR_FHSS_PULSE_SHAPE_BT_1 = 0x0B //!< Gaussian BT 1.0
-} lr11xx_lr_fhss_pulse_shape_t;
-
-/*!
- * @brief Modulation configuration for LR_FHSS packets
- */
-typedef struct lr11xx_lr_fhss_mod_params_lr_fhss_s
-{
- uint32_t br_in_bps; //!< LR_FHSS bitrate [bit/s]
- lr11xx_lr_fhss_pulse_shape_t pulse_shape; //!< LR_FHSS pulse shape
-} lr11xx_lr_fhss_mod_params_lr_fhss_t;
-
/*
* -----------------------------------------------------------------------------
* --- PRIVATE VARIABLES -------------------------------------------------------
@@ -114,34 +89,6 @@ typedef struct lr11xx_lr_fhss_mod_params_lr_fhss_s
* --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
*/
-/*!
- * @brief Set the modulation parameters for LR_FHSS
- *
- * The command @ref lr11xx_lr_fhss_set_pkt_type must be called prior this one.
- *
- * @param [in] context Chip implementation context
- * @param [in] mod_params The structure of modulation configuration
- *
- * @returns Operation status
- *
- * @see lr11xx_lr_fhss_set_pkt_type
- */
-static lr11xx_status_t lr11xx_lr_fhss_set_lr_fhss_mod_params( const void* context,
- const lr11xx_lr_fhss_mod_params_lr_fhss_t* mod_params );
-
-/*!
- * @brief Set the syncword for LR_FHSS
- *
- * Default value: 0x2C0F7995
- *
- * @param [in] context Chip implementation context
- * @param [in] sync_word The syncword to set. It is up to the caller to ensure this array is at least four bytes long
- *
- * @returns Operation status
- */
-static lr11xx_status_t lr11xx_lr_fhss_set_sync_word( const void* context,
- const uint8_t sync_word[LR11XX_LR_FHSS_SYNCWORD_LENGTH] );
-
/*!
* @brief Get the bit count and block count for a LR-FHSS frame
*
@@ -160,28 +107,36 @@ static uint16_t lr11xx_lr_fhss_get_nb_bits( const lr_fhss_v1_params_t* params, u
lr11xx_status_t lr11xx_lr_fhss_init( const void* context )
{
- const lr11xx_status_t set_packet_type_status =
- lr11xx_radio_set_pkt_type( context, LR11XX_LR_FHSS_PKT_TYPE_LR_FHSS );
+ const lr11xx_status_t set_packet_type_status = lr11xx_radio_set_pkt_type( context, LR11XX_RADIO_PKT_TYPE_LR_FHSS );
if( set_packet_type_status != LR11XX_STATUS_OK )
{
return set_packet_type_status;
}
- const lr11xx_lr_fhss_mod_params_lr_fhss_t mod_lr_fhss = {
- .br_in_bps = LR11XX_LR_FHSS_SET_MODULATION_PARAM_DIVIDE_BITRATE_BY_256 + LR_FHSS_BITRATE_IN_256_BPS_STEPS,
- .pulse_shape = LR11XX_LR_FHSS_PULSE_SHAPE_BT_1
+ const lr11xx_radio_mod_params_lr_fhss_t mod_lr_fhss = {
+ .br_in_bps = LR11XX_RADIO_LR_FHSS_BITRATE_488_BPS,
+ .pulse_shape = LR11XX_RADIO_LR_FHSS_PULSE_SHAPE_BT_1,
};
- const lr11xx_status_t set_modulation_param_status = lr11xx_lr_fhss_set_lr_fhss_mod_params( context, &mod_lr_fhss );
+ const lr11xx_status_t set_modulation_param_status = lr11xx_radio_set_lr_fhss_mod_params( context, &mod_lr_fhss );
return set_modulation_param_status;
}
+uint16_t lr11xx_lr_fhss_get_bit_delay_in_us( const lr11xx_lr_fhss_params_t* params, uint16_t payload_length )
+{
+ const uint16_t nb_bits = lr11xx_lr_fhss_get_nb_bits( &( params->lr_fhss_params ), payload_length );
+
+ const uint8_t nb_padding_bits = 1 + ( ( 32768 - nb_bits ) & 0x07 );
+
+ return 1600 + nb_padding_bits * 2048;
+}
+
lr11xx_status_t lr11xx_lr_fhss_build_frame( const void* context, const lr11xx_lr_fhss_params_t* lr_fhss_params,
uint16_t hop_sequence_id, const uint8_t* payload, uint8_t payload_length )
{
// Since the build_frame command is last, it is possible to check status through stat1
- lr11xx_status_t status = lr11xx_lr_fhss_set_sync_word( context, lr_fhss_params->lr_fhss_params.sync_word );
+ lr11xx_status_t status = lr11xx_radio_set_lr_fhss_sync_word( context, lr_fhss_params->lr_fhss_params.sync_word );
if( status != LR11XX_STATUS_OK )
{
return status;
@@ -228,35 +183,6 @@ unsigned int lr11xx_lr_fhss_get_hop_sequence_count( const lr11xx_lr_fhss_params_
* --- PRIVATE FUNCTIONS DEFINITION ---------------------------------------------
*/
-lr11xx_status_t lr11xx_lr_fhss_set_lr_fhss_mod_params( const void* radio,
- const lr11xx_lr_fhss_mod_params_lr_fhss_t* mod_params )
-{
- const uint8_t cbuffer[LR11XX_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH] = {
- ( uint8_t ) ( LR11XX_LR_FHSS_SET_MODULATION_PARAM_OC >> 8 ),
- ( uint8_t ) ( LR11XX_LR_FHSS_SET_MODULATION_PARAM_OC >> 0 ),
- ( uint8_t ) ( mod_params->br_in_bps >> 24 ),
- ( uint8_t ) ( mod_params->br_in_bps >> 16 ),
- ( uint8_t ) ( mod_params->br_in_bps >> 8 ),
- ( uint8_t ) ( mod_params->br_in_bps >> 0 ),
- ( uint8_t ) mod_params->pulse_shape,
- };
-
- return ( lr11xx_status_t ) lr11xx_hal_write( radio, cbuffer,
- LR11XX_LR_FHSS_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH, 0, 0 );
-}
-
-lr11xx_status_t lr11xx_lr_fhss_set_sync_word( const void* context,
- const uint8_t sync_word[LR11XX_LR_FHSS_SYNCWORD_LENGTH] )
-{
- const uint8_t cbuffer[LR11XX_LR_FHSS_SET_SYNC_WORD_LENGTH] = {
- ( uint8_t ) ( LR11XX_LR_FHSS_SET_SYNC_WORD_OC >> 8 ),
- ( uint8_t ) ( LR11XX_LR_FHSS_SET_SYNC_WORD_OC >> 0 ),
- };
-
- return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_LR_FHSS_SET_SYNC_WORD_LENGTH, sync_word,
- LR11XX_LR_FHSS_SYNCWORD_LENGTH );
-}
-
uint16_t lr11xx_lr_fhss_get_nb_bits( const lr_fhss_v1_params_t* params, uint16_t payload_length )
{
uint16_t length_bits = ( payload_length + 2 ) * 8 + 6;
@@ -287,4 +213,4 @@ uint16_t lr11xx_lr_fhss_get_nb_bits( const lr_fhss_v1_params_t* params, uint16_t
}
return LR11XX_LR_FHSS_HEADER_BITS * params->header_count + payload_bits;
-}
\ No newline at end of file
+}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.h
index 9a2711a..3b44f32 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_lr_fhss.h
@@ -81,10 +81,20 @@ extern "C" {
*/
lr11xx_status_t lr11xx_lr_fhss_init( const void* context );
+/**
+ * @brief Get the delay in microsecond between the last bit sent and the TX done interrupt
+ *
+ * @param [in] params lr11xx LR-FHSS parameter structure
+ * @param [in] payload_length Length of application-layer payload
+ *
+ * @returns Delay in microseconds
+ */
+uint16_t lr11xx_lr_fhss_get_bit_delay_in_us( const lr11xx_lr_fhss_params_t* params, uint16_t payload_length );
+
/*!
* @brief Configure a payload to be sent with LR_FHSS
*
- * When calling this method, lr11xx_lr_fhss_set_sync_word is implicitely called to configure the sync word.
+ * When calling this method, lr11xx_radio_set_lr_fhss_sync_word is implicitely called to configure the sync word.
* Note that the syncword must be 4 bytes long.
*
* @param [in] context Chip implementation context
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c
index e191510..2f408e0 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.c
@@ -68,6 +68,7 @@
#define LR11XX_RADIO_GET_RSSI_INST_CMD_LENGTH ( 2 )
#define LR11XX_RADIO_SET_GFSK_SYNC_WORD_CMD_LENGTH ( 2 + LR11XX_RADIO_GFSK_SYNC_WORD_LENGTH )
#define LR11XX_RADIO_SET_LORA_PUBLIC_NETWORK_CMD_LENGTH ( 2 + 8 )
+#define LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_LENGTH ( 2 + 0 )
#define LR11XX_RADIO_SET_RX_CMD_LENGTH ( 2 + 3 )
#define LR11XX_RADIO_SET_TX_CMD_LENGTH ( 2 + 3 )
#define LR11XX_RADIO_SET_RF_FREQUENCY_CMD_LENGTH ( 2 + 4 )
@@ -75,8 +76,11 @@
#define LR11XX_RADIO_SET_CAD_PARAMS_CMD_LENGTH ( 2 + 7 )
#define LR11XX_RADIO_SET_PKT_TYPE_CMD_LENGTH ( 2 + 1 )
#define LR11XX_RADIO_SET_MODULATION_PARAMS_GFSK_CMD_LENGTH ( 2 + 10 )
+#define LR11XX_RADIO_SET_MODULATION_PARAMS_BPSK_CMD_LENGTH ( 2 + 5 )
#define LR11XX_RADIO_SET_MODULATION_PARAMS_LORA_CMD_LENGTH ( 2 + 4 )
+#define LR11XX_RADIO_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH ( 2 + 5 )
#define LR11XX_RADIO_SET_PKT_PARAM_GFSK_CMD_LENGTH ( 2 + 9 )
+#define LR11XX_RADIO_SET_PKT_PARAM_BPSK_CMD_LENGTH ( 2 + 7 )
#define LR11XX_RADIO_SET_PKT_PARAM_LORA_CMD_LENGTH ( 2 + 6 )
#define LR11XX_RADIO_SET_TX_PARAMS_CMD_LENGTH ( 2 + 2 )
#define LR11XX_RADIO_SET_PKT_ADDRESS_CMD_LENGTH ( 2 + 2 )
@@ -88,12 +92,15 @@
#define LR11XX_RADIO_SET_TX_CW_CMD_LENGTH ( 2 )
#define LR11XX_RADIO_SET_TX_INFINITE_PREAMBLE_CMD_LENGTH ( 2 )
#define LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_CMD_LENGTH ( 2 + 1 )
+#define LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_EXT_CMD_LENGTH ( 2 + 2 )
#define LR11XX_RADIO_SET_GFSK_CRC_PARAMS_CMD_LENGTH ( 2 + 8 )
#define LR11XX_RADIO_SET_GFSK_WHITENING_CMD_LENGTH ( 2 + 2 )
#define LR11XX_RADIO_SET_RX_BOOSTED_LENGTH ( 2 + 1 )
#define LR11XX_RADIO_SET_RSSI_CALIBRATION_LENGTH ( 2 + 11 )
#define LR11XX_RADIO_SET_LORA_SYNC_WORD_CMD_LENGTH ( 2 + 1 )
#define LR11XX_RADIO_GET_LORA_RX_INFO_CMD_LENGTH ( 2 )
+#define LR11XX_RADIO_CFG_BLE_BEACON_CMD_LENGTH ( 2 + 1 )
+#define LR11XX_RADIO_BLE_BEACON_SEND_CMD_LENGTH ( 2 + 1 )
/**
* @brief Internal RTC frequency
@@ -141,7 +148,10 @@ enum
LR11XX_RADIO_SET_RX_BOOSTED_OC = 0x0227,
LR11XX_RADIO_SET_RSSI_CALIBRATION_OC = 0x0229,
LR11XX_RADIO_SET_LORA_SYNC_WORD_OC = 0x022B,
+ LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_OC = 0x022D,
+ LR11XX_RADIO_CFG_BLE_BEACON_OC = 0x022E,
LR11XX_RADIO_GET_LORA_RX_INFO_OC = 0x0230,
+ LR11XX_RADIO_BLE_BEACON_SEND_OC = 0x0231,
};
/*
@@ -380,6 +390,18 @@ lr11xx_status_t lr11xx_radio_set_lora_public_network( const void*
return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_LORA_SYNC_WORD_CMD_LENGTH, 0, 0 );
}
+lr11xx_status_t lr11xx_radio_set_lr_fhss_sync_word( const void* context,
+ const uint8_t sync_word[LR11XX_RADIO_LR_FHSS_SYNC_WORD_LENGTH] )
+{
+ const uint8_t cbuffer[LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_OC >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_LR_FHSS_SYNC_WORD_LENGTH, sync_word,
+ LR11XX_RADIO_LR_FHSS_SYNC_WORD_LENGTH );
+}
+
lr11xx_status_t lr11xx_radio_set_rx( const void* context, const uint32_t timeout_in_ms )
{
const uint32_t timeout_in_rtc_step = lr11xx_radio_convert_time_in_ms_to_rtc_step( timeout_in_ms );
@@ -534,6 +556,23 @@ lr11xx_status_t lr11xx_radio_set_gfsk_mod_params( const void*
0, 0 );
}
+lr11xx_status_t lr11xx_radio_set_bpsk_mod_params( const void* context,
+ const lr11xx_radio_mod_params_bpsk_t* mod_params )
+{
+ const uint8_t cbuffer[LR11XX_RADIO_SET_MODULATION_PARAMS_BPSK_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_SET_MODULATION_PARAM_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_SET_MODULATION_PARAM_OC >> 0 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 24 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 16 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 8 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 0 ),
+ ( uint8_t ) mod_params->pulse_shape,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_MODULATION_PARAMS_BPSK_CMD_LENGTH,
+ 0, 0 );
+}
+
lr11xx_status_t lr11xx_radio_set_lora_mod_params( const void* context,
const lr11xx_radio_mod_params_lora_t* mod_params )
{
@@ -550,6 +589,23 @@ lr11xx_status_t lr11xx_radio_set_lora_mod_params( const void*
0, 0 );
}
+lr11xx_status_t lr11xx_radio_set_lr_fhss_mod_params( const void* radio,
+ const lr11xx_radio_mod_params_lr_fhss_t* mod_params )
+{
+ const uint8_t cbuffer[LR11XX_RADIO_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_SET_MODULATION_PARAM_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_SET_MODULATION_PARAM_OC >> 0 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 24 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 16 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 8 ),
+ ( uint8_t ) ( mod_params->br_in_bps >> 0 ),
+ ( uint8_t ) mod_params->pulse_shape,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( radio, cbuffer, LR11XX_RADIO_SET_MODULATION_PARAMS_LR_FHSS_CMD_LENGTH,
+ 0, 0 );
+}
+
lr11xx_status_t lr11xx_radio_set_gfsk_pkt_params( const void* context,
const lr11xx_radio_pkt_params_gfsk_t* pkt_params )
{
@@ -570,6 +626,24 @@ lr11xx_status_t lr11xx_radio_set_gfsk_pkt_params( const void*
return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_PKT_PARAM_GFSK_CMD_LENGTH, 0, 0 );
}
+lr11xx_status_t lr11xx_radio_set_bpsk_pkt_params( const void* context,
+ const lr11xx_radio_pkt_params_bpsk_t* pkt_params )
+{
+ const uint8_t cbuffer[LR11XX_RADIO_SET_PKT_PARAM_BPSK_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_SET_PKT_PARAM_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_SET_PKT_PARAM_OC >> 0 ),
+ pkt_params->pld_len_in_bytes,
+ ( uint8_t ) ( pkt_params->ramp_up_delay >> 8 ),
+ ( uint8_t ) ( pkt_params->ramp_up_delay >> 0 ),
+ ( uint8_t ) ( pkt_params->ramp_down_delay >> 8 ),
+ ( uint8_t ) ( pkt_params->ramp_down_delay >> 0 ),
+ ( uint8_t ) ( pkt_params->pld_len_in_bits >> 8 ),
+ ( uint8_t ) ( pkt_params->pld_len_in_bits >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_PKT_PARAM_BPSK_CMD_LENGTH, 0, 0 );
+}
+
lr11xx_status_t lr11xx_radio_set_lora_pkt_params( const void* context,
const lr11xx_radio_pkt_params_lora_t* pkt_params )
{
@@ -747,15 +821,46 @@ lr11xx_status_t lr11xx_radio_set_tx_infinite_preamble( const void* context )
return status;
}
-lr11xx_status_t lr11xx_radio_set_lora_sync_timeout( const void* context, const uint8_t nb_symbol )
+lr11xx_status_t lr11xx_radio_set_lora_sync_timeout( const void* context, const uint16_t nb_symbol )
+{
+ if( nb_symbol <= 255 )
+ {
+ const uint8_t cbuffer[LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_OC >> 0 ),
+ nb_symbol,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_CMD_LENGTH, 0,
+ 0 );
+ }
+ else
+ {
+ uint8_t exp;
+ uint8_t mant;
+
+ lr11xx_radio_convert_nb_symb_to_mant_exp( nb_symbol, &mant, &exp );
+
+ return lr11xx_radio_set_lora_sync_timeout_with_mantissa_exponent( context, mant, exp );
+ }
+}
+
+lr11xx_status_t lr11xx_radio_set_lora_sync_timeout_with_mantissa_exponent( const void* context, const uint8_t mantissa,
+ const uint8_t exponent )
{
- const uint8_t cbuffer[LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_CMD_LENGTH] = {
+ const uint8_t cbuffer[LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_EXT_CMD_LENGTH] = {
( uint8_t ) ( LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_OC >> 8 ),
( uint8_t ) ( LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_OC >> 0 ),
- nb_symbol,
+ mantissa << 3 | exponent,
+ 0x01,
};
- return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_CMD_LENGTH, 0,
+ if( ( mantissa > 31 ) || ( exponent > 7 ) )
+ {
+ return LR11XX_STATUS_ERROR;
+ }
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RADIO_SET_LORA_SYNC_TIMEOUT_EXT_CMD_LENGTH, 0,
0 );
}
@@ -1115,6 +1220,19 @@ uint32_t lr11xx_radio_convert_time_in_ms_to_rtc_step( uint32_t time_in_ms )
return ( uint32_t ) ( time_in_ms * LR11XX_RTC_FREQ_IN_HZ / 1000 );
}
+lr11xx_status_t lr11xx_radio_cfg_ble_beacon( const void* context, const uint8_t channel_id, const uint8_t* buffer,
+ const uint8_t length )
+{
+ const uint8_t command[LR11XX_RADIO_CFG_BLE_BEACON_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_CFG_BLE_BEACON_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_CFG_BLE_BEACON_OC >> 0 ),
+ channel_id,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, command, LR11XX_RADIO_CFG_BLE_BEACON_CMD_LENGTH, buffer,
+ length );
+}
+
lr11xx_status_t lr11xx_radio_get_lora_rx_info( const void* context, bool* is_crc_present, lr11xx_radio_lora_cr_t* cr )
{
const uint8_t cbuffer[LR11XX_RADIO_GET_LORA_RX_INFO_CMD_LENGTH] = {
@@ -1135,11 +1253,41 @@ lr11xx_status_t lr11xx_radio_get_lora_rx_info( const void* context, bool* is_crc
return status;
}
+lr11xx_status_t lr11xx_radio_cfg_and_send_ble_beacon( const void* context, const uint8_t channel_id, const uint8_t* buffer,
+ const uint8_t length )
+{
+ const uint8_t command[LR11XX_RADIO_BLE_BEACON_SEND_CMD_LENGTH] = {
+ ( uint8_t ) ( LR11XX_RADIO_BLE_BEACON_SEND_OC >> 8 ),
+ ( uint8_t ) ( LR11XX_RADIO_BLE_BEACON_SEND_OC >> 0 ),
+ channel_id,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, command, LR11XX_RADIO_BLE_BEACON_SEND_CMD_LENGTH, buffer,
+ length );
+}
+
lr11xx_status_t lr11xx_radio_apply_high_acp_workaround( const void* context )
{
return lr11xx_regmem_write_regmem32_mask( context, 0x00F30054, 1 << 30, 0 << 30 );
}
+uint16_t lr11xx_radio_convert_nb_symb_to_mant_exp( const uint16_t nb_symbol, uint8_t* mant, uint8_t* exp )
+{
+ uint8_t exp_loc = 0;
+ uint16_t mant_loc = ( nb_symbol + 1 ) >> 1;
+
+ while( mant_loc > 31 )
+ {
+ mant_loc = ( mant_loc + 3 ) >> 2;
+ exp_loc++;
+ }
+
+ *mant = ( uint8_t ) mant_loc;
+ *exp = exp_loc;
+
+ return mant_loc << ( 2 * exp_loc + 1 );
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.h
index bcf2b0f..28a9657 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio.h
@@ -70,6 +70,35 @@ extern "C" {
0x97, 0x23, 0x52, 0x25, 0x56, 0x53, 0x65, 0x64 \
}
+/*!
+ * @brief Length in byte of the LR-FHSS sync word
+ */
+#define LR11XX_RADIO_LR_FHSS_SYNC_WORD_LENGTH ( 4 )
+
+/*!
+ * @brief Ramp-up delay for the power amplifier in Sigfox context
+ *
+ * This parameter configures the delay to fine tune the ramp-up time of the power amplifier for BPSK operation.
+ */
+enum
+{
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_UP_TIME_DEFAULT = 0x0000, //!< No optimization
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_UP_TIME_100_BPS = 0x1306, //!< Ramp-up optimization for 100bps
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_UP_TIME_600_BPS = 0x0325, //!< Ramp-up optimization for 600bps
+};
+
+/*!
+ * @brief Ramp-down delay for the power amplifier in Sigfox context
+ *
+ * This parameter configures the delay to fine tune the ramp-down time of the power amplifier for BPSK operation.
+ */
+enum
+{
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_DOWN_TIME_DEFAULT = 0x0000, //!< No optimization
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_DOWN_TIME_100_BPS = 0x1D70, //!< Ramp-down optimization for 100bps
+ LR11XX_RADIO_SIGFOX_DBPSK_RAMP_DOWN_TIME_600_BPS = 0x04E1, //!< Ramp-down optimization for 600bps
+};
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC TYPES ------------------------------------------------------------
@@ -205,6 +234,19 @@ lr11xx_status_t lr11xx_radio_set_gfsk_sync_word( const void* context,
*/
lr11xx_status_t lr11xx_radio_set_lora_sync_word( const void* context, const uint8_t sync_word );
+/*!
+ * @brief Set the syncword for LR-FHSS
+ *
+ * Default value: 0x2C0F7995
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] sync_word The syncword to set. It is up to the caller to ensure this array is at least four bytes long
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_radio_set_lr_fhss_sync_word( const void* context,
+ const uint8_t sync_word[LR11XX_RADIO_LR_FHSS_SYNC_WORD_LENGTH] );
+
/*!
* @brief Set the LoRa modem sync word to private / public
*
@@ -398,6 +440,21 @@ lr11xx_status_t lr11xx_radio_set_pkt_type( const void* context, const lr11xx_rad
lr11xx_status_t lr11xx_radio_set_gfsk_mod_params( const void* context,
const lr11xx_radio_mod_params_gfsk_t* mod_params );
+/*!
+ * @brief Set the modulation parameters for BPSK packets
+ *
+ * The command @ref lr11xx_radio_set_pkt_type must be called prior this one.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] mod_params The structure of modulation configuration
+ *
+ * @returns Operation status
+ *
+ * @see lr11xx_radio_set_pkt_type
+ */
+lr11xx_status_t lr11xx_radio_set_bpsk_mod_params( const void* context,
+ const lr11xx_radio_mod_params_bpsk_t* mod_params );
+
/*!
* @brief Set the modulation parameters for LoRa packets
*
@@ -413,6 +470,21 @@ lr11xx_status_t lr11xx_radio_set_gfsk_mod_params( const void*
lr11xx_status_t lr11xx_radio_set_lora_mod_params( const void* context,
const lr11xx_radio_mod_params_lora_t* mod_params );
+/*!
+ * @brief Set the modulation parameters for LR-FHSS
+ *
+ * The command @ref lr11xx_radio_set_pkt_type must be called prior this one.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] mod_params The structure of modulation configuration
+ *
+ * @returns Operation status
+ *
+ * @see lr11xx_lr_fhss_set_pkt_type
+ */
+lr11xx_status_t lr11xx_radio_set_lr_fhss_mod_params( const void* context,
+ const lr11xx_radio_mod_params_lr_fhss_t* mod_params );
+
/*!
* @brief Set the packet parameters for GFSK packets
*
@@ -428,6 +500,21 @@ lr11xx_status_t lr11xx_radio_set_lora_mod_params( const void*
lr11xx_status_t lr11xx_radio_set_gfsk_pkt_params( const void* context,
const lr11xx_radio_pkt_params_gfsk_t* pkt_params );
+/*!
+ * @brief Set the packet parameters for BPSK packets
+ *
+ * The command @ref lr11xx_radio_set_pkt_type must be called prior this one.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] pkt_params The structure of packet configuration
+ *
+ * @returns Operation status
+ *
+ * @see lr11xx_radio_set_pkt_type, lr11xx_radio_set_bpsk_mod_params
+ */
+lr11xx_status_t lr11xx_radio_set_bpsk_pkt_params( const void* context,
+ const lr11xx_radio_pkt_params_bpsk_t* pkt_params );
+
/*!
* @brief Set the packet parameters for LoRa packets
*
@@ -619,12 +706,31 @@ lr11xx_status_t lr11xx_radio_set_tx_infinite_preamble( const void* context );
* @brief Configure the LoRa modem to issue a RX timeout after an exact number of symbols given in parameter if no LoRa
* modulation is detected
*
+ * @warning Values of nb_symbol higher than 255 are only valid for chip firmware equal to or more recent than 0x308.
+ *
* @param [in] context Chip implementation context
* @param [in] nb_symbol number of symbols to compute the timeout
*
* @returns Operation status
*/
-lr11xx_status_t lr11xx_radio_set_lora_sync_timeout( const void* context, const uint8_t nb_symbol );
+lr11xx_status_t lr11xx_radio_set_lora_sync_timeout( const void* context, const uint16_t nb_symbol );
+
+/*!
+ * @brief Configure the LoRa modem to issue a RX timeout after an exact number of symbols given in parameter if no LoRa
+ * modulation is detected
+ *
+ * @warning This command has been introduced in chip firware 0x0308 and is not available in earlier version
+ *
+ * @remark The number of symbol is computed as mantissa ^ (2*exponent + 1)
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] mantissa Mantissa - from 0 to 31 - to compute the number of symbols of the timeout
+ * @param [in] exponent Exponent - from 0 to 7 - to compute the number of symbols of the timeout
+ *
+ * @returns Operation status
+ */
+lr11xx_status_t lr11xx_radio_set_lora_sync_timeout_with_mantissa_exponent( const void* context, const uint8_t mantissa,
+ const uint8_t exponent );
/*!
* @brief Configure the seed and the polynomial used to compute CRC in GFSK packet
@@ -743,6 +849,36 @@ uint32_t lr11xx_radio_get_gfsk_time_on_air_in_ms( const lr11xx_radio_pkt_params_
*/
uint32_t lr11xx_radio_convert_time_in_ms_to_rtc_step( uint32_t time_in_ms );
+/*!
+ * @brief Configure the radio for BLE beaconing.
+ *
+ * The caller shall ensure that the payload, if provided, follows the format of the Advertising physical channel PDU as defined in the
+ * Bluetooth core specification.
+ *
+ * This automatically configures the syncword to 0x8e89bed6 and the 3-byte CRC (polynomial set to 0x100065b, seed set to
+ * 0x555555).
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] channel_id BLE channel - allowed channels are 37, 38, 39
+ * @param [in] buffer Array of bytes to be used as beacon payload (optional)
+ * @param [in] length Number of bytes in the @ref buffer array
+ *
+ * @returns Operation status
+ *
+ * @note As opposed to the function @ref lr11xx_radio_cfg_and_send_ble_beacon, this function only configures the radio
+ * interface for BLE beacon advertising. To actually start the transmission, the function @ref lr11xx_radio_set_tx must
+ * be called.
+ * @note The previously configured payload with @ref lr11xx_radio_cfg_ble_beacon or @ref
+ * lr11xx_radio_cfg_and_send_ble_beacon is sent if @p length is set to 0, except if a call to @ref
+ * lr11xx_regmem_write_buffer8, @ref lr11xx_lr_fhss_build_frame is done in between or @ref lr11xx_system_set_sleep with
+ * warm start disabled
+ *
+ * @sa lr11xx_radio_cfg_and_send_ble_beacon
+ * @sa lr11xx_radio_set_tx
+ */
+lr11xx_status_t lr11xx_radio_cfg_ble_beacon( const void* context, const uint8_t channel_id, const uint8_t* buffer,
+ const uint8_t length );
+
/**
* @brief Get the information from the last received LoRa packet header (if @ref LR11XX_RADIO_LORA_PKT_EXPLICIT) or the
* locally configured settings (if @ref LR11XX_RADIO_LORA_PKT_IMPLICIT)
@@ -758,6 +894,34 @@ uint32_t lr11xx_radio_convert_time_in_ms_to_rtc_step( uint32_t time_in_ms );
*/
lr11xx_status_t lr11xx_radio_get_lora_rx_info( const void* context, bool* is_crc_present, lr11xx_radio_lora_cr_t* cr );
+/*!
+ * @brief Configure the radio for BLE and send the given beacon on the desired channel.
+ *
+ * The caller shall ensure that the payload, if provided, follows the format of the Advertising physical channel PDU as defined in the
+ * Bluetooth core specification.
+ *
+ * This automatically configures the syncword to 0x8e89bed6 and the 3-byte CRC (polynomial set to 0x100065b, seed set to
+ * 0x555555).
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] channel_id BLE channel - allowed channels are 37, 38, 39
+ * @param [in] buffer Array of bytes to be used as beacon payload (optional)
+ * @param [in] length Number of bytes in the @ref buffer array
+ *
+ * @returns Operation status
+ *
+ * @note This function combines the configuration for BLE beaconing - done with @ref lr11xx_radio_cfg_ble_beacon) -
+ * and the actual transmission - done with @ref lr11xx_radio_set_tx.
+ * @note The previously configured payload with @ref lr11xx_radio_cfg_ble_beacon or @ref
+ * lr11xx_radio_cfg_and_send_ble_beacon is sent if @p length is set to 0, except if a call to @ref
+ * lr11xx_regmem_write_buffer8, @ref lr11xx_lr_fhss_build_frame is done in between or @ref lr11xx_system_set_sleep with
+ * warm start disabled
+ *
+ * @sa lr11xx_radio_cfg_ble_beacon
+ */
+lr11xx_status_t lr11xx_radio_cfg_and_send_ble_beacon( const void* context, const uint8_t channel_id,
+ const uint8_t* buffer, const uint8_t length );
+
/*!
* @brief Apply the workaround for the high ACP limitation
*
@@ -767,6 +931,23 @@ lr11xx_status_t lr11xx_radio_get_lora_rx_info( const void* context, bool* is_crc
*/
lr11xx_status_t lr11xx_radio_apply_high_acp_workaround( const void* context );
+/**
+ * @brief Get the mantissa and exponent for a given number of symbol
+ *
+ * @remark This function computes the [mantissa, exponent] duple which corresponds to nb_of_symb: the smallest
+ * value verifying both following conditions:
+ * - nb_of_symb >= nb_symbol; and
+ * - nb_of_symb = mant * 2 ^ (2 * exp + 1)
+ *
+ * @param [in] nb_symbol Number of symbols
+ * @param [out] mant Mantissa computed from nb_symb
+ * @param [out] ext Exponent computed from nb_symb
+ *
+ * @returns Number of symbols corresponding to the [mantissa, exponent] duple computed with the following formula:
+ * nb_of_symb = mant * 2 ^ (2 * exp + 1)
+ */
+uint16_t lr11xx_radio_convert_nb_symb_to_mant_exp( const uint16_t nb_symbol, uint8_t* mant, uint8_t* exp );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h
index 6f5c58d..857d674 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_radio_types.h
@@ -52,6 +52,16 @@ extern "C" {
* --- PUBLIC MACROS -----------------------------------------------------------
*/
+/*!
+ * @brief Bit mask to set to indicate a LR-FHSS bitrate is defined in steps of 1/256 bit per seconds
+ */
+#define LR11XX_RADIO_LR_FHSS_BITRATE_DIVIDE_BY_256 ( 0x80000000 )
+
+/*!
+ * @brief LR-FHSS bitrate value at 488.28125 bps defined as steps of 1/256 bitrate per seconds
+ */
+#define LR11XX_RADIO_LR_FHSS_BITRATE_IN_256_BPS_STEPS ( 125000 )
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC CONSTANTS --------------------------------------------------------
@@ -293,9 +303,12 @@ typedef enum
*/
typedef enum
{
- LR11XX_RADIO_PKT_NONE = 0x00, //!< State after cold start, Wi-Fi or GNSS capture
- LR11XX_RADIO_PKT_TYPE_GFSK = 0x01, //!< GFSK modulation
- LR11XX_RADIO_PKT_TYPE_LORA = 0x02, //!< LoRa modulation
+ LR11XX_RADIO_PKT_NONE = 0x00, //!< State after cold start, Wi-Fi or GNSS capture
+ LR11XX_RADIO_PKT_TYPE_GFSK = 0x01, //!< GFSK modulation
+ LR11XX_RADIO_PKT_TYPE_LORA = 0x02, //!< LoRa modulation
+ LR11XX_RADIO_PKT_TYPE_BPSK = 0x03, //!< BPSK modulation
+ LR11XX_RADIO_PKT_TYPE_LR_FHSS = 0x04, //!< LR-FHSS modulation
+ LR11XX_RADIO_PKT_TYPE_RANGING = 0x05, //!< Ranging packet
} lr11xx_radio_pkt_type_t;
/*!
@@ -376,6 +389,32 @@ typedef enum
LR11XX_RADIO_GFSK_PULSE_SHAPE_BT_1 = 0x0B //!< Gaussian BT 1.0
} lr11xx_radio_gfsk_pulse_shape_t;
+/*!
+ * @brief BPSK pulse shape configurations
+ */
+typedef enum
+{
+ LR11XX_RADIO_DBPSK_PULSE_SHAPE = 0x16, //!< Double OSR / RRC / BT 0.7
+} lr11xx_radio_bpsk_pulse_shape_t;
+
+/*!
+ * @brief LR-FHSS bitrate configurations
+ */
+typedef enum
+{
+ LR11XX_RADIO_LR_FHSS_BITRATE_488_BPS =
+ ( int ) ( LR11XX_RADIO_LR_FHSS_BITRATE_DIVIDE_BY_256 +
+ LR11XX_RADIO_LR_FHSS_BITRATE_IN_256_BPS_STEPS ), //!< 488.28215 bps
+} lr11xx_radio_lr_fhss_bitrate_t;
+
+/*!
+ * @brief LR-FHSS pulse shape configurations
+ */
+typedef enum
+{
+ LR11XX_RADIO_LR_FHSS_PULSE_SHAPE_BT_1 = 0x0B //!< Gaussian BT 1.0
+} lr11xx_radio_lr_fhss_pulse_shape_t;
+
/*!
* @brief Channel Activity Detection parameters
*
@@ -469,6 +508,15 @@ typedef struct lr11xx_radio_mod_params_gfsk_s
uint32_t fdev_in_hz; //!< GFSK frequency deviation [Hz]
} lr11xx_radio_mod_params_gfsk_t;
+/*!
+ * @brief Modulation configuration for BPSK packet
+ */
+typedef struct lr11xx_radio_mod_params_bpsk_s
+{
+ uint32_t br_in_bps; //!< BPSK bitrate [bit/s]
+ lr11xx_radio_bpsk_pulse_shape_t pulse_shape; //!< BPSK pulse shape
+} lr11xx_radio_mod_params_bpsk_t;
+
/*!
* @brief Modulation configuration for LoRa packet
*/
@@ -480,6 +528,15 @@ typedef struct lr11xx_radio_mod_params_lora_s
uint8_t ldro; //!< LoRa LDRO
} lr11xx_radio_mod_params_lora_t;
+/*!
+ * @brief Modulation configuration for LR-FHSS packets
+ */
+typedef struct lr11xx_radio_mod_params_lr_fhss_s
+{
+ lr11xx_radio_lr_fhss_bitrate_t br_in_bps; //!< LR-FHSS bitrate
+ lr11xx_radio_lr_fhss_pulse_shape_t pulse_shape; //!< LR-FHSS pulse shape
+} lr11xx_radio_mod_params_lr_fhss_t;
+
/*!
* @brief Packet parameter configuration for GFSK packets
*/
@@ -495,6 +552,18 @@ typedef struct lr11xx_radio_pkt_params_gfsk_s
lr11xx_radio_gfsk_dc_free_t dc_free; //!< GFSK Whitening configuration
} lr11xx_radio_pkt_params_gfsk_t;
+/*!
+ * @brief Packet parameter configuration for BPSK packets
+ */
+typedef struct lr11xx_radio_pkt_params_bpsk_s
+{
+ uint8_t pld_len_in_bytes; //!< Payload length [bytes]
+ uint16_t ramp_up_delay; //!< Delay to fine tune ramp-up time, if non-zero
+ uint16_t ramp_down_delay; //!< Delay to fine tune ramp-down time, if non-zero
+ uint16_t pld_len_in_bits; //!< If non-zero, used to ramp down PA before end of a payload with length that is not a
+ //!< multiple of 8. pld_len_in_bits <= pld_len_in_bytes * 8
+} lr11xx_radio_pkt_params_bpsk_t;
+
/*!
* @brief Packet parameter configuration for LoRa packets
*/
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.c
new file mode 100644
index 0000000..201ce53
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.c
@@ -0,0 +1,340 @@
+/**
+ * @file lr11xx_ranging.c
+ *
+ * @brief Ranging driver implementation for LR11XX
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2022. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+#include
+#include "lr11xx_ranging.h"
+#include "lr11xx_hal.h"
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE MACROS-----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE CONSTANTS -------------------------------------------------------
+ */
+
+#define LR11XX_RANGING_SET_ADDRESS_CMD_LENGTH ( 2 + 5 )
+#define LR11XX_RANGING_SET_REQUEST_ADDRESS_CMD_LENGTH ( 2 + 4 )
+#define LR11XX_RANGING_SET_RX_TX_DELAY_CMD_LENGTH ( 2 + 4 )
+#define LR11XX_RANGING_SET_PARAMETERS_CMD_LENGTH ( 2 + 2 )
+#define LR11XX_RANGING_GET_RESULT_CMD_LENGTH ( 2 + 1 )
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE TYPES -----------------------------------------------------------
+ */
+
+/**
+ * @brief Operating codes for ranging-related operations
+ */
+enum
+{
+ LR11XX_RANGING_SET_ADDRESS = 0x021C,
+ LR11XX_RANGING_SET_REQUEST_ADDRESS = 0x021D,
+ LR11XX_RANGING_SET_RX_TX_DELAY = 0x021F,
+ LR11XX_RANGING_SET_PARAMETERS = 0x0228,
+ LR11XX_RANGING_GET_RESULT = 0x021E,
+};
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE VARIABLES -------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE FUNCTION DECLARATIONS -------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTION DEFINITIONS ---------------------------------------------
+ */
+
+lr11xx_status_t lr11xx_ranging_set_address( const void* context, const uint32_t address, const uint8_t check_length )
+{
+ const uint8_t cbuffer[LR11XX_RANGING_SET_ADDRESS_CMD_LENGTH] = {
+ ( uint8_t )( LR11XX_RANGING_SET_ADDRESS >> 8 ),
+ ( uint8_t )( LR11XX_RANGING_SET_ADDRESS >> 0 ),
+ ( uint8_t )( address >> 24 ),
+ ( uint8_t )( address >> 16 ),
+ ( uint8_t )( address >> 8 ),
+ ( uint8_t )( address >> 0 ),
+ check_length,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RANGING_SET_ADDRESS_CMD_LENGTH, 0, 0 );
+}
+
+lr11xx_status_t lr11xx_ranging_set_request_address( const void* context, const uint32_t request_address )
+{
+ const uint8_t cbuffer[LR11XX_RANGING_SET_REQUEST_ADDRESS_CMD_LENGTH] = {
+ ( uint8_t )( LR11XX_RANGING_SET_REQUEST_ADDRESS >> 8 ),
+ ( uint8_t )( LR11XX_RANGING_SET_REQUEST_ADDRESS >> 0 ),
+ ( uint8_t )( request_address >> 24 ),
+ ( uint8_t )( request_address >> 16 ),
+ ( uint8_t )( request_address >> 8 ),
+ ( uint8_t )( request_address >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RANGING_SET_REQUEST_ADDRESS_CMD_LENGTH, 0,
+ 0 );
+}
+
+lr11xx_status_t lr11xx_ranging_set_rx_tx_delay_indicator( const void* context, const uint32_t delay_indicator )
+{
+ const uint8_t cbuffer[LR11XX_RANGING_SET_RX_TX_DELAY_CMD_LENGTH] = {
+ ( uint8_t )( LR11XX_RANGING_SET_RX_TX_DELAY >> 8 ),
+ ( uint8_t )( LR11XX_RANGING_SET_RX_TX_DELAY >> 0 ),
+ ( uint8_t )( delay_indicator >> 24 ),
+ ( uint8_t )( delay_indicator >> 16 ),
+ ( uint8_t )( delay_indicator >> 8 ),
+ ( uint8_t )( delay_indicator >> 0 ),
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RANGING_SET_RX_TX_DELAY_CMD_LENGTH, 0, 0 );
+}
+
+lr11xx_status_t lr11xx_ranging_set_parameters( const void* context, const uint8_t nb_symbols )
+{
+ const uint8_t cbuffer[LR11XX_RANGING_SET_PARAMETERS_CMD_LENGTH] = {
+ ( uint8_t )( LR11XX_RANGING_SET_PARAMETERS >> 8 ), ( uint8_t )( LR11XX_RANGING_SET_PARAMETERS >> 0 ), 0x00,
+ nb_symbols
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_write( context, cbuffer, LR11XX_RANGING_SET_PARAMETERS_CMD_LENGTH, 0, 0 );
+}
+
+lr11xx_status_t lr11xx_ranging_get_raw_result( const void* context, const lr11xx_ranging_result_type_t type,
+ uint8_t result[LR11XX_RANGING_RESULT_LENGTH] )
+{
+ const uint8_t cbuffer[LR11XX_RANGING_GET_RESULT_CMD_LENGTH] = {
+ ( uint8_t )( LR11XX_RANGING_GET_RESULT >> 8 ),
+ ( uint8_t )( LR11XX_RANGING_GET_RESULT >> 0 ),
+ ( uint8_t ) type,
+ };
+
+ return ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer, LR11XX_RANGING_GET_RESULT_CMD_LENGTH, result,
+ LR11XX_RANGING_RESULT_LENGTH );
+}
+
+lr11xx_status_t lr11xx_ranging_get_recommended_rx_tx_delay_indicator( lr11xx_radio_lora_bw_t bw,
+ lr11xx_radio_lora_sf_t sf,
+ uint32_t* delay_indicator )
+{
+ lr11xx_status_t status = LR11XX_STATUS_OK;
+
+ *delay_indicator = 0u;
+
+ if( bw == LR11XX_RADIO_LORA_BW_500 )
+ {
+ if( sf == LR11XX_RADIO_LORA_SF5 )
+ {
+ *delay_indicator = 20149u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF6 )
+ {
+ *delay_indicator = 20227u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF7 )
+ {
+ *delay_indicator = 20258u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF8 )
+ {
+ *delay_indicator = 20277u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF9 )
+ {
+ *delay_indicator = 20286u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF10 )
+ {
+ *delay_indicator = 20292u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF11 )
+ {
+ *delay_indicator = 20295u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF12 )
+ {
+ *delay_indicator = 20298u;
+ }
+ else
+ {
+ status = LR11XX_STATUS_ERROR;
+ }
+ }
+ else if( bw == LR11XX_RADIO_LORA_BW_250 )
+ {
+ if( sf == LR11XX_RADIO_LORA_SF5 )
+ {
+ *delay_indicator = 20235u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF6 )
+ {
+ *delay_indicator = 20239u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF7 )
+ {
+ *delay_indicator = 20238u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF8 )
+ {
+ *delay_indicator = 20237u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF9 )
+ {
+ *delay_indicator = 20236u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF10 )
+ {
+ *delay_indicator = 20235u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF11 )
+ {
+ *delay_indicator = 20236u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF12 )
+ {
+ *delay_indicator = 20232u;
+ }
+ else
+ {
+ status = LR11XX_STATUS_ERROR;
+ }
+ }
+ else if( bw == LR11XX_RADIO_LORA_BW_125 )
+ {
+ if( sf == LR11XX_RADIO_LORA_SF5 )
+ {
+ *delay_indicator = 19035u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF6 )
+ {
+ *delay_indicator = 19040u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF7 )
+ {
+ *delay_indicator = 19040u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF8 )
+ {
+ *delay_indicator = 19039u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF9 )
+ {
+ *delay_indicator = 19036u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF10 )
+ {
+ *delay_indicator = 19038u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF11 )
+ {
+ *delay_indicator = 19036u;
+ }
+ else if( sf == LR11XX_RADIO_LORA_SF12 )
+ {
+ *delay_indicator = 19024u;
+ }
+ else
+ {
+ status = LR11XX_STATUS_ERROR;
+ }
+ }
+ else
+ {
+ status = LR11XX_STATUS_ERROR;
+ }
+ return status;
+}
+
+lr11xx_status_t lr11xx_ranging_set_recommended_rx_tx_delay_indicator( const void* context, lr11xx_radio_lora_bw_t bw,
+ lr11xx_radio_lora_sf_t sf )
+{
+ uint32_t delay_indicator = 0;
+ lr11xx_status_t status = lr11xx_ranging_get_recommended_rx_tx_delay_indicator( bw, sf, &delay_indicator );
+ if( status == LR11XX_STATUS_OK )
+ {
+ status = lr11xx_ranging_set_rx_tx_delay_indicator( context, delay_indicator );
+ }
+ return status;
+}
+
+int32_t lr11xx_ranging_distance_raw_to_meter( lr11xx_radio_lora_bw_t ranging_bw,
+ const uint8_t raw_distance_buf[LR11XX_RANGING_RESULT_LENGTH] )
+{
+ const uint8_t bitcnt = 24u;
+ uint8_t bw_scaling = 0u;
+
+ const uint32_t raw_distance =
+ ( ( uint32_t ) raw_distance_buf[3] << 0 ) + ( ( uint32_t ) raw_distance_buf[2] << 8 ) +
+ ( ( uint32_t ) raw_distance_buf[1] << 16 ) + ( ( uint32_t ) raw_distance_buf[0] << 24 );
+
+ if( ranging_bw == LR11XX_RADIO_LORA_BW_500 )
+ {
+ bw_scaling = 1u;
+ }
+ else if( ranging_bw == LR11XX_RADIO_LORA_BW_250 )
+ {
+ bw_scaling = 2u;
+ }
+ else if( ranging_bw == LR11XX_RADIO_LORA_BW_125 )
+ {
+ bw_scaling = 4u;
+ }
+
+ int32_t retval = raw_distance;
+ if( raw_distance >= ( 1 << ( bitcnt - 1 ) ) )
+ {
+ retval -= ( 1 << bitcnt );
+ }
+
+ return 300 * bw_scaling * retval / 4096;
+}
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE FUNCTION DEFINITIONS --------------------------------------------
+ */
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.h
new file mode 100644
index 0000000..f5940e2
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging.h
@@ -0,0 +1,234 @@
+/**
+ * @file lr11xx_ranging.h
+ *
+ * @brief Ranging driver definition for LR11XX
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2022. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LR11XX_RANGING_H
+#define LR11XX_RANGING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+#include
+#include "lr11xx_ranging_types.h"
+#include "lr11xx_radio_types.h"
+#include "lr11xx_types.h"
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC MACROS -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC CONSTANTS --------------------------------------------------------
+ */
+
+/**
+ * @brief Length in byte of the ranging result
+ */
+#define LR11XX_RANGING_RESULT_LENGTH ( 4 )
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC TYPES ------------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTION PROTOTYPES ---------------------------------------------
+ */
+
+/**
+ * @brief Set the ranging address for this subordinate device.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] address 32-bit subordinate address (default is 0x00000019)
+ * @param [in] check_length Number of bytes to be checked when comparing the device's
+ * address with request address value contained in received
+ * ranging frames (valid range 1..4, default is 4)
+ *
+ * @returns Operation status
+ *
+ * @note The address set by this function is only used in subordinate mode, that is,
+ * when receiving ranging requests. While processing received request packets,
+ * the ranging subordinate compares @p check_length bytes (LSB first) of
+ * the request address with its own address. Packets with non-matching request
+ * addresses are discarded.
+ */
+lr11xx_status_t lr11xx_ranging_set_address( const void* context, const uint32_t address, const uint8_t check_length );
+
+/**
+ * @brief Set the ranging address used for requests sent in manager mode.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] request_address 32-bit request address (default is 0x00000019)
+ *
+ * @returns Operation status
+ *
+ * @note The request address set by this function is only used in manager mode,
+ * that is, when sending ranging requests. The @p request_address is copied
+ * into the corresponding field in the next ranging request sent.
+ */
+lr11xx_status_t lr11xx_ranging_set_request_address( const void* context, const uint32_t request_address );
+
+/**
+ * @brief Set the transceiver RX/TX delay indicator to be compensated during ranging.
+ *
+ * The transceiver hardware induces a delay depending on the physical layer
+ * configuration (bandwidth, spreading factor). To achieve the desired ranging
+ * accuracy, this delay needs to be compensated by a calibration value.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] delay_indicator Delay value corresponding to the used bandwidth and spreading factor
+ *
+ * @returns lr11xx_status_t Operation status
+ *
+ * @note The same delay_indicator value needs to be configured in both manager and subordinate devices.
+ */
+lr11xx_status_t lr11xx_ranging_set_rx_tx_delay_indicator( const void* context, const uint32_t delay_indicator );
+
+/**
+ * @brief Configure ranging specific parameters.
+ *
+ * It is recommended to always call this command when configuring the ranging operation with @p nb_symbols = 15.
+ * This value balances the ranging accuracy and power consumption.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] nb_symbols Number of symbols contained in responses sent by subordinates
+ *
+ * @returns lr11xx_status_t Operation status
+ *
+ * @note The ranging parameters need to be configured in both manager and subordinate devices.
+ */
+lr11xx_status_t lr11xx_ranging_set_parameters( const void* context, const uint8_t nb_symbols );
+
+/**
+ * @brief Get the ranging result on the manager device.
+ *
+ * Retrieve the ranging result item corresponding to the given item type @p type.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] type Result item type to be retrieved
+ * @param [out] result Result data buffer
+ *
+ * @returns lr11xx_status_t Operation status
+ *
+ * @note This function is only available on devices in manager mode after
+ * the ranging is terminated.
+ */
+lr11xx_status_t lr11xx_ranging_get_raw_result( const void* context, const lr11xx_ranging_result_type_t type,
+ uint8_t result[LR11XX_RANGING_RESULT_LENGTH] );
+
+/**
+ * @brief Get the recommended hardware delay indicator on ranging TX/RX.
+ *
+ * @param [in] bw LoRa bandwidth used for ranging
+ * @param [in] sf LoRa spreading factor used for ranging
+ * @param [out] delay_indicator Recommended hardware delay indicator for the given physical layer configuration
+ *
+ * @returns Operation status
+ * @retval LR11XX_STATUS_OK on success
+ * @retval LR11XX_STATUS_ERROR if the given physical layer configuration is invalid
+ */
+lr11xx_status_t lr11xx_ranging_get_recommended_rx_tx_delay_indicator( lr11xx_radio_lora_bw_t bw,
+ lr11xx_radio_lora_sf_t sf,
+ uint32_t* delay_indicator );
+
+/**
+ * @brief Set recommended hardware delay indicator on ranging TX/RX for SF/BW.
+ *
+ * This helper function calls first @p lr11xx_ranging_get_recommended_rx_tx_delay_indicator to get the recommended delay
+ * indicator value for the given SF/BW, then it calls @p lr11xx_ranging_set_rx_tx_delay_indicator to configure the
+ * LR11xx.
+ *
+ * @param [in] context Chip implementation context
+ * @param [in] bw LoRa bandwidth used for ranging
+ * @param [in] sf LoRa spreading factor used for ranging
+ *
+ * @returns Operation status
+ * @retval LR11XX_STATUS_OK on success
+ * @retval LR11XX_STATUS_ERROR if the given physical layer configuration is invalid or other error
+ */
+lr11xx_status_t lr11xx_ranging_set_recommended_rx_tx_delay_indicator( const void* context, lr11xx_radio_lora_bw_t bw,
+ lr11xx_radio_lora_sf_t sf );
+
+/**
+ * @brief Convert the raw distance result obtained from the device to a distance result [m].
+ *
+ * This function is meaningful only to convert a ranging result obtained by calling @p lr11xx_ranging_get_raw_result
+ * with type set to @p LR11XX_RANGING_RESULT_TYPE_RAW
+ *
+ * @param [in] ranging_bw Bandwidth used during ranging
+ * @param [in] raw_distance_buf Buffer containing the raw distance result
+ *
+ * @returns int32_t Distance result [m]
+ *
+ * @see lr11xx_ranging_get_raw_result
+ *
+ * @note The caller must ensure that the @p ranging_bw parameter is one of the supported ones,
+ * i.e., #LR11XX_RADIO_LORA_BW_125, #LR11XX_RADIO_LORA_BW_250, #LR11XX_RADIO_LORA_BW_500.
+ */
+int32_t lr11xx_ranging_distance_raw_to_meter( lr11xx_radio_lora_bw_t ranging_bw,
+ const uint8_t raw_distance_buf[LR11XX_RANGING_RESULT_LENGTH] );
+
+/**
+ * @brief Convert the raw RSSI result obtained from the device to an RSSI result.
+ *
+ * This function is meaningful only to convert a ranging result obtained by calling @p lr11xx_ranging_get_raw_result
+ * with type set to @p LR11XX_RANGING_RESULT_TYPE_RSSI
+ *
+ * @param [in] raw_rssi_buf Buffer containing the raw RSSI result
+ *
+ * @returns int8_t RSSI result [dBm]
+ *
+ * @see lr11xx_ranging_get_raw_result
+ */
+static inline int8_t lr11xx_ranging_rssi_raw_to_value( const uint8_t raw_rssi_buf[LR11XX_RANGING_RESULT_LENGTH] )
+{
+ // Only the last byte is meaningful
+ return -( int8_t )( raw_rssi_buf[3] >> 1 );
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LR11XX_RANGING_H
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging_types.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging_types.h
new file mode 100644
index 0000000..9557fd5
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_ranging_types.h
@@ -0,0 +1,82 @@
+/**
+ * @file lr11xx_ranging_types.h
+ *
+ * @brief Ranging driver types for LR11XX
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2022. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LR11XX_RANGING_TYPES_H
+#define LR11XX_RANGING_TYPES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC MACROS -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC CONSTANTS --------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC TYPES ------------------------------------------------------------
+ */
+
+/**
+ * @brief Ranging result types
+ */
+typedef enum lr11xx_ranging_result_type_e
+{
+ LR11XX_RANGING_RESULT_TYPE_RAW = 0, ///< Raw distance result
+ LR11XX_RANGING_RESULT_TYPE_RSSI, ///< Ranging RSSI
+} lr11xx_ranging_result_type_t;
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTION PROTOTYPES ---------------------------------------------
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // LR11XX_RANGING_TYPES_H
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.c
index 3c5312a..5780402 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.c
@@ -153,6 +153,11 @@ lr11xx_status_t lr11xx_regmem_write_regmem32( const void* context, const uint32_
uint8_t cbuffer[LR11XX_REGMEM_WRITE_REGMEM32_CMD_LENGTH];
uint8_t cdata[LR11XX_REGMEM_BUFFER_SIZE_MAX];
+ if( length > LR11XX_REGMEM_MAX_WRITE_READ_WORDS )
+ {
+ return LR11XX_STATUS_ERROR;
+ }
+
lr11xx_regmem_fill_cbuffer_cdata_opcode_address_data( cbuffer, cdata, LR11XX_REGMEM_WRITE_REGMEM32_OC, address,
buffer, length );
@@ -166,6 +171,11 @@ lr11xx_status_t lr11xx_regmem_read_regmem32( const void* context, const uint32_t
uint8_t cbuffer[LR11XX_REGMEM_READ_REGMEM32_CMD_LENGTH];
lr11xx_status_t status = LR11XX_STATUS_ERROR;
+ if( length > LR11XX_REGMEM_MAX_WRITE_READ_WORDS )
+ {
+ return LR11XX_STATUS_ERROR;
+ }
+
lr11xx_regmem_fill_cbuffer_opcode_address_length( cbuffer, LR11XX_REGMEM_READ_REGMEM32_OC, address, length );
status = ( lr11xx_status_t ) lr11xx_hal_read( context, cbuffer, LR11XX_REGMEM_READ_REGMEM32_CMD_LENGTH,
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.h
index 9a89eb9..866a65e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_regmem.h
@@ -52,6 +52,11 @@ extern "C" {
* --- PUBLIC MACROS -----------------------------------------------------------
*/
+/*!
+ * @brief Maximum number of words that can be written to / read from a LR11XX chip with regmem32 commands
+ */
+#define LR11XX_REGMEM_MAX_WRITE_READ_WORDS 64
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC CONSTANTS --------------------------------------------------------
@@ -68,7 +73,7 @@ extern "C" {
*/
/*!
- * @brief Write words into register memory space of LR11XX.
+ * @brief Write up to 64 words into register memory space of LR11XX.
*
* A word is 32-bit long. The writing operations write contiguously in register memory, starting at the address
* provided.
@@ -86,7 +91,7 @@ lr11xx_status_t lr11xx_regmem_write_regmem32( const void* context, const uint32_
const uint8_t length );
/*!
- * @brief Read words into register memory space of LR11XX.
+ * @brief Read up to 64 words into register memory space of LR11XX.
*
* A word is 32-bit long. The reading operations read contiguously from register memory, starting at the address
* provided.
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system.c
index cc7f372..41e0861 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system.c
@@ -204,7 +204,7 @@ lr11xx_status_t lr11xx_system_get_version( const void* context, lr11xx_system_ve
if( status == LR11XX_STATUS_OK )
{
version->hw = rbuffer[0];
- version->type = rbuffer[1];
+ version->type = ( lr11xx_system_version_type_t ) rbuffer[1];
version->fw = ( ( uint16_t ) rbuffer[2] << 8 ) + ( uint16_t ) rbuffer[3];
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system_types.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system_types.h
index 23dec41..b7c2a0c 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system_types.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_system_types.h
@@ -112,6 +112,11 @@ enum lr11xx_system_irq_e
LR11XX_SYSTEM_IRQ_CAD_DETECTED = ( 1 << 9 ),
LR11XX_SYSTEM_IRQ_TIMEOUT = ( 1 << 10 ),
LR11XX_SYSTEM_IRQ_LR_FHSS_INTRA_PKT_HOP = ( 1 << 11 ),
+ LR11XX_SYSTEM_IRQ_RANGING_REQ_VALID = ( 1 << 14 ),
+ LR11XX_SYSTEM_IRQ_RANGING_REQ_DISCARDED = ( 1 << 15 ),
+ LR11XX_SYSTEM_IRQ_RANGING_RESP_DONE = ( 1 << 16 ),
+ LR11XX_SYSTEM_IRQ_RANGING_EXCH_VALID = ( 1 << 17 ),
+ LR11XX_SYSTEM_IRQ_RANGING_TIMEOUT = ( 1 << 18 ),
LR11XX_SYSTEM_IRQ_GNSS_SCAN_DONE = ( 1 << 19 ),
LR11XX_SYSTEM_IRQ_WIFI_SCAN_DONE = ( 1 << 20 ),
LR11XX_SYSTEM_IRQ_EOL = ( 1 << 21 ),
@@ -119,13 +124,18 @@ enum lr11xx_system_irq_e
LR11XX_SYSTEM_IRQ_ERROR = ( 1 << 23 ),
LR11XX_SYSTEM_IRQ_FSK_LEN_ERROR = ( 1 << 24 ),
LR11XX_SYSTEM_IRQ_FSK_ADDR_ERROR = ( 1 << 25 ),
+ LR11XX_SYSTEM_IRQ_LORA_RX_TIMESTAMP =
+ ( 1 << 27 ), //!< Available since firmware LR1110 0x0308 / LR1120 0x0102 / LR1121 0x0102
LR11XX_SYSTEM_IRQ_ALL_MASK =
LR11XX_SYSTEM_IRQ_TX_DONE | LR11XX_SYSTEM_IRQ_RX_DONE | LR11XX_SYSTEM_IRQ_PREAMBLE_DETECTED |
LR11XX_SYSTEM_IRQ_SYNC_WORD_HEADER_VALID | LR11XX_SYSTEM_IRQ_HEADER_ERROR | LR11XX_SYSTEM_IRQ_CRC_ERROR |
LR11XX_SYSTEM_IRQ_CAD_DONE | LR11XX_SYSTEM_IRQ_CAD_DETECTED | LR11XX_SYSTEM_IRQ_TIMEOUT |
- LR11XX_SYSTEM_IRQ_LR_FHSS_INTRA_PKT_HOP | LR11XX_SYSTEM_IRQ_GNSS_SCAN_DONE | LR11XX_SYSTEM_IRQ_WIFI_SCAN_DONE |
+ LR11XX_SYSTEM_IRQ_LR_FHSS_INTRA_PKT_HOP | LR11XX_SYSTEM_IRQ_RANGING_REQ_VALID |
+ LR11XX_SYSTEM_IRQ_RANGING_REQ_DISCARDED | LR11XX_SYSTEM_IRQ_RANGING_RESP_DONE |
+ LR11XX_SYSTEM_IRQ_RANGING_EXCH_VALID | LR11XX_SYSTEM_IRQ_RANGING_TIMEOUT |
+ LR11XX_SYSTEM_IRQ_GNSS_SCAN_DONE | LR11XX_SYSTEM_IRQ_WIFI_SCAN_DONE |
LR11XX_SYSTEM_IRQ_EOL | LR11XX_SYSTEM_IRQ_CMD_ERROR | LR11XX_SYSTEM_IRQ_ERROR |
- LR11XX_SYSTEM_IRQ_FSK_LEN_ERROR | LR11XX_SYSTEM_IRQ_FSK_ADDR_ERROR,
+ LR11XX_SYSTEM_IRQ_FSK_LEN_ERROR | LR11XX_SYSTEM_IRQ_FSK_ADDR_ERROR | LR11XX_SYSTEM_IRQ_LORA_RX_TIMESTAMP,
};
/**
@@ -297,14 +307,24 @@ typedef struct lr11xx_system_stat2_s
bool is_running_from_flash;
} lr11xx_system_stat2_t;
+/**
+ * @brief Chip type values
+ */
+typedef enum
+{
+ LR11XX_SYSTEM_VERSION_TYPE_LR1110 = 0x01,
+ LR11XX_SYSTEM_VERSION_TYPE_LR1120 = 0x02,
+ LR11XX_SYSTEM_VERSION_TYPE_LR1121 = 0x03,
+} lr11xx_system_version_type_t;
+
/**
* @brief Version structure definition
*/
typedef struct lr11xx_system_version_s
{
- uint8_t hw;
- uint8_t type;
- uint16_t fw;
+ uint8_t hw;
+ lr11xx_system_version_type_t type;
+ uint16_t fw;
} lr11xx_system_version_t;
/**
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_wifi.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_wifi.h
index e860f35..536c5af 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_wifi.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/lr11xx_driver/src/lr11xx_wifi.h
@@ -560,9 +560,9 @@ void lr11xx_wifi_parse_data_rate_info( const lr11xx_wifi_datarate_info_byte_t da
* @remark It is a driver limitation, not a LR11XX limitation, that avoid allocating temporary buffers of size too big
* when reading Wi-Fi passive scan results.
*
- * @see LR11XX_WIFI_N_RESULTS_MAX_PER_CHUNK
- *
* @returns The maximal number of results to fetch per SPI calls
+ *
+ * @see LR11XX_WIFI_N_RESULTS_MAX_PER_CHUNK
*/
uint8_t lr11xx_wifi_get_nb_results_max_per_chunk( void );
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md
index bdf66e9..503048a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/CHANGELOG.md
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [2.2.0] - 2023-03-27
+
+### Added
+
+- `sx126x_driver_version_get_version_string()` function - produces a c-string representation of the driver version
+- `SX126X_DRIVER_VERSION_CHECK` macro - validates the provided version information is compatible with the driver
+- `sx126x_lr_fhss_get_bit_delay_in_us( )` function - computes the delay between the last LR-FHSS bit sent and the TX done interrupt
+
## [2.1.0] - 2022-05-18
### Added
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.c
new file mode 100644
index 0000000..0e88f2b
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.c
@@ -0,0 +1,88 @@
+/*!
+ * @file sx126x_driver_version.c
+ *
+ * @brief Placeholder to keep the version of SX126x driver.
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2023. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+#include "sx126x_driver_version.h"
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE MACROS-----------------------------------------------------------
+ */
+
+#define STR_HELPER( x ) #x
+#define STR( x ) STR_HELPER( x )
+
+#define SX126X_DRIVER_VERSION_FULL \
+ "v" STR( SX126X_DRIVER_VERSION_MAJOR ) "." STR( SX126X_DRIVER_VERSION_MINOR ) "." STR( SX126X_DRIVER_VERSION_PATCH )
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE CONSTANTS -------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE TYPES -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE VARIABLES -------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
+ */
+
+const char* sx126x_driver_version_get_version_string( void )
+{
+ return ( const char* ) SX126X_DRIVER_VERSION_FULL;
+}
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
+ */
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.h
new file mode 100644
index 0000000..65f2f87
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_driver_version.h
@@ -0,0 +1,90 @@
+/*!
+ * @file sx126x_driver_version.h
+ *
+ * @brief Placeholder to keep the version of SX126x driver.
+ *
+ * The Clear BSD License
+ * Copyright Semtech Corporation 2023. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the disclaimer
+ * below) provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
+ * THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SX126X_DRIVER_VERSION_H
+#define SX126X_DRIVER_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC MACROS -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC CONSTANTS --------------------------------------------------------
+ */
+
+#define SX126X_DRIVER_VERSION_MAJOR 2
+#define SX126X_DRIVER_VERSION_MINOR 2
+#define SX126X_DRIVER_VERSION_PATCH 0
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC TYPES ------------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
+ */
+
+/*!
+ * @brief Compare version information with current ones
+ *
+ * This macro expands to true boolean value if the version information provided in argument is compatible or
+ * retro-compatible with the version of this code base
+ */
+#define SX126X_DRIVER_VERSION_CHECK( x, y, z ) \
+ ( x == SX126X_DRIVER_VERSION_MAJOR && \
+ ( y < SX126X_DRIVER_VERSION_MINOR || \
+ ( y == SX126X_DRIVER_VERSION_MINOR && z <= SX126X_DRIVER_VERSION_PATCH ) ) )
+
+const char* sx126x_driver_version_get_version_string( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // SX126X_DRIVER_VERSION_H
+
+/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.c
index c60a53d..a55dc2a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.c
@@ -165,6 +165,17 @@ sx126x_status_t sx126x_lr_fhss_init( const void* context, const sx126x_lr_fhss_p
return status;
}
+uint16_t sx126x_lr_fhss_get_bit_delay_in_us( const sx126x_lr_fhss_params_t* params, uint16_t payload_length )
+{
+ lr_fhss_digest_t digest;
+
+ lr_fhss_process_parameters( ¶ms->lr_fhss_params, payload_length, &digest );
+
+ const uint8_t nb_padding_bits = 1 + ( ( 32768 - digest.nb_bits ) & 0x07 );
+
+ return 1550 + nb_padding_bits * 2048;
+}
+
sx126x_status_t sx126x_lr_fhss_process_parameters( const sx126x_lr_fhss_params_t* params, uint16_t hop_sequence_id,
uint16_t payload_length, sx126x_lr_fhss_state_t* state )
{
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.h
index d68e80e..d4eccf5 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx126x_driver/src/sx126x_lr_fhss.h
@@ -108,6 +108,16 @@ extern "C" {
*/
sx126x_status_t sx126x_lr_fhss_init( const void* context, const sx126x_lr_fhss_params_t* params );
+/**
+ * @brief Get the delay in microsecond between the last bit sent and the TX done interrupt
+ *
+ * @param [in] params sx126x LR-FHSS parameter structure
+ * @param [in] payload_length Length of application-layer payload
+ *
+ * @returns Delay in microseconds
+ */
+uint16_t sx126x_lr_fhss_get_bit_delay_in_us( const sx126x_lr_fhss_params_t* params, uint16_t payload_length );
+
/**
* @brief Check the parameters, and in case of success, generate the digest summary which contains important size info
*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/license.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/license.md
deleted file mode 100644
index 5c52fa9..0000000
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/license.md
+++ /dev/null
@@ -1,25 +0,0 @@
---- Revised BSD License ---
-Copyright (c) 2020, SEMTECH CORPORATION
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the Semtech corporation nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner.c
index 0115f8d..1403e4a 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner.c
@@ -286,6 +286,12 @@ rp_hook_status_t rp_task_enqueue( radio_planner_t* rp, const rp_task_t* task, ui
return RP_TASK_STATUS_SCHEDULE_TASK_IN_PAST;
}
+ if( ( ( task->start_time_ms - now ) > 36000000 ) &&
+ ( task->start_time_ms > now ) ) // this task is too far in the futur , improve robustness to wrapping issue
+ {
+ return RP_TASK_STATUS_TASK_TOO_FAR_IN_FUTURE;
+ }
+
if( rp->tasks[hook_id].state == RP_TASK_STATE_RUNNING )
{
SMTC_MODEM_HAL_RP_TRACE_PRINTF( " RP: Task enqueue impossible. Task is already running\n" );
@@ -628,6 +634,12 @@ static void rp_irq_get_status( radio_planner_t* rp, const uint8_t hook_id )
smtc_modem_hal_assert( ral_lr_fhss_handle_tx_done( &rp->radio->ral,
&rp->radio_params[hook_id].tx.lr_fhss.ral_lr_fhss_params,
NULL ) == RAL_STATUS_OK );
+
+ // fix issue with delay between the end of the transmission and the generation of txdone irq
+ // get delay according to lr-fhss params
+ uint32_t bit_delay_us = ral_lr_fhss_get_bit_delay_in_us(
+ &rp->radio->ral, &rp->radio_params[hook_id].tx.lr_fhss.ral_lr_fhss_params, rp->payload_size[hook_id] );
+ rp->irq_timestamp_ms[hook_id] = rp->irq_timestamp_ms[hook_id] - ( bit_delay_us / 1000 );
}
}
else if( ( ( radio_irq & RAL_IRQ_RX_HDR_ERROR ) == RAL_IRQ_RX_HDR_ERROR ) ||
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner_types.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner_types.h
index c0c55ae..1790e2e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner_types.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_planner/src/radio_planner_types.h
@@ -230,6 +230,7 @@ typedef enum rp_hook_status_e
RP_HOOK_STATUS_ID_ERROR,
RP_TASK_STATUS_ALREADY_RUNNING,
RP_TASK_STATUS_SCHEDULE_TASK_IN_PAST,
+ RP_TASK_STATUS_TASK_TOO_FAR_IN_FUTURE,
} rp_hook_status_t;
/*!
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/lr11xx_crypto_engine/lr11xx_ce.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/lr11xx_crypto_engine/lr11xx_ce.c
index abcc301..1948d38 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/lr11xx_crypto_engine/lr11xx_ce.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/lr11xx_crypto_engine/lr11xx_ce.c
@@ -471,7 +471,7 @@ smtc_se_return_code_t smtc_secure_element_get_pin( uint8_t pin[SMTC_SE_PIN_SIZE]
return SMTC_SE_RC_ERROR_NPE;
}
- memcpy( pin, lr11xx_ce_data.pin, SMTC_SE_EUI_SIZE );
+ memcpy( pin, lr11xx_ce_data.pin, SMTC_SE_PIN_SIZE );
return SMTC_SE_RC_SUCCESS;
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/smtc_secure_element/smtc_secure_element.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/smtc_secure_element/smtc_secure_element.h
index 211f0c3..ffca7ca 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/smtc_secure_element/smtc_secure_element.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/smtc_secure_element/smtc_secure_element.h
@@ -1,303 +1,303 @@
-/**
- * @file smtc_secure_element.h
- *
- * @brief Secure Element API
- *
- * Revised BSD License
- * Copyright Semtech Corporation 2020. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Semtech corporation nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SMTC_SECURE_ELEMENT_H
-#define SMTC_SECURE_ELEMENT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * -----------------------------------------------------------------------------
- * --- DEPENDENCIES ------------------------------------------------------------
- */
-
-#include // C99 types
-#include // bool type
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC MACROS -----------------------------------------------------------
- */
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC CONSTANTS --------------------------------------------------------
- */
-
-/*!
- * Secure-element keys size in bytes
- */
-#define SMTC_SE_KEY_SIZE 16
-
-/*!
- * Secure-element EUI size in bytes
- */
-#define SMTC_SE_EUI_SIZE 8
-
-/*!
- * Secure-element pin size in bytes
- */
-#define SMTC_SE_PIN_SIZE 4
-
-/*!
- * Start value for multicast keys enumeration
- */
-#define SMTC_SE_MULTICAST_KEYS 127
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC TYPES ------------------------------------------------------------
- */
-
-/**
- * @brief Secure element return values.
- *
- * @enum smtc_se_return_code_t
- */
-
-typedef enum smtc_secure_element_return_code_e
-{
- SMTC_SE_RC_SUCCESS = 0, //!< No error occurred
- SMTC_SE_RC_FAIL_CMAC, //!< CMAC does not match
- SMTC_SE_RC_ERROR_NPE, //!< Null pointer exception
- SMTC_SE_RC_ERROR_INVALID_KEY_ID, //!< Invalid key identifier exception
- SMTC_SE_RC_ERROR_INVALID_LORAWAM_SPEC_VERSION, //!< Invalid LoRaWAN specification version
- SMTC_SE_RC_ERROR_BUF_SIZE, //!< Incompatible buffer size
- SMTC_SE_RC_ERROR, //!< Undefined Error occurred
- SMTC_SE_RC_FAIL_ENCRYPT, //!< Failed to encrypt
-} smtc_se_return_code_t;
-
-/**
- * @brief join-request / rejoin type identifier
- *
- * @enum smtc_se_join_req_identifier_t
- */
-typedef enum smtc_se_join_req_identifier_e
-{
- SMTC_SE_REJOIN_REQ_0 = 0x00, //!< Rejoin type 0
- SMTC_SE_REJOIN_REQ_1 = 0x01, //!< Rejoin type 1
- SMTC_SE_REJOIN_REQ_2 = 0x02, //!< Rejoin type 2
- SMTC_SE_JOIN_REQ = 0xFF, //!< Join-request
-} smtc_se_join_req_identifier_t;
-
-/*!
- * LoRaMac Key identifier
- *
- * @enum smtc_se_key_identifier_t
- */
-typedef enum smtc_se_key_identifier_e
-{
- SMTC_SE_APP_KEY = 0, //!< Application root key
- SMTC_SE_NWK_KEY, //!< Network root key
- SMTC_SE_J_S_INT_KEY, //!< Join session integrity key
- SMTC_SE_J_S_ENC_KEY, //!< Join session encryption key
- SMTC_SE_F_NWK_S_INT_KEY, //!< Forwarding Network session integrity key
- SMTC_SE_S_NWK_S_INT_KEY, //!< Serving Network session integrity key
- SMTC_SE_NWK_S_ENC_KEY, //!< Network session encryption key
- SMTC_SE_APP_S_KEY, //!< Application session key
- SMTC_SE_MC_ROOT_KEY, //!< Multicast root key
- SMTC_SE_MC_KE_KEY = SMTC_SE_MULTICAST_KEYS, //!< Multicast key encryption key
- SMTC_SE_MC_KEY_0, //!< Multicast root key index 0
- SMTC_SE_MC_APP_S_KEY_0, //!< Multicast Application session key index 0
- SMTC_SE_MC_NWK_S_KEY_0, //!< Multicast Network session key index 0
- SMTC_SE_MC_KEY_1, //!< Multicast root key index 1
- SMTC_SE_MC_APP_S_KEY_1, //!< Multicast Application session key index 1
- SMTC_SE_MC_NWK_S_KEY_1, //!< Multicast Network session key index 1
- SMTC_SE_MC_KEY_2, //!< Multicast root key index 2
- SMTC_SE_MC_APP_S_KEY_2, //!< Multicast Application session key index 2
- SMTC_SE_MC_NWK_S_KEY_2, //!< Multicast Network session key index 2
- SMTC_SE_MC_KEY_3, //!< Multicast root key index 3
- SMTC_SE_MC_APP_S_KEY_3, //!< Multicast Application session key index 3
- SMTC_SE_MC_NWK_S_KEY_3, //!< Multicast Network session key index 3
- SMTC_SE_SLOT_RAND_ZERO_KEY, //!< Zero key for slot randomization in class B
- SMTC_SE_NO_KEY, //!< No Key
-} smtc_se_key_identifier_t;
-
-/*
- * -----------------------------------------------------------------------------
- * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
- */
-
-/**
- * @brief Initialization of Secure Element driver
- *
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_init( void );
-
-/**
- * @brief Sets a key
- *
- * @param [in] key_id Key identifier
- * @param [in] key Key value
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_set_key( smtc_se_key_identifier_t key_id,
- const uint8_t key[SMTC_SE_KEY_SIZE] );
-
-/**
- * @brief Computes a CMAC of a message using provided initial Bx block
- *
- * @param [in] mic_bx_buffer Buffer containing the initial Bx block
- * @param [in] buffer Data buffer
- * @param [in] size Data buffer size
- * @param [in] key_id Key identifier to determine the AES key to be used
- * @param [in] cmac Computed cmac
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_compute_aes_cmac( uint8_t* mic_bx_buffer, const uint8_t* buffer,
- uint16_t size, smtc_se_key_identifier_t key_id,
- uint32_t* cmac );
-
-/**
- * @brief Verifies a CMAC (computes and compare with expected cmac)
- *
- * @param [in] buffer Data buffer
- * @param [in] size Data buffer size
- * @param [in] expected_cmac Expected cmac
- * @param [in] key_id Key identifier to determine the AES key to be used
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_verify_aes_cmac( uint8_t* buffer, uint16_t size, uint32_t expected_cmac,
- smtc_se_key_identifier_t key_id );
-
-/**
- * @brief Encrypt a buffer
- *
- * @param [in] buffer Data buffer
- * @param [in] size Data buffer size - this value shall be a multiple of 16
- * @param [in] key_id Key identifier to determine the AES key to be used
- * @param [in] enc_buffer Encrypted buffer
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_aes_encrypt( const uint8_t* buffer, uint16_t size,
- smtc_se_key_identifier_t key_id, uint8_t* enc_buffer );
-
-/**
- * @brief Derives and store a key
- *
- * @param [in] input Input data from which the key is derived ( 16 bytes )
- * @param [in] rootkey_id Key identifier of the root key to use to perform the derivation
- * @param [in] targetkey_id Key identifier of the key which will be derived
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_derive_and_store_key( uint8_t* input, smtc_se_key_identifier_t rootkey_id,
- smtc_se_key_identifier_t targetkey_id );
-
-/**
- * @brief Process join_accept message.
- *
- * @param [in] join_req_type LoRaMac join-request / rejoin type identifier
- * @param [in] joineui LoRaWAN Join server EUI
- * @param [in] dev_nonce Device nonce
- * @param [in] enc_join_accept Received encrypted join_accept message
- * @param [in] enc_join_accept_size Received encrypted join_accept message Size
- * @param [in] dec_join_accept Decrypted and validated join_accept message
- * @param [in] version_minor Detected LoRaWAN specification version minor field.
- * - 0 -> LoRaWAN 1.0.x
- * - 1 -> LoRaWAN 1.1.x
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_process_join_accept( smtc_se_join_req_identifier_t join_req_type,
- uint8_t joineui[SMTC_SE_EUI_SIZE], uint16_t dev_nonce,
- const uint8_t* enc_join_accept,
- uint8_t enc_join_accept_size, uint8_t* dec_join_accept,
- uint8_t* version_minor );
-
-/**
- * @brief Sets the DevEUI
- *
- * @param [in] deveui LoRaWAN devEUI
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_set_deveui( const uint8_t deveui[SMTC_SE_EUI_SIZE] );
-
-/**
- * @brief Gets the DevEUI
- *
- * @param [out] deveui The current DevEUI
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_get_deveui( uint8_t deveui[SMTC_SE_EUI_SIZE] );
-
-/**
- * @brief Sets the JoinEUI
- *
- * @param [in] joineui LoRaWAN JoinEUI
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_set_joineui( const uint8_t joineui[SMTC_SE_EUI_SIZE] );
-
-/**
- * @brief Gets the JoinEUI
- *
- * @param [out] joineui The current JoinEUI
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_get_joineui( uint8_t joineui[SMTC_SE_EUI_SIZE] );
-
-/**
- * @brief Sets the pin
- *
- * @param [in] pin The pin code
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_set_pin( const uint8_t pin[SMTC_SE_PIN_SIZE] );
-
-/**
- * @brief Gets the pin
- *
- * @param [out] pin The current pin code
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_get_pin( uint8_t pin[SMTC_SE_PIN_SIZE] );
-
-/**
- * @brief Store the current secure element context into NVM
- *
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_store_context( void );
-
-/**
- * @brief Restore the stored secure element context from NVM to RAM
- *
- * @return Secure element return code as defined in @ref smtc_se_return_code_t
- */
-smtc_se_return_code_t smtc_secure_element_restore_context( void );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // SMTC_SECURE_ELEMENT_H__
+/**
+ * @file smtc_secure_element.h
+ *
+ * @brief Secure Element API
+ *
+ * Revised BSD License
+ * Copyright Semtech Corporation 2020. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Semtech corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SMTC_SECURE_ELEMENT_H
+#define SMTC_SECURE_ELEMENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- DEPENDENCIES ------------------------------------------------------------
+ */
+
+#include // C99 types
+#include // bool type
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC MACROS -----------------------------------------------------------
+ */
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC CONSTANTS --------------------------------------------------------
+ */
+
+/*!
+ * Secure-element keys size in bytes
+ */
+#define SMTC_SE_KEY_SIZE 16
+
+/*!
+ * Secure-element EUI size in bytes
+ */
+#define SMTC_SE_EUI_SIZE 8
+
+/*!
+ * Secure-element pin size in bytes
+ */
+#define SMTC_SE_PIN_SIZE 4
+
+/*!
+ * Start value for multicast keys enumeration
+ */
+#define SMTC_SE_MULTICAST_KEYS 127
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC TYPES ------------------------------------------------------------
+ */
+
+/**
+ * @brief Secure element return values.
+ *
+ * @enum smtc_se_return_code_t
+ */
+
+typedef enum smtc_secure_element_return_code_e
+{
+ SMTC_SE_RC_SUCCESS = 0, //!< No error occurred
+ SMTC_SE_RC_FAIL_CMAC, //!< CMAC does not match
+ SMTC_SE_RC_ERROR_NPE, //!< Null pointer exception
+ SMTC_SE_RC_ERROR_INVALID_KEY_ID, //!< Invalid key identifier exception
+ SMTC_SE_RC_ERROR_INVALID_LORAWAM_SPEC_VERSION, //!< Invalid LoRaWAN specification version
+ SMTC_SE_RC_ERROR_BUF_SIZE, //!< Incompatible buffer size
+ SMTC_SE_RC_ERROR, //!< Undefined Error occurred
+ SMTC_SE_RC_FAIL_ENCRYPT, //!< Failed to encrypt
+} smtc_se_return_code_t;
+
+/**
+ * @brief join-request / rejoin type identifier
+ *
+ * @enum smtc_se_join_req_identifier_t
+ */
+typedef enum smtc_se_join_req_identifier_e
+{
+ SMTC_SE_REJOIN_REQ_0 = 0x00, //!< Rejoin type 0
+ SMTC_SE_REJOIN_REQ_1 = 0x01, //!< Rejoin type 1
+ SMTC_SE_REJOIN_REQ_2 = 0x02, //!< Rejoin type 2
+ SMTC_SE_JOIN_REQ = 0xFF, //!< Join-request
+} smtc_se_join_req_identifier_t;
+
+/*!
+ * LoRaMac Key identifier
+ *
+ * @enum smtc_se_key_identifier_t
+ */
+typedef enum smtc_se_key_identifier_e
+{
+ SMTC_SE_APP_KEY = 0, //!< Application root key
+ SMTC_SE_NWK_KEY, //!< Network root key
+ SMTC_SE_J_S_INT_KEY, //!< Join session integrity key
+ SMTC_SE_J_S_ENC_KEY, //!< Join session encryption key
+ SMTC_SE_F_NWK_S_INT_KEY, //!< Forwarding Network session integrity key
+ SMTC_SE_S_NWK_S_INT_KEY, //!< Serving Network session integrity key
+ SMTC_SE_NWK_S_ENC_KEY, //!< Network session encryption key
+ SMTC_SE_APP_S_KEY, //!< Application session key
+ SMTC_SE_MC_ROOT_KEY, //!< Multicast root key
+ SMTC_SE_MC_KE_KEY = SMTC_SE_MULTICAST_KEYS, //!< Multicast key encryption key
+ SMTC_SE_MC_KEY_0, //!< Multicast root key index 0
+ SMTC_SE_MC_APP_S_KEY_0, //!< Multicast Application session key index 0
+ SMTC_SE_MC_NWK_S_KEY_0, //!< Multicast Network session key index 0
+ SMTC_SE_MC_KEY_1, //!< Multicast root key index 1
+ SMTC_SE_MC_APP_S_KEY_1, //!< Multicast Application session key index 1
+ SMTC_SE_MC_NWK_S_KEY_1, //!< Multicast Network session key index 1
+ SMTC_SE_MC_KEY_2, //!< Multicast root key index 2
+ SMTC_SE_MC_APP_S_KEY_2, //!< Multicast Application session key index 2
+ SMTC_SE_MC_NWK_S_KEY_2, //!< Multicast Network session key index 2
+ SMTC_SE_MC_KEY_3, //!< Multicast root key index 3
+ SMTC_SE_MC_APP_S_KEY_3, //!< Multicast Application session key index 3
+ SMTC_SE_MC_NWK_S_KEY_3, //!< Multicast Network session key index 3
+ SMTC_SE_SLOT_RAND_ZERO_KEY, //!< Zero key for slot randomization in class B
+ SMTC_SE_NO_KEY, //!< No Key
+} smtc_se_key_identifier_t;
+
+/*
+ * -----------------------------------------------------------------------------
+ * --- PUBLIC FUNCTIONS PROTOTYPES ---------------------------------------------
+ */
+
+/**
+ * @brief Initialization of Secure Element driver
+ *
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_init( void );
+
+/**
+ * @brief Sets a key
+ *
+ * @param [in] key_id Key identifier
+ * @param [in] key Key value
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_set_key( smtc_se_key_identifier_t key_id,
+ const uint8_t key[SMTC_SE_KEY_SIZE] );
+
+/**
+ * @brief Computes a CMAC of a message using provided initial Bx block
+ *
+ * @param [in] mic_bx_buffer Buffer containing the initial Bx block
+ * @param [in] buffer Data buffer
+ * @param [in] size Data buffer size
+ * @param [in] key_id Key identifier to determine the AES key to be used
+ * @param [in] cmac Computed cmac
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_compute_aes_cmac( uint8_t* mic_bx_buffer, const uint8_t* buffer,
+ uint16_t size, smtc_se_key_identifier_t key_id,
+ uint32_t* cmac );
+
+/**
+ * @brief Verifies a CMAC (computes and compare with expected cmac)
+ *
+ * @param [in] buffer Data buffer
+ * @param [in] size Data buffer size
+ * @param [in] expected_cmac Expected cmac
+ * @param [in] key_id Key identifier to determine the AES key to be used
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_verify_aes_cmac( uint8_t* buffer, uint16_t size, uint32_t expected_cmac,
+ smtc_se_key_identifier_t key_id );
+
+/**
+ * @brief Encrypt a buffer
+ *
+ * @param [in] buffer Data buffer
+ * @param [in] size Data buffer size - this value shall be a multiple of 16
+ * @param [in] key_id Key identifier to determine the AES key to be used
+ * @param [in] enc_buffer Encrypted buffer
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_aes_encrypt( const uint8_t* buffer, uint16_t size,
+ smtc_se_key_identifier_t key_id, uint8_t* enc_buffer );
+
+/**
+ * @brief Derives and store a key
+ *
+ * @param [in] input Input data from which the key is derived ( 16 bytes )
+ * @param [in] rootkey_id Key identifier of the root key to use to perform the derivation
+ * @param [in] targetkey_id Key identifier of the key which will be derived
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_derive_and_store_key( uint8_t* input, smtc_se_key_identifier_t rootkey_id,
+ smtc_se_key_identifier_t targetkey_id );
+
+/**
+ * @brief Process join_accept message.
+ *
+ * @param [in] join_req_type LoRaMac join-request / rejoin type identifier
+ * @param [in] joineui LoRaWAN Join server EUI
+ * @param [in] dev_nonce Device nonce
+ * @param [in] enc_join_accept Received encrypted join_accept message
+ * @param [in] enc_join_accept_size Received encrypted join_accept message Size
+ * @param [in] dec_join_accept Decrypted and validated join_accept message
+ * @param [in] version_minor Detected LoRaWAN specification version minor field.
+ * - 0 -> LoRaWAN 1.0.x
+ * - 1 -> LoRaWAN 1.1.x
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_process_join_accept( smtc_se_join_req_identifier_t join_req_type,
+ uint8_t joineui[SMTC_SE_EUI_SIZE], uint16_t dev_nonce,
+ const uint8_t* enc_join_accept,
+ uint8_t enc_join_accept_size, uint8_t* dec_join_accept,
+ uint8_t* version_minor );
+
+/**
+ * @brief Sets the DevEUI
+ *
+ * @param [in] deveui LoRaWAN devEUI
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_set_deveui( const uint8_t deveui[SMTC_SE_EUI_SIZE] );
+
+/**
+ * @brief Gets the DevEUI
+ *
+ * @param [out] deveui The current DevEUI
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_get_deveui( uint8_t deveui[SMTC_SE_EUI_SIZE] );
+
+/**
+ * @brief Sets the JoinEUI
+ *
+ * @param [in] joineui LoRaWAN JoinEUI
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_set_joineui( const uint8_t joineui[SMTC_SE_EUI_SIZE] );
+
+/**
+ * @brief Gets the JoinEUI
+ *
+ * @param [out] joineui The current JoinEUI
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_get_joineui( uint8_t joineui[SMTC_SE_EUI_SIZE] );
+
+/**
+ * @brief Sets the pin
+ *
+ * @param [in] pin The pin code
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_set_pin( const uint8_t pin[SMTC_SE_PIN_SIZE] );
+
+/**
+ * @brief Gets the pin
+ *
+ * @param [out] pin The current pin code
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_get_pin( uint8_t pin[SMTC_SE_PIN_SIZE] );
+
+/**
+ * @brief Store the current secure element context into NVM
+ *
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_store_context( void );
+
+/**
+ * @brief Restore the stored secure element context from NVM to RAM
+ *
+ * @return Secure element return code as defined in @ref smtc_se_return_code_t
+ */
+smtc_se_return_code_t smtc_secure_element_restore_context( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // SMTC_SECURE_ELEMENT_H__
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.c
index 7f46ea3..eb0551f 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.c
@@ -1,936 +1,936 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
-
- LICENSE TERMS
-
- The redistribution and use of this software (with or without changes)
- is allowed without the payment of fees or royalties provided that:
-
- 1. source code distributions include the above copyright notice, this
- list of conditions and the following disclaimer;
-
- 2. binary distributions include the above copyright notice, this list
- of conditions and the following disclaimer in their documentation;
-
- 3. the name of the copyright holder is not used to endorse products
- built using this software without specific written permission.
-
- DISCLAIMER
-
- This software is provided 'as is' with no explicit or implied warranties
- in respect of its properties, including, but not limited to, correctness
- and/or fitness for purpose.
- ---------------------------------------------------------------------------
- Issue 09/09/2006
-
- This is an AES implementation that uses only 8-bit byte operations on the
- cipher state (there are options to use 32-bit types if available).
-
- The combination of mix columns and byte substitution used here is based on
- that developed by Karl Malbrain. His contribution is acknowledged.
- */
-
-/* define if you have a fast memcpy function on your system */
-#if 0
-# define HAVE_MEMCPY
-# include
-# if defined( _MSC_VER )
-# include
-# pragma intrinsic( memcpy )
-# endif
-#endif
-
-
-#include
-#include
-
-/* define if you have fast 32-bit types on your system */
-#if ( __CORTEX_M != 0 ) // if Cortex is different from M0/M0+
-# define HAVE_UINT_32T
-#endif
-
-/* define if you don't want any tables */
-#if 1
-# define USE_TABLES
-#endif
-
-/* On Intel Core 2 duo VERSION_1 is faster */
-
-/* alternative versions (test for performance on your system) */
-#if 1
-# define VERSION_1
-#endif
-
-#include "aes.h"
-
-//#if defined( HAVE_UINT_32T )
-// typedef unsigned long uint32_t;
-//#endif
-
-/* functions for finite field multiplication in the AES Galois field */
-
-#define WPOLY 0x011b
-#define BPOLY 0x1b
-#define DPOLY 0x008d
-
-#define f1(x) (x)
-#define f2(x) ((x << 1) ^ (((x >> 7) & 1) * WPOLY))
-#define f4(x) ((x << 2) ^ (((x >> 6) & 1) * WPOLY) ^ (((x >> 6) & 2) * WPOLY))
-#define f8(x) ((x << 3) ^ (((x >> 5) & 1) * WPOLY) ^ (((x >> 5) & 2) * WPOLY) \
- ^ (((x >> 5) & 4) * WPOLY))
-#define d2(x) (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0))
-
-#define f3(x) (f2(x) ^ x)
-#define f9(x) (f8(x) ^ x)
-#define fb(x) (f8(x) ^ f2(x) ^ x)
-#define fd(x) (f8(x) ^ f4(x) ^ x)
-#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
-
-#if defined( USE_TABLES )
-
-#define sb_data(w) { /* S Box data values */ \
- w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
- w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
- w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
- w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
- w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
- w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
- w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
- w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
- w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
- w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
- w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
- w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
- w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
- w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
- w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
- w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
- w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
- w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
- w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
- w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
- w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
- w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
- w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
- w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
- w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
- w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
- w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
- w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
- w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
- w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
- w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
- w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
-
-#define isb_data(w) { /* inverse S Box data values */ \
- w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\
- w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\
- w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\
- w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\
- w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\
- w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\
- w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\
- w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\
- w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\
- w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\
- w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\
- w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\
- w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\
- w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\
- w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\
- w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\
- w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\
- w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\
- w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\
- w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\
- w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\
- w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\
- w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\
- w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\
- w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\
- w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\
- w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\
- w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\
- w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\
- w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\
- w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\
- w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }
-
-#define mm_data(w) { /* basic data for forming finite field tables */ \
- w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\
- w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\
- w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\
- w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\
- w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\
- w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\
- w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\
- w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\
- w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\
- w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\
- w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\
- w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\
- w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\
- w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\
- w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\
- w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\
- w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\
- w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\
- w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\
- w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\
- w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\
- w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\
- w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\
- w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\
- w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\
- w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\
- w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\
- w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\
- w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\
- w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\
- w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\
- w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }
-
-static const uint8_t sbox[256] = sb_data(f1);
-
-#if defined( AES_DEC_PREKEYED )
-static const uint8_t isbox[256] = isb_data(f1);
-#endif
-
-static const uint8_t gfm2_sbox[256] = sb_data(f2);
-static const uint8_t gfm3_sbox[256] = sb_data(f3);
-
-#if defined( AES_DEC_PREKEYED )
-static const uint8_t gfmul_9[256] = mm_data(f9);
-static const uint8_t gfmul_b[256] = mm_data(fb);
-static const uint8_t gfmul_d[256] = mm_data(fd);
-static const uint8_t gfmul_e[256] = mm_data(fe);
-#endif
-
-#define s_box(x) sbox[(x)]
-#if defined( AES_DEC_PREKEYED )
-#define is_box(x) isbox[(x)]
-#endif
-#define gfm2_sb(x) gfm2_sbox[(x)]
-#define gfm3_sb(x) gfm3_sbox[(x)]
-#if defined( AES_DEC_PREKEYED )
-#define gfm_9(x) gfmul_9[(x)]
-#define gfm_b(x) gfmul_b[(x)]
-#define gfm_d(x) gfmul_d[(x)]
-#define gfm_e(x) gfmul_e[(x)]
-#endif
-#else
-
-/* this is the high bit of x right shifted by 1 */
-/* position. Since the starting polynomial has */
-/* 9 bits (0x11b), this right shift keeps the */
-/* values of all top bits within a byte */
-
-static uint8_t hibit(const uint8_t x)
-{ uint8_t r = (uint8_t)((x >> 1) | (x >> 2));
-
- r |= (r >> 2);
- r |= (r >> 4);
- return (r + 1) >> 1;
-}
-
-/* return the inverse of the finite field element x */
-
-static uint8_t gf_inv(const uint8_t x)
-{ uint8_t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0;
-
- if(x < 2)
- return x;
-
- for( ; ; )
- {
- if(n1)
- while(n2 >= n1) /* divide polynomial p2 by p1 */
- {
- n2 /= n1; /* shift smaller polynomial left */
- p2 ^= (p1 * n2) & 0xff; /* and remove from larger one */
- v2 ^= (v1 * n2); /* shift accumulated value and */
- n2 = hibit(p2); /* add into result */
- }
- else
- return v1;
-
- if(n2) /* repeat with values swapped */
- while(n1 >= n2)
- {
- n1 /= n2;
- p1 ^= p2 * n1;
- v1 ^= v2 * n1;
- n1 = hibit(p1);
- }
- else
- return v2;
- }
-}
-
-/* The forward and inverse affine transformations used in the S-box */
-uint8_t fwd_affine(const uint8_t x)
-{
-#if defined( HAVE_UINT_32T )
- uint32_t w = x;
- w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4);
- return 0x63 ^ ((w ^ (w >> 8)) & 0xff);
-#else
- return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4)
- ^ (x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4);
-#endif
-}
-
-uint8_t inv_affine(const uint8_t x)
-{
-#if defined( HAVE_UINT_32T )
- uint32_t w = x;
- w = (w << 1) ^ (w << 3) ^ (w << 6);
- return 0x05 ^ ((w ^ (w >> 8)) & 0xff);
-#else
- return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6)
- ^ (x >> 7) ^ (x >> 5) ^ (x >> 2);
-#endif
-}
-
-#define s_box(x) fwd_affine(gf_inv(x))
-#define is_box(x) gf_inv(inv_affine(x))
-#define gfm2_sb(x) f2(s_box(x))
-#define gfm3_sb(x) f3(s_box(x))
-#define gfm_9(x) f9(x)
-#define gfm_b(x) fb(x)
-#define gfm_d(x) fd(x)
-#define gfm_e(x) fe(x)
-
-#endif
-
-#if defined( HAVE_MEMCPY )
-# define block_copy_nn(d, s, l) memcpy(d, s, l)
-# define block_copy(d, s) memcpy(d, s, N_BLOCK)
-#else
-# define block_copy_nn(d, s, l) copy_block_nn(d, s, l)
-# define block_copy(d, s) copy_block(d, s)
-#endif
-
-static void copy_block( void *d, const void *s )
-{
-#if defined( HAVE_UINT_32T )
- ((uint32_t*)d)[ 0] = ((uint32_t*)s)[ 0];
- ((uint32_t*)d)[ 1] = ((uint32_t*)s)[ 1];
- ((uint32_t*)d)[ 2] = ((uint32_t*)s)[ 2];
- ((uint32_t*)d)[ 3] = ((uint32_t*)s)[ 3];
-#else
- ((uint8_t*)d)[ 0] = ((uint8_t*)s)[ 0];
- ((uint8_t*)d)[ 1] = ((uint8_t*)s)[ 1];
- ((uint8_t*)d)[ 2] = ((uint8_t*)s)[ 2];
- ((uint8_t*)d)[ 3] = ((uint8_t*)s)[ 3];
- ((uint8_t*)d)[ 4] = ((uint8_t*)s)[ 4];
- ((uint8_t*)d)[ 5] = ((uint8_t*)s)[ 5];
- ((uint8_t*)d)[ 6] = ((uint8_t*)s)[ 6];
- ((uint8_t*)d)[ 7] = ((uint8_t*)s)[ 7];
- ((uint8_t*)d)[ 8] = ((uint8_t*)s)[ 8];
- ((uint8_t*)d)[ 9] = ((uint8_t*)s)[ 9];
- ((uint8_t*)d)[10] = ((uint8_t*)s)[10];
- ((uint8_t*)d)[11] = ((uint8_t*)s)[11];
- ((uint8_t*)d)[12] = ((uint8_t*)s)[12];
- ((uint8_t*)d)[13] = ((uint8_t*)s)[13];
- ((uint8_t*)d)[14] = ((uint8_t*)s)[14];
- ((uint8_t*)d)[15] = ((uint8_t*)s)[15];
-#endif
-}
-
-static void copy_block_nn( uint8_t * d, const uint8_t *s, uint8_t nn )
-{
- while( nn-- )
- //*((uint8_t*)d)++ = *((uint8_t*)s)++;
- *d++ = *s++;
-}
-
-static void xor_block( void *d, const void *s )
-{
-#if defined( HAVE_UINT_32T )
- ((uint32_t*)d)[ 0] ^= ((uint32_t*)s)[ 0];
- ((uint32_t*)d)[ 1] ^= ((uint32_t*)s)[ 1];
- ((uint32_t*)d)[ 2] ^= ((uint32_t*)s)[ 2];
- ((uint32_t*)d)[ 3] ^= ((uint32_t*)s)[ 3];
-#else
- ((uint8_t*)d)[ 0] ^= ((uint8_t*)s)[ 0];
- ((uint8_t*)d)[ 1] ^= ((uint8_t*)s)[ 1];
- ((uint8_t*)d)[ 2] ^= ((uint8_t*)s)[ 2];
- ((uint8_t*)d)[ 3] ^= ((uint8_t*)s)[ 3];
- ((uint8_t*)d)[ 4] ^= ((uint8_t*)s)[ 4];
- ((uint8_t*)d)[ 5] ^= ((uint8_t*)s)[ 5];
- ((uint8_t*)d)[ 6] ^= ((uint8_t*)s)[ 6];
- ((uint8_t*)d)[ 7] ^= ((uint8_t*)s)[ 7];
- ((uint8_t*)d)[ 8] ^= ((uint8_t*)s)[ 8];
- ((uint8_t*)d)[ 9] ^= ((uint8_t*)s)[ 9];
- ((uint8_t*)d)[10] ^= ((uint8_t*)s)[10];
- ((uint8_t*)d)[11] ^= ((uint8_t*)s)[11];
- ((uint8_t*)d)[12] ^= ((uint8_t*)s)[12];
- ((uint8_t*)d)[13] ^= ((uint8_t*)s)[13];
- ((uint8_t*)d)[14] ^= ((uint8_t*)s)[14];
- ((uint8_t*)d)[15] ^= ((uint8_t*)s)[15];
-#endif
-}
-
-static void copy_and_key( void *d, const void *s, const void *k )
-{
-#if defined( HAVE_UINT_32T )
- ((uint32_t*)d)[ 0] = ((uint32_t*)s)[ 0] ^ ((uint32_t*)k)[ 0];
- ((uint32_t*)d)[ 1] = ((uint32_t*)s)[ 1] ^ ((uint32_t*)k)[ 1];
- ((uint32_t*)d)[ 2] = ((uint32_t*)s)[ 2] ^ ((uint32_t*)k)[ 2];
- ((uint32_t*)d)[ 3] = ((uint32_t*)s)[ 3] ^ ((uint32_t*)k)[ 3];
-#elif 1
- ((uint8_t*)d)[ 0] = ((uint8_t*)s)[ 0] ^ ((uint8_t*)k)[ 0];
- ((uint8_t*)d)[ 1] = ((uint8_t*)s)[ 1] ^ ((uint8_t*)k)[ 1];
- ((uint8_t*)d)[ 2] = ((uint8_t*)s)[ 2] ^ ((uint8_t*)k)[ 2];
- ((uint8_t*)d)[ 3] = ((uint8_t*)s)[ 3] ^ ((uint8_t*)k)[ 3];
- ((uint8_t*)d)[ 4] = ((uint8_t*)s)[ 4] ^ ((uint8_t*)k)[ 4];
- ((uint8_t*)d)[ 5] = ((uint8_t*)s)[ 5] ^ ((uint8_t*)k)[ 5];
- ((uint8_t*)d)[ 6] = ((uint8_t*)s)[ 6] ^ ((uint8_t*)k)[ 6];
- ((uint8_t*)d)[ 7] = ((uint8_t*)s)[ 7] ^ ((uint8_t*)k)[ 7];
- ((uint8_t*)d)[ 8] = ((uint8_t*)s)[ 8] ^ ((uint8_t*)k)[ 8];
- ((uint8_t*)d)[ 9] = ((uint8_t*)s)[ 9] ^ ((uint8_t*)k)[ 9];
- ((uint8_t*)d)[10] = ((uint8_t*)s)[10] ^ ((uint8_t*)k)[10];
- ((uint8_t*)d)[11] = ((uint8_t*)s)[11] ^ ((uint8_t*)k)[11];
- ((uint8_t*)d)[12] = ((uint8_t*)s)[12] ^ ((uint8_t*)k)[12];
- ((uint8_t*)d)[13] = ((uint8_t*)s)[13] ^ ((uint8_t*)k)[13];
- ((uint8_t*)d)[14] = ((uint8_t*)s)[14] ^ ((uint8_t*)k)[14];
- ((uint8_t*)d)[15] = ((uint8_t*)s)[15] ^ ((uint8_t*)k)[15];
-#else
- block_copy(d, s);
- xor_block(d, k);
-#endif
-}
-
-static void add_round_key( uint8_t d[N_BLOCK], const uint8_t k[N_BLOCK] )
-{
- xor_block(d, k);
-}
-
-static void shift_sub_rows( uint8_t st[N_BLOCK] )
-{ uint8_t tt;
-
- st[ 0] = s_box(st[ 0]); st[ 4] = s_box(st[ 4]);
- st[ 8] = s_box(st[ 8]); st[12] = s_box(st[12]);
-
- tt = st[1]; st[ 1] = s_box(st[ 5]); st[ 5] = s_box(st[ 9]);
- st[ 9] = s_box(st[13]); st[13] = s_box( tt );
-
- tt = st[2]; st[ 2] = s_box(st[10]); st[10] = s_box( tt );
- tt = st[6]; st[ 6] = s_box(st[14]); st[14] = s_box( tt );
-
- tt = st[15]; st[15] = s_box(st[11]); st[11] = s_box(st[ 7]);
- st[ 7] = s_box(st[ 3]); st[ 3] = s_box( tt );
-}
-
-#if defined( AES_DEC_PREKEYED )
-
-static void inv_shift_sub_rows( uint8_t st[N_BLOCK] )
-{ uint8_t tt;
-
- st[ 0] = is_box(st[ 0]); st[ 4] = is_box(st[ 4]);
- st[ 8] = is_box(st[ 8]); st[12] = is_box(st[12]);
-
- tt = st[13]; st[13] = is_box(st[9]); st[ 9] = is_box(st[5]);
- st[ 5] = is_box(st[1]); st[ 1] = is_box( tt );
-
- tt = st[2]; st[ 2] = is_box(st[10]); st[10] = is_box( tt );
- tt = st[6]; st[ 6] = is_box(st[14]); st[14] = is_box( tt );
-
- tt = st[3]; st[ 3] = is_box(st[ 7]); st[ 7] = is_box(st[11]);
- st[11] = is_box(st[15]); st[15] = is_box( tt );
-}
-
-#endif
-
-#if defined( VERSION_1 )
- static void mix_sub_columns( uint8_t dt[N_BLOCK] )
- { uint8_t st[N_BLOCK];
- block_copy(st, dt);
-#else
- static void mix_sub_columns( uint8_t dt[N_BLOCK], uint8_t st[N_BLOCK] )
- {
-#endif
- dt[ 0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]);
- dt[ 1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]);
- dt[ 2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]);
- dt[ 3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]);
-
- dt[ 4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]);
- dt[ 5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]);
- dt[ 6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]);
- dt[ 7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]);
-
- dt[ 8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]);
- dt[ 9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]);
- dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]);
- dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]);
-
- dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]);
- dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]);
- dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]);
- dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]);
- }
-
-#if defined( AES_DEC_PREKEYED )
-
-#if defined( VERSION_1 )
- static void inv_mix_sub_columns( uint8_t dt[N_BLOCK] )
- { uint8_t st[N_BLOCK];
- block_copy(st, dt);
-#else
- static void inv_mix_sub_columns( uint8_t dt[N_BLOCK], uint8_t st[N_BLOCK] )
- {
-#endif
- dt[ 0] = is_box(gfm_e(st[ 0]) ^ gfm_b(st[ 1]) ^ gfm_d(st[ 2]) ^ gfm_9(st[ 3]));
- dt[ 5] = is_box(gfm_9(st[ 0]) ^ gfm_e(st[ 1]) ^ gfm_b(st[ 2]) ^ gfm_d(st[ 3]));
- dt[10] = is_box(gfm_d(st[ 0]) ^ gfm_9(st[ 1]) ^ gfm_e(st[ 2]) ^ gfm_b(st[ 3]));
- dt[15] = is_box(gfm_b(st[ 0]) ^ gfm_d(st[ 1]) ^ gfm_9(st[ 2]) ^ gfm_e(st[ 3]));
-
- dt[ 4] = is_box(gfm_e(st[ 4]) ^ gfm_b(st[ 5]) ^ gfm_d(st[ 6]) ^ gfm_9(st[ 7]));
- dt[ 9] = is_box(gfm_9(st[ 4]) ^ gfm_e(st[ 5]) ^ gfm_b(st[ 6]) ^ gfm_d(st[ 7]));
- dt[14] = is_box(gfm_d(st[ 4]) ^ gfm_9(st[ 5]) ^ gfm_e(st[ 6]) ^ gfm_b(st[ 7]));
- dt[ 3] = is_box(gfm_b(st[ 4]) ^ gfm_d(st[ 5]) ^ gfm_9(st[ 6]) ^ gfm_e(st[ 7]));
-
- dt[ 8] = is_box(gfm_e(st[ 8]) ^ gfm_b(st[ 9]) ^ gfm_d(st[10]) ^ gfm_9(st[11]));
- dt[13] = is_box(gfm_9(st[ 8]) ^ gfm_e(st[ 9]) ^ gfm_b(st[10]) ^ gfm_d(st[11]));
- dt[ 2] = is_box(gfm_d(st[ 8]) ^ gfm_9(st[ 9]) ^ gfm_e(st[10]) ^ gfm_b(st[11]));
- dt[ 7] = is_box(gfm_b(st[ 8]) ^ gfm_d(st[ 9]) ^ gfm_9(st[10]) ^ gfm_e(st[11]));
-
- dt[12] = is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15]));
- dt[ 1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15]));
- dt[ 6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15]));
- dt[11] = is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15]));
- }
-
-#endif
-
-#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
-
-/* Set the cipher key for the pre-keyed version */
-
-return_type aes_set_key( const uint8_t key[], length_type keylen, aes_context ctx[1] )
-{
- uint8_t cc, rc, hi;
-
- switch( keylen )
- {
- case 16:
- case 24:
- case 32:
- break;
- default:
- ctx->rnd = 0;
- return ( uint8_t )-1;
- }
- block_copy_nn(ctx->ksch, key, keylen);
- hi = (keylen + 28) << 2;
- ctx->rnd = (hi >> 4) - 1;
- for( cc = keylen, rc = 1; cc < hi; cc += 4 )
- { uint8_t tt, t0, t1, t2, t3;
-
- t0 = ctx->ksch[cc - 4];
- t1 = ctx->ksch[cc - 3];
- t2 = ctx->ksch[cc - 2];
- t3 = ctx->ksch[cc - 1];
- if( cc % keylen == 0 )
- {
- tt = t0;
- t0 = s_box(t1) ^ rc;
- t1 = s_box(t2);
- t2 = s_box(t3);
- t3 = s_box(tt);
- rc = f2(rc);
- }
- else if( keylen > 24 && cc % keylen == 16 )
- {
- t0 = s_box(t0);
- t1 = s_box(t1);
- t2 = s_box(t2);
- t3 = s_box(t3);
- }
- tt = cc - keylen;
- ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0;
- ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1;
- ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2;
- ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3;
- }
- return 0;
-}
-
-#endif
-
-#if defined( AES_ENC_PREKEYED )
-
-/* Encrypt a single block of 16 bytes */
-
-return_type aes_encrypt( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK], const aes_context ctx[1] )
-{
- if( ctx->rnd )
- {
- uint8_t s1[N_BLOCK], r;
- copy_and_key( s1, in, ctx->ksch );
-
- for( r = 1 ; r < ctx->rnd ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns( s1 );
- add_round_key( s1, ctx->ksch + r * N_BLOCK);
- }
-#else
- { uint8_t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK);
- }
-#endif
- shift_sub_rows( s1 );
- copy_and_key( out, s1, ctx->ksch + r * N_BLOCK );
- }
- else
- return ( uint8_t )-1;
- return 0;
-}
-
-/* CBC encrypt a number of blocks (input and return an IV) */
-
-return_type aes_cbc_encrypt( const uint8_t *in, uint8_t *out,
- int32_t n_block, uint8_t iv[N_BLOCK], const aes_context ctx[1] )
-{
-
- while(n_block--)
- {
- xor_block(iv, in);
- if(aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS)
- return EXIT_FAILURE;
- //memcpy(out, iv, N_BLOCK);
- block_copy(out, iv);
- in += N_BLOCK;
- out += N_BLOCK;
- }
- return EXIT_SUCCESS;
-}
-
-#endif
-
-#if defined( AES_DEC_PREKEYED )
-
-/* Decrypt a single block of 16 bytes */
-
-return_type aes_decrypt( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK], const aes_context ctx[1] )
-{
- if( ctx->rnd )
- {
- uint8_t s1[N_BLOCK], r;
- copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK );
- inv_shift_sub_rows( s1 );
-
- for( r = ctx->rnd ; --r ; )
-#if defined( VERSION_1 )
- {
- add_round_key( s1, ctx->ksch + r * N_BLOCK );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint8_t s2[N_BLOCK];
- copy_and_key( s2, s1, ctx->ksch + r * N_BLOCK );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- copy_and_key( out, s1, ctx->ksch );
- }
- else
- return -1;
- return 0;
-}
-
-/* CBC decrypt a number of blocks (input and return an IV) */
-
-return_type aes_cbc_decrypt( const uint8_t *in, uint8_t *out,
- int32_t n_block, uint8_t iv[N_BLOCK], const aes_context ctx[1] )
-{
- while(n_block--)
- { uint8_t tmp[N_BLOCK];
-
- //memcpy(tmp, in, N_BLOCK);
- block_copy(tmp, in);
- if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)
- return EXIT_FAILURE;
- xor_block(out, iv);
- //memcpy(iv, tmp, N_BLOCK);
- block_copy(iv, tmp);
- in += N_BLOCK;
- out += N_BLOCK;
- }
- return EXIT_SUCCESS;
-}
-
-#endif
-
-#if defined( AES_ENC_128_OTFK )
-
-/* The 'on the fly' encryption key update for for 128 bit keys */
-
-static void update_encrypt_key_128( uint8_t k[N_BLOCK], uint8_t *rc )
-{ uint8_t cc;
-
- k[0] ^= s_box(k[13]) ^ *rc;
- k[1] ^= s_box(k[14]);
- k[2] ^= s_box(k[15]);
- k[3] ^= s_box(k[12]);
- *rc = f2( *rc );
-
- for(cc = 4; cc < 16; cc += 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-}
-
-/* Encrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
-
-void aes_encrypt_128( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
- const uint8_t key[N_BLOCK], uint8_t o_key[N_BLOCK] )
-{ uint8_t s1[N_BLOCK], r, rc = 1;
-
- if(o_key != key)
- block_copy( o_key, key );
- copy_and_key( s1, in, o_key );
-
- for( r = 1 ; r < 10 ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns( s1 );
- update_encrypt_key_128( o_key, &rc );
- add_round_key( s1, o_key );
- }
-#else
- { uint8_t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- update_encrypt_key_128( o_key, &rc );
- copy_and_key( s1, s2, o_key );
- }
-#endif
-
- shift_sub_rows( s1 );
- update_encrypt_key_128( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_DEC_128_OTFK )
-
-/* The 'on the fly' decryption key update for for 128 bit keys */
-
-static void update_decrypt_key_128( uint8_t k[N_BLOCK], uint8_t *rc )
-{ uint8_t cc;
-
- for( cc = 12; cc > 0; cc -= 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
- *rc = d2(*rc);
- k[0] ^= s_box(k[13]) ^ *rc;
- k[1] ^= s_box(k[14]);
- k[2] ^= s_box(k[15]);
- k[3] ^= s_box(k[12]);
-}
-
-/* Decrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
-
-void aes_decrypt_128( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
- const uint8_t key[N_BLOCK], uint8_t o_key[N_BLOCK] )
-{
- uint8_t s1[N_BLOCK], r, rc = 0x6c;
- if(o_key != key)
- block_copy( o_key, key );
-
- copy_and_key( s1, in, o_key );
- inv_shift_sub_rows( s1 );
-
- for( r = 10 ; --r ; )
-#if defined( VERSION_1 )
- {
- update_decrypt_key_128( o_key, &rc );
- add_round_key( s1, o_key );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint8_t s2[N_BLOCK];
- update_decrypt_key_128( o_key, &rc );
- copy_and_key( s2, s1, o_key );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- update_decrypt_key_128( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_ENC_256_OTFK )
-
-/* The 'on the fly' encryption key update for for 256 bit keys */
-
-static void update_encrypt_key_256( uint8_t k[2 * N_BLOCK], uint8_t *rc )
-{ uint8_t cc;
-
- k[0] ^= s_box(k[29]) ^ *rc;
- k[1] ^= s_box(k[30]);
- k[2] ^= s_box(k[31]);
- k[3] ^= s_box(k[28]);
- *rc = f2( *rc );
-
- for(cc = 4; cc < 16; cc += 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- k[16] ^= s_box(k[12]);
- k[17] ^= s_box(k[13]);
- k[18] ^= s_box(k[14]);
- k[19] ^= s_box(k[15]);
-
- for( cc = 20; cc < 32; cc += 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-}
-
-/* Encrypt a single block of 16 bytes with 'on the fly' 256 bit keying */
-
-void aes_encrypt_256( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
- const uint8_t key[2 * N_BLOCK], uint8_t o_key[2 * N_BLOCK] )
-{
- uint8_t s1[N_BLOCK], r, rc = 1;
- if(o_key != key)
- {
- block_copy( o_key, key );
- block_copy( o_key + 16, key + 16 );
- }
- copy_and_key( s1, in, o_key );
-
- for( r = 1 ; r < 14 ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns(s1);
- if( r & 1 )
- add_round_key( s1, o_key + 16 );
- else
- {
- update_encrypt_key_256( o_key, &rc );
- add_round_key( s1, o_key );
- }
- }
-#else
- { uint8_t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- if( r & 1 )
- copy_and_key( s1, s2, o_key + 16 );
- else
- {
- update_encrypt_key_256( o_key, &rc );
- copy_and_key( s1, s2, o_key );
- }
- }
-#endif
-
- shift_sub_rows( s1 );
- update_encrypt_key_256( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_DEC_256_OTFK )
-
-/* The 'on the fly' encryption key update for for 256 bit keys */
-
-static void update_decrypt_key_256( uint8_t k[2 * N_BLOCK], uint8_t *rc )
-{ uint8_t cc;
-
- for(cc = 28; cc > 16; cc -= 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- k[16] ^= s_box(k[12]);
- k[17] ^= s_box(k[13]);
- k[18] ^= s_box(k[14]);
- k[19] ^= s_box(k[15]);
-
- for(cc = 12; cc > 0; cc -= 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- *rc = d2(*rc);
- k[0] ^= s_box(k[29]) ^ *rc;
- k[1] ^= s_box(k[30]);
- k[2] ^= s_box(k[31]);
- k[3] ^= s_box(k[28]);
-}
-
-/* Decrypt a single block of 16 bytes with 'on the fly'
- 256 bit keying
-*/
-void aes_decrypt_256( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
- const uint8_t key[2 * N_BLOCK], uint8_t o_key[2 * N_BLOCK] )
-{
- uint8_t s1[N_BLOCK], r, rc = 0x80;
-
- if(o_key != key)
- {
- block_copy( o_key, key );
- block_copy( o_key + 16, key + 16 );
- }
-
- copy_and_key( s1, in, o_key );
- inv_shift_sub_rows( s1 );
-
- for( r = 14 ; --r ; )
-#if defined( VERSION_1 )
- {
- if( ( r & 1 ) )
- {
- update_decrypt_key_256( o_key, &rc );
- add_round_key( s1, o_key + 16 );
- }
- else
- add_round_key( s1, o_key );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint8_t s2[N_BLOCK];
- if( ( r & 1 ) )
- {
- update_decrypt_key_256( o_key, &rc );
- copy_and_key( s2, s1, o_key + 16 );
- }
- else
- copy_and_key( s2, s1, o_key );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- copy_and_key( out, s1, o_key );
-}
-
-#endif
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The redistribution and use of this software (with or without changes)
+ is allowed without the payment of fees or royalties provided that:
+
+ 1. source code distributions include the above copyright notice, this
+ list of conditions and the following disclaimer;
+
+ 2. binary distributions include the above copyright notice, this list
+ of conditions and the following disclaimer in their documentation;
+
+ 3. the name of the copyright holder is not used to endorse products
+ built using this software without specific written permission.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 09/09/2006
+
+ This is an AES implementation that uses only 8-bit byte operations on the
+ cipher state (there are options to use 32-bit types if available).
+
+ The combination of mix columns and byte substitution used here is based on
+ that developed by Karl Malbrain. His contribution is acknowledged.
+ */
+
+/* define if you have a fast memcpy function on your system */
+#if 0
+# define HAVE_MEMCPY
+# include
+# if defined( _MSC_VER )
+# include
+# pragma intrinsic( memcpy )
+# endif
+#endif
+
+
+#include
+#include
+
+/* define if you have fast 32-bit types on your system */
+#if ( __CORTEX_M != 0 ) // if Cortex is different from M0/M0+
+# define HAVE_UINT_32T
+#endif
+
+/* define if you don't want any tables */
+#if 1
+# define USE_TABLES
+#endif
+
+/* On Intel Core 2 duo VERSION_1 is faster */
+
+/* alternative versions (test for performance on your system) */
+#if 1
+# define VERSION_1
+#endif
+
+#include "aes.h"
+
+//#if defined( HAVE_UINT_32T )
+// typedef unsigned long uint32_t;
+//#endif
+
+/* functions for finite field multiplication in the AES Galois field */
+
+#define WPOLY 0x011b
+#define BPOLY 0x1b
+#define DPOLY 0x008d
+
+#define f1(x) (x)
+#define f2(x) ((x << 1) ^ (((x >> 7) & 1) * WPOLY))
+#define f4(x) ((x << 2) ^ (((x >> 6) & 1) * WPOLY) ^ (((x >> 6) & 2) * WPOLY))
+#define f8(x) ((x << 3) ^ (((x >> 5) & 1) * WPOLY) ^ (((x >> 5) & 2) * WPOLY) \
+ ^ (((x >> 5) & 4) * WPOLY))
+#define d2(x) (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0))
+
+#define f3(x) (f2(x) ^ x)
+#define f9(x) (f8(x) ^ x)
+#define fb(x) (f8(x) ^ f2(x) ^ x)
+#define fd(x) (f8(x) ^ f4(x) ^ x)
+#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
+
+#if defined( USE_TABLES )
+
+#define sb_data(w) { /* S Box data values */ \
+ w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
+ w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
+ w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
+ w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
+ w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
+ w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
+ w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
+ w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
+ w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
+ w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
+ w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
+ w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
+ w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
+ w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
+ w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
+ w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
+ w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
+ w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
+ w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
+ w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
+ w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
+ w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
+ w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
+ w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
+ w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
+ w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
+ w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
+ w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
+ w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
+ w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
+ w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
+ w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
+
+#define isb_data(w) { /* inverse S Box data values */ \
+ w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\
+ w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\
+ w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\
+ w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\
+ w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\
+ w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\
+ w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\
+ w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\
+ w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\
+ w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\
+ w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\
+ w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\
+ w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\
+ w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\
+ w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\
+ w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\
+ w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\
+ w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\
+ w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\
+ w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\
+ w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\
+ w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\
+ w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\
+ w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\
+ w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\
+ w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\
+ w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\
+ w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\
+ w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\
+ w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\
+ w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\
+ w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }
+
+#define mm_data(w) { /* basic data for forming finite field tables */ \
+ w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\
+ w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\
+ w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\
+ w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\
+ w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\
+ w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\
+ w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\
+ w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\
+ w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\
+ w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\
+ w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\
+ w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\
+ w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\
+ w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\
+ w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\
+ w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\
+ w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\
+ w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\
+ w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\
+ w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\
+ w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\
+ w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\
+ w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\
+ w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\
+ w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\
+ w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\
+ w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\
+ w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\
+ w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\
+ w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\
+ w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\
+ w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }
+
+static const uint8_t sbox[256] = sb_data(f1);
+
+#if defined( AES_DEC_PREKEYED )
+static const uint8_t isbox[256] = isb_data(f1);
+#endif
+
+static const uint8_t gfm2_sbox[256] = sb_data(f2);
+static const uint8_t gfm3_sbox[256] = sb_data(f3);
+
+#if defined( AES_DEC_PREKEYED )
+static const uint8_t gfmul_9[256] = mm_data(f9);
+static const uint8_t gfmul_b[256] = mm_data(fb);
+static const uint8_t gfmul_d[256] = mm_data(fd);
+static const uint8_t gfmul_e[256] = mm_data(fe);
+#endif
+
+#define s_box(x) sbox[(x)]
+#if defined( AES_DEC_PREKEYED )
+#define is_box(x) isbox[(x)]
+#endif
+#define gfm2_sb(x) gfm2_sbox[(x)]
+#define gfm3_sb(x) gfm3_sbox[(x)]
+#if defined( AES_DEC_PREKEYED )
+#define gfm_9(x) gfmul_9[(x)]
+#define gfm_b(x) gfmul_b[(x)]
+#define gfm_d(x) gfmul_d[(x)]
+#define gfm_e(x) gfmul_e[(x)]
+#endif
+#else
+
+/* this is the high bit of x right shifted by 1 */
+/* position. Since the starting polynomial has */
+/* 9 bits (0x11b), this right shift keeps the */
+/* values of all top bits within a byte */
+
+static uint8_t hibit(const uint8_t x)
+{ uint8_t r = (uint8_t)((x >> 1) | (x >> 2));
+
+ r |= (r >> 2);
+ r |= (r >> 4);
+ return (r + 1) >> 1;
+}
+
+/* return the inverse of the finite field element x */
+
+static uint8_t gf_inv(const uint8_t x)
+{ uint8_t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0;
+
+ if(x < 2)
+ return x;
+
+ for( ; ; )
+ {
+ if(n1)
+ while(n2 >= n1) /* divide polynomial p2 by p1 */
+ {
+ n2 /= n1; /* shift smaller polynomial left */
+ p2 ^= (p1 * n2) & 0xff; /* and remove from larger one */
+ v2 ^= (v1 * n2); /* shift accumulated value and */
+ n2 = hibit(p2); /* add into result */
+ }
+ else
+ return v1;
+
+ if(n2) /* repeat with values swapped */
+ while(n1 >= n2)
+ {
+ n1 /= n2;
+ p1 ^= p2 * n1;
+ v1 ^= v2 * n1;
+ n1 = hibit(p1);
+ }
+ else
+ return v2;
+ }
+}
+
+/* The forward and inverse affine transformations used in the S-box */
+uint8_t fwd_affine(const uint8_t x)
+{
+#if defined( HAVE_UINT_32T )
+ uint32_t w = x;
+ w ^= (w << 1) ^ (w << 2) ^ (w << 3) ^ (w << 4);
+ return 0x63 ^ ((w ^ (w >> 8)) & 0xff);
+#else
+ return 0x63 ^ x ^ (x << 1) ^ (x << 2) ^ (x << 3) ^ (x << 4)
+ ^ (x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4);
+#endif
+}
+
+uint8_t inv_affine(const uint8_t x)
+{
+#if defined( HAVE_UINT_32T )
+ uint32_t w = x;
+ w = (w << 1) ^ (w << 3) ^ (w << 6);
+ return 0x05 ^ ((w ^ (w >> 8)) & 0xff);
+#else
+ return 0x05 ^ (x << 1) ^ (x << 3) ^ (x << 6)
+ ^ (x >> 7) ^ (x >> 5) ^ (x >> 2);
+#endif
+}
+
+#define s_box(x) fwd_affine(gf_inv(x))
+#define is_box(x) gf_inv(inv_affine(x))
+#define gfm2_sb(x) f2(s_box(x))
+#define gfm3_sb(x) f3(s_box(x))
+#define gfm_9(x) f9(x)
+#define gfm_b(x) fb(x)
+#define gfm_d(x) fd(x)
+#define gfm_e(x) fe(x)
+
+#endif
+
+#if defined( HAVE_MEMCPY )
+# define block_copy_nn(d, s, l) memcpy(d, s, l)
+# define block_copy(d, s) memcpy(d, s, N_BLOCK)
+#else
+# define block_copy_nn(d, s, l) copy_block_nn(d, s, l)
+# define block_copy(d, s) copy_block(d, s)
+#endif
+
+static void copy_block( void *d, const void *s )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint32_t*)d)[ 0] = ((uint32_t*)s)[ 0];
+ ((uint32_t*)d)[ 1] = ((uint32_t*)s)[ 1];
+ ((uint32_t*)d)[ 2] = ((uint32_t*)s)[ 2];
+ ((uint32_t*)d)[ 3] = ((uint32_t*)s)[ 3];
+#else
+ ((uint8_t*)d)[ 0] = ((uint8_t*)s)[ 0];
+ ((uint8_t*)d)[ 1] = ((uint8_t*)s)[ 1];
+ ((uint8_t*)d)[ 2] = ((uint8_t*)s)[ 2];
+ ((uint8_t*)d)[ 3] = ((uint8_t*)s)[ 3];
+ ((uint8_t*)d)[ 4] = ((uint8_t*)s)[ 4];
+ ((uint8_t*)d)[ 5] = ((uint8_t*)s)[ 5];
+ ((uint8_t*)d)[ 6] = ((uint8_t*)s)[ 6];
+ ((uint8_t*)d)[ 7] = ((uint8_t*)s)[ 7];
+ ((uint8_t*)d)[ 8] = ((uint8_t*)s)[ 8];
+ ((uint8_t*)d)[ 9] = ((uint8_t*)s)[ 9];
+ ((uint8_t*)d)[10] = ((uint8_t*)s)[10];
+ ((uint8_t*)d)[11] = ((uint8_t*)s)[11];
+ ((uint8_t*)d)[12] = ((uint8_t*)s)[12];
+ ((uint8_t*)d)[13] = ((uint8_t*)s)[13];
+ ((uint8_t*)d)[14] = ((uint8_t*)s)[14];
+ ((uint8_t*)d)[15] = ((uint8_t*)s)[15];
+#endif
+}
+
+static void copy_block_nn( uint8_t * d, const uint8_t *s, uint8_t nn )
+{
+ while( nn-- )
+ //*((uint8_t*)d)++ = *((uint8_t*)s)++;
+ *d++ = *s++;
+}
+
+static void xor_block( void *d, const void *s )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint32_t*)d)[ 0] ^= ((uint32_t*)s)[ 0];
+ ((uint32_t*)d)[ 1] ^= ((uint32_t*)s)[ 1];
+ ((uint32_t*)d)[ 2] ^= ((uint32_t*)s)[ 2];
+ ((uint32_t*)d)[ 3] ^= ((uint32_t*)s)[ 3];
+#else
+ ((uint8_t*)d)[ 0] ^= ((uint8_t*)s)[ 0];
+ ((uint8_t*)d)[ 1] ^= ((uint8_t*)s)[ 1];
+ ((uint8_t*)d)[ 2] ^= ((uint8_t*)s)[ 2];
+ ((uint8_t*)d)[ 3] ^= ((uint8_t*)s)[ 3];
+ ((uint8_t*)d)[ 4] ^= ((uint8_t*)s)[ 4];
+ ((uint8_t*)d)[ 5] ^= ((uint8_t*)s)[ 5];
+ ((uint8_t*)d)[ 6] ^= ((uint8_t*)s)[ 6];
+ ((uint8_t*)d)[ 7] ^= ((uint8_t*)s)[ 7];
+ ((uint8_t*)d)[ 8] ^= ((uint8_t*)s)[ 8];
+ ((uint8_t*)d)[ 9] ^= ((uint8_t*)s)[ 9];
+ ((uint8_t*)d)[10] ^= ((uint8_t*)s)[10];
+ ((uint8_t*)d)[11] ^= ((uint8_t*)s)[11];
+ ((uint8_t*)d)[12] ^= ((uint8_t*)s)[12];
+ ((uint8_t*)d)[13] ^= ((uint8_t*)s)[13];
+ ((uint8_t*)d)[14] ^= ((uint8_t*)s)[14];
+ ((uint8_t*)d)[15] ^= ((uint8_t*)s)[15];
+#endif
+}
+
+static void copy_and_key( void *d, const void *s, const void *k )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint32_t*)d)[ 0] = ((uint32_t*)s)[ 0] ^ ((uint32_t*)k)[ 0];
+ ((uint32_t*)d)[ 1] = ((uint32_t*)s)[ 1] ^ ((uint32_t*)k)[ 1];
+ ((uint32_t*)d)[ 2] = ((uint32_t*)s)[ 2] ^ ((uint32_t*)k)[ 2];
+ ((uint32_t*)d)[ 3] = ((uint32_t*)s)[ 3] ^ ((uint32_t*)k)[ 3];
+#elif 1
+ ((uint8_t*)d)[ 0] = ((uint8_t*)s)[ 0] ^ ((uint8_t*)k)[ 0];
+ ((uint8_t*)d)[ 1] = ((uint8_t*)s)[ 1] ^ ((uint8_t*)k)[ 1];
+ ((uint8_t*)d)[ 2] = ((uint8_t*)s)[ 2] ^ ((uint8_t*)k)[ 2];
+ ((uint8_t*)d)[ 3] = ((uint8_t*)s)[ 3] ^ ((uint8_t*)k)[ 3];
+ ((uint8_t*)d)[ 4] = ((uint8_t*)s)[ 4] ^ ((uint8_t*)k)[ 4];
+ ((uint8_t*)d)[ 5] = ((uint8_t*)s)[ 5] ^ ((uint8_t*)k)[ 5];
+ ((uint8_t*)d)[ 6] = ((uint8_t*)s)[ 6] ^ ((uint8_t*)k)[ 6];
+ ((uint8_t*)d)[ 7] = ((uint8_t*)s)[ 7] ^ ((uint8_t*)k)[ 7];
+ ((uint8_t*)d)[ 8] = ((uint8_t*)s)[ 8] ^ ((uint8_t*)k)[ 8];
+ ((uint8_t*)d)[ 9] = ((uint8_t*)s)[ 9] ^ ((uint8_t*)k)[ 9];
+ ((uint8_t*)d)[10] = ((uint8_t*)s)[10] ^ ((uint8_t*)k)[10];
+ ((uint8_t*)d)[11] = ((uint8_t*)s)[11] ^ ((uint8_t*)k)[11];
+ ((uint8_t*)d)[12] = ((uint8_t*)s)[12] ^ ((uint8_t*)k)[12];
+ ((uint8_t*)d)[13] = ((uint8_t*)s)[13] ^ ((uint8_t*)k)[13];
+ ((uint8_t*)d)[14] = ((uint8_t*)s)[14] ^ ((uint8_t*)k)[14];
+ ((uint8_t*)d)[15] = ((uint8_t*)s)[15] ^ ((uint8_t*)k)[15];
+#else
+ block_copy(d, s);
+ xor_block(d, k);
+#endif
+}
+
+static void add_round_key( uint8_t d[N_BLOCK], const uint8_t k[N_BLOCK] )
+{
+ xor_block(d, k);
+}
+
+static void shift_sub_rows( uint8_t st[N_BLOCK] )
+{ uint8_t tt;
+
+ st[ 0] = s_box(st[ 0]); st[ 4] = s_box(st[ 4]);
+ st[ 8] = s_box(st[ 8]); st[12] = s_box(st[12]);
+
+ tt = st[1]; st[ 1] = s_box(st[ 5]); st[ 5] = s_box(st[ 9]);
+ st[ 9] = s_box(st[13]); st[13] = s_box( tt );
+
+ tt = st[2]; st[ 2] = s_box(st[10]); st[10] = s_box( tt );
+ tt = st[6]; st[ 6] = s_box(st[14]); st[14] = s_box( tt );
+
+ tt = st[15]; st[15] = s_box(st[11]); st[11] = s_box(st[ 7]);
+ st[ 7] = s_box(st[ 3]); st[ 3] = s_box( tt );
+}
+
+#if defined( AES_DEC_PREKEYED )
+
+static void inv_shift_sub_rows( uint8_t st[N_BLOCK] )
+{ uint8_t tt;
+
+ st[ 0] = is_box(st[ 0]); st[ 4] = is_box(st[ 4]);
+ st[ 8] = is_box(st[ 8]); st[12] = is_box(st[12]);
+
+ tt = st[13]; st[13] = is_box(st[9]); st[ 9] = is_box(st[5]);
+ st[ 5] = is_box(st[1]); st[ 1] = is_box( tt );
+
+ tt = st[2]; st[ 2] = is_box(st[10]); st[10] = is_box( tt );
+ tt = st[6]; st[ 6] = is_box(st[14]); st[14] = is_box( tt );
+
+ tt = st[3]; st[ 3] = is_box(st[ 7]); st[ 7] = is_box(st[11]);
+ st[11] = is_box(st[15]); st[15] = is_box( tt );
+}
+
+#endif
+
+#if defined( VERSION_1 )
+ static void mix_sub_columns( uint8_t dt[N_BLOCK] )
+ { uint8_t st[N_BLOCK];
+ block_copy(st, dt);
+#else
+ static void mix_sub_columns( uint8_t dt[N_BLOCK], uint8_t st[N_BLOCK] )
+ {
+#endif
+ dt[ 0] = gfm2_sb(st[0]) ^ gfm3_sb(st[5]) ^ s_box(st[10]) ^ s_box(st[15]);
+ dt[ 1] = s_box(st[0]) ^ gfm2_sb(st[5]) ^ gfm3_sb(st[10]) ^ s_box(st[15]);
+ dt[ 2] = s_box(st[0]) ^ s_box(st[5]) ^ gfm2_sb(st[10]) ^ gfm3_sb(st[15]);
+ dt[ 3] = gfm3_sb(st[0]) ^ s_box(st[5]) ^ s_box(st[10]) ^ gfm2_sb(st[15]);
+
+ dt[ 4] = gfm2_sb(st[4]) ^ gfm3_sb(st[9]) ^ s_box(st[14]) ^ s_box(st[3]);
+ dt[ 5] = s_box(st[4]) ^ gfm2_sb(st[9]) ^ gfm3_sb(st[14]) ^ s_box(st[3]);
+ dt[ 6] = s_box(st[4]) ^ s_box(st[9]) ^ gfm2_sb(st[14]) ^ gfm3_sb(st[3]);
+ dt[ 7] = gfm3_sb(st[4]) ^ s_box(st[9]) ^ s_box(st[14]) ^ gfm2_sb(st[3]);
+
+ dt[ 8] = gfm2_sb(st[8]) ^ gfm3_sb(st[13]) ^ s_box(st[2]) ^ s_box(st[7]);
+ dt[ 9] = s_box(st[8]) ^ gfm2_sb(st[13]) ^ gfm3_sb(st[2]) ^ s_box(st[7]);
+ dt[10] = s_box(st[8]) ^ s_box(st[13]) ^ gfm2_sb(st[2]) ^ gfm3_sb(st[7]);
+ dt[11] = gfm3_sb(st[8]) ^ s_box(st[13]) ^ s_box(st[2]) ^ gfm2_sb(st[7]);
+
+ dt[12] = gfm2_sb(st[12]) ^ gfm3_sb(st[1]) ^ s_box(st[6]) ^ s_box(st[11]);
+ dt[13] = s_box(st[12]) ^ gfm2_sb(st[1]) ^ gfm3_sb(st[6]) ^ s_box(st[11]);
+ dt[14] = s_box(st[12]) ^ s_box(st[1]) ^ gfm2_sb(st[6]) ^ gfm3_sb(st[11]);
+ dt[15] = gfm3_sb(st[12]) ^ s_box(st[1]) ^ s_box(st[6]) ^ gfm2_sb(st[11]);
+ }
+
+#if defined( AES_DEC_PREKEYED )
+
+#if defined( VERSION_1 )
+ static void inv_mix_sub_columns( uint8_t dt[N_BLOCK] )
+ { uint8_t st[N_BLOCK];
+ block_copy(st, dt);
+#else
+ static void inv_mix_sub_columns( uint8_t dt[N_BLOCK], uint8_t st[N_BLOCK] )
+ {
+#endif
+ dt[ 0] = is_box(gfm_e(st[ 0]) ^ gfm_b(st[ 1]) ^ gfm_d(st[ 2]) ^ gfm_9(st[ 3]));
+ dt[ 5] = is_box(gfm_9(st[ 0]) ^ gfm_e(st[ 1]) ^ gfm_b(st[ 2]) ^ gfm_d(st[ 3]));
+ dt[10] = is_box(gfm_d(st[ 0]) ^ gfm_9(st[ 1]) ^ gfm_e(st[ 2]) ^ gfm_b(st[ 3]));
+ dt[15] = is_box(gfm_b(st[ 0]) ^ gfm_d(st[ 1]) ^ gfm_9(st[ 2]) ^ gfm_e(st[ 3]));
+
+ dt[ 4] = is_box(gfm_e(st[ 4]) ^ gfm_b(st[ 5]) ^ gfm_d(st[ 6]) ^ gfm_9(st[ 7]));
+ dt[ 9] = is_box(gfm_9(st[ 4]) ^ gfm_e(st[ 5]) ^ gfm_b(st[ 6]) ^ gfm_d(st[ 7]));
+ dt[14] = is_box(gfm_d(st[ 4]) ^ gfm_9(st[ 5]) ^ gfm_e(st[ 6]) ^ gfm_b(st[ 7]));
+ dt[ 3] = is_box(gfm_b(st[ 4]) ^ gfm_d(st[ 5]) ^ gfm_9(st[ 6]) ^ gfm_e(st[ 7]));
+
+ dt[ 8] = is_box(gfm_e(st[ 8]) ^ gfm_b(st[ 9]) ^ gfm_d(st[10]) ^ gfm_9(st[11]));
+ dt[13] = is_box(gfm_9(st[ 8]) ^ gfm_e(st[ 9]) ^ gfm_b(st[10]) ^ gfm_d(st[11]));
+ dt[ 2] = is_box(gfm_d(st[ 8]) ^ gfm_9(st[ 9]) ^ gfm_e(st[10]) ^ gfm_b(st[11]));
+ dt[ 7] = is_box(gfm_b(st[ 8]) ^ gfm_d(st[ 9]) ^ gfm_9(st[10]) ^ gfm_e(st[11]));
+
+ dt[12] = is_box(gfm_e(st[12]) ^ gfm_b(st[13]) ^ gfm_d(st[14]) ^ gfm_9(st[15]));
+ dt[ 1] = is_box(gfm_9(st[12]) ^ gfm_e(st[13]) ^ gfm_b(st[14]) ^ gfm_d(st[15]));
+ dt[ 6] = is_box(gfm_d(st[12]) ^ gfm_9(st[13]) ^ gfm_e(st[14]) ^ gfm_b(st[15]));
+ dt[11] = is_box(gfm_b(st[12]) ^ gfm_d(st[13]) ^ gfm_9(st[14]) ^ gfm_e(st[15]));
+ }
+
+#endif
+
+#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
+
+/* Set the cipher key for the pre-keyed version */
+
+return_type aes_set_key( const uint8_t key[], length_type keylen, aes_context ctx[1] )
+{
+ uint8_t cc, rc, hi;
+
+ switch( keylen )
+ {
+ case 16:
+ case 24:
+ case 32:
+ break;
+ default:
+ ctx->rnd = 0;
+ return ( uint8_t )-1;
+ }
+ block_copy_nn(ctx->ksch, key, keylen);
+ hi = (keylen + 28) << 2;
+ ctx->rnd = (hi >> 4) - 1;
+ for( cc = keylen, rc = 1; cc < hi; cc += 4 )
+ { uint8_t tt, t0, t1, t2, t3;
+
+ t0 = ctx->ksch[cc - 4];
+ t1 = ctx->ksch[cc - 3];
+ t2 = ctx->ksch[cc - 2];
+ t3 = ctx->ksch[cc - 1];
+ if( cc % keylen == 0 )
+ {
+ tt = t0;
+ t0 = s_box(t1) ^ rc;
+ t1 = s_box(t2);
+ t2 = s_box(t3);
+ t3 = s_box(tt);
+ rc = f2(rc);
+ }
+ else if( keylen > 24 && cc % keylen == 16 )
+ {
+ t0 = s_box(t0);
+ t1 = s_box(t1);
+ t2 = s_box(t2);
+ t3 = s_box(t3);
+ }
+ tt = cc - keylen;
+ ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0;
+ ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1;
+ ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2;
+ ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3;
+ }
+ return 0;
+}
+
+#endif
+
+#if defined( AES_ENC_PREKEYED )
+
+/* Encrypt a single block of 16 bytes */
+
+return_type aes_encrypt( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK], const aes_context ctx[1] )
+{
+ if( ctx->rnd )
+ {
+ uint8_t s1[N_BLOCK], r;
+ copy_and_key( s1, in, ctx->ksch );
+
+ for( r = 1 ; r < ctx->rnd ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns( s1 );
+ add_round_key( s1, ctx->ksch + r * N_BLOCK);
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK);
+ }
+#endif
+ shift_sub_rows( s1 );
+ copy_and_key( out, s1, ctx->ksch + r * N_BLOCK );
+ }
+ else
+ return ( uint8_t )-1;
+ return 0;
+}
+
+/* CBC encrypt a number of blocks (input and return an IV) */
+
+return_type aes_cbc_encrypt( const uint8_t *in, uint8_t *out,
+ int32_t n_block, uint8_t iv[N_BLOCK], const aes_context ctx[1] )
+{
+
+ while(n_block--)
+ {
+ xor_block(iv, in);
+ if(aes_encrypt(iv, iv, ctx) != EXIT_SUCCESS)
+ return EXIT_FAILURE;
+ //memcpy(out, iv, N_BLOCK);
+ block_copy(out, iv);
+ in += N_BLOCK;
+ out += N_BLOCK;
+ }
+ return EXIT_SUCCESS;
+}
+
+#endif
+
+#if defined( AES_DEC_PREKEYED )
+
+/* Decrypt a single block of 16 bytes */
+
+return_type aes_decrypt( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK], const aes_context ctx[1] )
+{
+ if( ctx->rnd )
+ {
+ uint8_t s1[N_BLOCK], r;
+ copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK );
+ inv_shift_sub_rows( s1 );
+
+ for( r = ctx->rnd ; --r ; )
+#if defined( VERSION_1 )
+ {
+ add_round_key( s1, ctx->ksch + r * N_BLOCK );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ copy_and_key( s2, s1, ctx->ksch + r * N_BLOCK );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ copy_and_key( out, s1, ctx->ksch );
+ }
+ else
+ return -1;
+ return 0;
+}
+
+/* CBC decrypt a number of blocks (input and return an IV) */
+
+return_type aes_cbc_decrypt( const uint8_t *in, uint8_t *out,
+ int32_t n_block, uint8_t iv[N_BLOCK], const aes_context ctx[1] )
+{
+ while(n_block--)
+ { uint8_t tmp[N_BLOCK];
+
+ //memcpy(tmp, in, N_BLOCK);
+ block_copy(tmp, in);
+ if(aes_decrypt(in, out, ctx) != EXIT_SUCCESS)
+ return EXIT_FAILURE;
+ xor_block(out, iv);
+ //memcpy(iv, tmp, N_BLOCK);
+ block_copy(iv, tmp);
+ in += N_BLOCK;
+ out += N_BLOCK;
+ }
+ return EXIT_SUCCESS;
+}
+
+#endif
+
+#if defined( AES_ENC_128_OTFK )
+
+/* The 'on the fly' encryption key update for for 128 bit keys */
+
+static void update_encrypt_key_128( uint8_t k[N_BLOCK], uint8_t *rc )
+{ uint8_t cc;
+
+ k[0] ^= s_box(k[13]) ^ *rc;
+ k[1] ^= s_box(k[14]);
+ k[2] ^= s_box(k[15]);
+ k[3] ^= s_box(k[12]);
+ *rc = f2( *rc );
+
+ for(cc = 4; cc < 16; cc += 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+}
+
+/* Encrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
+
+void aes_encrypt_128( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK], uint8_t o_key[N_BLOCK] )
+{ uint8_t s1[N_BLOCK], r, rc = 1;
+
+ if(o_key != key)
+ block_copy( o_key, key );
+ copy_and_key( s1, in, o_key );
+
+ for( r = 1 ; r < 10 ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns( s1 );
+ update_encrypt_key_128( o_key, &rc );
+ add_round_key( s1, o_key );
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ update_encrypt_key_128( o_key, &rc );
+ copy_and_key( s1, s2, o_key );
+ }
+#endif
+
+ shift_sub_rows( s1 );
+ update_encrypt_key_128( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_DEC_128_OTFK )
+
+/* The 'on the fly' decryption key update for for 128 bit keys */
+
+static void update_decrypt_key_128( uint8_t k[N_BLOCK], uint8_t *rc )
+{ uint8_t cc;
+
+ for( cc = 12; cc > 0; cc -= 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+ *rc = d2(*rc);
+ k[0] ^= s_box(k[13]) ^ *rc;
+ k[1] ^= s_box(k[14]);
+ k[2] ^= s_box(k[15]);
+ k[3] ^= s_box(k[12]);
+}
+
+/* Decrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
+
+void aes_decrypt_128( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK], uint8_t o_key[N_BLOCK] )
+{
+ uint8_t s1[N_BLOCK], r, rc = 0x6c;
+ if(o_key != key)
+ block_copy( o_key, key );
+
+ copy_and_key( s1, in, o_key );
+ inv_shift_sub_rows( s1 );
+
+ for( r = 10 ; --r ; )
+#if defined( VERSION_1 )
+ {
+ update_decrypt_key_128( o_key, &rc );
+ add_round_key( s1, o_key );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ update_decrypt_key_128( o_key, &rc );
+ copy_and_key( s2, s1, o_key );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ update_decrypt_key_128( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_ENC_256_OTFK )
+
+/* The 'on the fly' encryption key update for for 256 bit keys */
+
+static void update_encrypt_key_256( uint8_t k[2 * N_BLOCK], uint8_t *rc )
+{ uint8_t cc;
+
+ k[0] ^= s_box(k[29]) ^ *rc;
+ k[1] ^= s_box(k[30]);
+ k[2] ^= s_box(k[31]);
+ k[3] ^= s_box(k[28]);
+ *rc = f2( *rc );
+
+ for(cc = 4; cc < 16; cc += 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ k[16] ^= s_box(k[12]);
+ k[17] ^= s_box(k[13]);
+ k[18] ^= s_box(k[14]);
+ k[19] ^= s_box(k[15]);
+
+ for( cc = 20; cc < 32; cc += 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+}
+
+/* Encrypt a single block of 16 bytes with 'on the fly' 256 bit keying */
+
+void aes_encrypt_256( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK], uint8_t o_key[2 * N_BLOCK] )
+{
+ uint8_t s1[N_BLOCK], r, rc = 1;
+ if(o_key != key)
+ {
+ block_copy( o_key, key );
+ block_copy( o_key + 16, key + 16 );
+ }
+ copy_and_key( s1, in, o_key );
+
+ for( r = 1 ; r < 14 ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns(s1);
+ if( r & 1 )
+ add_round_key( s1, o_key + 16 );
+ else
+ {
+ update_encrypt_key_256( o_key, &rc );
+ add_round_key( s1, o_key );
+ }
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ if( r & 1 )
+ copy_and_key( s1, s2, o_key + 16 );
+ else
+ {
+ update_encrypt_key_256( o_key, &rc );
+ copy_and_key( s1, s2, o_key );
+ }
+ }
+#endif
+
+ shift_sub_rows( s1 );
+ update_encrypt_key_256( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_DEC_256_OTFK )
+
+/* The 'on the fly' encryption key update for for 256 bit keys */
+
+static void update_decrypt_key_256( uint8_t k[2 * N_BLOCK], uint8_t *rc )
+{ uint8_t cc;
+
+ for(cc = 28; cc > 16; cc -= 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ k[16] ^= s_box(k[12]);
+ k[17] ^= s_box(k[13]);
+ k[18] ^= s_box(k[14]);
+ k[19] ^= s_box(k[15]);
+
+ for(cc = 12; cc > 0; cc -= 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ *rc = d2(*rc);
+ k[0] ^= s_box(k[29]) ^ *rc;
+ k[1] ^= s_box(k[30]);
+ k[2] ^= s_box(k[31]);
+ k[3] ^= s_box(k[28]);
+}
+
+/* Decrypt a single block of 16 bytes with 'on the fly'
+ 256 bit keying
+*/
+void aes_decrypt_256( const uint8_t in[N_BLOCK], uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK], uint8_t o_key[2 * N_BLOCK] )
+{
+ uint8_t s1[N_BLOCK], r, rc = 0x80;
+
+ if(o_key != key)
+ {
+ block_copy( o_key, key );
+ block_copy( o_key + 16, key + 16 );
+ }
+
+ copy_and_key( s1, in, o_key );
+ inv_shift_sub_rows( s1 );
+
+ for( r = 14 ; --r ; )
+#if defined( VERSION_1 )
+ {
+ if( ( r & 1 ) )
+ {
+ update_decrypt_key_256( o_key, &rc );
+ add_round_key( s1, o_key + 16 );
+ }
+ else
+ add_round_key( s1, o_key );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint8_t s2[N_BLOCK];
+ if( ( r & 1 ) )
+ {
+ update_decrypt_key_256( o_key, &rc );
+ copy_and_key( s2, s1, o_key + 16 );
+ }
+ else
+ copy_and_key( s2, s1, o_key );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.h
index 3272d9c..b4f9f40 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/aes.h
@@ -1,170 +1,170 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
-
- LICENSE TERMS
-
- The redistribution and use of this software (with or without changes)
- is allowed without the payment of fees or royalties provided that:
-
- 1. source code distributions include the above copyright notice, this
- list of conditions and the following disclaimer;
-
- 2. binary distributions include the above copyright notice, this list
- of conditions and the following disclaimer in their documentation;
-
- 3. the name of the copyright holder is not used to endorse products
- built using this software without specific written permission.
-
- DISCLAIMER
-
- This software is provided 'as is' with no explicit or implied warranties
- in respect of its properties, including, but not limited to, correctness
- and/or fitness for purpose.
- ---------------------------------------------------------------------------
- Issue 09/09/2006
-
- This is an AES implementation that uses only 8-bit byte operations on the
- cipher state.
- */
-
-#ifndef AES_H
-#define AES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#if 1
-# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
-#endif
-#if 0
-# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
-#endif
-#if 0
-# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
-#endif
-#if 0
-# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
-#endif
-#if 0
-# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
-#endif
-#if 0
-# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
-#endif
-
-#define N_ROW 4
-#define N_COL 4
-#define N_BLOCK (N_ROW * N_COL)
-#define N_MAX_ROUNDS 14
-
-typedef uint8_t return_type;
-
-/* Warning: The key length for 256 bit keys overflows a byte
- (see comment below)
-*/
-
-typedef uint8_t length_type;
-
-typedef struct
-{ uint8_t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
- uint8_t rnd;
-} aes_context;
-
-/* The following calls are for a precomputed key schedule
-
- NOTE: If the length_type used for the key length is an
- unsigned 8-bit character, a key length of 256 bits must
- be entered as a length in bytes (valid inputs are hence
- 128, 192, 16, 24 and 32).
-*/
-
-#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
-
-return_type aes_set_key( const uint8_t key[],
- length_type keylen,
- aes_context ctx[1] );
-#endif
-
-#if defined( AES_ENC_PREKEYED )
-
-return_type aes_encrypt( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const aes_context ctx[1] );
-
-return_type aes_cbc_encrypt( const uint8_t *in,
- uint8_t *out,
- int32_t n_block,
- uint8_t iv[N_BLOCK],
- const aes_context ctx[1] );
-#endif
-
-#if defined( AES_DEC_PREKEYED )
-
-return_type aes_decrypt( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const aes_context ctx[1] );
-
-return_type aes_cbc_decrypt( const uint8_t *in,
- uint8_t *out,
- int32_t n_block,
- uint8_t iv[N_BLOCK],
- const aes_context ctx[1] );
-#endif
-
-/* The following calls are for 'on the fly' keying. In this case the
- encryption and decryption keys are different.
-
- The encryption subroutines take a key in an array of bytes in
- key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
- 192, and 256 bits respectively. They then encrypts the input
- data, in[] with this key and put the reult in the output array
- out[]. In addition, the second key array, o_key[L], is used
- to output the key that is needed by the decryption subroutine
- to reverse the encryption operation. The two key arrays can
- be the same array but in this case the original key will be
- overwritten.
-
- In the same way, the decryption subroutines output keys that
- can be used to reverse their effect when used for encryption.
-
- Only 128 and 256 bit keys are supported in these 'on the fly'
- modes.
-*/
-
-#if defined( AES_ENC_128_OTFK )
-void aes_encrypt_128( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const uint8_t key[N_BLOCK],
- uint8_t o_key[N_BLOCK] );
-#endif
-
-#if defined( AES_DEC_128_OTFK )
-void aes_decrypt_128( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const uint8_t key[N_BLOCK],
- uint8_t o_key[N_BLOCK] );
-#endif
-
-#if defined( AES_ENC_256_OTFK )
-void aes_encrypt_256( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const uint8_t key[2 * N_BLOCK],
- uint8_t o_key[2 * N_BLOCK] );
-#endif
-
-#if defined( AES_DEC_256_OTFK )
-void aes_decrypt_256( const uint8_t in[N_BLOCK],
- uint8_t out[N_BLOCK],
- const uint8_t key[2 * N_BLOCK],
- uint8_t o_key[2 * N_BLOCK] );
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The redistribution and use of this software (with or without changes)
+ is allowed without the payment of fees or royalties provided that:
+
+ 1. source code distributions include the above copyright notice, this
+ list of conditions and the following disclaimer;
+
+ 2. binary distributions include the above copyright notice, this list
+ of conditions and the following disclaimer in their documentation;
+
+ 3. the name of the copyright holder is not used to endorse products
+ built using this software without specific written permission.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 09/09/2006
+
+ This is an AES implementation that uses only 8-bit byte operations on the
+ cipher state.
+ */
+
+#ifndef AES_H
+#define AES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+
+#if 1
+# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
+#endif
+#if 0
+# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
+#endif
+#if 0
+# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
+#endif
+#if 0
+# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
+#endif
+#if 0
+# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
+#endif
+#if 0
+# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
+#endif
+
+#define N_ROW 4
+#define N_COL 4
+#define N_BLOCK (N_ROW * N_COL)
+#define N_MAX_ROUNDS 14
+
+typedef uint8_t return_type;
+
+/* Warning: The key length for 256 bit keys overflows a byte
+ (see comment below)
+*/
+
+typedef uint8_t length_type;
+
+typedef struct
+{ uint8_t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
+ uint8_t rnd;
+} aes_context;
+
+/* The following calls are for a precomputed key schedule
+
+ NOTE: If the length_type used for the key length is an
+ unsigned 8-bit character, a key length of 256 bits must
+ be entered as a length in bytes (valid inputs are hence
+ 128, 192, 16, 24 and 32).
+*/
+
+#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
+
+return_type aes_set_key( const uint8_t key[],
+ length_type keylen,
+ aes_context ctx[1] );
+#endif
+
+#if defined( AES_ENC_PREKEYED )
+
+return_type aes_encrypt( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const aes_context ctx[1] );
+
+return_type aes_cbc_encrypt( const uint8_t *in,
+ uint8_t *out,
+ int32_t n_block,
+ uint8_t iv[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+#if defined( AES_DEC_PREKEYED )
+
+return_type aes_decrypt( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const aes_context ctx[1] );
+
+return_type aes_cbc_decrypt( const uint8_t *in,
+ uint8_t *out,
+ int32_t n_block,
+ uint8_t iv[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+/* The following calls are for 'on the fly' keying. In this case the
+ encryption and decryption keys are different.
+
+ The encryption subroutines take a key in an array of bytes in
+ key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
+ 192, and 256 bits respectively. They then encrypts the input
+ data, in[] with this key and put the reult in the output array
+ out[]. In addition, the second key array, o_key[L], is used
+ to output the key that is needed by the decryption subroutine
+ to reverse the encryption operation. The two key arrays can
+ be the same array but in this case the original key will be
+ overwritten.
+
+ In the same way, the decryption subroutines output keys that
+ can be used to reverse their effect when used for encryption.
+
+ Only 128 and 256 bit keys are supported in these 'on the fly'
+ modes.
+*/
+
+#if defined( AES_ENC_128_OTFK )
+void aes_encrypt_128( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK],
+ uint8_t o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_128_OTFK )
+void aes_decrypt_128( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK],
+ uint8_t o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_ENC_256_OTFK )
+void aes_encrypt_256( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK],
+ uint8_t o_key[2 * N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_256_OTFK )
+void aes_decrypt_256( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK],
+ uint8_t o_key[2 * N_BLOCK] );
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.c
index cce44d9..3bc327c 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.c
@@ -1,162 +1,162 @@
-/**************************************************************************
-Copyright (C) 2009 Lander Casado, Philippas Tsigas
-
-All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files
-(the "Software"), to deal with the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimers. Redistributions in
-binary form must reproduce the above copyright notice, this list of
-conditions and the following disclaimers in the documentation and/or
-other materials provided with the distribution.
-
-In no event shall the authors or copyright holders be liable for any special,
-incidental, indirect or consequential damages of any kind, or any damages
-whatsoever resulting from loss of use, data or profits, whether or not
-advised of the possibility of damage, and on any theory of liability,
-arising out of or in connection with the use or performance of this software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS WITH THE SOFTWARE
-
-*****************************************************************************/
-#include
-#include "aes.h"
-#include "cmac.h"
-#include //for memcpy and memset
-
-#ifndef MIN
-#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
-#endif
-
-#ifndef MAX
-#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
-#endif
-
-#define LSHIFT( v, r ) \
- do \
- { \
- int32_t i; \
- for( i = 0; i < 15; i++ ) \
- ( r )[i] = ( v )[i] << 1 | ( v )[i + 1] >> 7; \
- ( r )[15] = ( v )[15] << 1; \
- } while( 0 )
-
-#define XOR( v, r ) \
- do \
- { \
- int32_t i; \
- for( i = 0; i < 16; i++ ) \
- { \
- ( r )[i] = ( r )[i] ^ ( v )[i]; \
- } \
- } while( 0 )
-
-void AES_CMAC_Init( AES_CMAC_CTX* ctx )
-{
- memset( ctx->X, 0, sizeof ctx->X );
- ctx->M_n = 0;
- memset( ctx->rijndael.ksch, '\0', 240 );
-}
-
-void AES_CMAC_SetKey( AES_CMAC_CTX* ctx, const uint8_t key[AES_CMAC_KEY_LENGTH] )
-{
- aes_set_key( key, AES_CMAC_KEY_LENGTH, &ctx->rijndael );
-}
-
-void AES_CMAC_Update( AES_CMAC_CTX* ctx, const uint8_t* data, uint32_t len )
-{
- uint32_t mlen;
- uint8_t in[16];
-
- if( ctx->M_n > 0 )
- {
- mlen = MIN( 16 - ctx->M_n, len );
- memcpy( ctx->M_last + ctx->M_n, data, mlen );
- ctx->M_n += mlen;
- if( ctx->M_n < 16 || len == mlen )
- return;
- XOR( ctx->M_last, ctx->X );
-
- memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
- aes_encrypt( in, in, &ctx->rijndael );
- memcpy( &ctx->X[0], in, 16 );
-
- data += mlen;
- len -= mlen;
- }
- while( len > 16 )
- { /* not last block */
-
- XOR( data, ctx->X );
-
- memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
- aes_encrypt( in, in, &ctx->rijndael );
- memcpy( &ctx->X[0], in, 16 );
-
- data += 16;
- len -= 16;
- }
- /* potential last block, save it */
- memcpy( ctx->M_last, data, len );
- ctx->M_n = len;
-}
-
-void AES_CMAC_Final( uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX* ctx )
-{
- uint8_t K[16];
- uint8_t in[16];
- /* generate subkey K1 */
- memset( K, '\0', 16 );
-
- aes_encrypt( K, K, &ctx->rijndael );
-
- if( K[0] & 0x80 )
- {
- LSHIFT( K, K );
- K[15] ^= 0x87;
- }
- else
- LSHIFT( K, K );
-
- if( ctx->M_n == 16 )
- {
- /* last block was a complete block */
- XOR( K, ctx->M_last );
- }
- else
- {
- /* generate subkey K2 */
- if( K[0] & 0x80 )
- {
- LSHIFT( K, K );
- K[15] ^= 0x87;
- }
- else
- LSHIFT( K, K );
-
- /* padding(M_last) */
- ctx->M_last[ctx->M_n] = 0x80;
- while( ++ctx->M_n < 16 )
- ctx->M_last[ctx->M_n] = 0;
-
- XOR( K, ctx->M_last );
- }
- XOR( ctx->M_last, ctx->X );
-
- memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
- aes_encrypt( in, digest, &ctx->rijndael );
- memset( K, 0, sizeof K );
-}
+/**************************************************************************
+Copyright (C) 2009 Lander Casado, Philippas Tsigas
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal with the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimers. Redistributions in
+binary form must reproduce the above copyright notice, this list of
+conditions and the following disclaimers in the documentation and/or
+other materials provided with the distribution.
+
+In no event shall the authors or copyright holders be liable for any special,
+incidental, indirect or consequential damages of any kind, or any damages
+whatsoever resulting from loss of use, data or profits, whether or not
+advised of the possibility of damage, and on any theory of liability,
+arising out of or in connection with the use or performance of this software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS WITH THE SOFTWARE
+
+*****************************************************************************/
+#include
+#include "aes.h"
+#include "cmac.h"
+#include //for memcpy and memset
+
+#ifndef MIN
+#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
+#endif
+
+#ifndef MAX
+#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
+#endif
+
+#define LSHIFT( v, r ) \
+ do \
+ { \
+ int32_t i; \
+ for( i = 0; i < 15; i++ ) \
+ ( r )[i] = ( v )[i] << 1 | ( v )[i + 1] >> 7; \
+ ( r )[15] = ( v )[15] << 1; \
+ } while( 0 )
+
+#define XOR( v, r ) \
+ do \
+ { \
+ int32_t i; \
+ for( i = 0; i < 16; i++ ) \
+ { \
+ ( r )[i] = ( r )[i] ^ ( v )[i]; \
+ } \
+ } while( 0 )
+
+void AES_CMAC_Init( AES_CMAC_CTX* ctx )
+{
+ memset( ctx->X, 0, sizeof ctx->X );
+ ctx->M_n = 0;
+ memset( ctx->rijndael.ksch, '\0', 240 );
+}
+
+void AES_CMAC_SetKey( AES_CMAC_CTX* ctx, const uint8_t key[AES_CMAC_KEY_LENGTH] )
+{
+ aes_set_key( key, AES_CMAC_KEY_LENGTH, &ctx->rijndael );
+}
+
+void AES_CMAC_Update( AES_CMAC_CTX* ctx, const uint8_t* data, uint32_t len )
+{
+ uint32_t mlen;
+ uint8_t in[16];
+
+ if( ctx->M_n > 0 )
+ {
+ mlen = MIN( 16 - ctx->M_n, len );
+ memcpy( ctx->M_last + ctx->M_n, data, mlen );
+ ctx->M_n += mlen;
+ if( ctx->M_n < 16 || len == mlen )
+ return;
+ XOR( ctx->M_last, ctx->X );
+
+ memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
+ aes_encrypt( in, in, &ctx->rijndael );
+ memcpy( &ctx->X[0], in, 16 );
+
+ data += mlen;
+ len -= mlen;
+ }
+ while( len > 16 )
+ { /* not last block */
+
+ XOR( data, ctx->X );
+
+ memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
+ aes_encrypt( in, in, &ctx->rijndael );
+ memcpy( &ctx->X[0], in, 16 );
+
+ data += 16;
+ len -= 16;
+ }
+ /* potential last block, save it */
+ memcpy( ctx->M_last, data, len );
+ ctx->M_n = len;
+}
+
+void AES_CMAC_Final( uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX* ctx )
+{
+ uint8_t K[16];
+ uint8_t in[16];
+ /* generate subkey K1 */
+ memset( K, '\0', 16 );
+
+ aes_encrypt( K, K, &ctx->rijndael );
+
+ if( K[0] & 0x80 )
+ {
+ LSHIFT( K, K );
+ K[15] ^= 0x87;
+ }
+ else
+ LSHIFT( K, K );
+
+ if( ctx->M_n == 16 )
+ {
+ /* last block was a complete block */
+ XOR( K, ctx->M_last );
+ }
+ else
+ {
+ /* generate subkey K2 */
+ if( K[0] & 0x80 )
+ {
+ LSHIFT( K, K );
+ K[15] ^= 0x87;
+ }
+ else
+ LSHIFT( K, K );
+
+ /* padding(M_last) */
+ ctx->M_last[ctx->M_n] = 0x80;
+ while( ++ctx->M_n < 16 )
+ ctx->M_last[ctx->M_n] = 0;
+
+ XOR( K, ctx->M_last );
+ }
+ XOR( ctx->M_last, ctx->X );
+
+ memcpy( in, &ctx->X[0], 16 ); // Otherwise it does not look good
+ aes_encrypt( in, digest, &ctx->rijndael );
+ memset( K, 0, sizeof K );
+}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.h
index d56e4ac..7098cc4 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/cmac.h
@@ -1,71 +1,71 @@
-/**************************************************************************
-Copyright (C) 2009 Lander Casado, Philippas Tsigas
-
-All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files
-(the "Software"), to deal with the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimers. Redistributions in
-binary form must reproduce the above copyright notice, this list of
-conditions and the following disclaimers in the documentation and/or
-other materials provided with the distribution.
-
-In no event shall the authors or copyright holders be liable for any special,
-incidental, indirect or consequential damages of any kind, or any damages
-whatsoever resulting from loss of use, data or profits, whether or not
-advised of the possibility of damage, and on any theory of liability,
-arising out of or in connection with the use or performance of this software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS WITH THE SOFTWARE
-
-*****************************************************************************/
-
-#ifndef _CMAC_H_
-#define _CMAC_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "aes.h"
-
-#define AES_CMAC_KEY_LENGTH 16
-#define AES_CMAC_DIGEST_LENGTH 16
-
-typedef struct _AES_CMAC_CTX {
- aes_context rijndael;
- uint8_t X[16];
- uint8_t M_last[16];
- uint32_t M_n;
- } AES_CMAC_CTX;
-
-//#include
-
-//__BEGIN_DECLS
-void AES_CMAC_Init(AES_CMAC_CTX * ctx);
-void AES_CMAC_SetKey(AES_CMAC_CTX * ctx, const uint8_t key[AES_CMAC_KEY_LENGTH]);
-void AES_CMAC_Update(AES_CMAC_CTX * ctx, const uint8_t * data, uint32_t len);
- // __attribute__((__bounded__(__string__,2,3)));
-void AES_CMAC_Final(uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX * ctx);
- // __attribute__((__bounded__(__minbytes__,1,AES_CMAC_DIGEST_LENGTH)));
-//__END_DECLS
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CMAC_H_ */
-
+/**************************************************************************
+Copyright (C) 2009 Lander Casado, Philippas Tsigas
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal with the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimers. Redistributions in
+binary form must reproduce the above copyright notice, this list of
+conditions and the following disclaimers in the documentation and/or
+other materials provided with the distribution.
+
+In no event shall the authors or copyright holders be liable for any special,
+incidental, indirect or consequential damages of any kind, or any damages
+whatsoever resulting from loss of use, data or profits, whether or not
+advised of the possibility of damage, and on any theory of liability,
+arising out of or in connection with the use or performance of this software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS WITH THE SOFTWARE
+
+*****************************************************************************/
+
+#ifndef _CMAC_H_
+#define _CMAC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "aes.h"
+
+#define AES_CMAC_KEY_LENGTH 16
+#define AES_CMAC_DIGEST_LENGTH 16
+
+typedef struct _AES_CMAC_CTX {
+ aes_context rijndael;
+ uint8_t X[16];
+ uint8_t M_last[16];
+ uint32_t M_n;
+ } AES_CMAC_CTX;
+
+//#include
+
+//__BEGIN_DECLS
+void AES_CMAC_Init(AES_CMAC_CTX * ctx);
+void AES_CMAC_SetKey(AES_CMAC_CTX * ctx, const uint8_t key[AES_CMAC_KEY_LENGTH]);
+void AES_CMAC_Update(AES_CMAC_CTX * ctx, const uint8_t * data, uint32_t len);
+ // __attribute__((__bounded__(__string__,2,3)));
+void AES_CMAC_Final(uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX * ctx);
+ // __attribute__((__bounded__(__minbytes__,1,AES_CMAC_DIGEST_LENGTH)));
+//__END_DECLS
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _CMAC_H_ */
+
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/soft_se.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/soft_se.c
index 2c17ceb..4d26d50 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/soft_se.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_crypto/soft_secure_element/soft_se.c
@@ -652,7 +652,7 @@ smtc_se_return_code_t smtc_secure_element_get_pin( uint8_t pin[SMTC_SE_PIN_SIZE]
{
return SMTC_SE_RC_ERROR_NPE;
}
- memcpy( pin, soft_se_data.pin, SMTC_SE_EUI_SIZE );
+ memcpy( pin, soft_se_data.pin, SMTC_SE_PIN_SIZE );
return SMTC_SE_RC_SUCCESS;
}
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/headers/stream.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/headers/stream.h
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c
index fcc5a54..7801e15 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/alc_sync/alc_sync.c
@@ -542,7 +542,8 @@ void alc_sync_decode_device_app_time_periodicity_req( alc_sync_ctx_t* ctx, uint8
// The actual periodicity in seconds is 128*2^Period
ctx->periodicity_s = 128 << ( buffer[0] & 0x0F );
// To avoid a periodicity greater than the invalid delay previously set by the user
- alc_sync_set_valid_delay_second( ctx, MIN( ctx->periodicity_s * 3, ALC_SYNC_DEFAULT_S_SINCE_LAST_CORRECTION ) );
+ alc_sync_set_valid_delay_second( ctx, MIN( MAX( ctx->periodicity_s * 3, ctx->delay_before_time_no_more_valid_s ),
+ ALC_SYNC_DEFAULT_S_SINCE_LAST_CORRECTION ) );
}
void alc_sync_decode_force_device_resync_req( alc_sync_ctx_t* ctx, uint8_t* buffer )
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/rose.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/rose.c
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/rose.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/rose.h
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/stream.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_modem_services/src/stream/stream.c
old mode 100644
new mode 100755
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/README.md b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/README.md
new file mode 100644
index 0000000..3c2bc21
--- /dev/null
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/README.md
@@ -0,0 +1,22 @@
+# Semtech Radio Abstraction Layer
+
+This package proposes an implementation in C of the RAL (Radio Abstraction Layer).
+
+## Components
+
+The RAL is split in several components:
+
+- RAL interface
+- Implementation for SX1261/2/8 transceivers
+- Implementation for LR1110/20/21 transceivers
+- Implementation for SX1280/1 transceivers
+- Implementation for LLCC68 transceivers
+
+## Compatibility
+
+The current version of the RAL is compatible with the following version the drivers:
+
+- LR11xx driver unreleased (head of develop branch)
+- SX126x driver v2.0.1 and later
+- SX128x driver unreleased (head of develop branch)
+- LLCC68 driver v2.0.1 and later
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral.h
index c9b37f5..98ec3d1 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral.h
@@ -527,7 +527,7 @@ static inline ral_status_t ral_set_lora_cad_params( const ral_t* radio, const ra
*
* @returns Operation status
*/
-static inline ral_status_t ral_set_lora_symb_nb_timeout( const ral_t* radio, const uint8_t nb_of_symbs )
+static inline ral_status_t ral_set_lora_symb_nb_timeout( const ral_t* radio, const uint16_t nb_of_symbs )
{
return radio->driver.set_lora_symb_nb_timeout( radio->context, nb_of_symbs );
}
@@ -839,6 +839,21 @@ static inline unsigned int ral_lr_fhss_get_hop_sequence_count( const ral_t*
return radio->driver.lr_fhss_get_hop_sequence_count( radio->context, lr_fhss_params );
}
+/**
+ * @brief Return the delay in microsecond between the last bit sent and the Tx done interrupt using the given parameters
+ *
+ * @param [in] radio Pointer to radio data structure
+ * @param [in] lr_fhss_params Pointer to lr fhss parameters data structure
+ * @param [in] payload_length Payload length in byte
+ *
+ * @return Delay in microsecond
+ */
+static inline unsigned int ral_lr_fhss_get_bit_delay_in_us( const ral_t* radio, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length )
+{
+ return radio->driver.lr_fhss_get_bit_delay_in_us( radio->context, params, payload_length );
+}
+
/**
* @brief Get the coding rate and CRC configuration of the last received LoRa packet
*
@@ -931,6 +946,34 @@ static inline ral_status_t ral_get_random_numbers( const ral_t* radio, uint32_t*
return radio->driver.get_random_numbers( radio->context, numbers, n );
}
+/**
+ * @brief Generic finalizing function after reception
+ *
+ * @remark This function can be called when a @ref RAL_IRQ_RX_DONE occurs, not matter the reception mode
+ *
+ * @param [in] radio Pointer to radio data structure
+ *
+ * @returns Operation status
+ */
+static inline ral_status_t ral_handle_rx_done( const ral_t* radio )
+{
+ return radio->driver.handle_rx_done( radio->context );
+}
+
+/**
+ * @brief Generic finalizing function after transmission
+ *
+ * @remark This function can be called when a @ref RAL_IRQ_TX_DONE occurs
+ *
+ * @param [in] radio Pointer to radio data structure
+ *
+ * @returns Operation status
+ */
+static inline ral_status_t ral_handle_tx_done( const ral_t* radio )
+{
+ return radio->driver.handle_tx_done( radio->context );
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_defs.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_defs.h
index dbe70b7..b34f789 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_defs.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_defs.h
@@ -91,6 +91,13 @@ typedef enum ral_fallback_modes_e
RAL_FALLBACK_FS,
} ral_fallback_modes_t;
+typedef enum ral_xosc_cfg_e
+{
+ RAL_XOSC_CFG_XTAL,
+ RAL_XOSC_CFG_TCXO_RADIO_CTRL,
+ RAL_XOSC_CFG_TCXO_EXT_CTRL,
+} ral_xosc_cfg_t;
+
/**
* API return status
*/
@@ -323,7 +330,7 @@ typedef struct ral_gfsk_pkt_params_s
uint8_t sync_word_len_in_bits; //!< GFSK Sync word length in bits
ral_gfsk_address_filtering_t address_filtering; //!< GFSK Address filtering configuration
ral_gfsk_pkt_len_modes_t header_type; //!< GFSK Header type
- uint8_t pld_len_in_bytes; //!< GFSK Payload length in bytes
+ uint16_t pld_len_in_bytes; //!< GFSK Payload length in bytes
ral_gfsk_crc_type_t crc_type; //!< GFSK CRC type configuration
ral_gfsk_dc_free_t dc_free; //!< GFSK Whitening configuration
} ral_gfsk_pkt_params_t;
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_drv.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_drv.h
index b6fa6ae..bdec0d8 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_drv.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_drv.h
@@ -98,7 +98,7 @@ typedef ral_status_t ( *ral_set_gfsk_pkt_params_f )( const void* context, const
typedef ral_status_t ( *ral_set_lora_mod_params_f )( const void* context, const ral_lora_mod_params_t* params );
typedef ral_status_t ( *ral_set_lora_pkt_params_f )( const void* context, const ral_lora_pkt_params_t* params );
typedef ral_status_t ( *ral_set_lora_cad_params_f )( const void* context, const ral_lora_cad_params_t* params );
-typedef ral_status_t ( *ral_set_lora_symb_nb_timeout_f )( const void* context, const uint8_t nb_of_symbs );
+typedef ral_status_t ( *ral_set_lora_symb_nb_timeout_f )( const void* context, const uint16_t nb_of_symbs );
typedef ral_status_t ( *ral_set_flrc_mod_params_f )( const void* context, const ral_flrc_mod_params_t* params );
typedef ral_status_t ( *ral_set_flrc_pkt_params_f )( const void* context, const ral_flrc_pkt_params_t* params );
typedef ral_status_t ( *ral_get_gfsk_rx_pkt_status_f )( const void* context, ral_gfsk_rx_pkt_status_t* rx_pkt_status );
@@ -134,6 +134,8 @@ typedef ral_status_t ( *ral_lr_fhss_get_time_on_air_in_ms_f )( const void*
uint16_t payload_length, uint32_t* time_on_air );
typedef ral_status_t ( *ral_lr_fhss_get_hop_sequence_count_f )( const void* context,
const ral_lr_fhss_params_t* lr_fhss_params );
+typedef uint16_t ( *ral_lr_fhss_get_bit_delay_in_us_f )( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length );
typedef ral_status_t ( *ral_get_lora_rx_pkt_cr_crc_f )( const void* context, ral_lora_cr_t* cr, bool* is_crc_present );
typedef ral_status_t ( *ral_get_tx_consumption_in_ua_f )( const void* context, const int8_t output_pwr_in_dbm,
const uint32_t rf_freq_in_hz,
@@ -144,6 +146,8 @@ typedef ral_status_t ( *ral_get_gfsk_rx_consumption_in_ua_f )( const void* conte
typedef ral_status_t ( *ral_get_lora_rx_consumption_in_ua_f )( const void* context, const ral_lora_bw_t bw,
const bool rx_boosted, uint32_t* pwr_consumption_in_ua );
typedef ral_status_t ( *ral_get_random_numbers_f )( const void* radio, uint32_t* numbers, unsigned int n );
+typedef ral_status_t ( *ral_handle_rx_done_f )( const void* radio );
+typedef ral_status_t ( *ral_handle_tx_done_f )( const void* radio );
typedef struct ral_drv_s
{
@@ -201,11 +205,14 @@ typedef struct ral_drv_s
ral_lr_fhss_handle_tx_done_f lr_fhss_handle_tx_done;
ral_lr_fhss_get_time_on_air_in_ms_f lr_fhss_get_time_on_air_in_ms;
ral_lr_fhss_get_hop_sequence_count_f lr_fhss_get_hop_sequence_count;
+ ral_lr_fhss_get_bit_delay_in_us_f lr_fhss_get_bit_delay_in_us;
ral_get_lora_rx_pkt_cr_crc_f get_lora_rx_pkt_cr_crc;
ral_get_tx_consumption_in_ua_f get_tx_consumption_in_ua;
ral_get_gfsk_rx_consumption_in_ua_f get_gfsk_rx_consumption_in_ua;
ral_get_lora_rx_consumption_in_ua_f get_lora_rx_consumption_in_ua;
ral_get_random_numbers_f get_random_numbers;
+ ral_handle_rx_done_f handle_rx_done;
+ ral_handle_tx_done_f handle_tx_done;
} ral_drv_t;
/*
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.c
index d229415..a197e3e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.c
@@ -573,9 +573,16 @@ ral_status_t ral_llcc68_set_lora_cad_params( const void* context, const ral_lora
return ( ral_status_t ) llcc68_set_cad_params( context, &radio_lora_cad_params );
}
-ral_status_t ral_llcc68_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs )
+ral_status_t ral_llcc68_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs )
{
- return ( ral_status_t ) llcc68_set_lora_symb_nb_timeout( context, nb_of_symbs );
+ if( nb_of_symbs <= LLCC68_MAX_LORA_SYMB_NUM_TIMEOUT )
+ {
+ return ( ral_status_t ) llcc68_set_lora_symb_nb_timeout( context, nb_of_symbs );
+ }
+ else
+ {
+ return RAL_STATUS_UNKNOWN_VALUE;
+ }
}
ral_status_t ral_llcc68_set_flrc_mod_params( const void* context, const ral_flrc_mod_params_t* params )
@@ -770,6 +777,15 @@ ral_status_t ral_llcc68_lr_fhss_get_hop_sequence_count( const void*
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
+uint16_t ral_llcc68_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length )
+{
+ ( void ) context; // Unused parameter
+ ( void ) params; // Unused parameter
+ ( void ) payload_length; // Unused parameter
+ return 0;
+}
+
ral_status_t ral_llcc68_get_lora_rx_pkt_cr_crc( const void* context, ral_lora_cr_t* cr, bool* is_crc_present )
{
return RAL_STATUS_UNSUPPORTED_FEATURE;
@@ -799,6 +815,16 @@ ral_status_t ral_llcc68_get_random_numbers( const void* context, uint32_t* numbe
return ( ral_status_t ) llcc68_get_random_numbers( context, numbers, n );
}
+ral_status_t ral_llcc68_handle_rx_done( const void* context )
+{
+ return ( ral_status_t ) llcc68_handle_rx_done( context );
+}
+
+ral_status_t ral_llcc68_handle_tx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.h
index 1d578fa..2cd21ec 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_llcc68.h
@@ -86,11 +86,13 @@ extern "C" {
.lr_fhss_handle_tx_done = ral_llcc68_lr_fhss_handle_tx_done, \
.lr_fhss_get_time_on_air_in_ms = ral_llcc68_lr_fhss_get_time_on_air_in_ms, \
.lr_fhss_get_hop_sequence_count = ral_llcc68_lr_fhss_get_hop_sequence_count, \
+ .lr_fhss_get_bit_delay_in_us = ral_llcc68_lr_fhss_get_bit_delay_in_us, \
.get_lora_rx_pkt_cr_crc = ral_llcc68_get_lora_rx_pkt_cr_crc, \
.get_tx_consumption_in_ua = ral_llcc68_get_tx_consumption_in_ua, \
.get_gfsk_rx_consumption_in_ua = ral_llcc68_get_gfsk_rx_consumption_in_ua, \
.get_lora_rx_consumption_in_ua = ral_llcc68_get_lora_rx_consumption_in_ua, \
- .get_random_numbers = ral_llcc68_get_random_numbers, \
+ .get_random_numbers = ral_llcc68_get_random_numbers, .handle_rx_done = ral_llcc68_handle_rx_done, \
+ .handle_tx_done = ral_llcc68_handle_tx_done, \
}
#define RAL_LLCC68_INSTANTIATE( ctx ) \
@@ -273,7 +275,7 @@ ral_status_t ral_llcc68_set_lora_cad_params( const void* context, const ral_lora
/**
* @see ral_set_lora_symb_nb_timeout
*/
-ral_status_t ral_llcc68_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs );
+ral_status_t ral_llcc68_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs );
/**
* @see ral_set_flrc_mod_params
@@ -389,6 +391,12 @@ ral_status_t ral_llcc68_lr_fhss_get_time_on_air_in_ms( const void* context, cons
ral_status_t ral_llcc68_lr_fhss_get_hop_sequence_count( const void* context,
const ral_lr_fhss_params_t* lr_fhss_params );
+/**
+ * @see ral_lr_fhss_get_bit_delay_in_us
+ */
+uint16_t ral_llcc68_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length );
+
/**
* @see ral_get_lora_rx_pkt_cr_crc
*/
@@ -418,6 +426,16 @@ ral_status_t ral_llcc68_get_lora_rx_consumption_in_ua( const void* context, cons
*/
ral_status_t ral_llcc68_get_random_numbers( const void* context, uint32_t* numbers, unsigned int n );
+/**
+ * @see ral_handle_rx_done
+ */
+ral_status_t ral_llcc68_handle_rx_done( const void* context );
+
+/**
+ * @see ral_handle_tx_done
+ */
+ral_status_t ral_llcc68_handle_tx_done( const void* context );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.c
index c9dce8c..473e40e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.c
@@ -375,10 +375,10 @@ ral_status_t ral_lr11xx_init( const void* context )
ral_status_t status = RAL_STATUS_ERROR;
lr11xx_system_tcxo_supply_voltage_t tcxo_supply_voltage;
lr11xx_system_reg_mode_t reg_mode;
- lr11xx_system_rfswitch_cfg_t system_rf_switch_cfg = { 0 };
- bool tcxo_is_radio_controlled = false;
- bool crc_is_activated = false;
- uint32_t startup_time_in_tick = 0;
+ lr11xx_system_rfswitch_cfg_t system_rf_switch_cfg = { 0 };
+ ral_xosc_cfg_t xosc_cfg;
+ bool crc_is_activated = false;
+ uint32_t startup_time_in_tick = 0;
ral_lr11xx_bsp_get_crc_state( context, &crc_is_activated );
if( crc_is_activated == true )
@@ -404,8 +404,8 @@ ral_status_t ral_lr11xx_init( const void* context )
return status;
}
- ral_lr11xx_bsp_get_xosc_cfg( context, &tcxo_is_radio_controlled, &tcxo_supply_voltage, &startup_time_in_tick );
- if( tcxo_is_radio_controlled == true )
+ ral_lr11xx_bsp_get_xosc_cfg( context, &xosc_cfg, &tcxo_supply_voltage, &startup_time_in_tick );
+ if( xosc_cfg == RAL_XOSC_CFG_TCXO_RADIO_CTRL )
{
status = ( ral_status_t ) lr11xx_system_set_tcxo_mode( context, tcxo_supply_voltage, startup_time_in_tick );
if( status != RAL_STATUS_OK )
@@ -828,7 +828,7 @@ ral_status_t ral_lr11xx_set_lora_cad_params( const void* context, const ral_lora
return ( ral_status_t ) lr11xx_radio_set_cad_params( context, &radio_lora_cad_params );
}
-ral_status_t ral_lr11xx_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs )
+ral_status_t ral_lr11xx_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs )
{
return ( ral_status_t ) lr11xx_radio_set_lora_sync_timeout( context, nb_of_symbs );
}
@@ -1046,6 +1046,16 @@ ral_status_t ral_lr11xx_lr_fhss_get_hop_sequence_count( const void*
return ( ral_status_t ) lr11xx_lr_fhss_get_hop_sequence_count( &lr11xx_params );
}
+uint16_t ral_lr11xx_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length )
+{
+ lr11xx_lr_fhss_params_t lr11xx_params;
+
+ ral_lr11xx_convert_lr_fhss_params_from_ral( params, &lr11xx_params );
+
+ return lr11xx_lr_fhss_get_bit_delay_in_us( &lr11xx_params, payload_length );
+}
+
ral_status_t ral_lr11xx_get_lora_rx_pkt_cr_crc( const void* context, ral_lora_cr_t* cr, bool* is_crc_present )
{
return RAL_STATUS_UNSUPPORTED_FEATURE;
@@ -1234,6 +1244,16 @@ ral_status_t ral_lr11xx_get_random_numbers( const void* context, uint32_t* numbe
return status;
}
+ral_status_t ral_lr11xx_handle_rx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
+ral_status_t ral_lr11xx_handle_tx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.h
index 82444a7..4effb59 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx.h
@@ -87,11 +87,13 @@ extern "C" {
.lr_fhss_handle_tx_done = ral_lr11xx_lr_fhss_handle_tx_done, \
.lr_fhss_get_time_on_air_in_ms = ral_lr11xx_lr_fhss_get_time_on_air_in_ms, \
.lr_fhss_get_hop_sequence_count = ral_lr11xx_lr_fhss_get_hop_sequence_count, \
+ .lr_fhss_get_bit_delay_in_us = ral_lr11xx_lr_fhss_get_bit_delay_in_us, \
.get_lora_rx_pkt_cr_crc = ral_lr11xx_get_lora_rx_pkt_cr_crc, \
.get_tx_consumption_in_ua = ral_lr11xx_get_tx_consumption_in_ua, \
.get_gfsk_rx_consumption_in_ua = ral_lr11xx_get_gfsk_rx_consumption_in_ua, \
.get_lora_rx_consumption_in_ua = ral_lr11xx_get_lora_rx_consumption_in_ua, \
- .get_random_numbers = ral_lr11xx_get_random_numbers, \
+ .get_random_numbers = ral_lr11xx_get_random_numbers, .handle_rx_done = ral_lr11xx_handle_rx_done, \
+ .handle_tx_done = ral_lr11xx_handle_tx_done, \
}
#define RAL_LR11XX_INSTANTIATE( ctx ) \
@@ -279,7 +281,7 @@ ral_status_t ral_lr11xx_set_lora_cad_params( const void* context, const ral_lora
/**
* @see ral_set_lora_symb_nb_timeout
*/
-ral_status_t ral_lr11xx_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs );
+ral_status_t ral_lr11xx_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs );
/**
* @see ral_set_flrc_mod_params
@@ -390,6 +392,12 @@ ral_status_t ral_lr11xx_lr_fhss_handle_tx_done( const void* context, const ral_l
ral_status_t ral_lr11xx_lr_fhss_get_time_on_air_in_ms( const void* context, const ral_lr_fhss_params_t* lr_fhss_params,
uint16_t payload_length, uint32_t* time_on_air );
+/**
+ * @see ral_lr_fhss_get_bit_delay_in_us
+ */
+uint16_t ral_lr11xx_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length );
+
/**
* @see ral_lr_fhss_get_hop_sequence_count
*/
@@ -424,6 +432,16 @@ ral_status_t ral_lr11xx_get_lora_rx_consumption_in_ua( const void* context, cons
*/
ral_status_t ral_lr11xx_get_random_numbers( const void* context, uint32_t* numbers, unsigned int n );
+/**
+ * @see ral_handle_rx_done
+ */
+ral_status_t ral_lr11xx_handle_rx_done( const void* context );
+
+/**
+ * @see ral_handle_tx_done
+ */
+ral_status_t ral_lr11xx_handle_tx_done( const void* context );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx_bsp.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx_bsp.h
index b6eb2f8..b549c88 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx_bsp.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_lr11xx_bsp.h
@@ -116,11 +116,11 @@ void ral_lr11xx_bsp_get_reg_mode( const void* context, lr11xx_system_reg_mode_t*
* @remark If no TCXO is present, this function should set tcxo_is_radio_controlled to false, and return.
*
* @param [in] context Chip implementation context
- * @param [out] tcxo_is_radio_controlled Let the caller know if there is a radio-controlled TCXO
+ * @param [out] xosc_cfg Let the caller know what kind of XOSC is used
* @param [out] supply_voltage TCXO supply voltage parameter
* @param [out] startup_time_in_tick TCXO setup time in clock tick
*/
-void ral_lr11xx_bsp_get_xosc_cfg( const void* context, bool* tcxo_is_radio_controlled,
+void ral_lr11xx_bsp_get_xosc_cfg( const void* context, ral_xosc_cfg_t* xosc_cfg,
lr11xx_system_tcxo_supply_voltage_t* supply_voltage, uint32_t* startup_time_in_tick );
/**
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.c
index db101ef..2bd436e 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.c
@@ -329,6 +329,15 @@ static ral_status_t ral_sx126x_convert_lora_cad_params_from_ral( const ral_lora_
static void ral_sx126x_convert_lr_fhss_params_from_ral( const ral_lr_fhss_params_t* ral_lr_fhss_params,
sx126x_lr_fhss_params_t* radio_lr_fhss_params );
+/**
+ * @brief Configure the crystal trimming capacitor
+ *
+ * @param [in] context Radio context
+ *
+ * @returns Operation status
+ */
+static ral_status_t ral_sx126x_cfg_trim_cap( const void* context );
+
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
@@ -350,8 +359,8 @@ ral_status_t ral_sx126x_init( const void* context )
sx126x_tcxo_ctrl_voltages_t tcxo_supply_voltage;
sx126x_reg_mod_t reg_mode;
bool dio2_is_set_as_rf_switch = false;
- bool tcxo_is_radio_controlled = false;
- uint32_t startup_time_in_tick = 0;
+ ral_xosc_cfg_t xosc_cfg;
+ uint32_t startup_time_in_tick = 0;
status = ( ral_status_t ) sx126x_init_retention_list( context );
if( status != RAL_STATUS_OK )
@@ -373,8 +382,8 @@ ral_status_t ral_sx126x_init( const void* context )
return status;
}
- ral_sx126x_bsp_get_xosc_cfg( context, &tcxo_is_radio_controlled, &tcxo_supply_voltage, &startup_time_in_tick );
- if( tcxo_is_radio_controlled == true )
+ ral_sx126x_bsp_get_xosc_cfg( context, &xosc_cfg, &tcxo_supply_voltage, &startup_time_in_tick );
+ if( xosc_cfg == RAL_XOSC_CFG_TCXO_RADIO_CTRL )
{
status = ( ral_status_t ) sx126x_set_dio3_as_tcxo_ctrl( context, tcxo_supply_voltage, startup_time_in_tick );
if( status != RAL_STATUS_OK )
@@ -435,24 +444,37 @@ ral_status_t ral_sx126x_set_fs( const void* context )
ral_status_t ral_sx126x_set_tx( const void* context )
{
- return ( ral_status_t ) sx126x_set_tx( context, 0 );
+ ral_status_t status = ral_sx126x_cfg_trim_cap( context );
+
+ if( status == RAL_STATUS_OK )
+ {
+ status = ( ral_status_t ) sx126x_set_tx( context, 0 );
+ }
+
+ return status;
}
ral_status_t ral_sx126x_set_rx( const void* context, const uint32_t timeout_in_ms )
{
- if( timeout_in_ms == RAL_RX_TIMEOUT_CONTINUOUS_MODE )
+ ral_status_t status = ral_sx126x_cfg_trim_cap( context );
+
+ if( status == RAL_STATUS_OK )
{
- return ( ral_status_t ) sx126x_set_rx_with_timeout_in_rtc_step( context, 0x00FFFFFF );
- }
- else
- { // max timeout is 0xFFFFFE -> 262143 ms (0xFFFFFE / 64000 * 1000) - Single reception mode set if timeout_ms is 0
- if( timeout_in_ms < 262144 )
+ if( timeout_in_ms == RAL_RX_TIMEOUT_CONTINUOUS_MODE )
{
- return ( ral_status_t ) sx126x_set_rx( context, timeout_in_ms );
+ return ( ral_status_t ) sx126x_set_rx_with_timeout_in_rtc_step( context, 0x00FFFFFF );
}
else
- {
- return RAL_STATUS_ERROR;
+ { // max timeout is 0xFFFFFE -> 262143 ms (0xFFFFFE / 64000 * 1000) - Single reception mode set if timeout_ms
+ // is 0
+ if( timeout_in_ms < 262144 )
+ {
+ return ( ral_status_t ) sx126x_set_rx( context, timeout_in_ms );
+ }
+ else
+ {
+ return RAL_STATUS_ERROR;
+ }
}
}
@@ -507,17 +529,38 @@ ral_status_t ral_sx126x_set_rx_duty_cycle( const void* context, const uint32_t r
ral_status_t ral_sx126x_set_lora_cad( const void* context )
{
- return ( ral_status_t ) sx126x_set_cad( context );
+ ral_status_t status = ral_sx126x_cfg_trim_cap( context );
+
+ if( status == RAL_STATUS_OK )
+ {
+ status = ( ral_status_t ) sx126x_set_cad( context );
+ }
+
+ return status;
}
ral_status_t ral_sx126x_set_tx_cw( const void* context )
{
- return ( ral_status_t ) sx126x_set_tx_cw( context );
+ ral_status_t status = ral_sx126x_cfg_trim_cap( context );
+
+ if( status == RAL_STATUS_OK )
+ {
+ status = ( ral_status_t ) sx126x_set_tx_cw( context );
+ }
+
+ return status;
}
ral_status_t ral_sx126x_set_tx_infinite_preamble( const void* context )
{
- return ( ral_status_t ) sx126x_set_tx_infinite_preamble( context );
+ ral_status_t status = ral_sx126x_cfg_trim_cap( context );
+
+ if( status == RAL_STATUS_OK )
+ {
+ status = ( ral_status_t ) sx126x_set_tx_infinite_preamble( context );
+ }
+
+ return status;
}
ral_status_t ral_sx126x_cal_img( const void* context, const uint16_t freq1_in_mhz, const uint16_t freq2_in_mhz )
@@ -796,9 +839,16 @@ ral_status_t ral_sx126x_set_lora_cad_params( const void* context, const ral_lora
return ( ral_status_t ) sx126x_set_cad_params( context, &radio_lora_cad_params );
}
-ral_status_t ral_sx126x_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs )
+ral_status_t ral_sx126x_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs )
{
- return ( ral_status_t ) sx126x_set_lora_symb_nb_timeout( context, nb_of_symbs );
+ if( nb_of_symbs <= SX126X_MAX_LORA_SYMB_NUM_TIMEOUT )
+ {
+ return ( ral_status_t ) sx126x_set_lora_symb_nb_timeout( context, nb_of_symbs );
+ }
+ else
+ {
+ return RAL_STATUS_UNKNOWN_VALUE;
+ }
}
ral_status_t ral_sx126x_set_flrc_mod_params( const void* context, const ral_flrc_mod_params_t* params )
@@ -993,6 +1043,16 @@ ral_status_t ral_sx126x_lr_fhss_get_hop_sequence_count( const void*
return ( ral_status_t ) sx126x_lr_fhss_get_hop_sequence_count( &sx126x_params );
}
+uint16_t ral_sx126x_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length )
+{
+ sx126x_lr_fhss_params_t sx126x_params;
+
+ ral_sx126x_convert_lr_fhss_params_from_ral( params, &sx126x_params );
+
+ return sx126x_lr_fhss_get_bit_delay_in_us( &sx126x_params, payload_length );
+}
+
ral_status_t ral_sx126x_get_lora_rx_pkt_cr_crc( const void* context, ral_lora_cr_t* cr, bool* is_crc_present )
{
ral_status_t status = RAL_STATUS_ERROR;
@@ -1141,6 +1201,16 @@ ral_status_t ral_sx126x_get_random_numbers( const void* context, uint32_t* numbe
return ( ral_status_t ) sx126x_get_random_numbers( context, numbers, n );
}
+ral_status_t ral_sx126x_handle_rx_done( const void* context )
+{
+ return ( ral_status_t ) sx126x_handle_rx_done( context );
+}
+
+ral_status_t ral_sx126x_handle_tx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
@@ -1632,4 +1702,51 @@ static void ral_sx126x_convert_lr_fhss_params_from_ral( const ral_lr_fhss_params
};
}
+static ral_status_t ral_sx126x_cfg_trim_cap( const void* context )
+{
+ sx126x_tcxo_ctrl_voltages_t tcxo_supply_voltage;
+ ral_xosc_cfg_t xosc_cfg;
+ uint32_t startup_time_in_tick = 0;
+
+ ral_sx126x_bsp_get_xosc_cfg( context, &xosc_cfg, &tcxo_supply_voltage, &startup_time_in_tick );
+
+ if( xosc_cfg == RAL_XOSC_CFG_XTAL )
+ {
+ uint8_t trimming_cap_xta = SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC;
+ uint8_t trimming_cap_xtb = SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC;
+
+ ral_sx126x_bsp_get_trim_cap( context, &trimming_cap_xta, &trimming_cap_xtb );
+
+ if( ( trimming_cap_xta != SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC ) ||
+ ( trimming_cap_xtb != SX126X_XTAL_TRIMMING_CAPACITOR_DEFAULT_VALUE_STDBY_XOSC ) )
+ {
+ sx126x_status_t status;
+ sx126x_chip_status_t chip_status;
+
+ status = sx126x_get_status( context, &chip_status );
+ if( status != SX126X_STATUS_OK )
+ {
+ return ( ral_status_t ) status;
+ }
+
+ if( chip_status.chip_mode == SX126X_CHIP_MODE_STBY_RC )
+ {
+ status = sx126x_set_standby( context, SX126X_STANDBY_CFG_XOSC );
+ if( status != SX126X_STATUS_OK )
+ {
+ return ( ral_status_t ) status;
+ }
+ }
+
+ status = sx126x_set_trimming_capacitor_values( context, trimming_cap_xta, trimming_cap_xtb );
+ if( status != SX126X_STATUS_OK )
+ {
+ return ( ral_status_t ) status;
+ }
+ }
+ }
+
+ return RAL_STATUS_OK;
+}
+
/* --- EOF ------------------------------------------------------------------ */
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.h
index dd62576..38ce002 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x.h
@@ -87,11 +87,13 @@ extern "C" {
.lr_fhss_handle_tx_done = ral_sx126x_lr_fhss_handle_tx_done, \
.lr_fhss_get_time_on_air_in_ms = ral_sx126x_lr_fhss_get_time_on_air_in_ms, \
.lr_fhss_get_hop_sequence_count = ral_sx126x_lr_fhss_get_hop_sequence_count, \
+ .lr_fhss_get_bit_delay_in_us = ral_sx126x_lr_fhss_get_bit_delay_in_us, \
.get_lora_rx_pkt_cr_crc = ral_sx126x_get_lora_rx_pkt_cr_crc, \
.get_tx_consumption_in_ua = ral_sx126x_get_tx_consumption_in_ua, \
.get_gfsk_rx_consumption_in_ua = ral_sx126x_get_gfsk_rx_consumption_in_ua, \
.get_lora_rx_consumption_in_ua = ral_sx126x_get_lora_rx_consumption_in_ua, \
- .get_random_numbers = ral_sx126x_get_random_numbers, \
+ .get_random_numbers = ral_sx126x_get_random_numbers, .handle_rx_done = ral_sx126x_handle_rx_done, \
+ .handle_tx_done = ral_sx126x_handle_tx_done, \
}
#define RAL_SX126X_INSTANTIATE( ctx ) \
@@ -151,11 +153,19 @@ ral_status_t ral_sx126x_set_fs( const void* context );
/**
* @see ral_set_tx
+ *
+ * @remark In case the external oscillator is a crystal and at least one trimming capacitor is set to value different
+ * from the default one in @ref ral_sx126x_bsp_get_trim_cap, the implementation will perform a configuration of the
+ * trimming capacitors before configuring the transceiver into the desired mode.
*/
ral_status_t ral_sx126x_set_tx( const void* context );
/**
* @see ral_set_rx
+ *
+ * @remark In case the external oscillator is a crystal and at least one trimming capacitor is set to value different
+ * from the default one in @ref ral_sx126x_bsp_get_trim_cap, the implementation will perform a configuration of the
+ * trimming capacitors before configuring the transceiver into the desired mode.
*/
ral_status_t ral_sx126x_set_rx( const void* context, const uint32_t timeout_in_ms );
@@ -182,16 +192,28 @@ ral_status_t ral_sx126x_set_rx_duty_cycle( const void* context, const uint32_t r
/**
* @see ral_set_lora_cad
+ *
+ * @remark In case the external oscillator is a crystal and at least one trimming capacitor is set to value different
+ * from the default one in @ref ral_sx126x_bsp_get_trim_cap, the implementation will perform a configuration of the
+ * trimming capacitors before configuring the transceiver into the desired mode.
*/
ral_status_t ral_sx126x_set_lora_cad( const void* context );
/**
* @see ral_set_tx_cw
+ *
+ * @remark In case the external oscillator is a crystal and at least one trimming capacitor is set to value different
+ * from the default one in @ref ral_sx126x_bsp_get_trim_cap, the implementation will perform a configuration of the
+ * trimming capacitors before configuring the transceiver into the desired mode.
*/
ral_status_t ral_sx126x_set_tx_cw( const void* context );
/**
* @see ral_set_tx_infinite_preamble
+ *
+ * @remark In case the external oscillator is a crystal and at least one trimming capacitor is set to value different
+ * from the default one in @ref ral_sx126x_bsp_get_trim_cap, the implementation will perform a configuration of the
+ * trimming capacitors before configuring the transceiver into the desired mode.
*/
ral_status_t ral_sx126x_set_tx_infinite_preamble( const void* context );
@@ -279,7 +301,7 @@ ral_status_t ral_sx126x_set_lora_cad_params( const void* context, const ral_lora
/**
* @see ral_set_lora_symb_nb_timeout
*/
-ral_status_t ral_sx126x_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs );
+ral_status_t ral_sx126x_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs );
/**
* @see ral_set_flrc_mod_params
@@ -396,6 +418,12 @@ ral_status_t ral_sx126x_lr_fhss_get_time_on_air_in_ms( const void* context, cons
ral_status_t ral_sx126x_lr_fhss_get_hop_sequence_count( const void* context,
const ral_lr_fhss_params_t* lr_fhss_params );
+/**
+ * @see ral_lr_fhss_get_bit_delay_in_us
+ */
+uint16_t ral_sx126x_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length );
+
/**
* @see ral_get_lora_rx_pkt_cr_crc
*/
@@ -425,6 +453,16 @@ ral_status_t ral_sx126x_get_lora_rx_consumption_in_ua( const void* context, cons
*/
ral_status_t ral_sx126x_get_random_numbers( const void* context, uint32_t* numbers, unsigned int n );
+/**
+ * @see ral_handle_rx_done
+ */
+ral_status_t ral_sx126x_handle_rx_done( const void* context );
+
+/**
+ * @see ral_handle_tx_done
+ */
+ral_status_t ral_sx126x_handle_tx_done( const void* context );
+
#ifdef __cplusplus
}
#endif
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x_bsp.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x_bsp.h
index bf8cc76..3ab12a3 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x_bsp.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx126x_bsp.h
@@ -115,11 +115,11 @@ void ral_sx126x_bsp_get_tx_cfg( const void* context, const ral_sx126x_bsp_tx_cfg
* @remark If no TCXO is present, this function should set tcxo_is_radio_controlled to false, and return.
*
* @param [in] context Chip implementation context
- * @param [out] tcxo_is_radio_controlled Let the caller know if there is a radio-controlled TCXO
+ * @param [out] xosc_cfg Let the caller know what kind of XOSC is used
* @param [out] supply_voltage TCXO supply voltage parameter
* @param [out] startup_time_in_tick TCXO setup time in clock tick
*/
-void ral_sx126x_bsp_get_xosc_cfg( const void* context, bool* tcxo_is_radio_controlled,
+void ral_sx126x_bsp_get_xosc_cfg( const void* context, ral_xosc_cfg_t* xosc_cfg,
sx126x_tcxo_ctrl_voltages_t* supply_voltage, uint32_t* startup_time_in_tick );
/**
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.c b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.c
index 1e0e9b1..f5bcf67 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.c
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.c
@@ -718,7 +718,7 @@ ral_status_t ral_sx128x_set_lora_cad_params( const void* context, const ral_lora
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
-ral_status_t ral_sx128x_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs )
+ral_status_t ral_sx128x_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs )
{
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
@@ -963,6 +963,15 @@ ral_status_t ral_sx128x_lr_fhss_get_hop_sequence_count( const void*
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
+uint16_t ral_sx128x_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length )
+{
+ ( void ) context; // Unused parameter
+ ( void ) params; // Unused parameter
+ ( void ) payload_length; // Unused parameter
+ return 0;
+}
+
ral_status_t ral_sx128x_get_lora_rx_pkt_cr_crc( const void* context, ral_lora_cr_t* cr, bool* is_crc_present )
{
ral_status_t status = RAL_STATUS_ERROR;
@@ -1128,6 +1137,16 @@ ral_status_t ral_sx128x_get_random_numbers( const void* context, uint32_t* numbe
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
+ral_status_t ral_sx128x_handle_rx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
+ral_status_t ral_sx128x_handle_tx_done( const void* context )
+{
+ return RAL_STATUS_OK;
+}
+
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DEFINITION --------------------------------------------
diff --git a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.h b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.h
index b8a822c..976ca22 100644
--- a/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.h
+++ b/lora_basics_modem/lora_basics_modem/smtc_modem_core/smtc_ral/src/ral_sx128x.h
@@ -87,11 +87,13 @@ extern "C" {
.lr_fhss_handle_tx_done = ral_sx128x_lr_fhss_handle_tx_done, \
.lr_fhss_get_time_on_air_in_ms = ral_sx128x_lr_fhss_get_time_on_air_in_ms, \
.lr_fhss_get_hop_sequence_count = ral_sx128x_lr_fhss_get_hop_sequence_count, \
+ .lr_fhss_get_bit_delay_in_us = ral_sx128x_lr_fhss_get_bit_delay_in_us, \
.get_lora_rx_pkt_cr_crc = ral_sx128x_get_lora_rx_pkt_cr_crc, \
.get_tx_consumption_in_ua = ral_sx128x_get_tx_consumption_in_ua, \
.get_gfsk_rx_consumption_in_ua = ral_sx128x_get_gfsk_rx_consumption_in_ua, \
.get_lora_rx_consumption_in_ua = ral_sx128x_get_lora_rx_consumption_in_ua, \
- .get_random_numbers = ral_sx128x_get_random_numbers, \
+ .get_random_numbers = ral_sx128x_get_random_numbers, .handle_rx_done = ral_sx128x_handle_rx_done, \
+ .handle_tx_done = ral_sx128x_handle_tx_done, \
}
#define RAL_SX128X_INSTANTIATE( ctx ) \
@@ -279,7 +281,7 @@ ral_status_t ral_sx128x_set_lora_cad_params( const void* context, const ral_lora
/**
* @see ral_set_lora_symb_nb_timeout
*/
-ral_status_t ral_sx128x_set_lora_symb_nb_timeout( const void* context, const uint8_t nb_of_symbs );
+ral_status_t ral_sx128x_set_lora_symb_nb_timeout( const void* context, const uint16_t nb_of_symbs );
/**
* @see ral_set_flrc_mod_params
@@ -397,6 +399,12 @@ ral_status_t ral_sx128x_lr_fhss_get_time_on_air_in_ms( const void* context, cons
ral_status_t ral_sx128x_lr_fhss_get_hop_sequence_count( const void* context,
const ral_lr_fhss_params_t* lr_fhss_params );
+/**
+ * @see ral_lr_fhss_get_bit_delay_in_us
+ */
+uint16_t ral_sx128x_lr_fhss_get_bit_delay_in_us( const void* context, const ral_lr_fhss_params_t* params,
+ uint16_t payload_length );
+
/**
* @see ral_get_lora_rx_pkt_cr_crc
*/
@@ -425,6 +433,16 @@ ral_status_t ral_sx128x_get_lora_rx_consumption_in_ua( const void* context, cons
*/
ral_status_t ral_sx128x_get_random_numbers( const void* context, uint32_t* numbers, unsigned int n );
+/**
+ * @see ral_handle_rx_done
+ */
+ral_status_t ral_sx128x_handle_rx_done( const void* context );
+
+/**
+ * @see ral_handle_tx_done
+ */
+ral_status_t ral_sx128x_handle_tx_done( const void* context );
+
#ifdef __cplusplus
}
#endif
diff --git a/shields/LR11XX/LR1110TRK1xKS/BSP/ral_bsp/ral_lr11xx_bsp.c b/shields/LR11XX/LR1110TRK1xKS/BSP/ral_bsp/ral_lr11xx_bsp.c
index 731888a..7e0de61 100644
--- a/shields/LR11XX/LR1110TRK1xKS/BSP/ral_bsp/ral_lr11xx_bsp.c
+++ b/shields/LR11XX/LR1110TRK1xKS/BSP/ral_bsp/ral_lr11xx_bsp.c
@@ -319,13 +319,13 @@ void ral_lr11xx_bsp_get_reg_mode( const void* context, lr11xx_system_reg_mode_t*
*reg_mode = LR11XX_SYSTEM_REG_MODE_DCDC;
}
-void ral_lr11xx_bsp_get_xosc_cfg( const void* context, bool* tcxo_is_radio_controlled,
+void ral_lr11xx_bsp_get_xosc_cfg( const void* context, ral_xosc_cfg_t* xosc_cfg,
lr11xx_system_tcxo_supply_voltage_t* supply_voltage, uint32_t* startup_time_in_tick )
{
// Radio control TCXO 1.8V and 30 ms of startup time
- *tcxo_is_radio_controlled = true;
- *supply_voltage = LR11XX_SYSTEM_TCXO_CTRL_1_8V;
- *startup_time_in_tick = 982; // 30ms in 30.52µs ticks
+ *xosc_cfg = RAL_XOSC_CFG_TCXO_RADIO_CTRL;
+ *supply_voltage = LR11XX_SYSTEM_TCXO_CTRL_1_8V;
+ *startup_time_in_tick = 982; // 30ms in 30.52µs ticks
}
void ral_lr11xx_bsp_get_crc_state( const void* context, bool* crc_is_activated )
diff --git a/shields/LR11XX/common/src/ral_lr11xx_bsp.c b/shields/LR11XX/common/src/ral_lr11xx_bsp.c
index 3bc9c48..d396191 100644
--- a/shields/LR11XX/common/src/ral_lr11xx_bsp.c
+++ b/shields/LR11XX/common/src/ral_lr11xx_bsp.c
@@ -104,14 +104,14 @@ void ral_lr11xx_bsp_get_reg_mode( const void* context, lr11xx_system_reg_mode_t*
*reg_mode = smtc_shield_lr11xx_get_reg_mode( );
}
-void ral_lr11xx_bsp_get_xosc_cfg( const void* context, bool* tcxo_is_radio_controlled,
+void ral_lr11xx_bsp_get_xosc_cfg( const void* context, ral_xosc_cfg_t* xosc_cfg,
lr11xx_system_tcxo_supply_voltage_t* supply_voltage, uint32_t* startup_time_in_tick )
{
const smtc_shield_lr11xx_tcxo_cfg_t tcxo_cfg = smtc_shield_lr11xx_get_tcxo_cfg( );
- *tcxo_is_radio_controlled = tcxo_cfg.has_tcxo;
- *supply_voltage = tcxo_cfg.supply;
- *startup_time_in_tick = tcxo_cfg.startup_time_in_tick;
+ *xosc_cfg = tcxo_cfg.xosc_cfg;
+ *supply_voltage = tcxo_cfg.supply;
+ *startup_time_in_tick = tcxo_cfg.startup_time_in_tick;
}
void ral_lr11xx_bsp_get_crc_state( const void* context, bool* crc_is_activated )
diff --git a/shields/LR11XX/common/src/smtc_board_lr11xx.c b/shields/LR11XX/common/src/smtc_board_lr11xx.c
index 418a6de..6ca6e91 100644
--- a/shields/LR11XX/common/src/smtc_board_lr11xx.c
+++ b/shields/LR11XX/common/src/smtc_board_lr11xx.c
@@ -118,7 +118,7 @@ uint32_t smtc_board_get_tcxo_startup_time_in_ms( void )
{
const smtc_shield_lr11xx_tcxo_cfg_t cfg = smtc_shield_lr11xx_get_tcxo_cfg( );
- if( cfg.has_tcxo == true )
+ if( cfg.xosc_cfg != RAL_XOSC_CFG_XTAL )
{
return cfg.startup_time_in_tick * 1000 / 32768;
}
diff --git a/shields/LR11XX/smtc_shield_lr11xx/common/inc/smtc_shield_lr11xx_common_if.h b/shields/LR11XX/smtc_shield_lr11xx/common/inc/smtc_shield_lr11xx_common_if.h
index 50719b8..1eae778 100644
--- a/shields/LR11XX/smtc_shield_lr11xx/common/inc/smtc_shield_lr11xx_common_if.h
+++ b/shields/LR11XX/smtc_shield_lr11xx/common/inc/smtc_shield_lr11xx_common_if.h
@@ -45,6 +45,7 @@ extern "C" {
#include
#include
+#include "ral_lr11xx_bsp.h"
#include "lr11xx_radio_types.h"
#include "lr11xx_system_types.h"
@@ -71,7 +72,7 @@ typedef struct smtc_shield_lr11xx_pa_pwr_cfg_s
typedef struct
{
- bool has_tcxo;
+ ral_xosc_cfg_t xosc_cfg;
lr11xx_system_tcxo_supply_voltage_t supply;
uint32_t startup_time_in_tick;
} smtc_shield_lr11xx_tcxo_cfg_t;
diff --git a/shields/LR11XX/smtc_shield_lr11xx/common/src/smtc_shield_lr11x0_common.c b/shields/LR11XX/smtc_shield_lr11xx/common/src/smtc_shield_lr11x0_common.c
index 760b1f6..6d7b90a 100644
--- a/shields/LR11XX/smtc_shield_lr11xx/common/src/smtc_shield_lr11x0_common.c
+++ b/shields/LR11XX/smtc_shield_lr11xx/common/src/smtc_shield_lr11x0_common.c
@@ -53,18 +53,18 @@
*/
const lr11xx_system_rfswitch_cfg_t rfswitch_cfg = {
- .enable = LR11XX_SYSTEM_RFSW0_HIGH | LR11XX_SYSTEM_RFSW1_HIGH,
+ .enable = LR11XX_SYSTEM_RFSW0_HIGH | LR11XX_SYSTEM_RFSW1_HIGH | LR11XX_SYSTEM_RFSW2_HIGH,
.standby = 0,
.rx = LR11XX_SYSTEM_RFSW0_HIGH,
.tx = LR11XX_SYSTEM_RFSW0_HIGH | LR11XX_SYSTEM_RFSW1_HIGH,
.tx_hp = LR11XX_SYSTEM_RFSW1_HIGH,
.tx_hf = 0,
- .gnss = 0,
+ .gnss = LR11XX_SYSTEM_RFSW2_HIGH,
.wifi = 0,
};
const smtc_shield_lr11xx_tcxo_cfg_t tcxo_cfg = {
- .has_tcxo = true,
+ .xosc_cfg = RAL_XOSC_CFG_TCXO_RADIO_CTRL,
.supply = LR11XX_SYSTEM_TCXO_CTRL_3_0V,
.startup_time_in_tick = 164,
};
@@ -118,13 +118,13 @@ void smtc_shield_lr11xx_deinit( void )
void smtc_shield_lr11xx_handle_pre_gnss_scan( void )
{
smtc_shield_lr11xx_set_led_scan( );
- smtc_shield_lr11xx_set_lna_scan( );
+ smtc_shield_lr11xx_set_lna_scan( ); /* Not required if LNA is driven by LR11xx */
}
void smtc_shield_lr11xx_handle_post_gnss_scan( void )
{
smtc_shield_lr11xx_reset_led_scan( );
- smtc_shield_lr11xx_reset_lna_scan( );
+ smtc_shield_lr11xx_reset_lna_scan( ); /* Not required if LNA is driven by LR11xx */
}
void smtc_shield_lr11xx_handle_pre_wifi_scan( void )
diff --git a/smtc_hal/STMicroelectronics/STM32L4xx/src/smtc_hal_mcu.c b/smtc_hal/STMicroelectronics/STM32L4xx/src/smtc_hal_mcu.c
index 91b45fb..cf8b17f 100644
--- a/smtc_hal/STMicroelectronics/STM32L4xx/src/smtc_hal_mcu.c
+++ b/smtc_hal/STMicroelectronics/STM32L4xx/src/smtc_hal_mcu.c
@@ -624,4 +624,4 @@ static void vprint( const char* fmt, va_list argp )
}
#endif
-/* --- EOF ------------------------------------------------------------------ */
+/* --- EOF ------------------------------------------------------------------ */
\ No newline at end of file
diff --git a/smtc_hal/STMicroelectronics/STM32WB55xx/smtc_modem_hal/smtc_modem_hal.c b/smtc_hal/STMicroelectronics/STM32WB55xx/smtc_modem_hal/smtc_modem_hal.c
index 1b69277..6a59611 100644
--- a/smtc_hal/STMicroelectronics/STM32WB55xx/smtc_modem_hal/smtc_modem_hal.c
+++ b/smtc_hal/STMicroelectronics/STM32WB55xx/smtc_modem_hal/smtc_modem_hal.c
@@ -39,6 +39,7 @@
#include
#include
+#include
#include "ralf.h"