Skip to content

Commit

Permalink
FHSS: Moved FHSS reset and down to FHSS module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Feb 7, 2018
1 parent 4719187 commit 2cbe6dc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 62 deletions.
50 changes: 36 additions & 14 deletions source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#define TRACE_GROUP "fhss"

static int fhss_reset(fhss_structure_t *fhss_structure);
static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure);
static bool fhss_is_bc_sending_superframe(fhss_structure_t *fhss_structure);
static bool fhss_check_remaining_tx_time(fhss_structure_t *fhss_structure, uint16_t tx_length, uint8_t phy_header_length, uint8_t phy_tail_length);
Expand Down Expand Up @@ -68,19 +69,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
}
ns_list_init(&fhss_struct->fhss_failed_tx_list);
fhss_struct->own_hop = 0xff;
fhss_destroy_scramble_table(fhss_struct);
fhss_struct->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_struct->fhss_api);
fhss_struct->synch_panid = 0xffff;
fhss_beacon_periodic_stop(fhss_struct);
if (fhss_is_synch_root(fhss_struct) == false) {
fhss_struct->own_hop = 0xff;
}
fhss_struct->tx_allowed = false;
fhss_struct->synch_interval = (uint32_t) (fhss_struct->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
memset(fhss_struct->synch_parent, 0xff, 8);
fhss_struct->send_synch_info_on_next_broadcast_channel = false;
fhss_failed_list_free(fhss_struct);
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
fhss_reset(fhss_struct);

if (fhss_beacon_create_tasklet(fhss_struct) < 0) {
// XXX: should we free the fhss_structure here?
Expand Down Expand Up @@ -636,6 +625,35 @@ static int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure)
return 0;
}

static int fhss_reset(fhss_structure_t *fhss_structure)
{
if (fhss_structure) {
fhss_destroy_scramble_table(fhss_structure);
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
fhss_structure->synch_panid = 0xffff;
fhss_beacon_periodic_stop(fhss_structure);
fhss_structure->current_superframe = 0;
fhss_structure->current_channel_index = 0;
fhss_structure->channel_list_counter = 0;
if (fhss_is_synch_root(fhss_structure) == false) {
fhss_structure->own_hop = 0xff;
}
fhss_structure->tx_allowed = false;
fhss_structure->synch_interval = (uint32_t) (fhss_structure->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
fhss_structure->rx_channel = 0;
fhss_structure->beacons_received_timer = 0;
memset(fhss_structure->synch_parent, 0xff, 8);
fhss_structure->send_synch_info_on_next_broadcast_channel = false;
memset(&fhss_structure->synch_configuration, 0, sizeof(fhss_synch_configuration_t));
fhss_structure->synch_infos_sent_counter = 0;
fhss_structure->broadcast_start_superframe = 0;
fhss_failed_list_free(fhss_structure);
fhss_structure->fhss_state = FHSS_UNSYNCHRONIZED;
return 0;
}
return -1;
}

int fhss_add_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info)
{
if (!fhss_structure || !source_address || !synch_info) {
Expand Down Expand Up @@ -720,7 +738,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f

if (fhss_state == FHSS_UNSYNCHRONIZED) {
tr_debug("FHSS down");
fhss_down(fhss_structure);
fhss_reset(fhss_structure);
fhss_reset_synch_monitor(&fhss_structure->synch_monitor);
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->synch_monitor.drift_compensation);
fhss_stats_update(fhss_structure, STATS_FHSS_AVG_SYNCH_FIX, fhss_structure->synch_monitor.avg_synch_fix);
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, fhss_structure->synch_interval / 1000);
} else {
// Do not synchronize to current pan
if (fhss_structure->synch_panid == pan_id) {
Expand Down
45 changes: 1 addition & 44 deletions source/Service_Libs/fhss/fhss_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
fhss_structure_t *fhss_struct = 0;

static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
static int fhss_reset(fhss_structure_t *fhss_structure);
static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id);
static void fhss_set_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
static bool fhss_read_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
Expand Down Expand Up @@ -70,48 +69,6 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
}
}

static int fhss_reset(fhss_structure_t *fhss_structure)
{
if (fhss_structure) {
fhss_destroy_scramble_table(fhss_structure);
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
fhss_struct->synch_panid = 0xffff;
fhss_beacon_periodic_stop(fhss_structure);
fhss_struct->current_superframe = 0;
fhss_struct->current_channel_index = 0;
fhss_struct->channel_list_counter = 0;
if (fhss_is_synch_root(fhss_structure) == false) {
fhss_struct->own_hop = 0xff;
}
fhss_struct->tx_allowed = false;
fhss_struct->synch_interval = (uint32_t) (fhss_struct->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
fhss_struct->rx_channel = 0;
fhss_struct->beacons_received_timer = 0;
memset(fhss_struct->synch_parent, 0xff, 8);
fhss_struct->send_synch_info_on_next_broadcast_channel = false;
memset(&fhss_struct->synch_configuration, 0, sizeof(fhss_synch_configuration_t));
fhss_struct->synch_infos_sent_counter = 0;
fhss_struct->broadcast_start_superframe = 0;
fhss_failed_list_free(fhss_structure);
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
return 0;
}
return -1;
}

int fhss_down(fhss_structure_t *fhss_structure)
{
if (fhss_structure) {
fhss_reset(fhss_structure);
fhss_reset_synch_monitor(&fhss_struct->synch_monitor);
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->synch_monitor.drift_compensation);
fhss_stats_update(fhss_structure, STATS_FHSS_AVG_SYNCH_FIX, fhss_structure->synch_monitor.avg_synch_fix);
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, fhss_structure->synch_interval / 1000);
return 0;
}
return -1;
}

static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id)
{
if (timer_id <0 || !fhss_struct) {
Expand Down Expand Up @@ -195,7 +152,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
if (!fhss_structure) {
return -1;
}
fhss_destroy_scramble_table(fhss_structure);
fhss_structure->handle_state_set(fhss_structure, FHSS_UNSYNCHRONIZED, 0);
ns_dyn_mem_free(fhss_structure->ws);
ns_dyn_mem_free(fhss_structure);
fhss_structure = 0;
Expand Down
1 change: 0 additions & 1 deletion source/Service_Libs/fhss/fhss_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ struct fhss_structure
};

fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);
int fhss_down(fhss_structure_t *fhss_structure);
int8_t fhss_set_datarate(fhss_structure_t *fhss_structure, uint32_t datarate);
int8_t fhss_set_synch_configuration(fhss_structure_t *fhss_structure, const fhss_synch_configuration_t *fhss_synch_configuration);
fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api);
Expand Down
9 changes: 6 additions & 3 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ bool test_fhss_enable()
if (fhss_struct == fhss_get_object_with_api(&fhss_fake_api)) {
return false;
}
fhss_disable(fhss_struct);
ns_dyn_mem_free(fhss_struct);
fhss_struct = 0;
// Test tasklet creation failed
fhss_beacon_tasklet_stub.int8_value = -1;
nsdynmemlib_stub.returnCounter = 1;
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
return false;
}
fhss_disable(fhss_struct);
ns_dyn_mem_free(fhss_struct);
fhss_struct = 0;
return true;
}

Expand Down Expand Up @@ -553,7 +555,8 @@ bool test_fhss_event_timer_cb()
ns_timer_stub.cb(0, 0);
}

fhss_disable(fhss_struct);
ns_dyn_mem_free(fhss_struct);
fhss_struct = 0;
return true;
}

Expand Down

0 comments on commit 2cbe6dc

Please sign in to comment.