dci_tools_NB_IoT.c 20.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 34
#include "PHY/impl_defs_lte_NB_IoT.h"
#include "openair1/PHY/extern_NB_IoT.h"
35 36 37
//#include "PHY/LTE_TRANSPORT/extern_NB_IoT.h"
//#include "SCHED/defs_NB_IoT.h"
/*
Nick Ho's avatar
Nick Ho committed
38
#ifdef DEBUG_DCI_TOOLS
39
#include "PHY/vars_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
40
#endif
41 42
*/
//#include "assertions.h"
43
//#include "dlsch_tbs_full.h"
44
#include "PHY/LTE_TRANSPORT/dlsch_tbs_full_NB_IoT.h"
Nick Ho's avatar
Nick Ho committed
45 46 47

//#define DEBUG_HARQ

48 49
//#include "LAYER2/MAC/extern_NB_IoT.h"
//#include "LAYER2/MAC/defs_NB_IoT.h"
50
#include "PHY/defs_NB_IoT.h"
51

Nick Ho's avatar
Nick Ho committed
52 53
//#define DEBUG_DCI

54
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)
55
{
56
	//put the pdu
57
  memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_dci].dci_pdu[0],pdu,dci_size_bytes);
58
  //configure the dci alloc
59 60 61 62 63
  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;
  DCI_pdu->npdcch_start_symbol                         = npdcch_start_symbol;
Nick Ho's avatar
Nick Ho committed
64

65
  DCI_pdu->Num_dci++;
Nick Ho's avatar
Nick Ho committed
66

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


71
int generate_eNB_ulsch_params_from_dci_NB_IoT(PHY_VARS_eNB        *eNB,
Matthieu Kanj's avatar
Matthieu Kanj committed
72
                                              eNB_rxtx_proc_t            *proc,
73 74 75 76 77 78
                                              DCI_CONTENT                *DCI_Content,
                                              uint16_t                   rnti,
                                              DCI_format_NB_IoT_t        dci_format,
                                              uint8_t                    UE_id,
                                              uint8_t                    aggregation,
									                            uint8_t                    npdcch_start_symbol)
Nick Ho's avatar
Nick Ho committed
79 80
{

81
  void *ULSCH_DCI_NB_IoT = NULL;
82

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

  /// 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) 
    {
      
107 108 109 110 111 112 113 114 115 116 117
      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*/
118 119 120 121 122 123 124 125 126
      ((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;
127 128


129
      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
130 131

      // use this value to configure PHY both harq_processes and resource mapping.
132 133


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

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

147 148 149 150 151 152 153 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 195 196 197 198 199 200 201 202
int Scheddly_less_128[8] = {0,4,8,12,16,32,64,128};
int Scheddly_bigger_128[8] = {0,16,32,64,128,256,512,1024};
int Irep_to_Nrep[16] = {1,2,4,8,16,32,64,128,192,256,384,512,768,1024,1536,2048};


int Idelay_to_K0(uint8_t Sched_delay, int Rmax)
{
  int k0=0;

  if(Rmax <128)
  {
    k0 = Scheddly_less_128[Sched_delay];
  }else if(Rmax >=128)
  {
    k0 = Scheddly_bigger_128[Sched_delay];
  } 
  return k0;
}


int DCIrep_to_real_rep(uint8_t DCI_rep, int Rmax)
{
    int R=0;
    if(Rmax == 1)
    {
      if(DCI_rep == 0)
        R = 1;
    }else if (Rmax == 2)
    {
      if(DCI_rep == 0)
        R = 1;
      else if(DCI_rep == 1)
        R = 2;
    }else if (Rmax == 4)
    {
      if(DCI_rep == 0)
        R = 1;
      else if(DCI_rep == 1)
        R = 2;
        else if(DCI_rep == 2)
        R = 4;
    }else if (Rmax >= 8)
    {
      if(DCI_rep == 0)
        R = Rmax/8;
      else if(DCI_rep == 1)
        R = Rmax/4;
      else if(DCI_rep == 2)
        R = Rmax/2;
      else if(DCI_rep == 3)
        R = Rmax;
    }

    return R;
}

203
int generate_eNB_dlsch_params_from_dci_NB_IoT(PHY_VARS_eNB      *eNB,
204 205 206 207 208
                                              int                      frame,
                                              uint8_t                  subframe,
                                              DCI_CONTENT              *DCI_Content,
                                              uint16_t                 rnti,
                                              DCI_format_NB_IoT_t      dci_format,
Matthieu Kanj's avatar
Matthieu Kanj committed
209
                                              NB_IoT_eNB_NPDCCH_t      *ndlcch,
210
                                              LTE_DL_FRAME_PARMS    *frame_parms,
Matthieu Kanj's avatar
Matthieu Kanj committed
211
                                              uint8_t                  aggregation,         //////????? maybe add the ncce index ??????????
212 213
									                            uint8_t                  npdcch_start_symbol,
                                              uint8_t                  ncce_index)
Nick Ho's avatar
Nick Ho committed
214 215
{

Matthieu Kanj's avatar
Matthieu Kanj committed
216
 // NB_IoT_eNB_NPDCCH_t  *ndlcch     = ;
217
  void                  *DLSCH_DCI_NB_IoT = NULL;
Nick Ho's avatar
Nick Ho committed
218
  int tmp = 0;
Nick Ho's avatar
Nick Ho committed
219
  uint8_t  *DCI_tmp = NULL;
Nick Ho's avatar
Nick Ho committed
220
  uint8_t  *DCI_flip = NULL;
Nick Ho's avatar
Nick Ho committed
221

222
  //eNB->DCI_pdu = (DCI_PDU_NB_IoT*) malloc(sizeof(DCI_PDU_NB_IoT));
Nick Ho's avatar
Nick Ho committed
223

224
  //N1 parameters
225
  //uint8_t ncce_index = 0;
Nick Ho's avatar
Nick Ho committed
226

227
  /// type = 0 => DCI Format N0, type = 1 => DCI Format N1, 1 bits
228
  uint8_t type = 0;
229
  //NPDCCH order indicator (set to 0),1 bits
230
  uint8_t orderIndicator = 0;
231
  // Scheduling Delay, 3 bits
232
  uint8_t Sched_delay = 0;
233
  // Resourse Assignment (RU Assignment), 3 bits
234
  uint8_t ResAssign = 0;//Isf
235
  // Modulation and Coding Scheme, 4 bits
236
  uint8_t mcs = 0;
237
  // Repetition Number, 4 bits
238
  uint8_t RepNum = 0;
239
  // DCI subframe repetition Number, 2 bits
240
  uint8_t DCIRep = 0;
241
  // New Data Indicator,1 bits
242
  uint8_t ndi = 0;
243
  // HARQ-ACK resource,4 bits
244
  uint8_t HARQackRes = 0;
Nick Ho's avatar
Nick Ho committed
245

246
  //N2 parameters
Nick Ho's avatar
Nick Ho committed
247

248
  //Direct indication information, 8 bits
249
  uint8_t directIndInf= 0;
250
  // Reserved information bits, 6 bits
251
  uint8_t resInfoBits =0;
Nick Ho's avatar
Nick Ho committed
252

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

255
  switch (dci_format) {
Nick Ho's avatar
Nick Ho committed
256

257
  // Impossible to have a DCI N0, we have condition before
258 259
  case DCIFormatN0:
    return(-1);
Nick Ho's avatar
Nick Ho committed
260 261
    break;

262
  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
263 264


265
	/*Packed DCI here-------------------------------------------*/
266 267
    type               = DCI_Content->DCIN1_RAR.type;
    orderIndicator     = DCI_Content->DCIN1_RAR.orderIndicator; 
268
    Sched_delay        = DCI_Content->DCIN1_RAR.Scheddly;
269 270 271
    ResAssign          = DCI_Content->DCIN1_RAR.ResAssign; 
    mcs                = DCI_Content->DCIN1_RAR.mcs; 
    RepNum             = DCI_Content->DCIN1_RAR.RepNum; 
272 273
    ndi                = DCI_Content->DCIN1_RAR.ndi;
    HARQackRes         = DCI_Content->DCIN1_RAR.HARQackRes; 
274 275
    DCIRep             = DCI_Content->DCIN1_RAR.DCIRep;
    
276 277
    DLSCH_DCI_NB_IoT = (DCIN1_RAR_t *)malloc(sizeof(DCIN1_RAR_t));

278
    //DCI pdu content
279 280 281 282 283 284 285 286 287
    ((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
288

Nick Ho's avatar
Nick Ho committed
289
    //printf("DUMP: DCI N1 RAR : type = %d, orderIndicator = %d, Sched_delay = %d, ResAssign = %d, mcs = %d, RepNum = %d, ndi = %d, HARQackRes = %d, DCIRep = %d\n", type, orderIndicator, Sched_delay, ResAssign, mcs, RepNum, ndi, HARQackRes, DCIRep);
290
    //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);
291 292


293
    /*Now configure the npdcch structure*/
294

Matthieu Kanj's avatar
Matthieu Kanj committed
295 296 297
   // ndlcch->ncce_index          =   NCCE_index;
   // ndlcch->aggregation_level   =   aggregation;

Nick Ho's avatar
Nick Ho committed
298
    ndlcch->A[ncce_index]               = sizeof_DCIN1_RAR_t; // number of bits in DCI
Matthieu Kanj's avatar
Matthieu Kanj committed
299 300 301

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

304
    // use this value to configure PHY both harq_processes and resource mapping.
305
    ndlcch->scheduling_delay[ncce_index]         = Idelay_to_K0(Sched_delay,4);
Matthieu Kanj's avatar
Matthieu Kanj committed
306
    ndlcch->resource_assignment[ncce_index]      = resource_to_subframe[ResAssign];  //from Isf of DCI to the number of subframe
307
    ndlcch->repetition_number[ncce_index]        = Irep_to_Nrep[RepNum];                             // repetition number for NPDSCH
308
    ndlcch->dci_repetitions[ncce_index]          = DCIrep_to_real_rep(DCIRep,4);        ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
309

Nick Ho's avatar
Nick Ho committed
310
    //printf("dci_repetitions: %d, A = %d\n",ndlcch->dci_repetitions[ncce_index],ndlcch->A[ncce_index]);
311

Matthieu Kanj's avatar
Matthieu Kanj committed
312 313
    ndlcch->modulation[ncce_index]               = 2; //QPSK
    //// ////////////////////////////////////////////////if(ndlcch->round == 0) //this should be set from initialization (init-lte)
314

Matthieu Kanj's avatar
Matthieu Kanj committed
315 316
    //ndlcch->status[ncce_index] = ACTIVE_NB_IoT;
    ndlcch->mcs[ncce_index]    = mcs;
Nick Ho's avatar
Nick Ho committed
317 318

    //ndlcch->pdu[ncce_index]    = DLSCH_DCI_NB_IoT;
Nick Ho's avatar
Nick Ho committed
319
    DCI_tmp = (uint8_t*)DLSCH_DCI_NB_IoT;
Nick Ho's avatar
Nick Ho committed
320 321 322 323 324 325 326 327

    DCI_flip = (uint8_t*)malloc(3*sizeof(uint8_t));

    DCI_flip[0]        = DCI_tmp[2]*2;
    DCI_flip[1]        = DCI_tmp[1]*2;
    DCI_flip[2]        = DCI_tmp[0]*2;
    
    ndlcch->pdu[ncce_index]    = DCI_flip;
Nick Ho's avatar
Nick Ho committed
328

Nick Ho's avatar
Nick Ho committed
329
    printf("DCI N1 RAR PDU content:");
Nick Ho's avatar
Nick Ho committed
330
    for (tmp =0;tmp<3;tmp++)
Nick Ho's avatar
Nick Ho committed
331
      printf("%d ",DCI_flip[tmp]);
Nick Ho's avatar
Nick Ho committed
332
    printf("\n");
333 334 335 336 337 338
    /*
     * TS 36.213 ch 16.4.1.5
     * ITBS is always set equivalent to IMCS for data
     * ISF = ResAssign
     */

Matthieu Kanj's avatar
Matthieu Kanj committed
339 340
    ndlcch->TBS[ncce_index]      = TBStable_NB_IoT[mcs][ResAssign];
    //ndlcch->subframe[ncce_index] = subframe;
341
    ndlcch->counter_repetition_number[ncce_index] = DCIrep_to_real_rep(DCIRep,4);          ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
342 343 344 345 346 347 348
    //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

349
    LOG_I(PHY,"DCI packing for N1RAR done \n");
350

351 352 353 354 355 356
    //set in new_eNB_dlsch (initialization)
    /*
     * Mlimit
     * nsoft
     * round
     */
Nick Ho's avatar
Nick Ho committed
357 358


359
    break;
Nick Ho's avatar
Nick Ho committed
360

361
  case DCIFormatN1: // for user data
362
    
Nick Ho's avatar
Nick Ho committed
363

364 365
    type               = DCI_Content->DCIN1.type;
    orderIndicator     = DCI_Content->DCIN1.orderIndicator; 
366
    Sched_delay        = DCI_Content->DCIN1.Scheddly;
367 368 369 370 371 372
    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;
373 374

    DLSCH_DCI_NB_IoT = (DCIN1_t *)malloc(sizeof(DCIN1_t));
375
    /*Packed DCI here*/
376 377 378 379 380 381 382 383 384
    ((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
385 386


387
    //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
388

389
    /*Now configure the npdcch structure*/
Nick Ho's avatar
Nick Ho committed
390
    ndlcch->A[ncce_index]               = sizeof_DCIN1_t; // number of bits in DCI
391

Matthieu Kanj's avatar
Matthieu Kanj committed
392 393
    // ndlcch->ncce_index          =   NCCE_index;
    // ndlcch->aggregation_level   =   aggregation;
394

Matthieu Kanj's avatar
Matthieu Kanj committed
395 396
    //ndlcch->subframe_tx[subframe] = 1; // check if it's OK
    ndlcch->rnti[ncce_index]                  = rnti; //we store the RNTI (e.g. for RNTI will be used later)
397
    ndlcch->active[ncce_index]                = 1;//will be activated by the corresponding NDSLCH pdu
398

Matthieu Kanj's avatar
Matthieu Kanj committed
399
    // use this value to configure PHY both harq_processes and resource mapping.
Nick Ho's avatar
Nick Ho committed
400
    ndlcch->scheduling_delay[ncce_index]         = Idelay_to_K0(Sched_delay,4);
401 402
    ndlcch->resource_assignment[ncce_index]      = resource_to_subframe[ResAssign];  //from Isf of DCI to the number of subframe
    ndlcch->repetition_number[ncce_index]        = Irep_to_Nrep[RepNum];                             // repetition number for NPDSCH
Nick Ho's avatar
Nick Ho committed
403
    ndlcch->dci_repetitions[ncce_index]          = DCIrep_to_real_rep(DCIRep,4);        ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
Matthieu Kanj's avatar
Matthieu Kanj committed
404 405 406 407 408 409
    ndlcch->modulation[ncce_index]               = 2; //QPSK
    //if(ndlcch->round == 0){ //this should be set from initialization (init-lte)

  	//ndlcch->status[ncce_index]  = ACTIVE_NB_IoT;
  	ndlcch->mcs[ncce_index]     = mcs;
  	ndlcch->TBS[ncce_index]     = TBStable_NB_IoT[mcs][ResAssign]; // this table should be rewritten for nb-iot
Nick Ho's avatar
Nick Ho committed
410 411 412 413
    //ndlcch->pdu[ncce_index]    = DLSCH_DCI_NB_IoT;
    DCI_tmp = (uint8_t*)DLSCH_DCI_NB_IoT;

    DCI_flip = (uint8_t*)malloc(3*sizeof(uint8_t));
414
    DCI_flip[0]        = 129;
Nick Ho's avatar
Nick Ho committed
415

416
    //DCI_flip[0]        = DCI_tmp[2]*2;
Nick Ho's avatar
Nick Ho committed
417
    DCI_flip[1]        = DCI_tmp[1]*2;
Nick Ho's avatar
Nick Ho committed
418 419
    DCI_flip[2]        = DCI_tmp[0]*2;
    //DCI_flip[2]        = 4;
Nick Ho's avatar
Nick Ho committed
420
    ndlcch->pdu[ncce_index]    = DCI_flip;
Matthieu Kanj's avatar
Matthieu Kanj committed
421

Nick Ho's avatar
Nick Ho committed
422 423 424 425
    printf("DCI N1 PDU content:");
    for (tmp =0;tmp<3;tmp++)
      printf("%d ",DCI_flip[tmp]);
    printf("\n");
Matthieu Kanj's avatar
Matthieu Kanj committed
426

Nick Ho's avatar
Nick Ho committed
427
    ndlcch->counter_repetition_number[ncce_index] = DCIrep_to_real_rep(DCIRep,4);          ////??????? should be repalce by the value in spec table 16.6-3, check also Rmax
Matthieu Kanj's avatar
Matthieu Kanj committed
428 429 430
    //}
    //ndlcch->frame[ncce_index]    = frame;
    //ndlcch->subframe[ncce_index] = subframe;
431 432 433 434

    break;

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

436 437 438
    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
439

440
    DLSCH_DCI_NB_IoT = (DCIN2_Ind_t *)malloc(sizeof(DCIN2_Ind_t));
441
    /*Packed DCI here*/
442 443 444
    ((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
445 446


447
    //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
448

449
    // use this value to configure PHY both harq_processes and resource mapping.
450
    break;
Nick Ho's avatar
Nick Ho committed
451

452
    
453
  case DCIFormatN2_Pag:  //MP: for the moment is not implemented
Nick Ho's avatar
Nick Ho committed
454

455 456 457 458 459
    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
460

461
    DLSCH_DCI_NB_IoT = (DCIN2_Pag_t *)malloc(sizeof(DCIN2_Pag_t));
462
    /*Packed DCI here*/
463 464 465 466 467
    ((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
468 469


470
    //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
471

472
    // use this value to configure PHY both harq_processes and resource mapping.
473
    break;
Nick Ho's avatar
Nick Ho committed
474 475 476 477 478 479 480 481 482 483


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

  // compute DL power control parameters

484
  //free(DLSCH_DCI_NB_IoT);
Nick Ho's avatar
Nick Ho committed
485 486

  return(0);
487
}
488 489


Matthieu Kanj's avatar
Matthieu Kanj committed
490
uint8_t subframe2harq_pid_NB_IoT(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t subframe)
491
{
492
  //MAC_xface_NB_IoT *mac_xface_NB_IoT; //test_xface
493 494 495 496 497 498 499 500 501 502 503
  /*
    #ifdef DEBUG_DCI
    if (frame_parms->frame_type == TDD)
    printf("dci_tools.c: subframe2_harq_pid, subframe %d for TDD configuration %d\n",subframe,frame_parms->tdd_config);
    else
    printf("dci_tools.c: subframe2_harq_pid, subframe %d for FDD \n",subframe);
    #endif
  */

  uint8_t ret = 255;

Matthieu Kanj's avatar
Matthieu Kanj committed
504
  if (frame_parms->frame_type == FDD) {
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
    ret = (((frame<<1)+subframe)&7);
  } else {

    switch (frame_parms->tdd_config) {

    case 1:
      if ((subframe==2) ||
          (subframe==3) ||
          (subframe==7) ||
          (subframe==8))
        switch (subframe) {
        case 2:
        case 3:
          ret = (subframe-2);
          break;

        case 7:
        case 8:
          ret = (subframe-5);
          break;

        default:
          LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
          ret = (255);
          break;
        }

      break;

    case 2:
      if ((subframe!=2) && (subframe!=7)) {
        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
537
        //mac_xface_NB_IoT->macphy_exit("subframe2_harq_pid_NB_IoT, Illegal subframe");
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
        ret = (255);
      }

      ret = (subframe/7);
      break;

    case 3:
      if ((subframe<2) || (subframe>4)) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    case 4:
      if ((subframe<2) || (subframe>3)) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    case 5:
      if (subframe!=2) {
        LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
        ret = (255);
      }

      ret = (subframe-2);
      break;

    default:
      LOG_E(PHY,"subframe2_harq_pid_NB_IoT, Unsupported TDD mode %d\n",frame_parms->tdd_config);
      ret = (255);

    }
  }

  if (ret == 255) {
    LOG_E(PHY, "invalid harq_pid(%d) at SFN/SF = %d/%d\n", ret, frame, subframe);
580
    //mac_xface_NB_IoT->macphy_exit("invalid harq_pid");
581 582 583 584
  }
  return ret;
}