Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 2cbe6dc

Browse files
author
Jarkko Paso
committed
FHSS: Moved FHSS reset and down to FHSS module
1 parent 4719187 commit 2cbe6dc

File tree

4 files changed

+43
-62
lines changed

4 files changed

+43
-62
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#define TRACE_GROUP "fhss"
3737

38+
static int fhss_reset(fhss_structure_t *fhss_structure);
3839
static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure);
3940
static bool fhss_is_bc_sending_superframe(fhss_structure_t *fhss_structure);
4041
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);
@@ -68,19 +69,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
6869
}
6970
ns_list_init(&fhss_struct->fhss_failed_tx_list);
7071
fhss_struct->own_hop = 0xff;
71-
fhss_destroy_scramble_table(fhss_struct);
72-
fhss_struct->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_struct->fhss_api);
73-
fhss_struct->synch_panid = 0xffff;
74-
fhss_beacon_periodic_stop(fhss_struct);
75-
if (fhss_is_synch_root(fhss_struct) == false) {
76-
fhss_struct->own_hop = 0xff;
77-
}
78-
fhss_struct->tx_allowed = false;
79-
fhss_struct->synch_interval = (uint32_t) (fhss_struct->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
80-
memset(fhss_struct->synch_parent, 0xff, 8);
81-
fhss_struct->send_synch_info_on_next_broadcast_channel = false;
82-
fhss_failed_list_free(fhss_struct);
83-
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
72+
fhss_reset(fhss_struct);
8473

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

628+
static int fhss_reset(fhss_structure_t *fhss_structure)
629+
{
630+
if (fhss_structure) {
631+
fhss_destroy_scramble_table(fhss_structure);
632+
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
633+
fhss_structure->synch_panid = 0xffff;
634+
fhss_beacon_periodic_stop(fhss_structure);
635+
fhss_structure->current_superframe = 0;
636+
fhss_structure->current_channel_index = 0;
637+
fhss_structure->channel_list_counter = 0;
638+
if (fhss_is_synch_root(fhss_structure) == false) {
639+
fhss_structure->own_hop = 0xff;
640+
}
641+
fhss_structure->tx_allowed = false;
642+
fhss_structure->synch_interval = (uint32_t) (fhss_structure->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
643+
fhss_structure->rx_channel = 0;
644+
fhss_structure->beacons_received_timer = 0;
645+
memset(fhss_structure->synch_parent, 0xff, 8);
646+
fhss_structure->send_synch_info_on_next_broadcast_channel = false;
647+
memset(&fhss_structure->synch_configuration, 0, sizeof(fhss_synch_configuration_t));
648+
fhss_structure->synch_infos_sent_counter = 0;
649+
fhss_structure->broadcast_start_superframe = 0;
650+
fhss_failed_list_free(fhss_structure);
651+
fhss_structure->fhss_state = FHSS_UNSYNCHRONIZED;
652+
return 0;
653+
}
654+
return -1;
655+
}
656+
639657
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)
640658
{
641659
if (!fhss_structure || !source_address || !synch_info) {
@@ -720,7 +738,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f
720738

721739
if (fhss_state == FHSS_UNSYNCHRONIZED) {
722740
tr_debug("FHSS down");
723-
fhss_down(fhss_structure);
741+
fhss_reset(fhss_structure);
742+
fhss_reset_synch_monitor(&fhss_structure->synch_monitor);
743+
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->synch_monitor.drift_compensation);
744+
fhss_stats_update(fhss_structure, STATS_FHSS_AVG_SYNCH_FIX, fhss_structure->synch_monitor.avg_synch_fix);
745+
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, fhss_structure->synch_interval / 1000);
724746
} else {
725747
// Do not synchronize to current pan
726748
if (fhss_structure->synch_panid == pan_id) {

source/Service_Libs/fhss/fhss_common.c

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
fhss_structure_t *fhss_struct = 0;
3737

3838
static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
39-
static int fhss_reset(fhss_structure_t *fhss_structure);
4039
static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id);
4140
static void fhss_set_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
4241
static bool fhss_read_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
@@ -70,48 +69,6 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
7069
}
7170
}
7271

73-
static int fhss_reset(fhss_structure_t *fhss_structure)
74-
{
75-
if (fhss_structure) {
76-
fhss_destroy_scramble_table(fhss_structure);
77-
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
78-
fhss_struct->synch_panid = 0xffff;
79-
fhss_beacon_periodic_stop(fhss_structure);
80-
fhss_struct->current_superframe = 0;
81-
fhss_struct->current_channel_index = 0;
82-
fhss_struct->channel_list_counter = 0;
83-
if (fhss_is_synch_root(fhss_structure) == false) {
84-
fhss_struct->own_hop = 0xff;
85-
}
86-
fhss_struct->tx_allowed = false;
87-
fhss_struct->synch_interval = (uint32_t) (fhss_struct->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
88-
fhss_struct->rx_channel = 0;
89-
fhss_struct->beacons_received_timer = 0;
90-
memset(fhss_struct->synch_parent, 0xff, 8);
91-
fhss_struct->send_synch_info_on_next_broadcast_channel = false;
92-
memset(&fhss_struct->synch_configuration, 0, sizeof(fhss_synch_configuration_t));
93-
fhss_struct->synch_infos_sent_counter = 0;
94-
fhss_struct->broadcast_start_superframe = 0;
95-
fhss_failed_list_free(fhss_structure);
96-
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
97-
return 0;
98-
}
99-
return -1;
100-
}
101-
102-
int fhss_down(fhss_structure_t *fhss_structure)
103-
{
104-
if (fhss_structure) {
105-
fhss_reset(fhss_structure);
106-
fhss_reset_synch_monitor(&fhss_struct->synch_monitor);
107-
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->synch_monitor.drift_compensation);
108-
fhss_stats_update(fhss_structure, STATS_FHSS_AVG_SYNCH_FIX, fhss_structure->synch_monitor.avg_synch_fix);
109-
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, fhss_structure->synch_interval / 1000);
110-
return 0;
111-
}
112-
return -1;
113-
}
114-
11572
static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id)
11673
{
11774
if (timer_id <0 || !fhss_struct) {
@@ -195,7 +152,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
195152
if (!fhss_structure) {
196153
return -1;
197154
}
198-
fhss_destroy_scramble_table(fhss_structure);
155+
fhss_structure->handle_state_set(fhss_structure, FHSS_UNSYNCHRONIZED, 0);
199156
ns_dyn_mem_free(fhss_structure->ws);
200157
ns_dyn_mem_free(fhss_structure);
201158
fhss_structure = 0;

source/Service_Libs/fhss/fhss_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ struct fhss_structure
120120
};
121121

122122
fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);
123-
int fhss_down(fhss_structure_t *fhss_structure);
124123
int8_t fhss_set_datarate(fhss_structure_t *fhss_structure, uint32_t datarate);
125124
int8_t fhss_set_synch_configuration(fhss_structure_t *fhss_structure, const fhss_synch_configuration_t *fhss_synch_configuration);
126125
fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api);

test/nanostack/unittest/service_libs/fhss/test_fhss.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ bool test_fhss_enable()
8282
if (fhss_struct == fhss_get_object_with_api(&fhss_fake_api)) {
8383
return false;
8484
}
85-
fhss_disable(fhss_struct);
85+
ns_dyn_mem_free(fhss_struct);
86+
fhss_struct = 0;
8687
// Test tasklet creation failed
8788
fhss_beacon_tasklet_stub.int8_value = -1;
8889
nsdynmemlib_stub.returnCounter = 1;
8990
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
9091
return false;
9192
}
92-
fhss_disable(fhss_struct);
93+
ns_dyn_mem_free(fhss_struct);
94+
fhss_struct = 0;
9395
return true;
9496
}
9597

@@ -553,7 +555,8 @@ bool test_fhss_event_timer_cb()
553555
ns_timer_stub.cb(0, 0);
554556
}
555557

556-
fhss_disable(fhss_struct);
558+
ns_dyn_mem_free(fhss_struct);
559+
fhss_struct = 0;
557560
return true;
558561
}
559562

0 commit comments

Comments
 (0)