From 00cb43bac399060b59f3416980a9e19a4e3ee1e8 Mon Sep 17 00:00:00 2001
From: Laurent THOMAS <laurent.thomas@open-cells.com>
Date: Fri, 26 Jul 2024 14:59:47 +0200
Subject: [PATCH] Use gold cache for PRS decoding

---
 openair1/PHY/INIT/nr_init.c                   | 15 ------
 openair1/PHY/INIT/nr_init_ue.c                | 44 ----------------
 openair1/PHY/NR_REFSIG/nr_gold.c              | 52 -------------------
 openair1/PHY/NR_REFSIG/nr_gold_ue.c           | 37 -------------
 openair1/PHY/NR_REFSIG/nr_refsig.h            |  8 ---
 openair1/PHY/NR_REFSIG/nr_refsig_common.h     |  1 +
 openair1/PHY/NR_REFSIG/refsig.c               | 13 +++++
 openair1/PHY/NR_REFSIG/refsig_defs_ue.h       |  1 -
 openair1/PHY/NR_TRANSPORT/nr_prs.c            | 17 +++---
 openair1/PHY/NR_TRANSPORT/nr_scrambling.c     |  1 +
 .../PHY/NR_TRANSPORT/nr_transport_proto.h     |  2 +-
 .../PHY/NR_TRANSPORT/nr_uci_tools_common.c    |  2 +
 openair1/PHY/NR_TRANSPORT/pucch_rx.c          |  1 +
 .../nr_dl_channel_estimation.c                |  9 ++--
 openair1/PHY/defs_gNB.h                       |  3 --
 openair1/PHY/defs_nr_UE.h                     |  3 --
 openair1/SCHED_NR/phy_procedures_nr_gNB.c     |  2 +-
 17 files changed, 34 insertions(+), 177 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index 61a517c962a..8663fe37b9b 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -154,9 +154,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
   // ceil((NB_RB*8(max allocation per RB)*2(QPSK))/32)
   gNB->nr_csi_info = (nr_csi_info_t *)malloc16_clear(sizeof(nr_csi_info_t));
 
-  //PRS init
-  nr_init_prs(gNB);
-
   generate_ul_reference_signal_sequences(SHRT_MAX);
 
   /* Generate low PAPR type 1 sequences for PUSCH DMRS, these are used if transform precoding is enabled.  */
@@ -240,7 +237,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB)
 
 void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
 {
-  NR_DL_FRAME_PARMS* const fp = &gNB->frame_parms;
   const int Ptx = gNB->gNB_config.carrier_config.num_tx_ant.value;
   const int Prx = gNB->gNB_config.carrier_config.num_rx_ant.value;
   const int max_ul_mimo_layers = 4; // taken from phy_init_nr_gNB()
@@ -274,17 +270,6 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(common_vars->beam_id[i]);
   }
 
-  for (int rsc=0; rsc < gNB->prs_vars.NumPRSResources; rsc++) {
-    for (int slot=0; slot<fp->slots_per_frame; slot++) {
-      for (int symb=0; symb<fp->symbols_per_slot; symb++) {
-        free_and_zero(gNB->nr_gold_prs[rsc][slot][symb]);
-      }
-      free_and_zero(gNB->nr_gold_prs[rsc][slot]);
-    }
-    free_and_zero(gNB->nr_gold_prs[rsc]);
-  }
-  free_and_zero(gNB->nr_gold_prs);
-
   /* Do NOT free per-antenna txdataF/rxdataF: the gNB gets a pointer to the
    * RU's txdataF/rxdataF, and the RU will free that */
   free_and_zero(common_vars->txdataF);
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index 13f49224400..d0191b0225b 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -162,32 +162,6 @@ void init_nr_prs_ue_vars(PHY_VARS_NR_UE *ue)
 
   // load the config file params
   RCconfig_nrUE_prs(ue);
-
-  //PRS sequence init
-  ue->nr_gold_prs = malloc16(ue->prs_active_gNBs * sizeof(uint32_t ****));
-  uint32_t *****prs = ue->nr_gold_prs;
-  AssertFatal(prs!=NULL, "%s: positioning reference signal malloc failed\n", __FUNCTION__);
-  for (int gnb = 0; gnb < ue->prs_active_gNBs; gnb++) {
-    prs[gnb] = malloc16(ue->prs_vars[gnb]->NumPRSResources * sizeof(uint32_t ***));
-    AssertFatal(prs[gnb]!=NULL, "%s: positioning reference signal for gnb %d - malloc failed\n", __FUNCTION__, gnb);
-
-    for (int rsc = 0; rsc < ue->prs_vars[gnb]->NumPRSResources; rsc++) {
-      prs[gnb][rsc] = malloc16(fp->slots_per_frame * sizeof(uint32_t **));
-      AssertFatal(prs[gnb][rsc]!=NULL, "%s: positioning reference signal for gnb %d rsc %d- malloc failed\n", __FUNCTION__, gnb, rsc);
-
-      for (int slot=0; slot<fp->slots_per_frame; slot++) {
-        prs[gnb][rsc][slot] = malloc16(fp->symbols_per_slot * sizeof(uint32_t *));
-        AssertFatal(prs[gnb][rsc][slot]!=NULL, "%s: positioning reference signal for gnb %d rsc %d slot %d - malloc failed\n", __FUNCTION__, gnb, rsc, slot);
-
-        for (int symb=0; symb<fp->symbols_per_slot; symb++) {
-          prs[gnb][rsc][slot][symb] = malloc16(NR_MAX_PRS_INIT_LENGTH_DWORD * sizeof(uint32_t));
-          AssertFatal(prs[gnb][rsc][slot][symb]!=NULL, "%s: positioning reference signal for gnb %d rsc %d slot %d symbol %d - malloc failed\n", __FUNCTION__, gnb, rsc, slot, symb);
-        } // for symb
-      } // for slot
-    } // for rsc
-  } // for gnb
-
-  init_nr_gold_prs(ue);
 }
 
 int init_nr_ue_signal(PHY_VARS_NR_UE *ue, int nb_connected_gNB)
@@ -362,24 +336,6 @@ void term_nr_ue_signal(PHY_VARS_NR_UE *ue, int nb_connected_gNB)
     free_and_zero(ue->prach_vars[gNB_id]);
   }
 
-  for (int gnb = 0; gnb < ue->prs_active_gNBs; gnb++)
-  {
-    for (int rsc = 0; rsc < ue->prs_vars[gnb]->NumPRSResources; rsc++)
-    {
-      for (int slot=0; slot<fp->slots_per_frame; slot++)
-      {
-        for (int symb=0; symb<fp->symbols_per_slot; symb++)
-        {
-          free_and_zero(ue->nr_gold_prs[gnb][rsc][slot][symb]);
-        }
-        free_and_zero(ue->nr_gold_prs[gnb][rsc][slot]);
-      }
-      free_and_zero(ue->nr_gold_prs[gnb][rsc]);
-    }
-    free_and_zero(ue->nr_gold_prs[gnb]);
-  }
-  free_and_zero(ue->nr_gold_prs);
-
   for(int idx = 0; idx < NR_MAX_PRS_COMB_SIZE; idx++)
   {
     for(int k = 0; k < NR_MAX_PRS_RESOURCES_PER_SET; k++)
diff --git a/openair1/PHY/NR_REFSIG/nr_gold.c b/openair1/PHY/NR_REFSIG/nr_gold.c
index 066707029b1..d50ecaa94bd 100644
--- a/openair1/PHY/NR_REFSIG/nr_gold.c
+++ b/openair1/PHY/NR_REFSIG/nr_gold.c
@@ -20,55 +20,3 @@
  */
 
 #include "nr_refsig.h"
-
-void nr_init_prs(PHY_VARS_gNB* gNB)
-{
-  unsigned int x1 = 0, x2 = 0;
-  uint16_t Nid;
-
-  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
-  gNB->nr_gold_prs = (uint32_t ****)malloc16(gNB->prs_vars.NumPRSResources*sizeof(uint32_t ***));
-  uint32_t ****prs = gNB->nr_gold_prs;
-  AssertFatal(prs!=NULL, "NR init: positioning reference signal malloc failed\n");
-  for (int rsc=0; rsc < gNB->prs_vars.NumPRSResources; rsc++) {
-    prs[rsc] = (uint32_t ***)malloc16(fp->slots_per_frame*sizeof(uint32_t **));
-    AssertFatal(prs[rsc]!=NULL, "NR init: positioning reference signal for rsc %d - malloc failed\n", rsc);
-
-    for (int slot=0; slot<fp->slots_per_frame; slot++) {
-      prs[rsc][slot] = (uint32_t **)malloc16(fp->symbols_per_slot*sizeof(uint32_t *));
-      AssertFatal(prs[rsc][slot]!=NULL, "NR init: positioning reference signal for slot %d - malloc failed\n", slot);
-
-      for (int symb=0; symb<fp->symbols_per_slot; symb++) {
-        prs[rsc][slot][symb] = (uint32_t *)malloc16(NR_MAX_PRS_INIT_LENGTH_DWORD*sizeof(uint32_t));
-        AssertFatal(prs[rsc][slot][symb]!=NULL, "NR init: positioning reference signal for rsc %d slot %d symbol %d - malloc failed\n", rsc, slot, symb);
-      }
-    }
-  }
-
-  uint8_t reset;
-  uint8_t slotNum, symNum, rsc_id;
-
-  for (rsc_id = 0; rsc_id < gNB->prs_vars.NumPRSResources; rsc_id++) {
-    Nid = gNB->prs_vars.prs_cfg[rsc_id].NPRSID; // seed value
-    LOG_I(PHY, "Initiaized NR-PRS sequence with PRS_ID %3d for resource %d\n", Nid, rsc_id);
-    for (slotNum = 0; slotNum < fp->slots_per_frame; slotNum++) {
-      for (symNum = 0; symNum < fp->symbols_per_slot ; symNum++) {
-        reset = 1;
-        // initial x2 for prs as ts138.211
-        uint32_t c_init1, c_init2, c_init3;
-        uint32_t pow22=1<<22;
-        uint32_t pow10=1<<10;
-        c_init1 = pow22*ceil(Nid/1024);
-        c_init2 = pow10*(slotNum+symNum+1)*(2*(Nid%1024)+1);
-        c_init3 = Nid%1024;
-        x2 = c_init1 + c_init2 + c_init3;
-
-        for (uint8_t n=0; n<NR_MAX_PRS_INIT_LENGTH_DWORD; n++) {
-          gNB->nr_gold_prs[rsc_id][slotNum][symNum][n] = lte_gold_generic(&x1, &x2, reset);      
-          reset = 0;
-          //printf("%d \n",gNB->nr_gold_prs[slotNum][symNum][n]); 
-        }
-      }
-    }
-  }
-}
diff --git a/openair1/PHY/NR_REFSIG/nr_gold_ue.c b/openair1/PHY/NR_REFSIG/nr_gold_ue.c
index f9c23b33b86..4cb75e0f780 100644
--- a/openair1/PHY/NR_REFSIG/nr_gold_ue.c
+++ b/openair1/PHY/NR_REFSIG/nr_gold_ue.c
@@ -22,43 +22,6 @@
 #include "refsig_defs_ue.h"
 #include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" // for lte_gold_generic()
 
-void init_nr_gold_prs(PHY_VARS_NR_UE* ue)
-{
-  unsigned int x1 = 0, x2 = 0;
-  uint16_t Nid;
-
-  NR_DL_FRAME_PARMS *fp = &ue->frame_parms;
-  uint8_t reset;
-  uint8_t slotNum, symNum, gnb, rsc;
-  
-  for(gnb = 0; gnb < ue->prs_active_gNBs; gnb++) {
-    for(rsc = 0; rsc < ue->prs_vars[gnb]->NumPRSResources; rsc++) {
-      Nid = ue->prs_vars[gnb]->prs_resource[rsc].prs_cfg.NPRSID; // seed value
-      LOG_I(PHY,"Initialised NR-PRS sequence with PRS_ID %3d for resource %d\n",Nid, rsc);
-      for (slotNum = 0; slotNum < fp->slots_per_frame; slotNum++) {
-        for (symNum = 0; symNum < fp->symbols_per_slot ; symNum++) {
-          reset = 1;
-          // initial x2 for prs as ts138.211
-          uint32_t c_init1, c_init2, c_init3;
-          uint32_t pow22=1<<22;
-          uint32_t pow10=1<<10;
-          c_init1 = pow22*ceil(Nid/1024);
-          c_init2 = pow10*(slotNum+symNum+1)*(2*(Nid%1024)+1);
-          c_init3 = Nid%1024;
-          x2 = c_init1 + c_init2 + c_init3;
-
-          for (uint8_t n=0; n<NR_MAX_PRS_INIT_LENGTH_DWORD; n++) {
-            ue->nr_gold_prs[gnb][rsc][slotNum][symNum][n] = lte_gold_generic(&x1, &x2, reset);      
-            reset = 0;
-            //printf("%d \n",gNB->nr_gold_prs[slotNum][symNum][n]); 
-	    
-          }
-        }
-      }
-    } // for rsc
-  } // for gnb
-}
-
 void sl_init_psbch_dmrs_gold_sequences(PHY_VARS_NR_UE *UE)
 {
   unsigned int x1, x2;
diff --git a/openair1/PHY/NR_REFSIG/nr_refsig.h b/openair1/PHY/NR_REFSIG/nr_refsig.h
index 97b2bb0d37a..8636c9972a7 100644
--- a/openair1/PHY/NR_REFSIG/nr_refsig.h
+++ b/openair1/PHY/NR_REFSIG/nr_refsig.h
@@ -26,14 +26,6 @@
 
 #include "PHY/defs_gNB.h"
 #include "openair1/PHY/NR_REFSIG/nr_refsig_common.h"
-#include "PHY/LTE_REFSIG/lte_refsig.h"
-#include "PHY/sse_intrin.h"
-
-/*
-This function generates NR Gold Sequence(ts 138.211) for the PRS.
-@param PHY_VARS_gNB* gNB structure provides configuration, frame parameters and the pointers to the 32 bits sequence storage tables
-*/
-void nr_init_prs(PHY_VARS_gNB* gNB);
 
 int nr_pusch_dmrs_delta(uint8_t dmrs_config_type, unsigned short p);
 
diff --git a/openair1/PHY/NR_REFSIG/nr_refsig_common.h b/openair1/PHY/NR_REFSIG/nr_refsig_common.h
index e43c9f10d13..46678424f67 100644
--- a/openair1/PHY/NR_REFSIG/nr_refsig_common.h
+++ b/openair1/PHY/NR_REFSIG/nr_refsig_common.h
@@ -30,5 +30,6 @@ uint32_t *nr_gold_pdcch(int N_RB_DL, int symbols_per_slot, unsigned short n_idDM
 uint32_t *nr_gold_pdsch(int N_RB_DL, int symbols_per_slot, int nid, int nscid, int slot, int symbol);
 uint32_t *nr_gold_pusch(int N_RB_UL, int symbols_per_slot, int Nid, int nscid, int slot, int symbol);
 uint32_t *nr_gold_csi_rs(int N_RB_DL, int symbols_per_slot, int slot, int symb, uint32_t Nid);
+uint32_t *nr_gold_prs(int nid, int slot, int symbol);
 
 #endif
diff --git a/openair1/PHY/NR_REFSIG/refsig.c b/openair1/PHY/NR_REFSIG/refsig.c
index 5946227d852..871e1aa8053 100644
--- a/openair1/PHY/NR_REFSIG/refsig.c
+++ b/openair1/PHY/NR_REFSIG/refsig.c
@@ -205,3 +205,16 @@ uint32_t *nr_gold_csi_rs(int N_RB_DL, int symbols_per_slot, int slot, int symb,
   uint32_t x2 = temp_x2 % (1U << 31);
   return gold_cache(x2, csi_dmrs_init_length);
 }
+
+uint32_t *nr_gold_prs(int Nid, int slotNum, int symNum)
+{
+  LOG_D(PHY, "Initialised NR-PRS sequence for PCI %d\n", Nid);
+  // initial x2 for prs as ts138.211
+  uint32_t pow22 = 1 << 22;
+  uint32_t pow10 = 1 << 10;
+  uint32_t c_init1 = pow22 * ceil(Nid / 1024);
+  uint32_t c_init2 = pow10 * (slotNum + symNum + 1) * (2 * (Nid % 1024) + 1);
+  uint32_t c_init3 = Nid % 1024;
+  uint32_t x2 = c_init1 + c_init2 + c_init3;
+  return gold_cache(x2, NR_MAX_PRS_INIT_LENGTH_DWORD);
+}
diff --git a/openair1/PHY/NR_REFSIG/refsig_defs_ue.h b/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
index 290ea89ffeb..7df105d05c8 100644
--- a/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
+++ b/openair1/PHY/NR_REFSIG/refsig_defs_ue.h
@@ -51,7 +51,6 @@ int nr_pdsch_dmrs_rx(const PHY_VARS_NR_UE *ue,
                      unsigned short nb_pdsch_rb,
                      uint8_t config_type);
 
-void init_nr_gold_prs(PHY_VARS_NR_UE* ue);
 void sl_generate_pss(SL_NR_UE_INIT_PARAMS_t *sl_init_params, uint8_t n_sl_id2, uint16_t scaling);
 void sl_generate_pss_ifft_samples(sl_nr_ue_phy_params_t *sl_ue_params, SL_NR_UE_INIT_PARAMS_t *sl_init_params);
 void sl_generate_sss(SL_NR_UE_INIT_PARAMS_t *sl_init_params, uint16_t slss_id, uint16_t scaling);
diff --git a/openair1/PHY/NR_TRANSPORT/nr_prs.c b/openair1/PHY/NR_TRANSPORT/nr_prs.c
index 4a93e4d66a4..382e995a653 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_prs.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_prs.c
@@ -3,18 +3,18 @@
 #include "PHY/LTE_REFSIG/lte_refsig.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
 #include "PHY/sse_intrin.h"
-
+#include "openair1/PHY/NR_REFSIG/refsig_defs_ue.h"
 //#define DEBUG_PRS_MOD
 //#define DEBUG_PRS_MAP
 
 extern short nr_qpsk_mod_table[8];
 
-int nr_generate_prs(uint32_t **nr_gold_prs,
-                          c16_t *txdataF,
-                          int16_t amp,
-                          prs_config_t *prs_cfg,
-                          nfapi_nr_config_request_scf_t *config,
-                          NR_DL_FRAME_PARMS *frame_parms)
+int nr_generate_prs(int slot,
+                    c16_t *txdataF,
+                    int16_t amp,
+                    prs_config_t *prs_cfg,
+                    nfapi_nr_config_request_scf_t *config,
+                    NR_DL_FRAME_PARMS *frame_parms)
 {
   
   int k_prime = 0, k = 0, idx;
@@ -42,8 +42,9 @@ int nr_generate_prs(uint32_t **nr_gold_prs,
     k = (prs_cfg->REOffset+k_prime) % prs_cfg->CombSize + prs_cfg->RBOffset*12 + frame_parms->first_carrier_offset;
     
     // QPSK modulation
+    uint32_t *gold = nr_gold_prs(prs_cfg->NPRSID, slot, l);
     for (int m = 0; m < (12/prs_cfg->CombSize) * prs_cfg->NumRB; m++) {
-      idx = (((nr_gold_prs[l][(m<<1)>>5])>>((m<<1)&0x1f))&3);
+      idx = (((gold[(m << 1) >> 5]) >> ((m << 1) & 0x1f)) & 3);
       mod_prs[m<<1] = nr_qpsk_mod_table[idx<<1];
       mod_prs[(m<<1)+1] = nr_qpsk_mod_table[(idx<<1) + 1];
       
diff --git a/openair1/PHY/NR_TRANSPORT/nr_scrambling.c b/openair1/PHY/NR_TRANSPORT/nr_scrambling.c
index 353db70454f..23c5aa9d4e9 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_scrambling.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_scrambling.c
@@ -21,6 +21,7 @@
 
 #include "nr_transport_common_proto.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
+#include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" // for lte_gold_generic()
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #define DEBUG_SCRAMBLING(a)
 //#define DEBUG_SCRAMBLING(a) a
diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
index 75d77f211a0..a8b9e8ebf68 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
@@ -40,7 +40,7 @@
 
 NR_gNB_PHY_STATS_t *get_phy_stats(PHY_VARS_gNB *gNB, uint16_t rnti);
 
-int nr_generate_prs(uint32_t **nr_gold_prs,
+int nr_generate_prs(int slot,
                     c16_t *txdataF,
                     int16_t amp,
                     prs_config_t *prs_cfg,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_uci_tools_common.c b/openair1/PHY/NR_TRANSPORT/nr_uci_tools_common.c
index 1c3d0f70084..da9f1acfe57 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_uci_tools_common.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_uci_tools_common.c
@@ -31,6 +31,8 @@
  */
 
 #include "nr_dci.h"
+#include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" // for lte_gold_generic()
+
 
 void nr_group_sequence_hopping(pucch_GroupHopping_t PUCCH_GroupHopping,
                                uint32_t n_id,
diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
index 05d7f038322..eee3778c6a9 100644
--- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c
+++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
@@ -43,6 +43,7 @@
 #include "PHY/sse_intrin.h"
 #include "PHY/NR_UE_TRANSPORT/pucch_nr.h"
 #include <openair1/PHY/CODING/nrSmallBlock/nr_small_block_defs.h>
+#include "openair1/PHY/LTE_TRANSPORT/transport_proto.h" // for lte_gold_generic()
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_transport_proto.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
index 2e3059ee9ce..4eec02d2404 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
@@ -89,9 +89,9 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
   memset(ch_tmp_buf,0,sizeof(ch_tmp_buf));
   memset(chF_interpol,0,sizeof(chF_interpol));
   memset(chT_interpol,0,sizeof(chF_interpol));
-  
-  int slot_prs           = (proc->nr_slot_rx - rep_num*prs_cfg->PRSResourceTimeGap + frame_params->slots_per_frame)%frame_params->slots_per_frame;
-  uint32_t **nr_gold_prs = ue->nr_gold_prs[gNB_id][rsc_id][slot_prs];
+
+  int slot_prs =
+      (proc->nr_slot_rx - rep_num * prs_cfg->PRSResourceTimeGap + frame_params->slots_per_frame) % frame_params->slots_per_frame;
 
   int16_t *rxF, *pil, mod_prs[NR_MAX_PRS_LENGTH << 1];
   const int16_t *fl, *fm, *fmm, *fml, *fmr, *fr;
@@ -113,6 +113,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
   int16_t k_prime_table[K_PRIME_TABLE_ROW_SIZE][K_PRIME_TABLE_COL_SIZE] = PRS_K_PRIME_TABLE;
   for(int l = prs_cfg->SymbolStart; l < prs_cfg->SymbolStart+prs_cfg->NumPRSSymbols; l++)
   {
+    uint32_t *gold_prs = nr_gold_prs(ue->prs_vars[gNB_id]->prs_resource[rsc_id].prs_cfg.NPRSID, slot_prs, l);
     int symInd = l-prs_cfg->SymbolStart;
     if (prs_cfg->CombSize == 2) {
       k_prime = k_prime_table[0][symInd];
@@ -135,7 +136,7 @@ int nr_prs_channel_estimation(uint8_t gNB_id,
     AssertFatal(num_pilots > 0, "num_pilots needs to be gt 0 or mod_prs[0] UB");
     for (int m = 0; m < num_pilots; m++) 
     {
-      idx = (((nr_gold_prs[l][(m<<1)>>5])>>((m<<1)&0x1f))&3);
+      idx = (((gold_prs[(m << 1) >> 5]) >> ((m << 1) & 0x1f)) & 3);
       mod_prs[m<<1]     = nr_qpsk_mod_table[idx<<1];
       mod_prs[(m<<1)+1] = nr_qpsk_mod_table[(idx<<1) + 1];
     } 
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index de83c257e5d..1cb7d256fdb 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -609,9 +609,6 @@ typedef struct PHY_VARS_gNB_s {
   /// PBCH interleaver
   uint8_t nr_pbch_interleaver[NR_POLAR_PBCH_PAYLOAD_BITS];
 
-  /// PRS sequence
-  uint32_t ****nr_gold_prs;
-
   /// PRACH root sequence
   c16_t X_u[64][839];
 
diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h
index 0dafde1ec2e..db3e47aa1de 100644
--- a/openair1/PHY/defs_nr_UE.h
+++ b/openair1/PHY/defs_nr_UE.h
@@ -408,9 +408,6 @@ typedef struct PHY_VARS_NR_UE_s {
 
 #endif
   // Scrambling IDs used in PUSCH DMRS
-  // PRS sequence per gNB, per resource
-  uint32_t *****nr_gold_prs;
-
   c16_t X_u[64][839];
 
   // flag to activate PRB based averaging of channel estimates
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 8386752e815..97205f28c74 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -179,7 +179,7 @@ void phy_procedures_gNB_TX(processingData_L1tx_t *msgTx,
       {
         slot_prs = (slot - i*prs_config->PRSResourceTimeGap + fp->slots_per_frame)%fp->slots_per_frame;
         LOG_D(PHY,"gNB_TX: frame %d, slot %d, slot_prs %d, PRS Resource ID %d\n",frame, slot, slot_prs, rsc_id);
-        nr_generate_prs(gNB->nr_gold_prs[rsc_id][slot_prs],&gNB->common_vars.txdataF[0][txdataF_offset], AMP, prs_config, cfg, fp);
+        nr_generate_prs(slot_prs, &gNB->common_vars.txdataF[0][txdataF_offset], AMP, prs_config, cfg, fp);
       }
     }
   }
-- 
GitLab