nr_dmrs_rx.c 8.21 KB
Newer Older
Hongzhi Wang's avatar
Hongzhi Wang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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
 */

/*! \file PHY/NR_REFSIG/nr_dl_dmrs.c
23 24 25 26 27 28 29 30 31
 * \brief Top-level routines for generating DMRS from 38-211
 * \author
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email:
 * \note
 * \warning
 */
Hongzhi Wang's avatar
Hongzhi Wang committed
32 33 34

//#define NR_PBCH_DMRS_LENGTH_DWORD 5
//#define NR_PBCH_DMRS_LENGTH 144
35
//#define DEBUG_PUSCH
Hongzhi Wang's avatar
Hongzhi Wang committed
36 37 38

#include "refsig_defs_ue.h"
#include "PHY/defs_nr_UE.h"
39 40
#include "nr_refsig.h"
#include "PHY/defs_gNB.h"
Hongzhi Wang's avatar
Hongzhi Wang committed
41 42 43 44 45 46 47

/*Table 7.4.1.1.2-1/2 from 38.211 */
int wf1[8][2] = {{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,1}};
int wt1[8][2] = {{1,1},{1,1},{1,1},{1,1},{1,-1},{1,-1},{1,-1},{1,-1}};
int wf2[12][2] = {{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,-1},{1,1},{1,1},{1,1},{1,-1},{1,1},{1,1}};
int wt2[12][2] = {{1,1},{1,1},{1,1},{1,1},{1,1},{1,1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1}};

48
// complex conjugate of mod table
Hongzhi Wang's avatar
Hongzhi Wang committed
49 50
short nr_rx_mod_table[14]  = {0,0,23170,-23170,-23170,23170,23170,-23170,23170,23170,-23170,-23170,-23170,23170};
short nr_rx_nmod_table[14] = {0,0,-23170,23170,23170,-23170,-23170,23170,-23170,-23170,23170,23170,23170,-23170};
51 52


53 54 55 56 57 58
int nr_pusch_dmrs_rx(PHY_VARS_gNB *gNB,
                     unsigned int Ns,
                     unsigned int *nr_gold_pusch,
                     int32_t *output,
                     unsigned short p,
                     unsigned char lp,
59
                     unsigned short nb_pusch_rb,
60
                     uint32_t re_offset,
61
                     uint8_t dmrs_type)
62
{
63
  int8_t w, nb_dmrs;
64 65
  short *mod_table;
  unsigned char idx=0;
66
  int k;
67 68 69
  typedef int array_of_w[2];
  array_of_w *wf;
  array_of_w *wt;
70 71
  wf = (dmrs_type==pusch_dmrs_type1) ? wf1 : wf2;
  wt = (dmrs_type==pusch_dmrs_type1) ? wt1 : wt2;
72

73 74
  int dmrs_offset = re_offset/((dmrs_type==pusch_dmrs_type1)?2:3);

75
  if (dmrs_type > 2)
76
    LOG_E(PHY,"PUSCH DMRS config type %d not valid\n", dmrs_type+1);
77

78
  if ((p>=1000) && (p<((dmrs_type==pusch_dmrs_type1) ? 1008 : 1012))) {
79
      if (gNB->frame_parms.Ncp == NORMAL) {
80 81 82
        nb_dmrs = ((dmrs_type==pusch_dmrs_type1) ? 6:4);
        for (int i=dmrs_offset; i<dmrs_offset+(nb_pusch_rb*nb_dmrs); i++) {
          k = i-dmrs_offset;
83 84 85 86
          w = (wf[p-1000][i&1])*(wt[p-1000][lp]);
          mod_table = (w==1) ? nr_rx_mod_table : nr_rx_nmod_table;

          idx = ((((nr_gold_pusch[(i<<1)>>5])>>((i<<1)&0x1f))&1)<<1) ^ (((nr_gold_pusch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1);
87 88
          ((int16_t*)output)[k<<1] = mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
          ((int16_t*)output)[(k<<1)+1] = mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
89
#ifdef DEBUG_PUSCH
90 91 92 93
          printf("nr_pusch_dmrs_rx dmrs config type %d port %d nb_pusch_rb %d\n", dmrs_type, p, nb_pusch_rb);
          printf("wf[%d] = %d wt[%d]= %d\n", i&1, wf[p-1000][i&1], lp, wt[p-1000][lp]);
          printf("i %d idx %d pusch gold %u b0-b1 %d-%d mod_dmrs %d %d\n", i, idx, nr_gold_pusch[(i<<1)>>5], (((nr_gold_pusch[(i<<1)>>5])>>((i<<1)&0x1f))&1),
          (((nr_gold_pusch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1), ((int16_t*)output)[k<<1], ((int16_t*)output)[(k<<1)+1]);
94
#endif
95

96 97 98 99 100 101 102 103 104 105 106 107
        }
      } else {
        LOG_E(PHY,"extended cp not supported for PUSCH DMRS yet\n");
      }
  } else {
    LOG_E(PHY,"Illegal p %d PUSCH DMRS port\n",p);
  }

  return(0);
}


Hongzhi Wang's avatar
Hongzhi Wang committed
108
int nr_pdsch_dmrs_rx(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
109 110 111 112 113 114
                     unsigned int Ns,
                     unsigned int *nr_gold_pdsch,
                     int32_t *output,
                     unsigned short p,
                     unsigned char lp,
                     unsigned short nb_pdsch_rb)
Hongzhi Wang's avatar
Hongzhi Wang committed
115
{
Hongzhi Wang's avatar
Hongzhi Wang committed
116 117 118
  int8_t w,config_type;
  short *mod_table;
  unsigned char idx=0;
Hongzhi Wang's avatar
Hongzhi Wang committed
119 120 121 122 123

  typedef int array_of_w[2];
  array_of_w *wf;
  array_of_w *wt;

Hongzhi Wang's avatar
Hongzhi Wang committed
124
  config_type = 0; //to be updated by higher layer
Hongzhi Wang's avatar
Hongzhi Wang committed
125 126 127 128 129

  wf = (config_type==0) ? wf1 : wf2;
  wt = (config_type==0) ? wt1 : wt2;

  if (config_type > 1)
130
    LOG_E(PHY,"Bad PDSCH DMRS config type %d\n", config_type);
Hongzhi Wang's avatar
Hongzhi Wang committed
131 132

  if ((p>=1000) && (p<((config_type==0) ? 1008 : 1012))) {
Hongzhi Wang's avatar
Hongzhi Wang committed
133
      if (ue->frame_parms.Ncp == NORMAL) {
Hongzhi Wang's avatar
Hongzhi Wang committed
134

Hongzhi Wang's avatar
Hongzhi Wang committed
135
        for (int i=0; i<nb_pdsch_rb*((config_type==0) ? 6:4); i++) {
Hongzhi Wang's avatar
Hongzhi Wang committed
136

Hongzhi Wang's avatar
Hongzhi Wang committed
137 138
        	w = (wf[p-1000][i&1])*(wt[p-1000][lp]);
        	mod_table = (w==1) ? nr_rx_mod_table : nr_rx_nmod_table;
Hongzhi Wang's avatar
Hongzhi Wang committed
139

Hongzhi Wang's avatar
Hongzhi Wang committed
140 141 142 143 144 145 146 147
        	idx = ((((nr_gold_pdsch[(i<<1)>>5])>>((i<<1)&0x1f))&1)<<1) ^ (((nr_gold_pdsch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1);
    		((int16_t*)output)[i<<1] = mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
    		((int16_t*)output)[(i<<1)+1] = mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
#ifdef DEBUG_PDSCH
    		printf("nr_pdsch_dmrs_rx dmrs config type %d port %d nb_pdsch_rb %d\n", config_type, p, nb_pdsch_rb);
    		printf("wf[%d] = %d wt[%d]= %d\n", i&1, wf[p-1000][i&1], lp, wt[p-1000][lp]);
    		printf("i %d idx %d pdsch gold %u b0-b1 %d-%d mod_dmrs %d %d\n", i, idx, nr_gold_pdsch[(i<<1)>>5], (((nr_gold_pdsch[(i<<1)>>5])>>((i<<1)&0x1f))&1),
    				(((nr_gold_pdsch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1), ((int16_t*)output)[i<<1], ((int16_t*)output)[(i<<1)+1]);
Hongzhi Wang's avatar
Hongzhi Wang committed
148
#endif
Hongzhi Wang's avatar
Hongzhi Wang committed
149 150 151
       	}
      } else {
        LOG_E(PHY,"extended cp not supported for PDSCH DMRS yet\n");
152
      }
Hongzhi Wang's avatar
Hongzhi Wang committed
153 154 155 156 157 158 159
  } else {
    LOG_E(PHY,"Illegal p %d PDSCH DMRS port\n",p);
  }

  return(0);
}

yilmazt's avatar
yilmazt committed
160

Hongzhi Wang's avatar
Hongzhi Wang committed
161
int nr_pdcch_dmrs_rx(PHY_VARS_NR_UE *ue,
yilmazt's avatar
yilmazt committed
162 163 164 165 166 167
                     uint8_t eNB_offset,
                     unsigned int Ns,
                     unsigned int *nr_gold_pdcch,
                     int32_t *output,
                     unsigned short p,
                     unsigned short nb_rb_coreset)
Hongzhi Wang's avatar
Hongzhi Wang committed
168
{
169 170 171
  uint8_t idx=0;
  //uint8_t pdcch_rb_offset =0;
  //nr_gold_pdcch += ((int)floor(ue->frame_parms.ssb_start_subcarrier/12)+pdcch_rb_offset)*3/32;
Hongzhi Wang's avatar
Hongzhi Wang committed
172

173 174 175 176 177
  if (p==2000) {
    for (int i=0; i<((nb_rb_coreset*6)>>1); i++) {
      idx = ((((nr_gold_pdcch[(i<<1)>>5])>>((i<<1)&0x1f))&1)<<1) ^ (((nr_gold_pdcch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1);
      ((int16_t*)output)[i<<1] = nr_rx_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
      ((int16_t*)output)[(i<<1)+1] = nr_rx_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
Hongzhi Wang's avatar
Hongzhi Wang committed
178
#ifdef DEBUG_PDCCH
179
      if (i<8)
yilmazt's avatar
yilmazt committed
180 181
        printf("i %d idx %d pdcch gold %u b0-b1 %d-%d mod_dmrs %d %d addr %p\n", i, idx, nr_gold_pdcch[(i<<1)>>5], (((nr_gold_pdcch[(i<<1)>>5])>>((i<<1)&0x1f))&1),
               (((nr_gold_pdcch[((i<<1)+1)>>5])>>(((i<<1)+1)&0x1f))&1), ((int16_t*)output)[i<<1], ((int16_t*)output)[(i<<1)+1],&output[0]);
Hongzhi Wang's avatar
Hongzhi Wang committed
182
#endif
183 184
    }
  }
Hongzhi Wang's avatar
Hongzhi Wang committed
185

186
  return(0);
Hongzhi Wang's avatar
Hongzhi Wang committed
187 188
}

yilmazt's avatar
yilmazt committed
189 190 191 192

int nr_pbch_dmrs_rx(int symbol,
                    unsigned int *nr_gold_pbch,
                    int32_t *output)
Hongzhi Wang's avatar
Hongzhi Wang committed
193
{
Raymond Knopp's avatar
Raymond Knopp committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  int m,m0,m1;
  uint8_t idx=0;
  AssertFatal(symbol>=0 && symbol <3,"illegal symbol %d\n",symbol);
  if (symbol == 0) {
    m0=0;
    m1=60;
  }
  else if (symbol == 1) {
    m0=60;
    m1=84;
  }
  else {
    m0=84;
    m1=144;
  }
209
  //    printf("Generating pilots symbol %d, m0 %d, m1 %d\n",symbol,m0,m1);
Raymond Knopp's avatar
Raymond Knopp committed
210 211 212 213 214 215
  /// QPSK modulation
  for (m=m0; m<m1; m++) {
    idx = ((((nr_gold_pbch[(m<<1)>>5])>>((m<<1)&0x1f))&1)<<1) ^ (((nr_gold_pbch[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1);
    ((int16_t*)output)[(m-m0)<<1] = nr_rx_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
    ((int16_t*)output)[((m-m0)<<1)+1] = nr_rx_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
    
Hongzhi Wang's avatar
Hongzhi Wang committed
216
#ifdef DEBUG_PBCH
Raymond Knopp's avatar
Raymond Knopp committed
217 218
    if (m<16)
      {printf("nr_gold_pbch[(m<<1)>>5] %x\n",nr_gold_pbch[(m<<1)>>5]);
hongzhi wang's avatar
hongzhi wang committed
219
	printf("m %d  output %d %d addr %p\n", m, ((int16_t*)output)[m<<1], ((int16_t*)output)[(m<<1)+1],&output[0]);
Raymond Knopp's avatar
Raymond Knopp committed
220
      }
Hongzhi Wang's avatar
Hongzhi Wang committed
221
#endif
Raymond Knopp's avatar
Raymond Knopp committed
222 223
  }
  
Hongzhi Wang's avatar
Hongzhi Wang committed
224 225
  return(0);
}