From 9825842e97b5ccb76979f7f755b91b5558f4530e Mon Sep 17 00:00:00 2001 From: Sakthivel Velumani Date: Fri, 5 May 2023 13:13:09 -0400 Subject: [PATCH] Adjust samples in time only when valid PBCH is present --- executables/nr-ue.c | 25 ++++++------------- .../PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c | 4 +++ .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 2 +- openair1/PHY/defs_nr_UE.h | 1 + openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 18 +++++++------ 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 5860d7c64d..38c3020dc9 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -734,16 +734,6 @@ void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { } } -int computeSamplesShift(PHY_VARS_NR_UE *UE) { - int samples_shift = -(UE->rx_offset>>1); - if (samples_shift != 0) { - LOG_I(NR_PHY,"Adjusting frame in time by %i samples\n", samples_shift); - UE->rx_offset = 0; // reset so that it is not applied falsely in case of SSB being only in every second frame - UE->max_pos_fil += samples_shift << 15; // reset IIR filter when sample shift is applied - } - return samples_shift; -} - static inline int get_firstSymSamp(uint16_t slot, NR_DL_FRAME_PARMS *fp) { if (fp->numerology_index == 0) return fp->nb_prefix_samples0 + fp->ofdm_symbol_size; @@ -904,14 +894,13 @@ void *UE_thread(void *arg) { int readBlockSize, writeBlockSize; - if (slot_nr<(nb_slot_frame - 1)) { - readBlockSize=get_readBlockSize(slot_nr, &UE->frame_parms); - writeBlockSize=UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms); - } else { - UE->rx_offset_diff = computeSamplesShift(UE); - readBlockSize=get_readBlockSize(slot_nr, &UE->frame_parms) - - UE->rx_offset_diff; - writeBlockSize=UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms)- UE->rx_offset_diff; + readBlockSize=get_readBlockSize(slot_nr, &UE->frame_parms); + writeBlockSize=UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms); + if (UE->apply_timing_offset && (slot_nr == nb_slot_frame-1)) { + const int sampShift = -(UE->rx_offset>>1); + readBlockSize -= sampShift; + writeBlockSize -= sampShift; + UE->apply_timing_offset = false; } AssertFatal(readBlockSize == diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c index feed70b854..3d89464d33 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c @@ -94,6 +94,10 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, else ue->rx_offset = diff; + const int sample_shift = -(ue->rx_offset>>1); + // reset IIR filter for next offset calculation + ue->max_pos_fil += sample_shift << 15; + if(abs(diff)<5) count_max_pos_ok ++; else diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index 470164817b..1c049acbc6 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -284,7 +284,7 @@ void nr_processDLSegment(void* arg) { if (no_iteration_ldpc > dlsch->max_ldpc_iterations) no_iteration_ldpc = dlsch->max_ldpc_iterations; } else { - LOG_I(PHY,"%d.%d CRC NOT OK\n",rdata->proc->frame_rx,rdata->proc->nr_slot_rx); + LOG_D(PHY,"%d.%d CRC NOT OK\n",rdata->proc->frame_rx,rdata->proc->nr_slot_rx); no_iteration_ldpc = dlsch->max_ldpc_iterations + 1; } diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index aa8af44199..5a348f4998 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -516,6 +516,7 @@ typedef struct { int rx_offset; /// Timing offset int rx_offset_diff; /// Timing adjustment for ofdm symbol0 on HW USRP int 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 diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 8dec02b0a1..5609f7d608 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -352,12 +352,12 @@ void nr_ue_measurement_procedures(uint16_t l, VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_OUT); } -static void nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc, - int estimateSz, - struct complex16 dl_ch_estimates[][estimateSz], - nr_phy_data_t *phy_data, - c16_t rxdataF[][ue->frame_parms.samples_per_slot_wCP]) { +static int nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc, + int estimateSz, + struct complex16 dl_ch_estimates[][estimateSz], + nr_phy_data_t *phy_data, + c16_t rxdataF[][ue->frame_parms.samples_per_slot_wCP]) { int ret = 0; DevAssert(ue); @@ -420,6 +420,7 @@ static void nr_ue_pbch_procedures(PHY_VARS_NR_UE *ue, } + return ret; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_OUT); } @@ -929,9 +930,9 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, if(ssb_index == fp->ssb_index) { LOG_D(PHY," ------ Decode MIB: frame.slot %d.%d ------ \n", frame_rx%1024, nr_slot_rx); - nr_ue_pbch_procedures(ue, proc, estimateSz, dl_ch_estimates, phy_data, rxdataF); + const int pbchSuccess = nr_ue_pbch_procedures(ue, proc, estimateSz, dl_ch_estimates, phy_data, rxdataF); - if (ue->no_timing_correction==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); nr_adjust_synch_ue(fp, ue, @@ -943,6 +944,7 @@ void pbch_pdcch_processing(PHY_VARS_NR_UE *ue, 0, 16384); } + ue->apply_timing_offset = true; } LOG_D(PHY, "Doing N0 measurements in %s\n", __FUNCTION__); nr_ue_rrc_measurements(ue, proc, rxdataF);