proto.h 79.7 KB
Newer Older
1
/*******************************************************************************
2
    OpenAirInterface
ghaddab's avatar
ghaddab committed
3
    Copyright(c) 1999 - 2014 Eurecom
4

ghaddab's avatar
ghaddab committed
5 6 7 8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9 10


ghaddab's avatar
ghaddab committed
11 12 13 14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

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

  Contact Information
ghaddab's avatar
ghaddab committed
22 23 24
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
25

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

ghaddab's avatar
ghaddab committed
28
 *******************************************************************************/
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

/*! \file PHY/LTE_TRANSPORT/proto.h
 * \brief Function prototypes for PHY physical/transport channel processing and generation V8.6 2009-03
 * \author R. Knopp, F. Kaltenberger
 * \date 2011
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */
#ifndef __LTE_TRANSPORT_PROTO__H__
#define __LTE_TRANSPORT_PROTO__H__
#include "PHY/defs.h"
#include <math.h>

// Functions below implement 36-211 and 36-212

/** @addtogroup _PHY_TRANSPORT_
 * @{
 */

51
/** \fn free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch,unsigned char N_RB_DL)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    \brief This function frees memory allocated for a particular DLSCH at eNB
    @param dlsch Pointer to DLSCH to be removed
*/
void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch);

void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch, uint8_t abstraction_flag);

/** \fn new_eNB_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint8_t abstraction_flag)
    \brief This function allocates structures for a particular DLSCH at eNB
    @returns Pointer to DLSCH to be removed
    @param Kmimo Kmimo factor from 36-212/36-213
    @param Mdlharq Maximum number of HARQ rounds (36-212/36-213)
    @params N_RB_DL total number of resource blocks (determine the operating BW)
    @param abstraction_flag Flag to indicate abstracted interface
*/
LTE_eNB_DLSCH_t *new_eNB_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint8_t N_RB_DL, uint8_t abstraction_flag);

/** \fn free_ue_dlsch(LTE_UE_DLSCH_t *dlsch)
    \brief This function frees memory allocated for a particular DLSCH at UE
    @param dlsch Pointer to DLSCH to be removed
*/
void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch);

LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag);



void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch, uint8_t abstraction_flag);

void free_ue_ulsch(LTE_UE_ULSCH_t *ulsch);

LTE_UE_ULSCH_t *new_ue_ulsch(uint8_t Mdlharq, unsigned char N_RB_UL, uint8_t abstraction_flag);



/** \fn dlsch_encoding(uint8_t *input_buffer,
    LTE_DL_FRAME_PARMS *frame_parms,
    uint8_t num_pdcch_symbols,
    LTE_eNB_DLSCH_t *dlsch,
    int frame,
    uint8_t subframe)
    \brief This function performs a subset of the bit-coding functions for LTE as described in 36-212, Release 8.Support is limited to turbo-coded channels (DLSCH/ULSCH). The implemented functions are:
    - CRC computation and addition
    - Code block segmentation and sub-block CRC addition
    - Channel coding (Turbo coding)
    - Rate matching (sub-block interleaving, bit collection, selection and transmission
    - Code block concatenation
    @param input_buffer Pointer to input buffer for sub-frame
    @param frame_parms Pointer to frame descriptor structure
    @param num_pdcch_symbols Number of PDCCH symbols in this subframe
    @param dlsch Pointer to dlsch to be encoded
    @param frame Frame number
    @param subframe Subframe number
    @param rm_stats Time statistics for rate-matching
    @param te_stats Time statistics for turbo-encoding
    @param i_stats Time statistics for interleaving
    @returns status
*/
110
int32_t dlsch_encoding(uint8_t *a,
111 112 113 114 115 116 117 118
                       LTE_DL_FRAME_PARMS *frame_parms,
                       uint8_t num_pdcch_symbols,
                       LTE_eNB_DLSCH_t *dlsch,
                       int frame,
                       uint8_t subframe,
                       time_stats_t *rm_stats,
                       time_stats_t *te_stats,
                       time_stats_t *i_stats);
119 120

void dlsch_encoding_emul(PHY_VARS_eNB *phy_vars_eNB,
121 122
                         uint8_t *DLSCH_pdu,
                         LTE_eNB_DLSCH_t *dlsch);
123 124 125 126 127 128


// Functions below implement 36-211

/** \fn allocate_REs_in_RB(mod_sym_t **txdataF,
    uint32_t *jj,
129
    uint32_t *jj2,
130 131
    uint16_t re_offset,
    uint32_t symbol_offset,
132 133
    LTE_DL_eNB_HARQ_t *dlsch0_harq,
    LTE_DL_eNB_HARQ_t *dlsch1_harq,
134
    uint8_t pilots,
135
    int16_t amp,
136 137 138 139 140 141 142 143 144
    int16_t *qam_table_s,
    uint32_t *re_allocated,
    uint8_t skip_dc,
    uint8_t skip_half,
    uint8_t use2ndpilots,
    LTE_DL_FRAME_PARMS *frame_parms);

    \brief Fills RB with data
    \param txdataF pointer to output data (frequency domain signal)
145 146
    \param jj index to output (from CW 1)
    \param jj index to output (from CW 2)
147 148
    \param re_offset index of the first RE of the RB
    \param symbol_offset index to the OFDM symbol
149 150
    \param dlsch0_harq Pointer to Transport block 0 HARQ structure
    \param dlsch0_harq Pointer to Transport block 1 HARQ structure
151 152
    \param pilots =1 if symbol_offset is an OFDM symbol that contains pilots, 0 otherwise
    \param amp Amplitude for symbols
153 154
    \param qam_table_s0 pointer to scaled QAM table for Transport Block 0 (by rho_a or rho_b)
    \param qam_table_s1 pointer to scaled QAM table for Transport Block 1 (by rho_a or rho_b)
155 156 157 158 159 160 161
    \param re_allocated pointer to allocation counter
    \param skip_dc offset for positive RBs
    \param skip_half indicate that first or second half of RB must be skipped for PBCH/PSS/SSS
    \param use2ndpilots Set to use the pilots from antenna port 1 for PDSCH
    \param frame_parms Frame parameter descriptor
*/

162
int32_t allocate_REs_in_RB(LTE_DL_FRAME_PARMS *frame_parms,
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
                           mod_sym_t **txdataF,
                           uint32_t *jj,
                           uint32_t *jj2,
                           uint16_t re_offset,
                           uint32_t symbol_offset,
                           LTE_DL_eNB_HARQ_t *dlsch0_harq,
                           LTE_DL_eNB_HARQ_t *dlsch1_harq,
                           uint8_t pilots,
                           int16_t amp,
                           uint8_t precoder_index,
                           int16_t *qam_table_s0,
                           int16_t *qam_table_s1,
                           uint32_t *re_allocated,
                           uint8_t skip_dc,
                           uint8_t skip_half);
178

179

180 181
/** \fn int32_t dlsch_modulation(mod_sym_t **txdataF,
    int16_t amp,
182 183 184 185 186
    uint32_t sub_frame_offset,
    LTE_DL_FRAME_PARMS *frame_parms,
    uint8_t num_pdcch_symbols,
    LTE_eNB_DLSCH_t *dlsch);

187
    \brief This function is the top-level routine for generation of the sub-frame signal (frequency-domain) for DLSCH.
188 189 190 191 192
    @param txdataF Table of pointers for frequency-domain TX signals
    @param amp Amplitude of signal
    @param sub_frame_offset Offset of this subframe in units of subframes (usually 0)
    @param frame_parms Pointer to frame descriptor
    @param num_pdcch_symbols Number of PDCCH symbols in this subframe
193 194
    @param dlsch0 Pointer to Transport Block 0 DLSCH descriptor for this allocation
    @param dlsch1 Pointer to Transport Block 0 DLSCH descriptor for this allocation
195

196
*/
197
int32_t dlsch_modulation(mod_sym_t **txdataF,
198 199 200 201 202 203
                         int16_t amp,
                         uint32_t sub_frame_offset,
                         LTE_DL_FRAME_PARMS *frame_parms,
                         uint8_t num_pdcch_symbols,
                         LTE_eNB_DLSCH_t *dlsch0,
                         LTE_eNB_DLSCH_t *dlsch1);
204
/*
205
  \brief This function is the top-level routine for generation of the sub-frame signal (frequency-domain) for MCH.
206 207 208 209 210 211 212
  @param txdataF Table of pointers for frequency-domain TX signals
  @param amp Amplitude of signal
  @param subframe_offset Offset of this subframe in units of subframes (usually 0)
  @param frame_parms Pointer to frame descriptor
  @param dlsch Pointer to DLSCH descriptor for this allocation
*/
int mch_modulation(mod_sym_t **txdataF,
213 214 215 216
                   int16_t amp,
                   uint32_t subframe_offset,
                   LTE_DL_FRAME_PARMS *frame_parms,
                   LTE_eNB_DLSCH_t *dlsch);
217 218 219 220 221

/** \brief Top-level generation function for eNB TX of MBSFN
    @param phy_vars_eNB Pointer to eNB variables
    @param subframe Subframe for PMCH
    @param a Pointer to transport block
222
    @param abstraction_flag
223

224
*/
225
void generate_mch(PHY_VARS_eNB *phy_vars_eNB,int subframe,uint8_t *a,int abstraction_flag);
226 227 228 229

/** \brief This function generates the frequency-domain pilots (cell-specific downlink reference signals)
    @param phy_vars_eNB Pointer to eNB variables
    @param mcs MCS for MBSFN
230 231
    @param ndi new data indicator
    @param rdvix
232
    @param abstraction_flag
233

234
*/
235
void fill_eNB_dlsch_MCH(PHY_VARS_eNB *phy_vars_eNB,int mcs,int ndi,int rvidx,int abstraction_flag);
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

/** \brief This function generates the frequency-domain pilots (cell-specific downlink reference signals)
    @param phy_vars_ue Pointer to UE variables
    @param mcs MCS for MBSFN
    @param eNB_id index of eNB in ue variables
*/
void fill_UE_dlsch_MCH(PHY_VARS_UE *phy_vars_ue,int mcs,int ndi,int rvidx,int eNB_id);

/** \brief Receiver processing for MBSFN, symbols can be done separately for time/CPU-scheduling purposes
    @param phy_vars_ue Pointer to UE variables
    @param eNB_id index of eNB in ue variables
    @param subframe Subframe index of PMCH
    @param symbol Symbol index on which to act
*/
int rx_pmch(PHY_VARS_UE *phy_vars_ue,
251 252 253
            unsigned char eNB_id,
            uint8_t subframe,
            unsigned char symbol);
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

/** \brief Dump OCTAVE/MATLAB files for PMCH debugging
    @param phy_vars_ue Pointer to UE variables
    @param eNB_id index of eNB in ue variables
    @param coded_bits_per_codeword G from 36.211
    @param subframe Index of subframe
    @returns 0 on success
*/
void dump_mch(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint16_t coded_bits_per_codeword,int subframe);


/** \brief This function generates the frequency-domain pilots (cell-specific downlink reference signals)
    for N subframes.
    @param phy_vars_eNB Pointer to eNB variables
    @param txdataF Table of pointers for frequency-domain TX signals
    @param amp Amplitude of signal
    @param N Number of sub-frames to generate
*/
void generate_pilots(PHY_VARS_eNB *phy_vars_eNB,
273 274 275
                     mod_sym_t **txdataF,
                     int16_t amp,
                     uint16_t N);
276 277 278 279 280 281 282 283 284

/**
   \brief This function generates the frequency-domain pilots (cell-specific downlink reference signals) for one slot only
   @param phy_vars_eNB Pointer to eNB variables
   @param txdataF Table of pointers for frequency-domain TX signals
   @param amp Amplitude of signal
   @param slot index (0..19)
   @param first_pilot_only (0 no)
*/
285
int32_t generate_pilots_slot(PHY_VARS_eNB *phy_vars_eNB,
286 287 288 289 290
                             mod_sym_t **txdataF,
                             int16_t amp,
                             uint16_t slot,
                             int first_pilot_only);

291
int32_t generate_mbsfn_pilot(PHY_VARS_eNB *phy_vars_eNB,
292 293 294
                             mod_sym_t **txdataF,
                             int16_t amp,
                             uint16_t subframe);
295

296
int32_t generate_pss(mod_sym_t **txdataF,
297 298 299 300
                     int16_t amp,
                     LTE_DL_FRAME_PARMS *frame_parms,
                     uint16_t l,
                     uint16_t Ns);
301

302
int32_t generate_pss_emul(PHY_VARS_eNB *phy_vars_eNB,uint8_t sect_id);
303

304
int32_t generate_sss(mod_sym_t **txdataF,
305 306 307 308
                     short amp,
                     LTE_DL_FRAME_PARMS *frame_parms,
                     unsigned short symbol,
                     unsigned short slot_offset);
309

310
int32_t generate_pbch(LTE_eNB_PBCH *eNB_pbch,
311 312 313 314 315
                      mod_sym_t **txdataF,
                      int32_t amp,
                      LTE_DL_FRAME_PARMS *frame_parms,
                      uint8_t *pbch_pdu,
                      uint8_t frame_mod4);
316

317
int32_t generate_pbch_emul(PHY_VARS_eNB *phy_vars_eNB,uint8_t *pbch_pdu);
318 319 320 321 322 323 324

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream QPSK/QPSK reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
325
void qpsk_qpsk(int16_t *stream0_in,
326 327 328 329
               int16_t *stream1_in,
               int16_t *stream0_out,
               int16_t *rho01,
               int32_t length);
330 331 332 333 334 335 336 337 338 339 340 341

/** \brief This function perform LLR computation for dual-stream (QPSK/QPSK) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr128p pointer to pointer to symbol in dlsch_llr*/
342
int32_t dlsch_qpsk_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
343 344 345 346 347 348 349 350 351
                            int32_t **rxdataF_comp,
                            int32_t **rxdataF_comp_i,
                            int32_t **rho_i,
                            int16_t *dlsch_llr,
                            uint8_t symbol,
                            uint8_t first_symbol_flag,
                            uint16_t nb_rb,
                            uint16_t pbch_pss_sss_adj,
                            int16_t **llr128p);
352 353 354 355 356 357 358 359

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream QPSK/16QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
360 361
void qpsk_qam16(int16_t *stream0_in,
                int16_t *stream1_in,
362
                short *ch_mag_i,
363 364 365
                int16_t *stream0_out,
                int16_t *rho01,
                int32_t length);
366 367 368 369 370 371 372 373 374 375 376 377

/** \brief This function perform LLR computation for dual-stream (QPSK/16QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr128p pointer to pointer to symbol in dlsch_llr*/
378
int32_t dlsch_qpsk_16qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
379 380 381 382 383 384 385 386 387 388
                             int32_t **rxdataF_comp,
                             int32_t **rxdataF_comp_i,
                             int **dl_ch_mag_i, //|h_1|^2*(2/sqrt{10})
                             int32_t **rho_i,
                             int16_t *dlsch_llr,
                             uint8_t symbol,
                             uint8_t first_symbol_flag,
                             uint16_t nb_rb,
                             uint16_t pbch_pss_sss_adj,
                             int16_t **llr128p);
389 390 391 392 393 394 395 396

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream QPSK/64QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
397 398
void qpsk_qam64(int16_t *stream0_in,
                int16_t *stream1_in,
399
                short *ch_mag_i,
400 401 402
                int16_t *stream0_out,
                int16_t *rho01,
                int32_t length);
403 404 405 406 407 408 409 410 411 412 413 414

/** \brief This function perform LLR computation for dual-stream (QPSK/64QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr128p pointer to pointer to symbol in dlsch_llr*/
415
int32_t dlsch_qpsk_64qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
416 417 418 419 420 421 422 423 424 425
                             int32_t **rxdataF_comp,
                             int32_t **rxdataF_comp_i,
                             int **dl_ch_mag_i, //|h_1|^2*(2/sqrt{10})
                             int32_t **rho_i,
                             int16_t *dlsch_llr,
                             uint8_t symbol,
                             uint8_t first_symbol_flag,
                             uint16_t nb_rb,
                             uint16_t pbch_pss_sss_adj,
                             int16_t **llr128p);
426 427 428 429 430 431 432 433 434 435 436 437 438 439


/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 16QAM/QPSK reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam16_qpsk(short *stream0_in,
                short *stream1_in,
                short *ch_mag,
                short *stream0_out,
                short *rho01,
440
                int length);
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 579 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 614 615 616 617 618 619 620 621 622 623 624 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 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
/** \brief This function perform LLR computation for dual-stream (16QAM/QPSK) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_16qam_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
                         int **rxdataF_comp,
                         int **rxdataF_comp_i,
                         int **dl_ch_mag,   //|h_0|^2*(2/sqrt{10})
                         int **rho_i,
                         short *dlsch_llr,
                         unsigned char symbol,
                         unsigned char first_symbol_flag,
                         unsigned short nb_rb,
                         uint16_t pbch_pss_sss_adjust,
                         short **llr16p);

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 16QAM/16QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam16_qam16(short *stream0_in,
                 short *stream1_in,
                 short *ch_mag,
                 short *ch_mag_i,
                 short *stream0_out,
                 short *rho01,
                 int length);

/** \brief This function perform LLR computation for dual-stream (16QAM/16QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_16qam_16qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
                          int **rxdataF_comp,
                          int **rxdataF_comp_i,
                          int **dl_ch_mag,   //|h_0|^2*(2/sqrt{10})
                          int **dl_ch_mag_i, //|h_1|^2*(2/sqrt{10})
                          int **rho_i,
                          short *dlsch_llr,
                          unsigned char symbol,
                          unsigned char first_symbol_flag,
                          unsigned short nb_rb,
                          uint16_t pbch_pss_sss_adjust,
                          short **llr16p);

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 16QAM/64QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam16_qam64(short *stream0_in,
                 short *stream1_in,
                 short *ch_mag,
                 short *ch_mag_i,
                 short *stream0_out,
                 short *rho01,
                 int length);

/** \brief This function perform LLR computation for dual-stream (16QAM/64QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_16qam_64qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
                          int **rxdataF_comp,
                          int **rxdataF_comp_i,
                          int **dl_ch_mag,   //|h_0|^2*(2/sqrt{10})
                          int **dl_ch_mag_i, //|h_1|^2*(2/sqrt{10})
                          int **rho_i,
                          short *dlsch_llr,
                          unsigned char symbol,
                          unsigned char first_symbol_flag,
                          unsigned short nb_rb,
                          uint16_t pbch_pss_sss_adjust,
                          short **llr16p);

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 64QAM/64QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam64_qpsk(short *stream0_in,
                short *stream1_in,
                short *ch_mag,
                short *stream0_out,
                short *rho01,
                int length);

/** \brief This function perform LLR computation for dual-stream (64QAM/64QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_64qam_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
                         int **rxdataF_comp,
                         int **rxdataF_comp_i,
                         int **dl_ch_mag,
                         int **rho_i,
                         short *dlsch_llr,
                         unsigned char symbol,
                         unsigned char first_symbol_flag,
                         unsigned short nb_rb,
                         uint16_t pbch_pss_sss_adjust,
                         short **llr16p);

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 64QAM/16QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam64_qam16(short *stream0_in,
                 short *stream1_in,
                 short *ch_mag,
                 short *ch_mag_i,
                 short *stream0_out,
                 short *rho01,
                 int length);

/** \brief This function perform LLR computation for dual-stream (64QAM/16QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_64qam_16qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
                          int **rxdataF_comp,
                          int **rxdataF_comp_i,
                          int **dl_ch_mag,
                          int **dl_ch_mag_i,
                          int **rho_i,
                          short *dlsch_llr,
                          unsigned char symbol,
                          unsigned char first_symbol_flag,
                          unsigned short nb_rb,
                          uint16_t pbch_pss_sss_adjust,
                          short **llr16p);

/** \brief This function computes the LLRs for ML (max-logsum approximation) dual-stream 64QAM/64QAM reception.
    @param stream0_in Input from channel compensated (MR combined) stream 0
    @param stream1_in Input from channel compensated (MR combined) stream 1
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param stream0_out Output from LLR unit for stream0
    @param rho01 Cross-correlation between channels (MR combined)
    @param length in complex channel outputs*/
void qam64_qam64(short *stream0_in,
                 short *stream1_in,
                 short *ch_mag,
                 short *ch_mag_i,
                 short *stream0_out,
                 short *rho01,
                 int length);

/** \brief This function perform LLR computation for dual-stream (64QAM/64QAM) transmission.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param ch_mag   Input from scaled channel magnitude square of h0'*g0
    @param ch_mag_i Input from scaled channel magnitude square of h0'*g1
    @param rho_i Correlation between channel of signal and inteference
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
    @param first_symbol_flag flag to indicate this is the first symbol of the dlsch
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr16p pointer to pointer to symbol in dlsch_llr*/
int dlsch_64qam_64qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
                          int **rxdataF_comp,
                          int **rxdataF_comp_i,
                          int **dl_ch_mag,
                          int **dl_ch_mag_i,
                          int **rho_i,
                          short *dlsch_llr,
                          unsigned char symbol,
                          unsigned char first_symbol_flag,
                          unsigned short nb_rb,
                          uint16_t pbch_pss_sss_adjust,
                          short **llr16p);


/** \brief This function generates log-likelihood ratios (decoder input) for single-stream QPSK received waveforms.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param dlsch_llr llr output
    @param symbol OFDM symbol index in sub-frame
677
    @param first_symbol_flag
678 679 680 681
    @param nb_rb number of RBs for this allocation
    @param pbch_pss_sss_adj Number of channel bits taken by PBCH/PSS/SSS
    @param llr128p pointer to pointer to symbol in dlsch_llr
*/
682
int32_t dlsch_qpsk_llr(LTE_DL_FRAME_PARMS *frame_parms,
683 684 685 686 687 688 689
                       int32_t **rxdataF_comp,
                       int16_t *dlsch_llr,
                       uint8_t symbol,
                       uint8_t first_symbol_flag,
                       uint16_t nb_rb,
                       uint16_t pbch_pss_sss_adj,
                       int16_t **llr128p);
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

/**
   \brief This function generates log-likelihood ratios (decoder input) for single-stream 16QAM received waveforms
   @param frame_parms Frame descriptor structure
   @param rxdataF_comp Compensated channel output
   @param dlsch_llr llr output
   @param dl_ch_mag Squared-magnitude of channel in each resource element position corresponding to allocation and weighted for mid-point in 16QAM constellation
   @param symbol OFDM symbol index in sub-frame
   @param first_symbol_flag
   @param nb_rb number of RBs for this allocation
   @param pbch_pss_sss_adjust  Adjustment factor in RE for PBCH/PSS/SSS allocations
   @param llr128p pointer to pointer to symbol in dlsch_llr
*/

void dlsch_16qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
705 706 707 708 709 710 711 712
                     int32_t **rxdataF_comp,
                     int16_t *dlsch_llr,
                     int32_t **dl_ch_mag,
                     uint8_t symbol,
                     uint8_t first_symbol_flag,
                     uint16_t nb_rb,
                     uint16_t pbch_pss_sss_adjust,
                     int16_t **llr128p);
713 714 715 716 717 718 719 720 721 722 723 724 725 726

/**
   \brief This function generates log-likelihood ratios (decoder input) for single-stream 16QAM received waveforms
   @param frame_parms Frame descriptor structure
   @param rxdataF_comp Compensated channel output
   @param dlsch_llr llr output
   @param dl_ch_mag Squared-magnitude of channel in each resource element position corresponding to allocation, weighted by first mid-point of 64-QAM constellation
   @param dl_ch_magb Squared-magnitude of channel in each resource element position corresponding to allocation, weighted by second mid-point of 64-QAM constellation
   @param symbol OFDM symbol index in sub-frame
   @param first_symbol_flag
   @param nb_rb number of RBs for this allocation
   @param pbch_pss_sss_adjust PBCH/PSS/SSS RE adjustment (in REs)
*/
void dlsch_64qam_llr(LTE_DL_FRAME_PARMS *frame_parms,
727 728 729 730 731 732 733 734 735
                     int32_t **rxdataF_comp,
                     int16_t *dlsch_llr,
                     int32_t **dl_ch_mag,
                     int32_t **dl_ch_magb,
                     uint8_t symbol,
                     uint8_t first_symbol_flag,
                     uint16_t nb_rb,
                     uint16_t pbch_pss_sss_adjust,
                     short **llr_save);
736 737

/** \fn dlsch_siso(LTE_DL_FRAME_PARMS *frame_parms,
738 739
    int32_t **rxdataF_comp,
    int32_t **rxdataF_comp_i,
740 741 742 743 744 745 746 747 748 749 750
    uint8_t l,
    uint16_t nb_rb)
    \brief This function does the first stage of llr computation for SISO, by just extracting the pilots, PBCH and primary/secondary synchronization sequences.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param l symbol in sub-frame
    @param nb_rb Number of RBs in this allocation
*/

void dlsch_siso(LTE_DL_FRAME_PARMS *frame_parms,
751 752 753 754
                int32_t **rxdataF_comp,
                int32_t **rxdataF_comp_i,
                uint8_t l,
                uint16_t nb_rb);
755 756

/** \fn dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
757 758 759
    int32_t **rxdataF_comp,
    int32_t **dl_ch_mag,
    int32_t **dl_ch_magb,
760 761 762 763 764 765 766 767 768 769 770
    uint8_t symbol,
    uint16_t nb_rb)
    \brief This function does Alamouti combining on RX and prepares LLR inputs by skipping pilots, PBCH and primary/secondary synchronization signals.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param dl_ch_mag First squared-magnitude of channel (16QAM and 64QAM) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param dl_ch_magb Second squared-magnitude of channel (64QAM only) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param symbol Symbol in sub-frame
    @param nb_rb Number of RBs in this allocation
*/
void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
771 772 773 774 775
                    int32_t **rxdataF_comp,
                    int32_t **dl_ch_mag,
                    int32_t **dl_ch_magb,
                    uint8_t symbol,
                    uint16_t nb_rb);
776 777

/** \fn dlsch_antcyc(LTE_DL_FRAME_PARMS *frame_parms,
778 779 780
    int32_t **rxdataF_comp,
    int32_t **dl_ch_mag,
    int32_t **dl_ch_magb,
781 782 783 784 785 786 787 788 789 790 791
    uint8_t symbol,
    uint16_t nb_rb)
    \brief This function does antenna selection (based on antenna cycling pattern) on RX and prepares LLR inputs by skipping pilots, PBCH and primary/secondary synchronization signals.  Note that this is not LTE, it is just included for comparison purposes.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param dl_ch_mag First squared-magnitude of channel (16QAM and 64QAM) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param dl_ch_magb Second squared-magnitude of channel (64QAM only) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param symbol Symbol in sub-frame
    @param nb_rb Number of RBs in this allocation
*/
void dlsch_antcyc(LTE_DL_FRAME_PARMS *frame_parms,
792 793 794 795 796
                  int32_t **rxdataF_comp,
                  int32_t **dl_ch_mag,
                  int32_t **dl_ch_magb,
                  uint8_t symbol,
                  uint16_t nb_rb);
797 798

/** \fn dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
799 800 801 802 803 804
    int32_t **rxdataF_comp,
    int32_t **rxdataF_comp_i,
    int32_t **rho,
    int32_t **rho_i,
    int32_t **dl_ch_mag,
    int32_t **dl_ch_magb,
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
    uint8_t symbol,
    uint16_t nb_rb,
    uint8_t dual_stream_UE)

    \brief This function does maximal-ratio combining for dual-antenna receivers.
    @param frame_parms Frame descriptor structure
    @param rxdataF_comp Compensated channel output
    @param rxdataF_comp_i Compensated channel output for interference
    @param rho Cross correlation between spatial channels
    @param rho_i Cross correlation between signal and inteference channels
    @param dl_ch_mag First squared-magnitude of channel (16QAM and 64QAM) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param dl_ch_magb Second squared-magnitude of channel (64QAM only) for LLR computation.  Alamouti combining should be performed on this as well. Result is stored in first antenna position
    @param symbol Symbol in sub-frame
    @param nb_rb Number of RBs in this allocation
    @param dual_stream_UE Flag to indicate dual-stream detection
*/
void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
822 823 824 825 826 827 828 829 830 831 832
                         int32_t **rxdataF_comp,
                         int32_t **rxdataF_comp_i,
                         int32_t **rho,
                         int32_t **rho_i,
                         int32_t **dl_ch_mag,
                         int32_t **dl_ch_magb,
                         int32_t **dl_ch_mag_i,
                         int32_t **dl_ch_magb_i,
                         uint8_t symbol,
                         uint16_t nb_rb,
                         uint8_t dual_stream_UE);
833

834 835 836 837
/** \fn dlsch_extract_rbs_single(int32_t **rxdataF,
    int32_t **dl_ch_estimates,
    int32_t **rxdataF_ext,
    int32_t **dl_ch_estimates_ext,
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
    uint16_t pmi,
    uint8_t *pmi_ext,
    uint32_t *rb_alloc,
    uint8_t symbol,
    uint8_t subframe,
    LTE_DL_FRAME_PARMS *frame_parms)
    \brief This function extracts the received resource blocks, both channel estimates and data symbols,
    for the current allocation and for single antenna eNB transmission.
    @param rxdataF Raw FFT output of received signal
    @param dl_ch_estimates Channel estimates of current slot
    @param rxdataF_ext FFT output for RBs in this allocation
    @param dl_ch_estimates_ext Channel estimates for RBs in this allocation
    @param pmi subband Precoding matrix indicator
    @param pmi_ext Extracted PMI for chosen RBs
    @param rb_alloc RB allocation vector
    @param symbol Symbol to extract
    @param subframe Subframe number
855
    @param high_speed_flag
856 857
    @param frame_parms Pointer to frame descriptor
*/
858
uint16_t dlsch_extract_rbs_single(int32_t **rxdataF,
859 860 861 862 863 864 865 866 867 868
                                  int32_t **dl_ch_estimates,
                                  int32_t **rxdataF_ext,
                                  int32_t **dl_ch_estimates_ext,
                                  uint16_t pmi,
                                  uint8_t *pmi_ext,
                                  uint32_t *rb_alloc,
                                  uint8_t symbol,
                                  uint8_t subframe,
                                  uint32_t high_speed_flag,
                                  LTE_DL_FRAME_PARMS *frame_parms);
869

870 871 872 873
/** \fn dlsch_extract_rbs_dual(int32_t **rxdataF,
    int32_t **dl_ch_estimates,
    int32_t **rxdataF_ext,
    int32_t **dl_ch_estimates_ext,
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
    uint16_t pmi,
    uint8_t *pmi_ext,
    uint32_t *rb_alloc,
    uint8_t symbol,
    LTE_DL_FRAME_PARMS *frame_parms)
    \brief This function extracts the received resource blocks, both channel estimates and data symbols,
    for the current allocation and for dual antenna eNB transmission.
    @param rxdataF Raw FFT output of received signal
    @param dl_ch_estimates Channel estimates of current slot
    @param rxdataF_ext FFT output for RBs in this allocation
    @param dl_ch_estimates_ext Channel estimates for RBs in this allocation
    @param pmi subband Precoding matrix indicator
    @param pmi_ext Extracted PMI for chosen RBs
    @param rb_alloc RB allocation vector
    @param symbol Symbol to extract
    @param subframe Subframe index
890
    @param high_speed_flag
891 892
    @param frame_parms Pointer to frame descriptor
*/
893
uint16_t dlsch_extract_rbs_dual(int32_t **rxdataF,
894 895 896 897 898 899 900 901 902 903
                                int32_t **dl_ch_estimates,
                                int32_t **rxdataF_ext,
                                int32_t **dl_ch_estimates_ext,
                                uint16_t pmi,
                                uint8_t *pmi_ext,
                                uint32_t *rb_alloc,
                                uint8_t symbol,
                                uint8_t subframe,
                                uint32_t high_speed_flag,
                                LTE_DL_FRAME_PARMS *frame_parms);
904 905 906 907 908 909

/** \brief This function performs channel compensation (matched filtering) on the received RBs for this allocation.  In addition, it computes the squared-magnitude of the channel with weightings for 16QAM/64QAM detection as well as dual-stream detection (cross-correlation)
    @param rxdataF_ext Frequency-domain received signal in RBs to be demodulated
    @param dl_ch_estimates_ext Frequency-domain channel estimates in RBs to be demodulated
    @param dl_ch_mag First Channel magnitudes (16QAM/64QAM)
    @param dl_ch_magb Second weighted Channel magnitudes (64QAM)
910
    @param rxdataF_comp Compensated received waveform
911 912 913 914 915 916 917 918 919
    @param rho Cross-correlation between two spatial channels on each RX antenna
    @param frame_parms Pointer to frame descriptor
    @param symbol Symbol on which to operate
    @param first_symbol_flag set to 1 on first DLSCH symbol
    @param mod_order Modulation order of allocation
    @param nb_rb Number of RBs in allocation
    @param output_shift Rescaling for compensated output (should be energy-normalizing)
    @param phy_measurements Pointer to UE PHY measurements
*/
920
void dlsch_channel_compensation(int32_t **rxdataF_ext,
921 922 923 924 925 926 927 928 929 930 931 932
                                int32_t **dl_ch_estimates_ext,
                                int32_t **dl_ch_mag,
                                int32_t **dl_ch_magb,
                                int32_t **rxdataF_comp,
                                int32_t **rho,
                                LTE_DL_FRAME_PARMS *frame_parms,
                                uint8_t symbol,
                                uint8_t first_symbol_flag,
                                uint8_t mod_order,
                                uint16_t nb_rb,
                                uint8_t output_shift,
                                PHY_MEASUREMENTS *phy_measurements);
933 934 935 936 937 938 939 940 941

void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
                                   unsigned char symbol,
                                   unsigned short nb_rb,
                                   int **dl_ch_estimates_ext,
                                   int **dl_ch_estimates_ext_i,
                                   int **dl_ch_rho_ext,
                                   unsigned char output_shift);

942
void dlsch_channel_compensation_TM56(int **rxdataF_ext,
943 944 945 946 947 948 949 950 951 952 953 954 955
                                     int **dl_ch_estimates_ext,
                                     int **dl_ch_mag,
                                     int **dl_ch_magb,
                                     int **rxdataF_comp,
                                     unsigned char *pmi_ext,
                                     LTE_DL_FRAME_PARMS *frame_parms,
                                     PHY_MEASUREMENTS *phy_measurements,
                                     int eNB_id,
                                     unsigned char symbol,
                                     unsigned char mod_order,
                                     unsigned short nb_rb,
                                     unsigned char output_shift,
                                     unsigned char dl_power_off);
956

957
void dlsch_channel_compensation_TM3(LTE_DL_FRAME_PARMS *frame_parms,
958 959 960 961 962 963 964 965 966
                                    LTE_UE_PDSCH *lte_ue_pdsch_vars,
                                    PHY_MEASUREMENTS *phy_measurements,
                                    int eNB_id,
                                    unsigned char symbol,
                                    unsigned char mod_order0,
                                    unsigned char mod_order1,
                                    int round,
                                    unsigned short nb_rb,
                                    unsigned char output_shift);
967 968


969 970 971 972 973 974 975
/** \brief This function computes the average channel level over all allocated RBs and antennas (TX/RX) in order to compute output shift for compensated signal
    @param dl_ch_estimates_ext Channel estimates in allocated RBs
    @param frame_parms Pointer to frame descriptor
    @param avg Pointer to average signal strength
    @param pilots_flag Flag to indicate pilots in symbol
    @param nb_rb Number of allocated RBs
*/
976
void dlsch_channel_level(int32_t **dl_ch_estimates_ext,
977 978 979 980
                         LTE_DL_FRAME_PARMS *frame_parms,
                         int32_t *avg,
                         uint8_t pilots_flag,
                         uint16_t nb_rb);
981

982
void dlsch_channel_level_TM3(int **dl_ch_estimates_ext,
983 984 985 986
                             LTE_DL_FRAME_PARMS *frame_parms,
                             int *avg,
                             uint8_t symbol,
                             unsigned short nb_rb);
987 988

void dlsch_channel_level_TM56(int32_t **dl_ch_estimates_ext,
989 990
                              LTE_DL_FRAME_PARMS *frame_parms,
                              unsigned char *pmi_ext,
991
                              int32_t *avg,
992 993 994
                              uint8_t symbol_mod,
                              uint16_t nb_rb);

995
void dlsch_scale_channel(int32_t **dl_ch_estimates_ext,
996 997 998 999 1000 1001
                         LTE_DL_FRAME_PARMS *frame_parms,
                         LTE_UE_DLSCH_t **dlsch_ue,
                         uint8_t symbol_mod,
                         uint16_t nb_rb);

/** \brief This is the top-level entry point for DLSCH decoding in UE.  It should be replicated on several
1002
    threads (on multi-core machines) corresponding to different HARQ processes. The routine first
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    computes the segmentation information, followed by rate dematching and sub-block deinterleaving the of the
    received LLRs computed by dlsch_demodulation for each transport block segment. It then calls the
    turbo-decoding algorithm for each segment and stops after either after unsuccesful decoding of at least
    one segment or correct decoding of all segments.  Only the segment CRCs are check for the moment, the
    overall CRC is ignored.  Finally transport block reassembly is performed.
    @param phy_vars_ue Pointer to ue variables
    @param dlsch_llr Pointer to LLR values computed by dlsch_demodulation
    @param lte_frame_parms Pointer to frame descriptor
    @param dlsch Pointer to DLSCH descriptor
    @param subframe Subframe number
    @param num_pdcch_symbols Number of PDCCH symbols
    @param is_crnti indicates if PDSCH belongs to a CRNTI (necessary for parallelizing decoding threads)
    @param llr8_flag If 1, indicate that the 8-bit turbo decoder should be used
    @returns 0 on success, 1 on unsuccessful decoding
*/
uint32_t dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
1019 1020 1021 1022 1023 1024 1025 1026
                        int16_t *dlsch_llr,
                        LTE_DL_FRAME_PARMS *lte_frame_parms,
                        LTE_UE_DLSCH_t *dlsch,
                        LTE_DL_UE_HARQ_t *harq_process,
                        uint8_t subframe,
                        uint8_t harq_pid,
                        uint8_t is_crnti,
                        uint8_t llr8_flag);
1027 1028

uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
1029 1030 1031
                             uint8_t subframe,
                             uint8_t dlsch_id,
                             uint8_t eNB_id);
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048

/** \brief This function is the top-level entry point to PDSCH demodulation, after frequency-domain transformation and channel estimation.  It performs
    - RB extraction (signal and channel estimates)
    - channel compensation (matched filtering)
    - RE extraction (pilot, PBCH, synch. signals)
    - antenna combining (MRC, Alamouti, cycling)
    - LLR computation
    @param phy_vars_ue Pointer to PHY variables
    @param type Type of PDSCH (SI_PDSCH,RA_PDSCH,PDSCH,PMCH)
    @param eNB_id eNb index (Nid1) 0,1,2
    @param eNB_id_i Interfering eNB index (Nid1) 0,1,2, or 3 in case of MU-MIMO IC receiver
    @param subframe Subframe number
    @param symbol Symbol on which to act (within sub-frame)
    @param first_symbol_flag set to 1 on first DLSCH symbol
    @param dual_stream_UE Flag to indicate dual-stream interference cancellation
    @param i_mod Modulation order of the interfering stream
*/
1049
int32_t rx_pdsch(PHY_VARS_UE *phy_vars_ue,
1050 1051 1052 1053 1054 1055 1056 1057 1058
                 PDSCH_t type,
                 uint8_t eNB_id,
                 uint8_t eNB_id_i,
                 uint8_t subframe,
                 uint8_t symbol,
                 uint8_t first_symbol_flag,
                 uint8_t dual_stream_UE,
                 uint8_t i_mod,
                 uint8_t harq_pid);
1059

1060
int32_t rx_pdcch(LTE_UE_COMMON *lte_ue_common_vars,
1061 1062 1063 1064 1065 1066 1067
                 LTE_UE_PDCCH **lte_ue_pdcch_vars,
                 LTE_DL_FRAME_PARMS *frame_parms,
                 uint8_t subframe,
                 uint8_t eNB_id,
                 MIMO_mode_t mimo_mode,
                 uint32_t high_speed_flag,
                 uint8_t is_secondary_ue);
1068 1069 1070 1071 1072 1073 1074 1075
/*! \brief Performs detection of SSS to find cell ID and other framing parameters (FDD/TDD, normal/extended prefix)
  @param phy_vars_ue Pointer to UE variables
  @param tot_metric Pointer to variable containing maximum metric under framing hypothesis (to be compared to other hypotheses
  @param flip_max Pointer to variable indicating if start of frame is in second have of RX buffer (i.e. PSS/SSS is flipped)
  @param phase_max Pointer to variable (0 ... 6) containing rought phase offset between PSS and SSS (can be used for carrier
  frequency adjustment. 0 means -pi/3, 6 means pi/3.
  @returns 0 on success
*/
1076
int rx_sss(PHY_VARS_UE *phy_vars_ue,int32_t *tot_metric,uint8_t *flip_max,uint8_t *phase_max);
1077 1078 1079 1080 1081

/*! \brief receiver for the PBCH
  \returns number of tx antennas or -1 if error
*/
uint16_t rx_pbch(LTE_UE_COMMON *lte_ue_common_vars,
1082 1083 1084 1085 1086 1087
                 LTE_UE_PBCH *lte_ue_pbch_vars,
                 LTE_DL_FRAME_PARMS *frame_parms,
                 uint8_t eNB_id,
                 MIMO_mode_t mimo_mode,
                 uint32_t high_speed_flag,
                 uint8_t frame_mod4);
1088 1089

uint16_t rx_pbch_emul(PHY_VARS_UE *phy_vars_ue,
1090 1091
                      uint8_t eNB_id,
                      uint8_t pbch_phase);
1092 1093 1094 1095

/*! \brief PBCH scrambling. Applies 36.211 PBCH scrambling procedure.
  \param frame_parms Pointer to frame descriptor
  \param coded_data Output of the coding and rate matching
1096
  \param length Length of the sequence*/
1097
void pbch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
1098 1099
                     uint8_t* coded_data,
                     uint32_t length);
1100 1101 1102 1103 1104 1105

/*! \brief PBCH unscrambling
  This is similar to pbch_scrabling with the difference that inputs are signed s16s (llr values) and instead of flipping bits we change signs.
  \param frame_parms Pointer to frame descriptor
  \param llr Output of the demodulator
  \param length Length of the sequence
1106
  \param frame_mod4 Frame number modulo 4*/
1107
void pbch_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
1108 1109 1110
                       int8_t* llr,
                       uint32_t length,
                       uint8_t frame_mod4);
1111 1112 1113 1114 1115 1116

/*! \brief DCI Encoding. This routine codes an arbitrary DCI PDU after appending the 8-bit 3GPP CRC.  It then applied sub-block interleaving and rate matching.
  \param a Pointer to DCI PDU (coded in bytes)
  \param A Length of DCI PDU in bits
  \param E Length of DCI PDU in coded bits
  \param e Pointer to sequence
1117
  \param rnti RNTI for CRC scrambling*/
1118
void dci_encoding(uint8_t *a,
1119 1120 1121 1122
                  uint8_t A,
                  uint16_t E,
                  uint8_t *e,
                  uint16_t rnti);
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133

/*! \brief Top-level DCI entry point. This routine codes an set of DCI PDUs and performs PDCCH modulation, interleaving and mapping.
  \param num_ue_spec_dci  Number of UE specific DCI pdus to encode
  \param num_common_dci Number of Common DCI pdus to encode
  \param dci_alloc Allocation vectors for each DCI pdu
  \param n_rnti n_RNTI (see )
  \param amp Amplitude of QPSK symbols
  \param frame_parms Pointer to DL Frame parameter structure
  \param txdataF Pointer to tx signal buffers
  \param sub_frame_offset subframe offset in frame
  @returns Number of PDCCH symbols
1134
*/
1135
uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
1136 1137 1138 1139 1140 1141 1142
                         uint8_t num_common_dci,
                         DCI_ALLOC_t *dci_alloc,
                         uint32_t n_rnti,
                         int16_t amp,
                         LTE_DL_FRAME_PARMS *frame_parms,
                         mod_sym_t **txdataF,
                         uint32_t sub_frame_offset);
1143 1144

uint8_t generate_dci_top_emul(PHY_VARS_eNB *phy_vars_eNB,
1145 1146 1147 1148
                              uint8_t num_ue_spec_dci,
                              uint8_t num_common_dci,
                              DCI_ALLOC_t *dci_alloc,
                              uint8_t subframe);
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160


void generate_64qam_table(void);
void generate_16qam_table(void);

uint16_t extract_crc(uint8_t *dci,uint8_t DCI_LENGTH);

/*! \brief LLR from two streams. This function takes two streams (qpsk modulated) and calculates the LLR, considering one stream as interference.
  \param stream0_in pointer to first stream0
  \param stream1_in pointer to first stream1
  \param stream0_out pointer to output stream
  \param rho01 pointer to correlation matrix
1161
  \param length*/
1162
void qpsk_qpsk_TM3456(short *stream0_in,
1163 1164 1165 1166 1167
                      short *stream1_in,
                      short *stream0_out,
                      short *rho01,
                      int length
                     );
1168 1169 1170 1171 1172 1173 1174 1175

/** \brief Attempt decoding of a particular DCI with given length and format.
    @param DCI_LENGTH length of DCI in bits
    @param DCI_FMT Format of DCI
    @param e e-sequence (soft bits)
    @param decoded_output Output of Viterbi decoder
*/
void dci_decoding(uint8_t DCI_LENGTH,
1176 1177 1178
                  uint8_t DCI_FMT,
                  int8_t *e,
                  uint8_t *decoded_output);
1179 1180 1181 1182 1183

/** \brief Do 36.213 DCI decoding procedure by searching different RNTI options and aggregation levels.  Currently does
    not employ the complexity reducing procedure based on RNTI.
    @param phy_vars_ue UE variables
    @param dci_alloc Pointer to DCI_ALLOC_t array to store results for DLSCH/ULSCH programming
1184
    @param do_common If 1 perform search in common search-space else ue-specific search-space
1185 1186 1187 1188 1189
    @param eNB_id eNB Index on which to act
    @param subframe Index of subframe
    @returns bitmap of occupied CCE positions (i.e. those detected)
*/
uint16_t dci_decoding_procedure(PHY_VARS_UE *phy_vars_ue,
1190 1191 1192 1193
                                DCI_ALLOC_t *dci_alloc,
                                int do_common,
                                int16_t eNB_id,
                                uint8_t subframe);
1194 1195 1196


uint16_t dci_decoding_procedure_emul(LTE_UE_PDCCH **lte_ue_pdcch_vars,
1197 1198 1199 1200 1201
                                     uint8_t num_ue_spec_dci,
                                     uint8_t num_common_dci,
                                     DCI_ALLOC_t *dci_alloc_tx,
                                     DCI_ALLOC_t *dci_alloc_rx,
                                     int16_t eNB_id);
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222

/** \brief Compute Q (modulation order) based on I_MCS PDSCH.  Implements table 7.1.7.1-1 from 36.213.
    @param I_MCS */
uint8_t get_Qm(uint8_t I_MCS);

/** \brief Compute Q (modulation order) based on I_MCS for PUSCH.  Implements table 8.6.1-1 from 36.213.
    @param I_MCS */
uint8_t get_Qm_ul(uint8_t I_MCS);

/** \brief Compute I_TBS (transport-block size) based on I_MCS for PDSCH.  Implements table 7.1.7.1-1 from 36.213.
    @param I_MCS */
uint8_t get_I_TBS(uint8_t I_MCS);

/** \brief Compute I_TBS (transport-block size) based on I_MCS for PUSCH.  Implements table 8.6.1-1 from 36.213.
    @param I_MCS */
unsigned char get_I_TBS_UL(unsigned char I_MCS);

/** \brief Compute Q (modulation order) based on downlink I_MCS. Implements table 7.1.7.1-1 from 36.213.
    @param I_MCS
    @param nb_rb
    @return Transport block size */
1223
uint32_t get_TBS_DL(uint8_t mcs, uint16_t nb_rb);
1224 1225 1226 1227 1228

/** \brief Compute Q (modulation order) based on uplink I_MCS. Implements table 7.1.7.1-1 from 36.213.
    @param I_MCS
    @param nb_rb
    @return Transport block size */
1229
uint32_t get_TBS_UL(uint8_t mcs, uint16_t nb_rb);
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239

/* \brief Return bit-map of resource allocation for a given DCI rballoc (RIV format) and vrb type
   @param vrb_type VRB type (0=localized,1=distributed)
   @param rb_alloc_dci rballoc field from DCI
*/
uint32_t get_rballoc(uint8_t vrb_type,uint16_t rb_alloc_dci);

/* \brief Return bit-map of resource allocation for a given DCI rballoc (RIV format) and vrb type
   @returns Transmission mode (1-7)
*/
1240
uint8_t get_transmission_mode(module_id_t Mod_id, uint8_t CC_id, rnti_t rnti);
1241

1242

1243
/* \brief
1244
   @param ra_header Header of resource allocation (0,1) (See sections 7.1.6.1/7.1.6.2 of 36.213 Rel8.6)
1245
   @param rb_alloc Bitmap allocation from DCI (format 1,2)
1246 1247 1248 1249
   @returns number of physical resource blocks
*/
uint32_t conv_nprb(uint8_t ra_header,uint32_t rb_alloc,int N_RB_DL);

Raymond Knopp's avatar
 
Raymond Knopp committed
1250
int get_G(LTE_DL_FRAME_PARMS *frame_parms,uint16_t nb_rb,uint32_t *rb_alloc,uint8_t mod_order,uint8_t Nl,uint8_t num_pdcch_symbols,int frame,uint8_t subframe);
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276

int adjust_G(LTE_DL_FRAME_PARMS *frame_parms,uint32_t *rb_alloc,uint8_t mod_order,uint8_t subframe);
int adjust_G2(LTE_DL_FRAME_PARMS *frame_parms,uint32_t *rb_alloc,uint8_t mod_order,uint8_t subframe,uint8_t symbol);


#ifndef modOrder
#define modOrder(I_MCS,I_TBS) ((I_MCS-I_TBS)*2+2) // Find modulation order from I_TBS and I_MCS
#endif

/** \fn uint8_t I_TBS2I_MCS(uint8_t I_TBS);
    \brief This function maps I_tbs to I_mcs according to Table 7.1.7.1-1 in 3GPP TS 36.213 V8.6.0. Where there is two supported modulation orders for the same I_TBS then either high or low modulation is chosen by changing the equality of the two first comparisons in the if-else statement.
    \param I_TBS Index of Transport Block Size
    \return I_MCS given I_TBS
*/
uint8_t I_TBS2I_MCS(uint8_t I_TBS);

/** \fn uint8_t SE2I_TBS(float SE,
    uint8_t N_PRB,
    uint8_t symbPerRB);
    \brief This function maps a requested throughput in number of bits to I_tbs. The throughput is calculated as a function of modulation order, RB allocation and number of symbols per RB. The mapping orginates in the "Transport block size table" (Table 7.1.7.2.1-1 in 3GPP TS 36.213 V8.6.0)
    \param SE Spectral Efficiency (before casting to integer, multiply by 1024, remember to divide result by 1024!)
    \param N_PRB Number of PhysicalResourceBlocks allocated \sa lte_frame_parms->N_RB_DL
    \param symbPerRB Number of symbols per resource block allocated to this channel
    \return I_TBS given an SE and an N_PRB
*/
uint8_t SE2I_TBS(float SE,
1277 1278
                 uint8_t N_PRB,
                 uint8_t symbPerRB);
1279 1280 1281 1282 1283 1284
/** \brief This function generates the sounding reference symbol (SRS) for the uplink according to 36.211 v8.6.0. If IFFT_FPGA is defined, the SRS is quantized to a QPSK sequence.
    @param frame_parms LTE DL Frame Parameters
    @param soundingrs_ul_config_dedicated Dynamic configuration from RRC during Connection Establishment
    @param txdataF pointer to the frequency domain TX signal
    @returns 0 on success*/
int generate_srs_rx(LTE_DL_FRAME_PARMS *frame_parms,
1285 1286
                    SOUNDINGRS_UL_CONFIG_DEDICATED *soundingrs_ul_config_dedicated,
                    int *txdataF);
1287

1288
int32_t generate_srs_tx_emul(PHY_VARS_UE *phy_vars_ue,
1289
                             uint8_t subframe);
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299

/*!
  \brief This function is similar to generate_srs_tx but generates a conjugate sequence for channel estimation. If IFFT_FPGA is defined, the SRS is quantized to a QPSK sequence.
  @param phy_vars_ue Pointer to PHY_VARS structure
  @param eNB_id Index of destination eNB for this SRS
  @param amp Linear amplitude of SRS
  @param subframe Index of subframe on which to act
  @returns 0 on success, -1 on error with message
*/

1300
int32_t generate_srs_tx(PHY_VARS_UE *phy_vars_ue,
1301 1302 1303
                        uint8_t eNB_id,
                        int16_t amp,
                        uint32_t subframe);
1304 1305 1306 1307 1308

/*!
  \brief This function generates the downlink reference signal for the PUSCH according to 36.211 v8.6.0. The DRS occuies the RS defined by rb_alloc and the symbols 2 and 8 for extended CP and 3 and 10 for normal CP.
*/

1309
int32_t generate_drs_pusch(PHY_VARS_UE *phy_vars_ue,
1310 1311 1312 1313 1314 1315
                           uint8_t eNB_id,
                           int16_t amp,
                           uint32_t subframe,
                           uint32_t first_rb,
                           uint32_t nb_rb,
                           uint8_t ant);
1316 1317 1318 1319 1320 1321

/*!
  \brief This function initializes the Group Hopping, Sequence Hopping and nPRS sequences for PUCCH/PUSCH according to 36.211 v8.6.0. It should be called after configuration of UE (reception of SIB2/3) and initial configuration of eNB (or after reconfiguration of cell-specific parameters).
  @param frame_parms Pointer to a LTE_DL_FRAME_PARMS structure (eNB or UE)*/
void init_ul_hopping(LTE_DL_FRAME_PARMS *frame_parms);

1322
int32_t compareints (const void * a, const void * b);
1323 1324 1325


void ulsch_modulation(mod_sym_t **txdataF,
1326 1327 1328 1329 1330
                      int16_t amp,
                      frame_t frame,
                      uint32_t subframe,
                      LTE_DL_FRAME_PARMS *frame_parms,
                      LTE_UE_ULSCH_t *ulsch);
1331 1332


1333
void ulsch_extract_rbs_single(int32_t **rxdataF,
1334 1335 1336 1337 1338 1339
                              int32_t **rxdataF_ext,
                              uint32_t first_rb,
                              uint32_t nb_rb,
                              uint8_t l,
                              uint8_t Ns,
                              LTE_DL_FRAME_PARMS *frame_parms);
1340

1341
uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,frame_t frame,uint8_t subframe);
1342 1343 1344 1345
uint8_t subframe2harq_pid_eNBrx(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe);

int generate_ue_dlsch_params_from_dci(uint8_t subframe,
                                      void *dci_pdu,
1346
                                      rnti_t rnti,
1347 1348 1349 1350 1351 1352 1353 1354
                                      DCI_format_t dci_format,
                                      LTE_UE_DLSCH_t **dlsch,
                                      LTE_DL_FRAME_PARMS *frame_parms,
                                      PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
                                      uint16_t si_rnti,
                                      uint16_t ra_rnti,
                                      uint16_t p_rnti);

1355
int32_t generate_eNB_dlsch_params_from_dci(uint8_t subframe,
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
    void *dci_pdu,
    rnti_t rnti,
    DCI_format_t dci_format,
    LTE_eNB_DLSCH_t **dlsch_eNB,
    LTE_DL_FRAME_PARMS *frame_parms,
    PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
    uint16_t si_rnti,
    uint16_t ra_rnti,
    uint16_t p_rnti,
    uint16_t DL_pmi_single);
1366

1367
int32_t generate_eNB_ulsch_params_from_rar(uint8_t *rar_pdu,
1368 1369 1370 1371
    frame_t frame,
    uint8_t subframe,
    LTE_eNB_ULSCH_t *ulsch,
    LTE_DL_FRAME_PARMS *frame_parms);
1372 1373

int generate_ue_ulsch_params_from_dci(void *dci_pdu,
1374
                                      rnti_t rnti,
1375 1376 1377 1378 1379 1380 1381 1382 1383
                                      uint8_t subframe,
                                      DCI_format_t dci_format,
                                      PHY_VARS_UE *phy_vars_ue,
                                      uint16_t si_rnti,
                                      uint16_t ra_rnti,
                                      uint16_t p_rnti,
                                      uint16_t cba_rnti,
                                      uint8_t eNB_id,
                                      uint8_t use_srs);
1384

1385
int32_t generate_ue_ulsch_params_from_rar(PHY_VARS_UE *phy_vars_ue,
1386
    uint8_t eNB_id);
1387
double sinr_eff_cqi_calc(PHY_VARS_UE *phy_vars_ue,
1388
                         uint8_t eNB_id);
1389
int generate_eNB_ulsch_params_from_dci(void *dci_pdu,
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
                                       rnti_t rnti,
                                       uint8_t subframe,
                                       DCI_format_t dci_format,
                                       uint8_t UE_id,
                                       PHY_VARS_eNB *PHY_vars_eNB,
                                       uint16_t si_rnti,
                                       uint16_t ra_rnti,
                                       uint16_t p_rnti,
                                       uint16_t cba_rnti,
                                       uint8_t use_srs);
1400 1401 1402 1403 1404 1405 1406 1407

#ifdef USER_MODE
void dump_ulsch(PHY_VARS_eNB *phy_vars_eNb,uint8_t subframe, uint8_t UE_id);

void dump_dlsch(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,uint8_t harq_pid);
void dump_dlsch_SI(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe);
void dump_dlsch_ra(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe);

Raymond Knopp's avatar
Raymond Knopp committed
1408
void dump_dlsch2(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint16_t coded_bits_per_codeword,int round);
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
#endif

int dump_dci(LTE_DL_FRAME_PARMS *frame_parms, DCI_ALLOC_t *dci);

int dump_ue_stats(PHY_VARS_UE *phy_vars_ue, char* buffer, int length, runmode_t mode, int input_level_dBm);
int dump_eNB_stats(PHY_VARS_eNB *phy_vars_eNB, char* buffer, int length);



void generate_pcfich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms);

void pcfich_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
1421 1422 1423
                       uint8_t subframe,
                       uint8_t *b,
                       uint8_t *bt);
1424 1425

void pcfich_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
1426 1427
                         uint8_t subframe,
                         int16_t *d);
1428 1429

void generate_pcfich(uint8_t num_pdcch_symbols,
1430 1431 1432 1433
                     int16_t amp,
                     LTE_DL_FRAME_PARMS *frame_parms,
                     mod_sym_t **txdataF,
                     uint8_t subframe);
1434 1435

uint8_t rx_pcfich(LTE_DL_FRAME_PARMS *frame_parms,
1436 1437 1438
                  uint8_t subframe,
                  LTE_UE_PDCCH *lte_ue_pdcch_vars,
                  MIMO_mode_t mimo_mode);
1439 1440 1441 1442 1443 1444 1445 1446 1447

void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms);


void init_transport_channels(uint8_t);

void generate_RIV_tables(void);

/*!
1448 1449
  \brief This function performs the initial cell search procedure - PSS detection, SSS detection and PBCH detection.  At the
  end, the basic frame parameters are known (Frame configuration - TDD/FDD and cyclic prefix length,
1450 1451 1452 1453 1454 1455 1456
  N_RB_DL, PHICH_CONFIG and Nid_cell) and the UE can begin decoding PDCCH and DLSCH SI to retrieve the rest.  Once these
  parameters are know, the routine calls some basic initialization routines (cell-specific reference signals, etc.)
  @param phy_vars_ue Pointer to UE variables
*/
int initial_sync(PHY_VARS_UE *phy_vars_ue, runmode_t mode);

void rx_ulsch(PHY_VARS_eNB *phy_vars_eNB,
1457 1458 1459 1460 1461
              uint32_t subframe,
              uint8_t eNB_id,  // this is the effective sector id
              uint8_t UE_id,
              LTE_eNB_ULSCH_t **ulsch,
              uint8_t cooperation_flag);
1462 1463

void rx_ulsch_emul(PHY_VARS_eNB *phy_vars_eNB,
1464 1465 1466
                   uint8_t subframe,
                   uint8_t sect_id,
                   uint8_t UE_index);
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478

/*!
  \brief Encoding of PUSCH/ACK/RI/ACK from 36-212.
  @param a Pointer to ulsch SDU
  @param frame_parms Pointer to Frame parameters
  @param ulsch Pointer to ulsch descriptor
  @param harq_pid HARQ process ID
  @param tmode Transmission mode (1-7)
  @param control_only_flag Generate PUSCH with control information only
  @param Nbundled Parameter for ACK/NAK bundling (36.213 Section 7.3)
*/
uint32_t ulsch_encoding(uint8_t *a,
1479 1480 1481 1482 1483 1484
                        PHY_VARS_UE *phy_vars_ue,
                        uint8_t harq_pid,
                        uint8_t eNB_id,
                        uint8_t tmode,
                        uint8_t control_only_flag,
                        uint8_t Nbundled);
1485 1486 1487 1488 1489 1490 1491 1492 1493

/*!
  \brief Encoding of PUSCH/ACK/RI/ACK from 36-212 for emulation
  @param ulsch_buffer Pointer to ulsch SDU
  @param phy_vars_ue Pointer to UE top-level descriptor
  @param eNB_id ID of eNB receiving this PUSCH
  @param harq_pid HARQ process ID
  @param control_only_flag Generate PUSCH with control information only
*/
1494
int32_t ulsch_encoding_emul(uint8_t *ulsch_buffer,
1495 1496 1497 1498
                            PHY_VARS_UE *phy_vars_ue,
                            uint8_t eNB_id,
                            uint8_t harq_pid,
                            uint8_t control_only_flag);
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510

/*!
  \brief Decoding of PUSCH/ACK/RI/ACK from 36-212.
  @param phy_vars_eNB Pointer to eNB top-level descriptor
  @param UE_id ID of UE transmitting this PUSCH
  @param subframe Index of subframe for PUSCH
  @param control_only_flag Receive PUSCH with control information only
  @param Nbundled Nbundled parameter for ACK/NAK scrambling from 36-212/36-213
  @param llr8_flag If 1, indicate that the 8-bit turbo decoder should be used
  @returns 0 on success
*/
unsigned int  ulsch_decoding(PHY_VARS_eNB *phy_vars_eNB,
1511 1512 1513 1514 1515
                             uint8_t UE_id,
                             uint8_t subframe,
                             uint8_t control_only_flag,
                             uint8_t Nbundled,
                             uint8_t llr8_flag);
1516 1517

uint32_t ulsch_decoding_emul(PHY_VARS_eNB *phy_vars_eNB,
1518 1519 1520
                             uint8_t subframe,
                             uint8_t UE_index,
                             uint16_t *crnti);
1521 1522

void generate_phich_top(PHY_VARS_eNB *phy_vars_eNB,
1523 1524 1525 1526
                        uint8_t subframe,
                        int16_t amp,
                        uint8_t sect_id,
                        uint8_t abstraction_flag);
1527 1528 1529 1530 1531 1532 1533 1534

/* \brief  This routine demodulates the PHICH and updates PUSCH/ULSCH parameters.
   @param phy_vars_ue Pointer to UE variables
   @param subframe Subframe of received PDCCH/PHICH
   @param eNB_id Index of eNB
*/

void rx_phich(PHY_VARS_UE *phy_vars_ue,
1535 1536
              uint8_t subframe,
              uint8_t eNB_id);
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551


/** \brief  This routine provides the relationship between a PHICH TXOp and its corresponding PUSCH subframe (Table 8.3.-1 from 36.213).
    @param frame_parms Pointer to DL frame configuration parameters
    @param subframe Subframe of received/transmitted PHICH
    @returns subframe of PUSCH transmission
*/
uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe);

/** \brief  This routine provides the relationship between a PHICH TXOp and its corresponding PUSCH frame (Table 8.3.-1 from 36.213).
    @param frame_parms Pointer to DL frame configuration parameters
    @param frame Frame of received/transmitted PHICH
    @param subframe Subframe of received/transmitted PHICH
    @returns frame of PUSCH transmission
*/
1552
uint8_t phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms,frame_t frame,uint8_t subframe);;
1553

Raymond Knopp's avatar
 
Raymond Knopp committed
1554
void print_CQI(void *o,UCI_format_t uci_format,uint8_t eNB_id,int N_RB_DL);
1555

1556
void extract_CQI(void *o,UCI_format_t uci_format,LTE_eNB_UE_stats *stats,uint8_t N_RB_DL, uint16_t * crnti, uint8_t * access_mode);
1557

1558
void fill_CQI(LTE_UE_ULSCH_t *ulsch,PHY_MEASUREMENTS *meas,uint8_t eNB_id, uint8_t harq_pid,int N_RB_DL, rnti_t rnti, uint8_t trans_mode,double sinr_eff);
1559 1560
void reset_cba_uci(void *o);

Raymond Knopp's avatar
 
Raymond Knopp committed
1561 1562
uint16_t quantize_subband_pmi(PHY_MEASUREMENTS *meas,uint8_t eNB_id,int nb_subbands);
uint16_t quantize_subband_pmi2(PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_t a_id,int nb_subbands);
1563

Raymond Knopp's avatar
 
Raymond Knopp committed
1564
uint64_t pmi2hex_2Ar1(uint32_t pmi);
1565

Raymond Knopp's avatar
 
Raymond Knopp committed
1566
uint64_t pmi2hex_2Ar2(uint32_t pmi);
1567

Raymond Knopp's avatar
 
Raymond Knopp committed
1568
uint64_t cqi2hex(uint32_t cqi);
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580

uint16_t computeRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs);

uint32_t pmi_extend(LTE_DL_FRAME_PARMS *frame_parms,uint8_t wideband_pmi);


uint16_t get_nCCE(uint8_t num_pdcch_symbols,LTE_DL_FRAME_PARMS *frame_parms,uint8_t mi);

uint16_t get_nquad(uint8_t num_pdcch_symbols,LTE_DL_FRAME_PARMS *frame_parms,uint8_t mi);

uint8_t get_mi(LTE_DL_FRAME_PARMS *frame,uint8_t subframe);

Raymond Knopp's avatar
 
Raymond Knopp committed
1581
uint16_t get_nCCE_max(uint8_t Mod_id,uint8_t CC_id);
1582 1583 1584 1585 1586 1587

uint8_t get_num_pdcch_symbols(uint8_t num_dci,DCI_ALLOC_t *dci_alloc,LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe);

void pdcch_interleaving(LTE_DL_FRAME_PARMS *frame_parms,mod_sym_t **z, mod_sym_t **wbar,uint8_t n_symbols_pdcch,uint8_t mi);

void pdcch_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
1588 1589 1590
                        uint8_t subframe,
                        int8_t* llr,
                        uint32_t length);
1591 1592

void pdcch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
1593 1594 1595
                      uint8_t subframe,
                      uint8_t *e,
                      uint32_t length);
1596 1597

void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
1598 1599 1600 1601 1602
                      int mbsfn_flag,
                      LTE_eNB_DLSCH_t *dlsch,
                      int G,
                      uint8_t q,
                      uint8_t Ns);
1603 1604

void dlsch_unscrambling(LTE_DL_FRAME_PARMS *frame_parms,
1605 1606 1607 1608 1609 1610
                        int mbsfn_flag,
                        LTE_UE_DLSCH_t *dlsch,
                        int G,
                        int16_t* llr,
                        uint8_t q,
                        uint8_t Ns);
1611 1612 1613 1614

void init_ncs_cell(LTE_DL_FRAME_PARMS *frame_parms,uint8_t ncs_cell[20][7]);

void generate_pucch(mod_sym_t **txdataF,
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
                    LTE_DL_FRAME_PARMS *frame_parms,
                    uint8_t ncs_cell[20][7],
                    PUCCH_FMT_t fmt,
                    PUCCH_CONFIG_DEDICATED *pucch_config_dedicated,
                    uint16_t n1_pucch,
                    uint16_t n2_pucch,
                    uint8_t shortened_format,
                    uint8_t *payload,
                    int16_t amp,
                    uint8_t subframe);
1625 1626

void generate_pucch_emul(PHY_VARS_UE *phy_vars_ue,
1627 1628 1629 1630 1631
                         PUCCH_FMT_t format,
                         uint8_t ncs1,
                         uint8_t *pucch_ack_payload,
                         uint8_t sr,
                         uint8_t subframe);
1632 1633


1634
int32_t rx_pucch(PHY_VARS_eNB *phy_vars_eNB,
1635 1636 1637 1638 1639 1640 1641 1642
                 PUCCH_FMT_t fmt,
                 uint8_t UE_id,
                 uint16_t n1_pucch,
                 uint16_t n2_pucch,
                 uint8_t shortened_format,
                 uint8_t *payload,
                 uint8_t subframe,
                 uint8_t pucch1_thres);
1643

1644
int32_t rx_pucch_emul(PHY_VARS_eNB *phy_vars_eNB,
1645 1646 1647 1648 1649
                      uint8_t UE_index,
                      PUCCH_FMT_t fmt,
                      uint8_t n1_pucch_sel,
                      uint8_t *payload,
                      uint8_t subframe);
1650 1651 1652 1653 1654 1655 1656 1657 1658


/*!
  \brief Check for PRACH TXop in subframe
  @param frame_parms Pointer to LTE_DL_FRAME_PARMS
  @param frame frame index to check
  @param subframe subframe index to check
  @returns 0 on success
*/
1659
int is_prach_subframe(LTE_DL_FRAME_PARMS *frame_parms,frame_t frame, uint8_t subframe);
1660 1661 1662 1663 1664 1665 1666 1667 1668

/*!
  \brief Generate PRACH waveform
  @param phy_vars_ue Pointer to ue top-level descriptor
  @param eNB_id Index of destination eNB
  @param subframe subframe index to operate on
  @param index of preamble (0-63)
  @param Nf System frame number
  @returns 0 on success
1669

1670
*/
1671
int32_t generate_prach(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,uint16_t Nf);
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681

/*!
  \brief Process PRACH waveform
  @param phy_vars_eNB Pointer to eNB top-level descriptor
  @param subframe subframe index to operate on
  @param preamble_energy_list List of energies for each candidate preamble
  @param preamble_delay_list List of delays for each candidate preamble
  @param Nf System frame number
  @param tdd_mapindex Index of PRACH resource in Table 5.7.1-4 (TDD)
  @returns 0 on success
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
*/
void rx_prach(PHY_VARS_eNB *phy_vars_eNB,uint8_t subframe,uint16_t *preamble_energy_list, uint16_t *preamble_delay_list, uint16_t Nf, uint8_t tdd_mapindex);

/*!
  \brief Helper for MAC, returns number of available PRACH in TDD for a particular configuration index
  @param frame_parms Pointer to LTE_DL_FRAME_PARMS structure
  @returns 0-5 depending on number of available prach
*/
uint8_t get_num_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms);

/*!
  \brief Return the PRACH format as a function of the Configuration Index and Frame type.
  @param prach_ConfigIndex PRACH Configuration Index
  @param frame_type 0-FDD, 1-TDD
  @returns 0-1 accordingly
*/
uint8_t get_prach_fmt(uint8_t prach_ConfigIndex,lte_frame_type_t frame_type);

/*!
  \brief Helper for MAC, returns frequency index of PRACH resource in TDD for a particular configuration index
  @param frame_parms Pointer to LTE_DL_FRAME_PARMS structure
  @returns 0-5 depending on number of available prach
*/
uint8_t get_fid_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms,uint8_t tdd_map_index);

/*!
  \brief Comp ute DFT of PRACH ZC sequences.  Used for generation of prach in UE and reception of PRACH in eNB.
  @param prach_config_common Pointer to prachConfigCommon structure
1711
  @param Xu DFT output
1712 1713
*/
void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
1714 1715
                       lte_frame_type_t frame_type,
                       uint32_t X_u[64][839]);
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725

void init_prach_tables(int N_ZC);

/*!
  \brief Return the status of MBSFN in this frame/subframe
  @param frame Frame index
  @param subframe Subframe index
  @param frame_parms Pointer to frame parameters
  @returns 1 if subframe is for MBSFN
*/
1726
int is_pmch_subframe(frame_t frame, int subframe, LTE_DL_FRAME_PARMS *frame_parms);
1727

1728
uint8_t is_not_pilot(uint8_t pilots, uint8_t re, uint8_t nushift, uint8_t use2ndpilots);
1729 1730

uint32_t dlsch_decoding_abstraction(double *dlsch_MIPB,
1731 1732 1733 1734
                                    LTE_DL_FRAME_PARMS *lte_frame_parms,
                                    LTE_UE_DLSCH_t *dlsch,
                                    uint8_t subframe,
                                    uint8_t num_pdcch_symbols);
1735 1736 1737 1738

// DL power control functions
double get_pa_dB(PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated);

1739
double computeRhoA_eNB(PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
1740
                       LTE_eNB_DLSCH_t *dlsch_eNB,
1741
                       int dl_power_off);
1742 1743 1744 1745

double computeRhoB_eNB(PDSCH_CONFIG_DEDICATED  *pdsch_config_dedicated,
                       PDSCH_CONFIG_COMMON *pdsch_config_common,
                       uint8_t n_antenna_port,
1746
                       LTE_eNB_DLSCH_t *dlsch_eNB,int dl_power_off);
1747

1748
double computeRhoA_UE(PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762
                      LTE_UE_DLSCH_t *dlsch_ue,
                      uint8_t dl_power_off);

double computeRhoB_UE(PDSCH_CONFIG_DEDICATED  *pdsch_config_dedicated,
                      PDSCH_CONFIG_COMMON *pdsch_config_common,
                      uint8_t n_antenna_port,
                      LTE_UE_DLSCH_t *dlsch_ue,
                      uint8_t dl_power_off);

/*void compute_sqrt_RhoAoRhoB(PDSCH_CONFIG_DEDICATED  *pdsch_config_dedicated,
  PDSCH_CONFIG_COMMON *pdsch_config_common,
  uint8_t n_antenna_port,
  LTE_UE_DLSCH_t *dlsch_ue);
*/
1763 1764 1765

  uint8_t get_prach_prb_offset(LTE_DL_FRAME_PARMS *frame_parms, uint8_t tdd_mapindex, uint16_t Nf); 

1766 1767
/**@}*/
#endif