diff --git a/source/MAC/IEEE802_15_4/mac_mcps_sap.c b/source/MAC/IEEE802_15_4/mac_mcps_sap.c index 07a9e65da18..b62fead6746 100644 --- a/source/MAC/IEEE802_15_4/mac_mcps_sap.c +++ b/source/MAC/IEEE802_15_4/mac_mcps_sap.c @@ -1395,6 +1395,15 @@ static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setu } +static uint32_t mcps_generic_backoff_calc(protocol_interface_rf_mac_setup_s *rf_ptr) +{ + uint32_t random_period = mac_csma_backoff_get(rf_ptr); + if (rf_ptr->fhss_api) { + return mcps_calculate_tx_time(rf_ptr, random_period); + } + return random_period; +} + static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_ptr, mac_pre_build_frame_t *buffer) { phy_device_driver_s *dev_driver = rf_ptr->dev_driver->phy_driver; @@ -1411,6 +1420,7 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt tx_buf->len = buffer->mac_payload_length; memcpy(ptr, buffer->mac_payload, buffer->mac_payload_length ); + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); return 0; } @@ -1466,13 +1476,7 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt tx_buf->len = frame_length; uint8_t *mhr_start = ptr; - - uint32_t random_period = mac_csma_backoff_get(rf_ptr); - if (rf_ptr->fhss_api) { - buffer->tx_time = mcps_calculate_tx_time(rf_ptr, random_period); - } else { - buffer->tx_time = random_period; - } + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); ptr = mac_generic_packet_write(rf_ptr, ptr, buffer); @@ -1506,6 +1510,7 @@ static int8_t mcps_generic_packet_rebuild(protocol_interface_rf_mac_setup_s *rf_ tx_buf->len = buffer->mac_payload_length; memcpy(ptr, buffer->mac_payload, buffer->mac_payload_length ); + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); return 0; } @@ -1533,12 +1538,8 @@ static int8_t mcps_generic_packet_rebuild(protocol_interface_rf_mac_setup_s *rf_ tx_buf->len = frame_length; uint8_t *mhr_start = ptr; - uint32_t random_period = mac_csma_backoff_get(rf_ptr); - if (rf_ptr->fhss_api) { - buffer->tx_time = mcps_calculate_tx_time(rf_ptr, random_period); - } else { - buffer->tx_time = random_period; - } + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); + ptr = mac_generic_packet_write(rf_ptr, ptr, buffer); if (buffer->fcf_dsn.securityEnabled) {