initial_sync.c 32.9 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.0  (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 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*! \file PHY/LTE_TRANSPORT/initial_sync.c
* \brief Routines for initial UE synchronization procedure (PSS,SSS,PBCH and frame format detection)
* \author R. Knopp, F. Kaltenberger
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr,kaltenberger@eurecom.fr
* \note
* \warning
*/
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"
#include "defs.h"
#include "extern.h"
39

40

41 42
#include "common_lib.h"
extern openair0_config_t openair0_cfg[];
43

44
//#define DEBUG_INITIAL_SYNCH
45

46
int pbch_detection(PHY_VARS_UE *ue, runmode_t mode)
47
{
48

49 50 51
  uint8_t l,pbch_decoded,frame_mod4,pbch_tx_ant,dummy;
  LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
  char phich_resource[6];
52

53
#ifdef DEBUG_INITIAL_SYNCH
54 55
  LOG_I(PHY,"[UE%d] Initial sync: starting PBCH detection (rx_offset %d)\n",ue->Mod_id,
        ue->rx_offset);
56 57
#endif

58 59
  for (l=0; l<frame_parms->symbols_per_tti/2; l++) {

60
    slot_fep(ue,
61 62
	     l,
	     0,
63
	     ue->rx_offset,
64 65
	     0,
	     1);
66
  }
67
  for (l=0; l<frame_parms->symbols_per_tti/2; l++) {
68

69
    slot_fep(ue,
70 71
	     l,
	     1,
72
	     ue->rx_offset,
73 74
	     0,
	     1);
75
  }
76
  slot_fep(ue,
77 78
	   0,
	   2,
79
	   ue->rx_offset,
80 81
	   0,
	   1);
82

83 84
  lte_ue_measurements(ue,
		      ue->rx_offset,
85
		      0,
86 87 88 89 90
                      0,
		      0,
                      0);


91 92
  if (ue->frame_parms.frame_type == TDD) {
    ue_rrc_measurements(ue,
93
			2,
94 95 96
			0);
  }
  else {
97
    ue_rrc_measurements(ue,
98 99 100
			0,
			0);
  }
101
#ifdef DEBUG_INITIAL_SYNCH
102
  LOG_I(PHY,"[UE %d] RX RSSI %d dBm, digital (%d, %d) dB, linear (%d, %d), avg rx power %d dB (%d lin), RX gain %d dB\n",
103 104 105 106 107 108 109 110 111
        ue->Mod_id,
        ue->measurements.rx_rssi_dBm[0] - ((ue->frame_parms.nb_antennas_rx==2) ? 3 : 0),
        ue->measurements.rx_power_dB[0][0],
        ue->measurements.rx_power_dB[0][1],
        ue->measurements.rx_power[0][0],
        ue->measurements.rx_power[0][1],
        ue->measurements.rx_power_avg_dB[0],
        ue->measurements.rx_power_avg[0],
        ue->rx_total_gain_dB);
112

113
  LOG_I(PHY,"[UE %d] N0 %d dBm digital (%d, %d) dB, linear (%d, %d), avg noise power %d dB (%d lin)\n",
114 115 116 117 118 119 120 121
        ue->Mod_id,
        ue->measurements.n0_power_tot_dBm,
        ue->measurements.n0_power_dB[0],
        ue->measurements.n0_power_dB[1],
        ue->measurements.n0_power[0],
        ue->measurements.n0_power[1],
        ue->measurements.n0_power_avg_dB,
        ue->measurements.n0_power_avg);
122
#endif
123

124
  pbch_decoded = 0;
125 126

  for (frame_mod4=0; frame_mod4<4; frame_mod4++) {
127 128
    pbch_tx_ant = rx_pbch(&ue->common_vars,
                          ue->pbch_vars[0],
129 130 131
                          frame_parms,
                          0,
                          SISO,
132
                          ue->high_speed_flag,
133 134
                          frame_mod4);

135 136 137 138
    if ((pbch_tx_ant>0) && (pbch_tx_ant<=2)) {
      pbch_decoded = 1;
      break;
    }
139

140 141
    pbch_tx_ant = rx_pbch(&ue->common_vars,
                          ue->pbch_vars[0],
142 143 144
                          frame_parms,
                          0,
                          ALAMOUTI,
145
                          ue->high_speed_flag,
146 147
                          frame_mod4);

148 149 150 151 152
    if ((pbch_tx_ant>0) && (pbch_tx_ant<=2)) {
      pbch_decoded = 1;
      break;
    }
  }
153 154


155
  if (pbch_decoded) {
156

Xiwen JIANG's avatar
Xiwen JIANG committed
157
    frame_parms->nb_antenna_ports_eNB = pbch_tx_ant;
158

159 160 161
    // set initial transmission mode to 1 or 2 depending on number of detected TX antennas
    frame_parms->mode1_flag = (pbch_tx_ant==1);
    // openair_daq_vars.dlsch_transmission_mode = (pbch_tx_ant>1) ? 2 : 1;
162

163 164

    // flip byte endian on 24-bits for MIB
165 166 167
    //    dummy = ue->pbch_vars[0]->decoded_output[0];
    //    ue->pbch_vars[0]->decoded_output[0] = ue->pbch_vars[0]->decoded_output[2];
    //    ue->pbch_vars[0]->decoded_output[2] = dummy;
168 169

    // now check for Bandwidth of Cell
170
    dummy = (ue->pbch_vars[0]->decoded_output[2]>>5)&7;
171

172
    switch (dummy) {
173 174

    case 0 :
175 176
      frame_parms->N_RB_DL = 6;
      break;
177 178

    case 1 :
179 180
      frame_parms->N_RB_DL = 15;
      break;
181 182

    case 2 :
183 184
      frame_parms->N_RB_DL = 25;
      break;
185 186

    case 3 :
187 188
      frame_parms->N_RB_DL = 50;
      break;
189 190

    case 4 :
191 192
      frame_parms->N_RB_DL = 75;
      break;
193

194 195 196
    case 5:
      frame_parms->N_RB_DL = 100;
      break;
197

198
    default:
199
      LOG_E(PHY,"[UE%d] Initial sync: PBCH decoding: Unknown N_RB_DL\n",ue->Mod_id);
200 201 202
      return -1;
      break;
    }
203

204

lfarizav's avatar
lfarizav committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    // now check for PHICH parameters
    frame_parms->phich_config_common.phich_duration = (PHICH_DURATION_t)((ue->pbch_vars[0]->decoded_output[2]>>4)&1);
    dummy = (ue->pbch_vars[0]->decoded_output[2]>>2)&3;

    switch (dummy) {
    case 0:
      frame_parms->phich_config_common.phich_resource = oneSixth;
      sprintf(phich_resource,"1/6");
      break;

    case 1:
      frame_parms->phich_config_common.phich_resource = half;
      sprintf(phich_resource,"1/2");
      break;

    case 2:
      frame_parms->phich_config_common.phich_resource = one;
      sprintf(phich_resource,"1");
      break;

    case 3:
      frame_parms->phich_config_common.phich_resource = two;
      sprintf(phich_resource,"2");
      break;

    default:
      LOG_E(PHY,"[UE%d] Initial sync: Unknown PHICH_DURATION\n",ue->Mod_id);
      return -1;
      break;
    }

    for(int i=0; i<RX_NB_TH;i++)
    {
        ue->proc.proc_rxtx[i].frame_rx =   (((ue->pbch_vars[0]->decoded_output[2]&3)<<6) + (ue->pbch_vars[0]->decoded_output[1]>>2))<<2;
        ue->proc.proc_rxtx[i].frame_rx =   (((ue->pbch_vars[0]->decoded_output[2]&3)<<6) + (ue->pbch_vars[0]->decoded_output[1]>>2))<<2;

#ifndef USER_MODE
        // one frame delay
        ue->proc.proc_rxtx[i].frame_rx ++;
#endif
        ue->proc.proc_rxtx[i].frame_tx = ue->proc.proc_rxtx[0].frame_rx;
    }
#ifdef DEBUG_INITIAL_SYNCH
    LOG_I(PHY,"[UE%d] Initial sync: pbch decoded sucessfully mode1_flag %d, tx_ant %d, frame %d, N_RB_DL %d, phich_duration %d, phich_resource %s!\n",
          ue->Mod_id,
          frame_parms->mode1_flag,
          pbch_tx_ant,
          ue->proc.proc_rxtx[0].frame_rx,
          frame_parms->N_RB_DL,
          frame_parms->phich_config_common.phich_duration,
          phich_resource);  //frame_parms->phich_config_common.phich_resource);
#endif
    return(0);
  } else {
    return(-1);
  }

}
int pbch_detection_freq(PHY_VARS_UE *ue, runmode_t mode)
{

  uint8_t l,pbch_decoded,frame_mod4,pbch_tx_ant,dummy;
  LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
  char phich_resource[6];

#ifdef DEBUG_INITIAL_SYNCH
  LOG_I(PHY,"[UE%d] Initial sync: starting PBCH detection (rx_offset %d)\n",ue->Mod_id,
        ue->rx_offset);
#endif

  for (l=0; l<frame_parms->symbols_per_tti/2; l++) {

    slot_fep_freq(ue,
	     l,
	     0,
	     ue->rx_offset,
	     0,
	     1);
  }
  for (l=0; l<frame_parms->symbols_per_tti/2; l++) {

    slot_fep_freq(ue,
	     l,
	     1,
	     ue->rx_offset,
	     0,
	     1);
  }
  slot_fep_freq(ue,
	   0,
	   2,
	   ue->rx_offset,
	   0,
	   1);

  lte_ue_measurements(ue,
		      ue->rx_offset,
		      0,
                      0,
		      0,
                      0);


  if (ue->frame_parms.frame_type == TDD) {
    ue_rrc_measurements_freq(ue,
			2,
			0);
  }
  else {
    ue_rrc_measurements_freq(ue,
			0,
			0);
  }
#ifdef DEBUG_INITIAL_SYNCH
  LOG_I(PHY,"[UE %d] RX RSSI %d dBm, digital (%d, %d) dB, linear (%d, %d), avg rx power %d dB (%d lin), RX gain %d dB\n",
        ue->Mod_id,
        ue->measurements.rx_rssi_dBm[0] - ((ue->frame_parms.nb_antennas_rx==2) ? 3 : 0),
        ue->measurements.rx_power_dB[0][0],
        ue->measurements.rx_power_dB[0][1],
        ue->measurements.rx_power[0][0],
        ue->measurements.rx_power[0][1],
        ue->measurements.rx_power_avg_dB[0],
        ue->measurements.rx_power_avg[0],
        ue->rx_total_gain_dB);

  LOG_I(PHY,"[UE %d] N0 %d dBm digital (%d, %d) dB, linear (%d, %d), avg noise power %d dB (%d lin)\n",
        ue->Mod_id,
        ue->measurements.n0_power_tot_dBm,
        ue->measurements.n0_power_dB[0],
        ue->measurements.n0_power_dB[1],
        ue->measurements.n0_power[0],
        ue->measurements.n0_power[1],
        ue->measurements.n0_power_avg_dB,
        ue->measurements.n0_power_avg);
#endif

  pbch_decoded = 0;

  for (frame_mod4=0; frame_mod4<4; frame_mod4++) {
    pbch_tx_ant = rx_pbch(&ue->common_vars,
                          ue->pbch_vars[0],
                          frame_parms,
                          0,
                          SISO,
                          ue->high_speed_flag,
                          frame_mod4);

    if ((pbch_tx_ant>0) && (pbch_tx_ant<=2)) {
      pbch_decoded = 1;
      break;
    }

    pbch_tx_ant = rx_pbch(&ue->common_vars,
                          ue->pbch_vars[0],
                          frame_parms,
                          0,
                          ALAMOUTI,
                          ue->high_speed_flag,
                          frame_mod4);

    if ((pbch_tx_ant>0) && (pbch_tx_ant<=2)) {
      pbch_decoded = 1;
      break;
    }
  }


  if (pbch_decoded) {

    frame_parms->nb_antenna_ports_eNB = pbch_tx_ant;

    // set initial transmission mode to 1 or 2 depending on number of detected TX antennas
    frame_parms->mode1_flag = (pbch_tx_ant==1);
    // openair_daq_vars.dlsch_transmission_mode = (pbch_tx_ant>1) ? 2 : 1;


    // flip byte endian on 24-bits for MIB
    //    dummy = ue->pbch_vars[0]->decoded_output[0];
    //    ue->pbch_vars[0]->decoded_output[0] = ue->pbch_vars[0]->decoded_output[2];
    //    ue->pbch_vars[0]->decoded_output[2] = dummy;

    // now check for Bandwidth of Cell
    dummy = (ue->pbch_vars[0]->decoded_output[2]>>5)&7;

    switch (dummy) {

    case 0 :
      frame_parms->N_RB_DL = 6;
      break;

    case 1 :
      frame_parms->N_RB_DL = 15;
      break;

    case 2 :
      frame_parms->N_RB_DL = 25;
      break;

    case 3 :
      frame_parms->N_RB_DL = 50;
      break;

    case 4 :
      frame_parms->N_RB_DL = 75;
      break;

    case 5:
      frame_parms->N_RB_DL = 100;
      break;

    default:
      LOG_E(PHY,"[UE%d] Initial sync: PBCH decoding: Unknown N_RB_DL\n",ue->Mod_id);
      return -1;
      break;
    }


422
    // now check for PHICH parameters
423 424
    frame_parms->phich_config_common.phich_duration = (PHICH_DURATION_t)((ue->pbch_vars[0]->decoded_output[2]>>4)&1);
    dummy = (ue->pbch_vars[0]->decoded_output[2]>>2)&3;
425

426 427 428 429 430
    switch (dummy) {
    case 0:
      frame_parms->phich_config_common.phich_resource = oneSixth;
      sprintf(phich_resource,"1/6");
      break;
431

432 433 434 435
    case 1:
      frame_parms->phich_config_common.phich_resource = half;
      sprintf(phich_resource,"1/2");
      break;
436

437 438 439 440
    case 2:
      frame_parms->phich_config_common.phich_resource = one;
      sprintf(phich_resource,"1");
      break;
441

442 443 444 445
    case 3:
      frame_parms->phich_config_common.phich_resource = two;
      sprintf(phich_resource,"2");
      break;
446

447
    default:
448
      LOG_E(PHY,"[UE%d] Initial sync: Unknown PHICH_DURATION\n",ue->Mod_id);
449 450 451
      return -1;
      break;
    }
452

453 454 455 456
    for(int i=0; i<RX_NB_TH;i++)
    {
        ue->proc.proc_rxtx[i].frame_rx =   (((ue->pbch_vars[0]->decoded_output[2]&3)<<6) + (ue->pbch_vars[0]->decoded_output[1]>>2))<<2;
        ue->proc.proc_rxtx[i].frame_rx =   (((ue->pbch_vars[0]->decoded_output[2]&3)<<6) + (ue->pbch_vars[0]->decoded_output[1]>>2))<<2;
457

458
#ifndef USER_MODE
459 460
        // one frame delay
        ue->proc.proc_rxtx[i].frame_rx ++;
461
#endif
462 463
        ue->proc.proc_rxtx[i].frame_tx = ue->proc.proc_rxtx[0].frame_rx;
    }
464 465
#ifdef DEBUG_INITIAL_SYNCH
    LOG_I(PHY,"[UE%d] Initial sync: pbch decoded sucessfully mode1_flag %d, tx_ant %d, frame %d, N_RB_DL %d, phich_duration %d, phich_resource %s!\n",
466
          ue->Mod_id,
467 468
          frame_parms->mode1_flag,
          pbch_tx_ant,
469
          ue->proc.proc_rxtx[0].frame_rx,
470 471 472
          frame_parms->N_RB_DL,
          frame_parms->phich_config_common.phich_duration,
          phich_resource);  //frame_parms->phich_config_common.phich_resource);
473 474
#endif
    return(0);
475
  } else {
476 477
    return(-1);
  }
478

479 480
}

481 482 483 484
char phich_string[13][4] = {"","1/6","","1/2","","","one","","","","","","two"};
char duplex_string[2][4] = {"FDD","TDD"};
char prefix_string[2][9] = {"NORMAL","EXTENDED"};

485
int initial_sync(PHY_VARS_UE *ue, runmode_t mode)
486 487
{

488
  int32_t sync_pos,sync_pos2,sync_pos_slot;
489 490 491 492
  int32_t metric_fdd_ncp=0,metric_fdd_ecp=0,metric_tdd_ncp=0,metric_tdd_ecp=0;
  uint8_t phase_fdd_ncp,phase_fdd_ecp,phase_tdd_ncp,phase_tdd_ecp;
  uint8_t flip_fdd_ncp,flip_fdd_ecp,flip_tdd_ncp,flip_tdd_ecp;
  //  uint16_t Nid_cell_fdd_ncp=0,Nid_cell_fdd_ecp=0,Nid_cell_tdd_ncp=0,Nid_cell_tdd_ecp=0;
493
  LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
494 495
  int ret=-1;
  int aarx,rx_power=0;
496
  /*#ifdef OAI_USRP
497
  __m128i *rxdata128;
498
  #endif*/
499 500
  //  LOG_I(PHY,"**************************************************************\n");
  // First try FDD normal prefix
Raymond Knopp's avatar
 
Raymond Knopp committed
501 502
  frame_parms->Ncp=NORMAL;
  frame_parms->frame_type=FDD;
503
  init_frame_parms(frame_parms,1);
kaltenbe's avatar
kaltenbe committed
504
  /*
505
  write_output("rxdata0.m","rxd0",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
kaltenbe's avatar
kaltenbe committed
506 507
  exit(-1);
  */
508
  sync_pos = lte_sync_time(ue->common_vars.rxdata,
509
                           frame_parms,
510
                           (int *)&ue->common_vars.eNb_id);
511

512
  //  write_output("rxdata1.m","rxd1",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
513 514 515 516 517 518
  if (sync_pos >= frame_parms->nb_prefix_samples)
    sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;
  else
    sync_pos2 = sync_pos + FRAME_LENGTH_COMPLEX_SAMPLES - frame_parms->nb_prefix_samples;

#ifdef DEBUG_INITIAL_SYNCH
519
  LOG_I(PHY,"[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n",ue->Mod_id,sync_pos,ue->common_vars.eNb_id);
520 521 522
#endif

  // SSS detection
523

524 525 526 527
  // PSS is hypothesized in last symbol of first slot in Frame
  sync_pos_slot = (frame_parms->samples_per_tti>>1) - frame_parms->ofdm_symbol_size - frame_parms->nb_prefix_samples;

  if (sync_pos2 >= sync_pos_slot)
528
    ue->rx_offset = sync_pos2 - sync_pos_slot;
529
  else
530
    ue->rx_offset = FRAME_LENGTH_COMPLEX_SAMPLES + sync_pos2 - sync_pos_slot;
531

532
  if (((sync_pos2 - sync_pos_slot) >=0 ) &&
533
      ((sync_pos2 - sync_pos_slot) < ((FRAME_LENGTH_COMPLEX_SAMPLES-frame_parms->samples_per_tti/2)))) {
534
#ifdef DEBUG_INITIAL_SYNCH
535 536
    LOG_I(PHY,"Calling sss detection (FDD normal CP)\n");
#endif
537
    rx_sss(ue,&metric_fdd_ncp,&flip_fdd_ncp,&phase_fdd_ncp);
538
    frame_parms->nushift  = frame_parms->Nid_cell%6;
539

540
    if (flip_fdd_ncp==1)
541
      ue->rx_offset += (FRAME_LENGTH_COMPLEX_SAMPLES>>1);
542

543 544 545 546
    init_frame_parms(&ue->frame_parms,1);
    lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
    ret = pbch_detection(ue,mode);
    //   write_output("rxdata2.m","rxd2",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
547 548 549

#ifdef DEBUG_INITIAL_SYNCH
    LOG_I(PHY,"FDD Normal prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
550 551 552
          frame_parms->Nid_cell,metric_fdd_ncp,phase_fdd_ncp,flip_fdd_ncp,ret);
#endif
  } else {
553
#ifdef DEBUG_INITIAL_SYNCH
554
    LOG_I(PHY,"FDD Normal prefix: SSS error condition: sync_pos %d, sync_pos_slot %d\n", sync_pos, sync_pos_slot);
555 556 557 558 559 560 561
#endif
  }


  if (ret==-1) {

    // Now FDD extended prefix
Raymond Knopp's avatar
 
Raymond Knopp committed
562 563
    frame_parms->Ncp=EXTENDED;
    frame_parms->frame_type=FDD;
564
    init_frame_parms(frame_parms,1);
565

566 567 568 569
    if (sync_pos < frame_parms->nb_prefix_samples)
      sync_pos2 = sync_pos + FRAME_LENGTH_COMPLEX_SAMPLES - frame_parms->nb_prefix_samples;
    else
      sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;
570

571 572
    // PSS is hypothesized in last symbol of first slot in Frame
    sync_pos_slot = (frame_parms->samples_per_tti>>1) - frame_parms->ofdm_symbol_size - (frame_parms->nb_prefix_samples);
573

574
    if (sync_pos2 >= sync_pos_slot)
575
      ue->rx_offset = sync_pos2 - sync_pos_slot;
576
    else
577
      ue->rx_offset = FRAME_LENGTH_COMPLEX_SAMPLES + sync_pos2 - sync_pos_slot;
578

579
    //msg("nb_prefix_samples %d, rx_offset %d\n",frame_parms->nb_prefix_samples,ue->rx_offset);
580

581 582 583
    if (((sync_pos2 - sync_pos_slot) >=0 ) &&
        ((sync_pos2 - sync_pos_slot) < ((FRAME_LENGTH_COMPLEX_SAMPLES-frame_parms->samples_per_tti/2)))) {

584
      rx_sss(ue,&metric_fdd_ecp,&flip_fdd_ecp,&phase_fdd_ecp);
585
      frame_parms->nushift  = frame_parms->Nid_cell%6;
586

587
      if (flip_fdd_ecp==1)
588
        ue->rx_offset += (FRAME_LENGTH_COMPLEX_SAMPLES>>1);
589

590 591 592 593
      init_frame_parms(&ue->frame_parms,1);
      lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
      ret = pbch_detection(ue,mode);
      //     write_output("rxdata3.m","rxd3",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
594 595
#ifdef DEBUG_INITIAL_SYNCH
      LOG_I(PHY,"FDD Extended prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
596
            frame_parms->Nid_cell,metric_fdd_ecp,phase_fdd_ecp,flip_fdd_ecp,ret);
597
#endif
598
    } else {
599
#ifdef DEBUG_INITIAL_SYNCH
600
      LOG_I(PHY,"FDD Extended prefix: SSS error condition: sync_pos %d, sync_pos_slot %d\n", sync_pos, sync_pos_slot);
601 602 603 604 605
#endif
    }

    if (ret==-1) {
      // Now TDD normal prefix
Raymond Knopp's avatar
 
Raymond Knopp committed
606 607
      frame_parms->Ncp=NORMAL;
      frame_parms->frame_type=TDD;
608 609 610
      init_frame_parms(frame_parms,1);

      if (sync_pos >= frame_parms->nb_prefix_samples)
611
        sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;
612
      else
613
        sync_pos2 = sync_pos + FRAME_LENGTH_COMPLEX_SAMPLES - frame_parms->nb_prefix_samples;
614 615

      // PSS is hypothesized in 2nd symbol of third slot in Frame (S-subframe)
616 617 618 619 620
      sync_pos_slot = frame_parms->samples_per_tti +
                      (frame_parms->ofdm_symbol_size<<1) +
                      frame_parms->nb_prefix_samples0 +
                      (frame_parms->nb_prefix_samples);

621
      if (sync_pos2 >= sync_pos_slot)
622
        ue->rx_offset = sync_pos2 - sync_pos_slot;
623
      else
624
        ue->rx_offset = (FRAME_LENGTH_COMPLEX_SAMPLES>>1) + sync_pos2 - sync_pos_slot;
625

626
      rx_sss(ue,&metric_tdd_ncp,&flip_tdd_ncp,&phase_tdd_ncp);
627 628

      if (flip_tdd_ncp==1)
629
        ue->rx_offset += (FRAME_LENGTH_COMPLEX_SAMPLES>>1);
630 631

      frame_parms->nushift  = frame_parms->Nid_cell%6;
632
      init_frame_parms(&ue->frame_parms,1);
633

634 635 636
      lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
      ret = pbch_detection(ue,mode);
      //      write_output("rxdata4.m","rxd4",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
637 638

#ifdef DEBUG_INITIAL_SYNCH
639 640
      LOG_I(PHY,"TDD Normal prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
            frame_parms->Nid_cell,metric_tdd_ncp,phase_tdd_ncp,flip_tdd_ncp,ret);
641
#endif
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

      if (ret==-1) {
        // Now TDD extended prefix
        frame_parms->Ncp=EXTENDED;
        frame_parms->frame_type=TDD;
        init_frame_parms(frame_parms,1);
        sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;

        if (sync_pos >= frame_parms->nb_prefix_samples)
          sync_pos2 = sync_pos - frame_parms->nb_prefix_samples;
        else
          sync_pos2 = sync_pos + FRAME_LENGTH_COMPLEX_SAMPLES - frame_parms->nb_prefix_samples;

        // PSS is hypothesized in 2nd symbol of third slot in Frame (S-subframe)
        sync_pos_slot = frame_parms->samples_per_tti + (frame_parms->ofdm_symbol_size<<1) + (frame_parms->nb_prefix_samples<<1);

        if (sync_pos2 >= sync_pos_slot)
659
          ue->rx_offset = sync_pos2 - sync_pos_slot;
660
        else
661
          ue->rx_offset = (FRAME_LENGTH_COMPLEX_SAMPLES>>1) + sync_pos2 - sync_pos_slot;
662

663
        rx_sss(ue,&metric_tdd_ecp,&flip_tdd_ecp,&phase_tdd_ecp);
664 665 666
        frame_parms->nushift  = frame_parms->Nid_cell%6;

        if (flip_tdd_ecp==1)
667
          ue->rx_offset += (FRAME_LENGTH_COMPLEX_SAMPLES>>1);
668

669 670 671
        init_frame_parms(&ue->frame_parms,1);
        lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
        ret = pbch_detection(ue,mode);
672

673
	//	write_output("rxdata5.m","rxd5",ue->common_vars.rxdata[0],10*frame_parms->samples_per_tti,1,1);
674
#ifdef DEBUG_INITIAL_SYNCH
675 676
        LOG_I(PHY,"TDD Extended prefix: CellId %d metric %d, phase %d, flip %d, pbch %d\n",
              frame_parms->Nid_cell,metric_tdd_ecp,phase_tdd_ecp,flip_tdd_ecp,ret);
677 678 679 680
#endif
      }
    }
  }
681

682
  /* Consider this is a false detection if the offset is > 1000 Hz */
683
  if( (abs(ue->common_vars.freq_offset) > 150) && (ret == 0) )
684 685
  {
	  ret=-1;
Cedric Roux's avatar
Cedric Roux committed
686
#if DISABLE_LOG_X
687
	  printf("Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset);
Cedric Roux's avatar
Cedric Roux committed
688 689 690
#else
	  LOG_E(HW, "Ignore MIB with high freq offset [%d Hz] estimation \n",ue->common_vars.freq_offset);
#endif
691 692
  }

693 694
  if (ret==0) {  // PBCH found so indicate sync to higher layers and configure frame parameters

695
    //#ifdef DEBUG_INITIAL_SYNCH
Cedric Roux's avatar
Cedric Roux committed
696
#if DISABLE_LOG_X
697
    printf("[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
Cedric Roux's avatar
Cedric Roux committed
698 699 700
#else
    LOG_I(PHY, "[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
#endif
701
    //#endif
702

703
    if (ue->UE_scan_carrier == 0) {
704 705 706 707 708 709 710 711 712

    #if UE_AUTOTEST_TRACE
      LOG_I(PHY,"[UE  %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n",
              ue->Mod_id,
              ue->proc.proc_rxtx[0].frame_rx,
              ue->rx_offset,
              ue->common_vars.freq_offset );
    #endif

713
// send sync status to higher layers later when timing offset converge to target timing
714
#if OAISIM
715 716
      if (ue->mac_enabled==1) {
	LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
717
	//mac_resynch();
718
	mac_xface->dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
719
	ue->UE_mode[0] = PRACH;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
720 721
      }
      else {
722
	ue->UE_mode[0] = PUSCH;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
723
      }
724
#endif
Florian Kaltenberger's avatar
Florian Kaltenberger committed
725

726 727
      generate_pcfich_reg_mapping(frame_parms);
      generate_phich_reg_mapping(frame_parms);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
728

729 730 731

      ue->pbch_vars[0]->pdu_errors_conseq=0;

732
    }
733

Cedric Roux's avatar
Cedric Roux committed
734
#if DISABLE_LOG_X
735
    printf("[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm,  rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id,
736
	  ue->proc.proc_rxtx[0].frame_rx,
737 738 739 740 741 742
	  10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB,
	  10*log10(ue->measurements.rssi),
	  ue->rx_total_gain_dB,
	  ue->measurements.n0_power_tot_dBm,
	  10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB,
	  (10*log10(ue->measurements.rsrq[0])));
743 744


Cedric Roux's avatar
Cedric Roux committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
    printf("[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
	  ue->Mod_id,
	  ue->proc.proc_rxtx[0].frame_rx,
	  duplex_string[ue->frame_parms.frame_type],
	  prefix_string[ue->frame_parms.Ncp],
	  ue->frame_parms.Nid_cell,
	  ue->frame_parms.N_RB_DL,
	  ue->frame_parms.phich_config_common.phich_duration,
	  phich_string[ue->frame_parms.phich_config_common.phich_resource],
	  ue->frame_parms.nb_antenna_ports_eNB);
#else
    LOG_I(PHY, "[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm,  rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id,
	  ue->proc.proc_rxtx[0].frame_rx,
	  10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB,
	  10*log10(ue->measurements.rssi),
	  ue->rx_total_gain_dB,
	  ue->measurements.n0_power_tot_dBm,
	  10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB,
	  (10*log10(ue->measurements.rsrq[0])));
764

Cedric Roux's avatar
Cedric Roux committed
765
    LOG_I(PHY, "[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
766
	  ue->Mod_id,
767
	  ue->proc.proc_rxtx[0].frame_rx,
768 769 770 771 772 773
	  duplex_string[ue->frame_parms.frame_type],
	  prefix_string[ue->frame_parms.Ncp],
	  ue->frame_parms.Nid_cell,
	  ue->frame_parms.N_RB_DL,
	  ue->frame_parms.phich_config_common.phich_duration,
	  phich_string[ue->frame_parms.phich_config_common.phich_resource],
774
	  ue->frame_parms.nb_antenna_ports_eNB);
Cedric Roux's avatar
Cedric Roux committed
775
#endif
776

777
#if defined(OAI_USRP) || defined(EXMIMO) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
Cedric Roux's avatar
Cedric Roux committed
778
#  if DISABLE_LOG_X
779
    printf("[UE %d] Frame %d Measured Carrier Frequency %.0f Hz (offset %d Hz)\n",
780
	  ue->Mod_id,
781
	  ue->proc.proc_rxtx[0].frame_rx,
782 783
	  openair0_cfg[0].rx_freq[0]-ue->common_vars.freq_offset,
	  ue->common_vars.freq_offset);
Cedric Roux's avatar
Cedric Roux committed
784 785
#  else
    LOG_I(PHY, "[UE %d] Frame %d Measured Carrier Frequency %.0f Hz (offset %d Hz)\n",
786
	  ue->Mod_id,
787
	  ue->proc.proc_rxtx[0].frame_rx,
788 789
	  openair0_cfg[0].rx_freq[0]-ue->common_vars.freq_offset,
	  ue->common_vars.freq_offset);
Cedric Roux's avatar
Cedric Roux committed
790
#  endif
791
#endif
792
  } else {
793
#ifdef DEBUG_INITIAL_SYNC
794 795
    LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id);
    LOG_I(PHY,"[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n",ue->Mod_id,sync_pos,ue->common_vars.eNb_id);
796
    /*      LOG_I(PHY,"[UE%d] Initial sync: (metric fdd_ncp %d (%d), metric fdd_ecp %d (%d), metric_tdd_ncp %d (%d), metric_tdd_ecp %d (%d))\n",
797
          ue->Mod_id,
798 799 800 801
          metric_fdd_ncp,Nid_cell_fdd_ncp,
          metric_fdd_ecp,Nid_cell_fdd_ecp,
          metric_tdd_ncp,Nid_cell_tdd_ncp,
          metric_tdd_ecp,Nid_cell_tdd_ecp);*/
802
    LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id,
803
          frame_parms->Nid_cell,frame_parms->frame_type);
804
#endif
805

806 807 808 809
    ue->UE_mode[0] = NOT_SYNCHED;
    ue->pbch_vars[0]->pdu_errors_last=ue->pbch_vars[0]->pdu_errors;
    ue->pbch_vars[0]->pdu_errors++;
    ue->pbch_vars[0]->pdu_errors_conseq++;
810

811 812
  }

813
  // gain control
814
  if (ret!=0) { //we are not synched, so we cannot use rssi measurement (which is based on channel estimates)
815 816
    rx_power = 0;

817 818
    // do a measurement on the best guess of the PSS
    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
819
      rx_power += signal_energy(&ue->common_vars.rxdata[aarx][sync_pos2],
820
				frame_parms->ofdm_symbol_size+frame_parms->nb_prefix_samples);
821

822 823
    /*
    // do a measurement on the full frame
824
    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++)
825
      rx_power += signal_energy(&ue->common_vars.rxdata[aarx][0],
826
				frame_parms->samples_per_tti*10);
827
    */
828 829

    // we might add a low-pass filter here later
830
    ue->measurements.rx_power_avg[0] = rx_power/frame_parms->nb_antennas_rx;
831

832
    ue->measurements.rx_power_avg_dB[0] = dB_fixed(ue->measurements.rx_power_avg[0]);
833 834

#ifdef DEBUG_INITIAL_SYNCH
835
  LOG_I(PHY,"[UE%d] Initial sync : Estimated power: %d dB\n",ue->Mod_id,ue->measurements.rx_power_avg_dB[0] );
836 837 838
#endif

#ifndef OAI_USRP
839
#ifndef OAI_BLADERF
840
#ifndef OAI_LMSSDR
841
  phy_adjust_gain(ue,ue->measurements.rx_power_avg_dB[0],0);
842
#endif
843 844
#endif
#endif
845

846 847 848 849
  }
  else {

#ifndef OAI_USRP
850
#ifndef OAI_BLADERF
851
#ifndef OAI_LMSSDR
852
  phy_adjust_gain(ue,dB_fixed(ue->measurements.rssi),0);
853
#endif
854 855
#endif
#endif
856

857 858
  }

859
  //  exit_fun("debug exit");
860 861
  return ret;
}
lfarizav's avatar
lfarizav committed
862 863 864
int initial_sync_freq(PHY_VARS_UE *ue, runmode_t mode)
{
  //int32_t sync_pos,sync_pos2,sync_pos_slot;
865 866 867
  //int32_t metric_fdd_ncp=0,metric_fdd_ecp=0,metric_tdd_ncp=0,metric_tdd_ecp=0;
  //uint8_t phase_fdd_ncp,phase_fdd_ecp,phase_tdd_ncp,phase_tdd_ecp;
  //uint8_t flip_fdd_ncp,flip_fdd_ecp,flip_tdd_ncp,flip_tdd_ecp;
lfarizav's avatar
lfarizav committed
868 869 870
  //  uint16_t Nid_cell_fdd_ncp=0,Nid_cell_fdd_ecp=0,Nid_cell_tdd_ncp=0,Nid_cell_tdd_ecp=0;
  LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  int ret=-1;
871
  int aarx,rx_power=0;
lfarizav's avatar
lfarizav committed
872 873 874 875 876 877 878 879 880 881
  /*#ifdef OAI_USRP
  __m128i *rxdata128;
  #endif*/
  //  LOG_I(PHY,"**************************************************************\n");

  // First try FDD normal prefix
  //frame_parms->Ncp=NORMAL;
  //frame_parms->frame_type=FDD;
  frame_parms->frame_type=PHY_vars_eNB_g[0][0]->frame_parms.frame_type;
  frame_parms->Ncp=PHY_vars_eNB_g[0][0]->frame_parms.Ncp;
882
  init_frame_parms(frame_parms,1);
lfarizav's avatar
lfarizav committed
883 884 885 886 887 888 889 890 891 892
  //frame_parms->N_RB_DL=PHY_vars_eNB_g[0][0]->frame_parms.N_RB_DL;

// cellid
  frame_parms->Nid_cell=PHY_vars_eNB_g[0][0]->frame_parms.Nid_cell;
// nushift
  //rx_sss(ue,&metric_fdd_ncp,&flip_fdd_ncp,&phase_fdd_ncp);
  frame_parms->nushift  = frame_parms->Nid_cell%6;
  // lte-gold
  lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
  ret=pbch_detection_freq(ue,mode);
893
  //init_frame_parms(frame_parms,1);
894 895 896 897
  //printf("dumping enb frame params\n");
  //dump_frame_parms(&PHY_vars_eNB_g[0][0]->frame_parms);
  //printf("dumping ue frame params\n");
  //dump_frame_parms(frame_parms);
898 899 900 901 902 903 904 905 906
  if (ret==-1) { 
      frame_parms->frame_type=PHY_vars_eNB_g[0][0]->frame_parms.frame_type;
      frame_parms->Ncp=PHY_vars_eNB_g[0][0]->frame_parms.Ncp;
      init_frame_parms(frame_parms,1);
      frame_parms->nushift  = frame_parms->Nid_cell%6;
      lte_gold(frame_parms,ue->lte_gold_table[0],frame_parms->Nid_cell);
      ret = pbch_detection(ue,mode);

  }
lfarizav's avatar
lfarizav committed
907 908
  if (ret==0) {  // fake first PBCH found so indicate sync to higher layers and configure frame parameters

909
    //printf("[UE%d] frame_type is %c\n",ue->Mod_id, ue->rx_offset);
lfarizav's avatar
lfarizav committed
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
    //#ifdef DEBUG_INITIAL_SYNCH
    LOG_I(PHY,"[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
    //#endif
    printf("[UE%d] In synch, rx_offset %d samples\n",ue->Mod_id, ue->rx_offset);
    if (ue->UE_scan_carrier == 0) {

    #if UE_AUTOTEST_TRACE
      LOG_I(PHY,"[UE  %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n",
              ue->Mod_id,
              ue->proc.proc_rxtx[0].frame_rx,
              ue->rx_offset,
              ue->common_vars.freq_offset );
    #endif
      printf("[UE  %d] AUTOTEST Cell Sync : frame = %d, rx_offset %d, freq_offset %d \n",
              ue->Mod_id,
              ue->proc.proc_rxtx[0].frame_rx,
              ue->rx_offset,
              ue->common_vars.freq_offset );

      if (ue->mac_enabled==1) {
	LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
	//mac_resynch();
	mac_xface->dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
	ue->UE_mode[0] = PRACH;
      }
      else {
	ue->UE_mode[0] = PUSCH;
      }

      generate_pcfich_reg_mapping(frame_parms);
      generate_phich_reg_mapping(frame_parms);


      ue->pbch_vars[0]->pdu_errors_conseq=0;

    }

    LOG_I(PHY,"[UE %d] Frame %d RRC Measurements => rssi %3.1f dBm (dig %3.1f dB, gain %d), N0 %d dBm,  rsrp %3.1f dBm/RE, rsrq %3.1f dB\n",ue->Mod_id,
	  ue->proc.proc_rxtx[0].frame_rx,
	  10*log10(ue->measurements.rssi)-ue->rx_total_gain_dB,
	  10*log10(ue->measurements.rssi),
	  ue->rx_total_gain_dB,
	  ue->measurements.n0_power_tot_dBm,
	  10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB,
	  (10*log10(ue->measurements.rsrq[0])));

    LOG_I(PHY,"[UE %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
	  ue->Mod_id,
	  ue->proc.proc_rxtx[0].frame_rx,
	  duplex_string[ue->frame_parms.frame_type],
	  prefix_string[ue->frame_parms.Ncp],
	  ue->frame_parms.Nid_cell,
	  ue->frame_parms.N_RB_DL,
	  ue->frame_parms.phich_config_common.phich_duration,
	  phich_string[ue->frame_parms.phich_config_common.phich_resource],
	  ue->frame_parms.nb_antenna_ports_eNB);
    LOG_I(PHY,"[eNB %d] Frame %d MIB Information => %s, %s, NidCell %d, N_RB_DL %d, PHICH DURATION %d, PHICH RESOURCE %s, TX_ANT %d\n",
	  PHY_vars_eNB_g[0][0]->Mod_id,
	  PHY_vars_eNB_g[0][0]->proc.proc_rxtx[0].frame_rx,
	  duplex_string[PHY_vars_eNB_g[0][0]->frame_parms.frame_type],
	  prefix_string[PHY_vars_eNB_g[0][0]->frame_parms.Ncp],
	  PHY_vars_eNB_g[0][0]->frame_parms.Nid_cell,
	  PHY_vars_eNB_g[0][0]->frame_parms.N_RB_DL,
	  PHY_vars_eNB_g[0][0]->frame_parms.phich_config_common.phich_duration,
	  phich_string[PHY_vars_eNB_g[0][0]->frame_parms.phich_config_common.phich_resource],
	  PHY_vars_eNB_g[0][0]->frame_parms.nb_antenna_ports_eNB);

#if defined(OAI_USRP) || defined(EXMIMO) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
    LOG_I(PHY,"[UE %d] Frame %d Measured Carrier Frequency %.0f Hz (offset %d Hz)\n",
	  ue->Mod_id,
	  ue->proc.proc_rxtx[0].frame_rx,
	  openair0_cfg[0].rx_freq[0]-ue->common_vars.freq_offset,
	  ue->common_vars.freq_offset);
#endif
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
#ifndef OAI_USRP
#ifndef OAI_BLADERF
#ifndef OAI_LMSSDR
  	  phy_adjust_gain(ue,dB_fixed(ue->measurements.rssi),0);
#endif
#endif
#endif
  } else {
#ifdef DEBUG_INITIAL_SYNC
    LOG_I(PHY,"[UE%d] Initial sync : PBCH not ok\n",ue->Mod_id);
    LOG_I(PHY,"[UE%d] Initial sync : Estimated PSS position %d, Nid2 %d\n",ue->Mod_id,sync_pos,ue->common_vars.eNb_id);
    /*      LOG_I(PHY,"[UE%d] Initial sync: (metric fdd_ncp %d (%d), metric fdd_ecp %d (%d), metric_tdd_ncp %d (%d), metric_tdd_ecp %d (%d))\n",
          ue->Mod_id,
          metric_fdd_ncp,Nid_cell_fdd_ncp,
          metric_fdd_ecp,Nid_cell_fdd_ecp,
          metric_tdd_ncp,Nid_cell_tdd_ncp,
          metric_tdd_ecp,Nid_cell_tdd_ecp);*/
    LOG_I(PHY,"[UE%d] Initial sync : Estimated Nid_cell %d, Frame_type %d\n",ue->Mod_id,
          frame_parms->Nid_cell,frame_parms->frame_type);
#endif

    ue->UE_mode[0] = NOT_SYNCHED;
    ue->pbch_vars[0]->pdu_errors_last=ue->pbch_vars[0]->pdu_errors;
    ue->pbch_vars[0]->pdu_errors++;
    ue->pbch_vars[0]->pdu_errors_conseq++;

  }
  
lfarizav's avatar
lfarizav committed
1012 1013
  return ret;
}
1014