phich.c 49.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*! \file PHY/LTE_TRANSPORT/phich.c
* \brief Top-level routines for generating and decoding  the PHICH/HI physical/transport channel V8.6 2009-03
* \author R. Knopp
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr
* \note
* \warning
*/

#include "PHY/defs.h"
#include "PHY/extern.h"
#include "SCHED/defs.h"
#include "defs.h"
37 38 39 40

#include "LAYER2/MAC/extern.h"
#include "LAYER2/MAC/defs.h"

41 42 43 44
#ifndef USER_MODE
#include "ARCH/CBMIMO1/DEVICE_DRIVER/extern.h"
#endif

45 46
#include "T.h"

47 48 49 50 51 52 53
//#define DEBUG_PHICH 1

//extern unsigned short pcfich_reg[4];
//extern unsigned char pcfich_first_reg_idx;

//unsigned short phich_reg[MAX_NUM_PHICH_GROUPS][3];

Raymond Knopp's avatar
 
Raymond Knopp committed
54 55

uint8_t rv_table[4] = {0, 2, 3, 1};
56

57 58
uint8_t get_mi(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe)
{
59 60

  // for FDD
Raymond Knopp's avatar
 
Raymond Knopp committed
61
  if (frame_parms->frame_type == FDD)
62 63 64 65 66
    return 1;

  // for TDD
  switch (frame_parms->tdd_config) {

67
  case 0:
68 69 70
    if ((subframe==0) || (subframe==5))
      return(2);
    else return(1);
71

72
    break;
73 74

  case 1:
75 76 77
    if ((subframe==0) || (subframe==5))
      return(0);
    else return(1);
78

79
    break;
80 81

  case 2:
82 83 84
    if ((subframe==3) || (subframe==8))
      return(1);
    else return(0);
85

86
    break;
87 88

  case 3:
89 90 91
    if ((subframe==0) || (subframe==8) || (subframe==9))
      return(1);
    else return(0);
92

93
    break;
94

95 96 97 98
  case 4:
    if ((subframe==8) || (subframe==9))
      return(1);
    else return(0);
99

100
    break;
101

102 103 104 105
  case 5:
    if (subframe==8)
      return(1);
    else return(0);
106

107
    break;
108

109
  case 6:
110 111 112
    return(1);
    break;

113 114 115 116 117
  default:
    return(0);
  }
}

118 119
unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe)
{
120

Raymond Knopp's avatar
 
Raymond Knopp committed
121
  if (frame_parms->frame_type == FDD)
122
    return(subframe&7);
123

124 125
  switch (frame_parms->tdd_config) {
  case 3:
126
    if ( (subframe == 8) || (subframe == 9) ) {
127
      return(subframe-8);
128
    } else if (subframe==0)
129 130 131
      return(2);
    else {
      LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
132
            subframe,frame_parms->tdd_config);
133 134
      return(0);
    }
135

136
    break;
137

138
  }
139

140 141 142
  return(0);
}

143 144
uint8_t phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms,frame_t frame,uint8_t subframe)
{
145
  uint8_t pusch_frame = 255;
Raymond Knopp's avatar
 
Raymond Knopp committed
146
  if (frame_parms->frame_type == FDD) {
147
    pusch_frame = ((subframe<4) ? (frame - 1) : frame);
148
  } else {
149
    // Note this is not true, but it doesn't matter, the frame number is irrelevant for TDD!
150
    pusch_frame = (frame);
151
  }
152 153 154

  LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", frame, subframe, pusch_frame);
  return pusch_frame;
155 156
}

157 158
uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe)
{
159
  uint8_t pusch_subframe = 255;
160

Raymond Knopp's avatar
 
Raymond Knopp committed
161
  if (frame_parms->frame_type == FDD)
162
    pusch_subframe = (subframe<4 ? (subframe+6) : (subframe-4));
163

164 165 166
  switch (frame_parms->tdd_config) {
  case 0:
    if (subframe == 0)
167
      pusch_subframe = (3);
168
    else if (subframe == 5) {
169
      pusch_subframe = (8);
170
    } else if (subframe == 6)
171
      pusch_subframe = (2);
172
    else if (subframe == 1)
173
      pusch_subframe = (7);
174 175
    else {
      LOG_E(PHY, "phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
176
            subframe,frame_parms->tdd_config);
177
      pusch_subframe = (0);
178
    }
179

180
    break;
181

182 183
  case 1:
    if (subframe == 6)
184
      pusch_subframe = (2);
185
    else if (subframe == 9)
186
      pusch_subframe = (3);
187
    else if (subframe == 1)
188
      pusch_subframe = (7);
189
    else if (subframe == 4)
190
      pusch_subframe = (8);
191 192
    else {
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
193
            subframe,frame_parms->tdd_config);
194
      pusch_subframe = (0);
195
    }
196

197
    break;
198

199 200
  case 2:
    if (subframe == 8)
201
      pusch_subframe = (2);
202
    else if (subframe == 3)
203
      pusch_subframe = (7);
204 205
    else {
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
206
            subframe,frame_parms->tdd_config);
207
      pusch_subframe = (0);
208
    }
209

210
    break;
211

212
  case 3:
213
    if ( (subframe == 8) || (subframe == 9) ) {
214
      pusch_subframe = (subframe-6);
215
    } else if (subframe==0)
216
      pusch_subframe = (4);
217 218
    else {
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
219
            subframe,frame_parms->tdd_config);
220
      pusch_subframe = (0);
221
    }
222

223
    break;
224

225
  case 4:
226
    if ( (subframe == 8) || (subframe == 9) ) {
227
      pusch_subframe = (subframe-6);
228
    } else {
229
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
230
            subframe,frame_parms->tdd_config);
231
      pusch_subframe = (0);
232
    }
233 234 235

    break;

236
  case 5:
237
    if (subframe == 8) {
238
      pusch_subframe = (2);
239
    } else {
240
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
241
            subframe,frame_parms->tdd_config);
242
      pusch_subframe = (0);
243
    }
244

245 246 247
    break;

  case 6:
248
    if (subframe == 6) {
249
      pusch_subframe = (2);
250
    } else if (subframe == 9) {
251
      pusch_subframe = (3);
252
    } else if (subframe == 0) {
253
      pusch_subframe = (4);
254
    } else if (subframe == 1) {
255
      pusch_subframe = (7);
256
    } else if (subframe == 5) {
257
      pusch_subframe = (8);
258
    } else {
259
      LOG_E(PHY,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n",
260
            subframe,frame_parms->tdd_config);
261
      pusch_subframe = (0);
262
    }
263

264
    break;
265

266 267 268
  default:
    LOG_E(PHY, "no implementation for TDD UL/DL-config = %d!\n", frame_parms->tdd_config);
    pusch_subframe = (0);
269
  }
270

271 272
  LOG_D(PHY, "subframe  %d: PUSCH subframe = %d\n", subframe, pusch_subframe);
  return pusch_subframe;
273 274
}

275 276
int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg)
{
277 278 279 280 281 282

  if ((reg == frame_parms->pcfich_reg[0]) ||
      (reg == frame_parms->pcfich_reg[1]) ||
      (reg == frame_parms->pcfich_reg[2]) ||
      (reg == frame_parms->pcfich_reg[3]))
    return(1);
283

284 285 286
  return(0);
}

287 288
void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
{
289 290 291 292 293 294

  unsigned short n0 = (frame_parms->N_RB_DL * 2) - 4;  // 2 REG per RB less the 4 used by PCFICH in first symbol
  unsigned short n1 = (frame_parms->N_RB_DL * 3);      // 3 REG per RB in second and third symbol
  unsigned short n2 = n1;
  unsigned short mprime = 0;
  unsigned short Ngroup_PHICH;
295 296
  //  uint16_t *phich_reg = frame_parms->phich_reg;
  uint16_t *pcfich_reg = frame_parms->pcfich_reg;
297 298 299

  // compute Ngroup_PHICH (see formula at beginning of Section 6.9 in 36-211
  Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48;
300

301

302 303
  if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0)
    Ngroup_PHICH++;
304

305 306 307 308
  // check if Extended prefix
  if (frame_parms->Ncp == 1) {
    Ngroup_PHICH<<=1;
  }
309

310 311 312 313 314 315 316 317 318
  //#ifdef DEBUG_PHICH
  printf("Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n",
	 ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)),
	 frame_parms->phich_config_common.phich_resource,
	 frame_parms->phich_config_common.phich_duration==normal?"normal":"extended",
	 frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type,
	 pcfich_reg[frame_parms->pcfich_first_reg_idx],
	 n0,
	 n1,
319
	 ((frame_parms->Nid_cell))%n0);
320
  //#endif
321

322
  // This is the algorithm from Section 6.9.3 in 36-211, it works only for normal PHICH duration for now ...
323

324 325 326 327 328
  for (mprime=0; 
       mprime<((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)); 
       mprime++) {

    if (frame_parms->phich_config_common.phich_duration==normal) { // normal PHICH duration
329 330 331 332

      frame_parms->phich_reg[mprime][0] = (frame_parms->Nid_cell + mprime)%n0;

      if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
333 334
        frame_parms->phich_reg[mprime][0]++;

335
      if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+1)&3])
336 337
        frame_parms->phich_reg[mprime][0]++;

338
      if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+2)&3])
339 340
        frame_parms->phich_reg[mprime][0]++;

341
      if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3])
342
        frame_parms->phich_reg[mprime][0]++;
343 344 345

      frame_parms->phich_reg[mprime][1] = (frame_parms->Nid_cell + mprime + (n0/3))%n0;

346
      
347
      if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
348
        frame_parms->phich_reg[mprime][1]++;
349
      
350
      if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+1)&3])
351 352
        frame_parms->phich_reg[mprime][1]++;

353
      if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+2)&3])
354 355
        frame_parms->phich_reg[mprime][1]++;

356
      if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3])
357
        frame_parms->phich_reg[mprime][1]++;
358
      
359 360

      frame_parms->phich_reg[mprime][2] = (frame_parms->Nid_cell + mprime + (2*n0/3))%n0;
361
      
362
      if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[frame_parms->pcfich_first_reg_idx])
363 364
        frame_parms->phich_reg[mprime][2]++;

365
      if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+1)&3])
366 367
        frame_parms->phich_reg[mprime][2]++;

368
      if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+2)&3])
369 370
        frame_parms->phich_reg[mprime][2]++;

371
      if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3])
372
        frame_parms->phich_reg[mprime][2]++;
373 374 375 376 377
      
      //#ifdef DEBUG_PHICH
      printf("phich_reg :%d => %d,%d,%d\n",mprime,frame_parms->phich_reg[mprime][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]);
      //#endif
    } else { // extended PHICH duration
378 379 380 381 382 383 384 385
      frame_parms->phich_reg[mprime<<1][0] = (frame_parms->Nid_cell + mprime)%n0;
      frame_parms->phich_reg[1+(mprime<<1)][0] = (frame_parms->Nid_cell + mprime)%n0;

      frame_parms->phich_reg[mprime<<1][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1;
      frame_parms->phich_reg[mprime<<1][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2;

      frame_parms->phich_reg[1+(mprime<<1)][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1;
      frame_parms->phich_reg[1+(mprime<<1)][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2;
386 387 388 389
      //#ifdef DEBUG_PHICH
      printf("phich_reg :%d => %d,%d,%d\n",mprime<<1,frame_parms->phich_reg[mprime<<1][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]);
      printf("phich_reg :%d => %d,%d,%d\n",1+(mprime<<1),frame_parms->phich_reg[1+(mprime<<1)][0],frame_parms->phich_reg[1+(mprime<<1)][1],frame_parms->phich_reg[1+(mprime<<1)][2]);
      //#endif
390 391 392 393 394 395
    }
  } // mprime loop
}  // num_pdcch_symbols loop


void generate_phich_emul(LTE_DL_FRAME_PARMS *frame_parms,
396 397 398
                         uint8_t HI,
                         uint8_t subframe)
{
399 400 401 402


}

403 404
int32_t alam_bpsk_perm1[4] = {2,1,4,3}; // -conj(x) 1 (-1-j) -> 2 (1-j), 2->1, 3 (-1+j) -> (4) 1+j, 4->3
int32_t alam_bpsk_perm2[4] = {3,4,2,1}; // conj(x) 1 (-1-j) -> 3 (-1+j), 3->1, 2 (1-j) -> 4 (1+j), 4->2
405

406
// This routine generates the PHICH
407 408

void generate_phich(LTE_DL_FRAME_PARMS *frame_parms,
409 410 411 412 413
                    int16_t amp,
                    uint8_t nseq_PHICH,
                    uint8_t ngroup_PHICH,
                    uint8_t HI,
                    uint8_t subframe,
414
                    int32_t **y)
415 416
{

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
  int16_t d[24],*dp;
  //  unsigned int i,aa;
  unsigned int re_offset;
  int16_t y0_16[8],y1_16[8];
  int16_t *y0,*y1;
  // scrambling
  uint32_t x1, x2, s=0;
  uint8_t reset = 1;
  int16_t cs[12];
  uint32_t i,i2,i3,m,j;
  int16_t gain_lin_QPSK;
  uint32_t subframe_offset=((frame_parms->Ncp==0)?14:12)*frame_parms->ofdm_symbol_size*subframe;

  memset(d,0,24*sizeof(int16_t));

432 433
  if (frame_parms->mode1_flag==1)
    gain_lin_QPSK = (int16_t)(((int32_t)amp*ONE_OVER_SQRT2_Q15)>>15);
434
  else
435
    gain_lin_QPSK = amp/2;
436 437 438 439 440 441

  //printf("PHICH : gain_lin_QPSK %d\n",gain_lin_QPSK);

  // BPSK modulation of HI input (to be repeated 3 times, 36-212 Section 5.3.5, p. 56 in v8.6)
  if (HI>0)
    HI=1;
442

443

444 445
  //  c = (1-(2*HI))*SSS_AMP;
  // x1 is set in lte_gold_generic
446
  x2 = (((subframe+1)*((frame_parms->Nid_cell<<1)+1))<<9) + frame_parms->Nid_cell;
447

448
  s = lte_gold_generic(&x1, &x2, reset);
449

450
  // compute scrambling sequence
451
  for (i=0; i<12; i++) {
452 453 454 455 456 457 458 459
    cs[i] = (uint8_t)((s>>(i&0x1f))&1);
    cs[i] = (cs[i] == 0) ? (1-(HI<<1)) : ((HI<<1)-1);
  }

  if (frame_parms->Ncp == 0) { // Normal Cyclic Prefix

    //    printf("Doing PHICH : Normal CP, subframe %d\n",subframe);
    // 12 output symbols (Msymb)
460
    for (i=0,i2=0,i3=0; i<3; i++,i2+=4,i3+=8) {
461 462
      switch (nseq_PHICH) {
      case 0: // +1 +1 +1 +1
463 464 465 466 467 468 469 470 471 472
        d[i3]   = cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

473
      case 1: // +1 -1 +1 -1
474 475 476 477 478 479 480 481 482 483
        d[i3] = cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = -cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = -cs[3+i2];
        break;

484
      case 2: // +1 +1 -1 -1
485 486 487 488 489 490 491 492 493 494
        d[i3]   = cs[i2];
        d[1+i3]   = cs[i2];
        d[2+i3] = cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = -cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = -cs[3+i2];
        break;

495
      case 3: // +1 -1 -1 +1
496 497 498 499 500 501 502 503 504 505
        d[i3]   = cs[i2];
        d[1+i3]   = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = -cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = -cs[2+i2];
        d[6+i3] = cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

506
      case 4: // +j +j +j +j
507 508 509 510 511 512 513 514 515 516
        d[i3]   = -cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

517
      case 5: // +j -j +j -j
518 519 520 521 522 523 524 525 526 527
        d[1+i3] = cs[i2];
        d[3+i3] = -cs[1+i2];
        d[5+i3] = cs[2+i2];
        d[7+i3] = -cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[6+i3] = cs[3+i2];
        break;

528
      case 6: // +j +j -j -j
529 530 531 532 533 534 535 536 537 538
        d[1+i3] = cs[i2];
        d[3+i3] = cs[1+i2];
        d[5+i3] = -cs[2+i2];
        d[7+i3] = -cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = -cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[6+i3] = cs[3+i2];
        break;

539
      case 7: // +j -j -j +j
540 541 542 543 544 545 546 547 548 549
        d[1+i3] = cs[i2];
        d[3+i3] = -cs[1+i2];
        d[5+i3] = -cs[2+i2];
        d[7+i3] = cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        break;

550
      default:
551
        LOG_E(PHY,"phich_coding.c: Illegal PHICH Number\n");
552 553
      } // nseq_PHICH
    }
554

555 556
#ifdef DEBUG_PHICH
    LOG_D(PHY,"[PUSCH 0]PHICH d = ");
557 558

    for (i=0; i<24; i+=2)
559
      LOG_D(PHY,"(%d,%d)",d[i],d[i+1]);
560

561 562
    LOG_D(PHY,"\n");
#endif
563 564

    // modulation here
565 566
    if (frame_parms->mode1_flag == 0) {
      // do Alamouti precoding here
567

568 569 570 571
      // Symbol 0
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][0]*6);

      if (re_offset > frame_parms->ofdm_symbol_size)
572
        re_offset -= (frame_parms->ofdm_symbol_size-1);
573 574 575

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];
576

577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
      // first antenna position n -> x0
      y0_16[0]   = d[0]*gain_lin_QPSK;
      y0_16[1]   = d[1]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[2]*gain_lin_QPSK;
      y1_16[1]   = d[3]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[4]*gain_lin_QPSK;
      y0_16[5]   = d[5]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[6]*gain_lin_QPSK;
      y1_16[5]   = d[7]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

601 602 603 604 605 606 607
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m];
          y1[j]   += y1_16[m++];
          y0[j+1] += y0_16[m];
          y1[j+1] += y1_16[m++];
        }
608
      }
609

610 611 612 613
      // Symbol 1
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][1]*6);

      if (re_offset > frame_parms->ofdm_symbol_size)
614
        re_offset -= (frame_parms->ofdm_symbol_size-1);
615 616 617

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];
618

619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
      // first antenna position n -> x0
      y0_16[0]   = d[8]*gain_lin_QPSK;
      y0_16[1]   = d[9]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[10]*gain_lin_QPSK;
      y1_16[1]   = d[11]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[12]*gain_lin_QPSK;
      y0_16[5]   = d[13]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[14]*gain_lin_QPSK;
      y1_16[5]   = d[15]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

643 644 645 646 647 648 649
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m];
          y1[j]   += y1_16[m++];
          y0[j+1] += y0_16[m];
          y1[j+1] += y1_16[m++];
        }
650 651 652 653 654 655
      }

      // Symbol 2
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][2]*6);

      if (re_offset > frame_parms->ofdm_symbol_size)
656
        re_offset -= (frame_parms->ofdm_symbol_size-1);
657 658 659

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];
660

661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
      // first antenna position n -> x0
      y0_16[0]   = d[16]*gain_lin_QPSK;
      y0_16[1]   = d[17]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[18]*gain_lin_QPSK;
      y1_16[1]   = d[19]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[20]*gain_lin_QPSK;
      y0_16[5]   = d[21]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[22]*gain_lin_QPSK;
      y1_16[5]   = d[23]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

685 686 687 688 689 690 691
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m];
          y1[j]   += y1_16[m++];
          y0[j+1] += y0_16[m];
          y1[j+1] += y1_16[m++];
        }
692 693 694 695 696 697 698 699 700 701
      }

    } // mode1_flag

    else {
      // Symbol 0
      //      printf("[PUSCH 0]PHICH REG %d\n",frame_parms->phich_reg[ngroup_PHICH][0]);
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][0]*6);

      if (re_offset > frame_parms->ofdm_symbol_size)
702
        re_offset -= (frame_parms->ofdm_symbol_size-1);
703 704 705 706 707 708 709 710 711 712 713 714 715

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      //      printf("y0 %p\n",y0);

      y0_16[0]   = d[0]*gain_lin_QPSK;
      y0_16[1]   = d[1]*gain_lin_QPSK;
      y0_16[2]   = d[2]*gain_lin_QPSK;
      y0_16[3]   = d[3]*gain_lin_QPSK;
      y0_16[4]   = d[4]*gain_lin_QPSK;
      y0_16[5]   = d[5]*gain_lin_QPSK;
      y0_16[6]   = d[6]*gain_lin_QPSK;
      y0_16[7]   = d[7]*gain_lin_QPSK;

716 717 718 719 720
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m++];
          y0[j+1] += y0_16[m++];
        }
721
      }
722

723 724 725 726 727
      // Symbol 1
      //      printf("[PUSCH 0]PHICH REG %d\n",frame_parms->phich_reg[ngroup_PHICH][1]);
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][1]*6);

      if (re_offset > frame_parms->ofdm_symbol_size)
728
        re_offset -= (frame_parms->ofdm_symbol_size-1);
729 730

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
731

732 733 734 735 736 737 738 739 740
      y0_16[0]   = d[8]*gain_lin_QPSK;
      y0_16[1]   = d[9]*gain_lin_QPSK;
      y0_16[2]   = d[10]*gain_lin_QPSK;
      y0_16[3]   = d[11]*gain_lin_QPSK;
      y0_16[4]   = d[12]*gain_lin_QPSK;
      y0_16[5]   = d[13]*gain_lin_QPSK;
      y0_16[6]   = d[14]*gain_lin_QPSK;
      y0_16[7]   = d[15]*gain_lin_QPSK;

741 742 743 744 745
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m++];
          y0[j+1] += y0_16[m++];
        }
746 747 748 749 750 751 752
      }

      // Symbol 2
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][2]*6);

      //      printf("[PUSCH 0]PHICH REG %d\n",frame_parms->phich_reg[ngroup_PHICH][2]);
      if (re_offset > frame_parms->ofdm_symbol_size)
753 754
        re_offset -= (frame_parms->ofdm_symbol_size-1);

755
      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
756

757 758 759 760 761 762 763 764 765
      y0_16[0]   = d[16]*gain_lin_QPSK;
      y0_16[1]   = d[17]*gain_lin_QPSK;
      y0_16[2]   = d[18]*gain_lin_QPSK;
      y0_16[3]   = d[19]*gain_lin_QPSK;
      y0_16[4]   = d[20]*gain_lin_QPSK;
      y0_16[5]   = d[21]*gain_lin_QPSK;
      y0_16[6]   = d[22]*gain_lin_QPSK;
      y0_16[7]   = d[23]*gain_lin_QPSK;

766 767 768 769 770
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j]   += y0_16[m++];
          y0[j+1] += y0_16[m++];
        }
771
      }
772

773 774
      /*
      for (i=0;i<512;i++)
775
      printf("re %d (%d): %d,%d\n",i,subframe_offset+i,((int16_t*)&y[0][subframe_offset+i])[0],((int16_t*)&y[0][subframe_offset+i])[1]);
776 777
      */
    } // mode1_flag
778 779
  } else { // extended prefix

780 781 782
    // 6 output symbols
    if ((ngroup_PHICH & 1) == 1)
      dp = &d[4];
783
    else
784 785 786
      dp = d;

    switch (nseq_PHICH) {
787
    case 0: // +1 +1
788 789 790 791 792 793 794 795 796 797 798 799 800
      dp[0]  = cs[0];
      dp[2]  = cs[1];
      dp[8]  = cs[2];
      dp[10] = cs[3];
      dp[16] = cs[4];
      dp[18] = cs[5];
      dp[1]  = cs[0];
      dp[3]  = cs[1];
      dp[9]  = cs[2];
      dp[11] = cs[3];
      dp[17] = cs[4];
      dp[19] = cs[5];
      break;
801

802 803 804 805 806 807 808 809 810 811 812 813 814 815
    case 1: // +1 -1
      dp[0]  = cs[0];
      dp[2]  = -cs[1];
      dp[8]  = cs[2];
      dp[10] = -cs[3];
      dp[16] = cs[4];
      dp[18] = -cs[5];
      dp[1]  = cs[0];
      dp[3]  = -cs[1];
      dp[9]  = cs[2];
      dp[11] = -cs[3];
      dp[17] = cs[4];
      dp[19] = -cs[5];
      break;
816 817

    case 2: // +j +j
818 819 820 821 822 823 824 825 826 827 828 829
      dp[1]  = cs[0];
      dp[3]  = cs[1];
      dp[9]  = cs[2];
      dp[11] = cs[3];
      dp[17] = cs[4];
      dp[19] = cs[5];
      dp[0]  = -cs[0];
      dp[2]  = -cs[1];
      dp[8]  = -cs[2];
      dp[10] = -cs[3];
      dp[16] = -cs[4];
      dp[18] = -cs[5];
830

831
      break;
832 833

    case 3: // +j -j
834 835 836 837 838 839 840 841 842 843 844 845 846
      dp[1]  = cs[0];
      dp[3]  = -cs[1];
      dp[9]  = cs[2];
      dp[11] = -cs[3];
      dp[17] = cs[4];
      dp[19] = -cs[5];
      dp[0]  = -cs[0];
      dp[2]  = cs[1];
      dp[8]  = -cs[2];
      dp[10] = cs[3];
      dp[16] = -cs[4];
      dp[18] = cs[5];
      break;
847

848 849 850
    default:
      LOG_E(PHY,"phich_coding.c: Illegal PHICH Number\n");
    }
851 852 853



854 855 856 857
    if (frame_parms->mode1_flag == 0) {
      // do Alamouti precoding here
      // Symbol 0
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][0]*6);
858

859
      if (re_offset > frame_parms->ofdm_symbol_size)
860
        re_offset -= (frame_parms->ofdm_symbol_size-1);
861 862 863

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];
864

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
      // first antenna position n -> x0
      y0_16[0]   = d[0]*gain_lin_QPSK;
      y0_16[1]   = d[1]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[2]*gain_lin_QPSK;
      y1_16[1]   = d[3]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[4]*gain_lin_QPSK;
      y0_16[5]   = d[5]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[6]*gain_lin_QPSK;
      y1_16[5]   = d[7]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

889 890 891 892 893 894 895
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j] += y0_16[m];
          y1[j] += y1_16[m++];
          y0[j+1] += y0_16[m];
          y1[j+1] += y1_16[m++];
        }
896 897 898 899
      }

      // Symbol 1
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][1]<<2);
900

901
      if (re_offset > frame_parms->ofdm_symbol_size)
902 903
        re_offset -= (frame_parms->ofdm_symbol_size-1);

904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
      re_offset += (frame_parms->ofdm_symbol_size);

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];

      // first antenna position n -> x0
      y0_16[0]   = d[8]*gain_lin_QPSK;
      y0_16[1]   = d[9]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[10]*gain_lin_QPSK;
      y1_16[1]   = d[11]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[12]*gain_lin_QPSK;
      y0_16[5]   = d[13]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[14]*gain_lin_QPSK;
      y1_16[5]   = d[15]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

933 934 935 936 937
      for (i=0,j=0,m=0; i<4; i++,j+=2) {
        y0[j] += y0_16[m];
        y1[j] += y1_16[m++];
        y0[j+1] += y0_16[m];
        y1[j+1] += y1_16[m++];
938 939 940 941
      }

      // Symbol 2
      re_offset = frame_parms->first_carrier_offset +  (frame_parms->phich_reg[ngroup_PHICH][2]<<2);
942

943
      if (re_offset > frame_parms->ofdm_symbol_size)
944 945
        re_offset -= (frame_parms->ofdm_symbol_size-1);

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
      re_offset += (frame_parms->ofdm_symbol_size<<1);

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
      y1 = (int16_t*)&y[1][re_offset+subframe_offset];

      // first antenna position n -> x0
      y0_16[0]   = d[16]*gain_lin_QPSK;
      y0_16[1]   = d[17]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[0]   = -d[18]*gain_lin_QPSK;
      y1_16[1]   = d[19]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[2] = -y1_16[0];
      y0_16[3] = y1_16[1];
      y1_16[2] = y0_16[0];
      y1_16[3] = -y0_16[1];

      // first antenna position n -> x0
      y0_16[4]   = d[20]*gain_lin_QPSK;
      y0_16[5]   = d[21]*gain_lin_QPSK;
      // second antenna position n -> -x1*
      y1_16[4]   = -d[22]*gain_lin_QPSK;
      y1_16[5]   = d[23]*gain_lin_QPSK;
      // fill in the rest of the ALAMOUTI precoding
      y0_16[6] = -y1_16[4];
      y0_16[7] = y1_16[5];
      y1_16[6] = y0_16[4];
      y1_16[7] = -y0_16[5];

975 976 977 978 979
      for (i=0,j=0,m=0; i<4; i++,j+=2) {
        y0[j]   += y0_16[m];
        y1[j]   += y1_16[m++];
        y0[j+1] += y0_16[m];
        y1[j+1] += y1_16[m++];
980
      }
981
    } else {
982 983 984

      // Symbol 0
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][0]*6);
985

986
      if (re_offset > frame_parms->ofdm_symbol_size)
987
        re_offset -= (frame_parms->ofdm_symbol_size-1);
988 989

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
990

991 992 993 994 995 996 997 998 999
      y0_16[0]   = d[0]*gain_lin_QPSK;
      y0_16[1]   = d[1]*gain_lin_QPSK;
      y0_16[2]   = d[2]*gain_lin_QPSK;
      y0_16[3]   = d[3]*gain_lin_QPSK;
      y0_16[4]   = d[4]*gain_lin_QPSK;
      y0_16[5]   = d[5]*gain_lin_QPSK;
      y0_16[6]   = d[6]*gain_lin_QPSK;
      y0_16[7]   = d[7]*gain_lin_QPSK;

1000 1001 1002 1003 1004
      for (i=0,j=0,m=0; i<6; i++,j+=2) {
        if ((i!=(frame_parms->nushift))&&(i!=(frame_parms->nushift+3))) {
          y0[j] += y0_16[m++];
          y0[j+1] += y0_16[m++];
        }
1005 1006 1007 1008
      }

      // Symbol 1
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][1]<<2);
1009

1010
      if (re_offset > frame_parms->ofdm_symbol_size)
1011 1012
        re_offset -= (frame_parms->ofdm_symbol_size-1);

1013 1014 1015
      re_offset += (frame_parms->ofdm_symbol_size);

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
1016

1017 1018 1019 1020 1021 1022 1023 1024 1025
      y0_16[0]   = d[8]*gain_lin_QPSK;
      y0_16[1]   = d[9]*gain_lin_QPSK;
      y0_16[2]   = d[10]*gain_lin_QPSK;
      y0_16[3]   = d[11]*gain_lin_QPSK;
      y0_16[4]   = d[12]*gain_lin_QPSK;
      y0_16[5]   = d[13]*gain_lin_QPSK;
      y0_16[6]   = d[14]*gain_lin_QPSK;
      y0_16[7]   = d[15]*gain_lin_QPSK;

1026 1027 1028
      for (i=0,j=0,m=0; i<4; i++,j+=2) {
        y0[j] += y0_16[m++];
        y0[j+1] += y0_16[m++];
1029 1030 1031 1032 1033
      }


      // Symbol 2
      re_offset = frame_parms->first_carrier_offset + (frame_parms->phich_reg[ngroup_PHICH][2]<<2);
1034

1035
      if (re_offset > frame_parms->ofdm_symbol_size)
1036 1037
        re_offset -= (frame_parms->ofdm_symbol_size-1);

1038 1039 1040
      re_offset += (frame_parms->ofdm_symbol_size<<1);

      y0 = (int16_t*)&y[0][re_offset+subframe_offset];
1041

1042 1043 1044 1045 1046 1047 1048 1049 1050
      y0_16[0]   = d[16]*gain_lin_QPSK;
      y0_16[1]   = d[17]*gain_lin_QPSK;
      y0_16[2]   = d[18]*gain_lin_QPSK;
      y0_16[3]   = d[19]*gain_lin_QPSK;
      y0_16[4]   = d[20]*gain_lin_QPSK;
      y0_16[5]   = d[21]*gain_lin_QPSK;
      y0_16[6]   = d[22]*gain_lin_QPSK;
      y0_16[7]   = d[23]*gain_lin_QPSK;

1051 1052 1053
      for (i=0,j=0,m=0; i<4; i++) {
        y0[j]   += y0_16[m++];
        y0[j+1] += y0_16[m++];
1054 1055 1056 1057
      }

    } // mode1_flag
  } // normal/extended prefix
1058
}
1059 1060 1061

// This routine demodulates the PHICH and updates PUSCH/ULSCH parameters

1062
void rx_phich(PHY_VARS_UE *ue,
1063
	      UE_rxtx_proc_t *proc,
1064 1065 1066
              uint8_t subframe,
              uint8_t eNB_id)
{
1067 1068


1069 1070
  LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
  LTE_UE_PDCCH **pdcch_vars = ue->pdcch_vars;
1071 1072

  //  uint8_t HI;
1073
  uint8_t harq_pid = phich_subframe_to_harq_pid(frame_parms,proc->frame_rx,subframe);
1074
  LTE_UE_ULSCH_t *ulsch = ue->ulsch[eNB_id];
1075 1076 1077
  int16_t phich_d[24],*phich_d_ptr,HI16;
  //  unsigned int i,aa;
  int8_t d[24],*dp;
1078
  uint16_t reg_offset;
1079 1080 1081 1082 1083 1084

  // scrambling
  uint32_t x1, x2, s=0;
  uint8_t reset = 1;
  int16_t cs[12];
  uint32_t i,i2,i3,phich_quad;
1085
  int32_t **rxdataF_comp = pdcch_vars[eNB_id]->rxdataF_comp;
1086 1087 1088
  uint8_t Ngroup_PHICH,ngroup_PHICH,nseq_PHICH;
  uint8_t NSF_PHICH = 4;
  uint8_t pusch_subframe;
1089

1090
  // check if we're expecting a PHICH in this subframe
1091
  LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH RX\n",ue->Mod_id,harq_pid,proc->frame_rx,subframe);
1092

1093 1094
  if (!ulsch)
    return;
1095

1096 1097
  LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH RX Status: %d \n",ue->Mod_id,harq_pid,proc->frame_rx,subframe, ulsch->harq_processes[harq_pid]->status);

1098
  if (ulsch->harq_processes[harq_pid]->status == ACTIVE) {
1099
     LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH RX ACTIVE\n",ue->Mod_id,harq_pid,proc->frame_rx,subframe);
1100
    Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48;
1101

1102 1103
    if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0)
      Ngroup_PHICH++;
1104

1105 1106 1107
    if (frame_parms->Ncp == 1)
      NSF_PHICH = 2;

1108 1109 1110 1111

    ngroup_PHICH = (ulsch->harq_processes[harq_pid]->first_rb +
                    ulsch->harq_processes[harq_pid]->n_DMRS)%Ngroup_PHICH;

Raymond Knopp's avatar
 
Raymond Knopp committed
1112
    if ((frame_parms->tdd_config == 0) && (frame_parms->frame_type == TDD) ) {
1113
      pusch_subframe = phich_subframe2_pusch_subframe(frame_parms,subframe);
1114

1115
      if ((pusch_subframe == 4) || (pusch_subframe == 9))
1116
        ngroup_PHICH += Ngroup_PHICH;
1117
    }
1118 1119 1120 1121

    nseq_PHICH = ((ulsch->harq_processes[harq_pid]->first_rb/Ngroup_PHICH) +
                  ulsch->harq_processes[harq_pid]->n_DMRS)%(2*NSF_PHICH);
  } else {
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
    LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH RX %s\n",
        ue->Mod_id,
        harq_pid,
        proc->frame_rx,
        subframe,
        (ulsch->harq_processes[harq_pid]->status==SCH_IDLE?   "SCH_IDLE"  :
        (ulsch->harq_processes[harq_pid]->status==ACTIVE?     "ACTIVE"    :
        (ulsch->harq_processes[harq_pid]->status==CBA_ACTIVE? "CBA_ACTIVE":
        (ulsch->harq_processes[harq_pid]->status==DISABLED?   "DISABLED"  : "UNKNOWN")))));

1132 1133 1134 1135 1136 1137 1138
    return;
  }

  memset(d,0,24*sizeof(int8_t));
  phich_d_ptr = phich_d;

  // x1 is set in lte_gold_generic
1139
  x2 = (((subframe+1)*((frame_parms->Nid_cell<<1)+1))<<9) + frame_parms->Nid_cell;
1140

1141
  s = lte_gold_generic(&x1, &x2, reset);
1142

1143
  // compute scrambling sequence
1144
  for (i=0; i<12; i++) {
1145 1146 1147 1148 1149 1150 1151 1152
    cs[i] = 1-(((s>>(i&0x1f))&1)<<1);
  }

  if (frame_parms->Ncp == 0) { // Normal Cyclic Prefix


    // 12 output symbols (Msymb)

1153
    for (i=0,i2=0,i3=0; i<3; i++,i2+=4,i3+=8) {
1154 1155
      switch (nseq_PHICH) {
      case 0: // +1 +1 +1 +1
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
        d[i3]   = cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

1166
      case 1: // +1 -1 +1 -1
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
        d[i3] = cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = -cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = -cs[3+i2];
        break;

1177
      case 2: // +1 +1 -1 -1
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
        d[i3]   = cs[i2];
        d[1+i3]   = cs[i2];
        d[2+i3] = cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = -cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = -cs[3+i2];
        break;

1188
      case 3: // +1 -1 -1 +1
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
        d[i3]   = cs[i2];
        d[1+i3]   = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = -cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = -cs[2+i2];
        d[6+i3] = cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

1199
      case 4: // +j +j +j +j
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
        d[i3]   = -cs[i2];
        d[1+i3] = cs[i2];
        d[2+i3] = -cs[1+i2];
        d[3+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[5+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        d[7+i3] = cs[3+i2];
        break;

1210
      case 5: // +j -j +j -j
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
        d[1+i3] = cs[i2];
        d[3+i3] = -cs[1+i2];
        d[5+i3] = cs[2+i2];
        d[7+i3] = -cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = cs[1+i2];
        d[4+i3] = -cs[2+i2];
        d[6+i3] = cs[3+i2];
        break;

1221
      case 6: // +j +j -j -j
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
        d[1+i3] = cs[i2];
        d[3+i3] = cs[1+i2];
        d[5+i3] = -cs[2+i2];
        d[7+i3] = -cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = -cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[6+i3] = cs[3+i2];
        break;

1232
      case 7: // +j -j -j +j
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
        d[1+i3] = cs[i2];
        d[3+i3] = -cs[1+i2];
        d[5+i3] = -cs[2+i2];
        d[7+i3] = cs[3+i2];
        d[i3]   = -cs[i2];
        d[2+i3] = cs[1+i2];
        d[4+i3] = cs[2+i2];
        d[6+i3] = -cs[3+i2];
        break;

1243
      default:
1244
        LOG_E(PHY,"phich_coding.c: Illegal PHICH Number\n");
1245 1246
      } // nseq_PHICH
    }
1247

1248 1249
#ifdef DEBUG_PHICH
    LOG_D(PHY,"PHICH =>");
1250 1251

    for (i=0; i<24; i++) {
1252 1253
      LOG_D(PHY,"%2d,",d[i]);
    }
1254

1255 1256 1257 1258 1259
    LOG_D(PHY,"\n");
#endif
    // demodulation here


1260 1261
  } else { // extended prefix

1262 1263 1264
    // 6 output symbols
    if ((ngroup_PHICH & 1) == 1)
      dp = &d[4];
1265
    else
1266
      dp = d;
1267

1268
    switch (nseq_PHICH) {
1269
    case 0: // +1 +1
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
      dp[0]  = cs[0];
      dp[2]  = cs[1];
      dp[8]  = cs[2];
      dp[10] = cs[3];
      dp[16] = cs[4];
      dp[18] = cs[5];
      dp[1]  = cs[0];
      dp[3]  = cs[1];
      dp[9]  = cs[2];
      dp[11] = cs[3];
      dp[17] = cs[4];
      dp[19] = cs[5];
      break;
1283

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
    case 1: // +1 -1
      dp[0]  = cs[0];
      dp[2]  = -cs[1];
      dp[8]  = cs[2];
      dp[10] = -cs[3];
      dp[16] = cs[4];
      dp[18] = -cs[5];
      dp[1]  = cs[0];
      dp[3]  = -cs[1];
      dp[9]  = cs[2];
      dp[11] = -cs[3];
      dp[17] = cs[4];
      dp[19] = -cs[5];
      break;
1298 1299

    case 2: // +j +j
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
      dp[1]  = cs[0];
      dp[3]  = cs[1];
      dp[9]  = cs[2];
      dp[11] = cs[3];
      dp[17] = cs[4];
      dp[19] = cs[5];
      dp[0]  = -cs[0];
      dp[2]  = -cs[1];
      dp[8]  = -cs[2];
      dp[10] = -cs[3];
      dp[16] = -cs[4];
      dp[18] = -cs[5];
1312 1313 1314 1315

      break;

    case 3: // +j -j
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
      dp[1]  = cs[0];
      dp[3]  = -cs[1];
      dp[9]  = cs[2];
      dp[11] = -cs[3];
      dp[17] = cs[4];
      dp[19] = -cs[5];
      dp[0]  = -cs[0];
      dp[2]  = cs[1];
      dp[8]  = -cs[2];
      dp[10] = cs[3];
      dp[16] = -cs[4];
      dp[18] = cs[5];
      break;
1329

1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
    default:
      LOG_E(PHY,"phich_coding.c: Illegal PHICH Number\n");
    }
  }

  HI16 = 0;

  //#ifdef DEBUG_PHICH

  //#endif
1340
  /*
1341 1342 1343
  for (i=0;i<200;i++)
    printf("re %d: %d %d\n",i,((int16_t*)&rxdataF_comp[0][i])[0],((int16_t*)&rxdataF_comp[0][i])[1]);
  */
1344 1345
  for (phich_quad=0; phich_quad<3; phich_quad++) {
    if (frame_parms->Ncp == 1)
1346 1347 1348 1349 1350 1351 1352
      reg_offset = (frame_parms->phich_reg[ngroup_PHICH][phich_quad]*4)+ (phich_quad*frame_parms->N_RB_DL*12);
    else
      reg_offset = (frame_parms->phich_reg[ngroup_PHICH][phich_quad]*4);

    //    msg("\n[PUSCH 0]PHICH (RX) quad %d (%d)=>",phich_quad,reg_offset);
    dp = &d[phich_quad*8];;

1353 1354 1355
    for (i=0; i<8; i++) {
      phich_d_ptr[i] = ((int16_t*)&rxdataF_comp[0][reg_offset])[i];

1356 1357
#ifdef DEBUG_PHICH
      LOG_D(PHY,"%d,",((int16_t*)&rxdataF_comp[0][reg_offset])[i]);
1358 1359 1360 1361
#endif

      HI16 += (phich_d_ptr[i] * dp[i]);
    }
1362
  }
1363

1364 1365 1366 1367
#ifdef DEBUG_PHICH
  LOG_D(PHY,"\n");
  LOG_D(PHY,"HI16 %d\n",HI16);
#endif
1368

1369
  if (HI16>0) {   //NACK
1370
    if (ue->ulsch_Msg3_active[eNB_id] == 1) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1371
      LOG_D(PHY,"[UE  %d][PUSCH %d][RAPROC] Frame %d subframe %d Msg3 PHICH, received NAK (%d) nseq %d, ngroup %d\n",
1372
            ue->Mod_id,harq_pid,
1373
            proc->frame_rx,
1374 1375 1376 1377
            subframe,
            HI16,
            nseq_PHICH,
            ngroup_PHICH);
1378
      get_Msg3_alloc_ret(&ue->frame_parms,
1379
                         subframe,
1380
                         proc->frame_rx,
1381 1382
                         &ue->ulsch_Msg3_frame[eNB_id],
                         &ue->ulsch_Msg3_subframe[eNB_id]);
1383
      ulsch->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
1384
      //      ulsch->harq_processes[harq_pid]->Ndi = 0;
1385 1386
      ulsch->harq_processes[harq_pid]->round++;
      ulsch->harq_processes[harq_pid]->rvidx = rv_table[ulsch->harq_processes[harq_pid]->round&3];
1387

1388
      if (ulsch->harq_processes[harq_pid]->round>=ue->frame_parms.maxHARQ_Msg3Tx) {
1389 1390 1391
        ulsch->harq_processes[harq_pid]->subframe_scheduling_flag =0;
        ulsch->harq_processes[harq_pid]->status = IDLE;
        // inform MAC that Msg3 transmission has failed
1392
        ue->ulsch_Msg3_active[eNB_id] = 0;
1393
      }
1394
    } else {
1395
      //#ifdef DEBUG_PHICH
Raymond Knopp's avatar
 
Raymond Knopp committed
1396
      LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH, received NAK (%d) nseq %d, ngroup %d\n",
1397
            ue->Mod_id,harq_pid,
1398
            proc->frame_rx,
1399 1400 1401
            subframe,
            HI16,
            nseq_PHICH,
1402
            ngroup_PHICH,
1403
            ulsch->Mlimit);
1404
      //#endif
1405

1406
      //      ulsch->harq_processes[harq_pid]->Ndi = 0;
1407
      ulsch->harq_processes[harq_pid]->round++;
1408
      
1409
      if ( ulsch->harq_processes[harq_pid]->round >= (ulsch->Mlimit - 1) )
1410
      {
1411 1412 1413 1414 1415 1416 1417
          // this is last push re transmission
          ulsch->harq_processes[harq_pid]->rvidx = rv_table[ulsch->harq_processes[harq_pid]->round&3];
          ulsch->O_RI = 0;
          ulsch->O    = 0;
          ulsch->uci_format = HLC_subband_cqi_nopmi;

          // disable phich decoding since it is the last retransmission
1418
          ulsch->harq_processes[harq_pid]->status = IDLE;
1419 1420 1421 1422

          //ulsch->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
          //ulsch->harq_processes[harq_pid]->round  = 0;

1423
          //LOG_I(PHY,"PUSCH MAX Retransmission acheived ==> flush harq buff (%d) \n",harq_pid);
1424
          //LOG_I(PHY,"[HARQ-UL harqId: %d] PHICH NACK MAX RETRANS(%d) ==> subframe_scheduling_flag = %d round: %d\n", harq_pid, ulsch->Mlimit, ulsch->harq_processes[harq_pid]->subframe_scheduling_flag, ulsch->harq_processes[harq_pid]->round);
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
      }
      else
      {
          // ulsch->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
          ulsch->harq_processes[harq_pid]->rvidx = rv_table[ulsch->harq_processes[harq_pid]->round&3];
          ulsch->O_RI = 0;
          ulsch->O    = 0;
          ulsch->uci_format = HLC_subband_cqi_nopmi;
          //LOG_I(PHY,"[HARQ-UL harqId: %d] PHICH NACK ==> subframe_scheduling_flag = %d round: %d\n", harq_pid, ulsch->harq_processes[harq_pid]->subframe_scheduling_flag,ulsch->harq_processes[harq_pid]->round);
      }
1435
    }
1436 1437
#if T_TRACER
    T(T_UE_PHY_ULSCH_UE_NACK, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(subframe), T_INT(ue->Mod_id), T_INT(ulsch->rnti),
1438
      T_INT(harq_pid));
1439
#endif
1440

1441
  } else {  //ACK
1442
    if (ue->ulsch_Msg3_active[eNB_id] == 1) {
Raymond Knopp's avatar
 
Raymond Knopp committed
1443
      LOG_D(PHY,"[UE  %d][PUSCH %d][RAPROC] Frame %d subframe %d Msg3 PHICH, received ACK (%d) nseq %d, ngroup %d\n\n",
1444
            ue->Mod_id,harq_pid,
1445
            proc->frame_rx,
1446 1447 1448 1449
            subframe,
            HI16,
            nseq_PHICH,ngroup_PHICH);
    } else {
1450 1451
      //#ifdef PHICH_DEBUG
      LOG_D(PHY,"[UE  %d][PUSCH %d] Frame %d subframe %d PHICH, received ACK (%d) nseq %d, ngroup %d\n\n",
1452
            ue->Mod_id,harq_pid,
1453
            proc->frame_rx,
1454 1455
            subframe, HI16,
            nseq_PHICH,ngroup_PHICH);
1456 1457
      //#endif
    }
1458

1459 1460 1461 1462 1463 1464 1465
   // LOG_I(PHY,"[HARQ-UL harqId: %d] subframe_scheduling_flag = %d \n",harq_pid, ulsch->harq_processes[harq_pid]->subframe_scheduling_flag);

    // Incase of adaptive retransmission, PHICH is always decoded as ACK (at least with OAI-eNB)
    // Workaround:
    // rely only on DCI0 decoding and check if NDI has toggled
    //   save current harq_processes content in temporary struct
    //   harqId-8 corresponds to the temporary struct. In total we have 8 harq process(0 ..7) + 1 temporary harq process()
1466
    //ulsch->harq_processes[8] = ulsch->harq_processes[harq_pid];
1467

1468 1469
    ulsch->harq_processes[harq_pid]->subframe_scheduling_flag =0;
    ulsch->harq_processes[harq_pid]->status = IDLE;
Raymond Knopp's avatar
 
Raymond Knopp committed
1470
    ulsch->harq_processes[harq_pid]->round  = 0;
1471
    // inform MAC?
1472
    ue->ulsch_Msg3_active[eNB_id] = 0;
1473

1474 1475
#if T_TRACER
    T(T_UE_PHY_ULSCH_UE_ACK, T_INT(eNB_id), T_INT(proc->frame_rx%1024), T_INT(subframe), T_INT(ue->Mod_id), T_INT(ulsch->rnti),
1476
      T_INT(harq_pid));
1477 1478
#endif

1479
  }
1480

1481 1482
}

1483
void generate_phich_top(PHY_VARS_eNB *eNB,
1484 1485
                        eNB_rxtx_proc_t *proc,
			int16_t amp,
1486
                        uint8_t sect_id)
1487
{
1488 1489


1490 1491 1492
  LTE_DL_FRAME_PARMS *frame_parms=&eNB->frame_parms;
  LTE_eNB_ULSCH_t **ulsch = eNB->ulsch;
  int32_t **txdataF = eNB->common_vars.txdataF[sect_id];
1493 1494 1495 1496 1497 1498
  uint8_t harq_pid;
  uint8_t Ngroup_PHICH,ngroup_PHICH,nseq_PHICH;
  uint8_t NSF_PHICH = 4;
  uint8_t pusch_subframe;
  uint8_t UE_id;
  uint32_t pusch_frame;
1499
  int subframe = proc->subframe_tx;
1500 1501

  // compute Ngroup_PHICH (see formula at beginning of Section 6.9 in 36-211
1502

1503
  Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48;
1504

1505 1506 1507 1508 1509
  if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0)
    Ngroup_PHICH++;

  if (frame_parms->Ncp == 1)
    NSF_PHICH = 2;
1510

1511
  pusch_frame = phich_frame2_pusch_frame(frame_parms,proc->frame_tx,subframe);
1512 1513 1514
  pusch_subframe = phich_subframe2_pusch_subframe(frame_parms,subframe);
  harq_pid = subframe2harq_pid(frame_parms,pusch_frame,pusch_subframe);

1515
  for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) {
1516 1517
    if ((ulsch[UE_id])&&(ulsch[UE_id]->rnti>0)) {
      if (ulsch[UE_id]->harq_processes[harq_pid]->phich_active == 1) {
1518

1519
        LOG_D(PHY,"[eNB][PUSCH %d/%x] Frame %d subframe %d (pusch_subframe %d,pusch_frame %d) phich active %d\n",
1520
              harq_pid,ulsch[UE_id]->rnti,proc->frame_tx,subframe,pusch_subframe,pusch_frame,ulsch[UE_id]->harq_processes[harq_pid]->phich_active);
1521

1522 1523 1524 1525 1526 1527
        /* the HARQ process may have been reused by a new scheduling, so we use
         * previous values of first_rb and n_DMRS to compute ngroup_PHICH and nseq_PHICH
         */

        ngroup_PHICH = (ulsch[UE_id]->harq_processes[harq_pid]->previous_first_rb +
                        ulsch[UE_id]->harq_processes[harq_pid]->previous_n_DMRS)%Ngroup_PHICH;
1528 1529 1530 1531 1532 1533 1534

        if ((frame_parms->tdd_config == 0) && (frame_parms->frame_type == TDD) ) {

          if ((pusch_subframe == 4) || (pusch_subframe == 9))
            ngroup_PHICH += Ngroup_PHICH;
        }

1535 1536
        nseq_PHICH = ((ulsch[UE_id]->harq_processes[harq_pid]->previous_first_rb/Ngroup_PHICH) +
                      ulsch[UE_id]->harq_processes[harq_pid]->previous_n_DMRS)%(2*NSF_PHICH);
1537
        LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d Generating PHICH, ngroup_PHICH %d/%d, nseq_PHICH %d : HI %d, first_rb %d dci_alloc %d)\n",
1538
              eNB->Mod_id,harq_pid,proc->frame_tx,
1539
              subframe,ngroup_PHICH,Ngroup_PHICH,nseq_PHICH,
1540
              ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK,
1541
              ulsch[UE_id]->harq_processes[harq_pid]->previous_first_rb,
1542
              ulsch[UE_id]->harq_processes[harq_pid]->dci_alloc);
1543

Cedric Roux's avatar
Cedric Roux committed
1544 1545 1546 1547 1548 1549 1550 1551
        T(T_ENB_PHY_PHICH, T_INT(eNB->Mod_id), T_INT(proc->frame_tx), T_INT(subframe),
          T_INT(UE_id), T_INT(ulsch[UE_id]->rnti), T_INT(harq_pid),
          T_INT(Ngroup_PHICH), T_INT(NSF_PHICH),
          T_INT(ngroup_PHICH), T_INT(nseq_PHICH),
          T_INT(ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK),
          T_INT(ulsch[UE_id]->harq_processes[harq_pid]->previous_first_rb),
          T_INT(ulsch[UE_id]->harq_processes[harq_pid]->previous_n_DMRS));

1552
        if (ulsch[UE_id]->Msg3_active == 1) {
1553
          LOG_D(PHY,"[eNB %d][PUSCH %d][RAPROC] Frame %d, subframe %d: Generating Msg3 PHICH for UE %d, ngroup_PHICH %d/%d, nseq_PHICH %d : HI %d, first_rb %d\n",
1554
                eNB->Mod_id,harq_pid,proc->frame_tx,subframe,
1555
                UE_id,ngroup_PHICH,Ngroup_PHICH,nseq_PHICH,ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK,
1556
                ulsch[UE_id]->harq_processes[harq_pid]->previous_first_rb);
1557 1558
        }

1559
        if (eNB->abstraction_flag == 0) {
1560 1561 1562 1563
          generate_phich(frame_parms,
                         amp,//amp*2,
                         nseq_PHICH,
                         ngroup_PHICH,
1564
                         ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK,
1565 1566 1567 1568 1569 1570 1571
                         subframe,
                         txdataF);
        } else {
          /*
          generate_phich_emul(frame_parms,
                  //nseq_PHICH,
                  //ngroup_PHICH,
1572
                  ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK,
1573 1574 1575 1576 1577 1578 1579
                  subframe);
          */
        }

        // if no format0 DCI was transmitted by MAC, prepare the
        // MCS parameters for the retransmission

1580

1581 1582 1583
        if ((ulsch[UE_id]->harq_processes[harq_pid]->dci_alloc == 0) &&
            (ulsch[UE_id]->harq_processes[harq_pid]->rar_alloc == 0) ) {
          if (ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK==0 ) {
Cedric Roux's avatar
Cedric Roux committed
1584
            T(T_ENB_PHY_ULSCH_UE_NO_DCI_RETRANSMISSION, T_INT(eNB->Mod_id), T_INT(proc->frame_tx),
1585
              T_INT(subframe), T_INT(UE_id), T_INT(ulsch[UE_id]->rnti), T_INT(harq_pid));
1586
            LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d, subframe %d : PHICH NACK / (no format0 DCI) Setting subframe_scheduling_flag\n",
1587
                  eNB->Mod_id,harq_pid,proc->frame_tx,subframe);
1588 1589 1590 1591 1592 1593
            ulsch[UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
            ulsch[UE_id]->harq_processes[harq_pid]->rvidx = rv_table[ulsch[UE_id]->harq_processes[harq_pid]->round&3];
            ulsch[UE_id]->harq_processes[harq_pid]->O_RI                                  = 0;
            ulsch[UE_id]->harq_processes[harq_pid]->Or2                                   = 0;
            ulsch[UE_id]->harq_processes[harq_pid]->Or1                                   = 0;
            ulsch[UE_id]->harq_processes[harq_pid]->uci_format                            = HLC_subband_cqi_nopmi;
1594 1595 1596

          } else {
            LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d PHICH ACK (no format0 DCI) Clearing subframe_scheduling_flag, setting round to 0\n",
1597
                  eNB->Mod_id,harq_pid,proc->frame_tx,subframe);
1598 1599
            ulsch[UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
            ulsch[UE_id]->harq_processes[harq_pid]->round=0;
1600 1601 1602
          }
        }

1603
        ulsch[UE_id]->harq_processes[harq_pid]->phich_active=0;
1604 1605 1606 1607
      } // phich_active==1
    } //ulsch_ue[UE_id] is non-null
  }// UE loop
}