diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-07-31 14:34:36 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:34 -0800 |
commit | d717feaf3d6ce6f8823a6437000e0394b5b68134 (patch) | |
tree | 210870b5f95c8c7994b78357f11e70302b1839ef /host/lib | |
parent | bf986d32632199917dc811f00465ecf409c64a76 (diff) | |
download | uhd-d717feaf3d6ce6f8823a6437000e0394b5b68134.tar.gz uhd-d717feaf3d6ce6f8823a6437000e0394b5b68134.tar.bz2 uhd-d717feaf3d6ce6f8823a6437000e0394b5b68134.zip |
rfnoc: radio: Introduce coerce_rate() method
This is a helper method for property resolution, where set_rate() is not
appropriate.
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp | 16 | ||||
-rw-r--r-- | host/lib/rfnoc/radio_control_impl.cpp | 11 |
2 files changed, 24 insertions, 3 deletions
diff --git a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp index 6b50cc31c..fc90035f7 100644 --- a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp +++ b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp @@ -256,6 +256,22 @@ public: static const uhd::fs_path FE_PATH; protected: + /*! Helper function for property propagation: Like set_rate(), but called + * during a different context. + * + * This function is called from the samp_rate property resolver. The + * difference to set_rate() is that the latter is a user API, and may + * trigger different kinds of warnings or errors. + * If the radio supports changing its sampling rate at runtime, it is OK to + * call set_rate() within this function. + * + * Default implementation is to simply return the current rate. + */ + virtual double coerce_rate(const double /* rate */) + { + return _rate; + } + //! Properties for samp_rate (one per port) std::vector<property_t<double>> _samp_rate_in; //! Properties for samp_rate (one per port) diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp index f71c73289..9648b5dbf 100644 --- a/host/lib/rfnoc/radio_control_impl.cpp +++ b/host/lib/rfnoc/radio_control_impl.cpp @@ -175,9 +175,12 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) {&_spp_prop.back()}, [this, chan, &spp = _spp_prop.back()]() { RFNOC_LOG_TRACE("Calling resolver for spp@" << chan); + // TODO: Replace the magic number 16 (the protocol overhead) + // with something else that is calculated based on the CHDR width const int mtu = - static_cast<int>(get_mtu({res_source_info::OUTPUT_EDGE, chan})); - const int max_spp_per_mtu = mtu / (_samp_width / 8) - (mtu % _spc); + static_cast<int>(get_mtu({res_source_info::OUTPUT_EDGE, chan})) - 16; + const int mtu_samps = mtu / (_samp_width / 8); + const int max_spp_per_mtu = mtu_samps - (mtu_samps % _spc); if (spp.get() > max_spp_per_mtu) { RFNOC_LOG_WARNING("spp value " << spp.get() << " exceeds MTU of " << mtu << "! Coercing to " @@ -196,13 +199,15 @@ radio_control_impl::radio_control_impl(make_args_ptr make_args) "spp must be greater than zero! Coercing to " << spp.get()); } }); + // Note: The following resolver calls coerce_rate(), which is virtual. + // At run time, it will use the implementation by the child class. add_property_resolver({&_samp_rate_in.back(), &_samp_rate_out.back()}, {&_samp_rate_in.back(), &_samp_rate_out.back()}, [this, chan, &samp_rate_in = _samp_rate_in.at(chan), &samp_rate_out = _samp_rate_out.at(chan)]() { RFNOC_LOG_TRACE("Calling resolver for samp_rate@" << chan); - samp_rate_in = set_rate(samp_rate_in.get()); + samp_rate_in = coerce_rate(samp_rate_in.get()); samp_rate_out = samp_rate_in.get(); }); // Resolvers for type: These are constants |