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