ulsim.c 69.3 KB
Newer Older
1
/*
laurent's avatar
laurent committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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
 */
21 22

/*! \file ulsim.c
laurent's avatar
laurent committed
23 24 25 26 27 28 29 30
  \brief Top-level UL simulator
  \author R. Knopp
  \date 2011 - 2014
  \version 0.1
  \company Eurecom
  \email: knopp@eurecom.fr
  \note
  \warning
31 32
*/

33 34 35
#include <string.h>
#include <math.h>
#include <unistd.h>
36
#include "LAYER2/MAC/mac_vars.h"
37
#include "PHY/types.h"
38 39 40 41
#include "PHY/defs_common.h"
#include "PHY/defs_eNB.h"
#include "PHY/defs_UE.h"
#include "PHY/phy_vars.h"
42 43 44 45
#include "PHY/INIT/phy_init.h"
#include "PHY/LTE_TRANSPORT/transport_proto.h"
#include "PHY/LTE_UE_TRANSPORT/transport_proto_ue.h"
#include "PHY/TOOLS/lte_phy_scope.h"
46 47 48
#include "SCHED/sched_common_vars.h"
#include "SCHED/sched_eNB.h"
#include "SCHED_UE/sched_UE.h"
49
#include "SIMULATION/TOOLS/sim.h"
50
#include "OCG_vars.h"
51
#include "unitary_defs.h"
52
#include "dummy_functions.c"
frtabu's avatar
frtabu committed
53
#include "nfapi/oai_integration/vendor_ext.h"
54
#include "common/config/config_load_configmodule.h"
55 56
#include "executables/thread-common.h"
#include "targets/RT/USER/lte-softmodem.h"
laurent's avatar
laurent committed
57
#include "executables/split_headers.h"
58

59
double cpuf;
laurent's avatar
laurent committed
60 61
#define inMicroS(a) (((double)(a))/(cpu_freq_GHz*1000.0))
//#define MCS_COUNT 23//added for PHY abstraction
laurent's avatar
laurent committed
62
#include <openair1/SIMULATION/LTE_PHY/common_sim.h>
63 64
channel_desc_t *eNB2UE[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX];
channel_desc_t *UE2eNB[NUMBER_OF_UE_MAX][NUMBER_OF_eNB_MAX];
laurent's avatar
laurent committed
65
//Added for PHY abstractionopenair1/PHY/TOOLS/lte_phy_scope.h
66
node_desc_t *enb_data[NUMBER_OF_eNB_MAX];
67 68 69
node_desc_t *ue_data[NUMBER_OF_UE_MAX];
//double sinr_bler_map[MCS_COUNT][2][16];

70
extern uint16_t beta_ack[16],beta_ri[16],beta_cqi[16];
71
//extern  char* namepointer_chMag ;
72
int xforms=0;
73 74 75
FD_lte_phy_scope_enb *form_enb;
char title[255];

76 77 78 79 80 81 82
/*the following parameters are used to control the processing times*/
double t_tx_max = -1000000000; /*!< \brief initial max process time for tx */
double t_rx_max = -1000000000; /*!< \brief initial max process time for rx */
double t_tx_min = 1000000000; /*!< \brief initial min process time for tx */
double t_rx_min = 1000000000; /*!< \brief initial min process time for tx */
int n_tx_dropped = 0; /*!< \brief initial max process time for tx */
int n_rx_dropped = 0; /*!< \brief initial max process time for rx */
Laurent's avatar
Laurent committed
83 84 85
static int cmpdouble(const void *p1, const void *p2) {
  return *(double *)p1 > *(double *)p2;
}
frtabu's avatar
frtabu committed
86

87

laurent's avatar
laurent committed
88 89 90 91 92 93 94 95
int split73=0;
void sendFs6Ul(PHY_VARS_eNB *eNB, int UE_id, int harq_pid, int segmentID, int16_t *data, int dataLen, int r_offset) {
  AssertFatal(false, "Must not be called in this context\n");
}
void sendFs6Ulharq(enum pckType type, int UEid, PHY_VARS_eNB *eNB, LTE_eNB_UCI *uci, int frame, int subframe, uint8_t *harq_ack, uint8_t tdd_mapping_mode, uint16_t tdd_multiplexing_mask, uint16_t rnti, int32_t stat) {
  AssertFatal(false, "Must not be called in this context\n");
}

96 97 98 99
extern void fep_full(RU_t *ru, int subframe);
extern void ru_fep_full_2thread(RU_t *ru, int subframe);
//extern void eNB_fep_full(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc);
//extern void eNB_fep_full_2thread(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc);
100 101 102 103

nfapi_dl_config_request_t DL_req;
nfapi_ul_config_request_t UL_req;
nfapi_hi_dci0_request_t HI_DCI0_req;
Cedric Roux's avatar
Cedric Roux committed
104
nfapi_ul_config_request_pdu_t ul_config_pdu_list[MAX_NUM_DL_PDU];
105 106 107 108
nfapi_tx_request_pdu_t tx_pdu_list[MAX_NUM_TX_REQUEST_PDU];
nfapi_tx_request_t TX_req;
Sched_Rsp_t sched_resp;

109

110
void
Cedric Roux's avatar
Cedric Roux committed
111
fill_nfapi_ulsch_config_request(nfapi_ul_config_request_pdu_t *ul_config_pdu,
laurent's avatar
laurent committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                                uint8_t                        cqi_req,
                                uint8_t                        p_eNB,
                                uint8_t                        cqi_ReportModeAperiodic,
                                uint8_t                        betaOffset_CQI_Index,
                                uint8_t                        betaOffset_RI_Index,
                                uint8_t                        dl_cqi_pmi_size,
                                uint8_t                        tmode,
                                uint32_t                       handle,
                                uint16_t                       rnti,
                                uint8_t                        resource_block_start,
                                uint8_t                        number_of_resource_blocks,
                                uint8_t                        modulation_type,
                                uint8_t                        cyclic_shift_2_for_drms,
                                uint8_t                        frequency_hopping_enabled_flag,
                                uint8_t                        frequency_hopping_bits,
                                uint8_t                        new_data_indication,
                                uint8_t                        redundancy_version,
                                uint8_t                        harq_process_number,
                                uint8_t                        ul_tx_mode,
                                uint8_t                        current_tx_nb,
                                uint8_t                        n_srs,
                                uint16_t                       size) {
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t));
  ul_config_pdu->pdu_type                                                    = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE;
  ul_config_pdu->pdu_size                                                    = (uint8_t) (2 + sizeof(nfapi_ul_config_ulsch_pdu));
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.tl.tag                             = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.handle                             = handle;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti                               = rnti;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.resource_block_start               = resource_block_start;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks          = number_of_resource_blocks;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type                    = modulation_type;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms            = cyclic_shift_2_for_drms;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag     = frequency_hopping_enabled_flag;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits             = frequency_hopping_bits;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.new_data_indication                = new_data_indication;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.redundancy_version                 = redundancy_version;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.harq_process_number                = harq_process_number;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode                         = ul_tx_mode;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.current_tx_nb                      = current_tx_nb;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.n_srs                              = n_srs;
  ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.size                               = size;

Raymond Knopp's avatar
Raymond Knopp committed
154 155
  //printf("Filling ul_config_pdu : Q %d, TBS %d, rv %d, ndi %d\n", modulation_type,size,redundancy_version,new_data_indication);

156 157 158 159 160 161 162 163 164 165
  if (cqi_req == 1) {
    // Add CQI portion
    ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE;
    ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_ul_config_ulsch_cqi_ri_pdu));
    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG;
    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type = 1;
    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1;
    LOG_D(MAC, "report_type %d\n",ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type);

    if (p_eNB <= 2
laurent's avatar
laurent committed
166
        && (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10))
167 168 169 170
      ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 1;
    else if (p_eNB <= 2) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 0;
    else if (p_eNB == 4) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 2;

Cedric Roux's avatar
Cedric Roux committed
171
    for (int ri = 0;
laurent's avatar
laurent committed
172 173 174
         ri <  (1 << ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size);
         ri++)
      ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] =  dl_cqi_pmi_size;
Cedric Roux's avatar
Cedric Roux committed
175

176 177 178 179
    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = betaOffset_CQI_Index;
    ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri  = betaOffset_RI_Index;
  }
}
180

181
void fill_ulsch_dci(PHY_VARS_eNB *eNB,
laurent's avatar
laurent committed
182 183 184 185 186 187 188 189 190 191
                    int frame,
                    int subframe,
                    Sched_Rsp_t *sched_resp,
                    uint16_t rnti,
                    void *UL_dci,
                    int first_rb,
                    int nb_rb,
                    int mcs,
                    int modulation_type,
                    int ndi,
Raymond Knopp's avatar
Raymond Knopp committed
192
                    int TBS,
laurent's avatar
laurent committed
193 194 195 196
                    int cqi_flag,
                    uint8_t beta_CQI,
                    uint8_t beta_RI,
                    uint8_t cqi_size) {
197 198 199
  nfapi_ul_config_request_body_t *ul_req=&sched_resp->UL_req->ul_config_request_body;
  int harq_pid = ((frame*10)+subframe)&7;

Raymond Knopp's avatar
Raymond Knopp committed
200
  //printf("ulsch in frame %d, subframe %d => harq_pid %d, mcs %d, ndi %d\n",frame,subframe,harq_pid,mcs,ndi);
201 202

  switch (eNB->frame_parms.N_RB_UL) {
laurent's avatar
laurent committed
203 204
    case 6:
      break;
205

laurent's avatar
laurent committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
    case 25:
      if (eNB->frame_parms.frame_type == TDD) {
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->type    = 0;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_5MHz_TDD_1_6_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci);
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->mcs     = mcs;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->ndi     = ndi;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->TPC     = 0;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->cshift  = 0;
        ((DCI0_5MHz_TDD_1_6_t *)UL_dci)->dai     = 1;
      } else {
        ((DCI0_5MHz_FDD_t *)UL_dci)->type    = 0;
        ((DCI0_5MHz_FDD_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //      printf("nb_rb %d/%d, rballoc %d (dci %x) (dcip %p)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_5MHz_FDD_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci,UL_dci);
        ((DCI0_5MHz_FDD_t *)UL_dci)->mcs     = mcs;
        ((DCI0_5MHz_FDD_t *)UL_dci)->ndi     = ndi;
        ((DCI0_5MHz_FDD_t *)UL_dci)->TPC     = 0;
        ((DCI0_5MHz_FDD_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_5MHz_FDD_t *)UL_dci)->cshift  = 0;
      }
227

laurent's avatar
laurent committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
      break;

    case 50:
      if (eNB->frame_parms.frame_type == TDD) {
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->type    = 0;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //      printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_10MHz_TDD_1_6_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci);
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->mcs     = mcs;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->ndi     = ndi;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->TPC     = 0;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->cshift  = 0;
        ((DCI0_10MHz_TDD_1_6_t *)UL_dci)->dai     = 1;
      } else {
        ((DCI0_10MHz_FDD_t *)UL_dci)->type    = 0;
        ((DCI0_10MHz_FDD_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_10MHz_FDD_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci);
        ((DCI0_10MHz_FDD_t *)UL_dci)->mcs     = mcs;
        ((DCI0_10MHz_FDD_t *)UL_dci)->ndi     = ndi;
        ((DCI0_10MHz_FDD_t *)UL_dci)->TPC     = 0;
        ((DCI0_10MHz_FDD_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_10MHz_FDD_t *)UL_dci)->cshift  = 0;
      }

      break;

    case 100:
      if (eNB->frame_parms.frame_type == TDD) {
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->type    = 0;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //      printf("nb_rb %d/%d, rballoc %d (dci %x)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_20MHz_TDD_1_6_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci);
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->mcs     = mcs;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->ndi     = ndi;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->TPC     = 0;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->cshift  = 0;
        ((DCI0_20MHz_TDD_1_6_t *)UL_dci)->dai     = 1;
      } else {
        ((DCI0_20MHz_FDD_t *)UL_dci)->type    = 0;
        ((DCI0_20MHz_FDD_t *)UL_dci)->rballoc = computeRIV(eNB->frame_parms.N_RB_UL,first_rb,nb_rb); // 12 RBs from position 8
        //   printf("nb_rb %d/%d, rballoc %d (dci %x) (UL_dci %p)\n",nb_rb,eNB->frame_parms.N_RB_UL,((DCI0_20MHz_FDD_t*)UL_dci)->rballoc,*(uint32_t *)UL_dci,(void*)UL_dci);
        ((DCI0_20MHz_FDD_t *)UL_dci)->mcs     = mcs;
        ((DCI0_20MHz_FDD_t *)UL_dci)->ndi     = ndi;
        ((DCI0_20MHz_FDD_t *)UL_dci)->TPC     = 0;
        ((DCI0_20MHz_FDD_t *)UL_dci)->cqi_req = cqi_flag&1;
        ((DCI0_20MHz_FDD_t *)UL_dci)->cshift  = 0;
      }
275

laurent's avatar
laurent committed
276
      break;
277

laurent's avatar
laurent committed
278 279
    default:
      break;
280 281
  }

Cedric Roux's avatar
Cedric Roux committed
282
  fill_nfapi_ulsch_config_request(&ul_req->ul_config_pdu_list[0],
laurent's avatar
laurent committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
                                  cqi_flag&1,
                                  1,  // p_eNB
                                  0,  // reportmode Aperiodic
                                  beta_CQI,
                                  beta_RI,
                                  cqi_size,
                                  //cc,
                                  //UE_template->physicalConfigDedicated,
                                  1,
                                  0,
                                  14,     // rnti
                                  first_rb, // resource_block_start
                                  nb_rb,  // number_of_resource_blocks
                                  modulation_type,
                                  0,  // cyclic_shift_2_for_drms
                                  0,  // frequency_hopping_enabled_flag
                                  0,  // frequency_hopping_bits
                                  ndi,  // new_data_indication
                                  mcs>28?(mcs-28):0,  // redundancy_version
                                  harq_pid, // harq_process_number
                                  0,  // ul_tx_mode
                                  0,  // current_tx_nb
                                  0,  // n_srs
                                  TBS);
307 308 309
  sched_resp->UL_req->header.message_id = NFAPI_UL_CONFIG_REQUEST;
  ul_req->number_of_pdus=1;
  ul_req->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG;
laurent's avatar
laurent committed
310
}
Cedric Roux's avatar
Cedric Roux committed
311

laurent's avatar
laurent committed
312
enum eTypes { eBool, eInt, eFloat, eText };
laurent's avatar
laurent committed
313
static int verbose,help,disable_bundling=0,cqi_flag=0, extended_prefix_flag=0, test_perf=0, subframe=3, transmission_m=1,n_rx=1;
314

laurent's avatar
laurent committed
315
int main(int argc, char **argv) {
316
  int i,j,aa,u;
317 318 319
  PHY_VARS_eNB *eNB;
  PHY_VARS_UE *UE;
  RU_t *ru;
320 321
  int aarx,aatx;
  double channelx,channely;
laurent's avatar
laurent committed
322 323
  static double sigma2, sigma2_dB=10,SNR,SNR2=0,snr0=-2.0,snr1,SNRmeas,rate,saving_bler=0;
  static double input_snr_step=.2,snr_int=30;
324
  double blerr;
laurent's avatar
laurent committed
325
  int rvidx[8]= {0,2,3,1,0,2,3,1};
326 327
  int **txdata;
  LTE_DL_FRAME_PARMS *frame_parms;
328 329
  double s_re0[30720],s_im0[30720],r_re0[30720],r_im0[30720];
  double s_re1[30720],s_im1[30720],r_re1[30720],r_im1[30720];
330 331
  double r_re2[30720],r_im2[30720];
  double r_re3[30720],r_im3[30720];
laurent's avatar
laurent committed
332 333 334 335
  double *s_re[2]= {s_re0,s_re1};
  double *s_im[2]= {s_im0,s_im1};
  double *r_re[4]= {r_re0,r_re1,r_re2,r_re3};
  double *r_im[4]= {r_im0,r_im1,r_im2,r_im3};
336 337
  double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel
  double iqim=0.0;
laurent's avatar
laurent committed
338
  int cqi_error,cqi_errors,ack_errors,cqi_crc_falsepositives,cqi_crc_falsenegatives;
339 340 341 342
  int ch_realization;
  int eNB_id = 0;
  int chMod = 0 ;
  int UE_id = 0;
laurent's avatar
laurent committed
343
  static int nb_rb=25,first_rb=0,mcs=0,round=0;
344
  //unsigned char l;
laurent's avatar
laurent committed
345
  static int awgn_flag = 0 ;
346
  SCM_t channel_model=Rice1;
laurent's avatar
laurent committed
347
  unsigned char *input_buffer=0,harq_pid;
348 349 350
  unsigned short input_buffer_length;
  unsigned int ret;
  unsigned int coded_bits_per_codeword,nsymb;
Laurent's avatar
Laurent committed
351
  unsigned int tx_lev=0,tx_lev_dB,trials,errs[5]= {0,0,0,0,0},round_trials[4]= {0,0,0,0};
352
  FILE *bler_fd=NULL;
353
  char bler_fname[512];
354 355
  FILE *time_meas_fd=NULL;
  char time_meas_fname[256];
356 357 358 359
  FILE *input_fdUL=NULL,*trch_out_fdUL=NULL;
  //  unsigned char input_file=0;
  char input_val_str[50],input_val_str2[50];
  //  FILE *rx_frame_file;
360
  FILE *csv_fdUL=NULL;
361
  char csv_fname[512];
laurent's avatar
laurent committed
362 363 364
  static int n_frames=5000;
  static int n_ch_rlz = 1;
  static int abstx = 0;
365
  int hold_channel=0;
366
  channel_desc_t *UE2eNB;
367
  //uint8_t control_only_flag = 0;
laurent's avatar
laurent committed
368 369 370 371
  static int delay = 0;
  static double maxDoppler = 0.0;
  static int srs_flag = 0;
  static int N_RB_DL=25,osf=1;
372
  //uint8_t cyclic_shift = 0;
laurent's avatar
laurent committed
373 374 375 376
  static uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2,cqi_size=11;
  static uint8_t tdd_config=3,frame_type=FDD;
  static int N0=30;
  static double tx_gain=1.0;
377
  double cpu_freq_GHz;
laurent's avatar
laurent committed
378
  int iter_trials;
379 380 381
  uint32_t UL_alloc_pdu;
  int s,Kr,Kr_bytes;
  int dump_perf=0;
laurent's avatar
laurent committed
382
  static int dump_table =0;
383
  double effective_rate=0.0;
laurent's avatar
laurent committed
384 385
  char channel_model_input[10]= {0};
  static int max_turbo_iterations=4;
386
  int nb_rb_set = 0;
387
  int sf;
laurent's avatar
laurent committed
388
  static int threequarter_fs=0;
389
  int ndi;
Raymond Knopp's avatar
 
Raymond Knopp committed
390
  opp_enabled=1; // to enable the time meas
391 392 393 394
  sched_resp.DL_req = &DL_req;
  sched_resp.UL_req = &UL_req;
  sched_resp.HI_DCI0_req = &HI_DCI0_req;
  sched_resp.TX_req = &TX_req;
laurent's avatar
laurent committed
395 396 397 398
  memset((void *)&DL_req,0,sizeof(DL_req));
  memset((void *)&UL_req,0,sizeof(UL_req));
  memset((void *)&HI_DCI0_req,0,sizeof(HI_DCI0_req));
  memset((void *)&TX_req,0,sizeof(TX_req));
399 400
  UL_req.ul_config_request_body.ul_config_pdu_list = ul_config_pdu_list;
  TX_req.tx_request_body.tx_pdu_list = tx_pdu_list;
401
  cpu_freq_GHz = (double)get_cpu_freq_GHz();
402
  cpuf = cpu_freq_GHz;
laurent's avatar
laurent committed
403
  set_parallel_conf("PARALLEL_SINGLE_THREAD");
404
  printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz);
yilmazt's avatar
yilmazt committed
405
  AssertFatal(load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) != NULL, "Cannot load configuration module, exiting\n");
406
  logInit();
407 408
  set_glog(OAILOG_WARNING);
  T_stdout = 1;
Calisson's avatar
Calisson committed
409 410 411
  // enable these lines if you need debug info
  // however itti will catch all signals, so ctrl-c won't work anymore
  // alternatively you can disable ITTI completely in CMakeLists.txt
Raymond Knopp's avatar
Raymond Knopp committed
412 413 414
  //  itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, NULL);
  //  set_comp_log(PHY,LOG_DEBUG,LOG_HIGH,1);
  //  set_glog(LOG_DEBUG,LOG_HIGH);
laurent's avatar
laurent committed
415 416
  //hapZEbm:n:Y:X:x:s:w:e:q:d:D:O:c:r:i:f:y:c:oA:C:R:g:N:l:S:T:QB:PI:LF
  static paramdef_t options[] = {
laurent's avatar
laurent committed
417
    { "awgn", "Use AWGN channel and not multipath", PARAMFLAG_BOOL, strptr:NULL, defintval:0, TYPE_INT, 0, NULL, NULL },
laurent's avatar
laurent committed
418 419 420 421
    { "BnbRBs", "The LTE bandwith in RBs (100 is 20MHz)",0, iptr:&N_RB_DL,  defintval:25, TYPE_INT, 0 },
    { "mcs", "The MCS to use", 0, iptr:&mcs,  defintval:10, TYPE_INT, 0 },
    { "nb_frame", "number of frame in a test",0, iptr:&n_frames,  defintval:1, TYPE_INT, 0 },
    { "snr", "starting snr", 0, dblptr:&snr0,  defdblval:-2.9, TYPE_DOUBLE, 0 },
422
    { "wsnrInterrupt", "snr int ?", 0, dblptr:&snr_int,  defdblval:30, TYPE_DOUBLE, 0 },
laurent's avatar
laurent committed
423
    { "e_snr_step", "step increasing snr",0, dblptr:&input_snr_step,  defdblval:0.2, TYPE_DOUBLE, 0 },
laurent's avatar
laurent committed
424 425 426 427 428 429 430 431
    { "rb_dynamic", "number of rb in dynamic allocation",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "first_rb", "first rb used in dynamic allocation",0, iptr:&first_rb,  defintval:0, TYPE_INT, 0 },
    { "osrs", "enable srs generation",PARAMFLAG_BOOL, iptr:&srs_flag,  defintval:0, TYPE_INT, 0 },
    { "gchannel", "[A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'),  Rice8('L'), Rice1('M')",0, strptr:NULL,  defstrval:NULL, TYPE_STRING, 0 },
    { "delay_chan", "Channel delay",0, iptr:&delay,  defintval:0, TYPE_INT, 0 },
    { "Doppler", "Maximum doppler shift",0, dblptr:&maxDoppler,  defdblval:0.0, TYPE_DOUBLE, 0 },
    { "Zdump", "dump table",PARAMFLAG_BOOL,  iptr:&dump_table, defintval:0, TYPE_INT, 0 },
    { "Forms", "Display the soft scope", PARAMFLAG_BOOL, iptr:&xforms,  defintval:0, TYPE_INT, 0 },
laurent's avatar
laurent committed
432
    { "Lparallel", "Enable parallel execution",0, strptr:NULL,  defstrval:NULL, TYPE_STRING,  0 },
laurent's avatar
laurent committed
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
    { "Iterations", "Number of iterations of turbo decoder", 0, iptr:&max_turbo_iterations,  defintval:4, TYPE_INT, 0 },
    { "Performance", "Display CPU perfomance of each L1 piece", PARAMFLAG_BOOL,  iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "Q_cqi", "Enable CQI", PARAMFLAG_BOOL, iptr:&cqi_flag,  defintval:0, TYPE_INT, 0 },
    { "prefix_extended","Extended prefix", PARAMFLAG_BOOL, iptr:&extended_prefix_flag,  defintval:0, TYPE_INT, 0 },
    { "RI_beta", "TBD", 0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "CQI_beta", "TBD",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "ACK_beta", "TBD",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "input_file", "input IQ data file",0, iptr:NULL,  defintval:0, TYPE_INT, 0 },
    { "N0", "N0",0, iptr:&N0,  defintval:30, TYPE_INT, 0 },
    { "EsubSampling","three quarters sub-sampling",PARAMFLAG_BOOL, iptr:&threequarter_fs, defintval:0, TYPE_INT, 0 },
    { "TDD", "Enable TDD and set the tdd configuration mode",0, iptr:NULL,  defintval:25, TYPE_INT, 0 },
    { "Subframe", "subframe to use",0, iptr:&subframe,  defintval:3, TYPE_INT, 0 },
    { "xTransmission","transmission mode (1 or 2 are supported)",0, iptr:NULL,  defintval:25, TYPE_INT, 0 },
    { "yN_rx", "TBD: n_rx",0, iptr:&n_rx,  defintval:1, TYPE_INT, 0 },
    { "bundling_disable", "bundling disable",PARAMFLAG_BOOL,  iptr:&disable_bundling, defintval:0, TYPE_INT, 0 },
    { "Y",  "n_ch_rlz",0, iptr:&n_ch_rlz,  defintval:1, TYPE_INT, 0 },
    { "X",  "abstx", PARAMFLAG_BOOL,  iptr:&abstx, defintval:0, TYPE_INT, 0 },
laurent's avatar
laurent committed
450
    { "Operf", "Set the percentage of effective rate to testbench the modem performance (typically 30 and 70, range 1-100)",0, iptr:&test_perf,  defintval:0, TYPE_INT, 0 },
laurent's avatar
laurent committed
451
    { "verbose", "display debug text", PARAMFLAG_BOOL,  iptr:&verbose, defintval:0, TYPE_INT, 0 },
laurent's avatar
laurent committed
452
    { "help", "display help and exit", PARAMFLAG_BOOL,  iptr:&help, defintval:0, TYPE_INT, 0 },
laurent's avatar
laurent committed
453 454
    { "", "",0,  iptr:NULL, defintval:0, TYPE_INT, 0 },
  };
frtabu's avatar
frtabu committed
455
  struct option *long_options = parse_oai_options(options);
laurent's avatar
laurent committed
456 457
  int option_index;
  int res;
458

laurent's avatar
laurent committed
459 460 461 462 463
  while ((res=getopt_long_only(argc, argv, "", long_options, &option_index)) == 0) {
    if (options[option_index].voidptr != NULL ) {
      if (long_options[option_index].has_arg==no_argument)
        *(bool *)options[option_index].iptr=1;
      else switch (options[option_index].type) {
frtabu's avatar
frtabu committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
          case TYPE_INT:
            *(int *)options[option_index].iptr=atoi(optarg);
            break;

          case TYPE_DOUBLE:
            *(double *)options[option_index].dblptr=atof(optarg);
            break;

          case TYPE_UINT8:
            *(uint8_t *)options[option_index].dblptr=atoi(optarg);
            break;

          case TYPE_UINT16:
            *(uint16_t *)options[option_index].dblptr=atoi(optarg);
            break;

          default:
            printf("not decoded type.\n");
            exit(1);
laurent's avatar
laurent committed
483
        }
484

laurent's avatar
laurent committed
485 486
      continue;
    }
487

laurent's avatar
laurent committed
488
    switch (long_options[option_index].name[0]) {
frtabu's avatar
frtabu committed
489 490 491 492
      case 'T':
        tdd_config=atoi(optarg);
        frame_type=TDD;
        break;
laurent's avatar
laurent committed
493

frtabu's avatar
frtabu committed
494 495 496 497
      case 'a':
        channel_model = AWGN;
        chMod = 1;
        break;
laurent's avatar
laurent committed
498

frtabu's avatar
frtabu committed
499 500 501 502 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
      case 'g':
        strncpy(channel_model_input,optarg,9);
        struct tmp {
          char opt;
          int m;
          int M;
        }
        tmp[]= {
          {'A',SCM_A,2},
          {'B',SCM_B,3},
          {'C',SCM_C,4},
          {'D',SCM_D,5},
          {'E',EPA,6},
          {'G',ETU,8},
          {'H',Rayleigh8,9},
          {'I',Rayleigh1,10},
          {'J',Rayleigh1_corr,11},
          {'K',Rayleigh1_anticorr,12},
          {'L',Rice8,13},
          {'M',Rice1,14},
          {'N',AWGN,1},
          {0,0,0}
        };
        struct tmp *ptr;

        for (ptr=tmp; ptr->opt!=0; ptr++)
          if ( ptr->opt == optarg[0] ) {
            channel_model=ptr->m;
            chMod=ptr->M;
            break;
          }
laurent's avatar
laurent committed
530

frtabu's avatar
frtabu committed
531 532
        AssertFatal(ptr->opt != 0, "Unsupported channel model: %s !\n", optarg );
        break;
laurent's avatar
laurent committed
533

frtabu's avatar
frtabu committed
534 535 536 537 538 539 540 541 542 543
      case 'x':
        transmission_m=atoi(optarg);
        AssertFatal(transmission_m==1 || transmission_m==2,
                    "Unsupported transmission mode %d\n",transmission_m);
        break;

      case 'r':
        nb_rb = atoi(optarg);
        nb_rb_set = 1;
        break;
544

laurent's avatar
laurent committed
545 546 547
      //case 'c':
      //  cyclic_shift = atoi(optarg);
      //  break;
548

frtabu's avatar
frtabu committed
549 550 551 552 553
      case 'i':
        input_fdUL = fopen(optarg,"r");
        printf("Reading in %s (%p)\n",optarg,input_fdUL);
        AssertFatal(input_fdUL != (FILE *)NULL,"Unknown file %s\n",optarg);
        break;
laurent's avatar
laurent committed
554

frtabu's avatar
frtabu committed
555 556 557 558
      case 'A':
        beta_ACK = atoi(optarg);
        AssertFatal(beta_ACK>15,"beta_ack must be in (0..15)\n");
        break;
laurent's avatar
laurent committed
559

frtabu's avatar
frtabu committed
560 561 562 563
      case 'C':
        beta_CQI = atoi(optarg);
        AssertFatal((beta_CQI>15)||(beta_CQI<2),"beta_cqi must be in (2..15)\n");
        break;
laurent's avatar
laurent committed
564

frtabu's avatar
frtabu committed
565 566 567 568
      case 'R':
        beta_RI = atoi(optarg);
        AssertFatal((beta_RI>15)||(beta_RI<2),"beta_ri must be in (0..13)\n");
        break;
laurent's avatar
laurent committed
569

frtabu's avatar
frtabu committed
570 571 572 573
      case 'P':
        dump_perf=1;
        opp_enabled=1;
        break;
laurent's avatar
laurent committed
574

frtabu's avatar
frtabu committed
575 576 577 578 579 580 581 582
      case 'L':
        set_parallel_conf(optarg);
        break;

      default:
        printf("Wrong option: %s\n",long_options[option_index].name);
        exit(1);
        break;
laurent's avatar
laurent committed
583 584
    }
  }
585

laurent's avatar
laurent committed
586 587 588 589
  if ( res != -1 ) {
    printf("A wrong option has been found\n");
    exit(1);
  }
590

laurent's avatar
laurent committed
591
  if (help || verbose )
frtabu's avatar
frtabu committed
592 593
    display_options_values(options, true);

laurent's avatar
laurent committed
594 595
  if (help)
    exit(0);
frtabu's avatar
frtabu committed
596

laurent's avatar
laurent committed
597 598
  if (thread_struct.parallel_conf != PARALLEL_SINGLE_THREAD)
    set_worker_conf("WORKER_ENABLE");
frtabu's avatar
frtabu committed
599

600 601 602
  RC.nb_L1_inst = 1;
  RC.nb_RU = 1;
  lte_param_init(&eNB,&UE,&ru,
603
                 1,
laurent's avatar
laurent committed
604 605 606 607 608 609 610 611 612 613 614 615 616
                 1,
                 n_rx,
                 1,
                 1,
                 extended_prefix_flag,
                 frame_type,
                 0,
                 tdd_config,
                 N_RB_DL,
                 4,
                 threequarter_fs,
                 osf,
                 0);
frtabu's avatar
frtabu committed
617
  RC.eNB = (PHY_VARS_eNB ** *)malloc(sizeof(PHY_VARS_eNB **));
618 619 620 621 622
  RC.eNB[0] = (PHY_VARS_eNB **)malloc(sizeof(PHY_VARS_eNB *));
  RC.ru = (RU_t **)malloc(sizeof(RC.ru));
  RC.eNB[0][0] = eNB;
  RC.ru[0] = ru;

laurent's avatar
laurent committed
623
  for (int k=0; k<eNB->RU_list[0]->nb_rx; k++) eNB->common_vars.rxdataF[k]     =  eNB->RU_list[0]->common.rxdataF[k];
Cedric Roux's avatar
Cedric Roux committed
624

laurent's avatar
laurent committed
625
  memset((void *)&eNB->UL_INFO,0,sizeof(eNB->UL_INFO));
626 627 628 629 630
  printf("Setting indication lists\n");
  eNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list   = eNB->rx_pdu_list;
  eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list = eNB->crc_pdu_list;
  eNB->UL_INFO.sr_ind.sr_indication_body.sr_pdu_list = eNB->sr_pdu_list;
  eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list;
631 632
  eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_pdu_list = eNB->cqi_pdu_list;
  eNB->UL_INFO.cqi_ind.cqi_indication_body.cqi_raw_pdu_list = eNB->cqi_raw_pdu_list;
633
  printf("lte_param_init done\n");
Calisson's avatar
Calisson committed
634
  // for a call to phy_reset_ue later we need PHY_vars_UE_g allocated and pointing to UE
frtabu's avatar
frtabu committed
635
  PHY_vars_UE_g = (PHY_VARS_UE ** *)malloc(sizeof(PHY_VARS_UE **));
laurent's avatar
laurent committed
636
  PHY_vars_UE_g[0] = (PHY_VARS_UE **) malloc(sizeof(PHY_VARS_UE *));
Calisson's avatar
Calisson committed
637 638
  PHY_vars_UE_g[0][0] = UE;

639
  if (nb_rb_set == 0)
640
    nb_rb = eNB->frame_parms.N_RB_UL;
641

642
  printf("1 . rxdataF_comp[0] %p\n",eNB->pusch_vars[0]->rxdataF_comp[0]);
643
  printf("Setting mcs = %d\n",mcs);
644
  printf("n_frames = %d\n", n_frames);
Raymond Knopp's avatar
 
Raymond Knopp committed
645
  snr1 = snr0+snr_int;
646
  printf("SNR0 %f, SNR1 %f\n",snr0,snr1);
647 648 649
  frame_parms = &eNB->frame_parms;
  txdata = UE->common_vars.txdata;
  nsymb = (eNB->frame_parms.Ncp == NORMAL) ? 14 : 12;
650
  sprintf(bler_fname,"ULbler_mcs%d_nrb%d_ChannelModel%d_nsim%d.csv",mcs,nb_rb,chMod,n_frames);
651
  bler_fd = fopen(bler_fname,"w");
laurent's avatar
laurent committed
652

653 654 655 656
  if (bler_fd==NULL) {
    fprintf(stderr,"Problem creating file %s\n",bler_fname);
    exit(-1);
  }
657

658
  fprintf(bler_fd,"#SNR;mcs;nb_rb;TBS;rate;errors[0];trials[0];errors[1];trials[1];errors[2];trials[2];errors[3];trials[3]\n");
659 660

  if (test_perf != 0) {
661 662 663 664
    char hostname[1024];
    hostname[1023] = '\0';
    gethostname(hostname, 1023);
    printf("Hostname: %s\n", hostname);
665 666 667 668
    //char dirname[FILENAME_MAX];
    //sprintf(dirname, "%s//SIMU/USER/pre-ci-logs-%s", getenv("OPENAIR_TARGETS"),hostname);
    //mkdir(dirname, 0777);
    sprintf(time_meas_fname,"time_meas_prb%d_mcs%d_antrx%d_channel%s_tx%d.csv",
laurent's avatar
laurent committed
669
            N_RB_DL,mcs,n_rx,channel_model_input,transmission_m);
670
    time_meas_fd = fopen(time_meas_fname,"w");
laurent's avatar
laurent committed
671

672 673 674 675
    if (time_meas_fd==NULL) {
      fprintf(stderr,"Cannot create file %s!\n",time_meas_fname);
      exit(-1);
    }
676
  }
677 678 679

  if(abstx) {
    // CSV file
laurent's avatar
laurent committed
680
    sprintf(csv_fname,"EULdataout_tx%d_mcs%d_nbrb%d_chan%d_nsimus%d_eren.m",transmission_m,mcs,nb_rb,chMod,n_frames);
681
    csv_fdUL = fopen(csv_fname,"w");
laurent's avatar
laurent committed
682

683 684 685 686
    if (csv_fdUL == NULL) {
      fprintf(stderr,"Problem opening file %s\n",csv_fname);
      exit(-1);
    }
laurent's avatar
laurent committed
687

688 689
    fprintf(csv_fdUL,"data_all%d=[",mcs);
  }
690

691 692 693 694 695 696
  if (xforms==1) {
    fl_initialize (&argc, argv, NULL, 0, 0);
    form_enb = create_lte_phy_scope_enb();
    sprintf (title, "LTE PHY SCOPE eNB");
    fl_show_form (form_enb->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
  }
697

hbilel's avatar
hbilel committed
698
  UE->pdcch_vars[0][0]->crnti = 14;
699
  UE->frame_parms.soundingrs_ul_config_common.enabled_flag = srs_flag;
700
  UE->frame_parms.soundingrs_ul_config_common.srs_BandwidthConfig = 2;
701 702 703 704
  UE->frame_parms.soundingrs_ul_config_common.srs_SubframeConfig = 3;
  UE->soundingrs_ul_config_dedicated[eNB_id].srsConfigDedicatedSetup = srs_flag;
  UE->soundingrs_ul_config_dedicated[eNB_id].duration = 1;
  UE->soundingrs_ul_config_dedicated[eNB_id].srs_ConfigIndex = 2;
705 706 707
  UE->soundingrs_ul_config_dedicated[eNB_id].srs_Bandwidth = 0;
  UE->soundingrs_ul_config_dedicated[eNB_id].transmissionComb = 0;
  UE->soundingrs_ul_config_dedicated[eNB_id].freqDomainPosition = 0;
708
  UE->soundingrs_ul_config_dedicated[eNB_id].cyclicShift = 0;
709
  eNB->frame_parms.soundingrs_ul_config_common.enabled_flag = srs_flag;
710
  eNB->frame_parms.soundingrs_ul_config_common.srs_BandwidthConfig = 2;
711 712 713 714
  eNB->frame_parms.soundingrs_ul_config_common.srs_SubframeConfig = 3;
  eNB->soundingrs_ul_config_dedicated[UE_id].srsConfigDedicatedSetup = srs_flag;
  eNB->soundingrs_ul_config_dedicated[UE_id].duration = 1;
  eNB->soundingrs_ul_config_dedicated[UE_id].srs_ConfigIndex = 2;
715 716 717
  eNB->soundingrs_ul_config_dedicated[UE_id].srs_Bandwidth = 0;
  eNB->soundingrs_ul_config_dedicated[UE_id].transmissionComb = 0;
  eNB->soundingrs_ul_config_dedicated[UE_id].freqDomainPosition = 0;
718
  eNB->soundingrs_ul_config_dedicated[UE_id].cyclicShift = 0;
719 720 721 722 723 724 725
  eNB->pusch_config_dedicated[UE_id].betaOffset_ACK_Index = beta_ACK;
  eNB->pusch_config_dedicated[UE_id].betaOffset_RI_Index  = beta_RI;
  eNB->pusch_config_dedicated[UE_id].betaOffset_CQI_Index = beta_CQI;
  UE->pusch_config_dedicated[eNB_id].betaOffset_ACK_Index = beta_ACK;
  UE->pusch_config_dedicated[eNB_id].betaOffset_RI_Index  = beta_RI;
  UE->pusch_config_dedicated[eNB_id].betaOffset_CQI_Index = beta_CQI;
  UE->ul_power_control_dedicated[eNB_id].deltaMCS_Enabled = 1;
726 727 728
  // disable periodic cqi/ri reporting
  UE->cqi_report_config[eNB_id].CQI_ReportPeriodic.ri_ConfigIndex = -1;
  UE->cqi_report_config[eNB_id].CQI_ReportPeriodic.cqi_PMI_ConfigIndex = -1;
729
  printf("PUSCH Beta : ACK %f, RI %f, CQI %f\n",(double)beta_ack[beta_ACK]/8,(double)beta_ri[beta_RI]/8,(double)beta_cqi[beta_CQI]/8);
730 731
  UE2eNB = new_channel_desc_scm(1,
                                n_rx,
732
                                channel_model,
laurent's avatar
laurent committed
733 734
                                N_RB2sampling_rate(eNB->frame_parms.N_RB_UL),
                                N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL),
735
                                30e-9,
736 737 738 739 740 741 742
                                forgetting_factor,
                                delay,
                                0);
  // set Doppler
  UE2eNB->max_Doppler = maxDoppler;

  // NN: N_RB_UL has to be defined in ulsim
laurent's avatar
laurent committed
743 744
  for (int k=0; k<NUMBER_OF_UE_MAX; k++) eNB->ulsch[k] = new_eNB_ulsch(max_turbo_iterations,N_RB_DL,0);

745
  UE->ulsch[0]   = new_ue_ulsch(N_RB_DL,0);
746
  printf("ULSCH %p\n",UE->ulsch[0]);
747

laurent's avatar
laurent committed
748
  if(get_thread_worker_conf() == WORKER_ENABLE) {
749
    extern void init_fep_thread(RU_t *, pthread_attr_t *);
750
    extern void init_td_thread(PHY_VARS_eNB *);
751
    init_fep_thread(ru,NULL);
752
    init_td_thread(eNB);
753
  }
laurent's avatar
laurent committed
754

755
  // Create transport channel structures for 2 transport blocks (MIMO)
756
  for (i=0; i<2; i++) {
757
    eNB->dlsch[0][i] = new_eNB_dlsch(1,8,1827072,N_RB_DL,0,&eNB->frame_parms);
laurent's avatar
laurent committed
758

759
    if (!eNB->dlsch[0][i]) {
760 761 762
      printf("Can't get eNB dlsch structures\n");
      exit(-1);
    }
laurent's avatar
laurent committed
763

764
    eNB->dlsch[0][i]->rnti = 14;
765
  }
laurent's avatar
laurent committed
766

767
  /* allocate memory for both subframes (only one is really used
laurent's avatar
laurent committed
768 769 770 771
     but there is now "copy_harq_proc_struct" which needs both
     to be valid)
     TODO: refine this somehow (necessary?)
  */
772 773 774
  for (sf = 0; sf < 2; sf++) {
    for (i=0; i<2; i++) {
      UE->dlsch[sf][0][i]  = new_ue_dlsch(1,8,1827072,MAX_TURBO_ITERATIONS,N_RB_DL,0);
laurent's avatar
laurent committed
775

776 777 778 779
      if (!UE->dlsch[sf][0][i]) {
        printf("Can't get ue dlsch structures\n");
        exit(-1);
      }
laurent's avatar
laurent committed
780

781 782 783
      UE->dlsch[sf][0][i]->rnti   = 14;
    }
  }
784

785 786
  UE->dlsch_SI[0]  = new_ue_dlsch(1,1,1827072,MAX_TURBO_ITERATIONS,N_RB_DL,0);
  UE->dlsch_ra[0]  = new_ue_dlsch(1,1,1827072,MAX_TURBO_ITERATIONS,N_RB_DL,0);
787 788
  UE->measurements.rank[0] = 0;
  UE->transmission_mode[0] = 2;
laurent's avatar
laurent committed
789
  UE->pucch_config_dedicated[0].tdd_AckNackFeedbackMode = disable_bundling == 0 ? bundling : multiplexing;
790
  eNB->transmission_mode[0] = 2;
laurent's avatar
laurent committed
791
  eNB->pucch_config_dedicated[0].tdd_AckNackFeedbackMode = disable_bundling == 0 ? bundling : multiplexing;
792 793 794 795 796 797
  UE->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
  eNB->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
  UE->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
  eNB->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 0;
  UE->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
  eNB->frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = 0;
798
  UE->mac_enabled=0;
799
  L1_rxtx_proc_t *proc_rxtx         = &eNB->proc.L1_proc;
800
  UE_rxtx_proc_t *proc_rxtx_ue = &UE->proc.proc_rxtx[subframe&1];
801 802 803 804
  proc_rxtx->frame_rx=1;
  proc_rxtx->subframe_rx=subframe;
  proc_rxtx->frame_tx=pdcch_alloc2ul_frame(&eNB->frame_parms,1,subframe);
  proc_rxtx->subframe_tx=pdcch_alloc2ul_subframe(&eNB->frame_parms,subframe);
805
  proc_rxtx_ue->frame_tx = proc_rxtx->frame_rx;
806
  proc_rxtx_ue->frame_rx = (subframe<4)?(proc_rxtx->frame_tx-1):(proc_rxtx->frame_tx);
807
  proc_rxtx_ue->subframe_tx = proc_rxtx->subframe_rx;
808
  proc_rxtx_ue->subframe_rx = (proc_rxtx->subframe_tx+6)%10;
laurent's avatar
laurent committed
809 810 811 812 813 814
  proc_rxtx->threadPool=(tpool_t*)malloc(sizeof(tpool_t));
  proc_rxtx->respEncode=(notifiedFIFO_t*) malloc(sizeof(notifiedFIFO_t));
  proc_rxtx->respDecode=(notifiedFIFO_t*) malloc(sizeof(notifiedFIFO_t));
  initTpool("n",proc_rxtx->threadPool, true);
  initNotifiedFIFO(proc_rxtx->respEncode);
  initNotifiedFIFO(proc_rxtx->respDecode);
815

816
  printf("Init UL hopping UE\n");
817
  init_ul_hopping(&UE->frame_parms);
818
  printf("Init UL hopping eNB\n");
819
  init_ul_hopping(&eNB->frame_parms);
820
  UE->dlsch[subframe&1][0][0]->harq_ack[ul_subframe2pdcch_alloc_subframe(&eNB->frame_parms,subframe)].send_harq_status = 1;
821 822
  UE->ulsch_Msg3_active[eNB_id] = 0;
  UE->ul_power_control_dedicated[eNB_id].accumulationEnabled=1;
823 824
  coded_bits_per_codeword = nb_rb * (12 * get_Qm_ul(mcs)) * nsymb;

825
  if (cqi_flag == 1) coded_bits_per_codeword-=UE->ulsch[0]->O;
826 827

  rate = (double)dlsch_tbs25[get_I_TBS(mcs)][nb_rb-1]/(coded_bits_per_codeword);
828
  printf("Rate = %f (mod %d), coded bits %u\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword);
829

830
  for (ch_realization=0; ch_realization<n_ch_rlz; ch_realization++) {
831 832 833 834 835 836
    /*
      if(abstx){
      int ulchestim_f[300*12];
      int ulchestim_t[2*(frame_parms->ofdm_symbol_size)];
      }
    */
837
    if(abstx) {
838 839 840
      printf("**********************Channel Realization Index = %d **************************\n", ch_realization);
      saving_bler=1;
    }
841

Raymond Knopp's avatar
 
Raymond Knopp committed
842
    //    if ((subframe>5) || (subframe < 4))
843
    //      UE->frame++;
844 845

    for (SNR=snr0; SNR<snr1; SNR+=input_snr_step) {
846 847 848 849 850 851 852 853 854 855 856 857 858 859
      errs[0]=0;
      errs[1]=0;
      errs[2]=0;
      errs[3]=0;
      round_trials[0] = 0;
      round_trials[1] = 0;
      round_trials[2] = 0;
      round_trials[3] = 0;
      cqi_errors=0;
      ack_errors=0;
      cqi_crc_falsepositives=0;
      cqi_crc_falsenegatives=0;
      round=0;
      //randominit(0);
860
      harq_pid = subframe2harq_pid(&UE->frame_parms,proc_rxtx_ue->frame_tx,subframe);
861
      input_buffer_length = UE->ulsch[0]->harq_processes[harq_pid]->TBS/8;
laurent's avatar
laurent committed
862 863 864 865

      if ( input_buffer != NULL )
        free(input_buffer);

866
      input_buffer = (unsigned char *)memalign(32,input_buffer_length+64);
laurent's avatar
laurent committed
867

868
      //      printf("UL frame %d/subframe %d, harq_pid %d\n",UE->frame,subframe,harq_pid);
869
      if (input_fdUL == NULL) {
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
        if (n_frames == 1) {
          trch_out_fdUL= fopen("ulsch_trchUL.txt","w");

          for (i=0; i<input_buffer_length; i++) {
            input_buffer[i] = taus()&0xff;

            for (j=0; j<8; j++)
              fprintf(trch_out_fdUL,"%d\n",(input_buffer[i]>>(7-j))&1);
          }

          fclose(trch_out_fdUL);
        } else {
          for (i=0; i<input_buffer_length; i++)
            input_buffer[i] = taus()&0xff;
        }
      } else {
        n_frames=1;
        i=0;

        while (!feof(input_fdUL)) {
890
          ret=fscanf(input_fdUL,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2);
laurent's avatar
laurent committed
891

892
          if (ret != 2) printf("ERROR: error reading file\n");
893 894

          if ((i%4)==0) {
laurent's avatar
laurent committed
895 896
            ((short *)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
            ((short *)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));
897 898

            if ((i/4)<100)
laurent's avatar
laurent committed
899
              printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short *)txdata[0])[i/4],((short *)txdata[0])[(i/4)+1]); //1,input_val2,);
900 901 902 903 904 905 906 907 908
          }

          i++;

          if (i>(FRAME_LENGTH_SAMPLES))
            break;
        }

        printf("Read in %d samples\n",i/4);
bruno mongazon's avatar
bruno mongazon committed
909 910
        //      LOG_M("txsig0UL.m","txs0", txdata[0],2*frame_parms->samples_per_tti,1,1);
        //    LOG_M("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
911 912 913
        tx_lev = signal_energy(&txdata[0][0],
                               OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
        tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
914 915
      }

916
      iter_trials=0;
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
      reset_meas(&UE->phy_proc_tx);
      reset_meas(&UE->ofdm_mod_stats);
      reset_meas(&UE->ulsch_modulation_stats);
      reset_meas(&UE->ulsch_encoding_stats);
      reset_meas(&UE->ulsch_interleaving_stats);
      reset_meas(&UE->ulsch_rate_matching_stats);
      reset_meas(&UE->ulsch_turbo_encoding_stats);
      reset_meas(&UE->ulsch_segmentation_stats);
      reset_meas(&UE->ulsch_multiplexing_stats);
      reset_meas(&eNB->phy_proc_rx);
      reset_meas(&eNB->ulsch_channel_estimation_stats);
      reset_meas(&eNB->ulsch_freq_offset_estimation_stats);
      reset_meas(&eNB->rx_dft_stats);
      reset_meas(&eNB->ulsch_decoding_stats);
      reset_meas(&eNB->ulsch_turbo_decoding_stats);
      reset_meas(&eNB->ulsch_deinterleaving_stats);
      reset_meas(&eNB->ulsch_demultiplexing_stats);
      reset_meas(&eNB->ulsch_rate_unmatching_stats);
laurent's avatar
laurent committed
935
      reset_meas(&eNB->ulsch_demodulation_stats);
936 937 938 939 940 941 942
      reset_meas(&eNB->ulsch_tc_init_stats);
      reset_meas(&eNB->ulsch_tc_alpha_stats);
      reset_meas(&eNB->ulsch_tc_beta_stats);
      reset_meas(&eNB->ulsch_tc_gamma_stats);
      reset_meas(&eNB->ulsch_tc_ext_stats);
      reset_meas(&eNB->ulsch_tc_intl1_stats);
      reset_meas(&eNB->ulsch_tc_intl2_stats);
Cedric Roux's avatar
Cedric Roux committed
943
      // initialization
laurent's avatar
laurent committed
944 945 946 947 948 949 950 951
      varArray_t *table_tx=initVarArray(1000,sizeof(double));
      varArray_t *table_tx_ifft=initVarArray(1000,sizeof(double));
      varArray_t *table_tx_mod=initVarArray(1000,sizeof(double));
      varArray_t *table_tx_enc=initVarArray(1000,sizeof(double));
      varArray_t *table_rx=initVarArray(1000,sizeof(double));
      varArray_t *table_rx_fft=initVarArray(1000,sizeof(double));
      varArray_t *table_rx_demod=initVarArray(1000,sizeof(double));
      varArray_t *table_rx_dec=initVarArray(1000,sizeof(double));
952
      ndi=0;
953
      phy_reset_ue(0,0,0);
954
      UE->UE_mode[eNB_id]=PUSCH;
laurent's avatar
laurent committed
955
      SET_LOG_DEBUG(UE_TIMING);
956

957 958
      for (trials = 0; trials<n_frames; trials++) {
        //      printf("*");
959 960
        //        UE->frame++;
        //        eNB->frame++;
laurent's avatar
laurent committed
961
        ndi = (1-ndi);
962 963 964 965
        fflush(stdout);
        round=0;

        while (round < 4) {
laurent's avatar
laurent committed
966 967 968 969 970 971 972 973
          proc_rxtx->frame_rx=1;
          proc_rxtx->subframe_rx=subframe;
          proc_rxtx->frame_tx=pdcch_alloc2ul_frame(&eNB->frame_parms,1,subframe);
          proc_rxtx->subframe_tx=pdcch_alloc2ul_subframe(&eNB->frame_parms,subframe);
          proc_rxtx_ue->frame_tx = proc_rxtx->frame_rx;
          proc_rxtx_ue->frame_rx = (subframe<4)?(proc_rxtx->frame_tx-1):(proc_rxtx->frame_tx);
          proc_rxtx_ue->subframe_tx = proc_rxtx->subframe_rx;
          proc_rxtx_ue->subframe_rx = (proc_rxtx->subframe_tx+6)%10;
974 975
          eNB->ulsch[0]->harq_processes[harq_pid]->round=round;
          UE->ulsch[0]->harq_processes[harq_pid]->round=round;
976

977
          if (n_frames==1) printf("filling ulsch: Trial %u : Round %d (subframe %d, frame %d)\n",trials,round,proc_rxtx_ue->subframe_tx,proc_rxtx_ue->frame_tx);
978

laurent's avatar
laurent committed
979 980
          round_trials[round]++;
          UL_req.sfn_sf = (1<<4)+subframe;
Cedric Roux's avatar
Cedric Roux committed
981

laurent's avatar
laurent committed
982
          if (n_frames==1) printf("filling ulsch: eNB prog frame %d, subframe %d (%d,%d)\n",proc_rxtx->frame_rx,subframe,sched_resp.frame,sched_resp.subframe);
983

laurent's avatar
laurent committed
984
          int modulation_type;
985

laurent's avatar
laurent committed
986 987 988 989 990 991 992
          if (mcs < 11)      modulation_type = 2;
          else if (mcs < 21) modulation_type = 4;
          else if (mcs < 29) modulation_type = 6;
          else {
            LOG_E(SIM,"mcs %i is not valid\n",mcs);
            exit(-1);
          }
993

laurent's avatar
laurent committed
994 995 996 997 998 999
          fill_ulsch_dci(eNB, proc_rxtx->frame_rx, subframe, &sched_resp, 14,
                         (void *)&UL_alloc_pdu, first_rb,nb_rb, (round==0)?mcs:(28+rvidx[round]),
                         modulation_type, ndi, get_TBS_UL(mcs,nb_rb), cqi_flag, beta_CQI,
                         beta_RI, cqi_size);
          UE->ulsch_Msg3_active[eNB_id] = 0;
          UE->ul_power_control_dedicated[eNB_id].accumulationEnabled=1;
1000

laurent's avatar
laurent committed
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
          if (n_frames==1)
            printf("filling ulsch: ue prog SFN/SF %d/%d\n",proc_rxtx_ue->frame_rx,proc_rxtx_ue->subframe_rx);

          generate_ue_ulsch_params_from_dci((void *)&UL_alloc_pdu,
                                            14,
                                            (subframe+6)%10,
                                            format0,
                                            UE,
                                            proc_rxtx_ue,
                                            SI_RNTI,
                                            0,
                                            P_RNTI,
                                            CBA_RNTI,
                                            0,
                                            srs_flag);
          sched_resp.subframe=(subframe+6)%10;
          sched_resp.frame=(1024+eNB->proc.frame_rx+((subframe<4)?-1:0))&1023;
1018
          schedule_response(&sched_resp, proc_rxtx);
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

          /////////////////////
          if (abstx) {
            if (trials==0 && round==0 && SNR==snr0) { //generate a new channel
              hold_channel = 0;
              flagMag=0;
            } else {
              hold_channel = 1;
              flagMag = 1;
            }
          } else {
            hold_channel = 0;
            flagMag=1;
          }

          ///////////////////////////////////////

          if (input_fdUL == NULL) {
laurent's avatar
laurent committed
1037 1038 1039
            eNB->proc.frame_rx = 1;
            eNB->proc.subframe_rx = subframe;
            ru->proc.frame_rx = 1;
1040
            ru->proc.tti_rx = subframe;
laurent's avatar
laurent committed
1041 1042 1043 1044 1045 1046 1047
            proc_rxtx_ue->frame_tx = proc_rxtx->frame_rx;
            proc_rxtx_ue->frame_rx = proc_rxtx->frame_tx;
            proc_rxtx_ue->subframe_tx = proc_rxtx->subframe_rx;
            proc_rxtx_ue->subframe_rx = proc_rxtx->subframe_tx;
            phy_procedures_UE_TX(UE,proc_rxtx_ue,0,0,normal_txrx);
            tx_lev = signal_energy(&UE->common_vars.txdata[0][eNB->frame_parms.samples_per_tti*subframe],
                                   eNB->frame_parms.samples_per_tti);
Cedric Roux's avatar
Cedric Roux committed
1048

1049
            if (n_frames==1) {
bruno mongazon's avatar
bruno mongazon committed
1050
              LOG_M("txsigF0UL.m","txsF0", &UE->common_vars.txdataF[0][eNB->frame_parms.ofdm_symbol_size*nsymb*subframe],eNB->frame_parms.ofdm_symbol_size*nsymb,1,
laurent's avatar
laurent committed
1051
                    1);
bruno mongazon's avatar
bruno mongazon committed
1052
              //LOG_M("txsigF1.m","txsF1", UE->common_vars.txdataF[0],FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX,1,1);
1053
            }
laurent's avatar
laurent committed
1054
          }  // input_fd == NULL
Cedric Roux's avatar
Cedric Roux committed
1055

1056 1057 1058
          tx_lev_dB = (unsigned int) dB_fixed_times10(tx_lev);

          if (n_frames==1) {
bruno mongazon's avatar
bruno mongazon committed
1059 1060
            LOG_M("txsig0UL.m","txs0", &txdata[0][eNB->frame_parms.samples_per_tti*subframe],2*frame_parms->samples_per_tti,1,1);
            //        LOG_M("txsig1UL.m","txs1", &txdata[1][eNB->frame_parms.samples_per_tti*subframe],2*frame_parms->samples_per_tti,1,1);
1061 1062 1063 1064
          }

          //AWGN
          //Set target wideband RX noise level to N0
1065
          sigma2_dB = N0;//-10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12));//10*log10((double)tx_lev)  +10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12)) - SNR;
1066 1067
          sigma2 = pow(10,sigma2_dB/10);
          // compute tx_gain to achieve target SNR (per resource element!)
frtabu's avatar
frtabu committed
1068
          tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);// *(nb_rb*12/(double)UE->frame_parms.ofdm_symbol_size)/(double)tx_lev);
1069

laurent's avatar
laurent committed
1070
          if (n_frames==1)
1071
            printf("tx_lev = %u (%u.%u dB,%f), gain %f\n",tx_lev,tx_lev_dB/10,tx_lev_dB,10*log10((double)tx_lev),10*log10(tx_gain));
1072 1073 1074

          // fill measurement symbol (19) with noise
          for (i=0; i<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
1075
            for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
laurent's avatar
laurent committed
1076 1077
              ((short *) &ru->common.rxdata[aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
              ((short *) &ru->common.rxdata[aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
1078 1079 1080 1081 1082
            }
          }

          // multipath channel

1083
          for (i=0; i<eNB->frame_parms.samples_per_tti; i++) {
1084
            for (aa=0; aa<1; aa++) {
1085 1086
              s_re[aa][i] = ((double)(((short *)&UE->common_vars.txdata[aa][eNB->frame_parms.samples_per_tti*subframe]))[(i<<1)]);
              s_im[aa][i] = ((double)(((short *)&UE->common_vars.txdata[aa][eNB->frame_parms.samples_per_tti*subframe]))[(i<<1)+1]);
1087 1088 1089 1090 1091 1092
            }
          }

          if (awgn_flag == 0) {
            if (UE2eNB->max_Doppler == 0) {
              multipath_channel(UE2eNB,s_re,s_im,r_re,r_im,
1093
                                eNB->frame_parms.samples_per_tti,hold_channel,0);
1094 1095
            } else {
              multipath_tv_channel(UE2eNB,s_re,s_im,r_re,r_im,
1096
                                   2*eNB->frame_parms.samples_per_tti,hold_channel);
1097 1098 1099 1100 1101 1102 1103 1104 1105
            }
          }

          if(abstx) {
            if(saving_bler==0)
              if (trials==0 && round==0) {
                // calculate freq domain representation to compute SINR
                freq_channel(UE2eNB, N_RB_DL,12*N_RB_DL + 1);
                // snr=pow(10.0,.1*SNR);
1106
                fprintf(csv_fdUL,"%f,%u,%u,%f,%f,%f,",SNR,tx_lev,tx_lev_dB,sigma2_dB,tx_gain,SNR2);
1107 1108 1109 1110 1111 1112 1113 1114

                //fprintf(csv_fdUL,"%f,",SNR);
                for (u=0; u<12*nb_rb; u++) {
                  for (aarx=0; aarx<UE2eNB->nb_rx; aarx++) {
                    for (aatx=0; aatx<UE2eNB->nb_tx; aatx++) {
                      // abs_channel = (eNB2UE->chF[aarx+(aatx*eNB2UE->nb_rx)][u].x*eNB2UE->chF[aarx+(aatx*eNB2UE->nb_rx)][u].x + eNB2UE->chF[aarx+(aatx*eNB2UE->nb_rx)][u].y*eNB2UE->chF[aarx+(aatx*eNB2UE->nb_rx)][u].y);
                      channelx = UE2eNB->chF[aarx+(aatx*UE2eNB->nb_rx)][u].x;
                      channely = UE2eNB->chF[aarx+(aatx*UE2eNB->nb_rx)][u].y;
laurent's avatar
laurent committed
1115
                      // if(transmission_m==5){
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
                      fprintf(csv_fdUL,"%e+i*(%e),",channelx,channely);
                      // }
                      // else{
                      //  pilot_sinr = 10*log10(snr*abs_channel);
                      //  fprintf(csv_fd,"%e,",pilot_sinr);
                      // }
                    }
                  }
                }
              }
          }

          if (n_frames==1)
            printf("Sigma2 %f (sigma2_dB %f), tx_gain %f (%f dB)\n",sigma2,sigma2_dB,tx_gain,20*log10(tx_gain));

1131 1132
          for (i=0; i<eNB->frame_parms.samples_per_tti; i++) {
            for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
laurent's avatar
laurent committed
1133 1134 1135 1136 1137
              ((short *) &ru->common.rxdata[aa][eNB->frame_parms.samples_per_tti*subframe])[2*i] =
                (short) ((tx_gain*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0));
              ((short *) &ru->common.rxdata[aa][eNB->frame_parms.samples_per_tti*subframe])[2*i+1] =
                (short) ((tx_gain*r_im[aa][i]) + (iqim*tx_gain*r_re[aa][i]) +
                         sqrt(sigma2/2)*gaussdouble(0.0,1.0));
1138 1139 1140
            }
          }

1141
          if (n_frames<=10) {
laurent's avatar
laurent committed
1142 1143 1144 1145 1146 1147
            printf("rx_level Null symbol %f\n",10*log10((double)signal_energy((int *)
                   &ru->common.rxdata[0][(eNB->frame_parms.samples_per_tti<<1) -
                                         eNB->frame_parms.ofdm_symbol_size],OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES/2)));
            printf("rx_level data symbol %f\n",
                   10*log10(signal_energy((int *)&ru->common.rxdata[0][160+(eNB->frame_parms.samples_per_tti*subframe)],
                                          OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES/2)));
1148 1149
          }

laurent's avatar
laurent committed
1150 1151
          SNRmeas = 10*log10(((double)signal_energy((int *)&ru->common.rxdata[0][160+(eNB->frame_parms.samples_per_tti*subframe)],
                              OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES/2))/((double)signal_energy((int *)
1152
                                  &ru->common.rxdata[0][(eNB->frame_parms.samples_per_tti<<1) -eNB->frame_parms.ofdm_symbol_size],
1153
                                  OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES/2)) - 1)+10*log10(eNB->frame_parms.N_RB_UL/nb_rb);
1154

1155
          if (n_frames<=10) {
1156
            printf("SNRmeas %f\n",SNRmeas);
laurent's avatar
laurent committed
1157
            LOG_M("rxsig0UL.m","rxs0", &ru->common.rxdata[0][eNB->frame_parms.samples_per_tti*subframe],eNB->frame_parms.samples_per_tti,1,1);
1158

laurent's avatar
laurent committed
1159
            if (eNB->frame_parms.nb_antennas_rx>1) LOG_M("rxsig1UL.m","rxs1", &ru->common.rxdata[1][eNB->frame_parms.samples_per_tti*subframe],eNB->frame_parms.samples_per_tti,1,1);
1160 1161
          }

frtabu's avatar
frtabu committed
1162
          start_meas(&eNB->phy_proc_rx);
laurent's avatar
laurent committed
1163
          ru->feprx = (get_thread_worker_conf() == WORKER_ENABLE) ? ru_fep_full_2thread        : fep_full;
1164
          ru->feprx(ru,subframe);
laurent's avatar
laurent committed
1165
          phy_procedures_eNB_uespec_RX(eNB,proc_rxtx);
frtabu's avatar
frtabu committed
1166 1167
          stop_meas(&eNB->phy_proc_rx);

1168 1169 1170
          if (cqi_flag > 0) {
            cqi_error = 0;

1171
            if (eNB->ulsch[0]->harq_processes[harq_pid]->Or1 < 32) {
1172
              for (i=2; i<4; i++) {
1173 1174
                //                printf("cqi %d : %d (%d)\n",i,eNB->ulsch[0]->o[i],UE->ulsch[0]->o[i]);
                if (eNB->ulsch[0]->harq_processes[harq_pid]->o[i] != UE->ulsch[0]->o[i])
1175 1176 1177 1178 1179 1180 1181 1182
                  cqi_error = 1;
              }
            } else {
            }

            if (cqi_error == 1) {
              cqi_errors++;

1183
              if (eNB->ulsch[0]->harq_processes[harq_pid]->cqi_crc_status == 1)
1184 1185
                cqi_crc_falsepositives++;
            } else {
1186
              if (eNB->ulsch[0]->harq_processes[harq_pid]->cqi_crc_status == 0)
1187 1188 1189 1190
                cqi_crc_falsenegatives++;
            }
          }

1191
          if (eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0] != UE->ulsch[0]->o_ACK[0])
1192 1193
            ack_errors++;

1194
          //    printf("ulsch_coding: O[%d] %d\n",i,o_flip[i]);
laurent's avatar
laurent committed
1195 1196
          //          if (ret <= eNB->ulsch[0]->max_turbo_iterations) {
          iter_trials++;
1197

laurent's avatar
laurent committed
1198
          if (eNB->ulsch[0]->harq_processes[harq_pid]->status == SCH_IDLE) {
1199
            if (n_frames==1) {
1200
              printf("No ULSCH errors found, o_ACK[0]= %d, cqi_crc_status=%d\n",eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0],eNB->ulsch[0]->harq_processes[harq_pid]->cqi_crc_status);
1201

1202 1203 1204
              if (eNB->ulsch[0]->harq_processes[harq_pid]->cqi_crc_status==1)
                print_CQI(eNB->ulsch[0]->harq_processes[harq_pid]->o,
                          eNB->ulsch[0]->harq_processes[harq_pid]->uci_format,0,eNB->frame_parms.N_RB_DL);
1205

1206
              dump_ulsch(eNB,eNB->proc.frame_rx,subframe,0,round);
1207 1208 1209 1210 1211 1212 1213 1214
              exit(-1);
            }

            round=5;
          } else {
            errs[round]++;

            if (n_frames==1) {
1215
              printf("ULSCH errors found o_ACK[0]= %d\n",eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0]);
1216

1217 1218 1219
              for (s=0; s<eNB->ulsch[0]->harq_processes[harq_pid]->C; s++) {
                if (s<eNB->ulsch[0]->harq_processes[harq_pid]->Cminus)
                  Kr = eNB->ulsch[0]->harq_processes[harq_pid]->Kminus;
1220
                else
1221
                  Kr = eNB->ulsch[0]->harq_processes[harq_pid]->Kplus;
1222 1223 1224 1225 1226

                Kr_bytes = Kr>>3;
                printf("Decoded_output (Segment %d):\n",s);

                for (i=0; i<Kr_bytes; i++)
1227 1228
                  printf("%d : %x (%x)\n",i,eNB->ulsch[0]->harq_processes[harq_pid]->c[s][i],
                         eNB->ulsch[0]->harq_processes[harq_pid]->c[s][i]^UE->ulsch[0]->harq_processes[harq_pid]->c[s][i]);
1229 1230
              }

1231
              dump_ulsch(eNB,eNB->proc.frame_rx,subframe,0,round);
frtabu's avatar
frtabu committed
1232
              round=5;
1233 1234
            }

1235
            if (n_frames==1) printf("round %d errors %u/%u\n",round,errs[round],trials);
laurent's avatar
laurent committed
1236

1237 1238 1239 1240 1241
            round++;

            if (n_frames==1) {
              printf("ULSCH in error in round %d\n",round);
            }
Cedric Roux's avatar
Cedric Roux committed
1242
          }  // ulsch error
1243 1244 1245 1246 1247 1248
        } // round

        //      printf("\n");
        if ((errs[0]>=100) && (trials>(n_frames/2)))
          break;

laurent's avatar
laurent committed
1249 1250
        if (xforms==1)
          phy_scope_eNB(form_enb,eNB,0);
1251

laurent's avatar
laurent committed
1252 1253 1254 1255 1256 1257 1258 1259
        double t_tx = inMicroS(UE->phy_proc_tx.p_time);
        double t_tx_ifft = inMicroS(UE->ofdm_mod_stats.p_time);
        double t_tx_mod = inMicroS(UE->ulsch_modulation_stats.p_time);
        double t_tx_enc = inMicroS(UE->ulsch_encoding_stats.p_time);
        double t_rx = inMicroS(eNB->phy_proc_rx.p_time);
        double t_rx_fft = inMicroS(ru->ofdm_demod_stats.p_time);
        double t_rx_demod = inMicroS(eNB->ulsch_demodulation_stats.p_time);
        double t_rx_dec = inMicroS(eNB->ulsch_decoding_stats.p_time);
1260

laurent's avatar
laurent committed
1261
        if (t_tx > 2000 )// 2ms is too much time for a subframe
1262 1263
          n_tx_dropped++;

laurent's avatar
laurent committed
1264
        if (t_rx > 2000 )
1265 1266
          n_rx_dropped++;

laurent's avatar
laurent committed
1267 1268 1269 1270 1271 1272 1273 1274
        appendVarArray(table_tx, &t_tx);
        appendVarArray(table_tx_ifft, &t_tx_ifft);
        appendVarArray(table_tx_mod, &t_tx_mod );
        appendVarArray(table_tx_enc, &t_tx_enc );
        appendVarArray(table_rx, &t_rx );
        appendVarArray(table_rx_fft, &t_rx_fft );
        appendVarArray(table_rx_demod, &t_rx_demod );
        appendVarArray(table_rx_dec, &t_rx_dec );
1275
      }   //trials
1276

1277
      // sort table
laurent's avatar
laurent committed
1278 1279 1280 1281 1282 1283 1284 1285
      qsort (dataArray(table_tx), table_tx->size, table_tx->atomSize, &cmpdouble);
      qsort (dataArray(table_tx_ifft), table_tx_ifft->size, table_tx_ifft->atomSize, &cmpdouble);
      qsort (dataArray(table_tx_mod), table_tx_mod->size, table_tx_mod->atomSize, &cmpdouble);
      qsort (dataArray(table_tx_enc), table_tx_enc->size, table_tx_enc->atomSize, &cmpdouble);
      qsort (dataArray(table_rx), table_rx->size, table_rx->atomSize, &cmpdouble);
      qsort (dataArray(table_rx_fft), table_rx_fft->size, table_rx_fft->atomSize, &cmpdouble);
      qsort (dataArray(table_rx_demod), table_rx_demod->size, table_rx_demod->atomSize, &cmpdouble);
      qsort (dataArray(table_rx_dec), table_rx_dec->size, table_rx_dec->atomSize, &cmpdouble);
1286

Navid Nikaein's avatar
Navid Nikaein committed
1287
      if (dump_table == 1 ) {
1288
        set_component_filelog(SIM); // file located in /tmp/usim.txt
laurent's avatar
laurent committed
1289 1290
        LOG_UDUMPMSG(SIM,dataArray(table_tx),table_tx->size,LOG_DUMP_DOUBLE,"The transmitter raw data: \n");
        LOG_UDUMPMSG(SIM,dataArray(table_rx),table_rx->size,LOG_DUMP_DOUBLE,"The receiver raw data: \n");
1291 1292
      }

laurent's avatar
laurent committed
1293
      printf("\n**********rb: %d ***mcs : %d  *********SNR = %f dB (%f): TX %u dB (gain %f dB), N0W %f dB, I0 %u dB, delta_IF %d [ (%d,%d) dB / (%u,%u) dB ]**************************\n",
1294 1295 1296 1297
             nb_rb,mcs,SNR,SNR2,
             tx_lev_dB,
             20*log10(tx_gain),
             (double)N0,
1298
             eNB->measurements.n0_power_tot_dB,
laurent's avatar
laurent committed
1299
             get_hundred_times_delta_IF(UE,eNB_id,harq_pid),
1300 1301
             dB_fixed(eNB->pusch_vars[0]->ulsch_power[0]),
             dB_fixed(eNB->pusch_vars[0]->ulsch_power[1]),
1302 1303
             eNB->measurements.n0_power_dB[0],
             eNB->measurements.n0_power_dB[1]);
1304
      effective_rate = ((double)(round_trials[0])/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3]));
1305
      printf("Errors (%u/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e) => effective rate %f (%3.1f%%,%f,%f), normalized delay %f (%f)\n",
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
             errs[0],
             round_trials[0],
             errs[1],
             round_trials[1],
             errs[2],
             round_trials[2],
             errs[3],
             round_trials[3],
             (double)errs[0]/(round_trials[0]),
             (double)errs[1]/(round_trials[0]),
             (double)errs[2]/(round_trials[0]),
             (double)errs[3]/(round_trials[0]),
             rate*effective_rate,
             100*effective_rate,
             rate,
1321
             rate*get_Qm_ul(mcs),
1322
             (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])/
1323
             (double)eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
1324 1325
             (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));

1326
      if (cqi_flag >0) {
1327
        printf("CQI errors %d/%u,false positives %d/%u, CQI false negatives %d/%u\n",
1328 1329 1330
               cqi_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3],
               cqi_crc_falsepositives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3],
               cqi_crc_falsenegatives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]);
1331
      }
1332

1333
      if (eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0] > 0)
1334
        printf("ACK/NAK errors %d/%u\n",ack_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]);
1335

1336
      fprintf(bler_fd,"%f;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u\n",
1337 1338 1339
              SNR,
              mcs,
              nb_rb,
1340
              eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
1341 1342 1343 1344 1345 1346 1347 1348 1349
              rate,
              errs[0],
              round_trials[0],
              errs[1],
              round_trials[1],
              errs[2],
              round_trials[2],
              errs[3],
              round_trials[3]);
laurent's avatar
laurent committed
1350
      double timeBase=1/(1000*cpu_freq_GHz);
1351 1352

      if (dump_perf==1) {
1353
        printf("UE TX function statistics (per 1ms subframe)\n\n");
laurent's avatar
laurent committed
1354 1355 1356 1357 1358 1359 1360 1361 1362
        printDistribution(&UE->phy_proc_tx,table_tx,"Total PHY proc tx");
        printDistribution(&UE->ofdm_mod_stats, table_tx_ifft, "OFDM_mod time");
        printDistribution(&UE->ulsch_modulation_stats,table_tx_mod, "ULSCH modulation time");
        printDistribution(&UE->ulsch_encoding_stats,table_tx_enc, "ULSCH encoding time");
        printStatIndent(&UE->ulsch_segmentation_stats,"ULSCH segmentation time");
        printStatIndent(&UE->ulsch_turbo_encoding_stats,"ULSCH turbo encoding time");
        printStatIndent(&UE->ulsch_rate_matching_stats,"ULSCH rate-matching time");
        printStatIndent(&UE->ulsch_interleaving_stats,"ULSCH sub-block interleaving");
        printStatIndent(&UE->ulsch_multiplexing_stats,"ULSCH multiplexing time");
frtabu's avatar
frtabu committed
1363
        printf("\n");
laurent's avatar
laurent committed
1364 1365 1366
        printDistribution(&eNB->phy_proc_rx,table_rx,"Total PHY proc rx subframe");
        printDistribution(&ru->ofdm_demod_stats,table_rx_fft,"|__ OFDM_demod time");
        printDistribution(&eNB->ulsch_demodulation_stats,table_rx_demod,"|__ ULSCH demodulation time");
frtabu's avatar
frtabu committed
1367
        printDistribution(&eNB->ulsch_decoding_stats,table_rx_dec,"|__ ULSCH Decoding time");
laurent's avatar
laurent committed
1368 1369
        printf("     (%.2f Mbit/s, avg iter %.2f, max %.2f)\n",
               UE->ulsch[0]->harq_processes[harq_pid]->TBS/1000.0,
frtabu's avatar
frtabu committed
1370 1371
               (double)iter_trials,
               (double)eNB->ulsch_decoding_stats.max*timeBase);
laurent's avatar
laurent committed
1372 1373 1374
        printStatIndent2(&eNB->ulsch_deinterleaving_stats,"sub-block interleaving" );
        printStatIndent2(&eNB->ulsch_demultiplexing_stats,"sub-block demultiplexing" );
        printStatIndent2(&eNB->ulsch_rate_unmatching_stats,"sub-block rate-matching" );
laurent's avatar
laurent committed
1375
        printf("    |__ turbo_decoder(%d bits), avg iterations: %.1f       %.2f us (%d cycles, %d trials)\n",
laurent's avatar
laurent committed
1376 1377 1378 1379 1380 1381 1382
               eNB->ulsch[0]->harq_processes[harq_pid]->Cminus ?
               eNB->ulsch[0]->harq_processes[harq_pid]->Kminus :
               eNB->ulsch[0]->harq_processes[harq_pid]->Kplus,
               eNB->ulsch_tc_intl1_stats.trials/(double)eNB->ulsch_tc_init_stats.trials,
               (double)eNB->ulsch_turbo_decoding_stats.diff/eNB->ulsch_turbo_decoding_stats.trials*timeBase,
               (int)((double)eNB->ulsch_turbo_decoding_stats.diff/eNB->ulsch_turbo_decoding_stats.trials),
               eNB->ulsch_turbo_decoding_stats.trials);
laurent's avatar
laurent committed
1383 1384 1385 1386 1387 1388 1389
        printStatIndent3(&eNB->ulsch_tc_init_stats,"init");
        printStatIndent3(&eNB->ulsch_tc_alpha_stats,"alpha");
        printStatIndent3(&eNB->ulsch_tc_beta_stats,"beta");
        printStatIndent3(&eNB->ulsch_tc_gamma_stats,"gamma");
        printStatIndent3(&eNB->ulsch_tc_ext_stats,"ext");
        printStatIndent3(&eNB->ulsch_tc_intl1_stats,"turbo internal interleaver");
        printStatIndent3(&eNB->ulsch_tc_intl2_stats,"intl2+HardDecode+CRC");
1390 1391
      }

1392 1393 1394 1395 1396 1397 1398 1399 1400
      if(abstx) { //ABSTRACTION
        blerr= (double)errs[1]/(round_trials[1]);
        //printf("hata yok XX,");
        blerr = (double)errs[0]/(round_trials[0]);

        if(saving_bler==0)
          fprintf(csv_fdUL,"%e;\n",blerr);

        //    printf("hata yok XX,");
1401

1402 1403 1404
        if(blerr<1)
          saving_bler = 0;
        else saving_bler =1;
1405
      } //ABStraction
1406

1407
      if ( (test_perf != 0) && (100 * effective_rate > test_perf )) {
1408
        //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3\n");
1409
        fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;",
1410 1411
                SNR,
                mcs,
1412
                eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
                rate,
                errs[0],
                round_trials[0],
                errs[1],
                round_trials[1],
                errs[2],
                round_trials[2],
                errs[3],
                round_trials[3]);
        //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3;ND;\n");
1423
        fprintf(time_meas_fd,"%f;%d;%d;%f;%2.1f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%f;%f;",
1424 1425
                SNR,
                mcs,
1426
                eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442
                rate*effective_rate,
                100*effective_rate,
                rate,
                errs[0],
                round_trials[0],
                errs[1],
                round_trials[1],
                errs[2],
                round_trials[2],
                errs[3],
                round_trials[3],
                (double)errs[0]/(round_trials[0]),
                (double)errs[1]/(round_trials[0]),
                (double)errs[2]/(round_trials[0]),
                (double)errs[3]/(round_trials[0]),
                (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])/
1443
                (double)eNB->ulsch[0]->harq_processes[harq_pid]->TBS,
1444 1445 1446
                (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0]));
        //fprintf(time_meas_fd,"UE_PROC_TX(%d); OFDM_MOD(%d); UL_MOD(%d); UL_ENC(%d); eNB_PROC_RX(%d); OFDM_DEMOD(%d); UL_DEMOD(%d); UL_DECOD(%d);\n",
        fprintf(time_meas_fd,"%d; %d; %d; %d; %d; %d; %d; %d;",
1447 1448 1449 1450 1451
                UE->phy_proc_tx.trials,
                UE->ofdm_mod_stats.trials,
                UE->ulsch_modulation_stats.trials,
                UE->ulsch_encoding_stats.trials,
                eNB->phy_proc_rx.trials,
1452
                ru->ofdm_demod_stats.trials,
1453 1454
                eNB->ulsch_demodulation_stats.trials,
                eNB->ulsch_decoding_stats.trials
1455 1456
               );
        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%f;%f;",
1457 1458 1459 1460 1461
                get_time_meas_us(&UE->phy_proc_tx),
                get_time_meas_us(&UE->ofdm_mod_stats),
                get_time_meas_us(&UE->ulsch_modulation_stats),
                get_time_meas_us(&UE->ulsch_encoding_stats),
                get_time_meas_us(&eNB->phy_proc_rx),
1462
                get_time_meas_us(&ru->ofdm_demod_stats),
1463 1464
                get_time_meas_us(&eNB->ulsch_demodulation_stats),
                get_time_meas_us(&eNB->ulsch_decoding_stats)
1465 1466
               );
        //fprintf(time_meas_fd,"UE_PROC_TX_STD;UE_PROC_TX_MAX;UE_PROC_TX_MIN;UE_PROC_TX_MED;UE_PROC_TX_Q1;UE_PROC_TX_Q3;UE_PROC_TX_DROPPED;\n");
laurent's avatar
laurent committed
1467
        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",
frtabu's avatar
frtabu committed
1468
                squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped);
1469
        //fprintf(time_meas_fd,"IFFT;\n");
laurent's avatar
laurent committed
1470
        fprintf(time_meas_fd,"%f;%f;%f;%f;",
frtabu's avatar
frtabu committed
1471
                squareRoot(&UE->ofdm_mod_stats),
laurent's avatar
laurent committed
1472
                median(table_tx_ifft),q1(table_tx_ifft),q3(table_tx_ifft));
1473
        //fprintf(time_meas_fd,"MOD;\n");
laurent's avatar
laurent committed
1474
        fprintf(time_meas_fd,"%f;%f;%f;%f;",
frtabu's avatar
frtabu committed
1475
                squareRoot(&UE->ulsch_modulation_stats),
laurent's avatar
laurent committed
1476
                median(table_tx_mod), q1(table_tx_mod), q3(table_tx_mod));
1477
        //fprintf(time_meas_fd,"ENC;\n");
laurent's avatar
laurent committed
1478
        fprintf(time_meas_fd,"%f;%f;%f;%f;",
frtabu's avatar
frtabu committed
1479
                squareRoot(&UE->ulsch_encoding_stats),
laurent's avatar
laurent committed
1480
                median(table_tx_enc),q1(table_tx_enc),q3(table_tx_enc));
1481
        //fprintf(time_meas_fd,"eNB_PROC_RX_STD;eNB_PROC_RX_MAX;eNB_PROC_RX_MIN;eNB_PROC_RX_MED;eNB_PROC_RX_Q1;eNB_PROC_RX_Q3;eNB_PROC_RX_DROPPED;\n");
laurent's avatar
laurent committed
1482
        fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",
frtabu's avatar
frtabu committed
1483
                squareRoot(&eNB->phy_proc_rx), t_rx_max, t_rx_min,
laurent's avatar
laurent committed
1484
                median(table_rx), q1(table_rx), q3(table_rx), n_rx_dropped);
1485
        //fprintf(time_meas_fd,"FFT;\n");
laurent's avatar
laurent committed
1486
        fprintf(time_meas_fd,"%f;%f;%f;%f;",
frtabu's avatar
frtabu committed
1487
                squareRoot(&ru->ofdm_demod_stats),
laurent's avatar
laurent committed
1488
                median(table_rx_fft), q1(table_rx_fft), q3(table_rx_fft));
1489
        //fprintf(time_meas_fd,"DEMOD;\n");
laurent's avatar
laurent committed
1490
        fprintf(time_meas_fd,"%f;%f;%f;%f;",
frtabu's avatar
frtabu committed
1491
                squareRoot(&eNB->ulsch_demodulation_stats),
laurent's avatar
laurent committed
1492
                median(table_rx_demod), q1(table_rx_demod), q3(table_rx_demod));
1493
        //fprintf(time_meas_fd,"DEC;\n");
laurent's avatar
laurent committed
1494
        fprintf(time_meas_fd,"%f;%f;%f;%f\n",
frtabu's avatar
frtabu committed
1495
                squareRoot(&eNB->ulsch_decoding_stats),
laurent's avatar
laurent committed
1496
                median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec));
1497 1498 1499 1500
        printf("[passed] effective rate : %f  (%2.1f%%,%f)): log and break \n",rate*effective_rate, 100*effective_rate, rate );
        break;
      } else if (test_perf !=0 ) {
        printf("[continue] effective rate : %f  (%2.1f%%,%f)): increase snr \n",rate*effective_rate, 100*effective_rate, rate);
1501 1502
      }

1503 1504
      if (((double)errs[0]/(round_trials[0]))<1e-2)
        break;
laurent's avatar
laurent committed
1505
    } // SNR
1506 1507

    //
bruno mongazon's avatar
bruno mongazon committed
1508 1509
    //LOG_M("chestim_f.m","chestf",eNB->pusch_vars[0]->drs_ch_estimates[0][0],300*12,2,1);
    // LOG_M("chestim_t.m","chestt",eNB->pusch_vars[0]->drs_ch_estimates_time[0][0], (frame_parms->ofdm_symbol_size)*2,2,1);
1510 1511
  }//ch realization

1512
  oai_exit=1;
1513
  pthread_cond_signal(&ru->proc.cond_fep);
1514

1515
  if (abstx) { // ABSTRACTION
1516 1517 1518
    fprintf(csv_fdUL,"];");
    fclose(csv_fdUL);
  }
1519

1520
  fclose(bler_fd);
1521

1522 1523
  if (test_perf !=0)
    fclose (time_meas_fd);
1524

1525 1526
  return(0);
}
1527

1528 1529 1530 1531
/* temporary dummy implem of get_softmodem_optmask, till basic simulators implemented as device */
uint64_t get_softmodem_optmask(void) {
  return 0;
}