Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions nrf_802154/common/include/nrf_802154_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#endif

#include <nrfx.h>
#include "nrf_802154_nrfx_addons.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -68,13 +69,20 @@ extern "C" {
#endif

/**
* @def NRF_802154_CCA_ED_THRESHOLD_DEFAULT
* @def NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT
*
* Energy detection threshold used in the CCA procedure.
* Energy detection threshold in dBm used in the CCA procedure.
*
* Note: NRF_802154_CCA_ED_THRESHOLD_DEFAULT is deprecated.
*
*/
#ifndef NRF_802154_CCA_ED_THRESHOLD_DEFAULT
#define NRF_802154_CCA_ED_THRESHOLD_DEFAULT 0x14
#ifdef NRF_802154_CCA_ED_THRESHOLD_DEFAULT
#undef NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT
#define NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT (ED_RSSIOFFS + NRF_802154_CCA_ED_THRESHOLD_DEFAULT)
#else
#ifndef NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT
#define NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT (-75)
#endif
#endif

/**
Expand Down
1 change: 0 additions & 1 deletion nrf_802154/common/include/nrf_802154_nrfx_addons.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#define NRF_802154_NRFX_ADDONS_H__

#include "nrfx.h"
#include "nrf_802154_config.h"
#include "nrf_802154_const.h"

/* The usage of ED_RSSISCALE is described imprecisely in the nRF product specifications. The meaning of
Expand Down
2 changes: 1 addition & 1 deletion nrf_802154/common/include/nrf_802154_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ typedef uint8_t nrf_802154_term_t;
typedef struct
{
nrf_radio_cca_mode_t mode; // !< CCA mode.
uint8_t ed_threshold; // !< Busy threshold of the CCA energy. Not used in @ref NRF_RADIO_CCA_MODE_CARRIER.
int8_t ed_threshold; // !< Busy threshold of the CCA energy. Not used in @ref NRF_RADIO_CCA_MODE_CARRIER. The threshold is absolute value in dBm.
uint8_t corr_threshold; // !< Busy threshold of the CCA correlator. Not used in @ref NRF_RADIO_CCA_MODE_ED.
uint8_t corr_limit; // !< Limit of occurrences above the busy threshold of the CCA correlator. Not used in @ref NRF_RADIO_CCA_MODE_ED.
} nrf_802154_cca_cfg_t;
Expand Down
8 changes: 8 additions & 0 deletions nrf_802154/doc/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ See also :ref:`nrf_802154_limitations` for permanent limitations.
Main branch - nRF 802.15.4 Radio Driver
***************************************

Notable changes
===============

* The configuration macro :c:macro:`NRF_802154_CCA_ED_THRESHOLD_DEFAULT` is deprecated.
It is superseded by the :c:macro:`NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT` macro, which specifies the absolute value of the CCA ED threshold in dBm. (KRKNWK-19974)
* The Energy Detection (ED) sample, Received Signal Strength Indicator (RSSI), and Clear Channel Assessment (CCA) threshold now account for Low-Noise Amplifier (LNA) gain.
These values now represent the power at the antenna connector, rather than at the radio. (KRKNWK-19974)

Added
=====

Expand Down
7 changes: 5 additions & 2 deletions nrf_802154/driver/src/mac_features/nrf_802154_delayed_trx.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <stdbool.h>
#include <stdint.h>

#include <nrfx.h>
#include "../nrf_802154_debug.h"
#include "nrf_802154_config.h"
#include "nrf_802154_const.h"
Expand Down Expand Up @@ -75,8 +76,10 @@
#define TX_SETUP_TIME_MAX 360u ///< Maximum time needed to prepare TX procedure [us]. It does not include TX ramp-up time.
#define RX_SETUP_TIME_MAX 290u ///< Maximum time needed to prepare RX procedure [us]. It does not include RX ramp-up time.
#elif defined(NRF54L_SERIES)
#define TX_SETUP_TIME_MAX 600u ///< Maximum time needed to prepare TX procedure [us]. It does not include TX ramp-up time.
#define RX_SETUP_TIME_MAX 600u ///< Maximum time needed to prepare RX procedure [us]. It does not include RX ramp-up time.
NRF_STATIC_ASSERT(NRF_CONFIG_CPU_FREQ_MHZ == 128,
"Currently nrf-802154 only works when frequency is 128MHz");
#define TX_SETUP_TIME_MAX 185u ///< Maximum time needed to prepare TX procedure [us]. It does not include TX ramp-up time.
#define RX_SETUP_TIME_MAX 150u ///< Maximum time needed to prepare RX procedure [us]. It does not include RX ramp-up time.
#elif defined(NRF54H_SERIES)
#ifndef TX_SETUP_TIME_MAX
#define TX_SETUP_TIME_MAX 400u ///< Maximum time needed to prepare TX procedure [us]. It does not include TX ramp-up time.
Expand Down
27 changes: 10 additions & 17 deletions nrf_802154/driver/src/nrf_802154_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "nrf_802154_tx_power.h"
#include "nrf_802154_types_internal.h"
#include "nrf_802154_utils.h"
#include "nrf_802154_nrfx_addons.h"
#include "drivers/nrfx_errors.h"
#include "hal/nrf_radio.h"
#include "mac_features/nrf_802154_filter.h"
Expand Down Expand Up @@ -94,10 +95,10 @@
/// Overhead of hardware preparation for ED procedure (aTurnaroundTime) [number of iterations]
#define ED_ITERS_OVERHEAD 2U

#define MAX_CRIT_SECT_TIME 60 ///< Maximal time that the driver spends in single critical section.
#define MAX_CRIT_SECT_TIME 60 ///< Maximal time that the driver spends in single critical section.

#define LQI_VALUE_FACTOR 4 ///< Factor needed to calculate LQI value based on data from RADIO peripheral
#define LQI_MAX 0xff ///< Maximal LQI value
#define LQI_VALUE_FACTOR ED_RSSISCALE ///< Factor needed to calculate LQI value based on data from RADIO peripheral
#define LQI_MAX 0xff ///< Maximal LQI value

/** Get LQI of given received packet. If CRC is calculated by hardware LQI is included instead of CRC
* in the frame. Length is stored in byte with index 0; CRC is 2 last bytes.
Expand All @@ -122,7 +123,7 @@ static rx_buffer_t * const mp_current_rx_buffer = &nrf_802154_rx_buffers[0];
static uint8_t * mp_ack; ///< Pointer to Ack frame buffer.
static uint8_t * mp_tx_data; ///< Pointer to the data to transmit.
static uint32_t m_ed_time_left; ///< Remaining time of the current energy detection procedure [us].
static uint8_t m_ed_result; ///< Result of the current energy detection procedure.
static int8_t m_ed_result; ///< Result of the current energy detection procedure.
static uint8_t m_last_lqi; ///< LQI of the last received non-ACK frame, corrected for the temperature.
static nrf_802154_fal_tx_power_split_t m_tx_power; ///< Power to be used to transmit the current frame split into components.
static uint8_t m_tx_channel; ///< Channel to be used to transmit the current frame.
Expand Down Expand Up @@ -241,11 +242,7 @@ static void rssi_measurement_wait(void)
*/
static int8_t rssi_last_measurement_get(void)
{
uint8_t rssi_sample = nrf_802154_trx_rssi_last_sample_get();

rssi_sample = nrf_802154_rssi_sample_corrected_get(rssi_sample);

return -((int8_t)rssi_sample);
return nrf_802154_trx_rssi_last_sample_get();
}

/** Get LQI of a received frame.
Expand Down Expand Up @@ -2500,15 +2497,11 @@ void nrf_802154_trx_transmit_frame_ccabusy(void)
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
}

void nrf_802154_trx_energy_detection_finished(uint8_t ed_sample)
void nrf_802154_trx_energy_detection_finished(int8_t ed_sample_dbm)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);

if (m_ed_result < ed_sample)
{
// Collect maximum value of samples provided by trx
m_ed_result = ed_sample;
}
m_ed_result = MAX(m_ed_result, ed_sample_dbm);

if (m_ed_time_left >= ED_ITER_DURATION)
{
Expand Down Expand Up @@ -2536,7 +2529,7 @@ void nrf_802154_trx_energy_detection_finished(uint8_t ed_sample)

nrf_802154_energy_detected_t ed_result = {};

ed_result.ed_dbm = nrf_802154_rssi_ed_sample_to_dbm_convert(m_ed_result);
ed_result.ed_dbm = m_ed_result;

energy_detected_notify(&ed_result);
}
Expand Down Expand Up @@ -2844,7 +2837,7 @@ bool nrf_802154_core_energy_detection(nrf_802154_term_t term_lvl, uint32_t time_
}

m_ed_time_left = time_us;
m_ed_result = 0;
m_ed_result = ED_RSSIOFFS;

state_set(RADIO_STATE_ED);
ed_init();
Expand Down
2 changes: 1 addition & 1 deletion nrf_802154/driver/src/nrf_802154_pib.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void nrf_802154_pib_init(void)
memset(m_data.extended_addr, 0, sizeof(m_data.extended_addr));

m_data.cca.mode = NRF_802154_CCA_MODE_DEFAULT;
m_data.cca.ed_threshold = NRF_802154_CCA_ED_THRESHOLD_DEFAULT;
m_data.cca.ed_threshold = NRF_802154_CCA_ED_THRESHOLD_DBM_DEFAULT;
m_data.cca.corr_threshold = NRF_802154_CCA_CORR_THRESHOLD_DEFAULT;
m_data.cca.corr_limit = NRF_802154_CCA_CORR_LIMIT_DEFAULT;

Expand Down
23 changes: 20 additions & 3 deletions nrf_802154/driver/src/nrf_802154_rssi.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#if defined(NRF52_SERIES)

/* Implementation for nRF52 family. */
int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
static int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
{
(void)rssi_sample;

Expand Down Expand Up @@ -99,7 +99,7 @@ int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
return result;
}

#else
#elif defined(NRF53_SERIES)

/** Macro for calculating x raised to the power of 2. */
#define POW_2(x) ((x) * (x))
Expand Down Expand Up @@ -137,7 +137,7 @@ static int8_t normalize_rssi(int32_t rssi_value)
}

/* Implementation based on Errata 87 for nRF53 family. */
int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
static int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
{
int32_t temp;
int32_t rssi_sample_i32;
Expand All @@ -154,6 +154,13 @@ int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
return compensated_rssi - (int8_t)rssi_sample;
}

#else

static int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample)
{
return 0;
}

#endif

uint8_t nrf_802154_rssi_sample_corrected_get(uint8_t rssi_sample)
Expand Down Expand Up @@ -213,3 +220,13 @@ int8_t nrf_802154_rssi_ed_sample_to_dbm_convert(uint8_t ed_sample)

return result;
}

uint8_t nrf_802154_rssi_dbm_to_hw(int8_t dbm)
{
return dbm - ED_RSSIOFFS;
}

int8_t nrf_802154_rssi_hw_to_dbm(uint8_t hwval)
{
return hwval + ED_RSSIOFFS;
}
29 changes: 18 additions & 11 deletions nrf_802154/driver/src/nrf_802154_rssi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@
* @brief RSSI calculations used internally in the 802.15.4 driver.
*/

/**
* @brief Gets the RSSISAMPLE temperature correction value.
*
* The correction value is based on the last temperature value reported by the platform.
*
* @param[in] rssi_sample Value read from the RSSISAMPLE register.
*
* @returns RSSISAMPLE temperature correction value.
*/
int8_t nrf_802154_rssi_sample_temp_corr_value_get(uint8_t rssi_sample);

/**
* @brief Adjusts the given RSSISAMPLE value by a temperature correction factor.
*
Expand Down Expand Up @@ -120,6 +109,24 @@ int8_t nrf_802154_rssi_dbm_from_energy_level_calculate(uint8_t energy_level);
*/
int8_t nrf_802154_rssi_ed_sample_to_dbm_convert(uint8_t ed_sample);

/**
* @brief Converts the a dBm value to radio hardware value.
*
* @param[in] dbm The dBm value.
*
* @return Value in hardware units.
*/
uint8_t nrf_802154_rssi_dbm_to_hw(int8_t dbm);

/**
* @brief Converts the a radio hardware value to dBm value.
*
* @param[in] hwval The radio hardware value.
*
* @return Value in dBm.
*/
int8_t nrf_802154_rssi_hw_to_dbm(uint8_t hwval);

/**
*@}
**/
Expand Down
26 changes: 22 additions & 4 deletions nrf_802154/driver/src/nrf_802154_trx.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,17 @@ static void channel_set(uint8_t channel)
static void cca_configuration_update(void)
{
nrf_802154_cca_cfg_t cca_cfg;
uint8_t threshold_hw;
int8_t lna_gain_db = 0;

nrf_802154_pib_cca_cfg_get(&cca_cfg);
mpsl_fem_lna_is_configured(&lna_gain_db);

threshold_hw = nrf_802154_rssi_dbm_to_hw(cca_cfg.ed_threshold + lna_gain_db);

nrf_radio_cca_configure(NRF_RADIO,
cca_cfg.mode,
nrf_802154_rssi_cca_ed_threshold_corrected_get(cca_cfg.ed_threshold),
nrf_802154_rssi_cca_ed_threshold_corrected_get(threshold_hw),
cca_cfg.corr_threshold,
cca_cfg.corr_limit);
}
Expand Down Expand Up @@ -1514,7 +1520,15 @@ bool nrf_802154_trx_rssi_measure_is_started(void)

uint8_t nrf_802154_trx_rssi_last_sample_get(void)
{
return nrf_radio_rssi_sample_get(NRF_RADIO);
int8_t lna_gain_db = 0;
uint8_t rssi_sample_minus_dbm = nrf_radio_rssi_sample_get(NRF_RADIO);
uint8_t rssi_sample_corrected_minus_dbm =
nrf_802154_rssi_sample_corrected_get(rssi_sample_minus_dbm);
int8_t rssi_sample_corrected_dbm = -((int8_t)rssi_sample_corrected_minus_dbm);

mpsl_fem_lna_is_configured(&lna_gain_db);

return rssi_sample_corrected_dbm - lna_gain_db;
}

bool nrf_802154_trx_rssi_sample_is_available(void)
Expand Down Expand Up @@ -2848,12 +2862,16 @@ static void irq_handler_edend(void)

NRF_802154_ASSERT(m_trx_state == TRX_STATE_ENERGY_DETECTION);

uint8_t ed_sample = nrf_radio_ed_sample_get(NRF_RADIO);
int8_t lna_gain_db = 0;
uint8_t ed_sample_hw = nrf_radio_ed_sample_get(NRF_RADIO);
int8_t ed_sample_dbm = nrf_802154_rssi_ed_sample_to_dbm_convert(ed_sample_hw);

energy_detection_finish();
m_trx_state = TRX_STATE_FINISHED;

nrf_802154_trx_energy_detection_finished(ed_sample);
mpsl_fem_lna_is_configured(&lna_gain_db);

nrf_802154_trx_energy_detection_finished(ed_sample_dbm - lna_gain_db);

nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
}
Expand Down
4 changes: 2 additions & 2 deletions nrf_802154/driver/src/nrf_802154_trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,9 @@ extern void nrf_802154_trx_standalone_cca_finished(bool channel_was_idle);
* - @ref nrf_802154_trx_go_idle,
* - @ref nrf_802154_trx_disable.
*
* @param ed_sample Sample of detected energy.
* @param ed_sample_dbm Sample of detected energy.
*/
extern void nrf_802154_trx_energy_detection_finished(uint8_t ed_sample);
extern void nrf_802154_trx_energy_detection_finished(int8_t ed_sample_dbm);

/**@brief Returns RADIO->EVENTS_END handle that hardware can subscribe to.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ typedef enum
*/
#define SPINEL_DATATYPE_NRF_802154_CCA_CFG_S \
SPINEL_DATATYPE_UINT8_S /* mode */ \
SPINEL_DATATYPE_UINT8_S /* ed_threshold */ \
SPINEL_DATATYPE_INT8_S /* ed_threshold */ \
SPINEL_DATATYPE_UINT8_S /* corr_threshold */ \
SPINEL_DATATYPE_UINT8_S /* corr_limit */

Expand Down
4 changes: 2 additions & 2 deletions nrf_802154/serialization/src/nrf_802154_spinel_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static nrf_802154_ser_err_t cca_cfg_await(uint32_t timeout,

NRF_802154_SPINEL_LOG_BANNER_RESPONSE();
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->mode, "Mode");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->ed_threshold, "ED threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%d", p_cfg->ed_threshold, "ED threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->corr_threshold, "Corr threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->corr_limit, "Corr limit");

Expand Down Expand Up @@ -1884,7 +1884,7 @@ void nrf_802154_cca_cfg_set(const nrf_802154_cca_cfg_t * p_cfg)

NRF_802154_SPINEL_LOG_BANNER_CALLING();
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->mode, "Mode");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->ed_threshold, "ED threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%d", p_cfg->ed_threshold, "ED threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->corr_threshold, "Corr threshold");
NRF_802154_SPINEL_LOG_VAR_NAMED("%u", p_cfg->corr_limit, "Corr limit");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ int8_t mpsl_fem_tx_power_split(const mpsl_tx_power_t power,
*/
int32_t mpsl_fem_pa_power_control_set(mpsl_fem_pa_power_control_t pa_power_control);

/** @brief Returns LNA gain if the LNA signal is configured and enabled, 0 otherwise.
*
* @param[out] p_gain The configured gain in dB if LNA is configured and enabled.
* If there is no LNA present or the LNA does not affect
* the signal gain, returns 0 dB.
*/
void mpsl_fem_lna_is_configured(int8_t * const p_gain);

#endif // MPSL_FEM_PROTOCOL_API_H__

/**@} */
5 changes: 5 additions & 0 deletions nrf_802154/sl/sl_opensource/src/nrf_802154_sl_fem.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ uint32_t mpsl_tx_power_dbm_to_radio_register_convert(mpsl_tx_power_t req_radio_p
return to_radio_tx_power_convert(req_radio_power).reg;
}

void mpsl_fem_lna_is_configured(int8_t * const p_gain)
{
*p_gain = 0;
}

#ifdef __cplusplus
}
#endif