phy_procedures_lte_eNb.c 114 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
/*! \file phy_procedures_lte_eNB.c
 * \brief Implementation of eNB procedures from 36.213 LTE specifications
24
 * \author R. Knopp, F. Kaltenberger, N. Nikaein
25 26 27
 * \date 2011
 * \version 0.1
 * \company Eurecom
28
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,navid.nikaein@eurecom.fr
29 30 31 32 33 34 35 36 37
 * \note
 * \warning
 */

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "SCHED/extern.h"

38
#include "PHY/LTE_TRANSPORT/if4_tools.h"
Sandeep Kumar's avatar
Sandeep Kumar committed
39
#include "PHY/LTE_TRANSPORT/if5_tools.h"
40

41 42 43 44
#ifdef EMOS
#include "SCHED/phy_procedures_emos.h"
#endif

45
//#define DEBUG_PHY_PROC (Already defined in cmake)
46 47 48 49 50 51 52
//#define DEBUG_ULSCH

#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/defs.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"

53 54
#include "T.h"

55
#include "assertions.h"
gauthier's avatar
gauthier committed
56
#include "msc.h"
57

58 59
#include <time.h>

60
#if defined(ENABLE_ITTI)
gauthier's avatar
gauthier committed
61
#   include "intertask_interface.h"
62 63
#endif

64 65 66 67 68 69
//#define DIAG_PHY

#define NS_PER_SLOT 500000

#define PUCCH 1

70 71
void exit_fun(const char* s);

72 73
extern int exit_openair;

74 75
// Fix per CC openair rf/if device update
// extern openair0_device openair0;
76

77 78 79
unsigned char dlsch_input_buffer[2700] __attribute__ ((aligned(32)));
int eNB_sync_buffer0[640*6] __attribute__ ((aligned(32)));
int eNB_sync_buffer1[640*6] __attribute__ ((aligned(32)));
80 81
int *eNB_sync_buffer[2] = {eNB_sync_buffer0, eNB_sync_buffer1};

82
extern uint16_t hundred_times_log10_NPRB[100];
83

84
unsigned int max_peak_val;
85
int max_sync_pos;
86 87 88 89 90 91 92

//DCI_ALLOC_t dci_alloc[8];

#ifdef EMOS
fifo_dump_emos_eNB emos_dump_eNB;
#endif

93
#if defined(SMBV) 
94 95
extern const char smbv_fname[];
extern unsigned short config_frames[4];
96
extern uint8_t smbv_frame_cnt;
97 98 99 100 101 102
#endif

#ifdef DIAG_PHY
extern int rx_sig_fifo;
#endif

knopp's avatar
knopp committed
103
uint8_t is_SR_subframe(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id)
104
{
105

106 107
  const int subframe = proc->subframe_rx;
  const int frame = proc->frame_rx;
108

109
  LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking for SR TXOp(sr_ConfigIndex %d)\n",
110 111
        eNB->Mod_id,eNB->ulsch[UE_id]->rnti,frame,subframe,
        eNB->scheduling_request_config[UE_id].sr_ConfigIndex);
112

113 114
  if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 4) {        // 5 ms SR period
    if ((subframe%5) == eNB->scheduling_request_config[UE_id].sr_ConfigIndex)
115
      return(1);
116 117
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 14) { // 10 ms SR period
    if (subframe==(eNB->scheduling_request_config[UE_id].sr_ConfigIndex-5))
118
      return(1);
119 120
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 34) { // 20 ms SR period
    if ((10*(frame&1)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-15))
121
      return(1);
122 123
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 74) { // 40 ms SR period
    if ((10*(frame&3)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-35))
124
      return(1);
125 126
  } else if (eNB->scheduling_request_config[UE_id].sr_ConfigIndex <= 154) { // 80 ms SR period
    if ((10*(frame&7)+subframe) == (eNB->scheduling_request_config[UE_id].sr_ConfigIndex-75))
127
      return(1);
128 129 130 131
  }

  return(0);
}
132

133

134
int32_t add_ue(int16_t rnti, PHY_VARS_eNB *eNB)
135
{
136
  uint8_t i;
137

138 139

  LOG_D(PHY,"[eNB %d/%d] Adding UE with rnti %x\n",
140 141
        eNB->Mod_id,
        eNB->CC_id,
Cedric Roux's avatar
Cedric Roux committed
142
        (uint16_t)rnti);
143 144

  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
145
    if ((eNB->dlsch[i]==NULL) || (eNB->ulsch[i]==NULL)) {
146
      MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed add ue %"PRIx16" (ENOMEM)", rnti);
147 148
      LOG_E(PHY,"Can't add UE, not enough memory allocated\n");
      return(-1);
149
    } else {
150
      if (eNB->UE_stats[i].crnti==0) {
151
        MSC_LOG_EVENT(MSC_PHY_ENB, "0 Add ue %"PRIx16" ", rnti);
152
        LOG_D(PHY,"UE_id %d associated with rnti %x\n",i, (uint16_t)rnti);
153 154 155
        eNB->dlsch[i][0]->rnti = rnti;
        eNB->ulsch[i]->rnti = rnti;
        eNB->UE_stats[i].crnti = rnti;
knopp's avatar
knopp committed
156

157 158 159
	eNB->UE_stats[i].Po_PUCCH1_below = 0;
	eNB->UE_stats[i].Po_PUCCH1_above = (int32_t)pow(10.0,.1*(eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH+eNB->rx_total_gain_dB));
	eNB->UE_stats[i].Po_PUCCH        = (int32_t)pow(10.0,.1*(eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH+eNB->rx_total_gain_dB));
160
	LOG_D(PHY,"Initializing Po_PUCCH: p0_NominalPUCCH %d, gain %d => %d\n",
161 162 163
	      eNB->frame_parms.ul_power_control_config_common.p0_NominalPUCCH,
	      eNB->rx_total_gain_dB,
	      eNB->UE_stats[i].Po_PUCCH);
knopp's avatar
knopp committed
164
  
165
        return(i);
166
      }
167
    }
168 169 170 171
  }
  return(-1);
}

172
int mac_phy_remove_ue(module_id_t Mod_idP,rnti_t rntiP) {
173
  uint8_t i;
174
  int CC_id;
175
  PHY_VARS_eNB *eNB;
176 177

  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
178
    eNB = PHY_vars_eNB_g[Mod_idP][CC_id];
179
    for (i=0; i<NUMBER_OF_UE_MAX; i++) {
180
      if ((eNB->dlsch[i]==NULL) || (eNB->ulsch[i]==NULL)) {
181 182 183 184
	MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (ENOMEM)", rnti);
	LOG_E(PHY,"Can't remove UE, not enough memory allocated\n");
	return(-1);
      } else {
185
	if (eNB->UE_stats[i].crnti==rntiP) {
186
	  MSC_LOG_EVENT(MSC_PHY_ENB, "0 Removed ue %"PRIx16" ", rntiP);
187 188 189

	  LOG_D(PHY,"eNB %d removing UE %d with rnti %x\n",eNB->Mod_id,i,rntiP);

190
	  //LOG_D(PHY,("[PHY] UE_id %d\n",i);
191 192 193 194
	  clean_eNb_dlsch(eNB->dlsch[i][0]);
	  clean_eNb_ulsch(eNB->ulsch[i]);
	  //eNB->UE_stats[i].crnti = 0;
	  memset(&eNB->UE_stats[i],0,sizeof(LTE_eNB_UE_stats));
195 196
	  //  mac_exit_wrapper("Removing UE");
	  
197

198 199
	  return(i);
	}
200
      }
201
    }
202
  }
203
  MSC_LOG_EVENT(MSC_PHY_ENB, "0 Failed remove ue %"PRIx16" (not found)", rntiP);
204 205 206
  return(-1);
}

207
int8_t find_next_ue_index(PHY_VARS_eNB *eNB)
208
{
209
  uint8_t i;
210

211
  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
212 213
    if (eNB->UE_stats[i].crnti==0) {
      /*if ((eNB->dlsch[i]) &&
214 215
	(eNB->dlsch[i][0]) &&
	(eNB->dlsch[i][0]->rnti==0))*/
216 217 218
      LOG_D(PHY,"Next free UE id is %d\n",i);
      return(i);
    }
219
  }
220

221 222 223
  return(-1);
}

gauthier's avatar
gauthier committed
224
int get_ue_active_harq_pid(const uint8_t Mod_id,const uint8_t CC_id,const uint16_t rnti, const int frame, const uint8_t subframe,uint8_t *harq_pid,uint8_t *round,const uint8_t ul_flag)
225 226 227 228
{
  LTE_eNB_DLSCH_t *DLSCH_ptr;
  LTE_eNB_ULSCH_t *ULSCH_ptr;
  uint8_t ulsch_subframe,ulsch_frame;
229
  int i;
230
  int8_t UE_id = find_ue(rnti,PHY_vars_eNB_g[Mod_id][CC_id]);
231 232

  if (UE_id==-1) {
233
    LOG_D(PHY,"Cannot find UE with rnti %x (Mod_id %d, CC_id %d)\n",rnti, Mod_id, CC_id);
234 235
    *round=0;
    return(-1);
236 237 238
  }

  if (ul_flag == 0)  {// this is a DL request
239
    DLSCH_ptr = PHY_vars_eNB_g[Mod_id][CC_id]->dlsch[(uint32_t)UE_id][0];
240

241 242
    /* let's go synchronous for the moment - maybe we can change at some point */
    i = (frame * 10 + subframe) % 8;
243

244 245 246 247 248
    if (DLSCH_ptr->harq_processes[i]->status == ACTIVE) {
      *harq_pid = i;
      *round = DLSCH_ptr->harq_processes[i]->round;
    } else if (DLSCH_ptr->harq_processes[i]->status == SCH_IDLE) {
      *harq_pid = i;
249
      *round = 0;
250 251 252
    } else {
      printf("%s:%d: bad state for harq process - PLEASE REPORT!!\n", __FILE__, __LINE__);
      abort();
253
    }
254
  } else { // This is a UL request
255

256 257 258
    ULSCH_ptr = PHY_vars_eNB_g[Mod_id][CC_id]->ulsch[(uint32_t)UE_id];
    ulsch_subframe = pdcch_alloc2ul_subframe(&PHY_vars_eNB_g[Mod_id][CC_id]->frame_parms,subframe);
    ulsch_frame    = pdcch_alloc2ul_frame(&PHY_vars_eNB_g[Mod_id][CC_id]->frame_parms,frame,subframe);
259
    // Note this is for TDD configuration 3,4,5 only
260
    *harq_pid = subframe2harq_pid(&PHY_vars_eNB_g[Mod_id][CC_id]->frame_parms,
261 262
                                  ulsch_frame,
                                  ulsch_subframe);
263
    *round    = ULSCH_ptr->harq_processes[*harq_pid]->round;
264
    LOG_T(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d Checking HARQ, round %d\n",Mod_id,*harq_pid,frame,subframe,*round);
265
  }
266

267 268 269
  return(0);
}

knopp's avatar
knopp committed
270
int16_t get_target_pusch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
271
{
272
  return PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.ul_power_control_config_common.p0_NominalPUSCH;
273 274
}

knopp's avatar
knopp committed
275 276
int16_t get_target_pucch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
{
277
  return PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.ul_power_control_config_common.p0_NominalPUCCH;
knopp's avatar
knopp committed
278 279
}

280
#ifdef EMOS
281
void phy_procedures_emos_eNB_TX(unsigned char subframe, PHY_VARS_eNB *eNB)
282
{
283 284 285 286

}
#endif

287

288

289
void phy_procedures_eNB_S_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,relaying_type_t r_type)
290 291
{
  UNUSED(r_type);
292
  int subframe = proc->subframe_rx;
293

294
#ifdef DEBUG_PHY_PROC
295
  LOG_D(PHY,"[eNB %d] Frame %d: Doing phy_procedures_eNB_S_RX(%d)\n", eNB->Mod_id,proc->frame_rx, subframe);
296
#endif
297

298

299
  if (eNB->abstraction_flag == 0) {
300
    lte_eNB_I0_measurements(eNB,
301
			    subframe,
302
                            0,
303
                            eNB->first_run_I0_measurements);
304
  }
305

306
#ifdef PHY_ABSTRACTION
307
  else {
308
    lte_eNB_I0_measurements_emul(eNB,
309
                                 0);
310
  }
311

312 313
#endif

314

315 316
}

317 318


319
#ifdef EMOS
320
void phy_procedures_emos_eNB_RX(unsigned char subframe,PHY_VARS_eNB *eNB)
321 322
{

323 324
  uint8_t aa;
  uint16_t last_subframe_emos;
325
  uint16_t pilot_pos1 = 3 - eNB->frame_parms.Ncp, pilot_pos2 = 10 - 2*eNB->frame_parms.Ncp;
326
  uint32_t bytes;
327 328 329

  last_subframe_emos=0;

330

331

332

333
#ifdef EMOS_CHANNEL
334

335
  //if (last_slot%2==1) // this is for all UL subframes
336
  if (subframe==3)
337 338 339 340 341 342 343
    for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
      memcpy(&emos_dump_eNB.channel[aa][last_subframe_emos*2*eNB->frame_parms.N_RB_UL*12],
             &eNB->pusch_vars[0]->drs_ch_estimates[0][aa][eNB->frame_parms.N_RB_UL*12*pilot_pos1],
             eNB->frame_parms.N_RB_UL*12*sizeof(int));
      memcpy(&emos_dump_eNB.channel[aa][(last_subframe_emos*2+1)*eNB->frame_parms.N_RB_UL*12],
             &eNB->pusch_vars[0]->drs_ch_estimates[0][aa][eNB->frame_parms.N_RB_UL*12*pilot_pos2],
             eNB->frame_parms.N_RB_UL*12*sizeof(int));
344
    }
345

346 347
#endif

348
  if (subframe==4) {
349
    emos_dump_eNB.timestamp = rt_get_time_ns();
350 351 352 353 354
    emos_dump_eNB.frame_tx = eNB->proc[subframe].frame_rx;
    emos_dump_eNB.rx_total_gain_dB = eNB->rx_total_gain_dB;
    emos_dump_eNB.mimo_mode = eNB->transmission_mode[0];
    memcpy(&emos_dump_eNB.measurements,
           &eNB->measurements[0],
355
           sizeof(PHY_MEASUREMENTS_eNB));
356
    memcpy(&emos_dump_eNB.UE_stats[0],&eNB->UE_stats[0],NUMBER_OF_UE_MAX*sizeof(LTE_eNB_UE_stats));
357 358

    bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, &emos_dump_eNB, sizeof(fifo_dump_emos_eNB));
359

360 361
    //bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, "test", sizeof("test"));
    if (bytes!=sizeof(fifo_dump_emos_eNB)) {
362
      LOG_W(PHY,"[eNB %d] Frame %d, subframe %d, Problem writing EMOS data to FIFO (bytes=%d, size=%d)\n",
363
            eNB->Mod_id,eNB->proc[(subframe+1)%10].frame_rx, subframe,bytes,sizeof(fifo_dump_emos_eNB));
364
    } else {
365
      if (eNB->proc[(subframe+1)%10].frame_tx%100==0) {
366
        LOG_I(PHY,"[eNB %d] Frame %d (%d), subframe %d, Writing %d bytes EMOS data to FIFO\n",
367
              eNB->Mod_id,eNB->proc[(subframe+1)%10].frame_rx, ((fifo_dump_emos_eNB*)&emos_dump_eNB)->frame_tx, subframe, bytes);
368
      }
369
    }
370 371 372 373 374 375 376
  }
}
#endif


#define AMP_OVER_SQRT2 ((AMP*ONE_OVER_SQRT2_Q15)>>15)
#define AMP_OVER_2 (AMP>>1)
377 378
int QPSK[4]= {AMP_OVER_SQRT2|(AMP_OVER_SQRT2<<16),AMP_OVER_SQRT2|((65536-AMP_OVER_SQRT2)<<16),((65536-AMP_OVER_SQRT2)<<16)|AMP_OVER_SQRT2,((65536-AMP_OVER_SQRT2)<<16)|(65536-AMP_OVER_SQRT2)};
int QPSK2[4]= {AMP_OVER_2|(AMP_OVER_2<<16),AMP_OVER_2|((65536-AMP_OVER_2)<<16),((65536-AMP_OVER_2)<<16)|AMP_OVER_2,((65536-AMP_OVER_2)<<16)|(65536-AMP_OVER_2)};
379

gauthier's avatar
gauthier committed
380

381

Cedric Roux's avatar
Cedric Roux committed
382
unsigned int taus(void);
383
DCI_PDU DCI_pdu_tmp;
384

385

386
void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,PHY_VARS_RN *rn,relaying_type_t r_type) {
387 388


389
#ifdef Rel10
390 391
  MCH_PDU *mch_pduP;
  MCH_PDU  mch_pdu;
392
  //  uint8_t sync_area=255;
393
#endif
394

395
  int subframe = proc->subframe_tx;
396

397
  if (eNB->abstraction_flag==0) {
398 399
    // This is DL-Cell spec pilots in Control region
    generate_pilots_slot(eNB,
400
			 eNB->common_vars.txdataF[0],
401 402
			 AMP,
			 subframe<<1,1);
403
  }
404
  
405
#ifdef Rel10
406 407 408 409
  // 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
  mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
				    eNB->CC_id,
410
				    proc->frame_tx,
411 412 413 414 415 416
				    subframe);
  
  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
      LOG_I(PHY,"[eNB%"PRIu8"] Frame %d subframe %d : Got MCH pdu for MBSFN (MCS %"PRIu8", TBS %d) \n",
417 418
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->mcs,
	    eNB->dlsch_MCH->harq_processes[0]->TBS>>3);
419 420
    else {
      LOG_D(PHY,"[DeNB %"PRIu8"] Frame %d subframe %d : Do not transmit MCH pdu for MBSFN sync area %"PRIu8" (%s)\n",
421
	    eNB->Mod_id,proc->frame_tx,subframe,mch_pduP->sync_area,
422 423
	    (mch_pduP->Pdu_size == 0)? "Empty MCH PDU":"Let RN transmit for the moment");
      mch_pduP = NULL;
gauthier's avatar
gauthier committed
424
    }
425
    
426
    break;
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
    
  case multicast_relay:
    if ((mch_pduP->Pdu_size > 0) && ((mch_pduP->mcch_active == 1) || mch_pduP->msi_active==1)) {
      LOG_I(PHY,"[RN %"PRIu8"] Frame %d subframe %d: Got the MCH PDU for MBSFN  sync area %"PRIu8" (MCS %"PRIu8", TBS %"PRIu16")\n",
	    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;
      LOG_I(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",
	    rn->Mod_id,rn->frame, subframe,subframe%5,
	    rn->sync_area[subframe%5],mch_pduP->mcs,mch_pduP->Pdu_size);
443
    } else {
444
      mch_pduP=NULL;
445
    }
446 447
    
    rn->mch_avtive[subframe]=0;
448
    break;
449
    
450
  default:
451
    LOG_W(PHY,"[eNB %"PRIu8"] Frame %d subframe %d: unknown relaying type %d \n",
452
	  eNB->Mod_id,proc->frame_tx,subframe,r_type);
453 454 455 456 457
    mch_pduP=NULL;
    break;
  }// switch
  
  if (mch_pduP) {
458
    fill_eNB_dlsch_MCH(eNB,mch_pduP->mcs,1,0);
459
    // Generate PMCH
460
    generate_mch(eNB,proc,(uint8_t*)mch_pduP->payload);
461
  } else {
462
    LOG_D(PHY,"[eNB/RN] Frame %d subframe %d: MCH not generated \n",proc->frame_tx,subframe);
463
  }
464
  
465
#endif
466
}
467

468
void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
469

470 471
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
  int **txdataF = eNB->common_vars.txdataF[0];
472
  uint8_t *pbch_pdu=&eNB->pbch_pdu[0];
473 474
  int subframe = proc->subframe_tx;
  int frame = proc->frame_tx;
475

476
  // generate Cell-Specific Reference Signals for both slots
477
  if (eNB->abstraction_flag==0) {
478 479 480 481 482 483 484 485 486 487 488 489 490 491
    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)
      generate_pilots_slot(eNB,
			   txdataF,
			   AMP,
			   (subframe<<1)+1,0);
    
    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
  }    
492

493
  // First half of PSS/SSS (FDD, slot 0)
494
  if (subframe == 0) {
495
    if ((fp->frame_type == FDD) &&
496
	(eNB->abstraction_flag==0)) {
497 498 499 500 501 502 503 504 505 506 507
      generate_pss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   0);
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 5 : 4,
		   0);
      
508
    }
509
    
510
    // generate PBCH (Physical Broadcast CHannel) info
511
    if ((frame&3) == 0) {
512
      pbch_pdu[2] = 0;
513
      
514
      // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators
515
      switch (fp->N_RB_DL) {
516
      case 6:
517 518
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5);
	break;
519
	
520
      case 15:
521 522 523
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5);
	break;
	
524
      case 25:
525 526 527
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
	break;
	
528
      case 50:
529 530 531
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5);
	break;
	
532
      case 75:
533 534 535
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5);
	break;
	
536
      case 100:
537 538 539
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5);
	break;
	
540
      default:
541 542 543
	// FIXME if we get here, this should be flagged as an error, right?
	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
	break;
544
      }
545
      
546
      pbch_pdu[2] = (pbch_pdu[2]&0xef) |
547 548 549
	((fp->phich_config_common.phich_duration << 4)&0x10);
      
      switch (fp->phich_config_common.phich_resource) {
550
      case oneSixth:
551 552 553
	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2);
	break;
	
554
      case half:
555 556 557
	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2);
	break;
	
558
      case one:
559 560 561
	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2);
	break;
	
562
      case two:
563 564 565
	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2);
	break;
	
566
      default:
567 568
	// unreachable
	break;
569
      }
570
      
571 572
      pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((frame>>8)&0x3);
      pbch_pdu[1] = frame&0xfc;
573
      pbch_pdu[0] = 0;
574
    }
575 576 577 578
      
    /// First half of SSS (TDD, slot 1)
    
    if ((fp->frame_type == TDD)&&
579
	(eNB->abstraction_flag==0)){
580 581 582 583 584 585
      generate_sss(txdataF,
		   AMP,
		   fp,
		   (fp->Ncp==NORMAL) ? 6 : 5,
		   1);
    }
586

587
    /// generate PBCH
588
    if (eNB->abstraction_flag==0) {
589
      generate_pbch(&eNB->pbch,
590 591 592 593
                    txdataF,
                    AMP,
                    fp,
                    pbch_pdu,
594
                    frame&3);
595 596 597 598
    }
#ifdef PHY_ABSTRACTION
    else {
      generate_pbch_emul(eNB,pbch_pdu);
599
    }
600
#endif
601

602 603 604
  }
  else if ((subframe == 1) &&
	   (fp->frame_type == TDD)&&
605
	   (eNB->abstraction_flag==0)) {
606 607 608 609 610
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 2);
611
  }
612 613 614 615
  
  // Second half of PSS/SSS (FDD, slot 10)
  else if ((subframe == 5) && 
	   (fp->frame_type == FDD) &&
616
	   (eNB->abstraction_flag==0)) {
617 618 619 620 621 622 623 624 625 626
    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);
627

628
  }
629

630 631 632
  //  Second-half of SSS (TDD, slot 11)
  else if ((subframe == 5) &&
	   (fp->frame_type == TDD) &&
633
	   (eNB->abstraction_flag==0)) {
634 635 636 637 638
    generate_sss(txdataF,
		 AMP,
		 fp,
		 (fp->Ncp==NORMAL) ? 6 : 5,
		 11);
639
  }
640

641 642 643
  // Second half of PSS (TDD, slot 12)
  else if ((subframe == 6) &&
	   (fp->frame_type == TDD) &&
644
	   (eNB->abstraction_flag==0)) {
645 646 647 648 649 650
    generate_pss(txdataF,
		 AMP,
		 fp,
		 2,
		 12);
  }
651

652
}
653

knopp's avatar
knopp committed
654
void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
655

656
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
657 658
  int frame = proc->frame_tx;
  int subframe = proc->subframe_tx;
659 660 661 662 663 664 665 666 667

  // if we have SI_RNTI, configure dlsch parameters and CCE index
  if (dci_alloc->rnti == SI_RNTI) {
    LOG_D(PHY,"Generating dlsch params for SI_RNTI\n");
    generate_eNB_dlsch_params_from_dci(frame,
				       subframe,
				       &dci_alloc->dci_pdu[0],
				       dci_alloc->rnti,
				       dci_alloc->format,
668
				       &eNB->dlsch_SI,
669 670 671 672 673
				       fp,
				       eNB->pdsch_config_dedicated,
				       SI_RNTI,
				       0,
				       P_RNTI,
674
				       eNB->UE_stats[0].DL_pmi_single);
675 676
    
    
677
    eNB->dlsch_SI->nCCE[subframe] = dci_alloc->firstCCE;
678
    
679
    LOG_T(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (SI)  => %"PRIu8"\n",eNB->Mod_id,frame,subframe,
680
	  eNB->dlsch_SI->nCCE[subframe]);
681 682 683 684
    
#if defined(SMBV) 
    
    // configure SI DCI
685 686
    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
      LOG_D(PHY,"[SMBV] Frame %3d, SI in SF %d DCI %"PRIu32"\n",frame,subframe,i);
687 688 689 690 691 692 693 694 695 696 697 698 699 700
      smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "SI", dci_alloc, i);
    }
    
#endif
    
    
  } else if (dci_alloc->ra_flag == 1) {  // This is format 1A allocation for RA
    // configure dlsch parameters and CCE index
    LOG_D(PHY,"Generating dlsch params for RA_RNTI\n");    
    generate_eNB_dlsch_params_from_dci(frame,
				       subframe,
				       &dci_alloc->dci_pdu[0],
				       dci_alloc->rnti,
				       dci_alloc->format,
701
				       &eNB->dlsch_ra,
702 703 704 705 706
				       fp,
				       eNB->pdsch_config_dedicated,
				       SI_RNTI,
				       dci_alloc->rnti,
				       P_RNTI,
707
				       eNB->UE_stats[0].DL_pmi_single);
708 709
    
    
710
    eNB->dlsch_ra->nCCE[subframe] = dci_alloc->firstCCE;
711
    
712
    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (RA)  => %"PRIu8"\n",eNB->Mod_id,frame,subframe,
713
	  eNB->dlsch_ra->nCCE[subframe]);
714 715 716
#if defined(SMBV) 
    
    // configure RA DCI
717 718
    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
      LOG_D(PHY,"[SMBV] Frame %3d, RA in SF %d DCI %"PRIu32"\n",frame,subframe,i);
719
      smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "RA", dci_alloc, i);
720
    }
721 722 723 724 725 726 727 728 729 730
    
#endif
    
  }
  
  else if ((dci_alloc->format != format0)&&
	   (dci_alloc->format != format3)&&
	   (dci_alloc->format != format3A)&&
	   (dci_alloc->format != format4)){ // this is a normal DLSCH allocation
    
731

732 733 734 735
    
    if (UE_id>=0) {
#if defined(SMBV) 
      // Configure this user
736 737
      if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
	LOG_D(PHY,"[SMBV] Frame %3d, SF %d (SMBV SF %d) Configuring user %d with RNTI %"PRIu16" in TM%"PRIu8"\n",frame,subframe,(smbv_frame_cnt*10) + (subframe),UE_id+1,
738 739
              dci_alloc->rnti,eNB->transmission_mode[(uint8_t)UE_id]);
	smbv_configure_user(smbv_fname,UE_id+1,eNB->transmission_mode[(uint8_t)UE_id],dci_alloc->rnti);
740
      }
741 742
      
#endif
743

744 745 746 747 748 749
      LOG_D(PHY,"Generating dlsch params for RNTI %x\n",dci_alloc->rnti);      
      generate_eNB_dlsch_params_from_dci(frame,
					 subframe,
					 &dci_alloc->dci_pdu[0],
					 dci_alloc->rnti,
					 dci_alloc->format,
750
					 eNB->dlsch[(uint8_t)UE_id],
751 752 753 754 755
					 fp,
					 eNB->pdsch_config_dedicated,
					 SI_RNTI,
					 0,
					 P_RNTI,
756
					 eNB->UE_stats[(uint8_t)UE_id].DL_pmi_single);
757
      LOG_D(PHY,"[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d subframe %d: Generated dlsch params\n",
758
	    eNB->Mod_id,dci_alloc->rnti,eNB->dlsch[(uint8_t)UE_id][0]->current_harq_pid,frame,subframe);
759 760
      
      
Cedric Roux's avatar
Cedric Roux committed
761 762
      T(T_ENB_PHY_DLSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
        T_INT(dci_alloc->rnti), T_INT(dci_alloc->format),
Cedric Roux's avatar
Cedric Roux committed
763
        T_INT(eNB->dlsch[(int)UE_id][0]->current_harq_pid),
764 765
        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[eNB->dlsch[(int)UE_id][0]->current_harq_pid]->mcs),
        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[eNB->dlsch[(int)UE_id][0]->current_harq_pid]->TBS));
766

767
      eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe] = dci_alloc->firstCCE;
768
      
769
      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for ue DCI (PDSCH %"PRIx16")  => %"PRIu8"/%u\n",eNB->Mod_id,frame,subframe,
770
	    dci_alloc->rnti,eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe]);
771 772 773 774
      
#if defined(SMBV) 
      
      // configure UE-spec DCI
775 776
      if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
	LOG_D(PHY,"[SMBV] Frame %3d, PDSCH in SF %d DCI %"PRIu32"\n",frame,subframe,i);
777
	smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1,dci_alloc, i);
778
      }
779
      
780
#endif
781 782 783
      
      LOG_D(PHY,"[eNB %"PRIu8"][DCI][PDSCH %"PRIx16"] Frame %d subframe %d UE_id %"PRId8" Generated DCI format %d, aggregation %d\n",
	    eNB->Mod_id, dci_alloc->rnti,
784
	    frame, subframe,UE_id,
785 786
	    dci_alloc->format,
	    1<<dci_alloc->L);
787
    } else {
788
      LOG_D(PHY,"[eNB %"PRIu8"][PDSCH] Frame %d : No UE_id with corresponding rnti %"PRIx16", dropping DLSCH\n",
789
	    eNB->Mod_id,frame,dci_alloc->rnti);
790
    }
791
  }
792 793
  
}
794

knopp's avatar
knopp committed
795
void generate_eNB_ulsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
796

797
  int harq_pid;
798
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
799
  int frame = proc->frame_tx;
knopp's avatar
knopp committed
800
  int subframe = proc->subframe_tx;
801

802
  LOG_D(PHY,
803 804 805
	"[eNB %"PRIu8"][PUSCH %"PRIu8"] Frame %d subframe %d UL Frame %"PRIu32", UL Subframe %"PRIu8", Generated ULSCH (format0) DCI (rnti %"PRIx16", dci %"PRIx8"), aggregation %d\n",
	eNB->Mod_id,
	subframe2harq_pid(fp,
806
			  pdcch_alloc2ul_frame(fp,frame,subframe),
807
			  pdcch_alloc2ul_subframe(fp,subframe)),
808
	frame,
809
	subframe,
810
	pdcch_alloc2ul_frame(fp,frame,subframe),
811 812 813 814 815
	pdcch_alloc2ul_subframe(fp,subframe),
	dci_alloc->rnti,
	dci_alloc->dci_pdu[0],
	1<<dci_alloc->L);
  
816
  generate_eNB_ulsch_params_from_dci(eNB,
knopp's avatar
knopp committed
817
				     proc,
818
				     &dci_alloc->dci_pdu[0],
819 820 821 822 823 824 825 826 827 828
				     dci_alloc->rnti,
				     format0,
				     UE_id,
				     SI_RNTI,
				     0,
				     P_RNTI,
				     CBA_RNTI,
				     0);  // do_srs
  
  LOG_T(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resources for UE spec DCI (PUSCH %"PRIx16") => %d\n",
829
	eNB->Mod_id,frame,subframe,dci_alloc->rnti,
830 831 832 833 834
	dci_alloc->firstCCE);
  
#if defined(SMBV) 
  
  // configure UE-spec DCI for UL Grant
835 836
  if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
    LOG_D(PHY,"[SMBV] Frame %3d, SF %d UL DCI %"PRIu32"\n",frame,subframe,i);
837
    smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1, &DCI_pdu->dci_alloc[i], i);
838
  }
839 840 841 842 843 844
  
#endif
  
  
  // get the hard_pid for this subframe 
  harq_pid = subframe2harq_pid(fp,
845
			       pdcch_alloc2ul_frame(fp,frame,subframe),
846 847 848
			       pdcch_alloc2ul_subframe(fp,subframe));
  
  if (harq_pid==255) { // should not happen, log an error and exit, this is a fatal error
849
    LOG_E(PHY,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",eNB->Mod_id,frame);
850 851 852 853
    mac_xface->macphy_exit("FATAL\n"); 
  }
  
  if ((dci_alloc->rnti  >= CBA_RNTI) && (dci_alloc->rnti < P_RNTI))
854
    eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag = 1;
855
  else
856
    eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
857
  
Cedric Roux's avatar
Cedric Roux committed
858
  T(T_ENB_PHY_ULSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
Cedric Roux's avatar
Cedric Roux committed
859 860 861 862 863 864
    T_INT(dci_alloc->rnti), T_INT(harq_pid),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->mcs),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->round),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->first_rb),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->nb_rb),
    T_INT(eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->TBS));
865
}
866

867
void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *dlsch, LTE_eNB_DLSCH_t *dlsch1,LTE_eNB_UE_stats *ue_stats,int ra_flag,int num_pdcch_symbols) {
868

869 870
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
871 872 873
  int harq_pid = dlsch->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch_harq=dlsch->harq_processes[harq_pid];
  int input_buffer_length = dlsch_harq->TBS/8;
874
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
875 876 877 878
  uint8_t *DLSCH_pdu=NULL;
  uint8_t DLSCH_pdu_tmp[768*8];
  uint8_t DLSCH_pdu_rar[256];
  int i;
879

880 881 882
  LOG_D(PHY,
	"[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d, subframe %d: Generating PDSCH/DLSCH with input size = %"PRIu16", G %d, nb_rb %"PRIu16", mcs %"PRIu8", pmi_alloc %"PRIx16", rv %"PRIu8" (round %"PRIu8")\n",
	eNB->Mod_id, dlsch->rnti,harq_pid,
883
	frame, subframe, input_buffer_length,