@@ -109,17 +109,16 @@ static void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step
109
109
* step_size = (mac [7 ] % (channel_table_length - 1 )) + 1 ;
110
110
}
111
111
112
- static uint8_t tr51_find_excluded (int32_t channel , uint16_t * excluded_channels , uint16_t number_of_excluded_channels )
112
+ static uint8_t tr51_find_excluded (int32_t channel , uint32_t * excluded_channels )
113
113
{
114
- uint8_t count = 0 ;
115
114
if (excluded_channels != NULL ) {
116
- for ( count = 0 ; count < number_of_excluded_channels ; count ++ ) {
117
- if ( channel == excluded_channels [ count ]) {
118
- return 1 ;
119
- }
115
+ uint8_t index = channel / 32 ;
116
+ channel %= 32 ;
117
+ if ( excluded_channels [ index ] & (( uint32_t ) 1 << channel )) {
118
+ return true;
120
119
}
121
120
}
122
- return 0 ;
121
+ return false ;
123
122
}
124
123
125
124
/**
@@ -129,18 +128,17 @@ static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels,
129
128
* @param first_element Start generated by CFD function.
130
129
* @param step_size Step size generated by CFD function.
131
130
* @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.
131
+ * @param excluded_channels Bit mask where excluded channels are set to 1.
134
132
* @return Number of channels in sequence.
135
133
*/
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 )
134
+ 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 , uint32_t * excluded_channels )
137
135
{
138
136
uint16_t cntr = channel_table_length ;
139
137
uint8_t index = first_element ;
140
138
uint8_t slot = 0 ;
141
139
while (cntr -- ) {
142
140
if (channel_table [index ] != -1 ) {
143
- if (! tr51_find_excluded (channel_table [index ], excluded_channels , number_of_excluded_channels ) ) {
141
+ if (tr51_find_excluded (channel_table [index ], excluded_channels ) == false ) {
144
142
output_table [slot ] = channel_table [index ];
145
143
slot ++ ;
146
144
}
@@ -196,7 +194,7 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
196
194
return channel_number ;
197
195
}
198
196
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 )
197
+ int32_t tr51_get_uc_channel_index (uint16_t slot_number , uint8_t * mac , int16_t number_of_channels , uint32_t * excluded_channels )
200
198
{
201
199
uint16_t nearest_prime = tr51_calc_nearest_prime_number (number_of_channels );
202
200
int32_t channel_table [nearest_prime ];
@@ -207,11 +205,11 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu
207
205
tr51_compute_cfd (mac , & first_element , & step_size , nearest_prime );
208
206
// Not sure yet which one is the correct second parameter
209
207
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, 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 );
208
+ tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , excluded_channels );
211
209
return output_table [slot_number ];
212
210
}
213
211
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 )
212
+ int32_t tr51_get_bc_channel_index (uint16_t slot_number , uint16_t bsi , int16_t number_of_channels , uint32_t * excluded_channels )
215
213
{
216
214
uint16_t nearest_prime = tr51_calc_nearest_prime_number (number_of_channels );
217
215
int32_t channel_table [nearest_prime ];
@@ -223,6 +221,6 @@ int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t nu
223
221
tr51_compute_cfd (mac , & first_element , & step_size , nearest_prime );
224
222
// Not sure yet which one is the correct second parameter
225
223
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, 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 );
224
+ tr51_calculate_hopping_sequence (channel_table , nearest_prime , first_element , step_size , output_table , excluded_channels );
227
225
return output_table [slot_number ];
228
226
}
0 commit comments