nr_parms.c 10.9 KB
Newer Older
Guy De Souza's avatar
Guy De Souza committed
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"
Guy De Souza's avatar
Guy De Souza committed
23
#include "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

ChenWeiTai's avatar
ChenWeiTai committed
29
int nr_init_frame_parms(nfapi_nr_config_request_t* config,
30
                        NR_DL_FRAME_PARMS *frame_parms)
31 32
{

33
  int N_RB = config->rf_config.dl_carrier_bandwidth.value;
ChenWeiTai's avatar
ChenWeiTai committed
34
  int Ncp = config->subframe_config.dl_cyclic_prefix_type.value;
Guy De Souza's avatar
Guy De Souza committed
35
  int mu = config->subframe_config.numerology_index_mu.value;
36

hongzhi wang's avatar
hongzhi wang committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#if DISABLE_LOG_X
  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
#else
  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
#endif

  if (Ncp == EXTENDED)
    AssertFatal(mu == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, mu);

  switch(mu) {

    case NR_MU_0: //15kHz scs
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
      break;

    case NR_MU_1: //30kHz scs
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];

      switch(N_RB){
        case 11:
        case 24:
        case 38:
        case 78:
        case 51:
        case 65:

        case 106: //40 MHz
          if (frame_parms->threequarter_fs) {
            frame_parms->ofdm_symbol_size = 1536;
            frame_parms->first_carrier_offset = 900; //1536 - 636
            frame_parms->nb_prefix_samples0 = 132;
            frame_parms->nb_prefix_samples = 108;
          }
          else {
            frame_parms->ofdm_symbol_size = 2048;
            frame_parms->first_carrier_offset = 1412; //2048 - 636
            frame_parms->nb_prefix_samples0 = 176;
            frame_parms->nb_prefix_samples = 144;
          }
          break;

        case 133:
        case 162:
        case 189:

        case 217: //80 MHz
          if (frame_parms->threequarter_fs) {
            frame_parms->ofdm_symbol_size = 3072;
            frame_parms->first_carrier_offset = 1770; //3072 - 1302
            frame_parms->nb_prefix_samples0 = 264;
            frame_parms->nb_prefix_samples = 216;
          }
          else {
            frame_parms->ofdm_symbol_size = 4096;
            frame_parms->first_carrier_offset = 2794; //4096 - 1302
            frame_parms->nb_prefix_samples0 = 352;
            frame_parms->nb_prefix_samples = 288;
          }
          break;

        case 245:
        case 273:
      default:
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
      }
      break;

    case NR_MU_2: //60kHz scs
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];

      switch(N_RB){ //FR1 bands only
        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:
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
      }
      break;

    case NR_MU_3:
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
      break;

    case NR_MU_4:
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
      break;

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


  frame_parms->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
  frame_parms->samples_per_subframe_wCP = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_slot * frame_parms->slots_per_subframe;
  frame_parms->samples_per_frame_wCP = 10 * frame_parms->samples_per_subframe_wCP;
  frame_parms->samples_per_subframe = (frame_parms->samples_per_subframe_wCP + (frame_parms->nb_prefix_samples0 * frame_parms->slots_per_subframe) +
                                      (frame_parms->nb_prefix_samples * frame_parms->slots_per_subframe * (frame_parms->symbols_per_slot - 1)));
  frame_parms->samples_per_frame = 10 * frame_parms->samples_per_subframe;
Guy De Souza's avatar
Guy De Souza committed
149
  frame_parms->freq_range = (frame_parms->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
hongzhi wang's avatar
hongzhi wang committed
150 151 152 153

  return 0;
}

Guy De Souza's avatar
Guy De Souza committed
154
int nr_init_frame_parms_ue(nfapi_nr_config_request_t* config,
hongzhi wang's avatar
hongzhi wang committed
155 156 157 158 159 160 161
                        NR_DL_FRAME_PARMS *frame_parms)
{

  int N_RB = 106;
  int Ncp = 0;
  int mu = 1;

162
#if DISABLE_LOG_X
163
  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
164
#else
165
  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
166 167
#endif

Wang's avatar
Wang committed
168

Guy De Souza's avatar
Guy De Souza committed
169
  if (Ncp == EXTENDED)
170
    AssertFatal(mu == NR_MU_2,"Invalid cyclic prefix %d for numerology index %d\n", Ncp, mu);
171

172
  switch(mu) {
173 174

    case NR_MU_0: //15kHz scs
175
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
176
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
177 178 179
      break;

    case NR_MU_1: //30kHz scs
180
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_1];
181
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_1];
182

183
      switch(N_RB){
184 185 186 187 188 189 190 191
        case 11:
        case 24:
        case 38:
        case 78:
        case 51:
        case 65:

        case 106: //40 MHz
Guy De Souza's avatar
Guy De Souza committed
192 193 194 195 196 197 198 199 200 201 202 203
          if (frame_parms->threequarter_fs) {
            frame_parms->ofdm_symbol_size = 1536;
            frame_parms->first_carrier_offset = 900; //1536 - 636
            frame_parms->nb_prefix_samples0 = 132;
            frame_parms->nb_prefix_samples = 108;
          }
          else {
            frame_parms->ofdm_symbol_size = 2048;
            frame_parms->first_carrier_offset = 1412; //2048 - 636
            frame_parms->nb_prefix_samples0 = 176;
            frame_parms->nb_prefix_samples = 144;
          }
204 205 206 207 208 209 210
          break;

        case 133:
        case 162:
        case 189:

        case 217: //80 MHz
211 212 213
          if (frame_parms->threequarter_fs) {
            frame_parms->ofdm_symbol_size = 3072;
            frame_parms->first_carrier_offset = 1770; //3072 - 1302
Guy De Souza's avatar
Guy De Souza committed
214
            frame_parms->nb_prefix_samples0 = 264;
215 216 217 218 219
            frame_parms->nb_prefix_samples = 216;
          }
          else {
            frame_parms->ofdm_symbol_size = 4096;
            frame_parms->first_carrier_offset = 2794; //4096 - 1302
Guy De Souza's avatar
Guy De Souza committed
220
            frame_parms->nb_prefix_samples0 = 352;
221 222
            frame_parms->nb_prefix_samples = 288;
          }
223 224 225 226 227
          break;

        case 245:
        case 273:
      default:
228
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
229 230 231 232
      }
      break;

    case NR_MU_2: //60kHz scs
233
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_2];
234
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_2];
235

236
      switch(N_RB){ //FR1 bands only
237 238 239 240 241 242 243 244 245 246 247 248 249
        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:
250
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
251 252 253 254
      }
      break;

    case NR_MU_3:
255
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
256
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
257 258 259
      break;

    case NR_MU_4:
260
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
261
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
262 263 264
      break;

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

hongzhi wang's avatar
hongzhi wang committed
268
    frame_parms->nb_prefix_samples0 = 160;
hongzhi wang's avatar
hongzhi wang committed
269 270 271 272 273 274
    frame_parms->nb_prefix_samples = 144;
    frame_parms->symbols_per_tti = 14;
    frame_parms->numerology_index = 0;
    frame_parms->ttis_per_subframe = 1;
    frame_parms->slots_per_tti = 2; //only slot config 1 is supported     

hongzhi wang's avatar
hongzhi wang committed
275 276 277 278
    frame_parms->ofdm_symbol_size = 2048;
    frame_parms->samples_per_tti = 30720;
    frame_parms->samples_per_subframe = 30720 * frame_parms->ttis_per_subframe;
    frame_parms->first_carrier_offset = 2048-600;
hongzhi wang's avatar
hongzhi wang committed
279

Guy De Souza's avatar
Guy De Souza committed
280
  frame_parms->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
Guy De Souza's avatar
Guy De Souza committed
281
  frame_parms->samples_per_subframe_wCP = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_slot * frame_parms->slots_per_subframe;
282
  frame_parms->samples_per_frame_wCP = 10 * frame_parms->samples_per_subframe_wCP;
hongzhi wang's avatar
hongzhi wang committed
283 284
  //frame_parms->samples_per_subframe = (frame_parms->samples_per_subframe_wCP + (frame_parms->nb_prefix_samples0 * frame_parms->slots_per_subframe) +
  //                                    (frame_parms->nb_prefix_samples * frame_parms->slots_per_subframe * (frame_parms->symbols_per_slot - 1)));
Guy De Souza's avatar
Guy De Souza committed
285
  frame_parms->samples_per_frame = 10 * frame_parms->samples_per_subframe;
Guy De Souza's avatar
Guy De Souza committed
286
  frame_parms->freq_range = (frame_parms->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
287

288 289 290
  return 0;
}

291
void nr_dump_frame_parms(NR_DL_FRAME_PARMS *frame_parms)
292
{
293
  LOG_I(PHY,"frame_parms->scs=%d\n",frame_parms->subcarrier_spacing);
294 295
  LOG_I(PHY,"frame_parms->ofdm_symbol_size=%d\n",frame_parms->ofdm_symbol_size);
  LOG_I(PHY,"frame_parms->nb_prefix_samples0=%d\n",frame_parms->nb_prefix_samples0);
296 297 298 299
  LOG_I(PHY,"frame_parms->nb_prefix_samples=%d\n",frame_parms->nb_prefix_samples);
  LOG_I(PHY,"frame_parms->slots_per_subframe=%d\n",frame_parms->slots_per_subframe);
  LOG_I(PHY,"frame_parms->samples_per_subframe_wCP=%d\n",frame_parms->samples_per_subframe_wCP);
  LOG_I(PHY,"frame_parms->samples_per_frame_wCP=%d\n",frame_parms->samples_per_frame_wCP);
Guy De Souza's avatar
Guy De Souza committed
300 301
  LOG_I(PHY,"frame_parms->samples_per_subframe=%d\n",frame_parms->samples_per_subframe);
  LOG_I(PHY,"frame_parms->samples_per_frame=%d\n",frame_parms->samples_per_frame);
302
}