1 /******************************************************************************
3 * Copyright (c) 2021 Intel.
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.
17 *******************************************************************************/
19 #include "nr5g_fapi_framework.h"
20 #include "nr5g_fapi_fapi2phy_p7_pvt_proc.h"
22 #define FAPI_EMPTY_RB_BITMAP_MASK (0u)
23 #define FAPI_EMPTY_RBG_INDEX (0u)
24 #define FAPI_MAX_RB_BIT_NUM (273u)
26 static uint16_t nr5g_fapi_rb_bitmap_mask(
39 return FAPI_EMPTY_RB_BITMAP_MASK;
43 uint16_t nr5g_fapi_get_rb_bits_for_rbg(
44 const uint8_t rb_bitmap[FAPI_RB_BITMAP_SIZE],
47 uint16_t rb_bitmap_mask)
49 uint16_t rb_bits = 0u;
50 const uint16_t rb_bits_bit_size = sizeof(rb_bits) * CHAR_BIT;
51 const uint16_t nth_rb_bit = nth_rbg_bit * rbg_size;
52 const uint32_t rb_byte_1 = ( nth_rb_bit / rb_bits_bit_size ) * sizeof(rb_bits);
53 const uint32_t rb_byte_2 = rb_byte_1 + 1u;
54 if (rb_byte_1 < FAPI_RB_BITMAP_SIZE)
56 rb_bits |= rb_bitmap[rb_byte_1];
58 if (rb_byte_2 < FAPI_RB_BITMAP_SIZE)
60 rb_bits |= (rb_bitmap[rb_byte_2] << CHAR_BIT);
62 const uint32_t local_rbg_idx = nth_rb_bit % rb_bits_bit_size;
63 return (rb_bits >> local_rbg_idx) & rb_bitmap_mask;
66 static bool nr5g_fapi_has_rbg_bits_in_rb_bitmap(
67 const uint8_t rb_bitmap[FAPI_RB_BITMAP_SIZE],
68 const uint16_t rbg_bit,
69 const uint8_t rbg_size,
70 const uint16_t rb_bitmap_mask)
72 const uint16_t rb_bits_for_rbg = nr5g_fapi_get_rb_bits_for_rbg(
73 rb_bitmap, rbg_bit, rbg_size, rb_bitmap_mask);
74 if (rb_bitmap_mask == rb_bits_for_rbg)
78 else if (FAPI_EMPTY_RB_BITMAP_MASK != rb_bits_for_rbg)
80 NR5G_FAPI_LOG(ERROR_LOG, ("rb_bits don not match rb_bitmap_mask."
81 " rbg_size %u rbg_bit=%u rb_bits_for_rbg=%#X rb_bitmap_mask=%#X",
82 rbg_size, rbg_bit, rb_bits_for_rbg, rb_bitmap_mask));
87 /** @ingroup group_source_api_p7_fapi2phy_proc
89 * @param[in] rb_bitmap Pointer to FAPI DL resource block bitmap.
90 * @param[in] bwp_start Value of bandwidth partition start.
91 * @param[in] bwp_size Value of bandwidth partition size.
92 * @param[in] rbg_size Value of resource block group size.
93 * @param[in] get_rbg_index_mask Function placing bit in rbgIndex (bit order).
95 * @return Returns IAPI nRBGIndex
98 * See TS 138 214 5.1.2.2.1/6.1.2.2.1 for more info.
99 * IAPI uses bit per Resource Block Group,
100 * FAPI uses bit per Virtual Resource Block.
101 * Therefore 1 nRBGIndex bit (IAPI), maps to nRBGSize bits (FAPI)
102 * Bitmaps mappings representation:
103 * IAPI: nRBGIndex = RBG-0................RBG-17 (for PDSCH MSB to LSB,
104 * for PUSCH LSB to MSB)
105 * FAPI RB-0...RB-272:
106 * FAPI rbBitmap[i] = RB-(7+i*8)...........RB-(0+i*8) (MSB to LSB)
109 uint32_t nr5g_fapi_calc_rbg_index(
110 const uint8_t rb_bitmap[FAPI_RB_BITMAP_SIZE],
113 uint32_t(*get_rbg_index_mask)(uint32_t nth_bit))
115 const uint8_t rbg_size = nr5g_fapi_calc_n_rbg_size(bwp_size);
116 const uint16_t rb_bitmap_mask = nr5g_fapi_rb_bitmap_mask(rbg_size);
117 if (FAPI_EMPTY_RB_BITMAP_MASK == rb_bitmap_mask)
119 NR5G_FAPI_LOG(ERROR_LOG, ("Wrong rbg_size=%u. rbg_index set to 0.",
121 return FAPI_EMPTY_RBG_INDEX;
123 if (bwp_start >= FAPI_MAX_RB_BIT_NUM)
125 NR5G_FAPI_LOG(ERROR_LOG, ("Wrong bwp_start=%u. rbg_index set to 0.",
127 return FAPI_EMPTY_RBG_INDEX;
130 const uint16_t rbg_bit_begin = bwp_start / rbg_size;
131 const uint16_t rb_bit_end = fmin(FAPI_MAX_RB_BIT_NUM, bwp_start + bwp_size);
132 const uint16_t rbg_bit_last = ceil((double)rb_bit_end / rbg_size) - 1u;
134 const uint16_t start_offset = bwp_start % rbg_size;
135 uint16_t rb_bitmap_mask_1st_rbg =
136 rb_bitmap_mask & (rb_bitmap_mask << start_offset);
137 const uint16_t last_rbg_size =
138 (0u == rb_bit_end % rbg_size) ? rbg_size : rb_bit_end % rbg_size;
139 const uint16_t end_offset = rbg_size - last_rbg_size;
140 uint16_t rb_bitmap_mask_last_rbg = rb_bitmap_mask >> end_offset;
141 if (rbg_bit_begin == rbg_bit_last)
143 const uint16_t mask = rb_bitmap_mask_1st_rbg & rb_bitmap_mask_last_rbg;
144 rb_bitmap_mask_1st_rbg = mask;
145 rb_bitmap_mask_last_rbg = mask;
148 uint32_t result = 0u;
150 if (nr5g_fapi_has_rbg_bits_in_rb_bitmap(
151 rb_bitmap, rbg_bit_begin, rbg_size, rb_bitmap_mask_1st_rbg))
153 result |= get_rbg_index_mask(rbg_bit_begin);
156 if (nr5g_fapi_has_rbg_bits_in_rb_bitmap(
157 rb_bitmap, rbg_bit_last, rbg_size, rb_bitmap_mask_last_rbg))
159 result |= get_rbg_index_mask(rbg_bit_last);
163 for (rbg_bit = rbg_bit_begin + 1u; rbg_bit < rbg_bit_last; rbg_bit++)
165 if (nr5g_fapi_has_rbg_bits_in_rb_bitmap(
166 rb_bitmap, rbg_bit, rbg_size, rb_bitmap_mask))
168 result |= get_rbg_index_mask(rbg_bit);
175 /** @ingroup group_source_api_p7_fapi2phy_proc
177 * @param[in] bwp_size Variable holding the Bandwidth part size.
179 * @return Returns ::RBG Size.
182 * This functions calculates and return RBG Size from Bandwidth part size
186 uint8_t nr5g_fapi_calc_n_rbg_size(
189 uint8_t n_rbg_size = 0;
190 if (bwp_size >= 1 && bwp_size <= 36) {
192 } else if (bwp_size >= 37 && bwp_size <= 72) {
194 } else if (bwp_size >= 73 && bwp_size <= 144) {
196 } else if (bwp_size >= 145 && bwp_size <= 275) {