From 21e1580be6b40992a9f44784f0a14f626cff83e2 Mon Sep 17 00:00:00 2001
From: laurent <laurent.thomas@open-cells.com>
Date: Mon, 18 Feb 2019 11:59:20 +0100
Subject: [PATCH] critical compilation warnings

---
 openair1/PHY/INIT/nr_init_ue.c                |  2 +-
 openair1/PHY/NR_UE_TRANSPORT/dci_nr.c         |  1 +
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   |  3 +-
 .../NR_UE_TRANSPORT/nr_dlsch_demodulation.c   |  2 +-
 openair1/PHY/NR_UE_TRANSPORT/nr_prach.c       |  2 +-
 openair1/SCHED_NR_UE/phy_procedures_nr_ue.c   | 26 +++---
 openair1/SCHED_NR_UE/pucch_uci_ue_nr.c        |  5 +-
 openair1/SCHED_UE/phy_procedures_lte_ue.c     | 18 ++--
 openair2/LAYER2/NR_MAC_UE/mac.h               |  2 +-
 openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c   |  3 +-
 targets/ARCH/rfsimulator/simulator.c          | 87 +++++++++----------
 targets/RT/USER/nr-ue.c                       | 43 +++------
 12 files changed, 86 insertions(+), 108 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index fc207cee84d..18bf3b423b1 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -919,7 +919,7 @@ void init_nr_ue_transport(PHY_VARS_NR_UE *ue,int abstraction_flag) {
 
   for (i=0; i<NUMBER_OF_CONNECTED_eNB_MAX; i++) {
     for (j=0; j<2; j++) {
-      for (k=0; k<2; k++) {
+      for (k=0; k<RX_NB_TH_MAX; k++) {
 	AssertFatal((ue->dlsch[k][i][j]  = new_nr_ue_dlsch(1,NUMBER_OF_HARQ_PID_MAX,NSOFT,MAX_LDPC_ITERATIONS,ue->frame_parms.N_RB_DL, abstraction_flag))!=NULL,"Can't get ue dlsch structures\n");
 
 	LOG_D(PHY,"dlsch[%d][%d][%d] => %p\n",k,i,j,ue->dlsch[i][j]);
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
index 3d481a0468a..4208f176565 100755
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
@@ -421,6 +421,7 @@ void nr_pdcch_extract_rbs_single(int32_t **rxdataF,
 #ifdef NR_PDCCH_DCI_DEBUG
       printf("\t\t<-NR_PDCCH_DCI_DEBUG (nr_pdcch_extract_rbs_single)-> c_rb=%d\n",c_rb);
 #endif
+      rxF=NULL;
       // first we set initial conditions for pointer to rxdataF depending on the situation of the first RB within the CORESET (c_rb = n_BWP_start)
       if ((c_rb < (frame_parms->N_RB_DL >> 1)) && ((frame_parms->N_RB_DL & 1) == 0)) {
         //if RB to be treated is lower than middle system bandwidth then rxdataF pointed at (offset + c_br + symbol * ofdm_symbol_size): even case
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index 2888a59606f..5f7a8c61cbc 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -516,7 +516,8 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
                            p_nrLDPC_procBuf[r],
                            p_procTime);
 
-		if (check_crc(llrProcBuf,harq_process->B,harq_process->F,crc_type)) {
+		// Fixme: correct type is unsigned, but nrLDPC_decoder and all called behind use signed int
+		if (check_crc((uint8_t*)llrProcBuf,harq_process->B,harq_process->F,crc_type)) {
 		  printf("CRC OK\n");
 		  ret = 2;
 		}
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
index a9f6b02567c..ca0aa50d0e8 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
@@ -1350,7 +1350,7 @@ void nr_dlsch_channel_compensation(int **rxdataF_ext,
   unsigned char aatx,aarx,pilots=0;
   __m128i *dl_ch128,*dl_ch128_2,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128,*rho128;
   __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128,QAM_amp128b;
-
+  QAM_amp128b = _mm_setzero_si128();
 
   if (symbol == 2){
       pilots=1;
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c
index 9c7146ca036..621318d2bc0 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c
@@ -577,7 +577,7 @@ int32_t generate_nr_prach( PHY_VARS_NR_UE *ue, uint8_t eNB_id, uint8_t subframe,
   uint8_t preamble_index     = ue->prach_resources[eNB_id]->ra_PreambleIndex;
   //uint8_t tdd_mapindex       = ue->prach_resources[eNB_id]->ra_TDD_map_index;
   int16_t *prachF           = ue->prach_vars[eNB_id]->prachF;
-  static int16_t prach_tmp[45600*2] __attribute__((aligned(32)));
+  static int16_t prach_tmp[45600*4] __attribute__((aligned(32)));
   int16_t *prach            = prach_tmp;
   int16_t *prach2;
   int16_t amp               = ue->prach_vars[eNB_id]->amp;
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 5eee7b9c0c4..60ab602432e 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -1595,22 +1595,10 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8
   int harq_pid;
   int frame_tx=proc->frame_tx;
   int nr_tti_tx=proc->nr_tti_tx;
-  int Mod_id = ue->Mod_id;
-  int CC_id = ue->CC_id;
-  uint8_t Msg3_flag=0;
-  uint16_t first_rb, nb_rb;
   unsigned int input_buffer_length;
   int i;
   int aa;
   int tx_amp;
-  uint8_t ulsch_input_buffer[5477] __attribute__ ((aligned(32)));
-  uint8_t access_mode;
-  uint8_t Nbundled=0;
-  uint8_t NbundledCw1=0;
-  uint8_t ack_status_cw0=0;
-  uint8_t ack_status_cw1=0;
-  uint8_t cqi_status = 0;
-  uint8_t ri_status  = 0;
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_IN);
 
   /* reset harq for tx of current rx slot because it is sure that transmission has already been achieved for this slot */
@@ -1621,6 +1609,18 @@ void ue_ulsch_uespec_procedures(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8
 
 #if 0
 
+  int Mod_id = ue->Mod_id;
+  int CC_id = ue->CC_id;
+  uint8_t Msg3_flag=0;
+  uint16_t first_rb, nb_rb;
+  uint8_t ulsch_input_buffer[5477] __attribute__ ((aligned(32)));
+  uint8_t access_mode;
+  uint8_t Nbundled=0;
+  uint8_t NbundledCw1=0;
+  uint8_t ack_status_cw0=0;
+  uint8_t ack_status_cw1=0;
+  uint8_t cqi_status = 0;
+  uint8_t ri_status  = 0;
   if (ue->mac_enabled == 1) {
     if ((ue->ulsch_Msg3_active[eNB_id] == 1) &&
 	(ue->ulsch_Msg3_frame[eNB_id] == frame_tx) &&
@@ -3079,7 +3079,7 @@ int nr_ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *
   int nb_searchspace_total = pdcch_vars2->nb_search_space;
 
   uint16_t c_rnti=pdcch_vars[eNB_id]->crnti;
-  uint16_t cs_rnti,new_rnti,tc_rnti;
+  uint16_t cs_rnti=0,new_rnti=0,tc_rnti;
   uint16_t p_rnti=P_RNTI;
   uint16_t si_rnti=SI_RNTI;
   uint16_t ra_rnti=99;
diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
index fb38c80eb8d..8ee2202d621 100644
--- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
+++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
@@ -36,6 +36,7 @@
 
 #include "PHY/NR_REFSIG/ss_pbch_nr.h"
 #include "PHY/defs_nr_UE.h"
+#include <openair1/SCHED/sched_common.h>
 
 #ifndef NO_RAT_NR
 
@@ -278,7 +279,7 @@ bool pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue, uint8_t gNB_id, UE_nr_rxtx_proc_
   /* Part - III */
   /* Choice PUCCH format and its related parameters */
   pucch_format_nr_t format = pucch_format0_nr;
-  uint8_t  starting_symbol_index;
+  uint8_t  starting_symbol_index=0;
   uint8_t nb_symbols_total = 0;
   uint8_t  nb_symbols = 0;
   uint16_t starting_prb = 0;;  /* it can be considered as first  hop on case of pucch hopping */
@@ -729,7 +730,7 @@ uint8_t get_downlink_ack(PHY_VARS_NR_UE *ue, uint8_t gNB_id,  UE_nr_rxtx_proc_t
         }
       }
       if (do_reset == TRUE) {
-        init_downlink_harq_status(&ue->dlsch[ue->current_thread_id[proc->nr_tti_rx]][gNB_id][code_word]->harq_processes[dl_harq_pid]);
+        init_downlink_harq_status(ue->dlsch[ue->current_thread_id[proc->nr_tti_rx]][gNB_id][code_word]->harq_processes[dl_harq_pid]);
       }
     }
   }
diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c
index bfb6b1b467d..c9ea45f03bf 100644
--- a/openair1/SCHED_UE/phy_procedures_lte_ue.c
+++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c
@@ -322,10 +322,10 @@ void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
 
   // if contention resolution fails, go back to PRACH
   PHY_vars_UE_g[Mod_id][CC_id]->UE_mode[eNB_index] = PRACH;
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[0][eNB_index]->crnti_is_temporary = 0;
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[0][eNB_index]->crnti = 0;
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti_is_temporary = 0;
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti = 0;
+  for (int i=0; i <RX_NB_TH_MAX; i++ ) {
+    PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[i][eNB_index]->crnti_is_temporary = 0;
+    PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[i][eNB_index]->crnti = 0;
+  }
   LOG_E(PHY,"[UE %d] Random-access procedure fails, going back to PRACH, setting SIStatus = 0, discard temporary C-RNTI and State RRC_IDLE\n",Mod_id);
 }
 
@@ -336,16 +336,18 @@ void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
 
   LOG_I(PHY,"[UE %d][RAPROC] Random-access procedure succeeded. Set C-RNTI = Temporary C-RNTI\n",Mod_id);
 
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[0][eNB_index]->crnti_is_temporary = 0;
-  PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti_is_temporary = 0;
+  for (int i=0; i <RX_NB_TH_MAX; i++ ) {
+    PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[i][eNB_index]->crnti_is_temporary = 0;
+  }
   PHY_vars_UE_g[Mod_id][CC_id]->ulsch_Msg3_active[eNB_index] = 0;
   PHY_vars_UE_g[Mod_id][CC_id]->UE_mode[eNB_index] = PUSCH;
 
   for (i=0; i<8; i++) {
     if (PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]) {
       PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]->status=SCH_IDLE;
-      PHY_vars_UE_g[Mod_id][CC_id]->dlsch[0][eNB_index][0]->harq_processes[i]->round=0;
-      PHY_vars_UE_g[Mod_id][CC_id]->dlsch[1][eNB_index][0]->harq_processes[i]->round=0;
+      for (int i=0; i <RX_NB_TH_MAX; i++ ) {
+        PHY_vars_UE_g[Mod_id][CC_id]->dlsch[i][eNB_index][0]->harq_processes[i]->round=0;
+      }
       PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]->subframe_scheduling_flag=0;
     }
   }
diff --git a/openair2/LAYER2/NR_MAC_UE/mac.h b/openair2/LAYER2/NR_MAC_UE/mac.h
index 65a00c9cea2..d0b6d4730d1 100644
--- a/openair2/LAYER2/NR_MAC_UE/mac.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac.h
@@ -65,7 +65,7 @@ typedef struct {
 } __attribute__ ((__packed__)) NR_MAC_SUBHEADER_LONG;
 
 typedef struct {
-    uint8_t LCID:5;     // octet 1 [5:0]
+    uint8_t LCID:6;     // octet 1 [5:0]
     uint8_t R:2;        // octet 1 [7:6]
 } __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED;
 
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
index 4e8b72614d2..1aeead9feb7 100644
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
@@ -74,7 +74,7 @@ int8_t handle_dlsch (module_id_t module_id, int cc_id, uint8_t gNB_index, fapi_n
   return nr_ue_process_dlsch( module_id,
 			      cc_id,
 			      gNB_index,
-			      &dci_ind,
+			      dci_ind,
 			      pduP,
 			      pdu_len);
 
@@ -308,4 +308,5 @@ int nr_ue_dcireq(nr_dcireq_t *dcireq) {
   dl_config->dl_config_list[0].dci_config_pdu.dci_config_rel15.N_RB_BWP = 106;
 
   
+  return 0;
 }
diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c
index 03084b538fe..e68db002cf7 100644
--- a/targets/ARCH/rfsimulator/simulator.c
+++ b/targets/ARCH/rfsimulator/simulator.c
@@ -39,7 +39,7 @@ typedef struct {
 
 typedef struct buffer_s {
   int conn_sock;
-  bool alreadyWrote;
+  bool alreadyRead;
   uint64_t lastReceivedTS;
   bool headerMode;
   transferHeader th;
@@ -49,7 +49,6 @@ typedef struct buffer_s {
   sample_t *circularBuf;
 } buffer_t;
 
-
 typedef struct {
   int listen_sock, epollfd;
   uint64_t nextTimestamp;
@@ -90,17 +89,41 @@ For this, export RFSIMULATOR=enb (eNB case) or \n\
                  RFSIMULATOR=<an ip address> (UE case)\n\
 \x1b[m"
 
-int fullwrite(int fd, void *_buf, int count) {
+enum  blocking_t {
+  notBlocking,
+  blocking
+};
+
+void setblocking(int sock, enum blocking_t active) {
+  int opts;
+  AssertFatal( (opts = fcntl(sock, F_GETFL)) >= 0,"");
+
+  if (active==blocking)
+    opts = opts & ~O_NONBLOCK;
+  else
+    opts = opts | O_NONBLOCK;
+
+  AssertFatal(fcntl(sock, F_SETFL, opts) >= 0, "");
+}
+
+static bool flushInput(rfsimulator_state_t *t);
+
+int fullwrite(int fd, void *_buf, int count, rfsimulator_state_t *t) {
   char *buf = _buf;
   int ret = 0;
   int l;
+    
+  setblocking(fd, notBlocking);
 
   while (count) {
     l = write(fd, buf, count);
-
     if (l <= 0) {
-      if(errno==EAGAIN || errno==EINTR)
+      if (errno==EINTR)
         continue;
+      if(errno==EAGAIN) {
+	flushInput(t);
+	continue;
+      }
       else
         return -1;
     }
@@ -113,23 +136,6 @@ int fullwrite(int fd, void *_buf, int count) {
   return ret;
 }
 
-enum  blocking_t {
-  blocking,
-  notBlocking
-};
-
-void setblocking(int sock, enum blocking_t active) {
-  int opts;
-  AssertFatal( (opts = fcntl(sock, F_GETFL)) >= 0,"");
-
-  if (active==blocking)
-    opts = opts & ~O_NONBLOCK;
-  else
-    opts = opts | O_NONBLOCK;
-
-  AssertFatal(fcntl(sock, F_SETFL, opts) >= 0, "");
-}
-
 int server_start(openair0_device *device) {
   rfsimulator_state_t *t = (rfsimulator_state_t *) device->priv;
   t->typeStamp=MAGICeNB;
@@ -177,7 +183,7 @@ int start_ue(openair0_device *device) {
 
   setblocking(sock, notBlocking);
   allocCirBuf(t, sock);
-  t->buf[sock].alreadyWrote=true; //+=t->initialAhead; // UE is slave
+  t->buf[sock].alreadyRead=true; // UE will start blocking on read
   return 0;
 }
 
@@ -188,10 +194,9 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi
     buffer_t *ptr=&t->buf[i];
 
     if (ptr->conn_sock >= 0 ) {
-      setblocking(ptr->conn_sock, blocking);
       transferHeader header= {t->typeStamp, nsamps, nbAnt, timestamp};
       int n=-1;
-      AssertFatal( fullwrite(ptr->conn_sock,&header, sizeof(header)) == sizeof(header), "");
+      AssertFatal( fullwrite(ptr->conn_sock,&header, sizeof(header), t) == sizeof(header), "");
       sample_t tmpSamples[nsamps][nbAnt];
 
       for(int a=0; a<nbAnt; a++) {
@@ -201,15 +206,13 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi
           tmpSamples[s][a]=in[s];
       }
 
-      n = fullwrite(ptr->conn_sock, (void *)tmpSamples, sampleToByte(nsamps,nbAnt));
+      n = fullwrite(ptr->conn_sock, (void *)tmpSamples, sampleToByte(nsamps,nbAnt), t);
 
       if (n != sampleToByte(nsamps,nbAnt) ) {
         LOG_E(HW,"rfsimulator: write error ret %d (wanted %ld) error %s\n", n, sampleToByte(nsamps,nbAnt), strerror(errno));
         abort();
       }
 
-      ptr->alreadyWrote=true; //+=nsamps;
-      setblocking(ptr->conn_sock, notBlocking);
     }
   }
 
@@ -218,7 +221,7 @@ int rfsimulator_write(openair0_device *device, openair0_timestamp timestamp, voi
   return nsamps;
 }
 
-bool flushInput(rfsimulator_state_t *t) {
+static bool flushInput(rfsimulator_state_t *t) {
   // Process all incoming events on sockets
   // store the data in lists
   struct epoll_event events[FD_SETSIZE]= {0};
@@ -237,6 +240,8 @@ bool flushInput(rfsimulator_state_t *t) {
     if (events[nbEv].events & EPOLLIN && fd == t->listen_sock) {
       int conn_sock;
       AssertFatal( (conn_sock = accept(t->listen_sock,NULL,NULL)) != -1, "");
+      setblocking(conn_sock, notBlocking);
+      
       allocCirBuf(t, conn_sock);
       LOG_I(HW,"A ue connected\n");
     } else {
@@ -287,7 +292,7 @@ bool flushInput(rfsimulator_state_t *t) {
         AssertFatal( (t->typeStamp == MAGICUE  && b->th.magic==MAGICeNB) ||
                      (t->typeStamp == MAGICeNB && b->th.magic==MAGICUE), "Socket Error in protocol");
         b->headerMode=false;
-
+	b->alreadyRead=true;
         if ( b->lastReceivedTS != b->th.timestamp) {
           int nbAnt= b->th.nbAnt;
 
@@ -347,13 +352,6 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
       t->nextTimestamp+=nsamps;
       LOG_W(HW,"Generated void samples for Rx: %ld\n", t->nextTimestamp);
 
-      for (int a=0; a<nbAnt; a++) {
-        sample_t *out=(sample_t *)samplesVoid[a];
-
-        for ( int i=0; i < nsamps; i++ )
-          out[i]=0;
-      }
-
       *ptimestamp = t->nextTimestamp-nsamps;
       return nsamps;
     }
@@ -365,7 +363,7 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
 
       for ( int sock=0; sock<FD_SETSIZE; sock++)
         if ( t->buf[sock].circularBuf &&
-             t->buf[sock].alreadyWrote && //>= t->initialAhead &&
+             t->buf[sock].alreadyRead && //>= t->initialAhead &&
              (t->nextTimestamp+nsamps) > t->buf[sock].lastReceivedTS ) {
           have_to_wait=true;
           break;
@@ -381,18 +379,14 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
   }
 
   // Clear the output buffer
-  for (int a=0; a<nbAnt; a++) {
-    sample_t *out=(sample_t *)samplesVoid[a];
-
-    for ( int i=0; i < nsamps; i++ )
-      out[i]=0;
-  }
+  for (int a=0; a<nbAnt; a++)
+    memset(samplesVoid[a],0,sampleToByte(nsamps,1));
 
   // Add all input signal in the output buffer
   for (int sock=0; sock<FD_SETSIZE; sock++) {
     buffer_t *ptr=&t->buf[sock];
 
-    if ( ptr->circularBuf && ptr->alreadyWrote ) {
+    if ( ptr->circularBuf && ptr->alreadyRead ) {
       for (int a=0; a<nbAnt; a++) {
         sample_t *out=(sample_t *)samplesVoid[a];
 
@@ -440,8 +434,7 @@ int rfsimulator_set_gains(openair0_device *device, openair0_config_t *openair0_c
 
 __attribute__((__visibility__("default")))
 int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
-  set_log(HW,OAILOG_DEBUG);
-  set_log(PHY,OAILOG_DEBUG);
+  //set_log(HW,OAILOG_DEBUG);
   rfsimulator_state_t *rfsimulator = (rfsimulator_state_t *)calloc(sizeof(rfsimulator_state_t),1);
 
   if ((rfsimulator->ip=getenv("RFSIMULATOR")) == NULL ) {
diff --git a/targets/RT/USER/nr-ue.c b/targets/RT/USER/nr-ue.c
index a857feac968..4003556bcbd 100644
--- a/targets/RT/USER/nr-ue.c
+++ b/targets/RT/USER/nr-ue.c
@@ -785,9 +785,8 @@ void *UE_thread(void *arg) {
     int i;
     char threadname[128];
     int th_id;
-    UE->proc.proc_rxtx[0].counter_decoder = 0;
-    UE->proc.proc_rxtx[1].counter_decoder = 0;
-    UE->proc.proc_rxtx[2].counter_decoder = 0;
+    for (int i=0; i<  RX_NB_TH_MAX; i++ ) 
+       UE->proc.proc_rxtx[i].counter_decoder = 0;
 
     static uint8_t thread_idx = 0;
 
@@ -827,7 +826,7 @@ void *UE_thread(void *arg) {
 	    usleep(500*1000);
 	  }
 #endif
-
+	  LOG_W(PHY,"is_synchro %d\n" ,  is_synchronized );
             if (instance_cnt_synch < 0) {  // we can invoke the synch
                 // grab 10 ms of signal and wakeup synch thread
 	if (UE->mode != loop_through_memory) {
@@ -843,14 +842,6 @@ void *UE_thread(void *arg) {
 						    rxp,
 						    UE->frame_parms.samples_per_subframe,
 						    UE->frame_parms.nb_antennas_rx), "");
-	    AssertFatal( UE->frame_parms.samples_per_subframe ==
-			 UE->rfdevice.trx_write_func(&UE->rfdevice,
-						     timestamp+(2*UE->frame_parms.samples_per_subframe) -
-						     openair0_cfg[0].tx_sample_advance,
-						     dummy_tx,
-						     UE->frame_parms.samples_per_subframe,
-						     UE->frame_parms.nb_antennas_tx,
-						     1),"");
 	  }
 	  for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
 	    free(dummy_tx[i]);
@@ -875,15 +866,7 @@ void *UE_thread(void *arg) {
 				       dummy_rx,
 				       UE->frame_parms.samples_per_subframe,
 				       UE->frame_parms.nb_antennas_rx);
-	  AssertFatal( UE->frame_parms.samples_per_subframe ==
-		       UE->rfdevice.trx_write_func(&UE->rfdevice,
-						   timestamp+(2*UE->frame_parms.samples_per_subframe) -
-						   openair0_cfg[0].tx_sample_advance,
-						   dummy_tx,
-						   UE->frame_parms.samples_per_subframe,
-						   UE->frame_parms.nb_antennas_tx,
-						   1),"");
-	   usleep(9000); // this sleep improves in the case of simulated RF and doesn't harm with true radio
+	   usleep(500); // this sleep improves in the case of simulated RF and doesn't harm with true radio
 	  
 	  }
 	  for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
@@ -911,14 +894,6 @@ void *UE_thread(void *arg) {
 							     (void**)UE->common_vars.rxdata,
 							     unitTransfer,
 							     UE->frame_parms.nb_antennas_rx),"");
-		      AssertFatal( unitTransfer == 
-				   UE->rfdevice.trx_write_func(&UE->rfdevice,
-							       timestamp+(2*UE->frame_parms.samples_per_subframe) -
-							       openair0_cfg[0].tx_sample_advance,
-							       dummy_tx,
-							       unitTransfer,
-							       UE->frame_parms.nb_antennas_tx,
-							       1),"");
 		    }
 		    for (int i=0; i<UE->frame_parms.nb_antennas_tx; i++)
 		      free(dummy_tx[i]);
@@ -995,9 +970,13 @@ void *UE_thread(void *arg) {
                                 UE->rx_offset < 10*UE->frame_parms.samples_per_subframe )
                             UE->rx_offset_diff = 1;
 
-                        LOG_E(PHY,"AbsSubframe %d.%d TTI SET rx_off_diff to %d rx_offset %d \n",proc->frame_rx,subframe_nr,UE->rx_offset_diff,UE->rx_offset);
-		        if ( getenv("RFSIMULATOR") != 0)
-			   UE->rx_offset_diff=0;	
+
+		        
+                        if ( getenv("RFSIMULATOR") != 0) {
+                           LOG_E(PHY,"AbsSubframe %d.%d TTI SET rx_off_diff to %d rx_offset %d \n",
+                           proc->frame_rx,subframe_nr,UE->rx_offset_diff,UE->rx_offset);
+			   //UE->rx_offset_diff=0;	
+                        }
                         readBlockSize=UE->frame_parms.samples_per_subframe -
                                       UE->frame_parms.ofdm_symbol_size -
                                       UE->frame_parms.nb_prefix_samples0 -
-- 
GitLab