From 84aa1f8ff5aa1427a29476fee102301350d10803 Mon Sep 17 00:00:00 2001 From: Sakthivel Velumani Date: Thu, 6 Nov 2025 15:07:54 -0500 Subject: [PATCH] clean-up: fix code repetition --- openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c index 2818c20c37..0af17c3cf5 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c @@ -2696,6 +2696,18 @@ void nr_ue_ul_scheduler(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info) } } +static void get_pusch_frame_slot(const int current_frame, + const int current_slot, + const int k2, + const int delta, + const int slots_per_frame, + frame_t *frame_tx, + int *slot_tx) +{ + *slot_tx = (current_slot + k2 + delta) % slots_per_frame; + *frame_tx = (current_frame + (current_slot + k2 + delta) / slots_per_frame) % MAX_FRAME_NUMBER; +} + // PUSCH scheduler: // - Calculate the slot in which ULSCH should be scheduled. This is current slot + K2, // - where K2 is the offset between the slot in which UL DCI is received and the slot @@ -2734,8 +2746,7 @@ int nr_ue_pusch_scheduler(const NR_UE_MAC_INST_t *mac, GET_DURATION_RX_TO_TX(&mac->phy_config.config_req.ntn_config, mu)); - *slot_tx = (current_slot + k2 + delta) % slots_per_frame; - *frame_tx = (current_frame + (current_slot + k2 + delta) / slots_per_frame) % MAX_FRAME_NUMBER; + get_pusch_frame_slot(current_frame, current_slot, k2, delta, slots_per_frame, frame_tx, slot_tx); } else { AssertFatal(k2 >= GET_DURATION_RX_TO_TX(&mac->phy_config.config_req.ntn_config, mu), "Slot offset K2 (%ld) needs to be higher than DURATION_RX_TO_TX (%ld). Please set min_rxtxtime at least to %ld in " @@ -2752,8 +2763,7 @@ int nr_ue_pusch_scheduler(const NR_UE_MAC_INST_t *mac, } // Calculate TX slot and frame - *slot_tx = (current_slot + k2) % slots_per_frame; - *frame_tx = (current_frame + (current_slot + k2) / slots_per_frame) % MAX_FRAME_NUMBER; + get_pusch_frame_slot(current_frame, current_slot, k2, 0, slots_per_frame, frame_tx, slot_tx); } LOG_D(NR_MAC, "[%04d.%02d] UL transmission in [%04d.%02d] (k2 %ld delta %d)\n", current_frame, current_slot, *frame_tx, *slot_tx, k2, delta);