Skip to content

Commit 8c0b6db

Browse files
author
Jarkko Paso
committed
FHSS WS: Fixed drifting TX trig timer
1 parent e32d3c1 commit 8c0b6db

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
308308
} else {
309309
// On unicast, start timer to trigger polling event on next TX slot
310310
uint32_t delay_between_tx_slots_us = MS_TO_US(fhss_structure->ws->txrx_slot_length_ms) * 2;
311+
// Timer could drift to RX slot when broadcast interval is high. Return timer to TX slot.
312+
if (fhss_ws_check_tx_allowed(fhss_structure) == false) {
313+
delay_between_tx_slots_us -= MS_TO_US(fhss_structure->ws->txrx_slot_length_ms - (calc_own_tx_trig_slot(fhss_structure->own_hop) * (fhss_structure->ws->txrx_slot_length_ms / 2)));
314+
}
311315
if (delay_between_tx_slots_us < get_remaining_slots_us(fhss_structure, fhss_broadcast_handler, MS_TO_US(fhss_structure->ws->fhss_configuration.fhss_broadcast_interval))) {
312316
eventOS_callback_timer_start(fhss_structure->fhss_event_timer, delay_between_tx_slots_us / 50);
313317
}
@@ -529,16 +533,12 @@ static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure)
529533
}
530534

531535
uint32_t remaining_time_ms = get_remaining_slots_us(fhss_structure, fhss_broadcast_handler, MS_TO_US(fhss_structure->ws->fhss_configuration.fhss_broadcast_interval)) / 1000;
532-
uint32_t tx_slot_begin = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) - (fhss_structure->ws->txrx_slot_length_ms * (fhss_structure->own_hop & 1));
533-
uint32_t rx_slot_begin = tx_slot_begin - fhss_structure->ws->txrx_slot_length_ms;
534-
uint32_t n_o_tx_slots = number_of_tx_slots;
535-
536-
while (n_o_tx_slots--) {
537-
if ((remaining_time_ms <= tx_slot_begin) && (remaining_time_ms > rx_slot_begin)) {
538-
return true;
539-
}
540-
tx_slot_begin -= (2 * fhss_structure->ws->txrx_slot_length_ms);
541-
rx_slot_begin = tx_slot_begin - fhss_structure->ws->txrx_slot_length_ms;
536+
uint32_t tx_slot_begin_ms = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) - (fhss_structure->ws->txrx_slot_length_ms * (fhss_structure->own_hop & 1));
537+
tx_slot_begin_ms = tx_slot_begin_ms - (((tx_slot_begin_ms - remaining_time_ms) / (2 * fhss_structure->ws->txrx_slot_length_ms)) * (2 * fhss_structure->ws->txrx_slot_length_ms));
538+
uint32_t rx_slot_begin_ms = tx_slot_begin_ms - fhss_structure->ws->txrx_slot_length_ms;
539+
// Check if we are currently on TX slot.
540+
if ((remaining_time_ms <= tx_slot_begin_ms) && (remaining_time_ms > rx_slot_begin_ms)) {
541+
return true;
542542
}
543543

544544
return false;

0 commit comments

Comments
 (0)