Skip to content

Commit e456662

Browse files
author
Jarkko Paso
committed
FHSS: Removed scramble table generation from fhss enable
1 parent b643622 commit e456662

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fhss_structure_t *fhss_struct = 0;
4242
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);
4343
static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
4444
static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id);
45-
static int fhss_generate_scramble_table(fhss_structure_t *fhss_structure);
4645
static bool fhss_is_there_common_divisor(uint16_t i, uint8_t j);
4746
static void fhss_update_channel(fhss_structure_t *fhss_structure);
4847
static int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor, bool reset_compensation);
@@ -65,6 +64,7 @@ int8_t fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *fhss_config
6564
if (!fhss_struct) {
6665
return -3;
6766
}
67+
memset(fhss_struct, 0, sizeof(fhss_structure_t));
6868
fhss_struct->fhss_api = fhss_api;
6969
fhss_struct->fhss_configuration = *fhss_configuration;
7070
fhss_struct->platform_functions = *fhss_timer;
@@ -89,8 +89,6 @@ int8_t fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *fhss_config
8989
fhss_struct->fhss_beacon_info_store = NULL;
9090
fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
9191

92-
fhss_generate_scramble_table(fhss_struct);
93-
9492
if (fhss_beacon_create_tasklet(fhss_struct) < 0) {
9593
// XXX: should we free the fhss_structure here?
9694
return -5;
@@ -308,10 +306,19 @@ static int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor, bool re
308306
return -1;
309307
}
310308

309+
static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure)
310+
{
311+
if (fhss_structure->fhss_scramble_table) {
312+
ns_dyn_mem_free(fhss_structure->fhss_scramble_table);
313+
fhss_structure->fhss_scramble_table = NULL;
314+
}
315+
}
316+
311317
static int fhss_reset(fhss_structure_t *fhss_structure)
312318
{
313319
if (fhss_structure) {
314320
fhss_structure->platform_functions.fhss_timer_stop(fhss_superframe_handler, fhss_structure->fhss_api);
321+
fhss_destroy_scramble_table(fhss_structure);
315322
fhss_struct->synch_panid = 0xffff;
316323
fhss_beacon_periodic_stop(fhss_structure);
317324
fhss_struct->current_superframe = 0;
@@ -355,6 +362,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
355362
if (!fhss_structure) {
356363
return -1;
357364
}
365+
fhss_destroy_scramble_table(fhss_structure);
358366
ns_dyn_mem_free(fhss_structure);
359367
fhss_structure = 0;
360368
fhss_struct = 0;
@@ -876,9 +884,13 @@ static bool fhss_is_there_common_divisor(uint16_t i, uint8_t j)
876884
}
877885

878886

879-
static int fhss_generate_scramble_table(fhss_structure_t *fhss_structure)
887+
int fhss_generate_scramble_table(fhss_structure_t *fhss_structure)
880888
{
881889
uint8_t j = 2;
890+
fhss_structure->fhss_scramble_table = ns_dyn_mem_alloc(MAX_SCRAMBLE_TABLE_INDEXES);
891+
if (fhss_structure->fhss_scramble_table == NULL) {
892+
return -1;
893+
}
882894
// Generate indexes to extend the channel sequence. Generated indexes cannot have common divisors with value number_of_channels.
883895
for(int i=0; i<MAX_SCRAMBLE_TABLE_INDEXES;)
884896
{

source/Service_Libs/fhss/fhss.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ typedef struct
100100
// Used for randomizing broadcast sending. Device is not allowed to start broadcasting before the given superframe.
101101
uint8_t broadcast_start_superframe;
102102
/*Indexes in this table will be used to extend the repeated channel sequence*/
103-
uint8_t fhss_scramble_table[MAX_SCRAMBLE_TABLE_INDEXES];
103+
uint8_t *fhss_scramble_table;
104104
/** Used to monitor and fix synchronization drift*/
105105
fhss_synch_monitor_s synch_monitor;
106106
/** Used to drop multiple synch info messages on same broadcast channel*/
@@ -151,6 +151,7 @@ int fhss_failed_handle_remove(fhss_structure_t *fhss_structure, uint8_t handle);
151151
void fhss_set_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
152152
void fhss_clear_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
153153
bool fhss_read_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
154+
int fhss_generate_scramble_table(fhss_structure_t *fhss_structure);
154155
#define MAX_FHSS_TIMER_DIVIDER 100
155156
#define SYNCH_MONITOR_AVG_SAMPLES 5
156157

source/Service_Libs/fhss/fhss_mac_interface.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint
212212
tr_debug("Synch same panid %u", pan_id);
213213
return;
214214
}
215+
if (fhss_structure->fhss_scramble_table == NULL) {
216+
if (fhss_generate_scramble_table(fhss_structure)) {
217+
tr_error("Failed to generate scramble table");
218+
return;
219+
}
220+
}
215221
uint32_t datarate = fhss_structure->callbacks.read_datarate(api);
216222
fhss_set_datarate(fhss_structure, datarate);
217223
uint8_t mac_address[8];

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ bool test_fhss_down()
826826
fhss_struct = malloc(sizeof(fhss_structure_t));
827827
fhss_struct->platform_functions.fhss_timer_stop = &fhss_timer_stop_stub;
828828
fhss_struct->fhss_beacon_info_store = NULL;
829+
fhss_struct->fhss_scramble_table = malloc(20);
829830
ns_list_init(&fhss_struct->fhss_failed_tx_list);
830831
// Test without FHSS
831832
if (fhss_down(NULL) == 0) {

test/nanostack/unittest/stub/fhss_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,8 @@ void fhss_update_beacon_info_lifetimes(fhss_structure_t *fhss_structure, uint32_
185185
{
186186

187187
}
188+
189+
int fhss_generate_scramble_table(fhss_structure_t *fhss_structure)
190+
{
191+
return 0;
192+
}

0 commit comments

Comments
 (0)