nr_gold_ue.c 4.81 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 23 24 25 26 27
/*
 * 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.1  (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
 */

#include "refsig_defs_ue.h"

void nr_gold_pbch(PHY_VARS_NR_UE* ue)
{

  unsigned int n, x1, x2;
Guy De Souza's avatar
Guy De Souza committed
28
  unsigned int Nid, i_ssb, i_ssb2;
Hongzhi Wang's avatar
Hongzhi Wang committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  unsigned char Lmax, l, n_hf, N_hf;

  Nid = ue->frame_parms.Nid_cell;

  Lmax = 8; //(fp->dl_CarrierFreq < 3e9)? 4:8;
  N_hf = (Lmax == 4)? 2:1;

  for (n_hf = 0; n_hf < N_hf; n_hf++) {

    for (l = 0; l < Lmax ; l++) {
      i_ssb = l & (Lmax-1);
      i_ssb2 = (i_ssb<<2) + n_hf;

      x1 = 1 + (1<<31);
      x2 = (1<<11) * (i_ssb2 + 1) * ((Nid>>2) + 1) + (1<<6) * (i_ssb2 + 1) + (Nid&3);
      x2 = x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);

      // skip first 50 double words (1600 bits)
      for (n = 1; n < 50; n++) {
        x1 = (x1>>1) ^ (x1>>4);
        x1 = x1 ^ (x1<<31) ^ (x1<<28);
        x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
        x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
      }

      for (n=0; n<NR_PBCH_DMRS_LENGTH_DWORD; n++) {
        x1 = (x1>>1) ^ (x1>>4);
        x1 = x1 ^ (x1<<31) ^ (x1<<28);
        x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
        x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
        ue->nr_gold_pbch[n_hf][l][n] = x1 ^ x2;
      }

    }
  }

}

Hongzhi Wang's avatar
Hongzhi Wang committed
67
void nr_gold_pdcch(PHY_VARS_NR_UE* ue,unsigned short n_idDMRS, unsigned short length_dmrs)
68 69 70 71 72 73 74 75 76
{

  unsigned char ns,l;
  unsigned int n,x1,x2,x2tmp0;
  unsigned int nid;

    if (n_idDMRS)
      nid = n_idDMRS;
    else
Hongzhi Wang's avatar
Hongzhi Wang committed
77
      nid = ue->frame_parms.Nid_cell;
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    for (ns=0; ns<20; ns++) {

      for (l=0; l<length_dmrs; l++) {

    	x2tmp0 = ((14*ns+l+1)*((nid<<1)+1))<<17;
        x2 = (x2tmp0+(nid<<1))%(1<<31);  //cinit

        x1 = 1+ (1<<31);
        x2=x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);

        // skip first 50 double words (1600 bits)
        for (n=1; n<50; n++) {
          x1 = (x1>>1) ^ (x1>>4);
          x1 = x1 ^ (x1<<31) ^ (x1<<28);
          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
            //printf("x1 : %x, x2 : %x\n",x1,x2);
        }

Hongzhi Wang's avatar
Hongzhi Wang committed
98
        for (n=0; n<52; n++) {
99 100 101 102
          x1 = (x1>>1) ^ (x1>>4);
          x1 = x1 ^ (x1<<31) ^ (x1<<28);
          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
103
          ue->nr_gold_pdcch[0][ns][l][n] = x1^x2;
104 105 106 107 108 109
            //printf("n=%d : c %x\n",n,x1^x2);
        }
      }
    }
}

Hongzhi Wang's avatar
Hongzhi Wang committed
110
void nr_gold_pdsch(PHY_VARS_NR_UE* ue,unsigned short lbar,unsigned short *n_idDMRS, unsigned short length_dmrs)
Hongzhi Wang's avatar
Hongzhi Wang committed
111 112 113
{

  unsigned char ns,l;
Hongzhi Wang's avatar
Hongzhi Wang committed
114
  unsigned int n,x1,x2,x2tmp0;
Hongzhi Wang's avatar
Hongzhi Wang committed
115 116 117 118
  int nscid;
  unsigned int nid;

  /// to be updated from higher layer
Hongzhi Wang's avatar
Hongzhi Wang committed
119
  //unsigned short lbar = 0;
Hongzhi Wang's avatar
Hongzhi Wang committed
120 121 122 123 124

  for (nscid=0; nscid<2; nscid++) {
    if (n_idDMRS)
      nid = n_idDMRS[nscid];
    else
Hongzhi Wang's avatar
Hongzhi Wang committed
125
      nid = ue->frame_parms.Nid_cell;
hongzhi wang's avatar
hongzhi wang committed
126 127
      
      //printf("gold pdsch nid %d lbar %d\n",nid,lbar);
Hongzhi Wang's avatar
Hongzhi Wang committed
128 129 130 131 132 133

    for (ns=0; ns<20; ns++) {

      for (l=0; l<length_dmrs; l++) {

    	x2tmp0 = ((14*ns+(lbar+l)+1)*((nid<<1)+1))<<17;
134
        x2 = (x2tmp0+(nid<<1)+nscid)%(1<<31);  //cinit
hongzhi wang's avatar
hongzhi wang committed
135 136
        
                //printf("ns %d gold pdsch x2 %d\n",ns,x2);
Hongzhi Wang's avatar
Hongzhi Wang committed
137 138 139 140 141 142 143 144 145 146 147 148 149

        x1 = 1+ (1<<31);
        x2=x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);

        // skip first 50 double words (1600 bits)
        for (n=1; n<50; n++) {
          x1 = (x1>>1) ^ (x1>>4);
          x1 = x1 ^ (x1<<31) ^ (x1<<28);
          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
            //printf("x1 : %x, x2 : %x\n",x1,x2);
        }

Hongzhi Wang's avatar
Hongzhi Wang committed
150
        for (n=0; n<52; n++) {
Hongzhi Wang's avatar
Hongzhi Wang committed
151 152 153 154
          x1 = (x1>>1) ^ (x1>>4);
          x1 = x1 ^ (x1<<31) ^ (x1<<28);
          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
155
          ue->nr_gold_pdsch[nscid][ns][l][n] = x1^x2;
hongzhi wang's avatar
hongzhi wang committed
156
            // if ((ns==2)&&(l==0))
Hongzhi Wang's avatar
Hongzhi Wang committed
157 158 159 160 161 162 163
            //printf("n=%d : c %x\n",n,x1^x2);
        }

      }
    }
  }
}