dci_tools_nb_iot.c 13.6 KB
Newer Older
Nick Ho's avatar
Nick Ho 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
/*
 * 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 PHY/LTE_TRANSPORT/dci_tools.c
 * \brief PHY Support routines (eNB/UE) for filling PDSCH/PUSCH/DLSCH/ULSCH data structures based on DCI PDUs generated by eNB MAC scheduler.
 * \author R. Knopp
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */
32
//#include "PHY/defs.h"
33
#include "PHY/extern_NB_IoT.h"
34
#include "PHY/LTE_TRANSPORT/extern_NB_IoT.h"
35
#include "SCHED/defs_nb_iot.h"
Nick Ho's avatar
Nick Ho committed
36
#ifdef DEBUG_DCI_TOOLS
37
#include "PHY/vars_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
38 39
#endif
#include "assertions.h"
40
//#include "dlsch_tbs_full.h"
41
#include "PHY/LTE_TRANSPORT/dlsch_tbs_full_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
42 43 44

//#define DEBUG_HARQ

45 46
#include "LAYER2/MAC/extern_NB_IoT.h"
#include "LAYER2/MAC/defs_nb_iot.h"
47 48
#include "PHY/defs_nb_iot.h"

Nick Ho's avatar
Nick Ho committed
49 50
//#define DEBUG_DCI

51
void add_dci_NB_IoT(DCI_PDU_NB_IoT *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt, uint8_t npdcch_start_symbol)
52
{
53
	//put the pdu
54
  memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_dci].dci_pdu[0],pdu,dci_size_bytes);
55
  //configure the dci alloc
56 57 58 59
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].dci_length = dci_size_bits;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].L          = aggregation;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].rnti       = rnti;
  DCI_pdu->dci_alloc[DCI_pdu->Num_dci].format     = dci_fmt;
60
  DCI_pdu->npdcch_start_symbol = npdcch_start_symbol;
Nick Ho's avatar
Nick Ho committed
61

62
  DCI_pdu->Num_dci++;
Nick Ho's avatar
Nick Ho committed
63

64 65
  LOG_D(MAC,"add ue specific dci format %d for rnti %x \n",dci_fmt,rnti);
}
Nick Ho's avatar
Nick Ho committed
66 67


68
int generate_eNB_ulsch_params_from_dci_NB_IoT(PHY_VARS_eNB_NB_IoT *eNB,
69
                                              eNB_rxtx_proc_NB_IoT_t *proc,
70 71
                                              DCI_CONTENT *DCI_Content,
                                              uint16_t rnti,
72
                                              DCI_format_NB_IoT_t dci_format,
73 74 75
                                              uint8_t UE_id,
                                              uint8_t aggregation,
									                            uint8_t npdcch_start_symbol)
Nick Ho's avatar
Nick Ho committed
76 77
{

78
  void *ULSCH_DCI_NB_IoT = NULL;
79

80
  eNB->DCI_pdu = (DCI_PDU_NB_IoT*) malloc(sizeof(DCI_PDU_NB_IoT));
Nick Ho's avatar
Nick Ho committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

  /// type = 0 => DCI Format N0, type = 1 => DCI Format N1, 1 bits
  uint8_t type;
  /// Subcarrier indication, 6 bits
  uint8_t scind;
  /// Resourse Assignment (RU Assignment), 3 bits
  uint8_t ResAssign;
  /// Modulation and Coding Scheme, 4 bits
  uint8_t mcs;
  /// New Data Indicator, 1 bits
  uint8_t ndi;
  /// Scheduling Delay, 2 bits
  uint8_t Scheddly;
  /// Repetition Number, 3 bits
  uint8_t RepNum;
  /// Redundancy version for HARQ (only use 0 and 2), 1 bits
  uint8_t rv;
  /// DCI subframe repetition Number, 2 bits
  uint8_t DCIRep;
  
  if (dci_format == DCIFormatN0) 
    {
      
104 105 106 107 108 109 110 111 112 113 114
      type        = DCI_Content->DCIN0.type;
      scind       = DCI_Content->DCIN0.scind;
      ResAssign   = DCI_Content->DCIN0.ResAssign;
      mcs         = DCI_Content->DCIN0.mcs;
      ndi         = DCI_Content->DCIN0.ndi;
      Scheddly    = DCI_Content->DCIN0.Scheddly;
      RepNum      = DCI_Content->DCIN0.RepNum;
      rv          = DCI_Content->DCIN0.rv;
      DCIRep      = DCI_Content->DCIN0.DCIRep;

      /*Packed DCI here*/
115 116 117 118 119 120 121 122 123
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->type      =type;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->scind     =scind;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->ResAssign =ResAssign;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->Scheddly  =Scheddly;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->mcs       =mcs;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->rv        =rv;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->RepNum    =RepNum;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->ndi       =ndi;
      ((DCIN0_t *)ULSCH_DCI_NB_IoT)->DCIRep    =DCIRep;
124 125


126
      add_dci_NB_IoT(eNB->DCI_pdu,ULSCH_DCI_NB_IoT,rnti,sizeof(DCIN0_t),aggregation,sizeof_DCIN0_t,DCIFormatN0, npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
127 128

      // use this value to configure PHY both harq_processes and resource mapping.
129 130


Nick Ho's avatar
Nick Ho committed
131 132 133
      
      return(0);
    } 
134 135
  else 
    {
Nick Ho's avatar
Nick Ho committed
136 137
        LOG_E(PHY,"generate_eNB_ulsch_params_from_dci, Illegal dci_format %d\n",dci_format);
        return(-1);
138
    }
Nick Ho's avatar
Nick Ho committed
139 140
}

141
//map the Isf (DCI param) to the number of subframes (Nsf)
142 143
int resource_to_subframe[8] = {1,2,3,4,5,6,8,10}; 

144
int generate_eNB_dlsch_params_from_dci_NB_IoT(PHY_VARS_eNB_NB_IoT *eNB,
145 146 147 148
                                              int frame,
                                              uint8_t subframe,
                                              DCI_CONTENT *DCI_Content,
                                              uint16_t rnti,
149
                                              DCI_format_NB_IoT_t dci_format,
150
                                              NB_IoT_eNB_NDLSCH_t *ndlsch,
151
                                              NB_IoT_DL_FRAME_PARMS *frame_parms,
152 153
                                              uint8_t aggregation,
									                            uint8_t npdcch_start_symbol)
Nick Ho's avatar
Nick Ho committed
154 155
{

156
  NB_IoT_DL_eNB_HARQ_t* ndlsch_harq = ndlsch->harq_process;
157 158
  void *DLSCH_DCI_NB_IoT = NULL;
  eNB->DCI_pdu = (DCI_PDU_NB_IoT*) malloc(sizeof(DCI_PDU_NB_IoT));
Nick Ho's avatar
Nick Ho committed
159 160


161

162
  //N1 parameters
Nick Ho's avatar
Nick Ho committed
163

164
  /// type = 0 => DCI Format N0, type = 1 => DCI Format N1, 1 bits
165
  uint8_t type = 0;
166
  //NPDCCH order indicator (set to 0),1 bits
167
  uint8_t orderIndicator = 0;
168
  // Scheduling Delay, 3 bits
169
  uint8_t Sched_delay = 0;
170
  // Resourse Assignment (RU Assignment), 3 bits
171
  uint8_t ResAssign = 0;//Isf
172
  // Modulation and Coding Scheme, 4 bits
173
  uint8_t mcs = 0;
174
  // Repetition Number, 4 bits
175
  uint8_t RepNum = 0;
176
  // DCI subframe repetition Number, 2 bits
177
  uint8_t DCIRep = 0;
178
  // New Data Indicator,1 bits
179
  uint8_t ndi = 0;
180
  // HARQ-ACK resource,4 bits
181
  uint8_t HARQackRes = 0;
Nick Ho's avatar
Nick Ho committed
182

183
  //N2 parameters
Nick Ho's avatar
Nick Ho committed
184

185
  //Direct indication information, 8 bits
186
  uint8_t directIndInf= 0;
187
  // Reserved information bits, 6 bits
188
  uint8_t resInfoBits =0;
Nick Ho's avatar
Nick Ho committed
189

190
  //   printf("Generate eNB DCI, format %d, rnti %x (pdu %p)\n",dci_format,rnti,dci_pdu);
Nick Ho's avatar
Nick Ho committed
191

192
  switch (dci_format) {
Nick Ho's avatar
Nick Ho committed
193

194
  // Impossible to have a DCI N0, we have condition before
195 196
  case DCIFormatN0:
    return(-1);
Nick Ho's avatar
Nick Ho committed
197 198
    break;

199
  case DCIFormatN1_RAR:  // This is DLSCH allocation for control traffic (no NDI and no ACK/NACK resource for RAR DCI)
Nick Ho's avatar
Nick Ho committed
200 201


202
	/*Packed DCI here-------------------------------------------*/
203 204
    type               = DCI_Content->DCIN1_RAR.type;
    orderIndicator     = DCI_Content->DCIN1_RAR.orderIndicator; 
205
    Sched_delay        = DCI_Content->DCIN1_RAR.Scheddly;
206 207 208
    ResAssign          = DCI_Content->DCIN1_RAR.ResAssign; 
    mcs                = DCI_Content->DCIN1_RAR.mcs; 
    RepNum             = DCI_Content->DCIN1_RAR.RepNum; 
209 210
    ndi                = DCI_Content->DCIN1_RAR.ndi;
    HARQackRes         = DCI_Content->DCIN1_RAR.HARQackRes; 
211 212
    DCIRep             = DCI_Content->DCIN1_RAR.DCIRep;
    
213
    //DCI pdu content
214 215 216 217 218 219 220 221 222
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->type           =type;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->orderIndicator =orderIndicator;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->Scheddly       =Sched_delay;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->ResAssign      =ResAssign;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->mcs            =mcs;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->RepNum         =RepNum;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->ndi            =ndi;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->HARQackRes     =HARQackRes;
    ((DCIN1_RAR_t *)DLSCH_DCI_NB_IoT)->DCIRep         =DCIRep;
Nick Ho's avatar
Nick Ho committed
223 224


225
    add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN1_RAR_t),aggregation,sizeof_DCIN1_RAR_t,DCIFormatN1_RAR, npdcch_start_symbol);
226 227 228 229 230


    /*Now configure the ndlsch structure*/

    ndlsch->subframe_tx[subframe] = 1; // check if it's OK
231 232
    ndlsch->rnti = rnti; //we store the RNTI (e.g. for RNTI will be used later)
    ndlsch->active = 0; //will be activated by the corresponding NDSLCH pdu
Nick Ho's avatar
Nick Ho committed
233

234
    // use this value to configure PHY both harq_processes and resource mapping.
235 236 237 238 239 240 241
    ndlsch_harq->scheduling_delay = Sched_delay;
    ndlsch_harq->resource_assignment = resource_to_subframe[ResAssign];  //from Isf of DCI to the number of subframe
    ndlsch_harq->repetition_number = RepNum;
    ndlsch_harq->dci_subframe_repetitions = DCIRep;
    ndlsch_harq->modulation = 2; //QPSK
    if(ndlsch_harq->round == 0) //this should be set from initialization (init-lte)
    	ndlsch_harq->status = ACTIVE;
242
    
243
    ndlsch_harq->mcs = mcs;
244 245 246 247 248 249 250

    /*
     * TS 36.213 ch 16.4.1.5
     * ITBS is always set equivalent to IMCS for data
     * ISF = ResAssign
     */

251
    ndlsch_harq->TBS = TBStable_NB_IoT[mcs][ResAssign];
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    ndlsch_harq->subframe = subframe;

    //ndlsch_harq->B; we don-t have now my is given when we receive the dlsch data
    //ndlsch->error_treshold
    //ndlsch->G??
    //ndlsc->nsoft?? //set in new_eNB_dlsch (initialization)
    //ndlsch-> sqrt_rho_a?? set in dlsch_modulation
    //ndlsch-> sqrt_rho_b??? set in dlsch_modulation

    //set in new_eNB_dlsch (initialization)
    /*
     * Mlimit
     * nsoft
     * round
     */
Nick Ho's avatar
Nick Ho committed
267 268


269
    break;
Nick Ho's avatar
Nick Ho committed
270

271
  case DCIFormatN1: // for user data
272
    
Nick Ho's avatar
Nick Ho committed
273

274 275
    type               = DCI_Content->DCIN1.type;
    orderIndicator     = DCI_Content->DCIN1.orderIndicator; 
276
    Sched_delay        = DCI_Content->DCIN1.Scheddly;
277 278 279 280 281 282 283 284
    ResAssign          = DCI_Content->DCIN1.ResAssign; 
    mcs                = DCI_Content->DCIN1.mcs; 
    RepNum             = DCI_Content->DCIN1.RepNum; 
    ndi                = DCI_Content->DCIN1.ndi;
    HARQackRes         = DCI_Content->DCIN1.HARQackRes; 
    DCIRep             = DCI_Content->DCIN1.DCIRep;
    
    /*Packed DCI here*/
285 286 287 288 289 290 291 292 293
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->type           =type;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->orderIndicator =orderIndicator;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->Scheddly       =Sched_delay;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->ResAssign      =ResAssign;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->mcs            =mcs;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->RepNum         =RepNum;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->ndi            =ndi;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->HARQackRes     =HARQackRes;
    ((DCIN1_t *)DLSCH_DCI_NB_IoT)->DCIRep         =DCIRep;
Nick Ho's avatar
Nick Ho committed
294 295


296
    add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN1_t),aggregation,sizeof_DCIN1_t,DCIFormatN1,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
297

298 299 300
    /*Now configure the ndlsch structure*/

    ndlsch->subframe_tx[subframe] = 1; // check if it's OK
301 302
    ndlsch->rnti = rnti; //we store the RNTI (e.g. for RNTI will be used later)
    ndlsch->active = 0;//will be activated by the corresponding NDSLCH pdu
Nick Ho's avatar
Nick Ho committed
303

304 305 306 307 308 309 310 311 312
    // use this value to configure PHY both harq_processes and resource mapping.
        ndlsch_harq->scheduling_delay = Sched_delay;
        ndlsch_harq->resource_assignment = resource_to_subframe[ResAssign]; //from Isf of DCI to the number of subframe
        ndlsch_harq->repetition_number = RepNum;
        ndlsch_harq->dci_subframe_repetitions = DCIRep;
        ndlsch_harq->modulation = 2; //QPSK
        if(ndlsch_harq->round == 0){ //this should be set from initialization (init-lte)
        	ndlsch_harq->status = ACTIVE;
        	ndlsch_harq->mcs = mcs;
313
        	ndlsch_harq->TBS = TBStable_NB_IoT[mcs][ResAssign]; // this table should be rewritten for nb-iot
314 315 316 317 318 319 320 321 322
        }
        ndlsch_harq->frame = frame;
        ndlsch_harq->subframe = subframe;



    break;

  case DCIFormatN2_Ind: //MP: for the moment is not implemented
Nick Ho's avatar
Nick Ho committed
323

324 325 326
    type               = DCI_Content->DCIN2_Ind.type;
    directIndInf       = DCI_Content->DCIN2_Ind.directIndInf; 
    resInfoBits        = DCI_Content->DCIN2_Ind.resInfoBits; 
Nick Ho's avatar
Nick Ho committed
327

328
    /*Packed DCI here*/
329 330 331
    ((DCIN2_Ind_t *)DLSCH_DCI_NB_IoT)->type           =type;
    ((DCIN2_Ind_t *)DLSCH_DCI_NB_IoT)->directIndInf   =directIndInf;
    ((DCIN2_Ind_t *)DLSCH_DCI_NB_IoT)->resInfoBits    =resInfoBits;
Nick Ho's avatar
Nick Ho committed
332 333


334
    add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN2_Ind_t),aggregation,sizeof_DCIN2_Ind_t,DCIFormatN2_Ind,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
335

336
    // use this value to configure PHY both harq_processes and resource mapping.
337
    break;
Nick Ho's avatar
Nick Ho committed
338

339
    
340
  case DCIFormatN2_Pag:  //MP: for the moment is not implemented
Nick Ho's avatar
Nick Ho committed
341

342 343 344 345 346
    type               = DCI_Content->DCIN2_Pag.type;
    ResAssign          = DCI_Content->DCIN2_Pag.ResAssign; 
    mcs                = DCI_Content->DCIN2_Pag.mcs; 
    RepNum             = DCI_Content->DCIN2_Pag.RepNum; 
    DCIRep             = DCI_Content->DCIN2_Pag.DCIRep; 
Nick Ho's avatar
Nick Ho committed
347

348
    /*Packed DCI here*/
349 350 351 352 353
    ((DCIN2_Pag_t *)DLSCH_DCI_NB_IoT)->type      =type;
    ((DCIN2_Pag_t *)DLSCH_DCI_NB_IoT)->ResAssign =ResAssign;
    ((DCIN2_Pag_t *)DLSCH_DCI_NB_IoT)->mcs       =mcs;
    ((DCIN2_Pag_t *)DLSCH_DCI_NB_IoT)->RepNum    =RepNum;
    ((DCIN2_Pag_t *)DLSCH_DCI_NB_IoT)->DCIRep    =DCIRep;
Nick Ho's avatar
Nick Ho committed
354 355


356
    add_dci_NB_IoT(eNB->DCI_pdu,DLSCH_DCI_NB_IoT,rnti,sizeof(DCIN2_Pag_t),aggregation,sizeof_DCIN2_Pag_t,DCIFormatN2_Pag,npdcch_start_symbol);
Nick Ho's avatar
Nick Ho committed
357

358
    // use this value to configure PHY both harq_processes and resource mapping.
359
    break;
Nick Ho's avatar
Nick Ho committed
360 361 362 363 364 365 366 367 368 369 370 371 372


  default:
    LOG_E(PHY,"Unknown DCI format\n");
    return(-1);
    break;
  }

  // compute DL power control parameters



  return(0);
373
}