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

22
23
24
25
26
27
28
29
#include <string.h>
#include <math.h>
#include <unistd.h>
#include "SIMULATION/TOOLS/defs.h"
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/vars.h"
30

31
32
33
34
35
36
37
38
39
40
41
42
#ifdef EMOS
#include "SCHED/phy_procedures_emos.h"
#endif
#include "SCHED/defs.h"
#include "SCHED/vars.h"
#include "LAYER2/MAC/vars.h"
#include "OCG_vars.h"

#ifdef XFORMS
#include "PHY/TOOLS/lte_phy_scope.h"
#endif

43
#include "unitary_defs.h"
44
45
#define N_TRIALS 100

46
47
PHY_VARS_eNB *eNB,*eNB1,*eNB2;
PHY_VARS_UE *UE;
48
49

#define UL_RB_ALLOC 0x1ff;
50
#define CCCH_RB_ALLOC computeRIV(eNB->frame_parms.N_RB_UL,0,2)
51
#define DLSCH_RB_ALLOC ((uint16_t)0x1fbf) // igore DC component,RB13
52

53

54
55
DCI_PDU DCI_pdu;

56
DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2Lcommon, DCI_format_t format_selector[MAX_NUM_DCI], uint8_t num_dci, uint32_t rnti)
57
{
58
59
60
  uint32_t BCCH_alloc_pdu[2];
  uint32_t DLSCH_alloc_pdu[2];
  uint32_t UL_alloc_pdu[2];
61

62
  int ind;
Cedric Roux's avatar
Cedric Roux committed
63
64
65
  int dci_length_bytes=0,dci_length=0;
  int BCCH_pdu_size_bits=0, BCCH_pdu_size_bytes=0;
  int UL_pdu_size_bits=0, UL_pdu_size_bytes=0;
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  int mcs = 3;

  DCI_pdu.Num_ue_spec_dci = 0;
  DCI_pdu.Num_common_dci = 0;

  if (lte_frame_parms->frame_type == TDD) {
    switch (lte_frame_parms->N_RB_DL) {
    case 6:
      dci_length = sizeof_DCI1_1_5MHz_TDD_t;
      dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t);
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah               = 0;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc           = DLSCH_RB_ALLOC;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs               = mcs;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid          = 0;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi               = 1;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                = 0;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC               = 0;
      ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai               = 0;
84

85
86
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type           = 1;
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
87
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
88
89
90
91
92
93
94
95
96
97
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv             = 0;
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
      ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);

      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
98
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
99
100
101
102
103
104
105
106
107
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
      ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_TDD_1_6_t;
      UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_TDD_1_6_t);
      break;
108

109
110
111
112
    case 25:
      dci_length = sizeof_DCI1_5MHz_TDD_t;
      dci_length_bytes = sizeof(DCI1_5MHz_TDD_t);
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                 = 0;
113
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc          = DLSCH_RB_ALLOC;
114
115
116
117
118
119
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                 = mcs;
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid            = 0;
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                 = 1;
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                  = 0;
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                 = 0;
      ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                 = 0;
120

121
122
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type            = 1;
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type        = 0;
123
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
124
125
126
127
128
129
130
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi             = 1;
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv              = 0;
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs             = 2;
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid        = 0;
      ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC             = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
131

132
133
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
134
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
135
136
137
138
139
140
141
142
143
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
      ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_5MHz_TDD_1_6_t;
      UL_pdu_size_bytes = sizeof(DCI0_5MHz_TDD_1_6_t);
      break;
144

145
146
147
148
    case 50:
      dci_length = sizeof_DCI1_10MHz_TDD_t;
      dci_length_bytes = sizeof(DCI1_10MHz_TDD_t);
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah              = 0;
149
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc       = DLSCH_RB_ALLOC;
150
151
152
153
154
155
156
157
158
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs              = mcs;
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid         = 0;
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi              = 1;
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv               = 0;
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC              = 0;
      ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai              = 0;

      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type          = 1;
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type      = 0;
159
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc    = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
160
161
162
163
164
165
166
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi           = 1;
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv            = 0;
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs           = 2;
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid      = 0;
      ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC           = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
167

168
169
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
170
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
171
172
173
174
175
176
177
178
179
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
      ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_10MHz_TDD_1_6_t;
      UL_pdu_size_bytes = sizeof(DCI0_10MHz_TDD_1_6_t);
      break;
180

181
182
183
184
    case 100:
      dci_length = sizeof_DCI1_20MHz_TDD_t;
      dci_length_bytes = sizeof(DCI1_20MHz_TDD_t);
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah                = 0;
185
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc         = DLSCH_RB_ALLOC;
186
187
188
189
190
191
192
193
194
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs                = mcs;
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid           = 0;
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi                = 1;
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv                 = 0;
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC                = 0;
      ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai                = 0;

      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type            = 1;
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type        = 0;
195
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc      = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
196
197
198
199
200
201
202
203
204
205
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi             = 1;
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv              = 0;
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs             = 2;
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid        = 0;
      ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC             = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);

      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping           = 0;
206
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
207
208
209
210
211
212
213
214
215
216
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai               = 1;
      ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_20MHz_TDD_1_6_t;
      UL_pdu_size_bytes = sizeof(DCI0_20MHz_TDD_1_6_t);
      break;
    }
217
  } else { //FDD
218
219
220
221
222
    switch (lte_frame_parms->N_RB_DL) {
    case 6:
      dci_length = sizeof_DCI1_1_5MHz_FDD_t;
      dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t);
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
223
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
224
225
226
227
228
229
230
231
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
      ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;

      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
232
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 0, 4);
233
234
235
236
237
238
239
240
241
242
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
      ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);

      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
243
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
244
245
246
247
248
249
250
251
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_1_5MHz_FDD_t;
      UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_FDD_t);
      break;
252

253
254
255
256
    case 25:
      dci_length = sizeof_DCI1_5MHz_FDD_t;
      dci_length_bytes = sizeof(DCI1_5MHz_FDD_t);
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
257
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
258
259
260
261
262
263
264
265
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
      ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;

      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
266
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 18, 4);
267
268
269
270
271
272
273
274
275
276
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
      ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_5MHz_FDD_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_FDD_t);

      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
277
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
278
279
280
281
282
283
284
285
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_5MHz_FDD_t;
      UL_pdu_size_bytes = sizeof(DCI0_5MHz_FDD_t);
      break;
286

287
288
289
290
    case 50:
      dci_length = sizeof_DCI1_10MHz_FDD_t;
      dci_length_bytes = sizeof(DCI1_10MHz_FDD_t);
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
291
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
292
293
294
295
296
297
298
299
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
      ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;

      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
300
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 30, 4);
301
302
303
304
305
306
307
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
      ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_10MHz_FDD_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_FDD_t);
308

309
310
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
311
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
312
313
314
315
316
317
318
319
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_10MHz_FDD_t;
      UL_pdu_size_bytes = sizeof(DCI0_10MHz_FDD_t);
      break;
320

321
322
323
324
    case 100:
      dci_length = sizeof_DCI1_20MHz_FDD_t;
      dci_length_bytes = sizeof(DCI1_20MHz_FDD_t);
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah           = 0;
325
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc    = DLSCH_RB_ALLOC;
326
327
328
329
330
331
332
333
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs           = mcs;
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid      = 0;
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi           = 1;
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv            = 0;
      ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC           = 0;

      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->type           = 1;
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type       = 0;
334
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc     = computeRIV(lte_frame_parms->N_RB_DL, 70, 4);
335
336
337
338
339
340
341
342
343
344
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi            = 1;
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv             = 0;
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs            = 2;
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid       = 0;
      ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC            = 1;
      BCCH_pdu_size_bits  = sizeof_DCI1A_20MHz_FDD_t;
      BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_FDD_t);

      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->type              = 0;
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->hopping           = 0;
345
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc        = DLSCH_RB_ALLOC;
346
347
348
349
350
351
352
353
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->mcs               = mcs;
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->ndi               = 1;
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->TPC               = 2;
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cshift            = 3;
      ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req           = 1;
      UL_pdu_size_bits  = sizeof_DCI0_20MHz_FDD_t;
      UL_pdu_size_bytes = sizeof(DCI0_20MHz_FDD_t);
      break;
354
    }
355
  }
356

357
  for (ind = 0; ind<num_dci; ind++) {
358
359
360
361
362
363
364
365
366
367
368
369
    if (format_selector[ind]==format1A) {
      // add common dci
      DCI_pdu.dci_alloc[ind].dci_length = BCCH_pdu_size_bits;
      DCI_pdu.dci_alloc[ind].L          = log2Lcommon;
      DCI_pdu.dci_alloc[ind].rnti       = SI_RNTI;
      DCI_pdu.dci_alloc[ind].format     = format1A;
      DCI_pdu.dci_alloc[ind].ra_flag    = 0;
      memcpy((void*)&DCI_pdu.dci_alloc[0].dci_pdu[0], &BCCH_alloc_pdu[0], BCCH_pdu_size_bytes);
      DCI_pdu.Num_common_dci++;
      printf("Added common dci (%d) for rnti %x\n",ind,SI_RNTI);
    }
    
370

371
372
373
374
375
376
377
378
379
380
381
    if (format_selector[ind]==format1) {
      DCI_pdu.dci_alloc[ind].dci_length = dci_length;
      DCI_pdu.dci_alloc[ind].L          = log2L;
      DCI_pdu.dci_alloc[ind].rnti       = rnti;
      DCI_pdu.dci_alloc[ind].format     = format1;
      DCI_pdu.dci_alloc[ind].ra_flag    = 0;
      memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &DLSCH_alloc_pdu[0], dci_length_bytes);
      DCI_pdu.Num_ue_spec_dci++;
    }
    
    if (format_selector[ind]==format0) {
382
383
384
385
386
387
      DCI_pdu.dci_alloc[ind].dci_length = UL_pdu_size_bits;
      DCI_pdu.dci_alloc[ind].L          = log2L;
      DCI_pdu.dci_alloc[ind].rnti       = rnti;
      DCI_pdu.dci_alloc[ind].format     = format0;
      DCI_pdu.dci_alloc[ind].ra_flag    = 0;
      memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &UL_alloc_pdu[0], UL_pdu_size_bytes);
388
389
      DCI_pdu.Num_ue_spec_dci++;
    }
390
  }
391
  
392
393
394
  return(&DCI_pdu);
}

395
396
extern int QPSK[4],QPSK2[4];

397
398
int main(int argc, char **argv)
{
399
400
401
402
403

  char c;

  int i,l,aa;
  double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1;
404

405
  int **txdata;
406
  double s_re[2][30720*2],s_im[2][30720*2],r_re[2][30720*2],r_im[2][30720*2];
407
408
  double iqim=0.0;
  //  int subframe_offset;
gauthier's avatar
gauthier committed
409
  uint8_t subframe=0;
410
411
412
413
414
415
416
#ifdef XFORMS
  FD_lte_phy_scope_ue *form_ue;
  char title[255];
#endif
  int trial, n_errors_common=0,n_errors_ul=0,n_errors_dl=0,n_errors_cfi=0,n_errors_hi=0;
  unsigned char eNb_id = 0;

gauthier's avatar
gauthier committed
417
  uint8_t awgn_flag=0;
418
419
  int n_frames=1;
  channel_desc_t *eNB2UE;
gauthier's avatar
gauthier committed
420
421
422
423
424
  uint32_t nsymb,tx_lev,tx_lev_dB=0,num_pdcch_symbols=3;
  uint8_t extended_prefix_flag=0,transmission_mode=1,n_tx=1,n_rx=1;
  uint16_t Nid_cell=0;
  //  int8_t interf1=-128,interf2=-128;
  uint8_t dci_cnt=0;
425
  LTE_DL_FRAME_PARMS *frame_parms;
426
427
428
  uint8_t log2L=2, log2Lcommon=2;
  DCI_format_t format_selector[MAX_NUM_DCI];
  uint8_t num_dci=0;
429
  uint8_t numCCE,common_active=0,ul_active=0,dl_active=0;
430

gauthier's avatar
gauthier committed
431
432
433
  uint32_t n_trials_common=0,n_trials_ul=0,n_trials_dl=0,false_detection_cnt=0;
  uint8_t common_rx,ul_rx,dl_rx;
  uint8_t tdd_config=3;
434
435
436

  FILE *input_fd=NULL;
  char input_val_str[50],input_val_str2[50];
gauthier's avatar
gauthier committed
437
438
  uint16_t n_rnti=0x1234;
  uint8_t osf=1,N_RB_DL=25;
439
440
441
442
443

  SCM_t channel_model=Rayleigh1_anticorr;

  DCI_ALLOC_t dci_alloc_rx[8];

444
  int ret;
445

gauthier's avatar
gauthier committed
446
447
  uint8_t harq_pid;
  uint8_t phich_ACK;
448

gauthier's avatar
gauthier committed
449
  uint8_t num_phich_interf = 0;
450
  lte_frame_type_t frame_type=TDD;
451
452
  //  int re_offset;
  //  uint32_t *txptr;
453
454
  int aarx;
  int k;
knopp's avatar
   
knopp committed
455
  uint32_t perfect_ce = 0;
456
  int CCE_table[800];
457

458
  number_of_cards = 1;
459
460
461
462

  logInit();


knopp's avatar
   
knopp committed
463
  while ((c = getopt (argc, argv, "hapFg:R:c:n:s:x:y:z:L:M:N:I:f:i:S:P:Y")) != -1) {
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
509
    switch (c) {
    case 'a':
      printf("Running AWGN simulation\n");
      awgn_flag = 1;
      break;

    case 'R':
      N_RB_DL = atoi(optarg);
      break;

    case 'F':
      frame_type = FDD;
      break;

    case 'c':
      tdd_config=atoi(optarg);

      if (tdd_config>6) {
        printf("Illegal tdd_config %d (should be 0-6)\n",tdd_config);
        exit(-1);
      }

      break;

    case 'g':
      switch((char)*optarg) {
      case 'A':
        channel_model=SCM_A;
        break;

      case 'B':
        channel_model=SCM_B;
        break;

      case 'C':
        channel_model=SCM_C;
        break;

      case 'D':
        channel_model=SCM_D;
        break;

      case 'E':
        channel_model=EPA;
        break;

510
      case 'F':
511
512
513
514
515
        channel_model=EVA;
        break;

      case 'G':
        channel_model=ETU;
knopp's avatar
   
knopp committed
516
        break;
517
518

      default:
519
        printf("Unsupported channel model!\n");
520
        exit(-1);
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

      break;

      /*
          case 'i':
      interf1=atoi(optarg);
      break;
          case 'j':
      interf2=atoi(optarg);
      break;
      */
    case 'n':
      n_frames = atoi(optarg);
      break;

    case 's':
      snr0 = atoi(optarg);
      break;

    case 'p':
      extended_prefix_flag=1;
      break;

    case 'x':
      transmission_mode=atoi(optarg);

      if ((transmission_mode!=1) &&
          (transmission_mode!=2) &&
          (transmission_mode!=6)) {
551
        printf("Unsupported transmission mode %d\n",transmission_mode);
552
553
554
555
556
557
558
559
560
        exit(-1);
      }

      break;

    case 'y':
      n_tx=atoi(optarg);

      if ((n_tx==0) || (n_tx>2)) {
561
        printf("Unsupported number of tx antennas %d\n",n_tx);
562
563
564
565
566
567
568
569
570
        exit(-1);
      }

      break;

    case 'z':
      n_rx=atoi(optarg);

      if ((n_rx==0) || (n_rx>2)) {
571
        printf("Unsupported number of rx antennas %d\n",n_rx);
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
        exit(-1);
      }

      break;

    case 'S':
      subframe=atoi(optarg);
      break;

    case 'L':
      log2L=atoi(optarg);

      if ((log2L!=0)&&
          (log2L!=1)&&
          (log2L!=2)&&
          (log2L!=3)) {
588
        printf("Unsupported DCI aggregation level %d (should be 0,1,2,3)\n",log2L);
589
590
591
592
593
594
595
596
597
598
        exit(-1);
      }

      break;

    case 'M':
      log2Lcommon=atoi(optarg);

      if ((log2Lcommon!=2)&&
          (log2Lcommon!=3)) {
599
        printf("Unsupported Common DCI aggregation level %d (should be 2 or 3)\n",log2Lcommon);
600
601
602
603
604
605
        exit(-1);
      }

      break;

    case 'N':
606
607
608
609
610
611
612
613
614
      format_selector[num_dci] = (DCI_format_t) atoi(optarg);
      if ((format_selector[num_dci]<format0) || (format_selector[num_dci] > format1A)) {
	printf("only formats 0, 1, and 1A supported for the moment\n");
	exit(-1);
      }
      if (format_selector[num_dci]==format0) ul_active=1;
      if (format_selector[num_dci]==format1A) common_active=1;
      if (format_selector[num_dci]==format1) dl_active=1;
      num_dci++;
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
      break;

    case 'O':
      osf = atoi(optarg);
      break;

    case 'I':
      Nid_cell = atoi(optarg);
      break;

    case 'f':
      input_fd = fopen(optarg,"r");

      if (input_fd==NULL) {
        printf("Problem with filename %s\n",optarg);
        exit(-1);
      }

      break;

    case 'i':
      n_rnti=atoi(optarg);
      break;

    case 'P':
      num_phich_interf=atoi(optarg);
      break;

    case 'Y':
      perfect_ce = 1;
      break;

    case 'h':
      printf("%s -h(elp) -a(wgn on) -c tdd_config -n n_frames -r RiceanFactor -s snr0 -t Delayspread -x transmission mode (1,2,6) -y TXant -z RXant -L AggregLevelUEspec -M AggregLevelCommonDCI -N DCIFormat\n\n",
             argv[0]);
      printf("-h This message\n");
      printf("-a Use AWGN channel and not multipath\n");
      printf("-c TDD config\n");
      printf("-R N_RB_DL\n");
      printf("-F use FDD frame\n");
      printf("-p Use extended prefix mode\n");
      printf("-n Number of frames to simulate\n");
      printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n");
      printf("-s Starting SNR, runs from SNR to SNR + 5 dB.  If n_frames is 1 then just SNR is simulated\n");
      printf("-t Delay spread for multipath channel\n");
      printf("-x Transmission mode (1,2,6 for the moment)\n");
      printf("-y Number of TX antennas used in eNB\n");
      printf("-z Number of RX antennas used in UE\n");
      printf("-P Number of interfering PHICH\n");
664
      printf("-L log2 of Aggregation level for UE Specific DCI (0,1,2,3)\n");
665
      printf("-M log2 Aggregation level for Common DCI (4,8)\n");
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
      printf("-N Format for UE Spec DCI (0 - format0,\n");
      printf("                           1 - format1,\n");
      printf("                           2 - format1A,\n");
      printf("                           3 - format1B_2A,\n");
      printf("                           4 - format1B_4A,\n");
      printf("                           5 - format1C,\n");
      printf("                           6 - format1D_2A,\n");
      printf("                           7 - format1D_4A,\n");
      printf("                           8 - format2A_2A_L10PRB,\n");
      printf("                           9 - format2A_2A_M10PRB,\n");
      printf("                          10 - format2A_4A_L10PRB,\n");
      printf("                          11 - format2A_4A_M10PRB,\n");
      printf("                          12 - format2_2A_L10PRB,\n");
      printf("                          13 - format2_2A_M10PRB,\n");
      printf("                          14 - format2_4A_L10PRB,\n");
      printf("                          15 - format2_4A_M10PRB\n");
      printf("                          16 - format2_2D_M10PRB\n");
      printf("                          17 - format2_2D_L10PRB\n");
      printf("   can be called multiple times to add more than one DCI\n");
685
686
687
688
689
690
      printf("-O Oversampling factor\n");
      printf("-I Cell Id\n");
      printf("-F Input sample stream\n");
      exit(1);
      break;
    }
691
692
693
694
695
696
  }

  if ((transmission_mode>1) && (n_tx==1))
    n_tx=2;

  lte_param_init(n_tx,
697
                 n_tx,
698
699
700
                 n_rx,
                 transmission_mode,
                 extended_prefix_flag,
701
		 frame_type,
702
703
                 Nid_cell,
                 tdd_config,
704
                 N_RB_DL,
705
		 0,
706
                 osf,
knopp's avatar
   
knopp committed
707
                 perfect_ce);
708

709
710
711
712
#ifdef XFORMS
  fl_initialize (&argc, argv, NULL, 0, 0);
  form_ue = create_lte_phy_scope_ue();
  sprintf (title, "LTE PHY SCOPE UE");
713
  fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
714
715
716
717
#endif


  mac_xface->computeRIV = computeRIV;
718
  mac_xface->frame_parms = &eNB->frame_parms;
719
720
721
722
723
  //  init_transport_channels(transmission_mode);

  if (n_frames==1)
    snr1 = snr0+.1;
  else
724
    snr1 = snr0+8.0;
725
726
727

  printf("SNR0 %f, SNR1 %f\n",snr0,snr1);

728
  frame_parms = &eNB->frame_parms;
729
  printf("Getting %d dcis\n",num_dci);
730

731
  get_dci(frame_parms, log2L, log2Lcommon, format_selector, num_dci, n_rnti);
732

733
  txdata = eNB->common_vars.txdata[eNb_id];
734

735
  nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12;
736
737

  printf("Subframe %d, FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",
738
         subframe,NUMBER_OF_OFDM_CARRIERS,
739
         eNB->frame_parms.Ncp,eNB->frame_parms.samples_per_tti,nsymb);
740

741
  eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx,
742
                                UE->frame_parms.nb_antennas_rx,
743
                                channel_model,
744
745
				N_RB2sampling_rate(eNB->frame_parms.N_RB_DL),
				N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL),
746
747
748
749
                                0,
                                0,
                                0);

knopp's avatar
knopp committed
750
  eNB_rxtx_proc_t *proc_rxtx = &eNB->proc.proc_rxtx[subframe&1];
751

752
753
  eNB->ulsch[0] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,N_RB_DL,0);
  UE->ulsch[0]   = new_ue_ulsch(N_RB_DL,0);
754
755


knopp's avatar
knopp committed
756
757
  proc_rxtx->frame_tx    = 0;
  proc_rxtx->subframe_tx = subframe;
knopp's avatar
   
knopp committed
758

759
  if (input_fd==NULL) {
760
    printf("No input file, so starting TX\n");
761
  } else {
762
    i=0;
763

764
    while (!feof(input_fd)) {
765
      ret=fscanf(input_fd,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2);
766

Cedric Roux's avatar
Cedric Roux committed
767
768
769
770
771
      if (ret != 2) {
        printf("%s:%d:%s: fscanf error, exiting\n", __FILE__, __LINE__, __FUNCTION__);
        exit(1);
      }

772
      if ((i%4)==0) {
773
774
775
776
777
        ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL));
        ((short*)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL));

        if ((i/4)<100)
          printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,);
778
      }
779

780
      i++;
781

782
      if (i>(4*FRAME_LENGTH_SAMPLES))
783
        break;
784
    }
785

786
787
788
789
    printf("Read in %d samples\n",i/4);
    write_output("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
    //    write_output("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1);
    tx_lev = signal_energy(&txdata[0][0],
790
                           OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES);
791
792
793
794
    tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
  }


795
  UE->UE_mode[0] = PUSCH;
796

797
  //  nCCE_max = get_nCCE(3,&eNB->frame_parms,get_mi(&eNB->frame_parms,0));
798
  //printf("nCCE_max %d\n",nCCE_max);
799

800
  //printf("num_phich interferers %d\n",num_phich_interf);
801
  for (SNR=snr0; SNR<snr1; SNR+=0.2) {
802
803


804
805
806
807
808
809
810
811
812
813
    n_errors_common = 0;
    n_errors_ul     = 0;
    n_errors_dl     = 0;
    n_errors_cfi    = 0;
    n_errors_hi     = 0;
    n_trials_common=0;
    n_trials_ul=0;
    n_trials_dl=0;

    for (trial=0; trial<n_frames; trial++) {
814
      
815
      //    printf("DCI (SF %d): txdataF %p (0 %p)\n",subframe,&eNB->common_vars.txdataF[eNb_id][aa][512*14*subframe],&eNB->common_vars.txdataF[eNb_id][aa][0]);
816
      for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) {
817
        memset(&eNB->common_vars.txdataF[eNb_id][aa][0],0,FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX*sizeof(int32_t));
818

819
820
821
      }


822
823
      generate_pilots_slot(eNB,
                           eNB->common_vars.txdataF[eNb_id],
824
825
826
                           AMP,    //1024,
                           (subframe*2),
                           0);
827
828
      generate_pilots_slot(eNB,
                           eNB->common_vars.txdataF[eNb_id],
829
830
831
832
833
834
835
836
837
                           AMP,    //1024,
                           (subframe*2)+1,
                           0);


      if (input_fd == NULL) {
        numCCE=0;
        n_trials_common++;
        common_active = 1;
838
	if (eNB->frame_parms.N_RB_DL >= 50) { 
839
840
841
	  if (ul_active==1) { 
	    n_trials_ul++;
	  }
842
	}
843
        if (eNB->frame_parms.N_RB_DL >= 25) { 
844
845
846
	  if (dl_active==1) { 
	    n_trials_dl++;
	  }
847
	}
848
849
        num_pdcch_symbols = get_num_pdcch_symbols(DCI_pdu.Num_common_dci+DCI_pdu.Num_ue_spec_dci,
                            DCI_pdu.dci_alloc, frame_parms, subframe);
850
	numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe));
851
852
853
854

        if (n_frames==1) {
          printf("num_dci %d, num_pddch_symbols %d, nCCE %d\n",
                 DCI_pdu.Num_common_dci+DCI_pdu.Num_ue_spec_dci,
855
                 num_pdcch_symbols,numCCE);
856
        }
857
858

        // apply RNTI-based nCCE allocation
859
860
	memset(CCE_table,0,800*sizeof(int));

861
862
863
        for (i = 0; i < DCI_pdu.Num_common_dci + DCI_pdu.Num_ue_spec_dci; i++) {
          // SI RNTI
          if (DCI_pdu.dci_alloc[i].rnti == SI_RNTI) {
864
865
866
867
868
869
            DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
							       1<<DCI_pdu.dci_alloc[i].L,
							       numCCE,
							       1,
							       SI_RNTI,
							       subframe);
870
871
872
          }
          // RA RNTI
          else if (DCI_pdu.dci_alloc[i].ra_flag == 1) {
873
874
875
876
877
878
            DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
							       1<<DCI_pdu.dci_alloc[i].L,
							       numCCE,
							       1,
							       DCI_pdu.dci_alloc[i].rnti,
							       subframe);
879
880
881
          }
          // C RNTI
          else {
882
883
884
885
886
887
            DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table,
							       1<<DCI_pdu.dci_alloc[i].L,
							       numCCE,
							       0,
							       DCI_pdu.dci_alloc[i].rnti,
							       subframe);
888
889
890
          }

          if (n_frames==1)
891
892
            printf("dci %d: rnti 0x%x, format %d, L %d (aggreg %d), nCCE %d/%d dci_length %d\n",i,DCI_pdu.dci_alloc[i].rnti, DCI_pdu.dci_alloc[i].format,
                   DCI_pdu.dci_alloc[i].L, 1<<DCI_pdu.dci_alloc[i].L, DCI_pdu.dci_alloc[i].firstCCE, numCCE, DCI_pdu.dci_alloc[i].dci_length);
893

894
          if (DCI_pdu.dci_alloc[i].firstCCE==-1)
895
            exit(-1);
896
897
        }

898
899
900
901
902
        num_pdcch_symbols = generate_dci_top(DCI_pdu.Num_ue_spec_dci,
                                             DCI_pdu.Num_common_dci,
                                             DCI_pdu.dci_alloc,
                                             0,
                                             AMP,
903
904
                                             &eNB->frame_parms,
                                             eNB->common_vars.txdataF[eNb_id],
905
906
907
908
909
                                             subframe);

        if (n_frames==1)
          printf("num_pdcch_symbols at TX %d\n",num_pdcch_symbols);

910
        if (is_phich_subframe(&eNB->frame_parms,subframe)) {
911
912
913
          if (n_frames==1)
            printf("generating PHICH\n");

knopp's avatar
knopp committed
914
          harq_pid = phich_subframe_to_harq_pid(&eNB->frame_parms, proc_rxtx->frame_tx, subframe);
915
916

          phich_ACK = taus()&1;
917
918
919
920
921
          eNB->ulsch[0]->harq_processes[harq_pid]->phich_active = 1;
          eNB->ulsch[0]->harq_processes[harq_pid]->first_rb     = 0;
          eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS       = 0;
          eNB->ulsch[0]->harq_processes[harq_pid]->phich_ACK    = phich_ACK;
          eNB->ulsch[0]->harq_processes[harq_pid]->dci_alloc    = 1;
922

923
924
          UE->ulsch[0]->harq_processes[harq_pid]->first_rb       = 0;
          UE->ulsch[0]->harq_processes[harq_pid]->n_DMRS         = 0;
925

926
          generate_phich_top(eNB,proc_rxtx,AMP,0);
927
          
928
929
          // generate 3 interfering PHICH
          if (num_phich_interf>0) {
930
            eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 4;
931
            generate_phich_top(eNB,proc_rxtx,1024,0);
932
933
934
          }

          if (num_phich_interf>1) {
935
936
            eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 8;
            eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1;
937
            generate_phich_top(eNB,proc_rxtx,1024,0);
938
939
          }
          if (num_phich_interf>2) {
940
941
            eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 12;
            eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1;
942
            generate_phich_top(eNB,proc_rxtx,1024,0);
943
944
945

          }

946
          eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 0;
947
          
948
        }
949

950
        //  write_output("pilotsF.m","rsF",txdataF[0],lte_eNB->frame_parms.ofdm_symbol_size,1,1);
951
952

        if (n_frames==1) {
953
          write_output("txsigF0.m","txsF0", eNB->common_vars.txdataF[eNb_id][0],4*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX,1,1);
954

955
          if (eNB->frame_parms.nb_antenna_ports_eNB > 1)
956
            write_output("txsigF1.m","txsF1", eNB->common_vars.txdataF[eNb_id][1],4*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX,1,1);
957
        }
958
959
960
961

        tx_lev = 0;


962
        for (aa=0; aa<eNB->frame_parms.nb_antenna_ports_eNB; aa++) {
963
964
965
966
          if (eNB->frame_parms.Ncp == 1)
            PHY_ofdm_mod(&eNB->common_vars.txdataF[eNb_id][aa][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],        // input,
                         &txdata[aa][subframe*eNB->frame_parms.samples_per_tti],         // output
                         eNB->frame_parms.ofdm_symbol_size,
967
                         2*nsymb,                 // number of symbols
968
                         eNB->frame_parms.nb_prefix_samples,               // number of prefix samples
969
970
                         CYCLIC_PREFIX);
          else {
971
972
            normal_prefix_mod(&eNB->common_vars.txdataF[eNb_id][aa][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],
                              &txdata[aa][subframe*eNB->frame_parms.samples_per_tti],
973
974
975
976
                              2*nsymb,
                              frame_parms);
          }

977
978
          tx_lev += signal_energy(&txdata[aa][subframe*eNB->frame_parms.samples_per_tti],
                                  eNB->frame_parms.ofdm_symbol_size);
979
980
981
        }

        tx_lev_dB = (unsigned int) dB_fixed(tx_lev);
982
      }
983
984

      for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
985
        for (aa=0; aa<eNB->frame_parms.nb_antenna_ports_eNB; aa++) {
986
          if (awgn_flag == 0) {
987
988
            s_re[aa][i] = ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
            s_im[aa][i] = ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)+1]);
989
          } else {
990
            for (aarx=0; aarx<UE->frame_parms.nb_antennas_rx; aarx++) {
991
              if (aa==0) {
992
993
                r_re[aarx][i] = ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
                r_im[aarx][i] = ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)+1]);
994
              } else {
995
996
                r_re[aarx][i] += ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]);
                r_im[aarx][i] += ((double)(((short *)txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)+1]);
knopp's avatar
   
knopp committed
997
              }
998
999
1000
1001
1002
1003
            }
          }
        }
      }


1004

1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
      if (awgn_flag == 0) {
        multipath_channel(eNB2UE,s_re,s_im,r_re,r_im,
                          2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0);
      }

      //write_output("channel0.m","chan0",ch[0],channel_length,1,8);

      // scale by path_loss = NOW - P_noise
      //sigma2       = pow(10,sigma2_dB/10);
      //N0W          = -95.87;
1015
      sigma2_dB = (double)tx_lev_dB +10*log10((double)eNB->frame_parms.ofdm_symbol_size/(double)(12*eNB->frame_parms.N_RB_DL)) - SNR;
1016
1017
1018
1019
1020
1021
1022
1023
1024

      if (n_frames==1)
        printf("sigma2_dB %f (SNR %f dB) tx_lev_dB %d\n",sigma2_dB,SNR,tx_lev_dB);

      //AWGN
      sigma2 = pow(10,sigma2_dB/10);

      //  printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB);
      for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
1025
        for (aa=0; aa<UE->frame_parms.nb_antennas_rx; aa++) {
1026

1027
1028
          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = (short) (.667*(r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
          ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] = (short) (.667*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(
1029
1030
                0.0,1.0)));
          /*
1031
1032
1033
1034
          ((short*)UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] =
            ((short*)txdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i];
          ((short*)UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] =
            ((short*)txdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1];
1035
          */
1036
        }
1037
1038
1039
      }

      // UE receiver
1040
      for (l=0; l<eNB->frame_parms.symbols_per_tti; l++) {
1041

1042
        //  subframe_offset = (l/eNB->frame_parms.symbols_per_tti)*eNB->frame_parms.samples_per_tti;
1043
1044
        //      printf("subframe_offset = %d\n",subframe_offset);

1045
1046
1047
        slot_fep(UE,
                 l%(eNB->frame_parms.symbols_per_tti/2),
                 (2*subframe)+(l/(eNB->frame_parms.symbols_per_tti/2)),
1048
                 0,
1049
1050
                 0,
		 0);
1051

1052
        if (UE->perfect_ce == 1) {
1053
1054
          if (awgn_flag==0) {
            // fill in perfect channel estimates
1055
            freq_channel(eNB2UE,UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1);
1056
1057
1058
1059
1060
1061
1062

            //write_output("channel.m","ch",desc1->ch[0],desc1->channel_length,1,8);
            //write_output("channelF.m","chF",desc1->chF[0],nb_samples,1,8);
            for(k=0; k<NUMBER_OF_eNB_MAX; k++) {
              for(aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
                for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
                  for (i=0; i<frame_parms->N_RB_DL*12; i++) {
1063
                    ((int16_t *) UE->common_vars.dl_ch_estimates[k][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
1064
                          eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP);
1065
                    ((int16_t *) UE->common_vars.dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(
1066
1067
1068
1069
1070
1071
                          eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP);
                  }
                }
              }
            }
          } else {
Xiwen JIANG's avatar
Xiwen JIANG committed
1072
            for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
1073
1074
              for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
                for (i=0; i<frame_parms->N_RB_DL*12; i++) {
1075
1076
                  ((int16_t *) UE->common_vars.dl_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(short)(AMP);
                  ((int16_t *) UE->common_vars.dl_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=0/2;
1077
1078
1079
1080
                }
              }
            }
          }
1081
        }
1082

1083
        if (l==((eNB->frame_parms.Ncp==0)?4:3)) {
1084

1085
          //      write_output("H00.m","h00",&(UE->common_vars.dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(eNB->frame_parms.ofdm_symbol_size),1,1);
1086
1087

          // do PDCCH procedures here
1088
          UE->pdcch_vars[0]->crnti = n_rnti;
1089
1090

          //    printf("Doing RX : num_pdcch_symbols at TX %d\n",num_pdcch_symbols);
1091
1092
1093
          rx_pdcch(&UE->common_vars,
                   UE->pdcch_vars,
                   &UE->frame_parms,
1094
                   0 /*frame*/,
1095
1096
                   subframe,
                   0,
1097
1098
1099
1100
1101
1102
1103
1104
                   (UE->frame_parms.mode1_flag == 1) ? SISO : ALAMOUTI,
                   UE->high_speed_flag,
                   UE->is_secondary_ue);

          if (is_phich_subframe(&UE->frame_parms,subframe)) {
            UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->status = ACTIVE;
            //UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->Ndi = 1;
            rx_phich(UE,
1105
		     &UE->proc.proc_rxtx[subframe&1],
1106
1107
                     subframe,
                     0);
1108
          }
1109

1110
          //    if (UE->pdcch_vars[0]->num_pdcch_symbols != num_pdcch_symbols)
1111
          //      break;
1112
          dci_cnt = dci_decoding_procedure(UE,
1113
1114
1115
1116
1117
1118
1119
1120
                                           dci_alloc_rx,1,
                                           0,subframe);

          common_rx=0;
          ul_rx=0;
          dl_rx=0;