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

22 23 24 25 26 27
#include "PHY/defs.h"
#include "defs.h"
//#define DEBUG_FEP

#define SOFFSET 0

28
int slot_fep_mbsfn(PHY_VARS_UE *ue,
29 30 31 32 33
                   unsigned char l,
                   int subframe,
                   int sample_offset,
                   int no_prefix)
{
Raymond Knopp's avatar
Raymond Knopp committed
34
 
35 36
  LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  LTE_UE_COMMON *common_vars   = &ue->common_vars;
37
  uint8_t eNB_id = 0;//ue_common_vars->eNb_id;
38

39 40 41 42 43
  unsigned char aa;
  unsigned char frame_type = frame_parms->frame_type; // Frame Type: 0 - FDD, 1 - TDD;
  unsigned int nb_prefix_samples = frame_parms->ofdm_symbol_size>>2;//(no_prefix ? 0 : frame_parms->nb_prefix_samples);
  unsigned int nb_prefix_samples0 = frame_parms->ofdm_symbol_size>>2;//(no_prefix ? 0 : frame_parms->nb_prefix_samples0);
  unsigned int subframe_offset;
44 45

  //   int i;
46 47 48
  unsigned int frame_length_samples = frame_parms->samples_per_tti * 10;
  void (*dft)(int16_t *,int16_t *, int);

49
  switch (frame_parms->ofdm_symbol_size) {
50

51
  case 128:
52 53
    dft = dft128;
    break;
54

55
  case 256:
56 57
    dft = dft256;
    break;
58

59
  case 512:
60 61
    dft = dft512;
    break;
62

63
  case 1024:
64 65
    dft = dft1024;
    break;
66

67 68 69 70 71
  case 1536:
    dft = dft1536;
    break;

  case 2048:
72 73
    dft = dft2048;
    break;
74

75 76 77 78
  default:
    dft = dft512;
    break;
  }
79

80 81 82
  if (no_prefix) {
    subframe_offset = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * subframe;

83
  } else {
84 85 86 87 88 89 90 91 92
    subframe_offset = frame_parms->samples_per_tti * subframe;

  }


  if (l<0 || l>=12) {
    msg("slot_fep_mbsfn: l must be between 0 and 11\n");
    return(-1);
  }
93

94
  if (((subframe == 0) || (subframe == 5) ||    // SFn 0,4,5,9;
95 96 97
       (subframe == 4) || (subframe == 9))
      && (frame_type==FDD) )    {   //check for valid MBSFN subframe
    msg("slot_fep_mbsfn: Subframe must be 1,2,3,6,7,8 for FDD, Got %d \n",subframe);
98
    return(-1);
99 100 101 102
  } else if (((subframe == 0) || (subframe == 1) || (subframe==2) ||  // SFn 0,4,5,9;
              (subframe == 5) || (subframe == 6))
             && (frame_type==TDD) )   {   //check for valid MBSFN subframe
    msg("slot_fep_mbsfn: Subframe must be 3,4,7,8,9 for TDD, Got %d \n",subframe);
103 104
    return(-1);
  }
105

106
#ifdef DEBUG_FEP
107 108
  msg("slot_fep_mbsfn: subframe %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, subframe_offset %d, sample_offset %d\n", subframe, l, nb_prefix_samples,nb_prefix_samples0,subframe_offset,
      sample_offset);
109 110
#endif

111
  for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
112
    memset(&common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*l],0,frame_parms->ofdm_symbol_size*sizeof(int));
113
    if (l==0) {
gabrielC's avatar
gabrielC committed
114 115 116
#if UE_TIMING_TRACE
        start_meas(&ue->rx_dft_stats);
#endif
117
      dft((int16_t *)&common_vars->rxdata[aa][(sample_offset +
118 119 120
          nb_prefix_samples0 +
          subframe_offset -
          SOFFSET) % frame_length_samples],
121
          (int16_t *)&common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*l],1);
gabrielC's avatar
gabrielC committed
122
#if UE_TIMING_TRACE
123
      stop_meas(&ue->rx_dft_stats);
gabrielC's avatar
gabrielC committed
124
#endif
125 126 127 128 129 130
    } else {
      if ((sample_offset +
           (frame_parms->ofdm_symbol_size+nb_prefix_samples0+nb_prefix_samples) +
           (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1) +
           subframe_offset-
           SOFFSET) > (frame_length_samples - frame_parms->ofdm_symbol_size))
131 132
        memcpy((short *)&common_vars->rxdata[aa][frame_length_samples],
               (short *)&common_vars->rxdata[aa][0],
133 134
               frame_parms->ofdm_symbol_size*sizeof(int));

gabrielC's avatar
gabrielC committed
135
#if UE_TIMING_TRACE
136
      start_meas(&ue->rx_dft_stats);
gabrielC's avatar
gabrielC committed
137
#endif
138
      dft((int16_t *)&common_vars->rxdata[aa][(sample_offset +
139 140 141 142
          (frame_parms->ofdm_symbol_size+nb_prefix_samples0+nb_prefix_samples) +
          (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1) +
          subframe_offset-
          SOFFSET) % frame_length_samples],
143
          (int16_t *)&common_vars->common_vars_rx_data_per_thread[subframe&0x1].rxdataF[aa][frame_parms->ofdm_symbol_size*l],1);
gabrielC's avatar
gabrielC committed
144
#if UE_TIMING_TRACE
145
      stop_meas(&ue->rx_dft_stats);
gabrielC's avatar
gabrielC committed
146
#endif
147 148
    }
  }
149

Raymond Knopp's avatar
Raymond Knopp committed
150 151


152
  //if ((l==0) || (l==(4-frame_parms->Ncp))) {
153 154 155
  // changed to invoke MBSFN channel estimation in symbols 2,6,10
  if ((l==2)||(l==6)||(l==10)) {
    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
156
      if (ue->perfect_ce == 0) {
157
#ifdef DEBUG_FEP
158
        msg("Channel estimation eNB %d, aatx %d, subframe %d, symbol %d\n",eNB_id,aa,subframe,l);
159 160
#endif

161
        lte_dl_mbsfn_channel_estimation(ue,
162 163 164 165
                                        eNB_id,
                                        0,
                                        subframe,
                                        l);
166 167
        /*   for (i=0;i<ue->PHY_measurements.n_adj_cells;i++) {
        lte_dl_mbsfn_channel_estimation(ue,
168 169 170 171
               eNB_id,
             i+1,
               subframe,
               l);
172
             lte_dl_channel_estimation(ue,eNB_id,0,
173 174 175 176
           Ns,
           aa,
           l,
           symbol);
177 178
           for (i=0;i<ue->PHY_measurements.n_adj_cells;i++) {
        lte_dl_channel_estimation(ue,eNB_id,i+1,
179 180 181 182 183 184 185 186
             Ns,
             aa,
             l,
             symbol); */
        //  }

        // do frequency offset estimation here!
        // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1})
187
#ifdef DEBUG_FEP
188 189 190 191
        msg("Frequency offset estimation\n");
#endif
        // if ((l == 0) || (l==(4-frame_parms->Ncp)))
        /*    if ((l==2)||(l==6)||(l==10))
192
          lte_mbsfn_est_freq_offset(common_vars->dl_ch_estimates[0],
193 194
                  frame_parms,
                  l,
195
                  &common_vars->freq_offset); */
196
      }
Raymond Knopp's avatar
 
Raymond Knopp committed
197
    }
198
  }
199

200 201 202 203 204
#ifdef DEBUG_FEP
  msg("slot_fep_mbsfn: done\n");
#endif
  return(0);
}