25
25
#include "fhss_ws.h"
26
26
#include "nsdynmemLIB.h"
27
27
#include "common_functions.h"
28
+ #include "eventOS_callback_timer.h"
29
+ #include "randLIB.h"
28
30
#include "ns_trace.h"
29
31
#include <string.h>
30
32
@@ -48,6 +50,7 @@ struct ws_ie_t {
48
50
49
51
static void fhss_ws_update_uc_channel_callback (fhss_structure_t * fhss_structure );
50
52
static void fhss_unicast_handler (const fhss_api_t * fhss_api , uint16_t delay );
53
+ static void fhss_ws_start_tx_poll_timer (fhss_structure_t * fhss_structure , uint16_t queue_size , uint8_t channel_dwell_interval );
51
54
52
55
fhss_structure_t * fhss_ws_enable (fhss_api_t * fhss_api , const fhss_ws_configuration_t * fhss_configuration , const fhss_timer_t * fhss_timer )
53
56
{
@@ -124,10 +127,8 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
124
127
#endif /*FHSS_CHANNEL_DEBUG*/
125
128
}
126
129
fhss_structure -> callbacks .change_channel (fhss_structure -> fhss_api , next_channel );
127
- if (fhss_structure -> callbacks .read_tx_queue_size (fhss_structure -> fhss_api , true)) {
128
- // TODO: Randomize polling TX queue when on broadcast channel
129
- fhss_structure -> callbacks .tx_poll (fhss_structure -> fhss_api );
130
- }
130
+ fhss_ws_start_tx_poll_timer (fhss_structure , fhss_structure -> callbacks .read_tx_queue_size (fhss_structure -> fhss_api , true),
131
+ fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval );
131
132
}
132
133
133
134
static int own_floor (float value )
@@ -454,9 +455,24 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay)
454
455
timeout = fhss_ws_get_sf_timeout_callback (fhss_structure );
455
456
fhss_start_timer (fhss_structure , timeout - (delay * fhss_structure -> platform_functions .fhss_resolution_divider ), fhss_unicast_handler );
456
457
fhss_ws_update_uc_channel_callback (fhss_structure );
457
- if (fhss_structure -> callbacks .read_tx_queue_size (fhss_structure -> fhss_api , false)) {
458
- fhss_structure -> callbacks .tx_poll (fhss_structure -> fhss_api );
458
+ fhss_ws_start_tx_poll_timer (fhss_structure , fhss_structure -> callbacks .read_tx_queue_size (fhss_structure -> fhss_api , false),
459
+ fhss_structure -> ws -> fhss_configuration .fhss_uc_dwell_interval );
460
+ }
461
+
462
+ static void fhss_ws_start_tx_poll_timer (fhss_structure_t * fhss_structure , uint16_t queue_size , uint8_t channel_dwell_interval )
463
+ {
464
+ if (!queue_size ) {
465
+ return ;
459
466
}
467
+ /* Start timer with random timeout to trigger TX queue poll event.
468
+ * Min random is 1/50 of the channel dwell interval.
469
+ * Max random is 1/10 of the channel dwell interval.
470
+ * Event timer resolution is 50us.
471
+ * Divide random with TX queue size to transmit faster when TX queue is growing
472
+ */
473
+ uint16_t min_random = ((((uint32_t )channel_dwell_interval * 1000 ) / 50 ) / 50 ) / queue_size ;
474
+ uint16_t max_random = ((((uint32_t )channel_dwell_interval * 1000 ) / 10 ) / 50 ) / queue_size ;
475
+ eventOS_callback_timer_start (fhss_structure -> fhss_event_timer , randLIB_get_random_in_range (min_random , max_random ));
460
476
}
461
477
462
478
int fhss_ws_set_callbacks (fhss_structure_t * fhss_structure )
0 commit comments