mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
4.2 KiB
C++
156 lines
4.2 KiB
C++
/**
|
|
*
|
|
* \section COPYRIGHT
|
|
*
|
|
* Copyright 2013-2020 Software Radio Systems Limited
|
|
*
|
|
* By using this file, you agree to the terms and conditions set
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
* the distribution.
|
|
*
|
|
*/
|
|
|
|
#ifndef SRSLTE_TTI_POINT_H
|
|
#define SRSLTE_TTI_POINT_H
|
|
|
|
#include "logmap.h"
|
|
#include "srslte/adt/interval.h"
|
|
#include <cstdint>
|
|
#include <limits>
|
|
|
|
namespace srslte {
|
|
|
|
struct tti_point {
|
|
constexpr tti_point() = default;
|
|
explicit tti_point(uint32_t tti_val_) : tti_val(tti_val_ % 10240u)
|
|
{
|
|
if (tti_val_ > std::numeric_limits<uint32_t>::max() / 2) {
|
|
// there was a overflow at tti initialization
|
|
uint32_t diff = std::numeric_limits<uint32_t>::max() - tti_val_;
|
|
if (diff < 10240) {
|
|
tti_val = 10240 - diff - 1;
|
|
} else {
|
|
srslte::logmap::get("COMMON")->error("Invalid TTI point assigned\n");
|
|
}
|
|
}
|
|
}
|
|
void reset() { tti_val = std::numeric_limits<uint32_t>::max(); }
|
|
uint32_t sf_idx() const { return tti_val % 10; }
|
|
uint32_t sfn() const { return tti_val / 10; }
|
|
|
|
// comparison operators
|
|
bool operator==(const tti_point& other) const { return tti_val == other.tti_val; }
|
|
bool operator!=(const tti_point& other) const { return tti_val != other.tti_val; }
|
|
bool operator<(const tti_point& other) const
|
|
{
|
|
bool lower_val = tti_val < other.tti_val;
|
|
bool wrap_flag = (lower_val ? other.tti_val - tti_val : tti_val - other.tti_val) > 10240 / 2;
|
|
return (lower_val != wrap_flag);
|
|
}
|
|
bool operator<=(const tti_point& other) const { return *this == other or *this < other; }
|
|
bool operator>(const tti_point& other) const { return not(*this <= other); }
|
|
bool operator>=(const tti_point& other) const { return not(*this < other); }
|
|
|
|
// add/subtract
|
|
int operator-(const tti_point& other) const
|
|
{
|
|
int diff = static_cast<int>(tti_val) - static_cast<int>(other.tti_val);
|
|
if (diff > 10240 / 2) {
|
|
return diff - 10240;
|
|
}
|
|
if (diff < -10240 / 2) {
|
|
return diff + 10240;
|
|
}
|
|
return diff;
|
|
}
|
|
tti_point& operator+=(uint32_t jump)
|
|
{
|
|
tti_val = (tti_val + jump) % 10240;
|
|
return *this;
|
|
}
|
|
tti_point& operator-=(uint32_t jump)
|
|
{
|
|
tti_val -= jump - ((tti_val < jump) ? 10240 : 0);
|
|
return *this;
|
|
}
|
|
tti_point& operator++() { return this->operator+=(1); }
|
|
tti_point operator++(int)
|
|
{
|
|
tti_point ret{tti_val};
|
|
this-> operator+=(1);
|
|
return ret;
|
|
}
|
|
bool is_valid() const { return tti_val < 10240; }
|
|
explicit operator uint32_t() const { return tti_val; }
|
|
uint32_t to_uint() const { return tti_val; }
|
|
bool is_in_interval(tti_point l, tti_point u) const { return (*this >= l and *this <= u); }
|
|
|
|
private:
|
|
uint32_t tti_val = std::numeric_limits<uint32_t>::max();
|
|
};
|
|
inline tti_point operator+(tti_point tti, uint32_t jump)
|
|
{
|
|
return tti_point{(uint32_t)tti + jump};
|
|
}
|
|
inline tti_point operator+(uint32_t jump, tti_point tti)
|
|
{
|
|
return tti_point{(uint32_t)tti + jump};
|
|
}
|
|
inline tti_point operator-(tti_point tti, uint32_t jump)
|
|
{
|
|
return tti_point{(uint32_t)tti + 10240 - jump};
|
|
}
|
|
inline tti_point max(tti_point tti1, tti_point tti2)
|
|
{
|
|
return tti1 > tti2 ? tti1 : tti2;
|
|
}
|
|
inline tti_point min(tti_point tti1, tti_point tti2)
|
|
{
|
|
return tti1 < tti2 ? tti1 : tti2;
|
|
}
|
|
|
|
using tti_interval = srslte::interval<srslte::tti_point>;
|
|
|
|
} // namespace srslte
|
|
|
|
namespace fmt {
|
|
template <>
|
|
struct formatter<srslte::tti_point> {
|
|
template <typename ParseContext>
|
|
auto parse(ParseContext& ctx) -> decltype(ctx.begin())
|
|
{
|
|
return ctx.begin();
|
|
}
|
|
template <typename FormatContext>
|
|
auto format(srslte::tti_point tti, FormatContext& ctx) -> decltype(std::declval<FormatContext>().out())
|
|
{
|
|
return format_to(ctx.out(), "{}", tti.to_uint());
|
|
}
|
|
};
|
|
} // namespace fmt
|
|
|
|
namespace srsenb {
|
|
|
|
using tti_point = srslte::tti_point;
|
|
|
|
inline srslte::tti_point to_tx_dl(srslte::tti_point t)
|
|
{
|
|
return t + TX_ENB_DELAY;
|
|
}
|
|
inline srslte::tti_point to_tx_ul(srslte::tti_point t)
|
|
{
|
|
return t + (TX_ENB_DELAY + FDD_HARQ_DELAY_DL_MS);
|
|
}
|
|
inline srslte::tti_point to_tx_dl_ack(srslte::tti_point t)
|
|
{
|
|
return to_tx_ul(t);
|
|
}
|
|
inline srslte::tti_point to_tx_ul_ack(srslte::tti_point t)
|
|
{
|
|
return to_tx_ul(t) + TX_ENB_DELAY;
|
|
}
|
|
|
|
} // namespace srsenb
|
|
|
|
#endif // SRSLTE_TTI_POINT_H
|