Skip to content

Commit 9c78a95

Browse files
author
Jarkko Paso
committed
MAC: Static CSMA period when using FHSS
This will prevent the synchronization error when too short CSMA random used.
1 parent 708e8d3 commit 9c78a95

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
/* Define TX Timeot Period */
3939
// Hardcoded to 1200ms. Should be changed dynamic: (FHSS) channel retries needs longer timeout
4040
#define NWKTX_TIMEOUT_PERIOD (1200*20)
41+
// Measured 3750us with 1280 byte secured packet from calculating TX time to starting CSMA timer on PHY.
42+
// Typically varies from 500us to several milliseconds depending on packet size and the platform.
43+
// MAC should learn and make this dynamic by sending first few packets with predefined CSMA period.
44+
#define MIN_FHSS_CSMA_PERIOD_US 4000
4145

4246
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);
4347
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)
9195
if (backoff_in_us == 0) {
9296
backoff_in_us = 1;
9397
}
98+
if (rf_mac_setup->fhss_api) {
99+
// Synchronization error when backoff time is shorter than allowed.
100+
// TODO: Make this dynamic.
101+
if (backoff_in_us < MIN_FHSS_CSMA_PERIOD_US) {
102+
backoff_in_us += MIN_FHSS_CSMA_PERIOD_US;
103+
}
104+
}
94105
return backoff_in_us;
95106
}
96107

0 commit comments

Comments
 (0)