Commit c5e4bea6 authored by Laurent THOMAS's avatar Laurent THOMAS

make explicit return of the clock drift to shift the corresponding number of samples

remove corresponding global variables
parent b99e8567
...@@ -439,11 +439,13 @@ static void UE_synch(void *arg) { ...@@ -439,11 +439,13 @@ static void UE_synch(void *arg) {
uint64_t dl_carrier, ul_carrier; uint64_t dl_carrier, ul_carrier;
nr_get_carrier_frequencies(UE, &dl_carrier, &ul_carrier); nr_get_carrier_frequencies(UE, &dl_carrier, &ul_carrier);
nr_initial_sync_t ret = nr_initial_sync(&syncD->proc, UE, 2, get_softmodem_params()->sa);
if (nr_initial_sync(&syncD->proc, UE, 2, get_softmodem_params()->sa) == 0) { if (!ret.cell_notdetected) {
syncD->rx_offset = ret.rx_offset;
freq_offset = UE->common_vars.freq_offset; // frequency offset computed with pss in initial sync freq_offset = UE->common_vars.freq_offset; // frequency offset computed with pss in initial sync
hw_slot_offset = ((UE->rx_offset<<1) / UE->frame_parms.samples_per_subframe * UE->frame_parms.slots_per_subframe) + hw_slot_offset =
round((float)((UE->rx_offset<<1) % UE->frame_parms.samples_per_subframe)/UE->frame_parms.samples_per_slot0); ((ret.rx_offset << 1) / UE->frame_parms.samples_per_subframe * UE->frame_parms.slots_per_subframe)
+ round((float)((ret.rx_offset << 1) % UE->frame_parms.samples_per_subframe) / UE->frame_parms.samples_per_slot0);
// rerun with new cell parameters and frequency-offset // rerun with new cell parameters and frequency-offset
// todo: the freq_offset computed on DL shall be scaled before being applied to UL // todo: the freq_offset computed on DL shall be scaled before being applied to UL
...@@ -462,7 +464,6 @@ static void UE_synch(void *arg) { ...@@ -462,7 +464,6 @@ static void UE_synch(void *arg) {
else else
UE->is_synchronized = 1; UE->is_synchronized = 1;
} else { } else {
if (UE->UE_scan_carrier == 1) { if (UE->UE_scan_carrier == 1) {
if (freq_offset >= 0) if (freq_offset >= 0)
...@@ -607,8 +608,9 @@ void processSlotTX(void *arg) ...@@ -607,8 +608,9 @@ void processSlotTX(void *arg)
RU_write(rxtxD); RU_write(rxtxD);
} }
static void UE_dl_preprocessing(PHY_VARS_NR_UE *UE, const UE_nr_rxtx_proc_t *proc, int *tx_wait_for_dlsch, nr_phy_data_t *phy_data) static int UE_dl_preprocessing(PHY_VARS_NR_UE *UE, const UE_nr_rxtx_proc_t *proc, int *tx_wait_for_dlsch, nr_phy_data_t *phy_data)
{ {
int sampleShift = 0;
if (IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa) { if (IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa) {
// Start synchronization with a target gNB // Start synchronization with a target gNB
...@@ -636,20 +638,16 @@ static void UE_dl_preprocessing(PHY_VARS_NR_UE *UE, const UE_nr_rxtx_proc_t *pro ...@@ -636,20 +638,16 @@ static void UE_dl_preprocessing(PHY_VARS_NR_UE *UE, const UE_nr_rxtx_proc_t *pro
UE->if_inst->dl_indication(&dl_indication); UE->if_inst->dl_indication(&dl_indication);
} }
uint64_t a=rdtsc_oai(); sampleShift = pbch_pdcch_processing(UE, proc, phy_data);
pbch_pdcch_processing(UE, proc, phy_data);
if (phy_data->dlsch[0].active && phy_data->dlsch[0].rnti_type == TYPE_C_RNTI_) { if (phy_data->dlsch[0].active && phy_data->dlsch[0].rnti_type == TYPE_C_RNTI_) {
// indicate to tx thread to wait for DLSCH decoding // indicate to tx thread to wait for DLSCH decoding
const int ack_nack_slot = (proc->nr_slot_rx + phy_data->dlsch[0].dlsch_config.k1_feedback) % UE->frame_parms.slots_per_frame; const int ack_nack_slot = (proc->nr_slot_rx + phy_data->dlsch[0].dlsch_config.k1_feedback) % UE->frame_parms.slots_per_frame;
LOG_D(NR_PHY, "Adding one event to wait after decoding slot %d, for futre tx slot %d\n", proc->nr_slot_rx, ack_nack_slot);
tx_wait_for_dlsch[ack_nack_slot]++; tx_wait_for_dlsch[ack_nack_slot]++;
} }
LOG_D(PHY, "In %s: slot %d, time %llu\n", __FUNCTION__, proc->nr_slot_rx, (rdtsc_oai()-a)/3500);
} }
ue_ta_procedures(UE, proc->nr_slot_tx, proc->frame_tx); ue_ta_procedures(UE, proc->nr_slot_tx, proc->frame_tx);
return; return sampleShift;
} }
void UE_dl_processing(void *arg) { void UE_dl_processing(void *arg) {
...@@ -710,34 +708,36 @@ void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp, bool toTrash) ...@@ -710,34 +708,36 @@ void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp, bool toTrash)
} }
void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { static void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp, int rx_offset)
{
LOG_I(PHY,"Resynchronizing RX by %d samples\n",UE->rx_offset); LOG_I(PHY, "Resynchronizing RX by %d samples\n", rx_offset);
if (IS_SOFTMODEM_IQPLAYER || IS_SOFTMODEM_IQRECORDER) { if (IS_SOFTMODEM_IQPLAYER || IS_SOFTMODEM_IQRECORDER) {
// Resynchonize by slot (will work with numerology 1 only) // Resynchonize by slot (will work with numerology 1 only)
for ( int size=UE->rx_offset ; size > 0 ; size -= UE->frame_parms.samples_per_subframe/2 ) { for (int size = rx_offset; size > 0; size -= UE->frame_parms.samples_per_subframe / 2) {
int unitTransfer=size>UE->frame_parms.samples_per_subframe/2 ? UE->frame_parms.samples_per_subframe/2 : size ; int unitTransfer = size > UE->frame_parms.samples_per_subframe / 2 ? UE->frame_parms.samples_per_subframe / 2 : size;
AssertFatal(unitTransfer == AssertFatal(unitTransfer
UE->rfdevice.trx_read_func(&UE->rfdevice, == UE->rfdevice.trx_read_func(&UE->rfdevice,
timestamp, timestamp,
(void **)UE->common_vars.rxdata, (void **)UE->common_vars.rxdata,
unitTransfer, unitTransfer,
UE->frame_parms.nb_antennas_rx),""); UE->frame_parms.nb_antennas_rx),
"");
} }
} else { } else {
*timestamp += UE->frame_parms.get_samples_per_slot(1,&UE->frame_parms); *timestamp += UE->frame_parms.get_samples_per_slot(1, &UE->frame_parms);
for ( int size=UE->rx_offset ; size > 0 ; size -= UE->frame_parms.samples_per_subframe ) { for (int size = rx_offset; size > 0; size -= UE->frame_parms.samples_per_subframe) {
int unitTransfer=size>UE->frame_parms.samples_per_subframe ? UE->frame_parms.samples_per_subframe : size ; int unitTransfer = size > UE->frame_parms.samples_per_subframe ? UE->frame_parms.samples_per_subframe : size;
// we write before read because gNB waits for UE to write and both executions halt // we write before read because gNB waits for UE to write and both executions halt
// this happens here as the read size is samples_per_subframe which is very much larger than samp_per_slot // this happens here as the read size is samples_per_subframe which is very much larger than samp_per_slot
if (IS_SOFTMODEM_RFSIM) dummyWrite(UE,*timestamp, unitTransfer); if (IS_SOFTMODEM_RFSIM)
AssertFatal(unitTransfer == dummyWrite(UE, *timestamp, unitTransfer);
UE->rfdevice.trx_read_func(&UE->rfdevice, AssertFatal(unitTransfer
== UE->rfdevice.trx_read_func(&UE->rfdevice,
timestamp, timestamp,
(void **)UE->common_vars.rxdata, (void **)UE->common_vars.rxdata,
unitTransfer, unitTransfer,
UE->frame_parms.nb_antennas_rx),""); UE->frame_parms.nb_antennas_rx),
"");
*timestamp += unitTransfer; // this does not affect the read but needed for RFSIM write *timestamp += unitTransfer; // this does not affect the read but needed for RFSIM write
} }
} }
...@@ -764,8 +764,6 @@ void *UE_thread(void *arg) ...@@ -764,8 +764,6 @@ void *UE_thread(void *arg)
//this thread should be over the processing thread to keep in real time //this thread should be over the processing thread to keep in real time
PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg;
// int tx_enabled = 0; // int tx_enabled = 0;
openair0_timestamp timestamp = 0;
openair0_timestamp writeTimestamp = 0;
void *rxp[NB_ANTENNAS_RX]; void *rxp[NB_ANTENNAS_RX];
int start_rx_stream = 0; int start_rx_stream = 0;
fapi_nr_config_request_t *cfg = &UE->nrUE_config; fapi_nr_config_request_t *cfg = &UE->nrUE_config;
...@@ -796,9 +794,10 @@ void *UE_thread(void *arg) ...@@ -796,9 +794,10 @@ void *UE_thread(void *arg)
for(int i=0; i < num_ind_fifo; i++) { for(int i=0; i < num_ind_fifo; i++) {
initNotifiedFIFO(UE->tx_resume_ind_fifo + i); initNotifiedFIFO(UE->tx_resume_ind_fifo + i);
} }
int shiftForNextFrame = 0;
int intialSyncOffset = 0;
openair0_timestamp sync_timestamp;
while (!oai_exit) { while (!oai_exit) {
if (syncRunning) { if (syncRunning) {
notifiedFIFO_elt_t *res=tryPullTpool(&nf,&(get_nrUE_params()->Tpool)); notifiedFIFO_elt_t *res=tryPullTpool(&nf,&(get_nrUE_params()->Tpool));
...@@ -806,25 +805,28 @@ void *UE_thread(void *arg) ...@@ -806,25 +805,28 @@ void *UE_thread(void *arg)
syncRunning=false; syncRunning=false;
if (UE->is_synchronized) { if (UE->is_synchronized) {
decoded_frame_rx = mac->mib_frame; decoded_frame_rx = mac->mib_frame;
LOG_I(PHY,"UE synchronized decoded_frame_rx=%d UE->init_sync_frame=%d trashed_frames=%d\n", LOG_A(PHY,
"UE synchronized! decoded_frame_rx=%d UE->init_sync_frame=%d trashed_frames=%d\n",
decoded_frame_rx, decoded_frame_rx,
UE->init_sync_frame, UE->init_sync_frame,
trashed_frames); trashed_frames);
// shift the frame index with all the frames we trashed meanwhile we perform the synch search // shift the frame index with all the frames we trashed meanwhile we perform the synch search
decoded_frame_rx = (decoded_frame_rx + UE->init_sync_frame + trashed_frames) % MAX_FRAME_NUMBER; decoded_frame_rx = (decoded_frame_rx + UE->init_sync_frame + trashed_frames) % MAX_FRAME_NUMBER;
syncData_t *syncMsg = (syncData_t *)NotifiedFifoData(res);
intialSyncOffset = syncMsg->rx_offset;
} }
delNotifiedFIFO_elt(res); delNotifiedFIFO_elt(res);
start_rx_stream=0; start_rx_stream=0;
} else { } else {
if (IS_SOFTMODEM_IQPLAYER || IS_SOFTMODEM_IQRECORDER) { if (IS_SOFTMODEM_IQPLAYER || IS_SOFTMODEM_IQRECORDER) {
// For IQ recorder/player we force synchronization to happen in 280 ms // For IQ recorder-player we force synchronization to happen in 280 ms
while (trashed_frames != 28) { while (trashed_frames != 28) {
readFrame(UE, &timestamp, true); readFrame(UE, &sync_timestamp, true);
trashed_frames+=2; trashed_frames += 2;
} }
} else { } else {
readFrame(UE, &timestamp, true); readFrame(UE, &sync_timestamp, true);
trashed_frames+=2; trashed_frames += 2;
} }
continue; continue;
} }
...@@ -833,7 +835,7 @@ void *UE_thread(void *arg) ...@@ -833,7 +835,7 @@ void *UE_thread(void *arg)
AssertFatal(!syncRunning, "At this point synchronization can't be running\n"); AssertFatal(!syncRunning, "At this point synchronization can't be running\n");
if (!UE->is_synchronized) { if (!UE->is_synchronized) {
readFrame(UE, &timestamp, false); readFrame(UE, &sync_timestamp, false);
notifiedFIFO_elt_t *Msg = newNotifiedFIFO_elt(sizeof(syncData_t), 0, &nf, UE_synch); notifiedFIFO_elt_t *Msg = newNotifiedFIFO_elt(sizeof(syncData_t), 0, &nf, UE_synch);
syncData_t *syncMsg = (syncData_t *)NotifiedFifoData(Msg); syncData_t *syncMsg = (syncData_t *)NotifiedFifoData(Msg);
syncMsg->UE = UE; syncMsg->UE = UE;
...@@ -846,16 +848,16 @@ void *UE_thread(void *arg) ...@@ -846,16 +848,16 @@ void *UE_thread(void *arg)
if (start_rx_stream == 0) { if (start_rx_stream == 0) {
start_rx_stream=1; start_rx_stream=1;
syncInFrame(UE, &timestamp); syncInFrame(UE, &sync_timestamp, intialSyncOffset);
UE->rx_offset=0; shiftForNextFrame = 0; // will be used to track clock drift
UE->time_sync_cell=0;
// read in first symbol // read in first symbol
AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == AssertFatal(UE->frame_parms.ofdm_symbol_size + UE->frame_parms.nb_prefix_samples0
UE->rfdevice.trx_read_func(&UE->rfdevice, == UE->rfdevice.trx_read_func(&UE->rfdevice,
&timestamp, &sync_timestamp,
(void **)UE->common_vars.rxdata, (void **)UE->common_vars.rxdata,
UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, UE->frame_parms.ofdm_symbol_size + UE->frame_parms.nb_prefix_samples0,
UE->frame_parms.nb_antennas_rx),""); UE->frame_parms.nb_antennas_rx),
"");
// we have the decoded frame index in the return of the synch process // we have the decoded frame index in the return of the synch process
// and we shifted above to the first slot of next frame // and we shifted above to the first slot of next frame
decoded_frame_rx++; decoded_frame_rx++;
...@@ -871,7 +873,7 @@ void *UE_thread(void *arg) ...@@ -871,7 +873,7 @@ void *UE_thread(void *arg)
continue; continue;
} }
// start of normal case, the UE is in sync
absolute_slot++; absolute_slot++;
int slot_nr = absolute_slot % nb_slot_frame; int slot_nr = absolute_slot % nb_slot_frame;
...@@ -893,26 +895,21 @@ void *UE_thread(void *arg) ...@@ -893,26 +895,21 @@ void *UE_thread(void *arg)
int firstSymSamp = get_firstSymSamp(slot_nr, &UE->frame_parms); int firstSymSamp = get_firstSymSamp(slot_nr, &UE->frame_parms);
for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++) for (int i=0; i<UE->frame_parms.nb_antennas_rx; i++)
rxp[i] = (void *)&UE->common_vars.rxdata[i][firstSymSamp+ rxp[i] = (void *)&UE->common_vars
UE->frame_parms.get_samples_slot_timestamp(slot_nr,&UE->frame_parms,0)]; .rxdata[i][firstSymSamp + UE->frame_parms.get_samples_slot_timestamp(slot_nr, &UE->frame_parms, 0)];
int readBlockSize, writeBlockSize;
readBlockSize = get_readBlockSize(slot_nr, &UE->frame_parms); int iq_shift_to_apply = 0;
writeBlockSize = UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms); if (slot_nr == nb_slot_frame - 1) {
if (UE->apply_timing_offset && (slot_nr == nb_slot_frame - 1)) { // we shift of half of measured drift, at each beginning of frame for both rx and tx
const int sampShift = -(UE->rx_offset>>1); iq_shift_to_apply = shiftForNextFrame;
readBlockSize -= sampShift; shiftForNextFrame = 0; // We will get a new measured offset if we decode PBCH
writeBlockSize -= sampShift;
UE->apply_timing_offset = false;
} }
AssertFatal(readBlockSize == const int readBlockSize = get_readBlockSize(slot_nr, &UE->frame_parms) - iq_shift_to_apply;
UE->rfdevice.trx_read_func(&UE->rfdevice, openair0_timestamp rx_timestamp;
&timestamp, AssertFatal(readBlockSize
rxp, == UE->rfdevice.trx_read_func(&UE->rfdevice, &rx_timestamp, rxp, readBlockSize, UE->frame_parms.nb_antennas_rx),
readBlockSize, "");
UE->frame_parms.nb_antennas_rx),"");
if(slot_nr == (nb_slot_frame - 1)) { if(slot_nr == (nb_slot_frame - 1)) {
// read in first symbol of next frame and adjust for timing drift // read in first symbol of next frame and adjust for timing drift
...@@ -931,11 +928,13 @@ void *UE_thread(void *arg) ...@@ -931,11 +928,13 @@ void *UE_thread(void *arg)
} }
// use previous timing_advance value to compute writeTimestamp // use previous timing_advance value to compute writeTimestamp
writeTimestamp = timestamp + const openair0_timestamp writeTimestamp =
UE->frame_parms.get_samples_slot_timestamp(slot_nr,&UE->frame_parms,DURATION_RX_TO_TX) rx_timestamp + UE->frame_parms.get_samples_slot_timestamp(slot_nr, &UE->frame_parms, DURATION_RX_TO_TX) - firstSymSamp
- firstSymSamp - UE->N_TA_offset - timing_advance; - UE->N_TA_offset - timing_advance;
// but use current UE->timing_advance value to compute writeBlockSize // but use current UE->timing_advance value to compute writeBlockSize
int writeBlockSize =
UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms) - iq_shift_to_apply;
if (UE->timing_advance != timing_advance) { if (UE->timing_advance != timing_advance) {
writeBlockSize -= UE->timing_advance - timing_advance; writeBlockSize -= UE->timing_advance - timing_advance;
timing_advance = UE->timing_advance; timing_advance = UE->timing_advance;
...@@ -948,7 +947,12 @@ void *UE_thread(void *arg) ...@@ -948,7 +947,12 @@ void *UE_thread(void *arg)
notifiedFIFO_elt_t *newRx = newNotifiedFIFO_elt(sizeof(nr_rxtx_thread_data_t), curMsg.proc.nr_slot_rx, NULL, UE_dl_processing); notifiedFIFO_elt_t *newRx = newNotifiedFIFO_elt(sizeof(nr_rxtx_thread_data_t), curMsg.proc.nr_slot_rx, NULL, UE_dl_processing);
nr_rxtx_thread_data_t *curMsgRx = (nr_rxtx_thread_data_t *)NotifiedFifoData(newRx); nr_rxtx_thread_data_t *curMsgRx = (nr_rxtx_thread_data_t *)NotifiedFifoData(newRx);
*curMsgRx = (nr_rxtx_thread_data_t){.proc = curMsg.proc, .UE = UE}; *curMsgRx = (nr_rxtx_thread_data_t){.proc = curMsg.proc, .UE = UE};
UE_dl_preprocessing(UE, &curMsgRx->proc, tx_wait_for_dlsch, &curMsgRx->phy_data); int ret = UE_dl_preprocessing(UE, &curMsgRx->proc, tx_wait_for_dlsch, &curMsgRx->phy_data);
if (ret)
// if ret is 0, no rx_offset has been computed,
// or the computed value is 0 = no offset to do
// we store it to apply the drift compensation at beginning of next frame
shiftForNextFrame = ret;
pushTpool(&(get_nrUE_params()->Tpool), newRx); pushTpool(&(get_nrUE_params()->Tpool), newRx);
// Start TX slot processing here. It runs in parallel with RX slot processing // Start TX slot processing here. It runs in parallel with RX slot processing
......
...@@ -33,29 +33,22 @@ ...@@ -33,29 +33,22 @@
// The adjustment is performed once per frame based on the // The adjustment is performed once per frame based on the
// last channel estimate of the receiver // last channel estimate of the receiver
void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, int nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
PHY_VARS_NR_UE *ue, PHY_VARS_NR_UE *ue,
module_id_t gNB_id, module_id_t gNB_id,
const int estimateSz, const int estimateSz,
struct complex16 dl_ch_estimates_time[][estimateSz], struct complex16 dl_ch_estimates_time[][estimateSz],
uint8_t frame, uint8_t frame,
uint8_t subframe, uint8_t slot,
unsigned char clear,
short coef) short coef)
{ {
static int count_max_pos_ok = 0;
static int first_time = 1;
int max_val = 0, max_pos = 0; int max_val = 0, max_pos = 0;
const int sync_pos = 0;
uint8_t sync_offset = 0; uint8_t sync_offset = 0;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_IN); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_IN);
short ncoef = 32767 - coef; short ncoef = 32767 - coef;
LOG_D(PHY,"AbsSubframe %d: rx_offset (before) = %d\n",subframe,ue->rx_offset);
// search for maximum position within the cyclic prefix // search for maximum position within the cyclic prefix
for (int i = -frame_parms->nb_prefix_samples/2; i < frame_parms->nb_prefix_samples/2; i++) { for (int i = -frame_parms->nb_prefix_samples/2; i < frame_parms->nb_prefix_samples/2; i++) {
int temp = 0; int temp = 0;
...@@ -74,53 +67,32 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, ...@@ -74,53 +67,32 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
} }
// filter position to reduce jitter // filter position to reduce jitter
if (clear == 1) ue->max_pos_avg = ((ue->max_pos_avg * coef) >> 15) + (max_pos * ncoef);
ue->max_pos_fil = max_pos << 15;
else
ue->max_pos_fil = ((ue->max_pos_fil * coef) >> 15) + (max_pos * ncoef);
// do not filter to have proactive timing adjustment int diff = ue->max_pos_avg >> 15;
//ue->max_pos_fil = max_pos << 15;
int diff = (ue->max_pos_fil >> 15) - sync_pos;
if (frame_parms->freq_range==nr_FR2) if (frame_parms->freq_range==nr_FR2)
sync_offset = 2; sync_offset = 2;
else else
sync_offset = 0; sync_offset = 0;
if ( abs(diff) < (SYNCH_HYST+sync_offset) ) int sampleShift = 0;
ue->rx_offset = 0; if (abs(diff) > (NR_SYNCH_HYST + sync_offset))
else sampleShift = diff;
ue->rx_offset = diff;
const int sample_shift = -(ue->rx_offset>>1); const int sample_shift = -(sampleShift / 2);
// reset IIR filter for next offset calculation // reset IIR filter for next offset calculation
ue->max_pos_fil += sample_shift * 32768; ue->max_pos_avg += sample_shift * 32768;
if(abs(diff)<5)
count_max_pos_ok ++;
else
count_max_pos_ok = 0;
//printf("adjust sync count_max_pos_ok = %d\n",count_max_pos_ok);
if(count_max_pos_ok > 10 && first_time == 1) {
first_time = 0;
ue->time_sync_cell = 1;
}
#ifdef DEBUG_PHY LOG_D(PHY,
LOG_I(PHY,"AbsSubframe %d: diff = %i, rx_offset (final) = %i : clear = %d, max_pos = %d, max_pos_fil = %d, max_val = %d, sync_pos %d\n", "Slot %d: diff = %i, rx_offset (final) = %i : max_pos = %d, max_pos filtered = %ld, max_power = %d\n",
subframe, slot,
diff, diff,
ue->rx_offset, sampleShift,
clear,
max_pos, max_pos,
ue->max_pos_fil, ue->max_pos_avg,
max_val, max_val);
sync_pos);
#endif //DEBUG_PHY
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_OUT);
return sample_shift;
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
*/ */
/*!\brief Timing drift hysterisis in samples*/ /*!\brief Timing drift hysterisis in samples*/
#define SYNCH_HYST 2 #define NR_SYNCH_HYST 1
/* A function to perform the channel estimation of DL PRS signal */ /* A function to perform the channel estimation of DL PRS signal */
int nr_prs_channel_estimation(uint8_t gNB_id, int nr_prs_channel_estimation(uint8_t gNB_id,
...@@ -91,14 +91,13 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, ...@@ -91,14 +91,13 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue,
int rxdataFsize, int rxdataFsize,
c16_t rxdataF[][rxdataFsize]); c16_t rxdataF[][rxdataFsize]);
void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, int nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
PHY_VARS_NR_UE *ue, PHY_VARS_NR_UE *ue,
module_id_t gNB_id, module_id_t gNB_id,
int estimateSz, int estimateSz,
struct complex16 dl_ch_estimates_time [][estimateSz], struct complex16 dl_ch_estimates_time[][estimateSz],
uint8_t frame, uint8_t frame,
uint8_t subframe, uint8_t subframe,
unsigned char clear,
short coef); short coef);
void nr_ue_measurements(PHY_VARS_NR_UE *ue, void nr_ue_measurements(PHY_VARS_NR_UE *ue,
......
...@@ -50,7 +50,7 @@ extern openair0_config_t openair0_cfg[]; ...@@ -50,7 +50,7 @@ extern openair0_config_t openair0_cfg[];
//static nfapi_nr_config_request_t* config =&config_t; //static nfapi_nr_config_request_t* config =&config_t;
int cnt=0; int cnt=0;
#define DEBUG_INITIAL_SYNCH // #define DEBUG_INITIAL_SYNCH
#define DUMP_PBCH_CH_ESTIMATES 0 #define DUMP_PBCH_CH_ESTIMATES 0
// create a new node of SSB structure // create a new node of SSB structure
...@@ -111,11 +111,6 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc, ...@@ -111,11 +111,6 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc,
NR_UE_SSB *best_ssb = NULL; NR_UE_SSB *best_ssb = NULL;
NR_UE_SSB *current_ssb; NR_UE_SSB *current_ssb;
#ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY,"[UE%d] Initial sync: starting PBCH detection (rx_offset %d)\n",ue->Mod_id,
ue->rx_offset);
#endif
uint8_t N_L = (frame_parms->Lmax == 4)? 4:8; uint8_t N_L = (frame_parms->Lmax == 4)? 4:8;
uint8_t N_hf = (frame_parms->Lmax == 4)? 2:1; uint8_t N_hf = (frame_parms->Lmax == 4)? 2:1;
...@@ -129,7 +124,7 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc, ...@@ -129,7 +124,7 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc,
start_meas(&ue->dlsch_channel_estimation_stats); start_meas(&ue->dlsch_channel_estimation_stats);
// computing correlation between received DMRS symbols and transmitted sequence for current i_ssb and n_hf // computing correlation between received DMRS symbols and transmitted sequence for current i_ssb and n_hf
for(int i=pbch_initial_symbol; i<pbch_initial_symbol+3;i++) for(int i=pbch_initial_symbol; i<pbch_initial_symbol+3;i++)
nr_pbch_dmrs_correlation(ue,proc,i,i-pbch_initial_symbol,current_ssb,rxdataF); nr_pbch_dmrs_correlation(ue, proc, i, i - pbch_initial_symbol, current_ssb, rxdataF);
stop_meas(&ue->dlsch_channel_estimation_stats); stop_meas(&ue->dlsch_channel_estimation_stats);
current_ssb->metric = current_ssb->c_re*current_ssb->c_re + current_ssb->c_im*current_ssb->c_im; current_ssb->metric = current_ssb->c_re*current_ssb->c_re + current_ssb->c_im*current_ssb->c_im;
...@@ -178,42 +173,30 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc, ...@@ -178,42 +173,30 @@ int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc,
free_list(best_ssb); free_list(best_ssb);
if (ret == 0)
if (ret==0) { frame_parms->nb_antenna_ports_gNB = 1; // pbch_tx_ant;
frame_parms->nb_antenna_ports_gNB = 1; //pbch_tx_ant;
// set initial transmission mode to 1 or 2 depending on number of detected TX antennas // set initial transmission mode to 1 or 2 depending on number of detected TX antennas
//frame_parms->mode1_flag = (pbch_tx_ant==1); // frame_parms->mode1_flag = (pbch_tx_ant==1);
// openair_daq_vars.dlsch_transmission_mode = (pbch_tx_ant>1) ? 2 : 1; // openair_daq_vars.dlsch_transmission_mode = (pbch_tx_ant>1) ? 2 : 1;
#ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY, "[UE%d] Initial sync: pbch decoded sucessfully, ssb index %d\n", ue->Mod_id, frame_parms->ssb_index); LOG_I(PHY, "[UE%d] Initial sync: pbch decoded sucessfully, ssb index %d\n", ue->Mod_id, frame_parms->ssb_index);
#endif return ret;
return(0);
} else {
return(-1);
}
} }
int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_frames, int sa) nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_frames, int sa)
{ {
int32_t sync_pos, sync_pos_frame; // k_ssb, N_ssb_crb, sync_pos2, int32_t sync_pos, sync_pos_frame; // k_ssb, N_ssb_crb, sync_pos2,
int32_t metric_tdd_ncp=0; int32_t metric_tdd_ncp = 0;
uint8_t phase_tdd_ncp; uint8_t phase_tdd_ncp;
int frame_id; int frame_id;
NR_DL_FRAME_PARMS *fp = &ue->frame_parms; NR_DL_FRAME_PARMS *fp = &ue->frame_parms;
int ret=-1; nr_initial_sync_t ret = {true, 0};
int rx_power=0; //aarx,
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_IN); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_IN);
LOG_D(PHY, "nr_initial sync ue RB_DL %d\n", fp->N_RB_DL);
LOG_D(PHY,"nr_initial sync ue RB_DL %d\n", fp->N_RB_DL);
/* Initial synchronisation /* Initial synchronisation
* *
...@@ -229,10 +212,10 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -229,10 +212,10 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
*/ */
const uint32_t rxdataF_sz = ue->frame_parms.samples_per_slot_wCP; const uint32_t rxdataF_sz = ue->frame_parms.samples_per_slot_wCP;
__attribute__ ((aligned(32))) c16_t rxdataF[ue->frame_parms.nb_antennas_rx][rxdataF_sz]; __attribute__((aligned(32))) c16_t rxdataF[ue->frame_parms.nb_antennas_rx][rxdataF_sz];
cnt++; cnt++;
if (1){ // (cnt>100) if (1) { // (cnt>100)
cnt =0; cnt = 0;
// initial sync performed on two successive frames, if pbch passes on first frame, no need to process second frame // initial sync performed on two successive frames, if pbch passes on first frame, no need to process second frame
// only one frame is used for symulation tools // only one frame is used for symulation tools
...@@ -246,22 +229,21 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -246,22 +229,21 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY, "[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos, ue->common_vars.nid2); LOG_I(PHY, "[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n", ue->Mod_id, sync_pos, ue->common_vars.nid2);
LOG_I(PHY,"sync_pos %d ssb_offset %d \n",sync_pos,ue->ssb_offset); LOG_I(PHY, "sync_pos %d ssb_offset %d \n", sync_pos, ue->ssb_offset);
#endif #endif
/* check that SSS/PBCH block is continuous inside the received buffer */ /* check that SSS/PBCH block is continuous inside the received buffer */
if (ue->ssb_offset + NR_N_SYMBOLS_SSB * (fp->ofdm_symbol_size + fp->nb_prefix_samples) < fp->samples_per_frame) { if (ue->ssb_offset + NR_N_SYMBOLS_SSB * (fp->ofdm_symbol_size + fp->nb_prefix_samples) < fp->samples_per_frame) {
// digital compensation of FFO for SSB symbols // digital compensation of FFO for SSB symbols
if (ue->UE_fo_compensation){ if (ue->UE_fo_compensation) {
double s_time = 1/(1.0e3*fp->samples_per_subframe); // sampling time double s_time = 1 / (1.0e3 * fp->samples_per_subframe); // sampling time
double off_angle = -2*M_PI*s_time*(ue->common_vars.freq_offset); // offset rotation angle compensation per sample double off_angle = -2 * M_PI * s_time * (ue->common_vars.freq_offset); // offset rotation angle compensation per sample
// In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1 // In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1
// and we do not know yet in which slot it goes. // and we do not know yet in which slot it goes.
for (int n = frame_id * fp->samples_per_frame; n < (frame_id + 1) * fp->samples_per_frame; n++) { for (int n = frame_id * fp->samples_per_frame; n < (frame_id + 1) * fp->samples_per_frame; n++) {
for (int ar=0; ar<fp->nb_antennas_rx; ar++) { for (int ar = 0; ar < fp->nb_antennas_rx; ar++) {
const double re = ue->common_vars.rxdata[ar][n].r; const double re = ue->common_vars.rxdata[ar][n].r;
const double im = ue->common_vars.rxdata[ar][n].i; const double im = ue->common_vars.rxdata[ar][n].i;
ue->common_vars.rxdata[ar][n].r = (short)(round(re * cos(n * off_angle) - im * sin(n * off_angle))); ue->common_vars.rxdata[ar][n].r = (short)(round(re * cos(n * off_angle) - im * sin(n * off_angle)));
...@@ -283,21 +265,21 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -283,21 +265,21 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
nr_slot_fep_init_sync(ue, proc, i, frame_id * fp->samples_per_frame + ue->ssb_offset, false, rxdataF, link_type_dl); nr_slot_fep_init_sync(ue, proc, i, frame_id * fp->samples_per_frame + ue->ssb_offset, false, rxdataF, link_type_dl);
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY,"Calling sss detection (normal CP)\n"); LOG_I(PHY, "Calling sss detection (normal CP)\n");
#endif #endif
int freq_offset_sss = 0; int freq_offset_sss = 0;
bool ret_sss = rx_sss_nr(ue, proc, &metric_tdd_ncp, &phase_tdd_ncp, &freq_offset_sss, rxdataF); bool ret_sss = rx_sss_nr(ue, proc, &metric_tdd_ncp, &phase_tdd_ncp, &freq_offset_sss, rxdataF);
ret = !ret_sss; ret.cell_notdetected = !ret_sss; // rx_sss_nr returns true if success
// digital compensation of FFO for SSB symbols // digital compensation of FFO for SSB symbols
if (ue->UE_fo_compensation){ if (ue->UE_fo_compensation) {
double s_time = 1/(1.0e3*fp->samples_per_subframe); // sampling time double s_time = 1 / (1.0e3 * fp->samples_per_subframe); // sampling time
double off_angle = -2*M_PI*s_time*freq_offset_sss; // offset rotation angle compensation per sample double off_angle = -2 * M_PI * s_time * freq_offset_sss; // offset rotation angle compensation per sample
// In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1 // In SA we need to perform frequency offset correction until the end of buffer because we need to decode SIB1
// and we do not know yet in which slot it goes. // and we do not know yet in which slot it goes.
for (int n = frame_id * fp->samples_per_frame; n < (frame_id + 1) * fp->samples_per_frame; n++) { for (int n = frame_id * fp->samples_per_frame; n < (frame_id + 1) * fp->samples_per_frame; n++) {
for (int ar=0; ar<fp->nb_antennas_rx; ar++) { for (int ar = 0; ar < fp->nb_antennas_rx; ar++) {
const double re = ue->common_vars.rxdata[ar][n].r; const double re = ue->common_vars.rxdata[ar][n].r;
const double im = ue->common_vars.rxdata[ar][n].i; const double im = ue->common_vars.rxdata[ar][n].i;
ue->common_vars.rxdata[ar][n].r = (short)(round(re * cos(n * off_angle) - im * sin(n * off_angle))); ue->common_vars.rxdata[ar][n].r = (short)(round(re * cos(n * off_angle) - im * sin(n * off_angle)));
...@@ -308,49 +290,48 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -308,49 +290,48 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
ue->common_vars.freq_offset += freq_offset_sss; ue->common_vars.freq_offset += freq_offset_sss;
} }
if (ret==0) { //we got sss channel if (ret.cell_notdetected == 0) { // we got sss channel
nr_gold_pbch(ue); nr_gold_pbch(ue);
ret = nr_pbch_detection(proc, ue, 1, rxdataF); // start pbch detection at first symbol after pss ret.cell_notdetected = nr_pbch_detection(proc, ue, 1, rxdataF); // start pbch detection at first symbol after pss
} }
if (ret == 0) { if (ret.cell_notdetected == 0) {
// sync at symbol ue->symbol_offset // sync at symbol ue->symbol_offset
// computing the offset wrt the beginning of the frame // computing the offset wrt the beginning of the frame
int mu = fp->numerology_index; int mu = fp->numerology_index;
// number of symbols with different prefix length // number of symbols with different prefix length
// every 7*(1<<mu) symbols there is a different prefix length (38.211 5.3.1) // every 7*(1<<mu) symbols there is a different prefix length (38.211 5.3.1)
int n_symb_prefix0 = (ue->symbol_offset/(7*(1<<mu)))+1; int n_symb_prefix0 = (ue->symbol_offset / (7 * (1 << mu))) + 1;
sync_pos_frame = n_symb_prefix0*(fp->ofdm_symbol_size + fp->nb_prefix_samples0)+(ue->symbol_offset-n_symb_prefix0)*(fp->ofdm_symbol_size + fp->nb_prefix_samples); sync_pos_frame = n_symb_prefix0 * (fp->ofdm_symbol_size + fp->nb_prefix_samples0)
// for a correct computation of frame number to sync with the one decoded at MIB we need to take into account in which of the n_frames we got sync + (ue->symbol_offset - n_symb_prefix0) * (fp->ofdm_symbol_size + fp->nb_prefix_samples);
// for a correct computation of frame number to sync with the one decoded at MIB we need to take into account in which of
// the n_frames we got sync
ue->init_sync_frame = n_frames - 1 - frame_id; ue->init_sync_frame = n_frames - 1 - frame_id;
// compute the scramblingID_pdcch and the gold pdcch // compute the scramblingID_pdcch and the gold pdcch
ue->scramblingID_pdcch = fp->Nid_cell; ue->scramblingID_pdcch = fp->Nid_cell;
nr_gold_pdcch(ue,fp->Nid_cell); nr_gold_pdcch(ue, fp->Nid_cell);
// compute the scrambling IDs for PDSCH DMRS // compute the scrambling IDs for PDSCH DMRS
for (int i=0; i<NR_NB_NSCID; i++) { for (int i = 0; i < NR_NB_NSCID; i++) {
ue->scramblingID_dlsch[i]=fp->Nid_cell; ue->scramblingID_dlsch[i] = fp->Nid_cell;
nr_gold_pdsch(ue, i, ue->scramblingID_dlsch[i]); nr_gold_pdsch(ue, i, ue->scramblingID_dlsch[i]);
} }
nr_init_csi_rs(fp, ue->nr_csi_info->nr_gold_csi_rs, fp->Nid_cell); nr_init_csi_rs(fp, ue->nr_csi_info->nr_gold_csi_rs, fp->Nid_cell);
// initialize the pusch dmrs // initialize the pusch dmrs
for (int i=0; i<NR_NB_NSCID; i++) { for (int i = 0; i < NR_NB_NSCID; i++) {
ue->scramblingID_ulsch[i]=fp->Nid_cell; ue->scramblingID_ulsch[i] = fp->Nid_cell;
nr_init_pusch_dmrs(ue, ue->scramblingID_ulsch[i], i); nr_init_pusch_dmrs(ue, ue->scramblingID_ulsch[i], i);
} }
// we also need to take into account the shift by samples_per_frame in case the if is true // we also need to take into account the shift by samples_per_frame in case the if is true
if (ue->ssb_offset < sync_pos_frame){ if (ue->ssb_offset < sync_pos_frame) {
ue->rx_offset = fp->samples_per_frame - sync_pos_frame + ue->ssb_offset; ret.rx_offset = fp->samples_per_frame - sync_pos_frame + ue->ssb_offset;
ue->init_sync_frame += 1; ue->init_sync_frame += 1;
} } else
else ret.rx_offset = ue->ssb_offset - sync_pos_frame;
ue->rx_offset = ue->ssb_offset - sync_pos_frame;
} }
/* /*
...@@ -368,23 +349,26 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -368,23 +349,26 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
ue->common_vars.freq_offset ); ue->common_vars.freq_offset );
*/ */
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY,"TDD Normal prefix: CellId %d metric %d, phase %d, pbch %d\n", LOG_I(PHY,
fp->Nid_cell,metric_tdd_ncp,phase_tdd_ncp,ret); "TDD Normal prefix: CellId %d metric %d, phase %d, pbch detected %d, measured offset %d\n",
fp->Nid_cell,
metric_tdd_ncp,
phase_tdd_ncp,
!ret.cell_notdetected,
ret.rx_offset);
#endif #endif
} } else {
else {
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY,"TDD Normal prefix: SSS error condition: sync_pos %d\n", sync_pos); LOG_I(PHY, "TDD Normal prefix: SSS error condition: sync_pos %d\n", sync_pos);
#endif #endif
} }
if (ret == 0) break; if (ret.cell_notdetected == 0)
} break;
} }
else { } else {
ret = -1; ret.cell_notdetected = true;
} }
/* Consider this is a false detection if the offset is > 1000 Hz /* Consider this is a false detection if the offset is > 1000 Hz
...@@ -395,25 +379,24 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -395,25 +379,24 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
LOG_E(HW, "Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset); LOG_E(HW, "Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset);
}*/ }*/
if (ret==0) { // PBCH found so indicate sync to higher layers and configure frame parameters if (ret.cell_notdetected == 0) { // PBCH found so indicate sync to higher layers and configure frame parameters
//#ifdef DEBUG_INITIAL_SYNCH //#ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset); LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n", ue->Mod_id, ret.rx_offset);
//#endif //#endif
if (ue->UE_scan_carrier == 0) { if (ue->UE_scan_carrier == 0) {
#if UE_AUTOTEST_TRACE
#if UE_AUTOTEST_TRACE LOG_I(PHY,
LOG_I(PHY,"[UE %d] AUTOTEST Cell Sync : rx_offset %d, freq_offset %d \n", "[UE %d] AUTOTEST Cell Sync : rx_offset %d, freq_offset %d \n",
ue->Mod_id, ue->Mod_id,
ue->rx_offset, ue->rx_offset,
ue->common_vars.freq_offset ); ue->common_vars.freq_offset);
#endif #endif
// send sync status to higher layers later when timing offset converge to target timing
// send sync status to higher layers later when timing offset converge to target timing
} }
LOG_I(PHY, LOG_I(PHY,
...@@ -428,15 +411,14 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -428,15 +411,14 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id, LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id,
frame_parms->Nid_cell,frame_parms->frame_type); frame_parms->Nid_cell,frame_parms->frame_type);
#endif #endif
} }
// gain control // gain control
if (ret!=0) { //we are not synched, so we cannot use rssi measurement (which is based on channel estimates) if (ret.cell_notdetected != 0) { // we are not synched, so we cannot use rssi measurement (which is based on channel estimates)
rx_power = 0; int rx_power = 0;
// do a measurement on the best guess of the PSS // do a measurement on the best guess of the PSS
//for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) // for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
// rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2], // rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2],
// frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples); // frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples);
...@@ -453,12 +435,10 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra ...@@ -453,12 +435,10 @@ int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, int n_fra
ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]); ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]);
#ifdef DEBUG_INITIAL_SYNCH #ifdef DEBUG_INITIAL_SYNCH
LOG_I(PHY,"[UE%d] Initial sync : Estimated power: %d dB\n",ue->Mod_id,ue->measurements.rx_power_avg_dB[0] ); LOG_I(PHY, "[UE%d] Initial sync : Estimated power: %d dB\n", ue->Mod_id, ue->measurements.rx_power_avg_dB[0]);
#endif #endif
} }
// exit_fun("debug exit"); // exit_fun("debug exit");
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_INITIAL_UE_SYNC, VCD_FUNCTION_OUT);
return ret; return ret;
} }
...@@ -287,6 +287,7 @@ int rx_sss(PHY_VARS_NR_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uin ...@@ -287,6 +287,7 @@ int rx_sss(PHY_VARS_NR_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uin
/*! \brief receiver for the PBCH /*! \brief receiver for the PBCH
\returns number of tx antennas or -1 if error \returns number of tx antennas or -1 if error
*/ */
int nr_rx_pbch(PHY_VARS_NR_UE *ue, int nr_rx_pbch(PHY_VARS_NR_UE *ue,
const UE_nr_rxtx_proc_t *proc, const UE_nr_rxtx_proc_t *proc,
const int estimateSz, const int estimateSz,
...@@ -297,11 +298,6 @@ int nr_rx_pbch(PHY_VARS_NR_UE *ue, ...@@ -297,11 +298,6 @@ int nr_rx_pbch(PHY_VARS_NR_UE *ue,
fapiPbch_t *result, fapiPbch_t *result,
c16_t rxdataF[][ue->frame_parms.samples_per_slot_wCP]); c16_t rxdataF[][ue->frame_parms.samples_per_slot_wCP]);
int nr_pbch_detection(const UE_nr_rxtx_proc_t *proc,
PHY_VARS_NR_UE *ue,
int pbch_initial_symbol,
c16_t rxdataF[][ue->frame_parms.samples_per_slot_wCP]);
#ifndef modOrder #ifndef modOrder
#define modOrder(I_MCS,I_TBS) ((I_MCS-I_TBS)*2+2) // Find modulation order from I_TBS and I_MCS #define modOrder(I_MCS,I_TBS) ((I_MCS-I_TBS)*2+2) // Find modulation order from I_TBS and I_MCS
#endif #endif
...@@ -323,7 +319,11 @@ int dump_ue_stats(PHY_VARS_NR_UE *phy_vars_ue, ...@@ -323,7 +319,11 @@ int dump_ue_stats(PHY_VARS_NR_UE *phy_vars_ue,
@param n_frames @param n_frames
@param sa current running mode @param sa current running mode
*/ */
int nr_initial_sync(const UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *phy_vars_ue, int n_frames, int sa); typedef struct {
bool cell_notdetected;
int rx_offset;
} nr_initial_sync_t;
nr_initial_sync_t nr_initial_sync(UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *phy_vars_ue, int n_frames, int sa);
/*! /*!
\brief This function gets the carrier frequencies either from FP or command-line-set global variables, depending on the \brief This function gets the carrier frequencies either from FP or command-line-set global variables, depending on the
......
...@@ -486,11 +486,7 @@ typedef struct PHY_VARS_NR_UE_s { ...@@ -486,11 +486,7 @@ typedef struct PHY_VARS_NR_UE_s {
/// temporary offset during cell search prior to MIB decoding /// temporary offset during cell search prior to MIB decoding
int ssb_offset; int ssb_offset;
uint16_t symbol_offset; /// offset in terms of symbols for detected ssb in sync uint16_t symbol_offset; /// offset in terms of symbols for detected ssb in sync
int rx_offset; /// Timing offset int64_t max_pos_avg; /// Timing offset IIR filter
int rx_offset_diff; /// Timing adjustment for ofdm symbol0 on HW USRP
int64_t max_pos_fil; /// Timing offset IIR filter
bool apply_timing_offset; /// Do time sync for current frame
int time_sync_cell;
/// Timing Advance updates variables /// Timing Advance updates variables
/// Timing advance update computed from the TA command signalled from gNB /// Timing advance update computed from the TA command signalled from gNB
...@@ -644,6 +640,7 @@ typedef struct nr_rxtx_thread_data_s { ...@@ -644,6 +640,7 @@ typedef struct nr_rxtx_thread_data_s {
int writeBlockSize; int writeBlockSize;
nr_phy_data_t phy_data; nr_phy_data_t phy_data;
int tx_wait_for_dlsch; int tx_wait_for_dlsch;
int rx_offset;
} nr_rxtx_thread_data_t; } nr_rxtx_thread_data_t;
typedef struct LDPCDecode_ue_s { typedef struct LDPCDecode_ue_s {
......
...@@ -98,7 +98,7 @@ typedef struct { ...@@ -98,7 +98,7 @@ typedef struct {
*/ */
void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_tx_t *phy_data); void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_tx_t *phy_data);
void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data); int pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data);
void pdsch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data); void pdsch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data);
......
...@@ -826,7 +826,7 @@ static bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t * ...@@ -826,7 +826,7 @@ static bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *
return dec; return dec;
} }
void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data) int pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data)
{ {
int frame_rx = proc->frame_rx; int frame_rx = proc->frame_rx;
int nr_slot_rx = proc->nr_slot_rx; int nr_slot_rx = proc->nr_slot_rx;
...@@ -834,6 +834,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr ...@@ -834,6 +834,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr
fapi_nr_config_request_t *cfg = &ue->nrUE_config; fapi_nr_config_request_t *cfg = &ue->nrUE_config;
NR_DL_FRAME_PARMS *fp = &ue->frame_parms; NR_DL_FRAME_PARMS *fp = &ue->frame_parms;
NR_UE_PDCCH_CONFIG *phy_pdcch_config = &phy_data->phy_pdcch_config; NR_UE_PDCCH_CONFIG *phy_pdcch_config = &phy_data->phy_pdcch_config;
int sampleShift = 0;
nr_ue_dlsch_init(phy_data->dlsch, NR_MAX_NB_LAYERS>4 ? 2:1, ue->max_ldpc_iterations); nr_ue_dlsch_init(phy_data->dlsch, NR_MAX_NB_LAYERS>4 ? 2:1, ue->max_ldpc_iterations);
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN);
...@@ -896,17 +897,9 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr ...@@ -896,17 +897,9 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr
if (ue->no_timing_correction==0 && pbchSuccess == 0) { if (ue->no_timing_correction==0 && pbchSuccess == 0) {
LOG_D(PHY,"start adjust sync slot = %d no timing %d\n", nr_slot_rx, ue->no_timing_correction); LOG_D(PHY,"start adjust sync slot = %d no timing %d\n", nr_slot_rx, ue->no_timing_correction);
nr_adjust_synch_ue(fp, sampleShift =
ue, nr_adjust_synch_ue(fp, ue, gNB_id, fp->ofdm_symbol_size, dl_ch_estimates_time, frame_rx, nr_slot_rx, 16384);
gNB_id,
fp->ofdm_symbol_size,
dl_ch_estimates_time,
frame_rx,
nr_slot_rx,
0,
16384);
} }
ue->apply_timing_offset = true;
} }
LOG_D(PHY, "Doing N0 measurements in %s\n", __FUNCTION__); LOG_D(PHY, "Doing N0 measurements in %s\n", __FUNCTION__);
nr_ue_rrc_measurements(ue, proc, rxdataF); nr_ue_rrc_measurements(ue, proc, rxdataF);
...@@ -996,6 +989,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr ...@@ -996,6 +989,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr
LOG_D(PHY,"[UE %d] Frame %d, nr_slot_rx %d: found %d DCIs\n", ue->Mod_id, frame_rx, nr_slot_rx, dci_cnt); LOG_D(PHY,"[UE %d] Frame %d, nr_slot_rx %d: found %d DCIs\n", ue->Mod_id, frame_rx, nr_slot_rx, dci_cnt);
phy_pdcch_config->nb_search_space = 0; phy_pdcch_config->nb_search_space = 0;
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP_PDCCH, VCD_FUNCTION_OUT); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP_PDCCH, VCD_FUNCTION_OUT);
return sampleShift;
} }
void pdsch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data) void pdsch_processing(PHY_VARS_NR_UE *ue, const UE_nr_rxtx_proc_t *proc, nr_phy_data_t *phy_data)
......
...@@ -959,7 +959,6 @@ int main(int argc, char **argv) ...@@ -959,7 +959,6 @@ int main(int argc, char **argv)
//multipath channel //multipath channel
//multipath_channel(gNB2UE,s_re,s_im,r_re,r_im,frame_length_complex_samples,0); //multipath_channel(gNB2UE,s_re,s_im,r_re,r_im,frame_length_complex_samples,0);
UE->rx_offset=0;
UE_proc.frame_rx = frame; UE_proc.frame_rx = frame;
UE_proc.nr_slot_rx = slot; UE_proc.nr_slot_rx = slot;
UE_proc.gNB_id = 0; UE_proc.gNB_id = 0;
......
...@@ -766,18 +766,19 @@ int main(int argc, char **argv) ...@@ -766,18 +766,19 @@ int main(int argc, char **argv)
} }
if (UE->is_synchronized == 0) { if (UE->is_synchronized == 0) {
UE_nr_rxtx_proc_t proc={0}; UE_nr_rxtx_proc_t proc={0};
ret = nr_initial_sync(&proc, UE, 1, 0); nr_initial_sync_t ret = nr_initial_sync(&proc, UE, 1, 0);
printf("nr_initial_sync1 returns %d\n",ret); printf("nr_initial_sync1 returns %d\n", ret.cell_notdetected);
if (ret<0) n_errors++; if (ret.cell_notdetected)
n_errors++;
} }
else { else {
UE_nr_rxtx_proc_t proc={0}; UE_nr_rxtx_proc_t proc={0};
UE->rx_offset=0;
uint8_t ssb_index = 0; uint8_t ssb_index = 0;
const int estimateSz = frame_parms->symbols_per_slot * frame_parms->ofdm_symbol_size; const int estimateSz = frame_parms->symbols_per_slot * frame_parms->ofdm_symbol_size;
__attribute__((aligned(32))) struct complex16 dl_ch_estimates[frame_parms->nb_antennas_rx][estimateSz]; __attribute__((aligned(32))) struct complex16 dl_ch_estimates[frame_parms->nb_antennas_rx][estimateSz];
__attribute__((aligned(32))) struct complex16 dl_ch_estimates_time[frame_parms->nb_antennas_rx][frame_parms->ofdm_symbol_size]; __attribute__((
aligned(32))) struct complex16 dl_ch_estimates_time[frame_parms->nb_antennas_rx][frame_parms->ofdm_symbol_size];
while (!((SSB_positions >> ssb_index) & 0x01)) while (!((SSB_positions >> ssb_index) & 0x01))
ssb_index++; // to select the first transmitted ssb ssb_index++; // to select the first transmitted ssb
UE->symbol_offset = nr_get_ssb_start_symbol(frame_parms, ssb_index); UE->symbol_offset = nr_get_ssb_start_symbol(frame_parms, ssb_index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment