From d8773fda4e993882e0161ef2c020128088128c39 Mon Sep 17 00:00:00 2001
From: winckel <winckel@eurecom.fr>
Date: Tue, 4 Feb 2014 15:57:39 +0000
Subject: [PATCH] Changed eNB configuration file reading position to update
 earlier physical parameters.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5025 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair2/ENB_APP/enb_app.c           |  7 ++-
 targets/RTAI/USER/lte-enb.c          | 41 ++++++++++-----
 targets/RTAI/USER/lte-softmodem.c    | 76 ++++++++++++++++++++++------
 targets/SIMU/USER/oaisim_functions.c | 28 ++++++++--
 4 files changed, 116 insertions(+), 36 deletions(-)

diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index afccaa471b..583e3e1c8a 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -49,7 +49,6 @@
 # endif
 
 extern unsigned char NB_eNB_INST;
-extern char         *g_conf_config_file_name;
 #endif
 
 #if defined(ENABLE_ITTI)
@@ -185,11 +184,11 @@ void *eNB_app_task(void *args_p)
 #   endif
 # endif
 
-    enb_properties = enb_config_init(g_conf_config_file_name);
+    enb_properties = enb_config_get();
 
     AssertFatal (enb_nb <= enb_properties->number,
-                 "Number of eNB is greater than eNB defined in configuration file %s (%d/%d)!",
-                 g_conf_config_file_name, enb_nb, enb_properties->number);
+                 "Number of eNB is greater than eNB defined in configuration file (%d/%d)!",
+                 enb_nb, enb_properties->number);
 
     for (enb_id = enb_id_start; (enb_id < enb_id_end) ; enb_id++)
     {
diff --git a/targets/RTAI/USER/lte-enb.c b/targets/RTAI/USER/lte-enb.c
index 379c734f2b..6234f230a8 100644
--- a/targets/RTAI/USER/lte-enb.c
+++ b/targets/RTAI/USER/lte-enb.c
@@ -93,6 +93,7 @@
 #include "UTIL/OTG/otg_vars.h"
 #include "UTIL/MATH/oml.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
+#include "enb_config.h"
 
 #if defined(ENABLE_ITTI)
 # include "intertask_interface_init.h"
@@ -166,7 +167,7 @@ u8 eNB_id=0;
 u32 carrier_freq_fdd[4]= {2680e6,0,0,0};
 u32 carrier_freq_tdd[4]= {2590e6-4000,0,0,0};
 u32 carrier_freq[4];
-char *g_conf_config_file_name = NULL;
+static char *conf_config_file_name = NULL;
 
 struct timing_info_t {
   //unsigned int frame, hw_slot, last_slot, next_slot;
@@ -636,6 +637,7 @@ static void *eNB_thread(void *arg)
 
 int main(int argc, char **argv)
 {
+  const Enb_properties_array_t *enb_properties;
 #ifdef RTAI
   RT_TASK *task;
 #endif
@@ -722,7 +724,7 @@ int main(int argc, char **argv)
 #endif
         break;
       case 'O':
-        g_conf_config_file_name = optarg;
+        conf_config_file_name = optarg;
         break;
       case 'R':
         N_RB_DL = atoi(optarg);
@@ -743,6 +745,26 @@ int main(int argc, char **argv)
     }
   }
 
+  NB_eNB_INST=1;
+  NB_INST=1;
+
+  if ((UE_flag == 0) && (conf_config_file_name != NULL)) {
+    int i;
+
+    /* Read eNB configuration file */
+    enb_properties = enb_config_init(conf_config_file_name);
+
+    AssertFatal (NB_eNB_INST <= enb_properties->number,
+                 "Number of eNB is greater than eNB defined in configuration file %s (%d/%d)!",
+                 conf_config_file_name, NB_eNB_INST, enb_properties->number);
+
+    /* Update some simulation parameters */
+    frame_type =        enb_properties->properties[0]->frame_type;
+    for (i = 0 ; i < (sizeof(carrier_freq) / sizeof (carrier_freq[0])); i++) {
+      carrier_freq[i] = enb_properties->properties[0]->downlink_frequency;
+    }
+  }
+
   set_taus_seed (0);
 
   // initialize the log (see log.h for details)
@@ -778,15 +800,16 @@ int main(int argc, char **argv)
                 Nid_cell, cooperation_flag, transmission_mode, abstraction_flag,
                 nb_antennas_rx,0);
 
-  g_log->log_component[HW].level = LOG_INFO;
+  g_log->level = LOG_WARNING;
+  g_log->log_component[HW].level = LOG_WARNING;
   g_log->log_component[HW].flag  = LOG_LOW;
-  g_log->log_component[PHY].level = LOG_INFO;
+  g_log->log_component[PHY].level = LOG_WARNING;
   g_log->log_component[PHY].flag  = LOG_LOW;
   g_log->log_component[MAC].level = LOG_INFO;
   g_log->log_component[MAC].flag  = LOG_LOW;
-  g_log->log_component[RLC].level = LOG_INFO;
+  g_log->log_component[RLC].level = LOG_WARNING;
   g_log->log_component[RLC].flag  = LOG_LOW;
-  g_log->log_component[PDCP].level = LOG_INFO;
+  g_log->log_component[PDCP].level = LOG_WARNING;
   g_log->log_component[PDCP].flag  = LOG_LOW;
   g_log->log_component[RRC].level = LOG_INFO;
   g_log->log_component[RRC].flag  = LOG_LOW;
@@ -824,17 +847,11 @@ int main(int argc, char **argv)
   }
 #endif
 
-
-  NB_eNB_INST=1;
-  NB_INST=1;
-
   openair_daq_vars.ue_dl_rb_alloc=0x1fff;
   openair_daq_vars.target_ue_dl_mcs=16;
   openair_daq_vars.ue_ul_nb_rb=6;
   openair_daq_vars.target_ue_ul_mcs=9;
 
-
-
   // set eNB to max gain
   PHY_vars_eNB_g[0]->rx_total_gain_eNB_dB =  rxg_max[0] + rxgain[0] -
       30; //was measured at rxgain=30;
diff --git a/targets/RTAI/USER/lte-softmodem.c b/targets/RTAI/USER/lte-softmodem.c
index d930ce0c9c..20de03a26f 100644
--- a/targets/RTAI/USER/lte-softmodem.c
+++ b/targets/RTAI/USER/lte-softmodem.c
@@ -100,6 +100,7 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include "UTIL/OTG/otg_vars.h"
 #include "UTIL/MATH/oml.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
+#include "enb_config.h"
 
 #if defined(ENABLE_ITTI)
 # include "intertask_interface_init.h"
@@ -167,8 +168,10 @@ int fs4_test=0;
 char UE_flag=0;
 u8  eNB_id=0,UE_id=0;
 
-u32 carrier_freq[4]= {1907600000,1907600000,1907600000,1907600000};
-char *g_conf_config_file_name = NULL;
+u32 carrier_freq[4] =           {1907600000,1907600000,1907600000,1907600000}; /* For UE! */
+u32 downlink_frequency[4] =     {1907600000,1907600000,1907600000,1907600000};
+s32 uplink_frequency_offset[4]= {-120000000,-120000000,-120000000,-120000000};
+static char *conf_config_file_name = NULL;
 
 struct timing_info_t {
   //unsigned int frame, hw_slot, last_slot, next_slot;
@@ -1013,6 +1016,7 @@ static void *UE_thread(void *arg)
 }
 
 int main(int argc, char **argv) {
+  const Enb_properties_array_t *enb_properties;
 
 #ifdef RTAI
   // RT_TASK *task;
@@ -1106,10 +1110,14 @@ int main(int argc, char **argv) {
           UE_flag = 1;
           break;
         case 'C':
-          carrier_freq[0] = atoi(optarg);
-          carrier_freq[1] = atoi(optarg);
-          carrier_freq[2] = atoi(optarg);
-          carrier_freq[3] = atoi(optarg);
+          downlink_frequency[0] = atoi(optarg);
+          downlink_frequency[1] = atoi(optarg);
+          downlink_frequency[2] = atoi(optarg);
+          downlink_frequency[3] = atoi(optarg);
+          carrier_freq[0] = downlink_frequency[0];
+          carrier_freq[1] = downlink_frequency[1];
+          carrier_freq[2] = downlink_frequency[2];
+          carrier_freq[3] = downlink_frequency[3];
           break;
         case 'S':
           fs4_test=1;
@@ -1127,7 +1135,7 @@ int main(int argc, char **argv) {
 #endif
           break;
         case 'O':
-          g_conf_config_file_name = optarg;
+          conf_config_file_name = optarg;
           break;
         case 'F':
           sprintf(rxg_fname,"%srxg.lime",optarg);
@@ -1214,6 +1222,28 @@ int main(int argc, char **argv) {
         }
     }
 
+  frame_parms = (LTE_DL_FRAME_PARMS*) malloc(sizeof(LTE_DL_FRAME_PARMS));
+
+  if ((UE_flag == 0) && (conf_config_file_name != NULL)) {
+    int i;
+
+    NB_eNB_INST = 1;
+
+    /* Read eNB configuration file */
+    enb_properties = enb_config_init(conf_config_file_name);
+
+    AssertFatal (NB_eNB_INST <= enb_properties->number,
+                 "Number of eNB is greater than eNB defined in configuration file %s (%d/%d)!",
+                 conf_config_file_name, NB_eNB_INST, enb_properties->number);
+
+    /* Update some simulation parameters */
+    frame_parms->frame_type =   enb_properties->properties[0]->frame_type;
+    for (i = 0 ; i < (sizeof(downlink_frequency) / sizeof (downlink_frequency[0])); i++) {
+      downlink_frequency[i] =       enb_properties->properties[0]->downlink_frequency;
+      uplink_frequency_offset[i] =  enb_properties->properties[0]->uplink_frequency_offset;
+    }
+  }
+
   if (UE_flag==1)
     printf("configuring for UE\n");
   else
@@ -1258,7 +1288,6 @@ int main(int argc, char **argv) {
 #endif
 
   // init the parameters
-  frame_parms = (LTE_DL_FRAME_PARMS*) malloc(sizeof(LTE_DL_FRAME_PARMS));
   frame_parms->N_RB_DL            = 25;
   frame_parms->N_RB_UL            = 25;
   frame_parms->Ncp                = 0;
@@ -1288,7 +1317,6 @@ int main(int argc, char **argv) {
   }
   frame_parms->nb_antennas_tx_eNB = (transmission_mode == 1) ? 1 : 2; //initial value overwritten by initial sync later
   frame_parms->mode1_flag         = (transmission_mode == 1) ? 1 : 0;
-  frame_parms->frame_type         = 1;
   frame_parms->tdd_config         = 3;
   frame_parms->tdd_config_S       = 0;
   frame_parms->phich_config_common.phich_resource = oneSixth;
@@ -1314,6 +1342,7 @@ int main(int argc, char **argv) {
   // prach_fmt = get_prach_fmt(frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->frame_type);
   // N_ZC = (prach_fmt <4)?839:139;
 
+  g_log->level = LOG_WARNING;
   if (UE_flag==1) {
     g_log->log_component[HW].level = LOG_DEBUG;
     g_log->log_component[HW].flag  = LOG_HIGH;
@@ -1532,6 +1561,8 @@ int main(int argc, char **argv) {
   for (ant=max(frame_parms->nb_antennas_tx,frame_parms->nb_antennas_rx);ant<4;ant++) {
     p_exmimo_config->rf.rf_mode[ant] = 0;
     carrier_freq[ant] = 0; //this turns off all other LIMEs
+    downlink_frequency[ant] = 0; //this turns off all other LIMEs
+    uplink_frequency_offset[ant] = 0;
   }
 
   /*
@@ -1545,26 +1576,42 @@ int main(int argc, char **argv) {
     }
     else {
       p_exmimo_config->rf.rf_mode[ant] = 0;
-      carrier_freq[ant] = 0; //this turns off all other LIMEs
+      downlink_frequency[ant] = 0; //this turns off all other LIMEs
     }
   }
   */
 
   for (ant = 0; ant<4; ant++) { 
     p_exmimo_config->rf.do_autocal[ant] = 1;
-    p_exmimo_config->rf.rf_freq_rx[ant] = carrier_freq[ant];
-    p_exmimo_config->rf.rf_freq_tx[ant] = carrier_freq[ant];
+    if (UE_flag==0) {
+      /* eNB */
+      if (frame_parms->frame_type == FDD) {
+        p_exmimo_config->rf.rf_freq_rx[ant] = downlink_frequency[ant] + uplink_frequency_offset[ant];
+      } else {
+        p_exmimo_config->rf.rf_freq_rx[ant] = downlink_frequency[ant];
+      }
+      p_exmimo_config->rf.rf_freq_tx[ant] = downlink_frequency[ant];
+    } else {
+      /* UE */
+      p_exmimo_config->rf.rf_freq_rx[ant] = carrier_freq[ant];
+      if (frame_parms->frame_type == FDD) {
+        p_exmimo_config->rf.rf_freq_tx[ant] = carrier_freq[ant] + uplink_frequency_offset[ant];
+      } else {
+        p_exmimo_config->rf.rf_freq_tx[ant] = carrier_freq[ant];
+      }
+    }
+
     p_exmimo_config->rf.rx_gain[ant][0] = rxgain[ant];
     p_exmimo_config->rf.tx_gain[ant][0] = txgain[ant];
     
     p_exmimo_config->rf.rf_local[ant]   = rf_local[ant];
     p_exmimo_config->rf.rf_rxdc[ant]    = rf_rxdc[ant];
 
-    if ((carrier_freq[ant] >= 850000000) && (carrier_freq[ant] <= 865000000)) {
+    if ((downlink_frequency[ant] >= 850000000) && (downlink_frequency[ant] <= 865000000)) {
       p_exmimo_config->rf.rf_vcocal[ant]  = rf_vcocal_850[ant];
       p_exmimo_config->rf.rffe_band_mode[ant] = DD_TDD;	    
     }
-    else if ((carrier_freq[ant] >= 1900000000) && (carrier_freq[ant] <= 2000000000)) {
+    else if ((downlink_frequency[ant] >= 1900000000) && (downlink_frequency[ant] <= 2000000000)) {
       p_exmimo_config->rf.rf_vcocal[ant]  = rf_vcocal[ant];
       p_exmimo_config->rf.rffe_band_mode[ant] = B19G_TDD;	    
     }
@@ -1579,7 +1626,6 @@ int main(int argc, char **argv) {
     p_exmimo_config->rf.rffe_gain_rxlow[ant] = 31;
   }
 
-
   dump_frame_parms(frame_parms);
   
   mac_xface = malloc(sizeof(MAC_xface));
diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c
index c34e6ddc1d..dd553f6358 100644
--- a/targets/SIMU/USER/oaisim_functions.c
+++ b/targets/SIMU/USER/oaisim_functions.c
@@ -7,6 +7,7 @@
 
 #include <sys/timerfd.h>
 
+#include "assertions.h"
 #include "oaisim_functions.h"
 
 #include "PHY/extern.h"
@@ -29,6 +30,7 @@
 #include "lteRALue.h"
 
 #include "cor_SF_sim.h"
+#include "enb_config.h"
 
 #if defined(ENABLE_ITTI)
 # include "intertask_interface.h"
@@ -53,7 +55,7 @@ int otg_times = 0;
 int if_times = 0;
 int for_times = 0;
 
-char *g_conf_config_file_name = NULL;
+static char *conf_config_file_name = NULL;
 u16 Nid_cell = 0; //needed by init_lte_vars
 int nb_antennas_rx=2; // //
 u8 target_dl_mcs = 0;
@@ -168,14 +170,15 @@ static struct option long_options[] = {
 };
 
 void get_simulation_options(int argc, char *argv[]) {
-  int option;
+  int                           option;
+  const Enb_properties_array_t *enb_properties;
 
   while ((option = getopt_long (argc, argv, "aA:b:B:c:C:D:d:eE:f:FGg:hHi:IJ:j:k:K:l:L:m:M:n:N:oO:p:P:Q:rR:s:S:t:T:u:U:vV:w:W:x:X:y:Y:z:Z:", long_options, NULL)) != -1) {
     switch (option) {
     case LONG_OPTION_ENB_CONF:
       if (optarg) {
-          g_conf_config_file_name = strdup(optarg);
-          printf("eNB configuration file is %s\n", g_conf_config_file_name);
+          conf_config_file_name = strdup(optarg);
+          printf("eNB configuration file is %s\n", conf_config_file_name);
       }
       break;
 
@@ -436,7 +439,7 @@ void get_simulation_options(int argc, char *argv[]) {
       break;
 
     case 'O':
-      g_conf_config_file_name = optarg;
+      conf_config_file_name = optarg;
       break;
 
     case 'o':
@@ -586,6 +589,21 @@ void get_simulation_options(int argc, char *argv[]) {
       break;
     }
   }
+
+  if ((oai_emulation.info.nb_enb_local > 0) && (conf_config_file_name != NULL))
+  {
+      /* Read eNB configuration file */
+      enb_properties = enb_config_init(conf_config_file_name);
+
+      AssertFatal (oai_emulation.info.nb_enb_local <= enb_properties->number,
+                   "Number of eNB is greater than eNB defined in configuration file %s (%d/%d)!",
+                   conf_config_file_name, oai_emulation.info.nb_enb_local, enb_properties->number);
+
+      /* Update some simulation parameters */
+      oai_emulation.info.frame_type =           enb_properties->properties[0]->frame_type;
+      oai_emulation.info.extended_prefix_flag = enb_properties->properties[0]->prefix_type;
+
+  }
 }
 
 void check_and_adjust_params() {
-- 
GitLab