diff options
Diffstat (limited to 'include/osmosdr')
-rw-r--r-- | include/osmosdr/CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/osmosdr/ranges.h | 6 | ||||
-rw-r--r-- | include/osmosdr/sink.h | 98 | ||||
-rw-r--r-- | include/osmosdr/source.h | 98 | ||||
-rw-r--r-- | include/osmosdr/time_spec.h | 141 |
5 files changed, 344 insertions, 0 deletions
diff --git a/include/osmosdr/CMakeLists.txt b/include/osmosdr/CMakeLists.txt index ecdf792..d185ee6 100644 --- a/include/osmosdr/CMakeLists.txt +++ b/include/osmosdr/CMakeLists.txt @@ -24,6 +24,7 @@ install(FILES api.h pimpl.h ranges.h + time_spec.h device.h source.h sink.h diff --git a/include/osmosdr/ranges.h b/include/osmosdr/ranges.h index ccb2dbc..77d5026 100644 --- a/include/osmosdr/ranges.h +++ b/include/osmosdr/ranges.h @@ -25,6 +25,12 @@ namespace osmosdr{ + //! A wildcard motherboard index + static const size_t ALL_MBOARDS = size_t(~0); + + //! A wildcard channel index + static const size_t ALL_CHANS = size_t(~0); + /*! * A range object describes a set of discrete values of the form: * y = start + step*n, where n is an integer between 0 and (stop - start)/step diff --git a/include/osmosdr/sink.h b/include/osmosdr/sink.h index 10c9038..906976e 100644 --- a/include/osmosdr/sink.h +++ b/include/osmosdr/sink.h @@ -22,6 +22,7 @@ #include <osmosdr/api.h> #include <osmosdr/ranges.h> +#include <osmosdr/time_spec.h> #include <gnuradio/hier_block2.h> namespace osmosdr { @@ -273,6 +274,103 @@ public: * \return a range of bandwidths in Hz */ virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ) = 0; + + /*! + * Set the time source for the device. + * This sets the method of time synchronization, + * typically a pulse per second or an encoded time. + * Typical options for source: external, MIMO. + * \param source a string representing the time source + * \param mboard which motherboard to set the config + */ + virtual void set_time_source(const std::string &source, + const size_t mboard = 0) = 0; + + /*! + * Get the currently set time source. + * \param mboard which motherboard to get the config + * \return the string representing the time source + */ + virtual std::string get_time_source(const size_t mboard) = 0; + + /*! + * Get a list of possible time sources. + * \param mboard which motherboard to get the list + * \return a vector of strings for possible settings + */ + virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0; + + /*! + * Set the clock source for the device. + * This sets the source for a 10 Mhz reference clock. + * Typical options for source: internal, external, MIMO. + * \param source a string representing the clock source + * \param mboard which motherboard to set the config + */ + virtual void set_clock_source(const std::string &source, + const size_t mboard = 0) = 0; + + /*! + * Get the currently set clock source. + * \param mboard which motherboard to get the config + * \return the string representing the clock source + */ + virtual std::string get_clock_source(const size_t mboard) = 0; + + /*! + * Get a list of possible clock sources. + * \param mboard which motherboard to get the list + * \return a vector of strings for possible settings + */ + virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0; + + /*! + * Get the master clock rate. + * \param mboard the motherboard index 0 to M-1 + * \return the clock rate in Hz + */ + virtual double get_clock_rate(size_t mboard = 0) = 0; + + /*! + * Set the master clock rate. + * \param rate the new rate in Hz + * \param mboard the motherboard index 0 to M-1 + */ + virtual void set_clock_rate(double rate, size_t mboard = 0) = 0; + + /*! + * Get the current time registers. + * \param mboard the motherboard index 0 to M-1 + * \return the current device time + */ + virtual ::osmosdr::time_spec_t get_time_now(size_t mboard = 0) = 0; + + /*! + * Get the time when the last pps pulse occured. + * \param mboard the motherboard index 0 to M-1 + * \return the current device time + */ + virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard = 0) = 0; + + /*! + * Sets the time registers immediately. + * \param time_spec the new time + * \param mboard the motherboard index 0 to M-1 + */ + virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec, + size_t mboard = 0) = 0; + + /*! + * Set the time registers at the next pps. + * \param time_spec the new time + */ + virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec) = 0; + + /*! + * Sync the time registers with an unknown pps edge. + * \param time_spec the new time + */ + virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) = 0; }; } /* namespace osmosdr */ diff --git a/include/osmosdr/source.h b/include/osmosdr/source.h index 2bd3213..88f8385 100644 --- a/include/osmosdr/source.h +++ b/include/osmosdr/source.h @@ -22,6 +22,7 @@ #include <osmosdr/api.h> #include <osmosdr/ranges.h> +#include <osmosdr/time_spec.h> #include <gnuradio/hier_block2.h> namespace osmosdr { @@ -317,6 +318,103 @@ public: * \return a range of bandwidths in Hz */ virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ) = 0; + + /*! + * Set the time source for the device. + * This sets the method of time synchronization, + * typically a pulse per second or an encoded time. + * Typical options for source: external, MIMO. + * \param source a string representing the time source + * \param mboard which motherboard to set the config + */ + virtual void set_time_source(const std::string &source, + const size_t mboard = 0) = 0; + + /*! + * Get the currently set time source. + * \param mboard which motherboard to get the config + * \return the string representing the time source + */ + virtual std::string get_time_source(const size_t mboard) = 0; + + /*! + * Get a list of possible time sources. + * \param mboard which motherboard to get the list + * \return a vector of strings for possible settings + */ + virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0; + + /*! + * Set the clock source for the device. + * This sets the source for a 10 Mhz reference clock. + * Typical options for source: internal, external, MIMO. + * \param source a string representing the clock source + * \param mboard which motherboard to set the config + */ + virtual void set_clock_source(const std::string &source, + const size_t mboard = 0) = 0; + + /*! + * Get the currently set clock source. + * \param mboard which motherboard to get the config + * \return the string representing the clock source + */ + virtual std::string get_clock_source(const size_t mboard) = 0; + + /*! + * Get a list of possible clock sources. + * \param mboard which motherboard to get the list + * \return a vector of strings for possible settings + */ + virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0; + + /*! + * Get the master clock rate. + * \param mboard the motherboard index 0 to M-1 + * \return the clock rate in Hz + */ + virtual double get_clock_rate(size_t mboard = 0) = 0; + + /*! + * Set the master clock rate. + * \param rate the new rate in Hz + * \param mboard the motherboard index 0 to M-1 + */ + virtual void set_clock_rate(double rate, size_t mboard = 0) = 0; + + /*! + * Get the current time registers. + * \param mboard the motherboard index 0 to M-1 + * \return the current device time + */ + virtual ::osmosdr::time_spec_t get_time_now(size_t mboard = 0) = 0; + + /*! + * Get the time when the last pps pulse occured. + * \param mboard the motherboard index 0 to M-1 + * \return the current device time + */ + virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard = 0) = 0; + + /*! + * Sets the time registers immediately. + * \param time_spec the new time + * \param mboard the motherboard index 0 to M-1 + */ + virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec, + size_t mboard = 0) = 0; + + /*! + * Set the time registers at the next pps. + * \param time_spec the new time + */ + virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec) = 0; + + /*! + * Sync the time registers with an unknown pps edge. + * \param time_spec the new time + */ + virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) = 0; }; } /* namespace osmosdr */ diff --git a/include/osmosdr/time_spec.h b/include/osmosdr/time_spec.h new file mode 100644 index 0000000..13fbfd6 --- /dev/null +++ b/include/osmosdr/time_spec.h @@ -0,0 +1,141 @@ +// +// Copyright 2010-2012 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_OSMOSDR_TIME_SPEC_H +#define INCLUDED_OSMOSDR_TIME_SPEC_H + +#include <osmosdr/api.h> +#include <boost/operators.hpp> +#include <ctime> + +namespace osmosdr{ + + /*! + * 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 time_spec_t provides clock-domain independent time storage, + * but can convert fractional seconds to/from clock-domain specific units. + * + * 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. + */ + class OSMOSDR_API time_spec_t : boost::additive<time_spec_t>, boost::totally_ordered<time_spec_t>{ + public: + + /*! + * Get the system time in time_spec_t format. + * Uses the highest precision clock available. + * \return the system time as a time_spec_t + */ + static time_spec_t get_system_time(void); + + /*! + * 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); + + /*! + * Create a time_spec_t from whole seconds and fractional ticks. + * 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, long tick_count, double tick_rate); + + /*! + * Create a time_spec_t from a 64-bit tick count. + * Translation from clock-domain specific units. + * \param ticks an integer count of ticks + * \param tick_rate the number of ticks per second + */ + static time_spec_t from_ticks(long long ticks, double tick_rate); + + /*! + * 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 + */ + long get_tick_count(double tick_rate) const; + + /*! + * Convert the time spec into a 64-bit tick count. + * Translation into clock-domain specific units. + * \param tick_rate the number of ticks per second + * \return an integer number of ticks + */ + long long to_ticks(const double tick_rate) const; + + /*! + * 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 + */ + double get_real_secs(void) const; + + /*! + * 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 + */ + 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 + OSMOSDR_API bool operator==(const time_spec_t &, const time_spec_t &); + + //! Implement less_than_comparable interface + OSMOSDR_API bool operator<(const time_spec_t &, const time_spec_t &); + + inline time_t time_spec_t::get_full_secs(void) const{ + return this->_full_secs; + } + + inline double time_spec_t::get_frac_secs(void) const{ + return this->_frac_secs; + } + +} //namespace osmosdr + +#endif /* INCLUDED_OSMOSDR_TIME_SPEC_H */ |