From 102ec93096e11186de176636449eebe3a4058369 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Mon, 11 Feb 2019 18:45:28 +0100 Subject: [PATCH 001/117] first implementation of multiple ssb at gnb --- openair1/PHY/INIT/nr_parms.c | 3 + openair1/PHY/NR_TRANSPORT/nr_pbch.c | 1 - openair1/PHY/NR_TRANSPORT/nr_pss.c | 1 - openair1/PHY/defs_nr_common.h | 5 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 90 ++++++++++++++++------- 5 files changed, 68 insertions(+), 32 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index f37883b388..273bfbfe1a 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -46,7 +46,10 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, fp->numerology_index = mu; fp->Ncp = Ncp; fp->N_RB_DL = N_RB_DL; + fp->L_ssb = 8; // TODO get the number of SSB value from higher layers (and config file finally) + fp->ssb_type = nr_ssb_type_B; // TODO get the type from higher layers (and config file finally) + switch(mu) { case NR_MU_0: //15kHz scs diff --git a/openair1/PHY/NR_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_TRANSPORT/nr_pbch.c index 2e2c99f106..3b81aae04e 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pbch.c @@ -443,6 +443,5 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, k-=frame_parms->ofdm_symbol_size; } - return 0; } diff --git a/openair1/PHY/NR_TRANSPORT/nr_pss.c b/openair1/PHY/NR_TRANSPORT/nr_pss.c index 29dbe4ec99..e0d7b6ae33 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_pss.c +++ b/openair1/PHY/NR_TRANSPORT/nr_pss.c @@ -59,7 +59,6 @@ int nr_generate_pss( int16_t *d_pss, /// Resource mapping a = amp; - // PSS occupies a predefined position (subcarriers 56-182, symbol 0) within the SSB block starting from k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + 56; //and if (k>= frame_parms->ofdm_symbol_size) k-=frame_parms->ofdm_symbol_size; diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 58a8833b18..8f6f22f6a4 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -303,11 +303,13 @@ typedef struct NR_DL_FRAME_PARMS { /// TDD configuration uint16_t tdd_uplink_nr[2*NR_MAX_SLOTS_PER_FRAME]; /* this is a bitmap of symbol of each slot given for 2 frames */ - //SSB related params + //SSB related params /// Start in Subcarrier index of the SSB block uint16_t ssb_start_subcarrier; /// SSB type nr_ssb_type_e ssb_type; + /// Number of SSB + uint8_t L_ssb; /// PBCH polar encoder params t_nrPolar_params pbch_polar_params; @@ -317,5 +319,4 @@ typedef struct NR_DL_FRAME_PARMS { } NR_DL_FRAME_PARMS; - #endif diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index a7f8ef6884..6827b082d1 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -76,28 +76,47 @@ int return_ssb_type(nfapi_config_request_t *cfg) }*/ + // First SSB starting symbol candidate is used and type B is chosen for 30kHz SCS -int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp) +int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp, uint8_t i_ssb) { int mu = cfg->subframe_config.numerology_index_mu.value; int symbol = 0; + uint8_t n, n_temp; + nr_ssb_type_e type = fp->ssb_type; + int case_AC[2] = {2,8}; + int case_BD[4] = {4,8,16,20}; + int case_E[8] = {8, 12, 16, 20, 32, 36, 40, 44}; + switch(mu) { - case NR_MU_0: - symbol = 2; + case NR_MU_0: // case A + n = i_ssb >> 1; + symbol = case_AC[i_ssb % 2] + 14*n; break; - case NR_MU_1: // case B - symbol = 4; + case NR_MU_1: + if (type == 1){ // case B + n = i_ssb >> 2; + symbol = case_BD[i_ssb % 4] + 28*n; + } + if (type == 2){ // case C + n = i_ssb >> 1; + symbol = case_AC[i_ssb % 2] + 14*n; + } break; - case NR_MU_3: - symbol = 4; + case NR_MU_3: // case D + n_temp = i_ssb >> 2; + n = n_temp + (n_temp >> 2); + symbol = case_BD[i_ssb % 4] + 28*n; break; - case NR_MU_4: - symbol = 8; + case NR_MU_4: // case E + n_temp = i_ssb >> 3; + n = n_temp + (n_temp >> 2); + symbol = case_E[i_ssb % 8] + 56*n; break; default: @@ -122,33 +141,46 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { nfapi_nr_config_request_t *cfg = &gNB->gNB_config; int **txdataF = gNB->common_vars.txdataF; uint8_t *pbch_pdu=&gNB->pbch_pdu[0]; - int ss_slot = (cfg->sch_config.half_frame_index.value)? 10 : 0; - uint8_t Lmax, ssb_index=0, n_hf=0; + // to set a effective slot number between 0 to 9 in the half frame where the SSB is supposed to be + uint8_t Lmax, ssb_index, n_hf; + int ssb_start_symbol, rel_slot; + + n_hf = cfg->sch_config.half_frame_index.value; + rel_slot = (n_hf)? (slot-10) : slot; + + Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; // max number of ssb + + if (fp->L_ssb > Lmax) + AssertFatal(0==1, "Invalid number of SSB larger than %d \n", Lmax); LOG_D(PHY,"common_signal_procedures: frame %d, slot %d\n",frame,slot); - int ssb_start_symbol = nr_get_ssb_start_symbol(cfg, fp); - nr_set_ssb_first_subcarrier(cfg, fp); - Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; - - - if (slot == ss_slot) + if(rel_slot<10 && rel_slot>=0) { - // Current implementation is based on SSB in first half frame, first candidate - LOG_D(PHY,"SS TX: frame %d, slot %d, start_symbol %d\n",frame,slot, ssb_start_symbol); + for (int i=0; i<2; i++) // max two SSB per frame + { + ssb_index = i + 2*rel_slot; // computing the ssb_index + if (ssb_index < (fp->L_ssb)) // generating the ssb only if the current ssb index is lower than number of SSB configured + { + int ssb_start_symbol_abs = nr_get_ssb_start_symbol(cfg, fp, ssb_index); // computing the starting symbol for current ssb + ssb_start_symbol = ssb_start_symbol_abs % 14; // start symbol wrt slot - nr_generate_pss(gNB->d_pss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); - nr_generate_sss(gNB->d_sss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); + nr_set_ssb_first_subcarrier(cfg, fp); + + LOG_D(PHY,"SS TX: frame %d, slot %d, start_symbol %d\n",frame,slot, ssb_start_symbol); - if (!(frame&7)){ - LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,slot,gNB->pbch_configured); - if (gNB->pbch_configured != 1)return; - gNB->pbch_configured = 0; - } + nr_generate_pss(gNB->d_pss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); + nr_generate_sss(gNB->d_sss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); - nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF[0], AMP, ssb_start_symbol, cfg, fp); + if (!(frame&7)){ + LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,slot,gNB->pbch_configured); + if (gNB->pbch_configured != 1)return; + gNB->pbch_configured = 0; + } - nr_generate_pbch(&gNB->pbch, + nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF[0], AMP, ssb_start_symbol, cfg, fp); + + nr_generate_pbch(&gNB->pbch, gNB->nrPolar_params, pbch_pdu, gNB->nr_pbch_interleaver, @@ -157,6 +189,8 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { ssb_start_symbol, n_hf,Lmax,ssb_index, frame, cfg, fp); + } + } } } From 0a9ea26b9ec9926bb53d6a6c32acc0663eb512d0 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 12 Feb 2019 10:28:57 +0100 Subject: [PATCH 002/117] bit-wise choice of SSB to transmit --- openair1/PHY/INIT/nr_parms.c | 2 +- openair1/PHY/defs_nr_common.h | 2 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 9 +++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index 273bfbfe1a..b8aa48c10b 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -46,7 +46,7 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, fp->numerology_index = mu; fp->Ncp = Ncp; fp->N_RB_DL = N_RB_DL; - fp->L_ssb = 8; // TODO get the number of SSB value from higher layers (and config file finally) + fp->L_ssb = 255; // TODO get the number of SSB value from higher layers (and config file finally) fp->ssb_type = nr_ssb_type_B; // TODO get the type from higher layers (and config file finally) diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 8f6f22f6a4..0d491b887d 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -309,7 +309,7 @@ typedef struct NR_DL_FRAME_PARMS { /// SSB type nr_ssb_type_e ssb_type; /// Number of SSB - uint8_t L_ssb; + uint64_t L_ssb; /// PBCH polar encoder params t_nrPolar_params pbch_polar_params; diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 6827b082d1..e89c0480d0 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -150,9 +150,6 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; // max number of ssb - if (fp->L_ssb > Lmax) - AssertFatal(0==1, "Invalid number of SSB larger than %d \n", Lmax); - LOG_D(PHY,"common_signal_procedures: frame %d, slot %d\n",frame,slot); if(rel_slot<10 && rel_slot>=0) @@ -160,7 +157,7 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { for (int i=0; i<2; i++) // max two SSB per frame { ssb_index = i + 2*rel_slot; // computing the ssb_index - if (ssb_index < (fp->L_ssb)) // generating the ssb only if the current ssb index is lower than number of SSB configured + if ((fp->L_ssb >> ssb_index) & 0x01) // generating the ssb only if the bit of L_ssb at current ssb index is 1 { int ssb_start_symbol_abs = nr_get_ssb_start_symbol(cfg, fp, ssb_index); // computing the starting symbol for current ssb ssb_start_symbol = ssb_start_symbol_abs % 14; // start symbol wrt slot @@ -229,7 +226,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, num_dci = gNB->pdcch_vars.num_dci; num_pdsch_rnti = gNB->pdcch_vars.num_pdsch_rnti; - if (num_dci) { + /*if (num_dci) { LOG_I(PHY, "[gNB %d] Frame %d slot %d \ Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, slot, num_dci); @@ -248,7 +245,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, AMP, slot, *fp, *cfg); } } - } + }*/ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0); } From 0348ce15981309d494fa6167850002691ff93b22 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 12 Feb 2019 11:50:21 +0100 Subject: [PATCH 003/117] bug fix in nr gold for pbch --- openair1/PHY/NR_REFSIG/nr_gold.c | 2 +- openair1/PHY/NR_REFSIG/nr_gold_ue.c | 2 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/openair1/PHY/NR_REFSIG/nr_gold.c b/openair1/PHY/NR_REFSIG/nr_gold.c index 968f7fa7a4..08e6022764 100644 --- a/openair1/PHY/NR_REFSIG/nr_gold.c +++ b/openair1/PHY/NR_REFSIG/nr_gold.c @@ -38,7 +38,7 @@ void nr_init_pbch_dmrs(PHY_VARS_gNB* gNB) for (n_hf = 0; n_hf < N_hf; n_hf++) { for (l = 0; l < Lmax ; l++) { i_ssb = l & (Lmax-1); - i_ssb2 = (i_ssb<<2) + n_hf; + i_ssb2 = i_ssb + (n_hf<<2); reset = 1; x2 = (1<<11) * (i_ssb2 + 1) * ((Nid>>2) + 1) + (1<<6) * (i_ssb2 + 1) + (Nid&3); diff --git a/openair1/PHY/NR_REFSIG/nr_gold_ue.c b/openair1/PHY/NR_REFSIG/nr_gold_ue.c index 3bb8745875..78b92959e1 100644 --- a/openair1/PHY/NR_REFSIG/nr_gold_ue.c +++ b/openair1/PHY/NR_REFSIG/nr_gold_ue.c @@ -37,7 +37,7 @@ void nr_gold_pbch(PHY_VARS_NR_UE* ue) for (l = 0; l < Lmax ; l++) { i_ssb = l & (Lmax-1); - i_ssb2 = (i_ssb<<2) + n_hf; + i_ssb2 = i_ssb + (n_hf<<2); x1 = 1 + (1<<31); x2 = (1<<11) * (i_ssb2 + 1) * ((Nid>>2) + 1) + (1<<6) * (i_ssb2 + 1) + (Nid&3); diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index e89c0480d0..674021d99f 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -165,7 +165,6 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { nr_set_ssb_first_subcarrier(cfg, fp); LOG_D(PHY,"SS TX: frame %d, slot %d, start_symbol %d\n",frame,slot, ssb_start_symbol); - nr_generate_pss(gNB->d_pss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); nr_generate_sss(gNB->d_sss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); @@ -226,7 +225,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, num_dci = gNB->pdcch_vars.num_dci; num_pdsch_rnti = gNB->pdcch_vars.num_pdsch_rnti; - /*if (num_dci) { + if (num_dci) { LOG_I(PHY, "[gNB %d] Frame %d slot %d \ Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, slot, num_dci); @@ -245,7 +244,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, AMP, slot, *fp, *cfg); } } - }*/ + } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0); } From 186269cd5d690556c7e4dcbac25b4715dec95616 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 12 Feb 2019 15:37:24 +0100 Subject: [PATCH 004/117] removed pbch_configured issue for frames multiple of 8 --- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 674021d99f..bfa785095b 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -141,11 +141,11 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { nfapi_nr_config_request_t *cfg = &gNB->gNB_config; int **txdataF = gNB->common_vars.txdataF; uint8_t *pbch_pdu=&gNB->pbch_pdu[0]; - // to set a effective slot number between 0 to 9 in the half frame where the SSB is supposed to be uint8_t Lmax, ssb_index, n_hf; int ssb_start_symbol, rel_slot; n_hf = cfg->sch_config.half_frame_index.value; + // to set a effective slot number between 0 to 9 in the half frame where the SSB is supposed to be rel_slot = (n_hf)? (slot-10) : slot; Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; // max number of ssb @@ -162,18 +162,12 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { int ssb_start_symbol_abs = nr_get_ssb_start_symbol(cfg, fp, ssb_index); // computing the starting symbol for current ssb ssb_start_symbol = ssb_start_symbol_abs % 14; // start symbol wrt slot - nr_set_ssb_first_subcarrier(cfg, fp); + nr_set_ssb_first_subcarrier(cfg, fp); // setting the first subcarrier LOG_D(PHY,"SS TX: frame %d, slot %d, start_symbol %d\n",frame,slot, ssb_start_symbol); nr_generate_pss(gNB->d_pss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); nr_generate_sss(gNB->d_sss, txdataF[0], AMP, ssb_start_symbol, cfg, fp); - if (!(frame&7)){ - LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,slot,gNB->pbch_configured); - if (gNB->pbch_configured != 1)return; - gNB->pbch_configured = 0; - } - nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF[0], AMP, ssb_start_symbol, cfg, fp); nr_generate_pbch(&gNB->pbch, From db1eb5d92118e9f98905669c429e83d37be38820 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Wed, 13 Feb 2019 17:49:16 +0100 Subject: [PATCH 005/117] CellID taken from config file --- openair2/LAYER2/NR_MAC_gNB/config.c | 5 +++++ openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 1 + openair2/RRC/NR/rrc_gNB.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 30917fd543..9b2a61b39e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -184,6 +184,7 @@ void config_nr_mib(int Mod_idP, void config_common(int Mod_idP, int CC_idP, + int cellid, int nr_bandP, uint64_t dl_CarrierFreqP, uint32_t dl_BandwidthP @@ -193,6 +194,8 @@ void config_common(int Mod_idP, int mu = 1; + cfg->sch_config.physical_cell_id.value = cellid; + // FDD cfg->subframe_config.duplex_mode.value = 1; cfg->subframe_config.duplex_mode.tl.tag = NFAPI_SUBFRAME_CONFIG_DUPLEX_MODE_TAG; @@ -232,6 +235,7 @@ void config_common(int Mod_idP, int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_idP, + int cellid, int p_gNB, int nr_bandP, uint64_t dl_CarrierFreqP, @@ -261,6 +265,7 @@ int rrc_mac_config_req_gNB(module_id_t Mod_idP, if( servingcellconfigcommon != NULL ){ config_common(Mod_idP, CC_idP, + cellid, nr_bandP, dl_CarrierFreqP, dl_BandwidthP diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 784496ff9e..94226f4f8e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -38,6 +38,7 @@ void mac_top_init_gNB(void); int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, + int cellid, int p_gNB, int nr_bandP, uint64_t dl_CarrierFreqP, diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 10fc6b6a4e..bbf6e475e7 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -236,7 +236,7 @@ static void init_NR_SI(const protocol_ctxt_t* const ctxt_pP, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].Ncp_UL = configuration->UL_prefix_type[CC_id]; RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq = configuration->downlink_frequency[CC_id]; RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id]; - + ///MIB RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_MIB = 0; RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t*) malloc16(4); @@ -264,6 +264,7 @@ static void init_NR_SI(const protocol_ctxt_t* const ctxt_pP, rrc_mac_config_req_gNB(ctxt_pP->module_id, CC_id, + RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].physCellId, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].p_gNB, configuration->nr_band[CC_id], RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq, From 5c2f57369d0032b6c5b5edf7cd77313ea05beafe Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 14 Feb 2019 16:29:35 +0100 Subject: [PATCH 006/117] Implementation of SS block pattern choice --- openair1/PHY/INIT/nr_parms.c | 18 +++++++++++++++--- .../CONF/gnb.band78.tm1.106PRB.usrpx300.conf | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index b8aa48c10b..f67170a69d 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -47,20 +47,29 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, fp->Ncp = Ncp; fp->N_RB_DL = N_RB_DL; fp->L_ssb = 255; // TODO get the number of SSB value from higher layers (and config file finally) - fp->ssb_type = nr_ssb_type_B; // TODO get the type from higher layers (and config file finally) - switch(mu) { case NR_MU_0: //15kHz scs fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0]; fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_0]; + fp->ssb_type = nr_ssb_type_A; break; case NR_MU_1: //30kHz scs fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1]; fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_1]; + // selection of SS block pattern according to TS 38101-1 Table 5.4.3.3-1 for SCS 30kHz + if (fp->eutra_band == 5 || fp->eutra_band == 66) + fp->ssb_type = nr_ssb_type_B; + else{ + if (fp->eutra_band == 41 || ( fp->eutra_band > 76 && fp->eutra_band < 80) ) + fp->ssb_type = nr_ssb_type_C; + else + AssertFatal(1==0,"NR Operating Band n%d not available for SS block SCS with mu=%d\n", fp->eutra_band, mu); + } + switch(N_RB_DL){ case 11: case 24: @@ -147,11 +156,13 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, case NR_MU_3: fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3]; fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_3]; + fp->ssb_type = nr_ssb_type_D; break; case NR_MU_4: fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4]; fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_4]; + fp->ssb_type = nr_ssb_type_E; break; default: @@ -184,7 +195,8 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config, NR_DL_FRAME_PARMS *fp) { - + fp->eutra_band = config->nfapi_config.rf_bands.rf_band[0]; + fp->frame_type = !(config->subframe_config.duplex_mode.value); return nr_init_frame_parms0(fp, config->subframe_config.numerology_index_mu.value, config->subframe_config.dl_cyclic_prefix_type.value, diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf index d62b06aaa5..f170d7ce87 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf @@ -26,10 +26,10 @@ gNBs = node_function = "3GPP_gNODEB"; node_timing = "synch_to_ext_device"; node_synch_ref = 0; - frame_type = "FDD"; + frame_type = "TDD"; DL_prefix_type = "NORMAL"; UL_prefix_type = "NORMAL"; - eutra_band = 22; + eutra_band = 78; downlink_frequency = 3510000000L; uplink_frequency_offset = -120000000; Nid_cell = 0; From 380bac3e984ffe1db43ac29d6d9dea0b5a3028b6 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Fri, 15 Feb 2019 11:06:30 +0100 Subject: [PATCH 007/117] Warning removals and first update of small block coding --- .../nfapi/public_inc/nfapi_interface.h | 2 +- .../nfapi/public_inc/nfapi_nr_interface.h | 2 +- openair1/PHY/CODING/TESTBENCH/polartest.c | 122 +++++++++++++-- openair1/PHY/CODING/coding_defs.h | 2 + openair1/PHY/CODING/crc_byte.c | 2 +- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 2 +- .../CODING/nrPolar_tools/nr_polar_encoder.c | 139 ++++++++++-------- .../PHY/CODING/nrSmallBlock/encodeSmall.c | 0 openair1/PHY/CODING/nr_rate_matching.c | 1 + openair1/PHY/LTE_TRANSPORT/dlsch_coding.c | 2 +- .../SCHED_NR_UE/pucch_power_control_ue_nr.c | 2 + openair1/SCHED_NR_UE/pucch_uci_ue_nr.c | 57 +------ openair1/SIMULATION/NR_PHY/dlschsim.c | 18 +-- openair1/SIMULATION/NR_PHY/dlsim.c | 49 +++--- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 13 +- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 22 +++ 17 files changed, 261 insertions(+), 176 deletions(-) create mode 100644 openair1/PHY/CODING/nrSmallBlock/encodeSmall.c diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h index 51f66c3075..fc3859be94 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h @@ -583,7 +583,7 @@ typedef struct { } nfapi_pnf_phy_rf_config_t; #define NFAPI_PNF_PHY_RF_TAG 0x1003 -// Generic strucutre for single tlv value. +// Generic structure for single tlv value. typedef struct { nfapi_tl_t tl; uint16_t value; diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h index 4273186dcf..36c865be01 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h @@ -72,7 +72,7 @@ typedef struct // These TLVs are used by the VNF to configure the RF in the PNF // nfapi_uint16_tlv_t max_transmit_power; - nfapi_uint16_tlv_t nrarfcn; + nfapi_uint32_tlv_t nrarfcn; // nfapi_nmm_frequency_bands_t nmm_gsm_frequency_bands; // nfapi_nmm_frequency_bands_t nmm_umts_frequency_bands; diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index 6d50070b86..e4b4758493 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -11,10 +11,36 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h" #include "PHY/CODING/coding_defs.h" #include "SIMULATION/TOOLS/sim.h" +//#include "PHY/NR_TRANSPORT/nr_transport.h" +//#include "common/utils/LOG/log.h" //#define DEBUG_DCI_POLAR_PARAMS //#define DEBUG_POLAR_TIMING //#define DEBUG_CRC +//#define DEBUG_POLARTEST + +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}; + +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); + + for (uint8_t i=0; i0x%08x\n", testInput[0]); - for (int i=0; i<32; i++) - printf("%d\n",(testInput[0]>>i)&1);*/ - +#ifdef DEBUG_POLARTEST + printf("testInput: "); + for (int i = 0; i < testArrayLength; i++) printf("[%d]->0x%08x\t",i, testInput[i]); + printf("\n"); + printf("testInput[0]: "); + for (int i=0; i<32; i++) printf("[%d]=%d-",i,(testInput[0]>>i)&1); + printf("\n"); + printf("testInput[1]: "); + for (int i=0; i<32; i++) printf("[%d]=%d-",i,(testInput[1]>>i)&1); + printf("\n"); +#endif int len_mod64=currentPtr->payloadBits&63; ((uint64_t*)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)<0x%08x\t",i, testInput[i]); + printf("\n"); + + printf("testInput[0]: "); + for (int i=0; i<32; i++) printf("[%d]=%d-",i,(testInput[0]>>i)&1); + printf("\n"); + printf("testInput[1]: "); + for (int i=0; i<32; i++) printf("[%d]=%d-",i,(testInput[1]>>i)&1); + printf("\n"); +#endif + + if (matlabDebug == 1){ + memset(testInput,0,sizeof(uint32_t) * testArrayLength); + /*testInput[0] |= ((uint32_t)1 << 31); testInput[0] |= ((uint32_t)1 << 28); testInput[0] |= ((uint32_t)1 << 26); + testInput[0] |= ((uint32_t)1 << 25); testInput[0] |= ((uint32_t)1 << 22); testInput[0] |= ((uint32_t)1 << 21); + testInput[0] |= ((uint32_t)1 << 19); testInput[0] |= ((uint32_t)1 << 17); testInput[0] |= ((uint32_t)1 << 15); + testInput[0] |= ((uint32_t)1 << 14); testInput[0] |= ((uint32_t)1 << 12); testInput[0] |= ((uint32_t)1 << 10); + testInput[0] |= ((uint32_t)1 << 8); testInput[0] |= ((uint32_t)1 << 5); testInput[0] |= ((uint32_t)1 << 3); + testInput[0] |= ((uint32_t)1 << 2); testInput[0] |= ((uint32_t)1 << 1);*/ + + + + testInput[0] |= ((uint32_t)1 << 30); testInput[0] |= ((uint32_t)1 << 29); testInput[0] |= ((uint32_t)1 << 28); + testInput[0] |= ((uint32_t)1 << 26); testInput[0] |= ((uint32_t)1 << 23); testInput[0] |= ((uint32_t)1 << 21); + testInput[0] |= ((uint32_t)1 << 19); testInput[0] |= ((uint32_t)1 << 17); testInput[0] |= ((uint32_t)1 << 16); + testInput[0] |= ((uint32_t)1 << 14); testInput[0] |= ((uint32_t)1 << 12); testInput[0] |= ((uint32_t)1 << 10); + testInput[0] |= ((uint32_t)1 << 9); testInput[0] |= ((uint32_t)1 << 6); testInput[0] |= ((uint32_t)1 << 5); + testInput[0] |= ((uint32_t)1 << 3); testInput[0] |= ((uint32_t)1); + + + /*printf("testInput (a_31,..., a_0): "); + for (int i=31; i>=0; i--) printf("%d-",(testInput[0]>>i)&1); //a_31, a_30, ..., a_0 + printf("testInput = 0x%llx\n", testInput[0]); + printf("\n");*/ + + + /*for (int i=0;i<32;i++){ + memset(testInput,0,sizeof(uint32_t) * testArrayLength); + testInput[0] |= ((uint32_t)1 << i); + int crc = crc24c(testInput,32); + printf("[i=%d]testInput = 0x%08lx, crc = 0x%lx\n", i,testInput[0], crc); + } + memset(testInput,0,sizeof(uint32_t) * testArrayLength); + int crc = crc24c(testInput,32); + printf("testInput = 0x%08lx, crc = 0x%lx\n", testInput[0], crc);*/ + + } + + uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS]; + memset((void*)nr_pbch_interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS); + nr_init_pbch_interleaver(nr_pbch_interleaver); + for (int i=0; i<=31;i++) + printf("nr_pbch_interleaver[%d]=%d\n",i,nr_pbch_interleaver[i]); + + for (int i=0; i0x%08x\n", encoderOutput[0]); diff --git a/openair1/PHY/CODING/coding_defs.h b/openair1/PHY/CODING/coding_defs.h index 0f316e7869..1b23de1cb9 100644 --- a/openair1/PHY/CODING/coding_defs.h +++ b/openair1/PHY/CODING/coding_defs.h @@ -30,6 +30,8 @@ #include #include +typedef unsigned __int128 uint128_t; + #define CRC24_A 0 #define CRC24_B 1 #define CRC16 2 diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index d728d6b9ad..67190698e1 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -258,7 +258,7 @@ unsigned int crcPayload(unsigned char * inptr, int bitlen, uint32_t* crc256Table int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) { uint32_t crc=0,oldcrc=0; - uint8_t crc_len,temp; + uint8_t crc_len; switch (crc_type) { case CRC24_A: diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index 68e9ef3571..bd056c3a18 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -147,7 +147,7 @@ void polar_encoder_dci(uint32_t *in, t_nrPolar_paramsPtr polarParams, uint16_t n_RNTI); -void polar_encoder_fast(uint64_t *A, +void polar_encoder_fast(uint64_t *Aprime, uint32_t *out, int32_t crcmask, t_nrPolar_paramsPtr polarParams); diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c index 50d14d87e2..bafddae850 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c @@ -33,6 +33,7 @@ //#define DEBUG_POLAR_ENCODER //#define DEBUG_POLAR_ENCODER_DCI //#define DEBUG_POLAR_ENCODER_TIMING +#define DEBUG_POLAR_MATLAB #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" @@ -336,8 +337,8 @@ void build_polar_tables(t_nrPolar_paramsPtr polarParams) { if (polarParams->information_bit_pattern[i] > 0) { polarParams->G_N_tab[k] = (uint64_t*)memalign(32,(polarParams->N/64)*sizeof(uint64_t)); memset((void*)polarParams->G_N_tab[k],0,(polarParams->N/64)*sizeof(uint64_t)); - for (int j=0;jN;j++) - polarParams->G_N_tab[k][j/64] |= ((uint64_t)polarParams->G_N[i][j])<<(j&63); + for (int j=0;jN;j++) + polarParams->G_N_tab[k][j/64] |= ((uint64_t)polarParams->G_N[i][j])<<(j&63); #ifdef DEBUG_POLAR_ENCODER printf("Bit %d Selecting row %d of G : ",k,i); for (int j=0;jN;j+=4) printf("%1x",polarParams->G_N[i][j]+(polarParams->G_N[i][j+1]*2)+(polarParams->G_N[i][j+2]*4)+(polarParams->G_N[i][j+3]*8)); @@ -385,7 +386,7 @@ void build_polar_tables(t_nrPolar_paramsPtr polarParams) { } -void polar_encoder_fast(uint64_t *A, +void polar_encoder_fast(uint64_t *Aprime, uint32_t *out, int32_t crcmask, t_nrPolar_paramsPtr polarParams) { @@ -394,9 +395,13 @@ void polar_encoder_fast(uint64_t *A, AssertFatal(polarParams->K < 129, "K = %d > 128, is not supported yet\n",polarParams->K); AssertFatal(polarParams->payloadBits < 65, "payload bits = %d > 64, is not supported yet\n",polarParams->payloadBits); - uint64_t B[4]={0,0,0,0},Cprime[4]={0,0,0,0}; + uint64_t B[4]={0,0,0,0}, Cprime[4]={0,0,0,0}; int bitlen = polarParams->payloadBits; +#ifdef DEBUG_POLAR_MATLAB + if (polarParams->K<65) printf("[polar_encoder_fast]A[0] = 0x%llx\n", (unsigned long long)(Aprime[0])); //(unsigned long long)(Aprime[0]&(((uint64_t)1<>8))); } else if (bitlen<=64) { uint8_t A64_flip[8]; - uint64_t Aprime= (uint32_t)(((uint64_t)*A)<<(64-bitlen)); - A64_flip[0]=((uint8_t*)&Aprime)[7]; - A64_flip[1]=((uint8_t*)&Aprime)[6]; - A64_flip[2]=((uint8_t*)&Aprime)[5]; - A64_flip[3]=((uint8_t*)&Aprime)[4]; - A64_flip[4]=((uint8_t*)&Aprime)[3]; - A64_flip[5]=((uint8_t*)&Aprime)[2]; - A64_flip[6]=((uint8_t*)&Aprime)[1]; - A64_flip[7]=((uint8_t*)&Aprime)[0]; + uint64_t AprimeTmp= (uint32_t)(((uint64_t)*Aprime)<<(64-bitlen)); + A64_flip[0]=((uint8_t*)&AprimeTmp)[7]; + A64_flip[1]=((uint8_t*)&AprimeTmp)[6]; + A64_flip[2]=((uint8_t*)&AprimeTmp)[5]; + A64_flip[3]=((uint8_t*)&AprimeTmp)[4]; + A64_flip[4]=((uint8_t*)&AprimeTmp)[3]; + A64_flip[5]=((uint8_t*)&AprimeTmp)[2]; + A64_flip[6]=((uint8_t*)&AprimeTmp)[1]; + A64_flip[7]=((uint8_t*)&AprimeTmp)[0]; tcrc = (uint64_t)((crcmask^(crc24c(A64_flip,bitlen)>>8))); } + else if (bitlen<=128) { + uint8_t A128_flip[16]; + uint128_t AprimeTmp= (uint32_t)(((uint128_t)*Aprime)<<(128-bitlen)); + A128_flip[0]=((uint8_t*)&AprimeTmp)[15]; A128_flip[1]=((uint8_t*)&AprimeTmp)[14]; + A128_flip[2]=((uint8_t*)&AprimeTmp)[13]; A128_flip[3]=((uint8_t*)&AprimeTmp)[12]; + A128_flip[4]=((uint8_t*)&AprimeTmp)[11]; A128_flip[5]=((uint8_t*)&AprimeTmp)[10]; + A128_flip[6] =((uint8_t*)&AprimeTmp)[9]; A128_flip[7] =((uint8_t*)&AprimeTmp)[8]; + A128_flip[8] =((uint8_t*)&AprimeTmp)[7]; A128_flip[9] =((uint8_t*)&AprimeTmp)[6]; + A128_flip[10]=((uint8_t*)&AprimeTmp)[5]; A128_flip[11]=((uint8_t*)&AprimeTmp)[4]; + A128_flip[12]=((uint8_t*)&AprimeTmp)[3]; A128_flip[13]=((uint8_t*)&AprimeTmp)[2]; + A128_flip[14]=((uint8_t*)&AprimeTmp)[1]; A128_flip[15]=((uint8_t*)&AprimeTmp)[0]; + tcrc = (uint64_t)((crcmask^(crc24c(A128_flip,bitlen)>>8))); + } int n; - // this is number of quadwords in the bit string - int quadwlen = (polarParams->K>>6); + int quadwlen = (polarParams->K>>6); // this is number of quadwords (64-bits) in the bit string if ((polarParams->K&63) > 0) quadwlen++; - // Create the B bitstring as - // b_{N'-1} b_{N'-2} ... b_{N'-A} b_{N'-A-1} ... b_{N'-A-Nparity} = a_{N-1} a_{N-2} ... a_{N-A} p_{N_parity-1} ... p_0 + // Create the B bit string as + // 0, 0, ..., 0, a'_0, a'_1, ..., a'_A-1, p_0, p_1, ..., p_{N_parity-1} - for (n=0;ncrcParityBits) | tcrc; - else B[n] = (A[n] << polarParams->crcParityBits) | (A[n-1]>>(64-polarParams->crcParityBits)); + //??? b_{N'-1} b_{N'-2} ... b_{N'-A} b_{N'-A-1} ... b_{N'-A-Nparity} = a_{N-1} a_{N-2} ... a_{N-A} p_{N_parity-1} ... p_0 + + + for (n=0;ncrcParityBits) | tcrc; + else B[n] = (Aprime[n] << polarParams->crcParityBits) | (Aprime[n-1]>>(64-polarParams->crcParityBits)); - +#ifdef DEBUG_POLAR_MATLAB + // B = pbchB + for (int i = 0; i < quadwlen; i++) printf("[polar_encoder_fast]B[%d] = 0x%llx\n", i, (unsigned long long)(B[i])); +#endif + uint8_t *Bbyte = (uint8_t*)B; // for each byte of B, lookup in corresponding table for 64-bit word corresponding to that byte and its position if (polarParams->K<65) @@ -464,10 +489,15 @@ void polar_encoder_fast(uint64_t *A, } } +#ifdef DEBUG_POLAR_MATLAB + // Cprime = pbchCprime + for (int i = 0; i < quadwlen; i++) printf("[polar_encoder_fast]C'[%d]= 0x%llx\n", i, (unsigned long long)(Cprime[i])); +#endif + #ifdef DEBUG_POLAR_ENCODER if (polarParams->K<65) printf("A %llx B %llx Cprime %llx (payload bits %d,crc %x)\n", - (unsigned long long)(A[0]&(((uint64_t)1<payloadBits, @@ -475,52 +505,35 @@ void polar_encoder_fast(uint64_t *A, else if (polarParams->K<129) { if (bitlen<64) printf("A %llx B %llx|%llx Cprime %llx|%llx (payload bits %d,crc %x)\n", - (unsigned long long)(A[0]&(((uint64_t)1<payloadBits, tcrc); else printf("A %llx|%llx B %llx|%llx Cprime %llx|%llx (payload bits %d,crc %x)\n", - (unsigned long long)(A[1]&(((uint64_t)1<<(bitlen-64))-1)),(unsigned long long)(A[0]), + (unsigned long long)(Aprime[1]&(((uint64_t)1<<(bitlen-64))-1)),(unsigned long long)(Aprime[0]), (unsigned long long)(B[1]),(unsigned long long)(B[0]), (unsigned long long)(Cprime[1]),(unsigned long long)(Cprime[0]), polarParams->payloadBits, - crc24c((uint8_t*)A,bitlen)>>8); + crc24c((uint8_t*)Aprime,bitlen)>>8); } #endif - /* printf("Bbytes : %x.%x.%x.%x.%x.%x.%x.%x\n",Bbyte[0],Bbyte[1],Bbyte[2],Bbyte[3],Bbyte[4],Bbyte[5],Bbyte[6],Bbyte[7]); - printf("%llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n",polarParams->cprime_tab[0][Bbyte[0]] , - polarParams->cprime_tab[1][Bbyte[1]] , - polarParams->cprime_tab[2][Bbyte[2]] , - polarParams->cprime_tab[3][Bbyte[3]] , - polarParams->cprime_tab[4][Bbyte[4]] , - polarParams->cprime_tab[5][Bbyte[5]] , - polarParams->cprime_tab[6][Bbyte[6]] , - polarParams->cprime_tab[7][Bbyte[7]]);*/ // now do Gu product (here using 64-bit XORs, we can also do with SIMD after) // here we're reading out the bits LSB -> MSB, is this correct w.r.t. 3GPP ? uint64_t Cprime_i; - /* printf("%llx Cprime_0 (%llx) G %llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n",Cprime_i,Cprime &1, - polarParams->G_N_tab[0][0], - polarParams->G_N_tab[0][1], - polarParams->G_N_tab[0][2], - polarParams->G_N_tab[0][3], - polarParams->G_N_tab[0][4], - polarParams->G_N_tab[0][5], - polarParams->G_N_tab[0][6], - polarParams->G_N_tab[0][7]);*/ uint64_t D[8]={0,0,0,0,0,0,0,0}; int off=0; int len=polarParams->K; + for (int j=0;j<(1+(polarParams->K>>6));j++,off+=64,len-=64) { for (int i=0;i<((len>63) ? 64 : len);i++) { Cprime_i = -((Cprime[j]>>i)&1); // this converts bit 0 as, 0 => 0000x00, 1 => 1111x11 - /* -#ifdef DEBUG_POLAR_ENCODER + + #ifdef DEBUG_POLAR_ENCODER printf("%llx Cprime_%d (%llx) G %llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n", Cprime_i,off+i,(Cprime[j]>>i) &1, polarParams->G_N_tab[off+i][0], @@ -531,8 +544,8 @@ void polar_encoder_fast(uint64_t *A, polarParams->G_N_tab[off+i][5], polarParams->G_N_tab[off+i][6], polarParams->G_N_tab[off+i][7]); -#endif - */ + #endif + uint64_t *Gi=polarParams->G_N_tab[off+i]; D[0] ^= (Cprime_i & Gi[0]); D[1] ^= (Cprime_i & Gi[1]); @@ -545,17 +558,17 @@ void polar_encoder_fast(uint64_t *A, } } #ifdef DEBUG_POLAR_ENCODER - printf("D %llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n", - D[0], - D[1], - D[2], - D[3], - D[4], - D[5], - D[6], - D[7]); + printf("D %llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n", D[0], D[1], D[2], D[3], D[4], D[5], D[6], D[7]); #endif - polar_rate_matching(polarParams,(void*)D,(void*)out); +#ifdef DEBUG_POLAR_MATLAB + // D = pbchD + for (int i = 0; i < 8; i++) printf("[polar_encoder_fast]D[%d] = 0x%016llx\n", i, (unsigned long long)(D[i])); +#endif + polar_rate_matching(polarParams,(void*)D,(void*)out); +#ifdef DEBUG_POLAR_MATLAB + // out = pbchF + for (int i = 0; i < (NR_POLAR_PBCH_E/32); i++) printf("[polar_encoder_fast]F[%d] = 0x%08lx\n", i, (unsigned long)(out[i])); +#endif } diff --git a/openair1/PHY/CODING/nrSmallBlock/encodeSmall.c b/openair1/PHY/CODING/nrSmallBlock/encodeSmall.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openair1/PHY/CODING/nr_rate_matching.c b/openair1/PHY/CODING/nr_rate_matching.c index 0bce31630f..f71535f654 100644 --- a/openair1/PHY/CODING/nr_rate_matching.c +++ b/openair1/PHY/CODING/nr_rate_matching.c @@ -26,6 +26,7 @@ #include "PHY/defs_gNB.h" #include "PHY/defs_nr_UE.h" +#include "PHY/CODING/coding_defs.h" //#define RM_DEBUG 1 diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c index a7e4b33c16..12870016fa 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c @@ -703,7 +703,7 @@ int dlsch_encoding_all(PHY_VARS_eNB *eNB, int dlsch_encoding(PHY_VARS_eNB *eNB, - unsigned char *a, + unsigned char *a, uint8_t num_pdcch_symbols, LTE_eNB_DLSCH_t *dlsch, int frame, diff --git a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c index 93400def0a..3a910cfd1e 100644 --- a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c @@ -33,6 +33,8 @@ #include "SCHED_NR_UE/pucch_uci_ue_nr.h" #include "SCHED_NR_UE/pucch_power_control_ue_nr.h" +int16_t get_PL(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index); + /**************** defines **************************************/ /**************** variables **************************************/ diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c index fb38c80eb8..27295f15d3 100644 --- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c @@ -36,6 +36,7 @@ #include "PHY/NR_REFSIG/ss_pbch_nr.h" #include "PHY/defs_nr_UE.h" +#include "PHY/NR_UE_TRANSPORT/pucch_nr.h" #ifndef NO_RAT_NR @@ -51,57 +52,7 @@ int8_t nr_ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP, uint8_t eNB_id, uint16_t rnti, sub_frame_t subframe); uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id); uint8_t is_ri_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id); -/* -void nr_generate_pucch0(int32_t **txdataF, - NR_DL_FRAME_PARMS *frame_parms, - PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, - int16_t amp, - int nr_tti_tx, - uint8_t mcs, - uint8_t nrofSymbols, - uint8_t startingSymbolIndex, - uint16_t startingPRB); -void nr_generate_pucch1(int32_t **txdataF, - NR_DL_FRAME_PARMS *frame_parms, - PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, - uint64_t payload, - int16_t amp, - int nr_tti_tx, - uint8_t nrofSymbols, - uint8_t startingSymbolIndex, - uint16_t startingPRB, - uint16_t startingPRB_intraSlotHopping, - uint8_t timeDomainOCC, - uint8_t nr_bit); - -void nr_generate_pucch2(int32_t **txdataF, - NR_DL_FRAME_PARMS *frame_parms, - PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, - uint64_t payload, - int16_t amp, - int nr_tti_tx, - uint8_t nrofSymbols, - uint8_t startingSymbolIndex, - uint8_t nrofPRB, - uint16_t startingPRB, - uint8_t nr_bit); - -void nr_generate_pucch3_4(int32_t **txdataF, - NR_DL_FRAME_PARMS *frame_parms, - pucch_format_nr_t fmt, - PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, - uint64_t payload, - int16_t amp, - int nr_tti_tx, - uint8_t nrofSymbols, - uint8_t startingSymbolIndex, - uint8_t nrofPRB, - uint16_t startingPRB, - uint8_t nr_bit, - uint8_t occ_length_format4, - uint8_t occ_index_format4); -*/ /**************** variables **************************************/ @@ -556,7 +507,8 @@ bool pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_ switch(format) { case pucch_format0_nr: { - nr_generate_pucch0(ue,ue->common_vars.txdataF, + nr_generate_pucch0(ue, + ue->common_vars.txdataF, &ue->frame_parms, &ue->pucch_config_dedicated_nr[gNB_id], tx_amp, @@ -570,7 +522,8 @@ bool pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_ } case pucch_format1_nr: { - nr_generate_pucch1(ue,ue->common_vars.txdataF, + nr_generate_pucch1(ue, + ue->common_vars.txdataF, &ue->frame_parms, &ue->pucch_config_dedicated_nr[gNB_id], pucch_payload, diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 1c2b2305d6..c648d19264 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -145,8 +145,7 @@ int main(int argc, char **argv) { //uint16_t NB_RB=25; SCM_t channel_model = AWGN; //Rayleigh1_anticorr; uint8_t N_RB_DL = 106, mu = 1; - unsigned char frame_type = 0; - unsigned char pbch_phase = 0; + unsigned char frame_type = 0, pbch_phase = 0; int frame = 0, subframe = 0; int frame_length_complex_samples; //int frame_length_complex_samples_no_prefix; @@ -341,8 +340,8 @@ int main(int argc, char **argv) { printf("-x Transmission mode (1,2,6 for the moment)\n"); printf("-y Number of TX antennas used in eNB\n"); printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-i Relative strength of first interfering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second interfering eNB (in dB) - cell_id mod 3 = 2\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); @@ -482,13 +481,10 @@ int main(int argc, char **argv) { short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); double errors_bit_uncoded = 0; - unsigned char *estimated_output; - unsigned char *estimated_output_bit; - unsigned char *test_input_bit; + //unsigned char *estimated_output = malloc16(sizeof(unsigned char) * 16 * 68 * 384); + unsigned char *estimated_output_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); + unsigned char *test_input_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); unsigned int errors_bit = 0; - test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[UE->current_thread_id[subframe]][0][0]; NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; harq_process->mcs = Imcs; @@ -503,7 +499,7 @@ int main(int argc, char **argv) { for (i = 0; i < TBS / 8; i++) test_input[i] = (unsigned char) rand(); - estimated_output = harq_process->b; + //estimated_output = harq_process->b; #ifdef DEBUG_DLSCHSIM for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1d440c5d0d..4b7102ae7f 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -42,10 +42,11 @@ #include "PHY/MODULATION/modulation_UE.h" #include "PHY/INIT/phy_init.h" #include "PHY/NR_TRANSPORT/nr_transport.h" -#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +//#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED_NR/sched_nr.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" +#include "SCHED_NR/fapi_nr_l1.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" @@ -54,6 +55,10 @@ #include "NR_PHY_INTERFACE/NR_IF_Module.h" #include "NR_UE_PHY_INTERFACE/NR_IF_Module.h" +#include "LAYER2/NR_MAC_UE/mac_proto.h" +#include "LAYER2/NR_MAC_gNB/mac_proto.h" +#include "RRC/NR/MESSAGES/asn1_msg.h" + PHY_VARS_gNB *gNB; PHY_VARS_NR_UE *UE; @@ -78,7 +83,7 @@ int32_t get_uldl_offset(int nr_bandP) {return(0);} NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} int8_t dummy_nr_ue_dl_indication(nr_downlink_indication_t *dl_info){return(0);} -int8_t dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} +int dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) { return(SF_DL);} @@ -99,13 +104,6 @@ int rlc_module_init (void) {return(0);} void pdcp_layer_init(void) {} int rrc_init_nr_global_param(void){return(0);} -void config_common(int Mod_idP, - int CC_idP, - int nr_bandP, - uint64_t dl_CarrierFreqP, - uint32_t dl_BandwidthP - ); - // needed for some functions PHY_VARS_NR_UE ***PHY_vars_UE_g; @@ -115,40 +113,39 @@ int main(int argc, char **argv) { char c; - - int i,l,aa; + int i,aa; double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1=2.0; uint8_t snr1set=0; int **txdata; double **s_re,**s_im,**r_re,**r_im; - double iqim = 0.0; - unsigned char pbch_pdu[6]; + //double iqim = 0.0; + //unsigned char pbch_pdu[6]; // int sync_pos, sync_pos_slot; // FILE *rx_frame_file; FILE *output_fd = NULL; uint8_t write_output_file=0; //int result; - int freq_offset; - // int subframe_offset; + // int freq_offset, subframe_offset; // char fname[40], vname[40]; - int trial,n_trials=1,n_errors,n_errors2,n_alamouti; + int trial,n_trials=1,n_errors=0; + //int n_errors2=0,n_alamouti=0; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; channel_desc_t *gNB2UE; - uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; + //uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; uint8_t extended_prefix_flag=0; int8_t interf1=-21,interf2=-21; FILE *input_fd=NULL,*pbch_file_fd=NULL; - char input_val_str[50],input_val_str2[50]; + //char input_val_str[50],input_val_str2[50]; - uint8_t frame_mod4,num_pdcch_symbols = 0; + //uint8_t frame_mod4, num_pdcch_symbols = 0; SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - double pbch_sinr; - int pbch_tx_ant; + //double pbch_sinr; + //int pbch_tx_ant; int N_RB_DL=273,mu=1; unsigned char frame_type = 0; @@ -358,8 +355,8 @@ int main(int argc, char **argv) printf("-x Transmission mode (1,2,6 for the moment)\n"); printf("-y Number of TX antennas used in eNB\n"); printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-i Relative strength of first interfering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second interfering eNB (in dB) - cell_id mod 3 = 2\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); @@ -497,7 +494,7 @@ int main(int argc, char **argv) gNB_mac = RC.nrmac[0]; config_common(0,0,78,(uint64_t)3640000000L,N_RB_DL); - config_nr_mib(0,0,1,kHz30,0,0,0,0); + config_nr_mib(0,0,1,kHz30,0,0,0,0,0); nr_l2_init_ue(); UE_mac = get_mac_inst(0); @@ -640,8 +637,8 @@ int main(int argc, char **argv) for (SNR=snr0; SNRul_config_request; - fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + //fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; nr_phy_config_t *phy_config = &mac->phy_config; //ul_config->ul_config_list[ul_config->number_pdus].ulsch_config_pdu.rnti = rnti; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index d29a9fb908..b0f6cff84e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -36,6 +36,7 @@ #include "LAYER2/MAC/mac_extern.h" #include "LAYER2/MAC/mac_proto.h" #include "LAYER2/NR_MAC_gNB/mac_proto.h" +#include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" @@ -324,7 +325,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, rnti = UE_RNTI(module_idP, i); CC_id = UE_PCCID(module_idP, i); - int spf = get_spf(cfg); + //int spf = get_spf(cfg); if (((frameP&127) == 0) && (slotP == 0)) { LOG_I(MAC, @@ -382,11 +383,11 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, } for (int ii=0; iidlsch[ii][0]; - if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - clean_eNb_dlsch(dlsch); - } + NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0]; + if((dlsch != NULL) && (dlsch->rnti == rnti)){ + LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); + clean_eNb_dlsch(dlsch); + } } for(int j = 0; j < 10; j++){ diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 784496ff9e..7060d80e7a 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -36,6 +36,28 @@ void mac_top_init_gNB(void); +uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw); + +uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn); + +void config_nr_mib(int Mod_idP, + int CC_idP, + int p_gNBP, + int subCarrierSpacingCommon, + uint32_t ssb_SubcarrierOffset, + int dmrs_TypeA_Position, + uint32_t pdcch_ConfigSIB1, + int cellBarred, + int intraFreqReselection + ); + +void config_common(int Mod_idP, + int CC_idP, + int nr_bandP, + uint64_t dl_CarrierFreqP, + uint32_t dl_BandwidthP + ); + int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, int p_gNB, From 688830e83ec60c646ed416666f217d89884c9da3 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Fri, 15 Feb 2019 17:01:58 +0100 Subject: [PATCH 008/117] SSB pattern now hardcoded in rrc, to be taken from config file in the next commit --- nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h | 8 ++++---- openair1/PHY/INIT/nr_init.c | 1 + openair1/PHY/INIT/nr_parms.c | 2 +- openair1/PHY/defs_nr_common.h | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 6 +++++- openair2/LAYER2/NR_MAC_gNB/config.c | 9 ++++++++- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 3 ++- openair2/RRC/NR/rrc_gNB.c | 3 ++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h index 4273186dcf..1747e4f71b 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h @@ -28,12 +28,12 @@ typedef struct { /*typedef struct { nfapi_tl_t tl; int64_t value; -} nfapi_int64_tlv_t; +} nfapi_int64_tlv_t;*/ typedef struct { nfapi_tl_t tl; uint64_t value; -} nfapi_uint64_tlv_t;*/ +} nfapi_uint64_tlv_t; // nFAPI enums typedef enum { @@ -175,8 +175,8 @@ typedef struct { nfapi_uint16_tlv_t physical_cell_id; nfapi_uint16_tlv_t half_frame_index; nfapi_uint16_tlv_t ssb_subcarrier_offset; - nfapi_uint16_tlv_t ssb_sib1_position_in_burst; - nfapi_uint16_tlv_t ssb_scg_position_in_burst; + nfapi_uint16_tlv_t ssb_sib1_position_in_burst; // in sib1 + nfapi_uint64_tlv_t ssb_scg_position_in_burst; // in servingcellconfigcommon nfapi_uint16_tlv_t ssb_periodicity; nfapi_uint16_tlv_t ss_pbch_block_power; nfapi_uint16_tlv_t n_ssb_crb; diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 1866eac96d..7f52c80992 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -438,6 +438,7 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config) gNB_config->sch_config.ssb_subcarrier_offset.value = phy_config->cfg->sch_config.ssb_subcarrier_offset.value;//0; gNB_config->sch_config.n_ssb_crb.value = (phy_config->cfg->rf_config.dl_carrier_bandwidth.value-20); gNB_config->sch_config.physical_cell_id.value = phy_config->cfg->sch_config.physical_cell_id.value; + gNB_config->sch_config.ssb_scg_position_in_burst.value= phy_config->cfg->sch_config.ssb_scg_position_in_burst.value; if (phy_config->cfg->subframe_config.duplex_mode.value == 0) { gNB_config->subframe_config.duplex_mode.value = TDD; diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index f67170a69d..a5eb2e659b 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -46,7 +46,6 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, fp->numerology_index = mu; fp->Ncp = Ncp; fp->N_RB_DL = N_RB_DL; - fp->L_ssb = 255; // TODO get the number of SSB value from higher layers (and config file finally) switch(mu) { @@ -197,6 +196,7 @@ int nr_init_frame_parms(nfapi_nr_config_request_t* config, fp->eutra_band = config->nfapi_config.rf_bands.rf_band[0]; fp->frame_type = !(config->subframe_config.duplex_mode.value); + fp->L_ssb = config->sch_config.ssb_scg_position_in_burst.value; return nr_init_frame_parms0(fp, config->subframe_config.numerology_index_mu.value, config->subframe_config.dl_cyclic_prefix_type.value, diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 0d491b887d..4267b79144 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -308,7 +308,7 @@ typedef struct NR_DL_FRAME_PARMS { uint16_t ssb_start_subcarrier; /// SSB type nr_ssb_type_e ssb_type; - /// Number of SSB + /// SS block pattern (max 64 ssb, each bit is on/off ssb) uint64_t L_ssb; /// PBCH polar encoder params t_nrPolar_params pbch_polar_params; diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1d440c5d0d..b6125ce7b7 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -101,7 +101,9 @@ int rrc_init_nr_global_param(void){return(0);} void config_common(int Mod_idP, int CC_idP, + int Nid_cell, int nr_bandP, + uint64_t ssb_pattern, uint64_t dl_CarrierFreqP, uint32_t dl_BandwidthP ); @@ -151,6 +153,8 @@ int main(int argc, char **argv) int pbch_tx_ant; int N_RB_DL=273,mu=1; + uint64_t ssb_pattern = 0; + unsigned char frame_type = 0; unsigned char pbch_phase = 0; @@ -496,7 +500,7 @@ int main(int argc, char **argv) mac_top_init_gNB(); gNB_mac = RC.nrmac[0]; - config_common(0,0,78,(uint64_t)3640000000L,N_RB_DL); + config_common(0,0,Nid_cell,78,ssb_pattern,(uint64_t)3640000000L,N_RB_DL); config_nr_mib(0,0,1,kHz30,0,0,0,0); nr_l2_init_ue(); diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 9b2a61b39e..b2ea58d362 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -186,7 +186,8 @@ void config_common(int Mod_idP, int CC_idP, int cellid, int nr_bandP, - uint64_t dl_CarrierFreqP, + uint64_t ssb_pattern, + uint64_t dl_CarrierFreqP, uint32_t dl_BandwidthP ){ @@ -195,6 +196,7 @@ void config_common(int Mod_idP, int mu = 1; cfg->sch_config.physical_cell_id.value = cellid; + cfg->sch_config.ssb_scg_position_in_burst.value = ssb_pattern; // FDD cfg->subframe_config.duplex_mode.value = 1; @@ -238,6 +240,7 @@ int rrc_mac_config_req_gNB(module_id_t Mod_idP, int cellid, int p_gNB, int nr_bandP, + uint64_t ssb_pattern, uint64_t dl_CarrierFreqP, int dl_BandwidthP, NR_BCCH_BCH_Message_t *mib, @@ -262,11 +265,15 @@ int rrc_mac_config_req_gNB(module_id_t Mod_idP, ); }// END if( mib != NULL ) + + + if( servingcellconfigcommon != NULL ){ config_common(Mod_idP, CC_idP, cellid, nr_bandP, + ssb_pattern, dl_CarrierFreqP, dl_BandwidthP ); diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 94226f4f8e..6db3b9202b 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -38,9 +38,10 @@ void mac_top_init_gNB(void); int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, - int cellid, + int cellid, int p_gNB, int nr_bandP, + uint64_t ssb_pattern, uint64_t dl_CarrierFreqP, int dl_BandwidthP, NR_BCCH_BCH_Message_t *mib, diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index bbf6e475e7..daf368f50d 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -261,12 +261,13 @@ static void init_NR_SI(const protocol_ctxt_t* const ctxt_pP, LOG_I(NR_RRC,"Done init_NR_SI\n"); - + uint64_t ssb_pattern = 255; rrc_mac_config_req_gNB(ctxt_pP->module_id, CC_id, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].physCellId, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].p_gNB, configuration->nr_band[CC_id], + ssb_pattern, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq, configuration->N_RB_DL[CC_id], (NR_BCCH_BCH_Message_t *)&RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].mib, From 9cbfe2e3fac81469fcf90d5b6bcc888665ed46c8 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Sun, 17 Feb 2019 17:43:33 +0100 Subject: [PATCH 009/117] More warning removals --- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 41 ++++++++++--------- .../SCHED_NR_UE/pucch_power_control_ue_nr.c | 2 +- openair1/SCHED_NR_UE/pucch_uci_ue_nr.c | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 5 ++- openair2/GNB_APP/gnb_config.c | 2 +- openair2/LAYER2/NR_MAC_UE/mac.h | 10 ++--- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 5 ++- openair2/RRC/NR/L2_nr_interface.c | 1 - openair2/RRC/NR/rrc_gNB.c | 9 ++-- 10 files changed, 40 insertions(+), 39 deletions(-) diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index a4d627823f..5ff6c0d559 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2961,8 +2961,8 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * //uint8_t pbch_phase; int ret = 0; uint16_t frame_tx; - static uint8_t first_run = 1; - uint8_t pbch_trials = 0; + //static uint8_t first_run = 1; + //uint8_t pbch_trials = 0; DevAssert(ue); @@ -3054,9 +3054,10 @@ unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb #ifdef NR_PDCCH_SCHED -int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc) +int nr_ue_pdcch_procedures(uint8_t eNB_id, + PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc) { - // unsigned int dci_cnt=0, i; //removed for nr_ue_pdcch_procedures and added in the loop for nb_coreset_active #ifdef NR_PDCCH_SCHED_DEBUG printf("<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Entering function nr_ue_pdcch_procedures() \n"); @@ -3100,10 +3101,10 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * #endif // p in TS 38.212 Subclause 10.1, for each active BWP the UE can deal with 3 different CORESETs (including coresetId 0 for common search space) - int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; + //int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; unsigned int dci_cnt=0; // this table contains 56 (NBR_NR_DCI_FIELDS) elements for each dci field and format described in TS 38.212. Each element represents the size in bits for each dci field - uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; + //uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; // this is the UL bandwidth part. FIXME! To be defined where this value comes from // uint16_t n_RB_ULBWP = 106; // this is the DL bandwidth part. FIXME! To be defined where this value comes from @@ -3130,7 +3131,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * * To be implemented LATER !!! */ //int _offset,_index,_M; - int searchSpace_id = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceId; + //int searchSpace_id = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceId; #ifdef NR_PDCCH_SCHED_DEBUG @@ -3143,16 +3144,16 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * // the searchSpace indicates that we need to monitor PDCCH in current nr_tti_rx // get the parameters describing the current SEARCHSPACE // the CORESET id applicable to the current SearchSpace - int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; + //int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; // FIXME this variable is a bit string (14 bits) identifying every OFDM symbol in a slot. // at the moment we will not take into consideration this variable and we will consider that the OFDM symbol offset is always the first OFDM in a symbol uint16_t symbol_within_slot_mon = pdcch_vars2->searchSpace[nb_searchspace_active].monitoringSymbolWithinSlot; // get the remaining parameters describing the current SEARCHSPACE: // FIXME! To be defined where we get this information from - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L2 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel2; - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L4 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel4; - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L8 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel8; - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16; + //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; + //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L2 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel2; + //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L4 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel4; + //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L8 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel8; + //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16; // FIXME! A table of five enum elements // searchSpaceType indicates whether this is a common search space or a UE-specific search space //int searchSpaceType = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceType.type; @@ -3899,7 +3900,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; int ret=0, ret1=0; - int CC_id = ue->CC_id; + //int CC_id = ue->CC_id; NR_UE_PDSCH *pdsch_vars; uint8_t is_cw0_active = 0; uint8_t is_cw1_active = 0; @@ -4957,11 +4958,11 @@ int phy_procedures_slot_parallelization_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_pr #endif -int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, - uint8_t do_pdcch_flag,runmode_t mode) { - - - +int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, + uint8_t do_pdcch_flag, + runmode_t mode) +{ int l,l2; int pilot1; @@ -5201,7 +5202,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN } // for l=1..l2 // do first symbol of next downlink nr_tti_rx for channel estimation - int next_nr_tti_rx = (1+nr_tti_rx)%10; + //int next_nr_tti_rx = (1+nr_tti_rx)%10; /* if (nr_subframe_select(&ue->frame_parms,next_nr_tti_rx) != SF_UL)*/ { /*nr_slot_fep(ue, diff --git a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c index 3a910cfd1e..4541c7fdc6 100644 --- a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c @@ -148,7 +148,7 @@ int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_pro } } - int l = 0; + //int l = 0; int k2; if (power_config->twoPUCCH_PC_AdjustmentStates > 1) { diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c index 27295f15d3..5c80040e2b 100644 --- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c @@ -36,7 +36,7 @@ #include "PHY/NR_REFSIG/ss_pbch_nr.h" #include "PHY/defs_nr_UE.h" -#include "PHY/NR_UE_TRANSPORT/pucch_nr.h" +//#include "PHY/NR_UE_TRANSPORT/pucch_nr.h" #ifndef NO_RAT_NR diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 4b7102ae7f..8582c70e13 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -56,7 +56,8 @@ #include "NR_UE_PHY_INTERFACE/NR_IF_Module.h" #include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "LAYER2/NR_MAC_gNB/mac_proto.h" +//#include "LAYER2/NR_MAC_gNB/mac_proto.h" +//#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" #include "RRC/NR/MESSAGES/asn1_msg.h" @@ -107,7 +108,7 @@ int rrc_init_nr_global_param(void){return(0);} // needed for some functions PHY_VARS_NR_UE ***PHY_vars_UE_g; -uint16_t conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; +short conjugate[8]__attribute__((aligned(16))) = {-1,1,-1,1,-1,1,-1,1}; int main(int argc, char **argv) { diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index 4484cc18a8..82f92b0a4c 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -629,7 +629,7 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) { paramdef_t GNBParams[] = GNBPARAMS_DESC; paramlist_def_t GNBParamList = {GNB_CONFIG_STRING_GNB_LIST,NULL,0}; ////////// Physical parameters - checkedparam_t config_check_CCparams[] = NRCCPARAMS_CHECK; + //checkedparam_t config_check_CCparams[] = NRCCPARAMS_CHECK; paramdef_t CCsParams[] = NRCCPARAMS_DESC; paramlist_def_t CCsParamList = {GNB_CONFIG_STRING_COMPONENT_CARRIERS,NULL,0}; diff --git a/openair2/LAYER2/NR_MAC_UE/mac.h b/openair2/LAYER2/NR_MAC_UE/mac.h index 65a00c9cea..b108bb2f1a 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac.h +++ b/openair2/LAYER2/NR_MAC_UE/mac.h @@ -65,7 +65,7 @@ typedef struct { } __attribute__ ((__packed__)) NR_MAC_SUBHEADER_LONG; typedef struct { - uint8_t LCID:5; // octet 1 [5:0] + uint8_t LCID:6; // octet 1 [5:0] uint8_t R:2; // octet 1 [7:6] } __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED; @@ -82,10 +82,10 @@ typedef struct { #define DL_SCH_LCID_TCI_STATE_IND_UE_SPEC_PDCCH 0x34 #define DL_SCH_LCID_TCI_STATE_ACT_UE_SPEC_PDSCH 0x35 #define DL_SCH_LCID_APERIODIC_CSI_TRI_STATE_SUBSEL 0x36 -#define DL_SCH_LCID_SP_CSI_RS_CSI_IM_RES_SET_ACT 0X37 -#define DL_SCH_LCID_DUPLICATION_ACT 0X38 -#define DL_SCH_LCID_SCell_ACT_4_OCT 0X39 -#define DL_SCH_LCID_SCell_ACT_1_OCT 0X3A +#define DL_SCH_LCID_SP_CSI_RS_CSI_IM_RES_SET_ACT 0x37 +#define DL_SCH_LCID_DUPLICATION_ACT 0x38 +#define DL_SCH_LCID_SCell_ACT_4_OCT 0x39 +#define DL_SCH_LCID_SCell_ACT_1_OCT 0x3A #define DL_SCH_LCID_L_DRX 0x3B #define DL_SCH_LCID_DRX 0x3C #define DL_SCH_LCID_TA_COMMAND 0x3D diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index ede150a399..39b6303bcd 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -1754,7 +1754,7 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); dci->time_dom_resource_assignment, dlsch_config_pdu_1_0->number_symbols, dlsch_config_pdu_1_0->start_symbol); - printf(">>> (nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%d\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", + printf(">>> (nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%f\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", dlsch_config_pdu_1_0->vrb_to_prb_mapping, dlsch_config_pdu_1_0->mcs, dlsch_config_pdu_1_0->ndi, diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index b0f6cff84e..27d4dc36a9 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -37,6 +37,7 @@ #include "LAYER2/MAC/mac_proto.h" #include "LAYER2/NR_MAC_gNB/mac_proto.h" #include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" +#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h" #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" @@ -385,8 +386,8 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, for (int ii=0; iidlsch[ii][0]; if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - clean_eNb_dlsch(dlsch); + LOG_I(MAC, "clean_gNB_dlsch UE %x \n", rnti); + clean_gNB_dlsch(dlsch); } } diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index 0dca3b80d2..c8cdfd336f 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -58,7 +58,6 @@ int8_t mac_rrc_nr_data_req(const module_id_t Mod_idP, uint8_t sfn_msb = (uint8_t)((frameP>>4)&0x3f); #ifdef DEBUG_RRC - int i; LOG_I(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id); #endif diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 10fc6b6a4e..52ac623b5e 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -144,16 +144,15 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( rrc_gNB_ue_context_t *const ue_context_pP ){ - uint8_t size; - uint8_t buffer[100]; - int CC_id = ue_context_pP->ue_context.primaryCC_id; - OCTET_STRING_t *secondaryCellGroup; + //uint8_t size, buffer[100]; + //int CC_id = ue_context_pP->ue_context.primaryCC_id; + //OCTET_STRING_t *secondaryCellGroup; NR_CellGroupConfig_t *cellGroupconfig; struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_BearerToAddModList; struct NR_MAC_CellGroupConfig *mac_CellGroupConfig; struct NR_PhysicalCellGroupConfig *physicalCellGroupConfig; struct NR_SpCellConfig *spCellConfig; - struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; + //struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; cellGroupconfig = CALLOC(1,sizeof(NR_CellGroupConfig_t)); cellGroupconfig->rlc_BearerToAddModList = CALLOC(1,sizeof(struct NR_CellGroupConfig__rlc_BearerToAddModList)); From 15f07d2bb1e77febefcc0be7e7c669f128d6881b Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 21 Feb 2019 13:33:19 +0100 Subject: [PATCH 010/117] multiple SSB generation in pbchsim --- openair1/PHY/INIT/nr_init.c | 4 +-- openair1/PHY/INIT/phy_init.h | 2 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 53 ++++++++++++++++------------ 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 7f52c80992..84f8888eff 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -387,7 +387,7 @@ void install_schedule_handlers(IF_Module_t *if_inst) /// this function is a temporary addition for NR configuration -void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu,int Nid_cell) +void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu,int Nid_cell,uint64_t position_in_burst) { NR_DL_FRAME_PARMS *fp = &gNB->frame_parms; nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config; @@ -404,7 +404,7 @@ void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu, gNB_config->sch_config.n_ssb_crb.value = (N_RB_DL-20); gNB_config->sch_config.ssb_subcarrier_offset.value = 0; gNB_config->sch_config.physical_cell_id.value=Nid_cell; - + gNB_config->sch_config.ssb_scg_position_in_burst.value=position_in_burst; gNB->mac_enabled = 1; diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h index 2a7dcf88fd..a454fb8e80 100644 --- a/openair1/PHY/INIT/phy_init.h +++ b/openair1/PHY/INIT/phy_init.h @@ -383,7 +383,7 @@ void init_nr_ue_transport(PHY_VARS_NR_UE *ue,int abstraction_flag); void nr_dump_frame_parms(NR_DL_FRAME_PARMS *frame_parms); int phy_init_nr_gNB(PHY_VARS_gNB *gNB, unsigned char is_secondary_gNB, unsigned char abstraction_flag); void nr_phy_config_request(NR_PHY_Config_t *gNB); -void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu,int Nid_cell); +void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu,int Nid_cell,uint64_t position_in_burst); void phy_free_nr_gNB(PHY_VARS_gNB *gNB); int l1_north_init_gNB(void); void init_nr_transport(PHY_VARS_gNB *gNB); diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 214a33fb73..c023a69671 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -105,6 +105,7 @@ int main(int argc, char **argv) int trial,n_trials=1,n_errors=0,n_errors_payload=0; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; + uint64_t SSB_positions=0x01; channel_desc_t *gNB2UE; @@ -280,6 +281,10 @@ int main(int argc, char **argv) break; + case 'M': + SSB_positions = atoi(optarg); + break; + case 'N': Nid_cell = atoi(optarg); break; @@ -333,6 +338,7 @@ int main(int argc, char **argv) printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); printf("-o Carrier frequency offset in Hz\n"); + printf("-M Multiple SSB positions in burst\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); @@ -366,32 +372,34 @@ int main(int argc, char **argv) frame_parms->N_RB_UL = N_RB_DL; frame_parms->Nid_cell = Nid_cell; - nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu,Nid_cell); + nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu,Nid_cell,SSB_positions); phy_init_nr_gNB(gNB,0,0); double fs,bw,scs,eps; - - if (mu == 1 && N_RB_DL == 217) { - fs = 122.88e6; - bw = 80e6; - scs = 30000; - } - else if (mu == 1 && N_RB_DL == 245) { - fs = 122.88e6; - bw = 90e6; - scs = 30000; + + switch (mu) { + case 1: + scs = 30000; + if (N_RB_DL == 217) { + fs = 122.88e6; + bw = 80e6; + + } + else if (N_RB_DL == 245) { + fs = 122.88e6; + bw = 90e6; + } + else if (N_RB_DL == 273) { + fs = 122.88e6; + bw = 100e6; + } + else if (N_RB_DL == 106) { + fs = 61.44e6; + bw = 40e6; + } + else AssertFatal(1==0,"Unsupported numerology for mu %d, N_RB %d\n",mu, N_RB_DL); + break; } - else if (mu == 1 && N_RB_DL == 273) { - fs = 122.88e6; - bw = 100e6; - scs = 30000; - } - else if (mu == 1 && N_RB_DL == 106) { - fs = 61.44e6; - bw = 40e6; - scs = 30000; - } - else AssertFatal(1==0,"Unsupported numerology for mu %d, N_RB %d\n",mu, N_RB_DL); // cfo with respect to sub-carrier spacing eps = cfo/scs; @@ -476,6 +484,7 @@ int main(int argc, char **argv) if (input_fd==NULL) { gNB->pbch_configured = 1; for (int i=0;i<4;i++) gNB->pbch_pdu[i]=i+1; + nr_common_signal_procedures (gNB,frame,subframe); LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); From a5025d4c4fbb930b923c322361e6e1897b15a638 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 21 Feb 2019 15:30:09 +0100 Subject: [PATCH 011/117] SSB positions in burst from config file --- openair2/COMMON/rrc_messages_types.h | 2 +- openair2/GNB_APP/gnb_config.c | 33 ++++++++++--------- openair2/GNB_APP/gnb_paramdef.h | 2 +- openair2/LAYER2/NR_MAC_gNB/config.c | 2 -- openair2/RRC/NR/MESSAGES/asn1_msg.c | 17 +++++++--- openair2/RRC/NR/rrc_gNB.c | 6 ++-- .../CONF/gnb.band78.tm1.106PRB.usrpx300.conf | 2 +- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h index 922c949307..1c12f41150 100644 --- a/openair2/COMMON/rrc_messages_types.h +++ b/openair2/COMMON/rrc_messages_types.h @@ -361,7 +361,7 @@ typedef struct NRRrcConfigurationReq_s { lte_prefix_type_t UL_BWP_prefix_type[MAX_NUM_CCs]; long UL_timeAlignmentTimerCommon[MAX_NUM_CCs]; long ServingCellConfigCommon_n_TimingAdvanceOffset[MAX_NUM_CCs]; - long ServingCellConfigCommon_ssb_PositionsInBurst_PR[MAX_NUM_CCs]; + uint64_t ServingCellConfigCommon_ssb_PositionsInBurst_PR[MAX_NUM_CCs]; long ServingCellConfigCommon_ssb_periodicityServingCell[MAX_NUM_CCs]; //ServingCellConfigCommon long ServingCellConfigCommon_dmrs_TypeA_Position[MAX_NUM_CCs]; //ServingCellConfigCommon long NIA_SubcarrierSpacing[MAX_NUM_CCs]; //ServingCellConfigCommon Used only for non-initial access diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index 4484cc18a8..99b6286483 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -103,7 +103,6 @@ void RCconfig_nr_flexran() *UL_frequencyShift7p5khz, *UL_SCS_SubcarrierSpacing, *UL_BWP_SubcarrierSpacing, *UL_BWP_prefix_type, *UL_timeAlignmentTimerCommon, *ServingCellConfigCommon_n_TimingAdvanceOffset, - *ServingCellConfigCommon_ssb_PositionsInBurst_PR, *NIA_SubcarrierSpacing, *referenceSubcarrierSpacing, *dl_UL_TransmissionPeriodicity, *rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_choice, *rach_groupBconfigured, *rach_messagePowerOffsetGroupB, @@ -118,7 +117,7 @@ void RCconfig_nr_flexran() *SearchSpace_searchSpaceType, *ue_Specific__dci_Formats, *RateMatchPatternLTE_CRS_subframeAllocation_choice; - uint64_t downlink_frequency; + uint64_t downlink_frequency, ServingCellConfigCommon_ssb_PositionsInBurst_PR; int32_t nr_band, uplink_frequency_offset, N_RB_DL, nb_antenna_ports, MIB_subCarrierSpacingCommon, MIB_ssb_SubcarrierOffset, MIB_dmrs_TypeA_Position, @@ -484,7 +483,7 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) { char* UL_timeAlignmentTimerCommon = 0; char* ServingCellConfigCommon_n_TimingAdvanceOffset = 0; - char* ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0; + uint64_t ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0; int32_t ServingCellConfigCommon_ssb_periodicityServingCell = 0; int32_t ServingCellConfigCommon_dmrs_TypeA_Position = 0; char* NIA_SubcarrierSpacing = 0; @@ -1125,19 +1124,23 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) { RC.config_file_name, i, ServingCellConfigCommon_n_TimingAdvanceOffset); } - if (strcmp(ServingCellConfigCommon_ssb_PositionsInBurst_PR,"shortBitmap")==0) { - NRRRC_CONFIGURATION_REQ (msg_p).ServingCellConfigCommon_ssb_PositionsInBurst_PR[j] = NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_shortBitmap; - }else if (strcmp(ServingCellConfigCommon_ssb_PositionsInBurst_PR,"mediumBitmap")==0) { - NRRRC_CONFIGURATION_REQ (msg_p).ServingCellConfigCommon_ssb_PositionsInBurst_PR[j] = NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap; - }else if (strcmp(ServingCellConfigCommon_ssb_PositionsInBurst_PR,"longBitmap")==0) { - NRRRC_CONFIGURATION_REQ (msg_p).ServingCellConfigCommon_ssb_PositionsInBurst_PR[j] = NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_longBitmap; - }else if (strcmp(ServingCellConfigCommon_ssb_PositionsInBurst_PR,"NOTHING")==0) { - NRRRC_CONFIGURATION_REQ (msg_p).ServingCellConfigCommon_ssb_PositionsInBurst_PR[j] = NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_NOTHING; - }else { - AssertFatal (0,"Failed to parse gNB configuration file %s, gnb %d unknown value \"%s\" for ServingCellConfigCommon_ssb_PositionsInBurst_PR choice !\n", - RC.config_file_name, i, ServingCellConfigCommon_ssb_PositionsInBurst_PR); - } + uint64_t t_freq; + if(nr_band == 41 || (nr_band > 76 && nr_band < 80)) + t_freq = 2400000000; + else + t_freq = 3000000000; + + if (downlink_frequency 15)) + AssertFatal (0,"Failed to parse gNB configuration file %s, gnb %d unvalid value \"%ld\" for ssb_PositionsInBurst at DL frequency %ld !\n", + RC.config_file_name, i, ServingCellConfigCommon_ssb_PositionsInBurst_PR, downlink_frequency); + else { + if(downlink_frequency<6000000000 && (ServingCellConfigCommon_ssb_PositionsInBurst_PR > 255)) + AssertFatal (0,"Failed to parse gNB configuration file %s, gnb %d unvalid value \"%ld\" for ssb_PositionsInBurst at DL frequency %ld !\n", + RC.config_file_name, i, ServingCellConfigCommon_ssb_PositionsInBurst_PR, downlink_frequency); + else + NRRRC_CONFIGURATION_REQ (msg_p).ServingCellConfigCommon_ssb_PositionsInBurst_PR[j] = ServingCellConfigCommon_ssb_PositionsInBurst_PR; + } switch (ServingCellConfigCommon_ssb_periodicityServingCell) { case 5: diff --git a/openair2/GNB_APP/gnb_paramdef.h b/openair2/GNB_APP/gnb_paramdef.h index 15a2e97239..6ac5bfc42d 100644 --- a/openair2/GNB_APP/gnb_paramdef.h +++ b/openair2/GNB_APP/gnb_paramdef.h @@ -640,7 +640,7 @@ typedef enum { {GNB_CONFIG_STRING_UL_BWP_PREFIX_TYPE, NULL, 0, strptr:&UL_BWP_prefix_type, defstrval:"NORMAL", TYPE_STRING, 0}, \ {GNB_CONFIG_STRING_UL_TIMEALIGNMENTTIMERCOMMON, NULL, 0, strptr:&UL_timeAlignmentTimerCommon, defstrval:"infinity", TYPE_STRING, 0}, \ {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON_N_TIMINGADVANCEOFFSET, NULL, 0, strptr:&ServingCellConfigCommon_n_TimingAdvanceOffset, defstrval:"n0", TYPE_STRING, 0}, \ -{GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON_SSB_POSITIONSINBURST_PR, NULL, 0, strptr:&ServingCellConfigCommon_ssb_PositionsInBurst_PR, defstrval:"shortBitmap", TYPE_STRING, 0}, \ +{GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON_SSB_POSITIONSINBURST_PR, NULL, 0, i64ptr:(int64_t *)&ServingCellConfigCommon_ssb_PositionsInBurst_PR, defint64val:0, TYPE_UINT64, 0}, \ {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON_SSB_PERIODICITYSERVINGCELL, NULL, 0, iptr:&ServingCellConfigCommon_ssb_periodicityServingCell, defintval:10, TYPE_UINT, 0}, \ {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON_DMRS_TYPEA_POSITION, NULL, 0, iptr:&ServingCellConfigCommon_dmrs_TypeA_Position, defintval:0, TYPE_UINT, 0}, \ {GNB_CONFIG_STRING_NIA_SUBCARRIERSPACING, NULL, 0, strptr:&NIA_SubcarrierSpacing, defstrval:"kHz15", TYPE_STRING, 0}, \ diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index b2ea58d362..12d01981d2 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -266,8 +266,6 @@ int rrc_mac_config_req_gNB(module_id_t Mod_idP, }// END if( mib != NULL ) - - if( servingcellconfigcommon != NULL ){ config_common(Mod_idP, CC_idP, diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index df45ae5e05..1b3e367ec7 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -747,15 +747,21 @@ void do_SERVINGCELLCONFIGCOMMON(uint8_t Mod_id, //ssb_PositionsInBurst (*servingcellconfigcommon)->ssb_PositionsInBurst->present = configuration->ServingCellConfigCommon_ssb_PositionsInBurst_PR[CC_id]; - if((*servingcellconfigcommon)->ssb_PositionsInBurst->present == NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_shortBitmap){ + uint64_t t_freq; + if(configuration->nr_band[CC_id] == 41 || (configuration->nr_band[CC_id] > 76 && configuration->nr_band[CC_id] < 80)) + t_freq = 2400000000; + else + t_freq = 3000000000; + + if(configuration->downlink_frequency[CC_id]ssb_PositionsInBurst->choice.shortBitmap.size = 1; (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.shortBitmap.bits_unused = 4; - (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.shortBitmap.buf[0] = 0x0f; - }else if((*servingcellconfigcommon)->ssb_PositionsInBurst->present == NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap){ + (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.shortBitmap.buf[0] = configuration->ServingCellConfigCommon_ssb_PositionsInBurst_PR[CC_id]; + }else if(configuration->downlink_frequency[CC_id]<6000000000){ (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.mediumBitmap.size = 1; (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.mediumBitmap.bits_unused = 0; - (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.mediumBitmap.buf[0] = 0xff; - }else if((*servingcellconfigcommon)->ssb_PositionsInBurst->present == NR_ServingCellConfigCommon__ssb_PositionsInBurst_PR_longBitmap){ + (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.mediumBitmap.buf[0] = configuration->ServingCellConfigCommon_ssb_PositionsInBurst_PR[CC_id]; + }else { (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.longBitmap.size = 8; (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.longBitmap.bits_unused = 0; (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.longBitmap.buf[0] = 0xff; @@ -768,6 +774,7 @@ void do_SERVINGCELLCONFIGCOMMON(uint8_t Mod_id, (*servingcellconfigcommon)->ssb_PositionsInBurst->choice.longBitmap.buf[7] = 0xff; } + //ssb_periodicityServingCell *(*servingcellconfigcommon)->ssb_periodicityServingCell = configuration->ServingCellConfigCommon_ssb_periodicityServingCell[CC_id]; //dmrs_TypeA_Position diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index daf368f50d..de9d8fb60d 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -261,13 +261,13 @@ static void init_NR_SI(const protocol_ctxt_t* const ctxt_pP, LOG_I(NR_RRC,"Done init_NR_SI\n"); - uint64_t ssb_pattern = 255; + rrc_mac_config_req_gNB(ctxt_pP->module_id, CC_id, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].physCellId, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].p_gNB, configuration->nr_band[CC_id], - ssb_pattern, + configuration->ServingCellConfigCommon_ssb_PositionsInBurst_PR[CC_id], RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq, configuration->N_RB_DL[CC_id], (NR_BCCH_BCH_Message_t *)&RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].mib, @@ -332,7 +332,7 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu gnb_mod_idP, RC.nrrrc[ctxt.module_id]->carrier[CC_id].cba_rnti[0], RC.nrrrc[ctxt.module_id]->carrier[CC_id].cba_rnti[1], RC.nrrrc[ctxt.module_id]->carrier[CC_id].cba_rnti[2], - RC.nrrrc[ctxt.module_id]->carrier[CC_id].cba_rnti[3], + RC.nrrrc[ctxt.module_id]->caNRRRC_CONFIGURATION_REQrrier[CC_id].cba_rnti[3], RC.nrrrc[ctxt.module_id]->carrier[CC_id].num_active_cba_groups); } diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf index f170d7ce87..385064b667 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpx300.conf @@ -70,7 +70,7 @@ gNBs = UL_BWP_prefix_type = "NORMAL"; UL_timeAlignmentTimerCommon = "infinity"; ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" - ServingCellConfigCommon_ssb_PositionsInBurst_PR = "shortBitmap"; + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0xff; ServingCellConfigCommon_ssb_periodicityServingCell = 10; ServingCellConfigCommon_dmrs_TypeA_Position = 2; NIA_SubcarrierSpacing = "kHz15"; From 5a9fb475f2361ff0d3f8c181728deb1c2f07beae Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 21 Feb 2019 17:29:15 +0100 Subject: [PATCH 012/117] Lmax in frame_parms and nr_band number from freq at UE --- openair1/PHY/INIT/nr_parms.c | 10 +++ openair1/PHY/NR_REFSIG/nr_gold.c | 2 +- openair1/PHY/NR_REFSIG/nr_gold_ue.c | 3 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 2 +- openair1/PHY/defs_nr_common.h | 2 + openair1/SCHED_NR/phy_procedures_nr_gNB.c | 5 +- targets/RT/USER/nr-ue.c | 75 +++++++++++++---------- targets/RT/USER/nr-uesoftmodem.c | 2 +- 8 files changed, 59 insertions(+), 42 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index a5eb2e659b..14d95ad488 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -179,6 +179,16 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, fp->samples_per_frame = 10 * fp->samples_per_subframe; fp->freq_range = (fp->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2; + // definition of Lmax according to ts 38.213 section 4.1 + if (fp->dl_CarrierFreq < 6e9){ + if(fp->frame_type && (fp->ssb_type==2)) + fp->Lmax = (fp->dl_CarrierFreq < 2.4e9)? 4 : 8; + else + fp->Lmax = (fp->dl_CarrierFreq < 3e9)? 4 : 8; + } + else + fp->Lmax = 64; + // Initial bandwidth part configuration -- full carrier bandwidth fp->initial_bwp_dl.bwp_id = 0; fp->initial_bwp_dl.scs = fp->subcarrier_spacing; diff --git a/openair1/PHY/NR_REFSIG/nr_gold.c b/openair1/PHY/NR_REFSIG/nr_gold.c index 08e6022764..bd60933155 100644 --- a/openair1/PHY/NR_REFSIG/nr_gold.c +++ b/openair1/PHY/NR_REFSIG/nr_gold.c @@ -32,7 +32,7 @@ void nr_init_pbch_dmrs(PHY_VARS_gNB* gNB) Nid = cfg->sch_config.physical_cell_id.value; - Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; + Lmax = fp->Lmax; N_hf = (Lmax == 4)? 2:1; for (n_hf = 0; n_hf < N_hf; n_hf++) { diff --git a/openair1/PHY/NR_REFSIG/nr_gold_ue.c b/openair1/PHY/NR_REFSIG/nr_gold_ue.c index 78b92959e1..726aab8a37 100644 --- a/openair1/PHY/NR_REFSIG/nr_gold_ue.c +++ b/openair1/PHY/NR_REFSIG/nr_gold_ue.c @@ -29,8 +29,7 @@ void nr_gold_pbch(PHY_VARS_NR_UE* ue) unsigned char Lmax, l, n_hf, N_hf; Nid = ue->frame_parms.Nid_cell; - - Lmax = 8; //(fp->dl_CarrierFreq < 3e9)? 4:8; + Lmax = ue->frame_parms.Lmax; N_hf = (Lmax == 4)? 2:1; for (n_hf = 0; n_hf < N_hf; n_hf++) { diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a0b150eda1..dc8fb09e2a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -531,7 +531,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; uint8_t nushift; uint16_t M; - uint8_t Lmax=8; //to update + uint8_t Lmax=frame_parms->Lmax; uint8_t ssb_index=0; //uint16_t crc; //unsigned short idx_demod =0; diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 4267b79144..267c156184 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -308,6 +308,8 @@ typedef struct NR_DL_FRAME_PARMS { uint16_t ssb_start_subcarrier; /// SSB type nr_ssb_type_e ssb_type; + /// Max number of SSB in frame + uint8_t Lmax; /// SS block pattern (max 64 ssb, each bit is on/off ssb) uint64_t L_ssb; /// PBCH polar encoder params diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index bfa785095b..e64d2d8635 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -141,14 +141,13 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { nfapi_nr_config_request_t *cfg = &gNB->gNB_config; int **txdataF = gNB->common_vars.txdataF; uint8_t *pbch_pdu=&gNB->pbch_pdu[0]; - uint8_t Lmax, ssb_index, n_hf; + uint8_t ssb_index, n_hf; int ssb_start_symbol, rel_slot; n_hf = cfg->sch_config.half_frame_index.value; // to set a effective slot number between 0 to 9 in the half frame where the SSB is supposed to be rel_slot = (n_hf)? (slot-10) : slot; - Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8; // max number of ssb LOG_D(PHY,"common_signal_procedures: frame %d, slot %d\n",frame,slot); @@ -177,7 +176,7 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { txdataF[0], AMP, ssb_start_symbol, - n_hf,Lmax,ssb_index, + n_hf,fp->Lmax,ssb_index, frame, cfg, fp); } } diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c index 3f0545c4cf..5cd4db26d2 100644 --- a/targets/RT/USER/nr-ue.c +++ b/targets/RT/USER/nr-ue.c @@ -175,35 +175,38 @@ typedef struct band_info_s { band_info_t bands_to_scan; static const eutra_band_t eutra_bands[] = { - { 1, 1920 * MHz, 1980 * MHz, 2110 * MHz, 2170 * MHz, FDD}, - { 2, 1850 * MHz, 1910 * MHz, 1930 * MHz, 1990 * MHz, FDD}, - { 3, 1710 * MHz, 1785 * MHz, 1805 * MHz, 1880 * MHz, FDD}, - { 4, 1710 * MHz, 1755 * MHz, 2110 * MHz, 2155 * MHz, FDD}, - { 5, 824 * MHz, 849 * MHz, 869 * MHz, 894 * MHz, FDD}, - { 6, 830 * MHz, 840 * MHz, 875 * MHz, 885 * MHz, FDD}, - { 7, 2500 * MHz, 2570 * MHz, 2620 * MHz, 2690 * MHz, FDD}, - { 8, 880 * MHz, 915 * MHz, 925 * MHz, 960 * MHz, FDD}, - { 9, 1749900 * KHz, 1784900 * KHz, 1844900 * KHz, 1879900 * KHz, FDD}, - {10, 1710 * MHz, 1770 * MHz, 2110 * MHz, 2170 * MHz, FDD}, - {11, 1427900 * KHz, 1452900 * KHz, 1475900 * KHz, 1500900 * KHz, FDD}, - {12, 698 * MHz, 716 * MHz, 728 * MHz, 746 * MHz, FDD}, - {13, 777 * MHz, 787 * MHz, 746 * MHz, 756 * MHz, FDD}, - {14, 788 * MHz, 798 * MHz, 758 * MHz, 768 * MHz, FDD}, - {17, 704 * MHz, 716 * MHz, 734 * MHz, 746 * MHz, FDD}, - {20, 832 * MHz, 862 * MHz, 791 * MHz, 821 * MHz, FDD}, - {22, 3510 * MHz, 3590 * MHz, 3410 * MHz, 3490 * MHz, FDD}, - {33, 1900 * MHz, 1920 * MHz, 1900 * MHz, 1920 * MHz, TDD}, - {34, 2010 * MHz, 2025 * MHz, 2010 * MHz, 2025 * MHz, TDD}, - {35, 1850 * MHz, 1910 * MHz, 1850 * MHz, 1910 * MHz, TDD}, - {36, 1930 * MHz, 1990 * MHz, 1930 * MHz, 1990 * MHz, TDD}, - {37, 1910 * MHz, 1930 * MHz, 1910 * MHz, 1930 * MHz, TDD}, - {38, 2570 * MHz, 2620 * MHz, 2570 * MHz, 2630 * MHz, TDD}, - {39, 1880 * MHz, 1920 * MHz, 1880 * MHz, 1920 * MHz, TDD}, - {40, 2300 * MHz, 2400 * MHz, 2300 * MHz, 2400 * MHz, TDD}, - {41, 2496 * MHz, 2690 * MHz, 2496 * MHz, 2690 * MHz, TDD}, - {42, 3400 * MHz, 3600 * MHz, 3400 * MHz, 3600 * MHz, TDD}, - {43, 3600 * MHz, 3800 * MHz, 3600 * MHz, 3800 * MHz, TDD}, - {44, 703 * MHz, 803 * MHz, 703 * MHz, 803 * MHz, TDD}, + {1, 1920000, 1980000, 2110000, 2170000, FDD}, + {2, 1850000, 1910000, 1930000, 1990000, FDD}, + {3, 1710000, 1785000, 1805000, 1880000, FDD}, + {5, 824000, 849000, 869000, 894000, FDD}, + {7, 2500000, 2570000, 2620000, 2690000, FDD}, + {8, 880000, 915000, 925000, 960000, FDD}, + {12, 698000, 716000, 728000, 746000, FDD}, + {20, 832000, 862000, 791000, 821000, FDD}, + {25, 1850000, 1915000, 1930000, 1995000, FDD}, + {28, 703000, 758000, 758000, 813000, FDD}, + {34, 2010000, 2025000, 2010000, 2025000, TDD}, + {38, 2570000, 2620000, 2570000, 2630000, TDD}, + {39, 1880000, 1920000, 1880000, 1920000, TDD}, + {40, 2300000, 2400000, 2300000, 2400000, TDD}, + {41, 2496000, 2690000, 2496000, 2690000, TDD}, + {50, 1432000, 1517000, 1432000, 1517000, TDD}, + {51, 1427000, 1432000, 1427000, 1432000, TDD}, + {66, 1710000, 1780000, 2110000, 2200000, FDD}, + {70, 1695000, 1710000, 1995000, 2020000, FDD}, + {71, 663000, 698000, 617000, 652000, FDD}, + {74, 1427000, 1470000, 1475000, 1518000, FDD}, + {75, 000, 000, 1432000, 1517000, FDD}, + {76, 000, 000, 1427000, 1432000, FDD}, + {77, 3300000, 4200000, 3300000, 4200000, TDD}, + {78, 3300000, 3800000, 3300000, 3800000, TDD}, + {79, 4400000, 5000000, 4400000, 5000000, TDD}, + {80, 1710000, 1785000, 000, 000, FDD}, + {81, 860000, 915000, 000, 000, FDD}, + {82, 832000, 862000, 000, 000, FDD}, + {83, 703000, 748000, 000, 000, FDD}, + {84, 1920000, 1980000, 000, 000, FDD}, + {86, 1710000, 1785000, 000, 000, FDD} }; PHY_VARS_NR_UE* init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, @@ -333,6 +336,7 @@ static void *UE_thread_synch(void *arg) { int i, hw_slot_offset; PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE*) arg; int current_band = 0; + lte_frame_type_t current_type; int current_offset = 0; sync_mode_t sync_mode = pbch; int CC_id = UE->CC_id; @@ -351,19 +355,22 @@ static void *UE_thread_synch(void *arg) { if (UE->UE_scan == 0) { int ind; - for ( ind=0; - ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); - ind++) { + int64_t dl_freq_khz = downlink_frequency[0][0]/1000; + for ( ind=0; ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); ind++) { current_band = eutra_bands[ind].band; + current_type = eutra_bands[ind].frame_type; LOG_D(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", current_band, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); - if ( eutra_bands[ind].dl_min <= downlink_frequency[0][0] && eutra_bands[ind].dl_max >= downlink_frequency[0][0] ) { + if ( eutra_bands[ind].dl_min <= dl_freq_khz && eutra_bands[ind].dl_max >= dl_freq_khz ) { for (i=0; i<4; i++) - uplink_frequency_offset[CC_id][i] = eutra_bands[ind].ul_min - eutra_bands[ind].dl_min; + uplink_frequency_offset[CC_id][i] = (eutra_bands[ind].ul_min - eutra_bands[ind].dl_min) *1000; break; } } AssertFatal( ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]), "Can't find EUTRA band for frequency"); + UE->frame_parms.eutra_band = current_band; + UE->frame_parms.frame_type = current_type; + LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], oai_exit, openair0_cfg[0].rx_num_channels); diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c index d3d660e7f5..0321906b77 100644 --- a/targets/RT/USER/nr-uesoftmodem.c +++ b/targets/RT/USER/nr-uesoftmodem.c @@ -661,7 +661,7 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; config[CC_id]->sch_config.physical_cell_id.value = 0; - + frame_parms[CC_id]->eutra_band = 78; frame_parms[CC_id]->frame_type = FDD; frame_parms[CC_id]->tdd_config = 3; //frame_parms[CC_id]->tdd_config_S = 0; From 2156ba10d595a5cd935a4fce1ba9f51edcda2021 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Mon, 25 Feb 2019 16:51:41 +0100 Subject: [PATCH 013/117] config files changed and pdcch/pdsch enabled --- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 4 ++-- .../CONF/gnb.band22.tm1.106PRB.adrv9371zc706.conf | 6 +++--- .../CONF/gnb.band78.tm1.106PRB.usrpn300.conf | 6 +++--- .../CONF/gnb.band78.tm1.217PRB.usrpn300.conf | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index f1db75d534..d922a3143d 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -213,7 +213,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, num_dci = gNB->pdcch_vars.num_dci; num_pdsch_rnti = gNB->pdcch_vars.num_pdsch_rnti; - /*if (num_dci) { + if (num_dci) { LOG_I(PHY, "[gNB %d] Frame %d slot %d \ Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, slot, num_dci); @@ -232,7 +232,7 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, AMP, slot, *fp, *cfg); } } - }*/ + } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0); } diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band22.tm1.106PRB.adrv9371zc706.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band22.tm1.106PRB.adrv9371zc706.conf index 258d6c5f03..5fd4b465b3 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band22.tm1.106PRB.adrv9371zc706.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band22.tm1.106PRB.adrv9371zc706.conf @@ -26,10 +26,10 @@ gNBs = node_function = "3GPP_gNODEB"; node_timing = "synch_to_ext_device"; node_synch_ref = 0; - frame_type = "FDD"; + frame_type = "TDD"; DL_prefix_type = "NORMAL"; UL_prefix_type = "NORMAL"; - eutra_band = 22; + eutra_band = 78; downlink_frequency = 3510000000L; uplink_frequency_offset = -120000000; Nid_cell = 0; @@ -70,7 +70,7 @@ gNBs = UL_BWP_prefix_type = "NORMAL"; UL_timeAlignmentTimerCommon = "infinity"; ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" - ServingCellConfigCommon_ssb_PositionsInBurst_PR = "shortBitmap"; + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0x01; ServingCellConfigCommon_ssb_periodicityServingCell = 10; ServingCellConfigCommon_dmrs_TypeA_Position = 2; NIA_SubcarrierSpacing = "kHz15"; diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf index 3aaf0c5506..077d1e5bd3 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf @@ -26,10 +26,10 @@ gNBs = node_function = "3GPP_gNODEB"; node_timing = "synch_to_ext_device"; node_synch_ref = 0; - frame_type = "FDD"; + frame_type = "TDD"; DL_prefix_type = "NORMAL"; UL_prefix_type = "NORMAL"; - eutra_band = 22; + eutra_band = 78; downlink_frequency = 3510000000L; uplink_frequency_offset = -120000000; Nid_cell = 0; @@ -70,7 +70,7 @@ gNBs = UL_BWP_prefix_type = "NORMAL"; UL_timeAlignmentTimerCommon = "infinity"; ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" - ServingCellConfigCommon_ssb_PositionsInBurst_PR = "shortBitmap"; + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0x01; ServingCellConfigCommon_ssb_periodicityServingCell = 10; ServingCellConfigCommon_dmrs_TypeA_Position = 2; NIA_SubcarrierSpacing = "kHz15"; diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpn300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpn300.conf index a604feabec..dbd937d61a 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpn300.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpn300.conf @@ -26,10 +26,10 @@ gNBs = node_function = "3GPP_gNODEB"; node_timing = "synch_to_ext_device"; node_synch_ref = 0; - frame_type = "FDD"; + frame_type = "TDD"; DL_prefix_type = "NORMAL"; UL_prefix_type = "NORMAL"; - eutra_band = 22; + eutra_band = 78; downlink_frequency = 3510000000L; uplink_frequency_offset = -120000000; Nid_cell = 0; @@ -70,7 +70,7 @@ gNBs = UL_BWP_prefix_type = "NORMAL"; UL_timeAlignmentTimerCommon = "infinity"; ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" - ServingCellConfigCommon_ssb_PositionsInBurst_PR = "shortBitmap"; + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0x01; ServingCellConfigCommon_ssb_periodicityServingCell = 10; ServingCellConfigCommon_dmrs_TypeA_Position = 2; NIA_SubcarrierSpacing = "kHz15"; From 353f153353863b97fad69d3a0c59494ffac0f448 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 26 Feb 2019 18:06:43 +0100 Subject: [PATCH 014/117] slot_fep for ssb done once before sss and pbch channel estimation moved out of slot_fep --- openair1/PHY/INIT/nr_init.c | 2 +- openair1/PHY/MODULATION/modulation_UE.h | 3 +- openair1/PHY/MODULATION/slot_fep_nr.c | 49 ++--------------- .../nr_dl_channel_estimation.c | 8 +-- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 4 -- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 52 +++++++++---------- openair1/PHY/NR_UE_TRANSPORT/pss_nr.c | 3 +- openair1/PHY/NR_UE_TRANSPORT/sss_nr.c | 18 ------- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 3 -- openair1/SIMULATION/NR_PHY/pbchsim.c | 40 +++++--------- targets/RT/USER/nr-ue.c | 2 +- 11 files changed, 48 insertions(+), 136 deletions(-) diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 568070df93..2f613152dd 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -363,7 +363,7 @@ void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu, NR_DL_FRAME_PARMS *fp = &gNB->frame_parms; nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config; //overwrite for new NR parameters - gNB_config->nfapi_config.rf_bands.rf_band[0] = 78; + gNB_config->nfapi_config.rf_bands.rf_band[0] = 5; gNB_config->nfapi_config.nrarfcn.value = 620000; gNB_config->subframe_config.numerology_index_mu.value = mu; gNB_config->subframe_config.duplex_mode.value = TDD; diff --git a/openair1/PHY/MODULATION/modulation_UE.h b/openair1/PHY/MODULATION/modulation_UE.h index 9734c02907..63c3637886 100644 --- a/openair1/PHY/MODULATION/modulation_UE.h +++ b/openair1/PHY/MODULATION/modulation_UE.h @@ -53,8 +53,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *phy_vars_ue, unsigned char Ns, int sample_offset, int no_prefix, - int reset_freq_est, - NR_CHANNEL_EST_t channel); + NR_CHANNEL_EST_t channel); int slot_fep_mbsfn(PHY_VARS_UE *phy_vars_ue, unsigned char l, diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c index 1e1751fe24..f41212e543 100644 --- a/openair1/PHY/MODULATION/slot_fep_nr.c +++ b/openair1/PHY/MODULATION/slot_fep_nr.c @@ -39,12 +39,10 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, unsigned char Ns, int sample_offset, int no_prefix, - int reset_freq_est, NR_CHANNEL_EST_t channel) { NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; NR_UE_COMMON *common_vars = &ue->common_vars; - uint8_t eNB_id = 0;//ue_common_vars->eNb_id; unsigned char aa; unsigned char symbol = l;//+((7-frame_parms->Ncp)*(Ns&1)); ///symbol within sub-frame unsigned int nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples); @@ -204,56 +202,17 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, switch(channel){ case NR_PBCH_EST: - -#ifdef DEBUG_FEP - printf("Channel estimation eNB %d, slot %d, symbol %d\n",eNB_id,Ns,l); -#endif -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); -#endif - nr_pbch_channel_estimation(ue,eNB_id,0, - Ns, - l, - symbol); - //} -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); -#endif - - // do frequency offset estimation here! - // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1}) -#ifdef DEBUG_FEP - printf("Frequency offset estimation\n"); -#endif - - if (l==(4-frame_parms->Ncp)) { - -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_freq_offset_estimation_stats); -#endif - - /*lte_est_freq_offset(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[0], - frame_parms, - l, - &common_vars->freq_offset, - reset_freq_est);*/ -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_freq_offset_estimation_stats); -#endif - - } - break; case NR_PDCCH_EST: #ifdef DEBUG_FEP - printf("PDCCH Channel estimation eNB %d, aatx %d, slot %d, symbol %d start_sc %d\n",eNB_id,aa,Ns,l,coreset_start_subcarrier); + printf("PDCCH Channel estimation aatx %d, slot %d, symbol %d start_sc %d\n",aa,Ns,l,coreset_start_subcarrier); #endif #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); #endif - nr_pdcch_channel_estimation(ue,eNB_id,0, + nr_pdcch_channel_estimation(ue,0, Ns, l, symbol, @@ -267,7 +226,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, case NR_PDSCH_EST: #ifdef DEBUG_FEP - printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l); + printf("Channel estimation aatx %d, slot %d, symbol %d\n",aa,Ns,l); #endif #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); @@ -276,7 +235,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, ue->frame_parms.nushift = (p>>1)&1;; if (symbol ==l0) - nr_pdsch_channel_estimation(ue,eNB_id,0, + nr_pdsch_channel_estimation(ue,0, Ns, p, l, 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 a90450b0a5..05ee82ae29 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -33,10 +33,8 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol) { int pilot[200] __attribute__((aligned(16))); @@ -78,8 +76,8 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, k = nushift; #ifdef DEBUG_CH - printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, - ue->frame_parms.Ncp,l,Ns,k, symbol); + printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, + ue->frame_parms.Ncp,Ns,k, symbol); #endif switch (k) { @@ -254,7 +252,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, } int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, unsigned char l, @@ -478,7 +475,6 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, } int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, unsigned short p, diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index ae4295a99b..a6ede43504 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -43,7 +43,6 @@ \param symbol symbol within frame */ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, unsigned char l, @@ -52,14 +51,11 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned short nb_rb_coreset); int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol); int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_id, uint8_t eNB_offset, unsigned char Ns, unsigned short p, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index e5f079ebc3..ea4745fe23 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -35,6 +35,7 @@ #include "PHY/INIT/phy_init.h" #include "PHY/MODULATION/modulation_UE.h" #include "nr_transport_proto_ue.h" +#include "PHY/NR_UE_ESTIMATION/nr_estimation.h" //#include "SCHED/defs.h" //#include "SCHED/extern.h" @@ -68,32 +69,18 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples; - //symbol 1 - nr_slot_fep(ue, - 1, - 0, - ue->ssb_offset, - 0, - 1, - NR_PBCH_EST); - - //symbol 2 - nr_slot_fep(ue, - 2, - 0, - ue->ssb_offset, - 0, - 1, - NR_PBCH_EST); - - //symbol 3 - nr_slot_fep(ue, - 3, - 0, - ue->ssb_offset, - 0, - 1, - NR_PBCH_EST); + for(int i=1; i<4;i++) { + +#if UE_TIMING_TRACE + start_meas(&ue->dlsch_channel_estimation_stats); +#endif + nr_pbch_channel_estimation(ue,0, + 0, + i); +#if UE_TIMING_TRACE + stop_meas(&ue->dlsch_channel_estimation_stats); +#endif + } //put back nb_prefix_samples0 frame_parms->nb_prefix_samples0 = nb_prefix_samples0; @@ -224,6 +211,15 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) /* check that SSS/PBCH block is continuous inside the received buffer */ if (sync_pos < (NR_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_subframe - (NB_SYMBOLS_PBCH * fp->ofdm_symbol_size))) { + + for(int i=0; i<4;i++) + nr_slot_fep(ue, + i, + 0, + ue->ssb_offset, + 0, + NR_PBCH_EST); + #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"Calling sss detection (normal CP)\n"); #endif @@ -241,8 +237,8 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) int nb_prefix_samples0 = fp->nb_prefix_samples0; fp->nb_prefix_samples0 = fp->nb_prefix_samples; - nr_slot_fep(ue,0, 0, ue->ssb_offset, 0, 1, NR_PDCCH_EST); - nr_slot_fep(ue,1, 0, ue->ssb_offset, 0, 1, NR_PDCCH_EST); + nr_slot_fep(ue,0, 0, ue->ssb_offset, 0, NR_PDCCH_EST); + nr_slot_fep(ue,1, 0, ue->ssb_offset, 0, NR_PDCCH_EST); fp->nb_prefix_samples0 = nb_prefix_samples0; LOG_I(PHY,"[UE %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n", diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c index 9b09a846bb..e4495a5526 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c @@ -898,6 +898,7 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain } if (fo_flag){ + // fractional frequency offser computation according to Cross-correlation Synchronization Algorithm Using PSS // Shoujun Huang, Yongtao Su, Ying He and Shan Tang, "Joint time and frequency offset estimation in LTE downlink," 7th International Conference on Communications and Networking in China, 2012. @@ -922,7 +923,7 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain // estimation of fractional frequency offset: angle[(result1)'*(result2)]/pi ffo_est=atan2(re1*im2-re2*im1,re1*re2+im1*im2)/M_PI; - + #ifdef DBG_PSS_NR printf("ffo %lf\n",ffo_est); #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c index 26639a5134..493672f890 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c @@ -443,24 +443,6 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max) // For now, symbol 0 = PSS/PBCH and it is never in symbol 0 or 7*2^mu (i.e. always shorter prefix) frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples; - // Do FFTs for SSS/PSS - // SSS - nr_slot_fep(ue, - SSS_SYMBOL_NB-PSS_SYMBOL_NB, // symbol number w.r.t. PSS - 0, // Ns slot number - ue->ssb_offset, // sample_offset of int16_t - 0, // no_prefix - 1, // reset frequency estimation - NR_SSS_EST); - - // PSS - nr_slot_fep(ue, - 0, - 0, - ue->ssb_offset, - 0, - 1, - NR_SSS_EST); frame_parms->nb_prefix_samples0 = nb_prefix_samples0; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 1a631000f5..a2388def23 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -4991,7 +4991,6 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN nr_tti_rx, 0, 0, - 1, NR_PDCCH_EST); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT); #if UE_TIMING_TRACE @@ -5022,7 +5021,6 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN nr_tti_rx, 0, 0, - 1, NR_PDSCH_EST); //printf("phy procedure pdsch start measurement\n"); @@ -5106,7 +5104,6 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN nr_tti_rx, 0, 0, - 1, NR_PBCH_EST); nr_ue_pbch_procedures(eNB_id,ue,proc,0); diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index a52c6ecf0d..74850d2509 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -43,6 +43,7 @@ #include "PHY/INIT/phy_init.h" #include "PHY/NR_TRANSPORT/nr_transport.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +#include "PHY/NR_UE_ESTIMATION/nr_estimation.h" #include "SCHED_NR/sched_nr.h" @@ -371,6 +372,7 @@ int main(int argc, char **argv) frame_parms->N_RB_DL = N_RB_DL; frame_parms->N_RB_UL = N_RB_DL; frame_parms->Nid_cell = Nid_cell; + frame_parms->ssb_type = nr_ssb_type_B; nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu,Nid_cell,SSB_positions); phy_init_nr_gNB(gNB,0,0); @@ -545,7 +547,6 @@ int main(int argc, char **argv) n_errors_payload = 0; for (trial=0; trialrx_offset=0; - //symbol 1 - nr_slot_fep(UE, - 5, - 0, - 0, - 0, - 1, - NR_PBCH_EST); - - //symbol 2 - nr_slot_fep(UE, - 6, - 0, - 0, - 0, - 1, - NR_PBCH_EST); - - //symbol 3 - nr_slot_fep(UE, - 7, - 0, - 0, - 0, - 1, - NR_PBCH_EST); + + for (int i=5; i<8; i++) { + nr_slot_fep(UE, + i, + 0, + 0, + 0, + NR_PBCH_EST); + + nr_pbch_channel_estimation(UE,0,0,i); + } ret = nr_rx_pbch(UE, &UE->proc.proc_rxtx[0], diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c index 1dc3085edf..020dd9adbf 100644 --- a/targets/RT/USER/nr-ue.c +++ b/targets/RT/USER/nr-ue.c @@ -965,7 +965,7 @@ void *UE_thread(void *arg) { UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, UE->frame_parms.nb_antennas_rx),""); //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0), 1, 1); - //nr_slot_fep(UE,0, 0, 0, 1, 1, NR_PDCCH_EST); + //nr_slot_fep(UE,0, 0, 0, 1, NR_PDCCH_EST); } //UE->mode != loop_through_memory else rt_sleep_ns(1000*1000); From 49e9baee5b3605e0e0dde4963ccb5db4619b44d6 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Fri, 1 Mar 2019 13:04:23 +0100 Subject: [PATCH 015/117] brute force ssb detection --- .../nfapi/public_inc/nfapi_nr_interface.h | 2 +- openair1/PHY/INIT/nr_init.c | 7 ++- openair1/PHY/MODULATION/slot_fep_nr.c | 12 +++- .../nr_dl_channel_estimation.c | 17 +++--- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 11 ++-- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 60 +++++++++++-------- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 2 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 4 ++ openair1/PHY/NR_UE_TRANSPORT/sss_nr.c | 15 ----- openair1/PHY/defs_nr_UE.h | 3 + openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 11 +++- openair1/SIMULATION/NR_PHY/pbchsim.c | 15 ++--- 12 files changed, 87 insertions(+), 72 deletions(-) diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h index 69b1c5c3ac..7c78d817a6 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h @@ -75,7 +75,7 @@ typedef struct // These TLVs are used by the VNF to configure the RF in the PNF // nfapi_uint16_tlv_t max_transmit_power; - nfapi_uint16_tlv_t nrarfcn; + nfapi_uint32_tlv_t nrarfcn; // nfapi_nmm_frequency_bands_t nmm_gsm_frequency_bands; // nfapi_nmm_frequency_bands_t nmm_umts_frequency_bands; diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 2f613152dd..3a116de25f 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -363,7 +363,7 @@ void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu, NR_DL_FRAME_PARMS *fp = &gNB->frame_parms; nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config; //overwrite for new NR parameters - gNB_config->nfapi_config.rf_bands.rf_band[0] = 5; + gNB_config->nfapi_config.rf_bands.rf_band[0] = 78; gNB_config->nfapi_config.nrarfcn.value = 620000; gNB_config->subframe_config.numerology_index_mu.value = mu; gNB_config->subframe_config.duplex_mode.value = TDD; @@ -377,12 +377,13 @@ void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu, gNB_config->sch_config.ssb_scg_position_in_burst.value=position_in_burst; gNB->mac_enabled = 1; - fp->dl_CarrierFreq = from_nrarfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.nrarfcn.value); - fp->ul_CarrierFreq = fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000); + fp->dl_CarrierFreq = 3500000000;//from_nrarfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.nrarfcn.value); + fp->ul_CarrierFreq = 3500000000;//fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000); fp->threequarter_fs = 0; nr_init_frame_parms(gNB_config, fp); gNB->configured = 1; LOG_I(PHY,"gNB configured\n"); + } diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c index f41212e543..6ce486e3a0 100644 --- a/openair1/PHY/MODULATION/slot_fep_nr.c +++ b/openair1/PHY/MODULATION/slot_fep_nr.c @@ -45,8 +45,16 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, NR_UE_COMMON *common_vars = &ue->common_vars; unsigned char aa; unsigned char symbol = l;//+((7-frame_parms->Ncp)*(Ns&1)); ///symbol within sub-frame - unsigned int nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples); - unsigned int nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples0); + unsigned int nb_prefix_samples; + unsigned int nb_prefix_samples0; + if (ue->is_synchronized) { + nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples); + nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples0); + } + else { + nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples); + nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples); + } //unsigned int subframe_offset;//,subframe_offset_F; unsigned int slot_offset; //int i; 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 05ee82ae29..20227b827b 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -32,6 +32,7 @@ //#define DEBUG_PDCCH + int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, @@ -47,13 +48,14 @@ 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, ssb_index=0, n_hf=0; + 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; nushift = ue->frame_parms.Nid_cell%4; ue->frame_parms.nushift = nushift; - unsigned int ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier; if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size; @@ -120,7 +122,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, pil = (int16_t *)&pilot[0]; rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; dl_ch = (int16_t *)&dl_ch_estimates[aarx][ch_offset]; - + memset(dl_ch,0,4*(ue->frame_parms.ofdm_symbol_size)); if (ue->high_speed_flag==0) // multiply previous channel estimate by ch_est_alpha multadd_complex_vector_real_scalar(dl_ch-(ue->frame_parms.ofdm_symbol_size<<1), @@ -137,6 +139,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, // Treat first 2 pilots specially (left edge) ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + #ifdef DEBUG_CH printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])); printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]); @@ -154,6 +157,8 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + #ifdef DEBUG_CH printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); #endif @@ -165,9 +170,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; - ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); - ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); - #ifdef DEBUG_CH printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); #endif @@ -195,6 +197,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, } ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + #ifdef DEBUG_CH printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); #endif @@ -213,6 +216,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + #ifdef DEBUG_CH printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); #endif @@ -247,7 +251,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, //} } - return(0); } diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index a6ede43504..ed24edaf56 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -51,9 +51,9 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned short nb_rb_coreset); int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_offset, - unsigned char Ns, - unsigned char symbol); + uint8_t eNB_offset, + unsigned char Ns, + unsigned char symbol); int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, @@ -61,8 +61,9 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned short p, unsigned char l, unsigned char symbol, - unsigned short bwp_start_subcarrier, - unsigned short nb_rb_pdsch); + unsigned short bwp_start_subcarrier, + unsigned short nb_rb_pdsch); + void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, PHY_VARS_NR_UE *ue, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index ea4745fe23..dce3bb51f1 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -53,48 +53,48 @@ int cnt=0; #define DEBUG_INITIAL_SYNCH -int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) + +int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) { NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; - #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 - // save the nb_prefix_samples0 since we are not synchronized to subframes yet and the SSB has all symbols with nb_prefix_samples - int nb_prefix_samples0 = frame_parms->nb_prefix_samples0; - frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples; + uint8_t N_L = (frame_parms->Lmax == 4)? 4:8; + uint8_t N_hf = (frame_parms->Lmax == 4)? 2:1; + // loops over possible pbch dmrs cases to retrive best estimated i_ssb (and n_hf for Lmax=4) for multiple ssb detection + 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; - for(int i=1; i<4;i++) { - #if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); + start_meas(&ue->dlsch_channel_estimation_stats); #endif - nr_pbch_channel_estimation(ue,0, - 0, - i); + for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); + stop_meas(&ue->dlsch_channel_estimation_stats); #endif + + ret = nr_rx_pbch(ue, + &ue->proc.proc_rxtx[0], + ue->pbch_vars[0], + frame_parms, + 0, + SISO, + ue->high_speed_flag); + + } + } } - //put back nb_prefix_samples0 - frame_parms->nb_prefix_samples0 = nb_prefix_samples0; - - - ret = nr_rx_pbch(ue, - &ue->proc.proc_rxtx[0], - ue->pbch_vars[0], - frame_parms, - 0, - SISO, - ue->high_speed_flag); - - if (ret==0) { frame_parms->nb_antenna_ports_eNB = 1; //pbch_tx_ant; @@ -211,6 +211,14 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) /* check that SSS/PBCH block is continuous inside the received buffer */ if (sync_pos < (NR_NUMBER_OF_SUBFRAMES_PER_FRAME*fp->samples_per_subframe - (NB_SYMBOLS_PBCH * fp->ofdm_symbol_size))) { + /* slop_fep function works for lte and takes into account begining of frame with prefix for subframe 0 */ + /* for NR this is not the case but slot_fep is still used for computing FFT of samples */ + /* in order to achieve correct processing for NR prefix samples is forced to 0 and then restored after function call */ + /* symbol number are from beginning of SS/PBCH blocks as below: */ + /* Signal PSS PBCH SSS PBCH */ + /* symbol number 0 1 2 3 */ + /* time samples in buffer rxdata are used as input of FFT -> FFT results are stored in the frequency buffer rxdataF */ + /* rxdataF stores SS/PBCH from beginning of buffers in the same symbol order as in time domain */ for(int i=0; i<4;i++) nr_slot_fep(ue, @@ -230,7 +238,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) //nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,n_ssb_crb,0); nr_gold_pbch(ue); - ret = nr_pbch_detection(ue,mode); + ret = nr_pbch_detection(ue,1,mode); // start pbch detection at first symbol after pss nr_gold_pdcch(ue,0, 2); /* diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a88b51e37a..49d8d80b04 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -426,7 +426,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, uint8_t nushift; uint16_t M; uint8_t Lmax=frame_parms->Lmax; - uint8_t ssb_index=0; + uint8_t ssb_index=ue->i_ssb; //uint16_t crc; //unsigned short idx_demod =0; uint32_t decoderState=0; 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 3c272b9c17..36158fa259 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1125,6 +1125,10 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, MIMO_mode_t mimo_mode, uint32_t high_speed_flag); +int nr_pbch_detection(PHY_VARS_NR_UE *ue, + int pbch_initial_symbol, + runmode_t mode); + uint16_t rx_pbch_emul(PHY_VARS_NR_UE *phy_vars_ue, uint8_t eNB_id, uint8_t pbch_phase); diff --git a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c index 493672f890..3d36822956 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/sss_nr.c @@ -430,21 +430,6 @@ int rx_sss_nr(PHY_VARS_NR_UE *ue, int32_t *tot_metric,uint8_t *phase_max) int32_t metric, metric_re; int16_t *d; - /* slop_fep function works for lte and takes into account begining of frame with prefix for subframe 0 */ - /* for NR this is not the case but slot_fep is still used for computing FFT of samples */ - /* in order to achieve correct processing for NR prefix samples is forced to 0 and then restored after function call */ - /* symbol number are from beginning of SS/PBCH blocks as below: */ - /* Signal PSS PBCH SSS PBCH */ - /* symbol number 0 1 2 3 */ - /* time samples in buffer rxdata are used as input of FFT -> FFT results are stored in the frequency buffer rxdataF */ - /* rxdataF stores SS/PBCH from beginning of buffers in the same symbol order as in time domain */ - - int nb_prefix_samples0 = frame_parms->nb_prefix_samples0; - // For now, symbol 0 = PSS/PBCH and it is never in symbol 0 or 7*2^mu (i.e. always shorter prefix) - frame_parms->nb_prefix_samples0 = frame_parms->nb_prefix_samples; - - - frame_parms->nb_prefix_samples0 = nb_prefix_samples0; // pss sss extraction pss_sss_extract_nr(ue, diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a3c404ba61..f384bcaccf 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -1143,6 +1143,8 @@ 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; int rx_offset; /// Timing offset int rx_offset_diff; /// Timing adjustment for ofdm symbol0 on HW USRP int time_sync_cell; @@ -1307,6 +1309,7 @@ typedef struct { } PHY_VARS_NR_UE; + /* this structure is used to pass both UE phy vars and * proc to the function UE_thread_rxn_txnp4 */ diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index a2388def23..3b04a79321 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -5098,14 +5098,23 @@ 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++) + for (int i=0; i<3; i++) { nr_slot_fep(ue, (5+i), //mu=1 case B nr_tti_rx, 0, 0, NR_PBCH_EST); + +#if UE_TIMING_TRACE + start_meas(&ue->dlsch_channel_estimation_stats); +#endif + nr_pbch_channel_estimation(ue,0,0,5+i); +#if UE_TIMING_TRACE + stop_meas(&ue->dlsch_channel_estimation_stats); +#endif + } nr_ue_pbch_procedures(eNB_id,ue,proc,0); } diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 74850d2509..f424dc9f29 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -372,7 +372,8 @@ int main(int argc, char **argv) frame_parms->N_RB_DL = N_RB_DL; frame_parms->N_RB_UL = N_RB_DL; frame_parms->Nid_cell = Nid_cell; - frame_parms->ssb_type = nr_ssb_type_B; + frame_parms->nushift = Nid_cell%4; + frame_parms->ssb_type = nr_ssb_type_C; nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu,Nid_cell,SSB_positions); phy_init_nr_gNB(gNB,0,0); @@ -605,17 +606,9 @@ int main(int argc, char **argv) 0, 0, NR_PBCH_EST); - - nr_pbch_channel_estimation(UE,0,0,i); } - - ret = nr_rx_pbch(UE, - &UE->proc.proc_rxtx[0], - UE->pbch_vars[0], - frame_parms, - 0, - SISO, - UE->high_speed_flag); + + ret = nr_pbch_detection(UE,5,0); // start pbch detection from symbol 5 and mode 0 if (ret==0) { //UE->rx_ind.rx_indication_body->mib_pdu.ssb_index; //not yet detected automatically From 568fa2375ca0df2a4f323751109e66f81a5698fb Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 1 Mar 2019 15:41:17 +0100 Subject: [PATCH 016/117] adding loop over slots in nr_pbchsim --- openair1/SIMULATION/NR_PHY/pbchsim.c | 47 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index f424dc9f29..8811ae97f7 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -488,28 +488,35 @@ int main(int argc, char **argv) gNB->pbch_configured = 1; for (int i=0;i<4;i++) gNB->pbch_pdu[i]=i+1; - nr_common_signal_procedures (gNB,frame,subframe); - - LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); - if (gNB->frame_parms.nb_antennas_tx>1) - LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1); - - //TODO: loop over slots - for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { - if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { - PHY_ofdm_mod(gNB->common_vars.txdataF[aa], - txdata[aa], - frame_parms->ofdm_symbol_size, - 12, - frame_parms->nb_prefix_samples, - CYCLIC_PREFIX); - } else { - nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], - txdata[aa], - 14, - frame_parms); + for (int slot=0;slotslots_per_frame;slot++) { + for (aa=0; aaframe_parms.nb_antennas_tx; aa++) + memset(gNB->common_vars.txdataF[aa],0,frame_parms->samples_per_slot_wCP*sizeof(int32_t)); + + nr_common_signal_procedures (gNB,frame,slot); + + //TODO: loop over slots + for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { + if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { + PHY_ofdm_mod(gNB->common_vars.txdataF[aa], + &txdata[aa][slot*frame_parms->samples_per_slot], + frame_parms->ofdm_symbol_size, + 12, + frame_parms->nb_prefix_samples, + CYCLIC_PREFIX); + } else { + nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], + &txdata[aa][slot*frame_parms->samples_per_slot], + 14, + frame_parms); + } } } + + LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1); + + } else { printf("Reading %d samples from file to antenna buffer %d\n",frame_length_complex_samples,0); From 62e56f212e9f6594a6e4a9386584f230b4b2ea79 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Fri, 1 Mar 2019 17:57:53 +0100 Subject: [PATCH 017/117] some hardcoding removed in pbch detection still some left --- openair1/PHY/INIT/nr_parms.c | 53 +++++++++++++++++ openair1/PHY/INIT/phy_init.h | 1 + .../nr_dl_channel_estimation.c | 14 ++--- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 3 +- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 2 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 3 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 57 +------------------ openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 2 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 11 +++- 9 files changed, 75 insertions(+), 71 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index 14d95ad488..a2471d6d55 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -27,6 +27,59 @@ uint32_t nr_subcarrier_spacing[MAX_NUM_SUBCARRIER_SPACING] = {15e3, 30e3, 60e3, uint16_t nr_slots_per_subframe[MAX_NUM_SUBCARRIER_SPACING] = {1, 2, 4, 16, 32}; +int nr_get_ssb_start_symbol(NR_DL_FRAME_PARMS *fp, uint8_t i_ssb, uint8_t half_frame_index) +{ + + int mu = fp->numerology_index; + int symbol = 0; + uint8_t n, n_temp; + nr_ssb_type_e type = fp->ssb_type; + int case_AC[2] = {2,8}; + int case_BD[4] = {4,8,16,20}; + int case_E[8] = {8, 12, 16, 20, 32, 36, 40, 44}; + + switch(mu) { + + case NR_MU_0: // case A + n = i_ssb >> 1; + symbol = case_AC[i_ssb % 2] + 14*n; + break; + + case NR_MU_1: + if (type == 1){ // case B + n = i_ssb >> 2; + symbol = case_BD[i_ssb % 4] + 28*n; + } + if (type == 2){ // case C + n = i_ssb >> 1; + symbol = case_AC[i_ssb % 2] + 14*n; + } + break; + + case NR_MU_3: // case D + n_temp = i_ssb >> 2; + n = n_temp + (n_temp >> 2); + symbol = case_BD[i_ssb % 4] + 28*n; + break; + + case NR_MU_4: // case E + n_temp = i_ssb >> 3; + n = n_temp + (n_temp >> 2); + symbol = case_E[i_ssb % 8] + 56*n; + break; + + + default: + AssertFatal(0==1, "Invalid numerology index %d for the synchronization block\n", mu); + } + + if (half_frame_index) + symbol += (5 * fp->symbols_per_slot * fp->slots_per_subframe); + + return symbol; +} + + int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, int mu, int Ncp, diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h index a454fb8e80..ddda39a4c8 100644 --- a/openair1/PHY/INIT/phy_init.h +++ b/openair1/PHY/INIT/phy_init.h @@ -376,6 +376,7 @@ void phy_config_request(PHY_Config_t *phy_config); int init_frame_parms(LTE_DL_FRAME_PARMS *frame_parms,uint8_t osf); void dump_frame_parms(LTE_DL_FRAME_PARMS *frame_parms); +int nr_get_ssb_start_symbol(NR_DL_FRAME_PARMS *fp, uint8_t i_ssb, uint8_t half_frame_index); int nr_init_frame_parms(nfapi_nr_config_request_t* config, NR_DL_FRAME_PARMS *frame_parms); int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *frame_parms,int mu,int Ncp,int N_RB_DL,int n_ssb_crb,int ssb_subcarrier_offset); int init_nr_ue_signal(PHY_VARS_NR_UE *ue,int nb_connected_eNB,uint8_t abstraction_flag); 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 20227b827b..15e83b51d0 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -36,7 +36,8 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char symbol) + unsigned char symbol, + int dmrss) { int pilot[200] __attribute__((aligned(16))); unsigned char aarx; @@ -44,7 +45,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned int pilot_cnt; int16_t ch[2],*pil,*rxF,*dl_ch,*fl,*fm,*fr; int ch_offset,symbol_offset; - int dmrss; //uint16_t Nid_cell = (eNB_offset == 0) ? ue->frame_parms.Nid_cell : ue->measurements.adj_cell_id[eNB_offset-1]; @@ -59,18 +59,14 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned int ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier; if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size; - if (ue->is_synchronized ==0 ) dmrss = symbol-1; - else dmrss = symbol-5; - if (ue->high_speed_flag == 0) // use second channel estimate position for temporary storage ch_offset = ue->frame_parms.ofdm_symbol_size ; else ch_offset = ue->frame_parms.ofdm_symbol_size*symbol; - AssertFatal((symbol > 0 && symbol < 4 && ue->is_synchronized == 0) || - (symbol > 4 && symbol < 8 && ue->is_synchronized == 1), - "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n", - symbol,ue->is_synchronized); + AssertFatal(dmrss >= 0 && dmrss < 3, + "symbol %d is illegal for PBCH DM-RS \n", + dmrss); symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index ed24edaf56..5418b16d1b 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -53,7 +53,8 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char symbol); + unsigned char symbol, + int dmrss); 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 dce3bb51f1..4f0f905e9f 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -78,7 +78,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod start_meas(&ue->dlsch_channel_estimation_stats); #endif for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 49d8d80b04..4d8ce3dec9 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -34,6 +34,7 @@ #include "PHY/phy_extern_nr_ue.h" #include "PHY/sse_intrin.h" #include "PHY/LTE_REFSIG/lte_refsig.h" +#include "PHY/INIT/phy_init.h" //#define DEBUG_PBCH 1 //#define DEBUG_PBCH_ENCODING @@ -442,7 +443,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, int symbol_offset=1; if (ue->is_synchronized > 0) - symbol_offset=4; + symbol_offset=2; else symbol_offset=0; diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index d922a3143d..aeda4b3549 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -30,6 +30,7 @@ #include "SCHED/fapi_l1.h" #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" +#include "PHY/INIT/phy_init.h" #include "T.h" @@ -77,60 +78,6 @@ int return_ssb_type(nfapi_config_request_t *cfg) }*/ -// First SSB starting symbol candidate is used and type B is chosen for 30kHz SCS - -int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp, uint8_t i_ssb) -{ - - int mu = cfg->subframe_config.numerology_index_mu.value; - int symbol = 0; - uint8_t n, n_temp; - nr_ssb_type_e type = fp->ssb_type; - int case_AC[2] = {2,8}; - int case_BD[4] = {4,8,16,20}; - int case_E[8] = {8, 12, 16, 20, 32, 36, 40, 44}; - - - switch(mu) { - - case NR_MU_0: // case A - n = i_ssb >> 1; - symbol = case_AC[i_ssb % 2] + 14*n; - break; - - case NR_MU_1: - if (type == 1){ // case B - n = i_ssb >> 2; - symbol = case_BD[i_ssb % 4] + 28*n; - } - if (type == 2){ // case C - n = i_ssb >> 1; - symbol = case_AC[i_ssb % 2] + 14*n; - } - break; - - case NR_MU_3: // case D - n_temp = i_ssb >> 2; - n = n_temp + (n_temp >> 2); - symbol = case_BD[i_ssb % 4] + 28*n; - break; - - case NR_MU_4: // case E - n_temp = i_ssb >> 3; - n = n_temp + (n_temp >> 2); - symbol = case_E[i_ssb % 8] + 56*n; - break; - - - default: - AssertFatal(0==1, "Invalid numerology index %d for the synchronization block\n", mu); - } - - if (cfg->sch_config.half_frame_index.value) - symbol += (5 * fp->symbols_per_slot * fp->slots_per_subframe); - - return symbol; -} void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp) { fp->ssb_start_subcarrier = (12 * cfg->sch_config.n_ssb_crb.value + cfg->sch_config.ssb_subcarrier_offset.value)/(1<subframe_config.numerology_index_mu.value); @@ -158,7 +105,7 @@ void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) { ssb_index = i + 2*rel_slot; // computing the ssb_index if ((fp->L_ssb >> ssb_index) & 0x01) { // generating the ssb only if the bit of L_ssb at current ssb index is 1 - int ssb_start_symbol_abs = nr_get_ssb_start_symbol(cfg, fp, ssb_index); // computing the starting symbol for current ssb + int ssb_start_symbol_abs = nr_get_ssb_start_symbol(fp, ssb_index, n_hf); // computing the starting symbol for current ssb ssb_start_symbol = ssb_start_symbol_abs % 14; // start symbol wrt slot nr_set_ssb_first_subcarrier(cfg, fp); // setting the first subcarrier diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 3b04a79321..33b42749e0 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -5109,7 +5109,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); + nr_pbch_channel_estimation(ue,0,0,5+i,i); #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 8811ae97f7..4b281184b8 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -378,6 +378,8 @@ int main(int argc, char **argv) nr_phy_config_request_sim(gNB,N_RB_DL,N_RB_DL,mu,Nid_cell,SSB_positions); phy_init_nr_gNB(gNB,0,0); + uint8_t n_hf = gNB_config->sch_config.half_frame_index.value; + double fs,bw,scs,eps; switch (mu) { @@ -494,7 +496,6 @@ int main(int argc, char **argv) nr_common_signal_procedures (gNB,frame,slot); - //TODO: loop over slots for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { PHY_ofdm_mod(gNB->common_vars.txdataF[aa], @@ -605,8 +606,12 @@ int main(int argc, char **argv) } else { UE->rx_offset=0; + + uint8_t ssb_index = 0; + while (!((SSB_positions >> ssb_index) & 0x01)) ssb_index++; // to select the first transmitted ssb - for (int i=5; i<8; i++) { + int start_symbol = nr_get_ssb_start_symbol(frame_parms, ssb_index, n_hf); + for (int i=start_symbol+1; irx_ind.rx_indication_body->mib_pdu.ssb_index; //not yet detected automatically From 2aa32eff67f8edcc863fef749ceb56be6d4af1db Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Mon, 4 Mar 2019 15:32:43 +0100 Subject: [PATCH 018/117] brute force multiple ssb detection works in pbchsim --- .../nr_dl_channel_estimation.c | 6 ++-- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 4 ++- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 31 ++++++++++--------- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 22 +++++++++---- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 1 + openair1/PHY/defs_nr_UE.h | 3 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 11 +++++-- openair1/SIMULATION/NR_PHY/pbchsim.c | 8 ++--- 8 files changed, 53 insertions(+), 33 deletions(-) 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 From ab825dd68abdbea30ad3896e883a68cac0292076 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Wed, 6 Mar 2019 08:50:30 +0100 Subject: [PATCH 019/117] bugfix in pbch channel estimation and dci debug comment mode restored --- openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c | 4 ++-- openair1/PHY/NR_UE_TRANSPORT/dci_nr.c | 8 ++++---- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) 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 d39677d232..e6dab8e922 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -51,8 +51,8 @@ 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; - 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; + int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = ue->frame_parms.Nid_cell%4; ue->frame_parms.nushift = nushift; diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index 6f2f5bcf2d..e3e2331ac4 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -1418,11 +1418,11 @@ void nr_dci_decoding_procedure0(int s, *format_found=_format_2_3_found; } - //#ifdef NR_PDCCH_DCI_DEBUG + #ifdef NR_PDCCH_DCI_DEBUG printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> format_found=%d\n",*format_found); printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> crc_scrambled=%d\n",*crc_scrambled); + #endif - //#endif if (*format_found!=255) { dci_alloc[*dci_cnt].dci_length = sizeof_bits; dci_alloc[*dci_cnt].rnti = crc; @@ -1432,13 +1432,13 @@ void nr_dci_decoding_procedure0(int s, dci_alloc[*dci_cnt].dci_pdu[1] = dci_estimation[1]; dci_alloc[*dci_cnt].dci_pdu[2] = dci_estimation[2]; dci_alloc[*dci_cnt].dci_pdu[3] = dci_estimation[3]; - //#ifdef NR_PDCCH_DCI_DEBUG + #ifdef NR_PDCCH_DCI_DEBUG printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> rnti matches -> DCI FOUND !!! crc =>0x%x, sizeof_bits %d, sizeof_bytes %d \n", dci_alloc[*dci_cnt].rnti, dci_alloc[*dci_cnt].dci_length, sizeof_bytes); printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> dci_cnt %d (format_css %d crc_scrambled %d) L %d, firstCCE %d pdu[0] 0x%lx pdu[1] 0x%lx \n", *dci_cnt, format_css,*crc_scrambled,dci_alloc[*dci_cnt].L, dci_alloc[*dci_cnt].firstCCE,dci_alloc[*dci_cnt].dci_pdu[0],dci_alloc[*dci_cnt].dci_pdu[1]); - //#endif + #endif if ((format_css == cformat0_0_and_1_0) || (format_uss == uformat0_0_and_1_0)) { if ((*crc_scrambled == _p_rnti) || (*crc_scrambled == _si_rnti) || (*crc_scrambled == _ra_rnti)) { dci_alloc[*dci_cnt].format = format1_0; diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index e821e9696a..c067142897 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -52,7 +52,7 @@ //#define DEBUG_DCI #define NR_PDCCH_DCI_TOOLS -#define NR_PDCCH_DCI_TOOLS_DEBUG +//#define NR_PDCCH_DCI_TOOLS_DEBUG typedef unsigned __int128 uint128_t; From 6ce8c3742af1efd3e72678e66dfc688096c57147 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 7 Mar 2019 10:10:06 +0100 Subject: [PATCH 020/117] minor fixes in pbchsim --- openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c | 2 +- openair1/PHY/NR_UE_TRANSPORT/pss_nr.c | 2 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) 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 e6dab8e922..f17f6eb9b8 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -74,7 +74,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, k = nushift; #ifdef DEBUG_CH - printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, + printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, ue->frame_parms.Ncp,Ns,k, symbol); #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c index e4495a5526..40945bebef 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c @@ -899,7 +899,7 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain if (fo_flag){ - // fractional frequency offser computation according to Cross-correlation Synchronization Algorithm Using PSS + // fractional frequency offset computation according to Cross-correlation Synchronization Algorithm Using PSS // Shoujun Huang, Yongtao Su, Ying He and Shan Tang, "Joint time and frequency offset estimation in LTE downlink," 7th International Conference on Communications and Networking in China, 2012. int64_t result1,result2; diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 6891e5b875..cc01357868 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -412,6 +412,7 @@ int main(int argc, char **argv) // computation of integer and fractional FO to compare with estimation results int IFO; if(eps!=0.0){ + UE->UE_fo_compensation = 1; printf("Introducing a CFO of %lf relative to SCS of %d kHz\n",eps,(int)(scs/1000)); if (eps>0) IFO=(int)(eps+0.5); @@ -520,7 +521,7 @@ int main(int argc, char **argv) } else { printf("Reading %d samples from file to antenna buffer %d\n",frame_length_complex_samples,0); - + UE->UE_fo_compensation = 1; // perform fo compensation when samples from file are used if (fread(txdata[0], sizeof(int32_t), frame_length_complex_samples, @@ -594,9 +595,9 @@ int main(int argc, char **argv) } if (n_trials==1) { - LOG_M("rxsig0.m","rxs0", UE->common_vars.rxdata[0],frame_parms->samples_per_subframe,1,1); + LOG_M("rxsig0.m","rxs0", UE->common_vars.rxdata[0],frame_parms->samples_per_frame,1,1); if (gNB->frame_parms.nb_antennas_tx>1) - LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_parms->samples_per_subframe,1,1); + LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_parms->samples_per_frame,1,1); } if (UE->is_synchronized == 0) { From aadc28257005676b35234347a76bb63f7f043f79 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Thu, 7 Feb 2019 13:05:35 +0100 Subject: [PATCH 021/117] [ulschsim] Initial version (copy of dlschsim) --- cmake_targets/CMakeLists.txt | 3 + cmake_targets/build_oai | 2 +- openair1/SIMULATION/NR_PHY/ulschsim.c | 672 ++++++++++++++++++++++++++ 3 files changed, 676 insertions(+), 1 deletion(-) create mode 100644 openair1/SIMULATION/NR_PHY/ulschsim.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index af9c3edf68..949731a021 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2557,6 +2557,9 @@ add_executable(nr_dlsim ${T_SOURCE}) target_link_libraries(nr_dlsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR RRC_LIB NR_RRC_LIB CONFIG_LIB L2_NR -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) +add_executable(nr_ulschsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/ulschsim.c ${T_SOURCE}) +target_link_libraries(nr_ulschsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) + foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 3bbc1ccb71..596ff978f1 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -691,7 +691,7 @@ function main() { echo_info "Compiling unitary tests simulators" # TODO: fix: dlsim_tm4 pucchsim prachsim pdcchsim pbchsim mbmssim #simlist="dlsim_tm4 dlsim ulsim pucchsim prachsim pdcchsim pbchsim mbmssim" - simlist="dlsim ulsim polartest ldpctest nr_pbchsim nr_dlschsim nr_dlsim" + simlist="dlsim ulsim polartest ldpctest nr_pbchsim nr_dlschsim nr_dlsim nr_ulschsim" for f in $simlist ; do compilations \ phy_simulators $f \ diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c new file mode 100644 index 0000000000..2b36a03e61 --- /dev/null +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -0,0 +1,672 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include +#include +#include +#include +#include +#include + +#include "common/config/config_userapi.h" +#include "common/utils/LOG/log.h" +#include "common/ran_context.h" + +#include "SIMULATION/TOOLS/sim.h" +#include "SIMULATION/RF/rf.h" +#include "PHY/types.h" +#include "PHY/defs_nr_common.h" +#include "PHY/defs_nr_UE.h" +#include "PHY/defs_gNB.h" +#include "PHY/INIT/phy_init.h" +#include "PHY/NR_REFSIG/refsig_defs_ue.h" +#include "PHY/NR_REFSIG/nr_mod_table.h" +#include "PHY/MODULATION/modulation_eNB.h" +#include "PHY/MODULATION/modulation_UE.h" +#include "PHY/NR_TRANSPORT/nr_transport.h" +#include "PHY/NR_TRANSPORT/nr_dlsch.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" + +#include "SCHED_NR/sched_nr.h" + +//#include "PHY/MODULATION/modulation_common.h" +//#include "common/config/config_load_configmodule.h" +//#include "UTIL/LISTS/list.h" +//#include "common/ran_context.h" + +//#define DEBUG_DLSCHSIM + +PHY_VARS_gNB *gNB; +PHY_VARS_NR_UE *UE; +RAN_CONTEXT_t RC; + +double cpuf; + +// dummy functions +int nfapi_mode = 0; +int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { + return (0); +} +int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { + return (0); +} + +int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { + return (0); +} + +int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { + return (0); +} + +int oai_nfapi_nr_dl_config_req(nfapi_nr_dl_config_request_t *dl_config_req) { + return (0); +} + +uint32_t from_nrarfcn(int nr_bandP, uint32_t dl_earfcn) { + return (0); +} +int32_t get_uldl_offset(int eutra_bandP) { + return (0); +} + +NR_IF_Module_t * +NR_IF_Module_init(int Mod_id) { + return (NULL); +} + +void exit_function(const char *file, const char *function, const int line, + const char *s) { + const char *msg = s == NULL ? "no comment" : s; + printf("Exiting at: %s:%d %s(), %s\n", file, line, function, msg); + exit(-1); +} + +// needed for some functions +PHY_VARS_NR_UE *PHY_vars_UE_g[1][1] = { { NULL } }; +uint16_t n_rnti = 0x1234; + +char quantize(double D, double x, unsigned char B) { + double qxd; + short maxlev; + qxd = floor(x / D); + maxlev = 1 << (B - 1); //(char)(pow(2,B-1)); + + //printf("x=%f,qxd=%f,maxlev=%d\n",x,qxd, maxlev); + + if (qxd <= -maxlev) + qxd = -maxlev; + else if (qxd >= maxlev) + qxd = maxlev - 1; + + return ((char) qxd); +} + +int main(int argc, char **argv) { + char c; + int i; //,j,l,aa; + double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0; + double snr_step = 0.1; + uint8_t snr1set = 0; + int **txdata; + double **s_re, **s_im, **r_re, **r_im; + // int sync_pos, sync_pos_slot; + // FILE *rx_frame_file; + FILE *output_fd = NULL; + uint8_t write_output_file = 0; + // int subframe_offset; + // char fname[40], vname[40]; + int trial, n_trials = 1, n_errors = 0, n_false_positive = 0; + uint8_t transmission_mode = 1, n_tx = 1, n_rx = 1; + uint16_t Nid_cell = 0; + channel_desc_t *gNB2UE; + uint8_t extended_prefix_flag = 0; + int8_t interf1 = -21, interf2 = -21; + FILE *input_fd = NULL, *pbch_file_fd = NULL; + //char input_val_str[50],input_val_str2[50]; + //uint16_t NB_RB=25; + SCM_t channel_model = AWGN; //Rayleigh1_anticorr; + uint16_t N_RB_DL = 106, mu = 1; + unsigned char frame_type = 0; + unsigned char pbch_phase = 0; + int frame = 0, subframe = 0; + int frame_length_complex_samples; + //int frame_length_complex_samples_no_prefix; + NR_DL_FRAME_PARMS *frame_parms; + //nfapi_nr_config_request_t *gNB_config; + uint8_t Kmimo = 0; + uint32_t Nsoft = 0; + double sigma; + unsigned char qbits = 8; + int ret; + //int run_initial_sync=0; + int loglvl = OAILOG_WARNING; + float target_error_rate = 0.01; + + uint16_t nb_symb_sch = 12; + uint16_t nb_rb = 50; + uint8_t Imcs = 9; + + cpuf = get_cpu_freq_GHz(); + + if (load_configmodule(argc, argv) == 0) { + exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); + } + + //logInit(); + randominit(0); + + while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:N:F:R:P:")) != -1) { + switch (c) { + case 'f': + write_output_file = 1; + output_fd = fopen(optarg, "w"); + + if (output_fd == NULL) { + printf("Error opening %s\n", optarg); + exit(-1); + } + + break; + + case 'd': + frame_type = 1; + break; + + case 'g': + switch ((char) *optarg) { + case 'A': + channel_model = SCM_A; + break; + + case 'B': + channel_model = SCM_B; + break; + + case 'C': + channel_model = SCM_C; + break; + + case 'D': + channel_model = SCM_D; + break; + + case 'E': + channel_model = EPA; + break; + + case 'F': + channel_model = EVA; + break; + + case 'G': + channel_model = ETU; + break; + + default: + msg("Unsupported channel model!\n"); + exit(-1); + } + + break; + + case 'i': + interf1 = atoi(optarg); + break; + + case 'j': + interf2 = atoi(optarg); + break; + + case 'n': + n_trials = atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n", snr0); + break; + + case 'S': + snr1 = atof(optarg); + snr1set = 1; + msg("Setting SNR1 to %f\n", snr1); + break; + + case 'p': + extended_prefix_flag = 1; + break; + + /* + case 'r': + ricean_factor = pow(10,-.1*atof(optarg)); + if (ricean_factor>1) { + printf("Ricean factor must be between 0 and 1\n"); + exit(-1); + } + break; + */ + + case 'y': + n_tx = atoi(optarg); + + if ((n_tx == 0) || (n_tx > 2)) { + msg("Unsupported number of tx antennas %d\n", n_tx); + exit(-1); + } + + break; + + case 'z': + n_rx = atoi(optarg); + + if ((n_rx == 0) || (n_rx > 2)) { + msg("Unsupported number of rx antennas %d\n", n_rx); + exit(-1); + } + + break; + + case 'N': + Nid_cell = atoi(optarg); + break; + + case 'R': + N_RB_DL = atoi(optarg); + break; + + case 'F': + input_fd = fopen(optarg, "r"); + + if (input_fd == NULL) { + printf("Problem with filename %s\n", optarg); + exit(-1); + } + + break; + + case 'P': + pbch_phase = atoi(optarg); + + if (pbch_phase > 3) + printf("Illegal PBCH phase (0-3) got %d\n", pbch_phase); + + break; + + case 'm': + Imcs = atoi(optarg); + break; + + case 'l': + nb_symb_sch = atoi(optarg); + break; + + case 'r': + nb_rb = atoi(optarg); + break; + + case 'x': + transmission_mode = atoi(optarg); + break; + + default: + case 'h': + printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); + printf("-h This message\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit(-1); + break; + } + } + + logInit(); + set_glog(loglvl); + T_stdout = 1; + + if (snr1set == 0) + snr1 = snr0 + 10; + + gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, + 61.44e6, //N_RB2sampling_rate(N_RB_DL), + 40e6, //N_RB2channel_bandwidth(N_RB_DL), + 0, 0, 0); + + if (gNB2UE == NULL) { + msg("Problem generating channel model. Exiting.\n"); + exit(-1); + } + + RC.gNB = (PHY_VARS_gNB ** *) malloc(sizeof(PHY_VARS_gNB **)); + RC.gNB[0] = (PHY_VARS_gNB **) malloc(sizeof(PHY_VARS_gNB *)); + RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB)); + gNB = RC.gNB[0][0]; + //gNB_config = &gNB->gNB_config; + frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH) + frame_parms->nb_antennas_tx = n_tx; + frame_parms->nb_antennas_rx = n_rx; + frame_parms->N_RB_DL = N_RB_DL; + frame_parms->Ncp = extended_prefix_flag ? EXTENDED : NORMAL; + crcTableInit(); + nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell); + phy_init_nr_gNB(gNB, 0, 0); + //init_eNB_afterRU(); + frame_length_complex_samples = frame_parms->samples_per_subframe; + //frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP; + s_re = malloc(2 * sizeof(double *)); + s_im = malloc(2 * sizeof(double *)); + r_re = malloc(2 * sizeof(double *)); + r_im = malloc(2 * sizeof(double *)); + txdata = malloc(2 * sizeof(int *)); + + for (i = 0; i < 2; i++) { + s_re[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(s_re[i], frame_length_complex_samples * sizeof(double)); + s_im[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(s_im[i], frame_length_complex_samples * sizeof(double)); + r_re[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(r_re[i], frame_length_complex_samples * sizeof(double)); + r_im[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(r_im[i], frame_length_complex_samples * sizeof(double)); + txdata[i] = malloc(frame_length_complex_samples * sizeof(int)); + bzero(r_re[i], frame_length_complex_samples * sizeof(int)); + } + + if (pbch_file_fd != NULL) { + load_pbch_desc(pbch_file_fd); + } + + /* for (int k=0; k<2; k++) { + // Create transport channel structures for 2 transport blocks (MIMO) + for (i=0; i<2; i++) { + gNB->dlsch[k][i] = new_gNB_dlsch(Kmimo,8,Nsoft,0,frame_parms,gNB_config); + + if (!gNB->dlsch[k][i]) { + printf("Can't get eNB dlsch structures\n"); + exit(-1); + } + gNB->dlsch[k][i]->Nsoft = 10; + gNB->dlsch[k][i]->rnti = n_rnti+k; + } + }*/ + //configure UE + UE = malloc(sizeof(PHY_VARS_NR_UE)); + memcpy(&UE->frame_parms, frame_parms, sizeof(NR_DL_FRAME_PARMS)); + + //phy_init_nr_top(frame_parms); + if (init_nr_ue_signal(UE, 1, 0) != 0) { + printf("Error at UE NR initialisation\n"); + exit(-1); + } + + //nr_init_frame_parms_ue(&UE->frame_parms); + //init_nr_ue_transport(UE, 0); + for (int sf = 0; sf < 2; sf++) { + for (i = 0; i < 2; i++) { + UE->dlsch[sf][0][i] = new_nr_ue_dlsch(Kmimo, 8, Nsoft, 5, N_RB_DL, + 0); + + if (!UE->dlsch[sf][0][i]) { + printf("Can't get ue dlsch structures\n"); + exit(-1); + } + + UE->dlsch[sf][0][i]->rnti = n_rnti; + } + } + + UE->dlsch_SI[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); + UE->dlsch_ra[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); + unsigned char harq_pid = 0; //dlsch->harq_ids[subframe]; + NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0]; + nfapi_nr_dl_config_dlsch_pdu_rel15_t *rel15 = &dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; + //time_stats_t *rm_stats, *te_stats, *i_stats; + uint8_t is_crnti = 0, llr8_flag = 0; + unsigned int TBS = 8424; + unsigned int available_bits; + uint8_t nb_re_dmrs = 6; + uint16_t length_dmrs = 1; + unsigned char mod_order; + uint8_t Nl = 1; + uint8_t rvidx = 0; + dlsch->rnti = 1; + /*dlsch->harq_processes[0]->mcs = Imcs; + dlsch->harq_processes[0]->rvidx = rvidx;*/ + //printf("dlschsim harqid %d nb_rb %d, mscs %d\n",dlsch->harq_ids[subframe], + // dlsch->harq_processes[0]->nb_rb,dlsch->harq_processes[0]->mcs,dlsch->harq_processes[0]->Nl); + mod_order = nr_get_Qm(Imcs, 1); + available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1); + TBS = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, Nl); + printf("available bits %d TBS %d mod_order %d\n", available_bits, TBS, mod_order); + //dlsch->harq_ids[subframe]= 0; + rel15->n_prb = nb_rb; + rel15->nb_symbols = nb_symb_sch; + rel15->modulation_order = mod_order; + rel15->nb_layers = Nl; + rel15->nb_re_dmrs = nb_re_dmrs; + rel15->transport_block_size = TBS; + double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); + short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); + short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); + double errors_bit_uncoded = 0; + unsigned char *estimated_output; + unsigned char *estimated_output_bit; + unsigned char *test_input_bit; + unsigned int errors_bit = 0; + test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; + NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; + harq_process->mcs = Imcs; + harq_process->Nl = Nl; + harq_process->nb_rb = nb_rb; + harq_process->Qm = mod_order; + harq_process->rvidx = rvidx; + printf("harq process ue mcs = %d Qm = %d, symb %d\n", harq_process->mcs, harq_process->Qm, nb_symb_sch); + unsigned char *test_input; + test_input = (unsigned char *) malloc16(sizeof(unsigned char) * TBS / 8); + + for (i = 0; i < TBS / 8; i++) + test_input[i] = (unsigned char) rand(); + + estimated_output = harq_process->b; + +#ifdef DEBUG_DLSCHSIM + for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); +#endif + + /*for (int i=0; i0x%08x\n",crc24c(test_input, 32)); + // generate signal + if (input_fd == NULL) { + nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms); + } + + for (SNR = snr0; SNR < snr1; SNR += snr_step) { + n_errors = 0; + n_false_positive = 0; + + for (trial = 0; trial < n_trials; trial++) { + errors_bit_uncoded = 0; + for (i = 0; i < available_bits; i++) { +#ifdef DEBUG_CODER + if ((i&0xf)==0) + printf("\ne %d..%d: ",i,i+15); +#endif + + //if (i<16) + // printf("encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); + if (dlsch->harq_processes[0]->f[i] == 0) + modulated_input[i] = 1.0; ///sqrt(2); //QPSK + else + modulated_input[i] = -1.0; ///sqrt(2); + + //if (i<16) printf("modulated_input[%d] = %d\n",i,modulated_input[i]); + //SNR =10; + SNR_lin = pow(10, SNR / 10.0); + sigma = 1.0 / sqrt(2 * SNR_lin); + channel_output_fixed[i] = (short) quantize(sigma / 4.0 / 4.0, + modulated_input[i] + sigma * gaussdouble(0.0, 1.0), + qbits); + //channel_output_fixed[i] = (char)quantize8bit(sigma/4.0,(2.0*modulated_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0)); + //printf("llr[%d]=%d\n",i,channel_output_fixed[i]); + //printf("channel_output_fixed[%d]: %d\n",i,channel_output_fixed[i]); + + //channel_output_fixed[i] = (char)quantize(1,channel_output_fixed[i],qbits); + + //if (i<16) printf("channel_output_fixed[%d] = %d\n",i,channel_output_fixed[i]); + + //Uncoded BER + if (channel_output_fixed[i] < 0) + channel_output_uncoded[i] = 1; //QPSK demod + else + channel_output_uncoded[i] = 0; + + if (channel_output_uncoded[i] != dlsch->harq_processes[harq_pid]->f[i]) + errors_bit_uncoded = errors_bit_uncoded + 1; + } + + //if (errors_bit_uncoded>10) + //printf("errors bits uncoded %f\n", errors_bit_uncoded); +#ifdef DEBUG_CODER + printf("\n"); + exit(-1); +#endif + ret = nr_dlsch_decoding(UE, channel_output_fixed, &UE->frame_parms, + dlsch0_ue, dlsch0_ue->harq_processes[0], frame, nb_symb_sch, + subframe, harq_pid, is_crnti, llr8_flag); + + if (ret > dlsch0_ue->max_ldpc_iterations) + n_errors++; + + //count errors + errors_bit = 0; + + for (i = 0; i < TBS; i++) { + estimated_output_bit[i] = (dlsch0_ue->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7); + test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments + + if (estimated_output_bit[i] != test_input_bit[i]) { + errors_bit++; + //printf("estimated bits error occurs @%d ",i); + } + } + + if (errors_bit > 0) { + n_false_positive++; + if (n_trials == 1) + printf("errors_bit %d (trial %d)\n", errors_bit, trial); + } + } + + printf("SNR %f, BLER %f (false positive %f)\n", SNR, + (float) n_errors / (float) n_trials, + (float) n_false_positive / (float) n_trials); + + if ((float) n_errors / (float) n_trials < target_error_rate) { + printf("PDSCH test OK\n"); + break; + } + } + + /*LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1);*/ + + //TODO: loop over slots + /*for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { + if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { + PHY_ofdm_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + frame_parms->ofdm_symbol_size, + 12, + frame_parms->nb_prefix_samples, + CYCLIC_PREFIX); + } else { + nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + 14, + frame_parms); + } + } + + LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1); + + + for (i=0; inb_antennas_tx; aa++) { + r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); + r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); + } + }*/ + + for (i = 0; i < 2; i++) { + printf("gNB %d\n", i); + free_gNB_dlsch(gNB->dlsch[0][i]); + printf("UE %d\n", i); + free_nr_ue_dlsch(UE->dlsch[0][0][i]); + } + + for (i = 0; i < 2; i++) { + free(s_re[i]); + free(s_im[i]); + free(r_re[i]); + free(r_im[i]); + free(txdata[i]); + } + + free(s_re); + free(s_im); + free(r_re); + free(r_im); + free(txdata); + + if (output_fd) + fclose(output_fd); + + if (input_fd) + fclose(input_fd); + + return (n_errors); +} + From ad402982fe6a0deccaa0a90d30943c6e259c611e Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Thu, 7 Feb 2019 13:11:10 +0100 Subject: [PATCH 022/117] [ulschsim] Add support fo perfect channel (no noise) Also print the uncoded error bits --- openair1/SIMULATION/NR_PHY/ulschsim.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 2b36a03e61..72d4050f89 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -483,7 +483,7 @@ int main(int argc, char **argv) { double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); - double errors_bit_uncoded = 0; + unsigned int errors_bit_uncoded = 0; unsigned char *estimated_output; unsigned char *estimated_output_bit; unsigned char *test_input_bit; @@ -543,9 +543,13 @@ int main(int argc, char **argv) { //SNR =10; SNR_lin = pow(10, SNR / 10.0); sigma = 1.0 / sqrt(2 * SNR_lin); +#if 1 channel_output_fixed[i] = (short) quantize(sigma / 4.0 / 4.0, modulated_input[i] + sigma * gaussdouble(0.0, 1.0), qbits); +#else + channel_output_fixed[i] = (short) quantize(0.01, modulated_input[i], qbits); +#endif //channel_output_fixed[i] = (char)quantize8bit(sigma/4.0,(2.0*modulated_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0)); //printf("llr[%d]=%d\n",i,channel_output_fixed[i]); //printf("channel_output_fixed[%d]: %d\n",i,channel_output_fixed[i]); @@ -565,7 +569,7 @@ int main(int argc, char **argv) { } //if (errors_bit_uncoded>10) - //printf("errors bits uncoded %f\n", errors_bit_uncoded); + printf("errors bits uncoded %u\n", errors_bit_uncoded); #ifdef DEBUG_CODER printf("\n"); exit(-1); From 009b195d57fe3b8337fe9da6e5010daa55264dc2 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Wed, 13 Feb 2019 12:46:44 +0100 Subject: [PATCH 023/117] Initializing and freeing NR_UE_ULSCH_t. Creating nr_ulsch_coding.c --- cmake_targets/CMakeLists.txt | 1 + openair1/PHY/INIT/nr_init_ue.c | 12 +- openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 4 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 4 +- .../PHY/NR_UE_TRANSPORT/nr_transport_ue.h | 41 ++-- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 204 ++++++++++++++++++ openair1/PHY/defs_nr_UE.h | 4 +- openair1/SCHED_NR_UE/harq_nr.c | 12 +- openair1/SCHED_NR_UE/harq_nr.h | 8 +- openair1/SIMULATION/NR_PHY/ulschsim.c | 12 +- .../NR_UE_PHY/unit_tests/src/harq_test.c | 6 +- 11 files changed, 272 insertions(+), 36 deletions(-) create mode 100644 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 949731a021..674d441dd9 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1304,6 +1304,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_initial_sync.c ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_pbch.c ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c + ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c ${OPENAIR1_DIR}/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_tbs_tools.c diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index a150717e42..7a4cd9f446 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -361,8 +361,13 @@ void phy_config_harq_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id, uint16_t max_harq_tx ) { + int num_of_threads,num_of_code_words; + PHY_VARS_NR_UE *phy_vars_ue = PHY_vars_UE_g[Mod_id][CC_id]; - phy_vars_ue->ulsch[eNB_id]->Mlimit = max_harq_tx; + + for (num_of_threads=0;num_of_threadsulsch[eNB_id][num_of_threads][num_of_code_words]->Mlimit = max_harq_tx; } extern uint16_t beta_cqi[16]; @@ -923,11 +928,12 @@ void init_nr_ue_transport(PHY_VARS_NR_UE *ue,int abstraction_flag) { AssertFatal((ue->dlsch[k][i][j] = new_nr_ue_dlsch(1,NUMBER_OF_HARQ_PID_MAX,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag))!=NULL,"Can't get ue dlsch structures\n"); LOG_D(PHY,"dlsch[%d][%d][%d] => %p\n",k,i,j,ue->dlsch[k][i][j]); + + AssertFatal((ue->ulsch[k][i][j] = new_nr_ue_ulsch(ue->frame_parms.N_RB_UL, NUMBER_OF_HARQ_PID_MAX, abstraction_flag))!=NULL,"Can't get ue ulsch structures\n"); + LOG_D(PHY,"ulsch[%d][%d][%d] => %p\n",k,i,j,ue->ulsch[k][i][j]); } } - //AssertFatal((ue->ulsch[i] = new_ue_ulsch(ue->frame_parms.N_RB_UL, abstraction_flag))!=NULL,"Can't get ue ulsch structures\n"); - ue->dlsch_SI[i] = new_nr_ue_dlsch(1,1,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag); ue->dlsch_ra[i] = new_nr_ue_dlsch(1,1,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag); diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index 7415b36281..7191e5f48b 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -69,7 +69,7 @@ void free_gNB_dlsch(NR_gNB_DLSCH_t *dlsch) #endif if (dlsch->harq_processes[i]->b) { - free16(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES); + free16(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES); //this should be MAX_NR_DLSCH_PAYLOAD_BYTES dlsch->harq_processes[i]->b = NULL; #ifdef DEBUG_DLSCH_FREE printf("Freeing dlsch process %d b (%p)\n",i,dlsch->harq_processes[i]->b); @@ -196,7 +196,7 @@ NR_gNB_DLSCH_t *new_gNB_dlsch(unsigned char Kmimo, for (r=0; rharq_processes[i]->c[r] = (uint8_t*)malloc16(8448); - dlsch->harq_processes[i]->d[r] = (uint8_t*)malloc16(68*384); + dlsch->harq_processes[i]->d[r] = (uint8_t*)malloc16(68*384); //max size for coded output if (dlsch->harq_processes[i]->c[r]) { bzero(dlsch->harq_processes[i]->c[r],8448); } else { 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 3c272b9c17..2b8e0258e6 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -61,10 +61,10 @@ void free_nr_ue_dlsch(NR_UE_DLSCH_t *dlsch); NR_UE_DLSCH_t *new_nr_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag); -void free_ue_ulsch(NR_UE_ULSCH_t *ulsch); +void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch); -NR_UE_ULSCH_t *new_ue_ulsch(unsigned char N_RB_UL, uint8_t abstraction_flag); +NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, uint8_t abstraction_flag); void fill_UE_dlsch_MCH(PHY_VARS_NR_UE *ue,int mcs,int ndi,int rvidx,int eNB_id); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index 0760c44b53..1f99da06c0 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -110,20 +110,24 @@ typedef struct { uint32_t B; /// Length of ACK information (bits) uint8_t O_ACK; - /// Pointer to the payload - uint8_t *b; - /// Pointers to transport block segments - uint8_t *c[MAX_NUM_ULSCH_SEGMENTS]; /// Index of current HARQ round for this ULSCH uint8_t round; /// MCS format of this ULSCH uint8_t mcs; /// Redundancy-version of the current sub-frame uint8_t rvidx; - /// LDPC-code outputs - uint8_t d[MAX_NUM_ULSCH_SEGMENTS][3*8448]; - /// Interleaver outputs - uint8_t w[MAX_NUM_ULSCH_SEGMENTS][3*8448]; + /// pointer to pdu from MAC interface (TS 36.212 V15.4.0, Sec 5.1 p. 8) + uint8_t *a; + /// Pointer to the payload + CRC + uint8_t *b; + /// Pointers to transport block segments + uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC-code outputs (TS 36.212 V15.4.0, Sec 5.3.2 p. 17) + uint8_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; // 66*Z_c is the maximum LDPC block length. We use 68 for internal manipulation of the buffer + /// Rate matching (Bit selection) outputs (TS 36.212 V15.4.0, Sec 5.4.2.1 p. 28) + uint8_t *e[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// Rate matching (Interleaving) outputs (TS 36.212 V15.4.0, Sec 5.4.2.2 p. 30) + uint8_t *f[MAX_NUM_NR_ULSCH_SEGMENTS]; /// Number of code segments uint32_t C; /// Number of bits in code segments @@ -168,6 +172,7 @@ typedef struct { // UL number of harq processes uint8_t number_harq_processes_for_pusch; #endif + /* /// Pointer to CQI data (+1 for 8 bits crc) uint8_t o[1+MAX_CQI_BYTES]; /// Length of CQI data (bits) @@ -180,22 +185,25 @@ typedef struct { uint8_t O_RI; /// Pointer to ACK uint8_t o_ACK[4]; + */ /// Minimum number of CQI bits for PUSCH (36-212 r8.6, Sec 5.2.4.1 p. 37) uint8_t O_CQI_MIN; /// ACK/NAK Bundling flag uint8_t bundling; - /// Concatenated "e"-sequences (for definition see 36-212 V8.6 2009-03, p.17-18) - uint8_t e[MAX_NUM_CHANNEL_BITS]; + /// Concatenated "g"-sequences (for definition see 36-212 V15.4.0 2018-12, p.31) + uint8_t g[MAX_NUM_NR_CHANNEL_BITS]; /// Interleaved "h"-sequences (for definition see 36-212 V8.6 2009-03, p.17-18) - uint8_t h[MAX_NUM_CHANNEL_BITS]; + uint8_t h[MAX_NUM_NR_CHANNEL_BITS]; /// Scrambled "b"-sequences (for definition see 36-211 V8.6 2009-03, p.14) - uint8_t b_tilde[MAX_NUM_CHANNEL_BITS]; + uint8_t b_tilde[MAX_NUM_NR_CHANNEL_BITS]; /// Modulated "d"-sequences (for definition see 36-211 V8.6 2009-03, p.14) - int32_t d[MAX_NUM_RE]; + int32_t d[MAX_NUM_NR_RE]; /// Transform-coded "z"-sequences (for definition see 36-211 V8.6 2009-03, p.14-15) - int32_t z[MAX_NUM_RE]; + int32_t z[MAX_NUM_NR_RE]; + /* /// "q" sequences for CQI/PMI (for definition see 36-212 V8.6 2009-03, p.27) uint8_t q[MAX_CQI_PAYLOAD]; + /// coded and interleaved CQI bits uint8_t o_w[(MAX_CQI_BITS+8)*3]; /// coded CQI bits @@ -204,6 +212,7 @@ typedef struct { uint8_t q_ACK[MAX_ACK_PAYLOAD]; /// coded RI bits uint8_t q_RI[MAX_RI_PAYLOAD]; + */ /// beta_offset_cqi times 8 uint16_t beta_offset_cqi_times8; /// beta_offset_ri times 8 @@ -229,9 +238,9 @@ typedef struct { /// num active cba group uint8_t num_active_cba_groups; /// num dci found for cba - uint8_t num_cba_dci[10]; + //uint8_t num_cba_dci[10]; /// allocated CBA RNTI - uint16_t cba_rnti[4];//NUM_MAX_CBA_GROUP]; + //uint16_t cba_rnti[4];//NUM_MAX_CBA_GROUP]; /// UL max-harq-retransmission uint8_t Mlimit; } NR_UE_ULSCH_t; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c new file mode 100644 index 0000000000..8ad2a8ecb4 --- /dev/null +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -0,0 +1,204 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +* \brief Top-level routines for coding the ULSCH transport channel as described in 38.212 V15.4 2018-12 +* \author Khalid Ahmed +* \date 2019 +* \version 0.1 +* \company Fraunhofer IIS +* \email: khalid.ahmed@iis.fraunhofer.de +* \note +* \warning +*/ + +#include "PHY/defs_UE.h" +#include "PHY/phy_extern_ue.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +#include "PHY/CODING/coding_defs.h" +#include "PHY/CODING/coding_extern.h" +#include "PHY/CODING/lte_interleaver_inline.h" +#include "PHY/CODING/nrLDPC_encoder/defs.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" +#include "common/utils/LOG/vcd_signal_dumper.h" + + + + + +void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch) +{ + int i; + int r; + + if (ulsch) { +#ifdef DEBUG_ULSCH_FREE + printf("Freeing ulsch %p\n",ulsch); +#endif + + for (i=0; iharq_processes[i]) { + if (ulsch->harq_processes[i]->b) { + free16(ulsch->harq_processes[i]->b,MAX_NR_ULSCH_PAYLOAD_BYTES); + ulsch->harq_processes[i]->b = NULL; + } + for (r=0; rharq_processes[i]->c[r]) { + free16(ulsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+768); + ulsch->harq_processes[i]->c[r] = NULL; + } + + if (ulsch->harq_processes[i]->d[r]) { + free16(ulsch->harq_processes[i]->d[r],68*384); + ulsch->harq_processes[i]->d[r] = NULL; + } + + if (ulsch->harq_processes[i]->e[r]) { + free16(ulsch->harq_processes[i]->e[r],68*384); + ulsch->harq_processes[i]->e[r] = NULL; + } + + if (ulsch->harq_processes[i]->f[r]) { + free16(ulsch->harq_processes[i]->f[r],68*384); + ulsch->harq_processes[i]->f[r] = NULL; + } + + } + + free16(ulsch->harq_processes[i],sizeof(NR_UL_UE_HARQ_t)); + ulsch->harq_processes[i] = NULL; + } + } + free16(ulsch,sizeof(NR_UE_ULSCH_t)); + ulsch = NULL; + } + +} + +NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, uint8_t abstraction_flag) +{ + + NR_UE_ULSCH_t *ulsch; + unsigned char exit_flag = 0,i,j,r; + unsigned char bw_scaling =1; + + switch (N_RB_UL) { + + case 106: + bw_scaling =2; + break; + + default: + bw_scaling =1; + break; + } + + ulsch = (NR_UE_ULSCH_t *)malloc16(sizeof(NR_UE_ULSCH_t)); + + if (ulsch) { + memset(ulsch,0,sizeof(NR_UE_ULSCH_t)); + + ulsch->number_harq_processes_for_pusch = NR_MAX_ULSCH_HARQ_PROCESSES; + ulsch->Mlimit = 4; // maximum harq retransmissions + + for (i=0; iharq_processes[i] = (NR_UL_UE_HARQ_t *)malloc16(sizeof(NR_UL_UE_HARQ_t)); + + // printf("ulsch->harq_processes[%d] %p\n",i,ulsch->harq_processes[i]); + if (ulsch->harq_processes[i]) { + memset(ulsch->harq_processes[i], 0, sizeof(NR_UL_UE_HARQ_t)); + ulsch->harq_processes[i]->b = (unsigned char*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + ulsch->harq_processes[i]->a = (uint8_t*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + + if (ulsch->harq_processes[i]->a) { + bzero(ulsch->harq_processes[i]->a,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + } else { + printf("Can't allocate PDU\n"); + exit_flag=1; + } + + if (ulsch->harq_processes[i]->b) + memset(ulsch->harq_processes[i]->b,0,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + else { + LOG_E(PHY,"Can't get b\n"); + exit_flag=1; + } + + if (abstraction_flag==0) { + for (r=0; rharq_processes[i]->c[r] = (uint8_t*)malloc16(8448); + ulsch->harq_processes[i]->d[r] = (uint8_t*)malloc16(68*384); //max size for coded output + ulsch->harq_processes[i]->e[r] = (uint8_t*)malloc16(68*384); + ulsch->harq_processes[i]->f[r] = (uint8_t*)malloc16(68*384); + if (ulsch->harq_processes[i]->c[r]) { + bzero(ulsch->harq_processes[i]->c[r],8448); + } else { + printf("Can't get c\n"); + exit_flag=2; + } + if (ulsch->harq_processes[i]->d[r]) { + bzero(ulsch->harq_processes[i]->d[r],(68*384)); + } else { + printf("Can't get d\n"); + exit_flag=2; + } + if (ulsch->harq_processes[i]->e[r]) { + bzero(ulsch->harq_processes[i]->e[r],(68*384)); + } else { + printf("Can't get e\n"); + exit_flag=2; + } + if (ulsch->harq_processes[i]->f[r]) { + bzero(ulsch->harq_processes[i]->f[r],(68*384)); + } else { + printf("Can't get f\n"); + exit_flag=2; + } + } + } + + ulsch->harq_processes[i]->subframe_scheduling_flag = 0; + ulsch->harq_processes[i]->first_tx = 1; + } else { + LOG_E(PHY,"Can't get harq_p %d\n",i); + exit_flag=3; + } + } + + if ((abstraction_flag == 0) && (exit_flag==0)) { + for (i=0; i<8; i++) + for (j=0; j<96; j++) + for (r=0; rharq_processes[i]->d[r][j] = NR_NULL; + + return(ulsch); + } else if (abstraction_flag==1) + return(ulsch); + } + + LOG_E(PHY,"new_ue_ulsch exit flag, size of %d , %zu\n",exit_flag, sizeof(LTE_UE_ULSCH_t)); + free_nr_ue_ulsch(ulsch); + return(NULL); + + +} \ No newline at end of file diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a3c404ba61..10bfa46338 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -1044,8 +1044,8 @@ typedef struct { NR_UE_PBCH *pbch_vars[NUMBER_OF_CONNECTED_eNB_MAX]; NR_UE_PDCCH *pdcch_vars[RX_NB_TH_MAX][NUMBER_OF_CONNECTED_eNB_MAX]; NR_UE_PRACH *prach_vars[NUMBER_OF_CONNECTED_eNB_MAX]; - NR_UE_DLSCH_t *dlsch[RX_NB_TH_MAX][NUMBER_OF_CONNECTED_eNB_MAX][2]; // two RxTx Threads - NR_UE_ULSCH_t *ulsch[NUMBER_OF_CONNECTED_eNB_MAX]; + NR_UE_DLSCH_t *dlsch[RX_NB_TH_MAX][NUMBER_OF_CONNECTED_eNB_MAX][NR_MAX_NB_CODEWORDS]; // two RxTx Threads + NR_UE_ULSCH_t *ulsch[RX_NB_TH_MAX][NUMBER_OF_CONNECTED_eNB_MAX][NR_MAX_NB_CODEWORDS]; // two code words NR_UE_DLSCH_t *dlsch_SI[NUMBER_OF_CONNECTED_eNB_MAX]; NR_UE_DLSCH_t *dlsch_ra[NUMBER_OF_CONNECTED_eNB_MAX]; NR_UE_DLSCH_t *dlsch_p[NUMBER_OF_CONNECTED_eNB_MAX]; diff --git a/openair1/SCHED_NR_UE/harq_nr.c b/openair1/SCHED_NR_UE/harq_nr.c index 23d828ec93..31dcfcacbe 100644 --- a/openair1/SCHED_NR_UE/harq_nr.c +++ b/openair1/SCHED_NR_UE/harq_nr.c @@ -150,7 +150,7 @@ void get_dci_info_for_harq(PHY_VARS_NR_UE *ue, NR_DCI_INFO_EXTRACTED_t *nr_dci_i * *********************************************************************/ -void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, uint8_t number_harq_processes_pusch) +void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, int thread_id, int code_word_idx, uint8_t number_harq_processes_pusch) { NR_UE_ULSCH_t *ulsch; @@ -160,7 +160,7 @@ void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, uint8_t number_h memset(ulsch,0,sizeof(NR_UE_ULSCH_t)); - ue->ulsch[gNB_id] = ulsch; + ue->ulsch[thread_id][gNB_id][code_word_idx] = ulsch; } else { LOG_E(PHY, "Fatal memory allocation problem at line %d in function %s of file %s \n", __LINE__ , __func__, __FILE__); @@ -185,7 +185,7 @@ void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, uint8_t number_h } for (int slot_tx = 0; slot_tx < NR_MAX_SLOTS_PER_FRAME; slot_tx++) { - ue->ulsch[gNB_id]->harq_process_id[slot_tx] = NR_MAX_HARQ_PROCESSES; + ue->ulsch[thread_id][gNB_id][code_word_idx]->harq_process_id[slot_tx] = NR_MAX_HARQ_PROCESSES; } } @@ -202,9 +202,9 @@ void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, uint8_t number_h * *********************************************************************/ -void release_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id) +void release_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, int thread_id, int code_word_idx) { - NR_UE_ULSCH_t *ulsch = ue->ulsch[gNB_id]; + NR_UE_ULSCH_t *ulsch = ue->ulsch[thread_id][gNB_id][code_word_idx]; for (int process_id = 0; process_id < ulsch->number_harq_processes_for_pusch; process_id++) { @@ -215,7 +215,7 @@ void release_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id) free16(ulsch, sizeof(NR_UE_ULSCH_t)); - ue->ulsch[gNB_id] = NULL; + ue->ulsch[thread_id][gNB_id][code_word_idx] = NULL; } /******************************************************************* diff --git a/openair1/SCHED_NR_UE/harq_nr.h b/openair1/SCHED_NR_UE/harq_nr.h index 2d3e87ddab..ee6e8625b0 100644 --- a/openair1/SCHED_NR_UE/harq_nr.h +++ b/openair1/SCHED_NR_UE/harq_nr.h @@ -83,17 +83,21 @@ void get_dci_info_for_harq(PHY_VARS_NR_UE *ue, NR_DCI_INFO_EXTRACTED_t *nr_dci_i /** \brief This function configures uplink HARQ context @param PHY_VARS_NR_UE ue context @param gNB_id gNodeB identifier + @param thread_id RXTX thread index + @param code_word_idx code word index @param number_harq_processes_pusch maximum number of uplink HARQ processes @returns none */ -void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, uint8_t number_harq_processes_pusch); +void config_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, int thread_id, int code_word_idx, uint8_t number_harq_processes_pusch); /** \brief This function releases uplink HARQ context @param PHY_VARS_NR_UE ue context @param gNB_id gNodeB identifier + @param thread_id RXTX thread index + @param code_word_idx code word index @returns none */ -void release_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id); +void release_uplink_harq_process(PHY_VARS_NR_UE *ue, int gNB_id, int thread_id, int code_word_idx); /** \brief This function stores slot for transmission in HARQ context @param ulsch uplink context diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 72d4050f89..951d969c51 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) { //char input_val_str[50],input_val_str2[50]; //uint16_t NB_RB=25; SCM_t channel_model = AWGN; //Rayleigh1_anticorr; - uint16_t N_RB_DL = 106, mu = 1; + uint16_t N_RB_DL = 106, N_RB_UL = 106, mu = 1; unsigned char frame_type = 0; unsigned char pbch_phase = 0; int frame = 0, subframe = 0; @@ -291,6 +291,7 @@ int main(int argc, char **argv) { case 'R': N_RB_DL = atoi(optarg); + N_RB_UL = N_RB_DL; break; case 'F': @@ -381,6 +382,7 @@ int main(int argc, char **argv) { frame_parms->nb_antennas_tx = n_tx; frame_parms->nb_antennas_rx = n_rx; frame_parms->N_RB_DL = N_RB_DL; + frame_parms->N_RB_UL = N_RB_UL; frame_parms->Ncp = extended_prefix_flag ? EXTENDED : NORMAL; crcTableInit(); nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell); @@ -446,6 +448,13 @@ int main(int argc, char **argv) { exit(-1); } + UE->ulsch[sf][0][i] = new_nr_ue_ulsch(N_RB_UL, 8, 0); + + if (!UE->ulsch[sf][0][i]) { + printf("Can't get ue ulsch structures\n"); + exit(-1); + } + UE->dlsch[sf][0][i]->rnti = n_rnti; } } @@ -649,6 +658,7 @@ int main(int argc, char **argv) { free_gNB_dlsch(gNB->dlsch[0][i]); printf("UE %d\n", i); free_nr_ue_dlsch(UE->dlsch[0][0][i]); + free_nr_ue_ulsch(UE->ulsch[0][0][i]); } for (i = 0; i < 2; i++) { diff --git a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/harq_test.c b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/harq_test.c index ab99841668..05170e0bc9 100644 --- a/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/harq_test.c +++ b/openair1/SIMULATION/NR_UE_PHY/unit_tests/src/harq_test.c @@ -54,6 +54,8 @@ int test_harq_uplink(PHY_VARS_NR_UE *phy_vars_ue) { int gNB_id = 0; + int thread_number = 0; + int code_word_idx = 0; int harq_pid = 0; int ndi = 1; uint8_t rnti_type = _C_RNTI_; @@ -61,7 +63,7 @@ int test_harq_uplink(PHY_VARS_NR_UE *phy_vars_ue) printf("\nHARQ Uplink \n"); - config_uplink_harq_process(phy_vars_ue , gNB_id, NR_DEFAULT_DLSCH_HARQ_PROCESSES); + config_uplink_harq_process(phy_vars_ue , gNB_id, thread_number, code_word_idx, NR_DEFAULT_DLSCH_HARQ_PROCESSES); NR_UE_ULSCH_t *ulsch_harq = phy_vars_ue->ulsch[gNB_id]; @@ -91,7 +93,7 @@ int test_harq_uplink(PHY_VARS_NR_UE *phy_vars_ue) } } - release_uplink_harq_process(phy_vars_ue , gNB_id); + release_uplink_harq_process(phy_vars_ue , gNB_id, thread_number, code_word_idx); return 0; } From 3d3f49c5c0931c446ce7dfb17597f3ac4cc4c2e5 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Mon, 18 Feb 2019 15:15:44 +0100 Subject: [PATCH 024/117] nr_ulsch_encoding is implemented and tested --- openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 13 +- .../NR_TRANSPORT/nr_transport_common_proto.h | 2 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 3 + .../PHY/NR_UE_TRANSPORT/nr_transport_ue.h | 14 +- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 313 ++++++++++++++++-- openair1/SIMULATION/NR_PHY/ulschsim.c | 65 +++- 6 files changed, 358 insertions(+), 52 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index 7191e5f48b..eb1bdb0508 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -272,7 +272,7 @@ int nr_dlsch_encoding(unsigned char *a, unsigned int G; unsigned int crc=1; - + int i; uint8_t harq_pid = dlsch->harq_ids[slot]; nfapi_nr_dl_config_dlsch_pdu_rel15_t rel15 = dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; uint16_t nb_rb = rel15.n_prb; @@ -302,7 +302,9 @@ int nr_dlsch_encoding(unsigned char *a, A = rel15.transport_block_size; G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,rel15.nb_layers); + LOG_D(PHY,"dlsch coding A %d G %d mod_order %d\n", A,G, mod_order); + Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, rel15.nb_layers); @@ -328,8 +330,13 @@ int nr_dlsch_encoding(unsigned char *a, dlsch->harq_processes[harq_pid]->B = A+24; // dlsch->harq_processes[harq_pid]->b = a; + memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); + //write_output("enc_b.m","enc_in0",&dlsch->harq_processes[harq_pid]->b[0],(A/8)+4,1,4); + //for(i=0;i<10;i++) + //printf("dlsch->harq_processes[harq_pid]->b %d\n", dlsch->harq_processes[harq_pid]->b[i]); + nr_segmentation(dlsch->harq_processes[harq_pid]->b, dlsch->harq_processes[harq_pid]->c, dlsch->harq_processes[harq_pid]->B, @@ -351,6 +358,7 @@ int nr_dlsch_encoding(unsigned char *a, Kr = dlsch->harq_processes[harq_pid]->K; Kr_bytes = Kr>>3; + //write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); //printf("segment Z %d k %d Kr %d BG %d\n", *pz,dlsch->harq_processes[harq_pid]->K,Kr,BG); //start_meas(te_stats); @@ -388,6 +396,7 @@ int nr_dlsch_encoding(unsigned char *a, //stop_meas(te_stats); //printf("end ldpc encoder -- output\n"); + //write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); #ifdef DEBUG_DLSCH_CODING write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); write_output("enc_output0.m","enc0",&dlsch->harq_processes[harq_pid]->d[0][0],(3*8*Kr_bytes)+12,1,4); @@ -429,6 +438,7 @@ int nr_dlsch_encoding(unsigned char *a, rel15.redundancy_version, E); + #ifdef DEBUG_DLSCH_CODING for (int i =0; i<16; i++) printf("output ratematching e[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->e[i+r_offset], r_offset); @@ -442,6 +452,7 @@ int nr_dlsch_encoding(unsigned char *a, dlsch->harq_processes[harq_pid]->f+r_offset); //stop_meas(i_stats); + #ifdef DEBUG_DLSCH_CODING for (int i =0; i<16; i++) printf("output interleaving f[%d]= %d r_offset %d\n", i,dlsch->harq_processes[harq_pid]->f[i+r_offset], r_offset); diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_common_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_common_proto.h index b075da4e97..14ba3de923 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_transport_common_proto.h +++ b/openair1/PHY/NR_TRANSPORT/nr_transport_common_proto.h @@ -38,7 +38,7 @@ #define MAX_NUM_NR_ULSCH_SEGMENTS MAX_NUM_NR_DLSCH_SEGMENTS #define MAX_NR_DLSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056) -#define MAX_NR_ULSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056) +#define MAX_NR_ULSCH_PAYLOAD_BYTES (MAX_NUM_NR_ULSCH_SEGMENTS*1056) #define MAX_NUM_NR_CHANNEL_BITS (14*273*12*6) // 14 symbols, 273 RB #define MAX_NUM_NR_RE (14*273*12) 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 2b8e0258e6..d3e7dd0621 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1006,6 +1006,9 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, uint8_t is_crnti, uint8_t llr8_flag); +int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, + NR_DL_FRAME_PARMS* frame_parms); + uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, UE_nr_rxtx_proc_t *proc, int eNB_id, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index 1f99da06c0..885039c592 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -102,6 +102,8 @@ typedef struct { uint16_t first_rb; /// Current Number of RBs uint16_t nb_rb; + /// number of layers + uint8_t Nl; /// Last TPC command uint8_t TPC; /// Transport block size @@ -117,17 +119,17 @@ typedef struct { /// Redundancy-version of the current sub-frame uint8_t rvidx; /// pointer to pdu from MAC interface (TS 36.212 V15.4.0, Sec 5.1 p. 8) - uint8_t *a; + unsigned char *a; /// Pointer to the payload + CRC uint8_t *b; /// Pointers to transport block segments uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC-code outputs + uint8_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; /// LDPC-code outputs (TS 36.212 V15.4.0, Sec 5.3.2 p. 17) - uint8_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; // 66*Z_c is the maximum LDPC block length. We use 68 for internal manipulation of the buffer - /// Rate matching (Bit selection) outputs (TS 36.212 V15.4.0, Sec 5.4.2.1 p. 28) - uint8_t *e[MAX_NUM_NR_ULSCH_SEGMENTS]; + uint8_t e[MAX_NUM_NR_CHANNEL_BITS] __attribute__((aligned(32))); /// Rate matching (Interleaving) outputs (TS 36.212 V15.4.0, Sec 5.4.2.2 p. 30) - uint8_t *f[MAX_NUM_NR_ULSCH_SEGMENTS]; + uint8_t f[MAX_NUM_NR_CHANNEL_BITS] __attribute__((aligned(32))); /// Number of code segments uint32_t C; /// Number of bits in code segments @@ -162,6 +164,8 @@ typedef struct { typedef struct { /// Current Number of Symbols uint8_t Nsymb_pusch; + /// number of DMRS resource elements + uint8_t nb_re_dmrs; /// SRS active flag uint8_t srs_active; //#if defined(UPGRADE_RAT_NR) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 8ad2a8ecb4..965627e4a8 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -56,6 +56,11 @@ void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch) for (i=0; iharq_processes[i]) { + + if (ulsch->harq_processes[i]->a) { + free16(ulsch->harq_processes[i]->a,MAX_NR_ULSCH_PAYLOAD_BYTES); + ulsch->harq_processes[i]->a = NULL; + } if (ulsch->harq_processes[i]->b) { free16(ulsch->harq_processes[i]->b,MAX_NR_ULSCH_PAYLOAD_BYTES); ulsch->harq_processes[i]->b = NULL; @@ -71,16 +76,6 @@ void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch) ulsch->harq_processes[i]->d[r] = NULL; } - if (ulsch->harq_processes[i]->e[r]) { - free16(ulsch->harq_processes[i]->e[r],68*384); - ulsch->harq_processes[i]->e[r] = NULL; - } - - if (ulsch->harq_processes[i]->f[r]) { - free16(ulsch->harq_processes[i]->f[r],68*384); - ulsch->harq_processes[i]->f[r] = NULL; - } - } free16(ulsch->harq_processes[i],sizeof(NR_UL_UE_HARQ_t)); @@ -119,6 +114,9 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u ulsch->number_harq_processes_for_pusch = NR_MAX_ULSCH_HARQ_PROCESSES; ulsch->Mlimit = 4; // maximum harq retransmissions + //for (i=0; i<10; i++) + //ulsch->harq_ids[i] = 0; + for (i=0; iharq_processes[i] = (NR_UL_UE_HARQ_t *)malloc16(sizeof(NR_UL_UE_HARQ_t)); @@ -126,8 +124,8 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u // printf("ulsch->harq_processes[%d] %p\n",i,ulsch->harq_processes[i]); if (ulsch->harq_processes[i]) { memset(ulsch->harq_processes[i], 0, sizeof(NR_UL_UE_HARQ_t)); - ulsch->harq_processes[i]->b = (unsigned char*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); - ulsch->harq_processes[i]->a = (uint8_t*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + ulsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + ulsch->harq_processes[i]->a = (unsigned char*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); if (ulsch->harq_processes[i]->a) { bzero(ulsch->harq_processes[i]->a,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); @@ -137,7 +135,7 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u } if (ulsch->harq_processes[i]->b) - memset(ulsch->harq_processes[i]->b,0,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + bzero(ulsch->harq_processes[i]->b,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); else { LOG_E(PHY,"Can't get b\n"); exit_flag=1; @@ -148,8 +146,7 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u // account for filler in first segment and CRCs for multiple segment case ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(8448); ulsch->harq_processes[i]->d[r] = (uint8_t*)malloc16(68*384); //max size for coded output - ulsch->harq_processes[i]->e[r] = (uint8_t*)malloc16(68*384); - ulsch->harq_processes[i]->f[r] = (uint8_t*)malloc16(68*384); + if (ulsch->harq_processes[i]->c[r]) { bzero(ulsch->harq_processes[i]->c[r],8448); } else { @@ -162,18 +159,6 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u printf("Can't get d\n"); exit_flag=2; } - if (ulsch->harq_processes[i]->e[r]) { - bzero(ulsch->harq_processes[i]->e[r],(68*384)); - } else { - printf("Can't get e\n"); - exit_flag=2; - } - if (ulsch->harq_processes[i]->f[r]) { - bzero(ulsch->harq_processes[i]->f[r],(68*384)); - } else { - printf("Can't get f\n"); - exit_flag=2; - } } } @@ -185,15 +170,13 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u } } - if ((abstraction_flag == 0) && (exit_flag==0)) { - for (i=0; i<8; i++) - for (j=0; j<96; j++) - for (r=0; rharq_processes[i]->d[r][j] = NR_NULL; + if (exit_flag==0) { + for (i=0; iharq_processes[i]->round=0; + } return(ulsch); - } else if (abstraction_flag==1) - return(ulsch); + } } LOG_E(PHY,"new_ue_ulsch exit flag, size of %d , %zu\n",exit_flag, sizeof(LTE_UE_ULSCH_t)); @@ -201,4 +184,264 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u return(NULL); -} \ No newline at end of file +} + + + +int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, + NR_DL_FRAME_PARMS* frame_parms) +{ + +/////////////////////////parameters and variables declaration///////////////////////// +/////////// + + unsigned int G,crc; + uint8_t harq_pid; + NR_UL_UE_HARQ_t *harq_process; + uint16_t nb_rb ; + uint8_t nb_symb_sch ; + uint32_t A, Z; + uint32_t *pz; + uint8_t mod_order; + uint16_t Kr,r,r_offset,Kr_bytes; + uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; + uint8_t kb,BG; + uint32_t E; + uint8_t Ilbrm; + uint32_t Tbslbrm; + uint8_t nb_re_dmrs; + uint16_t length_dmrs; + int i; + +/////////// +/////////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////parameters and variables initialization///////////////////////// +/////////// + + crc = 1; + harq_pid = 0; + harq_process = ulsch->harq_processes[harq_pid]; + nb_rb = harq_process->nb_rb; + nb_symb_sch = harq_process->nb_symbols; + A = harq_process->TBS; + pz = &Z; + mod_order = nr_get_Qm(harq_process->mcs,1); + Kr=0; + r_offset=0; + BG = 1; + Ilbrm = 0; + Tbslbrm = 950984; //max tbs + nb_re_dmrs = ulsch->nb_re_dmrs; + length_dmrs = 1; + +/////////// +///////////////////////////////////////////////////////////////////////////////////////// + + /* + uint8_t *channel_input[MAX_NUM_DLSCH_SEGMENTS]; //unsigned char + for(j=0;jNl); + LOG_D(PHY,"dlsch coding A %d G %d mod_order %d\n", A,G, mod_order); + printf("ulsch coding A %d G %d mod_order %d\n", A,G, mod_order); + + Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, harq_process->Nl); + + // if (harq_process->Ndi == 1) { // this is a new packet + if (harq_process->round == 0) { // this is a new packet +#ifdef DEBUG_DLSCH_CODING + printf("encoding thinks this is a new packet \n"); +#endif + +///////////////////////// a---->| add CRC |---->b ///////////////////////// +/////////// + /* + int i; + printf("dlsch (tx): \n"); + for (i=0;i<(A>>3);i++) + printf("%02x.",a[i]); + printf("\n"); + */ + // Add 24-bit crc (polynomial A) to payload + crc = crc24a(harq_process->a,A)>>8; + harq_process->a[A>>3] = ((uint8_t*)&crc)[2]; + harq_process->a[1+(A>>3)] = ((uint8_t*)&crc)[1]; + harq_process->a[2+(A>>3)] = ((uint8_t*)&crc)[0]; + //printf("CRC %x (A %d)\n",crc,A); + //printf("a0 %d a1 %d a2 %d\n", a[A>>3], a[1+(A>>3)], a[2+(A>>3)]); + + harq_process->B = A+24; + + memcpy(harq_process->b,harq_process->a,(A/8)+4); + + //write_output("ulsch_b.m","enc_in0",&harq_process->b[0],(A/8)+4,1,4); + //for(i=0;i<10;i++) + //printf("harq_process->b %d\n", harq_process->b[i]); + + + +/////////// +/////////////////////////////////////////////////////////////////////////// + +///////////////////////// b---->| block segmentation |---->c ///////////////////////// +/////////// + + nr_segmentation(harq_process->b, + harq_process->c, + harq_process->B, + &harq_process->C, + &harq_process->K, + pz, + &harq_process->F); + + kb = harq_process->K/(*pz); + if ( kb==22){ + BG = 1; + } + else{ + BG = 2; + } + + Kr = harq_process->K; + Kr_bytes = Kr>>3; + + write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); + +/////////// +///////////////////////////////////////////////////////////////////////////////////// + + +///////////////////////// c---->| LDCP coding |---->d ///////////////////////// +/////////// + + //printf("segment Z %d kb %d k %d Kr %d BG %d\n", *pz,kb,harq_process->K,Kr,BG); + + //start_meas(te_stats); + for (r=0; rC; r++) { + d_tmp[r] = &harq_process->d[r][0]; + //channel_input[r] = &harq_process->d[r][0]; +#ifdef DEBUG_DLSCH_CODING + printf("Encoder: B %d F %d \n",harq_process->B, harq_process->F); + printf("start ldpc encoder segment %d/%d\n",r,harq_process->C); + printf("input %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); + for (int cnt =0 ; cnt < 22*(*pz)/8; cnt ++){ + printf("%d ", harq_process->c[r][cnt]); + } + printf("\n"); + +#endif + //ldpc_encoder_orig((unsigned char*)harq_process->c[r],harq_process->d[r],Kr,BG,0); + //ldpc_encoder_optim((unsigned char*)harq_process->c[r],(unsigned char*)&harq_process->d[r][0],Kr,BG,NULL,NULL,NULL,NULL); + } + + //for (int i=0;i<68*384;i++) + // printf("channel_input[%d]=%d\n",i,channel_input[i]); + + + + /*printf("output %d %d %d %d %d \n", harq_process->d[0][0], harq_process->d[0][1], harq_process->d[r][2],harq_process->d[0][3], harq_process->d[0][4]); + for (int cnt =0 ; cnt < 66*(*pz); cnt ++){ + printf("%d \n", harq_process->d[0][cnt]); + } + printf("\n");*/ + + //ldpc_encoder_optim_8seg(harq_process->c,d_tmp,Kr,BG,harq_process->C,NULL,NULL,NULL,NULL); + ldpc_encoder_optim_8seg(harq_process->c,harq_process->d,Kr,BG,harq_process->C,NULL,NULL,NULL,NULL); + + //stop_meas(te_stats); + //printf("end ldpc encoder -- output\n"); + //write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); +#ifdef DEBUG_DLSCH_CODING + write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); + write_output("ulsch_enc_output0.m","enc0",&harq_process->d[0][0],(3*8*Kr_bytes)+12,1,4); +#endif + +/////////// +/////////////////////////////////////////////////////////////////////////////// + + } + + for (r=0; rC; r++) { // looping over C segments +#ifdef DEBUG_DLSCH_CODING + printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n", + r, + G, + Kr*3, + mod_order,nb_rb); +#endif + + //start_meas(rm_stats); +#ifdef DEBUG_DLSCH_CODING + printf("rvidx in encoding = %d\n", harq_process->rvidx); +#endif + +///////////////////////// d---->| Rate matching bit selection |---->e ///////////////////////// +/////////// + + E = nr_get_E(G, harq_process->C, mod_order, harq_process->Nl, r); + + nr_rate_matching_ldpc(Ilbrm, + Tbslbrm, + BG, + *pz, + harq_process->d[r], + harq_process->e+r_offset, + harq_process->C, + harq_process->rvidx, + E); + + + +#ifdef DEBUG_DLSCH_CODING + for (int i =0; i<16; i++) + printf("output ratematching e[%d]= %d r_offset %d\n", i,harq_process->e[i+r_offset], r_offset); +#endif + +/////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + + +///////////////////////// e---->| Rate matching bit interleaving |---->f ///////////////////////// +/////////// + + //stop_meas(rm_stats); + + //start_meas(i_stats); + nr_interleaving_ldpc(E, + mod_order, + harq_process->e+r_offset, + harq_process->f+r_offset); + //stop_meas(i_stats); + + +#ifdef DEBUG_DLSCH_CODING + for (int i =0; i<16; i++) + printf("output interleaving f[%d]= %d r_offset %d\n", i,harq_process->f[i+r_offset], r_offset); + + if (r==harq_process->C-1) + write_output("enc_output.m","enc",harq_process->f,G,1,4); +#endif + + r_offset += E; + +/////////// +/////////////////////////////////////////////////////////////////////////////////////////////// + + } + + memcpy(ulsch->g,harq_process->f,G>>3); // g is the concatenated code block + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT); + + return(0); +} diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 951d969c51..80121b3d7f 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -122,7 +122,7 @@ char quantize(double D, double x, unsigned char B) { int main(int argc, char **argv) { char c; - int i; //,j,l,aa; + int i,sf; //,j,l,aa; double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0; double snr_step = 0.1; uint8_t snr1set = 0; @@ -438,7 +438,7 @@ int main(int argc, char **argv) { //nr_init_frame_parms_ue(&UE->frame_parms); //init_nr_ue_transport(UE, 0); - for (int sf = 0; sf < 2; sf++) { + for (sf = 0; sf < 2; sf++) { for (i = 0; i < 2; i++) { UE->dlsch[sf][0][i] = new_nr_ue_dlsch(Kmimo, 8, Nsoft, 5, N_RB_DL, 0); @@ -464,6 +464,9 @@ int main(int argc, char **argv) { unsigned char harq_pid = 0; //dlsch->harq_ids[subframe]; NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0]; nfapi_nr_dl_config_dlsch_pdu_rel15_t *rel15 = &dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; + + NR_UE_ULSCH_t *ulsch = UE->ulsch[0][0][0]; + //time_stats_t *rm_stats, *te_stats, *i_stats; uint8_t is_crnti = 0, llr8_flag = 0; unsigned int TBS = 8424; @@ -474,6 +477,7 @@ int main(int argc, char **argv) { uint8_t Nl = 1; uint8_t rvidx = 0; dlsch->rnti = 1; + ulsch->nb_re_dmrs = nb_re_dmrs; //[adk] A HOT FIX until cearting nfapi_nr_ul_config_ulsch_pdu_rel15_t /*dlsch->harq_processes[0]->mcs = Imcs; dlsch->harq_processes[0]->rvidx = rvidx;*/ //printf("dlschsim harqid %d nb_rb %d, mscs %d\n",dlsch->harq_ids[subframe], @@ -497,9 +501,13 @@ int main(int argc, char **argv) { unsigned char *estimated_output_bit; unsigned char *test_input_bit; unsigned int errors_bit = 0; + test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; harq_process->mcs = Imcs; @@ -516,6 +524,26 @@ int main(int argc, char **argv) { estimated_output = harq_process->b; + + /////////////////////////[adk] preparing UL harq_process parameters///////////////////////// + /////////// + NR_UL_UE_HARQ_t *harq_process_ul_ue = ulsch->harq_processes[harq_pid]; + + if (harq_process_ul_ue){ + + harq_process_ul_ue->mcs = Imcs; + harq_process_ul_ue->Nl = Nl; + harq_process_ul_ue->nb_rb = nb_rb; + harq_process_ul_ue->nb_symbols = nb_symb_sch; + harq_process_ul_ue->rvidx = rvidx; + harq_process_ul_ue->TBS = TBS; + harq_process_ul_ue->a = &test_input[0]; + + } + /////////// + //////////////////////////////////////////////////////////////////////////////////////////// + + #ifdef DEBUG_DLSCHSIM for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); #endif @@ -527,6 +555,7 @@ int main(int argc, char **argv) { // generate signal if (input_fd == NULL) { nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms); + nr_ulsch_encoding(ulsch, frame_parms); } for (SNR = snr0; SNR < snr1; SNR += snr_step) { @@ -540,10 +569,14 @@ int main(int argc, char **argv) { if ((i&0xf)==0) printf("\ne %d..%d: ",i,i+15); #endif + /* + if (i<16){ + printf("dlsch_encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); + printf("ulsch_encoder output f[%d] = %d\n",i,ulsch->harq_processes[0]->f[i]); - //if (i<16) - // printf("encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); - if (dlsch->harq_processes[0]->f[i] == 0) + } + */ + if (ulsch->harq_processes[0]->f[i] == 0) modulated_input[i] = 1.0; ///sqrt(2); //QPSK else modulated_input[i] = -1.0; ///sqrt(2); @@ -594,7 +627,7 @@ int main(int argc, char **argv) { errors_bit = 0; for (i = 0; i < TBS; i++) { - estimated_output_bit[i] = (dlsch0_ue->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7); + estimated_output_bit[i] = (ulsch->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7); test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments if (estimated_output_bit[i] != test_input_bit[i]) { @@ -653,12 +686,24 @@ int main(int argc, char **argv) { } }*/ + for (i = 0; i < 2; i++) { + printf("gNB %d\n", i); - free_gNB_dlsch(gNB->dlsch[0][i]); - printf("UE %d\n", i); - free_nr_ue_dlsch(UE->dlsch[0][0][i]); - free_nr_ue_ulsch(UE->ulsch[0][0][i]); + + if (gNB->dlsch[0][i]) + free_gNB_dlsch(gNB->dlsch[0][i]); + + for (sf = 0; sf < 2; sf++) { + + printf("UE %d\n", i); + + if (UE->dlsch[sf][0][i]) + free_nr_ue_dlsch(UE->dlsch[sf][0][i]); + + if (UE->ulsch[sf][0][i]) + free_nr_ue_ulsch(UE->ulsch[sf][0][i]); + } } for (i = 0; i < 2; i++) { From ea2bc826f1b2650f547fd00eb81d006482452cf4 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Wed, 20 Feb 2019 17:20:39 +0100 Subject: [PATCH 025/117] minor clean ups --- cmake_targets/CMakeLists.txt | 5 ++++- openair1/PHY/CODING/crc_byte.c | 6 +++++- openair1/PHY/INIT/nr_init_ue.c | 5 ++--- openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 8 +------- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 7 ------- openair1/PHY/defs_nr_common.h | 4 ++-- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 674d441dd9..6ed11eebfa 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2558,7 +2558,10 @@ add_executable(nr_dlsim ${T_SOURCE}) target_link_libraries(nr_dlsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR RRC_LIB NR_RRC_LIB CONFIG_LIB L2_NR -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) -add_executable(nr_ulschsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/ulschsim.c ${T_SOURCE}) +add_executable(nr_ulschsim + ${OPENAIR1_DIR}/SIMULATION/NR_PHY/ulschsim.c + ${OPENAIR_DIR}/common/utils/backtrace.c + ${T_SOURCE}) target_link_libraries(nr_ulschsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index d728d6b9ad..5e0ebeb991 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -32,6 +32,7 @@ #include "coding_defs.h" +#include "assertions.h" /*ref 36-212 v8.6.0 , pp 8-9 */ /* the highest degree is set by default */ @@ -275,7 +276,7 @@ int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) break; default: - crc_len=3; + AssertFatal(1,"Invalid crc_type \n"); } for (int i=0; i>24; break; + + default: + AssertFatal(1,"Invalid crc_type \n"); } if (crc == oldcrc) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index 7a4cd9f446..986d423034 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -925,9 +925,8 @@ void init_nr_ue_transport(PHY_VARS_NR_UE *ue,int abstraction_flag) { for (i=0; idlsch[k][i][j] = new_nr_ue_dlsch(1,NUMBER_OF_HARQ_PID_MAX,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag))!=NULL,"Can't get ue dlsch structures\n"); - - LOG_D(PHY,"dlsch[%d][%d][%d] => %p\n",k,i,j,ue->dlsch[k][i][j]); + AssertFatal((ue->dlsch[k][i][j] = new_nr_ue_dlsch(1,NUMBER_OF_HARQ_PID_MAX,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag))!=NULL,"Can't get ue dlsch structures\n"); + LOG_D(PHY,"dlsch[%d][%d][%d] => %p\n",k,i,j,ue->dlsch[k][i][j]); AssertFatal((ue->ulsch[k][i][j] = new_nr_ue_ulsch(ue->frame_parms.N_RB_UL, NUMBER_OF_HARQ_PID_MAX, abstraction_flag))!=NULL,"Can't get ue ulsch structures\n"); LOG_D(PHY,"ulsch[%d][%d][%d] => %p\n",k,i,j,ue->ulsch[k][i][j]); diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index eb1bdb0508..4e8c2d2ff5 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -272,7 +272,6 @@ int nr_dlsch_encoding(unsigned char *a, unsigned int G; unsigned int crc=1; - int i; uint8_t harq_pid = dlsch->harq_ids[slot]; nfapi_nr_dl_config_dlsch_pdu_rel15_t rel15 = dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; uint16_t nb_rb = rel15.n_prb; @@ -333,10 +332,6 @@ int nr_dlsch_encoding(unsigned char *a, memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); - //write_output("enc_b.m","enc_in0",&dlsch->harq_processes[harq_pid]->b[0],(A/8)+4,1,4); - //for(i=0;i<10;i++) - //printf("dlsch->harq_processes[harq_pid]->b %d\n", dlsch->harq_processes[harq_pid]->b[i]); - nr_segmentation(dlsch->harq_processes[harq_pid]->b, dlsch->harq_processes[harq_pid]->c, dlsch->harq_processes[harq_pid]->B, @@ -358,7 +353,6 @@ int nr_dlsch_encoding(unsigned char *a, Kr = dlsch->harq_processes[harq_pid]->K; Kr_bytes = Kr>>3; - //write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); //printf("segment Z %d k %d Kr %d BG %d\n", *pz,dlsch->harq_processes[harq_pid]->K,Kr,BG); //start_meas(te_stats); @@ -466,5 +460,5 @@ int nr_dlsch_encoding(unsigned char *a, VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT); - return(0); + return 0; } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 965627e4a8..6b17eff585 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -284,12 +284,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, memcpy(harq_process->b,harq_process->a,(A/8)+4); - //write_output("ulsch_b.m","enc_in0",&harq_process->b[0],(A/8)+4,1,4); - //for(i=0;i<10;i++) - //printf("harq_process->b %d\n", harq_process->b[i]); - - - /////////// /////////////////////////////////////////////////////////////////////////// @@ -315,7 +309,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, Kr = harq_process->K; Kr_bytes = Kr>>3; - write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); /////////// ///////////////////////////////////////////////////////////////////////////////////// diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 58a8833b18..21c1af5774 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -87,10 +87,10 @@ #define NR_MAX_CSET_DURATION 3 #define NR_MAX_NB_RBG 18 -#define NR_MAX_NB_LAYERS 8 +#define NR_MAX_NB_LAYERS 8 // SU-MIMO (3GPP TS 38.211 V15.4.0 section 7.3.1.3) #define NR_MAX_NB_CODEWORDS 2 #define NR_MAX_NB_HARQ_PROCESSES 16 -#define NR_MAX_PDSCH_ENCODED_LENGTH 950984 +#define NR_MAX_PDSCH_ENCODED_LENGTH NR_MAX_NB_RB*NR_SYMBOLS_PER_SLOT*NR_NB_SC_PER_RB*8*NR_MAX_NB_LAYERS // 8 is the maximum modulation order (it was 950984 before !!) #define NR_MAX_PDSCH_TBS 3824 typedef enum { From a7fc22c807f16c42866a12d1cd47aa40b23ba406 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Tue, 26 Feb 2019 12:53:00 +0100 Subject: [PATCH 026/117] Adding harq_pid as an input to nr_ulsch_encoding --- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 18 +++++++++++++++++- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 5 ++--- openair1/SIMULATION/NR_PHY/ulschsim.c | 10 +++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) 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 d3e7dd0621..3db43237a0 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1007,7 +1007,23 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, uint8_t llr8_flag); int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, - NR_DL_FRAME_PARMS* frame_parms); + NR_DL_FRAME_PARMS* frame_parms, + uint8_t harq_pid); + +/*! \brief Perform PUSCH scrambling. TS 38.211 V15.4.0 subclause 6.3.1.1 + @param[in] in Pointer to input bits + @param[in] size of input bits + @param[in] Nid cell id + @param[in] n_RNTI CRNTI + @param[out] out the scrambled bits +*/ + +void nr_pusch_codeword_scrambling(uint8_t *in, + uint16_t size, + uint32_t Nid, + uint32_t n_RNTI, + uint32_t* out); + uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, UE_nr_rxtx_proc_t *proc, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 6b17eff585..4e46903ebf 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -189,14 +189,14 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, - NR_DL_FRAME_PARMS* frame_parms) + NR_DL_FRAME_PARMS* frame_parms, + uint8_t harq_pid) { /////////////////////////parameters and variables declaration///////////////////////// /////////// unsigned int G,crc; - uint8_t harq_pid; NR_UL_UE_HARQ_t *harq_process; uint16_t nb_rb ; uint8_t nb_symb_sch ; @@ -221,7 +221,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, /////////// crc = 1; - harq_pid = 0; harq_process = ulsch->harq_processes[harq_pid]; nb_rb = harq_process->nb_rb; nb_symb_sch = harq_process->nb_symbols; diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 80121b3d7f..de3bd2fe62 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -52,7 +52,7 @@ //#include "UTIL/LISTS/list.h" //#include "common/ran_context.h" -//#define DEBUG_DLSCHSIM +//#define DEBUG_ULSCHSIM PHY_VARS_gNB *gNB; PHY_VARS_NR_UE *UE; @@ -544,7 +544,7 @@ int main(int argc, char **argv) { //////////////////////////////////////////////////////////////////////////////////////////// -#ifdef DEBUG_DLSCHSIM +#ifdef DEBUG_ULSCHSIM for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); #endif @@ -553,9 +553,13 @@ int main(int argc, char **argv) { //printf("crc32: [0]->0x%08x\n",crc24c(test_input, 32)); // generate signal + + /////////////////////////[adk] ULSCH coding///////////////////////// + /////////// + if (input_fd == NULL) { nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms); - nr_ulsch_encoding(ulsch, frame_parms); + nr_ulsch_encoding(ulsch, frame_parms, harq_pid); } for (SNR = snr0; SNR < snr1; SNR += snr_step) { From 9947a6bccd3508ac75c50e360bcdf09a2590c7ff Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Mar 2019 16:58:47 +0100 Subject: [PATCH 027/117] ULSCH decoding functionality at gNB side Added the following structs and enums in "defs_gNB.h" - NR_UL_gNB_HARQ_t - NR_gNB_ULSCH_t - NR_SCH_status_t added the following structs in "nfapi_nr_interface.h" - nfapi_nr_ul_config_ulsch_pdu - nfapi_nr_ul_config_ulsch_pdu_rel15_t - nfapi_nr_ul_srs_config_t - nr_pusch_freq_hopping_t added nr_ulsch.h for the ulsch decoding function declarations - free_gNB_ulsch - new_gNB_ulsch - nr_ulsch_decoding added nr_ulsch_decoding.c for the implementation of the ulsch decoding functions - free_gNB_ulsch - new_gNB_ulsch - nr_ulsch_decoding --- cmake_targets/CMakeLists.txt | 1 + .../nfapi/public_inc/nfapi_nr_interface.h | 41 ++ openair1/PHY/NR_TRANSPORT/nr_ulsch.h | 49 ++ openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 583 ++++++++++++++++++ openair1/PHY/defs_gNB.h | 195 +++++- 5 files changed, 860 insertions(+), 9 deletions(-) create mode 100644 openair1/PHY/NR_TRANSPORT/nr_ulsch.h create mode 100644 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 6ed11eebfa..79f057c29e 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1275,6 +1275,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_dlsch.c ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_dlsch_tools.c ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_dlsch_coding.c + ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_ulsch_decoding.c ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_tbs_tools.c ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/nr_sch_dmrs.c ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_gold.c diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h index 94b7121998..b953a715ef 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface.h @@ -673,4 +673,45 @@ typedef struct { nfapi_vendor_extension_tlv_t vendor_extension; } nfapi_nr_dl_config_request_t; + +typedef enum {nr_pusch_freq_hopping_disabled = 0 , + nr_pusch_freq_hopping_enabled = 1 + } nr_pusch_freq_hopping_t; + +typedef struct{ + uint8_t aperiodicSRS_ResourceTrigger; +} nfapi_nr_ul_srs_config_t; + +typedef struct { + uint8_t bandwidth_part_ind; + uint16_t number_rbs; + uint16_t start_rb; + uint8_t frame_offset; + uint16_t number_symbols; + uint16_t start_symbol; + nr_pusch_freq_hopping_t pusch_freq_hopping; + uint8_t mcs; + uint8_t Qm; + uint8_t ndi; + uint8_t rv; + uint8_t harq_process_nbr; + int8_t accumulated_delta_PUSCH; + int8_t absolute_delta_PUSCH; + uint8_t n_layers; + uint8_t tpmi; + uint8_t n_dmrs_cdm_groups; + uint8_t dmrs_ports[4]; + uint8_t n_front_load_symb; + nfapi_nr_ul_srs_config_t srs_config; + uint8_t csi_reportTriggerSize; + uint8_t maxCodeBlockGroupsPerTransportBlock; + uint8_t ptrs_dmrs_association_port; + uint8_t beta_offset_ind; +} nfapi_nr_ul_config_ulsch_pdu_rel15_t; + +typedef struct { + uint16_t rnti; + nfapi_nr_ul_config_ulsch_pdu_rel15_t ulsch_pdu_rel15; +} nfapi_nr_ul_config_ulsch_pdu; + #endif diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch.h b/openair1/PHY/NR_TRANSPORT/nr_ulsch.h new file mode 100644 index 0000000000..77cc101679 --- /dev/null +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch.h @@ -0,0 +1,49 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file PHY/NR_TRANSPORT/nr_ulsch.h +* \brief functions used for PUSCH/ULSCH physical and transport channels for gNB +* \author Ahmed Hussein +* \date 2019 +* \version 0.1 +* \company Fraunhofer IIS +* \email: ahmed.hussein@iis.fraunhofer.de +* \note +* \warning +*/ + +#include "PHY/defs_gNB.h" + +void free_gNB_ulsch(NR_gNB_ULSCH_t *ulsch); + +NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag); + +uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, + uint8_t UE_id, + short *ulsch_llr, + NR_DL_FRAME_PARMS *frame_parms, + uint32_t frame, + uint16_t nb_symb_sch, + uint8_t nr_tti_rx, + uint8_t harq_pid, + uint8_t is_crnti, + uint8_t llr8_flag); + diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c new file mode 100644 index 0000000000..1d72507de9 --- /dev/null +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -0,0 +1,583 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file PHY/NR_TRANSPORT/nr_ulsch_decoding.c +* \brief Top-level routines for decoding LDPC (ULSCH) transport channels from 38.212, V15.4.0 2018-12 +* \author Ahmed Hussein +* \date 2019 +* \version 0.1 +* \company Fraunhofer IIS +* \email: ahmed.hussein@iis.fraunhofer.de +* \note +* \warning +*/ + + +// [from gNB coding] +#include "PHY/defs_gNB.h" +#include "PHY/phy_extern.h" +#include "PHY/CODING/coding_extern.h" +#include "PHY/CODING/coding_defs.h" +#include "PHY/CODING/lte_interleaver_inline.h" +#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h" +#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h" +#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h" +#include "PHY/NR_TRANSPORT/nr_ulsch.h" +#include "PHY/NR_TRANSPORT/nr_dlsch.h" +#include "SCHED_NR/sched_nr.h" +#include "defs.h" +#include "common/utils/LOG/vcd_signal_dumper.h" +#include "common/utils/LOG/log.h" +#include +//#define DEBUG_ULSCH_DECODING + +#define OAI_UL_LDPC_MAX_NUM_LLR 27000//26112 // NR_LDPC_NCOL_BG1*NR_LDPC_ZMAX = 68*384 + +static uint64_t nb_total_decod =0; +static uint64_t nb_error_decod =0; + +//extern double cpuf; + +void free_gNB_ulsch(NR_gNB_ULSCH_t *ulsch) +{ + + int i,r; + + if (ulsch) { + for (i=0; iharq_processes[i]) { + if (ulsch->harq_processes[i]->b) { + free16(ulsch->harq_processes[i]->b,MAX_NR_ULSCH_PAYLOAD_BYTES); + ulsch->harq_processes[i]->b = NULL; + } + for (r=0; rharq_processes[i]->c[r],(8448)*sizeof(uint8_t)); + ulsch->harq_processes[i]->c[r] = NULL; + } + for (r=0; rharq_processes[i]->d[r]) { + free16(ulsch->harq_processes[i]->d[r],(68*384)*sizeof(int16_t)); + ulsch->harq_processes[i]->d[r] = NULL; + } + } + for (r=0; r<(MAX_NUM_NR_ULSCH_SEGMENTS); r++) { + if (ulsch->harq_processes[i]->p_nrLDPC_procBuf[r]){ + nrLDPC_free_mem(ulsch->harq_processes[i]->p_nrLDPC_procBuf[r]); + ulsch->harq_processes[i]->p_nrLDPC_procBuf[r] = NULL; + } + } + free16(ulsch->harq_processes[i],sizeof(NR_UL_gNB_HARQ_t)); + ulsch->harq_processes[i] = NULL; + } + } + free16(ulsch,sizeof(NR_gNB_ULSCH_t)); + ulsch = NULL; + } +} + + +NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag) +{ + + NR_gNB_ULSCH_t *ulsch; + uint8_t exit_flag = 0,i,r; + unsigned char bw_scaling =1; + + switch (N_RB_UL) { + case 106: + bw_scaling =2; + break; + + default: + bw_scaling =1; + break; + } + + ulsch = (NR_gNB_ULSCH_t *)malloc16(sizeof(NR_gNB_ULSCH_t)); + + if (ulsch) { + + memset(ulsch,0,sizeof(NR_gNB_ULSCH_t)); + + ulsch->max_ldpc_iterations = max_ldpc_iterations; + ulsch->Mlimit = 4; + + for (i=0; iharq_processes[i] = (NR_UL_gNB_HARQ_t *)malloc16(sizeof(NR_UL_gNB_HARQ_t)); + + if (ulsch->harq_processes[i]) { + + memset(ulsch->harq_processes[i],0,sizeof(NR_UL_gNB_HARQ_t)); + + ulsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + + if (ulsch->harq_processes[i]->b) + memset(ulsch->harq_processes[i]->b,0,MAX_NR_ULSCH_PAYLOAD_BYTES/bw_scaling); + else + exit_flag=3; + + if (abstraction_flag == 0) { + for (r=0; rharq_processes[i]->p_nrLDPC_procBuf[r] = nrLDPC_init_mem(); + + ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(8448*sizeof(uint8_t)); + + if (ulsch->harq_processes[i]->c[r]) + memset(ulsch->harq_processes[i]->c[r],0,8448*sizeof(uint8_t)); + else + exit_flag=2; + + ulsch->harq_processes[i]->d[r] = (int16_t*)malloc16((68*384)*sizeof(int16_t)); + + if (ulsch->harq_processes[i]->d[r]) + memset(ulsch->harq_processes[i]->d[r],0,(68*384)*sizeof(int16_t)); + else + exit_flag=2; + } + } + } else { + exit_flag=1; + } + } + + if (exit_flag==0) + return(ulsch); + } + + printf("new_gNB_ulsch with size %zu: exit_flag = %u\n",sizeof(NR_UL_gNB_HARQ_t), exit_flag); + free_gNB_ulsch(ulsch); + + return(NULL); +} + + +uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, + uint8_t UE_id, + short *ulsch_llr, + NR_DL_FRAME_PARMS *frame_parms, + uint32_t frame, + uint16_t nb_symb_sch, + uint8_t nr_tti_rx, + uint8_t harq_pid, + uint8_t is_crnti, + uint8_t llr8_flag) +{ + + uint32_t A,E; + uint32_t G; + uint32_t ret,offset; + int32_t no_iteration_ldpc; + uint32_t r,r_offset=0,Kr=8424,Kr_bytes,K_bytes_F,err_flag=0; + uint8_t crc_type; + int8_t llrProcBuf[OAI_UL_LDPC_MAX_NUM_LLR] __attribute__ ((aligned(32))); + + + NR_gNB_ULSCH_t *ulsch = phy_vars_gNB->ulsch[UE_id][0]; + NR_UL_gNB_HARQ_t *harq_process = ulsch->harq_processes[harq_pid]; + nfapi_nr_ul_config_ulsch_pdu_rel15_t *nfapi_ulsch_pdu_rel15 = &harq_process->ulsch_pdu.ulsch_pdu_rel15; + + t_nrLDPC_dec_params decParams; + t_nrLDPC_dec_params* p_decParams = &decParams; + t_nrLDPC_time_stats procTime; + t_nrLDPC_time_stats* p_procTime = &procTime ; + t_nrLDPC_procBuf** p_nrLDPC_procBuf = harq_process->p_nrLDPC_procBuf; + + int16_t z [68*384]; + int8_t l [68*384]; + int16_t inv_d [68*384]; + uint8_t kb, kc; + uint8_t Ilbrm = 0; + uint32_t Tbslbrm = 950984; + uint16_t nb_rb = 30; //to update + uint8_t nb_re_dmrs = 6; + uint16_t length_dmrs = 1; + + uint32_t i,j; + + __m128i *pv = (__m128i*)&z; + __m128i *pl = (__m128i*)&l; + + + if (!ulsch_llr) { + printf("ulsch_decoding.c: NULL ulsch_llr pointer\n"); + return(ulsch->max_ldpc_iterations); + } + + if (!harq_process) { + printf("ulsch_decoding.c: NULL harq_process pointer\n"); + return(ulsch->max_ldpc_iterations); + } + + if (!frame_parms) { + printf("ulsch_decoding.c: NULL frame_parms pointer\n"); + return(ulsch->max_ldpc_iterations); + } + + nb_rb = nfapi_ulsch_pdu_rel15->number_rbs; + + // harq_process->trials[nfapi_ulsch_pdu_rel15->round]++; + + harq_process->TBS = nr_compute_tbs(nfapi_ulsch_pdu_rel15->mcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, nfapi_ulsch_pdu_rel15->n_layers); + + A = harq_process->TBS; + ret = ulsch->max_ldpc_iterations; + + harq_process->G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, nfapi_ulsch_pdu_rel15->Qm,nfapi_ulsch_pdu_rel15->n_layers); + G = harq_process->G; + + LOG_I(PHY,"ULSCH Decoding, harq_pid %d TBS %d G %d mcs %d Nl %d nb_symb_sch %d nb_rb %d\n",harq_pid,A,G, nfapi_ulsch_pdu_rel15->mcs, nfapi_ulsch_pdu_rel15->n_layers, nb_symb_sch,nb_rb); + + if (harq_process->round == 0) { + // This is a new packet, so compute quantities regarding segmentation + harq_process->B = A+24; + + // [hna] Perform nr_segmenation with input and output set to NULL to calculate only (B, C, K, Z, F) + nr_segmentation(NULL, + NULL, + harq_process->B, + &harq_process->C, + &harq_process->K, + &harq_process->Z, // [hna] Z is Zc + &harq_process->F); + + p_decParams->Z = harq_process->Z; + +#ifdef DEBUG_ULSCH_DECODING + printf("ulsch decoding nr segmentation Z %d\n", p_decParams->Z); + if (!frame%100) + printf("K %d C %d Z %d nl %d \n", harq_process->K, harq_process->C, p_decParams->Z, harq_process->Nl); +#endif + } + + kb = harq_process->K/harq_process->Z; + + if ( kb==22) { + p_decParams->BG = 1; + p_decParams->R = 13; + kc = 68; + } else { + p_decParams->BG = 2; + p_decParams->R = 13; + kc = 52; + } + + p_decParams->numMaxIter = ulsch->max_ldpc_iterations; + Kr = p_decParams->Z*kb; + p_decParams->outMode= 0; + + err_flag = 0; + r_offset = 0; + + unsigned char bw_scaling =1; + + switch (frame_parms->N_RB_UL) { + + case 106: + bw_scaling =2; + break; + + default: + bw_scaling =1; + break; + } + + if (harq_process->C > MAX_NUM_NR_ULSCH_SEGMENTS/bw_scaling) { + LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,MAX_NUM_NR_ULSCH_SEGMENTS/bw_scaling); + return((1+ulsch->max_ldpc_iterations)); + } +#ifdef DEBUG_ULSCH_DECODING + printf("Segmentation: C %d, K %d\n",harq_process->C,harq_process->K); +#endif + + opp_enabled=1; + + Kr = harq_process->K; // [hna] overwrites this line "Kr = p_decParams->Z*kb" + Kr_bytes = Kr>>3; + + K_bytes_F = Kr_bytes-(harq_process->F>>3); + + Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, nfapi_ulsch_pdu_rel15->n_layers); + + for (r=0; rC; r++) { + + E = nr_get_E(G, harq_process->C, nfapi_ulsch_pdu_rel15->Qm, nfapi_ulsch_pdu_rel15->n_layers, r); + +#if gNB_TIMING_TRACE + start_meas(ulsch_deinterleaving_stats); +#endif + + //////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////// nr_deinterleaving_ldpc /////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////// + + //////////////////////////// ulsch_llr =====> harq_process->e ////////////////////////////// + + nr_deinterleaving_ldpc(E, + nfapi_ulsch_pdu_rel15->Qm, + harq_process->e[r], + ulsch_llr+r_offset); + + //for (int i =0; i<16; i++) + // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); + +#if gNB_TIMING_TRACE + stop_meas(ulsch_deinterleaving_stats); +#endif + +#if gNB_TIMING_TRACE + start_meas(ulsch_rate_unmatching_stats); +#endif + +#ifdef DEBUG_ULSCH_DECODING + LOG_D(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n", + harq_pid,r, G, + Kr*3, + harq_process->TBS, + nfapi_ulsch_pdu_rel15->Qm, + nfapi_ulsch_pdu_rel15->number_rbs, + nfapi_ulsch_pdu_rel15->n_layers, + nfapi_ulsch_pdu_rel15->rv, + harq_process->round); +#endif + ////////////////////////////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////// nr_rate_matching_ldpc_rx //////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////// + + ///////////////////////// harq_process->e =====> harq_process->d ///////////////////////// + + if (nr_rate_matching_ldpc_rx(Ilbrm, + Tbslbrm, + p_decParams->BG, + p_decParams->Z, + harq_process->d[r], + harq_process->e[r], + harq_process->C, + nfapi_ulsch_pdu_rel15->rv, + (harq_process->round==0)?1:0, + E)==-1) { +#if gNB_TIMING_TRACE + stop_meas(ulsch_rate_unmatching_stats); +#endif + LOG_E(PHY,"ulsch_decoding.c: Problem in rate_matching\n"); + return(ulsch->max_ldpc_iterations); + } else { +#if gNB_TIMING_TRACE + stop_meas(ulsch_rate_unmatching_stats); +#endif + } + + r_offset += E; + +#ifdef DEBUG_ULSCH_DECODING + if (r==0) { + write_output("decoder_llr.m","decllr",ulsch_llr,G,1,0); + write_output("decoder_in.m","dec",&harq_process->d[0][0],(3*8*Kr_bytes)+12,1,0); + } + + printf("decoder input(segment %d) :",r); + int i; + for (i=0;i<(3*8*Kr_bytes)+12;i++) + printf("%d : %d\n",i,harq_process->d[r][i]); + printf("\n"); +#endif + + + // printf("Clearing c, %p\n",harq_process->c[r]); + memset(harq_process->c[r],0,Kr_bytes); + + // printf("done\n"); + if (harq_process->C == 1) + crc_type = CRC24_A; + else + crc_type = CRC24_B; + + if (err_flag == 0) { + +#if gNB_TIMING_TRACE + start_meas(ulsch_turbo_decoding_stats); +#endif + + for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++) { + inv_d[cnt] = (1)*harq_process->d[r][cnt]; + } + + memset(pv,0,2*harq_process->Z*sizeof(int16_t)); + memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); + + for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } + + for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } + + for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) { + pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + } + + ////////////////////////////////////////////////////////////////////////////////////////// + + + ////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////// nrLDPC_decoder ///////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////// pl =====> llrProcBuf ////////////////////////////////// + + no_iteration_ldpc = nrLDPC_decoder(p_decParams, + (int8_t*)&pl[0], + llrProcBuf, + p_nrLDPC_procBuf[r], + p_procTime); + + if (check_crc(llrProcBuf,harq_process->B,harq_process->F,crc_type)) { + printf("CRC OK\n"); + ret = 2; + } else { + printf("CRC NOK\n"); + ret = 1+ulsch->max_ldpc_iterations; + } + + nb_total_decod++; + if (no_iteration_ldpc > ulsch->max_ldpc_iterations){ + nb_error_decod++; + } + + ret=no_iteration_ldpc; + + for (int m=0; m < Kr>>3; m ++) { + harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; + } + +#ifdef DEBUG_ULSCH_DECODING + //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); + for (int k=0;k>3;k++) + printf("output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); + printf("no_iterations_ldpc %d (ret %d)\n",no_iteration_ldpc,ret); + //write_output("dec_output.m","dec0",harq_process->c[0],Kr_bytes,1,4); +#endif + +#if gNB_TIMING_TRACE + stop_meas(ulsch_turbo_decoding_stats); +#endif + } + + if ((err_flag == 0) && (ret>=(1+ulsch->max_ldpc_iterations))) { + // a Code segment is in error so break; + LOG_D(PHY,"AbsSubframe %d.%d CRC failed, segment %d/%d \n",frame%1024,nr_tti_rx,r,harq_process->C-1); + err_flag = 1; + } + ////////////////////////////////////////////////////////////////////////////////////////// + } + + int32_t frame_rx_prev = frame; + int32_t tti_rx_prev = nr_tti_rx - 1; + if (tti_rx_prev < 0) { + frame_rx_prev--; + tti_rx_prev += 10*frame_parms->ttis_per_subframe; + } + frame_rx_prev = frame_rx_prev%1024; + + if (err_flag == 1) { + +#if gNB_DEBUG_TRACE + LOG_I(PHY,"[gNB %d] ULSCH: Setting NAK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d) Kr %d r %d harq_process->round %d\n", + phy_vars_gNB->Mod_id, frame, nr_tti_rx, harq_pid,harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs,Kr,r,harq_process->round); +#endif + + // harq_process->harq_ack.ack = 0; + // harq_process->harq_ack.harq_id = harq_pid; + // harq_process->harq_ack.send_harq_status = 1; + // harq_process->errors[harq_process->round]++; + harq_process->round++; + + if (harq_process->round >= ulsch->Mlimit) { + harq_process->status = SCH_IDLE; + harq_process->round = 0; + harq_process->handled = 0; + ulsch->harq_mask &= ~(1 << harq_pid); + } + + if(is_crnti) { + LOG_D(PHY,"[gNB %d] ULSCH: Setting NACK for nr_tti_rx %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n", + phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->status,harq_process->round,ulsch->Mlimit,harq_process->TBS); + } + + harq_process->handled = 1; + return((1+ulsch->max_ldpc_iterations)); + + } else { + +#if gNB_DEBUG_TRACE + LOG_I(PHY,"[gNB %d] ULSCH: Setting ACK for nr_tti_rx %d TBS %d mcs %d nb_rb %d harq_process->round %d\n", + phy_vars_gNB->Mod_id,nr_tti_rx,harq_process->TBS,harq_process->mcs,harq_process->nb_rb, harq_process->round); +#endif + + harq_process->status = SCH_IDLE; + harq_process->round = 0; + // harq_process->handled = 0; + ulsch->harq_mask &= ~(1 << harq_pid); + // harq_process->harq_ack.ack = 1; + // harq_process->harq_ack.harq_id = harq_pid; + // harq_process->harq_ack.send_harq_status = 1; + + if(is_crnti) + { + LOG_D(PHY,"[gNB %d] ULSCH: Setting ACK for nr_tti_rx %d (pid %d, round %d, TBS %d)\n",phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->round,harq_process->TBS); + } + } + + // Reassembly of Transport block here + offset = 0; + Kr = harq_process->K; + Kr_bytes = Kr>>3; + + for (r=0; rC; r++) { + + memcpy(harq_process->b+offset, + harq_process->c[r], + Kr_bytes- - (harq_process->F>>3) -((harq_process->C>1)?3:0)); + + offset += (Kr_bytes - (harq_process->F>>3) - ((harq_process->C>1)?3:0)); + +#ifdef DEBUG_ULSCH_DECODING + printf("Segment %d : Kr= %d bytes\n",r,Kr_bytes); + printf("copied %d bytes to b sequence (harq_pid %d)\n", + (Kr_bytes - (harq_process->F>>3)-((harq_process->C>1)?3:0)),harq_pid); + printf("b[0] = %x,c[%d] = %x\n", + harq_process->b[offset], + harq_process->F>>3, + harq_process->c[r]); +#endif + + } + + ulsch->last_iteration_cnt = ret; + + return(ret); +} \ No newline at end of file diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index 10b99eb113..24be9688dc 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -38,6 +38,10 @@ #include "CODING/nrPolar_tools/nr_polar_pbch_defs.h" #include "openair2/NR_PHY_INTERFACE/NR_IF_Module.h" #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h" +#include "PHY/impl_defs_top.h" +#include "PHY/defs_common.h" +#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h" +#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h" #define MAX_NUM_RU_PER_gNB MAX_NUM_RU_PER_eNB @@ -72,6 +76,7 @@ typedef struct { uint64_t dci_pdu[2]; } NR_gNB_DCI_ALLOC_t; + typedef struct { uint8_t num_dci; uint8_t num_pdsch_rnti; @@ -79,6 +84,14 @@ typedef struct { } NR_gNB_PDCCH; +typedef enum { + NR_SCH_IDLE, + NR_ACTIVE, + NR_CBA_ACTIVE, + NR_DISABLED +} NR_SCH_status_t; + + typedef struct { /// Nfapi DLSCH PDU nfapi_nr_dl_config_dlsch_pdu dlsch_pdu; @@ -114,7 +127,6 @@ typedef struct { typedef struct { - /// Pointers to 16 HARQ processes for the DLSCH NR_DL_gNB_HARQ_t *harq_processes[NR_MAX_NB_HARQ_PROCESSES]; /// TX buffers for UE-spec transmission (antenna ports 5 or 7..14, prior to precoding) @@ -160,6 +172,170 @@ typedef struct { } NR_gNB_DLSCH_t; +typedef struct { + /// Nfapi ULSCH PDU + nfapi_nr_ul_config_ulsch_pdu ulsch_pdu; + /// Frame where current HARQ round was sent + uint32_t frame; + /// Subframe where current HARQ round was sent + uint32_t subframe; + /// Index of current HARQ round for this DLSCH + uint8_t round; + /// Last TPC command + uint8_t TPC; + /// MIMO mode for this DLSCH + MIMO_mode_t mimo_mode; + /// Flag indicating that this ULSCH has been allocated by a DCI (otherwise it is a retransmission based on PHICH NAK) + uint8_t dci_alloc; + /// Flag indicating that this ULSCH has been allocated by a RAR (otherwise it is a retransmission based on PHICH NAK or DCI) + uint8_t rar_alloc; + /// Status Flag indicating for this ULSCH (idle,active,disabled) + NR_SCH_status_t status; + /// Subframe scheduling indicator (i.e. Transmission opportunity indicator) + uint8_t subframe_scheduling_flag; + /// Subframe cba scheduling indicator (i.e. CBA Transmission opportunity indicator) + uint8_t subframe_cba_scheduling_flag; + /// PHICH active flag + uint8_t phich_active; + /// PHICH ACK + uint8_t phich_ACK; + /// First Allocated RB - previous scheduling. This is needed for PHICH generation which is done after a new scheduling + uint16_t previous_first_rb; + /// Flag to indicate that the UL configuration has been handled. Used to remove a stale ULSCH when frame wraps around + uint8_t handled; + /// Flag to indicate that this ULSCH is for calibration information sent from UE (i.e. no MAC SDU to pass up) + // int calibration_flag; + /// delta_TF for power control + int32_t delta_TF; + + + /////////////////////// ulsch decoding /////////////////////// + /// Transport block size (This is A from 38.212 V15.4.0 section 5.1) + uint32_t TBS; + /// Pointer to the payload (38.212 V15.4.0 section 5.1) + uint8_t *b; + /// The payload + CRC (24 bits) in bits (38.212 V15.4.0 section 5.1) + uint32_t B; + /// Pointers to code blocks after code block segmentation and CRC attachment (38.212 V15.4.0 section 5.2.2) + uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// Number of bits in each code block (38.212 V15.4.0 section 5.2.2) + uint32_t K; + /// Number of "Filler" bits added in the code block segmentation (38.212 V15.4.0 section 5.2.2) + uint32_t F; + /// Number of code blocks after code block segmentation (38.212 V15.4.0 section 5.2.2) + uint32_t C; + /// Pointers to code blocks after LDPC coding (38.212 V15.4.0 section 5.3.2) + int16_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC processing buffer + t_nrLDPC_procBuf* p_nrLDPC_procBuf[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC lifting size (38.212 V15.4.0 table 5.3.2-1) + uint32_t Z; + /// code blocks after bit selection in rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1) + int16_t e[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; + /// Number of bits in each code block after rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1) + uint32_t E; + /// Number of soft channel bits after code block concatenation (38.212 V15.4.0 section 5.5) + uint32_t G; + ////////////////////////////////////////////////////////////// + + + /////////////////////////// DMRS ///////////////////////////// + /// n_DMRS for cyclic shift of DMRS (36.213 Table 9.1.2-2) + uint8_t n_DMRS; + /// n_DMRS 2 for cyclic shift of DMRS (36.211 Table 5.5.1.1.-1) + uint8_t n_DMRS2; + /// n_DMRS for cyclic shift of DMRS (36.213 Table 9.1.2-2) - previous scheduling + /// This is needed for PHICH generation which + /// is done after a new scheduling + uint8_t previous_n_DMRS; + ////////////////////////////////////////////////////////////// + + + ///////////////////// UCI multiplexing /////////////////////// + /// CQI CRC status + uint8_t cqi_crc_status; + /// Pointer to CQI data + uint8_t o[MAX_CQI_BYTES]; + /// Format of CQI data + UCI_format_t uci_format; + /// Length of CQI data under RI=1 assumption(bits) + uint8_t Or1; + /// Length of CQI data under RI=2 assumption(bits) + uint8_t Or2; + /// Rank information + uint8_t o_RI[2]; + /// Length of rank information (bits) + uint8_t O_RI; + /// Pointer to ACK + uint8_t o_ACK[4]; + /// Length of ACK information (bits) + uint8_t O_ACK; + /// The value of DAI in DCI format 0 + uint8_t V_UL_DAI; + /// "q" sequences for CQI/PMI (for definition see 36-212 V8.6 2009-03, p.27) + int8_t q[MAX_CQI_PAYLOAD]; + /// number of coded CQI bits after interleaving + uint8_t o_RCC; + /// coded and interleaved CQI bits + int8_t o_w[(MAX_CQI_BITS+8)*3]; + /// coded CQI bits + int8_t o_d[96+((MAX_CQI_BITS+8)*3)]; + /// coded ACK bits + int16_t q_ACK[MAX_ACK_PAYLOAD]; + /// coded RI bits + int16_t q_RI[MAX_RI_PAYLOAD]; + /// Temporary h sequence to flag PUSCH_x/PUSCH_y symbols which are not scrambled + uint8_t h[MAX_NUM_CHANNEL_BITS]; + /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) + int16_t w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)]; + ////////////////////////////////////////////////////////////// +} NR_UL_gNB_HARQ_t; + + +typedef struct { + /// Pointers to 16 HARQ processes for the ULSCH + NR_UL_gNB_HARQ_t *harq_processes[NR_MAX_ULSCH_HARQ_PROCESSES]; + /// Current HARQ process id + int harq_process_id[NR_MAX_SLOTS_PER_FRAME]; + /// HARQ process mask, indicates which processes are currently active + uint16_t harq_mask; + /// ACK/NAK Bundling flag + uint8_t bundling; + /// beta_offset_cqi times 8 + uint16_t beta_offset_cqi_times8; + /// beta_offset_ri times 8 + uint16_t beta_offset_ri_times8; + /// beta_offset_harqack times 8 + uint16_t beta_offset_harqack_times8; + /// Flag to indicate that gNB awaits UE Msg3 + uint8_t Msg3_active; + /// Flag to indicate that gNB should decode UE Msg3 + uint8_t Msg3_flag; + /// Subframe for Msg3 + uint8_t Msg3_subframe; + /// Frame for Msg3 + uint32_t Msg3_frame; + /// Allocated RNTI for this ULSCH + uint16_t rnti; + /// RNTI type + uint8_t rnti_type; + /// cyclic shift for DM RS + uint8_t cyclicShift; + /// for cooperative communication + uint8_t cooperation_flag; + /// Maximum number of HARQ rounds + uint8_t Mlimit; + /// Maximum number of LDPC iterations + uint8_t max_ldpc_iterations; + /// number of iterations used in last LDPC decoding + uint8_t last_iteration_cnt; + /// num active cba group + uint8_t num_active_cba_groups; + /// num active cba group + uint16_t cba_rnti[NUM_MAX_CBA_GROUP]; +} NR_gNB_ULSCH_t; + + typedef struct { /// \brief Pointers (dynamic) to the received data in the time domain. /// - first index: rx antenna [0..nb_antennas_rx[ @@ -394,17 +570,18 @@ typedef struct PHY_VARS_gNB_s { LTE_eNB_PHICH phich_vars[2]; NR_gNB_COMMON common_vars; - LTE_eNB_UCI uci_vars[NUMBER_OF_UE_MAX]; - LTE_eNB_SRS srs_vars[NUMBER_OF_UE_MAX]; - LTE_eNB_PUSCH *pusch_vars[NUMBER_OF_UE_MAX]; - LTE_eNB_PRACH prach_vars; - NR_gNB_DLSCH_t *dlsch[NUMBER_OF_UE_MAX][2]; // Nusers times two spatial streams - LTE_eNB_ULSCH_t *ulsch[NUMBER_OF_UE_MAX+1]; // Nusers + number of RA + LTE_eNB_UCI uci_vars[NUMBER_OF_UE_MAX]; + LTE_eNB_SRS srs_vars[NUMBER_OF_UE_MAX]; + LTE_eNB_PUSCH *pusch_vars[NUMBER_OF_UE_MAX]; + LTE_eNB_PRACH prach_vars; + NR_gNB_DLSCH_t *dlsch[NUMBER_OF_UE_MAX][2]; // Nusers times two spatial streams + NR_gNB_ULSCH_t *ulsch[NUMBER_OF_UE_MAX+1][2]; // [Nusers times + number of RA][2 codewords], index 0 in [NUMBER_OF_UE_MAX+1] is for RA + // LTE_eNB_ULSCH_t *ulsch[NUMBER_OF_UE_MAX+1]; // Nusers + number of RA NR_gNB_DLSCH_t *dlsch_SI,*dlsch_ra,*dlsch_p; NR_gNB_DLSCH_t *dlsch_MCH; NR_gNB_DLSCH_t *dlsch_PCH; - LTE_eNB_UE_stats UE_stats[NUMBER_OF_UE_MAX]; - LTE_eNB_UE_stats *UE_stats_ptr[NUMBER_OF_UE_MAX]; + LTE_eNB_UE_stats UE_stats[NUMBER_OF_UE_MAX]; + LTE_eNB_UE_stats *UE_stats_ptr[NUMBER_OF_UE_MAX]; uint8_t pbch_configured; uint8_t pbch_pdu[4]; //PBCH_PDU_SIZE From e5fd0fcd00328c50b10fbf118500f039857f9c7c Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Mar 2019 17:42:06 +0100 Subject: [PATCH 028/117] added the ulsch decoding functions to ulschsim.c now ulschsim.c is uplink only with no downlink decoding functions or variables --- openair1/PHY/INIT/nr_init.c | 69 +- openair1/SIMULATION/NR_PHY/ulschsim.c | 1207 +++++++++++++------------ 2 files changed, 646 insertions(+), 630 deletions(-) diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 46e3010972..1a2382b526 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -33,6 +33,7 @@ #include "assertions.h" #include +#include "PHY/NR_TRANSPORT/nr_ulsch.h" #include "PHY/NR_REFSIG/nr_refsig.h" #include "PHY/LTE_REFSIG/lte_refsig.h" #include "SCHED_NR/fapi_nr_l1.h" @@ -77,12 +78,14 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, unsigned char abstraction_flag) { // shortcuts NR_DL_FRAME_PARMS *const fp = &gNB->frame_parms; - nfapi_nr_config_request_t *cfg = &gNB->gNB_config; + nfapi_nr_config_request_t *cfg = &gNB->gNB_config; NR_gNB_COMMON *const common_vars = &gNB->common_vars; - LTE_eNB_PUSCH **const pusch_vars = gNB->pusch_vars; - LTE_eNB_SRS *const srs_vars = gNB->srs_vars; - LTE_eNB_PRACH *const prach_vars = &gNB->prach_vars; + LTE_eNB_PUSCH **const pusch_vars = gNB->pusch_vars; + LTE_eNB_SRS *const srs_vars = gNB->srs_vars; + LTE_eNB_PRACH *const prach_vars = &gNB->prach_vars; + int i, UE_id; + LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__); gNB->total_dlsch_bitrate = 0; gNB->total_transmitted_bits = 0; @@ -110,7 +113,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, init_dfts(); // PBCH DMRS gold sequences generation nr_init_pbch_dmrs(gNB); - // Polar encoder init for PBCH //PDCCH DMRS init gNB->nr_gold_pdcch_dmrs = (uint32_t ***)malloc16(fp->slots_per_frame*sizeof(uint32_t **)); uint32_t ***pdcch_dmrs = gNB->nr_gold_pdcch_dmrs; @@ -148,6 +150,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, } nr_init_pdsch_dmrs(gNB, cfg->sch_config.physical_cell_id.value); + /// Transport init necessary for NR synchro init_nr_transport(gNB); @@ -167,14 +170,15 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB, gNB->first_run_I0_measurements = 1; ///This flag used to be static. With multiple gNBs this does no longer work, hence we put it in the structure. However it has to be initialized with 1, which is performed here. common_vars->rxdata = (int32_t **)NULL; - common_vars->txdataF = (int32_t **)malloc16(15*sizeof(int32_t *)); - common_vars->rxdataF = (int32_t **)malloc16(64*sizeof(int32_t *)); + common_vars->txdataF = (int32_t **)malloc16(15*sizeof(int32_t*)); + common_vars->rxdataF = (int32_t **)malloc16(64*sizeof(int32_t*)); - for (i=0; i<15; i++) { - common_vars->txdataF[i] = (int32_t *)malloc16_clear(fp->samples_per_frame_wCP*sizeof(int32_t) ); - LOG_D(PHY,"[INIT] common_vars->txdataF[%d] = %p (%lu bytes)\n", - i,common_vars->txdataF[i], - fp->samples_per_frame_wCP*sizeof(int32_t)); + for (i=0;i<15;i++){ + common_vars->txdataF[i] = (int32_t*)malloc16_clear(fp->samples_per_frame_wCP*sizeof(int32_t) ); // [hna] samples_per_frame without CP + + LOG_D(PHY,"[INIT] common_vars->txdataF[%d] = %p (%lu bytes)\n", + i,common_vars->txdataF[i], + fp->samples_per_frame_wCP*sizeof(int32_t)); } // Channel estimates for SRS @@ -417,6 +421,7 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config) { gNB_config->rf_config.ul_carrier_bandwidth.value, gNB_config->sch_config.physical_cell_id.value, fp->dl_CarrierFreq ); + nr_init_frame_parms(gNB_config, fp); if (RC.gNB[Mod_id][CC_id]->configured == 1) { @@ -436,6 +441,7 @@ void init_nr_transport(PHY_VARS_gNB *gNB) { LOG_I(PHY, "Initialise nr transport\n"); for (i=0; idlsch[i][j]->rnti=0; - LOG_D(PHY,"dlsch[%d][%d] => %p rnti:%d\n",i,j,gNB->dlsch[i][j], gNB->dlsch[i][j]->rnti); + gNB->dlsch[i][j]->rnti=0; + LOG_D(PHY,"dlsch[%d][%d] => %p rnti:%d\n",i,j,gNB->dlsch[i][j], gNB->dlsch[i][j]->rnti); }*/ + + ///////////////////////// Initializing gNB ULSCH ///////////////////////// + LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i); + + // ULSCH for RA + if(i==0) { + gNB->ulsch[i][j] = new_gNB_ulsch(5, fp->N_RB_UL, 0); + + if (!gNB->ulsch[i][j]) { + LOG_E(PHY,"Can't get gNB ulsch structures\n"); + exit(-1); + } + } + + // ULSCH for data + gNB->ulsch[i+1][j] = new_gNB_ulsch(5, fp->N_RB_UL, 0); + + if (!gNB->ulsch[i+1][j]) { + LOG_E(PHY,"Can't get gNB ulsch structures\n"); + exit(-1); + } + ////////////////////////////////////////////////////////////////////////// } - //LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i); - //gNB->ulsch[1+i] = new_gNB_ulsch(MAX_TURBO_ITERATIONS,fp->N_RB_UL, 0); - /*if (!gNB->ulsch[1+i]) { - LOG_E(PHY,"Can't get gNB ulsch structures\n"); - exit(-1); - }*/ // this is the transmission mode for the signalling channels // this will be overwritten with the real transmission mode by the RRC once the UE is connected //gNB->transmission_mode[i] = fp->nb_antenna_ports_gNB==1 ? 1 : 2; } - // ULSCH for RA - //gNB->ulsch[0] = new_gNB_ulsch(MAX_TURBO_ITERATIONS, fp->N_RB_UL, 0); - /*if (!gNB->ulsch[0]) { - LOG_E(PHY,"Can't get gNB ulsch structures\n"); - exit(-1); - }*/ gNB->dlsch_SI = new_gNB_dlsch(1,8,NSOFT, 0, fp, cfg); LOG_D(PHY,"gNB %d.%d : SI %p\n",gNB->Mod_id,gNB->CC_id,gNB->dlsch_SI); gNB->dlsch_ra = new_gNB_dlsch(1,8,NSOFT, 0, fp, cfg); diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index de3bd2fe62..9b0c3562af 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -1,23 +1,23 @@ /* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ +* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The OpenAirInterface Software Alliance licenses this file to You under +* the OAI Public License, Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.openairinterface.org/?page_id=698 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*------------------------------------------------------------------------------- +* For more information about the OpenAirInterface (OAI) Software Alliance: +* contact@openairinterface.org +*/ #include #include @@ -32,6 +32,7 @@ #include "SIMULATION/TOOLS/sim.h" #include "SIMULATION/RF/rf.h" + #include "PHY/types.h" #include "PHY/defs_nr_common.h" #include "PHY/defs_nr_UE.h" @@ -43,6 +44,7 @@ #include "PHY/MODULATION/modulation_UE.h" #include "PHY/NR_TRANSPORT/nr_transport.h" #include "PHY/NR_TRANSPORT/nr_dlsch.h" +#include "PHY/NR_TRANSPORT/nr_ulsch.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED_NR/sched_nr.h" @@ -63,41 +65,40 @@ double cpuf; // dummy functions int nfapi_mode = 0; int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { - return (0); + return (0); } int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { - return (0); + return (0); } int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { - return (0); + return (0); } int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { - return (0); + return (0); } int oai_nfapi_nr_dl_config_req(nfapi_nr_dl_config_request_t *dl_config_req) { - return (0); + return (0); } uint32_t from_nrarfcn(int nr_bandP, uint32_t dl_earfcn) { - return (0); + return (0); } int32_t get_uldl_offset(int eutra_bandP) { - return (0); + return (0); } NR_IF_Module_t * NR_IF_Module_init(int Mod_id) { - return (NULL); + return (NULL); } -void exit_function(const char *file, const char *function, const int line, - const char *s) { - const char *msg = s == NULL ? "no comment" : s; - printf("Exiting at: %s:%d %s(), %s\n", file, line, function, msg); - exit(-1); +void exit_function(const char *file, const char *function, const int line, const char *s) { + const char *msg = s == NULL ? "no comment" : s; + printf("Exiting at: %s:%d %s(), %s\n", file, line, function, msg); + exit(-1); } // needed for some functions @@ -105,631 +106,631 @@ PHY_VARS_NR_UE *PHY_vars_UE_g[1][1] = { { NULL } }; uint16_t n_rnti = 0x1234; char quantize(double D, double x, unsigned char B) { - double qxd; - short maxlev; - qxd = floor(x / D); - maxlev = 1 << (B - 1); //(char)(pow(2,B-1)); + double qxd; + short maxlev; + qxd = floor(x / D); + maxlev = 1 << (B - 1); //(char)(pow(2,B-1)); - //printf("x=%f,qxd=%f,maxlev=%d\n",x,qxd, maxlev); + //printf("x=%f,qxd=%f,maxlev=%d\n",x,qxd, maxlev); - if (qxd <= -maxlev) - qxd = -maxlev; - else if (qxd >= maxlev) - qxd = maxlev - 1; + if (qxd <= -maxlev) + qxd = -maxlev; + else if (qxd >= maxlev) + qxd = maxlev - 1; - return ((char) qxd); + return ((char) qxd); } int main(int argc, char **argv) { - char c; - int i,sf; //,j,l,aa; - double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0; - double snr_step = 0.1; - uint8_t snr1set = 0; - int **txdata; - double **s_re, **s_im, **r_re, **r_im; - // int sync_pos, sync_pos_slot; - // FILE *rx_frame_file; - FILE *output_fd = NULL; - uint8_t write_output_file = 0; - // int subframe_offset; - // char fname[40], vname[40]; - int trial, n_trials = 1, n_errors = 0, n_false_positive = 0; - uint8_t transmission_mode = 1, n_tx = 1, n_rx = 1; - uint16_t Nid_cell = 0; - channel_desc_t *gNB2UE; - uint8_t extended_prefix_flag = 0; - int8_t interf1 = -21, interf2 = -21; - FILE *input_fd = NULL, *pbch_file_fd = NULL; - //char input_val_str[50],input_val_str2[50]; - //uint16_t NB_RB=25; - SCM_t channel_model = AWGN; //Rayleigh1_anticorr; - uint16_t N_RB_DL = 106, N_RB_UL = 106, mu = 1; - unsigned char frame_type = 0; - unsigned char pbch_phase = 0; - int frame = 0, subframe = 0; - int frame_length_complex_samples; - //int frame_length_complex_samples_no_prefix; - NR_DL_FRAME_PARMS *frame_parms; - //nfapi_nr_config_request_t *gNB_config; - uint8_t Kmimo = 0; - uint32_t Nsoft = 0; - double sigma; - unsigned char qbits = 8; - int ret; - //int run_initial_sync=0; - int loglvl = OAILOG_WARNING; - float target_error_rate = 0.01; - - uint16_t nb_symb_sch = 12; - uint16_t nb_rb = 50; - uint8_t Imcs = 9; - - cpuf = get_cpu_freq_GHz(); - - if (load_configmodule(argc, argv) == 0) { - exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); - } - - //logInit(); - randominit(0); - - while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:N:F:R:P:")) != -1) { - switch (c) { - case 'f': - write_output_file = 1; - output_fd = fopen(optarg, "w"); - - if (output_fd == NULL) { - printf("Error opening %s\n", optarg); - exit(-1); - } - - break; - - case 'd': - frame_type = 1; - break; - - case 'g': - switch ((char) *optarg) { - case 'A': - channel_model = SCM_A; - break; - - case 'B': - channel_model = SCM_B; - break; - - case 'C': - channel_model = SCM_C; - break; - - case 'D': - channel_model = SCM_D; - break; - - case 'E': - channel_model = EPA; - break; - - case 'F': - channel_model = EVA; - break; - - case 'G': - channel_model = ETU; - break; - - default: - msg("Unsupported channel model!\n"); - exit(-1); - } - - break; - - case 'i': - interf1 = atoi(optarg); - break; - - case 'j': - interf2 = atoi(optarg); - break; - - case 'n': - n_trials = atoi(optarg); - break; - - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n", snr0); - break; - - case 'S': - snr1 = atof(optarg); - snr1set = 1; - msg("Setting SNR1 to %f\n", snr1); - break; - - case 'p': - extended_prefix_flag = 1; - break; - - /* - case 'r': - ricean_factor = pow(10,-.1*atof(optarg)); - if (ricean_factor>1) { - printf("Ricean factor must be between 0 and 1\n"); - exit(-1); - } - break; - */ - - case 'y': - n_tx = atoi(optarg); - - if ((n_tx == 0) || (n_tx > 2)) { - msg("Unsupported number of tx antennas %d\n", n_tx); - exit(-1); - } - - break; - - case 'z': - n_rx = atoi(optarg); - - if ((n_rx == 0) || (n_rx > 2)) { - msg("Unsupported number of rx antennas %d\n", n_rx); - exit(-1); - } - - break; - - case 'N': - Nid_cell = atoi(optarg); - break; - - case 'R': - N_RB_DL = atoi(optarg); - N_RB_UL = N_RB_DL; - break; - - case 'F': - input_fd = fopen(optarg, "r"); - - if (input_fd == NULL) { - printf("Problem with filename %s\n", optarg); - exit(-1); - } - - break; - - case 'P': - pbch_phase = atoi(optarg); - - if (pbch_phase > 3) - printf("Illegal PBCH phase (0-3) got %d\n", pbch_phase); - - break; - - case 'm': - Imcs = atoi(optarg); - break; - - case 'l': - nb_symb_sch = atoi(optarg); - break; - - case 'r': - nb_rb = atoi(optarg); - break; - - case 'x': - transmission_mode = atoi(optarg); - break; - - default: - case 'h': - printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); - printf("-h This message\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); - printf("-n Number of frames to simulate\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-N Nid_cell\n"); - printf("-R N_RB_DL\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit(-1); - break; - } - } - - logInit(); - set_glog(loglvl); - T_stdout = 1; - - if (snr1set == 0) - snr1 = snr0 + 10; - - gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, - 61.44e6, //N_RB2sampling_rate(N_RB_DL), - 40e6, //N_RB2channel_bandwidth(N_RB_DL), - 0, 0, 0); - - if (gNB2UE == NULL) { - msg("Problem generating channel model. Exiting.\n"); - exit(-1); - } - - RC.gNB = (PHY_VARS_gNB ** *) malloc(sizeof(PHY_VARS_gNB **)); - RC.gNB[0] = (PHY_VARS_gNB **) malloc(sizeof(PHY_VARS_gNB *)); - RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB)); - gNB = RC.gNB[0][0]; - //gNB_config = &gNB->gNB_config; - frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH) - frame_parms->nb_antennas_tx = n_tx; - frame_parms->nb_antennas_rx = n_rx; - frame_parms->N_RB_DL = N_RB_DL; - frame_parms->N_RB_UL = N_RB_UL; - frame_parms->Ncp = extended_prefix_flag ? EXTENDED : NORMAL; - crcTableInit(); - nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell); - phy_init_nr_gNB(gNB, 0, 0); - //init_eNB_afterRU(); - frame_length_complex_samples = frame_parms->samples_per_subframe; - //frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP; - s_re = malloc(2 * sizeof(double *)); - s_im = malloc(2 * sizeof(double *)); - r_re = malloc(2 * sizeof(double *)); - r_im = malloc(2 * sizeof(double *)); - txdata = malloc(2 * sizeof(int *)); - - for (i = 0; i < 2; i++) { - s_re[i] = malloc(frame_length_complex_samples * sizeof(double)); - bzero(s_re[i], frame_length_complex_samples * sizeof(double)); - s_im[i] = malloc(frame_length_complex_samples * sizeof(double)); - bzero(s_im[i], frame_length_complex_samples * sizeof(double)); - r_re[i] = malloc(frame_length_complex_samples * sizeof(double)); - bzero(r_re[i], frame_length_complex_samples * sizeof(double)); - r_im[i] = malloc(frame_length_complex_samples * sizeof(double)); - bzero(r_im[i], frame_length_complex_samples * sizeof(double)); - txdata[i] = malloc(frame_length_complex_samples * sizeof(int)); - bzero(r_re[i], frame_length_complex_samples * sizeof(int)); - } - - if (pbch_file_fd != NULL) { - load_pbch_desc(pbch_file_fd); - } - - /* for (int k=0; k<2; k++) { - // Create transport channel structures for 2 transport blocks (MIMO) - for (i=0; i<2; i++) { - gNB->dlsch[k][i] = new_gNB_dlsch(Kmimo,8,Nsoft,0,frame_parms,gNB_config); - - if (!gNB->dlsch[k][i]) { - printf("Can't get eNB dlsch structures\n"); - exit(-1); - } - gNB->dlsch[k][i]->Nsoft = 10; - gNB->dlsch[k][i]->rnti = n_rnti+k; - } - }*/ - //configure UE - UE = malloc(sizeof(PHY_VARS_NR_UE)); - memcpy(&UE->frame_parms, frame_parms, sizeof(NR_DL_FRAME_PARMS)); - - //phy_init_nr_top(frame_parms); - if (init_nr_ue_signal(UE, 1, 0) != 0) { - printf("Error at UE NR initialisation\n"); - exit(-1); - } - - //nr_init_frame_parms_ue(&UE->frame_parms); - //init_nr_ue_transport(UE, 0); - for (sf = 0; sf < 2; sf++) { - for (i = 0; i < 2; i++) { - UE->dlsch[sf][0][i] = new_nr_ue_dlsch(Kmimo, 8, Nsoft, 5, N_RB_DL, - 0); - - if (!UE->dlsch[sf][0][i]) { - printf("Can't get ue dlsch structures\n"); - exit(-1); - } - - UE->ulsch[sf][0][i] = new_nr_ue_ulsch(N_RB_UL, 8, 0); - - if (!UE->ulsch[sf][0][i]) { - printf("Can't get ue ulsch structures\n"); - exit(-1); - } - - UE->dlsch[sf][0][i]->rnti = n_rnti; - } - } - - UE->dlsch_SI[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); - UE->dlsch_ra[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); - unsigned char harq_pid = 0; //dlsch->harq_ids[subframe]; - NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0]; - nfapi_nr_dl_config_dlsch_pdu_rel15_t *rel15 = &dlsch->harq_processes[harq_pid]->dlsch_pdu.dlsch_pdu_rel15; - - NR_UE_ULSCH_t *ulsch = UE->ulsch[0][0][0]; - - //time_stats_t *rm_stats, *te_stats, *i_stats; - uint8_t is_crnti = 0, llr8_flag = 0; - unsigned int TBS = 8424; - unsigned int available_bits; - uint8_t nb_re_dmrs = 6; - uint16_t length_dmrs = 1; - unsigned char mod_order; - uint8_t Nl = 1; - uint8_t rvidx = 0; - dlsch->rnti = 1; - ulsch->nb_re_dmrs = nb_re_dmrs; //[adk] A HOT FIX until cearting nfapi_nr_ul_config_ulsch_pdu_rel15_t - /*dlsch->harq_processes[0]->mcs = Imcs; - dlsch->harq_processes[0]->rvidx = rvidx;*/ - //printf("dlschsim harqid %d nb_rb %d, mscs %d\n",dlsch->harq_ids[subframe], - // dlsch->harq_processes[0]->nb_rb,dlsch->harq_processes[0]->mcs,dlsch->harq_processes[0]->Nl); - mod_order = nr_get_Qm(Imcs, 1); - available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1); - TBS = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, Nl); - printf("available bits %d TBS %d mod_order %d\n", available_bits, TBS, mod_order); - //dlsch->harq_ids[subframe]= 0; - rel15->n_prb = nb_rb; - rel15->nb_symbols = nb_symb_sch; - rel15->modulation_order = mod_order; - rel15->nb_layers = Nl; - rel15->nb_re_dmrs = nb_re_dmrs; - rel15->transport_block_size = TBS; - double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); - short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); - short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); - unsigned int errors_bit_uncoded = 0; - unsigned char *estimated_output; - unsigned char *estimated_output_bit; - unsigned char *test_input_bit; - unsigned int errors_bit = 0; - - test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - - estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - - estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - - NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; - NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; - harq_process->mcs = Imcs; - harq_process->Nl = Nl; - harq_process->nb_rb = nb_rb; - harq_process->Qm = mod_order; - harq_process->rvidx = rvidx; - printf("harq process ue mcs = %d Qm = %d, symb %d\n", harq_process->mcs, harq_process->Qm, nb_symb_sch); - unsigned char *test_input; - test_input = (unsigned char *) malloc16(sizeof(unsigned char) * TBS / 8); - - for (i = 0; i < TBS / 8; i++) - test_input[i] = (unsigned char) rand(); - - estimated_output = harq_process->b; - - - /////////////////////////[adk] preparing UL harq_process parameters///////////////////////// - /////////// - NR_UL_UE_HARQ_t *harq_process_ul_ue = ulsch->harq_processes[harq_pid]; - - if (harq_process_ul_ue){ - - harq_process_ul_ue->mcs = Imcs; - harq_process_ul_ue->Nl = Nl; - harq_process_ul_ue->nb_rb = nb_rb; - harq_process_ul_ue->nb_symbols = nb_symb_sch; - harq_process_ul_ue->rvidx = rvidx; - harq_process_ul_ue->TBS = TBS; - harq_process_ul_ue->a = &test_input[0]; - - } - /////////// - //////////////////////////////////////////////////////////////////////////////////////////// + char c; + int i,sf; //,j,l,aa; + double SNR, SNR_lin, snr0 = -2.0, snr1 = 2.0; + double snr_step = 0.1; + uint8_t snr1set = 0; + int **txdata; + double **s_re, **s_im, **r_re, **r_im; + // int sync_pos, sync_pos_slot; + // FILE *rx_frame_file; + FILE *output_fd = NULL; + uint8_t write_output_file = 0; + // int subframe_offset; + // char fname[40], vname[40]; + int trial, n_trials = 1, n_errors = 0, n_false_positive = 0; + uint8_t transmission_mode = 1, n_tx = 1, n_rx = 1; + uint16_t Nid_cell = 0; + channel_desc_t *gNB2UE; + uint8_t extended_prefix_flag = 0; + int8_t interf1 = -21, interf2 = -21; + FILE *input_fd = NULL, *pbch_file_fd = NULL; + //char input_val_str[50],input_val_str2[50]; + //uint16_t NB_RB=25; + SCM_t channel_model = AWGN; //Rayleigh1_anticorr; + uint8_t N_RB_DL = 106, N_RB_UL = 106, mu = 1; + unsigned char frame_type = 0; + unsigned char pbch_phase = 0; + int frame = 0, subframe = 0; + int frame_length_complex_samples; + //int frame_length_complex_samples_no_prefix; + NR_DL_FRAME_PARMS *frame_parms; + //nfapi_nr_config_request_t *gNB_config; + // uint8_t Kmimo = 0; + uint32_t Nsoft = 0; + double sigma; + unsigned char qbits = 8; + int ret; + //int run_initial_sync=0; + int loglvl = OAILOG_WARNING; + float target_error_rate = 0.01; + + uint16_t nb_symb_sch = 12; + uint16_t nb_rb = 50; + uint8_t Imcs = 9; + + cpuf = get_cpu_freq_GHz(); + + if (load_configmodule(argc, argv) == 0) { + exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); + } + + //logInit(); + randominit(0); + + while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:N:F:R:P:")) != -1) { + switch (c) { + case 'f': + write_output_file = 1; + output_fd = fopen(optarg, "w"); + + if (output_fd == NULL) { + printf("Error opening %s\n", optarg); + exit(-1); + } + + break; + + case 'd': + frame_type = 1; + break; + + case 'g': + switch ((char) *optarg) { + case 'A': + channel_model = SCM_A; + break; + + case 'B': + channel_model = SCM_B; + break; + + case 'C': + channel_model = SCM_C; + break; + + case 'D': + channel_model = SCM_D; + break; + + case 'E': + channel_model = EPA; + break; + + case 'F': + channel_model = EVA; + break; + + case 'G': + channel_model = ETU; + break; + + default: + msg("Unsupported channel model!\n"); + exit(-1); + } + + break; + + case 'i': + interf1 = atoi(optarg); + break; + + case 'j': + interf2 = atoi(optarg); + break; + + case 'n': + n_trials = atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n", snr0); + break; + + case 'S': + snr1 = atof(optarg); + snr1set = 1; + msg("Setting SNR1 to %f\n", snr1); + break; + + case 'p': + extended_prefix_flag = 1; + break; + + /* + case 'r': + ricean_factor = pow(10,-.1*atof(optarg)); + if (ricean_factor>1) { + printf("Ricean factor must be between 0 and 1\n"); + exit(-1); + } + break; + */ + + case 'y': + n_tx = atoi(optarg); + + if ((n_tx == 0) || (n_tx > 2)) { + msg("Unsupported number of tx antennas %d\n", n_tx); + exit(-1); + } + + break; + + case 'z': + n_rx = atoi(optarg); + + if ((n_rx == 0) || (n_rx > 2)) { + msg("Unsupported number of rx antennas %d\n", n_rx); + exit(-1); + } + + break; + + case 'N': + Nid_cell = atoi(optarg); + break; + + case 'R': + N_RB_DL = atoi(optarg); + N_RB_UL = N_RB_DL; + break; + + case 'F': + input_fd = fopen(optarg, "r"); + + if (input_fd == NULL) { + printf("Problem with filename %s\n", optarg); + exit(-1); + } + + break; + + case 'P': + pbch_phase = atoi(optarg); + + if (pbch_phase > 3) + printf("Illegal PBCH phase (0-3) got %d\n", pbch_phase); + + break; + + case 'm': + Imcs = atoi(optarg); + break; + + case 'l': + nb_symb_sch = atoi(optarg); + break; + + case 'r': + nb_rb = atoi(optarg); + break; + + case 'x': + transmission_mode = atoi(optarg); + break; + + default: + case 'h': + printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); + printf("-h This message\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit(-1); + break; + } + } + + logInit(); + set_glog(loglvl); + T_stdout = 1; + + if (snr1set == 0) + snr1 = snr0 + 10; + + gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, 61.44e6, //N_RB2sampling_rate(N_RB_DL), + 40e6, //N_RB2channel_bandwidth(N_RB_DL), + 0, 0, 0); + + if (gNB2UE == NULL) { + msg("Problem generating channel model. Exiting.\n"); + exit(-1); + } + + RC.gNB = (PHY_VARS_gNB ** *) malloc(sizeof(PHY_VARS_gNB **)); + RC.gNB[0] = (PHY_VARS_gNB **) malloc(sizeof(PHY_VARS_gNB *)); + RC.gNB[0][0] = malloc(sizeof(PHY_VARS_gNB)); + gNB = RC.gNB[0][0]; + //gNB_config = &gNB->gNB_config; + + frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH) + frame_parms->nb_antennas_tx = n_tx; + frame_parms->nb_antennas_rx = n_rx; + frame_parms->N_RB_DL = N_RB_DL; + frame_parms->N_RB_UL = N_RB_UL; + frame_parms->Ncp = extended_prefix_flag ? EXTENDED : NORMAL; + + crcTableInit(); + + nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell); + + phy_init_nr_gNB(gNB, 0, 0); + //init_eNB_afterRU(); + + frame_length_complex_samples = frame_parms->samples_per_subframe; + //frame_length_complex_samples_no_prefix = frame_parms->samples_per_subframe_wCP; + s_re = malloc(2 * sizeof(double *)); + s_im = malloc(2 * sizeof(double *)); + r_re = malloc(2 * sizeof(double *)); + r_im = malloc(2 * sizeof(double *)); + txdata = malloc(2 * sizeof(int * )); + + for (i = 0; i < 2; i++) { + s_re[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(s_re[i], frame_length_complex_samples * sizeof(double)); + s_im[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(s_im[i], frame_length_complex_samples * sizeof(double)); + r_re[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(r_re[i], frame_length_complex_samples * sizeof(double)); + r_im[i] = malloc(frame_length_complex_samples * sizeof(double)); + bzero(r_im[i], frame_length_complex_samples * sizeof(double)); + txdata[i] = malloc(frame_length_complex_samples * sizeof(int)); + bzero(r_re[i], frame_length_complex_samples * sizeof(int)); // [hna] r_re should be txdata + } + + if (pbch_file_fd != NULL) { + load_pbch_desc(pbch_file_fd); + } + + /* for (int k=0; k<2; k++) { + // Create transport channel structures for 2 transport blocks (MIMO) + for (i=0; i<2; i++) { + gNB->dlsch[k][i] = new_gNB_dlsch(Kmimo,8,Nsoft,0,frame_parms,gNB_config); + + if (!gNB->dlsch[k][i]) { + printf("Can't get eNB dlsch structures\n"); + exit(-1); + } + gNB->dlsch[k][i]->Nsoft = 10; + gNB->dlsch[k][i]->rnti = n_rnti+k; + } + }*/ + //configure UE + UE = malloc(sizeof(PHY_VARS_NR_UE)); + memcpy(&UE->frame_parms, frame_parms, sizeof(NR_DL_FRAME_PARMS)); + + //phy_init_nr_top(frame_parms); + if (init_nr_ue_signal(UE, 1, 0) != 0) { + printf("Error at UE NR initialisation\n"); + exit(-1); + } + + //nr_init_frame_parms_ue(&UE->frame_parms); + //init_nr_ue_transport(UE, 0); + for (sf = 0; sf < 2; sf++) { + for (i = 0; i < 2; i++) { + + UE->ulsch[sf][0][i] = new_nr_ue_ulsch(N_RB_UL, 8, 0); + + if (!UE->ulsch[sf][0][i]) { + printf("Can't get ue ulsch structures\n"); + exit(-1); + } + + } + } + + UE->dlsch_SI[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); + UE->dlsch_ra[0] = new_nr_ue_dlsch(1, 1, Nsoft, 5, N_RB_DL, 0); + + unsigned char harq_pid = 0; //dlsch->harq_ids[subframe]; + //time_stats_t *rm_stats, *te_stats, *i_stats; + uint8_t is_crnti = 0, llr8_flag = 0; + unsigned int TBS = 8424; + unsigned int available_bits; + uint8_t nb_re_dmrs = 6; + uint16_t length_dmrs = 1; + unsigned char mod_order; + uint8_t Nl = 1; + uint8_t rvidx = 0; + uint8_t UE_id = 1; + + NR_gNB_ULSCH_t *ulsch_gNB = gNB->ulsch[UE_id][0]; + nfapi_nr_ul_config_ulsch_pdu_rel15_t *rel15_ul = &ulsch_gNB->harq_processes[harq_pid]->ulsch_pdu.ulsch_pdu_rel15; + + NR_UE_ULSCH_t *ulsch_ue = UE->ulsch[0][0][0]; + + ulsch_ue->nb_re_dmrs = nb_re_dmrs; //[adk] A HOT FIX until cearting nfapi_nr_ul_config_ulsch_pdu_rel15_t + + mod_order = nr_get_Qm(Imcs, 1); + available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1); + TBS = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, Nl); + printf("available bits %d TBS %d mod_order %d\n", available_bits, TBS, mod_order); + + /////////// setting rel15_ul parameters /////////// + rel15_ul->number_rbs = nb_rb; + rel15_ul->number_symbols = nb_symb_sch; + rel15_ul->Qm = mod_order; + rel15_ul->mcs = Imcs; + rel15_ul->rv = rvidx; + rel15_ul->n_layers = Nl; + /////////////////////////////////////////////////// + + double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); // [hna] 16 segments, 68*Zc + short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); + short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); + unsigned int errors_bit_uncoded = 0; + // unsigned char *estimated_output; + unsigned char *estimated_output_bit; + unsigned char *test_input_bit; + unsigned int errors_bit = 0; + + test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + // estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + + unsigned char *test_input; + test_input = (unsigned char *) malloc16(sizeof(unsigned char) * TBS / 8); + + for (i = 0; i < TBS / 8; i++) + test_input[i] = (unsigned char) rand(); + + // estimated_output = ulsch_gNB->harq_processes[harq_pid]->b; + + /////////////////////////[adk] preparing UL harq_process parameters///////////////////////// + /////////// + NR_UL_UE_HARQ_t *harq_process_ul_ue = ulsch_ue->harq_processes[harq_pid]; + + if (harq_process_ul_ue) { + + harq_process_ul_ue->mcs = Imcs; + harq_process_ul_ue->Nl = Nl; + harq_process_ul_ue->nb_rb = nb_rb; + harq_process_ul_ue->nb_symbols = nb_symb_sch; + harq_process_ul_ue->rvidx = rvidx; + harq_process_ul_ue->TBS = TBS; + harq_process_ul_ue->a = &test_input[0]; + + } + /////////// + //////////////////////////////////////////////////////////////////////////////////////////// #ifdef DEBUG_ULSCHSIM - for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); + for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); #endif - /*for (int i=0; i0x%08x\n",crc24c(test_input, 32)); - // generate signal + //printf("crc32: [0]->0x%08x\n",crc24c(test_input, 32)); + // generate signal - /////////////////////////[adk] ULSCH coding///////////////////////// - /////////// + /////////////////////////[adk] ULSCH coding///////////////////////// + /////////// - if (input_fd == NULL) { - nr_dlsch_encoding(test_input, subframe, dlsch, frame_parms); - nr_ulsch_encoding(ulsch, frame_parms, harq_pid); - } + if (input_fd == NULL) { + nr_ulsch_encoding(ulsch_ue, frame_parms, harq_pid); + } - for (SNR = snr0; SNR < snr1; SNR += snr_step) { - n_errors = 0; - n_false_positive = 0; + /////////// + //////////////////////////////////////////////////////////////////// + + + for (SNR = snr0; SNR < snr1; SNR += snr_step) { + n_errors = 0; + n_false_positive = 0; + + for (trial = 0; trial < n_trials; trial++) { + + errors_bit_uncoded = 0; + + for (i = 0; i < available_bits; i++) { - for (trial = 0; trial < n_trials; trial++) { - errors_bit_uncoded = 0; - for (i = 0; i < available_bits; i++) { #ifdef DEBUG_CODER - if ((i&0xf)==0) - printf("\ne %d..%d: ",i,i+15); + if ((i&0xf)==0) + printf("\ne %d..%d: ",i,i+15); #endif - /* - if (i<16){ - printf("dlsch_encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); - printf("ulsch_encoder output f[%d] = %d\n",i,ulsch->harq_processes[0]->f[i]); + /* + if (i<16){ + printf("dlsch_encoder output f[%d] = %d\n",i,dlsch->harq_processes[0]->f[i]); + printf("ulsch_encoder output f[%d] = %d\n",i,ulsch_ue->harq_processes[0]->f[i]); + } + */ - } - */ - if (ulsch->harq_processes[0]->f[i] == 0) - modulated_input[i] = 1.0; ///sqrt(2); //QPSK - else - modulated_input[i] = -1.0; ///sqrt(2); + if (ulsch_ue->harq_processes[0]->f[i] == 0) + modulated_input[i] = 1.0; ///sqrt(2); //QPSK + else + modulated_input[i] = -1.0; ///sqrt(2); + + //if (i<16) printf("modulated_input[%d] = %d\n",i,modulated_input[i]); + //SNR =10; - //if (i<16) printf("modulated_input[%d] = %d\n",i,modulated_input[i]); - //SNR =10; - SNR_lin = pow(10, SNR / 10.0); - sigma = 1.0 / sqrt(2 * SNR_lin); + SNR_lin = pow(10, SNR / 10.0); + sigma = 1.0 / sqrt(2 * SNR_lin); #if 1 - channel_output_fixed[i] = (short) quantize(sigma / 4.0 / 4.0, - modulated_input[i] + sigma * gaussdouble(0.0, 1.0), - qbits); + channel_output_fixed[i] = (short) quantize(sigma / 4.0 / 4.0, + modulated_input[i] + sigma * gaussdouble(0.0, 1.0), + qbits); #else - channel_output_fixed[i] = (short) quantize(0.01, modulated_input[i], qbits); + channel_output_fixed[i] = (short) quantize(0.01, modulated_input[i], qbits); #endif - //channel_output_fixed[i] = (char)quantize8bit(sigma/4.0,(2.0*modulated_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0)); - //printf("llr[%d]=%d\n",i,channel_output_fixed[i]); - //printf("channel_output_fixed[%d]: %d\n",i,channel_output_fixed[i]); + //channel_output_fixed[i] = (char)quantize8bit(sigma/4.0,(2.0*modulated_input[i]) - 1.0 + sigma*gaussdouble(0.0,1.0)); + //printf("llr[%d]=%d\n",i,channel_output_fixed[i]); + //printf("channel_output_fixed[%d]: %d\n",i,channel_output_fixed[i]); - //channel_output_fixed[i] = (char)quantize(1,channel_output_fixed[i],qbits); + //channel_output_fixed[i] = (char)quantize(1,channel_output_fixed[i],qbits); - //if (i<16) printf("channel_output_fixed[%d] = %d\n",i,channel_output_fixed[i]); + //if (i<16) printf("channel_output_fixed[%d] = %d\n",i,channel_output_fixed[i]); - //Uncoded BER - if (channel_output_fixed[i] < 0) - channel_output_uncoded[i] = 1; //QPSK demod - else - channel_output_uncoded[i] = 0; + //Uncoded BER + if (channel_output_fixed[i] < 0) + channel_output_uncoded[i] = 1; //QPSK demod + else + channel_output_uncoded[i] = 0; - if (channel_output_uncoded[i] != dlsch->harq_processes[harq_pid]->f[i]) - errors_bit_uncoded = errors_bit_uncoded + 1; - } + if (channel_output_uncoded[i] != ulsch_ue->harq_processes[harq_pid]->f[i]) + errors_bit_uncoded = errors_bit_uncoded + 1; + } + + //if (errors_bit_uncoded>10) + printf("errors bits uncoded %u\n", errors_bit_uncoded); - //if (errors_bit_uncoded>10) - printf("errors bits uncoded %u\n", errors_bit_uncoded); #ifdef DEBUG_CODER - printf("\n"); - exit(-1); + printf("\n"); + exit(-1); #endif - ret = nr_dlsch_decoding(UE, channel_output_fixed, &UE->frame_parms, - dlsch0_ue, dlsch0_ue->harq_processes[0], frame, nb_symb_sch, - subframe, harq_pid, is_crnti, llr8_flag); - if (ret > dlsch0_ue->max_ldpc_iterations) - n_errors++; + ret = nr_ulsch_decoding(gNB, UE_id, channel_output_fixed, frame_parms, + frame, nb_symb_sch, subframe, harq_pid, is_crnti, llr8_flag); - //count errors - errors_bit = 0; + if (ret > ulsch_gNB->max_ldpc_iterations) + n_errors++; - for (i = 0; i < TBS; i++) { - estimated_output_bit[i] = (ulsch->harq_processes[0]->b[i / 8] & (1 << (i & 7))) >> (i & 7); - test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments + //count errors + errors_bit = 0; - if (estimated_output_bit[i] != test_input_bit[i]) { - errors_bit++; - //printf("estimated bits error occurs @%d ",i); - } - } + for (i = 0; i < TBS; i++) { + estimated_output_bit[i] = (ulsch_gNB->harq_processes[harq_pid]->b[i/8] & (1 << (i & 7))) >> (i & 7); + test_input_bit[i] = (test_input[i / 8] & (1 << (i & 7))) >> (i & 7); // Further correct for multiple segments - if (errors_bit > 0) { - n_false_positive++; - if (n_trials == 1) - printf("errors_bit %d (trial %d)\n", errors_bit, trial); - } - } + if (estimated_output_bit[i] != test_input_bit[i]) { + errors_bit++; + //printf("estimated bits error occurs @%d ",i); + } + } - printf("SNR %f, BLER %f (false positive %f)\n", SNR, - (float) n_errors / (float) n_trials, - (float) n_false_positive / (float) n_trials); + if (errors_bit > 0) { + n_false_positive++; + if (n_trials == 1) + printf("errors_bit %d (trial %d)\n", errors_bit, trial); + } + } + + printf("*****************************************\n"); + printf("SNR %f, BLER %f (false positive %f)\n", SNR, + (float) n_errors / (float) n_trials, + (float) n_false_positive / (float) n_trials); + printf("*****************************************\n"); - if ((float) n_errors / (float) n_trials < target_error_rate) { - printf("PDSCH test OK\n"); - break; - } - } + if ((float) n_errors / (float) n_trials < target_error_rate) + break; + } - /*LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); - if (gNB->frame_parms.nb_antennas_tx>1) - LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1);*/ + /*LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsigF1.m","txsF1", gNB->common_vars.txdataF[1],frame_length_complex_samples_no_prefix,1,1);*/ - //TODO: loop over slots - /*for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { - if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { - PHY_ofdm_mod(gNB->common_vars.txdataF[aa], - txdata[aa], - frame_parms->ofdm_symbol_size, - 12, - frame_parms->nb_prefix_samples, - CYCLIC_PREFIX); - } else { - nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], - txdata[aa], - 14, - frame_parms); - } - } + //TODO: loop over slots + /*for (aa=0; aaframe_parms.nb_antennas_tx; aa++) { + if (gNB_config->subframe_config.dl_cyclic_prefix_type.value == 1) { + PHY_ofdm_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + frame_parms->ofdm_symbol_size, + 12, + frame_parms->nb_prefix_samples, + CYCLIC_PREFIX); + } else { + nr_normal_prefix_mod(gNB->common_vars.txdataF[aa], + txdata[aa], + 14, + frame_parms); + } + } - LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1); - if (gNB->frame_parms.nb_antennas_tx>1) - LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1); + LOG_M("txsig0.m","txs0", txdata[0],frame_length_complex_samples,1,1); + if (gNB->frame_parms.nb_antennas_tx>1) + LOG_M("txsig1.m","txs1", txdata[1],frame_length_complex_samples,1,1); - for (i=0; inb_antennas_tx; aa++) { - r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); - r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); - } - }*/ + for (i=0; inb_antennas_tx; aa++) { + r_re[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)]); + r_im[aa][i] = ((double)(((short *)txdata[aa]))[(i<<1)+1]); + } + }*/ + for (i = 0; i < 2; i++) { - for (i = 0; i < 2; i++) { + printf("----------------------\n"); + printf("freeing codeword %d\n", i); + printf("----------------------\n"); - printf("gNB %d\n", i); + printf("gNB ulsch[0][%d]\n", i); // [hna] ulsch[0] is for RA - if (gNB->dlsch[0][i]) - free_gNB_dlsch(gNB->dlsch[0][i]); + free_gNB_ulsch(gNB->ulsch[0][i]); - for (sf = 0; sf < 2; sf++) { + printf("gNB ulsch[%d][%d]\n",UE_id, i); - printf("UE %d\n", i); + free_gNB_ulsch(gNB->ulsch[UE_id][i]); - if (UE->dlsch[sf][0][i]) - free_nr_ue_dlsch(UE->dlsch[sf][0][i]); + for (sf = 0; sf < 2; sf++) { - if (UE->ulsch[sf][0][i]) - free_nr_ue_ulsch(UE->ulsch[sf][0][i]); - } - } + printf("UE ulsch[%d][0][%d]\n", sf, i); - for (i = 0; i < 2; i++) { - free(s_re[i]); - free(s_im[i]); - free(r_re[i]); - free(r_im[i]); - free(txdata[i]); - } + if (UE->ulsch[sf][0][i]) + free_nr_ue_ulsch(UE->ulsch[sf][0][i]); + } - free(s_re); - free(s_im); - free(r_re); - free(r_im); - free(txdata); + printf("\n"); + } - if (output_fd) - fclose(output_fd); + for (i = 0; i < 2; i++) { + free(s_re[i]); + free(s_im[i]); + free(r_re[i]); + free(r_im[i]); + free(txdata[i]); + } - if (input_fd) - fclose(input_fd); + free(s_re); + free(s_im); + free(r_re); + free(r_im); + free(txdata); - return (n_errors); + if (output_fd) + fclose(output_fd); + + if (input_fd) + fclose(input_fd); + + return (n_errors); } From bc53a0a77144772de29c7244b0eee5d7801d53f5 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Mar 2019 17:48:51 +0100 Subject: [PATCH 029/117] indentation + some comments --- openair1/PHY/CODING/coding_defs.h | 2 +- openair1/PHY/CODING/nr_segmentation.c | 2 +- openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 5 +- .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 1146 ++++++++--------- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 4 +- openair1/SIMULATION/NR_PHY/dlschsim.c | 4 +- 6 files changed, 579 insertions(+), 584 deletions(-) diff --git a/openair1/PHY/CODING/coding_defs.h b/openair1/PHY/CODING/coding_defs.h index 0f316e7869..0c1dbfae35 100644 --- a/openair1/PHY/CODING/coding_defs.h +++ b/openair1/PHY/CODING/coding_defs.h @@ -453,7 +453,7 @@ int32_t nr_segmentation(unsigned char *input_buffer, unsigned int B, unsigned int *C, unsigned int *K, - unsigned int *Zout, + unsigned int *Zout, unsigned int *F); uint32_t nr_compute_tbs(uint8_t mcs, diff --git a/openair1/PHY/CODING/nr_segmentation.c b/openair1/PHY/CODING/nr_segmentation.c index 8d0cc9e7d3..421f440ec2 100644 --- a/openair1/PHY/CODING/nr_segmentation.c +++ b/openair1/PHY/CODING/nr_segmentation.c @@ -34,7 +34,7 @@ int32_t nr_segmentation(unsigned char *input_buffer, unsigned int B, unsigned int *C, unsigned int *K, - unsigned int *Zout, + unsigned int *Zout, // [hna] Zout is Zc unsigned int *F) { diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index 4e8c2d2ff5..50e836fe58 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -195,6 +195,9 @@ NR_gNB_DLSCH_t *new_gNB_dlsch(unsigned char Kmimo, if (abstraction_flag==0) { for (r=0; rharq_processes[i]->c[r] = (uint8_t*)malloc16(8448); dlsch->harq_processes[i]->d[r] = (uint8_t*)malloc16(68*384); //max size for coded output if (dlsch->harq_processes[i]->c[r]) { @@ -337,7 +340,7 @@ int nr_dlsch_encoding(unsigned char *a, dlsch->harq_processes[harq_pid]->B, &dlsch->harq_processes[harq_pid]->C, &dlsch->harq_processes[harq_pid]->K, - pz, + pz, // [hna] pz is Zc &dlsch->harq_processes[harq_pid]->F); F = dlsch->harq_processes[harq_pid]->F; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index def3a71754..7cc6dde893 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -76,11 +76,11 @@ void free_nr_ue_dlsch(NR_UE_DLSCH_t *dlsch) } for (r=0; r<(MAX_NUM_NR_DLSCH_SEGMENTS); r++) { - if (dlsch->harq_processes[i]->p_nrLDPC_procBuf[r]){ - nrLDPC_free_mem(dlsch->harq_processes[i]->p_nrLDPC_procBuf[r]); - dlsch->harq_processes[i]->p_nrLDPC_procBuf[r] = NULL; - } - } + if (dlsch->harq_processes[i]->p_nrLDPC_procBuf[r]){ + nrLDPC_free_mem(dlsch->harq_processes[i]->p_nrLDPC_procBuf[r]); + dlsch->harq_processes[i]->p_nrLDPC_procBuf[r] = NULL; + } + } free16(dlsch->harq_processes[i],sizeof(NR_DL_UE_HARQ_t)); dlsch->harq_processes[i] = NULL; @@ -143,7 +143,7 @@ NR_UE_DLSCH_t *new_nr_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint if (abstraction_flag == 0) { for (r=0; rharq_processes[i]->p_nrLDPC_procBuf[r] = nrLDPC_init_mem(); + dlsch->harq_processes[i]->p_nrLDPC_procBuf[r] = nrLDPC_init_mem(); dlsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(1056); if (dlsch->harq_processes[i]->c[r]) @@ -192,7 +192,7 @@ void nr_dlsch_unscrambling(int16_t* llr, reset = 0; } if (((s>>(i&0x1f))&1)==1) - llr[i] = -llr[i]; + llr[i] = -llr[i]; } } @@ -203,7 +203,7 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, NR_UE_DLSCH_t *dlsch, NR_DL_UE_HARQ_t *harq_process, uint32_t frame, - uint16_t nb_symb_sch, + uint16_t nb_symb_sch, uint8_t nr_tti_rx, uint8_t harq_pid, uint8_t is_crnti, @@ -247,7 +247,7 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, //NR_DL_UE_HARQ_t *harq_process = dlsch->harq_processes[0]; - if (!dlsch_llr) { + if (!dlsch_llr) { printf("dlsch_decoding.c: NULL dlsch_llr pointer\n"); return(dlsch->max_ldpc_iterations); } @@ -305,57 +305,59 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, // This is a new packet, so compute quantities regarding segmentation harq_process->B = A+24; nr_segmentation(NULL, - NULL, - harq_process->B, - &harq_process->C, - &harq_process->K, - &harq_process->Z, - &harq_process->F); - p_decParams->Z = harq_process->Z; + NULL, + harq_process->B, + &harq_process->C, + &harq_process->K, + &harq_process->Z, // [hna] Z is Zc + &harq_process->F); + + p_decParams->Z = harq_process->Z; #ifdef DEBUG_DLSCH_DECODING printf("dlsch decoding nr segmentation Z %d\n", p_decParams->Z); - if (!frame%100) - printf("K %d C %d Z %d nl %d \n", harq_process->K, harq_process->C, p_decParams->Z, harq_process->Nl); + if (!frame%100) + printf("K %d C %d Z %d nl %d \n", harq_process->K, harq_process->C, p_decParams->Z, harq_process->Nl); #endif } - Coderate = (float) A /(float) G; - if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25){ - p_decParams->BG = 2; - if (Coderate < 0.3333){ - p_decParams->R = 15; - kc = 52; - } - else if (Coderate <0.6667){ - p_decParams->R = 13; - kc = 32; - } - else { - p_decParams->R = 23; - kc = 17; - } - } - else{ - p_decParams->BG = 1; - if (Coderate < 0.6667){ - p_decParams->R = 13; - kc = 68; - } - else if (Coderate <0.8889){ - p_decParams->R = 23; - kc = 35; - } - else { - p_decParams->R = 89; - kc = 27; - } - } - //printf("coderate %f kc %d \n", Coderate, kc); + Coderate = (float) A /(float) G; + if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25) + { + p_decParams->BG = 2; + if (Coderate < 0.3333){ + p_decParams->R = 15; + kc = 52; + } + else if (Coderate <0.6667){ + p_decParams->R = 13; + kc = 32; + } + else { + p_decParams->R = 23; + kc = 17; + } + } + else{ + p_decParams->BG = 1; + if (Coderate < 0.6667){ + p_decParams->R = 13; + kc = 68; + } + else if (Coderate <0.8889){ + p_decParams->R = 23; + kc = 35; + } + else { + p_decParams->R = 89; + kc = 27; + } + } - p_decParams->numMaxIter = dlsch->max_ldpc_iterations; - p_decParams->outMode= 0; + //printf("coderate %f kc %d \n", Coderate, kc); + p_decParams->numMaxIter = dlsch->max_ldpc_iterations; + p_decParams->outMode= 0; err_flag = 0; r_offset = 0; @@ -363,27 +365,27 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, unsigned char bw_scaling =1; switch (frame_parms->N_RB_DL) { + case 106: + bw_scaling =2; + break; - case 106: - bw_scaling =2; - break; - - default: - bw_scaling =1; - break; + default: + bw_scaling =1; + break; } if (harq_process->C > MAX_NUM_NR_DLSCH_SEGMENTS/bw_scaling) { LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,MAX_NUM_NR_DLSCH_SEGMENTS/bw_scaling); return((1+dlsch->max_ldpc_iterations)); } + #ifdef DEBUG_DLSCH_DECODING printf("Segmentation: C %d, K %d\n",harq_process->C,harq_process->K); #endif opp_enabled=1; - Kr = harq_process->K; + Kr = harq_process->K; // [hna] overwrites this line "Kr = p_decParams->Z*kb" Kr_bytes = Kr>>3; K_bytes_F = Kr_bytes-(harq_process->F>>3); @@ -400,11 +402,11 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, #endif nr_deinterleaving_ldpc(E, harq_process->Qm, - harq_process->w[r], + harq_process->w[r], // [hna] w is e dlsch_llr+r_offset); //for (int i =0; i<16; i++) - // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); + // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); #if UE_TIMING_TRACE stop_meas(dlsch_deinterleaving_stats); @@ -441,31 +443,30 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, #endif LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n"); return(dlsch->max_ldpc_iterations); - } else - { + } else { #if UE_TIMING_TRACE stop_meas(dlsch_rate_unmatching_stats); #endif } //for (int i =0; i<16; i++) - // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); + // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); r_offset += E; #ifdef DEBUG_DLSCH_DECODING if (r==0) { - write_output("decoder_llr.m","decllr",dlsch_llr,G,1,0); - write_output("decoder_in.m","dec",&harq_process->d[0][0],(3*8*Kr_bytes)+12,1,0); + write_output("decoder_llr.m","decllr",dlsch_llr,G,1,0); + write_output("decoder_in.m","dec",&harq_process->d[0][0],(3*8*Kr_bytes)+12,1,0); } printf("decoder input(segment %d) :",r); - int i; for (i=0;i<(3*8*Kr_bytes)+12;i++) + int i; + for (i=0;i<(3*8*Kr_bytes)+12;i++) printf("%d : %d\n",i,harq_process->d[r][i]); - printf("\n"); + printf("\n"); #endif - // printf("Clearing c, %p\n",harq_process->c[r]); memset(harq_process->c[r],0,Kr_bytes); @@ -482,74 +483,70 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, if (err_flag == 0) { #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); #endif //LOG_E(PHY,"AbsSubframe %d.%d Start LDPC segment %d/%d A %d ",frame%1024,nr_tti_rx,r,harq_process->C-1, A); //printf("harq process dr iteration %d\n", p_decParams->numMaxIter); + memset(pv,0,2*harq_process->Z*sizeof(int16_t)); + //memset(pl,0,2*p_decParams->Z*sizeof(int8_t)); + memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); - memset(pv,0,2*harq_process->Z*sizeof(int16_t)); - //memset(pl,0,2*p_decParams->Z*sizeof(int8_t)); - memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); + for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F; i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); + } - for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F; i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); - } + for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); + } - for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); - } - - for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) - { - - pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); - - } + for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) + { + pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + } - no_iteration_ldpc = nrLDPC_decoder(p_decParams, - (int8_t*)&pl[0], - llrProcBuf, + no_iteration_ldpc = nrLDPC_decoder(p_decParams, + (int8_t*)&pl[0], + llrProcBuf, p_nrLDPC_procBuf[r], p_procTime); - // Fixme: correct type is unsigned, but nrLDPC_decoder and all called behind use signed int - if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) { - printf("Segment %d CRC OK\n",r); - ret = 2; - } - else { - printf("CRC NOK\n"); - ret = 1+dlsch->max_ldpc_iterations; - } - + // Fixme: correct type is unsigned, but nrLDPC_decoder and all called behind use signed int + if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) { + printf("Segment %d CRC OK\n",r); + ret = 2; + } + else { + printf("CRC NOK\n"); + ret = 1+dlsch->max_ldpc_iterations; + } - nb_total_decod++; - if (no_iteration_ldpc > dlsch->max_ldpc_iterations){ - nb_error_decod++; - } + nb_total_decod++; + if (no_iteration_ldpc > dlsch->max_ldpc_iterations){ + nb_error_decod++; + } - ret=no_iteration_ldpc; + ret=no_iteration_ldpc; - //if (!nb_total_decod%10000){ - //printf("Error number of iteration LPDC %d %ld/%ld \n", no_iteration_ldpc, nb_error_decod,nb_total_decod);fflush(stdout); - //} - //else - //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); + //if (!nb_total_decod%10000){ + //printf("Error number of iteration LPDC %d %ld/%ld \n", no_iteration_ldpc, nb_error_decod,nb_total_decod);fflush(stdout); + //} + //else + //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); - for (int m=0; m < Kr>>3; m ++) - { - harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; - } + for (int m=0; m < Kr>>3; m ++) + { + harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; + } #ifdef DEBUG_DLSCH_DECODING //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); for (int k=0;k>3;k++) - printf("output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); + printf("output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); printf("no_iterations_ldpc %d (ret %d)\n",no_iteration_ldpc,ret); //write_output("dec_output.m","dec0",harq_process->c[0],Kr_bytes,1,4); #endif @@ -664,18 +661,18 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, #ifdef UE_DLSCH_PARALLELISATION uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, - UE_nr_rxtx_proc_t *proc, - int eNB_id, - short *dlsch_llr, - NR_DL_FRAME_PARMS *frame_parms, - NR_UE_DLSCH_t *dlsch, - NR_DL_UE_HARQ_t *harq_process, - uint32_t frame, - uint16_t nb_symb_sch, - uint8_t nr_tti_rx, - uint8_t harq_pid, - uint8_t is_crnti, - uint8_t llr8_flag) + UE_nr_rxtx_proc_t *proc, + int eNB_id, + short *dlsch_llr, + NR_DL_FRAME_PARMS *frame_parms, + NR_UE_DLSCH_t *dlsch, + NR_DL_UE_HARQ_t *harq_process, + uint32_t frame, + uint16_t nb_symb_sch, + uint8_t nr_tti_rx, + uint8_t harq_pid, + uint8_t is_crnti, + uint8_t llr8_flag) { #if UE_TIMING_TRACE @@ -786,27 +783,28 @@ uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, // This is a new packet, so compute quantities regarding segmentation harq_process->B = A+24; nr_segmentation(NULL, - NULL, - harq_process->B, - &harq_process->C, - &harq_process->K, - &harq_process->Z, - &harq_process->F); - p_decParams->Z = harq_process->Z; + NULL, + harq_process->B, + &harq_process->C, + &harq_process->K, + &harq_process->Z, + &harq_process->F); + + p_decParams->Z = harq_process->Z; } - kb = harq_process->K/harq_process->Z; - if ( kb==22){ - p_decParams->BG = 1; - p_decParams->R = 13; - kc = 68; - } - else{ - p_decParams->BG = 2; - p_decParams->R = 13; - kc = 52; - } + kb = harq_process->K/harq_process->Z; + if ( kb==22){ + p_decParams->BG = 1; + p_decParams->R = 13; + kc = 68; + } + else{ + p_decParams->BG = 2; + p_decParams->R = 13; + kc = 52; + } p_decParams->numMaxIter = 2; Kr = p_decParams->Z*kb; @@ -842,135 +840,133 @@ uint32_t nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue, #endif opp_enabled=1; -if (harq_process->C>1) { // wakeup worker if more than 1 segment - if (pthread_mutex_lock(&proc->mutex_dlsch_td) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE dlsch td\n",phy_vars_ue->Mod_id ); - exit_fun("nothing to add"); - } + if (harq_process->C>1) { // wakeup worker if more than 1 segment + if (pthread_mutex_lock(&proc->mutex_dlsch_td) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE dlsch td\n",phy_vars_ue->Mod_id ); + exit_fun("nothing to add"); + } - /*Qm= harq_process->Qm; - Nl=harq_process->Nl; - r_thread = harq_process->C/2-1; - C= harq_process->C; + /*Qm= harq_process->Qm; + Nl=harq_process->Nl; + r_thread = harq_process->C/2-1; + C= harq_process->C; - Gp = G/Nl/Qm; - GpmodC = Gp%C; + Gp = G/Nl/Qm; + GpmodC = Gp%C; - if (r_thread < (C-(GpmodC))) - Er = Nl*Qm * (Gp/C); - else - Er = Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); - printf("mthread Er %d\n", Er); + if (r_thread < (C-(GpmodC))) + Er = Nl*Qm * (Gp/C); + else + Er = Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); + printf("mthread Er %d\n", Er); - printf("mthread instance_cnt_dlsch_td %d\n", proc->instance_cnt_dlsch_td);*/ + printf("mthread instance_cnt_dlsch_td %d\n", proc->instance_cnt_dlsch_td);*/ - proc->instance_cnt_dlsch_td++; - proc->eNB_id = eNB_id; - proc->harq_pid = harq_pid; - proc->llr8_flag = llr8_flag; - //proc->r[0] = 1; + proc->instance_cnt_dlsch_td++; + proc->eNB_id = eNB_id; + proc->harq_pid = harq_pid; + proc->llr8_flag = llr8_flag; + //proc->r[0] = 1; - if (proc->instance_cnt_dlsch_td == 0) - { - LOG_D(PHY,"unblock dlsch td processing thread blocked on instance_cnt_dlsch_td : %d \n", proc->instance_cnt_dlsch_td ); - if (pthread_cond_signal(&proc->cond_dlsch_td) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE dlsch td\n", phy_vars_ue->Mod_id); - exit_fun("nothing to add"); - } - if (pthread_mutex_unlock(&proc->mutex_dlsch_td) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE dlsch td \n",phy_vars_ue->Mod_id ); - exit_fun("nothing to add"); - } + if (proc->instance_cnt_dlsch_td == 0) + { + LOG_D(PHY,"unblock dlsch td processing thread blocked on instance_cnt_dlsch_td : %d \n", proc->instance_cnt_dlsch_td ); + if (pthread_cond_signal(&proc->cond_dlsch_td) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE dlsch td\n", phy_vars_ue->Mod_id); + exit_fun("nothing to add"); + } + if (pthread_mutex_unlock(&proc->mutex_dlsch_td) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE dlsch td \n",phy_vars_ue->Mod_id ); + exit_fun("nothing to add"); + } + } else + { + LOG_E( PHY, "[SCHED][UE %d] UE dlsch td thread busy (IC %d)!!\n", phy_vars_ue->Mod_id, proc->instance_cnt_dlsch_td); + if (proc->instance_cnt_dlsch_td > 4) + exit_fun("instance_cnt_dlsch_td > 4"); + } + //AssertFatal(pthread_cond_signal(&proc->cond_slot1_dl_processing) ==0 ,""); + AssertFatal(pthread_mutex_unlock(&proc->mutex_dlsch_td) ==0,""); - } else - { - LOG_E( PHY, "[SCHED][UE %d] UE dlsch td thread busy (IC %d)!!\n", phy_vars_ue->Mod_id, proc->instance_cnt_dlsch_td); - if (proc->instance_cnt_dlsch_td > 4) - exit_fun("instance_cnt_dlsch_td > 4"); - } - //AssertFatal(pthread_cond_signal(&proc->cond_slot1_dl_processing) ==0 ,""); - AssertFatal(pthread_mutex_unlock(&proc->mutex_dlsch_td) ==0,""); + if (harq_process->C>2) { + if (pthread_mutex_lock(&proc->mutex_dlsch_td1) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE dlsch td\n",phy_vars_ue->Mod_id ); + exit_fun("nothing to add"); + } - if (harq_process->C>2) { - if (pthread_mutex_lock(&proc->mutex_dlsch_td1) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE dlsch td\n",phy_vars_ue->Mod_id ); - exit_fun("nothing to add"); - } + proc->instance_cnt_dlsch_td1++; + proc->eNB_id = eNB_id; + proc->harq_pid = harq_pid; + proc->llr8_flag = llr8_flag; + // proc->Er = Er; - proc->instance_cnt_dlsch_td1++; - proc->eNB_id = eNB_id; - proc->harq_pid = harq_pid; - proc->llr8_flag = llr8_flag; - // proc->Er = Er; + if (proc->instance_cnt_dlsch_td1 == 0) + { + LOG_D(PHY,"unblock slot1 dl processing thread blocked on instance_cnt_dlsch_td : %d \n", proc->instance_cnt_dlsch_td1 ); + if (pthread_cond_signal(&proc->cond_dlsch_td1) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE dlsch td\n", phy_vars_ue->Mod_id); + exit_fun("nothing to add"); + } + if (pthread_mutex_unlock(&proc->mutex_dlsch_td1) != 0) { + LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE dlsch td \n",phy_vars_ue->Mod_id ); + exit_fun("nothing to add"); + } + } else + { + LOG_E( PHY, "[SCHED][UE %d] UE dlsch td thread 1 busy (IC %d)!!\n", phy_vars_ue->Mod_id, proc->instance_cnt_dlsch_td1); + if (proc->instance_cnt_dlsch_td1 > 4) + exit_fun("instance_cnt_dlsch_td1 > 4"); + } - if (proc->instance_cnt_dlsch_td1 == 0) - { - LOG_D(PHY,"unblock slot1 dl processing thread blocked on instance_cnt_dlsch_td : %d \n", proc->instance_cnt_dlsch_td1 ); - if (pthread_cond_signal(&proc->cond_dlsch_td1) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE dlsch td\n", phy_vars_ue->Mod_id); - exit_fun("nothing to add"); - } - if (pthread_mutex_unlock(&proc->mutex_dlsch_td1) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE dlsch td \n",phy_vars_ue->Mod_id ); - exit_fun("nothing to add"); - } + AssertFatal(pthread_mutex_unlock(&proc->mutex_dlsch_td1) ==0,""); - } else - { - LOG_E( PHY, "[SCHED][UE %d] UE dlsch td thread 1 busy (IC %d)!!\n", phy_vars_ue->Mod_id, proc->instance_cnt_dlsch_td1); - if (proc->instance_cnt_dlsch_td1 > 4) - exit_fun("instance_cnt_dlsch_td1 > 4"); - } + } + /* + if (pthread_mutex_timedlock(&proc->mutex_td,&wait) != 0) { + printf("[eNB] ERROR pthread_mutex_lock for TD thread (IC %d)\n", proc->instance_cnt_td); + exit_fun( "error locking mutex_fep" ); + return -1; + } - AssertFatal(pthread_mutex_unlock(&proc->mutex_dlsch_td1) ==0,""); + if (proc->instance_cnt_td==0) { + printf("[UE] TD thread busy\n"); + exit_fun("TD thread busy"); + pthread_mutex_unlock( &proc->mutex_td ); + return -1; + } - } - /* - if (pthread_mutex_timedlock(&proc->mutex_td,&wait) != 0) { - printf("[eNB] ERROR pthread_mutex_lock for TD thread (IC %d)\n", proc->instance_cnt_td); - exit_fun( "error locking mutex_fep" ); - return -1; - } + ++proc->instance_cnt_td; - if (proc->instance_cnt_td==0) { - printf("[UE] TD thread busy\n"); - exit_fun("TD thread busy"); - pthread_mutex_unlock( &proc->mutex_td ); - return -1; - } + proc->tdp.UE = phy_vars_ue; + proc->tdp.eNB_id = eNB_id; + proc->tdp.harq_pid = harq_pid; + proc->tdp.llr8_flag = llr8_flag; - ++proc->instance_cnt_td; - - proc->tdp.UE = phy_vars_ue; - proc->tdp.eNB_id = eNB_id; - proc->tdp.harq_pid = harq_pid; - proc->tdp.llr8_flag = llr8_flag; - - printf("----- 2thread llr flag %d tdp flag %d\n",llr8_flag, proc->tdp.llr8_flag); + printf("----- 2thread llr flag %d tdp flag %d\n",llr8_flag, proc->tdp.llr8_flag); - // wakeup worker to do second half segments - if (pthread_cond_signal(&proc->cond_td) != 0) { - printf("[UE] ERROR pthread_cond_signal for td thread exit\n"); - exit_fun( "ERROR pthread_cond_signal" ); - return (1+dlsch->last_iteration_cnt); - } + // wakeup worker to do second half segments + if (pthread_cond_signal(&proc->cond_td) != 0) { + printf("[UE] ERROR pthread_cond_signal for td thread exit\n"); + exit_fun( "ERROR pthread_cond_signal" ); + return (1+dlsch->last_iteration_cnt); + } - pthread_mutex_unlock( &proc->mutex_td );*/ + pthread_mutex_unlock( &proc->mutex_td );*/ - Cby2 = 1; //harq_process->C/2; - //proc->decoder_main_available = 1; - } - else { - Cby2 = 1; - } + Cby2 = 1; //harq_process->C/2; + //proc->decoder_main_available = 1; + } + else { + Cby2 = 1; + } - //for (r=0; rK; Kr_bytes = Kr>>3; @@ -1041,27 +1037,27 @@ if (harq_process->C>1) { // wakeup worker if more than 1 segment } //for (int i =0; i<16; i++) - // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); + // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); //r_offset += E; //printf("main thread r_offset %d\n",r_offset); #ifdef DEBUG_DLSCH_DECODING for (int i =0; i<16; i++) - printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); + printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); #endif #ifdef DEBUG_DLSCH_DECODING if (r==0) { - write_output("decoder_llr.m","decllr",dlsch_llr,G,1,0); - write_output("decoder_in.m","dec",&harq_process->d[0][96],(3*8*Kr_bytes)+12,1,0); + write_output("decoder_llr.m","decllr",dlsch_llr,G,1,0); + write_output("decoder_in.m","dec",&harq_process->d[0][96],(3*8*Kr_bytes)+12,1,0); } printf("decoder input(segment %d) :",r); for (int i=0;i<(3*8*Kr_bytes);i++) printf("%d : %d\n",i,harq_process->d[r][i]); - printf("\n"); + printf("\n"); #endif @@ -1082,98 +1078,94 @@ if (harq_process->C>1) { // wakeup worker if more than 1 segment Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS, harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_ldpc_iterations); */ - if (llr8_flag) { - AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", - Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); - } + if (llr8_flag) { + AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", + Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); + } #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); #endif LOG_D(PHY,"mthread AbsSubframe %d.%d Start turbo segment %d/%d \n",frame%1024,nr_tti_rx,r,harq_process->C-1); - - for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++){ - inv_d[cnt] = (1)*harq_process->d[r][cnt]; - } - memset(pv,0,2*p_decParams->Z*sizeof(int16_t)); - //memset(pl,0,2*p_decParams->Z*sizeof(int8_t)); - memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); + for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++){ + inv_d[cnt] = (1)*harq_process->d[r][cnt]; + } + + memset(pv,0,2*p_decParams->Z*sizeof(int16_t)); + //memset(pl,0,2*p_decParams->Z*sizeof(int8_t)); + memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); - for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) - { + for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) + { + pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + } - pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + no_iteration_ldpc = nrLDPC_decoder(p_decParams, + (int8_t*)&pl[0], + llrProcBuf, + p_nrLDPC_procBuf, + p_procTime); - } + nb_total_decod++; + if (no_iteration_ldpc > 10){ + nb_error_decod++; + ret = 1+dlsch->max_ldpc_iterations; + } + else { + ret=2; + } - no_iteration_ldpc = nrLDPC_decoder(p_decParams, - (int8_t*)&pl[0], - llrProcBuf, - p_nrLDPC_procBuf, - p_procTime); + if (check_crc(llrProcBuf,harq_process->B,harq_process->F,crc_type)) { + printf("CRC OK\n"); + ret = 2; + } + else { + printf("CRC NOK\n"); + ret = 1+dlsch->max_ldpc_iterations; + } - nb_total_decod++; - if (no_iteration_ldpc > 10){ - nb_error_decod++; - ret = 1+dlsch->max_ldpc_iterations; - } - else { - ret=2; - } - - if (check_crc(llrProcBuf,harq_process->B,harq_process->F,crc_type)) { - printf("CRC OK\n"); - ret = 2; - } - else { - printf("CRC NOK\n"); - ret = 1+dlsch->max_ldpc_iterations; - } - - //if (!nb_total_decod%10000){ - printf("Error number of iteration LPDC %d %ld/%ld \n", no_iteration_ldpc, nb_error_decod,nb_total_decod);fflush(stdout); - //} + //if (!nb_total_decod%10000){ + printf("Error number of iteration LPDC %d %ld/%ld \n", no_iteration_ldpc, nb_error_decod,nb_total_decod);fflush(stdout); + //} - //else - //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); + //else + //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); - for (int m=0; m < Kr>>3; m ++) - { - harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; - } + for (int m=0; m < Kr>>3; m ++) + { + harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; + } - /*for (int u=0; u < Kr>>3; u ++) - { - ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; - } + /*for (int u=0; u < Kr>>3; u ++) + { + ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; + } - printf("output unsigned ullrProcBuf \n"); + printf("output unsigned ullrProcBuf \n"); - for (int j=0; j < Kr>>3; j ++) - { + for (int j=0; j < Kr>>3; j ++) + { + printf(" %d \n", ullrProcBuf[j]); + } + printf(" \n");*/ + //printf("output channel decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); - printf(" %d \n", ullrProcBuf[j]); - - } - printf(" \n");*/ - //printf("output channel decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); - - //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); + //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); #ifdef DEBUG_DLSCH_DECODING - for (int k=0;k<32;k++) - printf("output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); + for (int k=0;k<32;k++) + printf("output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); #endif #if UE_TIMING_TRACE @@ -1252,40 +1244,40 @@ if (harq_process->C>1) { // wakeup worker if more than 1 segment */ uint32_t wait = 0; if (harq_process->C==2){ - while((proc->decoder_thread_available == 0) ) + while((proc->decoder_thread_available == 0) ) { usleep(1); wait++; } } else if ((harq_process->C==3) ){ - while((proc->decoder_thread_available == 0) || (proc->decoder_thread_available1 == 0)) - { - usleep(1); - wait++; - } + while((proc->decoder_thread_available == 0) || (proc->decoder_thread_available1 == 0)) + { + usleep(1); + wait++; + } } proc->decoder_main_available = 0; for (r=0; rC; r++) { - Kr = harq_process->K; //to check if same K in all segments - Kr_bytes = Kr>>3; + Kr = harq_process->K; //to check if same K in all segments + Kr_bytes = Kr>>3; - memcpy(harq_process->b+offset, - harq_process->c[r], - Kr_bytes- - (harq_process->F>>3) -((harq_process->C>1)?3:0)); - offset += (Kr_bytes - (harq_process->F>>3) - ((harq_process->C>1)?3:0)); + memcpy(harq_process->b+offset, + harq_process->c[r], + Kr_bytes- - (harq_process->F>>3) -((harq_process->C>1)?3:0)); + offset += (Kr_bytes - (harq_process->F>>3) - ((harq_process->C>1)?3:0)); #ifdef DEBUG_DLSCH_DECODING - printf("Segment %d : Kr= %d bytes\n",r,Kr_bytes); - printf("copied %d bytes to b sequence (harq_pid %d)\n", - (Kr_bytes - (harq_process->F>>3)-((harq_process->C>1)?3:0)),harq_pid); - printf("b[0] = %x,c[%d] = %x\n", - harq_process->b[offset], - harq_process->F>>3, - harq_process->c[r]); + printf("Segment %d : Kr= %d bytes\n",r,Kr_bytes); + printf("copied %d bytes to b sequence (harq_pid %d)\n", + (Kr_bytes - (harq_process->F>>3)-((harq_process->C>1)?3:0)),harq_pid); + printf("b[0] = %x,c[%d] = %x\n", + harq_process->b[offset], + harq_process->F>>3, + harq_process->c[r]); #endif } @@ -1346,14 +1338,14 @@ void *nr_dlsch_decoding_2thread0(void *arg) char threadname[256]; sprintf(threadname,"UE_thread_dlsch_td_%d", proc->sub_frame_start); - cpu_set_t cpuset; + cpu_set_t cpuset; CPU_ZERO(&cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.dlsch_td_one != -1 ) - CPU_SET(threads.dlsch_td_one, &cpuset); + CPU_SET(threads.dlsch_td_one, &cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.dlsch_td_two != -1 ) - CPU_SET(threads.dlsch_td_two, &cpuset); + CPU_SET(threads.dlsch_td_two, &cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.dlsch_td_three != -1 ) - CPU_SET(threads.dlsch_td_three, &cpuset); + CPU_SET(threads.dlsch_td_three, &cpuset); @@ -1376,42 +1368,42 @@ void *nr_dlsch_decoding_2thread0(void *arg) init_thread(900000,1000000 , FIFO_PRIORITY-1, &cpuset, threadname); while (!oai_exit) { - //proc->decoder_thread_available = 1; - - if (pthread_mutex_lock(&proc->mutex_dlsch_td) != 0) { - LOG_E( PHY, "[SCHED][UE] error locking mutex for UE dlsch td\n" ); - exit_fun("nothing to add"); - } - while (proc->instance_cnt_dlsch_td < 0) { - // most of the time, the thread is waiting here - pthread_cond_wait( &proc->cond_dlsch_td, &proc->mutex_dlsch_td ); - } - if (pthread_mutex_unlock(&proc->mutex_dlsch_td) != 0) { - LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE dlsch_td \n" ); - exit_fun("nothing to add"); - } + //proc->decoder_thread_available = 1; + + if (pthread_mutex_lock(&proc->mutex_dlsch_td) != 0) { + LOG_E( PHY, "[SCHED][UE] error locking mutex for UE dlsch td\n" ); + exit_fun("nothing to add"); + } + while (proc->instance_cnt_dlsch_td < 0) { + // most of the time, the thread is waiting here + pthread_cond_wait( &proc->cond_dlsch_td, &proc->mutex_dlsch_td ); + } + if (pthread_mutex_unlock(&proc->mutex_dlsch_td) != 0) { + LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE dlsch_td \n" ); + exit_fun("nothing to add"); + } - uint32_t wait = 0; - while(proc->decoder_main_available == 0) - { - usleep(1); - wait++; - } + uint32_t wait = 0; + while(proc->decoder_main_available == 0) + { + usleep(1); + wait++; + } - //proc->decoder_thread_available = 0; - //PHY_VARS_NR_UE *phy_vars_ue = tdp->UE; - int eNB_id = proc->eNB_id; - int harq_pid = proc->harq_pid; - llr8_flag1 = proc->llr8_flag; - //r_offset = proc->Er; - //UE_rxtx_proc_t *proc = tdp->proc; - int frame = proc->frame_rx; - int subframe = proc->nr_tti_rx; - NR_UE_DLSCH_t *dlsch = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]; - NR_DL_UE_HARQ_t *harq_process = dlsch->harq_processes[harq_pid]; - short *dlsch_llr = phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr[0]; - //printf("2thread0 llr flag %d tdp flag %d\n",llr8_flag1, tdp->llr8_flag); - p_nrLDPC_procBuf = harq_process->p_nrLDPC_procBuf[1]; + //proc->decoder_thread_available = 0; + //PHY_VARS_NR_UE *phy_vars_ue = tdp->UE; + int eNB_id = proc->eNB_id; + int harq_pid = proc->harq_pid; + llr8_flag1 = proc->llr8_flag; + //r_offset = proc->Er; + //UE_rxtx_proc_t *proc = tdp->proc; + int frame = proc->frame_rx; + int subframe = proc->nr_tti_rx; + NR_UE_DLSCH_t *dlsch = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]; + NR_DL_UE_HARQ_t *harq_process = dlsch->harq_processes[harq_pid]; + short *dlsch_llr = phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr[0]; + //printf("2thread0 llr flag %d tdp flag %d\n",llr8_flag1, tdp->llr8_flag); + p_nrLDPC_procBuf = harq_process->p_nrLDPC_procBuf[1]; /* if (nb_rb > frame_parms->N_RB_DL) { @@ -1444,27 +1436,27 @@ void *nr_dlsch_decoding_2thread0(void *arg) harq_process->B = A+24; nr_segmentation(NULL, - NULL, - harq_process->B, - &harq_process->C, - &harq_process->K, - &harq_process->Z, - &harq_process->F); - p_decParams->Z = harq_process->Z; + NULL, + harq_process->B, + &harq_process->C, + &harq_process->K, + &harq_process->Z, + &harq_process->F); + p_decParams->Z = harq_process->Z; } kb = harq_process->K/harq_process->Z; - if ( kb==22){ - p_decParams->BG = 1; - p_decParams->R = 13; - kc = 68; - } - else{ - p_decParams->BG = 2; - p_decParams->R = 13; - kc = 52; - } + if ( kb==22){ + p_decParams->BG = 1; + p_decParams->R = 13; + kc = 68; + } + else{ + p_decParams->BG = 2; + p_decParams->R = 13; + kc = 52; + } p_decParams->numMaxIter = 2; Kr = p_decParams->Z*kb; @@ -1510,14 +1502,14 @@ void *nr_dlsch_decoding_2thread0(void *arg) Cprime = C; //assume CBGTI not present if (r <= Cprime - ((G/(Nl*Qm))%Cprime) - 1) - r_offset = Nl*Qm*(G/(Nl*Qm*Cprime)); + r_offset = Nl*Qm*(G/(Nl*Qm*Cprime)); else - r_offset = Nl*Qm*((G/(Nl*Qm*Cprime))+1); + r_offset = Nl*Qm*((G/(Nl*Qm*Cprime))+1); - // printf("thread0 r_offset %d\n",r_offset); - + // printf("thread0 r_offset %d\n",r_offset); + //for (r=(harq_process->C/2); rC; r++) { - r=1; //(harq_process->C/2); + r=1; //(harq_process->C/2); Kr = harq_process->K; @@ -1537,7 +1529,7 @@ void *nr_dlsch_decoding_2thread0(void *arg) dlsch_llr+r_offset); //for (int i =0; i<16; i++) - // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); + // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); #if UE_TIMING_TRACE stop_meas(dlsch_deinterleaving_stats); @@ -1582,7 +1574,7 @@ void *nr_dlsch_decoding_2thread0(void *arg) } //for (int i =0; i<16; i++) - // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); + // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); //r_offset += E; @@ -1616,10 +1608,10 @@ void *nr_dlsch_decoding_2thread0(void *arg) Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS, harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_ldpc_iterations); */ - if (llr8_flag1) { - AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", - Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); - } + if (llr8_flag1) { + AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", + Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); + } #if UE_TIMING_TRACE start_meas(dlsch_turbo_decoding_stats); #endif @@ -1634,58 +1626,58 @@ void *nr_dlsch_decoding_2thread0(void *arg) memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) - { + for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) + { - pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); - } + } - no_iteration_ldpc = nrLDPC_decoder(p_decParams, - (int8_t*)&pl[0], - llrProcBuf, + no_iteration_ldpc = nrLDPC_decoder(p_decParams, + (int8_t*)&pl[0], + llrProcBuf, p_nrLDPC_procBuf, - p_procTime); + p_procTime); - if (no_iteration_ldpc > 10) - printf("Error number of iteration LPDC %d\n", no_iteration_ldpc); - //else - //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); + if (no_iteration_ldpc > 10) + printf("Error number of iteration LPDC %d\n", no_iteration_ldpc); + //else + //printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); - for (int m=0; m < Kr>>3; m ++) - { - harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; - } + for (int m=0; m < Kr>>3; m ++) + { + harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; + } - /*for (int u=0; u < Kr>>3; u ++) - { - ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; - } + /*for (int u=0; u < Kr>>3; u ++) + { + ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; + } - printf("output unsigned ullrProcBuf \n"); + printf("output unsigned ullrProcBuf \n"); - for (int j=0; j < Kr>>3; j ++) - { + for (int j=0; j < Kr>>3; j ++) + { - printf(" %d \n", ullrProcBuf[j]); + printf(" %d \n", ullrProcBuf[j]); - } - printf(" \n");*/ -#ifdef DEBUG_DLSCH_DECODING - for (int k=0;k<2;k++) - printf("segment 1 output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); + } + printf(" \n");*/ +#ifdef DEBUG_DLSCH_DECODING + for (int k=0;k<2;k++) + printf("segment 1 output decoder [%d] = 0x%02x \n", k, harq_process->c[r][k]); #endif - + #if UE_TIMING_TRACE stop_meas(dlsch_turbo_decoding_stats); #endif @@ -1818,7 +1810,7 @@ void *nr_dlsch_decoding_2thread0(void *arg) #define FIFO_PRIORITY 39 void *nr_dlsch_decoding_2thread1(void *arg) { - static __thread int UE_dlsch_td_retval1; + static __thread int UE_dlsch_td_retval1; struct nr_rxtx_thread_data *rtd = arg; UE_nr_rxtx_proc_t *proc = rtd->proc; PHY_VARS_NR_UE *phy_vars_ue = rtd->UE; @@ -1860,14 +1852,14 @@ void *nr_dlsch_decoding_2thread1(void *arg) char threadname[256]; sprintf(threadname,"UE_thread_dlsch_td1_%d", proc->sub_frame_start); - cpu_set_t cpuset; + cpu_set_t cpuset; CPU_ZERO(&cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.dlsch_td_one != -1 ) - CPU_SET(threads.dlsch_td_one, &cpuset); + CPU_SET(threads.dlsch_td_one, &cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.dlsch_td_two != -1 ) - CPU_SET(threads.dlsch_td_two, &cpuset); + CPU_SET(threads.dlsch_td_two, &cpuset); if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.dlsch_td_three != -1 ) - CPU_SET(threads.dlsch_td_three, &cpuset); + CPU_SET(threads.dlsch_td_three, &cpuset); @@ -1881,51 +1873,51 @@ void *nr_dlsch_decoding_2thread1(void *arg) uint32_t ret,offset; uint32_t r,r_offset=0,Kr,Kr_bytes,err_flag=0,K_bytes_F; uint8_t crc_type; - uint8_t C,Cprime; + uint8_t C,Cprime; uint8_t Qm; - uint8_t Nl; + uint8_t Nl; //uint32_t Er; - init_thread(900000,1000000 , FIFO_PRIORITY-1, &cpuset, threadname); - printf("2thread1 oai_exit %d\n", oai_exit); - while (!oai_exit) { - if (pthread_mutex_lock(&proc->mutex_dlsch_td1) != 0) { - LOG_E( PHY, "[SCHED][UE] error locking mutex for UE dlsch td\n" ); - exit_fun("nothing to add"); - } - while (proc->instance_cnt_dlsch_td1 < 0) { - // most of the time, the thread is waiting here - pthread_cond_wait( &proc->cond_dlsch_td1, &proc->mutex_dlsch_td1 ); - } - if (pthread_mutex_unlock(&proc->mutex_dlsch_td1) != 0) { - LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE dlsch_td \n" ); - exit_fun("nothing to add"); - } + init_thread(900000,1000000 , FIFO_PRIORITY-1, &cpuset, threadname); + printf("2thread1 oai_exit %d\n", oai_exit); + while (!oai_exit) { + if (pthread_mutex_lock(&proc->mutex_dlsch_td1) != 0) { + LOG_E( PHY, "[SCHED][UE] error locking mutex for UE dlsch td\n" ); + exit_fun("nothing to add"); + } + while (proc->instance_cnt_dlsch_td1 < 0) { + // most of the time, the thread is waiting here + pthread_cond_wait( &proc->cond_dlsch_td1, &proc->mutex_dlsch_td1 ); + } + if (pthread_mutex_unlock(&proc->mutex_dlsch_td1) != 0) { + LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE dlsch_td \n" ); + exit_fun("nothing to add"); + } - //printf("2thread1 main available %d\n", proc->decoder_main_available); + //printf("2thread1 main available %d\n", proc->decoder_main_available); - uint32_t wait = 0; - while(proc->decoder_main_available == 0) - { - usleep(1); - wait++; - } - - //proc->decoder_thread_available1 = 0; - //PHY_VARS_NR_UE *phy_vars_ue = tdp->UE; - int eNB_id = proc->eNB_id; - int harq_pid = proc->harq_pid; - llr8_flag1 = proc->llr8_flag; - //r_offset = proc->Er; - //UE_rxtx_proc_t *proc = tdp->proc; - int frame = proc->frame_rx; - int subframe = proc->nr_tti_rx; - NR_UE_DLSCH_t *dlsch = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]; - NR_DL_UE_HARQ_t *harq_process = dlsch->harq_processes[harq_pid]; - short *dlsch_llr = phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr[0]; - //printf("2thread0 llr flag %d tdp flag %d\n",llr8_flag1, tdp->llr8_flag); - //printf("2thread1 nr_tti_tx %d subframe %d SF thread id %d r_offset %d\n", proc->nr_tti_rx, subframe, phy_vars_ue->current_thread_id[subframe], r_offset); - p_nrLDPC_procBuf = harq_process->p_nrLDPC_procBuf[2]; + uint32_t wait = 0; + while(proc->decoder_main_available == 0) + { + usleep(1); + wait++; + } + + //proc->decoder_thread_available1 = 0; + //PHY_VARS_NR_UE *phy_vars_ue = tdp->UE; + int eNB_id = proc->eNB_id; + int harq_pid = proc->harq_pid; + llr8_flag1 = proc->llr8_flag; + //r_offset = proc->Er; + //UE_rxtx_proc_t *proc = tdp->proc; + int frame = proc->frame_rx; + int subframe = proc->nr_tti_rx; + NR_UE_DLSCH_t *dlsch = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]; + NR_DL_UE_HARQ_t *harq_process = dlsch->harq_processes[harq_pid]; + short *dlsch_llr = phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr[0]; + //printf("2thread0 llr flag %d tdp flag %d\n",llr8_flag1, tdp->llr8_flag); + //printf("2thread1 nr_tti_tx %d subframe %d SF thread id %d r_offset %d\n", proc->nr_tti_rx, subframe, phy_vars_ue->current_thread_id[subframe], r_offset); + p_nrLDPC_procBuf = harq_process->p_nrLDPC_procBuf[2]; /* if (nb_rb > frame_parms->N_RB_DL) { @@ -1960,27 +1952,27 @@ void *nr_dlsch_decoding_2thread1(void *arg) // This is a new packet, so compute quantities regarding segmentation harq_process->B = A+24; nr_segmentation(NULL, - NULL, - harq_process->B, - &harq_process->C, - &harq_process->K, - &harq_process->Z, - &harq_process->F); - p_decParams->Z = harq_process->Z; + NULL, + harq_process->B, + &harq_process->C, + &harq_process->K, + &harq_process->Z, + &harq_process->F); + p_decParams->Z = harq_process->Z; } kb = harq_process->K/harq_process->Z; - if ( kb==22){ - p_decParams->BG = 1; - p_decParams->R = 89; - kc = 68; - } - else{ - p_decParams->BG = 2; - p_decParams->R = 13; - kc = 52; - } + if ( kb==22){ + p_decParams->BG = 1; + p_decParams->R = 89; + kc = 68; + } + else{ + p_decParams->BG = 2; + p_decParams->R = 13; + kc = 52; + } p_decParams->numMaxIter = 2; Kr = p_decParams->Z*kb; @@ -2025,23 +2017,23 @@ void *nr_dlsch_decoding_2thread1(void *arg) Cprime = C; //assume CBGTI not present if (r <= Cprime - ((G/(Nl*Qm))%Cprime) - 1) - r_offset = Nl*Qm*(G/(Nl*Qm*Cprime)); + r_offset = Nl*Qm*(G/(Nl*Qm*Cprime)); else - r_offset = Nl*Qm*((G/(Nl*Qm*Cprime))+1); + r_offset = Nl*Qm*((G/(Nl*Qm*Cprime))+1); - //printf("sub thread r_offset %d\n", r_offset); + //printf("sub thread r_offset %d\n", r_offset); //for (r=(harq_process->C/2); rC; r++) { - r=2; //(harq_process->C/2); - r_offset = r*r_offset; - //printf("thread1 r=%d r_offset %d \n",r, r_offset); + r=2; //(harq_process->C/2); + r_offset = r*r_offset; + //printf("thread1 r=%d r_offset %d \n",r, r_offset); - Kr = harq_process->K; - Kr_bytes = Kr>>3; - K_bytes_F = Kr_bytes-(harq_process->F>>3); + Kr = harq_process->K; + Kr_bytes = Kr>>3; + K_bytes_F = Kr_bytes-(harq_process->F>>3); - Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, harq_process->Nl); + Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, harq_process->Nl); E = nr_get_E(G, harq_process->C, harq_process->Qm, harq_process->Nl, r); @@ -2059,7 +2051,7 @@ void *nr_dlsch_decoding_2thread1(void *arg) dlsch_llr+r_offset); //for (int i =0; i<16; i++) - // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); + // printf("rx output deinterleaving w[%d]= %d r_offset %d\n", i,harq_process->w[r][i], r_offset); #if UE_TIMING_TRACE stop_meas(dlsch_deinterleaving_stats); @@ -2082,15 +2074,15 @@ void *nr_dlsch_decoding_2thread1(void *arg) #endif if (nr_rate_matching_ldpc_rx(Ilbrm, - Tbslbrm, - p_decParams->BG, - p_decParams->Z, - harq_process->d[r], - harq_process->w[r], - harq_process->C, - harq_process->rvidx, - (harq_process->round==0)?1:0, - E)==-1) { + Tbslbrm, + p_decParams->BG, + p_decParams->Z, + harq_process->d[r], + harq_process->w[r], + harq_process->C, + harq_process->rvidx, + (harq_process->round==0)?1:0, + E)==-1) { #if UE_TIMING_TRACE stop_meas(dlsch_rate_unmatching_stats); #endif @@ -2104,7 +2096,7 @@ void *nr_dlsch_decoding_2thread1(void *arg) } //for (int i =0; i<16; i++) - // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); + // printf("rx output ratematching d[%d]= %d r_offset %d\n", i,harq_process->d[r][i], r_offset); //r_offset += E; @@ -2136,71 +2128,71 @@ void *nr_dlsch_decoding_2thread1(void *arg) Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS, harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_ldpc_iterations); */ - if (llr8_flag1) { - AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", - Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); - } + if (llr8_flag1) { + AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", + Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); + } #if UE_TIMING_TRACE start_meas(dlsch_turbo_decoding_stats); #endif // LOG_D(PHY,"AbsSubframe %d.%d Start turbo segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1); - memset(pv,0,2*p_decParams->Z*sizeof(int16_t)); + memset(pv,0,2*p_decParams->Z*sizeof(int16_t)); //memset(pl,0,2*p_decParams->Z*sizeof(int8_t)); - memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); + memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) - { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); - } + for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) + { + pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + } - for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) - { + for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) + { - pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); + pl[j] = _mm_packs_epi16(pv[i],pv[i+1]); - } + } - no_iteration_ldpc = nrLDPC_decoder(p_decParams, - (int8_t*)&pl[0], - llrProcBuf, + no_iteration_ldpc = nrLDPC_decoder(p_decParams, + (int8_t*)&pl[0], + llrProcBuf, p_nrLDPC_procBuf, - p_procTime); + p_procTime); - if (no_iteration_ldpc > 10) - printf("Error number of iteration LPDC %d\n", no_iteration_ldpc); - //else - // printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); + if (no_iteration_ldpc > 10) + printf("Error number of iteration LPDC %d\n", no_iteration_ldpc); + //else + // printf("OK number of iteration LPDC %d\n", no_iteration_ldpc); - for (int m=0; m < Kr>>3; m ++) - { - harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; - } + for (int m=0; m < Kr>>3; m ++) + { + harq_process->c[r][m]= (uint8_t) llrProcBuf[m]; + } - /*for (int u=0; u < Kr>>3; u ++) - { - ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; - } + /*for (int u=0; u < Kr>>3; u ++) + { + ullrProcBuf[u]= (uint8_t) llrProcBuf[u]; + } - printf("output unsigned ullrProcBuf \n"); + printf("output unsigned ullrProcBuf \n"); - for (int j=0; j < Kr>>3; j ++) - { + for (int j=0; j < Kr>>3; j ++) + { - printf(" %d \n", ullrProcBuf[j]); + printf(" %d \n", ullrProcBuf[j]); - } - printf(" \n");*/ + } + printf(" \n");*/ #endif - //printf("output channel decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); + //printf("output channel decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); - //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); + //printf("output decoder %d %d %d %d %d \n", harq_process->c[r][0], harq_process->c[r][1], harq_process->c[r][2],harq_process->c[r][3], harq_process->c[r][4]); #if UE_TIMING_TRACE stop_meas(dlsch_turbo_decoding_stats); @@ -2239,7 +2231,7 @@ void *nr_dlsch_decoding_2thread1(void *arg) //printf("end 2thread1 proc->instance_cnt_dlsch_td1 %d\n", proc->instance_cnt_dlsch_td1); } - //printf("after 2thread1 after oai exit proc->instance_cnt_dlsch_td %d\n", proc->instance_cnt_dlsch_td1); + //printf("after 2thread1 after oai exit proc->instance_cnt_dlsch_td %d\n", proc->instance_cnt_dlsch_td1); // thread finished free(arg); return &UE_dlsch_td_retval1; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 4e46903ebf..b4b7463e18 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -42,8 +42,6 @@ - - void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch) { int i; @@ -88,6 +86,8 @@ void free_nr_ue_ulsch(NR_UE_ULSCH_t *ulsch) } + + NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, uint8_t abstraction_flag) { diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 2b36a03e61..29c4fed74d 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -404,7 +404,7 @@ int main(int argc, char **argv) { r_im[i] = malloc(frame_length_complex_samples * sizeof(double)); bzero(r_im[i], frame_length_complex_samples * sizeof(double)); txdata[i] = malloc(frame_length_complex_samples * sizeof(int)); - bzero(r_re[i], frame_length_complex_samples * sizeof(int)); + bzero(r_re[i], frame_length_complex_samples * sizeof(int)); // [hna] r_re should be txdata } if (pbch_file_fd != NULL) { @@ -480,7 +480,7 @@ int main(int argc, char **argv) { rel15->nb_layers = Nl; rel15->nb_re_dmrs = nb_re_dmrs; rel15->transport_block_size = TBS; - double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); + double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); // [hna] 16 segments, 68*Zc short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); double errors_bit_uncoded = 0; From d7abeed6abbc61b63ba45dbbe7f49f825a51a7c2 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Wed, 6 Mar 2019 16:48:37 +0100 Subject: [PATCH 030/117] Applying LDPC code rate fix at nr_ulsch_encoding --- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index b4b7463e18..70a34f2c66 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -200,18 +200,19 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, NR_UL_UE_HARQ_t *harq_process; uint16_t nb_rb ; uint8_t nb_symb_sch ; - uint32_t A, Z; + uint32_t A, Z, F; uint32_t *pz; uint8_t mod_order; uint16_t Kr,r,r_offset,Kr_bytes; uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; - uint8_t kb,BG; + uint8_t BG; uint32_t E; uint8_t Ilbrm; uint32_t Tbslbrm; uint8_t nb_re_dmrs; uint16_t length_dmrs; int i; + float Coderate; /////////// /////////////////////////////////////////////////////////////////////////////////////// @@ -230,10 +231,12 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, Kr=0; r_offset=0; BG = 1; + F=0; Ilbrm = 0; Tbslbrm = 950984; //max tbs nb_re_dmrs = ulsch->nb_re_dmrs; length_dmrs = 1; + Coderate = 0.0; /////////// ///////////////////////////////////////////////////////////////////////////////////////// @@ -251,7 +254,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs,mod_order,harq_process->Nl); - LOG_D(PHY,"dlsch coding A %d G %d mod_order %d\n", A,G, mod_order); + LOG_D(PHY,"ulsch coding A %d G %d mod_order %d\n", A,G, mod_order); printf("ulsch coding A %d G %d mod_order %d\n", A,G, mod_order); Tbslbrm = nr_compute_tbs(28,nb_rb,frame_parms->symbols_per_slot,0,0, harq_process->Nl); @@ -266,7 +269,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, /////////// /* int i; - printf("dlsch (tx): \n"); + printf("ulsch (tx): \n"); for (i=0;i<(A>>3);i++) printf("%02x.",a[i]); printf("\n"); @@ -297,13 +300,15 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, pz, &harq_process->F); - kb = harq_process->K/(*pz); - if ( kb==22){ - BG = 1; - } - else{ - BG = 2; - } + F = harq_process->F; + Coderate = (float) A /(float) G; + + if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25){ + BG = 2; + } + else{ + BG = 1; + } Kr = harq_process->K; Kr_bytes = Kr>>3; @@ -316,7 +321,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, ///////////////////////// c---->| LDCP coding |---->d ///////////////////////// /////////// - //printf("segment Z %d kb %d k %d Kr %d BG %d\n", *pz,kb,harq_process->K,Kr,BG); + //printf("segment Z %d k %d Kr %d BG %d\n", *pz,harq_process->K,Kr,BG); //start_meas(te_stats); for (r=0; rC; r++) { @@ -364,6 +369,15 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, } for (r=0; rC; r++) { // looping over C segments + + if (harq_process->F>0) { + for (int k=(Kr-F-2*(*pz)); kd[r][k] = NR_NULL; + //if (k<(Kr-F+8)) + //printf("r %d filler bits [%d] = %d \n", r,k, harq_process->d[r][k]); + } + } + #ifdef DEBUG_DLSCH_CODING printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n", r, From a1da7a2f9555965b7edf8bccd2422e4b1d73b384 Mon Sep 17 00:00:00 2001 From: Ahmed Hussein Date: Wed, 6 Mar 2019 18:32:20 +0100 Subject: [PATCH 031/117] Applying LDPC code fix at "nr_ulsch_decoding.c" (works for mcs 4 to 28) --- openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index 1d72507de9..ace93e4ee3 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -187,7 +187,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, uint32_t A,E; uint32_t G; uint32_t ret,offset; - int32_t no_iteration_ldpc; + int32_t no_iteration_ldpc, length_dec; uint32_t r,r_offset=0,Kr=8424,Kr_bytes,K_bytes_F,err_flag=0; uint8_t crc_type; int8_t llrProcBuf[OAI_UL_LDPC_MAX_NUM_LLR] __attribute__ ((aligned(32))); @@ -206,12 +206,13 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, int16_t z [68*384]; int8_t l [68*384]; int16_t inv_d [68*384]; - uint8_t kb, kc; + uint8_t kc; uint8_t Ilbrm = 0; uint32_t Tbslbrm = 950984; uint16_t nb_rb = 30; //to update uint8_t nb_re_dmrs = 6; uint16_t length_dmrs = 1; + double Coderate = 0.0; uint32_t i,j; @@ -249,6 +250,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, LOG_I(PHY,"ULSCH Decoding, harq_pid %d TBS %d G %d mcs %d Nl %d nb_symb_sch %d nb_rb %d\n",harq_pid,A,G, nfapi_ulsch_pdu_rel15->mcs, nfapi_ulsch_pdu_rel15->n_layers, nb_symb_sch,nb_rb); if (harq_process->round == 0) { + // This is a new packet, so compute quantities regarding segmentation harq_process->B = A+24; @@ -270,20 +272,43 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, #endif } - kb = harq_process->K/harq_process->Z; + Coderate = (float) A /(float) G; - if ( kb==22) { - p_decParams->BG = 1; - p_decParams->R = 13; - kc = 68; - } else { + if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25){ p_decParams->BG = 2; - p_decParams->R = 13; - kc = 52; + if (Coderate < 0.3333) { + p_decParams->R = 15; + kc = 52; + } + else if (Coderate <0.6667) { + p_decParams->R = 13; + kc = 32; + } + else { + p_decParams->R = 23; + kc = 17; + } + } else { + p_decParams->BG = 1; + if (Coderate < 0.6667) { + p_decParams->R = 13; + kc = 68; + } + else if (Coderate <0.8889) { + p_decParams->R = 23; + kc = 35; + } + else { + p_decParams->R = 89; + kc = 27; + } } + //printf("coderate %f kc %d \n", Coderate, kc); + + + p_decParams->numMaxIter = ulsch->max_ldpc_iterations; - Kr = p_decParams->Z*kb; p_decParams->outMode= 0; err_flag = 0; @@ -410,10 +435,14 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, memset(harq_process->c[r],0,Kr_bytes); // printf("done\n"); - if (harq_process->C == 1) + if (harq_process->C == 1) { crc_type = CRC24_A; - else + length_dec = harq_process->B; + } + else { crc_type = CRC24_B; + length_dec = (harq_process->B+24*harq_process->C)/harq_process->C; + } if (err_flag == 0) { @@ -421,19 +450,18 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, start_meas(ulsch_turbo_decoding_stats); #endif - for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++) { - inv_d[cnt] = (1)*harq_process->d[r][cnt]; - } + //LOG_E(PHY,"AbsSubframe %d.%d Start LDPC segment %d/%d A %d ",frame%1024,nr_tti_rx,r,harq_process->C-1, A); + memset(pv,0,2*harq_process->Z*sizeof(int16_t)); memset((pv+K_bytes_F),127,harq_process->F*sizeof(int16_t)); - for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F+((2*p_decParams->Z)>>3); i++, j++) { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + for (i=((2*p_decParams->Z)>>3), j = 0; i < K_bytes_F; i++, j++) { + pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); } - for (i=Kr_bytes+((2*p_decParams->Z)>>3),j=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++, j++) { - pv[i]= _mm_loadu_si128((__m128i*)(&inv_d[8*j])); + for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++) { + pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j])); } for (i=0, j=0; j < ((kc*p_decParams->Z)>>4); i+=2, j++) { @@ -455,8 +483,8 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, p_nrLDPC_procBuf[r], p_procTime); - if (check_crc(llrProcBuf,harq_process->B,harq_process->F,crc_type)) { - printf("CRC OK\n"); + if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) { + printf("Segment %d CRC OK\n",r); ret = 2; } else { printf("CRC NOK\n"); From af59ee996d742ce3bb50c982130374da210e6670 Mon Sep 17 00:00:00 2001 From: Khalid Ahmed Date: Wed, 13 Feb 2019 12:45:01 +0100 Subject: [PATCH 032/117] Add build directories to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1ed392ef06..61d9558916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cmake_targets/log/ cmake_targets/ran_build/ +cmake_targets/*/build/ targets/bin/ From 980d20c8b8cbcd3560f2688cbfa7c828acb73dc3 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 7 Mar 2019 15:45:52 +0100 Subject: [PATCH 033/117] i_ssb detection message added in pbchsim --- openair1/SIMULATION/NR_PHY/pbchsim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index cc01357868..548a4f3dc3 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -412,7 +412,6 @@ int main(int argc, char **argv) // computation of integer and fractional FO to compare with estimation results int IFO; if(eps!=0.0){ - UE->UE_fo_compensation = 1; printf("Introducing a CFO of %lf relative to SCS of %d kHz\n",eps,(int)(scs/1000)); if (eps>0) IFO=(int)(eps+0.5); @@ -644,11 +643,11 @@ int main(int argc, char **argv) if (ret!=0) n_errors++; } } //noise trials - printf("SNR %f: trials %d, n_errors_crc = %d, n_errors_payload %d\n", SNR,n_trials,n_errors,n_errors_payload); if (((float)n_errors/(float)n_trials <= target_error_rate) && (n_errors_payload==0)) { printf("PBCH test OK\n"); + printf("Synchronization obtained for i_ssb = %d\n",UE->rx_ind.rx_indication_body[0].mib_pdu.ssb_index); break; } From dd61e5a71739f9c92f9c11de7e59d8b4b2ec8da0 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Fri, 8 Mar 2019 15:44:50 +0100 Subject: [PATCH 034/117] Working short block coding and various warning removals in --phy_simulators --- cmake_targets/CMakeLists.txt | 13 +- openair1/PHY/CODING/TESTBENCH/ldpctest.c | 8 +- openair1/PHY/CODING/TESTBENCH/polartest.c | 83 +++-- .../PHY/CODING/TESTBENCH/smallblocktest.c | 169 ++++++++++ .../nrPolar_tools/nr_bitwise_operations.c | 6 +- .../CODING/nrPolar_tools/nr_polar_decoder.c | 308 ++---------------- .../nrPolar_tools/nr_polar_decoding_tools.c | 127 ++++---- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 284 +++++++--------- .../CODING/nrPolar_tools/nr_polar_encoder.c | 14 +- .../nrPolar_tools/nr_polar_procedures.c | 42 ++- .../CODING/nrSmallBlock/decodeSmallBlock.c | 117 +++++++ .../PHY/CODING/nrSmallBlock/encodeSmall.c | 0 .../CODING/nrSmallBlock/encodeSmallBlock.c | 44 +++ .../CODING/nrSmallBlock/nr_small_block_defs.h | 134 ++++++++ openair1/PHY/CODING/nr_polar_init.c | 19 +- 15 files changed, 766 insertions(+), 602 deletions(-) create mode 100644 openair1/PHY/CODING/TESTBENCH/smallblocktest.c create mode 100644 openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c delete mode 100644 openair1/PHY/CODING/nrSmallBlock/encodeSmall.c create mode 100644 openair1/PHY/CODING/nrSmallBlock/encodeSmallBlock.c create mode 100644 openair1/PHY/CODING/nrSmallBlock/nr_small_block_defs.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index c4e2399351..668c3acc2e 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1143,15 +1143,19 @@ set(PHY_POLARSRC ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_procedures.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_sequence_pattern.c ) +set(PHY_SMALLBLOCKSRC + ${OPENAIR1_DIR}/PHY/CODING/nrSmallBlock/encodeSmallBlock.c + ${OPENAIR1_DIR}/PHY/CODING/nrSmallBlock/decodeSmallBlock.c +) set(PHY_TURBOIF ${OPENAIR1_DIR}/PHY/CODING/coding_load.c - ) +) set(PHY_LDPCSRC ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c - ) +) add_library(coding MODULE ${PHY_TURBOSRC} ) @@ -1326,6 +1330,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/TOOLS/time_meas.c ${OPENAIR1_DIR}/PHY/TOOLS/lut.c ${PHY_POLARSRC} + ${PHY_SMALLBLOCKSRC} ${PHY_LDPCSRC} ) @@ -1372,6 +1377,7 @@ set(PHY_SRC_UE ${OPENAIR1_DIR}/PHY/INIT/nr_init_ue.c # ${OPENAIR1_DIR}/SIMULATION/NR_UE_PHY/unit_tests/src/pucch_uci_test.c ${PHY_POLARSRC} + ${PHY_SMALLBLOCKSRC} ${PHY_LDPCSRC} ) @@ -2558,6 +2564,9 @@ target_link_libraries (dlsim_tm4 add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c) target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) +add_executable(smallblocktest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c) +target_link_libraries(smallblocktest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) + add_executable(ldpctest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c) target_link_libraries(ldpctest SIMU PHY PHY_NR m ${ATLAS_LIBRARIES}) diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c index 6db9548dbe..d8ba986175 100644 --- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c +++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c @@ -382,12 +382,12 @@ int test_ldpc(short No_iteration, //Uncoded BER if (channel_output_fixed[j][i]<0) - channel_output_uncoded[j][i]=1; //QPSK demod - else - channel_output_uncoded[j][i]=0; + channel_output_uncoded[j][i]=1; //QPSK demod + else + channel_output_uncoded[j][i]=0; if (channel_output_uncoded[j][i] != channel_input[j][i-2*Zc]) - *errors_bit_uncoded = (*errors_bit_uncoded) + 1; + *errors_bit_uncoded = (*errors_bit_uncoded) + 1; } } // End segments diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index e4b4758493..72ef16907c 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -62,7 +62,6 @@ int main(int argc, char *argv[]) { int16_t nBitError = 0; // -1 = Decoding failed (All list entries have failed the CRC checks). uint32_t decoderState=0, blockErrorState=0; //0 = Success, -1 = Decoding failed, 1 = Block Error. uint16_t testLength = 0, coderLength = 0, blockErrorCumulative=0, bitErrorCumulative=0; - double timeEncoderCumulative = 0, timeDecoderCumulative = 0; uint8_t aggregation_level = 8, decoderListSize = 8, pathMetricAppr = 0, matlabDebug = 0; while ((arguments = getopt (argc, argv, "s:d:f:c:i:l:a:hqgm")) != -1) @@ -217,7 +216,7 @@ int main(int argc, char *argv[]) { memset(dci_estimation,0,sizeof(uint32_t)*4); printf("dci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]); - nr_bit2byte_uint32_8_t(encoder_output, currentPtrDCI->encoderLength, encoder_outputByte); + nr_bit2byte_uint32_8(encoder_output, currentPtrDCI->encoderLength, encoder_outputByte); printf("[polartest] encoder_outputByte: "); for (int i = 0; i < currentPtrDCI->encoderLength; i++) printf("%d-", encoder_outputByte[i]); printf("\n"); @@ -257,7 +256,7 @@ int main(int argc, char *argv[]) { uint32_t testInputcrc2=0x00291880; uint8_t testInputCRC2[8]; - nr_crc_bit2bit_uint32_8_t(testInputCRC, 32, testInputCRC2); + nr_crc_bit2bit_uint32_8(testInputCRC, 32, testInputCRC2); printf("testInputCRC2: [0]->%x \t [1]->%x \t [2]->%x \t [3]->%x\n" " [4]->%x \t [5]->%x \t [6]->%x \t [7]->%x\n", testInputCRC2[0], testInputCRC2[1], testInputCRC2[2], testInputCRC2[3], @@ -339,7 +338,7 @@ int main(int argc, char *argv[]) { for (int i=0; ipayloadBits; i++) aPrioriArray[i] = NAN; for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { - printf("SNR %f\n",SNR); + printf("SNR %f\n",SNR); SNR_lin = pow(10, SNR/10); for (itr = 1; itr <= iterations; itr++) { @@ -420,11 +419,11 @@ int main(int argc, char *argv[]) { uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS]; memset((void*)nr_pbch_interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS); nr_init_pbch_interleaver(nr_pbch_interleaver); - for (int i=0; i<=31;i++) + /*for (int i=0; i<=31;i++) printf("nr_pbch_interleaver[%d]=%d\n",i,nr_pbch_interleaver[i]); for (int i=0; i0x%08x\n", encoderOutput[1]);*/ //Bit-to-byte: - nr_bit2byte_uint32_8_t(encoderOutput, coderLength, encoderOutputByte); + nr_bit2byte_uint32_8(encoderOutput, coderLength, encoderOutputByte); //BPSK modulation for(int i=0; i 15) channelOutput_int16[i] = 127; - else if (channelOutput[i] < -16) channelOutput_int16[i] = -128; - else channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); + if (channelOutput[i] > 15) + channelOutput_int16[i] = 127; + else if (channelOutput[i] < -16) + channelOutput_int16[i] = -128; + else + channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); } - - } start_meas(&timeDecoder); @@ -466,44 +468,38 @@ int main(int argc, char *argv[]) { NR_POLAR_DECODER_LISTSIZE, aPrioriArray, NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION);*/ - if (decoder_int16==0) - decoderState = polar_decoder_aPriori(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - aPrioriArray); - else - decoderState = polar_decoder_int16(channelOutput_int16, - (uint64_t*)estimatedOutput, - currentPtr); - + if (decoder_int16 == 1) + decoderState = polar_decoder_int16(channelOutput_int16, + (uint64_t*) estimatedOutput, + currentPtr); + else + decoderState = polar_decoder_aPriori(channelOutput, + estimatedOutput, currentPtr, + NR_POLAR_DECODER_LISTSIZE, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, + aPrioriArray); stop_meas(&timeDecoder); /*printf("testInput: [0]->0x%08x\n", testInput[0]); printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]);*/ - //calculate errors if (decoderState!=0) { blockErrorState=-1; nBitError=-1; } else { - for (int j = 0; j < currentPtr->payloadBits; j++) { - if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) nBitError++; + for (int j = 0; j < currentPtr->payloadBits; j++) { + if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) + nBitError++; // printf("bit %d: %d => %d\n",j,(testInput[0]>>j)&1,(estimatedOutput[0]>>j)&1); - } - - - if (nBitError>0) { - blockErrorState=1; - // printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]); - } + } + if (nBitError>0) { + blockErrorState=1; + //printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]); + } } //Iteration times are in microseconds. - timeEncoderCumulative+=(timeEncoder.diff/(cpu_freq_GHz*1000.0)); - timeDecoderCumulative+=(timeDecoder.diff/(cpu_freq_GHz*1000.0)); fprintf(logFile,",%f,%d,%d,%f,%f\n", SNR, nBitError, blockErrorState, (timeEncoder.diff/(cpu_freq_GHz*1000.0)), (timeDecoder.diff/(cpu_freq_GHz*1000.0))); @@ -521,17 +517,16 @@ int main(int argc, char *argv[]) { } //Calculate error statistics for the SNR. - printf("[ListSize=%d, Appr=%d] SNR=%+8.3f, BLER=%9.6f, BER=%12.9f, t_Encoder=%9.3fus, t_Decoder=%9.3fus\n", + printf("[ListSize=%d, Appr=%d] SNR=%+8.3f, BLER=%9.6f, BER=%12.9f, t_Encoder=%12.6fus, t_Decoder=%12.6fus\n", decoderListSize, pathMetricAppr, SNR, ((double)blockErrorCumulative/iterations), ((double)bitErrorCumulative / (iterations*testLength)), - (double)timeEncoder.diff/timeEncoder.trials/(cpu_freq_GHz*1000.0),(double)timeDecoder.diff/timeDecoder.trials/(cpu_freq_GHz*1000.0)); - //(timeEncoderCumulative/iterations),timeDecoderCumulative/iterations); + (double)timeEncoder.diff/timeEncoder.trials/(cpu_freq_GHz*1000.0), + (double)timeDecoder.diff/timeDecoder.trials/(cpu_freq_GHz*1000.0)); if (blockErrorCumulative==0 && bitErrorCumulative==0) break; blockErrorCumulative = 0; bitErrorCumulative = 0; - timeEncoderCumulative = 0; timeDecoderCumulative = 0; } print_meas(&timeEncoder,"polar_encoder",NULL,NULL); diff --git a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c new file mode 100644 index 0000000000..7ffa3900a6 --- /dev/null +++ b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c @@ -0,0 +1,169 @@ +#include "PHY/CODING/nrSmallBlock/nr_small_block_defs.h" +#include "SIMULATION/TOOLS/sim.h" +#include + +//#define DEBUG_SMALLBLOCKTEST + +signed char quantize(double D, double x, unsigned char B) +{ + double qxd; + short maxlev; + qxd = floor(x/D); + + maxlev = 1<<(B-1);//(char)(pow(2,B-1)); + + if (qxd <= -maxlev) + qxd = -maxlev; + else if (qxd >= maxlev) + qxd = maxlev-1; + + return((char)qxd); +} + +int main(int argc, char *argv[]) { + + time_stats_t timeEncoder,timeDecoder; + opp_enabled=1; + cpu_freq_GHz = get_cpu_freq_GHz(); + reset_meas(&timeEncoder); + reset_meas(&timeDecoder); + randominit(0); + + int arguments, iterations = 1000, matlabDebug = 0, messageLength = 11; + uint32_t testInput, encoderOutput, codingDifference, nBitError=0, blockErrorState = 0, blockErrorCumulative=0, bitErrorCumulative=0; + uint16_t estimatedOutput; + double SNRstart = -20.0, SNRstop = 5.0, SNRinc= 0.5; //dB + double SNR, SNR_lin, sigma; + double modulatedInput[NR_SMALL_BLOCK_CODED_BITS], channelOutput[NR_SMALL_BLOCK_CODED_BITS]; + int16_t channelOutput_int16[NR_SMALL_BLOCK_CODED_BITS]; + int8_t channelOutput_int8[NR_SMALL_BLOCK_CODED_BITS]; + unsigned char qbits=8; + + while ((arguments = getopt (argc, argv, "s:d:f:l:i:mhg")) != -1) + switch (arguments) + { + case 's': + SNRstart = atof(optarg); + break; + + case 'd': + SNRinc = atof(optarg); + break; + + case 'f': + SNRstop = atof(optarg); + break; + + case 'l': + messageLength = atoi(optarg); + break; + + case 'i': + iterations = atoi(optarg); + break; + + case 'm': + matlabDebug = 1; + //#define DEBUG_POLAR_MATLAB + break; + + case 'g': + iterations = 1; + SNRstart = -6.0; + SNRstop = -6.0; + messageLength = 11; + break; + + case 'h': + printf("./smallblocktest -s SNRstart -d SNRinc -f SNRstop -l messageLength -i iterations -m Matlab Debug\n"); + exit(-1); + + default: + perror("[smallblocktest.c] Problem at argument parsing with getopt"); + exit(-1); + } + + + uint16_t mask = 0x07ff >> (11-messageLength); + for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { + printf("SNR %f\n",SNR); + SNR_lin = pow(10, SNR/10.0); + sigma = 1.0/sqrt(SNR_lin); + + for (int itr = 1; itr <= iterations; itr++) { + + //Generate random test input of length "messageLength" + testInput = 0; + for (int i = 1; i < messageLength; i++) { + testInput |= ( ((uint32_t) (rand()%2)) &1); + testInput<<=1; + } + testInput |= ( ((uint32_t) (rand()%2)) &1); + + //Encoding + start_meas(&timeEncoder); + encoderOutput = encodeSmallBlock((uint16_t*)&testInput, (uint8_t)messageLength); + stop_meas(&timeEncoder); + + for (int i=0; i>i) & 1 ) { + modulatedInput[i]=-1; + } else { + modulatedInput[i]=1; + } + + //AWGN + channelOutput[i] = modulatedInput[i] + ( gaussdouble(0.0,1.0) * ( 1/sqrt(SNR_lin) ) ); + + //Quantization + channelOutput_int8[i] = quantize(sigma/16.0, channelOutput[i], qbits); + } + + //Decoding + start_meas(&timeDecoder); + estimatedOutput = decodeSmallBlock(channelOutput_int8, (uint8_t)messageLength); + stop_meas(&timeDecoder); + +#ifdef DEBUG_SMALLBLOCKTEST + printf("[smallblocktest] Input = 0x%x, Output = 0x%x, DecoderOutput = 0x%x\n", testInput, encoderOutput, estimatedOutput); + for (int i=0;i<32;i++) + printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, Mask[%d] = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (mask>>i)&1); +#endif + + //Error Calculation + estimatedOutput &= mask; + codingDifference = ((uint32_t)estimatedOutput) ^ testInput; // Count the # of 1's in codingDifference by Brian Kernighan’s algorithm. + + //for (int i=0;i<32;i++) + //printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, codingDifference[%d]=%d, Mask[%d] = %d, bitError = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (codingDifference>>i)&1, i, (mask>>i)&1, nBitError); + + + for (nBitError = 0; codingDifference; nBitError++) + codingDifference &= codingDifference - 1; + + blockErrorState = (nBitError > 0) ? 1 : 0; + + blockErrorCumulative+=blockErrorState; + bitErrorCumulative+=nBitError; + + nBitError = 0; blockErrorState = 0; + } + + //Error statistics for the SNR; iteration times are in nanoseconds and microseconds, respectively. + printf("[smallblocktest] SNR=%+7.3f, BER=%9.6f, BLER=%9.6f, t_Encoder=%9.3fns, t_Decoder=%7.3fus\n", + SNR, + ((double)bitErrorCumulative / (iterations*messageLength)), + ((double)blockErrorCumulative/iterations), + ((double)timeEncoder.diff/timeEncoder.trials)/(cpu_freq_GHz), + ((double)timeDecoder.diff/timeDecoder.trials)/(cpu_freq_GHz*1000.0)); + + blockErrorCumulative=0; + bitErrorCumulative=0; + } + + print_meas(&timeEncoder, "smallblock_encoder", NULL, NULL); + print_meas(&timeDecoder, "smallblock_decoder", NULL, NULL); + + return (0); +} diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c index beabeead36..a5e78b6f2b 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c @@ -21,7 +21,7 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" -void nr_bit2byte_uint32_8_t(uint32_t *in, uint16_t arraySize, uint8_t *out) { +void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { uint8_t arrayInd = ceil(arraySize / 32.0); for (int i = 0; i < (arrayInd-1); i++) { for (int j = 0; j < 32; j++) { @@ -32,7 +32,7 @@ void nr_bit2byte_uint32_8_t(uint32_t *in, uint16_t arraySize, uint8_t *out) { for (int j = 0; j < arraySize - ((arrayInd-1) * 32); j++) out[j + ((arrayInd-1) * 32)] = (in[(arrayInd-1)] >> j) & 1; } -void nr_byte2bit_uint8_32_t(uint8_t *in, uint16_t arraySize, uint32_t *out) { +void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out) { uint8_t arrayInd = ceil(arraySize / 32.0); for (int i = 0; i < arrayInd; i++) { out[i]=0; @@ -44,7 +44,7 @@ void nr_byte2bit_uint8_32_t(uint8_t *in, uint16_t arraySize, uint32_t *out) { } } -void nr_crc_bit2bit_uint32_8_t(uint32_t *in, uint16_t arraySize, uint8_t *out) { +void nr_crc_bit2bit_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { out[0]=0xff; out[1]=0xff; out[2]=0xff; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 305a9c6266..b754bda1f9 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -39,12 +39,11 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" -int8_t polar_decoder( - double *input, - uint8_t *out, - t_nrPolar_paramsPtr polarParams, - uint8_t listSize, - uint8_t pathMetricAppr) +int8_t polar_decoder(double *input, + uint8_t *out, + t_nrPolar_paramsPtr polarParams, + uint8_t listSize, + uint8_t pathMetricAppr) { //Assumes no a priori knowledge. @@ -276,18 +275,18 @@ int8_t polar_decoder( /* * Return bits. */ - //nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + //nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); return(0); } int8_t polar_decoder_aPriori(double *input, - uint32_t *out, - t_nrPolar_paramsPtr polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload) + uint32_t *out, + t_nrPolar_paramsPtr polarParams, + uint8_t listSize, + uint8_t pathMetricAppr, + double *aPrioriPayload) { - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); + uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); @@ -528,269 +527,10 @@ int8_t polar_decoder_aPriori(double *input, /* * Return bits. */ - nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); - - return(0); - -} - - - -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *out, - t_nrPolar_paramsPtr polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE* logFile) -{ - - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize); - double *pathMetric = malloc(sizeof(double)*(2*listSize)); - uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True - - for (int i=0; i<(2*listSize); i++) { - pathMetric[i] = 0; - crcState[i]=1; - } - for (int i=0; iN; i++) { - llrUpdated[i][polarParams->n]=1; - bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2); - } - - uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3 - uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2 - for (int i = 0; i < polarParams->K; i++){ - extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - } - - for (int i=0; ipayloadBits; i++) { - for (int j=0; jcrcParityBits; j++) { - tempECGM[i][j]=polarParams->crc_generator_matrix[i][j]; - } - } - for (int i=polarParams->payloadBits; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - if( (i-polarParams->payloadBits) == j ){ - tempECGM[i][j]=1; - } else { - tempECGM[i][j]=0; - } - } - } - - for (int i=0; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j]; - } - } - - //The index of the last 1-valued bit that appears in each column. - uint16_t last1ind[polarParams->crcParityBits]; - for (int j=0; jcrcParityBits; j++) { - for (int i=0; iK; i++) { - if (extended_crc_generator_matrix[i][j]==1) last1ind[j]=i; - } - } - - double *d_tilde = malloc(sizeof(double) * polarParams->N); - nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); - for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j]; - - - /* - * SCL polar decoder. - */ - - uint32_t nonFrozenBit=0; - uint8_t currentListSize=1; - uint8_t decoderIterationCheck=0; - int16_t checkCrcBits=-1; - uint8_t listIndex[2*listSize], copyIndex; - - for (uint16_t currentBit=0; currentBitN; currentBit++){ - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); - if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 - } else { //Information or CRC bit. - if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 0) ) { - //Information bit with known value of "0". - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); - bitUpdated[currentBit][0]=1; //0=False, 1=True - } else if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 1) ) { - //Information bit with known value of "1". - updatePathMetric(pathMetric, llr, currentListSize, 1, currentBit, pathMetricAppr); - for (uint8_t i=0; icrcParityBits); - } else { - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); - - for (int i = 0; i < currentListSize; i++) { - for (int j = 0; j < polarParams->N; j++) { - for (int k = 0; k < (polarParams->n+1); k++) { - bit[j][k][i+currentListSize]=bit[j][k][i]; - llr[j][k][i+currentListSize]=llr[j][k][i];}}} - for (int i = 0; i < currentListSize; i++) { - bit[currentBit][0][i]=0; - crcState[i+currentListSize]=crcState[i]; - } - for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1; - bitUpdated[currentBit][0]=1; - updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); - currentListSize*=2; - - //Keep only the best "listSize" number of entries. - if (currentListSize > listSize) { - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - - //sort listIndex[listSize, ..., 2*listSize-1] in descending order. - uint8_t swaps, tempInd; - for (uint8_t i = 0; i < listSize; i++) { - swaps = 0; - for (uint8_t j = listSize; j < (2*listSize - i) - 1; j++) { - if (listIndex[j+1] > listIndex[j]) { - tempInd = listIndex[j]; - listIndex[j] = listIndex[j + 1]; - listIndex[j + 1] = tempInd; - swaps++; - } - } - if (swaps == 0) - break; - } - - //First, backup the best "listSize" number of entries. - for (int k=(listSize-1); k>0; k--) { - for (int i=0; iN; i++) { - for (int j=0; j<(polarParams->n+1); j++) { - bit[i][j][listIndex[(2*listSize-1)-k]]=bit[i][j][listIndex[k]]; - llr[i][j][listIndex[(2*listSize-1)-k]]=llr[i][j][listIndex[k]]; - } - } - } - for (int k=(listSize-1); k>0; k--) { - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][listIndex[(2*listSize-1)-k]] = crcChecksum[i][listIndex[k]]; - } - } - for (int k=(listSize-1); k>0; k--) crcState[listIndex[(2*listSize-1)-k]]=crcState[listIndex[k]]; - - //Copy the best "listSize" number of entries to the first indices. - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - for (int i = 0; i < polarParams->N; i++) { - for (int j = 0; j < (polarParams->n + 1); j++) { - bit[i][j][k] = bit[i][j][copyIndex]; - llr[i][j][k] = llr[i][j][copyIndex]; - } - } - } - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][k]=crcChecksum[i][copyIndex]; - } - } - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - crcState[k]=crcState[copyIndex]; - } - currentListSize = listSize; - } - } - - for (int i=0; icrcParityBits; i++) { - if (last1ind[i]==nonFrozenBit) { - checkCrcBits=i; - break; - } - } - - if ( checkCrcBits > (-1) ) { - for (uint8_t i = 0; i < currentListSize; i++) { - if (crcChecksum[checkCrcBits][i]==1) { - crcState[i]=0; //0=False, 1=True - } - } - } - - for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i]; - if (decoderIterationCheck==0) { - //perror("[SCL polar decoder] All list entries have failed the CRC checks."); - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - return(-1); - } - - nonFrozenBit++; - decoderIterationCheck=0; - checkCrcBits=-1; - } - } - - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - - for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) { - if ( crcState[listIndex[i]] == 1 ) { - for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_U[j]=bit[j][0][listIndex[i]]; - - //Extract the information bits (û to ĉ) - nr_polar_info_bit_extraction(polarParams->nr_polar_U, polarParams->nr_polar_CPrime, polarParams->information_bit_pattern, polarParams->N); - - //Deinterleaving (ĉ to b) - nr_polar_deinterleaver(polarParams->nr_polar_CPrime, polarParams->nr_polar_B, polarParams->interleaving_pattern, polarParams->K); - - //Remove the CRC (â) - for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; - - break; - } - } - - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K); - nr_free_uint8_2D_array(tempECGM, polarParams->K); - - /* - * Return bits. - */ - nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); return(0); } - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_paramsPtr polarParams, @@ -798,7 +538,6 @@ int8_t polar_decoder_dci(double *input, uint8_t pathMetricAppr, uint16_t n_RNTI) { - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True @@ -1035,7 +774,7 @@ int8_t polar_decoder_dci(double *input, /* * Return bits. */ - nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); return(0); } @@ -1072,24 +811,20 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) { } uint32_t polar_decoder_int16(int16_t *input, - uint64_t *out, - t_nrPolar_params *polarParams) + uint64_t *out, + t_nrPolar_params *polarParams) { - - - int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N); nr_polar_rate_matching_int16(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); for (int i=0;iN;i++) { - if (d_tilde[i]<-128) d_tilde[i]=-128; - else if (d_tilde[i]>127) d_tilde[i]=128; + if (d_tilde[i]<-128) d_tilde[i]=-128; + else if (d_tilde[i]>127) d_tilde[i]=127; } memcpy((void*)&polarParams->tree.root->alpha[0],(void*)&d_tilde[0],sizeof(int16_t)*polarParams->N); - generic_polar_decoder(polarParams,polarParams->tree.root); - + generic_polar_decoder(polarParams, polarParams->tree.root); //Extract the information bits (û to ĉ) uint64_t Cprime[4]={0,0,0,0}; @@ -1117,7 +852,6 @@ uint32_t polar_decoder_int16(int16_t *input, } } - int len=polarParams->payloadBits; //int len_mod64=len&63; int crclen = polarParams->crcParityBits; @@ -1160,9 +894,5 @@ uint32_t polar_decoder_int16(int16_t *input, out[0]=Ar; - return(crc^rxcrc); - - - } diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index bec322b946..6ac29eb50b 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -37,15 +37,15 @@ //#define DEBUG_NEW_IMPL 1 void updateLLR(double ***llr, - uint8_t **llrU, - uint8_t ***bit, - uint8_t **bitU, - uint8_t listSize, - uint16_t row, - uint16_t col, - uint16_t xlen, - uint8_t ylen, - uint8_t approximation) + uint8_t **llrU, + uint8_t ***bit, + uint8_t **bitU, + uint8_t listSize, + uint16_t row, + uint16_t col, + uint16_t xlen, + uint8_t ylen, + uint8_t approximation) { uint16_t offset = (xlen/(pow(2,(ylen-col-1)))); for (uint8_t i=0; itree.num_nodes=0; + polarParams->tree.root = add_nodes(polarParams->n,0,polarParams); +#ifdef DEBUG_NEW_IMPL + printf("root : left %p, right %p\n",polarParams->tree.root->left,polarParams->tree.root->right); +#endif +} - -decoder_node_t *new_decoder_node(int first_leaf_index,int level) { +decoder_node_t *new_decoder_node(int first_leaf_index, int level) { decoder_node_t *node=(decoder_node_t *)malloc(sizeof(decoder_node_t)); @@ -208,32 +208,34 @@ decoder_node_t *new_decoder_node(int first_leaf_index,int level) { node->beta = (int16_t*)malloc16(node->Nv*sizeof(int16_t)); memset((void*)node->beta,-1,node->Nv*sizeof(int16_t)); - return(node); } -decoder_node_t *add_nodes(int level,int first_leaf_index,t_nrPolar_params *pp) { +decoder_node_t *add_nodes(int level, int first_leaf_index, t_nrPolar_params *polarParams) { - int all_frozen_below=1; + int all_frozen_below = 1; int Nv = 1<tree.num_nodes,Nv,level); + printf("New node %d order %d, level %d\n",polarParams->tree.num_nodes,Nv,level); #endif - pp->tree.num_nodes++; + polarParams->tree.num_nodes++; if (level==0) { #ifdef DEBUG_NEW_IMPL - printf("leaf %d (%s)\n",first_leaf_index,pp->information_bit_pattern[first_leaf_index]==1 ? "information or crc" : "frozen"); + printf("leaf %d (%s)\n", first_leaf_index, polarParams->information_bit_pattern[first_leaf_index]==1 ? "information or crc" : "frozen"); #endif new_node->leaf=1; - new_node->all_frozen = pp->information_bit_pattern[first_leaf_index]==0 ? 1 : 0; + new_node->all_frozen = polarParams->information_bit_pattern[first_leaf_index]==0 ? 1 : 0; return new_node; // this is a leaf node } for (int i=0;iinformation_bit_pattern[i+first_leaf_index]>0) all_frozen_below=0; + if (polarParams->information_bit_pattern[i+first_leaf_index]>0) + all_frozen_below=0; } - if (all_frozen_below==0) new_node->left=add_nodes(level-1,first_leaf_index,pp); + + if (all_frozen_below==0) + new_node->left=add_nodes(level-1, first_leaf_index, polarParams); else { #ifdef DEBUG_NEW_IMPL printf("aggregating frozen bits %d ... %d at level %d (%s)\n",first_leaf_index,first_leaf_index+Nv-1,level,((first_leaf_index/Nv)&1)==0?"left":"right"); @@ -241,22 +243,14 @@ decoder_node_t *add_nodes(int level,int first_leaf_index,t_nrPolar_params *pp) { new_node->leaf=1; new_node->all_frozen=1; } - if (all_frozen_below==0) new_node->right=add_nodes(level-1,first_leaf_index+(Nv/2),pp); + if (all_frozen_below==0) + new_node->right=add_nodes(level-1,first_leaf_index+(Nv/2),polarParams); #ifdef DEBUG_NEW_IMPL printf("new_node (%d): first_leaf_index %d, left %p, right %p\n",Nv,first_leaf_index,new_node->left,new_node->right); -#endif - return(new_node); -} - - -void build_decoder_tree(t_nrPolar_params *pp) { - - pp->tree.num_nodes=0; - pp->tree.root = add_nodes(pp->n,0,pp); -#ifdef DEBUG_NEW_IMPL - printf("root : left %p, right %p\n",pp->tree.root->left,pp->tree.root->right); #endif + + return(new_node); } #if defined(__arm__) || defined(__aarch64__) @@ -271,7 +265,7 @@ void build_decoder_tree(t_nrPolar_params *pp) { #define _mm_subs_pi16(a,b) vsub_s16(a,b) #endif -void applyFtoleft(t_nrPolar_params *pp,decoder_node_t *node) { +void applyFtoleft(t_nrPolar_params *pp, decoder_node_t *node) { int16_t *alpha_v=node->alpha; int16_t *alpha_l=node->left->alpha; int16_t *betal = node->left->beta; @@ -370,16 +364,16 @@ void applyFtoleft(t_nrPolar_params *pp,decoder_node_t *node) { #endif { // equvalent scalar code to above, activated only on non x86/ARM architectures for (int i=0;iNv/2;i++) { - a=alpha_v[i]; - b=alpha_v[i+(node->Nv/2)]; - maska=a>>15; - maskb=b>>15; - absa=(a+maska)^maska; - absb=(b+maskb)^maskb; - minabs = absaNv/2)]; + maska=a>>15; + maskb=b>>15; + absa=(a+maska)^maska; + absb=(b+maskb)^maskb; + minabs = absaNv == 2) { // apply hard decision on left node betal[0] = (alpha_l[0]>0) ? -1 : 1; @@ -463,11 +457,7 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) { } } - -int16_t all1[16] = {1,1,1,1, - 1,1,1,1, - 1,1,1,1, - 1,1,1,1}; +int16_t all1[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; void computeBeta(t_nrPolar_params *pp,decoder_node_t *node) { @@ -504,38 +494,35 @@ void computeBeta(t_nrPolar_params *pp,decoder_node_t *node) { int ssr4len = node->Nv/2/8; register __m128i allones=*((__m128i*)all1); for (int i=0;iNv/2;i++) { - betav[i] = (betal[i] != betar[i]) ? 1 : -1; + betav[i] = (betal[i] != betar[i]) ? 1 : -1; } } } else memcpy((void*)&betav[0],betar,(node->Nv/2)*sizeof(int16_t)); memcpy((void*)&betav[node->Nv/2],betar,(node->Nv/2)*sizeof(int16_t)); - } -void generic_polar_decoder(t_nrPolar_params *pp,decoder_node_t *node) { - +void generic_polar_decoder(t_nrPolar_params *polarParams, decoder_node_t *node) { // Apply F to left - applyFtoleft(pp,node); + applyFtoleft(polarParams, node); // if left is not a leaf recurse down to the left - if (node->left->leaf==0) generic_polar_decoder(pp,node->left); + if (node->left->leaf==0) + generic_polar_decoder(polarParams, node->left); - applyGtoright(pp,node); - if (node->right->leaf==0) generic_polar_decoder(pp,node->right); + applyGtoright(polarParams, node); + if (node->right->leaf==0) generic_polar_decoder(polarParams, node->right); - computeBeta(pp,node); + computeBeta(polarParams, node); } diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index bd056c3a18..76f1c322fe 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -54,8 +54,7 @@ #define NR_POLAR_AGGREGATION_LEVEL_8_PRIME 163 //uint16_t #define NR_POLAR_AGGREGATION_LEVEL_16_PRIME 167 //uint16_t -static const uint8_t nr_polar_subblock_interleaver_pattern[32] = { 0, 1, 2, 4, 3, 5, 6, 7, 8, 16, 9, 17, 10, 18, 11, 19, 12, 20, 13, 21, 14, 22, 15, 23, 24, 25, 26, 28, 27, 29, 30, 31 }; - +static const uint8_t nr_polar_subblock_interleaver_pattern[32] = {0,1,2,4,3,5,6,7,8,16,9,17,10,18,11,19,12,20,13,21,14,22,15,23,24,25,26,28,27,29,30,31}; #define Nmax 1024 #define nmax 10 @@ -112,7 +111,7 @@ struct nrPolar_params { uint8_t **G_N; uint64_t **G_N_tab; int groupsize; - int *rm_tab; + int *rm_tab; uint64_t cprime_tab0[32][256]; uint64_t cprime_tab1[32][256]; uint64_t B_tab0[32][256]; @@ -148,9 +147,9 @@ void polar_encoder_dci(uint32_t *in, uint16_t n_RNTI); void polar_encoder_fast(uint64_t *Aprime, - uint32_t *out, - int32_t crcmask, - t_nrPolar_paramsPtr polarParams); + uint32_t *out, + int32_t crcmask, + t_nrPolar_paramsPtr polarParams); int8_t polar_decoder(double *input, uint8_t *output, @@ -158,10 +157,6 @@ int8_t polar_decoder(double *input, uint8_t listSize, uint8_t pathMetricAppr); -uint32_t polar_decoder_int16(int16_t *input, - uint64_t *out, - t_nrPolar_params *polarParams); - int8_t polar_decoder_aPriori(double *input, uint32_t *output, t_nrPolar_paramsPtr polarParams, @@ -169,15 +164,6 @@ int8_t polar_decoder_aPriori(double *input, uint8_t pathMetricAppr, double *aPrioriPayload); -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *output, - t_nrPolar_paramsPtr polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE* logFile); - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_paramsPtr polarParams, @@ -185,11 +171,28 @@ int8_t polar_decoder_dci(double *input, uint8_t pathMetricAppr, uint16_t n_RNTI); -void generic_polar_decoder(t_nrPolar_params *, - decoder_node_t *); +uint32_t polar_decoder_int16(int16_t *input, + uint64_t *out, + t_nrPolar_params *polarParams); + +void generic_polar_decoder(t_nrPolar_params *, decoder_node_t *); + +void applyFtoleft(t_nrPolar_params *polarParams, decoder_node_t *node); + +void applyGtoright(t_nrPolar_params *polarParams, decoder_node_t *node); + +void computeBeta(t_nrPolar_params *polarParams, decoder_node_t *node); + + +void build_decoder_tree(t_nrPolar_params *polarParams); + +decoder_node_t *new_decoder_node(int first_leaf_index, int level); + +decoder_node_t *add_nodes(int level, int first_leaf_index, t_nrPolar_params *polarParams); + -void build_decoder_tree(t_nrPolar_params *pp); void build_polar_tables(t_nrPolar_paramsPtr polarParams); + void init_polar_deinterleaver_table(t_nrPolar_params *polarParams); void nr_polar_init(t_nrPolar_paramsPtr *polarParams, @@ -216,168 +219,143 @@ const uint16_t* nr_polar_sequence_pattern(uint8_t n); * @param E * @param n_max */ uint32_t nr_polar_output_length(uint16_t K, - uint16_t E, - uint8_t n_max); + uint16_t E, + uint8_t n_max); void nr_polar_channel_interleaver_pattern(uint16_t *cip, - uint8_t I_BIL, - uint16_t E); + uint8_t I_BIL, + uint16_t E); void nr_polar_rate_matching_pattern(uint16_t *rmp, - uint16_t *J, - const uint8_t *P_i_, - uint16_t K, - uint16_t N, - uint16_t E); + uint16_t *J, + const uint8_t *P_i_, + uint16_t K, + uint16_t N, + uint16_t E); void nr_polar_rate_matching(double *input, - double *output, - uint16_t *rmp, - uint16_t K, - uint16_t N, - uint16_t E); + double *output, + uint16_t *rmp, + uint16_t K, + uint16_t N, + uint16_t E); void nr_polar_rate_matching_int16(int16_t *input, - int16_t *output, - uint16_t *rmp, - uint16_t K, - uint16_t N, - uint16_t E); + int16_t *output, + uint16_t *rmp, + uint16_t K, + uint16_t N, + uint16_t E); -void nr_polar_interleaving_pattern(uint16_t K, - uint8_t I_IL, - uint16_t *PI_k_); +void nr_polar_interleaving_pattern(uint16_t K, uint8_t I_IL, uint16_t *PI_k_); void nr_polar_info_bit_pattern(uint8_t *ibp, - int16_t *Q_I_N, - int16_t *Q_F_N, - uint16_t *J, - const uint16_t *Q_0_Nminus1, - uint16_t K, - uint16_t N, - uint16_t E, - uint8_t n_PC); + int16_t *Q_I_N, + int16_t *Q_F_N, + uint16_t *J, + const uint16_t *Q_0_Nminus1, + uint16_t K, + uint16_t N, + uint16_t E, + uint8_t n_PC); void nr_polar_info_bit_extraction(uint8_t *input, - uint8_t *output, - uint8_t *pattern, - uint16_t size); + uint8_t *output, + uint8_t *pattern, + uint16_t size); -void nr_bit2byte_uint32_8_t(uint32_t *in, - uint16_t arraySize, - uint8_t *out); +void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out); -void nr_byte2bit_uint8_32_t(uint8_t *in, - uint16_t arraySize, - uint32_t *out); +void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out); -void nr_crc_bit2bit_uint32_8_t(uint32_t *in, - uint16_t arraySize, - uint8_t *out); +void nr_crc_bit2bit_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out); void nr_polar_bit_insertion(uint8_t *input, - uint8_t *output, - uint16_t N, - uint16_t K, - int16_t *Q_I_N, - int16_t *Q_PC_N, - uint8_t n_PC); + uint8_t *output, + uint16_t N, + uint16_t K, + int16_t *Q_I_N, + int16_t *Q_PC_N, + uint8_t n_PC); void nr_matrix_multiplication_uint8_1D_uint8_2D(uint8_t *matrix1, - uint8_t **matrix2, - uint8_t *output, - uint16_t row, - uint16_t col); + uint8_t **matrix2, + uint8_t *output, + uint16_t row, + uint16_t col); -uint8_t ***nr_alloc_uint8_3D_array(uint16_t xlen, - uint16_t ylen, - uint16_t zlen); +uint8_t ***nr_alloc_uint8_3D_array(uint16_t xlen, uint16_t ylen, uint16_t zlen); -uint8_t **nr_alloc_uint8_2D_array(uint16_t xlen, - uint16_t ylen); +uint8_t **nr_alloc_uint8_2D_array(uint16_t xlen, uint16_t ylen); -double ***nr_alloc_double_3D_array(uint16_t xlen, - uint16_t ylen, - uint16_t zlen); +double ***nr_alloc_double_3D_array(uint16_t xlen, uint16_t ylen, uint16_t zlen); -double **nr_alloc_double_2D_array(uint16_t xlen, - uint16_t ylen); +double **nr_alloc_double_2D_array(uint16_t xlen, uint16_t ylen); -void nr_free_double_3D_array(double ***input, - uint16_t xlen, - uint16_t ylen); - -void nr_free_double_2D_array(double **input, - uint16_t xlen); - -void nr_free_uint8_3D_array(uint8_t ***input, - uint16_t xlen, - uint16_t ylen); - -void nr_free_uint8_2D_array(uint8_t **input, - uint16_t xlen); - -void nr_sort_asc_double_1D_array_ind(double *matrix, - uint8_t *ind, - uint8_t len); - -void nr_sort_asc_int16_1D_array_ind(int32_t *matrix, - int *ind, - int len); +void nr_free_double_3D_array(double ***input, uint16_t xlen, uint16_t ylen); void nr_free_double_2D_array(double **input, uint16_t xlen); +void nr_free_uint8_3D_array(uint8_t ***input, uint16_t xlen, uint16_t ylen); + +void nr_free_uint8_2D_array(uint8_t **input, uint16_t xlen); + +void nr_sort_asc_double_1D_array_ind(double *matrix, uint8_t *ind, uint8_t len); + +void nr_sort_asc_int16_1D_array_ind(int32_t *matrix, int *ind, int len); + +void nr_free_double_2D_array(double **input, uint16_t xlen); void updateLLR(double ***llr, - uint8_t **llrU, - uint8_t ***bit, - uint8_t **bitU, - uint8_t listSize, - uint16_t row, - uint16_t col, - uint16_t xlen, - uint8_t ylen, - uint8_t approximation); + uint8_t **llrU, + uint8_t ***bit, + uint8_t **bitU, + uint8_t listSize, + uint16_t row, + uint16_t col, + uint16_t xlen, + uint8_t ylen, + uint8_t approximation); void updateBit(uint8_t ***bit, - uint8_t **bitU, - uint8_t listSize, - uint16_t row, - uint16_t col, - uint16_t xlen, - uint8_t ylen); + uint8_t **bitU, + uint8_t listSize, + uint16_t row, + uint16_t col, + uint16_t xlen, + uint8_t ylen); void updatePathMetric(double *pathMetric, - double ***llr, - uint8_t listSize, - uint8_t bitValue, - uint16_t row, - uint8_t approximation); + double ***llr, + uint8_t listSize, + uint8_t bitValue, + uint16_t row, + uint8_t approximation); void updatePathMetric2(double *pathMetric, - double ***llr, - uint8_t listSize, - uint16_t row, - uint8_t approximation); + double ***llr, + uint8_t listSize, + uint16_t row, + uint8_t approximation); void computeLLR(double ***llr, - uint16_t row, - uint16_t col, - uint8_t i, - uint16_t offset, - uint8_t approximation); + uint16_t row, + uint16_t col, + uint8_t i, + uint16_t offset, + uint8_t approximation); void updateCrcChecksum(uint8_t **crcChecksum, - uint8_t **crcGen, - uint8_t listSize, - uint32_t i2, - uint8_t len); + uint8_t **crcGen, + uint8_t listSize, + uint32_t i2, + uint8_t len); void updateCrcChecksum2(uint8_t **crcChecksum, - uint8_t **crcGen, - uint8_t listSize, - uint32_t i2, - uint8_t len); + uint8_t **crcGen, + uint8_t listSize, + uint32_t i2, + uint8_t len); uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits); @@ -386,24 +364,14 @@ uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits); uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits); //Also nr_polar_rate_matcher -static inline void nr_polar_interleaver(uint8_t *input, - uint8_t *output, - uint16_t *pattern, - uint16_t size) -{ - for (int i=0; ipayloadBits)>>8); #endif -nr_bit2byte_uint32_8_t((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);*/ +nr_bit2byte_uint32_8((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);*/ - nr_bit2byte_uint32_8_t((uint32_t*)in, polarParams->payloadBits, polarParams->nr_polar_A); + nr_bit2byte_uint32_8((uint32_t*)in, polarParams->payloadBits, polarParams->nr_polar_A); /* * Bytewise operations */ @@ -147,7 +147,7 @@ nr_bit2byte_uint32_8_t((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);* for (int i=0; i< polarParams->encoderLength;i++) printf("f[%d]=%d\n", i, polarParams->nr_polar_E[i]); #endif - nr_byte2bit_uint8_32_t(polarParams->nr_polar_E, polarParams->encoderLength, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_E, polarParams->encoderLength, out); } void polar_encoder_dci(uint32_t *in, @@ -163,7 +163,7 @@ void polar_encoder_dci(uint32_t *in, * Bytewise operations */ //(a to a') - nr_bit2byte_uint32_8_t(in, polarParams->payloadBits, polarParams->nr_polar_A); + nr_bit2byte_uint32_8(in, polarParams->payloadBits, polarParams->nr_polar_A); for (int i=0; icrcParityBits; i++) polarParams->nr_polar_APrime[i]=1; for (int i=0; ipayloadBits; i++) polarParams->nr_polar_APrime[i+(polarParams->crcParityBits)]=polarParams->nr_polar_A[i]; #ifdef DEBUG_POLAR_ENCODER_DCI @@ -202,7 +202,7 @@ void polar_encoder_dci(uint32_t *in, } /* //(a to a') - nr_crc_bit2bit_uint32_8_t(in, polarParams->payloadBits, polarParams->nr_polar_aPrime); + nr_crc_bit2bit_uint32_8(in, polarParams->payloadBits, polarParams->nr_polar_aPrime); //Parity bits computation (p) polarParams->crcBit = crc24c(polarParams->nr_polar_aPrime, (polarParams->payloadBits+polarParams->crcParityBits)); #ifdef DEBUG_POLAR_ENCODER_DCI @@ -273,7 +273,7 @@ void polar_encoder_dci(uint32_t *in, /* * Return bits. */ - nr_byte2bit_uint8_32_t(polarParams->nr_polar_E, polarParams->encoderLength, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_E, polarParams->encoderLength, out); #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] E: "); for (int i = 0; i < polarParams->encoderLength; i++) printf("%d-", polarParams->nr_polar_E[i]); diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c index 985266447b..fd7793ca79 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c @@ -33,12 +33,12 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" void nr_polar_bit_insertion(uint8_t *input, - uint8_t *output, - uint16_t N, - uint16_t K, - int16_t *Q_I_N, - int16_t *Q_PC_N, - uint8_t n_PC) + uint8_t *output, + uint16_t N, + uint16_t K, + int16_t *Q_I_N, + int16_t *Q_PC_N, + uint8_t n_PC) { uint16_t k=0; uint8_t flag; @@ -256,8 +256,13 @@ void nr_polar_info_bit_extraction(uint8_t *input, } -void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P_i_, uint16_t K, uint16_t N, uint16_t E){ - +void nr_polar_rate_matching_pattern(uint16_t *rmp, + uint16_t *J, + const uint8_t *P_i_, + uint16_t K, + uint16_t N, + uint16_t E) +{ uint8_t i; uint16_t *d, *y, ind; d = (uint16_t *)malloc(sizeof(uint16_t) * N); @@ -293,8 +298,13 @@ void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P } -void nr_polar_rate_matching(double *input, double *output, uint16_t *rmp, uint16_t K, uint16_t N, uint16_t E){ - +void nr_polar_rate_matching(double *input, + double *output, + uint16_t *rmp, + uint16_t K, + uint16_t N, + uint16_t E) +{ if (E>=N) { //repetition for (int i=0; i<=N-1; i++) output[i]=0; for (int i=0; i<=E-1; i++){ @@ -311,11 +321,15 @@ void nr_polar_rate_matching(double *input, double *output, uint16_t *rmp, uint16 output[rmp[i]]=input[i]; } } - } -void nr_polar_rate_matching_int16(int16_t *input, int16_t *output, uint16_t *rmp, uint16_t K, uint16_t N, uint16_t E){ - +void nr_polar_rate_matching_int16(int16_t *input, + int16_t *output, + uint16_t *rmp, + uint16_t K, + uint16_t N, + uint16_t E) +{ if (E>=N) { //repetition for (int i=0; i<=N-1; i++) output[i]=0; for (int i=0; i<=E-1; i++){ @@ -332,6 +346,4 @@ void nr_polar_rate_matching_int16(int16_t *input, int16_t *output, uint16_t *rmp output[rmp[i]]=input[i]; } } - } - diff --git a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c new file mode 100644 index 0000000000..95237ea40b --- /dev/null +++ b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c @@ -0,0 +1,117 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*!\file PHY/CODING/nrSmallBlock/decodeSmallBlock.c + * \brief + * \author Turker Yilmaz + * \date 2019 + * \version 0.1 + * \company EURECOM + * \email turker.yilmaz@eurecom.fr + * \note + * \warning +*/ + +#include "PHY/CODING/nrSmallBlock/nr_small_block_defs.h" +#include "assertions.h" +#include "PHY/sse_intrin.h" + +//#define DEBUG_DECODESMALLBLOCK + +uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ + uint16_t out = 0; + + AssertFatal(len >= 3 && len <= 11, "[decodeSmallBlock] Message Length = %d (Small Block Coding is only defined for input lengths 3 to 11)", len); + + if(len<7) { + int16_t Rhat[NR_SMALL_BLOCK_CODED_BITS] = {0}, Rhatabs[NR_SMALL_BLOCK_CODED_BITS] = {0}; + uint16_t maxVal; + uint8_t maxInd = 0; + + for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) + Rhat[j] += in[k] * hadamard32InterleavedTransposed[j][k]; + +#if defined(__AVX2__) + for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; i += 16) { + __m256i a15_a0 = _mm256_loadu_si256((__m256i*)&Rhat[i]); + a15_a0 = _mm256_abs_epi16(a15_a0); + _mm256_storeu_si256((__m256i*)(&Rhatabs[i]), a15_a0); + } +#else + for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; i += 8) { + __m128i a7_a0 = _mm_loadu_si128((__m128i*)&Rhat[i]); + a7_a0 = _mm_abs_epi16(a7_a0); + _mm_storeu_si128((__m128i*)(&Rhatabs[i]), a7_a0); + } +#endif + maxVal = Rhatabs[0]; + for (int k = 1; k < NR_SMALL_BLOCK_CODED_BITS; ++k){ + if (Rhatabs[k] > maxVal){ + maxVal = Rhatabs[k]; + maxInd = k; + } + } + + out = properOrderedBasis[maxInd] | ( (Rhat[maxInd] > 0) ? (uint16_t)0 : (uint16_t)1 ); + +#ifdef DEBUG_DECODESMALLBLOCK + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) + printf("[decodeSmallBlock]Rhat[%d]=%d %d %d %d\n",k, Rhat[k], maxVal, maxInd, ((uint32_t)out>>k)&1); + printf("[decodeSmallBlock]0x%x 0x%x\n", out, properOrderedBasis[maxInd]); +#endif + + } else { + int8_t Dmatrix[NR_SMALL_BLOCK_CODED_BITS][NR_SMALL_BLOCK_CODED_BITS] = {0}; + int16_t DmatrixFHT[NR_SMALL_BLOCK_CODED_BITS][NR_SMALL_BLOCK_CODED_BITS] = {0}; + uint16_t maxVal; + uint8_t maxRow = 0, maxCol = 0; + + for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) + Dmatrix[j][k] = in[k] * maskD[j][k]; + + + for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; ++i) + for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) + DmatrixFHT[i][j] += Dmatrix[i][k] * hadamard32InterleavedTransposed[j][k]; + + maxVal = abs(DmatrixFHT[0][0]); + for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; ++i) + for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) + if (abs(DmatrixFHT[i][j]) > maxVal){ + maxVal = abs(DmatrixFHT[i][j]); + maxRow = i; + maxCol = j; + } + + out = properOrderedBasisExtended[maxRow] | properOrderedBasis[maxCol] | ( (DmatrixFHT[maxRow][maxCol] > 0) ? (uint16_t)0 : (uint16_t)1 ); + +#ifdef DEBUG_DECODESMALLBLOCK + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) + printf("[decodeSmallBlock]maxRow = %d maxCol = %d out[%d]=%d\n", maxRow, maxCol, k, ((uint32_t)out>>k)&1); +#endif + + } + + return out; +} diff --git a/openair1/PHY/CODING/nrSmallBlock/encodeSmall.c b/openair1/PHY/CODING/nrSmallBlock/encodeSmall.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/openair1/PHY/CODING/nrSmallBlock/encodeSmallBlock.c b/openair1/PHY/CODING/nrSmallBlock/encodeSmallBlock.c new file mode 100644 index 0000000000..8358bd270b --- /dev/null +++ b/openair1/PHY/CODING/nrSmallBlock/encodeSmallBlock.c @@ -0,0 +1,44 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*!\file PHY/CODING/nrSmallBlock/encodeSmallBlock.c + * \brief + * \author Turker Yilmaz + * \date 2019 + * \version 0.1 + * \company EURECOM + * \email turker.yilmaz@eurecom.fr + * \note + * \warning +*/ + +#include "PHY/CODING/nrSmallBlock/nr_small_block_defs.h" + +//input = [0 ... 0 c_K-1 ... c_2 c_1 c_0] +//output = [d_31 d_30 ... d_2 d_1 d_0] +uint32_t encodeSmallBlock(uint16_t *in, uint8_t len){ + uint32_t out = 0; + for (uint16_t i=0; i 0) + out^=nrSmallBlockBasis[i]; + + return out; +} diff --git a/openair1/PHY/CODING/nrSmallBlock/nr_small_block_defs.h b/openair1/PHY/CODING/nrSmallBlock/nr_small_block_defs.h new file mode 100644 index 0000000000..50559aa0d2 --- /dev/null +++ b/openair1/PHY/CODING/nrSmallBlock/nr_small_block_defs.h @@ -0,0 +1,134 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*!\file PHY/CODING/nrSmallBlock/nr_small_block_defs.h + * \brief + * \author Turker Yilmaz + * \date 2019 + * \version 0.1 + * \company EURECOM + * \email turker.yilmaz@eurecom.fr + * \note + * \warning +*/ + +#ifndef __NR_SMALL_BLOCK_DEFS__H__ +#define __NR_SMALL_BLOCK_DEFS__H__ + +#include +#include +#include +#include +#include + +#define NR_SMALL_BLOCK_CODED_BITS 32 + +#define L1d_CLS 64 + +uint32_t encodeSmallBlock(uint16_t *in, uint8_t len); + +uint16_t decodeSmallBlock(int8_t *in, uint8_t len); + +static const uint32_t nrSmallBlockBasis[11] = {0xFFFFFFFF, 0x4BA5A933, 0x7D910E5A, 0x6D26339C, 0x71C7C3E0, + 0x7E0FFC00, 0x731D8E64, 0x6B44F5B0, 0x7DC218EC, 0x4DA1B746, 0x42F0FFFF}; + +static const uint16_t properOrderedBasis[32] = {0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000A, 0x000C, 0x000E, 0x0010, 0x0012, + 0x0014, 0x0016, 0x0018, 0x001A, 0x001C, 0x001E, 0x0020, 0x0022, 0x0024, 0x0026, + 0x0028, 0x002A, 0x002C, 0x002E, 0x0030, 0x0032, 0x0034, 0x0036, 0x0038, 0x003A, 0x003C, 0x003E}; + +static const uint16_t properOrderedBasisExtended[32] = {0x0000, 0x0040, 0x0080, 0x00C0, 0x0100, 0x0140, 0x0180, 0x01C0, 0x0200, 0x0240, + 0x0280, 0x02C0, 0x0300, 0x0340, 0x0380, 0x03C0, 0x0400, 0x0440, 0x0480, 0x04C0, + 0x0500, 0x0540, 0x0580, 0x05C0, 0x0600, 0x0640, 0x0680, 0x06C0, 0x0700, 0x0740, 0x0780, 0x07C0}; + +static const int8_t hadamard32InterleavedTransposed[32][32] __attribute__ ((aligned(32))) = { + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {-1,-1,1,1,-1,-1,1,1,-1,1,1,-1,1,-1,1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,-1,1}, + {1,-1,1,-1,-1,1,-1,1,1,-1,-1,-1,1,1,1,1,-1,1,1,1,-1,1,1,-1,-1,1,-1,-1,-1,-1,-1,1}, + {-1,1,1,-1,1,-1,-1,1,-1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,-1,1,1}, + {1,1,-1,-1,-1,1,1,-1,-1,-1,1,1,-1,-1,1,1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1}, + {-1,-1,-1,-1,1,-1,1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,-1,1,1,-1,1,1}, + {1,-1,-1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,1,1}, + {-1,1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,1,-1,1}, + {1,1,1,1,1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,1,1,1,-1,-1,-1,1,1,1,-1,-1,-1,1}, + {-1,-1,1,1,-1,1,-1,-1,1,-1,1,-1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,1,-1,1,-1,-1,-1,1,1}, + {1,-1,1,-1,-1,-1,1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1,-1,1,-1,1,-1,1,1,1,-1,-1,1,1,1,1}, + {-1,1,1,-1,1,1,1,-1,1,1,-1,1,1,-1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,1,-1,1}, + {1,1,-1,-1,-1,-1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,1,1,-1,-1,-1,1,1,1}, + {-1,-1,-1,-1,1,1,-1,1,-1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,1,-1,1}, + {1,-1,-1,1,1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1}, + {-1,1,-1,1,-1,1,1,1,-1,-1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,-1,1,-1,1,-1,1,-1,1,1}, + {1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,1}, + {-1,-1,1,1,-1,-1,1,1,-1,1,-1,1,-1,1,-1,1,1,-1,1,-1,1,-1,1,-1,-1,1,-1,1,-1,-1,1,1}, + {1,-1,1,-1,-1,1,-1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,1,1,-1,-1,-1,1,1,1,1,1,1}, + {-1,1,1,-1,1,-1,-1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,1,-1,1}, + {1,1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,1,1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1}, + {-1,-1,-1,-1,1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,1,-1,-1,1,1,1,-1,1,1,1,-1,-1,1,-1,1}, + {1,-1,-1,1,1,1,-1,-1,-1,1,1,1,1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,-1,-1,-1,1,-1,-1,1}, + {-1,1,-1,1,-1,-1,-1,-1,1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,1,1,-1,1,1}, + {1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,-1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1}, + {-1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,-1,1,1,-1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,1,1,1,-1,1}, + {1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,-1,-1,1,1,-1,1,1,-1,-1,1,-1,1,1,-1,1,1,-1,-1,-1,1}, + {-1,1,1,-1,1,1,1,-1,1,1,1,-1,-1,1,1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,1,1}, + {1,1,-1,-1,-1,-1,-1,1,1,1,-1,-1,1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,1,-1,1,1,1,-1,-1,1}, + {-1,-1,-1,-1,1,1,-1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,1,1}, + {1,-1,-1,1,1,-1,1,1,1,-1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1}, + {-1,1,-1,1,-1,1,1,1,-1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,-1,1,-1,-1,1,1,-1,1,-1,1,-1,1} +}; + +static const int8_t maskD[32][32] __attribute__ ((aligned(32))) = { + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, + {1,1,-1,1,1,-1,-1,1,1,-1,-1,-1,1,1,1,-1,-1,1,-1,-1,-1,1,1,1,-1,-1,1,1,-1,-1,-1,1}, + {1,1,1,1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,-1,1,1,-1,1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,1}, + {1,1,-1,1,-1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,1,-1,1,1,1,1,-1,-1,1,1,1}, + {1,1,-1,-1,1,-1,-1,-1,1,1,1,-1,-1,1,1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,-1,-1,-1,-1,1}, + {1,1,1,-1,1,1,1,-1,1,-1,-1,1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1,1,1}, + {1,1,-1,-1,-1,1,-1,1,-1,1,-1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,-1,1,-1,-1,1,-1,1,1,1}, + {1,1,1,-1,-1,-1,1,1,-1,-1,1,1,1,-1,-1,1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1,1,1,-1,-1,1}, + {1,-1,-1,1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,-1,-1,1,1,1,1,-1,1,-1,-1,1,-1,-1,1,1,-1,1}, + {1,-1,1,1,1,-1,1,1,-1,1,1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,-1,1,-1,-1,-1,-1,-1,1,1}, + {1,-1,-1,1,-1,-1,-1,-1,1,-1,1,1,1,1,-1,1,-1,1,-1,1,1,-1,-1,-1,1,-1,-1,1,1,-1,1,1}, + {1,-1,1,1,-1,1,1,-1,1,1,-1,-1,1,1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,-1,1,-1,1}, + {1,-1,1,-1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,-1,-1,1,1,1,1,1,-1,-1,1,1}, + {1,-1,-1,-1,1,1,-1,-1,-1,1,1,1,1,-1,1,1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,1,1,1,1,-1,1}, + {1,-1,1,-1,-1,1,1,1,1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,1,1,-1,-1,1,-1,-1,1,-1,1}, + {1,-1,-1,-1,-1,-1,-1,1,1,1,-1,1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,1,1,1,-1,1,-1,1,1}, + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,1,-1,1,1,1,1,-1,1}, + {-1,-1,1,-1,-1,1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,1,1,-1,-1,1,1}, + {-1,-1,-1,-1,1,1,-1,1,1,-1,1,-1,1,1,1,1,1,1,-1,1,-1,-1,1,-1,-1,1,1,-1,1,-1,1,1}, + {-1,-1,1,-1,1,-1,1,1,1,1,-1,1,1,1,1,-1,-1,1,1,-1,1,-1,1,-1,1,-1,1,-1,-1,1,-1,1}, + {-1,-1,1,1,-1,1,1,1,-1,-1,-1,1,1,-1,-1,-1,1,-1,1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,1}, + {-1,-1,-1,1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,1,-1,1}, + {-1,-1,1,1,1,-1,1,-1,1,-1,1,1,-1,1,1,1,1,-1,-1,1,-1,-1,-1,1,1,1,-1,1,-1,1,-1,1}, + {-1,-1,-1,1,1,1,-1,-1,1,1,-1,-1,-1,1,1,-1,-1,-1,1,-1,1,-1,-1,1,-1,-1,-1,1,1,-1,1,1}, + {-1,1,1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,-1,1,1,1,-1,1,-1,1,-1,-1,-1,-1,1,1,1,1}, + {-1,1,-1,-1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,-1,-1,-1,1}, + {-1,1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1}, + {-1,1,-1,-1,1,-1,-1,1,-1,-1,1,1,-1,-1,1,1,1,1,1,-1,1,1,1,1,-1,-1,-1,1,-1,1,1,1}, + {-1,1,-1,1,-1,1,-1,1,1,1,1,1,-1,1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,1,1,-1,-1,-1,1}, + {-1,1,1,1,-1,-1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1,1,-1,-1,1,1,1,1,1,1,1}, + {-1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,1,1,1,}, + {-1,1,1,1,1,1,1,-1,-1,-1,1,-1,1,-1,1,1,1,-1,1,-1,1,1,-1,-1,1,-1,1,-1,1,-1,-1,1} +}; + + + +#endif + diff --git a/openair1/PHY/CODING/nr_polar_init.c b/openair1/PHY/CODING/nr_polar_init.c index 93bcdecd6e..946657a905 100644 --- a/openair1/PHY/CODING/nr_polar_init.c +++ b/openair1/PHY/CODING/nr_polar_init.c @@ -42,9 +42,9 @@ static int intcmp(const void *p1,const void *p2) { } void nr_polar_init(t_nrPolar_paramsPtr *polarParams, - int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level) + int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level) { t_nrPolar_paramsPtr currentPtr = *polarParams; uint16_t aggregation_prime = nr_polar_aggregation_prime(aggregation_level); @@ -63,7 +63,8 @@ void nr_polar_init(t_nrPolar_paramsPtr *polarParams, if (newPolarInitNode != NULL) { newPolarInitNode->idx = (messageType * messageLength * aggregation_prime); - newPolarInitNode->nextPtr = NULL; + newPolarInitNode->nextPtr = (t_nrPolar_params *)NULL; + //printf("newPolarInitNode->idx %d, (%d,%d,%d:%d)\n",newPolarInitNode->idx,messageType,messageLength,aggregation_prime,aggregation_level); if (messageType == 0) { //PBCH @@ -186,9 +187,7 @@ void nr_polar_init(t_nrPolar_paramsPtr *polarParams, currentPtr = currentPtr->nextPtr; } currentPtr->nextPtr= newPolarInitNode; - printf("Adding new polarParams entry to list index %d,%p\n", - newPolarInitNode->idx, - currentPtr->nextPtr); + printf("Adding new polarParams entry to list index %d,%p\n", newPolarInitNode->idx, currentPtr->nextPtr); return; } @@ -209,9 +208,9 @@ void nr_polar_print_polarParams(t_nrPolar_paramsPtr polarParams) } t_nrPolar_paramsPtr nr_polar_params (t_nrPolar_paramsPtr polarParams, - int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level) + int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level) { t_nrPolar_paramsPtr currentPtr = NULL; From 2d39da3b57fee88a477b1666c6fb2ed897316ad7 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 8 Mar 2019 17:12:23 +0100 Subject: [PATCH 035/117] inc no physim exectuables in CI script --- ci-scripts/oai-ci-vm-tool | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool index 940bcd2852..fd867b6661 100755 --- a/ci-scripts/oai-ci-vm-tool +++ b/ci-scripts/oai-ci-vm-tool @@ -252,7 +252,7 @@ case $key in VM_NAME=ci-phy-sim ARCHIVES_LOC=phy_sim LOG_PATTERN=.Rel15.txt - NB_PATTERN_FILES=8 + NB_PATTERN_FILES=9 BUILD_OPTIONS="--phy_simulators" VM_MEMORY=4096 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" @@ -331,7 +331,7 @@ case $key in VM_NAME=ci-phy-sim ARCHIVES_LOC=phy_sim LOG_PATTERN=.Rel15.txt - NB_PATTERN_FILES=8 + NB_PATTERN_FILES=9 BUILD_OPTIONS="--phy_simulators" VM_MEMORY=4096 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" From 3fc4c6a4647ab10a2c4e17cf2143c70368188b9c Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 12 Mar 2019 12:51:01 +0100 Subject: [PATCH 036/117] multiple ssb detection via pbch dmrs (selection of best ssb only, working in pbchsim for SNR>=0) --- .../nr_dl_channel_estimation.c | 163 ++++++++++++++++++ openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 6 + .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 59 +++++-- openair1/PHY/defs_nr_UE.h | 9 + 4 files changed, 222 insertions(+), 15 deletions(-) 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 f17f6eb9b8..99267152b0 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -32,6 +32,169 @@ //#define DEBUG_PDCCH +int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, + uint8_t eNB_offset, + unsigned char Ns, + unsigned char symbol, + NR_UE_SSB *current_ssb) +{ + int pilot[200] __attribute__((aligned(16))); + unsigned char aarx; + unsigned short k; + unsigned int pilot_cnt; + int16_t ch[2],*pil,*rxF; + int symbol_offset; + int dmrss; + + uint8_t nushift; + uint8_t ssb_index=current_ssb->i_ssb; + uint8_t n_hf=current_ssb->n_hf; + int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF; + + nushift = ue->frame_parms.Nid_cell%4; + ue->frame_parms.nushift = nushift; + unsigned int ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier; + if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size; + + if (ue->is_synchronized ==0 ) dmrss = symbol-1; + else dmrss = symbol-5; + + AssertFatal((symbol > 0 && symbol < 4 && ue->is_synchronized == 0) || + (symbol > 4 && symbol < 8 && ue->is_synchronized == 1), + "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n", + symbol,ue->is_synchronized); + + symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol; + + + k = nushift; + +#ifdef DEBUG_CH + printf("PBCH DMRS Correlation : ThreadId %d, eNB_offset %d , OFDM size %d, Ncp=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ue->frame_parms.ofdm_symbol_size, + ue->frame_parms.Ncp,Ns,k, symbol); +#endif + + // generate pilot + nr_pbch_dmrs_rx(dmrss,ue->nr_gold_pbch[n_hf][ssb_index], &pilot[0]); + + int re_offset = ssb_offset; + for (aarx=0; aarxframe_parms.nb_antennas_rx; aarx++) { + + pil = (int16_t *)&pilot[0]; + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + +#ifdef DEBUG_CH + printf("pbch ch est pilot addr %p RB_DL %d\n",&pilot[0], ue->frame_parms.N_RB_DL); + printf("k %d, first_carrier %d\n",k,ue->frame_parms.first_carrier_offset); + printf("rxF addr %p\n", rxF); +#endif + //if ((ue->frame_parms.N_RB_DL&1)==0) { + + // Treat first 2 pilots specially (left edge) + ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); + ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("ch 0 %d\n",((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])); + printf("pilot 0 : rxF - > (%d,%d) addr %p ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],&rxF[0],ch[0],ch[1],pil[0],pil[1]); +#endif + + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + + ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); + ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("pilot 1 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); +#endif + + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("pilot 2 : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); +#endif + + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + for (pilot_cnt=3; pilot_cnt<(3*20); pilot_cnt+=3) { + + // if (pilot_cnt == 30) + // rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k)]; + + // in 2nd symbol, skip middle REs (48 with DMRS, 144 for SSS, and another 48 with DMRS) + if (dmrss == 1 && pilot_cnt == 12) { + pilot_cnt=48; + re_offset = (re_offset+144)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + } + ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); + ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); +#endif + + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + + ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); + ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+1,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); +#endif + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + + ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15); + ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15); + + current_ssb->c_re +=ch[0]; + current_ssb->c_im +=ch[1]; + +#ifdef DEBUG_CH + printf("pilot %d : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt+2,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]); +#endif + + pil+=2; + re_offset = (re_offset+4)&(ue->frame_parms.ofdm_symbol_size-1); + rxF = (int16_t *)&rxdataF[aarx][(symbol_offset+k+re_offset)]; + + } + + + //} + + } + return(0); +} + int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 591b4733ce..1ec9cec96f 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -50,6 +50,12 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, unsigned short coreset_start_subcarrier, unsigned short nb_rb_coreset); +int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, + uint8_t eNB_offset, + unsigned char Ns, + unsigned char symbol, + NR_UE_SSB *current_ssb); + int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 0b9795b6bc..a147d10457 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -58,6 +58,11 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod { NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; + uint8_t best_ssb =0; + uint8_t n_hf =0; + uint32_t best_metric =0; + + NR_UE_SSB *current_ssb = malloc(sizeof(NR_UE_SSB)); #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"[UE%d] Initial sync: starting PBCH detection (rx_offset %d)\n",ue->Mod_id, @@ -70,30 +75,53 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod // loops over possible pbch dmrs cases to retrive best estimated i_ssb (and n_hf for Lmax=4) for multiple ssb detection for (int hf = 0; hf < N_hf; hf++) { for (int l = 0; l < N_L ; l++) { - if (ret !=0) { + + // initialization of structure parameters + current_ssb->n_hf = hf; + current_ssb->i_ssb = l; + current_ssb->c_re = 0; + current_ssb->c_im = 0; #if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); + start_meas(&ue->dlsch_channel_estimation_stats); #endif - for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); + stop_meas(&ue->dlsch_channel_estimation_stats); #endif - - ret = nr_rx_pbch(ue, - &ue->proc.proc_rxtx[0], - ue->pbch_vars[0], - frame_parms, - 0, - l, - SISO, - ue->high_speed_flag); - + + current_ssb->metric = current_ssb->c_re*current_ssb->c_re + current_ssb->c_im+current_ssb->c_re; + + if(current_ssb->metric > best_metric) { // if metric of current structure is higher than the best one + best_metric = current_ssb->metric; + best_ssb = l; + n_hf = hf; } + } } +#if UE_TIMING_TRACE + start_meas(&ue->dlsch_channel_estimation_stats); +#endif + // computing channel estimation for selected best ssb + for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); +#endif + + ret = nr_rx_pbch(ue, + &ue->proc.proc_rxtx[0], + ue->pbch_vars[0], + frame_parms, + 0, + best_ssb, + SISO, + ue->high_speed_flag); + if (ret==0) { frame_parms->nb_antenna_ports_eNB = 1; //pbch_tx_ant; @@ -116,6 +144,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"[UE%d] Initial sync: pbch decoded sucessfully\n",ue->Mod_id); #endif + return(0); } else { return(-1); diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a482a48207..a846f46e0f 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -950,6 +950,15 @@ typedef struct { int16_t *prach; } NR_UE_PRACH; +// structure used for multiple SSB detection +typedef struct NR_UE_SSB { + uint8_t i_ssb; // i_ssb between 0 and 7 (it corresponds to ssb_index only for Lmax=4,8) + uint8_t n_hf; // n_hf = 0,1 for Lmax =4 or n_hf = 0 for Lmax =8,64 + uint32_t metric; // metric to order SSB hypothesis + uint32_t c_re; + uint32_t c_im; +} NR_UE_SSB; + /*typedef enum { /// do not detect any DCIs in the current subframe NO_DCI = 0x0, From f070801d0ae33622a3795aee7dac505e623bd309 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Tue, 12 Mar 2019 15:36:24 +0100 Subject: [PATCH 037/117] AVX512F intrinsics added for shortBlockCoding --- .../nrPolar_tools/nr_polar_decoding_tools.c | 4 +- .../CODING/nrSmallBlock/decodeSmallBlock.c | 49 +++++++++++++++++-- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index 6ac29eb50b..9f8fac24c5 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -362,7 +362,7 @@ void applyFtoleft(t_nrPolar_params *pp, decoder_node_t *node) { else #endif - { // equvalent scalar code to above, activated only on non x86/ARM architectures + { // equivalent scalar code to above, activated only on non x86/ARM architectures for (int i=0;iNv/2;i++) { a=alpha_v[i]; b=alpha_v[i+(node->Nv/2)]; @@ -442,7 +442,7 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) { } else #endif - {// equvalent scalar code to above, activated only on non x86/ARM architectures or Nv=1,2 + {// equivalent scalar code to above, activated only on non x86/ARM architectures or Nv=1,2 for (int i=0;iNv/2;i++) { alpha_r[i] = alpha_v[i+(node->Nv/2)] - (betal[i]*alpha_v[i]); } diff --git a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c index 95237ea40b..38b9a6b13c 100644 --- a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c +++ b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c @@ -36,6 +36,9 @@ //#define DEBUG_DECODESMALLBLOCK +//input = [dÌ‚_0] [dÌ‚_1] [dÌ‚_2] ... [dÌ‚_31] +//output = [? ... ? ĉ_K-1 ... ĉ_2 ĉ_1 ĉ_0] + uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ uint16_t out = 0; @@ -80,23 +83,58 @@ uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ #endif } else { + uint8_t maxRow = 0, maxCol = 0; + +#if defined(__AVX2__) + int16_t maxVal = 0; + int DmatrixElementVal = 0; + int8_t DmatrixElement[NR_SMALL_BLOCK_CODED_BITS] = {0}; + __m256i _in_256 = _mm256_loadu_si256 ((__m256i*)&in[0]); + __m256i _maskD_256, _Dmatrixj_256, _maskH_256, _DmatrixElement_256; + for (int j = 0; j < ( 1<<(len-6) ); ++j) { + _maskD_256 = _mm256_loadu_si256 ((__m256i*)(&maskD[j][0])); + _Dmatrixj_256 = _mm256_sign_epi8 (_in_256, _maskD_256); + for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) { + _maskH_256 = _mm256_loadu_si256 ((__m256i*)(&hadamard32InterleavedTransposed[k][0])); + _DmatrixElement_256 = _mm256_sign_epi8 (_Dmatrixj_256, _maskH_256); +#if defined(__AVX512F__) + DmatrixElementVal = _mm512_reduce_add_epi32 ( + _mm512_add_epi32( + _mm512_cvtepi8_epi32 (_mm256_extracti128_si256 (_DmatrixElement_256, 1)), + _mm512_cvtepi8_epi32 (_mm256_castsi256_si128 (_DmatrixElement_256)) + ) + ); +#else + _mm256_storeu_si256((__m256i*)(&DmatrixElement[0]), _DmatrixElement_256); + for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; ++i) + DmatrixElementVal += DmatrixElement[i]; +#endif + if (abs(DmatrixElementVal) > abs(maxVal)){ + maxVal = DmatrixElementVal; + maxRow = j; + maxCol = k; + } + DmatrixElementVal=0; + } + } + out = properOrderedBasisExtended[maxRow] | properOrderedBasis[maxCol] | ( (maxVal > 0) ? (uint16_t)0 : (uint16_t)1 ); +#else int8_t Dmatrix[NR_SMALL_BLOCK_CODED_BITS][NR_SMALL_BLOCK_CODED_BITS] = {0}; int16_t DmatrixFHT[NR_SMALL_BLOCK_CODED_BITS][NR_SMALL_BLOCK_CODED_BITS] = {0}; uint16_t maxVal; - uint8_t maxRow = 0, maxCol = 0; + uint8_t rowLimit = 1<<(len-6); - for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) + for (int j = 0; j < ( rowLimit ); ++j) for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) Dmatrix[j][k] = in[k] * maskD[j][k]; - - for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; ++i) + for (int i = 0; i < ( rowLimit ); ++i) for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) DmatrixFHT[i][j] += Dmatrix[i][k] * hadamard32InterleavedTransposed[j][k]; maxVal = abs(DmatrixFHT[0][0]); - for (int i = 0; i < NR_SMALL_BLOCK_CODED_BITS; ++i) + for (int i = 0; i < ( rowLimit ); ++i) for (int j = 0; j < NR_SMALL_BLOCK_CODED_BITS; ++j) if (abs(DmatrixFHT[i][j]) > maxVal){ maxVal = abs(DmatrixFHT[i][j]); @@ -105,6 +143,7 @@ uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ } out = properOrderedBasisExtended[maxRow] | properOrderedBasis[maxCol] | ( (DmatrixFHT[maxRow][maxCol] > 0) ? (uint16_t)0 : (uint16_t)1 ); +#endif #ifdef DEBUG_DECODESMALLBLOCK for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) From 2c75720d798bae449649841e84fc33fbb42f6558 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Wed, 13 Mar 2019 17:48:23 +0100 Subject: [PATCH 038/117] multiple ssb detection via pbch dmrs (ordered list) --- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 104 +++++++++++++----- openair1/PHY/defs_nr_UE.h | 3 +- 2 files changed, 79 insertions(+), 28 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index a147d10457..e75f5a647a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -54,15 +54,61 @@ int cnt=0; #define DEBUG_INITIAL_SYNCH +// create a new node of SSB structure +NR_UE_SSB* create_ssb_node(uint8_t i, uint8_t h) { + + NR_UE_SSB *new_node = (NR_UE_SSB*)malloc(sizeof(NR_UE_SSB)); + new_node->i_ssb = i; + new_node->n_hf = h; + new_node->c_re = 0; + new_node->c_im = 0; + new_node->metric = 0; + new_node->next_ssb = NULL; + + return new_node; +} + + +// insertion of the structure in the ordered list (highest metric first) +NR_UE_SSB* insert_into_list(NR_UE_SSB *head, NR_UE_SSB *node) { + + if (node->metric > head->metric) { + node->next_ssb = head; + head = node; + return head; + } + + NR_UE_SSB *current = head; + while (current->next_ssb !=NULL) { + NR_UE_SSB *temp=current->next_ssb; + if(node->metric > current->metric) { + node->next_ssb = temp; + current->next_ssb = node; + return head; + } + else + current = temp; + } + current->next_ssb = node; + + return head; +} + + +void free_list(NR_UE_SSB *node) { + if (node->next_ssb != NULL) + free_list(node->next_ssb); + free(node); +} + + int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) { NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; - uint8_t best_ssb =0; - uint8_t n_hf =0; - uint32_t best_metric =0; - NR_UE_SSB *current_ssb = malloc(sizeof(NR_UE_SSB)); + NR_UE_SSB *best_ssb = NULL; + 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, @@ -76,11 +122,8 @@ 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++) { - // initialization of structure parameters - current_ssb->n_hf = hf; - current_ssb->i_ssb = l; - current_ssb->c_re = 0; - current_ssb->c_im = 0; + // initialization of structure + current_ssb = create_ssb_node(l,hf); #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); @@ -94,34 +137,42 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod current_ssb->metric = current_ssb->c_re*current_ssb->c_re + current_ssb->c_im+current_ssb->c_re; - if(current_ssb->metric > best_metric) { // if metric of current structure is higher than the best one - best_metric = current_ssb->metric; - best_ssb = l; - n_hf = hf; - } + // generate a list of SSB structures + if (best_ssb == NULL) + best_ssb = current_ssb; + else + best_ssb = insert_into_list(best_ssb,current_ssb); } } + NR_UE_SSB *temp_ptr=best_ssb; + while (ret!=0 && temp_ptr != NULL) { + #if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); + start_meas(&ue->dlsch_channel_estimation_stats); #endif // computing channel estimation for selected best ssb - for(int i=pbch_initial_symbol; ii_ssb,best_ssb->n_hf); #if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); + stop_meas(&ue->dlsch_channel_estimation_stats); #endif - ret = nr_rx_pbch(ue, - &ue->proc.proc_rxtx[0], - ue->pbch_vars[0], - frame_parms, - 0, - best_ssb, - SISO, - ue->high_speed_flag); + ret = nr_rx_pbch(ue, + &ue->proc.proc_rxtx[0], + ue->pbch_vars[0], + frame_parms, + 0, + temp_ptr->i_ssb, + SISO, + ue->high_speed_flag); + temp_ptr=temp_ptr->next_ssb; + } + + free_list(best_ssb); + if (ret==0) { frame_parms->nb_antenna_ports_eNB = 1; //pbch_tx_ant; @@ -144,7 +195,6 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"[UE%d] Initial sync: pbch decoded sucessfully\n",ue->Mod_id); #endif - return(0); } else { return(-1); diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a846f46e0f..2a17bbbbe5 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -957,6 +957,7 @@ typedef struct NR_UE_SSB { uint32_t metric; // metric to order SSB hypothesis uint32_t c_re; uint32_t c_im; + struct NR_UE_SSB *next_ssb; } NR_UE_SSB; /*typedef enum { @@ -1088,7 +1089,7 @@ typedef struct { uint32_t nr_gold_pbch[2][64][NR_PBCH_DMRS_LENGTH_DWORD]; /// PDSCH DMRS - uint32_t nr_gold_pdsch[2][20][2][21]; + uint32_t nr_gold_pdsch[2][20][2][52]; /// PDCCH DMRS uint32_t nr_gold_pdcch[7][20][3][52]; From cc847e9c5c9a4d4c618ff668c3a3cb77fbcceeb2 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Thu, 14 Mar 2019 17:29:17 +0100 Subject: [PATCH 039/117] bugfix in nr_initial_sync --- openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index e75f5a647a..26c01d3bb6 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -154,7 +154,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #endif // computing channel estimation for selected best ssb for(int i=pbch_initial_symbol; ii_ssb,best_ssb->n_hf); + nr_pbch_channel_estimation(ue,0,0,i,i-pbch_initial_symbol,temp_ptr->i_ssb,temp_ptr->n_hf); #if UE_TIMING_TRACE stop_meas(&ue->dlsch_channel_estimation_stats); #endif From 02d3decd6d74f50adaac09986c8d9bfe1440a28a Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Fri, 15 Mar 2019 12:43:47 +0100 Subject: [PATCH 040/117] another bugfix nr_initial_sync --- openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 26c01d3bb6..23baadda8a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -81,7 +81,7 @@ NR_UE_SSB* insert_into_list(NR_UE_SSB *head, NR_UE_SSB *node) { NR_UE_SSB *current = head; while (current->next_ssb !=NULL) { NR_UE_SSB *temp=current->next_ssb; - if(node->metric > current->metric) { + if(node->metric > temp->metric) { node->next_ssb = temp; current->next_ssb = node; return head; From d13644773d1603a1518657c8f5fd23a5e8d6bf5c Mon Sep 17 00:00:00 2001 From: laurent Date: Mon, 18 Mar 2019 13:30:25 +0100 Subject: [PATCH 041/117] some critical warnings --- openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c | 2 +- openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h | 2 +- openair1/PHY/NR_UE_TRANSPORT/dci_nr.c | 4 ++-- openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 2 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 4 ++-- openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h | 4 ++-- openair1/PHY/defs_nr_UE.h | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 6 +++--- openair1/SIMULATION/NR_PHY/pbchsim.c | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 1 + openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c | 3 --- 12 files changed, 16 insertions(+), 18 deletions(-) diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index bec322b946..a1a17a9d9e 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -525,7 +525,7 @@ void computeBeta(t_nrPolar_params *pp,decoder_node_t *node) { } -void generic_polar_decoder(t_nrPolar_params *pp,decoder_node_t *node) { +void generic_polar_decoder(const t_nrPolar_params *pp,decoder_node_t *node) { // Apply F to left diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index d42e8bb6fc..39c2620406 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -184,7 +184,7 @@ int8_t polar_decoder_dci(double *input, uint8_t pathMetricAppr, uint16_t n_RNTI); -void generic_polar_decoder(t_nrPolar_params *, +void generic_polar_decoder(const t_nrPolar_params *, decoder_node_t *); void build_decoder_tree(t_nrPolar_params *pp); diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index 6f2f5bcf2d..c476d42768 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -1430,8 +1430,8 @@ void nr_dci_decoding_procedure0(int s, dci_alloc[*dci_cnt].firstCCE = CCEind; dci_alloc[*dci_cnt].dci_pdu[0] = dci_estimation[0]; dci_alloc[*dci_cnt].dci_pdu[1] = dci_estimation[1]; - dci_alloc[*dci_cnt].dci_pdu[2] = dci_estimation[2]; - dci_alloc[*dci_cnt].dci_pdu[3] = dci_estimation[3]; + //dci_alloc[*dci_cnt].dci_pdu[2] = dci_estimation[2]; + //dci_alloc[*dci_cnt].dci_pdu[3] = dci_estimation[3]; //#ifdef NR_PDCCH_DCI_DEBUG printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> rnti matches -> DCI FOUND !!! crc =>0x%x, sizeof_bits %d, sizeof_bytes %d \n", dci_alloc[*dci_cnt].rnti, dci_alloc[*dci_cnt].dci_length, sizeof_bytes); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index e5f079ebc3..02b3d57afe 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -100,7 +100,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) ret = nr_rx_pbch(ue, - &ue->proc.proc_rxtx[0], + 0, ue->pbch_vars[0], frame_parms, 0, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 1ce2f347ab..6a86c12c24 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -409,7 +409,7 @@ unsigned char sign(int8_t x) { 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,6,23}; int nr_rx_pbch( PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc, + int subframe_rx, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -435,7 +435,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, //time_stats_t path_metric,sorting,update_LLR; memset(&pbch_a[0], 0, sizeof(uint8_t) * NR_POLAR_PBCH_PAYLOAD_BITS); //printf("nr_pbch_ue nid_cell %d\n",frame_parms->Nid_cell); - int subframe_rx = proc->subframe_rx; + pbch_e_rx = &nr_ue_pbch_vars->llr[0]; // clear LLR buffer memset(nr_ue_pbch_vars->llr,0,NR_POLAR_PBCH_E); 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 3c272b9c17..e8d22ac11c 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1118,7 +1118,7 @@ int rx_sss(PHY_VARS_NR_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uin \returns number of tx antennas or -1 if error */ int nr_rx_pbch( PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc, + int subframe_rx, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -1675,7 +1675,7 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint8_t eNB_id, int frame, uint8_t nr_tti_rx, - uint32_t dci_pdu[4], + uint64_t dci_pdu[2], uint16_t rnti, uint8_t dci_length, NR_DCI_format_t dci_format, diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a3c404ba61..95381ad560 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -1079,7 +1079,7 @@ typedef struct { uint32_t nr_gold_pbch[2][64][NR_PBCH_DMRS_LENGTH_DWORD]; /// PDSCH DMRS - uint32_t nr_gold_pdsch[2][20][2][21]; + uint32_t nr_gold_pdsch[2][20][2][52]; /// PDCCH DMRS uint32_t nr_gold_pdcch[7][20][3][52]; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 1a631000f5..f2e701deed 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -123,7 +123,7 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint8_t eNB_id, int frame, uint8_t nr_tti_rx, - uint32_t dci_pdu[4], + uint64_t dci_pdu[2], uint16_t rnti, uint8_t dci_length, NR_DCI_format_t dci_format, @@ -2969,7 +2969,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_IN); //LOG_I(PHY,"[UE %d] Frame %d, Trying PBCH %d (NidCell %d, eNB_id %d)\n",ue->Mod_id,frame_rx,pbch_phase,ue->frame_parms.Nid_cell,eNB_id); - ret = nr_rx_pbch(ue, proc, + ret = nr_rx_pbch(ue, proc->subframe_rx, ue->pbch_vars[eNB_id], &ue->frame_parms, eNB_id, @@ -3085,7 +3085,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * uint16_t p_rnti=P_RNTI; uint16_t si_rnti=SI_RNTI; uint16_t ra_rnti=99; - uint16_t sp_csi_rnti,sfi_rnti,int_rnti,tpc_pusch_rnti,tpc_pucch_rnti,tpc_srs_rnti; //FIXME + uint16_t sp_csi_rnti=0,sfi_rnti=0,int_rnti=0,tpc_pusch_rnti=0,tpc_pucch_rnti=0,tpc_srs_rnti=0; //FIXME uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES] = {c_rnti,cs_rnti,new_rnti,tc_rnti,p_rnti,si_rnti,ra_rnti,sp_csi_rnti,sfi_rnti,int_rnti,tpc_pusch_rnti,tpc_pucch_rnti,tpc_srs_rnti}; #ifdef NR_PDCCH_SCHED_DEBUG diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 214a33fb73..572b1bb9b2 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -615,7 +615,7 @@ int main(int argc, char **argv) NR_PBCH_EST); ret = nr_rx_pbch(UE, - &UE->proc.proc_rxtx[0], + 0, UE->pbch_vars[0], frame_parms, 0, diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 44f1cf05ea..e3dad2db70 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -1754,7 +1754,7 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); dci->time_dom_resource_assignment, dlsch_config_pdu_1_0->number_symbols, dlsch_config_pdu_1_0->start_symbol); - printf(">>> (nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%d\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", + printf(">>> (nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%f\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", dlsch_config_pdu_1_0->vrb_to_prb_mapping, dlsch_config_pdu_1_0->mcs, dlsch_config_pdu_1_0->ndi, diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index 0911cac62d..1e5150c93f 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -396,6 +396,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0]; if((dlsch != NULL) && (dlsch->rnti == rnti)){ LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); + LOG_E(PHY,"Calling with wrong paramter type\n"); clean_eNb_dlsch(dlsch); } } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index 114ec60447..1f88e2a03c 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -462,6 +462,3 @@ int get_symbolsperslot(nfapi_nr_config_request_t *cfg) { } -int nr_schedule_dci() { - -} From afb40cf509507b96d7f245d2fe7ce91043e6b8c3 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Mon, 18 Mar 2019 17:13:19 +0100 Subject: [PATCH 042/117] CI: trying to increase the RAM size on the phy-sim VM Signed-off-by: Raphael Defosseux --- ci-scripts/oai-ci-vm-tool | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool index fd867b6661..1245d046ff 100755 --- a/ci-scripts/oai-ci-vm-tool +++ b/ci-scripts/oai-ci-vm-tool @@ -254,7 +254,7 @@ case $key in LOG_PATTERN=.Rel15.txt NB_PATTERN_FILES=9 BUILD_OPTIONS="--phy_simulators" - VM_MEMORY=4096 + VM_MEMORY=8192 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" NBARGS=$[$NBARGS+256] shift @@ -333,7 +333,7 @@ case $key in LOG_PATTERN=.Rel15.txt NB_PATTERN_FILES=9 BUILD_OPTIONS="--phy_simulators" - VM_MEMORY=4096 + VM_MEMORY=8192 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" NBARGS=$[$NBARGS+256] ;; From d9c68d8b30aed4518be25a4bfcd1aa6c54a5dd4d Mon Sep 17 00:00:00 2001 From: laurent Date: Thu, 21 Mar 2019 14:15:26 +0100 Subject: [PATCH 043/117] new thread model --- cmake_targets/CMakeLists.txt | 7 +- common/utils/threadPool/Makefile | 8 + common/utils/threadPool/measurement_display.c | 61 ++ common/utils/threadPool/thread-pool.c | 219 +++++ common/utils/threadPool/thread-pool.h | 244 ++++++ common/utils/threadPool/thread-pool.md | 69 ++ executables/nr-ue.c | 803 +++++++++++++++++ executables/nr-uesoftmodem.c | 826 ++++++++++++++++++ executables/nr-uesoftmodem.h | 246 ++++++ .../PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c | 7 +- .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 2 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 4 +- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 45 +- openair1/PHY/defs_nr_UE.h | 21 - openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 1 - openair1/SCHED_UE/phy_procedures_lte_ue.c | 6 +- openair2/LAYER2/NR_MAC_UE/mac.h | 8 +- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 4 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 8 +- targets/ARCH/COMMON/common_lib.h | 2 +- 21 files changed, 2502 insertions(+), 91 deletions(-) create mode 100644 common/utils/threadPool/Makefile create mode 100644 common/utils/threadPool/measurement_display.c create mode 100644 common/utils/threadPool/thread-pool.c create mode 100644 common/utils/threadPool/thread-pool.h create mode 100644 common/utils/threadPool/thread-pool.md create mode 100644 executables/nr-ue.c create mode 100644 executables/nr-uesoftmodem.c create mode 100644 executables/nr-uesoftmodem.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index af9c3edf68..3da38c4f5f 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2425,11 +2425,10 @@ add_executable(nr-uesoftmodem ${rrc_h} ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h - ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c - ${OPENAIR_TARGETS}/RT/USER/nr-ue.c - ${OPENAIR_TARGETS}/RT/USER/nr-uesoftmodem.c + ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c + ${OPENAIR_DIR}/executables//nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/nr-ue.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c -# ${OPENAIR_TARGETS}/COMMON/create_tasks_ue.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c ${OPENAIR3_DIR}/NAS/UE/nas_ue_task.c diff --git a/common/utils/threadPool/Makefile b/common/utils/threadPool/Makefile new file mode 100644 index 0000000000..6f0e884886 --- /dev/null +++ b/common/utils/threadPool/Makefile @@ -0,0 +1,8 @@ +all: measurement_display thread-pool-test + +measurement_display: measurement_display.c thread-pool.h + gcc measurement_display.c -I /data/openairinterface5g.nr/common/utils/ -I. /data/openairinterface5g.nr/common/utils/backtrace.c -lpthread -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o measurement_display + +thread-pool-test: thread-pool.c thread-pool.h + gcc -g thread-pool.c -I /data/openairinterface5g.nr/common/utils/ -I. /data/openairinterface5g.nr/common/utils/backtrace.c -lpthread -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o thread-pool-test + diff --git a/common/utils/threadPool/measurement_display.c b/common/utils/threadPool/measurement_display.c new file mode 100644 index 0000000000..ac7beca1fe --- /dev/null +++ b/common/utils/threadPool/measurement_display.c @@ -0,0 +1,61 @@ +/* + Author: Laurent THOMAS, Open Cells + copyleft: OpenAirInterface Software Alliance and it's licence +*/ + +#define __USE_GNU +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "thread-pool.h" + +#define SEP "\t" + +uint64_t cpuCyclesMicroSec; + +int main(int argc, char *argv[]) { + if(argc != 2) { + printf("Need one paramter: the trace Linux pipe (fifo)"); + exit(1); + } + + mkfifo(argv[1],0666); + int fd=open(argv[1], O_RDONLY); + + if ( fd == -1 ) { + perror("open read mode trace file:"); + exit(1); + } + + uint64_t deb=rdtsc(); + usleep(100000); + cpuCyclesMicroSec=(rdtsc()-deb)/100000; + printf("Cycles per µs: %lu\n",cpuCyclesMicroSec); + printf("Key" SEP "delay to process" SEP "processing time" SEP "delay to be read answer\n"); + notifiedFIFO_elt_t doneRequest; + + while ( 1 ) { + if ( read(fd,&doneRequest, sizeof(doneRequest)) == sizeof(doneRequest)) { + printf("%lu" SEP "%lu" SEP "%lu" SEP "%lu" "\n", + doneRequest.key, + (doneRequest.startProcessingTime-doneRequest.creationTime)/cpuCyclesMicroSec, + (doneRequest.endProcessingTime-doneRequest.startProcessingTime)/cpuCyclesMicroSec, + (doneRequest.returnTime-doneRequest.endProcessingTime)/cpuCyclesMicroSec + ); + } else { + printf("no measurements\n"); + sleep(1); + } + } +} diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c new file mode 100644 index 0000000000..ca050ea098 --- /dev/null +++ b/common/utils/threadPool/thread-pool.c @@ -0,0 +1,219 @@ +/* + Author: Laurent THOMAS, Open Cells + copyleft: OpenAirInterface Software Alliance and it's licence +*/ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +void displayList(notifiedFIFO_t *nf) { + int n=0; + notifiedFIFO_elt_t *ptr=nf->outF; + + while(ptr) { + printf("element: %d, key: %lu\n",++n,ptr->key); + ptr=ptr->next; + } + + printf("End of list: %d elements\n",n); +} + +static inline notifiedFIFO_elt_t *pullNotifiedFifoRemember( notifiedFIFO_t *nf, struct one_thread *thr) { + mutexlock(nf->lockF); + + while(!nf->outF) + condwait(nf->notifF, nf->lockF); + + notifiedFIFO_elt_t *ret=nf->outF; + nf->outF=nf->outF->next; + + if (nf->outF==NULL) + nf->inF=NULL; + + // For abort feature + thr->runningOnKey=ret->key; + thr->abortFlag=false; + mutexunlock(nf->lockF); + return ret; +} + +void *one_thread(void *arg) { + struct one_thread *myThread=(struct one_thread *) arg; + struct thread_pool *tp=myThread->pool; + // configure the thread core assignment + // TBD: reserve the core for us exclusively + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(myThread->coreID, &cpuset); + pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + //Configure the thread scheduler policy for Linux + struct sched_param sparam= {0}; + sparam.sched_priority = sched_get_priority_max(SCHED_RR); + pthread_setschedparam(pthread_self(), SCHED_RR, &sparam); + // set the thread name for debugging + sprintf(myThread->name,"Tpool_%d",myThread->coreID); + pthread_setname_np(pthread_self(), myThread->name ); + + // Infinite loop to process requests + do { + notifiedFIFO_elt_t *elt=pullNotifiedFifoRemember(&tp->incomingFifo, myThread); + + if (tp->measurePerf) elt->startProcessingTime=rdtsc(); + + elt->processingFunc(NotifiedFifoData(elt)); + + if (tp->measurePerf) elt->endProcessingTime=rdtsc(); + + if (elt->reponseFifo) { + // Check if the job is still alive, else it has been aborted + mutexlock(tp->incomingFifo.lockF); + + if (myThread->abortFlag) + delNotifiedFIFO_elt(elt); + else + pushNotifiedFIFO(elt->reponseFifo, elt); + + mutexunlock(tp->incomingFifo.lockF); + } + } while (true); +} + +void initTpool(char *params,tpool_t *pool, bool performanceMeas) { + memset(pool,0,sizeof(*pool)); + char *measr=getenv("threadPoolMeasurements"); + pool->measurePerf=performanceMeas; + // force measurement if the output is defined + pool->measurePerf=measr!=NULL; + + if (measr) { + mkfifo(measr,0666); + AssertFatal(-1 != (pool->dummyTraceFd= + open(measr, O_RDONLY| O_NONBLOCK)),""); + AssertFatal(-1 != (pool->traceFd= + open(measr, O_WRONLY|O_APPEND|O_NOATIME|O_NONBLOCK)),""); + } else + pool->traceFd=-1; + + //Configure the thread scheduler policy for Linux + struct sched_param sparam= {0}; + sparam.sched_priority = sched_get_priority_max(SCHED_RR)-1; + pthread_setschedparam(pthread_self(), SCHED_RR, &sparam); + pool->activated=true; + initNotifiedFIFO(&pool->incomingFifo); + char *saveptr, * curptr; + pool->nbThreads=0; + pool->restrictRNTI=false; + curptr=strtok_r(params,",",&saveptr); + + while ( curptr!=NULL ) { + if (curptr[0] == 'u' || curptr[0] == 'U') { + pool->restrictRNTI=true; + } else if ( curptr[0]>='0' && curptr[0]<='9' ) { + struct one_thread *tmp=pool->allthreads; + pool->allthreads=(struct one_thread *)malloc(sizeof(struct one_thread)); + pool->allthreads->next=tmp; + printf("create a thread for core %d\n", atoi(curptr)); + pool->allthreads->coreID=atoi(curptr); + pool->allthreads->id=pool->nbThreads; + pool->allthreads->pool=pool; + pthread_create(&pool->allthreads->threadID, NULL, one_thread, (void *)pool->allthreads); + pool->nbThreads++; + } else if (curptr[0] == 'n' || curptr[0] == 'N') { + pool->activated=false; + } else + printf("Error in options for thread pool: %s\n",curptr); + + curptr=strtok_r(NULL,",",&saveptr); + } + + if (pool->activated && pool->nbThreads==0) { + printf("No servers created in the thread pool, exit\n"); + exit(1); + } +} + +#ifdef TEST_THREAD_POOL + +struct testData { + int id; + char txt[30]; +}; + +void processing(void *arg) { + struct testData *in=(struct testData *)arg; + printf("doing: %d, %s, in thr %ld\n",in->id, in->txt,pthread_self() ); + sprintf(in->txt,"Done by %ld, job %d", pthread_self(), in->id); + usleep(rand()%100); + printf("done: %d, %s, in thr %ld\n",in->id, in->txt,pthread_self() ); +} + +int main() { + notifiedFIFO_t myFifo; + initNotifiedFIFO(&myFifo); + pushNotifiedFIFO(&myFifo,newNotifiedFIFO_elt(sizeof(struct testData), 1234,NULL,NULL)); + + for(int i=10; i>1; i--) { + pushNotifiedFIFO(&myFifo,newNotifiedFIFO_elt(sizeof(struct testData), 1000+i,NULL,NULL)); + } + + displayList(&myFifo); + notifiedFIFO_elt_t *tmp=pullNotifiedFIFO(&myFifo); + printf("pulled: %lu\n", tmp->key); + displayList(&myFifo); + tmp=pullNotifiedFIFO(&myFifo); + printf("pulled: %lu\n", tmp->key); + displayList(&myFifo); + abortNotifiedFIFO(&myFifo,1005); + printf("aborted 1005\n"); + displayList(&myFifo); + pushNotifiedFIFO(&myFifo,newNotifiedFIFO_elt(sizeof(struct testData), 12345678, NULL, NULL)); + displayList(&myFifo); + abortNotifiedFIFO(&myFifo,12345678); + printf("aborted 12345678\n"); + displayList(&myFifo); + + do { + tmp=pollNotifiedFIFO(&myFifo); + + if (tmp) { + printf("pulled: %lu\n", tmp->key); + displayList(&myFifo); + } else + printf("Empty list \n"); + } while(tmp); + + tpool_t pool; + char params[]="1,2,3,u"; + initTpool(params,&pool, true); + notifiedFIFO_t worker_back; + initNotifiedFIFO(&worker_back); + + for (int i=0; i <1000 ; i++) { + notifiedFIFO_elt_t *work=newNotifiedFIFO_elt(sizeof(struct testData), i, &worker_back, processing); + struct testData *x=(struct testData *)NotifiedFifoData(work); + x->id=i; + pushTpool(&pool, work); + } + + do { + tmp=pullTpool(&worker_back,&pool); + + if (tmp) { + struct testData *dd=NotifiedFifoData(tmp); + printf("Result: %s\n",dd->txt); + delNotifiedFIFO_elt(tmp); + } else + printf("Empty list \n"); + + abortTpool(&pool,510); + } while(tmp); + + return 0; +} +#endif diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h new file mode 100644 index 0000000000..6f34508c5a --- /dev/null +++ b/common/utils/threadPool/thread-pool.h @@ -0,0 +1,244 @@ +/* + Author: Laurent THOMAS, Open Cells + copyleft: OpenAirInterface Software Alliance and it's licence +*/ + +#ifndef THREAD_POOL_H +#define THREAD_POOL_H +#include +#include +#include +#include +#include +#include + +#ifdef DEBUG + #define THREADINIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP +#else + #define THREADINIT PTHREAD_MUTEX_INITIALIZER +#endif +#define mutexinit(mutex) AssertFatal(pthread_mutex_init(&mutex,NULL)==0,""); +#define condinit(signal) AssertFatal(pthread_cond_init(&signal,NULL)==0,""); +#define mutexlock(mutex) AssertFatal(pthread_mutex_lock(&mutex)==0,""); +#define mutextrylock(mutex) pthread_mutex_trylock(&mutex) +#define mutexunlock(mutex) AssertFatal(pthread_mutex_unlock(&mutex)==0,""); +#define condwait(condition, mutex) AssertFatal(pthread_cond_wait(&condition, &mutex)==0,""); +#define condbroadcast(signal) AssertFatal(pthread_cond_broadcast(&signal)==0,""); +#define condsignal(signal) AssertFatal(pthread_cond_broadcast(&signal)==0,""); + +typedef struct notifiedFIFO_elt_s { + struct notifiedFIFO_elt_s *next; + uint64_t key; //To filter out elements + struct notifiedFIFO_s *reponseFifo; + void (*processingFunc)(void *); + bool malloced; + uint64_t creationTime; + uint64_t startProcessingTime; + uint64_t endProcessingTime; + uint64_t returnTime; + void *msgData; +} notifiedFIFO_elt_t; + +typedef struct notifiedFIFO_s { + notifiedFIFO_elt_t *outF; + notifiedFIFO_elt_t *inF; + pthread_mutex_t lockF; + pthread_cond_t notifF; +} notifiedFIFO_t; + +// You can use this allocator or use any piece of memory +static inline notifiedFIFO_elt_t *newNotifiedFIFO_elt(int size, + uint64_t key, + notifiedFIFO_t *reponseFifo, + void (*processingFunc)(void *)) { + notifiedFIFO_elt_t *ret; + AssertFatal( NULL != (ret=(notifiedFIFO_elt_t *) malloc(sizeof(notifiedFIFO_elt_t)+size+32)), ""); + ret->next=NULL; + ret->key=key; + ret->reponseFifo=reponseFifo; + ret->processingFunc=processingFunc; + // We set user data piece aligend 32 bytes to be able to process it with SIMD + ret->msgData=(void *)ret+(sizeof(notifiedFIFO_elt_t)/32+1)*32; + ret->malloced=true; + return ret; +} + +static inline void *NotifiedFifoData(notifiedFIFO_elt_t *elt) { + return elt->msgData; +} + +static inline void delNotifiedFIFO_elt(notifiedFIFO_elt_t *elt) { + if (elt->malloced) { + elt->malloced=false; + free(elt); + } else + printf("delNotifiedFIFO on something not allocated by newNotifiedFIFO\n"); + + //LOG_W(UTIL,"delNotifiedFIFO on something not allocated by newNotifiedFIFO\n"); +} + +static inline void initNotifiedFIFO(notifiedFIFO_t *nf) { + mutexinit(nf->lockF); + condinit (nf->notifF); + nf->inF=NULL; + nf->outF=NULL; + // No delete function: the creator has only to free the memory +} + +static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) { + mutexlock(nf->lockF); + msg->next=NULL; + + if (nf->outF == NULL) + nf->outF = msg; + + if (nf->inF) + nf->inF->next = msg; + + nf->inF = msg; + condbroadcast(nf->notifF); + mutexunlock(nf->lockF); +} + +static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { + mutexlock(nf->lockF); + + while(!nf->outF) + condwait(nf->notifF, nf->lockF); + + notifiedFIFO_elt_t *ret=nf->outF; + nf->outF=nf->outF->next; + + if (nf->outF==NULL) + nf->inF=NULL; + + mutexunlock(nf->lockF); + return ret; +} + +static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) { + int tmp=mutextrylock(nf->lockF); + + if (tmp != 0 ) + return NULL; + + notifiedFIFO_elt_t *ret=nf->outF; + + if (ret!=NULL) + nf->outF=nf->outF->next; + + if (nf->outF==NULL) + nf->inF=NULL; + + mutexunlock(nf->lockF); + return ret; +} + +// This function aborts all messages matching the key +// If the queue is used in thread pools, it doesn't cancels already running processing +// because the message has already been picked +static inline void abortNotifiedFIFO(notifiedFIFO_t *nf, uint64_t key) { + mutexlock(nf->lockF); + notifiedFIFO_elt_t **start=&nf->outF; + + while(*start!=NULL) { + if ( (*start)->key == key ) { + notifiedFIFO_elt_t *request=*start; + *start=(*start)->next; + delNotifiedFIFO_elt(request); + } + + if (*start != NULL) + start=&(*start)->next; + } + + mutexunlock(nf->lockF); +} + +struct one_thread { + pthread_t threadID; + int id; + int coreID; + char name[256]; + uint64_t runningOnKey; + bool abortFlag; + struct thread_pool *pool; + struct one_thread *next; +}; + +typedef struct thread_pool { + int activated; + bool measurePerf; + int traceFd; + int dummyTraceFd; + uint64_t cpuCyclesMicroSec; + uint64_t startProcessingUE; + int nbThreads; + bool restrictRNTI; + notifiedFIFO_t incomingFifo; + struct one_thread *allthreads; +} tpool_t; + +static inline void pushTpool(tpool_t *t, notifiedFIFO_elt_t *msg) { + if (t->measurePerf) msg->creationTime=rdtsc(); + + pushNotifiedFIFO(&t->incomingFifo, msg); +} + +static inline notifiedFIFO_elt_t *pullTpool(notifiedFIFO_t *responseFifo, tpool_t *t) { + notifiedFIFO_elt_t *msg= pullNotifiedFIFO(responseFifo); + + if (t->measurePerf) + msg->returnTime=rdtsc(); + + if (t->traceFd) + if(write(t->traceFd, msg, sizeof(*msg))); + + return msg; +} + +static inline notifiedFIFO_elt_t *tryPullTpool(notifiedFIFO_t *responseFifo, tpool_t *t) { + notifiedFIFO_elt_t *msg= pollNotifiedFIFO(responseFifo); + + if (msg == NULL) + return NULL; + + if (t->measurePerf) + msg->returnTime=rdtsc(); + + if (t->traceFd) + if(write(t->traceFd, msg, sizeof(*msg))); + + return msg; +} + +static inline void abortTpool(tpool_t *t, uint64_t key) { + notifiedFIFO_t *nf=&t->incomingFifo; + mutexlock(nf->lockF); + notifiedFIFO_elt_t **start=&nf->outF; + + while(*start!=NULL) { + if ( (*start)->key == key ) { + notifiedFIFO_elt_t *request=*start; + *start=(*start)->next; + delNotifiedFIFO_elt(request); + } + + if (*start != NULL) + start=&(*start)->next; + } + + struct one_thread *ptr=t->allthreads; + + while(ptr!=NULL) { + if (ptr->runningOnKey==key) + ptr->abortFlag=true; + + ptr=ptr->next; + } + + mutexunlock(nf->lockF); +} +void initTpool(char *params,tpool_t *pool, bool performanceMeas); + +#endif diff --git a/common/utils/threadPool/thread-pool.md b/common/utils/threadPool/thread-pool.md new file mode 100644 index 0000000000..92cc21b975 --- /dev/null +++ b/common/utils/threadPool/thread-pool.md @@ -0,0 +1,69 @@ +# Thread pool + +The thread pool is a working server, made of a set of worker threads that can be mapped on CPU cores. + +Each worker loop on pick from the same input queue jobs to do. +When a job is done, the worker sends a return if a return is defined. + +A selective abort allows to cancel parallel jobs (usage: a client pushed jobs, but from a response of one job, the other linked jobs becomes useless). + +All the thread pool functions are thread safe, nevertheless the working functions are implemented by the thread pool client, so the client has to tackle the parallel execution of his functions called "processingFunc" hereafter. + +## license +Author: Laurent Thomas, Open cells project +The owner share the code usage to Openairsoftware alliance as per OSA license terms + +# jobs + +A job is a message (notifiedFIFO_elt_t): +next: internal FIFO chain, do not set it +key: a long int that the client can use to identify a message or a group of messages +responseFifo: if the client defines a response FIFO, the message will be posted back after processing +processingFunc: any funtion (type void processingFunc(void *)) that the worker will launch +msgData: the data passed to processingFunc. It can be added automatically, or you can set it to a buffer you are managing +malloced: a boolean that enable internal free in these cases: no return Fifo or Abort feature + +The job messages can be created with newNotifiedFIFO_elt() and delNotifiedFIFO_elt() or managed by the client. + +# Queues of jobs + +Queues are type of: notifiedFIFO_t that must be initialized by init_notifiedFIFO() +No delete function is required, the creator has only to free the data of type notifiedFIFO_t + +push_notifiedFIFO() add a job in the queue +pull_notifiedFIFO() is blocking, poll_notifiedFIFO() is non blocking + +abort_notifiedFIFO() allows the customer to delete all waiting jobs that match with the key (see key in jobs definition) + +# Thread pools + +## initialization +The clients can create one or more thread pools with init_tpool() +the params string structure: describes a list of cores, separated by "," that run a worker thread + +The threads are all Linux real time scheduler, their name is set automatically is "Tpool_" + +## adding jobs +The client create their jobs messages as a notifiedFIFO_elt_t, then they push it with pushTpool() (that internally calls push_notifiedFIFO()) + +If they need a return, they have to create response queues with init_notifiedFIFO() and set this FIFO pointer in the notifiedFIFO_elt_t before pushing the job. + +## abort + +A abort service abortTpool() allows to abort all jobs that match a key (see jobs "key"). When the abort returns, it garanties no job (matching the key) response will be posted on response queues. + +Nevertheless, jobs already performed before the return of abortTpool() are pushed in the response Fifo queue. + +## Performance measurements + +A performance measurement is integrated: the pool will automacillay fill timestamps: + +* creationTime: time the request is push to the pool; +* startProcessingTime: time a worker start to run on the job +* endProcessingTime: time the worker finished the job +* returnTime: time the client reads the result + +if you set the environement variable: thread-pool-measurements to a valid file name +These measurements will be wrote to this Linux pipe. + +A tool to read the linux fifo and display it in ascii will be provided (TBD) diff --git a/executables/nr-ue.c b/executables/nr-ue.c new file mode 100644 index 0000000000..d45ee37d19 --- /dev/null +++ b/executables/nr-ue.c @@ -0,0 +1,803 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.0 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file lte-ue.c + * \brief threads and support functions for real-time LTE UE target + * \author R. Knopp, F. Kaltenberger, Navid Nikaein + * \date 2015 + * \version 0.1 + * \company Eurecom + * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr + * \note + * \warning + */ +#include "executables/nr-uesoftmodem.h" + +#include "LAYER2/NR_MAC_UE/mac.h" +//#include "RRC/LTE/rrc_extern.h" +#include "PHY_INTERFACE/phy_interface_extern.h" + +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "fapi_nr_ue_l1.h" +#include "PHY/phy_extern_nr_ue.h" +#include "PHY/INIT/phy_init.h" +#include "PHY/MODULATION/modulation_UE.h" +#include "LAYER2/NR_MAC_UE/mac_proto.h" +#include "RRC/NR_UE/rrc_proto.h" + +//#ifndef NO_RAT_NR +#include "SCHED_NR/phy_frame_config_nr.h" +//#endif +#include "SCHED_NR_UE/defs.h" + +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" + +#include "common/utils/LOG/log.h" +#include "common/utils/LOG/vcd_signal_dumper.h" + +#include "T.h" + +#ifdef XFORMS + #include "PHY/TOOLS/nr_phy_scope.h" + + extern char do_forms; +#endif + + +extern double cpuf; +//static nfapi_nr_config_request_t config_t; +//static nfapi_nr_config_request_t* config =&config_t; + +/* + * NR SLOT PROCESSING SEQUENCE + * + * Processing occurs with following steps for connected mode: + * + * - Rx samples for a slot are received, + * - PDCCH processing (including DCI extraction for downlink and uplink), + * - PDSCH processing (including transport blocks decoding), + * - PUCCH/PUSCH (transmission of acknowledgements, CSI, ... or data). + * + * Time between reception of the slot and related transmission depends on UE processing performance. + * It is defined by the value NR_UE_CAPABILITY_SLOT_RX_TO_TX. + * + * In NR, network gives the duration between Rx slot and Tx slot in the DCI: + * - for reception of a PDSCH and its associated acknowledgment slot (with a PUCCH or a PUSCH), + * - for reception of an uplink grant and its associated PUSCH slot. + * + * So duration between reception and it associated transmission depends on its transmission slot given in the DCI. + * NR_UE_CAPABILITY_SLOT_RX_TO_TX means the minimum duration but higher duration can be given by the network because UE can support it. + * + * Slot k + * -------+------------+-------- + * Frame | Tx samples | + * Subframe | buffer | + * Slot n -------+------------+-------- + * ------ +------------+-------- | + * | Rx samples | | + * | buffer | | + * -------+------------+-------- | + * | | + * V | + * +------------+ | + * | PDCCH | | + * | processing | | + * +------------+ | + * | | | + * | v | + * | +------------+ | + * | | PDSCH | | + * | | processing | decoding result | + * | +------------+ -> ACK/NACK of PDSCH | + * | | | + * | v | + * | +-------------+------------+ | + * | | PUCCH/PUSCH | Tx samples | | + * | | processing | transfer | | + * | +-------------+------------+ | + * | | + * |/___________________________________________________________\| + * \ duration between reception and associated transmission / + * + * Remark: processing is done slot by slot, it can be distribute on different threads which are executed in parallel. + * This is an architecture optimization in order to cope with real time constraints. + * By example, for LTE, subframe processing is spread over 4 different threads. + * + */ + +#ifndef NO_RAT_NR + #define DURATION_RX_TO_TX (NR_UE_CAPABILITY_SLOT_RX_TO_TX) /* for NR this will certainly depends to such UE capability which is not yet defined */ +#else + #define DURATION_RX_TO_TX (4) /* For LTE, this duration is fixed to 4 and it is linked to LTE standard for both modes FDD/TDD */ +#endif + +#define FRAME_PERIOD 100000000ULL +#define DAQ_PERIOD 66667ULL +#define FIFO_PRIORITY 40 + +typedef enum { + pss=0, + pbch=1, + si=2 +} sync_mode_t; + + +int32_t **rxdata; +int32_t **txdata; + +#define KHz (1000UL) +#define MHz (1000*KHz) +typedef struct eutra_band_s { + int16_t band; + uint32_t ul_min; + uint32_t ul_max; + uint32_t dl_min; + uint32_t dl_max; + lte_frame_type_t frame_type; +} eutra_band_t; + +typedef struct band_info_s { + int nbands; + eutra_band_t band_info[100]; +} band_info_t; + +band_info_t bands_to_scan; + +static const eutra_band_t eutra_bands[] = { + { 1, 1920 * MHz, 1980 * MHz, 2110 * MHz, 2170 * MHz, FDD}, + { 2, 1850 * MHz, 1910 * MHz, 1930 * MHz, 1990 * MHz, FDD}, + { 3, 1710 * MHz, 1785 * MHz, 1805 * MHz, 1880 * MHz, FDD}, + { 4, 1710 * MHz, 1755 * MHz, 2110 * MHz, 2155 * MHz, FDD}, + { 5, 824 * MHz, 849 * MHz, 869 * MHz, 894 * MHz, FDD}, + { 6, 830 * MHz, 840 * MHz, 875 * MHz, 885 * MHz, FDD}, + { 7, 2500 * MHz, 2570 * MHz, 2620 * MHz, 2690 * MHz, FDD}, + { 8, 880 * MHz, 915 * MHz, 925 * MHz, 960 * MHz, FDD}, + { 9, 1749900 * KHz, 1784900 * KHz, 1844900 * KHz, 1879900 * KHz, FDD}, + {10, 1710 * MHz, 1770 * MHz, 2110 * MHz, 2170 * MHz, FDD}, + {11, 1427900 * KHz, 1452900 * KHz, 1475900 * KHz, 1500900 * KHz, FDD}, + {12, 698 * MHz, 716 * MHz, 728 * MHz, 746 * MHz, FDD}, + {13, 777 * MHz, 787 * MHz, 746 * MHz, 756 * MHz, FDD}, + {14, 788 * MHz, 798 * MHz, 758 * MHz, 768 * MHz, FDD}, + {17, 704 * MHz, 716 * MHz, 734 * MHz, 746 * MHz, FDD}, + {20, 832 * MHz, 862 * MHz, 791 * MHz, 821 * MHz, FDD}, + {22, 3510 * MHz, 3590 * MHz, 3410 * MHz, 3490 * MHz, FDD}, + {33, 1900 * MHz, 1920 * MHz, 1900 * MHz, 1920 * MHz, TDD}, + {34, 2010 * MHz, 2025 * MHz, 2010 * MHz, 2025 * MHz, TDD}, + {35, 1850 * MHz, 1910 * MHz, 1850 * MHz, 1910 * MHz, TDD}, + {36, 1930 * MHz, 1990 * MHz, 1930 * MHz, 1990 * MHz, TDD}, + {37, 1910 * MHz, 1930 * MHz, 1910 * MHz, 1930 * MHz, TDD}, + {38, 2570 * MHz, 2620 * MHz, 2570 * MHz, 2630 * MHz, TDD}, + {39, 1880 * MHz, 1920 * MHz, 1880 * MHz, 1920 * MHz, TDD}, + {40, 2300 * MHz, 2400 * MHz, 2300 * MHz, 2400 * MHz, TDD}, + {41, 2496 * MHz, 2690 * MHz, 2496 * MHz, 2690 * MHz, TDD}, + {42, 3400 * MHz, 3600 * MHz, 3400 * MHz, 3600 * MHz, TDD}, + {43, 3600 * MHz, 3800 * MHz, 3600 * MHz, 3800 * MHz, TDD}, + {44, 703 * MHz, 803 * MHz, 703 * MHz, 803 * MHz, TDD}, +}; + +PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, + uint8_t UE_id, + uint8_t abstraction_flag) + +{ + PHY_VARS_NR_UE *ue; + + if (frame_parms!=(NR_DL_FRAME_PARMS *)NULL) { // if we want to give initial frame parms, allocate the PHY_VARS_UE structure and put them in + ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); + memset(ue,0,sizeof(PHY_VARS_NR_UE)); + memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); + } else ue = PHY_vars_UE_g[UE_id][0]; + + ue->Mod_id = UE_id; + ue->mac_enabled = 1; + // initialize all signal buffers + init_nr_ue_signal(ue,1,abstraction_flag); + // intialize transport + init_nr_ue_transport(ue,abstraction_flag); + return(ue); +} + +/*! + * It performs band scanning and synchonization. + * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. + */ + +typedef struct syncData_s { + PHY_VARS_NR_UE *UE; +} syncData_t; + +static void UE_synch(void *arg) { + syncData_t *syncD=(syncData_t *) arg; + int i, hw_slot_offset; + PHY_VARS_NR_UE *UE = syncD->UE; + int current_band = 0; + int current_offset = 0; + sync_mode_t sync_mode = pbch; + int CC_id = UE->CC_id; + int freq_offset=0; + UE->is_synchronized = 0; + + if (UE->UE_scan == 0) { + int ind; + + for ( ind=0; ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); + ind++) { + current_band = eutra_bands[ind].band; + LOG_D(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", current_band, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); + + if ( eutra_bands[ind].dl_min <= downlink_frequency[0][0] && eutra_bands[ind].dl_max >= downlink_frequency[0][0] ) { + for (i=0; i<4; i++) + uplink_frequency_offset[CC_id][i] = eutra_bands[ind].ul_min - eutra_bands[ind].dl_min; + + break; + } + } + + AssertFatal( ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]), "Can't find EUTRA band for frequency"); + LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", + downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], + oai_exit, openair0_cfg[0].rx_num_channels); + + for (i=0; irf_map.card].rx_num_channels; i++) { + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; + openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = + downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; + openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; + + if (uplink_frequency_offset[CC_id][i] != 0) // + openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_FDD; + else //FDD + openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_TDD; + } + + sync_mode = pbch; + } else { + current_band=0; + + for (i=0; irf_map.card].rx_num_channels; i++) { + downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[CC_id].dl_min; + uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = + bands_to_scan.band_info[CC_id].ul_min-bands_to_scan.band_info[CC_id].dl_min; + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; + openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = + downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; + openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; + } + } + + LOG_W(PHY, "Starting sync detection\n"); + + switch (sync_mode) { + case pss: + LOG_I(PHY,"[SCHED][UE] Scanning band %d (%d), freq %u\n",bands_to_scan.band_info[current_band].band, current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); + //lte_sync_timefreq(UE,current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); + current_offset += 20000000; // increase by 20 MHz + + if (current_offset > bands_to_scan.band_info[current_band].dl_max-bands_to_scan.band_info[current_band].dl_min) { + current_band++; + current_offset=0; + } + + if (current_band==bands_to_scan.nbands) { + current_band=0; + oai_exit=1; + } + + for (i=0; irf_map.card].rx_num_channels; i++) { + downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].dl_min+current_offset; + uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].ul_min-bands_to_scan.band_info[0].dl_min + current_offset; + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; + openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; + openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; + + if (UE->UE_scan_carrier) { + openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; + } + } + + break; + + case pbch: + LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); + + if (nr_initial_sync( UE, UE->mode ) == 0) { + 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_slot; + LOG_I(PHY,"Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", + hw_slot_offset, + freq_offset, + UE->rx_total_gain_dB, + downlink_frequency[0][0]+freq_offset, + downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset, + UE->UE_scan_carrier ); + + // rerun with new cell parameters and frequency-offset + for (i=0; irf_map.card].rx_num_channels; i++) { + openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; + + if (freq_offset >= 0) + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] += abs(freq_offset); + else + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] -= abs(freq_offset); + + openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i]+uplink_frequency_offset[CC_id][i]; + downlink_frequency[CC_id][i] = openair0_cfg[CC_id].rx_freq[i]; + } + + // reconfigure for potentially different bandwidth + switch(UE->frame_parms.N_RB_DL) { + case 6: + openair0_cfg[UE->rf_map.card].sample_rate =1.92e6; + openair0_cfg[UE->rf_map.card].rx_bw =.96e6; + openair0_cfg[UE->rf_map.card].tx_bw =.96e6; + // openair0_cfg[0].rx_gain[0] -= 12; + break; + + case 25: + openair0_cfg[UE->rf_map.card].sample_rate =7.68e6; + openair0_cfg[UE->rf_map.card].rx_bw =2.5e6; + openair0_cfg[UE->rf_map.card].tx_bw =2.5e6; + // openair0_cfg[0].rx_gain[0] -= 6; + break; + + case 50: + openair0_cfg[UE->rf_map.card].sample_rate =15.36e6; + openair0_cfg[UE->rf_map.card].rx_bw =5.0e6; + openair0_cfg[UE->rf_map.card].tx_bw =5.0e6; + // openair0_cfg[0].rx_gain[0] -= 3; + break; + + case 100: + openair0_cfg[UE->rf_map.card].sample_rate=30.72e6; + openair0_cfg[UE->rf_map.card].rx_bw=10.0e6; + openair0_cfg[UE->rf_map.card].tx_bw=10.0e6; + // openair0_cfg[0].rx_gain[0] -= 0; + break; + } + + if (UE->mode != loop_through_memory) { + UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); + //UE->rfdevice.trx_set_gains_func(&openair0,&openair0_cfg[0]); + //UE->rfdevice.trx_stop_func(&UE->rfdevice); + // sleep(1); + //nr_init_frame_parms_ue(&UE->frame_parms); + /*if (UE->rfdevice.trx_start_func(&UE->rfdevice) != 0 ) { + LOG_E(HW,"Could not start the device\n"); + oai_exit=1; + }*/ + } + + if (UE->UE_scan_carrier == 1) { + UE->UE_scan_carrier = 0; + } else { + UE->is_synchronized = 1; + } + } else { + // initial sync failed + // calculate new offset and try again + if (UE->UE_scan_carrier == 1) { + if (freq_offset >= 0) + freq_offset += 100; + + freq_offset *= -1; + LOG_I(PHY, "[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n", + freq_offset, + UE->rx_total_gain_dB, + downlink_frequency[0][0]+freq_offset, + downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset ); + + for (i=0; irf_map.card].rx_num_channels; i++) { + openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+freq_offset; + openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]+freq_offset; + openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; + + if (UE->UE_scan_carrier==1) + openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; + } + + if (UE->mode != loop_through_memory) + UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); + }// initial_sync=0 + + break; + + case si: + default: + break; + } + } +} + +void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { + // Process Rx data for one sub-frame + if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_DOWNLINK_SLOT) { + //clean previous FAPI MESSAGE + UE->rx_ind.number_pdus = 0; + UE->dci_ind.number_of_dcis = 0; + //clean previous FAPI MESSAGE + // call L2 for DL_CONFIG (DCI) + UE->dcireq.module_id = UE->Mod_id; + UE->dcireq.gNB_index = 0; + UE->dcireq.cc_id = 0; + UE->dcireq.frame = proc->frame_rx; + UE->dcireq.slot = proc->nr_tti_rx; + nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later + NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); + UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req; + UE_mac->scheduled_response.slot = proc->nr_tti_rx; + nr_ue_scheduled_response(&UE_mac->scheduled_response); + //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); + printf("Processing slot %d\n",proc->nr_tti_rx); +#ifdef UE_SLOT_PARALLELISATION + phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); +#else + phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode); + // printf(">>> nr_ue_pdcch_procedures ended\n"); +#endif + } + + if (UE->mac_enabled==1) { + // trigger L2 to run ue_scheduler thru IF module + // [TODO] mapping right after NR initial sync + if(UE->if_inst != NULL && UE->if_inst->ul_indication != NULL) { + UE->ul_indication.module_id = 0; + UE->ul_indication.gNB_index = 0; + UE->ul_indication.cc_id = 0; + UE->ul_indication.frame = proc->frame_rx; + UE->ul_indication.slot = proc->nr_tti_rx; + UE->if_inst->ul_indication(&UE->ul_indication); + } + } +} + +/*! + * \brief This is the UE thread for RX subframe n and TX subframe n+4. + * This thread performs the phy_procedures_UE_RX() on every received slot. + * then, if TX is enabled it performs TX for n+4. + * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. + * \returns a pointer to an int. The storage is not on the heap and must not be freed. + */ + +typedef struct processingData_s { + UE_nr_rxtx_proc_t proc; + PHY_VARS_NR_UE *UE; +} processingData_t; + +void UE_processing(void *arg) { + processingData_t *rxtxD=(processingData_t *) arg; + UE_nr_rxtx_proc_t *proc = &rxtxD->proc; + PHY_VARS_NR_UE *UE = rxtxD->UE; + processSubframeRX(UE, proc); + //printf(">>> mac ended\n"); + // Prepare the future Tx data +#if 0 +#ifndef NO_RAT_NR + + if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_UPLINK_SLOT) +#else + if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_UL) || + (UE->frame_parms.frame_type == FDD) ) +#endif + if (UE->mode != loop_through_memory) + phy_procedures_nrUE_TX(UE,proc,0,0,UE->mode,no_relay); + + //phy_procedures_UE_TX(UE,proc,0,0,UE->mode,no_relay); +#endif +#if 0 + + if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_S) && + (UE->frame_parms.frame_type == TDD)) + if (UE->mode != loop_through_memory) + //phy_procedures_UE_S_TX(UE,0,0,no_relay); + updateTimes(current, &t3, 10000, timing_proc_name); + +#endif +} + +void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { + void *rxp[NB_ANTENNAS_RX]; + void *dummy_tx[UE->frame_parms.nb_antennas_tx]; + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); + + for(int x=0; x<10; x++) { + for (int i=0; iframe_parms.nb_antennas_rx; i++) + rxp[i] = ((void *)&UE->common_vars.rxdata[i][0]) + 4*x*UE->frame_parms.samples_per_subframe; + + AssertFatal( UE->frame_parms.samples_per_subframe == + UE->rfdevice.trx_read_func(&UE->rfdevice, + timestamp, + rxp, + UE->frame_parms.samples_per_subframe, + UE->frame_parms.nb_antennas_rx), ""); + } + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + free(dummy_tx[i]); +} + +void trashFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { + void *dummy_tx[UE->frame_parms.nb_antennas_tx]; + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); + + void *dummy_rx[UE->frame_parms.nb_antennas_rx]; + + for (int i=0; iframe_parms.nb_antennas_rx; i++) + dummy_rx[i]=malloc16(UE->frame_parms.samples_per_subframe*4); + + for (int sf=0; sfrfdevice.trx_read_func(&UE->rfdevice, + timestamp, + dummy_rx, + UE->frame_parms.samples_per_subframe, + UE->frame_parms.nb_antennas_rx); + } + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + free(dummy_tx[i]); + + for (int i=0; iframe_parms.nb_antennas_rx; i++) + free(dummy_rx[i]); +} + +void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { + if (UE->no_timing_correction==0) { + LOG_I(PHY,"Resynchronizing RX by %d samples (mode = %d)\n",UE->rx_offset,UE->mode); + void *dummy_tx[UE->frame_parms.nb_antennas_tx]; + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); + + for ( int size=UE->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 ; + AssertFatal(unitTransfer == + UE->rfdevice.trx_read_func(&UE->rfdevice, + timestamp, + (void **)UE->common_vars.rxdata, + unitTransfer, + UE->frame_parms.nb_antennas_rx),""); + } + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + free(dummy_tx[i]); + } +} + +int computeSamplesShift(PHY_VARS_NR_UE *UE) { + if ( getenv("RFSIMULATOR") != 0) { + LOG_E(PHY,"SET rx_offset %d \n",UE->rx_offset); + //UE->rx_offset_diff=0; + return 0; + } + + // compute TO compensation that should be applied for this frame + if ( UE->rx_offset < 5*UE->frame_parms.samples_per_slot && + UE->rx_offset > 0 ) + return -1 ; + + if ( UE->rx_offset > 5*UE->frame_parms.samples_per_slot && + UE->rx_offset < 10*UE->frame_parms.samples_per_slot ) + return 1; + + return 0; +} + +void *UE_thread(void *arg) { + PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; + // int tx_enabled = 0; + openair0_timestamp timestamp; + void *rxp[NB_ANTENNAS_RX], *txp[NB_ANTENNAS_TX]; + int start_rx_stream = 0; + const uint16_t table_sf_slot[20] = {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9}; + AssertFatal(0== openair0_device_load(&(UE->rfdevice), &openair0_cfg[0]), ""); + UE->rfdevice.host_type = RAU_HOST; + AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); + notifiedFIFO_t nf; + initNotifiedFIFO(&nf); + bool syncRunning=false; + notifiedFIFO_elt_t *syncMsg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); + syncData_t *syncD=(syncData_t *)NotifiedFifoData(syncMsg); + syncD->UE=UE; + int nbSlotProcessing=0; + int thread_idx=0; + notifiedFIFO_elt_t *processingMsg[RX_NB_TH]; + + for (int i=0; iUE=UE; + } + + const int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; + int absolute_slot=-1; + + while (!oai_exit) { + if (!syncD->UE->is_synchronized) { + if (syncRunning) { + notifiedFIFO_elt_t *res=tryPullTpool(&nf, Tpool); + + if (res) { + syncRunning=false; + } else + trashFrame(UE, ×tamp); + } else { + readFrame(UE, ×tamp); + pushTpool(Tpool, syncMsg); + syncRunning=true; + } + + continue; + } + + if (start_rx_stream==0) { + start_rx_stream=1; + syncInFrame(UE, ×tamp); + UE->rx_offset=0; + UE->time_sync_cell=0; + //printf("first stream frame rx %d\n",UE->proc.proc_rxtx[0].frame_rx); + // read in first symbol + AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == + UE->rfdevice.trx_read_func(&UE->rfdevice, + ×tamp, + (void **)UE->common_vars.rxdata, + UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, + UE->frame_parms.nb_antennas_rx),""); + continue; + } + + absolute_slot++; + thread_idx = absolute_slot % RX_NB_TH; + int slot_nr=absolute_slot % nb_slot_frame; + UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[thread_idx]))->proc); + // update thread index for received subframe + proc->nr_tti_rx= slot_nr; + UE->current_thread_id[slot_nr] = thread_idx; + proc->subframe_rx=table_sf_slot[slot_nr]; + proc->nr_tti_tx = (absolute_slot + DURATION_RX_TO_TX) % nb_slot_frame; + proc->subframe_tx=proc->nr_tti_rx; + proc->frame_rx = ( absolute_slot/nb_slot_frame ) % MAX_FRAME_NUMBER; + proc->frame_tx = ( (absolute_slot + DURATION_RX_TO_TX) /nb_slot_frame ) % MAX_FRAME_NUMBER; + LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, thread_idx); + + for (int i=0; iframe_parms.nb_antennas_rx; i++) + rxp[i] = (void *)&UE->common_vars.rxdata[i][UE->frame_parms.ofdm_symbol_size+ + UE->frame_parms.nb_prefix_samples0+ + slot_nr*UE->frame_parms.samples_per_slot]; + + for (int i=0; iframe_parms.nb_antennas_tx; i++) + txp[i] = (void *)&UE->common_vars.txdata[i][proc->nr_tti_tx*UE->frame_parms.samples_per_slot]; + + int readBlockSize, writeBlockSize; + + if (slot_nr<(nb_slot_frame - 1)) { + readBlockSize=UE->frame_parms.samples_per_slot; + writeBlockSize=UE->frame_parms.samples_per_slot; + } else { + UE->rx_offset_diff = computeSamplesShift(UE); + readBlockSize=UE->frame_parms.samples_per_slot - + UE->frame_parms.ofdm_symbol_size - + UE->frame_parms.nb_prefix_samples0 - + UE->rx_offset_diff; + writeBlockSize=UE->frame_parms.samples_per_slot - + UE->rx_offset_diff; + } + + AssertFatal(readBlockSize == + UE->rfdevice.trx_read_func(&UE->rfdevice, + ×tamp, + rxp, + readBlockSize, + UE->frame_parms.nb_antennas_rx),""); + AssertFatal( writeBlockSize == + UE->rfdevice.trx_write_func(&UE->rfdevice, + timestamp+ + (2*UE->frame_parms.samples_per_slot) - + UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0 - + openair0_cfg[0].tx_sample_advance, + txp, + writeBlockSize, + UE->frame_parms.nb_antennas_tx, + 1),""); + + if( slot_nr==(nb_slot_frame-1)) { + // read in first symbol of next frame and adjust for timing drift + int first_symbols=writeBlockSize-readBlockSize; + + if ( first_symbols > 0 ) + AssertFatal(first_symbols == + UE->rfdevice.trx_read_func(&UE->rfdevice, + ×tamp, + (void **)UE->common_vars.rxdata, + first_symbols, + UE->frame_parms.nb_antennas_rx),""); + else + LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols); + } + + proc->timestamp_tx = timestamp+ + (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- + UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; + + if (getenv("RFSIMULATOR")) { + // FixMe: Wait previous thread is done, because race conditions seems too bad + // in case of actual RF board, the overlap between threads mitigate the issue + while (!tryPullTpool(&nf, Tpool)) { + nbSlotProcessing--; + usleep(200); + } + } + + while (nbSlotProcessing >= RX_NB_TH && !tryPullTpool(&nf, Tpool)) { + nbSlotProcessing--; + usleep(200); + } + + pushTpool(Tpool, processingMsg[thread_idx]); + } // while !oai_exit + + return NULL; +} + +void init_UE(int nb_inst) { + int inst; + NR_UE_MAC_INST_t *mac_inst; + pthread_t threads[nb_inst]; + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_setschedpolicy(&attr, SCHED_RR); + struct sched_param sched; + sched.sched_priority = sched_get_priority_max(SCHED_RR)-1; + pthread_attr_setschedparam(&attr, &sched); + + for (inst=0; inst < nb_inst; inst++) { + // UE->rfdevice.type = NONE_DEV; + //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; + LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); + PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); + PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; + AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); + nr_l3_init_ue(); + nr_l2_init_ue(); + mac_inst = get_mac_inst(0); + mac_inst->if_module = UE->if_inst; + UE->if_inst->scheduled_response = nr_ue_scheduled_response; + UE->if_inst->phy_config_request = nr_ue_phy_config_request; + LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); + //init_UE_threads(inst); + //UE = PHY_vars_UE_g[inst][0]; + AssertFatal(0 == pthread_create(&threads[inst], + &attr, + UE_thread, + (void *)UE), ""); + } + + printf("UE threads created by %ld\n", gettid()); +} + diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c new file mode 100644 index 0000000000..5384e0835d --- /dev/null +++ b/executables/nr-uesoftmodem.c @@ -0,0 +1,826 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + + +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include + +#include "T.h" +#include "assertions.h" +#include "PHY/types.h" +#include "PHY/defs_nr_UE.h" +#include "common/ran_context.h" +#include "common/config/config_userapi.h" +#include "common/utils/load_module_shlib.h" +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "../../ARCH/COMMON/common_lib.h" +#include "../../ARCH/ETHERNET/USERSPACE/LIB/if_defs.h" + +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "PHY/phy_vars_nr_ue.h" +#include "PHY/LTE_TRANSPORT/transport_vars.h" +#include "SCHED/sched_common_vars.h" +#include "PHY/MODULATION/modulation_vars.h" +//#include "../../SIMU/USER/init_lte.h" + +#include "LAYER2/MAC/mac_vars.h" +#include "LAYER2/MAC/mac_proto.h" +#include "RRC/LTE/rrc_vars.h" +#include "PHY_INTERFACE/phy_interface_vars.h" + +#ifdef SMBV +#include "PHY/TOOLS/smbv.h" +unsigned short config_frames[4] = {2,9,11,13}; +#endif +#include "common/utils/LOG/log.h" +#include "common/utils/LOG/vcd_signal_dumper.h" + +#include "UTIL/OPT/opt.h" +#include "enb_config.h" +//#include "PHY/TOOLS/time_meas.h" + +#ifndef OPENAIR2 + #include "UTIL/OTG/otg_vars.h" +#endif + +#include "intertask_interface.h" +#include "create_tasks.h" + +#include "PHY/INIT/phy_init.h" +#include "system.h" +#include +#include +#include +#include +#include + +#ifdef XFORMS +#include + +/* Callbacks, globals and object handlers */ + +extern void reset_stats( FL_OBJECT *, long ); + +/* Forms and Objects */ + +typedef struct { + FL_FORM *stats_form; + void *vdata; + char *cdata; + long ldata; + FL_OBJECT *stats_text; + FL_OBJECT *stats_button; +} FD_stats_form; + +extern FD_stats_form *create_form_stats_form( void ); + +#include "PHY/TOOLS/nr_phy_scope.h" +//#include "stats.h" +// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0) +// at eNB 0, an UL scope for every UE +FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; +//FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX]; +//FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; +char title[255]; +//unsigned char scope_enb_num_ue = 2; +static pthread_t forms_thread; //xforms +#endif //XFORMS +#include + +RAN_CONTEXT_t RC; +volatile int start_eNB = 0; +volatile int start_UE = 0; +volatile int oai_exit = 0; + +static clock_source_t clock_source = internal; +int single_thread_flag=1; + +int threequarter_fs=0; + +uint32_t downlink_frequency[MAX_NUM_CCs][4]; +int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; + +extern int16_t nr_dlsch_demod_shift; + +int UE_scan = 0; +int UE_scan_carrier = 0; +int UE_fo_compensation = 0; +runmode_t mode = normal_txrx; +openair0_config_t openair0_cfg[MAX_CARDS]; + +#if MAX_NUM_CCs == 1 +rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain}}; +double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0}}; +double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0}}; +#else +rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain},{max_gain,max_gain,max_gain,max_gain}}; +double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0},{20,0,0,0}}; +double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0},{20,0,0,0}}; +#endif + +double rx_gain_off = 0.0; + +double sample_rate=30.72e6; +double bw = 10.0e6; + +static int tx_max_power[MAX_NUM_CCs] = {0}; + +char rf_config_file[1024]; + +int chain_offset=0; +int phy_test = 0; +uint8_t usim_test = 0; + +uint8_t dci_Format = 0; +uint8_t agregation_Level =0xFF; + +uint8_t nb_antenna_tx = 1; +uint8_t nb_antenna_rx = 1; + +char ref[128] = "internal"; +char channels[128] = "0"; + +char *parallel_config = NULL; +char *worker_config = NULL; + +static THREAD_STRUCT thread_struct; +void set_parallel_conf(char *parallel_conf) { + if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; + + printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); +} +void set_worker_conf(char *worker_conf) { + if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; + else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; + + printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); +} +PARALLEL_CONF_t get_thread_parallel_conf(void) { + return thread_struct.parallel_conf; +} +WORKER_CONF_t get_thread_worker_conf(void) { + return thread_struct.worker_conf; +} +int rx_input_level_dBm; + +//static int online_log_messages=0; + +#ifdef XFORMS + extern int otg_enabled; + int do_forms=0; +#else + int otg_enabled; +#endif +//int number_of_cards = 1; + +static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; +static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; +int16_t node_synch_ref[MAX_NUM_CCs]; + +uint32_t target_dl_mcs = 28; //maximum allowed mcs +uint32_t target_ul_mcs = 20; +uint32_t timing_advance = 0; +uint8_t exit_missed_slots=1; +uint64_t num_missed_slots=0; // counter for the number of missed slots + + +int transmission_mode=1; +int numerology = 0; + +/* flag set by eNB conf file to specify if the radio head is local or remote (default option is local) */ +//uint8_t local_remote_radio = BBU_LOCAL_RADIO_HEAD; +/* struct for ethernet specific parameters given in eNB conf file */ +//eth_params_t *eth_params; + +double cpuf; + +char uecap_xer[1024],uecap_xer_in=0; + +int oaisim_flag=0; +int emulate_rf = 0; + +tpool_t *Tpool; + +char *usrp_args=NULL; +char *usrp_clksrc=NULL; + +/* forward declarations */ +void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); + + +/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed + * this is very hackish - find a proper solution + */ +uint8_t abstraction_flag=0; + +/*---------------------BMC: timespec helpers -----------------------------*/ + +struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; +struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; + +struct timespec clock_difftime(struct timespec start, struct timespec end) { + struct timespec temp; + + if ((end.tv_nsec-start.tv_nsec)<0) { + temp.tv_sec = end.tv_sec-start.tv_sec-1; + temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; + } else { + temp.tv_sec = end.tv_sec-start.tv_sec; + temp.tv_nsec = end.tv_nsec-start.tv_nsec; + } + + return temp; +} + +void print_difftimes(void) { + LOG_I(HW,"difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); +} + +void exit_function(const char *file, const char *function, const int line, const char *s) { + int CC_id; + + if (s != NULL) { + printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s); + } + + oai_exit = 1; + + if (PHY_vars_UE_g && PHY_vars_UE_g[0]) { + for(CC_id=0; CC_idrfdevice.trx_end_func) + PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][CC_id]->rfdevice); + } + } + + sleep(1); //allow lte-softmodem threads to exit first + itti_terminate_tasks (TASK_UNKNOWN); +} + +#ifdef XFORMS + + +void reset_stats(FL_OBJECT *button, long arg) { + //int i,j,k; + /*PHY_VARS_eNB *phy_vars_eNB = PHY_vars_eNB_g[0][0]; + + for (i=0; idlsch[i][0]->Mlimit; j++) { + phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0; + phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0; + phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0; + } + + phy_vars_eNB->UE_stats[i].dlsch_l2_errors[k]=0; + phy_vars_eNB->UE_stats[i].ulsch_errors[k]=0; + phy_vars_eNB->UE_stats[i].ulsch_consecutive_errors=0; + + for (j=0; julsch[i]->Mlimit; j++) { + phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts[k][j]=0; + phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts_last[k][j]=0; + phy_vars_eNB->UE_stats[i].ulsch_round_errors[k][j]=0; + phy_vars_eNB->UE_stats[i].ulsch_round_fer[k][j]=0; + } + } + + phy_vars_eNB->UE_stats[i].dlsch_sliding_cnt=0; + phy_vars_eNB->UE_stats[i].dlsch_NAK_round0=0; + phy_vars_eNB->UE_stats[i].dlsch_mcs_offset=0; + }*/ +} + +static void *scope_thread(void *arg) { + struct sched_param sched_param; + sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1; + sched_setscheduler(0, SCHED_FIFO,&sched_param); + printf("Scope thread has priority %d\n",sched_param.sched_priority); + //wait the modem is runnign + sleep(5); + + while (!oai_exit) { + phy_scope_UE(form_ue[0], + PHY_vars_UE_g[0][0], + 0,0,1); + usleep(100*1000); + } + + pthread_exit((void *)arg); +} +#endif + +void init_scope(void) { +#ifdef XFORMS + int ret; + int fl_argc=1; + + if (do_forms==1) { + char *name="5G-UE-scope"; + fl_initialize (&fl_argc, &name, NULL, 0, 0); + int UE_id = 0; + form_ue[UE_id] = create_lte_phy_scope_ue(); + sprintf (title, "NR DL SCOPE UE"); + fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); + fl_set_button(form_ue[UE_id]->button_0,0); + fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); + ret = pthread_create(&forms_thread, NULL, scope_thread, NULL); + + if (ret == 0) + pthread_setname_np( forms_thread, "xforms" ); + + printf("Scope thread created, ret=%d\n",ret); + } + +#endif +} + + +#if defined(ENABLE_ITTI) +void *l2l1_task(void *arg) { + MessageDef *message_p = NULL; + int result; + itti_set_task_real_time(TASK_L2L1); + itti_mark_task_ready(TASK_L2L1); + + do { + // Wait for a message + itti_receive_msg (TASK_L2L1, &message_p); + + switch (ITTI_MSG_ID(message_p)) { + case TERMINATE_MESSAGE: + oai_exit=1; + itti_exit_task (); + break; + + case ACTIVATE_MESSAGE: + start_UE = 1; + break; + + case DEACTIVATE_MESSAGE: + start_UE = 0; + break; + + case MESSAGE_TEST: + LOG_I(EMU, "Received %s\n", ITTI_MSG_NAME(message_p)); + break; + + default: + LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p)); + break; + } + + result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p); + AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); + } while(!oai_exit); + + return NULL; +} +#endif + +int16_t dlsch_demod_shift; + +static void get_options(void) { + int CC_id; + int tddflag=0, nonbiotflag; + char *loopfile=NULL; + int dumpframe=0; + uint32_t online_log_messages; + uint32_t glog_level, glog_verbosity; + uint32_t start_telnetsrv=0; + paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; + paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; + config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); + + if (strlen(in_path) > 0) { + opt_type = OPT_PCAP; + opt_enabled=1; + printf("Enabling OPT for PCAP with the following file %s \n",in_path); + } + + if (strlen(in_ip) > 0) { + opt_enabled=1; + opt_type = OPT_WIRESHARK; + printf("Enabling OPT for wireshark for local interface"); + } + + config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); + + if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { + set_glog_onlinelog(online_log_messages); + } + + if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { + set_glog(glog_level); + } + + if (start_telnetsrv) { + load_module_shlib("telnetsrv",NULL,0,NULL); + } + + paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC; + paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; + config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL); + config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL); + + if ( (cmdline_uemodeparams[CMDLINE_CALIBUERX_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue; + + if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXMED_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_med; + + if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXBYP_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_byp; + + if (cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) + if ( *(cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) > 0) mode = debug_prach; + + if (cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) + if ( *(cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) > 0) mode = no_L2_connect; + + if (cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) + if ( *(cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) > 0) mode = calib_prach_tx; + + if (dumpframe > 0) mode = rx_dump_frame; + + for (CC_id=0; CC_iddl_CarrierFreq = downlink_frequency[0][0]; + } + + UE_scan=0; + + if (tddflag > 0) { + for (CC_id=0; CC_idframe_type = TDD; + } + + /*if (frame_parms[0]->N_RB_DL !=0) { + if ( frame_parms[0]->N_RB_DL < 6 ) { + frame_parms[0]->N_RB_DL = 6; + printf ( "%i: Invalid number of ressource blocks, adjusted to 6\n",frame_parms[0]->N_RB_DL); + } + if ( frame_parms[0]->N_RB_DL > 100 ) { + frame_parms[0]->N_RB_DL = 100; + printf ( "%i: Invalid number of ressource blocks, adjusted to 100\n",frame_parms[0]->N_RB_DL); + } + if ( frame_parms[0]->N_RB_DL > 50 && frame_parms[0]->N_RB_DL < 100 ) { + frame_parms[0]->N_RB_DL = 50; + printf ( "%i: Invalid number of ressource blocks, adjusted to 50\n",frame_parms[0]->N_RB_DL); + } + if ( frame_parms[0]->N_RB_DL > 25 && frame_parms[0]->N_RB_DL < 50 ) { + frame_parms[0]->N_RB_DL = 25; + printf ( "%i: Invalid number of ressource blocks, adjusted to 25\n",frame_parms[0]->N_RB_DL); + } + UE_scan = 0; + frame_parms[0]->N_RB_UL=frame_parms[0]->N_RB_DL; + for (CC_id=1; CC_idN_RB_DL=frame_parms[0]->N_RB_DL; + frame_parms[CC_id]->N_RB_UL=frame_parms[0]->N_RB_UL; + } + }*/ + + for (CC_id=1; CC_idsubframe_config.numerology_index_mu.value =1; + config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD + config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL + config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; + config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; + config[CC_id]->sch_config.physical_cell_id.value = 0; + frame_parms[CC_id]->frame_type = FDD; + frame_parms[CC_id]->tdd_config = 3; + //frame_parms[CC_id]->tdd_config_S = 0; + frame_parms[CC_id]->N_RB_DL = 106; + frame_parms[CC_id]->N_RB_UL = 106; + frame_parms[CC_id]->Ncp = NORMAL; + //frame_parms[CC_id]->Ncp_UL = NORMAL; + frame_parms[CC_id]->Nid_cell = 0; + //frame_parms[CC_id]->num_MBSFN_config = 0; + frame_parms[CC_id]->nb_antenna_ports_eNB = 1; + frame_parms[CC_id]->nb_antennas_tx = 1; + frame_parms[CC_id]->nb_antennas_rx = 1; + //frame_parms[CC_id]->nushift = 0; + ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; + //frame_parms[CC_id]->phich_config_common.phich_duration = normal; + // UL RS Config + /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0 + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; + + frame_parms[CC_id]->pusch_config_common.n_SB = 1; + frame_parms[CC_id]->pusch_config_common.hoppingMode = 0; + frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0; + frame_parms[CC_id]->pusch_config_common.enable64QAM = 0; + + frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/ + // NR: Init to legacy LTE 20Mhz params + frame_parms[CC_id]->numerology_index = 0; + frame_parms[CC_id]->ttis_per_subframe = 1; + frame_parms[CC_id]->slots_per_tti = 2; + } +} + +void init_openair0(void) { + int card; + int i; + + for (card=0; cardN_RB_DL == 106) { + if (numerology==0) { + if (frame_parms[0]->threequarter_fs) { + openair0_cfg[card].sample_rate=23.04e6; + openair0_cfg[card].samples_per_frame = 230400; + openair0_cfg[card].tx_bw = 10e6; + openair0_cfg[card].rx_bw = 10e6; + } else { + openair0_cfg[card].sample_rate=30.72e6; + openair0_cfg[card].samples_per_frame = 307200; + openair0_cfg[card].tx_bw = 10e6; + openair0_cfg[card].rx_bw = 10e6; + } + } else if (numerology==1) { + openair0_cfg[card].sample_rate=61.44e6; + openair0_cfg[card].samples_per_frame = 307200; + openair0_cfg[card].tx_bw = 20e6; + openair0_cfg[card].rx_bw = 20e6; + } else if (numerology==2) { + openair0_cfg[card].sample_rate=122.88e6; + openair0_cfg[card].samples_per_frame = 307200; + openair0_cfg[card].tx_bw = 40e6; + openair0_cfg[card].rx_bw = 40e6; + } else { + LOG_E(PHY,"Unsupported numerology!\n"); + exit(-1); + } + } else if(frame_parms[0]->N_RB_DL == 50) { + openair0_cfg[card].sample_rate=15.36e6; + openair0_cfg[card].samples_per_frame = 153600; + openair0_cfg[card].tx_bw = 5e6; + openair0_cfg[card].rx_bw = 5e6; + } else if (frame_parms[0]->N_RB_DL == 25) { + openair0_cfg[card].sample_rate=7.68e6; + openair0_cfg[card].samples_per_frame = 76800; + openair0_cfg[card].tx_bw = 2.5e6; + openair0_cfg[card].rx_bw = 2.5e6; + } else if (frame_parms[0]->N_RB_DL == 6) { + openair0_cfg[card].sample_rate=1.92e6; + openair0_cfg[card].samples_per_frame = 19200; + openair0_cfg[card].tx_bw = 1.5e6; + openair0_cfg[card].rx_bw = 1.5e6; + } + + if (frame_parms[0]->frame_type==TDD) + openair0_cfg[card].duplex_mode = duplex_mode_TDD; + else //FDD + openair0_cfg[card].duplex_mode = duplex_mode_FDD; + + printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card, + PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx, + PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); + openair0_cfg[card].Mod_id = 0; + openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL; + openair0_cfg[card].clock_source = clock_source; + openair0_cfg[card].tx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx); + openair0_cfg[card].rx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); + + for (i=0; i<4; i++) { + if (irx_total_gain_dB - rx_gain_off; + openair0_cfg[card].configFilename = rf_config_file; + printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n", + card,i, openair0_cfg[card].tx_gain[i], + openair0_cfg[card].rx_gain[i], + openair0_cfg[card].tx_freq[i], + openair0_cfg[card].rx_freq[i]); + } + + if (usrp_args) openair0_cfg[card].sdr_addrs = usrp_args; + + if (usrp_clksrc) { + if (strcmp(usrp_clksrc, "internal") == 0) { + openair0_cfg[card].clock_source = internal; + LOG_D(PHY, "USRP clock source set as internal\n"); + } else if (strcmp(usrp_clksrc, "external") == 0) { + openair0_cfg[card].clock_source = external; + LOG_D(PHY, "USRP clock source set as external\n"); + } else if (strcmp(usrp_clksrc, "gpsdo") == 0) { + openair0_cfg[card].clock_source = gpsdo; + LOG_D(PHY, "USRP clock source set as gpsdo\n"); + } else { + openair0_cfg[card].clock_source = internal; + LOG_I(PHY, "USRP clock source unknown ('%s'). defaulting to internal\n", usrp_clksrc); + } + } else { + openair0_cfg[card].clock_source = internal; + LOG_I(PHY, "USRP clock source not specified. defaulting to internal\n"); + } + } +} + + +int main( int argc, char **argv ) { + //uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2; + PHY_VARS_NR_UE *UE[MAX_NUM_CCs]; + start_background_system(); + + if ( load_configmodule(argc,argv) == NULL) { + exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); + } + + CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); + set_default_frame_parms(frame_parms); + mode = normal_txrx; + memset(openair0_cfg,0,sizeof(openair0_config_t)*MAX_CARDS); + memset(tx_max_power,0,sizeof(int)*MAX_NUM_CCs); + // initialize logging + logInit(); + // get options and fill parameters from configuration file + get_options (); //Command-line options, enb_properties +#if T_TRACER + T_Config_Init(); +#endif + //randominit (0); + set_taus_seed (0); + tpool_t pool; + Tpool = &pool; + char params[]="1,2,3,u"; + initTpool(params, Tpool, false); + cpuf=get_cpu_freq_GHz(); + itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); + + if (opt_type != OPT_NONE) { + if (init_opt(in_path, in_ip) == -1) + LOG_E(OPT,"failed to run OPT \n"); + } + +#ifdef PDCP_USE_NETLINK + netlink_init(); +#if defined(PDCP_USE_NETLINK_QUEUES) + pdcp_netlink_init(); +#endif +#endif +#ifndef PACKAGE_VERSION +# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL" +#endif + LOG_I(HW, "Version: %s\n", PACKAGE_VERSION); + + // init the parameters + for (int CC_id=0; CC_idnb_antennas_tx = nb_antenna_tx; + frame_parms[CC_id]->nb_antennas_rx = nb_antenna_rx; + frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later + LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); + } + + NB_UE_INST=1; + NB_INST=1; + PHY_vars_UE_g = malloc(sizeof(PHY_VARS_NR_UE **)); + PHY_vars_UE_g[0] = malloc(sizeof(PHY_VARS_NR_UE *)*MAX_NUM_CCs); + + for (int CC_id=0; CC_idofdm_symbol_size); + nr_init_frame_parms_ue(frame_parms[CC_id],numerology,NORMAL,frame_parms[CC_id]->N_RB_DL,(frame_parms[CC_id]->N_RB_DL-20)>>1,0); + PHY_vars_UE_g[0][CC_id] = init_nr_ue_vars(frame_parms[CC_id], 0,abstraction_flag); + UE[CC_id] = PHY_vars_UE_g[0][CC_id]; + + if (phy_test==1) + UE[CC_id]->mac_enabled = 0; + else + UE[CC_id]->mac_enabled = 1; + + if (UE[CC_id]->mac_enabled == 0) { //set default UL parameters for testing mode + for (int i=0; ipusch_config_dedicated[i] = malloc(sizeof(PUSCH_CONFIG_DEDICATED)); + //UE[CC_id]->scheduling_request_config[i] = malloc(sizeof(SCHEDULING_REQUEST_CONFIG)); + /*UE[CC_id]->pusch_config_dedicated[i].betaOffset_ACK_Index = beta_ACK; + UE[CC_id]->pusch_config_dedicated[i].betaOffset_RI_Index = beta_RI; + UE[CC_id]->pusch_config_dedicated[i].betaOffset_CQI_Index = beta_CQI; + + UE[CC_id]->scheduling_request_config[i].sr_PUCCH_ResourceIndex = 0; + UE[CC_id]->scheduling_request_config[i].sr_ConfigIndex = 7+(0%3); + UE[CC_id]->scheduling_request_config[i].dsr_TransMax = sr_n4;*/ + } + } + + UE[CC_id]->UE_scan = UE_scan; + UE[CC_id]->UE_scan_carrier = UE_scan_carrier; + UE[CC_id]->UE_fo_compensation = UE_fo_compensation; + UE[CC_id]->mode = mode; + printf("UE[%d]->mode = %d\n",CC_id,mode); + + for (uint8_t i=0; imac_enabled == 1) + UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1234; + else + UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1235; + } + + UE[CC_id]->rx_total_gain_dB = (int)rx_gain[CC_id][0] + rx_gain_off; + UE[CC_id]->tx_power_max_dBm = tx_max_power[CC_id]; + + if (frame_parms[CC_id]->frame_type==FDD) { + UE[CC_id]->N_TA_offset = 0; + } else { + if (frame_parms[CC_id]->N_RB_DL == 100) + UE[CC_id]->N_TA_offset = 624; + else if (frame_parms[CC_id]->N_RB_DL == 50) + UE[CC_id]->N_TA_offset = 624/2; + else if (frame_parms[CC_id]->N_RB_DL == 25) + UE[CC_id]->N_TA_offset = 624/4; + } + } + + // printf("tx_max_power = %d -> amp %d\n",tx_max_power[0],get_tx_amp(tx_max_poHwer,tx_max_power)); + init_openair0(); + // init UE_PF_PO and mutex lock + pthread_mutex_init(&ue_pf_po_mutex, NULL); + memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); + mlockall(MCL_CURRENT | MCL_FUTURE); + init_scope(); + number_of_cards = 1; + + for(int CC_id=0; CC_idrf_map.card=0; + PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset; +#if defined(OAI_USRP) || defined(OAI_ADRV9371_ZC706) + PHY_vars_UE_g[0][CC_id]->hw_timing_advance = timing_advance; +#else + PHY_vars_UE_g[0][CC_id]->hw_timing_advance = 160; +#endif + } + + // wait for end of program + printf("TYPE TO TERMINATE\n"); + init_UE(1); + + while(true) + sleep(3600); + + return 0; +} diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h new file mode 100644 index 0000000000..df6b2f7282 --- /dev/null +++ b/executables/nr-uesoftmodem.h @@ -0,0 +1,246 @@ +#ifndef NR_UESOFTMODEM_H +#define NR_UESOFTMODEM_H + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../../ARCH/COMMON/common_lib.h" +#undef MALLOC +#include "assertions.h" +#include "PHY/types.h" +#include "PHY/defs_nr_UE.h" +#include "SIMULATION/ETH_TRANSPORT/proto.h" +#include + + +#if defined(ENABLE_ITTI) + #if defined(ENABLE_USE_MME) + #include "s1ap_eNB.h" + #ifdef PDCP_USE_NETLINK + #include "SIMULATION/ETH_TRANSPORT/proto.h" + #endif + #endif +#endif + +/* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ +#define CONFIG_HLP_RFCFGF "Configuration file for front-end (e.g. LMS7002M)\n" +#define CONFIG_HLP_ULMAXE "set the eNodeB max ULSCH erros\n" +#define CONFIG_HLP_CALUER "set UE RX calibration\n" +#define CONFIG_HLP_CALUERM "" +#define CONFIG_HLP_CALUERB "" +#define CONFIG_HLP_DBGUEPR "UE run normal prach power ramping, but don't continue random-access\n" +#define CONFIG_HLP_CALPRACH "UE run normal prach with maximum power, but don't continue random-access\n" +#define CONFIG_HLP_NOL2CN "bypass L2 and upper layers\n" +#define CONFIG_HLP_UERXG "set UE RX gain\n" +#define CONFIG_HLP_UERXGOFF "external UE amplifier offset\n" +#define CONFIG_HLP_UETXG "set UE TX gain\n" +#define CONFIG_HLP_UENANTR "set UE number of rx antennas\n" +#define CONFIG_HLP_UENANTT "set UE number of tx antennas\n" +#define CONFIG_HLP_UESCAN "set UE to scan around carrier\n" +#define CONFIG_HLP_UEFO "set UE to enable estimation and compensation of frequency offset\n" +#define CONFIG_HLP_DUMPFRAME "dump UE received frame to rxsig_frame0.dat and exit\n" +#define CONFIG_HLP_DLSHIFT "dynamic shift for LLR compuation for TM3/4 (default 0)\n" +#define CONFIG_HLP_UELOOP "get softmodem (UE) to loop through memory instead of acquiring from HW\n" +#define CONFIG_HLP_PHYTST "test UE phy layer, mac disabled\n" +#define CONFIG_HLP_DMAMAP "sets flag for improved EXMIMO UE performance\n" +#define CONFIG_HLP_EXCCLK "tells hardware to use an external clock reference\n" +#define CONFIG_HLP_USIM "use XOR autentication algo in case of test usim mode\n" +#define CONFIG_HLP_NOSNGLT "Disables single-thread mode in lte-softmodem\n" +#define CONFIG_HLP_TADV "Set timing_advance\n" +#define CONFIG_HLP_DLF "Set the downlink frequency for all component carriers\n" +#define CONFIG_HLP_CHOFF "Channel id offset\n" +#define CONFIG_HLP_SOFTS "Enable soft scope and L1 and L2 stats (Xforms)\n" +#define CONFIG_HLP_EXMCAL "Calibrate the EXMIMO borad, available files: exmimo2_2arxg.lime exmimo2_2brxg.lime \n" +#define CONFIG_HLP_ITTIL "Generate ITTI analyzser logs (similar to wireshark logs but with more details)\n" +#define CONFIG_HLP_DLMCS "Set the maximum downlink MCS\n" +#define CONFIG_HLP_STMON "Enable processing timing measurement of lte softmodem on per subframe basis \n" +#define CONFIG_HLP_PRB "Set the PRB, valid values: 6, 25, 50, 100 \n" +#define CONFIG_HLP_MSLOTS "Skip the missed slots/subframes \n" +#define CONFIG_HLP_ULMCS "Set the maximum uplink MCS\n" +#define CONFIG_HLP_TDD "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n" +#define CONFIG_HLP_UE "Set the lte softmodem as a UE\n" +#define CONFIG_HLP_L2MONW "Enable L2 wireshark messages on localhost \n" +#define CONFIG_HLP_L2MONP "Enable L2 pcap messages on localhost \n" +#define CONFIG_HLP_VCD "Enable VCD (generated file will is named openair_dump_eNB.vcd, read it with target/RT/USER/eNB.gtkw\n" +#define CONFIG_HLP_TQFS "Apply three-quarter of sampling frequency, 23.04 Msps to reduce the data rate on USB/PCIe transfers (only valid for 20 MHz)\n" +#define CONFIG_HLP_TPORT "tracer port\n" +#define CONFIG_HLP_NOTWAIT "don't wait for tracer, start immediately\n" +#define CONFIG_HLP_TNOFORK "to ease debugging with gdb\n" + +#define CONFIG_HLP_NUMEROLOGY "adding numerology for 5G\n" +#define CONFIG_HLP_EMULATE_RF "Emulated RF enabled(disable by defult)\n" +#define CONFIG_HLP_PARALLEL_CMD "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n" +#define CONFIG_HLP_WORKER_CMD "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n" + +#define CONFIG_HLP_DISABLNBIOT "disable nb-iot, even if defined in config\n" + +#define CONFIG_HLP_USRP_ARGS "set the arguments to identify USRP (same syntax as in UHD)\n" +#define CONFIG_HLP_USRP_CLK_SRC "USRP clock source: 'internal' or 'external'\n" + +/***************************************************************************************************************************************/ +/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument + when calling config_get or config_getlist functions */ + + +/*------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters defining UE running mode */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_UEMODEPARAMS_DESC { \ + {"calib-ue-rx", CONFIG_HLP_CALUER, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"calib-ue-rx-med", CONFIG_HLP_CALUERM, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"calib-ue-rx-byp", CONFIG_HLP_CALUERB, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"debug-ue-prach", CONFIG_HLP_DBGUEPR, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"no-L2-connect", CONFIG_HLP_NOL2CN, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"calib-prach-tx", CONFIG_HLP_CALPRACH, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"loop-memory", CONFIG_HLP_UELOOP, 0, strptr:&loopfile, defstrval:"iqs.in", TYPE_STRING,0}, \ + {"ue-dump-frame", CONFIG_HLP_DUMPFRAME, PARAMFLAG_BOOL, iptr:&dumpframe, defintval:0, TYPE_INT, 0}, \ + } +#define CMDLINE_CALIBUERX_IDX 0 +#define CMDLINE_CALIBUERXMED_IDX 1 +#define CMDLINE_CALIBUERXBYP_IDX 2 +#define CMDLINE_DEBUGUEPRACH_IDX 3 +#define CMDLINE_NOL2CONNECT_IDX 4 +#define CMDLINE_CALIBPRACHTX_IDX 5 +#define CMDLINE_MEMLOOP_IDX 6 +#define CMDLINE_DUMPMEMORY_IDX 7 +/*------------------------------------------------------------------------------------------------------------------------------------------*/ + + +/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters specific to UE */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_UEPARAMS_DESC { \ + {"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ + {"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ + {"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ + {"ue-fo-compensation", CONFIG_HLP_UEFO, PARAMFLAG_BOOL, iptr:&UE_fo_compensation, defintval:0, TYPE_INT, 0}, \ + {"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:90, TYPE_INT, 0}, \ + {"r" , CONFIG_HLP_PRB, 0, iptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT, 0}, \ + {"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ + {"usrp-args", CONFIG_HLP_USRP_ARGS, 0, strptr:(char **)&usrp_args, defstrval:"type=b200", TYPE_STRING, 0}, \ + {"usrp-clksrc", CONFIG_HLP_USRP_CLK_SRC,0, strptr:(char **)&usrp_clksrc, defstrval:"internal", TYPE_STRING, 0} \ + } + +#define DEFAULT_DLF 2680000000 + +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters common to eNodeB and UE */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_PARAMS_DESC { \ + {"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&rf_config_file, defstrval:NULL, TYPE_STRING, sizeof(rf_config_file)}, \ + {"ulsch-max-errors", CONFIG_HLP_ULMAXE, 0, uptr:&ULSCH_max_consecutive_errors, defuintval:0, TYPE_UINT, 0}, \ + {"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&phy_test, defintval:0, TYPE_INT, 0}, \ + {"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&usim_test, defintval:0, TYPE_UINT8, 0}, \ + {"external-clock", CONFIG_HLP_EXCCLK, PARAMFLAG_BOOL, uptr:&clock_source, defintval:0, TYPE_INT, 0}, \ + {"single-thread-disable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&single_thread_flag, defintval:1, TYPE_INT, 0}, \ + {"nr-dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&nr_dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ + {"A" , CONFIG_HLP_TADV, 0, uptr:&timing_advance, defintval:0, TYPE_UINT, 0}, \ + {"C" , CONFIG_HLP_DLF, 0, uptr:&(downlink_frequency[0][0]), defuintval:2680000000, TYPE_UINT, 0}, \ + {"a" , CONFIG_HLP_CHOFF, 0, iptr:&chain_offset, defintval:0, TYPE_INT, 0}, \ + {"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, iptr:&do_forms, defintval:0, TYPE_INT, 0}, \ + {"E" , CONFIG_HLP_TQFS, PARAMFLAG_BOOL, iptr:&threequarter_fs, defintval:0, TYPE_INT, 0}, \ + {"m" , CONFIG_HLP_DLMCS, 0, uptr:&target_dl_mcs, defintval:0, TYPE_UINT, 0}, \ + {"t" , CONFIG_HLP_ULMCS, 0, uptr:&target_ul_mcs, defintval:0, TYPE_UINT, 0}, \ + {"W" , CONFIG_HLP_L2MONW, 0, strptr:(char **)&in_ip, defstrval:"127.0.0.1", TYPE_STRING, sizeof(in_ip)}, \ + {"P" , CONFIG_HLP_L2MONP, 0, strptr:(char **)&in_path, defstrval:"/tmp/oai_opt.pcap", TYPE_STRING, sizeof(in_path)}, \ + {"q" , CONFIG_HLP_STMON, PARAMFLAG_BOOL, iptr:&opp_enabled, defintval:0, TYPE_INT, 0}, \ + {"S" , CONFIG_HLP_MSLOTS, PARAMFLAG_BOOL, u8ptr:&exit_missed_slots, defintval:1, TYPE_UINT8, 0}, \ + {"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, \ + {"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&numerology, defintval:0, TYPE_INT, 0}, \ + {"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&emulate_rf, defintval:0, TYPE_INT, 0}, \ + {"parallel-config", CONFIG_HLP_PARALLEL_CMD,0, strptr:(char **)¶llel_config, defstrval:NULL, TYPE_STRING, 0}, \ + {"worker-config", CONFIG_HLP_WORKER_CMD, 0, strptr:(char **)&worker_config, defstrval:NULL, TYPE_STRING, 0}, \ + {"nbiot-disable", CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL, iptr:&nonbiotflag, defintval:0, TYPE_INT, 0} \ + } + +#define CONFIG_HLP_FLOG "Enable online log \n" +#define CONFIG_HLP_LOGL "Set the global log level, valide options: (9:trace, 8/7:debug, 6:info, 4:warn, 3:error)\n" +#define CONFIG_HLP_LOGV "Set the global log verbosity \n" +#define CONFIG_HLP_TELN "Start embedded telnet server \n" +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters for LOG utility */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_LOGPARAMS_DESC { \ + {"R" , CONFIG_HLP_FLOG, 0, uptr:&online_log_messages, defintval:1, TYPE_INT, 0}, \ + {"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ + {"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \ + {"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ + } +#define CMDLINE_ONLINELOG_IDX 0 +#define CMDLINE_GLOGLEVEL_IDX 1 +#define CMDLINE_GLOGVERBO_IDX 2 +#define CMDLINE_STARTTELN_IDX 3 + + +extern int T_port; +extern int T_nowait; +extern int T_dont_fork; + + + +/***************************************************************************************************************************************/ + +extern pthread_cond_t sync_cond; +extern pthread_mutex_t sync_mutex; +extern int sync_var; + + +extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; +extern int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; + +extern int rx_input_level_dBm; +extern uint8_t exit_missed_slots; +extern uint64_t num_missed_slots; // counter for the number of missed slots + +extern int oaisim_flag; +extern volatile int oai_exit; + +extern openair0_config_t openair0_cfg[MAX_CARDS]; +extern pthread_cond_t sync_cond; +extern pthread_mutex_t sync_mutex; +extern int sync_var; +extern int transmission_mode; +extern double cpuf; + +#if defined(ENABLE_ITTI) + extern volatile int start_eNB; + extern volatile int start_UE; +#endif + +// In nr-ue.c +extern int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg); +extern void fill_ue_band_info(void); +extern void init_UE(int); +extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char *name); +extern void reset_opp_meas(void); +extern void print_opp_meas(void); +void *UE_thread(void *arg); +PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, + uint8_t UE_id, + uint8_t abstraction_flag); +extern tpool_t *Tpool; +#endif 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 f1a3ef42ab..f3cd1a29f3 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c @@ -52,9 +52,7 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, ncoef = 32767 - coef; -//#ifdef DEBUG_PHY - LOG_D(PHY,"AbsSubframe %d.%d: rx_offset (before) = %d\n",ue->proc.proc_rxtx[0].frame_rx%1024,subframe,ue->rx_offset); -//#endif //DEBUG_PHY + LOG_D(PHY,"AbsSubframe %d: rx_offset (before) = %d\n",subframe,ue->rx_offset); // we only use channel estimates from tx antenna 0 here @@ -122,8 +120,7 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, #ifdef DEBUG_PHY - LOG_D(PHY,"AbsSubframe %d.%d: ThreadId %d diff =%i rx_offset (final) = %i : clear %d,max_pos = %d,max_pos_fil = %d (peak %d) max_val %d target_pos %d \n", - ue->proc.proc_rxtx[ue->current_thread_id[subframe]].frame_rx, + LOG_D(PHY,"AbsSubframe %d: ThreadId %d diff =%i rx_offset (final) = %i : clear %d,max_pos = %d,max_pos_fil = %d (peak %d) max_val %d target_pos %d \n", subframe, ue->current_thread_id[subframe], diff, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index def3a71754..b6a28c81b0 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -39,7 +39,7 @@ #include "PHY/NR_TRANSPORT/nr_dlsch.h" #include "SCHED_NR_UE/defs.h" #include "SIMULATION/TOOLS/sim.h" -#include "targets/RT/USER/nr-uesoftmodem.h" +#include "executables/nr-uesoftmodem.h" #include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h" #include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h" //#define DEBUG_DLSCH_DECODING diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index ca0aa50d0e..3a7af2e6be 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -203,14 +203,14 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #endif } else { - LOG_E(PHY,"[UE][FATAL] Frame %d nr_tti_rx %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,nr_tti_rx); + LOG_E(PHY,"[UE][FATAL] nr_tti_rx %d: no active DLSCH\n",nr_tti_rx); return(-1); } beamforming_mode = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]; break; default: - LOG_E(PHY,"[UE][FATAL] Frame %d nr_tti_rx %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,nr_tti_rx,type); + LOG_E(PHY,"[UE][FATAL] nr_tti_rx %d: Unknown PDSCH format %d\n",nr_tti_rx,type); return(-1); break; } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 02b3d57afe..23dda3fc24 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -122,11 +122,6 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, runmode_t mode) // ue->pbch_vars[0]->decoded_output[0] = ue->pbch_vars[0]->decoded_output[2]; // ue->pbch_vars[0]->decoded_output[2] = dummy; - for(int i=0; iproc.proc_rxtx[i].frame_tx = ue->proc.proc_rxtx[0].frame_rx; - } #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"[UE%d] Initial sync: pbch decoded sucessfully\n",ue->Mod_id); #endif @@ -292,9 +287,8 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) if (ue->UE_scan_carrier == 0) { #if UE_AUTOTEST_TRACE - LOG_I(PHY,"[UE %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n", + LOG_I(PHY,"[UE %d] AUTOTEST Cell Sync : rx_offset %d, freq_offset %d \n", ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, ue->rx_offset, ue->common_vars.freq_offset ); #endif @@ -305,30 +299,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) } -#if DISABLE_LOG_X - printf("[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm, rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, - 10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB, - 10*log10(ue->measurements.rssi), - ue->rx_total_gain_dB, - ue->measurements.n0_power_tot_dBm, - 10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB, - (10*log10(ue->measurements.rsrq[0]))); - - - printf("[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n", - ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, - duplex_string[fp->frame_type], - prefix_string[fp->Ncp], - fp->Nid_cell, - fp->N_RB_DL, - fp->phich_config_common.phich_duration, - phich_string[fp->phich_config_common.phich_resource], - fp->nb_antenna_ports_eNB); -#else - LOG_I(PHY, "[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm, rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, + LOG_I(PHY, "[UE %d] RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm, rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id, 10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB, 10*log10(ue->measurements.rssi), ue->rx_total_gain_dB, @@ -346,22 +317,12 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) fp->phich_config_common.phich_duration, phich_string[fp->phich_config_common.phich_resource], fp->nb_antenna_ports_eNB);*/ -#endif #if defined(OAI_USRP) || defined(EXMIMO) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706) -# if DISABLE_LOG_X - printf("[UE %d] Frame %d Measured Carrier Frequency %.0f Hz (offset %d Hz)\n", + LOG_I(PHY, "[UE %d] Measured Carrier Frequency %.0f Hz (offset %d Hz)\n", ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, openair0_cfg[0].rx_freq[0]+ue->common_vars.freq_offset, ue->common_vars.freq_offset); -# else - LOG_I(PHY, "[UE %d] Frame %d Measured Carrier Frequency %.0f Hz (offset %d Hz)\n", - ue->Mod_id, - ue->proc.proc_rxtx[0].frame_rx, - openair0_cfg[0].rx_freq[0]+ue->common_vars.freq_offset, - ue->common_vars.freq_offset); -# endif #endif } else { #ifdef DEBUG_INITIAL_SYNC diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 95381ad560..9f1c8e096d 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -267,27 +267,6 @@ typedef struct { uint8_t CC_id; /// Last RX timestamp openair0_timestamp timestamp_rx; - /// pthread attributes for main UE thread - pthread_attr_t attr_ue; - /// scheduling parameters for main UE thread - struct sched_param sched_param_ue; - /// pthread descriptor main UE thread - pthread_t pthread_ue; - /// \brief Instance count for synch thread. - /// \internal This variable is protected by \ref mutex_synch. - int instance_cnt_synch; - /// pthread attributes for synch processing thread - pthread_attr_t attr_synch; - /// scheduling parameters for synch thread - struct sched_param sched_param_synch; - /// pthread descriptor synch thread - pthread_t pthread_synch; - /// condition variable for UE synch thread; - pthread_cond_t cond_synch; - /// mutex for UE synch thread - pthread_mutex_t mutex_synch; - /// set of scheduling variables RXn-TXnp4 threads - UE_nr_rxtx_proc_t proc_rxtx[RX_NB_TH]; } UE_nr_proc_t; typedef enum { diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index ca30ab1cec..7c17987980 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -232,7 +232,6 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ printf("half frame bit: %d\n", phy_config->config_req.pbch_config.half_frame_bit); printf("-------------------------------\n"); - PHY_vars_UE_g[0][0]->proc.proc_rxtx[0].frame_rx = phy_config->config_req.pbch_config.system_frame_number; } if(phy_config->config_req.config_mask & FAPI_NR_CONFIG_REQUEST_MASK_DL_BWP_COMMON){ diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c index c9ea45f03b..3b24814951 100644 --- a/openair1/SCHED_UE/phy_procedures_lte_ue.c +++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c @@ -36,7 +36,7 @@ #include "PHY/defs_UE.h" #include "PHY/phy_extern_ue.h" #include -#include "targets/RT/USER/lte-softmodem.h" +#include "executables/nr-uesoftmodem.h" #include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h" #include "SCHED_UE/sched_UE.h" @@ -5116,13 +5116,13 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,u if (msg_p != NULL) { switch (ITTI_MSG_ID(msg_p)) { case PHY_FIND_CELL_REQ: - LOG_I(PHY, "[UE %d] Received %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p)); + LOG_I(PHY, "[UE ] Received %s\n", ITTI_MSG_NAME (msg_p)); /* TODO process the message */ break; default: - LOG_E(PHY, "[UE %d] Received unexpected message %s\n", ITTI_MSG_INSTANCE (msg_p) - NB_eNB_INST, ITTI_MSG_NAME (msg_p)); + LOG_E(PHY, "[UE %d] Received unexpected message %s\n", ITTI_MSG_INSTANCE (msg_p) , ITTI_MSG_NAME (msg_p)); break; } diff --git a/openair2/LAYER2/NR_MAC_UE/mac.h b/openair2/LAYER2/NR_MAC_UE/mac.h index d0b6d4730d..fe8e91500a 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac.h +++ b/openair2/LAYER2/NR_MAC_UE/mac.h @@ -43,10 +43,10 @@ /*!\brief UE layer 2 status */ typedef enum { - CONNECTION_OK = 0, - CONNECTION_LOST, - PHY_RESYNCH, - PHY_HO_PRACH + UE_CONNECTION_OK = 0, + UE_CONNECTION_LOST, + UE_PHY_RESYNCH, + UE_PHY_HO_PRACH } NR_UE_L2_STATE_t; typedef struct { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index f34000bc98..2379233776 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -30,8 +30,8 @@ * \warning */ -#ifndef __LAYER2_MAC_PROTO_H__ -#define __LAYER2_MAC_PROTO_H__ +#ifndef __LAYER2_MAC_UE_PROTO_H__ +#define __LAYER2_MAC_UE_PROTO_H__ #include "mac_defs.h" #include "mac.h" diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index e3dad2db70..7110a35331 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -686,7 +686,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler( mac->scheduled_response.dl_config = dl_config; - return CONNECTION_OK; + return UE_CONNECTION_OK; } ////////////// diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 840cb5b4cc..e391cc67b9 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -102,13 +102,13 @@ int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){ 0, 0); // TODO check tx/rx frame/slot is need for NR version switch(ret){ - case CONNECTION_OK: + case UE_CONNECTION_OK: break; - case CONNECTION_LOST: + case UE_CONNECTION_LOST: break; - case PHY_RESYNCH: + case UE_PHY_RESYNCH: break; - case PHY_HO_PRACH: + case UE_PHY_HO_PRACH: break; default: break; diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h index 685a628b26..d14b2457c9 100644 --- a/targets/ARCH/COMMON/common_lib.h +++ b/targets/ARCH/COMMON/common_lib.h @@ -424,7 +424,7 @@ extern "C" * \returns 0 in success */ int openair0_set_rx_frequencies(openair0_device* device, openair0_config_t *openair0_cfg); - +#define gettid() syscall(__NR_gettid) /*@}*/ #ifdef __cplusplus From 71bc14d0d909500924b99c37f579e03c34d85b74 Mon Sep 17 00:00:00 2001 From: laurent Date: Thu, 21 Mar 2019 14:33:25 +0100 Subject: [PATCH 044/117] new thread model - make affinity optional --- common/utils/threadPool/thread-pool.c | 51 ++++++++++++++++----------- executables/nr-ue.c | 14 -------- executables/nr-uesoftmodem.c | 2 +- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c index ca050ea098..4cc56fc9b8 100644 --- a/common/utils/threadPool/thread-pool.c +++ b/common/utils/threadPool/thread-pool.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include void displayList(notifiedFIFO_t *nf) { @@ -46,12 +48,16 @@ static inline notifiedFIFO_elt_t *pullNotifiedFifoRemember( notifiedFIFO_t *nf, void *one_thread(void *arg) { struct one_thread *myThread=(struct one_thread *) arg; struct thread_pool *tp=myThread->pool; + // configure the thread core assignment // TBD: reserve the core for us exclusively - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - CPU_SET(myThread->coreID, &cpuset); - pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + if ( myThread->coreID >= 0 && myThread->coreID < get_nprocs_conf()) { + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(myThread->coreID, &cpuset); + pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + } + //Configure the thread scheduler policy for Linux struct sched_param sparam= {0}; sparam.sched_priority = sched_get_priority_max(SCHED_RR); @@ -112,22 +118,27 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { curptr=strtok_r(params,",",&saveptr); while ( curptr!=NULL ) { - if (curptr[0] == 'u' || curptr[0] == 'U') { - pool->restrictRNTI=true; - } else if ( curptr[0]>='0' && curptr[0]<='9' ) { - struct one_thread *tmp=pool->allthreads; - pool->allthreads=(struct one_thread *)malloc(sizeof(struct one_thread)); - pool->allthreads->next=tmp; - printf("create a thread for core %d\n", atoi(curptr)); - pool->allthreads->coreID=atoi(curptr); - pool->allthreads->id=pool->nbThreads; - pool->allthreads->pool=pool; - pthread_create(&pool->allthreads->threadID, NULL, one_thread, (void *)pool->allthreads); - pool->nbThreads++; - } else if (curptr[0] == 'n' || curptr[0] == 'N') { - pool->activated=false; - } else - printf("Error in options for thread pool: %s\n",curptr); + int c=toupper(curptr[0]); + + switch (c) { + case 'U': + pool->restrictRNTI=true; + break; + + case 'N': + pool->activated=false; + break; + + default: + pool->allthreads=(struct one_thread *)malloc(sizeof(struct one_thread)); + pool->allthreads->next=pool->allthreads; + printf("create a thread for core %d\n", atoi(curptr)); + pool->allthreads->coreID=atoi(curptr); + pool->allthreads->id=pool->nbThreads; + pool->allthreads->pool=pool; + pthread_create(&pool->allthreads->threadID, NULL, one_thread, (void *)pool->allthreads); + pool->nbThreads++; + } curptr=strtok_r(NULL,",",&saveptr); } diff --git a/executables/nr-ue.c b/executables/nr-ue.c index d45ee37d19..46dd2835d9 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -19,16 +19,6 @@ * contact@openairinterface.org */ -/*! \file lte-ue.c - * \brief threads and support functions for real-time LTE UE target - * \author R. Knopp, F. Kaltenberger, Navid Nikaein - * \date 2015 - * \version 0.1 - * \company Eurecom - * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr - * \note - * \warning - */ #include "executables/nr-uesoftmodem.h" #include "LAYER2/NR_MAC_UE/mac.h" @@ -141,10 +131,6 @@ typedef enum { si=2 } sync_mode_t; - -int32_t **rxdata; -int32_t **txdata; - #define KHz (1000UL) #define MHz (1000*KHz) typedef struct eutra_band_s { diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 5384e0835d..ed5ff7aa1d 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -709,7 +709,7 @@ int main( int argc, char **argv ) { set_taus_seed (0); tpool_t pool; Tpool = &pool; - char params[]="1,2,3,u"; + char params[]="-1,-1,-1,-1"; initTpool(params, Tpool, false); cpuf=get_cpu_freq_GHz(); itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); From b68366e54ae41f899283f4324e7d97ec322dd649 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 5 Mar 2019 09:50:03 +0100 Subject: [PATCH 045/117] bugfix --- openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a90450b0a5..079cec04b9 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -50,8 +50,8 @@ 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, ssb_index=0, n_hf=0; - 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; + int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = ue->frame_parms.Nid_cell%4; ue->frame_parms.nushift = nushift; @@ -78,7 +78,7 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, k = nushift; #ifdef DEBUG_CH - printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns>>1], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, + printf("PBCH Channel Estimation : ThreadId %d, eNB_offset %d ch_offset %d, OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n",ue->current_thread_id[Ns], eNB_offset,ch_offset,ue->frame_parms.ofdm_symbol_size, ue->frame_parms.Ncp,l,Ns,k, symbol); #endif From 8e5c8ad2dfd0dc2e264231231ba7ac1a3cf196b2 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 8 Mar 2019 11:09:08 +0100 Subject: [PATCH 046/117] adding external ref to config file --- .../GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf index 3aaf0c5506..24a6e69e7c 100644 --- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.106PRB.usrpn300.conf @@ -254,7 +254,7 @@ RUs = ( max_pdschReferenceSignalPower = -27; max_rxgain = 114; eNB_instances = [0]; - sdr_addrs = "addr=192.168.10.2,second_addr=192.168.20.2,mgmt_addr=192.168.100.8"; + sdr_addrs = "addr=192.168.10.2,second_addr=192.168.20.2,mgmt_addr=192.168.100.8,clock_source=external,time_source=external"; } ); From 02de5fd0782e4dec388c1bb84545925a6180121c Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 8 Mar 2019 11:09:31 +0100 Subject: [PATCH 047/117] disabling debug messages --- openair1/PHY/NR_UE_TRANSPORT/dci_nr.c | 4 ++-- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index 6f2f5bcf2d..2e02ab5811 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -1418,11 +1418,11 @@ void nr_dci_decoding_procedure0(int s, *format_found=_format_2_3_found; } - //#ifdef NR_PDCCH_DCI_DEBUG +#ifdef NR_PDCCH_DCI_DEBUG printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> format_found=%d\n",*format_found); printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> crc_scrambled=%d\n",*crc_scrambled); + #endif - //#endif if (*format_found!=255) { dci_alloc[*dci_cnt].dci_length = sizeof_bits; dci_alloc[*dci_cnt].rnti = crc; diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index e821e9696a..c067142897 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -52,7 +52,7 @@ //#define DEBUG_DCI #define NR_PDCCH_DCI_TOOLS -#define NR_PDCCH_DCI_TOOLS_DEBUG +//#define NR_PDCCH_DCI_TOOLS_DEBUG typedef unsigned __int128 uint128_t; From c4188d80130f7bb260b998f9f9fa75a55607626e Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 8 Mar 2019 11:09:56 +0100 Subject: [PATCH 048/117] moving adjust sync out of measurement procedures and making it dependent on successfull decoding of DCI --- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 60 ++++++++------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 1a631000f5..1dc042e93a 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2760,37 +2760,6 @@ void nr_ue_measurement_procedures( } #endif - // accumulate and filter timing offset estimation every nr_tti_rx (instead of every frame) - if (( slot == 2) && (l==(1-frame_parms->Ncp))) { - - // AGC -/* - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GAIN_CONTROL, VCD_FUNCTION_IN); - -#ifndef OAI_USRP -#ifndef OAI_BLADERF -#ifndef OAI_LMSSDR -#ifndef OAI_ADRV9371_ZC706 - phy_adjust_gain (ue,dB_fixed(ue->measurements.rssi),0); -#endif -#endif -#endif -#endif - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GAIN_CONTROL, VCD_FUNCTION_OUT); -*/ - eNB_id = 0; - - LOG_D(PHY,"start adjust sync l = %d slot = %d no timing %d\n",l, slot, ue->no_timing_correction); - if (ue->no_timing_correction==0) - nr_adjust_synch_ue(&ue->frame_parms, - ue, - eNB_id, - nr_tti_rx, - 0, - 16384); - - } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_OUT); } @@ -3364,7 +3333,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * } // end for loop nb_searchspace_active - return(0); + return(dci_cnt); } #endif // NR_PDCCH_SCHED @@ -4969,6 +4938,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][0]; uint16_t nb_symb_sch = 8; // to be updated by higher layer uint8_t nb_symb_pdcch = pdcch_vars->coreset[0].duration; + uint8_t dci_cnt = 0; LOG_D(PHY," ****** start RX-Chain for Frame.Slot %d.%d ****** \n", frame_rx%1024, nr_tti_rx); @@ -4978,7 +4948,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN #ifdef NR_PDCCH_SCHED nr_gold_pdcch(ue,0, 2); - //if (nr_tti_rx==1){ + LOG_D(PHY," ------ --> PDCCH ChannelComp/LLR Frame.slot %d.%d ------ \n", frame_rx%1024, nr_tti_rx); for (uint16_t l=0; lMod_id,frame_rx,nr_tti_rx); - return(-1); + dci_cnt = nr_ue_pdcch_procedures(eNB_id,ue,proc); + + if (dci_cnt > 0) { + + LOG_I(PHY,"[UE %d] Frame %d, nr_tti_rx %d: found %d DCIs\n",ue->Mod_id,frame_rx,nr_tti_rx,dci_cnt); + + if (0/*ue->no_timing_correction==0*/) { + LOG_I(PHY,"start adjust sync slot = %d no timing %d\n", nr_tti_rx, ue->no_timing_correction); + nr_adjust_synch_ue(&ue->frame_parms, + ue, + eNB_id, + nr_tti_rx, + 0, + 16384); + } + } + else { + LOG_D(PHY,"[UE %d] Frame %d, nr_tti_rx %d: No DCIs found\n",ue->Mod_id,frame_rx,nr_tti_rx); } - //} #endif //NR_PDCCH_SCHED From 7ca8fc9de1a2bbaea6fb587bca6c219b81f49e4e Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 19 Mar 2019 15:43:20 +0100 Subject: [PATCH 049/117] increasing timeout on trx_read for x300/n300 in usrp_lib.cpp removing unncesessary sleeps and mallocs, improving error messages in nr-ue.c --- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 4 +- targets/RT/USER/nr-ue.c | 48 ++++++-------------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index ffdec958a9..58a8697f79 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -597,10 +597,10 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp for (int i=0; irx_stream->recv(buff_ptrs, nsamps, s->rx_md); + samples_received = s->rx_stream->recv(buff_ptrs, nsamps, s->rx_md,1.0); } else { // receive a single channel (e.g. from connector RF A) - samples_received = s->rx_stream->recv(buff[0], nsamps, s->rx_md); + samples_received = s->rx_stream->recv(buff[0], nsamps, s->rx_md,1.0); } } diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c index 4ab0781787..e3e5cb962e 100644 --- a/targets/RT/USER/nr-ue.c +++ b/targets/RT/USER/nr-ue.c @@ -756,10 +756,6 @@ static void *UE_thread_rxn_txnp4(void *arg) { void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { void *rxp[NB_ANTENNAS_RX]; - void *dummy_tx[UE->frame_parms.nb_antennas_tx]; - - for (int i=0; iframe_parms.nb_antennas_tx; i++) - dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); for(int x=0; x<10; x++) { for (int i=0; iframe_parms.nb_antennas_rx; i++) @@ -770,37 +766,28 @@ void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { timestamp, rxp, UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx), ""); + UE->frame_parms.nb_antennas_rx), "readFrame error"); } - for (int i=0; iframe_parms.nb_antennas_tx; i++) - free(dummy_tx[i]); } void trashFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - void *dummy_tx[UE->frame_parms.nb_antennas_tx]; - - for (int i=0; iframe_parms.nb_antennas_tx; i++) - dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); - void *dummy_rx[UE->frame_parms.nb_antennas_rx]; for (int i=0; iframe_parms.nb_antennas_rx; i++) dummy_rx[i]=malloc16(UE->frame_parms.samples_per_subframe*4); for (int sf=0; sfrfdevice.trx_read_func(&UE->rfdevice, - timestamp, - dummy_rx, - UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx); - usleep(500); // this sleep improves in the case of simulated RF and doesn't harm with true radio + //printf("Reading dummy sf %d\n",sf); + AssertFatal( UE->frame_parms.samples_per_subframe == + UE->rfdevice.trx_read_func(&UE->rfdevice, + timestamp, + dummy_rx, + UE->frame_parms.samples_per_subframe, + UE->frame_parms.nb_antennas_rx), "trashFrame error"); + //usleep(500); // this sleep improves in the case of simulated RF and doesn't harm with true radio } - for (int i=0; iframe_parms.nb_antennas_tx; i++) - free(dummy_tx[i]); - for (int i=0; iframe_parms.nb_antennas_rx; i++) free(dummy_rx[i]); } @@ -808,10 +795,6 @@ void trashFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { if (UE->no_timing_correction==0) { LOG_I(PHY,"Resynchronizing RX by %d samples (mode = %d)\n",UE->rx_offset,UE->mode); - void *dummy_tx[UE->frame_parms.nb_antennas_tx]; - - for (int i=0; iframe_parms.nb_antennas_tx; i++) - dummy_tx[i]=malloc16_clear(UE->frame_parms.samples_per_subframe*4); for ( int size=UE->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 ; @@ -820,11 +803,8 @@ void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { timestamp, (void **)UE->common_vars.rxdata, unitTransfer, - UE->frame_parms.nb_antennas_rx),""); + UE->frame_parms.nb_antennas_rx),"syncInFrame error"); } - - for (int i=0; iframe_parms.nb_antennas_tx; i++) - free(dummy_tx[i]); } } @@ -952,7 +932,7 @@ void *UE_thread(void *arg) { ×tamp, (void **)UE->common_vars.rxdata, UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, - UE->frame_parms.nb_antennas_rx),""); + UE->frame_parms.nb_antennas_rx),"first symbol read error"); //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0), 1, 1); //nr_slot_fep(UE,0, 0, 0, 1, 1, NR_PDCCH_EST); } //UE->mode != loop_through_memory @@ -1031,7 +1011,7 @@ void *UE_thread(void *arg) { ×tamp, rxp, readBlockSize, - UE->frame_parms.nb_antennas_rx),""); + UE->frame_parms.nb_antennas_rx),"read error"); AssertFatal( writeBlockSize == UE->rfdevice.trx_write_func(&UE->rfdevice, timestamp+ @@ -1041,7 +1021,7 @@ void *UE_thread(void *arg) { txp, writeBlockSize, UE->frame_parms.nb_antennas_tx, - 1),""); + 1),"write error"); if( slot_nr==(nb_slot_frame-1)) { // read in first symbol of next frame and adjust for timing drift @@ -1053,7 +1033,7 @@ void *UE_thread(void *arg) { ×tamp, (void **)UE->common_vars.rxdata, first_symbols, - UE->frame_parms.nb_antennas_rx),""); + UE->frame_parms.nb_antennas_rx),"first symbols read error"); else LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols); } From c3e567bb33902ed8665df17231703c64a11bd70b Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Fri, 22 Mar 2019 10:17:03 +0100 Subject: [PATCH 050/117] CI: removing TDD 20MHz scenarios from CI test-suite temporarly Signed-off-by: Raphael Defosseux --- ...0mhz_tm1.xml => enb_usrp210_band40_test_20mhz_tm1_not_run.xml} | 0 ...test_20mhz.xml => if4p5_usrp210_band40_test_20mhz_not_run.xml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename ci-scripts/xml_files/{enb_usrp210_band40_test_20mhz_tm1.xml => enb_usrp210_band40_test_20mhz_tm1_not_run.xml} (100%) rename ci-scripts/xml_files/{if4p5_usrp210_band40_test_20mhz.xml => if4p5_usrp210_band40_test_20mhz_not_run.xml} (100%) diff --git a/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml b/ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_not_run.xml similarity index 100% rename from ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1.xml rename to ci-scripts/xml_files/enb_usrp210_band40_test_20mhz_tm1_not_run.xml diff --git a/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml b/ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz_not_run.xml similarity index 100% rename from ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz.xml rename to ci-scripts/xml_files/if4p5_usrp210_band40_test_20mhz_not_run.xml From 0ba1958e3991de12a8f06ba42d460a9f58033714 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Fri, 22 Mar 2019 11:59:22 +0100 Subject: [PATCH 051/117] CI: fix when XML file is missing during HtmlInit Signed-off-by: Raphael Defosseux --- ci-scripts/main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ci-scripts/main.py b/ci-scripts/main.py index 70bfa1894f..dc101fe7ea 100644 --- a/ci-scripts/main.py +++ b/ci-scripts/main.py @@ -2542,14 +2542,19 @@ elif re.match('^InitiateHtml$', mode, re.IGNORECASE): Usage() sys.exit('Insufficient Parameter') count = 0 + foundCount = 0 while (count < SSH.nbTestXMLfiles): xml_test_file = sys.path[0] + "/" + SSH.testXMLfiles[count] - xmlTree = ET.parse(xml_test_file) - xmlRoot = xmlTree.getroot() - SSH.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-' + str(count))) - SSH.htmlTabNames.append(xmlRoot.findtext('htmlTabName',default='Test-' + str(count))) - SSH.htmlTabIcons.append(xmlRoot.findtext('htmlTabIcon',default='info-sign')) + if (os.path.isfile(xml_test_file)): + xmlTree = ET.parse(xml_test_file) + xmlRoot = xmlTree.getroot() + SSH.htmlTabRefs.append(xmlRoot.findtext('htmlTabRef',default='test-tab-' + str(count))) + SSH.htmlTabNames.append(xmlRoot.findtext('htmlTabName',default='Test-' + str(count))) + SSH.htmlTabIcons.append(xmlRoot.findtext('htmlTabIcon',default='info-sign')) + foundCount += 1 count += 1 + if foundCount != SSH.nbTestXMLfiles: + SSH.nbTestXMLfiles = foundCount SSH.CreateHtmlHeader() elif re.match('^FinalizeHtml$', mode, re.IGNORECASE): SSH.CreateHtmlFooter(SSH.finalStatus) From 30e06d16ce5afb8e3719bbbafba96b3a2c23fcde Mon Sep 17 00:00:00 2001 From: laurent Date: Fri, 22 Mar 2019 14:03:27 +0100 Subject: [PATCH 052/117] revised doc --- common/utils/threadPool/thread-pool.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/utils/threadPool/thread-pool.md b/common/utils/threadPool/thread-pool.md index 92cc21b975..2b6336fb60 100644 --- a/common/utils/threadPool/thread-pool.md +++ b/common/utils/threadPool/thread-pool.md @@ -11,7 +11,7 @@ All the thread pool functions are thread safe, nevertheless the working function ## license Author: Laurent Thomas, Open cells project -The owner share the code usage to Openairsoftware alliance as per OSA license terms +The owner share this piece code to Openairsoftware alliance as per OSA license terms # jobs @@ -41,6 +41,8 @@ abort_notifiedFIFO() allows the customer to delete all waiting jobs that match w The clients can create one or more thread pools with init_tpool() the params string structure: describes a list of cores, separated by "," that run a worker thread +If the core exists on the CPU, the thread pool initialization sets the affinity between this thread and the related code (use negative values is allowed, so the thread will never be mapped on a specific core). + The threads are all Linux real time scheduler, their name is set automatically is "Tpool_" ## adding jobs @@ -66,4 +68,4 @@ A performance measurement is integrated: the pool will automacillay fill timesta if you set the environement variable: thread-pool-measurements to a valid file name These measurements will be wrote to this Linux pipe. -A tool to read the linux fifo and display it in ascii will be provided (TBD) +A tool to read the linux fifo and display it in ascii is provided: see the local directory Makefile for this tool and to compile the thread pool unitary tests. From 0f04910f2f6d5349d976ae6d75bdaee561599417 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 22 Mar 2019 15:22:19 +0100 Subject: [PATCH 053/117] moving get_band to separate function --- openair1/PHY/INIT/nr_parms.c | 63 ++++++++++++++++++++++++++++++++ openair1/PHY/INIT/phy_init.h | 3 ++ openair1/PHY/defs_nr_common.h | 17 +++++++++ targets/RT/USER/nr-ue.c | 39 ++------------------ targets/RT/USER/nr-uesoftmodem.c | 14 +++---- 5 files changed, 93 insertions(+), 43 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index 021d0b10bb..7fee692f08 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -300,3 +300,66 @@ void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp) LOG_I(PHY,"fp->initial_bwp_dl.location=%d\n",fp->initial_bwp_dl.location); LOG_I(PHY,"fp->initial_bwp_dl.ofdm_symbol_size=%d\n",fp->initial_bwp_dl.ofdm_symbol_size); } + + +static const eutra_band_t eutra_bands[] = { + {1, 1920000, 1980000, 2110000, 2170000, FDD}, + {2, 1850000, 1910000, 1930000, 1990000, FDD}, + {3, 1710000, 1785000, 1805000, 1880000, FDD}, + {5, 824000, 849000, 869000, 894000, FDD}, + {7, 2500000, 2570000, 2620000, 2690000, FDD}, + {8, 880000, 915000, 925000, 960000, FDD}, + {12, 698000, 716000, 728000, 746000, FDD}, + {20, 832000, 862000, 791000, 821000, FDD}, + {25, 1850000, 1915000, 1930000, 1995000, FDD}, + {28, 703000, 758000, 758000, 813000, FDD}, + {34, 2010000, 2025000, 2010000, 2025000, TDD}, + {38, 2570000, 2620000, 2570000, 2630000, TDD}, + {39, 1880000, 1920000, 1880000, 1920000, TDD}, + {40, 2300000, 2400000, 2300000, 2400000, TDD}, + {41, 2496000, 2690000, 2496000, 2690000, TDD}, + {50, 1432000, 1517000, 1432000, 1517000, TDD}, + {51, 1427000, 1432000, 1427000, 1432000, TDD}, + {66, 1710000, 1780000, 2110000, 2200000, FDD}, + {70, 1695000, 1710000, 1995000, 2020000, FDD}, + {71, 663000, 698000, 617000, 652000, FDD}, + {74, 1427000, 1470000, 1475000, 1518000, FDD}, + {75, 000, 000, 1432000, 1517000, FDD}, + {76, 000, 000, 1427000, 1432000, FDD}, + {77, 3300000, 4200000, 3300000, 4200000, TDD}, + {78, 3300000, 3800000, 3300000, 3800000, TDD}, + {79, 4400000, 5000000, 4400000, 5000000, TDD}, + {80, 1710000, 1785000, 000, 000, FDD}, + {81, 860000, 915000, 000, 000, FDD}, + {82, 832000, 862000, 000, 000, FDD}, + {83, 703000, 748000, 000, 000, FDD}, + {84, 1920000, 1980000, 000, 000, FDD}, + {86, 1710000, 1785000, 000, 000, FDD} +}; + +int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { + + int ind; + int64_t dl_freq_khz = downlink_frequency/1000; + for ( ind=0; + ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); + ind++) { + *current_band = eutra_bands[ind].band; + *current_type = eutra_bands[ind].frame_type; + LOG_I(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", ind, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); + + if ( eutra_bands[ind].dl_min <= dl_freq_khz && eutra_bands[ind].dl_max >= dl_freq_khz ) { + *current_offset = (eutra_bands[ind].ul_min - eutra_bands[ind].dl_min)*1000; + + LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", + downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); + break; + } + } + + if( ind == sizeof(eutra_bands) / sizeof(eutra_bands[0])) { + LOG_E(PHY,"Can't find EUTRA band for frequency %d\n", downlink_frequency); + return(-1); + } +} + diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h index ddda39a4c8..f500375e4b 100644 --- a/openair1/PHY/INIT/phy_init.h +++ b/openair1/PHY/INIT/phy_init.h @@ -391,6 +391,9 @@ void init_nr_transport(PHY_VARS_gNB *gNB); void init_dfts(void); +int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); + + /** @} */ #endif diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 267c156184..c09566c67e 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -321,4 +321,21 @@ typedef struct NR_DL_FRAME_PARMS { } NR_DL_FRAME_PARMS; +#define KHz (1000UL) +#define MHz (1000*KHz) + +typedef struct eutra_band_s { + int16_t band; + uint32_t ul_min; + uint32_t ul_max; + uint32_t dl_min; + uint32_t dl_max; + lte_frame_type_t frame_type; +} eutra_band_t; + +typedef struct band_info_s { + int nbands; + eutra_band_t band_info[100]; +} band_info_t; + #endif diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c index afab7be1ad..a4afdcd6b6 100644 --- a/targets/RT/USER/nr-ue.c +++ b/targets/RT/USER/nr-ue.c @@ -150,27 +150,12 @@ void init_UE(int nb_inst); int32_t **rxdata; int32_t **txdata; -#define KHz (1000UL) -#define MHz (1000*KHz) #define SAIF_ENABLED #ifdef SAIF_ENABLED uint64_t g_ue_rx_thread_busy = 0; #endif -typedef struct eutra_band_s { - int16_t band; - uint32_t ul_min; - uint32_t ul_max; - uint32_t dl_min; - uint32_t dl_max; - lte_frame_type_t frame_type; -} eutra_band_t; - -typedef struct band_info_s { - int nbands; - eutra_band_t band_info[100]; -} band_info_t; band_info_t bands_to_scan; @@ -354,29 +339,11 @@ static void *UE_thread_synch(void *arg) { init_thread(100000, 500000, FIFO_PRIORITY-1, &cpuset, threadname); UE->is_synchronized = 0; + printf("UE_scan %d\n",UE->UE_scan); + if (UE->UE_scan == 0) { - int ind; - int64_t dl_freq_khz = downlink_frequency[0][0]/1000; - for ( ind=0; - ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); - ind++) { - current_band = eutra_bands[ind].band; - current_type = eutra_bands[ind].frame_type; - LOG_D(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", current_band, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); - if ( eutra_bands[ind].dl_min <= dl_freq_khz && eutra_bands[ind].dl_max >= dl_freq_khz ) { - for (i=0; i<4; i++) - uplink_frequency_offset[CC_id][i] = (eutra_bands[ind].ul_min - eutra_bands[ind].dl_min)*1000; - - break; - } - } - - - AssertFatal( ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]), "Can't find EUTRA band for frequency"); - - UE->frame_parms.eutra_band = current_band; - UE->frame_parms.frame_type = current_type; + get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c index bb3dfe8282..226010a1db 100644 --- a/targets/RT/USER/nr-uesoftmodem.c +++ b/targets/RT/USER/nr-uesoftmodem.c @@ -932,14 +932,14 @@ int main( int argc, char **argv ) { LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); - //init_ul_hopping(frame_parms[CC_id]); - //phy_init_nr_top(frame_parms[CC_id]); - } + get_band(downlink_frequency[CC_id][0], &frame_parms[CC_id]->eutra_band, &uplink_frequency_offset[CC_id][0], &frame_parms[CC_id]->frame_type); - for (CC_id=0; CC_idprach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->frame_type); - // N_ZC = (prach_fmt <4)?839:139; + //init_ul_hopping(frame_parms[CC_id]); + //phy_init_nr_top(frame_parms[CC_id]); + + //init prach for openair1 test + // prach_fmt = get_prach_fmt(frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->frame_type); + // N_ZC = (prach_fmt <4)?839:139; } NB_UE_INST=1; From 0d91083eadc4a35e4a7370db03ab4a9f32468270 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 22 Mar 2019 17:40:47 +0100 Subject: [PATCH 054/117] trying to harmonize the nr_bandtable --- openair1/PHY/INIT/nr_parms.c | 83 +++++++++++++++-------------- openair1/PHY/defs_nr_common.h | 20 +++---- openair2/LAYER2/NR_MAC_gNB/config.c | 56 ++----------------- targets/RT/USER/nr-ue.c | 44 ++------------- 4 files changed, 62 insertions(+), 141 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index 7fee692f08..095101fb89 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -302,39 +302,39 @@ void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp) } -static const eutra_band_t eutra_bands[] = { - {1, 1920000, 1980000, 2110000, 2170000, FDD}, - {2, 1850000, 1910000, 1930000, 1990000, FDD}, - {3, 1710000, 1785000, 1805000, 1880000, FDD}, - {5, 824000, 849000, 869000, 894000, FDD}, - {7, 2500000, 2570000, 2620000, 2690000, FDD}, - {8, 880000, 915000, 925000, 960000, FDD}, - {12, 698000, 716000, 728000, 746000, FDD}, - {20, 832000, 862000, 791000, 821000, FDD}, - {25, 1850000, 1915000, 1930000, 1995000, FDD}, - {28, 703000, 758000, 758000, 813000, FDD}, - {34, 2010000, 2025000, 2010000, 2025000, TDD}, - {38, 2570000, 2620000, 2570000, 2630000, TDD}, - {39, 1880000, 1920000, 1880000, 1920000, TDD}, - {40, 2300000, 2400000, 2300000, 2400000, TDD}, - {41, 2496000, 2690000, 2496000, 2690000, TDD}, - {50, 1432000, 1517000, 1432000, 1517000, TDD}, - {51, 1427000, 1432000, 1427000, 1432000, TDD}, - {66, 1710000, 1780000, 2110000, 2200000, FDD}, - {70, 1695000, 1710000, 1995000, 2020000, FDD}, - {71, 663000, 698000, 617000, 652000, FDD}, - {74, 1427000, 1470000, 1475000, 1518000, FDD}, - {75, 000, 000, 1432000, 1517000, FDD}, - {76, 000, 000, 1427000, 1432000, FDD}, - {77, 3300000, 4200000, 3300000, 4200000, TDD}, - {78, 3300000, 3800000, 3300000, 3800000, TDD}, - {79, 4400000, 5000000, 4400000, 5000000, TDD}, - {80, 1710000, 1785000, 000, 000, FDD}, - {81, 860000, 915000, 000, 000, FDD}, - {82, 832000, 862000, 000, 000, FDD}, - {83, 703000, 748000, 000, 000, FDD}, - {84, 1920000, 1980000, 000, 000, FDD}, - {86, 1710000, 1785000, 000, 000, FDD} +nr_bandentry_t nr_bandtable[] = { + {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, + {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, + {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, + {5, 824000, 849000, 869000, 894000, 20, 173800}, + {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, + {8, 880000, 915000, 925000, 960000, 20, 185000}, + {12, 698000, 716000, 728000, 746000, 20, 145800}, + {20, 832000, 862000, 791000, 821000, 20, 158200}, + {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, + {28, 703000, 758000, 758000, 813000, 20, 151600}, + {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, + {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, + {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, + {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, + {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, + {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, + {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, + {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, + {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, + {71, 663000, 698000, 617000, 652000, 20, 123400}, + {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, + {75, 000, 000, 1432000, 1517000, 20, 286400}, + {76, 000, 000, 1427000, 1432000, 20, 285400}, + {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, + {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, + {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, + {80, 1710000, 1785000, 000, 000, 20, 342000}, + {81, 860000, 915000, 000, 000, 20, 176000}, + {82, 832000, 862000, 000, 000, 20, 166400}, + {83, 703000, 748000, 000, 000, 20, 140600}, + {84, 1920000, 1980000, 000, 000, 20, 384000}, + {86, 1710000, 1785000, 000, 000, 20, 342000} }; int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { @@ -342,14 +342,17 @@ int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *cu int ind; int64_t dl_freq_khz = downlink_frequency/1000; for ( ind=0; - ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); + ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); ind++) { - *current_band = eutra_bands[ind].band; - *current_type = eutra_bands[ind].frame_type; - LOG_I(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", ind, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); + *current_band = nr_bandtable[ind].band; + LOG_I(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); - if ( eutra_bands[ind].dl_min <= dl_freq_khz && eutra_bands[ind].dl_max >= dl_freq_khz ) { - *current_offset = (eutra_bands[ind].ul_min - eutra_bands[ind].dl_min)*1000; + if ( nr_bandtable[ind].dl_min <= dl_freq_khz && nr_bandtable[ind].dl_max >= dl_freq_khz ) { + *current_offset = (nr_bandtable[ind].ul_min - nr_bandtable[ind].dl_min)*1000; + if (*current_offset == 0) + *current_type = TDD; + else + *current_type = FDD; LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); @@ -357,7 +360,7 @@ int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *cu } } - if( ind == sizeof(eutra_bands) / sizeof(eutra_bands[0])) { + if( ind == sizeof(nr_bandtable) / sizeof(nr_bandtable[0])) { LOG_E(PHY,"Can't find EUTRA band for frequency %d\n", downlink_frequency); return(-1); } diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index c09566c67e..605ce8c4c8 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -324,18 +324,20 @@ typedef struct NR_DL_FRAME_PARMS { #define KHz (1000UL) #define MHz (1000*KHz) -typedef struct eutra_band_s { +typedef struct nr_bandentry_s { int16_t band; - uint32_t ul_min; - uint32_t ul_max; - uint32_t dl_min; - uint32_t dl_max; - lte_frame_type_t frame_type; -} eutra_band_t; + uint64_t ul_min; + uint64_t ul_max; + uint64_t dl_min; + uint64_t dl_max; + uint64_t N_OFFs_DL; + uint64_t step_size; +} nr_bandentry_t; typedef struct band_info_s { int nbands; - eutra_band_t band_info[100]; -} band_info_t; + nr_bandentry_t band_info[100]; +} nr_band_info_t; + #endif diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 12d01981d2..1e1258e089 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -49,59 +49,9 @@ extern RAN_CONTEXT_t RC; extern void mac_top_init_gNB(void); extern uint8_t nfapi_mode; -int32_t **rxdata; -int32_t **txdata; - -typedef struct nr_bandentry_s { - int16_t band; - uint64_t ul_min; - uint64_t ul_max; - uint64_t dl_min; - uint64_t dl_max; - uint64_t N_OFFs_DL; - uint64_t step_size; -} nr_bandentry_t; - -typedef struct band_info_s { - int nbands; - nr_bandentry_t band_info[100]; -} nr_band_info_t; - -static const nr_bandentry_t nr_bandtable[] = { - {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, - {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, - {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, - {5, 824000, 849000, 869000, 894000, 20, 173800}, - {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, - {8, 880000, 915000, 925000, 960000, 20, 185000}, - {12, 698000, 716000, 728000, 746000, 20, 145800}, - {20, 832000, 862000, 791000, 821000, 20, 158200}, - {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, - {28, 703000, 758000, 758000, 813000, 20, 151600}, - {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, - {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, - {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, - {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, - {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, - {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, - {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, - {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, - {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, - {71, 663000, 698000, 617000, 652000, 20, 123400}, - {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, - {75, 000, 000, 1432000, 1517000, 20, 286400}, - {76, 000, 000, 1427000, 1432000, 20, 285400}, - {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, - {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, - {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, - {80, 1710000, 1785000, 000, 000, 20, 342000}, - {81, 860000, 915000, 000, 000, 20, 176000}, - {82, 832000, 862000, 000, 000, 20, 166400}, - {83, 703000, 748000, 000, 000, 20, 140600}, - {84, 1920000, 1980000, 000, 000, 20, 384000}, - {86, 1710000, 1785000, 000, 000, 20, 342000} -}; - +//int32_t **rxdata; +//int32_t **txdata; +extern nr_bandentry_t *nr_bandtable; uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw) { diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c index a4afdcd6b6..362300d4d7 100644 --- a/targets/RT/USER/nr-ue.c +++ b/targets/RT/USER/nr-ue.c @@ -157,43 +157,6 @@ int32_t **txdata; #endif -band_info_t bands_to_scan; - -static const eutra_band_t eutra_bands[] = { - {1, 1920000, 1980000, 2110000, 2170000, FDD}, - {2, 1850000, 1910000, 1930000, 1990000, FDD}, - {3, 1710000, 1785000, 1805000, 1880000, FDD}, - {5, 824000, 849000, 869000, 894000, FDD}, - {7, 2500000, 2570000, 2620000, 2690000, FDD}, - {8, 880000, 915000, 925000, 960000, FDD}, - {12, 698000, 716000, 728000, 746000, FDD}, - {20, 832000, 862000, 791000, 821000, FDD}, - {25, 1850000, 1915000, 1930000, 1995000, FDD}, - {28, 703000, 758000, 758000, 813000, FDD}, - {34, 2010000, 2025000, 2010000, 2025000, TDD}, - {38, 2570000, 2620000, 2570000, 2630000, TDD}, - {39, 1880000, 1920000, 1880000, 1920000, TDD}, - {40, 2300000, 2400000, 2300000, 2400000, TDD}, - {41, 2496000, 2690000, 2496000, 2690000, TDD}, - {50, 1432000, 1517000, 1432000, 1517000, TDD}, - {51, 1427000, 1432000, 1427000, 1432000, TDD}, - {66, 1710000, 1780000, 2110000, 2200000, FDD}, - {70, 1695000, 1710000, 1995000, 2020000, FDD}, - {71, 663000, 698000, 617000, 652000, FDD}, - {74, 1427000, 1470000, 1475000, 1518000, FDD}, - {75, 000, 000, 1432000, 1517000, FDD}, - {76, 000, 000, 1427000, 1432000, FDD}, - {77, 3300000, 4200000, 3300000, 4200000, TDD}, - {78, 3300000, 3800000, 3300000, 3800000, TDD}, - {79, 4400000, 5000000, 4400000, 5000000, TDD}, - {80, 1710000, 1785000, 000, 000, FDD}, - {81, 860000, 915000, 000, 000, FDD}, - {82, 832000, 862000, 000, 000, FDD}, - {83, 703000, 748000, 000, 000, FDD}, - {84, 1920000, 1980000, 000, 000, FDD}, - {86, 1710000, 1785000, 000, 000, FDD} -}; - PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, uint8_t abstraction_flag) @@ -364,7 +327,8 @@ static void *UE_thread_synch(void *arg) { sync_mode = pbch; } else { current_band=0; - + LOG_E(PHY,"Fixme!\n"); + /* for (i=0; irf_map.card].rx_num_channels; i++) { downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[CC_id].dl_min; uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = @@ -374,6 +338,7 @@ static void *UE_thread_synch(void *arg) { downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; } + */ } // AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); @@ -388,6 +353,7 @@ static void *UE_thread_synch(void *arg) { AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); switch (sync_mode) { + /* case pss: LOG_I(PHY,"[SCHED][UE] Scanning band %d (%d), freq %u\n",bands_to_scan.band_info[current_band].band, current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); //lte_sync_timefreq(UE,current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); @@ -416,7 +382,7 @@ static void *UE_thread_synch(void *arg) { } break; - + */ case pbch: #if DISABLE_LOG_X printf("[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); From 14ae2b54bd1aa8e0ba2b53d6f7f50c8f6a73a65a Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 25 Mar 2019 09:50:03 +0100 Subject: [PATCH 055/117] renaming band_info_s ton nr_band_info_s to avoid confusion with LTE --- openair1/PHY/defs_nr_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 605ce8c4c8..0c2f8771ec 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -334,7 +334,7 @@ typedef struct nr_bandentry_s { uint64_t step_size; } nr_bandentry_t; -typedef struct band_info_s { +typedef struct nr_band_info_s { int nbands; nr_bandentry_t band_info[100]; } nr_band_info_t; From 52a142d0df66c46abdedcca9c75f2e011ba8a282 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 26 Mar 2019 09:39:11 +0100 Subject: [PATCH 056/117] bugfix in pbch correlation --- .../PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c | 13 +++++-------- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 1 + openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) 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 f6fd1f28f2..917734f8ec 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -36,6 +36,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned char symbol, + int dmrss, NR_UE_SSB *current_ssb) { int pilot[200] __attribute__((aligned(16))); @@ -44,7 +45,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, unsigned int pilot_cnt; int16_t ch[2],*pil,*rxF; int symbol_offset; - int dmrss; + uint8_t nushift; uint8_t ssb_index=current_ssb->i_ssb; @@ -56,13 +57,9 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, unsigned int ssb_offset = ue->frame_parms.first_carrier_offset + ue->frame_parms.ssb_start_subcarrier; if (ssb_offset>= ue->frame_parms.ofdm_symbol_size) ssb_offset-=ue->frame_parms.ofdm_symbol_size; - if (ue->is_synchronized ==0 ) dmrss = symbol-1; - else dmrss = symbol-5; - - AssertFatal((symbol > 0 && symbol < 4 && ue->is_synchronized == 0) || - (symbol > 4 && symbol < 8 && ue->is_synchronized == 1), - "symbol %d is illegal for PBCH DM-RS (is_synchronized %d)\n", - symbol,ue->is_synchronized); + AssertFatal(dmrss >= 0 && dmrss < 3, + "symbol %d is illegal for PBCH DM-RS \n", + dmrss); symbol_offset = ue->frame_parms.ofdm_symbol_size*symbol; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 1ec9cec96f..29400bbdc7 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -54,6 +54,7 @@ int nr_pbch_dmrs_correlation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned char symbol, + int dmrss, NR_UE_SSB *current_ssb); int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 62dad0c027..0e0676b972 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -130,7 +130,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #endif // computing correlation between received DMRS symbols and transmitted sequence for current i_ssb and n_hf for(int i=pbch_initial_symbol; idlsch_channel_estimation_stats); #endif From a3049674c6494fd3c9cd35623d960d6a91b672f4 Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Tue, 26 Mar 2019 10:27:12 +0100 Subject: [PATCH 057/117] warning fixed in get_band --- openair1/PHY/INIT/nr_parms.c | 10 +++++----- openair1/PHY/INIT/phy_init.h | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index 095101fb89..bdcf562e6a 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -337,13 +337,14 @@ nr_bandentry_t nr_bandtable[] = { {86, 1710000, 1785000, 000, 000, 20, 342000} }; -int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { +void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { int ind; int64_t dl_freq_khz = downlink_frequency/1000; for ( ind=0; ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); ind++) { + *current_band = nr_bandtable[ind].band; LOG_I(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); @@ -360,9 +361,8 @@ int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *cu } } - if( ind == sizeof(nr_bandtable) / sizeof(nr_bandtable[0])) { - LOG_E(PHY,"Can't find EUTRA band for frequency %d\n", downlink_frequency); - return(-1); - } + AssertFatal(ind != (sizeof(nr_bandtable) / sizeof(nr_bandtable[0])), + "Can't find EUTRA band for frequency %d\n", downlink_frequency); + } diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h index f500375e4b..bc92d0939e 100644 --- a/openair1/PHY/INIT/phy_init.h +++ b/openair1/PHY/INIT/phy_init.h @@ -391,7 +391,7 @@ void init_nr_transport(PHY_VARS_gNB *gNB); void init_dfts(void); -int get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); +void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); /** @} */ diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 652158605b..1416905696 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -154,7 +154,7 @@ int main(int argc, char **argv) int pbch_tx_ant; int N_RB_DL=273,mu=1; - uint64_t ssb_pattern = 0; + uint64_t ssb_pattern = 0x01; unsigned char frame_type = 0; unsigned char pbch_phase = 0; From f421e730067516fde2fd9f22c1fabbe0049a2c09 Mon Sep 17 00:00:00 2001 From: Hongzhi Wang Date: Tue, 26 Mar 2019 11:47:31 +0100 Subject: [PATCH 058/117] Adding channel compensation dual stream correlation and layer demapping for nr IA decoder --- openair1/PHY/INIT/nr_init_ue.c | 9 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 1036 +++++++++++++---- .../nr_dlsch_llr_computation.c | 52 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 59 +- openair1/PHY/defs_nr_UE.h | 2 + 5 files changed, 899 insertions(+), 259 deletions(-) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index a150717e42..0b2daa7da3 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -592,7 +592,8 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c AssertFatal( pdsch, "pdsch==0" ); pdsch->pmi_ext = (uint8_t*)malloc16_clear( fp->N_RB_DL ); - pdsch->llr[0] = (int16_t*)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); + pdsch->llr[0] = (int16_t*)malloc16_clear( (8*(3*8*6144))*sizeof(int16_t) ); + pdsch->layer_llr[0] = (int16_t*)malloc16_clear( (8*(3*8*6144))*sizeof(int16_t) ); pdsch->llr128 = (int16_t**)malloc16_clear( sizeof(int16_t*) ); // FIXME! no further allocation for (int16_t*)pdsch->llr128 !!! expect SIGSEGV // FK, 11-3-2015: this is only as a temporary pointer, no memory is stored there @@ -761,7 +762,8 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, for (th_id=0; th_idllr_shifts = (uint8_t*)malloc16_clear(7*2*fp->N_RB_DL*12); (*pdsch_vars_th)[th_id][eNB_id]->llr_shifts_p = (*pdsch_vars_th)[0][eNB_id]->llr_shifts; - (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*((3*8*8448)+12))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->layer_llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); (*pdsch_vars_th)[th_id][eNB_id]->llr128_2ndstream = (int16_t**)malloc16_clear( sizeof(int16_t*) ); (*pdsch_vars_th)[th_id][eNB_id]->rho = (int32_t**)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) ); } @@ -882,7 +884,8 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, if (abstraction_flag == 0) { for (th_id=0; th_idllr[1] = (int16_t*)malloc16_clear( (8*((3*8*8448)+12))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); + (*pdsch_vars_th)[th_id][eNB_id]->layer_llr[1] = (int16_t*)malloc16_clear( (8*(3*8*8448))*sizeof(int16_t) ); } } else { //abstraction == 1 diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index ca0aa50d0e..ce6c8fc9e9 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -131,11 +131,15 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, unsigned short nb_rb_pdsch = 50; int16_t *pllr_symbol_cw0; int16_t *pllr_symbol_cw1; + int16_t *pllr_symbol_layer0; + int16_t *pllr_symbol_layer1; //int16_t *pllr_symbol_cw0_deint; //int16_t *pllr_symbol_cw1_deint; uint32_t llr_offset_symbol; //uint16_t bundle_L = 2; uint8_t l0 =2; + uint16_t n_tx=1, n_rx=1; + int32_t median[16]; switch (type) { case SI_PDSCH: @@ -279,7 +283,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #ifdef DEBUG_HARQ printf("Demod dlsch0_harq->pmi_alloc %d\n", dlsch0_harq->pmi_alloc); #endif -#if 0 + if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) { #ifdef DEBUG_DLSCH_MOD LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]); @@ -288,7 +292,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #if UE_TIMING_TRACE start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, @@ -296,6 +300,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, @@ -307,10 +313,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, printf("\n"); #endif - if (rx_type >= rx_IC_single_stream) { if (eNB_id_in_connected_eNB) // we are in TM5 - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id_i], pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, @@ -318,12 +323,14 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id_i]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, dlsch0_harq->mimo_mode); else - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, + nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, @@ -331,15 +338,14 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id_i]->pmi_ext, rballoc, symbol, + start_rb, + nb_rb_pdsch, nr_tti_rx, ue->high_speed_flag, frame_parms, dlsch0_harq->mimo_mode); } - } else - -#endif - if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0 + } else if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0 //printf("start nr dlsch extract nr_tti_rx %d thread id %d \n", nr_tti_rx, ue->current_thread_id[nr_tti_rx]); nb_rb = nr_dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], @@ -418,8 +424,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #if UE_TIMING_TRACE start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif - aatx = frame_parms->nb_antenna_ports_eNB; - aarx = frame_parms->nb_antennas_rx; + n_tx = frame_parms->nb_antenna_ports_eNB; + n_rx = frame_parms->nb_antennas_rx; + nb_re= (symbol==l0)? (nb_rb*6):(nb_rb*12); nr_dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, @@ -466,36 +473,29 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, avgs = cmax(avgs,avg[(aatx<<1)+aarx]); pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1; - }/* + } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { - dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext, - frame_parms, - pdsch_vars[eNB_id]->pmi_ext, - avg_0, - avg_1, - symbol, - nb_rb, - dlsch0_harq->mimo_mode); + nr_dlsch_channel_level_median(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + median, + n_tx, + n_rx, + 2*nb_re,// subcarriers Re Im + 0); - LOG_D(PHY,"Channel Level TM34 avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0], - avg_1[0], rx_type, rx_standard, dlsch_demod_shift); - if (rx_type>rx_standard) { - avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; - avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; - pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); - pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); - // printf("dlsch_demod_shift %d\n", dlsch_demod_shift); - } - else { - avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift; - avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift; - pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); - pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); - } - } + for (aatx = 0; aatx < n_tx; ++aatx) + { + for (aarx = 0; aarx < n_rx; ++aarx) + { + avgs = cmax(avgs, median[aatx*n_rx + aarx]); + } + } + + pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1; // this might need to be tuned + + }/* else if (dlsch0_harq->mimo_moden_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext, @@ -629,22 +629,20 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, }*/ } -#if 0 else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ - dlsch_channel_compensation_TM34(frame_parms, - pdsch_vars[eNB_id], - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - dlsch1_harq->Qm, - harq_pid, - dlsch0_harq->round, - dlsch0_harq->mimo_mode, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh0, - pdsch_vars[eNB_id]->log2_maxh1); + nr_dlsch_channel_compensation_core(pdsch_vars[eNB_id]->rxdataF_ext, + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + pdsch_vars[eNB_id]->rxdataF_comp0, //rxdataF_comp + NULL, + n_tx, + n_rx, + dlsch0_harq->Qm, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, // subcarriers Re Im + 0); // we start from the beginning of the vector /* if (symbol == 5) { write_output("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM write_output("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 @@ -652,22 +650,23 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, write_output("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM } */ // compute correlation between signal and interference channels (rho12 and rho21) - dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22 - symbol, - nb_rb, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->log2_maxh0); + nr_dlsch_dual_stream_correlation_core(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + n_tx, + n_rx, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, + 0); //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] ); - //to be optimized (just take complex conjugate) - dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21 - symbol, - nb_rb, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->log2_maxh1); + nr_dlsch_dual_stream_correlation_core(&(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + n_tx, + n_rx, + pdsch_vars[eNB_id]->log2_maxh, + 2*nb_re, + 0); // printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext ); //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh); /* if (symbol == 5) { @@ -677,105 +676,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, write_output("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM } */ - } else if (dlsch0_harq->mimo_moden_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->pmi_ext, - frame_parms, - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - dlsch0_harq->dl_power_off); - - for (rb=0; rbpmi_ext[rb]) { - case 0: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=1; - break; - case 1: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=0; - break; - case 2: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=3; - break; - case 3: - pdsch_vars[eNB_id_i]->pmi_ext[rb]=2; - break; - } - // if (rb==0) - // printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]); - } - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext, - pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, - pdsch_vars[eNB_id_i]->dl_ch_mag0, - pdsch_vars[eNB_id_i]->dl_ch_magb0, - pdsch_vars[eNB_id_i]->rxdataF_comp0, - pdsch_vars[eNB_id_i]->pmi_ext, - frame_parms, - measurements, - eNB_id_i, - symbol, - i_mod, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - dlsch0_harq->dl_power_off); -#ifdef DEBUG_PHY - if (symbol==5) { - write_output("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); - write_output("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); - } -#endif - dlsch_dual_stream_correlation(frame_parms, - symbol, - nb_rb, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->log2_maxh); - } else if (dlsch0_harq->dl_power_off==1) { - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->pmi_ext, - frame_parms, - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - nb_rb, - pdsch_vars[eNB_id]->log2_maxh, - 1); - - } - - - } else if (dlsch0_harq->mimo_mode==TM7) { //TM7 - - nr_dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL, - frame_parms, - symbol, - first_symbol_flag, - get_Qm(dlsch0_harq->mcs), - nb_rb, - //9, - pdsch_vars[eNB_id]->log2_maxh, - measurements); // log2_maxh+I0_shift - } -#endif + } #if UE_TIMING_TRACE stop_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); @@ -790,39 +691,29 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif -#if 0 if (frame_parms->nb_antennas_rx > 1) { if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ // TM3 or TM4 - if (frame_parms->nb_antenna_ports_eNB == 2) { - dlsch_detection_mrc_TM34(frame_parms, - pdsch_vars[eNB_id], - harq_pid, - dlsch0_harq->round, - symbol, - nb_rb, - 1); + nr_dlsch_detection_mrc_core(pdsch_vars[eNB_id]->rxdataF_comp0, + NULL, + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + NULL, + NULL, + n_tx, + n_rx, + 2*nb_re, + 0); /* if (symbol == 5) { write_output("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM write_output("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 } */ - } - } else { - dlsch_detection_mrc(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id_i]->rxdataF_comp0, - pdsch_vars[eNB_id]->rho, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id_i]->dl_ch_mag0, - pdsch_vars[eNB_id_i]->dl_ch_magb0, - symbol, - nb_rb, - rx_type==rx_IC_single_stream); } } +#if 0 // printf("Combining"); if ((dlsch0_harq->mimo_mode == SISO) || ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) && @@ -878,12 +769,15 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol-1]; //pllr_symbol_cw0_deint = (int8_t*)pdsch_vars[eNB_id]->llr[0]; //pllr_symbol_cw1_deint = (int8_t*)pdsch_vars[eNB_id]->llr[1]; + pllr_symbol_layer0 = pdsch_vars[eNB_id]->layer_llr[0]; + pllr_symbol_layer1 = pdsch_vars[eNB_id]->layer_llr[1]; + pllr_symbol_layer0 += llr_offset_symbol; + pllr_symbol_layer1 += llr_offset_symbol; pllr_symbol_cw0 = pdsch_vars[eNB_id]->llr[0]; pllr_symbol_cw1 = pdsch_vars[eNB_id]->llr[1]; pllr_symbol_cw0 += llr_offset_symbol; pllr_symbol_cw1 += llr_offset_symbol; - nb_re= (symbol==l0)? (nb_rb*6):(nb_rb*12); pdsch_vars[eNB_id]->llr_offset[symbol] = nb_re*dlsch0_harq->Qm + llr_offset_symbol; /*LOG_I(PHY,"compute LLRs [symbol %d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %x @LLR Buff(symb) %x\n", @@ -929,7 +823,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, rxdataF_comp_ptr, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -938,7 +832,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -950,7 +844,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -960,7 +854,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -972,7 +866,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -982,7 +876,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1015,7 +909,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1025,7 +919,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1038,7 +932,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1049,7 +943,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1062,7 +956,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1073,7 +967,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1108,7 +1002,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1118,7 +1012,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0,//i pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1131,7 +1025,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->layer_llr[0], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); @@ -1142,7 +1036,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->layer_llr[1], symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); @@ -1155,7 +1049,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, - (int16_t*)pllr_symbol_cw0, + (int16_t*)pllr_symbol_layer0, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); @@ -1166,7 +1060,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pllr_symbol_cw1, + pllr_symbol_layer1, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); @@ -1222,6 +1116,13 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, //nr_dlsch_deinterleaving(symbol,bundle_L,(int16_t*)pllr_symbol_cw0,(int16_t*)pllr_symbol_cw0_deint, nb_rb_pdsch); + if (rx_type==rx_IC_dual_stream) { + nr_dlsch_layer_demapping(pdsch_vars[eNB_id]->llr, + dlsch[0]->harq_processes[harq_pid]->Nl, + dlsch[0]->harq_processes[harq_pid]->G, + pdsch_vars[eNB_id]->layer_llr); + } + #if UE_TIMING_TRACE stop_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #if DISABLE_LOG_X @@ -1382,10 +1283,10 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, // get channel amplitude if not QPSK mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); - mmtmpD0 = _mm_srai_epi32(mmtmpD0,(output_shift-2)); + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); - mmtmpD1 = _mm_srai_epi32(mmtmpD1,(output_shift-2)); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); @@ -1793,6 +1694,209 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, #endif } +void nr_dlsch_channel_compensation_core(int **rxdataF_ext, + int **dl_ch_estimates_ext, + int **dl_ch_mag, + int **dl_ch_magb, + int **rxdataF_comp, + int **rho, + unsigned char n_tx, + unsigned char n_rx, + unsigned char mod_order, + unsigned char output_shift, + int length, + int start_point) + +{ + + unsigned short ii; + int length_mod8 = 0; + int length2; + __m128i *dl_ch128,*dl_ch_mag128,*dl_ch_mag128b, *dl_ch128_2, *rxdataF128,*rxdataF_comp128,*rho128; + __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b; + int aatx = 0, aarx = 0; + + for (aatx=0; aatx 1 ? n_rx : 2; + + dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point]; + dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point]; + dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point]; + rxdataF128 = (__m128i *)&rxdataF_ext[aarx][start_point]; + rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point]; + + length_mod8 = length&7; + if (length_mod8 == 0){ + length2 = length>>3; + + for (ii=0; ii2) { + // get channel amplitude if not QPSK + + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + + mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + + mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); + + // store channel magnitude here in a new field of dlsch + + dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); + dl_ch_mag128b[0] = dl_ch_mag128[0]; + dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128); + dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1); + //print_ints("Re(ch):",(int16_t*)&mmtmpD0); + //print_shorts("QAM_amp:",(int16_t*)&QAM_amp128); + //print_shorts("mag:",(int16_t*)&dl_ch_mag128[0]); + dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0); + dl_ch_mag128b[1] = dl_ch_mag128[1]; + dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128); + dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1); + + dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b); + dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1); + + dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b); + dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1); + + } + + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]); + + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + // print_ints("im",&mmtmpD1); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + // print_ints("re(shift)",&mmtmpD0); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + // print_ints("im(shift)",&mmtmpD1); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); + rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + // print_shorts("rx:",rxdataF128); + // print_shorts("ch:",dl_ch128); + // print_shorts("pack:",rxdataF_comp128); + + // multiply by conjugated channel + mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); + // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) + mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); + mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); + mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); + mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); + + rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); + // print_shorts("rx:",rxdataF128+1); + // print_shorts("ch:",dl_ch128+1); + //print_shorts("pack:",rxdataF_comp128+1); + + dl_ch128+=2; + dl_ch_mag128+=2; + dl_ch_mag128b+=2; + rxdataF128+=2; + rxdataF_comp128+=2; + } + }else { + printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n" + "need to adapt the code!\n"); + } + } + } + +/*This part of code makes sense only for processing in 2x2 blocks*/ + if (rho) { + + + for (aarx=0; aarx>3; + + for (ii=0; iisqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a)); - LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol_mod,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); + LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp); ch_amp128 = _mm_set1_epi16(ch_amp); // Q3.13 @@ -1980,6 +2084,389 @@ void nr_dlsch_channel_level(int **dl_ch_estimates_ext, #endif } +void nr_dlsch_channel_level_median(int **dl_ch_estimates_ext, + int32_t *median, + int n_tx, + int n_rx, + int length, + int start_point) +{ + +#if defined(__x86_64__)||defined(__i386__) + + short ii; + int aatx,aarx; + int length2; + int max = 0, min=0; + int norm_pack; + __m128i *dl_ch128, norm128D; + + for (aatx=0; aatx>2; + + for (ii=0;ii max) + max = norm_pack; + if (norm_pack < min) + min = norm_pack; + + dl_ch128+=1; + } + + median[aatx*n_rx + aarx] = (max+min)>>1; + + // printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); + } + } + + _mm_empty(); + _m_empty(); + +#elif defined(__arm__) + + short rb; + unsigned char aatx,aarx,nre=12,symbol_mod; + int32x4_t norm128D; + int16x4_t *dl_ch128; + + for (aatx=0; aatxnb_antenna_ports_eNB; aatx++){ + for (aarx=0; aarxnb_antennas_rx; aarx++) { + max = 0; + min = 0; + norm128D = vdupq_n_s32(0); + + dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*n_rx + aarx][start_point]; + + length_mod8=length&3; + length2 = length>>2; + + for (ii=0;ii max) + max = norm_pack; + if (norm_pack < min) + min = norm_pack; + + dl_ch128+=1; + } + + median[aatx*n_rx + aarx] = (max+min)>>1; + + //printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); + } + } +#endif + +} + +void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, + int **dl_ch_estimates_ext_i, + int **dl_ch_rho_ext, + unsigned char n_tx, + unsigned char n_rx, + unsigned char output_shift, + int length, + int start_point) +{ +#if defined(__x86_64__)||defined(__i386__) + + __m128i *dl_ch128,*dl_ch128i,*dl_ch_rho128,mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3; + unsigned char aarx; + int ii, length2, length_mod8; + + + for (aarx=0; aarx>3; + + for (ii=0; ii1) { + + for (aatx=0; aatx>2; + + for (i=0; i>2; + + for (i=0; i>2; + + for (i=0; i>2; + + for (i=0; i1) { + + for (aatx=0; aatx>2; + + for (i=0; i>2; + + for (i=0; i>2; + + for (i=0; inb_antennas_rx); } +unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, + int **dl_ch_estimates, + int **rxdataF_ext, + int **dl_ch_estimates_ext, + unsigned short pmi, + unsigned char *pmi_ext, + unsigned int *rb_alloc, + unsigned char symbol, + unsigned short start_rb, + unsigned short nb_rb_pdsch, + unsigned char nr_tti_rx, + uint32_t high_speed_flag, + NR_DL_FRAME_PARMS *frame_parms, + MIMO_mode_t mimo_mode) { + + int prb,nb_rb=0; + unsigned short k; + //int prb_off,prb_off2; + int skip_half=0,l;//sss_symb,pss_symb=0,nsymb + int i,aarx; + int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; + int symbol_mod,pilots=0,j=0; + unsigned char *pmi_loc; + + pilots = (symbol==2) ? 1 : 0; //to updated from config + k = frame_parms->first_carrier_offset + 516; //0 + + //nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; + l=symbol; + + for (aarx=0; aarxnb_antennas_rx; aarx++) { + + if (high_speed_flag==1) { + dl_ch0 = &dl_ch_estimates[aarx][symbol*(frame_parms->ofdm_symbol_size)]; + dl_ch1 = &dl_ch_estimates[2+aarx][symbol*(frame_parms->ofdm_symbol_size)]; + } else { + dl_ch0 = &dl_ch_estimates[aarx][0]; + dl_ch1 = &dl_ch_estimates[2+aarx][0]; + } + + pmi_loc = pmi_ext; + + // pointers to extracted RX signals and channel estimates + rxF_ext = &rxdataF_ext[aarx][symbol*(nb_rb_pdsch*12)]; + dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(nb_rb_pdsch*12)]; + dl_ch1_ext = &dl_ch_estimates_ext[2+aarx][symbol*(nb_rb_pdsch*12)]; + + for (prb=0; prbN_RB_DL; prb++) { + skip_half=0; + + if ((frame_parms->N_RB_DL&1) == 0) { // even number of RBs + + // For second half of RBs skip DC carrier + if (k>=frame_parms->ofdm_symbol_size) { + rxF = &rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))]; + k=k-(frame_parms->ofdm_symbol_size); + } + + /* + if (mimo_mode <= PUSCH_PRECODING1) + *pmi_loc = (pmi>>((prb>>2)<<1))&3; + else + *pmi_loc=(pmi>>prb)&1;*/ + + // *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); + // pmi_loc++; + + + if (pilots == 0) { + + memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); + memcpy(dl_ch1_ext,dl_ch1,12*sizeof(int)); + memcpy(rxF_ext,rxF,12*sizeof(int)); + dl_ch0_ext +=12; + dl_ch1_ext +=12; + rxF_ext +=12; + } else { // pilots==1 + j=0; + for (i=0; i<12; i++) { + if ((i&1)!=frame_parms->nushift) { + rxF_ext[j]=rxF[i]; + // printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + dl_ch0_ext[j]=dl_ch0p[i]; + dl_ch1_ext[j++]=dl_ch1p[i]; + } + } + dl_ch0_ext+=6; + dl_ch1_ext+=6; + rxF_ext+=6; + } // pilots==1 + + dl_ch0+=12; + dl_ch1+=12; + rxF+=12; + k+=12; + } + } // for prb + } // for aarx + return(nb_rb/frame_parms->nb_antennas_rx); +} + +void nr_dlsch_layer_demapping(int16_t **llr_cw, + uint8_t Nl, + uint8_t mod_order, + uint16_t length, + int16_t **llr_layers) { + + switch (Nl) { + + case 1: + memcpy((void*)llr_layers[0], (void*)llr_cw[0], (length)*sizeof(int16_t)); + break; + + case 2: + case 3: + case 4: + for (int i=0; i<(length/Nl/mod_order); i++){ + for (int l=0; lN_RB_DL*12)]; - int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rho=(int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)]; + int16_t *rxF=(int16_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; + int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; + int16_t *rho=(int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; int len; - uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; + //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; if (first_symbol_flag == 1) { llr16 = (int16_t*)dlsch_llr; @@ -1152,18 +1152,10 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_qpsk_qpsk_llr: llr is null, symbol %d\n",symbol); - if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) { - // if symbol has pilots - if (frame_parms->nb_antenna_ports_eNB!=1) - // in 2 antenna ports we have 8 REs per symbol per RB - len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3); - else - // for 1 antenna port we have 10 REs per symbol per RB - len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6); - } else { - // symbol has no pilots - len = (nb_rb*12) - pbch_pss_sss_adjust; - } + if (symbol ==2) //to update from config + len = nb_rb*6; + else + len = nb_rb*12; // printf("nr_dlsch_qpsk_qpsk_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust); // printf("qpsk_qpsk: len %d, llr16 %p\n",len,llr16); @@ -2986,14 +2978,14 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t **llr16p) { - int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rho = (int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)]; + int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; + int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; + int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*nb_rb*12)]; + int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*nb_rb*12)]; + int16_t *rho = (int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; int len; - uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; + //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; // first symbol has different structure due to more pilots if (first_symbol_flag == 1) { @@ -3005,18 +2997,10 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_16qam_16qam_llr: llr is null, symbol %d\n",symbol); - if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) { - // if symbol has pilots - if (frame_parms->nb_antenna_ports_eNB!=1) - // in 2 antenna ports we have 8 REs per symbol per RB - len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3); - else - // for 1 antenna port we have 10 REs per symbol per RB - len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6); - } else { - // symbol has no pilots - len = (nb_rb*12) - pbch_pss_sss_adjust; - } + if (symbol ==2) //to update from config + len = nb_rb*6; + else + len = nb_rb*12; // printf("symbol %d: qam16_llr, len %d (llr16 %p)\n",symbol,len,llr16); 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 e8d22ac11c..8e2dbea2d9 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -753,18 +753,20 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, @param high_speed_flag @param frame_parms Pointer to frame descriptor */ -uint16_t dlsch_extract_rbs_dual(int32_t **rxdataF, - int32_t **dl_ch_estimates, - int32_t **rxdataF_ext, - int32_t **dl_ch_estimates_ext, - uint16_t pmi, - uint8_t *pmi_ext, - uint32_t *rb_alloc, - uint8_t symbol, - uint8_t subframe, - uint32_t high_speed_flag, - NR_DL_FRAME_PARMS *frame_parms, - MIMO_mode_t mimo_mode); +unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, + int **dl_ch_estimates, + int **rxdataF_ext, + int **dl_ch_estimates_ext, + unsigned short pmi, + unsigned char *pmi_ext, + unsigned int *rb_alloc, + unsigned char symbol, + unsigned short start_rb, + unsigned short nb_rb_pdsch, + unsigned char nr_tti_rx, + uint32_t high_speed_flag, + NR_DL_FRAME_PARMS *frame_parms, + MIMO_mode_t mimo_mode); /** \fn dlsch_extract_rbs_TM7(int32_t **rxdataF, int32_t **dl_bf_ch_estimates, @@ -826,6 +828,19 @@ void nr_dlsch_channel_compensation(int32_t **rxdataF_ext, uint8_t output_shift, PHY_NR_MEASUREMENTS *phy_measurements); +void nr_dlsch_channel_compensation_core(int **rxdataF_ext, + int **dl_ch_estimates_ext, + int **dl_ch_mag, + int **dl_ch_magb, + int **rxdataF_comp, + int **rho, + unsigned char n_tx, + unsigned char n_rx, + unsigned char mod_order, + unsigned char output_shift, + int length, + int start_point); + void nr_dlsch_deinterleaving(uint8_t symbol, uint16_t L, uint16_t *llr, @@ -881,6 +896,26 @@ void dlsch_channel_level_TM34_meas(int *ch00, int *avg_1, unsigned short nb_rb); +void nr_dlsch_channel_level_median(int **dl_ch_estimates_ext, + int32_t *median, + int n_tx, + int n_rx, + int length, + int start_point); + +void nr_dlsch_detection_mrc_core(int **rxdataF_comp, + int **rxdataF_comp_i, + int **rho, + int **rho_i, + int **dl_ch_mag, + int **dl_ch_magb, + int **dl_ch_mag_i, + int **dl_ch_magb_i, + unsigned char n_tx, + unsigned char n_rx, + int length, + int start_point); + void det_HhH(int32_t *after_mf_00, int32_t *after_mf_01, int32_t *after_mf_10, diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 95381ad560..4b55f920c5 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -510,6 +510,8 @@ typedef struct { /// - first index: ? [0..1] (hard coded) /// - second index: ? [0..1179743] (hard coded) int16_t *llr[2]; + /// Pointers to layer llr vectors (4 layers). + int16_t *layer_llr[4]; /// \f$\log_2(\max|H_i|^2)\f$ int16_t log2_maxh; /// \f$\log_2(\max|H_i|^2)\f$ //this is for TM3-4 layer1 channel compensation From 3554fb9b006f6662e50c84257a0720739fa6fda9 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 26 Mar 2019 13:48:20 +0100 Subject: [PATCH 059/117] adding testcases for smallblocktest --- cmake_targets/autotests/test_case_list.xml | 25 +++++++++++++++++++++- cmake_targets/build_oai | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index 2f66c6af34..aa1db28d75 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1076,7 +1076,30 @@ segmentation fault|assertion|exiting|fatal 3 - + + + execution + shortblocktest Test cases. (Test1: 3 bits), + (Test2: 6 bits) + (Test3: 7 bits) + (Test4: 11 bits) + + + $OPENAIR_DIR/cmake_targets/build_oai + --phy_simulators -c + $OPENAIR_DIR/cmake_targets/autotests/tools/free_mem.bash + + $OPENAIR_DIR/targets/bin/smallblocktest.Rel15 + -l 3 + -l 6 + -l 7 + -l 11 + smallblocktest.test1 smallblocktest.test2 smallblocktest.test3 smallblocktest.test3 + BLER= 0.000000 + segmentation fault|assertion|exiting|fatal + 3 + + execution diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 01ab01f0a7..69aafbc41b 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -696,7 +696,7 @@ function main() { echo_info "Compiling unitary tests simulators" # TODO: fix: dlsim_tm4 pucchsim prachsim pdcchsim pbchsim mbmssim #simlist="dlsim_tm4 dlsim ulsim pucchsim prachsim pdcchsim pbchsim mbmssim" - simlist="dlsim ulsim polartest ldpctest nr_pbchsim nr_dlschsim nr_dlsim" + simlist="dlsim ulsim polartest ldpctest smallblocktest nr_pbchsim nr_dlschsim nr_dlsim" for f in $simlist ; do compilations \ phy_simulators $f \ From dea3125734a40c8263cf6b6a1ea82f4e7152da34 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 26 Mar 2019 14:48:30 +0100 Subject: [PATCH 060/117] moving nr_bandtable back to MAC --- openair1/PHY/INIT/nr_parms.c | 63 ------------------------- openair1/PHY/INIT/phy_init.h | 2 - openair2/LAYER2/NR_MAC_gNB/config.c | 65 +++++++++++++++++++++++++- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 2 + 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index bdcf562e6a..a828804002 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -302,67 +302,4 @@ void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp) } -nr_bandentry_t nr_bandtable[] = { - {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, - {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, - {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, - {5, 824000, 849000, 869000, 894000, 20, 173800}, - {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, - {8, 880000, 915000, 925000, 960000, 20, 185000}, - {12, 698000, 716000, 728000, 746000, 20, 145800}, - {20, 832000, 862000, 791000, 821000, 20, 158200}, - {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, - {28, 703000, 758000, 758000, 813000, 20, 151600}, - {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, - {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, - {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, - {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, - {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, - {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, - {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, - {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, - {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, - {71, 663000, 698000, 617000, 652000, 20, 123400}, - {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, - {75, 000, 000, 1432000, 1517000, 20, 286400}, - {76, 000, 000, 1427000, 1432000, 20, 285400}, - {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, - {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, - {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, - {80, 1710000, 1785000, 000, 000, 20, 342000}, - {81, 860000, 915000, 000, 000, 20, 176000}, - {82, 832000, 862000, 000, 000, 20, 166400}, - {83, 703000, 748000, 000, 000, 20, 140600}, - {84, 1920000, 1980000, 000, 000, 20, 384000}, - {86, 1710000, 1785000, 000, 000, 20, 342000} -}; - -void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { - - int ind; - int64_t dl_freq_khz = downlink_frequency/1000; - for ( ind=0; - ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); - ind++) { - - *current_band = nr_bandtable[ind].band; - LOG_I(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); - - if ( nr_bandtable[ind].dl_min <= dl_freq_khz && nr_bandtable[ind].dl_max >= dl_freq_khz ) { - *current_offset = (nr_bandtable[ind].ul_min - nr_bandtable[ind].dl_min)*1000; - if (*current_offset == 0) - *current_type = TDD; - else - *current_type = FDD; - - LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", - downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); - break; - } - } - - AssertFatal(ind != (sizeof(nr_bandtable) / sizeof(nr_bandtable[0])), - "Can't find EUTRA band for frequency %d\n", downlink_frequency); - -} diff --git a/openair1/PHY/INIT/phy_init.h b/openair1/PHY/INIT/phy_init.h index bc92d0939e..6f9cff07bf 100644 --- a/openair1/PHY/INIT/phy_init.h +++ b/openair1/PHY/INIT/phy_init.h @@ -391,8 +391,6 @@ void init_nr_transport(PHY_VARS_gNB *gNB); void init_dfts(void); -void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); - /** @} */ #endif diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 1e1258e089..d41ff93e9b 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -51,7 +51,70 @@ extern uint8_t nfapi_mode; //int32_t **rxdata; //int32_t **txdata; -extern nr_bandentry_t *nr_bandtable; + +nr_bandentry_t nr_bandtable[] = { + {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, + {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, + {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, + {5, 824000, 849000, 869000, 894000, 20, 173800}, + {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, + {8, 880000, 915000, 925000, 960000, 20, 185000}, + {12, 698000, 716000, 728000, 746000, 20, 145800}, + {20, 832000, 862000, 791000, 821000, 20, 158200}, + {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, + {28, 703000, 758000, 758000, 813000, 20, 151600}, + {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, + {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, + {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, + {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, + {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, + {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, + {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, + {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, + {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, + {71, 663000, 698000, 617000, 652000, 20, 123400}, + {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, + {75, 000, 000, 1432000, 1517000, 20, 286400}, + {76, 000, 000, 1427000, 1432000, 20, 285400}, + {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, + {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, + {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, + {80, 1710000, 1785000, 000, 000, 20, 342000}, + {81, 860000, 915000, 000, 000, 20, 176000}, + {82, 832000, 862000, 000, 000, 20, 166400}, + {83, 703000, 748000, 000, 000, 20, 140600}, + {84, 1920000, 1980000, 000, 000, 20, 384000}, + {86, 1710000, 1785000, 000, 000, 20, 342000} +}; + +void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { + + int ind; + int64_t dl_freq_khz = downlink_frequency/1000; + for ( ind=0; + ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); + ind++) { + + *current_band = nr_bandtable[ind].band; + LOG_I(PHY, "Scanning band %d, dl_min %"PRIu64", ul_min %"PRIu64"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); + + if ( nr_bandtable[ind].dl_min <= dl_freq_khz && nr_bandtable[ind].dl_max >= dl_freq_khz ) { + *current_offset = (nr_bandtable[ind].ul_min - nr_bandtable[ind].dl_min)*1000; + if (*current_offset == 0) + *current_type = TDD; + else + *current_type = FDD; + + LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", + downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); + break; + } + } + + AssertFatal(ind != (sizeof(nr_bandtable) / sizeof(nr_bandtable[0])), + "Can't find EUTRA band for frequency %d\n", downlink_frequency); + +} uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw) { diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index a214b160a2..9c14b84a23 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -102,4 +102,6 @@ int to_absslot(nfapi_nr_config_request_t *cfg,int frame,int slot); int get_symbolsperslot(nfapi_nr_config_request_t *cfg); +void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); + #endif /*__LAYER2_NR_MAC_PROTO_H__*/ From 40b52195fcc4b3dd9a2b192f4e366774bfc7a4e2 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 26 Mar 2019 16:16:34 +0100 Subject: [PATCH 061/117] redefining max number of UEs for memory allocation. Using the PHYSIM macro, different allocations are used for phy_simulators and real-time modem. --- .gitignore | 1 - cmake_targets/CMakeLists.txt | 2 +- openair2/LAYER2/MAC/mac_extern.h | 4 ---- openair2/RRC/LTE/rrc_extern.h | 6 ------ openair2/RRC/NR/nr_rrc_extern.h | 6 ------ targets/COMMON/openairinterface5g_limits.h | 9 ++++++++- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 61d9558916..2adc5d457c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ cmake_targets/log/ -cmake_targets/ran_build/ cmake_targets/*/build/ targets/bin/ diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 79f057c29e..7899c71a7b 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -671,7 +671,7 @@ add_boolean_option(EXMIMO_IOT True "????") add_boolean_option(LOCALIZATION False "???") add_integer_option(MAX_NUM_CCs 1 "????") add_boolean_option(MU_RECEIVER False "????") -add_boolean_option(PHYSIM True "for L1 simulators (dlsim, ulsim, ...)") +add_boolean_option(PHYSIM False "for L1 simulators (dlsim, ulsim, ...)") add_boolean_option(PHY_CONTEXT True "not clear: must remain False for dlsim") add_boolean_option(PHY_EMUL False "not clear: must remain False for dlsim") add_boolean_option(SMBV False "Rohde&Schwarz SMBV100A vector signal generator") diff --git a/openair2/LAYER2/MAC/mac_extern.h b/openair2/LAYER2/MAC/mac_extern.h index ca72882471..825756a095 100644 --- a/openair2/LAYER2/MAC/mac_extern.h +++ b/openair2/LAYER2/MAC/mac_extern.h @@ -58,11 +58,7 @@ extern eNB_DLSCH_INFO eNB_dlsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][MAX_MOBILES -#ifndef PHYSIM -#define NB_INST 1 -#else extern unsigned char NB_INST; -#endif extern unsigned char NB_eNB_INST; extern unsigned char NB_UE_INST; extern unsigned char NB_RN_INST; diff --git a/openair2/RRC/LTE/rrc_extern.h b/openair2/RRC/LTE/rrc_extern.h index 59200fb9cc..68c805dffe 100644 --- a/openair2/RRC/LTE/rrc_extern.h +++ b/openair2/RRC/LTE/rrc_extern.h @@ -44,17 +44,11 @@ extern LogicalChannelConfig_t SRB1_logicalChannelConfig_defaultValue; extern LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue; -#ifndef PHY_EMUL -#ifndef PHYSIM -//#define NB_INST 1 -#else extern unsigned char NB_INST; -#endif extern unsigned char NB_eNB_INST; extern unsigned char NB_UE_INST; extern unsigned short NODE_ID[1]; extern void* bigphys_malloc(int); -#endif //CONSTANTS diff --git a/openair2/RRC/NR/nr_rrc_extern.h b/openair2/RRC/NR/nr_rrc_extern.h index 7509dfc727..a9af422f02 100644 --- a/openair2/RRC/NR/nr_rrc_extern.h +++ b/openair2/RRC/NR/nr_rrc_extern.h @@ -43,17 +43,11 @@ extern LogicalChannelConfig_t SRB1_logicalChannelConfig_defaultValue; extern LogicalChannelConfig_t SRB2_logicalChannelConfig_defaultValue; -#ifndef PHY_EMUL -#ifndef PHYSIM -//#define NB_INST 1 -#else extern unsigned char NB_INST; -#endif extern unsigned char NB_eNB_INST; extern unsigned char NB_UE_INST; extern unsigned short NODE_ID[1]; extern void* bigphys_malloc(int); -#endif //CONSTANTS diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h index d44f0c5601..9645acf4dd 100644 --- a/targets/COMMON/openairinterface5g_limits.h +++ b/targets/COMMON/openairinterface5g_limits.h @@ -1,11 +1,12 @@ #ifndef OPENAIRINTERFACE5G_LIMITS_H_ #define OPENAIRINTERFACE5G_LIMITS_H_ -#if defined(CBMIMO1) || defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706) +#if 1 /*defined(CBMIMO1) || defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706)*/ # define NUMBER_OF_eNB_MAX 1 # define NUMBER_OF_gNB_MAX 1 # define NUMBER_OF_RU_MAX 2 # define NUMBER_OF_NR_RU_MAX 2 +# ifndef PHYSIM # ifndef UE_EXPANSION # define NUMBER_OF_UE_MAX 16 # define NUMBER_OF_NR_UE_MAX 16 @@ -17,6 +18,12 @@ # define NUMBER_OF_CONNECTED_eNB_MAX 1 # define NUMBER_OF_CONNECTED_gNB_MAX 1 # endif +# else +# define NUMBER_OF_UE_MAX 1 +# define NUMBER_OF_NR_UE_MAX 1 +# define NUMBER_OF_CONNECTED_eNB_MAX 1 +# define NUMBER_OF_CONNECTED_gNB_MAX 1 +# endif #else # define NUMBER_OF_eNB_MAX 7 # define NUMBER_OF_gNB_MAX 7 From 97f4ec965ec28cacb9fcbb8526ea86a3817a37e9 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 26 Mar 2019 18:19:36 +0100 Subject: [PATCH 062/117] desparate to get the get_band function to work for all targets --- cmake_targets/CMakeLists.txt | 59 +++----- openair2/LAYER2/NR_MAC_gNB/config.c | 117 ---------------- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 4 + openair2/LAYER2/NR_MAC_gNB/nr_mac_common.c | 148 +++++++++++++++++++++ 4 files changed, 167 insertions(+), 161 deletions(-) create mode 100644 openair2/LAYER2/NR_MAC_gNB/nr_mac_common.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index af9c3edf68..8f11e99a75 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -167,7 +167,7 @@ endif() # set(CMAKE_C_FLAGS - "${CMAKE_C_FLAGS} ${C_FLAGS_PROCESSOR} -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing -rdynamic -funroll-loops -Wno-packed-bitfield-compat -fPIC ") + "${CMAKE_C_FLAGS} ${C_FLAGS_PROCESSOR} -std=gnu99 -Wall -Wstrict-prototypes -fno-strict-aliasing -rdynamic -funroll-loops -Wno-packed-bitfield-compat -fPIC") # add autotools definitions that were maybe used! set(MKVER "'MAKE_VERSION(a,b,c)=((a)*256+(b)*16+c)'") set(CMAKE_C_FLAGS @@ -1575,6 +1575,7 @@ add_library(L2 ${ENB_APP_SRC} ) add_dependencies(L2 rrc_flag s1ap_flag x2_flag) + add_library(MAC_NR ${MAC_NR_SRC} ) @@ -1593,7 +1594,6 @@ add_dependencies(S1AP_LIB nr_rrc_flag s1ap_flag) add_library(L2_UE ${L2_SRC_UE} ${MAC_SRC_UE} - #${MAC_NR_SRC_UE} ) if (NOT ${NOS1}) target_compile_definitions(L2_UE PUBLIC -DPDCP_USE_NETLINK) @@ -1602,44 +1602,13 @@ endif() add_dependencies(L2_UE rrc_flag s1ap_flag x2_flag) add_library( NR_L2_UE - #${L2_SRC_UE} ${NR_L2_SRC_UE} ${MAC_NR_SRC_UE} - #${MAC_SRC_UE} -) - -set ( NR_LTE_UE_REUSE_SRC - ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_sync_timefreq.c - ${OPENAIR1_DIR}/SCHED/phy_procedures_lte_common.c - #${OPENAIR1_DIR}/SCHED_UE/phy_procedures_lte_ue.c - ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c - #${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/pmch_common.c - - #${OPENAIR1_DIR}/PHY/LTE_REFSIG/lte_dl_cell_spec.c - #${OPENAIR1_DIR}/PHY/CODING/lte_segmentation.c - #${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/prach_common.c -# ${OPENAIR1_DIR}/PHY/INIT/lte_init_ue.c - ${OPENAIR1_DIR}/PHY/CODING/crc_byte.c - ${OPENAIR1_DIR}/PHY/CODING/viterbi_lte.c - ${OPENAIR1_DIR}/PHY/CODING/viterbi.c - #${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/phich_common.c - ${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation.c - -# ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c -# ${OPENAIR1_DIR}/PHY/CODING/lte_rate_matching.c - ${OPENAIR1_DIR}/PHY/CODING/ccoding_byte_lte.c - ${OPENAIR1_DIR}/PHY/CODING/ccoding_byte.c - ${OPENAIR1_DIR}/PHY/LTE_REFSIG/lte_gold.c - ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_est_freq_offset.c - ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_dl_channel_estimation.c - ${OPENAIR1_DIR}/PHY/LTE_ESTIMATION/lte_ue_measurements.c - #${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c - #${OPENAIR1_DIR}/PHY/LTE_UE_TRANSPORT/dlsch_llr_computation_avx2.c -) - -add_library( NR_LTE_UE_REUSE_LIB - ${NR_LTE_UE_REUSE_SRC} -) + ) + +add_library( MAC_NR_COMMON + ${OPENAIR2_DIR}/LAYER2/NR_MAC_gNB/nr_mac_common.c + ) include_directories("${OPENAIR2_DIR}/NR_UE_PHY_INTERFACE") include_directories("${OPENAIR2_DIR}/LAYER2/NR_MAC_UE") @@ -2368,7 +2337,7 @@ target_link_libraries (nr-softmodem -Wl,--start-group UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB SCHED_RU_LIB SCHED_NR_LIB PHY_NR PHY PHY_COMMON PHY_RU LFDS GTPV1U SECU_CN SECU_OSA ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} LFDS7 ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} - RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB L2 L2_NR + RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB L2 L2_NR MAC_NR_COMMON NFAPI_COMMON_LIB NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB -Wl,--end-group z dl) @@ -2409,7 +2378,7 @@ target_link_libraries (nr-softmodem-nos1 -Wl,--start-group UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB SCHED_RU_LIB SCHED_NR_LIB PHY_NR PHY PHY_COMMON PHY_RU LFDS GTPV1U SECU_CN SECU_OSA ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} LFDS7 ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ${MIH_LIB} - RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB L2 L2_NR + RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB L2 L2_NR MAC_NR_COMMON NFAPI_COMMON_LIB NFAPI_LIB NFAPI_VNF_LIB NFAPI_PNF_LIB NFAPI_USER_LIB -Wl,--end-group z dl) @@ -2444,7 +2413,7 @@ add_executable(nr-uesoftmodem target_link_libraries (nr-uesoftmodem -Wl,--start-group - RRC_LIB NR_RRC_LIB SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_UE PHY_RU LFDS NR_L2_UE #NR_LTE_UE_REUSE_LIB + RRC_LIB NR_RRC_LIB SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_UE PHY_RU LFDS NR_L2_UE MAC_NR_COMMON ${MSC_LIB} ${RAL_LIB} ${NAS_UE_LIB} ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} LFDS7 ${ATLAS_LIBRARIES} -Wl,--end-group z dl) @@ -2478,7 +2447,7 @@ add_executable(nr-uesoftmodem-nos1 target_link_libraries (nr-uesoftmodem-nos1 -Wl,--start-group - RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_UE PHY_UE PHY_RU LFDS NR_L2_UE + RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB GTPV1U SECU_CN SECU_OSA UTIL HASHTABLE SCTP_CLIENT UDP SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB PHY_COMMON PHY_NR_UE PHY_UE PHY_RU LFDS NR_L2_UE MAC_NR_COMMON ${MSC_LIB} ${RAL_LIB} ${ITTI_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} LFDS7 ${ATLAS_LIBRARIES} -Wl,--end-group z dl) @@ -2555,7 +2524,7 @@ add_executable(nr_dlsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/dlsim.c ${OPENAIR_DIR}/common/utils/backtrace.c ${T_SOURCE}) -target_link_libraries(nr_dlsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR RRC_LIB NR_RRC_LIB CONFIG_LIB L2_NR -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) +target_link_libraries(nr_dlsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_NR -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) @@ -2688,7 +2657,9 @@ L2 L2_NR L2_UE NR_L2_UE -NR_LTE_UE_REUSE_LIB +MAC_NR_COMMON +MAC_NR +MAC_UE_NR CN_UTILS GTPV1U SCTP_CLIENT diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index d41ff93e9b..6954b9507d 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -49,123 +49,6 @@ extern RAN_CONTEXT_t RC; extern void mac_top_init_gNB(void); extern uint8_t nfapi_mode; -//int32_t **rxdata; -//int32_t **txdata; - -nr_bandentry_t nr_bandtable[] = { - {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, - {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, - {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, - {5, 824000, 849000, 869000, 894000, 20, 173800}, - {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, - {8, 880000, 915000, 925000, 960000, 20, 185000}, - {12, 698000, 716000, 728000, 746000, 20, 145800}, - {20, 832000, 862000, 791000, 821000, 20, 158200}, - {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, - {28, 703000, 758000, 758000, 813000, 20, 151600}, - {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, - {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, - {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, - {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, - {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, - {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, - {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, - {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, - {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, - {71, 663000, 698000, 617000, 652000, 20, 123400}, - {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, - {75, 000, 000, 1432000, 1517000, 20, 286400}, - {76, 000, 000, 1427000, 1432000, 20, 285400}, - {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, - {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, - {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, - {80, 1710000, 1785000, 000, 000, 20, 342000}, - {81, 860000, 915000, 000, 000, 20, 176000}, - {82, 832000, 862000, 000, 000, 20, 166400}, - {83, 703000, 748000, 000, 000, 20, 140600}, - {84, 1920000, 1980000, 000, 000, 20, 384000}, - {86, 1710000, 1785000, 000, 000, 20, 342000} -}; - -void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { - - int ind; - int64_t dl_freq_khz = downlink_frequency/1000; - for ( ind=0; - ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); - ind++) { - - *current_band = nr_bandtable[ind].band; - LOG_I(PHY, "Scanning band %d, dl_min %"PRIu64", ul_min %"PRIu64"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); - - if ( nr_bandtable[ind].dl_min <= dl_freq_khz && nr_bandtable[ind].dl_max >= dl_freq_khz ) { - *current_offset = (nr_bandtable[ind].ul_min - nr_bandtable[ind].dl_min)*1000; - if (*current_offset == 0) - *current_type = TDD; - else - *current_type = FDD; - - LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", - downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); - break; - } - } - - AssertFatal(ind != (sizeof(nr_bandtable) / sizeof(nr_bandtable[0])), - "Can't find EUTRA band for frequency %d\n", downlink_frequency); - -} - -uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw) -{ - - uint64_t dl_CarrierFreq_by_1k = dl_CarrierFreq / 1000; - int bw_kHz = bw / 1000; - - int i; - - LOG_I(MAC,"Searching for nr band %d DL Carrier frequency %llu bw %u\n",nr_bandP,(long long unsigned int)dl_CarrierFreq,bw); - AssertFatal(nr_bandP < 86, "nr_band %d > 86\n", nr_bandP); - for (i = 0; i < 30 && nr_bandtable[i].band != nr_bandP; i++); - - AssertFatal(dl_CarrierFreq_by_1k >= nr_bandtable[i].dl_min, - "Band %d, bw %u : DL carrier frequency %llu kHz < %llu\n", - nr_bandP, bw, (long long unsigned int)dl_CarrierFreq_by_1k, - (long long unsigned int)nr_bandtable[i].dl_min); - AssertFatal(dl_CarrierFreq_by_1k <= - (nr_bandtable[i].dl_max - bw_kHz), - "Band %d, dl_CarrierFreq %llu bw %u: DL carrier frequency %llu kHz > %llu\n", - nr_bandP, (long long unsigned int)dl_CarrierFreq,bw, (long long unsigned int)dl_CarrierFreq_by_1k, - (long long unsigned int)(nr_bandtable[i].dl_max - bw_kHz)); - - int deltaFglobal; - - if (dl_CarrierFreq < 3e9) deltaFglobal = 5; - else deltaFglobal = 15; - - // This is equation before Table 5.4.2.1-1 in 38101-1-f30 - // F_REF=F_REF_Offs + deltaF_Global(N_REF-NREF_REF_Offs) - return (((dl_CarrierFreq_by_1k - nr_bandtable[i].dl_min)/deltaFglobal) + - nr_bandtable[i].N_OFFs_DL); -} - - -uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn) -{ - - int i; - int deltaFglobal; - - if (nr_bandP < 77 || nr_bandP > 79) deltaFglobal = 5; - else deltaFglobal = 15; - - AssertFatal(nr_bandP < 87, "nr_band %d > 86\n", nr_bandP); - for (i = 0; i < 31 && nr_bandtable[i].band != nr_bandP; i++); - AssertFatal(dl_nrarfcn>=nr_bandtable[i].N_OFFs_DL,"dl_nrarfcn %u < N_OFFs_DL %llu\n",dl_nrarfcn, (long long unsigned int)nr_bandtable[i].N_OFFs_DL); - - return 1000*(nr_bandtable[i].dl_min + (dl_nrarfcn - nr_bandtable[i].N_OFFs_DL) * deltaFglobal); - -} void config_nr_mib(int Mod_idP, int CC_idP, diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 9c14b84a23..6f0bd9d595 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -104,4 +104,8 @@ int get_symbolsperslot(nfapi_nr_config_request_t *cfg); void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type); +uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn); + +uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw); + #endif /*__LAYER2_NR_MAC_PROTO_H__*/ diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_common.c b/openair2/LAYER2/NR_MAC_gNB/nr_mac_common.c new file mode 100644 index 0000000000..f2c2e437cc --- /dev/null +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_common.c @@ -0,0 +1,148 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file nr_mac_common.c + * \brief Common MAC functions for NR UE and gNB + * \author Florian Kaltenberger and Raymond Knopp + * \date 2019 + * \version 0.1 + * \company Eurecom, NTUST + * \email: florian.kalteberger@eurecom.fr, raymond.knopp@eurecom.fr + * @ingroup _mac + + */ + +#include "LAYER2/NR_MAC_gNB/mac_proto.h" + +nr_bandentry_t nr_bandtable[] = { + {1, 1920000, 1980000, 2110000, 2170000, 20, 422000}, + {2, 1850000, 1910000, 1930000, 1990000, 20, 386000}, + {3, 1710000, 1785000, 1805000, 1880000, 20, 361000}, + {5, 824000, 849000, 869000, 894000, 20, 173800}, + {7, 2500000, 2570000, 2620000, 2690000, 20, 524000}, + {8, 880000, 915000, 925000, 960000, 20, 185000}, + {12, 698000, 716000, 728000, 746000, 20, 145800}, + {20, 832000, 862000, 791000, 821000, 20, 158200}, + {25, 1850000, 1915000, 1930000, 1995000, 20, 386000}, + {28, 703000, 758000, 758000, 813000, 20, 151600}, + {34, 2010000, 2025000, 2010000, 2025000, 20, 402000}, + {38, 2570000, 2620000, 2570000, 2630000, 20, 514000}, + {39, 1880000, 1920000, 1880000, 1920000, 20, 376000}, + {40, 2300000, 2400000, 2300000, 2400000, 20, 460000}, + {41, 2496000, 2690000, 2496000, 2690000, 3, 499200}, + {50, 1432000, 1517000, 1432000, 1517000, 20, 286400}, + {51, 1427000, 1432000, 1427000, 1432000, 20, 285400}, + {66, 1710000, 1780000, 2110000, 2200000, 20, 422000}, + {70, 1695000, 1710000, 1995000, 2020000, 20, 399000}, + {71, 663000, 698000, 617000, 652000, 20, 123400}, + {74, 1427000, 1470000, 1475000, 1518000, 20, 295000}, + {75, 000, 000, 1432000, 1517000, 20, 286400}, + {76, 000, 000, 1427000, 1432000, 20, 285400}, + {77, 3300000, 4200000, 3300000, 4200000, 1, 620000}, + {78, 3300000, 3800000, 3300000, 3800000, 1, 620000}, + {79, 4400000, 5000000, 4400000, 5000000, 2, 693334}, + {80, 1710000, 1785000, 000, 000, 20, 342000}, + {81, 860000, 915000, 000, 000, 20, 176000}, + {82, 832000, 862000, 000, 000, 20, 166400}, + {83, 703000, 748000, 000, 000, 20, 140600}, + {84, 1920000, 1980000, 000, 000, 20, 384000}, + {86, 1710000, 1785000, 000, 000, 20, 342000} +}; + +void get_band(uint32_t downlink_frequency, uint8_t *current_band, int32_t *current_offset, lte_frame_type_t *current_type) { + + int ind; + int64_t dl_freq_khz = downlink_frequency/1000; + for ( ind=0; + ind < sizeof(nr_bandtable) / sizeof(nr_bandtable[0]); + ind++) { + + *current_band = nr_bandtable[ind].band; + LOG_I(PHY, "Scanning band %d, dl_min %"PRIu64", ul_min %"PRIu64"\n", ind, nr_bandtable[ind].dl_min,nr_bandtable[ind].ul_min); + + if ( nr_bandtable[ind].dl_min <= dl_freq_khz && nr_bandtable[ind].dl_max >= dl_freq_khz ) { + *current_offset = (nr_bandtable[ind].ul_min - nr_bandtable[ind].dl_min)*1000; + if (*current_offset == 0) + *current_type = TDD; + else + *current_type = FDD; + + LOG_I( PHY, "DL frequency %"PRIu32": band %d, frame_type %d, UL frequency %"PRIu32"\n", + downlink_frequency, *current_band, *current_type, downlink_frequency+*current_offset); + break; + } + } + + AssertFatal(ind != (sizeof(nr_bandtable) / sizeof(nr_bandtable[0])), + "Can't find EUTRA band for frequency %d\n", downlink_frequency); + +} + +uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw) +{ + + uint64_t dl_CarrierFreq_by_1k = dl_CarrierFreq / 1000; + int bw_kHz = bw / 1000; + + int i; + + LOG_I(MAC,"Searching for nr band %d DL Carrier frequency %llu bw %u\n",nr_bandP,(long long unsigned int)dl_CarrierFreq,bw); + AssertFatal(nr_bandP < 86, "nr_band %d > 86\n", nr_bandP); + for (i = 0; i < 30 && nr_bandtable[i].band != nr_bandP; i++); + + AssertFatal(dl_CarrierFreq_by_1k >= nr_bandtable[i].dl_min, + "Band %d, bw %u : DL carrier frequency %llu kHz < %llu\n", + nr_bandP, bw, (long long unsigned int)dl_CarrierFreq_by_1k, + (long long unsigned int)nr_bandtable[i].dl_min); + AssertFatal(dl_CarrierFreq_by_1k <= + (nr_bandtable[i].dl_max - bw_kHz), + "Band %d, dl_CarrierFreq %llu bw %u: DL carrier frequency %llu kHz > %llu\n", + nr_bandP, (long long unsigned int)dl_CarrierFreq,bw, (long long unsigned int)dl_CarrierFreq_by_1k, + (long long unsigned int)(nr_bandtable[i].dl_max - bw_kHz)); + + int deltaFglobal; + + if (dl_CarrierFreq < 3e9) deltaFglobal = 5; + else deltaFglobal = 15; + + // This is equation before Table 5.4.2.1-1 in 38101-1-f30 + // F_REF=F_REF_Offs + deltaF_Global(N_REF-NREF_REF_Offs) + return (((dl_CarrierFreq_by_1k - nr_bandtable[i].dl_min)/deltaFglobal) + + nr_bandtable[i].N_OFFs_DL); +} + + +uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn) +{ + + int i; + int deltaFglobal; + + if (nr_bandP < 77 || nr_bandP > 79) deltaFglobal = 5; + else deltaFglobal = 15; + + AssertFatal(nr_bandP < 87, "nr_band %d > 86\n", nr_bandP); + for (i = 0; i < 31 && nr_bandtable[i].band != nr_bandP; i++); + AssertFatal(dl_nrarfcn>=nr_bandtable[i].N_OFFs_DL,"dl_nrarfcn %u < N_OFFs_DL %llu\n",dl_nrarfcn, (long long unsigned int)nr_bandtable[i].N_OFFs_DL); + + return 1000*(nr_bandtable[i].dl_min + (dl_nrarfcn - nr_bandtable[i].N_OFFs_DL) * deltaFglobal); + +} From ab299dd2e289a1296f501a8dcc8aac415b85a68e Mon Sep 17 00:00:00 2001 From: Francesco Mani Date: Wed, 27 Mar 2019 09:43:09 +0100 Subject: [PATCH 063/117] modification to pbchsim without initial sync --- openair1/SIMULATION/NR_PHY/pbchsim.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 548a4f3dc3..e4ff2f48d7 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -618,9 +618,18 @@ int main(int argc, char **argv) 0, 0, NR_PBCH_EST); + + nr_pbch_channel_estimation(UE,0,0,i,i-(UE->symbol_offset+1),ssb_index%8,n_hf); } - ret = nr_pbch_detection(UE,UE->symbol_offset+1,0); + ret = nr_rx_pbch(UE, + 0, + UE->pbch_vars[0], + frame_parms, + 0, + ssb_index%8, + SISO, + UE->high_speed_flag); if (ret==0) { //UE->rx_ind.rx_indication_body->mib_pdu.ssb_index; //not yet detected automatically From 4af9f321cfc030d6e0f8e25ccb65b604ec4abbb2 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 27 Mar 2019 16:10:51 +0100 Subject: [PATCH 064/117] Fix multiple SSB support for PUSCH --- openair1/SIMULATION/NR_PHY/ulschsim.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index 9b0c3562af..ca3860c5b0 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -146,7 +146,7 @@ int main(int argc, char **argv) { //char input_val_str[50],input_val_str2[50]; //uint16_t NB_RB=25; SCM_t channel_model = AWGN; //Rayleigh1_anticorr; - uint8_t N_RB_DL = 106, N_RB_UL = 106, mu = 1; + uint16_t N_RB_DL = 106, N_RB_UL = 106, mu = 1; unsigned char frame_type = 0; unsigned char pbch_phase = 0; int frame = 0, subframe = 0; @@ -162,7 +162,7 @@ int main(int argc, char **argv) { //int run_initial_sync=0; int loglvl = OAILOG_WARNING; float target_error_rate = 0.01; - + uint64_t SSB_positions=0x01; uint16_t nb_symb_sch = 12; uint16_t nb_rb = 50; uint8_t Imcs = 9; @@ -176,7 +176,7 @@ int main(int argc, char **argv) { //logInit(); randominit(0); - while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:N:F:R:P:")) != -1) { + while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:M:N:F:R:P:")) != -1) { switch (c) { case 'f': write_output_file = 1; @@ -287,6 +287,10 @@ int main(int argc, char **argv) { break; + case 'M': + SSB_positions = atoi(optarg); + break; + case 'N': Nid_cell = atoi(optarg); break; @@ -346,6 +350,7 @@ int main(int argc, char **argv) { printf("-z Number of RX antennas used in UE\n"); printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-M Multiple SSB positions in burst\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); @@ -365,7 +370,8 @@ int main(int argc, char **argv) { if (snr1set == 0) snr1 = snr0 + 10; - gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, 61.44e6, //N_RB2sampling_rate(N_RB_DL), + gNB2UE = new_channel_desc_scm(n_tx, n_rx, channel_model, + 61.44e6, //N_RB2sampling_rate(N_RB_DL), 40e6, //N_RB2channel_bandwidth(N_RB_DL), 0, 0, 0); @@ -389,7 +395,7 @@ int main(int argc, char **argv) { crcTableInit(); - nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell); + nr_phy_config_request_sim(gNB, N_RB_DL, N_RB_DL, mu, Nid_cell, SSB_positions); phy_init_nr_gNB(gNB, 0, 0); //init_eNB_afterRU(); @@ -649,8 +655,10 @@ int main(int argc, char **argv) { (float) n_false_positive / (float) n_trials); printf("*****************************************\n"); - if ((float) n_errors / (float) n_trials < target_error_rate) + if ((float) n_errors / (float) n_trials < target_error_rate) { + printf("PUSCH test OK\n"); break; + } } /*LOG_M("txsigF0.m","txsF0", gNB->common_vars.txdataF[0],frame_length_complex_samples_no_prefix,1,1); From 19d9693c0449d4e6096c8eaa3b3da617d158f65f Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Thu, 28 Mar 2019 17:48:34 +0100 Subject: [PATCH 065/117] adding get_band to new nr-ue executable --- executables/nr-ue.c | 73 ++++-------------------------------- executables/nr-uesoftmodem.c | 5 +++ 2 files changed, 13 insertions(+), 65 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 46dd2835d9..402c379687 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -131,55 +131,6 @@ typedef enum { si=2 } sync_mode_t; -#define KHz (1000UL) -#define MHz (1000*KHz) -typedef struct eutra_band_s { - int16_t band; - uint32_t ul_min; - uint32_t ul_max; - uint32_t dl_min; - uint32_t dl_max; - lte_frame_type_t frame_type; -} eutra_band_t; - -typedef struct band_info_s { - int nbands; - eutra_band_t band_info[100]; -} band_info_t; - -band_info_t bands_to_scan; - -static const eutra_band_t eutra_bands[] = { - { 1, 1920 * MHz, 1980 * MHz, 2110 * MHz, 2170 * MHz, FDD}, - { 2, 1850 * MHz, 1910 * MHz, 1930 * MHz, 1990 * MHz, FDD}, - { 3, 1710 * MHz, 1785 * MHz, 1805 * MHz, 1880 * MHz, FDD}, - { 4, 1710 * MHz, 1755 * MHz, 2110 * MHz, 2155 * MHz, FDD}, - { 5, 824 * MHz, 849 * MHz, 869 * MHz, 894 * MHz, FDD}, - { 6, 830 * MHz, 840 * MHz, 875 * MHz, 885 * MHz, FDD}, - { 7, 2500 * MHz, 2570 * MHz, 2620 * MHz, 2690 * MHz, FDD}, - { 8, 880 * MHz, 915 * MHz, 925 * MHz, 960 * MHz, FDD}, - { 9, 1749900 * KHz, 1784900 * KHz, 1844900 * KHz, 1879900 * KHz, FDD}, - {10, 1710 * MHz, 1770 * MHz, 2110 * MHz, 2170 * MHz, FDD}, - {11, 1427900 * KHz, 1452900 * KHz, 1475900 * KHz, 1500900 * KHz, FDD}, - {12, 698 * MHz, 716 * MHz, 728 * MHz, 746 * MHz, FDD}, - {13, 777 * MHz, 787 * MHz, 746 * MHz, 756 * MHz, FDD}, - {14, 788 * MHz, 798 * MHz, 758 * MHz, 768 * MHz, FDD}, - {17, 704 * MHz, 716 * MHz, 734 * MHz, 746 * MHz, FDD}, - {20, 832 * MHz, 862 * MHz, 791 * MHz, 821 * MHz, FDD}, - {22, 3510 * MHz, 3590 * MHz, 3410 * MHz, 3490 * MHz, FDD}, - {33, 1900 * MHz, 1920 * MHz, 1900 * MHz, 1920 * MHz, TDD}, - {34, 2010 * MHz, 2025 * MHz, 2010 * MHz, 2025 * MHz, TDD}, - {35, 1850 * MHz, 1910 * MHz, 1850 * MHz, 1910 * MHz, TDD}, - {36, 1930 * MHz, 1990 * MHz, 1930 * MHz, 1990 * MHz, TDD}, - {37, 1910 * MHz, 1930 * MHz, 1910 * MHz, 1930 * MHz, TDD}, - {38, 2570 * MHz, 2620 * MHz, 2570 * MHz, 2630 * MHz, TDD}, - {39, 1880 * MHz, 1920 * MHz, 1880 * MHz, 1920 * MHz, TDD}, - {40, 2300 * MHz, 2400 * MHz, 2300 * MHz, 2400 * MHz, TDD}, - {41, 2496 * MHz, 2690 * MHz, 2496 * MHz, 2690 * MHz, TDD}, - {42, 3400 * MHz, 3600 * MHz, 3400 * MHz, 3600 * MHz, TDD}, - {43, 3600 * MHz, 3800 * MHz, 3600 * MHz, 3800 * MHz, TDD}, - {44, 703 * MHz, 803 * MHz, 703 * MHz, 803 * MHz, TDD}, -}; PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, uint8_t UE_id, @@ -226,20 +177,8 @@ static void UE_synch(void *arg) { if (UE->UE_scan == 0) { int ind; - for ( ind=0; ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]); - ind++) { - current_band = eutra_bands[ind].band; - LOG_D(PHY, "Scanning band %d, dl_min %"PRIu32", ul_min %"PRIu32"\n", current_band, eutra_bands[ind].dl_min,eutra_bands[ind].ul_min); - - if ( eutra_bands[ind].dl_min <= downlink_frequency[0][0] && eutra_bands[ind].dl_max >= downlink_frequency[0][0] ) { - for (i=0; i<4; i++) - uplink_frequency_offset[CC_id][i] = eutra_bands[ind].ul_min - eutra_bands[ind].dl_min; - - break; - } - } - - AssertFatal( ind < sizeof(eutra_bands) / sizeof(eutra_bands[0]), "Can't find EUTRA band for frequency"); + get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); + LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], oai_exit, openair0_cfg[0].rx_num_channels); @@ -259,7 +198,8 @@ static void UE_synch(void *arg) { sync_mode = pbch; } else { current_band=0; - + LOG_E(PHY,"Fixme!\n"); + /* for (i=0; irf_map.card].rx_num_channels; i++) { downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[CC_id].dl_min; uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = @@ -269,11 +209,13 @@ static void UE_synch(void *arg) { downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; } + */ } LOG_W(PHY, "Starting sync detection\n"); switch (sync_mode) { + /* case pss: LOG_I(PHY,"[SCHED][UE] Scanning band %d (%d), freq %u\n",bands_to_scan.band_info[current_band].band, current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); //lte_sync_timefreq(UE,current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); @@ -302,7 +244,8 @@ static void UE_synch(void *arg) { } break; - + */ + case pbch: LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index ed5ff7aa1d..e6a97c8f28 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -535,6 +535,8 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; config[CC_id]->sch_config.physical_cell_id.value = 0; + + frame_parms[CC_id]->eutra_band = 78; frame_parms[CC_id]->frame_type = FDD; frame_parms[CC_id]->tdd_config = 3; //frame_parms[CC_id]->tdd_config_S = 0; @@ -736,6 +738,9 @@ int main( int argc, char **argv ) { frame_parms[CC_id]->nb_antennas_rx = nb_antenna_rx; frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); + + get_band(downlink_frequency[CC_id][0], &frame_parms[CC_id]->eutra_band, &uplink_frequency_offset[CC_id][0], &frame_parms[CC_id]->frame_type); + } NB_UE_INST=1; From 8c5d67a8f3799fb33353b31fbd0e11cc6dcf94b6 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Thu, 28 Mar 2019 18:54:58 +0100 Subject: [PATCH 066/117] CI: fix long standing typo Signed-off-by: Raphael Defosseux --- ci-scripts/Jenkinsfile-gitlab | 6 +++--- ci-scripts/oai-ci-vm-tool | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index 6ae75d71ae..b5c34d5b81 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -131,10 +131,10 @@ pipeline { } } - stage ("Start VM -- nu-ue-usrp") { + stage ("Start VM -- nr-ue-usrp") { steps { timeout (time: 5, unit: 'MINUTES') { - sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant nu-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon" + sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant nr-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon" } } } @@ -239,7 +239,7 @@ pipeline { steps { gitlabCommitStatus(name: "Build nr-UE-usrp") { timeout (time: 20, unit: 'MINUTES') { - sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant nu-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}" + sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant nr-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}" } } } diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool index 1245d046ff..ed43e26729 100755 --- a/ci-scripts/oai-ci-vm-tool +++ b/ci-scripts/oai-ci-vm-tool @@ -39,7 +39,7 @@ function variant_usage { echo " --variant phy-sim OR -v3" echo " --variant cppcheck OR -v4" echo " --variant gnb-usrp OR -v5" - echo " --variant nu-ue-usrp OR -v6" + echo " --variant nr-ue-usrp OR -v6" echo " --variant enb-ethernet OR -v7" echo " --variant ue-ethernet OR -v8" } @@ -354,7 +354,7 @@ case $key in BUILD_OPTIONS="--gNB -w USRP" NBARGS=$[$NBARGS+256] ;; - nu-ue-usrp) + nr-ue-usrp) VM_NAME=ci-ue-nr-usrp ARCHIVES_LOC=nrue_usrp LOG_PATTERN=.Rel15.txt From 21a2f12a0a1911192486081df00121aa0bd34e89 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 10:34:38 +0200 Subject: [PATCH 067/117] removing next_thread business (not needed for now) removing unused code activating pdsch detection --- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 872 +------------------- 1 file changed, 25 insertions(+), 847 deletions(-) diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 55033e6652..596523b108 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -1264,37 +1264,6 @@ uint16_t nr_get_n1_pucch(PHY_VARS_NR_UE *ue, } -#ifdef EMOS - -void phy_procedures_emos_UE_TX(uint8_t next_slot,uint8_t eNB_id) { - uint8_t harq_pid; - - - if (next_slot%2==0) { - // get harq_pid from nr_tti_tx relationship - harq_pid = nr_subframe2harq_pid(&ue->frame_parms,ue->frame,(next_slot>>1)); - if (harq_pid==255) { - LOG_E(PHY,"[UE%d] Frame %d : FATAL ERROR: illegal harq_pid, returning\n", - 0,ue->frame); - return; - } - - if (ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag == 1) { - emos_dump_UE.uci_cnt[next_slot>>1] = 1; - memcpy(emos_dump_UE.UCI_data[0][next_slot>>1].o,ulsch[eNB_id]->o,MAX_CQI_BITS*sizeof(char)); - emos_dump_UE.UCI_data[0][next_slot>>1].O = ulsch[eNB_id]->O; - memcpy(emos_dump_UE.UCI_data[0][next_slot>>1].o_RI,ulsch[eNB_id]->o_RI,2*sizeof(char)); - emos_dump_UE.UCI_data[0][next_slot>>1].O_RI = ulsch[eNB_id]->O_RI; - memcpy(emos_dump_UE.UCI_data[0][next_slot>>1].o_ACK,ulsch[eNB_id]->o_ACK,4*sizeof(char)); - emos_dump_UE.UCI_data[0][next_slot>>1].O_ACK = ulsch[eNB_id]->harq_processes[harq_pid]->O_ACK; - } - else { - emos_dump_UE.uci_cnt[next_slot>>1] = 0; - } - } -} - -#endif void ulsch_common_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t empty_subframe) { @@ -1602,10 +1571,10 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8 VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_IN); /* reset harq for tx of current rx slot because it is sure that transmission has already been achieved for this slot */ - set_tx_harq_id(ue->ulsch[eNB_id], NR_MAX_HARQ_PROCESSES, proc->nr_tti_rx); + set_tx_harq_id(ue->ulsch[ue->current_thread_id[nr_tti_tx]][eNB_id][0], NR_MAX_HARQ_PROCESSES, proc->nr_tti_rx); /* get harq pid related to this next tx slot */ - harq_pid = get_tx_harq_id(ue->ulsch[eNB_id], nr_tti_tx); + harq_pid = get_tx_harq_id(ue->ulsch[ue->current_thread_id[nr_tti_tx]][eNB_id][0], nr_tti_tx); #if 0 @@ -2500,8 +2469,10 @@ void phy_procedures_UE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB unsigned int aa; uint8_t isSubframeSRS; + /* uint8_t next1_thread_id = ue->current_thread_id[proc->nr_tti_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[proc->nr_tti_rx]+1); uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); + */ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX,VCD_FUNCTION_IN); @@ -2637,6 +2608,7 @@ void phy_procedures_UE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB ue->ulsch[eNB_id]->o_ACK, &N_bundled, 0); + /* nr_reset_ack(&ue->frame_parms, ue->dlsch[next1_thread_id][eNB_id][0]->harq_ack, nr_tti_tx, @@ -2651,6 +2623,7 @@ void phy_procedures_UE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB ue->ulsch[eNB_id]->o_ACK, &N_bundled, 0); + */ } if (ue->dlsch_SI[eNB_id] != NULL) @@ -2765,93 +2738,6 @@ void nr_ue_measurement_procedures( } -#ifdef EMOS -void phy_procedures_emos_UE_RX(PHY_VARS_NR_UE *ue,uint8_t last_slot,uint8_t eNB_id) -{ - - uint8_t i,j; - //uint16_t last_slot_emos; - uint32_t bytes; - int Mod_id = ue->Mod_id; - - /* - if (last_slot<2) - last_slot_emos = last_slot; - else if (last_slot>9) - last_slot_emos = last_slot - 8; - else { - LOG_E(PHY,"emos rx last_slot_emos %d, last_slot %d\n", last_slot_emos,last_slot); - //mac_xface->macphy_exit("should never happen"); - } - */ - -#ifdef EMOS_CHANNEL - - if ((last_slot==10) || (last_slot==11)) { - for (i=0; iframe_parms.nb_antennas_rx; i++) - for (j=0; jframe_parms.nb_antennas_tx; j++) { - // first OFDM symbol with pilots - memcpy(&emos_dump_UE.channel[i][j][(last_slot%2)*2*ue->frame_parms.ofdm_symbol_size], - &ue->common_vars.dl_ch_estimates[eNB_id][(j<<1) + i][0], - ue->frame_parms.ofdm_symbol_size*sizeof(int)); - // second OFDM symbol with pilots - memcpy(&emos_dump_UE.channel[i][j][((last_slot%2)*2+1)*ue->frame_parms.ofdm_symbol_size], - &ue->common_vars.dl_ch_estimates[eNB_id][(j<<1) + i][(ue->frame_parms.Ncp == 0 ? 4 : 3)*ue->frame_parms.ofdm_symbol_size], - ue->frame_parms.ofdm_symbol_size*sizeof(int)); - } - } - -#endif - - if (last_slot==0) { - emos_dump_UE.timestamp = rt_get_time_ns(); - emos_dump_UE.frame_rx = proc->frame_rx; - emos_dump_UE.UE_mode = ue->UE_mode[eNB_id]; - emos_dump_UE.mimo_mode = ue->transmission_mode[eNB_id]; - emos_dump_UE.freq_offset = ue->common_vars.freq_offset; - emos_dump_UE.timing_advance = ue->timing_advance; - emos_dump_UE.timing_offset = ue->rx_offset; - emos_dump_UE.rx_total_gain_dB = ue->rx_total_gain_dB; - emos_dump_UE.eNb_id = eNB_id; - memcpy(&emos_dump_UE.PHY_measurements,&measurements,sizeof(PHY_MEASUREMENTS)); - } - - if (last_slot==1) { - emos_dump_UE.pbch_errors = ue->pbch_vars[eNB_id]->pdu_errors; - emos_dump_UE.pbch_errors_last = ue->pbch_vars[eNB_id]->pdu_errors_last; - emos_dump_UE.pbch_errors_conseq = ue->pbch_vars[eNB_id]->pdu_errors_conseq; - emos_dump_UE.pbch_fer = ue->pbch_vars[eNB_id]->pdu_fer; - } - - if (last_slot==19) { - emos_dump_UE.dlsch_errors = ue->dlsch_errors[eNB_id]; - emos_dump_UE.dlsch_errors_last = ue->dlsch_errors_last[eNB_id]; - emos_dump_UE.dlsch_received = ue->dlsch_received[eNB_id]; - emos_dump_UE.dlsch_received_last = ue->dlsch_received_last[eNB_id]; - emos_dump_UE.dlsch_fer = ue->dlsch_fer[eNB_id]; - emos_dump_UE.dlsch_cntl_errors = ue->dlsch_SI_errors[eNB_id]; - emos_dump_UE.dlsch_ra_errors = ue->dlsch_ra_errors[eNB_id]; - emos_dump_UE.total_TBS = ue->total_TBS[eNB_id]; - emos_dump_UE.total_TBS_last = ue->total_TBS_last[eNB_id]; - emos_dump_UE.bitrate = ue->bitrate[eNB_id]; - emos_dump_UE.total_received_bits = ue->total_received_bits[eNB_id]; - emos_dump_UE.pmi_saved = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->pmi_alloc; - emos_dump_UE.mcs = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->harq_processes[ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->current_harq_pid]->mcs; - emos_dump_UE.use_ia_receiver = openair_daq_vars.use_ia_receiver; - - bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, &emos_dump_UE, sizeof(fifo_dump_emos_UE)); - - if (bytes!=sizeof(fifo_dump_emos_UE)) { - LOG_W(PHY,"[UE %d] frame %d, slot %d, Problem writing EMOS data to FIFO\n",Mod_id,proc->frame_rx, last_slot); - } else { - if (proc->frame_rx%100==0) { - LOG_I(PHY,"[UE %d] frame %d, slot %d, Writing %d bytes EMOS data to FIFO\n",Mod_id,proc->frame_rx, last_slot, bytes); - } - } - } - -} -#endif #if 0 void restart_phy(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc, uint8_t eNB_id,uint8_t abstraction_flag) @@ -3032,8 +2918,10 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; NR_DCI_ALLOC_t dci_alloc_rx[8]; + /* uint8_t next1_thread_id = ue->current_thread_id[nr_tti_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[nr_tti_rx]+1); uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); + */ // table dci_fields_sizes_cnt contains dci_fields_sizes for each time a dci is decoded in the slot // each element represents the size in bits for each dci field, for each decoded dci -> [dci_cnt-1] @@ -3240,12 +3128,14 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * uint8_t *nCCE_current = &ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->nCCE[nr_tti_rx]; + /* uint8_t *nCCE_dest = &ue->pdcch_vars[next1_thread_id][eNB_id]->nCCE[nr_tti_rx]; uint8_t *nCCE_dest1 = &ue->pdcch_vars[next2_thread_id][eNB_id]->nCCE[nr_tti_rx]; memcpy(nCCE_dest, nCCE_current, sizeof(uint8_t)); memcpy(nCCE_dest1, nCCE_current, sizeof(uint8_t)); LOG_D(PHY,"current_thread %d next1_thread %d next2_thread %d \n", ue->current_thread_id[nr_tti_rx], next1_thread_id, next2_thread_id); + */ LOG_D(PHY,"[UE %d] AbsSubFrame %d.%d, Mode %s: DCI found %i --> rnti %x / crnti %x : format %d\n", ue->Mod_id,frame_rx%1024,nr_tti_rx,mode_string[ue->UE_mode[eNB_id]], @@ -3305,7 +3195,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id], ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id], ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id], - ue->ulsch[eNB_id], + ue->ulsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], &ue->frame_parms, ue->pdsch_config_dedicated, ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id], @@ -3753,7 +3643,6 @@ void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB #endif #endif - if(first_symbol_flag) { proc->first_symbol_available = 1; @@ -3770,8 +3659,10 @@ void process_rar(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, runmod NR_UE_DLSCH_t *dlsch0 = ue->dlsch_ra[eNB_id]; int harq_pid = 0; uint8_t *rar; + /* uint8_t next1_thread_id = ue->current_thread_id[nr_tti_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[nr_tti_rx]+1); uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); + */ LOG_D(PHY,"[UE %d][RAPROC] Frame %d nr_tti_rx %d Received RAR mode %d\n", ue->Mod_id, @@ -3796,9 +3687,11 @@ void process_rar(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, runmod ue->prach_resources[eNB_id]->ra_PreambleIndex, dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload */ + /* ue->pdcch_vars[next1_thread_id][eNB_id]->crnti = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->crnti; ue->pdcch_vars[next2_thread_id][eNB_id]->crnti = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->crnti; - + */ + if (timing_advance!=0xffff) { LOG_D(PHY,"[UE %d][RAPROC] Frame %d nr_tti_rx %d Got rnti %x and timing advance %d from RAR\n", @@ -4403,527 +4296,6 @@ void *UE_thread_slot1_dl_processing(void *arg) { } #endif -#ifdef UE_SLOT_PARALLELISATION -int phy_procedures_slot_parallelization_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, - uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode, - relaying_type_t r_type) { - - int l,l2; - int pmch_flag=0; - int frame_rx = proc->frame_rx; - int nr_tti_rx = proc->nr_tti_rx; - uint8_t pilot0; - uint8_t pilot1; - uint8_t slot0; - uint8_t slot1; - uint8_t first_ofdm_sym; - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_IN); - -#if T_TRACER - T(T_UE_PHY_DL_TICK, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(nr_tti_rx)); - - T(T_UE_PHY_INPUT_SIGNAL, T_INT(ue->Mod_id), T_INT(frame_rx%1024), T_INT(nr_tti_rx), T_INT(0), - T_BUFFER(&ue->common_vars.rxdata[0][nr_tti_rx*ue->frame_parms.samples_per_subframe], - ue->frame_parms.samples_per_subframe * 4)); -#endif - - // start timers -#ifdef UE_DEBUG_TRACE - LOG_I(PHY," ****** start RX-Chain for AbsSubframe %d.%d ****** \n", frame_rx%1024, nr_tti_rx); -#endif - -#if UE_TIMING_TRACE - start_meas(&ue->phy_proc_rx[ue->current_thread_id[nr_tti_rx]]); - start_meas(&ue->ue_front_end_stat[ue->current_thread_id[nr_tti_rx]]); -#endif - - pmch_flag = is_pmch_subframe(frame_rx,nr_tti_rx,&ue->frame_parms) ? 1 : 0; - - if (do_pdcch_flag) { - // deactivate reception until we scan pdcch - if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]) - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active = 0; - if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][1]) - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][1]->active = 0; - - if (ue->dlsch_SI[eNB_id]) - ue->dlsch_SI[eNB_id]->active = 0; - if (ue->dlsch_p[eNB_id]) - ue->dlsch_p[eNB_id]->active = 0; - if (ue->dlsch_ra[eNB_id]) - ue->dlsch_ra[eNB_id]->active = 0; - } - -#ifdef DEBUG_PHY_PROC - LOG_D(PHY,"[%s %d] Frame %d nr_tti_rx %d: Doing phy_procedures_UE_RX\n", - (r_type == multicast_relay) ? "RN/UE" : "UE", - ue->Mod_id,frame_rx, nr_tti_rx); -#endif - - - - - if (nr_subframe_select(&ue->frame_parms,nr_tti_rx) == SF_S) { // S-subframe, do first 5 symbols only - l2 = 5; - } else if (pmch_flag == 1) { // do first 2 symbols only - l2 = 1; - } else { // normal nr_tti_rx, last symbol to be processed is the first of the second slot - l2 = (ue->frame_parms.symbols_per_tti/2)-1; - } - - int prev_nr_tti_rx = (nr_tti_rx - 1)<0? 9: (nr_tti_rx - 1); - if (nr_subframe_select(&ue->frame_parms,prev_nr_tti_rx) != SF_DL) { - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // RX processing of symbols l=0...l2 - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - first_ofdm_sym = 0; - } else { - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // RX processing of symbols l=1...l2 (l=0 is done in last scheduling epoch) - //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - first_ofdm_sym = 1; - } - slot0 = (nr_tti_rx<<1); - slot1 = (nr_tti_rx<<1) + 1; - pilot0 = 0; - if (ue->frame_parms.Ncp == 0) { // normal prefix - pilot1 = 4; - } else { // extended prefix - pilot1 = 3; - } - - //LOG_I(PHY,"Set available channelEst to 0 AbsSubframe %d.%d \n",frame_rx,nr_tti_rx); - //LOG_I(PHY,"Set available llrs slot1 to 0 AbsSubframe %d.%d \n",frame_rx,nr_tti_rx); - //LOG_I(PHY,"Set available dci info slot0 to 0 AbsSubframe %d.%d \n",frame_rx,nr_tti_rx); - proc->chan_est_pilot0_slot1_available=0; - proc->llr_slot1_available=0; - proc->dci_slot0_available=0; - proc->first_symbol_available=0; - proc->chan_est_slot1_available=0; - //proc->channel_level=0; - - if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error locking mutex for UE slot1 dl processing\n",ue->Mod_id ); - exit_fun("nothing to add"); - } - - proc->instance_cnt_slot1_dl_processing++; - if (proc->instance_cnt_slot1_dl_processing == 0) - { - LOG_D(PHY,"unblock slot1 dl processing thread blocked on instance_cnt_slot1_dl_processing : %d \n", proc->instance_cnt_slot1_dl_processing ); - if (pthread_cond_signal(&proc->cond_slot1_dl_processing) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] ERROR pthread_cond_signal for UE slot1 processing thread\n", ue->Mod_id); - exit_fun("nothing to add"); - } - if (pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) != 0) { - LOG_E( PHY, "[SCHED][UE %d][Slot0] error unlocking mutex for UE slot1 dl processing \n",ue->Mod_id ); - exit_fun("nothing to add"); - } - - } else - { - LOG_E( PHY, "[SCHED][UE %d] UE RX thread busy (IC %d)!!\n", ue->Mod_id, proc->instance_cnt_slot1_dl_processing); - if (proc->instance_cnt_slot1_dl_processing > 2) - exit_fun("instance_cnt_slot1_dl_processing > 2"); - } - //AssertFatal(pthread_cond_signal(&proc->cond_slot1_dl_processing) ==0 ,""); - AssertFatal(pthread_mutex_unlock(&proc->mutex_slot1_dl_processing) ==0,""); - - - /**** Slot0 FE Processing ****/ - // I- start main thread for FFT/ChanEst symbol: 0/1 --> 7 -#if UE_TIMING_TRACE - start_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0]); -#endif - // 1- perform FFT for pilot ofdm symbols first (ofdmSym7 ofdmSym4 or (ofdmSym6 ofdmSym3)) - //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot1,pilot0); - front_end_fft(ue, - pilot0, - slot1, - 0, - 0); - //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot0,pilot1); - front_end_fft(ue, - pilot1, - slot0, - 0, - 0); - //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot0,pilot1); - front_end_chanEst(ue, - pilot1, - slot0, - 0); - //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot1,pilot0); - front_end_chanEst(ue, - pilot0, - slot1, - 0); - proc->chan_est_pilot0_slot1_available = 1; - //printf("Set available channelEst to 1 AbsSubframe %d.%d \n",frame_rx,nr_tti_rx); - - // 2- perform FFT for other ofdm symbols other than pilots - for (l=first_ofdm_sym; l<=l2; l++) - { - if( (l != pilot0) && (l != pilot1)) - { - //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot0,l); -#if UE_TIMING_TRACE - start_meas(&ue->ofdm_demod_stats); -#endif - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN); - front_end_fft(ue, - l, - slot0, - 0, - 0); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT); -#if UE_TIMING_TRACE - stop_meas(&ue->ofdm_demod_stats); -#endif - } - } // for l=1..l2 - - // 3- perform Channel Estimation for slot0 - for (l=first_ofdm_sym; l<=l2; l++) - { - if( (l != pilot0) && (l != pilot1)) - { - //printf("AbsSubframe %d.%d ChanEst slot %d, symbol %d\n", frame_rx,nr_tti_rx,slot0,l); - front_end_chanEst(ue, - l, - slot0, - 0); - } - ue_measurement_procedures(l-1,ue,proc,eNB_id,(nr_tti_rx<<1),abstraction_flag,mode); - } - - if (do_pdcch_flag) { -#if UE_TIMING_TRACE - start_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#endif - if (ue_pdcch_procedures(eNB_id,ue,proc,abstraction_flag) == -1) { - LOG_E(PHY,"[UE %d] Frame %d, nr_tti_rx %d: Error in pdcch procedures\n",ue->Mod_id,frame_rx,nr_tti_rx); -#if UE_TIMING_TRACE - stop_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#endif -#endif - //proc->dci_slot0_available = 1; - return(-1); - } - //proc->dci_slot0_available=1; -#if UE_TIMING_TRACE - stop_meas(&ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Slot0: PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->pdcch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#endif -#endif - } - - //printf("num_pdcch_symbols %d\n",ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols); - - // first slot has been processed (FFTs + Channel Estimation, PCFICH/PHICH/PDCCH) -#if UE_TIMING_TRACE - stop_meas(&ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Slot0: FFT + Channel Estimate + PCFICH/PHICH/PDCCH %5.2f \n",frame_rx,nr_tti_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#endif -#endif - - //wait until slot1 FE is done - uint32_t wait = 0; - while(proc->chan_est_slot1_available == 0) - { - usleep(1); - wait++; - } - -#if UE_TIMING_TRACE - stop_meas(&ue->ue_front_end_stat[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] FULL FE Processing %5.2f \n",frame_rx,nr_tti_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] FULL FE Processing %5.2f \n",frame_rx,nr_tti_rx,ue->ue_front_end_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#endif -#endif - /**** End nr_tti_rx FE Processing ****/ - - -#if 0 - //Trigger LLR parallelized for Slot 1 - proc->dci_slot0_available=1; - printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,nr_tti_rx); -#endif - - /**** Pdsch Procedure Slot0 ****/ - // start main thread for Pdsch Procedure (slot0) - // do procedures for C-RNTI - //printf("AbsSubframe %d.%d Pdsch Procedure (slot0)\n",frame_rx%1024,nr_tti_rx); - //printf("AbsSubframe %d.%d Pdsch Procedure PDSCH Active %d \n",frame_rx%1024,nr_tti_rx, ue->dlsch[ue->current_thread_id[nr_tti_rx]][0][0]->active); - -#if UE_TIMING_TRACE - start_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#endif - -#if UE_TIMING_TRACE - start_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0]); -#endif - if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active == 1) { - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN); - ue_pdsch_procedures(ue, - proc, - eNB_id, - PDSCH, - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (ue->frame_parms.symbols_per_tti>>1)-1, - abstraction_flag); - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT); - } - - // do procedures for SI-RNTI - if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) { - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_IN); - ue_pdsch_procedures(ue, - proc, - eNB_id, - SI_PDSCH, - ue->dlsch_SI[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (ue->frame_parms.symbols_per_tti>>1)-1, - abstraction_flag); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT); - } - - // do procedures for SI-RNTI - if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) { - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_IN); - ue_pdsch_procedures(ue, - proc, - eNB_id, - P_PDSCH, - ue->dlsch_p[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (ue->frame_parms.symbols_per_tti>>1)-1, - abstraction_flag); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT); - } - - // do procedures for RA-RNTI - if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) { - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_IN); - ue_pdsch_procedures(ue, - proc, - eNB_id, - RA_PDSCH, - ue->dlsch_ra[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (ue->frame_parms.symbols_per_tti>>1)-1, - abstraction_flag); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT); - } - -#if 1 - // LLR linear - proc->dci_slot0_available=1; - //printf("Set available dci slot0 to 1 AbsSubframe %d.%d \n",frame_rx%1024,nr_tti_rx); -#endif - -#if UE_TIMING_TRACE - stop_meas(&ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot0: LLR Computation %5.2f \n",frame_rx,nr_tti_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Slot0: LLR Computation %5.2f \n",frame_rx,nr_tti_rx,ue->pdsch_procedures_per_slot_stat[ue->current_thread_id[nr_tti_rx]][0].p_time/(cpuf*1000.0)); -#endif -#endif - - - //wait until LLR Slot1 is done - wait = 0; - while(proc->llr_slot1_available == 0) - { - usleep(1); - wait++; - } - - - -#if UE_TIMING_TRACE - stop_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Full LLR Computation %5.2f \n",frame_rx,nr_tti_rx,ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Full LLR Computation %5.2f \n",frame_rx,nr_tti_rx,ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#endif -#endif - //printf("[slot0 dl processing] AbsSubframe %d.%d Channel Decoder Start wait %d\n",frame_rx,nr_tti_rx,wait); - - - //=====================================================================// -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#endif - - LOG_D(PHY,"==> Start Turbo Decoder active dlsch %d SI %d RA %d \n",ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active, - ue->dlsch_SI[eNB_id]->active, - //ue->dlsch_p[eNB_id]->active, - ue->dlsch_ra[eNB_id]->active); - // Start Turbo decoder - if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active == 1) { - //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN); - ue_dlsch_procedures(ue, - proc, - eNB_id, - PDSCH, - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][1], - &ue->dlsch_errors[eNB_id], - mode, - abstraction_flag); - //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT); - } - - // do procedures for SI-RNTI - if ((ue->dlsch_SI[eNB_id]) && (ue->dlsch_SI[eNB_id]->active == 1)) { - ue_dlsch_procedures(ue, - proc, - eNB_id, - SI_PDSCH, - ue->dlsch_SI[eNB_id], - NULL, - &ue->dlsch_SI_errors[eNB_id], - mode, - abstraction_flag); - ue->dlsch_SI[eNB_id]->active = 0; - } - - // do procedures for P-RNTI - if ((ue->dlsch_p[eNB_id]) && (ue->dlsch_p[eNB_id]->active == 1)) { - ue_dlsch_procedures(ue, - proc, - eNB_id, - P_PDSCH, - ue->dlsch_p[eNB_id], - NULL, - &ue->dlsch_p_errors[eNB_id], - mode, - abstraction_flag); - ue->dlsch_p[eNB_id]->active = 0; - } - // do procedures for RA-RNTI - if ((ue->dlsch_ra[eNB_id]) && (ue->dlsch_ra[eNB_id]->active == 1)) { - ue_dlsch_procedures(ue, - proc, - eNB_id, - RA_PDSCH, - ue->dlsch_ra[eNB_id], - NULL, - &ue->dlsch_ra_errors[eNB_id], - mode, - abstraction_flag); - ue->dlsch_ra[eNB_id]->active = 0; - } - -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Channel Decoder: %5.2f \n",frame_rx,nr_tti_rx,ue->dlsch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "[AbsSFN %d.%d] Channel Decoder: %5.2f \n",frame_rx,nr_tti_rx,ue->dlsch_procedures_stat[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#endif - -#endif - - // duplicate harq structure - uint8_t current_harq_pid = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->current_harq_pid; - NR_DL_UE_HARQ_t *current_harq_processes = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->harq_processes[current_harq_pid]; - nr_harq_status_t *current_harq_ack = &ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->harq_ack[nr_tti_rx]; - - // For Debug parallelisation - //if (current_harq_ack->ack == 0) { - //printf("[slot0 dl processing][End of Channel Decoding] AbsSubframe %d.%d Decode Fail for HarqId%d Round%d\n",frame_rx,nr_tti_rx,current_harq_pid,current_harq_processes->round); - //} - for(uint8_t rx_th_idx=1; rx_th_idxdlsch[ue->current_thread_id[(nr_tti_rx+rx_th_idx)%10]][eNB_id][0]->harq_processes[current_harq_pid]; - nr_harq_status_t *harq_ack_dest = &ue->dlsch[ue->current_thread_id[(nr_tti_rx+rx_th_idx)%10]][eNB_id][0]->harq_ack[nr_tti_rx]; - - copy_harq_proc_struct(harq_processes_dest, current_harq_processes); - copy_ack_struct(harq_ack_dest, current_harq_ack); - - } - /* - NR_DL_UE_HARQ_t *harq_processes_dest = ue->dlsch[(nr_tti_rx+1)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid]; - NR_DL_UE_HARQ_t *harq_processes_dest1 = ue->dlsch[(nr_tti_rx+2)%RX_NB_TH][eNB_id][0]->harq_processes[current_harq_pid]; - - nr_harq_status_t *current_harq_ack = &ue->dlsch[nr_tti_rx%RX_NB_TH][eNB_id][0]->harq_ack[nr_tti_rx]; - nr_harq_status_t *harq_ack_dest = &ue->dlsch[(nr_tti_rx+1)%RX_NB_TH][eNB_id][0]->harq_ack[nr_tti_rx]; - nr_harq_status_t *harq_ack_dest1 = &ue->dlsch[(nr_tti_rx+2)%RX_NB_TH][eNB_id][0]->harq_ack[nr_tti_rx]; - - copy_harq_proc_struct(harq_processes_dest, current_harq_processes); - copy_ack_struct(harq_ack_dest, current_harq_ack); - - copy_harq_proc_struct(harq_processes_dest1, current_harq_processes); - copy_ack_struct(harq_ack_dest1, current_harq_ack); - */ - if (nr_tti_rx==9) { - if (frame_rx % 10 == 0) { - if ((ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]) != 0) - ue->dlsch_fer[eNB_id] = (100*(ue->dlsch_errors[eNB_id] - ue->dlsch_errors_last[eNB_id]))/(ue->dlsch_received[eNB_id] - ue->dlsch_received_last[eNB_id]); - - ue->dlsch_errors_last[eNB_id] = ue->dlsch_errors[eNB_id]; - ue->dlsch_received_last[eNB_id] = ue->dlsch_received[eNB_id]; - } - - - ue->bitrate[eNB_id] = (ue->total_TBS[eNB_id] - ue->total_TBS_last[eNB_id])*100; - ue->total_TBS_last[eNB_id] = ue->total_TBS[eNB_id]; - LOG_D(PHY,"[UE %d] Calculating bitrate Frame %d: total_TBS = %d, total_TBS_last = %d, bitrate %f kbits\n", - ue->Mod_id,frame_rx,ue->total_TBS[eNB_id], - ue->total_TBS_last[eNB_id],(float) ue->bitrate[eNB_id]/1000.0); - -#if UE_AUTOTEST_TRACE - if ((frame_rx % 100 == 0)) { - LOG_I(PHY,"[UE %d] AUTOTEST Metric : UE_DLSCH_BITRATE = %5.2f kbps (frame = %d) \n", ue->Mod_id, (float) ue->bitrate[eNB_id]/1000.0, frame_rx); - } -#endif - - } - -#ifdef EMOS - phy_procedures_emos_UE_RX(ue,slot,eNB_id); -#endif - - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT); - -#if UE_TIMING_TRACE - stop_meas(&ue->phy_proc_rx[ue->current_thread_id[nr_tti_rx]]); -#if DISABLE_LOG_X - printf("------FULL RX PROC [AbsSFN %d.%d]: %5.2f ------\n",frame_rx,nr_tti_rx,ue->phy_proc_rx[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#else - LOG_D(PHY, "------FULL RX PROC [AbsSFN %d.%d]: %5.2f ------\n",frame_rx,nr_tti_rx,ue->phy_proc_rx[ue->current_thread_id[nr_tti_rx]].p_time/(cpuf*1000.0)); -#endif -#endif - - LOG_D(PHY," ****** end RX-Chain for AbsSubframe %d.%d ****** \n", frame_rx%1024, nr_tti_rx); - return (0); -} -#endif int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, @@ -4943,8 +4315,10 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN LOG_D(PHY," ****** start RX-Chain for Frame.Slot %d.%d ****** \n", frame_rx%1024, nr_tti_rx); + /* uint8_t next1_thread_id = ue->current_thread_id[nr_tti_rx]== (RX_NB_TH-1) ? 0:(ue->current_thread_id[nr_tti_rx]+1); uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); + */ #ifdef NR_PDCCH_SCHED nr_gold_pdcch(ue,0, 2); @@ -4995,7 +4369,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN #endif //NR_PDCCH_SCHED - if (nr_tti_rx==1){ + if (dci_cnt > 0){ LOG_D(PHY," ------ --> PDSCH ChannelComp/LLR Frame.slot %d.%d ------ \n", frame_rx%1024, nr_tti_rx); //to update from pdsch config nr_gold_pdsch(ue,nb_symb_pdcch,0, 1); @@ -5013,7 +4387,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN } //set active for testing, to be removed - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active = 0; + ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active = 1; } else ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active = 0; @@ -5111,28 +4485,11 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active == 1) { VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN); + #if UE_TIMING_TRACE - - start_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); -#endif - /*nr_ue_pdsch_procedures(ue, - proc, - eNB_id, - PDSCH, - ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1, - abstraction_flag); - LOG_D(PHY," ------ end PDSCH ChannelComp/LLR slot 0: AbsSubframe %d.%d ------ \n", frame_rx%1024, nr_tti_rx); - LOG_D(PHY," ------ --> PDSCH Turbo Decoder slot 0/1: AbsSubframe %d.%d ------ \n", frame_rx%1024, nr_tti_rx);*/ -#if UE_TIMING_TRACE - stop_meas(&ue->pdsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); start_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[nr_tti_rx]]); #endif -//#endif //slot 1 - nr_ue_dlsch_procedures(ue, proc, eNB_id, @@ -5253,21 +4610,21 @@ start_meas(&ue->generic_stat); } // duplicate harq structure - + /* uint8_t current_harq_pid = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->current_harq_pid; NR_DL_UE_HARQ_t *current_harq_processes = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->harq_processes[current_harq_pid]; NR_DL_UE_HARQ_t *harq_processes_dest = ue->dlsch[next1_thread_id][eNB_id][0]->harq_processes[current_harq_pid]; NR_DL_UE_HARQ_t *harq_processes_dest1 = ue->dlsch[next2_thread_id][eNB_id][0]->harq_processes[current_harq_pid]; - + */ /*nr_harq_status_t *current_harq_ack = &ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->harq_ack[nr_tti_rx]; nr_harq_status_t *harq_ack_dest = &ue->dlsch[next1_thread_id][eNB_id][0]->harq_ack[nr_tti_rx]; nr_harq_status_t *harq_ack_dest1 = &ue->dlsch[next2_thread_id][eNB_id][0]->harq_ack[nr_tti_rx]; */ -copy_harq_proc_struct(harq_processes_dest, current_harq_processes); + //copy_harq_proc_struct(harq_processes_dest, current_harq_processes); //copy_ack_struct(harq_ack_dest, current_harq_ack); -copy_harq_proc_struct(harq_processes_dest1, current_harq_processes); +//copy_harq_proc_struct(harq_processes_dest1, current_harq_processes); //copy_ack_struct(harq_ack_dest1, current_harq_ack); if (nr_tti_rx==9) { @@ -5322,185 +4679,6 @@ return (0); } -#if 0 -#if defined(Rel10) || defined(Rel14) - -int phy_procedures_RN_UE_RX(uint8_t slot_rx, uint8_t next_slot, relaying_type_t r_type) -{ - - int do_proc =0; // do nothing by default - - switch(r_type) { - case no_relay: - do_proc=no_relay; // perform the normal UE operation - break; - - case multicast_relay: - if (slot_rx > 12) - do_proc = 0; // do nothing - else // SF#1, SF#2, SF3, SF#3, SF#4, SF#5, SF#6(do rx slot 12) - do_proc = multicast_relay ; // do PHY procedures UE RX - - break; - - default: // should'not be here - LOG_W(PHY,"Not supported relay type %d, do nothing \n", r_type); - do_proc= 0; - break; - } - - return do_proc; -} -#endif - -void phy_procedures_UE_lte(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag,uint8_t do_pdcch_flag,runmode_t mode, - relaying_type_t r_type) -{ -#if defined(ENABLE_ITTI) - MessageDef *msg_p; - const char *msg_name; - instance_t instance; - unsigned int Mod_id; - int result; -#endif - - int frame_rx = proc->frame_rx; - int frame_tx = proc->frame_tx; - int nr_tti_rx = proc->nr_tti_rx; - int nr_tti_tx = proc->nr_tti_tx; - //#ifdef UE_NR_PHY_DEMO - // int nr_tti_rx = proc->nr_tti_rx; - // int nr_tti_tx = proc->nr_tti_tx; - //#endif - -#undef DEBUG_PHY_PROC - - UE_L2_STATE_t ret; - int slot; - - if (ue->mac_enabled == 0) { - ue->UE_mode[eNB_id]=PUSCH; - } - - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_LTE,1); -#if UE_TIMING_TRACE - start_meas(&ue->phy_proc[ue->current_thread_id[nr_tti_rx]]); -#endif -#if defined(ENABLE_ITTI) - - do { - // Checks if a message has been sent to PHY sub-task - itti_poll_msg (TASK_PHY_UE, &msg_p); - - if (msg_p != NULL) { - msg_name = ITTI_MSG_NAME (msg_p); - instance = ITTI_MSG_INSTANCE (msg_p); - Mod_id = instance - NB_eNB_INST; - - switch (ITTI_MSG_ID(msg_p)) { - case PHY_FIND_CELL_REQ: - LOG_I(PHY, "[UE %d] Received %s\n", Mod_id, msg_name); - - /* TODO process the message */ - break; - - default: - LOG_E(PHY, "[UE %d] Received unexpected message %s\n", Mod_id, msg_name); - break; - } - - result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - } - } while(msg_p != NULL); - -#endif - - for (slot=0;slot<2;slot++) { - - if ((nr_subframe_select(&ue->frame_parms,nr_tti_tx)==SF_UL)|| - (ue->frame_parms.frame_type == FDD)) { - phy_procedures_UE_TX(ue,proc,eNB_id,abstraction_flag,mode,r_type); - } - - if ((nr_subframe_select(&ue->frame_parms,nr_tti_rx)==SF_DL) || - (ue->frame_parms.frame_type == FDD)) { -#if defined(Rel10) || defined(Rel14) - - if (phy_procedures_RN_UE_RX(nr_tti_rx, nr_tti_tx, r_type) != 0 ) -#endif - phy_procedures_UE_RX(ue,proc,eNB_id,abstraction_flag,do_pdcch_flag,mode,r_type); - } - - if ((nr_subframe_select(&ue->frame_parms,nr_tti_tx)==SF_S) && - (slot==1)) { - phy_procedures_UE_S_TX(ue,eNB_id,abstraction_flag,r_type); - } - - if ((nr_subframe_select(&ue->frame_parms,nr_tti_rx)==SF_S) && - (slot==0)) { -#if defined(Rel10) || defined(Rel14) - - if (phy_procedures_RN_UE_RX(nr_tti_rx, nr_tti_tx, r_type) != 0 ) -#endif - phy_procedures_UE_RX(ue,proc,eNB_id,abstraction_flag,do_pdcch_flag,mode,r_type); - } - - if (ue->mac_enabled==1) { - if (slot==0) { - //#ifdef UE_NR_PHY_DEMO - ret = mac_xface->ue_scheduler(ue->Mod_id, - frame_rx, - proc->subframe_rx, - nr_tti_rx%(ue->frame_parms.ttis_per_subframe), - frame_tx, - proc->subframe_tx, - nr_tti_tx%(ue->frame_parms.ttis_per_subframe), - nr_subframe_select(&ue->frame_parms,nr_tti_tx), - eNB_id, - 0/*FIXME CC_id*/); - //#else - /* ret = mac_xface->ue_scheduler(ue->Mod_id, - frame_rx, - nr_tti_rx, - frame_tx, - nr_tti_tx, - nr_subframe_select(&ue->frame_parms,nr_tti_tx), - eNB_id,*/ - // 0/*FIXME CC_id*/); - //#endif - - if (ret == CONNECTION_LOST) { - LOG_E(PHY,"[UE %d] Frame %d, nr_tti_rx %d RRC Connection lost, returning to PRACH\n",ue->Mod_id, - frame_rx,nr_tti_tx); - ue->UE_mode[eNB_id] = PRACH; - // mac_xface->macphy_exit("Connection lost"); - } else if (ret == PHY_RESYNCH) { - LOG_E(PHY,"[UE %d] Frame %d, nr_tti_rx %d RRC Connection lost, trying to resynch\n", - ue->Mod_id, - frame_rx,nr_tti_tx); - ue->UE_mode[eNB_id] = RESYNCH; - // mac_xface->macphy_exit("Connection lost"); - } else if (ret == PHY_HO_PRACH) { - LOG_I(PHY,"[UE %d] Frame %d, nr_tti_rx %d, return to PRACH and perform a contention-free access\n", - ue->Mod_id,frame_rx,nr_tti_tx); - ue->UE_mode[eNB_id] = PRACH; - } - } - } - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_LTE,0); -#if UE_TIMING_TRACE - stop_meas(&ue->phy_proc[ue->current_thread_id[nr_tti_rx]]); -#endif - } // slot -} - - - - -#endif uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id) From 4178da5af8960e02a41d2eb22a889b1dea87059e Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 13:29:28 +0200 Subject: [PATCH 068/117] bugfixing hardcoded value --- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index 3a7af2e6be..19d8a1da21 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -1985,18 +1985,18 @@ void nr_dlsch_channel_level(int **dl_ch_estimates_ext, //============================================================================================== unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, - int **dl_ch_estimates, - int **rxdataF_ext, - int **dl_ch_estimates_ext, - unsigned short pmi, - unsigned char *pmi_ext, - unsigned int *rb_alloc, - unsigned char symbol, - unsigned short start_rb, - unsigned short nb_rb_pdsch, - unsigned char nr_tti_rx, - uint32_t high_speed_flag, - NR_DL_FRAME_PARMS *frame_parms) { + int **dl_ch_estimates, + int **rxdataF_ext, + int **dl_ch_estimates_ext, + unsigned short pmi, + unsigned char *pmi_ext, + unsigned int *rb_alloc, //unused in NR + unsigned char symbol, + unsigned short start_rb, + unsigned short nb_rb_pdsch, + unsigned char nr_tti_rx, + uint32_t high_speed_flag, + NR_DL_FRAME_PARMS *frame_parms) { @@ -2008,20 +2008,8 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, unsigned char pilots=0,j=0; - //symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; - pilots = (symbol==2) ? 1 : 0; //to updated from config - //l=symbol; - //nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; - k = frame_parms->first_carrier_offset + 516; //0 - - /* if (frame_parms->frame_type == TDD) { // TDD - sss_symb = nsymb-1; - pss_symb = 2; - } else { - sss_symb = (nsymb>>1)-2; - pss_symb = (nsymb>>1)-1; - }*/ - + pilots = (symbol==2) ? 1 : 0; //to updated from config!!! + k = frame_parms->first_carrier_offset + 12*start_rb; for (aarx=0; aarxnb_antennas_rx; aarx++) { From 02f39f140c11c0d694c290e61ce530203b1a1a54 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 14:26:27 +0200 Subject: [PATCH 069/117] hardcoding tbs_table=1 as UE only supports that. --- openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c b/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c index f8b7454067..9fb73fa994 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c @@ -126,7 +126,7 @@ void nr_get_tbs(nfapi_nr_dl_config_dlsch_pdu *dlsch_pdu, uint16_t N_RE, Ninfo, Ninfo_prime, C, TBS=0, R; uint8_t table_idx, Qm, n, scale; - table_idx = get_table_idx(mcs_table, dci_format, rnti_type, ss_type); + table_idx = 1; //get_table_idx(mcs_table, dci_format, rnti_type, ss_type); scale = ((table_idx==2)&&((Imcs==20)||(Imcs==26)))?11:10; N_RE = min(156, N_RE_prime)*dlsch_rel15->n_prb; From efe25b728dd9895d8aeebe7ba09c9046c5c47e5e Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 14:27:51 +0200 Subject: [PATCH 070/117] setting nb_symb to 9 at UE like in gNB --- openair1/PHY/NR_TRANSPORT/nr_dlsch.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 38 ++++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c index eb2e11fec4..59647cd45f 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c @@ -215,7 +215,7 @@ uint8_t nr_generate_pdsch(NR_gNB_DLSCH_t dlsch, nr_dlsch_encoding(harq->pdu, slot, &dlsch, &frame_parms); #ifdef DEBUG_DLSCH printf("PDSCH encoding:\nPayload:\n"); -for (int i=0; i>7; i++) { +for (int i=0; iB>>7; i++) { for (int j=0; j<16; j++) printf("0x%02x\t", harq->pdu[(i<<4)+j]); printf("\n"); diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 596523b108..d37d2a1fb8 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -3768,7 +3768,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, // to be updated by higher layer uint8_t nb_re_dmrs = 6; uint16_t length_dmrs = 1; - uint16_t nb_symb_sch = 8; + uint16_t nb_symb_sch = 9; if (dlsch0==NULL) AssertFatal(0,"dlsch0 should be defined at this level \n"); @@ -3833,20 +3833,20 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, // start ldpc decode for CW 0 dlsch0->harq_processes[harq_pid]->G = nr_get_G(dlsch0->harq_processes[harq_pid]->nb_rb, - nb_symb_sch, - nb_re_dmrs, - length_dmrs, - dlsch0->harq_processes[harq_pid]->Qm, - dlsch0->harq_processes[harq_pid]->Nl); + nb_symb_sch, + nb_re_dmrs, + length_dmrs, + dlsch0->harq_processes[harq_pid]->Qm, + dlsch0->harq_processes[harq_pid]->Nl); #if UE_TIMING_TRACE start_meas(&ue->dlsch_unscrambling_stats); #endif nr_dlsch_unscrambling(pdsch_vars->llr[0], - dlsch0->harq_processes[harq_pid]->G, + dlsch0->harq_processes[harq_pid]->G, 0, - ue->frame_parms.Nid_cell, - dlsch0->rnti); - + ue->frame_parms.Nid_cell, + dlsch0->rnti); + #if UE_TIMING_TRACE stop_meas(&ue->dlsch_unscrambling_stats); @@ -3913,11 +3913,11 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, { // start ldpc decode for CW 1 dlsch1->harq_processes[harq_pid]->G = nr_get_G(dlsch1->harq_processes[harq_pid]->nb_rb, - nb_symb_sch, - nb_re_dmrs, - length_dmrs, - dlsch1->harq_processes[harq_pid]->Qm, - dlsch1->harq_processes[harq_pid]->Nl); + nb_symb_sch, + nb_re_dmrs, + length_dmrs, + dlsch1->harq_processes[harq_pid]->Qm, + dlsch1->harq_processes[harq_pid]->Nl); #if UE_TIMING_TRACE start_meas(&ue->dlsch_unscrambling_stats); #endif @@ -4309,7 +4309,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][0]; - uint16_t nb_symb_sch = 8; // to be updated by higher layer + uint16_t nb_symb_sch = 9; // to be updated by higher layer uint8_t nb_symb_pdcch = pdcch_vars->coreset[0].duration; uint8_t dci_cnt = 0; @@ -4407,6 +4407,12 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN nb_symb_pdcch, //ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, (nb_symb_sch+nb_symb_pdcch-1)); //ue->frame_parms.symbols_per_tti>>1, + /* + write_output("rxF_ext.m","rxFe",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_ext[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); + write_output("rxF_comp.m","rxFc",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_comp0[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); + write_output("rxF_llr.m","rxFllr",ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->llr[0],(nb_symb_sch-1)*50*12+50*6,1,0); + */ + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_OUT); } From 1fcd5aaae27842e006fb907967450d52e59ea022 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 14:28:20 +0200 Subject: [PATCH 071/117] adding loglevel as command line option --- openair1/SIMULATION/NR_PHY/dlschsim.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 2e2ccb40e3..2a95768a3e 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -174,7 +174,7 @@ int main(int argc, char **argv) { //logInit(); randominit(0); - while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:M:N:F:R:P:")) != -1) { + while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:M:N:F:R:P:L:")) != -1) { switch (c) { case 'f': write_output_file = 1; @@ -315,6 +315,10 @@ int main(int argc, char **argv) { break; + case 'L': + loglvl = atoi(optarg); + break; + case 'm': Imcs = atoi(optarg); break; From e613294c67edb7aece8eb891bd6db2a67ff45642 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Mon, 1 Apr 2019 16:27:51 +0200 Subject: [PATCH 072/117] Add nr_ulschsim Test cases to autotests --- cmake_targets/autotests/test_case_list.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index 2c47513c34..5003125967 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1117,6 +1117,26 @@ 3 + + execution + nr_ulschsim Test cases. (Test1: 106 PRB), + (Test2: 217 PRB), + (Test3: 273 PRB) + + $OPENAIR_DIR/cmake_targets/build_oai + --phy_simulators -c + $OPENAIR_DIR/cmake_targets/autotests/tools/free_mem.bash + + $OPENAIR_DIR/targets/bin/nr_ulschsim.Rel15 + -R 106 -m9 -s13 -n100 + -R 217 -m15 -s15 -n100 + -R 273 -m19 -s20 -n100 + nr_ulschsim.test1 nr_ulschsim.test2 nr_ulschsim.test3 + PUSCH test OK + segmentation fault|assertion|exiting|fatal + 3 + + execution dlsim_tm4 test cases (Test 1: 10 MHz, R2.FDD (MCS 5), EVA5, -1dB), From 10674d9ba93c1394e65f8d7bb694898b60b91d23 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Mon, 1 Apr 2019 16:44:08 +0200 Subject: [PATCH 073/117] fixing PDSCH RB offset at gNB --- openair1/PHY/NR_TRANSPORT/nr_dlsch.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c index 59647cd45f..a881ae539e 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c @@ -308,16 +308,13 @@ for (int i=0; i>4; i++) { // Non interleaved VRB to PRB mapping - uint16_t start_sc = frame_parms.first_carrier_offset + frame_parms.ssb_start_subcarrier; - if (start_sc >= frame_parms.ofdm_symbol_size) - start_sc -= frame_parms.ofdm_symbol_size; - /*rel15->start_prb*NR_NB_SC_PER_RB + - ((pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_COMMON) && (pdcch_params.dci_format == NFAPI_NR_DL_DCI_FORMAT_1_0))?\ - ((frame_parms.ssb_start_subcarrier/NR_NB_SC_PER_RB + pdcch_params.rb_offset)*NR_NB_SC_PER_RB) : 0;*/ + uint16_t start_sc = frame_parms.first_carrier_offset + rel15->start_prb*NR_NB_SC_PER_RB; + if (start_sc >= frame_parms.ofdm_symbol_size) + start_sc -= frame_parms.ofdm_symbol_size; #ifdef DEBUG_DLSCH_MAPPING -printf("PDSCH resource mapping started (start SC %d\tstart symbol %d\tN_PRB %d\tnb_symbols %d)\n", -start_sc, rel15->start_symbol, rel15->n_prb, rel15->nb_symbols); + printf("PDSCH resource mapping started (start SC %d\tstart symbol %d\tN_PRB %d\tnb_symbols %d)\n", + start_sc, rel15->start_symbol, rel15->n_prb, rel15->nb_symbols); #endif for (int ap=0; apnb_layers; ap++) { From 6db55b2f24d152e416c62db156300c254a6837cc Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Wed, 3 Apr 2019 11:26:39 +0200 Subject: [PATCH 074/117] - UE channel estimation no longer done in slot_fep. Also created dedicated memory for channel estimates of different channels - using nr_extract_dci_info instead of nr_generate_ue_ul_dlsch_params_from_dci as in phy_procedures_nr_ue. The latter was only a (poor) wrapper and not doing what the name suggests. also with FAPI things have to be done differently now. This will come in a next commit. - other minor changes to remove warning prepreatory changes --- openair1/PHY/INIT/nr_init_ue.c | 49 +++---- openair1/PHY/MODULATION/modulation_UE.h | 3 +- openair1/PHY/MODULATION/slot_fep_nr.c | 86 +----------- .../PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c | 4 +- .../nr_dl_channel_estimation.c | 36 +++-- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 2 - openair1/PHY/NR_UE_TRANSPORT/dci_nr.c | 2 +- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 85 +++--------- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 2 +- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 3 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 2 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 33 +++-- openair1/PHY/TOOLS/nr_phy_scope.c | 4 +- openair1/PHY/defs_nr_UE.h | 27 ++-- openair1/SCHED_NR/fapi_nr_l1.h | 3 - openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 131 +++++++++++------- openair1/SIMULATION/NR_PHY/dlsim.c | 11 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 11 +- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 14 ++ 19 files changed, 213 insertions(+), 295 deletions(-) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index 986d423034..87490b817c 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -607,6 +607,7 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c pdsch->rxdataF_uespec_pilots = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->rxdataF_comp0 = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->rho = (int32_t**)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) ); + pdsch->dl_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_bf_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pdsch->dl_bf_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); @@ -628,6 +629,7 @@ void phy_init_nr_ue__PDSCH( NR_UE_PDSCH* const pdsch, const NR_DL_FRAME_PARMS* c pdsch->rxdataF_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); pdsch->rxdataF_uespec_pilots[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->N_RB_DL*12); pdsch->rxdataF_comp0[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); + pdsch->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->ofdm_symbol_size*7*2); pdsch->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); pdsch->dl_bf_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * fp->ofdm_symbol_size*7*2); pdsch->dl_bf_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); @@ -724,22 +726,6 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, } } - // Channel estimates - for (eNB_id=0; eNB_id<7; eNB_id++) { - for (th_id=0; th_idcommon_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id] = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates_time[eNB_id] = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); - } - - for (i=0; inb_antennas_rx; i++) - for (j=0; j<4; j++) { - int idx = (j<<1) + i; - for (th_id=0; th_idcommon_vars_rx_data_per_thread[th_id].dl_ch_estimates[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) ); - common_vars->common_vars_rx_data_per_thread[th_id].dl_ch_estimates_time[eNB_id][idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 ); - } - } - } // DLSCH for (eNB_id=0; eNB_idn_connected_eNB; eNB_id++) { @@ -832,30 +818,32 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, (*pdcch_vars_th)[th_id][eNB_id]->rho = (int32_t**)malloc16( fp->nb_antennas_rx*sizeof(int32_t*) ); (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); - } - - for (i=0; inb_antennas_rx; i++) { - //ue_pdcch_vars[eNB_id]->rho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(fp->N_RB_DL*12*7*2) ); - for (th_id=0; th_idrho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(100*12*4) ); - } - for (j=0; j<4; j++) { //fp->nb_antennas_tx; j++) - int idx = (j<<1)+i; - // size_t num = 7*2*fp->N_RB_DL*12; - size_t num = 4*100*12; // 4 symbols, 100 PRBs, 12 REs per PRB - for (th_id=0; th_iddl_ch_estimates = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_time = (int32_t**)malloc16_clear(8*sizeof(int32_t*)); + + for (i=0; inb_antennas_rx; i++) { + (*pdcch_vars_th)[th_id][eNB_id]->rho[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*(100*12*4) ); + for (j=0; j<4; j++) { + int idx = (j<<1) + i; + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->symbols_per_slot*(fp->ofdm_symbol_size+LTE_CE_FILTER_LENGTH) ); + (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_time[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 ); + + // size_t num = 7*2*fp->N_RB_DL*12; + size_t num = 4*100*12; // 4 symbols, 100 PRBs, 12 REs per PRB (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_comp[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_rho_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); - } - } + } + } } // PBCH pbch_vars[eNB_id]->rxdataF_ext = (int32_t**)malloc16( fp->nb_antennas_rx*sizeof(int32_t*) ); pbch_vars[eNB_id]->rxdataF_comp = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); + pbch_vars[eNB_id]->dl_ch_estimates = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pbch_vars[eNB_id]->dl_ch_estimates_ext = (int32_t**)malloc16_clear( 8*sizeof(int32_t*) ); pbch_vars[eNB_id]->llr = (int16_t*)malloc16_clear( 1920 );// prach_vars[eNB_id]->prachF = (int16_t*)malloc16_clear( sizeof(int)*(7*2*sizeof(int)*(fp->ofdm_symbol_size*12)) ); @@ -867,6 +855,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, for (j=0; j<4; j++) {//fp->nb_antennas_tx;j++) { int idx = (j<<1)+i; pbch_vars[eNB_id]->rxdataF_comp[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*20*12*4 ); + pbch_vars[eNB_id]->dl_ch_estimates[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*7*2*sizeof(int)*(fp->ofdm_symbol_size) ); pbch_vars[eNB_id]->dl_ch_estimates_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*20*12*4 ); } } diff --git a/openair1/PHY/MODULATION/modulation_UE.h b/openair1/PHY/MODULATION/modulation_UE.h index 63c3637886..2bb04bd43a 100644 --- a/openair1/PHY/MODULATION/modulation_UE.h +++ b/openair1/PHY/MODULATION/modulation_UE.h @@ -52,8 +52,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *phy_vars_ue, unsigned char l, unsigned char Ns, int sample_offset, - int no_prefix, - NR_CHANNEL_EST_t channel); + int no_prefix); int slot_fep_mbsfn(PHY_VARS_UE *phy_vars_ue, unsigned char l, diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c index 6ce486e3a0..c6a6d93c18 100644 --- a/openair1/PHY/MODULATION/slot_fep_nr.c +++ b/openair1/PHY/MODULATION/slot_fep_nr.c @@ -35,16 +35,14 @@ #endif*/ int nr_slot_fep(PHY_VARS_NR_UE *ue, - unsigned char l, + unsigned char symbol, unsigned char Ns, int sample_offset, - int no_prefix, - NR_CHANNEL_EST_t channel) + int no_prefix) { NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; NR_UE_COMMON *common_vars = &ue->common_vars; unsigned char aa; - unsigned char symbol = l;//+((7-frame_parms->Ncp)*(Ns&1)); ///symbol within sub-frame unsigned int nb_prefix_samples; unsigned int nb_prefix_samples0; if (ue->is_synchronized) { @@ -60,19 +58,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, //int i; unsigned int frame_length_samples = frame_parms->samples_per_subframe * 10; unsigned int rx_offset; - NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[Ns]][0]; - uint16_t coreset_start_subcarrier = frame_parms->first_carrier_offset;//+((int)floor(frame_parms->ssb_start_subcarrier/NR_NB_SC_PER_RB)+pdcch_vars->coreset[0].rb_offset)*NR_NB_SC_PER_RB; - uint16_t nb_rb_coreset = 0; - uint16_t bwp_start_subcarrier = frame_parms->first_carrier_offset;//+516; - uint16_t nb_rb_pdsch = 50; - uint8_t p=0; - uint8_t l0 = pdcch_vars->coreset[0].duration; - uint64_t coreset_freq_dom = pdcch_vars->coreset[0].frequencyDomainResources; - for (int i = 0; i < 45; i++) { - if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> i) & 0x1) nb_rb_coreset++; - } - nb_rb_coreset = 6 * nb_rb_coreset; - //printf("corset duration %d nb_rb_coreset %d\n", l0, nb_rb_coreset); + void (*dft)(int16_t *,int16_t *, int); int tmp_dft_in[8192] __attribute__ ((aligned (32))); // This is for misalignment issues for 6 and 15 PRBs @@ -146,7 +132,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, nb_prefix_samples,nb_prefix_samples0,slot_offset,sample_offset,rx_offset,frame_length_samples); #endif - if (l==0) { + if (symbol==0) { if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) memcpy((short *)&common_vars->rxdata[aa][frame_length_samples], @@ -171,7 +157,7 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, #endif } } else { - rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// + + rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*symbol;// + // (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1); if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) @@ -206,68 +192,6 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue, #endif } - if (ue->perfect_ce == 0) { - - switch(channel){ - case NR_PBCH_EST: - break; - - case NR_PDCCH_EST: - -#ifdef DEBUG_FEP - printf("PDCCH Channel estimation aatx %d, slot %d, symbol %d start_sc %d\n",aa,Ns,l,coreset_start_subcarrier); -#endif -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); -#endif - nr_pdcch_channel_estimation(ue,0, - Ns, - l, - symbol, - coreset_start_subcarrier, - nb_rb_coreset); -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); -#endif - - break; - - case NR_PDSCH_EST: -#ifdef DEBUG_FEP - printf("Channel estimation aatx %d, slot %d, symbol %d\n",aa,Ns,l); -#endif -#if UE_TIMING_TRACE - start_meas(&ue->dlsch_channel_estimation_stats); -#endif - - ue->frame_parms.nushift = (p>>1)&1;; - - if (symbol ==l0) - nr_pdsch_channel_estimation(ue,0, - Ns, - p, - l, - symbol, - bwp_start_subcarrier, - nb_rb_pdsch); - -#if UE_TIMING_TRACE - stop_meas(&ue->dlsch_channel_estimation_stats); -#endif - - break; - - case NR_SSS_EST: - break; - - default: - LOG_E(PHY,"[UE][FATAL] Unknown channel format %d\n",channel); - return(-1); - break; - } - - } - #ifdef DEBUG_FEP printf("slot_fep: done\n"); #endif 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 f3cd1a29f3..24ca3d1ad6 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c @@ -60,8 +60,8 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, temp = 0; for (aa=0; aanb_antennas_rx; aa++) { - Re = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[(i<<1)]; - Im = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[1+(i<<1)]; + Re = ((int16_t*)ue->pdcch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time[aa])[(i<<1)]; + Im = ((int16_t*)ue->pdcch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time[aa])[1+(i<<1)]; temp += (Re*Re/2) + (Im*Im/2); } 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 917734f8ec..0ab83712d8 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c @@ -22,12 +22,10 @@ #include -//#include "defs.h" -//#include "SCHED/defs.h" -#include "PHY/defs_nr_UE.h" +#include "nr_estimation.h" #include "PHY/NR_REFSIG/refsig_defs_ue.h" #include "filt16a_32.h" -#include "T.h" + //#define DEBUG_PDSCH //#define DEBUG_PDCCH @@ -211,7 +209,7 @@ 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; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pbch_vars[eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = ue->frame_parms.Nid_cell%4; @@ -413,7 +411,6 @@ int nr_pbch_channel_estimation(PHY_VARS_NR_UE *ue, int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol, unsigned short coreset_start_subcarrier, unsigned short nb_rb_coreset) @@ -428,7 +425,7 @@ int nr_pdcch_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; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = 1; @@ -616,16 +613,16 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, break; } - if( (Ns== 1) && (l == 0)) + if( (Ns== 1) && (symbol == 0)) { // do ifft of channel estimate for (aarx=0; aarxframe_parms.nb_antennas_rx; aarx++) for (p=0; pframe_parms.nb_antenna_ports_eNB; p++) { - if (ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset][(p<<1)+aarx]) + if (ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates[(p<<1)+aarx]) { - LOG_D(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns], l); - idft((int16_t*) &ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset][(p<<1)+aarx][0], - (int16_t*) ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates_time[eNB_offset][(p<<1)+aarx],1); + LOG_D(PHY,"Channel Impulse Computation Slot %d ThreadId %d Symbol %d \n", Ns, ue->current_thread_id[Ns], symbol); + idft((int16_t*) &ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates[(p<<1)+aarx][0], + (int16_t*) ue->pdcch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates_time[(p<<1)+aarx],1); } } } @@ -634,13 +631,12 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, } int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, - uint8_t eNB_offset, - unsigned char Ns, - unsigned short p, - unsigned char l, - unsigned char symbol, - unsigned short bwp_start_subcarrier, - unsigned short nb_rb_pdsch) + uint8_t eNB_offset, + unsigned char Ns, + unsigned short p, + unsigned char symbol, + unsigned short bwp_start_subcarrier, + unsigned short nb_rb_pdsch) { int pilot[1320] __attribute__((aligned(16))); unsigned char aarx; @@ -652,7 +648,7 @@ int nr_pdsch_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; - int **dl_ch_estimates =ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].dl_ch_estimates[eNB_offset]; + int **dl_ch_estimates =ue->pdsch_vars[ue->current_thread_id[Ns]][eNB_offset]->dl_ch_estimates; int **rxdataF=ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF; nushift = (p>>1)&1; diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 29400bbdc7..1a4250028e 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -45,7 +45,6 @@ int nr_pdcch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, - unsigned char l, unsigned char symbol, unsigned short coreset_start_subcarrier, unsigned short nb_rb_coreset); @@ -69,7 +68,6 @@ int nr_pdsch_channel_estimation(PHY_VARS_NR_UE *ue, uint8_t eNB_offset, unsigned char Ns, unsigned short p, - unsigned char l, unsigned char symbol, unsigned short bwp_start_subcarrier, unsigned short nb_rb_pdsch); diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index e280fcbdf7..f01a5ef60a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -843,7 +843,7 @@ int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue, printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in nr_pdcch_extract_rbs_single(rxdataF -> rxdataF_ext || dl_ch_estimates -> dl_ch_estimates_ext)\n"); #endif nr_pdcch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdcch_vars[eNB_id]->dl_ch_estimates, pdcch_vars[eNB_id]->rxdataF_ext, pdcch_vars[eNB_id]->dl_ch_estimates_ext, s, diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index c067142897..f962ac2a3c 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -95,11 +95,8 @@ int nr_extract_dci_info(PHY_VARS_NR_UE *ue, uint8_t dci_length, uint16_t rnti, uint64_t dci_pdu[2], - NR_DCI_INFO_EXTRACTED_t *nr_pdci_info_extracted, + fapi_nr_dci_pdu_rel15_t *nr_pdci_info_extracted, uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], - NR_DL_UE_HARQ_t *pdlsch0_harq, - NR_UE_DLSCH_t *pdlsch0, - NR_UE_ULSCH_t *ulsch0, NR_DCI_format_t dci_format, uint8_t nr_tti_rx, uint16_t n_RB_ULBWP, @@ -631,7 +628,7 @@ int nr_extract_dci_info(PHY_VARS_NR_UE *ue, case TB1_MCS: // 18 TB1_MCS: (field defined for -,-,-,format1_1,-,-,-,-) nr_pdci_info_extracted->tb1_mcs = (uint8_t)nr_dci_field(dci_pdu,dci_fields_sizes_format,dci_field); //(((((*(uint128_t *)dci_pdu) << (left_shift - dci_fields_sizes[dci_field][dci_format]))) & pdu_bitmap) >> (dci_length - dci_fields_sizes[dci_field][dci_format])); - if (nr_pdci_info_extracted->mcs < 29) pdlsch0_harq->mcs = nr_pdci_info_extracted->tb1_mcs; + //if (nr_pdci_info_extracted->mcs < 29) pdlsch0_harq->mcs = nr_pdci_info_extracted->tb1_mcs; #ifdef NR_PDCCH_DCI_TOOLS_DEBUG printf("\t\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_extract_dci_info) -> nr_pdci_info_extracted->tb1_mcs=%x\n",nr_pdci_info_extracted->tb1_mcs); #endif @@ -1025,98 +1022,50 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint16_t rnti, uint8_t dci_length, NR_DCI_format_t dci_format, - NR_UE_PDCCH *pdcch_vars, - NR_UE_PDSCH *pdsch_vars, - NR_UE_DLSCH_t **dlsch, - NR_UE_ULSCH_t *ulsch, NR_DL_FRAME_PARMS *frame_parms, PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated, - uint8_t beamforming_mode, uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], uint16_t n_RB_ULBWP, uint16_t n_RB_DLBWP, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES], - NR_DCI_INFO_EXTRACTED_t *nr_dci_info_extracted) + fapi_nr_dci_pdu_rel15_t *nr_dci_info_extracted) { /* * Note only format0_0 and format1_0 are implemented */ - //uint8_t harq_pid=0; uint8_t frame_type=frame_parms->frame_type; - //uint8_t tpmi=0; - NR_UE_DLSCH_t *dlsch0=NULL;//*dlsch1=NULL; - NR_DL_UE_HARQ_t *dlsch0_harq=NULL;//*dlsch1_harq=NULL; - NR_UE_ULSCH_t *ulsch0=NULL;//*ulsch1=NULL; - - - NR_DCI_INFO_EXTRACTED_t *ptr_nr_dci_info_extracted = nr_dci_info_extracted; - - uint8_t status=0; - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n", - dci_format,rnti,dci_length,dci_pdu[0],dci_pdu[1]); - #endif - + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_format,rnti,dci_length,dci_pdu[0],dci_pdu[1]); -// uint8_t dci_fields_sizes_format[NBR_NR_DCI_FIELDS] ={0}; -// for (int m=0; mactive = 0; - if (dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format] != 0) { // 27 HARQ_PROCESS_NUMBER (27 is the position in dci_fields_sizes array for field HARQ_PROCESS_NUMBER) - //for (int i=0; i<=HARQ_PROCESS_NUMBER; i++) left_shift = left_shift + dci_fields_sizes[i][dci_format]; - nr_dci_info_extracted->harq_process_number = (uint8_t)nr_dci_field(dci_pdu,dci_fields_sizes_format,HARQ_PROCESS_NUMBER); - //(((((*(uint128_t *)dci_pdu) << (left_shift - dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format]))) & pdu_bitmap) >> (dci_length - dci_fields_sizes[HARQ_PROCESS_NUMBER][dci_format])); - //left_shift = 0; - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> nr_dci_info_extracted->harq_process_number=%x\n",nr_dci_info_extracted->harq_process_number); - for (int i=0; i<1000; i++) printf("%d",i); - #endif - } + memset(nr_dci_info_extracted,0,sizeof(nr_dci_info_extracted)); + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Entering function nr_extract_dci_info(dci_format=%d) \n",dci_format); - dlsch0_harq = dlsch[0]->harq_processes[nr_dci_info_extracted->harq_process_number]; - ulsch0 = ulsch; - //printf("nr_dci_info_extracted.harq_process_number = %d\n",nr_dci_info_extracted.harq_process_number); - //printf("dlsch0 = %d\n",dlsch0); - //printf("dlsch0_harq = %d\n",dlsch0_harq); - - if (!dlsch[0]) return -1; - if (!ulsch) return -1; -*/ - memset(&nr_dci_info_extracted,0,sizeof(nr_dci_info_extracted)); -// printf("we reach this point\n"); - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Entering function nr_extract_dci_info(dci_format=%d) \n",dci_format); - #endif status = nr_extract_dci_info(ue, eNB_id, frame_type, dci_length, rnti, dci_pdu, - ptr_nr_dci_info_extracted,//&nr_dci_info_extracted, + nr_dci_info_extracted,//&nr_dci_info_extracted, dci_fields_sizes, - dlsch0_harq, - dlsch0, - ulsch0, dci_format, nr_tti_rx, n_RB_ULBWP, n_RB_DLBWP, crc_scrambled_values); - //printf("\n>>> inside nr_generate_ue_ul_dlsch_params_from_dci after nr_extract_dci_info: mcs=%d\n",nr_dci_info_extracted->mcs); - #ifdef NR_PDCCH_DCI_TOOLS_DEBUG - if(status == 0) { - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> bad DCI %d !!! \n",dci_format); - return(-1); - } - //printf("\n>>> inside nr_generate_ue_ul_dlsch_params_from_dci after nr_extract_dci_info: modified mcs=%d \n",nr_dci_info_extracted->mcs); - printf("\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Ending function nr_extract_dci_info()\n"); - #endif + + if(status == 0) { + LOG_W(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> bad DCI %d !!! \n",dci_format); + return(-1); + } + + LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Ending function nr_extract_dci_info()\n"); + + //fill + return(0); } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index 19d8a1da21..842277192c 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -342,7 +342,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, if (beamforming_mode==0) { //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0 //printf("start nr dlsch extract nr_tti_rx %d thread id %d \n", nr_tti_rx, ue->current_thread_id[nr_tti_rx]); nb_rb = nr_dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 40cbb0d23e..203317e932 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -296,8 +296,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) i, 0, ue->ssb_offset, - 0, - NR_PBCH_EST); + 0); #ifdef DEBUG_INITIAL_SYNCH LOG_I(PHY,"Calling sss detection (normal CP)\n"); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a50edecb2c..a71bf89450 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -456,7 +456,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, // symbol refers to symbol within SSB. symbol_offset is the offset of the SSB wrt start of slot for (symbol=1; symbol<4; symbol++) { nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF, - nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id], + nr_ue_pbch_vars->dl_ch_estimates, nr_ue_pbch_vars->rxdataF_ext, nr_ue_pbch_vars->dl_ch_estimates_ext, symbol, 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 e1727c4847..305dc1c810 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1731,16 +1731,31 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, uint32_t nr_get_G(uint16_t nb_rb, uint16_t nb_symb_sch,uint8_t nb_re_dmrs,uint16_t length_dmrs, uint8_t Qm, uint8_t Nl) ; uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, - short *dlsch_llr, - NR_DL_FRAME_PARMS *frame_parms, - NR_UE_DLSCH_t *dlsch, - NR_DL_UE_HARQ_t *harq_process, - uint32_t frame, - uint16_t nb_symb_sch, - uint8_t nr_tti_rx, - uint8_t harq_pid, - uint8_t is_crnti, + short *dlsch_llr, + NR_DL_FRAME_PARMS *frame_parms, + NR_UE_DLSCH_t *dlsch, + NR_DL_UE_HARQ_t *harq_process, + uint32_t frame, + uint16_t nb_symb_sch, + uint8_t nr_tti_rx, + uint8_t harq_pid, + uint8_t is_crnti, uint8_t llr8_flag); +int nr_extract_dci_info(PHY_VARS_NR_UE *ue, + uint8_t eNB_id, + lte_frame_type_t frame_type, + uint8_t dci_length, + uint16_t rnti, + uint64_t dci_pdu[2], + fapi_nr_dci_pdu_rel15_t *nr_pdci_info_extracted, + uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS], + NR_DCI_format_t dci_format, + uint8_t nr_tti_rx, + uint16_t n_RB_ULBWP, + uint16_t n_RB_DLBWP, + uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES]); + + /**@}*/ #endif diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c index 3dd16ff0da..d1f1d1bea8 100644 --- a/openair1/PHY/TOOLS/nr_phy_scope.c +++ b/openair1/PHY/TOOLS/nr_phy_scope.c @@ -590,8 +590,8 @@ void phy_scope_UE(FD_lte_phy_scope_ue *form, time = calloc(samples_per_frame,sizeof(float)); corr = calloc(samples_per_frame,sizeof(float)); - chest_t = (int16_t**) phy_vars_ue->common_vars.common_vars_rx_data_per_thread[phy_vars_ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id]; - chest_f = (int16_t**) phy_vars_ue->common_vars.common_vars_rx_data_per_thread[phy_vars_ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id]; + chest_t = (int16_t**) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_time; + chest_f = (int16_t**) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates; pbch_llr = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->llr; pbch_comp = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->rxdataF_comp[0]; diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index f447c6895e..6dda24c7f9 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -378,17 +378,6 @@ typedef struct { /// - second index: symbol [0..28*ofdm_symbol_size[ int32_t **rxdataF; - /// \brief Hold the channel estimates in frequency domain. - /// - first index: eNB id [0..6] (hard coded) - /// - second index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx - /// - third index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ - int32_t **dl_ch_estimates[7]; - - /// \brief Hold the channel estimates in time domain (used for tracking). - /// - first index: eNB id [0..6] (hard coded) - /// - second index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx - /// - third index: samples? [0..2*ofdm_symbol_size[ - int32_t **dl_ch_estimates_time[7]; } NR_UE_COMMON_PER_THREAD; typedef struct { @@ -438,6 +427,10 @@ typedef struct { /// - third index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - fourth index: ? [0..168*N_RB_DL[ int32_t **rxdataF_comp1[8][8]; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; /// \brief Downlink channel estimates extracted in PRBS. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ @@ -830,6 +823,14 @@ typedef struct { /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ int32_t **rxdataF_comp; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; + /// \brief Hold the channel estimates in time domain (used for tracking). + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..2*ofdm_symbol_size[ + int32_t **dl_ch_estimates_time; /// \brief Pointers to extracted channel estimates of PDCCH symbols. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..168*N_RB_DL[ @@ -897,6 +898,10 @@ typedef struct { /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..287] (hard coded) int32_t **rxdataF_comp; + /// \brief Hold the channel estimates in frequency domain. + /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx + /// - second index: samples? [0..symbols_per_tti*(ofdm_symbol_size+LTE_CE_FILTER_LENGTH)[ + int32_t **dl_ch_estimates; /// \brief Pointers to downlink channel estimates in frequency-domain extracted in PRBS. /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - second index: ? [0..287] (hard coded) diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 66eb0fada7..71ef6039f3 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -32,9 +32,6 @@ #include "PHY/defs_gNB.h" #include "PHY/phy_extern.h" -#include "PHY/LTE_TRANSPORT/transport_proto.h" -#include "SCHED/sched_eNB.h" -#include "SCHED/sched_common.h" #include "SCHED_NR/sched_nr.h" #include "nfapi_nr_interface.h" diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index d37d2a1fb8..ea012c8937 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -3178,12 +3178,41 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * } if ((dci_alloc_rx[i].format == format1_1)){ // This format not implemented at a first time. FIXME } - NR_DCI_INFO_EXTRACTED_t nr_dci_info_extracted; - #ifdef NR_PDCCH_SCHED_DEBUG - printf("<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Entering function nr_generate_ue_ul_dlsch_params_from_dci with eNB_id=%d dci_cnt=%d\n", - eNB_id, - dci_cnt); - #endif + + + uint8_t status=0; + + LOG_D(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_alloc_rx[i].format,dci_alloc_rx[i].rnti,dci_alloc_rx[i].dci_length,dci_alloc_rx[i].dci_pdu[0],dci_alloc_rx[i].dci_pdu[1]); + + memset(&ue->dci_ind.dci_list[i].dci,0,sizeof(fapi_nr_dci_pdu_rel15_t)); + + ue->dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti; + ue->dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format; + ue->dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE; + ue->dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L; + + status = nr_extract_dci_info(ue, + eNB_id, + ue->frame_parms.frame_type, + dci_alloc_rx[i].dci_length, + dci_alloc_rx[i].rnti, + dci_alloc_rx[i].dci_pdu, + &ue->dci_ind.dci_list[i].dci, + dci_fields_sizes, + dci_alloc_rx[i].format, + nr_tti_rx, + pdcch_vars2->n_RB_BWP[nb_searchspace_active], + pdcch_vars2->n_RB_BWP[nb_searchspace_active], + crc_scrambled_values); + + if(status == 0) { + LOG_W(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> bad DCI %d !!! \n",dci_alloc_rx[i].format); + return(-1); + } + + LOG_D(PHY,"<-NR_PDCCH_PHY_PROCEDURES_UE (nr_ue_pdcch_procedures)-> Ending function nr_extract_dci_info()\n"); + + /* nr_generate_ue_ul_dlsch_params_from_dci(ue, eNB_id, frame_rx, @@ -3204,12 +3233,8 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * pdcch_vars2->n_RB_BWP[nb_searchspace_active], crc_scrambled_values, &nr_dci_info_extracted); + */ - ue->dci_ind.dci_list[i].rnti = dci_alloc_rx[i].rnti; - ue->dci_ind.dci_list[i].dci_format = dci_alloc_rx[i].format; - ue->dci_ind.dci_list[i].n_CCE = dci_alloc_rx[i].firstCCE; - ue->dci_ind.dci_list[i].N_CCE = (int)dci_alloc_rx[i].L; - memcpy(&ue->dci_ind.dci_list[i].dci, &nr_dci_info_extracted, sizeof(fapi_nr_dci_pdu_rel15_t) ); } // end for loop dci_cnt @@ -3570,6 +3595,8 @@ void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB int harq_pid; int i_mod,eNB_id_i,dual_stream_UE; int first_symbol_flag=0; + uint16_t pdsch_start_rb = 0; + uint16_t pdsch_nb_rb = 50; if (dlsch0->active == 0) return; @@ -3577,40 +3604,22 @@ void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB for (m=s0;m<=s1;m++) { if (dlsch0 && (!dlsch1)) { + + if (m==s0) + nr_pdsch_channel_estimation(ue, + 0 /*eNB_id*/, + nr_tti_rx, + 0 /*p*/, + m, + ue->frame_parms.first_carrier_offset+pdsch_start_rb*12, + pdsch_nb_rb); + harq_pid = dlsch0->current_harq_pid; LOG_D(PHY,"[UE %d] PDSCH type %d active in nr_tti_rx %d, harq_pid %d Symbol %d\n",ue->Mod_id,pdsch,nr_tti_rx,harq_pid,m); - if ((pdsch==PDSCH) && - (ue->transmission_mode[eNB_id] == 5) && - (dlsch0->harq_processes[harq_pid]->dl_power_off==0) && - (ue->use_ia_receiver ==1)) { - dual_stream_UE = 1; - eNB_id_i = ue->n_connected_eNB; - i_mod = dlsch0->harq_processes[harq_pid]->Qm; - - } - else if((pdsch==PDSCH) && (ue->transmission_mode[eNB_id]==3)) - { - dual_stream_UE = rx_IC_dual_stream; - eNB_id_i = eNB_id; - i_mod = 0; - } - else { - dual_stream_UE = 0; - eNB_id_i = eNB_id+1; - i_mod = 0; - } - - //TM7 UE specific channel estimation here!!! - if (ue->transmission_mode[eNB_id]==7) { - if (ue->frame_parms.Ncp==0) { - //if ((m==3) || (m==6) || (m==9) || (m==12)) - //LOG_D(PHY,"[UE %d] dlsch->active in nr_tti_rx %d => %d, l=%d\n",phy_vars_ue->Mod_id,nr_tti_rx,phy_vars_ue->dlsch_ue[eNB_id][0]->active, l); - //lte_dl_bf_channel_estimation(ue,eNB_id,0,nr_tti_rx*2+(m>6?1:0),5,m); - } else { - LOG_E(PHY,"[UE %d]Beamforming channel estimation not supported yet for TM7 extented CP.\n",ue->Mod_id); - } - } + dual_stream_UE = 0; + eNB_id_i = eNB_id+1; + i_mod = 0; if ((m==s0) && (m<3)) first_symbol_flag = 1; @@ -4320,9 +4329,23 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN uint8_t next2_thread_id = next1_thread_id== (RX_NB_TH-1) ? 0:(next1_thread_id+1); */ + uint8_t coreset_start=0, coreset_start_set=0; + uint16_t coreset_count = 0; + uint64_t coreset_freq_dom = pdcch_vars->coreset[0].frequencyDomainResources; + for (int i = 0; i < 45; i++) { + if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> (44-i)) & 0x1) { + if (!coreset_start_set) { + coreset_start = i; + coreset_start_set = 1; + } + coreset_count++; + } + } + uint16_t coreset_nb_rb = 6 * coreset_count; + uint16_t coreset_start_rb = 6 * coreset_start; + #ifdef NR_PDCCH_SCHED nr_gold_pdcch(ue,0, 2); - LOG_D(PHY," ------ --> PDCCH ChannelComp/LLR Frame.slot %d.%d ------ \n", frame_rx%1024, nr_tti_rx); for (uint16_t l=0; lframe_parms.first_carrier_offset+coreset_start_rb*12, + coreset_nb_rb); + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT); #if UE_TIMING_TRACE stop_meas(&ue->ofdm_demod_stats); @@ -4379,8 +4409,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN m, //to be updated from higher layer nr_tti_rx, 0, - 0, - NR_PDSCH_EST); + 0); //printf("phy procedure pdsch start measurement\n"); nr_ue_measurement_procedures(m,ue,proc,eNB_id,(nr_tti_rx<<1),mode); @@ -4408,7 +4437,10 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN (nb_symb_sch+nb_symb_pdcch-1)); //ue->frame_parms.symbols_per_tti>>1, /* - write_output("rxF_ext.m","rxFe",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_ext[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); + write_output("rxF.m","rxF",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF[0][0],ue->frame_parms.ofdm_symbol_size*14,1,1); + write_output("rxF_ch.m","rxFch",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->dl_ch_estimates[0][0],ue->frame_parms.ofdm_symbol_size*14,1,1); + write_output("rxF_ch_ext.m","rxFche",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->dl_ch_estimates_ext[0][2*50*12],50*12,1,1); + write_output("rxF_ext.m","rxFe",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_ext[0][0],50*12*14,1,1); write_output("rxF_comp.m","rxFc",&ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->rxdataF_comp0[0][0],ue->frame_parms.N_RB_DL*12*14,1,1); write_output("rxF_llr.m","rxFllr",ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->llr[0],(nb_symb_sch-1)*50*12+50*6,1,0); */ @@ -4472,8 +4504,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN (ue->symbol_offset+i), //mu=1 case B nr_tti_rx, 0, - 0, - NR_PBCH_EST); + 0); #if UE_TIMING_TRACE start_meas(&ue->dlsch_channel_estimation_stats); diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1416905696..1db984fd74 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -45,11 +45,14 @@ #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED_NR/sched_nr.h" +#include "SCHED_NR/fapi_nr_l1.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" #include "LAYER2/NR_MAC_UE/mac_extern.h" +#include "LAYER2/NR_MAC_UE/mac_proto.h" +#include "LAYER2/NR_MAC_gNB/mac_proto.h" #include "NR_PHY_INTERFACE/NR_IF_Module.h" #include "NR_UE_PHY_INTERFACE/NR_IF_Module.h" @@ -77,8 +80,8 @@ int32_t get_uldl_offset(int nr_bandP) {return(0);} NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} -int8_t dummy_nr_ue_dl_indication(nr_downlink_indication_t *dl_info){return(0);} -int8_t dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} +int dummy_nr_ue_dl_indication(nr_downlink_indication_t *dl_info){return(0);} +int dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info){return(0);} lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) { return(SF_DL);} @@ -111,7 +114,7 @@ void config_common(int Mod_idP, // needed for some functions PHY_VARS_NR_UE ***PHY_vars_UE_g; -uint16_t conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; +short conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; int main(int argc, char **argv) { @@ -510,7 +513,7 @@ int main(int argc, char **argv) gNB_mac = RC.nrmac[0]; config_common(0,0,Nid_cell,78,ssb_pattern,(uint64_t)3640000000L,N_RB_DL); - config_nr_mib(0,0,1,kHz30,0,0,0,0); + config_nr_mib(0,0,1,kHz30,0,0,0,0,0); nr_l2_init_ue(); UE_mac = get_mac_inst(0); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index 1e5150c93f..def897433e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -385,19 +385,18 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, // Note: This should not be done in the MAC! for (int ii=0; iiulsch[ii]; + NR_gNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii][0]; if((ulsch != NULL) && (ulsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_ulsch UE %x \n", rnti); - clean_eNb_ulsch(ulsch); + LOG_W(MAC, "TODO: clean_eNb_ulsch UE %x \n", rnti); + //clean_eNb_ulsch(ulsch); } } for (int ii=0; iidlsch[ii][0]; if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - LOG_E(PHY,"Calling with wrong paramter type\n"); - clean_eNb_dlsch(dlsch); + LOG_W(MAC, "TODO: clean_eNb_dlsch UE %x \n", rnti); + //clean_eNb_dlsch(dlsch); } } diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 6f0bd9d595..97a417fea1 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -67,6 +67,10 @@ void nr_schedule_css_dlsch_phytest(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP); +void nr_schedule_uss_dlsch_phytest(module_id_t module_idP, + frame_t frameP, + sub_frame_t slotP); + void nr_configure_css_dci_initial(nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params, nr_scs_e scs_common, @@ -108,4 +112,14 @@ uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn); uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw); +void config_nr_mib(int Mod_idP, + int CC_idP, + int p_gNBP, + int subCarrierSpacingCommon, + uint32_t ssb_SubcarrierOffset, + int dmrs_TypeA_Position, + uint32_t pdcch_ConfigSIB1, + int cellBarred, + int intraFreqReselection); + #endif /*__LAYER2_NR_MAC_PROTO_H__*/ From f0fe613130dc4689f01142afe355f34c99a6ddc0 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Wed, 3 Apr 2019 11:51:08 +0200 Subject: [PATCH 075/117] fixing warning --- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index f962ac2a3c..48125a01f8 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -1039,7 +1039,7 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> dci_format=%d, rnti=%d, dci_length=%d, dci_pdu[0]=0x%lx, dci_pdu[1]=0x%lx\n",dci_format,rnti,dci_length,dci_pdu[0],dci_pdu[1]); - memset(nr_dci_info_extracted,0,sizeof(nr_dci_info_extracted)); + memset(nr_dci_info_extracted,0,sizeof(*nr_dci_info_extracted)); LOG_D(PHY,"\t<-NR_PDCCH_DCI_TOOLS_DEBUG (nr_generate_ue_ul_dlsch_params_from_dci) -> Entering function nr_extract_dci_info(dci_format=%d) \n",dci_format); From 05dd8743e945091d6766680afcef5f26a9f9eb44 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Wed, 3 Apr 2019 17:16:00 +0200 Subject: [PATCH 076/117] first version of UE FAPI handling for DLSCH. paramters from DCI are now handled by MAC and passed back to the PHY to program PDSCH. Still need to check parameters and take them into account in PHY. --- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 2 +- openair1/PHY/defs_nr_UE.h | 2 +- openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 34 ++++++++------------ openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 22 +++++++++---- openair1/SIMULATION/NR_PHY/dlsim.c | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 25 ++++---------- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 23 +++++++++---- 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index 48125a01f8..47409d2102 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -52,7 +52,7 @@ //#define DEBUG_DCI #define NR_PDCCH_DCI_TOOLS -//#define NR_PDCCH_DCI_TOOLS_DEBUG +#define NR_PDCCH_DCI_TOOLS_DEBUG typedef unsigned __int128 uint128_t; diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 6dda24c7f9..7d05f798e2 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -1020,7 +1020,7 @@ typedef struct { /// UE FAPI DCI request nr_dcireq_t dcireq; - // CHECK if we need those as they are also included in dl_indictation + // pointers to the next 2 strcutres are also included in dl_indictation /// UE FAPI indication for DLSCH reception fapi_nr_rx_indication_t rx_ind; /// UE FAPI indication for DCI reception diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 7c17987980..5c8d9f72f7 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -55,7 +55,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ // Note: we have to handle the thread IDs for this. To be revisited completely. NR_UE_PDCCH *pdcch_vars2 = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0]; NR_UE_DLSCH_t *dlsch0 = PHY_vars_UE_g[module_id][cc_id]->dlsch[thread_id][0][0]; - NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[0]; + NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[thread_id][0][0]; NR_DL_FRAME_PARMS frame_parms = PHY_vars_UE_g[module_id][cc_id]->frame_parms; PRACH_RESOURCES_t *prach_resources = PHY_vars_UE_g[module_id][cc_id]->prach_resources[0]; @@ -106,32 +106,24 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ uint8_t current_harq_pid = dlsch_config_pdu->harq_process_nbr; dlsch0->current_harq_pid = current_harq_pid; dlsch0->active = 1; + dlsch0->rnti = dl_config->dl_config_list[i].dlsch_config_pdu.rnti; //dlsch0->harq_processes[0]->mcs = &dlsch_config_pdu->mcs; - NR_DL_UE_HARQ_t dlsch0_harq = *(dlsch0->harq_processes[current_harq_pid]); + NR_DL_UE_HARQ_t *dlsch0_harq = dlsch0->harq_processes[current_harq_pid]; - //dlsch0->harq_processes[current_harq_pid]->nb_rb = dlsch_config_pdu->number_rbs; - - dlsch0_harq.nb_rb = dlsch_config_pdu->number_rbs; - dlsch0_harq.start_rb = dlsch_config_pdu->start_rb; - dlsch0_harq.nb_symbols = dlsch_config_pdu->number_symbols; - dlsch0_harq.start_symbol = dlsch_config_pdu->start_symbol; - dlsch0_harq.mcs = dlsch_config_pdu->mcs; - dlsch0_harq.DCINdi = dlsch_config_pdu->ndi; - dlsch0_harq.rvidx = dlsch_config_pdu->rv; + dlsch0_harq->nb_rb = dlsch_config_pdu->number_rbs; + dlsch0_harq->start_rb = dlsch_config_pdu->start_rb; + dlsch0_harq->nb_symbols = dlsch_config_pdu->number_symbols; + dlsch0_harq->start_symbol = dlsch_config_pdu->start_symbol; + dlsch0_harq->mcs = dlsch_config_pdu->mcs; + dlsch0_harq->DCINdi = dlsch_config_pdu->ndi; + dlsch0_harq->rvidx = dlsch_config_pdu->rv; dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; - dlsch0_harq.harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; - dlsch0_harq.harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; - printf(">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq.mcs); - //for (int j = 0 ; j<1000; j++) printf("\nk = %d",j); - -#if 0 - dlsch0->harq_processes[current_harq_pid]->mcs = dlsch_config_pdu->mcs; - dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; - //pdlsch0->rnti = rnti; -#endif + dlsch0_harq->harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; + dlsch0_harq->harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; + printf(">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq->mcs); } } }else{ diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index ea012c8937..d3f22dea54 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -119,6 +119,7 @@ uint8_t nr_dci_decoding_procedure(int s, format_found_t *format_found, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES]); +/* int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint8_t eNB_id, int frame, @@ -139,7 +140,7 @@ int nr_generate_ue_ul_dlsch_params_from_dci(PHY_VARS_NR_UE *ue, uint16_t n_RB_DLBWP, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES], NR_DCI_INFO_EXTRACTED_t *nr_dci_info_extracted); - +*/ #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706) extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; @@ -3150,7 +3151,6 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * #endif ue->dci_ind.number_of_dcis = dci_cnt; - ue->dl_indication.dci_ind = &ue->dci_ind; // hang on rx_ind instance for (int i=0; idci_ind.dci_list[i].dci, - dci_fields_sizes, + dci_fields_sizes_cnt[i], dci_alloc_rx[i].format, nr_tti_rx, pdcch_vars2->n_RB_BWP[nb_searchspace_active], @@ -3238,9 +3238,17 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * } // end for loop dci_cnt - // TODO: check where should we send up this message. - //ue->if_inst->dl_indication(&ue->dl_indication); - + // fill dl_indication message + ue->dl_indication.module_id = ue->Mod_id; + ue->dl_indication.cc_id = ue->CC_id; + ue->dl_indication.gNB_index = eNB_id; + ue->dl_indication.frame = frame_rx; + ue->dl_indication.slot = nr_tti_rx; + ue->dl_indication.rx_ind = NULL; //no data, only dci for now + ue->dl_indication.dci_ind = &ue->dci_ind; + + // send to mac + ue->if_inst->dl_indication(&ue->dl_indication); #if UE_TIMING_TRACE stop_meas(&ue->dlsch_rx_pdcch_stats); @@ -4383,7 +4391,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN LOG_I(PHY,"[UE %d] Frame %d, nr_tti_rx %d: found %d DCIs\n",ue->Mod_id,frame_rx,nr_tti_rx,dci_cnt); - if (0/*ue->no_timing_correction==0*/) { + if (ue->no_timing_correction==0) { LOG_I(PHY,"start adjust sync slot = %d no timing %d\n", nr_tti_rx, ue->no_timing_correction); nr_adjust_synch_ue(&ue->frame_parms, ue, diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1db984fd74..6916f001c1 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -527,7 +527,7 @@ int main(int argc, char **argv) UE->if_inst->ul_indication = dummy_nr_ue_ul_indication; - //mac->if_module = nr_ue_if_module_init(0); + UE_mac->if_module = nr_ue_if_module_init(0); // generate signal diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 7110a35331..b729a7beb8 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -186,8 +186,8 @@ int8_t nr_ue_process_dlsch(module_id_t module_id, int cc_id, uint8_t gNB_index, ul_config->ul_config_list[ul_config->number_pdus].pucch_config_pdu.twoPUCCH_PC_AdjustmentStates = 0; } - if(mac->if_module != NULL && mac->if_module->ul_indication != NULL){ - mac->if_module->dl_indication(&mac->scheduled_response); + if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL){ + mac->if_module->scheduled_response(&mac->scheduled_response); } return 0; } @@ -1281,10 +1281,11 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request; + const uint16_t n_RB_ULBWP = 106; const uint16_t n_RB_DLBWP = 106; -printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); + printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); switch(dci_format){ case format0_0: @@ -1741,8 +1742,6 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); /* PDSCH_TO_HARQ_FEEDBACK_TIME_IND (only if CRC scrambled by C-RNTI or CS-RNTI or new-RNTI)*/ dlsch_config_pdu_1_0->pdsch_to_harq_feedback_time_ind = dci->pdsch_to_harq_feedback_time_ind; - dl_config->number_pdus = dl_config->number_pdus + 1; - printf("\n>>> (nr_ue_procedures.c) rnti=%d dl_config->number_pdus=%d\n", dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.rnti, dl_config->number_pdus); @@ -1770,14 +1769,7 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); - if(mac->if_module != NULL && mac->if_module->dl_indication != NULL) - //printf(">>> mac->if_module->dl_indication(&mac->phy_config); \n"); - //for (int k=0;k<1000;k++) printf(">>> %d ",k); - //mac->if_module->dl_indication(&mac->dl_info); - //mac->if_module->dl_indication(&mac->dl_config_request); - mac->if_module->dl_indication(&mac->phy_config); - - + dl_config->number_pdus = dl_config->number_pdus + 1; break; case format1_1: @@ -1959,14 +1951,12 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); /* DMRS_SEQ_INI */ //FIXME!!! - dl_config->number_pdus = dl_config->number_pdus + 1; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); - if(mac->if_module != NULL && mac->if_module->dl_indication != NULL) - mac->if_module->dl_indication(&mac->phy_config); - + dl_config->number_pdus = dl_config->number_pdus + 1; + break; case format2_0: @@ -1986,7 +1976,6 @@ printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); } - if(rnti == SI_RNTI){ }else if(rnti == mac->ra_rnti){ diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index e391cc67b9..ccac534f1c 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -34,6 +34,7 @@ #include "mac_proto.h" #include "assertions.h" #include "LAYER2/NR_MAC_UE/mac_extern.h" +#include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include @@ -126,16 +127,26 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ uint32_t ret_mask = 0x0; module_id_t module_id = dl_info->module_id; NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); + fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request; - // clean up scheduled_response structure - + dl_config->number_pdus = 0; + ul_config->number_pdus = 0; + //hook up pointers + mac->scheduled_response.dl_config = dl_config; + mac->scheduled_response.ul_config = ul_config; + mac->scheduled_response.tx_request = &mac->tx_request; + mac->scheduled_response.module_id = dl_info->module_id; + mac->scheduled_response.CC_id = dl_info->cc_id; + mac->scheduled_response.frame = dl_info->frame; + mac->scheduled_response.slot = dl_info->slot; if(dl_info->dci_ind != NULL){ printf("[L2][IF MODULE][DL INDICATION][DCI_IND]\n"); for(i=0; idci_ind->number_of_dcis; ++i){ printf(">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis); fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci; - /* + ret_mask |= (handle_dci( dl_info->module_id, dl_info->cc_id, @@ -143,7 +154,7 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ dci, (dl_info->dci_ind->dci_list+i)->rnti, (dl_info->dci_ind->dci_list+i)->dci_format)) << FAPI_NR_DCI_IND; - */ + /*switch((dl_info->dci_ind->dci_list+i)->dci_type){ case FAPI_NR_DCI_TYPE_0_0: @@ -244,8 +255,8 @@ nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){ nr_ue_if_module_inst[module_id]->cc_mask=0; nr_ue_if_module_inst[module_id]->current_frame = 0; nr_ue_if_module_inst[module_id]->current_slot = 0; - nr_ue_if_module_inst[module_id]->phy_config_request = NULL; - nr_ue_if_module_inst[module_id]->scheduled_response = NULL; + nr_ue_if_module_inst[module_id]->phy_config_request = nr_ue_phy_config_request; + nr_ue_if_module_inst[module_id]->scheduled_response = nr_ue_scheduled_response; nr_ue_if_module_inst[module_id]->dl_indication = nr_ue_dl_indication; nr_ue_if_module_inst[module_id]->ul_indication = nr_ue_ul_indication; } From 67e1afd3ac588013e7bfe29f5e499c414a41ad98 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Wed, 3 Apr 2019 17:47:00 +0200 Subject: [PATCH 077/117] reactivating timing correction --- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index d37d2a1fb8..b61b57dc74 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -4353,7 +4353,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN LOG_I(PHY,"[UE %d] Frame %d, nr_tti_rx %d: found %d DCIs\n",ue->Mod_id,frame_rx,nr_tti_rx,dci_cnt); - if (0/*ue->no_timing_correction==0*/) { + if (ue->no_timing_correction==0) { LOG_I(PHY,"start adjust sync slot = %d no timing %d\n", nr_tti_rx, ue->no_timing_correction); nr_adjust_synch_ue(&ue->frame_parms, ue, From 48a103ea82a7f2c6de7f8980ac43715cf2904469 Mon Sep 17 00:00:00 2001 From: laurent Date: Wed, 3 Apr 2019 22:12:10 +0200 Subject: [PATCH 078/117] fixes --- cmake_targets/CMakeLists.txt | 6 +- common/utils/LOG/log.c | 630 ++++---- common/utils/LOG/log.h | 353 ++--- common/utils/threadPool/thread-pool.h | 10 +- common/utils/utils.h | 16 + executables/nr-ue.c | 77 +- executables/nr-uesoftmodem.h | 1 + openair1/PHY/NR_TRANSPORT/nr_dci_tools.c | 4 +- .../PHY/NR_UE_TRANSPORT/nr_initial_sync.c | 8 +- openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c | 11 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 8 +- .../PHY/NR_UE_TRANSPORT/nr_transport_ue.h | 2 +- openair1/PHY/TOOLS/cdot_prod.c | 116 -- openair1/PHY/TOOLS/tools_defs.h | 110 +- openair1/PHY/defs_nr_UE.h | 106 +- openair1/PHY/thread_NR_UE.h | 78 + openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 3 +- openair1/SIMULATION/NR_PHY/pbchsim.c | 6 +- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 2 + openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 + openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 8 +- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h | 4 +- targets/RT/USER/nr-ue.c | 1175 --------------- targets/RT/USER/nr-uesoftmodem.c | 1262 ----------------- targets/RT/USER/nr-uesoftmodem.h | 258 ---- 27 files changed, 765 insertions(+), 3495 deletions(-) create mode 100644 openair1/PHY/thread_NR_UE.h delete mode 100644 targets/RT/USER/nr-ue.c delete mode 100644 targets/RT/USER/nr-uesoftmodem.c delete mode 100644 targets/RT/USER/nr-uesoftmodem.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index cbe0cfd151..7f9a4d6494 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2397,7 +2397,7 @@ add_executable(nr-uesoftmodem ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h ${OPENAIR_DIR}/common/utils/threadPool/thread-pool.c - ${OPENAIR_DIR}/executables//nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/nr-uesoftmodem.c ${OPENAIR_DIR}/executables/nr-ue.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c @@ -2431,8 +2431,8 @@ add_executable(nr-uesoftmodem-nos1 ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c - ${OPENAIR_TARGETS}/RT/USER/nr-ue.c - ${OPENAIR_TARGETS}/RT/USER/nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/nr-ue.c + ${OPENAIR_DIR}/executables/nr-uesoftmodem.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c #${OPENAIR_TARGETS}/COMMON/create_tasks_ue.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index a92bdf11e4..1124a26b72 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -40,7 +40,7 @@ #include "assertions.h" #if defined(ENABLE_ITTI) -# include "intertask_interface.h" + #include "intertask_interface.h" #endif # include @@ -75,16 +75,14 @@ char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, "", LOG_BLUE, LOG_CYBL char *log_level_highlight_end[] = {LOG_RESET,LOG_RESET,LOG_RESET, LOG_RESET,LOG_RESET}; /*!< \brief Optional end-format strings for highlighting */ -int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) -{ - +int write_file_matlab(const char *fname,const char *vname,void *data,int length,int dec,char format) { FILE *fp=NULL; int i; if (data == NULL) - return -1; - //printf("Writing %d elements of type %d to %s\n",length,format,fname); + return -1; + //printf("Writing %d elements of type %d to %s\n",length,format,fname); if (format == 10 || format ==11 || format == 12 || format == 13 || format == 14) { fp = fopen(fname,"a+"); @@ -92,8 +90,6 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, fp = fopen(fname,"w+"); } - - if (fp== NULL) { printf("[OPENAIR][FILE OUTPUT] Cannot open file %s\n",fname); return(-1); @@ -102,121 +98,108 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, if (format != 10 && format !=11 && format != 12 && format != 13 && format != 14) fprintf(fp,"%s = [",vname); - switch (format) { - case 0: // real 16-bit + case 0: // real 16-bit + for (i=0; i 0)) + fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + else if (i == 2*(length-1)) + fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); + else if (i == 0) + fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); + } - break; + break; - case 9: // real unsigned 8-bit - for (i=0; i 0)) + fprintf(fp,"%d,",((short *)data)[i]); + else if (i == (length-1)) + fprintf(fp,"%d;",((short *)data)[i]); + else if (i == 0) + fprintf(fp,"\n%d,",((short *)data)[i]); + } - break; - - - case 10 : // case eren 16 bit complex : - - for (i=0; i 0)) - fprintf(fp,"%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); - else if (i == 2*(length-1)) - fprintf(fp,"%d + j*(%d);",((short *)data)[i],((short *)data)[i+1]); - else if (i == 0) - fprintf(fp,"\n%d + j*(%d),",((short *)data)[i],((short *)data)[i+1]); - - - - } - - break; - - case 11 : //case eren 16 bit real for channel magnitudes: - for (i=0; i 0)) - fprintf(fp,"%d,",((short *)data)[i]); - else if (i == (length-1)) - fprintf(fp,"%d;",((short *)data)[i]); - else if (i == 0) - fprintf(fp,"\n%d,",((short *)data)[i]); - } - - printf("\n eren: length :%d",length); - break; - - case 12 : // case eren for log2_maxh real unsigned 8 bit - fprintf(fp,"%d \n",((unsigned char *)&data)[0]); - break; + printf("\n eren: length :%d",length); + break; + case 12 : // case eren for log2_maxh real unsigned 8 bit + fprintf(fp,"%d \n",((unsigned char *)&data)[0]); + break; } if (format != 10 && format !=11 && format !=12 && format != 13 && format != 15) { @@ -235,131 +218,141 @@ int write_file_matlab(const char *fname,const char *vname,void *data,int length, void log_getconfig(log_t *g_log) { char *gloglevel = NULL; int consolelog ; - - paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC; paramdef_t logparams_level[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_logfile[MAX_LOG_PREDEF_COMPONENTS]; paramdef_t logparams_debug[sizeof(log_maskmap)/sizeof(mapping)]; paramdef_t logparams_dump[sizeof(log_maskmap)/sizeof(mapping)]; - int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX); - if (ret <0) { - fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); - return; - } -/* set LOG display options (enable/disable color, thread name, level ) */ + if (ret <0) { + fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); + return; + } + + /* set LOG display options (enable/disable color, thread name, level ) */ for(int i=0; iflag = g_log->flag | log_options[j].value; - break; - } else if (log_options[j+1].name == NULL){ - fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); - exit(-1); - } - } - } - -/* build the parameter array for setting per component log level and infile options */ + for(int j=0; log_options[j].name != NULL ; j++) { + if (strcmp(logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i],log_options[j].name) == 0) { + g_log->flag = g_log->flag | log_options[j].value; + break; + } else if (log_options[j+1].name == NULL) { + fprintf(stderr,"Unknown log option: %s\n",logparams_defaults[LOG_OPTIONS_IDX].strlistptr[i]); + exit(-1); + } + } + } + + /* build the parameter array for setting per component log level and infile options */ memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); + for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { if(g_log->log_component[i].name == NULL) { - g_log->log_component[i].name = malloc(16); - sprintf((char *)g_log->log_component[i].name,"comp%i?",i); - logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; - logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; + g_log->log_component[i].name = malloc(16); + sprintf((char *)g_log->log_component[i].name,"comp%i?",i); + logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; + logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; } + sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name); sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name); -/* workaround: all log options in existing configuration files use lower case component names - where component names include uppercase char in log.h.... */ - for (int j=0 ; jlog_component[i].level = map_str_to_int(log_level_names, *(logparams_level[i].strptr)); set_log(i, g_log->log_component[i].level); + if (*(logparams_logfile[i].uptr) == 1) - set_component_filelog(i); + set_component_filelog(i); } -/* build then read the debug and dump parameter array */ - for (int i=0;log_maskmap[i].name != NULL ; i++) { - sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); - sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); - logparams_debug[i].defuintval = 0; - logparams_debug[i].type = TYPE_UINT; - logparams_debug[i].paramflags = PARAMFLAG_BOOL; - logparams_debug[i].uptr = NULL; - logparams_debug[i].chkPptr = NULL; - logparams_debug[i].numelt = 0; - logparams_dump[i].defuintval = 0; - logparams_dump[i].type = TYPE_UINT; - logparams_dump[i].paramflags = PARAMFLAG_BOOL; - logparams_dump[i].uptr = NULL; - logparams_dump[i].chkPptr = NULL; - logparams_dump[i].numelt = 0; + /* build then read the debug and dump parameter array */ + for (int i=0; log_maskmap[i].name != NULL ; i++) { + sprintf(logparams_debug[i].optname, LOG_CONFIG_DEBUG_FORMAT, log_maskmap[i].name); + sprintf(logparams_dump[i].optname, LOG_CONFIG_DUMP_FORMAT, log_maskmap[i].name); + logparams_debug[i].defuintval = 0; + logparams_debug[i].type = TYPE_UINT; + logparams_debug[i].paramflags = PARAMFLAG_BOOL; + logparams_debug[i].uptr = NULL; + logparams_debug[i].chkPptr = NULL; + logparams_debug[i].numelt = 0; + logparams_dump[i].defuintval = 0; + logparams_dump[i].type = TYPE_UINT; + logparams_dump[i].paramflags = PARAMFLAG_BOOL; + logparams_dump[i].uptr = NULL; + logparams_dump[i].chkPptr = NULL; + logparams_dump[i].numelt = 0; } - config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); - config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1 ,CONFIG_STRING_LOG_PREFIX); -/* set the debug mask according to the debug parameters values */ + + config_get( logparams_debug,(sizeof(log_maskmap)/sizeof(mapping)) - 1,CONFIG_STRING_LOG_PREFIX); + config_get( logparams_dump,(sizeof(log_maskmap)/sizeof(mapping)) - 1,CONFIG_STRING_LOG_PREFIX); + + /* set the debug mask according to the debug parameters values */ for (int i=0; log_maskmap[i].name != NULL ; i++) { if (*(logparams_debug[i].uptr) ) - g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + g_log->debug_mask = g_log->debug_mask | log_maskmap[i].value; + if (*(logparams_dump[i].uptr) ) - g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; - } -/* log globally enabled/disabled */ + g_log->dump_mask = g_log->dump_mask | log_maskmap[i].value; + } + + /* log globally enabled/disabled */ set_glog_onlinelog(consolelog); } -int register_log_component(char *name, char *fext, int compidx) -{ -int computed_compidx=compidx; +int register_log_component(char *name, char *fext, int compidx) { + int computed_compidx=compidx; if (strlen(fext) > 3) { - fext[3]=0; /* limit log file extension to 3 chars */ + fext[3]=0; /* limit log file extension to 3 chars */ } + if (compidx < 0) { /* this is not a pre-defined component */ - for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { - if (g_log->log_component[i].name == NULL) { - computed_compidx=i; - break; - } + for (int i = MAX_LOG_PREDEF_COMPONENTS; i< MAX_LOG_COMPONENTS; i++) { + if (g_log->log_component[i].name == NULL) { + computed_compidx=i; + break; } + } } + if (computed_compidx >= 0 && computed_compidx log_component[computed_compidx].name = strdup(name); - g_log->log_component[computed_compidx].stream = stdout; - g_log->log_component[computed_compidx].filelog = 0; - g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/.%s */ - sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); + g_log->log_component[computed_compidx].name = strdup(name); + g_log->log_component[computed_compidx].stream = stdout; + g_log->log_component[computed_compidx].filelog = 0; + g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/.%s */ + sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); } else { - fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); + fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); } -return computed_compidx; + + return computed_compidx; } -int logInit (void) -{ +int logInit (void) { int i; g_log = calloc(1, sizeof(log_t)); @@ -367,10 +360,8 @@ int logInit (void) perror ("cannot allocated memory for log generation module \n"); exit(EXIT_FAILURE); } + memset(g_log,0,sizeof(log_t)); - - - register_log_component("PHY","log",PHY); register_log_component("MAC","log",MAC); register_log_component("OPT","log",OPT); @@ -386,143 +377,121 @@ int logInit (void) register_log_component("OTG_JITTER","dat",OTG_JITTER); register_log_component("OCG","",OCG); register_log_component("PERF","",PERF); - register_log_component("OIP","",OIP); - register_log_component("CLI","",CLI); - register_log_component("MSC","log",MSC); - register_log_component("OCM","log",OCM); - register_log_component("HW","",HW); - register_log_component("OSA","",OSA); - register_log_component("eRAL","",RAL_ENB); - register_log_component("mRAL","",RAL_UE); - register_log_component("ENB_APP","log",ENB_APP); - register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); - register_log_component("TMR","",TMR); - register_log_component("USIM","txt",USIM); - register_log_component("SIM","txt",SIM); - + register_log_component("OIP","",OIP); + register_log_component("CLI","",CLI); + register_log_component("MSC","log",MSC); + register_log_component("OCM","log",OCM); + register_log_component("HW","",HW); + register_log_component("OSA","",OSA); + register_log_component("eRAL","",RAL_ENB); + register_log_component("mRAL","",RAL_UE); + register_log_component("ENB_APP","log",ENB_APP); + register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT); + register_log_component("TMR","",TMR); + register_log_component("USIM","txt",USIM); + register_log_component("SIM","txt",SIM); /* following log component are used for the localization*/ register_log_component("LOCALIZE","log",LOCALIZE); register_log_component("NAS","log",NAS); register_log_component("UDP","",UDP_); - - register_log_component("GTPV1U","",GTPU); - - register_log_component("S1AP","",S1AP); register_log_component("X2AP","",X2AP); - - register_log_component("SCTP","",SCTP); register_log_component("X2AP","",X2AP); register_log_component("LOADER","log",LOADER); register_log_component("ASN","log",ASN); - - for (int i=0 ; log_level_names[i].name != NULL ; i++) - g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name - - - - + g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name g_log->filelog_name = "/tmp/openair.log"; - log_getconfig(g_log); - - // set all unused component items to 0, they are for non predefined components for (i=MAX_LOG_PREDEF_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); + memset(&(g_log->log_component[i]),0,sizeof(log_component_t)); } - printf("log init done\n"); + printf("log init done\n"); return 0; } char *log_getthreadname(char *threadname, int bufsize) { + int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; -int rt = pthread_getname_np(pthread_self(), threadname,bufsize) ; - if (rt == 0) - { - return threadname; - } else { - return "thread?"; - } + if (rt == 0) { + return threadname; + } else { + return "thread?"; + } } static int log_header(char *log_buffer, int buffsize, int comp, int level,const char *format) { char threadname[PR_SET_NAME]; -return snprintf(log_buffer, buffsize , "%s%s[%s]%c %s %s%s", - log_level_highlight_end[level], - ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), - g_log->log_component[comp].name, - ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), - ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), - format, - log_level_highlight_end[level]); + return snprintf(log_buffer, buffsize, "%s%s[%s]%c %s %s%s", + log_level_highlight_end[level], + ( (g_log->flag & FLAG_NOCOLOR)?"":log_level_highlight_start[level]), + g_log->log_component[comp].name, + ( (g_log->flag & FLAG_LEVEL)?g_log->level2string[level]:' '), + ( (g_log->flag & FLAG_THREAD)?log_getthreadname(threadname,PR_SET_NAME+1):""), + format, + log_level_highlight_end[level]); } -void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char* format, ... ) - { - char log_buffer[MAX_LOG_TOTAL]={0}; +void logRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, ... ) { + char log_buffer[MAX_LOG_TOTAL]= {0}; va_list args; - va_start(args, format); - - - - - log_header(log_buffer,MAX_LOG_TOTAL ,comp, level,format); + log_header(log_buffer,MAX_LOG_TOTAL,comp, level,format); g_log->log_component[comp].vprint(g_log->log_component[comp].stream,log_buffer, args); + fflush(g_log->log_component[comp].stream); va_end(args); - - } -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ) { -va_list args; -char *wbuf; +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ) { + va_list args; + char *wbuf; + switch(datatype) { + case LOG_DUMP_DOUBLE: + wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); + break; - switch(datatype) { - case LOG_DUMP_DOUBLE: - wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); - break; - case LOG_DUMP_CHAR: - default: - wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); - break; + case LOG_DUMP_CHAR: + default: + wbuf=malloc((buffsize * 3 ) + 64 + MAX_LOG_TOTAL); + break; + } + + if (wbuf != NULL) { + va_start(args, format); + int pos=log_header(wbuf,MAX_LOG_TOTAL,component, OAILOG_INFO,""); + int pos2=vsprintf(wbuf+pos,format, args); + pos=pos+pos2; + va_end(args); + + for (int i=0; ilog_component[component].print(g_log->log_component[component].stream,wbuf); free(wbuf); - } + } } -int set_log(int component, int level) -{ +int set_log(int component, int level) { /* Checking parameters */ DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); @@ -530,38 +499,34 @@ int set_log(int component, int level) OAILOG_ERR); if ( g_log->log_component[component].level != OAILOG_DISABLE ) - g_log->log_component[component].savedlevel = g_log->log_component[component].level; - g_log->log_component[component].level = level; + g_log->log_component[component].savedlevel = g_log->log_component[component].level; + g_log->log_component[component].level = level; return 0; } -void set_glog(int level) -{ +void set_glog(int level) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - set_log(c, level); + set_log(c, level); } - } -void set_glog_onlinelog(int enable) -{ +void set_glog_onlinelog(int enable) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { - if ( enable ) { - g_log->log_component[c].level = g_log->log_component[c].savedlevel; - g_log->log_component[c].vprint = vfprintf; - g_log->log_component[c].print = fprintf; - g_log->log_component[c].stream = stdout; - } else { - g_log->log_component[c].level = OAILOG_DISABLE; - } - } + if ( enable ) { + g_log->log_component[c].level = g_log->log_component[c].savedlevel; + g_log->log_component[c].vprint = vfprintf; + g_log->log_component[c].print = fprintf; + g_log->log_component[c].stream = stdout; + } else { + g_log->log_component[c].level = OAILOG_DISABLE; + } + } } -void set_glog_filelog(int enable) -{ -static FILE *fptr; +void set_glog_filelog(int enable) { + static FILE *fptr; if ( enable ) { fptr = fopen(g_log->filelog_name,"w"); @@ -574,33 +539,35 @@ static FILE *fptr; } else { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { g_log->log_component[c].filelog = 0; + if (fptr != NULL) { fclose(fptr); } + g_log->log_component[c].stream = stdout; - } - } + } + } } -void set_component_filelog(int comp) -{ - if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { - g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - g_log->log_component[comp].filelog = 1; +void set_component_filelog(int comp) { + if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { + g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; + g_log->log_component[comp].filelog = 1; } -void close_component_filelog(int comp) -{ - g_log->log_component[comp].filelog = 0; - if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { - fclose(g_log->log_component[comp].stream); - g_log->log_component[comp].stream = stdout; - } - g_log->log_component[comp].vprint = vfprintf; - g_log->log_component[comp].print = fprintf; - +void close_component_filelog(int comp) { + g_log->log_component[comp].filelog = 0; + + if (g_log->log_component[comp].stream != NULL && g_log->log_component[comp].stream != stdout ) { + fclose(g_log->log_component[comp].stream); + g_log->log_component[comp].stream = stdout; + } + + g_log->log_component[comp].vprint = vfprintf; + g_log->log_component[comp].print = fprintf; } /* @@ -608,8 +575,7 @@ void close_component_filelog(int comp) * with string value NULL */ /* map a string to an int. Takes a mapping array and a string as arg */ -int map_str_to_int(mapping *map, const char *str) -{ +int map_str_to_int(mapping *map, const char *str) { while (1) { if (map->name == NULL) { return(-1); @@ -624,8 +590,7 @@ int map_str_to_int(mapping *map, const char *str) } /* map an int to a string. Takes a mapping array and a value */ -char *map_int_to_str(mapping *map, int val) -{ +char *map_int_to_str(mapping *map, int val) { while (1) { if (map->name == NULL) { return NULL; @@ -639,8 +604,7 @@ char *map_int_to_str(mapping *map, int val) } } -int is_newline( char *str, int size) -{ +int is_newline( char *str, int size) { int i; for ( i = 0; i < size; i++ ) { @@ -653,85 +617,62 @@ int is_newline( char *str, int size) return 0; } -void logClean (void) -{ +void logClean (void) { int i; LOG_UI(PHY,"\n"); - - - for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - close_component_filelog(i); + close_component_filelog(i); } } - + #ifdef LOG_TEST -int main(int argc, char *argv[]) -{ - +int main(int argc, char *argv[]) { logInit(); - - test_log(); - return 1; } -int test_log(void) -{ +int test_log(void) { LOG_ENTER(MAC); // because the default level is DEBUG LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "1 debug MAC \n"); LOG_W(MAC, "1 warning MAC \n"); - set_log(EMU, OAILOG_INFO); set_log(MAC, OAILOG_WARNING); - LOG_I(EMU, "2 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_E(MAC, "2 error MAC\n"); LOG_D(MAC, "2 debug MAC \n"); LOG_W(MAC, "2 warning MAC \n"); LOG_I(MAC, "2 info MAC \n"); - - set_log(MAC, OAILOG_NOTICE); - LOG_ENTER(MAC); LOG_I(EMU, "3 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "3 debug MAC \n"); LOG_W(MAC, "3 warning MAC \n"); LOG_I(MAC, "3 info MAC \n"); - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_ENTER(MAC); LOG_I(EMU, "4 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "4 debug MAC \n"); LOG_W(MAC, "4 warning MAC \n"); LOG_I(MAC, "4 info MAC \n"); - - set_log(MAC, LOG_DEBUG); set_log(EMU, LOG_DEBUG); - LOG_I(LOG, "5 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); LOG_D(MAC, "5 debug MAC \n"); LOG_W(MAC, "5 warning MAC \n"); LOG_I(MAC, "5 info MAC \n"); - - set_log(MAC, LOG_TRACE); set_log(EMU, LOG_TRACE); - LOG_ENTER(MAC); LOG_I(LOG, "6 Starting OAI logs version %s Build date: %s on %s\n", BUILD_VERSION, BUILD_DATE, BUILD_HOST); @@ -739,7 +680,6 @@ int test_log(void) LOG_W(MAC, "6 warning MAC \n"); LOG_I(MAC, "6 info MAC \n"); LOG_EXIT(MAC); - return 0; } #endif diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index db73bd7f5b..8390c3af25 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -45,14 +45,15 @@ #include #include #ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS + #define __STDC_FORMAT_MACROS #endif #include #ifndef _GNU_SOURCE -#define _GNU_SOURCE + #define _GNU_SOURCE #endif #include #include "T.h" +#include /*----------------------------------------------------------------------------*/ #ifdef __cplusplus @@ -127,11 +128,11 @@ extern "C" { /** @defgroup macros to identify a debug entity * @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged - * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro + * it allows to dynamically activate or not blocks of code. The LOG_MASKMAP_INIT macro * is used to map a character string name to each debug bit, it allows to set or clear * the corresponding bit via the defined name, from the configuration or from the telnet * server. - * @brief + * @brief * @{*/ #define DEBUG_PRACH (1<<0) #define DEBUG_RU (1<<1) @@ -150,22 +151,22 @@ extern "C" { #define LOG_MASKMAP_INIT {\ - {"PRACH", DEBUG_PRACH},\ - {"RU", DEBUG_RU},\ - {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ - {"LTEESTIM", DEBUG_LTEESTIM},\ - {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ - {"ULSCH", DEBUG_ULSCH},\ - {"RRC", DEBUG_RRC},\ - {"PDCP", DEBUG_PDCP},\ - {"DFT", DEBUG_DFT},\ - {"ASN1", DEBUG_ASN1},\ - {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ - {"SECURITY", DEBUG_SECURITY},\ - {"NAS", DEBUG_NAS},\ - {"UE_TIMING", UE_TIMING},\ - {NULL,-1}\ -} + {"PRACH", DEBUG_PRACH},\ + {"RU", DEBUG_RU},\ + {"UE_PHYPROC", DEBUG_UE_PHYPROC},\ + {"LTEESTIM", DEBUG_LTEESTIM},\ + {"DLCELLSPEC", DEBUG_DLCELLSPEC},\ + {"ULSCH", DEBUG_ULSCH},\ + {"RRC", DEBUG_RRC},\ + {"PDCP", DEBUG_PDCP},\ + {"DFT", DEBUG_DFT},\ + {"ASN1", DEBUG_ASN1},\ + {"CTRLSOCKET", DEBUG_CTRLSOCKET},\ + {"SECURITY", DEBUG_SECURITY},\ + {"NAS", DEBUG_NAS},\ + {"UE_TIMING", UE_TIMING},\ + {NULL,-1}\ + } @@ -178,51 +179,51 @@ extern "C" { typedef enum { - MIN_LOG_COMPONENTS = 0, - PHY = MIN_LOG_COMPONENTS, - MAC, - EMU, - SIM, - OCG, - OMG, - OPT, - OTG, - OTG_LATENCY, - OTG_LATENCY_BG, - OTG_GP, - OTG_GP_BG, - OTG_JITTER, - RLC, - PDCP, - RRC, - NAS, - PERF, - OIP, - CLI, - MSC, - OCM, - UDP_, - GTPU, - SPGW, - S1AP, - SCTP, - HW, - OSA, - RAL_ENB, - RAL_UE, - ENB_APP, - FLEXRAN_AGENT, - TMR, - USIM, - LOCALIZE, - X2AP, - GNB_APP, - NR_RRC, - NR_MAC, - NR_PHY, - LOADER, - ASN, - MAX_LOG_PREDEF_COMPONENTS, + MIN_LOG_COMPONENTS = 0, + PHY = MIN_LOG_COMPONENTS, + MAC, + EMU, + SIM, + OCG, + OMG, + OPT, + OTG, + OTG_LATENCY, + OTG_LATENCY_BG, + OTG_GP, + OTG_GP_BG, + OTG_JITTER, + RLC, + PDCP, + RRC, + NAS, + PERF, + OIP, + CLI, + MSC, + OCM, + UDP_, + GTPU, + SPGW, + S1AP, + SCTP, + HW, + OSA, + RAL_ENB, + RAL_UE, + ENB_APP, + FLEXRAN_AGENT, + TMR, + USIM, + LOCALIZE, + X2AP, + GNB_APP, + NR_RRC, + NR_MAC, + NR_PHY, + LOADER, + ASN, + MAX_LOG_PREDEF_COMPONENTS, } comp_name_t; @@ -231,42 +232,42 @@ comp_name_t; typedef struct { - char *name; /*!< \brief string name of item */ - int value; /*!< \brief integer value of mapping */ + char *name; /*!< \brief string name of item */ + int value; /*!< \brief integer value of mapping */ } mapping; typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap ); typedef int(*log_print_func_t)(FILE *stream, const char *format, ... ); typedef struct { - const char *name; - int level; - int savedlevel; - int flag; - int filelog; - char *filelog_name; - FILE *stream; - log_vprint_func_t vprint; - log_print_func_t print; - /* SR: make the log buffer component relative */ - char log_buffer[MAX_LOG_TOTAL]; + const char *name; + int level; + int savedlevel; + int flag; + int filelog; + char *filelog_name; + FILE *stream; + log_vprint_func_t vprint; + log_print_func_t print; + /* SR: make the log buffer component relative */ + char log_buffer[MAX_LOG_TOTAL]; } log_component_t; typedef struct { - log_component_t log_component[MAX_LOG_COMPONENTS]; - char level2string[NUM_LOG_LEVEL]; - int flag; - char* filelog_name; - uint64_t debug_mask; - uint64_t dump_mask; + log_component_t log_component[MAX_LOG_COMPONENTS]; + char level2string[NUM_LOG_LEVEL]; + int flag; + char *filelog_name; + uint64_t debug_mask; + uint64_t dump_mask; } log_t; #if defined(ENABLE_ITTI) typedef enum log_instance_type_e { - LOG_INSTANCE_UNKNOWN, - LOG_INSTANCE_ENB, - LOG_INSTANCE_UE, + LOG_INSTANCE_UNKNOWN, + LOG_INSTANCE_ENB, + LOG_INSTANCE_UE, } log_instance_type_t; void log_set_instance_type (log_instance_type_t instance); @@ -277,9 +278,9 @@ void log_set_instance_type (log_instance_type_t instance); log_t *g_log; #else #ifdef __cplusplus - extern "C" { +extern "C" { #endif -extern log_t *g_log; + extern log_t *g_log; #ifdef __cplusplus } #endif @@ -289,7 +290,7 @@ extern log_t *g_log; /*----------------------------------------------------------------------------*/ int logInit (void); void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7))); -void log_dump(int component, void *buffer, int buffsize,int datatype, const char* format, ... ); +void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... ); int set_log(int component, int level); void set_glog(int level); @@ -332,22 +333,22 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_CONFIG_DUMP_FORMAT "%s_dump" #define LOG_CONFIG_HELP_OPTIONS " list of comma separated options to enable log module behavior. Available options: \n"\ - " nocolor: disable color usage in log messages\n"\ - " level: add log level indication in log messages\n"\ - " thread: add threads names in log messages\n" - + " nocolor: disable color usage in log messages\n"\ + " level: add log level indication in log messages\n"\ + " thread: add threads names in log messages\n" + + - /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* LOG globalconfiguration parameters */ -/* optname help paramflags XXXptr defXXXval type numelt */ +/* LOG globalconfiguration parameters */ +/* optname help paramflags XXXptr defXXXval type numelt */ /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ #define LOG_GLOBALPARAMS_DESC { \ -{LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ -{LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ -} + {LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL, "Default log level for all componemts\n", 0, strptr:(char **)&gloglevel, defstrval:log_level_names[2].name, TYPE_STRING, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE, "Default console output option, for all components\n", 0, iptr:&(consolelog), defintval:1, TYPE_INT, 0}, \ + {LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS, 0, strlistptr:NULL, defstrlistval:NULL, TYPE_STRINGLIST,0} \ + } #define LOG_OPTIONS_IDX 2 /*----------------------------------------------------------------------------------*/ @@ -359,23 +360,23 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int #define LOG_DUMP_DOUBLE 1 // debugging macros #define LOG_F LOG_I /* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */ -# if T_TRACER - /* per component, level dependant macros */ -# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) -# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) -# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) -# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) -# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) - /* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ +# if T_TRACER +/* per component, level dependant macros */ +# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) +# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) +# define LOG_I(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_INFO ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ;} else { T(T_LEGACY_ ## c ## _INFO, T_PRINTF(x)) ;}} while (0) +# define LOG_D(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_DEBUG ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ;} else { T(T_LEGACY_ ## c ## _DEBUG, T_PRINTF(x)) ;}} while (0) +# define LOG_T(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_TRACE ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_TRACE, x) ;} else { T(T_LEGACY_ ## c ## _TRACE, T_PRINTF(x)) ;}} while (0) +/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */ # define LOG_DUMPMSG(c, f, b, s, x...) do { if(g_log->dump_mask & f) log_dump(c, b, s, LOG_DUMP_CHAR, x) ;} while (0) /* */ # define nfapi_log(FILE, FNC, LN, COMP, LVL, F...) do { if (T_stdout) { logRecord_mt(__FILE__, __FUNCTION__, __LINE__,COMP, LVL, F) ;}} while (0) /* */ - /* bitmask dependant macros, to isolate debugging code */ +/* bitmask dependant macros, to isolate debugging code */ # define LOG_DEBUGFLAG(D) (g_log->debug_mask & D) - /* bitmask dependant macros, to generate debug file such as matlab file or message dump */ +/* bitmask dependant macros, to generate debug file such as matlab file or message dump */ # define LOG_DUMPFLAG(D) (g_log->dump_mask & D) # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */ - /* define variable only used in LOG macro's */ +/* define variable only used in LOG macro's */ # define LOG_VAR(A,B) A B # else /* T_TRACER: remove all debugging and tracing messages, except errors */ # define LOG_I(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)/* */ @@ -385,15 +386,15 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int # define LOG_T(c, x...) /* */ # define LOG_DUMPMSG(c, b, s, x...) /* */ -# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) +# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...) # define LOG_DEBUGFLAG(D) ( 0 ) -# define LOG_DUMPFLAG(D) ( 0 ) +# define LOG_DUMPFLAG(D) ( 0 ) # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) # define LOG_VAR(A,B) # endif /* T_TRACER */ /* avoid warnings for variables only used in LOG macro's but set outside debug section */ -#define GCC_NOTUSED __attribute__((unused)) -#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B +#define GCC_NOTUSED __attribute__((unused)) +#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B /* unfiltered macros, usefull for simulators or messages at init time, before log is configured */ #define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0) @@ -425,78 +426,82 @@ static __inline__ uint64_t rdtsc(void) { extern double cpuf; -static inline uint64_t checkTCPU(int timeout, char * file, int line) { - static __thread uint64_t lastCPUTime=0; - static __thread uint64_t last=0; - uint64_t cur=rdtsc(); - struct timespec CPUt; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); - uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; - double microCycles=(double)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) { - //struct timespec ts; - //clock_gettime(CLOCK_MONOTONIC, &ts); - printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, - duration, timeout, (long long)CPUTime-lastCPUTime ); - } - last=cur; - lastCPUTime=CPUTime; - return cur; +static inline uint64_t checkTCPU(int timeout, char *file, int line) { + static __thread uint64_t lastCPUTime=0; + static __thread uint64_t last=0; + uint64_t cur=rdtsc(); + struct timespec CPUt; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &CPUt); + uint64_t CPUTime=CPUt.tv_sec*1000*1000+CPUt.tv_nsec/1000; + double microCycles=(double)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) { + //struct timespec ts; + //clock_gettime(CLOCK_MONOTONIC, &ts); + printf("%s:%d lte-ue delay %d (exceed %d), CPU for this period: %lld\n", file, line, + duration, timeout, (long long)CPUTime-lastCPUTime ); + } + + last=cur; + lastCPUTime=CPUTime; + return cur; } -static inline unsigned long long checkT(int timeout, char * file, int line) { - static __thread unsigned long long last=0; - unsigned long long cur=rdtsc(); - int microCycles=(int)(cpuf*1000); - int duration=(int)((cur-last)/microCycles); - if ( last!=0 && duration > timeout ) - printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, - duration, timeout); - last=cur; - return cur; +static inline unsigned long long checkT(int timeout, char *file, int line) { + static __thread unsigned long long last=0; + unsigned long long cur=rdtsc(); + int microCycles=(int)(cpuf*1000); + int duration=(int)((cur-last)/microCycles); + + if ( last!=0 && duration > timeout ) + printf("%s:%d lte-ue delay %d (exceed %d)\n", file, line, + duration, timeout); + + last=cur; + return cur; } typedef struct m { - uint64_t iterations; - uint64_t sum; - uint64_t maxArray[11]; + uint64_t iterations; + uint64_t sum; + uint64_t maxArray[11]; } Meas; -static inline void printMeas(char * txt, Meas *M, int period) { - if (M->iterations%period == 0 ) { - char txt2[512]; - sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" - PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", - txt, - M->sum/M->iterations, - M->iterations, - M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], - M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); +static inline void printMeas(char *txt, Meas *M, int period) { + if (M->iterations%period == 0 ) { + char txt2[512]; + sprintf(txt2,"%s avg=%" PRIu64 " iterations=%" PRIu64 " max=%" + PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 ":%" PRIu64 "\n", + txt, + M->sum/M->iterations, + M->iterations, + M->maxArray[1],M->maxArray[2], M->maxArray[3],M->maxArray[4], M->maxArray[5], + M->maxArray[6],M->maxArray[7], M->maxArray[8],M->maxArray[9],M->maxArray[10]); #if DISABLE_LOG_X - printf("%s",txt2); + printf("%s",txt2); #else - LOG_W(PHY, "%s",txt2); + LOG_W(PHY, "%s",txt2); #endif - } + } } -static inline int cmpint(const void* a, const void* b) { - uint64_t* aa=(uint64_t*)a; - uint64_t* bb=(uint64_t*)b; - return (int)(*aa-*bb); +static inline int cmpint(const void *a, const void *b) { + uint64_t *aa=(uint64_t *)a; + uint64_t *bb=(uint64_t *)b; + return (int)(*aa-*bb); } -static inline void updateTimes(uint64_t start, Meas *M, int period, char * txt) { - if (start!=0) { - uint64_t end=rdtsc(); - long long diff=(end-start)/(cpuf*1000); - M->maxArray[0]=diff; - M->sum+=diff; - M->iterations++; - qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); - printMeas(txt,M,period); - } +static inline void updateTimes(uint64_t start, Meas *M, int period, char *txt) { + if (start!=0) { + uint64_t end=rdtsc(); + long long diff=(end-start)/(cpuf*1000); + M->maxArray[0]=diff; + M->sum+=diff; + M->iterations++; + qsort(M->maxArray, 11, sizeof(uint64_t), cmpint); + printMeas(txt,M,period); + } } #define check(a) do { checkT(a,__FILE__,__LINE__); } while (0) diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h index 6f34508c5a..aa0003fd8a 100644 --- a/common/utils/threadPool/thread-pool.h +++ b/common/utils/threadPool/thread-pool.h @@ -92,7 +92,7 @@ static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) if (nf->outF == NULL) nf->outF = msg; - if (nf->inF) + if (nf->inF != NULL) nf->inF->next = msg; nf->inF = msg; @@ -103,7 +103,7 @@ static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { mutexlock(nf->lockF); - while(!nf->outF) + while(nf->outF == NULL) condwait(nf->notifF, nf->lockF); notifiedFIFO_elt_t *ret=nf->outF; @@ -124,8 +124,12 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) { notifiedFIFO_elt_t *ret=nf->outF; - if (ret!=NULL) + if (ret!=NULL) { + if (nf->outF==nf->outF->next) + LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n"); + nf->outF=nf->outF->next; + } if (nf->outF==NULL) nf->inF=NULL; diff --git a/common/utils/utils.h b/common/utils/utils.h index cfe3df34b9..11db07056e 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -3,6 +3,9 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif void *calloc_or_fail(size_t size); void *malloc_or_fail(size_t size); @@ -14,4 +17,17 @@ int hex_string_to_hex_value (uint8_t *hex_value, const char *hex_string, int siz char *itoa(int i); +#define findInList(keY, result, list, element_type) {\ + int i;\ + for (i=0; iframe_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); - } else ue = PHY_vars_UE_g[UE_id][0]; - + ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); + memset(ue,0,sizeof(PHY_VARS_NR_UE)); + memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); ue->Mod_id = UE_id; ue->mac_enabled = 1; // initialize all signal buffers @@ -160,6 +156,7 @@ PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, */ typedef struct syncData_s { + UE_nr_rxtx_proc_t *proc; PHY_VARS_NR_UE *UE; } syncData_t; @@ -167,18 +164,13 @@ static void UE_synch(void *arg) { syncData_t *syncD=(syncData_t *) arg; int i, hw_slot_offset; PHY_VARS_NR_UE *UE = syncD->UE; - int current_band = 0; - int current_offset = 0; sync_mode_t sync_mode = pbch; int CC_id = UE->CC_id; int freq_offset=0; UE->is_synchronized = 0; if (UE->UE_scan == 0) { - int ind; - get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); - LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], oai_exit, openair0_cfg[0].rx_num_channels); @@ -197,7 +189,6 @@ static void UE_synch(void *arg) { sync_mode = pbch; } else { - current_band=0; LOG_E(PHY,"Fixme!\n"); /* for (i=0; irf_map.card].rx_num_channels; i++) { @@ -245,11 +236,10 @@ static void UE_synch(void *arg) { break; */ - case pbch: LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); - if (nr_initial_sync( UE, UE->mode ) == 0) { + if (nr_initial_sync( syncD->proc, UE, UE->mode ) == 0) { 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_slot; LOG_I(PHY,"Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", @@ -377,7 +367,6 @@ void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { UE_mac->scheduled_response.slot = proc->nr_tti_rx; nr_ue_scheduled_response(&UE_mac->scheduled_response); //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); - printf("Processing slot %d\n",proc->nr_tti_rx); #ifdef UE_SLOT_PARALLELISATION phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); #else @@ -548,10 +537,6 @@ void *UE_thread(void *arg) { AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); notifiedFIFO_t nf; initNotifiedFIFO(&nf); - bool syncRunning=false; - notifiedFIFO_elt_t *syncMsg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); - syncData_t *syncD=(syncData_t *)NotifiedFifoData(syncMsg); - syncD->UE=UE; int nbSlotProcessing=0; int thread_idx=0; notifiedFIFO_elt_t *processingMsg[RX_NB_TH]; @@ -562,8 +547,13 @@ void *UE_thread(void *arg) { tmp->UE=UE; } + bool syncRunning=false; + notifiedFIFO_elt_t *syncMsg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); + syncData_t *syncD=(syncData_t *)NotifiedFifoData(syncMsg); + syncD->UE=UE; + syncD->proc=&((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc; const int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; - int absolute_slot=-1; + int absolute_slot, decoded_frame_rx=INT_MAX, trashed_frames=0; while (!oai_exit) { if (!syncD->UE->is_synchronized) { @@ -572,11 +562,14 @@ void *UE_thread(void *arg) { if (res) { syncRunning=false; - } else + } else { trashFrame(UE, ×tamp); + trashed_frames++; + } } else { readFrame(UE, ×tamp); pushTpool(Tpool, syncMsg); + trashed_frames=0; syncRunning=true; } @@ -588,7 +581,6 @@ void *UE_thread(void *arg) { syncInFrame(UE, ×tamp); UE->rx_offset=0; UE->time_sync_cell=0; - //printf("first stream frame rx %d\n",UE->proc.proc_rxtx[0].frame_rx); // read in first symbol AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == UE->rfdevice.trx_read_func(&UE->rfdevice, @@ -596,12 +588,21 @@ void *UE_thread(void *arg) { (void **)UE->common_vars.rxdata, UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, UE->frame_parms.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 + // the synch thread proc context is hard linked to regular processing thread context, thread id = 0 + UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc); + // shift the frame index with all the frames we trashed meanwhile we perform the synch search + proc->decoded_frame_rx=(proc->decoded_frame_rx + trashed_frames) % MAX_FRAME_NUMBER; + decoded_frame_rx=proc->decoded_frame_rx; + // we do ++ first in the regular processing, so it will be 0; + absolute_slot=decoded_frame_rx*nb_slot_frame + nb_slot_frame -1; continue; } absolute_slot++; thread_idx = absolute_slot % RX_NB_TH; - int slot_nr=absolute_slot % nb_slot_frame; + int slot_nr = absolute_slot % nb_slot_frame; UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[thread_idx]))->proc); // update thread index for received subframe proc->nr_tti_rx= slot_nr; @@ -611,6 +612,7 @@ void *UE_thread(void *arg) { proc->subframe_tx=proc->nr_tti_rx; proc->frame_rx = ( absolute_slot/nb_slot_frame ) % MAX_FRAME_NUMBER; proc->frame_tx = ( (absolute_slot + DURATION_RX_TO_TX) /nb_slot_frame ) % MAX_FRAME_NUMBER; + proc->decoded_frame_rx=-1; LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, thread_idx); for (int i=0; iframe_parms.nb_antennas_rx; i++) @@ -671,21 +673,37 @@ void *UE_thread(void *arg) { proc->timestamp_tx = timestamp+ (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; + notifiedFIFO_elt_t *res; if (getenv("RFSIMULATOR")) { // FixMe: Wait previous thread is done, because race conditions seems too bad // in case of actual RF board, the overlap between threads mitigate the issue - while (!tryPullTpool(&nf, Tpool)) { - nbSlotProcessing--; + // We must receive one message, that proves the slot processing is done + while ((res=tryPullTpool(&nf, Tpool)) == NULL) usleep(200); - } + + nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; } - while (nbSlotProcessing >= RX_NB_TH && !tryPullTpool(&nf, Tpool)) { + while (nbSlotProcessing >= RX_NB_TH && (res=tryPullTpool(&nf, Tpool)) != NULL ) { nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; + usleep(200); } + if ( decoded_frame_rx != proc->frame_rx && + ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) + LOG_E(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", + decoded_frame_rx, proc->frame_rx); + pushTpool(Tpool, processingMsg[thread_idx]); } // while !oai_exit @@ -704,12 +722,11 @@ void init_UE(int nb_inst) { struct sched_param sched; sched.sched_priority = sched_get_priority_max(SCHED_RR)-1; pthread_attr_setschedparam(&attr, &sched); - + for (inst=0; inst < nb_inst; inst++) { // UE->rfdevice.type = NONE_DEV; //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); - PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); nr_l3_init_ue(); diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index df6b2f7282..8bc07936f6 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -28,6 +28,7 @@ #include "PHY/defs_nr_UE.h" #include "SIMULATION/ETH_TRANSPORT/proto.h" #include +#include #if defined(ENABLE_ITTI) diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c index 06c0e30bde..e4bec93ddf 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c @@ -46,7 +46,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m uint8_t bsize = pdcch_params->reg_bundle_size; uint8_t R = pdcch_params->interleaver_size; uint16_t N_reg = pdcch_params->n_rb * pdcch_params->n_symb; - uint16_t Y, N_cce, M_s_max, n_CI=0, tmp, C; + uint16_t Y, N_cce, M_s_max, n_CI=0, tmp, C=0; uint16_t n_RNTI = (pdcch_params->search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? pdcch_params->rnti:0; uint32_t A[3]={39827,39829,39839}; @@ -64,7 +64,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m } if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) { - AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %d, bsize %d R %d)\n", + AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n", N_reg, bsize, R); C = N_reg/(bsize*R); } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c index 40cbb0d23e..faba84ce52 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c @@ -102,7 +102,7 @@ void free_list(NR_UE_SSB *node) { } -int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) +int nr_pbch_detection(UE_nr_rxtx_proc_t * proc, PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode) { NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; int ret =-1; @@ -160,7 +160,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod #endif ret = nr_rx_pbch(ue, - 0, + proc, ue->pbch_vars[0], frame_parms, 0, @@ -201,7 +201,7 @@ int nr_pbch_detection(PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mod char duplex_string[2][4] = {"FDD","TDD"}; char prefix_string[2][9] = {"NORMAL","EXTENDED"}; -int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) +int nr_initial_sync(UE_nr_rxtx_proc_t *proc, PHY_VARS_NR_UE *ue, runmode_t mode) { int32_t sync_pos, sync_pos_frame; // k_ssb, N_ssb_crb, sync_pos2, @@ -309,7 +309,7 @@ int nr_initial_sync(PHY_VARS_NR_UE *ue, runmode_t mode) //nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,n_ssb_crb,0); nr_gold_pbch(ue); - ret = nr_pbch_detection(ue,1,mode); // start pbch detection at first symbol after pss + ret = nr_pbch_detection(proc, ue,1,mode); // start pbch detection at first symbol after pss if (ret == 0) { // sync at symbol ue->symbol_offset diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index a50edecb2c..080e6b5159 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -410,7 +410,7 @@ unsigned char sign(int8_t x) { 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,6,23}; int nr_rx_pbch( PHY_VARS_NR_UE *ue, - int subframe_rx, + UE_nr_rxtx_proc_t *proc, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -448,15 +448,15 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, symbol_offset=0; #ifdef DEBUG_PBCH - //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF); + //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].rxdataF); write_output("rxdataF0_pbch.m","rxF0pbch", - &nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF[0][(symbol_offset+1)*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size*3,1,1); + &nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].rxdataF[0][(symbol_offset+1)*frame_parms->ofdm_symbol_size],frame_parms->ofdm_symbol_size*3,1,1); #endif // symbol refers to symbol within SSB. symbol_offset is the offset of the SSB wrt start of slot for (symbol=1; symbol<4; symbol++) { - nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF, - nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].dl_ch_estimates[eNB_id], + nr_pbch_extract(nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].rxdataF, + nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[proc->subframe_rx]].dl_ch_estimates[eNB_id], nr_ue_pbch_vars->rxdataF_ext, nr_ue_pbch_vars->dl_ch_estimates_ext, symbol, @@ -591,6 +591,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, #endif ue->dl_indication.rx_ind = &ue->rx_ind; // hang on rx_ind instance + ue->dl_indication.proc=proc; //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]; 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 e1727c4847..6290a700c5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1137,7 +1137,7 @@ int rx_sss(PHY_VARS_NR_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uin \returns number of tx antennas or -1 if error */ int nr_rx_pbch( PHY_VARS_NR_UE *ue, - int subframe_rx, + UE_nr_rxtx_proc_t *proc, NR_UE_PBCH *nr_ue_pbch_vars, NR_DL_FRAME_PARMS *frame_parms, uint8_t eNB_id, @@ -1145,7 +1145,8 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, MIMO_mode_t mimo_mode, uint32_t high_speed_flag); -int nr_pbch_detection(PHY_VARS_NR_UE *ue, +int nr_pbch_detection(UE_nr_rxtx_proc_t *proc, + PHY_VARS_NR_UE *ue, int pbch_initial_symbol, runmode_t mode); @@ -1433,7 +1434,8 @@ void generate_RIV_tables(void); @param phy_vars_ue Pointer to UE variables @param mode current running mode */ -int nr_initial_sync(PHY_VARS_NR_UE *phy_vars_ue, runmode_t mode); +int nr_initial_sync(UE_nr_rxtx_proc_t *proc, + PHY_VARS_NR_UE *phy_vars_ue, runmode_t mode); /*! diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index 885039c592..2facd85bab 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -277,7 +277,7 @@ typedef struct { /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) int16_t w[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; /// for abstraction soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) - double w_abs[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; + //double w_abs[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; /// soft bits for each received segment ("d"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) int16_t *d[MAX_NUM_NR_DLSCH_SEGMENTS]; /// LDPC processing buffers diff --git a/openair1/PHY/TOOLS/cdot_prod.c b/openair1/PHY/TOOLS/cdot_prod.c index 843a9605f1..d3e73ec28a 100644 --- a/openair1/PHY/TOOLS/cdot_prod.c +++ b/openair1/PHY/TOOLS/cdot_prod.c @@ -158,122 +158,6 @@ int32_t dot_product(int16_t *x, #endif } -int64_t dot_product64(int16_t *x, - int16_t *y, - uint32_t N, //must be a multiple of 8 - uint8_t output_shift) -{ - - uint32_t n; - -#if defined(__x86_64__) || defined(__i386__) - __m128i *x128,*y128,mmtmp1,mmtmp2,mmtmp3,mmcumul,mmcumul_re,mmcumul_im; - __m128i minus_i = _mm_set_epi16(-1,1,-1,1,-1,1,-1,1); - int64_t result; - - x128 = (__m128i*) x; - y128 = (__m128i*) y; - - mmcumul_re = _mm_setzero_si128(); - mmcumul_im = _mm_setzero_si128(); - - for (n=0; n<(N>>2); n++) { - -// printf("n=%d, x128=%p, y128=%p\n",n,x128,y128); - // print_shorts("x",&x128[0]); - // print_shorts("y",&y128[0]); - - // this computes Re(z) = Re(x)*Re(y) + Im(x)*Im(y) - mmtmp1 = _mm_madd_epi16(x128[0],y128[0]); - // print_ints("retmp",&mmtmp1); - // mmtmp1 contains real part of 4 consecutive outputs (32-bit) - // shift and accumulate results - mmtmp1 = _mm_srai_epi32(mmtmp1,output_shift); - mmcumul_re = _mm_add_epi32(mmcumul_re,mmtmp1); - //print_ints("re",&mmcumul_re); - - - // this computes Im(z) = Re(x)*Im(y) - Re(y)*Im(x) - mmtmp2 = _mm_shufflelo_epi16(y128[0],_MM_SHUFFLE(2,3,0,1)); - //print_shorts("y",&mmtmp2); - mmtmp2 = _mm_shufflehi_epi16(mmtmp2,_MM_SHUFFLE(2,3,0,1)); - //print_shorts("y",&mmtmp2); - mmtmp2 = _mm_sign_epi16(mmtmp2,minus_i); - // print_shorts("y",&mmtmp2); - - mmtmp3 = _mm_madd_epi16(x128[0],mmtmp2); - //print_ints("imtmp",&mmtmp3); - // mmtmp3 contains imag part of 4 consecutive outputs (32-bit) - // shift and accumulate results - mmtmp3 = _mm_srai_epi32(mmtmp3,output_shift); - mmcumul_im = _mm_add_epi32(mmcumul_im,mmtmp3); - //print_ints("im",&mmcumul_im); - - x128++; - y128++; - } - - // this gives Re Re Im Im - mmcumul = _mm_hadd_epi32(mmcumul_re,mmcumul_im); - //print_ints("cumul1",&mmcumul); - // this gives Re Im Re Im - mmcumul = _mm_hadd_epi32(mmcumul,mmcumul); - //print_ints("cumul2",&mmcumul); - - //mmcumul = _mm_srai_epi32(mmcumul,output_shift); - // extract the lower half - result = _mm_extract_epi64(mmcumul,0); - //printf("result: (%d,%d)\n",((int32_t*)&result)[0],((int32_t*)&result)[1]); - _mm_empty(); - _m_empty(); - - return(result); - -#elif defined(__arm__) - int16x4_t *x_128=(int16x4_t*)x; - int16x4_t *y_128=(int16x4_t*)y; - int32x4_t tmp_re,tmp_im; - int32x4_t tmp_re1,tmp_im1; - int32x4_t re_cumul,im_cumul; - int32x2_t re_cumul2,im_cumul2; - int32x4_t shift = vdupq_n_s32(-output_shift); - int32x2x2_t result2; - int16_t conjug[4]__attribute__((aligned(16))) = {-1,1,-1,1} ; - - re_cumul = vdupq_n_s32(0); - im_cumul = vdupq_n_s32(0); - - for (n=0; n<(N>>2); n++) { - - tmp_re = vmull_s16(*x_128++, *y_128++); - //tmp_re = [Re(x[0])Re(y[0]) Im(x[0])Im(y[0]) Re(x[1])Re(y[1]) Im(x[1])Im(y[1])] - tmp_re1 = vmull_s16(*x_128++, *y_128++); - //tmp_re1 = [Re(x1[1])Re(x2[1]) Im(x1[1])Im(x2[1]) Re(x1[1])Re(x2[2]) Im(x1[1])Im(x2[2])] - tmp_re = vcombine_s32(vpadd_s32(vget_low_s32(tmp_re),vget_high_s32(tmp_re)), - vpadd_s32(vget_low_s32(tmp_re1),vget_high_s32(tmp_re1))); - //tmp_re = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2]) Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] - - tmp_im = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); - //tmp_im = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] - tmp_im1 = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); - //tmp_im1 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] - tmp_im = vcombine_s32(vpadd_s32(vget_low_s32(tmp_im),vget_high_s32(tmp_im)), - vpadd_s32(vget_low_s32(tmp_im1),vget_high_s32(tmp_im1))); - //tmp_im = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - - re_cumul = vqaddq_s32(re_cumul,vqshlq_s32(tmp_re,shift)); - im_cumul = vqaddq_s32(im_cumul,vqshlq_s32(tmp_im,shift)); - } - - re_cumul2 = vpadd_s32(vget_low_s32(re_cumul),vget_high_s32(re_cumul)); - im_cumul2 = vpadd_s32(vget_low_s32(im_cumul),vget_high_s32(im_cumul)); - re_cumul2 = vpadd_s32(re_cumul2,re_cumul2); - im_cumul2 = vpadd_s32(im_cumul2,im_cumul2); - result2 = vzip_s32(re_cumul2,im_cumul2); - return(vget_lane_s32(result2.val[0],0)); -#endif -} - #ifdef MAIN diff --git a/openair1/PHY/TOOLS/tools_defs.h b/openair1/PHY/TOOLS/tools_defs.h index b57fc7e9de..8ba2ac0d40 100644 --- a/openair1/PHY/TOOLS/tools_defs.h +++ b/openair1/PHY/TOOLS/tools_defs.h @@ -354,10 +354,116 @@ int32_t dot_product(int16_t *x, uint32_t N, //must be a multiple of 8 uint8_t output_shift); -int64_t dot_product64(int16_t *x, +static inline int64_t dot_product64(int16_t *x, int16_t *y, uint32_t N, //must be a multiple of 8 - uint8_t output_shift); + uint8_t output_shift) +{ + +#if defined(__x86_64__) || defined(__i386__) + __m128i *x128,*y128,mmtmp1,mmtmp2,mmtmp3,mmcumul,mmcumul_re,mmcumul_im; + __m128i minus_i = _mm_set_epi16(-1,1,-1,1,-1,1,-1,1); + int64_t result; + + x128 = (__m128i*) x; + y128 = (__m128i*) y; + + mmcumul_re = _mm_setzero_si128(); + mmcumul_im = _mm_setzero_si128(); + + __m128i*end=x128+(N>>2); + for (__m128i* inPtr=x128; inPtr < end ; inPtr++) { + +// printf("n=%d, x128=%p, y128=%p\n",n,x128,y128); + // print_shorts("x",&x128[0]); + // print_shorts("y",&y128[0]); + + // this computes Re(z) = Re(x)*Re(y) + Im(x)*Im(y) + mmtmp1 = _mm_madd_epi16(*inPtr,*y128); + // print_ints("retmp",&mmtmp1); + // mmtmp1 contains real part of 4 consecutive outputs (32-bit) + // shift and accumulate results + mmtmp1 = _mm_srai_epi32(mmtmp1,output_shift); + mmcumul_re = _mm_add_epi32(mmcumul_re,mmtmp1); + //print_ints("re",&mmcumul_re); + + + // this computes Im(z) = Re(x)*Im(y) - Re(y)*Im(x) + mmtmp2 = _mm_shufflelo_epi16(*y128,_MM_SHUFFLE(2,3,0,1)); + //print_shorts("y",&mmtmp2); + mmtmp2 = _mm_shufflehi_epi16(mmtmp2,_MM_SHUFFLE(2,3,0,1)); + //print_shorts("y",&mmtmp2); + mmtmp2 = _mm_sign_epi16(mmtmp2,minus_i); + // print_shorts("y",&mmtmp2); + + mmtmp3 = _mm_madd_epi16(*inPtr,mmtmp2); + //print_ints("imtmp",&mmtmp3); + // mmtmp3 contains imag part of 4 consecutive outputs (32-bit) + // shift and accumulate results + mmtmp3 = _mm_srai_epi32(mmtmp3,output_shift); + mmcumul_im = _mm_add_epi32(mmcumul_im,mmtmp3); + //print_ints("im",&mmcumul_im); + y128++; + } + + // this gives Re Re Im Im + mmcumul = _mm_hadd_epi32(mmcumul_re,mmcumul_im); + //print_ints("cumul1",&mmcumul); + // this gives Re Im Re Im + mmcumul = _mm_hadd_epi32(mmcumul,mmcumul); + //print_ints("cumul2",&mmcumul); + + //mmcumul = _mm_srai_epi32(mmcumul,output_shift); + // extract the lower half + result = _mm_extract_epi64(mmcumul,0); + //printf("result: (%d,%d)\n",((int32_t*)&result)[0],((int32_t*)&result)[1]); + + return(result); + +#elif defined(__arm__) + int16x4_t *x_128=(int16x4_t*)x; + int16x4_t *y_128=(int16x4_t*)y; + int32x4_t tmp_re,tmp_im; + int32x4_t tmp_re1,tmp_im1; + int32x4_t re_cumul,im_cumul; + int32x2_t re_cumul2,im_cumul2; + int32x4_t shift = vdupq_n_s32(-output_shift); + int32x2x2_t result2; + int16_t conjug[4]__attribute__((aligned(16))) = {-1,1,-1,1} ; + + re_cumul = vdupq_n_s32(0); + im_cumul = vdupq_n_s32(0); + + for (n=0; n<(N>>2); n++) { + + tmp_re = vmull_s16(*x_128++, *y_128++); + //tmp_re = [Re(x[0])Re(y[0]) Im(x[0])Im(y[0]) Re(x[1])Re(y[1]) Im(x[1])Im(y[1])] + tmp_re1 = vmull_s16(*x_128++, *y_128++); + //tmp_re1 = [Re(x1[1])Re(x2[1]) Im(x1[1])Im(x2[1]) Re(x1[1])Re(x2[2]) Im(x1[1])Im(x2[2])] + tmp_re = vcombine_s32(vpadd_s32(vget_low_s32(tmp_re),vget_high_s32(tmp_re)), + vpadd_s32(vget_low_s32(tmp_re1),vget_high_s32(tmp_re1))); + //tmp_re = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2]) Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] + + tmp_im = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); + //tmp_im = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] + tmp_im1 = vmull_s16(vrev32_s16(vmul_s16(*x_128++,*(int16x4_t*)conjug)),*y_128++); + //tmp_im1 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] + tmp_im = vcombine_s32(vpadd_s32(vget_low_s32(tmp_im),vget_high_s32(tmp_im)), + vpadd_s32(vget_low_s32(tmp_im1),vget_high_s32(tmp_im1))); + //tmp_im = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] + + re_cumul = vqaddq_s32(re_cumul,vqshlq_s32(tmp_re,shift)); + im_cumul = vqaddq_s32(im_cumul,vqshlq_s32(tmp_im,shift)); + } + + re_cumul2 = vpadd_s32(vget_low_s32(re_cumul),vget_high_s32(re_cumul)); + im_cumul2 = vpadd_s32(vget_low_s32(im_cumul),vget_high_s32(im_cumul)); + re_cumul2 = vpadd_s32(re_cumul2,re_cumul2); + im_cumul2 = vpadd_s32(im_cumul2,im_cumul2); + result2 = vzip_s32(re_cumul2,im_cumul2); + return(vget_lane_s32(result2.val[0],0)); +#endif +} void dft12(int16_t *x,int16_t *y); void dft24(int16_t *x,int16_t *y,uint8_t scale_flag); diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index f447c6895e..c375313c6b 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -157,109 +157,6 @@ #include "targets/ARCH/COMMON/common_lib.h" -#include "NR_IF_Module.h" - -/// Context data structure for RX/TX portion of subframe processing -typedef struct { - /// index of the current UE RX/TX proc - int proc_id; - /// Component Carrier index - uint8_t CC_id; - /// timestamp transmitted to HW - openair0_timestamp timestamp_tx; - //#ifdef UE_NR_PHY_DEMO - /// NR TTI index within subframe_tx [0 .. ttis_per_subframe - 1] to act upon for transmission - int nr_tti_tx; - /// NR TTI index within subframe_rx [0 .. ttis_per_subframe - 1] to act upon for reception - int nr_tti_rx; - //#endif - /// subframe to act upon for transmission - int subframe_tx; - /// subframe to act upon for reception - int subframe_rx; - /// frame to act upon for transmission - int frame_tx; - /// frame to act upon for reception - int frame_rx; - /// \brief Instance count for RXn-TXnp4 processing thread. - /// \internal This variable is protected by \ref mutex_rxtx. - int instance_cnt_rxtx; - /// pthread structure for RXn-TXnp4 processing thread - pthread_t pthread_rxtx; - /// pthread attributes for RXn-TXnp4 processing thread - pthread_attr_t attr_rxtx; - /// condition variable for tx processing thread - pthread_cond_t cond_rxtx; - /// mutex for RXn-TXnp4 processing thread - pthread_mutex_t mutex_rxtx; - /// scheduling parameters for RXn-TXnp4 thread - struct sched_param sched_param_rxtx; - - /// internal This variable is protected by ref mutex_fep_slot1. - //int instance_cnt_slot0_dl_processing; - int instance_cnt_slot1_dl_processing; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_slot1_dl_processing; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_slot1_dl_processing; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_slot1_dl_processing; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_slot1_dl_processing; - //int instance_cnt_slot0_dl_processing; - int instance_cnt_dlsch_td; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_dlsch_td; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_dlsch_td; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_dlsch_td; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_dlsch_td; - // - uint8_t chan_est_pilot0_slot1_available; - uint8_t chan_est_slot1_available; - uint8_t llr_slot1_available; - uint8_t dci_slot0_available; - uint8_t first_symbol_available; - uint8_t decoder_thread_available; - uint8_t decoder_main_available; - uint8_t decoder_switch; - int counter_decoder; - uint8_t channel_level; - int eNB_id; - int harq_pid; - int llr8_flag; - /// scheduling parameters for fep_slot1 thread - struct sched_param sched_param_fep_slot1; - - int sub_frame_start; - int sub_frame_step; - unsigned long long gotIQs; - uint8_t decoder_thread_available1; - int instance_cnt_dlsch_td1; - /// pthread descriptor fep_slot1 thread - //pthread_t pthread_slot0_dl_processing; - pthread_t pthread_dlsch_td1; - /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_dlsch_td1; - /// condition variable for UE fep_slot1 thread; - //pthread_cond_t cond_slot0_dl_processing; - pthread_cond_t cond_dlsch_td1; - /// mutex for UE synch thread - //pthread_mutex_t mutex_slot0_dl_processing; - pthread_mutex_t mutex_dlsch_td1; - int dci_err_cnt; -} UE_nr_rxtx_proc_t; /// Context data structure for eNB subframe processing typedef struct { @@ -956,6 +853,9 @@ typedef struct UE_NR_SCAN_INFO_s { int32_t freq_offset_Hz[3][10]; } UE_NR_SCAN_INFO_t; + +#include "NR_IF_Module.h" + /// Top-level PHY Data Structure for UE typedef struct { /// \brief Module ID indicator for this instance diff --git a/openair1/PHY/thread_NR_UE.h b/openair1/PHY/thread_NR_UE.h new file mode 100644 index 0000000000..cba7a5ae41 --- /dev/null +++ b/openair1/PHY/thread_NR_UE.h @@ -0,0 +1,78 @@ +#ifndef __thread_NR_UE__ +#define __thread_NR_UE__ +#include +#include +/// Context data structure for RX/TX portion of subframe processing +typedef struct { + /// index of the current UE RX/TX proc + int proc_id; + /// Component Carrier index + uint8_t CC_id; + /// timestamp transmitted to HW + openair0_timestamp timestamp_tx; + //#ifdef UE_NR_PHY_DEMO + /// NR TTI index within subframe_tx [0 .. ttis_per_subframe - 1] to act upon for transmission + int nr_tti_tx; + /// NR TTI index within subframe_rx [0 .. ttis_per_subframe - 1] to act upon for reception + int nr_tti_rx; + //#endif + /// subframe to act upon for transmission + int subframe_tx; + /// subframe to act upon for reception + int subframe_rx; + /// frame to act upon for transmission + int frame_tx; + /// frame to act upon for reception + int frame_rx; + int decoded_frame_rx; + /// internal This variable is protected by ref mutex_fep_slot1. + //int instance_cnt_slot0_dl_processing; + int instance_cnt_slot1_dl_processing; + /// pthread descriptor fep_slot1 thread + //pthread_t pthread_slot0_dl_processing; + pthread_t pthread_slot1_dl_processing; + /// pthread attributes for fep_slot1 processing thread + // pthread_attr_t attr_slot0_dl_processing; + pthread_attr_t attr_slot1_dl_processing; + /// condition variable for UE fep_slot1 thread; + //pthread_cond_t cond_slot0_dl_processing; + pthread_cond_t cond_slot1_dl_processing; + /// mutex for UE synch thread + //pthread_mutex_t mutex_slot0_dl_processing; + pthread_mutex_t mutex_slot1_dl_processing; + //int instance_cnt_slot0_dl_processing; + int instance_cnt_dlsch_td; + /// pthread descriptor fep_slot1 thread + //pthread_t pthread_slot0_dl_processing; + pthread_t pthread_dlsch_td; + /// pthread attributes for fep_slot1 processing thread + // pthread_attr_t attr_slot0_dl_processing; + pthread_attr_t attr_dlsch_td; + /// condition variable for UE fep_slot1 thread; + //pthread_cond_t cond_slot0_dl_processing; + pthread_cond_t cond_dlsch_td; + /// mutex for UE synch thread + uint8_t chan_est_pilot0_slot1_available; + uint8_t chan_est_slot1_available; + uint8_t llr_slot1_available; + uint8_t dci_slot0_available; + uint8_t first_symbol_available; + uint8_t decoder_thread_available; + uint8_t decoder_main_available; + uint8_t decoder_switch; + int counter_decoder; + uint8_t channel_level; + int eNB_id; + int harq_pid; + int llr8_flag; + /// scheduling parameters for fep_slot1 thread + struct sched_param sched_param_fep_slot1; + + int sub_frame_start; + int sub_frame_step; + unsigned long long gotIQs; + uint8_t decoder_thread_available1; + int dci_err_cnt; +} UE_nr_rxtx_proc_t; + +#endif diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 7c17987980..2eba1f904e 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -251,7 +251,7 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ } } - + return 0; } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index d37d2a1fb8..7701184153 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2824,7 +2824,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PBCH_PROCEDURES, VCD_FUNCTION_IN); //LOG_I(PHY,"[UE %d] Frame %d, Trying PBCH %d (NidCell %d, eNB_id %d)\n",ue->Mod_id,frame_rx,pbch_phase,ue->frame_parms.Nid_cell,eNB_id); - ret = nr_rx_pbch(ue, proc->subframe_rx, + ret = nr_rx_pbch(ue, proc, ue->pbch_vars[eNB_id], &ue->frame_parms, eNB_id, diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 1416905696..ae8d3062ad 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -684,7 +684,8 @@ int main(int argc, char **argv) LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],frame_length_complex_samples,1,1); } if (UE->is_synchronized == 0) { - ret = nr_initial_sync(UE, normal_txrx); + UE_nr_rxtx_proc_t proc={0}; + ret = nr_initial_sync(&proc, UE, normal_txrx); printf("nr_initial_sync1 returns %d\n",ret); if (ret<0) n_errors++; } diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index e4ff2f48d7..36a913f939 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -600,7 +600,8 @@ int main(int argc, char **argv) } if (UE->is_synchronized == 0) { - ret = nr_initial_sync(UE, normal_txrx); + UE_nr_rxtx_proc_t proc={0}; + ret = nr_initial_sync(&proc, UE, normal_txrx); printf("nr_initial_sync1 returns %d\n",ret); if (ret<0) n_errors++; } @@ -621,9 +622,10 @@ int main(int argc, char **argv) nr_pbch_channel_estimation(UE,0,0,i,i-(UE->symbol_offset+1),ssb_index%8,n_hf); } + UE_nr_rxtx_proc_t proc={0}; ret = nr_rx_pbch(UE, - 0, + &proc, UE->pbch_vars[0], frame_parms, 0, diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 2379233776..c338920397 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -35,6 +35,7 @@ #include "mac_defs.h" #include "mac.h" +#include /**\brief decode mib pdu in NR_UE, from if_module ul_ind with P7 tx_ind message \param module_id module id @@ -46,6 +47,7 @@ \param pdu_length length of pdu \param cell_id cell id */ int8_t nr_ue_decode_mib( + UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, uint8_t gNB_index, diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 7110a35331..2b044db018 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -193,6 +193,7 @@ int8_t nr_ue_process_dlsch(module_id_t module_id, int cc_id, uint8_t gNB_index, } int8_t nr_ue_decode_mib( + UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, uint8_t gNB_index, @@ -594,6 +595,7 @@ int8_t nr_ue_decode_mib( if(mac->if_module != NULL && mac->if_module->phy_config_request != NULL){ mac->if_module->phy_config_request(&mac->phy_config); } + proc->decoded_frame_rx=frame; //} return 0; } diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index e391cc67b9..e1d3d900c1 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -42,9 +42,10 @@ static nr_ue_if_module_t *nr_ue_if_module_inst[MAX_IF_MODULES]; // L2 Abstraction Layer -int handle_bcch_bch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){ +int handle_bcch_bch(UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id){ - return nr_ue_decode_mib( module_id, + return nr_ue_decode_mib( proc, + module_id, cc_id, gNB_index, additional_bits, @@ -197,7 +198,8 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ for(i=0; irx_ind->number_pdus; ++i){ switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){ case FAPI_NR_RX_PDU_TYPE_MIB: - ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, + ret_mask |= (handle_bcch_bch( dl_info->proc, + dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.pdu, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.additional_bits, (dl_info->rx_ind->rx_indication_body+i)->mib_pdu.ssb_index, diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h index 0ecba9736d..c1c8522749 100755 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h @@ -34,6 +34,7 @@ #define __NR_IF_MODULE_H__ #include "platform_types.h" +#include #include "fapi_nr_ue_interface.h" @@ -64,6 +65,7 @@ typedef struct { frame_t frame; /// slot int slot; + UE_nr_rxtx_proc_t * proc; /// NR UE FAPI-like P7 message, direction: L1 to L2 /// data reception indication structure @@ -209,7 +211,7 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq); \param ssb_index SSB index within 0 - (L_ssb-1) corresponding to 38.331 ch.13 parameter i \param ssb_length corresponding to L1 parameter L_ssb \param cell_id cell id */ -int handle_bcch_bch(module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id); +int handle_bcch_bch(UE_nr_rxtx_proc_t *proc, module_id_t module_id, int cc_id, unsigned int gNB_index, uint8_t *pduP, unsigned int additional_bits, uint32_t ssb_index, uint32_t ssb_length, uint16_t cell_id); // TODO check /**\brief handle BCCH-DL-SCH message from dl_indication diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c deleted file mode 100644 index 362300d4d7..0000000000 --- a/targets/RT/USER/nr-ue.c +++ /dev/null @@ -1,1175 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.0 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file lte-ue.c - * \brief threads and support functions for real-time LTE UE target - * \author R. Knopp, F. Kaltenberger, Navid Nikaein - * \date 2015 - * \version 0.1 - * \company Eurecom - * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr - * \note - * \warning - */ -#include "nr-uesoftmodem.h" - -#include "rt_wrapper.h" - -#include "LAYER2/NR_MAC_UE/mac.h" -//#include "RRC/LTE/rrc_extern.h" -#include "PHY_INTERFACE/phy_interface_extern.h" - -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "fapi_nr_ue_l1.h" -#include "PHY/phy_extern_nr_ue.h" -#include "PHY/INIT/phy_init.h" -#include "PHY/MODULATION/modulation_UE.h" -#include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "RRC/NR_UE/rrc_proto.h" - -//#ifndef NO_RAT_NR -#include "SCHED_NR/phy_frame_config_nr.h" -//#endif -#include "SCHED_NR_UE/defs.h" - -#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" - -#include "common/utils/LOG/log.h" -#include "common/utils/LOG/vcd_signal_dumper.h" - -#include "T.h" - -#ifdef XFORMS - #include "PHY/TOOLS/nr_phy_scope.h" - - extern char do_forms; -#endif - - -extern double cpuf; -//static nfapi_nr_config_request_t config_t; -//static nfapi_nr_config_request_t* config =&config_t; - -/* - * NR SLOT PROCESSING SEQUENCE - * - * Processing occurs with following steps for connected mode: - * - * - Rx samples for a slot are received, - * - PDCCH processing (including DCI extraction for downlink and uplink), - * - PDSCH processing (including transport blocks decoding), - * - PUCCH/PUSCH (transmission of acknowledgements, CSI, ... or data). - * - * Time between reception of the slot and related transmission depends on UE processing performance. - * It is defined by the value NR_UE_CAPABILITY_SLOT_RX_TO_TX. - * - * In NR, network gives the duration between Rx slot and Tx slot in the DCI: - * - for reception of a PDSCH and its associated acknowledgment slot (with a PUCCH or a PUSCH), - * - for reception of an uplink grant and its associated PUSCH slot. - * - * So duration between reception and it associated transmission depends on its transmission slot given in the DCI. - * NR_UE_CAPABILITY_SLOT_RX_TO_TX means the minimum duration but higher duration can be given by the network because UE can support it. - * -* Slot k -* -------+------------+-------- -* Frame | Tx samples | -* Subframe | buffer | -* Slot n -------+------------+-------- -* ------ +------------+-------- | -* | Rx samples | | -* | buffer | | -* -------+------------+-------- | -* | | -* V | -* +------------+ | -* | PDCCH | | -* | processing | | -* +------------+ | -* | | | -* | v | -* | +------------+ | -* | | PDSCH | | -* | | processing | decoding result | -* | +------------+ -> ACK/NACK of PDSCH | -* | | | -* | v | -* | +-------------+------------+ | -* | | PUCCH/PUSCH | Tx samples | | -* | | processing | transfer | | -* | +-------------+------------+ | -* | | -* |/___________________________________________________________\| -* \ duration between reception and associated transmission / -* -* Remark: processing is done slot by slot, it can be distribute on different threads which are executed in parallel. -* This is an architecture optimization in order to cope with real time constraints. -* By example, for LTE, subframe processing is spread over 4 different threads. -* - */ - -#ifndef NO_RAT_NR - #define DURATION_RX_TO_TX (NR_UE_CAPABILITY_SLOT_RX_TO_TX) /* for NR this will certainly depends to such UE capability which is not yet defined */ -#else - #define DURATION_RX_TO_TX (4) /* For LTE, this duration is fixed to 4 and it is linked to LTE standard for both modes FDD/TDD */ -#endif - -#define FRAME_PERIOD 100000000ULL -#define DAQ_PERIOD 66667ULL -#define FIFO_PRIORITY 40 - -typedef enum { - pss=0, - pbch=1, - si=2 -} sync_mode_t; - -void init_UE_threads(PHY_VARS_NR_UE *UE); -void *UE_thread(void *arg); -void init_UE(int nb_inst); - -int32_t **rxdata; -int32_t **txdata; - -#define SAIF_ENABLED - -#ifdef SAIF_ENABLED - uint64_t g_ue_rx_thread_busy = 0; -#endif - - -PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, - uint8_t UE_id, - uint8_t abstraction_flag) - -{ - PHY_VARS_NR_UE *ue; - - if (frame_parms!=(NR_DL_FRAME_PARMS *)NULL) { // if we want to give initial frame parms, allocate the PHY_VARS_UE structure and put them in - ue = (PHY_VARS_NR_UE *)malloc(sizeof(PHY_VARS_NR_UE)); - memset(ue,0,sizeof(PHY_VARS_NR_UE)); - memcpy(&(ue->frame_parms), frame_parms, sizeof(NR_DL_FRAME_PARMS)); - } else ue = PHY_vars_UE_g[UE_id][0]; - - ue->Mod_id = UE_id; - ue->mac_enabled = 1; - // initialize all signal buffers - init_nr_ue_signal(ue,1,abstraction_flag); - // intialize transport - init_nr_ue_transport(ue,abstraction_flag); - return(ue); -} - -void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char *name) { -#ifdef DEADLINE_SCHEDULER - - if (sched_runtime!=0) { - struct sched_attr attr= {0}; - attr.size = sizeof(attr); - attr.sched_policy = SCHED_DEADLINE; - attr.sched_runtime = sched_runtime; - attr.sched_deadline = sched_deadline; - attr.sched_period = 0; - AssertFatal(sched_setattr(0, &attr, 0) == 0, - "[SCHED] %s thread: sched_setattr failed %s \n", name, strerror(errno)); - LOG_I(HW,"[SCHED][eNB] %s deadline thread %lu started on CPU %d\n", - name, (unsigned long)gettid(), sched_getcpu()); - } - -#else - - if (CPU_COUNT(cpuset) > 0) - AssertFatal( 0 == pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), cpuset), ""); - - struct sched_param sp; - sp.sched_priority = sched_fifo; - AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO,&sp)==0, - "Can't set thread priority, Are you root?\n"); - /* Check the actual affinity mask assigned to the thread */ - cpu_set_t *cset=CPU_ALLOC(CPU_SETSIZE); - - if (0 == pthread_getaffinity_np(pthread_self(), CPU_ALLOC_SIZE(CPU_SETSIZE), cset)) { - char txt[512]= {0}; - - for (int j = 0; j < CPU_SETSIZE; j++) - if (CPU_ISSET(j, cset)) - sprintf(txt+strlen(txt), " %d ", j); - - printf("CPU Affinity of thread %s is %s\n", name, txt); - } - - CPU_FREE(cset); -#endif - // Lock memory from swapping. This is a process wide call (not constraint to this thread). - mlockall(MCL_CURRENT | MCL_FUTURE); - pthread_setname_np( pthread_self(), name ); - // LTS: this sync stuff should be wrong - printf("waiting for sync (%s)\n",name); - pthread_mutex_lock(&sync_mutex); - printf("Locked sync_mutex, waiting (%s)\n",name); - - while (sync_var<0) - pthread_cond_wait(&sync_cond, &sync_mutex); - - pthread_mutex_unlock(&sync_mutex); - printf("started %s as PID: %ld\n",name, gettid()); -} - -void init_UE(int nb_inst) { - int inst; - NR_UE_MAC_INST_t *mac_inst; - - for (inst=0; inst < nb_inst; inst++) { - // UE->rfdevice.type = NONE_DEV; - //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); - PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); - PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); - nr_l3_init_ue(); - nr_l2_init_ue(); - mac_inst = get_mac_inst(0); - mac_inst->if_module = UE->if_inst; - UE->if_inst->scheduled_response = nr_ue_scheduled_response; - UE->if_inst->phy_config_request = nr_ue_phy_config_request; - LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); - //init_UE_threads(inst); - //UE = PHY_vars_UE_g[inst][0]; - AssertFatal(0 == pthread_create(&UE->proc.pthread_ue, - &UE->proc.attr_ue, - UE_thread, - (void *)UE), ""); - } - - printf("UE threads created by %ld\n", gettid()); -#if 0 -#if defined(ENABLE_USE_MME) - extern volatile int start_UE; - - while (start_UE == 0) { - sleep(1); - } - -#endif -#endif -} - -/*! - * \brief This is the UE synchronize thread. - * It performs band scanning and synchonization. - * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ -static void *UE_thread_synch(void *arg) { - - static int __thread UE_thread_synch_retval; - int i, hw_slot_offset; - PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; - int current_band = 0; - int current_offset = 0; - lte_frame_type_t current_type; - sync_mode_t sync_mode = pbch; - int CC_id = UE->CC_id; - int freq_offset=0; - char threadname[128]; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - if ( threads.sync != -1 ) - CPU_SET(threads.sync, &cpuset); - - // this thread priority must be lower that the main acquisition thread - sprintf(threadname, "sync UE %d", UE->Mod_id); - init_thread(100000, 500000, FIFO_PRIORITY-1, &cpuset, threadname); - UE->is_synchronized = 0; - - printf("UE_scan %d\n",UE->UE_scan); - - if (UE->UE_scan == 0) { - - get_band(downlink_frequency[CC_id][0], &UE->frame_parms.eutra_band, &uplink_frequency_offset[CC_id][0], &UE->frame_parms.frame_type); - - LOG_I( PHY, "[SCHED][UE] Check absolute frequency DL %"PRIu32", UL %"PRIu32" (oai_exit %d, rx_num_channels %d)\n", - downlink_frequency[0][0], downlink_frequency[0][0]+uplink_frequency_offset[0][0], - oai_exit, openair0_cfg[0].rx_num_channels); - - for (i=0; irf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - - if (uplink_frequency_offset[CC_id][i] != 0) // - openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_FDD; - else //FDD - openair0_cfg[UE->rf_map.card].duplex_mode = duplex_mode_TDD; - } - - sync_mode = pbch; - } else { - current_band=0; - LOG_E(PHY,"Fixme!\n"); - /* - for (i=0; irf_map.card].rx_num_channels; i++) { - downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[CC_id].dl_min; - uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = - bands_to_scan.band_info[CC_id].ul_min-bands_to_scan.band_info[CC_id].dl_min; - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; - } - */ - } - - // AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); - - while (oai_exit==0) { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - - while (UE->proc.instance_cnt_synch < 0) - // the thread waits here most of the time - pthread_cond_wait( &UE->proc.cond_synch, &UE->proc.mutex_synch ); - - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - switch (sync_mode) { - /* - case pss: - LOG_I(PHY,"[SCHED][UE] Scanning band %d (%d), freq %u\n",bands_to_scan.band_info[current_band].band, current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); - //lte_sync_timefreq(UE,current_band,bands_to_scan.band_info[current_band].dl_min+current_offset); - current_offset += 20000000; // increase by 20 MHz - - if (current_offset > bands_to_scan.band_info[current_band].dl_max-bands_to_scan.band_info[current_band].dl_min) { - current_band++; - current_offset=0; - } - - if (current_band==bands_to_scan.nbands) { - current_band=0; - oai_exit=1; - } - - for (i=0; irf_map.card].rx_num_channels; i++) { - downlink_frequency[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].dl_min+current_offset; - uplink_frequency_offset[UE->rf_map.card][UE->rf_map.chain+i] = bands_to_scan.band_info[current_band].ul_min-bands_to_scan.band_info[0].dl_min + current_offset; - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB; - - if (UE->UE_scan_carrier) { - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - } - } - - break; - */ - case pbch: -#if DISABLE_LOG_X - printf("[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); -#else - LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); -#endif - - if (nr_initial_sync( UE, UE->mode ) == 0) { - //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (10*UE->frame_parms.samples_per_slot), 1, 1); - 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_slot; - printf("Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", - hw_slot_offset, - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset, - UE->UE_scan_carrier ); - - // rerun with new cell parameters and frequency-offset - for (i=0; irf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; - - if (freq_offset >= 0) - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] += abs(freq_offset); - else - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] -= abs(freq_offset); - - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i]+uplink_frequency_offset[CC_id][i]; - downlink_frequency[CC_id][i] = openair0_cfg[CC_id].rx_freq[i]; - } - - // reconfigure for potentially different bandwidth - switch(UE->frame_parms.N_RB_DL) { - case 6: - openair0_cfg[UE->rf_map.card].sample_rate =1.92e6; - openair0_cfg[UE->rf_map.card].rx_bw =.96e6; - openair0_cfg[UE->rf_map.card].tx_bw =.96e6; - // openair0_cfg[0].rx_gain[0] -= 12; - break; - - case 25: - openair0_cfg[UE->rf_map.card].sample_rate =7.68e6; - openair0_cfg[UE->rf_map.card].rx_bw =2.5e6; - openair0_cfg[UE->rf_map.card].tx_bw =2.5e6; - // openair0_cfg[0].rx_gain[0] -= 6; - break; - - case 50: - openair0_cfg[UE->rf_map.card].sample_rate =15.36e6; - openair0_cfg[UE->rf_map.card].rx_bw =5.0e6; - openair0_cfg[UE->rf_map.card].tx_bw =5.0e6; - // openair0_cfg[0].rx_gain[0] -= 3; - break; - - case 100: - openair0_cfg[UE->rf_map.card].sample_rate=30.72e6; - openair0_cfg[UE->rf_map.card].rx_bw=10.0e6; - openair0_cfg[UE->rf_map.card].tx_bw=10.0e6; - // openair0_cfg[0].rx_gain[0] -= 0; - break; - } - - if (UE->mode != loop_through_memory) { - UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); - //UE->rfdevice.trx_set_gains_func(&openair0,&openair0_cfg[0]); - //UE->rfdevice.trx_stop_func(&UE->rfdevice); - // sleep(1); - //nr_init_frame_parms_ue(&UE->frame_parms); - /*if (UE->rfdevice.trx_start_func(&UE->rfdevice) != 0 ) { - LOG_E(HW,"Could not start the device\n"); - oai_exit=1; - }*/ - } - - if (UE->UE_scan_carrier == 1) { - UE->UE_scan_carrier = 0; - } else { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - UE->is_synchronized = 1; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - if( UE->mode == rx_dump_frame ) { - FILE *fd; - - if ((UE->proc.proc_rxtx[0].frame_rx&1) == 0) { // this guarantees SIB1 is present - if ((fd = fopen("rxsig_frame0.dat","w")) != NULL) { - fwrite((void *)&UE->common_vars.rxdata[0][0], - sizeof(int32_t), - 10*UE->frame_parms.samples_per_subframe, - fd); - LOG_I(PHY,"Dummping Frame ... bye bye \n"); - fclose(fd); - exit(0); - } else { - LOG_E(PHY,"Cannot open file for writing\n"); - exit(0); - } - } else { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - UE->is_synchronized = 0; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - } - } - } - } else { - // initial sync failed - // calculate new offset and try again - if (UE->UE_scan_carrier == 1) { - if (freq_offset >= 0) - freq_offset += 100; - - freq_offset *= -1; - - if (abs(freq_offset) > 7500) { - LOG_I( PHY, "[initial_sync] No cell synchronization found, abandoning\n" ); - FILE *fd; - - if ((fd = fopen("rxsig_frame0.dat","w"))!=NULL) { - fwrite((void *)&UE->common_vars.rxdata[0][0], - sizeof(int32_t), - 10*UE->frame_parms.samples_per_subframe, - fd); - LOG_I(PHY,"Dummping Frame ... bye bye \n"); - fclose(fd); - exit(0); - } - - //mac_xface->macphy_exit("No cell synchronization found, abandoning"); new mac - return &UE_thread_synch_retval; // not reached - } - } - -#if DISABLE_LOG_X - printf("[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n", - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset ); -#else - LOG_I(PHY, "[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n", - freq_offset, - UE->rx_total_gain_dB, - downlink_frequency[0][0]+freq_offset, - downlink_frequency[0][0]+uplink_frequency_offset[0][0]+freq_offset ); -#endif - - for (i=0; irf_map.card].rx_num_channels; i++) { - openair0_cfg[UE->rf_map.card].rx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+freq_offset; - openair0_cfg[UE->rf_map.card].tx_freq[UE->rf_map.chain+i] = downlink_frequency[CC_id][i]+uplink_frequency_offset[CC_id][i]+freq_offset; - openair0_cfg[UE->rf_map.card].rx_gain[UE->rf_map.chain+i] = UE->rx_total_gain_dB;//-USRP_GAIN_OFFSET; - - if (UE->UE_scan_carrier==1) - openair0_cfg[UE->rf_map.card].autocal[UE->rf_map.chain+i] = 1; - } - - if (UE->mode != loop_through_memory) - UE->rfdevice.trx_set_freq_func(&UE->rfdevice,&openair0_cfg[0],0); - }// initial_sync=0 - - break; - - case si: - default: - break; - } - -#if 0 //defined XFORMS - - if (do_forms) { - extern FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; - phy_scope_UE(form_ue[0], - PHY_vars_UE_g[0][0], - 0,0,1); - } - -#endif - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - // indicate readiness - UE->proc.instance_cnt_synch--; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_UE_THREAD_SYNCH, 0 ); - } // while !oai_exit - - return &UE_thread_synch_retval; -} - -void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { - // Process Rx data for one sub-frame - if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_DOWNLINK_SLOT) { - //clean previous FAPI MESSAGE - UE->rx_ind.number_pdus = 0; - UE->dci_ind.number_of_dcis = 0; - //clean previous FAPI MESSAGE - // call L2 for DL_CONFIG (DCI) - UE->dcireq.module_id = UE->Mod_id; - UE->dcireq.gNB_index = 0; - UE->dcireq.cc_id = 0; - UE->dcireq.frame = proc->frame_rx; - UE->dcireq.slot = proc->nr_tti_rx; - nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later - NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); - UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req; - UE_mac->scheduled_response.slot = proc->nr_tti_rx; - nr_ue_scheduled_response(&UE_mac->scheduled_response); - //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); - printf("Processing slot %d\n",proc->nr_tti_rx); -#ifdef UE_SLOT_PARALLELISATION - phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); -#else - phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode); - // printf(">>> nr_ue_pdcch_procedures ended\n"); -#endif - } - - if (UE->mac_enabled==1) { - // trigger L2 to run ue_scheduler thru IF module - // [TODO] mapping right after NR initial sync - if(UE->if_inst != NULL && UE->if_inst->ul_indication != NULL) { - UE->ul_indication.module_id = 0; - UE->ul_indication.gNB_index = 0; - UE->ul_indication.cc_id = 0; - UE->ul_indication.frame = proc->frame_rx; - UE->ul_indication.slot = proc->nr_tti_rx; - UE->if_inst->ul_indication(&UE->ul_indication); - } - } -} - -/*! - * \brief This is the UE thread for RX subframe n and TX subframe n+4. - * This thread performs the phy_procedures_UE_RX() on every received slot. - * then, if TX is enabled it performs TX for n+4. - * \param arg is a pointer to a \ref PHY_VARS_NR_UE structure. - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ - -static void *UE_thread_rxn_txnp4(void *arg) { - struct nr_rxtx_thread_data *rtd = arg; - UE_nr_rxtx_proc_t *proc = rtd->proc; - PHY_VARS_NR_UE *UE = rtd->UE; - //proc->counter_decoder = 0; - proc->instance_cnt_rxtx=-1; - proc->subframe_rx=proc->sub_frame_start; - proc->dci_err_cnt=0; - char threadname[256]; - sprintf(threadname,"UE_%d_proc_%d", UE->Mod_id, proc->sub_frame_start); - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - char timing_proc_name[256]; - sprintf(timing_proc_name,"Delay to process sub-frame proc %d",proc->sub_frame_start); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 0 && threads.one != -1 ) - CPU_SET(threads.one, &cpuset); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 1 && threads.two != -1 ) - CPU_SET(threads.two, &cpuset); - - if ( (proc->sub_frame_start+1)%RX_NB_TH == 2 && threads.three != -1 ) - CPU_SET(threads.three, &cpuset); - - //CPU_SET(threads.three, &cpuset); - init_thread(900000,1000000, FIFO_PRIORITY-1, &cpuset, - threadname); - - while (!oai_exit) { - AssertFatal( 0 == pthread_mutex_lock(&proc->mutex_rxtx), "[SCHED][UE] error locking mutex for UE RXTX\n" ); - - while (proc->instance_cnt_rxtx < 0) { - // most of the time, the thread is waiting here - pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); - } - - AssertFatal ( 0== pthread_mutex_unlock(&proc->mutex_rxtx), "[SCHED][UE] error unlocking mutex for UE RXn_TXnp4\n" ); - processSubframeRX(UE, proc); - //printf(">>> mac ended\n"); - // Prepare the future Tx data -#if 0 -#ifndef NO_RAT_NR - - if (slot_select_nr(&UE->frame_parms, proc->frame_tx, proc->nr_tti_tx) & NR_UPLINK_SLOT) -#else - if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_UL) || - (UE->frame_parms.frame_type == FDD) ) -#endif - if (UE->mode != loop_through_memory) - phy_procedures_nrUE_TX(UE,proc,0,0,UE->mode,no_relay); - - //phy_procedures_UE_TX(UE,proc,0,0,UE->mode,no_relay); -#endif -#if 0 - - if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_S) && - (UE->frame_parms.frame_type == TDD)) - if (UE->mode != loop_through_memory) - //phy_procedures_UE_S_TX(UE,0,0,no_relay); - updateTimes(current, &t3, 10000, timing_proc_name); - -#endif - AssertFatal( 0 == pthread_mutex_lock(&proc->mutex_rxtx), "[SCHED][UE] error locking mutex for UE RXTX\n" ); - proc->instance_cnt_rxtx--; -#if BASIC_SIMULATOR - - if (pthread_cond_signal(&proc->cond_rxtx) != 0) abort(); - -#endif - AssertFatal (0 == pthread_mutex_unlock(&proc->mutex_rxtx), "[SCHED][UE] error unlocking mutex for UE RXTX\n" ); - } - - // thread finished - free(arg); - return NULL; -} - -void readFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - void *rxp[NB_ANTENNAS_RX]; - - for(int x=0; x<10; x++) { - for (int i=0; iframe_parms.nb_antennas_rx; i++) - rxp[i] = ((void *)&UE->common_vars.rxdata[i][0]) + 4*x*UE->frame_parms.samples_per_subframe; - - AssertFatal( UE->frame_parms.samples_per_subframe == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - rxp, - UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx), "readFrame error"); - } - -} - -void trashFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - void *dummy_rx[UE->frame_parms.nb_antennas_rx]; - - for (int i=0; iframe_parms.nb_antennas_rx; i++) - dummy_rx[i]=malloc16(UE->frame_parms.samples_per_subframe*4); - - for (int sf=0; sfframe_parms.samples_per_subframe == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - dummy_rx, - UE->frame_parms.samples_per_subframe, - UE->frame_parms.nb_antennas_rx), "trashFrame error"); - //usleep(500); // this sleep improves in the case of simulated RF and doesn't harm with true radio - } - - for (int i=0; iframe_parms.nb_antennas_rx; i++) - free(dummy_rx[i]); -} - -void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) { - if (UE->no_timing_correction==0) { - LOG_I(PHY,"Resynchronizing RX by %d samples (mode = %d)\n",UE->rx_offset,UE->mode); - - for ( int size=UE->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 ; - AssertFatal(unitTransfer == - UE->rfdevice.trx_read_func(&UE->rfdevice, - timestamp, - (void **)UE->common_vars.rxdata, - unitTransfer, - UE->frame_parms.nb_antennas_rx),"syncInFrame error"); - } - } -} - -int computeSamplesShift(PHY_VARS_NR_UE *UE) { - if ( getenv("RFSIMULATOR") != 0) { - LOG_E(PHY,"SET rx_offset %d \n",UE->rx_offset); - //UE->rx_offset_diff=0; - return 0; - } - - // compute TO compensation that should be applied for this frame - if ( UE->rx_offset < 5*UE->frame_parms.samples_per_slot && - UE->rx_offset > 0 ) - return -1 ; - - if ( UE->rx_offset > 5*UE->frame_parms.samples_per_slot && - UE->rx_offset < 10*UE->frame_parms.samples_per_slot ) - return 1; - - return 0; -} - -/*! - * \brief This is the main UE thread. - * This thread controls the other three UE threads: - * - UE_thread_rxn_txnp4 (even subframes) - * - UE_thread_rxn_txnp4 (odd subframes) - * - UE_thread_synch - * \param arg unused - * \returns a pointer to an int. The storage is not on the heap and must not be freed. - */ - -void *UE_thread(void *arg) { - PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; - // int tx_enabled = 0; - openair0_timestamp timestamp; - void *rxp[NB_ANTENNAS_RX], *txp[NB_ANTENNAS_TX]; - int start_rx_stream = 0; - int i; - char threadname[128]; - int th_id; - const uint16_t table_sf_slot[20] = {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9}; - - for (int i=0; i< RX_NB_TH_MAX; i++ ) - UE->proc.proc_rxtx[i].counter_decoder = 0; - - static uint8_t thread_idx = 0; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - if ( threads.main != -1 ) - CPU_SET(threads.main, &cpuset); - - sprintf(threadname, "Main UE %d", UE->Mod_id); - init_thread(100000, 500000, FIFO_PRIORITY, &cpuset,threadname); - - if ((oaisim_flag == 0) && (UE->mode !=loop_through_memory)) - AssertFatal(0== openair0_device_load(&(UE->rfdevice), &openair0_cfg[0]), ""); - - UE->rfdevice.host_type = RAU_HOST; - init_UE_threads(UE); -#ifdef NAS_UE - //MessageDef *message_p; - //message_p = itti_alloc_new_message(TASK_NAS_UE, INITIALIZE_MESSAGE); - //itti_send_msg_to_task (TASK_NAS_UE, UE->Mod_id + NB_eNB_INST, message_p); -#endif - int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; - int slot_nr=-1; - - //int cumulated_shift=0; - if ((oaisim_flag == 0) && (UE->mode != loop_through_memory)) - AssertFatal(UE->rfdevice.trx_start_func(&UE->rfdevice) == 0, "Could not start the device\n"); - - while (!oai_exit) { - AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), ""); - int instance_cnt_synch = UE->proc.instance_cnt_synch; - int is_synchronized = UE->is_synchronized; - AssertFatal ( 0== pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - - if (is_synchronized == 0) { -#if BASIC_SIMULATOR - - while (!((instance_cnt_synch = UE->proc.instance_cnt_synch) < 0)) { - printf("ue sync not ready\n"); - usleep(500*1000); - } - -#endif - - if (UE->mode != loop_through_memory) { - if (instance_cnt_synch < 0) { // we can invoke the synch - // grab 10 ms of signal and wakeup synch thread - readFrame(UE, ×tamp); - AssertFatal( 0 == pthread_mutex_lock(&UE->proc.mutex_synch), ""); - AssertFatal( 0 == ++UE->proc.instance_cnt_synch, "[SCHED][UE] UE sync thread busy!!\n" ); - AssertFatal( 0 == pthread_cond_signal(&UE->proc.cond_synch), ""); - AssertFatal( 0 == pthread_mutex_unlock(&UE->proc.mutex_synch), ""); - } else { - // grab 10 ms of signal into dummy buffer to wait result of sync detection - trashFrame(UE, ×tamp); - } - } - - continue; - } - - if (start_rx_stream==0) { - start_rx_stream=1; - - if (UE->mode != loop_through_memory) { - syncInFrame(UE, ×tamp); - UE->rx_offset=0; - UE->time_sync_cell=0; - UE->proc.proc_rxtx[0].frame_rx++; - - //UE->proc.proc_rxtx[1].frame_rx++; - for (th_id=1; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].frame_rx = UE->proc.proc_rxtx[0].frame_rx; - } - - //printf("first stream frame rx %d\n",UE->proc.proc_rxtx[0].frame_rx); - // read in first symbol - AssertFatal (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0 == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - (void **)UE->common_vars.rxdata, - UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0, - UE->frame_parms.nb_antennas_rx),"first symbol read error"); - //write_output("txdata_sym.m", "txdata_sym", UE->common_vars.rxdata[0], (UE->frame_parms.ofdm_symbol_size+UE->frame_parms.nb_prefix_samples0), 1, 1); - //nr_slot_fep(UE,0, 0, 0, 1, NR_PDCCH_EST); - } //UE->mode != loop_through_memory - else - rt_sleep_ns(1000*1000); - - continue; - } - - thread_idx++; - thread_idx%=RX_NB_TH; - //printf("slot_nr %d nb slot frame %d\n",slot_nr, nb_slot_frame); - slot_nr++; - slot_nr %= nb_slot_frame; - UE_nr_rxtx_proc_t *proc = &UE->proc.proc_rxtx[thread_idx]; - // update thread index for received subframe - UE->current_thread_id[slot_nr] = thread_idx; -#if BASIC_SIMULATOR - - for (int t = 0; t < RX_NB_TH; t++) { - UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[t]; - pthread_mutex_lock(&proc->mutex_rxtx); - - while (proc->instance_cnt_rxtx >= 0) pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx ); - - pthread_mutex_unlock(&proc->mutex_rxtx); - } - -#endif - LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, UE->current_thread_id[slot_nr]); - proc->nr_tti_rx=slot_nr; - proc->subframe_rx=table_sf_slot[slot_nr]; - proc->frame_tx = proc->frame_rx; - proc->nr_tti_tx= slot_nr + DURATION_RX_TO_TX; - - if (proc->nr_tti_tx > nb_slot_frame) { - proc->frame_tx = (proc->frame_tx + 1)%MAX_FRAME_NUMBER; - proc->nr_tti_tx %= nb_slot_frame; - } - - if(slot_nr == 0) { - UE->proc.proc_rxtx[0].frame_rx++; - - //UE->proc.proc_rxtx[1].frame_rx++; - for (th_id=1; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].frame_rx = UE->proc.proc_rxtx[0].frame_rx; - } - } - - if (UE->mode != loop_through_memory) { - for (i=0; iframe_parms.nb_antennas_rx; i++) - rxp[i] = (void *)&UE->common_vars.rxdata[i][UE->frame_parms.ofdm_symbol_size+ - UE->frame_parms.nb_prefix_samples0+ - slot_nr*UE->frame_parms.samples_per_slot]; - - for (i=0; iframe_parms.nb_antennas_tx; i++) - txp[i] = (void *)&UE->common_vars.txdata[i][((slot_nr+2)%NR_NUMBER_OF_SUBFRAMES_PER_FRAME)*UE->frame_parms.samples_per_slot]; - - int readBlockSize, writeBlockSize; - - if (slot_nr<(nb_slot_frame - 1)) { - readBlockSize=UE->frame_parms.samples_per_slot; - writeBlockSize=UE->frame_parms.samples_per_slot; - } else { - UE->rx_offset_diff = computeSamplesShift(UE); - readBlockSize=UE->frame_parms.samples_per_slot - - UE->frame_parms.ofdm_symbol_size - - UE->frame_parms.nb_prefix_samples0 - - UE->rx_offset_diff; - writeBlockSize=UE->frame_parms.samples_per_slot - - UE->rx_offset_diff; - } - - AssertFatal(readBlockSize == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - rxp, - readBlockSize, - UE->frame_parms.nb_antennas_rx),"read error"); - AssertFatal( writeBlockSize == - UE->rfdevice.trx_write_func(&UE->rfdevice, - timestamp+ - (2*UE->frame_parms.samples_per_slot) - - UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0 - - openair0_cfg[0].tx_sample_advance, - txp, - writeBlockSize, - UE->frame_parms.nb_antennas_tx, - 1),"write error"); - - if( slot_nr==(nb_slot_frame-1)) { - // read in first symbol of next frame and adjust for timing drift - int first_symbols=writeBlockSize-readBlockSize; - - if ( first_symbols > 0 ) - AssertFatal(first_symbols == - UE->rfdevice.trx_read_func(&UE->rfdevice, - ×tamp, - (void **)UE->common_vars.rxdata, - first_symbols, - UE->frame_parms.nb_antennas_rx),"first symbols read error"); - else - LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols); - } - - pickTime(gotIQs); - // operate on thread sf mod 2 - AssertFatal(pthread_mutex_lock(&proc->mutex_rxtx) ==0,""); -#ifdef SAIF_ENABLED - - if (!(proc->frame_rx%4000)) { - printf("frame_rx=%d rx_thread_busy=%ld - rate %8.3f\n", - proc->frame_rx, g_ue_rx_thread_busy, - (float)g_ue_rx_thread_busy/(proc->frame_rx*10+1)*100.0); - fflush(stdout); - } - -#endif - - //UE->proc.proc_rxtx[0].gotIQs=readTime(gotIQs); - //UE->proc.proc_rxtx[1].gotIQs=readTime(gotIQs); - for (th_id=0; th_id < RX_NB_TH; th_id++) { - UE->proc.proc_rxtx[th_id].gotIQs=readTime(gotIQs); - } - - proc->subframe_tx=proc->nr_tti_rx; - proc->timestamp_tx = timestamp+ - (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- - UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; - proc->instance_cnt_rxtx++; - LOG_D( PHY, "[SCHED][UE %d] UE RX instance_cnt_rxtx %d subframe %d !!\n", UE->Mod_id, proc->instance_cnt_rxtx,proc->subframe_rx); - - if (proc->instance_cnt_rxtx != 0) { -#ifdef SAIF_ENABLED - g_ue_rx_thread_busy++; -#endif - - if ( getenv("RFSIMULATOR") != NULL ) { - do { - AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, ""); - usleep(100); - AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, ""); - } while ( proc->instance_cnt_rxtx >= 0); - } else - LOG_E( PHY, "[SCHED][UE %d] !! UE RX thread busy (IC %d)!!\n", UE->Mod_id, proc->instance_cnt_rxtx); - - AssertFatal( proc->instance_cnt_rxtx <= 4, "[SCHED][UE %d] !!! UE instance_cnt_rxtx > 2 (IC %d) (Proc %d)!!", - UE->Mod_id, proc->instance_cnt_rxtx, - UE->current_thread_id[slot_nr]); - } - - AssertFatal (pthread_cond_signal(&proc->cond_rxtx) ==0,""); - AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) ==0,""); - // initRefTimes(t1); - // initStaticTime(lastTime); - // updateTimes(lastTime, &t1, 20000, "Delay between two IQ acquisitions (case 1)"); - // pickStaticTime(lastTime); - } //UE->mode != loop_through_memory - else { - processSubframeRX(UE,proc); - getchar(); - } // else loop_through_memory - } // while !oai_exit - - return NULL; -} - -/*! - * \brief Initialize the UE theads. - * Creates the UE threads: - * - UE_thread_rxtx0 - * - UE_thread_rxtx1 - * - UE_thread_synch - * - UE_thread_fep_slot0 - * - UE_thread_fep_slot1 - * - UE_thread_dlsch_proc_slot0 - * - UE_thread_dlsch_proc_slot1 - * and the locking between them. - */ -void init_UE_threads(PHY_VARS_NR_UE *UE) { - struct nr_rxtx_thread_data *rtd; - pthread_attr_init (&UE->proc.attr_ue); - pthread_attr_setstacksize(&UE->proc.attr_ue,8192);//5*PTHREAD_STACK_MIN); - pthread_mutex_init(&UE->proc.mutex_synch,NULL); - pthread_cond_init(&UE->proc.cond_synch,NULL); - UE->proc.instance_cnt_synch = -1; - - // the threads are not yet active, therefore access is allowed without locking - for (int i=0; iUE = UE; - rtd->proc = &UE->proc.proc_rxtx[i]; - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_rxtx,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_rxtx,NULL); - UE->proc.proc_rxtx[i].sub_frame_start=i; - UE->proc.proc_rxtx[i].sub_frame_step=RX_NB_TH; - printf("Init_UE_threads rtd %d proc %d nb_threads %d i %d\n",rtd->proc->sub_frame_start, UE->proc.proc_rxtx[i].sub_frame_start,RX_NB_TH, i); - pthread_create(&UE->proc.proc_rxtx[i].pthread_rxtx, NULL, UE_thread_rxn_txnp4, rtd); -#ifdef UE_DLSCH_PARALLELISATION - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_dlsch_td,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_dlsch_td,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_dlsch_td,NULL,nr_dlsch_decoding_2thread0, rtd); - //thread 2 - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_dlsch_td1,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_dlsch_td1,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_dlsch_td1,NULL,nr_dlsch_decoding_2thread1, rtd); -#endif -#ifdef UE_SLOT_PARALLELISATION - //pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_slot0_dl_processing,NULL); - //pthread_cond_init(&UE->proc.proc_rxtx[i].cond_slot0_dl_processing,NULL); - //pthread_create(&UE->proc.proc_rxtx[i].pthread_slot0_dl_processing,NULL,UE_thread_slot0_dl_processing, rtd); - pthread_mutex_init(&UE->proc.proc_rxtx[i].mutex_slot1_dl_processing,NULL); - pthread_cond_init(&UE->proc.proc_rxtx[i].cond_slot1_dl_processing,NULL); - pthread_create(&UE->proc.proc_rxtx[i].pthread_slot1_dl_processing,NULL,UE_thread_slot1_dl_processing, rtd); -#endif - } - - pthread_create(&UE->proc.pthread_synch,NULL,UE_thread_synch,(void *)UE); -} - - -#ifdef OPENAIR2 - /* - void fill_ue_band_info(void) { - - UE_EUTRA_Capability_t *UE_EUTRA_Capability = UE_rrc_inst[0].UECap->UE_EUTRA_Capability; - int i,j; - - bands_to_scan.nbands = UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.count; - - for (i=0; irf_Parameters.supportedBandListEUTRA.list.array[i]->bandEUTRA) { - memcpy(&bands_to_scan.band_info[i], - &eutra_bands[j], - sizeof(eutra_band_t)); - - printf("Band %d (%lu) : DL %u..%u Hz, UL %u..%u Hz, Duplex %s \n", - bands_to_scan.band_info[i].band, - UE_EUTRA_Capability->rf_Parameters.supportedBandListEUTRA.list.array[i]->bandEUTRA, - bands_to_scan.band_info[i].dl_min, - bands_to_scan.band_info[i].dl_max, - bands_to_scan.band_info[i].ul_min, - bands_to_scan.band_info[i].ul_max, - (bands_to_scan.band_info[i].frame_type==FDD) ? "FDD" : "TDD"); - break; - } - } - }*/ -#endif - -/* -int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg) { - - int i, CC_id; - NR_DL_FRAME_PARMS *frame_parms; - openair0_rf_map *rf_map; - - for (CC_id=0; CC_idrf_map; - - AssertFatal( phy_vars_ue[CC_id] !=0, ""); - frame_parms = &(phy_vars_ue[CC_id]->frame_parms); - - // replace RX signal buffers with mmaped HW versions - rxdata = (int32_t**)malloc16( frame_parms->nb_antennas_rx*sizeof(int32_t*) ); - txdata = (int32_t**)malloc16( frame_parms->nb_antennas_tx*sizeof(int32_t*) ); - - for (i=0; inb_antennas_rx; i++) { - LOG_I(PHY, "Mapping UE CC_id %d, rx_ant %d, freq %u on card %d, chain %d\n", - CC_id, i, downlink_frequency[CC_id][i], rf_map->card, rf_map->chain+i ); - free( phy_vars_ue[CC_id]->common_vars.rxdata[i] ); - rxdata[i] = (int32_t*)malloc16_clear( 307200*sizeof(int32_t) ); - phy_vars_ue[CC_id]->common_vars.rxdata[i] = rxdata[i]; // what about the "-N_TA_offset" ? // N_TA offset for TDD - } - - for (i=0; inb_antennas_tx; i++) { - LOG_I(PHY, "Mapping UE CC_id %d, tx_ant %d, freq %u on card %d, chain %d\n", - CC_id, i, downlink_frequency[CC_id][i], rf_map->card, rf_map->chain+i ); - free( phy_vars_ue[CC_id]->common_vars.txdata[i] ); - txdata[i] = (int32_t*)malloc16_clear( 307200*sizeof(int32_t) ); - phy_vars_ue[CC_id]->common_vars.txdata[i] = txdata[i]; - } - - // rxdata[x] points now to the same memory region as phy_vars_ue[CC_id]->common_vars.rxdata[x] - // txdata[x] points now to the same memory region as phy_vars_ue[CC_id]->common_vars.txdata[x] - // be careful when releasing memory! - // because no "release_ue_buffers"-function is available, at least rxdata and txdata memory will leak (only some bytes) - } - return 0; -} -*/ diff --git a/targets/RT/USER/nr-uesoftmodem.c b/targets/RT/USER/nr-uesoftmodem.c deleted file mode 100644 index 226010a1db..0000000000 --- a/targets/RT/USER/nr-uesoftmodem.c +++ /dev/null @@ -1,1262 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - - -#define _GNU_SOURCE /* See feature_test_macros(7) */ -#include - -#include "T.h" -#include "rt_wrapper.h" - -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "assertions.h" -#include "msc.h" - -#include "PHY/types.h" -#include "PHY/defs_nr_UE.h" -#include "common/ran_context.h" -#include "common/config/config_userapi.h" -#include "common/utils/load_module_shlib.h" -#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "../../ARCH/COMMON/common_lib.h" -#include "../../ARCH/ETHERNET/USERSPACE/LIB/if_defs.h" - -//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all - -#include "PHY/phy_vars_nr_ue.h" -#include "PHY/LTE_TRANSPORT/transport_vars.h" -#include "SCHED/sched_common_vars.h" -#include "PHY/MODULATION/modulation_vars.h" -//#include "../../SIMU/USER/init_lte.h" - -#include "LAYER2/MAC/mac.h" -#include "LAYER2/MAC/mac_vars.h" -#include "LAYER2/MAC/mac_proto.h" -#include "RRC/LTE/rrc_vars.h" -#include "PHY_INTERFACE/phy_interface_vars.h" - -#ifdef SMBV -#include "PHY/TOOLS/smbv.h" -unsigned short config_frames[4] = {2,9,11,13}; -#endif -#include "common/utils/LOG/log.h" -#include "common/utils/LOG/vcd_signal_dumper.h" - -#include "UTIL/OPT/opt.h" -#include "enb_config.h" -//#include "PHY/TOOLS/time_meas.h" - -#ifndef OPENAIR2 -#include "UTIL/OTG/otg_vars.h" -#endif - -#if defined(ENABLE_ITTI) -#include "intertask_interface.h" -#include "create_tasks.h" -#endif - -#include "PHY/INIT/phy_init.h" -#include "system.h" -#include "stats.h" -#ifdef XFORMS -#include "PHY/TOOLS/nr_phy_scope.h" -//#include "stats.h" -// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0) -// at eNB 0, an UL scope for every UE -FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; -//FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX]; -//FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; -char title[255]; -//unsigned char scope_enb_num_ue = 2; -static pthread_t forms_thread; //xforms -#endif //XFORMS -#include "nr-uesoftmodem.h" - -RAN_CONTEXT_t RC; - -pthread_cond_t sync_cond; -pthread_mutex_t sync_mutex; -int sync_var=-1; //!< protected by mutex \ref sync_mutex. - -uint16_t runtime_phy_rx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100] -uint16_t runtime_phy_tx[29][6]; // SISO [MCS 0-28][RBs 0-5 : 6, 15, 25, 50, 75, 100] - -#if defined(ENABLE_ITTI) -volatile int start_eNB = 0; -volatile int start_UE = 0; -#endif -volatile int oai_exit = 0; - -static clock_source_t clock_source = internal; -static int wait_for_sync = 0; - -unsigned int mmapped_dma=0; -int single_thread_flag=1; - -int threequarter_fs=0; - -uint32_t downlink_frequency[MAX_NUM_CCs][4]; -int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; - -extern int16_t nr_dlsch_demod_shift; - - -//static char *conf_config_file_name = NULL; - -#if defined(ENABLE_ITTI) -static char *itti_dump_file = NULL; -#endif - -int UE_scan = 0; -int UE_scan_carrier = 0; -int UE_fo_compensation = 0; -runmode_t mode = normal_txrx; - -FILE *input_fd=NULL; - - -#if MAX_NUM_CCs == 1 -rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain}}; -double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0}}; -double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0}}; -#else -rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain},{max_gain,max_gain,max_gain,max_gain}}; -double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0},{20,0,0,0}}; -double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0},{20,0,0,0}}; -#endif - -double rx_gain_off = 0.0; - -double sample_rate=30.72e6; -double bw = 10.0e6; - -static int tx_max_power[MAX_NUM_CCs] = {0}; - -char rf_config_file[1024]; - -int chain_offset=0; -int phy_test = 0; -uint8_t usim_test = 0; - -uint8_t dci_Format = 0; -uint8_t agregation_Level =0xFF; - -uint8_t nb_antenna_tx = 1; -uint8_t nb_antenna_rx = 1; - -char ref[128] = "internal"; -char channels[128] = "0"; - -char *parallel_config = NULL; -char *worker_config = NULL; - -static THREAD_STRUCT thread_struct; -void set_parallel_conf(char *parallel_conf) -{ - if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; - else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; - printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); -} -void set_worker_conf(char *worker_conf) -{ - if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; - else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; - printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); -} -PARALLEL_CONF_t get_thread_parallel_conf(void) -{ - return thread_struct.parallel_conf; -} -WORKER_CONF_t get_thread_worker_conf(void) -{ - return thread_struct.worker_conf; -} -int rx_input_level_dBm; - -//static int online_log_messages=0; - -#ifdef XFORMS -extern int otg_enabled; -int do_forms=0; -#else -int otg_enabled; -#endif -//int number_of_cards = 1; - -static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; -int16_t node_synch_ref[MAX_NUM_CCs]; - -uint32_t target_dl_mcs = 28; //maximum allowed mcs -uint32_t target_ul_mcs = 20; -uint32_t timing_advance = 0; -uint8_t exit_missed_slots=1; -uint64_t num_missed_slots=0; // counter for the number of missed slots - -extern PHY_VARS_NR_UE* init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, - uint8_t UE_id, - uint8_t abstraction_flag); - -int transmission_mode=1; -int numerology = 0; - -/* -int16_t glog_level = LOG_INFO; -int16_t glog_verbosity = LOG_MED; -int16_t hw_log_level = LOG_INFO; -int16_t hw_log_verbosity = LOG_MED; -int16_t phy_log_level = LOG_INFO; -int16_t phy_log_verbosity = LOG_MED; -int16_t mac_log_level = LOG_INFO; -int16_t mac_log_verbosity = LOG_MED; -int16_t rlc_log_level = LOG_INFO; -int16_t rlc_log_verbosity = LOG_MED; -int16_t pdcp_log_level = LOG_INFO; -int16_t pdcp_log_verbosity = LOG_MED; -int16_t rrc_log_level = LOG_INFO; -int16_t rrc_log_verbosity = LOG_MED; -int16_t opt_log_level = LOG_INFO; -int16_t opt_log_verbosity = LOG_MED; - -# if defined(ENABLE_USE_MME) -int16_t gtpu_log_level = LOG_DEBUG; -int16_t gtpu_log_verbosity = LOG_MED; -int16_t udp_log_level = LOG_DEBUG; -int16_t udp_log_verbosity = LOG_MED; -#endif -#if defined (ENABLE_SECURITY) -int16_t osa_log_level = LOG_INFO; -int16_t osa_log_verbosity = LOG_MED; -#endif -*/ - -char *rrh_UE_ip = "127.0.0.1"; -int rrh_UE_port = 51000; - -/* flag set by eNB conf file to specify if the radio head is local or remote (default option is local) */ -//uint8_t local_remote_radio = BBU_LOCAL_RADIO_HEAD; -/* struct for ethernet specific parameters given in eNB conf file */ -//eth_params_t *eth_params; - -openair0_config_t openair0_cfg[MAX_CARDS]; - -double cpuf; - -char uecap_xer[1024],uecap_xer_in=0; - -int oaisim_flag=0; -int emulate_rf = 0; - -threads_t threads = {-1,-1,-1,-1,-1,-1,-1,-1}; -int threads_offset = 0; - -char* usrp_args=NULL; -char* usrp_clksrc=NULL; - -/* forward declarations */ -void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); - - -/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed - * this is very hackish - find a proper solution - */ -uint8_t abstraction_flag=0; - -/*---------------------BMC: timespec helpers -----------------------------*/ - -struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; -struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; - -struct timespec clock_difftime(struct timespec start, struct timespec end) { - struct timespec temp; - if ((end.tv_nsec-start.tv_nsec)<0) { - temp.tv_sec = end.tv_sec-start.tv_sec-1; - temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; - } else { - temp.tv_sec = end.tv_sec-start.tv_sec; - temp.tv_nsec = end.tv_nsec-start.tv_nsec; - } - return temp; -} - -void print_difftimes(void) { -#ifdef DEBUG - printf("difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); -#else - LOG_I(HW,"difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); -#endif -} - -void update_difftimes(struct timespec start, struct timespec end) { - struct timespec diff_time = { .tv_sec = 0, .tv_nsec = 0 }; - int changed = 0; - diff_time = clock_difftime(start, end); - if ((min_diff_time.tv_nsec == 0) || (diff_time.tv_nsec < min_diff_time.tv_nsec)) { - min_diff_time.tv_nsec = diff_time.tv_nsec; - changed = 1; - } - if ((max_diff_time.tv_nsec == 0) || (diff_time.tv_nsec > max_diff_time.tv_nsec)) { - max_diff_time.tv_nsec = diff_time.tv_nsec; - changed = 1; - } -#if 1 - if (changed) print_difftimes(); -#endif -} - -/*------------------------------------------------------------------------*/ - -unsigned int build_rflocal(int txi, int txq, int rxi, int rxq) { - return (txi + (txq<<6) + (rxi<<12) + (rxq<<18)); -} -unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) { - return (dcoff_i_rxfe + (dcoff_q_rxfe<<8)); -} - -#if !defined(ENABLE_ITTI) -void signal_handler(int sig) { - void *array[10]; - size_t size; - - if (sig==SIGSEGV) { - // get void*'s for all entries on the stack - size = backtrace(array, 10); - - // print out all the frames to stderr - fprintf(stderr, "Error: signal %d:\n", sig); - backtrace_symbols_fd(array, size, 2); - exit(-1); - } else { - printf("trying to exit gracefully...\n"); - oai_exit = 1; - } -} -#endif -#define KNRM "\x1B[0m" -#define KRED "\x1B[31m" -#define KGRN "\x1B[32m" -#define KBLU "\x1B[34m" -#define RESET "\033[0m" - - -void exit_function(const char* file, const char* function, const int line, const char* s) -{ - - int CC_id; - - if (s != NULL) { - printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s); - } - - oai_exit = 1; - - if (PHY_vars_UE_g && PHY_vars_UE_g[0]) { - for(CC_id=0; CC_idrfdevice.trx_end_func) - PHY_vars_UE_g[0][CC_id]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][CC_id]->rfdevice); - } - } - -#if defined(ENABLE_ITTI) - sleep(1); //allow lte-softmodem threads to exit first - itti_terminate_tasks (TASK_UNKNOWN); -#endif -} - -#ifdef XFORMS - - -void reset_stats(FL_OBJECT *button, long arg) { - //int i,j,k; - /*PHY_VARS_eNB *phy_vars_eNB = PHY_vars_eNB_g[0][0]; - - for (i=0; idlsch[i][0]->Mlimit; j++) { - phy_vars_eNB->UE_stats[i].dlsch_NAK[k][j]=0; - phy_vars_eNB->UE_stats[i].dlsch_ACK[k][j]=0; - phy_vars_eNB->UE_stats[i].dlsch_trials[k][j]=0; - } - - phy_vars_eNB->UE_stats[i].dlsch_l2_errors[k]=0; - phy_vars_eNB->UE_stats[i].ulsch_errors[k]=0; - phy_vars_eNB->UE_stats[i].ulsch_consecutive_errors=0; - - for (j=0; julsch[i]->Mlimit; j++) { - phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_decoding_attempts_last[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_round_errors[k][j]=0; - phy_vars_eNB->UE_stats[i].ulsch_round_fer[k][j]=0; - } - } - - phy_vars_eNB->UE_stats[i].dlsch_sliding_cnt=0; - phy_vars_eNB->UE_stats[i].dlsch_NAK_round0=0; - phy_vars_eNB->UE_stats[i].dlsch_mcs_offset=0; - }*/ -} - -static void *scope_thread(void *arg) { - char stats_buffer[16384]; -# ifdef ENABLE_XFORMS_WRITE_STATS - FILE *UE_stats, *eNB_stats; -# endif - //int len = 0; - struct sched_param sched_param; - //int UE_id, CC_id; - //int ue_cnt=0; - - sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1; - sched_setscheduler(0, SCHED_FIFO,&sched_param); - - printf("Scope thread has priority %d\n",sched_param.sched_priority); - -# ifdef ENABLE_XFORMS_WRITE_STATS - - UE_stats = fopen("UE_stats.txt", "w"); - -#endif - - while (!oai_exit) { - //len = dump_ue_stats (PHY_vars_UE_g[0][0], &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0],stats_buffer, 0, mode,rx_input_level_dBm); - //fl_set_object_label(form_stats->stats_text, stats_buffer); - //fl_clear_browser(form_stats->stats_text); - //fl_add_browser_line(form_stats->stats_text, stats_buffer); - - //if (PHY_vars_UE_g[0][0]->is_synchronized == 1) - phy_scope_UE(form_ue[0], - PHY_vars_UE_g[0][0], - 0,0,1); - //else it is done in the synch thread - - //printf("doing forms\n"); - //usleep(100000); // 100 ms - sleep(0.1); - } - - // printf("%s",stats_buffer); - -# ifdef ENABLE_XFORMS_WRITE_STATS - - if (UE_stats) { - rewind (UE_stats); - fwrite (stats_buffer, 1, len, UE_stats); - fclose (UE_stats); - } - -# endif - - pthread_exit((void*)arg); -} -#endif - - - - -#if defined(ENABLE_ITTI) -void *l2l1_task(void *arg) { - MessageDef *message_p = NULL; - int result; - - itti_set_task_real_time(TASK_L2L1); - itti_mark_task_ready(TASK_L2L1); - - - do { - // Wait for a message - itti_receive_msg (TASK_L2L1, &message_p); - - switch (ITTI_MSG_ID(message_p)) { - case TERMINATE_MESSAGE: - oai_exit=1; - itti_exit_task (); - break; - - case ACTIVATE_MESSAGE: - start_UE = 1; - break; - - case DEACTIVATE_MESSAGE: - start_UE = 0; - break; - - case MESSAGE_TEST: - LOG_I(EMU, "Received %s\n", ITTI_MSG_NAME(message_p)); - break; - - default: - LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p)); - break; - } - - result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - } while(!oai_exit); - - return NULL; -} -#endif - -int16_t dlsch_demod_shift; - -static void get_options(void) { - int CC_id; - int tddflag, nonbiotflag; - char *loopfile=NULL; - int dumpframe=0; - uint32_t online_log_messages; - uint32_t glog_level, glog_verbosity; - uint32_t start_telnetsrv; - - paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; - paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; - - config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); - - if (strlen(in_path) > 0) { - opt_type = OPT_PCAP; - opt_enabled=1; - printf("Enabling OPT for PCAP with the following file %s \n",in_path); - } - if (strlen(in_ip) > 0) { - opt_enabled=1; - opt_type = OPT_WIRESHARK; - printf("Enabling OPT for wireshark for local interface"); - } - - config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); - if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { - set_glog_onlinelog(online_log_messages); - } - if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { - set_glog(glog_level); - } - - if (start_telnetsrv) { - load_module_shlib("telnetsrv",NULL,0,NULL); - } - - paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC; - paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; - - - config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL); - config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL); - if (loopfile != NULL) { - printf("Input file for hardware emulation: %s\n",loopfile); - mode=loop_through_memory; - input_fd = fopen(loopfile,"r"); - AssertFatal(input_fd != NULL,"Please provide a valid input file\n"); - } - - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERX_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue; - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXMED_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_med; - if ( (cmdline_uemodeparams[CMDLINE_CALIBUERXBYP_IDX].paramflags & PARAMFLAG_PARAMSET) != 0) mode = rx_calib_ue_byp; - if (cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_DEBUGUEPRACH_IDX].uptr) > 0) mode = debug_prach; - if (cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_NOL2CONNECT_IDX].uptr) > 0) mode = no_L2_connect; - if (cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) - if ( *(cmdline_uemodeparams[CMDLINE_CALIBPRACHTX_IDX].uptr) > 0) mode = calib_prach_tx; - if (dumpframe > 0) mode = rx_dump_frame; - - for (CC_id=0; CC_iddl_CarrierFreq = downlink_frequency[0][0]; - } - UE_scan=0; - - - if (tddflag > 0) { - for (CC_id=0; CC_idframe_type = TDD; - } - - /*if (frame_parms[0]->N_RB_DL !=0) { - if ( frame_parms[0]->N_RB_DL < 6 ) { - frame_parms[0]->N_RB_DL = 6; - printf ( "%i: Invalid number of ressource blocks, adjusted to 6\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 100 ) { - frame_parms[0]->N_RB_DL = 100; - printf ( "%i: Invalid number of ressource blocks, adjusted to 100\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 50 && frame_parms[0]->N_RB_DL < 100 ) { - frame_parms[0]->N_RB_DL = 50; - printf ( "%i: Invalid number of ressource blocks, adjusted to 50\n",frame_parms[0]->N_RB_DL); - } - if ( frame_parms[0]->N_RB_DL > 25 && frame_parms[0]->N_RB_DL < 50 ) { - frame_parms[0]->N_RB_DL = 25; - printf ( "%i: Invalid number of ressource blocks, adjusted to 25\n",frame_parms[0]->N_RB_DL); - } - UE_scan = 0; - frame_parms[0]->N_RB_UL=frame_parms[0]->N_RB_DL; - for (CC_id=1; CC_idN_RB_DL=frame_parms[0]->N_RB_DL; - frame_parms[CC_id]->N_RB_UL=frame_parms[0]->N_RB_UL; - } - }*/ - - - for (CC_id=1;CC_idsubframe_config.numerology_index_mu.value =1; - config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD - config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL - config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; - config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; - config[CC_id]->sch_config.physical_cell_id.value = 0; - frame_parms[CC_id]->eutra_band = 78; - frame_parms[CC_id]->frame_type = FDD; - frame_parms[CC_id]->tdd_config = 3; - //frame_parms[CC_id]->tdd_config_S = 0; - frame_parms[CC_id]->N_RB_DL = 106; - frame_parms[CC_id]->N_RB_UL = 106; - frame_parms[CC_id]->Ncp = NORMAL; - //frame_parms[CC_id]->Ncp_UL = NORMAL; - frame_parms[CC_id]->Nid_cell = 0; - //frame_parms[CC_id]->num_MBSFN_config = 0; - frame_parms[CC_id]->nb_antenna_ports_eNB = 1; - frame_parms[CC_id]->nb_antennas_tx = 1; - frame_parms[CC_id]->nb_antennas_rx = 1; - - //frame_parms[CC_id]->nushift = 0; - - ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; - //frame_parms[CC_id]->phich_config_common.phich_duration = normal; - - // UL RS Config - /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0 - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; - - frame_parms[CC_id]->pusch_config_common.n_SB = 1; - frame_parms[CC_id]->pusch_config_common.hoppingMode = 0; - frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0; - frame_parms[CC_id]->pusch_config_common.enable64QAM = 0; - - frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/ - - // NR: Init to legacy LTE 20Mhz params - frame_parms[CC_id]->numerology_index = 0; - frame_parms[CC_id]->ttis_per_subframe = 1; - frame_parms[CC_id]->slots_per_tti = 2; - - } - -} - -void init_openair0(void); -void init_openair0() { - - int card; - int i; - - for (card=0; cardN_RB_DL == 106) { - if (numerology==0) { - if (frame_parms[0]->threequarter_fs) { - openair0_cfg[card].sample_rate=23.04e6; - openair0_cfg[card].samples_per_frame = 230400; - openair0_cfg[card].tx_bw = 10e6; - openair0_cfg[card].rx_bw = 10e6; - } else { - openair0_cfg[card].sample_rate=30.72e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 10e6; - openair0_cfg[card].rx_bw = 10e6; - } - } else if (numerology==1) { - openair0_cfg[card].sample_rate=61.44e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 20e6; - openair0_cfg[card].rx_bw = 20e6; - } else if (numerology==2) { - openair0_cfg[card].sample_rate=122.88e6; - openair0_cfg[card].samples_per_frame = 307200; - openair0_cfg[card].tx_bw = 40e6; - openair0_cfg[card].rx_bw = 40e6; - } else { - LOG_E(PHY,"Unsupported numerology!\n"); - exit(-1); - } - } else if(frame_parms[0]->N_RB_DL == 50) { - openair0_cfg[card].sample_rate=15.36e6; - openair0_cfg[card].samples_per_frame = 153600; - openair0_cfg[card].tx_bw = 5e6; - openair0_cfg[card].rx_bw = 5e6; - } else if (frame_parms[0]->N_RB_DL == 25) { - openair0_cfg[card].sample_rate=7.68e6; - openair0_cfg[card].samples_per_frame = 76800; - openair0_cfg[card].tx_bw = 2.5e6; - openair0_cfg[card].rx_bw = 2.5e6; - } else if (frame_parms[0]->N_RB_DL == 6) { - openair0_cfg[card].sample_rate=1.92e6; - openair0_cfg[card].samples_per_frame = 19200; - openair0_cfg[card].tx_bw = 1.5e6; - openair0_cfg[card].rx_bw = 1.5e6; - } - - if (frame_parms[0]->frame_type==TDD) - openair0_cfg[card].duplex_mode = duplex_mode_TDD; - else //FDD - openair0_cfg[card].duplex_mode = duplex_mode_FDD; - - printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card, - PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx, - PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); - openair0_cfg[card].Mod_id = 0; - - openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL; - - openair0_cfg[card].clock_source = clock_source; - - - openair0_cfg[card].tx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_tx); - openair0_cfg[card].rx_num_channels=min(2,PHY_vars_UE_g[0][0]->frame_parms.nb_antennas_rx); - - for (i=0; i<4; i++) { - - if (irx_total_gain_dB - rx_gain_off; - - - openair0_cfg[card].configFilename = rf_config_file; - printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n", - card,i, openair0_cfg[card].tx_gain[i], - openair0_cfg[card].rx_gain[i], - openair0_cfg[card].tx_freq[i], - openair0_cfg[card].rx_freq[i]); - } - - if (usrp_args) openair0_cfg[card].sdr_addrs = usrp_args; - if (usrp_clksrc) { - if (strcmp(usrp_clksrc, "internal") == 0) { - openair0_cfg[card].clock_source = internal; - LOG_D(PHY, "USRP clock source set as internal\n"); - } else if (strcmp(usrp_clksrc, "external") == 0) { - openair0_cfg[card].clock_source = external; - LOG_D(PHY, "USRP clock source set as external\n"); - } else if (strcmp(usrp_clksrc, "gpsdo") == 0) { - openair0_cfg[card].clock_source = gpsdo; - LOG_D(PHY, "USRP clock source set as gpsdo\n"); - } else { - openair0_cfg[card].clock_source = internal; - LOG_I(PHY, "USRP clock source unknown ('%s'). defaulting to internal\n", usrp_clksrc); - } - } else { - openair0_cfg[card].clock_source = internal; - LOG_I(PHY, "USRP clock source not specified. defaulting to internal\n"); - } - - } -} - -int main( int argc, char **argv ) { - int i;//j,k,aa,re; -#if defined (XFORMS) - void *status; -#endif - - int CC_id; - uint8_t abstraction_flag=0; - //uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2; - -#if defined (XFORMS) - int ret; -#endif - - PHY_VARS_NR_UE *UE[MAX_NUM_CCs]; - - start_background_system(); - if ( load_configmodule(argc,argv) == NULL) { - exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); - } - CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); - -#ifdef DEBUG_CONSOLE - setvbuf(stdout, NULL, _IONBF, 0); - setvbuf(stderr, NULL, _IONBF, 0); -#endif - - set_default_frame_parms(frame_parms); - - mode = normal_txrx; - memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS); - - memset(tx_max_power,0,sizeof(int)*MAX_NUM_CCs); - - set_latency_target(); - - // initialize logging - logInit(); - - - // get options and fill parameters from configuration file - get_options (); //Command-line options, enb_properties - -#if T_TRACER - T_Config_Init(); -#endif - - //randominit (0); - set_taus_seed (0); - - printf("configuring for UE\n"); - - //if (ouput_vcd) - // VCD_SIGNAL_DUMPER_INIT("/tmp/openair_dump_UE.vcd"); - - //if (opp_enabled ==1) { - // reset_opp_meas(); - //} - cpuf=get_cpu_freq_GHz(); - -#if defined(ENABLE_ITTI) - //log_set_instance_type (LOG_INSTANCE_UE); - - itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); - - // initialize mscgen log after ITTI - MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); -#endif - - if (opt_type != OPT_NONE) { - if (init_opt(in_path, in_ip) == -1) - LOG_E(OPT,"failed to run OPT \n"); - } - -#ifdef PDCP_USE_NETLINK - netlink_init(); -#if defined(PDCP_USE_NETLINK_QUEUES) - pdcp_netlink_init(); -#endif -#endif - -#if !defined(ENABLE_ITTI) - // to make a graceful exit when ctrl-c is pressed - signal(SIGSEGV, signal_handler); - signal(SIGINT, signal_handler); -#endif - - - check_clock(); - -#ifndef PACKAGE_VERSION -# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL" -#endif - - LOG_I(HW, "Version: %s\n", PACKAGE_VERSION); - - // init the parameters - for (CC_id=0; CC_idnb_antennas_tx = nb_antenna_tx; - frame_parms[CC_id]->nb_antennas_rx = nb_antenna_rx; - frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later - - LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); - - get_band(downlink_frequency[CC_id][0], &frame_parms[CC_id]->eutra_band, &uplink_frequency_offset[CC_id][0], &frame_parms[CC_id]->frame_type); - - //init_ul_hopping(frame_parms[CC_id]); - //phy_init_nr_top(frame_parms[CC_id]); - - //init prach for openair1 test - // prach_fmt = get_prach_fmt(frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->frame_type); - // N_ZC = (prach_fmt <4)?839:139; - } - - NB_UE_INST=1; - NB_INST=1; - PHY_vars_UE_g = malloc(sizeof(PHY_VARS_NR_UE**)); - PHY_vars_UE_g[0] = malloc(sizeof(PHY_VARS_NR_UE*)*MAX_NUM_CCs); - - for (CC_id=0; CC_idofdm_symbol_size); - - nr_init_frame_parms_ue(frame_parms[CC_id],numerology,NORMAL,frame_parms[CC_id]->N_RB_DL,(frame_parms[CC_id]->N_RB_DL-20)>>1,0); - PHY_vars_UE_g[0][CC_id] = init_nr_ue_vars(frame_parms[CC_id], 0,abstraction_flag); - UE[CC_id] = PHY_vars_UE_g[0][CC_id]; - - if (phy_test==1) - UE[CC_id]->mac_enabled = 0; - else - UE[CC_id]->mac_enabled = 1; - - if (UE[CC_id]->mac_enabled == 0) { //set default UL parameters for testing mode - for (i=0; ipusch_config_dedicated[i] = malloc(sizeof(PUSCH_CONFIG_DEDICATED)); - - //UE[CC_id]->scheduling_request_config[i] = malloc(sizeof(SCHEDULING_REQUEST_CONFIG)); - - /*UE[CC_id]->pusch_config_dedicated[i].betaOffset_ACK_Index = beta_ACK; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_RI_Index = beta_RI; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_CQI_Index = beta_CQI; - - UE[CC_id]->scheduling_request_config[i].sr_PUCCH_ResourceIndex = 0; - UE[CC_id]->scheduling_request_config[i].sr_ConfigIndex = 7+(0%3); - UE[CC_id]->scheduling_request_config[i].dsr_TransMax = sr_n4;*/ - } - } - - UE[CC_id]->UE_scan = UE_scan; - UE[CC_id]->UE_scan_carrier = UE_scan_carrier; - UE[CC_id]->UE_fo_compensation = UE_fo_compensation; - UE[CC_id]->mode = mode; - printf("UE[%d]->mode = %d\n",CC_id,mode); - - for (uint8_t i=0; ipdcch_vars[i][0]->agregationLevel = agregation_Level; - //UE[CC_id]->pdcch_vars[i][0]->dciFormat = dci_Format; - - /*compute_prach_seq(&UE[CC_id]->frame_parms.prach_config_common, - UE[CC_id]->frame_parms.frame_type, - UE[CC_id]->X_u);*/ - - if (UE[CC_id]->mac_enabled == 1) - UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1234; - else - UE[CC_id]->pdcch_vars[i][0]->crnti = 0x1235; - } - - UE[CC_id]->rx_total_gain_dB = (int)rx_gain[CC_id][0] + rx_gain_off; - UE[CC_id]->tx_power_max_dBm = tx_max_power[CC_id]; - - if (frame_parms[CC_id]->frame_type==FDD) { - UE[CC_id]->N_TA_offset = 0; - } else { - if (frame_parms[CC_id]->N_RB_DL == 100) - UE[CC_id]->N_TA_offset = 624; - else if (frame_parms[CC_id]->N_RB_DL == 50) - UE[CC_id]->N_TA_offset = 624/2; - else if (frame_parms[CC_id]->N_RB_DL == 25) - UE[CC_id]->N_TA_offset = 624/4; - } - - } - - // printf("tx_max_power = %d -> amp %d\n",tx_max_power[0],get_tx_amp(tx_max_poHwer,tx_max_power)); - - - fill_modeled_runtime_table(runtime_phy_rx,runtime_phy_tx); - cpuf=get_cpu_freq_GHz(); - - - //dump_frame_parms(frame_parms[0]); - - init_openair0(); - - // default threads.main = 2 - // if there are enough processors, all others on subsequent CPUs - if (threads_offset>0) { - if (threads_offset+8<=get_nprocs()) { - if (threads.main<0) threads.main=threads_offset+1; - if (threads.sync<0) threads.sync=threads_offset+2; - if (threads.one<0) threads.one=threads_offset+3; - if (threads.two<0) threads.two=threads_offset+4; - if (threads.three<0) threads.three=threads_offset+5; - if (threads.slot1_proc_one<0) threads.slot1_proc_one=threads_offset+6; - if (threads.slot1_proc_two<0) threads.slot1_proc_two=threads_offset+7; - if (threads.slot1_proc_three<0) threads.slot1_proc_three=threads_offset+8; - } - else { - LOG_E(HW,"Not enough CPUs available (nprocs (=%d) >= threadmain (=%d) + 10)\n",get_nprocs(),threads_offset); - exit_fun("Error setting thread affinity\n"); - } - } - -#ifndef DEADLINE_SCHEDULER - - /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */ - - cpu_set_t cpuset; - int s; - char cpu_affinity[1024]; - CPU_ZERO(&cpuset); -#ifdef CPU_AFFINITY - int j; - if (get_nprocs()>=2) { - for (j = 2; j < get_nprocs(); j++) - CPU_SET(j, &cpuset); - - s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - if (s != 0) { - perror( "pthread_setaffinity_np"); - exit_fun("Error setting processor affinity"); - } - LOG_I(HW, "Setting the affinity of main function to all CPUs, for device library to use CPU 0 only!\n"); - } -#endif - - /* Check the actual affinity mask assigned to the thread */ - s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - if (s != 0) { - perror( "pthread_getaffinity_np"); - exit_fun("Error getting processor affinity "); - } - memset(cpu_affinity, 0 , sizeof(cpu_affinity)); - for (int j = 0; j < CPU_SETSIZE; j++) { - if (CPU_ISSET(j, &cpuset)) { - char temp[1024]; - sprintf(temp, " CPU_%d ", j); - strcat(cpu_affinity, temp); - } - } - LOG_I(HW, "CPU Affinity of main() function is... %s\n", cpu_affinity); -#endif - - - //openair0_cfg[0].log_level = glog_level; - - /*int eMBMS_active=0; - if (node_function[0] <= NGFI_RAU_IF4p5) { // don't initialize L2 for RRU - LOG_I(PHY,"Intializing L2\n"); - mac_xface = malloc(sizeof(MAC_xface)); - l2_init(frame_parms[0],eMBMS_active,(uecap_xer_in==1)?uecap_xer:NULL, - 0,// cba_group_active - 0); // HO flag - mac_xface->macphy_exit = &exit_fun; - } else if (node_function[0] == NGFI_RRU_IF4p5) { // Initialize PRACH in this case - - }*/ - - - -#if defined(ENABLE_ITTI) - - // don't create if node doesn't connect to RRC/S1/GTP - /*if (create_tasks(1) < 0) { - printf("cannot create ITTI tasks\n"); - exit(-1); // need a softer mode - }*/ - - printf("ITTI tasks created\n"); -#endif - - /*if (phy_test==0) { - if (UE_flag==1) { - printf("Filling UE band info\n"); - fill_ue_band_info(); - mac_xface->dl_phy_sync_success (0, 0, 0, 1); - } else if (node_function[0]>NGFI_RRU_IF4p5) - mac_xface->mrbch_phy_sync_failure (0, 0, 0); - }*/ - - // init UE_PF_PO and mutex lock - pthread_mutex_init(&ue_pf_po_mutex, NULL); - memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); - - - mlockall(MCL_CURRENT | MCL_FUTURE); - - pthread_cond_init(&sync_cond,NULL); - pthread_mutex_init(&sync_mutex, NULL); - - init_UE(1); - -#ifdef XFORMS - int UE_id; - int fl_argc=1; - - if (do_forms==1) { - // fl_initialize messes with argv and argc, so pretend to not pass any options - fl_initialize (&fl_argc, argv, NULL, 0, 0); - // restore the original command line args - // argv = fl_get_cmdline_args( &argc ); - //form_stats = create_form_stats_form(); - //fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); - UE_id = 0; - form_ue[UE_id] = create_lte_phy_scope_ue(); - sprintf (title, "NR DL SCOPE UE"); - fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); - - /* - if (openair_daq_vars.use_ia_receiver) { - fl_set_button(form_ue[UE_id]->button_0,1); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON"); - } else { - fl_set_button(form_ue[UE_id]->button_0,0); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); - }*/ - fl_set_button(form_ue[UE_id]->button_0,0); - fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); - - - ret = pthread_create(&forms_thread, NULL, scope_thread, NULL); - - if (ret == 0) - pthread_setname_np( forms_thread, "xforms" ); - - printf("Scope thread created, ret=%d\n",ret); - } - -#endif - - rt_sleep_ns(10*100000000ULL); - - number_of_cards = 1; - - for(CC_id=0; CC_idrf_map.card=0; - PHY_vars_UE_g[0][CC_id]->rf_map.chain=CC_id+chain_offset; - } - - - for (CC_id=0; CC_idhw_timing_advance = timing_advance; -#else - UE[CC_id]->hw_timing_advance = 160; -#endif - } - - - if (input_fd) { - printf("Reading in from file to antenna buffer %d\n",0); - if (fread(UE[0]->common_vars.rxdata[0], - sizeof(int32_t), - frame_parms[0]->samples_per_subframe*10, - input_fd) != frame_parms[0]->samples_per_subframe*10) - printf("error reading from file\n"); - } - - sleep(3); - - - printf("Sending sync to all threads\n"); - - pthread_mutex_lock(&sync_mutex); - sync_var=0; - pthread_cond_broadcast(&sync_cond); - pthread_mutex_unlock(&sync_mutex); - - // wait for end of program - printf("TYPE TO TERMINATE\n"); - //getchar(); - - /* -#if defined(ENABLE_ITTI) - printf("Entering ITTI signals handler\n"); - itti_wait_tasks_end(); - oai_exit=1; -#else - */ - - while (oai_exit==0) - rt_sleep_ns(100000000ULL); - - //#endif - - // stop threads -#ifdef XFORMS - printf("waiting for XFORMS thread\n"); - - if (do_forms==1) { - pthread_join(forms_thread,&status); - //fl_hide_form(form_stats->stats_form); - //fl_free_form(form_stats->stats_form); - fl_hide_form(form_ue[0]->lte_phy_scope_ue); - fl_free_form(form_ue[0]->lte_phy_scope_ue); - } - -#endif - - printf("stopping MODEM threads\n"); - - pthread_cond_destroy(&sync_cond); - pthread_mutex_destroy(&sync_mutex); - - - // *** Handle per CC_id openair0 - if (PHY_vars_UE_g[0][0]->rfdevice.trx_end_func) - PHY_vars_UE_g[0][0]->rfdevice.trx_end_func(&PHY_vars_UE_g[0][0]->rfdevice); - - //if (ouput_vcd) - //VCD_SIGNAL_DUMPER_CLOSE(); - - if (opt_enabled == 1) - terminate_opt(); - - logClean(); - - return 0; -} diff --git a/targets/RT/USER/nr-uesoftmodem.h b/targets/RT/USER/nr-uesoftmodem.h deleted file mode 100644 index 7f96480b2b..0000000000 --- a/targets/RT/USER/nr-uesoftmodem.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef NR_UESOFTMODEM_H -#define NR_UESOFTMODEM_H - -#define _GNU_SOURCE -#include -#include -#include -#include -#include "rt_wrapper.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "rt_wrapper.h" -#include "../../ARCH/COMMON/common_lib.h" -#undef MALLOC -#include "assertions.h" -#include "msc.h" -#include "PHY/types.h" -#include "PHY/defs_nr_UE.h" -#include "SIMULATION/ETH_TRANSPORT/proto.h" - -#if defined(ENABLE_ITTI) -#if defined(ENABLE_USE_MME) -#include "s1ap_eNB.h" -#ifdef PDCP_USE_NETLINK -#include "SIMULATION/ETH_TRANSPORT/proto.h" -#endif -#endif -#endif - -/* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ -#define CONFIG_HLP_RFCFGF "Configuration file for front-end (e.g. LMS7002M)\n" -#define CONFIG_HLP_ULMAXE "set the eNodeB max ULSCH erros\n" -#define CONFIG_HLP_CALUER "set UE RX calibration\n" -#define CONFIG_HLP_CALUERM "" -#define CONFIG_HLP_CALUERB "" -#define CONFIG_HLP_DBGUEPR "UE run normal prach power ramping, but don't continue random-access\n" -#define CONFIG_HLP_CALPRACH "UE run normal prach with maximum power, but don't continue random-access\n" -#define CONFIG_HLP_NOL2CN "bypass L2 and upper layers\n" -#define CONFIG_HLP_UERXG "set UE RX gain\n" -#define CONFIG_HLP_UERXGOFF "external UE amplifier offset\n" -#define CONFIG_HLP_UETXG "set UE TX gain\n" -#define CONFIG_HLP_UENANTR "set UE number of rx antennas\n" -#define CONFIG_HLP_UENANTT "set UE number of tx antennas\n" -#define CONFIG_HLP_UESCAN "set UE to scan around carrier\n" -#define CONFIG_HLP_UEFO "set UE to enable estimation and compensation of frequency offset\n" -#define CONFIG_HLP_DUMPFRAME "dump UE received frame to rxsig_frame0.dat and exit\n" -#define CONFIG_HLP_DLSHIFT "dynamic shift for LLR compuation for TM3/4 (default 0)\n" -#define CONFIG_HLP_UELOOP "get softmodem (UE) to loop through memory instead of acquiring from HW\n" -#define CONFIG_HLP_PHYTST "test UE phy layer, mac disabled\n" -#define CONFIG_HLP_DMAMAP "sets flag for improved EXMIMO UE performance\n" -#define CONFIG_HLP_EXCCLK "tells hardware to use an external clock reference\n" -#define CONFIG_HLP_USIM "use XOR autentication algo in case of test usim mode\n" -#define CONFIG_HLP_NOSNGLT "Disables single-thread mode in lte-softmodem\n" -#define CONFIG_HLP_TADV "Set timing_advance\n" -#define CONFIG_HLP_DLF "Set the downlink frequency for all component carriers\n" -#define CONFIG_HLP_CHOFF "Channel id offset\n" -#define CONFIG_HLP_SOFTS "Enable soft scope and L1 and L2 stats (Xforms)\n" -#define CONFIG_HLP_EXMCAL "Calibrate the EXMIMO borad, available files: exmimo2_2arxg.lime exmimo2_2brxg.lime \n" -#define CONFIG_HLP_ITTIL "Generate ITTI analyzser logs (similar to wireshark logs but with more details)\n" -#define CONFIG_HLP_DLMCS "Set the maximum downlink MCS\n" -#define CONFIG_HLP_STMON "Enable processing timing measurement of lte softmodem on per subframe basis \n" -#define CONFIG_HLP_PRB "Set the PRB, valid values: 6, 25, 50, 100 \n" -#define CONFIG_HLP_MSLOTS "Skip the missed slots/subframes \n" -#define CONFIG_HLP_ULMCS "Set the maximum uplink MCS\n" -#define CONFIG_HLP_TDD "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n" -#define CONFIG_HLP_UE "Set the lte softmodem as a UE\n" -#define CONFIG_HLP_L2MONW "Enable L2 wireshark messages on localhost \n" -#define CONFIG_HLP_L2MONP "Enable L2 pcap messages on localhost \n" -#define CONFIG_HLP_VCD "Enable VCD (generated file will is named openair_dump_eNB.vcd, read it with target/RT/USER/eNB.gtkw\n" -#define CONFIG_HLP_TQFS "Apply three-quarter of sampling frequency, 23.04 Msps to reduce the data rate on USB/PCIe transfers (only valid for 20 MHz)\n" -#define CONFIG_HLP_TPORT "tracer port\n" -#define CONFIG_HLP_NOTWAIT "don't wait for tracer, start immediately\n" -#define CONFIG_HLP_TNOFORK "to ease debugging with gdb\n" - -#define CONFIG_HLP_NUMEROLOGY "adding numerology for 5G\n" -#define CONFIG_HLP_EMULATE_RF "Emulated RF enabled(disable by defult)\n" -#define CONFIG_HLP_PARALLEL_CMD "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n" -#define CONFIG_HLP_WORKER_CMD "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n" - -#define CONFIG_HLP_DISABLNBIOT "disable nb-iot, even if defined in config\n" - -#define CONFIG_HLP_USRP_ARGS "set the arguments to identify USRP (same syntax as in UHD)\n" -#define CONFIG_HLP_USRP_CLK_SRC "USRP clock source: 'internal' or 'external'\n" - -/***************************************************************************************************************************************/ -/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument - when calling config_get or config_getlist functions */ - - -/*------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters defining UE running mode */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_UEMODEPARAMS_DESC { \ -{"calib-ue-rx", CONFIG_HLP_CALUER, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"calib-ue-rx-med", CONFIG_HLP_CALUERM, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"calib-ue-rx-byp", CONFIG_HLP_CALUERB, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ -{"debug-ue-prach", CONFIG_HLP_DBGUEPR, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"no-L2-connect", CONFIG_HLP_NOL2CN, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"calib-prach-tx", CONFIG_HLP_CALPRACH, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ -{"loop-memory", CONFIG_HLP_UELOOP, 0, strptr:&loopfile, defstrval:"iqs.in", TYPE_STRING,0}, \ -{"ue-dump-frame", CONFIG_HLP_DUMPFRAME, PARAMFLAG_BOOL, iptr:&dumpframe, defintval:0, TYPE_INT, 0}, \ -} -#define CMDLINE_CALIBUERX_IDX 0 -#define CMDLINE_CALIBUERXMED_IDX 1 -#define CMDLINE_CALIBUERXBYP_IDX 2 -#define CMDLINE_DEBUGUEPRACH_IDX 3 -#define CMDLINE_NOL2CONNECT_IDX 4 -#define CMDLINE_CALIBPRACHTX_IDX 5 -#define CMDLINE_MEMLOOP_IDX 6 -#define CMDLINE_DUMPMEMORY_IDX 7 -/*------------------------------------------------------------------------------------------------------------------------------------------*/ - - -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters specific to UE */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_UEPARAMS_DESC { \ -{"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ -{"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ -{"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ -{"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ -{"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ -{"ue-fo-compensation", CONFIG_HLP_UEFO, PARAMFLAG_BOOL, iptr:&UE_fo_compensation, defintval:0, TYPE_INT, 0}, \ -{"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:90, TYPE_INT, 0}, \ -{"r" , CONFIG_HLP_PRB, 0, iptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT, 0}, \ -{"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"usrp-args", CONFIG_HLP_USRP_ARGS, 0, strptr:(char **)&usrp_args, defstrval:"type=b200", TYPE_STRING, 0}, \ -{"usrp-clksrc", CONFIG_HLP_USRP_CLK_SRC,0, strptr:(char **)&usrp_clksrc, defstrval:"internal", TYPE_STRING, 0} \ -} - -#define DEFAULT_DLF 2680000000 - -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters common to eNodeB and UE */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_PARAMS_DESC { \ -{"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&rf_config_file, defstrval:NULL, TYPE_STRING, sizeof(rf_config_file)}, \ -{"ulsch-max-errors", CONFIG_HLP_ULMAXE, 0, uptr:&ULSCH_max_consecutive_errors, defuintval:0, TYPE_UINT, 0}, \ -{"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&phy_test, defintval:0, TYPE_INT, 0}, \ -{"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&usim_test, defintval:0, TYPE_UINT8, 0}, \ -{"mmapped-dma", CONFIG_HLP_DMAMAP, PARAMFLAG_BOOL, uptr:&mmapped_dma, defintval:0, TYPE_INT, 0}, \ -{"external-clock", CONFIG_HLP_EXCCLK, PARAMFLAG_BOOL, uptr:&clock_source, defintval:0, TYPE_INT, 0}, \ -{"wait-for-sync", NULL, PARAMFLAG_BOOL, iptr:&wait_for_sync, defintval:0, TYPE_INT, 0}, \ -{"single-thread-disable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&single_thread_flag, defintval:1, TYPE_INT, 0}, \ -{"threadoffset", NULL, 0, iptr:&(threads_offset), defintval:0, TYPE_INT, 0}, \ -{"threadMain", NULL, 0, iptr:&(threads.main), defintval:-1, TYPE_INT, 0}, \ -{"threadSync", NULL, 0, iptr:&(threads.sync), defintval:-1, TYPE_INT, 0}, \ -{"threadOneSubframe", NULL, 0, iptr:&(threads.one), defintval:-1, TYPE_INT, 0}, \ -{"threadTwoSubframe", NULL, 0, iptr:&(threads.two), defintval:-1, TYPE_INT, 0}, \ -{"threadThreeSubframe", NULL, 0, iptr:&(threads.three), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcOne", NULL, 0, iptr:&(threads.slot1_proc_one), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcTwo", NULL, 0, iptr:&(threads.slot1_proc_two), defintval:-1, TYPE_INT, 0}, \ -{"threadSlot1ProcThree", NULL, 0, iptr:&(threads.slot1_proc_three), defintval:-1, TYPE_INT, 0}, \ -{"nr-dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&nr_dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ -{"A" , CONFIG_HLP_TADV, 0, uptr:&timing_advance, defintval:0, TYPE_UINT, 0}, \ -{"C" , CONFIG_HLP_DLF, 0, uptr:&(downlink_frequency[0][0]), defuintval:2680000000, TYPE_UINT, 0}, \ -{"a" , CONFIG_HLP_CHOFF, 0, iptr:&chain_offset, defintval:0, TYPE_INT, 0}, \ -{"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, iptr:&do_forms, defintval:0, TYPE_INT, 0}, \ -{"E" , CONFIG_HLP_TQFS, PARAMFLAG_BOOL, iptr:&threequarter_fs, defintval:0, TYPE_INT, 0}, \ -{"K" , CONFIG_HLP_ITTIL, PARAMFLAG_NOFREE, strptr:&itti_dump_file, defstrval:"/tmp/itti.dump", TYPE_STRING, 0}, \ -{"m" , CONFIG_HLP_DLMCS, 0, uptr:&target_dl_mcs, defintval:0, TYPE_UINT, 0}, \ -{"t" , CONFIG_HLP_ULMCS, 0, uptr:&target_ul_mcs, defintval:0, TYPE_UINT, 0}, \ -{"W" , CONFIG_HLP_L2MONW, 0, strptr:(char **)&in_ip, defstrval:"127.0.0.1", TYPE_STRING, sizeof(in_ip)}, \ -{"P" , CONFIG_HLP_L2MONP, 0, strptr:(char **)&in_path, defstrval:"/tmp/oai_opt.pcap", TYPE_STRING, sizeof(in_path)}, \ -{"q" , CONFIG_HLP_STMON, PARAMFLAG_BOOL, iptr:&opp_enabled, defintval:0, TYPE_INT, 0}, \ -{"S" , CONFIG_HLP_MSLOTS, PARAMFLAG_BOOL, u8ptr:&exit_missed_slots, defintval:1, TYPE_UINT8, 0}, \ -{"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, \ -{"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&numerology, defintval:0, TYPE_INT, 0}, \ -{"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&emulate_rf, defintval:0, TYPE_INT, 0}, \ -{"parallel-config", CONFIG_HLP_PARALLEL_CMD,0, strptr:(char **)¶llel_config, defstrval:NULL, TYPE_STRING, 0}, \ -{"worker-config", CONFIG_HLP_WORKER_CMD, 0, strptr:(char **)&worker_config, defstrval:NULL, TYPE_STRING, 0}, \ -{"nbiot-disable", CONFIG_HLP_DISABLNBIOT, PARAMFLAG_BOOL, iptr:&nonbiotflag, defintval:0, TYPE_INT, 0} \ -} - -#define CONFIG_HLP_FLOG "Enable online log \n" -#define CONFIG_HLP_LOGL "Set the global log level, valide options: (9:trace, 8/7:debug, 6:info, 4:warn, 3:error)\n" -#define CONFIG_HLP_LOGV "Set the global log verbosity \n" -#define CONFIG_HLP_TELN "Start embedded telnet server \n" -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -/* command line parameters for LOG utility */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ -/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define CMDLINE_LOGPARAMS_DESC { \ -{"R" , CONFIG_HLP_FLOG, 0, uptr:&online_log_messages, defintval:1, TYPE_INT, 0}, \ -{"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ -{"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \ -{"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ -} -#define CMDLINE_ONLINELOG_IDX 0 -#define CMDLINE_GLOGLEVEL_IDX 1 -#define CMDLINE_GLOGVERBO_IDX 2 -#define CMDLINE_STARTTELN_IDX 3 - - -extern int T_port; -extern int T_nowait; -extern int T_dont_fork; - - - -/***************************************************************************************************************************************/ - -extern pthread_cond_t sync_cond; -extern pthread_mutex_t sync_mutex; -extern int sync_var; - - -extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; -extern int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; - -extern int rx_input_level_dBm; -extern uint8_t exit_missed_slots; -extern uint64_t num_missed_slots; // counter for the number of missed slots - -extern int oaisim_flag; -extern volatile int oai_exit; - -extern openair0_config_t openair0_cfg[MAX_CARDS]; -extern pthread_cond_t sync_cond; -extern pthread_mutex_t sync_mutex; -extern int sync_var; -extern int transmission_mode; -extern double cpuf; - -#if defined(ENABLE_ITTI) -extern volatile int start_eNB; -extern volatile int start_UE; -#endif - -#include "threads_t.h" -extern threads_t threads; - -// In nr-ue.c -extern int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg); -extern void fill_ue_band_info(void); -extern void init_UE(int); -extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char * name); -extern void reset_opp_meas(void); -extern void print_opp_meas(void); - -#endif From 645514e1c49fba1f86c32bf6eaab88fbde455510 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Thu, 4 Apr 2019 22:55:05 +0200 Subject: [PATCH 079/117] fixing pbchsim --- openair1/SIMULATION/NR_PHY/pbchsim.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index e4ff2f48d7..a2da438b64 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -616,8 +616,7 @@ int main(int argc, char **argv) i, 0, 0, - 0, - NR_PBCH_EST); + 0); nr_pbch_channel_estimation(UE,0,0,i,i-(UE->symbol_offset+1),ssb_index%8,n_hf); } From e85cd9b79f041484bcfddbb4aed93ecbf7b252b1 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 5 Apr 2019 00:55:05 +0200 Subject: [PATCH 080/117] gNB was not taking into account rnti for PDSCH. This code has to be revised once we start using dataScrambilngIdendityPDSCH --- openair1/PHY/INIT/nr_init_ue.c | 2 +- openair1/PHY/NR_TRANSPORT/nr_dlsch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index 87490b817c..2258ff41cc 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -831,7 +831,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue, (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_estimates_time[idx] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 ); // size_t num = 7*2*fp->N_RB_DL*12; - size_t num = 4*100*12; // 4 symbols, 100 PRBs, 12 REs per PRB + size_t num = 4*273*12; // 4 symbols, 100 PRBs, 12 REs per PRB (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_comp[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->dl_ch_rho_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); (*pdcch_vars_th)[th_id][eNB_id]->rxdataF_ext[idx] = (int32_t*)malloc16_clear( sizeof(int32_t) * num ); diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c index a881ae539e..48cd97809a 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c @@ -233,7 +233,7 @@ printf("\n"); for (int q=0; qnb_codewords; q++) memset((void*)scrambled_output[q], 0, (encoded_length>>5)*sizeof(uint32_t)); uint16_t n_RNTI = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? \ - ((pdcch_params.scrambling_id)?pdcch_params.rnti:0) : 0; + ((pdcch_params.scrambling_id==0)?pdcch_params.rnti:0) : 0; uint16_t Nid = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? \ pdcch_params.scrambling_id : config.sch_config.physical_cell_id.value; for (int q=0; qnb_codewords; q++) From 71fc1b689008e51523421fafa4e32f0fc11d092a Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Sat, 6 Apr 2019 18:37:00 +0200 Subject: [PATCH 081/117] makeing pdsch parameters dependent on DCI --- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 49 ++++++++---------- openair2/LAYER2/NR_MAC_UE/mac_vars.c | 5 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 54 ++++++++++---------- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index d3f22dea54..4f85e0fd66 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -3596,22 +3596,26 @@ void copy_harq_proc_struct(NR_DL_UE_HARQ_t *harq_processes_dest, NR_DL_UE_HARQ_t memcpy(harq_ack_dest, current_harq_ack, sizeof(nr_harq_status_t)); }*/ -void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, PDSCH_t pdsch, NR_UE_DLSCH_t *dlsch0, NR_UE_DLSCH_t *dlsch1, int s0, int s1) { +void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB_id, PDSCH_t pdsch, NR_UE_DLSCH_t *dlsch0, NR_UE_DLSCH_t *dlsch1) { int nr_tti_rx = proc->nr_tti_rx; int m; - int harq_pid; int i_mod,eNB_id_i,dual_stream_UE; int first_symbol_flag=0; - uint16_t pdsch_start_rb = 0; - uint16_t pdsch_nb_rb = 50; if (dlsch0->active == 0) return; - for (m=s0;m<=s1;m++) { + if (dlsch0 && (!dlsch1)) { + int harq_pid = dlsch0->current_harq_pid; + uint16_t pdsch_start_rb = dlsch0->harq_processes[harq_pid]->start_rb; + uint16_t pdsch_nb_rb = dlsch0->harq_processes[harq_pid]->nb_rb; + uint16_t s0 = dlsch0->harq_processes[harq_pid]->start_symbol; + uint16_t s1 = dlsch0->harq_processes[harq_pid]->nb_symbols; - if (dlsch0 && (!dlsch1)) { + LOG_D(PHY,"[UE %d] PDSCH type %d active in nr_tti_rx %d, harq_pid %d, rb_start %d, nb_rb %d, symbol_start %d, nb_symbols %d\n",ue->Mod_id,pdsch,nr_tti_rx,harq_pid,pdsch_start_rb,pdsch_nb_rb,s0,s1); + + for (m=s0;m<=s1;m++) { if (m==s0) nr_pdsch_channel_estimation(ue, @@ -3622,8 +3626,6 @@ void nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int eNB ue->frame_parms.first_carrier_offset+pdsch_start_rb*12, pdsch_nb_rb); - harq_pid = dlsch0->current_harq_pid; - LOG_D(PHY,"[UE %d] PDSCH type %d active in nr_tti_rx %d, harq_pid %d Symbol %d\n",ue->Mod_id,pdsch,nr_tti_rx,harq_pid,m); dual_stream_UE = 0; eNB_id_i = eNB_id+1; @@ -4440,9 +4442,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, PDSCH, ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0], - NULL, - nb_symb_pdcch, //ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - (nb_symb_sch+nb_symb_pdcch-1)); //ue->frame_parms.symbols_per_tti>>1, + NULL); /* write_output("rxF.m","rxF",&ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF[0][0],ue->frame_parms.ofdm_symbol_size*14,1,1); @@ -4464,9 +4464,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, SI_PDSCH, ue->dlsch_SI[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_SI, VCD_FUNCTION_OUT); } @@ -4478,9 +4477,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, P_PDSCH, ue->dlsch_p[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_P, VCD_FUNCTION_OUT); } @@ -4492,9 +4490,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN eNB_id, RA_PDSCH, ue->dlsch_ra[eNB_id], - NULL, - ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->num_pdcch_symbols, - ue->frame_parms.symbols_per_tti>>1); + NULL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC_RA, VCD_FUNCTION_OUT); } @@ -4592,9 +4589,7 @@ start_meas(&ue->generic_stat); eNB_id, SI_PDSCH, ue->dlsch_SI[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, proc, @@ -4615,9 +4610,7 @@ start_meas(&ue->generic_stat); eNB_id, P_PDSCH, ue->dlsch_p[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, @@ -4638,9 +4631,7 @@ start_meas(&ue->generic_stat); eNB_id, RA_PDSCH, ue->dlsch_ra[eNB_id], - NULL, - 1+(ue->frame_parms.symbols_per_tti>>1), - ue->frame_parms.symbols_per_tti-1); + NULL); /*ue_dlsch_procedures(ue, proc, diff --git a/openair2/LAYER2/NR_MAC_UE/mac_vars.c b/openair2/LAYER2/NR_MAC_UE/mac_vars.c index b2b1fa0ed1..95dea61a45 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_vars.c +++ b/openair2/LAYER2/NR_MAC_UE/mac_vars.c @@ -90,7 +90,7 @@ const float table_38213_13_12_c3[16] = { 1, 0.5f, 1, 0.5f, 1, 0.5f, 0.5f, 0.5f const int32_t table_38213_10_1_1_c2[5] = { 0, 0, 4, 2, 1 }; - +/* #define mu_pusch 1 // definition table j Table 6.1.2.1.1-4 #define j ((mu_pusch==3)?3:(mu_pusch==2)?2:1) @@ -131,4 +131,5 @@ const int32_t table_38213_10_1_1_c2[5] = { 0, 0, 4, 2, 1 }; {0,2,4}, // row index 14 {0,4,7}, // row index 15 {0,8,4} // row index 16 - }; \ No newline at end of file + }; +*/ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index b729a7beb8..bdd83aaf0b 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -235,12 +235,12 @@ int8_t nr_ue_decode_mib( #ifdef DEBUG_MIB printf("system frame number(6 MSB bits): %d\n", mac->mib->systemFrameNumber.buf[0]); printf("system frame number(with LSB): %d\n", (int)frame); - printf("subcarrier spacing: %d\n", (int)mac->mib->subCarrierSpacingCommon); + printf("subcarrier spacing (0=15or60, 1=30or120): %d\n", (int)mac->mib->subCarrierSpacingCommon); printf("ssb carrier offset(with MSB): %d\n", (int)ssb_subcarrier_offset); - printf("dmrs type A position: %d\n", (int)mac->mib->dmrs_TypeA_Position); + printf("dmrs type A position (0=pos2,1=pos3): %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 frequency reselection: %d\n", (int)mac->mib->intraFreqReselection); + printf("cell barred (0=barred,1=notBarred): %d\n", (int)mac->mib->cellBarred); + printf("intra frequency reselection (0=allowed,1=notAllowed): %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 @@ -1122,19 +1122,19 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( fapi_nr_ul_config_pusch_pdu_rel15_t *ulsch_config_pdu, fapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_config_pdu, uint8_t time_domain_ind, - long dmrs_typeA_pos + long dmrs_typeA_pos //0=pos2,1=pos3 ){ uint8_t k_offset=0; uint8_t sliv_S=0; uint8_t sliv_L=0; uint8_t table_5_1_2_1_1_2_time_dom_res_alloc_A[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?12:11}, // row index 1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?10:9}, // row index 2 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?9:8}, // row index 3 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?7:6}, // row index 4 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?5:4}, // row index 5 - {0,(dmrs_typeA_pos == 2)?9:10,(dmrs_typeA_pos == 2)?4:4}, // row index 6 - {0,(dmrs_typeA_pos == 2)?4:6, (dmrs_typeA_pos == 2)?4:4}, // row index 7 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?12:11}, // row index 1 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?10:9}, // row index 2 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?9:8}, // row index 3 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?7:6}, // row index 4 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?5:4}, // row index 5 + {0,(dmrs_typeA_pos == 0)?9:10,(dmrs_typeA_pos == 0)?4:4}, // row index 6 + {0,(dmrs_typeA_pos == 0)?4:6, (dmrs_typeA_pos == 0)?4:4}, // row index 7 {0,5,7}, // row index 8 {0,5,2}, // row index 9 {0,9,2}, // row index 10 @@ -1146,13 +1146,13 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4} // row index 16 }; uint8_t table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?6:5}, // row index 1 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?10:9}, // row index 2 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?9:8}, // row index 3 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?7:6}, // row index 4 - {0,(dmrs_typeA_pos == 2)?2:3, (dmrs_typeA_pos == 2)?5:4}, // row index 5 - {0,(dmrs_typeA_pos == 2)?6:8, (dmrs_typeA_pos == 2)?4:2}, // row index 6 - {0,(dmrs_typeA_pos == 2)?4:6, (dmrs_typeA_pos == 2)?4:4}, // row index 7 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?6:5}, // row index 1 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?10:9}, // row index 2 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?9:8}, // row index 3 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?7:6}, // row index 4 + {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?5:4}, // row index 5 + {0,(dmrs_typeA_pos == 0)?6:8, (dmrs_typeA_pos == 0)?4:2}, // row index 6 + {0,(dmrs_typeA_pos == 0)?4:6, (dmrs_typeA_pos == 0)?4:4}, // row index 7 {0,5,6}, // row index 8 {0,5,2}, // row index 9 {0,9,2}, // row index 10 @@ -1177,7 +1177,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4}, // row index 11 {0,10,4}, // row index 12 {0,2,7}, // row index 13 - {0,(dmrs_typeA_pos == 2)?2:3,(dmrs_typeA_pos == 2)?12:11}, // row index 14 + {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {1,2,4}, // row index 15 {0,0,0} // row index 16 }; @@ -1195,7 +1195,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,8,4}, // row index 11 {0,10,4}, // row index 12 {0,2,7}, // row index 13 - {0,(dmrs_typeA_pos == 2)?2:3,(dmrs_typeA_pos == 2)?12:11}, // row index 14 + {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {0,0,6}, // row index 15 {0,2,6} // row index 16 }; @@ -1243,9 +1243,9 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( * TS 38.214 subclause 5.1.2.1 Resource allocation in time domain (downlink) */ if(dlsch_config_pdu != NULL){ - k_offset = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][0]; - sliv_S = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][1]; - sliv_L = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][2]; + k_offset = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][0]; + sliv_S = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][1]; + sliv_L = table_5_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][2]; // k_offset = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][0]; // sliv_S = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][1]; // sliv_L = table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][2]; @@ -1262,9 +1262,9 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( * TS 38.214 subclause 6.1.2.1 Resource allocation in time domain (uplink) */ if(ulsch_config_pdu != NULL){ - k_offset = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][0]; - sliv_S = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][1]; - sliv_L = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind][2]; + k_offset = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][0]; + sliv_S = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][1]; + sliv_L = table_6_1_2_1_1_2_time_dom_res_alloc_A[time_domain_ind-1][2]; // k_offset = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][0]; // sliv_S = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][1]; // sliv_L = table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[nr_pdci_info_extracted->time_dom_resource_assignment][2]; From bdca3e48326b4a1369bee57399728fe2c253ecf5 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Sun, 7 Apr 2019 08:12:13 +0200 Subject: [PATCH 082/117] moving BWP config to MAC. --- executables/nr-ue.c | 31 ++++++--- executables/nr-uesoftmodem.c | 40 ------------ openair1/PHY/INIT/nr_parms.c | 13 ---- openair1/PHY/defs_nr_common.h | 6 -- openair1/SIMULATION/NR_PHY/dlsim.c | 59 ++++++++++------- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 66 ++++++++++---------- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 16 +++-- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 3 +- 8 files changed, 103 insertions(+), 131 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 402c379687..d52ec1e23b 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -374,7 +374,12 @@ void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { nr_ue_dcireq(&UE->dcireq); //to be replaced with function pointer later NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); UE_mac->scheduled_response.dl_config = &UE->dcireq.dl_config_req; - UE_mac->scheduled_response.slot = proc->nr_tti_rx; + UE_mac->scheduled_response.ul_config = NULL; + UE_mac->scheduled_response.tx_request = NULL; + UE_mac->scheduled_response.module_id = UE->Mod_id; + UE_mac->scheduled_response.CC_id = 0; + UE_mac->scheduled_response.frame = proc->frame_rx; + UE_mac->scheduled_response.slot = proc->nr_tti_rx; nr_ue_scheduled_response(&UE_mac->scheduled_response); //write_output("uerxdata_frame.m", "uerxdata_frame", UE->common_vars.rxdata[0], UE->frame_parms.samples_per_frame, 1, 1); printf("Processing slot %d\n",proc->nr_tti_rx); @@ -706,21 +711,27 @@ void init_UE(int nb_inst) { pthread_attr_setschedparam(&attr, &sched); for (inst=0; inst < nb_inst; inst++) { - // UE->rfdevice.type = NONE_DEV; - //PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; - LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]); - PHY_vars_UE_g[inst][0] = init_nr_ue_vars(NULL,inst,0); PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; AssertFatal((UE->if_inst = nr_ue_if_module_init(inst)) != NULL, "can not initial IF module\n"); nr_l3_init_ue(); nr_l2_init_ue(); - mac_inst = get_mac_inst(0); + mac_inst = get_mac_inst(inst); mac_inst->if_module = UE->if_inst; - UE->if_inst->scheduled_response = nr_ue_scheduled_response; - UE->if_inst->phy_config_request = nr_ue_phy_config_request; + + // Initial bandwidth part configuration -- full carrier bandwidth + mac_inst->initial_bwp_dl.bwp_id = 0; + mac_inst->initial_bwp_dl.location = 0; + mac_inst->initial_bwp_dl.scs = UE->frame_parms.subcarrier_spacing; + mac_inst->initial_bwp_dl.N_RB = UE->frame_parms.N_RB_DL; + mac_inst->initial_bwp_dl.cyclic_prefix = UE->frame_parms.Ncp; + + mac_inst->initial_bwp_ul.bwp_id = 0; + mac_inst->initial_bwp_ul.location = 0; + mac_inst->initial_bwp_ul.scs = UE->frame_parms.subcarrier_spacing; + mac_inst->initial_bwp_ul.N_RB = UE->frame_parms.N_RB_UL; + mac_inst->initial_bwp_ul.cyclic_prefix = UE->frame_parms.Ncp; + LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); - //init_UE_threads(inst); - //UE = PHY_vars_UE_g[inst][0]; AssertFatal(0 == pthread_create(&threads[inst], &attr, UE_thread, diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index e6a97c8f28..24f8d4eb0d 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -196,7 +196,6 @@ int rx_input_level_dBm; //int number_of_cards = 1; static NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]; -static nfapi_nr_config_request_t *config[MAX_NUM_CCs]; int16_t node_synch_ref[MAX_NUM_CCs]; uint32_t target_dl_mcs = 28; //maximum allowed mcs @@ -528,14 +527,6 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { for (CC_id=0; CC_idsubframe_config.numerology_index_mu.value =1; - config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD - config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL - config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; - config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; - config[CC_id]->sch_config.physical_cell_id.value = 0; - frame_parms[CC_id]->eutra_band = 78; frame_parms[CC_id]->frame_type = FDD; frame_parms[CC_id]->tdd_config = 3; @@ -550,24 +541,7 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { frame_parms[CC_id]->nb_antennas_tx = 1; frame_parms[CC_id]->nb_antennas_rx = 1; //frame_parms[CC_id]->nushift = 0; - ///frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; - //frame_parms[CC_id]->phich_config_common.phich_duration = normal; - // UL RS Config - /*frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 1;//n_DMRS1 set to 0 - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; - frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; - frame_parms[CC_id]->pusch_config_common.n_SB = 1; - frame_parms[CC_id]->pusch_config_common.hoppingMode = 0; - frame_parms[CC_id]->pusch_config_common.pusch_HoppingOffset = 0; - frame_parms[CC_id]->pusch_config_common.enable64QAM = 0; - - frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; - frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0;*/ // NR: Init to legacy LTE 20Mhz params frame_parms[CC_id]->numerology_index = 0; frame_parms[CC_id]->ttis_per_subframe = 1; @@ -759,20 +733,6 @@ int main( int argc, char **argv ) { else UE[CC_id]->mac_enabled = 1; - if (UE[CC_id]->mac_enabled == 0) { //set default UL parameters for testing mode - for (int i=0; ipusch_config_dedicated[i] = malloc(sizeof(PUSCH_CONFIG_DEDICATED)); - //UE[CC_id]->scheduling_request_config[i] = malloc(sizeof(SCHEDULING_REQUEST_CONFIG)); - /*UE[CC_id]->pusch_config_dedicated[i].betaOffset_ACK_Index = beta_ACK; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_RI_Index = beta_RI; - UE[CC_id]->pusch_config_dedicated[i].betaOffset_CQI_Index = beta_CQI; - - UE[CC_id]->scheduling_request_config[i].sr_PUCCH_ResourceIndex = 0; - UE[CC_id]->scheduling_request_config[i].sr_ConfigIndex = 7+(0%3); - UE[CC_id]->scheduling_request_config[i].dsr_TransMax = sr_n4;*/ - } - } - UE[CC_id]->UE_scan = UE_scan; UE[CC_id]->UE_scan_carrier = UE_scan_carrier; UE[CC_id]->UE_fo_compensation = UE_fo_compensation; diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c index a828804002..5c38ab3056 100644 --- a/openair1/PHY/INIT/nr_parms.c +++ b/openair1/PHY/INIT/nr_parms.c @@ -245,13 +245,6 @@ int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp, else fp->Lmax = 64; - // Initial bandwidth part configuration -- full carrier bandwidth - fp->initial_bwp_dl.bwp_id = 0; - fp->initial_bwp_dl.scs = fp->subcarrier_spacing; - fp->initial_bwp_dl.location = 0; - fp->initial_bwp_dl.N_RB = fp->N_RB_DL; - fp->initial_bwp_dl.cyclic_prefix = fp->Ncp; - fp->initial_bwp_dl.ofdm_symbol_size = fp->ofdm_symbol_size; return 0; } @@ -293,12 +286,6 @@ void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp) LOG_I(PHY,"fp->samples_per_frame_wCP=%d\n",fp->samples_per_frame_wCP); LOG_I(PHY,"fp->samples_per_subframe=%d\n",fp->samples_per_subframe); LOG_I(PHY,"fp->samples_per_frame=%d\n",fp->samples_per_frame); - LOG_I(PHY,"fp->initial_bwp_dl.bwp_id=%d\n",fp->initial_bwp_dl.bwp_id); - LOG_I(PHY,"fp->initial_bwp_dl.scs=%d\n",fp->initial_bwp_dl.scs); - LOG_I(PHY,"fp->initial_bwp_dl.N_RB=%d\n",fp->initial_bwp_dl.N_RB); - LOG_I(PHY,"fp->initial_bwp_dl.cyclic_prefix=%d\n",fp->initial_bwp_dl.cyclic_prefix); - LOG_I(PHY,"fp->initial_bwp_dl.location=%d\n",fp->initial_bwp_dl.location); - LOG_I(PHY,"fp->initial_bwp_dl.ofdm_symbol_size=%d\n",fp->initial_bwp_dl.ofdm_symbol_size); } diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index a589f555ff..6adb2271e2 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -161,8 +161,6 @@ typedef struct NR_BWP_PARMS { uint8_t location; /// Bandwidth in PRB uint16_t N_RB; - /// Size of FFT/IFFT - uint16_t ofdm_symbol_size; /// Cyclic prefix uint8_t cyclic_prefix; /// RBG params @@ -315,10 +313,6 @@ typedef struct NR_DL_FRAME_PARMS { /// PBCH polar encoder params t_nrPolar_params pbch_polar_params; - //BWP params - NR_BWP_PARMS initial_bwp_dl; - NR_BWP_PARMS initial_bwp_ul; - } NR_DL_FRAME_PARMS; #define KHz (1000UL) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 6916f001c1..3e8ec69cf1 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -614,11 +614,19 @@ int main(int argc, char **argv) carrier.sizeof_MIB = do_MIB_NR(&carrier,0,ssb_SubcarrierOffset,pdcch_ConfigSIB1,30,2); nr_rrc_mac_config_req_ue(0,0,0,carrier.mib.message.choice.mib,NULL,NULL,NULL); - fapi_nr_dl_config_request_t dl_config; + + // Initial bandwidth part configuration -- full carrier bandwidth + UE_mac->initial_bwp_dl.bwp_id = 0; + UE_mac->initial_bwp_dl.location = 0; + UE_mac->initial_bwp_dl.scs = UE->frame_parms.subcarrier_spacing; + UE_mac->initial_bwp_dl.N_RB = UE->frame_parms.N_RB_DL; + UE_mac->initial_bwp_dl.cyclic_prefix = UE->frame_parms.Ncp; + + fapi_nr_dl_config_request_t *dl_config = &UE_mac->dl_config_request; // Type0 PDCCH search space - dl_config.number_pdus = 1; - dl_config.dl_config_list[0].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.rnti = 0x1234; // to be set + dl_config->number_pdus = 1; + dl_config->dl_config_list[0].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.rnti = 0x1234; uint64_t mask = 0x0; uint16_t num_rbs=24; @@ -629,16 +637,16 @@ int main(int argc, char **argv) mask = mask >> 1; mask = mask | 0x100000000000; } - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.frequency_domain_resource = mask; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.rb_offset = rb_offset; // additional parameter other than coreset + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.frequency_domain_resource = mask; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.rb_offset = rb_offset; // additional parameter other than coreset - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.duration = num_symbols; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_mapping_type =CCE_REG_MAPPING_TYPE_NON_INTERLEAVED; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_reg_bundle_size = 0; // L 38.211 7.3.2.2 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_interleaver_size = 0; // R 38.211 7.3.2.2 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_shift_index = cell_id; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.pdcch_dmrs_scrambling_id = cell_id; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.duration = num_symbols; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_mapping_type =CCE_REG_MAPPING_TYPE_NON_INTERLEAVED; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_reg_bundle_size = 0; // L 38.211 7.3.2.2 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_interleaver_size = 0; // R 38.211 7.3.2.2 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.cce_reg_interleaved_shift_index = cell_id; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.precoder_granularity = PRECODER_GRANULARITY_SAME_AS_REG_BUNDLE; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.coreset.pdcch_dmrs_scrambling_id = cell_id; uint32_t number_of_search_space_per_slot=1; uint32_t first_symbol_index=0; @@ -647,15 +655,23 @@ int main(int argc, char **argv) coreset_duration = num_symbols * number_of_search_space_per_slot; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[0] = table_38213_10_1_1_c2[0]; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[1] = table_38213_10_1_1_c2[1]; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[2] = table_38213_10_1_1_c2[2]; // CCE aggregation level = 4 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[3] = table_38213_10_1_1_c2[3]; // CCE aggregation level = 8 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[4] = table_38213_10_1_1_c2[4]; // CCE aggregation level = 16 - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[0] = table_38213_10_1_1_c2[0]; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[1] = table_38213_10_1_1_c2[1]; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[2] = table_38213_10_1_1_c2[2]; // CCE aggregation level = 4 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[3] = table_38213_10_1_1_c2[3]; // CCE aggregation level = 8 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.number_of_candidates[4] = table_38213_10_1_1_c2[4]; // CCE aggregation level = 16 + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; - dl_config.dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = N_RB_DL; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = N_RB_DL; + + UE_mac->scheduled_response.dl_config = dl_config; + UE_mac->scheduled_response.ul_config = NULL; + UE_mac->scheduled_response.tx_request = NULL; + UE_mac->scheduled_response.module_id = 0; + UE_mac->scheduled_response.CC_id = 0; + UE_mac->scheduled_response.frame = frame; + UE_mac->scheduled_response.slot = slot; for (SNR=snr0; SNRscheduled_response.dl_config = &dl_config; nr_ue_scheduled_response(&UE_mac->scheduled_response); printf("Running phy procedures UE RX %d.%d\n",frame,slot); diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 4f69c4db18..f196293ea0 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -57,6 +57,8 @@ #include "fapi_nr_ue_interface.h" #include "NR_IF_Module.h" +#include "PHY/defs_nr_common.h" + #define NB_NR_UE_MAC_INST 1 typedef enum { @@ -64,44 +66,42 @@ typedef enum { SFN_C_MOD_2_EQ_1 } SFN_C_TYPE; + /*!\brief Top level UE MAC structure */ typedef struct { - - //// MAC config - NR_DRX_Config_t *drx_Config; - NR_SchedulingRequestConfig_t *schedulingRequestConfig; - NR_BSR_Config_t *bsr_Config; - NR_TAG_Config_t *tag_Config; - NR_PHR_Config_t *phr_Config; - NR_RNTI_Value_t *cs_RNTI; - NR_MIB_t *mib; - - /// Type0-PDCCH seach space - fapi_nr_dl_config_dci_dl_pdu_rel15_t type0_pdcch_dci_config; - uint32_t type0_pdcch_ss_mux_pattern; - SFN_C_TYPE type0_pdcch_ss_sfn_c; - uint32_t type0_pdcch_ss_n_c; - uint32_t type0_pdcch_consecutive_slots; - - /// Random access parameter - uint16_t ra_rnti; - - - //// FAPI-like interface message - fapi_nr_tx_request_t tx_request; - fapi_nr_ul_config_request_t ul_config_request; - fapi_nr_dl_config_request_t dl_config_request; - - - - /// Interface module instances - nr_ue_if_module_t *if_module; - nr_scheduled_response_t scheduled_response; - nr_phy_config_t phy_config; - + + //// MAC config + NR_DRX_Config_t *drx_Config; + NR_SchedulingRequestConfig_t *schedulingRequestConfig; + NR_BSR_Config_t *bsr_Config; + NR_TAG_Config_t *tag_Config; + NR_PHR_Config_t *phr_Config; + NR_RNTI_Value_t *cs_RNTI; + NR_MIB_t *mib; + + /// Type0-PDCCH seach space + fapi_nr_dl_config_dci_dl_pdu_rel15_t type0_pdcch_dci_config; + uint32_t type0_pdcch_ss_mux_pattern; + SFN_C_TYPE type0_pdcch_ss_sfn_c; + uint32_t type0_pdcch_ss_n_c; + uint32_t type0_pdcch_consecutive_slots; + + /// Random access parameter + uint16_t ra_rnti; + //BWP params + NR_BWP_PARMS initial_bwp_dl; + NR_BWP_PARMS initial_bwp_ul; + //// FAPI-like interface message + fapi_nr_tx_request_t tx_request; + fapi_nr_ul_config_request_t ul_config_request; + fapi_nr_dl_config_request_t dl_config_request; + /// Interface module instances + nr_ue_if_module_t *if_module; + nr_scheduled_response_t scheduled_response; + nr_phy_config_t phy_config; } NR_UE_MAC_INST_t; typedef enum seach_space_mask_e { diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index bdd83aaf0b..2ded389269 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -660,9 +660,10 @@ NR_UE_L2_STATE_t nr_ue_scheduler( dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15 = mac->type0_pdcch_dci_config; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DCI; + /* dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti = 0xaaaa; // to be set dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106; // to be set - /* + printf("nr_ue_scheduler Type0 PDCCH with rnti %x, BWP %d\n", dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti, dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP); @@ -1282,10 +1283,11 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; fapi_nr_ul_config_request_t *ul_config = &mac->ul_config_request; - const uint16_t n_RB_ULBWP = 106; - const uint16_t n_RB_DLBWP = 106; + //const uint16_t n_RB_DLBWP = dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP; //make sure this has been set + const uint16_t n_RB_DLBWP = mac->initial_bwp_dl.N_RB; + const uint16_t n_RB_ULBWP = mac->initial_bwp_ul.N_RB; - printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d\n",dci_format); + printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d (DL BWP %d, UL BWP %d)\n",dci_format,n_RB_DLBWP,n_RB_ULBWP); switch(dci_format){ case format0_0: @@ -1766,7 +1768,8 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa dlsch_config_pdu_1_0->pdsch_to_harq_feedback_time_ind); dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; - + dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; + printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); dl_config->number_pdus = dl_config->number_pdus + 1; @@ -1951,7 +1954,8 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa /* DMRS_SEQ_INI */ //FIXME!!! - + dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; + dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index ccac534f1c..4d1eb89984 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -275,6 +275,7 @@ int nr_ue_if_module_kill(uint32_t module_id) { int nr_ue_dcireq(nr_dcireq_t *dcireq) { fapi_nr_dl_config_request_t *dl_config=&dcireq->dl_config_req; + NR_UE_MAC_INST_t *UE_mac = get_mac_inst(0); // Type0 PDCCH search space dl_config->number_pdus = 1; @@ -316,7 +317,7 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq) { dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.duration = search_space_duration; dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.monitoring_symbols_within_slot = (0x3fff << first_symbol_index) & (0x3fff >> (14-coreset_duration-first_symbol_index)) & 0x3fff; - dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106; + dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = UE_mac->initial_bwp_dl.N_RB; return 0; From 69489f959d232d3cf9b56d77dfbf4e2c6a2c8f14 Mon Sep 17 00:00:00 2001 From: Hongzhi Wang Date: Mon, 8 Apr 2019 10:59:21 +0200 Subject: [PATCH 083/117] bug fix for compilation error --- openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index d4a82fe987..c99d2ea61b 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -293,7 +293,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, start_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #endif nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, @@ -316,7 +316,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, if (rx_type >= rx_IC_single_stream) { if (eNB_id_in_connected_eNB) // we are in TM5 nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id_i], + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, @@ -331,7 +331,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dlsch0_harq->mimo_mode); else nb_rb = nr_dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF, - common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id], + pdsch_vars[eNB_id]->dl_ch_estimates, pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, From 2da6fb8efb8838e0531319b6065ef16d3e4abff7 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 9 Apr 2019 09:02:11 +0200 Subject: [PATCH 084/117] fixing a bug in adjust_sync removing printfs --- executables/nr-ue.c | 15 ++++--- openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c | 2 +- openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 24 +++++------ openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 45 ++++++++++---------- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 8 ++-- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 10ee53667e..19b462d770 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -519,14 +519,17 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) { } // compute TO compensation that should be applied for this frame - if ( UE->rx_offset < 5*UE->frame_parms.samples_per_slot && - UE->rx_offset > 0 ) + if ( UE->rx_offset < UE->frame_parms.samples_per_frame/2 && + UE->rx_offset > 0 ) { + //LOG_I(PHY,"!!!adjusting -1 samples!!!\n"); return -1 ; + } - if ( UE->rx_offset > 5*UE->frame_parms.samples_per_slot && - UE->rx_offset < 10*UE->frame_parms.samples_per_slot ) + if ( UE->rx_offset > UE->frame_parms.samples_per_frame/2 && + UE->rx_offset < UE->frame_parms.samples_per_frame ) { + //LOG_I(PHY,"!!!adjusting +1 samples!!!\n"); return 1; - + } return 0; } @@ -706,7 +709,7 @@ void *UE_thread(void *arg) { if ( decoded_frame_rx != proc->frame_rx && ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) - LOG_E(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", + LOG_D(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", decoded_frame_rx, proc->frame_rx); pushTpool(Tpool, processingMsg[thread_idx]); diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c index 47409d2102..48125a01f8 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c @@ -52,7 +52,7 @@ //#define DEBUG_DCI #define NR_PDCCH_DCI_TOOLS -#define NR_PDCCH_DCI_TOOLS_DEBUG +//#define NR_PDCCH_DCI_TOOLS_DEBUG typedef unsigned __int128 uint128_t; diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 7db71ba916..139d48ffa9 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -123,7 +123,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; dlsch0_harq->harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; dlsch0_harq->harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; - printf(">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq->mcs); + LOG_D(MAC,">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq->mcs); } } }else{ @@ -212,17 +212,17 @@ int8_t nr_ue_phy_config_request(nr_phy_config_t *phy_config){ if(phy_config != NULL){ if(phy_config->config_req.config_mask & FAPI_NR_CONFIG_REQUEST_MASK_PBCH){ - printf("[L1][IF module][PHY CONFIG]\n"); - printf("subcarrier spacing: %d\n", phy_config->config_req.pbch_config.subcarrier_spacing_common); - printf("ssb carrier offset: %d\n", phy_config->config_req.pbch_config.ssb_subcarrier_offset); - 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 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); - printf("-------------------------------\n"); + LOG_I(MAC,"[L1][IF module][PHY CONFIG]\n"); + LOG_I(MAC,"subcarrier spacing: %d\n", phy_config->config_req.pbch_config.subcarrier_spacing_common); + LOG_I(MAC,"ssb carrier offset: %d\n", phy_config->config_req.pbch_config.ssb_subcarrier_offset); + LOG_I(MAC,"dmrs type A position: %d\n", phy_config->config_req.pbch_config.dmrs_type_a_position); + LOG_I(MAC,"pdcch config sib1: %d\n", phy_config->config_req.pbch_config.pdcch_config_sib1); + LOG_I(MAC,"cell barred: %d\n", phy_config->config_req.pbch_config.cell_barred); + LOG_I(MAC,"intra frequency reselection: %d\n", phy_config->config_req.pbch_config.intra_frequency_reselection); + LOG_I(MAC,"system frame number: %d\n", phy_config->config_req.pbch_config.system_frame_number); + LOG_I(MAC,"ssb index: %d\n", phy_config->config_req.pbch_config.ssb_index); + LOG_I(MAC,"half frame bit: %d\n", phy_config->config_req.pbch_config.half_frame_bit); + LOG_I(MAC,"-------------------------------\n"); } diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index b4a06ddb66..c5a569b781 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -35,6 +35,7 @@ #include "RRC/NR_UE/rrc_proto.h" #include "assertions.h" #include "PHY/defs_nr_UE.h" +#include "common/utils/LOG/log.h" #include #include @@ -203,7 +204,7 @@ int8_t nr_ue_decode_mib( void *pduP, uint16_t cell_id ){ - printf("[L2][MAC] decode mib\n"); + LOG_I(MAC,"[L2][MAC] decode mib\n"); NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); @@ -234,16 +235,16 @@ int8_t nr_ue_decode_mib( } #ifdef DEBUG_MIB - printf("system frame number(6 MSB bits): %d\n", mac->mib->systemFrameNumber.buf[0]); - printf("system frame number(with LSB): %d\n", (int)frame); - printf("subcarrier spacing (0=15or60, 1=30or120): %d\n", (int)mac->mib->subCarrierSpacingCommon); - printf("ssb carrier offset(with MSB): %d\n", (int)ssb_subcarrier_offset); - printf("dmrs type A position (0=pos2,1=pos3): %d\n", (int)mac->mib->dmrs_TypeA_Position); - printf("pdcch config sib1: %d\n", (int)mac->mib->pdcch_ConfigSIB1); - printf("cell barred (0=barred,1=notBarred): %d\n", (int)mac->mib->cellBarred); - printf("intra frequency reselection (0=allowed,1=notAllowed): %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); + LOG_I(MAC,"system frame number(6 MSB bits): %d\n", mac->mib->systemFrameNumber.buf[0]); + LOG_I(MAC,"system frame number(with LSB): %d\n", (int)frame); + LOG_I(MAC,"subcarrier spacing (0=15or60, 1=30or120): %d\n", (int)mac->mib->subCarrierSpacingCommon); + LOG_I(MAC,"ssb carrier offset(with MSB): %d\n", (int)ssb_subcarrier_offset); + LOG_I(MAC,"dmrs type A position (0=pos2,1=pos3): %d\n", (int)mac->mib->dmrs_TypeA_Position); + LOG_I(MAC,"pdcch config sib1: %d\n", (int)mac->mib->pdcch_ConfigSIB1); + LOG_I(MAC,"cell barred (0=barred,1=notBarred): %d\n", (int)mac->mib->cellBarred); + LOG_I(MAC,"intra frequency reselection (0=allowed,1=notAllowed): %d\n", (int)mac->mib->intraFreqReselection); + LOG_I(MAC,"half frame bit(extra bits): %d\n", (int)half_frame_bit); + LOG_I(MAC,"ssb index(extra bits): %d\n", (int)ssb_index); #endif subcarrier_spacing_t scs_ssb = scs_30kHz; // default for @@ -272,7 +273,7 @@ int8_t nr_ue_decode_mib( int32_t num_rbs = -1; int32_t num_symbols = -1; int32_t rb_offset = -1; - //printf("<<<<<<<<mib->pdcch_ConfigSIB1,index_4msb,index_4lsb,scs_ssb,scs_pdcch, (scs_ssb << 5)|scs_pdcch); // type0-pdcch coreset @@ -316,7 +317,7 @@ int8_t nr_ue_decode_mib( num_rbs = table_38213_13_4_c2[index_4msb]; num_symbols = table_38213_13_4_c3[index_4msb]; rb_offset = table_38213_13_4_c4[index_4msb]; - printf("<<<<<<<<type0_pdcch_ss_mux_pattern = 1; @@ -403,7 +404,7 @@ int8_t nr_ue_decode_mib( mask = mask >> 1; mask = mask | 0x100000000000; } - //printf(">>>>>>>>mask %x num_rbs %d rb_offset %d\n", mask, num_rbs, rb_offset); + //LOG_I(MAC,">>>>>>>>mask %x num_rbs %d rb_offset %d\n", mask, num_rbs, rb_offset); mac->type0_pdcch_dci_config.coreset.frequency_domain_resource = mask; mac->type0_pdcch_dci_config.coreset.rb_offset = rb_offset; // additional parameter other than coreset @@ -666,7 +667,7 @@ NR_UE_L2_STATE_t nr_ue_scheduler( dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti = 0xaaaa; // to be set dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106; // to be set - printf("nr_ue_scheduler Type0 PDCCH with rnti %x, BWP %d\n", + LOG_I(MAC,"nr_ue_scheduler Type0 PDCCH with rnti %x, BWP %d\n", dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.rnti, dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP); */ @@ -1289,7 +1290,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa const uint16_t n_RB_DLBWP = mac->initial_bwp_dl.N_RB; const uint16_t n_RB_ULBWP = mac->initial_bwp_ul.N_RB; - printf("\n>>> nr_ue_process_dci at MAC layer with dci_format=%d (DL BWP %d, UL BWP %d)\n",dci_format,n_RB_DLBWP,n_RB_ULBWP); + LOG_I(MAC,"nr_ue_process_dci at MAC layer with dci_format=%d (DL BWP %d, UL BWP %d)\n",dci_format,n_RB_DLBWP,n_RB_ULBWP); switch(dci_format){ case format0_0: @@ -1746,18 +1747,18 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa /* PDSCH_TO_HARQ_FEEDBACK_TIME_IND (only if CRC scrambled by C-RNTI or CS-RNTI or new-RNTI)*/ dlsch_config_pdu_1_0->pdsch_to_harq_feedback_time_ind = dci->pdsch_to_harq_feedback_time_ind; - printf("\n>>> (nr_ue_procedures.c) rnti=%d dl_config->number_pdus=%d\n", + LOG_D(MAC,"(nr_ue_procedures.c) rnti=%d dl_config->number_pdus=%d\n", dl_config->dl_config_list[dl_config->number_pdus].dlsch_config_pdu.rnti, dl_config->number_pdus); - printf(">>> (nr_ue_procedures.c) frequency_domain_resource_assignment=%d \t number_rbs=%d \t start_rb=%d\n", + LOG_D(MAC,"(nr_ue_procedures.c) frequency_domain_resource_assignment=%d \t number_rbs=%d \t start_rb=%d\n", dci->freq_dom_resource_assignment_DL, dlsch_config_pdu_1_0->number_rbs, dlsch_config_pdu_1_0->start_rb); - printf(">>> (nr_ue_procedures.c) time_domain_resource_assignment=%d \t number_symbols=%d \t start_symbol=%d\n", + LOG_D(MAC,"(nr_ue_procedures.c) time_domain_resource_assignment=%d \t number_symbols=%d \t start_symbol=%d\n", dci->time_dom_resource_assignment, dlsch_config_pdu_1_0->number_symbols, dlsch_config_pdu_1_0->start_symbol); - printf(">>> (nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%f\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", + LOG_D(MAC,"(nr_ue_procedures.c) vrb_to_prb_mapping=%d \n>>> mcs=%d\n>>> ndi=%d\n>>> rv=%d\n>>> harq_process_nbr=%d\n>>> dai=%d\n>>> scaling_factor_S=%f\n>>> tpc_pucch=%d\n>>> pucch_res_ind=%d\n>>> pdsch_to_harq_feedback_time_ind=%d\n", dlsch_config_pdu_1_0->vrb_to_prb_mapping, dlsch_config_pdu_1_0->mcs, dlsch_config_pdu_1_0->ndi, @@ -1772,7 +1773,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; - printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); + LOG_D(MAC,"(nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); dl_config->number_pdus = dl_config->number_pdus + 1; break; @@ -1959,7 +1960,7 @@ int8_t nr_ue_process_dci(module_id_t module_id, int cc_id, uint8_t gNB_index, fa dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15.N_RB_BWP = n_RB_DLBWP; dl_config->dl_config_list[dl_config->number_pdus].pdu_type = FAPI_NR_DL_CONFIG_TYPE_DLSCH; - printf(">>> (nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); + LOG_D(MAC,"(nr_ue_procedures.c) pdu_type=%d\n\n",dl_config->dl_config_list[dl_config->number_pdus].pdu_type); dl_config->number_pdus = dl_config->number_pdus + 1; diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index a8b3144262..c9f393cf46 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -65,7 +65,7 @@ int handle_bcch_dlsch(module_id_t module_id, int cc_id, unsigned int gNB_index, // L2 Abstraction Layer int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, fapi_nr_dci_pdu_rel15_t *dci, uint16_t rnti, uint32_t dci_type){ - printf("handle_dci: rnti %x,dci_type %d\n",rnti,dci_type); + //printf("handle_dci: rnti %x,dci_type %d\n",rnti,dci_type); return nr_ue_process_dci(module_id, cc_id, gNB_index, dci, rnti, dci_type); } @@ -143,9 +143,9 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ mac->scheduled_response.slot = dl_info->slot; if(dl_info->dci_ind != NULL){ - printf("[L2][IF MODULE][DL INDICATION][DCI_IND]\n"); + LOG_D(MAC,"[L2][IF MODULE][DL INDICATION][DCI_IND]\n"); for(i=0; idci_ind->number_of_dcis; ++i){ - printf(">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis); + LOG_I(MAC,">>>NR_IF_Module i=%d, dl_info->dci_ind->number_of_dcis=%d\n",i,dl_info->dci_ind->number_of_dcis); fapi_nr_dci_pdu_rel15_t *dci = &dl_info->dci_ind->dci_list[i].dci; ret_mask |= (handle_dci( @@ -205,7 +205,7 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info){ } if(dl_info->rx_ind != NULL){ - printf("[L2][IF MODULE][DL INDICATION][RX_IND]\n"); + LOG_I(MAC,"[L2][IF MODULE][DL INDICATION][RX_IND]\n"); for(i=0; irx_ind->number_pdus; ++i){ switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){ case FAPI_NR_RX_PDU_TYPE_MIB: From bc53a9afee60b0c6187d133fb7194f1d875a8c17 Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 9 Apr 2019 10:17:12 +0200 Subject: [PATCH 085/117] fix number of parallel slots processing limit --- cmake_targets/build_oai | 5 ----- executables/nr-ue.c | 17 +++++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 596ff978f1..ba7fdc6cb0 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -422,11 +422,6 @@ function main() { CMAKE_CMD="$CMAKE_CMD .." echo_info "CMAKE_CMD=$CMAKE_CMD" - if [ "$eNB" = "1" -o "$gNB" = "1" ] && [ "$UE" = "1" -o "$nrUE" = "1" ]; then - echo_error "Cannot build UE/nrUE and eNB/gNB on one build_oai execution" - echo_error "use 2 build_oai invocations" - exit - fi ######################################################### # check validity of HW and TP parameters for eNB / gNB diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 19b462d770..03249d7dcc 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -697,13 +697,14 @@ void *UE_thread(void *arg) { decoded_frame_rx=tmp->proc.decoded_frame_rx; } - while (nbSlotProcessing >= RX_NB_TH && (res=tryPullTpool(&nf, Tpool)) != NULL ) { - nbSlotProcessing--; - processingData_t *tmp=(processingData_t *)res->msgData; - - if (tmp->proc.decoded_frame_rx != -1) - decoded_frame_rx=tmp->proc.decoded_frame_rx; - + while (nbSlotProcessing >= RX_NB_TH ) { + if ( (res=tryPullTpool(&nf, Tpool)) != NULL ) { + nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; + } usleep(200); } @@ -711,7 +712,7 @@ void *UE_thread(void *arg) { ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) LOG_D(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", decoded_frame_rx, proc->frame_rx); - + nbSlotProcessing++; pushTpool(Tpool, processingMsg[thread_idx]); } // while !oai_exit From 7b3615de642b3f5f79c442181e9fb9535905b121 Mon Sep 17 00:00:00 2001 From: laurent Date: Wed, 10 Apr 2019 18:23:12 +0200 Subject: [PATCH 086/117] fix bugs --- common/utils/threadPool/Makefile | 4 +-- common/utils/threadPool/thread-pool.c | 3 ++ executables/nr-ue.c | 46 ++++++++++++++------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/common/utils/threadPool/Makefile b/common/utils/threadPool/Makefile index 6f0e884886..af0b44996c 100644 --- a/common/utils/threadPool/Makefile +++ b/common/utils/threadPool/Makefile @@ -1,8 +1,8 @@ all: measurement_display thread-pool-test measurement_display: measurement_display.c thread-pool.h - gcc measurement_display.c -I /data/openairinterface5g.nr/common/utils/ -I. /data/openairinterface5g.nr/common/utils/backtrace.c -lpthread -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o measurement_display + gcc measurement_display.c -I ${OPENAIR_DIR}/ -I ${OPENAIR_DIR}/common/utils/ -I. ${OPENAIR_DIR}/common/utils/backtrace.c -lpthread -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o measurement_display thread-pool-test: thread-pool.c thread-pool.h - gcc -g thread-pool.c -I /data/openairinterface5g.nr/common/utils/ -I. /data/openairinterface5g.nr/common/utils/backtrace.c -lpthread -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o thread-pool-test + gcc -g thread-pool.c -I ${OPENAIR_DIR}/ -I ${OPENAIR_DIR}/common/utils/ -I. ${OPENAIR_DIR}/common/utils/backtrace.c -I ${OPENAIR_DIR}/openair2/COMMON ${OPENAIR_DIR}/common/utils/LOG/log.c ${OPENAIR_DIR}/common/config/config_userapi.c ${OPENAIR_DIR}/common/config/config_load_configmodule.c ${OPENAIR_DIR}/common/config/config_cmdline.c -lpthread -ldl -D TEST_THREAD_POOL -I../LOG -I../../utils/T -o thread-pool-test diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c index 4cc56fc9b8..8eee0c2b8a 100644 --- a/common/utils/threadPool/thread-pool.c +++ b/common/utils/threadPool/thread-pool.c @@ -151,6 +151,9 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { #ifdef TEST_THREAD_POOL +void exit_function(const char *file, const char *function, const int line, const char *s) { +} + struct testData { int id; char txt[30]; diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 03249d7dcc..0f2b413d5d 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -530,6 +530,7 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) { //LOG_I(PHY,"!!!adjusting +1 samples!!!\n"); return 1; } + return 0; } @@ -605,6 +606,10 @@ void *UE_thread(void *arg) { decoded_frame_rx=proc->decoded_frame_rx; // we do ++ first in the regular processing, so it will be 0; absolute_slot=decoded_frame_rx*nb_slot_frame + nb_slot_frame -1; + + while (tryPullTpool(&nf, Tpool) != NULL) { + }; + continue; } @@ -683,28 +688,15 @@ void *UE_thread(void *arg) { UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; notifiedFIFO_elt_t *res; - if (getenv("RFSIMULATOR")) { - // FixMe: Wait previous thread is done, because race conditions seems too bad - // in case of actual RF board, the overlap between threads mitigate the issue - // We must receive one message, that proves the slot processing is done - while ((res=tryPullTpool(&nf, Tpool)) == NULL) - usleep(200); - - nbSlotProcessing--; - processingData_t *tmp=(processingData_t *)res->msgData; - - if (tmp->proc.decoded_frame_rx != -1) - decoded_frame_rx=tmp->proc.decoded_frame_rx; - } - while (nbSlotProcessing >= RX_NB_TH ) { if ( (res=tryPullTpool(&nf, Tpool)) != NULL ) { - nbSlotProcessing--; - processingData_t *tmp=(processingData_t *)res->msgData; - - if (tmp->proc.decoded_frame_rx != -1) - decoded_frame_rx=tmp->proc.decoded_frame_rx; + nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; } + usleep(200); } @@ -712,8 +704,21 @@ void *UE_thread(void *arg) { ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) LOG_D(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", decoded_frame_rx, proc->frame_rx); + nbSlotProcessing++; + processingMsg[thread_idx]->key=slot_nr; pushTpool(Tpool, processingMsg[thread_idx]); + + if (getenv("RFSIMULATOR")) { + // FixMe: Wait previous thread is done, because race conditions seems too bad + // in case of actual RF board, the overlap between threads mitigate the issue + // We must receive one message, that proves the slot processing is done + res=pullTpool(&nf, Tpool); + nbSlotProcessing--; + processingData_t *tmp=(processingData_t *)res->msgData; + if (tmp->proc.decoded_frame_rx != -1) + decoded_frame_rx=tmp->proc.decoded_frame_rx; + } } // while !oai_exit return NULL; @@ -739,20 +744,17 @@ void init_UE(int nb_inst) { nr_l2_init_ue(); mac_inst = get_mac_inst(inst); mac_inst->if_module = UE->if_inst; - // Initial bandwidth part configuration -- full carrier bandwidth mac_inst->initial_bwp_dl.bwp_id = 0; mac_inst->initial_bwp_dl.location = 0; mac_inst->initial_bwp_dl.scs = UE->frame_parms.subcarrier_spacing; mac_inst->initial_bwp_dl.N_RB = UE->frame_parms.N_RB_DL; mac_inst->initial_bwp_dl.cyclic_prefix = UE->frame_parms.Ncp; - mac_inst->initial_bwp_ul.bwp_id = 0; mac_inst->initial_bwp_ul.location = 0; mac_inst->initial_bwp_ul.scs = UE->frame_parms.subcarrier_spacing; mac_inst->initial_bwp_ul.N_RB = UE->frame_parms.N_RB_UL; mac_inst->initial_bwp_ul.cyclic_prefix = UE->frame_parms.Ncp; - LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); AssertFatal(0 == pthread_create(&threads[inst], &attr, From 2e6d9d7d4ad59e20d323a838f1ec310f00513db2 Mon Sep 17 00:00:00 2001 From: laurent Date: Thu, 11 Apr 2019 13:44:08 +0200 Subject: [PATCH 087/117] Remove table of thread_id in the main UE thread --- common/utils/threadPool/thread-pool.h | 50 ++++++----- executables/nr-ue.c | 119 ++++++++++++++------------ 2 files changed, 93 insertions(+), 76 deletions(-) diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h index aa0003fd8a..6f0230568a 100644 --- a/common/utils/threadPool/thread-pool.h +++ b/common/utils/threadPool/thread-pool.h @@ -77,16 +77,18 @@ static inline void delNotifiedFIFO_elt(notifiedFIFO_elt_t *elt) { //LOG_W(UTIL,"delNotifiedFIFO on something not allocated by newNotifiedFIFO\n"); } +static inline void initNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf) { + nf->inF=NULL; + nf->outF=NULL; +} static inline void initNotifiedFIFO(notifiedFIFO_t *nf) { mutexinit(nf->lockF); condinit (nf->notifF); - nf->inF=NULL; - nf->outF=NULL; + initNotifiedFIFO_nothreadSafe(nf); // No delete function: the creator has only to free the memory } -static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) { - mutexlock(nf->lockF); +static inline void pushNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) { msg->next=NULL; if (nf->outF == NULL) @@ -96,22 +98,39 @@ static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) nf->inF->next = msg; nf->inF = msg; +} + +static inline void pushNotifiedFIFO(notifiedFIFO_t *nf, notifiedFIFO_elt_t *msg) { + mutexlock(nf->lockF); + pushNotifiedFIFO_nothreadSafe(nf,msg); condbroadcast(nf->notifF); mutexunlock(nf->lockF); } -static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { - mutexlock(nf->lockF); - - while(nf->outF == NULL) - condwait(nf->notifF, nf->lockF); +static inline notifiedFIFO_elt_t *pullNotifiedFIFO_nothreadSafe(notifiedFIFO_t *nf) { + if (nf->outF == NULL) + return NULL; notifiedFIFO_elt_t *ret=nf->outF; + + if (nf->outF==nf->outF->next) + LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n"); + nf->outF=nf->outF->next; if (nf->outF==NULL) nf->inF=NULL; + return ret; +} + +static inline notifiedFIFO_elt_t *pullNotifiedFIFO(notifiedFIFO_t *nf) { + mutexlock(nf->lockF); + notifiedFIFO_elt_t *ret; + + while((ret=pullNotifiedFIFO_nothreadSafe(nf)) == NULL) + condwait(nf->notifF, nf->lockF); + mutexunlock(nf->lockF); return ret; } @@ -122,18 +141,7 @@ static inline notifiedFIFO_elt_t *pollNotifiedFIFO(notifiedFIFO_t *nf) { if (tmp != 0 ) return NULL; - notifiedFIFO_elt_t *ret=nf->outF; - - if (ret!=NULL) { - if (nf->outF==nf->outF->next) - LOG_E(TMR,"Circular list in thread pool: push several times the same buffer is forbidden\n"); - - nf->outF=nf->outF->next; - } - - if (nf->outF==NULL) - nf->inF=NULL; - + notifiedFIFO_elt_t *ret=pullNotifiedFIFO_nothreadSafe(nf); mutexunlock(nf->lockF); return ret; } diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 0f2b413d5d..cf0db42443 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -156,7 +156,7 @@ PHY_VARS_NR_UE *init_nr_ue_vars(NR_DL_FRAME_PARMS *frame_parms, */ typedef struct syncData_s { - UE_nr_rxtx_proc_t *proc; + UE_nr_rxtx_proc_t proc; PHY_VARS_NR_UE *UE; } syncData_t; @@ -239,7 +239,7 @@ static void UE_synch(void *arg) { case pbch: LOG_I(PHY, "[UE thread Synch] Running Initial Synch (mode %d)\n",UE->mode); - if (nr_initial_sync( syncD->proc, UE, UE->mode ) == 0) { + if (nr_initial_sync( &syncD->proc, UE, UE->mode ) == 0) { 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_slot; LOG_I(PHY,"Got synch: hw_slot_offset %d, carrier off %d Hz, rxgain %d (DL %u, UL %u), UE_scan_carrier %d\n", @@ -548,40 +548,45 @@ void *UE_thread(void *arg) { initNotifiedFIFO(&nf); int nbSlotProcessing=0; int thread_idx=0; - notifiedFIFO_elt_t *processingMsg[RX_NB_TH]; + notifiedFIFO_t freeBlocks; + initNotifiedFIFO_nothreadSafe(&freeBlocks); - for (int i=0; iUE=UE; - } + for (int i=0; iUE=UE; - syncD->proc=&((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc; const int nb_slot_frame = 10*UE->frame_parms.slots_per_subframe; - int absolute_slot, decoded_frame_rx=INT_MAX, trashed_frames=0; + int absolute_slot=0, decoded_frame_rx=INT_MAX, trashed_frames=0; while (!oai_exit) { - if (!syncD->UE->is_synchronized) { - if (syncRunning) { - notifiedFIFO_elt_t *res=tryPullTpool(&nf, Tpool); + if (syncRunning) { + notifiedFIFO_elt_t *res=tryPullTpool(&nf, Tpool); - if (res) { - syncRunning=false; - } else { - trashFrame(UE, ×tamp); - trashed_frames++; - } + if (res) { + syncRunning=false; + syncData_t *tmp=(syncData_t *)NotifiedFifoData(res); + // shift the frame index with all the frames we trashed meanwhile we perform the synch search + decoded_frame_rx=(tmp->proc.decoded_frame_rx+trashed_frames) % MAX_FRAME_NUMBER; + delNotifiedFIFO_elt(res); } else { - readFrame(UE, ×tamp); - pushTpool(Tpool, syncMsg); - trashed_frames=0; - syncRunning=true; + trashFrame(UE, ×tamp); + trashed_frames++; + continue; } + } + AssertFatal( !syncRunning, "At this point synchronisation can't be running\n"); + + if (!UE->is_synchronized) { + readFrame(UE, ×tamp); + notifiedFIFO_elt_t *Msg=newNotifiedFIFO_elt(sizeof(syncData_t),0,&nf,UE_synch); + syncData_t *syncMsg=(syncData_t *)NotifiedFifoData(Msg); + syncMsg->UE=UE; + memset(&syncMsg->proc, 0, sizeof(syncMsg->proc)); + pushTpool(Tpool, Msg); + trashed_frames=0; + syncRunning=true; continue; } @@ -599,33 +604,32 @@ void *UE_thread(void *arg) { UE->frame_parms.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 - // the synch thread proc context is hard linked to regular processing thread context, thread id = 0 - UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[0]))->proc); - // shift the frame index with all the frames we trashed meanwhile we perform the synch search - proc->decoded_frame_rx=(proc->decoded_frame_rx + trashed_frames) % MAX_FRAME_NUMBER; - decoded_frame_rx=proc->decoded_frame_rx; - // we do ++ first in the regular processing, so it will be 0; + decoded_frame_rx++; + // we do ++ first in the regular processing, so it will be beging of frame; absolute_slot=decoded_frame_rx*nb_slot_frame + nb_slot_frame -1; - - while (tryPullTpool(&nf, Tpool) != NULL) { - }; - continue; } absolute_slot++; + // whatever means thread_idx + // Fix me: will be wrong when slot 1 is slow, as slot 2 finishes + // Slot 3 will overlap if RX_NB_TH is 2 + // this is general failure in UE !!! thread_idx = absolute_slot % RX_NB_TH; int slot_nr = absolute_slot % nb_slot_frame; - UE_nr_rxtx_proc_t *proc=&(((processingData_t *)NotifiedFifoData(processingMsg[thread_idx]))->proc); + notifiedFIFO_elt_t *msgToPush; + AssertFatal((msgToPush=pullNotifiedFIFO_nothreadSafe(&freeBlocks)) != NULL,"chained list failure"); + processingData_t *curMsg=(processingData_t *)NotifiedFifoData(msgToPush); + curMsg->UE=UE; // update thread index for received subframe - proc->nr_tti_rx= slot_nr; - UE->current_thread_id[slot_nr] = thread_idx; - proc->subframe_rx=table_sf_slot[slot_nr]; - proc->nr_tti_tx = (absolute_slot + DURATION_RX_TO_TX) % nb_slot_frame; - proc->subframe_tx=proc->nr_tti_rx; - proc->frame_rx = ( absolute_slot/nb_slot_frame ) % MAX_FRAME_NUMBER; - proc->frame_tx = ( (absolute_slot + DURATION_RX_TO_TX) /nb_slot_frame ) % MAX_FRAME_NUMBER; - proc->decoded_frame_rx=-1; + curMsg->proc.nr_tti_rx= slot_nr; + curMsg->UE->current_thread_id[slot_nr] = thread_idx; + curMsg->proc.subframe_rx=table_sf_slot[slot_nr]; + curMsg->proc.nr_tti_tx = (absolute_slot + DURATION_RX_TO_TX) % nb_slot_frame; + curMsg->proc.subframe_tx=curMsg->proc.nr_tti_rx; + curMsg->proc.frame_rx = ( absolute_slot/nb_slot_frame ) % MAX_FRAME_NUMBER; + curMsg->proc.frame_tx = ( (absolute_slot + DURATION_RX_TO_TX) /nb_slot_frame ) % MAX_FRAME_NUMBER; + curMsg->proc.decoded_frame_rx=-1; LOG_D(PHY,"Process slot %d thread Idx %d \n", slot_nr, thread_idx); for (int i=0; iframe_parms.nb_antennas_rx; i++) @@ -634,7 +638,7 @@ void *UE_thread(void *arg) { slot_nr*UE->frame_parms.samples_per_slot]; for (int i=0; iframe_parms.nb_antennas_tx; i++) - txp[i] = (void *)&UE->common_vars.txdata[i][proc->nr_tti_tx*UE->frame_parms.samples_per_slot]; + txp[i] = (void *)&UE->common_vars.txdata[i][curMsg->proc.nr_tti_tx*UE->frame_parms.samples_per_slot]; int readBlockSize, writeBlockSize; @@ -683,31 +687,33 @@ void *UE_thread(void *arg) { LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols); } - proc->timestamp_tx = timestamp+ - (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- - UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; + curMsg->proc.timestamp_tx = timestamp+ + (DURATION_RX_TO_TX*UE->frame_parms.samples_per_slot)- + UE->frame_parms.ofdm_symbol_size-UE->frame_parms.nb_prefix_samples0; notifiedFIFO_elt_t *res; - while (nbSlotProcessing >= RX_NB_TH ) { + while (nbSlotProcessing >= RX_NB_TH) { if ( (res=tryPullTpool(&nf, Tpool)) != NULL ) { nbSlotProcessing--; processingData_t *tmp=(processingData_t *)res->msgData; if (tmp->proc.decoded_frame_rx != -1) decoded_frame_rx=tmp->proc.decoded_frame_rx; + + pushNotifiedFIFO_nothreadSafe(&freeBlocks,res); } usleep(200); } - if ( decoded_frame_rx != proc->frame_rx && - ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != proc->frame_rx ) + if ( decoded_frame_rx != curMsg->proc.frame_rx && + ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != curMsg->proc.frame_rx ) LOG_D(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n", - decoded_frame_rx, proc->frame_rx); + decoded_frame_rx, curMsg->proc.frame_rx ); nbSlotProcessing++; - processingMsg[thread_idx]->key=slot_nr; - pushTpool(Tpool, processingMsg[thread_idx]); + msgToPush->key=slot_nr; + pushTpool(Tpool, msgToPush); if (getenv("RFSIMULATOR")) { // FixMe: Wait previous thread is done, because race conditions seems too bad @@ -716,8 +722,11 @@ void *UE_thread(void *arg) { res=pullTpool(&nf, Tpool); nbSlotProcessing--; processingData_t *tmp=(processingData_t *)res->msgData; + if (tmp->proc.decoded_frame_rx != -1) decoded_frame_rx=tmp->proc.decoded_frame_rx; + + pushNotifiedFIFO_nothreadSafe(&freeBlocks,res); } } // while !oai_exit From 29e058df176bf036a9274a033418aa0115e8a23c Mon Sep 17 00:00:00 2001 From: Hongzhi Wang Date: Thu, 11 Apr 2019 14:45:03 +0200 Subject: [PATCH 088/117] ue pdsch config from fapi removing hardcoded values --- .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 8 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 125 +++++++++--------- .../nr_dlsch_llr_computation.c | 65 ++------- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 22 ++- openair1/PHY/defs_nr_UE.h | 1 + openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 3 + openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 16 ++- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- 8 files changed, 110 insertions(+), 132 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index e56ccd8af7..8b7b9150cf 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -235,10 +235,12 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, uint8_t kc; uint8_t Ilbrm = 0; uint32_t Tbslbrm = 950984; - uint16_t nb_rb = 30; //to update - uint8_t nb_re_dmrs = 6; - uint16_t length_dmrs = 1; + uint16_t nb_rb = 30; double Coderate = 0.0; + nfapi_nr_config_request_t *cfg = &phy_vars_ue->nrUE_config; + uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value; + uint8_t nb_re_dmrs = (dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4; + uint16_t length_dmrs = 1; //cfg->pdsch_config.dmrs_max_length.value; uint32_t i,j; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index c99d2ea61b..e80160ab69 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -114,7 +114,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, unsigned char aatx,aarx; - unsigned short nb_rb = 0, nb_re =0, round; + unsigned short nb_rb = 0, round; int avgs = 0;// rb; NR_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0; @@ -137,9 +137,10 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, //int16_t *pllr_symbol_cw1_deint; uint32_t llr_offset_symbol; //uint16_t bundle_L = 2; - uint8_t l0 =2; + uint8_t l0 =2, pilots=0; uint16_t n_tx=1, n_rx=1; int32_t median[16]; + uint32_t len; switch (type) { case SI_PDSCH: @@ -159,16 +160,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, case PDSCH: pdsch_vars = ue->pdsch_vars[ue->current_thread_id[nr_tti_rx]]; dlsch = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id]; - - - //set active for testing -> to be removed - dlsch[0]->harq_processes[harq_pid]->status = ACTIVE; - dlsch[0]->harq_processes[harq_pid]->Qm = 2; - dlsch[0]->harq_processes[harq_pid]->mcs = 9; - dlsch[0]->harq_processes[harq_pid]->Nl=1; - dlsch[0]->harq_processes[harq_pid]->round=0; - dlsch[0]->harq_processes[harq_pid]->nb_rb = nb_rb_pdsch; - frame_parms->nushift = 0; + + + dlsch[0]->harq_processes[harq_pid]->Qm = nr_get_Qm(dlsch[0]->harq_processes[harq_pid]->mcs, 1);; //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status); LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d, harq status %d.%d \n", @@ -223,6 +217,10 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, printf("[DEMOD] cw for TB0 = %d, cw for TB1 = %d\n", codeword_TB0, codeword_TB1); #endif + start_rb = dlsch0_harq->start_rb; + nb_rb_pdsch = dlsch0_harq->nb_rb; + l0 = dlsch0_harq->start_symbol; + DevAssert(dlsch0_harq); round = dlsch0_harq->round; //printf("round = %d\n", round); @@ -284,9 +282,11 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, printf("Demod dlsch0_harq->pmi_alloc %d\n", dlsch0_harq->pmi_alloc); #endif + pilots = (symbol==l0) ? 1 : 0; + if (frame_parms->nb_antenna_ports_eNB>1 && beamforming_mode==0) { #ifdef DEBUG_DLSCH_MOD - LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]); + LOG_I(PHY,"dlsch: using pmi %x (%p)\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0]); #endif #if UE_TIMING_TRACE @@ -298,8 +298,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id]->pmi_ext, - rballoc, symbol, + pilots, start_rb, nb_rb_pdsch, nr_tti_rx, @@ -307,7 +307,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, frame_parms, dlsch0_harq->mimo_mode); #ifdef DEBUG_DLSCH_MOD - printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc); + printf("dlsch: using pmi %lx, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc)); for (rb=0;rbpmi_ext[rb]); printf("\n"); @@ -321,8 +321,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id_i]->pmi_ext, - rballoc, symbol, + pilots, start_rb, nb_rb_pdsch, nr_tti_rx, @@ -336,8 +336,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id_i]->pmi_ext, - rballoc, symbol, + pilots, start_rb, nb_rb_pdsch, nr_tti_rx, @@ -353,8 +353,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_estimates_ext, dlsch0_harq->pmi_alloc, pdsch_vars[eNB_id]->pmi_ext, - rballoc, symbol, + pilots, start_rb, nb_rb_pdsch, nr_tti_rx, @@ -410,6 +410,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, return(-1); } + len = (symbol==l0)? (nb_rb*6):(nb_rb*12); + #if UE_TIMING_TRACE stop_meas(&ue->generic_stat_bis[ue->current_thread_id[nr_tti_rx]][slot]); #if DISABLE_LOG_X @@ -426,12 +428,12 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, #endif n_tx = frame_parms->nb_antenna_ports_eNB; n_rx = frame_parms->nb_antennas_rx; - nb_re= (symbol==l0)? (nb_rb*6):(nb_rb*12); nr_dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, dlsch, symbol, + pilots, nb_rb); if ((dlsch0_harq->mimo_modenb_antenna_ports_eNB;aatx++) @@ -482,7 +486,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, median, n_tx, n_rx, - 2*nb_re,// subcarriers Re Im + 2*len,// subcarriers Re Im 0); for (aatx = 0; aatx < n_tx; ++aatx) @@ -588,6 +592,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL, frame_parms, symbol, + pilots, first_symbol_flag, dlsch0_harq->Qm, nb_rb, @@ -641,7 +646,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, n_rx, dlsch0_harq->Qm, pdsch_vars[eNB_id]->log2_maxh, - 2*nb_re, // subcarriers Re Im + 2*len, // subcarriers Re Im 0); // we start from the beginning of the vector /* if (symbol == 5) { write_output("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM @@ -656,7 +661,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, n_tx, n_rx, pdsch_vars[eNB_id]->log2_maxh, - 2*nb_re, + 2*len, 0); //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] ); nr_dlsch_dual_stream_correlation_core(&(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), @@ -665,7 +670,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, n_tx, n_rx, pdsch_vars[eNB_id]->log2_maxh, - 2*nb_re, + 2*len, 0); // printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext ); //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh); @@ -705,7 +710,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, NULL, n_tx, n_rx, - 2*nb_re, + 2*len, 0); /* if (symbol == 5) { write_output("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM @@ -778,7 +783,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pllr_symbol_cw0 += llr_offset_symbol; pllr_symbol_cw1 += llr_offset_symbol; - pdsch_vars[eNB_id]->llr_offset[symbol] = nb_re*dlsch0_harq->Qm + llr_offset_symbol; + pdsch_vars[eNB_id]->llr_offset[symbol] = len*dlsch0_harq->Qm + llr_offset_symbol; /*LOG_I(PHY,"compute LLRs [symbol %d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %x @LLR Buff(symb) %x\n", symbol, @@ -803,6 +808,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pllr_symbol_cw0, symbol, + len, first_symbol_flag, nb_rb, beamforming_mode); @@ -813,6 +819,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pllr_symbol_cw1, symbol, + len, first_symbol_flag, nb_rb, beamforming_mode); @@ -824,7 +831,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, rxdataF_comp_ptr, pdsch_vars[eNB_id]->dl_ch_rho2_ext, pdsch_vars[eNB_id]->layer_llr[0], - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); if (rx_type==rx_IC_dual_stream) { @@ -833,7 +840,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], pdsch_vars[eNB_id]->layer_llr[1], - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); } @@ -890,7 +897,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->llr[0], pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr128, beamforming_mode); } else if (codeword_TB0 == -1){ @@ -898,7 +905,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->llr[1], pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr128_2ndstream, beamforming_mode); } @@ -933,7 +940,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, pdsch_vars[eNB_id]->layer_llr[0], - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128); if (rx_type==rx_IC_dual_stream) { @@ -944,7 +951,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], pdsch_vars[eNB_id]->layer_llr[1], - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); } @@ -982,7 +989,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, (int16_t*)pllr_symbol_cw0, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr_offset[symbol], beamforming_mode); } else if (codeword_TB0 == -1){ @@ -991,7 +998,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pllr_symbol_cw1, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr_offset[symbol], beamforming_mode); } @@ -1050,7 +1057,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dl_ch_mag_ptr,//i pdsch_vars[eNB_id]->dl_ch_rho2_ext, (int16_t*)pllr_symbol_layer0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); if (rx_type==rx_IC_dual_stream) { @@ -1061,7 +1068,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->dl_ch_mag0,//i pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], pllr_symbol_layer1, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,nr_tti_rx,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); } @@ -1080,7 +1087,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, nr_dlsch_qpsk_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, pllr_symbol_cw0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, beamforming_mode); } break; @@ -1090,7 +1097,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pdsch_vars[eNB_id]->rxdataF_comp0, pdsch_vars[eNB_id]->llr[0], pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr128, beamforming_mode); } @@ -1102,7 +1109,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, pllr_symbol_cw0, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, + symbol,len,first_symbol_flag,nb_rb, pdsch_vars[eNB_id]->llr_offset[symbol], beamforming_mode); } @@ -1182,6 +1189,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, } void nr_dlsch_deinterleaving(uint8_t symbol, + uint8_t start_symbol, uint16_t L, uint16_t *llr, uint16_t *llr_deint, @@ -1200,7 +1208,7 @@ void nr_dlsch_deinterleaving(uint8_t symbol, printf("N_bundle %d L %d nb_rb_pdsch %d\n",N_bundle, L,nb_rb_pdsch); - if (symbol==2) + if (symbol==start_symbol) nb_re = 6; else nb_re = 12; @@ -1238,6 +1246,7 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, int **rho, NR_DL_FRAME_PARMS *frame_parms, unsigned char symbol, + uint8_t pilots, uint8_t first_symbol_flag, unsigned char mod_order, unsigned short nb_rb, @@ -1248,16 +1257,11 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext, #if defined(__i386) || defined(__x86_64) unsigned short rb; - unsigned char aatx,aarx,pilots=0; + unsigned char aatx,aarx; __m128i *dl_ch128,*dl_ch128_2,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128,*rho128; __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b; QAM_amp128b = _mm_setzero_si128(); - if (symbol == 2){ - pilots=1; - } - - for (aatx=0; aatxnb_antenna_ports_eNB; aatx++) { if (mod_order == 4) { QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10) @@ -1902,19 +1906,19 @@ void nr_dlsch_scale_channel(int **dl_ch_estimates_ext, NR_DL_FRAME_PARMS *frame_parms, NR_UE_DLSCH_t **dlsch_ue, uint8_t symbol, + uint8_t pilots, unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) short rb, ch_amp; - unsigned char aatx,aarx,pilots=0; + unsigned char aatx,aarx; __m128i *dl_ch128, ch_amp128; - if (symbol==2){ + if (pilots==1){ nb_rb = nb_rb>>1; - pilots=1; } // Determine scaling amplitude based the symbol @@ -1962,6 +1966,7 @@ void nr_dlsch_channel_level(int **dl_ch_estimates_ext, NR_DL_FRAME_PARMS *frame_parms, int32_t *avg, uint8_t symbol, + uint32_t len, unsigned short nb_rb) { @@ -1971,14 +1976,9 @@ void nr_dlsch_channel_level(int **dl_ch_estimates_ext, unsigned char aatx,aarx,nre=12; __m128i *dl_ch128, avg128D; - if (symbol==2) //assume start symbol 2 - nre=6; - else - nre=12; - //nb_rb*nre = y * 2^x - int16_t x = factor2(nb_rb*nre); - int16_t y = (nb_rb*nre)>>x; + int16_t x = factor2(len); + int16_t y = (len)>>x; //printf("nb_rb*nre = %d = %d * 2^(%d)\n",nb_rb*nre,y,x); for (aatx=0; aatxnb_antenna_ports_eNB; aatx++) @@ -2477,8 +2477,8 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, int **dl_ch_estimates_ext, unsigned short pmi, unsigned char *pmi_ext, - unsigned int *rb_alloc, //unused in NR unsigned char symbol, + uint8_t pilots, unsigned short start_rb, unsigned short nb_rb_pdsch, unsigned char nr_tti_rx, @@ -2493,9 +2493,8 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, - unsigned char pilots=0,j=0; + unsigned char j=0; - pilots = (symbol==2) ? 1 : 0; //to updated from config!!! k = frame_parms->first_carrier_offset + 12*start_rb; for (aarx=0; aarxnb_antennas_rx; aarx++) { @@ -2578,8 +2577,8 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, int **dl_ch_estimates_ext, unsigned short pmi, unsigned char *pmi_ext, - unsigned int *rb_alloc, unsigned char symbol, + uint8_t pilots, unsigned short start_rb, unsigned short nb_rb_pdsch, unsigned char nr_tti_rx, @@ -2590,18 +2589,14 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, int prb,nb_rb=0; unsigned short k; //int prb_off,prb_off2; - int skip_half=0,l;//sss_symb,pss_symb=0,nsymb + int skip_half=0;//sss_symb,pss_symb=0,nsymb int i,aarx; int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; - int symbol_mod,pilots=0,j=0; + int j=0; unsigned char *pmi_loc; - pilots = (symbol==2) ? 1 : 0; //to updated from config k = frame_parms->first_carrier_offset + 516; //0 - //nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; - l=symbol; - for (aarx=0; aarxnb_antennas_rx; aarx++) { if (high_speed_flag==1) { diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c index 29f3ffd758..a02efd9a82 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_llr_computation.c @@ -632,6 +632,7 @@ int nr_dlsch_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rxdataF_comp, int16_t *dlsch_llr, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint8_t beamforming_mode) @@ -639,7 +640,7 @@ int nr_dlsch_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, uint32_t *rxF = (uint32_t*)&rxdataF_comp[0][((int32_t)symbol*nb_rb*12)]; uint32_t *llr32; - int i,len; + int i; llr32 = (uint32_t*)dlsch_llr; if (!llr32) { @@ -647,10 +648,6 @@ int nr_dlsch_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, return(-1); } - if (symbol ==2) //to update from config - len = nb_rb*6; - else - len = nb_rb*12; /* LOG_I(PHY,"dlsch_qpsk_llr: [symb %d / Length %d]: @LLR Buff %x, @LLR Buff(symb) %x \n", symbol, @@ -677,6 +674,7 @@ void nr_dlsch_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t *dlsch_llr, int32_t **dl_ch_mag, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, int16_t **llr32p, @@ -696,7 +694,7 @@ void nr_dlsch_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, #endif - int i,len; + int i; unsigned char len_mod4=0; @@ -720,11 +718,6 @@ void nr_dlsch_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, ch_mag = (int16x8_t*)&dl_ch_mag[0][(symbol*nb_rb*12)]; #endif - if (symbol ==2) //to update from config - len = nb_rb*6; - else - len = nb_rb*12; - // update output pointer according to number of REs in this symbol (<<2 because 4 bits per RE) if (first_symbol_flag == 1) *llr32p = dlsch_llr + (len<<2); @@ -798,6 +791,7 @@ void nr_dlsch_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **dl_ch_mag, int32_t **dl_ch_magb, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint32_t llr_offset, @@ -810,7 +804,7 @@ void nr_dlsch_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16x8_t *rxF = (int16x8_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; int16x8_t *ch_mag,*ch_magb,xmm1,xmm2; #endif - int i,len,len2; + int i,len2; unsigned char len_mod4; short *llr; int16_t *llr2; @@ -835,11 +829,6 @@ void nr_dlsch_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, ch_magb = (int16x8_t*)&dl_ch_magb[0][(symbol*frame_parms->N_RB_DL*12)]; #endif - if (symbol ==2) //to update from config - len = nb_rb*6; - else - len = nb_rb*12; - // printf("nr_dlsch_64qam_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust); /* LOG_I(PHY,"nr_dlsch_64qam_llr [symb %d / FirstSym %d / Length %d]: @LLR Buff %x \n", @@ -1131,6 +1120,7 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, int **rho_i, short *dlsch_llr, unsigned char symbol, + uint32_t len, unsigned char first_symbol_flag, unsigned short nb_rb, uint16_t pbch_pss_sss_adjust, @@ -1141,8 +1131,6 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t *rxF_i=(int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; int16_t *rho=(int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; - int len; - //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; if (first_symbol_flag == 1) { llr16 = (int16_t*)dlsch_llr; @@ -1152,11 +1140,6 @@ int nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_qpsk_qpsk_llr: llr is null, symbol %d\n",symbol); - if (symbol ==2) //to update from config - len = nb_rb*6; - else - len = nb_rb*12; - // printf("nr_dlsch_qpsk_qpsk_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust); // printf("qpsk_qpsk: len %d, llr16 %p\n",len,llr16); qpsk_qpsk((short *)rxF, @@ -2972,6 +2955,7 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rho_i, int16_t *dlsch_llr, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint16_t pbch_pss_sss_adjust, @@ -2984,8 +2968,6 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*nb_rb*12)]; int16_t *rho = (int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; - int len; - //uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; // first symbol has different structure due to more pilots if (first_symbol_flag == 1) { @@ -2997,11 +2979,6 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_16qam_16qam_llr: llr is null, symbol %d\n",symbol); - if (symbol ==2) //to update from config - len = nb_rb*6; - else - len = nb_rb*12; - // printf("symbol %d: qam16_llr, len %d (llr16 %p)\n",symbol,len,llr16); qam16_qam16((short *)rxF, @@ -8514,6 +8491,7 @@ int nr_dlsch_64qam_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rho_i, int16_t *dlsch_llr, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint16_t pbch_pss_sss_adjust, @@ -8521,15 +8499,13 @@ int nr_dlsch_64qam_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, uint32_t llr_offset) { - int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*frame_parms->N_RB_DL*12)]; - int16_t *rho = (int16_t*)&rho_i[0][(symbol*frame_parms->N_RB_DL*12)]; + int16_t *rxF = (int16_t*)&rxdataF_comp[0][(symbol*nb_rb*12)]; + int16_t *rxF_i = (int16_t*)&rxdataF_comp_i[0][(symbol*nb_rb*12)]; + int16_t *ch_mag = (int16_t*)&dl_ch_mag[0][(symbol*nb_rb*12)]; + int16_t *ch_mag_i = (int16_t*)&dl_ch_mag_i[0][(symbol*nb_rb*12)]; + int16_t *rho = (int16_t*)&rho_i[0][(symbol*nb_rb*12)]; int16_t *llr16; int8_t *pllr_symbol; // pointer where llrs should filled for this ofdm symbol - int len; - uint8_t symbol_mod = (symbol >= (7-frame_parms->Ncp))? (symbol-(7-frame_parms->Ncp)) : symbol; //first symbol has different structure due to more pilots /*if (first_symbol_flag == 1) { @@ -8543,19 +8519,6 @@ int nr_dlsch_64qam_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, AssertFatal(llr16!=NULL,"nr_dlsch_16qam_64qam_llr:llr is null, symbol %d\n",symbol); - if ((symbol_mod==0) || (symbol_mod==(4-frame_parms->Ncp))) { - // if symbol has pilots - if (frame_parms->nb_antenna_ports_eNB!=1) - // in 2 antenna ports we have 8 REs per symbol per RB - len = (nb_rb*8) - (2*pbch_pss_sss_adjust/3); - else - // for 1 antenna port we have 10 REs per symbol per RB - len = (nb_rb*10) - (5*pbch_pss_sss_adjust/6); - } else { - // symbol has no pilots - len = (nb_rb*12) - pbch_pss_sss_adjust; - } - pllr_symbol = (int8_t*)dlsch_llr; pllr_symbol += llr_offset; //printf("nr_dlsch_64qam_64qam_llr: symbol %d,nb_rb %d, len %d,pbch_pss_sss_adjust %d\n",symbol,nb_rb,len,pbch_pss_sss_adjust); 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 48cf637529..e7af632327 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -113,6 +113,7 @@ int32_t nr_dlsch_qpsk_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rho_i, int16_t *dlsch_llr, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint16_t pbch_pss_sss_adj, @@ -268,6 +269,7 @@ int nr_dlsch_16qam_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int **rho_i, short *dlsch_llr, unsigned char symbol, + uint32_t len, unsigned char first_symbol_flag, unsigned short nb_rb, uint16_t pbch_pss_sss_adjust, @@ -464,6 +466,7 @@ int nr_dlsch_64qam_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, int **rho_i, short *dlsch_llr, unsigned char symbol, + uint32_t len, unsigned char first_symbol_flag, unsigned short nb_rb, uint16_t pbch_pss_sss_adjust, @@ -486,6 +489,7 @@ int32_t nr_dlsch_qpsk_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rxdataF_comp, int16_t *dlsch_llr, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint8_t beamforming_mode); @@ -520,6 +524,7 @@ void nr_dlsch_16qam_llr(NR_DL_FRAME_PARMS *frame_parms, int16_t *dlsch_llr, int32_t **dl_ch_mag, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, int16_t **llr32p, @@ -568,6 +573,7 @@ void nr_dlsch_64qam_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **dl_ch_mag, int32_t **dl_ch_magb, uint8_t symbol, + uint32_t len, uint8_t first_symbol_flag, uint16_t nb_rb, uint32_t llr_offset, @@ -722,8 +728,8 @@ unsigned short nr_dlsch_extract_rbs_single(int **rxdataF, int **dl_ch_estimates_ext, unsigned short pmi, unsigned char *pmi_ext, - unsigned int *rb_alloc, unsigned char symbol, + uint8_t pilots, unsigned short start_rb, unsigned short nb_pdsch_rb, unsigned char nr_tti_rx, @@ -759,8 +765,8 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, int **dl_ch_estimates_ext, unsigned short pmi, unsigned char *pmi_ext, - unsigned int *rb_alloc, unsigned char symbol, + uint8_t pilots, unsigned short start_rb, unsigned short nb_rb_pdsch, unsigned char nr_tti_rx, @@ -822,6 +828,7 @@ void nr_dlsch_channel_compensation(int32_t **rxdataF_ext, int32_t **rho, NR_DL_FRAME_PARMS *frame_parms, uint8_t symbol, + uint8_t start_symbol, uint8_t first_symbol_flag, uint8_t mod_order, uint16_t nb_rb, @@ -842,6 +849,7 @@ void nr_dlsch_channel_compensation_core(int **rxdataF_ext, int start_point); void nr_dlsch_deinterleaving(uint8_t symbol, + uint8_t start_symbol, uint16_t L, uint16_t *llr, uint16_t *llr_deint, @@ -974,11 +982,12 @@ void dlsch_channel_compensation_TM34(NR_DL_FRAME_PARMS *frame_parms, @param pilots_flag Flag to indicate pilots in symbol @param nb_rb Number of allocated RBs */ -void nr_dlsch_channel_level(int32_t **dl_ch_estimates_ext, +void nr_dlsch_channel_level(int **dl_ch_estimates_ext, NR_DL_FRAME_PARMS *frame_parms, int32_t *avg, - uint8_t pilots_flag, - uint16_t nb_rb); + uint8_t symbol, + uint32_t len, + unsigned short nb_rb); void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, @@ -1007,7 +1016,8 @@ void dlsch_channel_level_TM7(int32_t **dl_bf_ch_estimates_ext, void nr_dlsch_scale_channel(int32_t **dl_ch_estimates_ext, NR_DL_FRAME_PARMS *frame_parms, NR_UE_DLSCH_t **dlsch_ue, - uint8_t symbol_mod, + uint8_t symbol, + uint8_t start_symbol, uint16_t nb_rb); /** \brief This is the top-level entry point for DLSCH decoding in UE. It should be replicated on several diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 1ea5814e8d..8f463b59b5 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -916,6 +916,7 @@ typedef struct { NR_UE_COMMON common_vars; nr_ue_if_module_t *if_inst; + nfapi_nr_config_request_t nrUE_config; nr_downlink_indication_t dl_indication; nr_uplink_indication_t ul_indication; diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 139d48ffa9..6b560c9463 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -123,7 +123,10 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ dlsch0->g_pucch = dlsch_config_pdu->accumulated_delta_PUCCH; dlsch0_harq->harq_ack.pucch_resource_indicator = dlsch_config_pdu->pucch_resource_id; dlsch0_harq->harq_ack.slot_for_feedback_ack = dlsch_config_pdu->pdsch_to_harq_feedback_time_ind; + dlsch0_harq->Nl=1; + dlsch0_harq->status = ACTIVE; LOG_D(MAC,">>>> \tdlsch0->g_pucch=%d\tdlsch0_harq.mcs=%d\n",dlsch0->g_pucch,dlsch0_harq->mcs); + } } }else{ diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index c83074d8a2..f622d56544 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -3784,9 +3784,10 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, NR_UE_PDSCH *pdsch_vars; uint8_t is_cw0_active = 0; uint8_t is_cw1_active = 0; - // to be updated by higher layer - uint8_t nb_re_dmrs = 6; - uint16_t length_dmrs = 1; + nfapi_nr_config_request_t *cfg = &ue->nrUE_config; + uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value; + uint8_t nb_re_dmrs = (dmrs_type==NFAPI_NR_DMRS_TYPE1)?6:4; + uint16_t length_dmrs = 1; //cfg->pdsch_config.dmrs_max_length.value; uint16_t nb_symb_sch = 9; if (dlsch0==NULL) @@ -3794,6 +3795,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, harq_pid = dlsch0->current_harq_pid; is_cw0_active = dlsch0->harq_processes[harq_pid]->status; + nb_symb_sch = dlsch0->harq_processes[harq_pid]->nb_symbols; if(dlsch1) is_cw1_active = dlsch1->harq_processes[harq_pid]->status; @@ -3908,7 +3910,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, nb_symb_sch, nr_tti_rx, harq_pid, - pdsch==PDSCH?1:0,//proc->decoder_switch, + pdsch==PDSCH?1:0, dlsch0->harq_processes[harq_pid]->TBS>256?1:0); //printf("start cW0 dlsch decoding\n"); #endif @@ -4324,11 +4326,13 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eN int l,l2; int pilot1; - int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][0]; - uint16_t nb_symb_sch = 9; // to be updated by higher layer + NR_UE_DLSCH_t **dlsch = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id]; + uint8_t harq_pid = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->current_harq_pid; + NR_DL_UE_HARQ_t *dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; + uint16_t nb_symb_sch = dlsch0_harq->nb_symbols; uint8_t nb_symb_pdcch = pdcch_vars->coreset[0].duration; uint8_t dci_cnt = 0; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index c5a569b781..c58d13839a 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -1087,7 +1087,7 @@ int8_t nr_ue_process_dci_freq_dom_resource_assignment( start_RB = riv%n_RB_DLBWP; // if (l_RB - 1) > floor (n_RB_DLBWP/2) we need to recalculate them using the following lines tmp_RIV = n_RB_DLBWP * (l_RB - 1) + start_RB; - if (tmp_RIV != riv) { // then (l_RB - 1) > floor (n_RB_DLBWP/2) and we need to recalculate l_RB and start_RB + if ((tmp_RIV != riv) || ((start_RB+l_RB)>n_RB_DLBWP)) { // then (l_RB - 1) > floor (n_RB_DLBWP/2) and we need to recalculate l_RB and start_RB l_RB = n_RB_DLBWP - l_RB + 2; start_RB = n_RB_DLBWP - start_RB - 1; } From 27ef071b8119e2ddfdfec2195479e8da483e23f4 Mon Sep 17 00:00:00 2001 From: Raymond Knopp Date: Fri, 12 Apr 2019 07:57:34 +0200 Subject: [PATCH 089/117] polartest changes for DCI parameters --- openair1/PHY/CODING/TESTBENCH/polartest.c | 4 ++++ openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index ddcc3ce826..108aacd96f 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -142,6 +142,10 @@ int main(int argc, char *argv[]) { if (polarMessageType == 0) { //PBCH } else if (polarMessageType == 1) { //DCI + if (aggregation_level != 16 && aggregation_level!=8 && aggregation_level != 4 && aggregation_level !=2 && aggregation_level !=1) { + printf("Illegal aggregation level %d\n",aggregation_level); + exit(-1); + } coderLength = 108*aggregation_level; } else if (polarMessageType == -1) { //UCI printf("UCI testing not supported yet\n"); diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c index e78f3a85b7..26832fd70c 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c @@ -88,7 +88,7 @@ uint32_t nr_polar_output_length(uint16_t K, if (n>n_2) n=n_2; if (n Date: Fri, 12 Apr 2019 08:55:10 +0200 Subject: [PATCH 090/117] added backtrace.c to smallblocktest executable --- cmake_targets/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 253a78726a..f3c0f4cca3 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2511,7 +2511,9 @@ add_executable(polartest target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) -add_executable(smallblocktest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c) +add_executable(smallblocktest +${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c +${OPENAIR_DIR}/common/utils/backtrace.c) target_link_libraries(smallblocktest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) add_executable(ldpctest From 99c6c9227ea39a21f993e5a82fef90f3fc0ca018 Mon Sep 17 00:00:00 2001 From: Raymond Knopp Date: Fri, 12 Apr 2019 13:27:20 +0200 Subject: [PATCH 091/117] cleanup after merge with develop-nr --- .../nfapi/public_inc/nfapi_interface.h | 2 +- openair1/PHY/CODING/TESTBENCH/ldpctest.c | 8 +-- openair1/PHY/CODING/coding_defs.h | 2 - openair1/PHY/CODING/crc_byte.c | 2 +- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 2 + .../CODING/nrPolar_tools/nr_polar_encoder.c | 1 + openair1/PHY/LTE_TRANSPORT/dlsch_coding.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 39 +++++++------ .../SCHED_NR_UE/pucch_power_control_ue_nr.c | 4 +- openair1/SCHED_NR_UE/pucch_uci_ue_nr.c | 56 +++++++++++++++++-- openair1/SIMULATION/NR_PHY/dlschsim.c | 8 +-- openair1/SIMULATION/NR_PHY/dlsim.c | 35 +++++------- openair2/GNB_APP/gnb_config.c | 2 +- openair2/LAYER2/NR_MAC_UE/mac.h | 8 +-- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 4 +- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 22 -------- openair2/RRC/NR/L2_nr_interface.c | 1 + openair2/RRC/NR/rrc_gNB.c | 9 +-- 19 files changed, 114 insertions(+), 95 deletions(-) diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h index fc3859be94..51f66c3075 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h @@ -583,7 +583,7 @@ typedef struct { } nfapi_pnf_phy_rf_config_t; #define NFAPI_PNF_PHY_RF_TAG 0x1003 -// Generic structure for single tlv value. +// Generic strucutre for single tlv value. typedef struct { nfapi_tl_t tl; uint16_t value; diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c index d8ba986175..6db9548dbe 100644 --- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c +++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c @@ -382,12 +382,12 @@ int test_ldpc(short No_iteration, //Uncoded BER if (channel_output_fixed[j][i]<0) - channel_output_uncoded[j][i]=1; //QPSK demod - else - channel_output_uncoded[j][i]=0; + channel_output_uncoded[j][i]=1; //QPSK demod + else + channel_output_uncoded[j][i]=0; if (channel_output_uncoded[j][i] != channel_input[j][i-2*Zc]) - *errors_bit_uncoded = (*errors_bit_uncoded) + 1; + *errors_bit_uncoded = (*errors_bit_uncoded) + 1; } } // End segments diff --git a/openair1/PHY/CODING/coding_defs.h b/openair1/PHY/CODING/coding_defs.h index 2277826a66..0c1dbfae35 100644 --- a/openair1/PHY/CODING/coding_defs.h +++ b/openair1/PHY/CODING/coding_defs.h @@ -30,8 +30,6 @@ #include #include -typedef unsigned __int128 uint128_t; - #define CRC24_A 0 #define CRC24_B 1 #define CRC16 2 diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index bf8d63fb39..5e0ebeb991 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -259,7 +259,7 @@ unsigned int crcPayload(unsigned char * inptr, int bitlen, uint32_t* crc256Table int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) { uint32_t crc=0,oldcrc=0; - uint8_t crc_len; + uint8_t crc_len,temp; switch (crc_type) { case CRC24_A: diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index f6c66e89dc..7b63e5757c 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -59,6 +59,8 @@ static const uint8_t nr_polar_subblock_interleaver_pattern[32] = {0,1,2,4,3,5,6, #define Nmax 1024 #define nmax 10 +#define uint128_t __uint128_t + typedef struct decoder_node_t_s { struct decoder_node_t_s *left; struct decoder_node_t_s *right; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c index 245094e238..b504812d0b 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c @@ -37,6 +37,7 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" +#include " //input [a_31 a_30 ... a_0] //output [f_31 f_30 ... f_0] [f_63 f_62 ... f_32] ... diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c index 12870016fa..a7e4b33c16 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c @@ -703,7 +703,7 @@ int dlsch_encoding_all(PHY_VARS_eNB *eNB, int dlsch_encoding(PHY_VARS_eNB *eNB, - unsigned char *a, + unsigned char *a, uint8_t num_pdcch_symbols, LTE_eNB_DLSCH_t *dlsch, int frame, diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 2a12b33104..c83074d8a2 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2814,8 +2814,8 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * //uint8_t pbch_phase; int ret = 0; uint16_t frame_tx; - //static uint8_t first_run = 1; - //uint8_t pbch_trials = 0; + static uint8_t first_run = 1; + uint8_t pbch_trials = 0; DevAssert(ue); @@ -2908,10 +2908,9 @@ unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb #ifdef NR_PDCCH_SCHED -int nr_ue_pdcch_procedures(uint8_t eNB_id, - PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc) +int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc) { + // unsigned int dci_cnt=0, i; //removed for nr_ue_pdcch_procedures and added in the loop for nb_coreset_active #ifdef NR_PDCCH_SCHED_DEBUG printf("<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Entering function nr_ue_pdcch_procedures() \n"); @@ -2959,10 +2958,10 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id, #endif // p in TS 38.212 Subclause 10.1, for each active BWP the UE can deal with 3 different CORESETs (including coresetId 0 for common search space) - //int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; + int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; unsigned int dci_cnt=0; // this table contains 56 (NBR_NR_DCI_FIELDS) elements for each dci field and format described in TS 38.212. Each element represents the size in bits for each dci field - //uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; + uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; // this is the UL bandwidth part. FIXME! To be defined where this value comes from // uint16_t n_RB_ULBWP = 106; // this is the DL bandwidth part. FIXME! To be defined where this value comes from @@ -2989,7 +2988,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id, * To be implemented LATER !!! */ //int _offset,_index,_M; - //int searchSpace_id = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceId; + int searchSpace_id = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceId; #ifdef NR_PDCCH_SCHED_DEBUG @@ -3002,16 +3001,16 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id, // the searchSpace indicates that we need to monitor PDCCH in current nr_tti_rx // get the parameters describing the current SEARCHSPACE // the CORESET id applicable to the current SearchSpace - //int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; + int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; // FIXME this variable is a bit string (14 bits) identifying every OFDM symbol in a slot. // at the moment we will not take into consideration this variable and we will consider that the OFDM symbol offset is always the first OFDM in a symbol uint16_t symbol_within_slot_mon = pdcch_vars2->searchSpace[nb_searchspace_active].monitoringSymbolWithinSlot; // get the remaining parameters describing the current SEARCHSPACE: // FIXME! To be defined where we get this information from - //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; - //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L2 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel2; - //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L4 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel4; - //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L8 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel8; - //NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L2 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel2; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L4 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel4; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L8 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel8; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16; // FIXME! A table of five enum elements // searchSpaceType indicates whether this is a common search space or a UE-specific search space //int searchSpaceType = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceType.type; @@ -3781,7 +3780,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; int ret=0, ret1=0; - //int CC_id = ue->CC_id; + int CC_id = ue->CC_id; NR_UE_PDSCH *pdsch_vars; uint8_t is_cw0_active = 0; uint8_t is_cw1_active = 0; @@ -4318,11 +4317,11 @@ void *UE_thread_slot1_dl_processing(void *arg) { -int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, - uint8_t do_pdcch_flag, - runmode_t mode) -{ +int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, + uint8_t do_pdcch_flag,runmode_t mode) { + + + int l,l2; int pilot1; diff --git a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c index f0005f25b1..debb0d4ed5 100644 --- a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c @@ -34,8 +34,6 @@ #include "SCHED_NR_UE/pucch_power_control_ue_nr.h" #include -int16_t get_PL(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index); - /**************** defines **************************************/ /**************** variables **************************************/ @@ -149,7 +147,7 @@ int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_pro } } - //int l = 0; + int l = 0; int k2; if (power_config->twoPUCCH_PC_AdjustmentStates > 1) { diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c index 161ee0b57c..ec5ed6d91d 100644 --- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c @@ -53,7 +53,57 @@ int8_t nr_ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP, uint8_t eNB_id, uint16_t rnti, sub_frame_t subframe); uint8_t is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id); uint8_t is_ri_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id); +/* +void nr_generate_pucch0(int32_t **txdataF, + NR_DL_FRAME_PARMS *frame_parms, + PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, + int16_t amp, + int nr_tti_tx, + uint8_t mcs, + uint8_t nrofSymbols, + uint8_t startingSymbolIndex, + uint16_t startingPRB); +void nr_generate_pucch1(int32_t **txdataF, + NR_DL_FRAME_PARMS *frame_parms, + PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, + uint64_t payload, + int16_t amp, + int nr_tti_tx, + uint8_t nrofSymbols, + uint8_t startingSymbolIndex, + uint16_t startingPRB, + uint16_t startingPRB_intraSlotHopping, + uint8_t timeDomainOCC, + uint8_t nr_bit); + +void nr_generate_pucch2(int32_t **txdataF, + NR_DL_FRAME_PARMS *frame_parms, + PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, + uint64_t payload, + int16_t amp, + int nr_tti_tx, + uint8_t nrofSymbols, + uint8_t startingSymbolIndex, + uint8_t nrofPRB, + uint16_t startingPRB, + uint8_t nr_bit); + +void nr_generate_pucch3_4(int32_t **txdataF, + NR_DL_FRAME_PARMS *frame_parms, + pucch_format_nr_t fmt, + PUCCH_CONFIG_DEDICATED *pucch_config_dedicated, + uint64_t payload, + int16_t amp, + int nr_tti_tx, + uint8_t nrofSymbols, + uint8_t startingSymbolIndex, + uint8_t nrofPRB, + uint16_t startingPRB, + uint8_t nr_bit, + uint8_t occ_length_format4, + uint8_t occ_index_format4); +*/ /**************** variables **************************************/ @@ -508,8 +558,7 @@ bool pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_ switch(format) { case pucch_format0_nr: { - nr_generate_pucch0(ue, - ue->common_vars.txdataF, + nr_generate_pucch0(ue,ue->common_vars.txdataF, &ue->frame_parms, &ue->pucch_config_dedicated[gNB_id], tx_amp, @@ -523,8 +572,7 @@ bool pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_ } case pucch_format1_nr: { - nr_generate_pucch1(ue, - ue->common_vars.txdataF, + nr_generate_pucch1(ue,ue->common_vars.txdataF, &ue->frame_parms, &ue->pucch_config_dedicated[gNB_id], pucch_payload, diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index fef06e5a50..2a95768a3e 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -493,9 +493,9 @@ int main(int argc, char **argv) { short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); double errors_bit_uncoded = 0; - //unsigned char *estimated_output = malloc16(sizeof(unsigned char) * 16 * 68 * 384); - unsigned char *estimated_output_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); - unsigned char *test_input_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); + unsigned char *estimated_output; + unsigned char *estimated_output_bit; + unsigned char *test_input_bit; unsigned int errors_bit = 0; test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); @@ -514,7 +514,7 @@ int main(int argc, char **argv) { for (i = 0; i < TBS / 8; i++) test_input[i] = (unsigned char) rand(); - //estimated_output = harq_process->b; + estimated_output = harq_process->b; #ifdef DEBUG_DLSCHSIM for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index acba9d0ef0..b95ea7502e 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -42,12 +42,11 @@ #include "PHY/MODULATION/modulation_UE.h" #include "PHY/INIT/phy_init.h" #include "PHY/NR_TRANSPORT/nr_transport.h" -//#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED_NR/sched_nr.h" #include "SCHED_NR/fapi_nr_l1.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" -#include "SCHED_NR/fapi_nr_l1.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" @@ -58,11 +57,6 @@ #include "NR_PHY_INTERFACE/NR_IF_Module.h" #include "NR_UE_PHY_INTERFACE/NR_IF_Module.h" -#include "LAYER2/NR_MAC_UE/mac_proto.h" -//#include "LAYER2/NR_MAC_gNB/mac_proto.h" -//#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" -#include "RRC/NR/MESSAGES/asn1_msg.h" - PHY_VARS_gNB *gNB; PHY_VARS_NR_UE *UE; @@ -126,40 +120,41 @@ int main(int argc, char **argv) { char c; - int i,aa; + + int i,l,aa; double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1=2.0; uint8_t snr1set=0; int **txdata; double **s_re,**s_im,**r_re,**r_im; - //double iqim = 0.0; - //unsigned char pbch_pdu[6]; + double iqim = 0.0; + unsigned char pbch_pdu[6]; // int sync_pos, sync_pos_slot; // FILE *rx_frame_file; FILE *output_fd = NULL; uint8_t write_output_file=0; //int result; - // int freq_offset, subframe_offset; + int freq_offset; + // int subframe_offset; // char fname[40], vname[40]; - int trial,n_trials=1,n_errors=0; - //int n_errors2=0,n_alamouti=0; + int trial,n_trials=1,n_errors,n_errors2,n_alamouti; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; uint64_t SSB_positions=0x01; channel_desc_t *gNB2UE; - //uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; + uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; uint8_t extended_prefix_flag=0; int8_t interf1=-21,interf2=-21; FILE *input_fd=NULL,*pbch_file_fd=NULL; - //char input_val_str[50],input_val_str2[50]; + char input_val_str[50],input_val_str2[50]; - //uint8_t frame_mod4, num_pdcch_symbols = 0; + uint8_t frame_mod4,num_pdcch_symbols = 0; SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - //double pbch_sinr; - //int pbch_tx_ant; + double pbch_sinr; + int pbch_tx_ant; int N_RB_DL=273,mu=1; uint64_t ssb_pattern = 0x01; @@ -681,8 +676,8 @@ int main(int argc, char **argv) for (SNR=snr0; SNRul_config_request; - //fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; nr_phy_config_t *phy_config = &mac->phy_config; //ul_config->ul_config_list[ul_config->number_pdus].ulsch_config_pdu.rnti = rnti; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index 4c7c491454..def897433e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -36,8 +36,6 @@ #include "LAYER2/MAC/mac_extern.h" #include "LAYER2/MAC/mac_proto.h" #include "LAYER2/NR_MAC_gNB/mac_proto.h" -#include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" -#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h" #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" @@ -337,7 +335,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, rnti = UE_RNTI(module_idP, i); CC_id = UE_PCCID(module_idP, i); - //int spf = get_spf(cfg); + int spf = get_spf(cfg); if (((frameP&127) == 0) && (slotP == 0)) { LOG_I(MAC, diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 9968c39df4..97a417fea1 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -36,28 +36,6 @@ void mac_top_init_gNB(void); -uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint32_t bw); - -uint64_t from_nrarfcn(int nr_bandP, uint32_t dl_nrarfcn); - -void config_nr_mib(int Mod_idP, - int CC_idP, - int p_gNBP, - int subCarrierSpacingCommon, - uint32_t ssb_SubcarrierOffset, - int dmrs_TypeA_Position, - uint32_t pdcch_ConfigSIB1, - int cellBarred, - int intraFreqReselection - ); - -void config_common(int Mod_idP, - int CC_idP, - int nr_bandP, - uint64_t dl_CarrierFreqP, - uint32_t dl_BandwidthP - ); - int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, int cellid, diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index c8cdfd336f..0dca3b80d2 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -58,6 +58,7 @@ int8_t mac_rrc_nr_data_req(const module_id_t Mod_idP, uint8_t sfn_msb = (uint8_t)((frameP>>4)&0x3f); #ifdef DEBUG_RRC + int i; LOG_I(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id); #endif diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index af5ec8df82..801673b2ef 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -144,15 +144,16 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( rrc_gNB_ue_context_t *const ue_context_pP ){ - //uint8_t size, buffer[100]; - //int CC_id = ue_context_pP->ue_context.primaryCC_id; - //OCTET_STRING_t *secondaryCellGroup; + uint8_t size; + uint8_t buffer[100]; + int CC_id = ue_context_pP->ue_context.primaryCC_id; + OCTET_STRING_t *secondaryCellGroup; NR_CellGroupConfig_t *cellGroupconfig; struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_BearerToAddModList; struct NR_MAC_CellGroupConfig *mac_CellGroupConfig; struct NR_PhysicalCellGroupConfig *physicalCellGroupConfig; struct NR_SpCellConfig *spCellConfig; - //struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; + struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; cellGroupconfig = CALLOC(1,sizeof(NR_CellGroupConfig_t)); cellGroupconfig->rlc_BearerToAddModList = CALLOC(1,sizeof(struct NR_CellGroupConfig__rlc_BearerToAddModList)); From b2add95524de502179abf2bce720793223f581b6 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Sun, 14 Apr 2019 17:38:52 +0200 Subject: [PATCH 092/117] Added clean_gNB_ulsch, fully working polartest, and many other minor warning removals. --- cmake_targets/CMakeLists.txt | 4 +- cmake_targets/autotests/test_case_list.xml | 17 +- cmake_targets/build_oai | 2 - openair1/PHY/CODING/TESTBENCH/polartest.c | 473 +++++++----------- .../PHY/CODING/TESTBENCH/smallblocktest.c | 6 +- openair1/PHY/CODING/crc_byte.c | 33 +- .../nrLDPC_decoder/nrLDPC_tools/time_meas.c | 117 ----- .../nrLDPC_decoder/nrLDPC_tools/time_meas.h | 156 ------ .../PHY/CODING/nrLDPC_decoder/nrLDPC_types.h | 2 +- .../nrPolar_tools/nr_bitwise_operations.c | 27 +- .../PHY/CODING/nrPolar_tools/nr_crc_byte.c | 62 +-- .../CODING/nrPolar_tools/nr_polar_decoder.c | 293 +---------- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 56 +-- .../CODING/nrPolar_tools/nr_polar_encoder.c | 103 +--- .../CODING/nrSmallBlock/decodeSmallBlock.c | 2 +- openair1/PHY/CODING/nr_polar_init.c | 19 +- openair1/PHY/NR_TRANSPORT/nr_dci.h | 2 - openair1/PHY/NR_TRANSPORT/nr_dlsch.h | 2 + openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 100 +++- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 4 +- openair1/SCHED_NR/fapi_nr_l1.h | 4 +- openair1/SIMULATION/NR_PHY/dlschsim.c | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 7 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 16 +- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 8 +- openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h | 4 - 26 files changed, 417 insertions(+), 1104 deletions(-) delete mode 100644 openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c delete mode 100644 openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 253a78726a..f504af1733 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2511,7 +2511,9 @@ add_executable(polartest target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) -add_executable(smallblocktest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c) +add_executable(smallblocktest + ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c + ${OPENAIR_DIR}/common/utils/backtrace.c) target_link_libraries(smallblocktest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) add_executable(ldpctest diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index c0f8eac447..a970ccbf5d 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1120,16 +1120,15 @@ execution shortblocktest Test cases. (Test1: 3 bits), - (Test2: 6 bits) - (Test3: 7 bits) - (Test4: 11 bits) - + (Test2: 6 bits), + (Test3: 7 bits), + (Test4: 11 bits) $OPENAIR_DIR/targets/bin/smallblocktest.Rel15 - -l 3 - -l 6 - -l 7 - -l 11 - smallblocktest.test1 smallblocktest.test2 smallblocktest.test3 smallblocktest.test3 + -l 3 -s -4 -d 1 -i 10000 + -l 6 -s -4 -d 1 -i 10000 + -l 7 -s -4 -d 1 -i 10000 + -l 11 -s -4 -d 1 -i 10000 + smallblocktest.test1 smallblocktest.test2 smallblocktest.test3 smallblocktest.test4 BLER= 0.000000 segmentation fault|assertion|exiting|fatal 3 diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 4bfa734709..af051abab7 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -80,8 +80,6 @@ function print_help() { This program installs OpenAirInterface Software You should have ubuntu 16.xx or 18.04 updated Options --h - This help -c | --clean Erase all files to make a rebuild from start -C | --clean-all diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index ddcc3ce826..49e71abbc9 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -16,43 +16,11 @@ //#define DEBUG_DCI_POLAR_PARAMS //#define DEBUG_POLAR_TIMING -//#define DEBUG_CRC //#define DEBUG_POLARTEST -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}; - -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); - - for (uint8_t i=0; i 60) { - printf("Illegal packet bitlength\n",testLength); - exit(-1); - } - - break; + testLength=atoi(optarg); + if (testLength < 12 || testLength > 60) { + printf("Illegal packet bitlength %d \n",testLength); + exit(-1); + } + break; case 'h': - printf("./polartest -s SNRstart -d SNRinc -f SNRstop -m [0=PBCH|1=DCI|2=UCI] -i iterations -l decoderListSize -a pathMetricAppr -L aggregation level (for DCI) -K packet_length (bits) for DCI/UCI\n"); + printf("./polartest\nOptions\n-h Print this help\n-s SNRstart (dB)\n-d SNRinc (dB)\n-f SNRstop (dB)\n-m [0=PBCH|1=DCI|2=UCI]\n" + "-i Number of iterations\n-l decoderListSize\n-a pathMetricAppr\n-q Flag for optimized coders usage\n-F Flag for test results logging\n" + "-L aggregation level (for DCI)\n-K packet_length (bits) for DCI/UCI\n"); exit(-1); break; @@ -140,23 +107,34 @@ int main(int argc, char *argv[]) { break; } + //Initiate timing. (Results depend on CPU Frequency. Therefore, might change due to performance variances during simulation.) + time_stats_t timeEncoder,timeDecoder; + opp_enabled=1; + cpu_freq_GHz = get_cpu_freq_GHz(); + reset_meas(&timeEncoder); + reset_meas(&timeDecoder); + randominit(0); + crcTableInit(); + if (polarMessageType == 0) { //PBCH + aggregation_level = NR_POLAR_PBCH_AGGREGATION_LEVEL; } else if (polarMessageType == 1) { //DCI - coderLength = 108*aggregation_level; + coderLength = 108*aggregation_level; } else if (polarMessageType == -1) { //UCI - printf("UCI testing not supported yet\n"); - exit(-1); + printf("UCI testing not supported yet\n"); + exit(-1); } //Logging time_t currentTime; - time (¤tTime); char fileName[512], currentTimeInfo[25]; char folderName[] = "."; - /* - folderName=getenv("HOME"); - strcat(folderName,"/Desktop/polartestResults"); - */ + FILE *logFile; + /*folderName=getenv("HOME"); + strcat(folderName,"/Desktop/polartestResults");*/ + +if (logFlag){ + time (¤tTime); #ifdef DEBUG_POLAR_TIMING sprintf(fileName,"%s/TIMING_ListSize_%d_pmAppr_%d_Payload_%d_Itr_%d",folderName,decoderListSize,pathMetricAppr,testLength,iterations); #else @@ -165,11 +143,8 @@ int main(int argc, char *argv[]) { strftime(currentTimeInfo, 25, "_%Y-%m-%d-%H-%M-%S.csv", localtime(¤tTime)); strcat(fileName,currentTimeInfo); //Create "~/Desktop/polartestResults" folder if it doesn't already exist. - /* - struct stat folder = {0}; - if (stat(folderName, &folder) == -1) mkdir(folderName, S_IRWXU | S_IRWXG | S_IRWXO); - */ - FILE *logFile; + /*struct stat folder = {0}; + if (stat(folderName, &folder) == -1) mkdir(folderName, S_IRWXU | S_IRWXG | S_IRWXO);*/ logFile = fopen(fileName, "w"); if (logFile==NULL) { @@ -178,11 +153,12 @@ int main(int argc, char *argv[]) { } #ifdef DEBUG_POLAR_TIMING - fprintf(logFile, - ",timeEncoderCRCByte[us],timeEncoderCRCBit[us],timeEncoderInterleaver[us],timeEncoderBitInsertion[us],timeEncoder1[us],timeEncoder2[us],timeEncoderRateMatching[us],timeEncoderByte2Bit[us]\n"); + fprintf(logFile,",timeEncoderCRCByte[us],timeEncoderCRCBit[us],timeEncoderInterleaver[us],timeEncoderBitInsertion[us],timeEncoder1[us],timeEncoder2[us],timeEncoderRateMatching[us],timeEncoderByte2Bit[us]\n"); #else fprintf(logFile,",SNR,nBitError,blockErrorState,t_encoder[us],t_decoder[us]\n"); #endif +} + uint8_t testArrayLength = ceil(testLength / 32.0); uint8_t coderArrayLength = ceil(coderLength / 32.0); uint32_t testInput[testArrayLength]; //generate randomly @@ -196,261 +172,160 @@ int main(int argc, char *argv[]) { double channelOutput[coderLength]; //add noise int16_t channelOutput_int16[coderLength]; t_nrPolar_params *currentPtr = nr_polar_params(polarMessageType, testLength, aggregation_level); + #ifdef DEBUG_DCI_POLAR_PARAMS uint32_t dci_pdu[4]; memset(dci_pdu,0,sizeof(uint32_t)*4); dci_pdu[0]=0x01189400; - printf("dci_pdu: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]); + printf("dci_pdu: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]); + uint16_t size=41; + rnti=3; + aggregation_level=8; uint32_t encoder_output[54]; memset(encoder_output,0,sizeof(uint32_t)*54); - uint16_t size=41; - uint16_t rnti=3; - aggregation_level=8; t_nrPolar_params *currentPtrDCI=nr_polar_params(1, size, aggregation_level); - polar_encoder_dci(dci_pdu, encoder_output, currentPtrDCI, rnti); - for (int i=0; i<54; i++) - printf("encoder_output: [%2d]->0x%08x \n",i, encoder_output[i]); + polar_encoder_dci(dci_pdu, encoder_output, currentPtrDCI, rnti); + for (int i=0; i<54; i++) printf("encoder_output: [%2d]->0x%08x \n", i, encoder_output[i]); uint8_t *encoder_outputByte = malloc(sizeof(uint8_t) * currentPtrDCI->encoderLength); - double *channel_output = malloc (sizeof(double) * currentPtrDCI->encoderLength); - uint32_t dci_estimation[4]; - memset(dci_estimation,0,sizeof(uint32_t)*4); - printf("dci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]); + double *modulated_input = malloc (sizeof(double) * currentPtrDCI->encoderLength); + double *channel_output = malloc (sizeof(double) * currentPtrDCI->encoderLength); + uint32_t dci_est[4]; + memset(dci_est,0,sizeof(uint32_t)*4); + printf("dci_est: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_est[0], dci_est[1], dci_est[2], dci_est[3]); nr_bit2byte_uint32_8(encoder_output, currentPtrDCI->encoderLength, encoder_outputByte); printf("[polartest] encoder_outputByte: "); + for (int i = 0; i < currentPtrDCI->encoderLength; i++) printf("%d-", encoder_outputByte[i]); printf("\n"); - for (int i = 0; i < currentPtrDCI->encoderLength; i++) printf("%d-", encoder_outputByte[i]); - - printf("\n"); - + SNR_lin = pow(10, 0/10); //SNR = 0 dB for(int i=0; iencoderLength; i++) { - if (encoder_outputByte[i] == 0) { - channel_output[i]=1/sqrt(2); - } else { - channel_output[i]=(-1)/sqrt(2); - } + if (encoder_outputByte[i] == 0) + modulated_input[i]=1/sqrt(2); + else + modulated_input[i]=(-1)/sqrt(2); + channel_output[i] = modulated_input[i] + (gaussdouble(0.0,1.0) * (1/sqrt(2*SNR_lin))); } - - decoderState = polar_decoder_dci(channel_output, - dci_estimation, - currentPtrDCI, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - rnti); - printf("dci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]); + decoderState = polar_decoder_dci(channel_output, dci_est, currentPtrDCI, NR_POLAR_DECODER_LISTSIZE, NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, rnti); + printf("dci_est: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_est[0], dci_est[1], dci_est[2], dci_est[3]); free(encoder_outputByte); free(channel_output); + free(modulated_input); return 0; #endif -#ifdef DEBUG_CRC - uint32_t crc; - unsigned int poly24c = 0xb2b11700; - uint32_t testInputCRC[4]; - testInputCRC[0]=0x00291880; - //testInputCRC[0]=0x01189400; - testInputCRC[1]=0x00000000; - testInputCRC[2]=0x00000000; - testInputCRC[3]=0x00000000; - uint32_t testInputcrc=0x01189400; - uint32_t testInputcrc2=0x00291880; - uint8_t testInputCRC2[8]; - nr_crc_bit2bit_uint32_8(testInputCRC, 32, testInputCRC2); - printf("testInputCRC2: [0]->%x \t [1]->%x \t [2]->%x \t [3]->%x\n" - " [4]->%x \t [5]->%x \t [6]->%x \t [7]->%x\n", - testInputCRC2[0], testInputCRC2[1], testInputCRC2[2], testInputCRC2[3], - testInputCRC2[4], testInputCRC2[5], testInputCRC2[6], testInputCRC2[7]); - unsigned int crc41 = crc24c(testInputCRC, 32); - unsigned int crc65 = crc24c(testInputCRC, 56); - printf("crc41: [0]->0x%08x\tcrc65: [0]->0x%08x\n",crc41, crc65); - for (int i=0; i<32; i++) printf("crc41[%d]=%d\tcrc65[%d]=%d\n",i,(crc41>>i)&1,i,(crc65>>i)&1); - - crc = crc24c(testInputCRC, testLength)>>8; - - for (int i=0; i<24; i++) printf("[i]=%d\n",(crc>>i)&1); - - printf("crc: [0]->0x%08x\n",crc); - //crcbit(testInputCRC, sizeof(test) - 1, poly24c)); - testInputCRC[testLength>>3] = ((uint8_t *)&crc)[2]; - testInputCRC[1+(testLength>>3)] = ((uint8_t *)&crc)[1]; - testInputCRC[2+(testLength>>3)] = ((uint8_t *)&crc)[0]; - printf("testInputCRC: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - testInputCRC[0], testInputCRC[1], testInputCRC[2], testInputCRC[3]); - //uint32_t trial32 = 0xffffffff; - uint32_t trial32 = 0xf10fffff; - uint8_t a[4]; - //memcpy(a, &trial32, sizeof(trial32)); - *(uint32_t *)a = trial32; - unsigned char trial[4]; - trial[0]=0xff; - trial[1]=0xff; - trial[2]=0x0f; - trial[3]=0xf1; - uint32_t trialcrc = crc24c(trial, 32); - uint32_t trialcrc32 = crc24c((uint8_t *)&trial32, 32); - //uint32_t trialcrc32 = crc24c(a, 32); - printf("crcbit(trial = %x\n", crcbit(trial, 4, poly24c)); - printf("trialcrc = %x\n", trialcrc); - printf("trialcrc32 = %x\n", trialcrc32); - - for (int i=0; i<32; i++) printf("trialcrc[%2d]=%d\ttrialcrc32[%2d]=%d\n",i,(trialcrc>>i)&1,i,(trialcrc32>>i)&1); - - //uint8_t nr_polar_A[32] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; - uint8_t nr_polar_A[32] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1}; - uint8_t nr_polar_crc[24]; - uint8_t **crc_generator_matrix = crc24c_generator_matrix(32); - nr_matrix_multiplication_uint8_1D_uint8_2D(nr_polar_A, - crc_generator_matrix, - nr_polar_crc, - 32, - 24); - - for (uint8_t i = 0; i < 24; i++) { - nr_polar_crc[i] = (nr_polar_crc[i] % 2); - printf("nr_polar_crc[%d]=%d\n",i,nr_polar_crc[i]); - } - - return 0; -#endif -#ifdef DEBUG_POLAR_TIMING - for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { - SNR_lin = pow(10, SNR / 10); - - for (itr = 1; itr <= iterations; itr++) { - for (int j=0; j0x%08x \n", testInput[0]); - polar_encoder_timing(testInput, encoderOutput, currentPtr, cpu_freq_GHz, logFile); - } - } - - fclose(logFile); - free(testInput); - free(encoderOutput); - free(modulatedInput); - free(channelOutput); - free(estimatedOutput); - return (0); -#endif // We assume no a priori knowledge available about the payload. double aPrioriArray[currentPtr->payloadBits]; for (int i=0; ipayloadBits; i++) aPrioriArray[i] = NAN; for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { - printf("SNR %f\n",SNR); - SNR_lin = pow(10, SNR/10); + printf("SNR %f\n",SNR); + SNR_lin = pow(10, SNR/10); - for (itr = 1; itr <= iterations; itr++) { - for (int i = 0; i < testArrayLength; i++) { - for (int j = 0; j < (sizeof(testInput[0])*8)-1; j++) { - testInput[i] |= ( ((uint32_t) (rand()%2)) &1); - testInput[i]<<=1; - } + for (itr = 1; itr <= iterations; itr++) { + //Generate random values for all the bits of "testInput", not just as much as "currentPtr->payloadBits". + for (int i = 0; i < testArrayLength; i++) { + for (int j = 0; j < (sizeof(testInput[0])*8)-1; j++) { + testInput[i] |= ( ((uint32_t) (rand()%2)) &1); + testInput[i]<<=1; + } + testInput[i] |= ( ((uint32_t) (rand()%2)) &1); + } +#ifdef DEBUG_POLARTEST + //testInput[0] = 0x360f8a5c; + printf("testInput: [0]->0x%08x\n", testInput[0]); + //for (int i=0; i<32; i++) printf("%d-",(testInput[0]>>i)&1); printf("\n"); +#endif + int len_mod64=currentPtr->payloadBits&63; + ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)< PBCH, 1 --> DCI, -1 --> UCI + if (polarMessageType == 0) + polar_encoder(testInput, encoderOutput, currentPtr); + else if (polarMessageType == 1) + polar_encoder_dci(testInput, encoderOutput, currentPtr, rnti); + } + stop_meas(&timeEncoder); - /*printf("testInput: [0]->0x%08x\n", testInput[0]); - for (int i=0; i<32; i++) - printf("%d\n",(testInput[0]>>i)&1);*/ - int len_mod64=currentPtr->payloadBits&63; - ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)<0x%08x\n", encoderOutput[0]); + //for (int i=1;i0x%08x\n", i, encoderOutput[1]); +#endif - if (decoder_int16==0) { - if (polarMessageType == 0) polar_encoder(testInput, encoderOutput, currentPtr); - else polar_encoder_dci(testInput, encoderOutput, currentPtr, 0); - } - else - polar_encoder_fast((uint64_t *)testInput, encoderOutput,0, currentPtr); - - //polar_encoder_fast((uint64_t*)testInput, (uint64_t*)encoderOutput,0, currentPtr); - stop_meas(&timeEncoder); - /*printf("encoderOutput: [0]->0x%08x\n", encoderOutput[0]); - printf("encoderOutput: [1]->0x%08x\n", encoderOutput[1]);*/ //Bit-to-byte: nr_bit2byte_uint32_8(encoderOutput, coderLength, encoderOutputByte); //BPSK modulation for(int i=0; i 15) channelOutput_int16[i] = 127; - else if (channelOutput[i] < -16) channelOutput_int16[i] = -128; - else channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); - } + if (decoder_int16==1) { + if (channelOutput[i] > 15) channelOutput_int16[i] = 127; + else if (channelOutput[i] < -16) channelOutput_int16[i] = -128; + else channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); + } } start_meas(&timeDecoder); - /*decoderState = polar_decoder(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - aPrioriArray, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION);*/ - if (decoder_int16==0) { - if (polarMessageType == 0) - decoderState = polar_decoder_aPriori(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - aPrioriArray); - else if (polarMessageType == 1) - decoderState = polar_decoder_dci(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - 0); + if (decoder_int16==1) { + decoderState = polar_decoder_int16(channelOutput_int16, (uint64_t *)estimatedOutput, currentPtr); + } else { //0 --> PBCH, 1 --> DCI, -1 --> UCI + if (polarMessageType == 0) + decoderState = polar_decoder(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION); + else if (polarMessageType == 1) + decoderState = polar_decoder_dci(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, + rnti); } - else decoderState = polar_decoder_int16(channelOutput_int16, - (uint64_t *)estimatedOutput, - currentPtr); - stop_meas(&timeDecoder); - /*printf("testInput: [0]->0x%08x\n", testInput[0]); - printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]);*/ + +#ifdef DEBUG_POLARTEST + printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]); +#endif //calculate errors if (decoderState!=0) { - blockErrorState=-1; - nBitError=-1; + blockErrorState=-1; + nBitError=-1; } else { - for (int j = 0; j < currentPtr->payloadBits; j++) { - if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) nBitError++; - - // printf("bit %d: %d => %d\n",j,(testInput[0]>>j)&1,(estimatedOutput[0]>>j)&1); - } - - if (nBitError>0) { - blockErrorState=1; - // printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]); - } + for (int i = 0; i < (testArrayLength-1); i++) { + for (int j = 0; j < 32; j++) { + if ( ((estimatedOutput[i]>>j) & 1) != ((testInput[i]>>j) & 1) ) + nBitError++; + } + } + for (int j = 0; j < testLength - ((testArrayLength-1) * 32); j++) + if ( ((estimatedOutput[(testArrayLength-1)]>>j) & 1) != ((testInput[(testArrayLength-1)]>>j) & 1) ) + nBitError++; } + if (nBitError>0) blockErrorState=1; +#ifdef DEBUG_POLARTEST + for (int i = 0; i < testArrayLength; i++) + printf("[polartest/decoderState=%d] testInput[%d]=0x%08x, estimatedOutput[%d]=0x%08x\n",decoderState, i, testInput[i], i, estimatedOutput[i]); +#endif //Iteration times are in microseconds. timeEncoderCumulative+=(timeEncoder.diff/(cpu_freq_GHz*1000.0)); timeDecoderCumulative+=(timeDecoder.diff/(cpu_freq_GHz*1000.0)); - fprintf(logFile,",%f,%d,%d,%f,%f\n", SNR, nBitError, blockErrorState, - (timeEncoder.diff/(cpu_freq_GHz*1000.0)), (timeDecoder.diff/(cpu_freq_GHz*1000.0))); + if (logFlag) fprintf(logFile,",%f,%d,%d,%f,%f\n", SNR, nBitError, blockErrorState, (timeEncoder.diff/(cpu_freq_GHz*1000.0)), (timeDecoder.diff/(cpu_freq_GHz*1000.0))); if (nBitError<0) { blockErrorCumulative++; @@ -463,6 +338,9 @@ int main(int argc, char *argv[]) { decoderState=0; nBitError=0; blockErrorState=0; + memset(testInput,0,sizeof(uint32_t) * testArrayLength); + memset(encoderOutput,0,sizeof(uint32_t) * coderArrayLength); + memset(estimatedOutput,0,sizeof(uint32_t) * testArrayLength); } //Calculate error statistics for the SNR. @@ -472,8 +350,7 @@ int main(int argc, char *argv[]) { (double)timeEncoder.diff/timeEncoder.trials/(cpu_freq_GHz*1000.0),(double)timeDecoder.diff/timeDecoder.trials/(cpu_freq_GHz*1000.0)); //(timeEncoderCumulative/iterations),timeDecoderCumulative/iterations); - if (blockErrorCumulative==0 && bitErrorCumulative==0) - break; + if (blockErrorCumulative==0 && bitErrorCumulative==0) break; blockErrorCumulative = 0; bitErrorCumulative = 0; @@ -483,6 +360,6 @@ int main(int argc, char *argv[]) { print_meas(&timeEncoder,"polar_encoder",NULL,NULL); print_meas(&timeDecoder,"polar_decoder",NULL,NULL); - fclose(logFile); + if (logFlag) fclose(logFile); return (0); } diff --git a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c index 0b863d2cbf..6278420d8a 100644 --- a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c +++ b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c @@ -127,17 +127,13 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_SMALLBLOCKTEST printf("[smallblocktest] Input = 0x%x, Output = 0x%x, DecoderOutput = 0x%x\n", testInput, encoderOutput, estimatedOutput); for (int i=0;i<32;i++) - printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, Mask[%d] = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (mask>>i)&1); + printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, codingDifference[%d]=%d, Mask[%d] = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (codingDifference>>i)&1, i, (mask>>i)&1); #endif //Error Calculation estimatedOutput &= mask; codingDifference = ((uint32_t)estimatedOutput) ^ testInput; // Count the # of 1's in codingDifference by Brian Kernighan’s algorithm. - //for (int i=0;i<32;i++) - //printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, codingDifference[%d]=%d, Mask[%d] = %d, bitError = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (codingDifference>>i)&1, i, (mask>>i)&1, nBitError); - - for (nBitError = 0; codingDifference; nBitError++) codingDifference &= codingDifference - 1; diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index bf8d63fb39..9ca5355ab4 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -106,17 +106,6 @@ void crcTableInit (void) } while (++c); } -//Generic version -void crcTable256Init (uint32_t poly, uint32_t* crc256Table) -{ - unsigned char c = 0; - - do { - crc256Table[c] = crcbit(&c, 1, poly); - } while (++c); - -} - /********************************************************* Byte by byte implementations, @@ -236,26 +225,6 @@ crc8 (unsigned char * inptr, int bitlen) return crc; } -//Generic version -unsigned int crcPayload(unsigned char * inptr, int bitlen, uint32_t* crc256Table) -{ - int octetlen, resbit; - unsigned int crc = 0; - octetlen = bitlen/8; // Change in bytes - resbit = (bitlen % 8); - - while (octetlen-- > 0) - { - crc = (crc << 8) ^ crc256Table[(*inptr++) ^ (crc >> 24)]; - } - - if (resbit > 0) - { - crc = (crc << resbit) ^ crc256Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]; - } - return crc; -} - int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) { uint32_t crc=0,oldcrc=0; @@ -335,7 +304,7 @@ main() { unsigned char test[] = "Thebigredfox"; crcTableInit(); - printf("%x\n", crcbit(test, sizeof(test) - 1, poly24)); + printf("%x\n", crcbit(test, sizeof(test) - 1, poly24a)); printf("%x\n", crc24(test, (sizeof(test) - 1)*8)); printf("%x\n", crcbit(test, sizeof(test) - 1, poly8)); printf("%x\n", crc8(test, (sizeof(test) - 1)*8)); diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c deleted file mode 100644 index c784188071..0000000000 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include -#include "time_meas.h" -#include -#include - -// global var for openair performance profiler -extern int opp_enabled; - - -double get_cpu_freq_GHz(void) { - - time_stats_t ts = {0}; - reset_meas(&ts); - ts.trials++; - ts.in = rdtsc_oai(); - sleep(1); - ts.diff = (rdtsc_oai()-ts.in); - cpu_freq_GHz = (double)ts.diff/1000000000; - printf("CPU Freq is %f \n", cpu_freq_GHz); - return cpu_freq_GHz; -} - -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name){ - - if (opp_enabled) { - - //static double cpu_freq_GHz = 3.2; - - //if (cpu_freq_GHz == 0.0) - //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow - - if (ts->trials>0) { - - //fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->diff_now/(cpu_freq_GHz*1000000.0)),subframe,ts->diff_now); - fprintf(file_name,"%15.3f ms, diff_now %15.3f \n",(ts->diff_now/(cpu_freq_GHz*1000000.0)),(double)ts->diff_now); - - } - } -} - -void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time) -{ - - if (opp_enabled) { - - static int first_time = 0; - static double cpu_freq_GHz = 0.0; - - if (cpu_freq_GHz == 0.0) - cpu_freq_GHz = get_cpu_freq_GHz(); - - if (first_time == 0) { - first_time=1; - - if ((total_exec_time == NULL) || (sf_exec_time== NULL)) - fprintf(stderr, "%25s %25s %25s %25s %25s %6f\n","Name","Total","Per Trials", "Num Trials","CPU_F_GHz", cpu_freq_GHz); - else - fprintf(stderr, "%25s %25s %25s %20s %15s %6f\n","Name","Total","Average/Frame","Trials", "CPU_F_GHz", cpu_freq_GHz); - } - - if (ts->trials>0) { - //printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials); - - if ((total_exec_time == NULL) || (sf_exec_time== NULL)) { - fprintf(stderr, "%25s: %15.3f ms ; %15.3f us; %15d;\n", - name, - (ts->diff/cpu_freq_GHz/1000000.0), - (ts->diff/ts->trials/cpu_freq_GHz/1000.0), - ts->trials); - } else { - fprintf(stderr, "%25s: %15.3f ms (%5.2f%%); %15.3f us (%5.2f%%); %15d;\n", - name, - (ts->diff/cpu_freq_GHz/1000000.0), - ((ts->diff/cpu_freq_GHz/1000000.0)/(total_exec_time->diff/cpu_freq_GHz/1000000.0))*100, // percentage - (ts->diff/ts->trials/cpu_freq_GHz/1000.0), - ((ts->diff/ts->trials/cpu_freq_GHz/1000.0)/(sf_exec_time->diff/sf_exec_time->trials/cpu_freq_GHz/1000.0))*100, // percentage - ts->trials); - } - } - } - -} - -double get_time_meas_us(time_stats_t *ts) -{ - - static double cpu_freq_GHz = 0.0; - - if (cpu_freq_GHz == 0.0) - cpu_freq_GHz = get_cpu_freq_GHz(); - - if (ts->trials>0) - return (ts->diff/ts->trials/cpu_freq_GHz/1000.0); - - return 0; -} diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h deleted file mode 100644 index e6bec31176..0000000000 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef __TIME_MEAS_DEFS__H__ -#define __TIME_MEAS_DEFS__H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// global var to enable openair performance profiler -static int opp_enabled = 1; -double cpu_freq_GHz; -#if defined(__x86_64__) || defined(__i386__) - -typedef struct { - - long long in; - long long diff; - long long diff_now; - long long p_time; /*!< \brief absolute process duration */ - long long diff_square; /*!< \brief process duration square */ - long long max; - int trials; - int meas_flag; -} time_stats_t; -#elif defined(__arm__) -typedef struct { - uint32_t in; - uint32_t diff_now; - uint32_t diff; - uint32_t p_time; /*!< \brief absolute process duration */ - uint32_t diff_square; /*!< \brief process duration square */ - uint32_t max; - int trials; -} time_stats_t; - -#endif -static inline void start_meas(time_stats_t *ts) __attribute__((always_inline)); -static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline)); - - -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name); -//void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time); -double get_time_meas_us(time_stats_t *ts); -double get_cpu_freq_GHz(void); - -#if defined(__i386__) -static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ - unsigned long long int x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} -#elif defined(__x86_64__) -static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ - unsigned long long a, d; - __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); - return (d<<32) | a; -} - -#elif defined(__arm__) -static inline uint32_t rdtsc_oai(void) __attribute__((always_inline)); -static inline uint32_t rdtsc_oai(void) -{ - uint32_t r = 0; - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) ); - return r; -} -#endif - -static inline void start_meas(time_stats_t *ts) -{ - - if (opp_enabled) { - if (ts->meas_flag==0) { - ts->trials++; - ts->in = rdtsc_oai(); - ts->meas_flag=1; - } - else { - ts->in = rdtsc_oai(); - } - } -} - -static inline void stop_meas(time_stats_t *ts) -{ - - if (opp_enabled) { - long long out = rdtsc_oai(); - - ts->diff_now = (out-ts->in); - - ts->diff_now = (out-ts->in); - ts->diff += (out-ts->in); - /// process duration is the difference between two clock points - ts->p_time = (out-ts->in); - ts->diff_square += (out-ts->in)*(out-ts->in); - - if ((out-ts->in) > ts->max) - ts->max = out-ts->in; - - ts->meas_flag=0; - } -} - -static inline void reset_meas(time_stats_t *ts) { - - ts->trials=0; - ts->diff=0; - ts->diff_now=0; - ts->p_time=0; - ts->diff_square=0; - ts->max=0; - ts->meas_flag=0; - -} - -static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) -{ - - if (opp_enabled) { - dst_ts->trials=src_ts->trials; - dst_ts->diff=src_ts->diff; - dst_ts->max=src_ts->max; - } -} - -#endif diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h index ae32f6ffb6..a61a15459c 100644 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h +++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h @@ -31,7 +31,7 @@ #ifndef __NR_LDPC_TYPES__H__ #define __NR_LDPC_TYPES__H__ -#include "./nrLDPC_tools/time_meas.h" +#include "PHY/TOOLS/time_meas.h" // ============================================================================== // TYPES diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c index a5e78b6f2b..fdba4e1b65 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c @@ -19,6 +19,17 @@ * contact@openairinterface.org */ +/*!\file PHY/CODING/nrPolar_tools/nr_bitwise_operations.c + * \brief + * \author Turker Yilmaz + * \date 2018 + * \version 0.1 + * \company EURECOM + * \email turker.yilmaz@eurecom.fr + * \note + * \warning +*/ + #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { @@ -29,7 +40,8 @@ void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { } } - for (int j = 0; j < arraySize - ((arrayInd-1) * 32); j++) out[j + ((arrayInd-1) * 32)] = (in[(arrayInd-1)] >> j) & 1; + for (int j = 0; j < arraySize - ((arrayInd-1) * 32); j++) + out[j + ((arrayInd-1) * 32)] = (in[(arrayInd-1)] >> j) & 1; } void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out) { @@ -43,16 +55,3 @@ void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out) { out[i]|=in[(i*32)]; } } - -void nr_crc_bit2bit_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { - out[0]=0xff; - out[1]=0xff; - out[2]=0xff; - uint8_t arrayInd = ceil(arraySize / 32.0); - for (int i = 0; i < arrayInd; i++) { - out[3+i*4] = ((in[i] & (0x0000000f))<<4) | ((in[i] & (0x000000f0))>>4); - out[4+i*4] = (((in[i] & (0x00000f00))<<4) | ((in[i] & (0x0000f000))>>4))>>8; - out[5+i*4] = (((in[i] & (0x000f0000))<<4) | ((in[i] & (0x00f00000))>>4))>>16; - out[6+i*4] = (((in[i] & (0x0f000000))<<4) | ((in[i] & (0xf0000000))>>4))>>24; - } -} diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c index ef329b3aaa..461eb7d6f6 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c @@ -21,43 +21,36 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" - // ----- Old implementation ---- uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits){ uint8_t crcPolynomialPattern[25] = {1,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,0,0,0,1,0,1,1,1}; // 1011 0010 1011 0001 0001 0111 D^24 + D^23 + D^21 + D^20 + D^17 + D^15 + D^13 + D^12 + D^8 + D^4 + D^2 + D + 1 - uint8_t crcPolynomialSize = 24;// 24 because crc24c + uint8_t crcPolynomialSize = 24; uint8_t temp1[crcPolynomialSize], temp2[crcPolynomialSize]; uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); if (crc_generator_matrix) - { for (int i = 0; i < payloadSizeBits; i++) - { crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; + temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } - return crc_generator_matrix; } @@ -70,30 +63,26 @@ uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits){ uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); if (crc_generator_matrix) - { for (int i = 0; i < payloadSizeBits; i++) - { crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ + for (int j = 0; j < crcPolynomialSize-1; j++) + temp1[j]=crc_generator_matrix[i+1][j+1]; - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } return crc_generator_matrix; @@ -105,33 +94,30 @@ uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits){ // 0110 0001 D^6 + D^5 + 1 uint8_t crcPolynomialSize = 6; uint8_t temp1[crcPolynomialSize], temp2[crcPolynomialSize]; - uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); - if (crc_generator_matrix) - { - for (int i = 0; i < payloadSizeBits; i++) - { - crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } - for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; + if (crc_generator_matrix) + for (int i = 0; i < payloadSizeBits; i++) + crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); + + for (int i = 0; i < crcPolynomialSize; i++) + crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ + for (int j = 0; j < crcPolynomialSize-1; j++) + temp1[j]=crc_generator_matrix[i+1][j+1]; - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } return crc_generator_matrix; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 5cf044309e..3c32de916e 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -21,11 +21,11 @@ /*!\file PHY/CODING/nrPolar_tools/nr_polar_decoder.c * \brief - * \author Turker Yilmaz + * \author Raymond Knopp, Turker Yilmaz * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email raymond.knopp@eurecom.fr, turker.yilmaz@eurecom.fr * \note * \warning */ @@ -39,12 +39,11 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" -int8_t polar_decoder( - double *input, - uint8_t *out, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr) { +int8_t polar_decoder(double *input, + uint32_t *out, + t_nrPolar_params *polarParams, + uint8_t listSize, + uint8_t pathMetricAppr) { //Assumes no a priori knowledge. uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True @@ -293,7 +292,7 @@ int8_t polar_decoder( /* * Return bits. */ - //nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); return(0); } @@ -572,282 +571,6 @@ int8_t polar_decoder_aPriori(double *input, } - -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *out, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE *logFile) { - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize); - double *pathMetric = malloc(sizeof(double)*(2*listSize)); - uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True - - for (int i=0; i<(2*listSize); i++) { - pathMetric[i] = 0; - crcState[i]=1; - } - - for (int i=0; iN; i++) { - llrUpdated[i][polarParams->n]=1; - bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2); - } - - uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3 - uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2 - - for (int i = 0; i < polarParams->K; i++) { - extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - } - - for (int i=0; ipayloadBits; i++) { - for (int j=0; jcrcParityBits; j++) { - tempECGM[i][j]=polarParams->crc_generator_matrix[i][j]; - } - } - - for (int i=polarParams->payloadBits; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - if( (i-polarParams->payloadBits) == j ) { - tempECGM[i][j]=1; - } else { - tempECGM[i][j]=0; - } - } - } - - for (int i=0; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j]; - } - } - - //The index of the last 1-valued bit that appears in each column. - uint16_t last1ind[polarParams->crcParityBits]; - - for (int j=0; jcrcParityBits; j++) { - for (int i=0; iK; i++) { - if (extended_crc_generator_matrix[i][j]==1) last1ind[j]=i; - } - } - - double *d_tilde = malloc(sizeof(double) * polarParams->N); - nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); - - for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j]; - - /* - * SCL polar decoder. - */ - uint32_t nonFrozenBit=0; - uint8_t currentListSize=1; - uint8_t decoderIterationCheck=0; - int16_t checkCrcBits=-1; - uint8_t listIndex[2*listSize], copyIndex; - - for (uint16_t currentBit=0; currentBitN; currentBit++) { - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); - - if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 - } else { //Information or CRC bit. - if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 0) ) { - //Information bit with known value of "0". - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); - bitUpdated[currentBit][0]=1; //0=False, 1=True - } else if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 1) ) { - //Information bit with known value of "1". - updatePathMetric(pathMetric, llr, currentListSize, 1, currentBit, pathMetricAppr); - - for (uint8_t i=0; icrcParityBits); - } else { - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); - - for (int i = 0; i < currentListSize; i++) { - for (int j = 0; j < polarParams->N; j++) { - for (int k = 0; k < (polarParams->n+1); k++) { - bit[j][k][i+currentListSize]=bit[j][k][i]; - llr[j][k][i+currentListSize]=llr[j][k][i]; - } - } - } - - for (int i = 0; i < currentListSize; i++) { - bit[currentBit][0][i]=0; - crcState[i+currentListSize]=crcState[i]; - } - - for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1; - - bitUpdated[currentBit][0]=1; - updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); - currentListSize*=2; - - //Keep only the best "listSize" number of entries. - if (currentListSize > listSize) { - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - //sort listIndex[listSize, ..., 2*listSize-1] in descending order. - uint8_t swaps, tempInd; - - for (uint8_t i = 0; i < listSize; i++) { - swaps = 0; - - for (uint8_t j = listSize; j < (2*listSize - i) - 1; j++) { - if (listIndex[j+1] > listIndex[j]) { - tempInd = listIndex[j]; - listIndex[j] = listIndex[j + 1]; - listIndex[j + 1] = tempInd; - swaps++; - } - } - - if (swaps == 0) - break; - } - - //First, backup the best "listSize" number of entries. - for (int k=(listSize-1); k>0; k--) { - for (int i=0; iN; i++) { - for (int j=0; j<(polarParams->n+1); j++) { - bit[i][j][listIndex[(2*listSize-1)-k]]=bit[i][j][listIndex[k]]; - llr[i][j][listIndex[(2*listSize-1)-k]]=llr[i][j][listIndex[k]]; - } - } - } - - for (int k=(listSize-1); k>0; k--) { - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][listIndex[(2*listSize-1)-k]] = crcChecksum[i][listIndex[k]]; - } - } - - for (int k=(listSize-1); k>0; k--) crcState[listIndex[(2*listSize-1)-k]]=crcState[listIndex[k]]; - - //Copy the best "listSize" number of entries to the first indices. - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->N; i++) { - for (int j = 0; j < (polarParams->n + 1); j++) { - bit[i][j][k] = bit[i][j][copyIndex]; - llr[i][j][k] = llr[i][j][copyIndex]; - } - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][k]=crcChecksum[i][copyIndex]; - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - crcState[k]=crcState[copyIndex]; - } - - currentListSize = listSize; - } - } - - for (int i=0; icrcParityBits; i++) { - if (last1ind[i]==nonFrozenBit) { - checkCrcBits=i; - break; - } - } - - if ( checkCrcBits > (-1) ) { - for (uint8_t i = 0; i < currentListSize; i++) { - if (crcChecksum[checkCrcBits][i]==1) { - crcState[i]=0; //0=False, 1=True - } - } - } - - for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i]; - - if (decoderIterationCheck==0) { - //perror("[SCL polar decoder] All list entries have failed the CRC checks."); - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - return(-1); - } - - nonFrozenBit++; - decoderIterationCheck=0; - checkCrcBits=-1; - } - } - - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - - for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) { - if ( crcState[listIndex[i]] == 1 ) { - for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_U[j]=bit[j][0][listIndex[i]]; - - //Extract the information bits (û to ĉ) - nr_polar_info_bit_extraction(polarParams->nr_polar_U, polarParams->nr_polar_CPrime, polarParams->information_bit_pattern, polarParams->N); - //Deinterleaving (ĉ to b) - nr_polar_deinterleaver(polarParams->nr_polar_CPrime, polarParams->nr_polar_B, polarParams->interleaving_pattern, polarParams->K); - - //Remove the CRC (â) - for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; - - break; - } - } - - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K); - nr_free_uint8_2D_array(tempECGM, polarParams->K); - /* - * Return bits. - */ - nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); - return(0); -} - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index f6c66e89dc..675015a712 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -21,11 +21,11 @@ /*!\file PHY/CODING/nrPolar_tools/nr_polar_defs.h * \brief - * \author Turker Yilmaz + * \author Raymond Knopp, Turker Yilmaz * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email raymond.knopp@eurecom.fr, turker.yilmaz@eurecom.fr * \note * \warning */ @@ -105,7 +105,7 @@ struct nrPolar_params { int16_t *Q_PC_N; uint8_t *information_bit_pattern; uint16_t *channel_interleaver_pattern; - uint32_t crc_polynomial; + //uint32_t crc_polynomial; uint8_t **crc_generator_matrix; //G_P uint8_t **G_N; @@ -116,7 +116,6 @@ struct nrPolar_params { uint64_t cprime_tab1[32][256]; uint64_t B_tab0[32][256]; uint64_t B_tab1[32][256]; - uint32_t *crc256Table; uint8_t **extended_crc_generator_matrix; //lowercase: bits, Uppercase: Bits stored in bytes //polar_encoder vectors @@ -151,7 +150,7 @@ void polar_encoder_fast(uint64_t *A, t_nrPolar_params *polarParams); int8_t polar_decoder(double *input, - uint8_t *output, + uint32_t *output, t_nrPolar_params *polarParams, uint8_t listSize, uint8_t pathMetricAppr); @@ -167,15 +166,6 @@ int8_t polar_decoder_aPriori(double *input, uint8_t pathMetricAppr, double *aPrioriPayload); -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *output, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE *logFile); - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, @@ -192,9 +182,9 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams); void nr_polar_print_polarParams(t_nrPolar_params *polarParams); -t_nrPolar_params *nr_polar_params ( int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level); +t_nrPolar_params *nr_polar_params (int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level); uint16_t nr_polar_aggregation_prime (uint8_t aggregation_level); @@ -256,16 +246,18 @@ void nr_polar_info_bit_extraction(uint8_t *input, uint16_t size); void nr_bit2byte_uint32_8(uint32_t *in, - uint16_t arraySize, - uint8_t *out); + uint16_t arraySize, + uint8_t *out); void nr_byte2bit_uint8_32(uint8_t *in, - uint16_t arraySize, - uint32_t *out); + uint16_t arraySize, + uint32_t *out); -void nr_crc_bit2bit_uint32_8(uint32_t *in, - uint16_t arraySize, - uint8_t *out); +uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits); + +uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits); + +uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits); void nr_polar_bit_insertion(uint8_t *input, uint8_t *output, @@ -370,12 +362,6 @@ void updateCrcChecksum2(uint8_t **crcChecksum, uint32_t i2, uint8_t len); -uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits); - -uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits); - -uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits); - //Also nr_polar_rate_matcher static inline void nr_polar_interleaver(uint8_t *input, uint8_t *output, @@ -385,12 +371,10 @@ static inline void nr_polar_interleaver(uint8_t *input, } static inline void nr_polar_deinterleaver(uint8_t *input, - uint8_t *output, - uint16_t *pattern, - uint16_t size) { - for (int i=0; ipayloadBits)>>8); #endif nr_bit2byte_uint32_8_t((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);*/ - nr_bit2byte_uint32_8((uint32_t *)in, polarParams->payloadBits, polarParams->nr_polar_A); + nr_bit2byte_uint32_8(in, polarParams->payloadBits, polarParams->nr_polar_A); /* * Bytewise operations */ //Calculate CRC. nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_A, - polarParams->crc_generator_matrix, - polarParams->nr_polar_crc, - polarParams->payloadBits, - polarParams->crcParityBits); + polarParams->crc_generator_matrix, + polarParams->nr_polar_crc, + polarParams->payloadBits, + polarParams->crcParityBits); for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2); @@ -78,6 +77,8 @@ void polar_encoder(uint32_t *in, for (int i = 0; iK; i++) B2 = B2 | ((uint64_t)polarParams->nr_polar_B[i] << i); printf("polar_B %llx\n",B2); + for (int i=0; i< polarParams->payloadBits; i++) printf("a[%d]=%d\n", i, polarParams->nr_polar_A[i]); + for (int i=0; i< polarParams->K; i++) printf("b[%d]=%d\n", i, polarParams->nr_polar_B[i]); #endif /* for (int j=0;jcrcParityBits;j++) { for (int i=0;ipayloadBits;i++) @@ -116,10 +117,10 @@ void polar_encoder(uint32_t *in, polarParams->nr_polar_U[247]=1; polarParams->nr_polar_U[253]=1;*/ nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_U, - polarParams->G_N, - polarParams->nr_polar_D, - polarParams->N, - polarParams->N); + polarParams->G_N, + polarParams->nr_polar_D, + polarParams->N, + polarParams->N); for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); @@ -169,35 +170,29 @@ void polar_encoder_dci(uint32_t *in, #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] A: "); - for (int i=0; ipayloadBits; i++) printf("%d-", polarParams->nr_polar_A[i]); - printf("\n"); + printf("[polar_encoder_dci] APrime: "); - for (int i=0; iK; i++) printf("%d-", polarParams->nr_polar_APrime[i]); - printf("\n"); + printf("[polar_encoder_dci] GP: "); - for (int i=0; icrcParityBits; i++) printf("%d-", polarParams->crc_generator_matrix[0][i]); - printf("\n"); #endif //Calculate CRC. nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_APrime, - polarParams->crc_generator_matrix, - polarParams->nr_polar_crc, - polarParams->K, - polarParams->crcParityBits); + polarParams->crc_generator_matrix, + polarParams->nr_polar_crc, + polarParams->K, + polarParams->crcParityBits); for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2); #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] CRC: "); - for (int i=0; icrcParityBits; i++) printf("%d-", polarParams->nr_polar_crc[i]); - printf("\n"); #endif @@ -209,55 +204,16 @@ void polar_encoder_dci(uint32_t *in, polarParams->nr_polar_B[i]= polarParams->nr_polar_crc[i-(polarParams->payloadBits)]; //Scrambling (b to c) - for (int i=0; i<16; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+8+i] = - ( polarParams->nr_polar_B[polarParams->payloadBits+8+i] + ((n_RNTI>>(15-i))&1) ) % 2; - } + for (int i=0; i<16; i++) + polarParams->nr_polar_B[polarParams->payloadBits+8+i]=( polarParams->nr_polar_B[polarParams->payloadBits+8+i] + ((n_RNTI>>(15-i))&1) ) % 2; - /* //(a to a') - nr_crc_bit2bit_uint32_8_t(in, polarParams->payloadBits, polarParams->nr_polar_aPrime); - //Parity bits computation (p) - polarParams->crcBit = crc24c(polarParams->nr_polar_aPrime, (polarParams->payloadBits+polarParams->crcParityBits)); - #ifdef DEBUG_POLAR_ENCODER_DCI - printf("[polar_encoder_dci] crc: 0x%08x\n", polarParams->crcBit); - for (int i=0; i<32; i++) - { - printf("%d\n",((polarParams->crcBit)>>i)&1); - } - #endif - //(a to b) - // - // Bytewise operations - // - uint8_t arrayInd = ceil(polarParams->payloadBits / 8.0); - for (int i=0; inr_polar_B[j+(i*8)] = ((polarParams->nr_polar_aPrime[3+i]>>(7-j)) & 1); - } - } - for (int i=0; i<((polarParams->payloadBits)%8); i++) { - polarParams->nr_polar_B[i+(arrayInd-1)*8] = ((polarParams->nr_polar_aPrime[3+(arrayInd-1)]>>(7-i)) & 1); - } - for (int i=0; i<8; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+i] = ((polarParams->crcBit)>>(31-i))&1; - } - //Scrambling (b to c) - for (int i=0; i<16; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+8+i] = - ( (((polarParams->crcBit)>>(23-i))&1) + ((n_RNTI>>(15-i))&1) ) % 2; - }*/ #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] B: "); - for (int i = 0; i < polarParams->K; i++) printf("%d-", polarParams->nr_polar_B[i]); - printf("\n"); #endif //Interleaving (c to c') - nr_polar_interleaver(polarParams->nr_polar_B, - polarParams->nr_polar_CPrime, - polarParams->interleaving_pattern, - polarParams->K); + nr_polar_interleaver(polarParams->nr_polar_B, polarParams->nr_polar_CPrime, polarParams->interleaving_pattern, polarParams->K); //Bit insertion (c' to u) nr_polar_bit_insertion(polarParams->nr_polar_CPrime, polarParams->nr_polar_U, @@ -268,13 +224,11 @@ void polar_encoder_dci(uint32_t *in, polarParams->n_pc); //Encoding (u to d) nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_U, - polarParams->G_N, - polarParams->nr_polar_D, - polarParams->N, - polarParams->N); - - for (uint16_t i = 0; i < polarParams->N; i++) - polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); + polarParams->G_N, + polarParams->nr_polar_D, + polarParams->N, + polarParams->N); + for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); //Rate matching //Sub-block interleaving (d to y) and Bit selection (y to e) @@ -288,16 +242,11 @@ void polar_encoder_dci(uint32_t *in, nr_byte2bit_uint8_32(polarParams->nr_polar_E, polarParams->encoderLength, out); #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] E: "); - for (int i = 0; i < polarParams->encoderLength; i++) printf("%d-", polarParams->nr_polar_E[i]); uint8_t outputInd = ceil(polarParams->encoderLength / 32.0); printf("\n[polar_encoder_dci] out: "); - - for (int i = 0; i < outputInd; i++) { - printf("[%d]->0x%08x\t", i, out[i]); - } - + for (int i = 0; i < outputInd; i++) printf("[%d]->0x%08x\t", i, out[i]); #endif } diff --git a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c index 8b53944455..3dd570cc18 100644 --- a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c +++ b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c @@ -48,7 +48,7 @@ uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ int16_t Rhat[NR_SMALL_BLOCK_CODED_BITS] = {0}, Rhatabs[NR_SMALL_BLOCK_CODED_BITS] = {0}; uint16_t maxVal; uint8_t maxInd = 0; - int jmax = (1<<(len-1)); + uint8_t jmax = (1<<(len-1)); for (int j = 0; j < jmax; ++j) for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) Rhat[j] += in[k] * hadamard32InterleavedTransposed[j][k]; diff --git a/openair1/PHY/CODING/nr_polar_init.c b/openair1/PHY/CODING/nr_polar_init.c index dd0056b3b5..f158d44303 100644 --- a/openair1/PHY/CODING/nr_polar_init.c +++ b/openair1/PHY/CODING/nr_polar_init.c @@ -21,19 +21,16 @@ /*!\file PHY/CODING/nr_polar_init.h * \brief - * \author Turker Yilmaz + * \author Turker Yilmaz, Raymond Knopp * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email turker.yilmaz@eurecom.fr, raymond.knopp@eurecom.fr * \note * \warning */ -#include "nrPolar_tools/nr_polar_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h" +#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "PHY/NR_TRANSPORT/nr_dci.h" static int intcmp(const void *p1,const void *p2) { @@ -95,7 +92,9 @@ static void nr_polar_init(t_nrPolar_params * *polarParams, } newPolarInitNode->K = newPolarInitNode->payloadBits + newPolarInitNode->crcParityBits; // Number of bits to encode. - newPolarInitNode->N = nr_polar_output_length(newPolarInitNode->K, newPolarInitNode->encoderLength, newPolarInitNode->n_max); + newPolarInitNode->N = nr_polar_output_length(newPolarInitNode->K, + newPolarInitNode->encoderLength, + newPolarInitNode->n_max); newPolarInitNode->n = log2(newPolarInitNode->N); newPolarInitNode->G_N = nr_polar_kronecker_power_matrices(newPolarInitNode->n); //polar_encoder vectors: @@ -182,9 +181,9 @@ void nr_polar_print_polarParams(t_nrPolar_params *polarParams) { return; } -t_nrPolar_params *nr_polar_params ( int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level) { +t_nrPolar_params *nr_polar_params (int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level) { static t_nrPolar_params *polarList = NULL; nr_polar_init(&polarList, messageType,messageLength,aggregation_level); t_nrPolar_params *polarParams=polarList; diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.h b/openair1/PHY/NR_TRANSPORT/nr_dci.h index 21fcd06c09..f53f5be282 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci.h +++ b/openair1/PHY/NR_TRANSPORT/nr_dci.h @@ -25,8 +25,6 @@ #include "PHY/defs_gNB.h" #include "PHY/NR_REFSIG/nr_refsig.h" -typedef unsigned __int128 uint128_t; - uint16_t nr_get_dci_size(nfapi_nr_dci_format_e format, nfapi_nr_rnti_type_e rnti_type, uint16_t N_RB, diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h index 06969eded0..102062f698 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h @@ -96,6 +96,8 @@ void free_gNB_dlsch(NR_gNB_DLSCH_t *dlsch); void clean_gNB_dlsch(NR_gNB_DLSCH_t *dlsch); +void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch); + int nr_dlsch_encoding(unsigned char *a, uint8_t subframe, NR_gNB_DLSCH_t *dlsch, diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index ace93e4ee3..bd6acb16d3 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -171,6 +171,104 @@ NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint8_t N_RB_UL, uint8 return(NULL); } +void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch) +{ + unsigned char i, j; + + if (ulsch) { + ulsch->harq_mask = 0; + ulsch->bundling = 0; + ulsch->beta_offset_cqi_times8 = 0; + ulsch->beta_offset_ri_times8 = 0; + ulsch->beta_offset_harqack_times8 = 0; + ulsch->Msg3_active = 0; + ulsch->Msg3_flag = 0; + ulsch->Msg3_subframe = 0; + ulsch->Msg3_frame = 0; + ulsch->rnti = 0; + ulsch->rnti_type = 0; + ulsch->cyclicShift = 0; + ulsch->cooperation_flag = 0; + ulsch->Mlimit = 0; + ulsch->max_ldpc_iterations = 0; + ulsch->last_iteration_cnt = 0; + ulsch->num_active_cba_groups = 0; + for (i=0;icba_rnti[i] = 0; + for (i=0;iharq_process_id[i] = 0; + + for (i=0; iharq_processes[i]){ + /// Nfapi ULSCH PDU + //nfapi_nr_ul_config_ulsch_pdu ulsch_pdu; + ulsch->harq_processes[i]->frame=0; + ulsch->harq_processes[i]->subframe=0; + ulsch->harq_processes[i]->round=0; + ulsch->harq_processes[i]->TPC=0; + ulsch->harq_processes[i]->mimo_mode=0; + ulsch->harq_processes[i]->dci_alloc=0; + ulsch->harq_processes[i]->rar_alloc=0; + ulsch->harq_processes[i]->status=0; + ulsch->harq_processes[i]->subframe_scheduling_flag=0; + ulsch->harq_processes[i]->subframe_cba_scheduling_flag=0; + ulsch->harq_processes[i]->phich_active=0; + ulsch->harq_processes[i]->phich_ACK=0; + ulsch->harq_processes[i]->previous_first_rb=0; + ulsch->harq_processes[i]->handled=0; + ulsch->harq_processes[i]->delta_TF=0; + + ulsch->harq_processes[i]->TBS=0; + /// Pointer to the payload (38.212 V15.4.0 section 5.1) + //uint8_t *b; + ulsch->harq_processes[i]->B=0; + /// Pointers to code blocks after code block segmentation and CRC attachment (38.212 V15.4.0 section 5.2.2) + //uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; + ulsch->harq_processes[i]->K=0; + ulsch->harq_processes[i]->F=0; + ulsch->harq_processes[i]->C=0; + /// Pointers to code blocks after LDPC coding (38.212 V15.4.0 section 5.3.2) + //int16_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC processing buffer + //t_nrLDPC_procBuf* p_nrLDPC_procBuf[MAX_NUM_NR_ULSCH_SEGMENTS]; + ulsch->harq_processes[i]->Z=0; + /// code blocks after bit selection in rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1) + //int16_t e[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; + ulsch->harq_processes[i]->E; + ulsch->harq_processes[i]->G; + + + ulsch->harq_processes[i]->n_DMRS=0; + ulsch->harq_processes[i]->n_DMRS2=0; + ulsch->harq_processes[i]->previous_n_DMRS=0; + + + ulsch->harq_processes[i]->cqi_crc_status=0; + for (j=0;jharq_processes[i]->o[j]=0; + ulsch->harq_processes[i]->uci_format=0; + ulsch->harq_processes[i]->Or1=0; + ulsch->harq_processes[i]->Or2=0; + ulsch->harq_processes[i]->o_RI[0]=0; ulsch->harq_processes[i]->o_RI[1]=0; + ulsch->harq_processes[i]->O_RI=0; + ulsch->harq_processes[i]->o_ACK[0]=0; ulsch->harq_processes[i]->o_ACK[1]=0; + ulsch->harq_processes[i]->o_ACK[2]=0; ulsch->harq_processes[i]->o_ACK[3]=0; + ulsch->harq_processes[i]->O_ACK=0; + ulsch->harq_processes[i]->V_UL_DAI=0; + /// "q" sequences for CQI/PMI (for definition see 36-212 V8.6 2009-03, p.27) + //int8_t q[MAX_CQI_PAYLOAD]; + ulsch->harq_processes[i]->o_RCC=0; + /// coded and interleaved CQI bits + //int8_t o_w[(MAX_CQI_BITS+8)*3]; + /// coded CQI bits + //int8_t o_d[96+((MAX_CQI_BITS+8)*3)]; + for (j=0;jharq_processes[i]->q_ACK[j]=0; + for (j=0;jharq_processes[i]->q_RI[j]=0; + /// Temporary h sequence to flag PUSCH_x/PUSCH_y symbols which are not scrambled + //uint8_t h[MAX_NUM_CHANNEL_BITS]; + /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) + //int16_t w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)]; + } + } + } +} uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, uint8_t UE_id, @@ -608,4 +706,4 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, ulsch->last_iteration_cnt = ret; return(ret); -} \ No newline at end of file +} diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 70a34f2c66..7abca59014 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -39,6 +39,7 @@ #include "PHY/CODING/nrLDPC_encoder/defs.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" #include "common/utils/LOG/vcd_signal_dumper.h" +#include "PHY/NR_TRANSPORT/nr_dlsch.h" @@ -92,7 +93,7 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u { NR_UE_ULSCH_t *ulsch; - unsigned char exit_flag = 0,i,j,r; + unsigned char exit_flag = 0,i,r; unsigned char bw_scaling =1; switch (N_RB_UL) { @@ -211,7 +212,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, uint32_t Tbslbrm; uint8_t nb_re_dmrs; uint16_t length_dmrs; - int i; float Coderate; /////////// diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 66eb0fada7..1cd268c3eb 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -32,7 +32,9 @@ #include "PHY/defs_gNB.h" #include "PHY/phy_extern.h" -#include "PHY/LTE_TRANSPORT/transport_proto.h" +//#include "PHY/LTE_TRANSPORT/transport_proto.h" +//#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED/sched_eNB.h" #include "SCHED/sched_common.h" #include "SCHED_NR/sched_nr.h" diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 1404fb79f4..b1502c7852 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -494,7 +494,7 @@ int main(int argc, char **argv) { unsigned char *test_input_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); unsigned int errors_bit = 0; test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + //estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index c9a8d58b04..4cdf4bed38 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -42,11 +42,13 @@ #include "PHY/MODULATION/modulation_UE.h" #include "PHY/INIT/phy_init.h" #include "PHY/NR_TRANSPORT/nr_transport.h" -//#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +//openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h #include "SCHED_NR/sched_nr.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include "SCHED_NR/fapi_nr_l1.h" +#include "SCHED_NR_UE/defs.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" @@ -58,6 +60,7 @@ #include "LAYER2/NR_MAC_UE/mac_proto.h" //#include "LAYER2/NR_MAC_gNB/mac_proto.h" //#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" +#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h" #include "RRC/NR/MESSAGES/asn1_msg.h" @@ -515,7 +518,7 @@ int main(int argc, char **argv) gNB_mac = RC.nrmac[0]; config_common(0,0,Nid_cell,78,ssb_pattern,(uint64_t)3640000000L,N_RB_DL); - config_nr_mib(0,0,1,kHz30,0,0,0,0); + config_nr_mib(0,0,1,kHz30,0,0,0,0,0); nr_l2_init_ue(); UE_mac = get_mac_inst(0); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index f9d157ace5..e485b4ba41 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -387,20 +387,20 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, // Note: This should not be done in the MAC! for (int ii=0; iiulsch[ii]; + NR_gNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii][0]; if((ulsch != NULL) && (ulsch->rnti == rnti)){ LOG_I(MAC, "clean_eNb_ulsch UE %x \n", rnti); - clean_eNb_ulsch(ulsch); + clean_gNB_ulsch(ulsch); } } for (int ii=0; iidlsch[ii][0]; - if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - LOG_E(PHY,"Calling with wrong paramter type\n"); - clean_eNb_dlsch(dlsch); - } + NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0]; + if((dlsch != NULL) && (dlsch->rnti == rnti)){ + LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); + LOG_E(PHY,"Calling with wrong parameter type\n"); + clean_gNB_dlsch(dlsch); + } } for(int j = 0; j < 10; j++){ diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 99452c4c7a..6d55ec8139 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -53,10 +53,12 @@ void config_nr_mib(int Mod_idP, void config_common(int Mod_idP, int CC_idP, + int Nid_cell, int nr_bandP, + uint64_t ssb_pattern, uint64_t dl_CarrierFreqP, uint32_t dl_BandwidthP - ); + ); int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, @@ -89,6 +91,10 @@ void nr_schedule_css_dlsch_phytest(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP); +void nr_schedule_uss_dlsch_phytest(module_id_t module_idP, + frame_t frameP, + sub_frame_t slotP); + void nr_configure_css_dci_initial(nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params, nr_scs_e scs_common, diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h index 6cd15fd32b..456f06a5ed 100644 --- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h @@ -171,8 +171,4 @@ 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__ */ From 0aec6f7aa17e0b4b7f640eac2157bba81b2d0457 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Sun, 14 Apr 2019 18:39:35 +0200 Subject: [PATCH 093/117] A couple minor warning removals --- openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c | 2 +- openair1/PHY/NR_TRANSPORT/nr_dlsch.h | 5 +++++ openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c index 1371cbee1a..9858f16cb0 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c @@ -36,7 +36,7 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" -#include " +#include //input [a_31 a_30 ... a_0] //output [f_31 f_30 ... f_0] [f_63 f_62 ... f_32] ... diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h index 102062f698..f5f1ba3d0a 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h @@ -67,6 +67,11 @@ void nr_pdsch_codeword_scrambling(uint8_t *in, uint32_t n_RNTI, uint32_t* out); +void nr_modulation(uint32_t *in, + uint16_t length, + nr_mod_t modulation_type, + int16_t *out); + void nr_pdsch_codeword_modulation(uint32_t *in, uint8_t Qm, uint32_t length, diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index bd6acb16d3..f9d8291423 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -232,8 +232,8 @@ void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch) ulsch->harq_processes[i]->Z=0; /// code blocks after bit selection in rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1) //int16_t e[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; - ulsch->harq_processes[i]->E; - ulsch->harq_processes[i]->G; + ulsch->harq_processes[i]->E=0; + ulsch->harq_processes[i]->G=0; ulsch->harq_processes[i]->n_DMRS=0; @@ -303,7 +303,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, int16_t z [68*384]; int8_t l [68*384]; - int16_t inv_d [68*384]; + //int16_t inv_d [68*384]; uint8_t kc; uint8_t Ilbrm = 0; uint32_t Tbslbrm = 950984; From 463164a4c393eef41492f901d847555ebe080bb4 Mon Sep 17 00:00:00 2001 From: Raymond Knopp Date: Sun, 14 Apr 2019 22:41:39 +0200 Subject: [PATCH 094/117] removal of unnecessary include files in fapi_nr_l1.h. --- openair1/SCHED_NR/fapi_nr_l1.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 1cd268c3eb..71ef6039f3 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -32,11 +32,6 @@ #include "PHY/defs_gNB.h" #include "PHY/phy_extern.h" -//#include "PHY/LTE_TRANSPORT/transport_proto.h" -//#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h -#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" -#include "SCHED/sched_eNB.h" -#include "SCHED/sched_common.h" #include "SCHED_NR/sched_nr.h" #include "nfapi_nr_interface.h" From 52a420bbede64ab986327fb13568e55c84b45d58 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Thu, 11 Apr 2019 22:45:42 +0200 Subject: [PATCH 095/117] increasing NB_PATTERN_FILES in ci script to account for new smallblocktest --- ci-scripts/oai-ci-vm-tool | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool index ed43e26729..3d9fb87cba 100755 --- a/ci-scripts/oai-ci-vm-tool +++ b/ci-scripts/oai-ci-vm-tool @@ -252,7 +252,7 @@ case $key in VM_NAME=ci-phy-sim ARCHIVES_LOC=phy_sim LOG_PATTERN=.Rel15.txt - NB_PATTERN_FILES=9 + NB_PATTERN_FILES=10 BUILD_OPTIONS="--phy_simulators" VM_MEMORY=8192 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" @@ -331,7 +331,7 @@ case $key in VM_NAME=ci-phy-sim ARCHIVES_LOC=phy_sim LOG_PATTERN=.Rel15.txt - NB_PATTERN_FILES=9 + NB_PATTERN_FILES=10 BUILD_OPTIONS="--phy_simulators" VM_MEMORY=8192 RUN_OPTIONS="./run_exec_autotests.bash -g \"01510*\" -q -np -b" From 2624dca2fe0ed174e2cfe621396de3f39ec4a1cc Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Fri, 12 Apr 2019 02:56:31 +0200 Subject: [PATCH 096/117] fixing test_case_list --- cmake_targets/autotests/test_case_list.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index a6c2a97056..792e46cec6 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1123,6 +1123,11 @@ (Test2: 6 bits), (Test3: 7 bits), (Test4: 11 bits) + + $OPENAIR_DIR/cmake_targets/build_oai + --phy_simulators -c + $OPENAIR_DIR/cmake_targets/autotests/tools/free_mem.bash + $OPENAIR_DIR/targets/bin/smallblocktest.Rel15 -l 3 -s -4 -d 1 -i 10000 -l 6 -s -4 -d 1 -i 10000 @@ -1135,7 +1140,7 @@ - + execution nr_ulschsim Test cases. (Test1: 106 PRB), (Test2: 217 PRB), From 75f131ad540b7644c829924aee79311249da3a72 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Mon, 15 Apr 2019 21:49:28 +0200 Subject: [PATCH 097/117] --phy_simulators warning removals, except for nr_dlsim. Polar coding old implementation's approximation and a priori information options needs to be corrected or removed --- openair1/PHY/CODING/TESTBENCH/polartest.c | 71 ++++++++++++++----- .../nrPolar_tools/nr_polar_decoding_tools.c | 10 +-- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 13 +++- openair1/PHY/INIT/lte_init_ue.c | 4 +- openair1/PHY/INIT/nr_init_ue.c | 6 +- openair1/PHY/LTE_UE_TRANSPORT/transport_ue.h | 2 +- openair1/PHY/NR_TRANSPORT/nr_dci.c | 1 + openair1/PHY/NR_TRANSPORT/nr_dci_tools.c | 3 +- openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 10 +-- openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c | 9 +-- openair1/PHY/NR_UE_TRANSPORT/dci_nr.c | 8 +-- .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 2 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 22 +++--- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 15 ++++ .../PHY/NR_UE_TRANSPORT/nr_transport_ue.h | 2 +- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 11 +-- openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c | 12 ++-- openair1/SIMULATION/NR_PHY/dlschsim.c | 43 +++++------ openair1/SIMULATION/NR_PHY/pbchsim.c | 50 ++++++------- openair1/SIMULATION/NR_PHY/ulschsim.c | 37 +++++----- openair2/LAYER2/MAC/config_ue.c | 3 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 1 + 22 files changed, 201 insertions(+), 134 deletions(-) diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index 49e71abbc9..32371df315 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -26,12 +26,13 @@ int main(int argc, char *argv[]) { double SNR, SNR_lin; int16_t nBitError = 0; // -1 = Decoding failed (All list entries have failed the CRC checks). uint32_t decoderState=0, blockErrorState=0; //0 = Success, -1 = Decoding failed, 1 = Block Error. - uint16_t testLength = NR_POLAR_PBCH_PAYLOAD_BITS, coderLength = NR_POLAR_PBCH_E, blockErrorCumulative=0, bitErrorCumulative=0; + uint16_t testLength = NR_POLAR_PBCH_PAYLOAD_BITS, coderLength = NR_POLAR_PBCH_E; + uint16_t blockErrorCumulative=0, bitErrorCumulative=0, aPrioriLength=0; double timeEncoderCumulative = 0, timeDecoderCumulative = 0; - uint8_t aggregation_level = 8, decoderListSize = 8, pathMetricAppr = 0, logFlag = 0; + uint8_t aggregation_level = 8, decoderListSize = 8, pathMetricAppr = 0, logFlag = 0, aPrioriFlag=0; uint16_t rnti=0; - while ((arguments = getopt (argc, argv, "s:d:f:m:i:l:a:hqgFL:K:")) != -1) + while ((arguments = getopt (argc, argv, "s:d:f:m:i:l:a:p:hqgFL:k:")) != -1) switch (arguments) { case 's': SNRstart = atof(optarg); @@ -63,6 +64,8 @@ int main(int argc, char *argv[]) { pathMetricAppr = (uint8_t) atoi(optarg); break; + + case 'q': decoder_int16 = 1; break; @@ -86,7 +89,7 @@ int main(int argc, char *argv[]) { } break; - case 'K': + case 'k': testLength=atoi(optarg); if (testLength < 12 || testLength > 60) { printf("Illegal packet bitlength %d \n",testLength); @@ -94,10 +97,19 @@ int main(int argc, char *argv[]) { } break; + case 'p': + aPrioriLength = (uint8_t) atoi(optarg); + if (aPrioriLength > testLength){ + printf("A priori information(%d) cannot be larger than test length(%d)\n",aPrioriLength, testLength); + exit(-1); + } + aPrioriFlag = 1; + break; + case 'h': printf("./polartest\nOptions\n-h Print this help\n-s SNRstart (dB)\n-d SNRinc (dB)\n-f SNRstop (dB)\n-m [0=PBCH|1=DCI|2=UCI]\n" "-i Number of iterations\n-l decoderListSize\n-a pathMetricAppr\n-q Flag for optimized coders usage\n-F Flag for test results logging\n" - "-L aggregation level (for DCI)\n-K packet_length (bits) for DCI/UCI\n"); + "-L aggregation level (for DCI)\n-k packet_length (bits) for DCI/UCI\n-p (Only for PBCH for now) A priori information length used in polar decoder\n"); exit(-1); break; @@ -171,6 +183,12 @@ if (logFlag){ double modulatedInput[coderLength]; //channel input double channelOutput[coderLength]; //add noise int16_t channelOutput_int16[coderLength]; + + //A priori knowledge about the payload is assumed according to "aPrioriFlag". + double aPrioriArray[testLength]; + uint8_t testInputByte[testLength]; + uint16_t aPrioriInd[aPrioriLength]; + t_nrPolar_params *currentPtr = nr_polar_params(polarMessageType, testLength, aggregation_level); #ifdef DEBUG_DCI_POLAR_PARAMS @@ -214,11 +232,6 @@ if (logFlag){ return 0; #endif - // We assume no a priori knowledge available about the payload. - double aPrioriArray[currentPtr->payloadBits]; - - for (int i=0; ipayloadBits; i++) aPrioriArray[i] = NAN; - for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { printf("SNR %f\n",SNR); SNR_lin = pow(10, SNR/10); @@ -232,10 +245,22 @@ if (logFlag){ } testInput[i] |= ( ((uint32_t) (rand()%2)) &1); } + //Generate random a priori information in "aPrioriArray", if "aPrioriFlag" is set. + if (aPrioriFlag){ + nr_bit2byte_uint32_8(testInput, testLength, testInputByte); + for (int i=0; i0x%08x\n", testInput[0]); - //for (int i=0; i<32; i++) printf("%d-",(testInput[0]>>i)&1); printf("\n"); + for (int i=0; i<32; i++) printf("testInput:%d-testInputByte:%d-aPrioriArray:%f\n",(testInput[0]>>i)&1, testInputByte[i], aPrioriArray[i]); #endif int len_mod64=currentPtr->payloadBits&63; ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)< PBCH, 1 --> DCI, -1 --> UCI - if (polarMessageType == 0) - decoderState = polar_decoder(channelOutput, - estimatedOutput, - currentPtr, - decoderListSize, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION); - else if (polarMessageType == 1) + if (polarMessageType == 0) { + if (aPrioriFlag) { + decoderState = polar_decoder_aPriori(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, + aPrioriArray); + } else { + decoderState = polar_decoder(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION); + } + } else if (polarMessageType == 1) { decoderState = polar_decoder_dci(channelOutput, estimatedOutput, currentPtr, decoderListSize, NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, rnti); + } } stop_meas(&timeDecoder); diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index 38f78bc47b..11aa5d98a4 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -97,12 +97,12 @@ void updatePathMetric(double *pathMetric, uint8_t approximation) { if (approximation) { //eq. (12) - for (uint8_t i=0; ialpha; int16_t *alpha_l=node->left->alpha; int16_t *betal = node->left->beta; @@ -390,7 +390,7 @@ void applyFtoleft(t_nrPolar_params *pp, decoder_node_t *node) { } } -void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) { +void applyGtoright(const t_nrPolar_params *pp,decoder_node_t *node) { int16_t *alpha_v=node->alpha; int16_t *alpha_r=node->right->alpha; @@ -461,7 +461,7 @@ void applyGtoright(t_nrPolar_params *pp,decoder_node_t *node) { int16_t all1[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; -void computeBeta(t_nrPolar_params *pp,decoder_node_t *node) { +void computeBeta(const t_nrPolar_params *pp,decoder_node_t *node) { int16_t *betav = node->beta; int16_t *betal = node->left->beta; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index b104e550c6..68e7543d5d 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -175,8 +175,17 @@ int8_t polar_decoder_dci(double *input, uint8_t pathMetricAppr, uint16_t n_RNTI); -void generic_polar_decoder(const t_nrPolar_params *, - decoder_node_t *); +void generic_polar_decoder(const t_nrPolar_params *pp, + decoder_node_t *node); + +void applyFtoleft(const t_nrPolar_params *pp, + decoder_node_t *node); + +void applyGtoright(const t_nrPolar_params *pp, + decoder_node_t *node); + +void computeBeta(const t_nrPolar_params *pp, + decoder_node_t *node); void build_decoder_tree(t_nrPolar_params *pp); void build_polar_tables(t_nrPolar_params *polarParams); diff --git a/openair1/PHY/INIT/lte_init_ue.c b/openair1/PHY/INIT/lte_init_ue.c index bcdd782073..9c9d67bdc2 100644 --- a/openair1/PHY/INIT/lte_init_ue.c +++ b/openair1/PHY/INIT/lte_init_ue.c @@ -355,7 +355,9 @@ void phy_config_dedicated_scell_ue(uint8_t Mod_id, #endif -void phy_config_harq_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id, +void phy_config_harq_ue(module_id_t Mod_id, + int CC_id, + uint8_t eNB_id, uint16_t max_harq_tx ) { diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c index b2be51f6a2..f5f6ca1523 100644 --- a/openair1/PHY/INIT/nr_init_ue.c +++ b/openair1/PHY/INIT/nr_init_ue.c @@ -357,8 +357,10 @@ void phy_config_dedicated_scell_ue(uint8_t Mod_id, } #endif -void phy_config_harq_ue(module_id_t Mod_id,int CC_id,uint8_t eNB_id, - uint16_t max_harq_tx ) +void phy_config_harq_ue(module_id_t Mod_id, + int CC_id, + uint8_t eNB_id, + uint16_t max_harq_tx) { int num_of_threads,num_of_code_words; diff --git a/openair1/PHY/LTE_UE_TRANSPORT/transport_ue.h b/openair1/PHY/LTE_UE_TRANSPORT/transport_ue.h index 98e6f90a53..4c433a5683 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/transport_ue.h +++ b/openair1/PHY/LTE_UE_TRANSPORT/transport_ue.h @@ -194,7 +194,7 @@ typedef struct { /// allocated CBA RNTI uint16_t cba_rnti[4];//NUM_MAX_CBA_GROUP]; /// UL max-harq-retransmission - uint8_t Mlimit; + uint16_t Mlimit; } LTE_UE_ULSCH_t; diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.c b/openair1/PHY/NR_TRANSPORT/nr_dci.c index 929ac823dd..15e31d9728 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci.c @@ -31,6 +31,7 @@ */ #include "nr_dci.h" +#include "nr_dlsch.h" //#define DEBUG_PDCCH_DMRS //#define DEBUG_DCI diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c index e4bec93ddf..dd11cd7867 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c @@ -64,8 +64,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m } if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) { - AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n", - N_reg, bsize, R); + AssertFatal((N_reg%(bsize*R))==0,"CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n",N_reg, bsize, R); C = N_reg/(bsize*R); } diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c index 50e836fe58..0a2927d881 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c @@ -282,8 +282,8 @@ int nr_dlsch_encoding(unsigned char *a, uint32_t A, Z, F=0; uint32_t *pz = &Z; uint8_t mod_order = rel15.modulation_order; - uint16_t Kr=0,r,r_offset=0,Kr_bytes; - uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; + uint16_t Kr=0,r,r_offset=0; + //uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; uint8_t BG=1; uint32_t E; uint8_t Ilbrm = 0; @@ -354,13 +354,16 @@ int nr_dlsch_encoding(unsigned char *a, } Kr = dlsch->harq_processes[harq_pid]->K; +#ifdef DEBUG_DLSCH_CODING + uint16_t Kr_bytes; Kr_bytes = Kr>>3; +#endif //printf("segment Z %d k %d Kr %d BG %d\n", *pz,dlsch->harq_processes[harq_pid]->K,Kr,BG); //start_meas(te_stats); for (r=0; rharq_processes[harq_pid]->C; r++) { - d_tmp[r] = &dlsch->harq_processes[harq_pid]->d[r][0]; + //d_tmp[r] = &dlsch->harq_processes[harq_pid]->d[r][0]; //channel_input[r] = &dlsch->harq_processes[harq_pid]->d[r][0]; #ifdef DEBUG_DLSCH_CODING printf("Encoder: B %d F %d \n",dlsch->harq_processes[harq_pid]->B, dlsch->harq_processes[harq_pid]->F); @@ -393,7 +396,6 @@ int nr_dlsch_encoding(unsigned char *a, //stop_meas(te_stats); //printf("end ldpc encoder -- output\n"); - //write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); #ifdef DEBUG_DLSCH_CODING write_output("enc_input0.m","enc_in0",&dlsch->harq_processes[harq_pid]->c[0][0],Kr_bytes,1,4); write_output("enc_output0.m","enc0",&dlsch->harq_processes[harq_pid]->d[0][0],(3*8*Kr_bytes)+12,1,4); diff --git a/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c b/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c index 9fb73fa994..83d0d72b28 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_tbs_tools.c @@ -112,12 +112,9 @@ void nr_get_tbs(nfapi_nr_dl_config_dlsch_pdu *dlsch_pdu, nfapi_nr_dl_config_pdcch_parameters_rel15_t params_rel15 = dci_pdu.pdcch_params_rel15; nfapi_nr_dl_config_dlsch_pdu_rel15_t *dlsch_rel15 = &dlsch_pdu->dlsch_pdu_rel15; uint8_t rnti_type = params_rel15.rnti_type; - uint8_t dci_format = params_rel15.dci_format; - uint8_t ss_type = params_rel15.search_space_type; uint8_t N_PRB_oh = ((rnti_type==NFAPI_NR_RNTI_SI)||(rnti_type==NFAPI_NR_RNTI_RA)||(rnti_type==NFAPI_NR_RNTI_P))? 0 : \ (config.pdsch_config.x_overhead.value); uint8_t N_PRB_DMRS = (config.pdsch_config.dmrs_type.value == NFAPI_NR_DMRS_TYPE1)?6:4; //This only works for antenna port 1000 - uint8_t mcs_table = config.pdsch_config.mcs_table.value; uint8_t N_sh_symb = dlsch_rel15->nb_symbols; uint8_t Imcs = dlsch_rel15->mcs_idx; uint16_t N_RE_prime = NR_NB_SC_PER_RB*N_sh_symb - N_PRB_DMRS - N_PRB_oh; @@ -126,7 +123,11 @@ void nr_get_tbs(nfapi_nr_dl_config_dlsch_pdu *dlsch_pdu, uint16_t N_RE, Ninfo, Ninfo_prime, C, TBS=0, R; uint8_t table_idx, Qm, n, scale; - table_idx = 1; //get_table_idx(mcs_table, dci_format, rnti_type, ss_type); + /*uint8_t mcs_table = config.pdsch_config.mcs_table.value; + uint8_t ss_type = params_rel15.search_space_type; + uint8_t dci_format = params_rel15.dci_format; + get_table_idx(mcs_table, dci_format, rnti_type, ss_type);*/ + table_idx = 1; scale = ((table_idx==2)&&((Imcs==20)||(Imcs==26)))?11:10; N_RE = min(156, N_RE_prime)*dlsch_rel15->n_prb; diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index f01a5ef60a..9b309983b1 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -332,7 +332,9 @@ void nr_pdcch_extract_rbs_single(int32_t **rxdataF, //uint8_t rb_count_bit; uint8_t i, j, aarx, bitcnt_coreset_freq_dom=0; int32_t *dl_ch0, *dl_ch0_ext, *rxF, *rxF_ext; +#ifdef NR_PDCCH_DCI_DEBUG int nushiftmod3 = frame_parms->nushift % 3; +#endif uint8_t symbol_mod; symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol; c_rb = n_BWP_start; // c_rb is the common resource block: RB within the BWP @@ -809,8 +811,6 @@ int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue, // indicates the number of active CORESETs for the current BWP to decode PDCCH: max is 3 (this variable is not useful here, to be removed) //uint8_t coreset_nbr_act; // indicates the number of REG contained in the PDCCH (number of RBs * number of symbols, in CORESET) - uint8_t coreset_nbr_reg; - uint32_t coreset_C; uint32_t coreset_nbr_rb = 0; // for (int j=0; j < coreset_nbr_act; j++) { // for each active CORESET (max number of active CORESETs in a BWP is 3), @@ -829,9 +829,9 @@ int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue, #ifdef NR_PDCCH_DCI_DEBUG printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_freq_dom=(%ld,%lx), coreset_nbr_rb=%d\n", coreset_freq_dom,coreset_freq_dom,coreset_nbr_rb); #endif - coreset_nbr_reg = coreset_time_dur * coreset_nbr_rb; - coreset_C = (uint32_t)(coreset_nbr_reg / (reg_bundle_size_L * coreset_interleaver_size_R)); #ifdef NR_PDCCH_DCI_DEBUG + uint8_t coreset_nbr_reg = coreset_time_dur * coreset_nbr_rb; + uint32_t coreset_C = (uint32_t)(coreset_nbr_reg / (reg_bundle_size_L * coreset_interleaver_size_R)); printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_nbr_rb=%d, coreset_nbr_reg=%d, coreset_C=(%d/(%d*%d))=%d\n", coreset_nbr_rb, coreset_nbr_reg, coreset_nbr_reg, reg_bundle_size_L,coreset_interleaver_size_R, coreset_C); #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index e56ccd8af7..f534c2d543 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -231,7 +231,7 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, int16_t z [68*384]; int8_t l [68*384]; //__m128i l; - int16_t inv_d [68*384]; + //int16_t inv_d [68*384]; uint8_t kc; uint8_t Ilbrm = 0; uint32_t Tbslbrm = 950984; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index c99d2ea61b..6bdd153aa5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -1118,9 +1118,10 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, if (rx_type==rx_IC_dual_stream) { nr_dlsch_layer_demapping(pdsch_vars[eNB_id]->llr, - dlsch[0]->harq_processes[harq_pid]->Nl, - dlsch[0]->harq_processes[harq_pid]->G, - pdsch_vars[eNB_id]->layer_llr); + dlsch[0]->harq_processes[harq_pid]->Nl, + dlsch[0]->harq_processes[harq_pid]->Qm, + dlsch[0]->harq_processes[harq_pid]->G, + pdsch_vars[eNB_id]->layer_llr); } #if UE_TIMING_TRACE @@ -2590,17 +2591,18 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, int prb,nb_rb=0; unsigned short k; //int prb_off,prb_off2; - int skip_half=0,l;//sss_symb,pss_symb=0,nsymb + //int skip_half=0,l,sss_symb,pss_symb=0,nsymb; int i,aarx; int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; - int symbol_mod,pilots=0,j=0; - unsigned char *pmi_loc; + int pilots=0,j=0; + //int symbol_mod; + //unsigned char *pmi_loc; pilots = (symbol==2) ? 1 : 0; //to updated from config k = frame_parms->first_carrier_offset + 516; //0 //nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; - l=symbol; + //l=symbol; for (aarx=0; aarxnb_antennas_rx; aarx++) { @@ -2612,7 +2614,7 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, dl_ch1 = &dl_ch_estimates[2+aarx][0]; } - pmi_loc = pmi_ext; + //pmi_loc = pmi_ext; // pointers to extracted RX signals and channel estimates rxF_ext = &rxdataF_ext[aarx][symbol*(nb_rb_pdsch*12)]; @@ -2620,13 +2622,13 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, dl_ch1_ext = &dl_ch_estimates_ext[2+aarx][symbol*(nb_rb_pdsch*12)]; for (prb=0; prbN_RB_DL; prb++) { - skip_half=0; + //skip_half=0; if ((frame_parms->N_RB_DL&1) == 0) { // even number of RBs // For second half of RBs skip DC carrier if (k>=frame_parms->ofdm_symbol_size) { - rxF = &rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))]; + rxF = &rxdataF[aarx][(symbol*(frame_parms->ofdm_symbol_size))]; k=k-(frame_parms->ofdm_symbol_size); } 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 48cf637529..ae6716711c 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1793,6 +1793,21 @@ int nr_extract_dci_info(PHY_VARS_NR_UE *ue, uint16_t n_RB_DLBWP, uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES]); +void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, + int **dl_ch_estimates_ext_i, + int **dl_ch_rho_ext, + unsigned char n_tx, + unsigned char n_rx, + unsigned char output_shift, + int length, + int start_point); + +void nr_dlsch_layer_demapping(int16_t **llr_cw, + uint8_t Nl, + uint8_t mod_order, + uint16_t length, + int16_t **llr_layers); + /**@}*/ #endif diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h index 2facd85bab..7d2abd9993 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h @@ -246,7 +246,7 @@ typedef struct { /// allocated CBA RNTI //uint16_t cba_rnti[4];//NUM_MAX_CBA_GROUP]; /// UL max-harq-retransmission - uint8_t Mlimit; + uint16_t Mlimit; } NR_UE_ULSCH_t; typedef struct { diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 7abca59014..95ca86959f 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -204,8 +204,8 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, uint32_t A, Z, F; uint32_t *pz; uint8_t mod_order; - uint16_t Kr,r,r_offset,Kr_bytes; - uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; + uint16_t Kr,r,r_offset; + //uint8_t *d_tmp[MAX_NUM_DLSCH_SEGMENTS]; uint8_t BG; uint32_t E; uint8_t Ilbrm; @@ -311,8 +311,10 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, } Kr = harq_process->K; +#ifdef DEBUG_DLSCH_CODING + uint16_t Kr_bytes; Kr_bytes = Kr>>3; - +#endif /////////// ///////////////////////////////////////////////////////////////////////////////////// @@ -325,7 +327,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, //start_meas(te_stats); for (r=0; rC; r++) { - d_tmp[r] = &harq_process->d[r][0]; + //d_tmp[r] = &harq_process->d[r][0]; //channel_input[r] = &harq_process->d[r][0]; #ifdef DEBUG_DLSCH_CODING printf("Encoder: B %d F %d \n",harq_process->B, harq_process->F); @@ -357,7 +359,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, //stop_meas(te_stats); //printf("end ldpc encoder -- output\n"); - //write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); #ifdef DEBUG_DLSCH_CODING write_output("ulsch_enc_input0.m","enc_in0",&harq_process->c[0][0],Kr_bytes,1,4); write_output("ulsch_enc_output0.m","enc0",&harq_process->d[0][0],(3*8*Kr_bytes)+12,1,4); diff --git a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c index 2327a5036b..41b055a7ff 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c @@ -990,7 +990,7 @@ void nr_uci_encoding(uint64_t payload, // A is the payload size, to be provided in function call uint8_t A = nr_bit; // L is the CRC size - uint8_t L; + //uint8_t L; // E is the rate matching output sequence length as given in TS 38.212 subclause 6.3.1.4.1 uint16_t E=0,E_init; @@ -1047,7 +1047,7 @@ void nr_uci_encoding(uint64_t payload, } *M_bit = E; - int I_seg; + //int I_seg; #ifdef DEBUG_NR_PUCCH_TX printf("\t\t [nr_uci_encoding] start function with fmt=%d, encoding A=%d bits into M_bit=%d (where nrofSymbols=%d,nrofPRB=%d)\n",fmt,A,*M_bit,nrofSymbols,nrofPRB); #endif @@ -1057,19 +1057,19 @@ void nr_uci_encoding(uint64_t payload, // CRC bits are not attached, and coding small block lengths (subclause 5.3.3) } else if (A>=12) { // procedure in subclause 6.3.1.2.1 (UCI encoded by Polar code -> subclause 6.3.1.3.1) - if ((A>=360 && E>=1088)||(A>=1013)) { + /*if ((A>=360 && E>=1088)||(A>=1013)) { I_seg = 1; } else { I_seg = 0; - } + }*/ - if (A>=20) { + /*if (A>=20) { // parity bits (subclause 5.2.1) computed by setting L=11 and using generator polynomial gCRC11(D) (subclause 5.1) L=11; } else if (A<=19) { // parity bits (subclause 5.2.1) computed by setting L=6 and using generator polynomial gCRC6(D) (subclause 5.1) L=6; - } + }*/ // code block segmentation and CRC attachment is performed according to subclause 5.2.1 // polar coding subclause 5.3.1 diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 76cd243b36..1a7a91f625 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -131,21 +131,22 @@ int main(int argc, char **argv) { // int sync_pos, sync_pos_slot; // FILE *rx_frame_file; FILE *output_fd = NULL; - uint8_t write_output_file = 0; + //uint8_t write_output_file = 0; // int subframe_offset; // char fname[40], vname[40]; int trial, n_trials = 1, n_errors = 0, n_false_positive = 0; - uint8_t transmission_mode = 1, n_tx = 1, n_rx = 1; + uint8_t n_tx = 1, n_rx = 1; + //uint8_t transmission_mode = 1; uint16_t Nid_cell = 0; channel_desc_t *gNB2UE; uint8_t extended_prefix_flag = 0; - int8_t interf1 = -21, interf2 = -21; + //int8_t interf1 = -21, interf2 = -21; FILE *input_fd = NULL, *pbch_file_fd = NULL; //char input_val_str[50],input_val_str2[50]; //uint16_t NB_RB=25; SCM_t channel_model = AWGN; //Rayleigh1_anticorr; uint16_t N_RB_DL = 106, mu = 1; - unsigned char frame_type = 0; + //unsigned char frame_type = 0; unsigned char pbch_phase = 0; int frame = 0, subframe = 0; int frame_length_complex_samples; @@ -176,7 +177,7 @@ int main(int argc, char **argv) { while ((c = getopt(argc, argv, "df:hpg:i:j:n:l:m:r:s:S:y:z:M:N:F:R:P:L:")) != -1) { switch (c) { - case 'f': + /*case 'f': write_output_file = 1; output_fd = fopen(optarg, "w"); @@ -185,11 +186,11 @@ int main(int argc, char **argv) { exit(-1); } - break; + break;*/ - case 'd': + /*case 'd': frame_type = 1; - break; + break;*/ case 'g': switch ((char) *optarg) { @@ -228,13 +229,13 @@ int main(int argc, char **argv) { break; - case 'i': + /*case 'i': interf1 = atoi(optarg); break; case 'j': interf2 = atoi(optarg); - break; + break;*/ case 'n': n_trials = atoi(optarg); @@ -331,33 +332,33 @@ int main(int argc, char **argv) { nb_rb = atoi(optarg); break; - case 'x': + /*case 'x': transmission_mode = atoi(optarg); - break; + break;*/ default: case 'h': printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); printf("-h This message\n"); printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); + //printf("-d Use TDD\n"); printf("-n Number of frames to simulate\n"); printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); printf("-S Ending SNR, runs from SNR0 to SNR1\n"); printf("-t Delay spread for multipath channel\n"); printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); + //printf("-x Transmission mode (1,2,6 for the moment)\n"); printf("-y Number of TX antennas used in eNB\n"); printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-M Multiple SSB positions in burst\n"); + //printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + //printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-M Multiple SSB positions in burst\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); + //printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + //printf("-f Output filename (.txt format) for Pe/SNR results\n"); printf("-F Input filename (.txt format) for RX conformance testing\n"); exit(-1); break; @@ -493,7 +494,7 @@ int main(int argc, char **argv) { short *channel_output_fixed = malloc16(sizeof(short) * 16 * 68 * 384); short *channel_output_uncoded = malloc16(sizeof(unsigned short) * 16 * 68 * 384); double errors_bit_uncoded = 0; - unsigned char *estimated_output; + //unsigned char *estimated_output; unsigned char *estimated_output_bit; unsigned char *test_input_bit; unsigned int errors_bit = 0; @@ -514,7 +515,7 @@ int main(int argc, char **argv) { for (i = 0; i < TBS / 8; i++) test_input[i] = (unsigned char) rand(); - estimated_output = harq_process->b; + //estimated_output = harq_process->b; #ifdef DEBUG_DLSCHSIM for (i = 0; i < TBS / 8; i++) printf("test_input[i]=%d \n",test_input[i]); diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 61d4c486f5..4664af3b67 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -92,13 +92,13 @@ int main(int argc, char **argv) uint8_t snr1set=0; int **txdata; double **s_re,**s_im,**r_re,**r_im; - double iqim = 0.0; + //double iqim = 0.0; double ip =0.0; - unsigned char pbch_pdu[6]; + //unsigned char pbch_pdu[6]; // int sync_pos, sync_pos_slot; // FILE *rx_frame_file; FILE *output_fd = NULL; - uint8_t write_output_file=0; + //uint8_t write_output_file=0; //int result; //int freq_offset; // int subframe_offset; @@ -110,8 +110,8 @@ int main(int argc, char **argv) channel_desc_t *gNB2UE; - uint8_t extended_prefix_flag=0; - int8_t interf1=-21,interf2=-21; + //uint8_t extended_prefix_flag=0; + //int8_t interf1=-21,interf2=-21; FILE *input_fd=NULL,*pbch_file_fd=NULL; @@ -126,7 +126,7 @@ int main(int argc, char **argv) int N_RB_DL=273,mu=1; - unsigned char frame_type = 0; + //unsigned char frame_type = 0; unsigned char pbch_phase = 0; int frame=0; @@ -152,7 +152,7 @@ int main(int argc, char **argv) while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:o:s:S:t:x:y:z:M:N:F:GR:dP:IL:")) != -1) { switch (c) { - case 'f': + /*case 'f': write_output_file=1; output_fd = fopen(optarg,"w"); @@ -161,11 +161,11 @@ int main(int argc, char **argv) exit(-1); } - break; + break;*/ - case 'd': + /*case 'd': frame_type = 1; - break; + break;*/ case 'g': switch((char)*optarg) { @@ -204,13 +204,13 @@ int main(int argc, char **argv) break; - case 'i': + /*case 'i': interf1=atoi(optarg); break; case 'j': interf2=atoi(optarg); - break; + break;*/ case 'n': n_trials = atoi(optarg); @@ -237,9 +237,9 @@ int main(int argc, char **argv) Td= atof(optarg); break; */ - case 'p': + /*case 'p': extended_prefix_flag=1; - break; + break;*/ /* case 'r': @@ -326,8 +326,8 @@ int main(int argc, char **argv) printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); printf("-h This message\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); + //printf("-p Use extended prefix mode\n"); + //printf("-d Use TDD\n"); printf("-n Number of frames to simulate\n"); printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); printf("-S Ending SNR, runs from SNR0 to SNR1\n"); @@ -336,16 +336,16 @@ int main(int argc, char **argv) printf("-x Transmission mode (1,2,6 for the moment)\n"); printf("-y Number of TX antennas used in eNB\n"); printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + //printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + //printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); printf("-o Carrier frequency offset in Hz\n"); printf("-M Multiple SSB positions in burst\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); + //printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + //printf("-f Output filename (.txt format) for Pe/SNR results\n"); printf("-F Input filename (.txt format) for RX conformance testing\n"); exit (-1); break; @@ -537,10 +537,9 @@ int main(int argc, char **argv) if (output_fd) fwrite(txdata[0],sizeof(int32_t),frame_length_complex_samples,output_fd); - int txlev = signal_energy(&txdata[0][5*frame_parms->ofdm_symbol_size + 4*frame_parms->nb_prefix_samples + frame_parms->nb_prefix_samples0], - frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples); - - // printf("txlev %d (%f)\n",txlev,10*log10(txlev)); + /*int txlev = signal_energy(&txdata[0][5*frame_parms->ofdm_symbol_size + 4*frame_parms->nb_prefix_samples + frame_parms->nb_prefix_samples0], + frame_parms->ofdm_symbol_size + frame_parms->nb_prefix_samples); + printf("txlev %d (%f)\n",txlev,10*log10(txlev));*/ for (i=0; iul_SCH_Config->retxBSR_Timer) { UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer = diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index cbbd4fcd15..bf07051507 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -48,6 +48,7 @@ #include "pdcp.h" #include "openair1/PHY/defs_gNB.h" +#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h" //Agent-related headers #include "flexran_agent_extern.h" From 5fa78b4d6e4d048f9ead364066614c423b6134bc Mon Sep 17 00:00:00 2001 From: yilmazt Date: Tue, 16 Apr 2019 17:24:58 +0200 Subject: [PATCH 098/117] Final --phy_simulators warning removals for this branch, and former polar coding function corrections --- common/utils/LOG/log.h | 6 +- openair1/PHY/CODING/TESTBENCH/polartest.c | 69 +---- .../PHY/CODING/TESTBENCH/smallblocktest.c | 12 +- openair1/PHY/CODING/crc_byte.c | 2 +- .../CODING/nrPolar_tools/nr_polar_decoder.c | 292 +----------------- .../nrPolar_tools/nr_polar_decoding_tools.c | 70 ++--- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 24 +- openair1/PHY/NR_TRANSPORT/nr_dci_tools.c | 5 +- openair1/PHY/defs_nr_common.h | 1 - openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 6 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 128 ++++---- .../SCHED_NR_UE/pucch_power_control_ue_nr.c | 25 +- openair1/SIMULATION/NR_PHY/dlsim.c | 65 ++-- openair2/GNB_APP/gnb_config.c | 6 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 27 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 2 +- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 4 +- openair2/RRC/NR/L2_nr_interface.c | 1 - openair2/RRC/NR/rrc_gNB.c | 15 +- 19 files changed, 209 insertions(+), 551 deletions(-) diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 8390c3af25..b8a72ece7b 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -83,11 +83,11 @@ extern "C" { * @brief LOG defines 9 levels of messages for users. Importance of these levels decrease gradually from 0 to 8 * @{*/ # define OAILOG_DISABLE -1 /*!< \brief disable all LOG messages, cannot be used in LOG macros, use only in LOG module */ -# define OAILOG_ERR 0 /*!< \brief critical error conditions, impact on "must have" fuctinalities */ +# define OAILOG_ERR 0 /*!< \brief critical error conditions, impact on "must have" functionalities */ # define OAILOG_WARNING 1 /*!< \brief warning conditions, shouldn't happen but doesn't impact "must have" functionalities */ # define OAILOG_INFO 2 /*!< \brief informational messages most people don't need, shouldn't impact real-time behavior */ -# define OAILOG_DEBUG 3 /*!< \brief first level debug-level messages, for developers , may impact real-time behavior */ -# define OAILOG_TRACE 4 /*!< \brief second level debug-level messages, for developers ,likely impact real-time behavior*/ +# define OAILOG_DEBUG 3 /*!< \brief first level debug-level messages, for developers, may impact real-time behavior */ +# define OAILOG_TRACE 4 /*!< \brief second level debug-level messages, for developers, likely impact real-time behavior*/ #define NUM_LOG_LEVEL 5 /*!< \brief the number of message levels users have with LOG (OAILOG_DISABLE is not available to user as a level, so it is not included)*/ /* @}*/ diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index 32371df315..76cde6c3be 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -27,9 +27,9 @@ int main(int argc, char *argv[]) { int16_t nBitError = 0; // -1 = Decoding failed (All list entries have failed the CRC checks). uint32_t decoderState=0, blockErrorState=0; //0 = Success, -1 = Decoding failed, 1 = Block Error. uint16_t testLength = NR_POLAR_PBCH_PAYLOAD_BITS, coderLength = NR_POLAR_PBCH_E; - uint16_t blockErrorCumulative=0, bitErrorCumulative=0, aPrioriLength=0; + uint16_t blockErrorCumulative=0, bitErrorCumulative=0; double timeEncoderCumulative = 0, timeDecoderCumulative = 0; - uint8_t aggregation_level = 8, decoderListSize = 8, pathMetricAppr = 0, logFlag = 0, aPrioriFlag=0; + uint8_t aggregation_level = 8, decoderListSize = 8, logFlag = 0; uint16_t rnti=0; while ((arguments = getopt (argc, argv, "s:d:f:m:i:l:a:p:hqgFL:k:")) != -1) @@ -60,12 +60,6 @@ int main(int argc, char *argv[]) { decoderListSize = (uint8_t) atoi(optarg); break; - case 'a': - pathMetricAppr = (uint8_t) atoi(optarg); - break; - - - case 'q': decoder_int16 = 1; break; @@ -97,19 +91,10 @@ int main(int argc, char *argv[]) { } break; - case 'p': - aPrioriLength = (uint8_t) atoi(optarg); - if (aPrioriLength > testLength){ - printf("A priori information(%d) cannot be larger than test length(%d)\n",aPrioriLength, testLength); - exit(-1); - } - aPrioriFlag = 1; - break; - case 'h': printf("./polartest\nOptions\n-h Print this help\n-s SNRstart (dB)\n-d SNRinc (dB)\n-f SNRstop (dB)\n-m [0=PBCH|1=DCI|2=UCI]\n" - "-i Number of iterations\n-l decoderListSize\n-a pathMetricAppr\n-q Flag for optimized coders usage\n-F Flag for test results logging\n" - "-L aggregation level (for DCI)\n-k packet_length (bits) for DCI/UCI\n-p (Only for PBCH for now) A priori information length used in polar decoder\n"); + "-i Number of iterations\n-l decoderListSize\n-q Flag for optimized coders usage\n-F Flag for test results logging\n" + "-L aggregation level (for DCI)\n-k packet_length (bits) for DCI/UCI\n"); exit(-1); break; @@ -148,9 +133,9 @@ int main(int argc, char *argv[]) { if (logFlag){ time (¤tTime); #ifdef DEBUG_POLAR_TIMING - sprintf(fileName,"%s/TIMING_ListSize_%d_pmAppr_%d_Payload_%d_Itr_%d",folderName,decoderListSize,pathMetricAppr,testLength,iterations); + sprintf(fileName,"%s/TIMING_ListSize_%d_Payload_%d_Itr_%d", folderName, decoderListSize, testLength, iterations); #else - sprintf(fileName,"%s/_ListSize_%d_pmAppr_%d_Payload_%d_Itr_%d",folderName,decoderListSize,pathMetricAppr,testLength,iterations); + sprintf(fileName,"%s/_ListSize_%d_Payload_%d_Itr_%d", folderName, decoderListSize, testLength, iterations); #endif strftime(currentTimeInfo, 25, "_%Y-%m-%d-%H-%M-%S.csv", localtime(¤tTime)); strcat(fileName,currentTimeInfo); @@ -184,11 +169,6 @@ if (logFlag){ double channelOutput[coderLength]; //add noise int16_t channelOutput_int16[coderLength]; - //A priori knowledge about the payload is assumed according to "aPrioriFlag". - double aPrioriArray[testLength]; - uint8_t testInputByte[testLength]; - uint16_t aPrioriInd[aPrioriLength]; - t_nrPolar_params *currentPtr = nr_polar_params(polarMessageType, testLength, aggregation_level); #ifdef DEBUG_DCI_POLAR_PARAMS @@ -224,7 +204,7 @@ if (logFlag){ modulated_input[i]=(-1)/sqrt(2); channel_output[i] = modulated_input[i] + (gaussdouble(0.0,1.0) * (1/sqrt(2*SNR_lin))); } - decoderState = polar_decoder_dci(channel_output, dci_est, currentPtrDCI, NR_POLAR_DECODER_LISTSIZE, NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, rnti); + decoderState = polar_decoder_dci(channel_output, dci_est, currentPtrDCI, NR_POLAR_DECODER_LISTSIZE, rnti); printf("dci_est: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_est[0], dci_est[1], dci_est[2], dci_est[3]); free(encoder_outputByte); free(channel_output); @@ -245,22 +225,10 @@ if (logFlag){ } testInput[i] |= ( ((uint32_t) (rand()%2)) &1); } - //Generate random a priori information in "aPrioriArray", if "aPrioriFlag" is set. - if (aPrioriFlag){ - nr_bit2byte_uint32_8(testInput, testLength, testInputByte); - for (int i=0; i0x%08x\n", testInput[0]); - for (int i=0; i<32; i++) printf("testInput:%d-testInputByte:%d-aPrioriArray:%f\n",(testInput[0]>>i)&1, testInputByte[i], aPrioriArray[i]); #endif int len_mod64=currentPtr->payloadBits&63; ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)< PBCH, 1 --> DCI, -1 --> UCI if (polarMessageType == 0) { - if (aPrioriFlag) { - decoderState = polar_decoder_aPriori(channelOutput, - estimatedOutput, - currentPtr, - decoderListSize, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - aPrioriArray); - } else { - decoderState = polar_decoder(channelOutput, - estimatedOutput, - currentPtr, - decoderListSize, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION); - } + decoderState = polar_decoder(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize); } else if (polarMessageType == 1) { decoderState = polar_decoder_dci(channelOutput, estimatedOutput, currentPtr, decoderListSize, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, rnti); } } @@ -379,8 +336,8 @@ if (logFlag){ } //Calculate error statistics for the SNR. - printf("[ListSize=%d, Appr=%d] SNR=%+8.3f, BLER=%9.6f, BER=%12.9f, t_Encoder=%9.3fus, t_Decoder=%9.3fus\n", - decoderListSize, pathMetricAppr, SNR, ((double)blockErrorCumulative/iterations), + printf("[ListSize=%d] SNR=%+8.3f, BLER=%9.6f, BER=%12.9f, t_Encoder=%9.3fus, t_Decoder=%9.3fus\n", + decoderListSize, SNR, ((double)blockErrorCumulative/iterations), ((double)bitErrorCumulative / (iterations*testLength)), (double)timeEncoder.diff/timeEncoder.trials/(cpu_freq_GHz*1000.0),(double)timeDecoder.diff/timeDecoder.trials/(cpu_freq_GHz*1000.0)); //(timeEncoderCumulative/iterations),timeDecoderCumulative/iterations); diff --git a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c index 6278420d8a..ee1a228ab8 100644 --- a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c +++ b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c @@ -29,13 +29,14 @@ int main(int argc, char *argv[]) { reset_meas(&timeDecoder); randominit(0); - int arguments, iterations = 1000, matlabDebug = 0, messageLength = 11; + int arguments, iterations = 1000, messageLength = 11; + //int matlabDebug = 0; uint32_t testInput, encoderOutput, codingDifference, nBitError=0, blockErrorState = 0, blockErrorCumulative=0, bitErrorCumulative=0; uint16_t estimatedOutput; double SNRstart = -20.0, SNRstop = 5.0, SNRinc= 0.5; //dB double SNR, SNR_lin, sigma; double modulatedInput[NR_SMALL_BLOCK_CODED_BITS], channelOutput[NR_SMALL_BLOCK_CODED_BITS]; - int16_t channelOutput_int16[NR_SMALL_BLOCK_CODED_BITS]; + //int16_t channelOutput_int16[NR_SMALL_BLOCK_CODED_BITS]; int8_t channelOutput_int8[NR_SMALL_BLOCK_CODED_BITS]; unsigned char qbits=8; @@ -62,10 +63,10 @@ int main(int argc, char *argv[]) { iterations = atoi(optarg); break; - case 'm': + /*case 'm': matlabDebug = 1; //#define DEBUG_POLAR_MATLAB - break; + break;*/ case 'g': iterations = 1; @@ -75,7 +76,8 @@ int main(int argc, char *argv[]) { break; case 'h': - printf("./smallblocktest -s SNRstart -d SNRinc -f SNRstop -l messageLength -i iterations -m Matlab Debug\n"); + //printf("./smallblocktest -s SNRstart -d SNRinc -f SNRstop -l messageLength -i iterations -m Matlab Debug\n"); + printf("./smallblocktest -s SNRstart -d SNRinc -f SNRstop -l messageLength -i iterations\n"); exit(-1); default: diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index 60bddd87f0..ee5c302adb 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -228,7 +228,7 @@ crc8 (unsigned char * inptr, int bitlen) int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) { uint32_t crc=0,oldcrc=0; - uint8_t crc_len,temp; + uint8_t crc_len=0; switch (crc_type) { case CRC24_A: diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 3c32de916e..66d0fc481c 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -42,8 +42,8 @@ int8_t polar_decoder(double *input, uint32_t *out, t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr) { + uint8_t listSize) +{ //Assumes no a priori knowledge. uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True @@ -117,12 +117,12 @@ int8_t polar_decoder(double *input, uint8_t listIndex[2*listSize], copyIndex; for (uint16_t currentBit=0; currentBitN; currentBit++) { - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); + updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1)); if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 + updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit); } else { //Information or CRC bit. - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); + updatePathMetric2(pathMetric, llr, currentListSize, currentBit); for (int i = 0; i < currentListSize; i++) { for (int j = 0; j < polarParams->N; j++) { @@ -296,286 +296,10 @@ int8_t polar_decoder(double *input, return(0); } -int8_t polar_decoder_aPriori(double *input, - uint32_t *out, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload) { - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize); - double *pathMetric = malloc(sizeof(double)*(2*listSize)); - uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True - - for (int i=0; i<(2*listSize); i++) { - pathMetric[i] = 0; - crcState[i]=1; - } - - for (int i=0; iN; i++) { - llrUpdated[i][polarParams->n]=1; - bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2); - } - - uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3 - uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2 - - for (int i = 0; i < polarParams->K; i++) { - extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - } - - for (int i=0; ipayloadBits; i++) { - for (int j=0; jcrcParityBits; j++) { - tempECGM[i][j]=polarParams->crc_generator_matrix[i][j]; - } - } - - for (int i=polarParams->payloadBits; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - if( (i-polarParams->payloadBits) == j ) { - tempECGM[i][j]=1; - } else { - tempECGM[i][j]=0; - } - } - } - - for (int i=0; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j]; - } - } - - //The index of the last 1-valued bit that appears in each column. - uint16_t last1ind[polarParams->crcParityBits]; - - for (int j=0; jcrcParityBits; j++) { - for (int i=0; iK; i++) { - if (extended_crc_generator_matrix[i][j]==1) last1ind[j]=i; - } - } - - double *d_tilde = malloc(sizeof(double) * polarParams->N); - nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); - - for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j]; - - /* - * SCL polar decoder. - */ - uint32_t nonFrozenBit=0; - uint8_t currentListSize=1; - uint8_t decoderIterationCheck=0; - int16_t checkCrcBits=-1; - uint8_t listIndex[2*listSize], copyIndex; - - for (uint16_t currentBit=0; currentBitN; currentBit++) { - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); - - if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 - } else { //Information or CRC bit. - if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 0) ) { - //Information bit with known value of "0". - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); - bitUpdated[currentBit][0]=1; //0=False, 1=True - } else if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 1) ) { - //Information bit with known value of "1". - updatePathMetric(pathMetric, llr, currentListSize, 1, currentBit, pathMetricAppr); - - for (uint8_t i=0; icrcParityBits); - } else { - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); - - for (int i = 0; i < currentListSize; i++) { - for (int j = 0; j < polarParams->N; j++) { - for (int k = 0; k < (polarParams->n+1); k++) { - bit[j][k][i+currentListSize]=bit[j][k][i]; - llr[j][k][i+currentListSize]=llr[j][k][i]; - } - } - } - - for (int i = 0; i < currentListSize; i++) { - bit[currentBit][0][i]=0; - crcState[i+currentListSize]=crcState[i]; - } - - for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1; - - bitUpdated[currentBit][0]=1; - updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); - currentListSize*=2; - - //Keep only the best "listSize" number of entries. - if (currentListSize > listSize) { - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - //sort listIndex[listSize, ..., 2*listSize-1] in descending order. - uint8_t swaps, tempInd; - - for (uint8_t i = 0; i < listSize; i++) { - swaps = 0; - - for (uint8_t j = listSize; j < (2*listSize - i) - 1; j++) { - if (listIndex[j+1] > listIndex[j]) { - tempInd = listIndex[j]; - listIndex[j] = listIndex[j + 1]; - listIndex[j + 1] = tempInd; - swaps++; - } - } - - if (swaps == 0) - break; - } - - //First, backup the best "listSize" number of entries. - for (int k=(listSize-1); k>0; k--) { - for (int i=0; iN; i++) { - for (int j=0; j<(polarParams->n+1); j++) { - bit[i][j][listIndex[(2*listSize-1)-k]]=bit[i][j][listIndex[k]]; - llr[i][j][listIndex[(2*listSize-1)-k]]=llr[i][j][listIndex[k]]; - } - } - } - - for (int k=(listSize-1); k>0; k--) { - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][listIndex[(2*listSize-1)-k]] = crcChecksum[i][listIndex[k]]; - } - } - - for (int k=(listSize-1); k>0; k--) crcState[listIndex[(2*listSize-1)-k]]=crcState[listIndex[k]]; - - //Copy the best "listSize" number of entries to the first indices. - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->N; i++) { - for (int j = 0; j < (polarParams->n + 1); j++) { - bit[i][j][k] = bit[i][j][copyIndex]; - llr[i][j][k] = llr[i][j][copyIndex]; - } - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][k]=crcChecksum[i][copyIndex]; - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - crcState[k]=crcState[copyIndex]; - } - - currentListSize = listSize; - } - } - - for (int i=0; icrcParityBits; i++) { - if (last1ind[i]==nonFrozenBit) { - checkCrcBits=i; - break; - } - } - - if ( checkCrcBits > (-1) ) { - for (uint8_t i = 0; i < currentListSize; i++) { - if (crcChecksum[checkCrcBits][i]==1) { - crcState[i]=0; //0=False, 1=True - } - } - } - - for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i]; - - if (decoderIterationCheck==0) { - //perror("[SCL polar decoder] All list entries have failed the CRC checks."); - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - return(-1); - } - - nonFrozenBit++; - decoderIterationCheck=0; - checkCrcBits=-1; - } - } - - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - - for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) { - if ( crcState[listIndex[i]] == 1 ) { - for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_U[j]=bit[j][0][listIndex[i]]; - - //Extract the information bits (û to ĉ) - nr_polar_info_bit_extraction(polarParams->nr_polar_U, polarParams->nr_polar_CPrime, polarParams->information_bit_pattern, polarParams->N); - //Deinterleaving (ĉ to b) - nr_polar_deinterleaver(polarParams->nr_polar_CPrime, polarParams->nr_polar_B, polarParams->interleaving_pattern, polarParams->K); - - //Remove the CRC (â) - for (int j = 0; j < polarParams->payloadBits; j++) - polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; - - break; - } - } - - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K); - nr_free_uint8_2D_array(tempECGM, polarParams->K); - /* - * Return bits. - */ - nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); - return(0); -} - - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, uint8_t listSize, - uint8_t pathMetricAppr, uint16_t n_RNTI) { uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True @@ -663,12 +387,12 @@ int8_t polar_decoder_dci(double *input, uint8_t listIndex[2*listSize], copyIndex; for (uint16_t currentBit=0; currentBitN; currentBit++) { - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); + updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1)); if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 + updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit); } else { //Information or CRC bit. - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); + updatePathMetric2(pathMetric, llr, currentListSize, currentBit); for (int i = 0; i < currentListSize; i++) { for (int j = 0; j < polarParams->N; j++) { diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c index 11aa5d98a4..bf8a90e0d9 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c @@ -44,20 +44,19 @@ void updateLLR(double ***llr, uint16_t row, uint16_t col, uint16_t xlen, - uint8_t ylen, - uint8_t approximation) + uint8_t ylen) { uint16_t offset = (xlen/(pow(2,(ylen-col-1)))); for (uint8_t i=0; i= offset ) { if(bitU[row-offset][col]==0) updateBit(bit, bitU, listSize, (row-offset), col, xlen, ylen); - if(llrU[row-offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row-offset), (col+1), xlen, ylen, approximation); - if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen, approximation); + if(llrU[row-offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row-offset), (col+1), xlen, ylen); + if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen); llr[row][col][i] = (pow((-1),bit[row-offset][col][i])*llr[row-offset][col+1][i]) + llr[row][col+1][i]; } else { - if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen, approximation); - if(llrU[row+offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row+offset), (col+1), xlen, ylen, approximation); - computeLLR(llr, row, col, i, offset, approximation); + if(llrU[row][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, row, (col+1), xlen, ylen); + if(llrU[row+offset][col+1]==0) updateLLR(llr, llrU, bit, bitU, listSize, (row+offset), (col+1), xlen, ylen); + computeLLR(llr, row, col, i, offset); } } llrU[row][col]=1; @@ -90,51 +89,34 @@ void updateBit(uint8_t ***bit, } void updatePathMetric(double *pathMetric, - double ***llr, + double ***llr, uint8_t listSize, uint8_t bitValue, - uint16_t row, - uint8_t approximation) + uint16_t row) { - if (approximation) { //eq. (12) - for (uint8_t i=0; i<2*listSize; i++) { - if ((2*bitValue) != ( 1 - copysign(1.0,llr[row][0][i]) )) pathMetric[i] += fabs(llr[row][0][i]); - } - } else { //eq. (11b) - int8_t multiplier = (2*bitValue) - 1; - for (uint8_t i=0; i<2*listSize; i++) pathMetric[i] += log ( 1 + exp(multiplier*llr[row][0][i]) ) ; - } + int8_t multiplier = (2*bitValue) - 1; + for (uint8_t i=0; i eq. (8a) and (11b), 1 --> eq. (9) and (12) #define NR_POLAR_AGGREGATION_LEVEL_1_PRIME 149 //uint16_t #define NR_POLAR_AGGREGATION_LEVEL_2_PRIME 151 //uint16_t @@ -154,25 +153,16 @@ void polar_encoder_fast(uint64_t *A, int8_t polar_decoder(double *input, uint32_t *output, t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr); + uint8_t listSize); uint32_t polar_decoder_int16(int16_t *input, uint64_t *out, const t_nrPolar_params *polarParams); -int8_t polar_decoder_aPriori(double *input, - uint32_t *output, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload); - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, uint8_t listSize, - uint8_t pathMetricAppr, uint16_t n_RNTI); void generic_polar_decoder(const t_nrPolar_params *pp, @@ -330,8 +320,7 @@ void updateLLR(double ***llr, uint16_t row, uint16_t col, uint16_t xlen, - uint8_t ylen, - uint8_t approximation); + uint8_t ylen); void updateBit(uint8_t ***bit, uint8_t **bitU, @@ -345,21 +334,18 @@ void updatePathMetric(double *pathMetric, double ***llr, uint8_t listSize, uint8_t bitValue, - uint16_t row, - uint8_t approximation); + uint16_t row); void updatePathMetric2(double *pathMetric, double ***llr, uint8_t listSize, - uint16_t row, - uint8_t approximation); + uint16_t row); void computeLLR(double ***llr, uint16_t row, uint16_t col, uint8_t i, - uint16_t offset, - uint8_t approximation); + uint16_t offset); void updateCrcChecksum(uint8_t **crcChecksum, uint8_t **crcGen, diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c index dd11cd7867..b392506095 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c @@ -64,8 +64,9 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m } if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) { - AssertFatal((N_reg%(bsize*R))==0,"CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n",N_reg, bsize, R); - C = N_reg/(bsize*R); + uint16_t assertFatalCond = (N_reg%(bsize*R)); + AssertFatal(assertFatalCond == 0,"CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n",N_reg, bsize, R); + C = N_reg/(bsize*R); } tmp = L * (( Y + (m*N_cce)/(L*M_s_max) + n_CI ) % CEILIDIV(N_cce,L)); diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 6adb2271e2..591d609454 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -333,5 +333,4 @@ typedef struct nr_band_info_s { nr_bandentry_t band_info[100]; } nr_band_info_t; - #endif diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 139d48ffa9..8a404b717c 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -56,7 +56,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ NR_UE_PDCCH *pdcch_vars2 = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0]; NR_UE_DLSCH_t *dlsch0 = PHY_vars_UE_g[module_id][cc_id]->dlsch[thread_id][0][0]; NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[thread_id][0][0]; - NR_DL_FRAME_PARMS frame_parms = PHY_vars_UE_g[module_id][cc_id]->frame_parms; + //NR_DL_FRAME_PARMS frame_parms = PHY_vars_UE_g[module_id][cc_id]->frame_parms; PRACH_RESOURCES_t *prach_resources = PHY_vars_UE_g[module_id][cc_id]->prach_resources[0]; // PUCCH_ConfigCommon_nr_t *pucch_config_common = PHY_vars_UE_g[module_id][cc_id]->pucch_config_common_nr[0]; @@ -185,11 +185,11 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ if(ul_config->ul_config_list[i].pdu_type == FAPI_NR_UL_CONFIG_TYPE_PRACH){ // prach config pdu fapi_nr_ul_config_prach_pdu *prach_config_pdu = &ul_config->ul_config_list[i].prach_config_pdu; - frame_parms.prach_config_common.rootSequenceIndex = prach_config_pdu->root_sequence_index; + /*frame_parms.prach_config_common.rootSequenceIndex = prach_config_pdu->root_sequence_index; frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex = prach_config_pdu->prach_configuration_index; frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = prach_config_pdu->zero_correlation_zone_config; frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag = prach_config_pdu->restrictedset_config; - frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset = prach_config_pdu->prach_freq_offset; + frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset = prach_config_pdu->prach_freq_offset;*/ prach_resources->ra_PreambleIndex = prach_config_pdu->preamble_index; } } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index c83074d8a2..a5ce07e883 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -1560,25 +1560,26 @@ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDUR #endif -void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id,uint8_t abstraction_flag) { - - int harq_pid; - int frame_tx=proc->frame_tx; +void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc, + uint8_t eNB_id, + uint8_t abstraction_flag) +{ int nr_tti_tx=proc->nr_tti_tx; - unsigned int input_buffer_length; - int i; - int aa; - int tx_amp; + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_IN); /* reset harq for tx of current rx slot because it is sure that transmission has already been achieved for this slot */ set_tx_harq_id(ue->ulsch[ue->current_thread_id[nr_tti_tx]][eNB_id][0], NR_MAX_HARQ_PROCESSES, proc->nr_tti_rx); +#if 0 + int frame_tx=proc->frame_tx; + int harq_pid; /* get harq pid related to this next tx slot */ harq_pid = get_tx_harq_id(ue->ulsch[ue->current_thread_id[nr_tti_tx]][eNB_id][0], nr_tti_tx); -#if 0 - + int tx_amp; + unsigned int input_buffer_length; int Mod_id = ue->Mod_id; int CC_id = ue->CC_id; uint8_t Msg3_flag=0; @@ -1599,9 +1600,9 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8 ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1; if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round==0) - generate_ue_ulsch_params_from_rar(ue, - proc, - eNB_id); + generate_ue_ulsch_params_from_rar(ue, + proc, + eNB_id); ue->ulsch[eNB_id]->power_offset = 14; LOG_D(PHY,"[UE %d][RAPROC] Frame %d: Setting Msg3_flag in nr_tti_rx %d, for harq_pid %d\n", @@ -1864,7 +1865,7 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8 #ifdef DEBUG_ULSCH LOG_D(PHY,"[UE] Frame %d, nr_tti_rx %d : ULSCH SDU (TX harq_pid %d) (%d bytes) : \n",frame_tx,nr_tti_tx,harq_pid, ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3); - for (i=0; iulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3; i++) + for (int i=0; iulsch[eNB_id]->harq_processes[harq_pid]->TBS>>3; i++) LOG_T(PHY,"%x.",ulsch_input_buffer[i]); LOG_T(PHY,"\n"); @@ -1874,7 +1875,7 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8 else { unsigned int taus(void); - for (i=0; iframe_parms, ue->ulsch[eNB_id]); - for (aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++) + for (int aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++) generate_drs_pusch(ue, proc, eNB_id, @@ -2670,22 +2671,18 @@ void phy_procedures_UE_S_TX(PHY_VARS_NR_UE *ue,uint8_t eNB_id,uint8_t abstractio #endif -void nr_ue_measurement_procedures( - uint16_t l, // symbol index of each slot [0..6] - PHY_VARS_NR_UE *ue, - UE_nr_rxtx_proc_t *proc, - uint8_t eNB_id, - uint16_t slot, // slot index of each radio frame [0..19] - runmode_t mode) +void nr_ue_measurement_procedures(uint16_t l, // symbol index of each slot [0..6] + PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc, + uint8_t eNB_id, + uint16_t slot, // slot index of each radio frame [0..19] + runmode_t mode) { - LOG_D(PHY,"ue_measurement_procedures l %u Ncp %d\n",l,ue->frame_parms.Ncp); - NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; - - int nr_tti_rx = proc->nr_tti_rx; - #if 0 + NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms; + int nr_tti_rx = proc->nr_tti_rx; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_IN); if (l==0) { @@ -2806,16 +2803,17 @@ void restart_phy(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc, uint8_t eNB_id,uint } #endif //(0) -void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc, uint8_t abstraction_flag) +void nr_ue_pbch_procedures(uint8_t eNB_id, + PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc, + uint8_t abstraction_flag) { - // int i; //int pbch_tx_ant=0; //uint8_t pbch_phase; int ret = 0; - uint16_t frame_tx; - static uint8_t first_run = 1; - uint8_t pbch_trials = 0; + //static uint8_t first_run = 1; + //uint8_t pbch_trials = 0; DevAssert(ue); @@ -2838,6 +2836,7 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * #ifdef DEBUG_PHY_PROC + uint16_t frame_tx; LOG_D(PHY,"[UE %d] frame %d, nr_tti_rx %d, Received PBCH (MIB): frame_tx %d. N_RB_DL %d\n", ue->Mod_id, frame_rx, @@ -2908,9 +2907,10 @@ unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb #ifdef NR_PDCCH_SCHED -int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc) +int nr_ue_pdcch_procedures(uint8_t eNB_id, + PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc) { - // unsigned int dci_cnt=0, i; //removed for nr_ue_pdcch_procedures and added in the loop for nb_coreset_active #ifdef NR_PDCCH_SCHED_DEBUG printf("<-NR_PDCCH_PHY_PROCEDURES_LTE_UE (nr_ue_pdcch_procedures)-> Entering function nr_ue_pdcch_procedures() \n"); @@ -2940,7 +2940,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * pdcch_vars[eNB_id]->crnti = 0x1234; //to be check how to set when using loop memory uint16_t c_rnti=pdcch_vars[eNB_id]->crnti; - uint16_t cs_rnti=0,new_rnti=0,tc_rnti; + uint16_t cs_rnti=0,new_rnti=0,tc_rnti=0; uint16_t p_rnti=P_RNTI; uint16_t si_rnti=SI_RNTI; uint16_t ra_rnti=99; @@ -2958,10 +2958,10 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * #endif // p in TS 38.212 Subclause 10.1, for each active BWP the UE can deal with 3 different CORESETs (including coresetId 0 for common search space) - int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; + //int nb_coreset_total = NR_NBR_CORESET_ACT_BWP; unsigned int dci_cnt=0; // this table contains 56 (NBR_NR_DCI_FIELDS) elements for each dci field and format described in TS 38.212. Each element represents the size in bits for each dci field - uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; + //uint8_t dci_fields_sizes[NBR_NR_DCI_FIELDS][NBR_NR_FORMATS] = {{0}}; // this is the UL bandwidth part. FIXME! To be defined where this value comes from // uint16_t n_RB_ULBWP = 106; // this is the DL bandwidth part. FIXME! To be defined where this value comes from @@ -2970,7 +2970,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * // Up to 10 searchSpaces can be configured to UE (s<=10) for (nb_searchspace_active=0; nb_searchspace_activesearchSpace[nb_searchspace_active].searchSpaceId; + //int searchSpace_id = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceId; #ifdef NR_PDCCH_SCHED_DEBUG @@ -3001,16 +3001,16 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * // the searchSpace indicates that we need to monitor PDCCH in current nr_tti_rx // get the parameters describing the current SEARCHSPACE // the CORESET id applicable to the current SearchSpace - int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; + //int searchSpace_coreset_id = pdcch_vars2->searchSpace[nb_searchspace_active].controlResourceSetId; // FIXME this variable is a bit string (14 bits) identifying every OFDM symbol in a slot. // at the moment we will not take into consideration this variable and we will consider that the OFDM symbol offset is always the first OFDM in a symbol uint16_t symbol_within_slot_mon = pdcch_vars2->searchSpace[nb_searchspace_active].monitoringSymbolWithinSlot; // get the remaining parameters describing the current SEARCHSPACE: // FIXME! To be defined where we get this information from - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; + /*NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L1 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel1; NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L2 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel2; NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L4 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel4; NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L8 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel8; - NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16; + NR_UE_SEARCHSPACE_nbrCAND_t num_cand_L16 = pdcch_vars2->searchSpace[nb_searchspace_active].nrofCandidates_aggrlevel16;*/ // FIXME! A table of five enum elements // searchSpaceType indicates whether this is a common search space or a UE-specific search space //int searchSpaceType = pdcch_vars2->searchSpace[nb_searchspace_active].searchSpaceType.type; @@ -3127,9 +3127,8 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_OUT); //LOG_D(PHY,"[UE %d][PUSCH] Frame %d nr_tti_rx %d PHICH RX\n",ue->Mod_id,frame_rx,nr_tti_rx); - - uint8_t *nCCE_current = &ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->nCCE[nr_tti_rx]; /* + uint8_t *nCCE_current = &ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id]->nCCE[nr_tti_rx]; uint8_t *nCCE_dest = &ue->pdcch_vars[next1_thread_id][eNB_id]->nCCE[nr_tti_rx]; uint8_t *nCCE_dest1 = &ue->pdcch_vars[next2_thread_id][eNB_id]->nCCE[nr_tti_rx]; memcpy(nCCE_dest, nCCE_current, sizeof(uint8_t)); @@ -3780,7 +3779,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; int ret=0, ret1=0; - int CC_id = ue->CC_id; + //int CC_id = ue->CC_id; NR_UE_PDSCH *pdsch_vars; uint8_t is_cw0_active = 0; uint8_t is_cw1_active = 0; @@ -3861,10 +3860,10 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, start_meas(&ue->dlsch_unscrambling_stats); #endif nr_dlsch_unscrambling(pdsch_vars->llr[0], - dlsch0->harq_processes[harq_pid]->G, - 0, - ue->frame_parms.Nid_cell, - dlsch0->rnti); + dlsch0->harq_processes[harq_pid]->G, + 0, + ue->frame_parms.Nid_cell, + dlsch0->rnti); #if UE_TIMING_TRACE @@ -3887,7 +3886,9 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, #endif #ifdef UE_DLSCH_PARALLELISATION - ret = nr_dlsch_decoding_mthread(ue,proc,eNB_id, + ret = nr_dlsch_decoding_mthread(ue, + proc, + eNB_id, pdsch_vars->llr[0], &ue->frame_parms, dlsch0, @@ -3898,6 +3899,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, harq_pid, pdsch==PDSCH?1:0, dlsch0->harq_processes[harq_pid]->TBS>256?1:0); + LOG_T(PHY,"UE_DLSCH_PARALLELISATION is defined, ret = %d\n", ret); #else ret = nr_dlsch_decoding(ue, pdsch_vars->llr[0], @@ -3910,6 +3912,7 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, harq_pid, pdsch==PDSCH?1:0,//proc->decoder_switch, dlsch0->harq_processes[harq_pid]->TBS>256?1:0); + LOG_T(PHY,"UE_DLSCH_PARALLELISATION is NOT defined, ret = %d\n", ret); //printf("start cW0 dlsch decoding\n"); #endif @@ -3964,7 +3967,9 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, #endif #ifdef UE_DLSCH_PARALLELISATION - ret1 = nr_dlsch_decoding_mthread(ue,proc, eNB_id, + ret1 = nr_dlsch_decoding_mthread(ue, + proc, + eNB_id, pdsch_vars->llr[1], &ue->frame_parms, dlsch1, @@ -3975,19 +3980,20 @@ void nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue, harq_pid, pdsch==PDSCH?1:0, dlsch1->harq_processes[harq_pid]->TBS>256?1:0); + LOG_T(PHY,"UE_DLSCH_PARALLELISATION is defined, ret1 = %d\n", ret1); #else - ret1 = nr_dlsch_decoding(ue, pdsch_vars->llr[1], &ue->frame_parms, dlsch1, dlsch1->harq_processes[harq_pid], frame_rx, - nb_symb_sch, + nb_symb_sch, nr_tti_rx, harq_pid, pdsch==PDSCH?1:0,//proc->decoder_switch, dlsch1->harq_processes[harq_pid]->TBS>256?1:0); + LOG_T(PHY,"UE_DLSCH_PARALLELISATION is NOT defined, ret1 = %d\n", ret1); printf("start cw1 dlsch decoding\n"); #endif @@ -4317,14 +4323,12 @@ void *UE_thread_slot1_dl_processing(void *arg) { -int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t eNB_id, - uint8_t do_pdcch_flag,runmode_t mode) { - - - - int l,l2; - int pilot1; - +int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, + UE_nr_rxtx_proc_t *proc, + uint8_t eNB_id, + uint8_t do_pdcch_flag, + runmode_t mode) +{ int frame_rx = proc->frame_rx; int nr_tti_rx = proc->nr_tti_rx; NR_UE_PDCCH *pdcch_vars = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][0]; diff --git a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c index debb0d4ed5..296d92969c 100644 --- a/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_power_control_ue_nr.c @@ -67,9 +67,19 @@ * *********************************************************************/ -int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_t *proc, pucch_format_nr_t pucch_format, - int nb_of_prbs, int N_sc_ctrl_RB, int N_symb_PUCCH, int O_UCI, int O_SR, int O_CSI, int O_ACK, - int O_CRC, int n_HARQ_ACK) { +int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, + uint8_t gNB_id, + UE_nr_rxtx_proc_t *proc, + pucch_format_nr_t pucch_format, + int nb_of_prbs, + int N_sc_ctrl_RB, + int N_symb_PUCCH, + int O_UCI, + int O_SR, + int O_CSI, + int O_ACK, + int O_CRC, + int n_HARQ_ACK) { int16_t P_O_NOMINAL_PUCCH = ue->pucch_config_common_nr[gNB_id].p0_nominal; PUCCH_PowerControl_t *power_config = &ue->pucch_config_dedicated_nr[gNB_id].pucch_PowerControl; @@ -147,7 +157,6 @@ int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_pro } } - int l = 0; int k2; if (power_config->twoPUCCH_PC_AdjustmentStates > 1) { @@ -156,11 +165,11 @@ int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_pro } /* response to a detection by the UE of a DCI format 1_0 or DCI format 1_1 */ - int K_PUCCH = 0; + //int K_PUCCH = 0; if (O_ACK != 0) { /* it assumes that PDCCH is in the first symbol of receive slot FFS TDDO NR */ - int slots_gap = (proc->nr_tti_tx > proc->nr_tti_rx ? (proc->nr_tti_tx - proc->nr_tti_rx - 1) : ((proc->nr_tti_tx + ue->frame_parms.ttis_per_subframe) - proc->nr_tti_rx - 1)); - K_PUCCH = (slots_gap * (ue->frame_parms.symbols_per_tti)) - 1; + //int slots_gap = (proc->nr_tti_tx > proc->nr_tti_rx ? (proc->nr_tti_tx - proc->nr_tti_rx - 1) : ((proc->nr_tti_tx + ue->frame_parms.ttis_per_subframe) - proc->nr_tti_rx - 1)); + //K_PUCCH = (slots_gap * (ue->frame_parms.symbols_per_tti)) - 1; } else { /* field k2 is not present - to check k2 of pucch from upper layer FFS TDDO NR */ @@ -189,7 +198,7 @@ int16_t get_pucch_tx_power_ue(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_pro } while(ue->pusch_config.pusch_TimeDomainResourceAllocation[i] != NULL); k2 = k2_min; } - K_PUCCH = N_SYMB_SLOT * k2; /* the product of a number of symbols per slot and the minimum of the values provided by higher layer parameter k2 */ + //K_PUCCH = N_SYMB_SLOT * k2; /* the product of a number of symbols per slot and the minimum of the values provided by higher layer parameter k2 */ } int contributor = (10 * log10((double)(pow(2,(ue->frame_parms.numerology_index)) * nb_of_prbs))); diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index acf10b14e3..899868d2f6 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -128,45 +128,46 @@ int main(int argc, char **argv) char c; - int i,l,aa; + int i,aa;//,l; double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1=2.0; uint8_t snr1set=0; int **txdata; double **s_re,**s_im,**r_re,**r_im; - double iqim = 0.0; - unsigned char pbch_pdu[6]; + //double iqim = 0.0; + //unsigned char pbch_pdu[6]; // int sync_pos, sync_pos_slot; // FILE *rx_frame_file; FILE *output_fd = NULL; - uint8_t write_output_file=0; + //uint8_t write_output_file=0; //int result; - int freq_offset; + //int freq_offset; // int subframe_offset; // char fname[40], vname[40]; - int trial,n_trials=1,n_errors,n_errors2,n_alamouti; + int trial,n_trials=1,n_errors=0; + //int n_errors2, n_alamouti; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; uint64_t SSB_positions=0x01; channel_desc_t *gNB2UE; - uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; - uint8_t extended_prefix_flag=0; - int8_t interf1=-21,interf2=-21; + //uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; + //uint8_t extended_prefix_flag=0; + //int8_t interf1=-21,interf2=-21; FILE *input_fd=NULL,*pbch_file_fd=NULL; - char input_val_str[50],input_val_str2[50]; + //char input_val_str[50],input_val_str2[50]; - uint8_t frame_mod4,num_pdcch_symbols = 0; + //uint8_t frame_mod4,num_pdcch_symbols = 0; SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - double pbch_sinr; - int pbch_tx_ant; + //double pbch_sinr; + //int pbch_tx_ant; int N_RB_DL=273,mu=1; uint64_t ssb_pattern = 0x01; - unsigned char frame_type = 0; + //unsigned char frame_type = 0; unsigned char pbch_phase = 0; int frame=0,slot=1; @@ -199,7 +200,7 @@ int main(int argc, char **argv) while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:M:N:F:GR:dP:IL:")) != -1) { switch (c) { - case 'f': + /*case 'f': write_output_file=1; output_fd = fopen(optarg,"w"); @@ -207,12 +208,11 @@ int main(int argc, char **argv) printf("Error opening %s\n",optarg); exit(-1); } + break;*/ - break; - - case 'd': + /*case 'd': frame_type = 1; - break; + break;*/ case 'g': switch((char)*optarg) { @@ -251,13 +251,13 @@ int main(int argc, char **argv) break; - case 'i': + /*case 'i': interf1=atoi(optarg); break; case 'j': interf2=atoi(optarg); - break; + break;*/ case 'n': n_trials = atoi(optarg); @@ -279,9 +279,9 @@ int main(int argc, char **argv) Td= atof(optarg); break; */ - case 'p': + /*case 'p': extended_prefix_flag=1; - break; + break;*/ /* case 'r': @@ -368,8 +368,8 @@ int main(int argc, char **argv) printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", argv[0]); printf("-h This message\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); + //printf("-p Use extended prefix mode\n"); + //printf("-d Use TDD\n"); printf("-n Number of frames to simulate\n"); printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); printf("-S Ending SNR, runs from SNR0 to SNR1\n"); @@ -378,15 +378,15 @@ int main(int argc, char **argv) printf("-x Transmission mode (1,2,6 for the moment)\n"); printf("-y Number of TX antennas used in eNB\n"); printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + //printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + //printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); printf("-M Multiple SSB positions in burst\n"); printf("-N Nid_cell\n"); printf("-R N_RB_DL\n"); printf("-O oversampling factor (1,2,4,8,16)\n"); printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); + //printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + //printf("-f Output filename (.txt format) for Pe/SNR results\n"); printf("-F Input filename (.txt format) for RX conformance testing\n"); exit (-1); break; @@ -683,8 +683,8 @@ int main(int argc, char **argv) for (SNR=snr0; SNRul_config_request; - fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; + //fapi_nr_dl_config_request_t *dl_config = &mac->dl_config_request; nr_phy_config_t *phy_config = &mac->phy_config; //ul_config->ul_config_list[ul_config->number_pdus].ulsch_config_pdu.rnti = rnti; @@ -1149,7 +1154,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,4,7}, // row index 15 {0,8,4} // row index 16 }; - uint8_t table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 + /*uint8_t table_5_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?6:5}, // row index 1 {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?10:9}, // row index 2 {0,(dmrs_typeA_pos == 0)?2:3, (dmrs_typeA_pos == 0)?9:8}, // row index 3 @@ -1166,8 +1171,8 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,2,4}, // row index 14 {0,4,6}, // row index 15 {0,8,4} // row index 16 - }; - uint8_t table_5_1_2_1_1_4_time_dom_res_alloc_B[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 + };*/ + /*uint8_t table_5_1_2_1_1_4_time_dom_res_alloc_B[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 {0,2,2}, // row index 1 {0,4,2}, // row index 2 {0,6,2}, // row index 3 @@ -1184,8 +1189,8 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {1,2,4}, // row index 15 {0,0,0} // row index 16 - }; - uint8_t table_5_1_2_1_1_5_time_dom_res_alloc_C[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 + };*/ + /*uint8_t table_5_1_2_1_1_5_time_dom_res_alloc_C[16][3]={ // for PDSCH from TS 38.214 subclause 5.1.2.1.1 {0,2,2}, // row index 1 {0,4,2}, // row index 2 {0,6,2}, // row index 3 @@ -1202,7 +1207,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {0,(dmrs_typeA_pos == 0)?2:3,(dmrs_typeA_pos == 0)?12:11}, // row index 14 {0,0,6}, // row index 15 {0,2,6} // row index 16 - }; + };*/ uint8_t mu_pusch = 1; // definition table j Table 6.1.2.1.1-4 uint8_t j = (mu_pusch==3)?3:(mu_pusch==2)?2:1; @@ -1224,7 +1229,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {j+3,0,14}, // row index 15 {j+3,0,10} // row index 16 }; - uint8_t table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PUSCH from TS 38.214 subclause 6.1.2.1.1 + /*uint8_t table_6_1_2_1_1_3_time_dom_res_alloc_A_extCP[16][3]={ // for PUSCH from TS 38.214 subclause 6.1.2.1.1 {j, 0,8}, // row index 1 {j, 0,12}, // row index 2 {j, 0,10}, // row index 3 @@ -1241,7 +1246,7 @@ int8_t nr_ue_process_dci_time_dom_resource_assignment( {j, 8,4}, // row index 14 {j+3,0,8}, // row index 15 {j+3,0,10} // row index 16 - }; + };*/ /* * TS 38.214 subclause 5.1.2.1 Resource allocation in time domain (downlink) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index bf07051507..02c27930d3 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -336,7 +336,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, rnti = UE_RNTI(module_idP, i); CC_id = UE_PCCID(module_idP, i); - int spf = get_spf(cfg); + //int spf = get_spf(cfg); if (((frameP&127) == 0) && (slotP == 0)) { LOG_I(MAC, diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 5a57bc2846..ce18158f18 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -203,8 +203,8 @@ void nr_schedule_uss_dlsch_phytest(module_id_t module_idP, int dl_carrier_bandwidth = cfg->rf_config.dl_carrier_bandwidth.value; // everything here is hard-coded to 30 kHz - int scs = get_dlscs(cfg); - int slots_per_frame = get_spf(cfg); + //int scs = get_dlscs(cfg); + //int slots_per_frame = get_spf(cfg); for (CC_id=0; CC_id>4)&0x3f); #ifdef DEBUG_RRC - int i; LOG_I(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id); #endif diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 801673b2ef..6b1ded3b1e 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -141,19 +141,18 @@ void rrc_gNB_process_SgNBAdditionRequest( void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( const protocol_ctxt_t *const ctxt_pP, - rrc_gNB_ue_context_t *const ue_context_pP - ){ - - uint8_t size; - uint8_t buffer[100]; - int CC_id = ue_context_pP->ue_context.primaryCC_id; - OCTET_STRING_t *secondaryCellGroup; + rrc_gNB_ue_context_t *const ue_context_pP) +{ + //uint8_t size; + //uint8_t buffer[100]; + //int CC_id = ue_context_pP->ue_context.primaryCC_id; + //OCTET_STRING_t *secondaryCellGroup; NR_CellGroupConfig_t *cellGroupconfig; struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_BearerToAddModList; struct NR_MAC_CellGroupConfig *mac_CellGroupConfig; struct NR_PhysicalCellGroupConfig *physicalCellGroupConfig; struct NR_SpCellConfig *spCellConfig; - struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; + //struct NR_CellGroupConfig__sCellToAddModList *sCellToAddModList; cellGroupconfig = CALLOC(1,sizeof(NR_CellGroupConfig_t)); cellGroupconfig->rlc_BearerToAddModList = CALLOC(1,sizeof(struct NR_CellGroupConfig__rlc_BearerToAddModList)); From a531ea62fa938db0d5ab1b12c139175a07388793 Mon Sep 17 00:00:00 2001 From: Rakesh Mundlamuri Date: Fri, 19 Apr 2019 17:24:18 +0530 Subject: [PATCH 099/117] The changes made in this branch is to enable -E(threequarter sampling rate) option for mu=1 and 217PRB(ie; 80 MHz) to run on USRP x310. --- openair1/PHY/INIT/nr_init.c | 3 +- targets/ARCH/COMMON/common_lib.h | 2 + targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 10 +- .../CONF/gnb.band78.tm1.217PRB.usrpx300.conf | 298 ++++++++++++++++++ targets/RT/USER/nr-softmodem.c | 1 + 5 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpx300.conf diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index ef555c0f20..397f206336 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -40,6 +40,7 @@ extern uint32_t from_nrarfcn(int nr_bandP,uint32_t dl_nrarfcn); extern int32_t get_uldl_offset(int nr_bandP); +extern openair0_config_t openair0_cfg[MAX_CARDS]; int l1_north_init_gNB() { int i,j; @@ -417,7 +418,7 @@ void nr_phy_config_request(NR_PHY_Config_t *phy_config) { RC.gNB[Mod_id][CC_id]->mac_enabled = 1; fp->dl_CarrierFreq = from_nrarfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.nrarfcn.value); fp->ul_CarrierFreq = fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000); - fp->threequarter_fs = 0; + fp->threequarter_fs = openair0_cfg[0].threequarter_fs; LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,DL freq %u)\n", Mod_id, CC_id, diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h index d14b2457c9..99b5bce50e 100644 --- a/targets/ARCH/COMMON/common_lib.h +++ b/targets/ARCH/COMMON/common_lib.h @@ -238,6 +238,8 @@ typedef struct { double rx_sample_rate; //! the sample rate for transmit. double tx_sample_rate; + //! check for threequarter sampling rate + int8_t threequarter_fs; } openair0_config_t; diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 58a8697f79..f7fb036ebd 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -1128,7 +1128,15 @@ extern "C" { openair0_cfg[0].rx_bw = 80e6; break; - case 61440000: + case 92160000: + // from usrp_time_offset + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; //to be checked + openair0_cfg[0].tx_bw = 80e6; + openair0_cfg[0].rx_bw = 80e6; + break; + + case 61440000: // from usrp_time_offset //openair0_cfg[0].samples_per_packet = 2048; openair0_cfg[0].tx_sample_advance = 15; diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpx300.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpx300.conf new file mode 100644 index 0000000000..51910091f7 --- /dev/null +++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/gnb.band78.tm1.217PRB.usrpx300.conf @@ -0,0 +1,298 @@ +Active_gNBs = ( "gNB-Eurecom-5GNRBox"); +# Asn1_verbosity, choice in: none, info, annoying +Asn1_verbosity = "none"; + +gNBs = +( + { + ////////// Identification parameters: + gNB_ID = 0xe00; + + cell_type = "CELL_MACRO_GNB"; + + gNB_name = "gNB-Eurecom-5GNRBox"; + + // Tracking area code, 0x0000 and 0xfffe are reserved values + tracking_area_code = 1; + + plmn_list = ({mcc = 208; mnc = 93; mnc_length = 2;}); + + tr_s_preference = "local_mac" + + ////////// Physical parameters: + + component_carriers = ( + { + node_function = "3GPP_gNODEB"; + node_timing = "synch_to_ext_device"; + node_synch_ref = 0; + frame_type = "TDD"; + DL_prefix_type = "NORMAL"; + UL_prefix_type = "NORMAL"; + eutra_band = 78; + downlink_frequency = 3510000000L; + uplink_frequency_offset = -120000000; + Nid_cell = 0; + N_RB_DL = 217; + nb_antenna_ports = 1; + nb_antennas_tx = 1; + nb_antennas_rx = 1; + tx_gain = 90; + rx_gain = 125; + MIB_subCarrierSpacingCommon = 30; + MIB_ssb_SubcarrierOffset = 0; + MIB_dmrs_TypeA_Position = 2; + pdcch_ConfigSIB1 = 0; + SIB1_frequencyOffsetSSB = "khz5"; + SIB1_ssb_PeriodicityServingCell = 5; + SIB1_ss_PBCH_BlockPower = -60; + absoluteFrequencySSB = 0; + DL_FreqBandIndicatorNR = 15; + DL_absoluteFrequencyPointA = 15; + DL_offsetToCarrier = 15; + DL_SCS_SubcarrierSpacing = "kHz30"; + DL_SCS_SpecificCarrier_k0 = 0; + DL_carrierBandwidth = 15; + DL_locationAndBandwidth = 15; + DL_BWP_SubcarrierSpacing = "kHz30"; + DL_BWP_prefix_type = "NORMAL"; + UL_FreqBandIndicatorNR = 15; + UL_absoluteFrequencyPointA = 13; + UL_additionalSpectrumEmission = 3; + UL_p_Max = -1; + UL_frequencyShift7p5khz = "TRUE"; + UL_offsetToCarrier = 10; + UL_SCS_SubcarrierSpacing = "kHz30"; + UL_SCS_SpecificCarrier_k0 = 0; + UL_carrierBandwidth = 15; + UL_locationAndBandwidth = 15; + UL_BWP_SubcarrierSpacing = "kHz30"; + UL_BWP_prefix_type = "NORMAL"; + UL_timeAlignmentTimerCommon = "infinity"; + ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0x01; + ServingCellConfigCommon_ssb_periodicityServingCell = 10; + ServingCellConfigCommon_dmrs_TypeA_Position = 2; + NIA_SubcarrierSpacing = "kHz15"; + ServingCellConfigCommon_ss_PBCH_BlockPower = -60; + referenceSubcarrierSpacing = "kHz15"; + dl_UL_TransmissionPeriodicity = "ms0p5"; + nrofDownlinkSlots = 10; + nrofDownlinkSymbols = 10; + nrofUplinkSlots = 10; + nrofUplinkSymbols = 10; + rach_totalNumberOfRA_Preambles = 63; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_choice = "oneEighth"; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneEighth = 4; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneFourth = 8; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneHalf = 16; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_one = 24; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_two = 32; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_four = 8; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_eight = 4; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_sixteen = 2; + rach_groupBconfigured = "ENABLE"; + rach_ra_Msg3SizeGroupA = 56; + rach_messagePowerOffsetGroupB = "dB0"; + rach_numberOfRA_PreamblesGroupA = 32; + rach_ra_ContentionResolutionTimer = 8; + rsrp_ThresholdSSB = 64; + rsrp_ThresholdSSB_SUL = 64; + prach_RootSequenceIndex_choice = "l839"; + prach_RootSequenceIndex_l839 = 0; + prach_RootSequenceIndex_l139 = 0; + prach_msg1_SubcarrierSpacing = "kHz30"; + restrictedSetConfig = "unrestrictedSet"; + msg3_transformPrecoding = "ENABLE"; + prach_ConfigurationIndex = 10; + prach_msg1_FDM = "one"; + prach_msg1_FrequencyStart = 10; + zeroCorrelationZoneConfig = 10; + preambleReceivedTargetPower = -150; + preambleTransMax = 6; + powerRampingStep = "dB0"; + ra_ResponseWindow = 8; + groupHoppingEnabledTransformPrecoding = "ENABLE"; + msg3_DeltaPreamble = 0; + p0_NominalWithGrant = 0; + PUSCH_TimeDomainResourceAllocation_k2 = 0; + PUSCH_TimeDomainResourceAllocation_mappingType = "typeA"; + PUSCH_TimeDomainResourceAllocation_startSymbolAndLength = 0; + pucch_ResourceCommon = 0; + pucch_GroupHopping = "neither"; + hoppingId = 0; + p0_nominal = -30; + PDSCH_TimeDomainResourceAllocation_k0 = 2; + PDSCH_TimeDomainResourceAllocation_mappingType = "typeA"; + PDSCH_TimeDomainResourceAllocation_startSymbolAndLength = 0; + rateMatchPatternId = 0; + RateMatchPattern_patternType = "bitmaps"; + symbolsInResourceBlock = "oneSlot"; + periodicityAndPattern = 2; + RateMatchPattern_controlResourceSet = 5; + RateMatchPattern_subcarrierSpacing = "kHz30"; + RateMatchPattern_mode = "dynamic"; + controlResourceSetZero = 0; + searchSpaceZero = 0; + searchSpaceSIB1 = 10; + searchSpaceOtherSystemInformation = 10; + pagingSearchSpace = 10; + ra_SearchSpace = 10; + PDCCH_common_controlResourceSetId = 5; + PDCCH_common_ControlResourceSet_duration = 2; + PDCCH_cce_REG_MappingType = "nonInterleaved"; + PDCCH_reg_BundleSize = 3; + PDCCH_interleaverSize = 3; + PDCCH_shiftIndex = 10; + PDCCH_precoderGranularity = "sameAsREG-bundle"; + PDCCH_TCI_StateId = 32; + tci_PresentInDCI = "ENABLE"; + PDCCH_DMRS_ScramblingID = 0; + SearchSpaceId = 10; + commonSearchSpaces_controlResourceSetId = 5; + SearchSpace_monitoringSlotPeriodicityAndOffset_choice = "sl1"; + SearchSpace_monitoringSlotPeriodicityAndOffset_value = 0; + SearchSpace_duration = 2; + SearchSpace_nrofCandidates_aggregationLevel1 = 0; + SearchSpace_nrofCandidates_aggregationLevel2 = 0; + SearchSpace_nrofCandidates_aggregationLevel4 = 0; + SearchSpace_nrofCandidates_aggregationLevel8 = 0; + SearchSpace_nrofCandidates_aggregationLevel16 = 0; + SearchSpace_searchSpaceType = "common"; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel1 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel2 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel4 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel8 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel16 = 1; + Common_dci_Format2_3_monitoringPeriodicity = 1; + Common_dci_Format2_3_nrofPDCCH_Candidates = 1; + ue_Specific__dci_Formats = "formats0-0-And-1-0"; + RateMatchPatternLTE_CRS_carrierFreqDL = 6; + RateMatchPatternLTE_CRS_carrierBandwidthDL = 6; + RateMatchPatternLTE_CRS_nrofCRS_Ports = 1; + RateMatchPatternLTE_CRS_v_Shift = 0; + RateMatchPatternLTE_CRS_radioframeAllocationPeriod = 1; + RateMatchPatternLTE_CRS_radioframeAllocationOffset = 0; + RateMatchPatternLTE_CRS_subframeAllocation_choice = "oneFrame"; + } + ); + + + srb1_parameters : + { + # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500] + timer_poll_retransmit = 80; + + # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200] + timer_reordering = 35; + + # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500] + timer_status_prohibit = 0; + + # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)] + poll_pdu = 4; + + # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)] + poll_byte = 99999; + + # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32] + max_retx_threshold = 4; + } + + # ------- SCTP definitions + SCTP : + { + # Number of streams to use in input/output + SCTP_INSTREAMS = 2; + SCTP_OUTSTREAMS = 2; + }; + + + ////////// MME parameters: + mme_ip_address = ( { ipv4 = "192.168.12.26"; + ipv6 = "192:168:30::17"; + active = "yes"; + preference = "ipv4"; + } + ); + + NETWORK_INTERFACES : + { + + GNB_INTERFACE_NAME_FOR_S1_MME = "eth0"; + GNB_IPV4_ADDRESS_FOR_S1_MME = "192.168.12.111/24"; + GNB_INTERFACE_NAME_FOR_S1U = "eth0"; + GNB_IPV4_ADDRESS_FOR_S1U = "192.168.12.111/24"; + GNB_PORT_FOR_S1U = 2152; # Spec 2152 + }; + } +); + +MACRLCs = ( + { + num_cc = 1; + tr_s_preference = "local_L1"; + tr_n_preference = "local_RRC"; + } +); + +L1s = ( + { + num_cc = 1; + tr_n_preference = "local_mac"; + } +); + +RUs = ( + { + local_rf = "yes" + nb_tx = 1 + nb_rx = 1 + att_tx = 0 + att_rx = 0; + bands = [7]; + max_pdschReferenceSignalPower = -27; + max_rxgain = 114; + eNB_instances = [0]; + sdr_addrs = "addr=192.168.30.2"; + + } +); + +THREAD_STRUCT = ( + { + #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT" + parallel_config = "PARALLEL_SINGLE_THREAD"; + #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE" + worker_config = "WORKER_DISABLE"; + } +); + +NETWORK_CONTROLLER : +{ + FLEXRAN_ENABLED = "no"; + FLEXRAN_INTERFACE_NAME = "lo"; + FLEXRAN_IPV4_ADDRESS = "127.0.0.1"; + FLEXRAN_PORT = 2210; + FLEXRAN_CACHE = "/mnt/oai_agent_cache"; + FLEXRAN_AWAIT_RECONF = "no"; +}; + + log_config : + { + global_log_level ="info"; + global_log_verbosity ="medium"; + hw_log_level ="info"; + hw_log_verbosity ="medium"; + phy_log_level ="info"; + phy_log_verbosity ="medium"; + mac_log_level ="info"; + mac_log_verbosity ="high"; + rlc_log_level ="info"; + rlc_log_verbosity ="medium"; + pdcp_log_level ="info"; + pdcp_log_verbosity ="medium"; + rrc_log_level ="info"; + rrc_log_verbosity ="medium"; + }; + diff --git a/targets/RT/USER/nr-softmodem.c b/targets/RT/USER/nr-softmodem.c index 5561258694..411281d72a 100644 --- a/targets/RT/USER/nr-softmodem.c +++ b/targets/RT/USER/nr-softmodem.c @@ -961,6 +961,7 @@ int main( int argc, char **argv ) fprintf(stderr,"Getting configuration failed\n"); exit(-1); } + openair0_cfg[0].threequarter_fs = threequarter_fs; #if T_TRACER From 65160704ab0fe814bb64b206a3a32d7383debb1e Mon Sep 17 00:00:00 2001 From: Rakesh Mundlamuri Date: Fri, 19 Apr 2019 23:45:30 +0530 Subject: [PATCH 100/117] Declaration of openair0_cfg --- openair1/SIMULATION/NR_PHY/dlschsim.c | 1 + openair1/SIMULATION/NR_PHY/dlsim.c | 1 + openair1/SIMULATION/NR_PHY/pbchsim.c | 1 + openair1/SIMULATION/NR_PHY/ulschsim.c | 1 + 4 files changed, 4 insertions(+) diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 2a95768a3e..beb2f77da9 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -103,6 +103,7 @@ void exit_function(const char *file, const char *function, const int line, // needed for some functions PHY_VARS_NR_UE *PHY_vars_UE_g[1][1] = { { NULL } }; uint16_t n_rnti = 0x1234; +openair0_config_t openair0_cfg[MAX_CARDS]; char quantize(double D, double x, unsigned char B) { double qxd; diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index b95ea7502e..8917a29623 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -115,6 +115,7 @@ void config_common(int Mod_idP, // needed for some functions PHY_VARS_NR_UE ***PHY_vars_UE_g; short conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1}; +openair0_config_t openair0_cfg[MAX_CARDS]; int main(int argc, char **argv) { diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 61d4c486f5..8e00e8f812 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -80,6 +80,7 @@ void exit_function(const char* file, const char* function, const int line,const // needed for some functions PHY_VARS_NR_UE * PHY_vars_UE_g[1][1]={{NULL}}; +openair0_config_t openair0_cfg[MAX_CARDS]; int main(int argc, char **argv) { diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c index ca3860c5b0..7b5ef99e9b 100644 --- a/openair1/SIMULATION/NR_PHY/ulschsim.c +++ b/openair1/SIMULATION/NR_PHY/ulschsim.c @@ -104,6 +104,7 @@ void exit_function(const char *file, const char *function, const int line, const // needed for some functions PHY_VARS_NR_UE *PHY_vars_UE_g[1][1] = { { NULL } }; uint16_t n_rnti = 0x1234; +openair0_config_t openair0_cfg[MAX_CARDS]; char quantize(double D, double x, unsigned char B) { double qxd; From a55f4006b4bf18a508c1541efb824c6c30adf0e4 Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 23 Apr 2019 10:07:30 +0200 Subject: [PATCH 101/117] change thread/core assignment, initial commit of replay IQ --- cmake_targets/CMakeLists.txt | 18 +++ common/utils/minimal_stub.c | 4 + common/utils/simple_executable.h | 33 ++++ common/utils/threadPool/measurement_display.c | 18 +-- executables/nr-ue.c | 29 ++++ executables/nr-uesoftmodem.c | 5 +- executables/nr-uesoftmodem.h | 1 - targets/ARCH/COMMON/common_lib.h | 142 ++++++++++-------- targets/ARCH/rfsimulator/simulator.c | 53 ++++--- targets/ARCH/rfsimulator/stored_node.c | 142 ++++++++++++++++++ 10 files changed, 340 insertions(+), 105 deletions(-) create mode 100644 common/utils/minimal_stub.c create mode 100644 common/utils/simple_executable.h create mode 100644 targets/ARCH/rfsimulator/stored_node.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 7f9a4d6494..87c51ccb62 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2155,6 +2155,24 @@ add_definitions(-DASN1_MINIMUM_VERSION=924) ################################# # add executables for operation ################################# +add_library(minimal_lib + ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/LOG/log.c + ${OPENAIR_DIR}/common/config/config_userapi.c + ${OPENAIR_DIR}/common/config/config_load_configmodule.c + ${OPENAIR_DIR}/common/config/config_cmdline.c + ${OPENAIR_DIR}/common/utils/minimal_stub.c + ) +target_link_libraries(minimal_lib pthread dl) + +add_executable(replay_node + ${OPENAIR_TARGETS}/ARCH/rfsimulator/stored_node.c + ) +target_link_libraries (replay_node minimal_lib) + +add_executable(measurement_display + ${OPENAIR_DIR}/common/utils/threadPool/measurement_display.c) +target_link_libraries (measurement_display minimal_lib) # lte-softmodem is both eNB and UE implementation ################################################### diff --git a/common/utils/minimal_stub.c b/common/utils/minimal_stub.c new file mode 100644 index 0000000000..86454fe53f --- /dev/null +++ b/common/utils/minimal_stub.c @@ -0,0 +1,4 @@ +int T_stdout; + +void exit_function(const char *file, const char *function, const int line, const char *s) { +} diff --git a/common/utils/simple_executable.h b/common/utils/simple_executable.h new file mode 100644 index 0000000000..97b29dd502 --- /dev/null +++ b/common/utils/simple_executable.h @@ -0,0 +1,33 @@ +#ifndef __SIMPLE_EXE_H__ +#define __SIMPLE_EXE_H__ +#define __USE_GNU +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common_lib.h" + +#ifdef T + #undef T + #define T(...) +#endif + +#endif diff --git a/common/utils/threadPool/measurement_display.c b/common/utils/threadPool/measurement_display.c index ac7beca1fe..8f6e2c239a 100644 --- a/common/utils/threadPool/measurement_display.c +++ b/common/utils/threadPool/measurement_display.c @@ -2,22 +2,8 @@ Author: Laurent THOMAS, Open Cells copyleft: OpenAirInterface Software Alliance and it's licence */ +#include -#define __USE_GNU -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "thread-pool.h" #define SEP "\t" @@ -26,7 +12,7 @@ uint64_t cpuCyclesMicroSec; int main(int argc, char *argv[]) { if(argc != 2) { - printf("Need one paramter: the trace Linux pipe (fifo)"); + printf("Need one parameter: the trace Linux pipe (fifo)"); exit(1); } diff --git a/executables/nr-ue.c b/executables/nr-ue.c index cf0db42443..7c96f14159 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -125,6 +125,34 @@ extern double cpuf; #define DAQ_PERIOD 66667ULL #define FIFO_PRIORITY 40 + +void init_thread(int core, char *name) { + pthread_setname_np(pthread_self(),name); + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + + if (core >0) + CPU_SET(core, &cpuset); + + AssertFatal( 0 == pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset), ""); + struct sched_param sp; + sp.sched_priority = FIFO_PRIORITY; + AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO,&sp)==0, + "Can't set thread priority, Are you root?\n"); + /* Check the actual affinity mask assigned to the thread */ + cpu_set_t *cset=CPU_ALLOC(CPU_SETSIZE); + + if (0 == pthread_getaffinity_np(pthread_self(), CPU_ALLOC_SIZE(CPU_SETSIZE), cset)) { + char txt[512]= {0}; + + for (int j = 0; j < CPU_SETSIZE; j++) + if (CPU_ISSET(j, cset)) + sprintf(txt+strlen(txt), " %d ", j); + + printf("CPU Affinity of thread %s is %s\n", name, txt); + } +} + typedef enum { pss=0, pbch=1, @@ -535,6 +563,7 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) { } void *UE_thread(void *arg) { + init_thread(1, "IQ samples"); PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; // int tx_enabled = 0; openair0_timestamp timestamp; diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 24f8d4eb0d..0a2f0ac2d5 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -541,7 +541,6 @@ void set_default_frame_parms(NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { frame_parms[CC_id]->nb_antennas_tx = 1; frame_parms[CC_id]->nb_antennas_rx = 1; //frame_parms[CC_id]->nushift = 0; - // NR: Init to legacy LTE 20Mhz params frame_parms[CC_id]->numerology_index = 0; frame_parms[CC_id]->ttis_per_subframe = 1; @@ -685,7 +684,7 @@ int main( int argc, char **argv ) { set_taus_seed (0); tpool_t pool; Tpool = &pool; - char params[]="-1,-1,-1,-1"; + char params[]="2,3"; initTpool(params, Tpool, false); cpuf=get_cpu_freq_GHz(); itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); @@ -712,9 +711,7 @@ int main( int argc, char **argv ) { frame_parms[CC_id]->nb_antennas_rx = nb_antenna_rx; frame_parms[CC_id]->nb_antenna_ports_eNB = 1; //initial value overwritten by initial sync later LOG_I(PHY,"Set nb_rx_antenna %d , nb_tx_antenna %d \n",frame_parms[CC_id]->nb_antennas_rx, frame_parms[CC_id]->nb_antennas_tx); - get_band(downlink_frequency[CC_id][0], &frame_parms[CC_id]->eutra_band, &uplink_frequency_offset[CC_id][0], &frame_parms[CC_id]->frame_type); - } NB_UE_INST=1; diff --git a/executables/nr-uesoftmodem.h b/executables/nr-uesoftmodem.h index 8bc07936f6..078a8066c3 100644 --- a/executables/nr-uesoftmodem.h +++ b/executables/nr-uesoftmodem.h @@ -236,7 +236,6 @@ extern double cpuf; extern int setup_ue_buffers(PHY_VARS_NR_UE **phy_vars_ue, openair0_config_t *openair0_cfg); extern void fill_ue_band_info(void); extern void init_UE(int); -extern void init_thread(int sched_runtime, int sched_deadline, int sched_fifo, cpu_set_t *cpuset, char *name); extern void reset_opp_meas(void); extern void print_opp_meas(void); void *UE_thread(void *arg); diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h index d14b2457c9..09ad515324 100644 --- a/targets/ARCH/COMMON/common_lib.h +++ b/targets/ARCH/COMMON/common_lib.h @@ -19,8 +19,8 @@ * contact@openairinterface.org */ -/*! \file common_lib.h - * \brief common APIs for different RF frontend device +/*! \file common_lib.h + * \brief common APIs for different RF frontend device * \author HongliangXU, Navid Nikaein * \date 2015 * \version 0.2 @@ -45,21 +45,16 @@ #define RAU_REMOTE_RADIO_HEAD 1 #ifndef MAX_CARDS -#define MAX_CARDS 8 + #define MAX_CARDS 8 #endif typedef int64_t openair0_timestamp; typedef volatile int64_t openair0_vtimestamp; - + /*!\brief structrue holds the parameters to configure USRP devices*/ typedef struct openair0_device_t openair0_device; - - - - - //#define USRP_GAIN_OFFSET (56.0) // 86 calibrated for USRP B210 @ 2.6 GHz to get equivalent RS EPRE in OAI to SMBV100 output typedef enum { @@ -80,9 +75,6 @@ typedef enum { */ /*!\brief RF device types */ -#ifdef OCP_FRAMEWORK -#include -#else typedef enum { MIN_RF_DEV_TYPE = 0, /*!\brief device is ExpressMIMO */ @@ -104,7 +96,6 @@ typedef enum { MAX_RF_DEV_TYPE } dev_type_t; -#endif /*!\brief transport protocol types */ @@ -122,16 +113,16 @@ typedef enum { /*!\brief openair0 device host type */ typedef enum { MIN_HOST_TYPE = 0, - /*!\brief device functions within a RAU */ + /*!\brief device functions within a RAU */ RAU_HOST, - /*!\brief device functions within a RRU */ + /*!\brief device functions within a RRU */ RRU_HOST, MAX_HOST_TYPE -}host_type_t; +} host_type_t; -/*! \brief RF Gain clibration */ +/*! \brief RF Gain clibration */ typedef struct { //! Frequency for which RX chain was calibrated double freq; @@ -159,7 +150,7 @@ typedef struct { duplex_mode_t duplex_mode; //! number of downlink resource blocks int num_rb_dl; - //! number of samples per frame + //! number of samples per frame unsigned int samples_per_frame; //! the sample rate for both transmit and receive. double sample_rate; @@ -174,9 +165,9 @@ typedef struct { //! number of TX channels (=TX antennas) int tx_num_channels; //! \brief RX base addresses for mmapped_dma - int32_t* rxbase[4]; + int32_t *rxbase[4]; //! \brief TX base addresses for mmapped_dma - int32_t* txbase[4]; + int32_t *txbase[4]; //! \brief Center frequency in Hz for RX. //! index: [0..rx_num_channels[ double rx_freq[4]; @@ -187,7 +178,7 @@ typedef struct { //! \brief Pointer to Calibration table for RX gains rx_gain_calib_table_t *rx_gain_calib_table; - //! mode for rxgain (ExpressMIMO2) + //! mode for rxgain (ExpressMIMO2) rx_gain_t rxg_mode[4]; //! \brief Gain for RX in dB. //! index: [0..rx_num_channels] @@ -201,15 +192,15 @@ typedef struct { double rx_bw; //! TX bandwidth in Hz double tx_bw; - //! clock source + //! clock source clock_source_t clock_source; //! Manual SDR IP address -//#if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) + //#if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR) char *sdr_addrs; //! Auto calibration flag int autocal[4]; //! rf devices work with x bits iqs when oai have its own iq format - //! the two following parameters are used to convert iqs + //! the two following parameters are used to convert iqs int iq_txshift; int iq_rxrescale; //! Configuration file for LMS7002M @@ -230,7 +221,7 @@ typedef struct { unsigned int sf_read_delay; // read delay in replay mode unsigned int sf_write_delay; // write delay in replay mode unsigned int eth_mtu; // ethernet MTU -#endif +#endif //! number of samples per tti unsigned int samples_per_tti; @@ -241,7 +232,7 @@ typedef struct { } openair0_config_t; -/*! \brief RF mapping */ +/*! \brief RF mapping */ typedef struct { //! card id int card; @@ -288,14 +279,14 @@ struct openair0_device_t { /*!brief Component Carrier ID of this device */ int CC_id; - + /*!brief Type of this device */ dev_type_t type; /*!brief Transport protocol type that the device suppports (in case I/Q samples need to be transported) */ transport_type_t transp_type; - /*!brief Type of the device's host (RAU/RRU) */ + /*!brief Type of the device's host (RAU/RRU) */ host_type_t host_type; /* !brief RF frontend parameters set by application */ @@ -317,25 +308,25 @@ struct openair0_device_t { /*! \brief Called to send a request message between RAU-RRU on control port @param device pointer to the device structure specific to the RF hardware target @param msg pointer to the message structure passed between RAU-RRU - @param msg_len length of the message - */ + @param msg_len length of the message + */ int (*trx_ctlsend_func)(openair0_device *device, void *msg, ssize_t msg_len); /*! \brief Called to receive a reply message between RAU-RRU on control port @param device pointer to the device structure specific to the RF hardware target @param msg pointer to the message structure passed between RAU-RRU - @param msg_len length of the message - */ + @param msg_len length of the message + */ int (*trx_ctlrecv_func)(openair0_device *device, void *msg, ssize_t msg_len); /*! \brief Called to send samples to the RF target @param device pointer to the device structure specific to the RF hardware target - @param timestamp The timestamp at whicch the first sample MUST be sent + @param timestamp The timestamp at whicch the first sample MUST be sent @param buff Buffer which holds the samples @param nsamps number of samples to be sent @param antenna_id index of the antenna if the device has multiple anteannas @param flags flags must be set to TRUE if timestamp parameter needs to be applied - */ + */ int (*trx_write_func)(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps,int antenna_id, int flags); /*! \brief Receive samples from hardware. @@ -351,55 +342,80 @@ struct openair0_device_t { */ int (*trx_read_func)(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps,int antenna_id); - /*! \brief print the device statistics + /*! \brief print the device statistics * \param device the hardware to use * \returns 0 on success */ int (*trx_get_stats_func)(openair0_device *device); - /*! \brief Reset device statistics + /*! \brief Reset device statistics * \param device the hardware to use - * \returns 0 in success + * \returns 0 in success */ int (*trx_reset_stats_func)(openair0_device *device); - /*! \brief Terminate operation of the transceiver -- free all associated resources + /*! \brief Terminate operation of the transceiver -- free all associated resources * \param device the hardware to use */ void (*trx_end_func)(openair0_device *device); - /*! \brief Stop operation of the transceiver + /*! \brief Stop operation of the transceiver */ int (*trx_stop_func)(openair0_device *device); /* Functions API related to UE*/ - /*! \brief Set RX feaquencies + /*! \brief Set RX feaquencies * \param device the hardware to use * \param openair0_cfg RF frontend parameters set by application - * \param exmimo_dump_config dump EXMIMO configuration - * \returns 0 in success + * \param exmimo_dump_config dump EXMIMO configuration + * \returns 0 in success */ - int (*trx_set_freq_func)(openair0_device* device, openair0_config_t *openair0_cfg,int exmimo_dump_config); - + int (*trx_set_freq_func)(openair0_device *device, openair0_config_t *openair0_cfg,int exmimo_dump_config); + /*! \brief Set gains * \param device the hardware to use * \param openair0_cfg RF frontend parameters set by application - * \returns 0 in success + * \returns 0 in success */ - int (*trx_set_gains_func)(openair0_device* device, openair0_config_t *openair0_cfg); + int (*trx_set_gains_func)(openair0_device *device, openair0_config_t *openair0_cfg); /*! \brief RRU Configuration callback * \param idx RU index * \param arg pointer to capabilities or configuration */ - void (*configure_rru)(int idx, void* arg); + void (*configure_rru)(int idx, void *arg); }; /* type of device init function, implemented in shared lib */ typedef int(*oai_device_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg); /* type of transport init function, implemented in shared lib */ -typedef int(*oai_transport_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params); +typedef int(*oai_transport_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t *eth_params); +#define UE_MAGICDL_FDD 0xA5A5A5A5A5A5A5A5 // UE DL FDD record +#define UE_MAGICUL_FDD 0x5A5A5A5A5A5A5A5A // UE UL FDD record +#define UE_MAGICDL_TDD 0xA6A6A6A6A6A6A6A6 // UE DL TDD record +#define UE_MAGICUL_TDD 0x6A6A6A6A6A6A6A6A // UE UL TDD record + +#define ENB_MAGICDL_FDD 0xB5B5B5B5B5B5B5B5 // eNB DL FDD record +#define ENB_MAGICUL_FDD 0x5B5B5B5B5B5B5B5B // eNB UL FDD record +#define ENB_MAGICDL_TDD 0xB6B6B6B6B6B6B6B6 // eNB DL TDD record +#define ENB_MAGICUL_TDD 0x6B6B6B6B6B6B6B6B // eNB UL TDD record + +#define OPTION_LZ4 0x00000001 // LZ4 compression (option_value is set to compressed size) + +#define sample_t uint32_t // 2*16 bits complex number + +typedef struct { + uint64_t magic; // Magic value (see defines above) + uint32_t size; // Number of samples per antenna to follow this header + uint32_t nbAnt; // Total number of antennas following this header + // Samples per antenna follow this header, + // i.e. nbAnt = 2 => this header+samples_antenna_0+samples_antenna_1 + // data following this header in bytes is nbAnt*size*sizeof(sample_t) + uint64_t timestamp; // Timestamp value of first sample + uint32_t option_value; // Option value + uint32_t option_flag; // Option flag +} samplesBlockHeader_t; #ifdef __cplusplus extern "C" @@ -407,23 +423,23 @@ extern "C" #endif - /*! \brief Initialize openair RF target. It returns 0 if OK */ - int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg); - /*! \brief Initialize transport protocol . It returns 0 if OK */ - int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params); +/*! \brief Initialize openair RF target. It returns 0 if OK */ +int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg); +/*! \brief Initialize transport protocol . It returns 0 if OK */ +int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t *eth_params); - - /*! \brief Get current timestamp of USRP - * \param device the hardware to use - */ - openair0_timestamp get_usrp_time(openair0_device *device); - /*! \brief Set RX frequencies - * \param device the hardware to use - * \param openair0_cfg RF frontend parameters set by application - * \returns 0 in success - */ - int openair0_set_rx_frequencies(openair0_device* device, openair0_config_t *openair0_cfg); +/*! \brief Get current timestamp of USRP + * \param device the hardware to use + */ +openair0_timestamp get_usrp_time(openair0_device *device); + +/*! \brief Set RX frequencies + * \param device the hardware to use + * \param openair0_cfg RF frontend parameters set by application + * \returns 0 in success + */ +int openair0_set_rx_frequencies(openair0_device *device, openair0_config_t *openair0_cfg); #define gettid() syscall(__NR_gettid) /*@}*/ diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c index a17327b03e..0edc587263 100644 --- a/targets/ARCH/rfsimulator/simulator.c +++ b/targets/ARCH/rfsimulator/simulator.c @@ -27,22 +27,15 @@ #define sample_t uint32_t // 2*16 bits complex number #define sampleToByte(a,b) ((a)*(b)*sizeof(sample_t)) #define byteToSample(a,b) ((a)/(sizeof(sample_t)*(b))) -#define MAGICeNB 0xA5A5A5A5A5A5A5A5 -#define MAGICUE 0x5A5A5A5A5A5A5A5A -typedef struct { - uint64_t magic; - uint32_t size; - uint32_t nbAnt; - uint64_t timestamp; -} transferHeader; +#define sample_t uint32_t // 2*16 bits complex number typedef struct buffer_s { int conn_sock; bool alreadyRead; uint64_t lastReceivedTS; bool headerMode; - transferHeader th; + samplesBlockHeader_t th; char *transferPtr; uint64_t remainToTransfer; char *circularBufEnd; @@ -55,6 +48,7 @@ typedef struct { uint64_t typeStamp; uint64_t initialAhead; char *ip; + int saveIQfile; buffer_t buf[FD_SETSIZE]; } rfsimulator_state_t; @@ -65,7 +59,7 @@ void allocCirBuf(rfsimulator_state_t *bridge, int sock) { ptr->conn_sock=sock; ptr->headerMode=true; ptr->transferPtr=(char *)&ptr->th; - ptr->remainToTransfer=sizeof(transferHeader); + ptr->remainToTransfer=sizeof(samplesBlockHeader_t); int sendbuff=1000*1000*10; AssertFatal ( setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sendbuff, sizeof(sendbuff)) == 0, ""); struct epoll_event ev= {0}; @@ -87,7 +81,7 @@ void socketError(rfsimulator_state_t *bridge, int sock) { LOG_W(HW,"Lost socket \n"); removeCirBuf(bridge, sock); - if (bridge->typeStamp==MAGICUE) + if (bridge->typeStamp==UE_MAGICDL_FDD) exit(1); } } @@ -120,6 +114,11 @@ void setblocking(int sock, enum blocking_t active) { static bool flushInput(rfsimulator_state_t *t); void fullwrite(int fd, void *_buf, int count, rfsimulator_state_t *t) { + if (t->saveIQfile != -1) { + if (write(t->saveIQfile, _buf, count) != count ) + LOG_E(HW,"write in save iq file failed (%s)\n",strerror(errno)); + } + char *buf = _buf; int l; setblocking(fd, notBlocking); @@ -145,7 +144,7 @@ void fullwrite(int fd, void *_buf, int count, rfsimulator_state_t *t) { int server_start(openair0_device *device) { rfsimulator_state_t *t = (rfsimulator_state_t *) device->priv; - t->typeStamp=MAGICeNB; + t->typeStamp=ENB_MAGICDL_FDD; AssertFatal((t->listen_sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, ""); int enable = 1; AssertFatal(setsockopt(t->listen_sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) == 0, ""); @@ -168,7 +167,7 @@ sin_addr: int start_ue(openair0_device *device) { rfsimulator_state_t *t = device->priv; - t->typeStamp=MAGICUE; + t->typeStamp=UE_MAGICDL_FDD; int sock; AssertFatal((sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, ""); struct sockaddr_in addr = { @@ -207,7 +206,7 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi buffer_t *ptr=&t->buf[i]; if (ptr->conn_sock >= 0 ) { - transferHeader header= {t->typeStamp, nsamps, nbAnt, timestamp}; + samplesBlockHeader_t header= {t->typeStamp, nsamps, nbAnt, timestamp}; fullwrite(ptr->conn_sock,&header, sizeof(header), t); sample_t tmpSamples[nsamps][nbAnt]; @@ -290,8 +289,8 @@ static bool flushInput(rfsimulator_state_t *t) { // check the header and start block transfer if ( b->headerMode==true && b->remainToTransfer==0) { - AssertFatal( (t->typeStamp == MAGICUE && b->th.magic==MAGICeNB) || - (t->typeStamp == MAGICeNB && b->th.magic==MAGICUE), "Socket Error in protocol"); + AssertFatal( (t->typeStamp == UE_MAGICDL_FDD && b->th.magic==ENB_MAGICDL_FDD) || + (t->typeStamp == ENB_MAGICDL_FDD && b->th.magic==UE_MAGICDL_FDD), "Socket Error in protocol"); b->headerMode=false; b->alreadyRead=true; @@ -322,7 +321,7 @@ static bool flushInput(rfsimulator_state_t *t) { b->headerMode=true; b->transferPtr=(char *)&b->th; - b->remainToTransfer=sizeof(transferHeader); + b->remainToTransfer=sizeof(samplesBlockHeader_t); b->th.magic=-1; } } @@ -447,10 +446,22 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { } rfsimulator->typeStamp = strncasecmp(rfsimulator->ip,"enb",3) == 0 ? - MAGICeNB: - MAGICUE; - LOG_I(HW,"rfsimulator: running as %s\n", rfsimulator-> typeStamp == MAGICeNB ? "eNB" : "UE"); - device->trx_start_func = rfsimulator->typeStamp == MAGICeNB ? + ENB_MAGICDL_FDD: + UE_MAGICDL_FDD; + LOG_I(HW,"rfsimulator: running as %s\n", rfsimulator-> typeStamp == ENB_MAGICDL_FDD ? "eNB" : "UE"); + char *saveF; + + if ((saveF=getenv("saveIQfile")) != NULL) { + rfsimulator->saveIQfile=open(saveF,O_APPEND| O_CREAT|O_TRUNC | O_WRONLY, 0666); + + if ( rfsimulator->saveIQfile != -1 ) + LOG_I(HW,"rfsimulator: will save written IQ samples in %s\n", saveF); + else + LOG_E(HW, "can't open %s for IQ saving (%s)\n", saveF, strerror(errno)); + } else + rfsimulator->saveIQfile = -1; + + device->trx_start_func = rfsimulator->typeStamp == ENB_MAGICDL_FDD ? server_start : start_ue; device->trx_get_stats_func = rfsimulator_get_stats; diff --git a/targets/ARCH/rfsimulator/stored_node.c b/targets/ARCH/rfsimulator/stored_node.c new file mode 100644 index 0000000000..7380f5f304 --- /dev/null +++ b/targets/ARCH/rfsimulator/stored_node.c @@ -0,0 +1,142 @@ +/* + Author: Laurent THOMAS, Open Cells + copyleft: OpenAirInterface Software Alliance and it's licence +*/ + +#include + + +void fullwrite(int fd, void *_buf, int count) { + char *buf = _buf; + int l; + + while (count) { + l = write(fd, buf, count); + + if (l <= 0) { + if (errno==EINTR) + continue; + + if(errno==EAGAIN) { + continue; + } else { + AssertFatal(false,"Lost socket\n"); + } + + count -= l; + buf += l; + } + } +} + +int server_start(short port) { + int listen_sock; + AssertFatal((listen_sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, ""); + int enable = 1; + AssertFatal(setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) == 0, ""); + struct sockaddr_in addr = { +sin_family: + AF_INET, +sin_port: + htons(port), +sin_addr: + { s_addr: INADDR_ANY } + }; + bind(listen_sock, (struct sockaddr *)&addr, sizeof(addr)); + AssertFatal(listen(listen_sock, 5) == 0, ""); + return accept(listen_sock,NULL,NULL); +} + +int client_start(char *IP, short port) { + int sock; + AssertFatal((sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, ""); + struct sockaddr_in addr = { +sin_family: + AF_INET, +sin_port: + htons(port), +sin_addr: + { s_addr: INADDR_ANY } + }; + addr.sin_addr.s_addr = inet_addr(IP); + bool connected=false; + + while(!connected) { + LOG_I(HW,"rfsimulator: trying to connect to %s:%d\n", IP, port); + + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) { + LOG_I(HW,"rfsimulator: connection established\n"); + connected=true; + } + + perror("simulated node"); + sleep(1); + } + + return sock; +} + +enum blocking_t { + notBlocking, + blocking +}; + +void setblocking(int sock, enum blocking_t active) { + int opts; + AssertFatal( (opts = fcntl(sock, F_GETFL)) >= 0,""); + + if (active==blocking) + opts = opts & ~O_NONBLOCK; + else + opts = opts | O_NONBLOCK; + + AssertFatal(fcntl(sock, F_SETFL, opts) >= 0, ""); +} + +int main(int argc, char *argv[]) { + if(argc != 4) { + printf("Need parameters: source file, server or destination IP, TCP port\n"); + exit(1); + } + + int fd; + AssertFatal((fd=open(argv[1],O_RDONLY)) != -1, "file: %s", argv[1]); + off_t fileSize=lseek(fd, 0, SEEK_END); + int serviceSock; + + if (strcmp(argv[2],"server")==0) { + serviceSock=server_start(atoi(argv[3])); + } else { + client_start(argv[2],atoi(argv[3])); + } + + samplesBlockHeader_t header; + int bufSize=100000; + void *buff=malloc(bufSize); + + while (1) { + //Rewind the file to loop on the samples + if ( lseek(fd, 0, SEEK_CUR) >= fileSize ) + lseek(fd, 0, SEEK_SET); + + // Read one block and send it + setblocking(serviceSock, blocking); + AssertFatal(read(fd,&header,sizeof(header)), ""); + fullwrite(serviceSock, &header, sizeof(header)); + int dataSize=sizeof(sample_t)*header.size*header.nbAnt; + + if (dataSize>bufSize) + buff=realloc(buff,dataSize); + + AssertFatal(read(fd,buff,dataSize) == dataSize, ""); + fullwrite(serviceSock, buff, dataSize); + // Purge incoming samples + setblocking(serviceSock, notBlocking); + + while(recv(serviceSock,buff, bufSize, MSG_DONTWAIT) > 0) { + } + } + + return 0; +} + From db79d72b370a96387fe1ea590fdbe1e873a189ca Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 23 Apr 2019 12:24:20 +0200 Subject: [PATCH 102/117] fix test replay --- targets/ARCH/rfsimulator/stored_node.c | 2 +- targets/RT/USER/lte-uesoftmodem.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/targets/ARCH/rfsimulator/stored_node.c b/targets/ARCH/rfsimulator/stored_node.c index 7380f5f304..888b5f6de0 100644 --- a/targets/ARCH/rfsimulator/stored_node.c +++ b/targets/ARCH/rfsimulator/stored_node.c @@ -22,7 +22,7 @@ void fullwrite(int fd, void *_buf, int count) { } else { AssertFatal(false,"Lost socket\n"); } - + } else { count -= l; buf += l; } diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 617756e722..9b8ea00123 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -431,6 +431,7 @@ static void *scope_thread(void *arg) { PHY_vars_UE_g[0][0], 0, 0,7); + usleep(10000); // printf("%s",stats_buffer); } From b11f6b07f27c275713e7524388fe29d8db7de251 Mon Sep 17 00:00:00 2001 From: "Bi-Ruei, Chiu" Date: Wed, 24 Apr 2019 23:50:22 +0800 Subject: [PATCH 103/117] Update asn1c commit to solve three issues 1. Fix code generated from ASN.1 of F1AP v15.4.0 failed to be compiled 2. Fix incorrect UPER encoding for empty extensible SEQUENCE in 38.331 3. Fix the problem that duplicate type names exist in OPEN TYPE --- cmake_targets/tools/build_helper | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper index 8c5d33975c..1c4b291069 100755 --- a/cmake_targets/tools/build_helper +++ b/cmake_targets/tools/build_helper @@ -683,7 +683,7 @@ install_asn1c_from_source(){ # better to use a given commit than a branch in case the branch # is updated and requires modifications in the source of OAI #git checkout velichkov_s1ap_plus_option_group - git checkout d3aed06bb2bec7df1b5c6d0333f8c7dfc5993372 + git checkout f12568d617dbf48497588f8e227d70388fa217c9 autoreconf -iv ./configure make -j`nproc` From 8a92138086c642721e074cbd2271d8760bc42552 Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 30 Apr 2019 10:17:08 +0200 Subject: [PATCH 104/117] rework threads in 5G --- cmake_targets/CMakeLists.txt | 25 +- common/utils/ocp_itti/intertask_interface.cpp | 17 +- common/utils/system.c | 136 +- common/utils/system.h | 24 + common/utils/threadPool/thread-pool.c | 26 +- common/utils/threadPool/thread-pool.h | 1 + executables/nr-gnb.c | 952 +++++++ executables/nr-ru.c | 2312 +++++++++++++++++ executables/nr-softmodem.c | 1243 +++++++++ executables/nr-softmodem.h | 251 ++ executables/nr-ue.c | 45 +- executables/nr-uesoftmodem.c | 14 +- executables/openairinterface5g_limits.h | 89 + executables/stats.c | 50 + executables/stats.h | 46 + executables/threads_t.h | 21 + openair1/PHY/NR_TRANSPORT/nr_dci_tools.c | 2 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 27 +- openair1/SCHED_NR/nr_ru_procedures.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 1 - openair2/ENB_APP/RRC_config_tools.h | 2 +- openair2/ENB_APP/flexran_agent.c | 39 +- openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c | 23 +- openair2/RRC/LTE/rrc_UE.c | 22 +- openair2/RRC/NR/L2_nr_interface.c | 1 - openair2/RRC/NR/rrc_gNB.c | 5 +- openair2/UTIL/ASYNC_IF/link_manager.c | 32 +- openair2/UTIL/CLI/cli_server.c | 5 +- openair2/UTIL/OPT/probe.c | 11 +- openair2/UTIL/OTG/otg_rx_socket.c | 12 +- openair3/NAS/UE/UEprocess.c | 18 +- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 3 + targets/RT/USER/lte-uesoftmodem.c | 2 +- 33 files changed, 5174 insertions(+), 285 deletions(-) create mode 100644 executables/nr-gnb.c create mode 100644 executables/nr-ru.c create mode 100644 executables/nr-softmodem.c create mode 100644 executables/nr-softmodem.h create mode 100644 executables/openairinterface5g_limits.h create mode 100644 executables/stats.c create mode 100644 executables/stats.h create mode 100644 executables/threads_t.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 87c51ccb62..cb9c181a94 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -754,6 +754,7 @@ include_directories("${OPENAIR_BIN_DIR}") # Legacy exact order +include_directories("${OPENAIR_DIR}/executables") include_directories("${OPENAIR2_DIR}/COMMON") include_directories("${OPENAIR2_DIR}/UTIL") include_directories("${OPENAIR2_DIR}/UTIL/LOG") @@ -792,10 +793,7 @@ include_directories("${OPENAIR3_DIR}/S1AP") include_directories("${OPENAIR2_DIR}/X2AP") include_directories("${OPENAIR3_DIR}/UDP") include_directories("${OPENAIR3_DIR}/GTPV1-U") -include_directories("${OPENAIR_DIR}/targets/COMMON") include_directories("${OPENAIR_DIR}/targets/ARCH/COMMON") -include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/USERSPACE/LIB/") -include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/DEFS") include_directories("${OPENAIR2_DIR}/ENB_APP") include_directories("${OPENAIR2_DIR}/GNB_APP") include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC") @@ -2107,7 +2105,7 @@ if (${XFORMS}) ${OPENAIR1_DIR}/PHY/TOOLS/nr_phy_scope.c ) set(XFORMS_SOURCE_SOFTMODEM - ${OPENAIR_TARGETS}/RT/USER/stats.c + ${OPENAIR_DIR}/executables/stats.c ) set(XFORMS_LIBRARIES "forms") endif (${XFORMS}) @@ -2335,12 +2333,10 @@ add_executable(nr-softmodem ${nr_rrc_h} ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h - ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c - ${OPENAIR_TARGETS}/RT/USER/nr-gnb.c - ${OPENAIR_TARGETS}/RT/USER/nr-ru.c - ${OPENAIR_TARGETS}/RT/USER/nr-softmodem.c + ${OPENAIR_DIR}/executables/nr-gnb.c + ${OPENAIR_DIR}/executables/nr-ru.c + ${OPENAIR_DIR}/executables/nr-softmodem.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c - ${OPENAIR_TARGETS}/COMMON/create_nr_tasks.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c ${OPENAIR_DIR}/common/utils/utils.c @@ -2373,13 +2369,10 @@ add_executable(nr-softmodem-nos1 ${rrc_h} ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h - ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c - ${OPENAIR_TARGETS}/RT/USER/nr-gnb.c - ${OPENAIR_TARGETS}/RT/USER/nr-ru.c - ${OPENAIR_TARGETS}/RT/USER/nr-softmodem.c + ${OPENAIR_DIR}/executables/nr-gnb.c + ${OPENAIR_DIR}/executables/nr-ru.c + ${OPENAIR_DIR}/executables/nr-softmodem.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c - ${OPENAIR_TARGETS}/COMMON/create_tasks.c - ${OPENAIR_TARGETS}/COMMON/create_nr_tasks.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c @@ -2448,11 +2441,9 @@ add_executable(nr-uesoftmodem-nos1 ${rrc_h} ${s1ap_h} # ${OPENAIR_BIN_DIR}/messages_xml.h - ${OPENAIR_TARGETS}/RT/USER/rt_wrapper.c ${OPENAIR_DIR}/executables/nr-ue.c ${OPENAIR_DIR}/executables/nr-uesoftmodem.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c - #${OPENAIR_TARGETS}/COMMON/create_tasks_ue.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c ${OPENAIR_DIR}/common/utils/utils.c diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp index 5b8d1a430e..e896413b68 100644 --- a/common/utils/ocp_itti/intertask_interface.cpp +++ b/common/utils/ocp_itti/intertask_interface.cpp @@ -8,6 +8,7 @@ #include +#include typedef struct timer_elm_s { timer_type_t type; ///< Timer type @@ -280,22 +281,8 @@ extern "C" { int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *args_p) { task_list_t *t=&tasks[task_id]; - AssertFatal ( pthread_create (&t->thread, NULL, start_routine, args_p) ==0, - "Thread creation for task %d failed!\n", task_id); - pthread_setname_np( t->thread, itti_get_task_name(task_id) ); + threadCreate (&t->thread, start_routine, args_p, itti_get_task_name(task_id),-1,OAI_PRIORITY_RT); LOG_I(TMR,"Created Posix thread %s\n", itti_get_task_name(task_id) ); -#if 1 // BMC test RT prio - { - int policy; - struct sched_param sparam; - memset(&sparam, 0, sizeof(sparam)); - sparam.sched_priority = sched_get_priority_max(SCHED_FIFO)-10; - policy = SCHED_FIFO ; - if (pthread_setschedparam(t->thread, policy, &sparam) != 0) { - LOG_E(TMR,"task %s : Failed to set pthread priority\n", itti_get_task_name(task_id) ); - } - } -#endif return 0; } diff --git a/common/utils/system.c b/common/utils/system.c index dcec681e2d..90e5185a67 100644 --- a/common/utils/system.c +++ b/common/utils/system.c @@ -28,13 +28,23 @@ * separate process solves this problem. */ +#define _GNU_SOURCE #include "system.h" #include #include #include #include #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define MAX_COMMAND 4096 static int command_pipe_read; @@ -50,37 +60,37 @@ static int module_initialized = 0; /* util functions */ /********************************************************************/ -static void lock_system(void) -{ +static void lock_system(void) { if (pthread_mutex_lock(&lock) != 0) { printf("pthread_mutex_lock fails\n"); abort(); } } -static void unlock_system(void) -{ +static void unlock_system(void) { if (pthread_mutex_unlock(&lock) != 0) { printf("pthread_mutex_unlock fails\n"); abort(); } } -static void write_pipe(int p, char *b, int size) -{ +static void write_pipe(int p, char *b, int size) { while (size) { int ret = write(p, b, size); + if (ret <= 0) exit(0); + b += ret; size -= ret; } } -static void read_pipe(int p, char *b, int size) -{ +static void read_pipe(int p, char *b, int size) { while (size) { int ret = read(p, b, size); + if (ret <= 0) exit(0); + b += ret; size -= ret; } @@ -95,14 +105,13 @@ static void read_pipe(int p, char *b, int size) * when the main process exits, because then a "read" on the pipe * will return 0, in which case "read_pipe" exits. */ -static void background_system_process(void) -{ +static void background_system_process(void) { int len; int ret; char command[MAX_COMMAND+1]; while (1) { - read_pipe(command_pipe_read, (char*)&len, sizeof(int)); + read_pipe(command_pipe_read, (char *)&len, sizeof(int)); read_pipe(command_pipe_read, command, len); ret = system(command); write_pipe(result_pipe_write, (char *)&ret, sizeof(int)); @@ -114,8 +123,7 @@ static void background_system_process(void) /* return -1 on error, 0 on success */ /********************************************************************/ -int background_system(char *command) -{ +int background_system(char *command) { int res; int len; @@ -125,18 +133,22 @@ int background_system(char *command) } len = strlen(command)+1; + if (len > MAX_COMMAND) { printf("FATAL: command too long. Increase MAX_COMMAND (%d).\n", MAX_COMMAND); printf("command was: '%s'\n", command); abort(); } + /* only one command can run at a time, so let's lock/unlock */ lock_system(); - write_pipe(command_pipe_write, (char*)&len, sizeof(int)); + write_pipe(command_pipe_write, (char *)&len, sizeof(int)); write_pipe(command_pipe_write, command, len); - read_pipe(result_pipe_read, (char*)&res, sizeof(int)); + read_pipe(result_pipe_read, (char *)&res, sizeof(int)); unlock_system(); + if (res == -1 || !WIFEXITED(res) || WEXITSTATUS(res) != 0) return -1; + return 0; } @@ -146,17 +158,16 @@ int background_system(char *command) /* to be called very early by the main processing */ /********************************************************************/ -void start_background_system(void) -{ +void start_background_system(void) { int p[2]; pid_t son; - module_initialized = 1; if (pipe(p) == -1) { perror("pipe"); exit(1); } + command_pipe_read = p[0]; command_pipe_write = p[1]; @@ -164,10 +175,11 @@ void start_background_system(void) perror("pipe"); exit(1); } + result_pipe_read = p[0]; result_pipe_write = p[1]; - son = fork(); + if (son == -1) { perror("fork"); exit(1); @@ -181,6 +193,88 @@ void start_background_system(void) close(result_pipe_read); close(command_pipe_write); - background_system_process(); } + +void thread_top_init(char *thread_name, + int affinity, + uint64_t runtime, + uint64_t deadline, + uint64_t period) { +#ifdef DEADLINE_SCHEDULER + struct sched_attr attr; + unsigned int flags = 0; + attr.size = sizeof(attr); + attr.sched_flags = 0; + attr.sched_nice = 0; + attr.sched_priority = 0; + attr.sched_policy = SCHED_DEADLINE; + attr.sched_runtime = runtime; + attr.sched_deadline = deadline; + attr.sched_period = period; + + AssertFatal(sched_setattr(0, &attr, flags) == 0, "[SCHED] eNB tx thread: sched_setattr failed\n"); + +#else +#ifdef CPU_AFFINITY + /* Set affinity mask to include CPUs 2 to MAX_CPUS */ + /* CPU 0 is reserved for UHD threads */ /* CPU 1 is reserved for all RX_TX threads */ + /* Enable CPU Affinity only if number of CPUs > 2 */ + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + if (affinity == 0) { + LOG_W(HW,"thread_top_init() called with affinity==0, but overruled by #ifdef CPU_AFFINITY\n"); + } else if (get_nprocs() > 2) { + for (j = 2; j < get_nprocs(); j++) + CPU_SET(j, &cpuset); + AssertFatal( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity"); + } +#endif //CPU_AFFINITY + + struct sched_param sparam={0}; + sparam.sched_priority = OAI_PRIORITY_RT; + AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO , &sparam) == 0,"Error setting thread priority"); + pthread_setname_np(pthread_self(), thread_name); +#endif + mlockall(MCL_CURRENT | MCL_FUTURE); +} + +void threadTopInit(const char* name, const int affinity, const int priority){ +struct sched_param sparam={0}; + sparam.sched_priority = priority; + AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO , &sparam) == 0,"Error setting thread priority"); + pthread_setname_np(pthread_self(), name); + if (affinity != -1 ) { + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(affinity, &cpuset); + AssertFatal( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity"); + } +} + +// Block CPU C-states deep sleep +void configure_linux(void) { + int ret; + static int latency_target_fd=-1; + uint32_t latency_target_value=10; // in microseconds + if (latency_target_fd == -1) { + if ( (latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR)) != -1 ) { + ret = write(latency_target_fd, &latency_target_value, sizeof(latency_target_value)); + if (ret == 0) { + printf("# error setting cpu_dma_latency to %d!: %s\n", latency_target_value, strerror(errno)); + close(latency_target_fd); + latency_target_fd=-1; + return; + } + } + } + if (latency_target_fd != -1) + LOG_I(HW,"# /dev/cpu_dma_latency set to %dus\n", latency_target_value); + else + LOG_E(HW,"Can't set /dev/cpu_dma_latency to %dus\n", latency_target_value); + + // Set CPU frequency to it's maximum + if ( 0 != system("for d in /sys/devices/system/cpu/cpu[0-9]*; do cat $d/cpufreq/cpuinfo_max_freq > $d/cpufreq/scaling_min_freq; done")) + LOG_W(HW,"Can't set cpu frequency\n"); + +} diff --git a/common/utils/system.h b/common/utils/system.h index 658c17adc1..b66d4031c9 100644 --- a/common/utils/system.h +++ b/common/utils/system.h @@ -21,6 +21,11 @@ #ifndef _SYSTEM_H_OAI_ #define _SYSTEM_H_OAI_ +#include +#ifdef __cplusplus +extern "C" { +#endif + /**************************************************** * send a command to the background process @@ -36,4 +41,23 @@ int background_system(char *command); void start_background_system(void); +void set_latency_target(void); +void configure_linux(void); + +void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority); +#define OAI_PRIORITY_RT_LOW sched_get_priority_min(SCHED_FIFO) +#define OAI_PRIORITY_RT sched_get_priority_max(SCHED_FIFO)-10 +#define OAI_PRIORITY_RT_MAX sched_get_priority_max(SCHED_FIFO) + +void thread_top_init(char *thread_name, + int affinity, + uint64_t runtime, + uint64_t deadline, + uint64_t period); + +#ifdef __cplusplus +} +#endif + + #endif /* _SYSTEM_H_OAI_ */ diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c index 8eee0c2b8a..a17495c91f 100644 --- a/common/utils/threadPool/thread-pool.c +++ b/common/utils/threadPool/thread-pool.c @@ -49,23 +49,6 @@ void *one_thread(void *arg) { struct one_thread *myThread=(struct one_thread *) arg; struct thread_pool *tp=myThread->pool; - // configure the thread core assignment - // TBD: reserve the core for us exclusively - if ( myThread->coreID >= 0 && myThread->coreID < get_nprocs_conf()) { - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - CPU_SET(myThread->coreID, &cpuset); - pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - } - - //Configure the thread scheduler policy for Linux - struct sched_param sparam= {0}; - sparam.sched_priority = sched_get_priority_max(SCHED_RR); - pthread_setschedparam(pthread_self(), SCHED_RR, &sparam); - // set the thread name for debugging - sprintf(myThread->name,"Tpool_%d",myThread->coreID); - pthread_setname_np(pthread_self(), myThread->name ); - // Infinite loop to process requests do { notifiedFIFO_elt_t *elt=pullNotifiedFifoRemember(&tp->incomingFifo, myThread); @@ -106,10 +89,6 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { } else pool->traceFd=-1; - //Configure the thread scheduler policy for Linux - struct sched_param sparam= {0}; - sparam.sched_priority = sched_get_priority_max(SCHED_RR)-1; - pthread_setschedparam(pthread_self(), SCHED_RR, &sparam); pool->activated=true; initNotifiedFIFO(&pool->incomingFifo); char *saveptr, * curptr; @@ -136,7 +115,10 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { pool->allthreads->coreID=atoi(curptr); pool->allthreads->id=pool->nbThreads; pool->allthreads->pool=pool; - pthread_create(&pool->allthreads->threadID, NULL, one_thread, (void *)pool->allthreads); + //Configure the thread scheduler policy for Linux + // set the thread name for debugging + sprintf(myThread->name,"Tpool_%d",myThread->coreID); + threadCreate(&pool->allthreads->threadID, one_thread, (void *)pool->allthreads, Tpool, myThread->name, myThread->coreID, OAI_PRIORITY_RT); pool->nbThreads++; } diff --git a/common/utils/threadPool/thread-pool.h b/common/utils/threadPool/thread-pool.h index 6f0230568a..2e1e504ed7 100644 --- a/common/utils/threadPool/thread-pool.h +++ b/common/utils/threadPool/thread-pool.h @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef DEBUG #define THREADINIT PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c new file mode 100644 index 0000000000..8b4822ba56 --- /dev/null +++ b/executables/nr-gnb.c @@ -0,0 +1,952 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file lte-enb.c + * \brief Top-level threads for gNodeB + * \author R. Knopp, F. Kaltenberger, Navid Nikaein + * \date 2012 + * \version 0.1 + * \company Eurecom + * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr + * \note + * \warning + */ + +#define _GNU_SOURCE +#include + +#include "time_utils.h" + +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "assertions.h" + +#include "PHY/types.h" + +#include "PHY/INIT/phy_init.h" + +#include "PHY/defs_gNB.h" +#include "SCHED/sched_eNB.h" +#include "SCHED_NR/sched_nr.h" +#include "SCHED_NR/fapi_nr_l1.h" +#include "PHY/LTE_TRANSPORT/transport_proto.h" + +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "../../ARCH/COMMON/common_lib.h" + +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "PHY/LTE_TRANSPORT/if4_tools.h" +#include "PHY/LTE_TRANSPORT/if5_tools.h" + +#include "PHY/phy_extern.h" + + +#include "LAYER2/MAC/mac.h" +#include "LAYER2/MAC/mac_extern.h" +#include "LAYER2/MAC/mac_proto.h" +#include "RRC/LTE/rrc_extern.h" +#include "PHY_INTERFACE/phy_interface.h" +#include "common/utils/LOG/log_extern.h" +#include "UTIL/OTG/otg_tx.h" +#include "UTIL/OTG/otg_externs.h" +#include "UTIL/MATH/oml.h" +#include "common/utils/LOG/vcd_signal_dumper.h" +#include "UTIL/OPT/opt.h" +#include "enb_config.h" + + +#ifndef OPENAIR2 + #include "UTIL/OTG/otg_extern.h" +#endif + +#if defined(ENABLE_ITTI) + #if defined(ENABLE_USE_MME) + #include "s1ap_eNB.h" + #ifdef PDCP_USE_NETLINK + #include "SIMULATION/ETH_TRANSPORT/proto.h" + #endif + #endif +#endif + +#include "T.h" + +//#define DEBUG_THREADS 1 + +//#define USRP_DEBUG 1 +// Fix per CC openair rf/if device update +// extern openair0_device openair0; + + +#if defined(ENABLE_ITTI) + extern volatile int start_gNB; + extern volatile int start_UE; +#endif +extern volatile int oai_exit; + +extern openair0_config_t openair0_cfg[MAX_CARDS]; + +extern int transmission_mode; + +uint16_t sl_ahead=4; +uint16_t sf_ahead=4; +//pthread_t main_gNB_thread; + +time_stats_t softmodem_stats_mt; // main thread +time_stats_t softmodem_stats_hw; // hw acquisition +time_stats_t softmodem_stats_rxtx_sf; // total tx time +time_stats_t nfapi_meas; // total tx time +time_stats_t softmodem_stats_rx_sf; // total rx time + +/* mutex, cond and variable to serialize phy proc TX calls + * (this mechanism may be relaxed in the future for better + * performances) + */ +static struct { + pthread_mutex_t mutex_phy_proc_tx; + pthread_cond_t cond_phy_proc_tx; + volatile uint8_t phy_proc_CC_id; +} sync_phy_proc; + +extern double cpuf; + +void init_gNB(int,int); +void stop_gNB(int nb_inst); + +int wakeup_txfh(gNB_L1_rxtx_proc_t *proc,PHY_VARS_gNB *gNB); +int wakeup_tx(PHY_VARS_gNB *gNB); +extern PARALLEL_CONF_t get_thread_parallel_conf(void); +extern WORKER_CONF_t get_thread_worker_conf(void); + + +void wakeup_prach_gNB(PHY_VARS_gNB *gNB,RU_t *ru,int frame,int subframe); + +extern uint8_t nfapi_mode; +extern void oai_subframe_ind(uint16_t sfn, uint16_t sf); +extern void add_subframe(uint16_t *frameP, uint16_t *subframeP, int offset); + +//#define TICK_TO_US(ts) (ts.diff) +#define TICK_TO_US(ts) (ts.trials==0?0:ts.diff/ts.trials) + + +static inline int rxtx(PHY_VARS_gNB *gNB,gNB_L1_rxtx_proc_t *proc, char *thread_name) { + start_meas(&softmodem_stats_rxtx_sf); + + // ******************************************************************* + + if (nfapi_mode == 1) { + // I am a PNF and I need to let nFAPI know that we have a (sub)frame tick + uint16_t frame = proc->frame_rx; + uint16_t slot = proc->slot_rx; + //add_subframe(&frame, &subframe, 4); + //oai_subframe_ind(proc->frame_tx, proc->subframe_tx); + //LOG_D(PHY, "oai_subframe_ind(frame:%u, subframe:%d) - NOT CALLED ********\n", frame, subframe); + start_meas(&nfapi_meas); + oai_subframe_ind(frame, slot); + stop_meas(&nfapi_meas); + + if (gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus|| + gNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs || + gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs || + gNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles || + gNB->UL_INFO.cqi_ind.number_of_cqis + ) { + LOG_D(PHY, "UL_info[rx_ind:%05d:%d harqs:%05d:%d crcs:%05d:%d preambles:%05d:%d cqis:%d] RX:%04d%d TX:%04d%d \n", + NFAPI_SFNSF2DEC(gNB->UL_INFO.rx_ind.sfn_sf), gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus, + NFAPI_SFNSF2DEC(gNB->UL_INFO.harq_ind.sfn_sf), gNB->UL_INFO.harq_ind.harq_indication_body.number_of_harqs, + NFAPI_SFNSF2DEC(gNB->UL_INFO.crc_ind.sfn_sf), gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, + NFAPI_SFNSF2DEC(gNB->UL_INFO.rach_ind.sfn_sf), gNB->UL_INFO.rach_ind.rach_indication_body.number_of_preambles, + gNB->UL_INFO.cqi_ind.number_of_cqis, + proc->frame_rx, proc->slot_rx, + proc->frame_tx, proc->slot_tx); + } + } + + /// NR disabling + // **************************************** + // Common RX procedures subframe n + T(T_GNB_PHY_DL_TICK, T_INT(gNB->Mod_id), T_INT(proc->frame_tx), T_INT(proc->slot_tx)); + /* + // if this is IF5 or 3GPP_gNB + if (gNB && gNB->RU_list && gNB->RU_list[0] && gNB->RU_list[0]->function < NGFI_RAU_IF4p5) { + wakeup_prach_gNB(gNB,NULL,proc->frame_rx,proc->slot_rx); + } + + // UE-specific RX processing for subframe n + if (nfapi_mode == 0 || nfapi_mode == 1) { + phy_procedures_gNB_uespec_RX(gNB, proc, no_relay ); + } + */ + pthread_mutex_lock(&gNB->UL_INFO_mutex); + gNB->UL_INFO.frame = proc->frame_rx; + gNB->UL_INFO.slot = proc->slot_rx; + gNB->UL_INFO.module_id = gNB->Mod_id; + gNB->UL_INFO.CC_id = gNB->CC_id; + gNB->if_inst->NR_UL_indication(&gNB->UL_INFO); + pthread_mutex_unlock(&gNB->UL_INFO_mutex); + + /// end + // ***************************************** + // TX processing for subframe n+sl_ahead + // run PHY TX procedures the one after the other for all CCs to avoid race conditions + // (may be relaxed in the future for performance reasons) + // ***************************************** + //if (wait_CCs(proc)<0) return(-1); + + if (oai_exit) return(-1); + + if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) { + phy_procedures_gNB_TX(gNB, proc, 1); + } + + stop_meas( &softmodem_stats_rxtx_sf ); + LOG_D(PHY,"%s() Exit proc[rx:%d%d tx:%d%d]\n", __FUNCTION__, proc->frame_rx, proc->slot_rx, proc->frame_tx, proc->slot_tx); +#if 0 + LOG_D(PHY, "rxtx:%lld nfapi:%lld phy:%lld tx:%lld rx:%lld prach:%lld ofdm:%lld ", + softmodem_stats_rxtx_sf.diff_now, nfapi_meas.diff_now, + TICK_TO_US(gNB->phy_proc), + TICK_TO_US(gNB->phy_proc_tx), + TICK_TO_US(gNB->phy_proc_rx), + TICK_TO_US(gNB->rx_prach), + TICK_TO_US(gNB->ofdm_mod_stats), + softmodem_stats_rxtx_sf.diff_now, nfapi_meas.diff_now); + LOG_D(PHY, + "dlsch[enc:%lld mod:%lld scr:%lld rm:%lld t:%lld i:%lld] rx_dft:%lld ", + TICK_TO_US(gNB->dlsch_encoding_stats), + TICK_TO_US(gNB->dlsch_modulation_stats), + TICK_TO_US(gNB->dlsch_scrambling_stats), + TICK_TO_US(gNB->dlsch_rate_matching_stats), + TICK_TO_US(gNB->dlsch_turbo_encoding_stats), + TICK_TO_US(gNB->dlsch_interleaving_stats), + TICK_TO_US(gNB->rx_dft_stats)); + LOG_D(PHY," ulsch[ch:%lld freq:%lld dec:%lld demod:%lld ru:%lld ", + TICK_TO_US(gNB->ulsch_channel_estimation_stats), + TICK_TO_US(gNB->ulsch_freq_offset_estimation_stats), + TICK_TO_US(gNB->ulsch_decoding_stats), + TICK_TO_US(gNB->ulsch_demodulation_stats), + TICK_TO_US(gNB->ulsch_rate_unmatching_stats)); + LOG_D(PHY, "td:%lld dei:%lld dem:%lld llr:%lld tci:%lld ", + TICK_TO_US(gNB->ulsch_turbo_decoding_stats), + TICK_TO_US(gNB->ulsch_deinterleaving_stats), + TICK_TO_US(gNB->ulsch_demultiplexing_stats), + TICK_TO_US(gNB->ulsch_llr_stats), + TICK_TO_US(gNB->ulsch_tc_init_stats)); + LOG_D(PHY, "tca:%lld tcb:%lld tcg:%lld tce:%lld l1:%lld l2:%lld]\n\n", + TICK_TO_US(gNB->ulsch_tc_alpha_stats), + TICK_TO_US(gNB->ulsch_tc_beta_stats), + TICK_TO_US(gNB->ulsch_tc_gamma_stats), + TICK_TO_US(gNB->ulsch_tc_ext_stats), + TICK_TO_US(gNB->ulsch_tc_intl1_stats), + TICK_TO_US(gNB->ulsch_tc_intl2_stats) + ); +#endif + return(0); +} + +static void *gNB_L1_thread_tx(void *param) { + PHY_VARS_gNB *gNB = (PHY_VARS_gNB *)param; + gNB_L1_proc_t *gNB_proc = &gNB->proc; + gNB_L1_rxtx_proc_t *proc = &gNB_proc->L1_proc_tx; + //PHY_VARS_gNB *gNB = RC.gNB[0][proc->CC_id]; + char thread_name[100]; + sprintf(thread_name,"TXnp4_%d\n",&gNB->proc.L1_proc == proc ? 0 : 1); + //thread_top_init(thread_name,1,470000,500000,500000); + + //wait_sync("tx_thread"); + + while (!oai_exit) { + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_PROC_RXTX1, 0 ); + + if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break; + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_PROC_RXTX1, 1 ); + + if (oai_exit) break; + + // ***************************************** + // TX processing for subframe n+4 + // run PHY TX procedures the one after the other for all CCs to avoid race conditions + // (may be relaxed in the future for performance reasons) + // ***************************************** + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SLOT_NUMBER_TX1_GNB,proc->slot_tx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SLOT_NUMBER_RX1_GNB,proc->slot_rx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX1_GNB,proc->frame_tx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX1_GNB,proc->frame_rx); + phy_procedures_gNB_TX(gNB, proc, 1); + pthread_mutex_lock( &proc->mutex ); + proc->instance_cnt = -1; + + // the thread can now be woken up + if (pthread_cond_signal(&proc->cond) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_cond_signal for gNB TXnp4 thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + } + + pthread_mutex_unlock( &proc->mutex ); + wakeup_txfh(proc,gNB); + } + + return 0; +} + +/*! + * \brief The RX UE-specific and TX thread of gNB. + * \param param is a \ref gNB_L1_proc_t structure which contains the info what to process. + * \returns a pointer to an int. The storage is not on the heap and must not be freed. + */ + +static void *gNB_L1_thread( void *param ) { + static int gNB_thread_rxtx_status; + PHY_VARS_gNB *gNB = (PHY_VARS_gNB *)param; + gNB_L1_proc_t *gNB_proc = &gNB->proc; + gNB_L1_rxtx_proc_t *proc = &gNB_proc->L1_proc; + //PHY_VARS_gNB *gNB = RC.gNB[0][proc->CC_id]; + char thread_name[100]; + // set default return value + gNB_thread_rxtx_status = 0; + sprintf(thread_name,"RXn_TXnp4_%d",&gNB->proc.L1_proc == proc ? 0 : 1); + //thread_top_init(thread_name,1,850000L,1000000L,2000000L); + + while (!oai_exit) { + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_PROC_RXTX0, 0 ); + + if (wait_on_condition(&proc->mutex,&proc->cond,&proc->instance_cnt,thread_name)<0) break; + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_PROC_RXTX0, 1 ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SLOT_NUMBER_TX0_GNB,proc->slot_tx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_SLOT_NUMBER_RX0_GNB,proc->slot_rx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_GNB,proc->frame_tx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_GNB,proc->frame_rx); + + if (oai_exit) break; + + if (gNB->CC_id==0) { + if (rxtx(gNB,proc,thread_name) < 0) break; + } + + if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT) { + phy_procedures_gNB_TX(gNB, proc, 1); + } + + if (release_thread(&proc->mutex,&proc->instance_cnt,thread_name)<0) break; + + if(get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) { + wakeup_tx(gNB); + } else if(get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT) { + wakeup_txfh(proc,gNB); + } + } // while !oai_exit + + LOG_D(PHY, " *** Exiting gNB thread RXn_TXnp4\n"); + gNB_thread_rxtx_status = 0; + return &gNB_thread_rxtx_status; +} + + +#if 0 //defined(ENABLE_ITTI) && defined(ENABLE_USE_MME) +// Wait for gNB application initialization to be complete (gNB registration to MME) +static void wait_system_ready (char *message, volatile int *start_flag) { + static char *indicator[] = {". ", ".. ", "... ", ".... ", ".....", + " ....", " ...", " ..", " .", " " + }; + int i = 0; + + while ((!oai_exit) && (*start_flag == 0)) { + LOG_N(EMU, message, indicator[i]); + fflush(stdout); + i = (i + 1) % (sizeof(indicator) / sizeof(indicator[0])); + usleep(200000); + } + + LOG_D(EMU,"\n"); +} +#endif + + + + + +void gNB_top(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, char *string, struct RU_t_s *ru) { + gNB_L1_proc_t *proc = &gNB->proc; + gNB_L1_rxtx_proc_t *L1_proc = &proc->L1_proc; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + RU_proc_t *ru_proc=&ru->proc; + proc->frame_rx = frame_rx; + proc->slot_rx = slot_rx; + + if (!oai_exit) { + T(T_ENB_MASTER_TICK, T_INT(0), T_INT(proc->frame_rx), T_INT(proc->slot_rx)); + L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sl_ahead*fp->samples_per_slot); + L1_proc->frame_rx = ru_proc->frame_rx; + L1_proc->slot_rx = ru_proc->tti_rx; + L1_proc->frame_tx = (L1_proc->slot_rx > (fp->slots_per_frame-1-sl_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx; + L1_proc->slot_tx = (L1_proc->slot_rx + sl_ahead)%fp->slots_per_frame; + + if (rxtx(gNB,L1_proc,string) < 0) LOG_E(PHY,"gNB %d CC_id %d failed during execution\n",gNB->Mod_id,gNB->CC_id); + + ru_proc->timestamp_tx = L1_proc->timestamp_tx; + ru_proc->tti_tx = L1_proc->slot_tx; + ru_proc->frame_tx = L1_proc->frame_tx; + } +} + +int wakeup_txfh(gNB_L1_rxtx_proc_t *proc,PHY_VARS_gNB *gNB) { + RU_t *ru; + RU_proc_t *ru_proc; + struct timespec wait; + wait.tv_sec=0; + wait.tv_nsec=5000000L; + //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~inside wakeup_txfh %d.%d IC_RU = %d\n", proc->frame_tx, proc->slot_tx, proc->instance_cnt_RUs); + + if(wait_on_condition(&proc->mutex_RUs,&proc->cond_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) { + LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", proc->frame_tx, proc->slot_tx); + return(-1); + } + + pthread_mutex_lock(&gNB->proc.mutex_RU_tx); + gNB->proc.RU_mask_tx = 0; + pthread_mutex_unlock(&gNB->proc.mutex_RU_tx); + + if (release_thread(&proc->mutex_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) return(-1); + + for(int i=0; inum_RU; i++) { + ru = gNB->RU_list[i]; + ru_proc = &ru->proc; + + if (ru_proc->instance_cnt_gNBs == 0) { + LOG_E(PHY,"Frame %d, subframe %d: TX FH thread busy, dropping Frame %d, subframe %d\n", ru_proc->frame_tx, ru_proc->tti_tx, proc->frame_rx, proc->slot_rx); + return(-1); + } + + if (pthread_mutex_timedlock(&ru_proc->mutex_gNBs,&wait) != 0) { + LOG_E( PHY, "[eNB] ERROR pthread_mutex_lock for eNB TX1 thread %d (IC %d)\n", ru_proc->tti_rx&1,ru_proc->instance_cnt_gNBs ); + exit_fun( "error locking mutex_gNB" ); + return(-1); + } + + ru_proc->instance_cnt_gNBs = 0; + ru_proc->timestamp_tx = proc->timestamp_tx; + ru_proc->tti_tx = proc->slot_tx; + ru_proc->frame_tx = proc->frame_tx; + LOG_I(PHY,"Signaling tx_thread_fh for %d.%d\n",ru_proc->frame_tx,ru_proc->tti_tx); + + // the thread can now be woken up + if (pthread_cond_signal(&ru_proc->cond_gNBs) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_cond_signal for gNB TXnp4 thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + return(-1); + } + + pthread_mutex_unlock( &ru_proc->mutex_gNBs ); + } + + return(0); +} + +int wakeup_tx(PHY_VARS_gNB *gNB) { + gNB_L1_proc_t *proc=&gNB->proc; + gNB_L1_rxtx_proc_t *L1_proc_tx = &proc->L1_proc_tx; + gNB_L1_rxtx_proc_t *L1_proc = &proc->L1_proc; + struct timespec wait; + wait.tv_sec=0; + wait.tv_nsec=5000000L; + + if (pthread_mutex_timedlock(&L1_proc_tx->mutex,&wait) != 0) { + LOG_E(PHY, "[SCHED][eNB] ERROR locking mutex for eNB L1_thread_tx\n"); + exit_fun("ERROR pthread_lock"); + return(-1); + } + + while(L1_proc_tx->instance_cnt == 0) { + pthread_cond_wait(&L1_proc_tx->cond,&L1_proc_tx->mutex); + } + + L1_proc_tx->instance_cnt = 0; + L1_proc_tx->slot_rx = L1_proc->slot_rx; + L1_proc_tx->frame_rx = L1_proc->frame_rx; + L1_proc_tx->slot_tx = L1_proc->slot_tx; + L1_proc_tx->frame_tx = L1_proc->frame_tx; + L1_proc_tx->timestamp_tx = L1_proc->timestamp_tx; + + // the thread can now be woken up + if (pthread_cond_signal(&L1_proc_tx->cond) != 0) { + LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + return(-1); + } + + pthread_mutex_unlock( &L1_proc_tx->mutex); + return(0); +} + +int wakeup_rxtx(PHY_VARS_gNB *gNB,RU_t *ru) { + gNB_L1_proc_t *proc=&gNB->proc; + gNB_L1_rxtx_proc_t *L1_proc=&proc->L1_proc; + NR_DL_FRAME_PARMS *fp = &gNB->frame_parms; + RU_proc_t *ru_proc=&ru->proc; + int i; + struct timespec wait; + pthread_mutex_lock(&proc->mutex_RU); + + for (i=0; inum_RU; i++) { + if (ru == gNB->RU_list[i]) { + if ((proc->RU_mask&(1< 0) + LOG_E(PHY,"gNB %d frame %d, subframe %d : previous information from RU %d (num_RU %d,mask %x) has not been served yet!\n", + gNB->Mod_id,proc->frame_rx,proc->slot_rx,ru->idx,gNB->num_RU,proc->RU_mask); + + proc->RU_mask |= (1<RU_mask != (1<num_RU)-1) { // not all RUs have provided their information so return + LOG_E(PHY,"Not all RUs have provided their info\n"); + pthread_mutex_unlock(&proc->mutex_RU); + return(0); + } else { // all RUs have provided their information so continue on and wakeup gNB processing + proc->RU_mask = 0; + pthread_mutex_unlock(&proc->mutex_RU); + } + + wait.tv_sec=0; + wait.tv_nsec=5000000L; + + /* accept some delay in processing - up to 5ms */ + for (i = 0; i < fp->slots_per_frame && L1_proc->instance_cnt == 0; i++) { + LOG_W( PHY,"[gNB] SFN.SL %d.%d, gNB RXn-TXnp4 thread busy!! (i %d, cnt %i)\n", L1_proc->frame_tx, L1_proc->slot_tx, i,L1_proc->instance_cnt); + usleep(100); + } + + if (L1_proc->instance_cnt == 0) { + exit_fun( "TX thread busy" ); + return(-1); + } + + // wake up TX for subframe n+sl_ahead + // lock the TX mutex and make sure the thread is ready + if (pthread_mutex_timedlock(&L1_proc->mutex,&wait) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_mutex_lock for gNB RXTX thread %d (IC %d)\n", L1_proc->slot_rx&1,L1_proc->instance_cnt ); + exit_fun( "error locking mutex" ); + return(-1); + } + + ++L1_proc->instance_cnt; + // We have just received and processed the common part of a subframe, say n. + // TS_rx is the last received timestamp (start of 1st slot), TS_tx is the desired + // transmitted timestamp of the next TX slot (first). + // The last (TS_rx mod samples_per_frame) was n*samples_per_tti, + // we want to generate subframe (n+sl_ahead), so TS_tx = TX_rx+sl_ahead*samples_per_tti, + // and proc->slot_tx = proc->slot_rx+sl_ahead + L1_proc->timestamp_tx = ru_proc->timestamp_rx + (sl_ahead*fp->samples_per_slot); + L1_proc->frame_rx = ru_proc->frame_rx; + L1_proc->slot_rx = ru_proc->tti_rx; + L1_proc->frame_tx = (L1_proc->slot_rx > (fp->slots_per_frame-1-sl_ahead)) ? (L1_proc->frame_rx+1)&1023 : L1_proc->frame_rx; + L1_proc->slot_tx = (L1_proc->slot_rx + sl_ahead)%fp->slots_per_frame; + LOG_I(PHY,"wakeupL1: passing parameter IC = %d, RX: %d.%d, TX: %d.%d to L1 sl_ahead = %d\n", L1_proc->instance_cnt, L1_proc->frame_rx, L1_proc->slot_rx, L1_proc->frame_tx, L1_proc->slot_tx, sl_ahead); + + // the thread can now be woken up + if (pthread_cond_signal(&L1_proc->cond) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_cond_signal for gNB RXn-TXnp4 thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + return(-1); + } + + pthread_mutex_unlock( &L1_proc->mutex ); + return(0); +} +/* +void wakeup_prach_gNB(PHY_VARS_gNB *gNB,RU_t *ru,int frame,int subframe) { + + gNB_L1_proc_t *proc = &gNB->proc; + LTE_DL_FRAME_PARMS *fp=&gNB->frame_parms; + int i; + + if (ru!=NULL) { + pthread_mutex_lock(&proc->mutex_RU_PRACH); + for (i=0;inum_RU;i++) { + if (ru == gNB->RU_list[i]) { + LOG_D(PHY,"frame %d, subframe %d: RU %d for gNB %d signals PRACH (mask %x, num_RU %d)\n",frame,subframe,i,gNB->Mod_id,proc->RU_mask_prach,gNB->num_RU); + if ((proc->RU_mask_prach&(1< 0) + LOG_E(PHY,"gNB %d frame %d, subframe %d : previous information (PRACH) from RU %d (num_RU %d, mask %x) has not been served yet!\n", + gNB->Mod_id,frame,subframe,ru->idx,gNB->num_RU,proc->RU_mask_prach); + proc->RU_mask_prach |= (1<RU_mask_prach != (1<num_RU)-1) { // not all RUs have provided their information so return + pthread_mutex_unlock(&proc->mutex_RU_PRACH); + return; + } + else { // all RUs have provided their information so continue on and wakeup gNB processing + proc->RU_mask_prach = 0; + pthread_mutex_unlock(&proc->mutex_RU_PRACH); + } + } + + // check if we have to detect PRACH first + if (is_prach_subframe(fp,frame,subframe)>0) { + LOG_D(PHY,"Triggering prach processing, frame %d, subframe %d\n",frame,subframe); + if (proc->instance_cnt_prach == 0) { + LOG_W(PHY,"[gNB] Frame %d Subframe %d, dropping PRACH\n", frame,subframe); + return; + } + + // wake up thread for PRACH RX + if (pthread_mutex_lock(&proc->mutex_prach) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_mutex_lock for gNB PRACH thread %d (IC %d)\n", proc->thread_index, proc->instance_cnt_prach); + exit_fun( "error locking mutex_prach" ); + return; + } + + ++proc->instance_cnt_prach; + // set timing for prach thread + proc->frame_prach = frame; + proc->subframe_prach = subframe; + + // the thread can now be woken up + if (pthread_cond_signal(&proc->cond_prach) != 0) { + LOG_E( PHY, "[gNB] ERROR pthread_cond_signal for gNB PRACH thread %d\n", proc->thread_index); + exit_fun( "ERROR pthread_cond_signal" ); + return; + } + + pthread_mutex_unlock( &proc->mutex_prach ); + } + +}*/ + +/*! + * \brief The prach receive thread of gNB. + * \param param is a \ref gNB_L1_proc_t structure which contains the info what to process. + * \returns a pointer to an int. The storage is not on the heap and must not be freed. + */ +/* +static void* gNB_thread_prach( void* param ) { + static int gNB_thread_prach_status; + + + PHY_VARS_gNB *gNB= (PHY_VARS_gNB *)param; + gNB_L1_proc_t *proc = &gNB->proc; + + // set default return value + gNB_thread_prach_status = 0; + + thread_top_init("gNB_thread_prach",1,500000L,1000000L,20000000L); + + + while (!oai_exit) { + + if (oai_exit) break; + + + if (wait_on_condition(&proc->mutex_prach,&proc->cond_prach,&proc->instance_cnt_prach,"gNB_prach_thread") < 0) break; + + LOG_D(PHY,"Running gNB prach procedures\n"); + prach_procedures(gNB +#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,0 +#endif + ); + + if (release_thread(&proc->mutex_prach,&proc->instance_cnt_prach,"gNB_prach_thread") < 0) break; + } + + LOG_I(PHY, "Exiting gNB thread PRACH\n"); + + gNB_thread_prach_status = 0; + return &gNB_thread_prach_status; +} +*/ + +extern void init_td_thread(PHY_VARS_gNB *, pthread_attr_t *); +extern void init_te_thread(PHY_VARS_gNB *, pthread_attr_t *); + +void init_gNB_proc(int inst) { + int i=0; + int CC_id; + PHY_VARS_gNB *gNB; + gNB_L1_proc_t *proc; + gNB_L1_rxtx_proc_t *L1_proc,*L1_proc_tx; + pthread_attr_t *attr0=NULL,*attr1=NULL; + //*attr_prach=NULL; + LOG_I(PHY,"%s(inst:%d) RC.nb_nr_CC[inst]:%d \n",__FUNCTION__,inst,RC.nb_nr_CC[inst]); + + for (CC_id=0; CC_idproc; + L1_proc = &proc->L1_proc; + L1_proc_tx = &proc->L1_proc_tx; + L1_proc->instance_cnt = -1; + L1_proc_tx->instance_cnt = -1; + L1_proc->instance_cnt_RUs = 0; + L1_proc_tx->instance_cnt_RUs = 0; + proc->instance_cnt_prach = -1; + proc->instance_cnt_asynch_rxtx = -1; + proc->CC_id = CC_id; + proc->first_rx =1; + proc->first_tx =1; + proc->RU_mask =0; + proc->RU_mask_tx = (1<num_RU)-1; + proc->RU_mask_prach =0; + pthread_mutex_init( &gNB->UL_INFO_mutex, NULL); + pthread_mutex_init( &L1_proc->mutex, NULL); + pthread_mutex_init( &L1_proc_tx->mutex, NULL); + pthread_cond_init( &L1_proc->cond, NULL); + pthread_cond_init( &L1_proc_tx->cond, NULL); + pthread_mutex_init( &proc->mutex_prach, NULL); + pthread_mutex_init( &proc->mutex_asynch_rxtx, NULL); + pthread_mutex_init( &proc->mutex_RU,NULL); + pthread_mutex_init( &proc->mutex_RU_tx,NULL); + pthread_mutex_init( &proc->mutex_RU_PRACH,NULL); + pthread_cond_init( &proc->cond_prach, NULL); + pthread_cond_init( &proc->cond_asynch_rxtx, NULL); + pthread_attr_init( &proc->attr_prach); + pthread_attr_init( &proc->attr_asynch_rxtx); + // pthread_attr_init( &proc->attr_td); + // pthread_attr_init( &proc->attr_te); + pthread_attr_init( &L1_proc->attr); + pthread_attr_init( &L1_proc_tx->attr); + attr0 = &L1_proc->attr; + attr1 = &L1_proc_tx->attr; + LOG_I(PHY,"gNB->single_thread_flag:%d\n", gNB->single_thread_flag); + + if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) { + threadCreate( &L1_proc->pthread, gNB_L1_thread, gNB, "L1_proc", -1, OAI_PRIORITY_RT ); + threadCreate( &L1_proc_tx->pthread, gNB_L1_thread_tx, gNB,"L1_proc_tx", -1, OAI_PRIORITY_RT); + } + + //pthread_create( &proc->pthread_prach, attr_prach, gNB_thread_prach, gNB ); + char name[16]; + + if (gNB->single_thread_flag==0) { + snprintf( name, sizeof(name), "L1 %d", i ); + pthread_setname_np( L1_proc->pthread, name ); + snprintf( name, sizeof(name), "L1TX %d", i ); + pthread_setname_np( L1_proc_tx->pthread, name ); + } + + AssertFatal(proc->instance_cnt_prach == -1,"instance_cnt_prach = %d\n",proc->instance_cnt_prach); + } + + /* setup PHY proc TX sync mechanism */ + pthread_mutex_init(&sync_phy_proc.mutex_phy_proc_tx, NULL); + pthread_cond_init(&sync_phy_proc.cond_phy_proc_tx, NULL); + sync_phy_proc.phy_proc_CC_id = 0; +} + + + +/*! + * \brief Terminate gNB TX and RX threads. + */ +void kill_gNB_proc(int inst) { + int *status; + PHY_VARS_gNB *gNB; + gNB_L1_proc_t *proc; + gNB_L1_rxtx_proc_t *L1_proc, *L1_proc_tx; + + for (int CC_id=0; CC_idproc; + L1_proc = &proc->L1_proc; + L1_proc_tx = &proc->L1_proc_tx; + LOG_I(PHY, "Killing TX CC_id %d inst %d\n", CC_id, inst ); + + if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) { + pthread_mutex_lock(&L1_proc->mutex); + L1_proc->instance_cnt = 0; + pthread_cond_signal(&L1_proc->cond); + pthread_mutex_unlock(&L1_proc->mutex); + pthread_mutex_lock(&L1_proc_tx->mutex); + L1_proc_tx->instance_cnt = 0; + pthread_cond_signal(&L1_proc_tx->cond); + pthread_mutex_unlock(&L1_proc_tx->mutex); + } + + proc->instance_cnt_prach = 0; + pthread_cond_signal( &proc->cond_prach ); + pthread_cond_signal( &proc->cond_asynch_rxtx ); + pthread_cond_broadcast(&sync_phy_proc.cond_phy_proc_tx); + // LOG_D(PHY, "joining pthread_prach\n"); + // pthread_join( proc->pthread_prach, (void**)&status ); + LOG_I(PHY, "Destroying prach mutex/cond\n"); + pthread_mutex_destroy( &proc->mutex_prach ); + pthread_cond_destroy( &proc->cond_prach ); + LOG_I(PHY, "Destroying UL_INFO mutex\n"); + pthread_mutex_destroy(&gNB->UL_INFO_mutex); + + if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) { + LOG_I(PHY, "Joining L1_proc mutex/cond\n"); + pthread_join( L1_proc->pthread, (void **)&status ); + LOG_I(PHY, "Joining L1_proc_tx mutex/cond\n"); + pthread_join( L1_proc_tx->pthread, (void **)&status ); + } + + LOG_I(PHY, "Destroying L1_proc mutex/cond\n"); + pthread_mutex_destroy( &L1_proc->mutex ); + pthread_cond_destroy( &L1_proc->cond ); + LOG_I(PHY, "Destroying L1_proc_tx mutex/cond\n"); + pthread_mutex_destroy( &L1_proc_tx->mutex ); + pthread_cond_destroy( &L1_proc_tx->cond ); + pthread_mutex_destroy( &proc->mutex_RU ); + pthread_mutex_destroy( &proc->mutex_RU_tx ); + } +} + + + + +void reset_opp_meas(void) { + int sfn; + reset_meas(&softmodem_stats_mt); + reset_meas(&softmodem_stats_hw); + + for (sfn=0; sfn < 10; sfn++) { + reset_meas(&softmodem_stats_rxtx_sf); + reset_meas(&softmodem_stats_rx_sf); + } +} + + +void print_opp_meas(void) { + int sfn=0; + print_meas(&softmodem_stats_mt, "Main gNB Thread", NULL, NULL); + print_meas(&softmodem_stats_hw, "HW Acquisation", NULL, NULL); + + for (sfn=0; sfn < 10; sfn++) { + print_meas(&softmodem_stats_rxtx_sf,"[gNB][total_phy_proc_rxtx]",NULL, NULL); + print_meas(&softmodem_stats_rx_sf,"[gNB][total_phy_proc_rx]",NULL,NULL); + } +} + + +/// eNB kept in function name for nffapi calls, TO FIX +void init_eNB_afterRU(void) { + int inst,CC_id,ru_id,i,aa; + PHY_VARS_gNB *gNB; + LOG_I(PHY,"%s() RC.nb_nr_inst:%d\n", __FUNCTION__, RC.nb_nr_inst); + + for (inst=0; instnum_RU>0,"Number of RU attached to gNB %d is zero\n",gNB->Mod_id); + + LOG_I(PHY,"Mapping RX ports from %d RUs to gNB %d\n",gNB->num_RU,gNB->Mod_id); + //LOG_I(PHY,"Overwriting gNB->prach_vars.rxsigF[0]:%p\n", gNB->prach_vars.rxsigF[0]); + gNB->prach_vars.rxsigF[0] = (int16_t **)malloc16(64*sizeof(int16_t *)); + LOG_I(PHY,"gNB->num_RU:%d\n", gNB->num_RU); + + for (ru_id=0,aa=0; ru_idnum_RU; ru_id++) { + AssertFatal(gNB->RU_list[ru_id]->common.rxdataF!=NULL, + "RU %d : common.rxdataF is NULL\n", + gNB->RU_list[ru_id]->idx); + AssertFatal(gNB->RU_list[ru_id]->prach_rxsigF!=NULL, + "RU %d : prach_rxsigF is NULL\n", + gNB->RU_list[ru_id]->idx); + + for (i=0; iRU_list[ru_id]->nb_rx; aa++,i++) { + LOG_I(PHY,"Attaching RU %d antenna %d to gNB antenna %d\n",gNB->RU_list[ru_id]->idx,i,aa); + gNB->prach_vars.rxsigF[0][aa] = gNB->RU_list[ru_id]->prach_rxsigF[i]; + gNB->common_vars.rxdataF[aa] = gNB->RU_list[ru_id]->common.rxdataF[i]; + } + } + + /* TODO: review this code, there is something wrong. + * In monolithic mode, we come here with nb_antennas_rx == 0 + * (not tested in other modes). + */ + //init_precoding_weights(RC.gNB[inst][CC_id]); + } + + init_gNB_proc(inst); + } + + for (ru_id=0; ru_idnr_wakeup_rxtx = wakeup_rxtx; + // RC.ru[ru_id]->wakeup_prach_eNB = wakeup_prach_gNB; + RC.ru[ru_id]->gNB_top = gNB_top; + } +} + +void init_gNB(int single_thread_flag,int wait_for_sync) { + int CC_id; + int inst; + PHY_VARS_gNB *gNB; + LOG_I(PHY,"[nr-softmodem.c] gNB structure about to allocated RC.nb_nr_L1_inst:%d RC.nb_nr_L1_CC[0]:%d\n",RC.nb_nr_L1_inst,RC.nb_nr_L1_CC[0]); + + if (RC.gNB == NULL) RC.gNB = (PHY_VARS_gNB ***) malloc(RC.nb_nr_L1_inst*sizeof(PHY_VARS_gNB **)); + + LOG_I(PHY,"[lte-softmodem.c] gNB structure RC.gNB allocated\n"); + + for (inst=0; instabstraction_flag = 0; + gNB->single_thread_flag = single_thread_flag; + /*nr_polar_init(&gNB->nrPolar_params, + NR_POLAR_PBCH_MESSAGE_TYPE, + NR_POLAR_PBCH_PAYLOAD_BITS, + NR_POLAR_PBCH_AGGREGATION_LEVEL);*/ + LOG_I(PHY,"Initializing gNB %d CC_id %d single_thread_flag:%d\n",inst,CC_id,single_thread_flag); +#ifndef OCP_FRAMEWORK + LOG_I(PHY,"Initializing gNB %d CC_id %d\n",inst,CC_id); +#endif + LOG_I(PHY,"Registering with MAC interface module\n"); + AssertFatal((gNB->if_inst = NR_IF_Module_init(inst))!=NULL,"Cannot register interface"); + gNB->if_inst->NR_Schedule_response = nr_schedule_response; + gNB->if_inst->NR_PHY_config_req = nr_phy_config_request; + memset((void *)&gNB->UL_INFO,0,sizeof(gNB->UL_INFO)); + memset((void *)&gNB->Sched_INFO,0,sizeof(gNB->Sched_INFO)); + LOG_I(PHY,"Setting indication lists\n"); + gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list = gNB->rx_pdu_list; + gNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list = gNB->crc_pdu_list; + gNB->UL_INFO.sr_ind.sr_indication_body.sr_pdu_list = gNB->sr_pdu_list; + gNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = gNB->harq_pdu_list; + gNB->UL_INFO.cqi_ind.cqi_pdu_list = gNB->cqi_pdu_list; + gNB->UL_INFO.cqi_ind.cqi_raw_pdu_list = gNB->cqi_raw_pdu_list; + gNB->prach_energy_counter = 0; + } + } + + LOG_I(PHY,"[nr-softmodem.c] gNB structure allocated\n"); +} + + +void stop_gNB(int nb_inst) { + for (int inst=0; inst. + + Contact Information + OpenAirInterface Admin: openair_admin@eurecom.fr + OpenAirInterface Tech : openair_tech@eurecom.fr + OpenAirInterface Dev : openair4g-devel@lists.eurecom.fr + + Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE + +*******************************************************************************/ + +/*! \file lte-enb.c + * \brief Top-level threads for eNodeB + * \author R. Knopp, F. Kaltenberger, Navid Nikaein + * \date 2012 + * \version 0.1 + * \company Eurecom + * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr, navid.nikaein@eurecom.fr + * \note + * \warning + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "common/utils/assertions.h" +#include "common/utils/system.h" +#include "msc.h" + +#include "../../ARCH/COMMON/common_lib.h" +#include "../../ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.h" + +#include "PHY/LTE_TRANSPORT/if4_tools.h" +#include "PHY/LTE_TRANSPORT/if5_tools.h" + +#include "PHY/types.h" +#include "PHY/defs_nr_common.h" +#include "PHY/phy_extern.h" +#include "PHY/LTE_TRANSPORT/transport_proto.h" +#include "PHY/INIT/phy_init.h" +#include "SCHED/sched_eNB.h" +#include "SCHED_NR/sched_nr.h" + +#include "LAYER2/MAC/mac.h" +#include "LAYER2/MAC/mac_extern.h" +#include "LAYER2/MAC/mac_proto.h" +#include "RRC/LTE/rrc_extern.h" +#include "PHY_INTERFACE/phy_interface.h" + +#include "common/utils/LOG/log.h" +#include "common/utils/LOG/vcd_signal_dumper.h" + +#include "enb_config.h" + +#ifdef SMBV +#include "PHY/TOOLS/smbv.h" +unsigned short config_frames[4] = {2,9,11,13}; +#endif + +/* these variables have to be defined before including ENB_APP/enb_paramdef.h */ +static int DEFBANDS[] = {7}; +static int DEFENBS[] = {0}; + +#include "ENB_APP/enb_paramdef.h" +#include "common/config/config_userapi.h" + +#ifndef OPENAIR2 + #include "UTIL/OTG/otg_extern.h" +#endif + +#if defined(ENABLE_ITTI) + #if defined(ENABLE_USE_MME) + #include "s1ap_eNB.h" + #ifdef PDCP_USE_NETLINK + #include "SIMULATION/ETH_TRANSPORT/proto.h" + #endif + #endif +#endif + +#include "T.h" +#include "nfapi_interface.h" + +extern volatile int oai_exit; + + +extern void nr_phy_init_RU(RU_t *); +extern void nr_phy_free_RU(RU_t *); +extern void nr_phy_config_request(NR_PHY_Config_t *gNB); + +extern PARALLEL_CONF_t get_thread_parallel_conf(void); +extern WORKER_CONF_t get_thread_worker_conf(void); + +void init_RU(char *); +void stop_RU(int nb_ru); +void do_ru_sync(RU_t *ru); + +void configure_ru(int idx, + void *arg); + +void configure_rru(int idx, + void *arg); + +int attach_rru(RU_t *ru); + +int connect_rau(RU_t *ru); + +extern uint16_t sl_ahead; + +extern int emulate_rf; +extern int numerology; + +/*************************************************************/ +/* Functions to attach and configure RRU */ + +extern void wait_gNBs(void); + +int attach_rru(RU_t *ru) { + ssize_t msg_len,len; + RRU_CONFIG_msg_t rru_config_msg; + int received_capabilities=0; + wait_gNBs(); + + // Wait for capabilities + while (received_capabilities==0) { + memset((void *)&rru_config_msg,0,sizeof(rru_config_msg)); + rru_config_msg.type = RAU_tick; + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE; + LOG_I(PHY,"Sending RAU tick to RRU %d\n",ru->idx); + AssertFatal((ru->ifdevice.trx_ctlsend_func(&ru->ifdevice,&rru_config_msg,rru_config_msg.len)!=-1), + "RU %d cannot access remote radio\n",ru->idx); + msg_len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE+sizeof(RRU_capabilities_t); + + // wait for answer with timeout + if ((len = ru->ifdevice.trx_ctlrecv_func(&ru->ifdevice, + &rru_config_msg, + msg_len))<0) { + LOG_I(PHY,"Waiting for RRU %d\n",ru->idx); + } else if (rru_config_msg.type == RRU_capabilities) { + AssertFatal(rru_config_msg.len==msg_len,"Received capabilities with incorrect length (%d!=%d)\n",(int)rru_config_msg.len,(int)msg_len); + LOG_I(PHY,"Received capabilities from RRU %d (len %d/%d, num_bands %d,max_pdschReferenceSignalPower %d, max_rxgain %d, nb_tx %d, nb_rx %d)\n",ru->idx, + (int)rru_config_msg.len,(int)msg_len, + ((RRU_capabilities_t *)&rru_config_msg.msg[0])->num_bands, + ((RRU_capabilities_t *)&rru_config_msg.msg[0])->max_pdschReferenceSignalPower[0], + ((RRU_capabilities_t *)&rru_config_msg.msg[0])->max_rxgain[0], + ((RRU_capabilities_t *)&rru_config_msg.msg[0])->nb_tx[0], + ((RRU_capabilities_t *)&rru_config_msg.msg[0])->nb_rx[0]); + received_capabilities=1; + } else { + LOG_E(PHY,"Received incorrect message %d from RRU %d\n",rru_config_msg.type,ru->idx); + } + } + + configure_ru(ru->idx, + (RRU_capabilities_t *)&rru_config_msg.msg[0]); + rru_config_msg.type = RRU_config; + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE+sizeof(RRU_config_t); + LOG_I(PHY,"Sending Configuration to RRU %d (num_bands %d,band0 %d,txfreq %u,rxfreq %u,att_tx %d,att_rx %d,N_RB_DL %d,N_RB_UL %d,3/4FS %d, prach_FO %d, prach_CI %d)\n",ru->idx, + ((RRU_config_t *)&rru_config_msg.msg[0])->num_bands, + ((RRU_config_t *)&rru_config_msg.msg[0])->band_list[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->tx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->rx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_tx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_rx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_DL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_UL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->threequarter_fs[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_FreqOffset[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_ConfigIndex[0]); + AssertFatal((ru->ifdevice.trx_ctlsend_func(&ru->ifdevice,&rru_config_msg,rru_config_msg.len)!=-1), + "RU %d failed send configuration to remote radio\n",ru->idx); + return 0; +} + +int connect_rau(RU_t *ru) { + RRU_CONFIG_msg_t rru_config_msg; + ssize_t msg_len; + int tick_received = 0; + int configuration_received = 0; + RRU_capabilities_t *cap; + int i; + int len; + + // wait for RAU_tick + while (tick_received == 0) { + msg_len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE; + + if ((len = ru->ifdevice.trx_ctlrecv_func(&ru->ifdevice, + &rru_config_msg, + msg_len))<0) { + LOG_I(PHY,"Waiting for RAU\n"); + } else { + if (rru_config_msg.type == RAU_tick) { + LOG_I(PHY,"Tick received from RAU\n"); + tick_received = 1; + } else LOG_E(PHY,"Received erroneous message (%d)from RAU, expected RAU_tick\n",rru_config_msg.type); + } + } + + // send capabilities + rru_config_msg.type = RRU_capabilities; + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE+sizeof(RRU_capabilities_t); + cap = (RRU_capabilities_t *)&rru_config_msg.msg[0]; + LOG_I(PHY,"Sending Capabilities (len %d, num_bands %d,max_pdschReferenceSignalPower %d, max_rxgain %d, nb_tx %d, nb_rx %d)\n", + (int)rru_config_msg.len,ru->num_bands,ru->max_pdschReferenceSignalPower,ru->max_rxgain,ru->nb_tx,ru->nb_rx); + + switch (ru->function) { + case NGFI_RRU_IF4p5: + cap->FH_fmt = OAI_IF4p5_only; + break; + + case NGFI_RRU_IF5: + cap->FH_fmt = OAI_IF5_only; + break; + + case MBP_RRU_IF5: + cap->FH_fmt = MBP_IF5; + break; + + default: + AssertFatal(1==0,"RU_function is unknown %d\n",RC.ru[0]->function); + break; + } + + cap->num_bands = ru->num_bands; + + for (i=0; inum_bands; i++) { + LOG_I(PHY,"Band %d: nb_rx %d nb_tx %d pdschReferenceSignalPower %d rxgain %d\n", + ru->band[i],ru->nb_rx,ru->nb_tx,ru->max_pdschReferenceSignalPower,ru->max_rxgain); + cap->band_list[i] = ru->band[i]; + cap->nb_rx[i] = ru->nb_rx; + cap->nb_tx[i] = ru->nb_tx; + cap->max_pdschReferenceSignalPower[i] = ru->max_pdschReferenceSignalPower; + cap->max_rxgain[i] = ru->max_rxgain; + } + + AssertFatal((ru->ifdevice.trx_ctlsend_func(&ru->ifdevice,&rru_config_msg,rru_config_msg.len)!=-1), + "RU %d failed send capabilities to RAU\n",ru->idx); + // wait for configuration + rru_config_msg.len = sizeof(RRU_CONFIG_msg_t)-MAX_RRU_CONFIG_SIZE+sizeof(RRU_config_t); + + while (configuration_received == 0) { + if ((len = ru->ifdevice.trx_ctlrecv_func(&ru->ifdevice, + &rru_config_msg, + rru_config_msg.len))<0) { + LOG_I(PHY,"Waiting for configuration from RAU\n"); + } else { + LOG_I(PHY,"Configuration received from RAU (num_bands %d,band0 %d,txfreq %u,rxfreq %u,att_tx %d,att_rx %d,N_RB_DL %d,N_RB_UL %d,3/4FS %d, prach_FO %d, prach_CI %d)\n", + ((RRU_config_t *)&rru_config_msg.msg[0])->num_bands, + ((RRU_config_t *)&rru_config_msg.msg[0])->band_list[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->tx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->rx_freq[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_tx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->att_rx[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_DL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->N_RB_UL[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->threequarter_fs[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_FreqOffset[0], + ((RRU_config_t *)&rru_config_msg.msg[0])->prach_ConfigIndex[0]); + configure_rru(ru->idx, + (void *)&rru_config_msg.msg[0]); + configuration_received = 1; + } + } + + return 0; +} +/*************************************************************/ +/* Southbound Fronthaul functions, RCC/RAU */ + +// southbound IF5 fronthaul for 16-bit OAI format +static inline void fh_if5_south_out(RU_t *ru) { + if (ru == RC.ru[0]) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, ru->proc.timestamp_tx&0xffffffff ); + + send_IF5(ru, ru->proc.timestamp_tx, ru->proc.tti_tx, &ru->seqno, IF5_RRH_GW_DL); +} + +// southbound IF5 fronthaul for Mobipass packet format +static inline void fh_if5_mobipass_south_out(RU_t *ru) { + if (ru == RC.ru[0]) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, ru->proc.timestamp_tx&0xffffffff ); + + send_IF5(ru, ru->proc.timestamp_tx, ru->proc.tti_tx, &ru->seqno, IF5_MOBIPASS); +} + +// southbound IF4p5 fronthaul +static inline void fh_if4p5_south_out(RU_t *ru) { + if (ru == RC.ru[0]) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, ru->proc.timestamp_tx&0xffffffff ); + + LOG_D(PHY,"Sending IF4p5 for frame %d subframe %d\n",ru->proc.frame_tx,ru->proc.tti_tx); + + if (nr_slot_select(&ru->gNB_list[0]->gNB_config,ru->proc.tti_tx)!=SF_UL) + send_IF4p5(ru,ru->proc.frame_tx, ru->proc.tti_tx, IF4p5_PDLFFT); +} + +/*************************************************************/ +/* Input Fronthaul from south RCC/RAU */ + +// Synchronous if5 from south +void fh_if5_south_in(RU_t *ru,int *frame, int *tti) { + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + RU_proc_t *proc = &ru->proc; + recv_IF5(ru, &proc->timestamp_rx, *tti, IF5_RRH_GW_UL); + proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_slot*20))&1023; + proc->tti_rx = (proc->timestamp_rx / fp->samples_per_slot)%20; + + if (proc->first_rx == 0) { + if (proc->tti_rx != *tti) { + LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->tti_rx %d, subframe %d)\n",proc->tti_rx,*tti); + exit_fun("Exiting"); + } + + if (proc->frame_rx != *frame) { + LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->frame_rx %d frame %d)\n",proc->frame_rx,*frame); + exit_fun("Exiting"); + } + } else { + proc->first_rx = 0; + *frame = proc->frame_rx; + *tti = proc->tti_rx; + } + + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TS, proc->timestamp_rx&0xffffffff ); +} + +// Synchronous if4p5 from south +void fh_if4p5_south_in(RU_t *ru,int *frame,int *slot) { + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + RU_proc_t *proc = &ru->proc; + int f,sl; + uint16_t packet_type; + uint32_t symbol_number=0; + uint32_t symbol_mask_full=0; + + /* + if ((fp->frame_type == TDD) && (subframe_select(fp,*slot)==SF_S)) + symbol_mask_full = (1<ul_symbols_in_S_subframe)-1; + else + symbol_mask_full = (1<symbols_per_slot)-1; + + AssertFatal(proc->symbol_mask[*slot]==0,"rx_fh_if4p5: proc->symbol_mask[%d] = %x\n",*slot,proc->symbol_mask[*slot]);*/ + do { // Blocking, we need a timeout on this !!!!!!!!!!!!!!!!!!!!!!! + recv_IF4p5(ru, &f, &sl, &packet_type, &symbol_number); + + if (packet_type == IF4p5_PULFFT) proc->symbol_mask[sl] = proc->symbol_mask[sl] | (1<first_rx==0) && (f!=*frame)) LOG_E(PHY,"rx_fh_if4p5: PULTICK received frame %d != expected %d\n",f,*frame); + + if ((proc->first_rx==0) && (sl!=*slot)) LOG_E(PHY,"rx_fh_if4p5: PULTICK received subframe %d != expected %d (first_rx %d)\n",sl,*slot,proc->first_rx); + + break; + } else if (packet_type == IF4p5_PRACH) { + // nothing in RU for RAU + } + + LOG_D(PHY,"rx_fh_if4p5: subframe %d symbol mask %x\n",*slot,proc->symbol_mask[sl]); + } while(proc->symbol_mask[sl] != symbol_mask_full); + + //caculate timestamp_rx, timestamp_tx based on frame and subframe + proc->tti_rx = sl; + proc->frame_rx = f; + proc->timestamp_rx = ((proc->frame_rx * fp->slots_per_frame) + proc->tti_rx ) * fp->samples_per_slot ; + // proc->timestamp_tx = proc->timestamp_rx + (4*fp->samples_per_subframe); + proc->tti_tx = (sl+sl_ahead)%fp->slots_per_frame; + proc->frame_tx = (sl>(fp->slots_per_frame-sl_ahead)) ? (f+1)&1023 : f; + + if (proc->first_rx == 0) { + if (proc->tti_rx != *slot) { + LOG_E(PHY,"Received Timestamp (IF4p5) doesn't correspond to the time we think it is (proc->tti_rx %d, subframe %d)\n",proc->tti_rx,*slot); + exit_fun("Exiting"); + } + + if (proc->frame_rx != *frame) { + LOG_E(PHY,"Received Timestamp (IF4p5) doesn't correspond to the time we think it is (proc->frame_rx %d frame %d)\n",proc->frame_rx,*frame); + exit_fun("Exiting"); + } + } else { + proc->first_rx = 0; + *frame = proc->frame_rx; + *slot = proc->tti_rx; + } + + if (ru == RC.ru[0]) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_RU, f ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_RX0_RU, sl); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_RU, proc->frame_tx ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_TX0_RU, proc->tti_tx ); + } + + proc->symbol_mask[proc->tti_rx] = 0; + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TS, proc->timestamp_rx&0xffffffff ); + LOG_D(PHY,"RU %d: fh_if4p5_south_in sleeping ...\n",ru->idx); +} + +// asynchronous inbound if4p5 fronthaul from south +void fh_if4p5_south_asynch_in(RU_t *ru,int *frame,int *slot) { + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + RU_proc_t *proc = &ru->proc; + uint16_t packet_type; + uint32_t symbol_number,symbol_mask,prach_rx; + // uint32_t got_prach_info=0; + symbol_number = 0; + symbol_mask = (1<<(fp->symbols_per_slot))-1; + prach_rx = 0; + + do { // Blocking, we need a timeout on this !!!!!!!!!!!!!!!!!!!!!!! + recv_IF4p5(ru, &proc->frame_rx, &proc->tti_rx, &packet_type, &symbol_number); + + // grab first prach information for this new subframe + /*if (got_prach_info==0) { + prach_rx = is_prach_subframe(fp, proc->frame_rx, proc->tti_rx); + got_prach_info = 1; + }*/ + if (proc->first_rx != 0) { + *frame = proc->frame_rx; + *slot = proc->tti_rx; + proc->first_rx = 0; + } else { + if (proc->frame_rx != *frame) { + LOG_E(PHY,"frame_rx %d is not what we expect %d\n",proc->frame_rx,*frame); + exit_fun("Exiting"); + } + + if (proc->tti_rx != *slot) { + LOG_E(PHY,"tti_rx %d is not what we expect %d\n",proc->tti_rx,*slot); + exit_fun("Exiting"); + } + } + + if (packet_type == IF4p5_PULFFT) symbol_mask &= (~(1< 0) || (prach_rx >0)); // haven't received all PUSCH symbols and PRACH information +} + + + + + +/*************************************************************/ +/* Input Fronthaul from North RRU */ + +// RRU IF4p5 TX fronthaul receiver. Assumes an if_device on input and if or rf device on output +// receives one subframe's worth of IF4p5 OFDM symbols and OFDM modulates +void fh_if4p5_north_in(RU_t *ru,int *frame,int *slot) { + uint32_t symbol_number=0; + uint32_t symbol_mask, symbol_mask_full; + uint16_t packet_type; + /// **** incoming IF4p5 from remote RCC/RAU **** /// + symbol_number = 0; + symbol_mask = 0; + symbol_mask_full = (1<<(ru->nr_frame_parms->symbols_per_slot))-1; + + do { + recv_IF4p5(ru, frame, slot, &packet_type, &symbol_number); + symbol_mask = symbol_mask | (1<nr_frame_parms; + RU_proc_t *proc = &ru->proc; + int tti_tx,frame_tx; + openair0_timestamp timestamp_tx; + recv_IF5(ru, ×tamp_tx, *slot, IF5_RRH_GW_DL); + // printf("Received subframe %d (TS %llu) from RCC\n",tti_tx,timestamp_tx); + tti_tx = (timestamp_tx/fp->samples_per_slot)%fp->slots_per_frame; + frame_tx = (timestamp_tx/(fp->samples_per_slot*fp->slots_per_frame))&1023; + + if (proc->first_tx != 0) { + *slot = tti_tx; + *frame = frame_tx; + proc->first_tx = 0; + } else { + AssertFatal(tti_tx == *slot, + "tti_tx %d is not what we expect %d\n",tti_tx,*slot); + AssertFatal(frame_tx == *frame, + "frame_tx %d is not what we expect %d\n",frame_tx,*frame); + } +} + +void fh_if4p5_north_asynch_in(RU_t *ru,int *frame,int *slot) { + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config; + RU_proc_t *proc = &ru->proc; + uint16_t packet_type; + uint32_t symbol_number,symbol_mask,symbol_mask_full=0; + int slot_tx,frame_tx; + LOG_D(PHY, "%s(ru:%p frame, subframe)\n", __FUNCTION__, ru); + symbol_number = 0; + symbol_mask = 0; + + // symbol_mask_full = ((subframe_select(fp,*slot) == SF_S) ? (1<dl_symbols_in_S_subframe) : (1<symbols_per_slot))-1; + do { + recv_IF4p5(ru, &frame_tx, &slot_tx, &packet_type, &symbol_number); + + if ((nr_slot_select(cfg,slot_tx) == SF_DL) && (symbol_number == 0)) start_meas(&ru->rx_fhaul); + + LOG_D(PHY,"subframe %d (%d): frame %d, subframe %d, symbol %d\n", + *slot,nr_slot_select(cfg,*slot),frame_tx,slot_tx,symbol_number); + + if (proc->first_tx != 0) { + *frame = frame_tx; + *slot = slot_tx; + proc->first_tx = 0; + //symbol_mask_full = ((subframe_select(fp,*slot) == SF_S) ? (1<dl_symbols_in_S_subframe) : (1<symbols_per_slot))-1; + } else { + AssertFatal(frame_tx == *frame, + "frame_tx %d is not what we expect %d\n",frame_tx,*frame); + AssertFatal(slot_tx == *slot, + "slot_tx %d is not what we expect %d\n",slot_tx,*slot); + } + + if (packet_type == IF4p5_PDLFFT) { + symbol_mask = symbol_mask | (1<rx_fhaul); + + proc->tti_tx = slot_tx; + proc->frame_tx = frame_tx; + + if ((frame_tx == 0)&&(slot_tx == 0)) proc->frame_tx_unwrap += 1024; + + proc->timestamp_tx = ((((uint64_t)frame_tx + (uint64_t)proc->frame_tx_unwrap) * fp->slots_per_frame) + (uint64_t)slot_tx) * (uint64_t)fp->samples_per_slot; + LOG_D(PHY,"RU %d/%d TST %llu, frame %d, subframe %d\n",ru->idx,0,(long long unsigned int)proc->timestamp_tx,frame_tx,slot_tx); + + // dump VCD output for first RU in list + if (ru == RC.ru[0]) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_RU, frame_tx ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_TX0_RU, slot_tx ); + } + + if (ru->feptx_ofdm) ru->feptx_ofdm(ru); + + if (ru->fh_south_out) ru->fh_south_out(ru); +} + +void fh_if5_north_out(RU_t *ru) { + RU_proc_t *proc=&ru->proc; + uint8_t seqno=0; + /// **** send_IF5 of rxdata to BBU **** /// + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 1 ); + send_IF5(ru, proc->timestamp_rx, proc->tti_rx, &seqno, IF5_RRH_GW_UL); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 0 ); +} + +// RRU IF4p5 northbound interface (RX) +void fh_if4p5_north_out(RU_t *ru) { + RU_proc_t *proc=&ru->proc; + + //NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + //const int subframe = proc->tti_rx; + if (ru->idx==0) VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_RX0_RU, proc->tti_rx ); + + /* + if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)!=SF_UL)) { + /// **** in TDD during DL send_IF4 of ULTICK to RCC **** /// + send_IF4p5(ru, proc->frame_rx, proc->tti_rx, IF4p5_PULTICK); + return; + }*/ + start_meas(&ru->tx_fhaul); + send_IF4p5(ru, proc->frame_rx, proc->tti_rx, IF4p5_PULFFT); + stop_meas(&ru->tx_fhaul); +} + +static void *emulatedRF_thread(void *param) { + RU_proc_t *proc = (RU_proc_t *) param; + int microsec = 500; // length of time to sleep, in miliseconds + struct timespec req = {0}; + req.tv_sec = 0; + req.tv_nsec = (numerology>0)? ((microsec * 1000L)/numerology):(microsec * 1000L)*2; + threadTopInit("emulatedRF",-1,OAI_PRIORITY_RT_LOW); + wait_sync("emulatedRF_thread"); + + while(!oai_exit) { + nanosleep(&req, (struct timespec *)NULL); + pthread_mutex_lock(&proc->mutex_emulateRF); + ++proc->instance_cnt_emulateRF; + pthread_mutex_unlock(&proc->mutex_emulateRF); + pthread_cond_signal(&proc->cond_emulateRF); + } + + return 0; +} + +void rx_rf(RU_t *ru,int *frame,int *slot) { + RU_proc_t *proc = &ru->proc; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + void *rxp[ru->nb_rx]; + unsigned int rxs; + int i; + openair0_timestamp ts,old_ts; + AssertFatal(*slotslots_per_frame && *slot>=0, "slot %d is illegal (%d)\n",*slot,fp->slots_per_frame); + + for (i=0; inb_rx; i++) + rxp[i] = (void *)&ru->common.rxdata[i][*slot*fp->samples_per_slot]; + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, 1 ); + old_ts = proc->timestamp_rx; + LOG_D(PHY,"Reading %d samples for slot %d (%p)\n",fp->samples_per_slot,*slot,rxp[0]); + + if(emulate_rf) { + wait_on_condition(&proc->mutex_emulateRF,&proc->cond_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread"); + release_thread(&proc->mutex_emulateRF,&proc->instance_cnt_emulateRF,"emulatedRF_thread"); + rxs = fp->samples_per_slot; + ts = old_ts + rxs; + } else { + rxs = ru->rfdevice.trx_read_func(&ru->rfdevice, + &ts, + rxp, + fp->samples_per_slot, + ru->nb_rx); + } + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, 0 ); + proc->timestamp_rx = ts-ru->ts_offset; + + //AssertFatal(rxs == fp->samples_per_subframe, + //"rx_rf: Asked for %d samples, got %d from USRP\n",fp->samples_per_subframe,rxs); + if (rxs != fp->samples_per_slot) LOG_E(PHY, "rx_rf: Asked for %d samples, got %d from USRP\n",fp->samples_per_slot,rxs); + + if (proc->first_rx == 1) { + ru->ts_offset = proc->timestamp_rx; + proc->timestamp_rx = 0; + } else { + if (proc->timestamp_rx - old_ts != fp->samples_per_slot) { + LOG_I(PHY,"rx_rf: rfdevice timing drift of %"PRId64" samples (ts_off %"PRId64")\n",proc->timestamp_rx - old_ts - fp->samples_per_slot,ru->ts_offset); + ru->ts_offset += (proc->timestamp_rx - old_ts - fp->samples_per_slot); + proc->timestamp_rx = ts-ru->ts_offset; + } + } + + proc->frame_rx = (proc->timestamp_rx / (fp->samples_per_slot*fp->slots_per_frame))&1023; + proc->tti_rx = (proc->timestamp_rx / fp->samples_per_slot)%fp->slots_per_frame; + // synchronize first reception to frame 0 subframe 0 + proc->timestamp_tx = proc->timestamp_rx+(sl_ahead*fp->samples_per_slot); + proc->tti_tx = (proc->tti_rx+sl_ahead)%fp->slots_per_frame; + proc->frame_tx = (proc->tti_rx>(fp->slots_per_frame-1-sl_ahead)) ? (proc->frame_rx+1)&1023 : proc->frame_rx; + LOG_I(PHY,"RU %d/%d TS %llu (off %d), frame %d, slot %d.%d / %d\n", + ru->idx, + 0, + (unsigned long long int)proc->timestamp_rx, + (int)ru->ts_offset,proc->frame_rx,proc->tti_rx,proc->tti_tx,fp->slots_per_frame); + + // dump VCD output for first RU in list + if (ru == RC.ru[0]) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_RX0_RU, proc->frame_rx ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_RX0_RU, proc->tti_rx ); + } + + if (proc->first_rx == 0) { + if (proc->tti_rx != *slot) { + LOG_E(PHY,"Received Timestamp (%llu) doesn't correspond to the time we think it is (proc->tti_rx %d, subframe %d)\n",(long long unsigned int)proc->timestamp_rx,proc->tti_rx,*slot); + exit_fun("Exiting"); + } + + if (proc->frame_rx != *frame) { + LOG_E(PHY,"Received Timestamp (%llu) doesn't correspond to the time we think it is (proc->frame_rx %d frame %d)\n",(long long unsigned int)proc->timestamp_rx,proc->frame_rx,*frame); + exit_fun("Exiting"); + } + } else { + proc->first_rx = 0; + *frame = proc->frame_rx; + *slot = proc->tti_rx; + } + + //printf("timestamp_rx %lu, frame %d(%d), subframe %d(%d)\n",ru->timestamp_rx,proc->frame_rx,frame,proc->tti_rx,subframe); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TS, proc->timestamp_rx&0xffffffff ); + + if (rxs != fp->samples_per_slot) { + //exit_fun( "problem receiving samples" ); + LOG_E(PHY, "problem receiving samples\n"); + } +} + + +void tx_rf(RU_t *ru) { + RU_proc_t *proc = &ru->proc; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + nfapi_nr_config_request_t *cfg = &ru->gNB_list[0]->gNB_config; + void *txp[ru->nb_tx]; + unsigned int txs; + int i; + T(T_ENB_PHY_OUTPUT_SIGNAL, T_INT(0), T_INT(0), T_INT(proc->frame_tx), T_INT(proc->tti_tx), + T_INT(0), T_BUFFER(&ru->common.txdata[0][proc->tti_tx * fp->samples_per_slot], fp->samples_per_slot * 4)); + nr_subframe_t SF_type = nr_slot_select(cfg,proc->tti_tx%fp->slots_per_frame); + int sf_extension = 0; + + if ((SF_type == SF_DL) || + (SF_type == SF_S)) { + int siglen=fp->samples_per_slot,flags=1; + /* + if (SF_type == SF_S) { + siglen = fp->dl_symbols_in_S_subframe*(fp->ofdm_symbol_size+fp->nb_prefix_samples0); + flags=3; // end of burst + } + if ((fp->frame_type == TDD) && + (SF_type == SF_DL)&& + (prevSF_type == SF_UL) && + (nextSF_type == SF_DL)) { + flags = 2; // start of burst + sf_extension = ru->N_TA_offset<<1; + } + + if ((cfg->subframe_config.duplex_mode == TDD) && + (SF_type == SF_DL)&& + (prevSF_type == SF_UL) && + (nextSF_type == SF_UL)) { + flags = 4; // start of burst and end of burst (only one DL SF between two UL) + sf_extension = ru->N_TA_offset<<1; + } */ + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_RU, proc->frame_tx ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_TX0_RU, proc->tti_tx ); + + for (i=0; inb_tx; i++) + txp[i] = (void *)&ru->common.txdata[i][(proc->tti_tx*fp->samples_per_slot)-sf_extension]; + + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (proc->timestamp_tx-ru->openair0_cfg.tx_sample_advance)&0xffffffff ); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 ); + // prepare tx buffer pointers + txs = ru->rfdevice.trx_write_func(&ru->rfdevice, + proc->timestamp_tx+ru->ts_offset-ru->openair0_cfg.tx_sample_advance-sf_extension, + txp, + siglen+sf_extension, + ru->nb_tx, + flags); + LOG_D(PHY,"[TXPATH] RU %d tx_rf, writing to TS %llu, frame %d, unwrapped_frame %d, subframe %d\n",ru->idx, + (long long unsigned int)proc->timestamp_tx,proc->frame_tx,proc->frame_tx_unwrap,proc->tti_tx); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 0 ); + AssertFatal(txs == siglen+sf_extension,"TX : Timeout (sent %d/%d)\n",txs, siglen); + } +} + + +/*! + * \brief The Asynchronous RX/TX FH thread of RAU/RCC/gNB/RRU. + * This handles the RX FH for an asynchronous RRU/UE + * \param param is a \ref gNB_L1_proc_t structure which contains the info what to process. + * \returns a pointer to an int. The storage is not on the heap and must not be freed. + */ +static void *ru_thread_asynch_rxtx( void *param ) { + static int ru_thread_asynch_rxtx_status; + RU_t *ru = (RU_t *)param; + RU_proc_t *proc = &ru->proc; + int subframe=0, frame=0; + thread_top_init("ru_thread_asynch_rxtx",1,870000L,1000000L,1000000L); + // wait for top-level synchronization and do one acquisition to get timestamp for setting frame/subframe + wait_sync("ru_thread_asynch_rxtx"); + // wait for top-level synchronization and do one acquisition to get timestamp for setting frame/subframe + printf( "waiting for devices (ru_thread_asynch_rx)\n"); + wait_on_condition(&proc->mutex_asynch_rxtx,&proc->cond_asynch_rxtx,&proc->instance_cnt_asynch_rxtx,"thread_asynch"); + printf( "devices ok (ru_thread_asynch_rx)\n"); + + while (!oai_exit) { + if (oai_exit) break; + + if (subframe==9) { + subframe=0; + frame++; + frame&=1023; + } else { + subframe++; + } + + LOG_D(PHY,"ru_thread_asynch_rxtx: Waiting on incoming fronthaul\n"); + + // asynchronous receive from south (Mobipass) + if (ru->fh_south_asynch_in) ru->fh_south_asynch_in(ru,&frame,&subframe); + // asynchronous receive from north (RRU IF4/IF5) + else if (ru->fh_north_asynch_in) { + if (nr_slot_select(&ru->gNB_list[0]->gNB_config,subframe)!=SF_UL) + ru->fh_north_asynch_in(ru,&frame,&subframe); + } else AssertFatal(1==0,"Unknown function in ru_thread_asynch_rxtx\n"); + } + + ru_thread_asynch_rxtx_status=0; + return(&ru_thread_asynch_rxtx_status); +} + + + + +/*! + * \brief The prach receive thread of RU. + * \param param is a \ref RU_proc_t structure which contains the info what to process. + * \returns a pointer to an int. The storage is not on the heap and must not be freed. + */ +static void *ru_thread_prach( void *param ) { + static int ru_thread_prach_status; + RU_t *ru = (RU_t *)param; + RU_proc_t *proc = (RU_proc_t *)&ru->proc; + // set default return value + ru_thread_prach_status = 0; + thread_top_init("ru_thread_prach",1,500000L,1000000L,20000000L); + + while (RC.ru_mask>0) { + usleep(1e6); + LOG_I(PHY,"%s() RACH waiting for RU to be configured\n", __FUNCTION__); + } + + LOG_I(PHY,"%s() RU configured - RACH processing thread running\n", __FUNCTION__); + + while (!oai_exit) { + if (oai_exit) break; + + if (wait_on_condition(&proc->mutex_prach,&proc->cond_prach,&proc->instance_cnt_prach,"ru_prach_thread") < 0) break; + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_RU_PRACH_RX, 1 ); + + /*if (ru->gNB_list[0]){ + prach_procedures( + ru->gNB_list[0] + #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,0 + #endif + ); + } + else { + rx_prach(NULL, + ru, + NULL, + NULL, + NULL, + proc->frame_prach, + 0 + #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,0 + #endif + ); + } + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_RU_PRACH_RX, 0 ); */ + if (release_thread(&proc->mutex_prach,&proc->instance_cnt_prach,"ru_prach_thread") < 0) break; + } + + LOG_I(PHY, "Exiting RU thread PRACH\n"); + ru_thread_prach_status = 0; + return &ru_thread_prach_status; +} + + +int wakeup_synch(RU_t *ru) { + struct timespec wait; + wait.tv_sec=0; + wait.tv_nsec=5000000L; + + // wake up synch thread + // lock the synch mutex and make sure the thread is ready + if (pthread_mutex_timedlock(&ru->proc.mutex_synch,&wait) != 0) { + LOG_E( PHY, "[RU] ERROR pthread_mutex_lock for RU synch thread (IC %d)\n", ru->proc.instance_cnt_synch ); + exit_fun( "error locking mutex_synch" ); + return(-1); + } + + ++ru->proc.instance_cnt_synch; + + // the thread can now be woken up + if (pthread_cond_signal(&ru->proc.cond_synch) != 0) { + LOG_E( PHY, "[RU] ERROR pthread_cond_signal for RU synch thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + return(-1); + } + + pthread_mutex_unlock( &ru->proc.mutex_synch ); + return(0); +} + +void do_ru_synch(RU_t *ru) { + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + RU_proc_t *proc = &ru->proc; + int i; + void *rxp[2],*rxp2[2]; + int32_t dummy_rx[ru->nb_rx][fp->samples_per_subframe] __attribute__((aligned(32))); + int rxs; + int ic; + + // initialize the synchronization buffer to the common_vars.rxdata + for (int i=0; inb_rx; i++) + rxp[i] = &ru->common.rxdata[i][0]; + + double temp_freq1 = ru->rfdevice.openair0_cfg->rx_freq[0]; + double temp_freq2 = ru->rfdevice.openair0_cfg->tx_freq[0]; + + for (i=0; i<4; i++) { + ru->rfdevice.openair0_cfg->rx_freq[i] = ru->rfdevice.openair0_cfg->tx_freq[i]; + ru->rfdevice.openair0_cfg->tx_freq[i] = temp_freq1; + } + + ru->rfdevice.trx_set_freq_func(&ru->rfdevice,ru->rfdevice.openair0_cfg,0); + + while ((ru->in_synch ==0)&&(!oai_exit)) { + // read in frame + rxs = ru->rfdevice.trx_read_func(&ru->rfdevice, + &(proc->timestamp_rx), + rxp, + fp->samples_per_subframe*10, + ru->nb_rx); + + if (rxs != fp->samples_per_subframe*10) LOG_E(PHY,"requested %d samples, got %d\n",fp->samples_per_subframe*10,rxs); + + // wakeup synchronization processing thread + wakeup_synch(ru); + ic=0; + + while ((ic>=0)&&(!oai_exit)) { + // continuously read in frames, 1ms at a time, + // until we are done with the synchronization procedure + for (i=0; inb_rx; i++) + rxp2[i] = (void *)&dummy_rx[i][0]; + + for (i=0; i<10; i++) + rxs = ru->rfdevice.trx_read_func(&ru->rfdevice, + &(proc->timestamp_rx), + rxp2, + fp->samples_per_subframe, + ru->nb_rx); + + pthread_mutex_lock(&ru->proc.mutex_synch); + ic = ru->proc.instance_cnt_synch; + pthread_mutex_unlock(&ru->proc.mutex_synch); + } // ic>=0 + } // in_synch==0 + + // read in rx_offset samples + LOG_I(PHY,"Resynchronizing by %d samples\n",ru->rx_offset); + rxs = ru->rfdevice.trx_read_func(&ru->rfdevice, + &(proc->timestamp_rx), + rxp, + ru->rx_offset, + ru->nb_rx); + + for (i=0; i<4; i++) { + ru->rfdevice.openair0_cfg->rx_freq[i] = temp_freq1; + ru->rfdevice.openair0_cfg->tx_freq[i] = temp_freq2; + } + + ru->rfdevice.trx_set_freq_func(&ru->rfdevice,ru->rfdevice.openair0_cfg,0); +} + + + +void wakeup_gNB_L1s(RU_t *ru) { + int i; + PHY_VARS_gNB **gNB_list = ru->gNB_list; + LOG_D(PHY,"wakeup_gNB_L1s (num %d) for RU %d ru->gNB_top:%p\n",ru->num_gNB,ru->idx, ru->gNB_top); + + if (ru->num_gNB==1 && ru->gNB_top!=0 && get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) { + // call gNB function directly + char string[20]; + sprintf(string,"Incoming RU %d",ru->idx); + LOG_D(PHY,"RU %d Call gNB_top\n",ru->idx); + ru->gNB_top(gNB_list[0],ru->proc.frame_rx,ru->proc.tti_rx,string,ru); + } else { + LOG_D(PHY,"ru->num_gNB:%d\n", ru->num_gNB); + + for (i=0; inum_gNB; i++) { + LOG_D(PHY,"ru->wakeup_rxtx:%p\n", ru->nr_wakeup_rxtx); + + if (ru->nr_wakeup_rxtx!=0 && ru->nr_wakeup_rxtx(gNB_list[i],ru) < 0) { + LOG_E(PHY,"could not wakeup gNB rxtx process for subframe %d\n", ru->proc.tti_rx); + } + } + } +} + +static inline int wakeup_prach_ru(RU_t *ru) { + struct timespec wait; + wait.tv_sec=0; + wait.tv_nsec=5000000L; + + if (pthread_mutex_timedlock(&ru->proc.mutex_prach,&wait) !=0) { + LOG_E( PHY, "[RU] ERROR pthread_mutex_lock for RU prach thread (IC %d)\n", ru->proc.instance_cnt_prach); + exit_fun( "error locking mutex_rxtx" ); + return(-1); + } + + if (ru->proc.instance_cnt_prach==-1) { + ++ru->proc.instance_cnt_prach; + ru->proc.frame_prach = ru->proc.frame_rx; + ru->proc.subframe_prach = ru->proc.tti_rx; + + // DJP - think prach_procedures() is looking at gNB frame_prach + if (ru->gNB_list[0]) { + ru->gNB_list[0]->proc.frame_prach = ru->proc.frame_rx; + ru->gNB_list[0]->proc.slot_prach = ru->proc.tti_rx; + } + + LOG_I(PHY,"RU %d: waking up PRACH thread\n",ru->idx); + // the thread can now be woken up + AssertFatal(pthread_cond_signal(&ru->proc.cond_prach) == 0, "ERROR pthread_cond_signal for RU prach thread\n"); + } else LOG_W(PHY,"RU prach thread busy, skipping\n"); + + pthread_mutex_unlock( &ru->proc.mutex_prach ); + return(0); +} + +// this is for RU with local RF unit +void fill_rf_config(RU_t *ru, char *rf_config_file) { + int i; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + nfapi_nr_config_request_t *gNB_config = &ru->gNB_list[0]->gNB_config; //tmp index + openair0_config_t *cfg = &ru->openair0_cfg; + int N_RB = gNB_config->rf_config.dl_carrier_bandwidth.value; + int mu = gNB_config->subframe_config.numerology_index_mu.value; + + if (mu == NR_MU_0) { //or if LTE + if(N_RB == 100) { + if (fp->threequarter_fs) { + cfg->sample_rate=23.04e6; + cfg->samples_per_frame = 230400; + cfg->tx_bw = 10e6; + cfg->rx_bw = 10e6; + } else { + cfg->sample_rate=30.72e6; + cfg->samples_per_frame = 307200; + cfg->tx_bw = 10e6; + cfg->rx_bw = 10e6; + } + } else if(N_RB == 50) { + cfg->sample_rate=15.36e6; + cfg->samples_per_frame = 153600; + cfg->tx_bw = 5e6; + cfg->rx_bw = 5e6; + } else if (N_RB == 25) { + cfg->sample_rate=7.68e6; + cfg->samples_per_frame = 76800; + cfg->tx_bw = 2.5e6; + cfg->rx_bw = 2.5e6; + } else if (N_RB == 6) { + cfg->sample_rate=1.92e6; + cfg->samples_per_frame = 19200; + cfg->tx_bw = 1.5e6; + cfg->rx_bw = 1.5e6; + } else AssertFatal(1==0,"Unknown N_RB %d\n",N_RB); + } else if (mu == NR_MU_1) { + if(N_RB == 217) { + if (fp->threequarter_fs) { + cfg->sample_rate=92.16e6; + cfg->samples_per_frame = 921600; + cfg->tx_bw = 40e6; + cfg->rx_bw = 40e6; + } else { + cfg->sample_rate=122.88e6; + cfg->samples_per_frame = 1228800; + cfg->tx_bw = 40e6; + cfg->rx_bw = 40e6; + } + } else if(N_RB == 106) { + cfg->sample_rate=61.44e6; + cfg->samples_per_frame = 614400; + cfg->tx_bw = 20e6; + cfg->rx_bw = 20e6; + } else { + AssertFatal(0==1,"N_RB %d not yet supported for numerology %d\n",N_RB,mu); + } + } else { + AssertFatal(0 == 1,"Numerology %d not supported for the moment\n",mu); + } + + if (gNB_config->subframe_config.duplex_mode.value==TDD) + cfg->duplex_mode = duplex_mode_TDD; + else //FDD + cfg->duplex_mode = duplex_mode_FDD; + + cfg->Mod_id = 0; + cfg->num_rb_dl=N_RB; + cfg->tx_num_channels=ru->nb_tx; + cfg->rx_num_channels=ru->nb_rx; + + for (i=0; inb_tx; i++) { + cfg->tx_freq[i] = (double)fp->dl_CarrierFreq; + cfg->rx_freq[i] = (double)fp->ul_CarrierFreq; + cfg->tx_gain[i] = ru->att_tx; + cfg->rx_gain[i] = ru->max_rxgain-ru->att_rx; + cfg->configFilename = rf_config_file; + printf("channel %d, Setting tx_gain offset %f, rx_gain offset %f, tx_freq %f, rx_freq %f\n", + i, cfg->tx_gain[i], + cfg->rx_gain[i], + cfg->tx_freq[i], + cfg->rx_freq[i]); + } +} + +/* this function maps the RU tx and rx buffers to the available rf chains. + Each rf chain is is addressed by the card number and the chain on the card. The + rf_map specifies for each antenna port, on which rf chain the mapping should start. Multiple + antennas are mapped to successive RF chains on the same card. */ +int setup_RU_buffers(RU_t *ru) { + int i,j; + int card,ant; + //uint16_t N_TA_offset = 0; + NR_DL_FRAME_PARMS *frame_parms; + //nfapi_nr_config_request_t *gNB_config = ru->gNB_list[0]->gNB_config; //tmp index + + if (ru) { + frame_parms = ru->nr_frame_parms; + printf("setup_RU_buffers: frame_parms = %p\n",frame_parms); + } else { + printf("RU[%d] not initialized\n", ru->idx); + return(-1); + } + + /* if (frame_parms->frame_type == TDD) { + if (frame_parms->N_RB_DL == 100) ru->N_TA_offset = 624; + else if (frame_parms->N_RB_DL == 50) ru->N_TA_offset = 624/2; + else if (frame_parms->N_RB_DL == 25) ru->N_TA_offset = 624/4; + } */ + if (ru->openair0_cfg.mmapped_dma == 1) { + // replace RX signal buffers with mmaped HW versions + for (i=0; inb_rx; i++) { + card = i/4; + ant = i%4; + printf("Mapping RU id %d, rx_ant %d, on card %d, chain %d\n",ru->idx,i,ru->rf_map.card+card, ru->rf_map.chain+ant); + free(ru->common.rxdata[i]); + ru->common.rxdata[i] = ru->openair0_cfg.rxbase[ru->rf_map.chain+ant]; + printf("rxdata[%d] @ %p\n",i,ru->common.rxdata[i]); + + for (j=0; j<16; j++) { + printf("rxbuffer %d: %x\n",j,ru->common.rxdata[i][j]); + ru->common.rxdata[i][j] = 16-j; + } + } + + for (i=0; inb_tx; i++) { + card = i/4; + ant = i%4; + printf("Mapping RU id %d, tx_ant %d, on card %d, chain %d\n",ru->idx,i,ru->rf_map.card+card, ru->rf_map.chain+ant); + free(ru->common.txdata[i]); + ru->common.txdata[i] = ru->openair0_cfg.txbase[ru->rf_map.chain+ant]; + printf("txdata[%d] @ %p\n",i,ru->common.txdata[i]); + + for (j=0; j<16; j++) { + printf("txbuffer %d: %x\n",j,ru->common.txdata[i][j]); + ru->common.txdata[i][j] = 16-j; + } + } + } else { // not memory-mapped DMA + //nothing to do, everything already allocated in lte_init + } + + return(0); +} + +static void *ru_stats_thread(void *param) { + RU_t *ru = (RU_t *)param; + wait_sync("ru_stats_thread"); + + while (!oai_exit) { + sleep(1); + + if (opp_enabled == 1) { + if (ru->feprx) print_meas(&ru->ofdm_demod_stats,"feprx",NULL,NULL); + + if (ru->feptx_ofdm) print_meas(&ru->ofdm_mod_stats,"feptx_ofdm",NULL,NULL); + + if (ru->fh_north_asynch_in) print_meas(&ru->rx_fhaul,"rx_fhaul",NULL,NULL); + + if (ru->fh_north_out) { + print_meas(&ru->tx_fhaul,"tx_fhaul",NULL,NULL); + print_meas(&ru->compression,"compression",NULL,NULL); + print_meas(&ru->transport,"transport",NULL,NULL); + } + } + } + + return(NULL); +} + +static void *ru_thread_tx( void *param ) { + RU_t *ru = (RU_t *)param; + RU_proc_t *proc = &ru->proc; + PHY_VARS_gNB *gNB; + gNB_L1_proc_t *gNB_proc; + gNB_L1_rxtx_proc_t *L1_proc; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + char filename[40]; + int print_frame = 8; + int i = 0; + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + thread_top_init("ru_thread_tx",1,400000,500000,500000); + //CPU_SET(5, &cpuset); + //pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + //wait_sync("ru_thread_tx"); + wait_on_condition(&proc->mutex_FH1,&proc->cond_FH1,&proc->instance_cnt_FH1,"ru_thread_tx"); + printf( "ru_thread_tx ready\n"); + + while (!oai_exit) { + if (oai_exit) break; + + LOG_I(PHY,"ru_thread_tx: Waiting for TX processing\n"); + // wait until eNBs are finished subframe RX n and TX n+4 + wait_on_condition(&proc->mutex_gNBs,&proc->cond_gNBs,&proc->instance_cnt_gNBs,"ru_thread_tx"); + + if (oai_exit) break; + + //printf("~~~~~~~~~~~~~~~~start process for ru_thread_tx %d.%d\n", proc->frame_tx, proc->tti_tx); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_FRAME_NUMBER_TX0_RU, proc->frame_tx ); + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TTI_NUMBER_TX0_RU, proc->tti_tx ); + + // do TX front-end processing if needed (precoding and/or IDFTs) + if (ru->feptx_prec) ru->feptx_prec(ru); + + // do OFDM if needed + if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru); + + if(!emulate_rf) { + // do outgoing fronthaul (south) if needed + if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru); + + if (ru->fh_north_out) ru->fh_north_out(ru); + } else { + if(proc->frame_tx == print_frame) { + for (i=0; inb_tx; i++) { + sprintf(filename,"tx%ddataF_frame%d_sl%d.m", i, print_frame, proc->tti_tx); + LOG_M(filename,"txdataF_frame",&ru->common.txdataF_BF[i][0],fp->samples_per_subframe_wCP, 1, 1); + + if(proc->tti_tx == 9) { + sprintf(filename,"tx%ddata_frame%d.m", i, print_frame); + LOG_M(filename,"txdata_frame",&ru->common.txdata[i][0],fp->samples_per_frame, 1, 1); + sprintf(filename,"tx%ddata_frame%d.dat", i, print_frame); + FILE *output_fd = fopen(filename,"w"); + + if (output_fd) { + fwrite(&ru->common.txdata[i][0], + sizeof(int32_t), + fp->samples_per_frame, + output_fd); + fclose(output_fd); + } else { + LOG_E(PHY,"Cannot write to file %s\n",filename); + } + }//if(proc->tti_tx == 9) + }//for (i=0; inb_tx; i++) + }//if(proc->frame_tx == print_frame) + }//else emulate_rf + + release_thread(&proc->mutex_gNBs,&proc->instance_cnt_gNBs,"ru_thread_tx"); + + for(i = 0; inum_gNB; i++) { + gNB = ru->gNB_list[i]; + gNB_proc = &gNB->proc; + L1_proc = (get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT)? &gNB_proc->L1_proc_tx : &gNB_proc->L1_proc; + pthread_mutex_lock(&gNB_proc->mutex_RU_tx); + + for (int j=0; jnum_RU; j++) { + if (ru == gNB->RU_list[j]) { + if ((gNB_proc->RU_mask_tx&(1< 0) + LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU tx %d (num_RU %d,mask %x) has not been served yet!\n", + gNB->Mod_id,gNB_proc->frame_rx,gNB_proc->slot_rx,ru->idx,gNB->num_RU,gNB_proc->RU_mask_tx); + + gNB_proc->RU_mask_tx |= (1<RU_mask_tx != (1<num_RU)-1) { // not all RUs have provided their information so return + pthread_mutex_unlock(&gNB_proc->mutex_RU_tx); + } else { // all RUs TX are finished so send the ready signal to eNB processing + gNB_proc->RU_mask_tx = 0; + pthread_mutex_unlock(&gNB_proc->mutex_RU_tx); + pthread_mutex_lock( &L1_proc->mutex_RUs); + L1_proc->instance_cnt_RUs = 0; + + // the thread can now be woken up + if (pthread_cond_signal(&L1_proc->cond_RUs) != 0) { + LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n"); + exit_fun( "ERROR pthread_cond_signal" ); + } + + pthread_mutex_unlock( &L1_proc->mutex_RUs ); + } + } + } + + release_thread(&proc->mutex_FH1,&proc->instance_cnt_FH1,"ru_thread_tx"); + return 0; +} + +static void *ru_thread( void *param ) { + static int ru_thread_status; + RU_t *ru = (RU_t *)param; + RU_proc_t *proc = &ru->proc; + NR_DL_FRAME_PARMS *fp = ru->nr_frame_parms; + int ret; + int slot = fp->slots_per_frame-1; + int frame =1023; + char filename[40],threadname[40]; + int print_frame = 8; + int i = 0; + // set default return value + ru_thread_status = 0; + // set default return value + sprintf(threadname,"ru_thread %d",ru->idx); + thread_top_init(threadname,0,870000,1000000,1000000); + LOG_I(PHY,"Starting RU %d (%s,%s),\n",ru->idx,NB_functions[ru->function],NB_timing[ru->if_timing]); + + if(emulate_rf) { + fill_rf_config(ru,ru->rf_config_file); + nr_init_frame_parms(&ru->gNB_list[0]->gNB_config, fp); + nr_dump_frame_parms(fp); + nr_phy_init_RU(ru); + + if (setup_RU_buffers(ru)!=0) { + printf("Exiting, cannot initialize RU Buffers\n"); + exit(-1); + } + } else { + // Start IF device if any + if (ru->start_if) { + LOG_I(PHY,"Starting IF interface for RU %d\n",ru->idx); + AssertFatal(ru->start_if(ru,NULL) == 0, "Could not start the IF device\n"); + + if (ru->if_south == LOCAL_RF) ret = connect_rau(ru); + else ret = attach_rru(ru); + + AssertFatal(ret==0,"Cannot connect to remote radio\n"); + } + + if (ru->if_south == LOCAL_RF) { // configure RF parameters only + fill_rf_config(ru,ru->rf_config_file); + nr_init_frame_parms(&ru->gNB_list[0]->gNB_config, fp); + nr_dump_frame_parms(fp); + nr_phy_init_RU(ru); + ret = openair0_device_load(&ru->rfdevice,&ru->openair0_cfg); + AssertFatal(ret==0,"Cannot connect to local radio\n"); + } + + if (setup_RU_buffers(ru)!=0) { + printf("Exiting, cannot initialize RU Buffers\n"); + exit(-1); + } + } + + LOG_I(PHY, "Signaling main thread that RU %d is ready\n",ru->idx); + pthread_mutex_lock(&RC.ru_mutex); + RC.ru_mask &= ~(1<idx); + pthread_cond_signal(&RC.ru_cond); + pthread_mutex_unlock(&RC.ru_mutex); + wait_sync("ru_thread"); + + if(!emulate_rf) { + // Start RF device if any + if (ru->start_rf) { + if (ru->start_rf(ru) != 0) + LOG_E(HW,"Could not start the RF device\n"); + else LOG_I(PHY,"RU %d rf device ready\n",ru->idx); + } else LOG_I(PHY,"RU %d no rf device\n",ru->idx); + + // if an asnych_rxtx thread exists + // wakeup the thread because the devices are ready at this point + + if ((ru->fh_south_asynch_in)||(ru->fh_north_asynch_in)) { + pthread_mutex_lock(&proc->mutex_asynch_rxtx); + proc->instance_cnt_asynch_rxtx=0; + pthread_mutex_unlock(&proc->mutex_asynch_rxtx); + pthread_cond_signal(&proc->cond_asynch_rxtx); + } else LOG_I(PHY,"RU %d no asynch_south interface\n",ru->idx); + + // if this is a slave RRU, try to synchronize on the DL frequency + if ((ru->is_slave) && (ru->if_south == LOCAL_RF)) do_ru_synch(ru); + } + + pthread_mutex_lock(&proc->mutex_FH1); + proc->instance_cnt_FH1 = 0; + pthread_mutex_unlock(&proc->mutex_FH1); + pthread_cond_signal(&proc->cond_FH1); + + // This is a forever while loop, it loops over subframes which are scheduled by incoming samples from HW devices + while (!oai_exit) { + // these are local subframe/frame counters to check that we are in synch with the fronthaul timing. + // They are set on the first rx/tx in the underly FH routines. + if (slot==(fp->slots_per_frame-1)) { + slot=0; + frame++; + frame&=1023; + } else { + slot++; + } + + // synchronization on input FH interface, acquire signals/data and block + if (ru->fh_south_in) ru->fh_south_in(ru,&frame,&slot); + else AssertFatal(1==0, "No fronthaul interface at south port"); + + LOG_D(PHY,"AFTER fh_south_in - SFN/SL:%d%d RU->proc[RX:%d.%d TX:%d.%d] RC.gNB[0][0]:[RX:%d%d TX(SFN):%d]\n", + frame,slot, + proc->frame_rx,proc->tti_rx, + proc->frame_tx,proc->tti_tx, + RC.gNB[0][0]->proc.frame_rx,RC.gNB[0][0]->proc.slot_rx, + RC.gNB[0][0]->proc.frame_tx); + /* + LOG_D(PHY,"RU thread (do_prach %d, is_prach_subframe %d), received frame %d, subframe %d\n", + ru->do_prach, + is_prach_subframe(fp, proc->frame_rx, proc->tti_rx), + proc->frame_rx,proc->tti_rx); + + if ((ru->do_prach>0) && (is_prach_subframe(fp, proc->frame_rx, proc->tti_rx)==1)) { + wakeup_prach_ru(ru); + }*/ + + // adjust for timing offset between RU + //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~%d.%d in ru_thread is in process\n", proc->frame_rx, proc->tti_rx); + if (ru->idx!=0) proc->frame_tx = (proc->frame_tx+proc->frame_offset)&1023; + + // do RX front-end processing (frequency-shift, dft) if needed + if (ru->feprx) ru->feprx(ru); + + // At this point, all information for subframe has been received on FH interface + + // wakeup all gNB processes waiting for this RU + if (ru->num_gNB>0) wakeup_gNB_L1s(ru); + + if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD && ru->num_eNB==0) { + // do TX front-end processing if needed (precoding and/or IDFTs) + if (ru->feptx_prec) ru->feptx_prec(ru); + + // do OFDM if needed + if ((ru->fh_north_asynch_in == NULL) && (ru->feptx_ofdm)) ru->feptx_ofdm(ru); + + if(!emulate_rf) { + // do outgoing fronthaul (south) if needed + if ((ru->fh_north_asynch_in == NULL) && (ru->fh_south_out)) ru->fh_south_out(ru); + + if (ru->fh_north_out) ru->fh_north_out(ru); + } else { + if(proc->frame_tx == print_frame) { + for (i=0; inb_tx; i++) { + sprintf(filename,"tx%ddataF_frame%d_sl%d.m", i, print_frame, proc->tti_tx); + LOG_M(filename,"txdataF_frame",&ru->common.txdataF_BF[i][0],fp->samples_per_slot_wCP, 1, 1); + + if(proc->tti_tx == 9) { + sprintf(filename,"tx%ddata_frame%d.m", i, print_frame); + LOG_M(filename,"txdata_frame",&ru->common.txdata[i][0],fp->samples_per_frame, 1, 1); + sprintf(filename,"tx%ddata_frame%d.dat", i, print_frame); + FILE *output_fd = fopen(filename,"w"); + + if (output_fd) { + fwrite(&ru->common.txdata[i][0], + sizeof(int32_t), + fp->samples_per_frame, + output_fd); + fclose(output_fd); + } else { + LOG_E(PHY,"Cannot write to file %s\n",filename); + } + }//if(proc->tti_tx == 9) + }//for (i=0; inb_tx; i++) + }//if(proc->frame_tx == print_frame) + }//else emulate_rf + + proc->emulate_rf_busy = 0; + }//if(get_thread_parallel_conf() == PARALLEL_SINGLE_THREAD) + } + + printf( "Exiting ru_thread \n"); + + if (ru->stop_rf != NULL) { + if (ru->stop_rf(ru) != 0) + LOG_E(HW,"Could not stop the RF device\n"); + else LOG_I(PHY,"RU %d rf device stopped\n",ru->idx); + } + + ru_thread_status = 0; + return &ru_thread_status; +} +/* +// This thread run the initial synchronization like a UE +void *ru_thread_synch(void *arg) { + + RU_t *ru = (RU_t*)arg; + NR_DL_FRAME_PARMS *fp=ru->nr_frame_parms; + int32_t sync_pos,sync_pos2; + uint32_t peak_val; + uint32_t sync_corr[307200] __attribute__((aligned(32))); + static int ru_thread_synch_status; + + + thread_top_init("ru_thread_synch",0,5000000,10000000,10000000); + + wait_sync("ru_thread_synch"); + + // initialize variables for PSS detection + lte_sync_time_init(ru->nr_frame_parms); + + while (!oai_exit) { + + // wait to be woken up + if (wait_on_condition(&ru->proc.mutex_synch,&ru->proc.cond_synch,&ru->proc.instance_cnt_synch,"ru_thread_synch")<0) break; + + // if we're not in synch, then run initial synch + if (ru->in_synch == 0) { + // run intial synch like UE + LOG_I(PHY,"Running initial synchronization\n"); + + sync_pos = lte_sync_time_gNB(ru->common.rxdata, + fp, + fp->samples_per_subframe*5, + &peak_val, + sync_corr); + LOG_I(PHY,"RU synch: %d, val %d\n",sync_pos,peak_val); + + if (sync_pos >= 0) { + if (sync_pos >= fp->nb_prefix_samples) + sync_pos2 = sync_pos - fp->nb_prefix_samples; + else + sync_pos2 = sync_pos + (fp->samples_per_subframe*10) - fp->nb_prefix_samples; + + if (fp->frame_type == FDD) { + + // PSS is hypothesized in last symbol of first slot in Frame + int sync_pos_slot = (fp->samples_per_subframe>>1) - fp->ofdm_symbol_size - fp->nb_prefix_samples; + + if (sync_pos2 >= sync_pos_slot) + ru->rx_offset = sync_pos2 - sync_pos_slot; + else + ru->rx_offset = (fp->samples_per_subframe*10) + sync_pos2 - sync_pos_slot; + } + else { + + } + + LOG_I(PHY,"Estimated sync_pos %d, peak_val %d => timing offset %d\n",sync_pos,peak_val,ru->rx_offset); + + if ((peak_val > 300000) && (sync_pos > 0)) { + // if (sync_pos++ > 3) { + write_output("ru_sync.m","sync",(void*)&sync_corr[0],fp->samples_per_subframe*5,1,2); + write_output("ru_rx.m","rxs",(void*)ru->ru_time.rxdata[0][0],fp->samples_per_subframe*10,1,1); + exit(-1); + } + + ru->in_synch=1; + } + } + + if (release_thread(&ru->proc.mutex_synch,&ru->proc.instance_cnt_synch,"ru_synch_thread") < 0) break; + } // oai_exit + + ru_thread_synch_status = 0; + return &ru_thread_synch_status; + +} +*/ + +int start_if(struct RU_t_s *ru,struct PHY_VARS_gNB_s *gNB) { + return(ru->ifdevice.trx_start_func(&ru->ifdevice)); +} + +int start_rf(RU_t *ru) { + return(ru->rfdevice.trx_start_func(&ru->rfdevice)); +} + +int stop_rf(RU_t *ru) { + ru->rfdevice.trx_end_func(&ru->rfdevice); + return 0; +} + +extern void fep_full(RU_t *ru); +extern void ru_fep_full_2thread(RU_t *ru); +extern void nr_feptx_ofdm(RU_t *ru); +extern void nr_feptx_ofdm_2thread(RU_t *ru); +extern void feptx_prec(RU_t *ru); +extern void init_fep_thread(RU_t *ru,pthread_attr_t *attr); +extern void init_nr_feptx_thread(RU_t *ru,pthread_attr_t *attr); + +void init_RU_proc(RU_t *ru) { + int i=0; + RU_proc_t *proc; + pthread_attr_t *attr_FH=NULL, *attr_FH1=NULL,*attr_prach=NULL,*attr_asynch=NULL, *attr_emulateRF=NULL;// *attr_synch=NULL; + //pthread_attr_t *attr_fep=NULL; +#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + //pthread_attr_t *attr_prach_br=NULL; +#endif + char name[100]; +#ifndef OCP_FRAMEWORK + LOG_I(PHY,"Initializing RU proc %d (%s,%s),\n",ru->idx,NB_functions[ru->function],NB_timing[ru->if_timing]); +#endif + proc = &ru->proc; + memset((void *)proc,0,sizeof(RU_proc_t)); + proc->ru = ru; + proc->instance_cnt_prach = -1; + proc->instance_cnt_synch = -1; ; + proc->instance_cnt_FH = -1; + proc->instance_cnt_FH1 = -1; + proc->instance_cnt_gNBs = -1; + proc->instance_cnt_asynch_rxtx = -1; + proc->instance_cnt_emulateRF = -1; + proc->first_rx = 1; + proc->first_tx = 1; + proc->frame_offset = 0; + proc->num_slaves = 0; + proc->frame_tx_unwrap = 0; + + for (i=0; i<10; i++) proc->symbol_mask[i]=0; + + pthread_mutex_init( &proc->mutex_prach, NULL); + pthread_mutex_init( &proc->mutex_asynch_rxtx, NULL); + pthread_mutex_init( &proc->mutex_synch,NULL); + pthread_mutex_init( &proc->mutex_FH,NULL); + pthread_mutex_init( &proc->mutex_FH1,NULL); + pthread_mutex_init( &proc->mutex_emulateRF,NULL); + pthread_mutex_init( &proc->mutex_gNBs, NULL); + pthread_cond_init( &proc->cond_prach, NULL); + pthread_cond_init( &proc->cond_FH, NULL); + pthread_cond_init( &proc->cond_FH1, NULL); + pthread_cond_init( &proc->cond_emulateRF, NULL); + pthread_cond_init( &proc->cond_asynch_rxtx, NULL); + pthread_cond_init( &proc->cond_synch,NULL); + pthread_cond_init( &proc->cond_gNBs, NULL); + pthread_attr_init( &proc->attr_FH); + pthread_attr_init( &proc->attr_FH1); + pthread_attr_init( &proc->attr_emulateRF); + pthread_attr_init( &proc->attr_prach); + pthread_attr_init( &proc->attr_synch); + pthread_attr_init( &proc->attr_asynch_rxtx); + pthread_attr_init( &proc->attr_fep); +#ifndef DEADLINE_SCHEDULER + attr_FH = &proc->attr_FH; + attr_FH1 = &proc->attr_FH1; + attr_emulateRF = &proc->attr_emulateRF; + attr_prach = &proc->attr_prach; + //attr_synch = &proc->attr_synch; + attr_asynch = &proc->attr_asynch_rxtx; +#endif + threadCreate( &proc->pthread_FH, ru_thread, (void *)ru, "thread_FH", -1, OAI_PRIORITY_RT ); + + if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) + threadCreate( &proc->pthread_FH1, ru_thread_tx, (void *)ru, "thread_FH1", -1, OAI_PRIORITY_RT ); + + if(emulate_rf) + threadCreate( &proc->pthread_emulateRF, emulatedRF_thread, (void *)proc, "emulateRF", -1, OAI_PRIORITY_RT ); + + if (ru->function == NGFI_RRU_IF4p5) { + threadCreate( &proc->pthread_prach, ru_thread_prach, (void *)ru, "RACH", -1, OAI_PRIORITY_RT ); + ///tmp deactivation of synch thread + // if (ru->is_slave == 1) pthread_create( &proc->pthread_synch, attr_synch, ru_thread_synch, (void*)ru); + + if ((ru->if_timing == synch_to_other) || + (ru->function == NGFI_RRU_IF5) || + (ru->function == NGFI_RRU_IF4p5)) threadCreate( &proc->pthread_asynch_rxtx, ru_thread_asynch_rxtx, (void *)ru, "asynch_rxtx", -1, OAI_PRIORITY_RT ); + + snprintf( name, sizeof(name), "ru_thread_FH %d", ru->idx ); + pthread_setname_np( proc->pthread_FH, name ); + } else if (ru->function == gNodeB_3GPP && ru->if_south == LOCAL_RF) { // DJP - need something else to distinguish between monolithic and PNF + LOG_I(PHY,"%s() DJP - added creation of pthread_prach\n", __FUNCTION__); + threadCreate( &proc->pthread_prach, ru_thread_prach, (void *)ru,"RACH", -1, OAI_PRIORITY_RT ); + } + + if (get_nprocs()>=2) { + if (ru->feprx) init_fep_thread(ru,NULL); + + if (ru->feptx_ofdm) nr_init_feptx_thread(ru,NULL); + } + + if (opp_enabled == 1) threadCreate(&ru->ru_stats_thread,ru_stats_thread,(void *)ru, "emulateRF", -1, OAI_PRIORITY_RT_LOW); +} + +void kill_RU_proc(int inst) { + RU_t *ru = RC.ru[inst]; + RU_proc_t *proc = &ru->proc; + pthread_mutex_lock(&proc->mutex_FH); + proc->instance_cnt_FH = 0; + pthread_mutex_unlock(&proc->mutex_FH); + pthread_cond_signal(&proc->cond_FH); + pthread_mutex_lock(&proc->mutex_prach); + proc->instance_cnt_prach = 0; + pthread_mutex_unlock(&proc->mutex_prach); + pthread_cond_signal(&proc->cond_prach); + pthread_mutex_lock(&proc->mutex_synch); + proc->instance_cnt_synch = 0; + pthread_mutex_unlock(&proc->mutex_synch); + pthread_cond_signal(&proc->cond_synch); + pthread_mutex_lock(&proc->mutex_gNBs); + proc->instance_cnt_gNBs = 0; + pthread_mutex_unlock(&proc->mutex_gNBs); + pthread_cond_signal(&proc->cond_gNBs); + pthread_mutex_lock(&proc->mutex_asynch_rxtx); + proc->instance_cnt_asynch_rxtx = 0; + pthread_mutex_unlock(&proc->mutex_asynch_rxtx); + pthread_cond_signal(&proc->cond_asynch_rxtx); + LOG_D(PHY, "Joining pthread_FH\n"); + pthread_join(proc->pthread_FH, NULL); + + if (ru->function == NGFI_RRU_IF4p5) { + LOG_D(PHY, "Joining pthread_prach\n"); + pthread_join(proc->pthread_prach, NULL); + + if (ru->is_slave) { + LOG_D(PHY, "Joining pthread_\n"); + pthread_join(proc->pthread_synch, NULL); + } + + if ((ru->if_timing == synch_to_other) || + (ru->function == NGFI_RRU_IF5) || + (ru->function == NGFI_RRU_IF4p5)) { + LOG_D(PHY, "Joining pthread_asynch_rxtx\n"); + pthread_join(proc->pthread_asynch_rxtx, NULL); + } + } + + if (get_nprocs() >= 2) { + if (ru->feprx) { + pthread_mutex_lock(&proc->mutex_fep); + proc->instance_cnt_fep = 0; + pthread_mutex_unlock(&proc->mutex_fep); + pthread_cond_signal(&proc->cond_fep); + LOG_D(PHY, "Joining pthread_fep\n"); + pthread_join(proc->pthread_fep, NULL); + pthread_mutex_destroy(&proc->mutex_fep); + pthread_cond_destroy(&proc->cond_fep); + } + + if (ru->feptx_ofdm) { + pthread_mutex_lock(&proc->mutex_feptx); + proc->instance_cnt_feptx = 0; + pthread_mutex_unlock(&proc->mutex_feptx); + pthread_cond_signal(&proc->cond_feptx); + LOG_D(PHY, "Joining pthread_feptx\n"); + pthread_join(proc->pthread_feptx, NULL); + pthread_mutex_destroy(&proc->mutex_feptx); + pthread_cond_destroy(&proc->cond_feptx); + } + } + + if (opp_enabled) { + LOG_D(PHY, "Joining ru_stats_thread\n"); + pthread_join(ru->ru_stats_thread, NULL); + } + + pthread_mutex_destroy(&proc->mutex_prach); + pthread_mutex_destroy(&proc->mutex_asynch_rxtx); + pthread_mutex_destroy(&proc->mutex_synch); + pthread_mutex_destroy(&proc->mutex_FH); + pthread_mutex_destroy(&proc->mutex_gNBs); + pthread_cond_destroy(&proc->cond_prach); + pthread_cond_destroy(&proc->cond_FH); + pthread_cond_destroy(&proc->cond_asynch_rxtx); + pthread_cond_destroy(&proc->cond_synch); + pthread_cond_destroy(&proc->cond_gNBs); + pthread_attr_destroy(&proc->attr_FH); + pthread_attr_destroy(&proc->attr_prach); + pthread_attr_destroy(&proc->attr_synch); + pthread_attr_destroy(&proc->attr_asynch_rxtx); + pthread_attr_destroy(&proc->attr_fep); +} + +int check_capabilities(RU_t *ru,RRU_capabilities_t *cap) { + FH_fmt_options_t fmt = cap->FH_fmt; + int i; + int found_band=0; + LOG_I(PHY,"RRU %d, num_bands %d, looking for band %d\n",ru->idx,cap->num_bands,ru->nr_frame_parms->eutra_band); + + for (i=0; inum_bands; i++) { + LOG_I(PHY,"band %d on RRU %d\n",cap->band_list[i],ru->idx); + + if (ru->nr_frame_parms->eutra_band == cap->band_list[i]) { + found_band=1; + break; + } + } + + if (found_band == 0) { + LOG_I(PHY,"Couldn't find target EUTRA band %d on RRU %d\n",ru->nr_frame_parms->eutra_band,ru->idx); + return(-1); + } + + switch (ru->if_south) { + case LOCAL_RF: + AssertFatal(1==0, "This RU should not have a local RF, exiting\n"); + return(0); + break; + + case REMOTE_IF5: + if (fmt == OAI_IF5_only || fmt == OAI_IF5_and_IF4p5) return(0); + + break; + + case REMOTE_IF4p5: + if (fmt == OAI_IF4p5_only || fmt == OAI_IF5_and_IF4p5) return(0); + + break; + + case REMOTE_MBP_IF5: + if (fmt == MBP_IF5) return(0); + + break; + + default: + LOG_I(PHY,"No compatible Fronthaul interface found for RRU %d\n", ru->idx); + return(-1); + } + + return(-1); +} + + +char rru_format_options[4][20] = {"OAI_IF5_only","OAI_IF4p5_only","OAI_IF5_and_IF4p5","MBP_IF5"}; + +char rru_formats[3][20] = {"OAI_IF5","MBP_IF5","OAI_IF4p5"}; +char ru_if_formats[4][20] = {"LOCAL_RF","REMOTE_OAI_IF5","REMOTE_MBP_IF5","REMOTE_OAI_IF4p5"}; + +void configure_ru(int idx, + void *arg) { + RU_t *ru = RC.ru[idx]; + RRU_config_t *config = (RRU_config_t *)arg; + RRU_capabilities_t *capabilities = (RRU_capabilities_t *)arg; + nfapi_nr_config_request_t *gNB_config = &ru->gNB_list[0]->gNB_config; + int ret; + LOG_I(PHY, "Received capabilities from RRU %d\n",idx); + + if (capabilities->FH_fmt < MAX_FH_FMTs) LOG_I(PHY, "RU FH options %s\n",rru_format_options[capabilities->FH_fmt]); + + AssertFatal((ret=check_capabilities(ru,capabilities)) == 0, + "Cannot configure RRU %d, check_capabilities returned %d\n", idx,ret); + // take antenna capabilities of RRU + ru->nb_tx = capabilities->nb_tx[0]; + ru->nb_rx = capabilities->nb_rx[0]; + // Pass configuration to RRU + LOG_I(PHY, "Using %s fronthaul (%d), band %d \n",ru_if_formats[ru->if_south],ru->if_south,ru->nr_frame_parms->eutra_band); + // wait for configuration + config->FH_fmt = ru->if_south; + config->num_bands = 1; + config->band_list[0] = ru->nr_frame_parms->eutra_band; + config->tx_freq[0] = ru->nr_frame_parms->dl_CarrierFreq; + config->rx_freq[0] = ru->nr_frame_parms->ul_CarrierFreq; + //config->tdd_config[0] = ru->nr_frame_parms->tdd_config; + //config->tdd_config_S[0] = ru->nr_frame_parms->tdd_config_S; + config->att_tx[0] = ru->att_tx; + config->att_rx[0] = ru->att_rx; + config->N_RB_DL[0] = gNB_config->rf_config.dl_carrier_bandwidth.value; + config->N_RB_UL[0] = gNB_config->rf_config.ul_carrier_bandwidth.value; + config->threequarter_fs[0] = ru->nr_frame_parms->threequarter_fs; + /* if (ru->if_south==REMOTE_IF4p5) { + config->prach_FreqOffset[0] = ru->nr_frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset; + config->prach_ConfigIndex[0] = ru->nr_frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex; + LOG_I(PHY,"REMOTE_IF4p5: prach_FrequOffset %d, prach_ConfigIndex %d\n", + config->prach_FreqOffset[0],config->prach_ConfigIndex[0]);*/ + nr_init_frame_parms(&ru->gNB_list[0]->gNB_config, ru->nr_frame_parms); + nr_phy_init_RU(ru); +} + +void configure_rru(int idx, + void *arg) { + RRU_config_t *config = (RRU_config_t *)arg; + RU_t *ru = RC.ru[idx]; + nfapi_nr_config_request_t *gNB_config = &ru->gNB_list[0]->gNB_config; + ru->nr_frame_parms->eutra_band = config->band_list[0]; + ru->nr_frame_parms->dl_CarrierFreq = config->tx_freq[0]; + ru->nr_frame_parms->ul_CarrierFreq = config->rx_freq[0]; + + if (ru->nr_frame_parms->dl_CarrierFreq == ru->nr_frame_parms->ul_CarrierFreq) { + gNB_config->subframe_config.duplex_mode.value = TDD; + //ru->nr_frame_parms->tdd_config = config->tdd_config[0]; + //ru->nr_frame_parms->tdd_config_S = config->tdd_config_S[0]; + } else + gNB_config->subframe_config.duplex_mode.value = FDD; + + ru->att_tx = config->att_tx[0]; + ru->att_rx = config->att_rx[0]; + gNB_config->rf_config.dl_carrier_bandwidth.value = config->N_RB_DL[0]; + gNB_config->rf_config.ul_carrier_bandwidth.value = config->N_RB_UL[0]; + ru->nr_frame_parms->threequarter_fs = config->threequarter_fs[0]; + + //ru->nr_frame_parms->pdsch_config_common.referenceSignalPower = ru->max_pdschReferenceSignalPower-config->att_tx[0]; + if (ru->function==NGFI_RRU_IF4p5) { + ru->nr_frame_parms->att_rx = ru->att_rx; + ru->nr_frame_parms->att_tx = ru->att_tx; + /* + LOG_I(PHY,"Setting ru->function to NGFI_RRU_IF4p5, prach_FrequOffset %d, prach_ConfigIndex %d, att (%d,%d)\n", + config->prach_FreqOffset[0],config->prach_ConfigIndex[0],ru->att_tx,ru->att_rx); + ru->nr_frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset = config->prach_FreqOffset[0]; + ru->nr_frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex = config->prach_ConfigIndex[0]; */ + } + + fill_rf_config(ru,ru->rf_config_file); + nr_init_frame_parms(&ru->gNB_list[0]->gNB_config, ru->nr_frame_parms); + nr_phy_init_RU(ru); +} + +/* +void init_precoding_weights(PHY_VARS_gNB *gNB) { + + int layer,ru_id,aa,re,ue,tb; + LTE_DL_FRAME_PARMS *fp=&gNB->frame_parms; + RU_t *ru; + LTE_gNB_DLSCH_t *dlsch; + + // init precoding weigths + for (ue=0;uedlsch[ue][tb]; + for (layer=0; layer<4; layer++) { + int nb_tx=0; + for (ru_id=0;ru_idnb_tx; + } + dlsch->ue_spec_bf_weights[layer] = (int32_t**)malloc16(nb_tx*sizeof(int32_t*)); + + for (aa=0; aaue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(fp->ofdm_symbol_size*sizeof(int32_t)); + for (re=0;reofdm_symbol_size; re++) { + dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff; + } + } + } + } + } +}*/ + +void set_function_spec_param(RU_t *ru) { + int ret; + + switch (ru->if_south) { + case LOCAL_RF: // this is an RU with integrated RF (RRU, gNB) + if (ru->function == NGFI_RRU_IF5) { // IF5 RRU + ru->do_prach = 0; // no prach processing in RU + ru->fh_north_in = NULL; // no shynchronous incoming fronthaul from north + ru->fh_north_out = fh_if5_north_out; // need only to do send_IF5 reception + ru->fh_south_out = tx_rf; // send output to RF + ru->fh_north_asynch_in = fh_if5_north_asynch_in; // TX packets come asynchronously + ru->feprx = NULL; // nothing (this is a time-domain signal) + ru->feptx_ofdm = NULL; // nothing (this is a time-domain signal) + ru->feptx_prec = NULL; // nothing (this is a time-domain signal) + ru->start_if = start_if; // need to start the if interface for if5 + ru->ifdevice.host_type = RRU_HOST; + ru->rfdevice.host_type = RRU_HOST; + ru->ifdevice.eth_params = &ru->eth_params; + reset_meas(&ru->rx_fhaul); + reset_meas(&ru->tx_fhaul); + reset_meas(&ru->compression); + reset_meas(&ru->transport); + ret = openair0_transport_load(&ru->ifdevice,&ru->openair0_cfg,&ru->eth_params); + printf("openair0_transport_init returns %d for ru_id %d\n", ret, ru->idx); + + if (ret<0) { + printf("Exiting, cannot initialize transport protocol\n"); + exit(-1); + } + } else if (ru->function == NGFI_RRU_IF4p5) { + ru->do_prach = 1; // do part of prach processing in RU + ru->fh_north_in = NULL; // no synchronous incoming fronthaul from north + ru->fh_north_out = fh_if4p5_north_out; // send_IF4p5 on reception + ru->fh_south_out = tx_rf; // send output to RF + ru->fh_north_asynch_in = fh_if4p5_north_asynch_in; // TX packets come asynchronously + ru->feprx = (get_nprocs()<=2) ? fep_full :ru_fep_full_2thread; // RX DFTs + ru->feptx_ofdm = (get_nprocs()<=2) ? nr_feptx_ofdm : nr_feptx_ofdm_2thread; // this is fep with idft only (no precoding in RRU) + ru->feptx_prec = NULL; + ru->start_if = start_if; // need to start the if interface for if4p5 + ru->ifdevice.host_type = RRU_HOST; + ru->rfdevice.host_type = RRU_HOST; + ru->ifdevice.eth_params = &ru->eth_params; + reset_meas(&ru->rx_fhaul); + reset_meas(&ru->tx_fhaul); + reset_meas(&ru->compression); + reset_meas(&ru->transport); + ret = openair0_transport_load(&ru->ifdevice,&ru->openair0_cfg,&ru->eth_params); + printf("openair0_transport_init returns %d for ru_id %d\n", ret, ru->idx); + + if (ret<0) { + printf("Exiting, cannot initialize transport protocol\n"); + exit(-1); + } + + malloc_IF4p5_buffer(ru); + } else if (ru->function == gNodeB_3GPP) { + ru->do_prach = 0; // no prach processing in RU + ru->feprx = (get_nprocs()<=2) ? fep_full : ru_fep_full_2thread; // RX DFTs + ru->feptx_ofdm = (get_nprocs()<=2) ? nr_feptx_ofdm : nr_feptx_ofdm_2thread; // this is fep with idft and precoding + ru->feptx_prec = feptx_prec; // this is fep with idft and precoding + ru->fh_north_in = NULL; // no incoming fronthaul from north + ru->fh_north_out = NULL; // no outgoing fronthaul to north + ru->start_if = NULL; // no if interface + ru->rfdevice.host_type = RAU_HOST; + } + + ru->fh_south_in = rx_rf; // local synchronous RF RX + ru->fh_south_out = tx_rf; // local synchronous RF TX + ru->start_rf = start_rf; // need to start the local RF interface + ru->stop_rf = stop_rf; + printf("configuring ru_id %d (start_rf %p)\n", ru->idx, start_rf); + /* + if (ru->function == gNodeB_3GPP) { // configure RF parameters only for 3GPP eNodeB, we need to get them from RAU otherwise + fill_rf_config(ru,rf_config_file); + init_frame_parms(&ru->frame_parms,1); + nr_phy_init_RU(ru); + } + + ret = openair0_device_load(&ru->rfdevice,&ru->openair0_cfg); + if (setup_RU_buffers(ru)!=0) { + printf("Exiting, cannot initialize RU Buffers\n"); + exit(-1); + }*/ + break; + + case REMOTE_IF5: // the remote unit is IF5 RRU + ru->do_prach = 0; + ru->feprx = (get_nprocs()<=2) ? fep_full : fep_full; // this is frequency-shift + DFTs + ru->feptx_prec = feptx_prec; // need to do transmit Precoding + IDFTs + ru->feptx_ofdm = (get_nprocs()<=2) ? nr_feptx_ofdm : nr_feptx_ofdm_2thread; // need to do transmit Precoding + IDFTs + ru->fh_south_in = fh_if5_south_in; // synchronous IF5 reception + ru->fh_south_out = fh_if5_south_out; // synchronous IF5 transmission + ru->fh_south_asynch_in = NULL; // no asynchronous UL + ru->start_rf = NULL; // no local RF + ru->stop_rf = NULL; + ru->start_if = start_if; // need to start if interface for IF5 + ru->ifdevice.host_type = RAU_HOST; + ru->ifdevice.eth_params = &ru->eth_params; + ru->ifdevice.configure_rru = configure_ru; + ret = openair0_transport_load(&ru->ifdevice,&ru->openair0_cfg,&ru->eth_params); + printf("openair0_transport_init returns %d for ru_id %d\n", ret, ru->idx); + + if (ret<0) { + printf("Exiting, cannot initialize transport protocol\n"); + exit(-1); + } + + break; + + case REMOTE_IF4p5: + ru->do_prach = 0; + ru->feprx = NULL; // DFTs + ru->feptx_prec = feptx_prec; // Precoding operation + ru->feptx_ofdm = NULL; // no OFDM mod + ru->fh_south_in = fh_if4p5_south_in; // synchronous IF4p5 reception + ru->fh_south_out = fh_if4p5_south_out; // synchronous IF4p5 transmission + ru->fh_south_asynch_in = (ru->if_timing == synch_to_other) ? fh_if4p5_south_in : NULL; // asynchronous UL if synch_to_other + ru->fh_north_out = NULL; + ru->fh_north_asynch_in = NULL; + ru->start_rf = NULL; // no local RF + ru->stop_rf = NULL; + ru->start_if = start_if; // need to start if interface for IF4p5 + ru->ifdevice.host_type = RAU_HOST; + ru->ifdevice.eth_params = &ru->eth_params; + ru->ifdevice.configure_rru = configure_ru; + ret = openair0_transport_load(&ru->ifdevice, &ru->openair0_cfg, &ru->eth_params); + printf("openair0_transport_init returns %d for ru_id %d\n", ret, ru->idx); + + if (ret<0) { + printf("Exiting, cannot initialize transport protocol\n"); + exit(-1); + } + + malloc_IF4p5_buffer(ru); + break; + + default: + LOG_E(PHY,"RU with invalid or unknown southbound interface type %d\n",ru->if_south); + break; + } // switch on interface type +} + +extern void RCconfig_RU(void); + +void init_RU(char *rf_config_file) { + int ru_id; + RU_t *ru; + PHY_VARS_gNB *gNB0= (PHY_VARS_gNB *)NULL; + NR_DL_FRAME_PARMS *fp = (NR_DL_FRAME_PARMS *)NULL; + int i; + int CC_id; + // create status mask + RC.ru_mask = 0; + pthread_mutex_init(&RC.ru_mutex,NULL); + pthread_cond_init(&RC.ru_cond,NULL); + // read in configuration file) + printf("configuring RU from file\n"); + RCconfig_RU(); + LOG_I(PHY,"number of L1 instances %d, number of RU %d, number of CPU cores %d\n",RC.nb_nr_L1_inst,RC.nb_RU,get_nprocs()); + + if (RC.nb_nr_CC != 0) + for (i=0; inum_RU=0; + + LOG_D(PHY,"Process RUs RC.nb_RU:%d\n",RC.nb_RU); + + for (ru_id=0; ru_idrf_config_file = rf_config_file; + ru->idx = ru_id; + ru->ts_offset = 0; + // use gNB_list[0] as a reference for RU frame parameters + // NOTE: multiple CC_id are not handled here yet! + + if (ru->num_gNB > 0) { + LOG_D(PHY, "%s() RC.ru[%d].num_gNB:%d ru->gNB_list[0]:%p RC.gNB[0][0]:%p rf_config_file:%s\n", __FUNCTION__, ru_id, ru->num_gNB, ru->gNB_list[0], RC.gNB[0][0], ru->rf_config_file); + + if (ru->gNB_list[0] == 0) { + LOG_E(PHY,"%s() DJP - ru->gNB_list ru->num_gNB are not initialized - so do it manually\n", __FUNCTION__); + ru->gNB_list[0] = RC.gNB[0][0]; + ru->num_gNB=1; + // + // DJP - feptx_prec() / feptx_ofdm() parses the gNB_list (based on num_gNB) and copies the txdata_F to txdata in RU + // + } else { + LOG_E(PHY,"DJP - delete code above this %s:%d\n", __FILE__, __LINE__); + } + } + + gNB0 = ru->gNB_list[0]; + fp = ru->nr_frame_parms; + LOG_D(PHY, "RU FUnction:%d ru->if_south:%d\n", ru->function, ru->if_south); + + if (gNB0) { + if ((ru->function != NGFI_RRU_IF5) && (ru->function != NGFI_RRU_IF4p5)) + AssertFatal(gNB0!=NULL,"gNB0 is null!\n"); + + if (gNB0) { + LOG_I(PHY,"Copying frame parms from gNB %d to ru %d\n",gNB0->Mod_id,ru->idx); + memcpy((void *)fp,(void *)&gNB0->frame_parms,sizeof(NR_DL_FRAME_PARMS)); + memset((void *)ru->frame_parms, 0, sizeof(LTE_DL_FRAME_PARMS)); + // attach all RU to all gNBs in its list/ + LOG_D(PHY,"ru->num_gNB:%d gNB0->num_RU:%d\n", ru->num_gNB, gNB0->num_RU); + + for (i=0; inum_gNB; i++) { + gNB0 = ru->gNB_list[i]; + gNB0->RU_list[gNB0->num_RU++] = ru; + } + } + } + + // LOG_I(PHY,"Initializing RRU descriptor %d : (%s,%s,%d)\n",ru_id,ru_if_types[ru->if_south],gNB_timing[ru->if_timing],ru->function); + set_function_spec_param(ru); + LOG_I(PHY,"Starting ru_thread %d\n",ru_id); + init_RU_proc(ru); + } // for ru_id + + // sleep(1); + LOG_D(HW,"[nr-softmodem.c] RU threads created\n"); +} + + + + +void stop_RU(int nb_ru) { + for (int inst = 0; inst < nb_ru; inst++) { + LOG_I(PHY, "Stopping RU %d processing threads\n", inst); + kill_RU_proc(inst); + } +} + + +/* --------------------------------------------------------*/ +/* from here function to use configuration module */ +void RCconfig_RU(void) { + int j = 0; + int i = 0; + paramdef_t RUParams[] = RUPARAMS_DESC; + paramlist_def_t RUParamList = {CONFIG_STRING_RU_LIST,NULL,0}; + config_getlist( &RUParamList,RUParams,sizeof(RUParams)/sizeof(paramdef_t), NULL); + + if ( RUParamList.numelt > 0) { + RC.ru = (RU_t **)malloc(RC.nb_RU*sizeof(RU_t *)); + RC.ru_mask=(1<idx = j; + RC.ru[j]->nr_frame_parms = (NR_DL_FRAME_PARMS *)malloc(sizeof(NR_DL_FRAME_PARMS)); + RC.ru[j]->frame_parms = (LTE_DL_FRAME_PARMS *)malloc(sizeof(LTE_DL_FRAME_PARMS)); + printf("Creating RC.ru[%d]:%p\n", j, RC.ru[j]); + RC.ru[j]->if_timing = synch_to_ext_device; + + if (RC.nb_nr_L1_inst >0) + RC.ru[j]->num_gNB = RUParamList.paramarray[j][RU_ENB_LIST_IDX].numelt; + else + RC.ru[j]->num_gNB = 0; + + for (i=0; inum_gNB; i++) RC.ru[j]->gNB_list[i] = RC.gNB[RUParamList.paramarray[j][RU_ENB_LIST_IDX].iptr[i]][0]; + + if (config_isparamset(RUParamList.paramarray[j], RU_SDR_ADDRS)) { + RC.ru[j]->openair0_cfg.sdr_addrs = strdup(*(RUParamList.paramarray[j][RU_SDR_ADDRS].strptr)); + } + + if (config_isparamset(RUParamList.paramarray[j], RU_SDR_CLK_SRC)) { + if (strcmp(*(RUParamList.paramarray[j][RU_SDR_CLK_SRC].strptr), "internal") == 0) { + RC.ru[j]->openair0_cfg.clock_source = internal; + LOG_D(PHY, "RU clock source set as internal\n"); + } else if (strcmp(*(RUParamList.paramarray[j][RU_SDR_CLK_SRC].strptr), "external") == 0) { + RC.ru[j]->openair0_cfg.clock_source = external; + LOG_D(PHY, "RU clock source set as external\n"); + } else if (strcmp(*(RUParamList.paramarray[j][RU_SDR_CLK_SRC].strptr), "gpsdo") == 0) { + RC.ru[j]->openair0_cfg.clock_source = gpsdo; + LOG_D(PHY, "RU clock source set as gpsdo\n"); + } else { + LOG_E(PHY, "Erroneous RU clock source in the provided configuration file: '%s'\n", *(RUParamList.paramarray[j][RU_SDR_CLK_SRC].strptr)); + } + } + + if (strcmp(*(RUParamList.paramarray[j][RU_LOCAL_RF_IDX].strptr), "yes") == 0) { + if ( !(config_isparamset(RUParamList.paramarray[j],RU_LOCAL_IF_NAME_IDX)) ) { + RC.ru[j]->if_south = LOCAL_RF; + RC.ru[j]->function = gNodeB_3GPP; + printf("Setting function for RU %d to gNodeB_3GPP\n",j); + } else { + RC.ru[j]->eth_params.local_if_name = strdup(*(RUParamList.paramarray[j][RU_LOCAL_IF_NAME_IDX].strptr)); + RC.ru[j]->eth_params.my_addr = strdup(*(RUParamList.paramarray[j][RU_LOCAL_ADDRESS_IDX].strptr)); + RC.ru[j]->eth_params.remote_addr = strdup(*(RUParamList.paramarray[j][RU_REMOTE_ADDRESS_IDX].strptr)); + RC.ru[j]->eth_params.my_portc = *(RUParamList.paramarray[j][RU_LOCAL_PORTC_IDX].uptr); + RC.ru[j]->eth_params.remote_portc = *(RUParamList.paramarray[j][RU_REMOTE_PORTC_IDX].uptr); + RC.ru[j]->eth_params.my_portd = *(RUParamList.paramarray[j][RU_LOCAL_PORTD_IDX].uptr); + RC.ru[j]->eth_params.remote_portd = *(RUParamList.paramarray[j][RU_REMOTE_PORTD_IDX].uptr); + + if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "udp") == 0) { + RC.ru[j]->if_south = LOCAL_RF; + RC.ru[j]->function = NGFI_RRU_IF5; + RC.ru[j]->eth_params.transp_preference = ETH_UDP_MODE; + printf("Setting function for RU %d to NGFI_RRU_IF5 (udp)\n",j); + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "raw") == 0) { + RC.ru[j]->if_south = LOCAL_RF; + RC.ru[j]->function = NGFI_RRU_IF5; + RC.ru[j]->eth_params.transp_preference = ETH_RAW_MODE; + printf("Setting function for RU %d to NGFI_RRU_IF5 (raw)\n",j); + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "udp_if4p5") == 0) { + RC.ru[j]->if_south = LOCAL_RF; + RC.ru[j]->function = NGFI_RRU_IF4p5; + RC.ru[j]->eth_params.transp_preference = ETH_UDP_IF4p5_MODE; + printf("Setting function for RU %d to NGFI_RRU_IF4p5 (udp)\n",j); + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "raw_if4p5") == 0) { + RC.ru[j]->if_south = LOCAL_RF; + RC.ru[j]->function = NGFI_RRU_IF4p5; + RC.ru[j]->eth_params.transp_preference = ETH_RAW_IF4p5_MODE; + printf("Setting function for RU %d to NGFI_RRU_IF4p5 (raw)\n",j); + } + } + + RC.ru[j]->max_pdschReferenceSignalPower = *(RUParamList.paramarray[j][RU_MAX_RS_EPRE_IDX].uptr);; + RC.ru[j]->max_rxgain = *(RUParamList.paramarray[j][RU_MAX_RXGAIN_IDX].uptr); + RC.ru[j]->num_bands = RUParamList.paramarray[j][RU_BAND_LIST_IDX].numelt; + + for (i=0; inum_bands; i++) RC.ru[j]->band[i] = RUParamList.paramarray[j][RU_BAND_LIST_IDX].iptr[i]; + } //strcmp(local_rf, "yes") == 0 + else { + printf("RU %d: Transport %s\n",j,*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr)); + RC.ru[j]->eth_params.local_if_name = strdup(*(RUParamList.paramarray[j][RU_LOCAL_IF_NAME_IDX].strptr)); + RC.ru[j]->eth_params.my_addr = strdup(*(RUParamList.paramarray[j][RU_LOCAL_ADDRESS_IDX].strptr)); + RC.ru[j]->eth_params.remote_addr = strdup(*(RUParamList.paramarray[j][RU_REMOTE_ADDRESS_IDX].strptr)); + RC.ru[j]->eth_params.my_portc = *(RUParamList.paramarray[j][RU_LOCAL_PORTC_IDX].uptr); + RC.ru[j]->eth_params.remote_portc = *(RUParamList.paramarray[j][RU_REMOTE_PORTC_IDX].uptr); + RC.ru[j]->eth_params.my_portd = *(RUParamList.paramarray[j][RU_LOCAL_PORTD_IDX].uptr); + RC.ru[j]->eth_params.remote_portd = *(RUParamList.paramarray[j][RU_REMOTE_PORTD_IDX].uptr); + + if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "udp") == 0) { + RC.ru[j]->if_south = REMOTE_IF5; + RC.ru[j]->function = NGFI_RAU_IF5; + RC.ru[j]->eth_params.transp_preference = ETH_UDP_MODE; + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "raw") == 0) { + RC.ru[j]->if_south = REMOTE_IF5; + RC.ru[j]->function = NGFI_RAU_IF5; + RC.ru[j]->eth_params.transp_preference = ETH_RAW_MODE; + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "udp_if4p5") == 0) { + RC.ru[j]->if_south = REMOTE_IF4p5; + RC.ru[j]->function = NGFI_RAU_IF4p5; + RC.ru[j]->eth_params.transp_preference = ETH_UDP_IF4p5_MODE; + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "raw_if4p5") == 0) { + RC.ru[j]->if_south = REMOTE_IF4p5; + RC.ru[j]->function = NGFI_RAU_IF4p5; + RC.ru[j]->eth_params.transp_preference = ETH_RAW_IF4p5_MODE; + } else if (strcmp(*(RUParamList.paramarray[j][RU_TRANSPORT_PREFERENCE_IDX].strptr), "raw_if5_mobipass") == 0) { + RC.ru[j]->if_south = REMOTE_IF5; + RC.ru[j]->function = NGFI_RAU_IF5; + RC.ru[j]->if_timing = synch_to_other; + RC.ru[j]->eth_params.transp_preference = ETH_RAW_IF5_MOBIPASS; + } + } /* strcmp(local_rf, "yes") != 0 */ + + RC.ru[j]->nb_tx = *(RUParamList.paramarray[j][RU_NB_TX_IDX].uptr); + RC.ru[j]->nb_rx = *(RUParamList.paramarray[j][RU_NB_RX_IDX].uptr); + RC.ru[j]->att_tx = *(RUParamList.paramarray[j][RU_ATT_TX_IDX].uptr); + RC.ru[j]->att_rx = *(RUParamList.paramarray[j][RU_ATT_RX_IDX].uptr); + }// j=0..num_rus + } else { + RC.nb_RU = 0; + } // setting != NULL + + return; +} diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c new file mode 100644 index 0000000000..c724940fb2 --- /dev/null +++ b/executables/nr-softmodem.c @@ -0,0 +1,1243 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + + +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include + + +#include "T.h" + +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all +#include + +#include "msc.h" + +#include "PHY/types.h" +#include "common/ran_context.h" + +#include "PHY/defs_gNB.h" +#include "common/config/config_userapi.h" +#include "common/utils/load_module_shlib.h" +#undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "../../ARCH/COMMON/common_lib.h" +#include "../../ARCH/ETHERNET/USERSPACE/LIB/if_defs.h" + +//#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all + +#include "PHY/phy_vars.h" +#include "SCHED/sched_common_vars.h" +#include "LAYER2/MAC/mac_vars.h" + +#include "LAYER2/MAC/mac.h" +#include "LAYER2/MAC/mac_proto.h" +#include "RRC/LTE/rrc_vars.h" +#include "PHY_INTERFACE/phy_interface_vars.h" +#include "gnb_config.h" + +#ifdef SMBV +#include "PHY/TOOLS/smbv.h" +unsigned short config_frames[4] = {2,9,11,13}; +#endif + +#include "common/utils/LOG/log.h" +#include "common/utils/LOG/vcd_signal_dumper.h" + +#include "UTIL/OPT/opt.h" + +//#include "PHY/TOOLS/time_meas.h" + +#ifndef OPENAIR2 + #include "UTIL/OTG/otg_vars.h" +#endif + +#if defined(ENABLE_ITTI) + #include "intertask_interface.h" +#endif + +#include "PHY/INIT/phy_init.h" + +#include "system.h" +#include + +#ifdef XFORMS + #include "PHY/TOOLS/lte_phy_scope.h" + #include "stats.h" +#endif +#include "nr-softmodem.h" +#include "NB_IoT_interface.h" + +#ifdef XFORMS + // current status is that every UE has a DL scope for a SINGLE eNB (gnb_id=0) + // at eNB 0, an UL scope for every UE + + FD_lte_phy_scope_ue *form_ue[NUMBER_OF_UE_MAX]; + FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX]; + FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; + char title[255]; + unsigned char scope_enb_num_ue = 2; + static pthread_t forms_thread; //xforms + +#endif //XFORMS + +short nr_mod_table[NR_MOD_TABLE_SIZE_SHORT] = {0,0,16384,16384,-16384,-16384,16384,16384,16384,-16384,-16384,16384,-16384,-16384,7327,7327,7327,21981,21981,7327,21981,21981,7327,-7327,7327,-21981,21981,-7327,21981,-21981,-7327,7327,-7327,21981,-21981,7327,-21981,21981,-7327,-7327,-7327,-21981,-21981,-7327,-21981,-21981,10726,10726,10726,3576,3576,10726,3576,3576,10726,17876,10726,25027,3576,17876,3576,25027,17876,10726,17876,3576,25027,10726,25027,3576,17876,17876,17876,25027,25027,17876,25027,25027,10726,-10726,10726,-3576,3576,-10726,3576,-3576,10726,-17876,10726,-25027,3576,-17876,3576,-25027,17876,-10726,17876,-3576,25027,-10726,25027,-3576,17876,-17876,17876,-25027,25027,-17876,25027,-25027,-10726,10726,-10726,3576,-3576,10726,-3576,3576,-10726,17876,-10726,25027,-3576,17876,-3576,25027,-17876,10726,-17876,3576,-25027,10726,-25027,3576,-17876,17876,-17876,25027,-25027,17876,-25027,25027,-10726,-10726,-10726,-3576,-3576,-10726,-3576,-3576,-10726,-17876,-10726,-25027,-3576,-17876,-3576,-25027,-17876,-10726,-17876,-3576,-25027,-10726,-25027,-3576,-17876,-17876,-17876,-25027,-25027,-17876,-25027,-25027,8886,8886,8886,12439,12439,8886,12439,12439,8886,5332,8886,1778,12439,5332,12439,1778,5332,8886,5332,12439,1778,8886,1778,12439,5332,5332,5332,1778,1778,5332,1778,1778,8886,19547,8886,15993,12439,19547,12439,15993,8886,23101,8886,26655,12439,23101,12439,26655,5332,19547,5332,15993,1778,19547,1778,15993,5332,23101,5332,26655,1778,23101,1778,26655,19547,8886,19547,12439,15993,8886,15993,12439,19547,5332,19547,1778,15993,5332,15993,1778,23101,8886,23101,12439,26655,8886,26655,12439,23101,5332,23101,1778,26655,5332,26655,1778,19547,19547,19547,15993,15993,19547,15993,15993,19547,23101,19547,26655,15993,23101,15993,26655,23101,19547,23101,15993,26655,19547,26655,15993,23101,23101,23101,26655,26655,23101,26655,26655,8886,-8886,8886,-12439,12439,-8886,12439,-12439,8886,-5332,8886,-1778,12439,-5332,12439,-1778,5332,-8886,5332,-12439,1778,-8886,1778,-12439,5332,-5332,5332,-1778,1778,-5332,1778,-1778,8886,-19547,8886,-15993,12439,-19547,12439,-15993,8886,-23101,8886,-26655,12439,-23101,12439,-26655,5332,-19547,5332,-15993,1778,-19547,1778,-15993,5332,-23101,5332,-26655,1778,-23101,1778,-26655,19547,-8886,19547,-12439,15993,-8886,15993,-12439,19547,-5332,19547,-1778,15993,-5332,15993,-1778,23101,-8886,23101,-12439,26655,-8886,26655,-12439,23101,-5332,23101,-1778,26655,-5332,26655,-1778,19547,-19547,19547,-15993,15993,-19547,15993,-15993,19547,-23101,19547,-26655,15993,-23101,15993,-26655,23101,-19547,23101,-15993,26655,-19547,26655,-15993,23101,-23101,23101,-26655,26655,-23101,26655,-26655,-8886,8886,-8886,12439,-12439,8886,-12439,12439,-8886,5332,-8886,1778,-12439,5332,-12439,1778,-5332,8886,-5332,12439,-1778,8886,-1778,12439,-5332,5332,-5332,1778,-1778,5332,-1778,1778,-8886,19547,-8886,15993,-12439,19547,-12439,15993,-8886,23101,-8886,26655,-12439,23101,-12439,26655,-5332,19547,-5332,15993,-1778,19547,-1778,15993,-5332,23101,-5332,26655,-1778,23101,-1778,26655,-19547,8886,-19547,12439,-15993,8886,-15993,12439,-19547,5332,-19547,1778,-15993,5332,-15993,1778,-23101,8886,-23101,12439,-26655,8886,-26655,12439,-23101,5332,-23101,1778,-26655,5332,-26655,1778,-19547,19547,-19547,15993,-15993,19547,-15993,15993,-19547,23101,-19547,26655,-15993,23101,-15993,26655,-23101,19547,-23101,15993,-26655,19547,-26655,15993,-23101,23101,-23101,26655,-26655,23101,-26655,26655,-8886,-8886,-8886,-12439,-12439,-8886,-12439,-12439,-8886,-5332,-8886,-1778,-12439,-5332,-12439,-1778,-5332,-8886,-5332,-12439,-1778,-8886,-1778,-12439,-5332,-5332,-5332,-1778,-1778,-5332,-1778,-1778,-8886,-19547,-8886,-15993,-12439,-19547,-12439,-15993,-8886,-23101,-8886,-26655,-12439,-23101,-12439,-26655,-5332,-19547,-5332,-15993,-1778,-19547,-1778,-15993,-5332,-23101,-5332,-26655,-1778,-23101,-1778,-26655,-19547,-8886,-19547,-12439,-15993,-8886,-15993,-12439,-19547,-5332,-19547,-1778,-15993,-5332,-15993,-1778,-23101,-8886,-23101,-12439,-26655,-8886,-26655,-12439,-23101,-5332,-23101,-1778,-26655,-5332,-26655,-1778,-19547,-19547,-19547,-15993,-15993,-19547,-15993,-15993,-19547,-23101,-19547,-26655,-15993,-23101,-15993,-26655,-23101,-19547,-23101,-15993,-26655,-19547,-26655,-15993,-23101,-23101,-23101,-26655,-26655,-23101,-26655,-26655}; + + +pthread_cond_t nfapi_sync_cond; +pthread_mutex_t nfapi_sync_mutex; +int nfapi_sync_var=-1; //!< protected by mutex \ref nfapi_sync_mutex + +uint8_t nfapi_mode = 0; // Default to monolithic mode + +pthread_cond_t sync_cond; +pthread_mutex_t sync_mutex; +int sync_var=-1; //!< protected by mutex \ref sync_mutex. +int config_sync_var=-1; + +#if defined(ENABLE_ITTI) + volatile int start_gNB = 0; +#endif +volatile int oai_exit = 0; + +static clock_source_t clock_source = internal; +static int wait_for_sync = 0; + +unsigned int mmapped_dma=0; +int single_thread_flag=1; + +static int8_t threequarter_fs=0; + +uint32_t downlink_frequency[MAX_NUM_CCs][4]; +int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; + +//Temp fix for inexisting NR upper layer +unsigned char NB_gNB_INST = 1; + +#if defined(ENABLE_ITTI) + static char *itti_dump_file = NULL; +#endif + +int UE_scan = 1; +int UE_scan_carrier = 0; +runmode_t mode = normal_txrx; + +FILE *input_fd=NULL; + + +#if MAX_NUM_CCs == 1 +rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain}}; +double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0}}; +double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0}}; +#else +rx_gain_t rx_gain_mode[MAX_NUM_CCs][4] = {{max_gain,max_gain,max_gain,max_gain},{max_gain,max_gain,max_gain,max_gain}}; +double tx_gain[MAX_NUM_CCs][4] = {{20,0,0,0},{20,0,0,0}}; +double rx_gain[MAX_NUM_CCs][4] = {{110,0,0,0},{20,0,0,0}}; +#endif + +double rx_gain_off = 0.0; + +double sample_rate=30.72e6; +double bw = 10.0e6; + +static int tx_max_power[MAX_NUM_CCs]; /* = {0,0}*/; + +char rf_config_file[1024]="/usr/local/etc/syriq/ue.band7.tm1.PRB100.NR40.dat"; + +int chain_offset=0; +int phy_test = 0; +uint8_t usim_test = 0; + +uint8_t dci_Format = 0; +uint8_t agregation_Level =0xFF; + +uint8_t nb_antenna_tx = 1; +uint8_t nb_antenna_rx = 1; + +char ref[128] = "internal"; +char channels[128] = "0"; + +int rx_input_level_dBm; + +#ifdef XFORMS + extern int otg_enabled; + static char do_forms=0; +#else + int otg_enabled; +#endif +//int number_of_cards = 1; + + +//static NR_DL_FRAME_PARMS *frame_parms[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; +uint8_t exit_missed_slots=1; +uint64_t num_missed_slots=0; // counter for the number of missed slots + + +extern void reset_opp_meas(void); +extern void print_opp_meas(void); + +extern void init_eNB_afterRU(void); + +int transmission_mode=1; +int emulate_rf = 0; +int numerology = 0; +char *parallel_config = NULL; +char *worker_config = NULL; + +static THREAD_STRUCT thread_struct; +void set_parallel_conf(char *parallel_conf) { + if(strcmp(parallel_conf,"PARALLEL_SINGLE_THREAD")==0) thread_struct.parallel_conf = PARALLEL_SINGLE_THREAD; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_SPLIT; + else if(strcmp(parallel_conf,"PARALLEL_RU_L1_TRX_SPLIT")==0) thread_struct.parallel_conf = PARALLEL_RU_L1_TRX_SPLIT; + + printf("[CONFIG] parallel conf is set to %d\n",thread_struct.parallel_conf); +} +void set_worker_conf(char *worker_conf) { + if(strcmp(worker_conf,"WORKER_DISABLE")==0) thread_struct.worker_conf = WORKER_DISABLE; + else if(strcmp(worker_conf,"WORKER_ENABLE")==0) thread_struct.worker_conf = WORKER_ENABLE; + + printf("[CONFIG] worker conf is set to %d\n",thread_struct.worker_conf); +} +PARALLEL_CONF_t get_thread_parallel_conf(void) { + return thread_struct.parallel_conf; +} +WORKER_CONF_t get_thread_worker_conf(void) { + return thread_struct.worker_conf; +} + + +/* struct for ethernet specific parameters given in eNB conf file */ +eth_params_t *eth_params; + +openair0_config_t openair0_cfg[MAX_CARDS]; + +double cpuf; + +extern char uecap_xer[1024]; +char uecap_xer_in=0; + +/* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed + * this is very hackish - find a proper solution + */ +uint8_t abstraction_flag=0; + +/* forward declarations */ +void set_default_frame_parms(nfapi_nr_config_request_t *config[MAX_NUM_CCs], NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); + +/*---------------------BMC: timespec helpers -----------------------------*/ + +struct timespec min_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; +struct timespec max_diff_time = { .tv_sec = 0, .tv_nsec = 0 }; + +struct timespec clock_difftime(struct timespec start, struct timespec end) { + struct timespec temp; + + if ((end.tv_nsec-start.tv_nsec)<0) { + temp.tv_sec = end.tv_sec-start.tv_sec-1; + temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; + } else { + temp.tv_sec = end.tv_sec-start.tv_sec; + temp.tv_nsec = end.tv_nsec-start.tv_nsec; + } + + return temp; +} + +void print_difftimes(void) { +#ifdef DEBUG + printf("difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); +#else + LOG_I(HW,"difftimes min = %lu ns ; max = %lu ns\n", min_diff_time.tv_nsec, max_diff_time.tv_nsec); +#endif +} + +void update_difftimes(struct timespec start, struct timespec end) { + struct timespec diff_time = { .tv_sec = 0, .tv_nsec = 0 }; + int changed = 0; + diff_time = clock_difftime(start, end); + + if ((min_diff_time.tv_nsec == 0) || (diff_time.tv_nsec < min_diff_time.tv_nsec)) { + min_diff_time.tv_nsec = diff_time.tv_nsec; + changed = 1; + } + + if ((max_diff_time.tv_nsec == 0) || (diff_time.tv_nsec > max_diff_time.tv_nsec)) { + max_diff_time.tv_nsec = diff_time.tv_nsec; + changed = 1; + } + +#if 1 + + if (changed) print_difftimes(); + +#endif +} + +/*------------------------------------------------------------------------*/ + +unsigned int build_rflocal(int txi, int txq, int rxi, int rxq) { + return (txi + (txq<<6) + (rxi<<12) + (rxq<<18)); +} +unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe) { + return (dcoff_i_rxfe + (dcoff_q_rxfe<<8)); +} + +#if !defined(ENABLE_ITTI) +void signal_handler(int sig) { + void *array[10]; + size_t size; + + if (sig==SIGSEGV) { + // get void*'s for all entries on the stack + size = backtrace(array, 10); + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(array, size, 2); + exit(-1); + } else { + printf("trying to exit gracefully...\n"); + oai_exit = 1; + } +} +#endif +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define KBLU "\x1B[34m" +#define RESET "\033[0m" + +#if defined(ENABLE_ITTI) +void signal_handler_itti(int sig) { + // Call exit function + char msg[256]; + memset(msg, 0, 256); + sprintf(msg, "caught signal %s\n", strsignal(sig)); + exit_function(__FILE__, __FUNCTION__, __LINE__, msg); +} +#endif + +void exit_function(const char *file, const char *function, const int line, const char *s) { + int ru_id; + + if (s != NULL) { + printf("%s:%d %s() Exiting OAI softmodem: %s\n",file,line, function, s); + } + + oai_exit = 1; + + if (RC.ru == NULL) + exit(-1); // likely init not completed, prevent crash or hang, exit now... + + for (ru_id=0; ru_idrfdevice.trx_end_func) { + RC.ru[ru_id]->rfdevice.trx_end_func(&RC.ru[ru_id]->rfdevice); + RC.ru[ru_id]->rfdevice.trx_end_func = NULL; + } + + if (RC.ru[ru_id] && RC.ru[ru_id]->ifdevice.trx_end_func) { + RC.ru[ru_id]->ifdevice.trx_end_func(&RC.ru[ru_id]->ifdevice); + RC.ru[ru_id]->ifdevice.trx_end_func = NULL; + } + } + + sleep(1); //allow lte-softmodem threads to exit first +#if defined(ENABLE_ITTI) + itti_terminate_tasks (TASK_UNKNOWN); +#endif + exit(1); +} + +#ifdef XFORMS + + +void reset_stats(FL_OBJECT *button, long arg) { + PHY_VARS_gNB *phy_vars_gNB = RC.gNB[0][0]; + + for (int i=0; idlsch[i][0]->Mlimit; j++) { + phy_vars_gNB->UE_stats[i].dlsch_NAK[k][j]=0; + phy_vars_gNB->UE_stats[i].dlsch_ACK[k][j]=0; + phy_vars_gNB->UE_stats[i].dlsch_trials[k][j]=0; + }*/ + phy_vars_gNB->UE_stats[i].dlsch_l2_errors[k]=0; + phy_vars_gNB->UE_stats[i].ulsch_errors[k]=0; + phy_vars_gNB->UE_stats[i].ulsch_consecutive_errors=0; + phy_vars_gNB->UE_stats[i].dlsch_sliding_cnt=0; + phy_vars_gNB->UE_stats[i].dlsch_NAK_round0=0; + phy_vars_gNB->UE_stats[i].dlsch_mcs_offset=0; + } + } +} + +static void *scope_thread(void *arg) { + threadTopInit("scope",-1,OAI_PRIORITY_RT_LOW); + int UE_id, CC_id; + int ue_cnt=0; +# ifdef ENABLE_XFORMS_WRITE_STATS + FILE *gNB_stats = fopen("gNB_stats.txt", "w"); +#endif + + while (!oai_exit) { + ue_cnt=0; + + for(UE_id=0; UE_id 0) { + /* Last task to create, others task must be ready before its start */ + if (itti_create_task (TASK_GNB_APP, gNB_app_task, NULL) < 0) { + LOG_E(GNB_APP, "Create task for gNB APP failed\n"); + return -1; + } + } + + /* + # if defined(ENABLE_USE_MME) + if (gnb_nb > 0) { + if (itti_create_task (TASK_SCTP, sctp_eNB_task, NULL) < 0) { + LOG_E(SCTP, "Create task for SCTP failed\n"); + return -1; + } + + if (itti_create_task (TASK_S1AP, s1ap_eNB_task, NULL) < 0) { + LOG_E(S1AP, "Create task for S1AP failed\n"); + return -1; + } + if(!emulate_rf){ + if (itti_create_task (TASK_UDP, udp_eNB_task, NULL) < 0) { + LOG_E(UDP_, "Create task for UDP failed\n"); + return -1; + } + } + + if (itti_create_task (TASK_GTPV1_U, >pv1u_eNB_task, NULL) < 0) { + LOG_E(GTPU, "Create task for GTPV1U failed\n"); + return -1; + } + } + + # endif + */ + + if (gnb_nb > 0) { + LOG_I(NR_RRC,"Creating NR RRC gNB Task\n"); + + if (itti_create_task (TASK_RRC_GNB, rrc_gnb_task, NULL) < 0) { + LOG_E(NR_RRC, "Create task for NR RRC gNB failed\n"); + return -1; + } + } + + return 0; +} + + +static void get_options(void) { + int tddflag, nonbiotflag; + uint32_t online_log_messages; + uint32_t glog_level, glog_verbosity; + uint32_t start_telnetsrv; + paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; + paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; + config_process_cmdline( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); + + if (strlen(in_path) > 0) { + opt_type = OPT_PCAP; + opt_enabled=1; + printf("Enabling OPT for PCAP with the following file %s \n",in_path); + } + + if (strlen(in_ip) > 0) { + opt_enabled=1; + opt_type = OPT_WIRESHARK; + printf("Enabling OPT for wireshark for local interface"); + } + + config_process_cmdline( cmdline_logparams,sizeof(cmdline_logparams)/sizeof(paramdef_t),NULL); + + if(config_isparamset(cmdline_logparams,CMDLINE_ONLINELOG_IDX)) { + set_glog_onlinelog(online_log_messages); + } + + if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) { + set_glog(glog_level); + } + + if (start_telnetsrv) { + load_module_shlib("telnetsrv",NULL,0,NULL); + } + +#if T_TRACER + paramdef_t cmdline_ttraceparams[] =CMDLINE_TTRACEPARAMS_DESC ; + config_process_cmdline( cmdline_ttraceparams,sizeof(cmdline_ttraceparams)/sizeof(paramdef_t),NULL); +#endif + + if ( !(CONFIG_ISFLAGSET(CONFIG_ABORT)) ) { + memset((void *)&RC,0,sizeof(RC)); + /* Read RC configuration file */ + NRRCConfig(); + NB_gNB_INST = RC.nb_nr_inst; + NB_RU = RC.nb_RU; + printf("Configuration: nb_rrc_inst %d, nb_nr_L1_inst %d, nb_ru %d\n",NB_gNB_INST,RC.nb_nr_L1_inst,NB_RU); + } + + if(parallel_config != NULL) set_parallel_conf(parallel_config); + + if(worker_config != NULL) set_worker_conf(worker_config); +} + + +#if T_TRACER + int T_nowait = 0; /* by default we wait for the tracer */ + int T_port = 2021; /* default port to listen to to wait for the tracer */ + int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */ +#endif + + + +void set_default_frame_parms(nfapi_nr_config_request_t *config[MAX_NUM_CCs], NR_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]) { + int CC_id; + + for (CC_id=0; CC_idsubframe_config.numerology_index_mu.value =1; + config[CC_id]->subframe_config.duplex_mode.value = 1; //FDD + config[CC_id]->subframe_config.dl_cyclic_prefix_type.value = 0; //NORMAL + config[CC_id]->rf_config.dl_carrier_bandwidth.value = 106; + config[CC_id]->rf_config.ul_carrier_bandwidth.value = 106; + config[CC_id]->sch_config.physical_cell_id.value = 0; + ///dl frequency to be filled in + /* //Set some default values that may be overwritten while reading options + frame_parms[CC_id]->frame_type = FDD; + frame_parms[CC_id]->tdd_config = 3; + frame_parms[CC_id]->tdd_config_S = 0; + frame_parms[CC_id]->N_RB_DL = 100; + frame_parms[CC_id]->N_RB_UL = 100; + frame_parms[CC_id]->Ncp = NORMAL; + frame_parms[CC_id]->Ncp_UL = NORMAL; + frame_parms[CC_id]->Nid_cell = 0; + frame_parms[CC_id]->num_MBSFN_config = 0; + frame_parms[CC_id]->nb_antenna_ports_eNB = 1; + frame_parms[CC_id]->nb_antennas_tx = 1; + frame_parms[CC_id]->nb_antennas_rx = 1; + + frame_parms[CC_id]->nushift = 0; + + frame_parms[CC_id]->phich_config_common.phich_resource = oneSixth; + frame_parms[CC_id]->phich_config_common.phich_duration = normal; + // UL RS Config + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = 0;//n_DMRS1 set to 0 + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 0; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0; + frame_parms[CC_id]->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0; + + frame_parms[CC_id]->prach_config_common.rootSequenceIndex=22; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=1; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.highSpeedFlag=0; + frame_parms[CC_id]->prach_config_common.prach_ConfigInfo.prach_FreqOffset=0; + + // downlink_frequency[CC_id][0] = 2680000000; // Use float to avoid issue with frequency over 2^31. + // downlink_frequency[CC_id][1] = downlink_frequency[CC_id][0]; + // downlink_frequency[CC_id][2] = downlink_frequency[CC_id][0]; + // downlink_frequency[CC_id][3] = downlink_frequency[CC_id][0]; + //printf("Downlink for CC_id %d frequency set to %u\n", CC_id, downlink_frequency[CC_id][0]); + frame_parms[CC_id]->dl_CarrierFreq=downlink_frequency[CC_id][0]; + */ + } +} + +/* +void init_openair0(void) { + + int card; + int i; + + for (card=0; cardrf_config.dl_carrier_bandwidth.value == 100) { + if (frame_parms[0]->threequarter_fs) { + openair0_cfg[card].sample_rate=23.04e6; + openair0_cfg[card].samples_per_frame = 230400; + openair0_cfg[card].tx_bw = 10e6; + openair0_cfg[card].rx_bw = 10e6; + } else { + openair0_cfg[card].sample_rate=30.72e6; + openair0_cfg[card].samples_per_frame = 307200; + openair0_cfg[card].tx_bw = 10e6; + openair0_cfg[card].rx_bw = 10e6; + } + } else if(config[0]->rf_config.dl_carrier_bandwidth.value == 50) { + openair0_cfg[card].sample_rate=15.36e6; + openair0_cfg[card].samples_per_frame = 153600; + openair0_cfg[card].tx_bw = 5e6; + openair0_cfg[card].rx_bw = 5e6; + } else if (config[0]->rf_config.dl_carrier_bandwidth.value == 25) { + openair0_cfg[card].sample_rate=7.68e6; + openair0_cfg[card].samples_per_frame = 76800; + openair0_cfg[card].tx_bw = 2.5e6; + openair0_cfg[card].rx_bw = 2.5e6; + } else if (config[0]->rf_config.dl_carrier_bandwidth.value == 6) { + openair0_cfg[card].sample_rate=1.92e6; + openair0_cfg[card].samples_per_frame = 19200; + openair0_cfg[card].tx_bw = 1.5e6; + openair0_cfg[card].rx_bw = 1.5e6; + } + + + if (config[0]->subframe_config.duplex_mode.value==TDD) + openair0_cfg[card].duplex_mode = duplex_mode_TDD; + else //FDD + openair0_cfg[card].duplex_mode = duplex_mode_FDD; + + printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card, + RC.gNB[0][0]->gNB_config.rf_config.tx_antenna_ports.value, + RC.gNB[0][0]->gNB_config.rf_config.tx_antenna_ports.value ); + openair0_cfg[card].Mod_id = 0; + + openair0_cfg[card].num_rb_dl=config[0]->rf_config.dl_carrier_bandwidth.value; + + openair0_cfg[card].clock_source = clock_source; + + + openair0_cfg[card].tx_num_channels=min(2,RC.gNB[0][0]->gNB_config.rf_config.tx_antenna_ports.value ); + openair0_cfg[card].rx_num_channels=min(2,RC.gNB[0][0]->gNB_config.rf_config.tx_antenna_ports.value ); + + for (i=0; i<4; i++) { + + if (irx_total_gain_dB; + + + openair0_cfg[card].configFilename = rf_config_file; + printf("Card %d, channel %d, Setting tx_gain %f, rx_gain %f, tx_freq %f, rx_freq %f\n", + card,i, openair0_cfg[card].tx_gain[i], + openair0_cfg[card].rx_gain[i], + openair0_cfg[card].tx_freq[i], + openair0_cfg[card].rx_freq[i]); + } + } // for loop on cards +} +*/ + +void wait_RUs(void) { + LOG_I(PHY,"Waiting for RUs to be configured ... RC.ru_mask:%02lx\n", RC.ru_mask); + // wait for all RUs to be configured over fronthaul + pthread_mutex_lock(&RC.ru_mutex); + + while (RC.ru_mask>0) { + pthread_cond_wait(&RC.ru_cond,&RC.ru_mutex); + printf("RC.ru_mask:%02lx\n", RC.ru_mask); + } + + pthread_mutex_unlock(&RC.ru_mutex); + LOG_I(PHY,"RUs configured\n"); +} + +void wait_gNBs(void) { + int i,j; + int waiting=1; + + while (waiting==1) { + printf("Waiting for gNB L1 instances to all get configured ... sleeping 50ms (nb_nr_sL1_inst %d)\n",RC.nb_nr_L1_inst); + usleep(50*1000); + waiting=0; + + for (i=0; iconfigured==0) { + waiting=1; + break; + } + } + } + } + + printf("gNB L1 are configured\n"); +} + +#if defined(ENABLE_ITTI) +/* + * helper function to terminate a certain ITTI task + */ +void terminate_task(task_id_t task_id, module_id_t mod_id) { + LOG_I(ENB_APP, "sending TERMINATE_MESSAGE to task %s (%d)\n", itti_get_task_name(task_id), task_id); + MessageDef *msg; + msg = itti_alloc_new_message (ENB_APP, TERMINATE_MESSAGE); + itti_send_msg_to_task (task_id, ENB_MODULE_ID_TO_INSTANCE(mod_id), msg); +} + +//extern void free_transport(PHY_VARS_gNB *); +extern void nr_phy_free_RU(RU_t *); + +int stop_L1L2(module_id_t gnb_id) { + LOG_W(ENB_APP, "stopping nr-softmodem\n"); + oai_exit = 1; + + if (!RC.ru) { + LOG_F(ENB_APP, "no RU configured\n"); + return -1; + } + + /* stop trx devices, multiple carrier currently not supported by RU */ + if (RC.ru[gnb_id]) { + if (RC.ru[gnb_id]->rfdevice.trx_stop_func) { + RC.ru[gnb_id]->rfdevice.trx_stop_func(&RC.ru[gnb_id]->rfdevice); + LOG_I(ENB_APP, "turned off RU rfdevice\n"); + } else { + LOG_W(ENB_APP, "can not turn off rfdevice due to missing trx_stop_func callback, proceding anyway!\n"); + } + + if (RC.ru[gnb_id]->ifdevice.trx_stop_func) { + RC.ru[gnb_id]->ifdevice.trx_stop_func(&RC.ru[gnb_id]->ifdevice); + LOG_I(ENB_APP, "turned off RU ifdevice\n"); + } else { + LOG_W(ENB_APP, "can not turn off ifdevice due to missing trx_stop_func callback, proceding anyway!\n"); + } + } else { + LOG_W(ENB_APP, "no RU found for index %d\n", gnb_id); + return -1; + } + + /* these tasks need to pick up new configuration */ + terminate_task(TASK_RRC_ENB, gnb_id); + terminate_task(TASK_L2L1, gnb_id); + LOG_I(ENB_APP, "calling kill_gNB_proc() for instance %d\n", gnb_id); + kill_gNB_proc(gnb_id); + LOG_I(ENB_APP, "calling kill_RU_proc() for instance %d\n", gnb_id); + kill_RU_proc(gnb_id); + oai_exit = 0; + + for (int cc_id = 0; cc_id < RC.nb_nr_CC[gnb_id]; cc_id++) { + //free_transport(RC.gNB[gnb_id][cc_id]); + phy_free_nr_gNB(RC.gNB[gnb_id][cc_id]); + } + + nr_phy_free_RU(RC.ru[gnb_id]); + free_lte_top(); + return 0; +} + +/* + * Restart the nr-softmodem after it has been soft-stopped with stop_L1L2() + */ +int restart_L1L2(module_id_t gnb_id) { + RU_t *ru = RC.ru[gnb_id]; + int cc_id; + MessageDef *msg_p = NULL; + LOG_W(ENB_APP, "restarting nr-softmodem\n"); + /* block threads */ + sync_var = -1; + + for (cc_id = 0; cc_id < RC.nb_nr_L1_CC[gnb_id]; cc_id++) { + RC.gNB[gnb_id][cc_id]->configured = 0; + } + + RC.ru_mask |= (1 << ru->idx); + /* copy the changed frame parameters to the RU */ + /* TODO this should be done for all RUs associated to this gNB */ + memcpy(&ru->nr_frame_parms, &RC.gNB[gnb_id][0]->frame_parms, sizeof(NR_DL_FRAME_PARMS)); + set_function_spec_param(RC.ru[gnb_id]); + LOG_I(ENB_APP, "attempting to create ITTI tasks\n"); + + if (itti_create_task (TASK_RRC_ENB, rrc_enb_task, NULL) < 0) { + LOG_E(RRC, "Create task for RRC eNB failed\n"); + return -1; + } else { + LOG_I(RRC, "Re-created task for RRC gNB successfully\n"); + } + + if (itti_create_task (TASK_L2L1, l2l1_task, NULL) < 0) { + LOG_E(PDCP, "Create task for L2L1 failed\n"); + return -1; + } else { + LOG_I(PDCP, "Re-created task for L2L1 successfully\n"); + } + + /* pass a reconfiguration request which will configure everything down to + * RC.eNB[i][j]->frame_parms, too */ + msg_p = itti_alloc_new_message(TASK_ENB_APP, RRC_CONFIGURATION_REQ); + RRC_CONFIGURATION_REQ(msg_p) = RC.rrc[gnb_id]->configuration; + itti_send_msg_to_task(TASK_RRC_ENB, ENB_MODULE_ID_TO_INSTANCE(gnb_id), msg_p); + /* TODO XForms might need to be restarted, but it is currently (09/02/18) + * broken, so we cannot test it */ + wait_gNBs(); + init_RU_proc(ru); + ru->rf_map.card = 0; + ru->rf_map.chain = 0; /* CC_id + chain_offset;*/ + wait_RUs(); + init_eNB_afterRU(); + printf("Sending sync to all threads\n"); + pthread_mutex_lock(&sync_mutex); + sync_var=0; + pthread_cond_broadcast(&sync_cond); + pthread_mutex_unlock(&sync_mutex); + return 0; +} +#endif + +static void wait_nfapi_init(char *thread_name) { + printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name); + pthread_mutex_lock( &nfapi_sync_mutex ); + + while (nfapi_sync_var<0) + pthread_cond_wait( &nfapi_sync_cond, &nfapi_sync_mutex ); + + pthread_mutex_unlock(&nfapi_sync_mutex); + printf( "NFAPI: got sync (%s)\n", thread_name); +} + +int main( int argc, char **argv ) { + int i; +#if defined (XFORMS) + //void *status; +#endif + int CC_id; + int ru_id; +#if defined (XFORMS) + int ret; +#endif + start_background_system(); + + ///static configuration for NR at the moment + if ( load_configmodule(argc,argv) == NULL) { + exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); + } + +#ifdef DEBUG_CONSOLE + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); +#endif + mode = normal_txrx; + memset(&openair0_cfg[0],0,sizeof(openair0_config_t)*MAX_CARDS); + memset(tx_max_power,0,sizeof(int)*MAX_NUM_CCs); + configure_linux(); + logInit(); + printf("Reading in command-line options\n"); + get_options (); + + if (CONFIG_ISFLAGSET(CONFIG_ABORT) ) { + fprintf(stderr,"Getting configuration failed\n"); + exit(-1); + } + +#if T_TRACER + T_Config_Init(); +#endif + //randominit (0); + set_taus_seed (0); + printf("configuring for RAU/RRU\n"); + + if (opp_enabled ==1) { + reset_opp_meas(); + } + + cpuf=get_cpu_freq_GHz(); +#if defined(ENABLE_ITTI) + itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); + // initialize mscgen log after ITTI + MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); +#endif + + if (opt_type != OPT_NONE) { + if (init_opt(in_path, in_ip) == -1) + LOG_E(OPT,"failed to run OPT \n"); + } + +#ifdef PDCP_USE_NETLINK + netlink_init(); +#if defined(PDCP_USE_NETLINK_QUEUES) + pdcp_netlink_init(); +#endif +#endif +#if !defined(ENABLE_ITTI) + // to make a graceful exit when ctrl-c is pressed + signal(SIGSEGV, signal_handler); + signal(SIGINT, signal_handler); +#endif +#ifndef PACKAGE_VERSION +# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL" +#endif + LOG_I(HW, "Version: %s\n", PACKAGE_VERSION); +#if defined(ENABLE_ITTI) + + if (RC.nb_nr_inst > 0) { + // don't create if node doesn't connect to RRC/S1/GTP + AssertFatal(create_gNB_tasks(1) == 0,"cannot create ITTI tasks\n"); + } else { + printf("No ITTI, Initializing L1\n"); + RCconfig_L1(); + } + +#endif + /* Start the agent. If it is turned off in the configuration, it won't start */ + RCconfig_nr_flexran(); + + for (i = 0; i < RC.nb_nr_L1_inst; i++) { + flexran_agent_start(i); + } + + // init UE_PF_PO and mutex lock + pthread_mutex_init(&ue_pf_po_mutex, NULL); + memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); + mlockall(MCL_CURRENT | MCL_FUTURE); + pthread_cond_init(&sync_cond,NULL); + pthread_mutex_init(&sync_mutex, NULL); +#ifdef XFORMS + int UE_id; + + if (do_forms==1) { + fl_initialize (&argc, argv, NULL, 0, 0); + form_stats_l2 = create_form_stats_form(); + fl_show_form (form_stats_l2->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "l2 stats"); + form_stats = create_form_stats_form(); + fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); + + for(UE_id=0; UE_idlte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); + + if (otg_enabled) { + fl_set_button(form_enb[CC_id][UE_id]->button_0,1); + fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic ON"); + } else { + fl_set_button(form_enb[CC_id][UE_id]->button_0,0); + fl_set_object_label(form_enb[CC_id][UE_id]->button_0,"DL Traffic OFF"); + } + } // CC_id + } // UE_id + + ret = threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); + + if (ret == 0) + pthread_setname_np( forms_thread, "xforms" ); + + printf("Scope thread created, ret=%d\n",ret); + } + +#endif + usleep(10*1000); + + if (nfapi_mode) { + printf("NFAPI*** - mutex and cond created - will block shortly for completion of PNF connection\n"); + pthread_cond_init(&sync_cond,NULL); + pthread_mutex_init(&sync_mutex, NULL); + } + + const char *nfapi_mode_str = ""; + + switch(nfapi_mode) { + case 0: + nfapi_mode_str = "MONOLITHIC"; + break; + + case 1: + nfapi_mode_str = "PNF"; + break; + + case 2: + nfapi_mode_str = "VNF"; + break; + + default: + nfapi_mode_str = ""; + break; + } + + printf("NFAPI MODE:%s\n", nfapi_mode_str); + + if (nfapi_mode==2) // VNF + wait_nfapi_init("main?"); + + printf("START MAIN THREADS\n"); + // start the main threads + number_of_cards = 1; + printf("RC.nb_nr_L1_inst:%d\n", RC.nb_nr_L1_inst); + + if (RC.nb_nr_L1_inst > 0) { + printf("Initializing gNB threads single_thread_flag:%d wait_for_sync:%d\n", single_thread_flag,wait_for_sync); + init_gNB(single_thread_flag,wait_for_sync); + } + + printf("wait_gNBs()\n"); + wait_gNBs(); + printf("About to Init RU threads RC.nb_RU:%d\n", RC.nb_RU); + + if (RC.nb_RU >0) { + printf("Initializing RU threads\n"); + init_RU(rf_config_file); + + for (ru_id=0; ru_idrf_map.card=0; + RC.ru[ru_id]->rf_map.chain=CC_id+chain_offset; + } + } + + config_sync_var=0; + + if (nfapi_mode==1) { // PNF + wait_nfapi_init("main?"); + } + + printf("wait RUs\n"); + wait_RUs(); + printf("ALL RUs READY!\n"); + printf("RC.nb_RU:%d\n", RC.nb_RU); + // once all RUs are ready initialize the rest of the gNBs ((dependence on final RU parameters after configuration) + printf("ALL RUs ready - init gNBs\n"); + + if (nfapi_mode != 1 && nfapi_mode != 2) { + printf("Not NFAPI mode - call init_eNB_afterRU()\n"); + init_eNB_afterRU(); + } else { + printf("NFAPI mode - DO NOT call init_gNB_afterRU()\n"); + } + + printf("ALL RUs ready - ALL gNBs ready\n"); + // connect the TX/RX buffers + printf("Sending sync to all threads\n"); + pthread_mutex_lock(&sync_mutex); + sync_var=0; + pthread_cond_broadcast(&sync_cond); + pthread_mutex_unlock(&sync_mutex); + printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__); + end_configmodule(); + printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__); + // wait for end of program + printf("TYPE TO TERMINATE\n"); + //getchar(); +#if defined(ENABLE_ITTI) + printf("Entering ITTI signals handler\n"); + itti_wait_tasks_end(); + printf("Returned from ITTI signal handler\n"); + oai_exit=1; + printf("oai_exit=%d\n",oai_exit); +#else + + while (oai_exit==0) + sleep(1); + + printf("Terminating application - oai_exit=%d\n",oai_exit); +#endif + // stop threads +#ifdef XFORMS + /* + printf("waiting for XFORMS thread\n"); + + if (do_forms==1) { + pthread_join(forms_thread,&status); + fl_hide_form(form_stats->stats_form); + fl_free_form(form_stats->stats_form); + + fl_hide_form(form_stats_l2->stats_form); + fl_free_form(form_stats_l2->stats_form); + + for(UE_id=0; UE_idlte_phy_scope_enb); + fl_free_form(form_enb[CC_id][UE_id]->lte_phy_scope_enb); + } + } + } + */ +#endif + printf("stopping MODEM threads\n"); + // cleanup + stop_gNB(NB_gNB_INST); + stop_RU(NB_RU); + + /* release memory used by the RU/gNB threads (incomplete), after all + * threads have been stopped (they partially use the same memory) */ + for (int inst = 0; inst < NB_gNB_INST; inst++) { + for (int cc_id = 0; cc_id < RC.nb_nr_CC[inst]; cc_id++) { + //free_transport(RC.gNB[inst][cc_id]); + phy_free_nr_gNB(RC.gNB[inst][cc_id]); + } + } + + for (int inst = 0; inst < NB_RU; inst++) { + nr_phy_free_RU(RC.ru[inst]); + } + + free_lte_top(); + pthread_cond_destroy(&sync_cond); + pthread_mutex_destroy(&sync_mutex); + pthread_cond_destroy(&nfapi_sync_cond); + pthread_mutex_destroy(&nfapi_sync_mutex); + pthread_mutex_destroy(&ue_pf_po_mutex); + + // *** Handle per CC_id openair0 + + for(ru_id=0; ru_idrfdevice.trx_end_func) + RC.ru[ru_id]->rfdevice.trx_end_func(&RC.ru[ru_id]->rfdevice); + + if (RC.ru[ru_id]->ifdevice.trx_end_func) + RC.ru[ru_id]->ifdevice.trx_end_func(&RC.ru[ru_id]->ifdevice); + } + + if (opt_enabled == 1) + terminate_opt(); + + logClean(); + printf("Bye.\n"); + return 0; +} diff --git a/executables/nr-softmodem.h b/executables/nr-softmodem.h new file mode 100644 index 0000000000..49e079ae13 --- /dev/null +++ b/executables/nr-softmodem.h @@ -0,0 +1,251 @@ +#ifndef NR_SOFTMODEM_H +#define NR_SOFTMODEM_H + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "targets/ARCH/COMMON/common_lib.h" +#undef MALLOC +#include "assertions.h" +#include "msc.h" +#include "PHY/types.h" + +#include "flexran_agent.h" +#include "PHY/defs_gNB.h" + +#if defined(ENABLE_ITTI) + #if defined(ENABLE_USE_MME) + #include "s1ap_eNB.h" + #ifdef PDCP_USE_NETLINK + #include "SIMULATION/ETH_TRANSPORT/proto.h" + #endif + #endif +#endif + +/* help strings definition for command line options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ +#define CONFIG_HLP_RFCFGF "Configuration file for front-end (e.g. LMS7002M)\n" +#define CONFIG_HLP_ULMAXE "set the eNodeB max ULSCH erros\n" +#define CONFIG_HLP_CALUER "set UE RX calibration\n" +#define CONFIG_HLP_CALUERM "" +#define CONFIG_HLP_CALUERB "" +#define CONFIG_HLP_DBGUEPR "UE run normal prach power ramping, but don't continue random-access\n" +#define CONFIG_HLP_CALPRACH "UE run normal prach with maximum power, but don't continue random-access\n" +#define CONFIG_HLP_NOL2CN "bypass L2 and upper layers\n" +#define CONFIG_HLP_UERXG "set UE RX gain\n" +#define CONFIG_HLP_UERXGOFF "external UE amplifier offset\n" +#define CONFIG_HLP_UETXG "set UE TX gain\n" +#define CONFIG_HLP_UENANTR "set UE number of rx antennas\n" +#define CONFIG_HLP_UENANTT "set UE number of tx antennas\n" +#define CONFIG_HLP_UESCAN "set UE to scan around carrier\n" +#define CONFIG_HLP_DUMPFRAME "dump UE received frame to rxsig_frame0.dat and exit\n" +#define CONFIG_HLP_DLSHIFT "dynamic shift for LLR compuation for TM3/4 (default 0)\n" +#define CONFIG_HLP_UELOOP "get softmodem (UE) to loop through memory instead of acquiring from HW\n" +#define CONFIG_HLP_PHYTST "test UE phy layer, mac disabled\n" +#define CONFIG_HLP_DMAMAP "sets flag for improved EXMIMO UE performance\n" +#define CONFIG_HLP_EXCCLK "tells hardware to use an external clock reference\n" +#define CONFIG_HLP_USIM "use XOR autentication algo in case of test usim mode\n" +#define CONFIG_HLP_NOSNGLT "Disables single-thread mode in lte-softmodem\n" +#define CONFIG_HLP_TADV "Set timing_advance\n" +#define CONFIG_HLP_DLF "Set the downlink frequency for all component carriers\n" +#define CONFIG_HLP_CHOFF "Channel id offset\n" +#define CONFIG_HLP_SOFTS "Enable soft scope and L1 and L2 stats (Xforms)\n" +#define CONFIG_HLP_EXMCAL "Calibrate the EXMIMO borad, available files: exmimo2_2arxg.lime exmimo2_2brxg.lime \n" +#define CONFIG_HLP_ITTIL "Generate ITTI analyzser logs (similar to wireshark logs but with more details)\n" +#define CONFIG_HLP_DLMCS "Set the maximum downlink MCS\n" +#define CONFIG_HLP_STMON "Enable processing timing measurement of lte softmodem on per subframe basis \n" +#define CONFIG_HLP_PRB "Set the PRB, valid values: 6, 25, 50, 100 \n" +#define CONFIG_HLP_MSLOTS "Skip the missed slots/subframes \n" +#define CONFIG_HLP_ULMCS "Set the maximum uplink MCS\n" +#define CONFIG_HLP_TDD "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n" +#define CONFIG_HLP_UE "Set the lte softmodem as a UE\n" +#define CONFIG_HLP_L2MONW "Enable L2 wireshark messages on localhost \n" +#define CONFIG_HLP_L2MONP "Enable L2 pcap messages on localhost \n" +#define CONFIG_HLP_VCD "Enable VCD (generated file will is named openair_dump_eNB.vcd, read it with target/RT/USER/eNB.gtkw\n" +#define CONFIG_HLP_TQFS "Apply three-quarter of sampling frequency, 23.04 Msps to reduce the data rate on USB/PCIe transfers (only valid for 20 MHz)\n" +#define CONFIG_HLP_TPORT "tracer port\n" +#define CONFIG_HLP_NOTWAIT "don't wait for tracer, start immediately\n" +#define CONFIG_HLP_TNOFORK "to ease debugging with gdb\n" +#define CONFIG_HLP_DISABLNBIOT "disable nb-iot, even if defined in config\n" + +#define CONFIG_HLP_NUMEROLOGY "adding numerology for 5G\n" +#define CONFIG_HLP_EMULATE_RF "Emulated RF enabled(disable by defult)\n" +#define CONFIG_HLP_PARALLEL_CMD "three config for level of parallelism 'PARALLEL_SINGLE_THREAD', 'PARALLEL_RU_L1_SPLIT', or 'PARALLEL_RU_L1_TRX_SPLIT'\n" +#define CONFIG_HLP_WORKER_CMD "two option for worker 'WORKER_DISABLE' or 'WORKER_ENABLE'\n" + +/***************************************************************************************************************************************/ +/* command line options definitions, CMDLINE_XXXX_DESC macros are used to initialize paramdef_t arrays which are then used as argument + when calling config_get or config_getlist functions */ + + +/*------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters defining UE running mode */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_UEMODEPARAMS_DESC { \ + {"calib-ue-rx", CONFIG_HLP_CALUER, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"calib-ue-rx-med", CONFIG_HLP_CALUERM, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"calib-ue-rx-byp", CONFIG_HLP_CALUERB, 0, iptr:&rx_input_level_dBm, defintval:0, TYPE_INT, 0}, \ + {"debug-ue-prach", CONFIG_HLP_DBGUEPR, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"no-L2-connect", CONFIG_HLP_NOL2CN, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"calib-prach-tx", CONFIG_HLP_CALPRACH, PARAMFLAG_BOOL, uptr:NULL, defuintval:1, TYPE_INT, 0}, \ + {"loop-memory", CONFIG_HLP_UELOOP, 0, strptr:&loopfile, defstrval:"iqs.in", TYPE_STRING,0}, \ + {"ue-dump-frame", CONFIG_HLP_DUMPFRAME, PARAMFLAG_BOOL, iptr:&dumpframe, defintval:0, TYPE_INT, 0}, \ + } +#define CMDLINE_CALIBUERX_IDX 0 +#define CMDLINE_CALIBUERXMED_IDX 1 +#define CMDLINE_CALIBUERXBYP_IDX 2 +#define CMDLINE_DEBUGUEPRACH_IDX 3 +#define CMDLINE_NOL2CONNECT_IDX 4 +#define CMDLINE_CALIBPRACHTX_IDX 5 +#define CMDLINE_MEMLOOP_IDX 6 +#define CMDLINE_DUMPMEMORY_IDX 7 +/*------------------------------------------------------------------------------------------------------------------------------------------*/ + + +/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters specific to UE */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*--------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_UEPARAMS_DESC { \ + {"ue-rxgain", CONFIG_HLP_UERXG, 0, dblptr:&(rx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-rxgain-off", CONFIG_HLP_UERXGOFF, 0, dblptr:&rx_gain_off, defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-txgain", CONFIG_HLP_UETXG, 0, dblptr:&(tx_gain[0][0]), defdblval:0, TYPE_DOUBLE, 0}, \ + {"ue-nb-ant-rx", CONFIG_HLP_UENANTR, 0, u8ptr:&nb_antenna_rx, defuintval:1, TYPE_UINT8, 0}, \ + {"ue-nb-ant-tx", CONFIG_HLP_UENANTT, 0, u8ptr:&nb_antenna_tx, defuintval:1, TYPE_UINT8, 0}, \ + {"ue-scan-carrier", CONFIG_HLP_UESCAN, PARAMFLAG_BOOL, iptr:&UE_scan_carrier, defintval:0, TYPE_INT, 0}, \ + {"ue-max-power", NULL, 0, iptr:&(tx_max_power[0]), defintval:90, TYPE_INT, 0}, \ + {"r" , CONFIG_HLP_PRB, 0, u8ptr:&(frame_parms[0]->N_RB_DL), defintval:25, TYPE_UINT8, 0}, \ + {"dlsch-demod-shift", CONFIG_HLP_DLSHIFT, 0, iptr:(int32_t *)&dlsch_demod_shift, defintval:0, TYPE_INT, 0}, \ + } + +#define DEFAULT_DLF 2680000000 + +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters common to eNodeB and UE */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_PARAMS_DESC { \ + {"rf-config-file", CONFIG_HLP_RFCFGF, 0, strptr:(char **)&rf_config_file, defstrval:NULL, TYPE_STRING, sizeof(rf_config_file)}, \ + {"ulsch-max-errors", CONFIG_HLP_ULMAXE, 0, uptr:&ULSCH_max_consecutive_errors, defuintval:0, TYPE_UINT, 0}, \ + {"phy-test", CONFIG_HLP_PHYTST, PARAMFLAG_BOOL, iptr:&phy_test, defintval:0, TYPE_INT, 0}, \ + {"usim-test", CONFIG_HLP_USIM, PARAMFLAG_BOOL, u8ptr:&usim_test, defintval:0, TYPE_UINT8, 0}, \ + {"mmapped-dma", CONFIG_HLP_DMAMAP, PARAMFLAG_BOOL, uptr:&mmapped_dma, defintval:0, TYPE_INT, 0}, \ + {"external-clock", CONFIG_HLP_EXCCLK, PARAMFLAG_BOOL, uptr:&clock_source, defintval:0, TYPE_INT, 0}, \ + {"wait-for-sync", NULL, PARAMFLAG_BOOL, iptr:&wait_for_sync, defintval:0, TYPE_INT, 0}, \ + {"single-thread-disable", CONFIG_HLP_NOSNGLT, PARAMFLAG_BOOL, iptr:&single_thread_flag, defintval:1, TYPE_INT, 0}, \ + {"A" , CONFIG_HLP_TADV, 0, uptr:&timing_advance, defintval:0, TYPE_UINT, 0}, \ + {"C" , CONFIG_HLP_DLF, 0, uptr:&(downlink_frequency[0][0]), defuintval:DEFAULT_DLF, TYPE_UINT, 0}, \ + {"a" , CONFIG_HLP_CHOFF, 0, iptr:&chain_offset, defintval:0, TYPE_INT, 0}, \ + {"d" , CONFIG_HLP_SOFTS, PARAMFLAG_BOOL, uptr:(uint32_t *)&do_forms, defintval:0, TYPE_INT8, 0}, \ + {"E" , CONFIG_HLP_TQFS, PARAMFLAG_BOOL, i8ptr:&threequarter_fs, defintval:0, TYPE_INT8, 0}, \ + {"K" , CONFIG_HLP_ITTIL, PARAMFLAG_NOFREE, strptr:&itti_dump_file, defstrval:"/tmp/itti.dump", TYPE_STRING, 0}, \ + {"m" , CONFIG_HLP_DLMCS, 0, uptr:&target_dl_mcs, defintval:0, TYPE_UINT, 0}, \ + {"t" , CONFIG_HLP_ULMCS, 0, uptr:&target_ul_mcs, defintval:0, TYPE_UINT, 0}, \ + {"W" , CONFIG_HLP_L2MONW, 0, strptr:(char **)&in_ip, defstrval:"127.0.0.1", TYPE_STRING, sizeof(in_ip)}, \ + {"P" , CONFIG_HLP_L2MONP, 0, strptr:(char **)&in_path, defstrval:"/tmp/oai_opt.pcap", TYPE_STRING, sizeof(in_path)}, \ + {"q" , CONFIG_HLP_STMON, PARAMFLAG_BOOL, iptr:&opp_enabled, defintval:0, TYPE_INT, 0}, \ + {"S" , CONFIG_HLP_MSLOTS, PARAMFLAG_BOOL, u8ptr:&exit_missed_slots, defintval:1, TYPE_UINT8, 0}, \ + {"T" , CONFIG_HLP_TDD, PARAMFLAG_BOOL, iptr:&tddflag, defintval:0, TYPE_INT, 0}, {"numerology" , CONFIG_HLP_NUMEROLOGY, PARAMFLAG_BOOL, iptr:&numerology, defintval:0, TYPE_INT, 0}, \ + {"emulate-rf" , CONFIG_HLP_EMULATE_RF, PARAMFLAG_BOOL, iptr:&emulate_rf, defintval:0, TYPE_INT, 0}, \ + {"parallel-config", CONFIG_HLP_PARALLEL_CMD,0, strptr:(char **)¶llel_config, defstrval:NULL, TYPE_STRING, 0}, \ + {"worker-config", CONFIG_HLP_WORKER_CMD, 0, strptr:(char **)&worker_config, defstrval:NULL, TYPE_STRING, 0}, \ + {"nbiot-disable", CONFIG_HLP_DISABLNBIOT,PARAMFLAG_BOOL, iptr:&nonbiotflag, defintval:0, TYPE_INT, 0} \ + } + +#define CONFIG_HLP_FLOG "Enable online log \n" +#define CONFIG_HLP_LOGL "Set the global log level, valide options: (9:trace, 8/7:debug, 6:info, 4:warn, 3:error)\n" +#define CONFIG_HLP_LOGV "Set the global log verbosity \n" +#define CONFIG_HLP_TELN "Start embedded telnet server \n" +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* command line parameters for LOG utility */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ +#define CMDLINE_LOGPARAMS_DESC { \ + {"R" , CONFIG_HLP_FLOG, 0, uptr:&online_log_messages, defintval:1, TYPE_INT, 0}, \ + {"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ + {"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \ + {"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ + } +#define CMDLINE_ONLINELOG_IDX 0 +#define CMDLINE_GLOGLEVEL_IDX 1 +#define CMDLINE_GLOGVERBO_IDX 2 +#define CMDLINE_STARTTELN_IDX 3 + + +extern int T_port; +extern int T_nowait; +extern int T_dont_fork; + + +/***************************************************************************************************************************************/ +/* */ +extern pthread_cond_t sync_cond; +extern pthread_mutex_t sync_mutex; +extern int sync_var; + + +extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; +extern int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; + +extern int rx_input_level_dBm; +extern uint8_t exit_missed_slots; +extern uint64_t num_missed_slots; // counter for the number of missed slots + +extern int oaisim_flag; +extern volatile int oai_exit; + +extern openair0_config_t openair0_cfg[MAX_CARDS]; +extern pthread_cond_t sync_cond; +extern pthread_mutex_t sync_mutex; +extern int sync_var; +extern int transmission_mode; +extern double cpuf; + +#if defined(ENABLE_ITTI) + extern volatile int start_gNB; +#endif + +#include "threads_t.h" +extern threads_t threads; + +// In nr-gnb.c +extern void init_gNB(int single_thread_flag,int wait_for_sync); +extern void stop_gNB(int); +extern void kill_gNB_proc(int inst); + +// In nr-ru.c +extern void init_RU(const char *); +extern void init_RU_proc(RU_t *ru); +extern void stop_RU(int nb_ru); +extern void kill_RU_proc(int inst); +extern void set_function_spec_param(RU_t *ru); + +extern void reset_opp_meas(void); +extern void print_opp_meas(void); + +extern void init_fep_thread(PHY_VARS_gNB *, pthread_attr_t *); + +void init_gNB_afterRU(void); + +extern int stop_L1L2(module_id_t gnb_id); +extern int restart_L1L2(module_id_t gnb_id); + +#endif + diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 7c96f14159..21b1edd617 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -43,6 +43,7 @@ #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "common/utils/LOG/log.h" +#include "common/utils/system.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "T.h" @@ -123,35 +124,6 @@ extern double cpuf; #define FRAME_PERIOD 100000000ULL #define DAQ_PERIOD 66667ULL -#define FIFO_PRIORITY 40 - - -void init_thread(int core, char *name) { - pthread_setname_np(pthread_self(),name); - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - if (core >0) - CPU_SET(core, &cpuset); - - AssertFatal( 0 == pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset), ""); - struct sched_param sp; - sp.sched_priority = FIFO_PRIORITY; - AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO,&sp)==0, - "Can't set thread priority, Are you root?\n"); - /* Check the actual affinity mask assigned to the thread */ - cpu_set_t *cset=CPU_ALLOC(CPU_SETSIZE); - - if (0 == pthread_getaffinity_np(pthread_self(), CPU_ALLOC_SIZE(CPU_SETSIZE), cset)) { - char txt[512]= {0}; - - for (int j = 0; j < CPU_SETSIZE; j++) - if (CPU_ISSET(j, cset)) - sprintf(txt+strlen(txt), " %d ", j); - - printf("CPU Affinity of thread %s is %s\n", name, txt); - } -} typedef enum { pss=0, @@ -403,7 +375,9 @@ void processSubframeRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { #ifdef UE_SLOT_PARALLELISATION phy_procedures_slot_parallelization_nrUE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL ); #else + uint64_t a=rdtsc(); phy_procedures_nrUE_RX( UE, proc, 0, 1, UE->mode); + printf("phy_procedures_nrUE_RX: slot:%d, time %lu\n", proc->nr_tti_rx, (rdtsc()-a)/3500); // printf(">>> nr_ue_pdcch_procedures ended\n"); #endif } @@ -563,7 +537,8 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) { } void *UE_thread(void *arg) { - init_thread(1, "IQ samples"); + //this thread should be over the processing thread to keep in real time + threadTopInit("UE_IQ",1,OAI_PRIORITY_RT_MAX); PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; // int tx_enabled = 0; openair0_timestamp timestamp; @@ -770,10 +745,7 @@ void init_UE(int nb_inst) { pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - pthread_attr_setschedpolicy(&attr, SCHED_RR); - struct sched_param sched; - sched.sched_priority = sched_get_priority_max(SCHED_RR)-1; - pthread_attr_setschedparam(&attr, &sched); + pthread_attr_setschedpolicy(&attr, SCHED_FIFO); for (inst=0; inst < nb_inst; inst++) { PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; @@ -794,10 +766,7 @@ void init_UE(int nb_inst) { mac_inst->initial_bwp_ul.N_RB = UE->frame_parms.N_RB_UL; mac_inst->initial_bwp_ul.cyclic_prefix = UE->frame_parms.Ncp; LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); - AssertFatal(0 == pthread_create(&threads[inst], - &attr, - UE_thread, - (void *)UE), ""); + threadCreate(&threads[inst], UE_thread, (void *)UE), "UEthread", -1, OAI_PRIORITY_RT); } printf("UE threads created by %ld\n", gettid()); diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 0a2f0ac2d5..babf169103 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -64,7 +64,6 @@ unsigned short config_frames[4] = {2,9,11,13}; #endif #include "intertask_interface.h" -#include "create_tasks.h" #include "PHY/INIT/phy_init.h" #include "system.h" @@ -311,11 +310,6 @@ void reset_stats(FL_OBJECT *button, long arg) { } static void *scope_thread(void *arg) { - struct sched_param sched_param; - sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO)+1; - sched_setscheduler(0, SCHED_FIFO,&sched_param); - printf("Scope thread has priority %d\n",sched_param.sched_priority); - //wait the modem is runnign sleep(5); while (!oai_exit) { @@ -343,12 +337,7 @@ void init_scope(void) { fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); fl_set_button(form_ue[UE_id]->button_0,0); fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); - ret = pthread_create(&forms_thread, NULL, scope_thread, NULL); - - if (ret == 0) - pthread_setname_np( forms_thread, "xforms" ); - - printf("Scope thread created, ret=%d\n",ret); + threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); } #endif @@ -763,6 +752,7 @@ int main( int argc, char **argv ) { // init UE_PF_PO and mutex lock pthread_mutex_init(&ue_pf_po_mutex, NULL); memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); + configure_linux(); mlockall(MCL_CURRENT | MCL_FUTURE); init_scope(); number_of_cards = 1; diff --git a/executables/openairinterface5g_limits.h b/executables/openairinterface5g_limits.h new file mode 100644 index 0000000000..53ee79a61d --- /dev/null +++ b/executables/openairinterface5g_limits.h @@ -0,0 +1,89 @@ +#ifndef OPENAIRINTERFACE5G_LIMITS_H_ +#define OPENAIRINTERFACE5G_LIMITS_H_ + +#if 1 /*defined(CBMIMO1) || defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_LMSSDR) || defined(OAI_ADRV9371_ZC706)*/ + #define NUMBER_OF_eNB_MAX 1 + #define NUMBER_OF_gNB_MAX 1 + #define NUMBER_OF_RU_MAX 2 + #define NUMBER_OF_NR_RU_MAX 2 + #ifndef PHYSIM + #ifndef UE_EXPANSION + #define NUMBER_OF_UE_MAX 16 + #define NUMBER_OF_NR_UE_MAX 16 + #define NUMBER_OF_CONNECTED_eNB_MAX 3 + #define NUMBER_OF_CONNECTED_gNB_MAX 3 + #else + #define NUMBER_OF_UE_MAX 256 + #define NUMBER_OF_NR_UE_MAX 256 + #define NUMBER_OF_CONNECTED_eNB_MAX 1 + #define NUMBER_OF_CONNECTED_gNB_MAX 1 + #endif + #else + #define NUMBER_OF_UE_MAX 1 + #define NUMBER_OF_NR_UE_MAX 1 + #define NUMBER_OF_CONNECTED_eNB_MAX 1 + #define NUMBER_OF_CONNECTED_gNB_MAX 1 + #endif +#else + #define NUMBER_OF_eNB_MAX 7 + #define NUMBER_OF_gNB_MAX 7 + #define NUMBER_OF_RU_MAX 32 + #define NUMBER_OF_NR_RU_MAX 32 + #ifndef UE_EXPANSION + #define NUMBER_OF_UE_MAX 20 + #define NUMBER_OF_NR_UE_MAX 20 + #define NUMBER_OF_CONNECTED_eNB_MAX 3 + #define NUMBER_OF_CONNECTED_gNB_MAX 3 + #else + #define NUMBER_OF_UE_MAX 256 + #define NUMBER_OF_NR_UE_MAX 256 + #define NUMBER_OF_CONNECTED_eNB_MAX 1 + #define NUMBER_OF_CONNECTED_gNB_MAX 1 + #endif + #if defined(STANDALONE) && STANDALONE==1 + #undef NUMBER_OF_eNB_MAX + #undef NUMBER_OF_gNB_MAX + + #undef NUMBER_OF_UE_MAX + #undef NUMBER_OF_NR_UE_MAX + + #undef NUMBER_OF_RU_MAX + #undef NUMBER_OF_NR_RU_MAX + + #define NUMBER_OF_eNB_MAX 3 + #define NUMBER_OF_gNB_MAX 3 + + #define NUMBER_OF_UE_MAX 3 + #define NUMBER_OF_NR_UE_MAX 3 + + #define NUMBER_OF_RU_MAX 3 + #define NUMBER_OF_NR_RU_MAX 3 + #endif + #if defined(LARGE_SCALE) && LARGE_SCALE + #undef NUMBER_OF_eNB_MAX + #undef NUMBER_OF_gNB_MAX + + #undef NUMBER_OF_UE_MAX + #undef NUMBER_OF_NR_UE_MAX + + #undef NUMBER_OF_CONNECTED_eNB_MAX + #undef NUMBER_OF_CONNECTED_gNB_MAX + + #undef NUMBER_OF_RU_MAX + #undef NUMBER_OF_NR_RU_MAX + + #define NUMBER_OF_eNB_MAX 2 + #define NUMBER_OF_gNB_MAX 2 + + #define NUMBER_OF_UE_MAX 120 + #define NUMBER_OF_NR_UE_MAX 120 + + #define NUMBER_OF_RU_MAX 16 + #define NUMBER_OF_NR_RU_MAX 16 + + #define NUMBER_OF_CONNECTED_eNB_MAX 1 // to save some memory + #define NUMBER_OF_CONNECTED_gNB_MAX 1 + #endif +#endif + +#endif /* OPENAIRINTERFACE5G_LIMITS_H_ */ diff --git a/executables/stats.c b/executables/stats.c new file mode 100644 index 0000000000..63cadc8ae6 --- /dev/null +++ b/executables/stats.c @@ -0,0 +1,50 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/* Form definition file generated by fdesign */ + +#include +#include "stats.h" + + +/*************************************** + ***************************************/ + +FD_stats_form * +create_form_stats_form( void ) { + FL_OBJECT *obj; + FD_stats_form *fdui = fl_malloc( sizeof *fdui ); + fdui->vdata = fdui->cdata = NULL; + fdui->ldata = 0; + fdui->stats_form = fl_bgn_form( FL_NO_BOX, 1115, 900 ); + obj = fl_add_box( FL_UP_BOX, 0, 0, 1115, 900, "" ); + //fdui->stats_text = obj = fl_add_text( FL_NORMAL_TEXT, 60, 50, 1000, 810, "test" ); + //fl_set_object_lsize( obj, FL_TINY_SIZE ); + fdui->stats_text = obj = fl_add_browser( FL_NORMAL_BROWSER, 60, 50, 1000, 810, "test" ); + fl_set_browser_fontsize(obj,FL_TINY_SIZE); + fdui->stats_button = obj = fl_add_button( FL_PUSH_BUTTON, 60, 10, 130, 30, "Reset Stats" ); + fl_set_object_lalign( obj, FL_ALIGN_CENTER ); + fl_set_object_color( obj, FL_GREEN, FL_GREEN); + fl_set_object_callback( obj, reset_stats, 0 ); + fl_end_form( ); + fdui->stats_form->fdui = fdui; + return fdui; +} diff --git a/executables/stats.h b/executables/stats.h new file mode 100644 index 0000000000..6c847a2860 --- /dev/null +++ b/executables/stats.h @@ -0,0 +1,46 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/* Header file generated by fdesign on Thu Aug 28 12:13:51 2014 */ + +#ifndef FD_stats_form_h_ +#define FD_stats_form_h_ + +#include + +/* Callbacks, globals and object handlers */ + +extern void reset_stats( FL_OBJECT *, long ); + +/* Forms and Objects */ + +typedef struct { + FL_FORM *stats_form; + void *vdata; + char *cdata; + long ldata; + FL_OBJECT *stats_text; + FL_OBJECT *stats_button; +} FD_stats_form; + +extern FD_stats_form *create_form_stats_form( void ); + +#endif /* FD_stats_form_h_ */ diff --git a/executables/threads_t.h b/executables/threads_t.h new file mode 100644 index 0000000000..0671f40988 --- /dev/null +++ b/executables/threads_t.h @@ -0,0 +1,21 @@ +#ifndef _THREADS_T_H_ +#define _THREADS_T_H_ + +typedef struct threads_s { + int main; + int sync; + int one; + int two; + int three; + int slot1_proc_one; + int slot1_proc_two; + int slot1_proc_three; + //int dlsch_td_one; + //int dlsch_td_two; + //int dlsch_td_three; + //int dlsch_td1_one; + //int dlsch_td1_two; + //int dlsch_td1_three; +} threads_t; + +#endif /* _THREADS_T_H_ */ diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c index e4bec93ddf..14d8958811 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c +++ b/openair1/PHY/NR_TRANSPORT/nr_dci_tools.c @@ -64,7 +64,7 @@ void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m } if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) { - AssertFatal((N_reg%(bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n", + AssertFatal((N_reg % (bsize*R))==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %us, bsize %d R %d)\n", N_reg, bsize, R); C = N_reg/(bsize*R); } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index c99d2ea61b..6c4fc3db10 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -84,6 +84,20 @@ unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{ extern void print_shorts(char *s,int16_t *x); +static void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, + int **dl_ch_estimates_ext_i, + int **dl_ch_rho_ext, + unsigned char n_tx, + unsigned char n_rx, + unsigned char output_shift, + int length, + int start_point); + +static void nr_dlsch_layer_demapping(int16_t **llr_cw, + uint8_t Nl, + uint8_t mod_order, + uint16_t length, + int16_t **llr_layers); int nr_rx_pdsch(PHY_VARS_NR_UE *ue, PDSCH_t type, @@ -112,7 +126,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, uint8_t slot = 0; #endif - unsigned char aatx,aarx; + unsigned char aatx=0,aarx=0; unsigned short nb_rb = 0, nb_re =0, round; int avgs = 0;// rb; @@ -1120,6 +1134,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, nr_dlsch_layer_demapping(pdsch_vars[eNB_id]->llr, dlsch[0]->harq_processes[harq_pid]->Nl, dlsch[0]->harq_processes[harq_pid]->G, + -1, pdsch_vars[eNB_id]->layer_llr); } @@ -2179,7 +2194,7 @@ void nr_dlsch_channel_level_median(int **dl_ch_estimates_ext, } -void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, +static void nr_dlsch_dual_stream_correlation_core(int **dl_ch_estimates_ext, int **dl_ch_estimates_ext_i, int **dl_ch_rho_ext, unsigned char n_tx, @@ -2287,7 +2302,7 @@ void nr_dlsch_detection_mrc_core(int **rxdataF_comp, __m128i *rxdataF_comp128_0, *rxdataF_comp128_1, *rxdataF_comp128_2, *rxdataF_comp128_3; __m128i *dl_ch_mag128_0, *dl_ch_mag128_1, *dl_ch_mag128_2, *dl_ch_mag128_3; __m128i *dl_ch_mag128_0b, *dl_ch_mag128_1b, *dl_ch_mag128_2b, *dl_ch_mag128_3b; - __m128i *rho128_0, *rho128_1, *rho128_2, *rho128_3; + __m128i *rho128_0, *rho128_1, *rho128_2=NULL, *rho128_3=NULL; __m128i *rho128_i0, *rho128_i1, *rho128_i2, *rho128_i3; int length_mod4 = 0; int length2; @@ -2592,9 +2607,9 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, //int prb_off,prb_off2; int skip_half=0,l;//sss_symb,pss_symb=0,nsymb int i,aarx; - int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; + int32_t *dl_ch0=NULL,*dl_ch0p=NULL,*dl_ch0_ext=NULL,*dl_ch1=NULL,*dl_ch1p=NULL,*dl_ch1_ext=NULL,*rxF=NULL,*rxF_ext=NULL; int symbol_mod,pilots=0,j=0; - unsigned char *pmi_loc; + unsigned char *pmi_loc=NULL; pilots = (symbol==2) ? 1 : 0; //to updated from config k = frame_parms->first_carrier_offset + 516; //0 @@ -2673,7 +2688,7 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, return(nb_rb/frame_parms->nb_antennas_rx); } -void nr_dlsch_layer_demapping(int16_t **llr_cw, +static void nr_dlsch_layer_demapping(int16_t **llr_cw, uint8_t Nl, uint8_t mod_order, uint16_t length, diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c index 65dfb64734..8a474d3644 100644 --- a/openair1/SCHED_NR/nr_ru_procedures.c +++ b/openair1/SCHED_NR/nr_ru_procedures.c @@ -205,7 +205,7 @@ void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx) { pthread_mutex_init( &proc->mutex_feptx, NULL); pthread_cond_init( &proc->cond_feptx, NULL); - pthread_create(&proc->pthread_feptx, attr_feptx, nr_feptx_thread, (void*)ru); + threadCreate(&proc->pthread_feptx, nr_feptx_thread, (void*)ru, "feptx", -1, OAI_PRIORITY_RT); } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index c83074d8a2..b5f19814f7 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2814,7 +2814,6 @@ void nr_ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t * //uint8_t pbch_phase; int ret = 0; uint16_t frame_tx; - static uint8_t first_run = 1; uint8_t pbch_trials = 0; DevAssert(ue); diff --git a/openair2/ENB_APP/RRC_config_tools.h b/openair2/ENB_APP/RRC_config_tools.h index a44da1f90c..488441ff59 100644 --- a/openair2/ENB_APP/RRC_config_tools.h +++ b/openair2/ENB_APP/RRC_config_tools.h @@ -30,7 +30,7 @@ #define RRC_CONFIG_TOOLS_H_ #define KHz (1000UL) -#define MHz (1000 * KHz) +#define MHz (1000*KHz) typedef struct eutra_band_s { int16_t band; diff --git a/openair2/ENB_APP/flexran_agent.c b/openair2/ENB_APP/flexran_agent.c index 9c0af82e90..2cf72c40ee 100644 --- a/openair2/ENB_APP/flexran_agent.c +++ b/openair2/ENB_APP/flexran_agent.c @@ -27,12 +27,12 @@ */ #include "flexran_agent.h" +#include #include void *send_thread(void *args); void *receive_thread(void *args); -pthread_t new_thread(void *(*f)(void *), void *b); Protocol__FlexranMessage *flexran_agent_timeout(void* args); @@ -102,6 +102,7 @@ void *flexran_agent_task(void *args){ } void *receive_thread(void *args) { + threadTopInit("flexran",-1,OAI_PRIORITY_RT_LOW); flexran_agent_info_t *d = args; void *data; @@ -145,38 +146,6 @@ error: } -/* utility function to create a thread */ -pthread_t new_thread(void *(*f)(void *), void *b) { - pthread_t t; - pthread_attr_t att; - - if (pthread_attr_init(&att)){ - fprintf(stderr, "pthread_attr_init err\n"); - exit(1); - } - - struct sched_param sched_param_recv_thread; - - sched_param_recv_thread.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; - pthread_attr_setschedparam(&att, &sched_param_recv_thread); - pthread_attr_setschedpolicy(&att, SCHED_FIFO); - - if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) { - fprintf(stderr, "pthread_attr_setdetachstate err\n"); - exit(1); - } - if (pthread_create(&t, &att, f, b)) { - fprintf(stderr, "pthread_create err\n"); - exit(1); - } - if (pthread_attr_destroy(&att)) { - fprintf(stderr, "pthread_attr_destroy err\n"); - exit(1); - } - - return t; -} - int channel_container_init = 0; int flexran_agent_start(mid_t mod_id) { @@ -227,8 +196,8 @@ int flexran_agent_start(mid_t mod_id) /*Initialize the continuous stats update mechanism*/ flexran_agent_init_cont_stats_update(mod_id); - - new_thread(receive_thread, flexran); + pthread_t t; + threadCreate(&t, receive_thread, flexran, "flexran", -1, OAI_PRIORITY_RT); /*Initialize and register the mac xface. Must be modified later *for more flexibility in agent management */ diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c index 0b6be93d59..c37d665fcc 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c @@ -101,33 +101,12 @@ static void *pdcp_thread_main(void* param) int init_pdcp_thread(void) { - int error_code; - struct sched_param p; - - pthread_attr_init (&pdcp_thread_attr); - pthread_attr_setstacksize(&pdcp_thread_attr,OPENAIR_THREAD_STACK_SIZE); - //attr_dlsch_threads.priority = 1; - - p.sched_priority = OPENAIR_THREAD_PRIORITY; - pthread_attr_setschedparam (&pdcp_thread_attr, &p); - pthread_attr_setschedpolicy (&pdcp_thread_attr, SCHED_FIFO); pthread_mutex_init(&pdcp_mutex,NULL); pthread_cond_init(&pdcp_cond,NULL); pdcp_instance_cnt = -1; LOG_I(PDCP,"Allocating PDCP thread\n"); - error_code = pthread_create(&pdcp_thread, - &pdcp_thread_attr, - pdcp_thread_main, - (void*)NULL); - - if (error_code!= 0) { - LOG_I(PDCP,"Could not allocate PDCP thread, error %d\n",error_code); - return(error_code); - } else { - LOG_I(PDCP,"Allocate PDCP thread successful\n"); - pthread_setname_np( pdcp_thread, "PDCP" ); - } + threadCreate(&pdcp_thread, pdcp_thread_main, (void*)NULL, "PDCP", -1, OAI_PRIORITY_RT); return(0); } diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 42d1e04caa..bef23a83a1 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -76,6 +76,7 @@ #include "pdcp.h" #include "plmn_data.h" #include "msc.h" +#include #if defined(ENABLE_ITTI) # include "intertask_interface.h" @@ -5477,7 +5478,6 @@ void rrc_control_socket_init(){ struct sockaddr_in rrc_ctrl_socket_addr; pthread_attr_t attr; - struct sched_param sched_param; int optval; // flag value for setsockopt //int n; // message byte size @@ -5505,27 +5505,11 @@ void rrc_control_socket_init(){ LOG_E(RRC,"[rrc_control_socket_init] ERROR: Failed on binding the socket\n"); exit(1); } - //create thread to listen to incoming packets - if (pthread_attr_init(&attr) != 0) { - LOG_E(RRC, "[rrc_control_socket_init]Failed to initialize pthread attribute for ProSe -> RRC communication (%d:%s)\n", - errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - sched_param.sched_priority = 10; - - pthread_attr_setschedpolicy(&attr, SCHED_RR); - pthread_attr_setschedparam(&attr, &sched_param); + threadTopInit("RRC Control Socket",-1,OAI_PRIORITY_RT); pthread_t rrc_control_socket_thread; - if (pthread_create(&rrc_control_socket_thread, &attr, rrc_control_socket_thread_fct, NULL) != 0) { - LOG_E(RRC, "[rrc_control_socket_init]Failed to create new thread for RRC/ProSeApp communication (%d:%s)\n", - errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - pthread_setname_np( rrc_control_socket_thread, "RRC Control Socket" ); + threadCreate(&rrc_control_socket_thread, rrc_control_socket_thread_fct, NULL, "RRC/ProSeApp", -1, OAI_PRIORITY_RT); } diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index 0dca3b80d2..c8cdfd336f 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -58,7 +58,6 @@ int8_t mac_rrc_nr_data_req(const module_id_t Mod_idP, uint8_t sfn_msb = (uint8_t)((frameP>>4)&0x3f); #ifdef DEBUG_RRC - int i; LOG_I(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id); #endif diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 801673b2ef..2cb5414ed0 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -116,10 +116,9 @@ mui_t rrc_gNB_mui = 0; void openair_nr_rrc_on(const protocol_ctxt_t* const ctxt_pP){ - int CC_id; LOG_I(NR_RRC, PROTOCOL_NR_RRC_CTXT_FMT" gNB:OPENAIR NR RRC IN....\n",PROTOCOL_NR_RRC_CTXT_ARGS(ctxt_pP)); - for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { + for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { rrc_config_nr_buffer (&RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1); RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1; rrc_config_nr_buffer (&RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1); @@ -144,8 +143,6 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( rrc_gNB_ue_context_t *const ue_context_pP ){ - uint8_t size; - uint8_t buffer[100]; int CC_id = ue_context_pP->ue_context.primaryCC_id; OCTET_STRING_t *secondaryCellGroup; NR_CellGroupConfig_t *cellGroupconfig; diff --git a/openair2/UTIL/ASYNC_IF/link_manager.c b/openair2/UTIL/ASYNC_IF/link_manager.c index c1ce742d0b..c8b7d59f50 100644 --- a/openair2/UTIL/ASYNC_IF/link_manager.c +++ b/openair2/UTIL/ASYNC_IF/link_manager.c @@ -30,6 +30,7 @@ #include "link_manager.h" #include "common/utils/LOG/log.h" +#include #include #include @@ -112,41 +113,14 @@ link_manager_t *create_link_manager( ret->socket_link = link; ret->run = 1; - if (pthread_attr_init(&attr)) - goto error; - - // Make the async interface threads real-time - //#ifndef LOWLATENCY - struct sched_param sched_param_recv_thread; - - sched_param_recv_thread.sched_priority = sched_get_priority_max(SCHED_RR) - 1; - pthread_attr_setschedparam(&attr, &sched_param_recv_thread); - pthread_attr_setschedpolicy(&attr, SCHED_RR); - //#endif - - if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) - goto error; - - if (pthread_create(&t, &attr, link_manager_sender_thread, ret)) - goto error; + threadCreate(&t, link_manager_sender_thread, ret, "flexranSender", -1, OAI_PRIORITY_RT_LOW); ret->sender = t; - if (pthread_create(&t, &attr, link_manager_receiver_thread, ret)) - /* we should destroy the other thread here */ - goto error; + threadCreate(&t, link_manager_receiver_thread, ret, "flexranReceiver", -1, OAI_PRIORITY_RT_LOW); ret->receiver = t; - if (pthread_attr_destroy(&attr)) - /* to be clean we should destroy the threads at this point, - * even if in practice we never reach it */ - goto error; - return ret; -error: - LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); - free(ret); - return NULL; } void destroy_link_manager(link_manager_t *manager) diff --git a/openair2/UTIL/CLI/cli_server.c b/openair2/UTIL/CLI/cli_server.c index d4f97f15ba..1994855b5d 100644 --- a/openair2/UTIL/CLI/cli_server.c +++ b/openair2/UTIL/CLI/cli_server.c @@ -90,10 +90,7 @@ int cli_server_init(cli_handler_t handler) } /* create telnet listener thread */ - if (pthread_create(&cli_server_listener, NULL, cli_server_listen, NULL)) { - perror("thread"); - return -1; - } + threadCreate(&cli_server_listener, cli_server_listen, NULL, "telnet", -1, OAI_PRIORITY_RT_LOW); return 0; } diff --git a/openair2/UTIL/OPT/probe.c b/openair2/UTIL/OPT/probe.c index a1e5367168..f2296017b8 100644 --- a/openair2/UTIL/OPT/probe.c +++ b/openair2/UTIL/OPT/probe.c @@ -90,6 +90,7 @@ what about the implementation #include #include +#include #include "opt.h" @@ -203,15 +204,7 @@ int opt_create_listener_socket(char *ip_address, uint16_t port) return -1; } - ret = pthread_create(&opt_listener.thread, NULL, opt_listener_thread, NULL); - - if (ret != 0) { - LOG_E(OPT, "Failed to create thread for server socket: %s\n", strerror(errno)); - opt_type = OPT_NONE; - close(opt_listener.sd); - opt_listener.sd = -1; - return -1; - } + threadCreate(&opt_listener.thread, opt_listener_thread, NULL, "flexran", -1, OAI_PRIORITY_RT_LOW); return 0; } diff --git a/openair2/UTIL/OTG/otg_rx_socket.c b/openair2/UTIL/OTG/otg_rx_socket.c index 88ecd3e904..9e9b6bf4a1 100644 --- a/openair2/UTIL/OTG/otg_rx_socket.c +++ b/openair2/UTIL/OTG/otg_rx_socket.c @@ -195,17 +195,7 @@ void server_socket_tcp_ip4() /* create new thread for the new connection */ - if (pthread_create(&id, NULL, (void *)recv_ip4_tcp, (void*)csock)) - LOG_W(OTG,"SOCKET:: TCP-IP4 ::pthread_create OK!\n"); - - else - LOG_W(OTG,"SOCKET:: TCP-IP4 ::Error in pthread_create \n"); - - if (pthread_detach(id)) - LOG_W(OTG,"SOCKET:: TCP-IP4 ::pthread_detach OK!\n"); - else - LOG_W(OTG,"SOCKET:: TCP-IP4 ::Error in pthread_detach\n"); - + threadCreate(&id, (void *)recv_ip4_tcp, (void*)csock), "OTG", -1, OAI_PRIORITY_RT_LOW); LOG_I(OTG,"SOCKET:: TCP-IP4 :: Client n=%d finish transmission\n", cmpt_cl); cmpt_cl+=1; } diff --git a/openair3/NAS/UE/UEprocess.c b/openair3/NAS/UE/UEprocess.c index 6a70911e21..2478eaee29 100644 --- a/openair3/NAS/UE/UEprocess.c +++ b/openair3/NAS/UE/UEprocess.c @@ -160,27 +160,15 @@ int main(int argc, const char *argv[]) */ pthread_t user_mngr; - if (pthread_create (&user_mngr, &attr, _nas_user_mngr, &user_fd) != 0) { - LOG_TRACE (ERROR, "UE-MAIN - " - "Failed to create the user management thread"); - user_api_close (user_api_id); - network_api_close (network_fd); - exit (EXIT_FAILURE); - } + threadCreate (&user_mngr, , _nas_user_mngr, &user_fd, "UE-nas", -1, OAI_PRIORITY_RT_LOW) ; /* * Start thread use to manage the network connection endpoint */ pthread_t network_mngr; - if (pthread_create (&network_mngr, &attr, _nas_network_mngr, - &network_fd) != 0) { - LOG_TRACE (ERROR, "UE-MAIN - " - "Failed to create the network management thread"); - user_api_close (user_api_id); - network_api_close (network_fd); - exit (EXIT_FAILURE); - } + threadCreate (&network_mngr, _nas_network_mngr, + &network_fd, "UE-nas-mgr", -1, OAI_PRIORITY_RT_LOW) ; pthread_attr_destroy (&attr); diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 58a8697f79..ab23d52b3a 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -1102,6 +1102,9 @@ extern "C" { device->type=USRP_X300_DEV; usrp_master_clock = 184.32e6; args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); + // USRP recommended: https://files.ettus.com/manual/page_usrp_x3x0_config.html + if ( 0 != system("sysctl -w net.core.rmem_max=33554432 net.core.wmem_max=33554432") ) + LOG_W(HW,"Can't set kernel paramters for X3xx\n"); } s->usrp = uhd::usrp::multi_usrp::make(args); diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index 9b8ea00123..e14abe4f57 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -1005,7 +1005,7 @@ printf("~~~~~~~~~~~~~~~~~~~~successfully get the parallel config[%d], worker con -#ifndef DEADLINE_SCHEDULER +#if 0 // #ifndef DEADLINE_SCHEDULER printf("NO deadline scheduler\n"); /* Currently we set affinity for UHD to CPU 0 for eNB/UE and only if number of CPUS >2 */ From 4d787625ab74412f971905d59a2f65fba2a7e51f Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 30 Apr 2019 14:25:42 +0200 Subject: [PATCH 105/117] still to compile --- common/utils/ocp_itti/intertask_interface.cpp | 2 +- common/utils/system.c | 20 ++++++++--- common/utils/system.h | 1 + executables/nr-gnb.c | 16 +++------ executables/nr-ru.c | 34 +++---------------- executables/nr-softmodem.c | 6 +--- executables/nr-softmodem.h | 2 +- executables/nr-ue.c | 6 ---- openair1/PHY/defs_RU.h | 19 ----------- openair1/PHY/defs_gNB.h | 8 ----- openair1/PHY/thread_NR_UE.h | 4 --- openair1/SCHED/phy_procedures_lte_eNb.c | 15 +++----- openair1/SCHED_NR/nr_ru_procedures.c | 3 +- openair1/SCHED_NR/sched_nr.h | 2 +- openair2/ENB_APP/flexran_agent.c | 1 - openair2/LAYER2/PDCP_v10.1.0/pdcp.h | 1 - openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c | 20 +---------- openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c | 1 - openair2/RRC/LTE/rrc_UE.c | 2 -- openair2/UTIL/ASYNC_IF/link_manager.c | 5 ++- openair3/NAS/COMMON/UTIL/nas_timer.c | 12 +------ openair3/NAS/UE/UEprocess.c | 7 ---- 22 files changed, 39 insertions(+), 148 deletions(-) diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp index e896413b68..3a1fff6e93 100644 --- a/common/utils/ocp_itti/intertask_interface.cpp +++ b/common/utils/ocp_itti/intertask_interface.cpp @@ -281,7 +281,7 @@ extern "C" { int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *args_p) { task_list_t *t=&tasks[task_id]; - threadCreate (&t->thread, start_routine, args_p, itti_get_task_name(task_id),-1,OAI_PRIORITY_RT); + threadCreate (&t->thread, start_routine, args_p, (char*)itti_get_task_name(task_id),-1,OAI_PRIORITY_RT); LOG_I(TMR,"Created Posix thread %s\n", itti_get_task_name(task_id) ); return 0; } diff --git a/common/utils/system.c b/common/utils/system.c index 90e5185a67..0a116661af 100644 --- a/common/utils/system.c +++ b/common/utils/system.c @@ -239,17 +239,27 @@ void thread_top_init(char *thread_name, mlockall(MCL_CURRENT | MCL_FUTURE); } -void threadTopInit(const char* name, const int affinity, const int priority){ -struct sched_param sparam={0}; +void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){ + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + struct sched_param sparam={0}; sparam.sched_priority = priority; - AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO , &sparam) == 0,"Error setting thread priority"); - pthread_setname_np(pthread_self(), name); + pthread_attr_setschedparam(&attr, &sparam); + + pthread_create(t, &attr, func, param); + + pthread_setname_np(*t, name); if (affinity != -1 ) { cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(affinity, &cpuset); - AssertFatal( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity"); + AssertFatal( pthread_setaffinity_np(*t, sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity"); } + + pthread_attr_destroy(&attr); } // Block CPU C-states deep sleep diff --git a/common/utils/system.h b/common/utils/system.h index b66d4031c9..a89a6c5b17 100644 --- a/common/utils/system.h +++ b/common/utils/system.h @@ -22,6 +22,7 @@ #ifndef _SYSTEM_H_OAI_ #define _SYSTEM_H_OAI_ #include +#include #ifdef __cplusplus extern "C" { #endif diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index 8b4822ba56..c76fae828e 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -38,6 +38,8 @@ #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all #include "assertions.h" +#include +#include #include "PHY/types.h" @@ -676,8 +678,8 @@ static void* gNB_thread_prach( void* param ) { } */ -extern void init_td_thread(PHY_VARS_gNB *, pthread_attr_t *); -extern void init_te_thread(PHY_VARS_gNB *, pthread_attr_t *); +extern void init_td_thread(PHY_VARS_gNB *); +extern void init_te_thread(PHY_VARS_gNB *); void init_gNB_proc(int inst) { int i=0; @@ -685,8 +687,6 @@ void init_gNB_proc(int inst) { PHY_VARS_gNB *gNB; gNB_L1_proc_t *proc; gNB_L1_rxtx_proc_t *L1_proc,*L1_proc_tx; - pthread_attr_t *attr0=NULL,*attr1=NULL; - //*attr_prach=NULL; LOG_I(PHY,"%s(inst:%d) RC.nb_nr_CC[inst]:%d \n",__FUNCTION__,inst,RC.nb_nr_CC[inst]); for (CC_id=0; CC_idmutex_RU_PRACH,NULL); pthread_cond_init( &proc->cond_prach, NULL); pthread_cond_init( &proc->cond_asynch_rxtx, NULL); - pthread_attr_init( &proc->attr_prach); - pthread_attr_init( &proc->attr_asynch_rxtx); - // pthread_attr_init( &proc->attr_td); - // pthread_attr_init( &proc->attr_te); - pthread_attr_init( &L1_proc->attr); - pthread_attr_init( &L1_proc_tx->attr); - attr0 = &L1_proc->attr; - attr1 = &L1_proc_tx->attr; LOG_I(PHY,"gNB->single_thread_flag:%d\n", gNB->single_thread_flag); if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) { diff --git a/executables/nr-ru.c b/executables/nr-ru.c index 547f4a7d51..f76cada501 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -604,7 +604,6 @@ static void *emulatedRF_thread(void *param) { struct timespec req = {0}; req.tv_sec = 0; req.tv_nsec = (numerology>0)? ((microsec * 1000L)/numerology):(microsec * 1000L)*2; - threadTopInit("emulatedRF",-1,OAI_PRIORITY_RT_LOW); wait_sync("emulatedRF_thread"); while(!oai_exit) { @@ -1592,17 +1591,12 @@ extern void ru_fep_full_2thread(RU_t *ru); extern void nr_feptx_ofdm(RU_t *ru); extern void nr_feptx_ofdm_2thread(RU_t *ru); extern void feptx_prec(RU_t *ru); -extern void init_fep_thread(RU_t *ru,pthread_attr_t *attr); -extern void init_nr_feptx_thread(RU_t *ru,pthread_attr_t *attr); +extern void init_fep_thread(RU_t *ru); +extern void init_nr_feptx_thread(RU_t *ru); void init_RU_proc(RU_t *ru) { int i=0; RU_proc_t *proc; - pthread_attr_t *attr_FH=NULL, *attr_FH1=NULL,*attr_prach=NULL,*attr_asynch=NULL, *attr_emulateRF=NULL;// *attr_synch=NULL; - //pthread_attr_t *attr_fep=NULL; -#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - //pthread_attr_t *attr_prach_br=NULL; -#endif char name[100]; #ifndef OCP_FRAMEWORK LOG_I(PHY,"Initializing RU proc %d (%s,%s),\n",ru->idx,NB_functions[ru->function],NB_timing[ru->if_timing]); @@ -1639,21 +1633,6 @@ void init_RU_proc(RU_t *ru) { pthread_cond_init( &proc->cond_asynch_rxtx, NULL); pthread_cond_init( &proc->cond_synch,NULL); pthread_cond_init( &proc->cond_gNBs, NULL); - pthread_attr_init( &proc->attr_FH); - pthread_attr_init( &proc->attr_FH1); - pthread_attr_init( &proc->attr_emulateRF); - pthread_attr_init( &proc->attr_prach); - pthread_attr_init( &proc->attr_synch); - pthread_attr_init( &proc->attr_asynch_rxtx); - pthread_attr_init( &proc->attr_fep); -#ifndef DEADLINE_SCHEDULER - attr_FH = &proc->attr_FH; - attr_FH1 = &proc->attr_FH1; - attr_emulateRF = &proc->attr_emulateRF; - attr_prach = &proc->attr_prach; - //attr_synch = &proc->attr_synch; - attr_asynch = &proc->attr_asynch_rxtx; -#endif threadCreate( &proc->pthread_FH, ru_thread, (void *)ru, "thread_FH", -1, OAI_PRIORITY_RT ); if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) @@ -1679,9 +1658,9 @@ void init_RU_proc(RU_t *ru) { } if (get_nprocs()>=2) { - if (ru->feprx) init_fep_thread(ru,NULL); + if (ru->feprx) init_fep_thread(ru); - if (ru->feptx_ofdm) nr_init_feptx_thread(ru,NULL); + if (ru->feptx_ofdm) nr_init_feptx_thread(ru); } if (opp_enabled == 1) threadCreate(&ru->ru_stats_thread,ru_stats_thread,(void *)ru, "emulateRF", -1, OAI_PRIORITY_RT_LOW); @@ -1769,11 +1748,6 @@ void kill_RU_proc(int inst) { pthread_cond_destroy(&proc->cond_asynch_rxtx); pthread_cond_destroy(&proc->cond_synch); pthread_cond_destroy(&proc->cond_gNBs); - pthread_attr_destroy(&proc->attr_FH); - pthread_attr_destroy(&proc->attr_prach); - pthread_attr_destroy(&proc->attr_synch); - pthread_attr_destroy(&proc->attr_asynch_rxtx); - pthread_attr_destroy(&proc->attr_fep); } int check_capabilities(RU_t *ru,RRU_capabilities_t *cap) { diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index c724940fb2..00620febd7 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -394,7 +394,6 @@ void reset_stats(FL_OBJECT *button, long arg) { } static void *scope_thread(void *arg) { - threadTopInit("scope",-1,OAI_PRIORITY_RT_LOW); int UE_id, CC_id; int ue_cnt=0; # ifdef ENABLE_XFORMS_WRITE_STATS @@ -1065,10 +1064,7 @@ int main( int argc, char **argv ) { } // CC_id } // UE_id - ret = threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); - - if (ret == 0) - pthread_setname_np( forms_thread, "xforms" ); + threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); printf("Scope thread created, ret=%d\n",ret); } diff --git a/executables/nr-softmodem.h b/executables/nr-softmodem.h index 49e079ae13..5dfb3e9b83 100644 --- a/executables/nr-softmodem.h +++ b/executables/nr-softmodem.h @@ -240,7 +240,7 @@ extern void set_function_spec_param(RU_t *ru); extern void reset_opp_meas(void); extern void print_opp_meas(void); -extern void init_fep_thread(PHY_VARS_gNB *, pthread_attr_t *); +extern void init_fep_thread(PHY_VARS_gNB *); void init_gNB_afterRU(void); diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 21b1edd617..6629d5155a 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -538,7 +538,6 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) { void *UE_thread(void *arg) { //this thread should be over the processing thread to keep in real time - threadTopInit("UE_IQ",1,OAI_PRIORITY_RT_MAX); PHY_VARS_NR_UE *UE = (PHY_VARS_NR_UE *) arg; // int tx_enabled = 0; openair0_timestamp timestamp; @@ -741,11 +740,6 @@ void init_UE(int nb_inst) { int inst; NR_UE_MAC_INST_t *mac_inst; pthread_t threads[nb_inst]; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); - pthread_attr_setschedpolicy(&attr, SCHED_FIFO); for (inst=0; inst < nb_inst; inst++) { PHY_VARS_NR_UE *UE = PHY_vars_UE_g[inst][0]; diff --git a/openair1/PHY/defs_RU.h b/openair1/PHY/defs_RU.h index 76769ed4db..73e75bb992 100644 --- a/openair1/PHY/defs_RU.h +++ b/openair1/PHY/defs_RU.h @@ -191,25 +191,6 @@ typedef struct RU_proc_t_s { int first_rx; /// flag to indicate first TX transmission int first_tx; - /// pthread attributes for RU FH processing thread - pthread_attr_t attr_FH; - pthread_attr_t attr_FH1; - /// pthread attributes for RU prach - pthread_attr_t attr_prach; -#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - /// pthread attributes for RU prach BL/CE UEs - pthread_attr_t attr_prach_br; -#endif - /// pthread attributes for RU synch thread - pthread_attr_t attr_synch; - /// pthread attributes for asynchronous RX thread - pthread_attr_t attr_asynch_rxtx; - /// pthread attributes for worker fep thread - pthread_attr_t attr_fep; - /// pthread attributes for worker feptx thread - pthread_attr_t attr_feptx; - /// pthread attributes for emulated RF - pthread_attr_t attr_emulateRF; /// scheduling parameters for RU FH thread struct sched_param sched_param_FH; struct sched_param sched_param_FH1; diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index 24be9688dc..8a962bb839 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -373,8 +373,6 @@ typedef struct { int instance_cnt; /// pthread structure for RXn-TXnp4 processing thread pthread_t pthread; - /// pthread attributes for RXn-TXnp4 processing thread - pthread_attr_t attr; /// condition variable for tx processing thread pthread_cond_t cond; /// mutex for RXn-TXnp4 processing thread @@ -430,12 +428,6 @@ typedef struct gNB_L1_proc_t_s { int first_rx; /// flag to indicate first TX transmission int first_tx; - /// pthread attributes for single gNB processing thread - pthread_attr_t attr_single; - /// pthread attributes for prach processing thread - pthread_attr_t attr_prach; - /// pthread attributes for asynchronous RX thread - pthread_attr_t attr_asynch_rxtx; /// scheduling parameters for parallel turbo-decoder thread struct sched_param sched_param_td; /// scheduling parameters for parallel turbo-encoder thread diff --git a/openair1/PHY/thread_NR_UE.h b/openair1/PHY/thread_NR_UE.h index cba7a5ae41..c5db3e14d7 100644 --- a/openair1/PHY/thread_NR_UE.h +++ b/openair1/PHY/thread_NR_UE.h @@ -32,8 +32,6 @@ typedef struct { //pthread_t pthread_slot0_dl_processing; pthread_t pthread_slot1_dl_processing; /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_slot1_dl_processing; /// condition variable for UE fep_slot1 thread; //pthread_cond_t cond_slot0_dl_processing; pthread_cond_t cond_slot1_dl_processing; @@ -46,8 +44,6 @@ typedef struct { //pthread_t pthread_slot0_dl_processing; pthread_t pthread_dlsch_td; /// pthread attributes for fep_slot1 processing thread - // pthread_attr_t attr_slot0_dl_processing; - pthread_attr_t attr_dlsch_td; /// condition variable for UE fep_slot1 thread; //pthread_cond_t cond_slot0_dl_processing; pthread_cond_t cond_dlsch_td; diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c index 276006ec3b..9409e650a8 100644 --- a/openair1/SCHED/phy_procedures_lte_eNb.c +++ b/openair1/SCHED/phy_procedures_lte_eNb.c @@ -38,6 +38,7 @@ #include "nfapi_interface.h" #include "fapi_l1.h" #include "common/utils/LOG/log.h" +#include #include "common/utils/LOG/vcd_signal_dumper.h" #include "assertions.h" @@ -1473,11 +1474,7 @@ void init_td_thread(PHY_VARS_eNB *eNB) { proc->tdp.eNB = eNB; proc->instance_cnt_td = -1; - pthread_attr_init( &proc->attr_td); - pthread_mutex_init( &proc->mutex_td, NULL); - pthread_cond_init( &proc->cond_td, NULL); - - pthread_create(&proc->pthread_td, &proc->attr_td, td_thread, (void*)&proc->tdp); + threadCreate(&proc->pthread_td, td_thread, (void*)&proc->tdp, "TD", -1, OAI_PRIORITY_RT); } void kill_td_thread(PHY_VARS_eNB *eNB) { @@ -1501,12 +1498,10 @@ void init_te_thread(PHY_VARS_eNB *eNB) { proc->tep[i].eNB = eNB; proc->tep[i].instance_cnt_te = -1; - pthread_mutex_init( &proc->tep[i].mutex_te, NULL); - pthread_cond_init( &proc->tep[i].cond_te, NULL); - pthread_attr_init( &proc->tep[i].attr_te); - LOG_I(PHY,"Creating te_thread %d\n",i); - pthread_create(&proc->tep[i].pthread_te, &proc->tep[i].attr_te, te_thread, (void*)&proc->tep[i]); + char txt[128]; + sprintf(txt,"TE_%d", i); + threadCreate(&proc->tep[i].pthread_te, te_thread, (void*)&proc->tep[i], txt, -1, OAI_PRIORITY_RT); } } void kill_te_thread(PHY_VARS_eNB *eNB) { diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c index 8a474d3644..a0f12a7287 100644 --- a/openair1/SCHED_NR/nr_ru_procedures.c +++ b/openair1/SCHED_NR/nr_ru_procedures.c @@ -41,6 +41,7 @@ #include "LAYER2/MAC/mac_extern.h" #include "LAYER2/MAC/mac.h" #include "common/utils/LOG/log.h" +#include "common/utils/system.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "T.h" @@ -196,7 +197,7 @@ static void *nr_feptx_thread(void *param) { return(NULL); } -void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx) { +void nr_init_feptx_thread(RU_t *ru) { RU_proc_t *proc = &ru->proc; diff --git a/openair1/SCHED_NR/sched_nr.h b/openair1/SCHED_NR/sched_nr.h index a120b8c140..3da78305da 100644 --- a/openair1/SCHED_NR/sched_nr.h +++ b/openair1/SCHED_NR/sched_nr.h @@ -38,7 +38,7 @@ nr_slot_t nr_slot_select (nfapi_nr_config_request_t *cfg, unsigned char slot); void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp); void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB, gNB_L1_rxtx_proc_t *proc, int do_meas); void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot); -void nr_init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx); +void nr_init_feptx_thread(RU_t *ru); void nr_feptx_ofdm(RU_t *ru); void nr_feptx_ofdm_2thread(RU_t *ru); void nr_feptx0(RU_t *ru,int first_symbol, int num_symbols); diff --git a/openair2/ENB_APP/flexran_agent.c b/openair2/ENB_APP/flexran_agent.c index 2cf72c40ee..225a60e285 100644 --- a/openair2/ENB_APP/flexran_agent.c +++ b/openair2/ENB_APP/flexran_agent.c @@ -102,7 +102,6 @@ void *flexran_agent_task(void *args){ } void *receive_thread(void *args) { - threadTopInit("flexran",-1,OAI_PRIORITY_RT_LOW); flexran_agent_info_t *d = args; void *data; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h index 054bb5fac4..ab00abc0cf 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h @@ -53,7 +53,6 @@ extern pthread_t pdcp_thread; -extern pthread_attr_t pdcp_thread_attr; extern pthread_mutex_t pdcp_mutex; extern pthread_cond_t pdcp_cond; extern int pdcp_instance_cnt; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c index 472c46c94a..b77151f8a3 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_netlink.c @@ -97,8 +97,6 @@ pdcp_netlink_init( int i; int nb_inst_enb; int nb_inst_ue; - pthread_attr_t attr; - struct sched_param sched_param; reset_meas(&ip_pdcp_stats_tmp); nb_inst_enb = 1; @@ -141,28 +139,12 @@ pdcp_netlink_init( } if ((nb_inst_ue + nb_inst_enb) > 0) { - if (pthread_attr_init(&attr) != 0) { - LOG_E(PDCP, "[NETLINK]Failed to initialize pthread attribute for Netlink -> PDCP communication (%d:%s)\n", - errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - sched_param.sched_priority = 10; - - pthread_attr_setschedpolicy(&attr, SCHED_RR); - pthread_attr_setschedparam(&attr, &sched_param); /* Create one thread that fetchs packets from the netlink. * When the netlink fifo is full, packets are silently dropped, this behaviour * should be avoided if we want a reliable link. */ - if (pthread_create(&pdcp_netlink_thread, &attr, pdcp_netlink_thread_fct, NULL) != 0) { - LOG_E(PDCP, "[NETLINK]Failed to create new thread for Netlink/PDCP communication (%d:%s)\n", - errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - pthread_setname_np( pdcp_netlink_thread, "PDCP netlink" ); + threadCreate(&pdcp_netlink_thread, pdcp_netlink_thread_fct, "PDCP netlink", -1, OAI_PRIORITY_RT_LOW ); } return 0; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c index c37d665fcc..f1f6ebb794 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_thread.c @@ -45,7 +45,6 @@ extern int oai_exit; extern char UE_flag; pthread_t pdcp_thread; -pthread_attr_t pdcp_thread_attr; pthread_mutex_t pdcp_mutex; pthread_cond_t pdcp_cond; int pdcp_instance_cnt; diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index bef23a83a1..ca4a565250 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -5477,7 +5477,6 @@ rrc_ue_process_sidelink_radioResourceConfig( void rrc_control_socket_init(){ struct sockaddr_in rrc_ctrl_socket_addr; - pthread_attr_t attr; int optval; // flag value for setsockopt //int n; // message byte size @@ -5506,7 +5505,6 @@ void rrc_control_socket_init(){ exit(1); } - threadTopInit("RRC Control Socket",-1,OAI_PRIORITY_RT); pthread_t rrc_control_socket_thread; threadCreate(&rrc_control_socket_thread, rrc_control_socket_thread_fct, NULL, "RRC/ProSeApp", -1, OAI_PRIORITY_RT); diff --git a/openair2/UTIL/ASYNC_IF/link_manager.c b/openair2/UTIL/ASYNC_IF/link_manager.c index c8b7d59f50..e67b7b0ec8 100644 --- a/openair2/UTIL/ASYNC_IF/link_manager.c +++ b/openair2/UTIL/ASYNC_IF/link_manager.c @@ -30,6 +30,7 @@ #include "link_manager.h" #include "common/utils/LOG/log.h" +#include #include #include @@ -104,9 +105,7 @@ link_manager_t *create_link_manager( LOG_D(MAC, "create new link manager\n"); - ret = calloc(1, sizeof(link_manager_t)); - if (ret == NULL) - goto error; + AssertFatal( (ret=calloc(1, sizeof(link_manager_t))) != NULL,""); ret->send_queue = send_queue; ret->receive_queue = receive_queue; diff --git a/openair3/NAS/COMMON/UTIL/nas_timer.c b/openair3/NAS/COMMON/UTIL/nas_timer.c index d92c48f483..7ddcb61d1d 100644 --- a/openair3/NAS/COMMON/UTIL/nas_timer.c +++ b/openair3/NAS/COMMON/UTIL/nas_timer.c @@ -397,24 +397,14 @@ static void _nas_timer_handler(int signal) /* Get the timer entry for which the system timer expired */ nas_timer_entry_t *te = _nas_timer_db.head->entry; - /* Execute the callback function */ - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - int rc = pthread_create (&te->pid, &attr, te->cb, te->args); - pthread_attr_destroy(&attr); + threadCreate (&te->pid, te->cb, te->args, "nas-timer", -1, OAI_PRIORITY_RT_LOW); - /* Wait for the thread to terminate before releasing the timer entry */ - if (rc == 0) { void *result = NULL; (void) pthread_join(te->pid, &result); - /* TODO: Check returned result ??? */ if (result) { free(result); } - } } #endif diff --git a/openair3/NAS/UE/UEprocess.c b/openair3/NAS/UE/UEprocess.c index 2478eaee29..7fe1435960 100644 --- a/openair3/NAS/UE/UEprocess.c +++ b/openair3/NAS/UE/UEprocess.c @@ -150,11 +150,6 @@ int main(int argc, const char *argv[]) (void) _nas_set_signal_handler (SIGINT, _nas_signal_handler); (void) _nas_set_signal_handler (SIGTERM, _nas_signal_handler); - pthread_attr_t attr; - pthread_attr_init (&attr); - pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - /* * Start thread use to manage the user connection endpoint */ @@ -170,8 +165,6 @@ int main(int argc, const char *argv[]) threadCreate (&network_mngr, _nas_network_mngr, &network_fd, "UE-nas-mgr", -1, OAI_PRIORITY_RT_LOW) ; - pthread_attr_destroy (&attr); - /* * Suspend execution of the main process until all connection * endpoints are still active From ba6d47a7580290e846214b4426b648c6becb909c Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 30 Apr 2019 21:46:49 +0200 Subject: [PATCH 106/117] rework threads in 5G --- common/utils/threadPool/thread-pool.c | 5 +++-- executables/nr-gnb.c | 3 --- executables/nr-ru.c | 7 +------ executables/nr-softmodem.c | 1 - executables/nr-ue.c | 2 +- openair1/SCHED/ru_procedures.c | 5 +++-- openair1/SCHED_NR/nr_ru_procedures.c | 1 - openair3/SCTP/sctp_eNB_task.c | 1 + targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 2 +- 9 files changed, 10 insertions(+), 17 deletions(-) diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c index a17495c91f..b45a8fa722 100644 --- a/common/utils/threadPool/thread-pool.c +++ b/common/utils/threadPool/thread-pool.c @@ -117,8 +117,9 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) { pool->allthreads->pool=pool; //Configure the thread scheduler policy for Linux // set the thread name for debugging - sprintf(myThread->name,"Tpool_%d",myThread->coreID); - threadCreate(&pool->allthreads->threadID, one_thread, (void *)pool->allthreads, Tpool, myThread->name, myThread->coreID, OAI_PRIORITY_RT); + sprintf(pool->allthreads->name,"Tpool_%d",pool->allthreads->coreID); + threadCreate(&pool->allthreads->threadID, one_thread, (void *)pool->allthreads, + pool->allthreads->name, pool->allthreads->coreID, OAI_PRIORITY_RT); pool->nbThreads++; } diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index c76fae828e..c0571f2bc5 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -272,7 +272,6 @@ static void *gNB_L1_thread_tx(void *param) { //PHY_VARS_gNB *gNB = RC.gNB[0][proc->CC_id]; char thread_name[100]; sprintf(thread_name,"TXnp4_%d\n",&gNB->proc.L1_proc == proc ? 0 : 1); - //thread_top_init(thread_name,1,470000,500000,500000); //wait_sync("tx_thread"); @@ -327,7 +326,6 @@ static void *gNB_L1_thread( void *param ) { // set default return value gNB_thread_rxtx_status = 0; sprintf(thread_name,"RXn_TXnp4_%d",&gNB->proc.L1_proc == proc ? 0 : 1); - //thread_top_init(thread_name,1,850000L,1000000L,2000000L); while (!oai_exit) { VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_PROC_RXTX0, 0 ); @@ -651,7 +649,6 @@ static void* gNB_thread_prach( void* param ) { // set default return value gNB_thread_prach_status = 0; - thread_top_init("gNB_thread_prach",1,500000L,1000000L,20000000L); while (!oai_exit) { diff --git a/executables/nr-ru.c b/executables/nr-ru.c index f76cada501..f64a92f5c2 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -777,7 +777,6 @@ static void *ru_thread_asynch_rxtx( void *param ) { RU_t *ru = (RU_t *)param; RU_proc_t *proc = &ru->proc; int subframe=0, frame=0; - thread_top_init("ru_thread_asynch_rxtx",1,870000L,1000000L,1000000L); // wait for top-level synchronization and do one acquisition to get timestamp for setting frame/subframe wait_sync("ru_thread_asynch_rxtx"); // wait for top-level synchronization and do one acquisition to get timestamp for setting frame/subframe @@ -825,7 +824,6 @@ static void *ru_thread_prach( void *param ) { RU_proc_t *proc = (RU_proc_t *)&ru->proc; // set default return value ru_thread_prach_status = 0; - thread_top_init("ru_thread_prach",1,500000L,1000000L,20000000L); while (RC.ru_mask>0) { usleep(1e6); @@ -1211,7 +1209,6 @@ static void *ru_thread_tx( void *param ) { int i = 0; cpu_set_t cpuset; CPU_ZERO(&cpuset); - thread_top_init("ru_thread_tx",1,400000,500000,500000); //CPU_SET(5, &cpuset); //pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); //wait_sync("ru_thread_tx"); @@ -1324,7 +1321,6 @@ static void *ru_thread( void *param ) { ru_thread_status = 0; // set default return value sprintf(threadname,"ru_thread %d",ru->idx); - thread_top_init(threadname,0,870000,1000000,1000000); LOG_I(PHY,"Starting RU %d (%s,%s),\n",ru->idx,NB_functions[ru->function],NB_timing[ru->if_timing]); if(emulate_rf) { @@ -1507,7 +1503,6 @@ void *ru_thread_synch(void *arg) { static int ru_thread_synch_status; - thread_top_init("ru_thread_synch",0,5000000,10000000,10000000); wait_sync("ru_thread_synch"); @@ -1633,7 +1628,7 @@ void init_RU_proc(RU_t *ru) { pthread_cond_init( &proc->cond_asynch_rxtx, NULL); pthread_cond_init( &proc->cond_synch,NULL); pthread_cond_init( &proc->cond_gNBs, NULL); - threadCreate( &proc->pthread_FH, ru_thread, (void *)ru, "thread_FH", -1, OAI_PRIORITY_RT ); + threadCreate( &proc->pthread_FH, ru_thread, (void *)ru, "thread_FH", -1, OAI_PRIORITY_RT_MAX ); if (get_thread_parallel_conf() == PARALLEL_RU_L1_SPLIT || get_thread_parallel_conf() == PARALLEL_RU_L1_TRX_SPLIT) threadCreate( &proc->pthread_FH1, ru_thread_tx, (void *)ru, "thread_FH1", -1, OAI_PRIORITY_RT ); diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 00620febd7..f45ae385fa 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -1065,7 +1065,6 @@ int main( int argc, char **argv ) { } // UE_id threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); - printf("Scope thread created, ret=%d\n",ret); } diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 6629d5155a..8b5d4eaed2 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -760,7 +760,7 @@ void init_UE(int nb_inst) { mac_inst->initial_bwp_ul.N_RB = UE->frame_parms.N_RB_UL; mac_inst->initial_bwp_ul.cyclic_prefix = UE->frame_parms.Ncp; LOG_I(PHY,"Intializing UE Threads for instance %d (%p,%p)...\n",inst,PHY_vars_UE_g[inst],PHY_vars_UE_g[inst][0]); - threadCreate(&threads[inst], UE_thread, (void *)UE), "UEthread", -1, OAI_PRIORITY_RT); + threadCreate(&threads[inst], UE_thread, (void *)UE, "UEthread", -1, OAI_PRIORITY_RT_MAX); } printf("UE threads created by %ld\n", gettid()); diff --git a/openair1/SCHED/ru_procedures.c b/openair1/SCHED/ru_procedures.c index f30f09859c..cb892489f1 100644 --- a/openair1/SCHED/ru_procedures.c +++ b/openair1/SCHED/ru_procedures.c @@ -44,6 +44,7 @@ #include "assertions.h" +#include "common/utils/system.h" #include "msc.h" #include @@ -483,7 +484,7 @@ void init_feptx_thread(RU_t *ru,pthread_attr_t *attr_feptx) { pthread_mutex_init( &proc->mutex_feptx, NULL); pthread_cond_init( &proc->cond_feptx, NULL); - pthread_create(&proc->pthread_feptx, attr_feptx, feptx_thread, (void*)ru); + threadCreate(&proc->pthread_feptx, feptx_thread, (void*)ru, "feptx", -1, OAI_PRIORITY_RT); } @@ -497,7 +498,7 @@ void init_fep_thread(RU_t *ru,pthread_attr_t *attr_fep) { pthread_mutex_init( &proc->mutex_fep, NULL); pthread_cond_init( &proc->cond_fep, NULL); - pthread_create(&proc->pthread_fep, attr_fep, fep_thread, (void*)ru); + threadCreate(&proc->pthread_fep, fep_thread, (void*)ru, "fep", -1, OAI_PRIORITY_RT); } diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c index a0f12a7287..d0b9d3ee48 100644 --- a/openair1/SCHED_NR/nr_ru_procedures.c +++ b/openair1/SCHED_NR/nr_ru_procedures.c @@ -180,7 +180,6 @@ static void *nr_feptx_thread(void *param) { RU_t *ru = (RU_t *)param; RU_proc_t *proc = &ru->proc; - thread_top_init("nr_feptx_thread",0,870000,1000000,1000000); while (!oai_exit) { diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c index e7265d66d6..60f233bc4a 100644 --- a/openair3/SCTP/sctp_eNB_task.c +++ b/openair3/SCTP/sctp_eNB_task.c @@ -40,6 +40,7 @@ #include #include "assertions.h" +#include "common/utils/system.h" #include "queue.h" #include "intertask_interface.h" diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index ab23d52b3a..8a012b39de 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -299,6 +299,7 @@ static int trx_usrp_start(openair0_device *device) { if (u_sf_mode != 2) { // not replay mode #endif + uhd::set_thread_priority_safe(1.0); usrp_state_t *s = (usrp_state_t *)device->priv; // setup GPIO for TDD, GPIO(4) = ATR_RX //set data direction register (DDR) to output @@ -1038,7 +1039,6 @@ extern "C" { << use_mmap << std::endl; } else { #endif - uhd::set_thread_priority_safe(1.0); usrp_state_t *s = (usrp_state_t *)calloc(sizeof(usrp_state_t),1); if (openair0_cfg[0].clock_source==gpsdo) From 7368e4bfc486d9a7a1ddc39cb4c0ef157d023759 Mon Sep 17 00:00:00 2001 From: laurent Date: Thu, 2 May 2019 12:17:31 +0200 Subject: [PATCH 107/117] fix compilation tests --- openair1/PHY/LTE_TRANSPORT/dlsch_coding.c | 9 -------- openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c | 4 ---- openair1/PHY/defs_L1_NB_IoT.h | 2 +- openair1/PHY/defs_common.h | 2 +- openair1/PHY/defs_eNB.h | 4 ++-- openair1/SCHED/ru_procedures.c | 25 +-------------------- openair1/SCHED_NR/nr_ru_procedures.c | 3 --- openair2/ENB_APP/enb_app.c | 3 +-- openair2/PHY_INTERFACE/UE_MAC_interface.h | 2 +- openair2/RRC/LTE/defs_NB_IoT.h | 2 +- 10 files changed, 8 insertions(+), 48 deletions(-) diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c index a7e4b33c16..85886f88b6 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c @@ -41,7 +41,6 @@ #include "common/utils/LOG/vcd_signal_dumper.h" #include "common/utils/LOG/log.h" #include -#include "targets/RT/USER/rt_wrapper.h" //#define DEBUG_DLSCH_CODING //#define DEBUG_DLSCH_FREE 1 @@ -337,14 +336,6 @@ int dlsch_encoding_2threads0(te_params *tep) { extern int oai_exit; void *te_thread(void *param) { - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - thread_top_init("te_thread",1,200000,250000,500000); - pthread_setname_np( pthread_self(),"te processing"); - LOG_I(PHY,"thread te created id=%ld\n", syscall(__NR_gettid)); - - te_params *tep = (te_params *)param; //wait_sync("te_thread"); diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c index 046e456916..6cb8c7d212 100644 --- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c +++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c @@ -42,7 +42,6 @@ #include "common/utils/LOG/vcd_signal_dumper.h" //#define DEBUG_ULSCH_DECODING -#include "targets/RT/USER/rt_wrapper.h" #include "transport_proto.h" extern WORKER_CONF_t get_thread_worker_conf(void); @@ -383,10 +382,7 @@ extern int oai_exit; void *td_thread(void *param) { PHY_VARS_eNB *eNB = ((td_params*)param)->eNB; eNB_proc_t *proc = &eNB->proc; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - thread_top_init("td_thread",1,200000,250000,500000); pthread_setname_np( pthread_self(),"td processing"); LOG_I(PHY,"thread td created id=%ld\n", syscall(__NR_gettid)); //wait_sync("td_thread"); diff --git a/openair1/PHY/defs_L1_NB_IoT.h b/openair1/PHY/defs_L1_NB_IoT.h index 8a7c853df5..bd583ee574 100644 --- a/openair1/PHY/defs_L1_NB_IoT.h +++ b/openair1/PHY/defs_L1_NB_IoT.h @@ -141,7 +141,7 @@ static inline void* malloc16_clear( size_t size ) #include #include "targets/ARCH/COMMON/common_lib.h" -#include "targets/COMMON/openairinterface5g_limits.h" +#include "openairinterface5g_limits.h" #define NUM_DCI_MAX_NB_IoT 32 diff --git a/openair1/PHY/defs_common.h b/openair1/PHY/defs_common.h index f479c30b8c..72387772bd 100644 --- a/openair1/PHY/defs_common.h +++ b/openair1/PHY/defs_common.h @@ -69,7 +69,7 @@ #include "TOOLS/tools_defs.h" -#include "targets/COMMON/openairinterface5g_limits.h" +#include "openairinterface5g_limits.h" #include "common/utils/LOG/log.h" #include "types.h" diff --git a/openair1/PHY/defs_eNB.h b/openair1/PHY/defs_eNB.h index d23586c634..8fc8fb4fa9 100644 --- a/openair1/PHY/defs_eNB.h +++ b/openair1/PHY/defs_eNB.h @@ -76,8 +76,8 @@ #include -#include "targets/ARCH/COMMON/common_lib.h" -#include "targets/COMMON/openairinterface5g_limits.h" +#include "common_lib.h" +#include "openairinterface5g_limits.h" #define NUMBER_OF_SUBBANDS_MAX 13 diff --git a/openair1/SCHED/ru_procedures.c b/openair1/SCHED/ru_procedures.c index cb892489f1..2724567f4b 100644 --- a/openair1/SCHED/ru_procedures.c +++ b/openair1/SCHED/ru_procedures.c @@ -49,8 +49,6 @@ #include -#include "targets/RT/USER/rt_wrapper.h" - extern int oai_exit; @@ -132,17 +130,8 @@ static void *feptx_thread(void *param) { RU_t *ru = (RU_t *)param; RU_proc_t *proc = &ru->proc; - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - - thread_top_init("feptx_thread",1,85000,120000,500000); - pthread_setname_np( pthread_self(),"feptx processing"); - LOG_I(PHY,"thread feptx created id=%ld\n", syscall(__NR_gettid)); - //CPU_SET(6, &cpuset); - //pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - //wait_sync("feptx_thread"); - + LOG_I(PHY,"thread feptx created \n"); while (!oai_exit) { @@ -163,8 +152,6 @@ static void *feptx_thread(void *param) { }*/ } - - return(NULL); } @@ -439,16 +426,6 @@ static void *fep_thread(void *param) { RU_t *ru = (RU_t *)param; RU_proc_t *proc = &ru->proc; - thread_top_init("fep_thread",1,100000,120000,5000000); - pthread_setname_np( pthread_self(),"fep processing"); - LOG_I(PHY,"thread fep created id=%ld\n", syscall(__NR_gettid)); - - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - //CPU_SET(2, &cpuset); - //pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); - //wait_sync("fep_thread"); - while (!oai_exit) { if (wait_on_condition(&proc->mutex_fep,&proc->cond_fep,&proc->instance_cnt_fep,"fep thread")<0) break; diff --git a/openair1/SCHED_NR/nr_ru_procedures.c b/openair1/SCHED_NR/nr_ru_procedures.c index d0b9d3ee48..653e9632b5 100644 --- a/openair1/SCHED_NR/nr_ru_procedures.c +++ b/openair1/SCHED_NR/nr_ru_procedures.c @@ -50,9 +50,6 @@ #include "msc.h" #include - -#include "targets/RT/USER/rt_wrapper.h" - // RU OFDM Modulator gNodeB extern openair0_config_t openair0_cfg[MAX_CARDS]; diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c index 37bcd36653..baa1409c52 100644 --- a/openair2/ENB_APP/enb_app.c +++ b/openair2/ENB_APP/enb_app.c @@ -55,6 +55,7 @@ extern unsigned char NB_eNB_INST; #endif +#include extern RAN_CONTEXT_t RC; #if defined(ENABLE_ITTI) @@ -64,8 +65,6 @@ extern RAN_CONTEXT_t RC; # define ENB_REGISTER_RETRY_DELAY 10 # endif -#include "targets/RT/USER/lte-softmodem.h" - /*------------------------------------------------------------------------------*/ /* diff --git a/openair2/PHY_INTERFACE/UE_MAC_interface.h b/openair2/PHY_INTERFACE/UE_MAC_interface.h index d010109f99..cadaf621d6 100644 --- a/openair2/PHY_INTERFACE/UE_MAC_interface.h +++ b/openair2/PHY_INTERFACE/UE_MAC_interface.h @@ -38,7 +38,7 @@ #include "nfapi_interface.h" #include "openair1/PHY/impl_defs_lte.h" -#include "targets/COMMON/openairinterface5g_limits.h" +#include "openairinterface5g_limits.h" diff --git a/openair2/RRC/LTE/defs_NB_IoT.h b/openair2/RRC/LTE/defs_NB_IoT.h index 0cc8a37bc0..422a5dcf9c 100644 --- a/openair2/RRC/LTE/defs_NB_IoT.h +++ b/openair2/RRC/LTE/defs_NB_IoT.h @@ -42,7 +42,7 @@ #include "rrc_types_NB_IoT.h" #include "COMMON/platform_constants.h" #include "COMMON/platform_types.h" -#include "targets/COMMON/openairinterface5g_limits.h" +#include "openairinterface5g_limits.h" #include "COMMON/mac_rrc_primitives.h" From 0061daeb9dbdf190a704551b6264df28b8bad4c4 Mon Sep 17 00:00:00 2001 From: laurent Date: Thu, 2 May 2019 21:21:53 +0200 Subject: [PATCH 108/117] some warnings --- executables/nr-ru.c | 1 - openair1/SCHED_NR/sched_nr.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/executables/nr-ru.c b/executables/nr-ru.c index f64a92f5c2..e6e62ad553 100644 --- a/executables/nr-ru.c +++ b/executables/nr-ru.c @@ -113,7 +113,6 @@ static int DEFENBS[] = {0}; extern volatile int oai_exit; -extern void nr_phy_init_RU(RU_t *); extern void nr_phy_free_RU(RU_t *); extern void nr_phy_config_request(NR_PHY_Config_t *gNB); diff --git a/openair1/SCHED_NR/sched_nr.h b/openair1/SCHED_NR/sched_nr.h index 3da78305da..7c5a5d0146 100644 --- a/openair1/SCHED_NR/sched_nr.h +++ b/openair1/SCHED_NR/sched_nr.h @@ -42,6 +42,9 @@ void nr_init_feptx_thread(RU_t *ru); void nr_feptx_ofdm(RU_t *ru); void nr_feptx_ofdm_2thread(RU_t *ru); void nr_feptx0(RU_t *ru,int first_symbol, int num_symbols); +void fep_full(RU_t *ru); +void feptx_prec(RU_t *ru); +int nr_phy_init_RU(RU_t *ru); void nr_configure_css_dci_initial(nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params, nr_scs_e scs_common, From 3cafcd72b9b92bc4ffa16e98942a9b8a1f4c0c43 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 7 May 2019 16:19:06 +0200 Subject: [PATCH 109/117] fixing a bad merge --- openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index 0ba8bb58d6..acc8c321ca 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -2589,9 +2589,8 @@ unsigned short nr_dlsch_extract_rbs_dual(int **rxdataF, int prb,nb_rb=0; unsigned short k; - int i,aarx; + int i,j,aarx; int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; - int pilots=0,j=0; k = frame_parms->first_carrier_offset + 516; //0 From 7e99e1f6b19c3214e74fff90c0099f727b9788c1 Mon Sep 17 00:00:00 2001 From: Florian Kaltenberger Date: Tue, 7 May 2019 22:25:14 +0200 Subject: [PATCH 110/117] small fix --- openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c index 8133f0b85f..73c5c3ef6f 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c @@ -314,15 +314,15 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue, &harq_process->Z, // [hna] Z is Zc &harq_process->F); - p_decParams->Z = harq_process->Z; - #ifdef DEBUG_DLSCH_DECODING - printf("dlsch decoding nr segmentation Z %d\n", p_decParams->Z); if (!frame%100) printf("K %d C %d Z %d nl %d \n", harq_process->K, harq_process->C, p_decParams->Z, harq_process->Nl); #endif } + p_decParams->Z = harq_process->Z; + //printf("dlsch decoding nr segmentation Z %d\n", p_decParams->Z); + Coderate = (float) A /(float) G; if ((A <=292) || ((A<=3824) && (Coderate <= 0.6667)) || Coderate <= 0.25) { From 7a5214c6b4760d7cbdf1005f32ac58c70b0d7846 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 14 May 2019 16:16:57 +0200 Subject: [PATCH 111/117] fix 4G merge issues --- cmake_targets/CMakeLists.txt | 8 ++++ common/utils/system.c | 42 ------------------- executables/nr-uesoftmodem.c | 2 +- .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c | 1 + openair1/PHY/defs_RU.h | 19 +++++++++ openair1/PHY/defs_gNB.h | 8 ++++ targets/ARCH/rfsimulator/simulator.c | 7 +++- targets/COMMON/openairinterface5g_limits.h | 8 ++-- 8 files changed, 46 insertions(+), 49 deletions(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index d5c5c10d64..d252e17d52 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -793,7 +793,10 @@ include_directories("${OPENAIR3_DIR}/S1AP") include_directories("${OPENAIR2_DIR}/X2AP") include_directories("${OPENAIR3_DIR}/UDP") include_directories("${OPENAIR3_DIR}/GTPV1-U") +include_directories("${OPENAIR_DIR}/targets/COMMON") include_directories("${OPENAIR_DIR}/targets/ARCH/COMMON") +include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/USERSPACE/LIB/") +include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/DEFS") include_directories("${OPENAIR2_DIR}/ENB_APP") include_directories("${OPENAIR2_DIR}/GNB_APP") include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC") @@ -2507,6 +2510,7 @@ target_link_libraries (nr-uesoftmodem-nos1 ${T_LIB}) add_executable(dlsim_tm4 ${OPENAIR1_DIR}/SIMULATION/LTE_PHY/dlsim_tm4.c ${OPENAIR1_DIR}/PHY/TOOLS/lte_phy_scope_tm4.c + ${OPENAIR_DIR}/common/utils/system.c ${T_SOURCE} ) target_link_libraries (dlsim_tm4 @@ -2533,18 +2537,21 @@ target_link_libraries(ldpctest SIMU PHY PHY_NR m ${ATLAS_LIBRARIES}) add_executable(nr_dlschsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/dlschsim.c ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/system.c ${T_SOURCE}) target_link_libraries(nr_dlschsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) add_executable(nr_pbchsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/pbchsim.c ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/system.c ${T_SOURCE}) target_link_libraries(nr_pbchsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB CONFIG_LIB -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) add_executable(nr_dlsim ${OPENAIR1_DIR}/SIMULATION/NR_PHY/dlsim.c ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/system.c ${T_SOURCE}) target_link_libraries(nr_dlsim -Wl,--start-group UTIL SIMU PHY_COMMON PHY_NR PHY_NR_UE SCHED_NR_LIB SCHED_NR_UE_LIB MAC_NR MAC_UE_NR MAC_NR_COMMON RRC_LIB NR_RRC_LIB CONFIG_LIB L2_NR -Wl,--end-group m pthread ${ATLAS_LIBRARIES} ${T_LIB} dl) @@ -2560,6 +2567,7 @@ foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim pr add_executable(${myExe} ${OPENAIR1_DIR}/SIMULATION/LTE_PHY/${myExe}.c ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/system.c ${XFORMS_SOURCE} ${T_SOURCE} ${CONFIG_SOURCES} diff --git a/common/utils/system.c b/common/utils/system.c index 0a116661af..31c1035129 100644 --- a/common/utils/system.c +++ b/common/utils/system.c @@ -196,48 +196,6 @@ void start_background_system(void) { background_system_process(); } -void thread_top_init(char *thread_name, - int affinity, - uint64_t runtime, - uint64_t deadline, - uint64_t period) { -#ifdef DEADLINE_SCHEDULER - struct sched_attr attr; - unsigned int flags = 0; - attr.size = sizeof(attr); - attr.sched_flags = 0; - attr.sched_nice = 0; - attr.sched_priority = 0; - attr.sched_policy = SCHED_DEADLINE; - attr.sched_runtime = runtime; - attr.sched_deadline = deadline; - attr.sched_period = period; - - AssertFatal(sched_setattr(0, &attr, flags) == 0, "[SCHED] eNB tx thread: sched_setattr failed\n"); - -#else -#ifdef CPU_AFFINITY - /* Set affinity mask to include CPUs 2 to MAX_CPUS */ - /* CPU 0 is reserved for UHD threads */ /* CPU 1 is reserved for all RX_TX threads */ - /* Enable CPU Affinity only if number of CPUs > 2 */ - cpu_set_t cpuset; - CPU_ZERO(&cpuset); - if (affinity == 0) { - LOG_W(HW,"thread_top_init() called with affinity==0, but overruled by #ifdef CPU_AFFINITY\n"); - } else if (get_nprocs() > 2) { - for (j = 2; j < get_nprocs(); j++) - CPU_SET(j, &cpuset); - AssertFatal( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) == 0, "Error setting processor affinity"); - } -#endif //CPU_AFFINITY - - struct sched_param sparam={0}; - sparam.sched_priority = OAI_PRIORITY_RT; - AssertFatal(pthread_setschedparam(pthread_self(),SCHED_FIFO , &sparam) == 0,"Error setting thread priority"); - pthread_setname_np(pthread_self(), thread_name); -#endif - mlockall(MCL_CURRENT | MCL_FUTURE); -} void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){ pthread_attr_t attr; diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index babf169103..dae14684c1 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -673,7 +673,7 @@ int main( int argc, char **argv ) { set_taus_seed (0); tpool_t pool; Tpool = &pool; - char params[]="2,3"; + char params[]="-1,-1"; initTpool(params, Tpool, false); cpuf=get_cpu_freq_GHz(); itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index 56f4d7cb1e..d99abd70a0 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -36,6 +36,7 @@ //#include "extern.h" #include "PHY/sse_intrin.h" #include "T.h" +#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h" #ifndef USER_MODE #define NOCYGWIN_STATIC static diff --git a/openair1/PHY/defs_RU.h b/openair1/PHY/defs_RU.h index 73e75bb992..76769ed4db 100644 --- a/openair1/PHY/defs_RU.h +++ b/openair1/PHY/defs_RU.h @@ -191,6 +191,25 @@ typedef struct RU_proc_t_s { int first_rx; /// flag to indicate first TX transmission int first_tx; + /// pthread attributes for RU FH processing thread + pthread_attr_t attr_FH; + pthread_attr_t attr_FH1; + /// pthread attributes for RU prach + pthread_attr_t attr_prach; +#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + /// pthread attributes for RU prach BL/CE UEs + pthread_attr_t attr_prach_br; +#endif + /// pthread attributes for RU synch thread + pthread_attr_t attr_synch; + /// pthread attributes for asynchronous RX thread + pthread_attr_t attr_asynch_rxtx; + /// pthread attributes for worker fep thread + pthread_attr_t attr_fep; + /// pthread attributes for worker feptx thread + pthread_attr_t attr_feptx; + /// pthread attributes for emulated RF + pthread_attr_t attr_emulateRF; /// scheduling parameters for RU FH thread struct sched_param sched_param_FH; struct sched_param sched_param_FH1; diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index 8a962bb839..24be9688dc 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -373,6 +373,8 @@ typedef struct { int instance_cnt; /// pthread structure for RXn-TXnp4 processing thread pthread_t pthread; + /// pthread attributes for RXn-TXnp4 processing thread + pthread_attr_t attr; /// condition variable for tx processing thread pthread_cond_t cond; /// mutex for RXn-TXnp4 processing thread @@ -428,6 +430,12 @@ typedef struct gNB_L1_proc_t_s { int first_rx; /// flag to indicate first TX transmission int first_tx; + /// pthread attributes for single gNB processing thread + pthread_attr_t attr_single; + /// pthread attributes for prach processing thread + pthread_attr_t attr_prach; + /// pthread attributes for asynchronous RX thread + pthread_attr_t attr_asynch_rxtx; /// scheduling parameters for parallel turbo-decoder thread struct sched_param sched_param_td; /// scheduling parameters for parallel turbo-encoder thread diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c index 0edc587263..679f92a1a0 100644 --- a/targets/ARCH/rfsimulator/simulator.c +++ b/targets/ARCH/rfsimulator/simulator.c @@ -201,6 +201,7 @@ sin_addr: int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, void **samplesVoid, int nsamps, int nbAnt, int flags) { rfsimulator_state_t *t = device->priv; + LOG_D(HW,"sending %d samples at time: %ld\n", nsamps, timestamp); for (int i=0; ibuf[i]; @@ -231,7 +232,7 @@ static bool flushInput(rfsimulator_state_t *t) { // Process all incoming events on sockets // store the data in lists struct epoll_event events[FD_SETSIZE]= {0}; - int nfds = epoll_wait(t->epollfd, events, FD_SETSIZE, 200); + int nfds = epoll_wait(t->epollfd, events, FD_SETSIZE, 20); if ( nfds==-1 ) { if ( errno==EINTR || errno==EAGAIN ) @@ -310,6 +311,7 @@ static bool flushInput(rfsimulator_state_t *t) { } if ( b->headerMode==false ) { + LOG_D(HW,"Set b->lastReceivedTS %ld\n", b->lastReceivedTS); b->lastReceivedTS=b->th.timestamp+b->th.size-byteToSample(b->remainToTransfer,b->th.nbAnt); if ( b->remainToTransfer==0) { @@ -364,13 +366,14 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo do { have_to_wait=false; - for ( int sock=0; sockbuf[sock].circularBuf && t->buf[sock].alreadyRead && //>= t->initialAhead && (t->nextTimestamp+nsamps) > t->buf[sock].lastReceivedTS ) { have_to_wait=true; break; } + } if (have_to_wait) /*printf("Waiting on socket, current last ts: %ld, expected at least : %ld\n", diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h index 9645acf4dd..9b4ee23dc8 100644 --- a/targets/COMMON/openairinterface5g_limits.h +++ b/targets/COMMON/openairinterface5g_limits.h @@ -8,10 +8,10 @@ # define NUMBER_OF_NR_RU_MAX 2 # ifndef PHYSIM # ifndef UE_EXPANSION -# define NUMBER_OF_UE_MAX 16 -# define NUMBER_OF_NR_UE_MAX 16 -# define NUMBER_OF_CONNECTED_eNB_MAX 3 -# define NUMBER_OF_CONNECTED_gNB_MAX 3 +# define NUMBER_OF_UE_MAX 4 +# define NUMBER_OF_NR_UE_MAX 4 +# define NUMBER_OF_CONNECTED_eNB_MAX 1 +# define NUMBER_OF_CONNECTED_gNB_MAX 1 # else # define NUMBER_OF_UE_MAX 256 # define NUMBER_OF_NR_UE_MAX 256 From b6c2f9c1df6421cc6f7123eeae740824475599ee Mon Sep 17 00:00:00 2001 From: laurent Date: Wed, 15 May 2019 16:05:05 +0200 Subject: [PATCH 112/117] trace in case tx/rx mismatch --- executables/openairinterface5g_limits.h | 8 ++++---- targets/ARCH/rfsimulator/simulator.c | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/executables/openairinterface5g_limits.h b/executables/openairinterface5g_limits.h index 53ee79a61d..ca29078758 100644 --- a/executables/openairinterface5g_limits.h +++ b/executables/openairinterface5g_limits.h @@ -8,10 +8,10 @@ #define NUMBER_OF_NR_RU_MAX 2 #ifndef PHYSIM #ifndef UE_EXPANSION - #define NUMBER_OF_UE_MAX 16 - #define NUMBER_OF_NR_UE_MAX 16 - #define NUMBER_OF_CONNECTED_eNB_MAX 3 - #define NUMBER_OF_CONNECTED_gNB_MAX 3 + #define NUMBER_OF_UE_MAX 4 + #define NUMBER_OF_NR_UE_MAX 4 + #define NUMBER_OF_CONNECTED_eNB_MAX 1 + #define NUMBER_OF_CONNECTED_gNB_MAX 1 #else #define NUMBER_OF_UE_MAX 256 #define NUMBER_OF_NR_UE_MAX 256 diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c index 679f92a1a0..f3847cfdab 100644 --- a/targets/ARCH/rfsimulator/simulator.c +++ b/targets/ARCH/rfsimulator/simulator.c @@ -198,7 +198,7 @@ sin_addr: t->buf[sock].alreadyRead=true; // UE will start blocking on read return 0; } - +uint64_t lastW=-1; int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, void **samplesVoid, int nsamps, int nbAnt, int flags) { rfsimulator_state_t *t = device->priv; LOG_D(HW,"sending %d samples at time: %ld\n", nsamps, timestamp); @@ -222,7 +222,7 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi fullwrite(ptr->conn_sock, (void *)tmpSamples, sampleToByte(nsamps,nbAnt), t); } } - + lastW=timestamp; LOG_D(HW,"sent %d samples at time: %ld->%ld, energy in first antenna: %d\n", nsamps, timestamp, timestamp+nsamps, signal_energy(samplesVoid[0], nsamps) ); return nsamps; @@ -306,6 +306,8 @@ static bool flushInput(rfsimulator_state_t *t) { } b->lastReceivedTS=b->th.timestamp; + AssertFatal(lastW == -1 || ( abs((double)lastW-b->lastReceivedTS) < (double)CirSize), + "Tx/Rx shift too large Tx:%lu, Rx:%lu\n", lastW, b->lastReceivedTS); b->transferPtr=(char *)&b->circularBuf[b->lastReceivedTS%CirSize]; b->remainToTransfer=sampleToByte(b->th.size, b->th.nbAnt); } From db9e181d407bf0da3cc3ba8f3d0d7398a249d2a0 Mon Sep 17 00:00:00 2001 From: Boris Djalal Date: Tue, 7 May 2019 16:24:54 +0200 Subject: [PATCH 113/117] CI: adding support for the N300 gNB + NR-UE testing -- pipeline is polling the develop-nr branch -- new conf file / new scenario files -- main python now supports LTE and 5G-NR executables in a Ubuntu/CentOS env --- ci-scripts/Jenkinsfile-poll-gNB-UE | 374 +++++++ .../gnb.band78.tm1.106PRB.usrpn300.conf | 298 ++++++ ci-scripts/main.py | 936 ++++++++++++++++-- ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml | 64 ++ ci-scripts/xml_files/gnb_usrp_build.xml | 39 + ci-scripts/xml_files/nr_ue_usrp_build.xml | 40 + targets/RT/USER/nr-softmodem.c | 2 + 7 files changed, 1670 insertions(+), 83 deletions(-) create mode 100644 ci-scripts/Jenkinsfile-poll-gNB-UE create mode 100644 ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf create mode 100644 ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml create mode 100644 ci-scripts/xml_files/gnb_usrp_build.xml create mode 100644 ci-scripts/xml_files/nr_ue_usrp_build.xml diff --git a/ci-scripts/Jenkinsfile-poll-gNB-UE b/ci-scripts/Jenkinsfile-poll-gNB-UE new file mode 100644 index 0000000000..532415b016 --- /dev/null +++ b/ci-scripts/Jenkinsfile-poll-gNB-UE @@ -0,0 +1,374 @@ +#!/bin/groovy +/* +* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The OpenAirInterface Software Alliance licenses this file to You under +* the OAI Public License, Version 1.1 (the "License"); you may not use this file +* except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.openairinterface.org/?page_id=698 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*------------------------------------------------------------------------------- +* For more information about the OpenAirInterface (OAI) Software Alliance: +* contact@openairinterface.org +*/ + + +// Abstraction function to send social media messages: +// like on Slack or Mattermost +def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) { + if (params.pipelineUsesSlack != null) { + if (params.pipelineUsesSlack) { + slackSend channel: pipeChannel, color: pipeColor, message: pipeMessage + } + } +} + +// Location of the test XML file to be run +def testXMLFile = params.pythonTestXmlFile +def mainPythonAllXmlFiles = "" + +// Name of the phone resource +def ciUSRPsResource = params.USRPsResource + +// Terminate Status +def termUE = 0 +def termENB = 1 +def termStatusArray = new Boolean[2] +termStatusArray[termUE] = false +termStatusArray[termENB] = false + +// Global Parameters. +def eNB_Repository +def eNB_Branch +def eNB_CommitID +def eNB_AllowMergeRequestProcess = false +def eNB_TargetBranch +def PROJECT_NAME = "test-boris" +def GIT_COMMIT_AUTHORi +def GIT_COMMIT_EMAIL +// Reversing list because pop() will take the last (right-most) element +//def modeList = ['TesteNB', 'TestUE', 'TesteNB'].reverse() + +// Global Parameters not to break the main.py command line and code. +def ADB_IPAddress = "none" +def ADB_Username = "none" +def ADB_Password = "none" +def EPC_IPAddress = "none" +def EPC_Username = "none" +def EPC_Password = "none" + + + +pipeline { + agent { + label pythonExecutor + } + options { + disableConcurrentBuilds() + gitLabConnection('OAI GitLab') + ansiColor('xterm') + lock (ciUSRPsResource) + } + + stages { + stage ('Retrieve latest from branch') { + steps { + script { + checkout([$class: 'GitSCM', branches: [[name: "${params.Branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://gitlab.eurecom.fr/oai/openairinterface5g.git']]]) + sh "git clean -x -d -ff" + sh "git log -n1" + } + } + } + stage ("print latest commit info") { + steps { + script { + echo "Building on: " + echo " Repository -- ${GIT_URL}" + echo " Branch -- ${GIT_BRANCH}" + echo " Commit -- ${GIT_COMMIT}" + } + } + } + stage ("Verify Parameters") { + steps { + script { + JOB_TIMESTAMP = sh returnStdout: true, script: 'date --utc --rfc-3339=seconds | sed -e "s#+00:00##"' + JOB_TIMESTAMP = JOB_TIMESTAMP.trim() + + echo '\u2705 \u001B[32mVerify Parameters\u001B[0m' + def allParametersPresent = true + + // It is already too late to check it + if (params.pythonExecutor != null) { + echo "eNB CI executor node : ${pythonExecutor}" + } + if (params.eNB_Repository == null) { + eNB_Repository = GIT_URL + } else { + eNB_Repository = params.eNB_Repository + } + echo "eNB_Repository = ${eNB_Repository}" + if (params.eNB_Branch== null) { + eNB_Branch = GIT_BRANCH + } else { + eNB_Branch = params.eNB_Branch + } + echo "eNB_Branch = ${eNB_Branch}" + if (params.eNB_CommitID == null) { + eNB_CommitID = GIT_COMMIT + } else { + eNB_CommitID = params.eNB_CommitID + } + echo "eNB_CommitID = ${eNB_CommitID}" + // If not present picking a default XML file + if (params.pythonTestXmlFile == null) { + // picking default + testXMLFile = 'xml_files/gnb_usrp_build.xml' + echo "Test XML file(default): ${testXMLFile}" + mainPythonAllXmlFiles += "--XMLTestFile=" + testXMLFile + " " + } else { + String[] myXmlTestSuite = testXMLFile.split("\\r?\\n") + for (xmlFile in myXmlTestSuite) { + if (fileExists("ci-scripts/" + xmlFile)) { + mainPythonAllXmlFiles += "--XMLTestFile=" + xmlFile + " " + echo "Test XML file : ${xmlFile}" + } + } + } + // If not present picking a default Stage Name + if (params.pipelineTestStageName == null) { + // picking default + testStageName = 'Template Test Stage' + } + + if (params.USRPsResource == null) { + allParametersPresent = false + } + + if (params.eNB_IPAddress == null) { + allParametersPresent = false + } + if (params.UE_IPAddress == null) { + allParametersPresent = false + } + if (params.eNB_SourceCodePath == null) { + allParametersPresent = false + } + if (params.eNB_Credentials == null) { + allParametersPresent = false + } + if (params.UE_Credentials == null) { + allParametersPresent = false + } + GIT_COMMIT_AUTHOR = sh ( + script: 'git show -s --pretty=%an', + returnStdout: true + ).trim() + echo "The author of the commit is: ${GIT_COMMIT_AUTHOR}" + GIT_COMMIT_EMAIL = sh ( + script: 'git show -s --pretty=%ae', + returnStdout: true + ).trim() + echo "The email of the author is: ${GIT_COMMIT_EMAIL}" + if (allParametersPresent) { + echo "All parameters are present" + } else { + echo "Some parameters are missing" + sh "./ci-scripts/fail.sh" + } + } + } + } + + stage ("Build and Test") { + steps { + script { + dir ('ci-scripts') { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'], + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.UE_Credentials}", usernameVariable: 'UE_Username', passwordVariable: 'UE_Password'] + ]) { + sh "python3 main.py --mode=InitiateHtml --eNBRepository=${eNB_Repository} --eNBBranch=${eNB_Branch} --eNBCommitID=${eNB_CommitID} --eNB_AllowMerge=${eNB_AllowMergeRequestProcess} --ADBIPAddress=${ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password} --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} ${mainPythonAllXmlFiles}" + String[] myXmlTestSuite = testXMLFile.split("\\r?\\n") + for (xmlFile in myXmlTestSuite) { + if (fileExists(xmlFile)) { + try { + sh "python3 main.py --mode=TesteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --UEIPAddress=${params.eNB_IPAddress} --UEUserName=${eNB_Username} --UEPassword=${eNB_Password} --eNBBranch=${eNB_Branch} --eNBSourceCodePath=${params.eNB_SourceCodePath} --UESourceCodePath=${params.eNB_SourceCodePath} --eNBRepository=${eNB_Repository} --eNBCommitID=${eNB_CommitID} --ADBIPAddress=${ADB_IPAddress} --EPCIPAddress=${EPC_IPAddress} --XMLTestFile=${xmlFile}" + } catch (Exception e) { + currentBuild.result = 'FAILURE' + } + } + } + } + } + } + } + } + + stage ("Terminate") { + parallel { + stage('Terminate NR UE') { + steps { + echo '\u2705 \u001B[32mTerminate NR UE\u001B[0m' + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'UE_Username', passwordVariable: 'UE_Password'] + ]) { + sh "python3 ci-scripts/main.py --mode=TerminateOAIUE --UEIPAddress=${params.eNB_IPAddress} --UEUserName=${UE_Username} --UEPassword=${UE_Password}" + } + } + post { + success { + script { + termStatusArray[termUE] = true + } + } + } + } + stage('Terminate NR eNB') { + steps { + echo '\u2705 \u001B[32mTerminate NR eNB\u001B[0m' + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'] + ]) { + sh "python3 ci-scripts/main.py --mode=TerminateeNB --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password}" + } + } + post { + success { + script { + termStatusArray[termENB] = true + } + } + } + } + } + } + + stage('Log Collection') { + parallel { + stage('Log Collection (gNB and NR UE - Build)') { + steps { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'] + ]) { + echo '\u2705 \u001B[32mLog Collection (gNB and NR UE - Build)\u001B[0m' + sh "python3 ci-scripts/main.py --mode=LogCollectBuild --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath}" + + echo '\u2705 \u001B[32mLog Transfer (gNB and NR UE - Build)\u001B[0m' + sh "sshpass -p \'${eNB_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress}:${eNB_SourceCodePath}/cmake_targets/build.log.zip ./build.log.${env.BUILD_ID}.zip || true" + } + script { + if(fileExists("build.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "build.log.${env.BUILD_ID}.zip" + } + } + } + } + stage('Log Collection (gNB - Run)') { + steps { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'] + ]) { + echo '\u2705 \u001B[32mLog Collection (gNB - Run)\u001B[0m' + sh "python3 ci-scripts/main.py --mode=LogCollecteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBSourceCodePath=${params.eNB_SourceCodePath}" + + echo '\u2705 \u001B[32mLog Transfer (gNB - Run)\u001B[0m' + sh "sshpass -p \'${eNB_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress}:${eNB_SourceCodePath}/cmake_targets/enb.log.zip ./enb.log.${env.BUILD_ID}.zip || true" + } + script { + if(fileExists("enb.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "enb.log.${env.BUILD_ID}.zip" + } + if(fileExists("ci-scripts/test_results.html")) { + sh "mv ci-scripts/test_results.html test_results-${JOB_NAME}.html" + sh "sed -i -e 's#TEMPLATE_JOB_NAME#${JOB_NAME}#' -e 's@build #TEMPLATE_BUILD_ID@build #${BUILD_ID}@' -e 's#Build-ID: TEMPLATE_BUILD_ID#Build-ID: ${BUILD_ID}#' -e 's#TEMPLATE_STAGE_NAME#${testStageName}#' test_results-${JOB_NAME}.html" + archiveArtifacts "test_results-${JOB_NAME}.html" + } + } + } + } + stage('Log Collection (NR UE - Run)') { + steps { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'] + ]) { + echo '\u2705 \u001B[32mLog Collection (gNB - Run)\u001B[0m' + sh "python3 ci-scripts/main.py --mode=LogCollectOAIUE --UEIPAddress=${params.eNB_IPAddress} --UEUserName=${eNB_Username} --UEPassword=${eNB_Password} --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --UESourceCodePath=${params.eNB_SourceCodePath}" + + echo '\u2705 \u001B[32mLog Transfer (gNB - Run)\u001B[0m' + sh "sshpass -p \'${eNB_Password}\' scp -o 'StrictHostKeyChecking no' -o 'ConnectTimeout 10' ${eNB_Username}@${params.eNB_IPAddress}:${eNB_SourceCodePath}/cmake_targets/ue.log.zip ./ue.log.${env.BUILD_ID}.zip || true" + } + script { + if(fileExists("ue.log.${env.BUILD_ID}.zip")) { + archiveArtifacts "ue.log.${env.BUILD_ID}.zip" + } + } + } + } + } + } + } + + post { + always { + script { + if ("MERGE".equals(env.gitlabActionType)) { + echo "This is a MERGE event" + } else { + gitlabCommitStatus(name: "Test-gNB-nrUE") { + if ((currentBuild.result == null) || (currentBuild.result == 'SUCCESS')) { + echo "Setting the gitlab commit status to pass" + } else { + sh "./ci-scripts/fail.sh" + } + } + } + emailext attachmentsPattern: '*results*.html', + body: '''Hi, +Here are attached HTML report files for $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS! + +Regards, +OAI CI Team''', + replyTo: 'no-reply@openairinterface.org', + subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!', + to: GIT_COMMIT_EMAIL + } + } + success { + script { + def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")" + if ("MERGE".equals(env.gitlabActionType)) { + echo "This is a MERGE event" + //addGitLabMRComment comment: message + def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")" + sendSocialMediaMessage('ci-test', 'good', message2) + } else { + sendSocialMediaMessage('ci-test', 'good', message) + } + } + } + failure { + script { + def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")" + if ("MERGE".equals(env.gitlabActionType)) { + echo "This is a MERGE event" + //addGitLabMRComment comment: message + def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")" + sendSocialMediaMessage('ci-test', 'danger', message2) + } else { + sendSocialMediaMessage('ci-test', 'danger', message) + } + } + } + } +} + diff --git a/ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf b/ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf new file mode 100644 index 0000000000..e71bb00ffb --- /dev/null +++ b/ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf @@ -0,0 +1,298 @@ +Active_gNBs = ( "gNB-Eurecom-5GNRBox"); +# Asn1_verbosity, choice in: none, info, annoying +Asn1_verbosity = "none"; + +gNBs = +( + { + ////////// Identification parameters: + gNB_ID = 0xe00; + + cell_type = "CELL_MACRO_GNB"; + + gNB_name = "gNB-Eurecom-5GNRBox"; + + // Tracking area code, 0x0000 and 0xfffe are reserved values + tracking_area_code = 1; + + plmn_list = ({mcc = 208; mnc = 93; mnc_length = 2;}); + + tr_s_preference = "local_mac" + + ////////// Physical parameters: + + component_carriers = ( + { + node_function = "3GPP_gNODEB"; + node_timing = "synch_to_ext_device"; + node_synch_ref = 0; + frame_type = "TDD"; + DL_prefix_type = "NORMAL"; + UL_prefix_type = "NORMAL"; + eutra_band = 78; + downlink_frequency = 3510000000L; + uplink_frequency_offset = -120000000; + Nid_cell = 0; + N_RB_DL = 106; + nb_antenna_ports = 1; + nb_antennas_tx = 1; + nb_antennas_rx = 1; + tx_gain = 90; + rx_gain = 125; + MIB_subCarrierSpacingCommon = 30; + MIB_ssb_SubcarrierOffset = 0; + MIB_dmrs_TypeA_Position = 2; + pdcch_ConfigSIB1 = 0; + SIB1_frequencyOffsetSSB = "khz5"; + SIB1_ssb_PeriodicityServingCell = 5; + SIB1_ss_PBCH_BlockPower = -60; + absoluteFrequencySSB = 0; + DL_FreqBandIndicatorNR = 15; + DL_absoluteFrequencyPointA = 15; + DL_offsetToCarrier = 15; + DL_SCS_SubcarrierSpacing = "kHz30"; + DL_SCS_SpecificCarrier_k0 = 0; + DL_carrierBandwidth = 15; + DL_locationAndBandwidth = 15; + DL_BWP_SubcarrierSpacing = "kHz30"; + DL_BWP_prefix_type = "NORMAL"; + UL_FreqBandIndicatorNR = 15; + UL_absoluteFrequencyPointA = 13; + UL_additionalSpectrumEmission = 3; + UL_p_Max = -1; + UL_frequencyShift7p5khz = "TRUE"; + UL_offsetToCarrier = 10; + UL_SCS_SubcarrierSpacing = "kHz30"; + UL_SCS_SpecificCarrier_k0 = 0; + UL_carrierBandwidth = 15; + UL_locationAndBandwidth = 15; + UL_BWP_SubcarrierSpacing = "kHz30"; + UL_BWP_prefix_type = "NORMAL"; + UL_timeAlignmentTimerCommon = "infinity"; + ServingCellConfigCommon_n_TimingAdvanceOffset = "n0" + ServingCellConfigCommon_ssb_PositionsInBurst_PR = 0x01; + ServingCellConfigCommon_ssb_periodicityServingCell = 10; + ServingCellConfigCommon_dmrs_TypeA_Position = 2; + NIA_SubcarrierSpacing = "kHz15"; + ServingCellConfigCommon_ss_PBCH_BlockPower = -60; + referenceSubcarrierSpacing = "kHz15"; + dl_UL_TransmissionPeriodicity = "ms0p5"; + nrofDownlinkSlots = 10; + nrofDownlinkSymbols = 10; + nrofUplinkSlots = 10; + nrofUplinkSymbols = 10; + rach_totalNumberOfRA_Preambles = 63; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_choice = "oneEighth"; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneEighth = 4; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneFourth = 8; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_oneHalf = 16; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_one = 24; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_two = 32; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_four = 8; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_eight = 4; + rach_ssb_perRACH_OccasionAndCB_PreamblesPerSSB_sixteen = 2; + rach_groupBconfigured = "ENABLE"; + rach_ra_Msg3SizeGroupA = 56; + rach_messagePowerOffsetGroupB = "dB0"; + rach_numberOfRA_PreamblesGroupA = 32; + rach_ra_ContentionResolutionTimer = 8; + rsrp_ThresholdSSB = 64; + rsrp_ThresholdSSB_SUL = 64; + prach_RootSequenceIndex_choice = "l839"; + prach_RootSequenceIndex_l839 = 0; + prach_RootSequenceIndex_l139 = 0; + prach_msg1_SubcarrierSpacing = "kHz30"; + restrictedSetConfig = "unrestrictedSet"; + msg3_transformPrecoding = "ENABLE"; + prach_ConfigurationIndex = 10; + prach_msg1_FDM = "one"; + prach_msg1_FrequencyStart = 10; + zeroCorrelationZoneConfig = 10; + preambleReceivedTargetPower = -150; + preambleTransMax = 6; + powerRampingStep = "dB0"; + ra_ResponseWindow = 8; + groupHoppingEnabledTransformPrecoding = "ENABLE"; + msg3_DeltaPreamble = 0; + p0_NominalWithGrant = 0; + PUSCH_TimeDomainResourceAllocation_k2 = 0; + PUSCH_TimeDomainResourceAllocation_mappingType = "typeA"; + PUSCH_TimeDomainResourceAllocation_startSymbolAndLength = 0; + pucch_ResourceCommon = 0; + pucch_GroupHopping = "neither"; + hoppingId = 0; + p0_nominal = -30; + PDSCH_TimeDomainResourceAllocation_k0 = 2; + PDSCH_TimeDomainResourceAllocation_mappingType = "typeA"; + PDSCH_TimeDomainResourceAllocation_startSymbolAndLength = 0; + rateMatchPatternId = 0; + RateMatchPattern_patternType = "bitmaps"; + symbolsInResourceBlock = "oneSlot"; + periodicityAndPattern = 2; + RateMatchPattern_controlResourceSet = 5; + RateMatchPattern_subcarrierSpacing = "kHz30"; + RateMatchPattern_mode = "dynamic"; + controlResourceSetZero = 0; + searchSpaceZero = 0; + searchSpaceSIB1 = 10; + searchSpaceOtherSystemInformation = 10; + pagingSearchSpace = 10; + ra_SearchSpace = 10; + PDCCH_common_controlResourceSetId = 5; + PDCCH_common_ControlResourceSet_duration = 2; + PDCCH_cce_REG_MappingType = "nonInterleaved"; + PDCCH_reg_BundleSize = 3; + PDCCH_interleaverSize = 3; + PDCCH_shiftIndex = 10; + PDCCH_precoderGranularity = "sameAsREG-bundle"; + PDCCH_TCI_StateId = 32; + tci_PresentInDCI = "ENABLE"; + PDCCH_DMRS_ScramblingID = 0; + SearchSpaceId = 10; + commonSearchSpaces_controlResourceSetId = 5; + SearchSpace_monitoringSlotPeriodicityAndOffset_choice = "sl1"; + SearchSpace_monitoringSlotPeriodicityAndOffset_value = 0; + SearchSpace_duration = 2; + SearchSpace_nrofCandidates_aggregationLevel1 = 0; + SearchSpace_nrofCandidates_aggregationLevel2 = 0; + SearchSpace_nrofCandidates_aggregationLevel4 = 0; + SearchSpace_nrofCandidates_aggregationLevel8 = 0; + SearchSpace_nrofCandidates_aggregationLevel16 = 0; + SearchSpace_searchSpaceType = "common"; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel1 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel2 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel4 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel8 = 1; + Common_dci_Format2_0_nrofCandidates_SFI_aggregationLevel16 = 1; + Common_dci_Format2_3_monitoringPeriodicity = 1; + Common_dci_Format2_3_nrofPDCCH_Candidates = 1; + ue_Specific__dci_Formats = "formats0-0-And-1-0"; + RateMatchPatternLTE_CRS_carrierFreqDL = 6; + RateMatchPatternLTE_CRS_carrierBandwidthDL = 6; + RateMatchPatternLTE_CRS_nrofCRS_Ports = 1; + RateMatchPatternLTE_CRS_v_Shift = 0; + RateMatchPatternLTE_CRS_radioframeAllocationPeriod = 1; + RateMatchPatternLTE_CRS_radioframeAllocationOffset = 0; + RateMatchPatternLTE_CRS_subframeAllocation_choice = "oneFrame"; + } + ); + + + srb1_parameters : + { + # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500] + timer_poll_retransmit = 80; + + # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200] + timer_reordering = 35; + + # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500] + timer_status_prohibit = 0; + + # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)] + poll_pdu = 4; + + # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)] + poll_byte = 99999; + + # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32] + max_retx_threshold = 4; + } + + # ------- SCTP definitions + SCTP : + { + # Number of streams to use in input/output + SCTP_INSTREAMS = 2; + SCTP_OUTSTREAMS = 2; + }; + + + ////////// MME parameters: + mme_ip_address = ( { ipv4 = "192.168.12.26"; + ipv6 = "192:168:30::17"; + active = "yes"; + preference = "ipv4"; + } + ); + + NETWORK_INTERFACES : + { + + GNB_INTERFACE_NAME_FOR_S1_MME = "eth0"; + GNB_IPV4_ADDRESS_FOR_S1_MME = "192.168.12.111/24"; + GNB_INTERFACE_NAME_FOR_S1U = "eth0"; + GNB_IPV4_ADDRESS_FOR_S1U = "192.168.12.111/24"; + GNB_PORT_FOR_S1U = 2152; # Spec 2152 + }; + } +); + +MACRLCs = ( + { + num_cc = 1; + tr_s_preference = "local_L1"; + tr_n_preference = "local_RRC"; + } +); + +L1s = ( + { + num_cc = 1; + tr_n_preference = "local_mac"; + } +); + +RUs = ( + { + local_rf = "yes" + nb_tx = 1 + nb_rx = 1 + att_tx = 0 + att_rx = 0; + bands = [7]; + max_pdschReferenceSignalPower = -27; + max_rxgain = 114; + eNB_instances = [0]; + sdr_addrs = "addr=192.168.20.2,second_addr=192.168.10.2,mgmt_addr=192.168.20.2,clock_source=external,time_source=external"; + + } +); + +THREAD_STRUCT = ( + { + #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT" + parallel_config = "PARALLEL_RU_L1_TRX_SPLIT"; + #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE" + worker_config = "WORKER_ENABLE"; + } +); + +NETWORK_CONTROLLER : +{ + FLEXRAN_ENABLED = "no"; + FLEXRAN_INTERFACE_NAME = "lo"; + FLEXRAN_IPV4_ADDRESS = "127.0.0.1"; + FLEXRAN_PORT = 2210; + FLEXRAN_CACHE = "/mnt/oai_agent_cache"; + FLEXRAN_AWAIT_RECONF = "no"; +}; + + log_config : + { + global_log_level ="info"; + global_log_verbosity ="medium"; + hw_log_level ="info"; + hw_log_verbosity ="medium"; + phy_log_level ="info"; + phy_log_verbosity ="medium"; + mac_log_level ="info"; + mac_log_verbosity ="high"; + rlc_log_level ="info"; + rlc_log_verbosity ="medium"; + pdcp_log_level ="info"; + pdcp_log_verbosity ="medium"; + rrc_log_level ="info"; + rrc_log_verbosity ="medium"; + }; + diff --git a/ci-scripts/main.py b/ci-scripts/main.py index dc101fe7ea..b6bac27831 100644 --- a/ci-scripts/main.py +++ b/ci-scripts/main.py @@ -1,3 +1,4 @@ +# dummy commit #/* # * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more # * contributor license agreements. See the NOTICE file distributed with @@ -43,6 +44,9 @@ ENB_PROCESS_SEG_FAULT = -11 ENB_PROCESS_ASSERTION = -12 ENB_PROCESS_REALTIME_ISSUE = -13 ENB_PROCESS_NOLOGFILE_TO_ANALYZE = -14 +UE_PROCESS_NOLOGFILE_TO_ANALYZE = -20 +UE_PROCESS_COULD_NOT_SYNC = -21 +UE_PROCESS_ASSERTION = -22 HSS_PROCESS_FAILED = -2 HSS_PROCESS_OK = +2 MME_PROCESS_FAILED = -3 @@ -64,6 +68,7 @@ import xml.etree.ElementTree as ET import logging import datetime import signal +#import platform from multiprocessing import Process, Lock, SimpleQueue logging.basicConfig( level=logging.DEBUG, @@ -98,8 +103,11 @@ class SSHConnection(): self.desc = '' self.Build_eNB_args = '' self.Initialize_eNB_args = '' + self.air_interface = 'lte' self.eNBLogFile = '' self.eNB_instance = '' + self.eNBOptions = '' + self.rruOptions = '' self.ping_args = '' self.ping_packetloss_threshold = '' self.iperf_args = '' @@ -120,13 +128,25 @@ class SSHConnection(): self.htmlTabNames = [] self.htmlTabIcons = [] self.finalStatus = False + self.OsVersion = '' + self.KernelVersion = '' + self.UhdVersion = '' + self.UsrpBoard = '' + self.CpuNb = '' + self.CpuModel = '' + self.CpuMHz = '' + self.UEIPAddress = '' + self.UEUserName = '' + self.UEPassword = '' + self.UE_instance = '' + self.UELogFile = '' + self.UESourceCodePath = '' + self.Build_OAI_UE_args = '' + self.Initialize_OAI_UE_args = '' + self.Initialize_OAI_eNB_args = '' + self.clean_repository = True self.eNBOsVersion = '' - self.eNBKernelVersion = '' - self.eNBUhdVersion = '' - self.eNBCpuNb = '' - self.eNBCpuModel = '' - self.eNBCpuMHz = '' - + def open(self, ipaddress, username, password): count = 0 connect_status = False @@ -321,11 +341,48 @@ class SSHConnection(): self.command('mkdir -p build_log_' + self.testCase_id, '\$', 5) self.command('mv log/* ' + 'build_log_' + self.testCase_id, '\$', 5) self.command('mv compile_oai_enb.log ' + 'build_log_' + self.testCase_id, '\$', 5) - # Workaround to run with develop-nr - self.command('if [ -e ran_build ]; then cp -rf ran_build lte_build_oai; fi', '\$', 30) self.close() self.CreateHtmlTestRow(self.Build_eNB_args, 'OK', ALL_PROCESSES_OK) + def BuildOAIUE(self): + if self.UEIPAddress == '' or self.eNBRepository == '' or self.eNBBranch == '' or self.UEUserName == '' or self.UEPassword == '' or self.UESourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + self.open(self.UEIPAddress, self.UEUserName, self.UEPassword) + self.command('mkdir -p ' + self.UESourceCodePath, '\$', 5) + self.command('cd ' + self.UESourceCodePath, '\$', 5) + self.command('if [ ! -e .git ]; then stdbuf -o0 git clone ' + self.eNBRepository + ' .; else stdbuf -o0 git fetch; fi', '\$', 600) + # here add a check if git clone or git fetch went smoothly + self.command('git config user.email "jenkins@openairinterface.org"', '\$', 5) + self.command('git config user.name "OAI Jenkins"', '\$', 5) + if self.clean_repository: + pass + self.command('echo ' + self.UEPassword + ' | sudo -S git clean -x -d -ff', '\$', 30) + # if the commit ID is provided use it to point to it + if self.eNBCommitID != '': + self.command('git checkout -f ' + self.eNBCommitID, '\$', 5) + # if the branch is not develop, then it is a merge request and we need to do + # the potential merge. Note that merge conflicts should already been checked earlier + if (self.eNB_AllowMerge): + if self.eNBTargetBranch == '': + if (self.eNBBranch != 'develop') and (self.eNBBranch != 'origin/develop'): + self.command('git merge --ff origin/develop -m "Temporary merge for CI"', '\$', 5) + else: + logging.debug('Merging with the target branch: ' + self.eNBTargetBranch) + self.command('git merge --ff origin/' + self.eNBTargetBranch + ' -m "Temporary merge for CI"', '\$', 5) + self.command('source oaienv', '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('mkdir -p log', '\$', 5) + self.command('chmod 777 log', '\$', 5) + # no need to remove in log (git clean did the trick) + self.command('stdbuf -o0 ./build_oai ' + self.Build_OAI_UE_args + ' 2>&1 | stdbuf -o0 tee -a compile_oai_ue.log', 'Bypassing the Tests', 600) + self.command('mkdir -p build_log_' + self.testCase_id, '\$', 5) + self.command('mv log/* ' + 'build_log_' + self.testCase_id, '\$', 5) + self.command('mv compile_oai_ue.log ' + 'build_log_' + self.testCase_id, '\$', 5) + self.close() + self.CreateHtmlTestRow(self.Build_OAI_UE_args, 'OK', ALL_PROCESSES_OK, 'OAI UE') + + def InitializeHSS(self): if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '' or self.EPCType == '': Usage() @@ -411,6 +468,7 @@ class SSHConnection(): self.command('cd ' + self.eNBSourceCodePath, '\$', 5) # Initialize_eNB_args usually start with -O and followed by the location in repository full_config_file = self.Initialize_eNB_args.replace('-O ','') + extra_options = '' extIdx = full_config_file.find('.conf') if (extIdx > 0): extra_options = full_config_file[extIdx + 5:] @@ -431,6 +489,16 @@ class SSHConnection(): result = re.search('rru', str(config_file)) if result is not None: rruCheck = True + # do not reset board twice in IF4.5 case + result = re.search('rru|enb', str(config_file)) + if result is not None: + self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 30) + result = re.search('type: b200', str(self.ssh.before)) + if result is not None: + logging.debug('Found a B2xx device --> resetting it') + self.command('echo ' + self.eNBPassword + ' | sudo -S sudo b2xx_fx3_utils --reset-device', '\$', 5) + # Reloading FGPA bin firmware + self.command('echo ' + self.eNBPassword + ' | sudo -S uhd_find_devices', '\$', 30) # Make a copy and adapt to EPC / eNB IP addresses self.command('cp ' + full_config_file + ' ' + ci_full_config_file, '\$', 5) self.command('sed -i -e \'s/CI_MME_IP_ADDR/' + self.EPCIPAddress + '/\' ' + ci_full_config_file, '\$', 2); @@ -438,12 +506,20 @@ class SSHConnection(): # Launch eNB with the modified config file self.command('source oaienv', '\$', 5) self.command('cd cmake_targets', '\$', 5) - self.command('echo "ulimit -c unlimited && ./lte_build_oai/build/lte-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh ', '\$', 5) + self.command('echo "ulimit -c unlimited && ./ran_build/build/' + self.air_interface + '-softmodem -O ' + self.eNBSourceCodePath + '/' + ci_full_config_file + extra_options + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh ', '\$', 5) self.command('chmod 775 ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh ', '\$', 5) - self.command('echo ' + self.eNBPassword + ' | sudo -S rm -Rf enb_' + self.testCase_id + '.log', '\$', 5) - self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb' + str(self.eNB_instance) + '_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S rm -Rf enb_' + self.testCase_id + '.log', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) + #use nohup instead of daemon + #self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb' + str(self.eNB_instance) + '_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + self.command('echo $USER; nohup sudo ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh' + ' > ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log' + ' 2>&1 &', self.eNBUserName, 5) if not rruCheck: self.eNBLogFile = 'enb_' + self.testCase_id + '.log' + if extra_options != '': + self.eNBOptions = extra_options time.sleep(6) doLoop = True loopCounter = 10 @@ -482,6 +558,8 @@ class SSHConnection(): time.sleep(6) else: doLoop = False + if rruCheck and extra_options != '': + self.rruOptions = extra_options self.CreateHtmlTestRow('-O ' + config_file + extra_options, 'OK', ALL_PROCESSES_OK) logging.debug('\u001B[1m Initialize eNB Completed\u001B[0m') @@ -517,6 +595,165 @@ class SSHConnection(): job.join() self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK) + def InitializeOAIUE(self): + if self.UEIPAddress == '' or self.UEUserName == '' or self.UEPassword == '' or self.UESourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + #initialize_OAI_UE_flag = True + #pStatus = self.CheckOAIUEProcessExist(initialize_OAI_UE_flag) + #if (pStatus < 0): + # self.CreateHtmlTestRow(self.Initialize_OAI_UE_args, 'KO', pStatus) + # self.CreateHtmlTabFooter(False) + # sys.exit(1) + self.open(self.UEIPAddress, self.UEUserName, self.UEPassword) + # b2xx_fx3_utils reset procedure + self.command('echo ' + self.UEPassword + ' | sudo -S uhd_find_devices', '\$', 30) + result = re.search('type: n3xx', str(self.ssh.before)) + if result is not None: + pass + logging.debug('Found a B2xx device --> resetting it') + self.command('echo ' + self.UEPassword + ' | sudo -S sudo b2xx_fx3_utils --reset-device', '\$', 5) + # Reloading FGPA bin firmware + self.command('echo ' + self.UEPassword + ' | sudo -S uhd_find_devices', '\$', 30) + else: + logging.debug('Did not find any B2xx device') + self.command('cd ' + self.UESourceCodePath, '\$', 5) + # Initialize_OAI_UE_args usually start with -C and followed by the location in repository + self.command('source oaienv', '\$', 5) + self.command('cd cmake_targets/ran_build/build', '\$', 5) + self.command('echo "ulimit -c unlimited && ./'+ self.air_interface +'-uesoftmodem ' + self.Initialize_OAI_UE_args + '" > ./my-lte-uesoftmodem-run' + str(self.UE_instance) + '.sh', '\$', 5) + self.command('chmod 775 ./my-lte-uesoftmodem-run' + str(self.UE_instance) + '.sh', '\$', 5) + self.command('echo ' + self.UEPassword + ' | sudo -S rm -Rf ' + self.UESourceCodePath + '/cmake_targets/ue_' + self.testCase_id + '.log', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) + #use nohup instead of daemon + self.command('echo $USER; nohup sudo ./my-lte-uesoftmodem-run' + str(self.UE_instance) + '.sh' + ' > ' + self.UESourceCodePath + '/cmake_targets/ue_' + self.testCase_id + '.log ' + ' 2>&1 &', self.UEUserName, 5) + #self.command('echo ' + self.UEPassword + ' | sudo -S -E daemon --inherit --unsafe --name=ue' + str(self.UE_instance) + '_daemon --chdir=' + self.UESourceCodePath + '/cmake_targets/ran_build/build -o ' + self.UESourceCodePath + '/cmake_targets/ue_' + self.testCase_id + '.log ./my-lte-uesoftmodem-run' + str(self.UE_instance) + '.sh', '\$', 5) + self.UELogFile = 'ue_' + self.testCase_id + '.log' + time.sleep(6) + self.command('cd ../..', '\$', 5) + doLoop = True + loopCounter = 10 + while (doLoop): + loopCounter = loopCounter - 1 + if (loopCounter == 0): + self.close() + doLoop = False + logging.error('\u001B[1;37;41m UE logging system did not show got sync! \u001B[0m') + self.CreateHtmlTestRow(self.Initialize_OAI_UE_args, 'KO', ALL_PROCESSES_OK, 'OAI UE') + self.CreateHtmlTabFooter(False) + sys.exit(1) + else: + self.command('stdbuf -o0 cat ' + self.UELogFile + ' | egrep --text --color=never -i "wait|sync"', '\$', 4) + if self.air_interface == 'nr': + result = re.search('Starting sync detection', str(self.ssh.before)) + else: + result = re.search('got sync', str(self.ssh.before)) + if result is None: + time.sleep(10) + else: + doLoop = False + self.CreateHtmlTestRow(self.Initialize_OAI_UE_args, 'OK', ALL_PROCESSES_OK, 'OAI UE') + logging.debug('\u001B[1m Initialize OAI UE Completed\u001B[0m') + self.close() + + def InitializeOAIeNB(self): + if self.eNBIPAddress == '' or self.eNBUserName == '' or self.eNBPassword == '' or self.eNBSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + #initialize_OAI_eNB_flag = True + #pStatus = self.CheckOAIeNBProcessExist(initialize_OAI_eNB_flag) + #if (pStatus < 0): + # self.CreateHtmlTestRow(self.Initialize_OAI_eNB_args, 'KO', pStatus) + # self.CreateHtmlTabFooter(False) + # sys.exit(1) + self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + # Initialize_OAI_eNB_args usually start with -C and followed by the location in repository + #full_config_file = self.Initialize_OAI_eNB_args.replace('-O ','') + #extIdx = full_config_file.find('.conf') + #if (extIdx > 0): + # extra_options = full_config_file[extIdx + 5:] + # # if tracer options is on, compiling and running T Tracer + # result = re.search('T_stdout', str(extra_options)) + ## if result is not None: + # logging.debug('\u001B[1m Compiling and launching T Tracer\u001B[0m') + # self.command('cd common/utils/T/tracer', '\$', 5) + # self.command('make', '\$', 10) + # self.command('echo $USER; nohup ./record -d ../T_messages.txt -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '_record.raw -ON -off VCD -off HEAVY -off LEGACY_GROUP_TRACE -off LEGACY_GROUP_DEBUG > ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '_record.log 2>&1 &', self.eNBUserName, 5) + # self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + # full_config_file = full_config_file[:extIdx + 5] + # config_path, config_file = os.path.split(full_config_file) + #ci_full_config_file = config_path + '/ci-' + config_file + #rruCheck = False + #result = re.search('rru', str(config_file)) + #if result is not None: + # rruCheck = True + ## Make a copy and adapt to EPC / eNB IP addresses + #self.command('cp ' + full_config_file + ' ' + ci_full_config_file, '\$', 5) + #self.command('sed -i -e \'s/CI_eNB_IP_ADDR/' + self.eNBIPAddress + '/\' ' + ci_full_config_file, '\$', 2); + # Launch eNB with the modified config file + self.command('source oaienv', '\$', 5) + self.command('cd cmake_targets/ran_build/build', '\$', 5) + #self.command('echo "ulimit -c unlimited && ./' + self.air_interface + '-softmodem ' + self.Initialize_OAI_eNB_args + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + self.eNBLogFile = 'enb_' + self.testCase_id + '.log' + self.command('echo "ulimit -c unlimited && ./' + self.air_interface + '-softmodem ' + self.Initialize_OAI_eNB_args + '|& tee ' + self.eNBSourceCodePath + '/cmake_targets/' + self.eNBLogFile + '" > ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + self.command('chmod 775 ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S rm -Rf ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) + #use nohup instead of daemon + self.command('echo $USER; nohup sudo ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh' + ' > ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log' + ' 2>&1 &', self.eNBUserName, 5) + #self.command('echo ' + self.eNBPassword + ' | sudo -S -E daemon --inherit --unsafe --name=enb' + str(self.eNB_instance) + '_daemon --chdir=' + self.eNBSourceCodePath + '/cmake_targets/ran_build/build -o ' + self.eNBSourceCodePath + '/cmake_targets/enb_' + self.testCase_id + '.log ./my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) + time.sleep(6) + self.command('cd ../..', '\$', 5) + doLoop = True + loopCounter = 10 + print('gNB log file: ' + self.eNBLogFile) + while (doLoop): + loopCounter = loopCounter - 1 + if (loopCounter == 0): + # In case of T tracer recording, we may need to kill it + #result = re.search('T_stdout', str(self.Initialize_OAI_eNB_args)) + #if result is not None: + # self.command('killall --signal SIGKILL record', '\$', 5) + self.close() + doLoop = False + logging.error('\u001B[1;37;41m eNB logging system did not show got sync! \u001B[0m') + self.CreateHtmlTestRow(self.Initialize_OAI_eNB_args, 'KO', ALL_PROCESSES_OK, 'OAI eNB') + self.CreateHtmlTabFooter(False) + ## In case of T tracer recording, we need to kill tshark on EPC side + #result = re.search('T_stdout', str(self.Initialize_OAI_eNB_args)) + #if result is not None: + # self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + # logging.debug('\u001B[1m Stopping tshark \u001B[0m') + # self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL tshark', '\$', 5) + # self.close() + # time.sleep(1) + # pcap_log_file = 'enb_' + self.testCase_id + '_s1log.pcap' + # copyin_res = self.copyin(self.EPCIPAddress, self.EPCUserName, self.EPCPassword, '/tmp/' + pcap_log_file, '.') + # if (copyin_res == 0): + # self.copyout(self.eNBIPAddress, self.eNBUserName, self.eNBPassword, pcap_log_file, self.eNBSourceCodePath + '/cmake_targets/.') + sys.exit(1) + else: + #print('current directory: ' + os.getcwd()) + #self.command('pwd', '\$', 4) + #print('self.command pwd: ' + str(self.ssh.before)) + self.command('stdbuf -o0 cat ' + self.eNBLogFile + ' | egrep --text --color=never -i "wait|sync"', '\$', 30) + #print(self.ssh.before) + result = re.search('got sync', str(self.ssh.before)) + if result is None: + time.sleep(11) + else: + doLoop = False + self.CreateHtmlTestRow(self.Initialize_OAI_eNB_args, 'OK', ALL_PROCESSES_OK, 'OAI eNB') + logging.debug('\u001B[1m Initialize OAI eNB Completed\u001B[0m') + self.close() + def checkDevTTYisUnlocked(self): self.open(self.ADBIPAddress, self.ADBUserName, self.ADBPassword) count = 0 @@ -604,21 +841,150 @@ class SSHConnection(): time.sleep(4) # We should check if we register count = 0 - while count < 3: + attach_cnt = 0 + attach_status = False + while count < 5: self.command('AT+CEREG?', 'OK', 5) - result = re.search('CEREG: 2,(?P[0-9\-]+)', str(self.ssh.before)) + result = re.search('CEREG: 2,(?P[0-9\-]+),', str(self.ssh.before)) if result is not None: mDataConnectionState = int(result.group('state')) if mDataConnectionState is not None: - logging.debug('+CEREG: 2,' + str(mDataConnectionState)) + if mDataConnectionState == 1: + count = 10 + attach_status = True + result = re.search('CEREG: 2,1,"(?P[0-9A-Z]+)","(?P[0-9A-Z]+)"', str(self.ssh.before)) + if result is not None: + networky = result.group('networky') + networkz = result.group('networkz') + logging.debug('\u001B[1m CAT-M module attached to eNB (' + str(networky) + '/' + str(networkz) + ')\u001B[0m') + else: + logging.debug('\u001B[1m CAT-M module attached to eNB\u001B[0m') + else: + logging.debug('+CEREG: 2,' + str(mDataConnectionState)) + attach_cnt = attach_cnt + 1 else: logging.debug(str(self.ssh.before)) + attach_cnt = attach_cnt + 1 count = count + 1 time.sleep(1) + if attach_status: + self.command('AT+CESQ', 'OK', 5) + result = re.search('CESQ: 99,99,255,255,(?P[0-9]+),(?P[0-9]+)', str(self.ssh.before)) + if result is not None: + nRSRQ = int(result.group('rsrq')) + nRSRP = int(result.group('rsrp')) + if (nRSRQ is not None) and (nRSRP is not None): + logging.debug(' RSRQ = ' + str(-20+(nRSRQ/2)) + ' dB') + logging.debug(' RSRP = ' + str(-140+nRSRP) + ' dBm') self.close() self.picocom_closure = False - self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK) + html_queue = SimpleQueue() self.checkDevTTYisUnlocked() + if attach_status: + html_cell = '
CAT-M module\nAttachment Completed in ' + str(attach_cnt+4) + ' seconds'
+			if (nRSRQ is not None) and (nRSRP is not None):
+				html_cell += '\n   RSRQ = ' + str(-20+(nRSRQ/2)) + ' dB'
+				html_cell += '\n   RSRP = ' + str(-140+nRSRP) + ' dBm
' + else: + html_cell += '' + html_queue.put(html_cell) + self.CreateHtmlTestRowQueue('N/A', 'OK', 1, html_queue) + else: + html_cell = '
CAT-M module\nAttachment Failed
' + html_queue.put(html_cell) + self.CreateHtmlTestRowQueue('N/A', 'KO', 1, html_queue) + + def PingCatM(self): + if self.EPCIPAddress == '' or self.EPCUserName == '' or self.EPCPassword == '' or self.EPCSourceCodePath == '': + Usage() + sys.exit('Insufficient Parameter') + initialize_eNB_flag = False + pStatus = self.CheckProcessExist(initialize_eNB_flag) + if (pStatus < 0): + self.CreateHtmlTestRow(self.ping_args, 'KO', pStatus) + self.CreateHtmlTabFooter(False) + sys.exit(1) + try: + statusQueue = SimpleQueue() + lock = Lock() + self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) + self.command('cd ' + self.EPCSourceCodePath, '\$', 5) + self.command('cd scripts', '\$', 5) + if re.match('OAI', self.EPCType, re.IGNORECASE): + logging.debug('Using the OAI EPC HSS: not implemented yet') + self.CreateHtmlTestRow(self.ping_args, 'KO', pStatus) + self.CreateHtmlTabFooter(False) + sys.exit(1) + else: + self.command('egrep --color=never "Allocated ipv4 addr" /opt/ltebox/var/log/xGwLog.0', '\$', 5) + result = re.search('Allocated ipv4 addr: (?P[0-9\.]+) from Pool', str(self.ssh.before)) + if result is not None: + moduleIPAddr = result.group('ipaddr') + else: + return + ping_time = re.findall("-c (\d+)",str(self.ping_args)) + device_id = 'catm' + ping_status = self.command('stdbuf -o0 ping ' + self.ping_args + ' ' + str(moduleIPAddr) + ' 2>&1 | stdbuf -o0 tee -a ping_' + self.testCase_id + '_' + device_id + '.log', '\$', int(ping_time[0])*1.5) + # TIMEOUT CASE + if ping_status < 0: + message = 'Ping with UE (' + str(moduleIPAddr) + ') crashed due to TIMEOUT!' + logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m') + self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message) + return + result = re.search(', (?P[0-9\.]+)% packet loss, time [0-9\.]+ms', str(self.ssh.before)) + if result is None: + message = 'Packet Loss Not Found!' + logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m') + self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message) + return + packetloss = result.group('packetloss') + if float(packetloss) == 100: + message = 'Packet Loss is 100%' + logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m') + self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message) + return + result = re.search('rtt min\/avg\/max\/mdev = (?P[0-9\.]+)\/(?P[0-9\.]+)\/(?P[0-9\.]+)\/[0-9\.]+ ms', str(self.ssh.before)) + if result is None: + message = 'Ping RTT_Min RTT_Avg RTT_Max Not Found!' + logging.debug('\u001B[1;37;41m ' + message + ' \u001B[0m') + self.ping_iperf_wrong_exit(lock, moduleIPAddr, device_id, statusQueue, message) + return + rtt_min = result.group('rtt_min') + rtt_avg = result.group('rtt_avg') + rtt_max = result.group('rtt_max') + pal_msg = 'Packet Loss : ' + packetloss + '%' + min_msg = 'RTT(Min) : ' + rtt_min + ' ms' + avg_msg = 'RTT(Avg) : ' + rtt_avg + ' ms' + max_msg = 'RTT(Max) : ' + rtt_max + ' ms' + lock.acquire() + logging.debug('\u001B[1;37;44m ping result (' + moduleIPAddr + ') \u001B[0m') + logging.debug('\u001B[1;34m ' + pal_msg + '\u001B[0m') + logging.debug('\u001B[1;34m ' + min_msg + '\u001B[0m') + logging.debug('\u001B[1;34m ' + avg_msg + '\u001B[0m') + logging.debug('\u001B[1;34m ' + max_msg + '\u001B[0m') + qMsg = pal_msg + '\n' + min_msg + '\n' + avg_msg + '\n' + max_msg + packetLossOK = True + if packetloss is not None: + if float(packetloss) > float(self.ping_packetloss_threshold): + qMsg += '\nPacket Loss too high' + logging.debug('\u001B[1;37;41m Packet Loss too high \u001B[0m') + packetLossOK = False + elif float(packetloss) > 0: + qMsg += '\nPacket Loss is not 0%' + logging.debug('\u001B[1;30;43m Packet Loss is not 0% \u001B[0m') + lock.release() + self.close() + html_cell = '
CAT-M module\nIP Address  : ' + moduleIPAddr + '\n' + qMsg + '
' + statusQueue.put(html_cell) + if (packetLossOK): + self.CreateHtmlTestRowQueue(self.ping_args, 'OK', 1, statusQueue) + else: + self.CreateHtmlTestRowQueue(self.ping_args, 'KO', 1, statusQueue) + self.AutoTerminateUEandeNB() + self.CreateHtmlTabFooter(False) + sys.exit(1) + except: + os.kill(os.getppid(),signal.SIGUSR1) def AttachUE_common(self, device_id, statusQueue, lock): try: @@ -1527,11 +1893,53 @@ class SSHConnection(): result = logStatus return result + def CheckOAIUEProcessExist(self, initialize_OAI_UE_flag): + multi_jobs = [] + status_queue = SimpleQueue() + if initialize_OAI_UE_flag == False: + p = Process(target = SSH.CheckOAIUEProcess, args = (status_queue,)) + p.daemon = True + p.start() + multi_jobs.append(p) + for job in multi_jobs: + job.join() + + if (status_queue.empty()): + return -15 + else: + result = 0 + while (not status_queue.empty()): + status = status_queue.get() + if (status < 0): + result = status + if result == OAI_UE_PROCESS_FAILED: + fileCheck = re.search('enb_', str(self.UELogFile)) + if fileCheck is not None: + self.copyin(self.UEIPAddress, self.UEUserName, self.UEPassword, self.UESourceCodePath + '/cmake_targets/' + self.UELogFile, '.') + logStatus = self.AnalyzeLogFile_UE(self.UELogFile) + if logStatus < 0: + result = logStatus + return result + + def CheckOAIUEProcess(self, status_queue): + try: + self.open(self.OAIUEIPAddress, self.OAIUEUserName, self.OAIUEPassword) + self.command('stdbuf -o0 ps -aux | grep -v grep | grep --color=never ' + self.air_interface + '-uesoftmodem', '\$', 5) + result = re.search(self.air_interface + '-uesoftmodem', str(self.ssh.before)) + if result is None: + logging.debug('\u001B[1;37;41m OAI UE Process Not Found! \u001B[0m') + status_queue.put(OAI_UE_PROCESS_FAILED) + else: + status_queue.put(OAI_UE_PROCESS_OK) + self.close() + except: + os.kill(os.getppid(),signal.SIGUSR1) + def CheckeNBProcess(self, status_queue): try: self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) - self.command('stdbuf -o0 ps -aux | grep -v grep | grep --color=never lte-softmodem', '\$', 5) - result = re.search('lte-softmodem', str(self.ssh.before)) + self.command('stdbuf -o0 ps -aux | grep -v grep | grep --color=never ' + self.air_interface + '-softmodem', '\$', 5) + result = re.search(self.air_interface + '-softmodem', str(self.ssh.before)) if result is None: logging.debug('\u001B[1;37;41m eNB Process Not Found! \u001B[0m') status_queue.put(ENB_PROCESS_FAILED) @@ -1615,7 +2023,18 @@ class SSHConnection(): uciStatMsgCount = 0 pdcpFailure = 0 ulschFailure = 0 + self.htmleNBFailureMsg = '' for line in enb_log_file.readlines(): + if self.rruOptions != '': + res1 = re.search('max_rxgain (?P[0-9]+)', self.rruOptions) + res2 = re.search('max_rxgain (?P[0-9]+)', str(line)) + if res1 is not None and res2 is not None: + requested_option = int(res1.group('requested_option')) + applied_option = int(res2.group('applied_option')) + if requested_option == applied_option: + self.htmleNBFailureMsg += ' Command line option(s) correctly applied ' + self.rruOptions + '\n\n' + else: + self.htmleNBFailureMsg += ' Command line option(s) NOT applied ' + self.rruOptions + '\n\n' result = re.search('[Ss]egmentation [Ff]ault', str(line)) if result is not None: foundSegFault = True @@ -1734,17 +2153,172 @@ class SSHConnection(): return ENB_PROCESS_REALTIME_ISSUE return 0 + def AnalyzeLogFile_UE(self, UElogFile): + if (not os.path.isfile('./' + UElogFile)): + return -1 + ue_log_file = open('./' + UElogFile, 'r') + foundAssertion = False + msgAssertion = '' + msgLine = 0 + foundSegFault = False + foundRealTimeIssue = False + rlcDiscardBuffer = 0 + rachCanceledProcedure = 0 + uciStatMsgCount = 0 + pdcpFailure = 0 + ulschFailure = 0 + no_cell_sync_found = False + mib_found = False + frequency_found = False + self.htmlUEFailureMsg = '' + for line in ue_log_file.readlines(): + result = re.search('[Ss]egmentation [Ff]ault', str(line)) + if result is not None: + foundSegFault = True + result = re.search('[Cc]ore [dD]ump', str(line)) + if result is not None: + foundSegFault = True + result = re.search('[Aa]ssertion', str(line)) + if result is not None: + foundAssertion = True + result = re.search('LLL', str(line)) + if result is not None: + foundRealTimeIssue = True + if foundAssertion and (msgLine < 3): + msgLine += 1 + msgAssertion += str(line) + result = re.search('uci->stat', str(line)) + if result is not None: + uciStatMsgCount += 1 + # No cell synchronization found, abandoning + result = re.search('No cell synchronization found, abandoning', str(line)) + if result is not None: + no_cell_sync_found = True + result = re.search("MIB Information => ([a-zA-Z]{1,10}), ([a-zA-Z]{1,10}), NidCell (?P\d{1,3}), N_RB_DL (?P\d{1,3}), PHICH DURATION (?P\d), PHICH RESOURCE (?P.{1,4}), TX_ANT (?P\d)", str(line)) + if result is not None and (not mib_found): + try: + mibMsg = "MIB Information: " + result.group(1) + ', ' + result.group(2) + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + mibMsg = " nidcell = " + result.group('nidcell') + self.htmlUEFailureMsg += mibMsg + logging.debug('\033[94m' + mibMsg + '\033[0m') + mibMsg = " n_rb_dl = " + result.group('n_rb_dl') + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + mibMsg = " phich_duration = " + result.group('phich_duration') + self.htmlUEFailureMsg += mibMsg + logging.debug('\033[94m' + mibMsg + '\033[0m') + mibMsg = " phich_resource = " + result.group('phich_resource') + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + mibMsg = " tx_ant = " + result.group('tx_ant') + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + mib_found = True + except Exception as e: + logging.error('\033[91m' + "MIB marker was not found" + '\033[0m') + result = re.search("Measured Carrier Frequency (?P\d{1,15}) Hz", str(line)) + if result is not None and (not frequency_found): + try: + mibMsg = "Measured Carrier Frequency = " + result.group('measured_carrier_frequency') + ' Hz' + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + frequency_found = True + except Exception as e: + logging.error('\033[91m' + "Measured Carrier Frequency not found" + '\033[0m') + result = re.search("Found (?P[\w,\s]{1,15}) \(name from internal table\)", str(line)) + if result is not None: + try: + mibMsg = "The operator is: " + result.group('operator') + self.htmlUEFailureMsg += mibMsg + '\n' + logging.debug('\033[94m' + mibMsg + '\033[0m') + except Exception as e: + logging.error('\033[91m' + "Operator name not found" + '\033[0m') + result = re.search("SIB5 InterFreqCarrierFreq element (.{1,4})/(.{1,4})", str(line)) + if result is not None: + try: + mibMsg = "SIB5 InterFreqCarrierFreq element " + result.group(1) + '/' + result.group(2) + self.htmlUEFailureMsg += mibMsg + ' -> ' + logging.debug('\033[94m' + mibMsg + '\033[0m') + except Exception as e: + logging.error('\033[91m' + "SIB5 InterFreqCarrierFreq element not found" + '\033[0m') + result = re.search("DL Carrier Frequency/ARFCN : (?P\d{1,15}/\d{1,4})", str(line)) + if result is not None: + try: + freq = result.group('carrier_frequency') + new_freq = re.sub('/[0-9]+','',freq) + float_freq = float(new_freq) / 1000000 + self.htmlUEFailureMsg += 'DL Freq: ' + ('%.1f' % float_freq) + ' MHz' + logging.debug('\033[94m' + " DL Carrier Frequency is: " + freq + '\033[0m') + except Exception as e: + logging.error('\033[91m' + " DL Carrier Frequency not found" + '\033[0m') + result = re.search("AllowedMeasBandwidth : (?P\d{1,7})", str(line)) + if result is not None: + try: + prb = result.group('allowed_bandwidth') + self.htmlUEFailureMsg += ' -- PRB: ' + prb + '\n' + logging.debug('\033[94m' + " AllowedMeasBandwidth: " + prb + '\033[0m') + except Exception as e: + logging.error('\033[91m' + " AllowedMeasBandwidth not found" + '\033[0m') + ue_log_file.close() + if uciStatMsgCount > 0: + statMsg = 'UE showed ' + str(uciStatMsgCount) + ' "uci->stat" message(s)' + logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') + self.htmlUEFailureMsg += statMsg + '\n' + if pdcpFailure > 0: + statMsg = 'UE showed ' + str(pdcpFailure) + ' "PDCP Out of Resources" message(s)' + logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') + self.htmlUEFailureMsg += statMsg + '\n' + if ulschFailure > 0: + statMsg = 'UE showed ' + str(ulschFailure) + ' "ULSCH in error in round" message(s)' + logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') + self.htmlUEFailureMsg += statMsg + '\n' + if rachCanceledProcedure > 0: + rachMsg = 'UE cancelled ' + str(rachCanceledProcedure) + ' RA procedure(s)' + logging.debug('\u001B[1;30;43m ' + rachMsg + ' \u001B[0m') + self.htmlUEFailureMsg += rachMsg + '\n' + if foundSegFault: + logging.debug('\u001B[1;37;41m UE ended with a Segmentation Fault! \u001B[0m') + return ENB_PROCESS_SEG_FAULT + if foundAssertion: + logging.debug('\u001B[1;37;43m UE ended with an assertion! \u001B[0m') + # removed for esthetics + #self.htmlUEFailureMsg += msgAssertion + self.htmlUEFailureMsg += 'UE ended with an assertion!\n' + if not mib_found or not frequency_found: + return UE_PROCESS_ASSERTION + if foundRealTimeIssue: + logging.debug('\u001B[1;37;41m UE faced real time issues! \u001B[0m') + self.htmlUEFailureMsg += 'UE faced real time issues!\n' + #return ENB_PROCESS_REALTIME_ISSUE + if no_cell_sync_found and not mib_found: + logging.debug('\u001B[1;37;41m UE could not synchronize ! \u001B[0m') + self.htmlUEFailureMsg += 'UE could not synchronize!\n' + return UE_PROCESS_COULD_NOT_SYNC + if rlcDiscardBuffer > 0: + rlcMsg = 'UE RLC discarded ' + str(rlcDiscardBuffer) + ' buffer(s)' + logging.debug('\u001B[1;37;41m ' + rlcMsg + ' \u001B[0m') + self.htmlUEFailureMsg += rlcMsg + '\n' + return ENB_PROCESS_REALTIME_ISSUE + return 0 + def TerminateeNB(self): self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) self.command('cd ' + self.eNBSourceCodePath + '/cmake_targets', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) + #use nohup instead of daemon self.command('echo ' + self.eNBPassword + ' | sudo -S daemon --name=enb' + str(self.eNB_instance) + '_daemon --stop', '\$', 5) self.command('rm -f my-lte-softmodem-run' + str(self.eNB_instance) + '.sh', '\$', 5) - self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGINT lte-softmodem || true', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGINT -r .*-softmodem || true', '\$', 5) time.sleep(5) - self.command('stdbuf -o0 ps -aux | grep -v grep | grep lte-softmodem', '\$', 5) - result = re.search('lte-softmodem', str(self.ssh.before)) + self.command('stdbuf -o0 ps -aux | grep softmodem | grep -v grep', '\$', 5) + result = re.search('-softmodem', str(self.ssh.before)) if result is not None: - self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGKILL lte-softmodem || true', '\$', 5) + self.command('echo ' + self.eNBPassword + ' | sudo -S killall --signal SIGKILL -r .*-softmodem || true', '\$', 5) time.sleep(5) self.close() # If tracer options is on, stopping tshark on EPC side @@ -1810,6 +2384,10 @@ class SSHConnection(): self.command('cd ' + self.EPCSourceCodePath, '\$', 5) self.command('cd scripts', '\$', 5) self.command('rm -f ./kill_hss.sh', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) self.command('echo ' + self.EPCPassword + ' | sudo -S daemon --name=simulated_hss --stop', '\$', 5) time.sleep(1) self.command('echo ' + self.EPCPassword + ' | sudo -S killall --signal SIGKILL hss_sim', '\$', 5) @@ -1874,6 +2452,50 @@ class SSHConnection(): job.join() self.CreateHtmlTestRow('N/A', 'OK', ALL_PROCESSES_OK) + def TerminateOAIUE(self): + self.open(self.UEIPAddress, self.UEUserName, self.UEPassword) + self.command('cd ' + self.UESourceCodePath + '/cmake_targets', '\$', 5) + #to use daemon on CentOS we need to source the function + #linux_distro = platform.linux_distribution()[0] + #if re.match('(.*)CentOS(.*)', linux_distro, re.IGNORECASE): + #self.command('source /etc/init.d/functions', '\$', 5) + #self.command('echo ' + self.UEPassword + ' | sudo -S daemon --name=ue' + str(self.UE_instance) + '_daemon --stop', '\$', 5) + self.command('rm -f my-lte-uesoftmodem-run' + str(self.UE_instance) + '.sh', '\$', 5) + self.command('echo ' + self.UEPassword + ' | sudo -S killall --signal SIGINT -r .*-uesoftmodem || true', '\$', 5) + time.sleep(5) + self.command('stdbuf -o0 ps -aux | grep uesoftmodem | grep -v grep', '\$', 5) + result = re.search('-uesoftmodem', str(self.ssh.before)) + if result is not None: + self.command('echo ' + self.UEPassword + ' | sudo -S killall --signal SIGKILL -r .*-uesoftmodem || true', '\$', 5) + time.sleep(5) + self.close() + result = re.search('ue_', str(self.UELogFile)) + if result is not None: + copyin_res = self.copyin(self.UEIPAddress, self.UEUserName, self.UEPassword, self.UESourceCodePath + '/cmake_targets/' + self.UELogFile, '.') + if (copyin_res == -1): + logging.debug('\u001B[1;37;41m Could not copy UE logfile to analyze it! \u001B[0m') + optionsMsg = '
Could not copy UE logfile to analyze it!
' + self.CreateHtmlTestRow(optionsMsg, 'KO', UE_PROCESS_NOLOGFILE_TO_ANALYZE, 'UE') + self.UELogFile = '' + return + logging.debug('\u001B[1m Analyzing UE logfile \u001B[0m') + logStatus = self.AnalyzeLogFile_UE(self.UELogFile) + if (logStatus < 0): + optionsMsg = '
Sniffing Unsuccessful\n'
+				optionsMsg += self.htmlUEFailureMsg
+				optionsMsg += '
' + self.CreateHtmlTestRow(optionsMsg, 'KO', logStatus, 'UE') + self.CreateHtmlTabFooter(False) + sys.exit(1) + else: + optionsMsg = '
Sniffing Successful\n'
+				optionsMsg += self.htmlUEFailureMsg
+				optionsMsg += '
' + self.CreateHtmlTestRow(optionsMsg, 'OK', ALL_PROCESSES_OK) + self.UELogFile = '' + else: + self.CreateHtmlTestRow('
No Log File to analyze
', 'OK', ALL_PROCESSES_OK) + def AutoTerminateUEandeNB(self): self.testCase_id = 'AUTO-KILL-UE' self.desc = 'Automatic Termination of UE' @@ -1890,8 +2512,20 @@ class SSHConnection(): self.CreateHtmlTestRow(str(self.idle_sleep_time) + ' sec', 'OK', ALL_PROCESSES_OK) def LogCollectBuild(self): - self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) - self.command('cd ' + self.eNBSourceCodePath, '\$', 5) + if (self.eNBIPAddress != '' and self.eNBUserName != '' and self.eNBPassword != ''): + IPAddress = self.eNBIPAddress + UserName = self.eNBUserName + Password = self.eNBPassword + SourceCodePath = self.eNBSourceCodePath + elif (self.UEIPAddress != '' and self.UEUserName != '' and self.UEPassword != ''): + IPAddress = self.UEIPAddress + UserName = self.UEUserName + Password = self.UEPassword + SourceCodePath = self.UESourceCodePath + else: + sys.exit('Insufficient Parameter') + self.open(IPAddress, UserName, Password) + self.command('cd ' + SourceCodePath, '\$', 5) self.command('cd cmake_targets', '\$', 5) self.command('rm -f build.log.zip', '\$', 5) self.command('zip build.log.zip build_log_*/*', '\$', 60) @@ -1907,6 +2541,7 @@ class SSHConnection(): self.command('echo ' + self.eNBPassword + ' | sudo -S rm enb*.log core* enb_*record.raw enb_*.pcap enb_*txt', '\$', 5) self.close() + def LogCollectPing(self): self.open(self.EPCIPAddress, self.EPCUserName, self.EPCPassword) self.command('cd ' + self.EPCSourceCodePath, '\$', 5) @@ -1964,43 +2599,69 @@ class SSHConnection(): self.command('zip spgw.log.zip xGwLog.0', '\$', 60) self.close() + def LogCollectOAIUE(self): + self.open(self.UEIPAddress, self.UEUserName, self.UEPassword) + self.command('cd ' + self.UESourceCodePath, '\$', 5) + self.command('cd cmake_targets', '\$', 5) + self.command('echo ' + self.UEPassword + ' | sudo -S rm -f ue.log.zip', '\$', 5) + self.command('echo ' + self.UEPassword + ' | sudo -S zip ue.log.zip ue*.log core* ue_*record.raw ue_*.pcap ue_*txt', '\$', 60) + self.command('echo ' + self.UEPassword + ' | sudo -S rm ue*.log core* ue_*record.raw ue_*.pcap ue_*txt', '\$', 5) + self.close() + def RetrieveSystemVersion(self): if self.eNBIPAddress == 'none': - self.eNBOsVersion = 'Ubuntu 16.04.5 LTS' - self.eNBKernelVersion = '4.15.0-45-generic' - self.eNBUhdVersion = '3.13.0.1-0' - self.eNBCpuNb = '4' - self.eNBCpuModel = 'Intel(R) Core(TM) i5-6200U' - self.eNBCpuMHz = '2399.996 MHz' + self.OsVersion = 'Ubuntu 16.04.5 LTS' + self.KernelVersion = '4.15.0-45-generic' + self.UhdVersion = '3.13.0.1-0' + self.UsrpBoard = 'B210' + self.CpuNb = '4' + self.CpuModel = 'Intel(R) Core(TM) i5-6200U' + self.CpuMHz = '2399.996 MHz' return - if self.eNBIPAddress == '' or self.eNBUserName == '' or self.eNBPassword == '': + machine = None + if self.eNBIPAddress != '' and self.eNBUserName != '' and self.eNBPassword != '': + machine = 'eNB' + IPAddress = self.eNBIPAddress + UserName = self.eNBUserName + Password = self.eNBPassword + elif self.UEIPAddress != '' and self.UEUserName != '' and self.UEPassword != '': + machine = 'UE' + IPAddress = self.UEIPAddress + UserName = self.UEUserName + Password = self.UEPassword + if machine is None: Usage() sys.exit('Insufficient Parameter') - self.open(self.eNBIPAddress, self.eNBUserName, self.eNBPassword) + self.open(IPAddress, UserName, Password) self.command('lsb_release -a', '\$', 5) result = re.search('Description:\\\\t(?P[a-zA-Z0-9\-\_\.\ ]+)', str(self.ssh.before)) if result is not None: - self.eNBOsVersion = result.group('os_type') - logging.debug('OS is: ' + self.eNBOsVersion) + self.OsVersion = result.group('os_type') + logging.debug('OS is: ' + self.OsVersion) self.command('uname -r', '\$', 5) result = re.search('uname -r\\\\r\\\\n(?P[a-zA-Z0-9\-\_\.]+)', str(self.ssh.before)) if result is not None: - self.eNBKernelVersion = result.group('kernel_version') - logging.debug('Kernel Version is: ' + self.eNBKernelVersion) + self.KernelVersion = result.group('kernel_version') + logging.debug('Kernel Version is: ' + self.KernelVersion) self.command('dpkg --list | egrep --color=never libuhd003', '\$', 5) result = re.search('libuhd003:amd64 *(?P[0-9\.]+)', str(self.ssh.before)) if result is not None: - self.eNBUhdVersion = result.group('uhd_version') - logging.debug('UHD Version is: ' + self.eNBUhdVersion) + self.UhdVersion = result.group('uhd_version') + logging.debug('UHD Version is: ' + self.UhdVersion) + self.command('echo ' + Password + ' | sudo -S uhd_find_devices', '\$', 12) + result = re.search('product: (?P[0-9A-Za-z]+)\\\\r\\\\n', str(self.ssh.before)) + if result is not None: + self.UsrpBoard = result.group('usrp_board') + logging.debug('USRP Board is: ' + self.UsrpBoard) self.command('lscpu', '\$', 5) result = re.search('CPU\(s\): *(?P[0-9]+).*Model name: *(?P[a-zA-Z0-9\-\_\.\ \(\)]+).*CPU MHz: *(?P[0-9\.]+)', str(self.ssh.before)) if result is not None: - self.eNBCpuNb = result.group('nb_cpus') - logging.debug('nb_cpus: ' + self.eNBCpuNb) - self.eNBCpuModel = result.group('model') - logging.debug('model: ' + self.eNBCpuModel) - self.eNBCpuMHz = result.group('cpu_mhz') + ' MHz' - logging.debug('cpu_mhz: ' + self.eNBCpuMHz) + self.CpuNb = result.group('nb_cpus') + logging.debug('nb_cpus: ' + self.CpuNb) + self.CpuModel = result.group('model') + logging.debug('model: ' + self.CpuModel) + self.CpuMHz = result.group('cpu_mhz') + ' MHz' + logging.debug('cpu_mhz: ' + self.CpuMHz) self.close() #----------------------------------------------------------- @@ -2008,6 +2669,9 @@ class SSHConnection(): #----------------------------------------------------------- def CreateHtmlHeader(self): if (not self.htmlHeaderCreated): + logging.debug('\u001B[1m----------------------------------------\u001B[0m') + logging.debug('\u001B[1m Creating HTML header \u001B[0m') + logging.debug('\u001B[1m----------------------------------------\u001B[0m') self.htmlFile = open('test_results.html', 'w') self.htmlFile.write('\n') self.htmlFile.write('\n') @@ -2085,18 +2749,13 @@ class SSHConnection(): self.htmlFile.write(' \n') self.htmlFile.write(' \n') - terminate_ue_flag = True if (self.ADBIPAddress != 'none'): + terminate_ue_flag = True self.GetAllUEDevices(terminate_ue_flag) self.GetAllCatMDevices(terminate_ue_flag) - else: - self.UEDevices.append('doughq9rehg') - self.UEDevices.append('dnsgiuahgia') - self.UEDevices.append('uehgieng9') - self.htmlUEConnected = len(self.UEDevices) - - self.htmlFile.write('

' + str(len(self.UEDevices)) + ' UE(s) is(are) connected to ADB bench server

\n') - self.htmlFile.write('

' + str(len(self.CatMDevices)) + ' CAT-M UE(s) is(are) connected to bench server

\n') + self.htmlUEConnected = len(self.UEDevices) + self.htmlFile.write('

' + str(len(self.UEDevices)) + ' UE(s) is(are) connected to ADB bench server

\n') + self.htmlFile.write('

' + str(len(self.CatMDevices)) + ' CAT-M UE(s) is(are) connected to bench server

\n') self.htmlFile.write('
\n') self.htmlFile.write('