nr_parms.c 8.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

22
#include "phy_init.h"
23
#include "common/utils/LOG/log.h"
24

25 26
/// Subcarrier spacings in Hz indexed by numerology index
uint32_t nr_subcarrier_spacing[MAX_NUM_SUBCARRIER_SPACING] = {15e3, 30e3, 60e3, 120e3, 240e3};
27
uint16_t nr_slots_per_subframe[MAX_NUM_SUBCARRIER_SPACING] = {1, 2, 4, 16, 32};
28

knopp's avatar
knopp committed
29

30
int nr_init_frame_parms0(NR_DL_FRAME_PARMS *fp,
knopp's avatar
knopp committed
31
			 int mu,
32 33
			 int Ncp,
			 int N_RB_DL)
knopp's avatar
knopp committed
34

35 36
{

hongzhi wang's avatar
hongzhi wang committed
37
#if DISABLE_LOG_X
38
  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB_DL, Ncp);
hongzhi wang's avatar
hongzhi wang committed
39
#else
40
  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB_DL, Ncp);
hongzhi wang's avatar
hongzhi wang committed
41 42
#endif

Guy De Souza's avatar
Guy De Souza committed
43
  if (Ncp == NFAPI_CP_EXTENDED)
hongzhi wang's avatar
hongzhi wang committed
44 45
    AssertFatal(mu == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, mu);

46 47 48
  fp->numerology_index = mu;
  fp->Ncp = Ncp;
  fp->N_RB_DL = N_RB_DL;
49

hongzhi wang's avatar
hongzhi wang committed
50 51 52
  switch(mu) {

    case NR_MU_0: //15kHz scs
knopp's avatar
knopp committed
53 54
      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
55
      fp->ssb_type = nr_ssb_type_A;
hongzhi wang's avatar
hongzhi wang committed
56 57 58
      break;

    case NR_MU_1: //30kHz scs
knopp's avatar
knopp committed
59 60
      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];
hongzhi wang's avatar
hongzhi wang committed
61

62 63 64 65 66 67 68 69 70 71
      // selection of SS block pattern according to TS 38101-1 Table 5.4.3.3-1 for SCS 30kHz
      if (fp->eutra_band == 5 || fp->eutra_band == 66) 
	      fp->ssb_type = nr_ssb_type_B;
      else{  
      	if (fp->eutra_band == 41 || ( fp->eutra_band > 76 && fp->eutra_band < 80) )
		fp->ssb_type = nr_ssb_type_C;
	else
		AssertFatal(1==0,"NR Operating Band n%d not available for SS block SCS with mu=%d\n", fp->eutra_band, mu);
      }

72
      switch(N_RB_DL){
hongzhi wang's avatar
hongzhi wang committed
73 74 75 76 77 78 79 80
        case 11:
        case 24:
        case 38:
        case 78:
        case 51:
        case 65:

        case 106: //40 MHz
knopp's avatar
knopp committed
81 82 83 84 85
          if (fp->threequarter_fs) {
            fp->ofdm_symbol_size = 1536;
            fp->first_carrier_offset = 900; //1536 - 636
            fp->nb_prefix_samples0 = 132;
            fp->nb_prefix_samples = 108;
hongzhi wang's avatar
hongzhi wang committed
86 87
          }
          else {
knopp's avatar
knopp committed
88 89 90 91
            fp->ofdm_symbol_size = 2048;
            fp->first_carrier_offset = 1412; //2048 - 636
            fp->nb_prefix_samples0 = 176;
            fp->nb_prefix_samples = 144;
hongzhi wang's avatar
hongzhi wang committed
92 93 94 95 96 97 98 99
          }
          break;

        case 133:
        case 162:
        case 189:

        case 217: //80 MHz
knopp's avatar
knopp committed
100 101 102 103 104
          if (fp->threequarter_fs) {
            fp->ofdm_symbol_size = 3072;
            fp->first_carrier_offset = 1770; //3072 - 1302
            fp->nb_prefix_samples0 = 264;
            fp->nb_prefix_samples = 216;
hongzhi wang's avatar
hongzhi wang committed
105
          }
knopp's avatar
knopp committed
106
	  else {
knopp's avatar
knopp committed
107 108 109 110
	    fp->ofdm_symbol_size = 4096;
	    fp->first_carrier_offset = 2794; //4096 - 1302
	    fp->nb_prefix_samples0 = 352;
	    fp->nb_prefix_samples = 288;
knopp's avatar
knopp committed
111
	  }
hongzhi wang's avatar
hongzhi wang committed
112 113 114
          break;

        case 245:
115
	  AssertFatal(fp->threequarter_fs==0,"3/4 sampling impossible for N_RB %d and MU %d\n",N_RB_DL,mu); 
knopp's avatar
knopp committed
116 117 118 119
	  fp->ofdm_symbol_size = 4096;
	  fp->first_carrier_offset = 2626; //4096 - 1478
	  fp->nb_prefix_samples0 = 352;
	  fp->nb_prefix_samples = 288;
knopp's avatar
knopp committed
120
	  break;
hongzhi wang's avatar
hongzhi wang committed
121
        case 273:
122
	  AssertFatal(fp->threequarter_fs==0,"3/4 sampling impossible for N_RB %d and MU %d\n",N_RB_DL,mu); 
knopp's avatar
knopp committed
123 124 125 126
	  fp->ofdm_symbol_size = 4096;
	  fp->first_carrier_offset = 2458; //4096 - 1638
	  fp->nb_prefix_samples0 = 352;
	  fp->nb_prefix_samples = 288;
knopp's avatar
knopp committed
127
	  break;
hongzhi wang's avatar
hongzhi wang committed
128
      default:
129
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB_DL, mu, fp);
hongzhi wang's avatar
hongzhi wang committed
130 131 132 133
      }
      break;

    case NR_MU_2: //60kHz scs
knopp's avatar
knopp committed
134 135
      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];
hongzhi wang's avatar
hongzhi wang committed
136

137
      switch(N_RB_DL){ //FR1 bands only
hongzhi wang's avatar
hongzhi wang committed
138 139 140 141 142 143 144 145 146 147 148 149 150
        case 11:
        case 18:
        case 38:
        case 24:
        case 31:
        case 51:
        case 65:
        case 79:
        case 93:
        case 107:
        case 121:
        case 135:
      default:
151
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB_DL, mu, fp);
hongzhi wang's avatar
hongzhi wang committed
152 153 154 155
      }
      break;

    case NR_MU_3:
knopp's avatar
knopp committed
156 157
      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
158
      fp->ssb_type = nr_ssb_type_D;
hongzhi wang's avatar
hongzhi wang committed
159 160 161
      break;

    case NR_MU_4:
knopp's avatar
knopp committed
162 163
      fp->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
      fp->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
164
      fp->ssb_type = nr_ssb_type_E;
hongzhi wang's avatar
hongzhi wang committed
165 166 167 168 169 170
      break;

  default:
    AssertFatal(1==0,"Invalid numerology index %d", mu);
  }

knopp's avatar
knopp committed
171
  fp->slots_per_frame = 10* fp->slots_per_subframe;
172 173 174

  fp->nb_antenna_ports_eNB = 1; // default value until overwritten by RRCConnectionReconfiguration

knopp's avatar
knopp committed
175 176 177
  fp->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
  fp->samples_per_subframe_wCP = fp->ofdm_symbol_size * fp->symbols_per_slot * fp->slots_per_subframe;
  fp->samples_per_frame_wCP = 10 * fp->samples_per_subframe_wCP;
178 179
  fp->samples_per_slot_wCP = fp->symbols_per_slot*fp->ofdm_symbol_size; 
  fp->samples_per_slot = fp->nb_prefix_samples0 + ((fp->symbols_per_slot-1)*fp->nb_prefix_samples) + (fp->symbols_per_slot*fp->ofdm_symbol_size); 
knopp's avatar
knopp committed
180 181 182 183
  fp->samples_per_subframe = (fp->samples_per_subframe_wCP + (fp->nb_prefix_samples0 * fp->slots_per_subframe) +
                                      (fp->nb_prefix_samples * fp->slots_per_subframe * (fp->symbols_per_slot - 1)));
  fp->samples_per_frame = 10 * fp->samples_per_subframe;
  fp->freq_range = (fp->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
hongzhi wang's avatar
hongzhi wang committed
184

185 186 187 188 189 190 191 192 193 194
  // definition of Lmax according to ts 38.213 section 4.1
  if (fp->dl_CarrierFreq < 6e9){
	if(fp->frame_type && (fp->ssb_type==2))
		fp->Lmax = (fp->dl_CarrierFreq < 2.4e9)? 4 : 8;
	else
		fp->Lmax = (fp->dl_CarrierFreq < 3e9)? 4 : 8;
  }  
  else
    fp->Lmax = 64;

Guy De Souza's avatar
Guy De Souza committed
195
  // Initial bandwidth part configuration -- full carrier bandwidth
knopp's avatar
knopp committed
196 197 198 199
  fp->initial_bwp_dl.bwp_id = 0;
  fp->initial_bwp_dl.scs = fp->subcarrier_spacing;
  fp->initial_bwp_dl.location = 0;
  fp->initial_bwp_dl.N_RB = fp->N_RB_DL;
200
  fp->initial_bwp_dl.cyclic_prefix = fp->Ncp;
knopp's avatar
knopp committed
201
  fp->initial_bwp_dl.ofdm_symbol_size = fp->ofdm_symbol_size;
Guy De Souza's avatar
Guy De Souza committed
202

hongzhi wang's avatar
hongzhi wang committed
203 204 205
  return 0;
}

knopp's avatar
knopp committed
206
int nr_init_frame_parms(nfapi_nr_config_request_t* config,
yilmazt's avatar
yilmazt committed
207 208
                        NR_DL_FRAME_PARMS *fp)
{
209

210 211
  fp->eutra_band = config->nfapi_config.rf_bands.rf_band[0];
  fp->frame_type = !(config->subframe_config.duplex_mode.value);
212
  fp->L_ssb = config->sch_config.ssb_scg_position_in_burst.value;
213
  return nr_init_frame_parms0(fp,
214 215 216
			      config->subframe_config.numerology_index_mu.value,
			      config->subframe_config.dl_cyclic_prefix_type.value,
			      config->rf_config.dl_carrier_bandwidth.value);
knopp's avatar
knopp committed
217
}
hongzhi wang's avatar
hongzhi wang committed
218

knopp's avatar
knopp committed
219
int nr_init_frame_parms_ue(NR_DL_FRAME_PARMS *fp,
knopp's avatar
knopp committed
220
			   int mu, 
knopp's avatar
knopp committed
221
			   int Ncp,
222
			   int N_RB_DL,
knopp's avatar
knopp committed
223 224
			   int n_ssb_crb,
			   int ssb_subcarrier_offset) 
knopp's avatar
knopp committed
225
{
226
  /*n_ssb_crb and ssb_subcarrier_offset are given in 15kHz SCS*/
227
  nr_init_frame_parms0(fp,mu,Ncp,N_RB_DL);
228
  fp->ssb_start_subcarrier = (12 * n_ssb_crb + ssb_subcarrier_offset)/(1<<mu);
229 230 231
  return 0;
}

knopp's avatar
knopp committed
232
void nr_dump_frame_parms(NR_DL_FRAME_PARMS *fp)
233
{
knopp's avatar
knopp committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
  LOG_I(PHY,"fp->scs=%d\n",fp->subcarrier_spacing);
  LOG_I(PHY,"fp->ofdm_symbol_size=%d\n",fp->ofdm_symbol_size);
  LOG_I(PHY,"fp->nb_prefix_samples0=%d\n",fp->nb_prefix_samples0);
  LOG_I(PHY,"fp->nb_prefix_samples=%d\n",fp->nb_prefix_samples);
  LOG_I(PHY,"fp->slots_per_subframe=%d\n",fp->slots_per_subframe);
  LOG_I(PHY,"fp->samples_per_subframe_wCP=%d\n",fp->samples_per_subframe_wCP);
  LOG_I(PHY,"fp->samples_per_frame_wCP=%d\n",fp->samples_per_frame_wCP);
  LOG_I(PHY,"fp->samples_per_subframe=%d\n",fp->samples_per_subframe);
  LOG_I(PHY,"fp->samples_per_frame=%d\n",fp->samples_per_frame);
  LOG_I(PHY,"fp->initial_bwp_dl.bwp_id=%d\n",fp->initial_bwp_dl.bwp_id);
  LOG_I(PHY,"fp->initial_bwp_dl.scs=%d\n",fp->initial_bwp_dl.scs);
  LOG_I(PHY,"fp->initial_bwp_dl.N_RB=%d\n",fp->initial_bwp_dl.N_RB);
  LOG_I(PHY,"fp->initial_bwp_dl.cyclic_prefix=%d\n",fp->initial_bwp_dl.cyclic_prefix);
  LOG_I(PHY,"fp->initial_bwp_dl.location=%d\n",fp->initial_bwp_dl.location);
  LOG_I(PHY,"fp->initial_bwp_dl.ofdm_symbol_size=%d\n",fp->initial_bwp_dl.ofdm_symbol_size);
249
}