@@ -46,8 +46,8 @@ pucch_resource_manager::pucch_resource_manager()
4646{
4747 auto reset_slot_record = [](rnti_pucch_res_id_slot_record& res_counter) {
4848 for (auto & ue_rec : res_counter.ues_using_pucch_res ) {
49- ue_rec.rnti = INVALID_RNTI;
50- ue_rec.format = pucch_format::NOF_FORMATS ;
49+ ue_rec.rnti = INVALID_RNTI;
50+ ue_rec.resource_usage = pucch_resource_usage::NOT_USED ;
5151 }
5252 for (auto & res : res_counter.used_common_resources ) {
5353 res = false ;
@@ -68,8 +68,8 @@ void pucch_resource_manager::slot_indication(slot_point slot_tx)
6868 rnti_pucch_res_id_slot_record& res_counter = get_slot_resource_counter (last_sl_ind - 1 );
6969
7070 for (auto & ue_rec : res_counter.ues_using_pucch_res ) {
71- ue_rec.rnti = INVALID_RNTI;
72- ue_rec.format = pucch_format::NOF_FORMATS ;
71+ ue_rec.rnti = INVALID_RNTI;
72+ ue_rec.resource_usage = pucch_resource_usage::NOT_USED ;
7373 }
7474 for (auto & res : res_counter.used_common_resources ) {
7575 res = false ;
@@ -114,23 +114,36 @@ const pucch_resource* pucch_resource_manager::reserve_specific_format2_res(slot_
114114
115115 // Get resource list of wanted slot.
116116 rnti_pucch_res_id_slot_record& res_counter = get_slot_resource_counter (slot_harq);
117-
117+ // Retrieve the PUCCH resource set.
118118 const auto & ue_res_id_set_for_harq_f2 = pucch_cfg.pucch_res_set [PUCCH_HARQ_F2_RES_SET_ID].pucch_res_id_list ;
119119
120+ // Make sure the resource indicator points to a valid resource.
120121 if (res_indicator >= ue_res_id_set_for_harq_f2.size ()) {
121122 return nullptr ;
122123 }
123124
125+ // Get PUCCH resource ID from the PUCCH resource set.
124126 const unsigned pucch_res_id = ue_res_id_set_for_harq_f2[res_indicator];
125-
126- const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
127+ // Get the PUCCH resource tracker in the PUCCH resource manager.
127128 auto & pucch_res_tracker = res_counter.ues_using_pucch_res [pucch_res_id];
129+ const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
128130
131+ // Check first if the wanted PUCCH resource is available.
129132 if (pucch_res_tracker.rnti == INVALID_RNTI) {
130- pucch_res_tracker.rnti = crnti;
131- pucch_res_tracker.format = pucch_format::FORMAT_2;
132- return &pucch_res_list[pucch_res_id];
133+ // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
134+ const auto * res_cfg =
135+ std::find_if (pucch_res_list.begin (), pucch_res_list.end (), [pucch_res_id](const pucch_resource& res) {
136+ return res.res_id == pucch_res_id;
137+ });
138+
139+ // If the PUCCH res with correct ID is found, then allocate it to the user.
140+ if (res_cfg != pucch_res_list.end ()) {
141+ pucch_res_tracker.rnti = crnti;
142+ pucch_res_tracker.resource_usage = pucch_resource_usage::HARQ_F2;
143+ return &(*res_cfg);
144+ }
133145 }
146+
134147 return nullptr ;
135148}
136149
@@ -141,18 +154,35 @@ const pucch_resource* pucch_resource_manager::reserve_csi_resource(slot_point
141154 srsran_sanity_check (slot_csi < last_sl_ind + RES_MANAGER_RING_BUFFER_SIZE,
142155 " PUCCH being allocated to far into the future" );
143156
144- const int csi_pucch_res_idx = get_pucch_res_idx_for_csi (ue_cell_cfg);
145- if (csi_pucch_res_idx < 0 ) {
157+ // Get CSI specific PUCCH resource ID from the CSI meas config.
158+ const int csi_pucch_res_idx_int = get_pucch_res_idx_for_csi (ue_cell_cfg);
159+ if (csi_pucch_res_idx_int < 0 ) {
146160 return nullptr ;
147161 }
162+ const unsigned csi_pucch_res_idx = static_cast <unsigned >(csi_pucch_res_idx_int);
163+
164+ // Get resource list of wanted slot.
148165 auto & slot_record = get_slot_resource_counter (slot_csi);
149166 if (slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti != INVALID_RNTI) {
150167 return nullptr ;
151168 }
152169
153- slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti = crnti;
154- slot_record.ues_using_pucch_res [csi_pucch_res_idx].format = pucch_format::FORMAT_2;
155- return &ue_cell_cfg.cfg_dedicated ().ul_config .value ().init_ul_bwp .pucch_cfg .value ().pucch_res_list [csi_pucch_res_idx];
170+ const auto & pucch_res_list =
171+ ue_cell_cfg.cfg_dedicated ().ul_config .value ().init_ul_bwp .pucch_cfg .value ().pucch_res_list ;
172+ // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
173+ const auto * res_cfg =
174+ std::find_if (pucch_res_list.begin (), pucch_res_list.end (), [csi_pucch_res_idx](const pucch_resource& res) {
175+ return res.res_id == csi_pucch_res_idx;
176+ });
177+
178+ // If the PUCCH res with correct ID is found, then allocate it to the user.
179+ if (res_cfg != pucch_res_list.end ()) {
180+ slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti = crnti;
181+ slot_record.ues_using_pucch_res [csi_pucch_res_idx].resource_usage = pucch_resource_usage::CSI;
182+ return &(*res_cfg);
183+ }
184+
185+ return nullptr ;
156186};
157187
158188const pucch_resource*
@@ -170,9 +200,21 @@ pucch_resource_manager::reserve_sr_res_available(slot_point slot_sr, rnti_t crnt
170200 return nullptr ;
171201 }
172202
173- slot_record.ues_using_pucch_res [sr_pucch_res_id].rnti = crnti;
174- slot_record.ues_using_pucch_res [sr_pucch_res_id].format = pucch_format::FORMAT_2;
175- return &pucch_cfg.pucch_res_list [sr_pucch_res_id];
203+ const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
204+ // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
205+ const auto * res_cfg =
206+ std::find_if (pucch_res_list.begin (), pucch_res_list.end (), [sr_pucch_res_id](const pucch_resource& res) {
207+ return res.res_id == sr_pucch_res_id;
208+ });
209+
210+ // If the PUCCH res with correct ID is found, then allocate it to the user.
211+ if (res_cfg != pucch_res_list.end ()) {
212+ slot_record.ues_using_pucch_res [sr_pucch_res_id].rnti = crnti;
213+ slot_record.ues_using_pucch_res [sr_pucch_res_id].resource_usage = pucch_resource_usage::SR;
214+ return &(*res_cfg);
215+ }
216+
217+ return nullptr ;
176218};
177219
178220bool pucch_resource_manager::release_harq_f1_resource (slot_point slot_harq, rnti_t crnti, const pucch_config& pucch_cfg)
@@ -200,8 +242,8 @@ bool pucch_resource_manager::release_sr_resource(slot_point slot_sr, rnti_t crnt
200242 return false ;
201243 }
202244
203- slot_record.ues_using_pucch_res [sr_pucch_res_id].rnti = INVALID_RNTI;
204- slot_record.ues_using_pucch_res [sr_pucch_res_id].format = pucch_format::NOF_FORMATS ;
245+ slot_record.ues_using_pucch_res [sr_pucch_res_id].rnti = INVALID_RNTI;
246+ slot_record.ues_using_pucch_res [sr_pucch_res_id].resource_usage = pucch_resource_usage::NOT_USED ;
205247 return true ;
206248}
207249
@@ -214,7 +256,7 @@ bool pucch_resource_manager::release_csi_resource(slot_point s
214256
215257 auto & slot_record = get_slot_resource_counter (slot_sr);
216258
217- // We assume each UE only has 1 SR Resource Config configured.
259+ // We assume each UE only has 1 CSI Resource Config configured.
218260 const int csi_pucch_res_idx = get_pucch_res_idx_for_csi (ue_cell_cfg);
219261 if (csi_pucch_res_idx < 0 ) {
220262 return false ;
@@ -223,8 +265,8 @@ bool pucch_resource_manager::release_csi_resource(slot_point s
223265 return false ;
224266 }
225267
226- slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti = INVALID_RNTI;
227- slot_record.ues_using_pucch_res [csi_pucch_res_idx].format = pucch_format::NOF_FORMATS ;
268+ slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti = INVALID_RNTI;
269+ slot_record.ues_using_pucch_res [csi_pucch_res_idx].resource_usage = pucch_resource_usage::NOT_USED ;
228270 return true ;
229271}
230272
@@ -247,19 +289,31 @@ const pucch_resource* pucch_resource_manager::fetch_csi_pucch_res_config(slot_po
247289
248290 rnti_pucch_res_id_slot_record& slot_record = get_slot_resource_counter (slot_tx);
249291
250- // We assume each UE only has 1 SR Resource Config configured.
251- const int csi_pucch_res_idx = get_pucch_res_idx_for_csi (ue_cell_cfg);
252- if (csi_pucch_res_idx < 0 ) {
292+ const int csi_pucch_res_idx_int = get_pucch_res_idx_for_csi (ue_cell_cfg);
293+ if (csi_pucch_res_idx_int < 0 ) {
253294 return nullptr ;
254295 }
255296
297+ const unsigned csi_pucch_res_idx = static_cast <unsigned >(csi_pucch_res_idx_int);
256298 if (slot_record.ues_using_pucch_res [csi_pucch_res_idx].rnti != crnti) {
257299 return nullptr ;
258300 }
259301
260- const pucch_config& pucch_cfg = ue_cell_cfg.cfg_dedicated ().ul_config .value ().init_ul_bwp .pucch_cfg .value ();
302+ const auto & pucch_res_list =
303+ ue_cell_cfg.cfg_dedicated ().ul_config .value ().init_ul_bwp .pucch_cfg .value ().pucch_res_list ;
261304
262- return &pucch_cfg.pucch_res_list [csi_pucch_res_idx];
305+ // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
306+ const auto * res_cfg =
307+ std::find_if (pucch_res_list.begin (), pucch_res_list.end (), [csi_pucch_res_idx](const pucch_resource& res) {
308+ return res.res_id == csi_pucch_res_idx;
309+ });
310+
311+ // If the PUCCH res with correct ID is found, then return it to the user.
312+ if (res_cfg != pucch_res_list.end ()) {
313+ return &(*res_cfg);
314+ }
315+
316+ return nullptr ;
263317}
264318
265319pucch_harq_resource_alloc_record pucch_resource_manager::reserve_next_harq_res_available (slot_point slot_harq,
@@ -284,27 +338,33 @@ pucch_harq_resource_alloc_record pucch_resource_manager::reserve_next_harq_res_a
284338 unsigned ue_first_f1_res_id = ue_res_id_set_for_harq.front ();
285339 span<resource_tracker> slot_ue_res_array (&slot_res_array[ue_first_f1_res_id], slot_res_array.size ());
286340
341+ // Check first if there is any PUCCH resource is available.
287342 auto * available_resource = std::find_if (slot_ue_res_array.begin (),
288343 slot_ue_res_array.end (),
289344 [](const resource_tracker res) { return res.rnti == INVALID_RNTI; });
290345
291346 const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
292347
348+ // If there is an available resource, try to allocate it.
293349 if (available_resource != slot_ue_res_array.end () and
294350 static_cast <unsigned >(available_resource - slot_ue_res_array.begin ()) <
295351 pucch_cfg.pucch_res_set [res_set_idx].pucch_res_id_list .size ()) {
352+ // Get the PUCCH resource indicator from the available resource position within the span.
296353 const unsigned pucch_res_indicator = static_cast <unsigned >(available_resource - slot_ue_res_array.begin ());
297-
354+ // Get the PUCCH resource ID from the PUCCH resource indicator and the PUCCH resource set.
298355 const unsigned pucch_res_idx_from_list = ue_res_id_set_for_harq[pucch_res_indicator];
299356
357+ // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
300358 const auto * res_cfg = std::find_if (
301359 pucch_res_list.begin (), pucch_res_list.end (), [pucch_res_idx_from_list](const pucch_resource& res) {
302360 return res.res_id == pucch_res_idx_from_list;
303361 });
304362
363+ // If so, allocate it.
305364 if (res_cfg != pucch_res_list.end ()) {
306- available_resource->rnti = crnti;
307- available_resource->format = format;
365+ available_resource->rnti = crnti;
366+ available_resource->resource_usage =
367+ format == pucch_format::FORMAT_1 ? pucch_resource_usage::HARQ_F1 : pucch_resource_usage::HARQ_F2;
308368 return pucch_harq_resource_alloc_record{.pucch_res = &(*res_cfg), .pucch_res_indicator = pucch_res_indicator};
309369 }
310370 }
@@ -327,20 +387,24 @@ bool pucch_resource_manager::release_harq_resource(slot_point slot_harq
327387 auto & slot_res_array = res_counter.ues_using_pucch_res ;
328388
329389 const unsigned res_set_idx = format == pucch_format::FORMAT_1 ? PUCCH_HARQ_F1_RES_SET_ID : PUCCH_HARQ_F2_RES_SET_ID;
390+ const pucch_resource_usage res_usage =
391+ format == pucch_format::FORMAT_1 ? pucch_resource_usage::HARQ_F1 : pucch_resource_usage::HARQ_F2;
330392
331393 // Get the span over the array of resources for the specific UE.
332394 const auto & ue_res_id_set_for_harq = pucch_cfg.pucch_res_set [res_set_idx].pucch_res_id_list ;
333395 unsigned ue_first_f1_res_id = ue_res_id_set_for_harq.front ();
334396 span<resource_tracker> slot_ue_res_array (&slot_res_array[ue_first_f1_res_id], slot_res_array.size ());
335397
336- auto * target_res = std::find_if (slot_ue_res_array.begin (),
337- slot_ue_res_array.end (),
338- [crnti](const resource_tracker res) { return res.rnti == crnti; });
398+ // Check first if the target PUCCH resource (given the CRNTI and usage) exists within the resource tracker.
399+ auto * target_res =
400+ std::find_if (slot_ue_res_array.begin (), slot_ue_res_array.end (), [crnti, res_usage](const resource_tracker res) {
401+ return res.rnti == crnti and res.resource_usage == res_usage;
402+ });
339403
340404 // If the resources was found, then release it (i.e., remove the C-RNTI of the user allocated to it).
341405 if (target_res != slot_ue_res_array.end ()) {
342- target_res->rnti = INVALID_RNTI;
343- target_res->format = pucch_format::NOF_FORMATS ;
406+ target_res->rnti = INVALID_RNTI;
407+ target_res->resource_usage = pucch_resource_usage::NOT_USED ;
344408 return true ;
345409 }
346410
@@ -363,19 +427,23 @@ int pucch_resource_manager::fetch_pucch_res_indic(slot_point slot_tx,
363427 auto & slot_res_array = res_counter.ues_using_pucch_res ;
364428
365429 const unsigned res_set_idx = format == pucch_format::FORMAT_1 ? PUCCH_HARQ_F1_RES_SET_ID : PUCCH_HARQ_F2_RES_SET_ID;
430+ const pucch_resource_usage res_usage =
431+ format == pucch_format::FORMAT_1 ? pucch_resource_usage::HARQ_F1 : pucch_resource_usage::HARQ_F2;
366432
367433 // Get the span over the array of resources for the specific UE.
368434 const auto & ue_res_id_set_for_harq = pucch_cfg.pucch_res_set [res_set_idx].pucch_res_id_list ;
369435 unsigned ue_first_f1_res_id = ue_res_id_set_for_harq.front ();
370436 span<resource_tracker> slot_ue_res_array (&slot_res_array[ue_first_f1_res_id], slot_res_array.size ());
371437
372- auto ue_resource =
373- std::find_if (slot_ue_res_array.begin (),
374- slot_ue_res_array.end (),
375- [target_rnti = crnti](const resource_tracker res) { return res.rnti == target_rnti; });
438+ // Check first if the target PUCCH resource (given the CRNTI and usage) exists within the resource tracker.
439+ auto * ue_resource = std::find_if (
440+ slot_ue_res_array.begin (), slot_ue_res_array.end (), [target_rnti = crnti, res_usage](const resource_tracker res) {
441+ return res.rnti == target_rnti and res.resource_usage == res_usage;
442+ });
376443
377444 if (ue_resource != slot_ue_res_array.end () and static_cast <unsigned >(ue_resource - slot_ue_res_array.begin ()) <
378445 pucch_cfg.pucch_res_set [res_set_idx].pucch_res_id_list .size ()) {
446+ // Get the PUCCH resource indicator from the available resource position within the span.
379447 return static_cast <unsigned >(ue_resource - slot_ue_res_array.begin ());
380448 }
381449
0 commit comments