@@ -42,7 +42,6 @@ fhss_structure_t *fhss_struct = 0;
42
42
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 );
43
43
static void fhss_event_timer_cb (int8_t timer_id , uint16_t slots );
44
44
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 );
46
45
static bool fhss_is_there_common_divisor (uint16_t i , uint8_t j );
47
46
static void fhss_update_channel (fhss_structure_t * fhss_structure );
48
47
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
65
64
if (!fhss_struct ) {
66
65
return -3 ;
67
66
}
67
+ memset (fhss_struct , 0 , sizeof (fhss_structure_t ));
68
68
fhss_struct -> fhss_api = fhss_api ;
69
69
fhss_struct -> fhss_configuration = * fhss_configuration ;
70
70
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
89
89
fhss_struct -> fhss_beacon_info_store = NULL ;
90
90
fhss_struct -> fhss_event_timer = eventOS_callback_timer_register (fhss_event_timer_cb );
91
91
92
- fhss_generate_scramble_table (fhss_struct );
93
-
94
92
if (fhss_beacon_create_tasklet (fhss_struct ) < 0 ) {
95
93
// XXX: should we free the fhss_structure here?
96
94
return -5 ;
@@ -308,10 +306,19 @@ static int fhss_reset_synch_monitor(fhss_synch_monitor_s *synch_monitor, bool re
308
306
return -1 ;
309
307
}
310
308
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
+
311
317
static int fhss_reset (fhss_structure_t * fhss_structure )
312
318
{
313
319
if (fhss_structure ) {
314
320
fhss_structure -> platform_functions .fhss_timer_stop (fhss_superframe_handler , fhss_structure -> fhss_api );
321
+ fhss_destroy_scramble_table (fhss_structure );
315
322
fhss_struct -> synch_panid = 0xffff ;
316
323
fhss_beacon_periodic_stop (fhss_structure );
317
324
fhss_struct -> current_superframe = 0 ;
@@ -355,6 +362,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
355
362
if (!fhss_structure ) {
356
363
return -1 ;
357
364
}
365
+ fhss_destroy_scramble_table (fhss_structure );
358
366
ns_dyn_mem_free (fhss_structure );
359
367
fhss_structure = 0 ;
360
368
fhss_struct = 0 ;
@@ -876,9 +884,13 @@ static bool fhss_is_there_common_divisor(uint16_t i, uint8_t j)
876
884
}
877
885
878
886
879
- static int fhss_generate_scramble_table (fhss_structure_t * fhss_structure )
887
+ int fhss_generate_scramble_table (fhss_structure_t * fhss_structure )
880
888
{
881
889
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
+ }
882
894
// Generate indexes to extend the channel sequence. Generated indexes cannot have common divisors with value number_of_channels.
883
895
for (int i = 0 ; i < MAX_SCRAMBLE_TABLE_INDEXES ;)
884
896
{
0 commit comments