1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /* This file contains all utility functions for MAC CL */
21 #include "common_def.h"
24 /*******************************************************************
26 * @brief Fetch cellCb from Hash list
30 * Function : rgClUtlGetCellCb
33 * - Searches for a cell entry at MAC CL
36 * @return Pointer to cellCb - success
39 * ****************************************************************/
40 LwrMacCellCb * lwrMacGetCellCb
47 if(cellId >= MAX_NUM_CELL)
49 DU_LOG("\nERROR --> Invalid Cell Id [%d]. rgClUtlGetCellCb failed.", cellId);
53 cellCb = &lwrMacCb.cellCb[cellId -1];
58 /*******************************************************************
60 * @brief Reverses bits in a number
64 * Function : reverseBits
67 * Reverses bits in a number
69 * @params[in] Number to be reversed
70 * Number of bits to be reversed
71 * @return Reversed number
73 * ****************************************************************/
74 uint32_t reverseBits(uint32_t num, uint8_t numBits)
76 uint32_t reverse_num = 0;
78 for (bitIdx = 0; bitIdx < numBits; bitIdx++)
80 if((num & (1 << bitIdx)))
81 reverse_num |= 1 << ((numBits - 1) - bitIdx);
86 /*******************************************************************
88 * @brief Fills DL DCI payload byte by byte
92 * Function : fillDlDciPayload
95 * Fills DL DCI payload byte by byte
97 * @params[in] Payload buffer pointer
98 * Current Byte position in buffer
99 * Current Bit Position in current byte
101 * Number of bits in value
104 * ****************************************************************/
106 void fillDlDciPayload(uint8_t *buf, uint8_t *bytePos, uint8_t *bitPos,\
107 uint32_t val, uint8_t valSize)
112 uint8_t bytePart1Size;
113 uint8_t bytePart2Size;
115 if(*bitPos + valSize <= 8)
117 bytePart1 = (uint8_t)val;
118 bytePart1 = (~((~0) << valSize)) & bytePart1;
119 buf[*bytePos] |= bytePart1;
122 else if(*bitPos + valSize > 8)
125 bytePart1Size = 8 - *bitPos;
126 bytePart2Size = valSize - bytePart1Size;
128 bytePart1 = ((~((~0) << bytePart1Size)) & temp) << *bitPos;
129 bytePart2 = val >> bytePart1Size;
131 buf[*bytePos] |= bytePart1;
134 fillDlDciPayload(buf, bytePos, bitPos, bytePart2, bytePart2Size);
140 * Frequency domain resources is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
141 * [TS38.213 10.1]. Bitmap of uint8 array. 45 bits.
144 * CORESET-freqdom.frequencyDomainResources : The bits of the bitmap have a one-to-one mapping with
145 * non-overlapping groups of 6 RBs. The most significant bit of the first word corresponds to
146 * the most significant bit defined in 38.331.
148 * FAPI and IAPI both are 45 bits. Mapped from bit 0 LS Byte for the FAPI and
149 * bit 0 LS U32 entry for IAPI.
150 * FAPI is to be filled in following format such that Intel L1 is able to decode it :
153 * FreqDomainResource[0] bits 7-0 -> nFreqDomain[0] bits 7-0
154 * FreqDomainResource[1] bits 7-0 -> nFreqDomain[0] bits 15-8
155 * FreqDomainResource[2] bits 7-0 -> nFreqDomain[0] bits 23-16
156 * FreqDomainResource[3] bits 7-0 -> nFreqDomain[0] bits 31-24
157 * FreqDomainResource[4] bits 7-0 -> nFreqDomain[1] bits 7-0
158 * FreqDomainResource[5] bits 7-0 -> nFreqDomain[1] bits 15-8
160 * where for the last entry bits 7,6 and 5 are don't care in the FAPI and bits
161 * 31-13 are don't care in the IAPI.
163 void convertFreqDomRsrcMapToIAPIFormat(uint8_t *sourceBitMap, uint8_t *destBitMap)
166 uint8_t numBitsToShift = 0;
167 uint64_t freqDomainResources = 0;
169 /* Bit operation to create a 64-bit integer that has
170 * 48 LSBs [Bit 47 to Bit 0] mapped to sourceBitMap[0] to sourceBitMap[5]
172 for(idx = FREQ_DOM_RSRC_SIZE-1; idx >=0; idx--)
174 freqDomainResources |= ((uint64_t)sourceBitMap[idx] << numBitsToShift);
178 /* Right shift 3 bits because bits[2-0] are unused in sourceBitMap[5] */
179 freqDomainResources = freqDomainResources >> 3;
181 /* Filling destBitMap such that LSB bit 0 of freqDomainResources maps to LSB
182 * of first word of destBitMap */
184 for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
186 destBitMap[idx] = freqDomainResources >> numBitsToShift;
191 /**********************************************************************
193 **********************************************************************/