Skip to content

Commit d6f4421

Browse files
AlbanJeantheau-silabsArto Kinnunen
authored andcommitted
Correct ufsi timing calculation
When calculating ufsi, the function was relying on the slot processed by the unicast fhss timer callback, which can be delayed. When it happens the slot value is wrong, and the ufsi is incorrect. The ufsi is then used by the peer to determined the reply channel, so the devices are thus unsynchronized until the next uplink packet.
1 parent 560619d commit d6f4421

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,35 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
499499
}
500500
}
501501
cur_slot--;
502-
uint32_t remaining_time_ms = 0;
503-
if (fhss_structure->ws->unicast_timer_running == true) {
504-
remaining_time_ms = US_TO_MS(get_remaining_slots_us(fhss_structure, fhss_unicast_handler, MS_TO_US(dwell_time) - NS_TO_US((int64_t)(fhss_structure->ws->drift_per_millisecond_ns * dwell_time))));
505-
}
502+
506503
uint32_t time_to_tx = 0;
507504
uint32_t cur_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api);
508505
if (cur_time < tx_time) {
509506
time_to_tx = US_TO_MS(tx_time - cur_time);
510507
}
511-
uint64_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time - remaining_time_ms) + time_to_tx;
508+
uint64_t ms_since_seq_start;
509+
if (fhss_structure->ws->unicast_timer_running == true) {
510+
if (fhss_structure->ws->next_uc_timeout < cur_time) {
511+
// The unicast timer has already expired, so count all previous slots
512+
// plus 1 completed slot
513+
// plus the time from timer expiration to now
514+
// plus the time until Tx
515+
ms_since_seq_start = ((cur_slot + 1) * dwell_time) + US_TO_MS(cur_time - fhss_structure->ws->next_uc_timeout) + time_to_tx;
516+
} else {
517+
// The unicast timer is still running, so count all previous slots
518+
// plus the remaining time in the slot
519+
// plus the time until Tx
520+
uint32_t remaining_time_ms = US_TO_MS(fhss_structure->ws->next_uc_timeout - cur_time);
521+
ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time - remaining_time_ms) + time_to_tx;
522+
}
523+
} else {
524+
// The unicast timer is not running. Act as if the slot has completed.
525+
// count all previous slots
526+
// plus 1 completed slot
527+
// plus the time until Tx
528+
ms_since_seq_start = ( (cur_slot + 1) * dwell_time) + time_to_tx;
529+
}
530+
512531
uint32_t seq_length = 0x10000;
513532
if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_TR51CF) {
514533
ms_since_seq_start %= (dwell_time * fhss_structure->number_of_uc_channels);

0 commit comments

Comments
 (0)