Merge "MAC SCH interface for RACH config"
[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  * @brief frequency domain allocation function. 
81  *
82  * @details
83  *
84  *     Function : freqDomResourceAlloc
85  *     
86  *     This function does allocation in frequency domain resource. using 
87  *     bitwise operator, the bits are set for the PRBs.
88  *     
89  *  @param[in]  startPrb - start PRB from where the freq alloc starts.  
90  *  @param[in]  prbSize - number of PRBs to be allocted.
91  *  @param[in]  freqDomain - 6 bytes of info, each bit represents a group of 6 PRB.
92  *  @return   void
93  **/
94 void freqDomResourceAlloc(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain)
95 {
96    uint8_t remBits = prbSize; /* each bit represents 6 PRBs */
97    uint8_t firstByte = 1;
98    uint8_t numBits,startBit,byteCount = 0;
99
100    while(remBits)
101    {
102       /* when the startPrb is not in this byteCount */
103       if(startPrb/8)
104       {
105          startPrb -= 8;
106          byteCount++;
107          continue;
108       }
109
110       /* max bytecount is 6 nearly equal to 45 bits*/
111       if(byteCount >= 6)
112           break;
113
114       /* when we are filling the second byte, then the start should be equal to 0 */
115       if(firstByte)
116          startBit = startPrb;
117       else
118          startBit = 0;
119
120       /* calculate the number of bits to be set in this byte */
121       if((remBits+startPrb) <= 8)
122          numBits = remBits;
123       else
124          numBits = 8 - startBit;
125
126       /* bit operation to set the bits */
127                 SET_BITS((startBit % 8),numBits,freqDomain[byteCount])
128       firstByte = 0;
129
130       /* the ramaining bits should be subtracted with the numBits set in this byte */
131       remBits -= numBits;
132       byteCount++;
133    }
134 }
135
136 /**********************************************************************
137          End of file
138 **********************************************************************/