diff --git a/openair1/PHY/defs_nr_common.h b/openair1/PHY/defs_nr_common.h index 5241f5736d53a71751752d873c271f9df6cc5749..172e0b20d6f787e005a1d31b8b64e639b3dac30c 100644 --- a/openair1/PHY/defs_nr_common.h +++ b/openair1/PHY/defs_nr_common.h @@ -224,12 +224,14 @@ typedef struct { } NR_PRACH_CONFIG_COMMON; typedef struct { + /// PRACH format retrieved from prach_ConfigIndex + uint16_t prach_format; /// Preamble index for PRACH (0-63) uint8_t ra_PreambleIndex; /// RACH MaskIndex uint8_t ra_RACH_MaskIndex; - /// Target received power at eNB (-120 ... -82 dBm) - uint32_t ra_PREAMBLE_RECEIVED_TARGET_POWER; + /// 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 diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index d0b64c1da6b5c094806dd1feb7865cc4d19c4c71..5f70cd86b87c6a31dd4de2fec52d926bc8bf90bd 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -117,8 +117,6 @@ typedef struct { /* Random Access parameters */ /// state of RA procedure RA_state_t ra_state; - /// RACH ConfigCommon - NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon; /// RA-rnti uint16_t ra_rnti; /// Temporary CRNTI diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 580e3c438d225bb2ee3208b9958ae4493c8b9afe..afb161b33742d23567ccd9ad169bebebe771eb5f 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -185,17 +185,26 @@ int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg, int mu, @param Mod_id Module id of UE @returns Po_NOMINAL_PUSCH (PREAMBLE_RECEIVED_TARGET_POWER+DELTA_PREAMBLE */ -int8_t nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t module_idP, uint8_t CC_id); +int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t module_idP, uint8_t CC_id); /** \brief Function to compute DELTA_PREAMBLE from 38.321 subclause 7.3 (for RA power ramping procedure and Msg3 PUSCH power control policy) @param Mod_id Module id of UE @returns DELTA_PREAMBLE */ -int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id); +int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format); /* Random Access */ +/* \brief This function schedules the PRACH according to prach_ConfigurationIndex and TS 38.211 tables 6.3.3.2.x +and fills the PRACH PDU per each FD occasion. +@param module_idP Index of UE instance +@param frameP Frame index +@param slotP Slot index +@returns void +*/ +void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t slotP); + /* \brief Function called by PHY to process the received RAR and check that the preamble matches what was sent by the gNB. It provides the timing advance and t-CRNTI. @param Mod_id Index of UE instance @param CC_id Index to a component carrier diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c index e61e58c7647ba087bd2cfc42d9ecdf09f2ee0a91..ab15935f16b6c770cf64afeb5fad183cd8103597 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c @@ -35,21 +35,16 @@ #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" #include "LAYER2/NR_MAC_UE/mac_proto.h" -// WIP todo: -//- frame_type and fr are hardcoded. Retireve from fp - /* TS 38.321 subclause 7.3 - return DELTA_PREAMBLE values in dB */ -int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){ +int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format){ - NR_UE_MAC_INST_t *nrUE_mac_inst = get_mac_inst(mod_id); - NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = nrUE_mac_inst->nr_rach_ConfigCommon; + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + NR_ServingCellConfigCommon_t *scc = mac->scc; + NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n"); - uint8_t preambleFormat, prachConfigIndex; - lte_frame_type_t frame_type = TDD; - nr_frequency_range_e fr = nr_FR1; - int mu; + uint8_t prachConfigIndex, mu; // SCS configuration from msg1_SubcarrierSpacing and table 4.2-1 in TS 38.211 @@ -95,9 +90,8 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){ // Preamble formats given by prach_ConfigurationIndex and tables 6.3.3.2-2 and 6.3.3.2-2 in TS 38.211 prachConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex; - preambleFormat = get_nr_prach_fmt(prachConfigIndex,frame_type,fr); - switch (preambleFormat) { + switch (prach_format) { // long preamble formats case 0: case 3: @@ -130,19 +124,25 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id){ return 5 + 3*mu; default: - AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, preambleFormat, prachConfigIndex); + AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, prach_format, prachConfigIndex); } } /* TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration */ -int8_t nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t mod_id, uint8_t CC_id){ +int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t mod_id, uint8_t CC_id){ - NR_UE_MAC_INST_t *nr_UE_mac_inst = get_mac_inst(mod_id); - NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = nr_UE_mac_inst->nr_rach_ConfigCommon; + NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + NR_ServingCellConfigCommon_t *scc = mac->scc; + NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; + int8_t receivedTargerPower, delta_preamble; + long preambleReceivedTargetPower; AssertFatal(nr_rach_ConfigCommon != NULL, "[UE %d] CCid %d FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id, CC_id); - int8_t receivedTargerPower = nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower + nr_get_DELTA_PREAMBLE(mod_id, CC_id) + (nr_UE_mac_inst->RA_PREAMBLE_POWER_RAMPING_COUNTER - 1) * prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP; + preambleReceivedTargetPower = nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower; + delta_preamble = nr_get_DELTA_PREAMBLE(mod_id, CC_id, prach_resources->prach_format); + + receivedTargerPower = preambleReceivedTargetPower + delta_preamble + (mac->RA_PREAMBLE_POWER_RAMPING_COUNTER - 1) * prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP; return receivedTargerPower; } \ No newline at end of file diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index f928aeb57281b02b35dca19877fc52c9e991b959..138d37d3940f93de008257a1432584635741e6ec 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -79,11 +79,14 @@ void nr_get_prach_resources(module_id_t mod_id, NR_RACH_ConfigDedicated_t * rach_ConfigDedicated){ NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); + NR_ServingCellConfigCommon_t *scc = mac->scc; NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon; + NR_RACH_ConfigGeneric_t *rach_ConfigGeneric; + // NR_BeamFailureRecoveryConfig_t *beam_failure_recovery_config = &mac->RA_BeamFailureRecoveryConfig; // todo int messagePowerOffsetGroupB, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3; - uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, msg1_FDM, prach_ConfigIndex, SFN_nbr, Msg3_size; + uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, prach_ConfigIndex, SFN_nbr, Msg3_size; // NR_RSRP_Range_t rsrp_ThresholdSSB; // todo @@ -116,9 +119,10 @@ void nr_get_prach_resources(module_id_t mod_id, // rsrp_ThresholdSSB = *nr_rach_ConfigCommon->rsrp_ThresholdSSB; - AssertFatal(mac->nr_rach_ConfigCommon != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); + AssertFatal(scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); - nr_rach_ConfigCommon = mac->nr_rach_ConfigCommon; + nr_rach_ConfigCommon = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; + rach_ConfigGeneric = &nr_rach_ConfigCommon->rach_ConfigGeneric; Msg3_size = mac->RA_Msg3_size; numberOfRA_Preambles = *nr_rach_ConfigCommon->totalNumberOfRA_Preambles; @@ -202,7 +206,7 @@ void nr_get_prach_resources(module_id_t mod_id, deltaPreamble_Msg3 = mac->deltaPreamble_Msg3; } - PLThreshold = prach_resources->RA_PCMAX - nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower - deltaPreamble_Msg3 - messagePowerOffsetGroupB; + PLThreshold = prach_resources->RA_PCMAX - rach_ConfigGeneric->preambleReceivedTargetPower - deltaPreamble_Msg3 - messagePowerOffsetGroupB; /* Msg3 has not been transmitted yet */ if (first_Msg3 == 1) { @@ -254,24 +258,7 @@ void nr_get_prach_resources(module_id_t mod_id, // 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; + prach_ConfigIndex = rach_ConfigGeneric->prach_ConfigurationIndex; // ra_RNTI computation // - todo: this is for TDD FR1 only @@ -281,7 +268,7 @@ void nr_get_prach_resources(module_id_t mod_id, // - 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; + f_id = 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]; @@ -348,7 +335,9 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, *mac_sdus, *payload, ra_ResponseWindow; uint16_t size_sdu = 0; unsigned short post_padding; - NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (NR_RACH_ConfigCommon_t *) NULL; + NR_ServingCellConfigCommon_t *scc = mac->scc; + NR_RACH_ConfigCommon_t *setup = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; + NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric; // int32_t frame_diff = 0; uint8_t sdu_lcids[NB_RB_MAX] = {0}; @@ -361,11 +350,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, LOG_D(MAC, "nr_ue_get_rach, RA_active value: %d", mac->RA_active); - AssertFatal(mac->nr_rach_ConfigCommon != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); - - if (mac->nr_rach_ConfigCommon != NULL) { - nr_rach_ConfigCommon = mac->nr_rach_ConfigCommon; - } else prach_resources = NULL; + AssertFatal(setup != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); if (mac->RA_active == 0) { /* RA not active - checking if RRC is ready to initiate the RA procedure */ @@ -375,7 +360,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, mac->RA_RAPID_found = 0; /* Set RA_PREAMBLE_POWER_RAMPING_STEP */ - switch (nr_rach_ConfigCommon->rach_ConfigGeneric.powerRampingStep){ // in dB + switch (rach_ConfigGeneric->powerRampingStep){ // in dB case 0: prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP = 0; break; @@ -444,7 +429,7 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, mac->RA_active = 1; prach_resources->Msg3 = payload; - ra_ResponseWindow = nr_rach_ConfigCommon->rach_ConfigGeneric.ra_ResponseWindow; + ra_ResponseWindow = rach_ConfigGeneric->ra_ResponseWindow; switch (ra_ResponseWindow) { case 0: mac->RA_window_cnt = 1; @@ -528,38 +513,38 @@ void nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, mac->RA_PREAMBLE_TRANSMISSION_COUNTER++; preambleTransMax = -1; - switch (nr_rach_ConfigCommon->rach_ConfigGeneric.preambleTransMax) { - case NR_RACH_ConfigGeneric__preambleTransMax_n3: + switch (rach_ConfigGeneric->preambleTransMax) { + case 0: preambleTransMax = 3; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n4: + case 1: preambleTransMax = 4; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n5: + case 2: preambleTransMax = 5; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n6: + case 3: preambleTransMax = 6; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n7: + case 4: preambleTransMax = 7; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n8: + case 5: preambleTransMax = 8; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n10: + case 6: preambleTransMax = 10; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n20: + case 7: preambleTransMax = 20; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n50: + case 8: preambleTransMax = 50; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n100: + case 9: preambleTransMax = 100; break; - case NR_RACH_ConfigGeneric__preambleTransMax_n200: + case 10: preambleTransMax = 200; break; }