From 565fb8834201748e339a3e290848f216f6b07d64 Mon Sep 17 00:00:00 2001
From: Guido Casati <guido.casati@iis.fraunhofer.de>
Date: Thu, 4 Nov 2021 16:08:41 +0100
Subject: [PATCH] Simplified set_tdd_config_nr_ue function

- reviewed redundant code
- removed unnecessary return
---
 openair2/LAYER2/NR_MAC_UE/config_ue.c | 76 ++++++++++-----------------
 openair2/LAYER2/NR_MAC_UE/mac_proto.h |  6 +--
 2 files changed, 30 insertions(+), 52 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c
index 3691fcee7f0..d9514691ba7 100755
--- a/openair2/LAYER2/NR_MAC_UE/config_ue.c
+++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c
@@ -38,15 +38,27 @@
 #include "common/utils/nr/nr_common.h"
 #include "executables/softmodem-common.h"
 
-int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg,
-                         int mu,
-                         int nrofDownlinkSlots, int nrofDownlinkSymbols,
-                         int nrofUplinkSlots,   int nrofUplinkSymbols) {
-
+void set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg,
+                          int mu,
+                          NR_TDD_UL_DL_ConfigCommon_t *tdd_config) {
+
+  int nrofDownlinkSlots   = tdd_config->pattern1.nrofDownlinkSlots;
+  int nrofDownlinkSymbols = tdd_config->pattern1.nrofDownlinkSymbols;
+  int nrofUplinkSlots     = tdd_config->pattern1.nrofUplinkSlots;
+  int nrofUplinkSymbols   = tdd_config->pattern1.nrofUplinkSymbols;
   int slot_number = 0;
   int nb_periods_per_frame;
   int nb_slots_to_set = TDD_CONFIG_NB_FRAMES*(1<<mu)*NR_NUMBER_OF_SUBFRAMES_PER_FRAME;
 
+  if (tdd_config->pattern1.ext1 == NULL) {
+    cfg->tdd_table.tdd_period = tdd_config->pattern1.dl_UL_TransmissionPeriodicity;
+  } else {
+    AssertFatal(tdd_config->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 != NULL, "tdd_config->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 is null\n");
+    cfg->tdd_table.tdd_period = *tdd_config->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530;
+  }
+
+  LOG_I(NR_MAC, "Setting TDD configuration period to %d\n", cfg->tdd_table.tdd_period);
+
   switch(cfg->tdd_table.tdd_period) {
     case 0:
       nb_periods_per_frame = 20; // 10ms/0p5ms
@@ -140,7 +152,8 @@ int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg,
     }
   }
 
-  return (0);
+  LOG_I(NR_MAC, "TDD has been properly configurated\n");
+
 }
 
 
@@ -228,28 +241,10 @@ void config_common_ue_sa(NR_UE_MAC_INST_t *mac,
   }
 
   // TDD Table Configuration
-  if(cfg->cell_config.frame_duplex_type == TDD){
-    if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1 == NULL) {
-      cfg->tdd_table.tdd_period = scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity;
-    } else {
-      AssertFatal(scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 != NULL,
-                  "scc_SIB->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 is null\n");
-      cfg->tdd_table.tdd_period = *scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530;
-    }
-    LOG_I(MAC,"Setting TDD configuration period to %d\n", cfg->tdd_table.tdd_period);
-    int return_tdd = set_tdd_config_nr_ue(cfg,
-         scc->uplinkConfigCommon->frequencyInfoUL.scs_SpecificCarrierList.list.array[0]->subcarrierSpacing,
-                     scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSlots,
-                     scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSymbols,
-                     scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots,
-                     scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols
-                     );
-
-    if (return_tdd !=0) {
-      LOG_E(NR_PHY, "TDD configuration cannot be done\n");
-    } else {
-      LOG_I(NR_PHY, "TDD has been properly configurated\n");
-    }
+  if (cfg->cell_config.frame_duplex_type == TDD){
+    set_tdd_config_nr_ue(cfg,
+                         scc->uplinkConfigCommon->frequencyInfoUL.scs_SpecificCarrierList.list.array[0]->subcarrierSpacing,
+                         scc->tdd_UL_DL_ConfigurationCommon);
   }
 
   // PRACH configuration
@@ -412,27 +407,10 @@ void config_common_ue(NR_UE_MAC_INST_t *mac,
     }
     
     // TDD Table Configuration
-    if(cfg->cell_config.frame_duplex_type == TDD){
-      if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1 == NULL) {
-        cfg->tdd_table.tdd_period = scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity;
-      } else {
-        AssertFatal(scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 != NULL,
-        "scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530 is null\n");
-        cfg->tdd_table.tdd_period = *scc->tdd_UL_DL_ConfigurationCommon->pattern1.ext1->dl_UL_TransmissionPeriodicity_v1530;
-      }
-      LOG_I(MAC,"Setting TDD configuration period to %d\n", cfg->tdd_table.tdd_period);
-      int return_tdd = set_tdd_config_nr_ue(cfg,
-					    scc->uplinkConfigCommon->frequencyInfoUL->scs_SpecificCarrierList.list.array[0]->subcarrierSpacing,
-					    scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSlots,
-					    scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofDownlinkSymbols,
-					    scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots,
-					    scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols
-					    );
-      if (return_tdd !=0) {
-        LOG_E(NR_PHY, "TDD configuration can not be done\n");
-      } else {
-        LOG_I(NR_PHY, "TDD has been properly configurated\n");
-      }
+    if (cfg->cell_config.frame_duplex_type == TDD){
+      set_tdd_config_nr_ue(cfg,
+                           scc->uplinkConfigCommon->frequencyInfoUL->scs_SpecificCarrierList.list.array[0]->subcarrierSpacing,
+                           scc->tdd_UL_DL_ConfigurationCommon);
     }
 
     // PRACH configuration
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
index 92710b3c0d6..3531fa564e3 100755
--- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
@@ -213,9 +213,9 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
                       uint8_t *ulsch_buffer,
                       uint16_t buflen);
 
-int set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg, int mu,
-                         int nrofDownlinkSlots, int nrofDownlinkSymbols,
-                         int nrofUplinkSlots,   int nrofUplinkSymbols);
+void set_tdd_config_nr_ue(fapi_nr_config_request_t *cfg,
+                          int mu,
+                          NR_TDD_UL_DL_ConfigCommon_t *tdd_config);
 
 void set_harq_status(NR_UE_MAC_INST_t *mac,
                      uint8_t pucch_id,
-- 
GitLab