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