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

/*! \file PHY/LTE_TRANSPORT/dlsch_modulation.c
23 24 25 26 27 28 29 30 31
 * \brief Top-level routines for generating the PDSCH physical channel from 36-211, V8.6 2009-03
 * \author R. Knopp, F. Kaltenberger
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr
 * \note
 * \warning
 */
32

33 34 35 36 37 38 39
#include "PHY/defs.h"
#include "PHY/extern.h"
#include "PHY/CODING/defs.h"
#include "PHY/CODING/extern.h"
#include "PHY/CODING/lte_interleaver_inline.h"
#include "PHY/LTE_TRANSPORT/defs.h"
#include "defs.h"
40
#include "UTIL/LOG/vcd_signal_dumper.h"
41

Florian Kaltenberger's avatar
Florian Kaltenberger committed
42
//#define DEBUG_DLSCH_MODULATION
43 44 45

//#define is_not_pilot(pilots,re,nushift,use2ndpilots) ((pilots==0) || ((re!=nushift) && (re!=nushift+6)&&((re!=nushift+3)||(use2ndpilots==1))&&((re!=nushift+9)||(use2ndpilots==1)))?1:0)

46 47
uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots)
{
48 49 50

  uint8_t offset = (pilots==2)?3:0;
  int nushiftmod3 = nushift%3;
51

52 53 54 55 56 57
  if (pilots==0)
    return(1);

  if (use2ndpilots==1) {  // This is for SISO (mode 1)
    if ((re!=nushift+offset) && (re!=((nushift+6+offset)%12)))
      return(1);
58
  } else { // 2 antenna pilots
59 60 61
    if ((re!=nushiftmod3) && (re!=nushiftmod3+6) && (re!=nushiftmod3+3) && (re!=nushiftmod3+9))
      return(1);
  }
62

63 64 65
  return(0);
}

66
uint8_t is_not_UEspecRS(int8_t lprime, uint8_t re, uint8_t nushift, uint8_t Ncp, uint8_t beamforming_mode, uint8_t Ns)
67
{
Florian Kaltenberger's avatar
Florian Kaltenberger committed
68
  uint8_t offset = 0;
69
  if (lprime==-1)
70 71
    return(1);

72
  switch (beamforming_mode) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
73 74 75 76 77 78 79
  case 7:
    offset = (lprime==1||lprime==3)?2:0;
    if (Ncp == NORMAL){
      if ((re!=nushift+offset) && (re!=((nushift+4+offset)%12)) &&  (re!=((nushift+8+offset)%12)))
	return(1);
      /*else{
	printf("(is_no_UEspec_RS):lprime=%d, re=%d, nushift=%d, offset=%d\n",lprime, re,nushift,offset);
80
        }*/
Florian Kaltenberger's avatar
Florian Kaltenberger committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    } else {
      if ((re!=nushift+offset) && (re!=((nushift+3+offset)%12)) && (re!=((nushift+6+offset)%12)) && (re!=((nushift+9+offset)%12)))
	return(1);
    }
    break;
    
  case 8:/*ToDo (36.211 v11.3 p86)*/ /* Mapping to REs */
    if (Ncp == NORMAL){
      if ((re!=offset+1) && (re!=5+offset+1) &&  (re!=10+offset+1)) 
	return(1);
    } else { 
      if (Ns%2==0) { // even slot in a subframe
	if ((re!=offset+1) && (re!=3+offset+1) &&  (re!=6+offset+1) && (re!=9+offset+1)) 
	  return(1);
      } else {  // odd slot in a subframe
	if ((re!=offset+2) && (re!=3+offset+2) &&  (re!=6+offset+2) && (re!=9+offset+2)) 
	  return(1);
98
      }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
99 100 101 102 103 104
    }
    break;
    
  default:
    msg("is_not_UEspecRS() [dlsch_modulation.c] : ERROR, unknown beamforming_mode %d\n",beamforming_mode);
    return(-1);
105
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
106

107
  return(0);
Raymond Knopp's avatar
 
Raymond Knopp committed
108 109
}

110 111
void generate_64qam_table(void)
{
112 113 114 115

  int a,b,c,index;


116 117 118 119 120 121
  for (a=-1; a<=1; a+=2)
    for (b=-1; b<=1; b+=2)
      for (c=-1; c<=1; c+=2) {
        index = (1+a)*2 + (1+b) + (1+c)/2;
        qam64_table[index] = -a*(QAM64_n1 + b*(QAM64_n2 + (c*QAM64_n3))); // 0 1 2
      }
122 123
}

124 125
void generate_16qam_table(void)
{
126 127 128

  int a,b,index;

129 130 131 132 133
  for (a=-1; a<=1; a+=2)
    for (b=-1; b<=1; b+=2) {
      index = (1+a) + (1+b)/2;
      qam16_table[index] = -a*(QAM16_n1 + (b*QAM16_n2));
    }
134 135 136 137 138
}




139 140
void layer1prec2A(int32_t *antenna0_sample, int32_t *antenna1_sample, uint8_t precoding_index)
{
141 142 143

  switch (precoding_index) {

144 145 146
    case 0: // 1 1
      *antenna1_sample=*antenna0_sample;
      break;
147

148 149 150 151
    case 1: // 1 -1
      ((int16_t *)antenna1_sample)[0] = -((int16_t *)antenna0_sample)[0];
      ((int16_t *)antenna1_sample)[1] = -((int16_t *)antenna0_sample)[1];
      break;
152

153 154 155 156
    case 2: // 1 j
      ((int16_t *)antenna1_sample)[0] = -((int16_t *)antenna0_sample)[1];
      ((int16_t *)antenna1_sample)[1] = ((int16_t *)antenna0_sample)[0];
      break;
157

158 159 160 161
    case 3: // 1 -j
      ((int16_t *)antenna1_sample)[0] = ((int16_t *)antenna0_sample)[1];
      ((int16_t *)antenna1_sample)[1] = -((int16_t *)antenna0_sample)[0];
      break;
162 163 164
  }

  // normalize
165
  /*  ((int16_t *)antenna0_sample)[0] = (int16_t)((((int16_t *)antenna0_sample)[0]*ONE_OVER_SQRT2_Q15)>>15);
166 167
      ((int16_t *)antenna0_sample)[1] = (int16_t)((((int16_t *)antenna0_sample)[1]*ONE_OVER_SQRT2_Q15)>>15);  ((int16_t *)antenna1_sample)[0] = (int16_t)((((int16_t *)antenna1_sample)[0]*ONE_OVER_SQRT2_Q15)>>15);
      ((int16_t *)antenna1_sample)[1] = (int16_t)((((int16_t *)antenna1_sample)[1]*ONE_OVER_SQRT2_Q15)>>15);  */
168
}
169

170 171 172
uint32_t FOUR[2]={0,4};
uint32_t TWO[2]={0,2};

173
#if 0
174
int allocate_REs_in_RB_no_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                                            int **txdataF,
                                            uint32_t *jj,
                                            uint32_t *jj2,
                                            uint16_t re_offset,
                                            uint32_t symbol_offset,
                                            LTE_DL_eNB_HARQ_t *dlsch0_harq,
                                            LTE_DL_eNB_HARQ_t *dlsch1_harq,
                                            uint8_t pilots,
                                            int16_t amp,
                                            uint8_t precoder_index,
                                            int16_t *qam_table_s0,
                                            int16_t *qam_table_s1,
                                            uint32_t *re_allocated,
                                            uint8_t skip_dc,
                                            uint8_t skip_half,
                                            uint8_t lprime,
                                            uint8_t mprime,
                                            uint8_t Ns,
                                            int *P1_SHIFT,
                                            int *P2_SHIFT)
195 196
{

197
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
198 199 200 201 202 203 204 205 206
  uint8_t *x0             = dlsch0_harq->e;
  uint32_t qam16_table_offset_re = 0;
  uint32_t qam16_table_offset_im = 0;

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;

  if (skip_dc == 0) {
207
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
208 209
         re<12;
         re++,x0p+=4,tti_offset++) {
210

211 212 213 214 215 216 217 218 219
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
    }
  }
  else {
220 221
    // 1st half of PRB
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
222 223
         re<6;
         re++,x0p+=4,tti_offset++) {
224

225 226 227 228 229 230 231
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
    }
232 233
    // 2nd half of PRB
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+7;
234 235
         re<12;
         re++,x0p+=4,tti_offset++) {
236

237 238 239 240 241 242 243 244 245 246
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
    }
  }
  *re_allocated = *re_allocated + 12;
  *jj=*jj + 48;
247

248 249 250
    return(0);
}

251
int allocate_REs_in_RB_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
                                         int **txdataF,
                                         uint32_t *jj,
                                         uint32_t *jj2,
                                         uint16_t re_offset,
                                         uint32_t symbol_offset,
                                         LTE_DL_eNB_HARQ_t *dlsch0_harq,
                                         LTE_DL_eNB_HARQ_t *dlsch1_harq,
                                         uint8_t pilots,
                                         int16_t amp,
                                         uint8_t precoder_index,
                                         int16_t *qam_table_s0,
                                         int16_t *qam_table_s1,
                                         uint32_t *re_allocated,
                                         uint8_t skip_dc,
                                         uint8_t skip_half,
                                         uint8_t lprime,
                                         uint8_t mprime,
                                         uint8_t Ns,
                                         int *P1_SHIFT,
                                         int *P2_SHIFT)
272
{
273

274

275
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
276 277 278 279 280 281 282 283 284 285 286 287

  uint8_t *x0             = dlsch0_harq->e;
  uint32_t qam16_table_offset_re = 0;
  uint32_t qam16_table_offset_im = 0;

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;


  if (skip_dc == 0) {
    //    printf("pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
288
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
289 290
         re<12;
         x0p+=4) {
291

292 293 294 295 296 297 298 299 300 301 302 303
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
      //      printf("pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
304
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
305 306
         re<6;
         x0p+=4) {
307

308 309 310 311 312 313 314 315 316 317
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }

318
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+6+P1_SHIFT[6];
319 320
         re<12;
         x0p+=4) {
321

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  *re_allocated = *re_allocated + 10;
  *jj=*jj + 40;

  return(0);
}

338
int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
                                            int **txdataF,
                                            uint32_t *jj,
                                            uint32_t *jj2,
                                            uint16_t re_offset,
                                            uint32_t symbol_offset,
                                            LTE_DL_eNB_HARQ_t *dlsch0_harq,
                                            LTE_DL_eNB_HARQ_t *dlsch1_harq,
                                            uint8_t pilots,
                                            int16_t amp,
                                            uint8_t precoder_index,
                                            int16_t *qam_table_s0,
                                            int16_t *qam_table_s1,
                                            uint32_t *re_allocated,
                                            uint8_t skip_dc,
                                            uint8_t skip_half,
                                            uint8_t lprime,
                                            uint8_t mprime,
                                            uint8_t Ns,
                                            int *P1_SHIFT,
                                            int *P2_SHIFT)
359 360
{

361
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
362 363 364 365 366 367 368 369 370 371 372

  uint8_t *x0             = dlsch0_harq->e;
  uint32_t qam64_table_offset_re = 0;
  uint32_t qam64_table_offset_im = 0;

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;

  if (skip_dc == 0) {

373
    x0p=&x0[*jj],tti_offset=symbol_offset+re_offset;
374

375
    /*    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
376 377
         re<12;
         re+=4,x0p+=24,tti_offset+=4) {*/
378

379 380
      qam64_table_offset_re=(x0p[0]<<2)|(x0p[2]<<1)|x0p[4];
      qam64_table_offset_im=(x0p[1]<<2)|(x0p[3]<<1)|x0p[5];
381 382
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
383

384 385
      qam64_table_offset_re=(x0p[6]<<2)|(x0p[8]<<1)|x0p[10];
      qam64_table_offset_im=(x0p[7]<<2)|(x0p[9]<<1)|x0p[11];
386 387 388
      ((int16_t *)&txdataF[0][tti_offset])[2]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[3]=qam_table_s0[qam64_table_offset_im];

389 390
      qam64_table_offset_re=(x0p[12]<<2)|(x0p[14]<<1)|x0p[16];
      qam64_table_offset_im=(x0p[13]<<2)|(x0p[15]<<1)|x0p[17];
391 392 393
      ((int16_t *)&txdataF[0][tti_offset])[4]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[5]=qam_table_s0[qam64_table_offset_im];

394 395
      qam64_table_offset_re=(x0p[18]<<2)|(x0p[20]<<1)|x0p[22];
      qam64_table_offset_im=(x0p[19]<<2)|(x0p[21]<<1)|x0p[23];
396 397
      ((int16_t *)&txdataF[0][tti_offset])[6]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[7]=qam_table_s0[qam64_table_offset_im];
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

      qam64_table_offset_re=(x0p[24]<<2)|(x0p[26]<<1)|x0p[28];
      qam64_table_offset_im=(x0p[25]<<2)|(x0p[27]<<1)|x0p[29];
      ((int16_t *)&txdataF[0][tti_offset])[8]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[9]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[30]<<2)|(x0p[32]<<1)|x0p[34];
      qam64_table_offset_im=(x0p[31]<<2)|(x0p[33]<<1)|x0p[35];
      ((int16_t *)&txdataF[0][tti_offset])[10]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[11]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[36]<<2)|(x0p[38]<<1)|x0p[40];
      qam64_table_offset_im=(x0p[37]<<2)|(x0p[39]<<1)|x0p[41];
      ((int16_t *)&txdataF[0][tti_offset])[12]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[13]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[42]<<2)|(x0p[44]<<1)|x0p[46];
      qam64_table_offset_im=(x0p[43]<<2)|(x0p[45]<<1)|x0p[47];
      ((int16_t *)&txdataF[0][tti_offset])[14]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[15]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[48]<<2)|(x0p[50]<<1)|x0p[52];
      qam64_table_offset_im=(x0p[49]<<2)|(x0p[51]<<1)|x0p[53];
      ((int16_t *)&txdataF[0][tti_offset])[16]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[17]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[54]<<2)|(x0p[56]<<1)|x0p[58];
      qam64_table_offset_im=(x0p[55]<<2)|(x0p[57]<<1)|x0p[59];
      ((int16_t *)&txdataF[0][tti_offset])[18]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[19]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[60]<<2)|(x0p[62]<<1)|x0p[64];
      qam64_table_offset_im=(x0p[61]<<2)|(x0p[63]<<1)|x0p[65];
      ((int16_t *)&txdataF[0][tti_offset])[20]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[21]=qam_table_s0[qam64_table_offset_im];

      qam64_table_offset_re=(x0p[66]<<2)|(x0p[68]<<1)|x0p[70];
      qam64_table_offset_im=(x0p[67]<<2)|(x0p[69]<<1)|x0p[71];
      ((int16_t *)&txdataF[0][tti_offset])[22]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[23]=qam_table_s0[qam64_table_offset_im];


      //    }
441 442
  }
  else {
443
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
444 445
         re<6;
         re++,x0p+=6,tti_offset++) {
446

447 448 449 450 451 452 453 454 455 456
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
    }

457
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+7;
458 459
         re<12;
         re++,x0p+=6,tti_offset++) {
460

461 462 463 464 465 466 467 468 469 470 471 472 473
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
    }
  }

  *re_allocated = *re_allocated + 12;
  *jj=*jj + 72;
474

475 476 477
  return(0);
}

478
int allocate_REs_in_RB_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
                                         int **txdataF,
                                         uint32_t *jj,
                                         uint32_t *jj2,
                                         uint16_t re_offset,
                                         uint32_t symbol_offset,
                                         LTE_DL_eNB_HARQ_t *dlsch0_harq,
                                         LTE_DL_eNB_HARQ_t *dlsch1_harq,
                                         uint8_t pilots,
                                         int16_t amp,
                                         uint8_t precoder_index,
                                         int16_t *qam_table_s0,
                                         int16_t *qam_table_s1,
                                         uint32_t *re_allocated,
                                         uint8_t skip_dc,
                                         uint8_t skip_half,
                                         uint8_t lprime,
                                         uint8_t mprime,
                                         uint8_t Ns,
                                         int *P1_SHIFT,
                                         int *P2_SHIFT)
499
{
500

501

502
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
503 504 505 506 507 508 509 510 511 512 513 514

  uint8_t *x0             = dlsch0_harq->e;
  uint32_t qam64_table_offset_re = 0;
  uint32_t qam64_table_offset_im = 0;

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;


  if (skip_dc == 0) {
    //    printf("pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
515
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
516 517
         re<12;
         x0p+=6) {
518

519 520 521 522 523 524 525 526 527 528 529 530 531 532
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
      //      printf("pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
533
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
534 535
         re<6;
         x0p+=6) {
536

537 538 539 540 541 542 543 544 545 546 547 548
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }

549
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+6+P1_SHIFT[6];
550 551
         re<12;
         x0p+=6) {
552

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  *re_allocated = *re_allocated + 10;
  *jj=*jj + 60;

  return(0);
}
570
#endif
571

572
int allocate_REs_in_RB(PHY_VARS_eNB *phy_vars_eNB,
573
                       int32_t **txdataF,
574 575
                       uint32_t *jj,
                       uint32_t *jj2,
576
		       uint16_t rb,
577 578 579 580 581 582 583 584 585 586 587
                       uint16_t re_offset,
                       uint32_t symbol_offset,
                       LTE_DL_eNB_HARQ_t *dlsch0_harq,
                       LTE_DL_eNB_HARQ_t *dlsch1_harq,
                       uint8_t pilots,
                       int16_t amp,
                       uint8_t precoder_index,
                       int16_t *qam_table_s0,
                       int16_t *qam_table_s1,
                       uint32_t *re_allocated,
                       uint8_t skip_dc,
588
                       uint8_t skip_half,
589 590 591 592
                       uint8_t lprime,
                       uint8_t mprime,
                       uint8_t Ns,
                       int *P1_SHIFT,
593 594
                       int *P2_SHIFT,
		       uint8_t nscid)
595
{
596

597
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
598
  MIMO_mode_t mimo_mode = -1;
599

600 601
  // first codeword
  uint8_t *x0 = NULL;
602
  int first_layer0 = -1; //= dlsch0_harq->first_layer;
Cedric Roux's avatar
Cedric Roux committed
603
  int Nlayers0 = -1; //  = dlsch0_harq->Nlayers;
604
  uint8_t mod_order0=0; // = get_Qm(dlsch0_harq->mcs);
605
  uint8_t precoder_index1;
606

607
  // second codeword (TM3-4, TM8-10)
Raymond Knopp's avatar
 
Raymond Knopp committed
608
  uint8_t *x1=NULL;
609 610 611 612
  int Nlayers1=-1;
  int first_layer1=-1;
  uint8_t mod_order1=0; //=2;
  uint8_t precoder_index0;
613 614

  int use2ndpilots = (frame_parms->mode1_flag==1)?1:0;
615

616
  uint32_t tti_offset; //,aa;
617 618 619 620 621
  uint8_t re;
  uint8_t qam64_table_offset_re = 0;
  uint8_t qam64_table_offset_im = 0;
  uint8_t qam16_table_offset_re = 0;
  uint8_t qam16_table_offset_im = 0;
622 623 624 625 626 627 628 629 630 631 632
  uint8_t qam64_table_offset_re0 = 0;
  uint8_t qam64_table_offset_im0 = 0;
  uint8_t qam16_table_offset_re0 = 0;
  uint8_t qam16_table_offset_im0 = 0;
  uint8_t qam64_table_offset_re1 = 0;
  uint8_t qam64_table_offset_im1 = 0;
  uint8_t qam16_table_offset_re1 = 0;
  uint8_t qam16_table_offset_im1 = 0;
  int16_t xx0_re,xx1_re;
  int16_t xx0_im,xx1_im;

633 634
  int16_t gain_lin_QPSK;//,gain_lin_16QAM1,gain_lin_16QAM2;
  int16_t re_off=re_offset;
635

636 637 638
  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;
  int16_t tmp_amp=amp;
639
  int s=1;
640
  int mprime2 = mprime,ind,ind_dword,ind_qpsk_symb,p,w;
641
  int Wbar_NCP[8][4] = {{1,1,1,1},{1,-1,1,-1},{1,1,1,1},{1,-1,1,-1},{1,1,-1,-1},{-1,-1,1,1},{1,-1,-1,1},{-1,1,1,-1}} ;
642
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
643

644
  int32_t qpsk[4],nqpsk[4],*qpsk_p;
645 646 647
  ((int16_t *)&qpsk[0])[0] = gain_lin_QPSK;
  ((int16_t *)&qpsk[0])[1] = gain_lin_QPSK;
  ((int16_t *)&qpsk[1])[0] = -gain_lin_QPSK;
648 649 650 651
  ((int16_t *)&qpsk[1])[1] = gain_lin_QPSK;
  ((int16_t *)&qpsk[2])[0] = gain_lin_QPSK;
  ((int16_t *)&qpsk[2])[1] = -gain_lin_QPSK;
  ((int16_t *)&qpsk[3])[0] = -gain_lin_QPSK;
652
  ((int16_t *)&qpsk[3])[1] = -gain_lin_QPSK;
653

654 655 656 657 658 659 660 661 662
  ((int16_t *)&nqpsk[0])[0] = -gain_lin_QPSK;
  ((int16_t *)&nqpsk[0])[1] = -gain_lin_QPSK;
  ((int16_t *)&nqpsk[1])[0] = gain_lin_QPSK;
  ((int16_t *)&nqpsk[1])[1] = -gain_lin_QPSK;
  ((int16_t *)&nqpsk[2])[0] = -gain_lin_QPSK;
  ((int16_t *)&nqpsk[2])[1] = gain_lin_QPSK;
  ((int16_t *)&nqpsk[3])[0] = gain_lin_QPSK;
  ((int16_t *)&nqpsk[3])[1] = gain_lin_QPSK;

663
  if (dlsch0_harq && (dlsch0_harq->status == ACTIVE) && dlsch1_harq && (dlsch1_harq->status == ACTIVE)) { //this is for TM3, TM4, TM8
664 665 666 667 668 669

    x0 = dlsch0_harq->e;
    mimo_mode = dlsch0_harq->mimo_mode;
    first_layer0 = dlsch0_harq->first_layer;
    Nlayers0 = dlsch0_harq->Nlayers;
    mod_order0 = get_Qm(dlsch0_harq->mcs);
670
    x1             = dlsch1_harq->e;
Raymond Knopp's avatar
 
Raymond Knopp committed
671
    // Fill these in later for TM8-10
672 673
    Nlayers1       = dlsch1_harq->Nlayers;
    first_layer1   = dlsch1_harq->first_layer;
674 675
    mod_order1     = get_Qm(dlsch1_harq->mcs);

676
  } else if (dlsch0_harq && (dlsch0_harq->status == ACTIVE)){ //This is for SIS0 TM1, TM6, etc
677 678 679 680 681 682 683

    x0 = dlsch0_harq->e;
    mimo_mode = dlsch0_harq->mimo_mode;
    first_layer0 = dlsch0_harq->first_layer;
    Nlayers0 = dlsch0_harq->Nlayers;
    mod_order0 = get_Qm(dlsch0_harq->mcs);

684
  } else if (dlsch1_harq && (dlsch1_harq->status == ACTIVE)){ // This is for TM4 retransmission
685 686 687 688 689 690 691

    x0 = dlsch1_harq->e;
    mimo_mode = dlsch1_harq->mimo_mode;
    first_layer0 = dlsch1_harq->first_layer;
    Nlayers0 = dlsch1_harq->Nlayers;
    mod_order0 = get_Qm(dlsch1_harq->mcs);

692
  }
693

694
#ifdef DEBUG_DLSCH_MODULATION
Florian Kaltenberger's avatar
Florian Kaltenberger committed
695
    LOG_D(PHY,"mimo_mode %d, first_layer0 %d, NLayers0 %d, first_layer1 %d, NLayers1 %d\n",mimo_mode,first_layer0,Nlayers0,first_layer1,Nlayers1);
696

Florian Kaltenberger's avatar
Florian Kaltenberger committed
697
    LOG_D(PHY,"allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d\n",mod_order0,symbol_offset,re_offset,skip_dc,skip_half,*jj, x0[*jj], x0[1+*jj]);
698
#endif
699 700 701 702

  first_re=0;
  last_re=12;

703
  if (skip_half==1)
704 705 706
    last_re=6;
  else if (skip_half==2)
    first_re=6;
707

708

709
  for (re=first_re; re<last_re; re++) {
710
  // printf("element %d precoder_index for allocation %d\n",re, precoder_index );
711

712 713
    if ((skip_dc == 1) && (re==6))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
714

715
    tti_offset = symbol_offset + re_off + re;
716

lukashov's avatar
lukashov committed
717
      //check that RE is not from Cell-specific RS
Raymond Knopp's avatar
 
Raymond Knopp committed
718

719
    if (is_not_pilot(pilots,re,frame_parms->nushift,use2ndpilots)==1) {
lukashov's avatar
lukashov committed
720
      //printf("re %d (jj %d)\n",re,*jj);
Raymond Knopp's avatar
 
Raymond Knopp committed
721

722

723
      if (mimo_mode == SISO) {  //SISO mapping
724 725 726 727 728
        *re_allocated = *re_allocated + 1;

        switch (mod_order0) {
        case 2:  //QPSK

729 730 731

          //printf("re %d %d(%d) : %d,%d => ",re,tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
          ((int16_t*)&txdataF[0][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
732 733 734

          *jj = *jj + 1;

735
          ((int16_t*)&txdataF[0][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766

          *jj = *jj + 1;

          break;

        case 4:  //16QAM

          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;

          *jj=*jj+1;


          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;

          *jj=*jj+1;

767 768
          ((int16_t *)&txdataF[0][tti_offset])[0]+=qam_table_s0[qam16_table_offset_re];
          ((int16_t *)&txdataF[0][tti_offset])[1]+=qam_table_s0[qam16_table_offset_im];
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807

          break;

        case 6:  //64QAM


          qam64_table_offset_re = 0;
          qam64_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam64_table_offset_re+=4;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam64_table_offset_im+=4;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam64_table_offset_re+=2;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam64_table_offset_im+=2;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam64_table_offset_re+=1;

          *jj=*jj+1;

          if (x0[*jj] == 1)
            qam64_table_offset_im+=1;

          *jj=*jj+1;

808 809
          ((int16_t *)&txdataF[0][tti_offset])[0]+=qam_table_s0[qam64_table_offset_re];
          ((int16_t *)&txdataF[0][tti_offset])[1]+=qam_table_s0[qam64_table_offset_im];
810 811 812 813

          break;

        }
814 815
      }

816 817
      else if (mimo_mode == ALAMOUTI) {
        *re_allocated = *re_allocated + 1;
818

819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);


        switch (mod_order0) {
        case 2:  //QPSK

          // first antenna position n -> x0

          ((int16_t*)&tmp_sample1)[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj=*jj+1;
          ((int16_t*)&tmp_sample1)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj=*jj+1;

          // second antenna position n -> -x1*

          ((int16_t*)&tmp_sample2)[0] = (x0[*jj]==1) ? (gain_lin_QPSK) : -gain_lin_QPSK;
          *jj=*jj+1;
          ((int16_t*)&tmp_sample2)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj=*jj+1;

839
	  //gain_lin_QPSK (=amp/sqrt(2)) is already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
lukashov's avatar
lukashov committed
840
          // normalization for 2 tx antennas
841 842 843 844
          ((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]));
          ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]));
          ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]));
          ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]));
845

lukashov's avatar
lukashov committed
846
        break;
847

lukashov's avatar
lukashov committed
848
        case 4:  //16QAM
849 850

          // Antenna 0 position n
lukashov's avatar
lukashov committed
851 852
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;
853

lukashov's avatar
lukashov committed
854 855 856 857 858 859
          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;
          *jj=*jj+1;
860 861


lukashov's avatar
lukashov committed
862 863 864 865 866 867
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
868

869 870 871 872 873
          //((int16_t *)&txdataF[0][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
          //((int16_t *)&txdataF[0][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
	  //gain_lin_QPSK (=amp/sqrt(2)) is already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[0][tti_offset])[0]+=(qam_table_s0[qam16_table_offset_re]);
	  ((int16_t *)&txdataF[0][tti_offset])[1]+=(qam_table_s0[qam16_table_offset_im]);
874

lukashov's avatar
lukashov committed
875
          // Antenna 1 position n Real part -> -x1*
876

lukashov's avatar
lukashov committed
877 878 879 880 881 882 883 884 885
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;
          *jj=*jj+1;
886 887


lukashov's avatar
lukashov committed
888 889 890 891 892 893
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
894

895 896 897 898 899
          //((int16_t *)&txdataF[1][tti_offset])[0]+=-(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
          //((int16_t *)&txdataF[1][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
	  //qam_table_s0 already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[1][tti_offset])[0]+=-(qam_table_s0[qam16_table_offset_re]);
	  ((int16_t *)&txdataF[1][tti_offset])[1]+=(qam_table_s0[qam16_table_offset_im]);
900

901 902
         //((int16_t *)&txdataF[1][tti_offset])[0]+=-qam_table_s0[qam16_table_offset_re];
         //((int16_t *)&txdataF[1][tti_offset])[1]+=qam_table_s0[qam16_table_offset_im];
903 904

          break;
lukashov's avatar
lukashov committed
905 906

        case 6:   // 64-QAM
907

lukashov's avatar
lukashov committed
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
          // Antenna 0
          qam64_table_offset_re = 0;
          qam64_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam64_table_offset_re+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=1;
          *jj=*jj+1;
930

931 932
          //((int16_t *)&txdataF[0][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
          //((int16_t *)&txdataF[0][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
933 934 935 936
	  //qam_table_s0 already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[0][tti_offset])[0]+=(qam_table_s0[qam64_table_offset_re]);
	  ((int16_t *)&txdataF[0][tti_offset])[1]+=(qam_table_s0[qam64_table_offset_im]);

937

lukashov's avatar
lukashov committed
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
          // Antenna 1 => -x1*
          qam64_table_offset_re = 0;
          qam64_table_offset_im = 0;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=1;
          *jj=*jj+1;
959

960 961
          //((int16_t *)&txdataF[1][tti_offset])[0]+=-(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
          //((int16_t *)&txdataF[1][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
962 963 964 965
	  //qam_table_s0 already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[1][tti_offset])[0]+=-(qam_table_s0[qam64_table_offset_re]);
	  ((int16_t *)&txdataF[1][tti_offset])[1]+=(qam_table_s0[qam64_table_offset_im]);

966

967
          break;
lukashov's avatar
lukashov committed
968
        }
969
  // fill in the rest of the ALAMOUTI precoding
lukashov's avatar
lukashov committed
970 971 972 973 974 975 976 977 978 979 980 981
        if (is_not_pilot(pilots,re + 1,frame_parms->nushift,use2ndpilots)==1) {
          ((int16_t *)&txdataF[0][tti_offset+1])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+1])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+1])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+1])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        }
        else {
          ((int16_t *)&txdataF[0][tti_offset+2])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+2])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+2])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+2])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        }
982
      }
983
      else if (mimo_mode == LARGE_CDD) {
984

lukashov's avatar
lukashov committed
985 986
        *re_allocated = *re_allocated + 1;

987
        if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
          switch (mod_order0) {

          default:
            LOG_E(PHY,"Unknown mod_order0 %d\n",mod_order0);
            xx0_re=xx0_im=0;
            break;

          case 2:  //QPSK
            //printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
            xx0_re = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj = *jj + 1;
            xx0_im = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj = *jj + 1;
            //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
            break;
1003

lukashov's avatar
lukashov committed
1004
          case 4:  //16QAM
1005

lukashov's avatar
lukashov committed
1006 1007 1008 1009 1010 1011 1012 1013
            qam16_table_offset_re0 = 0;
            qam16_table_offset_im0 = 0;
            if (x0[*jj] == 1)
              qam16_table_offset_re0+=2;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam16_table_offset_im0+=2;
            *jj=*jj+1;
1014

lukashov's avatar
lukashov committed
1015 1016 1017 1018 1019 1020
            if (x0[*jj] == 1)
              qam16_table_offset_re0+=1;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam16_table_offset_im0+=1;
            *jj=*jj+1;
1021

lukashov's avatar
lukashov committed
1022 1023 1024 1025
            xx0_re = qam_table_s0[qam16_table_offset_re0];
            xx0_im = qam_table_s0[qam16_table_offset_im0];

            break;
1026

lukashov's avatar
lukashov committed
1027
          case 6:  //64QAM
1028 1029


lukashov's avatar
lukashov committed
1030 1031
            qam64_table_offset_re0 = 0;
            qam64_table_offset_im0 = 0;
1032

lukashov's avatar
lukashov committed
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
            if (x0[*jj] == 1)
              qam64_table_offset_re0+=4;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam64_table_offset_im0+=4;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam64_table_offset_re0+=2;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam64_table_offset_im0+=2;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam64_table_offset_re0+=1;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam64_table_offset_im0+=1;
            *jj=*jj+1;

            xx0_re = qam_table_s0[qam64_table_offset_re0];
            xx0_im = qam_table_s0[qam64_table_offset_im0];

            break;
1056

lukashov's avatar
lukashov committed
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
          }

          switch (mod_order1) {

          default:
            LOG_E(PHY,"Unknown mod_order1 %d\n",mod_order1);
            xx1_re=xx1_im=0;
            break;

          case 2:  //QPSK
            //printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1068
            xx1_re = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1069
            *jj2 = *jj2 + 1;
1070
            xx1_im = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1071 1072 1073
            *jj2 = *jj2 + 1;
            //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
            break;
1074

lukashov's avatar
lukashov committed
1075
          case 4:  //16QAM
1076

lukashov's avatar
lukashov committed
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
            qam16_table_offset_re1 = 0;
            qam16_table_offset_im1 = 0;
            if (x1[*jj2] == 1)
              qam16_table_offset_re1+=2;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam16_table_offset_im1+=2;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam16_table_offset_re1+=1;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam16_table_offset_im1+=1;
            *jj2 = *jj2 + 1;

            xx1_re = qam_table_s1[qam16_table_offset_re1];
            xx1_im = qam_table_s1[qam16_table_offset_im1];

            break;
1096

lukashov's avatar
lukashov committed
1097
          case 6:  //64QAM
1098

lukashov's avatar
lukashov committed
1099 1100
            qam64_table_offset_re1 = 0;
            qam64_table_offset_im1 = 0;
1101

lukashov's avatar
lukashov committed
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
            if (x1[*jj2] == 1)
              qam64_table_offset_re1+=4;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im1+=4;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam64_table_offset_re1+=2;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im1+=2;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam64_table_offset_re1+=1;
            *jj2 = *jj2 + 1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im1+=1;
            *jj2 = *jj2 + 1;

            xx1_re = qam_table_s1[qam64_table_offset_re1];
            xx1_im = qam_table_s1[qam64_table_offset_im1];

            break;
1125

lukashov's avatar
lukashov committed
1126 1127 1128 1129 1130 1131
          }

          // This implements the Large CDD precoding for 2 TX antennas
          // -  -        -    -  -         -  -     -  -  -       -              -
          //| y0 |      | 1  0 || 1    0    || 1   1 || x0 |     |        x0 + x1 |
          //| y1 | = .5 | 0  1 || 0  (-1)^i || 1  -1 || x1 | = .5| (-1)^i(x0 - x1)|
1132
          // -  -        -    -  -         -  -     -  -  -       -
lukashov's avatar
lukashov committed
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
          // Note: Factor .5 is accounted for in amplitude when calling this function
          ((int16_t *)&txdataF[0][tti_offset])[0]+=((xx0_re+xx1_re)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[0]+=(s*((xx0_re-xx1_re)>>1));
          ((int16_t *)&txdataF[0][tti_offset])[1]+=((xx0_im+xx1_im)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[1]+=(s*((xx0_im-xx1_im)>>1));
          /*
          printf("CDD: xx0 (%d,%d), xx1(%d,%d), s(%d), txF[0] (%d,%d), txF[1] (%d,%d)\n",
           xx0_re,xx0_im,xx1_re,xx1_im, s, ((int16_t *)&txdataF[0][tti_offset])[0],((int16_t *)&txdataF[0][tti_offset])[1],
           ((int16_t *)&txdataF[1][tti_offset])[0],((int16_t *)&txdataF[1][tti_offset])[1]);
          */
          // s alternates +1/-1 for each RE
          s = -s;
        }
1146
      }
1147
      else if ((mimo_mode >= UNIFORM_PRECODING11)&&(mimo_mode <= PUSCH_PRECODING1)) {
lukashov's avatar
lukashov committed
1148
  // this is for transmission modes 5-6 (1 layer)
1149
        *re_allocated = *re_allocated + 1;
lukashov's avatar
lukashov committed
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);

        switch (mod_order0) {
        case 2:

          ((int16_t*)&tmp_sample1)[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj = *jj + 1;
          ((int16_t*)&tmp_sample1)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj = *jj + 1;

          //normalization for 2 tx antennas
1161
          /*((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1162 1163
          ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);

1164
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1165 1166 1167
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
            ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178
          }*/

          // We remove ONE_OVER_SQRT2_Q15 that was coming from precoder, as now it applied in computation sqrt_rho_a, sqrt_rho_b, same in the receiver in precoder function

          ((int16_t*)&txdataF[0][tti_offset])[0] += ((int16_t*)&tmp_sample1)[0];
          ((int16_t*)&txdataF[0][tti_offset])[1] += ((int16_t*)&tmp_sample1)[1];

          if (frame_parms->nb_antenna_ports_eNB == 2) {
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
1179 1180 1181
          }

          break;
1182

lukashov's avatar
lukashov committed
1183
        case 4:
1184

lukashov's avatar
lukashov committed
1185 1186 1187 1188 1189 1190 1191 1192 1193
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;
          *jj=*jj+1;
1194 1195


lukashov's avatar
lukashov committed
1196 1197 1198 1199 1200 1201
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
1202 1203


lukashov's avatar
lukashov committed
1204 1205 1206
           ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s0[qam16_table_offset_re]));
           ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s0[qam16_table_offset_im]));

1207 1208
           ((int16_t *)&txdataF[0][tti_offset])[0] += ((int16_t*)&tmp_sample1)[0];
           ((int16_t *)&txdataF[0][tti_offset])[1] += ((int16_t*)&tmp_sample1)[1];
1209

lukashov's avatar
lukashov committed
1210 1211
          if (frame_parms->nb_antennas_tx == 2) {
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1212 1213
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
1214 1215 1216
          }

          break;
1217

lukashov's avatar
lukashov committed
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
        case 6:

          qam64_table_offset_re = 0;
          qam64_table_offset_im = 0;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=1;
          *jj=*jj+1;
1240

lukashov's avatar
lukashov committed
1241 1242 1243
          ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s0[qam64_table_offset_re]));
          ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s0[qam64_table_offset_im]));

1244 1245
          ((int16_t *)&txdataF[0][tti_offset])[0] += ((int16_t*)&tmp_sample1)[0];
          ((int16_t *)&txdataF[0][tti_offset])[1] += ((int16_t*)&tmp_sample1)[1];
1246

1247
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1248
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1249 1250
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
1251
          }
1252

lukashov's avatar
lukashov committed
1253 1254
          break;
        }
1255
      }
1256
      else if ((mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1)&&(mimo_mode <= DUALSTREAM_PUSCH_PRECODING)) {
lukashov's avatar
lukashov committed
1257
  // this is for transmission mode 4 (1 layer)
1258
        *re_allocated = *re_allocated + 1;
lukashov's avatar
lukashov committed
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281

        if (precoder_index==0) {
          precoder_index0 = 0; //[1 1]
          precoder_index1 = 1; //[1 -1]
        }
        else if (precoder_index==1) {
          precoder_index0 = 2; //[1 j]
          precoder_index1 = 3; //[1 -j]
        }
        else {
         printf("problem with precoder in TM4\n");
          return(-1);
        }

        switch (mod_order0) {
        case 2:

          ((int16_t*)&tmp_sample1)[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj = *jj + 1;
          ((int16_t*)&tmp_sample1)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
          *jj = *jj + 1;

          //normalization for 2 tx antennas
1282 1283 1284 1285 1286
          // We remove ONE_OVER_2_Q15 that was coming from precoder,
          //as now it applied in computation sqrt_rho_a, sqrt_rho_b, same in the receiver in precoder function
          //ONE_OVER_SQRT2_Q15 remains from it
          ((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
          ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1287 1288

          //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1289

1290
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1291
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1292 1293
            ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1294 1295 1296
          }

        break;
1297

lukashov's avatar
lukashov committed
1298
        case 4:
1299

lukashov's avatar
lukashov committed
1300 1301 1302 1303 1304 1305 1306 1307 1308
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;
          *jj=*jj+1;
1309

lukashov's avatar
lukashov committed
1310 1311 1312 1313 1314 1315
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
1316

lukashov's avatar
lukashov committed
1317 1318
           ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s0[qam16_table_offset_re]));
           ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s0[qam16_table_offset_im]));
1319 1320 1321 1322 1323 1324

           // We remove ONE_OVER_2_Q15 that was coming from precoder,
           //as now it applied in computation sqrt_rho_a, sqrt_rho_b, same in the receiver in precoder function
           //ONE_OVER_SQRT2_Q15 remains from it
           ((int16_t *)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
           ((int16_t *)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
1325

1326
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1327
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1328 1329
            ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1330 1331 1332
          }

          break;
1333

lukashov's avatar
lukashov committed
1334
        case 6:
1335

lukashov's avatar
lukashov committed
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
          qam64_table_offset_re = 0;
          qam64_table_offset_im = 0;

          if (x0[*jj] == 1)
            qam64_table_offset_re+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=4;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam64_table_offset_im+=1;
          *jj=*jj+1;
1357

lukashov's avatar
lukashov committed
1358 1359
          ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s0[qam64_table_offset_re]));
          ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s0[qam64_table_offset_im]));
1360 1361
          ((int16_t *)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
          ((int16_t *)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
1362

1363 1364 1365 1366
          if (frame_parms->nb_antennas_tx == 2) {
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
            ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1367
          }
1368

lukashov's avatar
lukashov committed
1369 1370
          break;
        }
1371

lukashov's avatar
lukashov committed
1372 1373
        if (dlsch1_harq) {
          switch (mod_order1) {
1374

lukashov's avatar
lukashov committed
1375 1376 1377 1378 1379 1380 1381 1382
          case 2:

            ((int16_t*)&tmp_sample1)[0] = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj2 = *jj2 + 1;
            ((int16_t*)&tmp_sample1)[1] = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj2 = *jj2 + 1;

            //normalization for 2 tx antennas
1383 1384
            ((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1385

1386
            if (frame_parms->nb_antenna_ports_eNB== 2) {
lukashov's avatar
lukashov committed
1387
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1388 1389
              ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
              ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1390 1391 1392
            }

            break;
1393

lukashov's avatar
lukashov committed
1394
          case 4:
1395

lukashov's avatar
lukashov committed
1396 1397 1398 1399 1400 1401 1402 1403 1404
            qam16_table_offset_re = 0;
            qam16_table_offset_im = 0;

            if (x1[*jj2] == 1)
              qam16_table_offset_re+=2;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam16_table_offset_im+=2;
            *jj2=*jj2+1;
1405 1406


lukashov's avatar
lukashov committed
1407 1408 1409 1410 1411 1412
            if (x1[*jj2] == 1)
              qam16_table_offset_re+=1;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam16_table_offset_im+=1;
            *jj2=*jj2+1;
1413

lukashov's avatar
lukashov committed
1414 1415
             ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s1[qam16_table_offset_re]));
             ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s1[qam16_table_offset_im]));
1416 1417
             ((int16_t *)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
             ((int16_t *)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
1418

1419
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1420
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1421 1422
              ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
              ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1423 1424 1425
            }

            break;
1426

lukashov's avatar
lukashov committed
1427
          case 6:
1428

lukashov's avatar
lukashov committed
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
            qam64_table_offset_re = 0;
            qam64_table_offset_im = 0;
            if (x1[*jj2] == 1)
              qam64_table_offset_re+=4;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im+=4;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam64_table_offset_re+=2;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im+=2;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam64_table_offset_re+=1;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam64_table_offset_im+=1;
            *jj2=*jj2+1;
1449

lukashov's avatar
lukashov committed
1450 1451
            ((int16_t*)&tmp_sample1)[0] = (int16_t)((qam_table_s1[qam64_table_offset_re]));
            ((int16_t*)&tmp_sample1)[1] = (int16_t)((qam_table_s1[qam64_table_offset_im]));
1452 1453
            ((int16_t *)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
            ((int16_t *)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);
1454

1455
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1456
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1457 1458
              ((int16_t*)&txdataF[1][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample2)[0]*ONE_OVER_SQRT2_Q15)>>15);
              ((int16_t*)&txdataF[1][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample2)[1]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1459
            }
1460

lukashov's avatar
lukashov committed
1461
            break;
1462

lukashov's avatar
lukashov committed
1463 1464
          }
        }
1465
      }
1466

1467

1468
      if (mimo_mode == ALAMOUTI) {
1469 1470 1471 1472 1473 1474 1475
        re++;  // adjacent carriers are taken care of by precoding
        *re_allocated = *re_allocated + 1;

        if (is_not_pilot(pilots,re,frame_parms->nushift,use2ndpilots)==0) {
          re++;
          *re_allocated = *re_allocated + 1;
        }
1476
      }
1477

1478 1479 1480
      if (mimo_mode == TM7) {
        *re_allocated = *re_allocated + 1;

1481
        if (is_not_UEspecRS(lprime,re,frame_parms->Nid_cell%3,frame_parms->Ncp,7,Ns)) {
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540

          switch (mod_order0){
            case 2:  //QPSK

              ((int16_t*)&txdataF[5][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
              *jj = *jj + 1;
              ((int16_t*)&txdataF[5][tti_offset])[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
              *jj = *jj + 1;

              //printf("%d(%d) : %d,%d =>
              //",tti_offset,*jj,((int16_t*)&tmp_sample1)[0],((int16_t*)&tmp_sample1)[1]);
              break;

            case 4:  //16QAM

              qam16_table_offset_re = 0;
              qam16_table_offset_im = 0;

              if (x0[*jj] == 1)
                qam16_table_offset_re+=2;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam16_table_offset_im+=2;

              *jj=*jj+1;


              if (x0[*jj] == 1)
                qam16_table_offset_re+=1;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam16_table_offset_im+=1;

              *jj=*jj+1;

              ((int16_t*)&txdataF[5][tti_offset])[0] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
              ((int16_t*)&txdataF[5][tti_offset])[1] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);

              break;

            case 6:  //64QAM


              qam64_table_offset_re = 0;
              qam64_table_offset_im = 0;

              if (x0[*jj] == 1)
                qam64_table_offset_re+=4;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam64_table_offset_im+=4;

              *jj=*jj+1;
Raymond Knopp's avatar
 
Raymond Knopp committed
1541

1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
              if (x0[*jj] == 1)
                qam64_table_offset_re+=2;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam64_table_offset_im+=2;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam64_table_offset_re+=1;

              *jj=*jj+1;

              if (x0[*jj] == 1)
                qam64_table_offset_im+=1;

              *jj=*jj+1;

              ((int16_t*)&txdataF[5][tti_offset])[0] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
              ((int16_t*)&txdataF[5][tti_offset])[1] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);

              break;

          }
        } else {
          //precoding UE spec RS
          //printf("precoding UE spec RS\n");

          ind = 3*lprime*dlsch0_harq->nb_rb+mprime2;
          ind_dword = ind>>4;
          ind_qpsk_symb = ind&0xf;

          txdataF[5][tti_offset] = qpsk[(phy_vars_eNB->lte_gold_uespec_port5_table[0][Ns][ind_dword]>>(2*ind_qpsk_symb))&3];
          mprime2++;

        }
Xiwen JIANG's avatar
Xiwen JIANG committed
1580

1581
      } else if (mimo_mode == TM8) { //TM8,TM9,TM10
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1582 1583
        *re_allocated = *re_allocated + 1;

1584 1585
	// TODO: integrate second codeword!
	// in TM8, Nlayers is alwyas 1
1586
        if (is_not_UEspecRS(lprime,re,frame_parms->nushift,frame_parms->Ncp,8,Ns)) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1587 1588

	  //LOG_D(PHY,"TM8 tti_offset %d, jj %d, jj2 %d, x0 %p, x1 %p\n",tti_offset,*jj,*jj2,x0,x1);
1589
	  /*
1590 1591
          switch (mod_order0) {
          case 2:  //QPSK
Raymond Knopp's avatar
 
Raymond Knopp committed
1592

1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603
	    if (x0 && Nlayers0==1) {
	      ((int16_t*)&txdataF[first_layer0][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
	      *jj = *jj + 1;
	      ((int16_t*)&txdataF[first_layer0][tti_offset])[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
	      *jj = *jj + 1;
	    }
	    if (x1 && Nlayers1==1) {
	      ((int16_t*)&txdataF[first_layer1][tti_offset])[0] = (x1[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
	      *jj2 = *jj2 + 1;
	      ((int16_t*)&txdataF[first_layer1][tti_offset])[1] = (x1[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
	      *jj2 = *jj2 + 1;
1604
            }
Raymond Knopp's avatar
 
Raymond Knopp committed
1605

1606
            break;
1607

1608
          case 4:  //16QAM
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657
	    if (x0 && Nlayers0==1) {

	      qam16_table_offset_re = 0;
	      qam16_table_offset_im = 0;
	      
	      if (x0[*jj] == 1)
		qam16_table_offset_re+=2;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam16_table_offset_im+=2;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam16_table_offset_re+=1;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam16_table_offset_im+=1;
	      *jj = *jj + 1;
	      
	      ((int16_t*)&txdataF[first_layer0][tti_offset])[0] = qam_table_s0[qam16_table_offset_re];
	      ((int16_t*)&txdataF[first_layer0][tti_offset])[1] = qam_table_s0[qam16_table_offset_im];
	    }

	    if (x1 && Nlayers1==1) {

	      qam16_table_offset_re = 0;
	      qam16_table_offset_im = 0;
	      
	      if (x1[*jj2] == 1)
		qam16_table_offset_re+=2;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam16_table_offset_im+=2;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam16_table_offset_re+=1;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam16_table_offset_im+=1;
	      *jj2 = *jj2 + 1;
	      
	      ((int16_t*)&txdataF[first_layer1][tti_offset])[0] = qam_table_s0[qam16_table_offset_re];
	      ((int16_t*)&txdataF[first_layer1][tti_offset])[1] = qam_table_s0[qam16_table_offset_im];
	    }
1658 1659 1660 1661 1662

            break;

          case 6:  //64QAM

Florian Kaltenberger's avatar
Florian Kaltenberger committed
1663
	    if (x0 && Nlayers0==1) {
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
	      qam64_table_offset_re = 0;
	      qam64_table_offset_im = 0;
	      
	      if (x0[*jj] == 1)
		qam64_table_offset_re+=4;
	      *jj = *jj + 1;

	      if (x0[*jj] == 1)
		qam64_table_offset_im+=4;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam64_table_offset_re+=2;
	      *jj = *jj + 1;

	      if (x0[*jj] == 1)
		qam64_table_offset_im+=2;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam64_table_offset_re+=1;
	      *jj = *jj + 1;
	      
	      if (x0[*jj] == 1)
		qam64_table_offset_im+=1;
	      *jj = *jj + 1;
	      
              ((int16_t*)&txdataF[first_layer0][tti_offset])[0] = qam_table_s0[qam64_table_offset_re];
              ((int16_t*)&txdataF[first_layer0][tti_offset])[1] = qam_table_s0[qam64_table_offset_im];
            }
1694

Florian Kaltenberger's avatar
Florian Kaltenberger committed
1695
	    if (x1 && Nlayers1==1) {
1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
	      qam64_table_offset_re = 0;
	      qam64_table_offset_im = 0;
	      
	      if (x1[*jj2] == 1)
		qam64_table_offset_re+=4;
	      *jj2 = *jj2 + 1;

	      if (x1[*jj2] == 1)
		qam64_table_offset_im+=4;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam64_table_offset_re+=2;
	      *jj2 = *jj2 + 1;

	      if (x1[*jj2] == 1)
		qam64_table_offset_im+=2;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam64_table_offset_re+=1;
	      *jj2 = *jj2 + 1;
	      
	      if (x1[*jj2] == 1)
		qam64_table_offset_im+=1;
	      *jj2 = *jj2 + 1;
	      
              ((int16_t*)&txdataF[first_layer1][tti_offset])[0] = qam_table_s0[qam64_table_offset_re];
              ((int16_t*)&txdataF[first_layer1][tti_offset])[1] = qam_table_s0[qam64_table_offset_im];
1725 1726 1727 1728 1729
            }

            break;

          }
1730
	  */
1731
        }
1732
        else {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1733
          for (p=7; p<9; p++) {
1734
	    if (p==first_layer0 || p==first_layer1) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1735
	      if (frame_parms->Ncp==0) { //normal CP
1736
		ind = 3*lprime*frame_parms->N_RB_DL+3*rb+mprime2;
1737 1738 1739
		ind_dword = ind>>4 ;
		ind_qpsk_symb = ind&0xf ;
		
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1740
		if (((mprime2+rb)%2)==0) {
1741 1742 1743 1744
		  w = Wbar_NCP[p-7][lprime] ;
		} else {
		  w = Wbar_NCP[p-7][3-lprime] ;
		}
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1745 1746
	      } else { //extended CP
		// this is very likely wrong as the Wbar table is different for extended CP
1747 1748 1749 1750 1751
		ind = 4*lprime*dlsch0_harq->nb_rb+4*rb+mprime2 ;
		ind_dword = ind>>4 ;
		ind_qpsk_symb = ind&0xf ;
		int l = lprime%2 ;
		
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1752
		if ((mprime2%2)==0) {
1753 1754 1755 1756 1757 1758 1759 1760
		  w = Wbar_NCP[p-7][l] ;
		} else {
		  w = Wbar_NCP[p-7][1-l] ;
		}
	      }
	      qpsk_p = (w==1) ? qpsk : nqpsk;
	      
	      /* pointer to the frequency domain Tx signal */
1761
	      txdataF[p][tti_offset] = qpsk_p[(phy_vars_eNB->lte_gold_uespec_table[nscid][Ns][0][ind_dword]>>(2*ind_qpsk_symb))&3] ;
1762
	    }
1763
          }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1764
	  mprime2++ ;
1765
        }
1766
      } else if (mimo_mode>=TM9_10) {
1767
        printf("allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
1768
        return(-1);
Raymond Knopp's avatar
 
Raymond Knopp committed
1769
      }
1770 1771 1772 1773 1774
    }
  }
  return(0);
}

1775

1776
int allocate_REs_in_RB_MCH(int32_t **txdataF,
1777
                           uint32_t *jj,
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
                            uint16_t re_offset,
                            uint32_t symbol_offset,
                            uint8_t *x0,
                            uint8_t l,
                            uint8_t mod_order,
                            int16_t amp,
                            int16_t *qam_table_s,
                            uint32_t *re_allocated,
                            uint8_t skip_dc,
                            LTE_DL_FRAME_PARMS *frame_parms)
1788
{
1789

Xiwen JIANG's avatar
Xiwen JIANG committed
1790
  uint32_t tti_offset;
1791 1792 1793 1794 1795 1796 1797
  uint8_t re;
  uint8_t qam64_table_offset_re = 0;
  uint8_t qam64_table_offset_im = 0;
  uint8_t qam16_table_offset_re = 0;
  uint8_t qam16_table_offset_im = 0;
  int16_t gain_lin_QPSK;//,gain_lin_16QAM1,gain_lin_16QAM2;
  int16_t re_off=re_offset;
1798
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
1799 1800 1801
  uint8_t first_re,last_re;
  int inc;
#ifdef DEBUG_DLSCH_MODULATION
1802
  printf("allocate_re_MCH (mod %d): symbol_offset %d re_offset %d (%d), jj %d -> %d,%d, gain_lin_QPSK %d,txdataF %p\n",mod_order,symbol_offset,re_offset,skip_dc,*jj, x0[*jj], x0[1+*jj],gain_lin_QPSK,&txdataF[0][symbol_offset]);
1803 1804 1805 1806 1807
#endif

  last_re=12;
  first_re=0;
  inc=1;
1808

1809 1810 1811
  if ((l==2)||(l==10)) {
    inc=2;
    first_re=1;
1812
  } else if (l==6) {
1813 1814
    inc=2;
  }
1815 1816 1817

  for (re=first_re; re<last_re; re+=inc) {

1818 1819
    if ((skip_dc == 1) && (re==(6+first_re)))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
1820

1821
    tti_offset = symbol_offset + re_off + re;
1822

lukashov's avatar
lukashov committed
1823
    //printf("re %d (jj %d)\n",re,*jj);
1824
    *re_allocated = *re_allocated + 1;
1825 1826


1827
    switch (mod_order) {
1828

1829
      case 2:  //QPSK
1830

1831
      //            printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
Xiwen JIANG's avatar
Xiwen JIANG committed
1832
      ((int16_t*)&txdataF[4][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
1833 1834 1835

      *jj = *jj + 1;

Xiwen JIANG's avatar
Xiwen JIANG committed
1836
      ((int16_t*)&txdataF[4][tti_offset])[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
1837 1838 1839

      *jj = *jj + 1;

lukashov's avatar
lukashov committed
1840
      //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1841 1842 1843
      break;


1844
      case 4:  //16QAM
1845

1846 1847
    qam16_table_offset_re = 0;
    qam16_table_offset_im = 0;
1848

1849 1850
    if (x0[*jj] == 1)
      qam16_table_offset_re+=2;
1851

1852
    *jj=*jj+1;
1853

1854 1855
    if (x0[*jj] == 1)
      qam16_table_offset_im+=2;
1856

1857
    *jj=*jj+1;
1858 1859


1860 1861
    if (x0[*jj] == 1)
      qam16_table_offset_re+=1;
1862

1863
    *jj=*jj+1;
1864

1865 1866
    if (x0[*jj] == 1)
      qam16_table_offset_im+=1;
1867

1868
    *jj=*jj+1;
1869 1870


Xiwen JIANG's avatar
Xiwen JIANG committed
1871 1872
    ((int16_t *)&txdataF[4][tti_offset])[0]=qam_table_s[qam16_table_offset_re];//(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
    ((int16_t *)&txdataF[4][tti_offset])[1]=qam_table_s[qam16_table_offset_im];//(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
1873

1874
    break;
1875

1876
      case 6:  //64QAM
1877

1878 1879
    qam64_table_offset_re = 0;
    qam64_table_offset_im = 0;
1880

1881 1882
    if (x0[*jj] == 1)
      qam64_table_offset_re+=4;
1883

1884
    *jj=*jj+1;
1885

1886 1887
    if (x0[*jj] == 1)
      qam64_table_offset_im+=4;
1888

1889
    *jj=*jj+1;
1890

1891 1892
    if (x0[*jj] == 1)
      qam64_table_offset_re+=2;
1893

1894
    *jj=*jj+1;
1895

1896 1897
    if (x0[*jj] == 1)
      qam64_table_offset_im+=2;
1898

1899
    *jj=*jj+1;
1900

1901 1902
    if (x0[*jj] == 1)
      qam64_table_offset_re+=1;
1903

1904
    *jj=*jj+1;
1905

1906 1907
    if (x0[*jj] == 1)
      qam64_table_offset_im+=1;
1908

1909
    *jj=*jj+1;
1910

Xiwen JIANG's avatar
Xiwen JIANG committed
1911 1912
    ((int16_t *)&txdataF[4][tti_offset])[0]=qam_table_s[qam64_table_offset_re];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
    ((int16_t *)&txdataF[4][tti_offset])[1]=qam_table_s[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
1913

1914
    break;
1915

1916
    }
1917 1918
  }

1919 1920 1921
  return(0);
}

1922
uint8_t get_pmi(uint8_t N_RB_DL, MIMO_mode_t mode, uint32_t pmi_alloc,uint16_t rb)
1923
{
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1924
  /*
1925 1926
  MIMO_mode_t mode   = dlsch_harq->mimo_mode;
  uint32_t pmi_alloc = dlsch_harq->pmi_alloc;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1927
  */
1928

Raymond Knopp's avatar
 
Raymond Knopp committed
1929
  switch (N_RB_DL) {
1930 1931 1932 1933 1934
    case 6:   // 1 PRB per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>(rb<<1))&3);
      else
        return((pmi_alloc>>rb)&1);
1935

1936
      break;
1937

1938 1939 1940 1941 1942 1943
    default:
    case 25:  // 4 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb>>2)<<1))&3);
      else
        return((pmi_alloc>>(rb>>2))&1);
1944

1945
      break;
1946

1947 1948 1949 1950 1951
    case 50: // 6 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb/6)<<1))&3);
      else
        return((pmi_alloc>>(rb/6))&1);
1952

1953
      break;
1954

1955 1956 1957 1958 1959
    case 100: // 8 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb>>3)<<1))&3);
      else
        return((pmi_alloc>>(rb>>3))&1);
1960

1961
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1962
  }
1963 1964
}

Raymond Knopp's avatar
 
Raymond Knopp committed
1965

1966 1967 1968 1969 1970 1971 1972
inline int check_skip(int rb,int subframe_offset,LTE_DL_FRAME_PARMS *frame_parms,int l,int nsymb) __attribute__((always_inline));
inline int check_skip(int rb,int subframe_offset,LTE_DL_FRAME_PARMS *frame_parms,int l,int nsymb) {


  if ((frame_parms->N_RB_DL&1) == 1) { // ODD N_RB_DL
    // PBCH
    if ((subframe_offset==0) &&
1973 1974 1975 1976
        (rb>((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4))) {
1977 1978 1979 1980 1981
      return(1);
    }
    if (frame_parms->frame_type == TDD) { // TDD
            //SSS TDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)) ) {
1982
        return(1);
1983
      }
1984 1985
      //PSS TDD
      if (((subframe_offset==1) || (subframe_offset==6)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==2) ) {
1986
        return(1);
1987 1988 1989 1990
      }
    } else {
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) &&
1991 1992 1993 1994
          (rb>((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==((nsymb>>1)-1)) ) {
        return(1);
1995 1996 1997
      }
      //SSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==((nsymb>>1)-2)) ) {
1998
        return(1);
1999 2000 2001 2002 2003 2004
      }
    }
  }
  else { // even N_RB_DL
    //PBCH
    if ((subframe_offset==0) &&
2005 2006 2007
        (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=nsymb>>1) && (l<((nsymb>>1) + 4)))
2008 2009 2010 2011 2012
      return(1);

    if (frame_parms->frame_type == TDD) { // TDD
      //SSS
      if (((subframe_offset==0)||
2013 2014 2015 2016 2017
           (subframe_offset==5)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==nsymb-1) ) {
         return(1);
2018
      }
2019

2020 2021
      //PSS
      if (((subframe_offset==1)||
2022 2023 2024 2025 2026
           (subframe_offset==6)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==2) ) {
         return(1);
2027 2028 2029 2030
      }
    } else { // FDD
      //SSS
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==((nsymb>>1)-2)) ) {
2031
         return(1);
2032
      }
2033

2034 2035
      //PSS
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==((nsymb>>1)-1)) ) {
2036
         return(1);
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
      }
    }
  }

  return(0);
}

inline int check_skiphalf(int rb,int subframe_offset,LTE_DL_FRAME_PARMS *frame_parms,int l,int nsymb) __attribute__((always_inline));
inline int check_skiphalf(int rb,int subframe_offset,LTE_DL_FRAME_PARMS *frame_parms,int l,int nsymb) {

2047
  //  printf("check_skiphalf : rb %d, subframe_offset %d,l %d, nsymb %d\n",rb,subframe_offset,l,nsymb);
2048 2049 2050 2051 2052

  if ((frame_parms->N_RB_DL&1) == 1) { // ODD N_RB_DL

    // PBCH
    if ((subframe_offset==0) &&
2053 2054 2055
        (rb==((frame_parms->N_RB_DL>>1)-3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4)))
2056 2057 2058 2059 2060 2061 2062
      return(1);
    else if ((subframe_offset==0) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4)))
      return(2);

    if (frame_parms->frame_type == TDD) { // TDD
      //SSS TDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==(nsymb-1)))
2063
        return(1);
2064
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)))
2065
        return(2);
2066 2067
      //PSS TDD
      if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==2))
2068
        return(1);
2069
      else if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==2))
2070
        return(2);
2071 2072 2073 2074
    }
    else { // FDD
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==((nsymb>>1)-1)))
2075
        return(1);
2076
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(((nsymb>>1)-1))))
2077
        return(2);
2078 2079
      //SSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && ((l==((nsymb>>1)-2))))
2080
        return(1);
2081
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && ((l==(nsymb>>1)-2)))
2082
        return(2);
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
    }
  }
  else { // EVEN N_RB_DL
    return(0);
  }

  return(0);
}

inline int check_skip_dc(int rb,LTE_DL_FRAME_PARMS *frame_parms) __attribute__((always_inline));
inline int check_skip_dc(int rb,LTE_DL_FRAME_PARMS *frame_parms) {

  if (((frame_parms->N_RB_DL&1) == 1) &&  // odd N_RB_DL, rb==N_RB_DL/2 PRB contains DC element
      (rb==(frame_parms->N_RB_DL>>1)))
    return(1);
  else
    return(0);
}

2102

2103
int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
2104
                     int32_t **txdataF,
2105 2106 2107 2108 2109 2110
                     int16_t amp,
                     uint32_t subframe_offset,
                     uint8_t num_pdcch_symbols,
                     LTE_eNB_DLSCH_t *dlsch0,
                     LTE_eNB_DLSCH_t *dlsch1)
{
2111
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
2112 2113

  uint8_t nsymb;
Cedric Roux's avatar
Cedric Roux committed
2114
  uint8_t harq_pid = -1; //= dlsch0->current_harq_pid;
Cedric Roux's avatar
Cedric Roux committed
2115
  LTE_DL_eNB_HARQ_t *dlsch0_harq = NULL;
Cedric Roux's avatar
Cedric Roux committed
2116
  LTE_DL_eNB_HARQ_t *dlsch1_harq = NULL; //= dlsch1->harq_processes[harq_pid];
2117
  uint32_t i,i2,jj,jj2,re_allocated,symbol_offset;
2118 2119
  uint16_t l,rb,re_offset;
  uint32_t rb_alloc_ind;
Cedric Roux's avatar
Cedric Roux committed
2120
  uint32_t *rb_alloc = NULL; //=dlsch0_harq->rb_alloc;
2121

2122 2123
  uint8_t pilots=0;
  uint8_t skip_dc,skip_half;
2124
  uint8_t mod_order0 = 0;
2125
  uint8_t mod_order1 = 0;
2126
  int16_t amp_rho_a, amp_rho_b;
2127 2128
  int16_t qam16_table_a0[4],qam64_table_a0[8],qam16_table_b0[4],qam64_table_b0[8];
  int16_t qam16_table_a1[4],qam64_table_a1[8],qam16_table_b1[4],qam64_table_b1[8];
2129

2130
  int16_t *qam_table_s0=NULL,*qam_table_s1=NULL;
2131 2132
#if 0
  /* TODO: variable to be removed? */
2133
  int (*allocate_REs)(PHY_VARS_eNB*,
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153
                      int **,
                      uint32_t*,
                      uint32_t*,
                      uint16_t,
                      uint32_t,
                      LTE_DL_eNB_HARQ_t *,
                      LTE_DL_eNB_HARQ_t *,
                      uint8_t,
                      int16_t,
                      uint8_t,
                      int16_t *,
                      int16_t *,
                      uint32_t *,
                      uint8_t,
                      uint8_t,
                      uint8_t,
                      uint8_t,
                      uint8_t,
                      int *,
                      int *);
2154
#endif
2155

2156 2157
  int P1_SHIFT[13],P2_SHIFT[13];
  int offset,nushiftmod3;
2158

2159
  uint8_t get_pmi_temp;
2160

Cedric Roux's avatar
Cedric Roux committed
2161
  MIMO_mode_t mimo_mode = -1;
2162 2163
  uint8_t mprime=0,Ns;
  int8_t  lprime=-1;
Xiwen JIANG's avatar
Xiwen JIANG committed
2164
  int aa=0;
2165
  uint8_t nscid=0;
2166

Raymond Knopp's avatar
 
Raymond Knopp committed
2167
#ifdef DEBUG_DLSCH_MODULATION
2168 2169
  uint8_t Nl0=0;  //= dlsch0_harq->Nl;
  uint8_t Nl1=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
2170
#endif
2171

2172

2173
  if ((dlsch0 != NULL) && (dlsch1 != NULL)){
2174

2175 2176
    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2177
    mimo_mode = dlsch0_harq->mimo_mode;
2178 2179 2180 2181 2182 2183
    mod_order0 = get_Qm(dlsch0_harq->mcs);
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

2184 2185 2186 2187 2188
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
    mod_order1 = get_Qm(dlsch1_harq->mcs);
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = dlsch1_harq->Nl;
#endif
2189

2190 2191
    nscid = dlsch0_harq->nscid;

2192 2193 2194 2195
  }else if ((dlsch0 != NULL) && (dlsch1 == NULL)){

    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2196
    mimo_mode = dlsch0_harq->mimo_mode;
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208
    mod_order0 = get_Qm(dlsch0_harq->mcs);
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

    dlsch1_harq = NULL;
    mod_order1 = 0;
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = 0;
#endif

2209 2210
    nscid = dlsch0_harq->nscid;

2211 2212 2213 2214
  }else if ((dlsch0 == NULL) && (dlsch1 != NULL)){

    harq_pid = dlsch1->current_harq_pid;
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
2215
    mimo_mode = dlsch1_harq->mimo_mode;
2216 2217 2218 2219 2220 2221 2222 2223 2224
    mod_order0 = get_Qm(dlsch1_harq->mcs);
    rb_alloc = dlsch1_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch1_harq->Nl;
#endif

    dlsch0_harq = NULL;
    mod_order1 = 0;
#ifdef DEBUG_DLSCH_MODULATION
2225
    Nl1 = 0;
2226 2227
#endif

2228
    nscid = dlsch1_harq->nscid;
2229
  }
2230

2231
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
2232

2233
  nsymb = (frame_parms->Ncp==0) ? 14:12;
2234

2235
  if (dlsch0 != NULL){
Florian Kaltenberger's avatar
Florian Kaltenberger committed
2236 2237
    amp_rho_a = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_a)>>13); //amp=512 in  full scale; dlsch0->sqrt_rho_a=8192in Q2.13, 1 in full scale
    amp_rho_b = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_b)>>13);
2238
  } else{
Florian Kaltenberger's avatar
Florian Kaltenberger committed
2239 2240
    amp_rho_a = (int16_t)(((int32_t)amp*dlsch1->sqrt_rho_a)>>13);
    amp_rho_b = (int16_t)(((int32_t)amp*dlsch1->sqrt_rho_b)>>13);
2241
  }
2242

2243
  if (mod_order0 == 4)
2244
    for (i=0;i<4; i++) {
2245 2246
      qam16_table_a0[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_a)>>15);
      qam16_table_b0[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_b)>>15);
2247
    }
2248
  else if (mod_order0 == 6)
2249
    for (i=0; i<8; i++) {
2250 2251
      qam64_table_a0[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_a)>>15);
      qam64_table_b0[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_b)>>15);
2252
    }
2253 2254

  if (mod_order1 == 4)
2255
    for (i=0; i<4; i++) {
2256 2257 2258
      qam16_table_a1[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_a)>>15);
      qam16_table_b1[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_b)>>15);
    }
Raymond Knopp's avatar
Raymond Knopp committed
2259
  else if (mod_order1 == 6)
2260
    for (i=0; i<8; i++) {
2261 2262
      qam64_table_a1[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_a)>>15);
      qam64_table_b1[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_b)>>15);
2263 2264
    }

2265
  //Modulation mapping (difference w.r.t. LTE specs)
2266 2267 2268

  jj=0;
  jj2=0;
2269
  re_allocated=0;
2270

2271

Florian Kaltenberger's avatar
Florian Kaltenberger committed
2272 2273
    //#ifdef DEBUG_DLSCH_MODULATION
    LOG_D(PHY,"Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc0 %lx, mod0 %d, mod1 %d, rb_alloc[0] %d)\n",
lukashov's avatar
lukashov committed
2274 2275 2276 2277 2278
            harq_pid,
            dlsch0_harq->mimo_mode,
            pmi2hex_2Ar2(dlsch0_harq->pmi_alloc),
            mod_order0,
            mod_order1,
2279
            rb_alloc[0]);
Florian Kaltenberger's avatar
Florian Kaltenberger committed
2280 2281 2282 2283
    //#endif

  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
  for (l=num_pdcch_symbols; l<nsymb; l++) {
2284 2285 2286

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
2287
        pilots=2;   // pilots in nushift+3, nushift+9
2288
      else if (l==7)
2289
        pilots=1;   // pilots in nushift, nushift+6
2290
      else
2291 2292
        pilots=0;
    } else {
2293
      if ((l==3)||(l==9))
2294
        pilots=2;
2295
      else if (l==6)
2296
        pilots=1;
2297
      else
2298
        pilots=0;
2299 2300
    }

2301 2302 2303
    if(mimo_mode==TM7){ //36.211 V8.6.0 2009-03
      mprime = 0;
      if (frame_parms->Ncp==0) { // normal prefix
2304 2305 2306 2307 2308 2309 2310 2311
        if (l==12)
          lprime=3;   // pilots in nushift+3, nushift+9
        else if (l==9)
          lprime=2;   // pilots in nushift, nushift+6
        else if (l==6)
          lprime=1;   // pilots in nushift+3, nushift+9
        else if (l==3)
          lprime=0;   // pilots in nushift, nushift+6
2312
        else
2313
          lprime=-1;
2314
      } else {
2315
        if (l==10)
2316
          lprime=2;
2317
        else if (l==7)
2318
          lprime=1;
2319
        else if (l==4)
2320
          lprime=0;
2321 2322
        else
          lprime=-1;
2323
      }
Xiwen JIANG's avatar
Xiwen JIANG committed
2324

2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368
      
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
          (phy_vars_eNB->common_vars.beam_weights[0][5][aa])[i+1] = (phy_vars_eNB->dlsch[0][0]->ue_spec_bf_weights[0][aa])[i+frame_parms->N_RB_DL*12/2] ;
          //memcpy(PHY_vars_eNB->lte_eNB_common_vars.beam_weights[0][5][aa][i], PHY_vars_eNB->dlsch_eNB[0][0]->ue_spec_bf_weights[0][aa][i+149], 300) ;
        }
      }
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
        (phy_vars_eNB->common_vars.beam_weights[0][5][aa])[i+frame_parms->first_carrier_offset] = (phy_vars_eNB->dlsch[0][0]->ue_spec_bf_weights[0][aa])[i] ;
        // memcpy(PHY_vars_eNB->lte_eNB_common_vars.beam_weights[0][5][aa][i+363], PHY_vars_eNB->dlsch_eNB[0][0]->ue_spec_bf_weights[0][aa][i], 300) ;
        }
      }
      //printf("beam_weights[0][5][0][363]\n", PHY_vars_eNB->lte_eNB_common_vars.beam_weights[0][5][0][363]) ;
      //printf("beam_weights[0][5][0][362]\n", PHY_vars_eNB->lte_eNB_common_vars.beam_weights[0][5][0][362]) ;


    }
    else if (mimo_mode==TM8) {   /*TODO (p 86 36.211 v11.3)*/
      mprime = 0;
      if (frame_parms->Ncp==0) { 
        if (l==13)
          lprime=3;   
        else if (l==12)
          lprime=2;   
        else if (l==6)
          lprime=1;   
        else if (l==5)
          lprime=0;   
        else
          lprime=-1;
      } else {
        if (l==13)
          lprime=3;
        else if (l==12)
          lprime=2;
        else if (l==5)
          lprime=1;
        else if (l==4)
          lprime=0;
        else
          lprime=-1;
      }

2369
      /*NOTE: the antenna port 7 and 8 should be replaced with dlsch0_harq->first_layer and dlsch1_harq->first_layer below (when first_layer is actually initialized)*/
2370
      if (dlsch0 != NULL) {
Xiwen JIANG's avatar
Xiwen JIANG committed
2371
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
2372
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
2373
          (phy_vars_eNB->common_vars.beam_weights[0][7][aa])[i+1] = (dlsch0->ue_spec_bf_weights[0][aa])[i+frame_parms->N_RB_DL*12/2] ;
2374 2375 2376 2377
        }
      }
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
        (phy_vars_eNB->common_vars.beam_weights[0][7][aa])[i+frame_parms->first_carrier_offset] = (dlsch0->ue_spec_bf_weights[0][aa])[i] ;
        }
      }
      }
      if (dlsch1 != NULL) {
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
          (phy_vars_eNB->common_vars.beam_weights[0][8][aa])[i+1] = (dlsch1->ue_spec_bf_weights[0][aa])[i+frame_parms->N_RB_DL*12/2] ;
        }
      }
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
        (phy_vars_eNB->common_vars.beam_weights[0][8][aa])[i+frame_parms->first_carrier_offset] = (dlsch1->ue_spec_bf_weights[0][aa])[i] ;
2391
        }
Xiwen JIANG's avatar
Xiwen JIANG committed
2392
      }
2393

2394
      }
2395
    }
2396

2397
    Ns = 2*subframe_offset+(l>=(nsymb>>1));
2398

2399 2400 2401 2402 2403
    offset = (pilots==2)?3:0;
    nushiftmod3 = frame_parms->nushift%3;

    if (pilots>0) {  // compute pilot arrays, could be done statically if performance suffers
      if (frame_parms->mode1_flag == 1) {
2404 2405 2406 2407 2408 2409 2410 2411
        //      printf("l %d, nushift %d, offset %d\n",l,frame_parms->nushift,offset);
        for (i=0,i2=0;i<12;i++) {
          if ((i!=(frame_parms->nushift+offset)) && (i!=((frame_parms->nushift+6+offset)%12)))
            P1_SHIFT[i2++]=1;
          else
            P1_SHIFT[i2++]=2;
        }
        P1_SHIFT[0]--;
2412 2413
      }
      else {
2414 2415 2416 2417 2418 2419 2420
        for (i=0,i2=0;i<12;i++) {
          if ((i!=nushiftmod3) && (i!=nushiftmod3+6) && (i!=nushiftmod3+3) && (i!=nushiftmod3+9))
            P2_SHIFT[i2++]=1;
          else
            P2_SHIFT[i2++]=2;
        }
        P2_SHIFT[0]--;
2421 2422 2423 2424
      }
    }
    P1_SHIFT[12]=1;P2_SHIFT[12]=1;

2425 2426 2427
    re_offset = frame_parms->first_carrier_offset;
    symbol_offset = (uint32_t)frame_parms->ofdm_symbol_size*(l+(subframe_offset*nsymb));

2428 2429
#if 0
    /* TODO: remove this code? */
2430
    allocate_REs = allocate_REs_in_RB;
2431
#endif
2432

2433 2434 2435 2436 2437 2438
    switch (mod_order0) {
    case 2:
      qam_table_s0 = NULL;
      break;
    case 4:
      if (pilots) {
2439
        qam_table_s0 = qam16_table_b0;
2440 2441
#if 0
        /* TODO: remove this code? */
2442 2443 2444
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_16QAM_siso :
          allocate_REs_in_RB;
2445
#endif
2446 2447
      }
      else {
2448
        qam_table_s0 = qam16_table_a0;
2449 2450
#if 0
        /* TODO: remove this code? */
2451 2452 2453
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_16QAM_siso :
          allocate_REs_in_RB;
2454
#endif
2455

2456 2457
      }
      break;
2458

2459 2460
    case 6:
      if (pilots) {
2461
        qam_table_s0 = qam64_table_b0;
2462 2463
#if 0
        /* TODO: remove this code? */
2464 2465 2466
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_64QAM_siso :
          allocate_REs_in_RB;
2467
#endif
2468 2469
      }
      else {
2470
        qam_table_s0 = qam64_table_a0;
2471 2472
#if 0
        /* TODO: remove this code? */
2473 2474 2475
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_64QAM_siso :
          allocate_REs_in_RB;
2476
#endif
2477 2478
      }
      break;
2479

2480
    }
2481

2482 2483 2484
    switch (mod_order1) {
    case 2:
      qam_table_s1 = NULL;
2485 2486
#if 0
        /* TODO: remove this code? */
2487
      allocate_REs = allocate_REs_in_RB;
2488
#endif
2489 2490 2491
      break;
    case 4:
      if (pilots) {
2492
        qam_table_s1 = qam16_table_b1;
2493 2494
      }
      else {
2495
        qam_table_s1 = qam16_table_a1;
2496 2497 2498 2499
      }
      break;
    case 6:
      if (pilots) {
2500
        qam_table_s1 = qam64_table_b1;
2501 2502
      }
      else {
2503
        qam_table_s1 = qam64_table_a1;
2504 2505
      }
      break;
2506

2507 2508
    }

2509
    //for (aa=0;aa<frame_parms->nb_antennas_tx;aa++)
lukashov's avatar
lukashov committed
2510
    //memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
2511
    //printf("symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

      if (rb < 32)
        rb_alloc_ind = (rb_alloc[0]>>rb) & 1;
      else if (rb < 64)
        rb_alloc_ind = (rb_alloc[1]>>(rb-32)) & 1;
      else if (rb < 96)
        rb_alloc_ind = (rb_alloc[2]>>(rb-64)) & 1;
      else if (rb < 100)
        rb_alloc_ind = (rb_alloc[3]>>(rb-96)) & 1;
      else
        rb_alloc_ind = 0;
2524

2525
      if (check_skip(rb,subframe_offset,frame_parms,l,nsymb)==1)
2526
        rb_alloc_ind = 0;
2527

2528 2529
      skip_half = check_skiphalf(rb,subframe_offset,frame_parms,l,nsymb);
      skip_dc   = check_skip_dc(rb,frame_parms);
2530

2531

2532

2533 2534
     if (dlsch0) {
        if (dlsch0_harq->Nlayers>1) {
2535
          LOG_E(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2536 2537
          return(-1);
        }
2538
      }
2539 2540 2541

      if (dlsch1) {
        if (dlsch1_harq->Nlayers>1) {
2542
          LOG_E(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2543 2544 2545 2546 2547 2548 2549 2550
          return(-1);
        }
      }



      if (rb_alloc_ind > 0) {
        //    printf("Allocated rb %d/symbol %d, skip_half %d, subframe_offset %d, symbol_offset %d, re_offset %d, jj %d\n",rb,l,skip_half,subframe_offset,symbol_offset,re_offset,jj);
2551

2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562
      if (dlsch0 != NULL) {
        get_pmi_temp = get_pmi(frame_parms->N_RB_DL,
                               dlsch0->harq_processes[harq_pid]->mimo_mode,
                               dlsch0->harq_processes[harq_pid]->pmi_alloc,
                               rb);
      } else
        get_pmi_temp = get_pmi(frame_parms->N_RB_DL,
                               dlsch1->harq_processes[harq_pid]->mimo_mode,
                               dlsch1->harq_processes[harq_pid]->pmi_alloc,
                               rb);

2563

2564
      allocate_REs_in_RB(phy_vars_eNB,
lukashov's avatar
lukashov committed
2565 2566 2567
                         txdataF,
                         &jj,
                         &jj2,
2568
			 rb,
lukashov's avatar
lukashov committed
2569 2570
                         re_offset,
                         symbol_offset,
2571 2572
                         (dlsch0 == NULL) ? NULL : dlsch0->harq_processes[harq_pid],
                         (dlsch1 == NULL) ? NULL : dlsch1->harq_processes[harq_pid],
lukashov's avatar
lukashov committed
2573 2574
                         pilots,
                         ((pilots) ? amp_rho_b : amp_rho_a),
2575
                         get_pmi_temp,
lukashov's avatar
lukashov committed
2576 2577 2578 2579
                         qam_table_s0,
                         qam_table_s1,
                         &re_allocated,
                         skip_dc,
2580
                         skip_half,
2581 2582 2583 2584
                         lprime,
                         mprime,
                         Ns,
                         P1_SHIFT,
2585 2586
                         P2_SHIFT,
			 nscid);
2587

Xiwen JIANG's avatar
Xiwen JIANG committed
2588 2589
          if ((mimo_mode == TM7) && (lprime>=0))
            mprime +=3+frame_parms->Ncp;
2590
      }
2591
      else {
2592
        //      printf("Unallocated rb %d/symbol %d, re_offset %d, jj %d\n",rb,l,re_offset,jj);
2593
      }
2594 2595
      re_offset+=12; // go to next RB

2596
      // check if we crossed the symbol boundary and skip DCs
2597

2598 2599 2600 2601 2602 2603
      if (re_offset >= frame_parms->ofdm_symbol_size) {
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
      }
Florian Kaltenberger's avatar
Florian Kaltenberger committed
2604 2605 2606
  //#ifdef DEBUG_DLSCH_MODULATION
      LOG_D(PHY,"generate_dlsch : l=%d, rb=%d, jj=%d, jj2=%d, lprime=%d, mprime=%d, re_allocated = %d\n",l,rb,jj,jj2,lprime,mprime,re_allocated);
  //#endif
2607
    }
2608
  }
2609 2610


2611
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
2612

2613 2614 2615
  return (re_allocated);
}

lukashov's avatar
lukashov committed
2616

lukashov's avatar
lukashov committed
2617 2618 2619 2620 2621
int dlsch_modulation_SIC(int32_t **sic_buffer,
                         uint32_t subframe_offset,
                         LTE_DL_FRAME_PARMS *frame_parms,
                         uint8_t num_pdcch_symbols,
                         LTE_eNB_DLSCH_t *dlsch0,
lukashov's avatar
lukashov committed
2622
                         int G)
lukashov's avatar
lukashov committed
2623 2624 2625 2626
{

  uint8_t harq_pid = dlsch0->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
2627
  uint32_t i,jj,re_allocated=0;
lukashov's avatar
lukashov committed
2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640
  uint8_t mod_order0 = get_Qm(dlsch0_harq->mcs);
  uint8_t *x0  = dlsch0_harq->e;
  uint8_t qam64_table_offset_re = 0;
  uint8_t qam64_table_offset_im = 0;
  uint8_t qam16_table_offset_re = 0;
  uint8_t qam16_table_offset_im = 0;
  int16_t gain_lin_QPSK;
 #ifdef DEBUG_DLSCH_MODULATION
  uint8_t Nl0 = dlsch0_harq->Nl;
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);

2641
  gain_lin_QPSK = (int16_t)((ONE_OVER_SQRT2_Q15));
2642

lukashov's avatar
lukashov committed
2643 2644 2645
  jj = 0;
  i = 0;
  while (jj <= G-1) {
2646

lukashov's avatar
lukashov committed
2647
    re_allocated = re_allocated + 1;
lukashov's avatar
lukashov committed
2648

lukashov's avatar
lukashov committed
2649 2650
    switch (mod_order0) {
    case 2:  //QPSK
2651

lukashov's avatar
lukashov committed
2652
      ((int16_t*)&sic_buffer[0][i])[0] = (x0[jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
2653

lukashov's avatar
lukashov committed
2654
      jj = jj + 1;
2655

lukashov's avatar
lukashov committed
2656
      ((int16_t*)&sic_buffer[0][i])[1] = (x0[jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
2657

lukashov's avatar
lukashov committed
2658
      jj = jj + 1;
2659

lukashov's avatar
lukashov committed
2660 2661
      //printf("recon %d,%d\n",((int16_t*)&sic_buffer[0][i])[0],((int16_t*)&sic_buffer[0][i])[1]);
      i++;
2662

lukashov's avatar
lukashov committed
2663
      break;
lukashov's avatar
lukashov committed
2664

lukashov's avatar
lukashov committed
2665
    case 4:  //16QAM
lukashov's avatar
lukashov committed
2666

lukashov's avatar
lukashov committed
2667 2668
      qam16_table_offset_re = 0;
      qam16_table_offset_im = 0;
lukashov's avatar
lukashov committed
2669

lukashov's avatar
lukashov committed
2670 2671
      if (x0[jj] == 1)
        qam16_table_offset_re+=2;
lukashov's avatar
lukashov committed
2672

lukashov's avatar
lukashov committed
2673
      jj=jj+1;
lukashov's avatar
lukashov committed
2674

lukashov's avatar
lukashov committed
2675 2676
      if (x0[jj] == 1)
        qam16_table_offset_im+=2;
lukashov's avatar
lukashov committed
2677

lukashov's avatar
lukashov committed
2678
      jj=jj+1;
lukashov's avatar
lukashov committed
2679 2680


lukashov's avatar
lukashov committed
2681 2682
      if (x0[jj] == 1)
        qam16_table_offset_re+=1;
lukashov's avatar
lukashov committed
2683

lukashov's avatar
lukashov committed
2684
      jj=jj+1;
lukashov's avatar
lukashov committed
2685

lukashov's avatar
lukashov committed
2686 2687
      if (x0[jj] == 1)
        qam16_table_offset_im+=1;
lukashov's avatar
lukashov committed
2688

lukashov's avatar
lukashov committed
2689
      jj=jj+1;
lukashov's avatar
lukashov committed
2690 2691


lukashov's avatar
lukashov committed
2692 2693
      ((int16_t *)&sic_buffer[0][i])[0]+=qam16_table[qam16_table_offset_re];
      ((int16_t *)&sic_buffer[0][i])[1]+=qam16_table[qam16_table_offset_im];
2694 2695

      i++;
lukashov's avatar
lukashov committed
2696

lukashov's avatar
lukashov committed
2697
      break;
lukashov's avatar
lukashov committed
2698

lukashov's avatar
lukashov committed
2699
    case 6:
lukashov's avatar
lukashov committed
2700

lukashov's avatar
lukashov committed
2701 2702
      qam64_table_offset_re = 0;
      qam64_table_offset_im = 0;
lukashov's avatar
lukashov committed
2703

lukashov's avatar
lukashov committed
2704 2705
      if (x0[jj] == 1)
      qam64_table_offset_re+=4;
lukashov's avatar
lukashov committed
2706

lukashov's avatar
lukashov committed
2707
      jj=jj+1;
lukashov's avatar
lukashov committed
2708

lukashov's avatar
lukashov committed
2709 2710
      if (x0[jj] == 1)
        qam64_table_offset_im+=4;
lukashov's avatar
lukashov committed
2711

lukashov's avatar
lukashov committed
2712
      jj=jj+1;
lukashov's avatar
lukashov committed
2713

lukashov's avatar
lukashov committed
2714 2715
      if (x0[jj] == 1)
        qam64_table_offset_re+=2;
lukashov's avatar
lukashov committed
2716

lukashov's avatar
lukashov committed
2717
      jj=jj+1;
lukashov's avatar
lukashov committed
2718

lukashov's avatar
lukashov committed
2719 2720
      if (x0[jj] == 1)
        qam64_table_offset_im+=2;
lukashov's avatar
lukashov committed
2721

lukashov's avatar
lukashov committed
2722
      jj=jj+1;
lukashov's avatar
lukashov committed
2723

lukashov's avatar
lukashov committed
2724 2725
      if (x0[jj] == 1)
        qam64_table_offset_re+=1;
lukashov's avatar
lukashov committed
2726

lukashov's avatar
lukashov committed
2727
      jj=jj+1;
lukashov's avatar
lukashov committed
2728

lukashov's avatar
lukashov committed
2729 2730
      if (x0[jj] == 1)
        qam64_table_offset_im+=1;
lukashov's avatar
lukashov committed
2731

lukashov's avatar
lukashov committed
2732
      jj=jj+1;
lukashov's avatar
lukashov committed
2733 2734


lukashov's avatar
lukashov committed
2735 2736
      ((int16_t *)&sic_buffer[0][i])[0]+=(qam64_table[qam64_table_offset_re])>>1;//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
      ((int16_t *)&sic_buffer[0][i])[1]+=(qam64_table[qam64_table_offset_im])>>1;//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
2737

lukashov's avatar
lukashov committed
2738
      i++;
2739

lukashov's avatar
lukashov committed
2740
      break;
lukashov's avatar
lukashov committed
2741
      }
2742

lukashov's avatar
lukashov committed
2743
    }
lukashov's avatar
lukashov committed
2744 2745 2746


#ifdef DEBUG_DLSCH_MODULATION
2747
  printf("generate_dlsch : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch0_harq->nb_rb,dlsch0_harq->rb_alloc,mod_order0,Nl0,2,0,subframe_offset,1/*transmission mode*/));
lukashov's avatar
lukashov committed
2748 2749 2750 2751 2752 2753 2754 2755
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);

  return (re_allocated);
}


2756
int mch_modulation(int32_t **txdataF,
2757 2758 2759
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
2760
                   LTE_eNB_DLSCH_t *dlsch_eNB)
2761
{
2762 2763 2764 2765
  uint8_t nsymb,nsymb_pmch;
  uint32_t i,jj,re_allocated,symbol_offset;
  uint16_t l,rb,re_offset;
  uint8_t skip_dc=0;
2766
  uint8_t mod_order = get_Qm(dlsch_eNB->harq_processes[0]->mcs);
2767 2768 2769 2770 2771
  int16_t qam16_table_a[4],qam64_table_a[8];//,qam16_table_b[4],qam64_table_b[8];
  int16_t *qam_table_s;

  nsymb_pmch = 12;
  nsymb = (frame_parms->Ncp == NORMAL) ? 14 : 12;
2772

2773
  if (mod_order == 4)
2774
    for (i=0; i<4; i++) {
2775 2776 2777
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
2778
    for (i=0; i<8; i++) {
2779
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
2780 2781 2782
    }

  jj=0;
2783
  re_allocated=0;
2784

2785
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2786 2787
  for (l=2; l<nsymb_pmch; l++) {

2788
#ifdef DEBUG_DLSCH_MODULATION
2789
    printf("Generating MCH (mod %d) in subframe %d for symbol %d\n",mod_order, subframe_offset,l);
2790
#endif
2791 2792 2793 2794

    re_offset = frame_parms->first_carrier_offset;
    symbol_offset = (uint32_t)frame_parms->ofdm_symbol_size*(l+(subframe_offset*nsymb));

2795 2796
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

2797 2798

      if ((frame_parms->N_RB_DL&1) == 1) { // ODD N_RB_DL
2799

lukashov's avatar
lukashov committed
2800
    if (rb==(frame_parms->N_RB_DL>>1))
2801 2802 2803
          skip_dc = 1;
        else
          skip_dc = 0;
2804 2805 2806 2807

      }

      if (mod_order == 4)
2808
        qam_table_s = qam16_table_a;
2809
      else if (mod_order == 6)
2810
        qam_table_s = qam64_table_a;
2811
      else
2812
        qam_table_s = NULL;
2813

lukashov's avatar
lukashov committed
2814
      //printf("Allocated rb %d, subframe_offset %d,amp %d\n",rb,subframe_offset,amp);
2815
      allocate_REs_in_RB_MCH(txdataF,
2816 2817 2818
                             &jj,
                             re_offset,
                             symbol_offset,
2819
                             dlsch_eNB->harq_processes[0]->e,
2820 2821 2822 2823 2824 2825 2826 2827
                             l,
                             mod_order,
                             amp,
                             qam_table_s,
                             &re_allocated,
                             skip_dc,
                             frame_parms);

2828
      re_offset+=12; // go to next RB
2829

2830 2831
      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
2832 2833 2834 2835
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
2836 2837 2838 2839 2840
      }
    }
  }

#ifdef DEBUG_DLSCH_MODULATION
2841
  printf("generate_dlsch(MCH) : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch_eNB->harq_processes[0]->nb_rb,dlsch_eNB->harq_processes[0]->rb_alloc,mod_order,1,2,0,subframe_offset,1/*transmission mode*/));
2842
#endif
2843 2844

  return (re_allocated);
2845
}