7071432acbf1ed3df59b61414ac2118ad3315fca
[o-du/l2.git] / src / 5gnrmac / lwr_mac_util.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 /* This file contains all utility functions for MAC CL */
20
21 #include "stdio.h"
22 #include "envopt.h"
23 #include "envdep.h"
24 #include "envind.h"
25 #include "gen.h"
26 #include "ssi.h"
27 #include "cm_hash.h"
28 #include "gen.x"
29 #include "ssi.x"
30 #include "cm_hash.x"
31 #include "lwr_mac.h"
32
33  /*******************************************************************
34   *
35   * @brief Fetch cellCb from Hash list
36   *
37   * @details
38   *
39   *    Function : rgClUtlGetCellCb
40   *
41   *    Functionality:
42   *       - Searches for a cell entry at MAC CL 
43   *
44   * @params[in] cell Id
45   * @return Pointer to cellCb - success
46   *         NULLP - failure
47   *
48   * ****************************************************************/
49 PUBLIC ClCellCb * rgClUtlGetCellCb
50 (
51    U16 cellId
52 )
53 {
54    ClCellCb *cellCb;
55
56    if(cellId >= MAX_NUM_CELL_SUPP)
57    {
58       printf("\n Invalid Cell Id [%d]. rgClUtlGetCellCb failed.", cellId);
59       RETVALUE(NULLP);
60    }
61
62    cmHashListFind((CmHashListCp *)&clGlobalCp.cellCbLst, (U8 *)&cellId, sizeof(U16), 0, (PTR *)&cellCb);
63    
64    RETVALUE(cellCb);
65 }
66
67 /*******************************************************************
68  *
69  * @brief Reverses bits in a number
70  *
71  * @details
72  *
73  *    Function : reverseBits
74  *
75  *    Functionality:
76  *      Reverses bits in a number
77  *
78  * @params[in] Number to be reversed
79  *             Number of bits to be reversed
80  * @return Reversed number
81  *
82  * ****************************************************************/
83 uint32_t reverseBits(uint32_t num, uint8_t numBits)
84 {
85    uint32_t reverse_num = 0;
86    int i;
87    for (i = 0; i < numBits; i++)
88    {
89       if((num & (1 << i)))
90          reverse_num |= 1 << ((numBits - 1) - i);
91    }
92    return reverse_num;
93 }
94
95 /*******************************************************************
96  *
97  * @brief Fills DL DCI payload byte by byte
98  *
99  * @details
100  *
101  *    Function : fillDlDciPayload
102  *
103  *    Functionality:
104  *      Fills DL DCI payload byte by byte
105  *
106  * @params[in] Payload buffer pointer
107  *             Current Byte position in buffer
108  *             Current Bit Position in current byte
109  *             Value to be filled
110  *             Number of bits in value
111  * @return void
112  *
113  * ****************************************************************/
114
115 void fillDlDciPayload(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos,\
116    uint32_t val, uint8_t valSize)
117 {
118    uint8_t temp;
119    uint8_t bytePart1;
120    uint32_t bytePart2;
121    uint8_t bytePart1Size;
122    uint8_t bytePart2Size;
123
124    if(*bitPos + valSize <= 8)
125    {
126       bytePart1 = (uint8_t)val;
127       bytePart1 = (~((~0) << valSize)) & bytePart1;
128       buf[*bytePos] |= bytePart1;
129       *bitPos += valSize;
130    }
131    else if(*bitPos + valSize > 8)
132    {
133       temp = (uint8_t)val;
134       bytePart1Size = 8 - *bitPos;
135       bytePart2Size = valSize - bytePart1Size;
136
137       bytePart1 = ((~((~0) << bytePart1Size)) & temp) << *bitPos;
138       bytePart2 = val >> bytePart1Size;
139
140       buf[*bytePos] |= bytePart1;
141       (*bytePos)--;
142       *bitPos = 0;
143       fillDlDciPayload(buf, bytePos, bitPos, bytePart2, bytePart2Size);
144    }
145 }
146
147
148
149 /**********************************************************************
150          End of file
151 **********************************************************************/