From 1d24208370e86894f1a3d99f625b3712f74a13d8 Mon Sep 17 00:00:00 2001
From: Wang Tsu-Han <wangts@eurecom.fr>
Date: Fri, 26 Oct 2018 17:33:46 +0200
Subject: [PATCH] bug fix for RU_mask_tx

---
 .../CONF/enb.band7.tm1.100PRB.usrpx310.conf          | 12 ++++++++++++
 targets/RT/USER/lte-enb.c                            |  5 ++---
 targets/RT/USER/lte-ru.c                             | 11 ++++++-----
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
index 728492ee83..f48357c13c 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.100PRB.usrpx310.conf
@@ -188,6 +188,18 @@ RUs = (
          max_rxgain                    = 116;
          eNB_instances  = [0];
        sdr_addrs      = "type=x300";
+    },
+    {
+       local_rf       = "yes"
+         nb_tx          = 1
+         nb_rx          = 1
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [7];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 116;
+         eNB_instances  = [0];
+       sdr_addrs      = "type=x300";
     }
 );  
 
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 271572060c..70317983f6 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -385,7 +385,6 @@ static void* L1_thread( void* param ) {
 
 
   PHY_VARS_eNB *eNB = RC.eNB[0][proc->CC_id];
-  //RU_proc_t *ru_proc = NULL;
 
   char thread_name[100];
 
@@ -477,7 +476,6 @@ int wakeup_txfh(eNB_rxtx_proc_t *proc,PHY_VARS_eNB *eNB) {
 
   RU_t *ru;
   RU_proc_t *ru_proc;
-  int i;
 
 
   struct timespec wait;
@@ -486,7 +484,7 @@ int wakeup_txfh(eNB_rxtx_proc_t *proc,PHY_VARS_eNB *eNB) {
 //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~inside wakeup_txfh %d.%d IC_RU = %d\n", proc->frame_tx, proc->subframe_tx, proc->instance_cnt_RUs);
 
   if(wait_on_condition(&proc->mutex_RUs,&proc->cond_RUs,&proc->instance_cnt_RUs,"wakeup_txfh")<0) {
-    LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", ru_proc->frame_tx, ru_proc->subframe_tx);
+    LOG_E(PHY,"Frame %d, subframe %d: TX FH not ready\n", proc->frame_tx, proc->subframe_tx);
     return(-1);
   }
   pthread_mutex_lock(&eNB->proc.mutex_RU_tx);
@@ -924,6 +922,7 @@ void init_eNB_proc(int inst) {
     proc->first_rx                 =1;
     proc->first_tx                 =1;
     proc->RU_mask_tx               = (1<<eNB->num_RU)-1;
+printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~proc->RU_mask_tx = %d\n", proc->RU_mask_tx);
     proc->RU_mask                  =0;
     proc->RU_mask_prach            =0;
 
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 42d71cfbf4..fdd364d574 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -1554,7 +1554,7 @@ static void* ru_thread_tx( void* param ) {
     if (oai_exit) break;   
 
 
-	LOG_D(PHY,"ru_thread_tx: Waiting for TX processing\n");
+	LOG_I(PHY,"ru_thread_tx: Waiting for TX processing\n");
 	// wait until eNBs are finished subframe RX n and TX n+4
     wait_on_condition(&proc->mutex_eNBs,&proc->cond_eNBs,&proc->instance_cnt_eNBs,"ru_thread_tx");
     if (oai_exit) break;
@@ -1580,23 +1580,24 @@ static void* ru_thread_tx( void* param ) {
       pthread_mutex_lock(&eNB_proc->mutex_RU_tx);
       for (int j=0;j<eNB->num_RU;j++) {
         if (ru == eNB->RU_list[j]) {
-          if ((eNB_proc->RU_mask_tx&(1<<i)) > 0)
+          if ((eNB_proc->RU_mask_tx&(1<<j)) > 0)
             LOG_E(PHY,"eNB %d frame %d, subframe %d : previous information from RU tx %d (num_RU %d,mask %x) has not been served yet!\n",
 	      eNB->Mod_id,eNB_proc->frame_rx,eNB_proc->subframe_rx,ru->idx,eNB->num_RU,eNB_proc->RU_mask_tx);
-          eNB_proc->RU_mask_tx |= (1<<i);
+          eNB_proc->RU_mask_tx |= (1<<j);
         }
       }
       if (eNB_proc->RU_mask_tx != (1<<eNB->num_RU)-1) {  // not all RUs have provided their information so return
-        LOG_E(PHY,"Not all RUs TX are finished\n");
+printf("~~~~~~~~~~~~~~~~~~~~~~(mask = %d)\n", eNB_proc->RU_mask_tx);
         pthread_mutex_unlock(&eNB_proc->mutex_RU_tx);
-        continue;
       }
       else { // all RUs TX are finished so send the ready signal to eNB processing
+printf("~~~~~~~~~~~~~~~~~~~~~~ready to send wakeup signal\n");
         eNB_proc->RU_mask_tx = 0;
         pthread_mutex_unlock(&eNB_proc->mutex_RU_tx);
 
         pthread_mutex_lock( &L1_proc->mutex_RUs);
         L1_proc->instance_cnt_RUs = 0;
+printf("~~~~~~~~~~~~~~~~~~~~~~ru_thread_tx send signal to L1_thread_tx with (mask = %d)\n", eNB_proc->RU_mask_tx);
         // the thread can now be woken up
         if (pthread_cond_signal(&L1_proc->cond_RUs) != 0) {
           LOG_E( PHY, "[eNB] ERROR pthread_cond_signal for eNB TXnp4 thread\n");
-- 
GitLab