pcfich.c 5.12 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/pcfich.c
* \brief Top-level routines for generating and decoding  the PCFICH/CFI physical/transport channel V8.6 2009-03
* \author R. Knopp
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr
* \note
* \warning
*/
32 33
#include "PHY/impl_defs_top.h"
#include "PHY/defs_eNB.h"
knopp's avatar
knopp committed
34
#include "PHY/LTE_REFSIG/lte_refsig.h"
35 36

//#define DEBUG_PCFICH
37
extern uint8_t pcfich_b[4][32];
38 39 40


void pcfich_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
41 42 43 44
                       uint8_t subframe,
                       uint8_t *b,
                       uint8_t *bt)
{
45 46 47
  uint32_t i;
  uint8_t reset;
  uint32_t x1, x2, s=0;
48 49 50 51

  reset = 1;
  // x1 is set in lte_gold_generic
  x2 = ((((2*frame_parms->Nid_cell)+1)*(1+subframe))<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.7.1
52

53 54 55 56 57 58 59 60 61 62 63
  for (i=0; i<32; i++) {
    if ((i&0x1f)==0) {
      s = lte_gold_generic(&x1, &x2, reset);
      //printf("lte_gold[%d]=%x\n",i,s);
      reset = 0;
    }

    bt[i] = (b[i]&1) ^ ((s>>(i&0x1f))&1);
  }
}

64

65

66
void generate_pcfich(uint8_t num_pdcch_symbols,
67 68
                     int16_t amp,
                     LTE_DL_FRAME_PARMS *frame_parms,
69
                     int32_t **txdataF,
70 71
                     uint8_t subframe)
{
72

73
  uint8_t pcfich_bt[32],nsymb,pcfich_quad;
74
  int32_t pcfich_d[2][16];
75 76 77 78
  uint8_t i;
  uint32_t symbol_offset,m,re_offset,reg_offset;
  int16_t gain_lin_QPSK;
  uint16_t *pcfich_reg = frame_parms->pcfich_reg;
79 80 81

  int nushiftmod3 = frame_parms->nushift%3;
#ifdef DEBUG_PCFICH
82 83
  LOG_D(PHY,"Generating PCFICH in subfrmae %d for %d PDCCH symbols, AMP %d, p %d, Ncp %d\n",
	subframe,num_pdcch_symbols,amp,frame_parms->nb_antenna_ports_eNB,frame_parms->Ncp);
84 85 86
#endif

  // scrambling
87
  if ((num_pdcch_symbols>0) && (num_pdcch_symbols<4))
88 89 90
    pcfich_scrambling(frame_parms,subframe,pcfich_b[num_pdcch_symbols-1],pcfich_bt);

  // modulation
91
  if (frame_parms->nb_antenna_ports_eNB==1)
92
    gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
93
  else
94
    gain_lin_QPSK = amp/2;
95

96
  if (frame_parms->nb_antenna_ports_eNB==1) { // SISO
97

98
    for (i=0; i<16; i++) {
99 100 101 102
      ((int16_t*)(&(pcfich_d[0][i])))[0]   = ((pcfich_bt[2*i] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
      ((int16_t*)(&(pcfich_d[1][i])))[0]   = ((pcfich_bt[2*i] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
      ((int16_t*)(&(pcfich_d[0][i])))[1]   = ((pcfich_bt[2*i+1] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
      ((int16_t*)(&(pcfich_d[1][i])))[1]   = ((pcfich_bt[2*i+1] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
103
    }
104 105
  } else { // ALAMOUTI
    for (i=0; i<16; i+=2) {
106
      // first antenna position n -> x0
107 108
      ((int16_t*)(&(pcfich_d[0][i])))[0]   = ((pcfich_bt[2*i] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
      ((int16_t*)(&(pcfich_d[0][i])))[1]   = ((pcfich_bt[2*i+1] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
109
      // second antenna position n -> -x1*
110 111
      ((int16_t*)(&(pcfich_d[1][i])))[0]   = ((pcfich_bt[2*i+2] == 1) ? gain_lin_QPSK : -gain_lin_QPSK);
      ((int16_t*)(&(pcfich_d[1][i])))[1]   = ((pcfich_bt[2*i+3] == 1) ? -gain_lin_QPSK : gain_lin_QPSK);
112
      // fill in the rest of the ALAMOUTI precoding
113 114 115 116
      ((int16_t*)&pcfich_d[0][i+1])[0] = -((int16_t*)&pcfich_d[1][i])[0];
      ((int16_t*)&pcfich_d[0][i+1])[1] =  ((int16_t*)&pcfich_d[1][i])[1];
      ((int16_t*)&pcfich_d[1][i+1])[0] =  ((int16_t*)&pcfich_d[0][i])[0];
      ((int16_t*)&pcfich_d[1][i+1])[1] = -((int16_t*)&pcfich_d[0][i])[1];
117 118 119


    }
120 121 122 123 124
  }


  // mapping
  nsymb = (frame_parms->Ncp==0) ? 14:12;
125

126
  symbol_offset = (uint32_t)frame_parms->ofdm_symbol_size*(subframe*nsymb);
127 128 129 130
  re_offset = frame_parms->first_carrier_offset;

  // loop over 4 quadruplets and lookup REGs
  m=0;
131 132

  for (pcfich_quad=0; pcfich_quad<4; pcfich_quad++) {
133
    reg_offset = re_offset+((uint16_t)pcfich_reg[pcfich_quad]*6);
134

135 136
    if (reg_offset>=frame_parms->ofdm_symbol_size)
      reg_offset=1 + reg_offset-frame_parms->ofdm_symbol_size;
137 138

    for (i=0; i<6; i++) {
139
      if ((i!=nushiftmod3)&&(i!=(nushiftmod3+3))) {
140 141
        txdataF[0][symbol_offset+reg_offset+i] = pcfich_d[0][m];

Xiwen JIANG's avatar
Xiwen JIANG committed
142
        if (frame_parms->nb_antenna_ports_eNB>1)
143 144 145
          txdataF[1][symbol_offset+reg_offset+i] = pcfich_d[1][m];

        m++;
146 147 148 149 150 151 152
      }
    }
  }

}