diff options
Diffstat (limited to 'host')
33 files changed, 788 insertions, 549 deletions
diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 88e112584..58b5af9da 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -16,8 +16,7 @@ // #include <uhd/utils/safe_main.hpp> -#include <uhd/simple_device.hpp> -#include <uhd/props.hpp> +#include <uhd/usrp/simple_usrp.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <iostream> @@ -53,7 +52,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << std::endl; std::cout << boost::format("Creating the usrp device with: %s...") % transport_args << std::endl; - uhd::simple_device::sptr sdev = uhd::simple_device::make(transport_args); + uhd::usrp::simple_usrp::sptr sdev = uhd::usrp::simple_usrp::make(transport_args); uhd::device::sptr dev = sdev->get_device(); std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index b364f78cd..d63062032 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -24,8 +24,6 @@ ADD_SUBDIRECTORY(utils) INSTALL(FILES config.hpp device.hpp - props.hpp - simple_device.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd ) diff --git a/host/include/uhd/props.hpp b/host/include/uhd/props.hpp deleted file mode 100644 index 01746f853..000000000 --- a/host/include/uhd/props.hpp +++ /dev/null @@ -1,145 +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_PROPS_HPP -#define INCLUDED_UHD_PROPS_HPP - -#include <uhd/config.hpp> -#include <uhd/wax.hpp> -#include <boost/tuple/tuple.hpp> -#include <vector> -#include <string> - -namespace uhd{ - - //typedef for handling named properties - typedef std::vector<std::string> prop_names_t; - typedef boost::tuple<wax::obj, std::string> named_prop_t; - - /*! - * Utility function to separate a named property into its components. - * \param key a reference to the prop object - * \param name a reference to the name object - */ - inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file) - extract_named_prop(const wax::obj &key, const std::string &name = ""){ - if (key.type() == typeid(named_prop_t)){ - return key.as<named_prop_t>(); - } - return named_prop_t(key, name); - } - - /*! - * Possible device properties: - * In general, a device will have a single mboard. - * In certain mimo applications, multiple boards - * will be present in the interface for configuration. - */ - enum device_prop_t{ - DEVICE_PROP_NAME, //ro, std::string - DEVICE_PROP_MBOARD, //ro, wax::obj - DEVICE_PROP_MBOARD_NAMES, //ro, prop_names_t - DEVICE_PROP_MAX_RX_SAMPLES, //ro, size_t - DEVICE_PROP_MAX_TX_SAMPLES //ro, size_t - }; - - /*! - * Possible device mboard properties: - * The general mboard properties are listed below. - * Custom properties can be identified with a string - * and discovered though the others property. - */ - enum mboard_prop_t{ - MBOARD_PROP_NAME, //ro, std::string - MBOARD_PROP_OTHERS, //ro, prop_names_t - MBOARD_PROP_CLOCK_RATE, //ro, freq_t - MBOARD_PROP_RX_DSP, //ro, wax::obj - MBOARD_PROP_RX_DSP_NAMES, //ro, prop_names_t - MBOARD_PROP_TX_DSP, //ro, wax::obj - MBOARD_PROP_TX_DSP_NAMES, //ro, prop_names_t - MBOARD_PROP_RX_DBOARD, //ro, wax::obj - MBOARD_PROP_RX_DBOARD_NAMES, //ro, prop_names_t - MBOARD_PROP_TX_DBOARD, //ro, wax::obj - MBOARD_PROP_TX_DBOARD_NAMES, //ro, prop_names_t - MBOARD_PROP_CLOCK_CONFIG, //rw, clock_config_t - MBOARD_PROP_TIME_NOW, //wo, time_spec_t - MBOARD_PROP_TIME_NEXT_PPS //wo, time_spec_t - }; - - /*! - * Possible device dsp properties: - * A dsp can have a wide range of possible properties. - * A ddc would have a properties "decim", "freq", "taps"... - * Other properties could be gains, complex scalars, enables... - * For this reason the only required properties of a dsp is a name - * and a property to get list of other possible properties. - */ - enum dsp_prop_t{ - DSP_PROP_NAME, //ro, std::string - DSP_PROP_OTHERS //ro, prop_names_t - }; - - /*! - * Possible device dboard properties - */ - enum dboard_prop_t{ - DBOARD_PROP_NAME, //ro, std::string - DBOARD_PROP_SUBDEV, //ro, wax::obj - DBOARD_PROP_SUBDEV_NAMES, //ro, prop_names_t - DBOARD_PROP_USED_SUBDEVS //ro, prop_names_t - //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet - }; - - /*! ------ 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 - };*/ - - /*! - * Possible device subdev properties - */ - enum subdev_prop_t{ - SUBDEV_PROP_NAME, //ro, std::string - SUBDEV_PROP_OTHERS, //ro, prop_names_t - SUBDEV_PROP_GAIN, //rw, gain_t - SUBDEV_PROP_GAIN_RANGE, //ro, gain_range_t - SUBDEV_PROP_GAIN_NAMES, //ro, prop_names_t - SUBDEV_PROP_FREQ, //rw, freq_t - SUBDEV_PROP_FREQ_RANGE, //ro, freq_range_t - SUBDEV_PROP_ANTENNA, //rw, std::string - SUBDEV_PROP_ANTENNA_NAMES, //ro, prop_names_t - SUBDEV_PROP_ENABLED, //rw, bool - SUBDEV_PROP_QUADRATURE, //ro, bool - SUBDEV_PROP_IQ_SWAPPED, //ro, bool - SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool - SUBDEV_PROP_LO_INTERFERES //ro, bool - //SUBDEV_PROP_RSSI, //ro, gain_t //----> not on all boards, use named prop - //SUBDEV_PROP_BANDWIDTH //rw, freq_t //----> not on all boards, use named prop - }; - -} //namespace uhd - -#endif /* INCLUDED_UHD_PROPS_HPP */ diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index b9be370bd..c00daaaf0 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -17,11 +17,26 @@ INSTALL(FILES + #### props headers ### + dboard_props.hpp + device_props.hpp + dsp_props.hpp + mboard_props.hpp + subdev_props.hpp + + #### dboard headers ### dboard_base.hpp dboard_id.hpp dboard_interface.hpp dboard_manager.hpp + + ### usrp headers ### usrp_e.hpp usrp2.hpp + + ### utilities ### + tune_helper.hpp + simple_usrp.hpp + DESTINATION ${INCLUDE_DIR}/uhd/usrp ) diff --git a/host/include/uhd/usrp/dboard_interface.hpp b/host/include/uhd/usrp/dboard_interface.hpp index c779431ab..b3bab131d 100644 --- a/host/include/uhd/usrp/dboard_interface.hpp +++ b/host/include/uhd/usrp/dboard_interface.hpp @@ -38,32 +38,34 @@ public: //tells the host which unit to use enum unit_type_t{ - UNIT_TYPE_RX, - UNIT_TYPE_TX + UNIT_TYPE_RX = 'r', + UNIT_TYPE_TX = 't' }; //tells the host which device to use enum spi_dev_t{ - SPI_TX_DEV, - SPI_RX_DEV + SPI_DEV_RX = 'r', + SPI_DEV_TX = 't' }; - //args for writing spi data - enum spi_push_t{ - SPI_PUSH_RISE, - SPI_PUSH_FALL - }; - - //args for reading spi data - enum spi_latch_t{ - SPI_LATCH_RISE, - SPI_LATCH_FALL + //args for spi format + enum spi_edge_t{ + SPI_EDGE_RISE = 'r', + SPI_EDGE_FALL = 'f' }; //tell the host which gpio bank enum gpio_bank_t{ - GPIO_TX_BANK, - GPIO_RX_BANK + GPIO_BANK_RX = 'r', + GPIO_BANK_TX = 't' + }; + + //possible atr registers + enum atr_reg_t{ + ATR_REG_IDLE = 'i', + ATR_REG_TX_ONLY = 't', + ATR_REG_RX_ONLY = 'r', + ATR_REG_FULL_DUPLEX = 'f' }; //structors @@ -87,17 +89,13 @@ public: virtual int read_aux_adc(unit_type_t unit, int which_adc) = 0; /*! - * Set daughterboard ATR register. - * The ATR register for a particular bank has 2 values: - * one value when transmitting, one when receiving. - * The mask controls which pins are controlled by ATR. + * Set a daughterboard ATR register. * - * \param bank GPIO_TX_BANK or GPIO_RX_BANK - * \param tx_value 16-bits, 0=FPGA output low, 1=FPGA output high - * \param rx_value 16-bits, 0=FPGA output low, 1=FPGA output high - * \param mask 16-bits, 0=software, 1=atr + * \param bank GPIO_TX_BANK or GPIO_RX_BANK + * \param reg which ATR register to set + * \param value 16-bits, 0=FPGA output low, 1=FPGA output high */ - virtual void set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_value, boost::uint16_t rx_value, boost::uint16_t mask) = 0; + virtual void set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value) = 0; /*! * Set daughterboard GPIO data direction register. @@ -108,14 +106,6 @@ public: virtual void set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value) = 0; /*! - * Set daughterboard GPIO pin values. - * - * \param bank GPIO_TX_BANK or GPIO_RX_BANK - * \param value 16 bits, 0=low, 1=high - */ - virtual void write_gpio(gpio_bank_t bank, boost::uint16_t value) = 0; - - /*! * Read daughterboard GPIO pin values * * \param bank GPIO_TX_BANK or GPIO_RX_BANK @@ -142,32 +132,31 @@ public: * \brief Write data to SPI bus peripheral. * * \param dev which spi device - * \param push args for writing + * \param edge args for format * \param buf the data to write */ - void write_spi(spi_dev_t dev, spi_push_t push, const byte_vector_t &buf); + void write_spi(spi_dev_t dev, spi_edge_t edge, const byte_vector_t &buf); /*! * \brief Read data to SPI bus peripheral. * * \param dev which spi device - * \param latch args for reading + * \param edge args for format * \param num_bytes number of bytes to read * \return the data that was read */ - byte_vector_t read_spi(spi_dev_t dev, spi_latch_t latch, size_t num_bytes); + byte_vector_t read_spi(spi_dev_t dev, spi_edge_t edge, size_t num_bytes); /*! * \brief Read and write data to SPI bus peripheral. * The data read back will be the same length as the input buffer. * * \param dev which spi device - * \param latch args for reading - * \param push args for clock + * \param edge args for format * \param buf the data to write * \return the data that was read */ - byte_vector_t read_write_spi(spi_dev_t dev, spi_latch_t latch, spi_push_t push, const byte_vector_t &buf); + byte_vector_t read_write_spi(spi_dev_t dev, spi_edge_t edge, const byte_vector_t &buf); /*! * \brief Get the rate of the rx dboard clock. @@ -186,16 +175,14 @@ private: * \brief Read and write data to SPI bus peripheral. * * \param dev which spi device - * \param latch args for reading - * \param push args for clock + * \param edge args for format * \param buf the data to write * \param readback false for write only * \return the data that was read */ virtual byte_vector_t transact_spi( spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, + spi_edge_t edge, const byte_vector_t &buf, bool readback ) = 0; diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index c7c091220..ed8ee73ef 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -19,7 +19,7 @@ #define INCLUDED_UHD_USRP_DBOARD_MANAGER_HPP #include <uhd/config.hpp> -#include <uhd/props.hpp> +#include <uhd/utils/props.hpp> #include <uhd/usrp/dboard_base.hpp> #include <uhd/usrp/dboard_id.hpp> #include <boost/utility.hpp> diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp new file mode 100644 index 000000000..3b290319f --- /dev/null +++ b/host/include/uhd/usrp/dboard_props.hpp @@ -0,0 +1,38 @@ +// +// 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_DBOARD_PROPS_HPP +#define INCLUDED_UHD_USRP_DBOARD_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device dboard properties + */ + 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_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet + }; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_DBOARD_PROPS_HPP */ diff --git a/host/include/uhd/usrp/device_props.hpp b/host/include/uhd/usrp/device_props.hpp new file mode 100644 index 000000000..b8f6f5cd4 --- /dev/null +++ b/host/include/uhd/usrp/device_props.hpp @@ -0,0 +1,57 @@ +// +// 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_DEVICE_PROPS_HPP +#define INCLUDED_UHD_USRP_DEVICE_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device properties: + * In general, a device will have a single mboard. + * In certain mimo applications, multiple boards + * will be present in the interface for configuration. + */ + enum device_prop_t{ + DEVICE_PROP_NAME = 'n', //ro, std::string + DEVICE_PROP_MBOARD = 'm', //ro, wax::obj + DEVICE_PROP_MBOARD_NAMES = 'M', //ro, prop_names_t + DEVICE_PROP_MAX_RX_SAMPLES = 'r', //ro, size_t + DEVICE_PROP_MAX_TX_SAMPLES = 't' //ro, size_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/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp new file mode 100644 index 000000000..60c0df942 --- /dev/null +++ b/host/include/uhd/usrp/dsp_props.hpp @@ -0,0 +1,40 @@ +// +// 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_DSP_PROPS_HPP +#define INCLUDED_UHD_USRP_DSP_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device dsp properties: + * A dsp can have a wide range of possible properties. + * A ddc would have a properties "decim", "freq", "taps"... + * Other properties could be gains, complex scalars, enables... + * For this reason the only required properties of a dsp is a name + * and a property to get list of other possible properties. + */ + enum dsp_prop_t{ + DSP_PROP_NAME = 'n', //ro, std::string + DSP_PROP_OTHERS = 'o' //ro, prop_names_t + }; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_DSP_PROPS_HPP */ diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp new file mode 100644 index 000000000..cfc1f412e --- /dev/null +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -0,0 +1,50 @@ +// +// 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_MBOARD_PROPS_HPP +#define INCLUDED_UHD_USRP_MBOARD_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device mboard properties: + * The general mboard properties are listed below. + * Custom properties can be identified with a string + * and discovered though the others property. + */ + enum mboard_prop_t{ + MBOARD_PROP_NAME = 'n', //ro, std::string + MBOARD_PROP_OTHERS = 'o', //ro, prop_names_t + MBOARD_PROP_CLOCK_RATE = 'c', //ro, double + MBOARD_PROP_RX_DSP = 'd', //ro, wax::obj + MBOARD_PROP_RX_DSP_NAMES = 'D', //ro, prop_names_t + MBOARD_PROP_TX_DSP = 'u', //ro, wax::obj + MBOARD_PROP_TX_DSP_NAMES = 'U', //ro, prop_names_t + MBOARD_PROP_RX_DBOARD = 'e', //ro, wax::obj + 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_CLOCK_CONFIG = 'C', //rw, clock_config_t + MBOARD_PROP_TIME_NOW = 't', //wo, time_spec_t + MBOARD_PROP_TIME_NEXT_PPS = 'T' //wo, time_spec_t + }; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_MBOARD_PROPS_HPP */ diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/usrp/simple_usrp.hpp index 52928367a..2d6ad2a0f 100644 --- a/host/include/uhd/simple_device.hpp +++ b/host/include/uhd/usrp/simple_usrp.hpp @@ -15,29 +15,30 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_UHD_SIMPLE_DEVICE_HPP -#define INCLUDED_UHD_SIMPLE_DEVICE_HPP +#ifndef INCLUDED_UHD_USRP_SIMPLE_USRP_HPP +#define INCLUDED_UHD_USRP_SIMPLE_USRP_HPP #include <uhd/config.hpp> #include <uhd/device.hpp> #include <uhd/types/ranges.hpp> #include <uhd/types/stream_cmd.hpp> +#include <uhd/types/clock_config.hpp> #include <uhd/types/tune_result.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> #include <vector> -namespace uhd{ +namespace uhd{ namespace usrp{ /*! - * The simple UHD device class: - * A simple device facilitates ease-of-use for most use-case scenarios. + * The simple USRP device class: + * A simple usrp facilitates ease-of-use for most use-case scenarios. * The wrapper provides convenience functions to tune the devices * as well as to set the dboard gains, antennas, and other properties. */ -class UHD_API simple_device : boost::noncopyable{ +class UHD_API simple_usrp : boost::noncopyable{ public: - typedef boost::shared_ptr<simple_device> sptr; + typedef boost::shared_ptr<simple_usrp> sptr; static sptr make(const std::string &args); virtual device::sptr get_device(void) = 0; @@ -45,15 +46,13 @@ public: virtual std::string get_name(void) = 0; /******************************************************************* - * Timing + * Misc ******************************************************************/ virtual void set_time_now(const time_spec_t &time_spec) = 0; virtual void set_time_next_pps(const time_spec_t &time_spec) = 0; - - /******************************************************************* - * Streaming - ******************************************************************/ virtual void issue_stream_cmd(const stream_cmd_t &stream_cmd) = 0; + virtual void set_clock_config(const clock_config_t &clock_config) = 0; + virtual double get_clock_rate(void) = 0; /******************************************************************* * RX methods @@ -92,6 +91,6 @@ public: virtual std::vector<std::string> get_tx_antennas(void) = 0; }; -} //namespace uhd +}} -#endif /* INCLUDED_UHD_SIMPLE_DEVICE_HPP */ +#endif /* INCLUDED_UHD_USRP_SIMPLE_USRP_HPP */ diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp new file mode 100644 index 000000000..92d18340b --- /dev/null +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -0,0 +1,49 @@ +// +// 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_PROPS_HPP +#define INCLUDED_UHD_USRP_SUBDEV_PROPS_HPP + +#include <uhd/utils/props.hpp> + +namespace uhd{ namespace usrp{ + + /*! + * Possible device subdev properties + */ + enum subdev_prop_t{ + SUBDEV_PROP_NAME = 'n', //ro, std::string + SUBDEV_PROP_OTHERS = 'o', //ro, prop_names_t + SUBDEV_PROP_GAIN = 'g', //rw, float + SUBDEV_PROP_GAIN_RANGE = 'r', //ro, gain_range_t + SUBDEV_PROP_GAIN_NAMES = 'G', //ro, prop_names_t + SUBDEV_PROP_FREQ = 'f', //rw, double + SUBDEV_PROP_FREQ_RANGE = 'F', //ro, freq_range_t + SUBDEV_PROP_ANTENNA = 'a', //rw, std::string + SUBDEV_PROP_ANTENNA_NAMES = 'A', //ro, prop_names_t + SUBDEV_PROP_ENABLED = 'e', //rw, bool + SUBDEV_PROP_QUADRATURE = 'q', //ro, bool + SUBDEV_PROP_IQ_SWAPPED = 'i', //ro, bool + SUBDEV_PROP_SPECTRUM_INVERTED = 's', //ro, bool + SUBDEV_PROP_LO_INTERFERES = 'l' //ro, bool + //SUBDEV_PROP_RSSI, //ro, float //----> not on all boards, use named prop + //SUBDEV_PROP_BANDWIDTH //rw, double //----> not on all boards, use named prop + }; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_SUBDEV_PROPS_HPP */ diff --git a/host/include/uhd/utils/tune_helper.hpp b/host/include/uhd/usrp/tune_helper.hpp index 958d1eceb..f1e276d4f 100644 --- a/host/include/uhd/utils/tune_helper.hpp +++ b/host/include/uhd/usrp/tune_helper.hpp @@ -15,14 +15,14 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#ifndef INCLUDED_UHD_UTILS_TUNE_HELPER_HPP -#define INCLUDED_UHD_UTILS_TUNE_HELPER_HPP +#ifndef INCLUDED_UHD_USRP_TUNE_HELPER_HPP +#define INCLUDED_UHD_USRP_TUNE_HELPER_HPP #include <uhd/config.hpp> #include <uhd/wax.hpp> #include <uhd/types/tune_result.hpp> -namespace uhd{ +namespace uhd{ namespace usrp{ /*! * Tune a rx chain to the desired frequency: @@ -74,6 +74,6 @@ UHD_API tune_result_t tune_tx_subdev_and_duc( wax::obj subdev, wax::obj duc, double target_freq ); -} //namespace uhd +}} -#endif /* INCLUDED_UHD_UTILS_TUNE_HELPER_HPP */ +#endif /* INCLUDED_UHD_USRP_TUNE_HELPER_HPP */ diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index 1b673f44a..2831ab0b0 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -19,8 +19,8 @@ INSTALL(FILES algorithm.hpp assert.hpp gain_handler.hpp + props.hpp safe_main.hpp static.hpp - tune_helper.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils ) diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp new file mode 100644 index 000000000..6be0b2ce5 --- /dev/null +++ b/host/include/uhd/utils/props.hpp @@ -0,0 +1,48 @@ +// +// 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_PROPS_HPP +#define INCLUDED_UHD_UTILS_PROPS_HPP + +#include <uhd/config.hpp> +#include <uhd/wax.hpp> +#include <boost/tuple/tuple.hpp> +#include <vector> +#include <string> + +namespace uhd{ + + //typedef for handling named properties + typedef std::vector<std::string> prop_names_t; + typedef boost::tuple<wax::obj, std::string> named_prop_t; + + /*! + * Utility function to separate a named property into its components. + * \param key a reference to the prop object + * \param name a reference to the name object + */ + inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file) + extract_named_prop(const wax::obj &key, const std::string &name = ""){ + if (key.type() == typeid(named_prop_t)){ + return key.as<named_prop_t>(); + } + return named_prop_t(key, name); + } + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_PROPS_HPP */ diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 4e8dea6c5..3dfd54312 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -22,8 +22,6 @@ SET(libuhd_sources device.cpp gain_handler.cpp load_modules.cpp - simple_device.cpp - tune_helper.cpp types.cpp wax.cpp transport/if_addrs.cpp @@ -32,7 +30,9 @@ SET(libuhd_sources usrp/dboard/db_basic_and_lf.cpp usrp/dboard_base.cpp usrp/dboard_interface.cpp + usrp/simple_usrp.cpp usrp/dboard_manager.cpp + usrp/tune_helper.cpp usrp/usrp2/dboard_impl.cpp usrp/usrp2/dboard_interface.cpp usrp/usrp2/dsp_impl.cpp diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp index daf629f0b..36e2e8ed3 100644 --- a/host/lib/gain_handler.cpp +++ b/host/lib/gain_handler.cpp @@ -18,7 +18,7 @@ #include <uhd/utils/gain_handler.hpp> #include <uhd/utils/assert.hpp> #include <uhd/types/ranges.hpp> -#include <uhd/props.hpp> +#include <uhd/utils/props.hpp> #include <boost/assign/list_of.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index 50c868a24..be4e646ed 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -15,7 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <uhd/props.hpp> +#include <uhd/usrp/subdev_props.hpp> #include <uhd/types/ranges.hpp> #include <uhd/utils/assert.hpp> #include <uhd/utils/static.hpp> @@ -88,7 +88,7 @@ UHD_STATIC_BLOCK(reg_dboards){ basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){ _max_freq = max_freq; // set the gpios to safe values (all inputs) - get_interface()->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000); + get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000); } basic_rx::~basic_rx(void){ @@ -199,7 +199,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){ _max_freq = max_freq; // set the gpios to safe values (all inputs) - get_interface()->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000); + get_interface()->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000); } basic_tx::~basic_tx(void){ diff --git a/host/lib/usrp/dboard_interface.cpp b/host/lib/usrp/dboard_interface.cpp index f6d6b6456..c40c9b398 100644 --- a/host/lib/usrp/dboard_interface.cpp +++ b/host/lib/usrp/dboard_interface.cpp @@ -29,26 +29,25 @@ dboard_interface::~dboard_interface(void){ void dboard_interface::write_spi( spi_dev_t dev, - spi_push_t push, + spi_edge_t edge, const byte_vector_t &buf ){ - transact_spi(dev, SPI_LATCH_RISE, push, buf, false); //dont readback + transact_spi(dev, edge, buf, false); //dont readback } dboard_interface::byte_vector_t dboard_interface::read_spi( spi_dev_t dev, - spi_latch_t latch, + spi_edge_t edge, size_t num_bytes ){ byte_vector_t buf(num_bytes, 0x00); //dummy data - return transact_spi(dev, latch, SPI_PUSH_RISE, buf, true); //readback + return transact_spi(dev, edge, buf, true); //readback } dboard_interface::byte_vector_t dboard_interface::read_write_spi( spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, + spi_edge_t edge, const byte_vector_t &buf ){ - return transact_spi(dev, latch, push, buf, true); //readback + return transact_spi(dev, edge, buf, true); //readback } diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 15be7eedc..3a5cf3a35 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -16,6 +16,7 @@ // #include <uhd/usrp/dboard_manager.hpp> +#include <uhd/usrp/subdev_props.hpp> #include <uhd/utils/gain_handler.hpp> #include <uhd/utils/static.hpp> #include <uhd/utils/assert.hpp> @@ -275,12 +276,9 @@ wax::obj dboard_manager_impl::get_tx_subdev(const std::string &subdev_name){ void dboard_manager_impl::set_nice_gpio_pins(void){ //std::cout << "Set nice GPIO pins" << std::endl; - _interface->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000); //all inputs - _interface->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000); + _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000); //all inputs + _interface->set_atr_reg(dboard_interface::GPIO_BANK_RX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low - _interface->write_gpio(dboard_interface::GPIO_RX_BANK, 0x0000); //all zeros - _interface->write_gpio(dboard_interface::GPIO_TX_BANK, 0x0000); - - _interface->set_atr_reg(dboard_interface::GPIO_RX_BANK, 0x0000, 0x0000, 0x0000); //software controlled - _interface->set_atr_reg(dboard_interface::GPIO_TX_BANK, 0x0000, 0x0000, 0x0000); + _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000); //all inputs + _interface->set_atr_reg(dboard_interface::GPIO_BANK_TX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low } diff --git a/host/lib/simple_device.cpp b/host/lib/usrp/simple_usrp.cpp index 25beb45a9..a0551a630 100644 --- a/host/lib/simple_device.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -15,15 +15,19 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <uhd/simple_device.hpp> -#include <uhd/utils/tune_helper.hpp> +#include <uhd/usrp/simple_usrp.hpp> +#include <uhd/usrp/tune_helper.hpp> #include <uhd/utils/assert.hpp> -#include <uhd/props.hpp> +#include <uhd/usrp/subdev_props.hpp> +#include <uhd/usrp/mboard_props.hpp> +#include <uhd/usrp/device_props.hpp> +#include <uhd/usrp/dboard_props.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> #include <stdexcept> using namespace uhd; +using namespace uhd::usrp; /*********************************************************************** * Helper Functions @@ -39,9 +43,9 @@ static std::vector<double> get_xx_rates(wax::obj decerps, wax::obj rate){ /*********************************************************************** * Simple Device Implementation **********************************************************************/ -class simple_device_impl : public simple_device{ +class simple_usrp_impl : public simple_usrp{ public: - simple_device_impl(const device_addr_t &addr){ + simple_usrp_impl(const device_addr_t &addr){ _dev = device::make(addr); _mboard = (*_dev)[DEVICE_PROP_MBOARD]; _rx_ddc = _mboard[named_prop_t(MBOARD_PROP_RX_DSP, "ddc0")]; @@ -58,7 +62,7 @@ public: _tx_subdev = tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]; } - ~simple_device_impl(void){ + ~simple_usrp_impl(void){ /* NOP */ } @@ -71,7 +75,7 @@ public: } /******************************************************************* - * Timing + * Misc ******************************************************************/ void set_time_now(const time_spec_t &time_spec){ _mboard[MBOARD_PROP_TIME_NOW] = time_spec; @@ -81,13 +85,18 @@ public: _mboard[MBOARD_PROP_TIME_NEXT_PPS] = time_spec; } - /******************************************************************* - * Streaming - ******************************************************************/ void issue_stream_cmd(const stream_cmd_t &stream_cmd){ _rx_ddc[std::string("stream_cmd")] = stream_cmd; } + void set_clock_config(const clock_config_t &clock_config){ + _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; + } + + double get_clock_rate(void){ + return _mboard[MBOARD_PROP_CLOCK_RATE].as<double>(); + } + /******************************************************************* * RX methods ******************************************************************/ @@ -134,7 +143,7 @@ public: } std::vector<std::string> get_rx_antennas(void){ - return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >(); + return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>(); } /******************************************************************* @@ -183,7 +192,7 @@ public: } std::vector<std::string> get_tx_antennas(void){ - return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<std::vector<std::string> >(); + return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>(); } private: @@ -198,6 +207,6 @@ private: /*********************************************************************** * The Make Function **********************************************************************/ -simple_device::sptr simple_device::make(const std::string &args){ - return sptr(new simple_device_impl(device_addr_t::from_args_str(args))); +simple_usrp::sptr simple_usrp::make(const std::string &args){ + return sptr(new simple_usrp_impl(device_addr_t::from_args_str(args))); } diff --git a/host/lib/tune_helper.cpp b/host/lib/usrp/tune_helper.cpp index 1e5c4cd0d..79a6aff7b 100644 --- a/host/lib/tune_helper.cpp +++ b/host/lib/usrp/tune_helper.cpp @@ -15,12 +15,13 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <uhd/utils/tune_helper.hpp> +#include <uhd/usrp/tune_helper.hpp> #include <uhd/utils/algorithm.hpp> -#include <uhd/props.hpp> +#include <uhd/usrp/subdev_props.hpp> #include <cmath> using namespace uhd; +using namespace uhd::usrp; /*********************************************************************** * Tune Helper Function @@ -81,7 +82,7 @@ static tune_result_t tune_xx_subdev_and_dxc( /*********************************************************************** * RX Tune **********************************************************************/ -tune_result_t uhd::tune_rx_subdev_and_ddc( +tune_result_t uhd::usrp::tune_rx_subdev_and_ddc( wax::obj subdev, wax::obj ddc, double target_freq, double lo_offset ){ @@ -89,7 +90,7 @@ tune_result_t uhd::tune_rx_subdev_and_ddc( return tune_xx_subdev_and_dxc(is_tx, subdev, ddc, target_freq, lo_offset); } -tune_result_t uhd::tune_rx_subdev_and_ddc( +tune_result_t uhd::usrp::tune_rx_subdev_and_ddc( wax::obj subdev, wax::obj ddc, double target_freq ){ @@ -104,7 +105,7 @@ tune_result_t uhd::tune_rx_subdev_and_ddc( /*********************************************************************** * TX Tune **********************************************************************/ -tune_result_t uhd::tune_tx_subdev_and_duc( +tune_result_t uhd::usrp::tune_tx_subdev_and_duc( wax::obj subdev, wax::obj duc, double target_freq, double lo_offset ){ @@ -112,7 +113,7 @@ tune_result_t uhd::tune_tx_subdev_and_duc( return tune_xx_subdev_and_dxc(is_tx, subdev, duc, target_freq, lo_offset); } -tune_result_t uhd::tune_tx_subdev_and_duc( +tune_result_t uhd::usrp::tune_tx_subdev_and_duc( wax::obj subdev, wax::obj duc, double target_freq ){ diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index fd72aeaa4..30883cd50 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -15,10 +15,13 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // + +#include "usrp2_impl.hpp" +#include "usrp2_regs.hpp" +#include <uhd/usrp/subdev_props.hpp> +#include <uhd/usrp/dboard_props.hpp> #include <uhd/utils/assert.hpp> -#include <uhd/types/clock_config.hpp> #include <boost/format.hpp> -#include "usrp2_impl.hpp" using namespace uhd; using namespace uhd::usrp; @@ -57,11 +60,13 @@ void usrp2_impl::dboard_init(void){ //init the subdevs in use (use the first subdevice) _rx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_rx_subdev_names().at(0)); + update_rx_mux_config(); + _tx_subdevs_in_use = prop_names_t(1, _dboard_manager->get_tx_subdev_names().at(0)); - update_mux_config(); + update_tx_mux_config(); } -void usrp2_impl::update_mux_config(void){ +void usrp2_impl::update_rx_mux_config(void){ //calculate the rx mux boost::uint32_t rx_mux = 0; ASSERT_THROW(_rx_subdevs_in_use.size() == 1); @@ -76,6 +81,10 @@ void usrp2_impl::update_mux_config(void){ rx_mux = (((rx_mux >> 0) & 0x3) << 2) | (((rx_mux >> 2) & 0x3) << 0); } + this->poke(FR_DSP_RX_MUX, rx_mux); +} + +void usrp2_impl::update_tx_mux_config(void){ //calculate the tx mux boost::uint32_t tx_mux = 0x10; ASSERT_THROW(_tx_subdevs_in_use.size() == 1); @@ -85,15 +94,7 @@ void usrp2_impl::update_mux_config(void){ tx_mux = (((tx_mux >> 0) & 0x1) << 1) | (((tx_mux >> 1) & 0x1) << 0); } - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO); - out_data.data.mux_args.rx_mux = htonl(rx_mux); - out_data.data.mux_args.tx_mux = htonl(tx_mux); - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE); + this->poke(FR_DSP_TX_MUX, tx_mux); } /*********************************************************************** @@ -129,7 +130,7 @@ void usrp2_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){ _rx_subdevs_in_use = val.as<prop_names_t>(); - update_mux_config(); //if the val is bad, this will throw + update_rx_mux_config(); //if the val is bad, this will throw return; } @@ -169,7 +170,7 @@ void usrp2_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ void usrp2_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ if (key.as<dboard_prop_t>() == DBOARD_PROP_USED_SUBDEVS){ _tx_subdevs_in_use = val.as<prop_names_t>(); - update_mux_config(); //if the val is bad, this will throw + update_tx_mux_config(); //if the val is bad, this will throw return; } diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index 5a7d870b4..dcd6453a8 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -15,8 +15,12 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <uhd/utils/assert.hpp> #include "usrp2_impl.hpp" +#include "usrp2_regs.hpp" +#include <uhd/types/dict.hpp> +#include <uhd/utils/assert.hpp> +#include <boost/assign/list_of.hpp> +#include <algorithm> using namespace uhd::usrp; @@ -28,9 +32,8 @@ public: void write_aux_dac(unit_type_t, int, int); int read_aux_adc(unit_type_t, int); - void set_atr_reg(gpio_bank_t, boost::uint16_t, boost::uint16_t, boost::uint16_t); + void set_atr_reg(gpio_bank_t, atr_reg_t, boost::uint16_t); void set_gpio_ddr(gpio_bank_t, boost::uint16_t); - void write_gpio(gpio_bank_t, boost::uint16_t); boost::uint16_t read_gpio(gpio_bank_t); void write_i2c(int, const byte_vector_t &); @@ -41,14 +44,21 @@ public: private: byte_vector_t transact_spi( - spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, - const byte_vector_t &buf, - bool readback + spi_dev_t, spi_edge_t, const byte_vector_t &, bool ); usrp2_impl *_impl; + + //shadows + boost::uint32_t _ddr_shadow; + uhd::dict<atr_reg_t, uint32_t> _atr_reg_shadows; + + //utilities + static int bank_to_shift(gpio_bank_t bank){ + static const uhd::dict<gpio_bank_t, int> _bank_to_shift = \ + boost::assign::map_list_of(GPIO_BANK_RX, 0)(GPIO_BANK_TX, 16); + return _bank_to_shift[bank]; + } }; /*********************************************************************** @@ -63,6 +73,7 @@ dboard_interface::sptr make_usrp2_dboard_interface(usrp2_impl *impl){ **********************************************************************/ usrp2_dboard_interface::usrp2_dboard_interface(usrp2_impl *impl){ _impl = impl; + _ddr_shadow = 0; } usrp2_dboard_interface::~usrp2_dboard_interface(void){ @@ -83,70 +94,43 @@ double usrp2_dboard_interface::get_tx_clock_rate(void){ /*********************************************************************** * GPIO **********************************************************************/ -/*! - * Static function to convert a gpio bank enum - * to an over-the-wire value for the usrp2 control. - * \param bank the dboard interface gpio bank enum - * \return an over the wire representation - */ -static boost::uint8_t gpio_bank_to_otw(dboard_interface::gpio_bank_t bank){ - switch(bank){ - case uhd::usrp::dboard_interface::GPIO_TX_BANK: return USRP2_DIR_TX; - case uhd::usrp::dboard_interface::GPIO_RX_BANK: return USRP2_DIR_RX; - } - throw std::invalid_argument("unknown gpio bank type"); -} - void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO); - out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); - out_data.data.gpio_config.value = htons(value); - out_data.data.gpio_config.mask = htons(0xffff); - - //send and recv - usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_GPIO_DDR_SETTINGS_DUDE); -} - -void usrp2_dboard_interface::write_gpio(gpio_bank_t bank, boost::uint16_t value){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO); - out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); - out_data.data.gpio_config.value = htons(value); - out_data.data.gpio_config.mask = htons(0xffff); - - //send and recv - usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_I_SET_THE_GPIO_PIN_OUTS_DUDE); + //calculate the new 32 bit ddr value + int shift = bank_to_shift(bank); + boost::uint32_t new_ddr_val = + (_ddr_shadow & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits + | (boost::uint32_t(value) << shift); //or'ed in the new bits + + //poke in the value and shadow + _impl->poke(FR_GPIO_DDR, new_ddr_val); + _ddr_shadow = new_ddr_val; } boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO); - out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); - - //send and recv - usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE); - return ntohs(in_data.data.gpio_config.value); + boost::uint32_t data = _impl->peek(FR_GPIO_IO); + return boost::uint16_t(data >> bank_to_shift(bank)); } -void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_value, boost::uint16_t rx_value, boost::uint16_t mask){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO); - out_data.data.atr_config.bank = gpio_bank_to_otw(bank); - out_data.data.atr_config.tx_value = htons(tx_value); - out_data.data.atr_config.rx_value = htons(rx_value); - out_data.data.atr_config.mask = htons(mask); - - //send and recv - usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_ATR_SETTINGS_DUDE); +void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value){ + //map the atr reg to an offset in register space + static const uhd::dict<atr_reg_t, int> reg_to_addr = boost::assign::map_list_of + (ATR_REG_IDLE, FR_ATR_IDLE) (ATR_REG_TX_ONLY, FR_ATR_TX) + (ATR_REG_RX_ONLY, FR_ATR_RX) (ATR_REG_FULL_DUPLEX, FR_ATR_FULL) + ; + ASSERT_THROW(reg_to_addr.has_key(reg)); + + //ensure a value exists in the shadow + if (not _atr_reg_shadows.has_key(reg)) _atr_reg_shadows[reg] = 0; + + //calculate the new 32 bit atr value + int shift = bank_to_shift(bank); + boost::uint32_t new_atr_val = + (_atr_reg_shadows[reg] & ~(boost::uint32_t(0xffff) << shift)) //zero out new bits + | (boost::uint32_t(value) << shift); //or'ed in the new bits + + //poke in the value and shadow + _impl->poke(reg_to_addr[reg], new_atr_val); + _atr_reg_shadows[reg] = new_atr_val; } /*********************************************************************** @@ -160,44 +144,29 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, boost::uint16_t tx_va */ static boost::uint8_t spi_dev_to_otw(dboard_interface::spi_dev_t dev){ switch(dev){ - case uhd::usrp::dboard_interface::SPI_TX_DEV: return USRP2_DIR_TX; - case uhd::usrp::dboard_interface::SPI_RX_DEV: return USRP2_DIR_RX; + case uhd::usrp::dboard_interface::SPI_DEV_TX: return SPI_SS_TX_DB; + case uhd::usrp::dboard_interface::SPI_DEV_RX: return SPI_SS_RX_DB; } throw std::invalid_argument("unknown spi device type"); } /*! - * Static function to convert a spi latch enum + * Static function to convert a spi edge enum * to an over-the-wire value for the usrp2 control. - * \param latch the dboard interface spi latch enum + * \param edge the dboard interface spi edge enum * \return an over the wire representation */ -static boost::uint8_t spi_latch_to_otw(dboard_interface::spi_latch_t latch){ - switch(latch){ - case uhd::usrp::dboard_interface::SPI_LATCH_RISE: return USRP2_CLK_EDGE_RISE; - case uhd::usrp::dboard_interface::SPI_LATCH_FALL: return USRP2_CLK_EDGE_FALL; +static boost::uint8_t spi_edge_to_otw(dboard_interface::spi_edge_t edge){ + switch(edge){ + case uhd::usrp::dboard_interface::SPI_EDGE_RISE: return USRP2_CLK_EDGE_RISE; + case uhd::usrp::dboard_interface::SPI_EDGE_FALL: return USRP2_CLK_EDGE_FALL; } - throw std::invalid_argument("unknown spi latch type"); -} - -/*! - * Static function to convert a spi push enum - * to an over-the-wire value for the usrp2 control. - * \param push the dboard interface spi push enum - * \return an over the wire representation - */ -static boost::uint8_t spi_push_to_otw(dboard_interface::spi_push_t push){ - switch(push){ - case uhd::usrp::dboard_interface::SPI_PUSH_RISE: return USRP2_CLK_EDGE_RISE; - case uhd::usrp::dboard_interface::SPI_PUSH_FALL: return USRP2_CLK_EDGE_FALL; - } - throw std::invalid_argument("unknown spi push type"); + throw std::invalid_argument("unknown spi edge type"); } dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi( spi_dev_t dev, - spi_latch_t latch, - spi_push_t push, + spi_edge_t edge, const byte_vector_t &buf, bool readback ){ @@ -205,8 +174,7 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi( usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO); out_data.data.spi_args.dev = spi_dev_to_otw(dev); - out_data.data.spi_args.latch = spi_latch_to_otw(latch); - out_data.data.spi_args.push = spi_push_to_otw(push); + out_data.data.spi_args.edge = spi_edge_to_otw(edge); out_data.data.spi_args.readback = (readback)? 1 : 0; out_data.data.spi_args.bytes = buf.size(); @@ -214,9 +182,7 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi( ASSERT_THROW(buf.size() <= sizeof(out_data.data.spi_args.data)); //copy in the data - for (size_t i = 0; i < buf.size(); i++){ - out_data.data.spi_args.data[i] = buf[i]; - } + std::copy(buf.begin(), buf.end(), out_data.data.spi_args.data); //send and recv usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); @@ -224,10 +190,8 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::transact_spi( ASSERT_THROW(in_data.data.spi_args.bytes == buf.size()); //copy out the data - byte_vector_t result; - for (size_t i = 0; i < buf.size(); i++){ - result.push_back(in_data.data.spi_args.data[i]); - } + byte_vector_t result(buf.size()); + std::copy(in_data.data.spi_args.data, in_data.data.spi_args.data + buf.size(), result.begin()); return result; } @@ -245,9 +209,7 @@ void usrp2_dboard_interface::write_i2c(int i2c_addr, const byte_vector_t &buf){ ASSERT_THROW(buf.size() <= sizeof(out_data.data.i2c_args.data)); //copy in the data - for (size_t i = 0; i < buf.size(); i++){ - out_data.data.i2c_args.data[i] = buf[i]; - } + std::copy(buf.begin(), buf.end(), out_data.data.i2c_args.data); //send and recv usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); @@ -270,10 +232,8 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::read_i2c(int i2c_addr, s ASSERT_THROW(in_data.data.i2c_args.addr = num_bytes); //copy out the data - byte_vector_t result; - for (size_t i = 0; i < num_bytes; i++){ - result.push_back(in_data.data.i2c_args.data[i]); - } + byte_vector_t result(num_bytes); + std::copy(in_data.data.i2c_args.data, in_data.data.i2c_args.data + num_bytes, result.begin()); return result; } diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 0d43fac0e..d70248682 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -15,13 +15,16 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "usrp2_impl.hpp" +#include "usrp2_regs.hpp" +#include <uhd/usrp/dsp_props.hpp> #include <uhd/utils/assert.hpp> #include <boost/format.hpp> #include <boost/assign/list_of.hpp> #include <boost/math/special_functions/round.hpp> -#include "usrp2_impl.hpp" using namespace uhd; +using namespace uhd::usrp; static const size_t default_decim = 16; static const size_t default_interp = 16; @@ -64,25 +67,22 @@ void usrp2_impl::init_ddc_config(void){ update_ddc_config(); //initial command that kills streaming (in case if was left on) - //issue_ddc_stream_cmd(TODO) + stream_cmd_t stream_cmd_off; + stream_cmd_off.stream_now = true; + stream_cmd_off.continuous = false; + stream_cmd_off.num_samps = 0; + issue_ddc_stream_cmd(stream_cmd_off); } void usrp2_impl::update_ddc_config(void){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO); - out_data.data.ddc_args.freq_word = htonl( - calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) - ); - out_data.data.ddc_args.decim = htonl(_ddc_decim); + //set the decimation + this->poke(FR_DSP_RX_DECIM_RATE, _ddc_decim); + + //set the scaling static const boost::int16_t default_rx_scale_iq = 1024; - out_data.data.ddc_args.scale_iq = htonl( + this->poke(FR_DSP_RX_SCALE_IQ, calculate_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq) ); - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE); } void usrp2_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){ @@ -172,7 +172,9 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); _ddc_freq = new_freq; //shadow - update_ddc_config(); + this->poke(FR_DSP_RX_FREQ, + calculate_freq_word_and_update_actual_freq(_ddc_freq, get_master_clock_freq()) + ); return; } else if (key_name == "stream_cmd"){ @@ -210,20 +212,11 @@ void usrp2_impl::update_duc_config(void){ double interp_cubed = std::pow(double(tmp_interp), 3); boost::int16_t scale = rint((4096*std::pow(2, ceil(log2(interp_cubed))))/(1.65*interp_cubed)); - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO); - out_data.data.duc_args.freq_word = htonl( - calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq()) - ); - out_data.data.duc_args.interp = htonl(_duc_interp); - out_data.data.duc_args.scale_iq = htonl( - calculate_iq_scale_word(scale, scale) - ); + //set the interpolation + this->poke(FR_DSP_TX_INTERP_RATE, _ddc_decim); - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE); + //set the scaling + this->poke(FR_DSP_TX_SCALE_IQ, calculate_iq_scale_word(scale, scale)); } /*********************************************************************** @@ -297,7 +290,9 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); _duc_freq = new_freq; //shadow - update_duc_config(); + this->poke(FR_DSP_TX_FREQ, + calculate_freq_word_and_update_actual_freq(_duc_freq, get_master_clock_freq()) + ); return; } diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 30fee6c32..c168614ee 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -45,87 +45,50 @@ extern "C" { #define USRP2_UDP_DATA_PORT 49153 typedef enum{ - USRP2_CTRL_ID_HUH_WHAT, + USRP2_CTRL_ID_HUH_WHAT = ' ', //USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums //USRP2_CTRL_ID_SUX_MAN, - USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO, - USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE, - USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO, + USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO = 'a', + USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE = 'A', + USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO = 'b', - USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO, - USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE, - USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO, + USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO = 'm', + USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE = 'M', + USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO = 'n', - USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO, - USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE, + USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO = 'd', + USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE = 'D', - USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO, - USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE, + USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's', + USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S', - USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO, - USRP2_CTRL_ID_GOT_THE_GPIO_DDR_SETTINGS_DUDE, + USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO = 'i', + USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE = 'I', - USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO, - USRP2_CTRL_ID_I_SET_THE_GPIO_PIN_OUTS_DUDE, + USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO = 'h', + USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE = 'H', - USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO, - USRP2_CTRL_ID_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE, + USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO = 'x', + USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE = 'X', - USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO, - USRP2_CTRL_ID_GOT_THE_ATR_SETTINGS_DUDE, + USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO = 'y', + USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE = 'Y', - USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO, - USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE, + USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO = '{', + USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE = '}', - USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO, - USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE, + USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO = 'p', + USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE = 'P', - USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO, - USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE, + USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO = 'r', + USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE = 'R', - USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO, - USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE, - - USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO, - USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE, - - USRP2_CTRL_ID_SETUP_THIS_DDC_FOR_ME_BRO, - USRP2_CTRL_ID_TOTALLY_SETUP_THE_DDC_DUDE, - - USRP2_CTRL_ID_SEND_STREAM_COMMAND_FOR_ME_BRO, - USRP2_CTRL_ID_GOT_THAT_STREAM_COMMAND_DUDE, - - USRP2_CTRL_ID_SETUP_THIS_DUC_FOR_ME_BRO, - USRP2_CTRL_ID_TOTALLY_SETUP_THE_DUC_DUDE, - - USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO, - USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE, - - USRP2_CTRL_ID_UPDATE_THOSE_MUX_SETTINGS_BRO, - USRP2_CTRL_ID_UPDATED_THE_MUX_SETTINGS_DUDE, - - USRP2_CTRL_ID_PEACE_OUT + USRP2_CTRL_ID_PEACE_OUT = '~' } usrp2_ctrl_id_t; typedef enum{ - USRP2_PPS_SOURCE_SMA, - USRP2_PPS_SOURCE_MIMO -} usrp2_pps_source_t; - -typedef enum{ - USRP2_PPS_POLARITY_POS, - USRP2_PPS_POLARITY_NEG -} usrp2_pps_polarity_t; - -typedef enum{ - USRP2_REF_SOURCE_INT, - USRP2_REF_SOURCE_SMA, - USRP2_REF_SOURCE_MIMO -} usrp2_ref_source_t; - -typedef enum{ USRP2_DIR_RX, USRP2_DIR_TX } usrp2_dir_which_t; @@ -146,28 +109,8 @@ typedef struct{ _SINS_ uint16_t tx_id; } dboard_ids; struct { - _SINS_ uint8_t pps_source; - _SINS_ uint8_t pps_polarity; - _SINS_ uint8_t ref_source; - _SINS_ uint8_t _pad; - } clock_config; - struct { - _SINS_ uint8_t bank; - _SINS_ uint8_t _pad[3]; - _SINS_ uint16_t value; - _SINS_ uint16_t mask; - } gpio_config; - struct { - _SINS_ uint8_t bank; - _SINS_ uint8_t _pad[3]; - _SINS_ uint16_t tx_value; - _SINS_ uint16_t rx_value; - _SINS_ uint16_t mask; - } atr_config; - struct { _SINS_ uint8_t dev; - _SINS_ uint8_t latch; - _SINS_ uint8_t push; + _SINS_ uint8_t edge; _SINS_ uint8_t readback; _SINS_ uint8_t bytes; _SINS_ uint8_t data[sizeof(_SINS_ uint32_t)]; @@ -184,11 +127,6 @@ typedef struct{ _SINS_ uint32_t value; } aux_args; struct { - _SINS_ uint32_t freq_word; - _SINS_ uint32_t decim; - _SINS_ uint32_t scale_iq; - } ddc_args; - struct { _SINS_ uint8_t now; //stream now? _SINS_ uint8_t continuous; //auto-reload commmands? _SINS_ uint8_t _pad[2]; @@ -197,19 +135,9 @@ typedef struct{ _SINS_ uint32_t num_samps; } stream_cmd; struct { - _SINS_ uint32_t freq_word; - _SINS_ uint32_t interp; - _SINS_ uint32_t scale_iq; - } duc_args; - struct { - _SINS_ uint32_t secs; - _SINS_ uint32_t ticks; - _SINS_ uint8_t now; - } time_args; - struct { - _SINS_ uint32_t rx_mux; - _SINS_ uint32_t tx_mux; - } mux_args; + _SINS_ uint32_t addr; + _SINS_ uint32_t data; + } poke_args; } data; } usrp2_ctrl_data_t; diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 35dfd6287..7594c85fa 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -15,11 +15,15 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "usrp2_impl.hpp" +#include "usrp2_regs.hpp" +#include <uhd/usrp/mboard_props.hpp> #include <uhd/utils/assert.hpp> #include <uhd/types/mac_addr.hpp> -#include "usrp2_impl.hpp" +#include <uhd/types/dict.hpp> using namespace uhd; +using namespace uhd::usrp; /*********************************************************************** * Helper Methods @@ -46,55 +50,36 @@ void usrp2_impl::init_clock_config(void){ } void usrp2_impl::update_clock_config(void){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO); - - //translate ref source enums - switch(_clock_config.ref_source){ - case clock_config_t::REF_INT: - out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_INT; break; - case clock_config_t::REF_SMA: - out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_SMA; break; - case clock_config_t::REF_MIMO: - out_data.data.clock_config.ref_source = USRP2_REF_SOURCE_MIMO; break; - default: throw std::runtime_error("usrp2: unhandled clock configuration ref source"); - } + boost::uint32_t pps_flags = 0; //translate pps source enums switch(_clock_config.pps_source){ - case clock_config_t::PPS_SMA: - out_data.data.clock_config.pps_source = USRP2_PPS_SOURCE_SMA; break; - case clock_config_t::PPS_MIMO: - out_data.data.clock_config.pps_source = USRP2_PPS_SOURCE_MIMO; break; + case clock_config_t::PPS_SMA: pps_flags |= FRF_TIME64_PPS_SMA; break; + case clock_config_t::PPS_MIMO: pps_flags |= FRF_TIME64_PPS_MIMO; break; default: throw std::runtime_error("usrp2: unhandled clock configuration pps source"); } //translate pps polarity enums switch(_clock_config.pps_polarity){ - case clock_config_t::PPS_POS: - out_data.data.clock_config.pps_source = USRP2_PPS_POLARITY_POS; break; - case clock_config_t::PPS_NEG: - out_data.data.clock_config.pps_source = USRP2_PPS_POLARITY_NEG; break; + case clock_config_t::PPS_POS: pps_flags |= FRF_TIME64_PPS_POSEDGE; break; + case clock_config_t::PPS_NEG: pps_flags |= FRF_TIME64_PPS_NEGEDGE; break; default: throw std::runtime_error("usrp2: unhandled clock configuration pps polarity"); } - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE); + //set the pps flags + this->poke(FR_TIME64_FLAGS, pps_flags); + + //TODO clock source ref 10mhz (spi ad9510) } void usrp2_impl::set_time_spec(const time_spec_t &time_spec, bool now){ - //setup the out data - usrp2_ctrl_data_t out_data; - out_data.id = htonl(USRP2_CTRL_ID_GOT_A_NEW_TIME_FOR_YOU_BRO); - out_data.data.time_args.secs = htonl(time_spec.secs); - out_data.data.time_args.ticks = htonl(time_spec.ticks); - out_data.data.time_args.now = (now)? 1 : 0; - - //send and recv - usrp2_ctrl_data_t in_data = ctrl_send_and_recv(out_data); - ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_SWEET_I_GOT_THAT_TIME_DUDE); + //set ticks and seconds + this->poke(FR_TIME64_SECS, time_spec.secs); + this->poke(FR_TIME64_TICKS, time_spec.ticks); + + //set the register to latch it all in + boost::uint32_t imm_flags = (now)? FRF_TIME64_LATCH_NOW : FRF_TIME64_LATCH_NEXT_PPS; + this->poke(FR_TIME64_IMM, imm_flags); } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index b0ee395fb..b3a22e175 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -16,6 +16,7 @@ // #include <uhd/transport/if_addrs.hpp> +#include <uhd/usrp/device_props.hpp> #include <uhd/utils/assert.hpp> #include <uhd/utils/static.hpp> #include <boost/format.hpp> @@ -173,6 +174,30 @@ double usrp2_impl::get_master_clock_freq(void){ return 100e6; } +void usrp2_impl::poke(boost::uint32_t addr, boost::uint32_t data){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_POKE_THIS_REGISTER_FOR_ME_BRO); + out_data.data.poke_args.addr = htonl(addr); + out_data.data.poke_args.data = htonl(data); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE); +} + +boost::uint32_t usrp2_impl::peek(boost::uint32_t addr){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO); + out_data.data.poke_args.addr = htonl(addr); + + //send and recv + usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); + return ntohl(out_data.data.poke_args.data); +} + /*********************************************************************** * Control Send/Recv **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 3468a0cf1..55be420cd 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -102,6 +102,10 @@ public: //performs a control transaction usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &); + //peek and poke registers + void poke(boost::uint32_t addr, boost::uint32_t data); + boost::uint32_t peek(boost::uint32_t addr); + //misc access methods double get_master_clock_freq(void); @@ -168,7 +172,8 @@ private: void tx_dboard_set(const wax::obj &, const wax::obj &); uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dboards; uhd::prop_names_t _tx_subdevs_in_use; - void update_mux_config(void); + void update_rx_mux_config(void); + void update_tx_mux_config(void); //methods and shadows for the ddc dsp std::vector<size_t> _allowed_decim_and_interp_rates; diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp new file mode 100644 index 000000000..10545d712 --- /dev/null +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -0,0 +1,199 @@ +// +// 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_USRP2_REGS_HPP +#define INCLUDED_USRP2_REGS_HPP + +#include <boost/cstdint.hpp> + +//////////////////////////////////////////////////// +// Settings Bus, Slave #7, Not Byte Addressable! +// +// Output-only from processor point-of-view. +// 1KB of address space (== 256 32-bit write-only regs) + + +#define MISC_OUTPUT_BASE 0xD400 +//#define TX_PROTOCOL_ENGINE_BASE 0xD480 +//#define RX_PROTOCOL_ENGINE_BASE 0xD4C0 +//#define BUFFER_POOL_CTRL_BASE 0xD500 +//#define LAST_SETTING_REG 0xD7FC // last valid setting register + +#define SR_MISC 0 +#define SR_TX_PROT_ENG 32 +#define SR_RX_PROT_ENG 48 +#define SR_BUFFER_POOL_CTRL 64 +#define SR_UDP_SM 96 +#define SR_TX_DSP 208 +#define SR_TX_CTRL 224 +#define SR_RX_DSP 160 +#define SR_RX_CTRL 176 +#define SR_TIME64 192 +#define SR_SIMTIMER 198 +#define SR_LAST 255 + +#define _SR_ADDR(sr) (MISC_OUTPUT_BASE + (sr) * sizeof(boost::uint32_t)) + +///////////////////////////////////////////////// +// SPI Slave Constants +//////////////////////////////////////////////// +// Masks for controlling different peripherals +#define SPI_SS_AD9510 1 +#define SPI_SS_AD9777 2 +#define SPI_SS_RX_DAC 4 +#define SPI_SS_RX_ADC 8 +#define SPI_SS_RX_DB 16 +#define SPI_SS_TX_DAC 32 +#define SPI_SS_TX_ADC 64 +#define SPI_SS_TX_DB 128 + +///////////////////////////////////////////////// +// VITA49 64 bit time (write only) +//////////////////////////////////////////////// + /*! + * \brief Time 64 flags + * + * <pre> + * + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +-----------------------------------------------------------+-+-+ + * | |S|P| + * +-----------------------------------------------------------+-+-+ + * + * P - PPS edge selection (0=negedge, 1=posedge, default=0) + * S - Source (0=sma, 1=mimo, 0=default) + * + * </pre> + */ +#define FR_TIME64_SECS _SR_ADDR(SR_TIME64 + 0) // value to set absolute secs to on next PPS +#define FR_TIME64_TICKS _SR_ADDR(SR_TIME64 + 1) // value to set absolute ticks to on next PPS +#define FR_TIME64_FLAGS _SR_ADDR(SR_TIME64 + 2) // flags - see chart above +#define FR_TIME64_IMM _SR_ADDR(SR_TIME64 + 3) // set immediate (0=latch on next pps, 1=latch immediate, default=0) + +//pps flags (see above) +#define FRF_TIME64_PPS_NEGEDGE (0 << 0) +#define FRF_TIME64_PPS_POSEDGE (1 << 0) +#define FRF_TIME64_PPS_SMA (0 << 1) +#define FRF_TIME64_PPS_MIMO (1 << 1) + +#define FRF_TIME64_LATCH_NOW 1 +#define FRF_TIME64_LATCH_NEXT_PPS 0 + +///////////////////////////////////////////////// +// DSP TX Regs +//////////////////////////////////////////////// +#define FR_DSP_TX_FREQ _SR_ADDR(SR_TX_DSP + 0) +#define FR_DSP_TX_SCALE_IQ _SR_ADDR(SR_TX_DSP + 1) // {scale_i,scale_q} +#define FR_DSP_TX_INTERP_RATE _SR_ADDR(SR_TX_DSP + 2) + + /*! + * \brief output mux configuration. + * + * <pre> + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +-------------------------------+-------+-------+-------+-------+ + * | | DAC1 | DAC0 | + * +-------------------------------+-------+-------+-------+-------+ + * + * There are N DUCs (1 now) with complex inputs and outputs. + * There are two DACs. + * + * Each 4-bit DACx field specifies the source for the DAC + * Each subfield is coded like this: + * + * 3 2 1 0 + * +-------+ + * | N | + * +-------+ + * + * N specifies which DUC output is connected to this DAC. + * + * N which interp output + * --- ------------------- + * 0 DUC 0 I + * 1 DUC 0 Q + * 2 DUC 1 I + * 3 DUC 1 Q + * F All Zeros + * + * The default value is 0x10 + * </pre> + */ +#define FR_DSP_TX_MUX _SR_ADDR(SR_TX_DSP + 4) + +///////////////////////////////////////////////// +// DSP RX Regs +//////////////////////////////////////////////// +#define FR_DSP_RX_FREQ _SR_ADDR(SR_RX_DSP + 0) +#define FR_DSP_RX_SCALE_IQ _SR_ADDR(SR_RX_DSP + 1) // {scale_i,scale_q} +#define FR_DSP_RX_DECIM_RATE _SR_ADDR(SR_RX_DSP + 2) +#define FR_DSP_RX_DCOFFSET_I _SR_ADDR(SR_RX_DSP + 3) // Bit 31 high sets fixed offset mode, using lower 14 bits, + // otherwise it is automatic +#define FR_DSP_RX_DCOFFSET_Q _SR_ADDR(SR_RX_DSP + 4) // Bit 31 high sets fixed offset mode, using lower 14 bits + /*! + * \brief input mux configuration. + * + * This determines which ADC (or constant zero) is connected to + * each DDC input. There are N DDCs (1 now). Each has two inputs. + * + * <pre> + * Mux value: + * + * 3 2 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * +-------+-------+-------+-------+-------+-------+-------+-------+ + * | |Q0 |I0 | + * +-------+-------+-------+-------+-------+-------+-------+-------+ + * + * Each 2-bit I field is either 00 (A/D A), 01 (A/D B) or 1X (const zero) + * Each 2-bit Q field is either 00 (A/D A), 01 (A/D B) or 1X (const zero) + * + * The default value is 0x4 + * </pre> + */ +#define FR_DSP_RX_MUX _SR_ADDR(SR_RX_DSP + 5) // called adc_mux in dsp_core_rx.v + +//////////////////////////////////////////////// +// GPIO, Slave 4 +//////////////////////////////////////////////// +// +// These go to the daughterboard i/o pins +// +#define _FR_GPIO_ADDR(off) (0xC800 + (off) * sizeof(boost::uint32_t)) +#define FR_GPIO_IO _FR_GPIO_ADDR(0) // tx data in high 16, rx in low 16 +#define FR_GPIO_DDR _FR_GPIO_ADDR(1) // 32 bits, 1 means output. tx in high 16, rx in low 16 +#define FR_GPIO_TX_SEL _FR_GPIO_ADDR(2) // 16 2-bit fields select which source goes to TX DB +#define FR_GPIO_RX_SEL _FR_GPIO_ADDR(3) // 16 2-bit fields select which source goes to RX DB + +// each 2-bit sel field is layed out this way +#define FRF_GPIO_SEL_SW 0 // if pin is an output, set by software in the io reg +#define FRF_GPIO_SEL_ATR 1 // if pin is an output, set by ATR logic +#define FRF_GPIO_SEL_DEBUG_0 2 // if pin is an output, debug lines from FPGA fabric +#define FRF_GPIO_SEL_DEBUG_1 3 // if pin is an output, debug lines from FPGA fabric + +/////////////////////////////////////////////////// +// ATR Controller, Slave 11 +//////////////////////////////////////////////// +#define _FR_ATR_ADDR(off) (0xE400 + (off) * sizeof(boost::uint32_t)) +#define FR_ATR_IDLE _FR_ATR_ADDR(0) // tx data in high 16, rx in low 16 +#define FR_ATR_TX _FR_ATR_ADDR(1) +#define FR_ATR_RX _FR_ATR_ADDR(2) +#define FR_ATR_FULL _FR_ATR_ADDR(3) + +#endif /* INCLUDED_USRP2_REGS_HPP */ diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index 76b065ce2..72d26e1c2 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -19,7 +19,7 @@ #include <uhd/utils/gain_handler.hpp> #include <uhd/types/ranges.hpp> #include <uhd/types/dict.hpp> -#include <uhd/props.hpp> +#include <uhd/utils/props.hpp> #include <boost/bind.hpp> #include <iostream> diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp index b328216d0..6c945cbca 100644 --- a/host/utils/uhd_find_devices.cpp +++ b/host/utils/uhd_find_devices.cpp @@ -17,7 +17,6 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/device.hpp> -#include <uhd/props.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <iostream> diff --git a/host/utils/usrp2_burner.cpp b/host/utils/usrp2_burner.cpp index b24425316..9c1bf72fe 100644 --- a/host/utils/usrp2_burner.cpp +++ b/host/utils/usrp2_burner.cpp @@ -17,7 +17,7 @@ #include <uhd/utils/safe_main.hpp> #include <uhd/usrp/usrp2.hpp> -#include <uhd/props.hpp> +#include <uhd/usrp/device_props.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> #include <iostream> @@ -56,7 +56,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //create a usrp2 device uhd::device::sptr u2_dev = uhd::usrp::usrp2::make(device_addr); //FIXME usees the default mboard for now (until the mimo link is supported) - wax::obj u2_mb = (*u2_dev)[uhd::DEVICE_PROP_MBOARD]; + wax::obj u2_mb = (*u2_dev)[uhd::usrp::DEVICE_PROP_MBOARD]; std::cout << std::endl; //fetch and print current settings |