slot_fep_nr.c 9.49 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 23 24 25 26 27
/*
 * 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_UE.h"
#include "PHY/defs_nr_UE.h"
#include "modulation_UE.h"
#include "PHY/LTE_ESTIMATION/lte_estimation.h"
#include "PHY/NR_UE_ESTIMATION/nr_estimation.h"

28
//#define DEBUG_FEP
29 30 31

#define SOFFSET 0

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

37
int nr_slot_fep(PHY_VARS_NR_UE *ue,
38 39 40 41 42 43
		unsigned char l,
		unsigned char Ns,
		int sample_offset,
		int no_prefix,
		int reset_freq_est,
		NR_CHANNEL_EST_t channel)
44 45 46 47 48 49 50 51
{
  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  NR_UE_COMMON *common_vars   = &ue->common_vars;
  uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
  unsigned char aa;
  unsigned char symbol = l;//+((7-frame_parms->Ncp)*(Ns&1)); ///symbol within sub-frame
  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);
Hongzhi Wang's avatar
Hongzhi Wang committed
52
  //unsigned int subframe_offset;//,subframe_offset_F;
53 54 55 56
  unsigned int slot_offset;
  //int i;
  unsigned int frame_length_samples = frame_parms->samples_per_subframe * 10;
  unsigned int rx_offset;
57
  NR_UE_PDCCH *pdcch_vars  = ue->pdcch_vars[ue->current_thread_id[Ns]][0];
Guy De Souza's avatar
Guy De Souza committed
58
  uint16_t coreset_start_subcarrier = frame_parms->first_carrier_offset;//+((int)floor(frame_parms->ssb_start_subcarrier/NR_NB_SC_PER_RB)+pdcch_vars->coreset[0].rb_offset)*NR_NB_SC_PER_RB;
Hongzhi Wang's avatar
Hongzhi Wang committed
59
  uint16_t nb_rb_coreset = 0;
Guy De Souza's avatar
Guy De Souza committed
60
  uint16_t bwp_start_subcarrier = frame_parms->first_carrier_offset;//+516;
Hongzhi Wang's avatar
Hongzhi Wang committed
61
  uint16_t nb_rb_pdsch = 50;
hongzhi wang's avatar
hongzhi wang committed
62
  uint8_t p=0;
Hongzhi Wang's avatar
Hongzhi Wang committed
63 64 65 66 67 68 69
  uint8_t l0 = pdcch_vars->coreset[0].duration;
  uint64_t coreset_freq_dom  = pdcch_vars->coreset[0].frequencyDomainResources;
  for (int i = 0; i < 45; i++) {
    if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> i) & 0x1) nb_rb_coreset++;
  }
  nb_rb_coreset = 6 * nb_rb_coreset; 
  //printf("corset duration %d nb_rb_coreset %d\n", l0, nb_rb_coreset);
70 71

  void (*dft)(int16_t *,int16_t *, int);
knopp's avatar
knopp committed
72
  int tmp_dft_in[8192] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

  switch (frame_parms->ofdm_symbol_size) {
  case 128:
    dft = dft128;
    break;

  case 256:
    dft = dft256;
    break;

  case 512:
    dft = dft512;
    break;

  case 1024:
    dft = dft1024;
    break;

  case 1536:
    dft = dft1536;
    break;

  case 2048:
    dft = dft2048;
    break;

knopp's avatar
knopp committed
99 100 101 102 103 104 105 106
  case 4096:
    dft = dft4096;
    break;

  case 8192:
    dft = dft8192;
    break;

107 108 109 110 111 112
  default:
    dft = dft512;
    break;
  }

  if (no_prefix) {
113
    slot_offset = frame_parms->ofdm_symbol_size * (frame_parms->symbols_per_slot) * (Ns);
114
  } else {
115
    slot_offset = (frame_parms->samples_per_slot) * (Ns);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  }

  /*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>=20) {
    printf("slot_fep: Ns must be between 0 and 19\n");
    return(-1);
  }



  for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
131
    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));
132

Hongzhi Wang's avatar
Hongzhi Wang committed
133
    rx_offset = sample_offset + slot_offset + nb_prefix_samples0 - SOFFSET;
134 135 136
    // Align with 256 bit
    //    rx_offset = rx_offset&0xfffffff8;

137 138
#ifdef DEBUG_FEP
      //  if (ue->frame <100)
139 140
    /*LOG_I(PHY,*/printf("slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d,  sample_offset %d,rx_offset %d, frame_length_samples %d\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);
141 142
#endif

143 144 145 146 147 148 149 150 151 152 153 154
    if (l==0) {

      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_length_samples],
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
155
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
156 157 158 159 160 161
      } else { // use dft input from RX buffer directly
#if UE_TIMING_TRACE
          start_meas(&ue->rx_dft_stats);
#endif

        dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
162
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
#if UE_TIMING_TRACE
        stop_meas(&ue->rx_dft_stats);
#endif
      }
    } else {
      rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// +
      //                   (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1);

      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_length_samples],
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
184
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
185 186 187
      } else { // use dft input from RX buffer directly

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


    }

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

  if (ue->perfect_ce == 0) {

  switch(channel){
  case NR_PBCH_EST:

208
#ifdef DEBUG_FEP
knopp's avatar
knopp committed
209
    printf("Channel estimation eNB %d, slot %d, symbol %d\n",eNB_id,Ns,l);
210
#endif
211
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
212
    start_meas(&ue->dlsch_channel_estimation_stats);
213
#endif
knopp's avatar
knopp committed
214 215 216 217
    nr_pbch_channel_estimation(ue,eNB_id,0,
			       Ns,
			       l,
			       symbol);
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
      //}
#if UE_TIMING_TRACE
        stop_meas(&ue->dlsch_channel_estimation_stats);
#endif

      // do frequency offset estimation here!
      // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1})
#ifdef DEBUG_FEP
      printf("Frequency offset estimation\n");
#endif

      if (l==(4-frame_parms->Ncp)) {

#if UE_TIMING_TRACE
          start_meas(&ue->dlsch_freq_offset_estimation_stats);
#endif

        /*lte_est_freq_offset(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[0],
                            frame_parms,
                            l,
                            &common_vars->freq_offset,
			    reset_freq_est);*/
#if UE_TIMING_TRACE
        stop_meas(&ue->dlsch_freq_offset_estimation_stats);
#endif

      }
knopp's avatar
knopp committed
245

246 247 248 249 250
  break;

  case NR_PDCCH_EST:

#ifdef DEBUG_FEP
knopp's avatar
knopp committed
251
    printf("PDCCH Channel estimation eNB %d, aatx %d, slot %d, symbol %d start_sc %d\n",eNB_id,aa,Ns,l,coreset_start_subcarrier);
252 253
#endif
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
254
    start_meas(&ue->dlsch_channel_estimation_stats);
255
#endif
knopp's avatar
knopp committed
256 257 258 259 260 261
    nr_pdcch_channel_estimation(ue,eNB_id,0,
				Ns,
				l,
				symbol,
				coreset_start_subcarrier,
				nb_rb_coreset);
262
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
263
    stop_meas(&ue->dlsch_channel_estimation_stats);
264
#endif
knopp's avatar
knopp committed
265
    
266
    break;
knopp's avatar
knopp committed
267
    
268 269
  case NR_PDSCH_EST:
#ifdef DEBUG_FEP
knopp's avatar
knopp committed
270
    printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
271 272
#endif
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
273
    start_meas(&ue->dlsch_channel_estimation_stats);
274
#endif
hongzhi wang's avatar
hongzhi wang committed
275 276 277 278

  ue->frame_parms.nushift =  (p>>1)&1;;

    if (symbol ==l0)
knopp's avatar
knopp committed
279 280
    nr_pdsch_channel_estimation(ue,eNB_id,0,
				Ns,
hongzhi wang's avatar
hongzhi wang committed
281
				p,
knopp's avatar
knopp committed
282 283 284 285
				l,
				symbol,
				bwp_start_subcarrier,
				nb_rb_pdsch);
hongzhi wang's avatar
hongzhi wang committed
286
				
287
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
288
    stop_meas(&ue->dlsch_channel_estimation_stats);
289
#endif
knopp's avatar
knopp committed
290
    
291
    break;
knopp's avatar
knopp committed
292
    
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
  case NR_SSS_EST:
  break;

  default:
    LOG_E(PHY,"[UE][FATAL] Unknown channel format %d\n",channel);
    return(-1);
    break;
  }

  }

#ifdef DEBUG_FEP
  printf("slot_fep: done\n");
#endif
  return(0);
}