From db6dc6bb34a8fd584f9adcfdaa2a42d998cf1d13 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Tue, 18 Sep 2018 14:09:10 +0300 Subject: [PATCH 1/5] MAC: Fixed enhanced ack TX time --- source/MAC/IEEE802_15_4/mac_mcps_sap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/MAC/IEEE802_15_4/mac_mcps_sap.c b/source/MAC/IEEE802_15_4/mac_mcps_sap.c index 862d70fe6fa..1c4a6322895 100644 --- a/source/MAC/IEEE802_15_4/mac_mcps_sap.c +++ b/source/MAC/IEEE802_15_4/mac_mcps_sap.c @@ -1736,7 +1736,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m tx_buf->len = frame_length; uint8_t *mhr_start = ptr; - buffer->tx_time = rx_time + 196; //Send 196 us later + buffer->tx_time = mac_mcps_sap_get_phy_timestamp(rf_ptr) + 300; //Send 300 us later ptr = mac_generic_packet_write(rf_ptr, ptr, buffer); From a35b702e480e5e8630cba54105a9ebb1792af177 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 20 Sep 2018 11:26:23 +0300 Subject: [PATCH 2/5] FHSS: Increased min random of tx poll Because of bad synchronization, unicast packet was sent immediately after broadcast channel when receiver had not yet changed to unicast. --- source/Service_Libs/fhss/fhss_ws.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 66b17c20b6e..d5aa4fc67c2 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -163,12 +163,12 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay) // Should return to own (unicast) listening channel after broadcast channel next_channel = fhss_structure->rx_channel; /* Start timer with random timeout to trigger unicast TX queue poll event. - * Min random is 50us. + * Min random is 1/30 of the TX slot length. * Max random is 1/10 of the TX slot length. * Event timer resolution is 50us. */ uint32_t txrx_slot_length_us = fhss_structure->ws->txrx_slot_length_ms * 1000; - uint16_t uc_min_random = 1; + uint16_t uc_min_random = (txrx_slot_length_us / 30) / 50; uint16_t uc_max_random = (txrx_slot_length_us / 10) / 50; bool tx_allowed = fhss_ws_check_tx_allowed(fhss_structure); if (!tx_allowed) { From 308240790153d77df44409463dec4eb816bb2d93 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Fri, 28 Sep 2018 11:03:50 +0300 Subject: [PATCH 3/5] FHSS: implemented divide function --- source/Service_Libs/fhss/fhss_ws.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index d5aa4fc67c2..76ccdac9600 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -64,6 +64,12 @@ static void fhss_unicast_handler(const fhss_api_t *fhss_api, uint16_t delay); static bool fhss_ws_check_tx_allowed(fhss_structure_t *fhss_structure); static uint8_t fhss_set_txrx_slot_length(fhss_structure_t *fhss_structure); +// This function supports rounding up +static uint32_t divide_integer(uint32_t dividend, uint32_t divisor) +{ + return (dividend + divisor/2) / divisor; +} + fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer) { if (!fhss_api || !fhss_configuration || !fhss_timer) { @@ -253,14 +259,14 @@ static uint32_t fhss_ws_calculate_broadcast_interval_offset(fhss_structure_t *fh uint8_t dwell_time = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval; uint32_t broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval; - uint32_t remaining_time = (fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api) / 1000); + uint32_t remaining_time = divide_integer(fhss_structure->platform_functions.fhss_get_remaining_slots(fhss_broadcast_handler, fhss_structure->fhss_api), 1000); if (fhss_structure->ws->is_on_bc_channel == true) { remaining_time += (broadcast_interval - dwell_time); } uint32_t time_to_tx = 0; uint32_t cur_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api); if (cur_time < tx_time) { - time_to_tx = (tx_time - cur_time) / 1000; + time_to_tx = divide_integer(tx_time - cur_time, 1000); } return (broadcast_interval-remaining_time) + time_to_tx; } @@ -668,7 +674,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], } platform_enter_critical(); fhss_stop_timer(fhss_structure, fhss_broadcast_handler); - uint32_t time_from_reception_ms = (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000; + uint32_t time_from_reception_ms = divide_integer(fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp, 1000); uint32_t true_bc_interval_offset = (bc_timing_info->broadcast_interval_offset + time_from_reception_ms) % bc_timing_info->broadcast_interval; uint32_t timeout = ((bc_timing_info->broadcast_interval-true_bc_interval_offset)*1000); From f17e6cd23d198d7c88bde5fc6a95db067b587a4b Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Fri, 28 Sep 2018 11:52:44 +0300 Subject: [PATCH 4/5] FHSS: Check TX/RX slot in tx handle --- source/Service_Libs/fhss/fhss_ws.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 76ccdac9600..3d9d479fd75 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -368,6 +368,10 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a if (is_broadcast_addr || (fhss_structure->ws->is_on_bc_channel == true)) { return 0; } + // Check TX/RX slot + if (!fhss_ws_check_tx_allowed(fhss_structure)) { + return -1; + } if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) { fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->get_neighbor_info(api, destination_address); if (!neighbor_timing_info) { From 5ddf5fa890ac73f5481fa939c264e56fae9ab986 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Fri, 28 Sep 2018 12:58:19 +0300 Subject: [PATCH 5/5] FHSS: prevent unicast on broadcast channel in tx handle --- source/Service_Libs/fhss/fhss_ws.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 3d9d479fd75..211f4768944 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -365,9 +365,13 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a if (!fhss_structure) { return -1; } - if (is_broadcast_addr || (fhss_structure->ws->is_on_bc_channel == true)) { + if (is_broadcast_addr) { return 0; } + // Do not allow unicast destination on broadcast channel + if (!is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == true)) { + return -1; + } // Check TX/RX slot if (!fhss_ws_check_tx_allowed(fhss_structure)) { return -1;