dlsch_modulation.c 86.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22

/*! \file PHY/LTE_TRANSPORT/dlsch_modulation.c
23 24 25 26 27 28 29 30 31
 * \brief Top-level routines for generating the PDSCH physical channel from 36-211, V8.6 2009-03
 * \author R. Knopp, F. Kaltenberger
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr
 * \note
 * \warning
 */
32 33 34 35 36 37 38
#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
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
/*uint8_t is_not_UEspecRS(int first_layer,int re)
66
{
Raymond Knopp's avatar
 
Raymond Knopp committed
67
  return(1);
Xiwen JIANG's avatar
Xiwen JIANG committed
68
}*/
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 81 82
          return(1);
        /*else{
          printf("(is_no_UEspec_RS):lprime=%d, re=%d, nushift=%d, offset=%d\n",lprime, re,nushift,offset);
        }*/
83
      } else {
84 85 86 87 88 89 90 91 92
        if ((re!=nushift+offset) && (re!=((nushift+3+offset)%12)) && (re!=((nushift+6+offset)%12)) && (re!=((nushift+9+offset)%12)))
          return(1);
      }
      break;

    default:
      msg("is_not_UEspecRS() [dlsch_modulation.c] : ERROR, unknown beamforming_mode %d\n",beamforming_mode);
      return(-1);
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
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 273

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

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;


  if (skip_dc == 0) {
    //    printf("pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
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 284 285 286 287 288 289
      qam16_table_offset_re=TWO[x0p[0]];
      qam16_table_offset_im=TWO[x0p[1]];
      qam16_table_offset_re+=x0p[2];
      qam16_table_offset_im+=x0p[3];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam16_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam16_table_offset_im];
      //      printf("pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
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 500

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

  uint32_t tti_offset;
  uint8_t re;
  uint8_t *x0p;


  if (skip_dc == 0) {
    //    printf("pilots: P1_SHIFT[0] %d\n",P1_SHIFT[0]);
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 513 514 515 516 517 518
      qam64_table_offset_re=FOUR[x0p[0]];
      qam64_table_offset_im=FOUR[x0p[1]];
      qam64_table_offset_re+=TWO[x0p[2]];
      qam64_table_offset_im+=TWO[x0p[3]];
      qam64_table_offset_re+=x0p[4];
      qam64_table_offset_im+=x0p[5];
      ((int16_t *)&txdataF[0][tti_offset])[0]=qam_table_s0[qam64_table_offset_re];
      ((int16_t *)&txdataF[0][tti_offset])[1]=qam_table_s0[qam64_table_offset_im];
      //      printf("pilots: re %d, tti_offset %d, P1_SHIFT %d\n",re,tti_offset,P1_SHIFT[re+1]);
      tti_offset+=P1_SHIFT[re+1];
      re+=P1_SHIFT[re+1];
    }
  }
  else {
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 581
  uint8_t *x0 = NULL;
  MIMO_mode_t mimo_mode;
Xiwen JIANG's avatar
Xiwen JIANG committed
582

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


586 587
  int first_layer0; //= dlsch0_harq->first_layer;
  int Nlayers0; //  = dlsch0_harq->Nlayers;
588 589
  uint8_t mod_order0=0; // = get_Qm(dlsch0_harq->mcs);
  uint8_t mod_order1=0; //=2;
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;
596 597

  int use2ndpilots = (frame_parms->mode1_flag==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

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

627 628 629 630 631 632 633 634 635
  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;
636 637 638 639 640 641 642 643

  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;
    mod_order0 = get_Qm(dlsch0_harq->mcs);
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 649
    mod_order1     = get_Qm(dlsch1_harq->mcs);

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
  } 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;
    mod_order0 = get_Qm(dlsch0_harq->mcs);

  } 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;
    mod_order0 = get_Qm(dlsch1_harq->mcs);

666
  }
667

668 669 670 671 672 673 674 675 676
  if (dlsch0_harq != NULL){
    #ifdef DEBUG_DLSCH_MODULATION
      printf("allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d\n",mod_order0,symbol_offset,re_offset,skip_dc,skip_half,*jj, x0[*jj], x0[1+*jj]);
    #endif
  } else{
    #ifdef DEBUG_DLSCH_MODULATION
      printf("allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d\n",mod_order0,symbol_offset,re_offset,skip_dc,skip_half,*jj, x0[*jj], x0[1+*jj]);
    #endif
  }
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

687
  for (re=first_re; re<last_re; re++) {
688
  // printf("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) {
lukashov's avatar
lukashov committed
698
      //printf("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 709

          //printf("re %d %d(%d) : %d,%d => ",re,tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
          ((int16_t*)&txdataF[0][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
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
      else if (mimo_mode == ALAMOUTI) {
        *re_allocated = *re_allocated + 1;
796

797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
        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
lukashov's avatar
lukashov committed
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

lukashov's avatar
lukashov committed
826
        case 4:  //16QAM
827 828

          // Antenna 0 position n
lukashov's avatar
lukashov committed
829 830
          qam16_table_offset_re = 0;
          qam16_table_offset_im = 0;
831

lukashov's avatar
lukashov committed
832 833 834 835 836 837
          if (x0[*jj] == 1)
            qam16_table_offset_re+=2;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=2;
          *jj=*jj+1;
838 839


lukashov's avatar
lukashov committed
840 841 842 843 844 845
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
846

847 848 849 850 851
          //((int16_t *)&txdataF[0][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
          //((int16_t *)&txdataF[0][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
	  //gain_lin_QPSK (=amp/sqrt(2)) is already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[0][tti_offset])[0]+=(qam_table_s0[qam16_table_offset_re]);
	  ((int16_t *)&txdataF[0][tti_offset])[1]+=(qam_table_s0[qam16_table_offset_im]);
852

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

lukashov's avatar
lukashov committed
855 856 857 858 859 860 861 862 863
          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;
864 865


lukashov's avatar
lukashov committed
866 867 868 869 870 871
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
872

873 874 875 876 877
          //((int16_t *)&txdataF[1][tti_offset])[0]+=-(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
          //((int16_t *)&txdataF[1][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
	  //qam_table_s0 already contains the power offset from rho_a/rho_b, so here we do not need divide by sqrt(2) anymore
	  ((int16_t *)&txdataF[1][tti_offset])[0]+=-(qam_table_s0[qam16_table_offset_re]);
	  ((int16_t *)&txdataF[1][tti_offset])[1]+=(qam_table_s0[qam16_table_offset_im]);
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

          break;
lukashov's avatar
lukashov committed
883 884

        case 6:   // 64-QAM
885

lukashov's avatar
lukashov committed
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
          // 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;
908

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 914
	  //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]);

915

lukashov's avatar
lukashov committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
          // 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;
937

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 943
	  //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]);

944

945
          break;
lukashov's avatar
lukashov committed
946
        }
947
  // fill in the rest of the ALAMOUTI precoding
lukashov's avatar
lukashov committed
948 949 950 951 952 953 954 955 956 957 958 959
        if (is_not_pilot(pilots,re + 1,frame_parms->nushift,use2ndpilots)==1) {
          ((int16_t *)&txdataF[0][tti_offset+1])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+1])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+1])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+1])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        }
        else {
          ((int16_t *)&txdataF[0][tti_offset+2])[0] += -((int16_t *)&txdataF[1][tti_offset])[0]; //x1
          ((int16_t *)&txdataF[0][tti_offset+2])[1] += ((int16_t *)&txdataF[1][tti_offset])[1];
          ((int16_t *)&txdataF[1][tti_offset+2])[0] += ((int16_t *)&txdataF[0][tti_offset])[0];  //x0*
          ((int16_t *)&txdataF[1][tti_offset+2])[1] += -((int16_t *)&txdataF[0][tti_offset])[1];
        }
960
      }
961
      else if (mimo_mode == LARGE_CDD) {
962

lukashov's avatar
lukashov committed
963 964
        *re_allocated = *re_allocated + 1;

965
        if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
          switch (mod_order0) {

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

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

lukashov's avatar
lukashov committed
982
          case 4:  //16QAM
983

lukashov's avatar
lukashov committed
984 985 986 987 988 989 990 991
            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;
992

lukashov's avatar
lukashov committed
993 994 995 996 997 998
            if (x0[*jj] == 1)
              qam16_table_offset_re0+=1;
            *jj=*jj+1;
            if (x0[*jj] == 1)
              qam16_table_offset_im0+=1;
            *jj=*jj+1;
999

lukashov's avatar
lukashov committed
1000 1001 1002 1003
            xx0_re = qam_table_s0[qam16_table_offset_re0];
            xx0_im = qam_table_s0[qam16_table_offset_im0];

            break;
1004

lukashov's avatar
lukashov committed
1005
          case 6:  //64QAM
1006 1007


lukashov's avatar
lukashov committed
1008 1009
            qam64_table_offset_re0 = 0;
            qam64_table_offset_im0 = 0;
1010

lukashov's avatar
lukashov committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
            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;
1034

lukashov's avatar
lukashov committed
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
          }

          switch (mod_order1) {

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

          case 2:  //QPSK
            //printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1046
            xx1_re = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1047
            *jj2 = *jj2 + 1;
1048
            xx1_im = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
lukashov's avatar
lukashov committed
1049 1050 1051
            *jj2 = *jj2 + 1;
            //printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
            break;
1052

lukashov's avatar
lukashov committed
1053
          case 4:  //16QAM
1054

lukashov's avatar
lukashov committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
            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;
1074

lukashov's avatar
lukashov committed
1075
          case 6:  //64QAM
1076

lukashov's avatar
lukashov committed
1077 1078
            qam64_table_offset_re1 = 0;
            qam64_table_offset_im1 = 0;
1079

lukashov's avatar
lukashov committed
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
            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;
1103

lukashov's avatar
lukashov committed
1104 1105 1106 1107 1108 1109
          }

          // 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)|
1110
          // -  -        -    -  -         -  -     -  -  -       -
lukashov's avatar
lukashov committed
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
          // Note: Factor .5 is accounted for in amplitude when calling this function
          ((int16_t *)&txdataF[0][tti_offset])[0]+=((xx0_re+xx1_re)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[0]+=(s*((xx0_re-xx1_re)>>1));
          ((int16_t *)&txdataF[0][tti_offset])[1]+=((xx0_im+xx1_im)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[1]+=(s*((xx0_im-xx1_im)>>1));
          /*
          printf("CDD: xx0 (%d,%d), xx1(%d,%d), s(%d), txF[0] (%d,%d), txF[1] (%d,%d)\n",
           xx0_re,xx0_im,xx1_re,xx1_im, s, ((int16_t *)&txdataF[0][tti_offset])[0],((int16_t *)&txdataF[0][tti_offset])[1],
           ((int16_t *)&txdataF[1][tti_offset])[0],((int16_t *)&txdataF[1][tti_offset])[1]);
          */
          // s alternates +1/-1 for each RE
          s = -s;
        }
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
        *re_allocated = *re_allocated + 1;
lukashov's avatar
lukashov committed
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);

        switch (mod_order0) {
        case 2:

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

          //normalization for 2 tx antennas
1139
          /*((int16_t*)&txdataF[0][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*ONE_OVER_SQRT2_Q15)>>15);
lukashov's avatar
lukashov committed
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) {
lukashov's avatar
lukashov committed
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];
lukashov's avatar
lukashov committed
1157 1158 1159
          }

          break;
1160

lukashov's avatar
lukashov committed
1161
        case 4:
1162

lukashov's avatar
lukashov committed
1163 1164 1165 1166 1167 1168 1169 1170 1171
          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;
1172 1173


lukashov's avatar
lukashov committed
1174 1175 1176 1177 1178 1179
          if (x0[*jj] == 1)
            qam16_table_offset_re+=1;
          *jj=*jj+1;
          if (x0[*jj] == 1)
            qam16_table_offset_im+=1;
          *jj=*jj+1;
1180 1181


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

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 1189
          if (frame_parms->nb_antennas_tx == 2) {
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1190 1191
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
1192 1193 1194
          }

          break;
1195

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

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

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

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

1225
          if (frame_parms->nb_antenna_ports_eNB == 2) {
lukashov's avatar
lukashov committed
1226
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
1227 1228
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
1229
          }
1230

lukashov's avatar
lukashov committed
1231 1232
          break;
        }
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;
lukashov's avatar
lukashov committed
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259

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

        switch (mod_order0) {
        case 2:

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

          //normalization for 2 tx antennas
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

          //printf("%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
          if (frame_parms->nb_antenna_ports_eNB == 2) {
1342 1343 1344
            layer1prec2A(&tmp_sample1,&tmp_sample2,precoder_index);
            ((int16_t*)&txdataF[1][tti_offset])[0] += ((int16_t*)&tmp_sample2)[0];
            ((int16_t*)&txdataF[1][tti_offset])[1] += ((int16_t*)&tmp_sample2)[1];
lukashov's avatar
lukashov committed
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
          }
        }
1443
      }
1444

1445

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

1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 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
      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;

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

            case 4:  //16QAM

              qam16_table_offset_re = 0;
              qam16_table_offset_im = 0;

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

              *jj=*jj+1;

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

              *jj=*jj+1;


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

              *jj=*jj+1;

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

              *jj=*jj+1;

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

              break;

            case 6:  //64QAM


              qam64_table_offset_re = 0;
              qam64_table_offset_im = 0;

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

              *jj=*jj+1;

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

              *jj=*jj+1;
Raymond Knopp's avatar
 
Raymond Knopp committed
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 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
              if (x0[*jj] == 1)
                qam64_table_offset_re+=2;

              *jj=*jj+1;

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

              *jj=*jj+1;

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

              *jj=*jj+1;

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

              *jj=*jj+1;

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

              break;

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

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

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

        }
Xiwen JIANG's avatar
Xiwen JIANG committed
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)) {
1563 1564
          switch (mod_order0) {
          case 2:  //QPSK
Raymond Knopp's avatar
 
Raymond Knopp committed
1565

1566
            //    printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1567
            for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
1568 1569 1570 1571 1572
              ((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;
            }
Raymond Knopp's avatar
 
Raymond Knopp committed
1573

1574
            break;
1575

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

1601
              for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
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
                ((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;

1644
            for (int layer=first_layer0; layer<=(first_layer0+Nlayers0); layer++) {
1645 1646 1647 1648 1649 1650 1651 1652 1653
              ((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;

          }
        }
      } else if (mimo_mode>=TM9_10) {
1654
        printf("allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
1655
        return(-1);
Raymond Knopp's avatar
 
Raymond Knopp committed
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
  printf("allocate_re_MCH (mod %d): symbol_offset %d re_offset %d (%d), jj %d -> %d,%d, gain_lin_QPSK %d,txdataF %p\n",mod_order,symbol_offset,re_offset,skip_dc,*jj, x0[*jj], x0[1+*jj],gain_lin_QPSK,&txdataF[0][symbol_offset]);
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

lukashov's avatar
lukashov committed
1710
    //printf("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
      //            printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
Xiwen JIANG's avatar
Xiwen JIANG committed
1719
      ((int16_t*)&txdataF[4][tti_offset])[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
1720 1721 1722

      *jj = *jj + 1;

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 1725 1726

      *jj = *jj + 1;

lukashov's avatar
lukashov committed
1727
      //printf("%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
  //  printf("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);
}

1989

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

  uint8_t nsymb;
2001 2002
  uint8_t harq_pid; //= dlsch0->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch0_harq;
2003
  LTE_DL_eNB_HARQ_t *dlsch1_harq; //= 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;
2007 2008
  uint32_t *rb_alloc; //=dlsch0_harq->rb_alloc;

2009 2010
  uint8_t pilots=0;
  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
  int (*allocate_REs)(PHY_VARS_eNB*,
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038
                      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 *);
2039

2040 2041
  int P1_SHIFT[13],P2_SHIFT[13];
  int offset,nushiftmod3;
2042

2043
  uint8_t get_pmi_temp;
2044

2045
  MIMO_mode_t mimo_mode;
2046 2047
  uint8_t mprime=0,Ns;
  int8_t  lprime=-1;
Xiwen JIANG's avatar
Xiwen JIANG committed
2048
  int aa=0;
2049

2050

Raymond Knopp's avatar
 
Raymond Knopp committed
2051
#ifdef DEBUG_DLSCH_MODULATION
2052
  uint8_t Nl0;  //= dlsch0_harq->Nl;
2053
  uint8_t Nl1;
Raymond Knopp's avatar
 
Raymond Knopp committed
2054
#endif
2055

2056

2057
  if ((dlsch0 != NULL) && (dlsch1 != NULL)){
2058

2059 2060
    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2061
    mimo_mode = dlsch0_harq->mimo_mode;
2062 2063 2064 2065 2066 2067
    mod_order0 = get_Qm(dlsch0_harq->mcs);
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

2068 2069 2070 2071 2072
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
    mod_order1 = get_Qm(dlsch1_harq->mcs);
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = dlsch1_harq->Nl;
#endif
2073 2074 2075 2076 2077

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

    harq_pid = dlsch0->current_harq_pid;
    dlsch0_harq = dlsch0->harq_processes[harq_pid];
2078
    mimo_mode = dlsch0_harq->mimo_mode;
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
    mod_order0 = get_Qm(dlsch0_harq->mcs);
    rb_alloc = dlsch0_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch0_harq->Nl;
#endif

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

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

    harq_pid = dlsch1->current_harq_pid;
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
2095
    mimo_mode = dlsch1_harq->mimo_mode;
2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
    mod_order0 = get_Qm(dlsch1_harq->mcs);
    rb_alloc = dlsch1_harq->rb_alloc;
#ifdef DEBUG_DLSCH_MODULATION
    Nl0 = dlsch1_harq->Nl;
#endif

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

2108
  }
2109

2110
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
2111

2112
  nsymb = (frame_parms->Ncp==0) ? 14:12;
2113

2114
  if (dlsch0 != NULL){
2115
  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
2116
  amp_rho_b = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_b)>>13);
2117 2118 2119 2120
  } 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);
  }
2121

2122
  if (mod_order0 == 4)
2123
    for (i=0;i<4; i++) {
2124 2125
      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);
2126
    }
2127
  else if (mod_order0 == 6)
2128
    for (i=0; i<8; i++) {
2129 2130
      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);
2131
    }
2132 2133

  if (mod_order1 == 4)
2134
    for (i=0; i<4; i++) {
2135 2136 2137
      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
2138
  else if (mod_order1 == 6)
2139
    for (i=0; i<8; i++) {
2140 2141
      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);
2142 2143
    }

2144
  //Modulation mapping (difference w.r.t. LTE specs)
2145 2146 2147

  jj=0;
  jj2=0;
2148
  re_allocated=0;
2149

2150

2151
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2152 2153
  for (l=num_pdcch_symbols; l<nsymb; l++) {

2154
  if (dlsch0 != NULL ) {
2155
#ifdef DEBUG_DLSCH_MODULATION
2156
    printf("Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc0 %lx, mod0 %d, mod1 %d, rb_alloc[0] %d) in %d\n",
lukashov's avatar
lukashov committed
2157 2158 2159 2160 2161 2162 2163
            harq_pid,
            dlsch0_harq->mimo_mode,
            pmi2hex_2Ar2(dlsch0_harq->pmi_alloc),
            mod_order0,
            mod_order1,
            rb_alloc[0],
            len);
2164
#endif
2165
  }
2166 2167 2168

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
2169
        pilots=2;   // pilots in nushift+3, nushift+9
2170
      else if (l==7)
2171
        pilots=1;   // pilots in nushift, nushift+6
2172
      else
2173 2174
        pilots=0;
    } else {
2175
      if ((l==3)||(l==9))
2176
        pilots=2;
2177
      else if (l==6)
2178
        pilots=1;
2179
      else
2180
        pilots=0;
2181 2182
    }

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

      // mapping ue specific beamforming weights from UE specified DLSCH structure to common space
      for (aa=0;aa<frame_parms->nb_antennas_tx;aa++){
2209
        memcpy(phy_vars_eNB->common_vars.beam_weights[0][5][aa],dlsch0->ue_spec_bf_weights[0][aa],frame_parms->ofdm_symbol_size*sizeof(int32_t));
Xiwen JIANG's avatar
Xiwen JIANG committed
2210
      }
2211

2212
    }
2213

2214
    Ns = 2*subframe_offset+(l>=(nsymb>>1));
2215

2216 2217 2218 2219 2220
    offset = (pilots==2)?3:0;
    nushiftmod3 = frame_parms->nushift%3;

    if (pilots>0) {  // compute pilot arrays, could be done statically if performance suffers
      if (frame_parms->mode1_flag == 1) {
2221 2222 2223 2224 2225 2226 2227 2228
        //      printf("l %d, nushift %d, offset %d\n",l,frame_parms->nushift,offset);
        for (i=0,i2=0;i<12;i++) {
          if ((i!=(frame_parms->nushift+offset)) && (i!=((frame_parms->nushift+6+offset)%12)))
            P1_SHIFT[i2++]=1;
          else
            P1_SHIFT[i2++]=2;
        }
        P1_SHIFT[0]--;
2229 2230
      }
      else {
2231 2232 2233 2234 2235 2236 2237
        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]--;
2238 2239 2240 2241
      }
    }
    P1_SHIFT[12]=1;P2_SHIFT[12]=1;

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

2245
    allocate_REs = allocate_REs_in_RB;
2246

2247 2248 2249 2250 2251 2252
    switch (mod_order0) {
    case 2:
      qam_table_s0 = NULL;
      break;
    case 4:
      if (pilots) {
2253 2254 2255 2256
        qam_table_s0 = qam16_table_b0;
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_16QAM_siso :
          allocate_REs_in_RB;
2257 2258
      }
      else {
2259 2260 2261 2262
        qam_table_s0 = qam16_table_a0;
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_16QAM_siso :
          allocate_REs_in_RB;
2263

2264 2265
      }
      break;
2266

2267 2268
    case 6:
      if (pilots) {
2269 2270 2271 2272
        qam_table_s0 = qam64_table_b0;
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_pilots_64QAM_siso :
          allocate_REs_in_RB;
2273 2274
      }
      else {
2275 2276 2277 2278
        qam_table_s0 = qam64_table_a0;
        allocate_REs = (dlsch0->harq_processes[harq_pid]->mimo_mode == SISO) ?
          allocate_REs_in_RB_no_pilots_64QAM_siso :
          allocate_REs_in_RB;
2279 2280
      }
      break;
2281

2282
    }
2283

2284 2285 2286 2287 2288 2289 2290
    switch (mod_order1) {
    case 2:
      qam_table_s1 = NULL;
      allocate_REs = allocate_REs_in_RB;
      break;
    case 4:
      if (pilots) {
2291
        qam_table_s1 = qam16_table_b1;
2292 2293
      }
      else {
2294
        qam_table_s1 = qam16_table_a1;
2295 2296 2297 2298
      }
      break;
    case 6:
      if (pilots) {
2299
        qam_table_s1 = qam64_table_b1;
2300 2301
      }
      else {
2302
        qam_table_s1 = qam64_table_a1;
2303 2304
      }
      break;
2305

2306 2307
    }

2308
    //for (aa=0;aa<frame_parms->nb_antennas_tx;aa++)
lukashov's avatar
lukashov committed
2309
    //memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
2310
    //printf("symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322
    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;
2323

2324
      if (check_skip(rb,subframe_offset,frame_parms,l,nsymb)==1)
2325
        rb_alloc_ind = 0;
2326

2327 2328
      skip_half = check_skiphalf(rb,subframe_offset,frame_parms,l,nsymb);
      skip_dc   = check_skip_dc(rb,frame_parms);
2329

2330

2331

2332 2333 2334 2335 2336
     if (dlsch0) {
        if (dlsch0_harq->Nlayers>1) {
          msg("Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
          return(-1);
        }
2337
      }
2338 2339 2340

      if (dlsch1) {
        if (dlsch1_harq->Nlayers>1) {
2341
          printf("Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
2342 2343 2344 2345 2346 2347 2348 2349
          return(-1);
        }
      }



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

2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361
      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);

2362

2363
      allocate_REs_in_RB(phy_vars_eNB,
lukashov's avatar
lukashov committed
2364 2365 2366 2367 2368
                         txdataF,
                         &jj,
                         &jj2,
                         re_offset,
                         symbol_offset,
2369 2370
                         (dlsch0 == NULL) ? NULL : dlsch0->harq_processes[harq_pid],
                         (dlsch1 == NULL) ? NULL : dlsch1->harq_processes[harq_pid],
lukashov's avatar
lukashov committed
2371 2372
                         pilots,
                         ((pilots) ? amp_rho_b : amp_rho_a),
2373
                         get_pmi_temp,
lukashov's avatar
lukashov committed
2374 2375 2376 2377
                         qam_table_s0,
                         qam_table_s1,
                         &re_allocated,
                         skip_dc,
2378
                         skip_half,
2379 2380 2381 2382 2383
                         lprime,
                         mprime,
                         Ns,
                         P1_SHIFT,
                         P2_SHIFT);
2384

Xiwen JIANG's avatar
Xiwen JIANG committed
2385 2386
          if ((mimo_mode == TM7) && (lprime>=0))
            mprime +=3+frame_parms->Ncp;
2387
      }
2388
      else {
2389
        //      printf("Unallocated rb %d/symbol %d, re_offset %d, jj %d\n",rb,l,re_offset,jj);
2390
      }
2391 2392
      re_offset+=12; // go to next RB

2393
      // check if we crossed the symbol boundary and skip DCs
2394

2395 2396 2397 2398 2399 2400 2401
      if (re_offset >= frame_parms->ofdm_symbol_size) {
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
      }
    }
2402
  }
2403

2404
#ifdef DEBUG_DLSCH_MODULATION
2405 2406 2407 2408 2409
  if (dlsch0 != NULL){
    msg("generate_dlsch : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch0_harq->nb_rb,dlsch0_harq->rb_alloc,mod_order0,Nl0,2,0,subframe_offset));
  }else{
    msg("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));
  }
2410
#endif
2411

2412
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
2413

2414 2415 2416
  return (re_allocated);
}

lukashov's avatar
lukashov committed
2417

lukashov's avatar
lukashov committed
2418 2419 2420 2421 2422
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
2423
                         int G)
lukashov's avatar
lukashov committed
2424 2425 2426 2427
{

  uint8_t harq_pid = dlsch0->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
2428
  uint32_t i,jj,re_allocated=0;
lukashov's avatar
lukashov committed
2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442
  uint8_t mod_order0 = get_Qm(dlsch0_harq->mcs);
  uint8_t *x0  = dlsch0_harq->e;
  uint8_t qam64_table_offset_re = 0;
  uint8_t qam64_table_offset_im = 0;
  uint8_t qam16_table_offset_re = 0;
  uint8_t qam16_table_offset_im = 0;
  int16_t gain_lin_QPSK;
 #ifdef DEBUG_DLSCH_MODULATION
  uint8_t Nl0 = dlsch0_harq->Nl;
  uint8_t Nl1;
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);

2443
  gain_lin_QPSK = (int16_t)((ONE_OVER_SQRT2_Q15));
2444

lukashov's avatar
lukashov committed
2445 2446 2447
  jj = 0;
  i = 0;
  while (jj <= G-1) {
2448

lukashov's avatar
lukashov committed
2449
    re_allocated = re_allocated + 1;
lukashov's avatar
lukashov committed
2450

lukashov's avatar
lukashov committed
2451 2452
    switch (mod_order0) {
    case 2:  //QPSK
2453

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

lukashov's avatar
lukashov committed
2456
      jj = jj + 1;
2457

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

lukashov's avatar
lukashov committed
2460
      jj = jj + 1;
2461

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

lukashov's avatar
lukashov committed
2465
      break;
lukashov's avatar
lukashov committed
2466

lukashov's avatar
lukashov committed
2467
    case 4:  //16QAM
lukashov's avatar
lukashov committed
2468

lukashov's avatar
lukashov committed
2469 2470
      qam16_table_offset_re = 0;
      qam16_table_offset_im = 0;
lukashov's avatar
lukashov committed
2471

lukashov's avatar
lukashov committed
2472 2473
      if (x0[jj] == 1)
        qam16_table_offset_re+=2;
lukashov's avatar
lukashov committed
2474

lukashov's avatar
lukashov committed
2475
      jj=jj+1;
lukashov's avatar
lukashov committed
2476

lukashov's avatar
lukashov committed
2477 2478
      if (x0[jj] == 1)
        qam16_table_offset_im+=2;
lukashov's avatar
lukashov committed
2479

lukashov's avatar
lukashov committed
2480
      jj=jj+1;
lukashov's avatar
lukashov committed
2481 2482


lukashov's avatar
lukashov committed
2483 2484
      if (x0[jj] == 1)
        qam16_table_offset_re+=1;
lukashov's avatar
lukashov committed
2485

lukashov's avatar
lukashov committed
2486
      jj=jj+1;
lukashov's avatar
lukashov committed
2487

lukashov's avatar
lukashov committed
2488 2489
      if (x0[jj] == 1)
        qam16_table_offset_im+=1;
lukashov's avatar
lukashov committed
2490

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


lukashov's avatar
lukashov committed
2494 2495
      ((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];
2496 2497

      i++;
lukashov's avatar
lukashov committed
2498

lukashov's avatar
lukashov committed
2499
      break;
lukashov's avatar
lukashov committed
2500

lukashov's avatar
lukashov committed
2501
    case 6:
lukashov's avatar
lukashov committed
2502

lukashov's avatar
lukashov committed
2503 2504
      qam64_table_offset_re = 0;
      qam64_table_offset_im = 0;
lukashov's avatar
lukashov committed
2505

lukashov's avatar
lukashov committed
2506 2507
      if (x0[jj] == 1)
      qam64_table_offset_re+=4;
lukashov's avatar
lukashov committed
2508

lukashov's avatar
lukashov committed
2509
      jj=jj+1;
lukashov's avatar
lukashov committed
2510

lukashov's avatar
lukashov committed
2511 2512
      if (x0[jj] == 1)
        qam64_table_offset_im+=4;
lukashov's avatar
lukashov committed
2513

lukashov's avatar
lukashov committed
2514
      jj=jj+1;
lukashov's avatar
lukashov committed
2515

lukashov's avatar
lukashov committed
2516 2517
      if (x0[jj] == 1)
        qam64_table_offset_re+=2;
lukashov's avatar
lukashov committed
2518

lukashov's avatar
lukashov committed
2519
      jj=jj+1;
lukashov's avatar
lukashov committed
2520

lukashov's avatar
lukashov committed
2521 2522
      if (x0[jj] == 1)
        qam64_table_offset_im+=2;
lukashov's avatar
lukashov committed
2523

lukashov's avatar
lukashov committed
2524
      jj=jj+1;
lukashov's avatar
lukashov committed
2525

lukashov's avatar
lukashov committed
2526 2527
      if (x0[jj] == 1)
        qam64_table_offset_re+=1;
lukashov's avatar
lukashov committed
2528

lukashov's avatar
lukashov committed
2529
      jj=jj+1;
lukashov's avatar
lukashov committed
2530

lukashov's avatar
lukashov committed
2531 2532
      if (x0[jj] == 1)
        qam64_table_offset_im+=1;
lukashov's avatar
lukashov committed
2533

lukashov's avatar
lukashov committed
2534
      jj=jj+1;
lukashov's avatar
lukashov committed
2535 2536


lukashov's avatar
lukashov committed
2537 2538
      ((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);
2539

lukashov's avatar
lukashov committed
2540
      i++;
2541

lukashov's avatar
lukashov committed
2542
      break;
lukashov's avatar
lukashov committed
2543
      }
2544

lukashov's avatar
lukashov committed
2545
    }
lukashov's avatar
lukashov committed
2546 2547 2548


#ifdef DEBUG_DLSCH_MODULATION
2549
  printf("generate_dlsch : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch0_harq->nb_rb,dlsch0_harq->rb_alloc,mod_order0,Nl0,2,0,subframe_offset,1/*transmission mode*/));
lukashov's avatar
lukashov committed
2550 2551 2552 2553 2554 2555 2556 2557
#endif

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);

  return (re_allocated);
}


2558
int mch_modulation(int32_t **txdataF,
2559 2560 2561 2562 2563
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
                   LTE_eNB_DLSCH_t *dlsch)
{
2564 2565 2566 2567 2568 2569 2570 2571 2572 2573
  uint8_t nsymb,nsymb_pmch;
  uint32_t i,jj,re_allocated,symbol_offset;
  uint16_t l,rb,re_offset;
  uint8_t skip_dc=0;
  uint8_t mod_order = get_Qm(dlsch->harq_processes[0]->mcs);
  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;
2574

2575
  if (mod_order == 4)
2576
    for (i=0; i<4; i++) {
2577 2578 2579
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
2580
    for (i=0; i<8; i++) {
2581
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
2582 2583 2584
    }

  jj=0;
2585
  re_allocated=0;
2586

2587
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
2588 2589
  for (l=2; l<nsymb_pmch; l++) {

2590
#ifdef DEBUG_DLSCH_MODULATION
2591
    printf("Generating MCH (mod %d) in subframe %d for symbol %d\n",mod_order, subframe_offset,l);
2592
#endif
2593 2594 2595 2596

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

2597 2598
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

2599 2600

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

lukashov's avatar
lukashov committed
2602
    if (rb==(frame_parms->N_RB_DL>>1))
2603 2604 2605
          skip_dc = 1;
        else
          skip_dc = 0;
2606 2607 2608 2609

      }

      if (mod_order == 4)
2610
        qam_table_s = qam16_table_a;
2611
      else if (mod_order == 6)
2612
        qam_table_s = qam64_table_a;
2613
      else
2614
        qam_table_s = NULL;
2615

lukashov's avatar
lukashov committed
2616
      //printf("Allocated rb %d, subframe_offset %d,amp %d\n",rb,subframe_offset,amp);
2617
      allocate_REs_in_RB_MCH(txdataF,
2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629
                             &jj,
                             re_offset,
                             symbol_offset,
                             dlsch->harq_processes[0]->e,
                             l,
                             mod_order,
                             amp,
                             qam_table_s,
                             &re_allocated,
                             skip_dc,
                             frame_parms);

2630
      re_offset+=12; // go to next RB
2631

2632 2633
      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
2634 2635 2636 2637
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
2638 2639 2640 2641 2642
      }
    }
  }

#ifdef DEBUG_DLSCH_MODULATION
2643
  printf("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*/));
2644
#endif
2645 2646

  return (re_allocated);
2647
}