dci_nr.c 154 KB
Newer Older
Agustin's avatar
Agustin 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 28 29 30 31 32 33 34 35 36
/*
 * 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
 */

/*! \file PHY/LTE_TRANSPORT/dci_nr.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, A. Mico Pereperez
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */
#ifdef USER_MODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
37
#include "nr_transport_proto_ue.h"
hongzhi wang's avatar
hongzhi wang committed
38
#include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h"
hongzhi wang's avatar
hongzhi wang committed
39 40
#include "PHY/phy_extern_nr_ue.h"
#include "PHY/CODING/coding_extern.h"
Agustin's avatar
Agustin committed
41 42 43 44 45 46 47 48 49 50 51
#include "PHY/sse_intrin.h"

#include "assertions.h" 
#include "T.h"

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

//#define NR_LTE_PDCCH_DCI_SWITCH
#define NR_PDCCH_DCI_RUN              // activates new nr functions
52
#define NR_PDCCH_DCI_DEBUG            // activates NR_PDCCH_DCI_DEBUG logs
Agustin's avatar
Agustin committed
53 54
#define NR_NBR_CORESET_ACT_BWP 3      // The number of CoreSets per BWP is limited to 3 (including initial CORESET: ControlResourceId 0)
#define NR_NBR_SEARCHSPACE_ACT_BWP 10 // The number of SearSpaces per BWP is limited to 10 (including initial SEARCHSPACE: SearchSpaceId 0)
55
#define PDCCH_TEST_POLAR_TEMP_FIX
Agustin's avatar
Agustin committed
56 57 58 59




60
#ifdef NR_PDCCH_DCI_RUN
Agustin's avatar
Agustin committed
61

62
static const uint16_t conjugate[8]__attribute__((aligned(32))) = {-1,1,-1,1,-1,1,-1,1};
Agustin's avatar
Agustin committed
63 64


hongzhi wang's avatar
hongzhi wang committed
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
void nr_pdcch_demapping_deinterleaving(uint16_t *llr,
                                       uint16_t *z,
                                       NR_DL_FRAME_PARMS *frame_parms,
                                       uint8_t coreset_time_dur,
                                       uint32_t coreset_nbr_rb,
                                       uint8_t reg_bundle_size_L,
                                       uint8_t coreset_interleaver_size_R,
                                       uint8_t n_shift){
/*
 * This function will do demapping and deinterleaving from llr containing demodulated symbols
 * Demapping will regroup in REG and bundles
 * Deinterleaving will order the bundles
 * 
 * In the following example we can see the process. The llr contains the demodulated IQs, but they are not ordered from REG 0,1,2,..
 * In e_rx (z) we will order the REG ids and group them into bundles.
 * Then we will put the bundles in the correct order as indicated in subclause 7.3.2.2
 * 
                llr --------------------------> e_rx (z) ----> e_rx (z)
            |   ...
            |   ...
            |   REG 26
symbol 2    |   ...
            |   ...
            |   REG 5
            |   REG 2
            
            |   ...
            |   ...
            |   REG 25
symbol 1    |   ...
            |   ...
            |   REG 4
            |   REG 1
            
            |   ...
            |   ...                           ...              ...
            |   REG 24 (bundle 7)             ...              ...
symbol 0    |   ...                           bundle 3         bundle 6
            |   ...                           bundle 2         bundle 1
            |   REG 3                         bundle 1         bundle 7
            |   REG 0  (bundle 0)             bundle 0         bundle 0
Agustin's avatar
Agustin committed
106

hongzhi wang's avatar
hongzhi wang committed
107 108
*/
  int c=0,r=0;
109 110
  uint16_t bundle_j=0, f_bundle_j=0,f_reg=0;
  uint32_t coreset_C=0;
hongzhi wang's avatar
hongzhi wang committed
111 112 113 114 115 116 117 118 119
  uint16_t index_z, index_llr;

  int coreset_interleaved = 0;
  if (reg_bundle_size_L!=0){ // interleaving will be done only if reg_bundle_size_L != 0
    coreset_interleaved=1;
    coreset_C = (uint32_t)((coreset_nbr_rb * coreset_time_dur)/ (coreset_interleaver_size_R*reg_bundle_size_L));
  } else {
    reg_bundle_size_L=6;
  }
Agustin's avatar
Agustin committed
120

hongzhi wang's avatar
hongzhi wang committed
121 122 123 124 125
  for(int reg=0; reg<((coreset_nbr_rb*coreset_time_dur)); reg++){
    if ((reg%reg_bundle_size_L) == 0){
      if (r == coreset_interleaver_size_R) {
        r=0;
        c++;
Agustin's avatar
Agustin committed
126
      }
hongzhi wang's avatar
hongzhi wang committed
127 128 129
      bundle_j = (c*coreset_interleaver_size_R)+r;
      f_bundle_j = ((r*coreset_C)+c+n_shift)%((coreset_nbr_rb*coreset_time_dur)/reg_bundle_size_L);
      if (coreset_interleaved==0) f_bundle_j=bundle_j;
130
      #ifndef NR_PDCCH_DCI_DEBUG
hongzhi wang's avatar
hongzhi wang committed
131 132
        printf("\n\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_demapping_deinterleaving)-> [r=%d,c=%d] bundle_j(%d) interleaved at f_bundle_j(%d)\n",r,c,bundle_j,f_bundle_j);
      #endif
Agustin's avatar
Agustin committed
133
    }
hongzhi wang's avatar
hongzhi wang committed
134
    f_reg = (f_bundle_j*reg_bundle_size_L)+(reg%reg_bundle_size_L);
135 136
    //index_z   = 9*reg;
    index_z   = 9*(uint16_t)floor(reg/coreset_time_dur) + (9*coreset_nbr_rb)*(reg%coreset_time_dur);
hongzhi wang's avatar
hongzhi wang committed
137 138 139 140
    //index_llr = 9*(((uint16_t)floor(f_reg/reg_bundle_size_L)+(f_reg)%coreset_time_dur))*(coreset_nbr_rb);
    index_llr = 9*((uint16_t)floor(f_reg/coreset_time_dur)+((f_reg%coreset_time_dur)*(coreset_nbr_rb)));
    for (int i=0; i<9; i++){
      z[index_z + i] = llr[index_llr + i];
141
        #ifndef NR_PDCCH_DCI_DEBUG
hongzhi wang's avatar
hongzhi wang committed
142 143 144 145 146 147
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_demapping_deinterleaving)-> [reg=%d,bundle_j=%d] z[%d]=(%d,%d) <-> \t[f_reg=%d,fbundle_j=%d] llr[%d]=(%d,%d) \n",
                  reg,bundle_j,(index_z + i),*(char*) &z[index_z + i],*(1 + (char*) &z[index_z + i]),
                  f_reg,f_bundle_j,(index_llr + i),*(char*) &llr[index_llr + i], *(1 + (char*) &llr[index_llr + i]));
        #endif
    }
    if ((reg%reg_bundle_size_L) == 0) r++;
Agustin's avatar
Agustin committed
148
  }
hongzhi wang's avatar
hongzhi wang committed
149
}
Agustin's avatar
Agustin committed
150 151 152 153 154 155 156

#endif

#ifdef NR_PDCCH_DCI_RUN
int32_t nr_pdcch_llr(NR_DL_FRAME_PARMS *frame_parms, int32_t **rxdataF_comp,
		char *pdcch_llr, uint8_t symbol,uint32_t coreset_nbr_rb) {

157
	int16_t *rxF = (int16_t*) &rxdataF_comp[0][(symbol * coreset_nbr_rb * 12)];
Agustin's avatar
Agustin committed
158 159 160
	int32_t i;
	char *pdcch_llr8;

161
	pdcch_llr8 = &pdcch_llr[2 * symbol * coreset_nbr_rb * 9];
Agustin's avatar
Agustin committed
162 163 164 165 166

	if (!pdcch_llr8) {
		printf("pdcch_qpsk_llr: llr is null, symbol %d\n", symbol);
		return (-1);
	}
167
#ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
168 169 170 171 172 173 174 175 176 177 178
	printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_llr)-> llr logs: pdcch qpsk llr for symbol %d (pos %d), llr offset %d\n",symbol,(symbol*frame_parms->N_RB_DL*12),pdcch_llr8-pdcch_llr);
#endif
	//for (i = 0; i < (frame_parms->N_RB_DL * ((symbol == 0) ? 16 : 24)); i++) {
	for (i = 0; i < (coreset_nbr_rb * ((symbol == 0) ? 18 : 18)); i++) {

		if (*rxF > 31)
			*pdcch_llr8 = 31;
		else if (*rxF < -32)
			*pdcch_llr8 = -32;
		else
			*pdcch_llr8 = (char) (*rxF);
179 180
#ifndef NR_PDCCH_DCI_DEBUG
		    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_llr)-> llr logs: rb=%d i=%d *rxF:%d => *pdcch_llr8:%d\n",i/18,i,*rxF,*pdcch_llr8);
Agustin's avatar
Agustin committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
#endif
		rxF++;
		pdcch_llr8++;
	}

	return (0);

}
#endif



int32_t pdcch_llr(NR_DL_FRAME_PARMS *frame_parms,
                  int32_t **rxdataF_comp,
                  char *pdcch_llr,
                  uint8_t symbol)
{

  int16_t *rxF= (int16_t*) &rxdataF_comp[0][(symbol*frame_parms->N_RB_DL*12)];
  int32_t i;
  char *pdcch_llr8;

  pdcch_llr8 = &pdcch_llr[2*symbol*frame_parms->N_RB_DL*12];

  if (!pdcch_llr8) {
    printf("pdcch_qpsk_llr: llr is null, symbol %d\n",symbol);
    return(-1);
  }

  //    printf("pdcch qpsk llr for symbol %d (pos %d), llr offset %d\n",symbol,(symbol*frame_parms->N_RB_DL*12),pdcch_llr8-pdcch_llr);

  for (i=0; i<(frame_parms->N_RB_DL*((symbol==0) ? 16 : 24)); i++) {

    if (*rxF>31)
      *pdcch_llr8=31;
    else if (*rxF<-32)
      *pdcch_llr8=-32;
    else
      *pdcch_llr8 = (char)(*rxF);

    //    printf("%d %d => %d\n",i,*rxF,*pdcch_llr8);
    rxF++;
    pdcch_llr8++;
  }

  return(0);

}

//__m128i avg128P;

//compute average channel_level on each (TX,RX) antenna pair
void pdcch_channel_level(int32_t **dl_ch_estimates_ext,
                         NR_DL_FRAME_PARMS *frame_parms,
                         int32_t *avg,
                         uint8_t nb_rb)
{

  int16_t rb;
  uint8_t aatx,aarx;
#if defined(__x86_64__) || defined(__i386__)
  __m128i *dl_ch128;
  __m128i avg128P;
#elif defined(__arm__)
  int16x8_t *dl_ch128;
  int32x4_t *avg128P;
#endif
  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
      //clear average level
#if defined(__x86_64__) || defined(__i386__)
      avg128P = _mm_setzero_si128();
      dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][0];
#elif defined(__arm__)

#endif
      for (rb=0; rb<nb_rb; rb++) {

#if defined(__x86_64__) || defined(__i386__)
        avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[0],dl_ch128[0]));
        avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[1],dl_ch128[1]));
        avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[2],dl_ch128[2]));
#elif defined(__arm__)

#endif
        dl_ch128+=3;
        /*
          if (rb==0) {
          print_shorts("dl_ch128",&dl_ch128[0]);
          print_shorts("dl_ch128",&dl_ch128[1]);
          print_shorts("dl_ch128",&dl_ch128[2]);
          }
        */
      }

      DevAssert( nb_rb );
      avg[(aatx<<1)+aarx] = (((int32_t*)&avg128P)[0] +
                             ((int32_t*)&avg128P)[1] +
                             ((int32_t*)&avg128P)[2] +
                             ((int32_t*)&avg128P)[3])/(nb_rb*12);

      //            printf("Channel level : %d\n",avg[(aatx<<1)+aarx]);
    }

#if defined(__x86_64__) || defined(__i386__)
  _mm_empty();
  _m_empty();
#endif

}

#if defined(__x86_64) || defined(__i386__)
__m128i mmtmpPD0,mmtmpPD1,mmtmpPD2,mmtmpPD3;
#elif defined(__arm__)

#endif


void pdcch_detection_mrc_i(NR_DL_FRAME_PARMS *frame_parms,
                           int32_t **rxdataF_comp,
                           int32_t **rxdataF_comp_i,
                           int32_t **rho,
                           int32_t **rho_i,
                           uint8_t symbol)
{

  uint8_t aatx;

#if defined(__x86_64__) || defined(__i386__)
  __m128i *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1;
#elif defined(__arm__)
  int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1;
#endif
  int32_t i;

  if (frame_parms->nb_antennas_rx>1) {
    for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
      //if (frame_parms->mode1_flag && (aatx>0)) break;

#if defined(__x86_64__) || defined(__i386__)
      rxdataF_comp128_0   = (__m128i *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
      rxdataF_comp128_1   = (__m128i *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
#elif defined(__arm__)
      rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
      rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
#endif
      // MRC on each re of rb on MF output
      for (i=0; i<frame_parms->N_RB_DL*3; i++) {
#if defined(__x86_64__) || defined(__i386__)
        rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1));
#elif defined(__arm__)
        rxdataF_comp128_0[i] = vhaddq_s16(rxdataF_comp128_0[i],rxdataF_comp128_1[i]);
#endif
      }
    }

#if defined(__x86_64__) || defined(__i386__)
    rho128_0 = (__m128i *) &rho[0][symbol*frame_parms->N_RB_DL*12];
    rho128_1 = (__m128i *) &rho[1][symbol*frame_parms->N_RB_DL*12];
#elif defined(__arm__)
    rho128_0 = (int16x8_t *) &rho[0][symbol*frame_parms->N_RB_DL*12];
    rho128_1 = (int16x8_t *) &rho[1][symbol*frame_parms->N_RB_DL*12];
#endif
    for (i=0; i<frame_parms->N_RB_DL*3; i++) {
#if defined(__x86_64__) || defined(__i386__)
      rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1));
#elif defined(__arm__)
      rho128_0[i] = vhaddq_s16(rho128_0[i],rho128_1[i]);
#endif
    }

#if defined(__x86_64__) || defined(__i386__)
    rho128_i0 = (__m128i *) &rho_i[0][symbol*frame_parms->N_RB_DL*12];
    rho128_i1 = (__m128i *) &rho_i[1][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp128_i0   = (__m128i *)&rxdataF_comp_i[0][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp128_i1   = (__m128i *)&rxdataF_comp_i[1][symbol*frame_parms->N_RB_DL*12];
#elif defined(__arm__)
    rho128_i0 = (int16x8_t*) &rho_i[0][symbol*frame_parms->N_RB_DL*12];
    rho128_i1 = (int16x8_t*) &rho_i[1][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp128_i0   = (int16x8_t *)&rxdataF_comp_i[0][symbol*frame_parms->N_RB_DL*12];
    rxdataF_comp128_i1   = (int16x8_t *)&rxdataF_comp_i[1][symbol*frame_parms->N_RB_DL*12];

#endif
    // MRC on each re of rb on MF and rho
    for (i=0; i<frame_parms->N_RB_DL*3; i++) {
#if defined(__x86_64__) || defined(__i386__)
      rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1));
      rho128_i0[i]          = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1));
#elif defined(__arm__)
      rxdataF_comp128_i0[i] = vhaddq_s16(rxdataF_comp128_i0[i],rxdataF_comp128_i1[i]);
      rho128_i0[i]          = vhaddq_s16(rho128_i0[i],rho128_i1[i]);

#endif
    }
  }

#if defined(__x86_64__) || defined(__i386__)
  _mm_empty();
  _m_empty();
#endif
}


#ifdef NR_PDCCH_DCI_RUN
// This function will extract the mapped DM-RS PDCCH REs as per 38.211 Section 7.4.1.3.2 (Mapping to physical resources)
void nr_pdcch_extract_rbs_single(int32_t **rxdataF,
                                 int32_t **dl_ch_estimates,
                                 int32_t **rxdataF_ext,
                                 int32_t **dl_ch_estimates_ext,
                                 uint8_t symbol,
                                 uint32_t high_speed_flag,
                                 NR_DL_FRAME_PARMS *frame_parms,
                                 uint64_t coreset_freq_dom,
                                 uint32_t coreset_nbr_rb,
                                 uint32_t n_BWP_start) {

/*
 * This function is demapping DM-RS PDCCH RE
 * Implementing 38.211 Section 7.4.1.3.2 Mapping to physical resources
 * PDCCH DM-RS signals are mapped on RE a_k_l where:
 * k = 12*n + 4*kprime + 1
 * n=0,1,..
 * kprime=0,1,2
 * According to this equations, DM-RS PDCCH are mapped on k where k%12==1 || k%12==5 || k%12==9
 *
 */
  // the bitmap coreset_frq_domain contains 45 bits
  #define CORESET_FREQ_DOMAIN_BITMAP_SIZE   45
  // each bit is associated to 6 RBs
  #define BIT_TO_NBR_RB_CORESET_FREQ_DOMAIN  6
  #define NBR_RE_PER_RB_WITH_DMRS           12
  // after removing the 3 DMRS RE, the RB contains 9 RE with PDCCH
  #define NBR_RE_PER_RB_WITHOUT_DMRS         9

415
  uint16_t c_rb, nb_rb = 0;
Agustin's avatar
Agustin committed
416 417
  // this variable will be incremented by 1 each time a bit set to '0' is found in coreset_freq_dom bitmap
  uint16_t offset_discontiguous=0;
418 419
  //uint8_t rb_count_bit;
  uint8_t i, j, aarx, bitcnt_coreset_freq_dom=0;
Agustin's avatar
Agustin committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433
  int32_t *dl_ch0, *dl_ch0_ext, *rxF, *rxF_ext;
  int nushiftmod3 = frame_parms->nushift % 3;
  uint8_t symbol_mod;

  symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
  c_rb = n_BWP_start; // c_rb is the common resource block: RB within the BWP
  #ifdef DEBUG_DCI_DECODING
    LOG_I(PHY, "extract_rbs_single: symbol_mod %d\n",symbol_mod);
  #endif



  for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) {
    if (high_speed_flag == 1){
434
      dl_ch0 = &dl_ch_estimates[aarx][(symbol * (frame_parms->ofdm_symbol_size))];
Agustin's avatar
Agustin committed
435
      #ifdef NR_PDCCH_DCI_DEBUG
436 437
        printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> dl_ch0 = &dl_ch_estimates[aarx = (%d)][ (symbol * (frame_parms->ofdm_symbol_size (%d))) = (%d)]\n",
               aarx,frame_parms->ofdm_symbol_size,(symbol * (frame_parms->ofdm_symbol_size)));
Agustin's avatar
Agustin committed
438 439
      #endif
    } else {
440
      dl_ch0 = &dl_ch_estimates[aarx][0];
Agustin's avatar
Agustin committed
441
      #ifdef NR_PDCCH_DCI_DEBUG
442
        printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> dl_ch0 = &dl_ch_estimates[aarx = (%d)][0]\n",aarx);
Agustin's avatar
Agustin committed
443 444 445
      #endif
    }

446
    dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol * (coreset_nbr_rb * NBR_RE_PER_RB_WITH_DMRS)];
Agustin's avatar
Agustin committed
447
    #ifdef NR_PDCCH_DCI_DEBUG
448
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> dl_ch0_ext = &dl_ch_estimates_ext[aarx = (%d)][symbol * (frame_parms->N_RB_DL * 9) = (%d)]\n",
449
             aarx,symbol * (coreset_nbr_rb * NBR_RE_PER_RB_WITH_DMRS));
Agustin's avatar
Agustin committed
450
    #endif
451
    rxF_ext = &rxdataF_ext[aarx][symbol * (coreset_nbr_rb * NBR_RE_PER_RB_WITH_DMRS)];
Agustin's avatar
Agustin committed
452
    #ifdef NR_PDCCH_DCI_DEBUG
453
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> rxF_ext = &rxdataF_ext[aarx = (%d)][symbol * (frame_parms->N_RB_DL * 9) = (%d)]\n",
454
             aarx,symbol * (coreset_nbr_rb * NBR_RE_PER_RB_WITH_DMRS));
Agustin's avatar
Agustin committed
455 456 457 458 459 460 461 462 463 464
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> (for symbol=%d, aarx=%d), symbol_mod=%d, nushiftmod3=%d \n",symbol,aarx,symbol_mod,nushiftmod3);
    #endif

/*
 * The following for loop handles treatment of PDCCH contained in table rxdataF (in frequency domain)
 * In NR the PDCCH IQ symbols are contained within RBs in the CORESET defined by higher layers which is located within the BWP
 * Lets consider that the first RB to be considered as part of the CORESET and part of the PDCCH is n_BWP_start
 * Several cases have to be handled differently as IQ symbols are situated in different parts of rxdataF:
 * 1. Number of RBs in the system bandwidth is even
 *    1.1 The RB is <  than the N_RB_DL/2 -> IQ symbols are in the second half of the rxdataF (from first_carrier_offset)
465
 *    1.2 The RB is >= than the N_RB_DL/2 -> IQ symbols are in the first half of the rxdataF (from element 0)
Agustin's avatar
Agustin committed
466 467 468
 * 2. Number of RBs in the system bandwidth is odd
 * (particular case when the RB with DC as it is treated differently: it is situated in symbol borders of rxdataF)
 *    2.1 The RB is <= than the N_RB_DL/2   -> IQ symbols are in the second half of the rxdataF (from first_carrier_offset)
469
 *    2.2 The RB is >  than the N_RB_DL/2+1 -> IQ symbols are in the first half of the rxdataF (from element 0 + 2nd half RB containing DC)
Agustin's avatar
Agustin committed
470 471
 *    2.3 The RB is == N_RB_DL/2+1          -> IQ symbols are in the lower border of the rxdataF for first 6 IQ element and the upper border of the rxdataF for the last 6 IQ elements
 * If the first RB containing PDCCH within the UE BWP and within the CORESET is higher than half of the system bandwidth (N_RB_DL),
472
 * then the IQ symbol is going to be found at the position 0+c_rb-N_RB_DL/2 in rxdataF and
Agustin's avatar
Agustin committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
 * we have to point the pointer at (1+c_rb-N_RB_DL/2) in rxdataF
 */

    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> n_BWP_start=%d, coreset_nbr_rb=%d\n",n_BWP_start,coreset_nbr_rb);
    #endif

    for (c_rb = n_BWP_start; c_rb < (n_BWP_start + coreset_nbr_rb + (BIT_TO_NBR_RB_CORESET_FREQ_DOMAIN * offset_discontiguous)); c_rb++) {
      //c_rb_tmp = 0;
      if (((c_rb - n_BWP_start) % BIT_TO_NBR_RB_CORESET_FREQ_DOMAIN)==0) {
        bitcnt_coreset_freq_dom ++;
        while ((((coreset_freq_dom & 0x1FFFFFFFFFFF) >> (CORESET_FREQ_DOMAIN_BITMAP_SIZE - bitcnt_coreset_freq_dom)) & 0x1)== 0){ // 46 -> 45 is number of bits in coreset_freq_dom
          // next 6 RB are not part of the CORESET within the BWP as bit in coreset_freq_dom is set to 0
          bitcnt_coreset_freq_dom ++;
          //c_rb_tmp = c_rb_tmp + 6;
          c_rb = c_rb + BIT_TO_NBR_RB_CORESET_FREQ_DOMAIN;
          offset_discontiguous ++;
          #ifdef NR_PDCCH_DCI_DEBUG
491
            printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> we entered here as coreset_freq_dom=%lx (bit %d) is 0, coreset_freq_domain is discontiguous\n",coreset_freq_dom,(46 - bitcnt_coreset_freq_dom));
Agustin's avatar
Agustin committed
492 493 494 495 496 497 498 499 500 501 502 503
          #endif
        }
      }
      //c_rb = c_rb + c_rb_tmp;

      #ifdef NR_PDCCH_DCI_DEBUG
        printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> c_rb=%d\n",c_rb);
      #endif
      // first we set initial conditions for pointer to rxdataF depending on the situation of the first RB within the CORESET (c_rb = n_BWP_start)
      if ((c_rb < (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) == 0)) {
        //if RB to be treated is lower than middle system bandwidth then rxdataF pointed at (offset + c_br + symbol * ofdm_symbol_size): even case
        rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size)))];
504
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
505 506 507 508 509 510 511 512
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in even case c_rb (%d) is lower than half N_RB_DL -> rxF = &rxdataF[aarx = (%d)][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
                  c_rb,aarx,(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))));
        #endif
      }
      if ((c_rb >= (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) == 0)) {
        // number of RBs is even  and c_rb is higher than half system bandwidth (we don't skip DC)
        // if these conditions are true the pointer has to be situated at the 1st part of the rxdataF
        rxF = &rxdataF[aarx][(12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size)))]; // we point at the 1st part of the rxdataF in symbol
513
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
514 515 516 517 518 519 520 521 522 523 524 525
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in even case c_rb (%d) is higher than half N_RB_DL (not DC) -> rxF = &rxdataF[aarx = (%d)][(12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
               c_rb,aarx,(12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size))));
        #endif
        //rxF = &rxdataF[aarx][(1 + 12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size)))]; // we point at the 1st part of the rxdataF in symbol
        //#ifdef NR_PDCCH_DCI_DEBUG
        //  printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in even case c_rb (%d) is higher than half N_RB_DL (not DC) -> rxF = &rxdataF[aarx = (%d)][(1 + 12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
        //         c_rb,aarx,(1 + 12*(c_rb - (frame_parms->N_RB_DL>>1)) + (symbol * (frame_parms->ofdm_symbol_size))));
        //#endif
      }
      if ((c_rb < (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) != 0)){
        //if RB to be treated is lower than middle system bandwidth then rxdataF pointed at (offset + c_br + symbol * ofdm_symbol_size): odd case
        rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size)))];
526
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
527 528 529 530 531 532 533 534
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in odd case c_rb (%d) is lower or equal than half N_RB_DL -> rxF = &rxdataF[aarx = (%d)][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
                 c_rb,aarx,(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))));
        #endif
      }
      if ((c_rb > (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) != 0)){
        // number of RBs is odd  and   c_rb is higher than half system bandwidth + 1
        // if these conditions are true the pointer has to be situated at the 1st part of the rxdataF just after the first IQ symbols of the RB containing DC
        rxF = &rxdataF[aarx][(12*(c_rb - (frame_parms->N_RB_DL>>1)) - 6 + (symbol * (frame_parms->ofdm_symbol_size)))]; // we point at the 1st part of the rxdataF in symbol
535
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
536 537 538 539 540 541 542 543
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in odd case c_rb (%d) is higher than half N_RB_DL (not DC) -> rxF = &rxdataF[aarx = (%d)][(12*(c_rb - frame_parms->N_RB_DL) - 5 + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
                 c_rb,aarx,(12*(c_rb - (frame_parms->N_RB_DL>>1)) - 6 + (symbol * (frame_parms->ofdm_symbol_size))));
        #endif
      }
      if ((c_rb == (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) != 0)){ // treatment of RB containing the DC
        // if odd number RBs in system bandwidth and first RB to be treated is higher than middle system bandwidth (around DC)
        // we have to treat the RB in two parts: first part from i=0 to 5, the data is at the end of rxdataF (pointing at the end of the table)
        rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size)))];
544
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in odd case c_rb (%d) is half N_RB_DL + 1 we treat DC case -> rxF = &rxdataF[aarx = (%d)][(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))) = (%d)]\n",
                 c_rb,aarx,(frame_parms->first_carrier_offset + 12 * c_rb + (symbol * (frame_parms->ofdm_symbol_size))));
        #endif
        /*if (symbol_mod > 300) { // this if is going to be removed as DM-RS signals are present in all symbols of PDCCH
          for (i = 0; i < 6; i++) {
            dl_ch0_ext[i] = dl_ch0[i];
            rxF_ext[i] = rxF[i];
          }
          rxF = &rxdataF[aarx][(symbol * (frame_parms->ofdm_symbol_size))]; // we point at the 1st part of the rxdataF in symbol
          #ifdef NR_PDCCH_DCI_DEBUG
            printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in odd case c_rb (%d) is half N_RB_DL +1 we treat DC case -> rxF = &rxdataF[aarx = (%d)][(symbol * (frame_parms->ofdm_symbol_size)) = (%d)]\n",
                   c_rb,aarx,(symbol * (frame_parms->ofdm_symbol_size)));
          #endif
          for (; i < 12; i++) {
            dl_ch0_ext[i] = dl_ch0[i];
            rxF_ext[i] = rxF[(1 + i - 6)];
          }
          nb_rb++;
          dl_ch0_ext += 12;
          rxF_ext += 12;
          dl_ch0 += 12;
          rxF += 7;
          c_rb++;
          } else {*/
        j = 0;
        for (i = 0; i < 6; i++) { //treating first part of the RB note that i=5 would correspond to DC. We treat it in NR
          if ((i != 1) && (i != 5)) {
            dl_ch0_ext[j] = dl_ch0[i];
            rxF_ext[j++] = rxF[i];
            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
          }
        }
        // then we point at the begining of the symbol part of rxdataF do process second part of RB
        rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))]; // we point at the 1st part of the rxdataF in symbol
579
        #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
          printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> in odd case c_rb (%d) is half N_RB_DL +1 we treat DC case -> rxF = &rxdataF[aarx = (%d)][(symbol * (frame_parms->ofdm_symbol_size)) = (%d)]\n",
                 c_rb,aarx,(symbol * (frame_parms->ofdm_symbol_size)));
        #endif
        for (; i < 12; i++) {
          if ((i != 9)) {
            dl_ch0_ext[j] = dl_ch0[i];
            rxF_ext[j++] = rxF[(1 + i - 6)];
            //              printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1]));
          }
        }
        nb_rb++;
        dl_ch0_ext += NBR_RE_PER_RB_WITHOUT_DMRS;
        rxF_ext += NBR_RE_PER_RB_WITHOUT_DMRS;
        dl_ch0 += 12;
          //rxF += 7;
          //c_rb++;
          //n_BWP_start++; // We have to increment this variable here to be consequent in the for loop afterwards
        //}
      } else { // treatment of any RB that does not contain the DC
        /*if (symbol_mod > 300) {
          memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int32_t));
          for (i = 0; i < 12; i++) {
            rxF_ext[i] = rxF[i];
          }
          nb_rb++;
          dl_ch0_ext += 12;
          rxF_ext += 12;
          dl_ch0 += 12;
          //rxF += 12;
        } else {*/
        j = 0;
        for (i = 0; i < 12; i++) {
          if ((i != 1) && (i != 5) && (i != 9)) {
            rxF_ext[j] = rxF[i];
614
            #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
615 616 617 618
              printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> RB[c_rb %d] \t RE[re %d] => rxF_ext[%d]=(%d,%d)\t rxF[%d]=(%d,%d)",
                     c_rb, i, j, *(short *) &rxF_ext[j],*(1 + (short*) &rxF_ext[j]), i,
                     *(short *) &rxF[i], *(1 + (short*) &rxF[i]));
            #endif
hongzhi wang's avatar
hongzhi wang committed
619
            dl_ch0_ext[j] = dl_ch0[i];
Agustin's avatar
Agustin committed
620
            //printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> ch %d => dl_ch0(%d,%d)\n", i, *(short *) &dl_ch0[i], *(1 + (short*) &dl_ch0[i]));
621
            //printf("\t-> dl_ch0[%d] => dl_ch0_ext[%d](%d,%d)\n", i,j, *(short *) &dl_ch0[i], *(1 + (short*) &dl_ch0[i]));
hongzhi wang's avatar
hongzhi wang committed
622
            j++;
Agustin's avatar
Agustin committed
623
          } else {
624
            #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
              printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> RB[c_rb %d] \t RE[re %d] => rxF_ext[%d]=(%d,%d)\t rxF[%d]=(%d,%d) \t\t <==> DM-RS PDCCH, this is a pilot symbol\n",
                     c_rb, i, j, *(short *) &rxF_ext[j], *(1 + (short*) &rxF_ext[j]), i,
                     *(short *) &rxF[i], *(1 + (short*) &rxF[i]));
            #endif
          }
        }
        nb_rb++;
        dl_ch0_ext += NBR_RE_PER_RB_WITHOUT_DMRS;
        rxF_ext += NBR_RE_PER_RB_WITHOUT_DMRS;
        dl_ch0 += 12;
          //rxF += 12;
        //}
      }
    }
  }
}

#endif



void nr_pdcch_channel_compensation(int32_t **rxdataF_ext,
                                   int32_t **dl_ch_estimates_ext,
                                   int32_t **rxdataF_comp,
                                   int32_t **rho,
                                   NR_DL_FRAME_PARMS *frame_parms,
                                   uint8_t symbol,
                                   uint8_t output_shift,
                                   uint32_t coreset_nbr_rb)
{

hongzhi wang's avatar
hongzhi wang committed
656 657
  uint16_t rb; //,nb_rb=20;
  uint8_t aatx,aarx;
Agustin's avatar
Agustin committed
658

659 660 661 662 663
#if defined(__x86_64__) || defined(__i386__)
__m128i mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
#elif defined(__arm__)
int16x8_t mmtmpP0,mmtmpP1,mmtmpP2,mmtmpP3;
#endif
Agustin's avatar
Agustin committed
664

hongzhi wang's avatar
hongzhi wang committed
665 666
#if defined(__x86_64__) || defined(__i386__)
  __m128i *dl_ch128,*rxdataF128,*rxdataF_comp128;
Agustin's avatar
Agustin committed
667 668 669 670
#elif defined(__arm__)

#endif

hongzhi wang's avatar
hongzhi wang committed
671 672
  for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB;aatx++)
    for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
Agustin's avatar
Agustin committed
673 674

#if defined(__x86_64__) || defined(__i386__)
675 676 677
      dl_ch128          = (__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*coreset_nbr_rb*12];
      rxdataF128        = (__m128i *)&rxdataF_ext[aarx][symbol*coreset_nbr_rb*12];
      rxdataF_comp128   = (__m128i *)&rxdataF_comp[(aatx<<1)+aarx][symbol*coreset_nbr_rb*12];
hongzhi wang's avatar
hongzhi wang committed
678 679 680
      //printf("ch compensation dl_ch ext addr %p \n", &dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*20*12]);
      //printf("rxdataf ext addr %p symbol %d\n", &rxdataF_ext[aarx][symbol*20*12], symbol);
      //printf("rxdataf_comp addr %p\n",&rxdataF_comp[(aatx<<1)+aarx][symbol*20*12]); 
Agustin's avatar
Agustin committed
681 682

#elif defined(__arm__)
hongzhi wang's avatar
hongzhi wang committed
683
// to be filled in
Agustin's avatar
Agustin committed
684 685
#endif

hongzhi wang's avatar
hongzhi wang committed
686 687
      for (rb=0; rb<coreset_nbr_rb; rb++) {
        //printf("rb %d\n",rb);
Agustin's avatar
Agustin committed
688
#if defined(__x86_64__) || defined(__i386__)
hongzhi wang's avatar
hongzhi wang committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
        // multiply by conjugated channel
        mmtmpP0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]);
        //  print_ints("re",&mmtmpP0);
        // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
        mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1));
        mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
        mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
        //  print_ints("im",&mmtmpP1);
        mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[0]);
        // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
        mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
        //  print_ints("re(shift)",&mmtmpP0);
        mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
        //  print_ints("im(shift)",&mmtmpP1);
        mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
        mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
        //      print_ints("c0",&mmtmpP2);
        //  print_ints("c1",&mmtmpP3);
        rxdataF_comp128[0] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
708 709 710
          //print_shorts("rx:",rxdataF128);
          //print_shorts("ch:",dl_ch128);
          //print_shorts("pack:",rxdataF_comp128);
Agustin's avatar
Agustin committed
711

hongzhi wang's avatar
hongzhi wang committed
712 713 714 715 716 717 718 719 720 721 722 723 724
        // multiply by conjugated channel
        mmtmpP0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]);
        // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
        mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1));
        mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
        mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
        mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[1]);
        // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
        mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
        mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
        mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
        mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
        rxdataF_comp128[1] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
725 726 727
          //print_shorts("rx:",rxdataF128+1);
          //print_shorts("ch:",dl_ch128+1);
          //print_shorts("pack:",rxdataF_comp128+1);
Agustin's avatar
Agustin committed
728

hongzhi wang's avatar
hongzhi wang committed
729 730 731 732 733 734 735 736 737 738 739 740 741
          // multiply by conjugated channel
          mmtmpP0 = _mm_madd_epi16(dl_ch128[2],rxdataF128[2]);
          // mmtmpP0 contains real part of 4 consecutive outputs (32-bit)
          mmtmpP1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1));
          mmtmpP1 = _mm_shufflehi_epi16(mmtmpP1,_MM_SHUFFLE(2,3,0,1));
          mmtmpP1 = _mm_sign_epi16(mmtmpP1,*(__m128i*)&conjugate[0]);
          mmtmpP1 = _mm_madd_epi16(mmtmpP1,rxdataF128[2]);
          // mmtmpP1 contains imag part of 4 consecutive outputs (32-bit)
          mmtmpP0 = _mm_srai_epi32(mmtmpP0,output_shift);
          mmtmpP1 = _mm_srai_epi32(mmtmpP1,output_shift);
          mmtmpP2 = _mm_unpacklo_epi32(mmtmpP0,mmtmpP1);
          mmtmpP3 = _mm_unpackhi_epi32(mmtmpP0,mmtmpP1);
          rxdataF_comp128[2] = _mm_packs_epi32(mmtmpP2,mmtmpP3);
742 743 744 745 746 747 748 749 750 751
          ///////////////////////////////////////////////////////////////////////////////////////////////
            //print_shorts("rx:",rxdataF128+2);
            //print_shorts("ch:",dl_ch128+2);
            //print_shorts("pack:",rxdataF_comp128+2);

#ifndef NR_PDCCH_DCI_DEBUG
 for (int i=0; i<20 ; i++)
	printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_channel_compensation)-> rb=%d rxdataF128[%d]=(%d,%d) rxdataF_comp128[%d]=(%d,%d)\n",
                     rb, i, *(short *) &rxdataF128[i],*(1 + (short*) &rxdataF128[i]),
                     i,*(short *) &rxdataF_comp128[i], *(1 + (short*) &rxdataF_comp128[i]));
Agustin's avatar
Agustin committed
752

753
#endif
Agustin's avatar
Agustin committed
754

hongzhi wang's avatar
hongzhi wang committed
755 756 757 758 759 760
          dl_ch128+=3;
          rxdataF128+=3;
          rxdataF_comp128+=3;
        
#elif defined(__arm__)
// to be filled in
Agustin's avatar
Agustin committed
761
#endif
hongzhi wang's avatar
hongzhi wang committed
762 763
      }
    }
Agustin's avatar
Agustin committed
764
#if defined(__x86_64__) || defined(__i386__)
hongzhi wang's avatar
hongzhi wang committed
765 766
  _mm_empty();
  _m_empty();
Agustin's avatar
Agustin committed
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
#endif
}


void pdcch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
                         int32_t **rxdataF_comp,
                         uint8_t symbol)
{

  uint8_t aatx;

#if defined(__x86_64__) || defined(__i386__)
  __m128i *rxdataF_comp128_0,*rxdataF_comp128_1;
#elif defined(__arm__)
 int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1;
#endif
  int32_t i;

  if (frame_parms->nb_antennas_rx>1) {
    for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) {
#if defined(__x86_64__) || defined(__i386__)
      rxdataF_comp128_0   = (__m128i *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
      rxdataF_comp128_1   = (__m128i *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
#elif defined(__arm__)
      rxdataF_comp128_0   = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12];
      rxdataF_comp128_1   = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12];
#endif
      // MRC on each re of rb
      for (i=0; i<frame_parms->N_RB_DL*3; i++) {
#if defined(__x86_64__) || defined(__i386__)
        rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1));
#elif defined(__arm__)
        rxdataF_comp128_0[i] = vhaddq_s16(rxdataF_comp128_0[i],rxdataF_comp128_1[i]);
#endif
      }
    }
  }

#if defined(__x86_64__) || defined(__i386__)
  _mm_empty();
  _m_empty();
#endif

}

void pdcch_siso(NR_DL_FRAME_PARMS *frame_parms,
                int32_t **rxdataF_comp,
                uint8_t l)
{


  uint8_t rb,re,jj,ii;

  jj=0;
  ii=0;

  for (rb=0; rb<frame_parms->N_RB_DL; rb++) {

    for (re=0; re<12; re++) {

      rxdataF_comp[0][jj++] = rxdataF_comp[0][ii];
      ii++;
    }
  }
}


int32_t avgP[4];




#ifdef NR_PDCCH_DCI_RUN
int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue,
                    uint32_t frame,
                    uint8_t nr_tti_rx,
                    uint8_t eNB_id,
                    MIMO_mode_t mimo_mode,
                    uint32_t high_speed_flag,
                    uint8_t is_secondary_ue,
                    int nb_coreset_active,
                    uint16_t symbol_mon,
849
                    NR_SEARCHSPACE_TYPE_t searchSpaceType) {
Agustin's avatar
Agustin committed
850 851 852 853 854 855 856 857 858 859

	#ifdef MU_RECEIVER
	uint8_t eNB_id_i=eNB_id+1; //add 1 to eNB_id to separate from wanted signal, chosen as the B/F'd pilots from the SeNB are shifted by 1
#endif

  NR_UE_COMMON *common_vars      = &ue->common_vars;
  NR_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
  NR_UE_PDCCH **pdcch_vars       = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]];
  NR_UE_PDCCH *pdcch_vars2       = ue->pdcch_vars[ue->current_thread_id[nr_tti_rx]][eNB_id];

860 861 862
  int do_common;
  if (searchSpaceType == common) do_common=1;
  if (searchSpaceType == ue_specific) do_common=0;
Agustin's avatar
Agustin committed
863 864 865 866 867 868 869 870 871 872 873 874 875 876
  uint8_t log2_maxh, aatx, aarx;
  int32_t avgs;

  // number of RB (1 symbol) or REG (12 RE) in one CORESET: higher-layer parameter CORESET-freq-dom
  // (bit map 45 bits: each bit indicates 6 RB in CORESET -> 1 bit MSB indicates PRB 0..6 are part of CORESET)
  uint64_t coreset_freq_dom                                 = pdcch_vars2->coreset[nb_coreset_active].frequencyDomainResources;
  // number of symbols in CORESET: higher-layer parameter CORESET-time-dur {1,2,3}
  int coreset_time_dur                                      = pdcch_vars2->coreset[nb_coreset_active].duration;
  // depends on higher-layer parameter CORESET-shift-index {0,1,...,274}
  int n_shift                                               = pdcch_vars2->coreset[nb_coreset_active].cce_reg_mappingType.shiftIndex;
  // higher-layer parameter CORESET-REG-bundle-size (for non-interleaved L = 6 / for interleaved L {2,6})
  NR_UE_CORESET_REG_bundlesize_t reg_bundle_size_L          = pdcch_vars2->coreset[nb_coreset_active].cce_reg_mappingType.reg_bundlesize;
  // higher-layer parameter CORESET-interleaver-size {2,3,6}
  NR_UE_CORESET_interleaversize_t coreset_interleaver_size_R= pdcch_vars2->coreset[nb_coreset_active].cce_reg_mappingType.interleaversize;
877 878 879
  //NR_UE_CORESET_precoder_granularity_t precoder_granularity = pdcch_vars2->coreset[nb_coreset_active].precoderGranularity;
  //int tci_statesPDCCH                                       = pdcch_vars2->coreset[nb_coreset_active].tciStatesPDCCH;
  //int tci_present                                           = pdcch_vars2->coreset[nb_coreset_active].tciPresentInDCI;
Agustin's avatar
Agustin committed
880 881 882 883
  uint16_t pdcch_DMRS_scrambling_id                         = pdcch_vars2->coreset[nb_coreset_active].pdcchDMRSScramblingID;

  // The UE can be assigned 4 different BWP but only one active at a time.
  // For each BWP the number of CORESETs is limited to 3 (including initial CORESET Id=0 -> ControlResourceSetId (0..maxNrofControlReourceSets-1) (0..12-1)
884
  //uint32_t n_BWP_start = 0;
885
  //uint32_t n_rb_offset = 0;
886
  uint32_t n_rb_offset                                      = pdcch_vars2->coreset[nb_coreset_active].rb_offset+43; //to be removed 43
Agustin's avatar
Agustin committed
887 888 889 890 891 892
  // start time position for CORESET
  // parameter symbol_mon is a 14 bits bitmap indicating monitoring symbols within a slot
  uint8_t start_symbol = 0;

  // at the moment we are considering that the PDCCH is always starting at symbol 0 of current slot
  // the following code to initialize start_symbol must be activated once we implement PDCCH demapping on symbol not equal to 0 (considering symbol_mon)
893
  for (int i=0; i < 14; i++) {
894
    if (((symbol_mon >> (i+1))&0x1) != 0) {
Agustin's avatar
Agustin committed
895 896 897 898
      start_symbol = i;
      i=14;
    }
  }
899
  
900
#ifdef NR_PDCCH_DCI_DEBUG
901
  printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> symbol_mon=(%d) and start_symbol=(%d)\n",symbol_mon,start_symbol);
902
  printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_freq_dom=(%ld) n_rb_offset=(%d) coreset_time_dur=(%d) n_shift=(%d) reg_bundle_size_L=(%d) coreset_interleaver_size_R=(%d) \n",
903
          coreset_freq_dom,n_rb_offset,coreset_time_dur,n_shift,reg_bundle_size_L,coreset_interleaver_size_R);
904
#endif
Agustin's avatar
Agustin committed
905 906 907 908 909 910 911 912 913 914 915

  //
  // according to 38.213 v15.1.0: a PDCCH monitoring pattern within a slot,
  // indicating first symbol(s) of the control resource set within a slot
  // for PDCCH monitoring, by higher layer parameter monitoringSymbolsWithinSlot
  //
  // at the moment we do not implement this and start_symbol is always 0
  // note that the bitmap symbol_mon may indicate several monitoring times within a same slot (symbols 0..13)
  // this may lead to a modification in ue scheduler

  // indicates the number of active CORESETs for the current BWP to decode PDCCH: max is 3 (this variable is not useful here, to be removed)
916
  //uint8_t  coreset_nbr_act;
Agustin's avatar
Agustin committed
917 918 919 920 921 922 923 924 925
  // indicates the number of REG contained in the PDCCH (number of RBs * number of symbols, in CORESET)
  uint8_t  coreset_nbr_reg;
  uint32_t coreset_C;
  uint32_t coreset_nbr_rb = 0;

  // for (int j=0; j < coreset_nbr_act; j++) {
  // for each active CORESET (max number of active CORESETs in a BWP is 3),
  // we calculate the number of RB for each CORESET bitmap
  #ifdef NR_PDCCH_DCI_DEBUG
926
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_freq_dom=(%ld)\n",coreset_freq_dom);
Agustin's avatar
Agustin committed
927 928 929 930 931 932 933 934
  #endif
  int i; //for each bit in the coreset_freq_dom bitmap
  for (i = 0; i < 45; i++) {
    // this loop counts each bit of the bit map coreset_freq_dom, and increments nbr_RB_coreset for each bit set to '1'
    if (((coreset_freq_dom & 0x1FFFFFFFFFFF) >> i) & 0x1) coreset_nbr_rb++;
  }
  coreset_nbr_rb = 6 * coreset_nbr_rb; // coreset_nbr_rb has to be multiplied by 6 to indicate the number of PRB or REG(=12 RE) within the CORESET
  #ifdef NR_PDCCH_DCI_DEBUG
935
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_freq_dom=(%ld,%lx), coreset_nbr_rb=%d\n", coreset_freq_dom,coreset_freq_dom,coreset_nbr_rb);
Agustin's avatar
Agustin committed
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
  #endif
  coreset_nbr_reg = coreset_time_dur * coreset_nbr_rb;
  coreset_C = (uint32_t)(coreset_nbr_reg / (reg_bundle_size_L * coreset_interleaver_size_R));
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> coreset_nbr_rb=%d, coreset_nbr_reg=%d, coreset_C=(%d/(%d*%d))=%d\n",
            coreset_nbr_rb, coreset_nbr_reg, coreset_nbr_reg, reg_bundle_size_L,coreset_interleaver_size_R, coreset_C);
  #endif

  for (int s = start_symbol; s < (start_symbol + coreset_time_dur); s++) {
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter process pdcch ofdm symbol s=%d where coreset_time_dur=%d\n",s,coreset_time_dur);


    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter nr_pdcch_extract_rbs_single(is_secondary_ue=%d) to remove DM-RS PDCCH\n",
              is_secondary_ue);
951
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in nr_pdcch_extract_rbs_single(rxdataF -> rxdataF_ext || dl_ch_estimates -> dl_ch_estimates_ext)\n");
Agustin's avatar
Agustin committed
952 953 954 955 956 957 958 959 960 961
    #endif
    nr_pdcch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].rxdataF,
                                common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[nr_tti_rx]].dl_ch_estimates[eNB_id],
                                pdcch_vars[eNB_id]->rxdataF_ext,
                                pdcch_vars[eNB_id]->dl_ch_estimates_ext,
                                s,
                                high_speed_flag,
                                frame_parms,
                                coreset_freq_dom,
                                coreset_nbr_rb,
962
                                n_rb_offset);
Agustin's avatar
Agustin committed
963 964 965

    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter pdcch_channel_level(avgP=%d) => compute channel level based on ofdm symbol 0, pdcch_vars[eNB_id]->dl_ch_estimates_ext\n",avgP);
966
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in pdcch_channel_level(dl_ch_estimates_ext -> dl_ch_estimates_ext)\n");
Agustin's avatar
Agustin committed
967 968 969 970 971
    #endif
    // compute channel level based on ofdm symbol 0
    pdcch_channel_level(pdcch_vars[eNB_id]->dl_ch_estimates_ext,
                        frame_parms,
                        avgP,
972
                        coreset_nbr_rb);
Agustin's avatar
Agustin committed
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
    avgs = 0;
    for (aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
      for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
        avgs = cmax(avgs, avgP[(aarx << 1) + aatx]);
    log2_maxh = (log2_approx(avgs) / 2) + 5;  //+frame_parms->nb_antennas_rx;
#ifdef UE_DEBUG_TRACE
LOG_D(PHY,"nr_tti_rx %d: pdcch log2_maxh = %d (%d,%d)\n",nr_tti_rx,log2_maxh,avgP[0],avgs);
#endif

#if T_TRACER
T(T_UE_PHY_PDCCH_ENERGY, T_INT(eNB_id), T_INT(0), T_INT(frame%1024), T_INT(nr_tti_rx),
  T_INT(avgP[0]), T_INT(avgP[1]), T_INT(avgP[2]), T_INT(avgP[3]));
#endif
    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter nr_pdcch_channel_compensation(log2_maxh=%d)\n",log2_maxh);
988
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in nr_pdcch_channel_compensation(rxdataF_ext x dl_ch_estimates_ext -> rxdataF_comp)\n");
Agustin's avatar
Agustin committed
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
    #endif
    // compute LLRs for ofdm symbol 0 only
    nr_pdcch_channel_compensation(pdcch_vars[eNB_id]->rxdataF_ext,
                                  pdcch_vars[eNB_id]->dl_ch_estimates_ext,
                                  pdcch_vars[eNB_id]->rxdataF_comp,
                                  (aatx > 1) ? pdcch_vars[eNB_id]->rho : NULL,
                                  frame_parms,
                                  s,
                                  log2_maxh,
                                  coreset_nbr_rb); // log2_maxh+I0_shift


#ifdef DEBUG_PHY

	if (nr_tti_rx==5)
	write_output("rxF_comp_d.m","rxF_c_d",&pdcch_vars[eNB_id]->rxdataF_comp[0][s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);

#endif

#ifdef MU_RECEIVER

	if (is_secondary_ue) {
		//get MF output for interfering stream
		pdcch_channel_compensation(pdcch_vars[eNB_id_i]->rxdataF_ext,
				pdcch_vars[eNB_id_i]->dl_ch_estimates_ext,
				pdcch_vars[eNB_id_i]->rxdataF_comp,
				(aatx>1) ? pdcch_vars[eNB_id_i]->rho : NULL,
				frame_parms,
				0,
				log2_maxh);// log2_maxh+I0_shift
#ifdef DEBUG_PHY
		write_output("rxF_comp_i.m","rxF_c_i",&pdcch_vars[eNB_id_i]->rxdataF_comp[0][s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
#endif
		pdcch_dual_stream_correlation(frame_parms,
				0,
				pdcch_vars[eNB_id]->dl_ch_estimates_ext,
				pdcch_vars[eNB_id_i]->dl_ch_estimates_ext,
				pdcch_vars[eNB_id]->dl_ch_rho_ext,
				log2_maxh);
	}

#endif //MU_RECEIVER

    if (frame_parms->nb_antennas_rx > 1) {
#ifdef MU_RECEIVER

		if (is_secondary_ue) {
			pdcch_detection_mrc_i(frame_parms,
					pdcch_vars[eNB_id]->rxdataF_comp,
					pdcch_vars[eNB_id_i]->rxdataF_comp,
					pdcch_vars[eNB_id]->rho,
					pdcch_vars[eNB_id]->dl_ch_rho_ext,
					0);
#ifdef DEBUG_PHY
			write_output("rxF_comp_d.m","rxF_c_d",&pdcch_vars[eNB_id]->rxdataF_comp[0][s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
			write_output("rxF_comp_i.m","rxF_c_i",&pdcch_vars[eNB_id_i]->rxdataF_comp[0][s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);
#endif
		} else
#endif //MU_RECEIVER
      #ifdef NR_PDCCH_DCI_DEBUG
        printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter pdcch_detection_mrc(frame_parms->nb_antennas_rx=%d)\n",
                frame_parms->nb_antennas_rx);
      #endif
      pdcch_detection_mrc(frame_parms, pdcch_vars[eNB_id]->rxdataF_comp,s);
    }

#ifdef MU_RECEIVER

	if (is_secondary_ue) {
		pdcch_qpsk_qpsk_llr(frame_parms,
				pdcch_vars[eNB_id]->rxdataF_comp,
				pdcch_vars[eNB_id_i]->rxdataF_comp,
				pdcch_vars[eNB_id]->dl_ch_rho_ext,
				pdcch_vars[eNB_id]->llr16, //subsequent function require 16 bit llr, but output must be 8 bit (actually clipped to 4, because of the Viterbi decoder)
				pdcch_vars[eNB_id]->llr,
				0);
		/*
		 #ifdef DEBUG_PHY
		 if (subframe==5) {
		 write_output("llr8_seq.m","llr8",&pdcch_vars[eNB_id]->llr[s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,4);
		 write_output("llr16_seq.m","llr16",&pdcch_vars[eNB_id]->llr16[s*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,4);
		 }
		 #endif*/
	} else {
#endif //MU_RECEIVER

    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter nr_pdcch_llr(for symbol %d), pdcch_vars[eNB_id]->rxdataF_comp ---> pdcch_vars[eNB_id]->llr \n",s);
1077
      printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> in nr_pdcch_llr(rxdataF_comp -> llr)\n");
Agustin's avatar
Agustin committed
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
    #endif
    nr_pdcch_llr(frame_parms,
                 pdcch_vars[eNB_id]->rxdataF_comp,
                 (char *) pdcch_vars[eNB_id]->llr,
                 s,
                 coreset_nbr_rb);

#ifdef MU_RECEIVER
}
#endif //MU_RECEIVER
#if T_TRACER
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1089 1090
/*
  T(T_UE_PHY_PDCCH_IQ, T_INT(frame_parms->N_RB_DL), T_INT(frame_parms->N_RB_DL),
Agustin's avatar
Agustin committed
1091 1092
  T_INT(n_pdcch_symbols),
  T_BUFFER(pdcch_vars[eNB_id]->rxdataF_comp, frame_parms->N_RB_DL*12*n_pdcch_symbols* 4));
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1093
*/
Agustin's avatar
Agustin committed
1094 1095 1096 1097 1098 1099 1100 1101
#endif
#ifdef DEBUG_DCI_DECODING
	printf("demapping: nr_tti_rx %d, mi %d, tdd_config %d\n",nr_tti_rx,get_mi(frame_parms,nr_tti_rx),frame_parms->tdd_config);
#endif

  }


hongzhi wang's avatar
hongzhi wang committed
1102 1103 1104
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we enter nr_pdcch_demapping_deinterleaving()\n");
  #endif
Agustin's avatar
Agustin committed
1105

hongzhi wang's avatar
hongzhi wang committed
1106 1107 1108 1109 1110 1111 1112 1113
nr_pdcch_demapping_deinterleaving(pdcch_vars[eNB_id]->llr,
                                       (uint16_t*) pdcch_vars[eNB_id]->e_rx,
                                       frame_parms,
                                       coreset_time_dur,
                                       coreset_nbr_rb,
                                       reg_bundle_size_L,
                                       coreset_interleaver_size_R,
                                       n_shift);
Agustin's avatar
Agustin committed
1114 1115 1116 1117 1118


  nr_pdcch_unscrambling(pdcch_vars[eNB_id]->crnti,
                        frame_parms,
                        nr_tti_rx,
1119
                        (uint16_t*) pdcch_vars[eNB_id]->e_rx,
Agustin's avatar
Agustin committed
1120 1121 1122 1123
                        coreset_time_dur*coreset_nbr_rb*9*2,
                        // get_nCCE(n_pdcch_symbols, frame_parms, mi) * 72,
                        pdcch_DMRS_scrambling_id,
                        do_common);
1124
  #ifdef NR_PDCCH_DCI_DEBUG
1125 1126
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> we end nr_pdcch_unscrambling()\n");
  #endif
Agustin's avatar
Agustin committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167

  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t<-NR_PDCCH_DCI_DEBUG (nr_rx_pdcch)-> Ending nr_rx_pdcch() function\n");
  #endif
  return (0);
}
#endif



void pdcch_scrambling(NR_DL_FRAME_PARMS *frame_parms,
                      uint8_t nr_tti_rx,
                      uint8_t *e,
                      uint32_t length)
{
  int i;
  uint8_t reset;
  uint32_t x1, x2, s=0;

  reset = 1;
  // x1 is set in lte_gold_generic

  x2 = (nr_tti_rx<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.8.2

  for (i=0; i<length; i++) {
    if ((i&0x1f)==0) {
      s = lte_gold_generic(&x1, &x2, reset);
      //printf("lte_gold[%d]=%x\n",i,s);
      reset = 0;
    }

    //    printf("scrambling %d : e %d, c %d\n",i,e[i],((s>>(i&0x1f))&1));
    if (e[i] != 2) // <NIL> element is 2
      e[i] = (e[i]&1) ^ ((s>>(i&0x1f))&1);
  }
}


#ifdef NR_PDCCH_DCI_RUN

void nr_pdcch_unscrambling(uint16_t crnti, NR_DL_FRAME_PARMS *frame_parms, uint8_t nr_tti_rx,
1168 1169 1170 1171 1172 1173 1174
		uint16_t *z, uint32_t length, uint16_t pdcch_DMRS_scrambling_id, int do_common) {

	int i;
	uint8_t reset;
	uint32_t x1, x2, s = 0;
  uint16_t n_id; //{0,1,...,65535}
  uint32_t n_rnti;
Agustin's avatar
Agustin committed
1175

1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
	reset = 1;
	// x1 is set in first call to lte_gold_generic
	//do_common=1;
if (do_common){
  n_id = frame_parms->Nid_cell;
  n_rnti = 0;
} else {
  n_id = pdcch_DMRS_scrambling_id;
  n_rnti = (uint32_t)crnti;
}
//x2 = ((n_rnti * (1 << 16)) + n_id)%(1 << 31);
//uint32_t puissance_2_16 = ((1<<16)*n_rnti)+n_id;
//uint32_t puissance_2_31= (1<<30)*2;
//uint32_t calc_x2=puissance_2_16%puissance_2_31;
1190
 x2 = (((1<<16)*n_rnti)+n_id); //mod 2^31 is implicit //this is c_init in 38.211 v15.1.0 Section 7.3.2.3
1191 1192 1193
//	x2 = (nr_tti_rx << 9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.8.2
#ifndef NR_PDCCH_DCI_DEBUG
printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_unscrambling)->  (c_init=%d, n_id=%d, n_rnti=%d, length=%d)\n",x2,n_id,n_rnti,length);
Agustin's avatar
Agustin committed
1194
#endif
1195 1196 1197 1198 1199 1200
	for (i = 0; i < length; i++) {
		if ((i & 0x1f) == 0) {
			s = lte_gold_generic(&x1, &x2, reset);
			      //printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_unscrambling)-> lte_gold[%d]=%x\n",i,s);
			reset = 0;
		}
Agustin's avatar
Agustin committed
1201

1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
        #ifndef NR_PDCCH_DCI_DEBUG
		if (i%2 == 0) printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_unscrambling)->  unscrambling %d : scrambled_z=%d, => ",
		i,*(char*) &z[(int)floor(i/2)]);
		if (i%2 == 1) printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_unscrambling)->  unscrambling %d : scrambled_z=%d, => ",
		i,*(1 + (char*) &z[(int)floor(i/2)]));
        #endif
		if (((s >> (i % 32)) & 1) == 1){
		    if (i%2 == 0) *(char*) &z[(int)floor(i/2)] = -(*(char*) &z[(int)floor(i/2)]);
		    if (i%2 == 1) *(1 + (char*) &z[(int)floor(i/2)]) = -(*(1 + (char*) &z[(int)floor(i/2)]));
		}
			//llr[i] = -llr[i];
			//llr[i] = (-1)*llr[i];
        #ifndef NR_PDCCH_DCI_DEBUG
		if (i%2 == 0) printf("unscrambled_z=%d\n",*(char*) &z[(int)floor(i/2)]);
1216 1217
		if (i%2 == 1) printf("unscrambled_z=%d\n",*(1 + (char*) &z[(int)floor(i/2)]));
        #endif
Agustin's avatar
Agustin committed
1218

1219 1220
	}
}
Agustin's avatar
Agustin committed
1221

1222
#endif
Agustin's avatar
Agustin committed
1223 1224 1225


#ifdef NR_PDCCH_DCI_RUN
1226
void nr_dci_decoding_procedure0(int s,                                                                        
hongzhi wang's avatar
hongzhi wang committed
1227 1228
                                int p,
                                int coreset_time_dur,
1229 1230 1231 1232 1233 1234 1235
                                uint16_t coreset_nbr_rb,                                                     
                                NR_UE_PDCCH **pdcch_vars,                                                    
                                int do_common,                                                                
                                uint8_t nr_tti_rx,                                                            
                                NR_DCI_ALLOC_t *dci_alloc,                                                    
                                int16_t eNB_id,                                                               
                                uint8_t current_thread_id,                                                    
hongzhi wang's avatar
hongzhi wang committed
1236
                                NR_DL_FRAME_PARMS *frame_parms,
1237
                                t_nrPolar_paramsPtr *nrPolar_params,                                          
1238
                                //uint8_t mi,
1239
                                uint16_t crc_scrambled_values[TOTAL_NBR_SCRAMBLED_VALUES],                                            
Agustin's avatar
Agustin committed
1240
                                uint8_t L,
1241 1242
                                NR_UE_SEARCHSPACE_CSS_DCI_FORMAT_t format_css,
                                NR_UE_SEARCHSPACE_USS_DCI_FORMAT_t format_uss,
Agustin's avatar
Agustin committed
1243 1244 1245
                                uint8_t sizeof_bits,
                                uint8_t sizeof_bytes,
                                uint8_t *dci_cnt,
1246 1247
                                crc_scrambled_t *crc_scrambled,
                                format_found_t *format_found,
hongzhi wang's avatar
hongzhi wang committed
1248
                                uint16_t pdcch_DMRS_scrambling_id,
Agustin's avatar
Agustin committed
1249 1250 1251 1252 1253 1254
                                uint32_t *CCEmap0,
                                uint32_t *CCEmap1,
                                uint32_t *CCEmap2) {

  uint16_t crc, CCEind, nCCE[3];
  uint32_t *CCEmap = NULL, CCEmap_mask = 0;
1255
  uint8_t L2 = (1 << L);
Agustin's avatar
Agustin committed
1256 1257
  unsigned int Yk, nb_candidates = 0, i, m;
  unsigned int CCEmap_cand;
1258 1259
  double *polar_input = malloc (sizeof(double) * 108*L2);
  int8_t decoderState=0;
Agustin's avatar
Agustin committed
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270

  // A[p], p is the current active CORESET
  uint16_t A[3]={39827,39829,39839};
  //Table 10.1-2: Maximum number of PDCCH candidates    per slot and per serving cell as a function of the subcarrier spacing value 2^mu*15 KHz, mu {0,1,2,3}
  uint8_t m_max_slot_pdcch_Table10_1_2 [4] = {44,36,22,20};
  //Table 10.1-3: Maximum number of non-overlapped CCEs per slot and per serving cell as a function of the subcarrier spacing value 2^mu*15 KHz, mu {0,1,2,3}
  uint8_t cce_max_slot_pdcch_Table10_1_3 [4] = {56,56,48,32};

  int coreset_nbr_cce_per_symbol=0;

  #ifdef NR_PDCCH_DCI_DEBUG
1271
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> format_found is %d \n", *format_found);
Agustin's avatar
Agustin committed
1272 1273
  #endif

1274 1275 1276 1277 1278 1279
  //if (mode == NO_DCI) {
  //  #ifdef NR_PDCCH_DCI_DEBUG
  //    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> skip DCI decoding: expect no DCIs at nr_tti_rx %d in current searchSpace\n", nr_tti_rx);
  //  #endif
  //  return;
  //}
Agustin's avatar
Agustin committed
1280 1281

  #ifdef NR_PDCCH_DCI_DEBUG
1282
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> frequencyDomainResources=%lx, duration=%d\n",
Agustin's avatar
Agustin committed
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
            pdcch_vars[eNB_id]->coreset[p].frequencyDomainResources, pdcch_vars[eNB_id]->coreset[p].duration);
  #endif

  // nCCE = get_nCCE(pdcch_vars[eNB_id]->num_pdcch_symbols, frame_parms, mi);
  for (int i = 0; i < 45; i++) {
    // this loop counts each bit of the bit map coreset_freq_dom, and increments nbr_RB_coreset for each bit set to '1'
    if (((pdcch_vars[eNB_id]->coreset[p].frequencyDomainResources & 0x1FFFFFFFFFFF) >> i) & 0x1) coreset_nbr_cce_per_symbol++;
  }
  nCCE[p] = pdcch_vars[eNB_id]->coreset[p].duration*coreset_nbr_cce_per_symbol; // 1 CCE = 6 RB
  // p is the current CORESET we are currently monitoring (among the 3 possible CORESETs in a BWP)
  // the number of CCE in the current CORESET is:
  //   the number of symbols in the CORESET (pdcch_vars[eNB_id]->coreset[p].duration)
  //   multiplied by the number of bits set to '1' in the frequencyDomainResources bitmap
  //   (1 bit set to '1' corresponds to 6 RB and 1 CCE = 6 RB)
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> nCCE[%d]=%d\n",p,nCCE[p]);
  #endif

/*	if (nCCE > get_nCCE(3, frame_parms, 1)) {
		LOG_D(PHY,
				"skip DCI decoding: nCCE=%d > get_nCCE(3,frame_parms,1)=%d\n",
				nCCE, get_nCCE(3, frame_parms, 1));
		return;
	}

	if (nCCE < L2) {
		LOG_D(PHY, "skip DCI decoding: nCCE=%d < L2=%d\n", nCCE, L2);
		return;
	}

	if (mode == NO_DCI) {
		LOG_D(PHY, "skip DCI decoding: expect no DCIs at nr_tti_rx %d\n",
				nr_tti_rx);
		return;
	}
*/
  if (do_common == 1) {
    Yk = 0;
    if (pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.common_dci_formats == cformat2_0) {
        // for dci_format_2_0, the nb_candidates is obtained from a different variable
        switch (L2) {
        case 1:
          nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.sfi_nrofCandidates_aggrlevel1;
          break;
        case 2:
          nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.sfi_nrofCandidates_aggrlevel2;
          break;
        case 4:
          nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.sfi_nrofCandidates_aggrlevel4;
          break;
        case 8:
          nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.sfi_nrofCandidates_aggrlevel8;
          break;
        case 16:
          nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.sfi_nrofCandidates_aggrlevel16;
          break;
        default:
          break;
        }
    } else if (pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.common_dci_formats == cformat2_3) {
        // for dci_format_2_3, the nb_candidates is obtained from a different variable
        nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].searchSpaceType.srs_nrofCandidates;
    } else {
      nb_candidates = (L2 == 4) ? 4 : ((L2 == 8)? 2 : 1); // according to Table 10.1-1 (38.213 section 10.1)
      #ifdef NR_PDCCH_DCI_DEBUG
1348
        printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> we are in common searchSpace and nb_candidates=%d for L2=%d\n",nb_candidates,L2);
Agustin's avatar
Agustin committed
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
      #endif
    }
  } else {
    switch (L2) {
    case 1:
      nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].nrofCandidates_aggrlevel1;
      break;
    case 2:
      nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].nrofCandidates_aggrlevel2;
      break;
    case 4:
      nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].nrofCandidates_aggrlevel4;
      break;
    case 8:
      nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].nrofCandidates_aggrlevel8;
      break;
    case 16:
      nb_candidates = pdcch_vars[eNB_id]->searchSpace[s].nrofCandidates_aggrlevel16;
      break;
    default:
      break;
    }
1371

Agustin's avatar
Agustin committed
1372 1373 1374 1375 1376
    // Find first available in ue specific search space
    // according to procedure in Section 10.1 of 38.213
    // compute Yk
    Yk = (unsigned int) pdcch_vars[eNB_id]->crnti;
    for (i = 0; i <= nr_tti_rx; i++)
1377
      Yk = (Yk * A[p%3]) % 65537;
Agustin's avatar
Agustin committed
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
  }
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> L2(%d) | nCCE[%d](%d) | Yk(%d) | nb_candidates(%d)\n",L2,p,nCCE[p],Yk,nb_candidates);
  #endif
  /*  for (CCEind=0;
	 CCEind<nCCE2;
	 CCEind+=(1<<L)) {*/
//	if (nb_candidates * L2 > nCCE[p])
//		nb_candidates = nCCE[p] / L2;

// In the next code line there is maybe a bug. The spec is not comparing Table 10.1-2 with nb_candidates, but with total number of candidates for all s and all p
1389
  int m_p_s_L_max = (m_max_slot_pdcch_Table10_1_2[1]<=nb_candidates ? m_max_slot_pdcch_Table10_1_2[1] : nb_candidates);
Agustin's avatar
Agustin committed
1390 1391 1392 1393 1394 1395
  if (L==4) m_p_s_L_max=1; // Table 10.1-2 is not defined for L=4
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> m_max_slot_pdcch_Table10_1_2(%d)=%d\n",L,m_max_slot_pdcch_Table10_1_2[L]);
  #endif
  for (m = 0; m < nb_candidates; m++) {
    int n_ci = 0;
1396
    if (nCCE[p] < L2) return;
Agustin's avatar
Agustin committed
1397 1398 1399 1400 1401 1402
    int debug1 = nCCE[p] / L2;
    int debug2 = L2*m_p_s_L_max;
    #ifdef NR_PDCCH_DCI_DEBUG
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> debug1(%d)=nCCE[p]/L2 | nCCE[%d](%d) | L2(%d)\n",debug1,p,nCCE[p],L2);
      printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> debug2(%d)=L2*m_p_s_L_max | L2(%d) | m_p_s_L_max(%d)\n",debug2,L2,m_p_s_L_max);
    #endif
1403
    CCEind = (((Yk + (uint16_t)(floor((m*nCCE[p])/(L2*m_p_s_L_max))) + n_ci) % (uint16_t)(floor(nCCE[p] / L2))) * L2);
Agustin's avatar
Agustin committed
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456
    #ifdef NR_PDCCH_DCI_DEBUG
      printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> CCEind(%d) = (((Yk(%d) + ((m(%d)*nCCE[p](%d))/(L2(%d)*m_p_s_L_max(%d)))) % (nCCE[p] / L2)) * L2)\n",
               CCEind,Yk,m,nCCE[p],L2,m_p_s_L_max);
      printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> n_candidate(m)=%d | CCEind=%d |",m,CCEind);
    #endif
    if (CCEind < 32)
      CCEmap = CCEmap0;
    else if (CCEind < 64)
      CCEmap = CCEmap1;
    else if (CCEind < 96)
      CCEmap = CCEmap2;
    else {
      LOG_E(PHY, "Illegal CCEind %d (Yk %d, m %d, nCCE %d, L2 %d\n",CCEind, Yk, m, nCCE, L2);
      //mac_xface->macphy_exit("Illegal CCEind\n");
      return; // not reached
    }

    switch (L2) {
      case 1:
        CCEmap_mask = (1 << (CCEind & 0x1f));
        break;
      case 2:
        CCEmap_mask = (3 << (CCEind & 0x1f));
        break;
      case 4:
        CCEmap_mask = (0xf << (CCEind & 0x1f));
        break;
      case 8:
        CCEmap_mask = (0xff << (CCEind & 0x1f));
        break;
      case 16:
        CCEmap_mask = (0xfff << (CCEind & 0x1f));
        break;
      default:
        LOG_E(PHY, "Illegal L2 value %d\n", L2);
        //mac_xface->macphy_exit("Illegal L2\n");
        return; // not reached
    }
    CCEmap_cand = (*CCEmap) & CCEmap_mask;
    // CCE is not allocated yet
    #ifdef NR_PDCCH_DCI_DEBUG
      printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> CCEmap_cand=%d \n",CCEmap_cand);
    #endif

    if (CCEmap_cand == 0) {
      #ifdef DEBUG_DCI_DECODING
        if (do_common == 1)
          LOG_I(PHY,"[DCI search nPdcch %d - common] Attempting candidate %d Aggregation Level %d DCI length %d at CCE %d/%d (CCEmap %x,CCEmap_cand %x)\n",
                    pdcch_vars[eNB_id]->num_pdcch_symbols,m,L2,sizeof_bits,CCEind,nCCE,*CCEmap,CCEmap_mask);
        else
          LOG_I(PHY,"[DCI search nPdcch %d - ue spec] Attempting candidate %d Aggregation Level %d DCI length %d at CCE %d/%d (CCEmap %x,CCEmap_cand %x) format %d\n",
                    pdcch_vars[eNB_id]->num_pdcch_symbols,m,L2,sizeof_bits,CCEind,nCCE,*CCEmap,CCEmap_mask,format_c);
      #endif
1457
      #ifndef NR_PDCCH_DCI_DEBUG
Agustin's avatar
Agustin committed
1458 1459 1460 1461
        printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> ... we enter function dci_decoding(sizeof_bits=%d L=%d) -----\n",sizeof_bits,L);
        printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> ... we have to replace this part of the code by polar decoding\n");
      #endif

hongzhi wang's avatar
hongzhi wang committed
1462

1463
//      for (int m=0; m < (nCCE[p]*6*9*2); m++)
Agustin's avatar
Agustin committed
1464
      #ifdef NR_PDCCH_DCI_DEBUG
1465
        printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0: polar decoding)-> polar intput (with coreset_time_dur=%d, coreset_nbr_rb=%d, p=%d, CCEind=%d): \n",
hongzhi wang's avatar
hongzhi wang committed
1466
                coreset_time_dur,coreset_nbr_rb,p,CCEind);
Agustin's avatar
Agustin committed
1467
      #endif
1468
      int reg_p=0,reg_e=0;
hongzhi wang's avatar
hongzhi wang committed
1469
      for (int m=0; m < (L2*6); m++){
1470 1471 1472
        reg_p = (((int)floor(m/coreset_time_dur))+((m%coreset_time_dur)*(L2*6/coreset_time_dur)))*9*2;
        reg_e = m*9*2;
        for (int i=0; i<9*2; i++){
1473 1474 1475 1476 1477 1478
          //polar_input[reg_p+i] = (pdcch_vars[eNB_id]->e_rx[((CCEind*9*6*2) + reg_e + i)]>0) ? (1.0):(-1.0);
          polar_input[reg_e+i] = (pdcch_vars[eNB_id]->e_rx[((CCEind*9*6*2) + reg_e + i)]>0) ? (1/sqrt(2)):((-1)/sqrt(2));
          //printf("\t m=%d \tpolar_input[%d]=%lf <-> e_rx[%d]=%d\n",m,reg_e+i,polar_input[reg_e+i],
          //        ((CCEind*9*6*2) + reg_e + i),pdcch_vars[eNB_id]->e_rx[((CCEind*9*6*2) + reg_e + i)]);
          //printf("\t m=%d \tpolar_input[%d]=%lf <-> e_rx[%d]=%d\n",m,reg_p+i,polar_input[reg_p+i],
          //        ((CCEind*9*6*2) + reg_e + i),pdcch_vars[eNB_id]->e_rx[((CCEind*9*6*2) + reg_e + i)]);
1479
	    }
hongzhi wang's avatar
hongzhi wang committed
1480
	  }
1481

1482
      #ifndef NR_PDCCH_DCI_DEBUG
hongzhi wang's avatar
hongzhi wang committed
1483 1484 1485 1486 1487
	    printf("\n");
	    int j=0;
	    uint32_t polar_hex[27] = {0};
	    for (int i=0; i<L2*9*6*2; i++){
			if ((i%32 == 0) && (i!=0)) j++;
1488 1489
			//polar_hex[j] = (polar_hex[j]<<1) + ((polar_input[i]==-1)? 1:0);
			polar_hex[j] = polar_hex[j] + (((polar_input[i]==((-1)/sqrt(2)))?1:0)<<(i%32));
hongzhi wang's avatar
hongzhi wang committed
1490
		}
1491
		for (j=0;j<27;j++) printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0: polar decoding input)-> polar_hex[%d]=%x\n",j,polar_hex[j]);
hongzhi wang's avatar
hongzhi wang committed
1492 1493
      #endif
     
1494 1495
uint32_t dci_estimation[4]={0};
uint16_t rnti=3;
1496
      #ifdef PDCCH_TEST_POLAR_TEMP_FIX
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
      	  t_nrPolar_paramsPtr nrPolar_params = NULL;
      	  nr_polar_init(&nrPolar_params, 1, 41, 8);
      	  t_nrPolar_paramsPtr currentPtrDCI=nr_polar_params(nrPolar_params, 1, 41, 8);
	  decoderState = polar_decoder_dci(polar_input,
									 dci_estimation,
									 currentPtrDCI,//nrPolar_params,
									 8,//NR_POLAR_DECODER_LISTSIZE,
									 0,//NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION,
									 rnti); //rnti
 	  printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0: \t\tpolar decoding)-> decoderState %d\n", decoderState);				   
     #endif
    //dci_estimation[0] = 0x01189400;
	printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0: \t\tdci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n",
			dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]);

	crc = rnti;						   
    //crc = (crc16(&dci_decoded_output[current_thread_id][0], sizeof_bits) >> 16) ^ extract_crc(&dci_decoded_output[current_thread_id][0], sizeof_bits);
    #ifndef NR_PDCCH_DCI_DEBUG
       printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> ... we end function dci_decoding() with crc=%x\n",crc);
       printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> ... we have to replace this part of the code by polar decoding\n");
    #endif
    #ifdef DEBUG_DCI_DECODING
       printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0: crc =>%d\n",crc);
    #endif //uint16_t tc_rnti, uint16_t int_rnti, uint16_t sfi_rnti, uint16_t tpc_pusch_rnti, uint16_t tpc_pucch_rnti, uint16_t tpc_srs__rnti
    #ifdef NR_PDCCH_DCI_DEBUG
1522 1523 1524 1525 1526 1527 1528
       printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> format_found=%d\n",*format_found);
       printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> crc_scrambled=%d\n",*crc_scrambled);
     #endif

      if (crc == crc_scrambled_values[_C_RNTI_])  {
        *crc_scrambled =_c_rnti;
        *format_found=1;
Agustin's avatar
Agustin committed
1529
      }
1530 1531 1532
      if (crc == crc_scrambled_values[_CS_RNTI_])  {
        *crc_scrambled =_cs_rnti;
        *format_found=1;
Agustin's avatar
Agustin committed
1533
      }
1534 1535 1536
      if (crc == crc_scrambled_values[_NEW_RNTI_])  {
        *crc_scrambled =_new_rnti;
        *format_found=1;
Agustin's avatar
Agustin committed
1537
      }
1538 1539 1540
      if (crc == crc_scrambled_values[_TC_RNTI_])  {
        *crc_scrambled =_tc_rnti;
        *format_found=_format_1_0_found;
Agustin's avatar
Agustin committed
1541
      }
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
      if (crc == crc_scrambled_values[_P_RNTI_])  {
        *crc_scrambled =_p_rnti;
        *format_found=_format_1_0_found;
      }
      if (crc == crc_scrambled_values[_SI_RNTI_])  {
        *crc_scrambled =_si_rnti;
        *format_found=_format_1_0_found;
      }
      if (crc == crc_scrambled_values[_RA_RNTI_])  {
        *crc_scrambled =_ra_rnti;
        *format_found=_format_1_0_found;
      }
      if (crc == crc_scrambled_values[_SP_CSI_RNTI_])  {
        *crc_scrambled =_sp_csi_rnti;
        *format_found=_format_0_1_found;
      }
      if (crc == crc_scrambled_values[_SFI_RNTI_])  {
        *crc_scrambled =_sfi_rnti;
        *format_found=_format_2_0_found;
      }
      if (crc == crc_scrambled_values[_INT_RNTI_])  {
        *crc_scrambled =_int_rnti;
        *format_found=_format_2_1_found;
      }
      if (crc == crc_scrambled_values[_TPC_PUSCH_RNTI_]) {
        *crc_scrambled =_tpc_pusch_rnti;
        *format_found=_format_2_2_found;
      }
      if (crc == crc_scrambled_values[_TPC_PUCCH_RNTI_]) {
        *crc_scrambled =_tpc_pucch_rnti;
        *format_found=_format_2_2_found;
      }
      if (crc == crc_scrambled_values[_TPC_SRS_RNTI_]) {
        *crc_scrambled =_tpc_srs_rnti;
        *format_found=_format_2_3_found;
      }
#ifdef NR_PDCCH_DCI_DEBUG
1579
  printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> format_found=%d\n",*format_found);
1580 1581 1582
  printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> crc_scrambled=%d\n",*crc_scrambled);
#endif
      if (*format_found!=255) {
Agustin's avatar
Agustin committed
1583 1584 1585 1586
        dci_alloc[*dci_cnt].dci_length = sizeof_bits;
        dci_alloc[*dci_cnt].rnti = crc;
        dci_alloc[*dci_cnt].L = L;
        dci_alloc[*dci_cnt].firstCCE = CCEind;
1587 1588 1589 1590
        dci_alloc[*dci_cnt].dci_pdu[0] = dci_estimation[0];
        dci_alloc[*dci_cnt].dci_pdu[1] = dci_estimation[1];
        dci_alloc[*dci_cnt].dci_pdu[2] = dci_estimation[2];
        dci_alloc[*dci_cnt].dci_pdu[3] = dci_estimation[3];
Agustin's avatar
Agustin committed
1591
        #ifdef NR_PDCCH_DCI_DEBUG
1592 1593 1594 1595
          printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> rnti matches -> DCI FOUND !!! crc =>%x, sizeof_bits %d, sizeof_bytes %d \n",
                   dci_alloc[*dci_cnt].rnti, dci_alloc[*dci_cnt].dci_length, sizeof_bytes);
          printf ("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> dci_cnt %d (format_css %d crc_scrambled %d) L %d, firstCCE %d pdu[0] %x pdu[1] %x pdu[2] %x pdu[3] %x \n",
                   *dci_cnt, format_css,*crc_scrambled,dci_alloc[*dci_cnt].L, dci_alloc[*dci_cnt].firstCCE,dci_alloc[*dci_cnt].dci_pdu[0],dci_alloc[*dci_cnt].dci_pdu[1],dci_alloc[*dci_cnt].dci_pdu[2],dci_alloc[*dci_cnt].dci_pdu[3]);
Agustin's avatar
Agustin committed
1596
        #endif
1597
        if ((format_css == cformat0_0_and_1_0) || (format_uss == uformat0_0_and_1_0)){
1598
          if ((*crc_scrambled == _p_rnti) || (*crc_scrambled == _si_rnti) || (*crc_scrambled == _ra_rnti)){
1599 1600
            dci_alloc[*dci_cnt].format = format1_0;
            *dci_cnt = *dci_cnt + 1;
1601 1602
            *format_found=_format_1_0_found;
            printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> a format1_0=%d and dci_cnt=%d\n",*format_found,*dci_cnt);
1603
         } else {
1604
            if ((dci_estimation[0]&1) == 0){
1605 1606
              dci_alloc[*dci_cnt].format = format0_0;
              *dci_cnt = *dci_cnt + 1;
1607 1608
              *format_found=_format_0_0_found;
              printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> b format0_0=%d and dci_cnt=%d\n",*format_found,*dci_cnt);
1609
            }
1610
            if ((dci_estimation[0]&1) == 1){
1611 1612
              dci_alloc[*dci_cnt].format = format1_0;
              *dci_cnt = *dci_cnt + 1;
1613 1614
              *format_found=_format_1_0_found;
              printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> c format1_0=%d and dci_cnt=%d\n",*format_found,*dci_cnt);
1615
           }
Agustin's avatar
Agustin committed
1616 1617
          }
        }
1618
        if (format_css == cformat2_0){
Agustin's avatar
Agustin committed
1619 1620
          dci_alloc[*dci_cnt].format = format2_0;
          *dci_cnt = *dci_cnt + 1;
1621
          *format_found=_format_2_0_found;
Agustin's avatar
Agustin committed
1622
        }
1623 1624
        if (format_css == cformat2_1){
          dci_alloc[*dci_cnt].format = format2_1;
Agustin's avatar
Agustin committed
1625
          *dci_cnt = *dci_cnt + 1;
1626
          *format_found=_format_2_1_found;
Agustin's avatar
Agustin committed
1627
        }
1628
        if (format_css == cformat2_2){
Agustin's avatar
Agustin committed
1629 1630
          dci_alloc[*dci_cnt].format = format2_2;
          *dci_cnt = *dci_cnt + 1;
1631
          *format_found=_format_2_2_found;
Agustin's avatar
Agustin committed
1632
        }
1633
        if (format_css == cformat2_3){
Agustin's avatar
Agustin committed
1634 1635
          dci_alloc[*dci_cnt].format = format2_3;
          *dci_cnt = *dci_cnt + 1;
1636
          *format_found=_format_2_3_found;
Agustin's avatar
Agustin committed
1637
        }
1638
        if (format_uss == uformat0_1_and_1_1){
1639
          if ((dci_estimation[0]&1) == 0){
1640 1641
            dci_alloc[*dci_cnt].format = format0_1;
            *dci_cnt = *dci_cnt + 1;
1642
            *format_found=_format_0_1_found;
Agustin's avatar
Agustin committed
1643
          }
1644
          if ((dci_estimation[0]&1) == 1){
1645 1646
            dci_alloc[*dci_cnt].format = format1_1;
            *dci_cnt = *dci_cnt + 1;
1647
            *format_found=_format_1_1_found;
Agustin's avatar
Agustin committed
1648 1649
          }
        }
1650 1651
        // store first nCCE of group for PUCCH transmission of ACK/NAK
        pdcch_vars[eNB_id]->nCCE[nr_tti_rx] = CCEind;
Agustin's avatar
Agustin committed
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
/*				if (crc == si_rnti) {
					dci_alloc[*dci_cnt].format = format_si;
					*dci_cnt = *dci_cnt + 1;
				} else if (crc == p_rnti) {
					dci_alloc[*dci_cnt].format = format_p;
					*dci_cnt = *dci_cnt + 1;
				} else if (crc == ra_rnti) {
					dci_alloc[*dci_cnt].format = format_ra;
					// store first nCCE of group for PUCCH transmission of ACK/NAK
					pdcch_vars[eNB_id]->nCCE[nr_tti_rx] = CCEind;
					*dci_cnt = *dci_cnt + 1;
				} else if (crc == pdcch_vars[eNB_id]->crnti) {

					if ((mode & UL_DCI) && (format_c == format0)
							&& ((dci_decoded_output[current_thread_id][0] & 0x80)
									== 0)) { // check if pdu is format 0 or 1A
						if (*format0_found == 0) {
							dci_alloc[*dci_cnt].format = format0;
							*format0_found = 1;
							*dci_cnt = *dci_cnt + 1;
							pdcch_vars[eNB_id]->nCCE[nr_tti_rx] = CCEind;
						}
					} else if (format_c == format0) { // this is a format 1A DCI
						dci_alloc[*dci_cnt].format = format1A;
						*dci_cnt = *dci_cnt + 1;
						pdcch_vars[eNB_id]->nCCE[nr_tti_rx] = CCEind;
					} else {
						// store first nCCE of group for PUCCH transmission of ACK/NAK
						if (*format_c_found == 0) {
							dci_alloc[*dci_cnt].format = format_c;
							*dci_cnt = *dci_cnt + 1;
							*format_c_found = 1;
							pdcch_vars[eNB_id]->nCCE[nr_tti_rx] = CCEind;
						}
					}
				}*/
				//LOG_I(PHY,"DCI decoding CRNTI  [format: %d, nCCE[nr_tti_rx: %d]: %d ], AggregationLevel %d \n",format_c, nr_tti_rx, pdcch_vars[eNB_id]->nCCE[nr_tti_rx],L2);
				//  memcpy(&dci_alloc[*dci_cnt].dci_pdu[0],dci_decoded_output,sizeof_bytes);
        switch (1 << L) {
          case 1:
            *CCEmap |= (1 << (CCEind & 0x1f));
            break;
          case 2:
            *CCEmap |= (1 << (CCEind & 0x1f));
            break;
          case 4:
            *CCEmap |= (1 << (CCEind & 0x1f));
            break;
          case 8:
            *CCEmap |= (1 << (CCEind & 0x1f));
            break;
          case 16:
            *CCEmap |= (1 << (CCEind & 0x1f));
            break;
        }

#ifdef DEBUG_DCI_DECODING
				LOG_I(PHY,"[DCI search] Found DCI %d rnti %x Aggregation %d length %d format %s in CCE %d (CCEmap %x) candidate %d / %d \n",
						*dci_cnt,crc,1<<L,sizeof_bits,dci_format_strings[dci_alloc[*dci_cnt-1].format],CCEind,*CCEmap,m,nb_candidates );
				dump_dci(frame_parms,&dci_alloc[*dci_cnt-1]);

#endif
        return;
      } // rnti match
    } else { // CCEmap_cand == 0
1717 1718
      printf("\n");
    }
Agustin's avatar
Agustin committed
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
/*
		 if ( agregationLevel != 0xFF &&
		 (format_c == format0 && m==0 && si_rnti != SI_RNTI))
		 {
		 //Only valid for OAI : Save some processing time when looking for DCI format0. From the log we see the DCI only on candidate 0.
		 return;
		 }
		 */
  } // candidate loop
  #ifdef NR_PDCCH_DCI_DEBUG
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_dci_decoding_procedure0)-> end candidate loop\n");
1730
  #endif
Agustin's avatar
Agustin committed
1731
}
1732

Agustin's avatar
Agustin committed
1733 1734
#endif

1735 1736


Agustin's avatar
Agustin committed
1737

1738

Agustin's avatar
Agustin committed
1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
/*void dci_decoding_procedure0(NR_UE_PDCCH **pdcch_vars,
                             int do_common,
                             dci_detect_mode_t mode,
                             uint8_t nr_tti_rx,
                             DCI_ALLOC_t *dci_alloc,
                             int16_t eNB_id,
                             uint8_t current_thread_id,
                             NR_DL_FRAME_PARMS *frame_parms,
                             uint8_t mi,
                             uint16_t si_rnti,
                             uint16_t ra_rnti,
                             uint16_t p_rnti,
                             uint8_t L,
                             uint8_t format_si,
                             uint8_t format_p,
                             uint8_t format_ra,
                             uint8_t format_c,
                             uint8_t sizeof_bits,
                             uint8_t sizeof_bytes,
                             uint8_t *dci_cnt,
                             uint8_t *format0_found,
                             uint8_t *format_c_found,
                             uint32_t *CCEmap0,
                             uint32_t *CCEmap1,
                             uint32_t *CCEmap2)
{

  uint16_t crc,CCEind,nCCE;
  uint32_t *CCEmap=NULL,CCEmap_mask=0;
  int L2=(1<<L);
  unsigned int Yk,nb_candidates = 0,i,m;
  unsigned int CCEmap_cand;
#ifdef NR_PDCCH_DCI_DEBUG
    printf("\t\t<-NR_PDCCH_DCI_DEBUG (dci_decoding_procedure0)-> \n");
#endif
  nCCE = get_nCCE(pdcch_vars[eNB_id]->num_pdcch_symbols,frame_parms,mi);

  if (nCCE > get_nCCE(3,frame_parms,1)) {
    LOG_D(PHY,"skip DCI decoding: nCCE=%d > get_nCCE(3,frame_parms,1)=%d\n", nCCE, get_nCCE(3,frame_parms,1));
    return;
  }

  if (nCCE<L2) {
    LOG_D(PHY,"skip DCI decoding: nCCE=%d < L2=%d\n", nCCE, L2);
    return;
  }

  if (mode == NO_DCI) {
    LOG_D(PHY, "skip DCI decoding: expect no DCIs at nr_tti_rx %d\n", nr_tti_rx);
    return;
  }

  if (do_common == 1) {
    nb_candidates = (L2==4) ? 4 : 2;
    Yk=0;
  } else {
    // Find first available in ue specific search space
    // according to procedure in Section 9.1.1 of 36.213 (v. 8.6)
    // compute Yk
    Yk = (unsigned int)pdcch_vars[eNB_id]->crnti;

    for (i=0; i<=nr_tti_rx; i++)
      Yk = (Yk*39827)%65537;

    Yk = Yk % (nCCE/L2);

    switch (L2) {
    case 1:
    case 2:
      nb_candidates = 6;
      break;

    case 4:
    case 8:
      nb_candidates = 2;
      break;

    default:
      DevParam(L2, do_common, eNB_id);
      break;
    }
  }

  //  for (CCEind=0;
  //     CCEind<nCCE2;
  //     CCEind+=(1<<L)) {

  if (nb_candidates*L2 > nCCE)
    nb_candidates = nCCE/L2;

  for (m=0; m<nb_candidates; m++) {

    CCEind = (((Yk+m)%(nCCE/L2))*L2);

    if (CCEind<32)
      CCEmap = CCEmap0;
    else if (CCEind<64)
      CCEmap = CCEmap1;
    else if (CCEind<96)
      CCEmap = CCEmap2;
    else {
      LOG_E(PHY,"Illegal CCEind %d (Yk %d, m %d, nCCE %d, L2 %d\n",CCEind,Yk,m,nCCE,L2);
      mac_xface->macphy_exit("Illegal CCEind\n");
      return; // not reached
    }

    switch (L2) {
    case 1:
      CCEmap_mask = (1<<(CCEind&0x1f));
      break;

    case 2:
      CCEmap_mask = (3<<(CCEind&0x1f));
      break;

    case 4:
      CCEmap_mask = (0xf<<(CCEind&0x1f));
      break;

    case 8:
      CCEmap_mask = (0xff<<(CCEind&0x1f));
      break;

    default:
      LOG_E( PHY, "Illegal L2 value %d\n", L2 );
      mac_xface->macphy_exit( "Illegal L2\n" );
      return; // not reached
    }

    CCEmap_cand = (*CCEmap)&CCEmap_mask;

    // CCE is not allocated yet

    if (CCEmap_cand == 0) {
#ifdef DEBUG_DCI_DECODING

      if (do_common == 1)
        LOG_I(PHY,"[DCI search nPdcch %d - common] Attempting candidate %d Aggregation Level %d DCI length %d at CCE %d/%d (CCEmap %x,CCEmap_cand %x)\n",
                pdcch_vars[eNB_id]->num_pdcch_symbols,m,L2,sizeof_bits,CCEind,nCCE,*CCEmap,CCEmap_mask);
      else
        LOG_I(PHY,"[DCI search nPdcch %d - ue spec] Attempting candidate %d Aggregation Level %d DCI length %d at CCE %d/%d (CCEmap %x,CCEmap_cand %x) format %d\n",
                pdcch_vars[eNB_id]->num_pdcch_symbols,m,L2,sizeof_bits,CCEind,nCCE,*CCEmap,CCEmap_mask,format_c);

1882
#endif
Agustin's avatar
Agustin committed
1883 1884 1885