Skip to content

Commit

Permalink
FHSS: Added random timeout before polling TX queue after channel change
Browse files Browse the repository at this point in the history
- Timeout length depends on number of packets in TX queue to allow more rapid transmissions when needed
  • Loading branch information
Jarkko Paso committed Apr 17, 2018
1 parent b6e40af commit 7f94971
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
28 changes: 22 additions & 6 deletions source/Service_Libs/fhss/fhss_ws.c
Expand Up @@ -25,6 +25,8 @@
#include "fhss_ws.h"
#include "nsdynmemLIB.h"
#include "common_functions.h"
#include "eventOS_callback_timer.h"
#include "randLIB.h"
#include "ns_trace.h"
#include <string.h>

Expand All @@ -48,6 +50,7 @@ struct ws_ie_t {

static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure);
static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay);
static void fhss_ws_start_tx_poll_timer(fhss_structure_t *fhss_structure, uint16_t queue_size, uint8_t channel_dwell_interval);

fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer)
{
Expand Down Expand Up @@ -124,10 +127,8 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
#endif /*FHSS_CHANNEL_DEBUG*/
}
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
if (fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, true)) {
// TODO: Randomize polling TX queue when on broadcast channel
fhss_structure->callbacks.tx_poll(fhss_structure->fhss_api);
}
fhss_ws_start_tx_poll_timer(fhss_structure, fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, true),
fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval);
}

static int own_floor(float value)
Expand Down Expand Up @@ -454,9 +455,24 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay)
timeout = fhss_ws_get_sf_timeout_callback(fhss_structure);
fhss_start_timer(fhss_structure, timeout - (delay * fhss_structure->platform_functions.fhss_resolution_divider), fhss_unicast_handler);
fhss_ws_update_uc_channel_callback(fhss_structure);
if (fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, false)) {
fhss_structure->callbacks.tx_poll(fhss_structure->fhss_api);
fhss_ws_start_tx_poll_timer(fhss_structure, fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, false),
fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval);
}

static void fhss_ws_start_tx_poll_timer(fhss_structure_t *fhss_structure, uint16_t queue_size, uint8_t channel_dwell_interval)
{
if (!queue_size) {
return;
}
/* Start timer with random timeout to trigger TX queue poll event.
* Min random is 1/50 of the channel dwell interval.
* Max random is 1/10 of the channel dwell interval.
* Event timer resolution is 50us.
* Divide random with TX queue size to transmit faster when TX queue is growing
*/
uint16_t min_random = ((((uint32_t)channel_dwell_interval * 1000) / 50) / 50) / queue_size;
uint16_t max_random = ((((uint32_t)channel_dwell_interval * 1000) / 10) / 50) / queue_size;
eventOS_callback_timer_start(fhss_structure->fhss_event_timer, randLIB_get_random_in_range(min_random, max_random));
}

int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
Expand Down
3 changes: 3 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/Makefile
Expand Up @@ -16,6 +16,9 @@ TEST_SRC_FILES = \
../../stub/ns_list_stub.c \
../../stub/channel_list_stub.c \
../../stub/channel_functions_stub.c \
../../stub/ns_timer_stub.c \
../../stub/randLIB_stub.c \
../../stub/event_stub.c \
../../stub/fhss_stub.c \
../../stub/fhss_common_stub.c \
../../stub/fhss_callbacks_stub.c \
Expand Down

0 comments on commit 7f94971

Please sign in to comment.