nr_dci_tools.c 9.59 KB
Newer Older
yilmazt's avatar
yilmazt committed
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"
yilmazt's avatar
yilmazt committed
34
#define DEBUG_NFAPI_NR_RNTI_RA
yilmazt's avatar
yilmazt committed
35

Guy De Souza's avatar
Guy De Souza committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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
52
  /*Max number of candidates per aggregation level -- SIB1 configured search space only*/
Guy De Souza's avatar
Guy De Souza committed
53 54 55 56 57 58 59
  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
60 61
  uint8_t cond = N_reg%(bsize*R);
  AssertFatal(cond==0, "CCE to REG interleaving: Invalid configuration leading to non integer C\n");
Guy De Souza's avatar
Guy De Souza committed
62 63 64 65 66 67 68 69
  C = N_reg/(bsize*R);

  tmp = L * (( Y + (uint16_t)(floor((m*N_cce)/(L*M_s_max))) + n_CI ) % ((uint16_t)floor(N_cce/L)));

  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
70
    LOG_D(PHY, "cce_idx %d\n", cce->cce_idx);
Guy De Souza's avatar
Guy De Souza committed
71

Guy De Souza's avatar
Guy De Souza committed
72
    if (pdcch_params->cr_mapping_type == NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED) {
Guy De Souza's avatar
Guy De Souza committed
73
      LOG_D(PHY, "Interleaved CCE to REG mapping\n");
Guy De Souza's avatar
Guy De Souza committed
74 75 76
      uint8_t j = cce->cce_idx, j_prime;
      uint8_t r,c,idx;

Guy De Souza's avatar
Guy De Souza committed
77 78
      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
79 80 81
        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
82
        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
83 84

        for (uint8_t reg_idx=0; reg_idx<bsize; reg_idx++) {
Guy De Souza's avatar
Guy De Souza committed
85 86 87 88
          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
89
          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
90
        }
Guy De Souza's avatar
Guy De Souza committed
91
      }
Guy De Souza's avatar
Guy De Souza committed
92 93 94 95 96 97 98 99 100
    }
    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
101
      }
Guy De Souza's avatar
Guy De Souza committed
102

Guy De Souza's avatar
Guy De Souza committed
103
    }
Guy De Souza's avatar
Guy De Souza committed
104

Guy De Souza's avatar
Guy De Souza committed
105 106 107
  }
}

yilmazt's avatar
yilmazt committed
108
void nr_fill_dci_and_dlsch(PHY_VARS_gNB *gNB,
Guy De Souza's avatar
Guy De Souza committed
109 110 111 112 113
                           int frame,
                           int subframe,
                           gNB_rxtx_proc_t *proc,
                           NR_gNB_DCI_ALLOC_t *dci_alloc,
                           nfapi_nr_dl_config_request_pdu_t *pdu)
yilmazt's avatar
yilmazt committed
114 115
{
	NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
Guy De Souza's avatar
Guy De Souza committed
116
  uint8_t n_shift;
Guy De Souza's avatar
Guy De Souza committed
117
	uint32_t *dci_pdu = dci_alloc->dci_pdu;
Guy De Souza's avatar
Guy De Souza committed
118
  memset((void*)dci_pdu,0,4*sizeof(uint32_t));
Guy De Souza's avatar
Guy De Souza committed
119 120
	nfapi_nr_dl_config_dci_dl_pdu_rel15_t *pdu_rel15 = &pdu->dci_dl_pdu.dci_dl_pdu_rel15;
  nfapi_nr_dl_config_pdcch_parameters_rel15_t *params_rel15 = &pdu->dci_dl_pdu.pdcch_params_rel15;
yilmazt's avatar
yilmazt committed
121 122
	nfapi_nr_config_request_t *cfg = &gNB->gNB_config;

Guy De Souza's avatar
Guy De Souza committed
123
  uint16_t N_RB = fp->initial_bwp_dl.N_RB;
Guy De Souza's avatar
Guy De Souza committed
124
  uint8_t fsize=0, pos=0, cand_idx=0;
yilmazt's avatar
yilmazt committed
125

Guy De Souza's avatar
Guy De Souza committed
126 127 128 129 130 131
  /// Payload generation
  switch(params_rel15->dci_format) {

    case NFAPI_NR_DL_DCI_FORMAT_1_0:
      switch(params_rel15->rnti_type) {
        case NFAPI_NR_RNTI_RA:
yilmazt's avatar
yilmazt committed
132
#ifdef DEBUG_NFAPI_NR_RNTI_RA
yilmazt's avatar
yilmazt committed
133 134 135 136 137 138 139 140 141
printf("frequency_domain_assignment = %05d = %#08x\n"
		"   time_domain_assignment = %05d = %#08x\n"
		"       vrb_to_prb_mapping = %05d = %#08x\n"
		"                      MCS = %05d = %#08x\n"
		"               tb_scaling = %05d = %#08x\n",
		pdu_rel15->frequency_domain_assignment,pdu_rel15->frequency_domain_assignment,
		pdu_rel15->time_domain_assignment,pdu_rel15->time_domain_assignment,
		pdu_rel15->vrb_to_prb_mapping,pdu_rel15->vrb_to_prb_mapping,
		pdu_rel15->mcs,pdu_rel15->mcs,pdu_rel15->tb_scaling,pdu_rel15->tb_scaling);
yilmazt's avatar
yilmazt committed
142
#endif
Guy De Souza's avatar
Guy De Souza committed
143 144 145
          // Freq domain assignment
          fsize = (int)ceil( log2( (N_RB*(N_RB+1))>>1 ) );
          for (int i=0; i<fsize; i++)
Guy De Souza's avatar
Guy De Souza committed
146
            *dci_pdu |= ((pdu_rel15->frequency_domain_assignment>>(fsize-i-1))&1)<<pos++;
Guy De Souza's avatar
Guy De Souza committed
147 148
          // Time domain assignment
          for (int i=0; i<4; i++)
Guy De Souza's avatar
Guy De Souza committed
149
            *dci_pdu |= ((pdu_rel15->time_domain_assignment>>(3-i))&1)<<pos++;
Guy De Souza's avatar
Guy De Souza committed
150
          // VRB to PRB mapping
Guy De Souza's avatar
Guy De Souza committed
151
          *dci_pdu |= (pdu_rel15->vrb_to_prb_mapping&1)<<pos++;
Guy De Souza's avatar
Guy De Souza committed
152
          // MCS
Guy De Souza's avatar
Guy De Souza committed
153
          for (int i=0; i<5; i++)
Guy De Souza's avatar
Guy De Souza committed
154
            *dci_pdu |= ((pdu_rel15->mcs>>(4-i))&1)<<pos++;
Guy De Souza's avatar
Guy De Souza committed
155 156
          // TB scaling
          for (int i=0; i<2; i++)
Guy De Souza's avatar
Guy De Souza committed
157
            *dci_pdu |= ((pdu_rel15->tb_scaling>>(1-i))&1)<<pos++;
Guy De Souza's avatar
Guy De Souza committed
158 159 160 161 162 163 164 165 166 167
          
          break;

      }
      break;

    case NFAPI_NR_UL_DCI_FORMAT_0_0:
      break;
  }

Guy De Souza's avatar
Guy De Souza committed
168
  LOG_I(PHY, "DCI PDU: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n",
Guy De Souza's avatar
Guy De Souza committed
169 170
              dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]);

Guy De Souza's avatar
Guy De Souza committed
171
  /// rest of DCI alloc
Guy De Souza's avatar
Guy De Souza committed
172
  dci_alloc->L = 4;
Guy De Souza's avatar
Guy De Souza committed
173
  memcpy((void*)&dci_alloc->pdcch_params, (void*)params_rel15, sizeof(nfapi_nr_dl_config_pdcch_parameters_rel15_t));
Guy De Souza's avatar
Guy De Souza committed
174 175
  dci_alloc->size = nr_get_dci_size(dci_alloc->pdcch_params.dci_format,
                        dci_alloc->pdcch_params.rnti_type,
Guy De Souza's avatar
Guy De Souza committed
176 177
                        &fp->initial_bwp_dl,
                        cfg);
Guy De Souza's avatar
Guy De Souza committed
178 179 180
  n_shift = (dci_alloc->pdcch_params.config_type == NFAPI_NR_CSET_CONFIG_MIB_SIB1)?
                      cfg->sch_config.physical_cell_id.value : dci_alloc->pdcch_params.shift_index;
  nr_fill_cce_list(dci_alloc, n_shift, cand_idx);
Guy De Souza's avatar
Guy De Souza committed
181
  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);
Guy De Souza's avatar
Guy De Souza committed
182 183 184 185
  
  

/*	if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_1_0) {
186 187
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_1_0;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
		if (rel15->rnti_type == NFAPI_NR_RNTI_C
		 || rel15->rnti_type == NFAPI_NR_RNTI_CS
		 || rel15->rnti_type == NFAPI_NR_RNTI_new) {

		} else if (rel15->rnti_type == NFAPI_NR_RNTI_P) {

		} else if (rel15->rnti_type == NFAPI_NR_RNTI_SI) {

		} else if (rel15->rnti_type == NFAPI_NR_RNTI_RA) {

		} else if (rel15->rnti_type == NFAPI_NR_RNTI_TC) {

		} else {
			AssertFatal(1==0, "[nr_fill_dci_and_dlsch] Incorrect DCI Format(%d) and RNTI Type(%d) combination",rel15->dci_format, rel15->rnti_type);
		}
	} else if (rel15->dci_format == NFAPI_NR_UL_DCI_FORMAT_0_0) {
204 205
		dci_alloc->format = NFAPI_NR_UL_DCI_FORMAT_0_0;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_ul ,cfg);
yilmazt's avatar
yilmazt committed
206
	} else if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_1_1) {
207 208
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_1_1;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
209
	} else if (rel15->dci_format == NFAPI_NR_UL_DCI_FORMAT_0_1) {
210 211
		dci_alloc->format = NFAPI_NR_UL_DCI_FORMAT_0_1;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_ul ,cfg);
yilmazt's avatar
yilmazt committed
212
	} else if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_2_0) {
213 214
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_2_0;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
215
	} else if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_2_1) {
216 217
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_2_1;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
218
	} else if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_2_2) {
219 220
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_2_2;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
221
	} else if (rel15->dci_format == NFAPI_NR_DL_DCI_FORMAT_2_3) {
222 223
		dci_alloc->format = NFAPI_NR_DL_DCI_FORMAT_2_3;
		dci_alloc->size = nr_get_dci_size(rel15->dci_format, rel15->rnti_type, &fp->initial_bwp_params_dl ,cfg);
yilmazt's avatar
yilmazt committed
224 225
	} else {
		AssertFatal(1==0, "[nr_fill_dci_and_dlsch] Incorrect DCI Format(%d)",rel15->dci_format);
Guy De Souza's avatar
Guy De Souza committed
226
	}*/
yilmazt's avatar
yilmazt committed
227 228 229

	return;
}