nr_l1_helpers.c 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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
cig's avatar
cig committed
23
* \brief PHY/MAC helper functions
24 25
* \author Guido Casati
* \date 2019
26
* \version 2.0
27 28 29 30 31 32 33 34 35
* \email guido.casati@iis.fraunhofer.de
* @ingroup _mac

*/

#include "PHY/defs_nr_common.h"

#include "mac_defs.h"
#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
cig's avatar
cig committed
36
#include "LAYER2/NR_MAC_UE/mac_proto.h"
37

cig's avatar
cig committed
38
/* TS 38.321 subclause 7.3 - return DELTA_PREAMBLE values in dB */
cig's avatar
cig committed
39
int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format){
40

41 42 43 44 45 46
  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;
  NR_SubcarrierSpacing_t scs = *nr_rach_ConfigCommon->msg1_SubcarrierSpacing;
  int prach_sequence_length = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present - 1;
  uint8_t prachConfigIndex, mu;
47

48
  AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n");
49

50
  // SCS configuration from msg1_SubcarrierSpacing and table 4.2-1 in TS 38.211
51

52 53 54 55
  switch (scs){
    case NR_SubcarrierSpacing_kHz15:
    mu = 0;
    break;
cig's avatar
cig committed
56

57 58 59
    case NR_SubcarrierSpacing_kHz30:
    mu = 1;
    break;
cig's avatar
cig committed
60

61 62 63
    case NR_SubcarrierSpacing_kHz60:
    mu = 2;
    break;
64

65 66 67
    case NR_SubcarrierSpacing_kHz120:
    mu = 3;
    break;
68

69 70 71
    case NR_SubcarrierSpacing_kHz240:
    mu = 4;
    break;
72

73 74 75
    case NR_SubcarrierSpacing_spare3:
    mu = 5;
    break;
76

77 78 79
    case NR_SubcarrierSpacing_spare2:
    mu = 6;
    break;
80

81 82 83
    case NR_SubcarrierSpacing_spare1:
    mu = 7;
    break;
84

85 86 87
    default:
    AssertFatal(1 == 0,"Unknown msg1_SubcarrierSpacing %lu\n", scs);
  }
88

89
  // Preamble formats given by prach_ConfigurationIndex and tables 6.3.3.2-2 and 6.3.3.2-2 in TS 38.211
90

91
  prachConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex;
92

93
  if (prach_sequence_length == 0) {
laurent's avatar
laurent committed
94
    AssertFatal(prach_format < 4, "Illegal PRACH format %d for sequence length 839\n", prach_format);
cig's avatar
cig committed
95
    switch (prach_format) {
96

97 98 99 100 101 102 103 104 105 106
      // long preamble formats
      case 0:
      case 3:
      return  0;

      case 1:           
      return -3;

      case 2:
      return -6;
107 108 109 110 111
    }
  } else {
    switch (prach_format) { // short preamble formats
      case 0:
      case 3:
112 113
      return 8 + 3*mu;

114 115 116
      case 1:
      case 4:
      case 8:
117 118
      return 5 + 3*mu;

119 120
      case 2:
      case 5:
121 122
      return 3 + 3*mu;

123
      case 6:
124 125
      return 3*mu;

126
      case 7:
127 128 129
      return 5 + 3*mu;

      default:
cig's avatar
cig committed
130
      AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, prach_format, prachConfigIndex);
131
    }
132
  }
133
  return 0;
134 135
}

cig's avatar
cig committed
136
/* TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration */
cig's avatar
cig committed
137
int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t mod_id, uint8_t CC_id){
138
  
cig's avatar
cig committed
139 140 141 142 143
  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;
144 145 146

  AssertFatal(nr_rach_ConfigCommon != NULL, "[UE %d] CCid %d FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id, CC_id);

cig's avatar
cig committed
147 148 149 150
  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;
151 152

  return receivedTargerPower;
153
}
cig's avatar
cig committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

void get_num_re_dmrs(nfapi_nr_ue_pusch_pdu_t *pusch_pdu,
                     uint8_t *nb_dmrs_re_per_rb,
                     uint16_t *number_dmrs_symbols){

  int start_symbol          = pusch_pdu->start_symbol_index;
  uint8_t number_of_symbols = pusch_pdu->nr_of_symbols;
  uint16_t ul_dmrs_symb_pos = pusch_pdu->ul_dmrs_symb_pos;
  uint8_t dmrs_type         = pusch_pdu->dmrs_config_type;
  uint8_t cdm_grps_no_data  = pusch_pdu->num_dmrs_cdm_grps_no_data;

  *number_dmrs_symbols = 0;
  for (int i = start_symbol; i < start_symbol + number_of_symbols; i++) {
    if((ul_dmrs_symb_pos >> i) & 0x01)
      *number_dmrs_symbols += 1;
  }

  *nb_dmrs_re_per_rb = ((dmrs_type == pusch_dmrs_type1) ? 6:4)*cdm_grps_no_data;

}