diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/types/time_spec.hpp | 86 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_id.hpp | 2 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_iface.hpp | 39 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_manager.hpp | 21 | ||||
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/thread_priority.hpp | 58 |
6 files changed, 174 insertions, 33 deletions
diff --git a/host/include/uhd/types/time_spec.hpp b/host/include/uhd/types/time_spec.hpp index 25d9e41d0..59b85f4b7 100644 --- a/host/include/uhd/types/time_spec.hpp +++ b/host/include/uhd/types/time_spec.hpp @@ -19,58 +19,92 @@ #define INCLUDED_UHD_TYPES_TIME_SPEC_HPP #include <uhd/config.hpp> -#include <boost/cstdint.hpp> +#include <boost/operators.hpp> +#include <ctime> namespace uhd{ /*! - * A time_spec_t holds a seconds and fractional seconds time value. - * The time_spec_t can be used when setting the time on devices, - * and for dealing with time stamped samples though the metadata. - * and for controlling the start of streaming for applicable dsps. + * A time_spec_t holds a seconds and a fractional seconds time value. + * Depending upon usage, the time_spec_t can represent absolute times, + * relative times, or time differences (between absolute times). * - * The fractional seconds are represented in units of nanoseconds, - * which provide a clock-domain independent unit of time storage. - * The methods "get_ticks" and "set_ticks" can be used to convert - * the fractional seconds to and from clock-domain specific units. + * The time_spec_t provides clock-domain independent time storage, + * but can convert fractional seconds to/from clock-domain specific units. * - * The nanoseconds count is stored as double precision floating point. + * The fractional seconds are stored as double precision floating point. * This gives the fractional seconds enough precision to unambiguously * specify a clock-tick/sample-count up to rates of several petahertz. */ - struct UHD_API time_spec_t{ + class UHD_API time_spec_t : boost::additive<time_spec_t>, boost::totally_ordered<time_spec_t>{ + public: - //! whole/integer seconds count in seconds - boost::uint32_t secs; + /*! + * Create a time_spec_t from a real-valued seconds count. + * \param secs the real-valued seconds count (default = 0) + */ + time_spec_t(double secs = 0); + + /*! + * Create a time_spec_t from whole and fractional seconds. + * \param full_secs the whole/integer seconds count + * \param frac_secs the fractional seconds count (default = 0) + */ + time_spec_t(time_t full_secs, double frac_secs = 0); - //! fractional seconds count in nano-seconds - double nsecs; + /*! + * Create a time_spec_t from whole and fractional seconds. + * Translation from clock-domain specific units. + * \param full_secs the whole/integer seconds count + * \param tick_count the fractional seconds tick count + * \param tick_rate the number of ticks per second + */ + time_spec_t(time_t full_secs, size_t tick_count, double tick_rate); /*! - * Convert the fractional nsecs to clock ticks. + * Convert the fractional seconds to clock ticks. * Translation into clock-domain specific units. * \param tick_rate the number of ticks per second * \return the fractional seconds tick count */ - boost::uint32_t get_ticks(double tick_rate) const; + size_t get_tick_count(double tick_rate) const; /*! - * Set the fractional nsecs from clock ticks. - * Translation from clock-domain specific units. - * \param ticks the fractional seconds tick count - * \param tick_rate the number of ticks per second + * Get the time as a real-valued seconds count. + * Note: If this time_spec_t represents an absolute time, + * the precision of the fractional seconds may be lost. + * \return the real-valued seconds */ - void set_ticks(boost::uint32_t ticks, double tick_rate); + double get_real_secs(void) const; /*! - * Create a time_spec_t from whole and fractional seconds. - * \param secs the whole/integer seconds count in seconds (default = 0) - * \param nsecs the fractional seconds count in nanoseconds (default = 0) + * Get the whole/integer part of the time in seconds. + * \return the whole/integer seconds + */ + time_t get_full_secs(void) const; + + /*! + * Get the fractional part of the time in seconds. + * \return the fractional seconds */ - time_spec_t(boost::uint32_t secs = 0, double nsecs = 0); + double get_frac_secs(void) const; + + //! Implement addable interface + time_spec_t &operator+=(const time_spec_t &); + + //! Implement subtractable interface + time_spec_t &operator-=(const time_spec_t &); + //private time storage details + private: time_t _full_secs; double _frac_secs; }; + //! Implement equality_comparable interface + UHD_API bool operator==(const time_spec_t &, const time_spec_t &); + + //! Implement less_than_comparable interface + UHD_API bool operator<(const time_spec_t &, const time_spec_t &); + } //namespace uhd #endif /* INCLUDED_UHD_TYPES_TIME_SPEC_HPP */ diff --git a/host/include/uhd/usrp/dboard_id.hpp b/host/include/uhd/usrp/dboard_id.hpp index 8b6eaf6bd..4c45e4334 100644 --- a/host/include/uhd/usrp/dboard_id.hpp +++ b/host/include/uhd/usrp/dboard_id.hpp @@ -25,7 +25,7 @@ namespace uhd{ namespace usrp{ - class UHD_API dboard_id_t : boost::equality_comparable1<dboard_id_t>{ + class UHD_API dboard_id_t : boost::equality_comparable<dboard_id_t>{ public: /*! * Create a dboard id from an integer. diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index 7ecfcd3c0..caf1e6ee6 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -22,6 +22,7 @@ #include <uhd/types/serial.hpp> #include <boost/shared_ptr.hpp> #include <boost/cstdint.hpp> +#include <vector> namespace uhd{ namespace usrp{ @@ -35,13 +36,13 @@ class UHD_API dboard_iface{ public: typedef boost::shared_ptr<dboard_iface> sptr; - //tells the host which unit to use + //! tells the host which unit to use enum unit_t{ UNIT_RX = 'r', UNIT_TX = 't' }; - //possible atr registers + //! possible atr registers enum atr_reg_t{ ATR_REG_IDLE = 'i', ATR_REG_TX_ONLY = 't', @@ -49,6 +50,20 @@ public: ATR_REG_FULL_DUPLEX = 'f' }; + //! aux dac selection enums (per unit) + enum aux_dac_t{ + AUX_DAC_A = 'a', + AUX_DAC_B = 'b', + AUX_DAC_C = 'c', + AUX_DAC_D = 'd' + }; + + //! aux adc selection enums (per unit) + enum aux_adc_t{ + AUX_ADC_A = 'a', + AUX_ADC_B = 'b' + }; + /*! * Write to an aux dac. * @@ -56,7 +71,7 @@ public: * \param which_dac the dac index 0, 1, 2, 3... * \param value the value in volts */ - virtual void write_aux_dac(unit_t unit, int which_dac, float value) = 0; + virtual void write_aux_dac(unit_t unit, aux_dac_t which_dac, float value) = 0; /*! * Read from an aux adc. @@ -65,7 +80,7 @@ public: * \param which_adc the adc index 0, 1, 2, 3... * \return the value in volts */ - virtual float read_aux_adc(unit_t unit, int which_adc) = 0; + virtual float read_aux_adc(unit_t unit, aux_adc_t which_adc) = 0; /*! * Set a daughterboard output pin control source. @@ -159,6 +174,14 @@ public: ) = 0; /*! + * Set the rate of a dboard clock. + * + * \param unit which unit rx or tx + * \param rate the clock rate in Hz + */ + virtual void set_clock_rate(unit_t unit, double rate) = 0; + + /*! * Get the rate of a dboard clock. * * \param unit which unit rx or tx @@ -167,6 +190,14 @@ public: virtual double get_clock_rate(unit_t unit) = 0; /*! + * Get a list of possible rates for the dboard clock. + * + * \param unit which unit rx or tx + * \return a list of clock rates in Hz + */ + virtual std::vector<double> get_clock_rates(unit_t unit) = 0; + + /*! * Enable or disable a dboard clock. * * \param unit which unit rx or tx diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index b84fee4e7..e5831d4cf 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -40,7 +40,7 @@ public: typedef dboard_base::sptr(*dboard_ctor_t)(dboard_base::ctor_args_t); /*! - * Register a dboard into the system. + * Register a rx or tx dboard into the system. * For single subdevice boards, omit subdev_names. * \param dboard_id the dboard id (rx or tx) * \param dboard_ctor the dboard constructor function pointer @@ -48,7 +48,24 @@ public: * \param subdev_names the names of the subdevs on this dboard */ static void register_dboard( - dboard_id_t dboard_id, + const dboard_id_t &dboard_id, + dboard_ctor_t dboard_ctor, + const std::string &name, + const prop_names_t &subdev_names = prop_names_t(1, "") + ); + + /*! + * Register an xcvr dboard into the system. + * For single subdevice boards, omit subdev_names. + * \param rx_dboard_id the rx unit dboard id + * \param tx_dboard_id the tx unit dboard id + * \param dboard_ctor the dboard constructor function pointer + * \param name the canonical name for the dboard represented + * \param subdev_names the names of the subdevs on this dboard + */ + static void register_dboard( + const dboard_id_t &rx_dboard_id, + const dboard_id_t &tx_dboard_id, dboard_ctor_t dboard_ctor, const std::string &name, const prop_names_t &subdev_names = prop_names_t(1, "") diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index 3684fd6e7..c98eec639 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -25,5 +25,6 @@ INSTALL(FILES props.hpp safe_main.hpp static.hpp + thread_priority.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils ) diff --git a/host/include/uhd/utils/thread_priority.hpp b/host/include/uhd/utils/thread_priority.hpp new file mode 100644 index 000000000..988fc3012 --- /dev/null +++ b/host/include/uhd/utils/thread_priority.hpp @@ -0,0 +1,58 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP +#define INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP + +#include <uhd/config.hpp> + +namespace uhd{ + + static const float default_thread_priority = float(0.5); + + /*! + * Set the scheduling priority on the current thread. + * + * A new thread or calling process should make this call + * with the defailts this to enable realtime scheduling. + * + * A priority of zero corresponds to normal priority. + * Positive priority values are higher than normal. + * Negative priority values are lower than normal. + * + * \param priority a value between -1 and 1 + * \param realtime true to use realtime mode + * \throw exception on set priority failure + */ + UHD_API void set_thread_priority( + float priority = default_thread_priority, + bool realtime = true + ); + + /*! + * Set the scheduling priority on the current thread. + * Same as set_thread_priority but does not throw on failure. + * \return true on success, false on failure + */ + UHD_API bool set_thread_priority_safe( + float priority = default_thread_priority, + bool realtime = true + ); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP */ |