[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-428]Slot Indication at DUAPP
[o-du/l2.git] / src / cm / common_def.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 #ifndef __COMMON_DEF_H__
19 #define __COMMON_DEF_H__
20
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27
28 #include "cm_mem.h"
29 #include "envopt.h"
30 #include "envdep.h"
31 #include "envind.h"
32 #include "gen.h" 
33 #include "ssi.h" 
34 #include "cm_math.h"
35 #include "cm5.h"
36 #include "cm_tkns.h"
37 #include "cm_mblk.h"
38 #include "cm_llist.h"
39 #include "cm_hash.h"
40 #include "cm_lte.h"
41 #include "cm_err.h"
42 #include "cm_tpt.h"
43 #include "cm.h"
44 #include "gen.x"           /* general */
45 #include "ssi.x"           /* system services */
46 #include "cm_tpt.x"
47 #include "cm_tkns.x" 
48 #include "cm_mblk.x"
49 #include "cm_llist.x"
50 #include "cm5.x" 
51 #include "cm_hash.x"
52 #include "cm_lte.x"
53 #include "cm_lib.x"
54 #include "du_log.h"
55
56 #define RADIO_FRAME_DURATION 10 /* Time duration of a radio frame in ms */
57 /* MAX values */
58 #define MAX_NUM_CELL 2 /* Changed to 2 to support cell Id 2 even if there is only one cell in DU */
59 #define MAX_NUM_MU   4
60 #define MAX_NUM_UE   3
61 #define MAX_NUM_UE_PER_TTI 1
62 #define MAX_NUM_LC   MAX_DRB_LCID + 1   /*Spec 38.331: Sec 6.4: maxLC-ID Keyword*/
63 #define MAX_NUM_SRB  3    /* Max. no of Srbs */
64 #define MAX_NUM_DRB  29   /* spec 38.331, maxDRB */
65
66 /* 5G ORAN phy delay */
67 #define PHY_DELTA_DL 1
68 #define PHY_DELTA_UL 0
69
70  /* SELECTORS */ 
71 #define ODU_SELECTOR_LC 0
72 #define ODU_SELECTOR_TC 1
73 #define ODU_SELECTOR_LWLC 2
74
75 #define ODU_START_CRNTI   100
76 #define ODU_END_CRNTI     500
77
78 /* LCID */
79 #define SRB0_LCID  0
80 #define SRB1_LCID  1
81 #define SRB2_LCID  2
82 #define SRB3_LCID  3
83 #define MIN_DRB_LCID 4
84 #define MAX_DRB_LCID 32
85
86 #define FREQ_DOM_RSRC_SIZE  6      /* i.e. 6 bytes because Size of frequency domain resource is 45 bits */
87 #define PUCCH_FORMAT_0 0
88 #define PUCCH_FORMAT_1 1
89 #define PUCCH_FORMAT_2 2
90 #define PUCCH_FORMAT_3 3 
91 #define PUCCH_FORMAT_4 4
92
93 #define DEFAULT_MCS 4
94
95 #define BANDWIDTH_20MHZ 20
96 #define BANDWIDTH_100MHZ 100
97
98 /* PRB allocation as per 38.101, Section 5.3.2 */
99 #define TOTAL_PRB_20MHZ_MU0 106
100 #define TOTAL_PRB_100MHZ_MU1 273
101 #ifdef NR_TDD
102 #define MAX_NUM_RB TOTAL_PRB_100MHZ_MU1  /* value for numerology 1, 100 MHz */
103 #else
104 #define MAX_NUM_RB TOTAL_PRB_20MHZ_MU0 /* value for numerology 0, 20 MHz */
105 #endif
106
107 #define ODU_UE_THROUGHPUT_PRINT_TIME_INTERVAL      5     /* in milliseconds */
108 #define ODU_SNSSAI_THROUGHPUT_PRINT_TIME_INTERVAL  60000 /* in milliseconds */
109
110 /*Spec 38.331 Sec 6.4: Maximum number of paging occasion per paging frame*/
111 #define MAX_PO_PER_PF 4
112
113 /* Defining macros for common utility functions */
114 #define ODU_GET_MSG_BUF SGetMsg
115 #define ODU_PUT_MSG_BUF SPutMsg
116 #define ODU_ADD_PRE_MSG_MULT SAddPreMsgMult
117 #define ODU_ADD_PRE_MSG_MULT_IN_ORDER SAddPreMsgMultInOrder
118 #define ODU_ADD_POST_MSG_MULT SAddPstMsgMult
119 #define ODU_START_TASK SStartTask
120 #define ODU_STOP_TASK SStopTask
121 #define ODU_ATTACH_TTSK SAttachTTsk
122 #define ODU_POST_TASK SPstTsk
123 #define ODU_COPY_MSG_TO_FIX_BUF SCpyMsgFix
124 #define ODU_COPY_FIX_BUF_TO_MSG SCpyFixMsg
125 #define ODU_REG_TTSK SRegTTsk
126 #define ODU_SET_PROC_ID SSetProcId
127 #define ODU_GET_MSG_LEN SFndLenMsg
128 #define ODU_EXIT_TASK SExitTsk
129 #define ODU_PRINT_MSG SPrntMsg
130 #define ODU_REM_PRE_MSG SRemPreMsg
131 #define ODU_REM_PRE_MSG_MULT SRemPreMsgMult
132 #define ODU_REG_TMR_MT SRegTmrMt
133 #define ODU_SEGMENT_MSG SSegMsg
134 #define ODU_CAT_MSG SCatMsg
135 #define ODU_GET_PROCID SFndProcId
136 #define ODU_SET_THREAD_AFFINITY SSetAffinity
137 #define ODU_CREATE_TASK SCreateSTsk
138
139 #define MAX_SYMB_PER_SLOT 14 
140
141 /* Slice */
142 #define SD_SIZE 3
143
144 #ifdef NR_TDD
145 /* Maximum slots for max periodicity and highest numerology is 320.
146  * However, aligning to fapi_interface.h, setting this macro to 160 */
147 #define MAX_TDD_PERIODICITY_SLOTS 160 
148 #endif
149
150 #define GET_UE_ID( _crnti,_ueId)           \
151 {                                          \
152    _ueId = _crnti - ODU_START_CRNTI + 1;  \
153 }
154
155 #define GET_CRNTI( _crnti, _ueId)          \
156 {                                          \
157    _crnti = _ueId + ODU_START_CRNTI - 1;  \
158 }
159
160 /* Calculates cellIdx from cellId */
161 #define GET_CELL_IDX(_cellId, _cellIdx)   \
162 {                                         \
163    _cellIdx = _cellId - 1;                \
164 }
165
166 #define SET_BITS_MSB(_startBit, _numBits, _byte) \
167 {                                                \
168    _byte = (~((0xFF) >> _numBits));              \
169        _byte >>= _startBit;                          \
170 }
171
172 #define SET_BITS_LSB(_startBit, _numBits, _byte) \
173 {                                                \
174    _byte = (~((0xFF) << _numBits));              \
175        _byte <<= _startBit;                          \
176 }
177
178 /* this MACRO set 1 bit at the bit position */
179 #define SET_ONE_BIT(_bitPos, _out)            \
180 {                                             \
181    _out = ((1<<_bitPos) | _out);              \
182 }
183
184 /* this MACRO un-set 1 bit at the bit position */
185 #define UNSET_ONE_BIT(_bitPos, _out)            \
186 {                                               \
187    _out = (~(1<<_bitPos) & _out);               \
188 }
189
190 /* this MACRO finds the index of the rightmost set bit */
191 #define GET_RIGHT_MOST_SET_BIT( _in,_bitPos)        \
192 {                                                \
193    _bitPos = __builtin_ctz(_in);                 \
194 }
195
196 /* MACRO for checking CRNTI range*/
197 #define CHECK_CRNTI(_crnti, _isCrntiValid)                                         \
198 {                                                                   \
199   _isCrntiValid = ((_crnti >= ODU_START_CRNTI && _crnti <= ODU_END_CRNTI ) ? 1 : 0); \
200 }
201
202 #define CHECK_LCID(_lcId, _isLcidValid)      \
203 {\
204    _isLcidValid = ((_lcId >= SRB0_LCID && _lcId <= MAX_DRB_LCID) ? 1 : 0);\
205 }
206
207 typedef enum
208 {
209    UE_CFG_INACTIVE,
210    UE_CFG_INPROGRESS,
211    UE_CREATE_COMPLETE,
212    UE_DELETE_COMPLETE,
213    UE_RECFG_COMPLETE
214 }UeCfgState;
215
216 typedef enum
217 {
218    CONFIG_UNKNOWN,
219    CONFIG_ADD,
220    CONFIG_MOD,
221    CONFIG_DEL
222 }ConfigType;
223
224 #ifdef NR_TDD
225 typedef enum
226 {
227    DL_SLOT,
228    UL_SLOT,
229    FLEXI_SLOT
230 }SlotConfig;
231
232 typedef enum
233 {
234    TX_PRDCTY_MS_0P5,
235    TX_PRDCTY_MS_0P625,
236    TX_PRDCTY_MS_1,
237    TX_PRDCTY_MS_1P25,
238    TX_PRDCTY_MS_2,
239    TX_PRDCTY_MS_2P5,
240    TX_PRDCTY_MS_5,
241    TX_PRDCTY_MS_10
242 }DlUlTxPeriodicity;
243 #endif
244
245 typedef enum
246 {
247    SCS_15KHZ,
248    SCS_30KHZ,
249    SCS_60KHZ,
250    SCS_120KHZ,
251    SCS_240KHZ
252 }SCS;
253
254 typedef enum
255 {
256    SCS_5MS,
257    SCS_10MS,
258    SCS_20MS,
259    SCS_40MS,
260    SCS_80MS,
261    SCS_160MS
262 }ScsPeriodicity;
263
264 typedef enum
265 {
266    CELL_UP,
267    CELL_DOWN
268 }OduCellStatus;
269
270
271 typedef enum
272 {
273    DIR_NONE,
274    DIR_UL,
275    DIR_DL,
276    DIR_BOTH
277 }Direction;
278
279 typedef struct slotTimingInfo
280 {
281    uint16_t cellId;
282    uint16_t sfn;
283    uint16_t slot;
284 }SlotTimingInfo;
285
286 typedef struct PlmnIdentity
287 {
288    uint8_t mcc[3];
289    uint8_t mnc[3];
290 }Plmn;
291
292 typedef struct snssai
293 {
294    uint8_t   sst;
295    uint8_t   sd[SD_SIZE];
296 }Snssai;
297
298 typedef struct oduCellId
299 {
300    uint16_t cellId;
301 }OduCellId;
302
303 #ifdef NR_TDD
304 typedef struct tddCfg
305 {
306    bool               pres;
307    DlUlTxPeriodicity  tddPeriod;      /* DL UL Transmission periodicity */
308    SlotConfig         slotCfg[MAX_TDD_PERIODICITY_SLOTS][MAX_SYMB_PER_SLOT]; 
309 }TDDCfg;
310 #endif
311
312 OduCellStatus gCellStatus;
313 uint64_t gSlotCount;
314 uint64_t gDlDataRcvdCnt;   /* Number of DL data received at EGTP */
315
316 void fillCoresetFeqDomAllocMap(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
317 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len);
318 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf);
319 uint16_t convertScsEnumValToScsVal(uint8_t scsEnumValue);
320
321 uint8_t SGetSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data **ptr, Size size);
322 uint8_t SPutSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data *ptr, Size size);
323 uint8_t SGetStaticBufNewForDebug(char *file, char *func, char *line, \
324 Region region, Pool pool, Data **ptr, Size size, uint8_t memType);
325 uint8_t SPutStaticBufNewForDebug(char *file, char *func, char *line, \
326 Region region, Pool pool, Data *ptr, Size size, uint8_t memType);
327 uint8_t countSetBits(uint32_t num);
328
329 #endif
330
331 /**********************************************************************
332   End of file
333 ***********************************************************************/