slot_fep.c 8.28 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
#include "PHY/defs.h"
#include "defs.h"
//#define DEBUG_FEP

#define SOFFSET 0

28

29
int slot_fep(PHY_VARS_UE *ue,
30 31 32
             unsigned char l,
             unsigned char Ns,
             int sample_offset,
33 34
             int no_prefix,
	     int reset_freq_est)
35
{
36

37 38
  LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  LTE_UE_COMMON *common_vars   = &ue->common_vars;
39
  uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
40 41 42 43 44 45 46 47 48 49
  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);
  unsigned int subframe_offset;//,subframe_offset_F;
  unsigned int slot_offset;
  int i;
  unsigned int frame_length_samples = frame_parms->samples_per_tti * 10;
  unsigned int rx_offset;

50 51 52 53 54
  /*LTE_UE_DLSCH_t **dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id];
  unsigned char harq_pid = dlsch_ue[0]->current_harq_pid; 
  LTE_DL_UE_HARQ_t *dlsch0_harq = dlsch_ue[0]->harq_processes[harq_pid];
  int uespec_pilot[9][1200];*/

55
  void (*dft)(int16_t *,int16_t *, int);
56
  int tmp_dft_in[2048] __attribute__ ((aligned (32)));  // This is for misalignment issues for 6 and 15 PRBs
57

58 59
  switch (frame_parms->ofdm_symbol_size) {
  case 128:
60 61
    dft = dft128;
    break;
62

63
  case 256:
64 65
    dft = dft256;
    break;
66

67
  case 512:
68 69
    dft = dft512;
    break;
70

71
  case 1024:
72 73
    dft = dft1024;
    break;
74

75 76 77 78 79
  case 1536:
    dft = dft1536;
    break;

  case 2048:
80 81
    dft = dft2048;
    break;
82

83 84 85 86 87 88 89 90
  default:
    dft = dft512;
    break;
  }

  if (no_prefix) {
    subframe_offset = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1);
    slot_offset = frame_parms->ofdm_symbol_size * (frame_parms->symbols_per_tti>>1) * (Ns%2);
91
  } else {
92 93 94
    subframe_offset = frame_parms->samples_per_tti * (Ns>>1);
    slot_offset = (frame_parms->samples_per_tti>>1) * (Ns%2);
  }
95

96 97 98 99
  //  subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1);


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

104
  if (Ns<0 || Ns>=20) {
105
    printf("slot_fep: Ns must be between 0 and 19\n");
106 107 108 109
    return(-1);
  }


110 111

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

knopp's avatar
knopp committed
114
    rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET;
115 116
    // Align with 256 bit
    //    rx_offset = rx_offset&0xfffffff8;
knopp's avatar
knopp committed
117

118
    if (l==0) {
knopp's avatar
knopp committed
119

120
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
121 122
        memcpy((short *)&common_vars->rxdata[aa][frame_length_samples],
               (short *)&common_vars->rxdata[aa][0],
123
               frame_parms->ofdm_symbol_size*sizeof(int));
124

125
      if ((rx_offset&7)!=0) {  // if input to dft is not 256-bit aligned, issue for size 6,15 and 25 PRBs
126
        memcpy((void *)tmp_dft_in,
127
               (void *)&common_vars->rxdata[aa][rx_offset % frame_length_samples],
128 129
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
130
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[(Ns>>1)&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
131
      } else { // use dft input from RX buffer directly
Gabriel's avatar
Gabriel committed
132 133 134
#if UE_TIMING_TRACE
          start_meas(&ue->rx_dft_stats);
#endif
135

136
        dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
137
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[(Ns>>1)&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
Gabriel's avatar
Gabriel committed
138
#if UE_TIMING_TRACE
139
        stop_meas(&ue->rx_dft_stats);
Gabriel's avatar
Gabriel committed
140
#endif
141

142
      }
143
    } else {
144 145
      rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// +
      //                   (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1);
146

knopp's avatar
knopp committed
147
#ifdef DEBUG_FEP
148
      //  if (ue->frame <100)
149 150
      LOG_I(PHY,"slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx,Ns, symbol,
          nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples);
knopp's avatar
knopp committed
151
#endif
152

153
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
154 155
        memcpy((void *)&common_vars->rxdata[aa][frame_length_samples],
               (void *)&common_vars->rxdata[aa][0],
156
               frame_parms->ofdm_symbol_size*sizeof(int));
Gabriel's avatar
Gabriel committed
157
#if UE_TIMING_TRACE
158
      start_meas(&ue->rx_dft_stats);
Gabriel's avatar
Gabriel committed
159
#endif
160

161
      if ((rx_offset&7)!=0) {  // if input to dft is not 128-bit aligned, issue for size 6 and 15 PRBs
162
        memcpy((void *)tmp_dft_in,
163
               (void *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
164 165
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
166
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[(Ns>>1)&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
167
      } else { // use dft input from RX buffer directly
168

169
        dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
170
            (int16_t *)&common_vars->common_vars_rx_data_per_thread[(Ns>>1)&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
171
      }
Gabriel's avatar
Gabriel committed
172
#if UE_TIMING_TRACE
173
      stop_meas(&ue->rx_dft_stats);
Gabriel's avatar
Gabriel committed
174
#endif
knopp's avatar
knopp committed
175 176


177
    }
knopp's avatar
knopp committed
178

179 180 181 182
    #ifdef DEBUG_FEP
        //  if (ue->frame <100)
        printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx, symbol,rx_offset);
    #endif
183
  }
knopp's avatar
knopp committed
184

185
  if (ue->perfect_ce == 0) {
186
    if ((l==0) || (l==(4-frame_parms->Ncp))) {
Xiwen JIANG's avatar
Xiwen JIANG committed
187
      for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) {
188 189

#ifdef DEBUG_FEP
190
        printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
191
#endif
Gabriel's avatar
Gabriel committed
192
#if UE_TIMING_TRACE
193
        start_meas(&ue->dlsch_channel_estimation_stats);
Gabriel's avatar
Gabriel committed
194
#endif
195
        lte_dl_channel_estimation(ue,eNB_id,0,
196 197 198 199
                                  Ns,
                                  aa,
                                  l,
                                  symbol);
Gabriel's avatar
Gabriel committed
200
#if UE_TIMING_TRACE
201
        stop_meas(&ue->dlsch_channel_estimation_stats);
Gabriel's avatar
Gabriel committed
202
#endif
203

204 205
        for (i=0; i<ue->measurements.n_adj_cells; i++) {
          lte_dl_channel_estimation(ue,eNB_id,i+1,
206 207 208 209 210
                                    Ns,
                                    aa,
                                    l,
                                    symbol);
        }
211 212 213 214
      }


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

knopp's avatar
knopp committed
220
      if (l==(4-frame_parms->Ncp)) {
Gabriel's avatar
Gabriel committed
221 222 223
#if UE_TIMING_TRACE
          start_meas(&ue->dlsch_freq_offset_estimation_stats);
#endif
224
        lte_est_freq_offset(common_vars->common_vars_rx_data_per_thread[(Ns>>1)&0x1].dl_ch_estimates[0],
225 226
                            frame_parms,
                            l,
227
                            &common_vars->freq_offset,
228
			    reset_freq_est);
Gabriel's avatar
Gabriel committed
229
#if UE_TIMING_TRACE
230
        stop_meas(&ue->dlsch_freq_offset_estimation_stats);
Gabriel's avatar
Gabriel committed
231
#endif
232 233

      }
234
    }
235

236
  }
237

238
#ifdef DEBUG_FEP
239
  printf("slot_fep: done\n");
240 241 242
#endif
  return(0);
}