From 20fa442b23254f2082906847263f432f6f22dcf4 Mon Sep 17 00:00:00 2001
From: Guy De Souza <desouza@eurecom.fr>
Date: Mon, 9 Apr 2018 17:29:55 +0200
Subject: [PATCH] gNB Tx procedure

---
 cmake_targets/CMakeLists.txt                 |  1 +
 cmake_targets/build_oai                      |  4 +-
 openair1/PHY/defs.h                          |  3 ++
 openair1/SCHED_NR/phy_procedures_nr_common.c | 42 ++++++++++++++++++++
 openair1/SCHED_NR/phy_procedures_nr_gNB.c    | 41 +++++++++++++++++--
 targets/RT/USER/nr-gnb.c                     |  3 +-
 6 files changed, 87 insertions(+), 7 deletions(-)
 create mode 100644 openair1/SCHED_NR/phy_procedures_nr_common.c

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 0e08e801c1..560d4cb4f0 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -980,6 +980,7 @@ add_library(SCHED_LIB ${SCHED_SRC})
 
 set(SCHED_NR_SRC
   ${OPENAIR1_DIR}/SCHED_NR/phy_procedures_nr_common.c
+  ${OPENAIR1_DIR}/SCHED_NR/phy_procedures_nr_gNB.c
 )
 add_library(SCHED_NR_LIB ${SCHED_NR_SRC})
 
diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index 596b5aff72..d8d405369f 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -507,7 +507,7 @@ function main() {
 
   DIR=$OPENAIR_DIR/cmake_targets
   if [ "$NOS1" = "1" ] ; then
-      build_dir=noS1_build_ran
+      build_dir=noS1_ran_build
       if [ "$gNB" = "1" ] ; then
          exec=nr-softmodem-nos1
        elif [ "$nrUE" = "1" ] ; then
@@ -518,7 +518,7 @@ function main() {
          exec=lte-uesoftmodem-nos1
        fi
   else
-      build_dir=build_ran
+      build_dir=ran_build
       if [ "$gNB" = "1" ] ; then
          exec=nr-softmodem
        elif [ "$nrUE" = "1" ] ; then
diff --git a/openair1/PHY/defs.h b/openair1/PHY/defs.h
index 3a1eec7b2e..d627561065 100644
--- a/openair1/PHY/defs.h
+++ b/openair1/PHY/defs.h
@@ -166,6 +166,9 @@ static inline void* malloc16_clear( size_t size )
 #define MAX_FRAME_NUMBER 0x400
 
 #if 1
+
+#define nr_subframe_t lte_subframe_t
+
 typedef struct {
   /// EUTRA Band
   uint8_t eutra_band;
diff --git a/openair1/SCHED_NR/phy_procedures_nr_common.c b/openair1/SCHED_NR/phy_procedures_nr_common.c
new file mode 100644
index 0000000000..e4cb626237
--- /dev/null
+++ b/openair1/SCHED_NR/phy_procedures_nr_common.c
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file phy_procedures_lte_eNB.c
+* \brief Implementation of common utilities for eNB/UE procedures from 36.213 LTE specifications
+* \author R. Knopp, F. Kaltenberger
+* \date 2011
+* \version 0.1
+* \company Eurecom
+* \email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr
+* \note
+* \warning
+*/
+#include "PHY/defs.h"
+#include "PHY/extern.h"
+#include "SCHED/defs.h"
+#include "SCHED/extern.h"
+
+
+nr_subframe_t nr_subframe_select(nfapi_config_request_t *cfg,unsigned char subframe)
+{
+  if (cfg->subframe_config.duplex_mode.value == FDD)
+    return(SF_DL);
+}
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 5fdc8278c1..baaf375e9c 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -19,12 +19,11 @@
  *      contact@openairinterface.org
  */
 
-#include "PHY/defs_NR.h"
 #include "PHY/extern.h"
 #include "SCHED/defs.h"
 #include "SCHED/extern.h"
 #include "nfapi_interface.h"
-#include "fapi_l1.h"
+#include "SCHED/fapi_l1.h"
 #include "UTIL/LOG/log.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
 
@@ -39,8 +38,44 @@
 #   include "intertask_interface.h"
 #endif
 
+extern uint8_t nfapi_mode;
 
 void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) {
 
-  
+  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
+  nfapi_config_request_t *cfg = gNB->gNB_config;
+  int **txdataF = gNB->common_vars.txdataF;
+  uint8_t *pbch_pdu=&gNB->pbch_pdu[0];
+
+  LOG_D(PHY,"common_signal_procedures: frame %d, subframe %d\n",frame,subframe); 
+
+}
+
+void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB,
+			   gNB_rxtx_proc_t *proc,
+			   int do_meas)
+{
+  int aa;
+  int frame=proc->frame_tx;
+  int subframe=proc->subframe_tx;
+
+  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
+  nfapi_config_request_t *cfg = gNB->gNB_config;
+
+  int offset = gNB->CC_id;
+
+  if ((cfg->subframe_config.duplex_mode.value == TDD) && (nr_subframe_select(cfg,subframe)==SF_UL)) return;
+
+  //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
+  //if (do_meas==1) start_meas(&gNB->phy_proc_tx);
+
+  // clear the transmit data array for the current subframe
+  for (aa=0; aa<cfg->rf_config.tx_antenna_ports.value; aa++) {      
+    memset(&gNB->common_vars.txdataF[aa][subframe*fp->samples_per_subframe_wCP],
+	   0,fp->samples_per_subframe_wCP*sizeof(int32_t));
+  }
+
+  if (nfapi_mode == 0 || nfapi_mode == 1) {
+    common_signal_procedures(gNB,frame, subframe);
+  }
 }
diff --git a/targets/RT/USER/nr-gnb.c b/targets/RT/USER/nr-gnb.c
index 163028a9a8..b40b34e843 100644
--- a/targets/RT/USER/nr-gnb.c
+++ b/targets/RT/USER/nr-gnb.c
@@ -234,8 +234,7 @@ static inline int rxtx(PHY_VARS_gNB *gNB,gNB_rxtx_proc_t *proc, char *thread_nam
   //if (wait_CCs(proc)<0) return(-1);
   
   if (oai_exit) return(-1);
-/// To call after common signals for NR  
-  //phy_procedures_gNB_TX(gNB, proc, no_relay, NULL, 1);
+  phy_procedures_gNB_TX(gNB, proc, 1);
 
   stop_meas( &softmodem_stats_rxtx_sf );
 
-- 
GitLab