dlsch_modulation.c 36.3 KB
Newer Older
1
/*******************************************************************************
ghaddab's avatar
ghaddab committed
2
3
    OpenAirInterface 
    Copyright(c) 1999 - 2014 Eurecom
4

ghaddab's avatar
ghaddab committed
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


ghaddab's avatar
ghaddab committed
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

ghaddab's avatar
ghaddab committed
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
25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
  
ghaddab's avatar
ghaddab committed
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

/*! \file PHY/LTE_TRANSPORT/dlsch_modulation.c
* \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
*/
#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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

//#define DEBUG_DLSCH_MODULATION 

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

uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots) {

  uint8_t offset = (pilots==2)?3:0;
  int nushiftmod3 = nushift%3;
 
  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);
  }
  else { // 2 antenna pilots
    if ((re!=nushiftmod3) && (re!=nushiftmod3+6) && (re!=nushiftmod3+3) && (re!=nushiftmod3+9))
      return(1);
  }
  return(0);
}

knopp's avatar
   
knopp committed
72
73
74
75
76
uint8_t is_not_UEspecRS(int first_layer,int re) {

  return(1);
}

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
void generate_64qam_table(void) {

  int a,b,c,index;


  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
      } 
}

void generate_16qam_table(void) {

  int a,b,index;

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




void layer1prec2A(int32_t *antenna0_sample, int32_t *antenna1_sample, uint8_t precoding_index) {

  switch (precoding_index) {

  case 0: // 1 1
    *antenna1_sample=*antenna0_sample;
    break;

  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;

  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;

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

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

int allocate_REs_in_RB(mod_sym_t **txdataF,
		       uint32_t *jj,
		       uint16_t re_offset,
		       uint32_t symbol_offset,
		       uint8_t *output,
		       MIMO_mode_t mimo_mode,
		       uint8_t nu,
		       uint8_t pilots,
		       uint8_t mod_order,
		       uint8_t precoder_index,
		       int16_t amp,
		       int16_t *qam_table_s,
		       uint32_t *re_allocated,
		       uint8_t skip_dc,
		       uint8_t skip_half,
		       uint8_t use2ndpilots,
knopp's avatar
   
knopp committed
150
151
		       uint8_t Nlayers,
		       uint8_t first_layer,
152
153
154
155
156
157
158
159
160
161
162
163
164
165
		       LTE_DL_FRAME_PARMS *frame_parms) {

  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;
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);  
  uint8_t first_re,last_re;
  int32_t tmp_sample1,tmp_sample2;
  int16_t tmp_amp=amp;
knopp's avatar
   
knopp committed
166
  uint8_t layer;
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  /*
  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;
  }
*/

#ifdef DEBUG_DLSCH_MODULATION
  printf("allocate_re (mod %d): symbol_offset %d re_offset %d (%d,%d), jj %d -> %d,%d, nu %d\n",mod_order,symbol_offset,re_offset,skip_dc,skip_half,*jj, output[*jj], output[1+*jj],nu);
#endif

  first_re=0;
  last_re=12;

  if (skip_half==1) 
    last_re=6;
  else if (skip_half==2)
    first_re=6;
  
  for (re=first_re;re<last_re;re++) {
    
    if ((skip_dc == 1) && (re==6))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
    
    tti_offset = symbol_offset + re_off + re;
    
knopp's avatar
   
knopp committed
207
208
    // check that RE is not from Cell-specific RS

209
210
    if (is_not_pilot(pilots,re,frame_parms->nushift,use2ndpilots)==1) { 
      //     printf("re %d (jj %d)\n",re,*jj);
knopp's avatar
   
knopp committed
211

212
213
      
      if (mimo_mode == SISO) {  //SISO mapping
knopp's avatar
   
knopp committed
214
	*re_allocated = *re_allocated + 1;	
215
216
	switch (mod_order) {
	case 2:  //QPSK
knopp's avatar
   
knopp committed
217
218
	  //	  printf("%d(%d) : %d,%d => ",tti_offset,*jj,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
	  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
219
	    ((int16_t*)&txdataF[aa][tti_offset])[0] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
knopp's avatar
   
knopp committed
220
	  }
221
	  *jj = *jj + 1;
knopp's avatar
   
knopp committed
222
	  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
223
	    ((int16_t*)&txdataF[aa][tti_offset])[1] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
knopp's avatar
   
knopp committed
224
	  }
225
	  *jj = *jj + 1;
knopp's avatar
   
knopp committed
226
227
	  
	  // printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
	  break;
	  
	case 4:  //16QAM
	  
	  qam16_table_offset_re = 0;
	  qam16_table_offset_im = 0;
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=2;
	  *jj=*jj+1;
	  
	  
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  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);
	  }
	  
	  break;
	  
	case 6:  //64QAM
	  
	  
	  qam64_table_offset_re = 0;
	  qam64_table_offset_im = 0;
knopp's avatar
   
knopp committed
263
	  
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  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);
	  }
	  break;
	  
	}
      }
            
      else if (mimo_mode == ALAMOUTI){
knopp's avatar
   
knopp committed
293
	*re_allocated = *re_allocated + 1;	
294
          // normalization for 2 tx antennas
knopp's avatar
   
knopp committed
295
	amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);
296
297
298
299
300
301

	switch (mod_order) {
	case 2:  //QPSK
	  
	  // first antenna position n -> x0
	  
knopp's avatar
   
knopp committed
302
	  ((int16_t*)&tmp_sample1)[0] = (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	  *jj=*jj+1;
	  ((int16_t*)&tmp_sample1)[1] = (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
	  *jj=*jj+1;
	  
	  // second antenna position n -> -x1*
	  
	  ((int16_t*)&tmp_sample2)[0] = (output[*jj]==1) ? (gain_lin_QPSK) : -gain_lin_QPSK;
	  *jj=*jj+1;
	  ((int16_t*)&tmp_sample2)[1] = (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
	  *jj=*jj+1;
	  
      // 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);

	  break;
	  
	case 4:  //16QAM
	  
	  // Antenna 0 position n 
	  
	  qam16_table_offset_re = 0;
	  qam16_table_offset_im = 0;
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=2;
	  *jj=*jj+1;
	  
	  
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((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);
	  
	  // Antenna 1 position n Real part -> -x1*
	  
	  qam16_table_offset_re = 0;
	  qam16_table_offset_im = 0;
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=2;
	  *jj=*jj+1;
	  
	  
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((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);
	  
	  
	  break;
	case 6:   // 64-QAM
	  
	  // Antenna 0
	  qam64_table_offset_re = 0;
	  qam64_table_offset_im = 0;

	  if (output[*jj] == 1)
	    qam64_table_offset_re+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((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);
	  
	  
	  // Antenna 1 => -x1*
	  qam64_table_offset_re = 0;
	  qam64_table_offset_im = 0;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((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);
	  
	  break;
	}
	// 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 == ANTCYCLING ) {
knopp's avatar
   
knopp committed
441
	*re_allocated = *re_allocated + 1;	
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
	switch (mod_order) {
	case 2:  //QPSK
	  
	  ((int16_t*)&txdataF[re&1][tti_offset])[0] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
	  *jj = *jj + 1;
	  ((int16_t*)&txdataF[re&1][tti_offset])[1] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK;
	  *jj = *jj + 1;
	  break;
	  
	case 4:  //16QAM
	  
	  qam16_table_offset_re = 0;
	  qam16_table_offset_im = 0;

	  if (output[*jj] == 1)
	    qam16_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=2;
	  *jj=*jj+1;
	  
	  
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((int16_t *)&txdataF[re&1][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam16_table[qam16_table_offset_re])>>15);
	  ((int16_t *)&txdataF[re&1][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 (output[*jj] == 1)
	    qam64_table_offset_re+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((int16_t *)&txdataF[re&1][tti_offset])[0]+=(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_re])>>15);
	  ((int16_t *)&txdataF[re&1][tti_offset])[1]+=(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15);
	  
	}
      }
       
      else if ((mimo_mode >= UNIFORM_PRECODING11)&&(mimo_mode <= PUSCH_PRECODING1)) {
	// this is for transmission modes 4-6 (1 layer)
knopp's avatar
   
knopp committed
509
510
	*re_allocated = *re_allocated + 1;	         
	amp = (int16_t)(((int32_t)tmp_amp*ONE_OVER_SQRT2_Q15)>>15);
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613

	switch (mod_order) {
	case 2:  //QPSK

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

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

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

	  break;
	  
	case 4:  //16QAM
	  
	  qam16_table_offset_re = 0;
	  qam16_table_offset_im = 0;

	  if (output[*jj] == 1)
	    qam16_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=2;
	  *jj=*jj+1;
	  
	  
	  if (output[*jj] == 1)
	    qam16_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam16_table_offset_im+=1;
	  *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);

	   ((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_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];
	  }

	  break;
	  
	case 6:  //64QAM
	  
	  
	  qam64_table_offset_re = 0;
	  qam64_table_offset_im = 0;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=4;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=2;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_re+=1;
	  *jj=*jj+1;
	  if (output[*jj] == 1)
	    qam64_table_offset_im+=1;
	  *jj=*jj+1;
	  
	  ((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);

	  ((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_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];
	  }
	  
	  break;
	  
	}
      }
      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;
	}
      }
knopp's avatar
   
knopp committed
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
    
      if (mimo_mode >= TM8) { //TM8,TM9,TM10

	if (is_not_UEspecRS(first_layer,re)) {	  	  	
	  switch (mod_order) {
	  case 2:  //QPSK
	    //	  printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
	    for (layer=first_layer;layer<=(first_layer+Nlayers);layer++) {
	      
	      ((int16_t*)&txdataF[layer][tti_offset])[0] = (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
	      *jj = *jj + 1;
	      ((int16_t*)&txdataF[layer][tti_offset])[1] = (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
	      *jj = *jj + 1;
	    }
	    break;
	  
	  case 4:  //16QAM
	    if (is_not_UEspecRS(layer,re)) {	  	  
	      qam16_table_offset_re = 0;
	      qam16_table_offset_im = 0;
	      if (output[*jj] == 1)
		qam16_table_offset_re+=2;
	      *jj=*jj+1;
	      if (output[*jj] == 1)
		qam16_table_offset_im+=2;
	      *jj=*jj+1;
	      
	      
	      if (output[*jj] == 1)
		qam16_table_offset_re+=1;
	      *jj=*jj+1;
	      if (output[*jj] == 1)
		qam16_table_offset_im+=1;
	      *jj=*jj+1;
	      
	    
	      for (layer=first_layer;layer<=(first_layer+Nlayers);layer++) {
		((int16_t*)&txdataF[layer][tti_offset])[0] = qam_table_s[qam16_table_offset_re];
		((int16_t*)&txdataF[layer][tti_offset])[1] = qam_table_s[qam16_table_offset_im];
	      }
	    }
	    break;
	    
	  case 6:  //64QAM


	    qam64_table_offset_re = 0;
	    qam64_table_offset_im = 0;
	    
	    if (output[*jj] == 1)
	      qam64_table_offset_re+=4;
	    *jj=*jj+1;
	    if (output[*jj] == 1)
	      qam64_table_offset_im+=4;
	    *jj=*jj+1;
	    if (output[*jj] == 1)
	      qam64_table_offset_re+=2;
	    *jj=*jj+1;
	    if (output[*jj] == 1)
	      qam64_table_offset_im+=2;
	    *jj=*jj+1;
	    if (output[*jj] == 1)
	      qam64_table_offset_re+=1;
	    *jj=*jj+1;
	    if (output[*jj] == 1)
	      qam64_table_offset_im+=1;
	    *jj=*jj+1;
	    
	    for (layer=first_layer;layer<=(first_layer+Nlayers);layer++) {
	      ((int16_t*)&txdataF[layer][tti_offset])[0] = qam_table_s[qam64_table_offset_re];
	      ((int16_t*)&txdataF[layer][tti_offset])[1] = qam_table_s[qam64_table_offset_im];
	    }	  
	    break;
	    
	  }
	}
      }
      else if (mimo_mode>=TM9_10) {
	msg("allocate_REs_in_RB() [dlsch.c] : ERROR, unknown mimo_mode %d\n",mimo_mode);
	return(-1);
      }
695
    }
knopp's avatar
   
knopp committed
696
697
      
     
698
  }
knopp's avatar
   
knopp committed
699

700
701
702
703
704
705
706
707
708
709
710
711
712
713
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
745
746
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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
  return(0);
}

int allocate_REs_in_RB_MCH(mod_sym_t **txdataF,
			   uint32_t *jj,
			   uint16_t re_offset,
			   uint32_t symbol_offset,
			   uint8_t *output,
			   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) {

  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;
  gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);  
  uint8_t first_re,last_re;
  int inc;
#ifdef DEBUG_DLSCH_MODULATION
  printf("allocate_re_MCH (mod %d): symbol_offset %d re_offset %d (%d), jj %d -> %d,%d\n",mod_order,symbol_offset,re_offset,skip_dc,*jj, output[*jj], output[1+*jj]);
#endif

  last_re=12;
  first_re=0;
  inc=1;
  if ((l==2)||(l==10)) {
    inc=2;
    first_re=1;
  }
  else if (l==6) {
    inc=2;
  }
  
  for (re=first_re;re<last_re;re+=inc) {
    
    if ((skip_dc == 1) && (re==(6+first_re)))
      re_off=re_off - frame_parms->ofdm_symbol_size+1;
    
    tti_offset = symbol_offset + re_off + re;
    
    //    printf("re %d (jj %d)\n",re,*jj);
    *re_allocated = *re_allocated + 1;
    
    	
    switch (mod_order) {
    case 2:  //QPSK
      //      printf("%d : %d,%d => ",tti_offset,((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
      for (aa=0; aa<frame_parms->nb_antennas_tx; aa++)
	((int16_t*)&txdataF[aa][tti_offset])[0] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //I //b_i
	  *jj = *jj + 1;
	  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++)
	    ((int16_t*)&txdataF[aa][tti_offset])[1] += (output[*jj]==1) ? (-gain_lin_QPSK) : gain_lin_QPSK; //Q //b_{i+1}
	  *jj = *jj + 1;
	  
	  //  printf("%d,%d\n",((int16_t*)&txdataF[0][tti_offset])[0],((int16_t*)&txdataF[0][tti_offset])[1]);
	  break;
	  
    case 4:  //16QAM
      
      qam16_table_offset_re = 0;
      qam16_table_offset_im = 0;
      if (output[*jj] == 1)
	qam16_table_offset_re+=2;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam16_table_offset_im+=2;
      *jj=*jj+1;
      
      
      if (output[*jj] == 1)
	qam16_table_offset_re+=1;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam16_table_offset_im+=1;
      *jj=*jj+1;
      
      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);
      }
      
      break;
      
    case 6:  //64QAM
      
      
      qam64_table_offset_re = 0;
      qam64_table_offset_im = 0;
      
      if (output[*jj] == 1)
	qam64_table_offset_re+=4;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam64_table_offset_im+=4;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam64_table_offset_re+=2;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam64_table_offset_im+=2;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam64_table_offset_re+=1;
      *jj=*jj+1;
      if (output[*jj] == 1)
	qam64_table_offset_im+=1;
      *jj=*jj+1;
      
      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);
      }
      break;
      
    }
  }           
  return(0);
}

knopp's avatar
   
knopp committed
830
uint8_t get_pmi(uint8_t N_RB_DL,MIMO_mode_t mode,uint32_t pmi_alloc,uint16_t rb) {
831
832

  //  printf("Getting pmi for RB %d => %d\n",rb,(pmi_alloc>>((rb>>2)<<1))&3);
knopp's avatar
   
knopp committed
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
  switch (N_RB_DL) {
  case 6:   // 1 PRB per subband
    if (mode <= PUSCH_PRECODING1)
      return((pmi_alloc>>(rb<<1))&3);
    else
      return((pmi_alloc>>rb)&1);    
    break;
  case 25:  // 4 PRBs per subband
    if (mode <= PUSCH_PRECODING1)
      return((pmi_alloc>>((rb>>2)<<1))&3);
    else
      return((pmi_alloc>>(rb>>2))&1);
    break;
  case 50: // 6 PRBs per subband
    if (mode <= PUSCH_PRECODING1)
      return((pmi_alloc>>((rb/6)<<1))&3);
    else
      return((pmi_alloc>>(rb/6))&1);
    break;
  case 100: // 8 PRBs per subband
    if (mode <= PUSCH_PRECODING1)
      return((pmi_alloc>>((rb>>3)<<1))&3);
    else
      return((pmi_alloc>>(rb>>3))&1);    
    break;
  default:
    break;
  }
861
862
}

knopp's avatar
   
knopp committed
863

864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
int dlsch_modulation(mod_sym_t **txdataF,
		     int16_t amp,
		     uint32_t subframe_offset,
		     LTE_DL_FRAME_PARMS *frame_parms,
		     uint8_t num_pdcch_symbols,
		     LTE_eNB_DLSCH_t *dlsch){

  uint8_t nsymb;
  uint8_t harq_pid = dlsch->current_harq_pid;
  uint32_t i,jj,re_allocated,symbol_offset;
  uint16_t l,rb,re_offset;
  uint32_t rb_alloc_ind;
  uint32_t *rb_alloc = dlsch->rb_alloc;
  uint8_t pilots=0;
  uint8_t skip_dc,skip_half;
  uint8_t mod_order = get_Qm(dlsch->harq_processes[harq_pid]->mcs);
  int16_t amp_rho_a, amp_rho_b;
  int16_t qam16_table_a[4],qam64_table_a[8],qam16_table_b[4],qam64_table_b[8];
  int16_t *qam_table_s;
knopp's avatar
   
knopp committed
883
#ifdef DEBUG_DLSCH_MODULATION
knopp's avatar
   
knopp committed
884
  uint8_t Nl = dlsch->harq_processes[harq_pid]->Nl;
knopp's avatar
   
knopp committed
885
#endif
886
887
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_IN);

888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
  nsymb = (frame_parms->Ncp==0) ? 14:12;
  
  amp_rho_a = (int16_t)(((int32_t)amp*dlsch->sqrt_rho_a)>>13);
  amp_rho_b = (int16_t)(((int32_t)amp*dlsch->sqrt_rho_b)>>13);

  if (mod_order == 4)
    for (i=0;i<4;i++) {
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_a)>>15);
      qam16_table_b[i] = (int16_t)(((int32_t)qam16_table[i]*amp_rho_b)>>15);
    }
  else if (mod_order == 6)
    for (i=0;i<8;i++) {
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_a)>>15);
      qam64_table_b[i] = (int16_t)(((int32_t)qam64_table[i]*amp_rho_b)>>15);
    } 
  //Modulation mapping (difference w.r.t. LTE specs)
  
  jj=0;
  re_allocated=0;
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
  for (l=num_pdcch_symbols;l<nsymb;l++) {
    
#ifdef DEBUG_DLSCH_MODULATION
    msg("Generating DLSCH (harq_pid %d,mimo %d, pmi_alloc %x, mod %d, nu %d, rb_alloc[0] %d) in %d\n",harq_pid,dlsch->harq_processes[harq_pid]->mimo_mode,pmi2hex_2Ar1(dlsch->pmi_alloc),mod_order, dlsch->layer_index, rb_alloc[0], l);
#endif    

    if (frame_parms->Ncp==0) { // normal prefix
      if ((l==4)||(l==11))
	pilots=2;   // pilots in nushift+3, nushift+9
      else if (l==7)
	pilots=1;   // pilots in nushift, nushift+6
      else
	pilots=0;
    }
    else {
      if ((l==3)||(l==9))
	pilots=2;
      else if (l==6)
	pilots=1;
      else
	pilots=0;
    }

    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++)
    //	memset(&txdataF[aa][symbol_offset],0,frame_parms->ofdm_symbol_size<<2);
    //printf("symbol_offset %d,subframe offset %d : pilots %d\n",symbol_offset,subframe_offset,pilots);
      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)||
		 (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;
	    }	    
	    //PSS
	    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;
	    }
	  }
	  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;
	    }
	  }
	}
	
	if (dlsch->layer_index>1) {
	  msg("layer_index %d: re_offset %d, symbol %d offset %d\n",dlsch->layer_index,re_offset,l,symbol_offset); 
	  return(-1);
	}
	if (mod_order == 4)
	  qam_table_s = ((pilots) ? qam16_table_b : qam16_table_a);
	else if (mod_order == 6)
	  qam_table_s = ((pilots) ? qam64_table_b : qam64_table_a);
	else
	  qam_table_s = NULL;

	if (rb_alloc_ind > 0)
        {
knopp's avatar
   
knopp committed
1076
	  //	  printf("Allocated rb %d, subframe_offset %d, symbol_offset %d, re_offset %d\n",rb,subframe_offset,symbol_offset,re_offset);
1077
1078
1079
1080
1081
1082
1083
1084
1085
	  allocate_REs_in_RB(txdataF,
			     &jj,
			     re_offset,
			     symbol_offset,
			     dlsch->e,
			     dlsch->harq_processes[harq_pid]->mimo_mode,
			     dlsch->layer_index,
			     pilots,
			     mod_order,
knopp's avatar
   
knopp committed
1086
			     get_pmi(frame_parms->N_RB_DL,dlsch->harq_processes[harq_pid]->mimo_mode,dlsch->pmi_alloc,rb),
1087
1088
1089
1090
1091
1092
			     ((pilots) ? amp_rho_b : amp_rho_a),
			     qam_table_s,
			     &re_allocated,
			     skip_dc,
			     skip_half,
			     (frame_parms->mode1_flag==1)?1:0,
knopp's avatar
   
knopp committed
1093
1094
			     dlsch->harq_processes[harq_pid]->Nlayers, 
			     dlsch->harq_processes[harq_pid]->first_layer, 
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
			     frame_parms);
      }
	re_offset+=12; // go to next RB
	

	// check if we crossed the symbol boundary and skip DC
	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
	}
      }
	
  }
  


#ifdef DEBUG_DLSCH_MODULATION
knopp's avatar
   
knopp committed
1114
  msg("generate_dlsch : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch->nb_rb,dlsch->rb_alloc,mod_order,Nl,2,0,subframe_offset));
1115
1116
#endif
  
1117
1118
  vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_MODULATION, VCD_FUNCTION_OUT);

1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  return (re_allocated);
}

int mch_modulation(mod_sym_t **txdataF,
		   int16_t amp,
		   uint32_t subframe_offset,
		   LTE_DL_FRAME_PARMS *frame_parms,
		   LTE_eNB_DLSCH_t *dlsch){
  
  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;
  if (mod_order == 4)
    for (i=0;i<4;i++) {
      qam16_table_a[i] = (int16_t)(((int32_t)qam16_table[i]*amp)>>15);
    }
  else if (mod_order == 6)
    for (i=0;i<8;i++) {
      qam64_table_a[i] = (int16_t)(((int32_t)qam64_table[i]*amp)>>15);
    } 
  
   jj=0;
  re_allocated=0;
  //  printf("num_pdcch_symbols %d, nsymb %d\n",num_pdcch_symbols,nsymb);
  for (l=2;l<nsymb_pmch;l++) {
    
#ifdef DEBUG_DLSCH_MODULATION
    msg("Generating MCH (mod %d) in %d\n",mod_order, l);
#endif    

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

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

      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;

      }

      
      if (mod_order == 4)
	qam_table_s = qam16_table_a;
      else if (mod_order == 6)
	qam_table_s = qam64_table_a;
      else
	qam_table_s = NULL;

      //      printf("Allocated rb %d, subframe_offset %d\n",rb,subframe_offset);
      allocate_REs_in_RB_MCH(txdataF,
			     &jj,
			     re_offset,
			     symbol_offset,
			     dlsch->e,
			     l,
			     mod_order,
			     amp,
			     qam_table_s,
			     &re_allocated,
			     skip_dc,
			     frame_parms);
      
      re_offset+=12; // go to next RB
	
      
      // check if we crossed the symbol boundary and skip DC
      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
      }
    }
  }
	

  


#ifdef DEBUG_DLSCH_MODULATION
knopp's avatar
   
knopp committed
1211
  msg("generate_dlsch(MCH) : jj = %d,re_allocated = %d (G %d)\n",jj,re_allocated,get_G(frame_parms,dlsch->nb_rb,dlsch->rb_alloc,mod_order,1,2,0,subframe_offset));
1212
1213
1214
1215
#endif
    
    return (re_allocated);
}