phy_procedures_lte_eNb.c 65.4 KB
Newer Older
1 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.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
 */
21 22 23

/*! \file phy_procedures_lte_eNB.c
 * \brief Implementation of eNB procedures from 36.213 LTE specifications
24
 * \author R. Knopp, F. Kaltenberger, N. Nikaein, X. Foukas
25 26 27
 * \date 2011
 * \version 0.1
 * \company Eurecom
28
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr, x.foukas@sms.ed.ac.uk
29 30 31 32 33 34 35 36
 * \note
 * \warning
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"
37
#include "nfapi_interface.h"
38
#include "fapi_l1.h"
39 40 41
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"

42 43
#include "T.h"

44
#include "assertions.h"
gauthier's avatar
gauthier committed
45
#include "msc.h"
46

47 48
#include <time.h>

49
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
50
#   include "intertask_interface.h"
51 52
#endif

53

54

55

56
void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,PHY_VARS_RN *rn,relaying_type_t r_type) {
57 58


Cedric Roux's avatar
Cedric Roux committed
59
#if defined(Rel10) || defined(Rel14)
knopp's avatar
knopp committed
60
  MCH_PDU *mch_pduP=NULL;
61
  MCH_PDU  mch_pdu;
62
  //  uint8_t sync_area=255;
63
#endif
64

65
  int subframe = proc->subframe_tx;
66

knopp's avatar
knopp committed
67 68
  AssertFatal(1==0,"pmch not tested for the moment, exiting\n");

69 70 71 72 73 74
  // This is DL-Cell spec pilots in Control region
  generate_pilots_slot(eNB,
		       eNB->common_vars.txdataF,
		       AMP,
		       subframe<<1,1);

75
  
Cedric Roux's avatar
Cedric Roux committed
76
#if defined(Rel10) || defined(Rel14)
77 78
  // if mcch is active, send regardless of the node type: eNB or RN
  // when mcch is active, MAC sched does not allow MCCH and MTCH multiplexing
79
  /*
80 81
  mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
				    eNB->CC_id,
82
				    proc->frame_tx,
83
				    subframe);
84
  */
85 86 87
  switch (r_type) {
  case no_relay:
    if ((mch_pduP->Pdu_size > 0) && (mch_pduP->sync_area == 0)) // TEST: only transmit mcch for sync area 0
knopp's avatar
knopp committed
88
      LOG_D(PHY,"[eNB%"PRIu8"] Frame %d subframe %d : Got MCH pdu for MBSFN (MCS %"PRIu8", TBS %d) \n",
89 90
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->mcs,
	    eNB->dlsch_MCH->harq_processes[0]->TBS>>3);
91 92
    else {
      LOG_D(PHY,"[DeNB %"PRIu8"] Frame %d subframe %d : Do not transmit MCH pdu for MBSFN sync area %"PRIu8" (%s)\n",
93
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->sync_area,
94 95
	    (mch_pduP->Pdu_size == 0)? "Empty MCH PDU":"Let RN transmit for the moment");
      mch_pduP = NULL;
gauthier's avatar
gauthier committed
96
    }
97
    
98
    break;
99 100 101
    
  case multicast_relay:
    if ((mch_pduP->Pdu_size > 0) && ((mch_pduP->mcch_active == 1) || mch_pduP->msi_active==1)) {
knopp's avatar
knopp committed
102
      LOG_D(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Got the MCH PDU for MBSFN  sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
103 104 105 106 107 108 109 110 111
	    rn->Mod_id,rn->frame, subframe,
	    mch_pduP->sync_area,mch_pduP->mcs,mch_pduP->Pdu_size);
    } else if (rn->mch_avtive[subframe%5] == 1) { // SF2 -> SF7, SF3 -> SF8
      mch_pduP= &mch_pdu;
      memcpy(&mch_pduP->payload, // could be a simple copy
	     rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->b,
	     rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
      mch_pduP->Pdu_size = (uint16_t) (rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->TBS>>3);
      mch_pduP->mcs = rn->dlsch_rn_MCH[subframe%5]->harq_processes[0]->mcs;
knopp's avatar
knopp committed
112
      LOG_D(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Forward the MCH PDU for MBSFN received on SF %d sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
113 114
	    rn->Mod_id,rn->frame, subframe,subframe%5,
	    rn->sync_area[subframe%5],mch_pduP->mcs,mch_pduP->Pdu_size);
115
    } else {
116
      mch_pduP=NULL;
117
    }
118 119
    
    rn->mch_avtive[subframe]=0;
120
    break;
121
    
122
  default:
123
    LOG_W(PHY,"[eNB %"PRIu8"] Frame %d subframe %d: unknown relaying type %d \n",
124
	  eNB->Mod_id,proc->frame_tx,subframe,r_type);
125 126 127 128 129
    mch_pduP=NULL;
    break;
  }// switch
  
  if (mch_pduP) {
130
    fill_eNB_dlsch_MCH(eNB,mch_pduP->mcs,1,0);
131
    // Generate PMCH
132
    generate_mch(eNB,proc,(uint8_t*)mch_pduP->payload);
133
  } else {
134
    LOG_D(PHY,"[eNB/RN] Frame %d subframe %d: MCH not generated \n",proc->frame_tx,subframe);
135
  }
136
  
137
#endif
138
}
139

140
void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
141

142
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
143
  int **txdataF = eNB->common_vars.txdataF;
144
  uint8_t *pbch_pdu=&eNB->pbch_pdu[0];
145 146
  int subframe = proc->subframe_tx;
  int frame = proc->frame_tx;
147

148 149
  LOG_D(PHY,"common_signal_procedures: frame %d, subframe %d\n",frame,subframe); 

150
  // generate Cell-Specific Reference Signals for both slots
151 152 153 154 155 156 157
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
  generate_pilots_slot(eNB,
		       txdataF,
		       AMP,
		       subframe<<1,0);
  // check that 2nd slot is for DL
  if (subframe_select(fp,subframe) == SF_DL)
158 159 160
    generate_pilots_slot(eNB,
			 txdataF,
			 AMP,
161 162 163 164
			 (subframe<<1)+1,0);
  
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
      
165

166
  // First half of PSS/SSS (FDD, slot 0)
167
  if (subframe == 0) {
168
    if (fp->frame_type == FDD) {
169 170 171 172 173 174 175 176 177 178 179
      generate_pss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   0);
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 5 : 4,
		   0);
      
180
    }
181
    
182 183


184 185 186
      
    /// First half of SSS (TDD, slot 1)
    
187
    if (fp->frame_type == TDD) {
188 189 190 191 192 193
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   1);
    }
194

195 196
    // generate PBCH (Physical Broadcast CHannel) info

197
    /// generate PBCH
198 199 200
    if ((frame&3)==0) {
      AssertFatal(eNB->pbch_configured==1,"PBCH was not configured by MAC\n");
      eNB->pbch_configured=0;
201
    }
202 203 204 205 206 207 208
    generate_pbch(&eNB->pbch,
		  txdataF,
		  AMP,
		  fp,
		  pbch_pdu,
		  frame&3);
  
209
  }
210
  else if ((subframe == 1) &&
211
	   (fp->frame_type == TDD)){
212 213 214 215 216
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 2);
217
  }
218 219 220
  
  // Second half of PSS/SSS (FDD, slot 10)
  else if ((subframe == 5) && 
221
	   (fp->frame_type == FDD)) {
222 223 224 225 226 227 228 229 230 231
    generate_pss(txdataF,
		 AMP,
		 &eNB->frame_parms,
		 (fp->Ncp==NORMAL) ? 6 : 5,
		 10);
    generate_sss(txdataF,
		 AMP,
		 &eNB->frame_parms,
		 (fp->Ncp==NORMAL) ? 5 : 4,
		 10);
232

233
  }
234

235 236
  //  Second-half of SSS (TDD, slot 11)
  else if ((subframe == 5) &&
237
	   (fp->frame_type == TDD)) {
238 239 240 241 242
    generate_sss(txdataF,
		 AMP,
		 fp,
		 (fp->Ncp==NORMAL) ? 6 : 5,
		 11);
243
  }
244

245 246
  // Second half of PSS (TDD, slot 12)
  else if ((subframe == 6) &&
247
	   (fp->frame_type == TDD)) { 
248 249 250 251 252 253
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 12);
  }
254

255
}
256

257 258


259 260 261 262 263 264
void pdsch_procedures(PHY_VARS_eNB *eNB,
		      eNB_rxtx_proc_t *proc,
		      int harq_pid,
		      LTE_eNB_DLSCH_t *dlsch, 
		      LTE_eNB_DLSCH_t *dlsch1,
		      LTE_eNB_UE_stats *ue_stats,
265
		      int ra_flag) {
266

267 268
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
269 270
  LTE_DL_eNB_HARQ_t *dlsch_harq=dlsch->harq_processes[harq_pid];
  int input_buffer_length = dlsch_harq->TBS/8;
271
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
272

273
  if (dlsch->rnti == 0x02) {//frame < 200) {
274

275
    LOG_I(PHY,
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	  "[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d, subframe %d: Generating PDSCH/DLSCH with input size = %"PRIu16", pdsch_start %d, G %d, nb_rb %"PRIu16", rb0 %x, rb1 %x, TBS %"PRIu16", pmi_alloc %"PRIx64", rv %"PRIu8" (round %"PRIu8")\n",
	  eNB->Mod_id, dlsch->rnti,harq_pid,
	  frame, subframe, input_buffer_length, dlsch_harq->pdsch_start,
	  get_G(fp,
		dlsch_harq->nb_rb,
		dlsch_harq->rb_alloc,
		dlsch_harq->Qm,
		dlsch_harq->Nl,
		dlsch_harq->pdsch_start,
		frame,
		subframe,
		dlsch_harq->mimo_mode==TM7?7:0),
	  dlsch_harq->nb_rb,
	  dlsch_harq->rb_alloc[0],
	  dlsch_harq->rb_alloc[1],
	  dlsch_harq->TBS,
	  pmi2hex_2Ar1(dlsch_harq->pmi_alloc),
	  dlsch_harq->rvidx,
	  dlsch_harq->round);
  }    
296
#if defined(MESSAGE_CHART_GENERATOR_PHY)
297 298 299
  MSC_LOG_TX_MESSAGE(
		     MSC_PHY_ENB,MSC_PHY_UE,
		     NULL,0,
300
		     "%05u:%02u PDSCH/DLSCH input size = %"PRIu16", G %d, nb_rb %"PRIu16", TBS %"PRIu16", pmi_alloc %"PRIx16", rv %"PRIu8" (round %"PRIu8")",
301 302 303 304 305
		     frame, subframe,
		     input_buffer_length,
		     get_G(fp,
			   dlsch_harq->nb_rb,
			   dlsch_harq->rb_alloc,
306
			   dlsch_harq->Qm,
307
			   dlsch_harq->Nl,
308
			   dlsch_harq->pdsch_start,
309 310 311
			   frame,
			   subframe,
			   dlsch_harq->mimo_mode==TM7?7:0),
312
		     dlsch_harq->nb_rb,
313
		     dlsch_harq->TBS,
314 315 316 317
		     pmi2hex_2Ar1(dlsch_harq->pmi_alloc),
		     dlsch_harq->rvidx,
		     dlsch_harq->round);
#endif
318 319
  
  
320
  if (ue_stats) ue_stats->dlsch_sliding_cnt++;
321
  
322 323 324
  if (dlsch_harq->round == 0) {
    if (ue_stats)
      ue_stats->dlsch_trials[harq_pid][0]++;
325 326 327 328 329 330 331 332
  } else {
    ue_stats->dlsch_trials[harq_pid][dlsch_harq->round]++;
#ifdef DEBUG_PHY_PROC
#ifdef DEBUG_DLSCH
    LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
#endif
#endif
  }
333 334


335
  LOG_D(PHY,"Generating DLSCH/PDSCH %d\n",ra_flag);
336
  // 36-212 
337
  start_meas(&eNB->dlsch_encoding_stats);
338
  AssertFatal(dlsch_harq->pdu!=NULL,"dlsch_harq->pdu == NULL (rnti %x)\n",dlsch->rnti);
339 340
  eNB->te(eNB,
	  dlsch_harq->pdu,
341
	  dlsch_harq->pdsch_start,
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
	  dlsch,
	  frame,subframe,
	  &eNB->dlsch_rate_matching_stats,
	  &eNB->dlsch_turbo_encoding_stats,
	  &eNB->dlsch_interleaving_stats);
  stop_meas(&eNB->dlsch_encoding_stats);
  // 36-211
  start_meas(&eNB->dlsch_scrambling_stats);
  dlsch_scrambling(fp,
		   0,
		   dlsch,
		   harq_pid,
		   get_G(fp,
			 dlsch_harq->nb_rb,
			 dlsch_harq->rb_alloc,
357
			 dlsch_harq->Qm,
358
			 dlsch_harq->Nl,
359
			 dlsch_harq->pdsch_start,
360 361 362
			 frame,subframe,
			 0),
		   0,
363
		   frame,
364 365 366 367 368 369 370 371 372 373
		   subframe<<1);
  stop_meas(&eNB->dlsch_scrambling_stats);
  
  start_meas(&eNB->dlsch_modulation_stats);
  
  
  dlsch_modulation(eNB,
		   eNB->common_vars.txdataF,
		   AMP,
		   subframe,
374
		   dlsch_harq->pdsch_start,
375 376 377 378
		   dlsch,
		   dlsch1);
  
  stop_meas(&eNB->dlsch_modulation_stats);
379

380
  dlsch->active = 0;
381
  dlsch_harq->round++;
382
}
383 384


385

386
void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
knopp's avatar
knopp committed
387
			   eNB_rxtx_proc_t *proc,
388
                           relaying_type_t r_type,
389 390
			   PHY_VARS_RN *rn,
			   int do_meas)
391 392
{
  UNUSED(rn);
393 394
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
395
  uint32_t i,aa;
396
  uint8_t harq_pid;
397
  int8_t UE_id=0;
398
  uint8_t num_pdcch_symbols=0;
399
  uint8_t num_dci=0;
400 401
  uint8_t ul_subframe;
  uint32_t ul_frame;
402
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
403
  LTE_UL_eNB_HARQ_t *ulsch_harq;
404

405
  int offset = eNB->CC_id;//proc == &eNB->proc.proc_rxtx[0] ? 0 : 1;
406

407
  if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
408

Raymond Knopp's avatar
Raymond Knopp committed
409
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
410
  if (do_meas==1) start_meas(&eNB->phy_proc_tx);
411

412
  // clear the transmit data array for the current subframe
413 414 415
  for (aa=0; aa<fp->nb_antenna_ports_eNB; aa++) {      
    memset(&eNB->common_vars.txdataF[aa][subframe*fp->ofdm_symbol_size*(fp->symbols_per_tti)],
	   0,fp->ofdm_symbol_size*(fp->symbols_per_tti)*sizeof(int32_t));
416
  }
417
  
418

419
  if (is_pmch_subframe(frame,subframe,fp)) {
420
    pmch_procedures(eNB,proc,rn,r_type);
421 422 423
  }
  else {
    // this is not a pmch subframe, so generate PSS/SSS/PBCH
424
    common_signal_procedures(eNB,proc);
425
  }
426

427
  // clear existing ulsch dci allocations before applying info from MAC  (this is table
428
  ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
429
  ul_frame = pdcch_alloc2ul_frame(fp,frame,subframe);
430 431 432



433
  // clear previous allocation information for all UEs
434
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
435 436
    if (eNB->dlsch[i][0])
      eNB->dlsch[i][0]->subframe_tx[subframe] = 0;
437
  }
438

439
  /* save old HARQ information needed for PHICH generation */
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
  if (ul_subframe < 10) { // This means that there is a potential UL subframe that will be scheduled here
    for (i=0; i<NUMBER_OF_UE_MAX; i++) {
      harq_pid = subframe2harq_pid(fp,ul_frame,ul_subframe);
      if (eNB->ulsch[i]) {
	ulsch_harq = eNB->ulsch[i]->harq_processes[harq_pid];
	
	/* Store first_rb and n_DMRS for correct PHICH generation below.
	 * For PHICH generation we need "old" values of last scheduling
	 * for this HARQ process. 'generate_eNB_dlsch_params' below will
	 * overwrite first_rb and n_DMRS and 'generate_phich_top', done
	 * after 'generate_eNB_dlsch_params', would use the "new" values
	 * instead of the "old" ones.
	 *
	 * This has been tested for FDD only, may be wrong for TDD.
	 *
	 * TODO: maybe we should restructure the code to be sure it
	 *       is done correctly. The main concern is if the code
	 *       changes and first_rb and n_DMRS are modified before
	 *       we reach here, then the PHICH processing will be wrong,
	 *       using wrong first_rb and n_DMRS values to compute
	 *       ngroup_PHICH and nseq_PHICH.
	 *
	 * TODO: check if that works with TDD.
	 */
	ulsch_harq->previous_first_rb = ulsch_harq->first_rb;
	ulsch_harq->previous_n_DMRS   = ulsch_harq->n_DMRS;
	
467 468 469 470
      }
    }
  }

471

472

473 474 475 476 477
  //  num_pdcch_symbols = DCI_pdu->num_pdcch_symbols;
  num_pdcch_symbols = eNB->pdcch_vars[subframe&1].num_pdcch_symbols;
  num_dci           = eNB->pdcch_vars[subframe&1].num_dci;
  //  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(dci common %"PRIu8", dci uespec %"PRIu8"\n",num_pdcch_symbols,
  //        DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
478
  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(number dci %"PRIu8"\n",num_pdcch_symbols,
479 480
	num_dci);
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,num_pdcch_symbols);
481

482

483 484
  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,(frame*10)+subframe);

485
  if (num_dci > 0)
knopp's avatar
knopp committed
486
    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (num_dci %"PRIu8")\n",eNB->Mod_id,frame, subframe,
487
	  num_dci);
488

489
    
490 491 492 493 494 495 496 497 498
  generate_dci_top(num_pdcch_symbols,
		   num_dci,
		   &eNB->pdcch_vars[subframe&1].dci_alloc[0],
		   0,
		   AMP,
		   fp,
		   eNB->common_vars.txdataF,
		   subframe);
  
499

gauthier's avatar
gauthier committed
500
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,0);
501

502
  // Now scan UE specific DLSCH
503
  LTE_eNB_DLSCH_t *dlsch0,*dlsch1;
504
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
505
    {
506 507 508 509 510 511
      dlsch0 = eNB->dlsch[(uint8_t)UE_id][0]; 
      dlsch1 = eNB->dlsch[(uint8_t)UE_id][1]; 

      if ((dlsch0)&&
	  (dlsch0->rnti>0)&&
	  (dlsch0->active == 1)) {
512

513
	// get harq_pid
514
	harq_pid = dlsch0->harq_ids[subframe];
515 516 517 518 519
	AssertFatal(harq_pid>=0,"harq_pid is negative\n");
	// generate pdsch
	pdsch_procedures(eNB,
			 proc,
			 harq_pid,
520 521
			 dlsch0,
			 dlsch1,
522
			 &eNB->UE_stats[(uint32_t)UE_id],
523
			 0);
524 525


526
      }
527

gauthier's avatar
gauthier committed
528

529 530 531
      else if ((dlsch0)&&
	       (dlsch0->rnti>0)&&
	       (dlsch0->active == 0)) {
532

533
	// clear subframe TX flag since UE is not scheduled for PDSCH in this subframe (so that we don't look for PUCCH later)
534
	dlsch0->subframe_tx[subframe]=0;
535
      }
536
    }
537

538 539


540 541 542
  generate_phich_top(eNB,
		     proc,
		     AMP);
543

Raymond Knopp's avatar
Raymond Knopp committed
544
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0);
545
  if (do_meas==1) stop_meas(&eNB->phy_proc_tx);
546
  
547 548
}

549

550 551 552 553 554 555
void prach_procedures(PHY_VARS_eNB *eNB,
#ifdef Rel14
		      int br_flag
#endif
		      ) {
  uint16_t max_preamble[4],max_preamble_energy[4],max_preamble_delay[4];
556
  uint16_t i;
557
  int frame,subframe;
knopp's avatar
knopp committed
558

559 560 561 562
#ifdef Rel14
  if (br_flag==1) {
    subframe = eNB->proc.subframe_prach_br;
    frame = eNB->proc.frame_prach_br;
563 564 565
    pthread_mutex_lock(&eNB->UL_INFO_mutex);
    eNB->UL_INFO.rach_ind_br.number_of_preambles=0;
    pthread_mutex_unlock(&eNB->UL_INFO_mutex);
566 567 568 569
  }
  else
#endif
    {
570 571 572
      pthread_mutex_lock(&eNB->UL_INFO_mutex);
      eNB->UL_INFO.rach_ind.number_of_preambles=0;
      pthread_mutex_unlock(&eNB->UL_INFO_mutex);
573 574 575
      subframe = eNB->proc.subframe_prach;
      frame = eNB->proc.frame_prach;
    }
576 577 578
  RU_t *ru;
  int aa=0;
  int ru_aa;
579

580
 
581
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,1);
582

583 584


585 586
  for (i=0;i<eNB->num_RU;i++) {
    ru=eNB->RU_list[i];
587
    for (ru_aa=0,aa=0;ru_aa<ru->nb_rx;ru_aa++,aa++) {
588
      eNB->prach_vars.rxsigF[0][aa] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
589 590 591 592
#ifdef Rel14
      int ce_level;

      if (br_flag==1)
593
	for (ce_level=0;ce_level<4;ce_level++) eNB->prach_vars_br.rxsigF[ce_level][aa] = eNB->RU_list[i]->prach_rxsigF_br[ce_level][ru_aa];
594 595
#endif
    }
596
  }
597

598 599
  rx_prach(eNB,
	   eNB->RU_list[0],
600 601 602
	   &max_preamble[0],
	   &max_preamble_energy[0],
	   &max_preamble_delay[0],
603
	   frame,
604 605 606 607 608
	   0
#ifdef Rel14
	   ,br_flag
#endif
	   );
609

610
  //#ifdef DEBUG_PHY_PROC
knopp's avatar
knopp committed
611
  LOG_D(PHY,"[RAPROC] Frame %d, subframe %d : Most likely preamble %d, energy %d dB delay %d\n",
612
        frame,subframe,
613
	max_preamble[0],
614
        max_preamble_energy[0]/10,
615
        max_preamble_delay[0]);
616
  //q#endif
617

618 619 620 621 622 623 624
#ifdef Rel14
  if (br_flag==1) {
    int prach_mask;
      
    prach_mask = is_prach_subframe(&eNB->frame_parms,eNB->proc.frame_prach_br,eNB->proc.subframe_prach_br);
    
    eNB->UL_INFO.rach_ind_br.preamble_list                              = eNB->preamble_list_br;
625 626 627
    int ind=0;
    int ce_level=0;
    /* Save for later, it doesn't work    
628
    for (int ind=0,ce_level=0;ce_level<4;ce_level++) {
629 630 631
      
      if ((eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[ce_level]==1)&&
	  (prach_mask&(1<<(1+ce_level)) > 0) && // prach is active and CE level has finished its repetitions
632 633
	  (eNB->prach_vars_br.repetition_number[ce_level]==
	   eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level])) {
634
    */ 
635 636 637 638 639 640 641 642 643 644
    if (eNB->frame_parms.prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[0]==1){ 
      if (max_preamble_energy[0] > 350) {
	eNB->UL_INFO.rach_ind_br.number_of_preambles++;
	
	eNB->preamble_list_br[ind].preamble_rel8.timing_advance        = max_preamble_delay[ind];//
	eNB->preamble_list_br[ind].preamble_rel8.preamble              = max_preamble[ind];
	// note: fid is implicitly 0 here, this is the rule for eMTC RA-RNTI from 36.321, Section 5.1.4
	eNB->preamble_list_br[ind].preamble_rel8.rnti                  = 1+subframe+(eNB->prach_vars_br.first_frame[ce_level]%40);  
	eNB->preamble_list_br[ind].instance_length                     = 0; //don't know exactly what this is
	eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type   = 1+ce_level;  // CE Level
knopp's avatar
knopp committed
645
	LOG_D(PHY,"Filling NFAPI indication for RACH %d CELevel %d (mask %x) : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
646 647 648 649 650 651 652 653 654
	      ind,
	      ce_level,
	      prach_mask,
	      eNB->preamble_list_br[ind].preamble_rel8.timing_advance,
	      eNB->preamble_list_br[ind].preamble_rel8.preamble,
	      eNB->preamble_list_br[ind].preamble_rel8.rnti,
	      eNB->preamble_list_br[ind].preamble_rel13.rach_resource_type);
      }
      /*
655 656
	ind++;
      }
657 658
      } */// ce_level
    }
659 660 661
  }
  else
#endif
Cedric Roux's avatar
Cedric Roux committed
662

663
    {
664
      if (max_preamble_energy[0] > 350) {
665

666
	LOG_D(PHY,"[eNB %d/%d][RAPROC] Frame %d, subframe %d Initiating RA procedure with preamble %d, energy %d.%d dB, delay %d\n",
667 668 669 670 671 672 673 674
	      eNB->Mod_id,
	      eNB->CC_id,
	      frame,
	      subframe,
	      max_preamble[0],
	      max_preamble_energy[0]/10,
	      max_preamble_energy[0]%10,
	      max_preamble_delay[0]);
675
	
Cedric Roux's avatar
Cedric Roux committed
676
	    T(T_ENB_PHY_INITIATE_RA_PROCEDURE, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe),
677 678
	      T_INT(max_preamble[0]), T_INT(max_preamble_energy[0]), T_INT(max_preamble_delay[0]));
	    
679 680 681 682 683 684 685 686 687 688 689
	    pthread_mutex_lock(&eNB->UL_INFO_mutex);
	    
	    eNB->UL_INFO.rach_ind.number_of_preambles                 = 1;
	    eNB->UL_INFO.rach_ind.preamble_list                       = eNB->preamble_list;
	    
	    eNB->preamble_list[0].preamble_rel8.timing_advance        = max_preamble_delay[0];
	    eNB->preamble_list[0].preamble_rel8.preamble              = max_preamble[0];
	    eNB->preamble_list[0].preamble_rel8.rnti                  = 1+subframe;  // note: fid is implicitly 0 here
	    eNB->preamble_list[0].preamble_rel13.rach_resource_type   = 0;
	    eNB->preamble_list[0].instance_length                     = 0; //don't know exactly what this is
	    
knopp's avatar
knopp committed
690
	    LOG_D(PHY,"Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
691 692 693 694 695 696
		  eNB->preamble_list[0].preamble_rel8.timing_advance,
		  eNB->preamble_list[0].preamble_rel8.preamble,
		  eNB->preamble_list[0].preamble_rel8.rnti,
		  eNB->preamble_list[0].preamble_rel13.rach_resource_type);	    
	    pthread_mutex_unlock(&eNB->UL_INFO_mutex);
      
697
      } // max_preamble_energy > 350
698
    } // else br_flag
699
      /*
700
	mac_xface->initiate_ra_proc(eNB->Mod_id,
701 702 703 704 705 706 707 708 709 710 711 712
	eNB->CC_id,
	frame,
	preamble_max,
	preamble_delay_list[preamble_max]*update_TA/update_TA2,
	0,subframe,0);*/
      
    
    /*  } else {
    MSC_LOG_EVENT(MSC_PHY_ENB, "0 RA Failed add user, too many");
    LOG_I(PHY,"[eNB %d][RAPROC] frame %d, subframe %d: Unable to add user, max user count reached\n",
	  eNB->Mod_id,frame, subframe);
	  }*/
713

714
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
715 716
}

717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
void srs_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {

  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  const int subframe = proc->subframe_rx;
  const int frame = proc->frame_rx;

  int i;

  if (is_srs_occasion_common(fp,frame,subframe)) { 
  
  // Do SRS processing 
  // check if there is SRS and we have to use shortened format
  // TODO: check for exceptions in transmission of SRS together with ACK/NACK
    for (i=0;i<NUMBER_OF_UE_MAX;i++) {

      if (eNB->soundingrs_ul_config_dedicated[i].active==1) {

      
	if (lte_srs_channel_estimation(fp,
				       &eNB->common_vars,
				       &eNB->srs_vars[i],
				       &eNB->soundingrs_ul_config_dedicated[i],
				       subframe,
				       0/*eNB_id*/)) {
	  LOG_E(PHY,"problem processing SRS\n");
	}
	eNB->soundingrs_ul_config_dedicated[i].active=0;
      }
    }
  }
}

749 750
void fill_sr_indication(PHY_VARS_eNB *eNB,uint16_t rnti,int frame,int subframe,uint32_t stat) {
  
751 752 753 754 755 756 757
  pthread_mutex_lock(&eNB->UL_INFO_mutex);
  nfapi_sr_indication_pdu_t *pdu =   &eNB->UL_INFO.sr_ind.sr_pdu_list[eNB->UL_INFO.sr_ind.number_of_srs];

  pdu->instance_length                                = 0; // don't know what to do with this
  //  pdu->rx_ue_information.handle                       = handle;
  pdu->rx_ue_information.rnti                         = rnti;

758 759 760 761 762 763 764 765
  int SNRtimes10 = dB_fixed_times10(stat) - 200;//(10*eNB->measurements.n0_power_dB[0]);


  if      (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi=0;
  else if (SNRtimes10 >  635) pdu->ul_cqi_information.ul_cqi=255;
  else                        pdu->ul_cqi_information.ul_cqi=(640+SNRtimes10)/5;
  pdu->ul_cqi_information.channel = 0;

766 767 768 769 770
  eNB->UL_INFO.sr_ind.number_of_srs++;
  pthread_mutex_unlock(&eNB->UL_INFO_mutex);
}

void uci_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
Cedric Roux's avatar
Cedric Roux committed
771
{
772
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
773 774
  uint8_t SR_payload = 0,pucch_b0b1[4][2]= {{0,0},{0,0},{0,0},{0,0}},harq_ack[4]={0,0,0,0};
  int32_t metric[4]={0,0,0,0},metric_SR=0,max_metric;
775 776
  const int subframe = proc->subframe_rx;
  const int frame = proc->frame_rx;
777 778 779 780
  int i;
  LTE_eNB_UCI *uci;
  uint16_t tdd_multiplexing_mask=0;
  int res;
781

782
  for (i=0;i<NUMBER_OF_UE_MAX;i++) {
Cedric Roux's avatar
Cedric Roux committed
783

784 785 786 787
    uci = &eNB->uci_vars[i];
    if ((uci->active == 1) &&
	(uci->frame == frame) &&
	(uci->subframe == subframe)) {
788

789
      LOG_D(PHY,"Frame %d, subframe %d: Running uci procedures (type %d) for %d \n",frame,subframe,uci->type,i);
790
      uci->active=0;
Cedric Roux's avatar
Cedric Roux committed
791

knopp's avatar
knopp committed
792 793 794
      // Null out PUCCH PRBs for noise measurement
      switch(fp->N_RB_UL) {
      case 6:
Cedric Roux's avatar
Cedric Roux committed
795 796
        eNB->rb_mask_ul[0] |= (0x1 | (1<<5)); //position 5
        break;
knopp's avatar
knopp committed
797
      case 15:
Cedric Roux's avatar
Cedric Roux committed
798 799
        eNB->rb_mask_ul[0] |= (0x1 | (1<<14)); // position 14
        break;
knopp's avatar
knopp committed
800
      case 25:
Cedric Roux's avatar
Cedric Roux committed
801 802
        eNB->rb_mask_ul[0] |= (0x1 | (1<<24)); // position 24
        break;
knopp's avatar
knopp committed
803
      case 50:
Cedric Roux's avatar
Cedric Roux committed
804 805 806
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[1] |= (1<<17); // position 49 (49-32)
        break;
knopp's avatar
knopp committed
807
      case 75:
Cedric Roux's avatar
Cedric Roux committed
808 809 810
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[2] |= (1<<10); // position 74 (74-64)
        break;
knopp's avatar
knopp committed
811
      case 100:
Cedric Roux's avatar
Cedric Roux committed
812 813 814
        eNB->rb_mask_ul[0] |= 0x1;
        eNB->rb_mask_ul[3] |= (1<<3); // position 99 (99-96)
        break;
knopp's avatar
knopp committed
815
      default:
Cedric Roux's avatar
Cedric Roux committed
816 817
        LOG_E(PHY,"Unknown number for N_RB_UL %d\n",fp->N_RB_UL);
        break;
knopp's avatar
knopp committed
818
      }
819

820 821 822 823 824 825 826 827
      switch (uci->type) {
      case SR:
      case HARQ_SR:
		
	metric_SR = rx_pucch(eNB,
			      uci->pucch_fmt,
			      i,
			      uci->n_pucch_1_0_sr[0],
828
			      0, // n2_pucch
829
			      uci->srs_active, // shortened format
830 831 832 833
			      &SR_payload,
			      frame,
			      subframe,
			      PUCCH1_THRES);
knopp's avatar
knopp committed
834
	LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (SR n1pucch is %d)\n",
835
	      eNB->Mod_id,
836
	      uci->rnti,
837 838 839
	      frame,
	      subframe,
	      SR_payload,
840 841 842
	      uci->n_pucch_1_0_sr[0]);
	if (uci->type == SR) {
	  if (SR_payload == 1) {
843
	    fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
844 845 846 847 848 849 850 851
	    return;
	  }
	  else {
	    return;
	  }
	}
      case HARQ:
	if (fp->frame_type == FDD) {
852
	  LOG_D(PHY,"Frame %d Subframe %d Demodulating PUCCH (UCI %d) for ACK/NAK (uci->pucch_fmt %d,uci->type %d.uci->frame %d, uci->subframe %d): n1_pucch0 %d SR_payload %d\n",
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
		frame,subframe,i,
		uci->pucch_fmt,uci->type,
		uci->frame,uci->subframe,uci->n_pucch_1[0][0],
		SR_payload);
	  
	  metric[0] = rx_pucch(eNB,
			       uci->pucch_fmt,
			       i,
			       uci->n_pucch_1[0][0],
			       0, //n2_pucch
			       uci->srs_active, // shortened format
			       pucch_b0b1[0],
			       frame,
			       subframe,
			       PUCCH1a_THRES);
	  
	  
	  /* cancel SR detection if reception on n1_pucch0 is better than on SR PUCCH resource index, otherwise send it up to MAC */
	  if (uci->type==HARQ_SR && metric[0] > metric_SR) SR_payload = 0;
872
	  else if (SR_payload == 1) fill_sr_indication(eNB,uci->rnti,frame,subframe,metric_SR);
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
 
	  if (uci->type==HARQ_SR && metric[0] <= metric_SR) {
	    /* when transmitting ACK/NACK on SR PUCCH resource index, SR payload is always 1 */
	    SR_payload = 1;
	    
	    metric[0]=rx_pucch(eNB,
			       uci->pucch_fmt,
			       i,
			       uci->n_pucch_1_0_sr[0],
			       0, //n2_pucch
			       uci->srs_active, // shortened format
			       pucch_b0b1[0],
			       frame,
			       subframe,
			       PUCCH1a_THRES);
	  }
	  
890

891
	  LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d pucch1a (FDD) payload %d (metric %d)\n",
892 893 894
		eNB->Mod_id,
		uci->rnti,
		frame,subframe,
895 896
		pucch_b0b1[0][0],metric[0]);

897
      uci->stat = metric[0]; 	  
898
	  fill_uci_harq_indication(eNB,uci,frame,subframe,pucch_b0b1[0],0,0xffff);
899

900 901
	}
	else { // frame_type == TDD
knopp's avatar
knopp committed
902

903

904 905
	  // if SR was detected, use the n1_pucch from SR
	  if (SR_payload==1) {
906
#ifdef DEBUG_PHY_PROC
907 908 909 910
	    LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d with SR\n",eNB->Mod_id,
		  eNB->dlsch[UE_id][0]->rnti,
		  frame,subframe,
		  n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
911
#endif
912 913 914 915 916 917 918 919 920 921 922 923
	    
	    metric[0] = rx_pucch(eNB,
				 pucch_format1b,
				 i,
				 uci->n_pucch_1_0_sr[0],
				 0, //n2_pucch
				 uci->srs_active, // shortened format
				 pucch_b0b1[0],
				 frame,
				 subframe,
				 PUCCH1a_THRES);
	  } else { //using assigned pucch resources
924
#ifdef DEBUG_PHY_PROC
925 926 927 928 929 930 931 932 933
	    LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK M=%d (%d,%d,%d,%d) format %d\n",eNB->Mod_id,
		  eNB->dlsch[UE_id][0]->rnti,
		  frame,subframe,
		  uci->num_pucch_resources,
		  uci->n_pucch_1[res][0],
		  uci->n_pucch_1[res][1],
		  uci->n_pucch_1[res][2],
		  uci->n_pucch_1[res][3],
		  uci->pucch_fmt);
934
#endif
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
	    for (res=0;res<uci->num_pucch_resources;res++)
	      metric[res] = rx_pucch(eNB,
				     uci->pucch_fmt,
				     i,
				     uci->n_pucch_1[res][0],
				     0, // n2_pucch
				     uci->srs_active, // shortened format
				     pucch_b0b1[res],
				     frame,
				     subframe,
				     PUCCH1a_THRES);
	  	  
	    

	  }
950

951
	  
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
	  if (SR_payload == 1) { // this implements Table 7.3.1 from 36.213
	    if (pucch_b0b1[0][0] == 4) { // there isn't a likely transmission
	      harq_ack[0] = 4; // DTX
	    }
	    else if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] == 1) { // 1/4/7 ACKs
	      harq_ack[0] = 1;
	    }
	    else if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1) { // 2/5/8 ACKs
	      harq_ack[0] = 2;
	    }
	    else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1) { // 3/6/9 ACKs
	      harq_ack[0] = 3;
	    }
	    else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] != 1) { // 0 ACKs, or at least one DL assignment missed
	      harq_ack[0] = 0;
	    }
968
        uci->stat = metric[0];
969 970
	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,2,0xffff); // special_bundling mode
	  } 
knopp's avatar
knopp committed
971
	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==2)){ // multiplexing + no SR, implement Table 10.1.3-5 (Rel14) for multiplexing with M=2
972 973 974 975 976 977 978 979 980 981 982 983 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
	    if (pucch_b0b1[0][0] == 4 ||
		pucch_b0b1[1][0] == 4) { // there isn't a likely transmission
	      harq_ack[0] = 4; // DTX
	      harq_ack[1] = 6; // NACK/DTX
	    } 
	    else {
	      if (metric[1]>metric[0]) {
		if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 1; // ACK
		  tdd_multiplexing_mask = 0x3;
		}
		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1){
		  harq_ack[0] = 6; // NACK/DTX
		  harq_ack[1] = 1; // ACK
		  tdd_multiplexing_mask = 0x2;
		}
		else {
		  harq_ack[0] = 4; // DTX
		  harq_ack[1] = 4; // DTX
		}
	      }
	      else {
		if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 6; // NACK/DTX
		  tdd_multiplexing_mask = 0x1;
		}
		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
		  harq_ack[0] = 2; // NACK
		  harq_ack[1] = 6; // NACK/DTX
		}
		else {
		  harq_ack[0] = 4; // DTX
		  harq_ack[1] = 4; // DTX
		}
	      }
	    }
1010
        uci->stat = max(metric[0],metric[1]);
1011
	    fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
knopp's avatar
knopp committed
1012
	  } //else if ((uci->tdd_bundling == 0) && (res==2))
knopp's avatar
knopp committed
1013
	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==3)){ // multiplexing + no SR, implement Table 10.1.3-6 (Rel14) for multiplexing with M=3
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	    
	    if (harq_ack[0] == 4 ||
		harq_ack[1] == 4 ||
		harq_ack[2] == 4) { // there isn't a likely transmission
	      harq_ack[0] = 4; // DTX
	      harq_ack[1] = 6; // NACK/DTX
	      harq_ack[2] = 6; // NACK/DTX
	      
	    } 
	    else {
	      
	      max_metric = max(metric[0],max(metric[1],metric[2]));
	      
	      if (metric[0]==max_metric) {
		if (pucch_b0b1[0][0] == 1 && pucch_b0b1[0][1] == 1){
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 6; // NACK/DTX
		  harq_ack[2] = 6; // NACK/DTX
		  tdd_multiplexing_mask = 0x1;
		}
		else if (pucch_b0b1[0][0] != 1 && pucch_b0b1[0][1] != 1){
		  harq_ack[0] = 2; // NACK
		  harq_ack[1] = 6; // NACK/DTX
		  harq_ack[2] = 6; // NACK/DTX
		}
		else {
		  harq_ack[0] = 4; // DTX
		  harq_ack[1] = 4; // DTX
		  harq_ack[2] = 4; // DTX
		}
	      } // if (metric[0]==max_metric) {
	      else if (metric[1]==max_metric) {
	      
	        if (pucch_b0b1[1][0] == 1 && pucch_b0b1[1][1] != 1){
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 1; // ACK
		  harq_ack[2] = 6; // NACK/DTX
		  tdd_multiplexing_mask = 0x3;
		}
		else if (pucch_b0b1[1][0] != 1 && pucch_b0b1[1][1] == 1 ) {
		  harq_ack[0] = 6; // NACK/DTX
		  harq_ack[1] = 1; // ACK
		  harq_ack[2] = 6; // NACK/DTX
		  tdd_multiplexing_mask = 0x2;
		}
		else {
		  harq_ack[0] = 4; // DTX
		  harq_ack[1] = 4; // DTX
		  harq_ack[2] = 4; // DTX
		}
	      } // if (metric[1]==max_metric) {
	      else {
  	        if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] == 1){
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 1; // ACK
		  harq_ack[2] = 1; // ACK
		  tdd_multiplexing_mask = 0x7;
		}
		else if (pucch_b0b1[2][0] == 1 && pucch_b0b1[2][1] != 1 ) {
		  harq_ack[0] = 1; // ACK
		  harq_ack[1] = 6; // NACK/DTX
		  harq_ack[2] = 1; // ACK
		  tdd_multiplexing_mask = 0x5;
		}
		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] == 1 ) {
		  harq_ack[0] = 6; // NACK/DTX
		  harq_ack[1] = 1; // ACK
		  harq_ack[2] = 1; // ACK
		  tdd_multiplexing_mask = 0x6;
		}
		else if (pucch_b0b1[2][0] != 1 && pucch_b0b1[2][1] != 1 ) {
		  harq_ack[0] = 6; // NACK/DTX
		  harq_ack[1] = 6; // NACK/DTX
		  harq_ack[2] = 1; // ACK
		  tdd_multiplexing_mask = 0x4;
		}
	      }
1091 1092
            uci->stat = max_metric;
            fill_uci_harq_indication(eNB,uci,frame,subframe,harq_ack,1,tdd_multiplexing_mask); // multiplexing mode
1093
	    }
knopp's avatar
knopp committed
1094
	  } //else if ((uci->tdd_bundling == 0) && (res==3)) 
knopp's avatar
knopp committed
1095
	  else if ((uci->tdd_bundling == 0) && (uci->num_pucch_resources==4)){ // multiplexing + no SR, implement Table 10.1.3-7 (Rel14) for multiplexing with M=4
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
	    if (pucch_b0b1[0][0] == 4 ||<