diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-10 23:29:22 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-10 23:29:22 -0700 |
commit | 293ccdccd1e111942e9cc48ab87690da5202e406 (patch) | |
tree | 4e861ca41fabc1e2664b7d0807242ab9c61544fd /host/include | |
parent | 1301d665d621358ec6eccb41a020a4689cb0b566 (diff) | |
parent | 9e419c7b7f35062ceb2ed4e508cadb163067593f (diff) | |
download | uhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.gz uhd-293ccdccd1e111942e9cc48ab87690da5202e406.tar.bz2 uhd-293ccdccd1e111942e9cc48ab87690da5202e406.zip |
usrp-e: merged master, does not build
Diffstat (limited to 'host/include')
27 files changed, 519 insertions, 202 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index c0339dbd3..ad528c9fb 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,6 +25,7 @@ INSTALL(FILES config.hpp device.hpp device.ipp + version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd ) diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index a19d22880..c48b3dfff 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -42,6 +42,9 @@ public: typedef boost::function<device_addrs_t(const device_addr_t &)> find_t; typedef boost::function<sptr(const device_addr_t &)> make_t; + //! A reasonable default timeout for receive + static const size_t default_recv_timeout_ms = 100; + /*! * Register a device into the discovery and factory system. * @@ -158,12 +161,7 @@ public: * See the rx metadata fragment flags and offset fields for details. * * This is a blocking call and will not return until the number - * of samples returned have been written into each buffer. - * However, a call to receive may timeout and return zero samples. - * The timeout duration is decided by the underlying transport layer. - * The caller should assume that the call to receive will not return - * immediately when no packets are available to the transport layer, - * and that the timeout duration is reasonably tuned for performance. + * of samples returned have been written into each buffer or timeout. * * When using the full buffer recv mode, the metadata only applies * to the first packet received and written into the recv buffers. @@ -174,6 +172,7 @@ public: * \param metadata data to fill describing the buffer * \param io_type the type of data to fill into the buffer * \param recv_mode tells recv how to load the buffer + * \param timeout_ms the timeout in milliseconds to wait for a packet * \return the number of samples received or 0 on error */ virtual size_t recv( @@ -181,7 +180,8 @@ public: size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, - recv_mode_t recv_mode + recv_mode_t recv_mode, + size_t timeout_ms = default_recv_timeout_ms ) = 0; /*! @@ -192,7 +192,8 @@ public: size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, - recv_mode_t recv_mode + recv_mode_t recv_mode, + size_t timeout_ms = default_recv_timeout_ms ); //! Deprecated @@ -213,6 +214,17 @@ public: */ virtual size_t get_max_recv_samps_per_packet(void) const = 0; + /*! + * Receive and asynchronous message from the device. + * \param async_metadata the metadata to be filled in + * \param timeout_ms the timeout in milliseconds to wait for a message + * \return true when the async_metadata is valid, false for timeout + */ + virtual bool recv_async_msg( + async_metadata_t &async_metadata, + size_t timeout_ms = default_recv_timeout_ms + ) = 0; + }; } //namespace uhd diff --git a/host/include/uhd/device.ipp b/host/include/uhd/device.ipp index c38a2e43e..603c52859 100644 --- a/host/include/uhd/device.ipp +++ b/host/include/uhd/device.ipp @@ -52,12 +52,13 @@ namespace uhd{ size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, - recv_mode_t recv_mode + recv_mode_t recv_mode, + size_t timeout_ms ){ return this->recv( std::vector<void *>(1, buff), nsamps_per_buff, metadata, - io_type, recv_mode + io_type, recv_mode, timeout_ms ); } diff --git a/host/include/uhd/transport/alignment_buffer.ipp b/host/include/uhd/transport/alignment_buffer.ipp index ed7cfd26c..61b3b60f5 100644 --- a/host/include/uhd/transport/alignment_buffer.ipp +++ b/host/include/uhd/transport/alignment_buffer.ipp @@ -57,12 +57,15 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ std::vector<elem_type> &elems, const time_duration_t &time ){ + boost::system_time exit_time = boost::get_system_time() + time; buff_contents_type buff_contents_tmp; std::list<size_t> indexes_to_do(_all_indexes); //do an initial pop to load an initial sequence id size_t index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + if (not _buffs[index]->pop_with_timed_wait( + buff_contents_tmp, exit_time - boost::get_system_time() + )) return false; elems[index] = buff_contents_tmp.first; seq_type expected_seq_id = buff_contents_tmp.second; indexes_to_do.pop_front(); @@ -75,7 +78,9 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ _there_was_a_clear = false; indexes_to_do = _all_indexes; index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + if (not _buffs[index]->pop_with_timed_wait( + buff_contents_tmp, exit_time - boost::get_system_time() + )) return false; elems[index] = buff_contents_tmp.first; expected_seq_id = buff_contents_tmp.second; indexes_to_do.pop_front(); @@ -83,7 +88,9 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ //pop an element off for this index index = indexes_to_do.front(); - if (not _buffs[index]->pop_with_timed_wait(buff_contents_tmp, time)) return false; + if (not _buffs[index]->pop_with_timed_wait( + buff_contents_tmp, exit_time - boost::get_system_time() + )) return false; //if the sequence id matches: // store the popped element into the output, diff --git a/host/include/uhd/transport/udp_simple.hpp b/host/include/uhd/transport/udp_simple.hpp index 98dca02f0..c84393ecf 100644 --- a/host/include/uhd/transport/udp_simple.hpp +++ b/host/include/uhd/transport/udp_simple.hpp @@ -73,9 +73,10 @@ public: * Receive into the provided buffer. * Blocks until data is received or a timeout occurs. * \param buff a mutable buffer to receive into + * \param timeout_ms the timeout in milliseconds * \return the number of bytes received or zero on timeout */ - virtual size_t recv(const boost::asio::mutable_buffer &buff) = 0; + virtual size_t recv(const boost::asio::mutable_buffer &buff, size_t timeout_ms) = 0; }; }} //namespace diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index 50a2b5c3b..de96ea768 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -20,7 +20,10 @@ #include <uhd/config.hpp> #include <boost/foreach.hpp> +#include <boost/format.hpp> +#include <boost/lexical_cast.hpp> #include <stdexcept> +#include <typeinfo> #include <vector> #include <list> @@ -117,7 +120,10 @@ namespace uhd{ BOOST_FOREACH(const pair_t &p, _map){ if (p.first == key) return p.second; } - throw std::invalid_argument("key not found in dict"); + throw std::invalid_argument(str(boost::format( + "key \"%s\" not found in dict(%s, %s)" + ) % boost::lexical_cast<std::string>(key) + % typeid(Key).name() % typeid(Val).name())); } /*! diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp index 039196250..65952941c 100644 --- a/host/include/uhd/types/metadata.hpp +++ b/host/include/uhd/types/metadata.hpp @@ -26,7 +26,7 @@ namespace uhd{ /*! * RX metadata structure for describing sent IF data. - * Includes stream ID, time specification, and fragmentation flags. + * Includes time specification, fragmentation flags, burst flags, and error codes. * The receive routines will convert IF data headers into metadata. */ struct UHD_API rx_metadata_t{ @@ -62,7 +62,7 @@ namespace uhd{ * - timeout: no packet received, underlying code timed-out * - late command: a stream command was issued in the past * - broken chain: expected another stream command - * - overrun: an internal receive buffer has overrun + * - overflow: an internal receive buffer has filled * - bad packet: the buffer was unrecognizable as a vrt packet * * Note: When an overrun occurs in continuous streaming mode, @@ -74,27 +74,21 @@ namespace uhd{ * - none * - late command * - broken chain - * - overrun + * - overflow */ enum error_code_t { ERROR_CODE_NONE = 0x0, ERROR_CODE_TIMEOUT = 0x1, ERROR_CODE_LATE_COMMAND = 0x2, ERROR_CODE_BROKEN_CHAIN = 0x4, - ERROR_CODE_OVERRUN = 0x8, + ERROR_CODE_OVERFLOW = 0x8, ERROR_CODE_BAD_PACKET = 0xf } error_code; - - /*! - * The default constructor: - * Sets the fields to default values (flags set to false). - */ - rx_metadata_t(void); }; /*! * TX metadata structure for describing received IF data. - * Includes stream ID, time specification, and burst flags. + * Includes time specification, and start and stop burst flags. * The send routines will convert the metadata to IF data headers. */ struct UHD_API tx_metadata_t{ @@ -121,6 +115,38 @@ namespace uhd{ tx_metadata_t(void); }; + /*! + * Async metadata structure for describing transmit related events. + */ + struct UHD_API async_metadata_t{ + //! The channel number in a mimo configuration + size_t channel; + + /*! + * Time specification: when the async event occurred. + */ + bool has_time_spec; + time_spec_t time_spec; + + /*! + * Event codes: + * - success: a packet was successfully transmitted + * - underflow: an internal send buffer has emptied + * - sequence error: packet loss between host and device + * - time error: packet had time that was late (or too early) + * - underflow in packet: underflow occurred inside a packet + * - sequence error in burst: packet loss within a burst + */ + enum event_code_t { + EVENT_CODE_SUCCESS = 0x1, + EVENT_CODE_UNDERFLOW = 0x2, + EVENT_CODE_SEQ_ERROR = 0x4, + EVENT_CODE_TIME_ERROR = 0x8, + EVENT_CODE_UNDERFLOW_IN_PACKET = 0x10, + EVENT_CODE_SEQ_ERROR_IN_BURST = 0x20 + } event_code; + }; + } //namespace uhd #endif /* INCLUDED_UHD_TYPES_METADATA_HPP */ diff --git a/host/include/uhd/types/tune_result.hpp b/host/include/uhd/types/tune_result.hpp index c428a7692..9eebc161a 100644 --- a/host/include/uhd/types/tune_result.hpp +++ b/host/include/uhd/types/tune_result.hpp @@ -19,6 +19,7 @@ #define INCLUDED_UHD_TYPES_TUNE_RESULT_HPP #include <uhd/config.hpp> +#include <string> namespace uhd{ @@ -28,15 +29,18 @@ namespace uhd{ * the target and actual intermediate frequency. * The struct hold the result of tuning the DSP as * the target and actual digital converter frequency. - * It also tell us weather or not the spectrum is inverted. */ struct UHD_API tune_result_t{ double target_inter_freq; double actual_inter_freq; double target_dsp_freq; double actual_dsp_freq; - bool spectrum_inverted; - tune_result_t(void); + + /*! + * Create a pretty print string for this tune result struct. + * \return the printable string + */ + std::string to_pp_string(void) const; }; } //namespace uhd diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index 6f8c1a2d8..76ee24e5f 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -18,6 +18,7 @@ INSTALL(FILES #### props headers ### + codec_props.hpp dboard_props.hpp device_props.hpp dsp_props.hpp @@ -32,6 +33,7 @@ INSTALL(FILES dboard_manager.hpp ### utilities ### + subdev_spec.hpp tune_helper.hpp ### interfaces ### diff --git a/host/include/uhd/usrp/codec_props.hpp b/host/include/uhd/usrp/codec_props.hpp new file mode 100644 index 000000000..ab09b1703 --- /dev/null +++ b/host/include/uhd/usrp/codec_props.hpp @@ -0,0 +1,42 @@ +// +// 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_USRP_CODEC_PROPS_HPP +#define INCLUDED_UHD_USRP_CODEC_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device codec properties: + * A codec is expected to have a rate and gain elements. + * Other properties can be discovered through the others prop. + */ + enum codec_prop_t{ + CODEC_PROP_NAME = 'n', //ro, std::string + CODEC_PROP_OTHERS = 'o', //ro, prop_names_t + CODEC_PROP_GAIN_I = 'i', //rw, float + CODEC_PROP_GAIN_Q = 'q', //rw, float + CODEC_PROP_GAIN_RANGE = 'r', //ro, gain_range_t + CODEC_PROP_GAIN_NAMES = 'G' //ro, prop_names_t + }; + + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_CODEC_PROPS_HPP */ diff --git a/host/include/uhd/usrp/dboard_base.hpp b/host/include/uhd/usrp/dboard_base.hpp index e88d39876..9b75d791f 100644 --- a/host/include/uhd/usrp/dboard_base.hpp +++ b/host/include/uhd/usrp/dboard_base.hpp @@ -40,7 +40,7 @@ public: * Derived classes should pass the args into the base class, * but should not deal with the internals of the args. */ - struct ctor_args_impl; typedef ctor_args_impl* ctor_args_t; + typedef void * ctor_args_t; //structors dboard_base(ctor_args_t); diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index caf1e6ee6..fc7ea3052 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 <string> #include <vector> namespace uhd{ namespace usrp{ @@ -65,6 +66,12 @@ public: }; /*! + * Get the motherboard name of the form: usrp1, usrp2... + * \return string representing the motherboard name + */ + virtual std::string get_mboard_name(void) = 0; + + /*! * Write to an aux dac. * * \param unit which unit rx or tx diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp index 4d5c5efbd..aab6c31ce 100644 --- a/host/include/uhd/usrp/dboard_props.hpp +++ b/host/include/uhd/usrp/dboard_props.hpp @@ -23,16 +23,18 @@ namespace uhd{ namespace usrp{ /*! - * Possible device dboard properties + * Possible device dboard properties: + * A dboard has an id, one or more subdevices, and a codec. + * A dboard is considered to be unidirectional (RX or TX). */ enum dboard_prop_t{ DBOARD_PROP_NAME = 'n', //ro, std::string DBOARD_PROP_SUBDEV = 's', //ro, wax::obj DBOARD_PROP_SUBDEV_NAMES = 'S', //ro, prop_names_t - DBOARD_PROP_USED_SUBDEVS = 'u', //ro, prop_names_t DBOARD_PROP_DBOARD_ID = 'i', //rw, dboard_id_t - DBOARD_PROP_DBOARD_IFACE = 'f' //ro, dboard_iface::sptr - //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet + DBOARD_PROP_DBOARD_IFACE = 'f', //ro, dboard_iface::sptr + DBOARD_PROP_CODEC = 'c', //ro, wax::obj + DBOARD_PROP_GAIN_GROUP = 'g' //ro, gain_group }; }} //namespace diff --git a/host/include/uhd/usrp/device_props.hpp b/host/include/uhd/usrp/device_props.hpp index 983bcb672..346eec179 100644 --- a/host/include/uhd/usrp/device_props.hpp +++ b/host/include/uhd/usrp/device_props.hpp @@ -34,22 +34,6 @@ namespace uhd{ namespace usrp{ DEVICE_PROP_MBOARD_NAMES = 'M' //ro, prop_names_t }; - //////////////////////////////////////////////////////////////////////// - /*! ------ not dealing with yet, commented out ------------ - * Possible device codec properties: - * A codec is expected to have a rate and gain elements. - * Other properties can be discovered through the others prop. - */ - /*enum codec_prop_t{ - CODEC_PROP_NAME, //ro, std::string - CODEC_PROP_OTHERS, //ro, prop_names_t - CODEC_PROP_GAIN, //rw, gain_t - CODEC_PROP_GAIN_RANGE, //ro, gain_range_t - CODEC_PROP_GAIN_NAMES, //ro, prop_names_t - //CODEC_PROP_CLOCK_RATE //ro, freq_t //----> not sure we care to know - };*/ - - }} //namespace #endif /* INCLUDED_UHD_USRP_DEVICE_PROPS_HPP */ diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index a432ce50c..0f250f439 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -39,6 +39,8 @@ namespace uhd{ namespace usrp{ MBOARD_PROP_RX_DBOARD_NAMES = 'E', //ro, prop_names_t MBOARD_PROP_TX_DBOARD = 'v', //ro, wax::obj MBOARD_PROP_TX_DBOARD_NAMES = 'V', //ro, prop_names_t + MBOARD_PROP_RX_SUBDEV_SPEC = 'r', //rw, subdev_spec_t + MBOARD_PROP_TX_SUBDEV_SPEC = 'R', //rw, subdev_spec_t MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t MBOARD_PROP_TIME_NOW = 't', //rw, time_spec_t MBOARD_PROP_TIME_NEXT_PPS = 'T', //wo, time_spec_t diff --git a/host/include/uhd/usrp/mimo_usrp.hpp b/host/include/uhd/usrp/mimo_usrp.hpp index 68a42cad8..10a404059 100644 --- a/host/include/uhd/usrp/mimo_usrp.hpp +++ b/host/include/uhd/usrp/mimo_usrp.hpp @@ -24,6 +24,7 @@ #include <uhd/types/stream_cmd.hpp> #include <uhd/types/clock_config.hpp> #include <uhd/types/tune_result.hpp> +#include <uhd/usrp/subdev_spec.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> #include <vector> @@ -119,11 +120,15 @@ public: /******************************************************************* * RX methods ******************************************************************/ + virtual void set_rx_subdev_spec(size_t chan, const uhd::usrp::subdev_spec_t &spec) = 0; + virtual uhd::usrp::subdev_spec_t get_rx_subdev_spec(size_t chan) = 0; + virtual void set_rx_rate_all(double rate) = 0; virtual double get_rx_rate_all(void) = 0; virtual tune_result_t set_rx_freq(size_t chan, double freq) = 0; virtual tune_result_t set_rx_freq(size_t chan, double freq, double lo_off) = 0; + virtual double get_rx_freq(size_t chan) = 0; virtual freq_range_t get_rx_freq_range(size_t chan) = 0; virtual void set_rx_gain(size_t chan, float gain) = 0; @@ -147,11 +152,15 @@ public: /******************************************************************* * TX methods ******************************************************************/ + virtual void set_tx_subdev_spec(size_t chan, const uhd::usrp::subdev_spec_t &spec) = 0; + virtual uhd::usrp::subdev_spec_t get_tx_subdev_spec(size_t chan) = 0; + virtual void set_tx_rate_all(double rate) = 0; virtual double get_tx_rate_all(void) = 0; virtual tune_result_t set_tx_freq(size_t chan, double freq) = 0; virtual tune_result_t set_tx_freq(size_t chan, double freq, double lo_off) = 0; + virtual double get_tx_freq(size_t chan) = 0; virtual freq_range_t get_tx_freq_range(size_t chan) = 0; virtual void set_tx_gain(size_t chan, float gain) = 0; diff --git a/host/include/uhd/usrp/simple_usrp.hpp b/host/include/uhd/usrp/simple_usrp.hpp index 1d9136f08..4da63c929 100644 --- a/host/include/uhd/usrp/simple_usrp.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -24,6 +24,7 @@ #include <uhd/types/stream_cmd.hpp> #include <uhd/types/clock_config.hpp> #include <uhd/types/tune_result.hpp> +#include <uhd/usrp/subdev_spec.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> #include <vector> @@ -107,11 +108,15 @@ public: /******************************************************************* * RX methods ******************************************************************/ + virtual void set_rx_subdev_spec(const uhd::usrp::subdev_spec_t &spec) = 0; + virtual uhd::usrp::subdev_spec_t get_rx_subdev_spec(void) = 0; + virtual void set_rx_rate(double rate) = 0; virtual double get_rx_rate(void) = 0; virtual tune_result_t set_rx_freq(double freq) = 0; virtual tune_result_t set_rx_freq(double freq, double lo_off) = 0; + virtual double get_rx_freq(void) = 0; virtual freq_range_t get_rx_freq_range(void) = 0; virtual void set_rx_gain(float gain) = 0; @@ -134,11 +139,15 @@ public: /******************************************************************* * TX methods ******************************************************************/ + virtual void set_tx_subdev_spec(const uhd::usrp::subdev_spec_t &spec) = 0; + virtual uhd::usrp::subdev_spec_t get_tx_subdev_spec(void) = 0; + virtual void set_tx_rate(double rate) = 0; virtual double get_tx_rate(void) = 0; virtual tune_result_t set_tx_freq(double freq) = 0; virtual tune_result_t set_tx_freq(double freq, double lo_off) = 0; + virtual double get_tx_freq(void) = 0; virtual freq_range_t get_tx_freq_range(void) = 0; virtual void set_tx_gain(float gain) = 0; diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp index 1f8e91d68..cd07cb7a8 100644 --- a/host/include/uhd/usrp/subdev_props.hpp +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -23,6 +23,22 @@ namespace uhd{ namespace usrp{ /*! + * Possible subdev connection types: + * + * A complex subdevice is physically connected to both channels, + * which may be connected in one of two ways: IQ or QI (swapped). + * + * A real subdevice is only physically connected one channel, + * either only the I channel or only the Q channel. + */ + enum subdev_conn_t{ + SUBDEV_CONN_COMPLEX_IQ = 'C', + SUBDEV_CONN_COMPLEX_QI = 'c', + SUBDEV_CONN_REAL_I = 'R', + SUBDEV_CONN_REAL_Q = 'r' + }; + + /*! * Possible device subdev properties */ enum subdev_prop_t{ @@ -36,9 +52,7 @@ namespace uhd{ namespace usrp{ SUBDEV_PROP_ANTENNA = 'a', //rw, std::string SUBDEV_PROP_ANTENNA_NAMES = 'A', //ro, prop_names_t SUBDEV_PROP_LO_LOCKED = 'L', //ro, bool - SUBDEV_PROP_QUADRATURE = 'q', //ro, bool - SUBDEV_PROP_IQ_SWAPPED = 'i', //ro, bool - SUBDEV_PROP_SPECTRUM_INVERTED = 's', //ro, bool + SUBDEV_PROP_CONNECTION = 'c', //ro, subdev_conn_t SUBDEV_PROP_USE_LO_OFFSET = 'l', //ro, bool SUBDEV_PROP_RSSI = 'R', //ro, float SUBDEV_PROP_BANDWIDTH = 'B' //rw, double diff --git a/host/include/uhd/usrp/subdev_spec.hpp b/host/include/uhd/usrp/subdev_spec.hpp new file mode 100644 index 000000000..4d8f03b77 --- /dev/null +++ b/host/include/uhd/usrp/subdev_spec.hpp @@ -0,0 +1,95 @@ +// +// 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_USRP_SUBDEV_SPEC_HPP +#define INCLUDED_UHD_USRP_SUBDEV_SPEC_HPP + +#include <uhd/config.hpp> +#include <vector> +#include <string> + +namespace uhd{ namespace usrp{ + + /*! + * A subdevice specification (daughterboard, subdevice) name pairing. + */ + struct UHD_API subdev_spec_pair_t{ + //! The daughterboard name + std::string db_name; + + //! The subdevice name + std::string sd_name; + + /*! + * Create a new subdevice specification pair from dboard and subdev names. + * \param db_name the name of a daughterboard slot + * \param sd_name the name of a subdevice on that daughterboard + */ + subdev_spec_pair_t( + const std::string &db_name, const std::string &sd_name + ); + }; + + /*! + * A list of (daughterboard name, subdevice name) pairs: + * + * A subdevice specification represents a list of subdevices on a motherboard. + * The subdevices specified may span across multiple daughterboards; + * Hence the need for a subdevice specification over a simple list of strings. + * Typically, the user will pass a RX or TX subdevice specification into the API, + * and the implementation will infer the channel configuration from the specification. + * + * The subdevice specification can be represented as a markup-string. + * The markup-string is a whitespace separated list of dboard:subdev pairs. + * The "dboard:" part is optional on boards with only one daughterboard slot. + * The first pair represents the subdevice for channel zero, + * the second pair represents the subdevice for channel one, and so on. + * + * Examples: + * - Use subdevice AB on daughterboard A (USRP1): "A:AB" + * - Use subdevice A on daughterboard A for channel zero and subdevice A on daughterboard B for channel one (USRP1): "A:A B:A" + * - Use subdevice AB (USRP2): "AB" or ":AB" + * + * An empty subdevice specification can be used to automatically + * select the first subdevice on the first present daughterboard. + */ + class UHD_API subdev_spec_t : public std::vector<subdev_spec_pair_t>{ + public: + + /*! + * Create a subdev specification from a markup string. + * \param markup the markup string + */ + subdev_spec_t(const std::string &markup = ""); + + /*! + * Convert a subdev specification into a pretty print string. + * \return a printable string representing the subdev specification + */ + std::string to_pp_string(void) const; + + /*! + * Convert the subdevice specification into a markup string. + * The markup string contains the delimiter symbols. + * \return a string with delimiter markup + */ + std::string to_string(void) const; + }; + +}} + +#endif /* INCLUDED_UHD_USRP_SUBDEV_SPEC_HPP */ diff --git a/host/include/uhd/usrp/tune_helper.hpp b/host/include/uhd/usrp/tune_helper.hpp index f1e276d4f..df3907b3e 100644 --- a/host/include/uhd/usrp/tune_helper.hpp +++ b/host/include/uhd/usrp/tune_helper.hpp @@ -24,55 +24,75 @@ namespace uhd{ namespace usrp{ -/*! - * Tune a rx chain to the desired frequency: - * The IF of the subdevice is set as close as possible to - * the given target frequency + the LO offset (when applicable). - * The ddc cordic is setup to bring the IF down to baseband. - * \param subdev the dboard subdevice object with properties - * \param ddc the ddc properties object (with "if_rate", "bb_rate", "freq") - * \param target_freq the desired center frequency - * \param lo_offset an offset for the subdevice IF from center - * \return a tune result struct - */ -UHD_API tune_result_t tune_rx_subdev_and_ddc( - wax::obj subdev, wax::obj ddc, - double target_freq, double lo_offset -); + /*! + * Tune a rx chain to the desired frequency: + * The IF of the subdevice is set as close as possible to + * the given target frequency + the LO offset (when applicable). + * The ddc cordic is setup to bring the IF down to baseband. + * \param subdev the dboard subdevice object with properties + * \param ddc the mboard dsp object with properties + * \param target_freq the desired center frequency + * \param lo_offset an offset for the subdevice IF from center + * \return a tune result struct + */ + UHD_API tune_result_t tune_rx_subdev_and_dsp( + wax::obj subdev, wax::obj ddc, + double target_freq, double lo_offset + ); -/*! - * Tune a rx chain to the desired frequency: - * Same as the above, except the LO offset - * is calculated based on the subdevice and BW. - */ -UHD_API tune_result_t tune_rx_subdev_and_ddc( - wax::obj subdev, wax::obj ddc, double target_freq -); + /*! + * Tune a rx chain to the desired frequency: + * Same as the above, except the LO offset + * is calculated based on the subdevice and BW. + */ + UHD_API tune_result_t tune_rx_subdev_and_dsp( + wax::obj subdev, wax::obj ddc, double target_freq + ); -/*! - * Tune a tx chain to the desired frequency: - * The IF of the subdevice is set as close as possible to - * the given target frequency + the LO offset (when applicable). - * The duc cordic is setup to bring the baseband up to IF. - * \param subdev the dboard subdevice object with properties - * \param duc the duc properties object (with "if_rate", "bb_rate", "freq") - * \param target_freq the desired center frequency - * \param lo_offset an offset for the subdevice IF from center - * \return a tune result struct - */ -UHD_API tune_result_t tune_tx_subdev_and_duc( - wax::obj subdev, wax::obj duc, - double target_freq, double lo_offset -); + /*! + * Calculate the overall frequency from the combination of dboard IF and DDC shift. + * \param subdev the dboard subdevice object with properties + * \param ddc the mboard dsp object with properties + * \return the overall tune frequency of the system in Hz + */ + UHD_API double derive_freq_from_rx_subdev_and_dsp( + wax::obj subdev, wax::obj ddc + ); -/*! - * Tune a tx chain to the desired frequency: - * Same as the above, except the LO offset - * is calculated based on the subdevice and BW. - */ -UHD_API tune_result_t tune_tx_subdev_and_duc( - wax::obj subdev, wax::obj duc, double target_freq -); + /*! + * Tune a tx chain to the desired frequency: + * The IF of the subdevice is set as close as possible to + * the given target frequency + the LO offset (when applicable). + * The duc cordic is setup to bring the baseband up to IF. + * \param subdev the dboard subdevice object with properties + * \param duc the mboard dsp object with properties + * \param target_freq the desired center frequency + * \param lo_offset an offset for the subdevice IF from center + * \return a tune result struct + */ + UHD_API tune_result_t tune_tx_subdev_and_dsp( + wax::obj subdev, wax::obj duc, + double target_freq, double lo_offset + ); + + /*! + * Tune a tx chain to the desired frequency: + * Same as the above, except the LO offset + * is calculated based on the subdevice and BW. + */ + UHD_API tune_result_t tune_tx_subdev_and_dsp( + wax::obj subdev, wax::obj duc, double target_freq + ); + + /*! + * Calculate the overall frequency from the combination of dboard IF and DUC shift. + * \param subdev the dboard subdevice object with properties + * \param duc the mboard dsp object with properties + * \return the overall tune frequency of the system in Hz + */ + UHD_API double derive_freq_from_tx_subdev_and_dsp( + wax::obj subdev, wax::obj duc + ); }} diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index d484788b2..ef8e64ce0 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -22,11 +22,12 @@ INSTALL(FILES byteswap.hpp byteswap.ipp exception.hpp - gain_handler.hpp + gain_group.hpp pimpl.hpp props.hpp safe_main.hpp static.hpp thread_priority.hpp + warning.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils ) diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index b52edc6b5..1b5eacfa9 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -69,6 +69,31 @@ namespace std{ } /*! + * A wrapper around std::reverse that takes a range instead of an iterator. + * + * The elements are reversed into descending order using the less-than operator. + * + * \param range the range of elements to be reversed + */ + template<typename Range> inline void reverse(Range &range){ + return std::reverse(boost::begin(range), boost::end(range)); + } + + /*! + * A wrapper around std::reverse that takes a range instead of an iterator. + * + * The elements are reversed into descending order using the less-than operator. + * This wrapper reverses the elements non-destructively into a new range. + * Based on the builtin python function reversed(...) + * + * \param range the range of elements to be reversed + * \return a new range with the elements reversed + */ + template<typename Range> inline Range reversed(const Range &range){ + Range srange(range); std::reverse(srange); return srange; + } + + /*! * Is the value found within the elements in this range? * * Uses std::find to search the iterable for an element. @@ -112,17 +137,6 @@ namespace std{ } /*! - * A templated signum implementation. - * \param n the comparable to process - * \return -1 when n negative, +1 when n positive, otherwise 0 - */ - template<typename T> inline int signum(T n){ - if (n < 0) return -1; - if (n > 0) return +1; - return 0; - } - - /*! * A templated clip implementation. * \param val the value to clip between an upper and lower limit * \param bound1 the upper or lower bound diff --git a/host/include/uhd/utils/gain_group.hpp b/host/include/uhd/utils/gain_group.hpp new file mode 100644 index 000000000..3955dfa9a --- /dev/null +++ b/host/include/uhd/utils/gain_group.hpp @@ -0,0 +1,85 @@ +// +// 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_GAIN_GROUP_HPP +#define INCLUDED_UHD_UTILS_GAIN_GROUP_HPP + +#include <uhd/config.hpp> +#include <uhd/types/ranges.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/function.hpp> +#include <boost/utility.hpp> + +namespace uhd{ + +/*! + * A set of function to control a gain element. + */ +struct UHD_API gain_fcns_t{ + boost::function<gain_range_t(void)> get_range; + boost::function<float(void)> get_value; + boost::function<void(float)> set_value; +}; + +class UHD_API gain_group : boost::noncopyable{ +public: + typedef boost::shared_ptr<gain_group> sptr; + + /*! + * Get the overall gain range for this group. + * Overall step is defined as the minimum step size. + * \return a gain range with overall min, max, step + */ + virtual gain_range_t get_range(void) = 0; + + /*! + * Get the overall gain value for this group. + * \return a summation of all the gain values + */ + virtual float get_value(void) = 0; + + /*! + * Set the overall gain value for this group. + * The power will be distributed across individual gain elements. + * The semantics of how to do this are determined by the priority. + * \param gain the gain to set across the group + */ + virtual void set_value(float gain) = 0; + + /*! + * Register a set of gain functions into this group. + * Priority determines how power will be distributed + * with higher priorities getting the power first, + * and lower priorities getting the remainder power. + * \param gain_fcns the set of gain functions + * \param priority the priority of the gain element + */ + virtual void register_fcns( + const gain_fcns_t &gain_fcns, size_t priority = 0 + ) = 0; + + /*! + * Make a new empty gain group. + * \return a gain group object. + */ + static sptr make(void); +}; + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_GAIN_GROUP_HPP */ + diff --git a/host/include/uhd/utils/gain_handler.hpp b/host/include/uhd/utils/gain_handler.hpp deleted file mode 100644 index f4629e6a7..000000000 --- a/host/include/uhd/utils/gain_handler.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// -// 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_GAIN_HANDLER_HPP -#define INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP - -#include <uhd/config.hpp> -#include <uhd/wax.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/function.hpp> - -namespace uhd{ - -class UHD_API gain_handler{ -public: - typedef boost::shared_ptr<gain_handler> sptr; - typedef boost::function<bool(const wax::obj &, const wax::obj &)> is_equal_t; - - /*! - * A set of properties for dealing with gains. - */ - struct UHD_API props_t{ - wax::obj value, range, names; - props_t(void); //default constructor - }; - - /*! - * Make a new gain handler. - * The construction arguments are agnostic to the property type. - * It is up to the caller to provide an "is_equal" function that - * can tell weather two properties (in a wax obj) are equal. - * \param link a link to the wax obj with properties - * \param props a struct of properties keys - * \param is_equal the function that tests for equal properties - */ - static sptr make( - const wax::obj &link, - const props_t &props, - is_equal_t is_equal - ); - - /*! - * Intercept gets for overall gain, min, max, step. - * Ensures that the gain name is valid. - * \return true for handled, false to pass on - */ - virtual bool intercept_get(const wax::obj &key, wax::obj &val) = 0; - - /*! - * Intercept sets for overall gain. - * Ensures that the gain name is valid. - * Ensures that the new gain is within range. - * \return true for handled, false to pass on - */ - virtual bool intercept_set(const wax::obj &key, const wax::obj &val) = 0; - - /*! - * Function template to test if two wax types are equal: - * The constructor will bind an instance of this for a specific type. - * This bound equals functions allows the intercept methods to be non-templated. - */ - template <class T> static bool is_equal(const wax::obj &a, const wax::obj &b){ - try{ - return a.as<T>() == b.as<T>(); - } - catch(const wax::bad_cast &){ - return false; - } - } - -}; - -} //namespace uhd - -#endif /* INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP */ - diff --git a/host/include/uhd/utils/pimpl.hpp b/host/include/uhd/utils/pimpl.hpp index 09bf0c0a2..18454f0c4 100644 --- a/host/include/uhd/utils/pimpl.hpp +++ b/host/include/uhd/utils/pimpl.hpp @@ -20,6 +20,7 @@ #include <uhd/config.hpp> #include <boost/shared_ptr.hpp> +#include <boost/make_shared.hpp> /*! \file pimpl.hpp * "Pimpl idiom" (pointer to implementation idiom). @@ -50,6 +51,6 @@ * \param _args the constructor args for the pimpl */ #define UHD_PIMPL_MAKE(_name, _args) \ - boost::shared_ptr<_name>(new _name _args) + boost::make_shared<_name> _args #endif /* INCLUDED_UHD_UTILS_PIMPL_HPP */ diff --git a/host/include/uhd/utils/warning.hpp b/host/include/uhd/utils/warning.hpp new file mode 100644 index 000000000..91d8400ab --- /dev/null +++ b/host/include/uhd/utils/warning.hpp @@ -0,0 +1,34 @@ +// +// 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_WARNING_HPP +#define INCLUDED_UHD_UTILS_WARNING_HPP + +#include <uhd/config.hpp> +#include <string> + +namespace uhd{ + + /*! + * Print a formatted warning string to stderr. + * \param msg the multiline warning message + */ + UHD_API void print_warning(const std::string &msg); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_WARNING_HPP */ diff --git a/host/include/uhd/version.hpp b/host/include/uhd/version.hpp new file mode 100644 index 000000000..19d672e65 --- /dev/null +++ b/host/include/uhd/version.hpp @@ -0,0 +1,28 @@ +// +// 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_VERSION_HPP +#define INCLUDED_UHD_VERSION_HPP + +#include <uhd/config.hpp> +#include <string> + +namespace uhd{ + UHD_API std::string get_version_string(void); +} //namespace uhd + +#endif /* INCLUDED_UHD_VERSION_HPP */ |