Skip to content

Commit

Permalink
FHSS: Stop unicast schedule when fixed channel or no dwell interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 20, 2018
1 parent 62ffba3 commit 3d1c8a0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions source/Service_Libs/fhss/fhss_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ void fhss_start_timer(fhss_structure_t *fhss_structure, uint32_t time, void (*ca
}
}

void fhss_stop_timer(fhss_structure_t *fhss_structure, void (*callback)(const fhss_api_t *fhss_api, uint16_t))
{
if (callback){
fhss_structure->platform_functions.fhss_timer_stop(callback, fhss_structure->fhss_api);
}
}

int fhss_timeout_start(fhss_structure_t *fhss_structure, uint32_t time)
{
if (!fhss_structure) {
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api);
void fhss_clear_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
int8_t fhss_disable(fhss_structure_t *fhss_structure);
void fhss_start_timer(fhss_structure_t *fhss_structure, uint32_t time, void (*callback)(const fhss_api_t *fhss_api, uint16_t));
void fhss_stop_timer(fhss_structure_t *fhss_structure, void (*callback)(const fhss_api_t *fhss_api, uint16_t));
int fhss_timeout_start(fhss_structure_t *fhss_structure, uint32_t time);
int fhss_timeout_stop(fhss_structure_t *fhss_structure);
int fhss_update_synch_parent_address(fhss_structure_t *fhss_structure);
Expand Down
17 changes: 14 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ static int16_t fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_stat
if ((fhss_structure->ws->fhss_configuration.ws_uc_channel_function != WS_FIXED_CHANNEL)) {
fhss_ws_update_uc_channel_callback(fhss_structure);
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval*1000, fhss_unicast_handler);
fhss_structure->ws->unicast_timer_running = true;
}
}

Expand Down Expand Up @@ -622,7 +623,13 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay)
return;
}
timeout = fhss_ws_get_sf_timeout_callback(fhss_structure);
if (!timeout) {
fhss_stop_timer(fhss_structure, fhss_unicast_handler);
fhss_structure->ws->unicast_timer_running = false;
return;
}
fhss_start_timer(fhss_structure, timeout - (delay * fhss_structure->platform_functions.fhss_resolution_divider), fhss_unicast_handler);
fhss_structure->ws->unicast_timer_running = true;
fhss_ws_update_uc_channel_callback(fhss_structure);
// Unless we have broadcast schedule, we have to poll unicast queue when changing channel. This is randomized by the unicast schedule.
if (!fhss_structure->ws->fhss_configuration.fhss_broadcast_interval || !fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) {
Expand Down Expand Up @@ -660,7 +667,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
return -1;
}
platform_enter_critical();
fhss_structure->platform_functions.fhss_timer_stop(fhss_broadcast_handler, fhss_structure->fhss_api);
fhss_stop_timer(fhss_structure, fhss_broadcast_handler);
uint32_t time_from_reception_ms = (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000;
uint32_t true_bc_interval_offset = (bc_timing_info->broadcast_interval_offset + time_from_reception_ms) % bc_timing_info->broadcast_interval;
uint32_t timeout = ((bc_timing_info->broadcast_interval-true_bc_interval_offset)*1000);
Expand Down Expand Up @@ -697,9 +704,13 @@ int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_co
if (channel_count <= 0) {
return -1;
}
if ((fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_FIXED_CHANNEL) && (fhss_configuration->ws_uc_channel_function != WS_FIXED_CHANNEL)) {
// Start unicast schedule if channel function changed from fixed channel
if (fhss_configuration->ws_uc_channel_function == WS_FIXED_CHANNEL || fhss_configuration->fhss_uc_dwell_interval == 0) {
fhss_stop_timer(fhss_structure, fhss_unicast_handler);
fhss_structure->ws->unicast_timer_running = false;
}
if ((fhss_structure->ws->unicast_timer_running == false) && (fhss_configuration->ws_uc_channel_function != WS_FIXED_CHANNEL) && fhss_configuration->fhss_uc_dwell_interval) {
fhss_start_timer(fhss_structure, fhss_configuration->fhss_uc_dwell_interval*1000, fhss_unicast_handler);
fhss_structure->ws->unicast_timer_running = true;
}
fhss_structure->ws->fhss_configuration = *fhss_configuration;
fhss_structure->number_of_channels = channel_count;
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct fhss_ws
uint16_t uc_slot;
uint16_t bc_slot;
uint32_t txrx_slot_length_ms;
bool unicast_timer_running;
bool is_on_bc_channel;
struct fhss_ws_configuration fhss_configuration;
const struct broadcast_timing_info *parent_bc_info;
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/fhss_common_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ void fhss_start_timer(fhss_structure_t *fhss_structure, uint32_t time, void (*ca
}
}

void fhss_stop_timer(fhss_structure_t *fhss_structure, void (*callback)(const fhss_api_t *fhss_api, uint16_t))
{

}

int fhss_timeout_start(fhss_structure_t *fhss_structure, uint32_t time)
{
return 0;
Expand Down

0 comments on commit 3d1c8a0

Please sign in to comment.