@@ -302,6 +302,7 @@ static int16_t fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_stat
302302 if ((fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function != WS_FIXED_CHANNEL )) {
303303 fhss_ws_update_uc_channel_callback (fhss_structure );
304304 fhss_start_timer (fhss_structure , fhss_structure -> ws -> fhss_configuration .fhss_uc_dwell_interval * 1000 , fhss_unicast_handler );
305+ fhss_structure -> ws -> unicast_timer_running = true;
305306 }
306307 }
307308
@@ -622,7 +623,13 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay)
622623 return ;
623624 }
624625 timeout = fhss_ws_get_sf_timeout_callback (fhss_structure );
626+ if (!timeout ) {
627+ fhss_stop_timer (fhss_structure , fhss_unicast_handler );
628+ fhss_structure -> ws -> unicast_timer_running = false;
629+ return ;
630+ }
625631 fhss_start_timer (fhss_structure , timeout - (delay * fhss_structure -> platform_functions .fhss_resolution_divider ), fhss_unicast_handler );
632+ fhss_structure -> ws -> unicast_timer_running = true;
626633 fhss_ws_update_uc_channel_callback (fhss_structure );
627634 // Unless we have broadcast schedule, we have to poll unicast queue when changing channel. This is randomized by the unicast schedule.
628635 if (!fhss_structure -> ws -> fhss_configuration .fhss_broadcast_interval || !fhss_structure -> ws -> fhss_configuration .fhss_bc_dwell_interval ) {
@@ -660,7 +667,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
660667 return -1 ;
661668 }
662669 platform_enter_critical ();
663- fhss_structure -> platform_functions . fhss_timer_stop ( fhss_broadcast_handler , fhss_structure -> fhss_api );
670+ fhss_stop_timer ( fhss_structure , fhss_broadcast_handler );
664671 uint32_t time_from_reception_ms = (fhss_structure -> callbacks .read_timestamp (fhss_structure -> fhss_api ) - bc_timing_info -> bt_rx_timestamp )/1000 ;
665672 uint32_t true_bc_interval_offset = (bc_timing_info -> broadcast_interval_offset + time_from_reception_ms ) % bc_timing_info -> broadcast_interval ;
666673 uint32_t timeout = ((bc_timing_info -> broadcast_interval - true_bc_interval_offset )* 1000 );
@@ -697,9 +704,13 @@ int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_co
697704 if (channel_count <= 0 ) {
698705 return -1 ;
699706 }
700- if ((fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function == WS_FIXED_CHANNEL ) && (fhss_configuration -> ws_uc_channel_function != WS_FIXED_CHANNEL )) {
701- // Start unicast schedule if channel function changed from fixed channel
707+ if (fhss_configuration -> ws_uc_channel_function == WS_FIXED_CHANNEL || fhss_configuration -> fhss_uc_dwell_interval == 0 ) {
708+ fhss_stop_timer (fhss_structure , fhss_unicast_handler );
709+ fhss_structure -> ws -> unicast_timer_running = false;
710+ }
711+ if ((fhss_structure -> ws -> unicast_timer_running == false) && (fhss_configuration -> ws_uc_channel_function != WS_FIXED_CHANNEL ) && fhss_configuration -> fhss_uc_dwell_interval ) {
702712 fhss_start_timer (fhss_structure , fhss_configuration -> fhss_uc_dwell_interval * 1000 , fhss_unicast_handler );
713+ fhss_structure -> ws -> unicast_timer_running = true;
703714 }
704715 fhss_structure -> ws -> fhss_configuration = * fhss_configuration ;
705716 fhss_structure -> number_of_channels = channel_count ;
0 commit comments