edci.c 6.49 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 22 23 24 25 26 27 28 29 30 31 32 33 34
 * 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/LTE_TRANSPORT/dci.c
* \brief Implements PDCCH physical channel TX/RX procedures (36.211) and DCI encoding/decoding (36.212/36.213). Current LTE compliance V8.6 2009-03.
* \author R. Knopp
* \date 2011
* \version 0.1
* \company Eurecom
* \email: knopp@eurecom.fr
* \note
* \warning
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
35 36 37 38
#include "PHY/defs_eNB.h"
#include "PHY/phy_extern.h"
#include "SCHED/sched_eNB.h"
#include "SIMULATION/TOOLS/sim.h" // for taus 
39
#include "PHY/sse_intrin.h"
40 41
#include "transport_proto.h"
#include "transport_common_proto.h"
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
#include "assertions.h" 
#include "T.h"
#include "UTIL/LOG/log.h"

//#define DEBUG_DCI_ENCODING 1
//#define DEBUG_DCI_DECODING 1
//#define DEBUG_PHY

#ifdef Rel14
void generate_edci_top(PHY_VARS_eNB *eNB, int frame, int subframe) {

}

void mpdcch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
		       mDCI_ALLOC_t *mdci,
		       uint16_t i,
		       uint8_t *e,
		       uint32_t length)
{
  int n;
  uint8_t reset;
  uint32_t x1, x2, s=0;
  uint8_t Nacc=4;
  uint16_t j0,j,idelta;
  uint16_t i0 = mdci->i0;

  // Note: we could actually not do anything if i-i0 < Nacc, save it for later

  reset = 1;
  // x1 is set in lte_gold_generic

  if ((mdci->rnti == 0xFFFE) || 
      (mdci->ce_mode == 2)) // CEModeB Note: also for mdci->rnti==SC_RNTI
    Nacc=frame_parms->frame_type == FDD ? 4 : 10;
  else Nacc=1;
  
  if (frame_parms->frame_type == FDD || Nacc == 1) idelta = 0;
  else                                             idelta = Nacc-2;
  
  j0 = (i0+idelta)/Nacc;
  j  = (i - i0)/Nacc; 

  
  // rule for BL/CE UEs from Section 6.8.B2 in 36.211
  x2=  ((((j0+j)*Nacc)%10)<<9) +  mdci->dmrs_scrambling_init;
  
  for (n=0; n<length; n++) {
    if ((i&0x1f)==0) {
      s = lte_gold_generic(&x1, &x2, reset);
      //printf("lte_gold[%d]=%x\n",i,s);
      reset = 0;
    }
    e[i] = (e[i]&1) ^ ((s>>(i&0x1f))&1);
  }
}

// this table is the allocation of modulated MPDCCH format 5 symbols to REs
// There are in total 36 REs/ECCE * 4 ECCE/PRB_pair = 144 REs in total/PRB_pair, total is 168 REs => 24 REs for DMRS
// For format 5 there are 6 PRB pairs => 864 REs for 24 total ECCE
static uint16_t mpdcch5tab[864];

void init_mpdcch5tab_normal_regular_subframe_evenNRBDL(PHY_VARS_eNB *eNB) {
  int l,k,kmod,re;

  LOG_I(PHY,"Inititalizing mpdcch5tab for normal prefix, normal prefix, no PSS/SSS/PBCH, even N_RB_DL\n");
  for (l=0,re=0;l<14;l++) {
    for (k=0;k<72;k++){
      kmod = k % 12; 
      if (((l!=5) && (l!=6) && (l!=12) && (l!=13)) ||
	  (((l==5)||(l==6)||(l==12)||(l==13))&&(kmod!=0)&&(kmod!=5)&&(kmod!=10)))
	mpdcch5tab[re++]=(l*eNB->frame_parms.ofdm_symbol_size)+k;
    }
  }
  AssertFatal(re==864,"RE count not equal to 864\n");
}

extern uint8_t *generate_dci0(uint8_t *dci,
			      uint8_t *e,
			      uint8_t DCI_LENGTH,
			      uint8_t aggregation_level,
			      uint16_t rnti);

void generate_mdci_top(PHY_VARS_eNB *eNB, int frame, int subframe,int16_t amp,int32_t **txdataF) {

  LTE_eNB_MPDCCH *mpdcch= &eNB->mpdcch_vars[subframe&2];
  mDCI_ALLOC_t *mdci;
  int coded_bits;
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
  int i;
  int gain_lin_QPSK;

  for (i=0;i<mpdcch->num_dci;i++) {
    mdci = &mpdcch->mdci_alloc[i];


    AssertFatal(fp->frame_type==FDD,"TDD is not yet supported for MPDCCH\n");
    AssertFatal(fp->Ncp == NORMAL,"Extended Prefix not yet supported for MPDCCH\n");
    AssertFatal(mdci->L<=24,"L is %d\n",mdci->L);
    AssertFatal(fp->N_RB_DL==50 || fp->N_RB_DL==100,"Only N_RB_DL=50,100 for MPDCCH\n");
    // Force MPDDCH format 5
    AssertFatal(mdci->number_of_prb_pairs==6,"2 or 4 PRB pairs not support yet for MPDCCH\n");
    AssertFatal(mdci->reps>0,"mdci->reps==0\n");

    // 9 REs/EREG * 4 EREG/ECCE => 36 REs/ECCE => 72 bits/ECCE, so same as regular PDCCH channel encoding

    // Note: We only have to run this every Nacc subframes during repetitions, data and scrambling are constant, but we do it for now to simplify during testing

    generate_dci0(mdci->dci_pdu,
		  mpdcch->e+(72*mdci->firstCCE),
		  mdci->dci_length,
		  mdci->L,
		  mdci->rnti);

    
    coded_bits = 72 * mdci->L;

    // scrambling
    uint16_t absSF = (frame*10)+subframe; 

    AssertFatal(absSF < 1024,
		"Absolute subframe %d = %d*10 + %d > 1023\n",
		absSF,frame,subframe);

    mpdcch_scrambling(fp,
		      mdci,
		      absSF,
		      mpdcch->e+(72*mdci->firstCCE),
		      coded_bits);

    // Modulation for PDCCH
    if (fp->nb_antenna_ports_eNB==1)
      gain_lin_QPSK = (int16_t)((amp*ONE_OVER_SQRT2_Q15)>>15);
    else
      gain_lin_QPSK = amp/2;

    uint8_t *e_ptr = mpdcch->e;

    //    if (mdci->transmission_type==0) nprime=mdci->rnti&3; // for Localized 2+4 we use 6.8B.5 rule
    // map directly to one antenna port for now
    // Note: aside from the antenna port mapping, there is no difference between localized and distributed transmission for MPDCCH format 5

    // first RE of narrowband
    // mpdcchtab5 below contains the mapping from each coded symbol to relative RE avoiding the DMRS


    int re_offset = fp->first_carrier_offset + 1 + ((fp->N_RB_DL==100)?1:0) + mdci->narrowband*12*6;
    if (re_offset>fp->ofdm_symbol_size) re_offset-=(fp->ofdm_symbol_size-1);
    int32_t *txF = &txdataF[0][re_offset];
    int32_t yIQ;

    for (i=0; i<(coded_bits>>1); i++) {
      // QPSK modulation to yIQ
      ((int16_t*)&yIQ)[0] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK; e_ptr++;
      ((int16_t*)&yIQ)[1] = (*e_ptr == 1) ? -gain_lin_QPSK : gain_lin_QPSK; e_ptr++;
      txF[mpdcch5tab[i+(36*mdci->firstCCE)]] = yIQ;
    }

  }
} 

#endif