dlsch_modulation.c 92.2 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

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
{
68 69
  uint8_t offset = (lprime==1||lprime==3)?2:0;
  if (lprime==-1)
70 71
    return(1);

72
  switch (beamforming_mode) {
73 74
    case 7:
      if (Ncp == NORMAL){
75
        if ((re!=nushift+offset) && (re!=((nushift+4+offset)%12)) &&  (re!=((nushift+8+offset)%12)))
76 77 78 79
          return(1);
        /*else{
          printf("(is_no_UEspec_RS):lprime=%d, re=%d, nushift=%d, offset=%d\n",lprime, re,nushift,offset);
        }*/
80
      } else {
81 82 83 84 85
        if ((re!=nushift+offset) && (re!=((nushift+3+offset)%12)) && (re!=((nushift+6+offset)%12)) && (re!=((nushift+9+offset)%12)))
          return(1);
      }
      break;

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
      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);
          }
        }
        break;

101 102 103 104
    default:
      msg("is_not_UEspecRS() [dlsch_modulation.c] : ERROR, unknown beamforming_mode %d\n",beamforming_mode);
      return(-1);
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
105

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

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

  int a,b,c,index;


115 116 117 118 119 120
  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
      }
121 122
}

123 124
void generate_16qam_table(void)
{
125 126 127

  int a,b,index;

128 129 130 131 132
  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));
    }
133 134 135 136 137
}




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

  switch (precoding_index) {

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

147 148 149 150
    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;
151

152 153 154 155
    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;
156

157 158 159 160
    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;
161 162 163
  }

  // normalize
164
  /*  ((int16_t *)antenna0_sample)[0] = (int16_t)((((int16_t *)antenna0_sample)[0]*ONE_OVER_SQRT2_Q15)>>15);
165 166
      ((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);  */
167
}
168

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

172
#if 0
173
int allocate_REs_in_RB_no_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
                                            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)
194 195
{

196
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
197 198 199 200 201 202 203 204 205
  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) {
206
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
207 208
         re<12;
         re++,x0p+=4,tti_offset++) {
209

210 211 212 213 214 215 216 217 218
      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 {
219 220
    // 1st half of PRB
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
221 222
         re<6;
         re++,x0p+=4,tti_offset++) {
223

224 225 226 227 228 229 230
      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];
    }
231 232
    // 2nd half of PRB
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+7;
233 234
         re<12;
         re++,x0p+=4,tti_offset++) {
235

236 237 238 239 240 241 242 243 244 245
      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;
246

247 248 249
    return(0);
}

250
int allocate_REs_in_RB_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
                                         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)
271
{
272

273

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

  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]);
287
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
288 289
         re<12;
         x0p+=4) {
290

291 292 293 294 295 296 297 298 299 300 301 302
      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 {
303
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
304 305
         re<6;
         x0p+=4) {
306

307 308 309 310 311 312 313 314 315 316
      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];
    }

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

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
      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);
}

337
int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
                                            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)
358 359
{

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

  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) {

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

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

378 379
      qam64_table_offset_re=(x0p[0]<<2)|(x0p[2]<<1)|x0p[4];
      qam64_table_offset_im=(x0p[1]<<2)|(x0p[3]<<1)|x0p[5];
380 381
      ((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];
382

383 384
      qam64_table_offset_re=(x0p[6]<<2)|(x0p[8]<<1)|x0p[10];
      qam64_table_offset_im=(x0p[7]<<2)|(x0p[9]<<1)|x0p[11];
385 386 387
      ((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];

388 389
      qam64_table_offset_re=(x0p[12]<<2)|(x0p[14]<<1)|x0p[16];
      qam64_table_offset_im=(x0p[13]<<2)|(x0p[15]<<1)|x0p[17];
390 391 392
      ((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];

393 394
      qam64_table_offset_re=(x0p[18]<<2)|(x0p[20]<<1)|x0p[22];
      qam64_table_offset_im=(x0p[19]<<2)|(x0p[21]<<1)|x0p[23];
395 396
      ((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];
397 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

      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];


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

446 447 448 449 450 451 452 453 454 455
      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];
    }

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

460 461 462 463 464 465 466 467 468 469 470 471 472
      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;
473

474 475 476
  return(0);
}

477
int allocate_REs_in_RB_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
                                         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)
498
{
499

500

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

  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]);
514
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
515 516
         re<12;
         x0p+=6) {
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531
      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 {
532
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
533 534
         re<6;
         x0p+=6) {
535

536 537 538 539 540 541 542 543 544 545 546 547
      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];
    }

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

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
      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);
}
569
#endif
570

571
int allocate_REs_in_RB(PHY_VARS_eNB *phy_vars_eNB,
572
                       int32_t **txdataF,
573 574
                       uint32_t *jj,
                       uint32_t *jj2,
575
		       uint16_t rb,
576 577 578 579 580 581 582 583 584 585 586
                       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,
587
                       uint8_t skip_half,
588 589 590 591 592
                       uint8_t lprime,
                       uint8_t mprime,
                       uint8_t Ns,
                       int *P1_SHIFT,
                       int *P2_SHIFT)
593
{
594

595
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
596
  MIMO_mode_t mimo_mode = -1;
597

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

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

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

614
  uint32_t tti_offset; //,aa;
615 616 617 618 619
  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;
620 621 622 623 624 625 626 627 628 629 630
  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;

631 632
  int16_t gain_lin_QPSK;//,gain_lin_16QAM1,gain_lin_16QAM2;
  int16_t re_off=re_offset;
633

634 635 636
  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;
  int16_t tmp_amp=amp;
637
  int s=1;
638
  int mprime2 = mprime,ind,ind_dword,ind_qpsk_symb,p,w;
639
  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}} ;
640
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
641

642
  int32_t qpsk[4],nqpsk[4],*qpsk_p;
643 644 645
  ((int16_t *)&qpsk[0])[0] = gain_lin_QPSK;
  ((int16_t *)&qpsk[0])[1] = gain_lin_QPSK;
  ((int16_t *)&qpsk[1])[0] = -gain_lin_QPSK;
646 647 648 649
  ((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;
650
  ((int16_t *)&qpsk[3])[1] = -gain_lin_QPSK;
651

652 653 654 655 656 657 658 659 660
  ((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;

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

    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);
668
    x1             = dlsch1_harq->e;
Raymond Knopp's avatar
 
Raymond Knopp committed
669
    // Fill these in later for TM8-10
670 671
    Nlayers1       = dlsch1_harq->Nlayers;
    first_layer1   = dlsch1_harq->first_layer;
672 673
    mod_order1     = get_Qm(dlsch1_harq->mcs);

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

    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);

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

    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);

690
  }
691

692 693 694 695 696
#ifdef DEBUG_DLSCH_MODULATION
  printf("mimo_mode %d, first_layer0 %d, NLayers0 %d, first_layer1 %d, NLayers1 %d\n",mimo_mode,first_layer0,Nlayers0,first_layer1,Nlayers1);

  printf("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]);
#endif
697 698 699 700

  first_re=0;
  last_re=12;

701
  if (skip_half==1)
702 703 704
    last_re=6;
  else if (skip_half==2)
    first_re=6;
705

706

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

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

713
    tti_offset = symbol_offset + re_off + re;
714

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

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

720

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

        switch (mod_order0) {
        case 2:  //QPSK

727 728 729

          //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
730 731 732

          *jj = *jj + 1;

733
          ((int16_t*)&txdataF[0][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
734 735 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

          *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;

765 766
          ((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];
767 768 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

          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;

806 807
          ((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];
808 809 810 811

          break;

        }
812 813
      }

814 815
      else if (mimo_mode == ALAMOUTI) {
        *re_allocated = *re_allocated + 1;
816

817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
        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;

837
	  //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
838
          // normalization for 2 tx antennas
839 840 841 842
          ((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]));
843

lukashov's avatar
lukashov committed
844
        break;
845

lukashov's avatar
lukashov committed
846
        case 4:  //16QAM
847 848

          // Antenna 0 position n
lukashov's avatar
lukashov committed
849 850
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;
851

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


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

867 868 869 870 871
          //((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]);
872

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

lukashov's avatar
lukashov committed
875 876 877 878 879 880 881 882 883
          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;
884 885


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

893 894 895 896 897
          //((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]);
898

899 900
         //((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];
901 902

          break;
lukashov's avatar
lukashov committed
903 904

        case 6:   // 64-QAM
905

lukashov's avatar
lukashov committed
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
          // 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;
928

929 930
          //((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);
931 932 933 934
	  //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]);

935

lukashov's avatar
lukashov committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
          // 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;
957

958 959
          //((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);
960 961 962 963
	  //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]);

964

965
          break;
lukashov's avatar
lukashov committed
966
        }
967
  // fill in the rest of the ALAMOUTI precoding
lukashov's avatar
lukashov committed
968 969 970 971 972 973 974 975 976 977 978 979
        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];
        }
980
      }
981
      else if (mimo_mode == LARGE_CDD) {
982

lukashov's avatar
lukashov committed
983 984
        *re_allocated = *re_allocated + 1;

985
        if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
          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;
1001

lukashov's avatar
lukashov committed
1002
          case 4:  //16QAM
1003

lukashov's avatar
lukashov committed
1004 1005 1006 1007 1008 1009 1010 1011
            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;
1012

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

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

            break;
1024

lukashov's avatar
lukashov committed
1025
          case 6:  //64QAM
1026 1027


lukashov's avatar
lukashov committed
1028 1029
            qam64_table_offset_re0 = 0;
            qam64_table_offset_im0 = 0;
1030

lukashov's avatar
lukashov committed
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
            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;
1054

lukashov's avatar
lukashov committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
          }

          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]);
1066
            xx1_re = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1067
            *jj2 = *jj2 + 1;
1068
            xx1_im = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1069 1070 1071
            *jj2 = *jj2 + 1;
            //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
            break;
1072

lukashov's avatar
lukashov committed
1073
          case 4:  //16QAM
1074

lukashov's avatar
lukashov committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
            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;
1094

lukashov's avatar
lukashov committed
1095
          case 6:  //64QAM
1096

lukashov's avatar
lukashov committed
1097 1098
            qam64_table_offset_re1 = 0;
            qam64_table_offset_im1 = 0;
1099

lukashov's avatar
lukashov committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
            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;
1123

lukashov's avatar
lukashov committed
1124 1125 1126 1127 1128 1129
          }

          // 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)|
1130
          // -  -        -    -  -         -  -     -  -  -       -
lukashov's avatar
lukashov committed
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
          // 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;
        }
1144
      }
1145
      else if ((mimo_mode >= UNIFORM_PRECODING11)&&(mimo_mode <= PUSCH_PRECODING1)) {
lukashov's avatar
lukashov committed
1146
  // this is for transmission modes 5-6 (1 layer)
1147
        *re_allocated = *re_allocated + 1;
lukashov's avatar
lukashov committed
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
        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
1159
          /*((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
1160 1161
          ((int16_t*)&txdataF[0][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*ONE_OVER_SQRT2_Q15)>>15);

1162
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1163 1164 1165
            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);
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
          }*/

          // 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
1177 1178 1179
          }

          break;
1180

lukashov's avatar
lukashov committed
1181
        case 4:
1182

lukashov's avatar
lukashov committed
1183 1184 1185 1186 1187 1188 1189 1190 1191
          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;
1192 1193


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


lukashov's avatar
lukashov committed
1202 1203 1204
           ((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]));

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

lukashov's avatar
lukashov committed
1208 1209
          if (frame_parms->nb_antennas_tx == 2) {
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1210 1211
            ((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
1212 1213 1214
          }

          break;
1215

lukashov's avatar
lukashov committed
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
        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;
1238

lukashov's avatar
lukashov committed
1239 1240 1241
          ((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]));

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

1245
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1246
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1247 1248
            ((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
1249
          }
1250

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

        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
1280 1281 1282 1283 1284
          // 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
1285 1286

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

1288
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1289
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1290 1291
            ((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
1292 1293 1294
          }

        break;
1295

lukashov's avatar
lukashov committed
1296
        case 4:
1297

lukashov's avatar
lukashov committed
1298 1299 1300 1301 1302 1303 1304 1305 1306
          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;
1307

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

lukashov's avatar
lukashov committed
1315 1316
           ((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]));
1317 1318 1319 1320 1321 1322

           // 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);
1323

1324
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1325
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1326 1327
            ((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
1328 1329 1330
          }

          break;
1331

lukashov's avatar
lukashov committed
1332
        case 6:
1333

lukashov's avatar
lukashov committed
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
          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;
1355

lukashov's avatar
lukashov committed
1356 1357
          ((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]));
1358 1359
          ((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);
1360

1361 1362 1363 1364
          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
1365
          }
1366

lukashov's avatar
lukashov committed
1367 1368
          break;
        }
1369

lukashov's avatar
lukashov committed
1370 1371
        if (dlsch1_harq) {
          switch (mod_order1) {
1372

lukashov's avatar
lukashov committed
1373 1374 1375 1376 1377 1378 1379 1380
          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
1381 1382
            ((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
1383

1384
            if (frame_parms->nb_antenna_ports_eNB== 2) {
lukashov's avatar
lukashov committed
1385
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1386 1387
              ((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
1388 1389 1390
            }

            break;
1391

lukashov's avatar
lukashov committed
1392
          case 4:
1393

lukashov's avatar
lukashov committed
1394 1395 1396 1397 1398 1399 1400 1401 1402
            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;
1403 1404


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

lukashov's avatar
lukashov committed
1412 1413
             ((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]));
1414 1415
             ((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);
1416

1417
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1418
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1419 1420
              ((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
1421 1422 1423
            }

            break;
1424

lukashov's avatar
lukashov committed
1425
          case 6:
1426

lukashov's avatar
lukashov committed
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
            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;
1447

lukashov's avatar
lukashov committed
1448 1449
            ((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]));
1450 1451
            ((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);
1452

1453
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1454
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1455 1456
              ((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
1457
            }
1458

lukashov's avatar
lukashov committed
1459
            break;
1460

lukashov's avatar
lukashov committed
1461 1462
          }
        }
1463
      }
1464

1465

1466
      if (mimo_mode == ALAMOUTI) {
1467 1468 1469 1470 1471 1472 1473
        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;
        }
1474
      }
1475

1476 1477 1478
      if (mimo_mode == TM7) {
        *re_allocated = *re_allocated + 1;

1479
        if (is_not_UEspecRS(lprime,re,frame_parms->Nid_cell%3,frame_parms->Ncp,7,Ns)) {
1480 1481 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

          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
1539

1540 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
              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
1578

1579 1580 1581
      } else if (mimo_mode == TM8) { //TM8,TM9,TM10
	// TODO: integrate second codeword!
	// in TM8, Nlayers is alwyas 1
1582
        if (is_not_UEspecRS(lprime,re,frame_parms->nushift,frame_parms->Ncp,8,Ns)) {
1583 1584
          switch (mod_order0) {
          case 2:  //QPSK
Raymond Knopp's avatar
 
Raymond Knopp committed
1585

1586
            //    printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
   
	    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;
1599
            }
Raymond Knopp's avatar
 
Raymond Knopp committed
1600

1601
            break;
1602

1603
          case 4:  //16QAM
1604 1605 1606 1607 1608 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
	    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];
	    }
1653 1654 1655 1656 1657

            break;

          case 6:  //64QAM

1658 1659 1660 1661 1662 1663 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
	    if (x0 && Nlayers0==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;
	      
              ((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];
            }
1689

1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
	    if (x1 && Nlayers1==0) {
	      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];
1720 1721 1722 1723 1724 1725
            }

            break;

          }
        }
1726
        else {
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
          for (p=7; p<8; p++) {
	    if (p==first_layer0 || p==first_layer1) {
	      if (frame_parms->Ncp==0) {
		ind = 3*lprime*dlsch0_harq->nb_rb+3*rb+mprime2;
		ind_dword = ind>>4 ;
		ind_qpsk_symb = ind&0xf ;
		
		if (((mprime2+rb)%12)==0) {
		  w = Wbar_NCP[p-7][lprime] ;
		} else {
		  w = Wbar_NCP[p-7][3-lprime] ;
		}
	      } else {
		ind = 4*lprime*dlsch0_harq->nb_rb+4*rb+mprime2 ;
		ind_dword = ind>>4 ;
		ind_qpsk_symb = ind&0xf ;
		int l = lprime%2 ;
		
		if ((mprime2%12)==0) {
		  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 */
	      txdataF[p][tti_offset] = qpsk_p[(phy_vars_eNB->lte_gold_uespec_table[0][Ns][lprime][ind_dword]>>(2*ind_qpsk_symb))&3] ;
	      mprime2++ ;
	    }
1757 1758
          }
        }
1759
      } else if (mimo_mode>=TM9_10) {
1760
        printf("allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
1761
        return(-1);
Raymond Knopp's avatar
 
Raymond Knopp committed
1762
      }
1763 1764 1765 1766 1767
    }
  }
  return(0);
}

1768

1769
int allocate_REs_in_RB_MCH(int32_t **txdataF,
1770
                           uint32_t *jj,
1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
                            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)
1781
{
1782

Xiwen JIANG's avatar
Xiwen JIANG committed
1783
  uint32_t tti_offset;
1784 1785 1786 1787 1788 1789 1790
  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;
1791
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
1792 1793 1794
  uint8_t first_re,last_re;
  int inc;
#ifdef DEBUG_DLSCH_MODULATION
1795
  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]);
1796 1797 1798 1799 1800
#endif

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

1802 1803 1804
  if ((l==2)||(l==10)) {
    inc=2;
    first_re=1;
1805
  } else if (l==6) {
1806 1807
    inc=2;
  }
1808 1809 1810

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

1811 1812
    if ((skip_dc == 1) && (re==(6+first_re)))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
1813

1814
    tti_offset = symbol_offset + re_off + re;
1815

lukashov's avatar
lukashov committed
1816
    //printf("re %d (jj %d)\n",re,*jj);
1817
    *re_allocated = *re_allocated + 1;
1818 1819


1820
    switch (mod_order) {
1821

1822
      case 2:  //QPSK
1823

1824
      //            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
1825
      ((int16_t*)&txdataF[4][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
1826 1827 1828

      *jj = *jj + 1;

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

      *jj = *jj + 1;

lukashov's avatar
lukashov committed
1833
      //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1834 1835 1836
      break;


1837
      case 4:  //16QAM
1838

1839 1840
    qam16_table_offset_re = 0;
    qam16_table_offset_im = 0;
1841

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

1845
    *jj=*jj+1;
1846

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

1850
    *jj=*jj+1;
1851 1852


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

1856
    *jj=*jj+1;
1857

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

1861
    *jj=*jj+1;
1862 1863


Xiwen JIANG's avatar
Xiwen JIANG committed
1864 1865
    ((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);
1866

1867
    break;
1868

1869
      case 6:  //64QAM
1870

1871 1872
    qam64_table_offset_re = 0;
    qam64_table_offset_im = 0;
1873

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

1877
    *jj=*jj+1;
1878

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

1882
    *jj=*jj+1;
1883

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

1887
    *jj=*jj+1;
1888

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

1892
    *jj=*jj+1;
1893

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

1897
    *jj=*jj+1;
1898

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

1902
    *jj=*jj+1;
1903

Xiwen JIANG's avatar
Xiwen JIANG committed
1904 1905
    ((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);
1906

1907
    break;
1908

1909
    }
1910 1911
  }

1912 1913 1914
  return(0);
}

1915
uint8_t get_pmi(uint8_t N_RB_DL, MIMO_mode_t mode, uint32_t pmi_alloc,uint16_t rb)
1916
{
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1917
  /*
1918 1919
  MIMO_mode_t mode   = dlsch_harq->mimo_mode;
  uint32_t pmi_alloc = dlsch_harq->pmi_alloc;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1920
  */
1921

Raymond Knopp's avatar
 
Raymond Knopp committed
1922
  switch (N_RB_DL) {
1923 1924 1925 1926 1927
    case 6:   // 1 PRB per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>(rb<<1))&3);
      else
        return((pmi_alloc>>rb)&1);
1928

1929
      break;
1930

1931 1932 1933 1934 1935 1936
    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);
1937

1938
      break;
1939

1940 1941 1942 1943 1944
    case 50: // 6 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb/6)<<1))&3);
      else
        return((pmi_alloc>>(rb/6))&1);
1945

1946
      break;
1947

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

1954
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1955
  }
1956 1957
}

Raymond Knopp's avatar
 
Raymond Knopp committed
1958

1959 1960 1961 1962 1963 1964 1965
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) &&
1966 1967 1968 1969
        (rb>((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4))) {
1970 1971 1972 1973 1974
      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)) ) {
1975
        return(1);
1976
      }
1977 1978
      //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) ) {
1979
        return(1);
1980 1981 1982 1983
      }
    } else {
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) &&
1984 1985 1986 1987
          (rb>((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==((nsymb>>1)-1)) ) {
        return(1);
1988 1989 1990
      }
      //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)) ) {
1991
        return(1);
1992 1993 1994 1995 1996 1997
      }
    }
  }
  else { // even N_RB_DL
    //PBCH
    if ((subframe_offset==0) &&
1998 1999 2000
        (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=nsymb>>1) && (l<((nsymb>>1) + 4)))
2001 2002 2003 2004 2005
      return(1);

    if (frame_parms->frame_type == TDD) { // TDD
      //SSS
      if (((subframe_offset==0)||
2006 2007 2008 2009 2010
           (subframe_offset==5)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==nsymb-1) ) {
         return(1);
2011
      }
2012

2013 2014
      //PSS
      if (((subframe_offset==1)||
2015 2016 2017 2018 2019
           (subframe_offset==6)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==2) ) {
         return(1);
2020 2021 2022 2023
      }
    } 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)) ) {
2024
         return(1);
2025
      }
2026

2027 2028
      //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)) ) {
2029
         return(1);
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039
      }
    }
  }

  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) {

2040
  //  printf("check_skiphalf : rb %d, subframe_offset %d,l %d, nsymb %d\n",rb,subframe_offset,l,nsymb);
2041 2042 2043 2044 2045

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

    // PBCH
    if ((subframe_offset==0) &&
2046 2047 2048
        (rb==((frame_parms->N_RB_DL>>1)-3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4)))
2049 2050 2051 2052 2053 2054 2055
      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)))
2056
        return(1);
2057
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)))
2058
        return(2);
2059 2060
      //PSS TDD
      if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==2))
2061
        return(1);
2062
      else if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==2))
2063
        return(2);
2064 2065 2066 2067
    }
    else { // FDD
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==((nsymb>>1)-1)))
2068
        return(1);
2069
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(((nsymb>>1)-1))))
2070
        return(2);
2071 2072
      //SSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && ((l==((nsymb>>1)-2))))
2073
        return(1);
2074
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && ((l==(nsymb>>1)-2)))
2075
        return(2);
2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
    }
  }
  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);
}

2095

2096
int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
2097
                     int32_t **txdataF,
2098 2099 2100 2101 2102 2103
                     int16_t amp,
                     uint32_t subframe_offset,
                     uint8_t num_pdcch_symbols,
                     LTE_eNB_DLSCH_t *dlsch0,
                     LTE_eNB_DLSCH_t *dlsch1)
{
2104
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
2105 2106

  uint8_t nsymb;
Cedric Roux's avatar
Cedric Roux committed
2107
  uint8_t harq_pid = -1; //= dlsch0->current_harq_pid;
Cedric Roux's avatar
Cedric Roux committed
2108
  LTE_DL_eNB_HARQ_t *dlsch0_harq = NULL;
Cedric Roux's avatar
Cedric Roux committed
2109
  LTE_DL_eNB_HARQ_t *dlsch1_harq = NULL; //= dlsch1->harq_processes[harq_pid];
2110
  uint32_t i,i2,jj,jj2,re_allocated,symbol_offset;
2111 2112
  uint16_t l,rb,re_offset;
  uint32_t rb_alloc_ind;
Cedric Roux's avatar
Cedric Roux committed
2113
  uint32_t *rb_alloc = NULL; //=dlsch0_harq->rb_alloc;
2114

2115 2116
  uint8_t pilots=0;
  uint8_t skip_dc,skip_half;
2117
  uint8_t mod_order0 = 0;
2118
  uint8_t mod_order1 = 0;
2119
  int16_t amp_rho_a, amp_rho_b;
2120 2121
  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];
2122

2123
  int16_t *qam_table_s0=NULL,*qam_table_s1=NULL;
2124 2125
#if 0
  /* TODO: variable to be removed? */
2126
  int (*allocate_REs)(PHY_VARS_eNB*,
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146
                      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 *);
2147
#endif
2148

2149 2150
  int P1_SHIFT[13],P2_SHIFT[13];
  int offset,nushiftmod3;
2151

2152
  uint8_t get_pmi_temp;
2153

Cedric Roux's avatar
Cedric Roux committed
2154
  MIMO_mode_t mimo_mode = -1;
2155 2156
  uint8_t mprime=0,Ns;
  int8_t  lprime=-1;
Xiwen JIANG's avatar
Xiwen JIANG committed
2157
  int aa=0;
2158

2159

Raymond Knopp's avatar
 
Raymond Knopp committed
2160
#ifdef DEBUG_DLSCH_MODULATION
2161 2162
  uint8_t Nl0=0;  //= dlsch0_harq->Nl;
  uint8_t Nl1=0;
Raymond Knopp's avatar
 
Raymond Knopp committed
2163
#endif
2164

2165

2166
  if ((dlsch0 != NULL) && (dlsch1 != NULL)){
2167

2168 2169
    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2170
    mimo_mode = dlsch0_harq->mimo_mode;
2171 2172 2173 2174 2175 2176
    mod_order0 = get_Qm(dlsch0_harq->mcs);
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

2177 2178 2179 2180 2181
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
    mod_order1 = get_Qm(dlsch1_harq->mcs);
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = dlsch1_harq->Nl;
#endif
2182 2183 2184 2185 2186

  }else if ((dlsch0 != NULL) && (dlsch1 == NULL)){

    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2187
    mimo_mode = dlsch0_harq->mimo_mode;
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203
    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

  }else if ((dlsch0 == NULL) && (dlsch1 != NULL)){

    harq_pid = dlsch1->current_harq_pid;
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
2204
    mimo_mode = dlsch1_harq->mimo_mode;
2205 2206 2207 2208 2209 2210 2211 2212 2213
    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
2214
    Nl1 = 0;
2215 2216
#endif

2217
  }
2218

2219
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
2220

2221
  nsymb = (frame_parms->Ncp==0) ? 14:12;
2222

2223
  if (dlsch0 != NULL){
2224
  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
2225
  amp_rho_b = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_b)>>13);
2226 2227 2228 2229
  } else{
  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);
  }
2230

2231
  if (mod_order0 == 4)
2232
    for (i=0;i<4; i++) {
2233 2234
      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);
2235
    }
2236
  else if (mod_order0 == 6)
2237
    for (i=0; i<8; i++) {
2238 2239
      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);
2240
    }
2241 2242

  if (mod_order1 == 4)
2243
    for (i=0; i<4; i++) {
2244 2245 2246
      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
2247
  else if (mod_order1 == 6)
2248
    for (i=0; i<8; i++) {
2249 2250
      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);
2251 2252
    }

2253
  //Modulation mapping (difference w.r.t. LTE specs)
2254 2255 2256

  jj=0;
  jj2=0;
2257
  re_allocated=0;
2258

2259

2260
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2261 2262
  for (l=num_pdcch_symbols; l<nsymb; l++) {

2263
#ifdef DEBUG_DLSCH_MODULATION
2264
    printf("Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc0 %lx, mod0 %d, mod1 %d, rb_alloc[0] %d)\n",
lukashov's avatar
lukashov committed
2265 2266 2267 2268 2269
            harq_pid,
            dlsch0_harq->mimo_mode,
            pmi2hex_2Ar2(dlsch0_harq->pmi_alloc),
            mod_order0,
            mod_order1,
2270
            rb_alloc[0]);
2271
#endif
2272 2273 2274

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
2275
        pilots=2;   // pilots in nushift+3, nushift+9
2276
      else if (l==7)
2277
        pilots=1;   // pilots in nushift, nushift+6
2278
      else
2279 2280
        pilots=0;
    } else {
2281
      if ((l==3)||(l==9))
2282
        pilots=2;
2283
      else if (l==6)
2284
        pilots=1;
2285
      else
2286
        pilots=0;
2287 2288
    }

2289 2290 2291
    if(mimo_mode==TM7){ //36.211 V8.6.0 2009-03
      mprime = 0;
      if (frame_parms->Ncp==0) { // normal prefix
2292 2293 2294 2295 2296 2297 2298 2299
        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
2300
        else
2301
          lprime=-1;
2302
      } else {
2303
        if (l==10)
2304
          lprime=2;
2305
        else if (l==7)
2306
          lprime=1;
2307
        else if (l==4)
2308
          lprime=0;
2309 2310
        else
          lprime=-1;
2311
      }
Xiwen JIANG's avatar
Xiwen JIANG committed
2312

2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 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
      
      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;
      }

2357
      /*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)*/
2358
      if (dlsch0 != NULL) {
Xiwen JIANG's avatar
Xiwen JIANG committed
2359
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
2360
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
2361
          (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] ;
2362 2363 2364 2365
        }
      }
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
        for (i=0;i<frame_parms->N_RB_DL*12/2;i++){
2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378
        (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] ;
2379
        }
Xiwen JIANG's avatar
Xiwen JIANG committed
2380
      }
2381

2382
      }
2383
    }
2384

2385
    Ns = 2*subframe_offset+(l>=(nsymb>>1));
2386

2387 2388 2389 2390 2391
    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) {
2392 2393 2394 2395 2396 2397 2398 2399
        //      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]--;
2400 2401
      }
      else {
2402 2403 2404 2405 2406 2407 2408
        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]--;
2409 2410 2411 2412
      }
    }
    P1_SHIFT[12]=1;P2_SHIFT[12]=1;

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

2416 2417
#if 0
    /* TODO: remove this code? */
2418
    allocate_REs = allocate_REs_in_RB;
2419
#endif
2420

2421 2422 2423 2424 2425 2426
    switch (mod_order0) {
    case 2:
      qam_table_s0 = NULL;
      break;
    case 4:
      if (pilots) {
2427
        qam_table_s0 = qam16_table_b0;
2428 2429
#if 0
        /* TODO: remove this code? */
2430 2431 2432
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_16QAM_siso :
          allocate_REs_in_RB;
2433
#endif
2434 2435
      }
      else {
2436
        qam_table_s0 = qam16_table_a0;
2437 2438
#if 0
        /* TODO: remove this code? */
2439 2440 2441
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_16QAM_siso :
          allocate_REs_in_RB;
2442
#endif
2443

2444 2445
      }
      break;
2446

2447 2448
    case 6:
      if (pilots) {
2449
        qam_table_s0 = qam64_table_b0;
2450 2451
#if 0
        /* TODO: remove this code? */
2452 2453 2454
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_64QAM_siso :
          allocate_REs_in_RB;
2455
#endif
2456 2457
      }
      else {
2458
        qam_table_s0 = qam64_table_a0;
2459 2460
#if 0
        /* TODO: remove this code? */
2461 2462 2463
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_64QAM_siso :
          allocate_REs_in_RB;
2464
#endif
2465 2466
      }
      break;
2467

2468
    }
2469

2470 2471 2472
    switch (mod_order1) {
    case 2:
      qam_table_s1 = NULL;
2473 2474
#if 0
        /* TODO: remove this code? */
2475
      allocate_REs = allocate_REs_in_RB;
2476
#endif
2477 2478 2479
      break;
    case 4:
      if (pilots) {
2480
        qam_table_s1 = qam16_table_b1;
2481 2482
      }
      else {
2483
        qam_table_s1 = qam16_table_a1;
2484 2485 2486 2487
      }
      break;
    case 6:
      if (pilots) {
2488
        qam_table_s1 = qam64_table_b1;
2489 2490
      }
      else {
2491
        qam_table_s1 = qam64_table_a1;
2492 2493
      }
      break;
2494

2495 2496
    }

2497
    //for (aa=0;aa<frame_parms->nb_antennas_tx;aa++)
lukashov's avatar
lukashov committed
2498
    //memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
2499
    //printf("symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511
    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;
2512

2513
      if (check_skip(rb,subframe_offset,frame_parms,l,nsymb)==1)
2514
        rb_alloc_ind = 0;
2515

2516 2517
      skip_half = check_skiphalf(rb,subframe_offset,frame_parms,l,nsymb);
      skip_dc   = check_skip_dc(rb,frame_parms);
2518

2519

2520

2521 2522
     if (dlsch0) {
        if (dlsch0_harq->Nlayers>1) {
2523
          LOG_E(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2524 2525
          return(-1);
        }
2526
      }
2527 2528 2529

      if (dlsch1) {
        if (dlsch1_harq->Nlayers>1) {
2530
          LOG_E(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2531 2532 2533 2534 2535 2536 2537 2538
          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);
2539

2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550
      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);

2551

2552
      allocate_REs_in_RB(phy_vars_eNB,
lukashov's avatar
lukashov committed
2553 2554 2555
                         txdataF,
                         &jj,
                         &jj2,
2556
			 rb,
lukashov's avatar
lukashov committed
2557 2558
                         re_offset,
                         symbol_offset,
2559 2560
                         dlsch0->harq_processes[harq_pid],
                         dlsch1->harq_processes[harq_pid],
lukashov's avatar
lukashov committed
2561 2562
                         pilots,
                         ((pilots) ? amp_rho_b : amp_rho_a),
2563
                         get_pmi_temp,
lukashov's avatar
lukashov committed
2564 2565 2566 2567
                         qam_table_s0,
                         qam_table_s1,
                         &re_allocated,
                         skip_dc,
2568
                         skip_half,
2569 2570 2571 2572 2573
                         lprime,
                         mprime,
                         Ns,
                         P1_SHIFT,
                         P2_SHIFT);
2574

Xiwen JIANG's avatar
Xiwen JIANG committed
2575 2576
          if ((mimo_mode == TM7) && (lprime>=0))
            mprime +=3+frame_parms->Ncp;
2577
      }
2578
      else {
2579
        //      printf("Unallocated rb %d/symbol %d, re_offset %d, jj %d\n",rb,l,re_offset,jj);
2580
      }
2581 2582
      re_offset+=12; // go to next RB

2583
      // check if we crossed the symbol boundary and skip DCs
2584

2585 2586 2587 2588 2589 2590 2591
      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
      }
    }
2592
  }
2593

2594
#ifdef DEBUG_DLSCH_MODULATION
2595
  msg("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,mimo_mode==TM7? 7 : (mimo_mode==TM8? 8 : 1)));
2596
#endif
2597

2598
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
2599

2600 2601 2602
  return (re_allocated);
}

lukashov's avatar
lukashov committed
2603

lukashov's avatar
lukashov committed
2604 2605 2606 2607 2608
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
2609
                         int G)
lukashov's avatar
lukashov committed
2610 2611 2612 2613
{

  uint8_t harq_pid = dlsch0->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
2614
  uint32_t i,jj,re_allocated=0;
lukashov's avatar
lukashov committed
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627
  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);

2628
  gain_lin_QPSK = (int16_t)((ONE_OVER_SQRT2_Q15));
2629

lukashov's avatar
lukashov committed
2630 2631 2632
  jj = 0;
  i = 0;
  while (jj <= G-1) {
2633

lukashov's avatar
lukashov committed
2634
    re_allocated = re_allocated + 1;
lukashov's avatar
lukashov committed
2635

lukashov's avatar
lukashov committed
2636 2637
    switch (mod_order0) {
    case 2:  //QPSK
2638

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

lukashov's avatar
lukashov committed
2641
      jj = jj + 1;
2642

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

lukashov's avatar
lukashov committed
2645
      jj = jj + 1;
2646

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

lukashov's avatar
lukashov committed
2650
      break;
lukashov's avatar
lukashov committed
2651

lukashov's avatar
lukashov committed
2652
    case 4:  //16QAM
lukashov's avatar
lukashov committed
2653

lukashov's avatar
lukashov committed
2654 2655
      qam16_table_offset_re = 0;
      qam16_table_offset_im = 0;
lukashov's avatar
lukashov committed
2656

lukashov's avatar
lukashov committed
2657 2658
      if (x0[jj] == 1)
        qam16_table_offset_re+=2;
lukashov's avatar
lukashov committed
2659

lukashov's avatar
lukashov committed
2660
      jj=jj+1;
lukashov's avatar
lukashov committed
2661

lukashov's avatar
lukashov committed
2662 2663
      if (x0[jj] == 1)
        qam16_table_offset_im+=2;
lukashov's avatar
lukashov committed
2664

lukashov's avatar
lukashov committed
2665
      jj=jj+1;
lukashov's avatar
lukashov committed
2666 2667


lukashov's avatar
lukashov committed
2668 2669
      if (x0[jj] == 1)
        qam16_table_offset_re+=1;
lukashov's avatar
lukashov committed
2670

lukashov's avatar
lukashov committed
2671
      jj=jj+1;
lukashov's avatar
lukashov committed
2672

lukashov's avatar
lukashov committed
2673 2674
      if (x0[jj] == 1)
        qam16_table_offset_im+=1;
lukashov's avatar
lukashov committed
2675

lukashov's avatar
lukashov committed
2676
      jj=jj+1;
lukashov's avatar
lukashov committed
2677 2678


lukashov's avatar
lukashov committed
2679 2680
      ((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];
2681 2682

      i++;
lukashov's avatar
lukashov committed
2683

lukashov's avatar
lukashov committed
2684
      break;
lukashov's avatar
lukashov committed
2685

lukashov's avatar
lukashov committed
2686
    case 6:
lukashov's avatar
lukashov committed
2687

lukashov's avatar
lukashov committed
2688 2689
      qam64_table_offset_re = 0;
      qam64_table_offset_im = 0;
lukashov's avatar
lukashov committed
2690

lukashov's avatar
lukashov committed
2691 2692
      if (x0[jj] == 1)
      qam64_table_offset_re+=4;
lukashov's avatar
lukashov committed
2693

lukashov's avatar
lukashov committed
2694
      jj=jj+1;
lukashov's avatar
lukashov committed
2695

lukashov's avatar
lukashov committed
2696 2697
      if (x0[jj] == 1)
        qam64_table_offset_im+=4;
lukashov's avatar
lukashov committed
2698

lukashov's avatar
lukashov committed
2699
      jj=jj+1;
lukashov's avatar
lukashov committed
2700

lukashov's avatar
lukashov committed
2701 2702
      if (x0[jj] == 1)
        qam64_table_offset_re+=2;
lukashov's avatar
lukashov committed
2703

lukashov's avatar
lukashov committed
2704
      jj=jj+1;
lukashov's avatar
lukashov committed
2705

lukashov's avatar
lukashov committed
2706 2707
      if (x0[jj] == 1)
        qam64_table_offset_im+=2;
lukashov's avatar
lukashov committed
2708

lukashov's avatar
lukashov committed
2709
      jj=jj+1;
lukashov's avatar
lukashov committed
2710

lukashov's avatar
lukashov committed
2711 2712
      if (x0[jj] == 1)
        qam64_table_offset_re+=1;
lukashov's avatar
lukashov committed
2713

lukashov's avatar
lukashov committed
2714
      jj=jj+1;
lukashov's avatar
lukashov committed
2715

lukashov's avatar
lukashov committed
2716 2717
      if (x0[jj] == 1)
        qam64_table_offset_im+=1;
lukashov's avatar
lukashov committed
2718

lukashov's avatar
lukashov committed
2719
      jj=jj+1;
lukashov's avatar
lukashov committed
2720 2721


lukashov's avatar
lukashov committed
2722 2723
      ((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);
2724

lukashov's avatar
lukashov committed
2725
      i++;
2726

lukashov's avatar
lukashov committed
2727
      break;
lukashov's avatar
lukashov committed
2728
      }
2729

lukashov's avatar
lukashov committed
2730
    }
lukashov's avatar
lukashov committed
2731 2732 2733


#ifdef DEBUG_DLSCH_MODULATION
2734
  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
2735 2736 2737 2738 2739 2740 2741 2742
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);

  return (re_allocated);
}


2743
int mch_modulation(int32_t **txdataF,
2744 2745 2746
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
2747
                   LTE_eNB_DLSCH_t *dlsch_eNB)
2748
{
2749 2750 2751 2752
  uint8_t nsymb,nsymb_pmch;
  uint32_t i,jj,re_allocated,symbol_offset;
  uint16_t l,rb,re_offset;
  uint8_t skip_dc=0;
2753
  uint8_t mod_order = get_Qm(dlsch_eNB->harq_processes[0]->mcs);
2754 2755 2756 2757 2758
  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;
2759

2760
  if (mod_order == 4)
2761
    for (i=0; i<4; i++) {
2762 2763 2764
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
2765
    for (i=0; i<8; i++) {
2766
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
2767 2768 2769
    }

  jj=0;
2770
  re_allocated=0;
2771

2772
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2773 2774
  for (l=2; l<nsymb_pmch; l++) {

2775
#ifdef DEBUG_DLSCH_MODULATION
2776
    printf("Generating MCH (mod %d) in subframe %d for symbol %d\n",mod_order, subframe_offset,l);
2777
#endif
2778 2779 2780 2781

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

2782 2783
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

2784 2785

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

lukashov's avatar
lukashov committed
2787
    if (rb==(frame_parms->N_RB_DL>>1))
2788 2789 2790
          skip_dc = 1;
        else
          skip_dc = 0;
2791 2792 2793 2794

      }

      if (mod_order == 4)
2795
        qam_table_s = qam16_table_a;
2796
      else if (mod_order == 6)
2797
        qam_table_s = qam64_table_a;
2798
      else
2799
        qam_table_s = NULL;
2800

lukashov's avatar
lukashov committed
2801
      //printf("Allocated rb %d, subframe_offset %d,amp %d\n",rb,subframe_offset,amp);
2802
      allocate_REs_in_RB_MCH(txdataF,
2803 2804 2805
                             &jj,
                             re_offset,
                             symbol_offset,
2806
                             dlsch_eNB->harq_processes[0]->e,
2807 2808 2809 2810 2811 2812 2813 2814
                             l,
                             mod_order,
                             amp,
                             qam_table_s,
                             &re_allocated,
                             skip_dc,
                             frame_parms);

2815
      re_offset+=12; // go to next RB
2816

2817 2818
      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
2819 2820 2821 2822
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
2823 2824 2825 2826 2827
      }
    }
  }

#ifdef DEBUG_DLSCH_MODULATION
2828
  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*/));
2829
#endif
2830 2831

  return (re_allocated);
2832
}