NR UE: move openair0_config_t and openair0_device_t out of PHY_VARS_NR_UE and consistently use UE->rf_map.card
This commit is contained in:
+45
-33
@@ -201,18 +201,24 @@ typedef struct {
|
||||
int rx_offset;
|
||||
} syncData_t;
|
||||
|
||||
static int nr_ue_adjust_rx_gain(PHY_VARS_NR_UE *UE, openair0_config_t *cfg0, int gain_change)
|
||||
extern openair0_config_t openair0_cfg[MAX_CARDS];
|
||||
extern openair0_device_t openair0_dev[MAX_CARDS];
|
||||
|
||||
static int nr_ue_adjust_rx_gain(PHY_VARS_NR_UE *UE, int gain_change)
|
||||
{
|
||||
openair0_config_t *cfg0 = &openair0_cfg[UE->rf_map.card];
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
|
||||
// Increase the RX gain by the value determined by adjust_rxgain
|
||||
cfg0->rx_gain[0] += gain_change;
|
||||
|
||||
// Set new RX gain.
|
||||
int ret_gain = UE->rfdevice.trx_set_gains_func(&UE->rfdevice, cfg0);
|
||||
int ret_gain = dev0->trx_set_gains_func(dev0, cfg0);
|
||||
// APPLY RX gain again if crossed the MAX RX gain threshold
|
||||
if (ret_gain < 0) {
|
||||
gain_change += ret_gain;
|
||||
cfg0->rx_gain[0] += ret_gain;
|
||||
ret_gain = UE->rfdevice.trx_set_gains_func(&UE->rfdevice, cfg0);
|
||||
ret_gain = dev0->trx_set_gains_func(dev0, cfg0);
|
||||
}
|
||||
|
||||
int applied_rxgain = cfg0->rx_gain[0] - cfg0->rx_gain_offset[0];
|
||||
@@ -225,7 +231,8 @@ static void UE_synch(void *arg) {
|
||||
syncData_t *syncD = (syncData_t *)arg;
|
||||
PHY_VARS_NR_UE *UE = syncD->UE;
|
||||
UE->is_synchronized = 0;
|
||||
openair0_config_t *cfg0 = &UE->openair0_cfg[UE->rf_map.card];
|
||||
openair0_config_t *cfg0 = &openair0_cfg[UE->rf_map.card];
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
|
||||
if (UE->target_Nid_cell != -1) {
|
||||
LOG_W(NR_PHY, "Starting re-sync detection for target Nid_cell %i\n", UE->target_Nid_cell);
|
||||
@@ -260,11 +267,11 @@ static void UE_synch(void *arg) {
|
||||
} else {
|
||||
// rerun with new cell parameters and frequency-offset
|
||||
nr_rf_card_config_freq(cfg0, ul_carrier, dl_carrier, freq_offset);
|
||||
UE->rfdevice.trx_set_freq_func(&UE->rfdevice, cfg0);
|
||||
dev0->trx_set_freq_func(dev0, cfg0);
|
||||
}
|
||||
|
||||
if (get_nrUE_params()->agc) {
|
||||
nr_ue_adjust_rx_gain(UE, cfg0, UE->adjust_rxgain);
|
||||
nr_ue_adjust_rx_gain(UE, UE->adjust_rxgain);
|
||||
}
|
||||
|
||||
LOG_I(PHY,
|
||||
@@ -279,7 +286,7 @@ static void UE_synch(void *arg) {
|
||||
} else {
|
||||
int gain_change = 0;
|
||||
if (get_nrUE_params()->agc)
|
||||
gain_change = nr_ue_adjust_rx_gain(UE, cfg0, INCREASE_IN_RXGAIN);
|
||||
gain_change = nr_ue_adjust_rx_gain(UE, INCREASE_IN_RXGAIN);
|
||||
if (gain_change)
|
||||
LOG_I(PHY, "synch retry: Rx gain increased \n");
|
||||
else
|
||||
@@ -324,6 +331,8 @@ static void RU_write(nr_rxtx_thread_data_t *rxtxD, bool sl_tx_action, c16_t **tx
|
||||
PHY_VARS_NR_UE *UE = rxtxD->UE;
|
||||
const fapi_nr_config_request_t *cfg = &UE->nrUE_config;
|
||||
const UE_nr_rxtx_proc_t *proc = &rxtxD->proc;
|
||||
openair0_config_t *cfg0 = &openair0_cfg[UE->rf_map.card];
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
|
||||
NR_DL_FRAME_PARMS *fp = &UE->frame_parms;
|
||||
if (UE->sl_mode == 2)
|
||||
@@ -334,7 +343,7 @@ static void RU_write(nr_rxtx_thread_data_t *rxtxD, bool sl_tx_action, c16_t **tx
|
||||
radio_tx_burst_flag_t flags = TX_BURST_INVALID;
|
||||
|
||||
if (UE->received_config_request) {
|
||||
if (UE->openair0_cfg[0].duplex_mode == duplex_mode_FDD || get_softmodem_params()->continuous_tx) {
|
||||
if (cfg0->duplex_mode == duplex_mode_FDD || get_softmodem_params()->continuous_tx) {
|
||||
flags = TX_BURST_MIDDLE;
|
||||
// In case of Sidelink, USRP write needed only in case transmission
|
||||
// needs to be done in this slot and not based on tdd ULDL configuration.
|
||||
@@ -385,7 +394,7 @@ static void RU_write(nr_rxtx_thread_data_t *rxtxD, bool sl_tx_action, c16_t **tx
|
||||
const int maxWriteBlockSize = get_samples_per_slot(proc->nr_slot_tx, fp);
|
||||
while (writeBlockSize > maxWriteBlockSize) {
|
||||
const int dummyBlockSize = min(writeBlockSize - maxWriteBlockSize, maxWriteBlockSize);
|
||||
int tmp = openair0_write_reorder(&UE->rfdevice, writeTimestamp, (void **)txp, dummyBlockSize, fp->nb_antennas_tx, flags);
|
||||
int tmp = openair0_write_reorder(dev0, writeTimestamp, (void **)txp, dummyBlockSize, fp->nb_antennas_tx, flags);
|
||||
AssertFatal(tmp == dummyBlockSize, "");
|
||||
|
||||
writeTimestamp += dummyBlockSize;
|
||||
@@ -408,7 +417,7 @@ static void RU_write(nr_rxtx_thread_data_t *rxtxD, bool sl_tx_action, c16_t **tx
|
||||
writeBlockSize);
|
||||
}
|
||||
|
||||
int tmp = openair0_write_reorder(&UE->rfdevice, writeTimestamp, (void **)txp, writeBlockSize, fp->nb_antennas_tx, flags);
|
||||
int tmp = openair0_write_reorder(dev0, writeTimestamp, (void **)txp, writeBlockSize, fp->nb_antennas_tx, flags);
|
||||
AssertFatal(tmp == writeBlockSize, "");
|
||||
}
|
||||
|
||||
@@ -523,10 +532,12 @@ static int handle_sync_req_from_mac(PHY_VARS_NR_UE *UE)
|
||||
ul_CarrierFreq,
|
||||
cfg->dl_frequency,
|
||||
UE->target_Nid_cell);
|
||||
openair0_config_t *cfg0 = &openair0_cfg[UE->rf_map.card];
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
fp->dl_CarrierFreq = dl_CarrierFreq;
|
||||
fp->ul_CarrierFreq = ul_CarrierFreq;
|
||||
nr_rf_card_config_freq(&UE->openair0_cfg[UE->rf_map.card], ul_CarrierFreq, dl_CarrierFreq, 0);
|
||||
UE->rfdevice.trx_set_freq_func(&UE->rfdevice, &UE->openair0_cfg[UE->rf_map.card]);
|
||||
nr_rf_card_config_freq(cfg0, ul_CarrierFreq, dl_CarrierFreq, 0);
|
||||
dev0->trx_set_freq_func(dev0, cfg0);
|
||||
init_symbol_rotation(fp);
|
||||
}
|
||||
|
||||
@@ -650,6 +661,7 @@ void UE_dl_processing(void *arg) {
|
||||
void dummyWrite(PHY_VARS_NR_UE *UE, openair0_timestamp_t timestamp, int writeBlockSize)
|
||||
{
|
||||
NR_DL_FRAME_PARMS *fp = &UE->frame_parms;
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
if (UE->sl_mode == 2)
|
||||
fp = &UE->SL_UE_PHY_PARAMS.sl_frame_params;
|
||||
|
||||
@@ -660,13 +672,14 @@ void dummyWrite(PHY_VARS_NR_UE *UE, openair0_timestamp_t timestamp, int writeBlo
|
||||
for (int i = 0; i < fp->nb_antennas_tx; i++)
|
||||
dummy_tx[i]=dummy_tx_data[i];
|
||||
|
||||
int tmp = UE->rfdevice.trx_write_func(&UE->rfdevice, timestamp, dummy_tx, writeBlockSize, fp->nb_antennas_tx, 4);
|
||||
int tmp = dev0->trx_write_func(dev0, timestamp, dummy_tx, writeBlockSize, fp->nb_antennas_tx, 4);
|
||||
AssertFatal(writeBlockSize == tmp, "");
|
||||
}
|
||||
|
||||
void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp_t *timestamp, int duration_rx_to_tx, bool toTrash)
|
||||
{
|
||||
NR_DL_FRAME_PARMS *fp = &UE->frame_parms;
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
// two frames for initial sync
|
||||
int num_frames = 2;
|
||||
// In Sidelink worst case SL-SSB can be sent once in 16 frames
|
||||
@@ -688,7 +701,7 @@ void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp_t *timestamp, int duration
|
||||
((void *)&UE->common_vars.rxdata[i][0]) + 4 * ((x * fp->samples_per_subframe) + get_samples_slot_timestamp(fp, slot));
|
||||
|
||||
int read_block_size = get_samples_per_slot(slot, fp);
|
||||
int tmp = UE->rfdevice.trx_read_func(&UE->rfdevice, timestamp, rxp, read_block_size, fp->nb_antennas_rx);
|
||||
int tmp = dev0->trx_read_func(dev0, timestamp, rxp, read_block_size, fp->nb_antennas_rx);
|
||||
UEscopeCopy(UE, ueTimeDomainSamplesBeforeSync, rxp[0], sizeof(c16_t), 1, read_block_size, 0);
|
||||
AssertFatal(read_block_size == tmp, "");
|
||||
|
||||
@@ -709,6 +722,7 @@ void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp_t *timestamp, int duration
|
||||
static void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp_t *timestamp, int duration_rx_to_tx, openair0_timestamp_t rx_offset)
|
||||
{
|
||||
NR_DL_FRAME_PARMS *fp = &UE->frame_parms;
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
if (UE->sl_mode == 2)
|
||||
fp = &UE->SL_UE_PHY_PARAMS.sl_frame_params;
|
||||
|
||||
@@ -718,7 +732,7 @@ static void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp_t *timestamp, int
|
||||
int size = rx_offset;
|
||||
while (size > 0) {
|
||||
const int unitTransfer = min(get_samples_per_slot(slot, fp), size);
|
||||
const int res = UE->rfdevice.trx_read_func(&UE->rfdevice, timestamp, (void **)UE->common_vars.rxdata, unitTransfer, fp->nb_antennas_rx);
|
||||
const int res = dev0->trx_read_func(dev0, timestamp, (void **)UE->common_vars.rxdata, unitTransfer, fp->nb_antennas_rx);
|
||||
DevAssert(unitTransfer == res);
|
||||
if (IS_SOFTMODEM_RFSIM) {
|
||||
int ta = UE->timing_advance + UE->timing_advance_ntn;
|
||||
@@ -747,11 +761,13 @@ void *UE_thread(void *arg)
|
||||
{
|
||||
//this thread should be over the processing thread to keep in real time
|
||||
PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg;
|
||||
openair0_config_t *cfg0 = &openair0_cfg[UE->rf_map.card];
|
||||
openair0_device_t *dev0 = &openair0_dev[UE->rf_map.card];
|
||||
// int tx_enabled = 0;
|
||||
void *rxp[NB_ANTENNAS_RX];
|
||||
enum stream_status_e stream_status = STREAM_STATUS_UNSYNC;
|
||||
fapi_nr_config_request_t *cfg = &UE->nrUE_config;
|
||||
int tmp = openair0_device_load(&(UE->rfdevice), &UE->openair0_cfg[0]);
|
||||
int tmp = openair0_device_load(dev0, cfg0);
|
||||
AssertFatal(tmp == 0, "Could not load the device\n");
|
||||
NR_DL_FRAME_PARMS *fp = &UE->frame_parms;
|
||||
sl_nr_phy_config_request_t *sl_cfg = NULL;
|
||||
@@ -760,12 +776,12 @@ void *UE_thread(void *arg)
|
||||
sl_cfg = &UE->SL_UE_PHY_PARAMS.sl_config;
|
||||
}
|
||||
|
||||
UE->rfdevice.host_type = RAU_HOST;
|
||||
dev0->host_type = RAU_HOST;
|
||||
UE->is_synchronized = 0;
|
||||
int tmp2 = UE->rfdevice.trx_start_func(&UE->rfdevice);
|
||||
int tmp2 = dev0->trx_start_func(dev0);
|
||||
AssertFatal(tmp2 == 0, "Could not start the device\n");
|
||||
if (usrp_tx_thread == 1)
|
||||
UE->rfdevice.trx_write_init(&UE->rfdevice);
|
||||
dev0->trx_write_init(dev0);
|
||||
|
||||
InitSinLUT();
|
||||
|
||||
@@ -846,7 +862,7 @@ void *UE_thread(void *arg)
|
||||
/* For IQ recorder-player we force synchronization to happen in a fixed duration so that
|
||||
the replay runs in sync with recorded samples.
|
||||
*/
|
||||
const unsigned int sync_in_frames = UE->rfdevice.openair0_cfg->recplay_conf->u_f_sync;
|
||||
const unsigned int sync_in_frames = cfg0->recplay_conf->u_f_sync;
|
||||
while (trashed_frames != sync_in_frames) {
|
||||
readFrame(UE, &sync_timestamp, duration_rx_to_tx, true);
|
||||
trashed_frames += 2;
|
||||
@@ -887,16 +903,16 @@ void *UE_thread(void *arg)
|
||||
if (stream_status == STREAM_STATUS_UNSYNC) {
|
||||
stream_status = STREAM_STATUS_SYNCING;
|
||||
syncInFrame(UE, &sync_timestamp, duration_rx_to_tx, intialSyncOffset);
|
||||
openair0_write_reorder_clear_context(&UE->rfdevice);
|
||||
openair0_write_reorder_clear_context(dev0);
|
||||
shiftForNextFrame = -(UE->init_sync_frame + trashed_frames + 2) * UE->max_pos_acc * get_nrUE_params()->time_sync_I; // compensate for the time drift that happened during initial sync
|
||||
LOG_I(PHY, "max_pos_acc = %d, shiftForNextFrame = %d\n", UE->max_pos_acc, shiftForNextFrame);
|
||||
// read in first symbol
|
||||
AssertFatal(fp->ofdm_symbol_size + fp->nb_prefix_samples0
|
||||
== UE->rfdevice.trx_read_func(&UE->rfdevice,
|
||||
&sync_timestamp,
|
||||
(void **)UE->common_vars.rxdata,
|
||||
fp->ofdm_symbol_size + fp->nb_prefix_samples0,
|
||||
fp->nb_antennas_rx),
|
||||
== dev0->trx_read_func(dev0,
|
||||
&sync_timestamp,
|
||||
(void **)UE->common_vars.rxdata,
|
||||
fp->ofdm_symbol_size + fp->nb_prefix_samples0,
|
||||
fp->nb_antennas_rx),
|
||||
"");
|
||||
// we have the decoded frame index in the return of the synch process
|
||||
// and we shifted above to the first slot of next frame
|
||||
@@ -997,7 +1013,7 @@ void *UE_thread(void *arg)
|
||||
|
||||
const int readBlockSize = get_readBlockSize(slot_nr, fp) - iq_shift_to_apply;
|
||||
openair0_timestamp_t rx_timestamp;
|
||||
int tmp = UE->rfdevice.trx_read_func(&UE->rfdevice, &rx_timestamp, rxp, readBlockSize, fp->nb_antennas_rx);
|
||||
int tmp = dev0->trx_read_func(dev0, &rx_timestamp, rxp, readBlockSize, fp->nb_antennas_rx);
|
||||
metadata meta = {.slot = curMsg.proc.nr_slot_rx, .frame = curMsg.proc.frame_rx};
|
||||
UEscopeCopyWithMetadata(UE, ueTimeDomainSamples, rxp[0] - firstSymSamp * sizeof(c16_t), sizeof(c16_t), 1, readBlockSize, 0, &meta);
|
||||
AssertFatal(readBlockSize == tmp, "");
|
||||
@@ -1012,11 +1028,7 @@ void *UE_thread(void *arg)
|
||||
|
||||
if (first_symbols > 0) {
|
||||
openair0_timestamp_t ignore_timestamp;
|
||||
int tmp = UE->rfdevice.trx_read_func(&UE->rfdevice,
|
||||
&ignore_timestamp,
|
||||
(void **)UE->common_vars.rxdata,
|
||||
first_symbols,
|
||||
fp->nb_antennas_rx);
|
||||
int tmp = dev0->trx_read_func(dev0, &ignore_timestamp, (void **)UE->common_vars.rxdata, first_symbols, fp->nb_antennas_rx);
|
||||
AssertFatal(first_symbols == tmp, "");
|
||||
|
||||
} else
|
||||
@@ -1029,7 +1041,7 @@ void *UE_thread(void *arg)
|
||||
|
||||
// Calculate TX deadline, approximately 1 symbol before the first sample should be written
|
||||
const uint64_t samples_diff = writeTimestamp - rx_timestamp - fp->ofdm_symbol_size;
|
||||
const float deadline_us = samples_diff / UE->rfdevice.openair0_cfg->sample_rate * 1e6;
|
||||
const float deadline_us = samples_diff / cfg0->sample_rate * 1e6;
|
||||
const uint64_t absolute_deadline_us = current_time.tv_sec * 1e6 + current_time.tv_nsec / 1e3 + deadline_us;
|
||||
|
||||
// but use current UE->timing_advance value to compute writeBlockSize
|
||||
|
||||
Reference in New Issue
Block a user