@@ -308,6 +308,10 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
308
308
} else {
309
309
// On unicast, start timer to trigger polling event on next TX slot
310
310
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
+ }
311
315
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 ))) {
312
316
eventOS_callback_timer_start (fhss_structure -> fhss_event_timer , delay_between_tx_slots_us / 50 );
313
317
}
@@ -529,16 +533,12 @@ static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure)
529
533
}
530
534
531
535
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;
542
542
}
543
543
544
544
return false;
0 commit comments