nr_init.c 22.1 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 "executables/nr-softmodem-common.h"
23 24
#include "PHY/defs_gNB.h"
#include "PHY/phy_extern.h"
25
#include "PHY/NR_REFSIG/nr_refsig.h"
26
#include "PHY/INIT/phy_init.h"
Guy De Souza's avatar
Guy De Souza committed
27
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
28
#include "PHY/NR_TRANSPORT/nr_transport.h"
29
/*#include "RadioResourceConfigCommonSIB.h"
30 31
#include "RadioResourceConfigDedicated.h"
#include "TDD-Config.h"
32 33
#include "MBSFN-SubframeConfigList.h"*/
#include "openair1/PHY/defs_RU.h"
34
#include "LAYER2/NR_MAC_gNB/mac_proto.h"
35 36
#include "assertions.h"
#include <math.h>
37

38
#include "PHY/NR_TRANSPORT/nr_ulsch.h"
39
#include "PHY/NR_REFSIG/nr_refsig.h"
40
#include "SCHED_NR/fapi_nr_l1.h"
41
#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h"
42
#include "nfapi_nr_interface.h"
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
43

44
/*
Raymond Knopp's avatar
Raymond Knopp committed
45
extern uint32_t from_nrarfcn(int nr_bandP,uint32_t dl_nrarfcn);
46

47
extern int32_t get_nr_uldl_offset(int nr_bandP);
48
extern openair0_config_t openair0_cfg[MAX_CARDS];
49
*/
50 51 52

int l1_north_init_gNB() {

53
  if (RC.nb_nr_L1_inst > 0 &&  RC.gNB != NULL) {
54

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
55
    AssertFatal(RC.nb_nr_L1_inst>0,"nb_nr_L1_inst=%d\n",RC.nb_nr_L1_inst);
56
    AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
57
    LOG_I(PHY,"%s() RC.nb_nr_L1_inst:%d\n", __FUNCTION__, RC.nb_nr_L1_inst);
58

59
    for (int i=0; i<RC.nb_nr_L1_inst; i++) {
60 61
      AssertFatal(RC.gNB[i]!=NULL,"RC.gNB[%d] is null\n",i);

62 63
      if ((RC.gNB[i]->if_inst =  NR_IF_Module_init(i))<0) return(-1);
      
64
      LOG_I(PHY,"%s() RC.gNB[%d] installing callbacks\n", __FUNCTION__, i);
65 66
      RC.gNB[i]->if_inst->NR_PHY_config_req = nr_phy_config_request;
      RC.gNB[i]->if_inst->NR_Schedule_response = nr_schedule_response;
67
    }
68
  } else {
69
    LOG_I(PHY,"%s() Not installing PHY callbacks - RC.nb_nr_L1_inst:%d RC.gNB:%p\n", __FUNCTION__, RC.nb_nr_L1_inst, RC.gNB);
70
  }
71

72 73 74 75 76
  return(0);
}


int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
77 78
                    unsigned char is_secondary_gNB,
                    unsigned char abstraction_flag) {
79
  // shortcuts
80
  NR_DL_FRAME_PARMS *const fp       = &gNB->frame_parms;
81
  nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
82
  NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
83
  NR_gNB_PRACH *const prach_vars   = &gNB->prach_vars;
84 85
  NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
  /*LTE_eNB_SRS *const srs_vars       = gNB->srs_vars;
86
  LTE_eNB_PRACH *const prach_vars   = &gNB->prach_vars;*/
87

88
  int i;
89

90
  LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__);
91 92 93 94
  gNB->total_dlsch_bitrate = 0;
  gNB->total_transmitted_bits = 0;
  gNB->total_system_throughput = 0;
  gNB->check_for_MUMIMO_transmissions=0;
95

96
  while(gNB->configured == 0) usleep(10000);
97 98

  init_dfts();
99 100 101 102 103 104 105 106 107 108 109 110 111
  /*
    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
          );*/
112
  LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_gNB][MOD %02"PRIu8"][]\n", gNB->Mod_id);
113 114
  crcTableInit();
  init_dfts();
Guy De Souza's avatar
Guy De Souza committed
115
  // PBCH DMRS gold sequences generation
Guy De Souza's avatar
Guy De Souza committed
116
  nr_init_pbch_dmrs(gNB);
117
  //PDCCH DMRS init
118
  gNB->nr_gold_pdcch_dmrs = (uint32_t ***)malloc16(fp->slots_per_frame*sizeof(uint32_t **));
Guy De Souza's avatar
Guy De Souza committed
119
  uint32_t ***pdcch_dmrs             = gNB->nr_gold_pdcch_dmrs;
Guy De Souza's avatar
Guy De Souza committed
120
  AssertFatal(pdcch_dmrs!=NULL, "NR init: pdcch_dmrs malloc failed\n");
121

Guy De Souza's avatar
Guy De Souza committed
122
  for (int slot=0; slot<fp->slots_per_frame; slot++) {
123
    pdcch_dmrs[slot] = (uint32_t **)malloc16(fp->symbols_per_slot*sizeof(uint32_t *));
Guy De Souza's avatar
Guy De Souza committed
124
    AssertFatal(pdcch_dmrs[slot]!=NULL, "NR init: pdcch_dmrs for slot %d - malloc failed\n", slot);
125 126

    for (int symb=0; symb<fp->symbols_per_slot; symb++) {
Guy De Souza's avatar
Guy De Souza committed
127
      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
128 129
      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
130
  }
131

132
  nr_init_pdcch_dmrs(gNB, cfg->cell_config.phy_cell_id.value);
Guy De Souza's avatar
Guy De Souza committed
133
  nr_init_pbch_interleaver(gNB->nr_pbch_interleaver);
134 135 136
  //PDSCH DMRS init
  gNB->nr_gold_pdsch_dmrs = (uint32_t ****)malloc16(fp->slots_per_frame*sizeof(uint32_t ***));
  uint32_t ****pdsch_dmrs             = gNB->nr_gold_pdsch_dmrs;
Guy De Souza's avatar
Guy De Souza committed
137

138 139
  for (int slot=0; slot<fp->slots_per_frame; slot++) {
    pdsch_dmrs[slot] = (uint32_t ***)malloc16(fp->symbols_per_slot*sizeof(uint32_t **));
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
140
    AssertFatal(pdsch_dmrs[slot]!=NULL, "NR init: pdsch_dmrs for slot %d - malloc failed\n", slot);
141 142 143

    for (int symb=0; symb<fp->symbols_per_slot; symb++) {
      pdsch_dmrs[slot][symb] = (uint32_t **)malloc16(NR_MAX_NB_CODEWORDS*sizeof(uint32_t *));
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
144
      AssertFatal(pdsch_dmrs[slot][symb]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb);
145

Guy De Souza's avatar
Guy De Souza committed
146
      for (int q=0; q<NR_MAX_NB_CODEWORDS; q++) {
147
        pdsch_dmrs[slot][symb][q] = (uint32_t *)malloc16(NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD*sizeof(uint32_t));
Guy De Souza's avatar
Guy De Souza committed
148 149
        AssertFatal(pdsch_dmrs[slot][symb][q]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d codeword %d - malloc failed\n", slot, symb, q);
      }
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
150 151
    }
  }
152

153
  nr_init_pdsch_dmrs(gNB, cfg->cell_config.phy_cell_id.value);
154

Guy De Souza's avatar
Guy De Souza committed
155 156
  /// Transport init necessary for NR synchro
  init_nr_transport(gNB);
157 158 159

  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.
160
  common_vars->rxdata  = (int32_t **)malloc16(15*sizeof(int32_t*));
161
  common_vars->txdataF = (int32_t **)malloc16(15*sizeof(int32_t*));
162
  common_vars->rxdataF = (int32_t **)malloc16(15*sizeof(int32_t*));
163 164

  for (i=0;i<15;i++){
165 166 167
      common_vars->txdataF[i] = (int32_t*)malloc16_clear(fp->samples_per_frame_wCP*sizeof(int32_t)); // [hna] samples_per_frame without CP
      common_vars->rxdataF[i] = (int32_t*)malloc16_clear(fp->samples_per_frame_wCP*sizeof(int32_t));
      common_vars->rxdata[i] = (int32_t*)malloc16_clear(fp->samples_per_frame*sizeof(int32_t));
168 169 170 171

      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));
172
  }
173

174
  // Channel estimates for SRS
175
/*
176
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
177 178 179
    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 *) );

180
    for (i=0; i<64; i++) {
181 182
      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 );
183 184
    }
  } //UE_id
185
*/
186
  /*generate_ul_ref_sigs_rx();
187

188 189
  init_ulsch_power_LUT();*/

190
/*
191 192
  // SRS
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
193
    srs_vars[UE_id].srs = (int32_t *)malloc16_clear(2*fp->ofdm_symbol_size*sizeof(int32_t));
194
  }
195
*/
196
  // PRACH
197
  prach_vars->prachF = (int16_t *)malloc16_clear( 1024*2*sizeof(int16_t) );
198
  prach_vars->rxsigF = (int16_t *)malloc16_clear( 1024*2*sizeof(int16_t) );
199
  prach_vars->prach_ifft       = (int32_t *)malloc16_clear(1024*2*sizeof(int32_t));
200

201
  int N_RB_UL = cfg->carrier_config.ul_grid_size[cfg->ssb_config.scs_common.value].value;
202

Raymond Knopp's avatar
Raymond Knopp committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216
  for (int ULSCH_id=0; ULSCH_id<NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {

    pusch_vars[ULSCH_id] = (NR_gNB_PUSCH *)malloc16_clear( sizeof(NR_gNB_PUSCH) );
    pusch_vars[ULSCH_id]->rxdataF_ext           = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->rxdataF_ext2          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_estimates       = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_estimates_ext   = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_estimates_time  = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->rxdataF_comp          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_mag0             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_magb0            = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_mag             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->ul_ch_magb            = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[ULSCH_id]->rho                   = (int32_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) );
217 218

    for (i=0; i<fp->nb_antennas_rx; i++) {
219 220 221 222
      pusch_vars[ULSCH_id]->rxdataF_ext[i]           = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
      pusch_vars[ULSCH_id]->rxdataF_ext2[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
      pusch_vars[ULSCH_id]->ul_ch_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
      pusch_vars[ULSCH_id]->ul_ch_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
Raymond Knopp's avatar
Raymond Knopp committed
223
      pusch_vars[ULSCH_id]->ul_ch_estimates_time[i]  = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
224 225 226 227 228
      pusch_vars[ULSCH_id]->rxdataF_comp[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
      pusch_vars[ULSCH_id]->ul_ch_mag0[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
      pusch_vars[ULSCH_id]->ul_ch_magb0[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
      pusch_vars[ULSCH_id]->ul_ch_mag[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
      pusch_vars[ULSCH_id]->ul_ch_magb[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
Raymond Knopp's avatar
Raymond Knopp committed
229
      pusch_vars[ULSCH_id]->rho[i]                   = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
230 231
    }

Raymond Knopp's avatar
Raymond Knopp committed
232
    pusch_vars[ULSCH_id]->llr = (int16_t *)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); // [hna] 6144 is LTE and (8*((3*8*6144)+12)) is not clear 
233
  } //ulsch_id
234
/*
235 236
  for (ulsch_id=0; ulsch_id<NUMBER_OF_UE_MAX; ulsch_id++)
    gNB->UE_stats_ptr[ulsch_id] = &gNB->UE_stats[ulsch_id];
237
*/
238
  gNB->pdsch_config_dedicated->p_a = dB0; //defaul value until overwritten by RRCConnectionReconfiguration
239 240 241
  return (0);
}

242 243
void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
{
244
  //NR_DL_FRAME_PARMS* const fp       = &gNB->frame_parms;
245
  NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
246
  NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
247
  /*LTE_eNB_SRS *const srs_vars        = gNB->srs_vars;
248
  LTE_eNB_PRACH *const prach_vars    = &gNB->prach_vars;*/
249
  uint32_t ***pdcch_dmrs             = gNB->nr_gold_pdcch_dmrs;
250

251
  for (int i = 0; i < 15; i++) {
252
    free_and_zero(common_vars->txdataF[i]);
253
    /* rxdataF[i] is not allocated -> don't free */
254
  }
255

256 257
  free_and_zero(common_vars->txdataF);
  free_and_zero(common_vars->rxdataF);
258 259
  // PDCCH DMRS sequences
  free_and_zero(pdcch_dmrs);
260
/*
261 262 263 264 265 266
  // 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]);
    }
267

268 269 270 271
    free_and_zero(srs_vars[UE_id].srs_ch_estimates);
    free_and_zero(srs_vars[UE_id].srs_ch_estimates_time);
  } //UE_id

272
  //free_ul_ref_sigs();
273 274 275 276 277 278 279

  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]);

280
  free_and_zero(prach_vars->prach_ifft[0]);
281
  free_and_zero(prach_vars->rxsigF[0]);
282
*/
Raymond Knopp's avatar
Raymond Knopp committed
283
  for (int ULSCH_id=0; ULSCH_id<NUMBER_OF_NR_ULSCH_MAX; ULSCH_id++) {
284
    for (int i = 0; i < 2; i++) {
Raymond Knopp's avatar
Raymond Knopp committed
285 286 287 288 289 290 291 292 293 294 295
      free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext[i]);
      free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext2[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_ext[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_time[i]);
      free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb0[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag[i]);
      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb[i]);
      free_and_zero(pusch_vars[ULSCH_id]->rho[i]);
296
    }
297

Raymond Knopp's avatar
Raymond Knopp committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext);
    free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext2);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_ext);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_time);
    free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb0);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag);
    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb);
    free_and_zero(pusch_vars[ULSCH_id]->rho);

    free_and_zero(pusch_vars[ULSCH_id]->llr);
    free_and_zero(pusch_vars[ULSCH_id]);
  } //ULSCH_id
313
/*
314
  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) gNB->UE_stats_ptr[UE_id] = NULL;
315
*/
316
}
Guy De Souza's avatar
Guy De Souza committed
317
/*
318 319 320 321
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
322
}*/
Guy De Souza's avatar
Guy De Souza committed
323 324

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

326

327 328 329 330 331 332 333 334
void nr_phy_config_request_sim(PHY_VARS_gNB *gNB,
                               int N_RB_DL,
                               int N_RB_UL,
                               int mu,
                               int Nid_cell,
                               uint64_t position_in_burst)
{
  NR_DL_FRAME_PARMS *fp                                   = &gNB->frame_parms;
335
  nfapi_nr_config_request_scf_t *gNB_config               = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
336
  //overwrite for new NR parameters
337 338 339 340

  gNB_config->cell_config.phy_cell_id.value             = Nid_cell;
  gNB_config->ssb_config.scs_common.value               = mu;
  gNB_config->ssb_table.ssb_subcarrier_offset.value     = 0;
Francesco Mani's avatar
Francesco Mani committed
341
  gNB_config->ssb_table.ssb_offset_point_a.value        = (N_RB_DL-20)>>1;
342 343 344 345 346 347 348 349
  gNB_config->ssb_table.ssb_mask_list[0].ssb_mask.value = position_in_burst;
  gNB_config->ssb_table.ssb_mask_list[1].ssb_mask.value = position_in_burst>>32;
  gNB_config->cell_config.frame_duplex_type.value       = TDD;
  gNB_config->ssb_table.ssb_period.value		= 1; //10ms
  gNB_config->carrier_config.dl_grid_size[mu].value     = N_RB_DL;
  gNB_config->carrier_config.ul_grid_size[mu].value     = N_RB_UL;

  //gNB_config->subframe_config.dl_cyclic_prefix_type.value = (fp->Ncp == NORMAL) ? NFAPI_CP_NORMAL : NFAPI_CP_EXTENDED;
350

351
  gNB->mac_enabled   = 1;
Francesco Mani's avatar
Francesco Mani committed
352 353
  fp->dl_CarrierFreq = 3500000000;//from_nrarfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.nrarfcn.value);
  fp->ul_CarrierFreq = 3500000000;//fp->dl_CarrierFreq - (get_uldl_offset(gNB_config->nfapi_config.rf_bands.rf_band[0])*100000);
354
  fp->eutra_band = 78;
355
  fp->threequarter_fs= 0;
Guy De Souza's avatar
Guy De Souza committed
356
  nr_init_frame_parms(gNB_config, fp);
357
  gNB->configured    = 1;
Guy De Souza's avatar
Guy De Souza committed
358
  LOG_I(PHY,"gNB configured\n");
359
}
360 361


362
void nr_phy_config_request(NR_PHY_Config_t *phy_config) {
363
  uint8_t Mod_id = phy_config->Mod_id;
Rakesh's avatar
Rakesh committed
364
  int     return_tdd;
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
  NR_DL_FRAME_PARMS *fp = &RC.gNB[Mod_id]->frame_parms;
  nfapi_nr_config_request_scf_t *gNB_config = &RC.gNB[Mod_id]->gNB_config;

  gNB_config->cell_config.phy_cell_id.value             = phy_config->cfg->cell_config.phy_cell_id.value;
  gNB_config->carrier_config.dl_frequency.value         = phy_config->cfg->carrier_config.dl_frequency.value;
  gNB_config->carrier_config.uplink_frequency.value     = phy_config->cfg->carrier_config.uplink_frequency.value;
  gNB_config->ssb_config.scs_common.value               = phy_config->cfg->ssb_config.scs_common.value;
  gNB_config->carrier_config.dl_bandwidth.value         = phy_config->cfg->carrier_config.dl_bandwidth.value;
  gNB_config->carrier_config.uplink_bandwidth.value     = phy_config->cfg->carrier_config.uplink_bandwidth.value;
  gNB_config->ssb_table.ssb_subcarrier_offset.value     = phy_config->cfg->ssb_table.ssb_subcarrier_offset.value;
  gNB_config->ssb_table.ssb_offset_point_a.value        = phy_config->cfg->ssb_table.ssb_offset_point_a.value;
  gNB_config->ssb_table.ssb_mask_list[0].ssb_mask.value = phy_config->cfg->ssb_table.ssb_mask_list[0].ssb_mask.value;
  gNB_config->ssb_table.ssb_mask_list[1].ssb_mask.value = phy_config->cfg->ssb_table.ssb_mask_list[1].ssb_mask.value;
  gNB_config->ssb_table.ssb_period.value		= phy_config->cfg->ssb_table.ssb_period.value;
  for (int i=0; i<5; i++) {
    gNB_config->carrier_config.dl_grid_size[i].value    = phy_config->cfg->carrier_config.dl_grid_size[i].value;
    gNB_config->carrier_config.ul_grid_size[i].value    = phy_config->cfg->carrier_config.ul_grid_size[i].value;
    gNB_config->carrier_config.dl_k0[i].value           = phy_config->cfg->carrier_config.dl_k0[i].value;
    gNB_config->carrier_config.ul_k0[i].value           = phy_config->cfg->carrier_config.ul_k0[i].value;
  }
385

386 387 388

  if (phy_config->cfg->cell_config.frame_duplex_type.value == 0) {
    gNB_config->cell_config.frame_duplex_type.value = FDD;
389
  } else {
390
    gNB_config->cell_config.frame_duplex_type.value = TDD;
391 392
  }

393
  memcpy((void*)&gNB_config->prach_config,(void*)&phy_config->cfg->prach_config,sizeof(phy_config->cfg->prach_config));
394
  memcpy((void*)&gNB_config->tdd_table,(void*)&phy_config->cfg->tdd_table,sizeof(phy_config->cfg->tdd_table));
395 396

  RC.gNB[Mod_id]->mac_enabled     = 1;
397 398
  fp->dl_CarrierFreq = (gNB_config->carrier_config.dl_frequency.value)*1e3 + (gNB_config->carrier_config.dl_bandwidth.value)*5e5;

399 400
  int32_t dlul_offset = 0;
  lte_frame_type_t frame_type = 0;
401
  
402
  get_band(fp->dl_CarrierFreq,&fp->eutra_band,&dlul_offset,&frame_type);
Raymond Knopp's avatar
Raymond Knopp committed
403

404
  fp->ul_CarrierFreq = (gNB_config->carrier_config.uplink_frequency.value)*1e3 + (gNB_config->carrier_config.uplink_bandwidth.value)*5e5;
Raymond Knopp's avatar
Raymond Knopp committed
405

406 407
  fp->threequarter_fs = openair0_cfg[0].threequarter_fs;
  LOG_I(PHY,"Configuring MIB for instance %d, : (Nid_cell %d,DL freq %llu, UL freq %llu)\n",
408
        Mod_id,
409
        gNB_config->cell_config.phy_cell_id.value,
Raymond Knopp's avatar
Raymond Knopp committed
410 411
        (unsigned long long)fp->dl_CarrierFreq,
        (unsigned long long)fp->ul_CarrierFreq);
412

413
  nr_init_frame_parms(gNB_config, fp);
Rakesh's avatar
Rakesh committed
414
  
415

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

421 422
  RC.gNB[Mod_id]->configured     = 1;
  LOG_I(PHY,"gNB %d configured\n",Mod_id);
Guy De Souza's avatar
Guy De Souza committed
423
}
424 425 426 427 428

void init_nr_transport(PHY_VARS_gNB *gNB) {
  int i;
  int j;
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
429
  nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
430
  LOG_I(PHY, "Initialise nr transport\n");
431
  uint16_t grid_size = cfg->carrier_config.dl_grid_size[fp->numerology_index].value;
432

Raymond Knopp's avatar
Raymond Knopp committed
433
  for (i=0; i<NUMBER_OF_NR_DLSCH_MAX; i++) {
434

Raymond Knopp's avatar
Raymond Knopp committed
435
    LOG_I(PHY,"Allocating Transport Channel Buffers for DLSCH %d/%d\n",i,NUMBER_OF_NR_DLSCH_MAX);
436

437
    for (j=0; j<2; j++) {
438
      gNB->dlsch[i][j] = new_gNB_dlsch(fp,1,16,NSOFT,0,grid_size);
439

440
      if (!gNB->dlsch[i][j]) {
441 442
        LOG_E(PHY,"Can't get gNB dlsch structures for UE %d \n", i);
        exit(-1);
443
      }/* else {
444 445
        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);
446
      }*/
447 448
    }
  }
449

Raymond Knopp's avatar
Raymond Knopp committed
450
  for (i=0; i<NUMBER_OF_NR_ULSCH_MAX; i++) {
451

452
    LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i);
453

454
    for (j=0; j<2; j++) {
455
      // ULSCH for data
456
      gNB->ulsch[i][j] = new_gNB_ulsch(MAX_LDPC_ITERATIONS, fp->N_RB_UL, 0);
457

458
      if (!gNB->ulsch[i][j]) {
459 460 461
        LOG_E(PHY,"Can't get gNB ulsch structures\n");
        exit(-1);
      }
462

463
      /*
464 465 466 467 468 469 470
      LOG_I(PHY,"Initializing nFAPI for ULSCH, UE %d\n",i);
      // [hna] added here for RT implementation
      uint8_t harq_pid = 0;
      nfapi_nr_ul_config_ulsch_pdu *rel15_ul = &gNB->ulsch[i+1][j]->harq_processes[harq_pid]->ulsch_pdu;
  
      // --------- setting rel15_ul parameters ----------
      rel15_ul->rnti                           = 0x1234;
471
      rel15_ul->ulsch_pdu_rel15.start_rb       = 0;
472 473 474 475 476 477
      rel15_ul->ulsch_pdu_rel15.number_rbs     = 50;
      rel15_ul->ulsch_pdu_rel15.start_symbol   = 2;
      rel15_ul->ulsch_pdu_rel15.number_symbols = 12;
      rel15_ul->ulsch_pdu_rel15.nb_re_dmrs     = 6;
      rel15_ul->ulsch_pdu_rel15.length_dmrs    = 1;
      rel15_ul->ulsch_pdu_rel15.Qm             = 2;
Francesco Mani's avatar
Francesco Mani committed
478
      rel15_ul->ulsch_pdu_rel15.R              = 679;
479 480 481 482
      rel15_ul->ulsch_pdu_rel15.mcs            = 9;
      rel15_ul->ulsch_pdu_rel15.rv             = 0;
      rel15_ul->ulsch_pdu_rel15.n_layers       = 1;
      ///////////////////////////////////////////////////
483
      */
484

485
    }
486

487
  }
488

489
  gNB->rx_total_gain_dB=130;
490 491


492 493
  //fp->pucch_config_common.deltaPUCCH_Shift = 1;
}