A configuration structure for the CSMA transmit algorithm.

One of RAIL's schemes for polite spectrum access is an implementation of a Carrier-Sense Multiple Access (CSMA) algorithm based on IEEE 802.15.4 (unslotted).
In pseudo-code it works like this, showing relevant event notifications:

// Return true to transmit packet, false to not transmit packet.
bool perform_csma(const sl_rail_csma_config_t *csma_config)
{
  extern int idle_to_rx_us;
  bool is_fixed_backoff = ((csma_config->csma_min_bo_exp == 0)
                           && (csma_config->csma_max_bo_exp == 0));
  int backoff_exp = csma_config->csma_min_bo_exp; // Initial backoff exponent
  int backoff_multiplier = 1; // Assume fixed backoff
  int try;

  // Special-case tries == 0 to transmit immediately without backoff+CCA
  if (csma_config->csma_tries == 0) {
    return true;
  }

  // Start overall timeout if specified:
  if (csma_config->csma_timeout_us > 0) {
    start_abort_timer(csma_config->csma_timeout_us, SL_RAIL_EVENT_TX_CHANNEL_BUSY);
    // If timeout occurs, abort and signal the indicated event.
  }

  for (try = 0; try < csma_config->csma_tries; try++) {
    if (try > 0) {
      signal_event(SL_RAIL_EVENT_TX_CCA_RETRY);
    }
    // Determine the backoff multipler for this try:
    if (is_fixed_backoff) {
      // backoff_multiplier already set to 1 for fixed backoff
    } else {
      // Start with the backoff exponent for this try:
      if (try > 0) {
        backoff_exp++;
        if (backoff_exp > csma_config->csma_max_bo_exp) {
          backoff_exp = csma_config->csma_max_bo_exp;
        }
      }
      // Pick random multiplier between 0 and 2^backoff_exp - 1 inclusive:
      backoff_multiplier = pick_random_integer(0, (1 << backoff_exp) - 1);
    }
    // Perform the backoff:
    if (backoff_multiplier > 0) {
      delay_microseconds((backoff_multiplier * csma_config->cca_backoff_us)
                         - idle_to_rx_us);
    }
    enable_radio_receive();
    signal_event(SL_RAIL_EVENT_TX_START_CCA);
    delay_microseconds(idle_to_rx_us);
    // Perform the Clear-Channel Assessment (CCA):
    // Channel is considered busy if radio is actively receiving or
    // transmitting, or the energy detected during the duration period
    // is above the threshold.
    signal_event(SL_RAIL_EVENT_TX_CCA_ACTIVATED);
    if (perform_cca(csma_config->cca_duration_us, csma_config->cca_threshold_dbm)) {
      // CCA (and CSMA) success: Transmit after RX-to-TX turnaround
      stop_abort_timer();
      signal_event(SL_RAIL_EVENT_TX_CHANNEL_CLEAR);
      return true;
    } else {
      // CCA failed: loop to try again, or exit if out of tries
    }
  }
  // Overall CSMA failure: Don't transmit
  stop_abort_timer();
  signal_event(SL_RAIL_EVENT_TX_CHANNEL_BUSY);
  return false;
}

Public Attributes#

uint8_t

The minimum (starting) exponent for CSMA random backoff (2^exp - 1).

uint8_t

The maximum exponent for CSMA random backoff (2^exp - 1).

uint8_t

The number of backoff-then-CCA iterations that can fail before reporting SL_RAIL_EVENT_TX_CHANNEL_BUSY.

int8_t

The CCA RSSI threshold, in dBm, above which the channel is considered 'busy'.

uint16_t

The backoff unit period in RAIL's microsecond time base.

uint16_t

The minimum desired CCA check duration in microseconds.

An overall timeout, in RAIL's microsecond time base, for the operation.

Public Attribute Documentation#

csma_min_bo_exp#

uint8_t sl_rail_csma_config_t::csma_min_bo_exp

The minimum (starting) exponent for CSMA random backoff (2^exp - 1).

It can range from 0 to SL_RAIL_MAX_CSMA_EXPONENT.

Warnings


csma_max_bo_exp#

uint8_t sl_rail_csma_config_t::csma_max_bo_exp

The maximum exponent for CSMA random backoff (2^exp - 1).

It can range from 0 to SL_RAIL_MAX_CSMA_EXPONENT and must be greater than or equal to csma_min_bo_exp.
If both exponents are 0, a non-random fixed backoff of cca_backoff_us duration results.


csma_tries#

uint8_t sl_rail_csma_config_t::csma_tries

The number of backoff-then-CCA iterations that can fail before reporting SL_RAIL_EVENT_TX_CHANNEL_BUSY.

Typically ranges from 1 to SL_RAIL_MAX_LBT_TRIES; higher values are disallowed. A value 0 always transmits immediately without performing CSMA, similar to calling sl_rail_start_tx().


cca_threshold_dbm#

int8_t sl_rail_csma_config_t::cca_threshold_dbm

The CCA RSSI threshold, in dBm, above which the channel is considered 'busy'.


cca_backoff_us#

uint16_t sl_rail_csma_config_t::cca_backoff_us

The backoff unit period in RAIL's microsecond time base.

It is multiplied by the random backoff exponential controlled by csma_min_bo_exp and csma_max_bo_exp to determine the overall backoff period. For random backoffs, any value above 32768 microseconds for the 'EFR Series 2' and 8192 microseconds for the 'Series 3' will be truncated for a single backoff period. Up to 255 backoff periods are supported. For fixed backoffs it can go up to 65535 microseconds.


cca_duration_us#

uint16_t sl_rail_csma_config_t::cca_duration_us

The minimum desired CCA check duration in microseconds.

The RSSI is sampled during this duration.

Note


csma_timeout_us#

sl_rail_time_t sl_rail_csma_config_t::csma_timeout_us

An overall timeout, in RAIL's microsecond time base, for the operation.

If the transmission doesn't start before this timeout expires, the transmission will fail with SL_RAIL_EVENT_TX_CHANNEL_BUSY. A value 0 means no timeout is imposed.