[GITLAB] - UPGRADE TO v12 on Wednesday the 18th of December at 11.30AM

nr_dci_tools.c 16.7 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 32
/*
 * 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.1  (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 PHY/NR_TRANSPORT/nr_dci_tools.c
 * \brief
 * \author
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email:
 * \note
 * \warning
 */

33
#include "nr_dci.h"
34

35
//#define DEBUG_FILL_DCI
36

Guy De Souza's avatar
Guy De Souza committed
37
#include "nr_dlsch.h"
Guy De Souza's avatar
Guy De Souza committed
38

39

Guy De Souza's avatar
Guy De Souza committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
void nr_fill_cce_list(NR_gNB_DCI_ALLOC_t* dci_alloc, uint16_t n_shift, uint8_t m) {

  nr_cce_t* cce;
  nr_reg_t* reg;
  nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params = &dci_alloc->pdcch_params;

  uint8_t L = dci_alloc->L;
  uint8_t bsize = pdcch_params->reg_bundle_size;
  uint8_t R = pdcch_params->interleaver_size;
  uint16_t N_reg = pdcch_params->n_rb * pdcch_params->n_symb;
  uint16_t Y, N_cce, M_s_max, n_CI=0, tmp, C;

  if (pdcch_params->config_type == NFAPI_NR_CSET_CONFIG_MIB_SIB1)
    AssertFatal(L>=4, "Invalid aggregation level for SIB1 configured PDCCH %d\n", L);

  N_cce = N_reg / NR_NB_REG_PER_CCE;
Guy De Souza's avatar
Guy De Souza committed
56
  /*Max number of candidates per aggregation level -- SIB1 configured search space only*/
Guy De Souza's avatar
Guy De Souza committed
57 58 59 60 61 62 63
  M_s_max = (L==4)?4:(L==8)?2:1;

  if (pdcch_params->search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_COMMON)
    Y = 0;
  else { //NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC
  }

Guy De Souza's avatar
Guy De Souza committed
64
  uint8_t cond = N_reg%(bsize*R);
65 66
  AssertFatal(cond==0, "CCE to REG interleaving: Invalid configuration leading to non integer C (N_reg %d, bsize %d R %d)\n",
  N_reg, bsize, R);
Guy De Souza's avatar
Guy De Souza committed
67 68
  C = N_reg/(bsize*R);

Guy De Souza's avatar
Guy De Souza committed
69
  tmp = L * (( Y + (m*N_cce)/(L*M_s_max) + n_CI ) % (N_cce/L));
Guy De Souza's avatar
Guy De Souza committed
70 71 72 73 74

  LOG_I(PHY, "CCE list generation for candidate %d: bundle size %d ilv size %d tmp %d\n", m, bsize, R, tmp);
  for (uint8_t cce_idx=0; cce_idx<L; cce_idx++) {
    cce = &dci_alloc->cce_list[cce_idx];
    cce->cce_idx = tmp + cce_idx;
Guy De Souza's avatar
Guy De Souza committed
75
    LOG_D(PHY, "cce_idx %d\n", cce->cce_idx);
Guy De Souza's avatar
Guy De Souza committed
76

Guy De Souza's avatar
Guy De Souza committed
77
    if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) {
Guy De Souza's avatar
Guy De Souza committed
78
      LOG_D(PHY, "Interleaved CCE to REG mapping\n");
Guy De Souza's avatar
Guy De Souza committed
79 80 81
      uint8_t j = cce->cce_idx, j_prime;
      uint8_t r,c,idx;

Guy De Souza's avatar
Guy De Souza committed
82 83
      for (uint8_t bundle_idx=0; bundle_idx<NR_NB_REG_PER_CCE/bsize; bundle_idx++) {
        j_prime = 6*j/bsize + bundle_idx;
Guy De Souza's avatar
Guy De Souza committed
84 85 86
        r = j_prime%R;
        c = (j_prime-r)/R;
        idx = (r*C + c + n_shift)%(N_reg/bsize);
Guy De Souza's avatar
Guy De Souza committed
87
        LOG_D(PHY, "bundle idx = %d \n j = %d \t j_prime = %d \t r = %d \t c = %d\n", idx, j , j_prime, r, c);
Guy De Souza's avatar
Guy De Souza committed
88 89

        for (uint8_t reg_idx=0; reg_idx<bsize; reg_idx++) {
Guy De Souza's avatar
Guy De Souza committed
90 91 92 93
          reg = &cce->reg_list[reg_idx];
          reg->reg_idx = bsize*idx + reg_idx;
          reg->start_sc_idx = (reg->reg_idx/pdcch_params->n_symb) * NR_NB_SC_PER_RB;
          reg->symb_idx = reg->reg_idx % pdcch_params->n_symb;
Guy De Souza's avatar
Guy De Souza committed
94
          LOG_D(PHY, "reg %d symbol %d start subcarrier %d\n", reg->reg_idx, reg->symb_idx, reg->start_sc_idx);
Guy De Souza's avatar
Guy De Souza committed
95
        }
Guy De Souza's avatar
Guy De Souza committed
96
      }
Guy De Souza's avatar
Guy De Souza committed
97 98 99 100 101 102 103 104 105
    }
    else { // NFAPI_NR_CCE_REG_MAPPING_NON_INTERLEAVED
      LOG_D(PHY, "Non interleaved CCE to REG mapping\n");
      for (uint8_t reg_idx=0; reg_idx<NR_NB_REG_PER_CCE; reg_idx++) {
        reg = &cce->reg_list[reg_idx];
        reg->reg_idx = cce->cce_idx*NR_NB_REG_PER_CCE + reg_idx;
        reg->start_sc_idx = (reg->reg_idx/pdcch_params->n_symb) * NR_NB_SC_PER_RB;
        reg->symb_idx = reg->reg_idx % pdcch_params->n_symb;
        LOG_D(PHY, "reg %d symbol %d start subcarrier %d\n", reg->reg_idx, reg->symb_idx, reg->start_sc_idx);
Guy De Souza's avatar
Guy De Souza committed
106
      }
Guy De Souza's avatar
Guy De Souza committed
107

Guy De Souza's avatar
Guy De Souza committed
108
    }
Guy De Souza's avatar
Guy De Souza committed
109

Guy De Souza's avatar
Guy De Souza committed
110 111 112
  }
}

113
void nr_fill_dci_and_dlsch(PHY_VARS_gNB *gNB,
Guy De Souza's avatar
Guy De Souza committed
114 115
                           int frame,
                           int subframe,
Wang Tsu-Han's avatar
Wang Tsu-Han committed
116
                           gNB_L1_rxtx_proc_t *proc,
Guy De Souza's avatar
Guy De Souza committed
117
                           NR_gNB_DCI_ALLOC_t *dci_alloc,
Guy De Souza's avatar
Guy De Souza committed
118 119
                           nfapi_nr_dl_config_dci_dl_pdu *pdcch_pdu,
                           nfapi_nr_dl_config_dlsch_pdu *dlsch_pdu)
120
{
121

Guy De Souza's avatar
Guy De Souza committed
122
  uint8_t n_shift;
123

124

125 126
  uint64_t *dci_pdu = (uint64_t*)dci_alloc->dci_pdu;
  memset((void*)dci_pdu,0,2*sizeof(uint64_t));
127
  nfapi_nr_dl_config_dci_dl_pdu_rel15_t *pdu_rel15 = &pdcch_pdu->dci_dl_pdu_rel15;
Guy De Souza's avatar
Guy De Souza committed
128
  nfapi_nr_dl_config_pdcch_parameters_rel15_t *params_rel15 = &pdcch_pdu->pdcch_params_rel15;
129

130

131
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
132
  NR_gNB_DLSCH_t *dlsch = gNB->dlsch[0][0];
Guy De Souza's avatar
Guy De Souza committed
133
  NR_DL_gNB_HARQ_t **harq = dlsch->harq_processes;
134

Guy De Souza's avatar
Guy De Souza committed
135
  uint16_t N_RB = params_rel15->n_RB_BWP;
Guy De Souza's avatar
Guy De Souza committed
136
  uint8_t fsize=0, pos=0, cand_idx=0;
137

138

Guy De Souza's avatar
Guy De Souza committed
139 140 141
  dci_alloc->L = 8;
  memcpy((void*)&dci_alloc->pdcch_params, (void*)params_rel15, sizeof(nfapi_nr_dl_config_pdcch_parameters_rel15_t));
  dci_alloc->size = nr_get_dci_size(dci_alloc->pdcch_params.dci_format,
142 143 144
				    dci_alloc->pdcch_params.rnti_type,
				    N_RB,
				    cfg);
Guy De Souza's avatar
Guy De Souza committed
145

Guy De Souza's avatar
Guy De Souza committed
146
  AssertFatal(dci_alloc->size<=64, "DCI sizes above 64 bits not yet supported");
Guy De Souza's avatar
Guy De Souza committed
147
  n_shift = (dci_alloc->pdcch_params.config_type == NFAPI_NR_CSET_CONFIG_MIB_SIB1)?
148
    cfg->sch_config.physical_cell_id.value : dci_alloc->pdcch_params.shift_index;
Guy De Souza's avatar
Guy De Souza committed
149 150
  nr_fill_cce_list(dci_alloc, n_shift, cand_idx);

Guy De Souza's avatar
Guy De Souza committed
151 152 153
  /// Payload generation
  switch(params_rel15->dci_format) {

154

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  case NFAPI_NR_DL_DCI_FORMAT_1_0:
    switch(params_rel15->rnti_type) {
    case NFAPI_NR_RNTI_RA:
      //      printf("dci_pdu %llx\n",(unsigned long long int)*dci_pdu);
      // Freq domain assignment
      fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
      pos=fsize;
      *dci_pdu |= ((pdu_rel15->frequency_domain_assignment&((1<<fsize)-1)) << (dci_alloc->size-pos)); 
#ifdef DEBUG_FILL_DCI
      printf("frequency-domain assignment %d (%d bits)=> %d (%llx)\n",pdu_rel15->frequency_domain_assignment,fsize,dci_alloc->size-pos,(unsigned long long int)*dci_pdu);
#endif
      // Time domain assignment
      pos+=4;		   
      *dci_pdu |= ((pdu_rel15->time_domain_assignment&0xf) << (dci_alloc->size-pos)); 
#ifdef DEBUG_FILL_DCI
      printf("time-domain assignment %d  (3 bits)=> %d (%llx)\n",pdu_rel15->time_domain_assignment,dci_alloc->size-pos,(unsigned long long int)*dci_pdu);
#endif
      // VRB to PRB mapping

      pos++;
      *dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&0x1)<<(dci_alloc->size-pos);
#ifdef DEBUG_FILL_DCI
      printf("vrb to prb mapping %d  (1 bits)=> %d (%llx)\n",pdu_rel15->vrb_to_prb_mapping,dci_alloc->size-pos,(unsigned long long int)*dci_pdu);
#endif
      // MCS
      pos+=5;
      *dci_pdu |= (pdu_rel15->mcs&0x1f)<<(dci_alloc->size-pos);
#ifdef DEBUG_FILL_DCI
      printf("mcs %d  (5 bits)=> %d (%llx)\n",pdu_rel15->mcs,dci_alloc->size-pos,(unsigned long long int)*dci_pdu);
#endif
      // TB scaling
      pos+=2;
      *dci_pdu |= (pdu_rel15->tb_scaling&0x3)<<(dci_alloc->size-pos);
#ifdef DEBUG_FILL_DCI
      printf("tb_scaling %d  (2 bits)=> %d (%llx)\n",pdu_rel15->tb_scaling,dci_alloc->size-pos,(unsigned long long int)*dci_pdu);
#endif
      break;

    case NFAPI_NR_RNTI_C:  
      // indicating a DL DCI format 1bit
195 196
      pos++;
      *dci_pdu |= (pdu_rel15->format_indicator&1)<<(dci_alloc->size-pos);
197 198
      // Freq domain assignment (275rb >> fsize = 16)
      fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
199 200
      pos+=fsize;
      *dci_pdu |= ((pdu_rel15->frequency_domain_assignment&((1<<fsize)-1)) << (dci_alloc->size-pos)); 
201 202 203 204

      if (((pdu_rel15->frequency_domain_assignment+1)&1) ==0) //fsize are all 1  38.212 p86
	{
	  // ra_preamble_index 6 bits
205 206
	  pos+=6;
	  *dci_pdu |= ((pdu_rel15->ra_preamble_index&0x3f)<<(dci_alloc->size-pos));
207 208

	  // UL/SUL indicator  1 bit
209 210
	  pos++;
	  *dci_pdu |= (pdu_rel15->ul_sul_indicator&1)<<(dci_alloc->size-pos);
Guy De Souza's avatar
Guy De Souza committed
211
          
212
	  // SS/PBCH index  6 bits
213 214
	  pos+=6;
	  *dci_pdu |= ((pdu_rel15->ss_pbch_index&0x3f)<<(dci_alloc->size-pos));
Guy De Souza's avatar
Guy De Souza committed
215
        
216
	  //  prach_mask_index  4 bits
217 218
	  pos+=4;
	  *dci_pdu |= ((pdu_rel15->prach_mask_index&0xf)<<(dci_alloc->size-pos));
Guy De Souza's avatar
Guy De Souza committed
219
          
220
	}  //end if
Guy De Souza's avatar
Guy De Souza committed
221

222
      else {
Guy De Souza's avatar
Guy De Souza committed
223

224
	// Time domain assignment 4bit
225 226 227 228

	pos+=4;		   
	*dci_pdu |= ((pdu_rel15->time_domain_assignment&0xf) << (dci_alloc->size-pos)); 

Guy De Souza's avatar
Guy De Souza committed
229
      
230
	// VRB to PRB mapping  1bit
231 232
	pos++;
	*dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&1)<<(dci_alloc->size-pos);
Guy De Souza's avatar
Guy De Souza committed
233
      
234
	// MCS 5bit  //bit over 32, so dci_pdu ++
235 236
	pos+=5;
	*dci_pdu |= (pdu_rel15->mcs&0x1f)<<(dci_alloc->size-pos);
Guy De Souza's avatar
Guy De Souza committed
237
    
238
	// New data indicator 1bit
239 240
	pos++;
	*dci_pdu |= (pdu_rel15->ndi&1)<<(dci_alloc->size-pos);
Guy De Souza's avatar
Guy De Souza committed
241
      
242
	// Redundancy version  2bit
243 244
	pos+=2;
	*dci_pdu |= (pdu_rel15->rv&0x3)<<(dci_alloc->size-pos);
Guy De Souza's avatar
Guy De Souza committed
245
      
246
	// HARQ process number  4bit
247 248
	pos+=4;
	*dci_pdu  |= ((pdu_rel15->harq_pid&0xf)<<(dci_alloc->size-pos));      
Guy De Souza's avatar
Guy De Souza committed
249
 
250
	// Downlink assignment index  2bit
251 252
	pos+=2;
	*dci_pdu |= ((pdu_rel15->dai&3)<<(dci_alloc->size-pos));
Guy De Souza's avatar
Guy De Souza committed
253

254
	// TPC command for scheduled PUCCH  2bit
255 256
	pos+=2;
	*dci_pdu |= ((pdu_rel15->tpc&3)<<(dci_alloc->size-pos));  
Guy De Souza's avatar
Guy De Souza committed
257

258
	// PUCCH resource indicator  3bit
259 260
	pos+=3;
	*dci_pdu |= ((pdu_rel15->pucch_resource_indicator&0x7)<<(dci_alloc->size-pos));      
Guy De Souza's avatar
Guy De Souza committed
261

262
	// PDSCH-to-HARQ_feedback timing indicator 3bit
263 264
	pos+=3;
	*dci_pdu |= ((pdu_rel15->pdsch_to_harq_feedback_timing_indicator&0x7)<<(dci_alloc->size-pos)); 
Guy De Souza's avatar
Guy De Souza committed
265

266 267
      } //end else
      break;
Guy De Souza's avatar
Guy De Souza committed
268

269
    case NFAPI_NR_RNTI_P:
Guy De Souza's avatar
Guy De Souza committed
270
      
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
      // Short Messages Indicator – 2 bits
      for (int i=0; i<2; i++)
	*dci_pdu |= ((pdu_rel15->short_messages_indicator>>(1-i))&1)<<(dci_alloc->size-pos++);
      // Short Messages – 8 bits
      for (int i=0; i<8; i++)
	*dci_pdu |= ((pdu_rel15->short_messages>>(7-i))&1)<<(dci_alloc->size-pos++);
      // Freq domain assignment 0-16 bit
      fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
      for (int i=0; i<fsize; i++)
	*dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<(dci_alloc->size-pos++);
      // Time domain assignment 4 bit
      for (int i=0; i<4; i++)
	*dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<(dci_alloc->size-pos++);
      // VRB to PRB mapping 1 bit
      *dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&1)<<(dci_alloc->size-pos++);
      // MCS 5 bit
      for (int i=0; i<5; i++) 
	*dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
289
      
290 291 292
      // TB scaling 2 bit
      for (int i=0; i<2; i++)
	*dci_pdu |= ((pdu_rel15->tb_scaling>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
293

294

Guy De Souza's avatar
Guy De Souza committed
295 296
      break;
      
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    case NFAPI_NR_RNTI_SI:
      // Freq domain assignment 0-16 bit
      fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
      for (int i=0; i<fsize; i++)
	*dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<(dci_alloc->size-pos++);
      // Time domain assignment 4 bit
      for (int i=0; i<4; i++)
	*dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<(dci_alloc->size-pos++);
      // VRB to PRB mapping 1 bit
      *dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&1)<<(dci_alloc->size-pos++);
      // MCS 5bit  //bit over 32, so dci_pdu ++
      for (int i=0; i<5; i++)
	*dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<(dci_alloc->size-pos++);
      // Redundancy version  2bit
      for (int i=0; i<2; i++)
	*dci_pdu |= ((pdu_rel15->rv>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
313 314 315
      
      break;
      
316
    case NFAPI_NR_RNTI_TC:
Guy De Souza's avatar
Guy De Souza committed
317
      // indicating a DL DCI format 1bit
318
      *dci_pdu |= (pdu_rel15->format_indicator&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
319
      // Freq domain assignment 0-16 bit
320 321 322
      fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
      for (int i=0; i<fsize; i++)
	*dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
323
      // Time domain assignment 4 bit
324 325
      for (int i=0; i<4; i++)
	*dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
326
      // VRB to PRB mapping 1 bit
327
      *dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
328
      // MCS 5bit  //bit over 32, so dci_pdu ++
329 330
      for (int i=0; i<5; i++)
	*dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
331
      // New data indicator 1bit
332
      *dci_pdu |= (pdu_rel15->ndi&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
333
      // Redundancy version  2bit
334 335
      for (int i=0; i<2; i++)
	*dci_pdu |= ((pdu_rel15->rv>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
336
      // HARQ process number  4bit  
337 338
      for (int i=0; i<4; i++)
	*dci_pdu  |= ((pdu_rel15->harq_pid>>(3-i))&1)<<(dci_alloc->size-pos++); 
Guy De Souza's avatar
Guy De Souza committed
339 340
      
      // Downlink assignment index – 2 bits 
341 342
      for (int i=0; i<2; i++)
	*dci_pdu  |= ((pdu_rel15->dai>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
343 344
    
      // TPC command for scheduled PUCCH – 2 bits
345 346
      for (int i=0; i<2; i++)
	*dci_pdu  |= ((pdu_rel15->tpc>>(1-i))&1)<<(dci_alloc->size-pos++);    
Guy De Souza's avatar
Guy De Souza committed
347

348 349 350 351

      //      LOG_I(PHY, "DCI PDU: [0]->0x%08llx \t [1]->0x%08llx \t [2]->0x%08llx \t [3]->0x%08llx\n",
      //	    dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]);

Guy De Souza's avatar
Guy De Souza committed
352 353

      // PDSCH-to-HARQ_feedback timing indicator – 3 bits
354 355
      for (int i=0; i<3; i++)
	*dci_pdu  |= ((pdu_rel15->pdsch_to_harq_feedback_timing_indicator>>(2-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
356 357
      
      break;
358
    }
Guy De Souza's avatar
Guy De Souza committed
359

360
  case NFAPI_NR_UL_DCI_FORMAT_0_0:
Guy De Souza's avatar
Guy De Souza committed
361
    switch(params_rel15->rnti_type)
362
      {
Guy De Souza's avatar
Guy De Souza committed
363
      case NFAPI_NR_RNTI_C:
364 365 366 367 368 369 370 371 372 373 374 375 376
	// indicating a DL DCI format 1bit
	*dci_pdu |= (pdu_rel15->format_indicator&1)<<(dci_alloc->size-pos++);
	// Freq domain assignment  max 16 bit
	fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
	for (int i=0; i<fsize; i++)
	  *dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<(dci_alloc->size-pos++);
	// Time domain assignment 4bit
	for (int i=0; i<4; i++)
	  *dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<(dci_alloc->size-pos++);
	// Frequency hopping flag – 1 bit
	*dci_pdu |= (pdu_rel15->frequency_hopping_flag&1)<<(dci_alloc->size-pos++);
	// MCS  5 bit
	for (int i=0; i<5; i++)
377
          *dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<(dci_alloc->size-pos++);
378 379 380 381 382 383 384 385
	// New data indicator 1bit
	*dci_pdu |= (pdu_rel15->ndi&1)<<(dci_alloc->size-pos++);
	// Redundancy version  2bit
	for (int i=0; i<2; i++)
	  *dci_pdu |= ((pdu_rel15->rv>>(1-i))&1)<<(dci_alloc->size-pos++);
	// HARQ process number  4bit  
	for (int i=0; i<4; i++)
	  *dci_pdu  |= ((pdu_rel15->harq_pid>>(3-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
386
      
387
	// TPC command for scheduled PUSCH – 2 bits
Guy De Souza's avatar
Guy De Souza committed
388
        for (int i=0; i<2; i++)
389
          *dci_pdu |= ((pdu_rel15->tpc>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
390

391
	// Padding bits
Guy De Souza's avatar
Guy De Souza committed
392
        for(int a = pos;a<32;a++)
393
          *dci_pdu |= (pdu_rel15->padding&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
394

395
	// UL/SUL indicator – 1 bit
Guy De Souza's avatar
Guy De Souza committed
396
        if (cfg->pucch_config.pucch_GroupHopping.value)
397
          *dci_pdu |= (pdu_rel15->ul_sul_indicator&1)<<(dci_alloc->size-pos++); 
Guy De Souza's avatar
Guy De Souza committed
398
   
399
	break;
Guy De Souza's avatar
Guy De Souza committed
400 401 402
      
      case NFAPI_NR_RNTI_TC:
      
403 404 405 406 407 408 409 410 411 412 413 414 415
	// indicating a DL DCI format 1bit
	*dci_pdu |= (pdu_rel15->format_indicator&1)<<(dci_alloc->size-pos++);
	// Freq domain assignment  max 16 bit
	fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
	for (int i=0; i<fsize; i++)
	  *dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<(dci_alloc->size-pos++);
	// Time domain assignment 4bit
	for (int i=0; i<4; i++)
	  *dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<(dci_alloc->size-pos++);
	// Frequency hopping flag – 1 bit
	*dci_pdu |= (pdu_rel15->frequency_hopping_flag&1)<<(dci_alloc->size-pos++);
	// MCS  5 bit
	for (int i=0; i<5; i++)
416
          *dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<(dci_alloc->size-pos++);
417 418 419 420
	// New data indicator 1bit
	*dci_pdu |= (pdu_rel15->ndi&1)<<(dci_alloc->size-pos++);
	// Redundancy version  2bit
	for (int i=0; i<2; i++)
421
          *dci_pdu |= ((pdu_rel15->rv>>(1-i))&1)<<(dci_alloc->size-pos++);
422 423
	// HARQ process number  4bit  
	for (int i=0; i<4; i++)
424
          *dci_pdu  |= ((pdu_rel15->harq_pid>>(3-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
425 426 427

        // TPC command for scheduled PUSCH – 2 bits
        for (int i=0; i<2; i++)
428
          *dci_pdu |= ((pdu_rel15->tpc>>(1-i))&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
429 430 431

        // Padding bits
        for(int a = pos;a<32;a++)
432
	  *dci_pdu |= (pdu_rel15->padding&1)<<(dci_alloc->size-pos++);
Guy De Souza's avatar
Guy De Souza committed
433 434 435

        // UL/SUL indicator – 1 bit
        if (cfg->pucch_config.pucch_GroupHopping.value)
436
	  *dci_pdu |= (pdu_rel15->ul_sul_indicator&1)<<(dci_alloc->size-pos++); 
Guy De Souza's avatar
Guy De Souza committed
437 438 439

        break;
      } 
440
    break;
Guy De Souza's avatar
Guy De Souza committed
441 442
  }

443
  LOG_I(PHY, "DCI PDU: [0]->0x%16llxx \t [1]->0x%16llx \n",(long long unsigned int)dci_pdu[0], (long long unsigned int)dci_pdu[1]);
Guy De Souza's avatar
Guy De Souza committed
444
  LOG_I(PHY, "DCI type %d payload (size %d) generated on candidate %d\n", dci_alloc->pdcch_params.dci_format, dci_alloc->size, cand_idx);
445

Guy De Souza's avatar
Guy De Souza committed
446
  /// DLSCH struct
Guy De Souza's avatar
Guy De Souza committed
447
  memcpy((void*)&harq[dci_alloc->harq_pid]->dlsch_pdu, (void*)dlsch_pdu, sizeof(nfapi_nr_dl_config_dlsch_pdu));
Guy De Souza's avatar
Guy De Souza committed
448

449
}