From 9cb9e7d52255d3e14e57867eee76b555f705954c Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Fri, 13 Aug 2010 16:20:41 -0700 Subject: usrp1: Add usrp1 implementation --- host/lib/usrp/usrp1/mboard_impl.cpp | 188 ++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 host/lib/usrp/usrp1/mboard_impl.cpp (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp new file mode 100644 index 000000000..ee1ba305b --- /dev/null +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -0,0 +1,188 @@ +// +// 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 . +// + +#include "usrp1_impl.hpp" +#include "usrp_commands.h" +#include +#include +#include +#include + +using namespace uhd; +using namespace uhd::usrp; + +/*********************************************************************** + * Mboard Initialization + **********************************************************************/ +void usrp1_impl::mboard_init(void) +{ + _mboard_proxy = wax_obj_proxy::make( + boost::bind(&usrp1_impl::mboard_get, this, _1, _2), + boost::bind(&usrp1_impl::mboard_set, this, _1, _2)); + + /* + * Basic initialization + */ + _iface->poke32( 13, 0x00000000); //FR_MODE + _iface->poke32( 14, 0x00000000); //FR_DEBUG_EN + _iface->poke32( 1, 0x00000001); //FR_RX_SAMPLE_RATE_DEV + _iface->poke32( 0, 0x00000003); //FR_TX_SAMPLE_RATE_DEV + _iface->poke32( 15, 0x0000000f); //FR_DC_OFFSET_CL_EN + + /* + * Reset codecs + */ + _iface->poke32( 16, 0x00000000); //FR_ADC_OFFSET_0 + _iface->poke32( 17, 0x00000000); //FR_ADC_OFFSET_1 + _iface->poke32( 18, 0x00000000); //FR_ADC_OFFSET_2 + _iface->poke32( 19, 0x00000000); //FR_ADC_OFFSET_3 + + /* + * Reset GPIO masks + */ + _iface->poke32( 6, 0xffff0000); //FR_OE_1 + _iface->poke32( 10, 0xffff0000); //FR_IO_1 + _iface->poke32( 8, 0xffff0000); //FR_OE_3 + _iface->poke32( 12, 0xffff0000); //FR_IO_3 + + /* + * Disable ATR masks and reset state registers + */ + _iface->poke32( 23, 0x00000000); //FR_ATR_MASK_1 + _iface->poke32( 24, 0x00000000); //FR_ATR_TXVAL_1 + _iface->poke32( 25, 0x00000000); //FR_ATR_RXVAL_1 + _iface->poke32( 29, 0x00000000); //FR_ATR_MASK_3 + _iface->poke32( 30, 0x00000000); //FR_ATR_TXVAL_3 + _iface->poke32( 31, 0x00000000); //FR_ATR_RXVAL_3 + + /* + * Set defaults for RX format, decimation, and mux + */ + _iface->poke32( 49, 0x00000300); //FR_RX_FORMAT + _iface->poke32( 38, 0x000e4e41); //FR_RX_MUX + + /* + * Set defaults for TX format, interpolation, and mux + */ + _iface->poke32( 48, 0x00000000); //FR_TX_FORMAT + _iface->poke32( 39, 0x00000981); //FR_TX_MUX + + /* + * Reset DDC registers + */ + _iface->poke32( 34, 0x00000000); //FR_RX_FREQ_0 + _iface->poke32( 44, 0x00000000); //FR_RX_PHASE_0 + _iface->poke32( 35, 0x00000000); //FR_RX_FREQ_1 + _iface->poke32( 45, 0x00000000); //FR_RX_PHASE_1 + _iface->poke32( 36, 0x00000000); //FR_RX_FREQ_2 + _iface->poke32( 46, 0x00000000); //FR_RX_PHASE_2 + _iface->poke32( 37, 0x00000000); //FR_RX_FREQ_3 + _iface->poke32( 47, 0x00000000); //FR_RX_PHASE_3 + +} + +void usrp1_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) +{ + if (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_START_CONTINUOUS) { + _iface->write_firmware_cmd(VRQ_FPGA_SET_RX_ENABLE, true, 0, 0, 0); + } + + if (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS) { + _iface->write_firmware_cmd(VRQ_FPGA_SET_RX_ENABLE, false, 0, 0, 0); + } +} + +/*********************************************************************** + * Mboard Get + **********************************************************************/ +void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) +{ + wax::obj key; + std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(key.as()){ + case MBOARD_PROP_NAME: + val = std::string("usrp1 mboard"); + return; + + case MBOARD_PROP_OTHERS: + val = prop_names_t(); + return; + + case MBOARD_PROP_RX_DBOARD: + UHD_ASSERT_THROW(name == ""); + val = _rx_dboard_proxy->get_link(); + return; + + case MBOARD_PROP_RX_DBOARD_NAMES: + val = prop_names_t(1, ""); //vector of size 1 with empty string + return; + + case MBOARD_PROP_TX_DBOARD: + UHD_ASSERT_THROW(name == ""); + val = _tx_dboard_proxy->get_link(); + return; + + case MBOARD_PROP_TX_DBOARD_NAMES: + val = prop_names_t(1, ""); //vector of size 1 with empty string + return; + + case MBOARD_PROP_RX_DSP: + UHD_ASSERT_THROW(name == ""); + val = _rx_ddc_proxy->get_link(); + return; + + case MBOARD_PROP_RX_DSP_NAMES: + val = prop_names_t(1, ""); + return; + + case MBOARD_PROP_TX_DSP: + UHD_ASSERT_THROW(name == ""); + val = _tx_duc_proxy->get_link(); + return; + + case MBOARD_PROP_TX_DSP_NAMES: + val = prop_names_t(1, ""); + return; + + case MBOARD_PROP_CLOCK_CONFIG: + val = _clock_config; + return; + + default: UHD_THROW_PROP_GET_ERROR(); + } +} + +/*********************************************************************** + * Mboard Set + **********************************************************************/ +void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) +{ + //handle the get request conditioned on the key + switch(key.as()){ + + case MBOARD_PROP_STREAM_CMD: + issue_stream_cmd(val.as()); + return; + + case MBOARD_PROP_TIME_NOW: + case MBOARD_PROP_TIME_NEXT_PPS: + default: UHD_THROW_PROP_SET_ERROR(); + } +} -- cgit v1.2.3 From 2e978d8835b8f954b7c34c42138b64d3a5767f81 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 12:40:37 -0700 Subject: usrp1: compiling off next branch made usb checking changes implemented named_prop_t::extract change copied the remainder of the codec pga gain control --- host/lib/transport/CMakeLists.txt | 1 + host/lib/transport/libusb1_control.cpp | 14 ++++----- host/lib/usrp/usrp1/CMakeLists.txt | 56 ++++++++++++++++++++++------------ host/lib/usrp/usrp1/codec_ctrl.cpp | 8 ++--- host/lib/usrp/usrp1/codec_ctrl.hpp | 16 ++++++++++ host/lib/usrp/usrp1/codec_impl.cpp | 33 +++++++++----------- host/lib/usrp/usrp1/dboard_iface.cpp | 7 +++-- host/lib/usrp/usrp1/dboard_impl.cpp | 14 ++++----- host/lib/usrp/usrp1/mboard_impl.cpp | 12 +++----- host/lib/usrp/usrp1/usrp1_impl.cpp | 5 ++- 10 files changed, 98 insertions(+), 68 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index d6e1ff7ba..627d2d806 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -30,6 +30,7 @@ IF(LIBUSB_FOUND) ${CMAKE_SOURCE_DIR}/lib/transport/libusb1_control.cpp ${CMAKE_SOURCE_DIR}/lib/transport/libusb1_zero_copy.cpp ) + SET(HAVE_USB_SUPPORT TRUE) ENDIF(LIBUSB_FOUND) ######################################################################## diff --git a/host/lib/transport/libusb1_control.cpp b/host/lib/transport/libusb1_control.cpp index 2903d943d..c2f7060e8 100644 --- a/host/lib/transport/libusb1_control.cpp +++ b/host/lib/transport/libusb1_control.cpp @@ -16,10 +16,10 @@ // #include -#include #include #include #include +#include #include using namespace uhd::transport; @@ -61,15 +61,15 @@ libusb_control_impl::libusb_control_impl(uhd::usb_descriptor_t descriptor) : _descriptor(descriptor), _ctx(NULL), _dev_handle(NULL) { if (libusb_init(&_ctx) < 0) - UHD_THROW_SITE_INFO("USB: failed to initialize libusb"); + throw std::runtime_error("USB: failed to initialize libusb"); libusb_set_debug(_ctx, libusb_debug_level); if (!open_device()) - UHD_THROW_SITE_INFO("USB: failed to open device"); + throw std::runtime_error("USB: failed to open device"); if (!open_interface()) - UHD_THROW_SITE_INFO("USB: failed to open device interface"); + throw std::runtime_error("USB: failed to open device interface"); } @@ -85,7 +85,7 @@ uhd::usb_descriptor_t libusb_control_impl::create_descriptor(libusb_device *dev) libusb_device_descriptor desc; if (libusb_get_device_descriptor(dev, &desc) < 0) - UHD_THROW_SITE_INFO("USB: failed to get device descriptor"); + throw std::runtime_error("USB: failed to get device descriptor"); uhd::usb_descriptor_t descriptor; @@ -217,12 +217,12 @@ uhd::usb_descriptors_t usb_control::get_device_list() uhd::usb_descriptors_t descriptors; if (libusb_init(NULL) < 0) - UHD_THROW_SITE_INFO("USB: failed to initialize libusb"); + throw std::runtime_error("USB: failed to initialize libusb"); ssize_t cnt = libusb_get_device_list(NULL, &list); if (cnt < 0) - UHD_THROW_SITE_INFO("USB: failed to get device list"); + throw std::runtime_error("USB: failed to get device list"); ssize_t i = 0; for (i = 0; i < cnt; i++) { diff --git a/host/lib/usrp/usrp1/CMakeLists.txt b/host/lib/usrp/usrp1/CMakeLists.txt index eb7bd4b06..229a4ce63 100644 --- a/host/lib/usrp/usrp1/CMakeLists.txt +++ b/host/lib/usrp/usrp1/CMakeLists.txt @@ -17,23 +17,41 @@ #This file will be included by cmake, use absolute paths! -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../firmware/fx2/include) +######################################################################## +# Conditionally configure the USRP1 support +######################################################################## +MESSAGE(STATUS "Configuring usrp1 support...") -LIBUHD_APPEND_SOURCES( - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/clock_ctrl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/clock_ctrl.hpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_ctrl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_ctrl.hpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dboard_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dboard_iface.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dsp_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/io_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/mboard_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_iface.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_iface.hpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_impl.hpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_ctrl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_ctrl.hpp -) +IF(HAVE_USB_SUPPORT) + MESSAGE(STATUS "Has USB support - found") +ELSE(HAVE_USB_SUPPORT) + MESSAGE(STATUS "Has USB support - not found") +ENDIF(HAVE_USB_SUPPORT) + +#TODO check for usrp1 enable/disable option flag + +IF(HAVE_USB_SUPPORT) + MESSAGE(STATUS " Building usrp1 support.") + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../firmware/fx2/include) + + LIBUHD_APPEND_SOURCES( + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/clock_ctrl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/clock_ctrl.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_ctrl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_ctrl.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/codec_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dboard_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dboard_iface.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/dsp_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/io_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/mboard_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_iface.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_iface.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_impl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_impl.hpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_ctrl.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/usrp1/usrp1_ctrl.hpp + ) +ELSE(HAVE_USB_SUPPORT) + MESSAGE(STATUS " Skipping usrp1 support.") +ENDIF(HAVE_USB_SUPPORT) diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp index 866650c2c..d0576a769 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.cpp +++ b/host/lib/usrp/usrp1/codec_ctrl.cpp @@ -25,12 +25,12 @@ #include #include #include +#include #include #include #include #include #include -#include using namespace uhd; @@ -335,9 +335,9 @@ unsigned int usrp1_codec_ctrl_impl::compute_freq_control_word_9862( int v = (int) rint (fabs (target_freq) / master_freq * pow (2.0, 24.0)); *actual_freq = v * master_freq / pow (2.0, 24.0) * sign; - fprintf(stdout, - "compute_freq_control_word_9862: target = %g actual = %g delta = %g v = %8d\n", - target_freq, *actual_freq, *actual_freq - target_freq, v); + std::cout << boost::format( + "compute_freq_control_word_9862: target = %g actual = %g delta = %g v = %8d\n" + ) % target_freq % *actual_freq % (*actual_freq - target_freq) % v; return (unsigned int) v; } diff --git a/host/lib/usrp/usrp1/codec_ctrl.hpp b/host/lib/usrp/usrp1/codec_ctrl.hpp index 51e29345a..0605e3228 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.hpp +++ b/host/lib/usrp/usrp1/codec_ctrl.hpp @@ -19,6 +19,7 @@ #define INCLUDED_USRP1_CODEC_CTRL_HPP #include "usrp1_iface.hpp" +#include #include #include @@ -31,6 +32,9 @@ class usrp1_codec_ctrl : boost::noncopyable{ public: typedef boost::shared_ptr sptr; + static const uhd::gain_range_t tx_pga_gain_range; + static const uhd::gain_range_t rx_pga_gain_range; + /*! * Make a new clock control object. * \param iface the usrp1 iface object @@ -70,6 +74,18 @@ public: */ virtual void write_aux_dac(aux_dac_t which, float volts) = 0; + //! Set the TX PGA gain + virtual void set_tx_pga_gain(float gain) = 0; + + //! Get the TX PGA gain + virtual float get_tx_pga_gain(void) = 0; + + //! Set the RX PGA gain ('A' or 'B') + virtual void set_rx_pga_gain(float gain, char which) = 0; + + //! Get the RX PGA gain ('A' or 'B') + virtual float get_rx_pga_gain(char which) = 0; + virtual bool set_duc_freq(double freq) = 0; }; diff --git a/host/lib/usrp/usrp1/codec_impl.cpp b/host/lib/usrp/usrp1/codec_impl.cpp index 9253c06ba..7bf5631fb 100644 --- a/host/lib/usrp/usrp1/codec_impl.cpp +++ b/host/lib/usrp/usrp1/codec_impl.cpp @@ -16,6 +16,7 @@ // #include "usrp1_impl.hpp" +#include #include #include @@ -44,8 +45,7 @@ static const std::string ad9862_pga_gain_name = "ad9862 pga"; void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()) { @@ -62,17 +62,17 @@ void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val) return; case CODEC_PROP_GAIN_RANGE: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); val = usrp1_codec_ctrl::rx_pga_gain_range; return; case CODEC_PROP_GAIN_I: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); val = _codec_ctrl->get_rx_pga_gain('A'); return; case CODEC_PROP_GAIN_Q: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); val = _codec_ctrl->get_rx_pga_gain('B'); return; @@ -80,20 +80,19 @@ void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val) } } -void usrp1_impl::rx_codec_set(const wax::obj &, const wax::obj &) +void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the set request conditioned on the key switch(key.as()) { case CODEC_PROP_GAIN_I: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); _codec_ctrl->set_rx_pga_gain(val.as(), 'A'); return; case CODEC_PROP_GAIN_Q: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); _codec_ctrl->set_rx_pga_gain(val.as(), 'B'); return; @@ -106,8 +105,7 @@ void usrp1_impl::rx_codec_set(const wax::obj &, const wax::obj &) **********************************************************************/ void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()) { @@ -124,13 +122,13 @@ void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val) return; case CODEC_PROP_GAIN_RANGE: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); val = usrp1_codec_ctrl::tx_pga_gain_range; return; case CODEC_PROP_GAIN_I: //only one gain for I and Q case CODEC_PROP_GAIN_Q: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); val = _codec_ctrl->get_tx_pga_gain(); return; @@ -138,16 +136,15 @@ void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val) } } -void usrp1_impl::tx_codec_set(const wax::obj &, const wax::obj &) +void usrp1_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the set request conditioned on the key switch(key.as()){ case CODEC_PROP_GAIN_I: //only one gain for I and Q case CODEC_PROP_GAIN_Q: - UHD_ASSERT_THROW(name == ad9862_pga_gain_name); + UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); _codec_ctrl->set_tx_pga_gain(val.as()); return; diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index 11ad3fe8a..ef6a1e67b 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -51,9 +51,12 @@ public: /* NOP */ } - std::string get_mboard_name() + special_props_t get_special_props() { - return "usrp1"; + special_props_t props; + props.soft_clock_divider = true; + props.mangle_i2c_addrs = false; //TODO true on side B + return props; } void write_aux_dac(unit_t, aux_dac_t, float); diff --git a/host/lib/usrp/usrp1/dboard_impl.cpp b/host/lib/usrp/usrp1/dboard_impl.cpp index 4f2836ea9..9df87432d 100644 --- a/host/lib/usrp/usrp1/dboard_impl.cpp +++ b/host/lib/usrp/usrp1/dboard_impl.cpp @@ -82,8 +82,7 @@ void usrp1_impl::dboard_init(void) **********************************************************************/ void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -92,7 +91,7 @@ void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_rx_subdev(name); + val = _dboard_manager->get_rx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: @@ -112,7 +111,7 @@ void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_manager->get_rx_subdev(name), + val = make_gain_group(_dboard_manager->get_rx_subdev(key.name), _rx_codec_proxy->get_link()); return; @@ -142,8 +141,7 @@ void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val) **********************************************************************/ void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -152,7 +150,7 @@ void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_tx_subdev(name); + val = _dboard_manager->get_tx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: @@ -172,7 +170,7 @@ void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_manager->get_tx_subdev(name), + val = make_gain_group(_dboard_manager->get_tx_subdev(key.name), _tx_codec_proxy->get_link()); return; diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index ee1ba305b..2514072e0 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -111,9 +111,7 @@ void usrp1_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) **********************************************************************/ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) { - wax::obj key; - std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -126,7 +124,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_RX_DBOARD: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _rx_dboard_proxy->get_link(); return; @@ -135,7 +133,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_TX_DBOARD: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _tx_dboard_proxy->get_link(); return; @@ -144,7 +142,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_RX_DSP: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _rx_ddc_proxy->get_link(); return; @@ -153,7 +151,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_TX_DSP: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _tx_duc_proxy->get_link(); return; diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 4cb286354..1435b981c 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -165,8 +165,7 @@ usrp1_impl::~usrp1_impl(void){ **********************************************************************/ void usrp1_impl::get(const wax::obj &key_, wax::obj &val) { - wax::obj key; std::string name; - boost::tie(key, name) = extract_named_prop(key_); + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -175,7 +174,7 @@ void usrp1_impl::get(const wax::obj &key_, wax::obj &val) return; case DEVICE_PROP_MBOARD: - UHD_ASSERT_THROW(name == ""); + UHD_ASSERT_THROW(key.name == ""); val = _mboard_proxy->get_link(); return; -- cgit v1.2.3 From 5c0d3d30606b25c72c98785d49c13cc27ad49ec1 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 18:49:06 -0700 Subject: usrp1: created daughterboard duality everything that should have two is now stored into a dictionary of slot to type the set and get functions are now bound with a third argument for dboard slot the dboard iface has yet to be completed with the correct registers for a vs b --- host/lib/usrp/usrp1/codec_ctrl.cpp | 16 ++-- host/lib/usrp/usrp1/codec_ctrl.hpp | 3 +- host/lib/usrp/usrp1/codec_impl.cpp | 42 +++++----- host/lib/usrp/usrp1/dboard_iface.cpp | 28 +++++-- host/lib/usrp/usrp1/dboard_impl.cpp | 148 +++++++++++++++++++---------------- host/lib/usrp/usrp1/dsp_impl.cpp | 55 +++++++------ host/lib/usrp/usrp1/mboard_impl.cpp | 21 +++-- host/lib/usrp/usrp1/usrp1_impl.cpp | 13 ++- host/lib/usrp/usrp1/usrp1_impl.hpp | 103 +++++++++++++----------- 9 files changed, 246 insertions(+), 183 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/codec_ctrl.cpp b/host/lib/usrp/usrp1/codec_ctrl.cpp index d0576a769..01617de94 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.cpp +++ b/host/lib/usrp/usrp1/codec_ctrl.cpp @@ -17,8 +17,6 @@ #include "codec_ctrl.hpp" #include "usrp_commands.h" -#include "fpga_regs_standard.h" -#include "usrp_spi_defs.h" #include "ad9862_regs.hpp" #include #include @@ -45,7 +43,7 @@ const gain_range_t usrp1_codec_ctrl::rx_pga_gain_range(0, 20, 1); class usrp1_codec_ctrl_impl : public usrp1_codec_ctrl { public: //structors - usrp1_codec_ctrl_impl(usrp1_iface::sptr iface); + usrp1_codec_ctrl_impl(usrp1_iface::sptr iface, int spi_slave); ~usrp1_codec_ctrl_impl(void); //aux adc and dac control @@ -63,6 +61,7 @@ public: private: usrp1_iface::sptr _iface; + int _spi_slave; ad9862_regs_t _ad9862_regs; aux_adc_t _last_aux_adc_a, _last_aux_adc_b; void send_reg(boost::uint8_t addr); @@ -78,9 +77,10 @@ private: /*********************************************************************** * Codec Control Structors **********************************************************************/ -usrp1_codec_ctrl_impl::usrp1_codec_ctrl_impl(usrp1_iface::sptr iface) +usrp1_codec_ctrl_impl::usrp1_codec_ctrl_impl(usrp1_iface::sptr iface, int spi_slave) { _iface = iface; + _spi_slave = spi_slave; //soft reset _ad9862_regs.soft_reset = 1; @@ -295,7 +295,7 @@ void usrp1_codec_ctrl_impl::send_reg(boost::uint8_t addr) std::cout << "codec control write reg: 0x"; std::cout << std::setw(8) << std::hex << reg << std::endl; } - _iface->transact_spi(SPI_ENABLE_CODEC_A, + _iface->transact_spi(_spi_slave, spi_config_t::EDGE_RISE, reg, 16, false); } @@ -309,7 +309,7 @@ void usrp1_codec_ctrl_impl::recv_reg(boost::uint8_t addr) std::cout << std::setw(8) << std::hex << reg << std::endl; } - boost::uint32_t ret = _iface->transact_spi(SPI_ENABLE_CODEC_A, + boost::uint32_t ret = _iface->transact_spi(_spi_slave, spi_config_t::EDGE_RISE, reg, 16, true); if (codec_debug) { @@ -435,7 +435,7 @@ bool usrp1_codec_ctrl_impl::set_duc_freq(double freq) /*********************************************************************** * Codec Control Make **********************************************************************/ -usrp1_codec_ctrl::sptr usrp1_codec_ctrl::make(usrp1_iface::sptr iface) +usrp1_codec_ctrl::sptr usrp1_codec_ctrl::make(usrp1_iface::sptr iface, int spi_slave) { - return sptr(new usrp1_codec_ctrl_impl(iface)); + return sptr(new usrp1_codec_ctrl_impl(iface, spi_slave)); } diff --git a/host/lib/usrp/usrp1/codec_ctrl.hpp b/host/lib/usrp/usrp1/codec_ctrl.hpp index 0605e3228..6440f97d1 100644 --- a/host/lib/usrp/usrp1/codec_ctrl.hpp +++ b/host/lib/usrp/usrp1/codec_ctrl.hpp @@ -38,9 +38,10 @@ public: /*! * Make a new clock control object. * \param iface the usrp1 iface object + * \param spi_slave which spi device * \return the clock control object */ - static sptr make(usrp1_iface::sptr iface); + static sptr make(usrp1_iface::sptr iface, int spi_slave); //! aux adc identifier constants enum aux_adc_t{ diff --git a/host/lib/usrp/usrp1/codec_impl.cpp b/host/lib/usrp/usrp1/codec_impl.cpp index 7bf5631fb..766a7948f 100644 --- a/host/lib/usrp/usrp1/codec_impl.cpp +++ b/host/lib/usrp/usrp1/codec_impl.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include using namespace uhd; using namespace uhd::usrp; @@ -29,13 +31,15 @@ using namespace uhd::usrp; void usrp1_impl::codec_init(void) { //make proxies - _rx_codec_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::rx_codec_get, this, _1, _2), - boost::bind(&usrp1_impl::rx_codec_set, this, _1, _2)); - - _tx_codec_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::tx_codec_get, this, _1, _2), - boost::bind(&usrp1_impl::tx_codec_set, this, _1, _2)); + BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){ + _rx_codec_proxies[dboard_slot] = wax_obj_proxy::make( + boost::bind(&usrp1_impl::rx_codec_get, this, _1, _2, dboard_slot), + boost::bind(&usrp1_impl::rx_codec_set, this, _1, _2, dboard_slot)); + + _tx_codec_proxies[dboard_slot] = wax_obj_proxy::make( + boost::bind(&usrp1_impl::tx_codec_get, this, _1, _2, dboard_slot), + boost::bind(&usrp1_impl::tx_codec_set, this, _1, _2, dboard_slot)); + } } /*********************************************************************** @@ -43,14 +47,14 @@ void usrp1_impl::codec_init(void) **********************************************************************/ static const std::string ad9862_pga_gain_name = "ad9862 pga"; -void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val) +void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()) { case CODEC_PROP_NAME: - val = std::string("usrp1 adc - ad9862"); + val = str(boost::format("usrp1 adc - ad9862 - slot %c") % dboard_slot); return; case CODEC_PROP_OTHERS: @@ -68,19 +72,19 @@ void usrp1_impl::rx_codec_get(const wax::obj &key_, wax::obj &val) case CODEC_PROP_GAIN_I: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - val = _codec_ctrl->get_rx_pga_gain('A'); + val = _codec_ctrls[dboard_slot]->get_rx_pga_gain('A'); return; case CODEC_PROP_GAIN_Q: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - val = _codec_ctrl->get_rx_pga_gain('B'); + val = _codec_ctrls[dboard_slot]->get_rx_pga_gain('B'); return; default: UHD_THROW_PROP_GET_ERROR(); } } -void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val) +void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); @@ -88,12 +92,12 @@ void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val) switch(key.as()) { case CODEC_PROP_GAIN_I: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - _codec_ctrl->set_rx_pga_gain(val.as(), 'A'); + _codec_ctrls[dboard_slot]->set_rx_pga_gain(val.as(), 'A'); return; case CODEC_PROP_GAIN_Q: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - _codec_ctrl->set_rx_pga_gain(val.as(), 'B'); + _codec_ctrls[dboard_slot]->set_rx_pga_gain(val.as(), 'B'); return; default: UHD_THROW_PROP_SET_ERROR(); @@ -103,14 +107,14 @@ void usrp1_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val) /*********************************************************************** * TX Codec Properties **********************************************************************/ -void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val) +void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()) { case CODEC_PROP_NAME: - val = std::string("usrp1 dac - ad9862"); + val = str(boost::format("usrp1 dac - ad9862 - slot %c") % dboard_slot); return; case CODEC_PROP_OTHERS: @@ -129,14 +133,14 @@ void usrp1_impl::tx_codec_get(const wax::obj &key_, wax::obj &val) case CODEC_PROP_GAIN_I: //only one gain for I and Q case CODEC_PROP_GAIN_Q: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - val = _codec_ctrl->get_tx_pga_gain(); + val = _codec_ctrls[dboard_slot]->get_tx_pga_gain(); return; default: UHD_THROW_PROP_GET_ERROR(); } } -void usrp1_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val) +void usrp1_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); @@ -145,7 +149,7 @@ void usrp1_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val) case CODEC_PROP_GAIN_I: //only one gain for I and Q case CODEC_PROP_GAIN_Q: UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); - _codec_ctrl->set_tx_pga_gain(val.as()); + _codec_ctrls[dboard_slot]->set_tx_pga_gain(val.as()); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index ef6a1e67b..82ef9e65b 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -16,6 +16,7 @@ // #include "usrp1_iface.hpp" +#include "usrp1_impl.hpp" #include "fpga_regs_common.h" #include "usrp_spi_defs.h" #include "clock_ctrl.hpp" @@ -30,16 +31,27 @@ using namespace uhd; using namespace uhd::usrp; using namespace boost::assign; +/*********************************************************************** + * TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + * TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + * TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + * TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + * + * check the _dboard_slot and handle conditionally... + **********************************************************************/ + class usrp1_dboard_iface : public dboard_iface { public: usrp1_dboard_iface(usrp1_iface::sptr iface, usrp1_clock_ctrl::sptr clock, - usrp1_codec_ctrl::sptr codec) - { + usrp1_codec_ctrl::sptr codec, + usrp1_impl::dboard_slot_t dboard_slot + ){ _iface = iface; _clock = clock; _codec = codec; + _dboard_slot = dboard_slot; //init the clock rate shadows this->set_clock_rate(UNIT_RX, _clock->get_master_clock_freq()); @@ -55,7 +67,7 @@ public: { special_props_t props; props.soft_clock_divider = true; - props.mangle_i2c_addrs = false; //TODO true on side B + props.mangle_i2c_addrs = (_dboard_slot == usrp1_impl::DBOARD_SLOT_B); return props; } @@ -91,16 +103,18 @@ private: usrp1_clock_ctrl::sptr _clock; usrp1_codec_ctrl::sptr _codec; uhd::dict _clock_rates; + usrp1_impl::dboard_slot_t _dboard_slot; }; /*********************************************************************** * Make Function **********************************************************************/ -dboard_iface::sptr make_usrp1_dboard_iface(usrp1_iface::sptr iface, +dboard_iface::sptr usrp1_impl::make_dboard_iface(usrp1_iface::sptr iface, usrp1_clock_ctrl::sptr clock, - usrp1_codec_ctrl::sptr codec) -{ - return dboard_iface::sptr(new usrp1_dboard_iface(iface, clock, codec)); + usrp1_codec_ctrl::sptr codec, + usrp1_impl::dboard_slot_t dboard_slot +){ + return dboard_iface::sptr(new usrp1_dboard_iface(iface, clock, codec, dboard_slot)); } /*********************************************************************** diff --git a/host/lib/usrp/usrp1/dboard_impl.cpp b/host/lib/usrp/usrp1/dboard_impl.cpp index 9df87432d..ba826d2f5 100644 --- a/host/lib/usrp/usrp1/dboard_impl.cpp +++ b/host/lib/usrp/usrp1/dboard_impl.cpp @@ -23,96 +23,107 @@ #include #include #include +#include +#include #include using namespace uhd; using namespace uhd::usrp; /*********************************************************************** - * Dboard Initialization + * Helper Functions **********************************************************************/ -void usrp1_impl::dboard_init(void) -{ - _rx_db_eeprom = dboard_eeprom_t( - _iface->read_eeprom(I2C_ADDR_RX_A, 0, dboard_eeprom_t::num_bytes())); - - _tx_db_eeprom = dboard_eeprom_t( - _iface->read_eeprom(I2C_ADDR_TX_A, 0, dboard_eeprom_t::num_bytes())); - - - //create a new dboard interface and manager - _dboard_iface = make_usrp1_dboard_iface(_iface, _clock_ctrl, _codec_ctrl); - - _dboard_manager = dboard_manager::make(_rx_db_eeprom.id, - _tx_db_eeprom.id, - _dboard_iface); - - //setup the dboard proxies - _rx_dboard_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::rx_dboard_get, this, _1, _2), - boost::bind(&usrp1_impl::rx_dboard_set, this, _1, _2)); - - _tx_dboard_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::tx_dboard_get, this, _1, _2), - boost::bind(&usrp1_impl::tx_dboard_set, this, _1, _2)); +static boost::uint8_t get_rx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){ + switch(dboard_slot){ + case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_RX_A; + case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_RX_B; + default: UHD_THROW_INVALID_CODE_PATH(); + } +} +static boost::uint8_t get_tx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){ + switch(dboard_slot){ + case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_TX_A; + case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_TX_B; + default: UHD_THROW_INVALID_CODE_PATH(); + } } + /*********************************************************************** - * Helper functions + * Dboard Initialization **********************************************************************/ -//static int slot_to_i2c_addr (int slot) -//{ -// switch (slot) { -// case SLOT_TX_A: -// return I2C_ADDR_TX_A; -// case SLOT_RX_A: -// return I2C_ADDR_RX_A; -// case SLOT_TX_B: -// return I2C_ADDR_TX_B; -// case SLOT_RX_B: -// return I2C_ADDR_RX_B; -// default: -// return -1; -// } -//} +void usrp1_impl::dboard_init(void) +{ + BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){ + + //read the tx and rx dboard eeproms + _rx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( + get_rx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes() + )); + + _tx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( + get_tx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes() + )); + + //create a new dboard interface and manager + _dboard_ifaces[dboard_slot] = make_dboard_iface( + _iface, _clock_ctrl, _codec_ctrls[dboard_slot], dboard_slot + ); + + _dboard_managers[dboard_slot] = dboard_manager::make( + _rx_db_eeproms[dboard_slot].id, + _tx_db_eeproms[dboard_slot].id, + _dboard_ifaces[dboard_slot] + ); + + //setup the dboard proxies + _rx_dboard_proxies[dboard_slot] = wax_obj_proxy::make( + boost::bind(&usrp1_impl::rx_dboard_get, this, _1, _2, dboard_slot), + boost::bind(&usrp1_impl::rx_dboard_set, this, _1, _2, dboard_slot)); + + _tx_dboard_proxies[dboard_slot] = wax_obj_proxy::make( + boost::bind(&usrp1_impl::tx_dboard_get, this, _1, _2, dboard_slot), + boost::bind(&usrp1_impl::tx_dboard_set, this, _1, _2, dboard_slot)); + } +} /*********************************************************************** * RX Dboard Get **********************************************************************/ -void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) +void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string("usrp1 dboard (rx unit)"); + val = str(boost::format("usrp1 dboard (rx unit) - %c") % dboard_slot); return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_rx_subdev(key.name); + val = _dboard_managers[dboard_slot]->get_rx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: - val = _dboard_manager->get_rx_subdev_names(); + val = _dboard_managers[dboard_slot]->get_rx_subdev_names(); return; case DBOARD_PROP_DBOARD_ID: - val = _rx_db_eeprom.id; + val = _rx_db_eeproms[dboard_slot].id; return; case DBOARD_PROP_DBOARD_IFACE: - val = _dboard_iface; + val = _dboard_ifaces[dboard_slot]; return; case DBOARD_PROP_CODEC: - val = _rx_codec_proxy->get_link(); + val = _rx_codec_proxies[dboard_slot]->get_link(); return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_manager->get_rx_subdev(key.name), - _rx_codec_proxy->get_link()); + val = make_gain_group(_dboard_managers[dboard_slot]->get_rx_subdev(key.name), + _rx_codec_proxies[dboard_slot]->get_link()); return; default: UHD_THROW_PROP_GET_ERROR(); @@ -122,13 +133,15 @@ void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) /*********************************************************************** * RX Dboard Set **********************************************************************/ -void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val) +void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot) { switch(key.as()) { case DBOARD_PROP_DBOARD_ID: - _rx_db_eeprom.id = val.as(); - _iface->write_eeprom(I2C_ADDR_RX_A, 0, - _rx_db_eeprom.get_eeprom_bytes()); + _rx_db_eeproms[dboard_slot].id = val.as(); + _iface->write_eeprom( + get_rx_ee_addr(dboard_slot), 0, + _rx_db_eeproms[dboard_slot].get_eeprom_bytes() + ); return; default: @@ -139,39 +152,39 @@ void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val) /*********************************************************************** * TX Dboard Get **********************************************************************/ -void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) +void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) { named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string("usrp1 dboard (tx unit)"); + val = str(boost::format("usrp1 dboard (tx unit) - %c") % dboard_slot); return; case DBOARD_PROP_SUBDEV: - val = _dboard_manager->get_tx_subdev(key.name); + val = _dboard_managers[dboard_slot]->get_tx_subdev(key.name); return; case DBOARD_PROP_SUBDEV_NAMES: - val = _dboard_manager->get_tx_subdev_names(); + val = _dboard_managers[dboard_slot]->get_tx_subdev_names(); return; case DBOARD_PROP_DBOARD_ID: - val = _tx_db_eeprom.id; + val = _tx_db_eeproms[dboard_slot].id; return; case DBOARD_PROP_DBOARD_IFACE: - val = _dboard_iface; + val = _dboard_ifaces[dboard_slot]; return; case DBOARD_PROP_CODEC: - val = _tx_codec_proxy->get_link(); + val = _tx_codec_proxies[dboard_slot]->get_link(); return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_manager->get_tx_subdev(key.name), - _tx_codec_proxy->get_link()); + val = make_gain_group(_dboard_managers[dboard_slot]->get_tx_subdev(key.name), + _tx_codec_proxies[dboard_slot]->get_link()); return; default: UHD_THROW_PROP_GET_ERROR(); @@ -181,12 +194,15 @@ void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) /*********************************************************************** * TX Dboard Set **********************************************************************/ -void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val) +void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot) { switch(key.as()) { case DBOARD_PROP_DBOARD_ID: - _tx_db_eeprom.id = val.as(); - _iface->write_eeprom(I2C_ADDR_TX_A, 0, _tx_db_eeprom.get_eeprom_bytes()); + _tx_db_eeproms[dboard_slot].id = val.as(); + _iface->write_eeprom( + get_tx_ee_addr(dboard_slot), 0, + _tx_db_eeproms[dboard_slot].get_eeprom_bytes() + ); return; default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp index e9900131f..1a8993a01 100644 --- a/host/lib/usrp/usrp1/dsp_impl.cpp +++ b/host/lib/usrp/usrp1/dsp_impl.cpp @@ -29,19 +29,19 @@ using namespace uhd::usrp; /*********************************************************************** * RX DDC Initialization **********************************************************************/ -void usrp1_impl::rx_ddc_init(void) +void usrp1_impl::rx_dsp_init(void) { - _rx_ddc_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::rx_ddc_get, this, _1, _2), - boost::bind(&usrp1_impl::rx_ddc_set, this, _1, _2)); + _rx_dsp_proxy = wax_obj_proxy::make( + boost::bind(&usrp1_impl::rx_dsp_get, this, _1, _2), + boost::bind(&usrp1_impl::rx_dsp_set, this, _1, _2)); - rx_ddc_set(DSP_PROP_HOST_RATE, double(64e6/10)); + rx_dsp_set(DSP_PROP_HOST_RATE, double(64e6/10)); //FIXME magic number } /*********************************************************************** * RX DDC Get **********************************************************************/ -void usrp1_impl::rx_ddc_get(const wax::obj &key, wax::obj &val) +void usrp1_impl::rx_dsp_get(const wax::obj &key, wax::obj &val) { switch(key.as()){ case DSP_PROP_NAME: @@ -53,7 +53,7 @@ void usrp1_impl::rx_ddc_get(const wax::obj &key, wax::obj &val) return; case DSP_PROP_FREQ_SHIFT: - val = _ddc_freq; + val = _rx_dsp_freq; return; case DSP_PROP_CODEC_RATE: @@ -61,7 +61,7 @@ void usrp1_impl::rx_ddc_get(const wax::obj &key, wax::obj &val) return; case DSP_PROP_HOST_RATE: - val = _clock_ctrl->get_master_clock_freq()/_ddc_decim; + val = _clock_ctrl->get_master_clock_freq()/_rx_dsp_decim; return; default: UHD_THROW_PROP_GET_ERROR(); @@ -90,13 +90,13 @@ unsigned int compute_freq_word(double master, double target) return (unsigned int) v; } -void usrp1_impl::rx_ddc_set(const wax::obj &key, const wax::obj &val) +void usrp1_impl::rx_dsp_set(const wax::obj &key, const wax::obj &val) { switch(key.as()) { case DSP_PROP_FREQ_SHIFT: { double new_freq = val.as(); - _iface->poke32(FR_RX_FREQ_0, compute_freq_word(64e6, new_freq)); - _ddc_freq = new_freq; + _iface->poke32(FR_RX_FREQ_0, compute_freq_word(64e6, new_freq)); //FIXME magic rate + _tx_dsp_freq = new_freq; return; } case DSP_PROP_HOST_RATE: { @@ -110,8 +110,8 @@ void usrp1_impl::rx_ddc_set(const wax::obj &key, const wax::obj &val) return; } - _ddc_decim = rate; - _iface->poke32(FR_DECIM_RATE, _ddc_decim/2 - 1); + _rx_dsp_decim = rate; + _iface->poke32(FR_DECIM_RATE, _rx_dsp_decim/2 - 1); } return; @@ -123,20 +123,20 @@ void usrp1_impl::rx_ddc_set(const wax::obj &key, const wax::obj &val) /*********************************************************************** * TX DUC Initialization **********************************************************************/ -void usrp1_impl::tx_duc_init(void) +void usrp1_impl::tx_dsp_init(void) { - _tx_duc_proxy = wax_obj_proxy::make( - boost::bind(&usrp1_impl::tx_duc_get, this, _1, _2), - boost::bind(&usrp1_impl::tx_duc_set, this, _1, _2)); + _tx_dsp_proxy = wax_obj_proxy::make( + boost::bind(&usrp1_impl::tx_dsp_get, this, _1, _2), + boost::bind(&usrp1_impl::tx_dsp_set, this, _1, _2)); //initial config and update - tx_duc_set(DSP_PROP_HOST_RATE, double(64e6/10)); + tx_dsp_set(DSP_PROP_HOST_RATE, double(64e6/10)); //FIXME magic number } /*********************************************************************** * TX DUC Get **********************************************************************/ -void usrp1_impl::tx_duc_get(const wax::obj &key, wax::obj &val) +void usrp1_impl::tx_dsp_get(const wax::obj &key, wax::obj &val) { switch(key.as()) { case DSP_PROP_NAME: @@ -148,7 +148,7 @@ void usrp1_impl::tx_duc_get(const wax::obj &key, wax::obj &val) return; case DSP_PROP_FREQ_SHIFT: - val = _duc_freq; + val = _tx_dsp_freq; return; case DSP_PROP_CODEC_RATE: @@ -156,7 +156,7 @@ void usrp1_impl::tx_duc_get(const wax::obj &key, wax::obj &val) return; case DSP_PROP_HOST_RATE: - val = _clock_ctrl->get_master_clock_freq() * 2 / _duc_interp; + val = _clock_ctrl->get_master_clock_freq() * 2 / _tx_dsp_interp; return; default: UHD_THROW_PROP_GET_ERROR(); @@ -167,16 +167,19 @@ void usrp1_impl::tx_duc_get(const wax::obj &key, wax::obj &val) /*********************************************************************** * TX DUC Set **********************************************************************/ -void usrp1_impl::tx_duc_set(const wax::obj &key, const wax::obj &val) +void usrp1_impl::tx_dsp_set(const wax::obj &key, const wax::obj &val) { switch(key.as()) { case DSP_PROP_FREQ_SHIFT: { double new_freq = val.as(); - _codec_ctrl->set_duc_freq(new_freq); - _duc_freq = new_freq; + _codec_ctrls[DBOARD_SLOT_A]->set_duc_freq(new_freq); + _tx_dsp_freq = new_freq; return; } + + //TODO freq prop secondary: DBOARD_SLOT_B codec... + case DSP_PROP_HOST_RATE: { unsigned int rate = _clock_ctrl->get_master_clock_freq() * 2 / val.as(); @@ -187,8 +190,8 @@ void usrp1_impl::tx_duc_set(const wax::obj &key, const wax::obj &val) return; } - _duc_interp = rate; - _iface->poke32(FR_INTERP_RATE, _duc_interp / 4 - 1); + _tx_dsp_interp = rate; + _iface->poke32(FR_INTERP_RATE, _tx_dsp_interp / 4 - 1); return; } default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 2514072e0..e0a7fefb1 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -19,6 +19,7 @@ #include "usrp_commands.h" #include #include +#include #include #include @@ -109,6 +110,8 @@ void usrp1_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) /*********************************************************************** * Mboard Get **********************************************************************/ +static prop_names_t dboard_names = boost::assign::list_of("A")("B"); + void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) { named_prop_t key = named_prop_t::extract(key_); @@ -124,26 +127,28 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) return; case MBOARD_PROP_RX_DBOARD: - UHD_ASSERT_THROW(key.name == ""); - val = _rx_dboard_proxy->get_link(); + uhd::assert_has(dboard_names, key.name, "dboard name"); + if (key.name == "A") val = _rx_dboard_proxies[DBOARD_SLOT_A]->get_link(); + if (key.name == "B") val = _rx_dboard_proxies[DBOARD_SLOT_B]->get_link(); return; case MBOARD_PROP_RX_DBOARD_NAMES: - val = prop_names_t(1, ""); //vector of size 1 with empty string + val = dboard_names; return; case MBOARD_PROP_TX_DBOARD: - UHD_ASSERT_THROW(key.name == ""); - val = _tx_dboard_proxy->get_link(); + uhd::assert_has(dboard_names, key.name, "dboard name"); + if (key.name == "A") val = _tx_dboard_proxies[DBOARD_SLOT_A]->get_link(); + if (key.name == "B") val = _tx_dboard_proxies[DBOARD_SLOT_B]->get_link(); return; case MBOARD_PROP_TX_DBOARD_NAMES: - val = prop_names_t(1, ""); //vector of size 1 with empty string + val = dboard_names; return; case MBOARD_PROP_RX_DSP: UHD_ASSERT_THROW(key.name == ""); - val = _rx_ddc_proxy->get_link(); + val = _rx_dsp_proxy->get_link(); return; case MBOARD_PROP_RX_DSP_NAMES: @@ -152,7 +157,7 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) case MBOARD_PROP_TX_DSP: UHD_ASSERT_THROW(key.name == ""); - val = _tx_duc_proxy->get_link(); + val = _tx_dsp_proxy->get_link(); return; case MBOARD_PROP_TX_DSP_NAMES: diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 1435b981c..ece5f1dea 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -18,11 +18,13 @@ #include "usrp1_impl.hpp" #include "usrp1_ctrl.hpp" #include "fpga_regs_standard.h" +#include "usrp_spi_defs.h" #include #include #include #include #include +#include #include #include @@ -30,6 +32,10 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::transport; +const std::vector usrp1_impl::_dboard_slots = boost::assign::list_of + (usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B) +; + /*********************************************************************** * Discovery **********************************************************************/ @@ -132,7 +138,8 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, _clock_ctrl = usrp1_clock_ctrl::make(_iface); //create codec interface - _codec_ctrl = usrp1_codec_ctrl::make(_iface); + _codec_ctrls[DBOARD_SLOT_A] = usrp1_codec_ctrl::make(_iface, SPI_ENABLE_CODEC_A); + _codec_ctrls[DBOARD_SLOT_B] = usrp1_codec_ctrl::make(_iface, SPI_ENABLE_CODEC_B); //initialize the codecs codec_init(); @@ -144,10 +151,10 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, dboard_init(); //initialize the dsps - rx_ddc_init(); + rx_dsp_init(); //initialize the dsps - tx_duc_init(); + tx_dsp_init(); //initialize the send/recv io_init(); diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index 5abc37c7f..84ec26827 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -21,6 +21,7 @@ #include "codec_ctrl.hpp" #include #include +#include #include #include #include @@ -33,17 +34,6 @@ static const double MASTER_CLOCK_RATE = 64e6; //TODO get from clock control -/*! - * Make a usrp1 dboard interface. - * \param iface the usrp1 interface object - * \param clock the clock control interface - * \param codec the codec control interface - * \return a sptr to a new dboard interface - */ -uhd::usrp::dboard_iface::sptr make_usrp1_dboard_iface(usrp1_iface::sptr iface, - usrp1_clock_ctrl::sptr clock, - usrp1_codec_ctrl::sptr codec); - /*! * Simple wax obj proxy class: * Provides a wax obj interface for a set and a get function. @@ -75,6 +65,14 @@ private: */ class usrp1_impl : public uhd::device { public: + //! used everywhere to differentiate slots/sides... + enum dboard_slot_t{ + DBOARD_SLOT_A = 'A', + DBOARD_SLOT_B = 'B' + }; + //and a way to enumerate through a list of the above... + static const std::vector _dboard_slots; + //structors usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, usrp_ctrl::sptr ctrl_transport); @@ -97,9 +95,27 @@ public: size_t get_max_send_samps_per_packet(void) const { return 0; } size_t get_max_recv_samps_per_packet(void) const { return 0; } - bool recv_async_msg(uhd::async_metadata_t &, size_t) { return true; } + bool recv_async_msg(uhd::async_metadata_t &, size_t) { + //TODO sleep the number of ms supplied (dont want to hog CPU) + return false; + } private: + /*! + * Make a usrp1 dboard interface. + * \param iface the usrp1 interface object + * \param clock the clock control interface + * \param codec the codec control interface + * \param dboard_slot the slot identifier + * \return a sptr to a new dboard interface + */ + static uhd::usrp::dboard_iface::sptr make_dboard_iface( + usrp1_iface::sptr iface, + usrp1_clock_ctrl::sptr clock, + usrp1_codec_ctrl::sptr codec, + dboard_slot_t dboard_slot + ); + //interface to ioctls and file descriptor usrp1_iface::sptr _iface; @@ -120,16 +136,15 @@ private: usrp1_clock_ctrl::sptr _clock_ctrl; //ad9862 codec control interface - usrp1_codec_ctrl::sptr _codec_ctrl; + uhd::dict _codec_ctrls; //codec properties interfaces void codec_init(void); - void rx_codec_get(const wax::obj &, wax::obj &); - void rx_codec_set(const wax::obj &, const wax::obj &); - void tx_codec_get(const wax::obj &, wax::obj &); - void tx_codec_set(const wax::obj &, const wax::obj &); - wax_obj_proxy::sptr _rx_codec_proxy; - wax_obj_proxy::sptr _tx_codec_proxy; + void rx_codec_get(const wax::obj &, wax::obj &, dboard_slot_t); + void rx_codec_set(const wax::obj &, const wax::obj &, dboard_slot_t); + void tx_codec_get(const wax::obj &, wax::obj &, dboard_slot_t); + void tx_codec_set(const wax::obj &, const wax::obj &, dboard_slot_t); + uhd::dict _rx_codec_proxies, _tx_codec_proxies; //device functions and settings void get(const wax::obj &, wax::obj &); @@ -143,36 +158,34 @@ private: //xx dboard functions and settings void dboard_init(void); - uhd::usrp::dboard_manager::sptr _dboard_manager; - uhd::usrp::dboard_iface::sptr _dboard_iface; + uhd::dict _dboard_managers; + uhd::dict _dboard_ifaces; //rx dboard functions and settings - uhd::usrp::dboard_eeprom_t _rx_db_eeprom; - void rx_dboard_get(const wax::obj &, wax::obj &); - void rx_dboard_set(const wax::obj &, const wax::obj &); - uhd::prop_names_t _rx_subdevs_in_use; - wax_obj_proxy::sptr _rx_dboard_proxy; + uhd::dict _rx_db_eeproms; + void rx_dboard_get(const wax::obj &, wax::obj &, dboard_slot_t); + void rx_dboard_set(const wax::obj &, const wax::obj &, dboard_slot_t); + uhd::dict _rx_dboard_proxies; //tx dboard functions and settings - uhd::usrp::dboard_eeprom_t _tx_db_eeprom; - void tx_dboard_get(const wax::obj &, wax::obj &); - void tx_dboard_set(const wax::obj &, const wax::obj &); - uhd::prop_names_t _tx_subdevs_in_use; - wax_obj_proxy::sptr _tx_dboard_proxy; - - //rx ddc functions and settings - void rx_ddc_init(void); - void rx_ddc_get(const wax::obj &, wax::obj &); - void rx_ddc_set(const wax::obj &, const wax::obj &); - double _ddc_freq; size_t _ddc_decim; - wax_obj_proxy::sptr _rx_ddc_proxy; - - //tx duc functions and settings - void tx_duc_init(void); - void tx_duc_get(const wax::obj &, wax::obj &); - void tx_duc_set(const wax::obj &, const wax::obj &); - double _duc_freq; size_t _duc_interp; - wax_obj_proxy::sptr _tx_duc_proxy; + uhd::dict _tx_db_eeproms; + void tx_dboard_get(const wax::obj &, wax::obj &, dboard_slot_t); + void tx_dboard_set(const wax::obj &, const wax::obj &, dboard_slot_t); + uhd::dict _tx_dboard_proxies; + + //rx dsp functions and settings + void rx_dsp_init(void); + void rx_dsp_get(const wax::obj &, wax::obj &); + void rx_dsp_set(const wax::obj &, const wax::obj &); + double _rx_dsp_freq; size_t _rx_dsp_decim; + wax_obj_proxy::sptr _rx_dsp_proxy; + + //tx dsp functions and settings + void tx_dsp_init(void); + void tx_dsp_get(const wax::obj &, wax::obj &); + void tx_dsp_set(const wax::obj &, const wax::obj &); + double _tx_dsp_freq; size_t _tx_dsp_interp; + wax_obj_proxy::sptr _tx_dsp_proxy; //transports uhd::transport::usb_zero_copy::sptr _data_transport; -- cgit v1.2.3 From e7d4233a94571a2479b21bc081567214c38cc155 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 15 Aug 2010 19:12:41 -0700 Subject: usrp1: add skeleton code for setting subdev spec --- host/lib/usrp/usrp1/dboard_iface.cpp | 3 ++- host/lib/usrp/usrp1/mboard_impl.cpp | 33 +++++++++++++++++++++++++++++++-- host/lib/usrp/usrp1/usrp1_impl.hpp | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/dboard_iface.cpp b/host/lib/usrp/usrp1/dboard_iface.cpp index 82ef9e65b..142907e57 100644 --- a/host/lib/usrp/usrp1/dboard_iface.cpp +++ b/host/lib/usrp/usrp1/dboard_iface.cpp @@ -112,7 +112,7 @@ private: dboard_iface::sptr usrp1_impl::make_dboard_iface(usrp1_iface::sptr iface, usrp1_clock_ctrl::sptr clock, usrp1_codec_ctrl::sptr codec, - usrp1_impl::dboard_slot_t dboard_slot + dboard_slot_t dboard_slot ){ return dboard_iface::sptr(new usrp1_dboard_iface(iface, clock, codec, dboard_slot)); } @@ -221,6 +221,7 @@ void usrp1_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value) { if ((atr == ATR_REG_IDLE) || (atr == ATR_REG_FULL_DUPLEX)) { + //TODO probably just ignore these two atr settings because all dboards will try to set them std::cerr << "error: set_atr_reg(): unsupported state" << std::endl; return; } diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index e0a7fefb1..5e0285dfd 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -17,6 +17,7 @@ #include "usrp1_impl.hpp" #include "usrp_commands.h" +#include "../misc_utils.hpp" #include #include #include @@ -168,6 +169,14 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) val = _clock_config; return; + case MBOARD_PROP_RX_SUBDEV_SPEC: + val = _rx_subdev_spec; + return; + + case MBOARD_PROP_TX_SUBDEV_SPEC: + val = _tx_subdev_spec; + return; + default: UHD_THROW_PROP_GET_ERROR(); } } @@ -184,8 +193,28 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) issue_stream_cmd(val.as()); return; - case MBOARD_PROP_TIME_NOW: - case MBOARD_PROP_TIME_NEXT_PPS: + case MBOARD_PROP_RX_SUBDEV_SPEC: + _rx_subdev_spec = val.as(); + verify_rx_subdev_spec(_rx_subdev_spec, this->get_link()); + //sanity check + UHD_ASSERT_THROW(_rx_subdev_spec.size() <= 2); + //set the mux and set the number of rx channels + //-------------------------------------------------- + // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + //-------------------------------------------------- + return; + + case MBOARD_PROP_TX_SUBDEV_SPEC: + _tx_subdev_spec = val.as(); + verify_tx_subdev_spec(_tx_subdev_spec, this->get_link()); + //sanity check + UHD_ASSERT_THROW(_tx_subdev_spec.size() <= 2); + //set the mux and set the number of tx channels + //-------------------------------------------------- + // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + //-------------------------------------------------- + return; + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index 84ec26827..5166f989f 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ private: //configuration shadows uhd::clock_config_t _clock_config; + uhd::usrp::subdev_spec_t _rx_subdev_spec, _tx_subdev_spec; //clock control usrp1_clock_ctrl::sptr _clock_ctrl; -- cgit v1.2.3 From 564bfee0389d0274e7cd128d61dcbe50ca6a6cdd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 16 Aug 2010 00:09:47 -0700 Subject: usrp1: compiling with the latest next --- host/lib/usrp/usrp1/dboard_impl.cpp | 18 ++++++++++++------ host/lib/usrp/usrp1/dsp_impl.cpp | 12 ++++++------ host/lib/usrp/usrp1/mboard_impl.cpp | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/dboard_impl.cpp b/host/lib/usrp/usrp1/dboard_impl.cpp index ba826d2f5..c8d9c55dd 100644 --- a/host/lib/usrp/usrp1/dboard_impl.cpp +++ b/host/lib/usrp/usrp1/dboard_impl.cpp @@ -17,8 +17,8 @@ #include "usrp1_impl.hpp" #include "usrp_i2c_addr.h" -#include "../dsp_utils.hpp" -#include "../misc_utils.hpp" +#include +#include #include #include #include @@ -122,8 +122,11 @@ void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_ return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_managers[dboard_slot]->get_rx_subdev(key.name), - _rx_codec_proxies[dboard_slot]->get_link()); + val = make_gain_group( + _dboard_managers[dboard_slot]->get_rx_subdev(key.name), + _rx_codec_proxies[dboard_slot]->get_link(), + GAIN_GROUP_POLICY_RX + ); return; default: UHD_THROW_PROP_GET_ERROR(); @@ -183,8 +186,11 @@ void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_ return; case DBOARD_PROP_GAIN_GROUP: - val = make_gain_group(_dboard_managers[dboard_slot]->get_tx_subdev(key.name), - _tx_codec_proxies[dboard_slot]->get_link()); + val = make_gain_group( + _dboard_managers[dboard_slot]->get_tx_subdev(key.name), + _tx_codec_proxies[dboard_slot]->get_link(), + GAIN_GROUP_POLICY_TX + ); return; default: UHD_THROW_PROP_GET_ERROR(); diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp index 1a8993a01..260c01ea8 100644 --- a/host/lib/usrp/usrp1/dsp_impl.cpp +++ b/host/lib/usrp/usrp1/dsp_impl.cpp @@ -17,11 +17,12 @@ #include "usrp1_impl.hpp" #include "fpga_regs_standard.h" -#include "../dsp_utils.hpp" +#include #include #include +#include #include -#include +#include using namespace uhd; using namespace uhd::usrp; @@ -82,10 +83,9 @@ unsigned int compute_freq_word(double master, double target) double actual_freq = v * master / pow(2.0, 32.0); - if (0) - fprintf (stderr, - "compute_freq_control_word_fpga: target = %g actual = %g delta = %g\n", - target, actual_freq, actual_freq - target); + if (0) std::cerr << boost::format( + "compute_freq_control_word_fpga: target = %g actual = %g delta = %g\n" + ) % target % actual_freq % (actual_freq - target); return (unsigned int) v; } diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 5e0285dfd..ede9b2681 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -17,7 +17,7 @@ #include "usrp1_impl.hpp" #include "usrp_commands.h" -#include "../misc_utils.hpp" +#include #include #include #include -- cgit v1.2.3 From acc508a1ee21cf8c6f48f846dad53477c64c10d9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 16 Aug 2010 18:16:49 -0700 Subject: usrp1: rx and tx mux calculation --- host/lib/usrp/usrp1/mboard_impl.cpp | 113 +++++++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 7 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index ede9b2681..c3343f1f8 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -17,16 +17,119 @@ #include "usrp1_impl.hpp" #include "usrp_commands.h" +#include "fpga_regs_standard.h" #include -#include #include +#include +#include +#include +#include #include +#include #include #include using namespace uhd; using namespace uhd::usrp; +/*********************************************************************** + * Helper Functions + **********************************************************************/ +static boost::uint32_t calc_rx_mux( + const subdev_spec_t &subdev_spec, wax::obj mboard +){ + //create look-up-table for mapping dboard name and connection type to ADC flags + static const int ADC0 = 0, ADC1 = 1, ADC2 = 2, ADC3 = 3; + static const uhd::dict > name_to_conn_to_flag = boost::assign::map_list_of + ("A", boost::assign::map_list_of + (SUBDEV_CONN_COMPLEX_IQ, (ADC0 << 0) | (ADC1 << 2)) //I and Q + (SUBDEV_CONN_COMPLEX_QI, (ADC1 << 0) | (ADC0 << 2)) //I and Q + (SUBDEV_CONN_REAL_I, (ADC0 << 0) | (ADC0 << 2)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_REAL_Q, (ADC1 << 0) | (ADC1 << 2)) //I and Q (Q identical but ignored Z=1) + ) + ("B", boost::assign::map_list_of + (SUBDEV_CONN_COMPLEX_IQ, (ADC2 << 0) | (ADC3 << 2)) //I and Q + (SUBDEV_CONN_COMPLEX_QI, (ADC3 << 0) | (ADC2 << 2)) //I and Q + (SUBDEV_CONN_REAL_I, (ADC2 << 0) | (ADC2 << 2)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_REAL_Q, (ADC3 << 0) | (ADC3 << 2)) //I and Q (Q identical but ignored Z=1) + ) + ; + + //extract the number of channels + size_t nchan = subdev_spec.size(); + + //calculate the channel flags + int channel_flags = 0; + size_t num_reals = 0, num_quads = 0; + BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ + wax::obj dboard = mboard[named_prop_t(MBOARD_PROP_RX_DBOARD, pair.db_name)]; + wax::obj subdev = dboard[named_prop_t(DBOARD_PROP_SUBDEV, pair.sd_name)]; + subdev_conn_t conn = subdev[SUBDEV_PROP_CONNECTION].as(); + switch(conn){ + case SUBDEV_CONN_COMPLEX_IQ: + case SUBDEV_CONN_COMPLEX_QI: num_quads++; break; + case SUBDEV_CONN_REAL_I: + case SUBDEV_CONN_REAL_Q: num_reals++; break; + } + channel_flags = (channel_flags << 4) | name_to_conn_to_flag[pair.db_name][conn]; + } + + //calculate Z: + // for all real sources: Z = 1 + // for all quadrature sources: Z = 0 + // for mixed sources: warning + Z = 0 + int Z = (num_quads > 0)? 0 : 1; + if (num_quads != 0 and num_reals != 0) uhd::print_warning( + "Mixing real and quadrature rx subdevices is not supported.\n" + "The Q input to the real source(s) will be non-zero.\n" + ); + + //calculate the rx mux value + return ((channel_flags & 0xffff) << 4) | ((Z & 0x1) << 3) | ((nchan & 0x7) << 0); +} + +static boost::uint32_t calc_tx_mux( + const subdev_spec_t &subdev_spec, wax::obj mboard +){ + //create look-up-table for mapping channel number and connection type to flags + static const int ENB = 1 << 3, CHAN_I0 = 0, CHAN_Q0 = 1, CHAN_I1 = 2, CHAN_Q1 = 3; + static const uhd::dict > chan_to_conn_to_flag = boost::assign::map_list_of + (0, boost::assign::map_list_of + (SUBDEV_CONN_COMPLEX_IQ, ((CHAN_I0 | ENB) << 0) | ((CHAN_Q0 | ENB) << 4)) + (SUBDEV_CONN_COMPLEX_QI, ((CHAN_I0 | ENB) << 4) | ((CHAN_Q0 | ENB) << 0)) + (SUBDEV_CONN_REAL_I, ((CHAN_I0 | ENB) << 0)) + (SUBDEV_CONN_REAL_Q, ((CHAN_I0 | ENB) << 4)) + ) + (1, boost::assign::map_list_of + (SUBDEV_CONN_COMPLEX_IQ, ((CHAN_I1 | ENB) << 0) | ((CHAN_Q1 | ENB) << 4)) + (SUBDEV_CONN_COMPLEX_QI, ((CHAN_I1 | ENB) << 4) | ((CHAN_Q1 | ENB) << 0)) + (SUBDEV_CONN_REAL_I, ((CHAN_I1 | ENB) << 0)) + (SUBDEV_CONN_REAL_Q, ((CHAN_I1 | ENB) << 4)) + ) + ; + + //extract the number of channels + size_t nchan = subdev_spec.size(); + + //calculate the channel flags + int channel_flags = 0, chan = 0; + BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ + wax::obj dboard = mboard[named_prop_t(MBOARD_PROP_RX_DBOARD, pair.db_name)]; + wax::obj subdev = dboard[named_prop_t(DBOARD_PROP_SUBDEV, pair.sd_name)]; + subdev_conn_t conn = subdev[SUBDEV_PROP_CONNECTION].as(); + + //combine the channel flags: shift for slot A vs B + if (pair.db_name == "A") channel_flags |= chan_to_conn_to_flag[chan][conn] << 0; + if (pair.db_name == "B") channel_flags |= chan_to_conn_to_flag[chan][conn] << 8; + + //increment for the next channel + chan++; + } + + //calculate the tx mux value + return ((channel_flags & 0xffff) << 4) | ((nchan & 0x7) << 0); +} + /*********************************************************************** * Mboard Initialization **********************************************************************/ @@ -199,9 +302,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) //sanity check UHD_ASSERT_THROW(_rx_subdev_spec.size() <= 2); //set the mux and set the number of rx channels - //-------------------------------------------------- - // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO - //-------------------------------------------------- + _iface->poke32(FR_RX_MUX, calc_rx_mux(_rx_subdev_spec, _mboard_proxy->get_link())); return; case MBOARD_PROP_TX_SUBDEV_SPEC: @@ -210,9 +311,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) //sanity check UHD_ASSERT_THROW(_tx_subdev_spec.size() <= 2); //set the mux and set the number of tx channels - //-------------------------------------------------- - // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO - //-------------------------------------------------- + _iface->poke32(FR_TX_MUX, calc_tx_mux(_tx_subdev_spec, _mboard_proxy->get_link())); return; default: UHD_THROW_PROP_SET_ERROR(); -- cgit v1.2.3 From 5ac2f224154c819c0e0a788cbcd98da764950e70 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Wed, 18 Aug 2010 19:26:38 -0700 Subject: usrp1: Return proper mboard proxy --- host/lib/usrp/usrp1/mboard_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index c3343f1f8..48a919f2a 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -298,7 +298,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) case MBOARD_PROP_RX_SUBDEV_SPEC: _rx_subdev_spec = val.as(); - verify_rx_subdev_spec(_rx_subdev_spec, this->get_link()); + verify_rx_subdev_spec(_rx_subdev_spec, _mboard_proxy->get_link()); //sanity check UHD_ASSERT_THROW(_rx_subdev_spec.size() <= 2); //set the mux and set the number of rx channels @@ -307,7 +307,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) case MBOARD_PROP_TX_SUBDEV_SPEC: _tx_subdev_spec = val.as(); - verify_tx_subdev_spec(_tx_subdev_spec, this->get_link()); + verify_tx_subdev_spec(_tx_subdev_spec, _mboard_proxy->get_link()); //sanity check UHD_ASSERT_THROW(_tx_subdev_spec.size() <= 2); //set the mux and set the number of tx channels -- cgit v1.2.3 From f65bdc31e4432d09d52b7f45d5bfbd1f945a1a6f Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Mon, 23 Aug 2010 15:12:28 -0700 Subject: usrp1: Fix bug in calculating transmit mux Use transmit instead of receive properties. --- host/lib/usrp/usrp1/mboard_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 48a919f2a..74ec514ff 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -114,7 +114,7 @@ static boost::uint32_t calc_tx_mux( //calculate the channel flags int channel_flags = 0, chan = 0; BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ - wax::obj dboard = mboard[named_prop_t(MBOARD_PROP_RX_DBOARD, pair.db_name)]; + wax::obj dboard = mboard[named_prop_t(MBOARD_PROP_TX_DBOARD, pair.db_name)]; wax::obj subdev = dboard[named_prop_t(DBOARD_PROP_SUBDEV, pair.sd_name)]; subdev_conn_t conn = subdev[SUBDEV_PROP_CONNECTION].as(); -- cgit v1.2.3 From a161923ee63c5a8073fb14226b080895b491d998 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 26 Aug 2010 17:52:10 -0700 Subject: usrp1: swapped the mux values to account for the convert types routines --- host/lib/usrp/usrp1/mboard_impl.cpp | 63 +++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 74ec514ff..612dc732c 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -33,8 +33,21 @@ using namespace uhd; using namespace uhd::usrp; /*********************************************************************** - * Helper Functions + * Calculate the RX mux value: + * The I and Q mux values are intentionally reversed to flip I and Q + * to account for the reversal in the type conversion routines. **********************************************************************/ +static int calc_rx_mux_pair(int adc_for_i, int adc_for_q){ + return (adc_for_i << 2) | (adc_for_q << 0); //shift reversal here +} + +/*! + * 3 2 1 0 + * 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 + * +-----------------------+-------+-------+-------+-------+-+-----+ + * | must be zero | Q3| I3| Q2| I2| Q1| I1| Q0| I0|Z| NCH | + * +-----------------------+-------+-------+-------+-------+-+-----+ + */ static boost::uint32_t calc_rx_mux( const subdev_spec_t &subdev_spec, wax::obj mboard ){ @@ -42,16 +55,16 @@ static boost::uint32_t calc_rx_mux( static const int ADC0 = 0, ADC1 = 1, ADC2 = 2, ADC3 = 3; static const uhd::dict > name_to_conn_to_flag = boost::assign::map_list_of ("A", boost::assign::map_list_of - (SUBDEV_CONN_COMPLEX_IQ, (ADC0 << 0) | (ADC1 << 2)) //I and Q - (SUBDEV_CONN_COMPLEX_QI, (ADC1 << 0) | (ADC0 << 2)) //I and Q - (SUBDEV_CONN_REAL_I, (ADC0 << 0) | (ADC0 << 2)) //I and Q (Q identical but ignored Z=1) - (SUBDEV_CONN_REAL_Q, (ADC1 << 0) | (ADC1 << 2)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_COMPLEX_IQ, calc_rx_mux_pair(ADC0, ADC1)) //I and Q + (SUBDEV_CONN_COMPLEX_QI, calc_rx_mux_pair(ADC1, ADC0)) //I and Q + (SUBDEV_CONN_REAL_I, calc_rx_mux_pair(ADC0, ADC0)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_REAL_Q, calc_rx_mux_pair(ADC1, ADC1)) //I and Q (Q identical but ignored Z=1) ) ("B", boost::assign::map_list_of - (SUBDEV_CONN_COMPLEX_IQ, (ADC2 << 0) | (ADC3 << 2)) //I and Q - (SUBDEV_CONN_COMPLEX_QI, (ADC3 << 0) | (ADC2 << 2)) //I and Q - (SUBDEV_CONN_REAL_I, (ADC2 << 0) | (ADC2 << 2)) //I and Q (Q identical but ignored Z=1) - (SUBDEV_CONN_REAL_Q, (ADC3 << 0) | (ADC3 << 2)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_COMPLEX_IQ, calc_rx_mux_pair(ADC2, ADC3)) //I and Q + (SUBDEV_CONN_COMPLEX_QI, calc_rx_mux_pair(ADC3, ADC2)) //I and Q + (SUBDEV_CONN_REAL_I, calc_rx_mux_pair(ADC2, ADC2)) //I and Q (Q identical but ignored Z=1) + (SUBDEV_CONN_REAL_Q, calc_rx_mux_pair(ADC3, ADC3)) //I and Q (Q identical but ignored Z=1) ) ; @@ -88,6 +101,22 @@ static boost::uint32_t calc_rx_mux( return ((channel_flags & 0xffff) << 4) | ((Z & 0x1) << 3) | ((nchan & 0x7) << 0); } +/*********************************************************************** + * Calculate the TX mux value: + * The I and Q mux values are intentionally reversed to flip I and Q + * to account for the reversal in the type conversion routines. + **********************************************************************/ +static int calc_tx_mux_pair(int chn_for_i, int chn_for_q){ + return (chn_for_i << 4) | (chn_for_q << 0); //shift reversal here +} + +/*! + * 3 2 1 0 + * 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 + * +-----------------------+-------+-------+-------+-------+-+-----+ + * | | DAC1Q | DAC1I | DAC0Q | DAC0I |0| NCH | + * +-----------------------------------------------+-------+-+-----+ + */ static boost::uint32_t calc_tx_mux( const subdev_spec_t &subdev_spec, wax::obj mboard ){ @@ -95,16 +124,16 @@ static boost::uint32_t calc_tx_mux( static const int ENB = 1 << 3, CHAN_I0 = 0, CHAN_Q0 = 1, CHAN_I1 = 2, CHAN_Q1 = 3; static const uhd::dict > chan_to_conn_to_flag = boost::assign::map_list_of (0, boost::assign::map_list_of - (SUBDEV_CONN_COMPLEX_IQ, ((CHAN_I0 | ENB) << 0) | ((CHAN_Q0 | ENB) << 4)) - (SUBDEV_CONN_COMPLEX_QI, ((CHAN_I0 | ENB) << 4) | ((CHAN_Q0 | ENB) << 0)) - (SUBDEV_CONN_REAL_I, ((CHAN_I0 | ENB) << 0)) - (SUBDEV_CONN_REAL_Q, ((CHAN_I0 | ENB) << 4)) + (SUBDEV_CONN_COMPLEX_IQ, calc_tx_mux_pair(CHAN_I0 | ENB, CHAN_Q0 | ENB)) + (SUBDEV_CONN_COMPLEX_QI, calc_tx_mux_pair(CHAN_Q0 | ENB, CHAN_I0 | ENB)) + (SUBDEV_CONN_REAL_I, calc_tx_mux_pair(CHAN_I0 | ENB, 0 )) + (SUBDEV_CONN_REAL_Q, calc_tx_mux_pair(0, CHAN_I0 | ENB)) ) (1, boost::assign::map_list_of - (SUBDEV_CONN_COMPLEX_IQ, ((CHAN_I1 | ENB) << 0) | ((CHAN_Q1 | ENB) << 4)) - (SUBDEV_CONN_COMPLEX_QI, ((CHAN_I1 | ENB) << 4) | ((CHAN_Q1 | ENB) << 0)) - (SUBDEV_CONN_REAL_I, ((CHAN_I1 | ENB) << 0)) - (SUBDEV_CONN_REAL_Q, ((CHAN_I1 | ENB) << 4)) + (SUBDEV_CONN_COMPLEX_IQ, calc_tx_mux_pair(CHAN_I1 | ENB, CHAN_Q1 | ENB)) + (SUBDEV_CONN_COMPLEX_QI, calc_tx_mux_pair(CHAN_Q1 | ENB, CHAN_I1 | ENB)) + (SUBDEV_CONN_REAL_I, calc_tx_mux_pair(CHAN_I1 | ENB, 0 )) + (SUBDEV_CONN_REAL_Q, calc_tx_mux_pair(0, CHAN_I1 | ENB)) ) ; -- cgit v1.2.3 From 45d8240f77609914116e743c9ed24fad80288b57 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Thu, 26 Aug 2010 15:59:04 -0700 Subject: usrp1: Clean up initialization sequence of fpga registers --- host/lib/usrp/usrp1/mboard_impl.cpp | 77 +++++++++---------------------------- 1 file changed, 18 insertions(+), 59 deletions(-) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 612dc732c..8c9be9f73 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -168,65 +168,24 @@ void usrp1_impl::mboard_init(void) boost::bind(&usrp1_impl::mboard_get, this, _1, _2), boost::bind(&usrp1_impl::mboard_set, this, _1, _2)); - /* - * Basic initialization - */ - _iface->poke32( 13, 0x00000000); //FR_MODE - _iface->poke32( 14, 0x00000000); //FR_DEBUG_EN - _iface->poke32( 1, 0x00000001); //FR_RX_SAMPLE_RATE_DEV - _iface->poke32( 0, 0x00000003); //FR_TX_SAMPLE_RATE_DEV - _iface->poke32( 15, 0x0000000f); //FR_DC_OFFSET_CL_EN - - /* - * Reset codecs - */ - _iface->poke32( 16, 0x00000000); //FR_ADC_OFFSET_0 - _iface->poke32( 17, 0x00000000); //FR_ADC_OFFSET_1 - _iface->poke32( 18, 0x00000000); //FR_ADC_OFFSET_2 - _iface->poke32( 19, 0x00000000); //FR_ADC_OFFSET_3 - - /* - * Reset GPIO masks - */ - _iface->poke32( 6, 0xffff0000); //FR_OE_1 - _iface->poke32( 10, 0xffff0000); //FR_IO_1 - _iface->poke32( 8, 0xffff0000); //FR_OE_3 - _iface->poke32( 12, 0xffff0000); //FR_IO_3 - - /* - * Disable ATR masks and reset state registers - */ - _iface->poke32( 23, 0x00000000); //FR_ATR_MASK_1 - _iface->poke32( 24, 0x00000000); //FR_ATR_TXVAL_1 - _iface->poke32( 25, 0x00000000); //FR_ATR_RXVAL_1 - _iface->poke32( 29, 0x00000000); //FR_ATR_MASK_3 - _iface->poke32( 30, 0x00000000); //FR_ATR_TXVAL_3 - _iface->poke32( 31, 0x00000000); //FR_ATR_RXVAL_3 - - /* - * Set defaults for RX format, decimation, and mux - */ - _iface->poke32( 49, 0x00000300); //FR_RX_FORMAT - _iface->poke32( 38, 0x000e4e41); //FR_RX_MUX - - /* - * Set defaults for TX format, interpolation, and mux - */ - _iface->poke32( 48, 0x00000000); //FR_TX_FORMAT - _iface->poke32( 39, 0x00000981); //FR_TX_MUX - - /* - * Reset DDC registers - */ - _iface->poke32( 34, 0x00000000); //FR_RX_FREQ_0 - _iface->poke32( 44, 0x00000000); //FR_RX_PHASE_0 - _iface->poke32( 35, 0x00000000); //FR_RX_FREQ_1 - _iface->poke32( 45, 0x00000000); //FR_RX_PHASE_1 - _iface->poke32( 36, 0x00000000); //FR_RX_FREQ_2 - _iface->poke32( 46, 0x00000000); //FR_RX_PHASE_2 - _iface->poke32( 37, 0x00000000); //FR_RX_FREQ_3 - _iface->poke32( 47, 0x00000000); //FR_RX_PHASE_3 - + // Normal mode with no loopback or Rx counting + _iface->poke32(FR_MODE, 0x00000000); + _iface->poke32(FR_DEBUG_EN, 0x00000000); + _iface->poke32(FR_RX_SAMPLE_RATE_DIV, 0x00000001); + _iface->poke32(FR_TX_SAMPLE_RATE_DIV, 0x00000003); + _iface->poke32(FR_DC_OFFSET_CL_EN, 0x0000000f); + + // Reset offset correction registers + _iface->poke32(FR_ADC_OFFSET_0, 0x00000000); + _iface->poke32(FR_ADC_OFFSET_1, 0x00000000); + _iface->poke32(FR_ADC_OFFSET_2, 0x00000000); + _iface->poke32(FR_ADC_OFFSET_3, 0x00000000); + + // Set default for RX format to 16-bit I&Q and no half-band filter bypass + _iface->poke32(FR_RX_FORMAT, 0x00000300); + + // Set default for TX format to 16-bit I&Q + _iface->poke32(FR_TX_FORMAT, 0x00000000); } void usrp1_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) -- cgit v1.2.3 From 98510590c453bf366d29e488c1d3b54ec022f919 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Thu, 26 Aug 2010 17:07:17 -0700 Subject: usrp1: Add missing include for fpga registers --- host/lib/usrp/usrp1/mboard_impl.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 8c9be9f73..0b1335acf 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -18,6 +18,7 @@ #include "usrp1_impl.hpp" #include "usrp_commands.h" #include "fpga_regs_standard.h" +#include "fpga_regs_common.h" #include #include #include -- cgit v1.2.3 From 2c85b17215fbe5fd2f80a8c6d0c47504a631c09b Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Fri, 27 Aug 2010 23:16:43 -0700 Subject: usrp1: Read capabilities register --- host/lib/usrp/usrp1/mboard_impl.cpp | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 0b1335acf..75129c32f 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -160,6 +160,35 @@ static boost::uint32_t calc_tx_mux( return ((channel_flags & 0xffff) << 4) | ((nchan & 0x7) << 0); } +/*! + * Capabilities Register + * + * 3 2 1 0 + * 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 + * +-----------------------------------------------+-+-----+-+-----+ + * | Reserved |T|DUCs |R|DDCs | + * +-----------------------------------------------+-+-----+-+-----+ + */ +static int num_ddcs(boost::uint32_t regval) +{ + return (regval >> 0) & 0x0007; +} + +static int num_ducs(boost::uint32_t regval) +{ + return (regval >> 4) & 0x0007; +} + +static bool has_rx_halfband(boost::uint32_t regval) +{ + return (regval >> 3) & 0x0001; +} + +static bool has_tx_halfband(boost::uint32_t regval) +{ + return (regval >> 7) & 0x0001; +} + /*********************************************************************** * Mboard Initialization **********************************************************************/ @@ -187,6 +216,17 @@ void usrp1_impl::mboard_init(void) // Set default for TX format to 16-bit I&Q _iface->poke32(FR_TX_FORMAT, 0x00000000); + + // TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO + // + // Do something useful with the capabilities register + // + boost::uint32_t regval = _iface->peek32(FR_RB_CAPS); + std::cout << "USRP1 Capabilities" << std::endl; + std::cout << " number of duc's: " << num_ddcs(regval) << std::endl; + std::cout << " number of ddc's: " << num_ducs(regval) << std::endl; + std::cout << " rx halfband: " << has_rx_halfband(regval) << std::endl; + std::cout << " tx halfband: " << has_tx_halfband(regval) << std::endl; } void usrp1_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) -- cgit v1.2.3 From b96088b692a5c44974919ee36e253b6ea8c51972 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 31 Aug 2010 16:44:30 -0700 Subject: EEPROM burning in UHD. Changed some USB device handle stuff. Added usrp_init_eeprom.cpp. Hacked up the firmware makefile to behave and to generate .bin EEPROM images instead of IHX. --- firmware/fx2/src/common/build_eeprom.py | 103 +++-------------------- firmware/fx2/src/usrp1/Makefile.am | 58 +++---------- host/include/uhd/transport/usb_device_handle.hpp | 4 +- host/lib/transport/libusb1_base.cpp | 52 ++---------- host/lib/transport/libusb1_base.hpp | 10 --- host/lib/transport/libusb1_device_handle.cpp | 18 ++-- host/lib/usrp/usrp1/mboard_impl.cpp | 11 +++ host/lib/usrp/usrp1/usrp1_ctrl.cpp | 63 +++++++++++++- host/lib/usrp/usrp1/usrp1_ctrl.hpp | 31 +++++++ host/lib/usrp/usrp1/usrp1_iface.cpp | 21 +++-- host/lib/usrp/usrp1/usrp1_impl.cpp | 34 ++++---- host/utils/CMakeLists.txt | 4 + host/utils/usrp_init_eeprom.cpp | 69 +++++++++++++++ 13 files changed, 255 insertions(+), 223 deletions(-) create mode 100644 host/utils/usrp_init_eeprom.cpp (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/firmware/fx2/src/common/build_eeprom.py b/firmware/fx2/src/common/build_eeprom.py index 023c4b3f5..ae62587db 100755 --- a/firmware/fx2/src/common/build_eeprom.py +++ b/firmware/fx2/src/common/build_eeprom.py @@ -29,15 +29,6 @@ from optparse import OptionParser VID = 0xfffe # Free Software Folks PID = 0x0002 # Universal Software Radio Peripheral - - -def hex_to_bytes (s): - if len (s) & 0x1: - raise ValueError, "Length must be even" - r = [] - for i in range (0, len(s), 2): - r.append (int (s[i:i+2], 16)) - return r def msb (x): return (x >> 8) & 0xff @@ -45,56 +36,6 @@ def msb (x): def lsb (x): return x & 0xff -class ihx_rec (object): - def __init__ (self, addr, type, data): - self.addr = addr - self.type = type - self.data = data - -class ihx_file (object): - def __init__ (self): - self.pat = re.compile (r':[0-9A-F]{10,}') - def read (self, file): - r = [] - for line in file: - line = line.strip().upper () - if not self.pat.match (line): - raise ValueError, "Invalid hex record format" - bytes = hex_to_bytes (line[1:]) - sum = reduce (lambda x, y: x + y, bytes, 0) % 256 - if sum != 0: - raise ValueError, "Bad hex checksum" - lenx = bytes[0] - addr = (bytes[1] << 8) + bytes[2] - type = bytes[3] - data = bytes[4:-1] - if lenx != len (data): - raise ValueError, "Invalid hex record (bad length)" - if type != 0: - break; - r.append (ihx_rec (addr, type, data)) - - return r - -def get_code (filename): - """Read the intel hex format file FILENAME and return a tuple - of the code starting address and a list of bytes to load there. - """ - f = open (filename, 'r') - ifx = ihx_file () - r = ifx.read (f) - r.sort (lambda a,b: a.addr - b.addr) - code_start = r[0].addr - code_end = r[-1].addr + len (r[-1].data) - code_len = code_end - code_start - code = [0] * code_len - for x in r: - a = x.addr - l = len (x.data) - code[a-code_start:a-code_start+l] = x.data - return (code_start, code) - - def build_eeprom_image (filename, rev): """Build a ``C2 Load'' EEPROM image. @@ -102,9 +43,11 @@ def build_eeprom_image (filename, rev): the EZ-USB FX2 Technical Reference Manual """ # get the code we want to run - (start_addr, bytes) = get_code (filename) + f = open(filename, 'rb') + bytes = f.read() devid = rev + start_addr = 0 #prove me wrong rom_header = [ 0xC2, # boot from EEPROM @@ -135,41 +78,18 @@ def build_eeprom_image (filename, rev): 0x00 ] - image = rom_header + code_header + bytes + trailer + image = rom_header + code_header + [ord(c) for c in bytes] + trailer assert (len (image) <= 256) - return image - -def build_shell_script (out, ihx_filename, rev): - - image = build_eeprom_image (ihx_filename, rev) - - out.write ('#!/bin/sh\n') - out.write ('usrper -x load_firmware /usr/local/share/usrp/rev%d/std.ihx\n' % rev) - out.write ('sleep 1\n') - - # print "len(image) =", len(image) - - i2c_addr = 0x50 - rom_addr = 0x00 - - hex_image = map (lambda x : "%02x" % (x,), image) - - while (len (hex_image) > 0): - l = min (len (hex_image), 16) - out.write ('usrper i2c_write 0x%02x %02x%s\n' % - (i2c_addr, rom_addr, ''.join (hex_image[0:l]))) - hex_image = hex_image[l:] - rom_addr = rom_addr + l - out.write ('sleep 1\n') + return image if __name__ == '__main__': - usage = "usage: %prog -r REV [options] bootfile.ihx" + usage = "usage: %prog -r REV [options] bootfile.bin outfile.bin" parser = OptionParser (usage=usage) parser.add_option ("-r", "--rev", type="int", default=-1, help="Specify USRP revision number REV (2 or 4)") (options, args) = parser.parse_args () - if len (args) != 1: + if len (args) != 2: parser.print_help () sys.exit (1) if options.rev < 0: @@ -177,6 +97,11 @@ if __name__ == '__main__': "You must specify the USRP revision number (2 or 4) with -r REV\n") sys.exit (1) - ihx_filename = args[0] + infile = args[0] + outfile = args[1] + + image = "".join(chr(c) for c in build_eeprom_image(infile, options.rev)) - build_shell_script (sys.stdout, ihx_filename, options.rev) + f = open(outfile, 'wb') + f.write(str(image)) + f.close() diff --git a/firmware/fx2/src/usrp1/Makefile.am b/firmware/fx2/src/usrp1/Makefile.am index 5586e83a3..a964f9198 100644 --- a/firmware/fx2/src/usrp1/Makefile.am +++ b/firmware/fx2/src/usrp1/Makefile.am @@ -19,12 +19,12 @@ # Boston, MA 02110-1301, USA. # -firmware2dir = $(prefix)/share/usrp/rev2 -firmware2_DATA = std.ihx +#firmwaredir = $(prefix)/share/uhd/images +#firmware_DATA = usrp1_fw.ihx -# we put the same stuff in the rev4 directory -firmware4dir = $(prefix)/share/usrp/rev4 -firmware4_DATA = std.ihx +#eepromdir = $(firmwaredir) +#eepromfile = eeprom_boot.ihx +#eeprom_DATA = usrp1_eeprom.bin EXTRA_DIST = \ edit-gpif \ @@ -85,11 +85,6 @@ EXECUTABLES = \ STARTUP = _startup.rel -noinst_SCRIPTS = \ - burn-usrp2-eeprom \ - burn-usrp4-eeprom - - .c.rel: $(XCC) $(FW_INCLUDES) $(DEFINES) \ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$< @@ -107,34 +102,11 @@ EEPROM_BOOT_OBJS = eeprom_boot.rel eeprom_init.rel $(STARTUP) eeprom_boot.ihx: $(EEPROM_BOOT_OBJS) $(LIBDEP) $(XCC) $(LINKOPTS) -o $@ $(EEPROM_BOOT_OBJS) -burn-usrp2-eeprom: eeprom_boot.ihx - $(PYTHON) $(srcdir)/../common/build_eeprom.py -r2 eeprom_boot.ihx > $@ - chmod +x $@ - -burn-usrp4-eeprom: eeprom_boot.ihx - $(PYTHON) $(srcdir)/../common/build_eeprom.py -r4 eeprom_boot.ihx > $@ - chmod +x $@ - - -BLINK_LEDS_OBJS = blink_leds.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP) - -blink_leds.ihx: $(BLINK_LEDS_OBJS) $(LIBDEP) - $(XCC) $(LINKOPTS) -o $@ $(BLINK_LEDS_OBJS) - - -CHECK_MDELAY_OBJS = check_mdelay.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP) - -check_mdelay.ihx: $(CHECK_MDELAY_OBJS) $(LIBDEP) - $(XCC) $(LINKOPTS) -o $@ $(CHECK_MDELAY_OBJS) - - - -CHECK_UDELAY_OBJS = check_udelay.rel usrp_common.rel board_specific.rel spi.rel $(STARTUP) - -check_udelay.ihx: $(CHECK_UDELAY_OBJS) $(LIBDEP) - $(XCC) $(LINKOPTS) -o $@ $(CHECK_UDELAY_OBJS) - +usrp1_eeprom.bin: eeprom_boot.bin + $(PYTHON) ../common/build_eeprom.py -r4 $< $@ +eeprom_boot.bin: eeprom_boot.ihx + objcopy -I ihex -O binary $< $@ USRP_OBJS = \ vectors.rel \ @@ -146,25 +118,23 @@ std.ihx: $(USRP_OBJS) $(LIBDEP) $(XCC) $(LINKOPTS) -o $@ $(USRP_OBJS) CLEANFILES = \ - *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib \ - usrp_gpif.c usrp_gpif_inline.h \ - burn-usrp2-eeprom \ - burn-usrp4-eeprom + *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib *.bin \ + usrp_gpif.c usrp_gpif_inline.h DISTCLEANFILES = \ - *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib + *.ihx *.lnk *.lst *.map *.mem *.rel *.rst *.sym *.asm *.lib *.bin # build gpif stuff -all: usrp_gpif.c +all: usrp_gpif.c std.ihx usrp1_eeprom.bin usrp_gpif.c usrp_gpif_inline.h : gpif.c srcdir=$(srcdir) $(PYTHON) $(srcdir)/edit-gpif $(srcdir)/gpif.c usrp_gpif.c usrp_gpif_inline.h - # dependencies usrp_main.rel: usrp_gpif_inline.h + #usrp_main.rel: fpga.h usrp_common.h ../../include/usrp_commands.h usrp_gpif_inline.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h #usrp_common.rel: usrp_common.h ../../include/usrp_commands.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h #fpga.rel: usrp_common.h ../../include/usrp_commands.h fpga.h ../../include/usrp_config.h usrp_rev2_regs.h ../../include/fx2regs.h diff --git a/host/include/uhd/transport/usb_device_handle.hpp b/host/include/uhd/transport/usb_device_handle.hpp index 78c78f6b5..c3eb72b00 100644 --- a/host/include/uhd/transport/usb_device_handle.hpp +++ b/host/include/uhd/transport/usb_device_handle.hpp @@ -68,9 +68,9 @@ public: /*! * Return a vector of USB devices on this host - * \return a vector of USB device handles + * \return a vector of USB device handles that match vid and pid */ - static UHD_API std::vector get_device_list(); + static UHD_API std::vector get_device_list(boost::uint16_t vid, boost::uint16_t pid); }; //namespace usb diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 92dcd969f..e21c39aa3 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -24,22 +24,6 @@ using namespace uhd::transport; /********************************************************** * Helper Methods **********************************************************/ -/* - * Check for FSF device - * Compare the device's descriptor Vendor ID - * \param dev pointer to libusb_device - * \return true if Vendor ID matches 0xfffe - */ -bool check_fsf_device(libusb_device *dev) -{ - libusb_device_descriptor desc; - - if (libusb_get_device_descriptor(dev, &desc) < 0) { - UHD_ASSERT_THROW("USB: failed to get device descriptor"); - } - - return desc.idVendor == 0xfffe; -} /********************************************************** * libusb namespace @@ -52,37 +36,16 @@ void libusb::init(libusb_context **ctx, int debug_level) libusb_set_debug(*ctx, debug_level); } -std::vector libusb::get_fsf_device_list(libusb_context *ctx) -{ - libusb_device **libusb_dev_list; - std::vector fsf_dev_list; - - ssize_t dev_cnt = libusb_get_device_list(ctx, &libusb_dev_list); - - //find the FSF devices - for (ssize_t i = 0; i < dev_cnt; i++) { - libusb_device *dev = libusb_dev_list[i]; - - if (check_fsf_device(dev)) - fsf_dev_list.push_back(dev); - else - libusb_unref_device(dev); - } - - libusb_free_device_list(libusb_dev_list, 0); - - return fsf_dev_list; -} - libusb_device_handle *libusb::open_device(libusb_context *ctx, usb_device_handle::sptr handle) { libusb_device_handle *dev_handle = NULL; - std::vector fsf_dev_list = get_fsf_device_list(ctx); + libusb_device **libusb_dev_list; + size_t dev_cnt = libusb_get_device_list(ctx, &libusb_dev_list); //find and open the USB device - for (size_t i = 0; i < fsf_dev_list.size(); i++) { - libusb_device *dev = fsf_dev_list[i]; + for (size_t i = 0; i < dev_cnt; i++) { + libusb_device *dev = libusb_dev_list[i]; if (compare_device(dev, handle)) { libusb_open(dev, &dev_handle); @@ -96,7 +59,8 @@ libusb_device_handle *libusb::open_device(libusb_context *ctx, return dev_handle; } - +//note: changed order of checks so it only tries to get_serial and get_device_address if vid and pid match +//doing this so it doesn't try to open the device if it's not ours bool libusb::compare_device(libusb_device *dev, usb_device_handle::sptr handle) { @@ -108,12 +72,12 @@ bool libusb::compare_device(libusb_device *dev, libusb_device_descriptor libusb_desc; if (libusb_get_device_descriptor(dev, &libusb_desc) < 0) return false; - if (serial != get_serial(dev)) - return false; if (vendor_id != libusb_desc.idVendor) return false; if (product_id != libusb_desc.idProduct) return false; + if (serial != get_serial(dev)) + return false; if (device_addr != libusb_get_device_address(dev)) return false; diff --git a/host/lib/transport/libusb1_base.hpp b/host/lib/transport/libusb1_base.hpp index 442f89ded..abe5e22a2 100644 --- a/host/lib/transport/libusb1_base.hpp +++ b/host/lib/transport/libusb1_base.hpp @@ -41,16 +41,6 @@ namespace libusb { */ void init(libusb_context **ctx, int debug_level); - /* - * Get a list of Free Software Foundation devices (Vendor ID 0xfffe) - * As opposed to the public USB device handle interface, which returns - * generic identifiers, this call returns device pointers speficic - * to libusb. - * \param ctx the libusb context used for init - * \return a vector of libusb devices - */ - std::vector get_fsf_device_list(libusb_context *ctx); - /* * Open the device specified by a generic handle * Find the libusb_device cooresponding to the generic handle diff --git a/host/lib/transport/libusb1_device_handle.cpp b/host/lib/transport/libusb1_device_handle.cpp index 5d9d8faf0..43d0f0e26 100644 --- a/host/lib/transport/libusb1_device_handle.cpp +++ b/host/lib/transport/libusb1_device_handle.cpp @@ -17,6 +17,7 @@ #include "libusb1_base.hpp" #include +#include using namespace uhd::transport; @@ -91,19 +92,24 @@ usb_device_handle::sptr make_usb_device_handle(libusb_device *dev) device_addr)); } -std::vector usb_device_handle::get_device_list() +std::vector usb_device_handle::get_device_list(boost::uint16_t vid, boost::uint16_t pid) { libusb_context *ctx = NULL; - std::vector libusb_device_list; + libusb_device** libusb_device_list; std::vector device_handle_list; + libusb_device_descriptor desc; libusb::init(&ctx, libusb_debug_level); - libusb_device_list = libusb::get_fsf_device_list(ctx); - - for (size_t i = 0; i < libusb_device_list.size(); i++) { + size_t dev_size = libusb_get_device_list(ctx, &libusb_device_list); + for (size_t i = 0; i < dev_size; i++) { libusb_device *dev = libusb_device_list[i]; - device_handle_list.push_back(make_usb_device_handle(dev)); + if(libusb_get_device_descriptor(dev, &desc) < 0) { + UHD_ASSERT_THROW("USB: failed to get device descriptor"); + } + if(desc.idVendor == vid && desc.idProduct == pid) { + device_handle_list.push_back(make_usb_device_handle(dev)); + } } libusb_exit(ctx); diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 75129c32f..1409855cb 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -318,6 +319,16 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) **********************************************************************/ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) { + if(key.type() == typeid(std::string)) { + if(key.as() == "load_eeprom") { + std::string usrp1_fpga_image = val.as(); + std::cout << "USRP1 EEPROM image: " << usrp1_fpga_image << std::endl; + _ctrl_transport->usrp_load_eeprom(val.as()); + } + + return; + } + //handle the get request conditioned on the key switch(key.as()){ diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp index 98226b738..451129ef5 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace uhd; @@ -203,7 +204,7 @@ public: return -1; } } - //type 0x00 is end + //type 0x01 is end else if (type == 0x01) { usrp_control_write(FX2_FIRMWARE_LOAD, 0xe600, 0, &reset_n, 1); @@ -283,6 +284,55 @@ public: return 0; } + int usrp_load_eeprom(std::string filestring) + { + const char *filename = filestring.c_str(); + const uint16_t i2c_addr = 0x50; + + //FIXME: verify types + int len; + unsigned int addr; + unsigned char data[256]; + unsigned char sendbuf[17]; + + int ret; + std::ifstream file; + file.open(filename, std::ifstream::in); + + if (!file.good()) { + std::cerr << "cannot open EEPROM input file" << std::endl; + return -1; + } + + file.read((char *)data, 256); + len = file.gcount(); + + if(len == 256) { + std::cerr << "error: image size too large" << std::endl; + file.close(); + return -1; + } + + const int pagesize = 16; + addr = 0; + while(len > 0) { + sendbuf[0] = addr; + memcpy(sendbuf+1, &data[addr], len > pagesize ? pagesize : len); + ret = usrp_i2c_write(i2c_addr, sendbuf, (len > pagesize ? pagesize : len)+1); + if (ret < 0) { + std::cerr << "error: usrp_i2c_write failed: "; + std::cerr << ret << std::endl; + file.close(); + return -1; + } + addr += pagesize; + len -= pagesize; + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + } + file.close(); + return 0; + } + int usrp_set_led(int led_num, bool on) { @@ -371,6 +421,17 @@ public: return usrp_control_write(request, value, index, 0, 0); } + int usrp_i2c_write(boost::uint16_t i2c_addr, unsigned char *buf, boost::uint16_t len) + { + return usrp_control_write(VRQ_I2C_WRITE, i2c_addr, 0, buf, len); + } + + int usrp_i2c_read(boost::uint16_t i2c_addr, unsigned char *buf, boost::uint16_t len) + { + return usrp_control_read(VRQ_I2C_READ, i2c_addr, 0, buf, len); + } + + private: uhd::transport::usb_control::sptr _ctrl_transport; diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.hpp b/host/lib/usrp/usrp1/usrp1_ctrl.hpp index deedec4e8..a02d9f96c 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.hpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.hpp @@ -49,6 +49,13 @@ public: */ virtual int usrp_load_fpga(std::string filename) = 0; + /*! + * Load USB descriptor file in Intel HEX format into EEPROM + * \param filename name of EEPROM image + * \return 0 on success, error code otherwise + */ + virtual int usrp_load_eeprom(std::string filestring) = 0; + /*! * Set led usrp * \param led_num which LED to control (0 or 1) @@ -127,6 +134,30 @@ public: unsigned char *buff, boost::uint16_t length) = 0; + /*! + * Perform an I2C write + * \param i2c_addr I2C device address + * \param buf data to be written + * \param len length of data in bytes + * \return number of bytes written or error + */ + + virtual int usrp_i2c_write(boost::uint16_t i2c_addr, + unsigned char *buf, + boost::uint16_t len) = 0; + + /*! + * Perform an I2C read + * \param i2c_addr I2C device address + * \param buf data to be read + * \param len length of data in bytes + * \return number of bytes read or error + */ + + virtual int usrp_i2c_read(boost::uint16_t i2c_addr, + unsigned char *buf, + boost::uint16_t len) = 0; + }; #endif /* INCLUDED_USRP_CTRL_HPP */ diff --git a/host/lib/usrp/usrp1/usrp1_iface.cpp b/host/lib/usrp/usrp1/usrp1_iface.cpp index 8756a21c9..4bc18dd16 100644 --- a/host/lib/usrp/usrp1/usrp1_iface.cpp +++ b/host/lib/usrp/usrp1/usrp1_iface.cpp @@ -109,18 +109,19 @@ public: ******************************************************************/ static const size_t max_i2c_data_bytes = 64; + //TODO: make this handle EEPROM page sizes. right now you can't write over a 16-byte boundary. + //to accomplish this you'll have to have addr offset as a separate parameter. + void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes) { UHD_ASSERT_THROW(bytes.size() < max_i2c_data_bytes); unsigned char buff[max_i2c_data_bytes]; - std::copy(bytes.begin(), bytes.end(), buff); + std::copy(bytes.begin(), bytes.end(), buff); - int ret = _ctrl_transport->usrp_control_write(VRQ_I2C_WRITE, - addr & 0xff, - 0, - buff, - bytes.size()); + int ret = _ctrl_transport->usrp_i2c_write(addr & 0xff, + buff, + bytes.size()); // TODO throw and catch i2c failures during eeprom read if (iface_debug && (ret < 0)) @@ -132,11 +133,9 @@ public: UHD_ASSERT_THROW(num_bytes < max_i2c_data_bytes); unsigned char buff[max_i2c_data_bytes]; - int ret = _ctrl_transport->usrp_control_read(VRQ_I2C_READ, - addr & 0xff, - 0, - buff, - num_bytes); + int ret = _ctrl_transport->usrp_i2c_read(addr & 0xff, + buff, + num_bytes); // TODO throw and catch i2c failures during eeprom read if (iface_debug && ((ret < 0) || (unsigned)ret < (num_bytes))) { diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 3c3306525..8ad148274 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -34,6 +34,11 @@ using namespace uhd; using namespace uhd::usrp; using namespace uhd::transport; +const boost::uint16_t USRP1_VENDOR_ID = 0xfffe; +const boost::uint16_t USRP1_PRODUCT_ID = 0x0002; +const boost::uint16_t FX2_VENDOR_ID = 0x04b4; +const boost::uint16_t FX2_PRODUCT_ID = 0x8613; + const std::vector usrp1_impl::_dboard_slots = boost::assign::list_of (usrp1_impl::DBOARD_SLOT_A)(usrp1_impl::DBOARD_SLOT_B) ; @@ -54,33 +59,32 @@ static device_addrs_t usrp1_find(const device_addr_t &hint) ); std::cout << "USRP1 firmware image: " << usrp1_fw_image << std::endl; + boost::uint16_t vid = hint.has_key("uninit") ? FX2_VENDOR_ID : USRP1_VENDOR_ID; + boost::uint16_t pid = hint.has_key("uninit") ? FX2_PRODUCT_ID : USRP1_PRODUCT_ID; + //see what we got on the USB bus std::vector device_list = - usb_device_handle::get_device_list(); + usb_device_handle::get_device_list(vid, pid); + + if(device_list.size() == 0) return usrp1_addrs; //return nothing if no USRPs found //find the usrps and load firmware BOOST_FOREACH(usb_device_handle::sptr handle, device_list) { - if (handle->get_vendor_id() == 0xfffe && - handle->get_product_id() == 0x0002) { - usb_control::sptr ctrl_transport = usb_control::make(handle); usrp_ctrl::sptr usrp_ctrl = usrp_ctrl::make(ctrl_transport); usrp_ctrl->usrp_load_firmware(usrp1_fw_image); - } } - //get descriptors again with serial number - device_list = usb_device_handle::get_device_list(); + //get descriptors again with serial number, but using the initialized VID/PID now since we have firmware + vid = USRP1_VENDOR_ID; + pid = USRP1_PRODUCT_ID; + device_list = usb_device_handle::get_device_list(vid, pid); BOOST_FOREACH(usb_device_handle::sptr handle, device_list) { - if (handle->get_vendor_id() == 0xfffe && - handle->get_product_id() == 0x0002) { - device_addr_t new_addr; new_addr["type"] = "usrp1"; new_addr["serial"] = handle->get_serial(); usrp1_addrs.push_back(new_addr); - } } return usrp1_addrs; @@ -99,17 +103,15 @@ static device::sptr usrp1_make(const device_addr_t &device_addr) //try to match the given device address with something on the USB bus std::vector device_list = - usb_device_handle::get_device_list(); + usb_device_handle::get_device_list(USRP1_VENDOR_ID, USRP1_PRODUCT_ID); //create data and control transports usb_zero_copy::sptr data_transport; usrp_ctrl::sptr usrp_ctrl; - BOOST_FOREACH(usb_device_handle::sptr handle, device_list) { - if (handle->get_vendor_id() == 0xfffe && - handle->get_product_id() == 0x0002 && - handle->get_serial() == device_addr["serial"]) { + BOOST_FOREACH(usb_device_handle::sptr handle, device_list) { + if (handle->get_serial() == device_addr["serial"]) { usb_control::sptr ctrl_transport = usb_control::make(handle); usrp_ctrl = usrp_ctrl::make(ctrl_transport); usrp_ctrl->usrp_load_fpga(usrp1_fpga_image); diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index c349a9018..9d788b06c 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -39,9 +39,13 @@ TARGET_LINK_LIBRARIES(usrp2_addr_burner uhd) ADD_EXECUTABLE(usrp_burn_db_eeprom usrp_burn_db_eeprom.cpp) TARGET_LINK_LIBRARIES(usrp_burn_db_eeprom uhd) +ADD_EXECUTABLE(usrp_init_eeprom usrp_init_eeprom.cpp) +TARGET_LINK_LIBRARIES(usrp_init_eeprom uhd) + INSTALL(TARGETS usrp2_addr_burner usrp_burn_db_eeprom + usrp_init_eeprom RUNTIME DESTINATION ${PKG_DATA_DIR}/utils ) diff --git a/host/utils/usrp_init_eeprom.cpp b/host/utils/usrp_init_eeprom.cpp new file mode 100644 index 000000000..28c7c5745 --- /dev/null +++ b/host/utils/usrp_init_eeprom.cpp @@ -0,0 +1,69 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("image", po::value(), "IHX image file") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("USRP EEPROM initialization %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + device_addr["type"] = "usrp1"; + device_addr["uninit"] = "yeah"; //tell find to look for an uninitialized FX2 + + //find and create a control transport to do the writing. + + uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); + + if (found_addrs.size() == 0){ + std::cerr << "No uninitialized USRP devices found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < found_addrs.size(); i++){ + std::cout << "Writing EEPROM data..." << std::endl; + //uhd::device_addrs_t devs = uhd::device::find(found_addrs[i]); + uhd::device::sptr dev = uhd::device::make(found_addrs[i]); + wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; + mb[std::string("load_eeprom")] = vm["image"].as(); + } + + + std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; + return 0; +} -- cgit v1.2.3 From 7b066a4593646b6023f56283ff02cf0e4ee099a6 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 31 Aug 2010 17:32:55 -0700 Subject: Added usrp_serial_burner.cpp and capabilities for setting serial number in mboard_impl. Have not yet added read support. --- host/lib/usrp/usrp1/mboard_impl.cpp | 12 +++++- host/utils/CMakeLists.txt | 4 ++ host/utils/usrp_init_eeprom.cpp | 2 +- host/utils/usrp_serial_burner.cpp | 74 +++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 host/utils/usrp_serial_burner.cpp (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 1409855cb..8555577f5 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -19,6 +19,7 @@ #include "usrp_commands.h" #include "fpga_regs_standard.h" #include "fpga_regs_common.h" +#include "usrp_i2c_addr.h" #include #include #include @@ -321,11 +322,18 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) { if(key.type() == typeid(std::string)) { if(key.as() == "load_eeprom") { - std::string usrp1_fpga_image = val.as(); - std::cout << "USRP1 EEPROM image: " << usrp1_fpga_image << std::endl; + std::string usrp1_eeprom_image = val.as(); + std::cout << "USRP1 EEPROM image: " << usrp1_eeprom_image << std::endl; _ctrl_transport->usrp_load_eeprom(val.as()); } + if(key.as() == "serial") { + std::string sernum = val.as(); + uhd::byte_vector_t buf(sernum.begin(), sernum.end()); + buf.insert(buf.begin(), 248); + _iface->write_i2c(I2C_DEV_EEPROM, buf); + } + return; } diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 9d788b06c..48f91aaa7 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -42,10 +42,14 @@ TARGET_LINK_LIBRARIES(usrp_burn_db_eeprom uhd) ADD_EXECUTABLE(usrp_init_eeprom usrp_init_eeprom.cpp) TARGET_LINK_LIBRARIES(usrp_init_eeprom uhd) +ADD_EXECUTABLE(usrp_serial_burner usrp_serial_burner.cpp) +TARGET_LINK_LIBRARIES(usrp_serial_burner uhd) + INSTALL(TARGETS usrp2_addr_burner usrp_burn_db_eeprom usrp_init_eeprom + usrp_serial_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils ) diff --git a/host/utils/usrp_init_eeprom.cpp b/host/utils/usrp_init_eeprom.cpp index 28c7c5745..b05e400b1 100644 --- a/host/utils/usrp_init_eeprom.cpp +++ b/host/utils/usrp_init_eeprom.cpp @@ -28,7 +28,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ po::options_description desc("Allowed options"); desc.add_options() ("help", "help message") - ("image", po::value(), "IHX image file") + ("image", po::value(), "BIN image file") ; po::variables_map vm; diff --git a/host/utils/usrp_serial_burner.cpp b/host/utils/usrp_serial_burner.cpp new file mode 100644 index 000000000..cdb6eff65 --- /dev/null +++ b/host/utils/usrp_serial_burner.cpp @@ -0,0 +1,74 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("old", po::value(), "old USRP serial number (optional)") + ("new", po::value(), "new USRP serial number") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("USRP serial burner %s") % desc << std::endl; + return ~0; + } + + if(vm.count("new") == 0) { + std::cout << "error: must input --new arg" << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + device_addr["type"] = "usrp1"; + if(vm.count("old")) device_addr["serial"] = vm["old"].as(); + + //find and create a control transport to do the writing. + + uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); + + if (found_addrs.size() == 0){ + std::cerr << "No USRP devices found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < found_addrs.size(); i++){ + uhd::device::sptr dev = uhd::device::make(found_addrs[i]); + wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; + std::cout << "Writing serial number..." << std::endl; + mb[std::string("serial")] = vm["new"].as(); + } + + + std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; + return 0; +} -- cgit v1.2.3 From 4c7a66cfa0b84955fcd34b0e356c1141b21a7e17 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 31 Aug 2010 17:52:10 -0700 Subject: Added serial number read. Renamed the usrp1-specific utilities. --- host/lib/usrp/usrp1/mboard_impl.cpp | 15 ++++++++ host/utils/CMakeLists.txt | 12 +++--- host/utils/usrp1_init_eeprom.cpp | 69 ++++++++++++++++++++++++++++++++++ host/utils/usrp1_serial_burner.cpp | 75 +++++++++++++++++++++++++++++++++++++ host/utils/usrp_init_eeprom.cpp | 69 ---------------------------------- host/utils/usrp_serial_burner.cpp | 74 ------------------------------------ 6 files changed, 165 insertions(+), 149 deletions(-) create mode 100644 host/utils/usrp1_init_eeprom.cpp create mode 100644 host/utils/usrp1_serial_burner.cpp delete mode 100644 host/utils/usrp_init_eeprom.cpp delete mode 100644 host/utils/usrp_serial_burner.cpp (limited to 'host/lib/usrp/usrp1/mboard_impl.cpp') diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index 8555577f5..a90532cb8 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include using namespace uhd; @@ -251,6 +252,20 @@ void usrp1_impl::mboard_get(const wax::obj &key_, wax::obj &val) { named_prop_t key = named_prop_t::extract(key_); + if(key_.type() == typeid(std::string)) { + if(key.as() == "serial") { + uhd::byte_vector_t buf; + buf.insert(buf.begin(), 248); + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + _iface->write_i2c(I2C_DEV_EEPROM, buf); + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + buf = _iface->read_i2c(I2C_DEV_EEPROM, 8); + val = std::string(buf.begin(), buf.end()); + } + + return; + } + //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 48f91aaa7..a95864ca7 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -39,17 +39,17 @@ TARGET_LINK_LIBRARIES(usrp2_addr_burner uhd) ADD_EXECUTABLE(usrp_burn_db_eeprom usrp_burn_db_eeprom.cpp) TARGET_LINK_LIBRARIES(usrp_burn_db_eeprom uhd) -ADD_EXECUTABLE(usrp_init_eeprom usrp_init_eeprom.cpp) -TARGET_LINK_LIBRARIES(usrp_init_eeprom uhd) +ADD_EXECUTABLE(usrp1_init_eeprom usrp1_init_eeprom.cpp) +TARGET_LINK_LIBRARIES(usrp1_init_eeprom uhd) -ADD_EXECUTABLE(usrp_serial_burner usrp_serial_burner.cpp) -TARGET_LINK_LIBRARIES(usrp_serial_burner uhd) +ADD_EXECUTABLE(usrp1_serial_burner usrp1_serial_burner.cpp) +TARGET_LINK_LIBRARIES(usrp1_serial_burner uhd) INSTALL(TARGETS usrp2_addr_burner usrp_burn_db_eeprom - usrp_init_eeprom - usrp_serial_burner + usrp1_init_eeprom + usrp1_serial_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils ) diff --git a/host/utils/usrp1_init_eeprom.cpp b/host/utils/usrp1_init_eeprom.cpp new file mode 100644 index 000000000..b05e400b1 --- /dev/null +++ b/host/utils/usrp1_init_eeprom.cpp @@ -0,0 +1,69 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("image", po::value(), "BIN image file") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("USRP EEPROM initialization %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + device_addr["type"] = "usrp1"; + device_addr["uninit"] = "yeah"; //tell find to look for an uninitialized FX2 + + //find and create a control transport to do the writing. + + uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); + + if (found_addrs.size() == 0){ + std::cerr << "No uninitialized USRP devices found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < found_addrs.size(); i++){ + std::cout << "Writing EEPROM data..." << std::endl; + //uhd::device_addrs_t devs = uhd::device::find(found_addrs[i]); + uhd::device::sptr dev = uhd::device::make(found_addrs[i]); + wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; + mb[std::string("load_eeprom")] = vm["image"].as(); + } + + + std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; + return 0; +} diff --git a/host/utils/usrp1_serial_burner.cpp b/host/utils/usrp1_serial_burner.cpp new file mode 100644 index 000000000..bf7d3d3bb --- /dev/null +++ b/host/utils/usrp1_serial_burner.cpp @@ -0,0 +1,75 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("old", po::value(), "old USRP serial number (optional)") + ("new", po::value(), "new USRP serial number") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("USRP serial burner %s") % desc << std::endl; + return ~0; + } + + if(vm.count("new") == 0) { + std::cout << "error: must input --new arg" << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + device_addr["type"] = "usrp1"; + if(vm.count("old")) device_addr["serial"] = vm["old"].as(); + + //find and create a control transport to do the writing. + + uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); + + if (found_addrs.size() == 0){ + std::cerr << "No USRP devices found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < found_addrs.size(); i++){ + uhd::device::sptr dev = uhd::device::make(found_addrs[i]); + wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; + std::cout << "Writing serial number..." << std::endl; + mb[std::string("serial")] = vm["new"].as(); + std::cout << "Reading back serial number: " << mb[std::string("serial")].as() << std::endl; + } + + + std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; + return 0; +} diff --git a/host/utils/usrp_init_eeprom.cpp b/host/utils/usrp_init_eeprom.cpp deleted file mode 100644 index b05e400b1..000000000 --- a/host/utils/usrp_init_eeprom.cpp +++ /dev/null @@ -1,69 +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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("image", po::value(), "BIN image file") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("USRP EEPROM initialization %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - device_addr["type"] = "usrp1"; - device_addr["uninit"] = "yeah"; //tell find to look for an uninitialized FX2 - - //find and create a control transport to do the writing. - - uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); - - if (found_addrs.size() == 0){ - std::cerr << "No uninitialized USRP devices found" << std::endl; - return ~0; - } - - for (size_t i = 0; i < found_addrs.size(); i++){ - std::cout << "Writing EEPROM data..." << std::endl; - //uhd::device_addrs_t devs = uhd::device::find(found_addrs[i]); - uhd::device::sptr dev = uhd::device::make(found_addrs[i]); - wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; - mb[std::string("load_eeprom")] = vm["image"].as(); - } - - - std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; - return 0; -} diff --git a/host/utils/usrp_serial_burner.cpp b/host/utils/usrp_serial_burner.cpp deleted file mode 100644 index cdb6eff65..000000000 --- a/host/utils/usrp_serial_burner.cpp +++ /dev/null @@ -1,74 +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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("old", po::value(), "old USRP serial number (optional)") - ("new", po::value(), "new USRP serial number") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("USRP serial burner %s") % desc << std::endl; - return ~0; - } - - if(vm.count("new") == 0) { - std::cout << "error: must input --new arg" << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - device_addr["type"] = "usrp1"; - if(vm.count("old")) device_addr["serial"] = vm["old"].as(); - - //find and create a control transport to do the writing. - - uhd::device_addrs_t found_addrs = uhd::device::find(device_addr); - - if (found_addrs.size() == 0){ - std::cerr << "No USRP devices found" << std::endl; - return ~0; - } - - for (size_t i = 0; i < found_addrs.size(); i++){ - uhd::device::sptr dev = uhd::device::make(found_addrs[i]); - wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD]; - std::cout << "Writing serial number..." << std::endl; - mb[std::string("serial")] = vm["new"].as(); - } - - - std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl; - return 0; -} -- cgit v1.2.3