defs_gNB.h 24.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
#ifndef __PHY_DEFS_GNB__H__
#define __PHY_DEFS_GNB__H__

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

francescomani's avatar
francescomani committed
47
#define MAX_NUM_RU_PER_gNB 8
48 49 50 51 52 53 54
#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;
55

56

Guy De Souza's avatar
Guy De Souza committed
57
typedef struct {
58
  uint32_t pbch_a;
Hongzhi's avatar
Hongzhi committed
59 60 61
  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
62 63
} NR_gNB_PBCH;

64

65 66 67 68 69 70 71 72
typedef enum {
  NR_SCH_IDLE,
  NR_ACTIVE,
  NR_CBA_ACTIVE,
  NR_DISABLED
} NR_SCH_status_t;


73
typedef struct {
Guy De Souza's avatar
Guy De Souza committed
74
  /// Nfapi DLSCH PDU
Raymond Knopp's avatar
Raymond Knopp committed
75
  nfapi_nr_dl_tti_pdsch_pdu pdsch_pdu;
76 77 78 79 80
  /// pointer to pdu from MAC interface (this is "a" in 36.212)
  uint8_t *pdu;
  /// Pointer to the payload
  uint8_t *b;
  /// Pointers to transport block segments
81
  uint8_t **c;
82 83 84 85
  /// Frame where current HARQ round was sent
  uint32_t frame;
  /// Subframe where current HARQ round was sent
  uint32_t subframe;
86 87
  /// Interleaver outputs
  uint8_t *f;
88 89
  /// LDPC lifting size
  uint32_t Z;
90 91
  /// REs unavailable for DLSCH (overlapping with PTRS, CSIRS etc.)
  uint32_t unav_res;
92 93
} NR_DL_gNB_HARQ_t;

94 95 96 97 98
typedef struct {
  uint8_t active;
  nfapi_nr_dl_tti_csi_rs_pdu csirs_pdu;
} NR_gNB_CSIRS_t;

99
typedef struct {
100
  int dump_frame;
101
  int round_trials[8];
Raymond Knopp's avatar
Raymond Knopp committed
102 103
  int total_bytes_tx;
  int total_bytes_rx;
104 105
  int current_Qm;
  int current_RI;
106 107
  int power[MAX_ANT];
  int noise_power[MAX_ANT];
108
  int DTX;
109
  int sync_pos;
110
} NR_gNB_SCH_STATS_t;
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
typedef struct {
  int pucch0_sr_trials;
  int pucch0_sr_thres;
  int current_pucch0_sr_stat0;
  int current_pucch0_sr_stat1;
  int pucch0_positive_SR;
  int pucch01_trials;
  int pucch0_n00;
  int pucch0_n01;
  int pucch0_thres;
  int current_pucch0_stat0;
  int current_pucch0_stat1;
  int pucch01_DTX;
  int pucch02_trials;
  int pucch02_DTX;
  int pucch2_trials;
  int pucch2_DTX;
} NR_gNB_UCI_STATS_t;

131 132 133 134 135 136 137 138 139 140 141
typedef struct {
  int frame;
  uint16_t rnti;
  bool active;
  /// statistics for DLSCH measurement collection
  NR_gNB_SCH_STATS_t dlsch_stats;
  /// statistics for ULSCH measurement collection
  NR_gNB_SCH_STATS_t ulsch_stats;
  NR_gNB_UCI_STATS_t uci_stats;
} NR_gNB_PHY_STATS_t;

142
typedef struct {
143 144
  /// Pointers to variables related to DLSCH harq process
  NR_DL_gNB_HARQ_t harq_process;
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;
147 148 149 150 151 152
  /// Active flag for baseband transmitter processing
  uint8_t active;
  /// Number of soft channel bits
  uint32_t G;
} NR_gNB_DLSCH_t;

153 154 155 156
typedef struct {
  bool active;
  nfapi_nr_dl_tti_ssb_pdu ssb_pdu;
} NR_gNB_SSB_t;
157

158 159 160 161 162 163 164 165
typedef struct {
  int frame;
  int slot;
  nfapi_nr_prach_pdu_t pdu;  
} gNB_PRACH_list_t;

#define NUMBER_OF_NR_PRACH_MAX 8

166 167 168 169 170 171 172 173 174 175
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;
176
  gNB_PRACH_list_t list[NUMBER_OF_NR_PRACH_MAX];
177
} NR_gNB_PRACH;
178

179 180
typedef struct {
  uint8_t NumPRSResources;
181
  prs_config_t prs_cfg[NR_MAX_PRS_RESOURCES_PER_SET];
182 183
} NR_gNB_PRS;

184 185
typedef struct {
  /// Nfapi ULSCH PDU
186
  nfapi_nr_pusch_pdu_t ulsch_pdu;
187 188
  /// Index of current HARQ round for this DLSCH
  uint8_t round;
189
  bool new_rx;
190
  /////////////////////// ulsch decoding ///////////////////////
191 192 193
  /// flag used to clear d properly (together with d_to_be_cleared below)
  /// set to true in nr_fill_ulsch() when new_data_indicator is received
  bool harq_to_be_cleared;
194 195 196 197 198
  /// 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;
  /// Pointers to code blocks after code block segmentation and CRC attachment (38.212 V15.4.0 section 5.2.2)
199
  uint8_t **c;
200 201 202 203 204 205 206
  /// 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)
207
  int16_t **d;
208 209 210 211
  /// flag used to clear d properly (together with harq_to_be_cleared above)
  /// set to true in nr_ulsch_decoding() when harq_to_be_cleared is true
  /// when true, clear d in the next call to function nr_rate_matching_ldpc_rx()
  bool *d_to_be_cleared;
212 213 214 215
  /// LDPC lifting size (38.212 V15.4.0 table 5.3.2-1)
  uint32_t Z;
  /// 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;
216 217
  /// Number of segments processed so far
  uint32_t processedSegments;
218
  decode_abort_t abort_decode;
219 220 221
  /// Last index of LLR buffer that contains information.
  /// Used for computing LDPC decoder R
  int llrLen;
222 223
  //////////////////////////////////////////////////////////////
} NR_UL_gNB_HARQ_t;
224 225 226 227 228 229 230 231 232 233 234 235
static inline int lenWithCrc(int nbSeg, int len)
{
  if (nbSeg > 1)
    return (len + 24 + 24 * nbSeg) / nbSeg;
  return len + (len > NR_MAX_PDSCH_TBS ? 24 : 16);
}
static inline int crcType(int nbSeg, int len)
{
  if (nbSeg > 1)
    return CRC24_B;
  return len > NR_MAX_PDSCH_TBS ? CRC24_A : CRC16;
}
236

Robert Schmidt's avatar
Robert Schmidt committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
typedef struct {
  //! estimated rssi (dBm)
  int rx_rssi_dBm;
  //! estimated correlation (wideband linear) between spatial channels (computed in dlsch_demodulation)
  int rx_correlation[2];
  //! estimated correlation (wideband dB) between spatial channels (computed in dlsch_demodulation)
  int rx_correlation_dB[2];
  /// Wideband CQI (= SINR)
  int wideband_cqi[MAX_NUM_RU_PER_gNB];
  /// Wideband CQI in dB (= SINR dB)
  int wideband_cqi_dB[MAX_NUM_RU_PER_gNB];
  /// Wideband CQI (sum of all RX antennas, in dB)
  char wideband_cqi_tot;
  /// Subband CQI per RX antenna and RB (= SINR)
  int subband_cqi[MAX_NUM_RU_PER_gNB][275];
  /// Total Subband CQI and RB (= SINR)
  int subband_cqi_tot[275];
  /// Subband CQI in dB and RB (= SINR dB)
  int subband_cqi_dB[MAX_NUM_RU_PER_gNB][275];
  /// Total Subband CQI and RB
  int subband_cqi_tot_dB[275];
} ulsch_measurements_gNB;
259 260

typedef struct {
francescomani's avatar
francescomani committed
261 262
  uint32_t frame;
  uint32_t slot;
263
  uint32_t unav_res;
264
  /// Pointers to 16 HARQ processes for the ULSCH
265
  NR_UL_gNB_HARQ_t *harq_process;
266
  /// HARQ process mask, indicates which processes are currently active
267
  int harq_pid;
268 269 270 271 272
  /// Allocated RNTI for this ULSCH
  uint16_t rnti;
  /// Maximum number of LDPC iterations
  uint8_t max_ldpc_iterations;
  /// number of iterations used in last LDPC decoding
273 274 275 276 277
  uint8_t last_iteration_cnt;
  /// Status Flag indicating for this ULSCH
  bool active;
  /// Flag to indicate that the UL configuration has been handled. Used to remove a stale ULSCH when frame wraps around
  uint8_t handled;
278
  delay_t delay;
Robert Schmidt's avatar
Robert Schmidt committed
279
  ulsch_measurements_gNB ulsch_measurements;
280 281
} NR_gNB_ULSCH_t;

Francesco Mani's avatar
Francesco Mani committed
282 283 284 285 286 287 288 289 290
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;
291

292 293 294 295 296 297 298 299 300 301
typedef struct {
  uint8_t active;
  /// Frame where current SRS pdu was received
  uint32_t frame;
  /// Slot where current SRS pdu was received
  uint32_t slot;
  /// ULSCH PDU
  nfapi_nr_srs_pdu_t srs_pdu;
} NR_gNB_SRS_t;

302 303 304 305
typedef struct {
  /// \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[
306
  c16_t **rxdataF;
307 308 309 310
  /// \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.
311
  /// - third index: sample [0..samples_per_frame_woCP]
312
  c16_t **txdataF;
313 314 315 316
  /// \brief Anaglogue beam ID for each OFDM symbol (used when beamforming not done in RU)
  /// - first index: antenna port
  /// - second index: beam_id [0.. symbols_per_frame[
  uint8_t **beam_id;  
317 318
  int32_t *debugBuff;
  int32_t debugBuff_sample_offset;
319 320 321
} NR_gNB_COMMON;


322 323 324 325 326 327 328 329
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 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[
330
  int32_t **ul_ch_estimates_time;
331 332 333
  /// \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[
334 335 336 337 338
  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;
339 340 341 342
  /// \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;
343 344
  /// \f$\log_2(\max|H_i|^2)\f$
  int16_t log2_maxh;
345
  /// measured RX power based on DRS
346
  int ulsch_power[8];
347 348
  /// total signal over antennas
  int ulsch_power_tot;
349 350
  /// measured RX noise power
  int ulsch_noise_power[8];
351
  /// total noise over antennas
Jaroslava Fiedlerova's avatar
Jaroslava Fiedlerova committed
352
  uint32_t ulsch_noise_power_tot;
353 354 355
  /// \brief llr values.
  /// - first index: ? [0..1179743] (hard coded)
  int16_t *llr;
356 357 358 359
  /// \brief llr values per layer.
  /// - first index: ? [0..3] (hard coded)
  /// - first index: ? [0..1179743] (hard coded)
  int16_t **llr_layers;
360
  /// DMRS symbol index, to be updated every DMRS symbol within a slot.
361
  uint8_t dmrs_symbol;
362 363 364 365 366
  // 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
367
  int32_t ptrs_re_per_slot;
368 369 370 371
  /// \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;
372 373 374
  /// \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;
375 376
  /// \brief offset for llr corresponding to each symbol
  int llr_offset[14];
377 378
  /// flag to indicate DTX on reception
  int DTX;
379 380
} NR_gNB_PUSCH;

381
/// Context data structure for RX/TX portion of slot processing
382 383 384 385 386
typedef struct {
  /// Component Carrier index
  uint8_t              CC_id;
  /// timestamp transmitted to HW
  openair0_timestamp timestamp_tx;
387 388 389 390
  /// slot to act upon for transmission
  int slot_tx;
  /// slot to act upon for reception
  int slot_rx;
391 392 393 394 395 396
  /// 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
397
  int instance_cnt;
398
  /// pthread structure for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
399
  pthread_t pthread;
400
  /// pthread attributes for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
401
  pthread_attr_t attr;
402
  /// condition variable for tx processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
403
  pthread_cond_t cond;
404
  /// mutex for RXn-TXnp4 processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
405
  pthread_mutex_t mutex;
406 407
  /// scheduling parameters for RXn-TXnp4 thread
  struct sched_param sched_param_rxtx;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
408

409
  /// \internal This variable is protected by \ref mutex_RUs_tx.
Wang Tsu-Han's avatar
Wang Tsu-Han committed
410 411 412
  int instance_cnt_RUs;
  /// condition variable for tx processing thread
  pthread_cond_t cond_RUs;
413
  /// mutex for L1 RXTX processing thread
Wang Tsu-Han's avatar
Wang Tsu-Han committed
414
  pthread_mutex_t mutex_RUs;
415 416
  /// mutex for L1 TX FH synchronization
  pthread_mutex_t mutex_RUs_tx;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
417
} gNB_L1_rxtx_proc_t;
418 419


420
/// Context data structure for eNB slot processing
Wang Tsu-Han's avatar
Wang Tsu-Han committed
421
typedef struct gNB_L1_proc_t_s {
422 423 424 425 426 427 428 429
  /// 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;
430 431 432 433
  /// slot to act upon for reception
  int slot_rx;
  /// slot to act upon for PRACH
  int slot_prach;
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
  /// 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;
  /// \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;
452
  /// pthread structure for dumping L1 stats
453
  pthread_t L1_stats_thread;
454 455
  /// pthread structure for printing time meas
  pthread_t process_stats_thread;
456 457
  /// pthread structure for reordering L1 tx thread messages
  pthread_t pthread_tx_reorder;
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
  /// 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
491 492
  /// mutex for RU_tx access to eNB_tx processing (PDSCH/PUSCH)
  pthread_mutex_t mutex_RU_tx;
493 494 495 496 497
  /// 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
498
  int RU_mask, RU_mask_tx;
499 500 501
  /// 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
502 503
  gNB_L1_rxtx_proc_t L1_proc, L1_proc_tx;
} gNB_L1_proc_t;
504 505 506 507

typedef struct {
  // common measurements
  //! estimated noise power (linear)
Guy De Souza's avatar
Guy De Souza committed
508
  unsigned int   n0_power[MAX_NUM_RU_PER_gNB];
509
  //! estimated noise power (dB)
510
  unsigned int n0_power_dB[MAX_NUM_RU_PER_gNB];
511 512 513
  //! total estimated noise power (linear)
  unsigned int   n0_power_tot;
  //! estimated avg noise power (dB)
514
  unsigned int n0_power_tot_dB;
515
  //! estimated avg noise power per RB per RX ant (lin)
516
  fourDimArray_t *n0_subband_power;
517
  //! estimated avg noise power per RB per RX ant (dB)
518
  fourDimArray_t *n0_subband_power_dB;
519
  //! estimated avg subband noise power (dB)
520
  unsigned int n0_subband_power_avg_dB;
521
  //! estimated avg subband noise power per antenna (dB)
522
  unsigned int n0_subband_power_avg_perANT_dB[MAX_ANT];
523
  //! estimated avg noise power per RB (dB)
524
  int n0_subband_power_tot_dB[275];
525
  //! estimated avg noise power per RB (dBm)
526
  int n0_subband_power_tot_dBm[275];
527 528
  /// PRACH background noise level
  int            prach_I0;
529

530 531
} PHY_MEASUREMENTS_gNB;

francescomani's avatar
francescomani committed
532

533
#define MAX_NUM_NR_RX_RACH_PDUS 4
Francesco Mani's avatar
Francesco Mani committed
534 535
#define MAX_UL_PDUS_PER_SLOT 8
#define MAX_NUM_NR_SRS_PDUS 8
536 537 538 539
// the current RRC resource allocation is that each UE gets its
// "own" PUCCH resource (for F0) in a dedicated PRB in each slot
// therefore, we can have up to "number of UE" UCI PDUs
#define MAX_NUM_NR_UCI_PDUS MAX_MOBILES_PER_GNB
540

541 542 543 544 545 546
/// 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
547
  gNB_L1_proc_t        proc;
548 549 550
  int                  single_thread_flag;
  int                  abstraction_flag;
  int                  num_RU;
Guy De Souza's avatar
Guy De Souza committed
551
  RU_t                 *RU_list[MAX_NUM_RU_PER_gNB];
552 553 554 555 556
  /// 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
557
  int                  (*nr_start_if)(struct RU_t_s *ru, struct PHY_VARS_gNB_s *gNB);
558
  uint8_t              local_flag;
559
  nfapi_nr_config_request_scf_t  gNB_config;
yilmazt's avatar
yilmazt committed
560
  NR_DL_FRAME_PARMS    frame_parms;
561
  PHY_MEASUREMENTS_gNB measurements;
yilmazt's avatar
yilmazt committed
562 563
  NR_IF_Module_t       *if_inst;
  NR_UL_IND_t          UL_INFO;
564

565
  /// NFAPI RX ULSCH information
566
  nfapi_nr_rx_data_pdu_t  rx_pdu_list[MAX_UL_PDUS_PER_SLOT];
567
  /// NFAPI RX ULSCH CRC information
568 569 570 571 572
  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];
573
  /// NFAPI PRACH information
574
  nfapi_nr_prach_indication_pdu_t prach_pdu_indication_list[MAX_NUM_NR_RX_RACH_PDUS];
575

576
  nfapi_nr_ul_tti_request_t     UL_tti_req;
Francesco Mani's avatar
Francesco Mani committed
577
  nfapi_nr_uci_indication_t uci_indication;
578
  
579
  int max_nb_pucch;
580
  int max_nb_srs;
581 582 583
  int max_nb_pdsch;
  int max_nb_pusch;

584
  NR_gNB_PBCH        pbch;
585
  NR_gNB_COMMON      common_vars;
586
  NR_gNB_PRACH       prach_vars;
587
  NR_gNB_PRS         prs_vars;
francescomani's avatar
francescomani committed
588 589 590 591
  NR_gNB_PUSCH *pusch_vars;
  NR_gNB_PUCCH_t *pucch;
  NR_gNB_SRS_t *srs;
  NR_gNB_ULSCH_t *ulsch;
592
  NR_gNB_PHY_STATS_t phy_stats[MAX_MOBILES_PER_GNB];
593
  t_nrPolar_params    **polarParams;
594

rmagueta's avatar
rmagueta committed
595
  /// SRS variables
596
  nr_srs_info_t **nr_srs_info;
597

598 599 600
  /// CSI variables
  nr_csi_info_t *nr_csi_info;

601 602
  // reference amplitude for TX
  int16_t TX_AMP;
603 604 605 606

  // flag to activate 3GPP phase symbolwise rotation
  bool phase_comp;

607 608
  // PUCCH0 Look-up table for cyclic-shifts
  NR_gNB_PUCCH0_LUT_t pucch0_lut;
609 610 611 612

  /// 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
613 614 615
  /// PBCH interleaver
  uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS];

616
  /// PDCCH DMRS sequence
Guy De Souza's avatar
Guy De Souza committed
617
  uint32_t ***nr_gold_pdcch_dmrs;
618

ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
619
  /// PDSCH DMRS sequence
Guy De Souza's avatar
Guy De Souza committed
620
  uint32_t ****nr_gold_pdsch_dmrs;
621

622
  /// PUSCH DMRS
623
  uint32_t ****nr_gold_pusch_dmrs;
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
624

Raymond Knopp's avatar
Raymond Knopp committed
625 626
  // Mask of occupied RBs, per symbol and PRB
  uint32_t rb_mask_ul[14][9];
627

628
  /// PRS sequence
629
  uint32_t ****nr_gold_prs;
630

631
  /// PRACH root sequence
laurent's avatar
laurent committed
632
  c16_t X_u[64][839];
633

634 635
  /// OFDM symbol offset divisor for UL
  uint32_t ofdm_offset_divisor;
636

637
  int ldpc_offload_flag;
yilmazt's avatar
yilmazt committed
638

639 640 641 642 643
  int max_ldpc_iterations;
  /// indicate the channel estimation technique in time domain
  int chest_time;
  /// indicate the channel estimation technique in freq domain
  int chest_freq;
Sakthivel Velumani's avatar
Sakthivel Velumani committed
644

645 646 647
  /// counter to average prach energh over first 100 prach opportunities
  int prach_energy_counter;

648 649
  int pdcch_gold_init;
  int pdsch_gold_init[2];
650
  int pusch_gold_init[2];
651

652 653 654
  int ap_N1;
  int ap_N2;
  int ap_XP;
655

656
  int pucch0_thres;
657
  int pusch_thres;
658
  int prach_thres;
luis_pereira87's avatar
luis_pereira87 committed
659
  int srs_thres;
660
  uint64_t bad_pucch;
661 662
  int num_ulprbbl;
  int ulprbbl[275];
663
  /*
664
  time_stats_t phy_proc;
665
  */
666
  time_stats_t phy_proc_tx;
667 668
  time_stats_t phy_proc_rx;
  time_stats_t rx_prach;
669
  /*
670
  time_stats_t ofdm_mod_stats;
671
  */
672 673 674
  time_stats_t dlsch_encoding_stats;
  time_stats_t dlsch_modulation_stats;
  time_stats_t dlsch_scrambling_stats;
675 676
  time_stats_t dlsch_resource_mapping_stats;
  time_stats_t dlsch_precoding_stats;
677 678 679 680 681
  time_stats_t tinput;
  time_stats_t tprep;
  time_stats_t tparity;
  time_stats_t toutput;
  
682 683
  time_stats_t dlsch_rate_matching_stats;
  time_stats_t dlsch_interleaving_stats;
684
  time_stats_t dlsch_segmentation_stats;
685

686
  time_stats_t rx_pusch_stats;
687 688
  time_stats_t rx_pusch_init_stats;
  time_stats_t rx_pusch_symbol_processing_stats;
689
  time_stats_t ul_indication_stats;
690
  time_stats_t slot_indication_stats;
691
  time_stats_t schedule_response_stats;
692
  time_stats_t ulsch_decoding_stats;
693
  time_stats_t ulsch_ldpc_decoding_stats;
694
  time_stats_t ulsch_deinterleaving_stats;
695
  time_stats_t ulsch_channel_estimation_stats;
696
  time_stats_t ulsch_llr_stats;
697 698 699 700 701 702 703 704
  time_stats_t rx_srs_stats;
  time_stats_t generate_srs_stats;
  time_stats_t get_srs_signal_stats;
  time_stats_t srs_channel_estimation_stats;
  time_stats_t srs_timing_advance_stats;
  time_stats_t srs_report_tlv_stats;
  time_stats_t srs_beam_report_stats;
  time_stats_t srs_iq_matrix_stats;
705

706 707 708
  /*
  time_stats_t rx_dft_stats;
  time_stats_t ulsch_freq_offset_estimation_stats;
709
  */
710
  notifiedFIFO_t respPuschSymb;
711 712 713 714 715
  notifiedFIFO_t respDecode;
  notifiedFIFO_t resp_L1;
  notifiedFIFO_t L1_tx_free;
  notifiedFIFO_t L1_tx_filled;
  notifiedFIFO_t L1_tx_out;
716
  notifiedFIFO_t L1_rx_out;
717 718
  notifiedFIFO_t resp_RU_tx;
  tpool_t threadPool;
719
  int num_pusch_symbols_per_thread;
720 721 722 723 724
  pthread_t L1_rx_thread;
  int L1_rx_thread_core;
  pthread_t L1_tx_thread;
  int L1_tx_thread_core;
  struct processingData_L1tx *msgDataTx;
725
  void *scopeData;
726 727
  /// structure for analyzing high-level RT measurements
  rt_L1_profiling_t rt_L1_profiling; 
728 729
} PHY_VARS_gNB;

730 731 732 733 734 735 736 737 738 739 740 741
struct puschSymbolReqId {
  uint16_t ulsch_id;
  uint16_t frame;
  uint8_t  slot;
  uint16_t spare;
} __attribute__((packed));

union puschSymbolReqUnion {
  struct puschSymbolReqId s;
  uint64_t p;
};

Sakthi's avatar
Sakthi committed
742 743 744
typedef struct LDPCDecode_s {
  PHY_VARS_gNB *gNB;
  NR_UL_gNB_HARQ_t *ulsch_harq;
745
  t_nrLDPC_dec_params decoderParms;
Sakthi's avatar
Sakthi committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
  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 decodeIterations;
761
  uint32_t tbslbrm;
Sakthi's avatar
Sakthi committed
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
} 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;
};

777 778 779 780 781 782 783
typedef struct processingData_L1 {
  int frame_rx;
  int slot_rx;
  openair0_timestamp timestamp_tx;
  PHY_VARS_gNB *gNB;
} processingData_L1_t;

784 785
typedef enum {
  FILLED,
786
  FILLING,
787 788
  NOT_FILLED
} msgStatus_t;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
789

790
typedef struct processingData_L1tx {
Sakthivel Velumani's avatar
Sakthivel Velumani committed
791 792
  int frame;
  int slot;
793 794
  int frame_rx;
  int slot_rx;
795 796
  openair0_timestamp timestamp_tx;
  PHY_VARS_gNB *gNB;
797 798
  nfapi_nr_dl_tti_pdcch_pdu pdcch_pdu[NFAPI_NR_MAX_NB_CORESETS];
  nfapi_nr_ul_dci_request_pdus_t ul_pdcch_pdu[NFAPI_NR_MAX_NB_CORESETS];
799
  NR_gNB_CSIRS_t csirs_pdu[NR_SYMBOLS_PER_SLOT];
francescomani's avatar
francescomani committed
800
  NR_gNB_DLSCH_t **dlsch;
801 802
  NR_gNB_SSB_t ssb[64];
  uint16_t num_pdsch_slot;
803 804
  int num_dl_pdcch;
  int num_ul_pdcch;
805 806
  /* a reference to the sched_response, to release it when not needed anymore */
  int sched_response_id;
807
} processingData_L1tx_t;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
808

809 810 811 812 813
typedef struct processingData_L1rx {
  int frame_rx;
  int slot_rx;
  PHY_VARS_gNB *gNB;
} processingData_L1rx_t;
814
#endif