@@ -158,12 +158,17 @@ du_srs_policy_max_ul_th::du_srs_policy_max_ul_th(span<const du_cell_config> cell
158158 // Handle TDD and FDD configurations separately, as we treat partially-UL slots differently from
159159 // fully-UL slots.
160160 if (cell_cfg_list_[0 ].tdd_ul_dl_cfg_common .has_value ()) {
161+ const auto & tdd_cfg = cell_cfg_list_[0 ].tdd_ul_dl_cfg_common .value ();
161162 // For partially-UL slots, we need to check if the SRS can be placed in the UL symbols of the
162163 // slot.
163164 if (is_partually_ul_slot (offset, cell_cfg_list_[0 ].tdd_ul_dl_cfg_common .value ())) {
164- // TODO: Fix check for pattern 2.
165- if (res.symbols .start () < NOF_OFDM_SYM_PER_SLOT_NORMAL_CP -
166- cell_cfg_list_[0 ].tdd_ul_dl_cfg_common .value ().pattern1 .nof_ul_symbols ) {
165+ const unsigned slot_index =
166+ offset % (NOF_SUBFRAMES_PER_FRAME * get_nof_slots_per_subframe (tdd_cfg.ref_scs ));
167+ static constexpr unsigned max_srs_symbols = 6U ;
168+ const unsigned nof_ul_symbols_for_srs =
169+ std::min (srsran::get_active_tdd_ul_symbols (tdd_cfg, slot_index, cyclic_prefix::NORMAL).length (),
170+ max_srs_symbols);
171+ if (res.symbols .start () < NOF_OFDM_SYM_PER_SLOT_NORMAL_CP - nof_ul_symbols_for_srs) {
167172 continue ;
168173 }
169174 }
@@ -191,13 +196,15 @@ bool du_srs_policy_max_ul_th::alloc_resources(cell_group_config& cell_grp_cfg)
191196{
192197 // TODO: Adapt this to the case of UEs with multiple cells configs.
193198 srsran_assert (
194- cells[cell_grp_cfg.cells [0 ].serv_cell_cfg .cell_index ].cell_cfg .ue_ded_serv_cell_cfg .ul_config .has_value (),
195- " UE UL config is empty" );
199+ cells[cell_grp_cfg.cells [0 ].serv_cell_cfg .cell_index ].cell_cfg .ue_ded_serv_cell_cfg .ul_config .has_value () and
200+ not cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .has_value (),
201+ " UE UL config should be non-empty but with an empty SRS config" );
202+
203+ cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .emplace (
204+ cells[cell_grp_cfg.cells [0 ].serv_cell_cfg .cell_index ].default_srs_cfg );
196205
197206 // If periodic SRS is not enabled, don't allocate anything and exit with success.
198- if (not cells[0 ].cell_cfg .srs_cfg .srs_period .has_value () or not cells[cell_grp_cfg.cells [0 ].serv_cell_cfg .cell_index ]
199- .cell_cfg .ue_ded_serv_cell_cfg .ul_config .value ()
200- .init_ul_bwp .srs_cfg .has_value ()) {
207+ if (not cells[0 ].cell_cfg .srs_cfg .srs_period .has_value ()) {
201208 return true ;
202209 }
203210
@@ -210,19 +217,25 @@ bool du_srs_policy_max_ul_th::alloc_resources(cell_group_config& cell_grp_cfg)
210217
211218 // Verify where there are SRS resources to allocate a new UE.
212219 if (free_srs_list.empty ()) {
220+ // If the allocation failed, reset the SRS configuration.
221+ cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .reset ();
213222 return false ;
214223 }
215224
216225 // Find the best resource ID and offset for this UE.
217226 auto srs_res_id_offset = cells[0 ].find_optimal_ue_srs_resource ();
218227
219228 if (srs_res_id_offset == free_srs_list.end ()) {
229+ // If the allocation failed, reset the SRS configuration.
230+ cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .reset ();
220231 return false ;
221232 }
222233
223234 const auto & du_res_it = cells[0 ].get_du_srs_res_cfg (srs_res_id_offset->first );
224235
225236 if (du_res_it == cells[0 ].cell_srs_res_list .end ()) {
237+ // If the allocation failed, reset the SRS configuration.
238+ cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .reset ();
226239 return false ;
227240 }
228241
@@ -256,6 +269,9 @@ bool du_srs_policy_max_ul_th::alloc_resources(cell_group_config& cell_grp_cfg)
256269 only_ue_srs_res.freq_domain_shift =
257270 cells[cell_grp_cfg.cells [0 ].serv_cell_cfg .cell_index ].srs_common_params .freq_shift ;
258271
272+ only_ue_srs_res.periodicity_and_offset .emplace (srs_config::srs_periodicity_and_offset{
273+ .period = cells[0 ].cell_cfg .srs_cfg .srs_period .value (), .offset = static_cast <uint16_t >(srs_offset)});
274+
259275 // Update the SRS resource set with the SRS id.
260276 ue_srs_cfg.srs_res_set_list .front ().srs_res_id_list .front () = only_ue_srs_res.id .ue_res_id ;
261277
@@ -294,7 +310,8 @@ du_srs_policy_max_ul_th::cell_context::find_optimal_ue_srs_resource()
294310
295311 // Give priority to the last symbols within a slot. This reduces the space used for the SRS in a slot.
296312 const unsigned symb_weight =
297- (NOF_OFDM_SYM_PER_SLOT_NORMAL_CP - srs_res_cfg_it->symbols .start ()) * symbol_weight_base;
313+ symbol_weight_base *
314+ ((NOF_OFDM_SYM_PER_SLOT_NORMAL_CP - srs_res_cfg_it->symbols .start ()) / srs_res_cfg_it->symbols .length ());
298315
299316 // We consider a discount if the offset is already used but not full; this way, we give an incentive
300317 // to the SRS resources not to be allocated on a new slot, to avoid taking PUSCH symbols on a new
@@ -332,4 +349,8 @@ void du_srs_policy_max_ul_th::dealloc_resources(cell_group_config& cell_grp_cfg)
332349 srsran_assert (cells[0 ].slot_resource_cnt [offset_to_deallocate].first != 0 , " The offset is expected to be non-zero" );
333350 --cells[0 ].slot_resource_cnt [offset_to_deallocate].first ;
334351 }
352+
353+ // Reset the SRS configuration in this UE. This makes sure the DU will exit this function immediately when it gets
354+ // call again for the same UE (upon destructor's call).
355+ cell_grp_cfg.cells [0 ].serv_cell_cfg .ul_config ->init_ul_bwp .srs_cfg .reset ();
335356}
0 commit comments