lte_gold.c 6.48 KB
Newer Older
ghaddab's avatar
ghaddab committed
1
/*******************************************************************************
2
    OpenAirInterface
ghaddab's avatar
ghaddab committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.


    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
17 18
    along with OpenAirInterface.The full GNU General Public License is
   included in this distribution in the file called "COPYING". If not,
ghaddab's avatar
ghaddab committed
19 20 21 22 23
   see <http://www.gnu.org/licenses/>.

  Contact Information
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
24
  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
ghaddab's avatar
ghaddab committed
27 28

 *******************************************************************************/
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#include "defs.h"


/* c(n) = x1(n+Nc) + x2(n+Nc) mod 2
x1(n+31) = (x1(n+3)+x1(n))mod 2
x2(n+31) = (x2(n+3)+x2(n+2)+x2(n+1)+x2(n))mod 2
x1(0)=1,x1(n)=0,n=1...30
x2 <=> cinit = sum_{i=0}^{30} x2(i)2^i

equivalent
x1(n) = x1(n-28) + x1(n-31)
x2(n) = x2(n-28) + x2(n-29) + x2(n-30) + x2(n-31)
x1(0)=1,x1(1)=0,...x1(30)=0,x1(31)=1
x2 <=> cinit, x2(31) = x2(3)+x2(2)+x2(1)+x2(0)

N_RB^{max,DL}=110
c_init = 2^1 * (7(n_s + 1) + l + 1)*(2N_{ID}^{cell} + 1) + 2*N_{ID}^{cell} + N_CP
N_{ID}^{cell = 0..503
*/

//unsigned int lte_gold_table[3][20][2][14];  // need 55 bytes for sequence
// slot index x pilot within slot x sequence

52 53
void lte_gold(LTE_DL_FRAME_PARMS *frame_parms,uint32_t lte_gold_table[20][2][14],uint16_t Nid_cell)
{
54 55 56 57

  unsigned char ns,l,Ncp=1-frame_parms->Ncp;
  unsigned int n,x1,x2;//,x1tmp,x2tmp;

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

60 61 62 63
    for (l=0; l<2; l++) {

      x2 = Ncp +
           (Nid_cell<<1) +
64
	(((1+(Nid_cell<<1))*(1 + (((frame_parms->Ncp==0)?4:3)*l) + (7*(1+ns))))<<10); //cinit
65 66 67 68
      //x2 = frame_parms->Ncp + (Nid_cell<<1) + (1+(Nid_cell<<1))*(1 + (3*l) + (7*(1+ns))); //cinit
      //n = 0
      x1 = 1+ (1<<31);
      x2=x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);
69

70
      // skip first 50 double words (1600 bits)
71 72 73 74 75
      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);
76
      }
77 78 79 80 81 82 83

      for (n=0; n<14; 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);
        lte_gold_table[ns][l][n] = x1^x2;
84 85 86 87 88 89 90
      }

    }

  }
}

91 92
void lte_gold_ue_spec(LTE_DL_FRAME_PARMS *frame_parms,uint32_t lte_gold_uespec_table[2][20][2][21],uint16_t Nid_cell, uint16_t *n_idDMRS)
{
Raymond Knopp's avatar
 
Raymond Knopp committed
93 94 95 96 97

  unsigned char ns,l;
  unsigned int n,x1,x2;//,x1tmp,x2tmp;
  int nscid;
  int nid;
98 99

  for (nscid=0; nscid<2; nscid++) {
Raymond Knopp's avatar
 
Raymond Knopp committed
100 101 102 103
    if (n_idDMRS)
      nid = n_idDMRS[nscid];
    else
      nid = Nid_cell;
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

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

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


        x2 = ((((ns>>1)+1)*((nid<<1)+1))<<16) + nscid;
        //x2 = frame_parms->Ncp + (Nid_cell<<1) + (1+(Nid_cell<<1))*(1 + (3*l) + (7*(1+ns))); //cinit
        //n = 0
        //      printf("cinit (ns %d, l %d) => %d\n",ns,l,x2);
        x1 = 1+ (1<<31);
        x2=x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);

        // skip first 50 double words (1600 bits)
        //printf("n=0 : x1 %x, x2 %x\n",x1,x2);
        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);
        }

        for (n=0; n<14; 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);
          lte_gold_uespec_table[nscid][ns][l][n] = x1^x2;
          //  printf("n=%d : c %x\n",n,x1^x2);
        }

Raymond Knopp's avatar
 
Raymond Knopp committed
136 137 138 139 140
      }
    }
  }
}

141
void lte_gold_ue_spec_port5(uint32_t lte_gold_uespec_port5_table[20][38],uint16_t Nid_cell, uint16_t n_rnti)
142 143
{

Xiwen JIANG's avatar
Xiwen JIANG committed
144
  unsigned char ns;
145 146 147 148 149
  unsigned int n,x1,x2;


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

150 151 152
    x2 = ((((ns>>1)+1)*((Nid_cell<<1)+1))<<16) + n_rnti;
    //x2 = frame_parms->Ncp + (Nid_cell<<1) + (1+(Nid_cell<<1))*(1 + (3*l) + (7*(1+ns))); //cinit
    //n = 0
Xiwen JIANG's avatar
Xiwen JIANG committed
153
    //printf("cinit (ns %d, l %d) => %d\n",ns,l,x2);
154 155
    x1 = 1+ (1<<31);
    x2=x2 ^ ((x2 ^ (x2>>1) ^ (x2>>2) ^ (x2>>3))<<31);
156

Xiwen JIANG's avatar
Xiwen JIANG committed
157
    //skip first 50 double words (1600 bits)
158 159 160 161 162 163
    //printf("n=0 : x1 %x, x2 %x\n",x1,x2);
    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);
Xiwen JIANG's avatar
Xiwen JIANG committed
164
      //printf("x1 : %x, x2 : %x\n",x1,x2);
165
    }
166

167 168 169 170 171 172
    for (n=0; n<38; 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);
      lte_gold_uespec_port5_table[ns][n] = x1^x2;
Xiwen JIANG's avatar
Xiwen JIANG committed
173
      //printf("n=%d : c %x\n",n,x1^x2);
174
    }
175

176 177 178
  }
}

179
/*! \brief gold sequenquence generator
180
\param x1
181 182 183 184
\param x2 this should be set to c_init if reset=1
\param reset resets the generator
\return 32 bits of the gold sequence
*/
185
unsigned int lte_gold_generic(unsigned int *x1, unsigned int *x2, unsigned char reset)
186 187
{
  int n;
188

189 190 191
  if (reset) {
    *x1 = 1+ (1<<31);
    *x2=*x2 ^ ((*x2 ^ (*x2>>1) ^ (*x2>>2) ^ (*x2>>3))<<31);
192

193 194
    // skip first 50 double words (1600 bits)
    //      printf("n=0 : x1 %x, x2 %x\n",x1,x2);
195
    for (n=1; n<50; n++) {
196 197 198 199 200 201
      *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);
    }
  }
202

203 204 205 206 207
  *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);
  return(*x1^*x2);
208 209
  //  printf("n=%d : c %x\n",n,x1^x2);

210 211 212 213 214
}



#ifdef LTE_GOLD_MAIN
215 216
main()
{
217 218 219 220 221 222

  lte_gold(423,0);

}
#endif