diff --git a/src/src/radio.c b/src/src/radio.c index 4f42e9cd..2cd7c6b8 100644 --- a/src/src/radio.c +++ b/src/src/radio.c @@ -557,6 +557,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) if (aFrame->mInfo.mTxInfo.mCsmaCaEnabled) { + nrf_802154_max_num_csma_ca_backoffs_set(aFrame->mInfo.mTxInfo.mMaxCsmaBackoffs); nrf_802154_transmit_csma_ca_raw(&aFrame->mPsdu[-1]); } else diff --git a/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.c b/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.c index d8a55841..8e1502cc 100644 --- a/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.c +++ b/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.c @@ -53,6 +53,7 @@ static uint8_t m_nb; ///< The number of times the CSMA-CA algorithm was required to back off while attempting the current transmission. static uint8_t m_be; ///< Backoff exponent, which is related to how many backoff periods a device shall wait before attempting to assess a channel. +static uint8_t m_max_nb = NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS; ///< The maximum number of backoffs that the CSMA-CA algorithm will attempt before declaring a channel access failure. static const uint8_t * mp_data; ///< Pointer to a buffer containing PHR and PSDU of the frame being transmitted. static nrf_802154_timer_t m_timer; ///< Timer used to back off during CSMA-CA procedure. @@ -96,7 +97,7 @@ static void procedure_stop(void) */ static void notify_busy_channel(bool result) { - if (!result && (m_nb >= (NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS - 1))) + if (!result && ((m_max_nb == 0) || (m_nb >= (m_max_nb - 1)))) { nrf_802154_notify_transmit_failed(mp_data, NRF_802154_TX_ERROR_BUSY_CHANNEL); } @@ -163,7 +164,7 @@ static bool channel_busy(void) m_be++; } - if (m_nb < NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS) + if (m_nb < m_max_nb) { random_backoff_start(); result = false; @@ -179,6 +180,11 @@ static bool channel_busy(void) return result; } +void nrf_802154_csma_ca_max_num_csma_ca_backoffs_set(uint8_t max_num_nb) +{ + m_max_nb = max_num_nb; +} + void nrf_802154_csma_ca_start(const uint8_t * p_data) { assert(!procedure_is_running()); diff --git a/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.h b/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.h index 58df07c9..fc70d0d6 100644 --- a/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.h +++ b/third_party/NordicSemiconductor/drivers/radio/mac_features/nrf_802154_csma_ca.h @@ -44,6 +44,15 @@ * @brief CSMA-CA procedure. */ +/** + * @brief Sets the maximum number of backoffs that the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * @note If the @p max_num_nb is set to 0, the CSMA-CA algorithm will attempt one time before declaring a channel access failure. + * + * @param[in] max_num_nb The maximum number of CSMA-CA backoffs . + */ +void nrf_802154_csma_ca_max_num_csma_ca_backoffs_set(uint8_t max_num_nb); + /** * @brief Starts the CSMA-CA procedure for the transmission of a given frame. * diff --git a/third_party/NordicSemiconductor/drivers/radio/nrf_802154.c b/third_party/NordicSemiconductor/drivers/radio/nrf_802154.c index d61f6f35..46218755 100644 --- a/third_party/NordicSemiconductor/drivers/radio/nrf_802154.c +++ b/third_party/NordicSemiconductor/drivers/radio/nrf_802154.c @@ -661,6 +661,11 @@ void nrf_802154_cca_cfg_get(nrf_802154_cca_cfg_t * p_cca_cfg) } #if NRF_802154_CSMA_CA_ENABLED +void nrf_802154_max_num_csma_ca_backoffs_set(uint8_t max_num_nb) +{ + nrf_802154_csma_ca_max_num_csma_ca_backoffs_set(max_num_nb); +} + #if NRF_802154_USE_RAW_API void nrf_802154_transmit_csma_ca_raw(const uint8_t * p_data) diff --git a/third_party/NordicSemiconductor/drivers/radio/nrf_802154.h b/third_party/NordicSemiconductor/drivers/radio/nrf_802154.h index 56be11b8..135fe08e 100644 --- a/third_party/NordicSemiconductor/drivers/radio/nrf_802154.h +++ b/third_party/NordicSemiconductor/drivers/radio/nrf_802154.h @@ -1174,6 +1174,16 @@ void nrf_802154_cca_cfg_get(nrf_802154_cca_cfg_t * p_cca_cfg); * @{ */ #if NRF_802154_CSMA_CA_ENABLED + +/** + * @brief Sets the maximum number of backoffs that the CSMA-CA algorithm will attempt before declaring a channel access failure. + * + * @note If the @p max_num_nb is set to 0, the CSMA-CA algorithm will attempt one time before declaring a channel access failure. + * + * @param[in] max_num_nb The maximum number of CSMA-CA backoffs . + */ +void nrf_802154_max_num_csma_ca_backoffs_set(uint8_t max_num_nb); + #if NRF_802154_USE_RAW_API /**