From bed47a441d229dc556f54d3e1f9ec943051e81ab Mon Sep 17 00:00:00 2001
From: Raymond Knopp <florian.kaltenberger@eurecom.fr>
Date: Sun, 20 Mar 2016 21:24:38 +0100
Subject: [PATCH] activated 8-bit LLR decoding for DLSCH. added gtkw
 configuration for UE usrp.

---
 openair1/PHY/LTE_TRANSPORT/dci_tools.c        |  4 +-
 openair1/PHY/LTE_TRANSPORT/defs.h             |  4 ++
 openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c   |  4 ++
 .../PHY/LTE_TRANSPORT/dlsch_demodulation.c    |  2 +-
 openair1/PHY/LTE_TRANSPORT/print_stats.c      | 19 ++++++-
 openair1/SCHED/phy_procedures_lte_ue.c        |  4 +-
 targets/RT/USER/lte-ue.c                      | 10 ++++
 targets/RT/USER/ue_usrp.gtkw                  | 53 +++++++++++++++++++
 8 files changed, 93 insertions(+), 7 deletions(-)
 create mode 100644 targets/RT/USER/ue_usrp.gtkw

diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 3d8724fd4f..26c5d3667d 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -4467,7 +4467,7 @@ int generate_ue_dlsch_params_from_dci(int frame,
     dlsch[0]->g_pucch += delta_PUCCH_lut[TPC&3];
 
     if (TPC!=1)
-      LOG_I(PHY,"format1 TPC %d, dlsch0_harq->delta_PUCCH %d\n",TPC,dlsch0_harq->delta_PUCCH);
+      LOG_D(PHY,"format1 TPC %d, dlsch0_harq->delta_PUCCH %d\n",TPC,dlsch0_harq->delta_PUCCH);
 
     dlsch0_harq->rvidx     = rv;
 
@@ -4476,7 +4476,7 @@ int generate_ue_dlsch_params_from_dci(int frame,
 
     dlsch0_harq->dl_power_off = 1; //no power offset
 
-    LOG_D(PHY,"UE (%x/%d): Subframe %d Format2 DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch0_harq->DCINdi,
+    LOG_D(PHY,"UE (%x/%d): Subframe %d Format1 DCI: ndi %d, old_ndi %d (first tx %d) harq_status %d\n",dlsch[0]->rnti,harq_pid,subframe,ndi,dlsch0_harq->DCINdi,
           dlsch0_harq->first_tx,dlsch0_harq->status);
 
     //    printf("Format2 DCI (UE, hard pid %d): ndi %d, old_ndi %d (first tx %d)\n",harq_pid,ndi,dlsch0_harq->DCINdi,
diff --git a/openair1/PHY/LTE_TRANSPORT/defs.h b/openair1/PHY/LTE_TRANSPORT/defs.h
index 3cd608aa14..6c758b1c22 100644
--- a/openair1/PHY/LTE_TRANSPORT/defs.h
+++ b/openair1/PHY/LTE_TRANSPORT/defs.h
@@ -572,6 +572,10 @@ typedef struct {
   vrb_t vrb_type;
   /// downlink power offset field
   uint8_t dl_power_off;
+  /// trials per round statistics
+  uint32_t trials[8];
+  /// error statistics per round
+  uint32_t errors[8];
 } LTE_DL_UE_HARQ_t;
 
 typedef struct {
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
index efcd868338..c59652e2fa 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
@@ -243,6 +243,9 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
     return(max_turbo_iterations);
   }
   */
+
+  harq_process->trials[harq_process->round]++;
+
   A = harq_process->TBS; //2072 for QPSK 1/3
 
   ret = dlsch->max_turbo_iterations;
@@ -457,6 +460,7 @@ uint32_t  dlsch_decoding(PHY_VARS_UE *phy_vars_ue,
     dlsch->harq_ack[subframe].ack = 0;
     dlsch->harq_ack[subframe].harq_id = harq_pid;
     dlsch->harq_ack[subframe].send_harq_status = 1;
+    harq_process->errors[harq_process->round]++;
     harq_process->round++;
 
     //    LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round);
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
index de9acefb6e..f38cff301c 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_demodulation.c
@@ -281,7 +281,7 @@ int rx_pdsch(PHY_VARS_UE *phy_vars_ue,
     //  avgs = cmax(avgs,avg[(aarx<<1)+aatx]);
 
 
-    lte_ue_pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2);
+    lte_ue_pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1;
     // + log2_approx(frame_parms->nb_antennas_tx_eNB-1) //-1 because log2_approx counts the number of bits
     //      + log2_approx(frame_parms->nb_antennas_rx-1);
 
diff --git a/openair1/PHY/LTE_TRANSPORT/print_stats.c b/openair1/PHY/LTE_TRANSPORT/print_stats.c
index 032f8ce86f..839bc68190 100644
--- a/openair1/PHY/LTE_TRANSPORT/print_stats.c
+++ b/openair1/PHY/LTE_TRANSPORT/print_stats.c
@@ -61,6 +61,7 @@ int dump_ue_stats(PHY_VARS_UE *phy_vars_ue, char* buffer, int length, runmode_t
   uint8_t eNB=0;
   uint32_t RRC_status;
   int len=length;
+  int harq_pid,round;
 
   if (phy_vars_ue==NULL)
     return 0;
@@ -488,13 +489,27 @@ int dump_ue_stats(PHY_VARS_UE *phy_vars_ue, char* buffer, int length, runmode_t
       if (phy_vars_ue->transmission_mode[eNB] == 6)
         len += sprintf(&buffer[len], "[UE PROC] Mode 6 Wideband CQI eNB %d : %d dB\n",eNB,phy_vars_ue->PHY_measurements.precoded_cqi_dB[eNB][0]);
 
+      for (harq_pid=0;harq_pid<8;harq_pid++) {
+	len+=sprintf(&buffer[len],"[UE PROC] eNB %d: CW 0 harq_pid %d, mcs %d:",eNB,harq_pid,phy_vars_ue->dlsch_ue[0][0]->harq_processes[harq_pid]->mcs);
+	for (round=0;round<8;round++)
+	  len+=sprintf(&buffer[len],"%d/%d ",
+		       phy_vars_ue->dlsch_ue[0][0]->harq_processes[harq_pid]->errors[round],
+		       phy_vars_ue->dlsch_ue[0][0]->harq_processes[harq_pid]->trials[round]);
+	len+=sprintf(&buffer[len],"\n");
+      }
       if (phy_vars_ue->dlsch_ue[0] && phy_vars_ue->dlsch_ue[0][0] && phy_vars_ue->dlsch_ue[0][1]) {
         len += sprintf(&buffer[len], "[UE PROC] Saved PMI for DLSCH eNB %d : %jx (%p)\n",eNB,pmi2hex_2Ar1(phy_vars_ue->dlsch_ue[0][0]->pmi_alloc),phy_vars_ue->dlsch_ue[0][0]);
 
         len += sprintf(&buffer[len], "[UE PROC] eNB %d: dl_power_off = %d\n",eNB,phy_vars_ue->dlsch_ue[0][0]->harq_processes[0]->dl_power_off);
 
-        len += sprintf(&buffer[len], "[UE PROC] DL mcs1 (dlsch cw1) %d\n",phy_vars_ue->dlsch_ue[0][0]->harq_processes[0]->mcs);
-        len += sprintf(&buffer[len], "[UE PROC] DL mcs2 (dlsch cw2) %d\n",phy_vars_ue->dlsch_ue[0][1]->harq_processes[0]->mcs);
+	for (harq_pid=0;harq_pid<8;harq_pid++) {
+	  len+=sprintf(&buffer[len],"[UE PROC] eNB %d: CW 1 harq_pid %d, mcs %d:",eNB,harq_pid,phy_vars_ue->dlsch_ue[0][1]->harq_processes[0]->mcs);
+	  for (round=0;round<8;round++)
+	    len+=sprintf(&buffer[len],"%d/%d ",
+			 phy_vars_ue->dlsch_ue[0][1]->harq_processes[harq_pid]->errors[round],
+			 phy_vars_ue->dlsch_ue[0][1]->harq_processes[harq_pid]->trials[round]);
+	  len+=sprintf(&buffer[len],"\n");
+	}
       }
 
       len += sprintf(&buffer[len], "[UE PROC] DLSCH Total %d, Error %d, FER %d\n",phy_vars_ue->dlsch_received[0],phy_vars_ue->dlsch_errors[0],phy_vars_ue->dlsch_fer[0]);
diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
index cd452de193..1adf9931cd 100755
--- a/openair1/SCHED/phy_procedures_lte_ue.c
+++ b/openair1/SCHED/phy_procedures_lte_ue.c
@@ -2637,7 +2637,7 @@ int phy_procedures_UE_RX(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t abstrac
                                  phy_vars_ue->dlsch_ue[eNB_id][0]->harq_processes[harq_pid],
                                  subframe_prev,
                                  harq_pid,
-                                 1,0);
+                                 1,1);
             stop_meas(&phy_vars_ue->dlsch_decoding_stats);
           }
 
@@ -3320,7 +3320,7 @@ int phy_procedures_UE_RX(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t abstrac
                                phy_vars_ue->dlsch_ue_MCH[0]->harq_processes[0],
                                subframe_prev,
                                0,
-                               0,0);
+                               0,1);
         } else { // abstraction
 #ifdef PHY_ABSTRACTION
           ret = dlsch_decoding_emul(phy_vars_ue,
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 89aa19e8b9..7e67db5bc5 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -504,6 +504,16 @@ static void *UE_thread_synch(void *arg)
 	
 	  if (abs(freq_offset) > 7500) {
 	    LOG_I( PHY, "[initial_sync] No cell synchronization found, abandoning\n" );
+	    FILE *fd;
+	    if (fd = fopen("rxsig_frame0.dat","w")) {
+	      fwrite((void*)&UE->lte_ue_common_vars.rxdata[0][0],
+		     sizeof(int32_t),
+		     10*UE->lte_frame_parms.samples_per_tti,
+		     fd);
+	      LOG_I(PHY,"Dummping Frame ... bye bye \n");
+	      fclose(fd);
+	      exit(0);
+	    }
 	    mac_xface->macphy_exit("No cell synchronization found, abandoning");
 	    return &UE_thread_synch_retval; // not reached
 	  }
diff --git a/targets/RT/USER/ue_usrp.gtkw b/targets/RT/USER/ue_usrp.gtkw
new file mode 100644
index 0000000000..81940b5643
--- /dev/null
+++ b/targets/RT/USER/ue_usrp.gtkw
@@ -0,0 +1,53 @@
+[*]
+[*] GTKWave Analyzer v3.3.58 (w)1999-2014 BSI
+[*] Sun Mar 20 18:27:06 2016
+[*]
+[dumpfile] "/tmp/openair_dump_UE.vcd"
+[dumpfile_mtime] "Sun Mar 20 18:14:17 2016"
+[dumpfile_size] 92262400
+[savefile] "/home/papillon/openairinterface5g/targets/RT/USER/ue_usrp.gtkw"
+[timestart] 30032830000
+[size] 1215 640
+[pos] 105 102
+*-22.292629 30041590000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
+[sst_width] 224
+[signals_width] 262
+[sst_expanded] 1
+[sst_vpaned_height] 155
+@24
+variables.hw_subframe[63:0]
+@28
+functions.trx_read
+functions.trx_write
+@24
+variables.subframe_number_RX_UE[63:0]
+variables.subframe_number_TX_UE[63:0]
+@28
+functions.ue_thread_rx
+functions.ue_thread_tx
+@420
+variables.ue_inst_cnt_rx[63:0]
+variables.ue_inst_cnt_tx[63:0]
+@28
+functions.phy_procedures_ue_rx
+functions.phy_procedures_ue_tx
+@24
+variables.frame_number_RX_UE[63:0]
+variables.frame_number_TX_UE[63:0]
+@28
+functions.ue_slot_fep
+functions.lte_ue_measurement_procedures
+functions.ue_rrc_measurements
+functions.ue_gain_control
+functions.ue_adjust_synch
+functions.lte_ue_pbch_procedures
+functions.lte_ue_pdcch_procedures
+functions.rx_pdcch
+functions.dci_decoding
+functions.phy_ue_generate_prach
+functions.phy_ue_ulsch_encoding
+functions.phy_ue_ulsch_modulation
+functions.phy_ue_ulsch_scrambling
+functions.phy_ue_config_sib2
+[pattern_trace] 1
+[pattern_trace] 0
-- 
GitLab