@@ -32,8 +32,9 @@ SPDX-License-Identifier: BSD-3-Clause
32
32
#define BACKOFF_DC_1_HOUR 100
33
33
#define BACKOFF_DC_10_HOURS 1000
34
34
#define BACKOFF_DC_24_HOURS 10000
35
-
36
- #define CHANNELS_IN_MASK 16
35
+ #define MAX_PREAMBLE_LENGTH 8.0
36
+ #define TICK_GRANULARITY_JITTER 1.0
37
+ #define CHANNELS_IN_MASK 16
37
38
38
39
LoRaPHY::LoRaPHY ()
39
40
: _radio(NULL ),
@@ -388,23 +389,49 @@ uint8_t LoRaPHY::verify_link_ADR_req(verify_adr_params_t *verify_params,
388
389
return status;
389
390
}
390
391
391
- double LoRaPHY::compute_symb_timeout_lora (uint8_t phy_dr, uint32_t bandwidth)
392
+ float LoRaPHY::compute_symb_timeout_lora (uint8_t phy_dr, uint32_t bandwidth)
392
393
{
393
- return ((double )(1 << phy_dr) / (double ) bandwidth) * 1000 ;
394
+ // in milliseconds
395
+ return ((float )(1 << phy_dr) / (float ) bandwidth * 1000 );
394
396
}
395
397
396
- double LoRaPHY::compute_symb_timeout_fsk (uint8_t phy_dr)
398
+ float LoRaPHY::compute_symb_timeout_fsk (uint8_t phy_dr)
397
399
{
398
- return (8.0 / (double ) phy_dr); // 1 symbol equals 1 byte
400
+ return (8.0 / (float ) phy_dr); // 1 symbol equals 1 byte
399
401
}
400
402
401
- void LoRaPHY::get_rx_window_params (double t_symb, uint8_t min_rx_symb,
402
- uint32_t rx_error, uint32_t wakeup_time,
403
- uint32_t *window_timeout, int32_t *window_offset)
403
+
404
+ void LoRaPHY::get_rx_window_params (float t_symb, uint8_t min_rx_symb,
405
+ float error_fudge, float wakeup_time,
406
+ uint32_t *window_length, int32_t *window_offset,
407
+ uint8_t phy_dr)
404
408
{
405
- // Computed number of symbols
406
- *window_timeout = MAX ((uint32_t ) ceil (((2 * min_rx_symb - 8 ) * t_symb + 2 * rx_error) / t_symb), min_rx_symb);
407
- *window_offset = (int32_t ) ceil ((4.0 * t_symb) - ((*window_timeout * t_symb) / 2.0 ) - wakeup_time);
409
+ float min_rx_symbol_overlap_required = float (min_rx_symb);
410
+ float target_rx_window_offset;
411
+ float window_len_in_ms;
412
+
413
+ if (phy_params.fsk_supported && phy_dr == phy_params.max_rx_datarate ) {
414
+ min_rx_symbol_overlap_required = MAX_PREAMBLE_LENGTH;
415
+ }
416
+
417
+ // We wish to be as close as possible to the actual start of data, i.e.,
418
+ // we are interested in the preamble symbols which are at the tail of the
419
+ // preamble sequence.
420
+ target_rx_window_offset = (MAX_PREAMBLE_LENGTH - min_rx_symbol_overlap_required) * t_symb; // in ms
421
+
422
+ // Actual window offset in ms in response to timing error fudge factor and
423
+ // radio wakeup/turned around time.
424
+ *window_offset = floor (target_rx_window_offset - error_fudge - wakeup_time);
425
+
426
+ // Minimum reception time plus extra time (in ms) we may have turned on before the
427
+ // other side started transmission
428
+ window_len_in_ms = (min_rx_symbol_overlap_required * t_symb) - MIN (0 , (*window_offset - error_fudge - TICK_GRANULARITY_JITTER));
429
+
430
+ // Setting the window_length in terms of 'symbols' for LoRa modulation or
431
+ // in terms of 'bytes' for FSK
432
+ *window_length = (uint32_t ) ceil (window_len_in_ms / t_symb);
433
+
434
+
408
435
}
409
436
410
437
int8_t LoRaPHY::compute_tx_power (int8_t tx_power_idx, float max_eirp,
@@ -791,7 +818,7 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
791
818
uint32_t rx_error,
792
819
rx_config_params_t *rx_conf_params)
793
820
{
794
- double t_symbol = 0.0 ;
821
+ float t_symbol = 0.0 ;
795
822
796
823
// Get the datarate, perform a boundary check
797
824
rx_conf_params->datarate = MIN (datarate, phy_params.max_rx_datarate );
@@ -811,9 +838,9 @@ void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
811
838
rx_conf_params->frequency = phy_params.channels .channel_list [rx_conf_params->channel ].frequency ;
812
839
}
813
840
814
-
815
- get_rx_window_params (t_symbol, min_rx_symbols, rx_error, RADIO_WAKEUP_TIME ,
816
- & rx_conf_params->window_timeout , &rx_conf_params-> window_offset );
841
+ get_rx_window_params (t_symbol, min_rx_symbols, ( float ) rx_error, RADIO_WAKEUP_TIME,
842
+ &rx_conf_params-> window_timeout , &rx_conf_params-> window_offset ,
843
+ rx_conf_params->datarate );
817
844
}
818
845
819
846
bool LoRaPHY::rx_config (rx_config_params_t *rx_conf)
0 commit comments