drs_modulation.c 6.88 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 23 24 25 26 27 28 29 30 31
/*! \file PHY/LTE_TRANSPORT/drs_modulation.c
* \brief Top-level routines for generating the Demodulation Reference Signals from 36-211, V8.6 2009-03
* \author R. Knopp, F. Kaltenberger, A. Bhamri
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,ankit.bhamri@eurecom.fr
* \note
* \warning
*/
32 33
#include "PHY/defs_UE.h"
#include "PHY/phy_extern_ue.h"
34
#include "PHY/sse_intrin.h"
35 36
#include "transport_proto_ue.h"

37 38
//#define DEBUG_DRS

39
int generate_drs_pusch(PHY_VARS_UE *ue,
40
		       UE_rxtx_proc_t *proc,
41 42 43 44 45 46 47
                       uint8_t eNB_id,
                       short amp,
                       unsigned int subframe,
                       unsigned int first_rb,
                       unsigned int nb_rb,
                       uint8_t ant)
{
48

49 50
  uint16_t k,l,Msc_RS,Msc_RS_idx,rb,drs_offset;
  uint16_t * Msc_idx_ptr;
51 52
  int subframe_offset,re_offset,symbol_offset;

53 54
  //uint32_t phase_shift; // phase shift for cyclic delay in DM RS
  //uint8_t alpha_ind;
55

56 57
  int16_t alpha_re[12] = {32767, 28377, 16383,     0,-16384,  -28378,-32768,-28378,-16384,    -1, 16383, 28377};
  int16_t alpha_im[12] = {0,     16383, 28377, 32767, 28377,   16383,     0,-16384,-28378,-32768,-28378,-16384};
58

59
  uint8_t cyclic_shift,cyclic_shift0,cyclic_shift1;
60 61
  LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  int32_t *txdataF = ue->common_vars.txdataF[ant];
62 63 64 65 66 67
  uint32_t u,v,alpha_ind;
  uint32_t u0=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.grouphop[subframe<<1];
  uint32_t u1=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.grouphop[1+(subframe<<1)];
  uint32_t v0=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.seqhop[subframe<<1];
  uint32_t v1=frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.seqhop[1+(subframe<<1)];
  int32_t ref_re,ref_im;
68
  uint8_t harq_pid = subframe2harq_pid(frame_parms,proc->frame_tx,subframe);
69 70

  cyclic_shift0 = (frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift +
71 72 73
                   ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2 +
                   frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe<<1]+
                   ((ue->ulsch[0]->cooperation_flag==2)?10:0)+
74
                   ant*6) % 12;
75
  //  printf("PUSCH.cyclicShift %d, n_DMRS2 %d, nPRS %d\n",frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift,ue->ulsch[eNB_id]->n_DMRS2,ue->lte_frame_parms.pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[subframe<<1]);
76
  cyclic_shift1 = (frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift +
77 78 79
                   ue->ulsch[eNB_id]->harq_processes[harq_pid]->n_DMRS2 +
                   frame_parms->pusch_config_common.ul_ReferenceSignalsPUSCH.nPRS[(subframe<<1)+1]+
                   ((ue->ulsch[0]->cooperation_flag==2)?10:0)+
80
                   ant*6) % 12;
81 82 83

  //       cyclic_shift0 = 0;
  //        cyclic_shift1 = 0;
84
  Msc_RS = 12*nb_rb;
85

86
  Msc_idx_ptr = (uint16_t*) bsearch(&Msc_RS, dftsizes, 34, sizeof(uint16_t), compareints);
87

88 89 90
  if (Msc_idx_ptr)
    Msc_RS_idx = Msc_idx_ptr - dftsizes;
  else {
91
    LOG_I(PHY,"generate_drs_pusch: index for Msc_RS=%d not found\n",Msc_RS);
92 93
    return(-1);
  }
94 95 96

  for (l = (3 - frame_parms->Ncp),u=u0,v=v0,cyclic_shift=cyclic_shift0;
       l<frame_parms->symbols_per_tti;
97 98
       l += (7 - frame_parms->Ncp),u=u1,v=v1,cyclic_shift=cyclic_shift1) {

Cedric Roux's avatar
Cedric Roux committed
99
    drs_offset = 0;
100 101 102
#ifdef DEBUG_DRS
    printf("drs_modulation: Msc_RS = %d, Msc_RS_idx = %d, u=%d,v=%d\n",Msc_RS, Msc_RS_idx,u,v);
#endif
103 104 105 106 107


    re_offset = frame_parms->first_carrier_offset;
    subframe_offset = subframe*frame_parms->symbols_per_tti*frame_parms->ofdm_symbol_size;
    symbol_offset = subframe_offset + frame_parms->ofdm_symbol_size*l;
108

109

110
#ifdef DEBUG_DRS
111
    printf("generate_drs_pusch: symbol_offset %d, subframe offset %d, cyclic shift %d\n",symbol_offset,subframe_offset,cyclic_shift);
112 113
#endif
    alpha_ind = 0;
114 115

    for (rb=0; rb<frame_parms->N_RB_UL; rb++) {
116 117 118

      if ((rb >= first_rb) && (rb<(first_rb+nb_rb))) {

119
#ifdef DEBUG_DRS
120
        printf("generate_drs_pusch: doing RB %d, re_offset=%d, drs_offset=%d,cyclic shift %d\n",rb,re_offset,drs_offset,cyclic_shift);
121 122
#endif

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        for (k=0; k<12; k++) {
          ref_re = (int32_t) ul_ref_sigs[u][v][Msc_RS_idx][drs_offset<<1];
          ref_im = (int32_t) ul_ref_sigs[u][v][Msc_RS_idx][(drs_offset<<1)+1];

          ((int16_t*) txdataF)[2*(symbol_offset + re_offset)]   = (int16_t) (((ref_re*alpha_re[alpha_ind]) -
              (ref_im*alpha_im[alpha_ind]))>>15);
          ((int16_t*) txdataF)[2*(symbol_offset + re_offset)+1] = (int16_t) (((ref_re*alpha_im[alpha_ind]) +
              (ref_im*alpha_re[alpha_ind]))>>15);
          ((short*) txdataF)[2*(symbol_offset + re_offset)]   = (short) ((((short*) txdataF)[2*(symbol_offset + re_offset)]*(int32_t)amp)>>15);
          ((short*) txdataF)[2*(symbol_offset + re_offset)+1] = (short) ((((short*) txdataF)[2*(symbol_offset + re_offset)+1]*(int32_t)amp)>>15);


          alpha_ind = (alpha_ind + cyclic_shift);

          if (alpha_ind > 11)
            alpha_ind-=12;

140
#ifdef DEBUG_DRS
141
          printf("symbol_offset %d, alpha_ind %d , re_offset %d : (%d,%d)\n",
142 143 144 145 146 147
              symbol_offset,
              alpha_ind,
              re_offset,
              ((short*) txdataF)[2*(symbol_offset + re_offset)],
              ((short*) txdataF)[2*(symbol_offset + re_offset)+1]);

148
#endif  // DEBUG_DRS
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
          re_offset++;
          drs_offset++;

          if (re_offset >= frame_parms->ofdm_symbol_size)
            re_offset = 0;
        }

      } else {
        re_offset+=12; // go to next RB

        // check if we crossed the symbol boundary and skip DC

        if (re_offset >= frame_parms->ofdm_symbol_size) {
          if (frame_parms->N_RB_DL&1)  // odd number of RBs
            re_offset=6;
          else                         // even number of RBs (doesn't straddle DC)
            re_offset=0;
        }

168

169 170 171
      }
    }
  }
172

173 174 175
  return(0);
}