Merge "Replaced old SSI function with new macros jira id - ODUHIGH-212"
[o-du/l2.git] / src / 5gnrsch / sch_utils.c
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
19 /************************************************************************
20  
21      Name:     sch_utils.c
22   
23      Type:     C source file
24   
25      Desc:     C source code for scheduler utilities
26   
27      File:     sch_utils.c
28   
29 **********************************************************************/
30
31 /** @file sch_utils.c
32 @brief This file implements the schedulers util functions.
33 */
34
35 /* header files */
36 #include "common_def.h"
37 #include "du_app_mac_inf.h"
38 #include "lrg.h"
39 #include "tfu.h"
40 #include "tfu.x"           /* TFU types */
41 #include "lrg.x"           /* layer management typedefs for MAC */
42 #include "mac_sch_interface.h"
43 #include "sch.h"
44 #include "sch_utils.h"
45 #include "math.h"
46
47 /* spec-38.213 Table 13-1 */
48 int8_t coresetIdxTable[MAX_CORESET_INDEX][4] = {
49 {   1,   24,   2,   0}, /* index 0  */
50 {   1,   24,   2,   2}, /* index 1  */
51 {   1,   24,   2,   4}, /* index 2  */
52 {   1,   24,   3,   0}, /* index 3  */
53 {   1,   24,   3,   2}, /* index 4  */
54 {   1,   24,   3,   4}, /* index 5  */
55 {   1,   48,   1,  12}, /* index 6  */
56 {   1,   48,   1,  16}, /* index 7  */
57 {   1,   48,   2,  12}, /* index 8  */
58 {   1,   48,   2,  16}, /* index 9  */
59 {   1,   48,   3,  12}, /* index 10 */
60 {   1,   48,   3,  16}, /* index 11 */
61 {   1,   96,   1,  38}, /* index 12 */
62 {   1,   96,   2,  38}, /* index 13 */
63 {   1,   96,   3,  38}, /* index 14 */
64 {   0,    0,   0,   0}, /* index 15 */
65 };
66
67 /* spec-38.213 Table 13-11 */
68 /* m value is scaled to 2, when using it in formula, divide by 2 */
69 /* firstSymbol will vary depends on i, hence not filled */
70 int8_t searchSpaceIdxTable[MAX_SEARCH_SPACE_INDEX][4] = {
71 {   0,    1,   2,   0}, /* index 0  */
72 {   0,    2,   1,   0}, /* index 1  */
73 {   2,    1,   2,   0}, /* index 2  */
74 {   2,    2,   1,   0}, /* index 3  */
75 {   5,    1,   2,   0}, /* index 4  */
76 {   5,    2,   1,   0}, /* index 5  */
77 {   7,    1,   2,   0}, /* index 6  */
78 {   7,    2,   1,   0}, /* index 7  */
79 {   0,    1,   4,   0}, /* index 8  */
80 {   5,    1,   4,   0}, /* index 9  */
81 {   0,    1,   2,   0}, /* index 10 */
82 {   0,    1,   2,   0}, /* index 11 */
83 {   2,    1,   2,   0}, /* index 12 */
84 {   2,    1,   2,   0}, /* index 13 */
85 {   5,    1,   2,   0}, /* index 14 */
86 {   5,    1,   2,   0}, /* index 15 */
87 };
88
89 /* RACH tables */
90
91 /* spec-38.211 Table 6.3.3.2-1 */
92 /* Lra, delFRa, delF, numRb, k' */
93 uint16_t numRbForPrachTable[MAX_RACH_NUM_RB_IDX][5] = {
94 {   839,  1.25,  15,   6,   7    }, /* index 0 */
95 {   839,  1.25,  30,   3,   1    }, /* index 1 */
96 {   839,  1.25,  60,   2,   133  }, /* index 2 */
97 {   839,  5,     15,   24,  12   }, /* index 3 */
98 {   839,  5,     30,   12,  10   }, /* index 4 */
99 {   839,  5,     60,   6,   7    }, /* index 5 */
100 {   139,  15,    15,   12,  2    }, /* index 6 */
101 {   139,  15,    30,   6,   2    }, /* index 7 */
102 {   139,  15,    60,   3,   2    }, /* index 8 */
103 {   139,  30,    15,   24,  2    }, /* index 9 */
104 {   139,  30,    30,   12,  2    }, /* index 10 */
105 {   139,  30,    60,   6,   2    }, /* index 11 */
106 {   139,  60,    60,   12,  2    }, /* index 12 */
107 {   139,  60,    120,  6,   2    }, /* index 13 */
108 {   139,  120,   60,   24,  2    }, /* index 14 */
109 {   139,  120,   120,  12,  2    }, /* index 15 */
110 };
111
112 /* prach config index Table 6.3.3.2-2 spec 38.211 
113  * PRACH format given as follows:
114  * 0 = 0
115  * 1 = 1
116  * 2 = 2
117  * 3 = 3
118  * 4 = A1
119  * 5 = A2
120  * 6 = A3
121  * 7 = B1
122  * 8 = B4
123  * 9 = C0
124  * 10 = C2
125  * 11 = A1/B1
126  * 12 = A2/B2
127  * 13 = A3/B3 
128  * Subframe num is represented considering 0-9 bits and
129  * value 1 corresponds to the subframe that is valid 
130  */
131
132 uint16_t prachCfgIdxTable[MAX_PRACH_CONFIG_IDX][8] = {
133 { 0, 16,  1,    2,  0,  0,  0,  0 }, /* index 0   */
134 { 0, 16,  1,   16,  0,  0,  0,  0 }, /* index 1   */
135 { 0, 16,  1,  128,  0,  0,  0,  0 }, /* index 2   */
136 { 0, 16,  1,  512,  0,  0,  0,  0 }, /* index 3   */
137 { 0,  8,  1,    2,  0,  0,  0,  0 }, /* index 4   */
138 { 0,  8,  1,   16,  0,  0,  0,  0 }, /* index 5   */
139 { 0,  8,  1,  128,  0,  0,  0,  0 }, /* index 6   */
140 { 0,  8,  1,  512,  0,  0,  0,  0 }, /* index 7   */
141 { 0,  4,  1,    2,  0,  0,  0,  0 }, /* index 8   */
142 { 0,  4,  1,   16,  0,  0,  0,  0 }, /* index 9   */
143 { 0,  4,  1,  128,  0,  0,  0,  0 }, /* index 10  */
144 { 0,  4,  1,  512,  0,  0,  0,  0 }, /* index 11  */
145 { 0,  2,  1,    2,  0,  0,  0,  0 }, /* index 12  */
146 { 0,  2,  1,   16,  0,  0,  0,  0 }, /* index 13  */
147 { 0,  2,  1,  128,  0,  0,  0,  0 }, /* index 14  */
148 { 0,  2,  1,  512,  0,  0,  0,  0 }, /* index 15  */
149 { 0,  1,  0,    2,  0,  0,  0,  0 }, /* index 16  */
150 { 0,  1,  0,   16,  0,  0,  0,  0 }, /* index 17  */
151 { 0,  1,  0,  128,  0,  0,  0,  0 }, /* index 18  */
152 { 0,  1,  0,   66,  0,  0,  0,  0 }, /* index 19  */
153 { 0,  1,  0,  132,  0,  0,  0,  0 }, /* index 20  */
154 { 0,  1,  0,  264,  0,  0,  0,  0 }, /* index 21  */
155 { 0,  1,  0,  146,  0,  0,  0,  0 }, /* index 22  */
156 { 0,  1,  0,  292,  0,  0,  0,  0 }, /* index 23  */
157 { 0,  1,  0,  584,  0,  0,  0,  0 }, /* index 24  */
158 { 0,  1,  0,  341,  0,  0,  0,  0 }, /* index 25  */
159 { 0,  1,  0,  682,  0,  0,  0,  0 }, /* index 26  */
160 { 0,  1,  0, 1023,  0,  0,  0,  0 }, /* index 27  */
161 { 1, 16,  1,    2,  0,  0,  0,  0 }, /* index 28  */
162 { 1, 16,  1,   16,  0,  0,  0,  0 }, /* index 29  */
163 { 1, 16,  1,  128,  0,  0,  0,  0 }, /* index 30  */
164 { 1, 16,  1,  512,  0,  0,  0,  0 }, /* index 31  */
165 { 1,  8,  1,    2,  0,  0,  0,  0 }, /* index 32  */
166 { 1,  8,  1,   16,  0,  0,  0,  0 }, /* index 33  */
167 { 1,  8,  1,  128,  0,  0,  0,  0 }, /* index 34  */
168 { 1,  8,  1,  512,  0,  0,  0,  0 }, /* index 35  */
169 { 1,  4,  1,    2,  0,  0,  0,  0 }, /* index 36  */
170 { 1,  4,  1,   16,  0,  0,  0,  0 }, /* index 37  */
171 { 1,  4,  1,  128,  0,  0,  0,  0 }, /* index 38  */
172 { 1,  4,  1,  512,  0,  0,  0,  0 }, /* index 39  */
173 { 1,  2,  1,    2,  0,  0,  0,  0 }, /* index 40  */
174 { 1,  2,  1,   16,  0,  0,  0,  0 }, /* index 41  */
175 { 1,  2,  1,  128,  0,  0,  0,  0 }, /* index 42  */
176 { 1,  2,  1,  512,  0,  0,  0,  0 }, /* index 43  */
177 { 1,  1,  0,    2,  0,  0,  0,  0 }, /* index 44  */
178 { 1,  1,  0,   16,  0,  0,  0,  0 }, /* index 45  */
179 { 1,  1,  0,  128,  0,  0,  0,  0 }, /* index 46  */
180 { 1,  1,  0,   64,  0,  0,  0,  0 }, /* index 47  */
181 { 1,  1,  0,  132,  0,  0,  0,  0 }, /* index 48  */
182 { 1,  1,  0,  264,  0,  0,  0,  0 }, /* index 49  */
183 { 1,  1,  0,  146,  0,  0,  0,  0 }, /* index 50  */
184 { 1,  1,  0,  292,  0,  0,  0,  0 }, /* index 51  */
185 { 1,  1,  0,  584,  0,  0,  0,  0 }, /* index 52  */
186 { 2, 16,  1,    2,  0,  0,  0,  0 }, /* index 53  */
187 { 2,  8,  1,    2,  0,  0,  0,  0 }, /* index 54  */
188 { 2,  4,  0,    2,  0,  0,  0,  0 }, /* index 55  */
189 { 2,  2,  0,    2,  0,  0,  0,  0 }, /* index 56  */
190 { 2,  2,  0,   32,  0,  0,  0,  0 }, /* index 57  */
191 { 2,  1,  0,    2,  0,  0,  0,  0 }, /* index 58  */
192 { 2,  1,  0,   32,  0,  0,  0,  0 }, /* index 59  */
193 { 3, 16,  1,    2,  0,  0,  0,  0 }, /* index 60  */
194 { 3, 16,  1,   16,  0,  0,  0,  0 }, /* index 61  */
195 { 3, 16,  1,  128,  0,  0,  0,  0 }, /* index 62  */
196 { 3, 16,  1,  512,  0,  0,  0,  0 }, /* index 63  */
197 { 3,  8,  1,    2,  0,  0,  0,  0 }, /* index 64  */
198 { 3,  8,  1,   16,  0,  0,  0,  0 }, /* index 65  */
199 { 3,  8,  1,  128,  0,  0,  0,  0 }, /* index 66  */
200 { 3,  4,  1,    2,  0,  0,  0,  0 }, /* index 67  */
201 { 3,  4,  1,   16,  0,  0,  0,  0 }, /* index 68  */
202 { 3,  4,  1,  128,  0,  0,  0,  0 }, /* index 69  */
203 { 3,  4,  1,  512,  0,  0,  0,  0 }, /* index 70  */
204 { 3,  2,  1,    2,  0,  0,  0,  0 }, /* index 71  */
205 { 3,  2,  1,   16,  0,  0,  0,  0 }, /* index 72  */
206 { 3,  2,  1,  128,  0,  0,  0,  0 }, /* index 73  */
207 { 3,  2,  1,  512,  0,  0,  0,  0 }, /* index 74  */
208 { 3,  1,  0,    2,  0,  0,  0,  0 }, /* index 75  */
209 { 3,  1,  0,   16,  0,  0,  0,  0 }, /* index 76  */
210 { 3,  1,  0,  128,  0,  0,  0,  0 }, /* index 77  */
211 { 3,  1,  0,   66,  0,  0,  0,  0 }, /* index 78  */
212 { 3,  1,  0,  132,  0,  0,  0,  0 }, /* index 79  */
213 { 3,  1,  0,  264,  0,  0,  0,  0 }, /* index 80  */
214 { 3,  1,  0,  146,  0,  0,  0,  0 }, /* index 81  */
215 { 3,  1,  0,  292,  0,  0,  0,  0 }, /* index 82  */
216 { 3,  1,  0,  584,  0,  0,  0,  0 }, /* index 83  */
217 { 3,  1,  0,  341,  0,  0,  0,  0 }, /* index 84  */
218 { 3,  1,  0,  682,  0,  0,  0,  0 }, /* index 85  */
219 { 3,  1,  0, 1023,  0,  0,  0,  0 }, /* index 86  */
220 { 4, 16,  0,  528,  0,  1,  6,  2 }, /* index 87  */
221 { 4, 16,  1,   16,  0,  2,  6,  2 }, /* index 88  */
222 { 4,  8,  0,  528,  0,  1,  6,  2 }, /* index 89  */
223 { 4,  8,  1,   16,  0,  2,  6,  2 }, /* index 90  */
224 { 4,  4,  0,  528,  0,  1,  6,  2 }, /* index 91  */
225 { 4,  4,  1,  528,  0,  1,  6,  2 }, /* index 92  */
226 { 4,  4,  0,   16,  0,  2,  6,  2 }, /* index 93  */
227 { 4,  2,  0,  528,  0,  1,  6,  2 }, /* index 94  */
228 { 4,  2,  0,    2,  0,  2,  6,  2 }, /* index 95  */
229 { 4,  2,  0,   16,  0,  2,  6,  2 }, /* index 96  */
230 { 4,  2,  0,  128,  0,  2,  6,  2 }, /* index 97  */
231 { 4,  1,  0,   16,  0,  1,  6,  2 }, /* index 98  */
232 { 4,  1,  0,   66,  0,  1,  6,  2 }, /* index 99  */
233 { 4,  1,  0,  528,  0,  1,  6,  2 }, /* index 100  */
234 { 4,  1,  0,    2,  0,  2,  6,  2 }, /* index 101  */
235 { 4,  1,  0,  128,  0,  2,  6,  2 }, /* index 102  */
236 { 4,  1,  0,  132,  0,  2,  6,  2 }, /* index 103  */
237 { 4,  1,  0,  146,  0,  2,  6,  2 }, /* index 104  */
238 { 4,  1,  0,  341,  0,  2,  6,  2 }, /* index 105  */
239 { 4,  1,  0, 1023,  0,  2,  6,  2 }, /* index 106  */
240 { 4,  1,  0,  682,  0,  2,  6,  2 }, /* index 107  */
241 {11,  2,  0,  528,  0,  1,  7,  2 }, /* index 108  */
242 {11,  2,  0,   16,  0,  2,  7,  2 }, /* index 109  */
243 {11,  1,  0,   16,  0,  1,  7,  2 }, /* index 110  */
244 {11,  1,  0,   66,  0,  1,  7,  2 }, /* index 111  */
245 {11,  1,  0,  528,  0,  1,  7,  2 }, /* index 112  */
246 {11,  1,  0,    2,  0,  2,  7,  2 }, /* index 113  */
247 {11,  1,  0,  128,  0,  2,  7,  2 }, /* index 114  */
248 {11,  1,  0,  146,  0,  2,  7,  2 }, /* index 115  */
249 {11,  1,  0,  341,  0,  2,  7,  2 }, /* index 116  */
250 { 5, 16,  1,  580,  0,  1,  3,  4 }, /* index 117  */
251 { 5, 16,  1,   16,  0,  2,  3,  4 }, /* index 118  */
252 { 5,  8,  1,  580,  0,  1,  3,  4 }, /* index 119  */
253 { 5,  8,  1,   16,  0,  2,  3,  4 }, /* index 120  */
254 { 5,  4,  0,  580,  0,  1,  3,  4 }, /* index 121  */
255 { 5,  4,  0,   16,  0,  2,  3,  4 }, /* index 122  */
256 { 5,  2,  1,  580,  0,  1,  3,  4 }, /* index 123  */
257 { 5,  2,  0,    2,  0,  2,  3,  4 }, /* index 124  */
258 { 5,  2,  0,   16,  0,  2,  3,  4 }, /* index 125  */
259 { 5,  2,  0,  128,  0,  2,  3,  4 }, /* index 126  */
260 { 5,  1,  0,   16,  0,  1,  3,  4 }, /* index 127  */
261 { 5,  1,  0,   66,  0,  1,  3,  4 }, /* index 128  */
262 { 5,  1,  0,  528,  0,  1,  3,  4 }, /* index 129  */
263 { 5,  1,  0,    2,  0,  2,  3,  4 }, /* index 130  */
264 { 5,  1,  0,  128,  0,  2,  3,  4 }, /* index 131  */
265 { 5,  1,  0,  132,  0,  2,  3,  4 }, /* index 132  */
266 { 5,  1,  0,  146,  0,  2,  3,  4 }, /* index 133  */
267 { 5,  1,  0,  341,  0,  2,  3,  4 }, /* index 134  */
268 { 5,  1,  0, 1023,  0,  2,  3,  4 }, /* index 135  */
269 { 5,  1,  0,  682,  0,  2,  3,  4 }, /* index 136  */
270 {12,  2,  1,  580,  0,  1,  3,  4 }, /* index 137  */
271 {12,  2,  0,   16,  0,  2,  3,  4 }, /* index 138  */
272 {12,  1,  0,   16,  0,  1,  3,  4 }, /* index 139  */
273 {12,  1,  0,   66,  0,  1,  3,  4 }, /* index 140  */
274 {12,  1,  0,  528,  0,  1,  3,  4 }, /* index 141  */
275 {12,  1,  0,    2,  0,  2,  3,  4 }, /* index 142  */
276 {12,  1,  0,  128,  0,  2,  3,  4 }, /* index 143  */
277 {12,  1,  0,  146,  0,  2,  3,  4 }, /* index 144  */
278 {12,  1,  0,  341,  0,  2,  3,  4 }, /* index 145  */
279 {12,  1,  0, 1023,  0,  2,  3,  4 }, /* index 146  */
280 { 6, 16,  1,  528,  0,  1,  2,  6 }, /* index 147  */
281 { 6, 16,  1,   16,  0,  2,  2,  6 }, /* index 148  */
282 { 6,  8,  1,  528,  0,  1,  2,  6 }, /* index 149  */
283 { 6,  8,  1,   16,  0,  2,  2,  6 }, /* index 150  */
284 { 6,  4,  0,  528,  0,  1,  2,  6 }, /* index 151  */
285 { 6,  4,  0,   16,  0,  2,  2,  6 }, /* index 152  */
286 { 6,  2,  1,  580,  0,  2,  2,  6 }, /* index 153  */
287 { 6,  2,  0,    2,  0,  2,  2,  6 }, /* index 154  */
288 { 6,  2,  0,   16,  0,  2,  2,  6 }, /* index 155  */
289 { 6,  2,  0,  128,  0,  2,  2,  6 }, /* index 156  */
290 { 6,  1,  0,   16,  0,  1,  2,  6 }, /* index 157  */
291 { 6,  1,  0,   66,  0,  1,  2,  6 }, /* index 158  */
292 { 6,  1,  0,  528,  0,  1,  2,  6 }, /* index 159  */
293 { 6,  1,  0,    2,  0,  2,  2,  6 }, /* index 160  */
294 { 6,  1,  0,  128,  0,  2,  2,  6 }, /* index 161  */
295 { 6,  1,  0,  132,  0,  2,  2,  6 }, /* index 162  */
296 { 6,  1,  0,  146,  0,  2,  2,  6 }, /* index 163  */
297 { 6,  1,  0,  341,  0,  2,  2,  6 }, /* index 164  */
298 { 6,  1,  0, 1023,  0,  2,  2,  6 }, /* index 165  */
299 { 6,  1,  0,  682,  0,  2,  2,  6 }, /* index 166  */
300 {13,  2,  1,  580,  0,  2,  2,  6 }, /* index 167  */
301 {13,  2,  0,   16,  0,  2,  2,  6 }, /* index 168  */
302 {13,  1,  0,   16,  0,  1,  2,  6 }, /* index 169  */
303 {13,  1,  0,   66,  0,  1,  2,  6 }, /* index 170  */
304 {13,  1,  0,  528,  0,  1,  2,  6 }, /* index 171  */
305 {13,  1,  0,    2,  0,  2,  2,  6 }, /* index 172  */
306 {13,  1,  0,  128,  0,  2,  2,  6 }, /* index 173  */
307 {13,  1,  0,  146,  0,  2,  2,  6 }, /* index 174  */
308 {13,  1,  0,  341,  0,  2,  2,  6 }, /* index 175  */
309 {13,  1,  0, 1023,  0,  2,  2,  6 }, /* index 176  */
310 { 7, 16,  0,  528,  0,  1,  7,  2 }, /* index 177  */
311 { 7, 16,  1,   16,  0,  2,  7,  2 }, /* index 178  */
312 { 7,  8,  0,  528,  0,  1,  7,  2 }, /* index 179  */
313 { 7,  8,  1,   16,  0,  2,  7,  2 }, /* index 180  */
314 { 7,  4,  0,  528,  0,  1,  7,  2 }, /* index 181  */
315 { 7,  4,  1,  528,  0,  1,  7,  2 }, /* index 182  */
316 { 7,  4,  0,   16,  0,  2,  7,  2 }, /* index 183  */
317 { 7,  2,  0,  528,  0,  1,  7,  2 }, /* index 184  */
318 { 7,  2,  0,    2,  0,  2,  7,  2 }, /* index 185  */
319 { 7,  2,  0,   16,  0,  2,  7,  2 }, /* index 186  */
320 { 7,  2,  0,  128,  0,  2,  7,  2 }, /* index 187  */
321 { 7,  1,  0,   16,  0,  1,  7,  2 }, /* index 188  */
322 { 7,  1,  0,   66,  0,  1,  7,  2 }, /* index 189  */
323 { 7,  1,  0,  528,  0,  1,  7,  2 }, /* index 190  */
324 { 7,  1,  0,    2,  0,  2,  7,  2 }, /* index 191  */
325 { 7,  1,  0,  128,  0,  2,  7,  2 }, /* index 192  */
326 { 7,  1,  0,  132,  0,  2,  7,  2 }, /* index 193  */
327 { 7,  1,  0,  146,  0,  2,  7,  2 }, /* index 194  */
328 { 7,  1,  0,  341,  0,  2,  7,  2 }, /* index 195  */
329 { 7,  1,  0, 1023,  0,  2,  7,  2 }, /* index 196  */
330 { 7,  1,  0,  682,  0,  2,  7,  2 }, /* index 197  */
331 { 8, 16,  0,  528,  0,  2,  1, 12 }, /* index 198  */
332 { 8, 16,  1,   16,  0,  2,  1, 12 }, /* index 199  */
333 { 8,  8,  0,  528,  0,  2,  1, 12 }, /* index 200  */
334 { 8,  8,  1,   16,  0,  2,  1, 12 }, /* index 201  */
335 { 8,  4,  0,  528,  0,  2,  1, 12 }, /* index 202  */
336 { 8,  4,  0,   16,  0,  2,  1, 12 }, /* index 203  */
337 { 8,  4,  1,  528,  0,  2,  1, 12 }, /* index 204  */
338 { 8,  2,  0,  528,  0,  2,  1, 12 }, /* index 205  */
339 { 8,  2,  0,    2,  0,  2,  1, 12 }, /* index 206  */
340 { 8,  2,  0,   16,  0,  2,  1, 12 }, /* index 207  */
341 { 8,  2,  0,  128,  0,  2,  1, 12 }, /* index 208  */
342 { 8,  1,  0,    2,  0,  2,  1, 12 }, /* index 209  */
343 { 8,  1,  0,   16,  0,  2,  1, 12 }, /* index 210  */
344 { 8,  1,  0,  128,  0,  2,  1, 12 }, /* index 211  */
345 { 8,  1,  0,   66,  0,  2,  1, 12 }, /* index 212  */
346 { 8,  1,  0,  132,  0,  2,  1, 12 }, /* index 213  */
347 { 8,  1,  0,  528,  0,  2,  1, 12 }, /* index 214  */
348 { 8,  1,  0,  146,  0,  2,  1, 12 }, /* index 215  */
349 { 8,  1,  0,  341,  0,  2,  1, 12 }, /* index 216  */
350 { 8,  1,  0, 1023,  0,  2,  1, 12 }, /* index 217  */
351 { 8,  1,  0,  682,  0,  2,  1, 12 }, /* index 218  */
352 { 9,  8,  1,   16,  0,  2,  7,  2 }, /* index 219  */
353 { 9,  4,  1,  528,  0,  1,  7,  2 }, /* index 220  */
354 { 9,  4,  0,   16,  0,  2,  7,  2 }, /* index 221  */
355 { 9,  2,  0,  528,  0,  1,  7,  2 }, /* index 222  */
356 { 9,  2,  0,    2,  0,  2,  7,  2 }, /* index 223  */
357 { 9,  2,  0,   16,  0,  2,  7,  2 }, /* index 224  */
358 { 9,  2,  0,  128,  0,  2,  7,  2 }, /* index 225  */
359 { 9,  1,  0,   16,  0,  1,  7,  2 }, /* index 226  */
360 { 9,  1,  0,   66,  0,  1,  7,  2 }, /* index 227  */
361 { 9,  1,  0,  528,  0,  1,  7,  2 }, /* index 228  */
362 { 9,  1,  0,    2,  0,  2,  7,  2 }, /* index 229  */
363 { 9,  1,  0,  128,  0,  2,  7,  2 }, /* index 230  */
364 { 9,  1,  0,  132,  0,  2,  7,  2 }, /* index 231  */
365 { 9,  1,  0,  146,  0,  2,  7,  2 }, /* index 232  */
366 { 9,  1,  0,  341,  0,  2,  7,  2 }, /* index 233  */
367 { 9,  1,  0, 1023,  0,  2,  7,  2 }, /* index 234  */
368 { 9,  1,  0,  682,  0,  2,  7,  2 }, /* index 235  */
369 {10, 16,  1,  528,  0,  1,  2,  6 }, /* index 236  */
370 {10, 16,  1,   16,  0,  2,  2,  6 }, /* index 237  */
371 {10,  8,  1,  528,  0,  1,  2,  6 }, /* index 238  */
372 {10,  8,  1,   16,  0,  2,  2,  6 }, /* index 239  */
373 {10,  4,  0,  528,  0,  1,  2,  6 }, /* index 240  */
374 {10,  4,  0,   16,  0,  2,  2,  6 }, /* index 241  */
375 {10,  2,  1,  580,  0,  2,  2,  6 }, /* index 242  */
376 {10,  2,  0,    2,  0,  2,  2,  6 }, /* index 243  */
377 {10,  2,  0,   16,  0,  2,  2,  6 }, /* index 244  */
378 {10,  2,  0,  128,  0,  2,  2,  6 }, /* index 245  */
379 {10,  1,  0,   16,  0,  1,  2,  6 }, /* index 246  */
380 {10,  1,  0,   66,  0,  1,  2,  6 }, /* index 247  */
381 {10,  1,  0,  528,  0,  1,  2,  6 }, /* index 248  */
382 {10,  1,  0,    2,  0,  2,  2,  6 }, /* index 249  */
383 {10,  1,  0,  128,  0,  2,  2,  6 }, /* index 250  */
384 {10,  1,  0,  132,  0,  2,  2,  6 }, /* index 251  */
385 {10,  1,  0,  146,  0,  2,  2,  6 }, /* index 252  */
386 {10,  1,  0,  341,  0,  2,  2,  6 }, /* index 253  */
387 {10,  1,  0, 1023,  0,  2,  2,  6 }, /* index 254  */
388 {10,  1,  0,  682,  0,  2,  2,  6 }  /* index 255  */
389 };
390
391 /* Defintion of delta value Table 6.1.2.1.1-5 spec 38.214 */
392 uint8_t puschDeltaTable[MAX_MU_PUSCH] = { 2, 3, 4, 6 };
393
394 uint16_t tbSizeTable[TOTAL_TBSIZE_VALUES] = {
395          24,    32,    40,    48,    56,    64,    72,    80,    88,    96, \
396         104,   112,   120,   128,   136,   144,   152,   160,   168,   176, \
397         184,   192,   208,   224,   240,   256,   272,   288,   304,   320, \
398         336,   352,   368,   384,   408,   432,   456,   480,   504,   528, \
399         552,   576,   608,   640,   672,   704,   736,   768,   808,   848, \
400         888,   928,   984,  1032,  1064,  1128,  1160,  1192,  1224,  1256, \
401        1288,  1320,  1352,  1416,  1480,  1544,  1608,  1672,  1736,  1800, \
402        1864,  1928,  2024,  2088,  2152,  2216,  2280,  2408,  2472,  2536, \
403        2600,  2664,  2728,  2792,  2856,  2976,  3104,  3240,  3368,  3496, \
404        3624,  3752,  3824 };
405
406 uint16_t mcsTable[32][3] = {
407       {   0,   2,   120},   /* mcs index  0 */ 
408       {   1,   2,   157},   /* mcs index  1 */ 
409       {   2,   2,   193},   /* mcs index  2 */ 
410       {   3,   2,   251},   /* mcs index  3 */ 
411       {   4,   2,   308},   /* mcs index  4 */ 
412       {   5,   2,   379},   /* mcs index  5 */ 
413       {   6,   2,   449},   /* mcs index  6 */ 
414       {   7,   2,   526},   /* mcs index  7 */ 
415       {   8,   2,   602},   /* mcs index  8 */ 
416       {   9,   2,   679},   /* mcs index  9 */ 
417       {  10,   4,   340},   /* mcs index 10 */ 
418       {  11,   4,   378},   /* mcs index 11 */ 
419       {  12,   4,   434},   /* mcs index 12 */ 
420       {  13,   4,   490},   /* mcs index 13 */ 
421       {  14,   4,   553},   /* mcs index 14 */ 
422       {  15,   4,   616},   /* mcs index 15 */
423       {  16,   4,   658},   /* mcs index 16 */
424       {  17,   6,   438},   /* mcs index 17 */
425       {  18,   6,   466},   /* mcs index 18 */
426       {  19,   6,   517},   /* mcs index 19 */
427       {  20,   6,   567},   /* mcs index 20 */
428       {  21,   6,   616},   /* mcs index 21 */
429       {  22,   6,   666},   /* mcs index 22 */
430       {  23,   6,   719},   /* mcs index 23 */
431       {  24,   6,   772},   /* mcs index 24 */
432       {  25,   6,   822},   /* mcs index 25 */
433       {  26,   6,   873},   /* mcs index 26 */
434       {  27,   6,   910},   /* mcs index 27 */
435       {  28,   6,   948},   /* mcs index 28 */
436       {  29,   2,     0},   /* mcs index 29 */
437       {  30,   4,     0},   /* mcs index 30 */
438       {  31,   6,     0}};  /* mcs index 31 */
439
440 /* PUCCH resource sets before dedicated PUCCH resource configuration */
441 /* Table 9.2.1-1 spec 38.213      */ 
442 uint8_t pucchResourceSet[MAX_PUCCH_RES_SET_IDX][4] = {
443 { 0,  12,  2,  0 }, /* index  0 */
444 { 0,  12,  2,  0 }, /* index  1 */
445 { 0,  12,  2,  3 }, /* index  2 */
446 { 1,  10,  4,  0 }, /* index  3 */
447 { 1,  10,  4,  0 }, /* index  4 */
448 { 1,  10,  4,  2 }, /* index  5 */
449 { 1,  10,  4,  4 }, /* index  6 */
450 { 1,   4, 10,  0 }, /* index  7 */
451 { 1,   4, 10,  0 }, /* index  8 */
452 { 1,   4, 10,  2 }, /* index  9 */
453 { 1,   4, 10,  4 }, /* index 10 */
454 { 1,   0, 14,  0 }, /* index 11 */
455 { 1,   0, 14,  0 }, /* index 12 */
456 { 1,   0, 14,  2 }, /* index 13 */
457 { 1,   0, 14,  4 }, /* index 14 */
458 { 1,   0, 14,  0 }, /* index 15 */
459 };
460
461 /**
462  * @brief frequency domain allocation function. 
463  *
464  * @details
465  *
466  *     Function: schCalcTbSize
467  *     
468  *     This function finds the TBSize from table Table 5.1.3.2-1 spec 38.214
469  *     
470  *  @param[in]  payLoadSize - size of payload in bytes
471  *  @return     TBsize from the Table in bytes
472  **/
473 uint16_t schCalcTbSize(uint16_t payLoadSize)
474 {
475    uint8_t tbsIndex = 0;
476    payLoadSize = payLoadSize*8;
477
478    while(payLoadSize > tbSizeTable[tbsIndex])
479    {
480       tbsIndex++;
481    }
482
483    /* return the TBsize in bytes */
484    return (tbSizeTable[tbsIndex]/8);
485 }
486
487 /**
488  * @brief frequency domain allocation function. 
489  *
490  * @details
491  *
492  *     Function: schCalcNumPrb
493  *     
494  *     This function calculates the number of PRbs 
495  *     
496  *  @param[in]  tbSize in bytes
497  *  @param[in]  mcs
498  *  @param[in]  number of symbols
499  *  @return   number PRBs
500  **/
501 uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols)
502 {
503    uint16_t numPrb = 0;
504    uint16_t nre = 0;
505    uint16_t nreDash = 0;
506    uint8_t  qm     = mcsTable[mcs][1];
507    uint16_t rValue = mcsTable[mcs][2];
508    uint8_t  numLayer = 1;       /* v value */
509
510    tbSize = tbSize * 8; //Calculate tbSize in bits
511
512    /* formula used for calculation of rbSize, 38.213 section 5.1.3.2 *
513     * Ninfo = Nre . R . Qm . v                                       *
514     * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh                       *
515     * Nre = min(156,Nre') . nPrb                                     */
516
517    nre = ceil( (float)tbSize * 1024 / (qm * rValue * numLayer));
518
519    nreDash = ceil( (12 * numSymbols) - NUM_DMRS_SYMBOLS - 0);
520
521    if (nreDash > 156)
522       nre = 156;
523
524    numPrb = ceil((float)nre / nreDash);   
525    return numPrb;
526 }
527
528 /**
529  * @brief fetching ueCb from cellCb
530  *
531  * @details
532  *
533  *     Function: schGetUeCb
534  *
535  *     This function fetched UeCb based on crnti from cellCb
536  *
537  *  @param[in]  cellCb
538  *  @param[in]  crnti
539  *  @return     ueCb
540  **/
541 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti)
542 {
543    uint16_t ueIdx;
544    GET_UE_IDX(crnti, ueIdx);
545    return &(cellCb->ueCb[ueIdx -1]);
546 }
547
548 /**
549  * @brief initialize UL slot info
550  *
551  * @details
552  *
553  *     Function: schInitUlSlot
554  *
555  *     This function intializes UL slot of the cell
556  *
557  *  @param[in]  schUlSlotInfo
558  *  @return     void
559  **/
560 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo)
561 {
562    memset(schUlSlotInfo, 0, sizeof(SchUlSlotInfo));
563    schUlSlotInfo->totalPrb = MAX_NUM_RB;
564    for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
565    {
566       schUlSlotInfo->assignedPrb[itr] = 0;
567    }
568    schUlSlotInfo->puschCurrentPrb = PUSCH_START_RB;
569    schUlSlotInfo->schPuschInfo = NULLP;
570
571 }
572
573 /**
574  * @brief initialize DL slot info
575  *
576  * @details
577  *
578  *     Function: schInitDlSlot
579  *
580  *     This function intializes DL slot of the cell
581  *
582  *  @param[in]  schDlSlotInfo
583  *  @return     void
584  **/
585 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo)
586 {
587    memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
588    schDlSlotInfo->totalPrb = MAX_NUM_RB;
589    for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
590    {
591       schDlSlotInfo->assignedPrb[itr] = 0;
592    }
593   
594    for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
595    {
596       memset(&schDlSlotInfo->ssbInfo[itr], 0, sizeof(SsbInfo));
597    }
598
599
600 }
601 /**********************************************************************
602          End of file
603 **********************************************************************/