Skip to content

Commit c7d6560

Browse files
authored
Merge pull request #7806 from hasnainvirk/fix_for_cn470
LoRaWAN: Fixing Hard fault in CN470 PHY layer
2 parents 1eab072 + a779e6f commit c7d6560

File tree

4 files changed

+118
-37
lines changed

4 files changed

+118
-37
lines changed

features/lorawan/FSB_Usage.txt

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,52 @@
11
Frequency sub-bands in US915/AU915:
22

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.
3+
US915/AU915 PHYs define channel structures that can support up to 72 channels for upstream.
4+
The first 64 channels (0-63), occupy 125 kHz and the last 8 channels (64-71) occupy 500 kHz.
55
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
6+
Network acquisition can become costly if the device has no prior knowledge of the active channel plan and it enables
77
all 72 channels to begin with.
88

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:
9+
The LoRaWAN 1.0.2 Regional parameters specification refers to a strategy of probing a set of nine channels (8 + 1) for
10+
the joining process. According to that strategy, the device alternatively selects 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 has sent the first uplink (in the 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+
You can configure the Mbed LoRaWAN stack to use a particular frequency sub-band (FSB), which means that you don't have to
20+
probe all sets of channels. "fsb-mask" in lorawan/mbed_lib.json is the parameter that you can use to tell the
21+
system which FSB or 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. In other words, 64 125 kHz channels and 8 500 kHz channels are active. If you wish
23+
to use a custom FSB, you need to set an appropriate mask as the value of "fsb-mask". For example, if you wish to use the
24+
first FSB, in other words, the first 8 125 kHz channels (0-7) and the first 500 kHz channel:
2525
"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
26+
Similarly, if you wish to use the second FSB, in other words, the second set of 8 125 kHz channels (8-15) and the 2nd 500 kHz
2727
channel:
2828
"fsb-mask" = "{0xFF00, 0x0000, 0x0000, 0x0000, 0x0002}"
2929

3030
You can also combine FSBs if your base station supports more than 8 channels. For example:
3131
"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).
32+
means 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, so before joining,
35+
do not set a mask that enables only 500 kHz or only 125 kHz channels.
36+
37+
Frequency sub-bands in CN470 PHY:
38+
39+
The LoRaPHYCN470 class defines 96 channels in total, as per the LoRaWAN Regional Specification. These 96 channels
40+
are 125 kHz wide each and can be subdivided into 6 sub-bands containing 16 channels each.
41+
"fsb-mask-china" is the parameter that lorawan/mbed_lib.json defines. It can be used to enforce an FSB. It is defined
42+
as a C-style array, and the first element of the array corresponds to first 8 channels (0-7) and so on. By default, all
43+
96 channels are enabled, but there may be base stations that do not support all 96 channels. Therefore, network acquisition
44+
can become cumbersome if the device hops on random channels. The probability of finding a correct channel for a base station
45+
that supports 8 channels would be 1/12.
46+
47+
For example, if your base station supports 16 channels (channels 0-15), set the "fsb-mask-china" as:
48+
"fsb-mask-china" = "{0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}"
49+
50+
Similarly, if your base station supports 8 channels (channels 0-7), set the "fsb-mask-china" as:
51+
"fsb-mask-china" = "{0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}"
3352

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/LoRaPHYCN470.cpp

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static const uint8_t max_payloads_with_repeater_CN470[] = {51, 51, 51, 115, 222,
206206

207207
LoRaPHYCN470::LoRaPHYCN470()
208208
{
209+
static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK_CHINA;
210+
209211
bands[0] = CN470_BAND0;
210212

211213
// Channels
@@ -218,12 +220,9 @@ LoRaPHYCN470::LoRaPHYCN470()
218220
}
219221

220222
// Initialize the channels default mask
221-
default_channel_mask[0] = 0xFFFF;
222-
default_channel_mask[1] = 0xFFFF;
223-
default_channel_mask[2] = 0xFFFF;
224-
default_channel_mask[3] = 0xFFFF;
225-
default_channel_mask[4] = 0xFFFF;
226-
default_channel_mask[5] = 0xFFFF;
223+
for (uint8_t i = 0; i < CN470_MAX_NB_CHANNELS; i++) {
224+
default_channel_mask[i] = 0xFFFF & fsb_mask[i];
225+
}
227226

228227
// Update the channels mask
229228
copy_channel_mask(channel_mask, default_channel_mask, CN470_CHANNEL_MASK_SIZE);
@@ -302,6 +301,64 @@ LoRaPHYCN470::~LoRaPHYCN470()
302301
{
303302
}
304303

304+
lorawan_status_t LoRaPHYCN470::set_next_channel(channel_selection_params_t *params,
305+
uint8_t *channel, lorawan_time_t *time,
306+
lorawan_time_t *aggregate_timeoff)
307+
{
308+
uint8_t channel_count = 0;
309+
uint8_t delay_tx = 0;
310+
311+
uint8_t enabled_channels[CN470_MAX_NB_CHANNELS] = {0};
312+
313+
lorawan_time_t next_tx_delay = 0;
314+
band_t *band_table = (band_t *) phy_params.bands.table;
315+
316+
if (num_active_channels(phy_params.channels.mask, 0,
317+
phy_params.channels.mask_size) == 0) {
318+
319+
// Reactivate default channels
320+
copy_channel_mask(phy_params.channels.mask,
321+
phy_params.channels.default_mask,
322+
phy_params.channels.mask_size);
323+
}
324+
325+
if (params->aggregate_timeoff
326+
<= _lora_time->get_elapsed_time(params->last_aggregate_tx_time)) {
327+
// Reset Aggregated time off
328+
*aggregate_timeoff = 0;
329+
330+
// Update bands Time OFF
331+
next_tx_delay = update_band_timeoff(params->joined,
332+
params->dc_enabled,
333+
band_table, phy_params.bands.size);
334+
335+
// Search how many channels are enabled
336+
channel_count = enabled_channel_count(params->current_datarate,
337+
phy_params.channels.mask,
338+
enabled_channels, &delay_tx);
339+
} else {
340+
delay_tx++;
341+
next_tx_delay = params->aggregate_timeoff -
342+
_lora_time->get_elapsed_time(params->last_aggregate_tx_time);
343+
}
344+
345+
if (channel_count > 0) {
346+
// We found a valid channel
347+
*channel = enabled_channels[get_random(0, channel_count - 1)];
348+
*time = 0;
349+
return LORAWAN_STATUS_OK;
350+
}
351+
352+
if (delay_tx > 0) {
353+
// Delay transmission due to AggregatedTimeOff or to a band time off
354+
*time = next_tx_delay;
355+
return LORAWAN_STATUS_DUTYCYCLE_RESTRICTED;
356+
}
357+
358+
*time = 0;
359+
return LORAWAN_STATUS_NO_CHANNEL_FOUND;
360+
}
361+
305362
bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
306363
{
307364
int8_t dr = config->datarate;
@@ -332,7 +389,8 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
332389
_radio->set_channel(frequency);
333390

334391
// Radio configuration
335-
_radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0, 8,
392+
_radio->set_rx_config(MODEM_LORA, config->bandwidth, phy_dr, 1, 0,
393+
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
336394
config->window_timeout, false, 0, false, 0, 0, true,
337395
config->is_rx_continuous);
338396

@@ -371,7 +429,8 @@ bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
371429

372430
_radio->set_channel(channels[config->channel].frequency);
373431

374-
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, 0, phy_dr, 1, 8, false, true,
432+
_radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, 0, phy_dr, 1,
433+
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH, false, true,
375434
0, 0, false, 3000);
376435
// Setup maximum payload lenght of the radio driver
377436
_radio->set_max_payload_length(MODEM_LORA, config->pkt_len);
@@ -421,12 +480,9 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
421480
if (adr_settings.ch_mask_ctrl == 6) {
422481

423482
// Enable all 125 kHz channels
424-
temp_channel_masks[0] = 0xFFFF;
425-
temp_channel_masks[1] = 0xFFFF;
426-
temp_channel_masks[2] = 0xFFFF;
427-
temp_channel_masks[3] = 0xFFFF;
428-
temp_channel_masks[4] = 0xFFFF;
429-
temp_channel_masks[5] = 0xFFFF;
483+
for (uint8_t i = 0; i < CN470_CHANNEL_MASK_SIZE; i++) {
484+
temp_channel_masks[i] = 0xFFFF;
485+
}
430486

431487
} else if( adr_settings.ch_mask_ctrl == 7 ) {
432488

features/lorawan/lorastack/phy/LoRaPHYCN470.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class LoRaPHYCN470 : public LoRaPHY {
5656
LoRaPHYCN470();
5757
virtual ~LoRaPHYCN470();
5858

59+
virtual lorawan_status_t set_next_channel(channel_selection_params_t *params,
60+
uint8_t *channel, lorawan_time_t *time,
61+
lorawan_time_t *aggregate_timeoff);
62+
5963
virtual bool rx_config(rx_config_params_t* config);
6064

6165
virtual bool tx_config(tx_config_params_t* config, int8_t* tx_power,

features/lorawan/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
"fsb-mask": {
8585
"help": "FSB mask for upstream [Only for US915 & AU915] Check lorawan/FSB_Usage.txt for more details",
8686
"value": "{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}"
87+
},
88+
"fsb-mask-china": {
89+
"help": "FSB mask for upstream [CN470 PHY] Check lorawan/FSB_Usage.txt for more details",
90+
"value": "{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}"
8791
}
8892
}
8993
}

0 commit comments

Comments
 (0)