Skip to content

Commit 50ecc3d

Browse files
author
Jarkko Paso
authored
Refactoring Wi-SUN stack (ARMmbed#2686)
* Removed option to create FHSS on application * Separate module for WS PHY mode functions * Renamed functions to use ws_common prefix * Use struct assignment instead of memcpy to get FHSS config
1 parent 9d2386d commit 50ecc3d

File tree

9 files changed

+476
-447
lines changed

9 files changed

+476
-447
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "6LoWPAN/ws/ws_bootstrap_6lbr.h"
6666
#include "6LoWPAN/ws/ws_bootstrap_ffn.h"
6767
#include "6LoWPAN/ws/ws_bootstrap_lfn.h"
68+
#include "6LoWPAN/ws/ws_phy.h"
6869
#include "6LoWPAN/lowpan_adaptation_interface.h"
6970
#include "Service_Libs/etx/etx.h"
7071
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
@@ -582,8 +583,8 @@ static uint8_t ws_generate_exluded_channel_list_from_active_channels(ws_excluded
582583
void ws_fhss_configure_channel_masks(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration)
583584
{
584585
fhss_configuration->channel_mask_size = cur->ws_info->hopping_schdule.number_of_channels;
585-
ws_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
586-
ws_generate_channel_list(fhss_configuration->unicast_channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
586+
ws_common_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
587+
ws_common_generate_channel_list(fhss_configuration->unicast_channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
587588
// using bitwise AND operation for user set channel mask to remove channels not allowed in this device
588589
for (uint8_t n = 0; n < 8; n++) {
589590
fhss_configuration->unicast_channel_mask[n] &= cur->ws_info->cfg->fhss.fhss_channel_mask[n];
@@ -600,12 +601,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
600601
if (!fhss_api) {
601602
// When FHSS doesn't exist yet, create one
602603
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
603-
604-
fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->cfg->fhss.fhss_uc_dwell_interval;
605-
fhss_configuration.ws_uc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_uc_channel_function;
606-
fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_bc_channel_function;
607-
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->cfg->fhss.fhss_bc_dwell_interval;
608-
fhss_configuration.fhss_broadcast_interval = cur->ws_info->cfg->fhss.fhss_bc_interval;
604+
ws_fhss_set_defaults(cur, &fhss_configuration);
609605
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
610606

611607
if (!fhss_api) {
@@ -615,26 +611,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
615611
// Allow transmitting unicast frames only on TX slots in normal and expedited forwarding mode
616612
ns_fhss_ws_set_tx_allowance_level(fhss_api, WS_TX_SLOT, WS_TX_SLOT);
617613
} else {
618-
// Read defaults from the configuration to help FHSS testing
619-
const fhss_ws_configuration_t *fhss_configuration_copy = ns_fhss_ws_configuration_get(fhss_api);
620-
if (!fhss_configuration_copy) {
621-
// no configuration set yet
622-
return 0;
623-
}
624-
fhss_configuration = *fhss_configuration_copy;
625-
//Overwrite domain channel setup this will over write a default 35 channel
626-
int num_of_channels = channel_list_count_channels(fhss_configuration_copy->unicast_channel_mask);
627-
cur->ws_info->hopping_schdule.number_of_channels = (uint8_t) num_of_channels;
628-
memcpy(cur->ws_info->cfg->fhss.fhss_channel_mask, fhss_configuration_copy->unicast_channel_mask, sizeof(uint32_t) * 8);
629-
cur->ws_info->cfg->fhss.fhss_uc_channel_function = fhss_configuration_copy->ws_uc_channel_function;
630-
cur->ws_info->cfg->fhss.fhss_bc_channel_function = fhss_configuration_copy->ws_bc_channel_function;
631-
cur->ws_info->cfg->fhss.fhss_bc_dwell_interval = fhss_configuration_copy->fhss_bc_dwell_interval;
632-
cur->ws_info->cfg->fhss.fhss_bc_interval = fhss_configuration_copy->fhss_broadcast_interval;
633-
cur->ws_info->cfg->fhss.fhss_uc_dwell_interval = fhss_configuration_copy->fhss_uc_dwell_interval;
634-
cur->ws_info->cfg->fhss.fhss_bc_fixed_channel = fhss_configuration_copy->broadcast_fixed_channel;
635-
cur->ws_info->cfg->fhss.fhss_uc_fixed_channel = fhss_configuration_copy->unicast_fixed_channel;
636-
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
637-
ns_fhss_ws_configuration_set(fhss_api, &fhss_configuration);
614+
return -1;
638615
}
639616

640617
return 0;
@@ -677,14 +654,10 @@ uint16_t ws_randomize_fixed_channel(uint16_t configured_fixed_channel, uint8_t n
677654
int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery)
678655
{
679656
// Read configuration of existing FHSS and start using the default values for any network
680-
fhss_ws_configuration_t fhss_configuration;
681-
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
657+
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
658+
ws_fhss_set_defaults(cur, &fhss_configuration);
659+
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
682660

683-
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
684-
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
685-
ws_fhss_set_defaults(cur, &fhss_configuration);
686-
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
687-
}
688661
// Discovery is done using fixed channel
689662
if (discovery) {
690663
fhss_configuration.ws_uc_channel_function = WS_FIXED_CHANNEL;
@@ -706,13 +679,10 @@ int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery)
706679

707680
static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
708681
{
709-
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(cur->ws_info->fhss_api);
682+
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
710683

711-
if (!cur->ws_info->fhss_api || !fhss_configuration) {
712-
return -1;
713-
}
714684
// Set the LLC information to follow the actual fhss settings
715-
ws_bootstrap_llc_hopping_update(cur, fhss_configuration);
685+
ws_bootstrap_llc_hopping_update(cur, &fhss_configuration);
716686

717687
// Set neighbor info callback
718688
if (ns_fhss_set_neighbor_info_fp(cur->ws_info->fhss_api, &ws_get_neighbor_info)) {
@@ -729,14 +699,12 @@ static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
729699
*/
730700
void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry *cur, llc_neighbour_req_t *neighbor_info, ws_parent_synch_e synch_req)
731701
{
732-
733-
fhss_ws_configuration_t fhss_configuration;
734702
if (!neighbor_info->ws_neighbor->broadcast_timing_info_stored) {
735703
tr_error("No BC timing info for set new parent");
736704
return;
737705
}
738706

739-
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
707+
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
740708

741709
// Learning broadcast network configuration
742710
if (neighbor_info->ws_neighbor->broadcast_shedule_info_stored) {
@@ -1871,7 +1839,7 @@ int ws_bootstrap_restart_delayed(int8_t interface_id)
18711839

18721840
static int8_t ws_bootstrap_phy_mode_resolver(const mac_api_t *api, uint8_t phy_mode_id, phy_rf_channel_configuration_s *rf_config)
18731841
{
1874-
rf_config->modulation = ws_get_modulation_using_phy_mode_id(phy_mode_id);
1842+
rf_config->modulation = ws_phy_get_modulation_using_phy_mode_id(phy_mode_id);
18751843
if (rf_config->modulation == M_UNDEFINED) {
18761844
return -1;
18771845
}
@@ -1882,28 +1850,28 @@ static int8_t ws_bootstrap_phy_mode_resolver(const mac_api_t *api, uint8_t phy_m
18821850
uint8_t regulatory_domain = interface->ws_info->hopping_schdule.regulatory_domain;
18831851
uint8_t base_channel_plan_id = interface->ws_info->hopping_schdule.channel_plan_id;
18841852
if (base_channel_plan_id == 255) {
1885-
base_channel_plan_id = ws_convert_operating_class_to_channel_plan_id(interface->ws_info->hopping_schdule.operating_class, regulatory_domain);
1853+
base_channel_plan_id = ws_phy_convert_operating_class_to_channel_plan_id(interface->ws_info->hopping_schdule.operating_class, regulatory_domain);
18861854
}
18871855
if (!base_channel_plan_id) {
18881856
return -1;
18891857
}
18901858
// Function returns base channel plan ID, if it matches the PHY mode ID. Otherwise, nearest matching channel plan ID where PHY mode ID is allowed will be returned.
1891-
uint8_t channel_plan_id = ws_get_channel_plan_id_using_phy_mode_id(phy_mode_id, regulatory_domain, base_channel_plan_id);
1859+
uint8_t channel_plan_id = ws_phy_get_channel_plan_id_using_phy_mode_id(phy_mode_id, regulatory_domain, base_channel_plan_id);
18921860
if (!channel_plan_id) {
18931861
return -1;
18941862
}
18951863

1896-
rf_config->channel_0_center_frequency = ws_get_channel_0_frequency_using_channel_plan_id(channel_plan_id);
1897-
rf_config->channel_spacing = ws_get_channel_spacing_using_channel_plan_id(channel_plan_id);
1898-
rf_config->number_of_channels = ws_get_number_of_channels_using_channel_plan_id(channel_plan_id);
1899-
rf_config->datarate = ws_get_datarate_using_phy_mode_id(phy_mode_id);
1864+
rf_config->channel_0_center_frequency = ws_phy_get_channel_0_frequency_using_channel_plan_id(channel_plan_id);
1865+
rf_config->channel_spacing = ws_phy_get_channel_spacing_using_channel_plan_id(channel_plan_id);
1866+
rf_config->number_of_channels = ws_phy_get_number_of_channels_using_channel_plan_id(channel_plan_id);
1867+
rf_config->datarate = ws_phy_get_datarate_using_phy_mode_id(phy_mode_id);
19001868
if (!rf_config->channel_0_center_frequency || !rf_config->channel_spacing || !rf_config->number_of_channels || !rf_config->datarate) {
19011869
return -1;
19021870
}
1903-
rf_config->ofdm_option = ws_get_ofdm_option_using_phy_mode_id(phy_mode_id);
1904-
rf_config->ofdm_mcs = ws_get_ofdm_mcs_using_phy_mode_id(phy_mode_id);
1905-
rf_config->fec = ws_get_fsk_fec_enabled_using_phy_mode_id(phy_mode_id);
1906-
rf_config->modulation_index = ws_get_modulation_index_using_phy_mode_id(phy_mode_id);
1871+
rf_config->ofdm_option = ws_phy_get_ofdm_option_using_phy_mode_id(phy_mode_id);
1872+
rf_config->ofdm_mcs = ws_phy_get_ofdm_mcs_using_phy_mode_id(phy_mode_id);
1873+
rf_config->fec = ws_phy_get_fsk_fec_enabled_using_phy_mode_id(phy_mode_id);
1874+
rf_config->modulation_index = ws_phy_get_modulation_index_using_phy_mode_id(phy_mode_id);
19071875
return 0;
19081876
}
19091877

@@ -1942,7 +1910,7 @@ static int ws_bootstrap_set_rf_config(protocol_interface_info_entry_t *cur, phy_
19421910
// Enable MAC mode switch when base PHY mode ID could be found, otherwise disable the feature
19431911
uint8_t phy_mode_id = cur->ws_info->hopping_schdule.phy_mode_id;
19441912
if (phy_mode_id == 255) {
1945-
phy_mode_id = ws_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
1913+
phy_mode_id = ws_phy_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
19461914
}
19471915
if (!phy_mode_id) {
19481916
cur->mac_api->mac_mode_switch_resolver_set(cur->mac_api, NULL, phy_mode_id);
@@ -1974,10 +1942,10 @@ static int ws_bootstrap_operating_mode_resolver(protocol_interface_info_entry_t
19741942
memset(rf_config, 0, sizeof(phy_rf_channel_configuration_s));
19751943
rf_config->fec = false;
19761944
rf_config->modulation = M_2FSK;
1977-
rf_config->datarate = ws_get_datarate_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
1978-
rf_config->modulation_index = ws_get_modulation_index_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
1945+
rf_config->datarate = ws_phy_get_datarate_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
1946+
rf_config->modulation_index = ws_phy_get_modulation_index_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
19791947
rf_config->channel_0_center_frequency = (uint32_t)cur->ws_info->hopping_schdule.ch0_freq * 100000;
1980-
rf_config->channel_spacing = ws_decode_channel_spacing(cur->ws_info->hopping_schdule.channel_spacing);
1948+
rf_config->channel_spacing = ws_phy_decode_channel_spacing(cur->ws_info->hopping_schdule.channel_spacing);
19811949
rf_config->number_of_channels = cur->ws_info->hopping_schdule.number_of_channels;
19821950
return 0;
19831951
}
@@ -1989,7 +1957,7 @@ int ws_bootstrap_set_domain_rf_config(protocol_interface_info_entry_t *cur)
19891957

19901958
uint8_t phy_mode_id = cur->ws_info->hopping_schdule.phy_mode_id;
19911959
if (phy_mode_id == 255) {
1992-
phy_mode_id = ws_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
1960+
phy_mode_id = ws_phy_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
19931961
}
19941962

19951963
if (!phy_mode_id || ws_bootstrap_phy_mode_resolver(cur->mac_api, phy_mode_id, &rf_config)) {
@@ -2963,7 +2931,7 @@ static void ws_set_asynch_channel_list(protocol_interface_info_entry_t *cur, asy
29632931
uint16_t channel_number = cur->ws_info->cfg->fhss.fhss_uc_fixed_channel;
29642932
async_req->channel_list.channel_mask[channel_number / 32] = 1U << (channel_number % 32);
29652933
} else {
2966-
ws_generate_channel_list(async_req->channel_list.channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
2934+
ws_common_generate_channel_list(async_req->channel_list.channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
29672935
}
29682936

29692937
async_req->channel_list.channel_page = CHANNEL_PAGE_10;

source/6LoWPAN/ws/ws_bootstrap_6lbr.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@
8888
static int8_t ws_bootstrap_6lbr_fhss_configure(protocol_interface_info_entry_t *cur)
8989
{
9090
// Read configuration of existing FHSS and start using the default values for any network
91-
fhss_ws_configuration_t fhss_configuration;
92-
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
93-
94-
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
95-
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
96-
}
97-
91+
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
9892
//GET BSI from BBR module
9993
fhss_configuration.bsi = ws_bbr_bsi_generate(cur);
10094
ws_fhss_configure_channel_masks(cur, &fhss_configuration);

0 commit comments

Comments
 (0)