diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c index 15e83b51d0..d39677d232 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -37,7 +37,9 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned char symbol, - int dmrss) + int dmrss, + uint8_t ssb_index, + uint8_t n_hf) { int pilot[200] __attribute__((aligned(16))); unsigned char aarx; @@ -49,8 +51,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; uint8_t nushift; - uint8_t ssb_index=ue->i_ssb; - uint8_t n_hf=ue->n_hf; int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[eNB_offset]; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 5418b16d1b..591b4733ce 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -54,7 +54,9 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned char symbol, - int dmrss); + int dmrss, + uint8_t ssb_index, + uint8_t n_hf); int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 4f0f905e9f..0b9795b6bc 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -71,14 +71,12 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod for (int hf = 0; hf < N_hf; hf++) { for (int l = 0; l < N_L ; l++) { if (ret !=0) { - ue->i_ssb = l; - ue->n_hf = hf; #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); #endif for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); #endif @@ -88,6 +86,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod ue->pbch_vars[0], frame_parms, 0, + l, SISO, ue->high_speed_flag); @@ -130,7 +129,7 @@ char prefix_string[2][9] = {"NORMAL","EXTENDED"}; int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) { - int32_t sync_pos, sync_pos_slot; // 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; uint8_t phase_tdd_ncp; double im, re; @@ -173,20 +172,17 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) /* process pss search on received buffer */ sync_pos = pss_synchro_nr(ue, NO_RATE_CHANGE); - sync_pos_slot = (fp->samples_per_subframe/fp->slots_per_subframe) - 10*(fp->ofdm_symbol_size + fp->nb_prefix_samples); + if (sync_pos >= fp->nb_prefix_samples) + ue->ssb_offset = sync_pos - fp->nb_prefix_samples; + else + ue->ssb_offset = sync_pos + (fp->samples_per_subframe * 10) - fp->nb_prefix_samples; - if (sync_pos >= fp->nb_prefix_samples){ - ue->ssb_offset = sync_pos - fp->nb_prefix_samples;} - else{ - ue->ssb_offset = sync_pos + (fp->samples_per_subframe * 10) - fp->nb_prefix_samples;} - - ue->rx_offset = ue->ssb_offset - sync_pos_slot; //write_output("rxdata1.m","rxd1",ue->common_vars.rxdata[0],10*fp->samples_per_subframe,1,1); #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.eNb_id); - LOG_I(PHY,"sync_pos %d ssb_offset %d sync_pos_slot %d \n",sync_pos,ue->ssb_offset,sync_pos_slot); + LOG_I(PHY,"sync_pos %d ssb_offset %d \n",sync_pos,ue->ssb_offset); #endif // digital compensation of FFO for SSB symbols @@ -239,7 +235,14 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) nr_gold_pbch(ue); ret = nr_pbch_detection(ue,1,mode); // start pbch detection at first symbol after pss - + + if (ret == 0) { + // sync at symbol ue->symbol_offset + // computing the offset wrt the beginning of the frame + sync_pos_frame = (fp->ofdm_symbol_size + fp->nb_prefix_samples0)+((ue->symbol_offset)-1)*(fp->ofdm_symbol_size + fp->nb_prefix_samples); + ue->rx_offset = ue->ssb_offset - sync_pos_frame; + } + nr_gold_pdcch(ue,0, 2); /* int nb_prefix_samples0 = fp->nb_prefix_samples0; @@ -263,7 +266,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) } else { #ifdef DEBUG_INITIAL_SYNCH - LOG_I(PHY,"TDD Normal prefix: SSS error condition: sync_pos %d, sync_pos_slot %d\n", sync_pos, sync_pos_slot); + LOG_I(PHY,"TDD Normal prefix: SSS error condition: sync_pos %d\n", sync_pos); #endif } } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 4d8ce3dec9..11e3c5cfdf 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -414,6 +414,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, + uint8_t i_ssb, MIMO_mode_t mimo_mode, uint32_t high_speed_flag) { NR_UE_COMMON *nr_ue_common_vars = &ue->common_vars; @@ -424,10 +425,9 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, //uint32_t pbch_a_prime; int16_t *pbch_e_rx; uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; - uint8_t nushift; + uint8_t nushift,n_hf,ssb_index; uint16_t M; uint8_t Lmax=frame_parms->Lmax; - uint8_t ssb_index=ue->i_ssb; //uint16_t crc; //unsigned short idx_demod =0; uint32_t decoderState=0; @@ -443,7 +443,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, int symbol_offset=1; if (ue->is_synchronized > 0) - symbol_offset=2; + symbol_offset=ue->symbol_offset; else symbol_offset=0; @@ -527,7 +527,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif //un-scrambling M = NR_POLAR_PBCH_E; - nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; + nushift = (Lmax==4)? i_ssb&3 : i_ssb&7; uint32_t unscrambling_mask = (Lmax==64)?0x100006D:0x1000041; nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0,0); //polar decoding de-rate matching @@ -571,6 +571,16 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, for (int i=0; i<3; i++) decoded_output[i] = (uint8_t)((payload>>((3-i)<<3))&0xff); + n_hf = ((xtra_byte>>4)&0x01); // computing the half frame index from the extra byte + + ssb_index = i_ssb; // ssb index corresponds to i_ssb for Lmax = 4,8 + if (Lmax == 64) { // for Lmax = 64 ssb index 4th,5th and 6th bits are in extra byte + for (int i=0; i<3; i++) + ssb_index += (((xtra_byte>>(7-i))&0x01)<<(3+i)); + } + + ue->symbol_offset = nr_get_ssb_start_symbol(frame_parms, ssb_index, n_hf); + #ifdef DEBUG_PBCH printf("xtra_byte %x payload %x\n", xtra_byte, payload); @@ -578,14 +588,14 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, // printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]); printf("[PBCH] decoder payload[%d] = %x\n",i,decoded_output[i]); } - #endif + ue->dl_indication.rx_ind = &ue->rx_ind; // hang on rx_ind instance //ue->rx_ind.sfn_slot = 0; //should be set by higher-1-layer, i.e. clean_and_set_if_instance() ue->rx_ind.rx_indication_body[0].pdu_type = FAPI_NR_RX_PDU_TYPE_MIB; ue->rx_ind.rx_indication_body[0].mib_pdu.pdu = &decoded_output[0]; ue->rx_ind.rx_indication_body[0].mib_pdu.additional_bits = xtra_byte; - ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index = ssb_index; // confirm with TCL + ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index = i_ssb; // confirm with TCL ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_length = Lmax; // confirm with TCL ue->rx_ind.rx_indication_body[0].mib_pdu.cell_id = frame_parms->Nid_cell; // confirm with TCL ue->rx_ind.number_pdus = 1; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h index 36158fa259..e9ccedd04b 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1122,6 +1122,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, + uint8_t i_ssb, MIMO_mode_t mimo_mode, uint32_t high_speed_flag); diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index f384bcaccf..a482a48207 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -1143,8 +1143,7 @@ typedef struct { uint8_t decode_MIB; /// temporary offset during cell search prior to MIB decoding int ssb_offset; - uint8_t i_ssb; - uint8_t n_hf; + uint16_t symbol_offset; // offset in terms of symbols for detected ssb in sync int rx_offset; /// Timing offset int rx_offset_diff; /// Timing adjustment for ofdm symbol0 on HW USRP int time_sync_cell; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 33b42749e0..89ae3c0696 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2973,6 +2973,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * ue->pbch_vars[eNB_id], &ue->frame_parms, eNB_id, + ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index, SISO, ue->high_speed_flag); @@ -5098,9 +5099,13 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN if ( (nr_tti_rx == 0) && (ue->decode_MIB == 1)) { LOG_D(PHY," ------ PBCH ChannelComp/LLR: frame.slot %d.%d ------ \n", frame_rx%1024, nr_tti_rx); - for (int i=0; i<3; i++) { + + uint8_t i_ssb = ue->rx_ind.rx_indication_body[0].mib_pdu.ssb_index; + uint8_t n_hf = (((ue->rx_ind.rx_indication_body[0].mib_pdu.additional_bits)>>4)&0x01); + + for (int i=1; i<4; i++) { nr_slot_fep(ue, - (5+i), //mu=1 case B + (ue->symbol_offset+i), //mu=1 case B nr_tti_rx, 0, 0, @@ -5109,7 +5114,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); #endif - nr_pbch_channel_estimation(ue,0,0,5+i,i); + nr_pbch_channel_estimation(ue,0,0,ue->symbol_offset+i,i-1,i_ssb,n_hf); #if UE_TIMING_TRACE stop_meas(&ue->dlsch_channel_estimation_stats); #endif diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 4b281184b8..6891e5b875 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) unsigned char frame_type = 0; unsigned char pbch_phase = 0; - int frame=0,subframe=0; + int frame=0; int frame_length_complex_samples; int frame_length_complex_samples_no_prefix; NR_DL_FRAME_PARMS *frame_parms; @@ -610,8 +610,8 @@ int main(int argc, char **argv) uint8_t ssb_index = 0; while (!((SSB_positions >> ssb_index) & 0x01)) ssb_index++; // to select the first transmitted ssb - int start_symbol = nr_get_ssb_start_symbol(frame_parms, ssb_index, n_hf); - for (int i=start_symbol+1; isymbol_offset = nr_get_ssb_start_symbol(frame_parms, ssb_index, n_hf); + for (int i=UE->symbol_offset+1; isymbol_offset+4; i++) { nr_slot_fep(UE, i, 0, @@ -620,7 +620,7 @@ int main(int argc, char **argv) NR_PBCH_EST); } - ret = nr_pbch_detection(UE,start_symbol+1,0); + ret = nr_pbch_detection(UE,UE->symbol_offset+1,0); if (ret==0) { //UE->rx_ind.rx_indication_body->mib_pdu.ssb_index; //not yet detected automatically