Skip to content

Commit

Permalink
FHSS: Static channel functions added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Mar 7, 2018
1 parent 695e64c commit b9606c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
29 changes: 23 additions & 6 deletions source/Service_Libs/fhss/channel_functions.c
Expand Up @@ -42,7 +42,7 @@
static uint32_t global_seed = 1;


uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
static uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
{
if (start_value < 2) {
return 0;
Expand All @@ -60,22 +60,28 @@ uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
return 0;
}

void tr51_seed_rand(uint32_t seed)
static void tr51_seed_rand(uint32_t seed)
{
if (!seed) {
seed = 1;
}
global_seed = seed;
}

int32_t tr51_get_rand(void)
static int32_t tr51_get_rand(void)
{
uint32_t random_val = ((global_seed * 1103515245) + 12345) & 0x7fffffff;
global_seed = random_val;
return random_val;
}

void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table)
/**
* @brief Calculate channel table based on TR51 channel function.
* @param number_of_channels Number of channels in table.
* @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
* @param channel_table Output channel table. Has to be at least nearest_prime in length.
*/
static void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table)
{
int32_t i,j,k;
tr51_seed_rand(1);
Expand All @@ -97,7 +103,7 @@ void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_
}
}

void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step_size, uint16_t channel_table_length)
static void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step_size, uint16_t channel_table_length)
{
*first_element = (mac[5] ^ mac[6] ^ mac[7]) % channel_table_length;
*step_size = (mac[7] % (channel_table_length - 1)) + 1;
Expand All @@ -116,7 +122,18 @@ static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels,
return 0;
}

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)
/**
* @brief Calculate hopping sequence for a specific peer using tr51 channel function.
* @param channel_table Used channel table.
* @param channel_table_length Length of the used channel table.
* @param first_element Start generated by CFD function.
* @param step_size Step size generated by CFD function.
* @param output_table Output hopping sequence table.
* @param excluded_channels List of not used channels.
* @param number_of_excluded_channels Number of not used channels.
* @return Number of channels in sequence.
*/
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)
{
uint16_t cntr = channel_table_length;
uint8_t index = first_element;
Expand Down
20 changes: 0 additions & 20 deletions source/Service_Libs/fhss/channel_functions.h
Expand Up @@ -16,26 +16,6 @@
*/
#ifndef CHANNEL_FUNC_H_
#define CHANNEL_FUNC_H_
/**
* @brief Calculate channel table based on TR51 channel function.
* @param number_of_channels Number of channels in table.
* @param nearest_prime Nearest prime number. Must be equal to or larger than number_of_channels.
* @param channel_table Output channel table. Has to be at least nearest_prime in length.
*/
void tr51_calculate_channel_table(uint16_t number_of_channels, uint16_t nearest_prime, int32_t *channel_table);

/**
* @brief Calculate hopping sequence for a specific peer using tr51 channel function.
* @param channel_table Used channel table.
* @param channel_table_length Length of the used channel table.
* @param first_element Start generated by CFD function.
* @param step_size Step size generated by CFD function.
* @param output_table Output hopping sequence table.
* @param excluded_channels List of not used channels.
* @param number_of_excluded_channels Number of not used channels.
* @return Number of channels in sequence.
*/
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);

/**
* @brief Compute the unicast schedule channel index using tr51 channel function.
Expand Down

0 comments on commit b9606c9

Please sign in to comment.