diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index cb96f39a1b..8a52a24597 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -144,6 +144,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, } nr_init_pdcch_dmrs(gNB, cfg->sch_config.physical_cell_id.value); + nr_init_pbch_interleaver(gNB->nr_pbch_interleaver); /* lte_gold(fp,gNB->lte_gold_table,fp->Nid_cell); diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c index b8a4d88ba1..93288af29b 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c @@ -22,6 +22,7 @@ /*! \file PHY/NR_TRANSPORT/nr_pbch.c * \brief Top-level routines for generating the PBCH/BCH physical/transport channel V15.1 03/2018 * \author Guy De Souza +* \thanks Special Thanks to Son Dang for helpfull contributions and testing * \date 2018 * \version 0.1 * \company Eurecom @@ -39,9 +40,11 @@ //#define DEBUG_PBCH_ENCODING //#define DEBUG_PBCH_DMRS -//extern short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT]; #include "PHY/NR_REFSIG/nr_mod_table.h" +uint8_t nr_pbch_payload_interleaving_pattern[32] = {16, 23, 18, 17, 8, 30, 10, 6, 24, 7, 0, 5, 3, 2, 1, 4, + 9, 11, 12, 13, 14, 15, 19, 20, 21, 22, 25, 26, 27, 28, 29, 31}; + int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, int32_t **txdataF, int16_t amp, @@ -152,66 +155,83 @@ void nr_pbch_scrambling(NR_gNB_PBCH *pbch, uint8_t nushift, uint16_t M, uint16_t length, - uint8_t encoded) -{ + uint8_t encoded, + uint32_t unscrambling_mask) { uint8_t reset, offset; uint32_t x1, x2, s=0; uint32_t *pbch_e = pbch->pbch_e; - uint32_t unscrambling_mask = 0x100006D; reset = 1; // x1 is set in lte_gold_generic x2 = Nid; + // The Gold sequence is shifted by nushift* M, so we skip (nushift*M /32) double words for (int i=0; i<(uint16_t)ceil(((float)nushift*M)/32); i++) { -s = lte_gold_generic(&x1, &x2, reset); + s = lte_gold_generic(&x1, &x2, reset); reset = 0; } + // Scrambling is now done with offset (nushift*M)%32 offset = (nushift*M)&0x1f; #ifdef DEBUG_PBCH_ENCODING printf("Scrambling params: nushift %d M %d length %d encoded %d offset %d\n", nushift, M, length, encoded, offset); #endif - - for (int i=0; ipbch_a_prime ^= ((unscrambling_mask>>i)&1)? ((pbch->pbch_a_interleaved>>i)&1)<pbch_a_interleaved>>i)&1) ^ ((s>>((i+offset)&0x1f))&1))<>i)&1) + pbch->pbch_a_prime ^= ((pbch->pbch_a_interleaved>>i)&1)<pbch_a_prime ^= (((pbch->pbch_a_interleaved>>i)&1) ^ ((s>>((k+offset)&0x1f))&1))<>5] ^= (((s>>((i+offset)&0x1f))&1)<<(i&0x1f)); + } } } -// This portion of code is temporarily kept until the optimized version is validated -uint8_t nr_pbch_payload_interleaving_pattern[32] = {16, 23, 18, 17, 8, 30, 10, 6, 24, 7, 0, 5, 3, 2, 1, 4, - 9, 11, 12, 13, 14, 15, 19, 20, 21, 22, 25, 26, 27, 28, 29, 31}; -uint8_t nr_pbch_payload_interleaver(uint8_t i) { - uint8_t j_sfn=6, j_hrf=10, j_ssb=11, j_other=14; +void nr_init_pbch_interleaver(uint8_t *interleaver) { + uint8_t j_sfn=0, j_hrf=10, j_ssb=11, j_other=14; + memset((void*)interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS); - if (24<=i && i<=27) //Sfn bits - return nr_pbch_payload_interleaving_pattern[j_sfn + i -24]; - else if (i==28) // Hrf bit - return nr_pbch_payload_interleaving_pattern[j_hrf]; - else if (29<=i) // Ssb bits - return nr_pbch_payload_interleaving_pattern[j_ssb + (i-29)]; - else - return nr_pbch_payload_interleaving_pattern[(j_other + i)&0x1f]; + for (uint8_t i=0; ipbch_a; - memset((void*) xbyte, 0, 1); - //uint8_t pbch_a_b[32]; + uint32_t unscrambling_mask; - // LOG_D(PHY, "PBCH generation started\n"); + LOG_I(PHY, "PBCH generation started\n"); + + ///Payload generation memset((void*)pbch, 0, sizeof(NR_gNB_PBCH)); - ///Payload generation - // Fix byte endian - if (!(sfn&7)) - for (int i=0; i<(NR_PBCH_PDU_BITS>>3); i++) - pbch->pbch_a[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_pdu[i]; + pbch->pbch_a=0; + for (int i=0; ipbch_a |= ((pbch_pdu[2-(i>>3)]>>(7-(i&7)))&1)<pbch_a[i]); + for (int i=0; i<3; i++) + printf("pbch_pdu[%d]: 0x%02x\n", i, pbch_pdu[i]); + printf("PBCH payload = 0x%08x\n",pbch->pbch_a); #endif // Extra byte generation for (int i=0; i<4; i++) - (*xbyte) ^= ((sfn>>i)&1)<pbch_a |= ((sfn>>(3-i))&1)<<(24+i); // resp. 4th, 3rd, 2nd ans 1st lsb of sfn - (*xbyte) ^= n_hf<<4; // half frame index bit + pbch->pbch_a |= n_hf<<28; // half frame index bit if (Lmax == 64) for (int i=0; i<3; i++) - (*xbyte) ^= ((ssb_index>>(3+i))&1)<<(5+i); // resp. 4th, 5th and 6th bits of ssb_index + pbch->pbch_a |= ((ssb_index>>(5-i))&1)<<(29+i); // resp. 6th, 5th and 4th bits of ssb_index else - (*xbyte) ^= ((config->sch_config.ssb_subcarrier_offset.value>>5)&1)<<5; //MSB of k_SSB -#ifdef DEBUG_PBCH_ENCODING - printf("Extra byte:\n"); - for (int i=0; i<4; i++) - printf("pbch_a[%d]: 0x%02x\n", i, pbch->pbch_a[i]); -#endif + pbch->pbch_a |= ((config->sch_config.ssb_subcarrier_offset.value>>4)&1)<<29; //MSB of k_SSB (bit index 4) + + LOG_I(PHY,"After extra byte: pbch_a = 0x%08x\n",pbch->pbch_a); // Payload interleaving - uint32_t in=0;//, out=0; - for (int i=0; i>3; i++) - in |= (uint32_t)(pbch->pbch_a[i]<<((3-i)<<3)); - - for (int i=0; i<32; i++) { - pbch->pbch_a_interleaved |= ((in>>i)&1)<<(nr_pbch_payload_interleaver(i));//nr_pbch_payload_interleaving_pattern[i] + + for (int i=0; ipbch_a_interleaved |= ((pbch->pbch_a>>i)&1)<<(*(interleaver+i)); #ifdef DEBUG_PBCH_ENCODING - printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) %d\n", i, in, pbch->pbch_a_interleaved, nr_pbch_payload_interleaver(i), (in>>i)&1); + printf("i %d out 0x%08x ilv %d (in>>i)&1) %d\n", i, pbch->pbch_a_interleaved, *(interleaver+i), (pbch->pbch_a>>i)&1); #endif } @@ -282,10 +294,11 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, #endif // Scrambling + unscrambling_mask = (Lmax ==64)? 0x100006D:0x1000041; M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3); nushift = (((sfn>>2)&1)<<1) ^ ((sfn>>1)&1); pbch->pbch_a_prime = 0; - nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, NR_POLAR_PBCH_PAYLOAD_BITS, 0); + nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, NR_POLAR_PBCH_PAYLOAD_BITS, 0, unscrambling_mask); #ifdef DEBUG_PBCH_ENCODING printf("Payload scrambling: nushift %d M %d sfn3 %d sfn2 %d\n", nushift, M, (sfn>>2)&1, (sfn>>1)&1); printf("pbch_a_prime: 0x%08x\n", pbch->pbch_a_prime); @@ -303,7 +316,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, /// Scrambling M = NR_POLAR_PBCH_E; nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; - nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, NR_POLAR_PBCH_E, 1); + nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, NR_POLAR_PBCH_E, 1, 0); #ifdef DEBUG_PBCH_ENCODING printf("Scrambling:\n"); for (int i=0; illr; - uint32_t unscrambling_mask = 0x100006D; - reset = 1; // x1 is set in first call to lte_gold_generic @@ -469,7 +469,8 @@ void nr_pbch_unscrambling(NR_UE_PBCH *pbch, #endif if (bitwise) { - (pbch->pbch_a_interleaved) ^= ((unscrambling_mask>>i)&1)? ((pbch->pbch_a_prime>>i)&1)<pbch_a_prime>>i)&1) ^ ((s>>((i+offset)&0x1f))&1))<pbch_a_interleaved) ^= ((unscrambling_mask>>i)&1)? ((pbch->pbch_a_prime>>i)&1)<pbch_a_prime>>i)&1) ^ ((s>>((k+offset)&0x1f))&1))<>i)&1); } else { @@ -507,7 +508,7 @@ unsigned char sign(int8_t x) { } */ -uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,1,29,25,27,22,2,24,3,4,5,6,7,18,21,20,8,9,10,11,19,26,12,13,14,15,16,23,17}; +uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,7,29,25,27,5,8,24,9,10,11,12,13,1,4,3,14,15,16,17,2,26,18,19,20,21,22,30,23}; int nr_rx_pbch( PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, @@ -647,7 +648,8 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, //un-scrambling M = NR_POLAR_PBCH_E; nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; - nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0); + 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); @@ -668,18 +670,18 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, if(decoderState > 0) return(decoderState); - //printf("polar decoder output 0x%08x\n",nr_ue_pbch_vars->pbch_a_prime); + printf("polar decoder output 0x%08x\n",nr_ue_pbch_vars->pbch_a_prime); //payload un-scrambling memset(&nr_ue_pbch_vars->pbch_a_interleaved, 0, sizeof(uint32_t) ); M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3); - nushift = ((nr_ue_pbch_vars->pbch_a_prime>>6)&1) ^ (((nr_ue_pbch_vars->pbch_a_prime>>24)&1)<<1); - nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1); + nushift = ((nr_ue_pbch_vars->pbch_a_prime>>24)&1) ^ (((nr_ue_pbch_vars->pbch_a_prime>>6)&1)<<1); + nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1,unscrambling_mask); + printf("nushift %d sfn 3rd %d 2nd %d", nushift,((nr_ue_pbch_vars->pbch_a_prime>>6)&1), ((nr_ue_pbch_vars->pbch_a_prime>>24)&1) ); //payload deinterleaving //uint32_t in=0; uint32_t out=0; - for (int i=0; i<32; i++) { out |= ((nr_ue_pbch_vars->pbch_a_interleaved>>i)&1)<<(pbch_deinterleaving_pattern[i]); #ifdef DEBUG_PBCH @@ -687,14 +689,18 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif } - for (int i=0; i>3; i++) - decoded_output[i] = (uint8_t)((out>>(i<<3))&0xff); + uint32_t payload = 0; + uint8_t xtra_byte = 0; + xtra_byte = (out>>24)&0xff; + + for (int i=0; i>i)&1)<<(NR_POLAR_PBCH_PAYLOAD_BITS-i-1); + + for (int i=0; i<3; i++) + decoded_output[i] = (uint8_t)((payload>>((3-i)<<3))&0xff); - // Fix byte endian - // for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++) - // decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i]; - #ifdef DEBUG_PBCH + printf("xtra_byte %x payload %x\n", xtra_byte, payload); for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++){ // printf("unscrambling pbch_a[%d] = %x \n", i,pbch_a[i]); printf("[PBCH] decoder payload[%d] = %x\n",i,decoded_output[i]); @@ -707,7 +713,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, ue->rx_ind.rx_indication_body = (fapi_nr_rx_indication_body_t *)malloc(sizeof(fapi_nr_rx_indication_body_t)); ue->rx_ind.rx_indication_body->pdu_type = FAPI_NR_RX_PDU_TYPE_MIB; ue->rx_ind.rx_indication_body->mib_pdu.pdu = &decoded_output[0]; - ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = decoded_output[3]; + ue->rx_ind.rx_indication_body->mib_pdu.additional_bits = xtra_byte; ue->rx_ind.rx_indication_body->mib_pdu.ssb_index = ssb_index; // confirm with TCL ue->rx_ind.rx_indication_body->mib_pdu.ssb_length = Lmax; // confirm with TCL ue->rx_ind.rx_indication_body->mib_pdu.cell_id = frame_parms->Nid_cell; // confirm with TCL diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index 1a73469030..af3bd306a5 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -32,6 +32,9 @@ #include #include "PHY/sse_intrin.h" +#define CEILIDIV(a,b) ((a+b-1)/b) +#define ROUNDIDIV(a,b) (((a<<1)+b)/(b<<1)) + struct complex { double x; diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index f6280762d1..3df696ee29 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -41,7 +41,7 @@ #define MAX_NUM_RU_PER_gNB MAX_NUM_RU_PER_eNB typedef struct { - uint8_t pbch_a[NR_POLAR_PBCH_PAYLOAD_BITS>>3]; + uint32_t pbch_a; uint32_t pbch_a_interleaved; uint32_t pbch_a_prime; uint32_t pbch_e[NR_POLAR_PBCH_E_DWORD]; @@ -323,6 +323,9 @@ typedef struct PHY_VARS_gNB_s { /// PBCH DMRS sequence uint32_t nr_gold_pbch_dmrs[2][64][NR_PBCH_DMRS_LENGTH_DWORD]; + /// PBCH interleaver + uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS]; + /// PDCCH DMRS sequence uint32_t ***nr_gold_pdcch_dmrs; diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 29ce0412d9..93ff336687 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -146,7 +146,15 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) { gNB->pbch_configured = 0; } nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF, AMP_OVER_2, ssb_start_symbol, cfg, fp); - nr_generate_pbch(&gNB->pbch, gNB->nrPolar_params, pbch_pdu, txdataF, AMP_OVER_2, ssb_start_symbol, n_hf, Lmax, ssb_index, frame, cfg, fp); + nr_generate_pbch(&gNB->pbch, + gNB->nrPolar_params, + pbch_pdu, + gNB->nr_pbch_interleaver, + txdataF, + AMP_OVER_2, + ssb_start_symbol, + n_hf,Lmax,ssb_index, + frame, cfg, fp); } } diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index c457762ca8..69f744a50c 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -221,7 +221,7 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ printf("dmrs type A position: %d\n", phy_config->config_req.pbch_config.dmrs_type_a_position); printf("pdcch config sib1: %d\n", phy_config->config_req.pbch_config.pdcch_config_sib1); printf("cell barred: %d\n", phy_config->config_req.pbch_config.cell_barred); - printf("intra frequcney reselection: %d\n", phy_config->config_req.pbch_config.intra_frequency_reselection); + printf("intra frequency reselection: %d\n", phy_config->config_req.pbch_config.intra_frequency_reselection); printf("system frame number: %d\n", phy_config->config_req.pbch_config.system_frame_number); printf("ssb index: %d\n", phy_config->config_req.pbch_config.ssb_index); printf("half frame bit: %d\n", phy_config->config_req.pbch_config.half_frame_bit); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index ae94304aed..157ce9d84d 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -210,12 +210,14 @@ int8_t nr_ue_decode_mib( AssertFatal(mac->mib != NULL, "nr_ue_decode_mib() mac->mib == NULL\n"); //if(mac->mib != NULL){ - uint32_t frame = (mac->mib->systemFrameNumber.buf[0] >> mac->mib->systemFrameNumber.bits_unused); - uint32_t frame_number_4lsb = (uint32_t)(extra_bits & 0xf); // extra bits[0:3] - uint32_t half_frame_bit = (uint32_t)(( extra_bits >> 4 ) & 0x1 ); // extra bits[4] - uint32_t ssb_subcarrier_offset_msb = (uint32_t)(( extra_bits >> 5 ) & 0x1 ); // extra bits[5] + uint16_t frame = (mac->mib->systemFrameNumber.buf[0] >> mac->mib->systemFrameNumber.bits_unused); + uint16_t frame_number_4lsb = 0; + for (int i=0; i<4; i++) + frame_number_4lsb |= ((extra_bits>>i)&1)<<(3-i); + uint8_t half_frame_bit = ( extra_bits >> 4 ) & 0x1; // extra bits[4] + uint8_t ssb_subcarrier_offset_msb = ( extra_bits >> 5 ) & 0x1; // extra bits[5] - uint32_t ssb_subcarrier_offset = mac->mib->ssb_SubcarrierOffset; + uint8_t ssb_subcarrier_offset = (uint8_t)mac->mib->ssb_SubcarrierOffset; //uint32_t ssb_index = 0; // TODO: ssb_index should obtain from L1 in case Lssb != 64 @@ -238,7 +240,7 @@ int8_t nr_ue_decode_mib( printf("dmrs type A position: %d\n", (int)mac->mib->dmrs_TypeA_Position); printf("pdcch config sib1: %d\n", (int)mac->mib->pdcch_ConfigSIB1); printf("cell barred: %d\n", (int)mac->mib->cellBarred); - printf("intra frequcney reselection: %d\n", (int)mac->mib->intraFreqReselection); + printf("intra frequency reselection: %d\n", (int)mac->mib->intraFreqReselection); printf("half frame bit(extra bits): %d\n", (int)half_frame_bit); printf("ssb index(extra bits): %d\n", (int)ssb_index); #endif @@ -254,7 +256,6 @@ int8_t nr_ue_decode_mib( }else{ //NR_MIB__subCarrierSpacingCommon_scs30or120 scs_pdcch = scs_30kHz; } - scs_pdcch = 2; channel_bandwidth_t min_channel_bw = bw_40MHz; // deafult for testing diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h index c8c006a6b8..1799721325 100644 --- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h @@ -167,4 +167,8 @@ typedef struct gNB_MAC_INST_s { time_stats_t schedule_pch; } gNB_MAC_INST; +void nr_schedule_css_dlsch_phytest(module_id_t module_idP, + frame_t frameP, + sub_frame_t subframeP); + #endif /*__LAYER2_NR_MAC_GNB_H__ */ diff --git a/targets/RT/USER/nr-softmodem.c b/targets/RT/USER/nr-softmodem.c index 8b5b7f6e28..cb8c916a6d 100644 --- a/targets/RT/USER/nr-softmodem.c +++ b/targets/RT/USER/nr-softmodem.c @@ -191,7 +191,7 @@ int otg_enabled; //static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; +//static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; uint32_t target_dl_mcs = 28; //maximum allowed mcs uint32_t target_ul_mcs = 20; uint32_t timing_advance = 0;