nr_parms.c 11.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
{

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

hongzhi wang's avatar
hongzhi wang committed
37
38
39
40
41
42
#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

Guy De Souza's avatar
Guy De Souza committed
43
  if (Ncp == NFAPI_CP_EXTENDED)
hongzhi wang's avatar
hongzhi wang committed
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
    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);
  }

142
  frame_parms->slots_per_frame = 10* frame_parms->slots_per_subframe;
hongzhi wang's avatar
hongzhi wang committed
143
144
145
146
147
148
  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

Guy De Souza's avatar
Guy De Souza committed
151
152
153
154
155
156
157
158
  // Initial bandwidth part configuration -- full carrier bandwidth
  frame_parms->initial_bwp_dl.bwp_id = 0;
  frame_parms->initial_bwp_dl.scs = frame_parms->subcarrier_spacing;
  frame_parms->initial_bwp_dl.location = 0;
  frame_parms->initial_bwp_dl.N_RB = N_RB;
  frame_parms->initial_bwp_dl.cyclic_prefix = Ncp;
  frame_parms->initial_bwp_dl.ofdm_symbol_size = frame_parms->ofdm_symbol_size;

hongzhi wang's avatar
hongzhi wang committed
159
160
161
  return 0;
}

Guy De Souza's avatar
Guy De Souza committed
162
int nr_init_frame_parms_ue(nfapi_nr_config_request_t* config,
hongzhi wang's avatar
hongzhi wang committed
163
164
165
166
167
168
169
                        NR_DL_FRAME_PARMS *frame_parms)
{

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

170
#if DISABLE_LOG_X
171
  printf("Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
172
#else
173
  LOG_I(PHY,"Initializing frame parms for mu %d, N_RB %d, Ncp %d\n",mu, N_RB, Ncp);
174
175
#endif

Wang's avatar
Wang committed
176

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

180
  switch(mu) {
181
182

    case NR_MU_0: //15kHz scs
183
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_0];
184
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_0];
185
186
187
      break;

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

191
      switch(N_RB){
192
193
194
195
196
197
198
199
        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
200
201
202
203
204
205
206
207
208
209
210
211
          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;
          }
212
213
214
215
216
217
218
          break;

        case 133:
        case 162:
        case 189:

        case 217: //80 MHz
219
220
221
          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
222
            frame_parms->nb_prefix_samples0 = 264;
223
224
225
226
227
            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
228
            frame_parms->nb_prefix_samples0 = 352;
229
230
            frame_parms->nb_prefix_samples = 288;
          }
231
232
233
234
235
          break;

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

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

244
      switch(N_RB){ //FR1 bands only
245
246
247
248
249
250
251
252
253
254
255
256
257
        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:
258
        AssertFatal(1==0,"Number of resource blocks %d undefined for mu %d, frame parms = %p\n", N_RB, mu, frame_parms);
259
260
261
262
      }
      break;

    case NR_MU_3:
263
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_3];
264
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_3];
265
266
267
      break;

    case NR_MU_4:
268
      frame_parms->subcarrier_spacing = nr_subcarrier_spacing[NR_MU_4];
269
      frame_parms->slots_per_subframe = nr_slots_per_subframe[NR_MU_4];
270
271
272
      break;

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

hongzhi wang's avatar
hongzhi wang committed
276
    frame_parms->nb_prefix_samples0 = 160;
hongzhi wang's avatar
hongzhi wang committed
277
278
279
280
281
282
    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
283
284
285
286
    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
287

288
  frame_parms->slots_per_frame = 10* frame_parms->slots_per_subframe;
Guy De Souza's avatar
Guy De Souza committed
289
  frame_parms->symbols_per_slot = ((Ncp == NORMAL)? 14 : 12); // to redefine for different slot formats
Guy De Souza's avatar
Guy De Souza committed
290
  frame_parms->samples_per_subframe_wCP = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_slot * frame_parms->slots_per_subframe;
291
  frame_parms->samples_per_frame_wCP = 10 * frame_parms->samples_per_subframe_wCP;
hongzhi wang's avatar
hongzhi wang committed
292
293
  //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
294
  frame_parms->samples_per_frame = 10 * frame_parms->samples_per_subframe;
Guy De Souza's avatar
Guy De Souza committed
295
  frame_parms->freq_range = (frame_parms->dl_CarrierFreq < 6e9)? nr_FR1 : nr_FR2;
296

297
298
299
  return 0;
}

300
void nr_dump_frame_parms(NR_DL_FRAME_PARMS *frame_parms)
301
{
302
  LOG_I(PHY,"frame_parms->scs=%d\n",frame_parms->subcarrier_spacing);
303
304
  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);
305
306
307
308
  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
309
310
  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);
Guy De Souza's avatar
Guy De Souza committed
311
312
313
314
315
316
  LOG_I(PHY,"frame_parms->initial_bwp_dl.bwp_id=%d\n",frame_parms->initial_bwp_dl.bwp_id);
  LOG_I(PHY,"frame_parms->initial_bwp_dl.scs=%d\n",frame_parms->initial_bwp_dl.scs);
  LOG_I(PHY,"frame_parms->initial_bwp_dl.N_RB=%d\n",frame_parms->initial_bwp_dl.N_RB);
  LOG_I(PHY,"frame_parms->initial_bwp_dl.cyclic_prefix=%d\n",frame_parms->initial_bwp_dl.cyclic_prefix);
  LOG_I(PHY,"frame_parms->initial_bwp_dl.location=%d\n",frame_parms->initial_bwp_dl.location);
  LOG_I(PHY,"frame_parms->initial_bwp_dl.ofdm_symbol_size=%d\n",frame_parms->initial_bwp_dl.ofdm_symbol_size);
317
}