From ad4da1b068ddc76ce6681e4045ad4f117ac2c633 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Fri, 18 Sep 2020 13:53:39 +0200
Subject: [PATCH] PreProc IF: save PUCCH info per UE

---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c | 12 +++++++-----
 openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h          |  2 ++
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index e6dd29db6d..bbd2c18022 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -472,6 +472,12 @@ void nr_simple_dlsch_preprocessor(module_id_t module_id,
     LOG_E(MAC, "%s(): could not find CCE for UE %d\n", __func__, UE_id);
     return;
   }
+
+  /* Find PUCCH occasion */
+  nr_update_pucch_scheduling(
+      module_id, UE_id, frame, slot, num_slots_per_tdd, &sched_ctrl->pucch_sched_idx);
+  AssertFatal(sched_ctrl->pucch_sched_idx >= 0, "no uplink slot for PUCCH found!\n");
+
 }
 
 void nr_schedule_ue_spec(module_id_t module_id,
@@ -497,11 +503,6 @@ void nr_schedule_ue_spec(module_id_t module_id,
   //if (sched_ctrl->rbSize < 0 && !get_softmodem_params()->phy_test)
   //  return;
 
-  /* Find PUCCH occasion */
-  int pucch_sched;
-  nr_update_pucch_scheduling(module_id, UE_id, frame, slot, num_slots_per_tdd, &pucch_sched);
-  NR_sched_pucch *pucch = &UE_list->UE_sched_ctrl[UE_id].sched_pucch[pucch_sched];
-
   const uint16_t bwpSize = NRRIV2BW(sched_ctrl->active_bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
 
   const uint8_t mcs = 9;
@@ -644,6 +645,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
 
   const int current_harq_pid = sched_ctrl->current_harq_pid;
   NR_UE_harq_t *harq = &sched_ctrl->harq_processes[current_harq_pid];
+  NR_sched_pucch *pucch = &sched_ctrl->sched_pucch[sched_ctrl->pucch_sched_idx];
   harq->feedback_slot = pucch->ul_slot;
   harq->is_waiting = 1;
   UE_list->mac_stats[UE_id].dlsch_rounds[harq->round]++;
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index 80aecdb985..9fd3267f8c 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -291,6 +291,8 @@ typedef struct {
   /// the currently active BWP in DL
   NR_BWP_Downlink_t *active_bwp;
   NR_sched_pucch *sched_pucch;
+  /// selected PUCCH index, if scheduled
+  int pucch_sched_idx;
   NR_sched_pusch *sched_pusch;
 
   /// CCE index and aggregation, should be coherent with cce_list
-- 
2.26.2