lte_adjust_sync.c 4.5 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
#include "PHY/types.h"
23 24
#include "PHY/defs_UE.h"
#include "PHY/phy_extern_ue.h"
25

26
#include "UTIL/LOG/vcd_signal_dumper.h"
27
#include "lte_estimation_defs.h"
28

29
#define DEBUG_PHY
30 31 32 33 34 35

// Adjust location synchronization point to account for drift
// The adjustment is performed once per frame based on the
// last channel estimate of the receiver

void lte_adjust_synch(LTE_DL_FRAME_PARMS *frame_parms,
36
                      PHY_VARS_UE *ue,
37
                      unsigned char eNB_id,
38
					  uint8_t subframe,
39 40
                      unsigned char clear,
                      short coef)
41 42 43
{

  static int max_pos_fil = 0;
44 45
  static int count_max_pos_ok = 0;
  static int first_time = 1;
46
  int temp = 0, i, aa, max_val = 0, max_pos = 0;
47 48 49
  int diff;
  short Re,Im,ncoef;

50 51
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_IN);

52 53 54
  ncoef = 32767 - coef;

#ifdef DEBUG_PHY
55
  LOG_D(PHY,"AbsSubframe %d.%d: rx_offset (before) = %d\n",ue->proc.proc_rxtx[0].frame_rx%1024,subframe,ue->rx_offset);
56 57 58 59 60 61
#endif //DEBUG_PHY


  // we only use channel estimates from tx antenna 0 here
  for (i = 0; i < frame_parms->nb_prefix_samples; i++) {
    temp = 0;
62 63

    for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
64 65
      Re = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[(i<<2)];
      Im = ((int16_t*)ue->common_vars.common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates_time[eNB_id][aa])[1+(i<<2)];
66 67
      temp += (Re*Re/2) + (Im*Im/2);
    }
68

69 70 71 72 73 74 75 76 77 78 79 80
    if (temp > max_val) {
      max_pos = i;
      max_val = temp;
    }
  }

  // filter position to reduce jitter
  if (clear == 1)
    max_pos_fil = max_pos;
  else
    max_pos_fil = ((max_pos_fil * coef) + (max_pos * ncoef)) >> 15;

81
  // do not filter to have proactive timing adjustment
82
  max_pos_fil = max_pos;
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  if(subframe == 6)
  {
      diff = max_pos_fil - (frame_parms->nb_prefix_samples>>3);

      if ( abs(diff) < SYNCH_HYST )
          ue->rx_offset = 0;
      else
          ue->rx_offset = diff;

      if(abs(diff)<5)
          count_max_pos_ok ++;
      else
          count_max_pos_ok = 0;

      if(count_max_pos_ok > 10 && first_time == 1)
      {
          first_time = 0;
          ue->time_sync_cell = 1;
          if (ue->mac_enabled==1) {
              LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
              //mac_resynch();
105
              dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
106 107 108 109 110 111
              ue->UE_mode[0] = PRACH;
          }
          else {
              ue->UE_mode[0] = PUSCH;
          }
      }
112

113 114
      if ( ue->rx_offset < 0 )
          ue->rx_offset += FRAME_LENGTH_COMPLEX_SAMPLES;
115

116 117
      if ( ue->rx_offset >= FRAME_LENGTH_COMPLEX_SAMPLES )
          ue->rx_offset -= FRAME_LENGTH_COMPLEX_SAMPLES;
118

119 120


121
      #ifdef DEBUG_PHY
122 123
      LOG_D(PHY,"AbsSubframe %d.%d: ThreadId %d diff =%i rx_offset (final) = %i : clear %d,max_pos = %d,max_pos_fil = %d (peak %d) max_val %d target_pos %d \n",
              ue->proc.proc_rxtx[ue->current_thread_id[subframe]].frame_rx,
124
              subframe,
125
              ue->current_thread_id[subframe],
126 127 128 129 130 131 132 133
              diff,
              ue->rx_offset,
              clear,
              max_pos,
              max_pos_fil,
              temp,max_val,
              (frame_parms->nb_prefix_samples>>3));
      #endif //DEBUG_PHY
134

135 136
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_ADJUST_SYNCH, VCD_FUNCTION_OUT);
  }
137
}