nr_init.c 27.2 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
extern int32_t get_nr_uldl_offset(int nr_bandP);*/
47
extern openair0_config_t openair0_cfg[MAX_CARDS];
48

49 50
int l1_north_init_gNB()
{
51
  if (RC.nb_nr_L1_inst > 0 && RC.nb_nr_L1_CC != NULL && RC.gNB != NULL) {
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
52 53
    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");
54
    AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
55
    LOG_I(PHY,"%s() RC.nb_nr_L1_inst:%d\n", __FUNCTION__, RC.nb_nr_L1_inst);
56

57
    for (int i=0; i<RC.nb_nr_L1_inst; i++) {
58
      AssertFatal(RC.gNB[i]!=NULL,"RC.gNB[%d] is null\n",i);
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
59 60
      AssertFatal(RC.nb_nr_L1_CC[i]>0,"RC.nb_nr_L1_CC[%d]=%d\n",i,RC.nb_nr_L1_CC[i]);
      LOG_I(PHY,"%s() RC.nb_nr_L1_CC[%d]:%d\n", __FUNCTION__, i,  RC.nb_nr_L1_CC[i]);
61

62
      for (int j=0; j<RC.nb_nr_L1_CC[i]; j++) {
63 64
        AssertFatal(RC.gNB[i][j]!=NULL,"RC.gNB[%d][%d] is null\n",i,j);

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

        LOG_I(PHY,"%s() RC.gNB[%d][%d] installing callbacks\n", __FUNCTION__, i,  j);
68
        RC.gNB[i][j]->if_inst->NR_PHY_config_req    = nr_phy_config_request;
69
        RC.gNB[i][j]->if_inst->NR_Schedule_response = nr_schedule_response;
70 71
      }
    }
72
  } else {
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
73
    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);
74
  }
75

76 77 78 79 80
  return(0);
}


int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
81 82
                    unsigned char is_secondary_gNB,
                    unsigned char abstraction_flag) {
83
  // shortcuts
84
  NR_DL_FRAME_PARMS *const fp       = &gNB->frame_parms;
85
  nfapi_nr_config_request_t *cfg    = &gNB->gNB_config;
86
  NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
87
  NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
88 89
  dmrs_UplinkConfig_t *dmrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig;
  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
90
  /*LTE_eNB_SRS *const srs_vars       = gNB->srs_vars;
91
  LTE_eNB_PRACH *const prach_vars   = &gNB->prach_vars;*/
92

93
  int i;
94

95
  LOG_I(PHY,"[gNB %d] %s() About to wait for gNB to be configured\n", gNB->Mod_id, __FUNCTION__);
96 97 98 99
  gNB->total_dlsch_bitrate = 0;
  gNB->total_transmitted_bits = 0;
  gNB->total_system_throughput = 0;
  gNB->check_for_MUMIMO_transmissions=0;
100

101
  while(gNB->configured == 0) usleep(10000);
102 103

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

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

    for (int symb=0; symb<fp->symbols_per_slot; symb++) {
Guy De Souza's avatar
Guy De Souza committed
132
      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
133 134
      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
135
  }
136 137

  nr_init_pdcch_dmrs(gNB, cfg->sch_config.physical_cell_id.value);
Guy De Souza's avatar
Guy De Souza committed
138
  nr_init_pbch_interleaver(gNB->nr_pbch_interleaver);
139 140 141
  //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
142

143 144
  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
145
    AssertFatal(pdsch_dmrs[slot]!=NULL, "NR init: pdsch_dmrs for slot %d - malloc failed\n", slot);
146 147 148

    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
149
      AssertFatal(pdsch_dmrs[slot][symb]!=NULL, "NR init: pdsch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb);
150

Guy De Souza's avatar
Guy De Souza committed
151
      for (int q=0; q<NR_MAX_NB_CODEWORDS; q++) {
152
        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
153 154
        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
155 156
    }
  }
157

158
  //------------- config PUSCH DMRS parameters(to be updated from RRC)--------------//
159 160 161
  dmrs_Uplink_Config->pusch_dmrs_type = pusch_dmrs_type1;
  dmrs_Uplink_Config->pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
  dmrs_Uplink_Config->pusch_maxLength = pusch_len1;
162 163
  //--------------------------------------------------------------------------------//

164
  nr_init_pdsch_dmrs(gNB, cfg->sch_config.physical_cell_id.value);
165

166 167 168 169 170 171 172
  // default values until overwritten by RRCConnectionReconfiguration

  for (i=0;i<MAX_NR_OF_UL_ALLOCATIONS;i++){
    gNB->pusch_config.pusch_TimeDomainResourceAllocation[i] = (PUSCH_TimeDomainResourceAllocation_t *)malloc16(sizeof(PUSCH_TimeDomainResourceAllocation_t));
    gNB->pusch_config.pusch_TimeDomainResourceAllocation[i]->mappingType = typeB;
  }

173
  gNB->ptrs_configured = 1;
174 175 176 177 178 179 180 181 182 183

  //------------- config PUSCH PTRS parameters(to be updated from RRC)--------------//
  ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
  ptrs_Uplink_Config->timeDensity.ptrs_mcs2 = 0;
  ptrs_Uplink_Config->timeDensity.ptrs_mcs3 = 0;
  ptrs_Uplink_Config->frequencyDensity.n_rb0 = 0;     // setting N_RB values to 0 indicate abscence of frequency_density field in the configuration
  ptrs_Uplink_Config->frequencyDensity.n_rb1 = 0;
  ptrs_Uplink_Config->resourceElementOffset = 0;
  //--------------------------------------------------------------------------------//

Guy De Souza's avatar
Guy De Souza committed
184 185
  /// Transport init necessary for NR synchro
  init_nr_transport(gNB);
186

187
  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.
188
  common_vars->rxdata  = (int32_t **)malloc16(15*sizeof(int32_t*));
189
  common_vars->txdataF = (int32_t **)malloc16(15*sizeof(int32_t*));
190
  common_vars->rxdataF = (int32_t **)malloc16(15*sizeof(int32_t*));
191 192

  for (i=0;i<15;i++){
193 194 195
      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));
196 197 198 199

      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));
200
  }
201

202
  // Channel estimates for SRS
203
/*
204
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
205 206 207
    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 *) );

208
    for (i=0; i<64; i++) {
209 210
      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 );
211 212
    }
  } //UE_id
213
*/
214
  /*generate_ul_ref_sigs_rx();
215

216 217
  init_ulsch_power_LUT();*/

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

  // PRACH
225
  prach_vars->prachF = (int16_t *)malloc16_clear( 1024*2*sizeof(int16_t) );
226
  // assume maximum of 64 RX antennas for PRACH receiver
227
  prach_vars->prach_ifft[0]    = (int32_t **)malloc16_clear(64*sizeof(int32_t *));
228

229 230 231
  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 *));
232
*/
233

234
  for (int UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
235
    //FIXME
236
    pusch_vars[UE_id] = (NR_gNB_PUSCH *)malloc16_clear( sizeof(NR_gNB_PUSCH) );
237 238 239 240 241 242 243 244 245 246 247 248 249
    pusch_vars[UE_id]->rxdataF_ext              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->rxdataF_ext2             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_estimates          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_estimates_ext      = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_ptrs_estimates     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_estimates_time     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->rxdataF_comp             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_mag0               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_magb0              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_mag                = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->ul_ch_magb               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
    pusch_vars[UE_id]->rho                      = (int32_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) );
250 251

    for (i=0; i<fp->nb_antennas_rx; i++) {
252 253
      // RK 2 times because of output format of FFT!
      // FIXME We should get rid of this
254 255 256 257 258 259 260 261 262 263 264 265 266
      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]->ul_ch_estimates[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_estimates_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]->ul_ch_ptrs_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot ); // max intensity in freq is 1 sc every 2 RBs
      pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot );
      pusch_vars[UE_id]->ul_ch_estimates_time[i]       = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
      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_mag0[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_magb0[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_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 );
      pusch_vars[UE_id]->rho[i]                        = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
267 268
    }

269
    pusch_vars[UE_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 
270
  } //UE_id
271
/*
272 273
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
    gNB->UE_stats_ptr[UE_id] = &gNB->UE_stats[UE_id];
274
*/
275
  gNB->pdsch_config_dedicated->p_a = dB0; //defaul value until overwritten by RRCConnectionReconfiguration
276 277 278 279 280 281 282
  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
283
  nfapi_nr_config_request_t *cfg = phy_config->cfg;
284

Guy De Souza's avatar
Guy De Souza committed
285
  NR_DL_FRAME_PARMS *fp;
286
  PHICH_RESOURCE_t phich_resource_table[4]={oneSixth,half,one,two};
287
  int                 eutra_band     = cfg->nfapi_config.rf_bands.rf_band[0];
288 289
  int                 dl_Bandwidth   = cfg->rf_config.dl_carrier_bandwidth.value;
  int                 ul_Bandwidth   = cfg->rf_config.ul_carrier_bandwidth.value;
290 291 292 293 294
  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
295
  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",
296
  Mod_id, CC_id, eutra_band, dl_Bandwidth, ul_Bandwidth, Nid_cell, p_eNB,Ncp,dl_CarrierFreq );
297

Guy De Souza's avatar
Guy De Souza committed
298 299 300
  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);
301 302


Guy De Souza's avatar
Guy De Souza committed
303
  if (RC.gNB[Mod_id][CC_id]->configured == 1)
304 305 306 307 308
  {
    LOG_E(PHY,"Already eNB already configured, do nothing\n");
    return;
  }

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

Guy De Souza's avatar
Guy De Souza committed
311
  fp = &RC.gNB[Mod_id][CC_id]->frame_parms;
312 313 314

  fp->threequarter_fs                    = 0;

Guy De Souza's avatar
Guy De Souza committed
315
  nr_init_frame_parms(fp,1);
316

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


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

332
  for (int i = 0; i < 15; i++) {
333
    free_and_zero(common_vars->txdataF[i]);
334
    /* rxdataF[i] is not allocated -> don't free */
335
  }
336

337 338
  free_and_zero(common_vars->txdataF);
  free_and_zero(common_vars->rxdataF);
339 340
  // PDCCH DMRS sequences
  free_and_zero(pdcch_dmrs);
341
/*
342 343 344 345 346 347
  // 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]);
    }
348

349 350 351 352
    free_and_zero(srs_vars[UE_id].srs_ch_estimates);
    free_and_zero(srs_vars[UE_id].srs_ch_estimates_time);
  } //UE_id

353
  //free_ul_ref_sigs();
354 355 356 357 358 359 360

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

361
  free_and_zero(prach_vars->prach_ifft[0]);
362
  free_and_zero(prach_vars->rxsigF[0]);
363 364 365
*/
  for (int UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
    for (int i = 0; i < 2; i++) {
366 367
      free_and_zero(pusch_vars[UE_id]->rxdataF_ext[i]);
      free_and_zero(pusch_vars[UE_id]->rxdataF_ext2[i]);
368 369
      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext[i]);
370 371
      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]);
372
      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time[i]);
373
      free_and_zero(pusch_vars[UE_id]->rxdataF_comp[i]);
374 375
      free_and_zero(pusch_vars[UE_id]->ul_ch_mag0[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_magb0[i]);
376 377
      free_and_zero(pusch_vars[UE_id]->ul_ch_mag[i]);
      free_and_zero(pusch_vars[UE_id]->ul_ch_magb[i]);
378
      free_and_zero(pusch_vars[UE_id]->rho[i]);
379
    }
380

381 382
    free_and_zero(pusch_vars[UE_id]->rxdataF_ext);
    free_and_zero(pusch_vars[UE_id]->rxdataF_ext2);
383 384
    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates);
    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext);
385 386
    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates);
    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext);
387
    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time);
388
    free_and_zero(pusch_vars[UE_id]->rxdataF_comp);
389 390
    free_and_zero(pusch_vars[UE_id]->ul_ch_mag0);
    free_and_zero(pusch_vars[UE_id]->ul_ch_magb0);
391 392
    free_and_zero(pusch_vars[UE_id]->ul_ch_mag);
    free_and_zero(pusch_vars[UE_id]->ul_ch_magb);
393 394
    free_and_zero(pusch_vars[UE_id]->rho);

395 396 397
    free_and_zero(pusch_vars[UE_id]->llr);
    free_and_zero(pusch_vars[UE_id]);
  } //UE_id
398
/*
399
  for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) gNB->UE_stats_ptr[UE_id] = NULL;
400
*/
401
}
Guy De Souza's avatar
Guy De Souza committed
402
/*
403 404 405 406
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
407
}*/
Guy De Souza's avatar
Guy De Souza committed
408 409

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

411

412 413 414 415 416 417 418 419 420
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;
  nfapi_nr_config_request_t *gNB_config                   = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
421
  //overwrite for new NR parameters
422 423 424 425 426 427 428 429 430 431 432 433
  gNB_config->nfapi_config.rf_bands.rf_band[0]            = 78;
  gNB_config->nfapi_config.nrarfcn.value                  = 620000;
  gNB_config->subframe_config.numerology_index_mu.value   = mu;
  gNB_config->subframe_config.duplex_mode.value           = TDD;
  gNB_config->rf_config.dl_carrier_bandwidth.value        = N_RB_DL;
  gNB_config->rf_config.ul_carrier_bandwidth.value        = N_RB_UL;
  gNB_config->sch_config.half_frame_index.value           = 0;
  gNB_config->sch_config.ssb_subcarrier_offset.value      = 0;
  gNB_config->sch_config.n_ssb_crb.value                  = (N_RB_DL-20);
  gNB_config->sch_config.ssb_subcarrier_offset.value      = 0;
  gNB_config->sch_config.physical_cell_id.value           = Nid_cell;
  gNB_config->sch_config.ssb_scg_position_in_burst.value  = position_in_burst;
434 435
  gNB_config->subframe_config.dl_cyclic_prefix_type.value = (fp->Ncp == NORMAL) ? NFAPI_CP_NORMAL : NFAPI_CP_EXTENDED;

436
  gNB->mac_enabled   = 1;
Francesco Mani's avatar
Francesco Mani committed
437 438
  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);
439
  fp->threequarter_fs= 0;
Guy De Souza's avatar
Guy De Souza committed
440
  nr_init_frame_parms(gNB_config, fp);
441
  gNB->configured    = 1;
Guy De Souza's avatar
Guy De Souza committed
442
  LOG_I(PHY,"gNB configured\n");
443
}
444 445


446 447 448 449 450 451
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;
452
  gNB_config->nfapi_config.rf_bands.rf_band[0]          = phy_config->cfg->nfapi_config.rf_bands.rf_band[0]; //22
Raymond Knopp's avatar
Raymond Knopp committed
453
  gNB_config->nfapi_config.nrarfcn.value                = phy_config->cfg->nfapi_config.nrarfcn.value; //6600
454
  gNB_config->subframe_config.numerology_index_mu.value = phy_config->cfg->subframe_config.numerology_index_mu.value;//1
455 456
  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;
457 458
  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;
459
  gNB_config->sch_config.n_ssb_crb.value                = (phy_config->cfg->rf_config.dl_carrier_bandwidth.value-20);
460
  gNB_config->sch_config.physical_cell_id.value         = phy_config->cfg->sch_config.physical_cell_id.value;
461
  gNB_config->sch_config.ssb_scg_position_in_burst.value= phy_config->cfg->sch_config.ssb_scg_position_in_burst.value;
462
  gNB_config->sch_config.ssb_periodicity.value		    = phy_config->cfg->sch_config.ssb_periodicity.value;
463 464 465

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

  RC.gNB[Mod_id][CC_id]->mac_enabled     = 1;
Raymond Knopp's avatar
Raymond Knopp committed
471
  fp->dl_CarrierFreq = from_nrarfcn(gNB_config->nfapi_config.rf_bands.rf_band[0],gNB_config->nfapi_config.nrarfcn.value);
472 473
  get_band(fp->dl_CarrierFreq, &gNB_config->nfapi_config.rf_bands.rf_band[0], &uplink_frequency_offset[CC_id][0], &fp->frame_type);
  fp->ul_CarrierFreq = fp->dl_CarrierFreq + uplink_frequency_offset[CC_id][0];
474
  fp->threequarter_fs                    = openair0_cfg[0].threequarter_fs;
475
  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d, N_RB_UL %d, Nid_cell %d,DL freq %u, UL freq %u)\n",
476 477 478 479 480 481
        Mod_id,
        CC_id,
        gNB_config->nfapi_config.rf_bands.rf_band[0],
        gNB_config->rf_config.dl_carrier_bandwidth.value,
        gNB_config->rf_config.ul_carrier_bandwidth.value,
        gNB_config->sch_config.physical_cell_id.value,
482 483
        fp->dl_CarrierFreq,
        fp->ul_CarrierFreq);
484

485 486
  nr_init_frame_parms(gNB_config, fp);

487
  if (RC.gNB[Mod_id][CC_id]->configured == 1) {
488 489 490 491 492 493
    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
494
}
495 496 497 498 499 500 501 502

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

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

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

507 508
    for (j=0; j<2; j++) {
      gNB->dlsch[i][j] = new_gNB_dlsch(1,16,NSOFT,0,fp,cfg);
509

510
      if (!gNB->dlsch[i][j]) {
511 512
        LOG_E(PHY,"Can't get gNB dlsch structures for UE %d \n", i);
        exit(-1);
513
      }/* else {
514 515
        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);
516
      }*/
517 518
    }
  }
519

520
  for (i=0; i<NUMBER_OF_NR_ULSCH_MAX; i++) {
521

522 523 524
    LOG_I(PHY,"Allocating Transport Channel Buffer for ULSCH, UE %d\n",i);

    for (j=0; j<2; j++) {
525
      // ULSCH for data
526
      gNB->ulsch[i][j] = new_gNB_ulsch(MAX_LDPC_ITERATIONS, fp->N_RB_UL, 0);
527

528
      if (!gNB->ulsch[i][j]) {
529 530 531
        LOG_E(PHY,"Can't get gNB ulsch structures\n");
        exit(-1);
      }
532

533
      /*
534 535 536 537 538 539 540
      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;
541
      rel15_ul->ulsch_pdu_rel15.start_rb       = 0;
542
      rel15_ul->ulsch_pdu_rel15.number_rbs     = 50;
543 544
      rel15_ul->ulsch_pdu_rel15.start_symbol   = 0;
      rel15_ul->ulsch_pdu_rel15.number_symbols = 14;
545
      rel15_ul->ulsch_pdu_rel15.length_dmrs    = gNB->dmrs_UplinkConfig.pusch_maxLength;
546
      rel15_ul->ulsch_pdu_rel15.Qm             = 2;
Francesco Mani's avatar
Francesco Mani committed
547
      rel15_ul->ulsch_pdu_rel15.R              = 679;
548 549 550 551
      rel15_ul->ulsch_pdu_rel15.mcs            = 9;
      rel15_ul->ulsch_pdu_rel15.rv             = 0;
      rel15_ul->ulsch_pdu_rel15.n_layers       = 1;
      ///////////////////////////////////////////////////
552
      */
553

554
    }
555

556
  }
557

558 559 560 561 562
  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->rx_total_gain_dB=130;
563

564
  for(i=0; i<NUMBER_OF_NR_UE_MAX; i++)
565
    gNB->mu_mimo_mode[i].dl_pow_off = 2;
566

567 568 569 570 571 572
  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;
}