Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LoRaPHYAS923.cpp
00001 /** 00002 * @file LoRaPHYAS923.cpp 00003 * 00004 * @brief Implements LoRaPHY for Asia-Pacific 923 MHz band 00005 * 00006 * \code 00007 * ______ _ 00008 * / _____) _ | | 00009 * ( (____ _____ ____ _| |_ _____ ____| |__ 00010 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 00011 * _____) ) ____| | | || |_| ____( (___| | | | 00012 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 00013 * (C)2013 Semtech 00014 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 00015 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 00016 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 00017 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 00018 * embedded.connectivity.solutions=============== 00019 * 00020 * \endcode 00021 * 00022 * 00023 * License: Revised BSD License, see LICENSE.TXT file include in the project 00024 * 00025 * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE ) 00026 * 00027 * Copyright (c) 2017, Arm Limited and affiliates. 00028 * SPDX-License-Identifier: BSD-3-Clause 00029 * 00030 */ 00031 00032 #include "LoRaPHYAS923.h" 00033 #include "lora_phy_ds.h" 00034 00035 /*! 00036 * Number of default channels 00037 */ 00038 #define AS923_NUMB_DEFAULT_CHANNELS 2 00039 00040 /*! 00041 * Number of channels to apply for the CF list 00042 */ 00043 #define AS923_NUMB_CHANNELS_CF_LIST 5 00044 00045 /*! 00046 * Minimal datarate that can be used by the node 00047 */ 00048 #define AS923_TX_MIN_DATARATE DR_0 00049 00050 /*! 00051 * Maximal datarate that can be used by the node 00052 */ 00053 #define AS923_TX_MAX_DATARATE DR_7 00054 00055 /*! 00056 * Minimal datarate that can be used by the node 00057 */ 00058 #define AS923_RX_MIN_DATARATE DR_0 00059 00060 /*! 00061 * Maximal datarate that can be used by the node 00062 */ 00063 #define AS923_RX_MAX_DATARATE DR_7 00064 00065 /*! 00066 * Default datarate used by the node 00067 */ 00068 #define AS923_DEFAULT_DATARATE DR_2 00069 00070 #define AS923_DEFAULT_MAX_DATARATE DR_7 00071 00072 /*! 00073 * The minimum datarate which is used when the 00074 * dwell time is limited. 00075 */ 00076 #define AS923_DWELL_LIMIT_DATARATE DR_2 00077 00078 /*! 00079 * Minimal Rx1 receive datarate offset 00080 */ 00081 #define AS923_MIN_RX1_DR_OFFSET 0 00082 00083 /*! 00084 * Maximal Rx1 receive datarate offset 00085 */ 00086 #define AS923_MAX_RX1_DR_OFFSET 7 00087 00088 /*! 00089 * Default Rx1 receive datarate offset 00090 */ 00091 #define AS923_DEFAULT_RX1_DR_OFFSET 0 00092 00093 /*! 00094 * Minimal Tx output power that can be used by the node 00095 */ 00096 #define AS923_MIN_TX_POWER TX_POWER_7 00097 00098 /*! 00099 * Maximal Tx output power that can be used by the node 00100 */ 00101 #define AS923_MAX_TX_POWER TX_POWER_0 00102 00103 /*! 00104 * Default Tx output power used by the node 00105 */ 00106 #define AS923_DEFAULT_TX_POWER TX_POWER_0 00107 00108 /*! 00109 * Default Max EIRP 00110 */ 00111 #define AS923_DEFAULT_MAX_EIRP 16.0f 00112 00113 /*! 00114 * Default antenna gain 00115 */ 00116 #define AS923_DEFAULT_ANTENNA_GAIN 2.15f 00117 00118 /*! 00119 * ADR Ack limit 00120 */ 00121 #define AS923_ADR_ACK_LIMIT 64 00122 00123 /*! 00124 * ADR Ack delay 00125 */ 00126 #define AS923_ADR_ACK_DELAY 32 00127 00128 /*! 00129 * Enabled or disabled the duty cycle 00130 */ 00131 #define AS923_DUTY_CYCLE_ENABLED 0 00132 00133 /*! 00134 * Maximum RX window duration 00135 */ 00136 #define AS923_MAX_RX_WINDOW 3000 00137 00138 /*! 00139 * Receive delay 1 00140 */ 00141 #define AS923_RECEIVE_DELAY1 1000 00142 00143 /*! 00144 * Receive delay 2 00145 */ 00146 #define AS923_RECEIVE_DELAY2 2000 00147 00148 /*! 00149 * Join accept delay 1 00150 */ 00151 #define AS923_JOIN_ACCEPT_DELAY1 5000 00152 00153 /*! 00154 * Join accept delay 2 00155 */ 00156 #define AS923_JOIN_ACCEPT_DELAY2 6000 00157 00158 /*! 00159 * Maximum frame counter gap 00160 */ 00161 #define AS923_MAX_FCNT_GAP 16384 00162 00163 /*! 00164 * Ack timeout 00165 */ 00166 #define AS923_ACKTIMEOUT 2000 00167 00168 /*! 00169 * Random ack timeout limits 00170 */ 00171 #define AS923_ACK_TIMEOUT_RND 1000 00172 00173 #if ( AS923_DEFAULT_DATARATE > DR_5 ) 00174 #error "A default DR higher than DR_5 may lead to connectivity loss." 00175 #endif 00176 00177 /*! 00178 * Second reception window channel frequency definition. 00179 */ 00180 #define AS923_RX_WND_2_FREQ 923200000 00181 00182 /*! 00183 * Second reception window channel datarate definition. 00184 */ 00185 #define AS923_RX_WND_2_DR DR_2 00186 00187 /*! 00188 * Band 0 definition 00189 * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } 00190 */ 00191 static const band_t AS923_BAND0 = {100, AS923_MAX_TX_POWER, 0, 0, 0, 923000000, 928000000}; // 1.0 % 00192 00193 /*! 00194 * LoRaMac default channel 1 00195 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 00196 */ 00197 static const channel_params_t AS923_LC1 = { 923200000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }; 00198 00199 /*! 00200 * LoRaMac default channel 2 00201 * Channel = { Frequency [Hz], RX1 Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } 00202 */ 00203 static const channel_params_t AS923_LC2 = { 923400000, 0, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }; 00204 00205 /*! 00206 * LoRaMac channels which are allowed for the join procedure 00207 */ 00208 #define AS923_JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) ) 00209 00210 /*! 00211 * RSSI threshold for a free channel [dBm] 00212 */ 00213 #define AS923_RSSI_FREE_TH -85 00214 00215 /*! 00216 * Specifies the time the node performs a carrier sense 00217 */ 00218 #define AS923_CARRIER_SENSE_TIME 6 00219 00220 /*! 00221 * Data rates table definition 00222 */ 00223 static const uint8_t datarates_AS923 [] = {12, 11, 10, 9, 8, 7, 7, 50}; 00224 00225 /*! 00226 * Bandwidths table definition in Hz 00227 */ 00228 static const uint32_t bandwidths_AS923 [] = {125000, 125000, 125000, 125000, 125000, 125000, 250000, 0}; 00229 00230 #if (MBED_CONF_LORA_DWELL_TIME == 0) 00231 static const uint8_t max_payload_table[] = {51, 51, 51, 115, 242, 242, 242, 242}; 00232 static const uint8_t max_payload_table_with_repeater[] = {51, 51, 51, 115, 222, 222, 222, 222}; 00233 #else 00234 // this is the default, i.e., 00235 static const uint8_t max_payload_table[] = {0, 0, 11, 53, 125, 242, 242, 242}; 00236 static const uint8_t max_payload_table_with_repeater[] = {0, 0, 11, 53, 125, 242, 242, 242}; 00237 #endif 00238 00239 /*! 00240 * Effective datarate offsets for receive window 1. 00241 */ 00242 static const int8_t rx1_dr_offset_AS923 [] = {0, 1, 2, 3, 4, 5, -1, -2}; 00243 00244 LoRaPHYAS923::LoRaPHYAS923(LoRaWANTimeHandler &lora_time) 00245 : LoRaPHY(lora_time) 00246 { 00247 bands[0] = AS923_BAND0 ; 00248 00249 // Default Channels are always enabled in the channel list, 00250 // rest will be added later 00251 channels[0] = AS923_LC1 ; 00252 channels[0].band = 0; 00253 channels[1] = AS923_LC2 ; 00254 channels[1].band = 0; 00255 00256 // Initialize the default channel mask 00257 default_channel_mask[0] = LC(1) + LC(2); 00258 00259 // Update the channel mask list 00260 copy_channel_mask(channel_mask, default_channel_mask, AS923_CHANNEL_MASK_SIZE); 00261 00262 // set default channels 00263 phy_params.channels.channel_list = channels; 00264 phy_params.channels.channel_list_size = AS923_MAX_NB_CHANNELS; 00265 phy_params.channels.mask = channel_mask; 00266 phy_params.channels.default_mask = default_channel_mask; 00267 phy_params.channels.mask_size = AS923_CHANNEL_MASK_SIZE; 00268 00269 // set bands for AS923 spectrum 00270 phy_params.bands.table = (void *) bands; 00271 phy_params.bands.size = AS923_MAX_NB_BANDS; 00272 00273 // set bandwidths available in AS923 spectrum 00274 phy_params.bandwidths.table = (void *) bandwidths_AS923 ; 00275 phy_params.bandwidths.size = 8; 00276 00277 // set data rates available in AS923 spectrum 00278 phy_params.datarates.table = (void *) datarates_AS923 ; 00279 phy_params.datarates.size = 8; 00280 00281 // set payload sizes with respect to data rates 00282 phy_params.payloads.table = (void *) max_payload_table; 00283 phy_params.payloads.size = 8; 00284 phy_params.payloads_with_repeater.table = (void *) max_payload_table_with_repeater; 00285 phy_params.payloads_with_repeater.size = 8; 00286 00287 // dwell time setting, 400 ms 00288 phy_params.ul_dwell_time_setting = 1; 00289 phy_params.dl_dwell_time_setting = 1; 00290 phy_params.dwell_limit_datarate = AS923_DWELL_LIMIT_DATARATE; 00291 00292 phy_params.duty_cycle_enabled = AS923_DUTY_CYCLE_ENABLED; 00293 phy_params.accept_tx_param_setup_req = true; 00294 phy_params.fsk_supported = true; 00295 phy_params.cflist_supported = true; 00296 phy_params.dl_channel_req_supported = true; 00297 phy_params.custom_channelplans_supported = true; 00298 phy_params.default_channel_cnt = AS923_NUMB_DEFAULT_CHANNELS; 00299 phy_params.max_channel_cnt = AS923_MAX_NB_CHANNELS; 00300 phy_params.cflist_channel_cnt = AS923_NUMB_CHANNELS_CF_LIST; 00301 phy_params.min_tx_datarate = AS923_TX_MIN_DATARATE; 00302 phy_params.max_tx_datarate = AS923_TX_MAX_DATARATE; 00303 phy_params.min_rx_datarate = AS923_RX_MIN_DATARATE; 00304 phy_params.max_rx_datarate = AS923_RX_MAX_DATARATE; 00305 phy_params.default_datarate = AS923_DEFAULT_DATARATE; 00306 phy_params.default_max_datarate = AS923_DEFAULT_MAX_DATARATE; 00307 phy_params.min_rx1_dr_offset = AS923_MIN_RX1_DR_OFFSET; 00308 phy_params.max_rx1_dr_offset = AS923_MAX_RX1_DR_OFFSET; 00309 phy_params.default_rx1_dr_offset = AS923_DEFAULT_RX1_DR_OFFSET; 00310 phy_params.min_tx_power = AS923_MIN_TX_POWER; 00311 phy_params.max_tx_power = AS923_MAX_TX_POWER; 00312 phy_params.default_tx_power = AS923_DEFAULT_TX_POWER; 00313 phy_params.default_max_eirp = AS923_DEFAULT_MAX_EIRP; 00314 phy_params.default_antenna_gain = AS923_DEFAULT_ANTENNA_GAIN; 00315 phy_params.adr_ack_limit = AS923_ADR_ACK_LIMIT; 00316 phy_params.adr_ack_delay = AS923_ADR_ACK_DELAY; 00317 phy_params.max_rx_window = AS923_MAX_RX_WINDOW; 00318 phy_params.recv_delay1 = AS923_RECEIVE_DELAY1; 00319 phy_params.recv_delay2 = AS923_RECEIVE_DELAY2; 00320 phy_params.join_channel_mask = AS923_JOIN_CHANNELS; 00321 phy_params.join_accept_delay1 = AS923_JOIN_ACCEPT_DELAY1; 00322 phy_params.join_accept_delay2 = AS923_JOIN_ACCEPT_DELAY2; 00323 phy_params.max_fcnt_gap = AS923_MAX_FCNT_GAP; 00324 phy_params.ack_timeout = AS923_ACKTIMEOUT; 00325 phy_params.ack_timeout_rnd = AS923_ACK_TIMEOUT_RND; 00326 phy_params.rx_window2_datarate = AS923_RX_WND_2_DR; 00327 phy_params.rx_window2_frequency = AS923_RX_WND_2_FREQ; 00328 } 00329 00330 LoRaPHYAS923::~LoRaPHYAS923() 00331 { 00332 } 00333 00334 int8_t LoRaPHYAS923::get_alternate_DR(uint8_t nb_trials) 00335 { 00336 // Only AS923_DWELL_LIMIT_DATARATE is supported 00337 return AS923_DWELL_LIMIT_DATARATE; 00338 } 00339 00340 lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next_channel_prams, 00341 uint8_t* channel, lorawan_time_t* time, 00342 lorawan_time_t* aggregate_timeoff) 00343 { 00344 uint8_t next_channel_idx = 0; 00345 uint8_t nb_enabled_channels = 0; 00346 uint8_t delay_tx = 0; 00347 uint8_t enabled_channels[AS923_MAX_NB_CHANNELS] = { 0 }; 00348 lorawan_time_t next_tx_delay = 0; 00349 00350 if (num_active_channels(channel_mask, 0, 1) == 0) { 00351 // Reactivate default channels 00352 channel_mask[0] |= LC(1) + LC(2); 00353 } 00354 00355 if (next_channel_prams->aggregate_timeoff <= _lora_time.get_elapsed_time(next_channel_prams->last_aggregate_tx_time)) { 00356 // Reset Aggregated time off 00357 *aggregate_timeoff = 0; 00358 00359 // Update bands Time OFF 00360 next_tx_delay = update_band_timeoff(next_channel_prams->joined, 00361 next_channel_prams->dc_enabled, 00362 bands, AS923_MAX_NB_BANDS); 00363 00364 // Search how many channels are enabled 00365 nb_enabled_channels = enabled_channel_count(next_channel_prams->joined, 00366 next_channel_prams->current_datarate, 00367 channel_mask, 00368 enabled_channels, &delay_tx); 00369 } else { 00370 delay_tx++; 00371 next_tx_delay = next_channel_prams->aggregate_timeoff - _lora_time.get_elapsed_time(next_channel_prams->last_aggregate_tx_time); 00372 } 00373 00374 if (nb_enabled_channels > 0) { 00375 00376 _radio->lock(); 00377 00378 for (uint8_t i = 0, j = get_random(0, nb_enabled_channels - 1); i < AS923_MAX_NB_CHANNELS; i++) { 00379 next_channel_idx = enabled_channels[j]; 00380 j = ( j + 1 ) % nb_enabled_channels; 00381 00382 // Perform carrier sense for AS923_CARRIER_SENSE_TIME 00383 // If the channel is free, we can stop the LBT mechanism 00384 00385 if (_radio->perform_carrier_sense(MODEM_LORA, 00386 channels[next_channel_idx].frequency, 00387 AS923_RSSI_FREE_TH, 00388 AS923_CARRIER_SENSE_TIME) == true) { 00389 // Free channel found 00390 _radio->unlock(); 00391 *channel = next_channel_idx; 00392 *time = 0; 00393 return LORAWAN_STATUS_OK; 00394 } 00395 } 00396 _radio->unlock(); 00397 return LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND; 00398 } else { 00399 00400 if (delay_tx > 0) { 00401 // Delay transmission due to AggregatedTimeOff or to a band time off 00402 *time = next_tx_delay; 00403 return LORAWAN_STATUS_DUTYCYCLE_RESTRICTED; 00404 } 00405 00406 // Datarate not supported by any channel, restore defaults 00407 channel_mask[0] |= LC( 1 ) + LC( 2 ); 00408 *time = 0; 00409 return LORAWAN_STATUS_NO_CHANNEL_FOUND; 00410 } 00411 } 00412 00413 uint8_t LoRaPHYAS923::apply_DR_offset(int8_t dr, int8_t dr_offset) 00414 { 00415 // Initialize minDr for a downlink dwell time configuration of 0 00416 int8_t min_dr = DR_0; 00417 00418 // Update the minDR for a downlink dwell time configuration of 1 00419 if (phy_params.dl_dwell_time_setting == 1) { 00420 min_dr = AS923_DWELL_LIMIT_DATARATE; 00421 } 00422 00423 // Apply offset formula 00424 return MIN(DR_5, MAX(min_dr, dr - rx1_dr_offset_AS923 [dr_offset])); 00425 } 00426 00427
Generated on Tue Jul 12 2022 12:32:32 by
