From bebbc857a0cbb6bf11ef65b55d8971bd9967f41e Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 7 Jan 2025 11:10:26 +0100 Subject: [PATCH] Add get_ul_slot_offset function to calculate nth UL slot offset for UE in TDD period * the get_ul_slot_offset function calculates the offset of the nth uplink (UL) slot for a given UE index within a TDD period * this function uses the frame structure bitmap to determine the UL slot positions --- openair2/LAYER2/NR_MAC_gNB/config.c | 35 ++++++++++++++++++++++++++ openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 1 + 2 files changed, 36 insertions(+) diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 2b3e8056fc..8881ab2bd7 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -442,6 +442,41 @@ int get_ul_slots_per_frame(const frame_structure_t *fs) return fs->is_tdd ? fs->numb_period_frame * get_ul_slots_per_period(fs) : fs->numb_slots_frame; } +/** + * @brief Get the nth UL slot offset for UE index idx in a TDD period using the frame structure bitmap + * @param fs frame structure + * @param idx UE index + * @param count_mixed indicates whether counting mixed slot with UL symbols (e.g. for SRS) or only full UL slots + * @return slot index offset + */ +int get_ul_slot_offset(const frame_structure_t *fs, int idx, bool count_mixed) +{ + DevAssert(fs); + + // FDD + if (!fs->is_tdd) + return idx; + + // UL slots indexes in period + int ul_slot_idxs[fs->numb_slots_period]; + int ul_slot_count = 0; + + /* Populate the indices of UL slots in the TDD period from the bitmap + count also mixed slots with UL symbols if flag count_mixed is present */ + for (int i = 0; i < fs->numb_slots_period; i++) { + bool is_mixed = (fs->period_cfg.tdd_slot_bitmap[i].num_ul_symbols > 1) && (fs->period_cfg.tdd_slot_bitmap[i].slot_type == TDD_NR_MIXED_SLOT); + if ((count_mixed && is_mixed) || fs->period_cfg.tdd_slot_bitmap[i].slot_type == TDD_NR_UPLINK_SLOT) { + ul_slot_idxs[ul_slot_count++] = i; + } + } + + // Compute slot index offset + int period_idx = idx / ul_slot_count; // wrap up the count of complete TDD periods spanned by the index + int ul_slot_idx_in_period = idx % ul_slot_count; // wrap up the UL slot index within the current TDD period + + return ul_slot_idxs[ul_slot_idx_in_period] + period_idx * fs->numb_slots_period; +} + /** * @brief Configures the frame structure and the NFAPI config request * depending on the duplex mode. If TDD, does the TDD patterns diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index c2463201d1..d86f65e365 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -44,6 +44,7 @@ int get_ul_slots_per_frame(const frame_structure_t *fs); int get_dl_slots_per_period(const frame_structure_t *fs); int get_full_ul_slots_per_period(const frame_structure_t *fs); int get_full_dl_slots_per_period(const frame_structure_t *fs); +int get_ul_slot_offset(const frame_structure_t *fs, int idx, bool count_mixed); void mac_top_init_gNB(ngran_node_t node_type, NR_ServingCellConfigCommon_t *scc,