Fixes for SSB transmission in Radio mode integration [Issue-ID: ODUHIGH-267]
[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 "cm_math.h"
30 #include "envopt.h"
31 #include "envdep.h"
32 #include "envind.h"
33 #include "gen.h" 
34 #include "ssi.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_math.x"
47 #include "cm_tpt.x"
48 #include "cm_tkns.x" 
49 #include "cm_mblk.x"
50 #include "cm_llist.x"
51 #include "cm5.x" 
52 #include "cm_hash.x"
53 #include "cm_lte.x"
54 #include "cm_lib.x"
55 #include "du_log.h"
56
57 #define RADIO_FRAME_DURATION 10 /* Time duration of a radio frame in ms */
58 /* MAX values */
59 #define MAX_NUM_CELL 1
60 #define MAX_NUM_UE   1
61 #define MAX_NUM_LC   11
62 #define MAX_NUM_SRB  3    /* Max. no of Srbs */
63 #define MAX_NUM_DRB  29   /* spec 38.331, maxDRB */
64
65 /* 5G ORAN phy delay */
66 #define PHY_DELTA_DL 1
67 #define PHY_DELTA_UL 0
68
69  /* SELECTORS */ 
70 #define ODU_SELECTOR_LC 0
71 #define ODU_SELECTOR_TC 1
72 #define ODU_SELECTOR_LWLC 2
73
74 #define ODU_START_CRNTI   100
75 #define ODU_END_CRNTI     500
76
77 /* LCID */
78 #define SRB0_LCID  0
79 #define SRB1_LCID  1
80 #define SRB2_LCID  2
81 #define SRB3_LCID  3
82 #define MIN_DRB_LCID 4
83 #define MAX_DRB_LCID 32
84
85 #define FREQ_DOM_RSRC_SIZE  6      /* i.e. 6 bytes because Size of frequency domain resource is 45 bits */
86 #define PUCCH_FORMAT_0 0
87 #define PUCCH_FORMAT_1 1
88 #define PUCCH_FORMAT_2 2
89 #define PUCCH_FORMAT_3 3 
90 #define PUCCH_FORMAT_4 4
91
92 #define BANDWIDTH_20MHZ 20
93 #define BANDWIDTH_100MHZ 100
94
95 /* PRB allocation as per 38.101, Section 5.3.2 */
96 #define TOTAL_PRB_20MHZ_MU0 106
97 #define TOTAL_PRB_100MHZ_MU1 273
98
99 /* Defining macros for common utility functions */
100 #define ODU_GET_MSG_BUF SGetMsg
101 #define ODU_PUT_MSG_BUF SPutMsg
102 #define ODU_ADD_PRE_MSG_MULT SAddPreMsgMult
103 #define ODU_ADD_PRE_MSG_MULT_IN_ORDER SAddPreMsgMultInOrder
104 #define ODU_ADD_POST_MSG_MULT SAddPstMsgMult
105 #define ODU_START_TASK SStartTask
106 #define ODU_STOP_TASK SStopTask
107 #define ODU_ATTACH_TTSK SAttachTTsk
108 #define ODU_POST_TASK SPstTsk
109 #define ODU_COPY_MSG_TO_FIX_BUF SCpyMsgFix
110 #define ODU_COPY_FIX_BUF_TO_MSG SCpyFixMsg
111 #define ODU_REG_TTSK SRegTTsk
112 #define ODU_SET_PROC_ID SSetProcId
113 #define ODU_GET_MSG_LEN SFndLenMsg
114 #define ODU_EXIT_TASK SExitTsk
115 #define ODU_PRINT_MSG SPrntMsg
116 #define ODU_REM_PRE_MSG SRemPreMsg
117 #define ODU_REM_PRE_MSG_MULT SRemPreMsgMult
118 #define ODU_REG_TMR_MT SRegTmrMt
119 #define ODU_SEGMENT_MSG SSegMsg
120 #define ODU_CAT_MSG SCatMsg
121 #define ODU_GET_PROCID SFndProcId
122 #define ODU_SET_THREAD_AFFINITY SSetAffinity
123 #define ODU_CREATE_TASK SCreateSTsk
124
125 #ifdef NR_TDD
126 /* Maximum slots for max periodicity and highest numerology is 320.
127  * However, aligning to fapi_interface.h, setting this macro to 160 */
128 #define MAX_TDD_PERIODICITY_SLOTS 160 
129 #define MAX_SYMB_PER_SLOT 14 
130 #endif
131
132 #define GET_UE_IDX( _crnti,_ueIdx)         \
133 {                                          \
134    _ueIdx = _crnti - ODU_START_CRNTI + 1;  \
135 }
136
137 #define GET_CRNTI( _crnti,_ueIdx)          \
138 {                                          \
139    _crnti = _ueIdx + ODU_START_CRNTI - 1;  \
140 }
141
142 /* Calculates cellIdx from cellId */
143 #define GET_CELL_IDX(_cellId, _cellIdx)   \
144 {                                         \
145    _cellIdx = _cellId - 1;                \
146 }
147
148 #define SET_BITS_MSB(_startBit, _numBits, _byte) \
149 {                                                \
150    _byte = (~((0xFF) >> _numBits));              \
151        _byte >>= _startBit;                          \
152 }
153
154 #define SET_BITS_LSB(_startBit, _numBits, _byte) \
155 {                                                \
156    _byte = (~((0xFF) << _numBits));              \
157        _byte <<= _startBit;                          \
158 }
159
160 /* this MACRO set 1 bit at the bit position */
161 #define SET_ONE_BIT(_bitPos, _out)            \
162 {                                             \
163    _out = ((1<<_bitPos) | _out);              \
164 }
165
166 /* this MACRO un-set 1 bit at the bit position */
167 #define UNSET_ONE_BIT(_bitPos, _out)            \
168 {                                               \
169    _out = (~(1<<_bitPos) & _out);               \
170 }
171
172 /* this MACRO finds the index of the rightmost set bit */
173 #define GET_RIGHT_MOST_SET_BIT( _in,_bitPos)        \
174 {                                                \
175    _bitPos = __builtin_ctz(_in);                 \
176 }
177
178 typedef enum
179 {
180    UE_CFG_INACTIVE,
181    UE_CREATE_COMPLETE,
182    UE_RECFG_COMPLETE
183 }UeCfgState;
184
185 typedef enum
186 {
187    CONFIG_UNKNOWN,
188    CONFIG_ADD,
189    CONFIG_MOD,
190    CONFIG_DEL
191 }ConfigType;
192
193 #ifdef NR_TDD
194 typedef enum
195 {
196    DL_SLOT,
197    UL_SLOT,
198    FLEXI_SLOT
199 }SlotConfig;
200
201 typedef enum
202 {
203    TX_PRDCTY_MS_0P5,
204    TX_PRDCTY_MS_0P625,
205    TX_PRDCTY_MS_1,
206    TX_PRDCTY_MS_1P25,
207    TX_PRDCTY_MS_2,
208    TX_PRDCTY_MS_2P5,
209    TX_PRDCTY_MS_5,
210    TX_PRDCTY_MS_10
211 }DlUlTxPeriodicity;
212 #endif
213
214 typedef enum
215 {
216    SCS_15KHZ,
217    SCS_30KHZ,
218    SCS_60KHZ,
219    SCS_120KHZ,
220    SCS_240KHZ
221 }SCS;
222
223 typedef struct slotIndInfo
224 {
225    uint16_t cellId;
226    uint16_t sfn;
227    uint16_t slot;
228 }SlotIndInfo;
229
230 typedef struct PlmnIdentity
231 {
232    uint8_t mcc[3];
233    uint8_t mnc[3];
234 }Plmn;
235
236 typedef struct oduCellId
237 {
238    uint16_t cellId;
239 }OduCellId;
240
241 #ifdef NR_TDD
242 typedef struct tddCfg
243 {
244    bool               pres;
245    DlUlTxPeriodicity  tddPeriod;      /* DL UL Transmission periodicity */
246    SlotConfig         slotCfg[MAX_TDD_PERIODICITY_SLOTS][MAX_SYMB_PER_SLOT]; 
247 }TDDCfg;
248 #endif
249
250
251 uint64_t gSlotCount;
252 uint64_t gDlDataRcvdCnt;   /* Number of DL data received at EGTP */
253
254 void freqDomRscAllocType0(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
255 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len);
256 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf);
257
258 #endif
259
260 /**********************************************************************
261   End of file
262 ***********************************************************************/