42
42
static uint32_t global_seed = 1 ;
43
43
44
44
45
- uint16_t tr51_calc_nearest_prime_number (uint16_t start_value )
45
+ static uint16_t tr51_calc_nearest_prime_number (uint16_t start_value )
46
46
{
47
47
if (start_value < 2 ) {
48
48
return 0 ;
@@ -60,22 +60,28 @@ uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
60
60
return 0 ;
61
61
}
62
62
63
- void tr51_seed_rand (uint32_t seed )
63
+ static void tr51_seed_rand (uint32_t seed )
64
64
{
65
65
if (!seed ) {
66
66
seed = 1 ;
67
67
}
68
68
global_seed = seed ;
69
69
}
70
70
71
- int32_t tr51_get_rand (void )
71
+ static int32_t tr51_get_rand (void )
72
72
{
73
73
uint32_t random_val = ((global_seed * 1103515245 ) + 12345 ) & 0x7fffffff ;
74
74
global_seed = random_val ;
75
75
return random_val ;
76
76
}
77
77
78
- void tr51_calculate_channel_table (uint16_t number_of_channels , uint16_t nearest_prime , int32_t * channel_table )
78
+ /**
79
+ * @brief Calculate channel table based on TR51 channel function.
80
+ * @param number_of_channels Number of channels in table.
81
+ * @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
82
+ * @param channel_table Output channel table. Has to be at least nearest_prime in length.
83
+ */
84
+ static void tr51_calculate_channel_table (uint16_t number_of_channels , uint16_t nearest_prime , int32_t * channel_table )
79
85
{
80
86
int32_t i ,j ,k ;
81
87
tr51_seed_rand (1 );
@@ -97,7 +103,7 @@ void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_
97
103
}
98
104
}
99
105
100
- void tr51_compute_cfd (uint8_t * mac , uint8_t * first_element , uint8_t * step_size , uint16_t channel_table_length )
106
+ static void tr51_compute_cfd (uint8_t * mac , uint8_t * first_element , uint8_t * step_size , uint16_t channel_table_length )
101
107
{
102
108
* first_element = (mac [5 ] ^ mac [6 ] ^ mac [7 ]) % channel_table_length ;
103
109
* step_size = (mac [7 ] % (channel_table_length - 1 )) + 1 ;
@@ -116,7 +122,18 @@ static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels,
116
122
return 0 ;
117
123
}
118
124
119
- uint16_t tr51_calculate_hopping_sequence (int32_t * channel_table , uint16_t channel_table_length , uint8_t first_element , uint8_t step_size , int32_t * output_table , uint16_t * excluded_channels , uint16_t number_of_excluded_channels )
125
+ /**
126
+ * @brief Calculate hopping sequence for a specific peer using tr51 channel function.
127
+ * @param channel_table Used channel table.
128
+ * @param channel_table_length Length of the used channel table.
129
+ * @param first_element Start generated by CFD function.
130
+ * @param step_size Step size generated by CFD function.
131
+ * @param output_table Output hopping sequence table.
132
+ * @param excluded_channels List of not used channels.
133
+ * @param number_of_excluded_channels Number of not used channels.
134
+ * @return Number of channels in sequence.
135
+ */
136
+ static uint16_t tr51_calculate_hopping_sequence (int32_t * channel_table , uint16_t channel_table_length , uint8_t first_element , uint8_t step_size , int32_t * output_table , uint16_t * excluded_channels , uint16_t number_of_excluded_channels )
120
137
{
121
138
uint16_t cntr = channel_table_length ;
122
139
uint8_t index = first_element ;
@@ -179,7 +196,7 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
179
196
return channel_number ;
180
197
}
181
198
182
- int32_t tr51_get_uc_channel_index (uint16_t slot_number , uint8_t * mac , int16_t number_of_channels )
199
+ int32_t tr51_get_uc_channel_index (uint16_t slot_number , uint8_t * mac , int16_t number_of_channels , uint16_t * excluded_channels , uint16_t number_of_excluded_channels )
183
200
{
184
201
uint16_t nearest_prime = tr51_calc_nearest_prime_number (number_of_channels );
185
202
int32_t channel_table [nearest_prime ];
@@ -190,11 +207,11 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu
190
207
tr51_compute_cfd (mac , & first_element , & step_size , nearest_prime );
191
208
// Not sure yet which one is the correct second parameter
192
209
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
193
- tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , NULL , 0 );
210
+ tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , excluded_channels , number_of_excluded_channels );
194
211
return output_table [slot_number ];
195
212
}
196
213
197
- int32_t tr51_get_bc_channel_index (uint16_t slot_number , uint16_t bsi , int16_t number_of_channels )
214
+ int32_t tr51_get_bc_channel_index (uint16_t slot_number , uint16_t bsi , int16_t number_of_channels , uint16_t * excluded_channels , uint16_t number_of_excluded_channels )
198
215
{
199
216
uint16_t nearest_prime = tr51_calc_nearest_prime_number (number_of_channels );
200
217
int32_t channel_table [nearest_prime ];
@@ -206,6 +223,6 @@ int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t nu
206
223
tr51_compute_cfd (mac , & first_element , & step_size , nearest_prime );
207
224
// Not sure yet which one is the correct second parameter
208
225
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
209
- tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , NULL , 0 );
226
+ tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , excluded_channels , number_of_excluded_channels );
210
227
return output_table [slot_number ];
211
228
}
0 commit comments