From e0cdf278b5b5ce298c402433e771d8ffb2825232 Mon Sep 17 00:00:00 2001 From: francescomani Date: Mon, 17 Oct 2022 17:14:38 +0200 Subject: [PATCH 1/6] remove init_msg1 and sync_frame from prach structure --- .../PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c | 2 -- openair1/PHY/NR_UE_TRANSPORT/nr_prach.c | 4 ++-- openair1/PHY/defs_nr_common.h | 4 ---- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 17 ++--------------- openair1/SIMULATION/NR_PHY/prachsim.c | 1 - openair2/LAYER2/NR_MAC_UE/config_ue.c | 1 - openair2/LAYER2/NR_MAC_UE/mac_defs.h | 2 +- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 15 +++++++-------- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 4 +++- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 5 +++-- 11 files changed, 19 insertions(+), 38 deletions(-) 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 045197adc1..bbfd33b1fe 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_adjust_synch_ue.c @@ -110,8 +110,6 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms, //mac_resynch(); //dl_phy_sync_success(ue->Mod_id,frame,0,1);//ue->common_vars.eNb_id); ue->UE_mode[0] = PRACH; - ue->prach_resources[gNB_id]->sync_frame = frame; - ue->prach_resources[gNB_id]->init_msg1 = 0; } else { ue->UE_mode[0] = PUSCH; } diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c index f56f01f764..95c410aa0b 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c @@ -73,7 +73,6 @@ int32_t generate_nr_prach(PHY_VARS_NR_UE *ue, uint8_t gNB_id, int frame, uint8_t int16_t Ncp = 0, amp, *prach, *prach2, *prachF, *Xu; int32_t Xu_re, Xu_im; int prach_start, prach_sequence_length, i, prach_len, dftlen, mu, kbar, K, n_ra_prb, k, prachStartSymbol, sample_offset_slot; - //int restricted_Type; fd_occasion = 0; prach_len = 0; @@ -96,7 +95,8 @@ int32_t generate_nr_prach(PHY_VARS_NR_UE *ue, uint8_t gNB_id, int frame, uint8_t K = 24; k = 12*n_ra_prb - 6*fp->N_RB_UL; prachStartSymbol = prach_pdu->prach_start_symbol; - //restricted_Type = 0; + + LOG_D(PHY,"Generate NR PRACH %d.%d\n", frame, slot); compute_nr_prach_seq(nrUE_config->prach_config.prach_sequence_length, nrUE_config->prach_config.num_prach_fd_occasions_list[fd_occasion].num_root_sequences, diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 10c4c9df6d..a5ab87676e 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -230,10 +230,6 @@ typedef struct { int RA_PCMAX; /// Corresponding RA-RNTI for UL-grant uint16_t ra_RNTI; - /// Frame of last completed synch - uint16_t sync_frame; - /// Flag to indicate that prach is ready to start: it is enabled with an initial delay after the sync - uint8_t init_msg1; } NR_PRACH_RESOURCES_t; typedef struct { diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 697638f6cf..ca94fce44c 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -395,8 +395,6 @@ static void nr_ue_pbch_procedures(uint8_t gNB_id, if (ue->UE_mode[gNB_id] == NOT_SYNCHED && ue->no_timing_correction == 1){ if (get_softmodem_params()->do_ra) { ue->UE_mode[gNB_id] = PRACH; - ue->prach_resources[gNB_id]->sync_frame = frame_rx; - ue->prach_resources[gNB_id]->init_msg1 = 0; } else { ue->UE_mode[gNB_id] = PUSCH; } @@ -1458,19 +1456,8 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PRACH, VCD_FUNCTION_IN); - if (ue->mac_enabled == 0){ - - prach_resources->ra_TDD_map_index = 0; - prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = 10; - prach_resources->ra_RNTI = 0x1234; - nr_prach = 1; - prach_resources->init_msg1 = 1; - - } else { - - nr_prach = nr_ue_get_rach(prach_resources, &ue->prach_vars[0]->prach_pdu, mod_id, ue->CC_id, frame_tx, gNB_id, nr_slot_tx); - LOG_D(PHY, "In %s:[%d.%d] getting PRACH resources : %d\n", __FUNCTION__, frame_tx, nr_slot_tx,nr_prach); - } + nr_prach = nr_ue_get_rach(prach_resources, &ue->prach_vars[0]->prach_pdu, mod_id, ue->CC_id, frame_tx, gNB_id, nr_slot_tx); + LOG_D(PHY, "In %s:[%d.%d] getting PRACH resources : %d\n", __FUNCTION__, frame_tx, nr_slot_tx,nr_prach); if (nr_prach == GENERATE_PREAMBLE) { diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c index 7adb0d4b93..d0f3af4e60 100644 --- a/openair1/SIMULATION/NR_PHY/prachsim.c +++ b/openair1/SIMULATION/NR_PHY/prachsim.c @@ -718,7 +718,6 @@ int main(int argc, char **argv){ printf("raPreamble %d\n",preamble_tx); UE->prach_resources[0]->ra_PreambleIndex = preamble_tx; - UE->prach_resources[0]->init_msg1 = 1; // Configure channel bw = N_RB_UL*(180e3)*(1 << frame_parms->numerology_index); diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index 2804a9ec1e..909a0428d4 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -632,7 +632,6 @@ int nr_rrc_mac_config_req_ue( build_ssb_to_ro_map(mac);//->scc, mac->phy_config.config_req.cell_config.frame_duplex_type); if (!get_softmodem_params()->emulate_l1) mac->if_module->phy_config_request(&mac->phy_config); - mac->common_configuration_complete = 1; } if(scell_group_config != NULL ){ mac->cg = scell_group_config; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 51711e70f0..fb06cf749a 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -355,7 +355,7 @@ typedef struct { NR_CSI_ReportConfig_t *csirc; long physCellId; //// MAC config - int common_configuration_complete; + int first_sync_frame; NR_DRX_Config_t *drx_Config; NR_SchedulingRequestConfig_t *schedulingRequestConfig; NR_BSR_Config_t *bsr_Config; diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 524c3b3fcd..1e59782d21 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -52,12 +52,12 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { //init mac here nr_ue_mac_inst = (NR_UE_MAC_INST_t *)calloc(sizeof(NR_UE_MAC_INST_t),NB_NR_UE_MAC_INST); + nr_ue_mac_inst->first_sync_frame = -1; for (int j=0;jscell_group_config) { nr_rrc_mac_config_req_ue(0,0,0,NULL,NULL,NULL,rrc_inst->scell_group_config); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 00117ec4ad..9833ccbe35 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -677,26 +677,25 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = ra->rach_ConfigDedicated; // Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side - if (!prach_resources->init_msg1) { - if ((mac->common_configuration_complete > 0 || get_softmodem_params()->do_ra || get_softmodem_params()->nsa) && - ((MAX_FRAME_NUMBER + frame - prach_resources->sync_frame) % MAX_FRAME_NUMBER) > 150) { - prach_resources->init_msg1 = 1; + if (ra->ra_state == RA_UE_IDLE) { + if ((mac->first_sync_frame > -1 || get_softmodem_params()->do_ra || get_softmodem_params()->nsa) && + ((MAX_FRAME_NUMBER + frame - mac->first_sync_frame) % MAX_FRAME_NUMBER) > 150) { + ra->ra_state = GENERATE_PREAMBLE; } else { - LOG_D(NR_MAC,"PRACH Condition not met: frame %d, prach_resources->sync_frame %d\n",frame,prach_resources->sync_frame); + LOG_D(NR_MAC,"PRACH Condition not met: ra state %d, frame %d, prach_resources->sync_frame %d\n", ra->ra_state, frame, mac->first_sync_frame); return 0; } } - LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: init_msg1 %d, ra_state %d, RA_active %d\n", + LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: ra_state %d, RA_active %d\n", __FUNCTION__, mod_id, frame, nr_slot_tx, - prach_resources->init_msg1, ra->ra_state, ra->RA_active); - if (prach_resources->init_msg1 && ra->ra_state != RA_SUCCEEDED) { + if (ra->ra_state > RA_UE_IDLE && ra->ra_state < RA_SUCCEEDED) { if (ra->RA_active == 0) { /* RA not active - checking if RRC is ready to initiate the RA procedure */ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index be4bc4b362..6b04441cb3 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -374,7 +374,7 @@ int8_t nr_ue_decode_mib(module_id_t module_id, else ssb_sc_offset_norm = ssb_subcarrier_offset; - if (mac->common_configuration_complete == 0) + if (mac->first_sync_frame == -1) nr_ue_sib1_scheduler(module_id, cc_id, ssb_start_symbol, @@ -394,6 +394,8 @@ int8_t nr_ue_decode_mib(module_id_t module_id, mac->dl_config_request.sfn = frame; mac->dl_config_request.slot = ssb_start_symbol/14; + if (mac->first_sync_frame == -1) + mac->first_sync_frame = frame; return 0; } diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 7f6da1b915..21fa6176d4 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -2699,7 +2699,7 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s (int)slotP, &prach_occasion_info_p); - if (is_nr_prach_slot && ra->ra_state == RA_UE_IDLE) { + if (is_nr_prach_slot && ra->ra_state == GENERATE_PREAMBLE) { AssertFatal(NULL != prach_occasion_info_p,"PRACH Occasion Info not returned in a valid NR Prach Slot\n"); ra->generate_nr_prach = GENERATE_PREAMBLE; @@ -2733,7 +2733,8 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s prach_config_pdu->restricted_set = prach_config->restricted_set_config; prach_config_pdu->freq_msg1 = prach_config->num_prach_fd_occasions_list[prach_occasion_info_p->fdm].k1; - LOG_D(NR_MAC,"Selected RO Frame %u, Slot %u, Symbol %u, Fdm %u\n", frameP, prach_config_pdu->prach_slot, prach_config_pdu->prach_start_symbol, prach_config_pdu->num_ra); + LOG_D(NR_MAC,"PRACH scheduler: Selected RO Frame %u, Slot %u, Symbol %u, Fdm %u\n", + frameP, prach_config_pdu->prach_slot, prach_config_pdu->prach_start_symbol, prach_config_pdu->num_ra); // Search which SSB is mapped in the RO (among all the SSBs mapped to this RO) for (prach_config_pdu->ssb_nb_in_ro=0; prach_config_pdu->ssb_nb_in_ronb_mapped_ssb; prach_config_pdu->ssb_nb_in_ro++) { From c9553fe6967d0217748b938b3760748568f2c863 Mon Sep 17 00:00:00 2001 From: francescomani Date: Wed, 19 Oct 2022 17:32:16 +0200 Subject: [PATCH 2/6] moving prach_resources to MAC --- executables/nr-ue.c | 15 ++---- .../nfapi/public_inc/fapi_nr_ue_interface.h | 5 +- openair1/PHY/NR_UE_TRANSPORT/nr_prach.c | 3 +- openair1/PHY/defs_nr_UE.h | 1 - openair1/PHY/defs_nr_common.h | 29 ----------- openair1/SCHED_NR_UE/fapi_nr_ue_l1.c | 1 - openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 35 ++++++-------- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 27 +++++++++++ openair2/LAYER2/NR_MAC_UE/mac_proto.h | 15 ++++-- openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 48 +++++-------------- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 10 ++++ openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 2 +- 12 files changed, 87 insertions(+), 104 deletions(-) diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 8b022adc62..b7da1079bf 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -162,10 +162,8 @@ void init_nr_ue_vars(PHY_VARS_NR_UE *ue, ue->dci_thres = 0; // Setting UE mode to NOT_SYNCHED by default - for (gNB_id = 0; gNB_id < nb_connected_gNB; gNB_id++){ + for (gNB_id = 0; gNB_id < nb_connected_gNB; gNB_id++) ue->UE_mode[gNB_id] = NOT_SYNCHED; - ue->prach_resources[gNB_id] = (NR_PRACH_RESOURCES_t *)malloc16_clear(sizeof(NR_PRACH_RESOURCES_t)); - } // initialize all signal buffers init_nr_ue_signal(ue, nb_connected_gNB); @@ -268,7 +266,7 @@ static void process_queued_nr_nfapi_msgs(NR_UE_MAC_INST_t *mac, int sfn_slot) } free_and_zero(rach_ind->pdu_list); free_and_zero(rach_ind); - nr_Msg1_transmitted(0, 0, NFAPI_SFNSLOT2SFN(sfn_slot), 0); + nr_Msg1_transmitted(0); } if (dl_tti_request) { @@ -300,7 +298,7 @@ static void process_queued_nr_nfapi_msgs(NR_UE_MAC_INST_t *mac, int sfn_slot) } } -static void check_nr_prach(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info, NR_PRACH_RESOURCES_t *prach_resources) +static void check_nr_prach(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info) { fapi_nr_ul_config_request_t *ul_config = get_ul_config_request(mac, ul_info->slot_tx); if (!ul_config) @@ -313,8 +311,7 @@ static void check_nr_prach(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_inf AssertFatal(ul_config->number_pdus < sizeof(ul_config->ul_config_list) / sizeof(ul_config->ul_config_list[0]), "Number of PDUS in ul_config = %d > ul_config_list num elements", ul_config->number_pdus); fapi_nr_ul_config_prach_pdu *prach_pdu = &ul_config->ul_config_list[ul_config->number_pdus].prach_config_pdu; - uint8_t nr_prach = nr_ue_get_rach(prach_resources, - prach_pdu, + uint8_t nr_prach = nr_ue_get_rach(prach_pdu, ul_info->module_id, ul_info->cc_id, ul_info->frame_tx, @@ -349,8 +346,6 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) reset_queue(&nr_ul_dci_req_queue); reset_queue(&nr_ul_tti_req_queue); - NR_PRACH_RESOURCES_t prach_resources; - memset(&prach_resources, 0, sizeof(prach_resources)); NR_UL_TIME_ALIGNMENT_t ul_time_alignment; memset(&ul_time_alignment, 0, sizeof(ul_time_alignment)); int last_sfn_slot = -1; @@ -462,7 +457,7 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) nr_ue_scheduler(NULL, &ul_info); nr_ue_prach_scheduler(mod_id, ul_info.frame_tx, ul_info.slot_tx); nr_ue_pucch_scheduler(mod_id, ul_info.frame_tx, ul_info.slot_tx, NULL); - check_nr_prach(mac, &ul_info, &prach_resources); + check_nr_prach(mac, &ul_info); } if (!IS_SOFTMODEM_NOS1 && get_softmodem_params()->sa) { NR_UE_MAC_INST_t *mac = get_mac_inst(0); diff --git a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h index 656399df97..15aba4a541 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h @@ -191,7 +191,10 @@ typedef struct { uint16_t freq_msg1; // When multiple SSBs per RO is configured, this indicates which one is selected in this RO -> this is used to properly compute the PRACH preamble uint8_t ssb_nb_in_ro; - // nfapi_nr_ul_beamforming_t beamforming; + /// Preamble index for PRACH (0-63) + uint8_t ra_PreambleIndex; + /// Target received power at gNB (TODO possibly modify to uint) + int preamble_target_power; } fapi_nr_ul_config_prach_pdu; typedef struct { diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c index 95c410aa0b..e5e0e44b6b 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c @@ -61,7 +61,6 @@ int32_t generate_nr_prach(PHY_VARS_NR_UE *ue, uint8_t gNB_id, int frame, uint8_t NR_DL_FRAME_PARMS *fp=&ue->frame_parms; fapi_nr_config_request_t *nrUE_config = &ue->nrUE_config; - NR_PRACH_RESOURCES_t *prach_resources = ue->prach_resources[gNB_id]; fapi_nr_ul_config_prach_pdu *prach_pdu = &ue->prach_vars[gNB_id]->prach_pdu; uint8_t Mod_id, fd_occasion, preamble_index, restricted_set, not_found; @@ -90,7 +89,7 @@ int32_t generate_nr_prach(PHY_VARS_NR_UE *ue, uint8_t gNB_id, int frame, uint8_t n_ra_prb = nrUE_config->prach_config.num_prach_fd_occasions_list[fd_occasion].k1,//prach_pdu->freq_msg1; NCS = prach_pdu->num_cs; prach_fmt_id = prach_pdu->prach_format; - preamble_index = prach_resources->ra_PreambleIndex; + preamble_index = prach_pdu->ra_PreambleIndex; kbar = 1; K = 24; k = 12*n_ra_prb - 6*fp->N_RB_UL; diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 7533ca685f..a2f39880ca 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -598,7 +598,6 @@ typedef struct { UE_NR_SCAN_INFO_t scan_info[NB_BANDS_MAX]; - NR_PRACH_RESOURCES_t *prach_resources[NUMBER_OF_CONNECTED_gNB_MAX]; /// \brief ?. /// - first index: gNB [0..NUMBER_OF_CONNECTED_gNB_MAX[ (hard coded) uint32_t total_TBS[NUMBER_OF_CONNECTED_gNB_MAX]; diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index a5ab87676e..dbd402b2ac 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -203,35 +203,6 @@ typedef struct NR_BWP_PARMS { nr_prg_parms_t prg_parms; } NR_BWP_PARMS; -typedef struct { - /// PRACH format retrieved from prach_ConfigIndex - uint16_t prach_format; - /// Preamble index for PRACH (0-63) - uint8_t ra_PreambleIndex; - /// Preamble Tx Counter - uint8_t RA_PREAMBLE_TRANSMISSION_COUNTER; - /// Preamble Power Ramping Counter - uint8_t RA_PREAMBLE_POWER_RAMPING_COUNTER; - /// 2-step RA power offset - int POWER_OFFSET_2STEP_RA; - /// Target received power at gNB. Baseline is range -202..-60 dBm. Depends on delta preamble, power ramping counter and step. - int ra_PREAMBLE_RECEIVED_TARGET_POWER; - /// PRACH index for TDD (0 ... 6) depending on TDD configuration and prachConfigIndex - uint8_t ra_TDD_map_index; - /// RA Preamble Power Ramping Step in dB - uint32_t RA_PREAMBLE_POWER_RAMPING_STEP; - /// - uint8_t RA_PREAMBLE_BACKOFF; - /// - uint8_t RA_SCALING_FACTOR_BI; - /// Indicating whether it is 2-step or 4-step RA - nr_ra_type_e RA_TYPE; - /// UE configured maximum output power - int RA_PCMAX; - /// Corresponding RA-RNTI for UL-grant - uint16_t ra_RNTI; -} NR_PRACH_RESOURCES_t; - typedef struct { uint8_t k_0_p[MAX_NUM_NR_SRS_AP][MAX_NUM_NR_SRS_SYMBOLS]; uint8_t srs_generated_signal_bits; diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index cb4ffbe66c..5729bde20d 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -441,7 +441,6 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ uint8_t pdu_type = ul_config->ul_config_list[i].pdu_type, current_harq_pid, gNB_id = 0; /* PRACH */ - //NR_PRACH_RESOURCES_t *prach_resources; fapi_nr_ul_config_prach_pdu *prach_config_pdu; /* PUSCH */ nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index ca94fce44c..672198cf99 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -1450,33 +1450,29 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t int frame_tx = proc->frame_tx, nr_slot_tx = proc->nr_slot_tx, prach_power; // tx_amp uint8_t mod_id = ue->Mod_id; - NR_PRACH_RESOURCES_t * prach_resources = ue->prach_resources[gNB_id]; - AssertFatal(prach_resources != NULL, "ue->prach_resources[%u] == NULL\n", gNB_id); uint8_t nr_prach = 0; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PRACH, VCD_FUNCTION_IN); - nr_prach = nr_ue_get_rach(prach_resources, &ue->prach_vars[0]->prach_pdu, mod_id, ue->CC_id, frame_tx, gNB_id, nr_slot_tx); + nr_prach = nr_ue_get_rach(&ue->prach_vars[gNB_id]->prach_pdu, mod_id, ue->CC_id, frame_tx, gNB_id, nr_slot_tx); LOG_D(PHY, "In %s:[%d.%d] getting PRACH resources : %d\n", __FUNCTION__, frame_tx, nr_slot_tx,nr_prach); if (nr_prach == GENERATE_PREAMBLE) { - if (ue->mac_enabled == 1) { - int16_t pathloss = get_nr_PL(mod_id, ue->CC_id, gNB_id); - int16_t ra_preamble_rx_power = (int16_t)(prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER - pathloss + 30); - ue->tx_power_dBm[nr_slot_tx] = min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); + fapi_nr_ul_config_prach_pdu *prach_pdu = &ue->prach_vars[gNB_id]->prach_pdu; + int16_t pathloss = get_nr_PL(mod_id, ue->CC_id, gNB_id); + int16_t ra_preamble_rx_power = (int16_t)(prach_pdu->preamble_target_power - pathloss + 30); + ue->tx_power_dBm[nr_slot_tx] = min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); - LOG_D(PHY, "In %s: [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, PL %d dB, P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, RA-RNTI %x)\n", - __FUNCTION__, - mod_id, - frame_tx, - nr_slot_tx, - prach_resources->ra_PreambleIndex, - pathloss, - ue->tx_power_dBm[nr_slot_tx], - prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER, - prach_resources->ra_RNTI); - } + LOG_D(PHY, "In %s: [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, PL %d dB, P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm)\n", + __FUNCTION__, + mod_id, + frame_tx, + nr_slot_tx, + prach_pdu->ra_PreambleIndex, + pathloss, + ue->tx_power_dBm[nr_slot_tx], + prach_pdu->preamble_target_power); ue->prach_vars[gNB_id]->amp = AMP; @@ -1495,9 +1491,6 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t dB_fixed(prach_power), ue->prach_vars[gNB_id]->amp); - if (ue->mac_enabled == 1) - nr_Msg1_transmitted(mod_id, ue->CC_id, frame_tx, gNB_id); - } else if (nr_prach == WAIT_CONTENTION_RESOLUTION) { LOG_D(PHY, "In %s: [UE %d] RA waiting contention resolution\n", __FUNCTION__, mod_id); ue->UE_mode[gNB_id] = RA_WAIT_CR; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index fb06cf749a..1666050e3a 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -242,6 +242,31 @@ typedef enum { RA_FAILED = 5 } RA_state_t; +typedef struct { + /// PRACH format retrieved from prach_ConfigIndex + uint16_t prach_format; + /// Preamble Tx Counter + uint8_t RA_PREAMBLE_TRANSMISSION_COUNTER; + /// Preamble Power Ramping Counter + uint8_t RA_PREAMBLE_POWER_RAMPING_COUNTER; + /// 2-step RA power offset + int POWER_OFFSET_2STEP_RA; + /// Target received power at gNB. Baseline is range -202..-60 dBm. Depends on delta preamble, power ramping counter and step. + int ra_PREAMBLE_RECEIVED_TARGET_POWER; + /// PRACH index for TDD (0 ... 6) depending on TDD configuration and prachConfigIndex + uint8_t ra_TDD_map_index; + /// RA Preamble Power Ramping Step in dB + uint32_t RA_PREAMBLE_POWER_RAMPING_STEP; + /// + uint8_t RA_PREAMBLE_BACKOFF; + /// + uint8_t RA_SCALING_FACTOR_BI; + /// Indicating whether it is 2-step or 4-step RA + nr_ra_type_e RA_TYPE; + /// UE configured maximum output power + int RA_PCMAX; +} NR_PRACH_RESOURCES_t; + typedef struct { // pointer to RACH config dedicated @@ -302,6 +327,8 @@ typedef struct { /// RA SearchSpace NR_SearchSpace_t *ss; + + NR_PRACH_RESOURCES_t prach_resources; } RA_config_t; typedef struct { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 6d7eeb4b38..16b28d634d 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -392,6 +392,8 @@ void nr_ra_failed(uint8_t mod_id, uint8_t CC_id, NR_PRACH_RESOURCES_t *prach_res void nr_ra_succeeded(module_id_t mod_id, frame_t frame, int slot); +void nr_get_RA_window(NR_UE_MAC_INST_t *mac); + /* \brief Function called by PHY to retrieve information to be transmitted using the RA procedure. If the UE is not in PUSCH mode for a particular eNB index, this is assumed to be an Msg3 and MAC attempts to retrieves the CCCH message from RRC. If the UE is in PUSCH mode for a particular eNB @@ -403,8 +405,7 @@ andom-access to transmit a BSR along with the C-RNTI control element (see 5.1.4 @param gNB_id gNB index @param nr_slot_tx slot for PRACH transmission @returns indication to generate PRACH to phy */ -uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, - fapi_nr_ul_config_prach_pdu *prach_pdu, +uint8_t nr_ue_get_rach(fapi_nr_ul_config_prach_pdu *prach_pdu, module_id_t mod_id, int CC_id, frame_t frame, @@ -424,7 +425,15 @@ void nr_get_prach_resources(module_id_t mod_id, fapi_nr_ul_config_prach_pdu *prach_pdu, NR_RACH_ConfigDedicated_t * rach_ConfigDedicated); -void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id); +void init_RA(module_id_t mod_id, + NR_PRACH_RESOURCES_t *prach_resources, + NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon, + NR_RACH_ConfigGeneric_t *rach_ConfigGeneric, + NR_RACH_ConfigDedicated_t *rach_ConfigDedicated); + +void set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_pdu); + +void nr_Msg1_transmitted(module_id_t mod_id); void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, slot_t slotP, uint8_t gNB_id); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 9833ccbe35..f18f926bd4 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -527,7 +527,6 @@ void ra_preambles_config(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t ra->ra_PreambleIndex = ra->starting_preamble_nb + sizeOfRA_PreamblesGroupA + (rand_r((unsigned int *)seed) % (ra->cb_preambles_per_ssb - sizeOfRA_PreamblesGroupA)); } } - prach_resources->ra_PreambleIndex = ra->ra_PreambleIndex; } // RA-RNTI computation (associated to PRACH occasion in which the RA Preamble is transmitted) @@ -537,7 +536,7 @@ void ra_preambles_config(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t // - f_id: index of the PRACH occasion in the frequency domain // - s_id is starting symbol of the PRACH occasion [0...14] // - t_id is the first slot of the PRACH occasion in a system frame [0...80] -uint16_t set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_pdu){ +void set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_pdu){ RA_config_t *ra = &mac->ra; uint8_t ul_carrier_id = 0; // NUL @@ -548,9 +547,6 @@ uint16_t set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_p ra->ra_rnti = 1 + s_id + 14 * t_id + 1120 * f_id + 8960 * ul_carrier_id; LOG_D(MAC, "Computed ra_RNTI is %x \n", ra->ra_rnti); - - return ra->ra_rnti; - } // This routine implements Section 5.1.2 (UE Random Access Resource Selection) @@ -563,12 +559,12 @@ uint16_t set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_p // -- else if CSI-RS is selected above // - switch initialisation cases // -- RA initiated by beam failure recovery operation (subclause 5.17 TS 38.321) -// --- SSB selection, set prach_resources->ra_PreambleIndex +// --- SSB selection, set ra_PreambleIndex // -- RA initiated by PDCCH: ra_preamble_index provided by PDCCH && ra_PreambleIndex != 0b000000 // --- set PREAMBLE_INDEX to ra_preamble_index // --- select the SSB signalled by PDCCH // -- RA initiated for SI request: -// --- SSB selection, set prach_resources->ra_PreambleIndex +// --- SSB selection, set ra_PreambleIndex // - condition on notification of suspending power ramping counter from lower layer (5.1.3 TS 38.321) // - check if SSB or CSI-RS have not changed since the selection in the last RA Preamble tranmission // - Contention-based RA preamble selection: @@ -578,7 +574,7 @@ void nr_get_prach_resources(module_id_t mod_id, uint8_t gNB_id, NR_PRACH_RESOURCES_t *prach_resources, fapi_nr_ul_config_prach_pdu *prach_pdu, - NR_RACH_ConfigDedicated_t * rach_ConfigDedicated){ + NR_RACH_ConfigDedicated_t *rach_ConfigDedicated){ NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); RA_config_t *ra = &mac->ra; @@ -593,8 +589,7 @@ void nr_get_prach_resources(module_id_t mod_id, if (rach_ConfigDedicated->cfra){ uint8_t cfra_ssb_resource_idx = 0; ra->ra_PreambleIndex = rach_ConfigDedicated->cfra->resources.choice.ssb->ssb_ResourceList.list.array[cfra_ssb_resource_idx]->ra_PreambleIndex; - prach_resources->ra_PreambleIndex = ra->ra_PreambleIndex; - LOG_D(MAC, "In %s: selected RA preamble index %d for contention-free random access procedure for SSB with Id %d\n", __FUNCTION__, prach_resources->ra_PreambleIndex, cfra_ssb_resource_idx); + LOG_D(MAC, "In %s: selected RA preamble index %d for contention-free random access procedure for SSB with Id %d\n", __FUNCTION__, ra->ra_PreambleIndex, cfra_ssb_resource_idx); } } else { /* TODO: This controls the tx_power of UE and the ramping procedure of RA of UE. Later we @@ -602,18 +597,18 @@ void nr_get_prach_resources(module_id_t mod_id, int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? get_nr_PL(mod_id, CC_id, gNB_id) : 0; ssb_rach_config(ra, prach_resources, nr_rach_ConfigCommon, prach_pdu); ra_preambles_config(prach_resources, mac, dl_pathloss); - LOG_D(MAC, "[RAPROC] - Selected RA preamble index %d for contention-based random access procedure... \n", prach_resources->ra_PreambleIndex); + LOG_D(MAC, "[RAPROC] - Selected RA preamble index %d for contention-based random access procedure... \n", ra->ra_PreambleIndex); } if (prach_resources->RA_PREAMBLE_TRANSMISSION_COUNTER > 1) prach_resources->RA_PREAMBLE_POWER_RAMPING_COUNTER++; prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = nr_get_Po_NOMINAL_PUSCH(prach_resources, mod_id, CC_id); - prach_resources->ra_RNTI = set_ra_rnti(mac, prach_pdu); } // TbD: RA_attempt_number not used -void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id){ +void nr_Msg1_transmitted(module_id_t mod_id){ + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); RA_config_t *ra = &mac->ra; ra->ra_state = WAIT_RAR; @@ -659,8 +654,7 @@ void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, slot * @gNB_id gNB ID * @nr_slot_tx current UL TX slot */ -uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, - fapi_nr_ul_config_prach_pdu *prach_pdu, +uint8_t nr_ue_get_rach(fapi_nr_ul_config_prach_pdu *prach_pdu, module_id_t mod_id, int CC_id, frame_t frame, @@ -669,12 +663,8 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); RA_config_t *ra = &mac->ra; - NR_RACH_ConfigCommon_t *setup; - if (mac->scc) setup = mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; - else setup = mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup; - AssertFatal(&setup->rach_ConfigGeneric != NULL, "In %s: FATAL! rach_ConfigGeneric is NULL...\n", __FUNCTION__); - NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric; NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = ra->rach_ConfigDedicated; + NR_PRACH_RESOURCES_t *prach_resources = &ra->prach_resources; // Delay init RA procedure to allow the convergence of the IIR filter on PRACH noise measurements at gNB side if (ra->ra_state == RA_UE_IDLE) { @@ -682,7 +672,7 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, ((MAX_FRAME_NUMBER + frame - mac->first_sync_frame) % MAX_FRAME_NUMBER) > 150) { ra->ra_state = GENERATE_PREAMBLE; } else { - LOG_D(NR_MAC,"PRACH Condition not met: ra state %d, frame %d, prach_resources->sync_frame %d\n", ra->ra_state, frame, mac->first_sync_frame); + LOG_D(NR_MAC,"PRACH Condition not met: ra state %d, frame %d, sync_frame %d\n", ra->ra_state, frame, mac->first_sync_frame); return 0; } } @@ -774,17 +764,10 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, } - if (size_sdu > 0 && (ra->generate_nr_prach == GENERATE_PREAMBLE || get_softmodem_params()->nsa)) { + if (size_sdu > 0 && (ra->ra_state == GENERATE_PREAMBLE || get_softmodem_params()->nsa)) { LOG_D(NR_MAC, "In %s: [UE %d][%d.%d]: starting initialisation Random Access Procedure...\n", __FUNCTION__, mod_id, frame, nr_slot_tx); - // Init RA procedure - init_RA(mod_id, prach_resources, setup, rach_ConfigGeneric, rach_ConfigDedicated); - nr_get_RA_window(mac); - // Fill in preamble and PRACH resources - if (ra->generate_nr_prach == GENERATE_PREAMBLE) - nr_get_prach_resources(mod_id, CC_id, gNB_id, prach_resources, prach_pdu, rach_ConfigDedicated); - // Padding: fill remainder with 0 if (TBS_max - ra->Msg3_size > 0) { AssertFatal(TBS_max > ra->Msg3_size, "In %s: allocated resources are not enough for Msg3!\n", __FUNCTION__); @@ -867,12 +850,7 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, } LOG_D(MAC,"ra->generate_nr_prach %d ra->ra_state %d (GENERATE_IDLE %d)\n",ra->generate_nr_prach,ra->ra_state,GENERATE_IDLE); - if(ra->generate_nr_prach != GENERATE_IDLE) { - return ra->generate_nr_prach; - } else { - return ra->ra_state; - } - + return ra->generate_nr_prach; } void nr_get_RA_window(NR_UE_MAC_INST_t *mac){ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 21fa6176d4..7f6af3a444 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -2704,6 +2704,9 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s ra->generate_nr_prach = GENERATE_PREAMBLE; + init_RA(module_idP, &ra->prach_resources, setup, rach_ConfigGeneric, ra->rach_ConfigDedicated); + nr_get_RA_window(mac); + format = prach_occasion_info_p->format; format0 = format & 0xff; // single PRACH format format1 = (format >> 8) & 0xff; // dual PRACH format @@ -2797,9 +2800,16 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s } } // if format1 + nr_get_prach_resources(module_idP, 0, 0, &ra->prach_resources, prach_config_pdu, ra->rach_ConfigDedicated); + prach_config_pdu->ra_PreambleIndex = ra->ra_PreambleIndex; + prach_config_pdu->preamble_target_power = ra->prach_resources.ra_PREAMBLE_RECEIVED_TARGET_POWER; + set_ra_rnti(mac, prach_config_pdu); + fill_scheduled_response(&scheduled_response, NULL, ul_config, NULL, module_idP, 0 /*TBR fix*/, frameP, slotP, NULL); if(mac->if_module != NULL && mac->if_module->scheduled_response != NULL) mac->if_module->scheduled_response(&scheduled_response); + + nr_Msg1_transmitted(module_idP); } // is_nr_prach_slot } // if is_nr_UL_slot } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index 6f9011e6ed..585a176e75 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -946,7 +946,7 @@ void nr_get_Msg3alloc(module_id_t module_id, tdd_beam_association[num_tdd_period] = ra->beam_id; } - LOG_D(NR_MAC, "[RAPROC] Msg3 slot %d: current slot %u Msg3 frame %u k2 %u Msg3_tda_id %u\n", ra->Msg3_slot, current_slot, ra->Msg3_frame, k2,ra->Msg3_tda_id); + LOG_I(NR_MAC, "[RAPROC] Msg3 slot %d: current slot %u Msg3 frame %u k2 %u Msg3_tda_id %u\n", ra->Msg3_slot, current_slot, ra->Msg3_frame, k2,ra->Msg3_tda_id); uint16_t *vrb_map_UL = &RC.nrmac[module_id]->common_channels[CC_id].vrb_map_UL[ra->Msg3_slot * MAX_BWP_SIZE]; From c07cbce037d7abc8bcd35291d2bbd1fa513843a8 Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 21 Oct 2022 12:01:14 +0200 Subject: [PATCH 3/6] better handling of PRACH TX power to improve separation between PHY and MAC --- CMakeLists.txt | 1 - .../nfapi/public_inc/fapi_nr_ue_interface.h | 5 +- openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 2 +- .../PHY/NR_UE_ESTIMATION/nr_ue_measurements.c | 37 ++---- openair1/PHY/defs_nr_UE.h | 2 + openair1/PHY/defs_nr_common.h | 1 - openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 13 +- openair1/SCHED_NR_UE/pucch_uci_ue_nr.c | 2 +- openair1/SIMULATION/NR_PHY/prachsim.c | 13 +- openair2/GNB_APP/gnb_config.c | 1 + .../NR_MAC_COMMON/nr_compute_tbs_common.c | 4 +- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 22 ++-- openair2/LAYER2/NR_MAC_UE/mac_proto.h | 2 + openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 2 - openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c | 119 ------------------ openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h | 27 ---- openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 96 +++++++++++++- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 2 +- .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c | 1 - openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 13 +- openair2/RRC/NR/MESSAGES/asn1_msg.c | 1 - openair2/RRC/NR/nr_rrc_extern.h | 2 + 23 files changed, 151 insertions(+), 219 deletions(-) delete mode 100644 openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c delete mode 100644 openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8559320d51..81cc1edf76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2021,7 +2021,6 @@ set (MAC_NR_SRC_UE ${NR_UE_MAC_DIR}/nr_ue_procedures.c ${NR_UE_MAC_DIR}/nr_ue_scheduler.c ${NR_UE_MAC_DIR}/nr_ue_dci_configuration.c - ${NR_UE_MAC_DIR}/nr_l1_helpers.c ${NR_UE_MAC_DIR}/nr_ra_procedures.c ) diff --git a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h index 15aba4a541..fe12b5c1e3 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h @@ -119,6 +119,7 @@ typedef struct { uint16_t cell_id; uint16_t ssb_start_subcarrier; short rsrp_dBm; + int16_t pathloss; } fapi_nr_ssb_pdu_t; typedef struct { @@ -193,8 +194,8 @@ typedef struct { uint8_t ssb_nb_in_ro; /// Preamble index for PRACH (0-63) uint8_t ra_PreambleIndex; - /// Target received power at gNB (TODO possibly modify to uint) - int preamble_target_power; + /// PRACH TX power (TODO possibly modify to uint) + int16_t prach_tx_power; } fapi_nr_ul_config_prach_pdu; typedef struct { diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index f01a2af606..697c70bb21 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -122,7 +122,7 @@ void phy_adjust_gain_nr(PHY_VARS_NR_UE *ue, uint32_t rx_power_fil_dB, uint8_t gNB_id); -int16_t get_nr_PL(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index); +void compute_nr_PL(PHY_VARS_NR_UE *ue, int ssb_index); void nr_pdsch_ptrs_processing(PHY_VARS_NR_UE *ue, NR_UE_PDSCH **pdsch_vars, diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c index b0756282a3..518a083ac2 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c @@ -52,34 +52,23 @@ // - PRACH transmission from a UE is not in response to a detection of a PDCCH order by the UE // Measurement units: // - referenceSignalPower: dBm/RE (average EPRE of the resources elements that carry secondary synchronization signals in dBm) -int16_t get_nr_PL(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_index){ +void compute_nr_PL(PHY_VARS_NR_UE *ue, int ssb_index){ - PHY_VARS_NR_UE *ue = PHY_vars_UE_g[Mod_id][CC_id]; - int16_t pathloss; + //TODO improve PL measurements. Probably not correct as it is. - if (get_softmodem_params()->do_ra){ + long referenceSignalPower = ue->nrUE_config.ssb_config.ss_pbch_power; + int16_t pathloss = (int16_t)(referenceSignalPower - ue->measurements.ssb_rsrp_dBm[ssb_index]); - long referenceSignalPower = ue->nrUE_config.ssb_config.ss_pbch_power; - - pathloss = (int16_t)(referenceSignalPower - ue->measurements.rsrp_dBm[gNB_index]); - - LOG_D(MAC, "In %s: pathloss %d dB, UE RX total gain %d dB, referenceSignalPower %ld dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", - __FUNCTION__, - pathloss, - ue->rx_total_gain_dB, - referenceSignalPower, - pow(10, referenceSignalPower/10), - ue->measurements.rsrp_dBm[gNB_index], - pow(10, ue->measurements.rsrp_dBm[gNB_index]/10)); - - } else { - - pathloss = ((int16_t)(((10*ue->rx_total_gain_dB) - dB_fixed_times10(ue->measurements.rsrp[gNB_index]))/10)); - - } - - return pathloss; + LOG_D(PHY, "In %s: pathloss %d dB, UE RX total gain %d dB, referenceSignalPower %ld dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", + __FUNCTION__, + pathloss, + ue->rx_total_gain_dB, + referenceSignalPower, + pow(10, referenceSignalPower/10), + ue->measurements.ssb_rsrp_dBm[ssb_index], + pow(10, ue->measurements.ssb_rsrp_dBm[ssb_index]/10)); + ue->measurements.pathloss = pathloss; } uint32_t get_nr_rx_total_gain_dB (module_id_t Mod_id,uint8_t CC_id) diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index a2f39880ca..35dc8f2cdb 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -147,6 +147,8 @@ typedef struct { //! total estimated noise power (dBm) short n0_power_tot_dBm; + int16_t pathloss; + // UE measurements //! estimated received spatial signal power (linear) int rx_spatial_power[NUMBER_OF_CONNECTED_gNB_MAX][2][2]; diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index dbd402b2ac..fe0397970b 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -93,7 +93,6 @@ #define NR_MAX_NB_HARQ_PROCESSES 16 #define NR_MAX_PDSCH_TBS 3824 -#define NR_MAX_SIB_LENGTH 2976 // 3GPP TS 38.331 section 5.2.1 - The physical layer imposes a limit to the maximum size a SIB can take. The maximum SIB1 or SI message size is 2976 bits. #define MAX_NUM_NR_DLSCH_SEGMENTS_PER_LAYER 36 diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 672198cf99..58a893a543 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -52,7 +52,6 @@ #include "executables/softmodem-common.h" #include "executables/nr-uesoftmodem.h" #include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h" //#define DEBUG_PHY_PROC #define NR_PDCCH_SCHED @@ -174,6 +173,7 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind, rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.cell_id = frame_parms->Nid_cell; rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.ssb_start_subcarrier = frame_parms->ssb_start_subcarrier; rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.rsrp_dBm = ue->measurements.ssb_rsrp_dBm[frame_parms->ssb_index]; + rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.pathloss = ue->measurements.pathloss; break; case FAPI_NR_CSIRS_IND: memcpy(&rx_ind->rx_indication_body[n_pdus - 1].csirs_measurements, @@ -1100,6 +1100,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, LOG_D(PHY," ------ Decode MIB: frame.slot %d.%d ------ \n", frame_rx%1024, nr_slot_rx); nr_ue_pbch_procedures(gNB_id, ue, proc, estimateSz, dl_ch_estimates, phy_pdcch_config); + compute_nr_PL(ue, ssb_index); if (ue->no_timing_correction==0) { LOG_D(PHY,"start adjust sync slot = %d no timing %d\n", nr_slot_rx, ue->no_timing_correction); @@ -1460,19 +1461,15 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t if (nr_prach == GENERATE_PREAMBLE) { fapi_nr_ul_config_prach_pdu *prach_pdu = &ue->prach_vars[gNB_id]->prach_pdu; - int16_t pathloss = get_nr_PL(mod_id, ue->CC_id, gNB_id); - int16_t ra_preamble_rx_power = (int16_t)(prach_pdu->preamble_target_power - pathloss + 30); - ue->tx_power_dBm[nr_slot_tx] = min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); + ue->tx_power_dBm[nr_slot_tx] = prach_pdu->prach_tx_power; - LOG_D(PHY, "In %s: [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, PL %d dB, P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm)\n", + LOG_D(PHY, "In %s: [UE %d][RAPROC][%d.%d]: Generating PRACH Msg1 (preamble %d, P0_PRACH %d)\n", __FUNCTION__, mod_id, frame_tx, nr_slot_tx, prach_pdu->ra_PreambleIndex, - pathloss, - ue->tx_power_dBm[nr_slot_tx], - prach_pdu->preamble_target_power); + ue->tx_power_dBm[nr_slot_tx]); ue->prach_vars[gNB_id]->amp = AMP; diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c index 163a828003..6ed543daa1 100644 --- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c @@ -215,7 +215,7 @@ void pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, /* Generate PUCCH signal according to its format and parameters */ ue->generate_ul_signal[gNB_id] = 1; - int16_t PL = get_nr_PL(ue->Mod_id, ue->CC_id, gNB_id); /* LTE function because NR path loss not yet implemented FFS TODO NR */ + int16_t PL = ue->measurements.pathloss; /* LTE function because NR path loss not yet implemented FFS TODO NR */ int contributor = (10 * log10((double)(pow(2,(ue->frame_parms.numerology_index)) * nb_of_prbs))); int16_t pucch_tx_power = pucch_pdu->pucch_tx_power + contributor + PL; diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c index d0f3af4e60..be07f22769 100644 --- a/openair1/SIMULATION/NR_PHY/prachsim.c +++ b/openair1/SIMULATION/NR_PHY/prachsim.c @@ -264,7 +264,6 @@ int main(int argc, char **argv){ int n_bytes=0; NR_DL_FRAME_PARMS *frame_parms; - NR_PRACH_RESOURCES_t prach_resources; nfapi_nr_prach_config_t *prach_config; nfapi_nr_prach_pdu_t *prach_pdu; fapi_nr_prach_config_t *ue_prach_config; @@ -694,7 +693,6 @@ int main(int argc, char **argv){ ue_prach_pdu = &UE->prach_vars[0]->prach_pdu; ue_prach_config = &UE->nrUE_config.prach_config; - UE->prach_resources[0] = &prach_resources; txdata = UE->common_vars.txdata; UE->prach_vars[0]->amp = AMP; @@ -717,7 +715,7 @@ int main(int argc, char **argv){ if (n_frames == 1) printf("raPreamble %d\n",preamble_tx); - UE->prach_resources[0]->ra_PreambleIndex = preamble_tx; + ue_prach_pdu->ra_PreambleIndex = preamble_tx; // Configure channel bw = N_RB_UL*(180e3)*(1 << frame_parms->numerology_index); @@ -768,14 +766,7 @@ int main(int argc, char **argv){ ue_prach_config->num_prach_fd_occasions_list[fd_occasion].prach_root_sequence_index, UE->X_u); - /*tx_lev = generate_nr_prach(UE, - 0, //gNB_id, - subframe); */ //commented for testing purpose - - UE_nr_rxtx_proc_t proc={0}; - proc.frame_tx = frame; - proc.nr_slot_tx = slot; - nr_ue_prach_procedures(UE, &proc, 0); + tx_lev = generate_nr_prach(UE, 0, frame, slot); /* tx_lev_dB not used later, no need to set */ //tx_lev_dB = (unsigned int) dB_fixed(tx_lev); diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index a85840a38b..92255f065a 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -83,6 +83,7 @@ #include "NR_EUTRA-MBSFN-SubframeConfig.h" #include "RRC/NR/MESSAGES/asn1_msg.h" +#include "RRC/NR/nr_rrc_extern.h" #include "openair2/LAYER2/nr_pdcp/nr_pdcp.h" extern uint16_t sf_ahead; diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c index 4d7335713a..b4bb72dd31 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_compute_tbs_common.c @@ -27,7 +27,6 @@ #include "common/utils/nr/nr_common.h" #include -#include "PHY/defs_nr_common.h" //Table 5.1.2.2-2 uint16_t Tbstable_nr[INDEX_MAX_TBS_TABLE] = {24,32,40,48,56,64,72,80,88,96,104,112,120,128,136,144,152,160,168,176,184,192,208,224,240,256,272,288,304,320,336,352,368,384,408,432,456,480,504,528,552,576,608,640,672,704,736,768,808,848,888,928,984,1032,1064,1128,1160,1192,1224,1256,1288,1320,1352,1416,1480,1544,1608,1672,1736,1800,1864,1928,2024,2088,2152,2216,2280,2408,2472,2536,2600,2664,2728,2792,2856,2976,3104,3240,3368,3496,3624,3752,3824}; @@ -48,7 +47,8 @@ uint32_t nr_compute_tbs(uint16_t Qm, LOG_D(NR_MAC, "In %s: nb_symb_sch %d, nb_dmrs_prb %d, nb_rb %d, nb_rb_oh %d, tb_scaling %d Nl %d\n", __FUNCTION__, nb_symb_sch, nb_dmrs_prb, nb_rb, nb_rb_oh, tb_scaling, Nl); - const uint32_t nbp_re = NR_NB_SC_PER_RB * nb_symb_sch - nb_dmrs_prb - nb_rb_oh; + const int nb_subcarrier_per_rb = 12; + const uint32_t nbp_re = nb_subcarrier_per_rb * nb_symb_sch - nb_dmrs_prb - nb_rb_oh; const uint32_t nb_re = min(156, nbp_re) * nb_rb; // Intermediate number of information bits // Rx1024 is tabulated as 10 times the actual code rate diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 1666050e3a..4bf062dca9 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -38,9 +38,6 @@ #include #include "platform_types.h" -/* PHY */ -#include "PHY/defs_nr_common.h" - /* IF */ #include "NR_IF_Module.h" #include "fapi_nr_ue_interface.h" @@ -64,10 +61,7 @@ #include "NR_CellGroupConfig.h" #include "NR_ServingCellConfig.h" #include "NR_MeasConfig.h" -#include "fapi_nr_ue_interface.h" -#include "NR_IF_Module.h" -#include "PHY/defs_nr_common.h" -#include "openair2/LAYER2/NR_MAC_COMMON/nr_mac.h" + // ========== // NR UE defs @@ -371,6 +365,16 @@ typedef struct { int8_t delta_pucch; } PUCCH_sched_t; +typedef struct { + + uint32_t ssb_index; + /// SSB RSRP in dBm + short ssb_rsrp_dBm; + /// SSB pathloss + int16_t pathloss; + +} NR_PHY_meas_t; + /*!\brief Top level UE MAC structure */ typedef struct { @@ -423,8 +427,6 @@ typedef struct { RA_config_t ra; /// SSB index from MIB decoding uint8_t mib_ssb; - /// measured SSB RSRP in dBm - short ssb_rsrp_dBm; nr_csi_report_t csi_report_template[MAX_CSI_REPORTCONFIG]; @@ -460,6 +462,8 @@ typedef struct { uint16_t nr_band; uint8_t ssb_subcarrier_offset; + NR_PHY_meas_t phy_measurements; + dci_pdu_rel15_t def_dci_pdu_rel15[8]; // Defined for abstracted mode diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 16b28d634d..eece1a84ff 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -431,6 +431,8 @@ void init_RA(module_id_t mod_id, NR_RACH_ConfigGeneric_t *rach_ConfigGeneric, NR_RACH_ConfigDedicated_t *rach_ConfigDedicated); +int16_t get_prach_tx_power(module_id_t mod_id); + void set_ra_rnti(NR_UE_MAC_INST_t *mac, fapi_nr_ul_config_prach_pdu *prach_pdu); void nr_Msg1_transmitted(module_id_t mod_id); diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 1e59782d21..d7162d9bf1 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -35,8 +35,6 @@ #include "radio/COMMON/common_lib.h" //#undef MALLOC #include "assertions.h" -#include "PHY/types.h" -#include "PHY/defs_UE.h" #include "openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h" #include "executables/softmodem-common.h" #include "openair2/LAYER2/nr_pdcp/nr_pdcp.h" diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c deleted file mode 100644 index 2d704b5c81..0000000000 --- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c +++ /dev/null @@ -1,119 +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 - */ - -/*! \file nr_l1_helper.c -* \brief PHY/MAC helper functions -* \author Guido Casati -* \date 2019 -* \version 2.0 -* \email guido.casati@iis.fraunhofer.de -* @ingroup _mac - -*/ - -#include "PHY/defs_nr_common.h" -//#include "PHY/impl_defs_top.h" - -#include "mac_defs.h" -#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" -#include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h" -#include "NR_P-Max.h" - -// Implementation of 6.2.4 Configured ransmitted power -// 3GPP TS 38.101-1 version 16.5.0 Release 16 -// - -// The UE is allowed to set its configured maximum output power PCMAX,f,c for carrier f of serving cell c in each slot. -// The configured maximum output power PCMAX,f,c is set within the following bounds: PCMAX_L,f,c <= PCMAX,f,c <= PCMAX_H,f,c -// - -// Measurement units: -// - p_max: dBm -// - delta_TC_c: dB -// - P_powerclass: dBm -// - delta_P_powerclass: dB -// - MPR_c: dB -// - delta_MPR_c: dB -// - delta_T_IB_c dB -// - delta_rx_SRS dB -// note: -// - Assuming: -// -- Powerclass 3 capable UE (which is default power class unless otherwise stated) -// -- Maximum power reduction (MPR_c) for power class 3, QPSK, inner RB allocations -// -- no additional MPR (A_MPR_c) -// todo: -// - in current implementation delta_P_powerclass is not handling power classes different from 3 -long nr_get_Pcmax(module_id_t mod_id){ - - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - uint32_t band = (mac->scc!=NULL) ? *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0] : - *mac->scc_SIB->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list.array[0]->freqBandIndicatorNR; - NR_P_Max_t p_max = 0; - uint8_t P_powerclass = 23; - uint8_t delta_P_powerclass = 0; - uint8_t MPR_c = 1.5; - uint8_t delta_MPR_c = 0; - uint8_t A_MPR_c = 0; - uint8_t delta_T_IB_c = 0; - uint8_t delta_TC_c = 0; - uint8_t delta_rx_SRS = 0; - uint8_t P_MPR_c = 0; - long P_cmax_l = 0; - long P_cmax_h = 0; - long P_cmax = 0; - - if (band == 28 && mac->phy_config.config_req.carrier_config.uplink_bandwidth == 30){ - delta_MPR_c = 0.5; - } - - if (mac->cg && mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->ext1){ - if (*mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->ext1->powerBoostPi2BPSK == 1){ - // TbD: assuming power class 3 capable UE operating in TDD bands n40, n41, n77, n78, and n79 with Pi/2 BPSK modulation - delta_P_powerclass = -3; - p_max += 3; - } - } - - NR_P_Max_t *p_Max = (mac->scc!=NULL) ? mac->scc->uplinkConfigCommon->frequencyInfoUL->p_Max : mac->scc_SIB->uplinkConfigCommon->frequencyInfoUL.p_Max; - if (p_Max){ - - p_max += *p_Max; - - LOG_D(MAC, "In %s maximum UL transmission power p_max is %ld dBm \n", __FUNCTION__, p_max); - - P_cmax_l = min(p_max - delta_TC_c, (P_powerclass - delta_P_powerclass) - max(max(MPR_c + delta_MPR_c, A_MPR_c) + delta_T_IB_c + delta_TC_c + delta_rx_SRS, P_MPR_c)); - - P_cmax_h = min(p_max, P_powerclass - delta_P_powerclass); - - } else { - - P_cmax_l = (P_powerclass - delta_P_powerclass) - max(max(MPR_c + delta_MPR_c, A_MPR_c) + delta_T_IB_c + delta_TC_c + delta_rx_SRS, P_MPR_c); - - P_cmax_h = P_powerclass - delta_P_powerclass; - - } - - P_cmax = (P_cmax_h + P_cmax_l) / 2; - - LOG_D(MAC, "In %s configured maximum output power: %ld dBm <= PCMAX %ld dBm <= %ld dBm \n", __FUNCTION__, P_cmax_l, P_cmax, P_cmax_h); - - return P_cmax; - -} diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h deleted file mode 100644 index 3bfeb29e2e..0000000000 --- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h +++ /dev/null @@ -1,27 +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 - */ - -/** \brief Function to compute configured maximum output power according to clause 6.2.4 of 3GPP TS 38.101-1 version 16.5.0 Release 16 - @param Mod_id Module id of UE -*/ -long nr_get_Pcmax(module_id_t mod_id); -/** @}*/ - diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index f18f926bd4..bfcc5fa2eb 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -34,18 +34,102 @@ #include "NR_RACH-ConfigCommon.h" #include "RRC/NR_UE/rrc_proto.h" -/* PHY */ -#include "PHY/NR_UE_ESTIMATION/nr_estimation.h" - /* MAC */ #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" #include "NR_MAC_COMMON/nr_mac.h" #include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h" #include -void nr_get_RA_window(NR_UE_MAC_INST_t *mac); +// Implementation of 6.2.4 Configured ransmitted power +// 3GPP TS 38.101-1 version 16.5.0 Release 16 +// - +// The UE is allowed to set its configured maximum output power PCMAX,f,c for carrier f of serving cell c in each slot. +// The configured maximum output power PCMAX,f,c is set within the following bounds: PCMAX_L,f,c <= PCMAX,f,c <= PCMAX_H,f,c +// - +// Measurement units: +// - p_max: dBm +// - delta_TC_c: dB +// - P_powerclass: dBm +// - delta_P_powerclass: dB +// - MPR_c: dB +// - delta_MPR_c: dB +// - delta_T_IB_c dB +// - delta_rx_SRS dB +// note: +// - Assuming: +// -- Powerclass 3 capable UE (which is default power class unless otherwise stated) +// -- Maximum power reduction (MPR_c) for power class 3, QPSK, inner RB allocations +// -- no additional MPR (A_MPR_c) +// todo: +// - in current implementation delta_P_powerclass is not handling power classes different from 3 +long nr_get_Pcmax(module_id_t mod_id){ + + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + uint32_t band = (mac->scc!=NULL) ? *mac->scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0] : + *mac->scc_SIB->downlinkConfigCommon.frequencyInfoDL.frequencyBandList.list.array[0]->freqBandIndicatorNR; + NR_P_Max_t p_max = 0; + uint8_t P_powerclass = 23; + uint8_t delta_P_powerclass = 0; + uint8_t MPR_c = 1.5; + uint8_t delta_MPR_c = 0; + uint8_t A_MPR_c = 0; + uint8_t delta_T_IB_c = 0; + uint8_t delta_TC_c = 0; + uint8_t delta_rx_SRS = 0; + uint8_t P_MPR_c = 0; + long P_cmax_l = 0; + long P_cmax_h = 0; + long P_cmax = 0; + + if (band == 28 && mac->phy_config.config_req.carrier_config.uplink_bandwidth == 30){ + delta_MPR_c = 0.5; + } + + if (mac->cg && mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->ext1){ + if (*mac->cg->spCellConfig->spCellConfigDedicated->uplinkConfig->ext1->powerBoostPi2BPSK == 1){ + // TbD: assuming power class 3 capable UE operating in TDD bands n40, n41, n77, n78, and n79 with Pi/2 BPSK modulation + delta_P_powerclass = -3; + p_max += 3; + } + } + + NR_P_Max_t *p_Max = (mac->scc!=NULL) ? mac->scc->uplinkConfigCommon->frequencyInfoUL->p_Max : mac->scc_SIB->uplinkConfigCommon->frequencyInfoUL.p_Max; + if (p_Max){ + + p_max += *p_Max; + + LOG_D(MAC, "In %s maximum UL transmission power p_max is %ld dBm \n", __FUNCTION__, p_max); + + P_cmax_l = min(p_max - delta_TC_c, (P_powerclass - delta_P_powerclass) - max(max(MPR_c + delta_MPR_c, A_MPR_c) + delta_T_IB_c + delta_TC_c + delta_rx_SRS, P_MPR_c)); + + P_cmax_h = min(p_max, P_powerclass - delta_P_powerclass); + + } else { + + P_cmax_l = (P_powerclass - delta_P_powerclass) - max(max(MPR_c + delta_MPR_c, A_MPR_c) + delta_T_IB_c + delta_TC_c + delta_rx_SRS, P_MPR_c); + + P_cmax_h = P_powerclass - delta_P_powerclass; + + } + + P_cmax = (P_cmax_h + P_cmax_l) / 2; + + LOG_D(MAC, "In %s configured maximum output power: %ld dBm <= PCMAX %ld dBm <= %ld dBm \n", __FUNCTION__, P_cmax_l, P_cmax, P_cmax_h); + + return P_cmax; + +} + +int16_t get_prach_tx_power(module_id_t mod_id) { + + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + RA_config_t *ra = &mac->ra; + int16_t pathloss = mac->phy_measurements.pathloss; + int16_t ra_preamble_rx_power = (int16_t)(ra->prach_resources.ra_PREAMBLE_RECEIVED_TARGET_POWER - pathloss + 30); + return min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); + +} // Random Access procedure initialization as per 5.1.1 and initialization of variables specific // to Random Access type as specified in clause 5.1.1a (3GPP TS 38.321 version 16.2.1 Release 16) @@ -594,7 +678,7 @@ void nr_get_prach_resources(module_id_t mod_id, } else { /* TODO: This controls the tx_power of UE and the ramping procedure of RA of UE. Later we can abstract this, perhaps in the proxy. But for the time being lets leave it as below. */ - int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? get_nr_PL(mod_id, CC_id, gNB_id) : 0; + int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? mac->phy_measurements.pathloss : 0; ssb_rach_config(ra, prach_resources, nr_rach_ConfigCommon, prach_pdu); ra_preambles_config(prach_resources, mac, dl_pathloss); LOG_D(MAC, "[RAPROC] - Selected RA preamble index %d for contention-based random access procedure... \n", ra->ra_PreambleIndex); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 6b04441cb3..7559bdea81 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -2637,7 +2637,7 @@ uint8_t get_ssb_rsrp_payload(NR_UE_MAC_INST_t *mac, } } AssertFatal(*SSB_resource.list.array[ssb_rsrp[0][0]] == mac->mib_ssb, "Couldn't find corresponding SSB in csi_SSB_ResourceList\n"); - ssb_rsrp[1][0] = mac->ssb_rsrp_dBm; + ssb_rsrp[1][0] = mac->phy_measurements.ssb_rsrp_dBm; uint8_t ssbi; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 7f6af3a444..903b20b037 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -2802,7 +2802,7 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s nr_get_prach_resources(module_idP, 0, 0, &ra->prach_resources, prach_config_pdu, ra->rach_ConfigDedicated); prach_config_pdu->ra_PreambleIndex = ra->ra_PreambleIndex; - prach_config_pdu->preamble_target_power = ra->prach_resources.ra_PREAMBLE_RECEIVED_TARGET_POWER; + prach_config_pdu->prach_tx_power = get_prach_tx_power(module_idP); set_ra_rnti(mac, prach_config_pdu); fill_scheduled_response(&scheduled_response, NULL, ul_config, NULL, module_idP, 0 /*TBR fix*/, frameP, slotP, NULL); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c index d310c461dc..24772f7493 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c @@ -34,7 +34,6 @@ #include "common/utils/nr/nr_common.h" #include "utils.h" #include - #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" //#define SRS_IND_DEBUG diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index e548717459..623567354d 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -1085,6 +1085,14 @@ int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, frame_t } +void handle_ssb_meas(NR_UE_MAC_INST_t *mac, uint8_t ssb_index, int16_t rsrp_dbm, int16_t pathloss) { + + mac->phy_measurements.ssb_index = ssb_index; + mac->phy_measurements.ssb_rsrp_dBm = rsrp_dbm; + mac->phy_measurements.pathloss = pathloss; + +} + // L2 Abstraction Layer // Note: sdu should always be processed because data and timing advance updates are transmitted by the UE int8_t handle_dlsch(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t *ul_time_alignment, int pdu_id){ @@ -1225,7 +1233,10 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_ switch(dl_info->rx_ind->rx_indication_body[i].pdu_type){ case FAPI_NR_RX_PDU_TYPE_SSB: - mac->ssb_rsrp_dBm = (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.rsrp_dBm; + handle_ssb_meas(mac, + (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.ssb_index, + (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.rsrp_dBm, + (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.pathloss); ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, dl_info->phy_data, (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.pdu, (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.additional_bits, diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 9b782cc9bb..6cdf1adeaa 100755 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -75,7 +75,6 @@ #include "NR_DLInformationTransfer.h" #include "NR_RRCReestablishmentRequest.h" #include "NR_UE-CapabilityRequestFilterNR.h" -#include "PHY/defs_nr_common.h" #include "common/utils/nr/nr_common.h" #if defined(NR_Rel16) #include "NR_SCS-SpecificCarrier.h" diff --git a/openair2/RRC/NR/nr_rrc_extern.h b/openair2/RRC/NR/nr_rrc_extern.h index 3b08a24027..af2cfdd2c8 100644 --- a/openair2/RRC/NR/nr_rrc_extern.h +++ b/openair2/RRC/NR/nr_rrc_extern.h @@ -35,6 +35,8 @@ #include "LAYER2/MAC/mac.h" #include "LAYER2/RLC/rlc.h" +#define NR_MAX_SIB_LENGTH 2976 // 3GPP TS 38.331 section 5.2.1 - The physical layer imposes a limit to the maximum size a SIB can take. The maximum SIB1 or SI message size is 2976 bits. + extern UE_RRC_INST *UE_rrc_inst; extern uint8_t DRB2LCHAN[8]; From 21b14dddb4cfdc261605b19e2ae2f67c5270b678 Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 21 Oct 2022 17:11:04 +0200 Subject: [PATCH 4/6] removing unused code in dummy functions --- .../NR_PHY/nr_dummy_functions_prach.c | 333 ------------------ 1 file changed, 333 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c b/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c index 76f4e826ee..71e2577ec3 100644 --- a/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c +++ b/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c @@ -16,338 +16,5 @@ int32_t get_uldl_offset(int nr_bandP) { re NR_IF_Module_t *NR_IF_Module_init(int Mod_id) {return(NULL);} 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); } -/* - * 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 ra_procedures.c - * \brief Routines for UE MAC-layer Random Access procedures (TS 38.321, Release 15) - * \author R. Knopp, Navid Nikaein, Guido Casati - * \date 2019 - * \version 0.1 - * \company Eurecom - * \email: knopp@eurecom.fr navid.nikaein@eurecom.fr, guido.casati@iis.fraunhofer.de - * \note - * \warning - */ - - -/* -#include "common/utils/LOG/vcd_signal_dumper.h" -#include "PHY_INTERFACE/phy_interface_extern.h" -#include "SCHED_UE/sched_UE.h" -#include "COMMON/mac_rrc_primitives.h" -#include "RRC/LTE/rrc_extern.h" -#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" -#include "common/utils/LOG/log.h" -#include "UTIL/OPT/opt.h" -#include "OCG.h" -#include "OCG_extern.h" -#include "PHY/LTE_ESTIMATION/lte_estimation.h"*/ - -/* Tools */ -#include "SIMULATION/TOOLS/sim.h" // for taus - -/* RRC */ -#include "NR_RACH-ConfigCommon.h" - -/* PHY */ -#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h" -#include "PHY/defs_common.h" -#include "PHY/defs_nr_common.h" -#include "PHY/NR_UE_ESTIMATION/nr_estimation.h" - -/* MAC */ -#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" -#include "NR_MAC_COMMON/nr_mac.h" -#include "LAYER2/NR_MAC_UE/mac_proto.h" -#include "LAYER2/MAC/mac.h" - -extern int64_t table_6_3_3_2_2_prachConfig_Index [256][9]; -extern int64_t table_6_3_3_2_3_prachConfig_Index [256][9]; - -//extern uint8_t nfapi_mode; - -// WIP -// This routine implements Section 5.1.2 (UE Random Access Resource Selection) -// and Section 5.1.3 (Random Access Preamble Transmission) from 3GPP TS 38.321 -void nr_get_prach_resources(module_id_t mod_id, - int CC_id, - uint8_t gNB_id, - uint8_t t_id, - NR_PRACH_RESOURCES_t *prach_resources, - NR_RACH_ConfigDedicated_t * rach_ConfigDedicated){ - - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon; - // NR_BeamFailureRecoveryConfig_t *beam_failure_recovery_config = &mac->RA_BeamFailureRecoveryConfig; // todo - - int messagePowerOffsetGroupB = 0, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3 = 0; - uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, msg1_FDM, prach_ConfigIndex, SFN_nbr, Msg3_size; - - // NR_RSRP_Range_t rsrp_ThresholdSSB; // todo - - /////////////////////////////////////////////////////////// - //////////* UE Random Access Resource Selection *////////// - /////////////////////////////////////////////////////////// - - // todo: - // - switch initialisation cases - // -- RA initiated by beam failure recovery operation (subclause 5.17 TS 38.321) - // --- SSB selection, set prach_resources->ra_PreambleIndex - // -- RA initiated by PDCCH: ra_preamble_index provided by PDCCH && ra_PreambleIndex != 0b000000 - // --- set PREAMBLE_INDEX to ra_preamble_index - // --- select the SSB signalled by PDCCH - // -- RA initiated for SI request: - // --- SSB selection, set prach_resources->ra_PreambleIndex - - // if (rach_ConfigDedicated) { // This is for network controlled Mobility - // // operation for contention-free RA resources when: - // // - available SSB with SS-RSRP above rsrp-ThresholdSSB: SSB selection - // // - availalbe CSI-RS with CSI-RSRP above rsrp-ThresholdCSI-RS: CSI-RS selection - // prach_resources->ra_PreambleIndex = rach_ConfigDedicated->ra_PreambleIndex; - // return; - // } - - //////////* Contention-based RA preamble selection *////////// - // todo: - // - selection of SSB with SS-RSRP above rsrp-ThresholdSSB else select any SSB - // - todo determine next available PRACH occasion - - // rsrp_ThresholdSSB = *nr_rach_ConfigCommon->rsrp_ThresholdSSB; - - AssertFatal(mac->nr_rach_ConfigCommon != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); - - nr_rach_ConfigCommon = mac->nr_rach_ConfigCommon; - - Msg3_size = mac->RA_Msg3_size; - numberOfRA_Preambles = *nr_rach_ConfigCommon->totalNumberOfRA_Preambles; - - if (!nr_rach_ConfigCommon->groupBconfigured) { - noGroupB = 1; - } else { - // RA preambles group B is configured - // - Defining the number of RA preambles in RA Preamble Group A for each SSB */ - sizeOfRA_PreamblesGroupA = nr_rach_ConfigCommon->groupBconfigured->numberOfRA_PreamblesGroupA; - switch (nr_rach_ConfigCommon->groupBconfigured->ra_Msg3SizeGroupA){ - /* - Threshold to determine the groups of RA preambles */ - case 0: - messageSizeGroupA = 56; - break; - case 1: - messageSizeGroupA = 144; - break; - case 2: - messageSizeGroupA = 208; - break; - case 3: - messageSizeGroupA = 256; - break; - case 4: - messageSizeGroupA = 282; - break; - case 5: - messageSizeGroupA = 480; - break; - case 6: - messageSizeGroupA = 640; - break; - case 7: - messageSizeGroupA = 800; - break; - case 8: - messageSizeGroupA = 1000; - break; - case 9: - messageSizeGroupA = 72; - break; - default: - AssertFatal(1 == 0,"Unknown ra_Msg3SizeGroupA %lu\n", nr_rach_ConfigCommon->groupBconfigured->ra_Msg3SizeGroupA); - /* todo cases 10 -15*/ - } - - /* Power offset for preamble selection in dB */ - messagePowerOffsetGroupB = -9999; - switch (nr_rach_ConfigCommon->groupBconfigured->messagePowerOffsetGroupB){ - case 0: - messagePowerOffsetGroupB = -9999; - break; - case 1: - messagePowerOffsetGroupB = 0; - break; - case 2: - messagePowerOffsetGroupB = 5; - break; - case 3: - messagePowerOffsetGroupB = 8; - break; - case 4: - messagePowerOffsetGroupB = 10; - break; - case 5: - messagePowerOffsetGroupB = 12; - break; - case 6: - messagePowerOffsetGroupB = 15; - break; - case 7: - messagePowerOffsetGroupB = 18; - break; - default: - AssertFatal(1 == 0,"Unknown messagePowerOffsetGroupB %lu\n", nr_rach_ConfigCommon->groupBconfigured->messagePowerOffsetGroupB); - } - - } - - PLThreshold = prach_resources->RA_PCMAX - nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower - deltaPreamble_Msg3 - messagePowerOffsetGroupB; - - /* Msg3 has not been transmitted yet */ - if (first_Msg3 == 1) { - if (noGroupB == 1) { - // use Group A preamble - prach_resources->ra_PreambleIndex = (taus()) % numberOfRA_Preambles; - mac->RA_usedGroupA = 1; - } else if ((Msg3_size < messageSizeGroupA) && (get_nr_PL(mod_id, CC_id, gNB_id) > PLThreshold)) { - // Group B is configured and RA preamble Group A is used - // - todo add condition on CCCH_sdu_size for initiation by CCCH - prach_resources->ra_PreambleIndex = (taus()) % sizeOfRA_PreamblesGroupA; - mac->RA_usedGroupA = 1; - } else { - // Group B preamble is configured and used - // the first sizeOfRA_PreamblesGroupA RA preambles belong to RA Preambles Group A - // the remaining belong to RA Preambles Group B - prach_resources->ra_PreambleIndex = sizeOfRA_PreamblesGroupA + (taus()) % (numberOfRA_Preambles - sizeOfRA_PreamblesGroupA); - mac->RA_usedGroupA = 0; - } - } else { // Msg3 is being retransmitted - if (mac->RA_usedGroupA == 1 && noGroupB == 1) { - prach_resources->ra_PreambleIndex = (taus()) % numberOfRA_Preambles; - } else if (mac->RA_usedGroupA == 1 && noGroupB == 0){ - prach_resources->ra_PreambleIndex = (taus()) % sizeOfRA_PreamblesGroupA; - } else { - prach_resources->ra_PreambleIndex = sizeOfRA_PreamblesGroupA + (taus()) % (numberOfRA_Preambles - sizeOfRA_PreamblesGroupA); - } - } - - // todo determine next available PRACH occasion - // - if RA initiated for SI request and ra_AssociationPeriodIndex and si-RequestPeriod are configured - // - else if SSB is selected above - // - else if CSI-RS is selected above - - ///////////////////////////////////////////////////////////////////////////// - //////////* Random Access Preamble Transmission (5.1.3 TS 38.321) *////////// - ///////////////////////////////////////////////////////////////////////////// - // todo: - // - condition on notification of suspending power ramping counter from lower layer (5.1.3 TS 38.321) - // - check if SSB or CSI-RS have not changed since the selection in the last RA Preamble tranmission - // - Extend RA_rnti computation (e.g. f_id selection, ul_carrier_id are hardcoded) - - if (mac->RA_PREAMBLE_TRANSMISSION_COUNTER > 1) - mac->RA_PREAMBLE_TRANSMISSION_COUNTER++; - - prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = nr_get_Po_NOMINAL_PUSCH(prach_resources, mod_id, CC_id); - - // RA-RNTI computation (associated to PRACH occasion in which the RA Preamble is transmitted) - // 1) this does not apply to contention-free RA Preamble for beam failure recovery request - // 2) getting star_symb, SFN_nbr from table 6.3.3.2-3 (TDD and FR1 scenario) - - switch (nr_rach_ConfigCommon->rach_ConfigGeneric.msg1_FDM){ // todo this is not used - case 0: - msg1_FDM = 1; - break; - case 1: - msg1_FDM = 2; - break; - case 2: - msg1_FDM = 4; - break; - case 3: - msg1_FDM = 8; - break; - default: - AssertFatal(1 == 0,"Unknown msg1_FDM %lu\n", nr_rach_ConfigCommon->rach_ConfigGeneric.msg1_FDM); - } - - prach_ConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex; - - // ra_RNTI computation - // - todo: this is for TDD FR1 only - // - ul_carrier_id: UL carrier used for RA preamble transmission, hardcoded for NUL carrier - // - f_id: index of the PRACH occasion in the frequency domain - // - s_id is starting symbol of the PRACH occasion [0...14] - // - t_id is the first slot of the PRACH occasion in a system frame [0...80] - - ul_carrier_id = 0; // NUL - f_id = nr_rach_ConfigCommon->rach_ConfigGeneric.msg1_FrequencyStart; - SFN_nbr = table_6_3_3_2_3_prachConfig_Index[prach_ConfigIndex][4]; - s_id = table_6_3_3_2_3_prachConfig_Index[prach_ConfigIndex][5]; - - // Pick the first slot of the PRACH occasion in a system frame - for (i = 0; i < 10; i++){ - if (((SFN_nbr & (1 << i)) >> i) == 1){ - t_id = 2*i; - break; - } - } - prach_resources->ra_RNTI = 1 + s_id + 14 * t_id + 1120 * f_id + 8960 * ul_carrier_id; - mac->ra_rnti = prach_resources->ra_RNTI; - - LOG_D(MAC, "Computed ra_RNTI is %d", prach_resources->ra_RNTI); -} - -// TbD: RA_attempt_number not used -void nr_Msg1_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, uint8_t gNB_id){ - AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n"); - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - mac->ra_state = WAIT_RAR; - // Start contention resolution timer - mac->RA_attempt_number++; -} - -void nr_Msg3_transmitted(module_id_t mod_id, uint8_t CC_id, frame_t frameP, slot_t slotP, uint8_t gNB_id){ - AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n"); - LOG_D(MAC,"[UE %d][RAPROC] Frame %d : Msg3_tx: Starting contention resolution timer\n", mod_id, frameP); - NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); - // start contention resolution timer - mac->RA_contention_resolution_cnt = 0; - mac->RA_contention_resolution_timer_active = 1; -} - -///////////////////////////////////////////////////////////////////////// -///////* Random Access Preamble Initialization (5.1.1 TS 38.321) */////// -///////////////////////////////////////////////////////////////////////// -/// Handling inizialization by PDCCH order, MAC entity or RRC (TS 38.300) -/// Only one RA procedure is ongoing at any point in time in a MAC entity -/// the RA procedure on a SCell shall only be initiated by PDCCH order - -// WIP -// todo TS 38.321: -// - check if carrier to use is explicitly signalled then do (1) RA CARRIER SELECTION (SUL, NUL) (2) set PCMAX -// - BWP operation (subclause 5.15 TS 38.321) -// - handle initialization by beam failure recovery -// - handle initialization by handover -// - handle transmission on DCCH using PRACH (during handover, or sending SR for example) -// - take into account MAC CEs in size_sdu (currently hardcoded size to 1 MAC subPDU and 1 padding subheader) -// - fix rrc data req logic -// - retrieve TBS -// - add mac_rrc_nr_data_req_ue, etc ... -// - add the backoff condition here if we have it from a previous RA reponse which failed (i.e. backoff indicator) From 3b53d82b268c2656fdd08896fbae726eac03838e Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 28 Oct 2022 17:42:18 +0200 Subject: [PATCH 5/6] avoiding to use tx_lev since it was breaking prachsim (also some formatting) --- openair1/PHY/NR_TRANSPORT/nr_prach.c | 35 +++++++++++----------- openair1/SCHED_NR/nr_prach_procedures.c | 26 +++------------- openair1/SIMULATION/NR_PHY/prachsim.c | 40 ++++++++++++------------- 3 files changed, 41 insertions(+), 60 deletions(-) diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach.c b/openair1/PHY/NR_TRANSPORT/nr_prach.c index eb012532ce..b3d492d025 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_TRANSPORT/nr_prach.c @@ -413,14 +413,13 @@ void rx_nr_prach_ru(RU_t *ru, } void rx_nr_prach(PHY_VARS_gNB *gNB, - nfapi_nr_prach_pdu_t *prach_pdu, - int prachOccasion, - int frame, - int subframe, - uint16_t *max_preamble, - uint16_t *max_preamble_energy, - uint16_t *max_preamble_delay - ) + nfapi_nr_prach_pdu_t *prach_pdu, + int prachOccasion, + int frame, + int slot, + uint16_t *max_preamble, + uint16_t *max_preamble_energy, + uint16_t *max_preamble_delay) { AssertFatal(gNB!=NULL,"Can only be called from gNB\n"); @@ -481,7 +480,7 @@ void rx_nr_prach(PHY_VARS_gNB *gNB, prach_ifft = gNB->prach_vars.prach_ifft; prachF = gNB->prach_vars.prachF; if (LOG_DEBUGFLAG(PRACH)){ - if ((frame&1023) < 20) LOG_D(PHY,"PRACH (gNB) : running rx_prach for subframe %d, msg1_frequencystart %d, rootSequenceIndex %d\n", subframe,msg1_frequencystart,rootSequenceIndex); + if ((frame&1023) < 20) LOG_D(PHY,"PRACH (gNB) : running rx_prach for slot %d, msg1_frequencystart %d, rootSequenceIndex %d\n", slot, msg1_frequencystart, rootSequenceIndex); } start_meas(&gNB->rx_prach); @@ -506,7 +505,7 @@ void rx_nr_prach(PHY_VARS_gNB *gNB, if (LOG_DEBUGFLAG(PRACH)){ int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],(N_ZC==839) ? 840: 140)); - if (en>60) LOG_D(PHY,"frame %d, subframe %d : Trying preamble %d \n",frame,subframe,preamble_index); + if (en>60) LOG_D(PHY,"frame %d, slot %d : Trying preamble %d \n",frame,slot,preamble_index); } if (restricted_set == 0) { // This is the relative offset in the root sequence table (5.7.2-4 from 36.211) for the given preamble index @@ -585,8 +584,8 @@ void rx_nr_prach(PHY_VARS_gNB *gNB, // Compute DFT of RX signal (conjugate input, results in conjugate output) for each new rootSequenceIndex if (LOG_DEBUGFLAG(PRACH)) { int en = dB_fixed(signal_energy((int32_t*)&rxsigF[0][0],840)); - if (en>60) LOG_I(PHY,"frame %d, subframe %d : preamble index %d, NCS %d, N_ZC/NCS %d: offset %d, preamble shift %d , en %d)\n", - frame,subframe,preamble_index,NCS,N_ZC/NCS,preamble_offset,preamble_shift,en); + if (en>60) LOG_D(PHY,"frame %d, slot %d : preamble index %d, NCS %d, N_ZC/NCS %d: offset %d, preamble shift %d , en %d)\n", + frame,slot,preamble_index,NCS,N_ZC/NCS,preamble_offset,preamble_shift,en); } LOG_D(PHY,"PRACH RX preamble_index %d, preamble_offset %d\n",preamble_index,preamble_offset); @@ -605,8 +604,8 @@ void rx_nr_prach(PHY_VARS_gNB *gNB, memset(prachF, 0, sizeof(int16_t)*2*1024 ); if (LOG_DUMPFLAG(PRACH)) { - LOG_M("prach_rxF0.m","prach_rxF0",rxsigF[0],N_ZC,1,1); - LOG_M("prach_rxF1.m","prach_rxF1",rxsigF[1],6144,1,1); + LOG_M("prach_rxF0.m","prach_rxF0",rxsigF[0],N_ZC,1,1); + LOG_M("prach_rxF1.m","prach_rxF1",rxsigF[1],6144,1,1); } for (aa=0;aa*max_preamble_energy) { - LOG_D(PHY,"preamble_index %d, delay %d en %d dB > %d dB\n",preamble_index,i,levdB,*max_preamble_energy); - *max_preamble_energy = levdB; - *max_preamble_delay = i; // Note: This has to be normalized to the 30.72 Ms/s sampling rate - *max_preamble = preamble_index; + LOG_D(PHY,"preamble_index %d, delay %d en %d dB > %d dB\n",preamble_index,i,levdB,*max_preamble_energy); + *max_preamble_energy = levdB; + *max_preamble_delay = i; // Note: This has to be normalized to the 30.72 Ms/s sampling rate + *max_preamble = preamble_index; } } }// preamble_index diff --git a/openair1/SCHED_NR/nr_prach_procedures.c b/openair1/SCHED_NR/nr_prach_procedures.c index b0f59d5f47..2708cbd161 100644 --- a/openair1/SCHED_NR/nr_prach_procedures.c +++ b/openair1/SCHED_NR/nr_prach_procedures.c @@ -121,30 +121,12 @@ void L1_nr_prach_procedures(PHY_VARS_gNB *gNB,int frame,int slot) { ru=gNB->RU_list[0]; int prach_id=find_nr_prach(gNB,frame,slot,SEARCH_EXIST); - + if (prach_id>=0) { nfapi_nr_prach_pdu_t *prach_pdu = &gNB->prach_vars.list[prach_id].pdu; uint8_t prachStartSymbol; uint8_t N_dur = get_nr_prach_duration(prach_pdu->prach_format); - - /* - uint16_t format,RA_sfn_index; - uint8_t start_symbol,N_t_slot,N_dur,N_RA_slot,config_period; - get_nr_prach_info_from_index(gNB->gNB_config.prach_config.prach_ConfigurationIndex.value, - frame,slot, - gNB->gNB_config.carrier_config.dl_frequency.value, - gNB->frame_parms.numerology_index, - gNB->frame_parms.frame_type, - &format, - &start_symbol, - &N_t_slot, - &N_dur, - &RA_sfn_index, - &N_RA_slot, - &config_period); - */ - for(int prach_oc = 0; prach_oc < prach_pdu->num_prach_ocas; prach_oc++) { for (ru_aa=0,aa=0;ru_aanb_rx;ru_aa++,aa++) { gNB->prach_vars.rxsigF[aa] = ru->prach_rxsigF[prach_oc][ru_aa]; @@ -152,7 +134,7 @@ void L1_nr_prach_procedures(PHY_VARS_gNB *gNB,int frame,int slot) { prachStartSymbol = prach_pdu->prach_start_symbol+prach_oc*N_dur; //comment FK: the standard 38.211 section 5.3.2 has one extra term +14*N_RA_slot. This is because there prachStartSymbol is given wrt to start of the 15kHz slot or 60kHz slot. Here we work slot based, so this function is anyway only called in slots where there is PRACH. Its up to the MAC to schedule another PRACH PDU in the case there are there N_RA_slot \in {0,1}. - + rx_nr_prach(gNB, prach_pdu, prach_oc, @@ -160,8 +142,8 @@ void L1_nr_prach_procedures(PHY_VARS_gNB *gNB,int frame,int slot) { slot, &max_preamble[0], &max_preamble_energy[0], - &max_preamble_delay[0] - ); + &max_preamble_delay[0]); + free_nr_prach_entry(gNB,prach_id); LOG_D(PHY,"[RAPROC] Frame %d, slot %d, occasion %d (prachStartSymbol %d) : Most likely preamble %d, energy %d.%d dB delay %d (prach_energy counter %d)\n", frame,slot,prach_oc,prachStartSymbol, diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c index be07f22769..982e5b4136 100644 --- a/openair1/SIMULATION/NR_PHY/prachsim.c +++ b/openair1/SIMULATION/NR_PHY/prachsim.c @@ -766,7 +766,7 @@ int main(int argc, char **argv){ ue_prach_config->num_prach_fd_occasions_list[fd_occasion].prach_root_sequence_index, UE->X_u); - tx_lev = generate_nr_prach(UE, 0, frame, slot); + generate_nr_prach(UE, 0, frame, slot); /* tx_lev_dB not used later, no need to set */ //tx_lev_dB = (unsigned int) dB_fixed(tx_lev); @@ -832,31 +832,31 @@ int main(int argc, char **argv){ for (trial=0; trialsamples_per_frame, 0); - } + if (awgn_flag == 0) { + multipath_tv_channel(UE2gNB, s_re, s_im, r_re, r_im, frame_parms->samples_per_frame, 0); + } - if (n_frames==1) { - printf("rx_level data symbol %f, tx_lev %f\n", - 10*log10(signal_energy_fp(r_re,r_im,1,OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0)), - 10*log10(tx_lev)); - } + if (n_frames==1) { + printf("rx_level data symbol %f, tx_lev %f\n", + 10*log10(signal_energy_fp(r_re,r_im,1,OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0)), + 10*log10(tx_lev)); + } - for (i = 0; i< frame_parms->samples_per_subframe; i++) { - for (aa = 0; aa < frame_parms->nb_antennas_rx; aa++) { - ((short*) &ru->common.rxdata[aa][rx_prach_start])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) &ru->common.rxdata[aa][rx_prach_start])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + for (i = 0; i< frame_parms->samples_per_subframe; i++) { + for (aa = 0; aa < frame_parms->nb_antennas_rx; aa++) { + ((short*) &ru->common.rxdata[aa][rx_prach_start])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short*) &ru->common.rxdata[aa][rx_prach_start])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + } } - } } else { n_bytes = fread(&ru->common.rxdata[0][rx_prach_start],sizeof(int32_t),frame_parms->samples_per_subframe,input_fd); printf("fread %d bytes from file %s\n",n_bytes,input_file); From 4e80dc4a20251c55242cef74788a440477765469 Mon Sep 17 00:00:00 2001 From: francescomani Date: Thu, 3 Nov 2022 17:56:20 +0100 Subject: [PATCH 6/6] move PL comutation at MAC --- .../nfapi/public_inc/fapi_nr_ue_interface.h | 1 - openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h | 2 - .../PHY/NR_UE_ESTIMATION/nr_ue_measurements.c | 25 ----------- openair1/PHY/defs_nr_UE.h | 3 -- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 2 - openair1/SCHED_NR_UE/pucch_uci_ue_nr.c | 6 +-- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 2 - openair2/LAYER2/NR_MAC_UE/mac_proto.h | 3 ++ openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 4 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 44 ++++++++++++++++--- openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c | 9 ++-- 11 files changed, 47 insertions(+), 54 deletions(-) diff --git a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h index fe12b5c1e3..0ec3e636ee 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/fapi_nr_ue_interface.h @@ -119,7 +119,6 @@ typedef struct { uint16_t cell_id; uint16_t ssb_start_subcarrier; short rsrp_dBm; - int16_t pathloss; } fapi_nr_ssb_pdu_t; typedef struct { diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h index 697c70bb21..9725547b6f 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h @@ -122,8 +122,6 @@ void phy_adjust_gain_nr(PHY_VARS_NR_UE *ue, uint32_t rx_power_fil_dB, uint8_t gNB_id); -void compute_nr_PL(PHY_VARS_NR_UE *ue, int ssb_index); - void nr_pdsch_ptrs_processing(PHY_VARS_NR_UE *ue, NR_UE_PDSCH **pdsch_vars, NR_DL_FRAME_PARMS *frame_parms, diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c index 518a083ac2..8d9f6c7600 100644 --- a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c +++ b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c @@ -46,31 +46,6 @@ //#define DEBUG_MEAS_UE //#define DEBUG_RANK_EST -// Returns the pathloss in dB for the active UL BWP on the selected carrier based on the DL RS associated with the PRACH transmission -// computation according to clause 7.4 (Physical random access channel) of 3GPP TS 38.213 version 16.3.0 Release 16 -// Assumptions: -// - PRACH transmission from a UE is not in response to a detection of a PDCCH order by the UE -// Measurement units: -// - referenceSignalPower: dBm/RE (average EPRE of the resources elements that carry secondary synchronization signals in dBm) -void compute_nr_PL(PHY_VARS_NR_UE *ue, int ssb_index){ - - //TODO improve PL measurements. Probably not correct as it is. - - long referenceSignalPower = ue->nrUE_config.ssb_config.ss_pbch_power; - int16_t pathloss = (int16_t)(referenceSignalPower - ue->measurements.ssb_rsrp_dBm[ssb_index]); - - LOG_D(PHY, "In %s: pathloss %d dB, UE RX total gain %d dB, referenceSignalPower %ld dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", - __FUNCTION__, - pathloss, - ue->rx_total_gain_dB, - referenceSignalPower, - pow(10, referenceSignalPower/10), - ue->measurements.ssb_rsrp_dBm[ssb_index], - pow(10, ue->measurements.ssb_rsrp_dBm[ssb_index]/10)); - - ue->measurements.pathloss = pathloss; -} - uint32_t get_nr_rx_total_gain_dB (module_id_t Mod_id,uint8_t CC_id) { diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 35dc8f2cdb..f7cd57190c 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -147,8 +147,6 @@ typedef struct { //! total estimated noise power (dBm) short n0_power_tot_dBm; - int16_t pathloss; - // UE measurements //! estimated received spatial signal power (linear) int rx_spatial_power[NUMBER_OF_CONNECTED_gNB_MAX][2][2]; @@ -596,7 +594,6 @@ typedef struct { // when off, defaults to frequency domain interpolation int chest_freq; int chest_time; - int generate_ul_signal[NUMBER_OF_CONNECTED_gNB_MAX]; UE_NR_SCAN_INFO_t scan_info[NB_BANDS_MAX]; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 58a893a543..3f8fa0d96d 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -173,7 +173,6 @@ void nr_fill_rx_indication(fapi_nr_rx_indication_t *rx_ind, rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.cell_id = frame_parms->Nid_cell; rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.ssb_start_subcarrier = frame_parms->ssb_start_subcarrier; rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.rsrp_dBm = ue->measurements.ssb_rsrp_dBm[frame_parms->ssb_index]; - rx_ind->rx_indication_body[n_pdus - 1].ssb_pdu.pathloss = ue->measurements.pathloss; break; case FAPI_NR_CSIRS_IND: memcpy(&rx_ind->rx_indication_body[n_pdus - 1].csirs_measurements, @@ -1100,7 +1099,6 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, LOG_D(PHY," ------ Decode MIB: frame.slot %d.%d ------ \n", frame_rx%1024, nr_slot_rx); nr_ue_pbch_procedures(gNB_id, ue, proc, estimateSz, dl_ch_estimates, phy_pdcch_config); - compute_nr_PL(ue, ssb_index); if (ue->no_timing_correction==0) { LOG_D(PHY,"start adjust sync slot = %d no timing %d\n", nr_slot_rx, ue->no_timing_correction); diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c index 6ed543daa1..4f45250016 100644 --- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c +++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c @@ -213,12 +213,8 @@ void pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, pucch_pdu = &pucch_vars->pucch_pdu[i]; uint16_t nb_of_prbs = pucch_pdu->prb_size; /* Generate PUCCH signal according to its format and parameters */ - ue->generate_ul_signal[gNB_id] = 1; - int16_t PL = ue->measurements.pathloss; /* LTE function because NR path loss not yet implemented FFS TODO NR */ - int contributor = (10 * log10((double)(pow(2,(ue->frame_parms.numerology_index)) * nb_of_prbs))); - - int16_t pucch_tx_power = pucch_pdu->pucch_tx_power + contributor + PL; + int16_t pucch_tx_power = pucch_pdu->pucch_tx_power; if (pucch_tx_power > ue->tx_power_max_dBm) pucch_tx_power = ue->tx_power_max_dBm; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 4bf062dca9..e5fe2e377f 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -370,8 +370,6 @@ typedef struct { uint32_t ssb_index; /// SSB RSRP in dBm short ssb_rsrp_dBm; - /// SSB pathloss - int16_t pathloss; } NR_PHY_meas_t; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index eece1a84ff..97deda6d81 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -309,6 +309,7 @@ void select_pucch_resource(NR_UE_MAC_INST_t *mac, PUCCH_sched_t *pucch); int16_t get_pucch_tx_power_ue(NR_UE_MAC_INST_t *mac, + int scs, NR_PUCCH_Config_t *pucch_Config, PUCCH_sched_t *pucch, uint8_t format_type, @@ -462,6 +463,8 @@ fapi_nr_ul_config_request_t *get_ul_config_request(NR_UE_MAC_INST_t *mac, int sl void fill_ul_config(fapi_nr_ul_config_request_t *ul_config, frame_t frame_tx, int slot_tx, uint8_t pdu_type); +int16_t compute_nr_SSB_PL(NR_UE_MAC_INST_t *mac, short ssb_rsrp_dBm); + // PUSCH scheduler: // - Calculate the slot in which ULSCH should be scheduled. This is current slot + K2, // - where K2 is the offset between the slot in which UL DCI is received and the slot diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index bfcc5fa2eb..84d917e366 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -125,7 +125,7 @@ int16_t get_prach_tx_power(module_id_t mod_id) { NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); RA_config_t *ra = &mac->ra; - int16_t pathloss = mac->phy_measurements.pathloss; + int16_t pathloss = compute_nr_SSB_PL(mac, mac->phy_measurements.ssb_rsrp_dBm); int16_t ra_preamble_rx_power = (int16_t)(ra->prach_resources.ra_PREAMBLE_RECEIVED_TARGET_POWER - pathloss + 30); return min(nr_get_Pcmax(mod_id), ra_preamble_rx_power); @@ -678,7 +678,7 @@ void nr_get_prach_resources(module_id_t mod_id, } else { /* TODO: This controls the tx_power of UE and the ramping procedure of RA of UE. Later we can abstract this, perhaps in the proxy. But for the time being lets leave it as below. */ - int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? mac->phy_measurements.pathloss : 0; + int16_t dl_pathloss = !get_softmodem_params()->emulate_l1 ? compute_nr_SSB_PL(mac, mac->phy_measurements.ssb_rsrp_dBm) : 0; ssb_rach_config(ra, prach_resources, nr_rach_ConfigCommon, prach_pdu); ra_preambles_config(prach_resources, mac, dl_pathloss); LOG_D(MAC, "[RAPROC] - Selected RA preamble index %d for contention-based random access procedure... \n", ra->ra_PreambleIndex); diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 7559bdea81..f5d694d98f 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -1746,16 +1746,17 @@ void nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, } pucch_pdu->pucch_tx_power = get_pucch_tx_power_ue(mac, + scs, pucch_Config, pucch, pucch_pdu->format_type, pucch_pdu->prb_size, pucch_pdu->freq_hop_flag, pucch_pdu->add_dmrs_flag, - pucch_pdu->nr_of_symbols, - subframe_number, - O_ACK, O_SR, - O_CSI, O_CRC); + pucch_pdu->nr_of_symbols, + subframe_number, + O_ACK, O_SR, + O_CSI, O_CRC); } else AssertFatal(1==0,"problem with pucch configuration\n"); @@ -1795,6 +1796,7 @@ void nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac, int16_t get_pucch_tx_power_ue(NR_UE_MAC_INST_t *mac, + int scs, NR_PUCCH_Config_t *pucch_Config, PUCCH_sched_t *pucch, uint8_t format_type, @@ -1901,10 +1903,13 @@ int16_t get_pucch_tx_power_ue(NR_UE_MAC_INST_t *mac, return (PUCCH_POWER_DEFAULT); } - int16_t pucch_power = P_O_PUCCH + delta_F_PUCCH + DELTA_TF + G_b_f_c; + int16_t pathloss = compute_nr_SSB_PL(mac, mac->phy_measurements.ssb_rsrp_dBm); + int M_pucch_component = (10 * log10((double)(pow(2,scs) * nb_of_prbs))); + + int16_t pucch_power = P_O_PUCCH + M_pucch_component + pathloss + delta_F_PUCCH + DELTA_TF + G_b_f_c; NR_TST_PHY_PRINTF("PUCCH ( Tx power : %d dBm ) ( 10Log(...) : %d ) ( from Path Loss : %d ) ( delta_F_PUCCH : %d ) ( DELTA_TF : %d ) ( G_b_f_c : %d ) \n", - pucch_power, contributor, PL, delta_F_PUCCH, DELTA_TF, G_b_f_c); + pucch_power, M_pucch_component, pathloss, delta_F_PUCCH, DELTA_TF, G_b_f_c); return (pucch_power); } @@ -4225,5 +4230,32 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t } return ret; +} +// Returns the pathloss in dB for the active UL BWP on the selected carrier based on the DL RS associated with the PRACH transmission +// computation according to clause 7.4 (Physical random access channel) of 3GPP TS 38.213 version 16.3.0 Release 16 +// Assumptions: +// - PRACH transmission from a UE is not in response to a detection of a PDCCH order by the UE +// Measurement units: +// - referenceSignalPower: dBm/RE (average EPRE of the resources elements that carry secondary synchronization signals in dBm) +int16_t compute_nr_SSB_PL(NR_UE_MAC_INST_t *mac, short ssb_rsrp_dBm) +{ + + long referenceSignalPower; + //TODO improve PL measurements. Probably not correct as it is. + if (mac->scc) + referenceSignalPower = mac->scc->ss_PBCH_BlockPower; + else + referenceSignalPower = mac->scc_SIB->ss_PBCH_BlockPower; + + int16_t pathloss = (int16_t)(referenceSignalPower - ssb_rsrp_dBm); + + LOG_D(NR_MAC, "pathloss %d dB, referenceSignalPower %ld dBm/RE (%f mW), RSRP %d dBm (%f mW)\n", + pathloss, + referenceSignalPower, + pow(10, referenceSignalPower/10), + ssb_rsrp_dBm, + pow(10, ssb_rsrp_dBm/10)); + + return pathloss; } diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 623567354d..156f286911 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -1085,12 +1085,10 @@ int handle_dci(module_id_t module_id, int cc_id, unsigned int gNB_index, frame_t } -void handle_ssb_meas(NR_UE_MAC_INST_t *mac, uint8_t ssb_index, int16_t rsrp_dbm, int16_t pathloss) { - +void handle_ssb_meas(NR_UE_MAC_INST_t *mac, uint8_t ssb_index, int16_t rsrp_dbm) +{ mac->phy_measurements.ssb_index = ssb_index; mac->phy_measurements.ssb_rsrp_dBm = rsrp_dbm; - mac->phy_measurements.pathloss = pathloss; - } // L2 Abstraction Layer @@ -1235,8 +1233,7 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_ case FAPI_NR_RX_PDU_TYPE_SSB: handle_ssb_meas(mac, (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.ssb_index, - (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.rsrp_dBm, - (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.pathloss); + (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.rsrp_dBm); ret_mask |= (handle_bcch_bch(dl_info->module_id, dl_info->cc_id, dl_info->gNB_index, dl_info->phy_data, (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.pdu, (dl_info->rx_ind->rx_indication_body+i)->ssb_pdu.additional_bits,