Skip to content

Commit e1e48b4

Browse files
author
Hasnain Virk
committed
Final cleanup and ASCII art for algorithm v2
Final code cleanup and adding ascii art for the version 2 of the algorithm.
1 parent 5170daa commit e1e48b4

File tree

4 files changed

+64
-44
lines changed

4 files changed

+64
-44
lines changed

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ SPDX-License-Identifier: BSD-3-Clause
3232
#define BACKOFF_DC_1_HOUR 100
3333
#define BACKOFF_DC_10_HOURS 1000
3434
#define BACKOFF_DC_24_HOURS 10000
35-
#define MAX_PREAMBLE_LENGTH 8.0
36-
#define TICK_GRANULARITY_JITTER 1.0
35+
#define MAX_PREAMBLE_LENGTH 8.0f
36+
#define TICK_GRANULARITY_JITTER 1.0f
3737
#define CHANNELS_IN_MASK 16
3838

3939
LoRaPHY::LoRaPHY()
@@ -397,7 +397,7 @@ float LoRaPHY::compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth)
397397

398398
float LoRaPHY::compute_symb_timeout_fsk(uint8_t phy_dr)
399399
{
400-
return (8.0 / (float) phy_dr); // 1 symbol equals 1 byte
400+
return (8.0f / (float) phy_dr); // 1 symbol equals 1 byte
401401
}
402402

403403

@@ -420,11 +420,11 @@ void LoRaPHY::get_rx_window_params(float t_symb, uint8_t min_rx_symb,
420420

421421
// Actual window offset in ms in response to timing error fudge factor and
422422
// radio wakeup/turned around time.
423-
*window_offset = floor(target_rx_window_offset - error_fudge - MBED_CONF_LORA_WAKEUP_TIME);
423+
*window_offset = floor(target_rx_window_offset - error_fudge - wakeup_time);
424424

425425
// possible wait for next symbol start if we start inside the preamble
426426
float possible_wait_for_symb_start = MIN(t_symb,
427-
((2 * error_fudge) + MBED_CONF_LORA_WAKEUP_TIME + TICK_GRANULARITY_JITTER));
427+
((2 * error_fudge) + wakeup_time + TICK_GRANULARITY_JITTER));
428428

429429
// how early we might start reception relative to transmit start (so negative if before transmit starts)
430430
float earliest_possible_start_time = *window_offset - error_fudge - TICK_GRANULARITY_JITTER;
@@ -845,7 +845,7 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
845845
rx_conf_params->frequency = phy_params.channels.channel_list[rx_conf_params->channel].frequency;
846846
}
847847

848-
get_rx_window_params(t_symbol, min_rx_symbols, (float) rx_error, RADIO_WAKEUP_TIME,
848+
get_rx_window_params(t_symbol, min_rx_symbols, (float) rx_error, MBED_CONF_LORA_WAKEUP_TIME,
849849
&rx_conf_params->window_timeout, &rx_conf_params->window_offset,
850850
rx_conf_params->datarate);
851851
}

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -202,40 +202,63 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
202202

203203
/** Computing Receive Windows
204204
*
205-
* For more details please consult the following document, chapter 3.1.2.
206-
* http://www.semtech.com/images/datasheet/SX1272_settings_for_LoRaWAN_v2.0.pdf
207-
* or
208-
* http://www.semtech.com/images/datasheet/SX1276_settings_for_LoRaWAN_v2.0.pdf
209-
*
210-
* Downlink start: T = Tx + 1s (+/- 20 us)
211-
* |
212-
* TRxEarly | TRxLate
213-
* | | |
214-
* | | +---+---+---+---+---+---+---+---+
215-
* | | | Latest Rx window |
216-
* | | +---+---+---+---+---+---+---+---+
217-
* | | |
205+
* The algorithm tries to calculate the length of receive windows (i.e.,
206+
* the minimum time it should remain to acquire a lock on the Preamble
207+
* for synchronization) and the error offset which compensates for the system
208+
* timing errors. Basic idea behind the algorithm is to optimize for the
209+
* reception of last 'min_rx_symbols' symbols out of transmitted Premable
210+
* symbols. The algorithm compensates for the clock drifts, tick granularity
211+
* and system wake up time (from sleep state) by opening the window early for
212+
* the lower SFs. For higher SFs, the symbol time is large enough that we can
213+
* afford to open late (hence the positive offset).
214+
* The table below shows the calculated values for SF7 to SF12 with 125 kHz
215+
* bandwidth.
216+
*
217+
* +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
218+
* | SF | BW (kHz) | rx_error (ms) | wake_up (ms) | min_rx_symbols | window_timeout(symb) | window_offset(ms) |
219+
* +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
220+
* | 7 | 125 | 5 | 5 | 5 | 18 | -7 |
221+
* | 8 | 125 | 5 | 5 | 5 | 10 | -4 |
222+
* | 9 | 125 | 5 | 5 | 5 | 6 | 2 |
223+
* | 10 | 125 | 5 | 5 | 5 | 6 | 14 |
224+
* | 11 | 125 | 5 | 5 | 5 | 6 | 39 |
225+
* | 12 | 125 | 5 | 5 | 5 | 6 | 88 |
226+
* +----+-----+----------+---------+-------------------------+----------------------+-------------------------+
227+
*
228+
* For example for SF7, the receive window will open at downlink start time
229+
* plus the offset calculated and will remain open for the length window_timeout.
230+
*
231+
* Symbol time = 1.024 ms
232+
* Downlink start: T = Tx + 1s (+/- 20 us)
233+
* |
234+
* |
235+
* |
236+
* |
237+
* |
238+
* +---+---+---+---+---+---+---+---+
239+
* | 8 Preamble Symbols |
240+
* +---+---+---+---+---+---+---+---+
241+
* | RX Window start time = T +/- Offset
242+
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
243+
* | | | | | | | | | | | | | | | | | | |
244+
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
245+
*
246+
* Similarly for SF12:
247+
*
248+
* Symbol time = 32.768 ms
249+
* Downlink start: T = Tx + 1s (+/- 20 us)
250+
* |
251+
* |
252+
* |
253+
* |
254+
* |
218255
* +---+---+---+---+---+---+---+---+
219-
* | Earliest Rx window |
256+
* | 8 Preamble Symbols |
220257
* +---+---+---+---+---+---+---+---+
221-
* |
222-
* +---+---+---+---+---+---+---+---+
223-
*Downlink preamble 8 symbols | | | | | | | | |
224-
* +---+---+---+---+---+---+---+---+
225-
*
226-
* Worst case Rx window timings
227-
*
228-
* TRxLate = DEFAULT_MIN_RX_SYMBOLS * tSymbol - RADIO_WAKEUP_TIME
229-
* TRxEarly = 8 - DEFAULT_MIN_RX_SYMBOLS * tSymbol - RxWindowTimeout - RADIO_WAKEUP_TIME
230-
*
231-
* TRxLate - TRxEarly = 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
232-
*
233-
* RxOffset = ( TRxLate + TRxEarly ) / 2
234-
*
235-
* RxWindowTimeout = ( 2 * DEFAULT_MIN_RX_SYMBOLS - 8 ) * tSymbol + 2 * DEFAULT_SYSTEM_MAX_RX_ERROR
236-
* RxOffset = 4 * tSymbol - RxWindowTimeout / 2 - RADIO_WAKE_UP_TIME
237-
*
238-
* The minimum value of RxWindowTimeout must be 5 symbols which implies that the system always tolerates at least an error of 1.5 * tSymbol.
258+
* | RX Window start time = T +/- Offset
259+
* +---+---+---+---+---+---+
260+
* | | | | | | |
261+
* +---+---+---+---+---+---+
239262
*/
240263
/*!
241264
* Computes the RX window timeout and offset.

features/lorawan/mbed_lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"value": 5
7979
},
8080
"downlink-preamble-length": {
81-
"help": "Number of whole preamble symbols needed to have a firm lock on the signal. Default: 5 + 1",
81+
"help": "Number of whole preamble symbols needed to have a firm lock on the signal.",
8282
"value": 5
8383
},
8484
"uplink-preamble-length": {

features/lorawan/system/lorawan_data_structures.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
typedef uint32_t lorawan_time_t;
4545
#endif
4646

47-
// Radio wake-up time from sleep - unit ms.
48-
#define RADIO_WAKEUP_TIME 1.0
49-
5047
/*!
5148
* Sets the length of the LoRaMAC footer field.
5249
* Mainly indicates the MIC field length.
@@ -1259,8 +1256,8 @@ typedef struct {
12591256

12601257
/*!
12611258
* LoRaMac reception windows delay
1262-
* \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
1263-
* join frame : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
1259+
* \remark normal frame: RxWindowXDelay = ReceiveDelayX - Offset
1260+
* join frame : RxWindowXDelay = JoinAcceptDelayX - Offset
12641261
*/
12651262
uint32_t rx_window1_delay;
12661263
uint32_t rx_window2_delay;

0 commit comments

Comments
 (0)