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 mask = mask << (prbGrpStartBit - startPrbGrp);
62 freqAllocBitMap = freqAllocBitMap | mask;
67 /* Copying 48 LSBs from 64-bit integer to the 45 MSBS in 6-byte array
68 * The first (left-most / most significant) bit corresponds to the first RB
69 * group in the BWP, and so on
71 /* On right shifting freqAllocBitMap by 40 bits, the bits 47 to 40 of freqAllocBitMap
72 * will now become 8-LSB. Copying these 8-bits into freqDomain[].
73 * Now shifting freqAllocBitMap by 32 bits, the bit 39 to 32 of freqAllocBitMap will
74 * now become 8-LSB. Copying these 8-bits into next index of freqDomain.
77 numBitsToRightShift = 40;
78 mask = 0x0000FF0000000000;
79 for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
81 freqDomain[idx] = (freqAllocBitMap & mask) >> numBitsToRightShift;
82 numBitsToRightShift -= 8;
87 /*******************************************************************
89 * @brief Reverse and copy fixed buffer to mBuf
93 * Function : oduCpyFixBufToMsg
95 * Functionality: Reverse and copy fixed buffer to mBuf
97 * @params[in] Fixed buffer, msg buffer, length of message
98 * @return ROK - success
101 * ****************************************************************/
102 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len)
104 uint16_t idx = 0, revIdx = 0, temp = 0, copyLen = 0;
106 /* ODU_COPY_FIX_BUF_TO_MSG copies fixed buffer in reverse order. \
107 * Hence reversing the fixed buffer before copying in order to \
108 * maintain the actual order*/
109 for(idx = 0, revIdx = len-1; idx < len/2; idx++, revIdx--)
112 fixBuf[idx] = fixBuf[revIdx];
113 fixBuf[revIdx] = temp;
115 ODU_COPY_FIX_BUF_TO_MSG(fixBuf, mBuf, 0, len, (MsgLen *)©Len);
118 /*******************************************************************
120 * @brief Builds PLMN ID
124 * Function : plmnBuildId
126 * Functionality: Building the PLMN ID
128 * @params[in] PLMNID plmn
129 * @params[out] PLMNID in string format
130 * @return ROK - success
133 * ****************************************************************/
134 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf)
138 buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
141 buf[1] = ((0xf0) | (plmn.mcc[2]));
142 buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
146 buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
147 buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
152 /*******************************************************************
154 * @brief Function to map Sub carrier spacing enum value to value in kHz
158 * Function : fetchScsValue
161 * Function to map Sub carrier spacing enum value to value in kHz
163 * @params[in] sub-carrier spacing enum value
164 * @return sub-carrier spacing value in kHz
166 * ****************************************************************/
167 uint16_t fetchScsValue(uint8_t scsEnumValue)
176 return (15 * pow(2,scsEnumValue));
182 /*******************************************************************
184 * @brief SGetSBuf with debug logs
188 * Function : SGetSBufNewForDebug
190 * Functionality: SGetSBuf with debug logs
192 * @params[in] file name, fun name, region, pool, data ptr, size
194 * @return ROK - success
197 * ****************************************************************/
198 uint8_t SGetSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data **ptr, Size size)
200 if(SGetSBuf(region, pool, ptr, size) == ROK)
202 #ifdef ODU_MEMORY_DEBUG_LOG
203 if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
205 printf("\nCM_ALLOC=== SGetSBufNewForDebug %s +%d, %s, %d, %p\n",\
206 file, line, func, size, *ptr);
215 /*******************************************************************
217 * @brief SPutSBuf with debug logs
221 * Function : SPutSBufNewForDebug
223 * Functionality: SPutSBuf with debug logs
225 * @params[in] file name, fun name, region, pool, data ptr, size
227 * @return ROK - success
230 * ****************************************************************/
231 uint8_t SPutSBufNewForDebug(char *file, char *func, char *line, Region region, Pool pool, Data *ptr, Size size)
233 if(SPutSBuf(region, pool, ptr, size) == ROK)
235 #ifdef ODU_MEMORY_DEBUG_LOG
236 if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
238 printf("\nCM_FREE=== SPutSBufNewForDebug %s +%d, %s, %d, %p\n",\
239 file, line, func, size, ptr);
249 /*******************************************************************
251 * @brief SGetStaticBuf with debug logs
255 * Function : SGetStaticBufNewForDebug
257 * Functionality: SGetStaticBuf with debug logs
259 * @params[in] file name, fun name, region, pool, data ptr, size, memType
261 * @return ROK - success
264 * ****************************************************************/
265 uint8_t SGetStaticBufNewForDebug(char *file, char *func, char *line, \
266 Region region, Pool pool, Data **ptr, Size size, uint8_t memType)
268 if(SGetStaticBuffer(region, pool, ptr, size, memType) == ROK)
270 #ifdef ODU_MEMORY_DEBUG_LOG
271 printf("\nCM_ALLOC=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p\n",\
272 file, line, func, size, *ptr);
280 /*******************************************************************
282 * @brief SPutStaticBuf with debug logs
286 * Function : SPutStaticBufNewForDebug
288 * Functionality: SPutStaticBuf with debug logs
290 * @params[in] file name, fun name, region, pool, data ptr, size, memType
292 * @return ROK - success
295 * ****************************************************************/
296 uint8_t SPutStaticBufNewForDebug(char *file, char *func, char *line, \
297 Region region, Pool pool, Data *ptr, Size size, uint8_t memType)
299 if(SPutStaticBuffer(region, pool, ptr, size, memType) == ROK)
301 #ifdef ODU_MEMORY_DEBUG_LOG
302 printf("\nCM_FREE=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p\n",\
303 file, line, func, size, ptr);
310 /**********************************************************************
312 **********************************************************************/