diff --git a/lib/include/srsran/common/band_helper.h b/lib/include/srsran/common/band_helper.h index 22a255773..0b1d509f6 100644 --- a/lib/include/srsran/common/band_helper.h +++ b/lib/include/srsran/common/band_helper.h @@ -68,6 +68,35 @@ public: */ srsran_duplex_mode_t get_duplex_mode(uint16_t band) const; + struct sync_raster_t { + protected: + sync_raster_t(uint32_t f, uint32_t s, uint32_t l) : first(f), step(s), last(l), gscn(f) {} + uint32_t gscn; + + private: + uint32_t first; + uint32_t step; + uint32_t last; + + public: + bool valid() const { return step != 0; } + + void next() + { + if (gscn <= last) { + gscn += step; + } + } + + bool end() const { return (gscn > last or step == 0); } + + void reset() { gscn = first; } + + double get_frequency() const; + }; + + sync_raster_t get_sync_raster(uint16_t band, srsran_subcarrier_spacing_t scs) const; + private: // Elements of TS 38.101-1 Table 5.2-1: NR operating bands in FR1 struct nr_operating_band { @@ -225,7 +254,7 @@ private: {261, KHZ_120, 2070833, 2, 2084999, 2070833, 2, 2084999} }}; -// Elements of TS 38.101-1 Table 5.4.3.3-1 : Applicable SS raster entries per operating band + // Elements of TS 38.101-1 Table 5.4.3.3-1 : Applicable SS raster entries per operating band struct nr_band_ss_raster { uint16_t band; srsran_subcarrier_spacing_t scs; @@ -270,4 +299,4 @@ private: } // namespace srsran -#endif // SRSRAN_BAND_HELPER_H \ No newline at end of file +#endif // SRSRAN_BAND_HELPER_H diff --git a/lib/src/common/band_helper.cc b/lib/src/common/band_helper.cc index 4b91890b5..76e2821e1 100644 --- a/lib/src/common/band_helper.cc +++ b/lib/src/common/band_helper.cc @@ -12,6 +12,7 @@ #include "srsran/common/band_helper.h" #include +#include namespace srsran { @@ -104,6 +105,59 @@ srsran_duplex_mode_t srsran_band_helper::get_duplex_mode(uint16_t band) const return SRSRAN_DUPLEX_MODE_INVALID; } +struct sync_raster_impl : public srsran_band_helper::sync_raster_t { +public: + sync_raster_impl(uint32_t f, uint32_t s, uint32_t l) : sync_raster_t(f, s, l) + { + // Do nothing + } +}; + +double srsran_band_helper::sync_raster_t::get_frequency() const +{ + // Row 1 + if (gscn >= 2 and gscn <= 7498) { + double N = std::ceil((gscn - 1) / 3.0); + double M = (gscn - 3 * N) / 2.0 + 3.0; + return N * 1200e3 + M * 50e3; + } + + // Row 2 + if (gscn >= 7499 and gscn <= 22255) { + double N = gscn - 7499; + return 3000e6 + N * 1.44e6; + } + + // Row 3 + if (gscn >= 22256 and gscn <= 26639) { + double N = gscn - 22256; + return 2425.08e6 + N * 17.28e6; + } + + // Unhandled case + return NAN; +} + +srsran_band_helper::sync_raster_t srsran_band_helper::get_sync_raster(uint16_t band, + srsran_subcarrier_spacing_t scs) const +{ + // Look for the given band and SCS + for (const nr_band_ss_raster& ss_raster : nr_band_ss_raster_table) { + // Check if band and SCS match! + if (ss_raster.band == band && ss_raster.scs == scs) { + return sync_raster_impl(ss_raster.gscn_first, ss_raster.gscn_step, ss_raster.gscn_last); + } + + // As bands are in ascending order, do not waste more time if the current band is bigger + if (ss_raster.band > band) { + return sync_raster_impl(0, 0, 0); + } + } + + // Band is out of range, so consider invalid + return sync_raster_impl(0, 0, 0); +} + srsran_band_helper::nr_raster_params srsran_band_helper::get_raster_params(uint32_t nr_arfcn) { for (auto& fr : nr_fr_params) { @@ -114,4 +168,4 @@ srsran_band_helper::nr_raster_params srsran_band_helper::get_raster_params(uint3 return {}; // return empty params } -} // namespace srsran \ No newline at end of file +} // namespace srsran