Skip to content

Commit

Permalink
Iotthd 3995 (ARMmbed#2347)
Browse files Browse the repository at this point in the history
* FHSS WS: Created test api for setting number of channel retries

* FHSS WS: API to configure channel retries

* Compiler warning if max frame retries is too low
  • Loading branch information
Jarkko Paso authored Apr 23, 2020
1 parent e2ea4e4 commit d092f83
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
13 changes: 13 additions & 0 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ typedef struct fhss_configuration {
*/
typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uint8_t eui64[8], uint16_t bsi, uint16_t number_of_channels);

/**
* \brief Struct fhss_config_parameters defines FHSS configuration parameters.
*
*/
typedef struct fhss_config_parameters {
/** Number of channel retries defines how many consecutive channels are used when retransmitting a frame after initial transmission channel. */
uint8_t number_of_channel_retries;
} fhss_config_parameters_t;


/**
* \brief Struct fhss_ws_configuration defines configuration of WS FHSS.
*/
Expand Down Expand Up @@ -125,6 +135,9 @@ typedef struct fhss_ws_configuration {
/** Vendor defined channel function. */
fhss_vendor_defined_cf *vendor_defined_cf;

/** Configuration parameters. */
fhss_config_parameters_t config_parameters;

} fhss_ws_configuration_t;

/**
Expand Down
11 changes: 11 additions & 0 deletions nanostack/fhss_test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ extern "C" {
*/
int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packet_length);

/**
* \brief Set number of channel retries
*
* \param fhss_api FHSS instance.
* \param number_of_channel_retries Number of channel retries
*
* \return 0 Success
* \return -1 Failure
*/
int8_t fhss_set_number_of_channel_retries(const fhss_api_t *fhss_api, uint8_t number_of_channel_retries);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_bc_channel_function;
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->cfg->fhss.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->cfg->fhss.fhss_bc_interval;
fhss_configuration.config_parameters.number_of_channel_retries = WS_NUMBER_OF_CHANNEL_RETRIES;
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);

if (!fhss_api) {
Expand Down Expand Up @@ -1957,6 +1958,8 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
set_req.value_size = sizeof(bool);
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);

mac_helper_mac_mlme_max_retry_set(cur->id, WS_MAX_FRAME_RETRIES);

// Set the default parameters for MPL
cur->mpl_proactive_forwarding = true;

Expand Down
20 changes: 20 additions & 0 deletions source/6LoWPAN/ws/ws_common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ typedef struct ws_bs_ie {
*/
#define WS_TACK_MAX_MS 5


/* WS requires at least 19 MAC retransmissions (total 1+19=20 attempts). Default 802.15.4 macMaxFrameRetries is 3 (total 1+3=4 attempts).
* At least 4 channel retries must be used: (Initial channel + WS_NUMBER_OF_CHANNEL_RETRIES) * MAC attempts = (1+4)*4=20 attempts
*
* Valid settings could be for example:
* WS_MAX_FRAME_RETRIES WS_NUMBER_OF_CHANNEL_RETRIES Total attempts
* 0 19 1+0*1+19=20
* 1 9 1+1*1+9=20
* 2 6 1+2*1+6=21
* 3 4 1+3*1+4=20
*
*/
#define WS_MAX_FRAME_RETRIES 3
#define WS_NUMBER_OF_CHANNEL_RETRIES 4


#if (1 + WS_MAX_FRAME_RETRIES) * (1 + WS_NUMBER_OF_CHANNEL_RETRIES) < 20
#warning "MAX frame retries set too low"
#endif

/*
* Config new version consistent filter period in 100ms periods
*/
Expand Down
15 changes: 15 additions & 0 deletions source/Service_Libs/fhss/fhss_test_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packe
#endif
return 0;
}

int8_t fhss_set_number_of_channel_retries(const fhss_api_t *fhss_api, uint8_t number_of_channel_retries)
{
(void) fhss_api;
(void) number_of_channel_retries;
#ifdef HAVE_WS
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure || !fhss_structure->ws) {
return -1;
}
fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries = number_of_channel_retries;
tr_debug("Setting number of channel retries to: %u", number_of_channel_retries);
#endif
return 0;
}
8 changes: 5 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,18 @@ static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle,
if (fhss_structure->fhss_state == FHSS_UNSYNCHRONIZED) {
return false;
}

// Use channel retries only for data frames
if (FHSS_DATA_FRAME != frame_type) {
return false;
}

// Channel retries are disabled
if (!fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries) {
return false;
}
fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle);
if (fhss_failed_tx) {
fhss_failed_tx->retries_done++;
if (fhss_failed_tx->retries_done >= WS_NUMBER_OF_CHANNEL_RETRIES) {
if (fhss_failed_tx->retries_done >= fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries) {
// No more retries. Return false to stop retransmitting.
fhss_failed_handle_remove(fhss_structure, handle);
return false;
Expand Down
4 changes: 0 additions & 4 deletions source/Service_Libs/fhss/fhss_ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#ifndef FHSS_WS_H_
#define FHSS_WS_H_

/* WS requires at least 19 MAC retransmissions (total 1+19=20 attempts). 802.15.4 macMaxFrameRetries is 3 (total 1+3=4 attempts).
* At least 4 channel retries must be used: (Initial channel + WS_NUMBER_OF_CHANNEL_RETRIES) * MAC attempts = (1+4)*4=20 attempts
*/
#define WS_NUMBER_OF_CHANNEL_RETRIES 4
// TX slot length is optimised to this packet length
#define OPTIMAL_PACKET_LENGTH 500
// Default TX/RX slot length in milliseconds. Is used when datarate is not given by PHY.
Expand Down

0 comments on commit d092f83

Please sign in to comment.