gNB_scheduler_phytest.c 34.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * 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
 */

/*! \file gNB_scheduler_phytest.c
 * \brief gNB scheduling procedures in phy_test mode
 * \author  Guy De Souza
 * \date 07/2018
 * \email: desouza@eurecom.fr
 * \version 1.0
 * @ingroup _mac
 */

#include "nr_mac_gNB.h"
Guy De Souza's avatar
Guy De Souza committed
32
#include "SCHED_NR/sched_nr.h"
33
#include "mac_proto.h"
Guy De Souza's avatar
Guy De Souza committed
34 35
#include "PHY/NR_TRANSPORT/nr_dlsch.h"
#include "PHY/NR_TRANSPORT/nr_dci.h"
36
#include "executables/nr-softmodem.h"
Raymond Knopp's avatar
Raymond Knopp committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#include "common/utils/nr/nr_common.h"

#include "NR_SCS-SpecificCarrier.h"
#include "NR_TDD-UL-DL-ConfigCommon.h"
#include "NR_FrequencyInfoUL.h"
#include "NR_RACH-ConfigGeneric.h"
#include "NR_RACH-ConfigCommon.h"
#include "NR_PUSCH-TimeDomainResourceAllocation.h"
#include "NR_PUSCH-ConfigCommon.h"
#include "NR_PUCCH-ConfigCommon.h"
#include "NR_PDSCH-TimeDomainResourceAllocation.h"
#include "NR_PDSCH-ConfigCommon.h"
#include "NR_RateMatchPattern.h"
#include "NR_RateMatchPatternLTE-CRS.h"
#include "NR_SearchSpace.h"
#include "NR_ControlResourceSet.h"

54
extern RAN_CONTEXT_t RC;
55
//#define ENABLE_MAC_PAYLOAD_DEBUG 1
56

Raymond Knopp's avatar
Raymond Knopp committed
57
/*Scheduling of DLSCH with associated DCI in common search space on initialBWP
Guy De Souza's avatar
Guy De Souza committed
58
 * current version has only a DCI for type 1 PDCCH for C_RNTI*/
59 60
void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
                                   frame_t       frameP,
61
                                   sub_frame_t   slotP) {
62
  uint8_t  CC_id;
Raymond Knopp's avatar
Raymond Knopp committed
63 64
  gNB_MAC_INST                      *nr_mac      = RC.nrmac[module_idP];
  NR_COMMON_channels_t              *cc = &nr_mac->common_channels[0];
Raymond Knopp's avatar
Raymond Knopp committed
65 66 67 68
  nfapi_nr_dl_tti_request_body_t    *dl_req;
  nfapi_nr_dl_tti_request_pdu_t     *dl_tti_pdcch_pdu;
  nfapi_nr_dl_tti_request_pdu_t     *dl_tti_pdsch_pdu;
  nfapi_nr_pdu_t        *TX_req;
69

Guy De Souza's avatar
Guy De Souza committed
70
  uint16_t rnti = 0x1234;
Raymond Knopp's avatar
Raymond Knopp committed
71
  
72
  //  int time_domain_assignment,k0;
Raymond Knopp's avatar
Raymond Knopp committed
73 74

  NR_ServingCellConfigCommon_t *scc=cc->ServingCellConfigCommon;
Raymond Knopp's avatar
Raymond Knopp committed
75

Raymond Knopp's avatar
Raymond Knopp committed
76
  int dlBWP_carrier_bandwidth = NRRIV2BW(scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.locationAndBandwidth,275);
77

78 79
  
  /*
Raymond Knopp's avatar
Raymond Knopp committed
80
  int scs               = scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.subcarrierSpacing;
81
  
Raymond Knopp's avatar
Raymond Knopp committed
82
  int slots_per_frame   = 10*(1<<scs);
83

Raymond Knopp's avatar
Raymond Knopp committed
84
  int FR                = *scc->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0] >= 257 ? nr_FR2 : nr_FR1;
85
  */
86

87
  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
Raymond Knopp's avatar
Raymond Knopp committed
88 89 90 91 92
    LOG_D(MAC, "Scheduling common search space DCI type 1 dlBWP BW.firstRB %d.%d\n",
	  dlBWP_carrier_bandwidth,
	  NRRIV2PRBOFFSET(scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.locationAndBandwidth,275));
    
    
Raymond Knopp's avatar
Raymond Knopp committed
93 94 95 96 97
    dl_req = &nr_mac->DL_req[CC_id].dl_tti_request_body;
    dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
    memset((void*)dl_tti_pdcch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
    dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
    dl_tti_pdcch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
Raymond Knopp's avatar
Raymond Knopp committed
98
    
Raymond Knopp's avatar
Raymond Knopp committed
99 100 101 102
    dl_tti_pdsch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs+1];
    memset((void *)dl_tti_pdsch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
    dl_tti_pdsch_pdu->PDUType = NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE;
    dl_tti_pdsch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdsch_pdu));
103

Raymond Knopp's avatar
Raymond Knopp committed
104
    
105
    //    nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15 = &dl_tti_pdcch_pdu->pdcch_pdu.pdcch_pdu_rel15;
Raymond Knopp's avatar
Raymond Knopp committed
106
    nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
Raymond Knopp's avatar
Raymond Knopp committed
107
    
108 109 110
    pdsch_pdu_rel15->pduBitmap = 0;
    pdsch_pdu_rel15->rnti = rnti;
    pdsch_pdu_rel15->pduIndex = 0;
Raymond Knopp's avatar
Raymond Knopp committed
111 112

    // BWP
113 114 115 116 117
    pdsch_pdu_rel15->BWPSize  = NRRIV2BW(scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.locationAndBandwidth,275);
    pdsch_pdu_rel15->BWPStart = NRRIV2PRBOFFSET(scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.locationAndBandwidth,275);
    pdsch_pdu_rel15->SubcarrierSpacing = scc->downlinkConfigCommon->initialDownlinkBWP->genericParameters.subcarrierSpacing;
    pdsch_pdu_rel15->CyclicPrefix = 0;
    pdsch_pdu_rel15->NrOfCodewords = 1;
Raymond Knopp's avatar
Raymond Knopp committed
118
    int mcsIndex = 9;
119 120 121 122 123 124 125 126 127 128
    pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(mcsIndex,0);
    pdsch_pdu_rel15->qamModOrder[0] = 2;
    pdsch_pdu_rel15->mcsIndex[0] = mcsIndex;
    pdsch_pdu_rel15->mcsTable[0] = 0;
    pdsch_pdu_rel15->rvIndex[0] = 0;
    pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
    pdsch_pdu_rel15->nrOfLayers = 1;    
    pdsch_pdu_rel15->transmissionScheme = 0;
    pdsch_pdu_rel15->refPoint = 0; // Point A
    
129
    pdsch_pdu_rel15->dmrsConfigType = 0; // Type 1 by default for InitialBWP
130 131 132 133 134 135 136 137
    pdsch_pdu_rel15->dlDmrsScramblingId = *scc->physCellId;
    pdsch_pdu_rel15->SCID = 0;
    pdsch_pdu_rel15->numDmrsCdmGrpsNoData = 1;
    pdsch_pdu_rel15->dmrsPorts = 1;
    pdsch_pdu_rel15->resourceAlloc = 1;
    pdsch_pdu_rel15->rbStart = 0;
    pdsch_pdu_rel15->rbSize = 6;
    pdsch_pdu_rel15->VRBtoPRBMapping = 1; // non-interleaved, check if this is ok for initialBWP
Raymond Knopp's avatar
Raymond Knopp committed
138 139
    // choose shortest PDSCH
    int startSymbolAndLength=0;
140
    int StartSymbolIndex=-1,NrOfSymbols=14;
Raymond Knopp's avatar
Raymond Knopp committed
141 142 143 144 145 146 147 148 149 150
    int StartSymbolIndex_tmp,NrOfSymbols_tmp;

    for (int i=0;
	 i<scc->downlinkConfigCommon->initialDownlinkBWP->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.count;
	 i++) {
      startSymbolAndLength = scc->downlinkConfigCommon->initialDownlinkBWP->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.array[i]->startSymbolAndLength;
      SLIV2SL(startSymbolAndLength,&StartSymbolIndex_tmp,&NrOfSymbols_tmp);
      if (NrOfSymbols_tmp < NrOfSymbols) {
	NrOfSymbols = NrOfSymbols_tmp;
        StartSymbolIndex = StartSymbolIndex_tmp;
151 152
	//	k0 = *scc->downlinkConfigCommon->initialDownlinkBWP->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.array[i]->k0;
	//	time_domain_assignment = i;
Raymond Knopp's avatar
Raymond Knopp committed
153 154
      }
    }
155
    AssertFatal(StartSymbolIndex>=0,"StartSymbolIndex is negative\n");
156 157 158
    pdsch_pdu_rel15->StartSymbolIndex = StartSymbolIndex;
    pdsch_pdu_rel15->NrOfSymbols      = NrOfSymbols;
    pdsch_pdu_rel15->dlDmrsSymbPos = fill_dmrs_mask(NULL,
Raymond Knopp's avatar
Raymond Knopp committed
159 160
						    scc->dmrs_TypeA_Position,
						    NrOfSymbols);
161

162
    /*
Raymond Knopp's avatar
Raymond Knopp committed
163
    AssertFatal(k0==0,"k0 is not zero for Initial DL BWP TimeDomain Alloc\n");
164
    nr_configure_css_dci_initial(pdcch_pdu_rel15,
165 166
				 scs, 
				 scs, 
Raymond Knopp's avatar
Raymond Knopp committed
167
				 FR, 
168 169 170 171
				 0, 
				 0, 
				 0,
				 sfn_sf, slotP,
172
				 slots_per_frame,
173
				 dlBWP_carrier_bandwidth);
Raymond Knopp's avatar
Raymond Knopp committed
174 175
    
    
176 177 178
    pdu_rel15->frequency_domain_assignment = PRBalloc_to_locationandbandwidth0(pdsch_pdu_rel15->rbSize, 
                                                                               pdsch_pdu_rel15->rbStart, 
                                                                               dlBWP_carrier_bandwidth);
Raymond Knopp's avatar
Raymond Knopp committed
179 180
    pdu_rel15->time_domain_assignment = time_domain_assignment;
    
181
    pdu_rel15->vrb_to_prb_mapping = 1;
Guy De Souza's avatar
Guy De Souza committed
182
    pdu_rel15->mcs = 9;
183
    pdu_rel15->tb_scaling = 1;
Raymond Knopp's avatar
Raymond Knopp committed
184
    
185 186 187
    pdu_rel15->ra_preamble_index = 25;
    pdu_rel15->format_indicator = 1;
    pdu_rel15->ndi = 1;
Guy De Souza's avatar
Guy De Souza committed
188 189
    pdu_rel15->rv = 0;
    pdu_rel15->harq_pid = 0;
190 191 192 193
    pdu_rel15->dai = 2;
    pdu_rel15->tpc = 2;
    pdu_rel15->pucch_resource_indicator = 7;
    pdu_rel15->pdsch_to_harq_feedback_timing_indicator = 7;
Raymond Knopp's avatar
Raymond Knopp committed
194
    
195
    LOG_D(MAC, "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d, time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d ndi %d rv %d\n",
Raymond Knopp's avatar
Raymond Knopp committed
196 197 198 199 200 201 202 203
	  pdu_rel15->frequency_domain_assignment,
	  pdu_rel15->time_domain_assignment,
	  pdu_rel15->vrb_to_prb_mapping,
	  pdu_rel15->mcs,
	  pdu_rel15->tb_scaling,
	  pdu_rel15->ndi,
	  pdu_rel15->rv);
    
Guy De Souza's avatar
Guy De Souza committed
204
    params_rel15->rnti = rnti;
205
    params_rel15->rnti_type = NFAPI_NR_RNTI_C;
206
    params_rel15->dci_format = NFAPI_NR_DL_DCI_FORMAT_1_0;
Guy De Souza's avatar
Guy De Souza committed
207
    //params_rel15->aggregation_level = 1;
208
    LOG_D(MAC, "DCI type 1 params: rnti %x, rnti_type %d, dci_format %d\n \
209 210
                coreset params: mux_pattern %d, n_rb %d, n_symb %d, rb_offset %d  \n \
                ss params : nb_ss_sets_per_slot %d, first symb %d, nb_slots %d, sfn_mod2 %d, first slot %d\n",
Raymond Knopp's avatar
Raymond Knopp committed
211 212 213 214 215 216 217 218 219 220 221 222
	  params_rel15->rnti,
	  params_rel15->rnti_type,
	  params_rel15->dci_format,
	  params_rel15->mux_pattern,
	  params_rel15->n_rb,
	  params_rel15->n_symb,
	  params_rel15->rb_offset,
	  params_rel15->nb_ss_sets_per_slot,
	  params_rel15->first_symbol,
	  params_rel15->nb_slots,
	  params_rel15->sfn_mod2,
	  params_rel15->first_slot);
Raymond Knopp's avatar
Raymond Knopp committed
223
    nr_get_tbs_dl(&dl_tti_pdsch_pdu->pdsch_pdu, dl_tti_dci_pdu->dci_dl_pdu,0);
Raymond Knopp's avatar
Raymond Knopp committed
224
    LOG_D(MAC, "DLSCH PDU: start PRB %d n_PRB %d start symbol %d nb_symbols %d nb_layers %d nb_codewords %d mcs %d\n",
225 226 227 228 229 230 231
	  pdsch_pdu_rel15->rbStart,
	  pdsch_pdu_rel15->rbSize,
	  pdsch_pdu_rel15->StartSymbolIndex,
	  pdsch_pdu_rel15->NrOfSymbols,
	  pdsch_pdu_rel15->nrOfLayers,
	  pdsch_pdu_rel15->NrOfCodewords,
	  pdsch_pdu_rel15->mcsIndex[0]);
232
    */
Raymond Knopp's avatar
Raymond Knopp committed
233
    
Raymond Knopp's avatar
Raymond Knopp committed
234 235 236 237 238 239 240 241 242 243 244
    dl_req->nPDUs+=2;
    
    TX_req = &nr_mac->TX_req[CC_id].pdu_list[nr_mac->TX_req[CC_id].Number_of_PDUs];
    TX_req->PDU_length = 6;
    TX_req->PDU_index = nr_mac->pdu_index[CC_id]++;
    TX_req->num_TLV = 1;
    TX_req->TLVs[0].length = 8;
    memcpy((void*)&TX_req->TLVs[0].value.direct[0],(void*)&cc[CC_id].RAR_pdu.payload[0],TX_req->TLVs[0].length);
    nr_mac->TX_req[CC_id].Number_of_PDUs++;
    nr_mac->TX_req[CC_id].SFN=frameP;
    nr_mac->TX_req[CC_id].Slot=slotP;
245 246
  }
}
247

Raymond Knopp's avatar
Raymond Knopp committed
248
int configure_fapi_dl_Tx(int Mod_idP,
249
			 int *CCEIndex,
Raymond Knopp's avatar
Raymond Knopp committed
250
			 nfapi_nr_dl_tti_request_body_t *dl_req,
251 252 253 254
			 nfapi_nr_pdu_t *TX_req,
			 int *mcsIndex,
			 int *rbSize,
			 int *rbStart) {
Raymond Knopp's avatar
Raymond Knopp committed
255

Raymond Knopp's avatar
Raymond Knopp committed
256 257 258 259 260

  gNB_MAC_INST                        *nr_mac  = RC.nrmac[Mod_idP];
  NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
  NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
  
Raymond Knopp's avatar
Raymond Knopp committed
261 262
  nfapi_nr_dl_tti_request_pdu_t  *dl_tti_pdcch_pdu;
  nfapi_nr_dl_tti_request_pdu_t  *dl_tti_pdsch_pdu;
Raymond Knopp's avatar
Raymond Knopp committed
263
  int TBS;
264

Raymond Knopp's avatar
Raymond Knopp committed
265 266
  
  int bwp_id=1;
267
  
268
  int UE_id = 0;
Raymond Knopp's avatar
Raymond Knopp committed
269
  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
270

271

Raymond Knopp's avatar
Raymond Knopp committed
272
  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
273 274 275 276 277
  AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
	      "downlinkBWP_ToAddModList has %d BWP!\n",
	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
  NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];

278

Raymond Knopp's avatar
Raymond Knopp committed
279 280 281 282
  dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
  memset((void*)dl_tti_pdcch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
  dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
  dl_tti_pdcch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
Raymond Knopp's avatar
Raymond Knopp committed
283
  
Raymond Knopp's avatar
Raymond Knopp committed
284 285 286 287
  dl_tti_pdsch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs+1];
  memset((void*)dl_tti_pdsch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
  dl_tti_pdsch_pdu->PDUType = NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE;
  dl_tti_pdsch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdsch_pdu));
288

Raymond Knopp's avatar
Raymond Knopp committed
289 290
  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15 = &dl_tti_pdcch_pdu->pdcch_pdu.pdcch_pdu_rel15;
  nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
291 292


293 294 295
  pdsch_pdu_rel15->pduBitmap = 0;
  pdsch_pdu_rel15->rnti = UE_list->rnti[UE_id];
  pdsch_pdu_rel15->pduIndex = 0;
296

297
  // BWP
298 299 300 301 302
  pdsch_pdu_rel15->BWPSize  = NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
  pdsch_pdu_rel15->BWPStart = NRRIV2PRBOFFSET(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
  pdsch_pdu_rel15->SubcarrierSpacing = bwp->bwp_Common->genericParameters.subcarrierSpacing;
  if (bwp->bwp_Common->genericParameters.cyclicPrefix) pdsch_pdu_rel15->CyclicPrefix = *bwp->bwp_Common->genericParameters.cyclicPrefix;
  else pdsch_pdu_rel15->CyclicPrefix=0;
303

304
  pdsch_pdu_rel15->NrOfCodewords = 1;
305
  int mcs = (mcsIndex!=NULL) ? *mcsIndex : 9;
306 307
  pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(mcsIndex,0);
  pdsch_pdu_rel15->qamModOrder[0] = 2;
308
  pdsch_pdu_rel15->mcsIndex[0] = mcs;
309 310 311 312 313 314 315
  pdsch_pdu_rel15->mcsTable[0] = 0;
  pdsch_pdu_rel15->rvIndex[0] = 0;
  pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
  pdsch_pdu_rel15->nrOfLayers = 1;    
  pdsch_pdu_rel15->transmissionScheme = 0;
  pdsch_pdu_rel15->refPoint = 0; // Point A
    
316
  pdsch_pdu_rel15->dmrsConfigType = bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_Type == NULL ? 0 : 1;  
317 318 319 320 321
  pdsch_pdu_rel15->dlDmrsScramblingId = *scc->physCellId;
  pdsch_pdu_rel15->SCID = 0;
  pdsch_pdu_rel15->numDmrsCdmGrpsNoData = 1;
  pdsch_pdu_rel15->dmrsPorts = 1;
  pdsch_pdu_rel15->resourceAlloc = 1;
322 323
  pdsch_pdu_rel15->rbStart = (rbStart!=NULL) ? *rbStart : 0;
  pdsch_pdu_rel15->rbSize = (rbSize!=NULL) ? *rbSize : pdsch_pdu_rel15->BWPSize;
324
  pdsch_pdu_rel15->VRBtoPRBMapping = 1; // non-interleaved, check if this is ok for initialBWP
325 326
    // choose shortest PDSCH
  int startSymbolAndLength=0;
Raymond Knopp's avatar
Raymond Knopp committed
327 328 329 330 331 332
  int time_domain_assignment=2;
  int StartSymbolIndex,NrOfSymbols;

  AssertFatal(time_domain_assignment<bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.count,"time_domain_assignment %d>=%d\n",time_domain_assignment,bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.count);
  startSymbolAndLength = bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.array[time_domain_assignment]->startSymbolAndLength;
  SLIV2SL(startSymbolAndLength,&StartSymbolIndex,&NrOfSymbols);
333 334
  pdsch_pdu_rel15->StartSymbolIndex = StartSymbolIndex;
  pdsch_pdu_rel15->NrOfSymbols      = NrOfSymbols;
Raymond Knopp's avatar
Raymond Knopp committed
335 336
 
  //  k0 = *bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.array[i]->k0;
337
  pdsch_pdu_rel15->dlDmrsSymbPos    = fill_dmrs_mask(bwp->bwp_Dedicated->pdsch_Config->choice.setup,
Raymond Knopp's avatar
Raymond Knopp committed
338
						     scc->dmrs_TypeA_Position,
339
						     pdsch_pdu_rel15->NrOfSymbols);
340 341 342

  dci_pdu_rel15_t dci_pdu_rel15[MAX_DCI_CORESET];
  
343 344
  dci_pdu_rel15[0].frequency_domain_assignment = PRBalloc_to_locationandbandwidth0(pdsch_pdu_rel15->rbSize, 
										   pdsch_pdu_rel15->rbStart, 
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
										   NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,275));
  dci_pdu_rel15[0].time_domain_assignment = time_domain_assignment; // row index used here instead of SLIV;
  dci_pdu_rel15[0].vrb_to_prb_mapping = 1;
  dci_pdu_rel15[0].mcs = pdsch_pdu_rel15->mcsIndex[0];
  dci_pdu_rel15[0].tb_scaling = 1;
  
  dci_pdu_rel15[0].ra_preamble_index = 25;
  dci_pdu_rel15[0].format_indicator = 1;
  dci_pdu_rel15[0].ndi = 1;
  dci_pdu_rel15[0].rv = 0;
  dci_pdu_rel15[0].harq_pid = 0;
  dci_pdu_rel15[0].dai = 2;
  dci_pdu_rel15[0].tpc = 2;
  dci_pdu_rel15[0].pucch_resource_indicator = 7;
  dci_pdu_rel15[0].pdsch_to_harq_feedback_timing_indicator = 7;
  
361
  LOG_D(MAC, "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d (%d,%d,%d), time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d ndi %d rv %d\n",
362
	dci_pdu_rel15[0].frequency_domain_assignment,
363 364 365
	pdsch_pdu_rel15->rbStart, 
	pdsch_pdu_rel15->rbSize,	
	NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,275),
366 367 368 369 370 371
	dci_pdu_rel15[0].time_domain_assignment,
	dci_pdu_rel15[0].vrb_to_prb_mapping,
	dci_pdu_rel15[0].mcs,
	dci_pdu_rel15[0].tb_scaling,
	dci_pdu_rel15[0].ndi, 
	dci_pdu_rel15[0].rv);
372 373

    
374 375 376 377
  nr_configure_pdcch(pdcch_pdu_rel15,
		     1, // ue-specific
		     scc,
		     bwp);
378 379
  

380 381 382 383 384

  
  pdcch_pdu_rel15->numDlDci = 1;
  pdcch_pdu_rel15->AggregationLevel[0] = 4;  
  pdcch_pdu_rel15->RNTI[0]=UE_list->rnti[0];
385
  pdcch_pdu_rel15->CceIndex[0] = CCEIndex[0];
386 387 388 389 390 391 392 393 394 395
  pdcch_pdu_rel15->beta_PDCCH_1_0[0]=0;
  pdcch_pdu_rel15->powerControlOffsetSS[0]=1;
  
  int dci_formats[2];
  int rnti_types[2];
  
  dci_formats[0]  = NR_DL_DCI_FORMAT_1_0;
  rnti_types[0]   = NR_RNTI_C;

  pdcch_pdu_rel15->PayloadSizeBits[0]=nr_dci_size(dci_formats[0],rnti_types[0],pdcch_pdu_rel15->BWPSize);
396 397 398
  fill_dci_pdu_rel15(pdcch_pdu_rel15,&dci_pdu_rel15[0],dci_formats,rnti_types);

  LOG_D(MAC, "DCI params: rnti %d, rnti_type %d, dci_format %d\n \
Raymond Knopp's avatar
Raymond Knopp committed
399
	                      coreset params: FreqDomainResource %llx, start_symbol %d  n_symb %d\n",
400 401 402 403
	pdcch_pdu_rel15->RNTI[0],
	rnti_types[0],
	dci_formats[0],
	(unsigned long long)pdcch_pdu_rel15->FreqDomainResource,
Raymond Knopp's avatar
Raymond Knopp committed
404 405
	pdcch_pdu_rel15->StartSymbolIndex,
	pdcch_pdu_rel15->DurationSymbols);
406

Raymond Knopp's avatar
Raymond Knopp committed
407
  int x_Overhead = 0; // should be 0 for initialBWP
Raymond Knopp's avatar
Raymond Knopp committed
408
  nr_get_tbs_dl(&dl_tti_pdsch_pdu->pdsch_pdu, 
409
		x_Overhead);
Raymond Knopp's avatar
Raymond Knopp committed
410
  // Hardcode it for now
Raymond Knopp's avatar
Raymond Knopp committed
411
  TBS = dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15.TBSize[0];
412
  LOG_D(MAC, "DLSCH PDU: start PRB %d n_PRB %d startSymbolAndLength %d start symbol %d nb_symbols %d nb_layers %d nb_codewords %d mcs %d TBS: %d\n",
413 414
	pdsch_pdu_rel15->rbStart,
	pdsch_pdu_rel15->rbSize,
Raymond Knopp's avatar
Raymond Knopp committed
415
	startSymbolAndLength,
416 417 418 419 420
	pdsch_pdu_rel15->StartSymbolIndex,
	pdsch_pdu_rel15->NrOfSymbols,
	pdsch_pdu_rel15->nrOfLayers,
	pdsch_pdu_rel15->NrOfCodewords,
	pdsch_pdu_rel15->mcsIndex[0],
Raymond Knopp's avatar
Raymond Knopp committed
421
	TBS);
422
  
Raymond Knopp's avatar
Raymond Knopp committed
423
  dl_req->nPDUs+=2;
424
  
Raymond Knopp's avatar
Raymond Knopp committed
425 426 427 428 429 430 431 432

  TX_req->PDU_length = pdsch_pdu_rel15->TBSize[0];
  TX_req->PDU_index  = nr_mac->pdu_index[0]++;

  //  TX_req->num_TLV = 1;
  //  TX_req->TLVs[0].length = 8;
  //    memcpy((void*)&TX_req->TLVs[0].value.direct[0],(void*)&cc[CC_id].RAR_pdu.payload[0],TX_req->TLVs[0].length);

Raymond Knopp's avatar
Raymond Knopp committed
433 434 435
  return TBS/8; //Return TBS in bytes
}

436 437
void config_uldci(NR_BWP_Uplink_t *ubwp,nfapi_nr_pusch_pdu_t *pusch_pdu,nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15, dci_pdu_rel15_t *dci_pdu_rel15, int *dci_formats, int *rnti_types) {

438 439
  dci_pdu_rel15->frequency_domain_assignment = PRBalloc_to_locationandbandwidth0(pusch_pdu->rb_size, 
										 pusch_pdu->rb_start, 
440
										 NRRIV2BW(ubwp->bwp_Common->genericParameters.locationAndBandwidth,275));
441

442
  dci_pdu_rel15->time_domain_assignment = 2; // row index used here instead of SLIV;
443
  dci_pdu_rel15->frequency_hopping_flag = 0;
444
  dci_pdu_rel15->mcs = 9;
445
  
446 447 448 449 450
  dci_pdu_rel15->format_indicator = 0;
  dci_pdu_rel15->ndi = 1;
  dci_pdu_rel15->rv = 0;
  dci_pdu_rel15->harq_pid = 0;
  dci_pdu_rel15->tpc = 2;
451
  
452
  LOG_D(MAC, "[gNB scheduler phytest] ULDCI type 0 payload: PDCCH CCEIndex %d, freq_alloc %d, time_alloc %d, freq_hop_flag %d, mcs %d tpc %d ndi %d rv %d\n",
453 454 455 456 457 458 459 460
	pdcch_pdu_rel15->CceIndex[pdcch_pdu_rel15->numDlDci],
	dci_pdu_rel15->frequency_domain_assignment,
	dci_pdu_rel15->time_domain_assignment,
	dci_pdu_rel15->frequency_hopping_flag,
	dci_pdu_rel15->mcs,
	dci_pdu_rel15->tpc,
	dci_pdu_rel15->ndi, 
	dci_pdu_rel15->rv);
461 462 463 464 465 466 467 468 469
  
  dci_formats[pdcch_pdu_rel15->numDlDci] = NR_UL_DCI_FORMAT_0_0;
  rnti_types[pdcch_pdu_rel15->numDlDci]  = NR_RNTI_C;
  pdcch_pdu_rel15->numDlDci++;

}
    


Raymond Knopp's avatar
Raymond Knopp committed
470 471 472
void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
                                   frame_t       frameP,
                                   sub_frame_t   slotP,
Raymond Knopp's avatar
Raymond Knopp committed
473
                                   nfapi_nr_dl_tti_pdsch_pdu_rel15_t *dlsch_config)
Raymond Knopp's avatar
Raymond Knopp committed
474 475 476 477 478 479
{
  LOG_D(MAC, "In nr_schedule_uss_dlsch_phytest \n");
  
  gNB_MAC_INST                        *nr_mac      = RC.nrmac[module_idP];
  //NR_COMMON_channels_t                *cc           = nr_mac->common_channels;
  //NR_ServingCellConfigCommon_t *scc=cc->ServingCellConfigCommon;
Raymond Knopp's avatar
Raymond Knopp committed
480 481
  nfapi_nr_dl_tti_request_body_t   *dl_req;
  nfapi_nr_pdu_t            *TX_req;
482

483

Raymond Knopp's avatar
Raymond Knopp committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
  int TBS;
  int TBS_bytes;
  int lcid;
  int ta_len = 0;
  int header_length_total=0;
  int header_length_last;
  int sdu_length_total = 0;
  mac_rlc_status_resp_t rlc_status;
  uint16_t sdu_lengths[NB_RB_MAX];
  int num_sdus = 0;
  unsigned char dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
  int offset;
  int UE_id = 0;
  unsigned char sdu_lcids[NB_RB_MAX];
  int padding = 0, post_padding = 0;
499 500
  NR_UE_list_t *UE_list = &nr_mac->UE_list;
  uint16_t rnti = UE_list->rnti[UE_id];
501 502
  DLSCH_PDU dlsch_pdu;
  //PDSCH_PDU *pdsch_pdu = (PDSCH_PDU*) malloc(sizeof(PDSCH_PDU));
Raymond Knopp's avatar
Raymond Knopp committed
503
  
504
  int CCEIndex=-1;
Raymond Knopp's avatar
Raymond Knopp committed
505 506 507
  
  LOG_D(MAC, "Scheduling UE specific search space DCI type 1\n");
  int CC_id=0;
Raymond Knopp's avatar
Raymond Knopp committed
508 509
  dl_req = &nr_mac->DL_req[CC_id].dl_tti_request_body;
  TX_req = &nr_mac->TX_req[CC_id].pdu_list[nr_mac->TX_req[CC_id].Number_of_PDUs];
510 511 512 513 514
  
  //The --NOS1 use case currently schedules DLSCH transmissions only when there is IP traffic arriving
  //through the LTE stack
  if (IS_SOFTMODEM_NOS1){
    
515
    memset(&dlsch_pdu, 0, sizeof(DLSCH_PDU));
516 517 518 519 520
    int ta_update = 31;
    ta_len = 0;
    
    // Hardcode it for now
    TBS = 6784/8; //TBS in bytes
Raymond Knopp's avatar
Raymond Knopp committed
521
    //TBS = dl_tti_pdsch_pdu->pdsch_pdu.dlsch_pdu_rel15.transport_block_size;
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    
    for (lcid = NB_RB_MAX - 1; lcid >= DTCH; lcid--) {
      // TODO: check if the lcid is active
      
      LOG_D(MAC, "[eNB %d], Frame %d, DTCH%d->DLSCH, Checking RLC status (tbs %d, len %d)\n",
	    module_idP, frameP, lcid, TBS,
	    TBS - ta_len - header_length_total - sdu_length_total - 3);
      
      if (TBS - ta_len - header_length_total - sdu_length_total - 3 > 0) {
	rlc_status = mac_rlc_status_ind(module_idP,
					rnti,
					module_idP,
					frameP,
					slotP,
					ENB_FLAG_YES,
					MBMS_FLAG_NO,
					lcid,
					TBS - ta_len - header_length_total - sdu_length_total - 3
					//#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
					,0, 0
					//#endif
					);
	
	if (rlc_status.bytes_in_buffer > 0) {
	  LOG_D(MAC,
		"[eNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting %d bytes from RLC (lcid %d total hdr len %d), TBS: %d \n \n",
		module_idP, frameP,
		TBS - ta_len - header_length_total - sdu_length_total - 3,
		lcid,
		header_length_total,
		TBS);
553 554 555 556 557 558 559 560 561 562

	  CCEIndex = allocate_nr_CCEs(nr_mac,
				      1, // bwp_id
				      0, // coreset_id
				      4, // aggregation,
				      1, // search_space, 0 common, 1 ue-specific
				      UE_id,
				      0); // m
	  if (CCEIndex == -1) return;

563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
	  sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, rnti, module_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, lcid,
						   TBS,
						   (char *)&dlsch_buffer[sdu_length_total]
						   //#if (RRC_VERSION >= MAKE_VERSION(14, 0, 0))
						   ,0, 0
						   //#endif
						   );
	  
	  
	  
	  LOG_D(MAC,
		"[eNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",
		module_idP, sdu_lengths[num_sdus], lcid);
	  
	  sdu_lcids[num_sdus] = lcid;
	  sdu_length_total += sdu_lengths[num_sdus];
	  header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128);
	  header_length_total += header_length_last;
	  
	  num_sdus++;
	}
      } else {
	// no TBS left
	break;
      }
    }
    
    // last header does not have length field
    if (header_length_total) {
      header_length_total -= header_length_last;
      header_length_total++;
    }
    
    
597
    if (ta_len + sdu_length_total + header_length_total > 0) {
598 599 600 601 602 603 604 605 606 607
      
      
      if (TBS - header_length_total - sdu_length_total - ta_len <= 2) {
	padding = TBS - header_length_total - sdu_length_total - ta_len;
	post_padding = 0;
      } else {
	padding = 0;
	post_padding = 1;
      }
      
Raymond Knopp's avatar
Raymond Knopp committed
608
      offset = generate_dlsch_header((unsigned char *)nr_mac->UE_list.DLSCH_pdu[0][0].payload[0], //DLSCH_pdu.payload[0],
609 610 611 612 613 614
				     num_sdus,    //num_sdus
				     sdu_lengths,    //
				     sdu_lcids, 255,    // no drx
				     ta_update,    // timing advance
				     NULL,    // contention res id
				     padding, post_padding);
615

616 617 618 619 620 621
      LOG_D(MAC, "Offset bits: %d \n", offset);
      
      // Probably there should be other actions done before that
      // cycle through SDUs and place in dlsch_buffer
      
      //memcpy(&UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total);
Raymond Knopp's avatar
Raymond Knopp committed
622
      memcpy(&nr_mac->UE_list.DLSCH_pdu[0][UE_id].payload[0][offset], dlsch_buffer, sdu_length_total);
623 624 625 626 627
      
      
      // fill remainder of DLSCH with 0
      for (int j = 0; j < (TBS - sdu_length_total - offset); j++) {
	//UE_list->DLSCH_pdu[CC_id][0][UE_id].payload[0][offset + sdu_length_total + j] = 0;
Raymond Knopp's avatar
Raymond Knopp committed
628
	nr_mac->UE_list.DLSCH_pdu[0][0].payload[0][offset + sdu_length_total + j] = 0;
629
      }
630 631 632 633 634

      AssertFatal(CCEIndex>0,"CCEIndex is negative\n");
      int CCEIndices[2];
      CCEIndices[0] = CCEIndex;

Raymond Knopp's avatar
Raymond Knopp committed
635
      TBS_bytes = configure_fapi_dl_Tx(module_idP,
636
				       CCEIndices,
Raymond Knopp's avatar
Raymond Knopp committed
637
				       dl_req, 
638 639 640 641
				       TX_req,
				       dlsch_config!=NULL ? dlsch_config->mcsIndex : NULL,
				       dlsch_config!=NULL ? &dlsch_config->rbSize : NULL,
				       dlsch_config!=NULL ? &dlsch_config->rbStart : NULL);
642 643 644
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
      LOG_I(MAC, "Printing first 10 payload bytes at the gNB side, Frame: %d, slot: %d, , TBS size: %d \n \n", frameP, slotP, TBS_bytes);
      for(int i = 0; i < 10; i++) { // TBS_bytes dlsch_pdu_rel15->transport_block_size/8 6784/8
Raymond Knopp's avatar
Raymond Knopp committed
645 646
      LOG_I(MAC, "%x. ", ((uint8_t *)nr_mac->UE_list.DLSCH_pdu[CC_id][0][0].payload[0])[i]);
    }
647 648
#endif
      
Raymond Knopp's avatar
Raymond Knopp committed
649 650 651
      TX_req->num_TLV=1;
      TX_req->TLVs[0].length = TBS_bytes +2;
      memcpy((void*)&TX_req->TLVs[0].value.direct[0],(void*)&nr_mac->UE_list.DLSCH_pdu[0][0].payload[0],TBS_bytes);;
652 653
      
      
Raymond Knopp's avatar
Raymond Knopp committed
654 655 656
      nr_mac->TX_req[CC_id].Number_of_PDUs++;
      nr_mac->TX_req[CC_id].SFN = frameP;
      nr_mac->TX_req[CC_id].Slot = slotP;
657
    } //if (ta_len + sdu_length_total + header_length_total > 0)
658 659
  } //if (IS_SOFTMODEM_NOS1)
  
Raymond Knopp's avatar
Raymond Knopp committed
660 661
    //When the --NOS1 option is not enabled, DLSCH transmissions with random data
    //occur every time that the current function is called (dlsch phytest mode)
662
  else{
663 664 665 666 667 668 669
    CCEIndex = allocate_nr_CCEs(nr_mac,
				1, // bwp_id
				0, // coreset_id
				4, // aggregation,
				1, // search_space, 0 common, 1 ue-specific
				UE_id,
				0); // m
670
    AssertFatal(CCEIndex>=0,"CCEIndex is negative\n");
671 672 673 674
    if (CCEIndex == -1) return;

    int CCEIndices[2];
    CCEIndices[0] = CCEIndex;
675 676 677 678 679 680 681
    LOG_D(MAC,"Configuring DL_TX in %d.%d\n",frameP,slotP);
    TBS_bytes = configure_fapi_dl_Tx(module_idP,CCEIndices,dl_req, TX_req,
				     dlsch_config!=NULL ? dlsch_config->mcsIndex : NULL,
				     dlsch_config!=NULL ? &dlsch_config->rbSize : NULL,
				     dlsch_config!=NULL ? &dlsch_config->rbStart : NULL); 
// HOT FIX for all zero pdu problem
// ------------------------------------------------------------------------------------------------
682 683
    
    for(int i = 0; i < TBS_bytes; i++) { //
Raymond Knopp's avatar
Raymond Knopp committed
684
      ((uint8_t *)nr_mac->UE_list.DLSCH_pdu[0][0].payload[0])[i] = (unsigned char) rand();
685 686 687 688
      //LOG_I(MAC, "%x. ", ((uint8_t *)nr_mac->UE_list.DLSCH_pdu[CC_id][0][0].payload[0])[i]);
    }
#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
    if (frameP%100 == 0){
689 690 691 692
      LOG_I(MAC, "Printing first 10 payload bytes at the gNB side, Frame: %d, slot: %d, TBS size: %d \n", frameP, slotP, TBS_bytes);
      for(int i = 0; i < 10; i++) {
	LOG_I(MAC, "%x. ", ((uint8_t *)nr_mac->UE_list.DLSCH_pdu[CC_id][0][0].payload[0])[i]);
      }
693 694 695 696
    }
#endif
    
    //TX_req->segments[0].segment_length = 8;
Raymond Knopp's avatar
Raymond Knopp committed
697 698 699 700 701 702 703 704 705
    TX_req->num_TLV=1;
    TX_req->TLVs[0].length = TBS_bytes +2;
    memcpy((void*)&TX_req->TLVs[0].value.direct[0],
	   (void*)&nr_mac->UE_list.DLSCH_pdu[0][0].payload[0],
	   TBS_bytes);
    
    nr_mac->TX_req[CC_id].Number_of_PDUs++;
    nr_mac->TX_req[CC_id].SFN = frameP;
    nr_mac->TX_req[CC_id].Slot = slotP;
706
    // ------------------------------------------------------------------------------------------------
Ahmed Hussein's avatar
Ahmed Hussein committed
707
  }
Raymond Knopp's avatar
Raymond Knopp committed
708 709 710
}


711
void nr_schedule_uss_ulsch_phytest(int Mod_idP,
712
                                   frame_t       frameP,
713
                                   sub_frame_t   slotP) {
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728

  gNB_MAC_INST                      *nr_mac      = RC.nrmac[Mod_idP];
  NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
  NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;

  int bwp_id=1;

  int UE_id = 0;
  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
  AssertFatal(UE_list->active[UE_id] >=0,"Cannot find UE_id %d is not active\n",UE_id);

  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
  AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
	      "downlinkBWP_ToAddModList has %d BWP!\n",
	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
729
  NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[bwp_id-1];
730 731 732 733 734 735 736
  NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];
  nfapi_nr_ul_tti_request_t *UL_tti_req = &RC.nrmac[Mod_idP]->UL_tti_req[0];
  nfapi_nr_ul_dci_request_t *UL_dci_req = &RC.nrmac[Mod_idP]->UL_dci_req[0];


  uint16_t rnti = UE_list->rnti[UE_id];
  nfapi_nr_ul_dci_request_pdus_t  *ul_dci_request_pdu;
Raymond Knopp's avatar
Raymond Knopp committed
737

738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
  UL_tti_req->SFN = frameP;
  UL_tti_req->Slot = slotP;
  UL_tti_req->n_pdus = 1;
  UL_tti_req->pdus_list[0].pdu_type = NFAPI_NR_UL_CONFIG_PUSCH_PDU_TYPE;
  UL_tti_req->pdus_list[0].pdu_size = sizeof(nfapi_nr_pusch_pdu_t);
  nfapi_nr_pusch_pdu_t  *pusch_pdu = &UL_tti_req->pdus_list[0].pusch_pdu;
  memset(pusch_pdu,0,sizeof(nfapi_nr_pusch_pdu_t));
  
  LOG_D(MAC, "Scheduling UE specific PUSCH\n");
  //UL_tti_req = &nr_mac->UL_tti_req[CC_id];
  /*
  // original configuration
  rel15_ul->rnti                           = 0x1234;
  rel15_ul->ulsch_pdu_rel15.start_rb       = 30;
  rel15_ul->ulsch_pdu_rel15.number_rbs     = 50;
  rel15_ul->ulsch_pdu_rel15.start_symbol   = 2;
  rel15_ul->ulsch_pdu_rel15.number_symbols = 12;
  rel15_ul->ulsch_pdu_rel15.nb_re_dmrs     = 6;
  rel15_ul->ulsch_pdu_rel15.length_dmrs    = 1;
  rel15_ul->ulsch_pdu_rel15.Qm             = 2;
  rel15_ul->ulsch_pdu_rel15.mcs            = 9;
  rel15_ul->ulsch_pdu_rel15.rv             = 0;
  rel15_ul->ulsch_pdu_rel15.n_layers       = 1;
  */
  pusch_pdu->pdu_bit_map = PUSCH_PDU_BITMAP_PUSCH_DATA;
  pusch_pdu->rnti = rnti;
  pusch_pdu->handle = 0; //not yet used
  
  pusch_pdu->bwp_size  = NRRIV2BW(ubwp->bwp_Common->genericParameters.locationAndBandwidth,275);
  pusch_pdu->bwp_start = NRRIV2PRBOFFSET(ubwp->bwp_Common->genericParameters.locationAndBandwidth,275);
  pusch_pdu->subcarrier_spacing = ubwp->bwp_Common->genericParameters.subcarrierSpacing;
  pusch_pdu->cyclic_prefix = 0;
  //pusch information always include
  //this informantion seems to be redundant. with hthe mcs_index and the modulation table, the mod_order and target_code_rate can be determined.
  pusch_pdu->mcs_index = 9;
  pusch_pdu->mcs_table = 0; //0: notqam256 [TS38.214, table 5.1.3.1-1] - corresponds to nr_target_code_rate_table1 in PHY
  pusch_pdu->target_code_rate = nr_get_code_rate_ul(pusch_pdu->mcs_index,pusch_pdu->mcs_table) ;
  pusch_pdu->qam_mod_order = nr_get_Qm_ul(pusch_pdu->mcs_index,pusch_pdu->mcs_table) ;
  pusch_pdu->transform_precoding = 0;
  pusch_pdu->data_scrambling_id = 0; //It equals the higher-layer parameter Data-scrambling-Identity if configured and the RNTI equals the C-RNTI, otherwise L2 needs to set it to physical cell id.;
  pusch_pdu->nrOfLayers = 1;
  //DMRS
  pusch_pdu->ul_dmrs_symb_pos = 1;
  pusch_pdu->dmrs_config_type = 0;  //dmrs-type 1 (the one with a single DMRS symbol in the beginning)
  pusch_pdu->ul_dmrs_scrambling_id =  0; //If provided and the PUSCH is not a msg3 PUSCH, otherwise, L2 should set this to physical cell id.
  pusch_pdu->scid = 0; //DMRS sequence initialization [TS38.211, sec 6.4.1.1.1]. Should match what is sent in DCI 0_1, otherwise set to 0.
  //pusch_pdu->num_dmrs_cdm_grps_no_data;
  //pusch_pdu->dmrs_ports; //DMRS ports. [TS38.212 7.3.1.1.2] provides description between DCI 0-1 content and DMRS ports. Bitmap occupying the 11 LSBs with: bit 0: antenna port 1000 bit 11: antenna port 1011 and for each bit 0: DMRS port not used 1: DMRS port used
  //Pusch Allocation in frequency domain [TS38.214, sec 6.1.2.2]
  pusch_pdu->resource_alloc = 1; //type 1
  //pusch_pdu->rb_bitmap;// for ressource alloc type 0
  pusch_pdu->rb_start = 0;
  pusch_pdu->rb_size = 50;
  pusch_pdu->vrb_to_prb_mapping = 0;
  pusch_pdu->frequency_hopping = 0;
  //pusch_pdu->tx_direct_current_location;//The uplink Tx Direct Current location for the carrier. Only values in the value range of this field between 0 and 3299, which indicate the subcarrier index within the carrier corresponding 1o the numerology of the corresponding uplink BWP and value 3300, which indicates "Outside the carrier" and value 3301, which indicates "Undetermined position within the carrier" are used. [TS38.331, UplinkTxDirectCurrentBWP IE]
  pusch_pdu->uplink_frequency_shift_7p5khz = 0;
  //Resource Allocation in time domain
  pusch_pdu->start_symbol_index = 2;
  pusch_pdu->nr_of_symbols = 12;
  //Optional Data only included if indicated in pduBitmap
  pusch_pdu->pusch_data.rv_index = 0;
  pusch_pdu->pusch_data.harq_process_id = 0;
  pusch_pdu->pusch_data.new_data_indicator = 0;
  pusch_pdu->pusch_data.tb_size = nr_compute_tbs(pusch_pdu->mcs_index,
						 pusch_pdu->target_code_rate,
						 pusch_pdu->rb_size,
						 pusch_pdu->nr_of_symbols,
						 6, //nb_re_dmrs - not sure where this is coming from - its not in the FAPI
						 0, //nb_rb_oh
						 pusch_pdu->nrOfLayers = 1);
  pusch_pdu->pusch_data.num_cb = 0; //CBG not supported
  //pusch_pdu->pusch_data.cb_present_and_position;
  //pusch_pdu->pusch_uci;
  //pusch_pdu->pusch_ptrs;
  //pusch_pdu->dfts_ofdm;
  //beamforming
  //pusch_pdu->beamforming; //not used for now

817 818 819 820 821 822 823 824 825 826

  ul_dci_request_pdu = &UL_dci_req->ul_dci_pdu_list[UL_dci_req->numPdus];
  memset((void*)ul_dci_request_pdu,0,sizeof(nfapi_nr_ul_dci_request_pdus_t));
  ul_dci_request_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
  ul_dci_request_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15 = &ul_dci_request_pdu->pdcch_pdu.pdcch_pdu_rel15;

  int dci_formats[2];
  int rnti_types[2];

827 828 829 830 831 832 833 834
  int CCEIndex = allocate_nr_CCEs(nr_mac,
				  1, // bwp_id
				  0, // coreset_id
				  4, // aggregation,
				  1, // search_space, 0 common, 1 ue-specific
				  UE_id,
				  0); // m

835 836
  dci_formats[0]  = NR_UL_DCI_FORMAT_0_0;
  rnti_types[0]   = NR_RNTI_C;
837
  LOG_D(MAC,"Configuring ULDCI/PDCCH in %d.%d\n", frameP,slotP);
838 839 840 841 842
  nr_configure_pdcch(pdcch_pdu_rel15,
		     1, // ue-specific,
		     scc,
		     bwp);

843
  
844 845
  dci_pdu_rel15_t dci_pdu_rel15[MAX_DCI_CORESET];

846 847 848
  AssertFatal(CCEIndex>=0,"CCEIndex is negative \n");
  pdcch_pdu_rel15->CceIndex[pdcch_pdu_rel15->numDlDci] = CCEIndex;

849
  LOG_D(PHY,"CCEIndex %d\n",pdcch_pdu_rel15->CceIndex[pdcch_pdu_rel15->numDlDci]);
850 851

  config_uldci(ubwp,pusch_pdu,pdcch_pdu_rel15, &dci_pdu_rel15[0], dci_formats, rnti_types);
852 853 854 855
  
  pdcch_pdu_rel15->PayloadSizeBits[0]=nr_dci_size(dci_formats[0],rnti_types[0],pdcch_pdu_rel15->BWPSize);
  fill_dci_pdu_rel15(pdcch_pdu_rel15,&dci_pdu_rel15[0],dci_formats,rnti_types);
  
856
}