@@ -233,9 +233,6 @@ void fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure)
233
233
234
234
static uint32_t fhss_get_number_of_tx_slots (fhss_structure_t * fhss_structure )
235
235
{
236
- if (!fhss_structure -> ws -> txrx_slot_length_ms ) {
237
- return 0 ;
238
- }
239
236
return ((fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval - fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval ) / fhss_structure -> ws -> txrx_slot_length_ms ) / 2 ;
240
237
}
241
238
@@ -367,40 +364,23 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
367
364
next_channel = fhss_structure -> rx_channel ;
368
365
/* Start timer with random timeout to trigger unicast TX queue poll event.
369
366
* For hops 0,1,4,5,8,9,...
370
- * In high traffic:
371
- * Min random is 1/1000 of the TX slot length.
372
- * Max random is 1/100 of the TX slot length.
373
- * Otherwise:
374
367
* Min random is 1/100 of the TX slot length.
375
368
* Max random is 1/5 of the TX slot length.
376
369
*
377
370
* For hops 2,3,6,7,10,11,...
378
- * Min random is 1/1000 of the TX slot length plus 0.5*TX slot length.
379
- * Max random is 1/100 of the TX slot length plus 0.5*TX slot length.
371
+ * Min random is 1/100 of the TX slot length plus 0.5*TX slot length.
372
+ * Max random is 1/10 of the TX slot length plus 0.5*TX slot length.
380
373
* Event timer resolution is 50us.
381
374
*/
375
+ // returns 1 if polling of TX queue is done on latter half of the TX slot
376
+ uint8_t own_tx_trig_slot = calc_own_tx_trig_slot (fhss_structure -> own_hop );
382
377
uint32_t txrx_slot_length_us = MS_TO_US (fhss_structure -> ws -> txrx_slot_length_ms );
383
- uint16_t queue_size = fhss_structure -> callbacks .read_tx_queue_size (fhss_structure -> fhss_api , false);
384
- uint16_t uc_min_random , uc_max_random ;
385
- uint32_t tx_slot_shift_us = (txrx_slot_length_us ) / 50 ;
386
- uint32_t half_tx_slot_shift_us = tx_slot_shift_us / 2 ;
387
- // For busy or latter half of the TX slot polling devices, use short random
388
- if (queue_size >= QUEUE_SIZE_HIGH || calc_own_tx_trig_slot (fhss_structure -> own_hop )) {
389
- uc_min_random = ((txrx_slot_length_us / 1000 ) / 50 );
390
- uc_max_random = ((txrx_slot_length_us / 100 ) / 50 );
391
- } else {
392
- uc_min_random = ((txrx_slot_length_us / 100 ) / 50 );
393
- uc_max_random = ((txrx_slot_length_us / 5 ) / 50 );
394
- }
395
- // Shift for latter half of the TX slot
396
- if (calc_own_tx_trig_slot (fhss_structure -> own_hop )) {
397
- uc_min_random += half_tx_slot_shift_us ;
398
- uc_max_random += half_tx_slot_shift_us ;
399
- }
400
- // Shift for own TX slot
401
- if (!fhss_ws_check_tx_allowed (fhss_structure )) {
402
- uc_min_random += tx_slot_shift_us ;
403
- uc_max_random += tx_slot_shift_us ;
378
+ uint16_t uc_min_random = (((txrx_slot_length_us / 2 ) * own_tx_trig_slot ) / 50 ) + ((txrx_slot_length_us / 100 ) / 50 );
379
+ uint16_t uc_max_random = (((txrx_slot_length_us / 2 ) * own_tx_trig_slot ) / 50 ) + ((txrx_slot_length_us / 5 ) / 50 );
380
+ bool tx_allowed = fhss_ws_check_tx_allowed (fhss_structure );
381
+ if (!tx_allowed ) {
382
+ uc_min_random += (txrx_slot_length_us ) / 50 ;
383
+ uc_max_random += (txrx_slot_length_us ) / 50 ;
404
384
}
405
385
eventOS_callback_timer_start (fhss_structure -> fhss_event_timer , randLIB_get_random_in_range (uc_min_random , uc_max_random ));
406
386
@@ -730,28 +710,26 @@ static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure)
730
710
731
711
static bool fhss_ws_check_tx_time (fhss_structure_t * fhss_structure , uint16_t tx_length , uint8_t phy_header_length , uint8_t phy_tail_length )
732
712
{
733
- bool retval = true;
734
- if (fhss_structure -> own_hop != 0xff && fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval && fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval && fhss_get_number_of_tx_slots (fhss_structure )) {
735
- uint32_t tx_time_ms = US_TO_MS (fhss_get_tx_time (fhss_structure , tx_length , phy_header_length , phy_tail_length ));
736
- // Check if there is enough time for transmitting before the next RX slot. Check only for devices which are polling TX queue in the beginning of TX slot.
737
- if (!calc_own_tx_trig_slot (fhss_structure -> own_hop )) {
738
- 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 ;
739
- 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 ));
740
- 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 ));
741
- uint32_t rx_slot_begin_ms = tx_slot_begin_ms - fhss_structure -> ws -> txrx_slot_length_ms ;
742
- if ((remaining_time_ms < rx_slot_begin_ms ) || ((remaining_time_ms - rx_slot_begin_ms ) < tx_time_ms )) {
743
- retval = false;
744
- }
745
- }
746
- // Check if there is enough time for transmitting before the next multicast slot.
713
+ /*
714
+ * Check if there is enough time for transmitting before the next multicast slot.
715
+ */
747
716
#ifdef FHSS_WS_PROTECT_MC_SLOTS
748
- uint32_t time_to_bc_channel_ms = US_TO_MS (get_remaining_slots_us (fhss_structure , fhss_broadcast_handler , MS_TO_US (fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval )));
749
- if (tx_time_ms > time_to_bc_channel_ms ) {
750
- retval = false;
751
- }
752
- #endif
717
+ if (!fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval || !fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval ) {
718
+ return true;
753
719
}
754
- return retval ;
720
+ uint32_t tx_time = fhss_get_tx_time (fhss_structure , tx_length , phy_header_length , phy_tail_length );
721
+ uint32_t time_to_bc_channel_us = get_remaining_slots_us (fhss_structure , fhss_broadcast_handler , MS_TO_US (fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval ));
722
+ if (tx_time > time_to_bc_channel_us ) {
723
+ return false;
724
+ }
725
+ return true;
726
+ #else
727
+ (void ) fhss_structure ;
728
+ (void ) tx_length ;
729
+ (void ) phy_header_length ;
730
+ (void ) phy_tail_length ;
731
+ return true;
732
+ #endif
755
733
}
756
734
757
735
static bool fhss_ws_check_tx_conditions_callback (const fhss_api_t * api , bool is_broadcast_addr , uint8_t handle , int frame_type , uint16_t frame_length , uint8_t phy_header_length , uint8_t phy_tail_length )
0 commit comments