From 17a3c76540cdc4ace36a816f6b03b8fd32e22d5d Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Fri, 9 Apr 2021 21:31:31 +0200 Subject: [PATCH] Fix NR TDD pattern configuration --- .../interfaces/rrc_nr_interface_types.h | 15 -------- lib/src/asn1/rrc_nr_utils.cc | 36 +++++++++++++++++++ lib/src/phy/common/phy_common_nr.c | 14 ++++++++ 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lib/include/srsran/interfaces/rrc_nr_interface_types.h b/lib/include/srsran/interfaces/rrc_nr_interface_types.h index da270dda5..c96e8c4cb 100644 --- a/lib/include/srsran/interfaces/rrc_nr_interface_types.h +++ b/lib/include/srsran/interfaces/rrc_nr_interface_types.h @@ -35,21 +35,6 @@ struct phy_cfg_nr_t { phy_cfg_nr_t() { - // tdd-UL-DL-ConfigurationCommon - // referenceSubcarrierSpacing: kHz15 (0) - // pattern1 - // dl-UL-TransmissionPeriodicity: ms10 (7) - // nrofDownlinkSlots: 7 - // nrofDownlinkSymbols: 6 - // nrofUplinkSlots: 2 - // nrofUplinkSymbols: 4 - tdd.pattern1.period_ms = 10; - tdd.pattern1.nof_dl_slots = 7; - tdd.pattern1.nof_dl_symbols = 6; - tdd.pattern1.nof_ul_slots = 2; - tdd.pattern1.nof_ul_symbols = 4; - tdd.pattern2.period_ms = 0; - // physicalCellGroupConfig // pdsch-HARQ-ACK-Codebook: dynamic (1) harq_ack.harq_ack_codebook = srsran_pdsch_harq_ack_codebook_dynamic; diff --git a/lib/src/asn1/rrc_nr_utils.cc b/lib/src/asn1/rrc_nr_utils.cc index 72e644154..76e474114 100644 --- a/lib/src/asn1/rrc_nr_utils.cc +++ b/lib/src/asn1/rrc_nr_utils.cc @@ -259,6 +259,42 @@ bool make_phy_tdd_cfg(const tdd_ul_dl_cfg_common_s& tdd_ul_dl_cfg_common, srsran_tdd_config_nr.pattern1.nof_ul_symbols = tdd_ul_dl_cfg_common.pattern1.nrof_ul_symbols; // Copy and return struct *in_srsran_tdd_config_nr = srsran_tdd_config_nr; + + if (not tdd_ul_dl_cfg_common.pattern2_present) { + return true; + } + + switch (tdd_ul_dl_cfg_common.pattern2.dl_ul_tx_periodicity) { + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms1: + srsran_tdd_config_nr.pattern2.period_ms = 1; + break; + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms2: + srsran_tdd_config_nr.pattern2.period_ms = 2; + break; + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms5: + srsran_tdd_config_nr.pattern2.period_ms = 5; + break; + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms10: + srsran_tdd_config_nr.pattern2.period_ms = 10; + break; + + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms1p25: + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms0p5: + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms0p625: + case tdd_ul_dl_pattern_s::dl_ul_tx_periodicity_opts::ms2p5: + default: + asn1::log_warning("Invalid option for pattern2 dl_ul_tx_periodicity_opts %s", + tdd_ul_dl_cfg_common.pattern2.dl_ul_tx_periodicity.to_string()); + return false; + } + + srsran_tdd_config_nr.pattern2.nof_dl_slots = tdd_ul_dl_cfg_common.pattern2.nrof_dl_slots; + srsran_tdd_config_nr.pattern2.nof_dl_symbols = tdd_ul_dl_cfg_common.pattern2.nrof_dl_symbols; + srsran_tdd_config_nr.pattern2.nof_ul_slots = tdd_ul_dl_cfg_common.pattern2.nrof_ul_slots; + srsran_tdd_config_nr.pattern2.nof_ul_symbols = tdd_ul_dl_cfg_common.pattern2.nrof_ul_symbols; + // Copy and return struct + *in_srsran_tdd_config_nr = srsran_tdd_config_nr; + return true; } diff --git a/lib/src/phy/common/phy_common_nr.c b/lib/src/phy/common/phy_common_nr.c index ad4635d2d..360f4ca7b 100644 --- a/lib/src/phy/common/phy_common_nr.c +++ b/lib/src/phy/common/phy_common_nr.c @@ -179,10 +179,16 @@ float srsran_symbol_distance_s(uint32_t l0, uint32_t l1, uint32_t numerology) bool srsran_tdd_nr_is_dl(const srsran_tdd_config_nr_t* cfg, uint32_t numerology, uint32_t slot_idx) { + // Protect NULL pointer access if (cfg == NULL) { return false; } + // Prevent zero division + if (cfg->pattern1.period_ms == 0 && cfg->pattern2.period_ms == 0) { + return false; + } + // Calculate slot index within the TDD overall period uint32_t slot_x_ms = 1U << numerology; // Number of slots per millisecond uint32_t period_sum = (cfg->pattern1.period_ms + cfg->pattern2.period_ms) * slot_x_ms; // Total perdiod sum @@ -195,16 +201,23 @@ bool srsran_tdd_nr_is_dl(const srsran_tdd_config_nr_t* cfg, uint32_t numerology, slot_idx_period -= cfg->pattern1.period_ms * slot_x_ms; // Remove pattern 1 offset } + // Check DL boundaries return (slot_idx_period < pattern->nof_dl_slots || (slot_idx_period == pattern->nof_dl_slots && pattern->nof_dl_symbols != 0)); } bool srsran_tdd_nr_is_ul(const srsran_tdd_config_nr_t* cfg, uint32_t numerology, uint32_t slot_idx) { + // Protect NULL pointer access if (cfg == NULL) { return false; } + // Prevent zero division + if (cfg->pattern1.period_ms == 0 && cfg->pattern2.period_ms == 0) { + return false; + } + // Calculate slot index within the TDD overall period uint32_t slot_x_ms = 1U << numerology; // Number of slots per millisecond uint32_t period_sum = (cfg->pattern1.period_ms + cfg->pattern2.period_ms) * slot_x_ms; // Total perdiod sum @@ -220,5 +233,6 @@ bool srsran_tdd_nr_is_ul(const srsran_tdd_config_nr_t* cfg, uint32_t numerology, // Calculate slot in which UL starts uint32_t start_ul = (pattern->period_ms * slot_x_ms - pattern->nof_ul_slots) - 1; + // Check UL boundaries return (slot_idx_period > start_ul || (slot_idx_period == start_ul && pattern->nof_ul_symbols != 0)); }