Skip to content

Commit 8166585

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1602 from ARMmbed/IOTTHD-2311
Iotthd 2311
2 parents 90fbb45 + a88590f commit 8166585

File tree

6 files changed

+102
-192
lines changed

6 files changed

+102
-192
lines changed

source/Service_Libs/fhss/channel_functions.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
static uint32_t global_seed = 1;
4343

4444

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)
4646
{
4747
if (start_value < 2) {
4848
return 0;
@@ -60,22 +60,28 @@ uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
6060
return 0;
6161
}
6262

63-
void tr51_seed_rand(uint32_t seed)
63+
static void tr51_seed_rand(uint32_t seed)
6464
{
6565
if (!seed) {
6666
seed = 1;
6767
}
6868
global_seed = seed;
6969
}
7070

71-
int32_t tr51_get_rand(void)
71+
static int32_t tr51_get_rand(void)
7272
{
7373
uint32_t random_val = ((global_seed * 1103515245) + 12345) & 0x7fffffff;
7474
global_seed = random_val;
7575
return random_val;
7676
}
7777

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)
7985
{
8086
int32_t i,j,k;
8187
tr51_seed_rand(1);
@@ -97,7 +103,7 @@ void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_
97103
}
98104
}
99105

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)
101107
{
102108
*first_element = (mac[5] ^ mac[6] ^ mac[7]) % channel_table_length;
103109
*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,
116122
return 0;
117123
}
118124

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)
120137
{
121138
uint16_t cntr = channel_table_length;
122139
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
179196
return channel_number;
180197
}
181198

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)
183200
{
184201
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
185202
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
190207
tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime);
191208
// Not sure yet which one is the correct second parameter
192209
// 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);
194211
return output_table[slot_number];
195212
}
196213

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)
198215
{
199216
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
200217
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
206223
tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime);
207224
// Not sure yet which one is the correct second parameter
208225
// 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);
210227
return output_table[slot_number];
211228
}

source/Service_Libs/fhss/channel_functions.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,28 @@
1616
*/
1717
#ifndef CHANNEL_FUNC_H_
1818
#define CHANNEL_FUNC_H_
19-
/**
20-
* @brief Calculate channel table based on TR51 channel function.
21-
* @param number_of_channels Number of channels in table.
22-
* @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
23-
* @param channel_table Output channel table. Has to be at least nearest_prime in length.
24-
*/
25-
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);
26-
27-
/**
28-
* @brief Calculate hopping sequence for a specific peer using tr51 channel function.
29-
* @param channel_table Used channel table.
30-
* @param channel_table_length Length of the used channel table.
31-
* @param first_element Start generated by CFD function.
32-
* @param step_size Step size generated by CFD function.
33-
* @param output_table Output hopping sequence table.
34-
* @param excluded_channels List of not used channels.
35-
* @param number_of_excluded_channels Number of not used channels.
36-
* @return Number of channels in sequence.
37-
*/
38-
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);
3919

4020
/**
4121
* @brief Compute the unicast schedule channel index using tr51 channel function.
4222
* @param slot_number Current slot number.
4323
* @param mac MAC address of the node for which the index is calculated.
4424
* @param number_of_channels Number of channels.
25+
* @param excluded_channels Excluded channels.
26+
* @param number_of_excluded_channels Number of excluded channels.
4527
* @return Channel index.
4628
*/
47-
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels);
29+
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);
4830

4931
/**
5032
* @brief Compute the broadcast schedule channel index using tr51 channel function.
5133
* @param slot_number Current slot number.
5234
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
5335
* @param number_of_channels Number of channels.
36+
* @param excluded_channels Excluded channels.
37+
* @param number_of_excluded_channels Number of excluded channels.
5438
* @return Channel index.
5539
*/
56-
int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels);
40+
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);
5741

5842
/**
5943
* @brief Compute the unicast schedule channel index using direct hash channel function.

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
8282
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
8383

8484
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
85-
next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels);
85+
next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels, NULL, 0);
8686
if (++fhss_structure->ws->bc_slot == fhss_structure->number_of_channels) {
8787
fhss_structure->ws->bc_slot = 0;
8888
}
@@ -204,7 +204,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
204204
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
205205
return;
206206
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
207-
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels);
207+
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels, NULL, 0);
208208
if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) {
209209
fhss_structure->ws->uc_slot = 0;
210210
}
@@ -245,7 +245,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
245245
//TODO: Get destination UFSI, timestamp and dwell time from neighbour table
246246
uint16_t destination_slot = fhss_ws_calculate_destination_slot(fhss_structure, 0, 0, fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval, tx_time);
247247
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
248-
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels);
248+
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels, NULL, 0);
249249
} else if(fhss_structure->ws->fhss_configuration.ws_channel_function == WS_DH1CF) {
250250
tx_channel = dh1cf_get_uc_channel_index(destination_slot, destination_address, fhss_structure->number_of_channels);
251251
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_VENDOR_DEF_CF) {

test/nanostack/unittest/service_libs/channel_functions/channelfunctest.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ TEST_GROUP(channel_functions)
2929
}
3030
};
3131

32-
TEST(channel_functions, test_tr51_get_rand)
33-
{
34-
CHECK(test_tr51_get_rand());
35-
}
36-
37-
TEST(channel_functions, test_tr51_calculate_channel_table)
38-
{
39-
CHECK(test_tr51_calculate_channel_table());
40-
}
41-
42-
TEST(channel_functions, test_tr51_compute_cfd)
43-
{
44-
CHECK(test_tr51_compute_cfd());
45-
}
46-
47-
TEST(channel_functions, test_tr51_calculate_hopping_sequence)
48-
{
49-
CHECK(test_tr51_calculate_hopping_sequence());
50-
}
51-
5232
TEST(channel_functions, test_dh1cf_get_uc_channel_index)
5333
{
5434
CHECK(test_dh1cf_get_uc_channel_index());
@@ -59,12 +39,12 @@ TEST(channel_functions, test_dh1cf_get_bc_channel_index)
5939
CHECK(test_dh1cf_get_bc_channel_index());
6040
}
6141

62-
TEST(channel_functions, test_tr51_calc_nearest_prime_number)
42+
TEST(channel_functions, test_tr51_get_uc_channel_index)
6343
{
64-
CHECK(test_tr51_calc_nearest_prime_number());
44+
CHECK(test_tr51_get_uc_channel_index());
6545
}
6646

67-
TEST(channel_functions, test_tr51_get_uc_channel_index)
47+
TEST(channel_functions, test_tr51_get_bc_channel_index)
6848
{
69-
CHECK(test_tr51_get_uc_channel_index());
49+
CHECK(test_tr51_get_bc_channel_index());
7050
}

0 commit comments

Comments
 (0)