dlsch_modulation.c 53.2 KB
Newer Older
1
/*******************************************************************************
2 3
  OpenAirInterface
  Copyright(c) 1999 - 2014 Eurecom
4

5 6 7 8
  OpenAirInterface is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
9 10


11 12 13 14
  OpenAirInterface is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
15

16 17 18 19
  You should have received a copy of the GNU General Public License
  along with OpenAirInterface.The full GNU General Public License is
  included in this distribution in the file called "COPYING". If not,
  see <http://www.gnu.org/licenses/>.
20 21

  Contact Information
ghaddab's avatar
ghaddab committed
22 23 24
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
25

26
Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27

ghaddab's avatar
ghaddab committed
28
 *******************************************************************************/
29 30

/*! \file PHY/LTE_TRANSPORT/dlsch_modulation.c
31 32 33 34 35 36 37 38 39
 * \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
 */
40 41 42 43 44 45 46
#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"
47
#include "UTIL/LOG/vcd_signal_dumper.h"
48

49
//#define DEBUG_DLSCH_MODULATION
50 51 52

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

53 54
uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots)
{
55 56 57

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

59 60 61 62 63 64
  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);
65
  } else { // 2 antenna pilots
66 67 68
    if ((re!=nushiftmod3) && (re!=nushiftmod3+6) && (re!=nushiftmod3+3) && (re!=nushiftmod3+9))
      return(1);
  }
69

70 71 72
  return(0);
}

73
//uint8_t is_not_UEspecRS(int first_layer,int re)
74
uint8_t is_not_UEspecRS(int8_t lprime, uint8_t re, uint8_t nushift, uint8_t Ncp, uint8_t beamforming_mode)
75
{
76 77
  uint8_t offset = (lprime==1||lprime==3)?2:0;
  if (lprime==-1)
78 79
    return(1);

80
  switch (beamforming_mode) {
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    case 7:
      if (Ncp == NORMAL){
        if ((re!=nushift+offset) && (re!=((nushift+4+offset)%12)) &&  (re!=((nushift+8+offset)%12))) 
          return(1);
        /*else{
          printf("(is_no_UEspec_RS):lprime=%d, re=%d, nushift=%d, offset=%d\n",lprime, re,nushift,offset);
        }*/
      } else { 
        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
98

99
  return(0);
Raymond Knopp's avatar
 
Raymond Knopp committed
100 101
}

102 103
void generate_64qam_table(void)
{
104 105 106 107

  int a,b,c,index;


108 109 110 111 112 113
  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
      }
114 115
}

116 117
void generate_16qam_table(void)
{
118 119 120

  int a,b,index;

121 122 123 124 125
  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));
    }
126 127 128 129 130
}




131 132
void layer1prec2A(int32_t *antenna0_sample, int32_t *antenna1_sample, uint8_t precoding_index)
{
133 134 135

  switch (precoding_index) {

136 137 138
    case 0: // 1 1
      *antenna1_sample=*antenna0_sample;
      break;
139

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

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

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

  // normalize
157
  /*  ((int16_t *)antenna0_sample)[0] = (int16_t)((((int16_t *)antenna0_sample)[0]*ONE_OVER_SQRT2_Q15)>>15);
158 159
      ((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);  */
160
}
161

162
int allocate_REs_in_RB(PHY_VARS_eNB *phy_vars_eNB,
163 164 165 166 167 168 169 170 171 172 173 174 175 176
                       mod_sym_t **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,
177 178 179 180 181
                       uint8_t skip_half,
                       uint8_t lprime,
                       uint8_t mprime,
                       uint8_t Ns,
                       int32_t **beamforming_weights)
182
{
183

184
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->lte_frame_parms;
185 186 187 188
  uint8_t *x0             = dlsch0_harq->e;
  MIMO_mode_t mimo_mode   = dlsch0_harq->mimo_mode;

  int first_layer0        = dlsch0_harq->first_layer;
189
  int Nlayers0            = dlsch0_harq->Nlayers;
190 191 192
  uint8_t mod_order0      = get_Qm(dlsch0_harq->mcs);


Raymond Knopp's avatar
 
Raymond Knopp committed
193 194
  uint8_t *x1=NULL;
  uint8_t mod_order1=2;
195

Raymond Knopp's avatar
 
Raymond Knopp committed
196 197 198
  // Fill these in later for TM8-10
  //  int Nlayers1;
  //  int first_layer1;
199
  int use2ndpilots = (frame_parms->mode1_flag==1)?1:0;
200 201 202 203 204 205 206

  uint32_t tti_offset,aa;
  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;
207 208 209 210 211 212 213 214 215 216 217
  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;

218 219
  int16_t gain_lin_QPSK;//,gain_lin_16QAM1,gain_lin_16QAM2;
  int16_t re_off=re_offset;
220

221 222 223
  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;
  int16_t tmp_amp=amp;
224
  uint8_t layer;
225
  int s=1;
226
        
227
  int mprime2 = mprime,ind,ind_dword,ind_qpsk_symb;
228
  mod_sym_t qpsk[4];
229 230 231

  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
  //  if (mimo_mode == LARGE_CDD) gain_lin_QPSK>>=1;
232 233 234 235 236 237 238 239 240
  ((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;

241 242 243

  if (dlsch1_harq) {
    x1             = dlsch1_harq->e;
Raymond Knopp's avatar
 
Raymond Knopp committed
244
    // Fill these in later for TM8-10
245
    //    Nlayers1       = dlsch1_harq->Nlayers;
Raymond Knopp's avatar
 
Raymond Knopp committed
246
    //    first_layer1   = dlsch1_harq->first_layer;
247 248 249
    mod_order1     = get_Qm(dlsch1_harq->mcs);

  }
250

251
  /*
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
     switch (mod_order) {
     case 2:
// QPSK single stream

break;
case 4:
//16QAM Single stream
gain_lin_16QAM1 = (int16_t)(((int32_t)amp*QAM16_n1)>>15);
gain_lin_16QAM2 = (int16_t)(((int32_t)amp*QAM16_n2)>>15);

break;

case 6:
//64QAM Single stream
break;
default:
break;
}
   */
271

272 273 274
//#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
275 276 277

  first_re=0;
  last_re=12;
278
  
279
  if (skip_half==1)
280 281 282
    last_re=6;
  else if (skip_half==2)
    first_re=6;
283 284 285
  
    for (re=first_re; re<last_re; re++) {
  
286 287
    if ((skip_dc == 1) && (re==6))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
288 289


290 291
    tti_offset = symbol_offset + re_off + re;
    // printf("tti_offset = %d\n", tti_offset);
Raymond Knopp's avatar
 
Raymond Knopp committed
292 293
    // check that RE is not from Cell-specific RS

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

297

298
      if (mimo_mode == SISO) {  //SISO mapping
299 300 301
        *re_allocated = *re_allocated + 1;

        switch (mod_order0) {
302
          case 2:  //QPSK
303

304
//          printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
305 306 307 308
          for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
            ((int16_t*)&txdataF[aa][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
          }

309
            *jj = *jj + 1;
310

311 312 313
            for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
              ((int16_t*)&txdataF[aa][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
            }
314

315
            *jj = *jj + 1;
316

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

320
          case 4:  //16QAM
321

322 323
            qam16_table_offset_re = 0;
            qam16_table_offset_im = 0;
324

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

328
            *jj=*jj+1;
329

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

333
            *jj=*jj+1;
334 335


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

339
            *jj=*jj+1;
340

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

344
            *jj=*jj+1;
345

346 347 348 349 350 351
            for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
              ((int16_t *)&txdataF[aa][tti_offset])[0]+=qam_table_s0[qam16_table_offset_re];
              ((int16_t *)&txdataF[aa][tti_offset])[1]+=qam_table_s0[qam16_table_offset_im];
              //      ((int16_t *)&txdataF[aa][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
              //      ((int16_t *)&txdataF[aa][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
            }
352

353
            break;
354

355
          case 6:  //64QAM
356 357


358 359
            qam64_table_offset_re = 0;
            qam64_table_offset_im = 0;
360

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

364
            *jj=*jj+1;
365

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

369
            *jj=*jj+1;
370

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

374
            *jj=*jj+1;
375

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

379
            *jj=*jj+1;
380

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

384
            *jj=*jj+1;
385

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

389
            *jj=*jj+1;
390

391 392 393 394
            for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
              ((int16_t *)&txdataF[aa][tti_offset])[0]+=qam_table_s0[qam64_table_offset_re];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
              ((int16_t *)&txdataF[aa][tti_offset])[1]+=qam_table_s0[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
            }
395

396
            break;
397 398

        }
399
      }
400 401 402 403 404 405 406

      else if (mimo_mode == ALAMOUTI) {
        *re_allocated = *re_allocated + 1;
        // normalization for 2 tx antennas
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);

        switch (mod_order0) {
407
          case 2:  //QPSK
408

409
            // first antenna position n -> x0
410

411 412 413 414
            ((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;
415

416
            // second antenna position n -> -x1*
417

418 419 420 421
            ((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;
422

423 424 425 426 427
            // normalization for 2 tx antennas
            ((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);
            ((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);
428

429
            break;
430

431
          case 4:  //16QAM
432

433
            // Antenna 0 position n
434

435 436
            qam16_table_offset_re = 0;
            qam16_table_offset_im = 0;
437

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

441
            *jj=*jj+1;
442

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

446
            *jj=*jj+1;
447 448


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

452
            *jj=*jj+1;
453

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

457
            *jj=*jj+1;
458

459 460
            ((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);
461

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

464 465
            qam16_table_offset_re = 0;
            qam16_table_offset_im = 0;
466

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

470
            *jj=*jj+1;
471

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

475
            *jj=*jj+1;
476 477


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

481
            *jj=*jj+1;
482

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

486
            *jj=*jj+1;
487

488 489
            ((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);
490 491


492
            break;
493

494
          case 6:   // 64-QAM
495

496 497 498
            // Antenna 0
            qam64_table_offset_re = 0;
            qam64_table_offset_im = 0;
499

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

503
            *jj=*jj+1;
504

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

508
            *jj=*jj+1;
509

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

513
            *jj=*jj+1;
514

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

518
            *jj=*jj+1;
519

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

523
            *jj=*jj+1;
524

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

528
            *jj=*jj+1;
529

530 531
            ((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);
532 533


534 535 536
            // Antenna 1 => -x1*
            qam64_table_offset_re = 0;
            qam64_table_offset_im = 0;
537

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

541
            *jj=*jj+1;
542

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

546
            *jj=*jj+1;
547

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

551
            *jj=*jj+1;
552

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

556
            *jj=*jj+1;
557

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

561
            *jj=*jj+1;
562

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

566
            *jj=*jj+1;
567

568 569
            ((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);
570

571
            break;
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
        }

        // fill in the rest of the ALAMOUTI precoding
        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];
        }
      } else if (mimo_mode == LARGE_CDD) {

        *re_allocated = *re_allocated + 1;

        if (frame_parms->nb_antennas_tx == 2) {
          switch (mod_order0) {
592 593 594 595 596 597 598 599 600 601 602
            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;
603 604 605



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

609
            case 4:  //16QAM
610

611 612
              qam16_table_offset_re0 = 0;
              qam16_table_offset_im0 = 0;
613

614 615
              if (x0[*jj] == 1)
                qam16_table_offset_re0+=2;
616

617
              *jj=*jj+1;
618

619 620
              if (x0[*jj] == 1)
                qam16_table_offset_im0+=2;
621

622
              *jj=*jj+1;
623

624 625
              if (x0[*jj] == 1)
                qam16_table_offset_re0+=1;
626

627
              *jj=*jj+1;
628

629 630
              if (x0[*jj] == 1)
                qam16_table_offset_im0+=1;
631

632
              *jj=*jj+1;
633

634 635
              xx0_re = qam_table_s0[qam16_table_offset_re0];
              xx0_im = qam_table_s0[qam16_table_offset_im0];
636

637
              break;
638

639
            case 6:  //64QAM
640 641


642 643
              qam64_table_offset_re0 = 0;
              qam64_table_offset_im0 = 0;
644

645 646
              if (x0[*jj] == 1)
                qam64_table_offset_re0+=4;
647

648
              *jj=*jj+1;
649

650 651
              if (x0[*jj] == 1)
                qam64_table_offset_im0+=4;
652

653
              *jj=*jj+1;
654

655 656
              if (x0[*jj] == 1)
                qam64_table_offset_re0+=2;
657

658
              *jj=*jj+1;
659

660 661
              if (x0[*jj] == 1)
                qam64_table_offset_im0+=2;
662

663
              *jj=*jj+1;
664

665 666
              if (x0[*jj] == 1)
                qam64_table_offset_re0+=1;
667

668
              *jj=*jj+1;
669

670 671
              if (x0[*jj] == 1)
                qam64_table_offset_im0+=1;
672

673
              *jj=*jj+1;
674

675 676
              xx0_re = qam_table_s0[qam64_table_offset_re0];
              xx0_im = qam_table_s0[qam64_table_offset_im0];
677 678


679
              break;
680 681 682 683

          }

          switch (mod_order1) {
684 685 686 687
            default:
              LOG_E(PHY,"Unknown mod_order1 %d\n",mod_order1);
              xx1_re=xx1_im=0;
              break;
688

689 690 691 692 693 694 695 696
            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]);
              xx1_re = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
              *jj2 = *jj2 + 1;
              xx1_im = (x1[*jj2]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
              *jj2 = *jj2 + 1;
              // printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
              break;
697

698
            case 4:  //16QAM
699

700 701
              qam16_table_offset_re1 = 0;
              qam16_table_offset_im1 = 0;
702

703 704
              if (x1[*jj2] == 1)
                qam16_table_offset_re1+=2;
705

706
              *jj2 = *jj2 + 1;
707

708 709
              if (x1[*jj2] == 1)
                qam16_table_offset_im1+=2;
710

711
              *jj2 = *jj2 + 1;
712

713 714
              if (x1[*jj2] == 1)
                qam16_table_offset_re1+=1;
715

716
              *jj2 = *jj2 + 1;
717

718 719
              if (x1[*jj2] == 1)
                qam16_table_offset_im1+=1;
720

721
              *jj2 = *jj2 + 1;
722

723 724
              xx1_re = qam_table_s1[qam16_table_offset_re1];
              xx1_im = qam_table_s1[qam16_table_offset_im1];
725

726
              break;
727

728
            case 6:  //64QAM
729

730 731
              qam64_table_offset_re1 = 0;
              qam64_table_offset_im1 = 0;
732

733 734
              if (x1[*jj2] == 1)
                qam64_table_offset_re1+=4;
735

736
              *jj2 = *jj2 + 1;
737

738 739
              if (x1[*jj2] == 1)
                qam64_table_offset_im1+=4;
740

741
              *jj2 = *jj2 + 1;
742

743 744
              if (x1[*jj2] == 1)
                qam64_table_offset_re1+=2;
745

746
              *jj2 = *jj2 + 1;
747

748 749
              if (x1[*jj2] == 1)
                qam64_table_offset_im1+=2;
750

751
              *jj2 = *jj2 + 1;
752

753 754
              if (x1[*jj2] == 1)
                qam64_table_offset_re1+=1;
755

756
              *jj2 = *jj2 + 1;
757

758 759
              if (x1[*jj2] == 1)
                qam64_table_offset_im1+=1;
760

761
              *jj2 = *jj2 + 1;
762

763 764
              xx1_re = qam_table_s1[qam64_table_offset_re1];
              xx1_im = qam_table_s1[qam64_table_offset_im1];
765 766


767
              break;
768 769 770 771 772 773 774 775 776 777 778 779 780 781

          }

          // This implements the Large CDD precoding for 2 TX antennas
          // -  -        -    -  -         -  -     -  -  -       -              -
          //| y0 |      | 1  0 || 1    0    || 1   1 || x0 |     |        x0 + x1 |
          //| y1 | = .5 | 0  1 || 0  (-1)^i || 1  -1 || x1 | = .5| (-1)^i(x0 - x1)|
          // -  -        -    -  -         -  -     -  -  -       -
          // Note: Factor .5 is accounted for in amplitude when calling this function
          ((int16_t *)&txdataF[0][tti_offset])[0]+=((xx0_re+xx1_re)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[0]+=(s*((xx0_re-xx1_re)>>1));
          ((int16_t *)&txdataF[0][tti_offset])[1]+=((xx0_im+xx1_im)>>1);
          ((int16_t *)&txdataF[1][tti_offset])[1]+=(s*((xx0_im-xx1_im)>>1));
          /*
782 783 784 785
             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]);
           */
786 787 788 789 790 791 792 793 794
          // s alternates +1/-1 for each RE
          s = -s;
        }
      } else if ((mimo_mode >= UNIFORM_PRECODING11)&&(mimo_mode <= PUSCH_PRECODING1)) {
        // this is for transmission modes 4-6 (1 layer)
        *re_allocated = *re_allocated + 1;
        amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);

        switch (mod_order0) {
795
          case 2:  //QPSK
796

797 798 799 800
            ((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;
801

802 803 804
            // normalization for 2 tx antennas
            ((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);
805

806 807 808 809 810
            if (frame_parms->nb_antennas_tx == 2) {
              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);
            }
811

812
            break;
813

814
          case 4:  //16QAM
815

816 817
            qam16_table_offset_re = 0;
            qam16_table_offset_im = 0;
818

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

822
            *jj=*jj+1;
823

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

827
            *jj=*jj+1;
828 829


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

833
            *jj=*jj+1;
834

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

838
            *jj=*jj+1;
839

840 841
            ((int16_t*)&tmp_sample1)[0] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
            ((int16_t*)&tmp_sample1)[1] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
842

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

846 847 848 849 850
            if (frame_parms->nb_antennas_tx == 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];
            }
851

852
            break;
853

854
          case 6:  //64QAM
855 856


857 858
            qam64_table_offset_re = 0;
            qam64_table_offset_im = 0;
859

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

863
            *jj=*jj+1;
864

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

868
            *jj=*jj+1;
869

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

873
            *jj=*jj+1;
874

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

878
            *jj=*jj+1;
879

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

883
            *jj=*jj+1;
884

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

888
            *jj=*jj+1;
889

890 891
            ((int16_t*)&tmp_sample1)[0] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
            ((int16_t*)&tmp_sample1)[1] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
892

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

896 897 898 899 900
            if (frame_parms->nb_antennas_tx == 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];
            }
901

902
            break;
903 904

        }
905
      } else if(mimo_mode == TM7){
906 907
        *re_allocated = *re_allocated + 1;

908
        if (is_not_UEspecRS(lprime,re,frame_parms->Nid_cell%3,frame_parms->Ncp,7)) {
Raymond Knopp's avatar
 
Raymond Knopp committed
909

910 911
          switch (mod_order0){
            case 2:  //QPSK
912

913
              ((int16_t*)&tmp_sample1)[0] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
914
              *jj = *jj + 1;
915
              ((int16_t*)&tmp_sample1)[1] = (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
916 917
              *jj = *jj + 1;

918
              //printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&tmp_sample1)[0],((int16_t*)&tmp_sample1)[1]);
919
              for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
920 921 922 923
                ((int16_t*)&txdataF[aa][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[0] +=-(int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
924 925 926 927 928 929
              }

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

            case 4:  //16QAM
930 931 932 933 934 935 936

              qam16_table_offset_re = 0;
              qam16_table_offset_im = 0;

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

937
              *jj=*jj+1;
938 939 940 941

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

942 943
              *jj=*jj+1;

944 945 946 947

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

948
              *jj=*jj+1;
949 950 951 952

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

953 954 955 956
              *jj=*jj+1;

              ((int16_t*)&tmp_sample1)[0] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
              ((int16_t*)&tmp_sample1)[1] = (int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
957

958
              for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
959 960 961 962
                ((int16_t*)&txdataF[aa][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[0] +=-(int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
963 964
              }

965
              break;
966

967
            case 6:  //64QAM
968 969


970 971
              qam64_table_offset_re = 0;
              qam64_table_offset_im = 0;
972

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

976
              *jj=*jj+1;
977

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

981
              *jj=*jj+1;
982

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

986
              *jj=*jj+1;
987

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

991
              *jj=*jj+1;
992

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

996
              *jj=*jj+1;
997

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

1001
              *jj=*jj+1;
1002

1003 1004
              ((int16_t*)&tmp_sample1)[0] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
              ((int16_t*)&tmp_sample1)[1] = (int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
1005

1006
              for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
                ((int16_t*)&txdataF[aa][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[0] +=-(int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
                ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
              }

              break;

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

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

1024 1025
          tmp_sample1 = qpsk[(phy_vars_eNB->lte_gold_uespec_port5_table[0][Ns][ind_dword]>>(2*ind_qpsk_symb))&3];
          mprime2++;
1026

1027
          for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
1028 1029 1030 1031 1032
           
            ((int16_t*)&txdataF[aa][tti_offset])[0] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
            ((int16_t*)&txdataF[aa][tti_offset])[0] +=-(int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
            ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[0]*((int16_t*)&beamforming_weights[re][aa])[1])>>15);
            ((int16_t*)&txdataF[aa][tti_offset])[1] += (int16_t)((((int16_t*)&tmp_sample1)[1]*((int16_t*)&beamforming_weights[re][aa])[0])>>15);
1033 1034 1035

            // ((int16_t*)&txdataF[aa][tti_offset])[0] = 0xffff;
            // ((int16_t*)&txdataF[aa][tti_offset])[1] = 0xffff;
Xiwen JIANG's avatar
Xiwen JIANG committed
1036 1037 1038 1039
            //printf("lprime=%d,nb_rb=%d,mprime2=%d,ind=%d,Ns=%d\n",lprime,dlsch0_harq->nb_rb,mprime2,ind,Ns);
            //printf("tmp_sample1=(%d,%d)\n",((int16_t*)&tmp_sample1)[0],((int16_t*)&tmp_sample1)[1]);
            //printf("beamforing_weights[%d][%d]=(%d,%d)\n",re,aa,((int16_t*)&beamforming_weights[re][aa])[0],((int16_t*)&beamforming_weights[re][aa])[1]);
            //printf("txdataF[%d][%d]= (%d,%d)\n ",aa,tti_offset,((int16_t*)&txdataF[aa][tti_offset])[0],((int16_t*)&txdataF[aa][tti_offset])[1]);
1040
          }
1041

1042
        }
1043
      } else if (mimo_mode == TM8) { //TM8
1044 1045
        msg("allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
        return(-1);
Raymond Knopp's avatar
 
Raymond Knopp committed
1046
      }
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
      if (mimo_mode == ALAMOUTI) {
        re++;  // adjacent carriers are taken care of by precoding
        *re_allocated = *re_allocated + 1;

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

1057
    }
1058 1059


1060
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
1061

1062
return(0);
1063 1064 1065
}

int allocate_REs_in_RB_MCH(mod_sym_t **txdataF,
1066
                           uint32_t *jj,
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
                            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)
1077
{
1078 1079 1080 1081 1082 1083 1084 1085 1086

  uint32_t tti_offset,aa;
  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;
1087
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
1088 1089 1090
  uint8_t first_re,last_re;
  int inc;
#ifdef DEBUG_DLSCH_MODULATION
1091
  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]);
1092 1093 1094 1095 1096
#endif

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

1098 1099 1100
  if ((l==2)||(l==10)) {
    inc=2;
    first_re=1;
1101
  } else if (l==6) {
1102 1103
    inc=2;
  }
1104 1105 1106

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

1107 1108
    if ((skip_dc == 1) && (re==(6+first_re)))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
1109

1110
    tti_offset = symbol_offset + re_off + re;
1111

1112 1113
    //    printf("re %d (jj %d)\n",re,*jj);
    *re_allocated = *re_allocated + 1;
1114 1115


1116
    switch (mod_order) {
1117
      case 2:  //QPSK
1118

1119
      //            printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
1120
      for (aa=0; aa<frame_parms->nb_antennas_tx; aa++)
1121 1122
        ((int16_t*)&txdataF[aa][tti_offset])[0] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i

1123
        *jj = *jj + 1;
1124

1125 1126
        for (aa=0; aa<frame_parms->nb_antennas_tx; aa++)
          ((int16_t*)&txdataF[aa][tti_offset])[1] += (x0[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
1127

1128
    *jj = *jj + 1;
1129

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

1133
      case 4:  //16QAM
1134

1135 1136
    qam16_table_offset_re = 0;
    qam16_table_offset_im = 0;
1137

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

1141
    *jj=*jj+1;
1142

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

1146
    *jj=*jj+1;
1147 1148


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

1152
    *jj=*jj+1;
1153

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

1157
    *jj=*jj+1;
1158

1159 1160 1161 1162 1163 1164
    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
      ((int16_t *)&txdataF[aa][tti_offset])[0]+=qam_table_s[qam16_table_offset_re];
      ((int16_t *)&txdataF[aa][tti_offset])[1]+=qam_table_s[qam16_table_offset_im];
      //      ((int16_t *)&txdataF[aa][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
      //      ((int16_t *)&txdataF[aa][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_im])>>15);
    }
1165

1166
    break;
1167

1168
      case 6:  //64QAM
1169 1170


1171 1172
    qam64_table_offset_re = 0;
    qam64_table_offset_im = 0;
1173

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

1177
    *jj=*jj+1;
1178

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

1182
    *jj=*jj+1;
1183

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

1187
    *jj=*jj+1;
1188

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

1192
    *jj=*jj+1;
1193

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

1197
    *jj=*jj+1;
1198

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

1202
    *jj=*jj+1;
1203

1204 1205 1206 1207
    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
      ((int16_t *)&txdataF[aa][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[aa][tti_offset])[1]+=qam_table_s[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
    }
1208

1209
    break;
1210

1211
    }
1212 1213
  }

1214 1215 1216
  return(0);
}

1217 1218
uint8_t get_pmi(uint8_t N_RB_DL,LTE_DL_eNB_HARQ_t *dlsch_harq,uint16_t rb)
{
1219 1220 1221 1222


  MIMO_mode_t mode   = dlsch_harq->mimo_mode;
  uint32_t pmi_alloc = dlsch_harq->pmi_alloc;
1223 1224

  //  printf("Getting pmi for RB %d => %d\n",rb,(pmi_alloc>>((rb>>2)<<1))&3);
Raymond Knopp's avatar
 
Raymond Knopp committed
1225
  switch (N_RB_DL) {
1226 1227 1228 1229 1230
    case 6:   // 1 PRB per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>(rb<<1))&3);
      else
        return((pmi_alloc>>rb)&1);
1231

1232
      break;
1233

1234 1235 1236 1237 1238 1239
    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);
1240

1241
      break;
1242

1243 1244 1245 1246 1247
    case 50: // 6 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb/6)<<1))&3);
      else
        return((pmi_alloc>>(rb/6))&1);
1248

1249
      break;
1250

1251 1252 1253 1254 1255
    case 100: // 8 PRBs per subband
      if (mode <= PUSCH_PRECODING1)
        return((pmi_alloc>>((rb>>3)<<1))&3);
      else
        return((pmi_alloc>>(rb>>3))&1);
1256

1257
      break;
Raymond Knopp's avatar
 
Raymond Knopp committed
1258
  }
1259 1260
}

Raymond Knopp's avatar
 
Raymond Knopp committed
1261

1262 1263
int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
                     mod_sym_t **txdataF,
1264 1265 1266 1267
                     int16_t amp,
                     uint32_t subframe_offset,
                     uint8_t num_pdcch_symbols,
                     LTE_eNB_DLSCH_t *dlsch0,
1268 1269
                     LTE_eNB_DLSCH_t *dlsch1,
                     int32_t **beamforming_weights)
1270
{
1271
  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_eNB->lte_frame_parms;
1272 1273

  uint8_t nsymb;
1274 1275 1276 1277
  uint8_t harq_pid = dlsch0->current_harq_pid;
  LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
  LTE_DL_eNB_HARQ_t *dlsch1_harq; //= dlsch1->harq_processes[harq_pid];
  uint32_t i,jj,jj2,re_allocated,symbol_offset;
1278 1279
  uint16_t l,rb,re_offset;
  uint32_t rb_alloc_ind;
1280
  uint32_t *rb_alloc = dlsch0_harq->rb_alloc;
Xiwen JIANG's avatar
Xiwen JIANG committed
1281
  uint8_t pilots=0;
1282
  uint8_t skip_dc,skip_half;
1283
  uint8_t mod_order0 = get_Qm(dlsch0_harq->mcs);
1284
  uint8_t mod_order1 = 0;
1285
  int16_t amp_rho_a, amp_rho_b;
1286 1287 1288
  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];
  int16_t *qam_table_s0,*qam_table_s1;
1289 1290
  MIMO_mode_t mimo_mode = dlsch0_harq->mimo_mode;
  int32_t **beamforming_weights_RB = beamforming_weights;
1291 1292
  uint8_t mprime=0,Ns;
  int8_t  lprime=-1;
1293

Raymond Knopp's avatar
 
Raymond Knopp committed
1294
#ifdef DEBUG_DLSCH_MODULATION
1295 1296
  uint8_t Nl0 = dlsch0_harq->Nl;
  uint8_t Nl1;
Raymond Knopp's avatar
 
Raymond Knopp committed
1297
#endif
1298 1299 1300 1301 1302 1303 1304 1305

  if (dlsch1) {
    dlsch1_harq = dlsch1->harq_processes[harq_pid];
    mod_order1 = get_Qm(dlsch1_harq->mcs);
#ifdef DEBUG_DLSCH_MODULATION
    Nl1 = dlsch1_harq->Nl;
#endif
  }
1306

1307
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);
1308

1309
  nsymb = (frame_parms->Ncp==0) ? 14:12;
1310

1311 1312
  amp_rho_a = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_a)>>13);
  amp_rho_b = (int16_t)(((int32_t)amp*dlsch0->sqrt_rho_b)>>13);
1313

1314
  if (mod_order0 == 4)
1315
    for (i=0;i<4; i++) {
1316 1317
      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);
1318
    }
1319
  else if (mod_order0 == 6)
1320
    for (i=0; i<8; i++) {
1321 1322
      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);
1323
    }
1324 1325

  if (mod_order1 == 4)
1326
    for (i=0; i<4; i++) {
1327 1328 1329
      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
1330
  else if (mod_order1 == 6)
1331
    for (i=0; i<8; i++) {
1332 1333
      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);
1334 1335
    }

1336
  //Modulation mapping (difference w.r.t. LTE specs)
1337 1338 1339

  jj=0;
  jj2=0;
1340
  re_allocated=0;
1341

1342
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
1343 1344
  for (l=num_pdcch_symbols; l<nsymb; l++) {

1345
#ifdef DEBUG_DLSCH_MODULATION
1346
    msg("Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc0 %llx, mod0 %d, mod1 %d, rb_alloc[0] %d) in %d\n",
1347 1348 1349 1350 1351 1352 1353 1354
        harq_pid,
        dlsch0_harq->mimo_mode,
        pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),
        mod_order0,
        mod_order1,
        rb_alloc[0],
        l);
#endif
1355 1356 1357

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
1358
        pilots=2;   // pilots in nushift+3, nushift+9
1359
      else if (l==7)
1360
        pilots=1;   // pilots in nushift, nushift+6
1361
      else
1362 1363
        pilots=0;
    } else {
1364
      if ((l==3)||(l==9))
1365
        pilots=2;
1366
      else if (l==6)
1367
        pilots=1;
1368
      else
1369
        pilots=0;
1370 1371
    }

1372 1373 1374
    if(mimo_mode==TM7){ //36.211 V8.6.0 2009-03
      mprime = 0;
      if (frame_parms->Ncp==0) { // normal prefix
1375 1376 1377 1378 1379 1380 1381 1382
        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
1383
        else
1384
          lprime=-1;
1385
      } else {
1386
        if (l==10)
1387
          lprime=2;
1388
        else if (l==7)
1389
          lprime=1;
1390
        else if (l==4)
1391
          lprime=0;
1392 1393
        else
          lprime=-1;
1394 1395 1396
      }
    }
  
1397
    Ns = 2*subframe_offset+(l>=(nsymb>>1));
1398

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

    //for (aa=0;aa<frame_parms->nb_antennas_tx;aa++)
1403
    //  memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
1404
    //printf("symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 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
    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;

      // check for PBCH
      skip_half=0;

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

        if (rb==(frame_parms->N_RB_DL>>1))
          skip_dc = 1;
        else
          skip_dc = 0;

        // PBCH
        if ((subframe_offset==0) &&
            (rb>((frame_parms->N_RB_DL>>1)-3)) &&
            (rb<((frame_parms->N_RB_DL>>1)+3)) &&
            (l>=(nsymb>>1)) &&
            (l<((nsymb>>1) + 4))) {
          rb_alloc_ind = 0;
        }

        //PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
        if ((subframe_offset==0) &&
            (rb==((frame_parms->N_RB_DL>>1)-3)) &&
            (l>=(nsymb>>1)) &&
            (l<((nsymb>>1) + 4)))
          skip_half=1;
        else if ((subframe_offset==0) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4)))
          skip_half=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)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)) ) {
            rb_alloc_ind = 0;
          }

          //SSS TDD
          if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==(nsymb-1)))
            skip_half=1;
          else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(nsymb-1)))
            skip_half=2;

          //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) ) {
            rb_alloc_ind = 0;
          }

          //PSS TDD
          if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==2))
            skip_half=1;
          else if (((subframe_offset==1)||(subframe_offset==6)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==2))
            skip_half=2;
        } else {
          //PSS 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)-1)) ) {
            rb_alloc_ind = 0;
          }

          //PSS FDD
          if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==((nsymb>>1)-1)))
            skip_half=1;
          else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==(((nsymb>>1)-1))))
            skip_half=2;

          //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)) ) {
            rb_alloc_ind = 0;
          }

          //SSS FDD
          if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && ((l==((nsymb>>1)-2))))
            skip_half=1;
          else if (((subframe_offset==0)||(subframe_offset==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && ((l==(nsymb>>1)-2)))
            skip_half=2;

        }

      } else { // EVEN N_RB_DL
        //PBCH
        if ((subframe_offset==0) &&
            (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
            (rb<((frame_parms->N_RB_DL>>1)+3)) &&
            (l>=nsymb>>1) && (l<((nsymb>>1) + 4)))
          rb_alloc_ind = 0;

        skip_dc=0;
        skip_half=0;

        if (frame_parms->frame_type == TDD) { // TDD
          //SSS
          if (((subframe_offset==0)||
1510
                (subframe_offset==5)) &&
1511 1512 1513 1514 1515 1516 1517 1518
              (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
              (rb<((frame_parms->N_RB_DL>>1)+3)) &&
              (l==nsymb-1) ) {
            rb_alloc_ind = 0;
          }

          //PSS
          if (((subframe_offset==1)||
1519
                (subframe_offset==6)) &&
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
              (rb>=((frame_parms->N_RB_DL>>1)-3)) &&
              (rb<((frame_parms->N_RB_DL>>1)+3)) &&
              (l==2) ) {
            rb_alloc_ind = 0;
          }
        } 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)) ) {
            rb_alloc_ind = 0;
          }

          //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)) ) {
            rb_alloc_ind = 0;
          }
        }
      }
1537

1538 1539 1540
      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);
1541
      }
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564

      if (dlsch1) {
        if (dlsch1_harq->Nlayers>1) {
          msg("Nlayers %d: re_offset %d, symbol %d offset %d\n",dlsch0_harq->Nlayers,re_offset,l,symbol_offset);
          return(-1);
        }
      }

      if (mod_order0 == 4)
        qam_table_s0 = ((pilots) ? qam16_table_b0 : qam16_table_a0);
      else if (mod_order0 == 6)
        qam_table_s0 = ((pilots) ? qam64_table_b0 : qam64_table_a0);
      else
        qam_table_s0 = NULL;

      if (mod_order1 == 4)
        qam_table_s1 = ((pilots) ? qam16_table_b1 : qam16_table_a1);
      else if (mod_order1 == 6)
        qam_table_s1 = ((pilots) ? qam64_table_b1 : qam64_table_a1);
      else
        qam_table_s1 = NULL;

      if (rb_alloc_ind > 0) {
1565
        // 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);
1566
        allocate_REs_in_RB(phy_vars_eNB,
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
                           txdataF,
                           &jj,
                           &jj2,
                           re_offset,
                           symbol_offset,
                           dlsch0->harq_processes[harq_pid],
                           (dlsch1==NULL) ? NULL : dlsch1->harq_processes[harq_pid],
                           pilots,
                           ((pilots) ? amp_rho_b : amp_rho_a),
                           get_pmi(frame_parms->N_RB_DL,dlsch0->harq_processes[harq_pid],rb),
                           qam_table_s0,
                           qam_table_s1,
                           &re_allocated,
                           skip_dc,
1581 1582 1583 1584 1585 1586
                           skip_half,
                           lprime,
                           mprime,
                           Ns,
                           beamforming_weights_RB);

1587 1588
        if(mimo_mode==TM7 && lprime>=0)
           mprime +=3+frame_parms->Ncp;
1589

1590
      }
1591 1592

      re_offset+=12; // go to next RB
1593
      beamforming_weights_RB +=12;
1594 1595 1596 1597


      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
1598 1599 1600 1601 1602 1603 1604
              if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
                re_offset=1;
              else
                re_offset=7;  // odd number of RBs
          }
              beamforming_weights_RB = beamforming_weights;
               }
1605

1606
      }
1607

1608 1609 1610


#ifdef DEBUG_DLSCH_MODULATION
1611
  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));
1612
#endif
1613

1614
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);
1615

1616 1617 1618 1619
  return (re_allocated);
}

int mch_modulation(mod_sym_t **txdataF,
1620 1621 1622 1623 1624
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
                   LTE_eNB_DLSCH_t *dlsch)
{
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634
  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;
1635

1636
  if (mod_order == 4)
1637
    for (i=0; i<4; i++) {
1638 1639 1640
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
1641
    for (i=0; i<8; i++) {
1642
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
1643 1644 1645
    }

  jj=0;
1646
  re_allocated=0;
1647

1648
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
1649 1650
  for (l=2; l<nsymb_pmch; l++) {

1651
#ifdef DEBUG_DLSCH_MODULATION
1652
    printf("Generating MCH (mod %d) in subframe %d for symbol %d\n",mod_order, subframe_offset,l);
1653
#endif
1654 1655 1656 1657

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

1658 1659
    for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

1660 1661

      if ((frame_parms->N_RB_DL&1) == 1) { // ODD N_RB_DL
1662 1663 1664 1665 1666

        if (rb==(frame_parms->N_RB_DL>>1))
          skip_dc = 1;
        else
          skip_dc = 0;
1667 1668 1669

      }

1670

1671
      if (mod_order == 4)
1672
        qam_table_s = qam16_table_a;
1673
      else if (mod_order == 6)
1674
        qam_table_s = qam64_table_a;
1675
      else
1676
        qam_table_s = NULL;
1677

1678
      //      printf("Allocated rb %d, subframe_offset %d,amp %d\n",rb,subframe_offset,amp);
1679
      allocate_REs_in_RB_MCH(txdataF,
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
                             &jj,
                             re_offset,
                             symbol_offset,
                             dlsch->harq_processes[0]->e,
                             l,
                             mod_order,
                             amp,
                             qam_table_s,
                             &re_allocated,
                             skip_dc,
                             frame_parms);

1692
      re_offset+=12; // go to next RB
1693 1694


1695 1696
      // check if we crossed the symbol boundary and skip DC
      if (re_offset >= frame_parms->ofdm_symbol_size) {
1697 1698 1699 1700
        if (skip_dc == 0)  //even number of RBs (doesn't straddle DC)
          re_offset=1;
        else
          re_offset=7;  // odd number of RBs
1701 1702 1703 1704
      }
    }
  }

1705 1706


1707 1708 1709


#ifdef DEBUG_DLSCH_MODULATION
1710
  msg("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));
1711
#endif
1712 1713

  return (re_allocated);
1714
}