defs_gNB.h 30.8 KB
Newer Older
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
/*
 * 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/defs_gNB.h
 \brief Top-level defines and structure definitions for gNB
 \author Guy De Souza
 \date 2018
 \version 0.1
 \company Eurecom
 \email: desouza@eurecom.fr
 \note
 \warning
*/
yilmazt's avatar
yilmazt committed
32

33 34 35 36 37
#ifndef __PHY_DEFS_GNB__H__
#define __PHY_DEFS_GNB__H__

#include "defs_eNB.h"
#include "defs_nr_common.h"
38
#include "CODING/nrPolar_tools/nr_polar_pbch_defs.h"
39
#include "openair2/NR_PHY_INTERFACE/NR_IF_Module.h"
Hongzhi Wang's avatar
Hongzhi Wang committed
40
#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
41 42
#include "PHY/impl_defs_top.h"
#include "PHY/defs_common.h"
43
#include "PHY/CODING/nrLDPC_extern.h"
44
#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
45

46 47
#include "nfapi_nr_interface_scf.h"

48
#define MAX_NUM_RU_PER_gNB MAX_NUM_RU_PER_eNB
49 50 51 52 53 54 55
#define MAX_PUCCH0_NID 8

typedef struct {
  int nb_id;
  int Nid[MAX_PUCCH0_NID];
  int lut[MAX_PUCCH0_NID][160][14];
} NR_gNB_PUCCH0_LUT_t;
56

57

Guy De Souza's avatar
Guy De Souza committed
58
typedef struct {
59
  uint32_t pbch_a;
Hongzhi's avatar
Hongzhi committed
60 61 62
  uint32_t pbch_a_interleaved;
  uint32_t pbch_a_prime;
  uint32_t pbch_e[NR_POLAR_PBCH_E_DWORD];
Guy De Souza's avatar
Guy De Souza committed
63 64
} NR_gNB_PBCH;

65 66 67 68 69 70 71 72 73
typedef struct {
  uint8_t ssb_start_symbol;
  uint8_t n_hf;
  uint8_t Lmax;
  uint8_t ssb_index;
  int32_t sfn;
} NR_PBCH_parms_t;


74 75 76 77 78 79 80 81
typedef enum {
  NR_SCH_IDLE,
  NR_ACTIVE,
  NR_CBA_ACTIVE,
  NR_DISABLED
} NR_SCH_status_t;


82
typedef struct {
Guy De Souza's avatar
Guy De Souza committed
83
  /// Nfapi DLSCH PDU
Raymond Knopp's avatar
Raymond Knopp committed
84
  nfapi_nr_dl_tti_pdsch_pdu pdsch_pdu;
85 86 87 88 89 90 91
  /// pointer to pdu from MAC interface (this is "a" in 36.212)
  uint8_t *pdu;
  /// The payload + CRC size in bits, "B" from 36-212
  uint32_t B;
  /// Pointer to the payload
  uint8_t *b;
  /// Pointers to transport block segments
Hongzhi Wang's avatar
Hongzhi Wang committed
92
  uint8_t *c[MAX_NUM_NR_DLSCH_SEGMENTS];
93 94 95 96 97 98
  /// Frame where current HARQ round was sent
  uint32_t frame;
  /// Subframe where current HARQ round was sent
  uint32_t subframe;
  /// MIMO mode for this DLSCH
  MIMO_mode_t mimo_mode;
Hongzhi Wang's avatar
Hongzhi Wang committed
99
  /// Concatenated sequences
100
  uint8_t *e;
Hongzhi Wang's avatar
Hongzhi Wang committed
101 102 103
  /// LDPC-code outputs
  uint8_t *d[MAX_NUM_NR_DLSCH_SEGMENTS];
  /// Interleaver outputs
104
  uint8_t *f;
Hongzhi Wang's avatar
Hongzhi Wang committed
105
  /// Number of code segments
106
  uint32_t C;
Hongzhi Wang's avatar
Hongzhi Wang committed
107 108 109
  /// Number of bits in "small" code segments
  uint32_t K;
  /// Number of "Filler" bits
110
  uint32_t F;
Sakthivel Velumani's avatar
Sakthivel Velumani committed
111 112
  /// Encoder BG
  uint8_t BG;
113 114
  /// LDPC lifting size
  uint32_t Z;
115 116
} NR_DL_gNB_HARQ_t;

117 118 119 120 121 122 123 124 125 126 127
typedef struct {
  int frame;
  int slot;
  nfapi_nr_dl_tti_pdcch_pdu pdcch_pdu;
} NR_gNB_PDCCH_t;

typedef struct {
  int frame;
  int slot;
  nfapi_nr_ul_dci_request_pdus_t pdcch_pdu;
} NR_gNB_UL_PDCCH_t;
128

129
typedef struct {
130
  uint16_t rnti;
131
  int round_trials[8];
Raymond Knopp's avatar
Raymond Knopp committed
132 133
  int total_bytes_tx;
  int total_bytes_rx;
134 135 136
  int current_Qm;
  int current_RI;
} NR_gNB_SCH_STATS_t;
137 138

typedef struct {
139 140
  /// Pointers to variables related to DLSCH harq process
  NR_DL_gNB_HARQ_t harq_process;
Hongzhi Wang's avatar
Hongzhi Wang committed
141
  /// TX buffers for UE-spec transmission (antenna ports 5 or 7..14, prior to precoding)
142 143 144
  int32_t *txdataF[NR_MAX_NB_LAYERS];
  /// Modulated symbols buffer
  int32_t *mod_symbs[NR_MAX_NB_CODEWORDS];
145
  /// beamforming weights for UE-spec transmission (antenna ports 5 or 7..14), for each codeword, maximum 4 layers?
146
  int32_t **ue_spec_bf_weights[NR_MAX_NB_LAYERS];
147 148 149 150 151 152 153 154 155
  /// dl channel estimates (estimated from ul channel estimates)
  int32_t **calib_dl_ch_estimates;
  /// Allocated RNTI (0 means DLSCH_t is not currently used)
  uint16_t rnti;
  /// Active flag for baseband transmitter processing
  uint8_t active;
  /// HARQ process mask, indicates which processes are currently active
  uint16_t harq_mask;
  /// Indicator of TX activation per subframe.  Used during PUCCH detection for ACK/NAK.
156
  uint8_t slot_tx[80];
157 158 159
  /// First CCE of last PDSCH scheduling per subframe.  Again used during PUCCH detection for ACK/NAK.
  uint8_t nCCE[10];
  /// Process ID's per subframe.  Used to associate received ACKs on PUSCH/PUCCH to DLSCH harq process ids
160
  uint8_t harq_ids[2][80];
161 162 163 164 165 166 167 168
  /// Window size (in outgoing transport blocks) for fine-grain rate adaptation
  uint8_t ra_window_size;
  /// First-round error threshold for fine-grain rate adaptation
  uint8_t error_threshold;
  /// Number of soft channel bits
  uint32_t G;
  /// Codebook index for this dlsch (0,1,2,3)
  uint8_t codebook_index;
Hongzhi Wang's avatar
Hongzhi Wang committed
169
  /// Maximum number of HARQ processes
170 171 172
  uint8_t Mdlharq;
  /// Maximum number of HARQ rounds
  uint8_t Mlimit;
Hongzhi Wang's avatar
Hongzhi Wang committed
173
  /// MIMO transmission mode indicator for this sub-frame
174 175 176 177 178 179 180 181 182
  uint8_t Kmimo;
  /// Nsoft parameter related to UE Category
  uint32_t Nsoft;
  /// amplitude of PDSCH (compared to RS) in symbols without pilots
  int16_t sqrt_rho_a;
  /// amplitude of PDSCH (compared to RS) in symbols containing pilots
  int16_t sqrt_rho_b;
} NR_gNB_DLSCH_t;

183 184


185 186 187 188 189 190 191 192
typedef struct {
  int frame;
  int slot;
  nfapi_nr_prach_pdu_t pdu;  
} gNB_PRACH_list_t;

#define NUMBER_OF_NR_PRACH_MAX 8

193 194 195 196 197 198 199 200 201 202
typedef struct {
  /// \brief ?.
  /// first index: ? [0..1023] (hard coded)
  int16_t *prachF;
  /// \brief ?.
  /// second index: rx antenna [0..63] (hard coded) \note Hard coded array size indexed by \c nb_antennas_rx.
  /// third index: frequency-domain sample [0..ofdm_symbol_size*12[
  int16_t **rxsigF;
  /// \brief local buffer to compute prach_ifft
  int32_t *prach_ifft;
203
  gNB_PRACH_list_t list[NUMBER_OF_NR_PRACH_MAX];
204
} NR_gNB_PRACH;
205

206 207
typedef struct {
  /// Nfapi ULSCH PDU
208
  nfapi_nr_pusch_pdu_t ulsch_pdu;
209 210
  /// Frame where current HARQ round was sent
  uint32_t frame;
211 212
  /// Slot where current HARQ round was sent
  uint32_t slot;
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
  /// Index of current HARQ round for this DLSCH
  uint8_t round;
  /// Last TPC command
  uint8_t TPC;
  /// MIMO mode for this DLSCH
  MIMO_mode_t mimo_mode;
  /// Flag indicating that this ULSCH has been allocated by a DCI (otherwise it is a retransmission based on PHICH NAK)
  uint8_t dci_alloc;
  /// Flag indicating that this ULSCH has been allocated by a RAR (otherwise it is a retransmission based on PHICH NAK or DCI)
  uint8_t rar_alloc;
  /// Status Flag indicating for this ULSCH (idle,active,disabled)
  NR_SCH_status_t status;
  /// Subframe scheduling indicator (i.e. Transmission opportunity indicator)
  uint8_t subframe_scheduling_flag;
  /// Subframe cba scheduling indicator (i.e. CBA Transmission opportunity indicator)
  uint8_t subframe_cba_scheduling_flag;
  /// PHICH active flag
  uint8_t phich_active;
  /// PHICH ACK
  uint8_t phich_ACK;
  /// First Allocated RB - previous scheduling. This is needed for PHICH generation which is done after a new scheduling
  uint16_t previous_first_rb;
  /// Flag to indicate that the UL configuration has been handled. Used to remove a stale ULSCH when frame wraps around
  uint8_t handled;
  /// Flag to indicate that this ULSCH is for calibration information sent from UE (i.e. no MAC SDU to pass up)
  //  int calibration_flag;
  /// delta_TF for power control
  int32_t delta_TF;

  
  /////////////////////// ulsch decoding ///////////////////////
  /// Transport block size (This is A from 38.212 V15.4.0 section 5.1)
  uint32_t TBS;
  /// Pointer to the payload (38.212 V15.4.0 section 5.1)
  uint8_t *b;
  /// The payload + CRC (24 bits) in bits (38.212 V15.4.0 section 5.1)
  uint32_t B;
  /// Pointers to code blocks after code block segmentation and CRC attachment (38.212 V15.4.0 section 5.2.2)
  uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS];
  /// Number of bits in each code block (38.212 V15.4.0 section 5.2.2)
  uint32_t K;
  /// Number of "Filler" bits added in the code block segmentation (38.212 V15.4.0 section 5.2.2)
  uint32_t F;
  /// Number of code blocks after code block segmentation (38.212 V15.4.0 section 5.2.2)
  uint32_t C;
  /// Pointers to code blocks after LDPC coding (38.212 V15.4.0 section 5.3.2)
  int16_t *d[MAX_NUM_NR_ULSCH_SEGMENTS];
  /// LDPC processing buffer
  t_nrLDPC_procBuf* p_nrLDPC_procBuf[MAX_NUM_NR_ULSCH_SEGMENTS];
  /// LDPC lifting size (38.212 V15.4.0 table 5.3.2-1)
  uint32_t Z;
  /// code blocks after bit selection in rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1)
  int16_t e[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448];
  /// Number of bits in each code block after rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1)
  uint32_t E;
268 269
  /// Number of segments processed so far
  uint32_t processedSegments;
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
  //////////////////////////////////////////////////////////////


  /////////////////////////// DMRS /////////////////////////////
  /// n_DMRS  for cyclic shift of DMRS (36.213 Table 9.1.2-2)
  uint8_t n_DMRS;
  /// n_DMRS 2 for cyclic shift of DMRS (36.211 Table 5.5.1.1.-1)
  uint8_t n_DMRS2;
  /// n_DMRS  for cyclic shift of DMRS (36.213 Table 9.1.2-2) - previous scheduling
  /// This is needed for PHICH generation which
  /// is done after a new scheduling
  uint8_t previous_n_DMRS;
  //////////////////////////////////////////////////////////////


  ///////////////////// UCI multiplexing ///////////////////////
  /// CQI CRC status
  uint8_t cqi_crc_status;
  /// Pointer to CQI data
  uint8_t o[MAX_CQI_BYTES];
  /// Format of CQI data
  UCI_format_t uci_format;
  /// Length of CQI data under RI=1 assumption(bits)
  uint8_t Or1;
  /// Length of CQI data under RI=2 assumption(bits)
  uint8_t Or2;
  /// Rank information
  uint8_t o_RI[2];
  /// Length of rank information (bits)
  uint8_t O_RI;
  /// Pointer to ACK
  uint8_t o_ACK[4];
  /// Length of ACK information (bits)
  uint8_t O_ACK;
  /// The value of DAI in DCI format 0
  uint8_t V_UL_DAI;
  /// "q" sequences for CQI/PMI (for definition see 36-212 V8.6 2009-03, p.27)
  int8_t q[MAX_CQI_PAYLOAD];
  /// number of coded CQI bits after interleaving
  uint8_t o_RCC;
  /// coded and interleaved CQI bits
  int8_t o_w[(MAX_CQI_BITS+8)*3];
  /// coded CQI bits
  int8_t o_d[96+((MAX_CQI_BITS+8)*3)];
  /// coded ACK bits
  int16_t q_ACK[MAX_ACK_PAYLOAD];
  /// coded RI bits
  int16_t q_RI[MAX_RI_PAYLOAD];
  /// Temporary h sequence to flag PUSCH_x/PUSCH_y symbols which are not scrambled
  uint8_t h[MAX_NUM_CHANNEL_BITS];
  /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15)
321
  int16_t *w[MAX_NUM_NR_ULSCH_SEGMENTS];
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
  //////////////////////////////////////////////////////////////
} NR_UL_gNB_HARQ_t;


typedef struct {
  /// Pointers to 16 HARQ processes for the ULSCH
  NR_UL_gNB_HARQ_t *harq_processes[NR_MAX_ULSCH_HARQ_PROCESSES];
  /// Current HARQ process id
  int harq_process_id[NR_MAX_SLOTS_PER_FRAME];
  /// HARQ process mask, indicates which processes are currently active
  uint16_t harq_mask;
  /// ACK/NAK Bundling flag
  uint8_t bundling;
  /// beta_offset_cqi times 8
  uint16_t beta_offset_cqi_times8;
  /// beta_offset_ri times 8
  uint16_t beta_offset_ri_times8;
  /// beta_offset_harqack times 8
  uint16_t beta_offset_harqack_times8;
  /// Flag to indicate that gNB awaits UE Msg3
  uint8_t Msg3_active;
  /// Flag to indicate that gNB should decode UE Msg3
  uint8_t Msg3_flag;
  /// Subframe for Msg3
  uint8_t Msg3_subframe;
  /// Frame for Msg3
  uint32_t Msg3_frame;
  /// Allocated RNTI for this ULSCH
  uint16_t rnti;
  /// RNTI type
  uint8_t rnti_type;
  /// cyclic shift for DM RS
  uint8_t cyclicShift;
  /// for cooperative communication
  uint8_t cooperation_flag;
  /// Maximum number of HARQ rounds
  uint8_t Mlimit;
  /// Maximum number of LDPC iterations
  uint8_t max_ldpc_iterations;
  /// number of iterations used in last LDPC decoding
  uint8_t last_iteration_cnt;  
} NR_gNB_ULSCH_t;

Francesco Mani's avatar
Francesco Mani committed
365 366 367 368 369 370 371 372 373
typedef struct {
  uint8_t active;
  /// Frame where current PUCCH pdu was sent
  uint32_t frame;
  /// Slot where current PUCCH pdu was sent
  uint32_t slot;
  /// ULSCH PDU
  nfapi_nr_pucch_pdu_t pucch_pdu;
} NR_gNB_PUCCH_t;
374

375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
typedef struct {
  /// \brief Pointers (dynamic) to the received data in the time domain.
  /// - first index: rx antenna [0..nb_antennas_rx[
  /// - second index: ? [0..2*ofdm_symbol_size*frame_parms->symbols_per_tti[
  int32_t **rxdata;
  /// \brief Pointers (dynamic) to the received data in the frequency domain.
  /// - first index: rx antenna [0..nb_antennas_rx[
  /// - second index: ? [0..2*ofdm_symbol_size*frame_parms->symbols_per_tti[
  int32_t **rxdataF;
  /// \brief holds the transmit data in the frequency domain.
  /// For IFFT_FPGA this points to the same memory as PHY_vars->rx_vars[a].RX_DMA_BUFFER. //?
  /// - first index: eNB id [0..2] (hard coded)
  /// - second index: tx antenna [0..14[ where 14 is the total supported antenna ports.
  /// - third index: sample [0..]
  int32_t **txdataF;
390 391
  int32_t *debugBuff;
  int32_t debugBuff_sample_offset;
392 393 394
} NR_gNB_COMMON;


395 396 397 398 399 400 401 402 403 404 405 406
typedef struct {
  /// \brief Holds the received data in the frequency domain for the allocated RBs in repeated format.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..2*ofdm_symbol_size[
  int32_t **rxdataF_ext;
  /// \brief Holds the received data in the frequency domain for the allocated RBs in normal format.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index (definition from phy_init_lte_eNB()): ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **rxdataF_ext2;
  /// \brief Hold the channel estimates in time domain based on DRS.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..4*ofdm_symbol_size[
407
  int32_t **ul_ch_estimates_time;
408 409 410
  /// \brief Hold the channel estimates in frequency domain based on DRS.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
411 412 413 414 415
  int32_t **ul_ch_estimates;
  /// \brief Uplink channel estimates extracted in PRBS.
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **ul_ch_estimates_ext;
416 417 418 419 420 421 422 423
  /// \brief Hold the PTRS phase estimates in frequency domain.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **ul_ch_ptrs_estimates;
  /// \brief Uplink phase estimates extracted in PRBS.
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **ul_ch_ptrs_estimates_ext;
424 425 426 427 428 429 430 431 432 433 434 435
  /// \brief Holds the compensated signal.
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **rxdataF_comp;
  /// \brief Magnitude of the UL channel estimates. Used for 2nd-bit level thresholds in LLR computation
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **ul_ch_mag;
  /// \brief Magnitude of the UL channel estimates scaled for 3rd bit level thresholds in LLR computation
  /// - first index: rx antenna id [0..nb_antennas_rx[
  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
  int32_t **ul_ch_magb;
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
  /// \brief Cross-correlation of two UE signals.
  /// - first index: rx antenna [0..nb_antennas_rx[
  /// - second index: symbol [0..]
  int32_t **rho;
  /// \f$\log_2(\max|H_i|^2)\f$
  int16_t log2_maxh;
  /// \brief Magnitude of Uplink Channel first layer (16QAM level/First 64QAM level).
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..168*N_RB_UL[
  int32_t **ul_ch_mag0;
  /// \brief Magnitude of Uplink Channel second layer (16QAM level/First 64QAM level).
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..168*N_RB_UL[
  int32_t **ul_ch_mag1[8][8];
  /// \brief Magnitude of Uplink Channel, first layer (2nd 64QAM level).
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..168*N_RB_UL[
  int32_t **ul_ch_magb0;
  /// \brief Magnitude of Uplink Channel second layer (2nd 64QAM level).
  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
  /// - second index: ? [0..168*N_RB_UL[
  int32_t **ul_ch_magb1[8][8];
458 459 460 461 462
  /// measured RX power based on DRS
  int ulsch_power[2];
  /// \brief llr values.
  /// - first index: ? [0..1179743] (hard coded)
  int16_t *llr;
463
  /// DMRS symbol index, to be updated every DMRS symbol within a slot.
464
  uint8_t dmrs_symbol;
465 466 467 468 469
  // PTRS symbol index, to be updated every PTRS symbol within a slot.
  uint8_t ptrs_symbol_index;
  /// bit mask of PT-RS ofdm symbol indicies
  uint16_t ptrs_symbols;
  // PTRS subcarriers per OFDM symbol
470
  int32_t ptrs_re_per_slot;
471 472 473 474
  /// \brief Estimated phase error based upon PTRS on each symbol .
  /// - first index: ? [0..7] Number of Antenna
  /// - second index: ? [0...14] smybol per slot
  int32_t **ptrs_phase_per_slot;
475 476 477
  /// \brief Total RE count after DMRS/PTRS RE's are extracted from respective symbol.
  /// - first index: ? [0...14] smybol per slot
  int16_t *ul_valid_re_per_slot;
478 479
  /// flag to verify if channel level computation is done
  uint8_t cl_done;
480 481
} NR_gNB_PUSCH;

482
/// Context data structure for RX/TX portion of slot processing
483 484 485 486 487
typedef struct {
  /// Component Carrier index
  uint8_t              CC_id;
  /// timestamp transmitted to HW
  openair0_timestamp timestamp_tx;
488 489 490 491
  /// slot to act upon for transmission
  int slot_tx;
  /// slot to act upon for reception
  int slot_rx;
492 493 494 495 496 497
  /// frame to act upon for transmission
  int frame_tx;
  /// frame to act upon for reception
  int frame_rx;
  /// \brief Instance count for RXn-TXnp4 processing thread.
  /// \internal This variable is protected by \ref mutex_rxtx.
Wang Tsu-Han's avatar
Wang Tsu-Han committed
498
  int instance_cnt;
499
  /// pthread structure for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
500
  pthread_t pthread;
501
  /// pthread attributes for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
502
  pthread_attr_t attr;
503
  /// condition variable for tx processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
504
  pthread_cond_t cond;
505
  /// mutex for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
506
  pthread_mutex_t mutex;
507 508
  /// scheduling parameters for RXn-TXnp4 thread
  struct sched_param sched_param_rxtx;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
509

510
  /// \internal This variable is protected by \ref mutex_RUs_tx.
Wang Tsu-Han's avatar
Wang Tsu-Han committed
511 512 513
  int instance_cnt_RUs;
  /// condition variable for tx processing thread
  pthread_cond_t cond_RUs;
514
  /// mutex for L1 RXTX processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
515
  pthread_mutex_t mutex_RUs;
516 517
  /// mutex for L1 TX FH synchronization
  pthread_mutex_t mutex_RUs_tx;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
518
} gNB_L1_rxtx_proc_t;
519 520


521
/// Context data structure for eNB slot processing
Wang Tsu-Han's avatar
Wang Tsu-Han committed
522
typedef struct gNB_L1_proc_t_s {
523 524 525 526 527 528 529 530
  /// Component Carrier index
  uint8_t              CC_id;
  /// thread index
  int thread_index;
  /// timestamp received from HW
  openair0_timestamp timestamp_rx;
  /// timestamp to send to "slave rru"
  openair0_timestamp timestamp_tx;
531 532 533 534
  /// slot to act upon for reception
  int slot_rx;
  /// slot to act upon for PRACH
  int slot_prach;
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
  /// frame to act upon for reception
  int frame_rx;
  /// frame to act upon for transmission
  int frame_tx;
  /// frame to act upon for PRACH
  int frame_prach;
  /// \internal This variable is protected by \ref mutex_td.
  int instance_cnt_td;
  /// \internal This variable is protected by \ref mutex_te.
  int instance_cnt_te;
  /// \internal This variable is protected by \ref mutex_prach.
  int instance_cnt_prach;

  // instance count for over-the-air gNB synchronization
  int instance_cnt_synch;
  /// \internal This variable is protected by \ref mutex_asynch_rxtx.
  int instance_cnt_asynch_rxtx;
  /// pthread structure for eNB single processing thread
  pthread_t pthread_single;
  /// pthread structure for asychronous RX/TX processing thread
  pthread_t pthread_asynch_rxtx;
556 557
  /// pthread structure for printing time meas
  pthread_t L1_stats_thread;
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
  /// flag to indicate first RX acquisition
  int first_rx;
  /// flag to indicate first TX transmission
  int first_tx;
  /// pthread attributes for single gNB processing thread
  pthread_attr_t attr_single;
  /// pthread attributes for prach processing thread
  pthread_attr_t attr_prach;
  /// pthread attributes for asynchronous RX thread
  pthread_attr_t attr_asynch_rxtx;
  /// scheduling parameters for parallel turbo-decoder thread
  struct sched_param sched_param_td;
  /// scheduling parameters for parallel turbo-encoder thread
  struct sched_param sched_param_te;
  /// scheduling parameters for single eNB thread
  struct sched_param sched_param_single;
  /// scheduling parameters for prach thread
  struct sched_param sched_param_prach;
  /// scheduling parameters for asynch_rxtx thread
  struct sched_param sched_param_asynch_rxtx;
  pthread_cond_t cond_prach;
  /// condition variable for asynch RX/TX thread
  pthread_cond_t cond_asynch_rxtx;
  /// mutex for parallel turbo-decoder thread
  pthread_mutex_t mutex_td;
  /// mutex for parallel turbo-encoder thread
  pthread_mutex_t mutex_te;
  /// mutex for PRACH thread
  pthread_mutex_t mutex_prach;
  /// mutex for asynch RX/TX thread
  pthread_mutex_t mutex_asynch_rxtx;
  /// mutex for RU access to eNB processing (PDSCH/PUSCH)
  pthread_mutex_t mutex_RU;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
591 592
  /// mutex for RU_tx access to eNB_tx processing (PDSCH/PUSCH)
  pthread_mutex_t mutex_RU_tx;
593 594 595 596 597
  /// mutex for RU access to eNB processing (PRACH)
  pthread_mutex_t mutex_RU_PRACH;
  /// mutex for RU access to eNB processing (PRACH BR)
  pthread_mutex_t mutex_RU_PRACH_br;
  /// mask for RUs serving eNB (PDSCH/PUSCH)
Wang Tsu-Han's avatar
Wang Tsu-Han committed
598
  int RU_mask, RU_mask_tx;
599 600 601
  /// mask for RUs serving eNB (PRACH)
  int RU_mask_prach;
  /// set of scheduling variables RXn-TXnp4 threads
Wang Tsu-Han's avatar
Wang Tsu-Han committed
602 603
  gNB_L1_rxtx_proc_t L1_proc, L1_proc_tx;
} gNB_L1_proc_t;
604 605 606 607 608 609



typedef struct {
  // common measurements
  //! estimated noise power (linear)
Guy De Souza's avatar
Guy De Souza committed
610
  unsigned int   n0_power[MAX_NUM_RU_PER_gNB];
611
  //! estimated noise power (dB)
Guy De Souza's avatar
Guy De Souza committed
612
  unsigned short n0_power_dB[MAX_NUM_RU_PER_gNB];
613 614 615 616 617 618
  //! total estimated noise power (linear)
  unsigned int   n0_power_tot;
  //! estimated avg noise power (dB)
  unsigned short n0_power_tot_dB;
  //! estimated avg noise power (dB)
  short n0_power_tot_dBm;
619 620 621 622
  //! estimated avg noise power per RB per RX ant (lin)
  unsigned short n0_subband_power[MAX_NUM_RU_PER_gNB][275];
  //! estimated avg noise power per RB per RX ant (dB)
  unsigned short n0_subband_power_dB[MAX_NUM_RU_PER_gNB][275];
623
  //! estimated avg noise power per RB (dB)
624
  short n0_subband_power_tot_dB[275];
625
  //! estimated avg noise power per RB (dBm)
626
  short n0_subband_power_tot_dBm[275];
627

628 629
  // gNB measurements (per user)
  //! estimated received spatial signal power (linear)
630
  unsigned int   rx_spatial_power[NUMBER_OF_NR_ULSCH_MAX][NB_ANTENNAS_TX][NB_ANTENNAS_RX];
631
  //! estimated received spatial signal power (dB)
632
  unsigned short rx_spatial_power_dB[NUMBER_OF_NR_ULSCH_MAX][NB_ANTENNAS_TX][NB_ANTENNAS_RX];
633
  //! estimated rssi (dBm)
634
  short          rx_rssi_dBm[NUMBER_OF_NR_ULSCH_MAX];
635
  //! estimated correlation (wideband linear) between spatial channels (computed in dlsch_demodulation)
636
  int            rx_correlation[NUMBER_OF_NR_ULSCH_MAX][2];
637
  //! estimated correlation (wideband dB) between spatial channels (computed in dlsch_demodulation)
638
  int            rx_correlation_dB[NUMBER_OF_NR_ULSCH_MAX][2];
639 640

  /// Wideband CQI (= SINR)
641
  int            wideband_cqi[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB];
642
  /// Wideband CQI in dB (= SINR dB)
643
  int            wideband_cqi_dB[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB];
644
  /// Wideband CQI (sum of all RX antennas, in dB)
645
  char           wideband_cqi_tot[NUMBER_OF_NR_ULSCH_MAX];
646
  /// Subband CQI per RX antenna and RB (= SINR)
647
  int            subband_cqi[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB][275];
648
  /// Total Subband CQI and RB (= SINR)
649
  int            subband_cqi_tot[NUMBER_OF_NR_ULSCH_MAX][275];
650
  /// Subband CQI in dB and RB (= SINR dB)
651
  int            subband_cqi_dB[NUMBER_OF_NR_ULSCH_MAX][MAX_NUM_RU_PER_gNB][275];
652
  /// Total Subband CQI and RB
653
  int            subband_cqi_tot_dB[NUMBER_OF_NR_ULSCH_MAX][275];
654 655 656 657
  /// PRACH background noise level
  int            prach_I0;
} PHY_MEASUREMENTS_gNB;

658 659
#define MAX_NUM_NR_RX_RACH_PDUS 4
#define MAX_NUM_NR_RX_PRACH_PREAMBLES 4
Francesco Mani's avatar
Francesco Mani committed
660 661 662
#define MAX_UL_PDUS_PER_SLOT 8
#define MAX_NUM_NR_SRS_PDUS 8
#define MAX_NUM_NR_UCI_PDUS 8
663

664 665 666 667 668 669
/// Top-level PHY Data Structure for gNB
typedef struct PHY_VARS_gNB_s {
  /// Module ID indicator for this instance
  module_id_t          Mod_id;
  uint8_t              CC_id;
  uint8_t              configured;
yilmazt's avatar
yilmazt committed
670
  gNB_L1_proc_t        proc;
671 672 673
  int                  single_thread_flag;
  int                  abstraction_flag;
  int                  num_RU;
Guy De Souza's avatar
Guy De Souza committed
674
  RU_t                 *RU_list[MAX_NUM_RU_PER_gNB];
675 676 677 678 679
  /// Ethernet parameters for northbound midhaul interface
  eth_params_t         eth_params_n;
  /// Ethernet parameters for fronthaul interface
  eth_params_t         eth_params;
  int                  rx_total_gain_dB;
yilmazt's avatar
yilmazt committed
680
  int                  (*nr_start_if)(struct RU_t_s *ru, struct PHY_VARS_gNB_s *gNB);
681
  uint8_t              local_flag;
682
  nfapi_nr_config_request_scf_t  gNB_config;
yilmazt's avatar
yilmazt committed
683
  NR_DL_FRAME_PARMS    frame_parms;
684
  PHY_MEASUREMENTS_gNB measurements;
yilmazt's avatar
yilmazt committed
685 686
  NR_IF_Module_t       *if_inst;
  NR_UL_IND_t          UL_INFO;
687
  pthread_mutex_t      UL_INFO_mutex;
688

689
  /// NFAPI RX ULSCH information
690
  nfapi_nr_rx_data_pdu_t  rx_pdu_list[MAX_UL_PDUS_PER_SLOT];
691
  /// NFAPI RX ULSCH CRC information
692 693 694 695 696
  nfapi_nr_crc_t crc_pdu_list[MAX_UL_PDUS_PER_SLOT];
  /// NFAPI SRS information
  nfapi_nr_srs_indication_pdu_t srs_pdu_list[MAX_NUM_NR_SRS_PDUS];
  /// NFAPI UCI information
  nfapi_nr_uci_t uci_pdu_list[MAX_NUM_NR_UCI_PDUS];
697
  /// NFAPI PRACH information
698 699 700
  nfapi_nr_prach_indication_pdu_t prach_pdu_indication_list[MAX_NUM_NR_RX_RACH_PDUS];
  /// NFAPI PRACH information
  nfapi_nr_prach_indication_preamble_t preamble_list[MAX_NUM_NR_RX_PRACH_PREAMBLES];
701

702 703
  //Sched_Rsp_t         Sched_INFO;
  nfapi_nr_ul_tti_request_t     UL_tti_req;
Francesco Mani's avatar
Francesco Mani committed
704
  nfapi_nr_uci_indication_t uci_indication;
705
  
706 707
  //  nfapi_nr_dl_tti_pdcch_pdu    *pdcch_pdu;
  //  nfapi_nr_ul_dci_request_pdus_t  *ul_dci_pdu;
708
  nfapi_nr_dl_tti_ssb_pdu      ssb_pdu;
Raymond Knopp's avatar
Raymond Knopp committed
709

710
  uint16_t num_pdsch_rnti[80];
yilmazt's avatar
yilmazt committed
711
  NR_gNB_PBCH         pbch;
712 713
  nr_cce_t           cce_list[MAX_DCI_CORESET][NR_MAX_PDCCH_AGG_LEVEL];
  NR_gNB_COMMON      common_vars;
714
  NR_gNB_PRACH       prach_vars;
715
  NR_gNB_PUSCH       *pusch_vars[NUMBER_OF_NR_ULSCH_MAX];
Francesco Mani's avatar
Francesco Mani committed
716
  NR_gNB_PUCCH_t     *pucch[NUMBER_OF_NR_PUCCH_MAX];
717 718
  NR_gNB_PDCCH_t     pdcch_pdu[NUMBER_OF_NR_PDCCH_MAX];
  NR_gNB_UL_PDCCH_t  ul_pdcch_pdu[NUMBER_OF_NR_PDCCH_MAX];
719
  NR_gNB_DLSCH_t     *dlsch[NUMBER_OF_NR_DLSCH_MAX][2];    // Nusers times two spatial streams
720
  NR_gNB_ULSCH_t     *ulsch[NUMBER_OF_NR_ULSCH_MAX][2];  // [Nusers times][2 codewords] 
721 722
  NR_gNB_DLSCH_t     *dlsch_SI,*dlsch_ra,*dlsch_p;
  NR_gNB_DLSCH_t     *dlsch_PCH;
723 724 725 726 727
  /// statistics for DLSCH measurement collection
  NR_gNB_SCH_STATS_t dlsch_stats[NUMBER_OF_NR_SCH_STATS_MAX];
  /// statistics for ULSCH measurement collection
  NR_gNB_SCH_STATS_t ulsch_stats[NUMBER_OF_NR_SCH_STATS_MAX];

728 729
  t_nrPolar_params    *uci_polarParams;

730 731 732
  uint8_t pbch_configured;
  char gNB_generate_rar;

733 734
  // PUCCH0 Look-up table for cyclic-shifts
  NR_gNB_PUCCH0_LUT_t pucch0_lut;
735 736 737 738 739 740 741
  /// NR synchronization sequences
  int16_t d_pss[NR_PSS_LENGTH];
  int16_t d_sss[NR_SSS_LENGTH];

  /// PBCH DMRS sequence
  uint32_t nr_gold_pbch_dmrs[2][64][NR_PBCH_DMRS_LENGTH_DWORD];

Guy De Souza's avatar
Guy De Souza committed
742 743 744
  /// PBCH interleaver
  uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS];

745
  /// PDCCH DMRS sequence
Guy De Souza's avatar
Guy De Souza committed
746
  uint32_t ***nr_gold_pdcch_dmrs;
747

ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
748
  /// PDSCH DMRS sequence
Guy De Souza's avatar
Guy De Souza committed
749
  uint32_t ****nr_gold_pdsch_dmrs;
750

751
  /// PUSCH DMRS
752
  uint32_t ****nr_gold_pusch_dmrs;
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
753

754 755 756 757
  // Mask of occupied RBs
  uint32_t rb_mask_ul[9];
  int ulmask_symb;

758 759 760
  /// CSI  RS sequence
  uint32_t ***nr_gold_csi_rs;

761
  /// Indicator set to 0 after first SR
762
  uint8_t first_sr[NUMBER_OF_NR_SR_MAX];
763

764 765 766
  /// PRACH root sequence
  uint32_t X_u[64][839];

767 768 769 770 771 772 773 774 775 776 777
  uint32_t max_peak_val;

  /// \brief sinr for all subcarriers of the current link (used only for abstraction).
  /// first index: ? [0..N_RB_DL*12[
  double *sinr_dB;

  /// N0 (used for abstraction)
  double N0;

  unsigned char first_run_I0_measurements;

yilmazt's avatar
yilmazt committed
778

779 780 781 782 783 784 785 786 787 788 789 790 791 792
  unsigned char    is_secondary_gNB; // primary by default
  unsigned char    is_init_sync;     /// Flag to tell if initial synchronization is performed. This affects how often the secondary eNB will listen to the PSS from the primary system.
  unsigned char    has_valid_precoder; /// Flag to tell if secondary eNB has channel estimates to create NULL-beams from, and this B/F vector is created.
  unsigned char    PgNB_id;          /// id of Primary eNB

  /// hold the precoder for NULL beam to the primary user
  int              **dl_precoder_SgNB[3];
  char             log2_maxp; /// holds the maximum channel/precoder coefficient

  /// if ==0 enables phy only test mode
  int mac_enabled;
  /// counter to average prach energh over first 100 prach opportunities
  int prach_energy_counter;

793
  int pucch0_thres;
794
  /*
795
  time_stats_t phy_proc;
796
  */
797 798 799
  time_stats_t phy_proc_tx;
  time_stats_t phy_proc_rx;
  time_stats_t rx_prach;
800
  /*
801
  time_stats_t ofdm_mod_stats;
802
  */
803 804 805
  time_stats_t dlsch_encoding_stats;
  time_stats_t dlsch_modulation_stats;
  time_stats_t dlsch_scrambling_stats;
806 807 808 809 810
  time_stats_t tinput;
  time_stats_t tprep;
  time_stats_t tparity;
  time_stats_t toutput;
  
811 812
  time_stats_t dlsch_rate_matching_stats;
  time_stats_t dlsch_interleaving_stats;
813
  time_stats_t dlsch_segmentation_stats;
814

815
  time_stats_t rx_pusch_stats;
816 817
  time_stats_t ulsch_decoding_stats;
  time_stats_t ulsch_rate_unmatching_stats;
818
  time_stats_t ulsch_ldpc_decoding_stats;
819
  time_stats_t ulsch_deinterleaving_stats;
820 821
  time_stats_t ulsch_unscrambling_stats;
  time_stats_t ulsch_channel_estimation_stats;
822
  time_stats_t ulsch_ptrs_processing_stats;
823 824
  time_stats_t ulsch_channel_compensation_stats;
  time_stats_t ulsch_rbs_extraction_stats;
825
  time_stats_t ulsch_mrc_stats;
826
  time_stats_t ulsch_llr_stats;
827

828 829 830
  /*
  time_stats_t rx_dft_stats;
  time_stats_t ulsch_freq_offset_estimation_stats;
831
  */
832
  notifiedFIFO_t *respDecode;
Sakthivel Velumani's avatar
Sakthivel Velumani committed
833 834 835
  notifiedFIFO_t *resp_L1;
  notifiedFIFO_t *resp_L1_tx;
  notifiedFIFO_t *resp_RU_tx;
836
  tpool_t *threadPool;
837
  int nbDecode;
838
  uint8_t pusch_proc_threads;
839

840 841
} PHY_VARS_gNB;

Sakthi's avatar
Sakthi committed
842 843 844
typedef struct LDPCDecode_s {
  PHY_VARS_gNB *gNB;
  NR_UL_gNB_HARQ_t *ulsch_harq;
845
  t_nrLDPC_dec_params decoderParms;
Sakthi's avatar
Sakthi committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
  NR_gNB_ULSCH_t *ulsch;
  short* ulsch_llr; 
  int ulsch_id;
  int harq_pid;
  int rv_index;
  int A;
  int E;
  int Kc;
  int Qm;
  int Kr_bytes;
  int nbSegments;
  int segment_r;
  int r_offset;
  int offset;
  int Tbslbrm;
  int decodeIterations;
} ldpcDecode_t;

struct ldpcReqId {
  uint16_t rnti;
  uint16_t frame;
  uint8_t  subframe;
  uint8_t  codeblock;
  uint16_t spare;
} __attribute__((packed));

union ldpcReqUnion {
  struct ldpcReqId s;
  uint64_t p;
};

877 878 879 880 881 882 883 884 885
typedef struct processingData_L1 {
  int frame_rx;
  int frame_tx;
  int slot_rx;
  int slot_tx;
  openair0_timestamp timestamp_tx;
  PHY_VARS_gNB *gNB;
} processingData_L1_t;

886
#endif