From c5745c16226385fa4771eb3e60daa6cd5d6ea43b Mon Sep 17 00:00:00 2001
From: Sandeep Kumar <ee13b1025@iith.ac.in>
Date: Thu, 16 Jun 2016 17:44:05 +0200
Subject: [PATCH] highlight send/recv if4 -  midsave to swich pc

---
 openair1/PHY/LTE_TRANSPORT/if4_tools.c  | 33 +++++----
 openair1/PHY/LTE_TRANSPORT/prach.c      |  6 +-
 openair1/SCHED/phy_procedures_lte_eNb.c | 32 ++-------
 targets/RT/USER/lte-enb.c               | 89 ++++++++++++++-----------
 targets/RT/USER/lte-softmodem.c         |  4 +-
 5 files changed, 78 insertions(+), 86 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/if4_tools.c b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
index 06e057cdf0e..a8a27b2c090 100644
--- a/openair1/PHY/LTE_TRANSPORT/if4_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
@@ -38,16 +38,11 @@
 * \warning
 */
 
-#ifndef USER_MODE
-#include "if4_tools.h"
 #include <stdint.h>
-#else
-#include <stdint.h>
-#include "PHY/defs.h"
 
+#include "PHY/defs.h"
 #include "PHY/LTE_TRANSPORT/if4_tools.h"
 #include "PHY/TOOLS/ALAW/alaw_lut.h"
-#endif
 
 // Get device information
 void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc) {
@@ -70,6 +65,8 @@ void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc) {
     dl_packet->data_block = data_block;
 
     for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
+      
+      printf("\n Send IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);
 
       // Do compression of the two parts and generate data blocks			
       for (element_id=0; element_id<db_halflength; element_id++) {
@@ -84,14 +81,14 @@ void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc) {
       dl_packet->frame_status.sym_num = symbol_id; 
 			
       // Write the packet(s) to the fronthaul
-      //if ((bytes_sent = dev->eth_dev.trx_write_func (&dev->eth_dev,
-			//			                                         timestamp_rx,
-			//			                                         rx_eNB,
-			//			                                         spp_eth,
-			//			                                         dev->eth_dev.openair0_cfg->rx_num_channels,
-      //                                               0)) < 0) {
-      //  perror("RCC : ETHERNET write");
-      //}
+    //  if ((bytes_sent = eNB->ifdevice.trx_write_func(&eNB->ifdevice,
+    //                                                (proc->timestamp_tx-eNB->ifdevice.openair0_cfg.tx_sample_advance),
+    //  			                                         dl_packet,
+    //  			                                         eNB->frame_parms.samples_per_tti,
+    //  			                                         eNB->frame_parms.nb_antennas_tx,
+    //                                                 0)) < 0) {
+    //    perror("RCC : ETHERNET write");
+    //}
       
       slotoffsetF  += fp->ofdm_symbol_size;
       blockoffsetF += fp->ofdm_symbol_size;    
@@ -104,10 +101,10 @@ void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc) {
 
     for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
 
-      // Do compression of the two parts and generate data blocks			
+      // Do compression of the two parts and generate data blocks	- rxdataF		
       for (element_id=0; element_id<db_halflength; element_id++) {
-        data_block[element_id]  = lin2alaw[ (txdataF[0][blockoffsetF+element_id] & 0xffff) + 32768 ];          
-        data_block[element_id] |= lin2alaw[ (txdataF[0][blockoffsetF+element_id]>>16) + 32768 ]<<8;  
+        data_block[element_id]  = lin2alaw[ (rxdataF[0][blockoffsetF+element_id] & 0xffff) + 32768 ];          
+        data_block[element_id] |= lin2alaw[ (rxdataF[0][blockoffsetF+element_id]>>16) + 32768 ]<<8;  
         
         data_block[element_id+db_halflength]  = lin2alaw[ (txdataF[0][slotoffsetF+element_id] & 0xffff) + 32768 ];     
         data_block[element_id+db_halflength] |= lin2alaw[ (txdataF[0][slotoffsetF+element_id]>>16) + 32768 ]<<8;  
@@ -130,6 +127,8 @@ void recv_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t *packet_type, u
   // Caller: RRU - DL *** handle RCC case - UL and PRACH *** 
   if (eNB->node_function == NGFI_RRU_IF4) {
   
+    printf("\n Recv IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);
+  
 //    for(i=0; i<fp->symbols_per_tti; i++) {  
       // Read packet(s) from the fronthaul    
 //      if (dev->eth_dev.trx_read_func (&dev->eth_dev,
diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c
index 0f806e2ea1e..555685b23e1 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach.c
@@ -1269,16 +1269,16 @@ void rx_prach(PHY_VARS_eNB *eNB,
   }
 
   if (eNB->node_function == NGFI_RRU_IF4) {
-    //send prachF to RCC
+    /// **** send_IF4 of prachF to RCC **** ///
     return;
   }
+  
   // in case of RCC and prach received rx_thread wakes up prach
   //else if (eNB->node_function == NGFI_RCC_IF4) {
-    //wait for prachF from RRU and continue with PRACH processing
+  //  wait for prachF from RRU and continue with PRACH processing
   //}
 
 
-
   // here onwards is for eNodeB_3GPP or NGFI_RCC_IF4
 
   preamble_offset_old = 99;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index a42d01fd321..087404d10ae 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -1430,24 +1430,6 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 
 #endif
 
-  // Clean up split point *** RRU only function to recv and do_OFDM_mod ***  
-  if (eNB->node_function == eNodeB_3GPP) {
-    // Add above to IF4 split
-    // do_OFDM_mod
-    
-  }else if (eNB->node_function == NGFI_RCC_IF4) {
-	  //send_IF4(eNB,subframe<<1);
-	  //send_IF4(eNB,(subframe<<1)+1);
-    
-  }else if (eNB->node_function == NGFI_RRU_IF4) { // => acquisition from RCC (IF4)
-  	// get frame/subframe information from IF4 interface
-
-	  //recv_IF4(eNB,subframe<<1);
-	  //recv_IF4(eNB,1+(subframe<<1));
-    
-    //do_OFDM_mod   
-  }
-  
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX,0);
   stop_meas(&eNB->phy_proc_tx);
   
@@ -2572,12 +2554,14 @@ void phy_procedures_eNB_common_RX(PHY_VARS_eNB *eNB,const uint8_t abstraction_fl
     	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_SLOT_FEP,0);
 
 	if (eNB->node_function == NGFI_RRU_IF4) {
-	  //send_IF4(eNB,subframe<<1);
-	  //send_IF4(eNB,(subframe<<1)+1);
+    /// **** send_IF4 of rxdataF to RCC **** ///
+    /// Handle routing to prach thread for sending prach
 	}
 
       }
-      else if (eNB->node_function == NGFI_RCC_IF4) { // => acquisition from RRU (IF4)
+      else if (eNB->node_function == NGFI_RCC_IF4) {
+        /// **** recv_IF4 of rxdataF from RRU **** ///
+        /// **** recv_IF4 of prachF from RRU **** ///
 	      // get frame/subframe information from IF4 interface
 	      // timed loop (200 us)
 	
@@ -2598,11 +2582,7 @@ void phy_procedures_eNB_common_RX(PHY_VARS_eNB *eNB,const uint8_t abstraction_fl
 					  //symbol_mask = symbol_mask | (1<<symbol_number);
 					
 				//} while( (symbol_mask != symbol_mask_full) || (prach_rx == 0));    
-					 
-
-	      //recv_IF4(eNB,subframe<<1);
-	      //recv_IF4(eNB,1+(subframe<<1));
-	
+					 	
 	    // Tobi aka mr monaco: ETH
 	
 	    
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index aa30f0874b2..3afdb15ef1c 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -68,6 +68,8 @@
 
 //#undef FRAME_LENGTH_COMPLEX_SAMPLES //there are two conflicting definitions, so we better make sure we don't use it at all
 
+#include "PHY/LTE_TRANSPORT/if4_tools.h"
+
 #include "PHY/extern.h"
 #include "SCHED/extern.h"
 #include "LAYER2/MAC/extern.h"
@@ -494,50 +496,61 @@ static void* eNB_thread_rxtx( void* param )
 	  exit_fun("nothing to add");
 	  break;
 	}
+      } else {
+
+        /// **** recv_IF4 of txdataF from RCC **** ///        
+        //recv_IF4( eNB, proc, packet_type, symbol_number);        
+        
       }
     }
 
-    if (PHY_vars_eNB_g[0][proc->CC_id]->node_function != NGFI_RCC_IF4) {
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_SFGEN , 1 );
-      do_OFDM_mod_rt( proc->subframe_tx, PHY_vars_eNB_g[0][proc->CC_id] );
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_SFGEN , 0 );
-    /*
-      short *txdata = (short*)&PHY_vars_eNB_g[0][proc->CC_id]->common_vars.txdata[0][0][proc->subframe_tx*PHY_vars_eNB_g[0][proc->CC_id]->frame_parms.samples_per_tti];
-      int i;
-      for (i=0;i<PHY_vars_eNB_g[0][proc->CC_id]->frame_parms.samples_per_tti*2;i+=8) {
-      txdata[i] = 2047;
-      txdata[i+1] = 0;
-      txdata[i+2] = 0;
-      txdata[i+3] = 2047;
-      txdata[i+4] = -2047;
-      txdata[i+5] = 0;
-      txdata[i+6] = 0;
-      txdata[i+7] = -2047;      }
-    */
+  // eNodeB_3GPP and RRU create txdata and write to RF device
+  if (PHY_vars_eNB_g[0][proc->CC_id]->node_function != NGFI_RCC_IF4) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_SFGEN , 1 );
+    do_OFDM_mod_rt( proc->subframe_tx, PHY_vars_eNB_g[0][proc->CC_id] );
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_SFGEN , 0 );
+  /*
+    short *txdata = (short*)&PHY_vars_eNB_g[0][proc->CC_id]->common_vars.txdata[0][0][proc->subframe_tx*PHY_vars_eNB_g[0][proc->CC_id]->frame_parms.samples_per_tti];
+    int i;
+    for (i=0;i<PHY_vars_eNB_g[0][proc->CC_id]->frame_parms.samples_per_tti*2;i+=8) {
+    txdata[i] = 2047;
+    txdata[i+1] = 0;
+    txdata[i+2] = 0;
+    txdata[i+3] = 2047;
+    txdata[i+4] = -2047;
+    txdata[i+5] = 0;
+    txdata[i+6] = 0;
+    txdata[i+7] = -2047;      }
+  */
 
 
-      // Transmit TX buffer based on timestamp from RX
+    // Transmit TX buffer based on timestamp from RX
+  
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );
+    // prepare tx buffer pointers
+    int i;
+    for (i=0; i<PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx; i++)
+  txp[i] = (void*)&PHY_vars_eNB_g[0][0]->common_vars.txdata[0][i][proc->subframe_tx*PHY_vars_eNB_g[0][0]->frame_parms.samples_per_tti];
+    // if symb_written < spp ==> error 
+    PHY_vars_eNB_g[0][proc->CC_id]->rfdevice.trx_write_func(&PHY_vars_eNB_g[0][proc->CC_id]->rfdevice,
+          (proc->timestamp_tx-openair0_cfg[0].tx_sample_advance),
+          txp,
+          PHY_vars_eNB_g[0][0]->frame_parms.samples_per_tti,
+          PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx,
+          1);
     
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );
-      // prepare tx buffer pointers
-      int i;
-      for (i=0; i<PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx; i++)
-	txp[i] = (void*)&PHY_vars_eNB_g[0][0]->common_vars.txdata[0][i][proc->subframe_tx*PHY_vars_eNB_g[0][0]->frame_parms.samples_per_tti];
-      // if symb_written < spp ==> error 
-      PHY_vars_eNB_g[0][proc->CC_id]->rfdevice.trx_write_func(&PHY_vars_eNB_g[0][proc->CC_id]->rfdevice,
-			      (proc->timestamp_tx-openair0_cfg[0].tx_sample_advance),
-			      txp,
-			      PHY_vars_eNB_g[0][0]->frame_parms.samples_per_tti,
-			      PHY_vars_eNB_g[0][0]->frame_parms.nb_antennas_tx,
-			      1);
-      
 
-	
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 0 );
 
-      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (proc->timestamp_tx-openair0_cfg[0].tx_sample_advance)&0xffffffff );
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 0 );
 
-    }
+    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (proc->timestamp_tx-openair0_cfg[0].tx_sample_advance)&0xffffffff );
+
+  } else {  // RCC sends the txdataF using send_IF4 function
+
+    /// **** send_IF4 of txdataF to RRU **** ///    
+    //send_IF4(PHY_vars_eNB_g[0][proc->CC_id], proc);
+    
+  }
 
     if (pthread_mutex_lock(&proc->mutex_rxtx) != 0) {
       LOG_E( PHY, "[SCHED][eNB] error locking mutex for eNB TX proc\n");
@@ -743,13 +756,13 @@ static void* eNB_thread_rx_common( void* param )
 #endif 
   
   // Start RF device for this CC
-  if (eNB->node_function == eNodeB_3GPP || eNB->node_function == NGFI_RRU_IF4) {
+  if (eNB->node_function != NGFI_RCC_IF4) {
     if (eNB->rfdevice.trx_start_func(&eNB->rfdevice) != 0 ) 
       LOG_E(HW,"Could not start the RF device\n");
   }
     
   // Start IF device for this CC
-  if (eNB->node_function == NGFI_RCC_IF4 || eNB->node_function == NGFI_RRU_IF4) {
+  if (eNB->node_function != eNodeB_3GPP) {
     if (eNB->ifdevice.trx_start_func(&eNB->ifdevice) != 0 ) 
       LOG_E(HW,"Could not start the IF device\n");
   }
@@ -769,7 +782,7 @@ static void* eNB_thread_rx_common( void* param )
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_COMMON, 1 );
      // this spawns the prach inside and updates the frame and subframe counters
      phy_procedures_eNB_common_RX(eNB, 0);
-
+     
      
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_RX_COMMON, 0 );
    }
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 97feaed9194..efc2291dde1 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -1635,7 +1635,7 @@ int main( int argc, char **argv )
     
   // Handle spatially distributed MIMO antenna ports   
   // Load RF device and initialize
-  if (node_function == eNodeB_3GPP || node_function == NGFI_RRU_IF4) { 
+  if (node_function != NGFI_RCC_IF4) { 
     for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {  
       if (mode!=loop_through_memory) {
         returns=openair0_device_load(&(PHY_vars_eNB_g[0][CC_id]->rfdevice), &openair0_cfg[0]);
@@ -1651,7 +1651,7 @@ int main( int argc, char **argv )
   }  
   
   // Load transport protocol and initialize
-  if (node_function == NGFI_RCC_IF4 || node_function == NGFI_RRU_IF4){ 
+  if (node_function != eNodeB_3GPP){ 
     for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {  
       if (mode!=loop_through_memory) {
         returns=openair0_transport_load(&(PHY_vars_eNB_g[0][CC_id]->ifdevice), &openair0_cfg[0], (eth_params+CC_id));
-- 
GitLab