slot_fep_nr.c 14.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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.1  (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
 */

#include "PHY/defs_nr_UE.h"
23
#include "PHY/defs_gNB.h"
24
#include "modulation_UE.h"
25
#include "nr_modulation.h"
26 27 28
#include "PHY/LTE_ESTIMATION/lte_estimation.h"
#include "PHY/NR_UE_ESTIMATION/nr_estimation.h"

29
//#define DEBUG_FEP
30 31 32

#define SOFFSET 0

33
/*#ifdef LOG_I
34 35
#undef LOG_I
#define LOG_I(A,B...) printf(A)
36
#endif*/
37

38
int nr_slot_fep(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
39 40 41 42
                unsigned char symbol,
                unsigned char Ns,
                int sample_offset,
                int no_prefix)
43 44 45 46
{
  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  NR_UE_COMMON *common_vars   = &ue->common_vars;
  unsigned char aa;
Francesco Mani's avatar
Francesco Mani committed
47 48
  unsigned int nb_prefix_samples;
  unsigned int nb_prefix_samples0;
49
  unsigned int abs_symbol;
Francesco Mani's avatar
Francesco Mani committed
50 51 52 53 54 55 56 57
  if (ue->is_synchronized) {
    nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
    nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples0);
  }
  else {
    nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
    nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
  }
Hongzhi Wang's avatar
Hongzhi Wang committed
58
  //unsigned int subframe_offset;//,subframe_offset_F;
59 60 61 62
  unsigned int slot_offset;
  //int i;
  unsigned int frame_length_samples = frame_parms->samples_per_subframe * 10;
  unsigned int rx_offset;
63

64

frtabu's avatar
frtabu committed
65
  dft_size_idx_t dftsize;
Raymond Knopp's avatar
Raymond Knopp committed
66
  int tmp_dft_in[8192] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
67 68 69

  switch (frame_parms->ofdm_symbol_size) {
  case 128:
frtabu's avatar
frtabu committed
70
    dftsize = DFT_128;
71 72 73
    break;

  case 256:
frtabu's avatar
frtabu committed
74
    dftsize = DFT_256;
75 76 77
    break;

  case 512:
frtabu's avatar
frtabu committed
78
    dftsize = DFT_512;
79 80 81
    break;

  case 1024:
frtabu's avatar
frtabu committed
82
    dftsize = DFT_1024;
83 84 85
    break;

  case 1536:
frtabu's avatar
frtabu committed
86
    dftsize = DFT_1536;
87 88 89
    break;

  case 2048:
frtabu's avatar
frtabu committed
90
    dftsize = DFT_2048;
91 92
    break;

93
  case 3072:
frtabu's avatar
frtabu committed
94
    dftsize = DFT_3072;
95 96
    break;

Raymond Knopp's avatar
Raymond Knopp committed
97
  case 4096:
frtabu's avatar
frtabu committed
98
    dftsize = DFT_4096;
Raymond Knopp's avatar
Raymond Knopp committed
99 100 101
    break;

  case 8192:
frtabu's avatar
frtabu committed
102
    dftsize = DFT_8192;
Raymond Knopp's avatar
Raymond Knopp committed
103 104
    break;

105
  default:
106 107
    printf("unsupported ofdm symbol size \n");
    assert(0);
108 109 110
  }

  if (no_prefix) {
111
    slot_offset = frame_parms->ofdm_symbol_size * (frame_parms->symbols_per_slot) * (Ns);
112
  } else {
Sakthivel Velumani's avatar
Sakthivel Velumani committed
113
    slot_offset = frame_parms->get_samples_slot_timestamp(Ns,frame_parms,0);
114 115 116 117 118 119 120
  }

  /*if (l<0 || l>=7-frame_parms->Ncp) {
    printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp);
    return(-1);
    }*/

Sakthivel Velumani's avatar
Sakthivel Velumani committed
121
  if (Ns<0 || Ns>(frame_parms->slots_per_frame-1)) {
122
    printf("slot_fep: Ns must be between 0 and %d\n",frame_parms->slots_per_frame-1);
123 124 125 126
    return(-1);
  }

  for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
127
    memset(&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int));
128

129
    rx_offset = sample_offset + slot_offset - SOFFSET;
130 131 132
    // Align with 256 bit
    //    rx_offset = rx_offset&0xfffffff8;

133 134
#ifdef DEBUG_FEP
      //  if (ue->frame <100)
yilmazt's avatar
yilmazt committed
135 136
    /*LOG_I(PHY,*/printf("slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %u, nb_prefix_samples0 %u, slot_offset %u, sample_offset %d,rx_offset %u, frame_length_samples %u\n",
    		ue->proc.proc_rxtx[(Ns)&1].frame_rx, Ns, symbol, nb_prefix_samples, nb_prefix_samples0, slot_offset, sample_offset, rx_offset, frame_length_samples);
137 138
#endif

139 140 141
    abs_symbol = Ns * frame_parms->symbols_per_slot + symbol;
    
    for (int idx_symb = Ns*frame_parms->symbols_per_slot; idx_symb < abs_symbol; idx_symb++)
Sakthivel Velumani's avatar
Sakthivel Velumani committed
142
      rx_offset += (idx_symb%(0x7<<frame_parms->numerology_index)) ? nb_prefix_samples : nb_prefix_samples0;
143

144 145 146 147
    rx_offset += frame_parms->ofdm_symbol_size * symbol;

    if (abs_symbol%(0x7<<frame_parms->numerology_index)) {

148
      rx_offset += nb_prefix_samples;
149
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
150 151
        memcpy((short*) &common_vars->rxdata[aa][frame_length_samples],
               (short*) &common_vars->rxdata[aa][0],
152 153 154 155
               frame_parms->ofdm_symbol_size*sizeof(int));

      if ((rx_offset&7)!=0) {  // if input to dft is not 256-bit aligned, issue for size 6,15 and 25 PRBs
        memcpy((void *)tmp_dft_in,
156
               (void *) &common_vars->rxdata[aa][rx_offset % frame_length_samples],
157
               frame_parms->ofdm_symbol_size*sizeof(int));
frtabu's avatar
frtabu committed
158
        dft(dftsize,(int16_t *)tmp_dft_in,
159
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
160 161 162 163 164
      } else { // use dft input from RX buffer directly
#if UE_TIMING_TRACE
          start_meas(&ue->rx_dft_stats);
#endif

frtabu's avatar
frtabu committed
165
        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
166
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
167 168 169 170 171
#if UE_TIMING_TRACE
        stop_meas(&ue->rx_dft_stats);
#endif
      }
    } else {
172

173
      rx_offset += nb_prefix_samples0;
174
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
175 176
        memcpy((void *) &common_vars->rxdata[aa][frame_length_samples],
               (void *) &common_vars->rxdata[aa][0],
177 178 179 180 181 182 183
               frame_parms->ofdm_symbol_size*sizeof(int));
#if UE_TIMING_TRACE
      start_meas(&ue->rx_dft_stats);
#endif

      if ((rx_offset&7)!=0) {  // if input to dft is not 128-bit aligned, issue for size 6 and 15 PRBs
        memcpy((void *)tmp_dft_in,
184
               (void *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
185
               frame_parms->ofdm_symbol_size*sizeof(int));
frtabu's avatar
frtabu committed
186
        dft(dftsize,(int16_t *)tmp_dft_in,
187
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
188 189
      } else { // use dft input from RX buffer directly

frtabu's avatar
frtabu committed
190
        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
191
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
192 193 194 195 196 197 198 199 200 201
      }
#if UE_TIMING_TRACE
      stop_meas(&ue->rx_dft_stats);
#endif


    }

    #ifdef DEBUG_FEP
        //  if (ue->frame <100)
yilmazt's avatar
yilmazt committed
202
        printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[(Ns)&1].frame_rx, symbol, rx_offset);
203 204 205 206
    #endif
  }


207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
#ifdef DEBUG_FEP
  printf("slot_fep: done\n");
#endif
  return(0);
}

int nr_slot_fep_init_sync(PHY_VARS_NR_UE *ue,
                unsigned char symbol,
                unsigned char Ns,
                int sample_offset,
                int no_prefix)
{
  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  NR_UE_COMMON *common_vars   = &ue->common_vars;
  unsigned char aa;
  unsigned int nb_prefix_samples;
  unsigned int nb_prefix_samples0;
  unsigned int abs_symbol;
  if (ue->is_synchronized) {
    nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
    nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples0);
  }
  else {
    nb_prefix_samples = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
    nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
  }
  //unsigned int subframe_offset;//,subframe_offset_F;
  unsigned int slot_offset;
  //int i;
  unsigned int frame_length_samples = frame_parms->samples_per_subframe * 10;
  unsigned int rx_offset;


frtabu's avatar
frtabu committed
240
  dft_size_idx_t dftsize;
241 242 243 244
  int tmp_dft_in[8192] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs

  switch (frame_parms->ofdm_symbol_size) {
  case 128:
frtabu's avatar
frtabu committed
245
    dftsize = DFT_128;
246 247 248
    break;

  case 256:
frtabu's avatar
frtabu committed
249
    dftsize = DFT_256;
250 251 252
    break;

  case 512:
frtabu's avatar
frtabu committed
253
    dftsize = DFT_512;
254 255 256
    break;

  case 1024:
frtabu's avatar
frtabu committed
257
    dftsize = DFT_1024;
258 259 260
    break;

  case 1536:
frtabu's avatar
frtabu committed
261
    dftsize = DFT_1536;
262 263 264
    break;

  case 2048:
frtabu's avatar
frtabu committed
265
    dftsize = DFT_2048;
266 267 268
    break;

  case 3072:
frtabu's avatar
frtabu committed
269
    dftsize = DFT_3072;
270 271 272
    break;

  case 4096:
frtabu's avatar
frtabu committed
273
    dftsize = DFT_4096;
274 275 276
    break;

  case 8192:
frtabu's avatar
frtabu committed
277
    dftsize = DFT_8192;
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 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
    break;

  default:
    printf("unsupported ofdm symbol size \n");
    assert(0);
  }

  if (no_prefix) {
    slot_offset = frame_parms->ofdm_symbol_size * (frame_parms->symbols_per_slot) * (Ns);
  } else {
    slot_offset = frame_parms->get_samples_slot_timestamp(Ns,frame_parms,0);
  }

  /*if (l<0 || l>=7-frame_parms->Ncp) {
    printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp);
    return(-1);
    }*/

  if (Ns<0 || Ns>(frame_parms->slots_per_frame-1)) {
    printf("slot_fep: Ns must be between 0 and %d\n",frame_parms->slots_per_frame-1);
    return(-1);
  }

  for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
    memset(&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int));

    rx_offset = sample_offset + slot_offset - SOFFSET;
    // Align with 256 bit
    //    rx_offset = rx_offset&0xfffffff8;

#ifdef DEBUG_FEP
      //  if (ue->frame <100)
    /*LOG_I(PHY,*/printf("slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %u, nb_prefix_samples0 %u, slot_offset %u, sample_offset %d,rx_offset %u, frame_length_samples %u\n",
    		ue->proc.proc_rxtx[(Ns)&1].frame_rx, Ns, symbol, nb_prefix_samples, nb_prefix_samples0, slot_offset, sample_offset, rx_offset, frame_length_samples);
#endif

    abs_symbol = Ns * frame_parms->symbols_per_slot + symbol;
    
    for (int idx_symb = Ns*frame_parms->symbols_per_slot; idx_symb < abs_symbol; idx_symb++)
      rx_offset += (abs_symbol%(0x7<<frame_parms->numerology_index)) ? nb_prefix_samples : nb_prefix_samples0;

    rx_offset += frame_parms->ofdm_symbol_size * symbol;

    if (abs_symbol%(0x7<<frame_parms->numerology_index)) {

      rx_offset += nb_prefix_samples;
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
        memcpy((short*) &common_vars->rxdata[aa][frame_length_samples],
               (short*) &common_vars->rxdata[aa][0],
               frame_parms->ofdm_symbol_size*sizeof(int));

      if ((rx_offset&7)!=0) {  // if input to dft is not 256-bit aligned, issue for size 6,15 and 25 PRBs
        memcpy((void *)tmp_dft_in,
               (void *) &common_vars->rxdata[aa][rx_offset],
               frame_parms->ofdm_symbol_size*sizeof(int));
frtabu's avatar
frtabu committed
333
        dft(dftsize,(int16_t *)tmp_dft_in,
334 335 336 337 338 339
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
      } else { // use dft input from RX buffer directly
#if UE_TIMING_TRACE
          start_meas(&ue->rx_dft_stats);
#endif

frtabu's avatar
frtabu committed
340 341

        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
#if UE_TIMING_TRACE
        stop_meas(&ue->rx_dft_stats);
#endif
      }
    } else {

      rx_offset += nb_prefix_samples0;
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
        memcpy((void *) &common_vars->rxdata[aa][frame_length_samples],
               (void *) &common_vars->rxdata[aa][0],
               frame_parms->ofdm_symbol_size*sizeof(int));
#if UE_TIMING_TRACE
      start_meas(&ue->rx_dft_stats);
#endif

      if ((rx_offset&7)!=0) {  // if input to dft is not 128-bit aligned, issue for size 6 and 15 PRBs
        memcpy((void *)tmp_dft_in,
               (void *) &common_vars->rxdata[aa][rx_offset],
               frame_parms->ofdm_symbol_size*sizeof(int));
frtabu's avatar
frtabu committed
362
        dft(dftsize,(int16_t *)tmp_dft_in,
363 364
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
      } else { // use dft input from RX buffer directly
frtabu's avatar
frtabu committed
365
        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
      }
#if UE_TIMING_TRACE
      stop_meas(&ue->rx_dft_stats);
#endif


    }

    #ifdef DEBUG_FEP
        //  if (ue->frame <100)
        printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[(Ns)&1].frame_rx, symbol, rx_offset);
    #endif
  }


382 383 384 385 386 387
#ifdef DEBUG_FEP
  printf("slot_fep: done\n");
#endif
  return(0);
}

388

389 390 391
int nr_slot_fep_ul(NR_DL_FRAME_PARMS *frame_parms,
                   int32_t *rxdata,
                   int32_t *rxdataF,
392 393 394 395 396 397 398 399 400 401 402
                   unsigned char symbol,
                   unsigned char Ns,
                   int sample_offset,
                   int no_prefix)
{
  uint32_t slot_offset;
  uint32_t rxdata_offset;

  unsigned int nb_prefix_samples  = (no_prefix ? 0 : frame_parms->nb_prefix_samples);
  unsigned int nb_prefix_samples0 = (no_prefix ? 0 : frame_parms->nb_prefix_samples0);
  
frtabu's avatar
frtabu committed
403
  dft_size_idx_t dftsize;
404 405 406

  switch (frame_parms->ofdm_symbol_size) {
    case 128:
frtabu's avatar
frtabu committed
407
      dftsize = DFT_128;
408 409 410
      break;

    case 256:
frtabu's avatar
frtabu committed
411
      dftsize = DFT_256;
412 413 414
      break;

    case 512:
frtabu's avatar
frtabu committed
415
      dftsize = DFT_512;
416 417 418
      break;

    case 1024:
frtabu's avatar
frtabu committed
419
      dftsize = DFT_1024;
420 421 422
      break;

    case 1536:
frtabu's avatar
frtabu committed
423
      dftsize = DFT_1536;
424 425 426
      break;

    case 2048:
frtabu's avatar
frtabu committed
427
      dftsize = DFT_2048;
428 429 430
      break;

    case 4096:
frtabu's avatar
frtabu committed
431
      dftsize = DFT_4096;
432 433 434
      break;

    case 8192:
frtabu's avatar
frtabu committed
435
      dftsize = DFT_8192;
436 437 438
      break;

    default:
frtabu's avatar
frtabu committed
439
      dftsize = DFT_512;
440 441 442
      break;
  }
  
Sakthivel Velumani's avatar
Sakthivel Velumani committed
443
  slot_offset   = frame_parms->get_samples_slot_timestamp(Ns,frame_parms,0);
444

445 446 447 448 449
  
  if(symbol == 0)
    rxdata_offset = slot_offset + nb_prefix_samples0 - SOFFSET;
  else
    rxdata_offset = slot_offset + nb_prefix_samples0 + (symbol * (frame_parms->ofdm_symbol_size + nb_prefix_samples)) - SOFFSET;
450

frtabu's avatar
frtabu committed
451
  dft(dftsize,(int16_t *)&rxdata[rxdata_offset],
452
       (int16_t *)&rxdataF[symbol * frame_parms->ofdm_symbol_size], 1);
453 454 455

  return(0);
}