From 7af3d98fd9bcc3cc2db773c6f682118e40a9e919 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Wed, 21 Sep 2016 17:23:50 +0200
Subject: [PATCH] bugfix in ulsch_decoding. removal of logging in pucch.c and
 usrp_lib.cpp.

---
 openair1/PHY/LTE_TRANSPORT/pucch.c            |  8 +--
 openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c   | 61 +++++++++++--------
 targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp  |  8 +--
 .../CONF/enb.band7.tm1.100PRB.usrpb210.conf   |  5 +-
 targets/RT/USER/lte-enb.c                     |  2 +-
 5 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/pucch.c b/openair1/PHY/LTE_TRANSPORT/pucch.c
index 507ff91199..7787ddfcf3 100644
--- a/openair1/PHY/LTE_TRANSPORT/pucch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pucch.c
@@ -1015,7 +1015,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
       *payload = 0;
       *Po_PUCCH1_below = ((*Po_PUCCH1_below<<9) + (stat_max<<9)+1024)>>10;
     }
-    printf("[eNB] PUCCH fmt1:  stat_max : %d, sigma2_dB %d (I0 %d dBm, thres %d), Po_PUCCH1_below/above : %d / %d\n",dB_fixed(stat_max),sigma2_dB,eNB->measurements[0].n0_subband_power_tot_dBm[6],pucch1_thres,dB_fixed(*Po_PUCCH1_below),dB_fixed(*Po_PUCCH1_above));
+    //printf("[eNB] PUCCH fmt1:  stat_max : %d, sigma2_dB %d (I0 %d dBm, thres %d), Po_PUCCH1_below/above : %d / %d\n",dB_fixed(stat_max),sigma2_dB,eNB->measurements[0].n0_subband_power_tot_dBm[6],pucch1_thres,dB_fixed(*Po_PUCCH1_below),dB_fixed(*Po_PUCCH1_above));
     *Po_PUCCH_update = 1;
     if (UE_id==0) {
       VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SR_ENERGY,dB_fixed(stat_max));
@@ -1107,18 +1107,18 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 
     stat_re=0;
     stat_im=0;
-    printf("PUCCH1A : Po_PUCCH before %d dB (%d)\n",dB_fixed(*Po_PUCCH),*Po_PUCCH);
+    //    printf("PUCCH1A : Po_PUCCH before %d dB (%d)\n",dB_fixed(*Po_PUCCH),*Po_PUCCH);
     *Po_PUCCH = ((*Po_PUCCH>>1) + ((stat_max)>>1));
     *Po_PUCCH_dBm = dB_fixed(*Po_PUCCH/frame_parms->N_RB_UL) - eNB->rx_total_gain_dB;
     *Po_PUCCH_update = 1;
- 
+    /*
     printf("PUCCH1A : stat_max %d (%d,%d,%d) => Po_PUCCH %d\n",
 	   dB_fixed(stat_max),
 	   pucch1_thres+sigma2_dB,
 	   pucch1_thres,
 	   sigma2_dB,
 	   dB_fixed(*Po_PUCCH));
-
+    */
     // Do detection now
     if (sigma2_dB<(dB_fixed(stat_max)-pucch1_thres))  {//
 
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 7141a4983d..de81897d5a 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -302,7 +302,7 @@ int ulsch_decoding_data_2thread0(td_params* tdp) {
   }
 
   // go through second half of segments
-  for (; r<(ulsch_harq->C/2); r++) {
+  for (; r<(ulsch_harq->C); r++) {
 
 
     //    printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]);
@@ -461,6 +461,7 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
   int Q_m = get_Qm_ul(ulsch_harq->mcs);
   int G = ulsch_harq->nb_rb * (12 * Q_m) * ulsch_harq->Nsymb_pusch;
   unsigned int E;
+  int Cby2;
 
   uint8_t (*tc)(int16_t *y,
                 uint8_t *,
@@ -489,38 +490,44 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
   else
     tc = phy_threegpplte_turbo_decoder8;
 
-  if (pthread_mutex_timedlock(&proc->mutex_td,&wait) != 0) {
-    printf("[eNB] ERROR pthread_mutex_lock for TD thread (IC %d)\n", proc->instance_cnt_td);
-    exit_fun( "error locking mutex_fep" );
-    return -1;
-  }
+  if (ulsch_harq->C>1) { // wakeup worker if more than 1 segment
+    if (pthread_mutex_timedlock(&proc->mutex_td,&wait) != 0) {
+      printf("[eNB] ERROR pthread_mutex_lock for TD thread (IC %d)\n", proc->instance_cnt_td);
+      exit_fun( "error locking mutex_fep" );
+      return -1;
+    }
+    
+    if (proc->instance_cnt_td==0) {
+      printf("[eNB] TD thread busy\n");
+      exit_fun("TD thread busy");
+      pthread_mutex_unlock( &proc->mutex_td );
+      return -1;
+    }
+    
+    ++proc->instance_cnt_td;
+    
+    proc->tdp.eNB       = eNB;
+    proc->tdp.UE_id     = UE_id;
+    proc->tdp.harq_pid  = harq_pid;
+    proc->tdp.llr8_flag = llr8_flag;
+    
+    
+    // wakeup worker to do second half segments 
+    if (pthread_cond_signal(&proc->cond_td) != 0) {
+      printf("[eNB] ERROR pthread_cond_signal for td thread exit\n");
+      exit_fun( "ERROR pthread_cond_signal" );
+      return (1+ulsch->max_turbo_iterations);
+    }
 
-  if (proc->instance_cnt_td==0) {
-    printf("[eNB] TD thread busy\n");
-    exit_fun("TD thread busy");
     pthread_mutex_unlock( &proc->mutex_td );
-    return -1;
+    Cby2 = ulsch_harq->C/2;
   }
-  
-  ++proc->instance_cnt_td;
-
-  proc->tdp.eNB       = eNB;
-  proc->tdp.UE_id     = UE_id;
-  proc->tdp.harq_pid  = harq_pid;
-  proc->tdp.llr8_flag = llr8_flag;
-
-  // wakeup worker to do second half segments 
-  if (pthread_cond_signal(&proc->cond_td) != 0) {
-    printf("[eNB] ERROR pthread_cond_signal for td thread exit\n");
-    exit_fun( "ERROR pthread_cond_signal" );
-    return (1+ulsch->max_turbo_iterations);
+  else {
+    Cby2 = 1;
   }
 
-  pthread_mutex_unlock( &proc->mutex_td );
-
-
   // go through first half of segments in main thread
-  for (r=0; r<(ulsch_harq->C/2); r++) {
+  for (r=0; r<Cby2; r++) {
 
     //    printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]);
     // Get Turbo interleaver parameters
diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
index 56a0f50ff4..1a23015cbb 100644
--- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
+++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
@@ -215,10 +215,10 @@ static int trx_usrp_write(openair0_device *device, openair0_timestamp timestamp,
   else
     time_avg=(time_diff+time_avg) /2.0;
 
-   //prints statics of uhd every 10 seconds
+  /*   //prints statics of uhd every 10 seconds
    if ( loop % (10 * ((int)device->openair0_cfg[0].sample_rate /(int)nsamps )) ==0)
      LOG_I(HW,"usrp_write: min(ns)=%d, max(ns)=%d, avg(ns)=%d\n", (int)time_min, (int)time_max,(int)time_avg);
-
+  */
    loop++;
   return ret;
 }
@@ -331,12 +331,12 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
     time_avg= time_diff;
   else
     time_avg=(time_diff+time_avg) /2.0;
-
+  /*
   //prints statics of uhd every 10 seconds
   if ( loop % (10 * ((int)device->openair0_cfg[0].sample_rate /(int)nsamps )) ==0)
      LOG_I(HW,"usrp_read: min(ns)=%d, max(ns)=%d, avg(ns)=%d\n", (int)time_min, (int)time_max,(int)time_avg);
 
-  loop++;
+     loop++;*/
   return samples_received;
 }
 
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpb210.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpb210.conf
index 10da79724a..fea29a7d59 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpb210.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpb210.conf
@@ -31,11 +31,12 @@ eNBs =
         tdd_config_s            			      = 0;
         prefix_type             			      = "NORMAL";
         eutra_band              			      = 7;
-        downlink_frequency      			      = 2680000000L;
+        downlink_frequency      			      = 2660000000L;
         uplink_frequency_offset 			      = -120000000;
         Nid_cell					      = 0;
         N_RB_DL                 			      = 100;
         Nid_cell_mbsfn          			      = 0;
+        nb_antenna_ports				      = 1;
         nb_antennas_tx          			      = 1;
         nb_antennas_rx          			      = 1;
         tx_gain                                            = 90;
@@ -100,6 +101,8 @@ eNBs =
         ue_TimersAndConstants_t311			      = 10000;
         ue_TimersAndConstants_n310			      = 20;
         ue_TimersAndConstants_n311			      = 1;
+
+	ue_TransmissionMode	   			      = 1;
       }
     );
 
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index a05b1c8a9d..b8ce8dba57 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -835,7 +835,7 @@ void rx_rf(PHY_VARS_eNB *eNB,int *frame,int *subframe) {
   void *rxp[fp->nb_antennas_rx],*txp[fp->nb_antennas_tx]; 
   unsigned int rxs,txs;
   int i;
-  int tx_sfoffset = 2;//(eNB->single_thread_flag == 1) ? 3 : 3;
+  int tx_sfoffset = 3;//(eNB->single_thread_flag == 1) ? 3 : 3;
   if (proc->first_rx==0) {
     
     // Transmit TX buffer based on timestamp from RX
-- 
GitLab