@@ -76,7 +76,15 @@ void pucch_resource_manager::stop()
7676bool pucch_resource_manager::is_harq_common_resource_available (slot_point sl, size_t r_pucch)
7777{
7878 srsran_assert (r_pucch < 16 , " r_PUCCH must be less than 16" );
79- return collision_manager.can_alloc_common (sl, r_pucch);
79+ // TODO: Remove this method and use collision_manager.alloc_common directly once it checks for UL grant collisions
80+ // correctly.
81+ auto res = collision_manager.alloc_common (sl, r_pucch);
82+ if (res.has_value ()) {
83+ // Allocation was successful, free the resource and return true.
84+ collision_manager.free_common (sl, r_pucch);
85+ return true ;
86+ }
87+ return false ;
8088}
8189
8290void pucch_resource_manager::reserve_harq_common_resource (slot_point sl, size_t r_pucch)
@@ -156,11 +164,10 @@ pucch_resource_manager::reserve_sr_resource(slot_point slot_sr, rnti_t crnti, co
156164 // the resource had already been allocated, just return it.
157165 if (res_rnti != crnti) {
158166 // Check for collisions.
159- if (not collision_manager.can_alloc_ded (slot_sr, cell_res_id)) {
167+ if (not collision_manager.alloc_ded (slot_sr, cell_res_id). has_value ( )) {
160168 return nullptr ;
161169 }
162170 res_rnti = crnti;
163- collision_manager.alloc_ded (slot_sr, cell_res_id);
164171 }
165172
166173 return res_cfg;
@@ -205,11 +212,10 @@ const pucch_resource* pucch_resource_manager::reserve_csi_resource(slot_point
205212 // the resource had already been allocated, just return it.
206213 if (res_rnti != crnti) {
207214 // Check for collisions.
208- if (not collision_manager.can_alloc_ded (slot_csi, cell_res_id)) {
215+ if (not collision_manager.alloc_ded (slot_csi, cell_res_id). has_value ( )) {
209216 return nullptr ;
210217 }
211218 res_rnti = crnti;
212- collision_manager.alloc_ded (slot_csi, cell_res_id);
213219 }
214220
215221 return res_cfg;
@@ -384,59 +390,61 @@ pucch_harq_resource_alloc_record pucch_resource_manager::reserve_next_harq_res_a
384390
385391 // For PUCCH F0 and F2, we don't use the last 2 resources of the PUCCH resource set; these are reserved for CSI and SR
386392 // slots and should only be picked for through the specific PUCCH resource indicator.
387- const unsigned nof_eligible_resource =
393+ const unsigned nof_eligible_resources =
388394 cell_cfg.is_pucch_f0_and_f2 () ? ue_res_set_id_list.size () - 2U : ue_res_set_id_list.size ();
389- srsran_assert (nof_eligible_resource >= 1U ,
395+ srsran_assert (nof_eligible_resources >= 1U ,
390396 " rnti={}: Not enough eligible resources from PUCCH resource set={}" ,
391397 crnti,
392398 pucch_res_set_idx_to_uint (res_set_idx));
393399
394400 // Get context of wanted slot.
395401 auto & ctx = slots_ctx[slot_harq.to_uint ()];
396402
397- std::optional<uint8_t > available_r_pucch;
398- for (uint8_t r_pucch = 0 ; r_pucch != nof_eligible_resource; ++r_pucch) {
399- const unsigned cell_res_id = ue_res_set_id_list[r_pucch].cell_res_id ;
403+ std::optional<std::pair<uint8_t , unsigned >> available_res;
400404
405+ // If a resource is already allocated to this RNTI, use it.
406+ for (uint8_t r_pucch = 0 ; r_pucch != nof_eligible_resources; ++r_pucch) {
407+ const unsigned cell_res_id = ue_res_set_id_list[r_pucch].cell_res_id ;
401408 srsran_assert (cell_res_id < ctx.ues_using_pucch_res .size (),
402409 " PUCCH resource index from PUCCH resource set exceeds the size of the cell resource array" );
403410 auto & res_rnti = ctx.ues_using_pucch_res [cell_res_id];
404411
405412 if (res_rnti == crnti) {
406- // If a resource is already allocated to this RNTI, use it.
407- available_r_pucch = r_pucch;
413+ available_res = {r_pucch, cell_res_id};
408414 break ;
409415 }
416+ }
410417
411- if (not available_r_pucch.has_value () and res_rnti == rnti_t ::INVALID_RNTI and
412- collision_manager.can_alloc_ded (slot_harq, cell_res_id)) {
413- // Else, keep track of the first available resource.
414- available_r_pucch = r_pucch;
418+ if (not available_res.has_value ()) {
419+ // Else, keep track of the first available resource.
420+ for (uint8_t r_pucch = 0 ; r_pucch != nof_eligible_resources; ++r_pucch) {
421+ const unsigned cell_res_id = ue_res_set_id_list[r_pucch].cell_res_id ;
422+ srsran_assert (cell_res_id < ctx.ues_using_pucch_res .size (),
423+ " PUCCH resource index from PUCCH resource set exceeds the size of the cell resource array" );
424+ auto & res_rnti = ctx.ues_using_pucch_res [cell_res_id];
425+
426+ if (res_rnti == rnti_t ::INVALID_RNTI and collision_manager.alloc_ded (slot_harq, cell_res_id).has_value ()) {
427+ ctx.ues_using_pucch_res [cell_res_id] = crnti;
428+ available_res = {r_pucch, cell_res_id};
429+ break ;
430+ }
415431 }
416432 }
417433
418- const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
419-
420- // If there is an available resource, allocate it.
421- if (available_r_pucch.has_value ()) {
422- const unsigned r_pucch = available_r_pucch.value ();
423- // Get the PUCCH resource ID from the PUCCH resource indicator and the PUCCH resource set.
424- const unsigned cell_res_id = ue_res_set_id_list[r_pucch].cell_res_id ;
425-
434+ // If an available resource was found, return it.
435+ if (available_res.has_value ()) {
426436 // Search for the PUCCH resource with the correct PUCCH resource ID from the PUCCH resource list.
427- const auto * res_cfg =
428- std::find_if (pucch_res_list.begin (), pucch_res_list.end (), [cell_res_id](const pucch_resource& res) {
437+ const auto & pucch_res_list = pucch_cfg.pucch_res_list ;
438+ const auto * res_cfg = std::find_if (
439+ pucch_res_list.begin (), pucch_res_list.end (), [cell_res_id = available_res->second ](const pucch_resource& res) {
429440 return res.res_id .cell_res_id == cell_res_id;
430441 });
431442 srsran_sanity_check (res_cfg != pucch_res_list.end (),
432443 " rnti={}: PUCCH resource with cell_res_id={} not found in PUCCH resource list" ,
433444 crnti,
434- cell_res_id );
445+ available_res-> second );
435446
436- // Allocate it and return it.
437- ctx.ues_using_pucch_res [cell_res_id] = crnti;
438- collision_manager.alloc_ded (slot_harq, cell_res_id);
439- return pucch_harq_resource_alloc_record{.resource = res_cfg, .pucch_res_indicator = available_r_pucch.value ()};
447+ return pucch_harq_resource_alloc_record{.resource = res_cfg, .pucch_res_indicator = available_res->first };
440448 }
441449 return pucch_harq_resource_alloc_record{.resource = nullptr };
442450}
@@ -505,14 +513,11 @@ const pucch_resource* pucch_resource_manager::reserve_harq_resource_by_res_indic
505513 return res_cfg;
506514 }
507515
508- // Check for collisions .
509- if (not collision_manager.can_alloc_ded (slot_harq, cell_res_id)) {
516+ // Allocate the resource to this RNTI .
517+ if (not collision_manager.alloc_ded (slot_harq, cell_res_id). has_value ( )) {
510518 return nullptr ;
511519 }
512-
513- // Allocate the resource to this RNTI.
514520 res_rnti = crnti;
515- collision_manager.alloc_ded (slot_harq, cell_res_id);
516521 return res_cfg;
517522}
518523
0 commit comments