slot_fep.c 8.14 KB
Newer Older
ghaddab's avatar
ghaddab committed
1
/*******************************************************************************
2
    OpenAirInterface
ghaddab's avatar
ghaddab committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
17 18
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
ghaddab's avatar
ghaddab committed
19 20 21 22 23
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
ghaddab's avatar
ghaddab committed
27 28

 *******************************************************************************/
29 30 31 32 33 34 35
#include "PHY/defs.h"
#include "MAC_INTERFACE/extern.h"
#include "defs.h"
//#define DEBUG_FEP

#define SOFFSET 0

36

37
int slot_fep(PHY_VARS_UE *phy_vars_ue,
38 39 40
             unsigned char l,
             unsigned char Ns,
             int sample_offset,
41 42
             int no_prefix,
	     int reset_freq_est)
43
{
44 45 46

  LTE_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->lte_frame_parms;
  LTE_UE_COMMON *ue_common_vars   = &phy_vars_ue->lte_ue_common_vars;
47
  uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
48 49 50 51 52 53 54 55 56 57 58
  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;

  void (*dft)(int16_t *,int16_t *, int);
Raymond Knopp's avatar
 
Raymond Knopp committed
59
  int tmp_dft_in[256];  // This is for misalignment issues for 6 and 15 PRBs
60

61 62
  switch (frame_parms->ofdm_symbol_size) {
  case 128:
63 64
    dft = dft128;
    break;
65

66
  case 256:
67 68
    dft = dft256;
    break;
69

70
  case 512:
71 72
    dft = dft512;
    break;
73

74
  case 1024:
75 76
    dft = dft1024;
    break;
77

78 79 80 81 82
  case 1536:
    dft = dft1536;
    break;

  case 2048:
83 84
    dft = dft2048;
    break;
85

86 87 88 89 90 91 92 93
  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);
94
  } else {
95 96 97
    subframe_offset = frame_parms->samples_per_tti * (Ns>>1);
    slot_offset = (frame_parms->samples_per_tti>>1) * (Ns%2);
  }
98

99 100 101 102
  //  subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1);


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

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


113 114

  for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
115 116
    memset(&ue_common_vars->rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int));

Raymond Knopp's avatar
 
Raymond Knopp committed
117 118 119 120 121
    rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET;
    // Align with 128 bit
    rx_offset = rx_offset - rx_offset % 4;

#ifdef DEBUG_FEP
122
    //  if (phy_vars_ue->frame <100)
123
    printf("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\n", phy_vars_ue->frame_rx,Ns, symbol,
124
        nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset);
Raymond Knopp's avatar
 
Raymond Knopp committed
125
#endif
126

127
    if (l==0) {
Raymond Knopp's avatar
 
Raymond Knopp committed
128

129
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
130 131 132
        memcpy((short *)&ue_common_vars->rxdata[aa][frame_length_samples],
               (short *)&ue_common_vars->rxdata[aa][0],
               frame_parms->ofdm_symbol_size*sizeof(int));
133 134

      if ((rx_offset&3)!=0) {  // if input to dft is not 128-bit aligned, issue for size 6 and 15 PRBs
135 136 137 138 139 140 141
        memcpy((void *)tmp_dft_in,
               (void *)&ue_common_vars->rxdata[aa][(rx_offset-nb_prefix_samples0) % frame_length_samples],
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
            (int16_t *)&ue_common_vars->rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
      } else { // use dft input from RX buffer directly
        start_meas(&phy_vars_ue->rx_dft_stats);
142

143 144 145 146
        dft((int16_t *)&ue_common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
            (int16_t *)&ue_common_vars->rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
        stop_meas(&phy_vars_ue->rx_dft_stats);

147
      }
148
    } else {
Raymond Knopp's avatar
 
Raymond Knopp committed
149
      rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples) +
150
                   (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1);
151

Raymond Knopp's avatar
 
Raymond Knopp committed
152
#ifdef DEBUG_FEP
153
      //  if (phy_vars_ue->frame <100)
154
      printf("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\n", phy_vars_ue->frame_rx,Ns, symbol,
155
          nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset);
Raymond Knopp's avatar
 
Raymond Knopp committed
156
#endif
157

158
      if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size))
159 160 161 162
        memcpy((void *)&ue_common_vars->rxdata[aa][frame_length_samples],
               (void *)&ue_common_vars->rxdata[aa][0],
               frame_parms->ofdm_symbol_size*sizeof(int));

Raymond Knopp's avatar
 
Raymond Knopp committed
163
      start_meas(&phy_vars_ue->rx_dft_stats);
164

Raymond Knopp's avatar
 
Raymond Knopp committed
165
      if ((rx_offset&3)!=0) {  // if input to dft is not 128-bit aligned, issue for size 6 and 15 PRBs
166 167 168 169 170 171
        memcpy((void *)tmp_dft_in,
               (void *)&ue_common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
               frame_parms->ofdm_symbol_size*sizeof(int));
        dft((int16_t *)tmp_dft_in,
            (int16_t *)&ue_common_vars->rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
      } else { // use dft input from RX buffer directly
172

173 174
        dft((int16_t *)&ue_common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
            (int16_t *)&ue_common_vars->rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
175
      }
176

Raymond Knopp's avatar
 
Raymond Knopp committed
177 178 179
      stop_meas(&phy_vars_ue->rx_dft_stats);


180
    }
Raymond Knopp's avatar
 
Raymond Knopp committed
181

182
  }
Raymond Knopp's avatar
 
Raymond Knopp committed
183

Raymond Knopp's avatar
 
Raymond Knopp committed
184
  if (phy_vars_ue->perfect_ce == 0) {
185 186
    if ((l==0) || (l==(4-frame_parms->Ncp))) {
      for (aa=0; aa<frame_parms->nb_antennas_tx_eNB; aa++) {
187 188

#ifdef DEBUG_FEP
189
        printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l);
190
#endif
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
        start_meas(&phy_vars_ue->dlsch_channel_estimation_stats);
        lte_dl_channel_estimation(phy_vars_ue,eNB_id,0,
                                  Ns,
                                  aa,
                                  l,
                                  symbol);
        stop_meas(&phy_vars_ue->dlsch_channel_estimation_stats);

        for (i=0; i<phy_vars_ue->PHY_measurements.n_adj_cells; i++) {
          lte_dl_channel_estimation(phy_vars_ue,eNB_id,i+1,
                                    Ns,
                                    aa,
                                    l,
                                    symbol);
        }
206 207 208 209
      }


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

Raymond Knopp's avatar
 
Raymond Knopp committed
215
      if (l==(4-frame_parms->Ncp)) {
216 217 218 219
        start_meas(&phy_vars_ue->dlsch_freq_offset_estimation_stats);
        lte_est_freq_offset(ue_common_vars->dl_ch_estimates[0],
                            frame_parms,
                            l,
220 221
                            &ue_common_vars->freq_offset,
			    reset_freq_est);
222
        stop_meas(&phy_vars_ue->dlsch_freq_offset_estimation_stats);
223 224

      }
225
    }
226
  }
227

228
#ifdef DEBUG_FEP
229
  printf("slot_fep: done\n");
230 231 232
#endif
  return(0);
}