eNB_scheduler.c 20.6 KB
Newer Older
1
/*! \file eNB_scheduler.c
nikaeinn's avatar
nikaeinn committed
2
 * \brief eNB scheduler top level function operates on per subframe basis
3 4
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
5
 * \email: navid.nikaein@eurecom.fr
6 7
 * \version 0.5
 * @ingroup _mac
8

9
 */
10

11
#include "assertions.h"
12 13 14 15 16 17 18 19
#include "PHY/defs.h"
#include "PHY/extern.h"

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

#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/extern.h"
gauthier's avatar
gauthier committed
20

21 22 23 24 25 26
#include "LAYER2/MAC/proto.h"
#include "UTIL/LOG/log.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"
gauthier's avatar
gauthier committed
27

28 29
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
gauthier's avatar
gauthier committed
30

31 32
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
33

34 35
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
36 37
#endif

38 39 40 41
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1
//#define DEBUG_HEADER_PARSING 1
//#define DEBUG_PACKET_TRACE 1
gauthier's avatar
gauthier committed
42

43 44 45 46 47
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
gauthier's avatar
gauthier committed
48 49 50



51

52 53 54



55 56
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
57

knopp's avatar
 
knopp committed
58
  int mbsfn_status[MAX_NUM_CCs];
59
  protocol_ctxt_t   ctxt;
60
#ifdef EXMIMO
Cedric Roux's avatar
Cedric Roux committed
61
  //int ret;
62
#endif
63
#if defined(ENABLE_ITTI)
64
  MessageDef   *msg_p;
65
  const char         *msg_name;
66 67
  instance_t    instance;
  int           result;
68
#endif
knopp's avatar
 
knopp committed
69
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
knopp's avatar
 
knopp committed
70
  int CC_id,i,next_i;
knopp's avatar
 
knopp committed
71
  UE_list_t *UE_list=&eNB_mac_inst[module_idP].UE_list;
72
  rnti_t rnti;
73
  void         *DLSCH_dci=NULL;
74
  int size_bits=0,size_bytes=0;
75

76
  LOG_D(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler (UE_list->head %d)\n",module_idP, frameP, subframeP,UE_list->head);
77

78
  start_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
gauthier's avatar
gauthier committed
79
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
80

81
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
82 83
    DCI_pdu[CC_id] = &eNB_mac_inst[module_idP].common_channels[CC_id].DCI_pdu;
    mbsfn_status[CC_id]=0;
84 85
    // clear vrb_map
    memset(eNB_mac_inst[module_idP].common_channels[CC_id].vrb_map,0,100);
knopp's avatar
 
knopp committed
86
  }
87

knopp's avatar
 
knopp committed
88
  // refresh UE list based on UEs dropped by PHY in previous subframe
89 90 91
  i = UE_list->head;

  while (i>=0) {
92 93
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
94 95 96 97
    if ((frameP==0)&&(subframeP==0))
      LOG_I(MAC,"UE  rnti %x : %s\n", rnti, 
	    UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync");

98
    next_i= UE_list->next[i];
99

100 101 102
    PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63;
    if (i==UE_list->head)
      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR,PHY_vars_eNB_g[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]); 
103 104
    // increment this, it is cleared when we receive an sdu
    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
105 106

    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].cqi_req_timer++;
107
    
108
    if (mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti)==NULL) {
109
      //      mac_remove_ue(module_idP, i, frameP, subframeP);
110
    }
111 112
    else {
      // check uplink failure
Florian Kaltenberger's avatar
Florian Kaltenberger committed
113 114 115 116 117 118 119
      if ((UE_list->UE_sched_ctrl[i].ul_failure_timer>0)&&
	  (UE_list->UE_sched_ctrl[i].ul_out_of_sync==0)) {
	LOG_D(MAC,"UE %d rnti %x: UL Failure timer %d \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
	if (UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent==0) {
	  UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=1;
	  
	  // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
120
	  LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    
Florian Kaltenberger's avatar
Florian Kaltenberger committed
121 122
	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
	  *(uint32_t*)DLSCH_dci = 0;
123 124
	  if (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.frame_type == TDD) {
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	    case 6:
	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
	      break;
	    case 25:
	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 511;
	      size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
	      break;
	    case 50:
	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
	      break;
	    case 100:
	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 8191;
	      size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
	      size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
	      break;
149
	    }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
150 151
	  }
	  else { // FDD
152
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->frame_parms.N_RB_DL) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
153 154 155 156 157 158
	    case 6:
	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
	      break;
159 160 161 162 163 164
	    case 15:/*
	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;*/
	      break;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
165 166 167 168 169 170 171 172 173 174 175
	    case 25:
	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->rballoc = 511;
	      size_bytes = sizeof(DCI1A_5MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_5MHz_FDD_t;
	      break;
	    case 50:
	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;
176
		break;
177 178 179 180 181 182
	    case 75:
	      /*	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;*/
		break;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
183 184 185 186 187 188
	    case 100:
	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->type = 1;
	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->rballoc = 8191;
	      size_bytes = sizeof(DCI1A_20MHz_FDD_t);
	      size_bits  = sizeof_DCI1A_20MHz_FDD_t;
	      break;
189 190
	    }
	  }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
191 192 193 194 195 196 197 198 199
	  
	  add_ue_spec_dci(DCI_pdu[CC_id],
			  DLSCH_dci,
			  rnti,
			    size_bytes,
			  process_ue_cqi (module_idP,i),//aggregation,
			  size_bits,
			  format1A,
			  0);
200
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
201
	else { // ra_pdcch_sent==1
202
	  LOG_D(MAC,"UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    	    
Florian Kaltenberger's avatar
Florian Kaltenberger committed
203 204
	  if ((UE_list->UE_sched_ctrl[i].ul_failure_timer % 40) == 0)
	    UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=0; // resend every 4 frames	      
205
	}
206 207 208 209 210
      
	UE_list->UE_sched_ctrl[i].ul_failure_timer++;
	// check threshold
	if (UE_list->UE_sched_ctrl[i].ul_failure_timer > 200) {
	  // inform RRC of failure and clear timer
211
	  LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
212 213 214 215
	  mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
	  UE_list->UE_sched_ctrl[i].ul_failure_timer=0;
	  UE_list->UE_sched_ctrl[i].ul_out_of_sync=1;
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
216 217 218
      }
    } // ul_failure_timer>0
    
219
    i = next_i;
knopp's avatar
 
knopp committed
220
  }
221

222
#if defined(ENABLE_ITTI)
223

224
  do {
225 226
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
227

228 229 230
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
231

232 233 234 235
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
236

237 238 239 240
      case RRC_MAC_BCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_BCCH_DATA_REQ (msg_p).frame, RRC_MAC_BCCH_DATA_REQ (msg_p).enb_index);
241

242 243
        // TODO process BCCH data req.
        break;
244

245 246 247 248
      case RRC_MAC_CCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_CCCH_DATA_REQ (msg_p).frame, RRC_MAC_CCCH_DATA_REQ (msg_p).enb_index);
249

250 251
        // TODO process CCCH data req.
        break;
252 253 254

#ifdef Rel10

255 256 257 258
      case RRC_MAC_MCCH_DATA_REQ:
        LOG_D(MAC, "Received %s from %s: instance %d, frameP %d, eNB_index %d, mbsfn_sync_area %d\n",
              msg_name, ITTI_MSG_ORIGIN_NAME(msg_p), instance,
              RRC_MAC_MCCH_DATA_REQ (msg_p).frame, RRC_MAC_MCCH_DATA_REQ (msg_p).enb_index, RRC_MAC_MCCH_DATA_REQ (msg_p).mbsfn_sync_area);
259

260 261 262
        // TODO process MCCH data req.
        break;
#endif
263

264 265 266
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
267
      }
268 269 270 271

      result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p);
      AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
    }
272
  } while(msg_p != NULL);
273

274 275
#endif

gauthier's avatar
gauthier committed
276
  // clear DCI and BCCH contents before scheduling
277
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
278 279
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
280

281

282
#ifdef Rel10
283
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
284
#endif
285

knopp's avatar
 
knopp committed
286 287
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
288 289


knopp's avatar
 
knopp committed
290
  }
291

gauthier's avatar
gauthier committed
292
  //if (subframeP%5 == 0)
knopp's avatar
 
knopp committed
293
  //#ifdef EXMIMO
294
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
295
  pdcp_run(&ctxt);
knopp's avatar
 
knopp committed
296
  //#endif
297

298
  // check HO
299 300
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
301
            CC_id);
302 303

#ifdef Rel10
304 305

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
306 307 308 309
    if (eNB_mac_inst[module_idP].common_channels[CC_id].MBMS_flag >0) {
      start_meas(&eNB_mac_inst[module_idP].schedule_mch);
      mbsfn_status[CC_id] = schedule_MBMS(module_idP,CC_id,frameP,subframeP);
      stop_meas(&eNB_mac_inst[module_idP].schedule_mch);
knopp's avatar
 
knopp committed
310
    }
311
  }
312

313
#endif
knopp's avatar
 
knopp committed
314
  // refresh UE list based on UEs dropped by PHY in previous subframe
315
  /*
knopp's avatar
 
knopp committed
316 317 318
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
319
    LOG_T(MAC,"UE %d : rnti %x, stats %p\n",i,UE_RNTI(module_idP,i),mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i)));
knopp's avatar
 
knopp committed
320
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
 
knopp committed
321
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
 
knopp committed
322 323 324
    }
    i=next_i;
  }
325
  */
326

gauthier's avatar
gauthier committed
327
  switch (subframeP) {
328
  case 0:
329

330
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
331
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
332
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
333

knopp's avatar
knopp committed
334

335 336
    schedule_RA(module_idP,frameP,subframeP,2);

337

338
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
339
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
340 341 342
    } else if  ((mac_xface->frame_parms->tdd_config == TDD) || //TDD
                (mac_xface->frame_parms->tdd_config == 3) ||
                (mac_xface->frame_parms->tdd_config == 6)) {
343
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
344
    }
345

346 347
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
348

349 350 351
    break;

  case 1:
352

gauthier's avatar
gauthier committed
353
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
354
    // FDD, schedule normal UL/DLSCH
355 356
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
357 358
      case 0:
      case 1:
359
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
360
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
361 362 363
        break;

      case 6:
364
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
365
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
366 367 368 369 370 371
        break;

      default:
        break;
      }
    } else { //FDD
372
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
373
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
374
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
375
    }
376

377
    break;
378 379

  case 2:
380

gauthier's avatar
gauthier committed
381
    // TDD, nothing
382
    // FDD, normal UL/DLSCH
383
    if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
384
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
385
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
386
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
387
    }
388

389 390 391
    break;

  case 3:
392

gauthier's avatar
gauthier committed
393
    // TDD Config 2, ULSCH for subframeP 7
394 395
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
396 397
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
398
      case 2:
399
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
400 401 402

        // no break here!
      case 5:
403 404
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
405 406 407 408 409 410
        break;

      default:
        break;
      }
    } else { //FDD
411

412
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
413
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
414
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
415
    }
416

417
    break;
418 419

  case 4:
420

gauthier's avatar
gauthier committed
421
    // TDD Config 1, ULSCH for subframeP 8
422 423
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
424 425
    if (mac_xface->frame_parms->frame_type == 1) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
426
      case 1:
427
        //        schedule_RA(module_idP,frameP,subframeP);
428
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
429 430 431 432 433 434 435 436 437

        // no break here!
      case 2:

        // no break here!
      case 4:

        // no break here!
      case 5:
knopp's avatar
knopp committed
438

439 440
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
441 442 443 444 445 446
        break;

      default:
        break;
      }
    } else {
447
      if (mac_xface->frame_parms->frame_type == FDD) {  //FDD
448

449
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
450
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
451
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
452
      }
453
    }
454

455 456 457 458 459 460 461
    break;

  case 5:
    // TDD/FDD Schedule SI
    // TDD Config 0,6 ULSCH for subframes 9,3 resp.
    // TDD normal DLSCH
    // FDD normal UL/DLSCH
462
    schedule_SI(module_idP,frameP,subframeP);
463

464
    //schedule_RA(module_idP,frameP,subframeP,5);
465
    if (mac_xface->frame_parms->frame_type == FDD) {
466 467 468 469
      schedule_RA(module_idP,frameP,subframeP,1);
      schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
      schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
470 471
    } else if ((mac_xface->frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->frame_parms->tdd_config == 6)) { // TDD Config 6
472
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
473
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
474
    } else {
475 476
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
477
    }
478

479 480 481
    break;

  case 6:
482

483 484 485
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
486 487
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
488 489 490 491
      case 0:
        break;

      case 1:
492
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
493 494
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
495 496 497
        break;

      case 6:
498
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
499 500
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
501 502 503
        break;

      case 5:
504 505 506
        schedule_RA(module_idP,frameP,subframeP,2);
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
507 508 509 510
        break;

      case 3:
      case 4:
511 512
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
513 514 515 516 517 518
        break;

      default:
        break;
      }
    } else { //FDD
519
      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
520
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
521
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
522
    }
523

524
    break;
gauthier's avatar
gauthier committed
525

526
  case 7:
527

528 529
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
530 531
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
532 533
      case 3:
      case 4:
534 535 536
        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
537 538 539
        break;

      case 5:
540 541
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
542 543 544 545 546 547
        break;

      default:
        break;
      }
    } else { //FDD
548
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
549
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
550
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
551
    }
552

553 554 555
    break;

  case 8:
556

gauthier's avatar
gauthier committed
557
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
558 559
    //
    // FDD Normal UL/DLSCH
560 561
    if (mac_xface->frame_parms->frame_type == TDD) { // TDD
      switch (mac_xface->frame_parms->tdd_config) {
562 563 564 565 566
      case 2:
      case 3:
      case 4:
      case 5:

567
        //  schedule_RA(module_idP,subframeP);
568
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
569 570
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
571 572 573 574 575 576
        break;

      default:
        break;
      }
    } else { //FDD
577
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
578
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
579
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
580
    }
581

582 583 584
    break;

  case 9:
585

586
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
587 588
    if (mac_xface->frame_parms->frame_type == TDD) {
      switch (mac_xface->frame_parms->tdd_config) {
589
      case 1:
590
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
591 592 593
        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
594 595 596 597
        break;

      case 3:
      case 4:
598
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
599 600
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
601 602 603
        break;

      case 6:
604
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);
605 606 607
        //schedule_RA(module_idP,frameP,subframeP);
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
608 609 610 611
        break;

      case 2:
      case 5:
612 613 614
        //schedule_RA(module_idP,frameP,subframeP);
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
615 616 617 618 619 620
        break;

      default:
        break;
      }
    } else { //FDD
621
      schedule_ulsch(module_idP,frameP,cooperation_flag,9,3);
622
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
623
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
624
    }
625

626
    break;
gauthier's avatar
gauthier committed
627

628
  }
629

630
  LOG_D(MAC,"FrameP %d, subframeP %d : Scheduling CCEs\n",frameP,subframeP);
631

632
  // Allocate CCEs for good after scheduling is done
633 634
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++)
    allocate_CCEs(module_idP,CC_id,subframeP,0);
635

636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  /*
  int dummy=0;
  for (i=0;
       i<DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci;
       i++)
    if (DCI_pdu[CC_id]->dci_alloc[i].rnti==2)
      dummy=1;
	
  if (dummy==1)
    for (i=0;
	 i<DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci;
	 i++)
      LOG_I(MAC,"Frame %d, subframe %d: DCI %d/%d, format %d, rnti %x, NCCE %d(num_pdcch_symb %d)\n",
	    frameP,subframeP,i,DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci,
	    DCI_pdu[CC_id]->dci_alloc[i].format,
	    DCI_pdu[CC_id]->dci_alloc[i].rnti,
	    DCI_pdu[CC_id]->dci_alloc[i].firstCCE,
	    DCI_pdu[CC_id]->num_pdcch_symbols);


656
  LOG_D(MAC,"frameP %d, subframeP %d\n",frameP,subframeP);
657
  */
658

659
  stop_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
gauthier's avatar
gauthier committed
660
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
661

662
}
663 664 665