From 3f1e218a018de19f01860ac3f202946df74a1eb1 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Fri, 16 Jun 2017 11:51:10 +0200
Subject: [PATCH] pre-integration cleanup

---
 cmake_targets/CMakeLists.txt                  |  1 +
 .../PHY/LTE_ESTIMATION/lte_ue_measurements.c  |  4 +--
 openair1/PHY/LTE_TRANSPORT/dci_tools.c        | 27 ++++++++++---------
 .../PHY/LTE_TRANSPORT/dlsch_demodulation.c    | 12 +++++----
 openair1/SCHED/phy_procedures_lte_ue.c        |  3 ++-
 openair1/SIMULATION/LTE_PHY/dlsim_tm4.c       | 25 ++++++++++++-----
 6 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index a4aa081bec..83b9eb7c2f 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1915,6 +1915,7 @@ target_link_libraries (oaisim_nos1 forms)
 
 target_link_libraries (oaisim_nos1 ${T_LIB})
 
+
 # Unitary tests for each piece of L1: example, mbmssim is MBMS L1 simulator
 #####################################
 
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
index c47a64ae36..a836754c8f 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
@@ -32,8 +32,8 @@
 #define k1 ((long long int) 1000)
 #define k2 ((long long int) (1024-k1))
 
-#define DEBUG_MEAS_RRC
-#define DEBUG_MEAS_UE
+//#define DEBUG_MEAS_RRC
+//#define DEBUG_MEAS_UE
 //#define DEBUG_RANK_EST
 
 int16_t cond_num_threshold = 0;
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 9d63ac6ca7..56093dfa95 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -4997,19 +4997,19 @@ int check_dci_format2_2a_coherency(DCI_format_t dci_format,
     long long RIV_max = 0;
 
 #ifdef DEBUG_DCI
-    printf("extarcted dci - dci_format %d \n", dci_format);
-    printf("extarcted dci - rah        %d \n", rah);
-    printf("extarcted dci - mcs1       %d \n", mcs1);
-    printf("extarcted dci - mcs2       %d \n", mcs2);
-    printf("extarcted dci - rv1        %d \n", rv1);
-    printf("extarcted dci - rv2        %d \n", rv2);
-    //printf("extarcted dci - ndi1       %d \n", ndi1);
-   // printf("extarcted dci - ndi2       %d \n", ndi2);
-    printf("extarcted dci - rballoc    %x \n", rballoc);
-    printf("extarcted dci - harq pif   %d \n", harq_pid);
-    printf("extarcted dci - round0     %d \n", pdlsch0_harq->round);
-    printf("extarcted dci - round1     %d \n", pdlsch1_harq->round);
-
+    LOG_I(PHY, "extarcted dci - dci_format %d \n", dci_format);
+    LOG_I(PHY, "extarcted dci - rnti       %d \n", rnti);
+    LOG_I(PHY, "extarcted dci - rah        %d \n", rah);
+    LOG_I(PHY, "extarcted dci - mcs1       %d \n", mcs1);
+    LOG_I(PHY, "extarcted dci - mcs2       %d \n", mcs2);
+    LOG_I(PHY, "extarcted dci - rv1        %d \n", rv1);
+    LOG_I(PHY, "extarcted dci - rv2        %d \n", rv2);
+    //LOG_I(PHY, "extarcted dci - ndi1       %d \n", ndi1);
+    //LOG_I(PHY, "extarcted dci - ndi2       %d \n", ndi2);
+    LOG_I(PHY, "extarcted dci - rballoc    %x \n", rballoc);
+    LOG_I(PHY, "extarcted dci - harq pid   %d \n", harq_pid);
+    LOG_I(PHY, "extarcted dci - round0     %d \n", pdlsch0_harq->round);
+    LOG_I(PHY, "extarcted dci - round1     %d \n", pdlsch1_harq->round);
 #endif
 
     // I- check dci content minimum coherency
@@ -5528,6 +5528,7 @@ switch (tpmi) {
               dlsch_harq->pmi_alloc   = pmi_extend(frame_parms,3, 0);
             break;
             case 5:
+              dlsch_harq->mimo_mode   = PUSCH_PRECODING0;
               dlsch_harq->pmi_alloc   = pmi_alloc;//pmi_convert(frame_parms,dlsch0->pmi_alloc,0);
             break;
             case 6:
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
index 4733abdce1..e2e0d9acb9 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
@@ -48,6 +48,7 @@
  * default value: 0
  */
 int16_t dlsch_demod_shift = 0;
+int16_t interf_unaw_shift = 13;
 
 //#define DEBUG_HARQ
 
@@ -418,19 +419,20 @@ int rx_pdsch(PHY_VARS_UE *ue,
                                  nb_rb,
                                  dlsch0_harq->mimo_mode);
 
-      LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, interf_unaw_shift %d \n", avg_0[0],
+      LOG_D(PHY,"Channel Level TM34  avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0],
               avg_1[0], rx_type, rx_standard, dlsch_demod_shift);
         if (rx_type>rx_standard) {
-          avg_0[0] = (log2_approx(avg_0[0])/2) -13 + dlsch_demod_shift;// + 2 ;//+ 4;
-          avg_1[0] = (log2_approx(avg_1[0])/2) -13 + dlsch_demod_shift;// + 2 ;//+ 4;
+          avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
+          avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4;
           pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
           pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
          // printf("dlsch_demod_shift  %d\n", dlsch_demod_shift);
          }
           else {
-          avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + dlsch_demod_shift;
-          avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + dlsch_demod_shift;
+          avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift;
+          avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift;
           pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0);
+          pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0);
         }
       }
       else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6)
diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
index 41c72ec0e6..b045af747d 100644
--- a/openair1/SCHED/phy_procedures_lte_ue.c
+++ b/openair1/SCHED/phy_procedures_lte_ue.c
@@ -3694,7 +3694,7 @@ void process_rar(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, runmode_t mo
                                                  dlsch0->harq_processes[0]->b,
                                                  &ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->crnti,
                                                  ue->prach_resources[eNB_id]->ra_PreambleIndex,
-                                                 dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only
+                                                 dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload
       ue->pdcch_vars[(subframe_rx+1) & 0x1][eNB_id]->crnti = ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->crnti;
 
 
@@ -3978,6 +3978,7 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
 #endif
     }
 
+    // Check CRC for CW 0
     if (ret == (1+dlsch0->max_turbo_iterations)) {
       *dlsch_errors=*dlsch_errors+1;
 
diff --git a/openair1/SIMULATION/LTE_PHY/dlsim_tm4.c b/openair1/SIMULATION/LTE_PHY/dlsim_tm4.c
index 64ddd9ac31..ee333ac74f 100644
--- a/openair1/SIMULATION/LTE_PHY/dlsim_tm4.c
+++ b/openair1/SIMULATION/LTE_PHY/dlsim_tm4.c
@@ -625,10 +625,10 @@ int main(int argc, char **argv)
         rank_adapt=1;
         break;
       case 'V':
-        cond_num_threshold = atof(optarg);
+        cond_num_threshold = atoi(optarg);
         break;
       case 'J':
-        dlsch_demod_shift = atof(optarg);
+        dlsch_demod_shift = atoi(optarg);
         break;
       case 'K':
       tpmi_retr = atoi(optarg);
@@ -672,6 +672,16 @@ int main(int argc, char **argv)
     }
   }
 
+  if (dlsch_demod_shift==0) {
+    if ((transmission_mode==3 || transmission_mode==4) && (rx_type>rx_standard)) {
+      if (mcs1<17)
+        dlsch_demod_shift=0;
+      else
+       dlsch_demod_shift=-2;
+    }
+  }
+
+
   logInit();
   // enable these lines if you need debug info
   set_comp_log(PHY,LOG_DEBUG,LOG_HIGH,1);
@@ -719,10 +729,11 @@ int main(int argc, char **argv)
 
    if (transmission_mode==4 && rx_type == rx_SIC_dual_stream )
     use_sic_receiver = 1;
-  else if (transmission_mode==4 && rx_type == rx_IC_dual_stream )
+  else if (transmission_mode==4 && rx_type < rx_SIC_dual_stream )
     use_sic_receiver = 0;
 
 
+
   if (xforms==1) {
   fl_initialize (&argc, argv, NULL, 0, 0);
   form_ue = create_lte_phy_scope_ue();
@@ -3908,12 +3919,12 @@ int main(int argc, char **argv)
 #endif
 
                    if (transmission_mode==4 && use_sic_receiver==1){
-                    rx_type=rx_SIC_dual_stream;
-                    //printf("I am using SIC!\n");
+                    if (rx_type>rx_IC_single_stream)
+                      rx_type=rx_SIC_dual_stream;
                   }
                   else if (transmission_mode==4 && use_sic_receiver==0){
-                    rx_type=rx_IC_dual_stream;
-                  //printf("I am using PIA!\n");
+                    if (rx_type>rx_IC_single_stream)
+                      rx_type=rx_IC_dual_stream;
                 }
 
                       switch (transmission_mode) {
-- 
GitLab