lte_init_ru.c 10.5 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 23 24
#include "phy_init.h"
#include "SCHED/sched_eNB.h"
#include "PHY/phy_extern.h"
25
#include "PHY/LTE_REFSIG/lte_refsig.h"
26
#include "SIMULATION/TOOLS/sim.h"
27 28 29 30
#include "LTE_RadioResourceConfigCommonSIB.h"
#include "LTE_RadioResourceConfigDedicated.h"
#include "LTE_TDD-Config.h"
#include "LTE_MBSFN-SubframeConfigList.h"
31
#include "common/utils/LOG/vcd_signal_dumper.h"
32 33 34
#include "assertions.h"
#include <math.h>

35
void init_7_5KHz(void);
36

37
int phy_init_RU(RU_t *ru) {
yilmazt's avatar
yilmazt committed
38
  LTE_DL_FRAME_PARMS *fp = ru->frame_parms;
39
  RU_CALIBRATION *calibration = &ru->calibration;
yilmazt's avatar
yilmazt committed
40
  int i,j,p,re;
41
  init_dfts();
42 43
  LOG_I(PHY,"Initializing RU signal buffers (if_south %s) nb_tx %d\n",ru_if_types[ru->if_south],ru->nb_tx);

44
  if (ru->is_slave == 1) {
45
    generate_ul_ref_sigs_rx();
46 47
  }

48
  if (ru->if_south <= REMOTE_IF5) { // this means REMOTE_IF5 or LOCAL_RF, so allocate memory for time-domain signals
49
    // Time-domain signals
50 51
    ru->common.txdata        = (int32_t **)malloc16(ru->nb_tx*sizeof(int32_t *));
    ru->common.rxdata        = (int32_t **)malloc16(ru->nb_rx*sizeof(int32_t *) );
52 53 54

    for (i=0; i<ru->nb_tx; i++) {
      // Allocate 10 subframes of I/Q TX signal data (time) if not
55
      ru->common.txdata[i]  = (int32_t *)malloc16_clear( fp->samples_per_tti*10*sizeof(int32_t) );
56
      LOG_I(PHY,"[INIT] common.txdata[%d] = %p (%lu bytes)\n",i,ru->common.txdata[i],
57
            fp->samples_per_tti*10*sizeof(int32_t));
58
    }
59

60
    if (ru->is_slave == 1) {
61
      calibration->drs_ch_estimates_time = (int32_t **)malloc16_clear(ru->nb_rx*sizeof(int32_t *));
62

63 64 65 66
      for (i=0; i<ru->nb_rx; i++) {
        calibration->drs_ch_estimates_time[i] = (int32_t *)malloc16_clear(2*sizeof(int32_t)*fp->ofdm_symbol_size);
      }
    }
67

68 69
    for (i=0; i<ru->nb_rx; i++) {
      ru->common.rxdata[i] = (int32_t *)malloc16_clear( fp->samples_per_tti*10*sizeof(int32_t) );
70 71 72
    }
  } // IF5 or local RF
  else {
73
    //    LOG_I(PHY,"No rxdata/txdata for RU\n");
74 75
    ru->common.txdata        = (int32_t **)NULL;
    ru->common.rxdata        = (int32_t **)NULL;
76
  }
77

78
  if (ru->function != NGFI_RRU_IF5) { // we need to do RX/TX RU processing
79
    init_dfts();
80
    init_7_5KHz();
81
    LOG_I(PHY,"nb_tx %d\n",ru->nb_tx);
82 83 84 85
    ru->common.rxdata_7_5kHz = (int32_t **)malloc16(ru->nb_rx*sizeof(int32_t *) );

    for (i=0; i<ru->nb_rx; i++) {
      ru->common.rxdata_7_5kHz[i] = (int32_t *)malloc16_clear( 2*fp->samples_per_tti*2*sizeof(int32_t) );
86 87 88 89
      LOG_I(PHY,"rxdata_7_5kHz[%d] %p for RU %d\n",i,ru->common.rxdata_7_5kHz[i],ru->idx);
    }

    // allocate IFFT input buffers (TX)
90
    ru->common.txdataF_BF = (int32_t **)malloc16(ru->nb_tx*sizeof(int32_t *));
91
    LOG_I(PHY,"[INIT] common.txdata_BF= %p (%lu bytes)\n",ru->common.txdataF_BF,
92 93
          ru->nb_tx*sizeof(int32_t *));

94
    for (i=0; i<ru->nb_tx; i++) {
95
      ru->common.txdataF_BF[i] = (int32_t *)malloc16_clear(fp->symbols_per_tti*fp->ofdm_symbol_size*sizeof(int32_t) );
96 97
      LOG_I(PHY,"txdataF_BF[%d] %p for RU %d\n",i,ru->common.txdataF_BF[i],ru->idx);
    }
98

99
    // allocate FFT output buffers (RX)
100 101 102
    ru->common.rxdataF     = (int32_t **)malloc16(ru->nb_rx*sizeof(int32_t *) );

    for (i=0; i<ru->nb_rx; i++) {
103
      // allocate 2 subframes of I/Q signal data (frequency)
104
      ru->common.rxdataF[i] = (int32_t *)malloc16_clear(sizeof(int32_t)*(2*fp->ofdm_symbol_size*fp->symbols_per_tti) );
105 106
      LOG_I(PHY,"rxdataF[%d] %p for RU %d\n",i,ru->common.rxdataF[i],ru->idx);
    }
107 108 109 110 111 112 113 114 115 116 117 118 119

    if (ru->is_slave == 1) {
      // allocate FFT output buffers after extraction (RX)
      calibration->rxdataF_ext = (int32_t **)malloc16(2*sizeof(int32_t *));
      calibration->drs_ch_estimates = (int32_t **)malloc16(2*sizeof(int32_t *));

      for (i=0; i<ru->nb_rx; i++) {
        // allocate 2 subframes of I/Q signal data (frequency)
        calibration->rxdataF_ext[i] = (int32_t *)malloc16_clear(sizeof(int32_t)*fp->N_RB_UL*12*fp->symbols_per_tti );
        LOG_I(PHY,"rxdataF_ext[%d] %p for RU %d\n",i,calibration->rxdataF_ext[i],ru->idx);
        calibration->drs_ch_estimates[i] = (int32_t *)malloc16_clear(sizeof(int32_t)*fp->N_RB_UL*12*fp->symbols_per_tti);
      }
    }
120 121

    /* number of elements of an array X is computed as sizeof(X) / sizeof(X[0]) */
122
    //AssertFatal(ru->nb_rx <= sizeof(ru->prach_rxsigF) / sizeof(ru->prach_rxsigF[0]),
123 124 125 126
    //"nb_antennas_rx too large");
    ru->prach_rxsigF = (int16_t **)malloc(ru->nb_rx * sizeof(int16_t *));

    for (j=0; j<4; j++) ru->prach_rxsigF_br[j] = (int16_t **)malloc(ru->nb_rx * sizeof(int16_t *));
127 128

    for (i=0; i<ru->nb_rx; i++) {
129
      ru->prach_rxsigF[i] = (int16_t *)malloc16_clear( fp->ofdm_symbol_size*12*2*sizeof(int16_t) );
130
      LOG_D(PHY,"[INIT] prach_vars->rxsigF[%d] = %p\n",i,ru->prach_rxsigF[i]);
131 132 133 134

      for (j=0; j<4; j++) {
        ru->prach_rxsigF_br[j][i] = (int16_t *)malloc16_clear( fp->ofdm_symbol_size*12*2*sizeof(int16_t) );
        LOG_D(PHY,"[INIT] prach_vars_br->rxsigF[%d] = %p\n",i,ru->prach_rxsigF_br[j][i]);
135 136 137
      }
    }

138 139
    AssertFatal(RC.nb_L1_inst <= NUMBER_OF_eNB_MAX,"eNB instances %d > %d\n",
                RC.nb_L1_inst,NUMBER_OF_eNB_MAX);
140
    LOG_D(PHY,"[INIT] %s() RC.nb_L1_inst:%d \n", __FUNCTION__, RC.nb_L1_inst);
141
    int starting_antenna_index=0;
142 143

    for (i=0; i<ru->idx; i++) starting_antenna_index+=ru->nb_tx;
144

145
    for (i=0; i<RC.nb_L1_inst; i++) {
146
      for (p=0; p<15; p++) {
147
        LOG_D(PHY,"[INIT] %s() nb_antenna_ports_eNB:%d \n", __FUNCTION__, ru->eNB_list[i]->frame_parms.nb_antenna_ports_eNB);
148 149

        if (p<ru->eNB_list[i]->frame_parms.nb_antenna_ports_eNB || p==5) {
150
          LOG_D(PHY,"[INIT] %s() DO BEAM WEIGHTS nb_antenna_ports_eNB:%d nb_tx:%d\n", __FUNCTION__, ru->eNB_list[i]->frame_parms.nb_antenna_ports_eNB, ru->nb_tx);
151 152 153 154 155 156 157 158
          ru->beam_weights[i][p] = (int32_t **)malloc16_clear(ru->nb_tx*sizeof(int32_t *));

          for (j=0; j<ru->nb_tx; j++) {
            ru->beam_weights[i][p][j] = (int32_t *)malloc16_clear(fp->ofdm_symbol_size*sizeof(int32_t));
            // antenna ports 0-3 are mapped on antennas 0-3 as follows
            //    - antenna port p is mapped to antenna j on ru->idx as: p = (starting_antenna_index+j)%nb_anntena_ports_eNB
            // antenna port 4 is mapped on antenna 0
            // antenna ports 5-14 are mapped on all antennas
159

160 161 162 163 164
            if (((p<4) &&
                 (p==((starting_antenna_index+j)%ru->eNB_list[i]->frame_parms.nb_antenna_ports_eNB))) ||
                ((p==4) && (j==0))) {
              for (re=0; re<fp->ofdm_symbol_size; re++) {
                ru->beam_weights[i][p][j][re] = 0x00007fff;
165 166
                //LOG_D(PHY,"[INIT] lte_common_vars->beam_weights[%d][%d][%d][%d] = %d\n", i,p,j,re,ru->beam_weights[i][p][j][re]);
              }
167 168 169
            } else if (p>4) {
              for (re=0; re<fp->ofdm_symbol_size; re++) {
                ru->beam_weights[i][p][j][re] = 0x00007fff/ru->nb_tx;
170 171
                //LOG_D(PHY,"[INIT] lte_common_vars->beam_weights[%d][%d][%d][%d] = %d\n", i,p,j,re,ru->beam_weights[i][p][j][re]);
              }
172 173 174 175 176
            }

            //LOG_D(PHY,"[INIT] lte_common_vars->beam_weights[%d][%d] = %p (%lu bytes)\n", i,j,ru->beam_weights[i][p][j], fp->ofdm_symbol_size*sizeof(int32_t));
          } // for (j=0
        } // if (p<ru
177 178 179 180
      } // for p
    } //for i
  } // !=IF5

181
  ru->common.sync_corr = (uint32_t *)malloc16_clear( LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*sizeof(uint32_t)*fp->samples_per_tti );
182 183
  return(0);
}
184

185
void phy_free_RU(RU_t *ru) {
yilmazt's avatar
yilmazt committed
186
  int i,j,p;
187
  RU_CALIBRATION *calibration = &ru->calibration;
188
  LOG_I(PHY, "Feeing RU signal buffers (if_south %s) nb_tx %d\n", ru_if_types[ru->if_south], ru->nb_tx);
189 190
  free_and_zero(ru->frame_parms);

191 192
  if (ru->if_south <= REMOTE_IF5) { // this means REMOTE_IF5 or LOCAL_RF, so free memory for time-domain signals
    for (i = 0; i < ru->nb_tx; i++) free_and_zero(ru->common.txdata[i]);
193

194
    for (i = 0; i < ru->nb_rx; i++) free_and_zero(ru->common.rxdata[i]);
195 196 197 198 199 200 201

    if (ru->is_slave == 1) {
      for (i = 0; i < ru->nb_rx; i++) {
        free_and_zero(calibration->drs_ch_estimates_time[i]);
      }

      free_and_zero(calibration->drs_ch_estimates_time);
202
    }
203

204 205 206 207 208 209
    free_and_zero(ru->common.txdata);
    free_and_zero(ru->common.rxdata);
  } // else: IF5 or local RF -> nothing to free()

  if (ru->function != NGFI_RRU_IF5) { // we need to do RX/TX RU processing
    for (i = 0; i < ru->nb_rx; i++) free_and_zero(ru->common.rxdata_7_5kHz[i]);
210

211 212 213 214
    free_and_zero(ru->common.rxdata_7_5kHz);

    // free IFFT input buffers (TX)
    for (i = 0; i < ru->nb_tx; i++) free_and_zero(ru->common.txdataF_BF[i]);
215

216 217 218 219
    free_and_zero(ru->common.txdataF_BF);

    // free FFT output buffers (RX)
    for (i = 0; i < ru->nb_rx; i++) free_and_zero(ru->common.rxdataF[i]);
220

221
    free_and_zero(ru->common.rxdataF);
222

223
    if (ru->is_slave == 1) {
224 225 226 227 228 229 230
      for (i = 0; i < ru->nb_rx; i++) {
        free_and_zero(calibration->rxdataF_ext[i]);
        free_and_zero(calibration->drs_ch_estimates[i]);
      }

      free_and_zero(calibration->rxdataF_ext);
      free_and_zero(calibration->drs_ch_estimates);
231
    }
232 233 234

    for (i = 0; i < ru->nb_rx; i++) {
      free_and_zero(ru->prach_rxsigF[i]);
235

236 237
      for (j = 0; j < 4; j++) free_and_zero(ru->prach_rxsigF_br[j][i]);
    }
238

239
    for (j = 0; j < 4; j++) free_and_zero(ru->prach_rxsigF_br[j]);
240

241 242 243 244 245
    free_and_zero(ru->prach_rxsigF);
    /* ru->prach_rxsigF_br is not allocated -> don't free */

    for (i = 0; i < RC.nb_L1_inst; i++) {
      for (p = 0; p < 15; p++) {
246 247 248 249 250
        if (p < ru->eNB_list[i]->frame_parms.nb_antenna_ports_eNB || p == 5) {
          for (j=0; j<ru->nb_tx; j++) free_and_zero(ru->beam_weights[i][p][j]);

          free_and_zero(ru->beam_weights[i][p]);
        }
251 252 253
      }
    }
  }
254

255 256
  free_and_zero(ru->common.sync_corr);
}