defs_nr_common.h 11.7 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 32 33 34 35
/*
 * 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_nr_common.h
 \brief Top-level defines and structure definitions
 \author Guy De Souza
 \date 2018
 \version 0.1
 \company Eurecom
 \email: desouza@eurecom.fr
 \note
 \warning
*/

#ifndef __PHY_DEFS_NR_COMMON__H__
#define __PHY_DEFS_NR_COMMON__H__

Jacques's avatar
Jacques committed
36
#include "PHY/impl_defs_top.h"
37
#include "defs_common.h"
Raymond Knopp's avatar
Raymond Knopp committed
38
#include "nfapi_nr_interface_scf.h"
39
#include "impl_defs_nr.h"
Guy De Souza's avatar
Guy De Souza committed
40
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
41 42

#define nr_subframe_t lte_subframe_t
43
#define nr_slot_t lte_subframe_t
44 45 46

#define MAX_NUM_SUBCARRIER_SPACING 5

47 48
#define NR_MAX_NB_RB 275

49
#define NR_NB_SC_PER_RB 12
50
#define NR_NB_REG_PER_CCE 6
51

52 53 54 55 56
#define NR_SYMBOLS_PER_SLOT 14

#define ONE_OVER_SQRT2_Q15 23170
#define ONE_OVER_TWO_Q15 16384

57
#define NR_MOD_TABLE_SIZE_SHORT 686
Guy De Souza's avatar
Guy De Souza committed
58 59
#define NR_MOD_TABLE_BPSK_OFFSET 1
#define NR_MOD_TABLE_QPSK_OFFSET 3
60 61 62
#define NR_MOD_TABLE_QAM16_OFFSET 7
#define NR_MOD_TABLE_QAM64_OFFSET 23
#define NR_MOD_TABLE_QAM256_OFFSET 87
63

Guy De Souza's avatar
Guy De Souza committed
64 65 66
#define NR_PSS_LENGTH 127
#define NR_SSS_LENGTH 127

Guy De Souza's avatar
Guy De Souza committed
67
#define NR_PBCH_DMRS_LENGTH 144 // in mod symbols
68
#define NR_PBCH_DMRS_LENGTH_DWORD 10 // ceil(2(QPSK)*NR_PBCH_DMRS_LENGTH/32)
Guy De Souza's avatar
Guy De Souza committed
69

Guy De Souza's avatar
Guy De Souza committed
70 71 72 73 74 75
/*These max values are for the gold sequences which are generated at init for the
 * full carrier bandwidth*/
#define NR_MAX_PDCCH_DMRS_INIT_LENGTH ((NR_MAX_NB_RB<<1)*3) // 3 symbols *2(QPSK)
#define NR_MAX_PDCCH_DMRS_INIT_LENGTH_DWORD 52 // ceil(NR_MAX_PDCCH_DMRS_LENGTH/32)
/*used for the resource mapping*/
#define NR_MAX_PDCCH_DMRS_LENGTH 576 // 16(L)*2(QPSK)*3(3 DMRS symbs per REG)*6(REG per CCE)
76

77
#define NR_MAX_PDSCH_DMRS_LENGTH 3300      //275*6(k)*2(QPSK real+imag) 
Guy De Souza's avatar
Guy De Souza committed
78
#define NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD 104  // ceil(NR_MAX_PDSCH_DMRS_LENGTH/32)
ISIP CS/NCTU's avatar
ISIP CS/NCTU committed
79

80 81
#define NR_MAX_CSI_RS_LENGTH 4400 //275*8(max allocation per RB)*2(QPSK)
#define NR_MAX_CSI_RS_INIT_LENGTH_DWORD 138  // ceil(NR_MAX_CSI_RS_LENGTH/32)
82

83 84 85
#define NR_MAX_PUSCH_DMRS_LENGTH NR_MAX_PDSCH_DMRS_LENGTH 
#define NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD NR_MAX_PDSCH_DMRS_INIT_LENGTH_DWORD

86
#define NR_MAX_DCI_PAYLOAD_SIZE 64
Guy De Souza's avatar
Guy De Souza committed
87
#define NR_MAX_DCI_SIZE 1728 //16(L)*2(QPSK)*9(12 RE per REG - 3(DMRS))*6(REG per CCE)
Guy De Souza's avatar
Guy De Souza committed
88
#define NR_MAX_DCI_SIZE_DWORD 54 // ceil(NR_MAX_DCI_SIZE/32)
Guy De Souza's avatar
Guy De Souza committed
89

90 91
#define NR_MAX_NUM_BWP 4

92
#define NR_MAX_PDCCH_AGG_LEVEL 16 // 3GPP TS 38.211 V15.8 Section 7.3.2 Table 7.3.2.1-1: Supported PDCCH aggregation levels
93
#define NR_MAX_CSET_DURATION 3
94

Guy De Souza's avatar
Guy De Souza committed
95
#define NR_MAX_NB_RBG 18
Khalid Ahmed's avatar
Khalid Ahmed committed
96
#define NR_MAX_NB_LAYERS 8 // SU-MIMO (3GPP TS 38.211 V15.4.0 section 7.3.1.3)
Guy De Souza's avatar
Guy De Souza committed
97
#define NR_MAX_NB_CODEWORDS 2
98
#define NR_MAX_NB_HARQ_PROCESSES 16
Khalid Ahmed's avatar
Khalid Ahmed committed
99
#define NR_MAX_PDSCH_ENCODED_LENGTH NR_MAX_NB_RB*NR_SYMBOLS_PER_SLOT*NR_NB_SC_PER_RB*8*NR_MAX_NB_LAYERS // 8 is the maximum modulation order (it was 950984 before !!) 
100
#define NR_MAX_PUSCH_ENCODED_LENGTH NR_MAX_PDSCH_ENCODED_LENGTH
101
#define NR_MAX_PDSCH_TBS 3824
102
#define NR_MAX_SIB_LENGTH 2976 // 3GPP TS 38.331 section 5.2.1 - The physical layer imposes a limit to the maximum size a SIB can take. The maximum SIB1 or SI message size is 2976 bits.
Guy De Souza's avatar
Guy De Souza committed
103

104
#define MAX_NUM_NR_DLSCH_SEGMENTS 34
105 106 107 108 109
#define MAX_NR_DLSCH_PAYLOAD_BYTES (MAX_NUM_NR_DLSCH_SEGMENTS*1056)

#define MAX_NUM_NR_ULSCH_SEGMENTS MAX_NUM_NR_DLSCH_SEGMENTS
#define MAX_NR_ULSCH_PAYLOAD_BYTES (MAX_NUM_NR_ULSCH_SEGMENTS*1056)

110
#define MAX_NUM_NR_CHANNEL_BITS (14*273*12*8)  // 14 symbols, 273 RB
111 112
#define MAX_NUM_NR_RE (14*273*12)

113 114 115
extern const uint8_t nr_rv_round_map[4]; 
extern const uint8_t nr_rv_round_map_ue[4]; 

116 117 118 119 120 121 122 123
typedef enum {
  NR_MU_0=0,
  NR_MU_1,
  NR_MU_2,
  NR_MU_3,
  NR_MU_4,
} nr_numerology_index_e;

124 125 126 127 128 129 130
typedef enum {
  kHz15=0,
  kHz30,
  kHz60,
  kHz120,
  kHz240
} nr_scs_e;
131 132 133 134 135 136 137 138 139

typedef enum{
  nr_ssb_type_A = 0,
  nr_ssb_type_B,
  nr_ssb_type_C,
  nr_ssb_type_D,
  nr_ssb_type_E
} nr_ssb_type_e;

Guy De Souza's avatar
Guy De Souza committed
140 141 142 143 144
typedef enum {
  nr_FR1 = 0,
  nr_FR2
} nr_frequency_range_e;

Guy De Souza's avatar
Guy De Souza committed
145
typedef enum {
146 147 148 149 150
  MOD_BPSK=0,
  MOD_QPSK,
  MOD_QAM16,
  MOD_QAM64,
  MOD_QAM256
Guy De Souza's avatar
Guy De Souza committed
151 152
}nr_mod_t;

cig's avatar
cig committed
153 154 155 156 157
typedef enum {
  RA_2STEP = 0,
  RA_4STEP
} nr_ra_type_e;

Guy De Souza's avatar
Guy De Souza committed
158 159 160 161 162 163 164 165 166 167 168
typedef struct {
  /// Size of first RBG
  uint8_t start_size;
  /// Nominal size
  uint8_t P;
  /// Size of last RBG
  uint8_t end_size;
  /// Number of RBG
  uint8_t N_RBG;
}nr_rbg_parms_t;

Guy De Souza's avatar
Guy De Souza committed
169 170 171 172 173 174 175 176 177 178 179
typedef struct {
  /// Size of first PRG
  uint8_t start_size;
  /// Nominal size
  uint8_t P_prime;
  /// Size of last PRG
  uint8_t end_size;
  /// Number of PRG
  uint8_t N_PRG;
} nr_prg_parms_t;

180
typedef struct NR_BWP_PARMS {
Guy De Souza's avatar
Guy De Souza committed
181 182 183 184 185
  /// BWP ID
  uint8_t bwp_id;
  /// Subcarrier spacing
  nr_scs_e scs;
  /// Freq domain location -- 1st CRB index
186 187 188
  uint8_t location;
  /// Bandwidth in PRB
  uint16_t N_RB;
Guy De Souza's avatar
Guy De Souza committed
189 190
  /// Cyclic prefix
  uint8_t cyclic_prefix;
Guy De Souza's avatar
Guy De Souza committed
191 192
  /// RBG params
  nr_rbg_parms_t rbg_parms;
Guy De Souza's avatar
Guy De Souza committed
193 194
  /// PRG params
  nr_prg_parms_t prg_parms;
195 196
} NR_BWP_PARMS;

197 198
typedef struct {
  uint8_t reg_idx;
Guy De Souza's avatar
Guy De Souza committed
199
  uint16_t start_sc_idx;
200 201 202 203 204 205 206 207
  uint8_t symb_idx;
} nr_reg_t;

typedef struct {
  uint8_t cce_idx;
  nr_reg_t reg_list[NR_NB_REG_PER_CCE];
} nr_cce_t;

208
typedef struct {
cig's avatar
cig committed
209 210
  /// PRACH format retrieved from prach_ConfigIndex
  uint16_t prach_format;
211 212
  /// Preamble index for PRACH (0-63)
  uint8_t ra_PreambleIndex;
213 214 215 216 217 218
  /// Preamble Tx Counter
  uint8_t RA_PREAMBLE_TRANSMISSION_COUNTER;
  /// Preamble Power Ramping Counter
  uint8_t RA_PREAMBLE_POWER_RAMPING_COUNTER;
  /// 2-step RA power offset
  int POWER_OFFSET_2STEP_RA;
cig's avatar
cig committed
219 220
  /// Target received power at gNB. Baseline is range -202..-60 dBm. Depends on delta preamble, power ramping counter and step.
  int ra_PREAMBLE_RECEIVED_TARGET_POWER;
221 222 223 224 225 226 227 228
  /// PRACH index for TDD (0 ... 6) depending on TDD configuration and prachConfigIndex
  uint8_t ra_TDD_map_index;
  /// RA Preamble Power Ramping Step in dB
  uint32_t RA_PREAMBLE_POWER_RAMPING_STEP;
  ///
  uint8_t RA_PREAMBLE_BACKOFF;
  ///
  uint8_t RA_SCALING_FACTOR_BI;
cig's avatar
cig committed
229
  /// Indicating whether it is 2-step or 4-step RA
230
  nr_ra_type_e RA_TYPE;
cig's avatar
cig committed
231 232
  /// UE configured maximum output power
  int RA_PCMAX;
233 234 235 236
  /// Corresponding RA-RNTI for UL-grant
  uint16_t ra_RNTI;
  /// Pointer to Msg3 payload for UL-grant
  uint8_t *Msg3;
237
  /// Frame of last completed synch
238
  uint16_t sync_frame;
239 240
  /// Flag to indicate that prach is ready to start: it is enabled with an initial delay after the sync
  uint8_t init_msg1;
241 242
} NR_PRACH_RESOURCES_t;

243 244 245
typedef struct NR_DL_FRAME_PARMS NR_DL_FRAME_PARMS;

typedef uint32_t (*get_samples_per_slot_t)(int slot, NR_DL_FRAME_PARMS* fp);
Rakesh's avatar
Rakesh committed
246
typedef uint32_t (*get_slot_from_timestamp_t)(openair0_timestamp timestamp_rx, NR_DL_FRAME_PARMS* fp);
247

248
typedef uint32_t (*get_samples_slot_timestamp_t)(int slot, NR_DL_FRAME_PARMS* fp, uint8_t sl_ahead);
249 250

struct NR_DL_FRAME_PARMS {
Guy De Souza's avatar
Guy De Souza committed
251 252
  /// frequency range
  nr_frequency_range_e freq_range;
253 254
  //  /// Placeholder to replace overlapping fields below
  //  nfapi_nr_rf_config_t rf_config;
Raymond Knopp's avatar
Raymond Knopp committed
255
  /// Placeholder to replace SSB overlapping fields below
256
  //  nfapi_nr_sch_config_t sch_config;
257
  /// Number of resource blocks (RB) in DL
Raymond Knopp's avatar
Raymond Knopp committed
258
  int N_RB_DL;
259
  /// Number of resource blocks (RB) in UL
Raymond Knopp's avatar
Raymond Knopp committed
260
  int N_RB_UL;
261 262 263 264
  ///  total Number of Resource Block Groups: this is ceil(N_PRB/P)
  uint8_t N_RBG;
  /// Total Number of Resource Block Groups SubSets: this is P
  uint8_t N_RBGS;
265 266
  /// NR Band
  uint16_t nr_band;
267
  /// DL carrier frequency
268
  uint64_t dl_CarrierFreq;
269
  /// UL carrier frequency
270
  uint64_t ul_CarrierFreq;
271 272 273 274 275
  /// TX attenuation
  uint32_t att_tx;
  /// RX attenuation
  uint32_t att_rx;
  ///  total Number of Resource Block Groups: this is ceil(N_PRB/P)
276 277
  /// Frame type (0 FDD, 1 TDD)
  lte_frame_type_t frame_type;
278
  uint8_t tdd_config;
279 280
  /// Cell ID
  uint16_t Nid_cell;
281
  /// subcarrier spacing (15,30,60,120)
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
  uint32_t subcarrier_spacing;
  /// 3/4 sampling
  uint8_t threequarter_fs;
  /// Size of FFT
  uint16_t ofdm_symbol_size;
  /// Number of prefix samples in all but first symbol of slot
  uint16_t nb_prefix_samples;
  /// Number of prefix samples in first symbol of slot
  uint16_t nb_prefix_samples0;
  /// Carrier offset in FFT buffer for first RE in PRB0
  uint16_t first_carrier_offset;
  /// Number of OFDM/SC-FDMA symbols in one slot
  uint16_t symbols_per_slot;
  /// Number of slots per subframe
  uint16_t slots_per_subframe;
297
  /// Number of slots per frame
298
  uint16_t slots_per_frame;
299 300
  /// Number of samples in a subframe
  uint32_t samples_per_subframe;
301 302
  /// Number of samples in current slot
  get_samples_per_slot_t get_samples_per_slot;
Rakesh's avatar
Rakesh committed
303 304
  /// slot calculation from timestamp
  get_slot_from_timestamp_t get_slot_from_timestamp;
305 306 307 308 309 310
  /// Number of samples before slot
  get_samples_slot_timestamp_t get_samples_slot_timestamp;
  /// Number of samples in 0th and center slot of a subframe
  uint32_t samples_per_slot0;
  /// Number of samples in other slots of the subframe
  uint32_t samples_per_slotN0;
311 312 313 314
  /// Number of samples in a radio frame
  uint32_t samples_per_frame;
  /// Number of samples in a subframe without CP
  uint32_t samples_per_subframe_wCP;
315 316
  /// Number of samples in a slot without CP
  uint32_t samples_per_slot_wCP;
317 318
  /// Number of samples in a radio frame without CP
  uint32_t samples_per_frame_wCP;
319 320 321 322 323 324 325
  /// NR numerology index [0..5] as specified in 38.211 Section 4 (mu). 0=15khZ SCS, 1=30khZ, 2=60kHz, etc
  uint8_t numerology_index;
  /// Number of Physical transmit antennas in node
  uint8_t nb_antennas_tx;
  /// Number of Receive antennas in node
  uint8_t nb_antennas_rx;
  /// Number of common transmit antenna ports in eNodeB (1 or 2)
326
  uint8_t nb_antenna_ports_gNB;
327 328
  /// Cyclic Prefix for DL (0=Normal CP, 1=Extended CP)
  lte_prefix_type_t Ncp;
329 330
  /// sequence which is computed based on carrier frequency and numerology to rotate/derotate each OFDM symbol according to Section 5.3 in 38.211
  int16_t symbol_rotation[224*2];
Hongzhi Wang's avatar
Hongzhi Wang committed
331 332
  /// shift of pilot position in one RB
  uint8_t nushift;
333 334
  /// SRS configuration from TS 38.331 RRC
  SRS_NR srs_nr;
335 336
  /// Power used by SSB in order to estimate signal strength and path loss
  int ss_PBCH_BlockPower;
337 338 339 340 341
  /// for NR TDD management
  TDD_UL_DL_configCommon_t  *p_tdd_UL_DL_Configuration;

  TDD_UL_DL_configCommon_t  *p_tdd_UL_DL_ConfigurationCommon2;

342
  TDD_UL_DL_SlotConfig_t *p_TDD_UL_DL_ConfigDedicated;
343 344

  /// TDD configuration
Jacques's avatar
Jacques committed
345
  uint16_t tdd_uplink_nr[2*NR_MAX_SLOTS_PER_FRAME]; /* this is a bitmap of symbol of each slot given for 2 frames */
346

347 348
  uint8_t half_frame_bit;

349
  //SSB related params
350 351
  /// Start in Subcarrier index of the SSB block
  uint16_t ssb_start_subcarrier;
Guy De Souza's avatar
Guy De Souza committed
352
  /// SSB type
353
  nr_ssb_type_e ssb_type;
354 355
  /// Max number of SSB in frame
  uint8_t Lmax;
356
  /// SS block pattern (max 64 ssb, each bit is on/off ssb)
357
  uint64_t L_ssb;
358 359
  /// Total number of SSB transmitted
  uint8_t N_ssb;
360 361
  /// SSB index
  uint8_t ssb_index;
Guy De Souza's avatar
Guy De Souza committed
362 363
  /// PBCH polar encoder params
  t_nrPolar_params pbch_polar_params;
364
};
365 366 367



368 369 370
#define KHz (1000UL)
#define MHz (1000*KHz)

371
typedef struct nr_bandentry_s {
372
  int16_t band;
373 374 375 376 377
  uint64_t ul_min;
  uint64_t ul_max;
  uint64_t dl_min;
  uint64_t dl_max;
  uint64_t step_size;
378
  uint64_t N_OFFs_DL;
379
  uint8_t deltaf_raster;
380
} nr_bandentry_t;
381

382
typedef struct nr_band_info_s {
383
  int nbands;
384 385 386
  nr_bandentry_t band_info[100];
} nr_band_info_t;

387
#endif