@@ -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 ) {
@@ -253,14 +259,14 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh
253
259
uint8_t dwell_time = fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval ;
254
260
uint32_t broadcast_interval = fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval ;
255
261
256
- uint32_t remaining_time = (fhss_structure -> platform_functions .fhss_get_remaining_slots (fhss_broadcast_handler , fhss_structure -> fhss_api ) / 1000 );
262
+ uint32_t remaining_time = divide_integer (fhss_structure -> platform_functions .fhss_get_remaining_slots (fhss_broadcast_handler , fhss_structure -> fhss_api ), 1000 );
257
263
if (fhss_structure -> ws -> is_on_bc_channel == true) {
258
264
remaining_time += (broadcast_interval - dwell_time );
259
265
}
260
266
uint32_t time_to_tx = 0 ;
261
267
uint32_t cur_time = fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api );
262
268
if (cur_time < tx_time ) {
263
- time_to_tx = (tx_time - cur_time ) / 1000 ;
269
+ time_to_tx = divide_integer (tx_time - cur_time , 1000 ) ;
264
270
}
265
271
return (broadcast_interval - remaining_time ) + time_to_tx ;
266
272
}
@@ -668,7 +674,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
668
674
}
669
675
platform_enter_critical ();
670
676
fhss_stop_timer (fhss_structure , fhss_broadcast_handler );
671
- uint32_t time_from_reception_ms = (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp )/ 1000 ;
677
+ uint32_t time_from_reception_ms = divide_integer (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp , 1000 ) ;
672
678
uint32_t true_bc_interval_offset = (bc_timing_info -> broadcast_interval_offset + time_from_reception_ms ) % bc_timing_info -> broadcast_interval ;
673
679
uint32_t timeout = ((bc_timing_info -> broadcast_interval - true_bc_interval_offset )* 1000 );
674
680
0 commit comments