From c76951a31904fbe73d04366cc3457f9ee13fd450 Mon Sep 17 00:00:00 2001
From: Sandeep Kumar <ee13b1025@iith.ac.in>
Date: Thu, 16 Jun 2016 12:49:15 +0200
Subject: [PATCH] handle per cc device for some tx/rx cases

---
 openair1/SCHED/phy_procedures_lte_eNb.c |  5 +++--
 targets/RT/USER/lte-enb.c               | 21 ++++++++++++++++-----
 targets/RT/USER/lte-softmodem.c         | 10 +++++++---
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 0e1685d2662..a42d01fd321 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -73,7 +73,8 @@ void exit_fun(const char* s);
 
 extern int exit_openair;
 
-extern openair0_device openair0;
+// Fix per CC openair rf/if device update
+// extern openair0_device openair0;
 
 unsigned char dlsch_input_buffer[2700] __attribute__ ((aligned(32)));
 int eNB_sync_buffer0[640*6] __attribute__ ((aligned(32)));
@@ -2522,7 +2523,7 @@ void phy_procedures_eNB_common_RX(PHY_VARS_eNB *eNB,const uint8_t abstraction_fl
 	  rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
 
 	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ, 1 );
-	rxs = openair0.trx_read_func(&openair0,
+	rxs = eNB->rfdevice.trx_read_func(&eNB->rfdevice,
 				     &proc->timestamp_rx,
 				     rxp,
 				     fp->samples_per_tti,
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index 373a13e1503..aa30f0874b2 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -120,8 +120,8 @@ struct timing_info_t {
   unsigned int n_samples;
 } timing_info;
 
-
-extern openair0_device openair0;
+// Fix per CC openair rf/if device update
+// extern openair0_device openair0;
 
 #if defined(ENABLE_ITTI)
 extern volatile int             start_eNB;
@@ -524,7 +524,7 @@ static void* eNB_thread_rxtx( void* param )
       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 
-      openair0.trx_write_func(&openair0,
+      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,
@@ -741,8 +741,19 @@ static void* eNB_thread_rx_common( void* param )
 #if defined(ENABLE_ITTI)
   wait_system_ready ("Waiting for eNB application to be ready %s\r", &start_eNB);
 #endif 
-  if (openair0.trx_start_func(&openair0) != 0 ) 
-    LOG_E(HW,"Could not start the device\n");
+  
+  // Start RF device for this CC
+  if (eNB->node_function == eNodeB_3GPP || eNB->node_function == NGFI_RRU_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->ifdevice.trx_start_func(&eNB->ifdevice) != 0 ) 
+      LOG_E(HW,"Could not start the IF device\n");
+  }
+
  // This is a forever while loop, it loops over subframes which are scheduled by incoming samples from HW devices
  while (!oai_exit) {
    
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 8a2d8d93601..97feaed9194 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -280,6 +280,9 @@ eth_params_t *eth_params;
 
 openair0_config_t openair0_cfg[MAX_CARDS];
 
+// Change to openair_global to handle UE
+openair0_device openair0;
+
 double cpuf;
 
 char uecap_xer[1024],uecap_xer_in=0;
@@ -1592,11 +1595,11 @@ int main( int argc, char **argv )
   }
   
   /* device host type is set*/
-  //openair0.host_type = BBU_HOST;
+  openair0.host_type = BBU_HOST;
   /* device type is initialized NONE_DEV (no RF device) when the RF device will be initiated device type will be set */
-  //openair0.type = NONE_DEV;
+  openair0.type = NONE_DEV;
   /* transport type is initialized NONE_TP (no transport protocol) when the transport protocol will be initiated transport protocol type will be set */
-  //openair0.transp_type = NONE_TP;
+  openair0.transp_type = NONE_TP;
   //openair0_cfg[0].log_level = glog_level;
   
   // Legacy BBU - RRH init  
@@ -1661,6 +1664,7 @@ int main( int argc, char **argv )
       else if (mode==loop_through_memory) {    
       }    
     }
+  }
 
   printf("Done initializing RF and IF devices\n");
   
-- 
GitLab