nr_init.c 22.2 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
23
#include "PHY/defs_gNB.h"
#include "PHY/phy_extern.h"
Guy De Souza's avatar
Guy De Souza committed
24
#include "PHY/NR_REFSIG/nr_refsig.h"
25
#include "PHY/INIT/phy_init.h"
Guy De Souza's avatar
Guy De Souza committed
26
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
27
#include "PHY/NR_TRANSPORT/nr_transport.h"
28
29
30
#include "RadioResourceConfigCommonSIB.h"
#include "RadioResourceConfigDedicated.h"
#include "TDD-Config.h"
31
#include "LAYER2/MAC/mac_extern.h"
32
33
34
#include "MBSFN-SubframeConfigList.h"
#include "assertions.h"
#include <math.h>
35

Guy De Souza's avatar
Guy De Souza committed
36
#include "PHY/NR_REFSIG/nr_refsig.h" 
ChenWeiTai's avatar
ChenWeiTai committed
37
#include "PHY/LTE_REFSIG/lte_refsig.h"
ChenWeiTai's avatar
ChenWeiTai committed
38
#include "SCHED_NR/fapi_nr_l1.h"
ChenWeiTai's avatar
ChenWeiTai committed
39

40
41
42
43
44
45
46
extern uint32_t from_earfcn(int eutra_bandP,uint32_t dl_earfcn);
extern int32_t get_uldl_offset(int eutra_bandP);

int l1_north_init_gNB() {

  int i,j;

ChenWeiTai's avatar
ChenWeiTai committed
47
  if (RC.nb_nr_L1_inst > 0 && RC.nb_nr_L1_CC != NULL && RC.gNB != NULL)
48
  {
ChenWeiTai's avatar
ChenWeiTai committed
49
50
    AssertFatal(RC.nb_nr_L1_inst>0,"nb_nr_L1_inst=%d\n",RC.nb_nr_L1_inst);
    AssertFatal(RC.nb_nr_L1_CC!=NULL,"nb_nr_L1_CC is null\n");
51
52
    AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");

ChenWeiTai's avatar
ChenWeiTai committed
53
    LOG_I(PHY,"%s() RC.nb_nr_L1_inst:%d\n", __FUNCTION__, RC.nb_nr_L1_inst);
54

ChenWeiTai's avatar
ChenWeiTai committed
55
    for (i=0;i<RC.nb_nr_L1_inst;i++) {
56
      AssertFatal(RC.gNB[i]!=NULL,"RC.gNB[%d] is null\n",i);
ChenWeiTai's avatar
ChenWeiTai committed
57
      AssertFatal(RC.nb_nr_L1_CC[i]>0,"RC.nb_nr_L1_CC[%d]=%d\n",i,RC.nb_nr_L1_CC[i]);
58

ChenWeiTai's avatar
ChenWeiTai committed
59
      LOG_I(PHY,"%s() RC.nb_nr_L1_CC[%d]:%d\n", __FUNCTION__, i,  RC.nb_nr_L1_CC[i]);
60

ChenWeiTai's avatar
ChenWeiTai committed
61
      for (j=0;j<RC.nb_nr_L1_CC[i];j++) {
62
63
        AssertFatal(RC.gNB[i][j]!=NULL,"RC.gNB[%d][%d] is null\n",i,j);

64
        if ((RC.gNB[i][j]->if_inst =  NR_IF_Module_init(i))<0) return(-1); 
65
66
67

        LOG_I(PHY,"%s() RC.gNB[%d][%d] installing callbacks\n", __FUNCTION__, i,  j);

ChenWeiTai's avatar
ChenWeiTai committed
68
69
        RC.gNB[i][j]->if_inst->NR_PHY_config_req = nr_phy_config_request;
        RC.gNB[i][j]->if_inst->NR_Schedule_response = nr_schedule_response;
70
71
72
73
74
      }
    }
  }
  else
  {
ChenWeiTai's avatar
ChenWeiTai committed
75
    LOG_I(PHY,"%s() Not installing PHY callbacks - RC.nb_nr_L1_inst:%d RC.nb_nr_L1_CC:%p RC.gNB:%p\n", __FUNCTION__, RC.nb_nr_L1_inst, RC.nb_nr_L1_CC, RC.gNB);
76
77
78
79
80
81
82
83
  }
  return(0);
}


int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
                     unsigned char is_secondary_gNB,
                     unsigned char abstraction_flag)
84
85
{

86
87
  // shortcuts
  NR_DL_FRAME_PARMS* const fp       = &gNB->frame_parms;
88
  nfapi_nr_config_request_t* cfg       = &gNB->gNB_config;
89
90
91
92
93
94
95
  NR_gNB_COMMON* const common_vars  = &gNB->common_vars;
  LTE_eNB_PUSCH** const pusch_vars   = gNB->pusch_vars;
  LTE_eNB_SRS* const srs_vars        = gNB->srs_vars;
  LTE_eNB_PRACH* const prach_vars    = &gNB->prach_vars;

  int i, UE_id; 

Florian Kaltenberger's avatar
Florian Kaltenberger committed
96
  LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__);
97
98
99
100
101
102
103

  gNB->total_dlsch_bitrate = 0;
  gNB->total_transmitted_bits = 0;
  gNB->total_system_throughput = 0;
  gNB->check_for_MUMIMO_transmissions=0;
 
  while(gNB->configured == 0) usleep(10000);
104
105

  init_dfts();
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
  LOG_I(PHY,"[gNB %"PRIu8"] Initializing DL_FRAME_PARMS : N_RB_DL %"PRIu8", PHICH Resource %d, PHICH Duration %d nb_antennas_tx:%u nb_antennas_rx:%u PRACH[rootSequenceIndex:%u prach_Config_enabled:%u configIndex:%u highSpeed:%u zeroCorrelationZoneConfig:%u freqOffset:%u]\n",
        gNB->Mod_id,
        fp->N_RB_DL,fp->phich_config_common.phich_resource,
        fp->phich_config_common.phich_duration,
        fp->nb_antennas_tx, fp->nb_antennas_rx,
        fp->prach_config_common.rootSequenceIndex,
        fp->prach_config_common.prach_Config_enabled,
        fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex,
        fp->prach_config_common.prach_ConfigInfo.highSpeedFlag,
        fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig,
        fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset
        );*/
  LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_gNB][MOD %02"PRIu8"][]\n", gNB->Mod_id);

121
122
123
124
  crcTableInit();

  init_dfts();
  
Guy De Souza's avatar
Guy De Souza committed
125
  // PBCH DMRS gold sequences generation
Guy De Souza's avatar
Guy De Souza committed
126
  nr_init_pbch_dmrs(gNB);
Guy De Souza's avatar
Guy De Souza committed
127
  // Polar encoder init for PBCH
Guy De Souza's avatar
Guy De Souza committed
128
  nr_polar_init(&gNB->nrPolar_params,
Guy De Souza's avatar
Guy De Souza committed
129
        NR_POLAR_PBCH_MESSAGE_TYPE,
130
				NR_POLAR_PBCH_PAYLOAD_BITS,
Guy De Souza's avatar
Guy De Souza committed
131
				NR_POLAR_PBCH_AGGREGATION_LEVEL);
132

133
  //PDCCH DMRS init
Guy De Souza's avatar
Guy De Souza committed
134
135
  gNB->nr_gold_pdcch_dmrs = (uint32_t ***)malloc16(fp->slots_per_frame*sizeof(uint32_t**));
  uint32_t ***pdcch_dmrs             = gNB->nr_gold_pdcch_dmrs;
Guy De Souza's avatar
Guy De Souza committed
136
  AssertFatal(pdcch_dmrs!=NULL, "NR init: pdcch_dmrs malloc failed\n");
Guy De Souza's avatar
Guy De Souza committed
137
  for (int slot=0; slot<fp->slots_per_frame; slot++) {
Guy De Souza's avatar
Guy De Souza committed
138
139
140
    pdcch_dmrs[slot] = (uint32_t **)malloc16(fp->symbols_per_slot*sizeof(uint32_t*));
    AssertFatal(pdcch_dmrs[slot]!=NULL, "NR init: pdcch_dmrs for slot %d - malloc failed\n", slot);
    for (int symb=0; symb<fp->symbols_per_slot; symb++){
Guy De Souza's avatar
Guy De Souza committed
141
      pdcch_dmrs[slot][symb] = (uint32_t *)malloc16(NR_MAX_PDCCH_DMRS_INIT_LENGTH_DWORD*sizeof(uint32_t));
Guy De Souza's avatar
Guy De Souza committed
142
143
      AssertFatal(pdcch_dmrs[slot][symb]!=NULL, "NR init: pdcch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb);
    }
Guy De Souza's avatar
Guy De Souza committed
144
  }
145
146

  nr_init_pdcch_dmrs(gNB, cfg->sch_config.physical_cell_id.value);
Guy De Souza's avatar
Guy De Souza committed
147

148
149

   //PDSCH DMRS init
Guy De Souza's avatar
Guy De Souza committed
150
151
   gNB->nr_gold_pdsch_dmrs = (uint32_t ****)malloc16(fp->slots_per_frame*sizeof(uint32_t***));
   uint32_t ****pdsch_dmrs             = gNB->nr_gold_pdsch_dmrs;
152
   for (int slot=0; slot<fp->slots_per_frame; slot++) {
Guy De Souza's avatar
Guy De Souza committed
153
    pdsch_dmrs[slot] = (uint32_t ***)malloc16(fp->symbols_per_slot*sizeof(uint32_t**));
154
155
    AssertFatal(pdsch_dmrs[slot]!=NULL, "NR init: pdsch_dmrs for slot %d - malloc failed\n", slot);
    for (int symb=0; symb<fp->symbols_per_slot; symb++){
Guy De Souza's avatar
Guy De Souza committed
156
      pdsch_dmrs[slot][symb] = (uint32_t **)malloc16(NR_MAX_NB_CODEWORDS*sizeof(uint32_t*));
157
      AssertFatal(pdsch_dmrs[slot][symb]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb);
Guy De Souza's avatar
Guy De Souza committed
158
159
160
161
      for (int q=0; q<NR_MAX_NB_CODEWORDS; q++) {
        pdsch_dmrs[slot][symb][q] = (uint32_t*)malloc16(NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD*sizeof(uint32_t));
        AssertFatal(pdsch_dmrs[slot][symb][q]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d codeword %d - malloc failed\n", slot, symb, q);
      }
162
163
164
165
    }
  }
   
   nr_init_pdsch_dmrs(gNB, cfg->sch_config.physical_cell_id.value);
Guy De Souza's avatar
Guy De Souza committed
166
167
  /// Transport init necessary for NR synchro
  init_nr_transport(gNB);
168
   
169
170
171
172
173
174
175
176
/*
  lte_gold(fp,gNB->lte_gold_table,fp->Nid_cell);
  generate_pcfich_reg_mapping(fp);
  generate_phich_reg_mapping(fp);*/

  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    gNB->first_run_timing_advance[UE_id] =
      1; ///This flag used to be static. With multiple gNBs this does no longer work, hence we put it in the structure. However it has to be initialized with 1, which is performed here.
Guy De Souza's avatar
Guy De Souza committed
177

178
179
180
181
182
183
184
185
    // clear whole structure
    bzero( &gNB->UE_stats[UE_id], sizeof(LTE_eNB_UE_stats) );
    
    gNB->physicalConfigDedicated[UE_id] = NULL;
  }
  
  gNB->first_run_I0_measurements = 1; ///This flag used to be static. With multiple gNBs this does no longer work, hence we put it in the structure. However it has to be initialized with 1, which is performed here.

Guy De Souza's avatar
Guy De Souza committed
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  common_vars->rxdata  = (int32_t **)NULL;
  common_vars->txdataF = (int32_t **)malloc16(NB_ANTENNA_PORTS_ENB*sizeof(int32_t*));
  common_vars->rxdataF = (int32_t **)malloc16(64*sizeof(int32_t*));
  
  LOG_D(PHY,"[INIT] NB_ANTENNA_PORTS_ENB:%d fp->nb_antenna_ports_gNB:%d\n", NB_ANTENNA_PORTS_ENB, cfg->rf_config.tx_antenna_ports.value);

  for (i=0; i<NB_ANTENNA_PORTS_ENB; i++) {
    if (i<cfg->rf_config.tx_antenna_ports.value || i==5) {
      common_vars->txdataF[i] = (int32_t*)malloc16_clear(fp->samples_per_frame_wCP*sizeof(int32_t) );
      
      LOG_D(PHY,"[INIT] common_vars->txdataF[%d] = %p (%lu bytes)\n",
	    i,common_vars->txdataF[i],
	    fp->samples_per_frame_wCP*sizeof(int32_t));
    }
  }  
  
  
  // Channel estimates for SRS
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    
    srs_vars[UE_id].srs_ch_estimates      = (int32_t**)malloc16( 64*sizeof(int32_t*) );
    srs_vars[UE_id].srs_ch_estimates_time = (int32_t**)malloc16( 64*sizeof(int32_t*) );
    
    for (i=0; i<64; i++) {
      srs_vars[UE_id].srs_ch_estimates[i]      = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size );
      srs_vars[UE_id].srs_ch_estimates_time[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2 );
    }
  } //UE_id


  /*generate_ul_ref_sigs_rx();
  
  init_ulsch_power_LUT();*/

  // SRS
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    srs_vars[UE_id].srs = (int32_t*)malloc16_clear(2*fp->ofdm_symbol_size*sizeof(int32_t));
  }

  // PRACH
  prach_vars->prachF = (int16_t*)malloc16_clear( 1024*2*sizeof(int16_t) );

  // assume maximum of 64 RX antennas for PRACH receiver
  prach_vars->prach_ifft[0]    = (int32_t**)malloc16_clear(64*sizeof(int32_t*)); 
  for (i=0;i<64;i++) prach_vars->prach_ifft[0][i]    = (int32_t*)malloc16_clear(1024*2*sizeof(int32_t)); 

  prach_vars->rxsigF[0]        = (int16_t**)malloc16_clear(64*sizeof(int16_t*));

  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    
    //FIXME
    pusch_vars[UE_id] = (LTE_eNB_PUSCH*)malloc16_clear( NUMBER_OF_UE_MAX*sizeof(LTE_eNB_PUSCH) );
    
    pusch_vars[UE_id]->rxdataF_ext      = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->rxdataF_ext2     = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->drs_ch_estimates = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->drs_ch_estimates_time = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->rxdataF_comp     = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->ul_ch_mag  = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    pusch_vars[UE_id]->ul_ch_magb = (int32_t**)malloc16( 2*sizeof(int32_t*) );
    
    for (i=0; i<2; i++) {
      // RK 2 times because of output format of FFT!
      // FIXME We should get rid of this
251
252
253
      pusch_vars[UE_id]->rxdataF_ext[i]      = (int32_t*)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
      pusch_vars[UE_id]->rxdataF_ext2[i]     = (int32_t*)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
      pusch_vars[UE_id]->drs_ch_estimates[i] = (int32_t*)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
254
      pusch_vars[UE_id]->drs_ch_estimates_time[i] = (int32_t*)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
255
256
257
      pusch_vars[UE_id]->rxdataF_comp[i]     = (int32_t*)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
      pusch_vars[UE_id]->ul_ch_mag[i]  = (int32_t*)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
      pusch_vars[UE_id]->ul_ch_magb[i] = (int32_t*)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
      }
    
    pusch_vars[UE_id]->llr = (int16_t*)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) );
  } //UE_id

    
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
    gNB->UE_stats_ptr[UE_id] = &gNB->UE_stats[UE_id];
  
  gNB->pdsch_config_dedicated->p_a = dB0; //defaul value until overwritten by RRCConnectionReconfiguration
  

  return (0);

}
/*
void phy_config_request(PHY_Config_t *phy_config) {

  uint8_t Mod_id              = phy_config->Mod_id;
  int CC_id                   = phy_config->CC_id;
Guy De Souza's avatar
Guy De Souza committed
278
  nfapi_nr_config_request_t *cfg = phy_config->cfg;
279

Guy De Souza's avatar
Guy De Souza committed
280
  NR_DL_FRAME_PARMS *fp;
281
282
  PHICH_RESOURCE_t phich_resource_table[4]={oneSixth,half,one,two};
  int                 eutra_band     = cfg->nfapi_config.rf_bands.rf_band[0];  
283
284
  int                 dl_Bandwidth   = cfg->rf_config.dl_carrier_bandwidth.value;
  int                 ul_Bandwidth   = cfg->rf_config.ul_carrier_bandwidth.value;
285
286
287
288
289
  int                 Nid_cell       = cfg->sch_config.physical_cell_id.value;
  int                 Ncp            = cfg->subframe_config.dl_cyclic_prefix_type.value;
  int                 p_eNB          = cfg->rf_config.tx_antenna_ports.value;
  uint32_t            dl_CarrierFreq = cfg->nfapi_config.earfcn.value;

Guy De Souza's avatar
Guy De Souza committed
290
291
  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,gNB_tx_antenna_ports %d,Ncp %d,DL freq %u)\n",
	Mod_id, CC_id, eutra_band, dl_Bandwidth, ul_Bandwidth, Nid_cell, p_eNB,Ncp,dl_CarrierFreq	);
292

Guy De Souza's avatar
Guy De Souza committed
293
294
295
  AssertFatal(RC.gNB != NULL, "PHY instance pointer doesn't exist\n");
  AssertFatal(RC.gNB[Mod_id] != NULL, "PHY instance %d doesn't exist\n",Mod_id);
  AssertFatal(RC.gNB[Mod_id][CC_id] != NULL, "PHY instance %d, CCid %d doesn't exist\n",Mod_id,CC_id);
296
297


Guy De Souza's avatar
Guy De Souza committed
298
  if (RC.gNB[Mod_id][CC_id]->configured == 1)
299
300
301
302
303
  {
    LOG_E(PHY,"Already eNB already configured, do nothing\n");
    return;
  }

Guy De Souza's avatar
Guy De Souza committed
304
  RC.gNB[Mod_id][CC_id]->mac_enabled     = 1;
305

Guy De Souza's avatar
Guy De Souza committed
306
  fp = &RC.gNB[Mod_id][CC_id]->frame_parms;
307
308
309

  fp->threequarter_fs                    = 0;

Guy De Souza's avatar
Guy De Souza committed
310
  nr_init_frame_parms(fp,1);
311

Guy De Souza's avatar
Guy De Souza committed
312
313
314
  RC.gNB[Mod_id][CC_id]->configured                                   = 1;
  LOG_I(PHY,"gNB %d/%d configured\n",Mod_id,CC_id);
}*/
315
316
317
318
319


void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
{
//  NR_DL_FRAME_PARMS* const fp       = &gNB->frame_parms;
320
  nfapi_nr_config_request_t *cfg       = &gNB->gNB_config;
321
322
323
324
  NR_gNB_COMMON* const common_vars  = &gNB->common_vars;
  LTE_eNB_PUSCH** const pusch_vars   = gNB->pusch_vars;
  LTE_eNB_SRS* const srs_vars        = gNB->srs_vars;
  LTE_eNB_PRACH* const prach_vars    = &gNB->prach_vars;
325
  uint32_t ***pdcch_dmrs             = gNB->nr_gold_pdcch_dmrs;
326
327
328
329
330
331
332
333
334
335
336
337

  int i, UE_id;

  for (i = 0; i < NB_ANTENNA_PORTS_ENB; i++) {
    if (i < cfg->rf_config.tx_antenna_ports.value || i == 5) {
      free_and_zero(common_vars->txdataF[i]);
      /* rxdataF[i] is not allocated -> don't free */
    }
  }
  free_and_zero(common_vars->txdataF);
  free_and_zero(common_vars->rxdataF);

338
339
340
  // PDCCH DMRS sequences
  free_and_zero(pdcch_dmrs);

341
342
343
344
345
346
347
348
349
350
  // Channel estimates for SRS
  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) {
    for (i=0; i<64; i++) {
      free_and_zero(srs_vars[UE_id].srs_ch_estimates[i]);
      free_and_zero(srs_vars[UE_id].srs_ch_estimates_time[i]);
    }
    free_and_zero(srs_vars[UE_id].srs_ch_estimates);
    free_and_zero(srs_vars[UE_id].srs_ch_estimates_time);
  } //UE_id

351
  //free_ul_ref_sigs();
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) free_and_zero(srs_vars[UE_id].srs);

  free_and_zero(prach_vars->prachF);

  for (i = 0; i < 64; i++) free_and_zero(prach_vars->prach_ifft[0][i]);
  free_and_zero(prach_vars->prach_ifft[0]);

  free_and_zero(prach_vars->rxsigF[0]);

  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    for (i = 0; i < 2; i++) {
      free_and_zero(pusch_vars[UE_id]->rxdataF_ext[i]);
      free_and_zero(pusch_vars[UE_id]->rxdataF_ext2[i]);
      free_and_zero(pusch_vars[UE_id]->drs_ch_estimates[i]);
      free_and_zero(pusch_vars[UE_id]->drs_ch_estimates_time[i]);
      free_and_zero(pusch_vars[UE_id]->rxdataF_comp[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_mag[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_magb[i]);
    }
    free_and_zero(pusch_vars[UE_id]->rxdataF_ext);
    free_and_zero(pusch_vars[UE_id]->rxdataF_ext2);
    free_and_zero(pusch_vars[UE_id]->drs_ch_estimates);
    free_and_zero(pusch_vars[UE_id]->drs_ch_estimates_time);
    free_and_zero(pusch_vars[UE_id]->rxdataF_comp);
    free_and_zero(pusch_vars[UE_id]->ul_ch_mag);
    free_and_zero(pusch_vars[UE_id]->ul_ch_magb);
    free_and_zero(pusch_vars[UE_id]->llr);
    free_and_zero(pusch_vars[UE_id]);
  } //UE_id

  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) gNB->UE_stats_ptr[UE_id] = NULL;
}
Guy De Souza's avatar
Guy De Souza committed
385
/*
386
387
388
389
void install_schedule_handlers(IF_Module_t *if_inst)
{
  if_inst->PHY_config_req = phy_config_request;
  if_inst->schedule_response = schedule_response;
Guy De Souza's avatar
Guy De Souza committed
390
}*/
Guy De Souza's avatar
Guy De Souza committed
391
392

/// this function is a temporary addition for NR configuration
393

knopp's avatar
knopp committed
394
void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,int N_RB_DL,int N_RB_UL,int mu)
Guy De Souza's avatar
Guy De Souza committed
395
396
{
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
Guy De Souza's avatar
Guy De Souza committed
397
  nfapi_nr_config_request_t *gNB_config = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
398
399

  //overwrite for new NR parameters
Guy De Souza's avatar
Guy De Souza committed
400
401
  gNB_config->nfapi_config.rf_bands.rf_band[0] = 22;
  gNB_config->nfapi_config.earfcn.value = 6600;
knopp's avatar
knopp committed
402
403
  gNB_config->subframe_config.numerology_index_mu.value = mu;
  gNB_config->subframe_config.duplex_mode.value = TDD;
Guy De Souza's avatar
Guy De Souza committed
404
  gNB_config->rf_config.tx_antenna_ports.value = 1;
knopp's avatar
knopp committed
405
406
  gNB_config->rf_config.dl_carrier_bandwidth.value = N_RB_DL;
  gNB_config->rf_config.ul_carrier_bandwidth.value = N_RB_UL;
Guy De Souza's avatar
Guy De Souza committed
407
  gNB_config->sch_config.half_frame_index.value = 0;
Guy De Souza's avatar
Guy De Souza committed
408
  gNB_config->sch_config.ssb_subcarrier_offset.value = 0;
409
  gNB_config->sch_config.n_ssb_crb.value = (N_RB_DL-20);
Guy De Souza's avatar
Guy De Souza committed
410
  gNB_config->sch_config.ssb_subcarrier_offset.value = 0;
Guy De Souza's avatar
Guy De Souza committed
411
412
413
414


  gNB->mac_enabled     = 1;

Guy De Souza's avatar
Guy De Souza committed
415
416
  fp->dl_CarrierFreq = from_earfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.earfcn.value);
  fp->ul_CarrierFreq = fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000);
Guy De Souza's avatar
Guy De Souza committed
417
418
  fp->threequarter_fs                    = 0;

Guy De Souza's avatar
Guy De Souza committed
419
  nr_init_frame_parms(gNB_config, fp);
Guy De Souza's avatar
Guy De Souza committed
420
421
422

  gNB->configured                                   = 1;
  LOG_I(PHY,"gNB configured\n");
423
}
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439


void nr_phy_config_request(NR_PHY_Config_t *phy_config)
{

  uint8_t Mod_id                  = phy_config->Mod_id;
  int     CC_id                   = phy_config->CC_id;

  NR_DL_FRAME_PARMS         *fp         = &RC.gNB[Mod_id][CC_id]->frame_parms;
  nfapi_nr_config_request_t *gNB_config = &RC.gNB[Mod_id][CC_id]->gNB_config;


  gNB_config->nfapi_config.rf_bands.rf_band[0]          = phy_config->cfg->nfapi_config.rf_bands.rf_band[0]; //22
  gNB_config->nfapi_config.earfcn.value                 = phy_config->cfg->nfapi_config.earfcn.value; //6600
  gNB_config->subframe_config.numerology_index_mu.value = phy_config->cfg->subframe_config.numerology_index_mu.value;//1
  gNB_config->rf_config.tx_antenna_ports.value          = phy_config->cfg->rf_config.tx_antenna_ports.value; //1
440
441
  gNB_config->rf_config.dl_carrier_bandwidth.value      = phy_config->cfg->rf_config.dl_carrier_bandwidth.value;//106;
  gNB_config->rf_config.ul_carrier_bandwidth.value      = phy_config->cfg->rf_config.ul_carrier_bandwidth.value;//106;
442
443
  gNB_config->sch_config.half_frame_index.value         = 0;
  gNB_config->sch_config.ssb_subcarrier_offset.value    = phy_config->cfg->sch_config.ssb_subcarrier_offset.value;//0;
444
  gNB_config->sch_config.n_ssb_crb.value                = (phy_config->cfg->rf_config.dl_carrier_bandwidth.value-20);
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  gNB_config->sch_config.physical_cell_id.value         = phy_config->cfg->sch_config.physical_cell_id.value;

  if (phy_config->cfg->subframe_config.duplex_mode.value == 0) {
    gNB_config->subframe_config.duplex_mode.value    = TDD;
  }
  else {
    gNB_config->subframe_config.duplex_mode.value    = FDD;
  }

  RC.gNB[Mod_id][CC_id]->mac_enabled     = 1;

  fp->dl_CarrierFreq = from_earfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.earfcn.value);
  fp->ul_CarrierFreq = fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000);
  fp->threequarter_fs                    = 0;

  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,gNB_tx_antenna_ports %d,DL freq %u)\n",
  Mod_id, 
  CC_id, 
  gNB_config->nfapi_config.rf_bands.rf_band[0], 
464
465
  gNB_config->rf_config.dl_carrier_bandwidth.value, 
  gNB_config->rf_config.ul_carrier_bandwidth.value, 
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
  gNB_config->sch_config.physical_cell_id.value, 
  gNB_config->rf_config.tx_antenna_ports.value,
  fp->dl_CarrierFreq );

  nr_init_frame_parms(gNB_config, fp);

  if (RC.gNB[Mod_id][CC_id]->configured == 1){
    LOG_E(PHY,"Already gNB already configured, do nothing\n");
    return;
  }

  RC.gNB[Mod_id][CC_id]->configured     = 1;
  LOG_I(PHY,"gNB %d/%d configured\n",Mod_id,CC_id);



Guy De Souza's avatar
Guy De Souza committed
482
}
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

void init_nr_transport(PHY_VARS_gNB *gNB) {

  int i;
  int j;
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;

  LOG_I(PHY, "Initialise nr transport\n");

  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
    LOG_I(PHY,"Allocating Transport Channel Buffers for DLSCH, UE %d\n",i);
    for (j=0; j<2; j++) {
      gNB->dlsch[i][j] = new_gNB_dlsch(1,16,NSOFT,0,fp,cfg);
      if (!gNB->dlsch[i][j]) {
	LOG_E(PHY,"Can't get gNB dlsch structures for UE %d \n", i);
	exit(-1);
hongzhi wang's avatar
hongzhi wang committed
500
      }/* else {
501
502
	gNB->dlsch[i][j]->rnti=0;
	LOG_D(PHY,"dlsch[%d][%d] => %p rnti:%d\n",i,j,gNB->dlsch[i][j], gNB->dlsch[i][j]->rnti);
hongzhi wang's avatar
hongzhi wang committed
503
      }*/
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
    }
    
    //LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i);
    //gNB->ulsch[1+i] = new_gNB_ulsch(MAX_TURBO_ITERATIONS,fp->N_RB_UL, 0);
    
    /*if (!gNB->ulsch[1+i]) {
      LOG_E(PHY,"Can't get gNB ulsch structures\n");
      exit(-1);
    }*/
    
    // this is the transmission mode for the signalling channels
    // this will be overwritten with the real transmission mode by the RRC once the UE is connected
    //gNB->transmission_mode[i] = fp->nb_antenna_ports_gNB==1 ? 1 : 2;
  }
  // ULSCH for RA
  //gNB->ulsch[0] = new_gNB_ulsch(MAX_TURBO_ITERATIONS, fp->N_RB_UL, 0);
  
  /*if (!gNB->ulsch[0]) {
    LOG_E(PHY,"Can't get gNB ulsch structures\n");
    exit(-1);
  }*/
  gNB->dlsch_SI  = new_gNB_dlsch(1,8,NSOFT, 0, fp, cfg);
  LOG_D(PHY,"gNB %d.%d : SI %p\n",gNB->Mod_id,gNB->CC_id,gNB->dlsch_SI);
  gNB->dlsch_ra  = new_gNB_dlsch(1,8,NSOFT, 0, fp, cfg);
  LOG_D(PHY,"gNB %d.%d : RA %p\n",gNB->Mod_id,gNB->CC_id,gNB->dlsch_ra);
  gNB->dlsch_MCH = new_gNB_dlsch(1,8,NSOFT, 0, fp, cfg);
  LOG_D(PHY,"gNB %d.%d : MCH %p\n",gNB->Mod_id,gNB->CC_id,gNB->dlsch_MCH);
  
  
  gNB->rx_total_gain_dB=130;
  
  for(i=0; i<NUMBER_OF_UE_MAX; i++)
    gNB->mu_mimo_mode[i].dl_pow_off = 2;
  
  gNB->check_for_total_transmissions = 0;
  
  gNB->check_for_MUMIMO_transmissions = 0;
  
  gNB->FULL_MUMIMO_transmissions = 0;
  
  gNB->check_for_SUMIMO_transmissions = 0;
  
  //fp->pucch_config_common.deltaPUCCH_Shift = 1;
    
}