nr_gold.c 4.94 KB
Newer Older
Guy De Souza's avatar
Guy De Souza committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

22
#include "nr_refsig.h"
Guy De Souza's avatar
Guy De Souza committed
23 24 25

void nr_init_pbch_dmrs(PHY_VARS_gNB* gNB)
{
26
  unsigned int x1, x2;
27
  uint16_t Nid, i_ssb, i_ssb2;
Guy De Souza's avatar
Guy De Souza committed
28
  unsigned char Lmax, l, n_hf, N_hf;
29
  nfapi_nr_config_request_scf_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
30
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
Guy De Souza's avatar
Guy De Souza committed
31
  uint8_t reset;
Guy De Souza's avatar
Guy De Souza committed
32

33
  Nid = cfg->cell_config.phy_cell_id.value;
Guy De Souza's avatar
Guy De Souza committed
34

35
  Lmax = fp->Lmax;
Guy De Souza's avatar
Guy De Souza committed
36 37 38 39
  N_hf = (Lmax == 4)? 2:1;

  for (n_hf = 0; n_hf < N_hf; n_hf++) {
    for (l = 0; l < Lmax ; l++) {
40
      i_ssb = l & (Lmax-1);
41
      i_ssb2 = i_ssb + (n_hf<<2);
Guy De Souza's avatar
Guy De Souza committed
42

Guy De Souza's avatar
Guy De Souza committed
43
      reset = 1;
Guy De Souza's avatar
Guy De Souza committed
44 45
      x2 = (1<<11) * (i_ssb2 + 1) * ((Nid>>2) + 1) + (1<<6) * (i_ssb2 + 1) + (Nid&3);

46 47 48
      for (uint8_t n=0; n<NR_PBCH_DMRS_LENGTH_DWORD; n++) {
        gNB->nr_gold_pbch_dmrs[n_hf][l][n] = lte_gold_generic(&x1, &x2, reset);
        reset = 0;
Guy De Souza's avatar
Guy De Souza committed
49 50 51 52 53 54
      }

    }
  }

}
55 56 57 58

void nr_init_pdcch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid)
{

Guy De Souza's avatar
Guy De Souza committed
59
  uint32_t x1, x2;
Guy De Souza's avatar
Guy De Souza committed
60
  uint8_t reset;
61 62 63
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
  uint32_t ***pdcch_dmrs = gNB->nr_gold_pdcch_dmrs;

Guy De Souza's avatar
Guy De Souza committed
64 65
  for (uint8_t slot=0; slot<fp->slots_per_frame; slot++) {
    for (uint8_t symb=0; symb<fp->symbols_per_slot; symb++) {
66

Guy De Souza's avatar
Guy De Souza committed
67
      reset = 1;
68
      x2 = ((1<<17) * (14*slot+symb+1) * ((Nid<<1)+1)) + (Nid<<1);
69

Guy De Souza's avatar
Guy De Souza committed
70
      for (uint32_t n=0; n<NR_MAX_PDCCH_DMRS_INIT_LENGTH_DWORD; n++) {
71 72 73 74 75 76 77
        pdcch_dmrs[slot][symb][n] = lte_gold_generic(&x1, &x2, reset);
        reset = 0;
      }
    }  
  }

}
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
78 79 80 81 82 83


void nr_init_pdsch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid)
{
  
  uint32_t x1, x2;
Khalid Ahmed's avatar
Khalid Ahmed committed
84
  uint8_t reset, q;
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
85
  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
Guy De Souza's avatar
Guy De Souza committed
86 87 88 89
  uint32_t ****pdsch_dmrs = gNB->nr_gold_pdsch_dmrs;

  uint16_t N_n_scid[NR_MAX_NB_CODEWORDS]={Nid, Nid}; // Not correct, appropriate scrambling IDs have to be updated to support DCI 1_1
  uint8_t n_scid=0; // again works only for 1_0
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
90 91
  for (uint8_t slot=0; slot<fp->slots_per_frame; slot++) {
    for (uint8_t symb=0; symb<fp->symbols_per_slot; symb++) {
Guy De Souza's avatar
Guy De Souza committed
92 93
        reset = 1;
        x2 = ((1<<17) * (fp->symbols_per_slot*slot+symb+1) * ((N_n_scid[n_scid]<<1)+1) +((N_n_scid[n_scid]<<1)+n_scid));
94
	LOG_D(PHY,"DMRS slot %d, symb %d x2 %x\n",slot,symb,x2);
Guy De Souza's avatar
Guy De Souza committed
95
        for (uint32_t n=0; n<NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD; n++) {
Khalid Ahmed's avatar
Khalid Ahmed committed
96
          pdsch_dmrs[slot][symb][0][n] = lte_gold_generic(&x1, &x2, reset);
Guy De Souza's avatar
Guy De Souza committed
97
          reset = 0;
Khalid Ahmed's avatar
Khalid Ahmed committed
98
        }
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
99

Khalid Ahmed's avatar
Khalid Ahmed committed
100 101 102 103
        for (q = 1; q < NR_MAX_NB_CODEWORDS; q++)
          memcpy(pdsch_dmrs[slot][symb][q],pdsch_dmrs[slot][symb][0],sizeof(uint32_t)*NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD);
    }
  }
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
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 136 137 138 139 140 141 142 143 144 145 146


void nr_gold_pusch(PHY_VARS_gNB* gNB, unsigned short lbar,unsigned short *n_idDMRS, unsigned short length_dmrs)
{

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

  /// to be updated from higher layer
  //unsigned short lbar = 0;

  for (nscid=0; nscid<2; nscid++) {
    if (n_idDMRS)
      nid = n_idDMRS[nscid];
    else
      nid = gNB->frame_parms.Nid_cell;
      
      //printf("gold pdsch nid %d lbar %d\n",nid,lbar);

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

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

      x2tmp0 = ((14*ns+(lbar+l)+1)*((nid<<1)+1))<<17;
        x2 = (x2tmp0+(nid<<1)+nscid)%(1<<31);  //cinit
        
                //printf("ns %d gold pdsch x2 %d\n",ns,x2);

        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);
        }

147
        for (n=0; n<NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD; n++) {
148 149 150 151 152 153 154 155 156 157 158 159
          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);
          gNB->nr_gold_pusch[nscid][ns][l][n] = x1^x2;
            // if ((ns==2)&&(l==0))
            //printf("n=%d : c %x\n",n,x1^x2);
        }

      }
    }
  }
160
}