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 #include "common_def.h"
22 * @brief frequency domain allocation function.
26 * Function: fillCoresetFeqDomAllocMap
28 * This function does allocation in frequency domain resource.
29 * This is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
31 * @param[in] startPrb - start PRB from where the freq alloc starts.
32 * @param[in] prbSize - number of PRBs to be allocted.
33 * @param[in] freqDomain - 6 bytes of info, each bit represents a group of 6 PRB.
36 void fillCoresetFeqDomAllocMap(uint16_t startPrbGrp, uint16_t numPrbGrp, uint8_t *freqDomain)
39 uint8_t prbGrpStartBit = 0;
40 uint8_t numBitsToRightShift = 0;
42 uint64_t freqAllocBitMap = 0;
45 * Frequency allocation bit string is 45 bits long. Hence using 6 bytes (i.e. 48 bits) to represent it.
46 * Each bit corresponds to a group of 6 RBs.
48 * For example if a coreset includes PRB 24 to 47, then on dividing the PRBs into group of 6,
49 * startPrbGrp = 24/6 = 4
50 * numPrbGrp = 24/6 = 4
52 * Frequency allocation bit string is 48 bits long i.e. Bit 47...0
53 * Here, Bit 47 represents RB group 0, Bit 46 represent RB group 45 and so on.
54 * Since startPrbGrp = 4 and numPrbGrp = 4, it means RB group 4,5,6 and 7 are used in coreset.
55 * i.e. Bits 43, 42, 42 and 40 are masked to 1 and rest all bits are 0 in bitstring
61 printf("startPrbGrp [%d] numPrbGrp [%d] diff [%d]\n",startPrbGrp, numPrbGrp, (prbGrpStartBit - startPrbGrp));
62 mask = mask << (prbGrpStartBit - startPrbGrp);
63 freqAllocBitMap = freqAllocBitMap | mask;
68 /* Copying 48 LSBs from 64-bit integer to the 45 MSBS in 6-byte array
69 * The first (left-most / most significant) bit corresponds to the first RB
70 * group in the BWP, and so on
72 /* On right shifting freqAllocBitMap by 40 bits, the bits 47 to 40 of freqAllocBitMap
73 * will now become 8-LSB. Copying these 8-bits into freqDomain[].
74 * Now shifting freqAllocBitMap by 32 bits, the bit 39 to 32 of freqAllocBitMap will
75 * now become 8-LSB. Copying these 8-bits into next index of freqDomain.
78 numBitsToRightShift = 40;
79 mask = 0x0000FF0000000000;
80 for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
82 freqDomain[idx] = (freqAllocBitMap & mask) >> numBitsToRightShift;
83 numBitsToRightShift -= 8;
88 /*******************************************************************
90 * @brief Reverse and copy fixed buffer to mBuf
94 * Function : oduCpyFixBufToMsg
96 * Functionality: Reverse and copy fixed buffer to mBuf
98 * @params[in] Fixed buffer, msg buffer, length of message
99 * @return ROK - success
102 * ****************************************************************/
103 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len)
105 uint16_t idx = 0, revIdx = 0, temp = 0, copyLen = 0;
107 /* ODU_COPY_FIX_BUF_TO_MSG copies fixed buffer in reverse order. \
108 * Hence reversing the fixed buffer before copying in order to \
109 * maintain the actual order*/
110 for(idx = 0, revIdx = len-1; idx < len/2; idx++, revIdx--)
113 fixBuf[idx] = fixBuf[revIdx];
114 fixBuf[revIdx] = temp;
116 ODU_COPY_FIX_BUF_TO_MSG(fixBuf, mBuf, 0, len, (MsgLen *)©Len);
119 /*******************************************************************
121 * @brief Builds PLMN ID
125 * Function : plmnBuildId
127 * Functionality: Building the PLMN ID
129 * @params[in] PLMNID plmn
130 * @params[out] PLMNID in string format
131 * @return ROK - success
134 * ****************************************************************/
135 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf)
139 buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
142 buf[1] = ((0xf0) | (plmn.mcc[2]));
143 buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
147 buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
148 buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
153 /*******************************************************************
155 * @brief SGetSBuf with debug logs
159 * Function : SGetSBufNewForDebug
161 * Functionality: SGetSBuf with debug logs
163 * @params[in] file name, fun name, region, pool, data ptr, size
165 * @return ROK - success
168 * ****************************************************************/
169 uint8_t SGetSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data **ptr, Size size)
171 if(SGetSBuf(region, pool, ptr, size) == ROK)
173 #ifdef ODU_MEMORY_DEBUG_LOG
174 printf("\nCM_ALLOC=== SGetSBufNewForDebug %s +%d, %s, %d, %p\n",\
175 file, line, func, size, *ptr);
183 /*******************************************************************
185 * @brief SPutSBuf with debug logs
189 * Function : SPutSBufNewForDebug
191 * Functionality: SPutSBuf with debug logs
193 * @params[in] file name, fun name, region, pool, data ptr, size
195 * @return ROK - success
198 * ****************************************************************/
199 uint8_t SPutSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data *ptr, Size size)
201 if(SPutSBuf(region, pool, ptr, size) == ROK)
203 #ifdef ODU_MEMORY_DEBUG_LOG
204 printf("\nCM_FREE=== SPutSBufNewForDebug %s +%d, %s, %d, %p\n",\
205 file, line, func, size, ptr);
214 /*******************************************************************
216 * @brief SGetStaticBuf with debug logs
220 * Function : SGetStaticBufNewForDebug
222 * Functionality: SGetStaticBuf with debug logs
224 * @params[in] file name, fun name, region, pool, data ptr, size, memType
226 * @return ROK - success
229 * ****************************************************************/
230 uint8_t SGetStaticBufNewForDebug(char *file, char *func, char *line, \
231 Region region, Pool pool, Data **ptr, Size size, uint8_t memType)
233 if(SGetStaticBuffer(region, pool, ptr, size, memType) == ROK)
235 #ifdef ODU_MEMORY_DEBUG_LOG
236 printf("\nCM_ALLOC=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p\n",\
237 file, line, func, size, *ptr);
245 /*******************************************************************
247 * @brief SPutStaticBuf with debug logs
251 * Function : SPutStaticBufNewForDebug
253 * Functionality: SPutStaticBuf with debug logs
255 * @params[in] file name, fun name, region, pool, data ptr, size, memType
257 * @return ROK - success
260 * ****************************************************************/
261 uint8_t SPutStaticBufNewForDebug(char *file, char *func, char *line, \
262 Region region, Pool pool, Data *ptr, Size size, uint8_t memType)
264 if(SPutStaticBuffer(region, pool, ptr, size, memType) == ROK)
266 #ifdef ODU_MEMORY_DEBUG_LOG
267 printf("\nCM_FREE=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p\n",\
268 file, line, func, size, ptr);
275 /**********************************************************************
277 **********************************************************************/