Skip to content

Commit bc4f46f

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1656 from ARMmbed/IOTTHD-2441
FHSS: Added random timeout before polling TX queue after channel change
2 parents b6e40af + 7f94971 commit bc4f46f

File tree

2 files changed

+25
-6
lines changed
  • source/Service_Libs/fhss
  • test/nanostack/unittest/service_libs/fhss_ws

2 files changed

+25
-6
lines changed

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "fhss_ws.h"
2626
#include "nsdynmemLIB.h"
2727
#include "common_functions.h"
28+
#include "eventOS_callback_timer.h"
29+
#include "randLIB.h"
2830
#include "ns_trace.h"
2931
#include <string.h>
3032

@@ -48,6 +50,7 @@ struct ws_ie_t {
4850

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

5255
fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer)
5356
{
@@ -124,10 +127,8 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
124127
#endif /*FHSS_CHANNEL_DEBUG*/
125128
}
126129
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
127-
if (fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, true)) {
128-
// TODO: Randomize polling TX queue when on broadcast channel
129-
fhss_structure->callbacks.tx_poll(fhss_structure->fhss_api);
130-
}
130+
fhss_ws_start_tx_poll_timer(fhss_structure, fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, true),
131+
fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval);
131132
}
132133

133134
static int own_floor(float value)
@@ -454,9 +455,24 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay)
454455
timeout = fhss_ws_get_sf_timeout_callback(fhss_structure);
455456
fhss_start_timer(fhss_structure, timeout - (delay * fhss_structure->platform_functions.fhss_resolution_divider), fhss_unicast_handler);
456457
fhss_ws_update_uc_channel_callback(fhss_structure);
457-
if (fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, false)) {
458-
fhss_structure->callbacks.tx_poll(fhss_structure->fhss_api);
458+
fhss_ws_start_tx_poll_timer(fhss_structure, fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, false),
459+
fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval);
460+
}
461+
462+
static void fhss_ws_start_tx_poll_timer(fhss_structure_t *fhss_structure, uint16_t queue_size, uint8_t channel_dwell_interval)
463+
{
464+
if (!queue_size) {
465+
return;
459466
}
467+
/* Start timer with random timeout to trigger TX queue poll event.
468+
* Min random is 1/50 of the channel dwell interval.
469+
* Max random is 1/10 of the channel dwell interval.
470+
* Event timer resolution is 50us.
471+
* Divide random with TX queue size to transmit faster when TX queue is growing
472+
*/
473+
uint16_t min_random = ((((uint32_t)channel_dwell_interval * 1000) / 50) / 50) / queue_size;
474+
uint16_t max_random = ((((uint32_t)channel_dwell_interval * 1000) / 10) / 50) / queue_size;
475+
eventOS_callback_timer_start(fhss_structure->fhss_event_timer, randLIB_get_random_in_range(min_random, max_random));
460476
}
461477

462478
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)

test/nanostack/unittest/service_libs/fhss_ws/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ TEST_SRC_FILES = \
1616
../../stub/ns_list_stub.c \
1717
../../stub/channel_list_stub.c \
1818
../../stub/channel_functions_stub.c \
19+
../../stub/ns_timer_stub.c \
20+
../../stub/randLIB_stub.c \
21+
../../stub/event_stub.c \
1922
../../stub/fhss_stub.c \
2023
../../stub/fhss_common_stub.c \
2124
../../stub/fhss_callbacks_stub.c \

0 commit comments

Comments
 (0)