From 40adad6fc7f498ac9218f217b07e16e7fed1cb1f Mon Sep 17 00:00:00 2001
From: Florian Kaltenberger <florian.kaltenberger@eurecom.fr>
Date: Wed, 19 Jun 2019 22:50:38 +0200
Subject: [PATCH] fix after merge with develop-nr. however, I had to hardcode
 the parameters for the PUSCH in nr_ulsim as the fapi interface still has
 bugs.

---
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c  | 19 ++++-----
 openair1/SCHED_NR_UE/fapi_nr_ue_l1.c        |  1 +
 openair1/SCHED_NR_UE/phy_procedures_nr_ue.c |  6 +--
 openair1/SIMULATION/NR_PHY/ulsim.c          | 46 +++++++++++++++++----
 4 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 25b395bdf7a..7b161ac23d5 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -50,15 +50,12 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
                              unsigned char harq_pid){
 
   int N_PRB_oh, N_RE_prime, cwd_idx, length_dmrs, Nid_cell;
-  int nb_rb, Nsymb_pusch, first_rb, nb_codewords;
+  int nb_rb, Nsymb_pusch, first_rb, nb_codewords,mcs,rvidx;
   uint16_t n_rnti;
 
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
   NR_UE_ULSCH_t *ulsch_ue;
   NR_UL_UE_HARQ_t *harq_process_ul_ue;
 
-  ul_dci_pdu = &UE->dci_ind.dci_list[0].dci;
-
   //--------------------------Temporary configuration-----------------------------//
   length_dmrs = 1;
   n_rnti = 0x1234;
@@ -66,7 +63,9 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
   nb_rb = 50;
   first_rb = 30;
   Nsymb_pusch = 12;
-  nb_codewords = (ul_dci_pdu->precod_nbr_layers>4)?2:1;
+  nb_codewords = 1;
+  mcs = 9;
+  rvidx = 0;
   //------------------------------------------------------------------------------//
 
   for (cwd_idx = 0; cwd_idx < nb_codewords; cwd_idx++) {
@@ -87,19 +86,19 @@ int generate_ue_ulsch_params(PHY_VARS_NR_UE *UE,
 
     if (harq_process_ul_ue) {
 
-      harq_process_ul_ue->mcs                = ul_dci_pdu->mcs;
-      harq_process_ul_ue->Nl                 = ul_dci_pdu->precod_nbr_layers;
+      harq_process_ul_ue->mcs                = mcs;
+      harq_process_ul_ue->Nl                 = nb_codewords;
       harq_process_ul_ue->nb_rb              = nb_rb;
       harq_process_ul_ue->first_rb           = first_rb;
       harq_process_ul_ue->number_of_symbols  = Nsymb_pusch;
       harq_process_ul_ue->num_of_mod_symbols = N_RE_prime*nb_rb*nb_codewords;
-      harq_process_ul_ue->rvidx              = ul_dci_pdu->rv;
-      harq_process_ul_ue->TBS                = nr_compute_tbs(ul_dci_pdu->mcs,
+      harq_process_ul_ue->rvidx              = rvidx;
+      harq_process_ul_ue->TBS                = nr_compute_tbs(harq_process_ul_ue->mcs,
                                                               nb_rb,
                                                               Nsymb_pusch,
                                                               ulsch_ue->nb_re_dmrs,
                                                               length_dmrs,
-                                                              ul_dci_pdu->precod_nbr_layers);
+                                                              harq_process_ul_ue->Nl);
 
     }
 
diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
index a763b63765f..31a9f2058fb 100644
--- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
+++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
@@ -147,6 +147,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){
 	  ulsch0->harq_processes[current_harq_pid]->mcs = pusch_config_pdu->mcs;
 	  ulsch0->harq_processes[current_harq_pid]->DCINdi = pusch_config_pdu->ndi;
 	  ulsch0->harq_processes[current_harq_pid]->rvidx = pusch_config_pdu->rv;
+	  ulsch0->harq_processes[current_harq_pid]->Nl = pusch_config_pdu->n_layers;
 	  ulsch0->f_pusch = pusch_config_pdu->absolute_delta_PUSCH;
 	}
 	if(ul_config->ul_config_list[i].pdu_type == FAPI_NR_UL_CONFIG_TYPE_PUCCH){
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 43e6053216a..5cfea8115f2 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -2467,7 +2467,6 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t g
 
 
   NR_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
   NR_UE_ULSCH_t *ulsch_ue;
   NR_UL_UE_HARQ_t *harq_process_ul_ue;
   //int32_t ulsch_start=0;
@@ -2483,7 +2482,6 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t g
   start_meas(&ue->phy_proc_tx);
 #endif
 
-  ul_dci_pdu = &ue->dci_ind.dci_list[0].dci;
 
   harq_pid = 0; //temporary implementation
 
@@ -2497,7 +2495,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t g
   harq_process_ul_ue = ulsch_ue->harq_processes[harq_pid];
 
 
-  TBS = nr_compute_tbs(ul_dci_pdu->mcs, harq_process_ul_ue->nb_rb, ulsch_ue->Nsymb_pusch, ulsch_ue->nb_re_dmrs, ulsch_ue->length_dmrs, ul_dci_pdu->precod_nbr_layers);
+  TBS = nr_compute_tbs( harq_process_ul_ue->mcs, harq_process_ul_ue->nb_rb, ulsch_ue->Nsymb_pusch, ulsch_ue->nb_re_dmrs, ulsch_ue->length_dmrs, harq_process_ul_ue->Nl);
 
 //-----------------------------------------------------//
   // to be removed later when MAC is ready
@@ -2527,7 +2525,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t g
 
   nr_ue_pusch_common_procedures(ue,
                                 slot_tx,
-                                ul_dci_pdu->precod_nbr_layers,
+                                harq_process_ul_ue->Nl,
                                 &ue->frame_parms);
 
 
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 2895a5272ea..46ae206a3aa 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -55,6 +55,7 @@
 #include "PHY/TOOLS/tools_defs.h"
 #include "PHY/NR_TRANSPORT/nr_sch_dmrs.h"
 #include "PHY/phy_vars.h"
+#include "SCHED_NR_UE/fapi_nr_ue_l1.h"
 
 //#include "PHY/MODULATION/modulation_common.h"
 //#include "common/config/config_load_configmodule.h"
@@ -170,6 +171,7 @@ int main(int argc, char **argv) {
   int start_symbol = NR_SYMBOLS_PER_SLOT - nb_symb_sch;
   uint16_t nb_rb = 50;
   uint8_t Imcs = 9;
+  uint8_t precod_nbr_layers = 1;
   int gNB_id = 0;
   int ap;
   int tx_offset;
@@ -182,7 +184,6 @@ int main(int argc, char **argv) {
   cpuf = get_cpu_freq_GHz();
 
 
-  fapi_nr_dci_pdu_rel15_t *ul_dci_pdu;
   UE_nr_rxtx_proc_t UE_proc;
 
 
@@ -444,11 +445,6 @@ int main(int argc, char **argv) {
     }
   }
 
-  ul_dci_pdu = &UE->dci_ind.dci_list[0].dci;
-
-  ul_dci_pdu->mcs = Imcs;
-  ul_dci_pdu->rv = 0;
-  ul_dci_pdu->precod_nbr_layers = 1;
 
   unsigned char harq_pid = 0;
   unsigned int TBS = 8424;
@@ -459,14 +455,14 @@ int main(int argc, char **argv) {
 
   mod_order      = nr_get_Qm(Imcs, 1);
   available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1);
-  TBS            = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, ul_dci_pdu->precod_nbr_layers);
+  TBS            = nr_compute_tbs(Imcs, nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, precod_nbr_layers);
 
   NR_gNB_ULSCH_t *ulsch_gNB = gNB->ulsch[UE_id+1][0];
   nfapi_nr_ul_config_ulsch_pdu *rel15_ul = &ulsch_gNB->harq_processes[harq_pid]->ulsch_pdu;
   
   NR_UE_ULSCH_t **ulsch_ue = UE->ulsch[0][0];
 
-  // --------- setting rel15_ul parameters ----------
+  // --------- setting rel15_ul parameters for gNB --------
   rel15_ul->rnti                           = n_rnti;
   rel15_ul->ulsch_pdu_rel15.start_rb       = start_rb;
   rel15_ul->ulsch_pdu_rel15.number_rbs     = nb_rb;
@@ -477,9 +473,41 @@ int main(int argc, char **argv) {
   rel15_ul->ulsch_pdu_rel15.Qm             = mod_order;
   rel15_ul->ulsch_pdu_rel15.mcs            = Imcs;
   rel15_ul->ulsch_pdu_rel15.rv             = 0;
-  rel15_ul->ulsch_pdu_rel15.n_layers       = ul_dci_pdu->precod_nbr_layers;
+  rel15_ul->ulsch_pdu_rel15.ndi            = 0;
+  rel15_ul->ulsch_pdu_rel15.n_layers       = precod_nbr_layers;
   ///////////////////////////////////////////////////
 
+  nr_scheduled_response_t scheduled_response;
+  fapi_nr_ul_config_request_t ul_config;
+  //fapi_nr_tx_request_t tx_request;
+
+  scheduled_response.module_id = 0;
+  scheduled_response.CC_id = 0;
+  scheduled_response.frame = frame;
+  scheduled_response.slot = slot;
+  scheduled_response.dl_config = NULL;
+  scheduled_response.ul_config = &ul_config;
+  scheduled_response.dl_config = NULL;
+  
+
+  ul_config.sfn_slot = slot;
+  ul_config.number_pdus = 1;
+  ul_config.ul_config_list[0].pdu_type = FAPI_NR_UL_CONFIG_TYPE_PUSCH;
+  ul_config.ul_config_list[0].ulsch_config_pdu.rnti = n_rnti;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.number_rbs = nb_rb;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.start_rb = start_rb;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.number_symbols = nb_symb_sch;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.start_symbol = start_symbol;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.mcs = Imcs;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.ndi = 0;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.rv = 0;
+  ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.n_layers = precod_nbr_layers;
+  //there are plenty of other parameters that we don't seem to be using for now. e.g.
+  //ul_config.ul_config_list[0].ulsch_config_pdu.ulsch_pdu_rel15.absolute_delta_PUSCH = 0; 
+
+  // set FAPI parameters for UE, put them in the scheduled response and call 
+  //nr_ue_scheduled_response(&scheduled_response);
+
   unsigned char *estimated_output_bit;
   unsigned char *test_input_bit;
   unsigned int errors_bit = 0;
-- 
GitLab