dlsch_modulation.c 87.2 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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
#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"
39
#include "UTIL/LOG/vcd_signal_dumper.h"
40

41
//#define DEBUG_DLSCH_MODULATION 1
42 43 44

//#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)

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

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

51 52 53 54 55 56
  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);
57
  } else { // 2 antenna pilots
58 59 60
    if ((re!=nushiftmod3) && (re!=nushiftmod3+6) && (re!=nushiftmod3+3) && (re!=nushiftmod3+9))
      return(1);
  }
61

62 63 64
  return(0);
}

Xiwen JIANG's avatar
Xiwen JIANG committed
65 66 67 68
/*uint8_t is_not_UEspecRS(int first_layer,int re)
{
  return(1);
}*/
69
uint8_t is_not_UEspecRS(int8_t lprime, uint8_t re, uint8_t nushift, uint8_t Ncp, uint8_t beamforming_mode)
70
{
71 72
  uint8_t offset = (lprime==1||lprime==3)?2:0;
  if (lprime==-1)
73 74
    return(1);

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

    default:
90
      LOG_E(PHY,"is_not_UEspecRS() [dlsch_modulation.c] : ERROR, unknown beamforming_mode %d\n",beamforming_mode);
91 92
      return(-1);
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
93

94
  return(0);
Raymond Knopp's avatar
 
Raymond Knopp committed
95 96
}

97 98
void generate_64qam_table(void)
{
99 100 101 102

  int a,b,c,index;


103 104 105 106 107 108
  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
      }
109 110
}

111 112
void generate_16qam_table(void)
{
113 114 115

  int a,b,index;

116 117 118 119 120
  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));
    }
121 122 123 124 125
}




126 127
void layer1prec2A(int32_t *antenna0_sample, int32_t *antenna1_sample, uint8_t precoding_index)
{
128 129 130

  switch (precoding_index) {

131 132 133
    case 0: // 1 1
      *antenna1_sample=*antenna0_sample;
      break;
134

135 136 137 138
    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;
139

140 141 142 143
    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;
144

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

  // normalize
152
  /*  ((int16_t *)antenna0_sample)[0] = (int16_t)((((int16_t *)antenna0_sample)[0]*ONE_OVER_SQRT2_Q15)>>15);
153 154
      ((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);  */
155
}
156

157 158 159
uint32_t FOUR[2]={0,4};
uint32_t TWO[2]={0,2};

160
int allocate_REs_in_RB_no_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
                                            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)
181 182
{

183
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
184 185 186 187 188 189 190 191 192
  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) {
193
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
194 195
         re<12;
         re++,x0p+=4,tti_offset++) {
196

197 198 199 200 201 202 203 204 205
      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 {
206 207
    // 1st half of PRB
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
208 209
         re<6;
         re++,x0p+=4,tti_offset++) {
210

211 212 213 214 215 216 217
      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];
    }
218 219
    // 2nd half of PRB
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+7;
220 221
         re<12;
         re++,x0p+=4,tti_offset++) {
222

223 224 225 226 227 228 229 230 231 232
      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;
233

234 235 236
    return(0);
}

237
int allocate_REs_in_RB_pilots_16QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
                                         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)
258
{
259

260

261
  LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_eNB->frame_parms;
262 263 264 265 266 267 268 269 270 271 272

  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) {
273
    //    LOG_I(PHY,"pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
274
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
275 276
         re<12;
         x0p+=4) {
277

278 279 280 281 282 283
      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];
284
      //      LOG_I(PHY,"pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
285 286 287 288 289
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
290
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
291 292
         re<6;
         x0p+=4) {
293

294 295 296 297 298 299 300 301 302 303
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }

304
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+6+P1_SHIFT[6];
305 306
         re<12;
         x0p+=4) {
307

308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
      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);
}

324
int allocate_REs_in_RB_no_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
                                            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)
345 346
{

347
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
348 349 350 351 352 353 354 355 356 357 358

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

359
    x0p=&x0[*jj],tti_offset=symbol_offset+re_offset;
360

361
    /*    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
362 363
         re<12;
         re+=4,x0p+=24,tti_offset+=4) {*/
364

365 366
      qam64_table_offset_re=(x0p[0]<<2)|(x0p[2]<<1)|x0p[4];
      qam64_table_offset_im=(x0p[1]<<2)|(x0p[3]<<1)|x0p[5];
367 368
      ((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];
369

370 371
      qam64_table_offset_re=(x0p[6]<<2)|(x0p[8]<<1)|x0p[10];
      qam64_table_offset_im=(x0p[7]<<2)|(x0p[9]<<1)|x0p[11];
372 373 374
      ((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];

375 376
      qam64_table_offset_re=(x0p[12]<<2)|(x0p[14]<<1)|x0p[16];
      qam64_table_offset_im=(x0p[13]<<2)|(x0p[15]<<1)|x0p[17];
377 378 379
      ((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];

380 381
      qam64_table_offset_re=(x0p[18]<<2)|(x0p[20]<<1)|x0p[22];
      qam64_table_offset_im=(x0p[19]<<2)|(x0p[21]<<1)|x0p[23];
382 383
      ((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];
384 385 386 387 388 389 390 391 392 393 394 395 396 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

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


      //    }
427 428
  }
  else {
429
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset,re=0;
430 431
         re<6;
         re++,x0p+=6,tti_offset++) {
432

433 434 435 436 437 438 439 440 441 442
      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];
    }

443
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+7;
444 445
         re<12;
         re++,x0p+=6,tti_offset++) {
446

447 448 449 450 451 452 453 454 455 456 457 458 459
      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;
460

461 462 463
  return(0);
}

464
int allocate_REs_in_RB_pilots_64QAM_siso(PHY_VARS_eNB* phy_vars_eNB,
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
                                         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)
485
{
486

487

488
  LTE_DL_FRAME_PARMS *frame_parms=&phy_vars_eNB->frame_parms;
489 490 491 492 493 494 495 496 497 498 499

  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) {
500
    //    LOG_I(PHY,"pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
501
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
502 503
         re<12;
         x0p+=6) {
504

505 506 507 508 509 510 511 512
      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];
513
      //      LOG_I(PHY,"pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
514 515 516 517 518
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
519
    for (x0p=&x0[*jj],tti_offset=symbol_offset+re_offset+P1_SHIFT[0],re=P1_SHIFT[0];
520 521
         re<6;
         x0p+=6) {
522

523 524 525 526 527 528 529 530 531 532 533 534
      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];
    }

535
    for (tti_offset=symbol_offset+re_offset-frame_parms->ofdm_symbol_size+6+P1_SHIFT[6];
536 537
         re<12;
         x0p+=6) {
538

539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
      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);
}

557
int allocate_REs_in_RB(PHY_VARS_eNB* phy_vars_eNB,
558
                       int32_t **txdataF,
559 560 561 562 563 564 565 566 567 568 569 570 571
                       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,
572
                       uint8_t skip_half,
573 574 575 576 577
                       uint8_t lprime,
                       uint8_t mprime,
                       uint8_t Ns,
                       int *P1_SHIFT,
                       int *P2_SHIFT)
578
{
579

580
  uint8_t *x0 = NULL;
Cedric Roux's avatar
Cedric Roux committed
581
  MIMO_mode_t mimo_mode = -1;
Xiwen JIANG's avatar
Xiwen JIANG committed
582

583 584
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;

585

586
  int first_layer0 = -1; //= dlsch0_harq->first_layer;
Cedric Roux's avatar
Cedric Roux committed
587
  int Nlayers0 = -1; //  = dlsch0_harq->Nlayers;
588 589
  uint8_t mod_order0=0; 
  uint8_t mod_order1=0; 
590
  uint8_t precoder_index0,precoder_index1;
591

Raymond Knopp's avatar
 
Raymond Knopp committed
592 593 594 595
  uint8_t *x1=NULL;
  // Fill these in later for TM8-10
  //  int Nlayers1;
  //  int first_layer1;
Xiwen JIANG's avatar
Xiwen JIANG committed
596

597
  int use2ndpilots = (frame_parms->nb_antenna_ports_eNB==1)?1:0;
598

599
  uint32_t tti_offset; //,aa;
600 601 602 603 604
  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;
605 606 607 608 609 610 611 612 613 614 615
  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;

616 617
  int16_t gain_lin_QPSK;//,gain_lin_16QAM1,gain_lin_16QAM2;
  int16_t re_off=re_offset;
618

619 620 621
  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;
  int16_t tmp_amp=amp;
622
  int s=1;
623
  int mprime2 = mprime,ind,ind_dword,ind_qpsk_symb;
624 625 626

  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);

627 628 629 630 631 632 633 634 635 636
  int32_t qpsk[4];
  ((int16_t *)&qpsk[0])[0] = gain_lin_QPSK;
  ((int16_t *)&qpsk[0])[1] = gain_lin_QPSK;
  ((int16_t *)&qpsk[1])[0] = -gain_lin_QPSK;
  ((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;;
  ((int16_t *)&qpsk[3])[1] = -gain_lin_QPSK;

637 638 639 640 641 642
  if ((dlsch0_harq != NULL) && (dlsch1_harq != NULL)) { //this is for TM3, TM4

    x0 = dlsch0_harq->e;
    mimo_mode = dlsch0_harq->mimo_mode;
    first_layer0 = dlsch0_harq->first_layer;
    Nlayers0 = dlsch0_harq->Nlayers;
643
    mod_order0 = dlsch0_harq->Qm;
644
    x1             = dlsch1_harq->e;
Raymond Knopp's avatar
 
Raymond Knopp committed
645
    // Fill these in later for TM8-10
646
    //    Nlayers1       = dlsch1_harq->Nlayers;
Raymond Knopp's avatar
 
Raymond Knopp committed
647
    //    first_layer1   = dlsch1_harq->first_layer;
648
    mod_order1     = dlsch1_harq->Qm;
649

650 651 652 653 654 655
  } else if ((dlsch0_harq != NULL) && (dlsch1_harq == NULL)){ //This is for SIS0 TM1, TM6, etc

    x0 = dlsch0_harq->e;
    mimo_mode = dlsch0_harq->mimo_mode;
    first_layer0 = dlsch0_harq->first_layer;
    Nlayers0 = dlsch0_harq->Nlayers;
656
    mod_order0 = dlsch0_harq->Qm;
657 658 659 660 661 662 663

  } else if ((dlsch0_harq == NULL) && (dlsch1_harq != NULL)){ // This is for TM4 retransmission

    x0 = dlsch1_harq->e;
    mimo_mode = dlsch1_harq->mimo_mode;
    first_layer0 = dlsch1_harq->first_layer;
    Nlayers0 = dlsch1_harq->Nlayers;
664
    mod_order0 = dlsch1_harq->Qm;
665

666
  }
667

668 669
  if (dlsch0_harq != NULL){
    #ifdef DEBUG_DLSCH_MODULATION
670
      LOG_I(PHY,"allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d\n",mod_order0,symbol_offset,re_offset,skip_dc,skip_half,*jj, x0[*jj], x0[1+*jj]);
671 672 673
    #endif
  } else{
    #ifdef DEBUG_DLSCH_MODULATION
674
      LOG_I(PHY,"allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d\n",mod_order0,symbol_offset,re_offset,skip_dc,skip_half,*jj, x0[*jj], x0[1+*jj]);
675 676
    #endif
  }
677 678 679 680

  first_re=0;
  last_re=12;

681
  if (skip_half==1)
682 683 684
    last_re=6;
  else if (skip_half==2)
    first_re=6;
685

686

Xiwen JIANG's avatar
Xiwen JIANG committed
687
  for (re=first_re; re<last_re; re++) {
688
  // LOG_I(PHY,"element %d precoder_index for allocation %d\n",re, precoder_index );
689

690 691
    if ((skip_dc == 1) && (re==6))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
692

693
    tti_offset = symbol_offset + re_off + re;
694

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

697
    if (is_not_pilot(pilots,re,frame_parms->nushift,use2ndpilots)==1) {
698
      //LOG_I(PHY,"re %d (jj %d)\n",re,*jj);
Raymond Knopp's avatar
 
Raymond Knopp committed
699

700

701
      if (mimo_mode == SISO) {  //SISO mapping
702 703 704 705 706
        *re_allocated = *re_allocated + 1;

        switch (mod_order0) {
        case 2:  //QPSK

707

708
          //LOG_I(PHY,"re %d %d(%d) : %d,%d => ",re,tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
709
          ((int16_t*)&txdataF[0][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
710 711 712

          *jj = *jj + 1;

713
          ((int16_t*)&txdataF[0][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744

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

745 746
          ((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];
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785

          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;

786 787
          ((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];
788 789 790 791

          break;

        }
792
      }
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816

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

        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;

817
	  //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
818
          // normalization for 2 tx antennas
819 820 821 822
          ((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]));
823

lukashov's avatar
lukashov committed
824
        break;
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846

        case 4:  //16QAM

          // Antenna 0 position n
          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;

847 848
          //((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);
849 850 851
	  //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]);
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872

          // Antenna 1 position n Real part -> -x1*

          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;

873 874
          //((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);
875 876 877
	  //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]);
878

879 880
         //((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];
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908

          break;

        case 6:   // 64-QAM

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

909 910
          //((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);
911 912 913
	  //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]);
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937


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

938 939
          //((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);
940 941 942
	  //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]);
943 944 945 946


          break;
        }
947
  // fill in the rest of the ALAMOUTI precoding
948 949 950 951 952
        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];
lukashov's avatar
lukashov committed
953 954
        }
        else {
955 956 957 958 959
          ((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];
        }
960
      }
961
      else if (mimo_mode == LARGE_CDD) {
962 963 964

        *re_allocated = *re_allocated + 1;

965
        if (frame_parms->nb_antenna_ports_eNB == 2) {
966
          switch (mod_order0) {
lukashov's avatar
lukashov committed
967

968 969 970 971 972 973
          default:
            LOG_E(PHY,"Unknown mod_order0 %d\n",mod_order0);
            xx0_re=xx0_im=0;
            break;

          case 2:  //QPSK
974
            //LOG_I(PHY,"%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
975 976 977 978
            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;
979
            //LOG_I(PHY,"%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
            break;

          case 4:  //16QAM

            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;

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

            xx0_re = qam_table_s0[qam16_table_offset_re0];
            xx0_im = qam_table_s0[qam16_table_offset_im0];

            break;

          case 6:  //64QAM


            qam64_table_offset_re0 = 0;
            qam64_table_offset_im0 = 0;

            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;

          }

          switch (mod_order1) {
lukashov's avatar
lukashov committed
1038

1039 1040 1041 1042 1043 1044
          default:
            LOG_E(PHY,"Unknown mod_order1 %d\n",mod_order1);
            xx1_re=xx1_im=0;
            break;

          case 2:  //QPSK
1045
            //LOG_I(PHY,"%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1046 1047 1048 1049
            xx1_re = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj2 = *jj2 + 1;
            xx1_im = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
            *jj2 = *jj2 + 1;
1050
            //LOG_I(PHY,"%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
            break;

          case 4:  //16QAM

            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;

          case 6:  //64QAM

            qam64_table_offset_re1 = 0;
            qam64_table_offset_im1 = 0;

            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;

          }

          // 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)|
          // -  -        -    -  -         -  -     -  -  -       -
          // 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));
          /*
1117
          LOG_I(PHY,"CDD: xx0 (%d,%d), xx1(%d,%d), s(%d), txF[0] (%d,%d), txF[1] (%d,%d)\n",
1118 1119 1120 1121 1122 1123
           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;
        }
1124
      }
1125
      else if ((mimo_mode >= UNIFORM_PRECODING11)&&(mimo_mode <= PUSCH_PRECODING1)) {
lukashov's avatar
lukashov committed
1126
  // this is for transmission modes 5-6 (1 layer)
1127 1128 1129 1130
        *re_allocated = *re_allocated + 1;
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);

        switch (mod_order0) {
lukashov's avatar
lukashov committed
1131
        case 2:
1132 1133 1134 1135 1136 1137

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

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

1142
          if (frame_parms->nb_antenna_ports_eNB == 2) {
1143 1144 1145
            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);
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
          }*/

          // 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];
1157 1158 1159 1160
          }

          break;

lukashov's avatar
lukashov committed
1161
        case 4:
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181

          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;


lukashov's avatar
lukashov committed
1182 1183
           ((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]));
1184

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

lukashov's avatar
lukashov committed
1188
          if (frame_parms->nb_antennas_tx == 2) {
1189 1190 1191 1192 1193 1194 1195
            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];
          }

          break;

lukashov's avatar
lukashov committed
1196
        case 6:
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218

          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;

lukashov's avatar
lukashov committed
1219 1220
          ((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]));
1221 1222 1223 1224

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

1225
          if (frame_parms->nb_antenna_ports_eNB == 2) {
1226 1227 1228 1229 1230 1231
            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];
          }

          break;
lukashov's avatar
lukashov committed
1232
        }
1233
      }
1234
      else if ((mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1)&&(mimo_mode <= DUALSTREAM_PUSCH_PRECODING)) {
lukashov's avatar
lukashov committed
1235
  // this is for transmission mode 4 (1 layer)
1236
        *re_allocated = *re_allocated + 1;
1237

lukashov's avatar
lukashov committed
1238 1239 1240 1241 1242 1243 1244 1245 1246
        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 {
1247
         LOG_I(PHY,"problem with precoder in TM4\n");
lukashov's avatar
lukashov committed
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
          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
1260 1261 1262 1263 1264
          // 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
1265

1266
          //LOG_I(PHY,"%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1267

1268
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1269
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1270 1271
            ((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
1272 1273 1274
          }

        break;
1275

lukashov's avatar
lukashov committed
1276
        case 4:
1277

lukashov's avatar
lukashov committed
1278 1279 1280 1281 1282 1283 1284 1285 1286
          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;
1287

lukashov's avatar
lukashov committed
1288 1289 1290 1291 1292 1293
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
1294

lukashov's avatar
lukashov committed
1295 1296
           ((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]));
1297 1298 1299 1300 1301 1302

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

1304
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1305
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index0);
1306 1307
            ((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
1308 1309 1310
          }

          break;
1311

lukashov's avatar
lukashov committed
1312
        case 6:
1313

lukashov's avatar
lukashov committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
          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;
1335

lukashov's avatar
lukashov committed
1336 1337
          ((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]));
1338 1339
          ((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);
1340

1341 1342 1343 1344
          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
1345
          }
1346

lukashov's avatar
lukashov committed
1347 1348
          break;
        }
1349

lukashov's avatar
lukashov committed
1350 1351
        if (dlsch1_harq) {
          switch (mod_order1) {
1352

lukashov's avatar
lukashov committed
1353 1354 1355 1356 1357 1358 1359 1360
          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
1361 1362
            ((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
1363

1364
            if (frame_parms->nb_antenna_ports_eNB== 2) {
lukashov's avatar
lukashov committed
1365
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1366 1367
              ((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
1368 1369 1370
            }

            break;
1371

lukashov's avatar
lukashov committed
1372
          case 4:
1373

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


lukashov's avatar
lukashov committed
1385 1386 1387 1388 1389 1390
            if (x1[*jj2] == 1)
              qam16_table_offset_re+=1;
            *jj2=*jj2+1;
            if (x1[*jj2] == 1)
              qam16_table_offset_im+=1;
            *jj2=*jj2+1;
1391

lukashov's avatar
lukashov committed
1392 1393
             ((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]));
1394 1395
             ((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);
1396

1397
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1398
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1399 1400
              ((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
1401 1402 1403
            }

            break;
1404

lukashov's avatar
lukashov committed
1405
          case 6:
1406

lukashov's avatar
lukashov committed
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
            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;
1427

lukashov's avatar
lukashov committed
1428 1429
            ((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]));
1430 1431
            ((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);
1432

1433
            if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1434
              layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index1);
1435 1436
              ((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
1437
            }
1438

lukashov's avatar
lukashov committed
1439
            break;
1440

lukashov's avatar
lukashov committed
1441 1442
          }
        }
Xiwen JIANG's avatar
Xiwen JIANG committed
1443 1444
      }

1445

Xiwen JIANG's avatar
Xiwen JIANG committed
1446 1447 1448 1449 1450 1451 1452 1453 1454
      if (mimo_mode == ALAMOUTI) {
        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;
        }
      }
1455

1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
      if (mimo_mode == TM7) {
        *re_allocated = *re_allocated + 1;

        if (is_not_UEspecRS(lprime,re,frame_parms->Nid_cell%3,frame_parms->Ncp,7)) {

          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;

1469
              //LOG_I(PHY,"%d(%d) : %d,%d =>
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 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 1539 1540 1541 1542 1543 1544 1545 1546 1547
              //",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;

              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
1548
          //LOG_I(PHY,"precoding UE spec RS\n");
1549 1550 1551 1552 1553 1554 1555 1556 1557

          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
1558

1559
      } else if (mimo_mode >= TM8) { //TM8,TM9,TM10
1560
        //uint8_t is_not_UEspecRS(int8_t lprime, uint8_t re, uint8_t nushift, uint8_t Ncp, uint8_t beamforming_mode)
1561

1562
        if (is_not_UEspecRS(lprime,re,frame_parms->nushift,frame_parms->Ncp,8)) {
Xiwen JIANG's avatar
Xiwen JIANG committed
1563 1564 1565
          switch (mod_order0) {
          case 2:  //QPSK

1566
            //    LOG_I(PHY,"%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
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
            for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
              ((int16_t*)&txdataF[layer][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
              *jj = *jj + 1;
              ((int16_t*)&txdataF[layer][tti_offset])[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
              *jj = *jj + 1;
            }

            break;

          case 4:  //16QAM
1577
            if (is_not_UEspecRS(lprime,re,frame_parms->nushift,frame_parms->Ncp,8)) {
Xiwen JIANG's avatar
Xiwen JIANG committed
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 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
              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;

              for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
                ((int16_t*)&txdataF[layer][tti_offset])[0] = qam_table_s0[qam16_table_offset_re];
                ((int16_t*)&txdataF[layer][tti_offset])[1] = qam_table_s0[qam16_table_offset_im];
              }
            }

            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;

            for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
              ((int16_t*)&txdataF[layer][tti_offset])[0] = qam_table_s0[qam64_table_offset_re];
              ((int16_t*)&txdataF[layer][tti_offset])[1] = qam_table_s0[qam64_table_offset_im];
            }

            break;

          }
1652
        }
Xiwen JIANG's avatar
Xiwen JIANG committed
1653
      } else if (mimo_mode>=TM9_10) {
1654
        LOG_I(PHY,"allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
Xiwen JIANG's avatar
Xiwen JIANG committed
1655
        return(-1);
1656
      }
1657 1658 1659 1660 1661
    }
  }
  return(0);
}

1662

1663
int allocate_REs_in_RB_MCH(int32_t **txdataF,
1664
                           uint32_t *jj,
1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
                            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)
1675
{
1676

Xiwen JIANG's avatar
Xiwen JIANG committed
1677
  uint32_t tti_offset;
1678 1679 1680 1681 1682 1683 1684
  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;
1685
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
1686 1687 1688
  uint8_t first_re,last_re;
  int inc;
#ifdef DEBUG_DLSCH_MODULATION
1689
  LOG_I(PHY,"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]);
1690 1691 1692 1693 1694
#endif

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

1696 1697 1698
  if ((l==2)||(l==10)) {
    inc=2;
    first_re=1;
1699
  } else if (l==6) {
1700 1701
    inc=2;
  }
1702 1703 1704

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

1705 1706
    if ((skip_dc == 1) && (re==(6+first_re)))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
1707

1708
    tti_offset = symbol_offset + re_off + re;
1709

1710
    //LOG_I(PHY,"re %d (jj %d)\n",re,*jj);
1711
    *re_allocated = *re_allocated + 1;
1712 1713


1714
    switch (mod_order) {
1715

1716
      case 2:  //QPSK
1717

1718
      //            LOG_I(PHY,"%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
1719
      ((int16_t*)&txdataF[4][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
1720

Xiwen JIANG's avatar
Xiwen JIANG committed
1721
      *jj = *jj + 1;
1722

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

Xiwen JIANG's avatar
Xiwen JIANG committed
1725
      *jj = *jj + 1;
1726

1727
      //LOG_I(PHY,"%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1728 1729 1730
      break;


1731
      case 4:  //16QAM
1732

1733 1734
    qam16_table_offset_re = 0;
    qam16_table_offset_im = 0;
1735

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

1739
    *jj=*jj+1;
1740

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

1744
    *jj=*jj+1;
1745 1746


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

1750
    *jj=*jj+1;
1751

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

1755
    *jj=*jj+1;
1756 1757


Xiwen JIANG's avatar
Xiwen JIANG committed
1758 1759
    ((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);
1760

1761
    break;
1762

1763
      case 6:  //64QAM
1764

1765 1766
    qam64_table_offset_re = 0;
    qam64_table_offset_im = 0;
1767

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

1771
    *jj=*jj+1;
1772

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

1776
    *jj=*jj+1;
1777

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

1781
    *jj=*jj+1;
1782

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

1786
    *jj=*jj+1;
1787

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

1791
    *jj=*jj+1;
1792

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

1796
    *jj=*jj+1;
1797

Xiwen JIANG's avatar
Xiwen JIANG committed
1798 1799
    ((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);
1800

1801
    break;
1802

1803
    }
1804 1805
  }

1806 1807 1808
  return(0);
}

1809
uint8_t get_pmi(uint8_t N_RB_DL, MIMO_mode_t mode, uint32_t pmi_alloc,uint16_t rb)
1810
{
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1811
  /*
1812 1813
  MIMO_mode_t mode   = dlsch_harq->mimo_mode;
  uint32_t pmi_alloc = dlsch_harq->pmi_alloc;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1814
  */
1815

Raymond Knopp's avatar
 
Raymond Knopp committed
1816
  switch (N_RB_DL) {
1817 1818 1819 1820 1821
    case 6:   // 1 PRB per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>(rb<<1))&3);
      else
        return((pmi_alloc>>rb)&1);
1822

1823
      break;
1824

1825 1826 1827 1828 1829 1830
    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);
1831

1832
      break;
1833

1834 1835 1836 1837 1838
    case 50: // 6 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb/6)<<1))&3);
      else
        return((pmi_alloc>>(rb/6))&1);
1839

1840
      break;
1841

1842 1843 1844 1845 1846
    case 100: // 8 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb>>3)<<1))&3);
      else
        return((pmi_alloc>>(rb>>3))&1);
1847

1848
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1849
  }
1850 1851
}

Raymond Knopp's avatar
 
Raymond Knopp committed
1852

1853 1854 1855 1856 1857 1858 1859
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) &&
1860 1861 1862 1863
        (rb>((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4))) {
1864 1865 1866 1867 1868
      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)) ) {
1869
        return(1);
1870
      }
1871 1872
      //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) ) {
1873
        return(1);
1874 1875 1876 1877
      }
    } else {
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) &&
1878 1879 1880 1881
          (rb>((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==((nsymb>>1)-1)) ) {
        return(1);
1882 1883 1884
      }
      //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)) ) {
1885
        return(1);
1886 1887 1888 1889 1890 1891
      }
    }
  }
  else { // even N_RB_DL
    //PBCH
    if ((subframe_offset==0) &&
1892 1893 1894
        (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
        (rb<((frame_parms->N_RB_DL>>1)+3)) &&
        (l>=nsymb>>1) && (l<((nsymb>>1) + 4)))
1895 1896 1897 1898 1899
      return(1);

    if (frame_parms->frame_type == TDD) { // TDD
      //SSS
      if (((subframe_offset==0)||
1900 1901 1902 1903 1904
           (subframe_offset==5)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==nsymb-1) ) {
         return(1);
1905
      }
1906

1907 1908
      //PSS
      if (((subframe_offset==1)||
1909 1910 1911 1912 1913
           (subframe_offset==6)) &&
          (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
          (rb<((frame_parms->N_RB_DL>>1)+3)) &&
          (l==2) ) {
         return(1);
1914 1915 1916 1917
      }
    } 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)) ) {
1918
         return(1);
1919
      }
1920

1921 1922
      //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)) ) {
1923
         return(1);
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933
      }
    }
  }

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

1934
  //  LOG_I(PHY,"check_skiphalf : rb %d, subframe_offset %d,l %d, nsymb %d\n",rb,subframe_offset,l,nsymb);
1935 1936 1937 1938 1939

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

    // PBCH
    if ((subframe_offset==0) &&
1940 1941 1942
        (rb==((frame_parms->N_RB_DL>>1)-3)) &&
        (l>=(nsymb>>1)) &&
        (l<((nsymb>>1) + 4)))
1943 1944 1945 1946 1947 1948 1949
      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)))
1950
        return(1);
1951
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)))
1952
        return(2);
1953 1954
      //PSS TDD
      if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==2))
1955
        return(1);
1956
      else if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==2))
1957
        return(2);
1958 1959 1960 1961
    }
    else { // FDD
      //PSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==((nsymb>>1)-1)))
1962
        return(1);
1963
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(((nsymb>>1)-1))))
1964
        return(2);
1965 1966
      //SSS FDD
      if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && ((l==((nsymb>>1)-2))))
1967
        return(1);
1968
      else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && ((l==(nsymb>>1)-2)))
1969
        return(2);
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988
    }
  }
  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);
}

Raymond Knopp's avatar
Raymond Knopp committed
1989

1990
int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
1991
                     int32_t **txdataF,
1992 1993 1994 1995
                     int16_t amp,
                     uint32_t subframe_offset,
                     uint8_t num_pdcch_symbols,
                     LTE_eNB_DLSCH_t *dlsch0,
Xiwen JIANG's avatar
Xiwen JIANG committed
1996
                     LTE_eNB_DLSCH_t *dlsch1)
1997
{
1998
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->frame_parms;
1999 2000

  uint8_t nsymb;
Cedric Roux's avatar
Cedric Roux committed
2001
  uint8_t harq_pid = -1; //= dlsch0->current_harq_pid;
Cedric Roux's avatar
Cedric Roux committed
2002
  LTE_DL_eNB_HARQ_t *dlsch0_harq = NULL;
Cedric Roux's avatar
Cedric Roux committed
2003
  LTE_DL_eNB_HARQ_t *dlsch1_harq = NULL; //= dlsch1->harq_processes[harq_pid];
2004
  uint32_t i,i2,jj,jj2,re_allocated,symbol_offset;
2005 2006
  uint16_t l,rb,re_offset;
  uint32_t rb_alloc_ind;
Cedric Roux's avatar
Cedric Roux committed
2007
  uint32_t *rb_alloc = NULL; //=dlsch0_harq->rb_alloc;
2008

Xiwen JIANG's avatar
Xiwen JIANG committed
2009
  uint8_t pilots=0;
2010
  uint8_t skip_dc,skip_half;
2011
  uint8_t mod_order0 = 0;
2012
  uint8_t mod_order1 = 0;
2013
  int16_t amp_rho_a, amp_rho_b;
2014 2015
  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];
2016

2017
  int16_t *qam_table_s0=NULL,*qam_table_s1=NULL;
2018 2019
#if 0
  /* TODO: variable to be removed? */
2020
  int (*allocate_REs)(PHY_VARS_eNB*,
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
                      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 *);
2041
#endif
2042

2043 2044
  int P1_SHIFT[13],P2_SHIFT[13];
  int offset,nushiftmod3;
2045

2046
  uint8_t get_pmi_temp;
2047

Cedric Roux's avatar
Cedric Roux committed
2048
  MIMO_mode_t mimo_mode = -1;
2049 2050
  uint8_t mprime=0,Ns;
  int8_t  lprime=-1;
Xiwen JIANG's avatar
Xiwen JIANG committed
2051
  int aa=0;
2052

2053

Raymond Knopp's avatar
 
Raymond Knopp committed
2054
#ifdef DEBUG_DLSCH_MODULATION
2055
  uint8_t Nl0;  //= dlsch0_harq->Nl;
2056
  uint8_t Nl1;
Raymond Knopp's avatar
 
Raymond Knopp committed
2057
#endif
2058 2059 2060
  int ru_id;
  RU_t *ru;
  int eNB_id;
2061

2062

2063
  if ((dlsch0 != NULL) && (dlsch1 != NULL)){
2064

2065
    harq_pid = dlsch0->harq_ids[subframe_offset];
2066
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2067
    mimo_mode = dlsch0_harq->mimo_mode;
2068
    mod_order0 = dlsch0_harq->Qm;
2069 2070 2071 2072 2073
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

2074
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
2075
    mod_order1 = dlsch1_harq->Qm;
2076 2077 2078
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = dlsch1_harq->Nl;
#endif
2079 2080 2081

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

2082
    harq_pid = dlsch0->harq_ids[subframe_offset];
2083
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2084
    mimo_mode = dlsch0_harq->mimo_mode;
2085
    mod_order0 = dlsch0_harq->Qm;
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098
    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)){

2099
    harq_pid = dlsch1->harq_ids[subframe_offset];
2100
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
2101
    mimo_mode = dlsch1_harq->mimo_mode;
2102
    mod_order0 = dlsch1_harq->Qm;
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
    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
    Nl1 = NULL;
#endif

2114
  }
2115

2116
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
2117

2118
  nsymb = (frame_parms->Ncp==0) ? 14:12;
2119

2120
  if (dlsch0 != NULL){
2121
  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
2122
  amp_rho_b = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_b)>>13);
2123 2124 2125 2126
  } 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);
  }
2127

2128

2129
  if (mod_order0 == 4)
2130
    for (i=0;i<4; i++) {
2131 2132
      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);
2133
    }
2134
  else if (mod_order0 == 6)
2135
    for (i=0; i<8; i++) {
2136 2137
      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);
2138
    }
2139 2140

  if (mod_order1 == 4)
2141
    for (i=0; i<4; i++) {
2142 2143 2144
      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
2145
  else if (mod_order1 == 6)
2146
    for (i=0; i<8; i++) {
2147 2148
      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);
2149 2150
    }

2151
  //Modulation mapping (difference w.r.t. LTE specs)
2152 2153 2154

  jj=0;
  jj2=0;
2155
  re_allocated=0;
2156

2157

2158
  //  LOG_I(PHY,"num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2159 2160
  for (l=num_pdcch_symbols; l<nsymb; l++) {

2161
  if (dlsch0 != NULL ) {
2162
#ifdef DEBUG_DLSCH_MODULATION
2163
    LOG_I(PHY,"Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc0 %lx, mod0 %d, mod1 %d, rb_alloc[0] %d)\n",
lukashov's avatar
lukashov committed
2164 2165 2166 2167 2168
            harq_pid,
            dlsch0_harq->mimo_mode,
            pmi2hex_2Ar2(dlsch0_harq->pmi_alloc),
            mod_order0,
            mod_order1,
2169 2170
            rb_alloc[0]
            );
2171
#endif
2172
  }
2173 2174 2175

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
2176
        pilots=2;   // pilots in nushift+3, nushift+9
2177
      else if (l==7)
2178
        pilots=1;   // pilots in nushift, nushift+6
2179
      else
2180 2181
        pilots=0;
    } else {
2182
      if ((l==3)||(l==9))
2183
        pilots=2;
2184
      else if (l==6)
2185
        pilots=1;
2186
      else
2187
        pilots=0;
2188 2189
    }

2190 2191 2192
    if(mimo_mode==TM7){ //36.211 V8.6.0 2009-03
      mprime = 0;
      if (frame_parms->Ncp==0) { // normal prefix
2193 2194 2195 2196 2197 2198 2199 2200
        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
2201
        else
2202
          lprime=-1;
2203
      } else {
2204
        if (l==10)
2205
          lprime=2;
2206
        else if (l==7)
2207
          lprime=1;
2208
        else if (l==4)
2209
          lprime=0;
2210 2211
        else
          lprime=-1;
2212
      }
Xiwen JIANG's avatar
Xiwen JIANG committed
2213

2214 2215 2216 2217 2218 2219
      // mapping ue specific beamforming weights from UE specified DLSCH structure to RU beam weights for the eNB
      for (ru_id=0;ru_id<RC.nb_RU;ru_id++) {
	ru = RC.ru[ru_id];
	for (eNB_id=0;eNB_id<ru->num_eNB;eNB_id++){
	  if (phy_vars_eNB == ru->eNB_list[eNB_id]) {
	    for (aa=0;aa<ru->nb_tx;aa++){
2220
              LOG_I(PHY,"ru_id:%d eNB_id:%d aa:%d memcpy(ru->beam_weights, dlsch0->ue_spec_bf_weights[ru_id][0],)\n", ru_id, eNB_id, aa);
2221 2222 2223
	      memcpy(ru->beam_weights[eNB_id][5][aa],
		     dlsch0->ue_spec_bf_weights[ru_id][0],
		     frame_parms->ofdm_symbol_size*sizeof(int32_t));
2224 2225 2226
	    }
	  }
	}
Xiwen JIANG's avatar
Xiwen JIANG committed
2227
      }
2228

2229
    }
2230

2231
    Ns = 2*subframe_offset+(l>=(nsymb>>1));
2232

2233 2234 2235 2236
    offset = (pilots==2)?3:0;
    nushiftmod3 = frame_parms->nushift%3;

    if (pilots>0) {  // compute pilot arrays, could be done statically if performance suffers
2237
      if (frame_parms->nb_antenna_ports_eNB == 1) {
2238
	//	LOG_I(PHY,"l %d, nushift %d, offset %d\n",l,frame_parms->nushift,offset);
2239 2240 2241 2242 2243 2244 2245 2246 2247
	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]--;
      }
      else {
2248 2249 2250 2251 2252 2253 2254
        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]--;
2255 2256 2257 2258
      }
    }
    P1_SHIFT[12]=1;P2_SHIFT[12]=1;

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

2262 2263
#if 0
    /* TODO: remove this code? */
2264
    allocate_REs = allocate_REs_in_RB;
2265
#endif
2266

2267 2268 2269 2270 2271 2272
    switch (mod_order0) {
    case 2:
      qam_table_s0 = NULL;
      break;
    case 4:
      if (pilots) {
2273
        qam_table_s0 = qam16_table_b0;
2274 2275
#if 0
        /* TODO: remove this code? */
2276 2277 2278
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_16QAM_siso :
          allocate_REs_in_RB;
2279
#endif
2280 2281
      }
      else {
2282
        qam_table_s0 = qam16_table_a0;
2283 2284
#if 0
        /* TODO: remove this code? */
2285 2286 2287
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_16QAM_siso :
          allocate_REs_in_RB;
2288
#endif
2289

2290 2291
      }
      break;
2292

2293 2294
    case 6:
      if (pilots) {
2295
        qam_table_s0 = qam64_table_b0;
2296 2297
#if 0
        /* TODO: remove this code? */
2298 2299 2300
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_64QAM_siso :
          allocate_REs_in_RB;
2301
#endif
2302 2303
      }
      else {
2304
        qam_table_s0 = qam64_table_a0;
2305 2306
#if 0
        /* TODO: remove this code? */
2307 2308 2309
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_64QAM_siso :
          allocate_REs_in_RB;
2310
#endif
2311 2312
      }
      break;
2313

2314
    }
2315

2316 2317 2318
    switch (mod_order1) {
    case 2:
      qam_table_s1 = NULL;
2319 2320
#if 0
        /* TODO: remove this code? */
2321
      allocate_REs = allocate_REs_in_RB;
2322
#endif
2323 2324 2325
      break;
    case 4:
      if (pilots) {
2326
        qam_table_s1 = qam16_table_b1;
2327 2328
      }
      else {
2329
        qam_table_s1 = qam16_table_a1;
2330 2331 2332 2333
      }
      break;
    case 6:
      if (pilots) {
2334
        qam_table_s1 = qam64_table_b1;
2335 2336
      }
      else {
2337
        qam_table_s1 = qam64_table_a1;
2338 2339
      }
      break;
2340

2341 2342
    }

2343
    //for (aa=0;aa<frame_parms->nb_antennas_tx;aa++)
lukashov's avatar
lukashov committed
2344
    //memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
2345
    //LOG_I(PHY,"symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358
    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;

2359
      if (check_skip(rb,subframe_offset,frame_parms,l,nsymb)==1)
2360
        rb_alloc_ind = 0;
2361

2362 2363
      skip_half = check_skiphalf(rb,subframe_offset,frame_parms,l,nsymb);
      skip_dc   = check_skip_dc(rb,frame_parms);
2364

2365

2366

2367 2368
     if (dlsch0) {
        if (dlsch0_harq->Nlayers>1) {
2369
          LOG_E(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2370 2371
          return(-1);
        }
2372
      }
2373 2374 2375

      if (dlsch1) {
        if (dlsch1_harq->Nlayers>1) {
2376
          LOG_I(PHY,"Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2377 2378 2379 2380 2381 2382 2383
          return(-1);
        }
      }



      if (rb_alloc_ind > 0) {
2384
        //    LOG_I(PHY,"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);
2385

2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
      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);

2397

2398
      allocate_REs_in_RB(phy_vars_eNB,
lukashov's avatar
lukashov committed
2399 2400 2401 2402 2403
                         txdataF,
                         &jj,
                         &jj2,
                         re_offset,
                         symbol_offset,
2404 2405
                         (dlsch0 == NULL) ? NULL : dlsch0->harq_processes[harq_pid],
                         (dlsch1 == NULL) ? NULL : dlsch1->harq_processes[harq_pid],
lukashov's avatar
lukashov committed
2406 2407
                         pilots,
                         ((pilots) ? amp_rho_b : amp_rho_a),
2408
                         get_pmi_temp,
lukashov's avatar
lukashov committed
2409 2410 2411 2412
                         qam_table_s0,
                         qam_table_s1,
                         &re_allocated,
                         skip_dc,
2413
                         skip_half,
2414 2415 2416 2417 2418
                         lprime,
                         mprime,
                         Ns,
                         P1_SHIFT,
                         P2_SHIFT);
2419

Xiwen JIANG's avatar
Xiwen JIANG committed
2420 2421
          if ((mimo_mode == TM7) && (lprime>=0))
            mprime +=3+frame_parms->Ncp;
2422
      }
2423
      else {
2424
        //      LOG_I(PHY,"Unallocated rb %d/symbol %d, re_offset %d, jj %d\n",rb,l,re_offset,jj);
2425
      }
2426 2427
      re_offset+=12; // go to next RB

2428
      // check if we crossed the symbol boundary and skip DCs
2429

2430
      if (re_offset >= frame_parms->ofdm_symbol_size) {
Xiwen JIANG's avatar
Xiwen JIANG committed
2431 2432 2433 2434
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
2435
      }
Xiwen JIANG's avatar
Xiwen JIANG committed
2436
    }
2437
  }
Xiwen JIANG's avatar
Xiwen JIANG committed
2438

2439
#ifdef DEBUG_DLSCH_MODULATION
2440
  if (dlsch0 != NULL){
2441
    LOG_I(PHY,"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));
2442
  }else{
2443
    LOG_I(PHY,"generate_dlsch : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch1_harq->nb_rb,dlsch1_harq->rb_alloc,mod_order1,Nl1,2,0,subframe_offset,1));
Xiwen JIANG's avatar
Xiwen JIANG committed
2444
  }
2445
#endif
2446

2447
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
2448

2449 2450 2451
  return (re_allocated);
}

lukashov's avatar
lukashov committed
2452

lukashov's avatar
lukashov committed
2453 2454 2455 2456 2457
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
2458
                         int G)
lukashov's avatar
lukashov committed
2459 2460
{

2461
  AssertFatal(1==0,"This function needs to be reintegrated ...\n");
2462
  uint8_t harq_pid = -1;//dlsch0->current_harq_pid;
lukashov's avatar
lukashov committed
2463
  LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
2464
  uint32_t i,jj,re_allocated=0;
2465
  uint8_t mod_order0 = dlsch0_harq->Qm;
lukashov's avatar
lukashov committed
2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477
  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;
  uint8_t Nl1;
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
2478

2479
  gain_lin_QPSK = (int16_t)((ONE_OVER_SQRT2_Q15));
2480

lukashov's avatar
lukashov committed
2481 2482 2483
  jj = 0;
  i = 0;
  while (jj <= G-1) {
2484

lukashov's avatar
lukashov committed
2485
    re_allocated = re_allocated + 1;
lukashov's avatar
lukashov committed
2486

lukashov's avatar
lukashov committed
2487 2488
    switch (mod_order0) {
    case 2:  //QPSK
2489

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

lukashov's avatar
lukashov committed
2492
      jj = jj + 1;
2493

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

lukashov's avatar
lukashov committed
2496
      jj = jj + 1;
2497

2498
      //LOG_I(PHY,"recon %d,%d\n",((int16_t*)&sic_buffer[0][i])[0],((int16_t*)&sic_buffer[0][i])[1]);
lukashov's avatar
lukashov committed
2499
      i++;
2500

lukashov's avatar
lukashov committed
2501
      break;
lukashov's avatar
lukashov committed
2502

lukashov's avatar
lukashov committed
2503
    case 4:  //16QAM
lukashov's avatar
lukashov committed
2504

lukashov's avatar
lukashov committed
2505 2506
      qam16_table_offset_re = 0;
      qam16_table_offset_im = 0;
lukashov's avatar
lukashov committed
2507

lukashov's avatar
lukashov committed
2508 2509
      if (x0[jj] == 1)
        qam16_table_offset_re+=2;
lukashov's avatar
lukashov committed
2510

lukashov's avatar
lukashov committed
2511
      jj=jj+1;
lukashov's avatar
lukashov committed
2512

lukashov's avatar
lukashov committed
2513 2514
      if (x0[jj] == 1)
        qam16_table_offset_im+=2;
lukashov's avatar
lukashov committed
2515

lukashov's avatar
lukashov committed
2516
      jj=jj+1;
lukashov's avatar
lukashov committed
2517 2518


lukashov's avatar
lukashov committed
2519 2520
      if (x0[jj] == 1)
        qam16_table_offset_re+=1;
lukashov's avatar
lukashov committed
2521

lukashov's avatar
lukashov committed
2522
      jj=jj+1;
lukashov's avatar
lukashov committed
2523

lukashov's avatar
lukashov committed
2524 2525
      if (x0[jj] == 1)
        qam16_table_offset_im+=1;
lukashov's avatar
lukashov committed
2526

lukashov's avatar
lukashov committed
2527
      jj=jj+1;
lukashov's avatar
lukashov committed
2528 2529


lukashov's avatar
lukashov committed
2530 2531
      ((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];
2532 2533

      i++;
lukashov's avatar
lukashov committed
2534

lukashov's avatar
lukashov committed
2535
      break;
lukashov's avatar
lukashov committed
2536

lukashov's avatar
lukashov committed
2537
    case 6:
lukashov's avatar
lukashov committed
2538

lukashov's avatar
lukashov committed
2539 2540
      qam64_table_offset_re = 0;
      qam64_table_offset_im = 0;
lukashov's avatar
lukashov committed
2541

lukashov's avatar
lukashov committed
2542 2543
      if (x0[jj] == 1)
      qam64_table_offset_re+=4;
lukashov's avatar
lukashov committed
2544

lukashov's avatar
lukashov committed
2545
      jj=jj+1;
lukashov's avatar
lukashov committed
2546

lukashov's avatar
lukashov committed
2547 2548
      if (x0[jj] == 1)
        qam64_table_offset_im+=4;
lukashov's avatar
lukashov committed
2549

lukashov's avatar
lukashov committed
2550
      jj=jj+1;
lukashov's avatar
lukashov committed
2551

lukashov's avatar
lukashov committed
2552 2553
      if (x0[jj] == 1)
        qam64_table_offset_re+=2;
lukashov's avatar
lukashov committed
2554

lukashov's avatar
lukashov committed
2555
      jj=jj+1;
lukashov's avatar
lukashov committed
2556

lukashov's avatar
lukashov committed
2557 2558
      if (x0[jj] == 1)
        qam64_table_offset_im+=2;
lukashov's avatar
lukashov committed
2559

lukashov's avatar
lukashov committed
2560
      jj=jj+1;
lukashov's avatar
lukashov committed
2561

lukashov's avatar
lukashov committed
2562 2563
      if (x0[jj] == 1)
        qam64_table_offset_re+=1;
lukashov's avatar
lukashov committed
2564

lukashov's avatar
lukashov committed
2565
      jj=jj+1;
lukashov's avatar
lukashov committed
2566

lukashov's avatar
lukashov committed
2567 2568
      if (x0[jj] == 1)
        qam64_table_offset_im+=1;
lukashov's avatar
lukashov committed
2569

lukashov's avatar
lukashov committed
2570
      jj=jj+1;
lukashov's avatar
lukashov committed
2571 2572


lukashov's avatar
lukashov committed
2573 2574
      ((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);
2575

lukashov's avatar
lukashov committed
2576
      i++;
2577

lukashov's avatar
lukashov committed
2578
      break;
lukashov's avatar
lukashov committed
2579
      }
2580

lukashov's avatar
lukashov committed
2581
    }
2582 2583 2584


#ifdef DEBUG_DLSCH_MODULATION
2585
  LOG_I(PHY,"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*/));
2586
#endif
2587

2588
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
2589

2590 2591 2592
  return (re_allocated);
}

lukashov's avatar
lukashov committed
2593

2594
int mch_modulation(int32_t **txdataF,
2595 2596 2597 2598 2599
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
                   LTE_eNB_DLSCH_t *dlsch)
{
2600 2601 2602 2603
  uint8_t nsymb,nsymb_pmch;
  uint32_t i,jj,re_allocated,symbol_offset;
  uint16_t l,rb,re_offset;
  uint8_t skip_dc=0;
2604
  uint8_t mod_order = dlsch->harq_processes[0]->Qm;
2605 2606 2607 2608 2609
  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;
2610

2611
  if (mod_order == 4)
2612
    for (i=0; i<4; i++) {
2613 2614 2615
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
2616
    for (i=0; i<8; i++) {
2617
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
2618 2619 2620
    }

  jj=0;
2621
  re_allocated=0;
2622

2623
  //  LOG_I(PHY,"num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2624 2625
  for (l=2; l<nsymb_pmch; l++) {

2626
#ifdef DEBUG_DLSCH_MODULATION
2627
    LOG_I(PHY,"Generating MCH (mod %d) in subframe %d for symbol %d\n",mod_order, subframe_offset,l);
2628
#endif
2629 2630 2631 2632

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

2633 2634
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

2635 2636

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

lukashov's avatar
lukashov committed
2638
    if (rb==(frame_parms->N_RB_DL>>1))
2639 2640 2641
          skip_dc = 1;
        else
          skip_dc = 0;
2642 2643 2644 2645

      }

      if (mod_order == 4)
2646
        qam_table_s = qam16_table_a;
2647
      else if (mod_order == 6)
2648
        qam_table_s = qam64_table_a;
2649
      else
2650
        qam_table_s = NULL;
2651

2652
      //LOG_I(PHY,"Allocated rb %d, subframe_offset %d,amp %d\n",rb,subframe_offset,amp);
2653
      allocate_REs_in_RB_MCH(txdataF,
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665
                             &jj,
                             re_offset,
                             symbol_offset,
                             dlsch->harq_processes[0]->e,
                             l,
                             mod_order,
                             amp,
                             qam_table_s,
                             &re_allocated,
                             skip_dc,
                             frame_parms);

2666
      re_offset+=12; // go to next RB
2667

2668 2669
      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
2670 2671 2672 2673
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
2674 2675 2676 2677 2678
      }
    }
  }

#ifdef DEBUG_DLSCH_MODULATION
2679
  LOG_I(PHY,"generate_dlsch(MCH) : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch->harq_processes[0]->nb_rb,dlsch->harq_processes[0]->rb_alloc,mod_order,1,2,0,subframe_offset,1/*transmission mode*/));
2680
#endif
2681 2682

  return (re_allocated);
2683
}