From 9c78a9590116cb97e3b6b8e52322c22d5ebc3d74 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Mon, 17 Sep 2018 13:18:16 +0300 Subject: [PATCH] MAC: Static CSMA period when using FHSS This will prevent the synchronization error when too short CSMA random used. --- source/MAC/IEEE802_15_4/mac_pd_sap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/MAC/IEEE802_15_4/mac_pd_sap.c b/source/MAC/IEEE802_15_4/mac_pd_sap.c index e4c887c05ac..1b0b57cb278 100644 --- a/source/MAC/IEEE802_15_4/mac_pd_sap.c +++ b/source/MAC/IEEE802_15_4/mac_pd_sap.c @@ -38,6 +38,10 @@ /* Define TX Timeot Period */ // Hardcoded to 1200ms. Should be changed dynamic: (FHSS) channel retries needs longer timeout #define NWKTX_TIMEOUT_PERIOD (1200*20) +// Measured 3750us with 1280 byte secured packet from calculating TX time to starting CSMA timer on PHY. +// Typically varies from 500us to several milliseconds depending on packet size and the platform. +// MAC should learn and make this dynamic by sending first few packets with predefined CSMA period. +#define MIN_FHSS_CSMA_PERIOD_US 4000 static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *rf_ptr, phy_link_tx_status_e status, uint8_t cca_retry, uint8_t tx_retry); static void mac_sap_cca_fail_cb(protocol_interface_rf_mac_setup_s *rf_ptr); @@ -91,6 +95,13 @@ uint32_t mac_csma_backoff_get(protocol_interface_rf_mac_setup_s *rf_mac_setup) if (backoff_in_us == 0) { backoff_in_us = 1; } + if (rf_mac_setup->fhss_api) { + // Synchronization error when backoff time is shorter than allowed. + // TODO: Make this dynamic. + if (backoff_in_us < MIN_FHSS_CSMA_PERIOD_US) { + backoff_in_us += MIN_FHSS_CSMA_PERIOD_US; + } + } return backoff_in_us; }