This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8fe7aa84267d5c29b72c619c2319096697437e5b Author: raiden00pl <[email protected]> AuthorDate: Fri Oct 16 16:07:41 2026 +0200 arch/arm/nrf52: follow the CSMA-CA algorithm IEEE 802.15.4-2011 5.1.1.4 (Figure 11): - NB counts up. It was decremented, wrapped from 0 to 255 and ended the algorithm with a channel access failure on the first busy CCA. - NB is zero and BE is macMinBE before each transmission attempt. A retransmission after a missing ACK kept the values of the previous attempt. - The random backoff is 0 to 2^BE - 1 backoff periods (also IEEE 802.15.4-2006 7.5.1.4), it was 0 to 2^BE - 2. The default macMaxCSMABackoffs is 4 (Table 52), the driver used 1. Assisted-by: Claude Code Signed-off-by: raiden00pl <[email protected]> --- arch/arm/src/nrf52/nrf52_ieee802154_radio.c | 10 ++++++---- arch/arm/src/nrf52/nrf52_ieee802154_radio.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/nrf52/nrf52_ieee802154_radio.c b/arch/arm/src/nrf52/nrf52_ieee802154_radio.c index 7f66d00e1ab..5202011e666 100644 --- a/arch/arm/src/nrf52/nrf52_ieee802154_radio.c +++ b/arch/arm/src/nrf52/nrf52_ieee802154_radio.c @@ -1003,7 +1003,7 @@ static void nrf52_radioi8_trg_csma(struct nrf52_radioi8_dev_s *dev) /* Get random unit backoff period delay */ - delay = rand() % ((1 << dev->radio->state.BE) - 1); + delay = rand() % (1 << dev->radio->state.BE); /* TODO: * - locate backoff period boundary @@ -1030,7 +1030,7 @@ static void nrf52_radioi8_trg_csma(struct nrf52_radioi8_dev_s *dev) /* Get random unit backoff period delay */ - delay = rand() % ((1 << dev->radio->state.BE) - 1); + delay = rand() % (1 << dev->radio->state.BE); } /* CSMA is in use */ @@ -1385,10 +1385,12 @@ static void nrf52_radioi8_work_noack(void *arg) NRF52_RADIO_PUTREG(lower, NRF52_RADIO_TASKS_DISABLE_OFFSET, 1); - /* Try again */ + /* Try again, CSMA-CA starts again for each attempt */ tx->retrycount -= 1; nrf52_radioi8_trace_put(RADIO_TRACE_TXRETRY, tx->retrycount); + dev->radio->state.NB = 0; + dev->radio->state.BE = dev->radio->state.min_be; nrf52_radioi8_norm_setup(dev, tx->frame, csma); nrf52_radioi8_norm_trigger(dev); } @@ -1871,7 +1873,7 @@ static void nrf52_radioi8_state_tx(struct nrf52_radioi8_dev_s *dev) { /* Update backoff */ - dev->radio->state.NB -= 1; + dev->radio->state.NB += 1; dev->radio->state.BE = MIN(dev->radio->state.BE + 1, dev->radio->state.max_be); diff --git a/arch/arm/src/nrf52/nrf52_ieee802154_radio.h b/arch/arm/src/nrf52/nrf52_ieee802154_radio.h index c64525300f0..f5d09166720 100644 --- a/arch/arm/src/nrf52/nrf52_ieee802154_radio.h +++ b/arch/arm/src/nrf52/nrf52_ieee802154_radio.h @@ -42,7 +42,7 @@ /* IEEE 802.15.4 constants */ #define IEEE802154_MAX_FRAME_WAITTIME (16 + 32 + 4064) -#define IEEE802154_MAX_CSMA_BACKOFFS (1) +#define IEEE802154_MAX_CSMA_BACKOFFS (4) #define IEEE802154_MIN_BE (3) #define IEEE802154_MAX_BE (5) #define IEEE802154_CW0 (2)
