Skip to content

Commit

Permalink
MAC: Static CSMA period when using FHSS
Browse files Browse the repository at this point in the history
This will prevent the synchronization error when too short CSMA random used.
  • Loading branch information
Jarkko Paso committed Sep 20, 2018
1 parent 708e8d3 commit 9c78a95
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9c78a95

Please sign in to comment.