Skip to content

Commit

Permalink
FHSS: Separated broadcast schedule channel function
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 3, 2018
1 parent 327c310 commit 9fd804b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
7 changes: 5 additions & 2 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uin
*/
typedef struct fhss_ws_configuration
{
/** WS channel function. */
fhss_ws_channel_functions ws_channel_function;
/** WS unicast channel function. */
fhss_ws_channel_functions ws_uc_channel_function;

/** WS broadcast channel function. */
fhss_ws_channel_functions ws_bc_channel_function;

/** Broadcast schedule identifier. */
uint16_t bsi;
Expand Down
3 changes: 1 addition & 2 deletions nanostack/net_fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ extern "C" {
extern fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics);

/**
* @brief TODO: description.
* @brief Creates FHSS WS API instance which will be registered to software MAC.
* @param fhss_configuration Basic FHSS configuration.
* @param fhss_timer FHSS platform timer interface and configuration.
* @param fhss_statistics FHSS statistics storage.
* @return New FHSS instance if successful, NULL otherwise.
*/
extern fhss_api_t *ns_fhss_ws_create(const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer);
Expand Down
16 changes: 9 additions & 7 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static fhss_ws_neighbor_timing_info_t *ws_get_neighbor_info(const fhss_api_t *ap
static void ws_bootstrap_llc_hopping_update(struct protocol_interface_info_entry *cur, const fhss_ws_configuration_t *fhss_configuration)
{
memcpy(cur->ws_info->hopping_schdule.channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->hopping_schdule.channel_function = fhss_configuration->ws_channel_function;
cur->ws_info->hopping_schdule.channel_function = fhss_configuration->ws_uc_channel_function;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = fhss_configuration->fhss_bc_dwell_interval;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = fhss_configuration->fhss_broadcast_interval;
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = fhss_configuration->fhss_uc_dwell_interval;
Expand All @@ -205,7 +205,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
}

fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration.ws_channel_function = cur->ws_info->fhss_channel_function;
fhss_configuration.ws_uc_channel_function = cur->ws_info->fhss_channel_function;
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->fhss_bc_interval;

Expand All @@ -223,7 +223,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
return 0;
}
memcpy(cur->ws_info->fhss_channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->fhss_channel_function = fhss_configuration->ws_channel_function;
cur->ws_info->fhss_channel_function = fhss_configuration->ws_uc_channel_function;
cur->ws_info->fhss_bc_dwell_interval = fhss_configuration->fhss_bc_dwell_interval;
cur->ws_info->fhss_bc_interval = fhss_configuration->fhss_broadcast_interval;
cur->ws_info->fhss_uc_dwell_interval = fhss_configuration->fhss_uc_dwell_interval;
Expand All @@ -233,7 +233,9 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration)
{
fhss_configuration->fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration->ws_channel_function = cur->ws_info->fhss_channel_function;
fhss_configuration->ws_uc_channel_function = cur->ws_info->fhss_channel_function;
// TODO: Just temporarily using hard coded broadcast channel function
fhss_configuration->ws_bc_channel_function = WS_DH1CF;
fhss_configuration->fhss_bc_dwell_interval = cur->ws_info->fhss_bc_dwell_interval;
fhss_configuration->fhss_broadcast_interval = cur->ws_info->fhss_bc_interval;
ws_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);
Expand Down Expand Up @@ -267,7 +269,7 @@ static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
}

fhss_configuration.fhss_uc_dwell_interval = 0;
fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
fhss_configuration.ws_uc_channel_function = WS_FIXED_CHANNEL;
fhss_configuration.fhss_bc_dwell_interval = 0;
fhss_configuration.fhss_broadcast_interval = 0;
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
Expand Down Expand Up @@ -312,8 +314,8 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
ws_fhss_set_defaults(cur, &fhss_configuration);

// Learning unicast network configuration
fhss_configuration.ws_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
if (fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
fhss_configuration.ws_uc_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
if (fhss_configuration.ws_uc_channel_function == WS_FIXED_CHANNEL) {
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
}
/* Learning different unicast is not working currently at fhss network follows border router
Expand Down
41 changes: 19 additions & 22 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
{
int32_t next_channel = fhss_structure->rx_channel;

if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
if (fhss_structure->ws->fhss_configuration.ws_bc_channel_function == WS_TR51CF) {
next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels, NULL);
if (++fhss_structure->ws->bc_slot == fhss_structure->number_of_channels) {
fhss_structure->ws->bc_slot = 0;
}
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_DH1CF) {
} else if (fhss_structure->ws->fhss_configuration.ws_bc_channel_function == WS_DH1CF) {
next_channel = dh1cf_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels);
fhss_structure->ws->bc_slot++;
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_VENDOR_DEF_CF) {
} else if (fhss_structure->ws->fhss_configuration.ws_bc_channel_function == WS_VENDOR_DEF_CF) {
if (fhss_structure->ws->fhss_configuration.vendor_defined_cf) {
next_channel = fhss_structure->ws->fhss_configuration.vendor_defined_cf(fhss_structure->fhss_api, fhss_structure->ws->bc_slot, NULL, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ static uint32_t fhss_ws_calculate_ufsi(fhss_structure_t *fhss_structure, uint32_
}
uint64_t ms_since_seq_start = (cur_slot * dwell_time) + (dwell_time-remaining_time) + time_to_tx;
uint32_t seq_length = 0x10000;
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_TR51CF) {
ms_since_seq_start %= (dwell_time*fhss_structure->number_of_channels);
seq_length = fhss_structure->number_of_channels;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states
if (!fhss_structure) {
return;
}
if ((fhss_state == FHSS_SYNCHRONIZED) && (fhss_structure->ws->fhss_configuration.ws_channel_function != WS_FIXED_CHANNEL)) {
if (fhss_state == FHSS_SYNCHRONIZED) {
uint32_t fhss_broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
uint8_t fhss_bc_dwell_interval = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;

Expand All @@ -298,8 +298,10 @@ static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states
fhss_broadcast_handler(fhss_structure->fhss_api, 0);
}
// Start unicast schedule
fhss_ws_update_uc_channel_callback(fhss_structure);
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval*1000, fhss_unicast_handler);
if ((fhss_structure->ws->fhss_configuration.ws_uc_channel_function != WS_FIXED_CHANNEL)) {
fhss_ws_update_uc_channel_callback(fhss_structure);
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval*1000, fhss_unicast_handler);
}
}

fhss_structure->fhss_state = fhss_state;
Expand All @@ -311,17 +313,17 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
uint8_t mac_address[8];
int32_t next_channel = fhss_structure->rx_channel;
fhss_structure->callbacks.read_mac_address(fhss_structure->fhss_api, mac_address);
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_FIXED_CHANNEL) {
return;
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
} else if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_TR51CF) {
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels, NULL);
if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) {
fhss_structure->ws->uc_slot = 0;
}
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_DH1CF) {
} else if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_DH1CF) {
next_channel = fhss_structure->rx_channel = dh1cf_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels);
fhss_structure->ws->uc_slot++;
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_VENDOR_DEF_CF) {
} else if (fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_VENDOR_DEF_CF) {
if (fhss_structure->ws->fhss_configuration.vendor_defined_cf) {
next_channel = fhss_structure->rx_channel = fhss_structure->ws->fhss_configuration.vendor_defined_cf(fhss_structure->fhss_api, fhss_structure->ws->bc_slot, mac_address, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels);
}
Expand Down Expand Up @@ -453,9 +455,6 @@ static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_
if (!fhss_structure) {
return true;
}
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
return true;
}
// Do not allow broadcast destination on unicast channel
if (is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == false)) {
return false;
Expand Down Expand Up @@ -535,7 +534,7 @@ static void fhss_ws_data_tx_done_callback(const fhss_api_t *api, bool waiting_ac
if (!fhss_structure) {
return;
}
if ((fhss_structure->fhss_state == FHSS_SYNCHRONIZED) && (fhss_structure->ws->fhss_configuration.ws_channel_function != WS_FIXED_CHANNEL)) {
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
if (waiting_ack == false) {
if (fhss_structure->ws->is_on_bc_channel == false) {
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, fhss_structure->rx_channel);
Expand Down Expand Up @@ -612,7 +611,7 @@ static bool fhss_ws_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadc
return false;
}
// Do not use broadcast queue when fixed channel
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
if (fhss_structure->ws->fhss_configuration.ws_bc_channel_function == WS_FIXED_CHANNEL) {
return false;
}
// Broadcast packets are stored in broadcast queue
Expand Down Expand Up @@ -661,9 +660,6 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
if (!fhss_structure->ws) {
return -1;
}
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
return 0;
}
if (!bc_timing_info->broadcast_interval || !bc_timing_info->broadcast_dwell_interval) {
return -1;
}
Expand Down Expand Up @@ -701,14 +697,15 @@ int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_co
if (channel_count <= 0) {
return -1;
}
if ((fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) && (fhss_configuration->ws_channel_function != WS_FIXED_CHANNEL)) {
if ((fhss_structure->ws->fhss_configuration.ws_uc_channel_function == WS_FIXED_CHANNEL) && (fhss_configuration->ws_uc_channel_function != WS_FIXED_CHANNEL)) {
// Start unicast schedule if channel function changed from fixed channel
fhss_start_timer(fhss_structure, fhss_configuration->fhss_uc_dwell_interval*1000, fhss_unicast_handler);
}
fhss_structure->ws->fhss_configuration = *fhss_configuration;
fhss_structure->number_of_channels = channel_count;
tr_info("fhss Configuration set function:%d channels: %d, uc dwell: %d, bc dwell: %d, bc interval: %d, bsi:%d",
fhss_structure->ws->fhss_configuration.ws_channel_function,
tr_info("fhss Configuration set UC CF: %d, BC CF: %d, channels: %d, uc dwell: %d, bc dwell: %d, bc interval: %d, bsi:%d",
fhss_structure->ws->fhss_configuration.ws_uc_channel_function,
fhss_structure->ws->fhss_configuration.ws_bc_channel_function,
fhss_structure->number_of_channels,
fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval,
fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval,
Expand Down

0 comments on commit 9fd804b

Please sign in to comment.