@@ -64,6 +64,12 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay);
64
64
static bool fhss_ws_check_tx_allowed (fhss_structure_t * fhss_structure );
65
65
static uint8_t fhss_set_txrx_slot_length (fhss_structure_t * fhss_structure );
66
66
67
+ // This function supports rounding up
68
+ static uint32_t divide_integer (uint32_t dividend , uint32_t divisor )
69
+ {
70
+ return (dividend + divisor /2 ) / divisor ;
71
+ }
72
+
67
73
fhss_structure_t * fhss_ws_enable (fhss_api_t * fhss_api , const fhss_ws_configuration_t * fhss_configuration , const fhss_timer_t * fhss_timer )
68
74
{
69
75
if (!fhss_api || !fhss_configuration || !fhss_timer ) {
@@ -164,12 +170,12 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
164
170
// Should return to own (unicast) listening channel after broadcast channel
165
171
next_channel = fhss_structure -> rx_channel ;
166
172
/* Start timer with random timeout to trigger unicast TX queue poll event.
167
- * Min random is 50us .
173
+ * Min random is 1/30 of the TX slot length .
168
174
* Max random is 1/10 of the TX slot length.
169
175
* Event timer resolution is 50us.
170
176
*/
171
177
uint32_t txrx_slot_length_us = fhss_structure -> ws -> txrx_slot_length_ms * 1000 ;
172
- uint16_t uc_min_random = 1 ;
178
+ uint16_t uc_min_random = ( txrx_slot_length_us / 30 ) / 50 ;
173
179
uint16_t uc_max_random = (txrx_slot_length_us / 10 ) / 50 ;
174
180
bool tx_allowed = fhss_ws_check_tx_allowed (fhss_structure );
175
181
if (!tx_allowed ) {
@@ -254,14 +260,14 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh
254
260
uint8_t dwell_time = fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval ;
255
261
uint32_t broadcast_interval = fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval ;
256
262
257
- uint32_t remaining_time = (fhss_structure -> platform_functions .fhss_get_remaining_slots (fhss_broadcast_handler , fhss_structure -> fhss_api ) / 1000 );
263
+ uint32_t remaining_time = divide_integer (fhss_structure -> platform_functions .fhss_get_remaining_slots (fhss_broadcast_handler , fhss_structure -> fhss_api ), 1000 );
258
264
if (fhss_structure -> ws -> is_on_bc_channel == true) {
259
265
remaining_time += (broadcast_interval - dwell_time );
260
266
}
261
267
uint32_t time_to_tx = 0 ;
262
268
uint32_t cur_time = fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api );
263
269
if (cur_time < tx_time ) {
264
- time_to_tx = (tx_time - cur_time ) / 1000 ;
270
+ time_to_tx = divide_integer (tx_time - cur_time , 1000 ) ;
265
271
}
266
272
return (broadcast_interval - remaining_time ) + time_to_tx ;
267
273
}
@@ -360,9 +366,17 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
360
366
if (!fhss_structure ) {
361
367
return -1 ;
362
368
}
363
- if (is_broadcast_addr || ( fhss_structure -> ws -> is_on_bc_channel == true) ) {
369
+ if (is_broadcast_addr ) {
364
370
return 0 ;
365
371
}
372
+ // Do not allow unicast destination on broadcast channel
373
+ if (!is_broadcast_addr && (fhss_structure -> ws -> is_on_bc_channel == true)) {
374
+ return -1 ;
375
+ }
376
+ // Check TX/RX slot
377
+ if (!fhss_ws_check_tx_allowed (fhss_structure )) {
378
+ return -1 ;
379
+ }
366
380
if (fhss_structure -> fhss_state == FHSS_SYNCHRONIZED ) {
367
381
fhss_ws_neighbor_timing_info_t * neighbor_timing_info = fhss_structure -> ws -> get_neighbor_info (api , destination_address );
368
382
if (!neighbor_timing_info ) {
@@ -673,7 +687,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
673
687
fhss_structure -> ws -> synchronization_time = fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api );
674
688
platform_enter_critical ();
675
689
fhss_stop_timer (fhss_structure , fhss_broadcast_handler );
676
- uint32_t time_from_reception_ms = (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp )/ 1000 ;
690
+ uint32_t time_from_reception_ms = divide_integer (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp , 1000 ) ;
677
691
uint32_t true_bc_interval_offset = (bc_timing_info -> broadcast_interval_offset + time_from_reception_ms ) % bc_timing_info -> broadcast_interval ;
678
692
uint32_t timeout = ((bc_timing_info -> broadcast_interval - true_bc_interval_offset )* 1000 );
679
693
0 commit comments