From 329b04dd4966c4989a0e08b1051ed47b696eba11 Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Thu, 9 Apr 2015 09:08:41 +0000
Subject: [PATCH] patches13/0001-minor.patch

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7047 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair1/PHY/LTE_ESTIMATION/lte_sync_time.c |  4 ++-
 openair1/PHY/extern.h                       | 12 ++++----
 targets/ARCH/COMMON/common_lib.h            | 31 +++++++++++----------
 targets/RT/USER/lte-ue.c                    | 18 +++++++-----
 4 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/openair1/PHY/LTE_ESTIMATION/lte_sync_time.c b/openair1/PHY/LTE_ESTIMATION/lte_sync_time.c
index 342642d226..be04416a6a 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_sync_time.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_sync_time.c
@@ -256,7 +256,9 @@ void lte_sync_time_free(void) {
   sync_corr_ue0 = NULL;
   sync_corr_ue1 = NULL;
   sync_corr_ue2 = NULL;
-
+  primary_synch0_time = NULL;
+  primary_synch1_time = NULL;
+  primary_synch2_time = NULL;
 }
 
 static inline int abs32(int x) {
diff --git a/openair1/PHY/extern.h b/openair1/PHY/extern.h
index 433e48330c..e28ad12581 100755
--- a/openair1/PHY/extern.h
+++ b/openair1/PHY/extern.h
@@ -66,12 +66,12 @@ extern short primary_synch2[144];
 extern unsigned char primary_synch0_tab[72];
 extern unsigned char primary_synch1_tab[72];
 extern unsigned char primary_synch2_tab[72];
-extern int16_t *primary_synch0_time;
-extern int16_t *primary_synch1_time;
-extern int16_t *primary_synch2_time;
-extern int *sync_corr_ue0;
-extern int *sync_corr_ue1;
-extern int *sync_corr_ue2;
+extern int16_t *primary_synch0_time; //!< index: [0..ofdm_symbol_size*2[
+extern int16_t *primary_synch1_time; //!< index: [0..ofdm_symbol_size*2[
+extern int16_t *primary_synch2_time; //!< index: [0..ofdm_symbol_size*2[
+extern int *sync_corr_ue0; //!< index [0..10*samples_per_tti[
+extern int *sync_corr_ue1; //!< index [0..10*samples_per_tti[
+extern int *sync_corr_ue2; //!< index [0..10*samples_per_tti[
 
 extern int flagMag;
 //extern short **txdataF_rep_tmp;
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index da14fd5639..f74e360503 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -52,33 +52,36 @@ typedef enum {
 
 
 typedef struct {
-  /* Module ID for this configuration */
+  //! Module ID for this configuration
   int Mod_id;
-  /* the sample rate for both transmit and receive. */
+  //! the sample rate for both transmit and receive.
   double sample_rate;
-  /* number of samples per RX/TX packet (USRP + Ethernet) */
+  //! number of samples per RX/TX packet (USRP + Ethernet)
   int samples_per_packet;
-  /* number of RX channels (=RX antennas) */
+  //! number of RX channels (=RX antennas)
   int rx_num_channels;
-  /* number of TX channels (=TX antennas) */
+  //! number of TX channels (=TX antennas)
   int tx_num_channels;
-  /* center frequency in Hz for RX */
+  //! \brief Center frequency in Hz for RX.
+  //! index: [0..rx_num_channels[
   double rx_freq[4];
-  /* center frequency in Hz for TX */
+  //! \brief Center frequency in Hz for TX.
+  //! index: [0..rx_num_channels[ !!! see lte-ue.c:427 FIXME iterates over rx_num_channels
   double tx_freq[4];
-  /* mode for rxgain (ExpressMIMO2)*/
+  //! mode for rxgain (ExpressMIMO2)
   rx_gain_t rxg_mode[4];
-  /* gain for RX in dB */
+  //! \brief Gain for RX in dB.
+  //! index: [0..rx_num_channels[
   double rx_gain[4];
-  /* gain for TX in dB */
+  //! gain for TX in dB
   double tx_gain[4];
-  /* RX bandwidth in Hz */
+  //! RX bandwidth in Hz
   double rx_bw;
-  /* TX bandwidth in Hz */
+  //! TX bandwidth in Hz
   double tx_bw;
-  /* RRH IP addr for Ethernet interface */
+  //! RRH IP addr for Ethernet interface
   char *rrh_ip;
-  /* RRH port number for Ethernet interface */
+  //! RRH port number for Ethernet interface
   int rrh_port;
 } openair0_config_t;
 
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 08936e7c46..98bee99d4f 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -412,8 +412,8 @@ static void *UE_thread_synch(void *arg) {
 	if (abs(openair_daq_vars.freq_offset) > 7500) {
 	  LOG_I(PHY,"[initial_sync] No cell synchronization found, abandoning\n");
 	  mac_xface->macphy_exit("No cell synchronization found, abandoning");
+          return; // not reached
 	}
-	else {
 	  LOG_I(PHY,"[initial_sync] trying carrier off %d Hz, rxgain %d (DL %u, UL %u)\n",openair_daq_vars.freq_offset,
 		UE->rx_total_gain_dB,
 		downlink_frequency[0][0]+openair_daq_vars.freq_offset,
@@ -461,7 +461,6 @@ static void *UE_thread_synch(void *arg) {
 	    
 	      //	      rt_sleep_ns(FRAME_PERIOD);
 
-	} // freq_offset
       } // initial_sync=0
       break;
     case si:
@@ -623,6 +622,9 @@ static void *UE_thread_tx(void *arg) {
   return(0);
 }
 
+//! \brief .
+//! This is a pthread.
+//! \param arg expects a pointer to \ref PHY_VARS_UE.
 static void *UE_thread_rx(void *arg) {
   
   PHY_VARS_UE *UE = (PHY_VARS_UE*)arg;
@@ -685,15 +687,17 @@ static void *UE_thread_rx(void *arg) {
     if (pthread_mutex_lock(&UE->mutex_rx) != 0) {
       LOG_E(PHY,"[SCHED][eNB] error locking mutex for UE RX\n");
       exit_fun("nothing to add");
+      break;
     }
-    else {
       
       while (UE->instance_cnt_rx < 0) {
 	pthread_cond_wait(&UE->cond_rx,&UE->mutex_rx);
       }
+
       if (pthread_mutex_unlock(&UE->mutex_rx) != 0) {	
 	LOG_E(PHY,"[SCHED][eNB] error unlocking mutex for UE RX\n");
 	exit_fun("nothing to add");
+        break;
       }
       
       for (i=0;i<2;i++) {
@@ -727,7 +731,6 @@ static void *UE_thread_rx(void *arg) {
 		  UE->frame_rx,UE->slot_tx>>1);
 	    UE->UE_mode[0] = RESYNCH;
 	    //     mac_xface->macphy_exit("Connection lost");
-	    //exit(-1);
 	  } 
 	  else if (ret == PHY_HO_PRACH) {
 	    LOG_I(PHY,"[UE %d] Frame %d, subframe %d, return to PRACH and perform a contention-free access\n",
@@ -759,9 +762,10 @@ static void *UE_thread_rx(void *arg) {
 	  }
 	}
 	//    printf("UE_thread_rx done\n");
-    }
-  }      
-  return(0);
+  }
+
+  // thread finished
+  return 0;
 }
     
 
-- 
2.26.2