IF_Module.c 7.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#include "openair1/PHY/defs.h"
#include "openair2/PHY_INTERFACE/IF_Module.h"
#include "openair1/PHY/extern.h"
#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/proto.h"
#include "common/ran_context.h"

#define MAX_IF_MODULES 100

IF_Module_t *if_inst[MAX_IF_MODULES];
Sched_Rsp_t Sched_INFO[MAX_IF_MODULES][MAX_NUM_CCs];

13
void handle_rach(UL_IND_t *UL_info) {
14
  int i;
15 16 17 18 19

  if (UL_info->rach_ind.number_of_preambles>0) {

    AssertFatal(UL_info->rach_ind.number_of_preambles==1,"More than 1 preamble not supported\n");
    UL_info->rach_ind.number_of_preambles=0;
20
    LOG_D(MAC,"Frame %d, Subframe %d Calling initiate_ra_proc\n",UL_info->frame,UL_info->subframe);
21 22 23 24 25 26
    initiate_ra_proc(UL_info->module_id,
		     UL_info->CC_id,
		     UL_info->frame,
		     UL_info->subframe,
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.preamble,
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.timing_advance,
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
		     UL_info->rach_ind.preamble_list[0].preamble_rel8.rnti
#ifdef Rel14
		     ,0
#endif
		     );
  }

#ifdef Rel14
  if (UL_info->rach_ind_br.number_of_preambles>0) {

    AssertFatal(UL_info->rach_ind_br.number_of_preambles<5,"More than 4 preambles not supported\n");
    for (i=0;i<UL_info->rach_ind_br.number_of_preambles;i++) {
      AssertFatal(UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type>0,
		  "Got regular PRACH preamble, not BL/CE\n");
      LOG_D(MAC,"Frame %d, Subframe %d Calling initiate_ra_proc (CE_level %d)\n",UL_info->frame,UL_info->subframe,
	    UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type-1);
      initiate_ra_proc(UL_info->module_id,
		       UL_info->CC_id,
		       UL_info->frame,
		       UL_info->subframe,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.preamble,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.timing_advance,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel8.rnti,
		       UL_info->rach_ind_br.preamble_list[i].preamble_rel13.rach_resource_type);
    }
    UL_info->rach_ind.number_of_preambles=0;
53
  }
54
#endif
55 56
}

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
void handle_sr(UL_IND_t *UL_info) {

  int i;

  for (i=0;i<UL_info->sr_ind.number_of_srs;i++) 
    SR_indication(UL_info->module_id,
		  UL_info->CC_id,
		  UL_info->frame,
		  UL_info->subframe,
		  UL_info->sr_ind.sr_pdu_list[i].rx_ue_information.rnti,
		  UL_info->sr_ind.sr_pdu_list[i].ul_cqi_information.ul_cqi);

  UL_info->sr_ind.number_of_srs=0;
}

void handle_cqi(UL_IND_t *UL_info) {

  int i;

  for (i=0;i<UL_info->cqi_ind.number_of_cqis;i++) 
    cqi_indication(UL_info->module_id,
		   UL_info->CC_id,
		   UL_info->frame,
		   UL_info->subframe,
		   UL_info->cqi_ind.cqi_pdu_list[i].rx_ue_information.rnti,
		   &UL_info->cqi_ind.cqi_pdu_list[i].cqi_indication_rel9,
		   UL_info->cqi_ind.cqi_raw_pdu_list[i].pdu,
		   &UL_info->cqi_ind.cqi_pdu_list[i].ul_cqi_information);

  UL_info->cqi_ind.number_of_cqis=0;
}

void handle_harq(UL_IND_t *UL_info) {

  int i;

  for (i=0;i<UL_info->harq_ind.number_of_harqs;i++) 
    harq_indication(UL_info->module_id,
		    UL_info->CC_id,
		    UL_info->frame,
		    UL_info->subframe,
		    &UL_info->harq_ind.harq_pdu_list[i]);

  UL_info->harq_ind.number_of_harqs=0;
}

103 104 105 106 107 108
void handle_ulsch(UL_IND_t *UL_info) {

  int i;

  for (i=0;i<UL_info->rx_ind.number_of_pdus;i++) {

109
    LOG_D(MAC,"Frame %d, Subframe %d Calling rx_sdu \n",UL_info->frame,UL_info->subframe);
110 111 112 113 114 115 116 117 118 119
    rx_sdu(UL_info->module_id,
	   UL_info->CC_id,
	   UL_info->frame,
	   UL_info->subframe,
	   UL_info->rx_ind.rx_pdu_list[i].rx_ue_information.rnti,
	   UL_info->rx_ind.rx_pdu_list[i].data,
	   UL_info->rx_ind.rx_pdu_list[i].rx_indication_rel8.length,
	   UL_info->rx_ind.rx_pdu_list[i].rx_indication_rel8.timing_advance,
	   UL_info->rx_ind.rx_pdu_list[i].rx_indication_rel8.ul_cqi);
  }
120
    
121
  UL_info->rx_ind.number_of_pdus=0;
122
  
123
  for (i=0;i<UL_info->crc_ind.number_of_crcs;i++) {
124
    
125
    if (UL_info->crc_ind.crc_pdu_list[i].crc_indication_rel8.crc_flag == 1) { // CRC error indication
126
      LOG_D(MAC,"Frame %d, Subframe %d Calling rx_sdu (CRC error) \n",UL_info->frame,UL_info->subframe);
127 128 129 130 131 132 133 134 135 136
      rx_sdu(UL_info->module_id,
	     UL_info->CC_id,
	     UL_info->frame,
	     UL_info->subframe,
	     UL_info->crc_ind.crc_pdu_list[i].rx_ue_information.rnti,
	     (uint8_t *)NULL,
	     0,
	     0,
	     0);
    }
137 138
    
    
139 140 141 142
  }
  UL_info->crc_ind.number_of_crcs=0;
}

143 144 145 146 147 148 149 150 151 152 153 154
void UL_indication(UL_IND_t *UL_info)
{

  AssertFatal(UL_info!=NULL,"UL_INFO is null\n");


  module_id_t  module_id   = UL_info->module_id;
  int          CC_id       = UL_info->CC_id;
  Sched_Rsp_t  *sched_info = &Sched_INFO[module_id][CC_id];
  IF_Module_t  *ifi        = if_inst[module_id];
  eNB_MAC_INST *mac        = RC.mac[module_id];

155
  LOG_D(PHY,"UL_Indication: frame %d, subframe %d, module_id %d, CC_id %d\n",
156 157 158 159 160 161 162 163 164 165 166 167 168 169
	UL_info->frame,UL_info->subframe,
	module_id,CC_id);

  if (ifi->CC_mask==0) {
    ifi->current_frame    = UL_info->frame;
    ifi->current_subframe = UL_info->subframe;
  }
  else {
    AssertFatal(UL_info->frame != ifi->current_frame,"CC_mask %x is not full and frame has changed\n",ifi->CC_mask);
    AssertFatal(UL_info->subframe != ifi->current_subframe,"CC_mask %x is not full and subframe has changed\n",ifi->CC_mask);
  }
  ifi->CC_mask |= (1<<CC_id);
 

170 171 172 173
  // clear DL/UL info for new scheduling round
  clear_nfapi_information(RC.mac[module_id],CC_id,
			  UL_info->frame,UL_info->subframe);

174

175 176
  handle_rach(UL_info);

177 178 179 180 181 182
  handle_sr(UL_info);

  handle_cqi(UL_info);

  handle_harq(UL_info);

183
  // clear HI prior to handling ULSCH
184 185 186
  mac->HI_DCI0_req[CC_id].hi_dci0_request_body.number_of_hi                     = 0;
  
  handle_ulsch(UL_info);
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

  if (ifi->CC_mask == ((1<<MAX_NUM_CCs)-1)) {

    eNB_dlsch_ulsch_scheduler(module_id,
			      UL_info->frame+((UL_info->subframe>5)?1:0),
			      (UL_info->subframe+4)%10);

    ifi->CC_mask            = 0;

    sched_info->module_id   = module_id;
    sched_info->CC_id       = CC_id;
    sched_info->frame       = UL_info->frame + ((UL_info->subframe>5) ? 1 : 0);
    sched_info->subframe    = (UL_info->subframe+4)%10;
    sched_info->DL_req      = &mac->DL_req[CC_id];
    sched_info->HI_DCI0_req = &mac->HI_DCI0_req[CC_id];
202 203 204 205 206 207
    if ((mac->common_channels[CC_id].tdd_Config==NULL) ||
	(is_UL_sf(&mac->common_channels[CC_id],(sched_info->subframe+4)%10)>0)) 
      sched_info->UL_req      = &mac->UL_req[CC_id];
    else
      sched_info->UL_req      = NULL;

208 209
    sched_info->TX_req      = &mac->TX_req[CC_id];
    AssertFatal(ifi->schedule_response!=NULL,
210
		"schedule_response is null (mod %d, cc %d)\n",
211 212 213
		module_id,
		CC_id);
    ifi->schedule_response(sched_info);
214

215
    LOG_D(PHY,"Schedule_response: frame %d, subframe %d (dl_pdus %d / %p)\n",sched_info->frame,sched_info->subframe,sched_info->DL_req->dl_config_request_body.number_pdu,
216
	  &sched_info->DL_req->dl_config_request_body.number_pdu);
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
  }						 
}

IF_Module_t *IF_Module_init(int Mod_id){

  AssertFatal(Mod_id<MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);

  if (if_inst[Mod_id]==NULL) {
    if_inst[Mod_id] = (IF_Module_t*)malloc(sizeof(IF_Module_t));
    memset((void*)if_inst[Mod_id],0,sizeof(IF_Module_t));
    
    if_inst[Mod_id]->CC_mask=0;
    if_inst[Mod_id]->UL_indication = UL_indication;

    AssertFatal(pthread_mutex_init(&if_inst[Mod_id]->if_mutex,NULL)==0,
		"allocation of if_inst[%d]->if_mutex fails\n",Mod_id);
  }
  return if_inst[Mod_id];
}

void IF_Module_kill(int Mod_id) {

  AssertFatal(Mod_id>MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);
  if (if_inst[Mod_id]!=NULL) free(if_inst[Mod_id]);

}