Skip to content

Commit 207ae2d

Browse files
author
Hasnain Virk
committed
Adding FSB selection feature for US915 PHY
User can now define a custom frequency sub-band for the US915 PHY. FSB_Usage.txt defines how this parameter will be configured.
1 parent 2d33053 commit 207ae2d

File tree

3 files changed

+79
-37
lines changed

3 files changed

+79
-37
lines changed

features/lorawan/FSB_Usage.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Frequency sub-bands in US915/AU915:
2+
3+
US915/AU915 PHYs define channel structures which can support up-to 72 channels for upstream.
4+
First 64 channels (0-63), occupy 125 kHz and the last 8 channels (64-71) occupy 500 kHz.
5+
However, most of the base stations available in the market support 8 or 16 channels.
6+
Network acquisition can become costly if the device have no prior knowledge of active channel plan and it enables
7+
all 72 channels to begin with.
8+
9+
LoRaWAN 1.0.2 Regional parameters specification refers to a strategy of probing a set of nine channels (8 + 1) for
10+
joining process. According to that strategy the device is supposed to alternatively select a channel from a set of
11+
8, 125 kHz channels and a 500 kHz channel.
12+
For example send a join request alternatively on a randomly selected channel from a set of 0-7 channels and
13+
channel 64 which is the first 500 kHz channel.
14+
15+
Once the device has joined the network (in case of OTAA) or have sent the first uplink (in case of ABP), the network
16+
may send a LinkAdrReq mac command to set the channel mask to be used. Please note that these PHY layers do not
17+
support CFList so LinkAdrReq is the way the network tells you what channel plan to use.
18+
19+
Mbed LoRaWAN stack can be configured to use a particular frequency sub-band (FSB) which means that we don't have to
20+
probe all sets of channels. "fsb-mask" in lorawan/mbed_lib.json is the parameter which can be used to tell the
21+
system which FSB or a set of FSBs to use. By default the "fsb-mask" is set to "{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}"
22+
that means all channels are active, i.e., 64 125 kHz channels and 8 500 kHz channels are active. If the user wishes
23+
to use a custom FSB, he/she needs to set appropriate mask as the value of "fsb-mask". For example:
24+
If the user wishes to use the first FSB, i.e., first 8 125 kHz channels (0-7) and the first 500 kHz channel:
25+
"fsb-mask" = "{0x00FF, 0x0000, 0x0000, 0x0000, 0x0001}"
26+
Similarly, if the user wishes to use second FSB, i.e., 2nd set of 8 125 kHz channels (8-15) and the 2nd 500 kHz
27+
channel:
28+
"fsb-mask" = "{0xFF00, 0x0000, 0x0000, 0x0000, 0x0002}"
29+
30+
You can also combine FSBs if your base station supports more than 8 channels. For example:
31+
"fsb-mask" = "{0x00FF, 0x0000, 0x0000, 0xFF00, 0x0081}"
32+
will mean use channels 0-7(125 kHz) + channel 64 (500 KHz) and channels 56-63 (125 kHz) + channel 71 (500 kHz).
33+
34+
Please note that for Certification requirements, you need to alternate between 125 kHz and 500 kHz channels and that's
35+
why before joining you should not set a mask that enables only 500 kHz or only 125 kHz channels.

features/lorawan/lorastack/phy/LoRaPHYUS915.cpp

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -204,45 +204,52 @@ static const int8_t datarate_offsets_US915[5][4] =
204204
/*!
205205
* Maximum payload with respect to the datarate index. Cannot operate with repeater.
206206
*/
207-
static const uint8_t max_payloads_US915[] = { 11, 53, 125, 242, 242, 0, 0, 0, 53, 129, 242, 242, 242, 242, 0, 0 };
207+
static const uint8_t max_payloads_US915[] = {11, 53, 125, 242, 242, 0, 0, 0, 53, 129, 242, 242, 242, 242, 0, 0};
208208

209209
/*!
210210
* Maximum payload with respect to the datarate index. Can operate with repeater.
211211
*/
212212
static const uint8_t max_payloads_with_repeater_US915[] = {11, 53, 125, 242, 242, 0, 0, 0, 33, 109, 222, 222, 222, 222, 0, 0};
213213

214+
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK;
215+
214216
LoRaPHYUS915::LoRaPHYUS915()
215217
{
216218
bands[0] = US915_BAND0;
217219

218220
// Channels
219-
// 125 kHz channels
221+
// 125 kHz channels - Upstream
220222
for (uint8_t i = 0; i < US915_MAX_NB_CHANNELS - 8; i++) {
221223
channels[i].frequency = 902300000 + i * 200000;
222224
channels[i].dr_range.value = ( DR_3 << 4) | DR_0;
223225
channels[i].band = 0;
224226
}
225-
// 500 kHz channels
227+
// 500 kHz channels - Upstream
226228
for (uint8_t i = US915_MAX_NB_CHANNELS - 8; i < US915_MAX_NB_CHANNELS; i++) {
227229
channels[i].frequency = 903000000 + (i - ( US915_MAX_NB_CHANNELS - 8)) * 1600000;
228230
channels[i].dr_range.value = ( DR_4 << 4) | DR_4;
229231
channels[i].band = 0;
230232
}
231233

232234
// ChannelsMask
233-
default_channel_mask[0] = 0xFFFF;
234-
default_channel_mask[1] = 0xFFFF;
235-
default_channel_mask[2] = 0xFFFF;
236-
default_channel_mask[3] = 0xFFFF;
237-
default_channel_mask[4] = 0x00FF;
235+
for (uint8_t i = 0; i < US915_MAX_NB_CHANNELS; i++) {
236+
if (i == (US915_MAX_NB_CHANNELS - 1)) {
237+
// 64 - 71, 500 kHz channels will get enabled
238+
default_channel_mask[i] = 0x00FF & fsb_mask[i];
239+
continue;
240+
}
241+
242+
// 0 - 63 125 kHz channels will get enabled
243+
default_channel_mask[i] = 0xFFFF & fsb_mask[i];
244+
}
238245

239246
memset(channel_mask, 0, sizeof(channel_mask));
240247
memset(current_channel_mask, 0, sizeof(current_channel_mask));
241248

242249
// Copy channels default mask
243250
copy_channel_mask(channel_mask, default_channel_mask, US915_CHANNEL_MASK_SIZE);
244251

245-
// current channel masks keep track what of the
252+
// current channel masks keep track of the
246253
// channels previously used, i.e., which channels should be avoided in
247254
// next transmission
248255
copy_channel_mask(current_channel_mask, channel_mask, US915_CHANNEL_MASK_SIZE);
@@ -346,7 +353,7 @@ void LoRaPHYUS915::restore_default_channels()
346353
// Copy channels default mask
347354
copy_channel_mask(channel_mask, default_channel_mask, US915_CHANNEL_MASK_SIZE);
348355

349-
for ( uint8_t i = 0; i < US915_CHANNEL_MASK_SIZE; i++ ) {
356+
for (uint8_t i = 0; i < US915_CHANNEL_MASK_SIZE; i++) {
350357
// Copy-And the channels mask
351358
current_channel_mask[i] &= channel_mask[i];
352359
}
@@ -384,10 +391,11 @@ bool LoRaPHYUS915::rx_config(rx_config_params_t* config)
384391

385392
_radio->lock();
386393

387-
_radio->set_channel( frequency );
394+
_radio->set_channel(frequency);
388395

389396
// Radio configuration
390-
_radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0, 8,
397+
_radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0,
398+
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
391399
config->window_timeout, false, 0, false, 0, 0, true,
392400
config->is_rx_continuous);
393401
_radio->unlock();
@@ -429,7 +437,8 @@ bool LoRaPHYUS915::tx_config(tx_config_params_t* config, int8_t* tx_power,
429437

430438
_radio->set_channel(channels[config->channel].frequency);
431439

432-
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
440+
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1,
441+
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH,
433442
false, true, 0, 0, false, 3000);
434443

435444
// Setup maximum payload lenght of the radio driver
@@ -478,20 +487,20 @@ uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
478487
if (adr_settings.ch_mask_ctrl == 6) {
479488

480489
// Enable all 125 kHz channels
481-
temp_channel_masks[0] = 0xFFFF;
482-
temp_channel_masks[1] = 0xFFFF;
483-
temp_channel_masks[2] = 0xFFFF;
484-
temp_channel_masks[3] = 0xFFFF;
490+
for (uint8_t i = 0; i < US915_CHANNEL_MASK_SIZE - 1; i++) {
491+
temp_channel_masks[i] = 0xFFFF;
492+
}
493+
485494
// Apply chMask to channels 64 to 71
486495
temp_channel_masks[4] = adr_settings.channel_mask;
487496

488497
} else if (adr_settings.ch_mask_ctrl == 7) {
489498

490499
// Disable all 125 kHz channels
491-
temp_channel_masks[0] = 0x0000;
492-
temp_channel_masks[1] = 0x0000;
493-
temp_channel_masks[2] = 0x0000;
494-
temp_channel_masks[3] = 0x0000;
500+
for (uint8_t i = 0; i < US915_CHANNEL_MASK_SIZE - 1; i++) {
501+
temp_channel_masks[i] = 0x0000;
502+
}
503+
495504
// Apply chMask to channels 64 to 71
496505
temp_channel_masks[4] = adr_settings.channel_mask;
497506

@@ -531,11 +540,9 @@ uint8_t LoRaPHYUS915::link_ADR_request(adr_req_params_t* params,
531540
// Copy Mask
532541
copy_channel_mask(channel_mask, temp_channel_masks, US915_CHANNEL_MASK_SIZE);
533542

534-
current_channel_mask[0] &= channel_mask[0];
535-
current_channel_mask[1] &= channel_mask[1];
536-
current_channel_mask[2] &= channel_mask[2];
537-
current_channel_mask[3] &= channel_mask[3];
538-
current_channel_mask[4] = channel_mask[4];
543+
for (uint8_t i = 0; i < US915_CHANNEL_MASK_SIZE; i++) {
544+
current_channel_mask[i] &= channel_mask[i];
545+
}
539546
}
540547

541548
// Update status variables
@@ -553,7 +560,7 @@ uint8_t LoRaPHYUS915::accept_rx_param_setup_req(rx_param_setup_req_t* params)
553560
uint32_t freq = params->frequency;
554561

555562
// Verify radio frequency
556-
if ((_radio->check_rf_frequency( freq ) == false)
563+
if ((_radio->check_rf_frequency(freq) == false)
557564
|| (freq < US915_FIRST_RX1_CHANNEL)
558565
|| (freq > US915_LAST_RX1_CHANNEL)
559566
|| (((freq - (uint32_t) US915_FIRST_RX1_CHANNEL) % (uint32_t) US915_STEPWIDTH_RX1_CHANNEL) != 0)) {
@@ -588,9 +595,6 @@ int8_t LoRaPHYUS915::get_alternate_DR(uint8_t nb_trials)
588595
{
589596
int8_t datarate = 0;
590597

591-
// Re-enable 500 kHz default channels
592-
channel_mask[4] = 0x00FF;
593-
594598
if ((nb_trials & 0x01) == 0x01) {
595599
datarate = DR_4;
596600
} else {
@@ -616,11 +620,10 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
616620
copy_channel_mask(current_channel_mask, channel_mask, 4);
617621
}
618622

619-
// Check other channels
620-
if (params->current_datarate >= DR_4) {
621-
if ((current_channel_mask[4] & 0x00FF ) == 0) {
622-
current_channel_mask[4] = channel_mask[4];
623-
}
623+
// Update the 500 kHz channels in the running mask
624+
if ((params->current_datarate >= DR_4)
625+
&& (current_channel_mask[4] & 0x00FF) == 0) {
626+
current_channel_mask[4] = channel_mask[4];
624627
}
625628

626629
if (params->aggregate_timeoff <= _lora_time->get_elapsed_time(params->last_aggregate_tx_time)) {
@@ -641,9 +644,9 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
641644

642645
if (nb_enabled_channels > 0) {
643646
// We found a valid channel
644-
*channel = enabled_channels[get_random( 0, nb_enabled_channels - 1 )];
647+
*channel = enabled_channels[get_random(0, nb_enabled_channels - 1)];
645648
// Disable the channel in the mask
646-
disable_channel(current_channel_mask, *channel, US915_MAX_NB_CHANNELS - 8);
649+
disable_channel(current_channel_mask, *channel, US915_MAX_NB_CHANNELS);
647650

648651
*time = 0;
649652
return LORAWAN_STATUS_OK;

features/lorawan/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
"uplink-preamble-length": {
8181
"help": "Number of preamble symbols to transmit. Must be <= 8",
8282
"value": 8
83+
},
84+
"fsb-mask": {
85+
"help": "FSB mask for upstream [Only for US915, US915_HYBRID & AU915] Check lorawan/FSB_Usage.txt for more details",
86+
"value": "{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}"
8387
}
8488
}
8589
}

0 commit comments

Comments
 (0)