Skip to content

Commit

Permalink
[radio] add 'mInfo.mTxInfo.mMaxCsmaBackoffs' support
Browse files Browse the repository at this point in the history
Current radio driver doesn't process the 'mInfo.mTxInfo.mMaxCsmaBackoffs'
field of the tx frame. The maximum number of CSMA-CA backoffs is set to
the fixed value 4.

This commit sets the maximum number of CSMA-CA backoffs to
`mInfo.mTxInfo.mMaxCsmaBackoffs`.
  • Loading branch information
zhanglongxia committed Jan 3, 2025
1 parent 08c7763 commit 96d5521
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/src/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 5 additions & 0 deletions third_party/NordicSemiconductor/drivers/radio/nrf_802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions third_party/NordicSemiconductor/drivers/radio/nrf_802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit 96d5521

Please sign in to comment.