eNB_scheduler.c 21.9 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2 3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


nikaeinn's avatar
nikaeinn committed
11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

nikaeinn's avatar
nikaeinn committed
16 17 18 19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
nikaeinn's avatar
nikaeinn committed
22 23
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
nikaeinn's avatar
nikaeinn committed
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

nikaeinn's avatar
nikaeinn committed
28
*******************************************************************************/
29
/*! \file eNB_scheduler.c
nikaeinn's avatar
nikaeinn committed
30
 * \brief eNB scheduler top level function operates on per subframe basis
31 32
 * \author  Navid Nikaein and Raymond Knopp
 * \date 2010 - 2014
33
 * \email: navid.nikaein@eurecom.fr
34 35
 * \version 0.5
 * @ingroup _mac
36

37
 */
38

39
#include "assertions.h"
40 41 42 43 44 45 46 47
#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
48

49 50 51 52 53 54
#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
55

56 57
#include "RRC/LITE/extern.h"
#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
gauthier's avatar
gauthier committed
58

59 60
//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"
61

62 63
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
64 65
#endif

66 67 68 69
#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
70

71 72 73 74 75
/*
  #ifndef USER_MODE
  #define msg debug_msg
  #endif
 */
gauthier's avatar
gauthier committed
76 77 78



79

80 81 82



83 84
void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
{
85

knopp's avatar
 
knopp committed
86
  int mbsfn_status[MAX_NUM_CCs];
87
  protocol_ctxt_t   ctxt;
88
#ifdef EXMIMO
Cedric Roux's avatar
Cedric Roux committed
89
  //int ret;
90
#endif
91
#if defined(ENABLE_ITTI)
92
  MessageDef   *msg_p;
93
  const char         *msg_name;
94 95
  instance_t    instance;
  int           result;
96
#endif
knopp's avatar
 
knopp committed
97
  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
knopp's avatar
 
knopp committed
98
  int CC_id,i,next_i;
knopp's avatar
 
knopp committed
99
  UE_list_t *UE_list=&eNB_mac_inst[module_idP].UE_list;
100
  rnti_t rnti;
101
  void         *DLSCH_dci=NULL;
102
  int size_bits=0,size_bytes=0;
103

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

106
  start_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
gauthier's avatar
gauthier committed
107
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
108

109
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
110 111
    DCI_pdu[CC_id] = &eNB_mac_inst[module_idP].common_channels[CC_id].DCI_pdu;
    mbsfn_status[CC_id]=0;
112 113
    // clear vrb_map
    memset(eNB_mac_inst[module_idP].common_channels[CC_id].vrb_map,0,100);
knopp's avatar
 
knopp committed
114
  }
115

knopp's avatar
 
knopp committed
116
  // refresh UE list based on UEs dropped by PHY in previous subframe
117 118 119
  i = UE_list->head;

  while (i>=0) {
120 121 122 123
    rnti = UE_RNTI(module_idP, i);
    CC_id = UE_PCCID(module_idP, i);
    LOG_D(MAC,"UE %d: rnti %x (%p)\n", i, rnti,
          mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti));
124
    next_i= UE_list->next[i];
125

126 127 128
    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]); 
129 130
    // increment this, it is cleared when we receive an sdu
    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
131 132

    eNB_mac_inst[module_idP].UE_list.UE_sched_ctrl[i].cqi_req_timer++;
133
    
134
    if (mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti)==NULL) {
135
      //      mac_remove_ue(module_idP, i, frameP, subframeP);
136
    }
137 138
    else {
      // check uplink failure
Florian Kaltenberger's avatar
Florian Kaltenberger committed
139 140 141 142 143 144 145
      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)
146
	  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
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
	  *(uint32_t*)DLSCH_dci = 0;
	  if (PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.frame_type == TDD) {
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.N_RB_DL) {
	    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;
175
	    }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
176 177 178 179 180 181 182 183 184
	  }
	  else { // FDD
	    switch (PHY_vars_eNB_g[module_idP][CC_id]->lte_frame_parms.N_RB_DL) {
	    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;
185 186 187 188 189 190
	    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
191 192 193 194 195 196 197 198 199 200 201
	    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;
202
		break;
203 204 205 206 207 208
	    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
209 210 211 212 213 214
	    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;
215 216
	    }
	  }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
217 218 219 220 221 222 223 224 225
	  
	  add_ue_spec_dci(DCI_pdu[CC_id],
			  DLSCH_dci,
			  rnti,
			    size_bytes,
			  process_ue_cqi (module_idP,i),//aggregation,
			  size_bits,
			  format1A,
			  0);
226
	}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
227
	else { // ra_pdcch_sent==1
228
	  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
229 230
	  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	      
231
	}
232 233 234 235 236
      
	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
237
	  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);
238 239 240 241
	  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
242 243 244
      }
    } // ul_failure_timer>0
    
245
    i = next_i;
knopp's avatar
 
knopp committed
246
  }
247

248
#if defined(ENABLE_ITTI)
249

250
  do {
251 252
    // Checks if a message has been sent to MAC sub-task
    itti_poll_msg (TASK_MAC_ENB, &msg_p);
253

254 255 256
    if (msg_p != NULL) {
      msg_name = ITTI_MSG_NAME (msg_p);
      instance = ITTI_MSG_INSTANCE (msg_p);
257

258 259 260 261
      switch (ITTI_MSG_ID(msg_p)) {
      case MESSAGE_TEST:
        LOG_D(MAC, "Received %s\n", ITTI_MSG_NAME(msg_p));
        break;
262

263 264 265 266
      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);
267

268 269
        // TODO process BCCH data req.
        break;
270

271 272 273 274
      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);
275

276 277
        // TODO process CCCH data req.
        break;
278 279 280

#ifdef Rel10

281 282 283 284
      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);
285

286 287 288
        // TODO process MCCH data req.
        break;
#endif
289

290 291 292
      default:
        LOG_E(MAC, "Received unexpected message %s\n", msg_name);
        break;
gauthier's avatar
gauthier committed
293
      }
294 295 296 297

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

300 301
#endif

gauthier's avatar
gauthier committed
302
  // clear DCI and BCCH contents before scheduling
303
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
knopp's avatar
 
knopp committed
304 305
    DCI_pdu[CC_id]->Num_common_dci  = 0;
    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
306

307

308
#ifdef Rel10
309
    eNB_mac_inst[module_idP].common_channels[CC_id].mcch_active =0;
310
#endif
311

knopp's avatar
 
knopp committed
312 313
    eNB_mac_inst[module_idP].frame    = frameP;
    eNB_mac_inst[module_idP].subframe = subframeP;
314 315


knopp's avatar
 
knopp committed
316
  }
317

gauthier's avatar
gauthier committed
318
  //if (subframeP%5 == 0)
knopp's avatar
 
knopp committed
319
  //#ifdef EXMIMO
320
  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, 0,module_idP);
321
  pdcp_run(&ctxt);
knopp's avatar
 
knopp committed
322
  //#endif
323

324
  // check HO
325 326
  rrc_rx_tx(&ctxt,
            0, // eNB index, unused in eNB
327
            CC_id);
328 329

#ifdef Rel10
330 331

  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
332 333 334 335
    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
336
    }
337
  }
338

339
#endif
knopp's avatar
 
knopp committed
340
  // refresh UE list based on UEs dropped by PHY in previous subframe
341
  /*
knopp's avatar
 
knopp committed
342 343 344
  i=UE_list->head;
  while (i>=0) {
    next_i = UE_list->next[i];
345
    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
346
    if (mac_xface->get_eNB_UE_stats(module_idP,0,UE_RNTI(module_idP,i))==NULL) {
knopp's avatar
 
knopp committed
347
      mac_remove_ue(module_idP,i,frameP);
knopp's avatar
 
knopp committed
348 349 350
    }
    i=next_i;
  }
351
  */
352

gauthier's avatar
gauthier committed
353
  switch (subframeP) {
354
  case 0:
355

356
    // FDD/TDD Schedule Downlink RA transmissions (RA response, Msg4 Contention resolution)
gauthier's avatar
gauthier committed
357
    // Schedule ULSCH for FDD or subframeP 4 (TDD config 0,3,6)
358
    // Schedule Normal DLSCH
gauthier's avatar
gauthier committed
359

knopp's avatar
knopp committed
360

361 362
    schedule_RA(module_idP,frameP,subframeP,2);

363 364

    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
365
      schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
366 367 368
    } else if  ((mac_xface->lte_frame_parms->tdd_config == TDD) || //TDD
                (mac_xface->lte_frame_parms->tdd_config == 3) ||
                (mac_xface->lte_frame_parms->tdd_config == 6)) {
369
      //schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);//,calibration_flag);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
370
    }
371

372 373
    schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
    fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
374

375 376 377
    break;

  case 1:
378

gauthier's avatar
gauthier committed
379
    // TDD, schedule UL for subframeP 7 (TDD config 0,1) / subframeP 8 (TDD Config 6)
380 381
    // FDD, schedule normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
382 383 384
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 0:
      case 1:
385
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
386
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
387 388 389
        break;

      case 6:
390
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
391
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
392 393 394 395 396 397
        break;

      default:
        break;
      }
    } else { //FDD
398
      schedule_ulsch(module_idP,frameP,cooperation_flag,1,5);
399
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
400
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
401
    }
402

403
    break;
404 405

  case 2:
406

gauthier's avatar
gauthier committed
407
    // TDD, nothing
408 409
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == FDD) {  //FDD
410
      schedule_ulsch(module_idP,frameP,cooperation_flag,2,6);
411
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
412
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
413
    }
414

415 416 417
    break;

  case 3:
418

gauthier's avatar
gauthier committed
419
    // TDD Config 2, ULSCH for subframeP 7
420 421 422
    // TDD Config 2/5 normal DLSCH
    // FDD, normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
423 424
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
425
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,7);
426 427 428

        // no break here!
      case 5:
429 430
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
431 432 433 434 435 436
        break;

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

438
      schedule_ulsch(module_idP,frameP,cooperation_flag,3,7);
439
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
440
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
441
    }
442

443
    break;
444 445

  case 4:
446

gauthier's avatar
gauthier committed
447
    // TDD Config 1, ULSCH for subframeP 8
448 449 450
    // TDD Config 1/2/4/5 DLSCH
    // FDD UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == 1) { // TDD
451 452
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 1:
453
        //        schedule_RA(module_idP,frameP,subframeP);
454
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
455 456 457 458 459 460 461 462 463

        // no break here!
      case 2:

        // no break here!
      case 4:

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

465 466
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
467 468 469 470 471 472 473 474
        break;

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

475
	schedule_ulsch(module_idP, frameP, cooperation_flag, 4, 8);
476
	schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
477
        fill_DLSCH_dci(module_idP, frameP, subframeP,   mbsfn_status);
478
      }
479
    }
480

481 482 483 484 485 486 487
    break;

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

490
    //schedule_RA(module_idP,frameP,subframeP,5);
491
    if (mac_xface->lte_frame_parms->frame_type == FDD) {
492 493 494 495
      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);
496 497
    } else if ((mac_xface->lte_frame_parms->tdd_config == 0) || // TDD Config 0
               (mac_xface->lte_frame_parms->tdd_config == 6)) { // TDD Config 6
498
      //schedule_ulsch(module_idP,cooperation_flag,subframeP);
499
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
500
    } else {
501 502
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
503
    }
504

505 506 507
    break;

  case 6:
508

509 510 511 512
    // TDD Config 0,1,6 ULSCH for subframes 2,3
    // TDD Config 3,4,5 Normal DLSCH
    // FDD normal ULSCH/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
513 514 515 516 517
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 0:
        break;

      case 1:
518
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
519 520
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
521 522 523
        break;

      case 6:
524
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
525 526
        //  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
527 528 529
        break;

      case 5:
530 531 532
        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);
533 534 535 536
        break;

      case 3:
      case 4:
537 538
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
539 540 541 542 543 544
        break;

      default:
        break;
      }
    } else { //FDD
545
      schedule_ulsch(module_idP,frameP,cooperation_flag,6,0);
546
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
547
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
548
    }
549

550
    break;
gauthier's avatar
gauthier committed
551

552
  case 7:
553

554 555 556
    // TDD Config 3,4,5 Normal DLSCH
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
557 558 559
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 3:
      case 4:
560 561 562
        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);
563 564 565
        break;

      case 5:
566 567
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
568 569 570 571 572 573
        break;

      default:
        break;
      }
    } else { //FDD
574
      schedule_ulsch(module_idP,frameP,cooperation_flag,7,1);
575
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
576
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
577
    }
578

579 580 581
    break;

  case 8:
582

gauthier's avatar
gauthier committed
583
    // TDD Config 2,3,4,5 ULSCH for subframeP 2
584 585 586
    //
    // FDD Normal UL/DLSCH
    if (mac_xface->lte_frame_parms->frame_type == TDD) { // TDD
587 588 589 590 591 592
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 2:
      case 3:
      case 4:
      case 5:

593
        //  schedule_RA(module_idP,subframeP);
594
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
595 596
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
597 598 599 600 601 602
        break;

      default:
        break;
      }
    } else { //FDD
603
      schedule_ulsch(module_idP,frameP,cooperation_flag,8,2);
604
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
605
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
606
    }
607

608 609 610
    break;

  case 9:
611

612 613
    // TDD Config 1,3,4,6 ULSCH for subframes 3,3,3,4
    if (mac_xface->lte_frame_parms->frame_type == TDD) {
614 615
      switch (mac_xface->lte_frame_parms->tdd_config) {
      case 1:
616
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
617 618 619
        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);
620 621 622 623
        break;

      case 3:
      case 4:
624
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
625 626
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
627 628 629
        break;

      case 6:
630
        schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);
631 632 633
        //schedule_RA(module_idP,frameP,subframeP);
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
634 635 636 637
        break;

      case 2:
      case 5:
638 639 640
        //schedule_RA(module_idP,frameP,subframeP);
        schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
        fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
641 642 643 644 645 646
        break;

      default:
        break;
      }
    } else { //FDD
647
      schedule_ulsch(module_idP,frameP,cooperation_flag,9,3);
648
      schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
649
      fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
650
    }
651

652
    break;
gauthier's avatar
gauthier committed
653

654
  }
655

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

658
  // Allocate CCEs for good after scheduling is done
659 660
  for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++)
    allocate_CCEs(module_idP,CC_id,subframeP,0);
661

662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
  /*
  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);


682
  LOG_D(MAC,"frameP %d, subframeP %d\n",frameP,subframeP);
683
  */
684

685
  stop_meas(&eNB_mac_inst[module_idP].eNB_scheduler);
gauthier's avatar
gauthier committed
686
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
687

688
}
689 690 691