RADIO: Add test interface to offset Tx and Rx power

Add 2 test specific functions which can be used
to apply a gain to the Tx and Rx power.
The Tx power will be increased by that amount of dBs.
And so will the reported RSSI value.

Note that for Rx is only the RSSI measurement that is changed.
Performance will still be based on the power on the "antenna".

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-03-26 14:37:35 +01:00
parent df94612a84
commit 31614b4f84
5 changed files with 76 additions and 11 deletions

View File

@ -235,6 +235,8 @@ static bool radio_on = false;
static bool rssi_sampling_on = false;
static double cheat_rx_power_offset;
static void start_Tx(void);
static void start_Tx_FEC2(void);
static void start_Rx(void);
@ -1027,7 +1029,7 @@ static void Rx_handle_address_end_response(bs_time_t address_time) {
if (NRF_RADIO_regs.MODE == RADIO_MODE_MODE_Ieee802154_250Kbit) {
//The real HW only copies the LQI value after the payload in this mode
//Note that doing it this early is a cheat
double RSSI = p2G4_RSSI_value_to_dBm(rx_status.rx_resp.rssi.RSSI);
double RSSI = p2G4_RSSI_value_to_dBm(rx_status.rx_resp.rssi.RSSI) + cheat_rx_power_offset;
uint8_t LQI = nhwra_dBm_to_modem_LQIformat(RSSI);
//Eventually this should be generalized with the packet configuration:
((uint8_t*)NRF_RADIO_regs.PACKETPTR)[1 + rx_status.S1Offset + length] = LQI;
@ -1225,7 +1227,10 @@ static void Rx_Addr_received(void) {
if (rx_status.codedphy == false || rx_status.inFEC1 == true) {
if ( rssi_sampling_on ){
NRF_RADIO_regs.RSSISAMPLE = nhwra_RSSI_value_to_modem_format(p2G4_RSSI_value_to_dBm(rx_status.rx_resp.rssi.RSSI));
NRF_RADIO_regs.RSSISAMPLE = nhwra_RSSI_value_to_modem_format(
p2G4_RSSI_value_to_dBm(rx_status.rx_resp.rssi.RSSI)
+ cheat_rx_power_offset
);
nhw_RADIO_signal_EVENTS_RSSIEND(0);
}
}
@ -1329,7 +1334,7 @@ static void CCA_handle_end_response(void) {
__func__, CCAMode);
}
} else { // Ending an ED procedure
double RSSI = p2G4_RSSI_value_to_dBm(cca_status.cca_resp.RSSI_max);
double RSSI = p2G4_RSSI_value_to_dBm(cca_status.cca_resp.RSSI_max) + cheat_rx_power_offset;
NRF_RADIO_regs.EDSAMPLE = nhwra_dBm_to_modem_LQIformat(RSSI);
}
}
@ -1382,7 +1387,7 @@ static void start_CCA_ED(bool CCA_not_ED){
cca_status.CCA_notED = CCA_not_ED;
cca_status.is_busy = false;
nhwra_prep_cca_request(&cca_status.cca_req, CCA_not_ED);
nhwra_prep_cca_request(&cca_status.cca_req, CCA_not_ED, cheat_rx_power_offset);
update_abort_struct(&cca_status.cca_req.abort, &next_recheck_time);
@ -1394,3 +1399,7 @@ static void start_CCA_ED(bool CCA_not_ED){
int ret = p2G4_dev_req_cca_nc_b(&cca_status.cca_req, &cca_status.cca_resp);
handle_CCA_response(ret);
}
void hw_radio_testcheat_set_rx_power_gain(double power_offset){
cheat_rx_power_offset = power_offset;
}

View File

@ -57,6 +57,13 @@ void nhw_RADIO_regw_sideeffects_SUBSCRIBE_EDSTOP(unsigned int);
void nhw_RADIO_regw_sideeffects_SUBSCRIBE_CCASTART(unsigned int);
void nhw_RADIO_regw_sideeffects_SUBSCRIBE_CCASTOP(unsigned int);
/*
* Note
* hw_radio_testcheat_set_tx_power_gain() &
* hw_radio_testcheat_set_rx_power_gain()
* are defined in hw_testcheat_if.h
*/
/*
* Internal interface to bitcounter
*/

View File

@ -22,6 +22,7 @@
#include "nsi_hw_scheduler.h"
extern NRF_RADIO_Type NRF_RADIO_regs;
static double cheat_tx_power_offset;
static void nrfra_check_crc_conf_ble(void) {
if ( (NRF_RADIO_regs.CRCCNF & RADIO_CRCCNF_LEN_Msk)
@ -419,7 +420,7 @@ void nhwra_prep_tx_request(p2G4_txv2_t *tx_req, uint packet_size, bs_time_t pack
{
double TxPower = (int8_t)( NRF_RADIO_regs.TXPOWER & RADIO_TXPOWER_TXPOWER_Msk); //the cast is to sign extend it
tx_req->power_level = p2G4_power_from_d(TxPower); //Note that any possible Tx antenna or PA gain would need to be included here
tx_req->power_level = p2G4_power_from_d(TxPower + cheat_tx_power_offset); //Note that any possible Tx antenna or PA gain would need to be included here
}
{ //Note only default freq. map supported
@ -445,7 +446,7 @@ void nhwra_prep_tx_request(p2G4_txv2_t *tx_req, uint packet_size, bs_time_t pack
*
* Note: The abort substructure is NOT filled.
*/
void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED) {
void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED, double rx_pow_offset) {
cca_req->start_time = hwll_phy_time_from_dev(nsi_hws_get_time()); //We start right now
cca_req->antenna_gain = 0;
@ -466,13 +467,14 @@ void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED) {
if (CCA_not_ED) { //CCA request
uint edthreshold = (NRF_RADIO_regs.CCACTRL & RADIO_CCACTRL_CCAEDTHRES_Msk) >> RADIO_CCACTRL_CCAEDTHRES_Pos;
uint CCAMode = (NRF_RADIO_regs.CCACTRL & RADIO_CCACTRL_CCAMODE_Msk) >> RADIO_CCACTRL_CCAMODE_Pos;
double carrier_detect_level = -110; //dBm : Any detectable signal by the modem
double carrier_detect_level = -110 - rx_pow_offset; //dBm : Any detectable signal by the modem
double edthreshold_dBm = nrfra_LQIformat_to_dBm(edthreshold) - rx_pow_offset;
cca_req->scan_duration = 8*symbol_time;
cca_req->scan_period = 2*symbol_time; //let's measure 4 times (model design choice)
if (CCAMode == RADIO_CCACTRL_CCAMODE_EdMode) {
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(nrfra_LQIformat_to_dBm(edthreshold));
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(edthreshold_dBm);
cca_req->mod_threshold = p2G4_RSSI_value_from_dBm(100/*dBm*/); //not used
cca_req->stop_when_found = 0;
} else if (CCAMode == RADIO_CCACTRL_CCAMODE_CarrierMode) {
@ -484,10 +486,10 @@ void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED) {
} else if ((CCAMode == RADIO_CCACTRL_CCAMODE_CarrierAndEdMode)
|| (CCAMode == RADIO_CCACTRL_CCAMODE_CarrierOrEdMode) ) {
cca_req->stop_when_found = 1;
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(nrfra_LQIformat_to_dBm(edthreshold));
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(edthreshold_dBm);
cca_req->mod_threshold = p2G4_RSSI_value_from_dBm(carrier_detect_level);
} else if (CCAMode == RADIO_CCACTRL_CCAMODE_EdModeTest1) {
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(nrfra_LQIformat_to_dBm(edthreshold));
cca_req->rssi_threshold = p2G4_RSSI_value_from_dBm(edthreshold_dBm);
cca_req->mod_threshold = p2G4_RSSI_value_from_dBm(100/*dBm*/); //not used
cca_req->stop_when_found = 2;
} else {
@ -645,3 +647,7 @@ uint nhwra_tx_copy_payload(uint8_t *tx_buf){
memcpy(&tx_buf[i], &((uint8_t*)NRF_RADIO_regs.PACKETPTR)[i + S1Off], copy_len);
return payload_len;
}
void hw_radio_testcheat_set_tx_power_gain(double power_offset_i) {
cheat_tx_power_offset = power_offset_i;
}

View File

@ -23,7 +23,7 @@ void nhwra_prep_rx_request(p2G4_rxv2_t *ongoing_rx, p2G4_address_t *rx_addresses
void nhwra_prep_rx_request_FEC1(p2G4_rxv2_t *rx_req, p2G4_address_t *rx_addresses);
void nhwra_prep_tx_request(p2G4_txv2_t *tx_req, uint packet_size, bs_time_t packet_duration,
bs_time_t start_time, uint16_t coding_rate);
void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED);
void nhwra_prep_cca_request(p2G4_cca_t *cca_req, bool CCA_not_ED, double rx_pow_offset);
uint nhwra_tx_copy_payload(uint8_t *tx_buf);
uint nhwra_get_payload_length(uint8_t *buf);

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*
* This file specifies a set of interfaces meant to allow tests
* to modify the HW behavior.
* This APIs should only be used for test purposes, to facilitate testing.
*
* This API is specified in a relatively HW agnostic way, so as to facilitate
* other vendors providing an implementation for it, but
* it should be used with extra care as the functionality is likely to not be
* provided by other build targets than the ones based on this HW models.
*/
#ifndef _NRF_HWMODELS_HW_TESTCHEAT_IF_H
#define _NRF_HWMODELS_HW_TESTCHEAT_IF_H
#ifdef __cplusplus
extern "C"{
#endif
/**
* Offset the Tx power by <power_offset_i> dBs
*
* For example, set to -20 to lower the Tx power by 20dBs compared
* to what it would have been otherwise.
*/
void hw_radio_testcheat_set_tx_power_gain(double power_offset);
/**
* Offset the measured Rx power (RSSI) by <power_offset_i> dBs
*
* For example, set to 20 to raise the Rx power by 20dBs compared
* to what it would have been otherwise.
*/
void hw_radio_testcheat_set_rx_power_gain(double power_offset);
#ifdef __cplusplus
}
#endif
#endif