slot_fep_nr.c 9.17 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;
59
  uint16_t nb_rb_coreset = 24;
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 63
  uint8_t p=0;
  uint8_t l0 = 2;
64 65

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

  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
93 94 95 96 97 98 99 100
  case 4096:
    dft = dft4096;
    break;

  case 8192:
    dft = dft8192;
    break;

101 102 103 104 105 106
  default:
    dft = dft512;
    break;
  }

  if (no_prefix) {
107
    slot_offset = frame_parms->ofdm_symbol_size * (frame_parms->symbols_per_slot) * (Ns);
108
  } else {
109
    slot_offset = (frame_parms->samples_per_slot) * (Ns);
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
  }

  /*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++) {
125
    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));
126

Hongzhi Wang's avatar
Hongzhi Wang committed
127
    rx_offset = sample_offset + slot_offset + nb_prefix_samples0 - SOFFSET;
128 129 130
    // Align with 256 bit
    //    rx_offset = rx_offset&0xfffffff8;

131 132
#ifdef DEBUG_FEP
      //  if (ue->frame <100)
133 134
    /*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);
135 136
#endif

137 138 139 140 141 142 143 144 145 146 147 148
    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,
149
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
150 151 152 153 154 155
      } 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],
156
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
#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,
178
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
179 180 181
      } else { // use dft input from RX buffer directly

        dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
182
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
183 184 185 186 187 188 189 190 191 192
      }
#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
193
        printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[(Ns)&1].frame_rx, symbol,rx_offset);
194 195 196 197 198 199 200 201
    #endif
  }

  if (ue->perfect_ce == 0) {

  switch(channel){
  case NR_PBCH_EST:

202
#ifdef DEBUG_FEP
knopp's avatar
knopp committed
203
    printf("Channel estimation eNB %d, slot %d, symbol %d\n",eNB_id,Ns,l);
204
#endif
205
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
206
    start_meas(&ue->dlsch_channel_estimation_stats);
207
#endif
knopp's avatar
knopp committed
208 209 210 211
    nr_pbch_channel_estimation(ue,eNB_id,0,
			       Ns,
			       l,
			       symbol);
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
      //}
#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
239

240 241 242 243 244
  break;

  case NR_PDCCH_EST:

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

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

    if (symbol ==l0)
knopp's avatar
knopp committed
273 274
    nr_pdsch_channel_estimation(ue,eNB_id,0,
				Ns,
hongzhi wang's avatar
hongzhi wang committed
275
				p,
knopp's avatar
knopp committed
276 277 278 279
				l,
				symbol,
				bwp_start_subcarrier,
				nb_rb_pdsch);
hongzhi wang's avatar
hongzhi wang committed
280
				
281
#if UE_TIMING_TRACE
knopp's avatar
knopp committed
282
    stop_meas(&ue->dlsch_channel_estimation_stats);
283
#endif
knopp's avatar
knopp committed
284
    
285
    break;
knopp's avatar
knopp committed
286
    
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  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);
}