From 4a6543bd481370ae924ca90c325d5cd5b2dfe692 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 23 Jul 2010 22:55:30 -0700 Subject: usrp2: added codec impl for codec properties to usrp2 --- host/lib/usrp/usrp2/codec_impl.cpp | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 host/lib/usrp/usrp2/codec_impl.cpp (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp new file mode 100644 index 000000000..b9d51abf5 --- /dev/null +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -0,0 +1,96 @@ +// +// 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 "usrp2_impl.hpp" +#include +#include + +using namespace uhd; +using namespace uhd::usrp; + +/*********************************************************************** + * Helper Methods + **********************************************************************/ +void usrp2_mboard_impl::codec_init(void){ + //make proxies + _rx_codec_proxy = wax_obj_proxy::make( + boost::bind(&usrp2_mboard_impl::rx_codec_get, this, _1, _2), + boost::bind(&usrp2_mboard_impl::rx_codec_set, this, _1, _2) + ); + _tx_codec_proxy = wax_obj_proxy::make( + boost::bind(&usrp2_mboard_impl::tx_codec_get, this, _1, _2), + boost::bind(&usrp2_mboard_impl::tx_codec_set, this, _1, _2) + ); +} + +/*********************************************************************** + * RX Codec Properties + **********************************************************************/ +void usrp2_mboard_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_); + + //handle the get request conditioned on the key + switch(key.as()){ + case CODEC_PROP_NAME: + val = std::string("usrp2 adc"); + return; + + case CODEC_PROP_OTHERS: + val = prop_names_t(); + return; + + case CODEC_PROP_GAIN_NAMES: + val = prop_names_t(); //no gain elements to be controlled + return; + + default: UHD_THROW_PROP_GET_ERROR(); + } +} + +void usrp2_mboard_impl::rx_codec_set(const wax::obj &, const wax::obj &){ + UHD_THROW_PROP_SET_ERROR(); +} + +/*********************************************************************** + * TX Codec Properties + **********************************************************************/ +void usrp2_mboard_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_); + + //handle the get request conditioned on the key + switch(key.as()){ + case CODEC_PROP_NAME: + val = std::string("usrp2 dac - ad9777"); + return; + + case CODEC_PROP_OTHERS: + val = prop_names_t(); + return; + + case CODEC_PROP_GAIN_NAMES: + val = prop_names_t(); //no gain elements to be controlled + return; + + default: UHD_THROW_PROP_GET_ERROR(); + } +} + +void usrp2_mboard_impl::tx_codec_set(const wax::obj &, const wax::obj &){ + UHD_THROW_PROP_SET_ERROR(); +} -- cgit v1.2.3 From 02f5347c71f53f11162796b70f15fe74adcc3aa0 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 27 Jul 2010 13:56:59 -0700 Subject: Added gain support for USRP2+ ADC. --- host/lib/usrp/usrp2/codec_ctrl.cpp | 27 ++++++++++++---- host/lib/usrp/usrp2/codec_ctrl.hpp | 13 ++++++++ host/lib/usrp/usrp2/codec_impl.cpp | 63 ++++++++++++++++++++++++++++++++++++-- host/lib/usrp/usrp2/usrp2_impl.hpp | 2 ++ 4 files changed, 96 insertions(+), 9 deletions(-) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 107894d2a..b8f1df799 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -22,6 +22,7 @@ #include #include #include +#include static const bool codec_ctrl_debug = false; @@ -79,15 +80,29 @@ public: if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) { //if we're on a USRP2 _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_OFF); } else { //we're on a USRP2+ -// _ads62p44_regs.reset = 1; -// this->send_ads62p44_reg(0x00); //issue a reset to the ADC - //everything else should be pretty much default, i think -// _ads62p44_regs.decimation = DECIMATION_DECIMATE_1; - - + //send a global power-down to the ADC here... it will get lifted on reset + _ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_GLOBAL_PD; + this->send_ads62p44_reg(0x14); } } + void set_rx_digital_gain(float gain) { //combine fine/correction digital gains + if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + int fine_gain = int(gain/0.5); + _ads62p44_regs.fine_gain = fine_gain; //hey what about when it calls for 6.5dB? + _ads62p44_regs.gain_correction = (gain - (double(fine_gain) * 0.5)) / 0.05; + this->send_ads62p44_reg(0x17); + this->send_ads62p44_reg(0x1A); + } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 + } + + void set_rx_analog_gain(bool gain) { //turns on/off analog 3.5dB preamp + if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + _ads62p44_regs.coarse_gain = gain ? ads62p44_regs_t::COARSE_GAIN_3_5DB : ads62p44_regs_t::COARSE_GAIN_0DB; + this->send_ads62p44_reg(0x14); + } else UHD_THROW_INVALID_CODE_PATH(); + } + private: ad9777_regs_t _ad9777_regs; ads62p44_regs_t _ads62p44_regs; diff --git a/host/lib/usrp/usrp2/codec_ctrl.hpp b/host/lib/usrp/usrp2/codec_ctrl.hpp index ad014e0e1..d485690f6 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.hpp +++ b/host/lib/usrp/usrp2/codec_ctrl.hpp @@ -33,6 +33,19 @@ public: */ static sptr make(usrp2_iface::sptr iface); + /*! + * Set the analog preamplifier on the USRP2+ ADC (ADS62P44). + * \param gain enable or disable the 3.5dB preamp + */ + + virtual void set_rx_analog_gain(bool gain) = 0; + + /*! + * Set the digital gain on the USRP2+ ADC (ADS62P44). + * \param gain from 0-6.5dB + */ + + virtual void set_rx_digital_gain(float gain) = 0; }; #endif /* INCLUDED_CODEC_CTRL_HPP */ diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index b9d51abf5..b246a35f8 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -17,10 +17,22 @@ #include "usrp2_impl.hpp" #include +#include +#include #include +#include +#include +#include using namespace uhd; using namespace uhd::usrp; +using namespace boost::assign; + +//this only applies to USRP2P +static const uhd::dict codec_rx_gain_ranges = map_list_of + ("analog", gain_range_t(0, 3.5, float(3.5))) + ("digital", gain_range_t(0, 6.45, float(0.05))); + /*********************************************************************** * Helper Methods @@ -55,17 +67,62 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ return; case CODEC_PROP_GAIN_NAMES: - val = prop_names_t(); //no gain elements to be controlled + if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + val = prop_names_t(codec_rx_gain_ranges.keys()); + } else val = prop_names_t(); + return; + + case CODEC_PROP_GAIN_I: + case CODEC_PROP_GAIN_Q: + assert_has(_codec_rx_gains.keys(), name, "codec rx gain name"); + val = _codec_rx_gains[name]; return; default: UHD_THROW_PROP_GET_ERROR(); } } -void usrp2_mboard_impl::rx_codec_set(const wax::obj &, const wax::obj &){ - UHD_THROW_PROP_SET_ERROR(); +void usrp2_mboard_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_); + + float gain; + + switch(key.as()) { + case CODEC_PROP_GAIN_I: + case CODEC_PROP_GAIN_Q: + if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P + + gain = val.as(); + this->rx_codec_set_gain(gain, name); //okay. we can either have ONE gain and let codec_ctrl do the sorting between analog/digital gains, or we can have TWO gains and do the priority somewhere else. + return; + + default: + UHD_THROW_PROP_SET_ERROR(); + } } +/*********************************************************************** + * Helper function to set RX codec gain + ***********************************************************************/ + +void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){ + assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain name"); + + _codec_rx_gains[name] = gain; + + if(name == "analog") { + _codec_ctrl->set_rx_analog_gain(gain > 0); //just turn it on or off + return; + } + if(name == "digital") { + _codec_ctrl->set_rx_digital_gain(gain); + return; + } + UHD_THROW_PROP_SET_ERROR(); +} + + /*********************************************************************** * TX Codec Properties **********************************************************************/ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index eb61609c2..70c3705c9 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -169,6 +169,8 @@ private: 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_set_gain(float, const std::string &); + uhd::dict _codec_rx_gains; //properties interface for rx dboard void rx_dboard_get(const wax::obj &, wax::obj &); -- cgit v1.2.3 From c348a98c8004e7ac9d28231ae80dadef415440ef Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 28 Jul 2010 11:48:00 -0700 Subject: Added gain range property to rx_codec_get. --- host/lib/usrp/usrp2/codec_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index b246a35f8..5cc7a47ec 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -78,6 +78,11 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ val = _codec_rx_gains[name]; return; + case CODEC_PROP_GAIN_RANGE: + assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain range name"); + val = codec_rx_gain_ranges[name]; + return; + default: UHD_THROW_PROP_GET_ERROR(); } } -- cgit v1.2.3 From 8784cf70df692066f224ddf58d624b148ea98301 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 28 Jul 2010 15:40:43 -0700 Subject: ADC gain control works. Separated digital gain and fine gain correction into separate buckets. Changed the rounding policy of gain_group to floor() rather than round(). --- host/lib/gain_group.cpp | 3 +-- host/lib/usrp/usrp2/codec_ctrl.cpp | 12 ++++++++---- host/lib/usrp/usrp2/codec_ctrl.hpp | 10 +++++++++- host/lib/usrp/usrp2/codec_impl.cpp | 11 ++++++++--- 4 files changed, 26 insertions(+), 10 deletions(-) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/gain_group.cpp b/host/lib/gain_group.cpp index 5a14fa96f..d5d7730fd 100644 --- a/host/lib/gain_group.cpp +++ b/host/lib/gain_group.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -109,7 +108,7 @@ public: //fill in the largest step sizes first that are less than the remainder BOOST_FOREACH(size_t i, indexes_step_size_dec){ const gain_range_t range = all_fcns.at(i).get_range(); - float additional_gain = range.step*rint( + float additional_gain = range.step*int( std::clip(gain_bucket.at(i) + gain_left_to_distribute, range.min, range.max )/range.step) - gain_bucket.at(i); gain_bucket.at(i) += additional_gain; diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 2e645dcec..e5be62205 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -86,12 +86,16 @@ public: } } - void set_rx_digital_gain(float gain) { //combine fine/correction digital gains + void set_rx_digital_gain(float gain) { //fine digital gain if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { - int fine_gain = int(gain/0.5); - _ads62p44_regs.fine_gain = fine_gain; //hey what about when it calls for 6.5dB? - _ads62p44_regs.gain_correction = (gain - (double(fine_gain) * 0.5)) / 0.05; + _ads62p44_regs.fine_gain = int(gain/0.5); this->send_ads62p44_reg(0x17); + } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 + } + + void set_rx_digital_fine_gain(float gain) { //gain correction + if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + _ads62p44_regs.gain_correction = int(gain / 0.05); this->send_ads62p44_reg(0x1A); } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 } diff --git a/host/lib/usrp/usrp2/codec_ctrl.hpp b/host/lib/usrp/usrp2/codec_ctrl.hpp index d485690f6..57a37b94b 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.hpp +++ b/host/lib/usrp/usrp2/codec_ctrl.hpp @@ -42,10 +42,18 @@ public: /*! * Set the digital gain on the USRP2+ ADC (ADS62P44). - * \param gain from 0-6.5dB + * \param gain from 0-6dB */ virtual void set_rx_digital_gain(float gain) = 0; + + /*! + * Set the digital gain correction on the USRP2+ ADC (ADS62P44). + * \param gain from 0-0.5dB + */ + + virtual void set_rx_digital_fine_gain(float gain) = 0; + }; #endif /* INCLUDED_CODEC_CTRL_HPP */ diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 5cc7a47ec..969b5b4b9 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -30,8 +30,9 @@ using namespace boost::assign; //this only applies to USRP2P static const uhd::dict codec_rx_gain_ranges = map_list_of - ("analog", gain_range_t(0, 3.5, float(3.5))) - ("digital", gain_range_t(0, 6.45, float(0.05))); + ("analog", gain_range_t(0, 3.5, 3.5)) + ("digital", gain_range_t(0, 6.0, 0.5)) + ("digital-fine", gain_range_t(0, 0.5, 0.05)); /*********************************************************************** @@ -99,7 +100,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P gain = val.as(); - this->rx_codec_set_gain(gain, name); //okay. we can either have ONE gain and let codec_ctrl do the sorting between analog/digital gains, or we can have TWO gains and do the priority somewhere else. + this->rx_codec_set_gain(gain, name); return; default: @@ -124,6 +125,10 @@ void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){ _codec_ctrl->set_rx_digital_gain(gain); return; } + if(name == "digital-fine") { + _codec_ctrl->set_rx_digital_fine_gain(gain); + return; + } UHD_THROW_PROP_SET_ERROR(); } -- cgit v1.2.3 From 0019bb05437702a6727d3632c6efc6a600bb4aa2 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 25 Aug 2010 18:55:09 -0700 Subject: Change to get codec_impl to compile, dur. Changed memory map to correspond to new tx_policy code. --- firmware/microblaze/usrp2p/memory_map.h | 4 ++-- host/lib/usrp/usrp2/codec_impl.cpp | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index addcf67d4..8d0d0c365 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -417,12 +417,12 @@ typedef struct { // crazy order that matches the labels on the case #define LED_A (1 << 2) -#define LED_B (1 << 5) +#define LED_B (1 << 0) #define LED_E (1 << 3) #define LED_D (1 << 1) #define LED_C (1 << 4) // LED_F // controlled by CPLD -#define LED_RJ45 (1 << 0) +#define LED_RJ45 (1 << 5) #define output_regs ((output_regs_t *) MISC_OUTPUT_BASE) diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index f7f9ce2d5..db98e50ab 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -53,7 +53,8 @@ void usrp2_mboard_impl::codec_init(void){ /*********************************************************************** * RX Codec Properties **********************************************************************/ -void usrp2_mboard_impl::rx_codec_get(const wax::obj &key, wax::obj &val){ +void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ @@ -73,23 +74,21 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key, wax::obj &val){ case CODEC_PROP_GAIN_I: case CODEC_PROP_GAIN_Q: - assert_has(_codec_rx_gains.keys(), name, "codec rx gain name"); - val = _codec_rx_gains[name]; + assert_has(_codec_rx_gains.keys(), key.name, "codec rx gain name"); + val = _codec_rx_gains[key.name]; return; case CODEC_PROP_GAIN_RANGE: - assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain range name"); - val = codec_rx_gain_ranges[name]; - return; + assert_has(codec_rx_gain_ranges.keys(), key.name, "codec rx gain range name"); + val = codec_rx_gain_ranges[key.name]; + return; default: UHD_THROW_PROP_GET_ERROR(); } } void usrp2_mboard_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_); float gain; switch(key.as()) { @@ -98,7 +97,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P gain = val.as(); - this->rx_codec_set_gain(gain, name); + this->rx_codec_set_gain(gain, key.name); return; default: @@ -134,7 +133,8 @@ void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){ /*********************************************************************** * TX Codec Properties **********************************************************************/ -void usrp2_mboard_impl::tx_codec_get(const wax::obj &key, wax::obj &val){ +void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){ + named_prop_t key = named_prop_t::extract(key_); //handle the get request conditioned on the key switch(key.as()){ -- cgit v1.2.3 From 5982ec4ee2c6f9efca1c5068e42dc38b822df7dc Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 12 Oct 2010 14:46:41 -0700 Subject: USRP2P: This is surprisingly involved. Adding a consistent interface to deal with hardware revisions. --- firmware/microblaze/usrp2/Makefile.am | 3 +- firmware/microblaze/usrp2p/Makefile.am | 3 +- host/include/uhd/usrp/mboard_rev.hpp | 90 ++++++++++++++++++++++++++++++++++ host/lib/usrp/mboard_rev.cpp | 68 +++++++++++++++++++++++++ host/lib/usrp/usrp2/clock_ctrl.cpp | 36 +++++++------- host/lib/usrp/usrp2/codec_impl.cpp | 4 +- host/lib/usrp/usrp2/fw_common.h | 3 +- host/lib/usrp/usrp2/mboard_impl.cpp | 30 ++++++++---- host/lib/usrp/usrp2/usrp2_clk_regs.hpp | 15 ++++-- host/lib/usrp/usrp2/usrp2_iface.cpp | 4 +- host/lib/usrp/usrp2/usrp2_iface.hpp | 6 +-- host/lib/usrp/usrp2/usrp2_impl.hpp | 1 - host/lib/usrp/usrp2/usrp2_regs.hpp | 2 - 13 files changed, 219 insertions(+), 46 deletions(-) create mode 100644 host/include/uhd/usrp/mboard_rev.hpp create mode 100644 host/lib/usrp/mboard_rev.cpp (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/firmware/microblaze/usrp2/Makefile.am b/firmware/microblaze/usrp2/Makefile.am index 17f7a4744..e3f57728a 100644 --- a/firmware/microblaze/usrp2/Makefile.am +++ b/firmware/microblaze/usrp2/Makefile.am @@ -22,9 +22,10 @@ AM_CFLAGS = \ AM_LDFLAGS = \ $(COMMON_LFLAGS) \ - libusrp2.a \ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x0050 \ -Wl,-defsym -Wl,_STACK_SIZE=3072 + +LDADD = libusrp2.a ######################################################################## # USRP2 specific library and programs diff --git a/firmware/microblaze/usrp2p/Makefile.am b/firmware/microblaze/usrp2p/Makefile.am index 0d0b60437..a5df3ff08 100644 --- a/firmware/microblaze/usrp2p/Makefile.am +++ b/firmware/microblaze/usrp2p/Makefile.am @@ -22,10 +22,11 @@ AM_CFLAGS = \ AM_LDFLAGS = \ $(COMMON_LFLAGS) \ - libusrp2p.a \ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x8050 \ -Wl,-defsym -Wl,_STACK_SIZE=3072 +LDADD = libusrp2p.a + #all of this here is to relocate the hardware vectors to somewhere normal. RELOCATE_ARGS = \ --change-section-address .vectors.sw_exception+0x8000 \ diff --git a/host/include/uhd/usrp/mboard_rev.hpp b/host/include/uhd/usrp/mboard_rev.hpp new file mode 100644 index 000000000..5307d80c1 --- /dev/null +++ b/host/include/uhd/usrp/mboard_rev.hpp @@ -0,0 +1,90 @@ +// +// 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 . +// + +#ifndef INCLUDED_UHD_USRP_MBOARD_REV_HPP +#define INCLUDED_UHD_USRP_MBOARD_REV_HPP + +#include +#include +#include +#include + +namespace uhd{ namespace usrp{ + + class UHD_API mboard_rev_t : boost::equality_comparable{ + public: + /*! + * Create a mboard rev from an integer. + * \param rev the integer representation + */ + mboard_rev_t(boost::uint16_t rev = 0xffff); + + /*! + * Obtain a mboard rev that represents an invalid/uninit mboard ID + * \return the mboard rev with the 0xffff rev. + */ + static mboard_rev_t none(void); + + /*! + * Create a new mboard rev from an integer representation. + * \param uint16 an unsigned 16 bit integer + * \return a new mboard rev containing the integer + */ + static mboard_rev_t from_uint16(boost::uint16_t uint16); + + /*! + * Get the mboard rev represented as an integer. + * \return an unsigned 16 bit integer representation + */ + boost::uint16_t to_uint16(void) const; + + /*! + * Create a new mboard rev from a string representation. + * If the string has a 0x prefix, it will be parsed as hex. + * \param string a numeric string, possibly hex + * \return a new dboard id containing the integer + */ + static mboard_rev_t from_string(const std::string &string); + + /*! + * Get the mboard rev represented as an integer. + * \return a hex string representation with 0x prefix + */ + std::string to_string(void) const; + + /*! + * Get the pretty print representation of this mboard rev. + * \return a string with the mboard name and rev number + */ + std::string to_pp_string(void) const; + + private: + boost::uint16_t _rev; //internal representation + }; + + /*! + * Comparator operator overloaded for mboard rev. + * The boost::equality_comparable provides the !=. + * \param lhs the dboard id to the left of the operator + * \param rhs the dboard id to the right of the operator + * \return true when the mboard revs are equal + */ + UHD_API bool operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs); + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_MBOARD_REV_HPP */ diff --git a/host/lib/usrp/mboard_rev.cpp b/host/lib/usrp/mboard_rev.cpp new file mode 100644 index 000000000..8206d12af --- /dev/null +++ b/host/lib/usrp/mboard_rev.cpp @@ -0,0 +1,68 @@ +// +// 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 + +using namespace uhd::usrp; + +mboard_rev_t::mboard_rev_t(boost::uint16_t id){ + _rev = rev; +} + +mboard_rev_t mboard_rev_t::none(void){ + return mboard_rev_t(); +} + +mboard_rev_t mboard_rev_t::from_uint16(boost::uint16_t uint16){ + return mboard_rev_t(uint16); +} + +boost::uint16_t mboard_rev_t::to_uint16(void) const{ + return _rev; +} + +//used with lexical cast to parse a hex string +template struct to_hex{ + T value; + operator T() const {return value;} + friend std::istream& operator>>(std::istream& in, to_hex& out){ + in >> std::hex >> out.value; + return in; + } +}; + +mboard_rev_t mboard_rev_t::from_string(const std::string &string){ + if (string.substr(0, 2) == "0x"){ + return mboard_rev_t::from_uint16(boost::lexical_cast >(string)); + } + return mboard_rev_t::from_uint16(boost::lexical_cast(string)); +} + +std::string mboard_rev_t::to_string(void) const{ + return str(boost::format("0x%04x") % this->to_uint16()); +} + +//Note: to_pp_string is implemented in the dboard manager +//because it needs access to the dboard registration table + +bool uhd::usrp::operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs){ + return lhs.to_uint16() == rhs.to_uint16(); +} diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index c3dc4917e..8887faf12 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -17,6 +17,7 @@ #include "clock_ctrl.hpp" #include "ad9510_regs.hpp" +#include #include "usrp2_regs.hpp" //spi slave constants #include "usrp2_clk_regs.hpp" #include @@ -31,9 +32,7 @@ using namespace uhd; class usrp2_clock_ctrl_impl : public usrp2_clock_ctrl{ public: usrp2_clock_ctrl_impl(usrp2_iface::sptr iface){ - _iface = iface; //_iface has get_hw_rev(), which lets us know if it's a USRP2+ (>=0x80) or USRP2 (<0x80). - - clk_regs = usrp2_clk_regs_t(_iface->get_hw_rev()); + clk_regs = usrp2_clk_regs_t(iface->get_hw_rev()); _ad9510_regs.cp_current_setting = ad9510_regs_t::CP_CURRENT_SETTING_3_0MA; this->write_reg(clk_regs.pll_3); @@ -86,16 +85,13 @@ public: } void enable_mimo_clock_out(bool enb){ - //FIXME TODO put this revision read in a common place - boost::uint8_t rev_hi = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, 1).at(0); - //calculate the low and high dividers size_t divider = size_t(this->get_master_clock_rate()/10e6); size_t high = divider/2; size_t low = divider - high; - switch(rev_hi){ - case 3: //clock 2 + switch(clk_regs.exp){ + case 2: //U2 rev 3 _ad9510_regs.power_down_lvpecl_out2 = enb? ad9510_regs_t::POWER_DOWN_LVPECL_OUT2_NORMAL : ad9510_regs_t::POWER_DOWN_LVPECL_OUT2_SAFE_PD; @@ -104,11 +100,9 @@ public: _ad9510_regs.divider_low_cycles_out2 = low - 1; _ad9510_regs.divider_high_cycles_out2 = high - 1; _ad9510_regs.bypass_divider_out2 = 0; - this->write_reg(0x3e); - this->write_reg(0x4c); break; - case 4: //clock 5 + case 5: //U2 rev 4 _ad9510_regs.power_down_lvds_cmos_out5 = enb? 0 : 1; _ad9510_regs.lvds_cmos_select_out5 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT5_LVDS; _ad9510_regs.output_level_lvds_out5 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT5_1_75MA; @@ -116,19 +110,26 @@ public: _ad9510_regs.divider_low_cycles_out5 = low - 1; _ad9510_regs.divider_high_cycles_out5 = high - 1; _ad9510_regs.bypass_divider_out5 = 0; - this->write_reg(0x41); - this->write_reg(0x52); + break; + + case 6: //U2+ + _ad9510_regs.power_down_lvds_cmos_out6 = enb? 0 : 1; + _ad9510_regs.lvds_cmos_select_out6 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT6_LVDS; + _ad9510_regs.output_level_lvds_out6 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT6_1_75MA; + //set the registers (divider - 1) + _ad9510_regs.divider_low_cycles_out6 = low - 1; + _ad9510_regs.divider_high_cycles_out6 = high - 1; + _ad9510_regs.bypass_divider_out5 = 0; break; - //TODO FIXME do i want to throw, what about uninitialized boards? - //default: throw std::runtime_error("unknown rev hi in mboard eeprom"); - default: std::cerr << "unknown rev hi: " << rev_hi << std::endl; + default: } + this->write_reg(clk_regs.output(clk_regs.exp)); + this->write_reg(clk_regs.div_lo(clk_regs.exp)); this->update_regs(); } //uses output clock 7 (cmos) - //this clock is the same between USRP2 and USRP2+ and so this fn does not get a switch statement void enable_rx_dboard_clock(bool enb){ _ad9510_regs.power_down_lvds_cmos_out7 = enb? 0 : 1; _ad9510_regs.lvds_cmos_select_out7 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT7_CMOS; @@ -297,7 +298,6 @@ private: } usrp2_clk_regs_t clk_regs; - usrp2_iface::sptr _iface; ad9510_regs_t _ad9510_regs; }; diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index db98e50ab..04a11d922 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -67,7 +67,7 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ return; case CODEC_PROP_GAIN_NAMES: - if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().to_uint16() >= USRP2P_FIRST_HW_REV) { val = prop_names_t(codec_rx_gain_ranges.keys()); } else val = prop_names_t(); return; @@ -94,7 +94,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()) { case CODEC_PROP_GAIN_I: case CODEC_PROP_GAIN_Q: - if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P + if(_iface->get_hw_rev().to_uint16() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P gain = val.as(); this->rx_codec_set_gain(gain, key.name); diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 67955c831..6c9596092 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -55,8 +55,7 @@ extern "C" { //////////////////////////////////////////////////////////////////////// // EEPROM Layout //////////////////////////////////////////////////////////////////////// -#define USRP2_EE_MBOARD_REV_LSB 0x00 //1 byte -#define USRP2_EE_MBOARD_REV_MSB 0x01 //1 byte +#define USRP2_EE_MBOARD_REV 0x00 //2 bytes, little-endian (historic, don't blame me) #define USRP2_EE_MBOARD_MAC_ADDR 0x02 //6 bytes #define USRP2_EE_MBOARD_IP_ADDR 0x0C //uint32, big-endian #define USRP2_EE_MBOARD_BOOTLOADER_FLAGS 0xF7 diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index e0e0d726e..6ee6d03a1 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,9 @@ usrp2_mboard_impl::usrp2_mboard_impl( _iface = usrp2_iface::make(ctrl_transport); //extract the mboard rev numbers - _rev_lo = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_LSB, 1).at(0); - _rev_hi = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, 1).at(0); - - //set the device revision (USRP2 or USRP2+) based on the above - _iface->set_hw_rev((_rev_hi << 8) | _rev_lo); - + byte_vector_t rev_bytes = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, 2); + _iface->set_hw_rev(mboard_rev_t::from_uint16(rev_bytes.at(0) | (revbytes.at(1) << 8))); + //contruct the interfaces to mboard perifs _clock_ctrl = usrp2_clock_ctrl::make(_iface); _codec_ctrl = usrp2_codec_ctrl::make(_iface); @@ -224,12 +222,17 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ val = boost::asio::ip::address_v4(bytes).to_string(); return; } - } + + if (key.as() == "hw-rev"){ + //extract the mboard rev numbers + val = _iface->get_hw_rev().to_string(); + return; + } //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = str(boost::format("usrp2 mboard%d - rev %d:%d") % _index % _rev_hi % _rev_lo); + val = str(boost::format("usrp2 mboard%d - rev %s") % _index % _iface->get_hw_rev().to_string()); return; case MBOARD_PROP_OTHERS:{ @@ -321,9 +324,18 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_IP_ADDR, bytes); return; } + + if (key.as() == "hw-rev"){ + mboard_rev_t rev = mboard_rev_t::from_string(val.as()); + byte_vector_t revbytes(2); + revbytes(1) = rev.to_uint16() >> 8; + revbytes(0) = rev.to_uint16() & 0xff; + _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, revbytes); + _iface->set_hw_rev(rev); //so the iface knows what rev it is + return; } - //handle the get request conditioned on the key + //handle the set request conditioned on the key switch(key.as()){ case MBOARD_PROP_CLOCK_CONFIG: diff --git a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp index d057fb342..edbdfa15d 100644 --- a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp @@ -18,19 +18,24 @@ #ifndef INCLUDED_USRP2_CLK_REGS_HPP #define INCLUDED_USRP2_CLK_REGS_HPP +#include #include "usrp2_regs.hpp" class usrp2_clk_regs_t { public: usrp2_clk_regs_t(void) { ; } - usrp2_clk_regs_t(int hw_rev) { + usrp2_clk_regs_t(uhd::usrp::mboard_rev_t hw_rev) { test = 0; fpga = 1; - adc = (hw_rev>=USRP2P_FIRST_HW_REV) ? 2 : 4; + adc = (hw_rev.is_usrp2p()) ? 2 : 4; dac = 3; - serdes = (hw_rev>=USRP2P_FIRST_HW_REV) ? 4 : 2; //only used by usrp2+ - tx_db = (hw_rev>=USRP2P_FIRST_HW_REV) ? 5 : 6; - exp = (hw_rev>=USRP2P_FIRST_HW_REV) ? 6 : 5; + serdes = (hw_rev.is_usrp2p()) ? 4 : 2; //only used by usrp2+ + tx_db = (hw_rev.is_usrp2p()) ? 5 : 6; + + if(hw_rev.major() == 3) exp = 2; + else if(hw_rev.major() >= 4) exp = 5; + else if(hw_rev.major() > 10) exp = 6; + rx_db = 7; } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 0771c4945..7ce5cc936 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -260,12 +260,12 @@ public: /*********************************************************************** * Get/set hardware revision **********************************************************************/ - void set_hw_rev(int rev) { + void set_hw_rev(mboard_rev_t rev) { hw_rev = rev; regs = usrp2_get_regs(rev); //might be a better place to do this } - int get_hw_rev(void) { + mboard_rev_t get_hw_rev(void) { return hw_rev; } diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 55fbfa7e4..fe2687d02 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -112,12 +112,12 @@ public: * Set the hardware revision number. Also selects the proper register set for the device. * \param rev the 16-bit revision */ - virtual void set_hw_rev(int rev) = 0; + virtual void set_hw_rev(uhd::usrp::mboard_rev_t rev) = 0; /*! Return the hardware revision number * \return hardware revision */ - virtual int get_hw_rev(void) = 0; + virtual uhd::usrp::mboard_rev_t get_hw_rev(void) = 0; /*! * Register map selected from USRP2/USRP2+. @@ -126,7 +126,7 @@ public: /*! * Hardware revision as returned by the device. */ - int hw_rev; + uhd::usrp::mboard_rev_t hw_rev; }; #endif /* INCLUDED_USRP2_IFACE_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index b81711e2b..1ebd90ca4 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -95,7 +95,6 @@ public: private: size_t _index; - int _rev_hi, _rev_lo; const size_t _recv_frame_size; //properties for this mboard diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index f74c78b7b..8dae843ab 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -18,8 +18,6 @@ #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP -//these are used to set the - #define USRP2_MISC_OUTPUT_BASE 0xD400 #define USRP2_GPIO_BASE 0xC800 #define USRP2_ATR_BASE 0xE400 -- cgit v1.2.3 From 5b4cbfe4616492d96ad1b48578cf2d94e1216bf4 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 12 Oct 2010 16:26:19 -0700 Subject: USRP2P: mboard rev works through props interface. Added usrp2_burn_mb_rev.cpp to utils. It is not installed to the utils install dir. Not all happy with the mboard_rev setup -- is_usrp2p() is too specific for a generalized mboard_rev concept. I'm not sure where else to put it so for now it stays. --- firmware/microblaze/lib/u2_init.c | 4 +- host/include/uhd/usrp/mboard_rev.hpp | 34 +++++++++++++-- host/lib/usrp/CMakeLists.txt | 1 + host/lib/usrp/mboard_rev.cpp | 29 +++++++++++-- host/lib/usrp/usrp2/clock_ctrl.cpp | 6 ++- host/lib/usrp/usrp2/codec_ctrl.cpp | 10 ++--- host/lib/usrp/usrp2/codec_impl.cpp | 4 +- host/lib/usrp/usrp2/mboard_impl.cpp | 18 ++++---- host/lib/usrp/usrp2/usrp2_iface.cpp | 4 +- host/lib/usrp/usrp2/usrp2_iface.hpp | 1 + host/lib/usrp/usrp2/usrp2_regs.cpp | 11 ++--- host/lib/usrp/usrp2/usrp2_regs.hpp | 6 ++- host/utils/CMakeLists.txt | 3 ++ host/utils/usrp2_burn_mb_rev.cpp | 82 ++++++++++++++++++++++++++++++++++++ 14 files changed, 180 insertions(+), 33 deletions(-) create mode 100644 host/utils/usrp2_burn_mb_rev.cpp (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 099aafe83..3c8f5f02a 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -35,8 +35,8 @@ unsigned char u2_hw_rev_minor; static inline void get_hw_rev(void) { - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_LSB, &u2_hw_rev_minor, 1); - ok &= eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV_MSB, &u2_hw_rev_major, 1); + bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, &u2_hw_rev_minor, 1); + ok &= eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV+1, &u2_hw_rev_major, 1); } /* diff --git a/host/include/uhd/usrp/mboard_rev.hpp b/host/include/uhd/usrp/mboard_rev.hpp index 5307d80c1..be968d01d 100644 --- a/host/include/uhd/usrp/mboard_rev.hpp +++ b/host/include/uhd/usrp/mboard_rev.hpp @@ -25,7 +25,7 @@ namespace uhd{ namespace usrp{ - class UHD_API mboard_rev_t : boost::equality_comparable{ + class UHD_API mboard_rev_t : boost::equality_comparable, boost::less_than_comparable{ public: /*! * Create a mboard rev from an integer. @@ -71,6 +71,24 @@ namespace uhd{ namespace usrp{ * \return a string with the mboard name and rev number */ std::string to_pp_string(void) const; + + /*! + * Tell you if you're USRP2 or USRP2+ + * \return true if USRP2+, false if USRP2 + */ + bool is_usrp2p(void) const; + + /*! + * Get the major revision number + * \return major revision number + */ + boost::uint8_t major(void) const; + + /*! + * Get the minor revision number + * \return minor revision number + */ + boost::uint8_t minor(void) const; private: boost::uint16_t _rev; //internal representation @@ -79,11 +97,21 @@ namespace uhd{ namespace usrp{ /*! * Comparator operator overloaded for mboard rev. * The boost::equality_comparable provides the !=. - * \param lhs the dboard id to the left of the operator - * \param rhs the dboard id to the right of the operator + * \param lhs the mboard rev to the left of the operator + * \param rhs the mboard rev to the right of the operator * \return true when the mboard revs are equal */ UHD_API bool operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs); + + /*! + * Comparator operator overloaded for mboard rev. + * The boost::less_than_comparable provides the >, <=, >=. + * \param lhs the mboard rev to the left of the operator + * \param rhs the mboard rev to the right of the operator + * \return true when lhs < rhs + */ + + UHD_API bool operator<(const mboard_rev_t &lhs, const mboard_rev_t &rhs); }} //namespace diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 69a190bfa..fd4eb1016 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -23,6 +23,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_id.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dboard_manager.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/mboard_rev.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/mimo_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp diff --git a/host/lib/usrp/mboard_rev.cpp b/host/lib/usrp/mboard_rev.cpp index 8206d12af..41600951f 100644 --- a/host/lib/usrp/mboard_rev.cpp +++ b/host/lib/usrp/mboard_rev.cpp @@ -23,7 +23,9 @@ using namespace uhd::usrp; -mboard_rev_t::mboard_rev_t(boost::uint16_t id){ +static const mboard_rev_t usrp2p_first_hw_rev = mboard_rev_t(0x0A00); + +mboard_rev_t::mboard_rev_t(boost::uint16_t rev){ _rev = rev; } @@ -60,9 +62,30 @@ std::string mboard_rev_t::to_string(void) const{ return str(boost::format("0x%04x") % this->to_uint16()); } -//Note: to_pp_string is implemented in the dboard manager -//because it needs access to the dboard registration table +std::string mboard_rev_t::to_pp_string(void) const{ + if(this->is_usrp2p()) { + return str(boost::format("USRP2+, major rev %i, minor rev %i") % int(this->major()) % int(this->minor())); + } else { + return str(boost::format("USRP2, major rev %i, minor rev %i") % int(this->major()) % int(this->minor())); + } +} + +bool mboard_rev_t::is_usrp2p(void) const{ + return _rev >= usrp2p_first_hw_rev; +} + +boost::uint8_t mboard_rev_t::major(void) const{ + return _rev >> 8; +} + +boost::uint8_t mboard_rev_t::minor(void) const{ + return _rev & 0xff; +} bool uhd::usrp::operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs){ return lhs.to_uint16() == rhs.to_uint16(); } + +bool uhd::usrp::operator<(const mboard_rev_t &lhs, const mboard_rev_t &rhs){ + return lhs.to_uint16() < rhs.to_uint16(); +} diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 8887faf12..c652b592b 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -32,7 +32,8 @@ using namespace uhd; class usrp2_clock_ctrl_impl : public usrp2_clock_ctrl{ public: usrp2_clock_ctrl_impl(usrp2_iface::sptr iface){ - clk_regs = usrp2_clk_regs_t(iface->get_hw_rev()); + _iface = iface; + clk_regs = usrp2_clk_regs_t(_iface->get_hw_rev()); _ad9510_regs.cp_current_setting = ad9510_regs_t::CP_CURRENT_SETTING_3_0MA; this->write_reg(clk_regs.pll_3); @@ -123,6 +124,7 @@ public: break; default: + break; } this->write_reg(clk_regs.output(clk_regs.exp)); this->write_reg(clk_regs.div_lo(clk_regs.exp)); @@ -296,6 +298,8 @@ private: this->write_reg(clk_regs.div_hi(clk_regs.adc)); this->update_regs(); } + + usrp2_iface::sptr _iface; usrp2_clk_regs_t clk_regs; ad9510_regs_t _ad9510_regs; diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 22a892f02..533534bd0 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -59,7 +59,7 @@ public: } //power-up adc - if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) { //if we're on a USRP2 + if(!_iface->get_hw_rev().is_usrp2p()) { //if we're on a USRP2 _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_ON); } else { //we're on a USRP2+ _ads62p44_regs.reset = 1; @@ -77,7 +77,7 @@ public: this->send_ad9777_reg(0); //power-down adc - if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) { //if we're on a USRP2 + if(!_iface->get_hw_rev().is_usrp2p()) { //if we're on a USRP2 _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_OFF); } else { //we're on a USRP2+ //send a global power-down to the ADC here... it will get lifted on reset @@ -87,21 +87,21 @@ public: } void set_rx_digital_gain(float gain) { //fine digital gain - if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().is_usrp2p()) { _ads62p44_regs.fine_gain = int(gain/0.5); this->send_ads62p44_reg(0x17); } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 } void set_rx_digital_fine_gain(float gain) { //gain correction - if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().is_usrp2p()) { _ads62p44_regs.gain_correction = int(gain / 0.05); this->send_ads62p44_reg(0x1A); } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 } void set_rx_analog_gain(bool gain) { //turns on/off analog 3.5dB preamp - if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().is_usrp2p()) { _ads62p44_regs.coarse_gain = gain ? ads62p44_regs_t::COARSE_GAIN_3_5DB : ads62p44_regs_t::COARSE_GAIN_0DB; this->send_ads62p44_reg(0x14); } else UHD_THROW_INVALID_CODE_PATH(); diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 04a11d922..6065b6c28 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -67,7 +67,7 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ return; case CODEC_PROP_GAIN_NAMES: - if(_iface->get_hw_rev().to_uint16() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().is_usrp2p()) { val = prop_names_t(codec_rx_gain_ranges.keys()); } else val = prop_names_t(); return; @@ -94,7 +94,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()) { case CODEC_PROP_GAIN_I: case CODEC_PROP_GAIN_Q: - if(_iface->get_hw_rev().to_uint16() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P + if(!_iface->get_hw_rev().is_usrp2p()) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P gain = val.as(); this->rx_codec_set_gain(gain, key.name); diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 6ee6d03a1..3a7048cdd 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -51,7 +51,7 @@ usrp2_mboard_impl::usrp2_mboard_impl( //extract the mboard rev numbers byte_vector_t rev_bytes = _iface->read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, 2); - _iface->set_hw_rev(mboard_rev_t::from_uint16(rev_bytes.at(0) | (revbytes.at(1) << 8))); + _iface->set_hw_rev(mboard_rev_t::from_uint16(rev_bytes.at(0) | (rev_bytes.at(1) << 8))); //contruct the interfaces to mboard perifs _clock_ctrl = usrp2_clock_ctrl::make(_iface); @@ -158,7 +158,7 @@ void usrp2_mboard_impl::update_clock_config(void){ _iface->poke32(_iface->regs.time64_flags, pps_flags); //clock source ref 10mhz - if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) { + if(_iface->get_hw_rev().is_usrp2p()) { switch(_clock_config.ref_source){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x12); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; @@ -176,7 +176,7 @@ void usrp2_mboard_impl::update_clock_config(void){ //clock source ref 10mhz bool use_external = (_clock_config.ref_source != clock_config_t::REF_INT) - || (_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV); //USRP2P has an internal 10MHz TCXO + || (_iface->get_hw_rev().is_usrp2p()); //USRP2P has an internal 10MHz TCXO _clock_ctrl->enable_external_ref(use_external); } @@ -224,10 +224,11 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ } if (key.as() == "hw-rev"){ - //extract the mboard rev numbers + //extract the mboard rev number val = _iface->get_hw_rev().to_string(); return; } + } //handle the get request conditioned on the key switch(key.as()){ @@ -327,12 +328,13 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){ if (key.as() == "hw-rev"){ mboard_rev_t rev = mboard_rev_t::from_string(val.as()); - byte_vector_t revbytes(2); - revbytes(1) = rev.to_uint16() >> 8; - revbytes(0) = rev.to_uint16() & 0xff; - _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, revbytes); + byte_vector_t rev_bytes(2); + rev_bytes[1] = rev.to_uint16() >> 8; + rev_bytes[0] = rev.to_uint16() & 0xff; + _iface->write_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, rev_bytes); _iface->set_hw_rev(rev); //so the iface knows what rev it is return; + } } //handle the set request conditioned on the key diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 7ce5cc936..bce859629 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -260,12 +260,12 @@ public: /*********************************************************************** * Get/set hardware revision **********************************************************************/ - void set_hw_rev(mboard_rev_t rev) { + void set_hw_rev(uhd::usrp::mboard_rev_t rev) { hw_rev = rev; regs = usrp2_get_regs(rev); //might be a better place to do this } - mboard_rev_t get_hw_rev(void) { + uhd::usrp::mboard_rev_t get_hw_rev(void) { return hw_rev; } diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index fe2687d02..53a8e4bc8 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "fw_common.h" #include "usrp2_regs.hpp" diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index 49f077221..f9b54b76e 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -15,19 +15,20 @@ // along with this program. If not, see . // +#include #include "usrp2_regs.hpp" int sr_addr(int misc_output_base, int sr) { return misc_output_base + 4 * sr; } -usrp2_regs_t usrp2_get_regs(int hw_rev) { +usrp2_regs_t usrp2_get_regs(uhd::usrp::mboard_rev_t hw_rev) { //how about you just make this dependent on hw_rev instead of doing the init before main, and give up the const globals, since the application won't ever need both. - const int misc_output_base = (hw_rev>=USRP2P_FIRST_HW_REV) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, - gpio_base = (hw_rev>=USRP2P_FIRST_HW_REV) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, - atr_base = (hw_rev>=USRP2P_FIRST_HW_REV) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, - bp_base = (hw_rev>=USRP2P_FIRST_HW_REV) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; + const int misc_output_base = (hw_rev.is_usrp2p()) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, + gpio_base = (hw_rev.is_usrp2p()) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, + atr_base = (hw_rev.is_usrp2p()) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, + bp_base = (hw_rev.is_usrp2p()) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; usrp2_regs_t x; x.sr_misc = 0; diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 8dae843ab..bb15ed496 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -18,6 +18,8 @@ #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP +#include + #define USRP2_MISC_OUTPUT_BASE 0xD400 #define USRP2_GPIO_BASE 0xC800 #define USRP2_ATR_BASE 0xE400 @@ -28,7 +30,7 @@ #define USRP2P_ATR_BASE 0x3800 #define USRP2P_BP_STATUS_BASE 0x3300 -#define USRP2P_FIRST_HW_REV 0x0A00 +const uhd::usrp::mboard_rev_t USRP2P_FIRST_HW_REV(0x0A00); typedef struct { int sr_misc; @@ -101,7 +103,7 @@ typedef struct { extern const usrp2_regs_t usrp2_regs; //the register definitions, set in usrp2_regs.cpp and usrp2p_regs.cpp -usrp2_regs_t usrp2_get_regs(int hw_rev); +usrp2_regs_t usrp2_get_regs(uhd::usrp::mboard_rev_t hw_rev); //////////////////////////////////////////////////// // Settings Bus, Slave #7, Not Byte Addressable! diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index a95864ca7..083c7629c 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -45,6 +45,9 @@ TARGET_LINK_LIBRARIES(usrp1_init_eeprom uhd) ADD_EXECUTABLE(usrp1_serial_burner usrp1_serial_burner.cpp) TARGET_LINK_LIBRARIES(usrp1_serial_burner uhd) +ADD_EXECUTABLE(usrp2_burn_mb_rev usrp2_burn_mb_rev.cpp) +TARGET_LINK_LIBRARIES(usrp2_burn_mb_rev uhd) + INSTALL(TARGETS usrp2_addr_burner usrp_burn_db_eeprom diff --git a/host/utils/usrp2_burn_mb_rev.cpp b/host/utils/usrp2_burn_mb_rev.cpp new file mode 100644 index 000000000..59b072d17 --- /dev/null +++ b/host/utils/usrp2_burn_mb_rev.cpp @@ -0,0 +1,82 @@ +// +// 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 +#include +#include +#include +#include +#include +#include + +using namespace uhd; +using namespace uhd::usrp; +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + //command line variables + std::string args; + + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("args", po::value(&args)->default_value(""), "device address args [default = \"\"]") + ("rev", po::value(), "mboard rev to burn, omit for readback") + ; + + 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 Burn MB HW revision %s") % desc << std::endl; + std::cout << boost::format( + "Omit the rev argument to perform readback,\n" + "Or specify a new rev to burn into the eeprom.\n" + ) << std::endl; + return ~0; + } + + //make the device and extract the mboard + device::sptr dev = device::make(args); + wax::obj u2_mb = (*dev)[DEVICE_PROP_MBOARD]; + + //read the current mboard rev from eeprom + if (vm.count("rev") == 0){ + std::cout << "Getting rev..." << std::endl; + uhd::usrp::mboard_rev_t rev = mboard_rev_t::from_string(u2_mb[std::string("hw-rev")].as()); + std::cout << boost::format(" Current rev: %s") % rev.to_pp_string() << std::endl; + } + + //write a new mboard rev to eeprom + else{ + mboard_rev_t rev = mboard_rev_t::from_string(vm["rev"].as()); + std::cout << "Setting mboard rev..." << std::endl; + std::cout << boost::format(" New rev: %s") % rev.to_pp_string() << std::endl; + u2_mb[std::string("hw-rev")] = rev.to_string(); + } + + std::cout << " Done" << std::endl << std::endl; + return 0; +} -- cgit v1.2.3 From e0b3b4e3dd9f22d27e9465bba0c978a488733aae Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 10 Nov 2010 16:23:11 -0800 Subject: U2P: Ripped out the mboard_rev_t structure in favor of an enum in usrp2_regs.hpp and some logic. Also change ethernet.c to move generic code to eth_lib. --- firmware/microblaze/usrp2p/ethernet.c | 4 +- host/lib/usrp/usrp2/CMakeLists.txt | 2 - host/lib/usrp/usrp2/clock_ctrl.cpp | 1 - host/lib/usrp/usrp2/codec_ctrl.cpp | 10 +-- host/lib/usrp/usrp2/codec_impl.cpp | 4 +- host/lib/usrp/usrp2/mboard_impl.cpp | 5 +- host/lib/usrp/usrp2/mboard_rev.cpp | 89 -------------------- host/lib/usrp/usrp2/mboard_rev.hpp | 114 -------------------------- host/lib/usrp/usrp2/usrp2_clk_regs.hpp | 26 ++++-- host/lib/usrp/usrp2/usrp2_iface.cpp | 26 +++--- host/lib/usrp/usrp2/usrp2_iface.hpp | 21 ++--- host/lib/usrp/usrp2/usrp2_regs.cpp | 14 ++-- host/lib/usrp/usrp2/usrp2_regs.hpp | 144 +++++++++++++++++---------------- 13 files changed, 123 insertions(+), 337 deletions(-) delete mode 100644 host/lib/usrp/usrp2/mboard_rev.cpp delete mode 100644 host/lib/usrp/usrp2/mboard_rev.hpp (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/firmware/microblaze/usrp2p/ethernet.c b/firmware/microblaze/usrp2p/ethernet.c index 660f28934..36d6a17ca 100644 --- a/firmware/microblaze/usrp2p/ethernet.c +++ b/firmware/microblaze/usrp2p/ethernet.c @@ -294,7 +294,7 @@ unprogrammed(const void *t, size_t len) } //////////////////// MAC Addr Stuff /////////////////////// - +/* static int8_t src_mac_addr_initialized = false; static eth_mac_addr_t src_mac_addr = {{ 0x00, 0x50, 0xC2, 0x85, 0x3f, 0xff @@ -373,7 +373,7 @@ bool set_ip_addr(const struct ip_addr *t){ return ok; } - +*/ int ethernet_check_errors(void) { diff --git a/host/lib/usrp/usrp2/CMakeLists.txt b/host/lib/usrp/usrp2/CMakeLists.txt index a09c833bd..f7984fce5 100644 --- a/host/lib/usrp/usrp2/CMakeLists.txt +++ b/host/lib/usrp/usrp2/CMakeLists.txt @@ -48,8 +48,6 @@ IF(ENABLE_USRP2) ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/gps_ctrl.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/io_impl.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/mboard_impl.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/mboard_rev.cpp - ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/mboard_rev.hpp ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/serdes_ctrl.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/serdes_ctrl.hpp ${CMAKE_SOURCE_DIR}/lib/usrp/usrp2/usrp2_iface.cpp diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 8eaafe680..1f8e65ce6 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -17,7 +17,6 @@ #include "clock_ctrl.hpp" #include "ad9510_regs.hpp" -#include "mboard_rev.hpp" #include "usrp2_regs.hpp" //spi slave constants #include "usrp2_clk_regs.hpp" #include diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 533534bd0..8680c285a 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -59,7 +59,7 @@ public: } //power-up adc - if(!_iface->get_hw_rev().is_usrp2p()) { //if we're on a USRP2 + if(!_iface->is_usrp2p()) { //if we're on a USRP2 _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_ON); } else { //we're on a USRP2+ _ads62p44_regs.reset = 1; @@ -77,7 +77,7 @@ public: this->send_ad9777_reg(0); //power-down adc - if(!_iface->get_hw_rev().is_usrp2p()) { //if we're on a USRP2 + if(!_iface->is_usrp2p()) { //if we're on a USRP2 _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_OFF); } else { //we're on a USRP2+ //send a global power-down to the ADC here... it will get lifted on reset @@ -87,21 +87,21 @@ public: } void set_rx_digital_gain(float gain) { //fine digital gain - if(_iface->get_hw_rev().is_usrp2p()) { + if(_iface->is_usrp2p()) { _ads62p44_regs.fine_gain = int(gain/0.5); this->send_ads62p44_reg(0x17); } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 } void set_rx_digital_fine_gain(float gain) { //gain correction - if(_iface->get_hw_rev().is_usrp2p()) { + if(_iface->is_usrp2p()) { _ads62p44_regs.gain_correction = int(gain / 0.05); this->send_ads62p44_reg(0x1A); } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 } void set_rx_analog_gain(bool gain) { //turns on/off analog 3.5dB preamp - if(_iface->get_hw_rev().is_usrp2p()) { + if(_iface->is_usrp2p()) { _ads62p44_regs.coarse_gain = gain ? ads62p44_regs_t::COARSE_GAIN_3_5DB : ads62p44_regs_t::COARSE_GAIN_0DB; this->send_ads62p44_reg(0x14); } else UHD_THROW_INVALID_CODE_PATH(); diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 6065b6c28..1c1f60765 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -67,7 +67,7 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ return; case CODEC_PROP_GAIN_NAMES: - if(_iface->get_hw_rev().is_usrp2p()) { + if(_iface->is_usrp2p()) { val = prop_names_t(codec_rx_gain_ranges.keys()); } else val = prop_names_t(); return; @@ -94,7 +94,7 @@ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()) { case CODEC_PROP_GAIN_I: case CODEC_PROP_GAIN_Q: - if(!_iface->get_hw_rev().is_usrp2p()) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P + if(!_iface->is_usrp2p()) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P gain = val.as(); this->rx_codec_set_gain(gain, key.name); diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index eb5b79b20..5b9dd1fa3 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -20,7 +20,6 @@ #include #include #include -#include "mboard_rev.hpp" #include #include #include @@ -148,7 +147,7 @@ void usrp2_mboard_impl::update_clock_config(void){ _iface->poke32(_iface->regs.time64_flags, pps_flags); //clock source ref 10mhz - if(_iface->get_hw_rev().is_usrp2p()) { + if(_iface->is_usrp2p()) { switch(_clock_config.ref_source){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x12); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; @@ -166,7 +165,7 @@ void usrp2_mboard_impl::update_clock_config(void){ //clock source ref 10mhz bool use_external = (_clock_config.ref_source != clock_config_t::REF_INT) - || (_iface->get_hw_rev().is_usrp2p()); //USRP2P has an internal 10MHz TCXO + || (_iface->is_usrp2p()); //USRP2P has an internal 10MHz TCXO _clock_ctrl->enable_external_ref(use_external); } diff --git a/host/lib/usrp/usrp2/mboard_rev.cpp b/host/lib/usrp/usrp2/mboard_rev.cpp deleted file mode 100644 index 9d0ff89f5..000000000 --- a/host/lib/usrp/usrp2/mboard_rev.cpp +++ /dev/null @@ -1,89 +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 "mboard_rev.hpp" -#include -#include -#include -#include - -static const mboard_rev_t usrp2p_first_hw_rev = mboard_rev_t(0x0A00); - -mboard_rev_t::mboard_rev_t(boost::uint16_t rev){ - _rev = rev; -} - -mboard_rev_t mboard_rev_t::none(void){ - return mboard_rev_t(); -} - -mboard_rev_t mboard_rev_t::from_uint16(boost::uint16_t uint16){ - return mboard_rev_t(uint16); -} - -boost::uint16_t mboard_rev_t::to_uint16(void) const{ - return _rev; -} - -//used with lexical cast to parse a hex string -template struct to_hex{ - T value; - operator T() const {return value;} - friend std::istream& operator>>(std::istream& in, to_hex& out){ - in >> std::hex >> out.value; - return in; - } -}; - -mboard_rev_t mboard_rev_t::from_string(const std::string &string){ - if (string.substr(0, 2) == "0x"){ - return mboard_rev_t::from_uint16(boost::lexical_cast >(string)); - } - return mboard_rev_t::from_uint16(boost::lexical_cast(string)); -} - -std::string mboard_rev_t::to_string(void) const{ - return str(boost::format("0x%04x") % this->to_uint16()); -} - -std::string mboard_rev_t::to_pp_string(void) const{ - if(this->is_usrp2p()) { - return str(boost::format("USRP2+, major rev %i, minor rev %i") % int(this->major()) % int(this->minor())); - } else { - return str(boost::format("USRP2, major rev %i, minor rev %i") % int(this->major()) % int(this->minor())); - } -} - -bool mboard_rev_t::is_usrp2p(void) const{ - return _rev >= usrp2p_first_hw_rev; -} - -boost::uint8_t mboard_rev_t::major(void) const{ - return _rev >> 8; -} - -boost::uint8_t mboard_rev_t::minor(void) const{ - return _rev & 0xff; -} - -bool operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs){ - return lhs.to_uint16() == rhs.to_uint16(); -} - -bool operator<(const mboard_rev_t &lhs, const mboard_rev_t &rhs){ - return lhs.to_uint16() < rhs.to_uint16(); -} diff --git a/host/lib/usrp/usrp2/mboard_rev.hpp b/host/lib/usrp/usrp2/mboard_rev.hpp deleted file mode 100644 index a1b1d9605..000000000 --- a/host/lib/usrp/usrp2/mboard_rev.hpp +++ /dev/null @@ -1,114 +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 . -// - -#ifndef INCLUDED_MBOARD_REV_HPP -#define INCLUDED_MBOARD_REV_HPP - -#include -#include -#include -#include - -class UHD_API mboard_rev_t : boost::equality_comparable, boost::less_than_comparable{ - public: - /*! - * Create a mboard rev from an integer. - * \param rev the integer representation - */ - mboard_rev_t(boost::uint16_t rev = 0xffff); - - /*! - * Obtain a mboard rev that represents an invalid/uninit mboard ID - * \return the mboard rev with the 0xffff rev. - */ - static mboard_rev_t none(void); - - /*! - * Create a new mboard rev from an integer representation. - * \param uint16 an unsigned 16 bit integer - * \return a new mboard rev containing the integer - */ - static mboard_rev_t from_uint16(boost::uint16_t uint16); - - /*! - * Get the mboard rev represented as an integer. - * \return an unsigned 16 bit integer representation - */ - boost::uint16_t to_uint16(void) const; - - /*! - * Create a new mboard rev from a string representation. - * If the string has a 0x prefix, it will be parsed as hex. - * \param string a numeric string, possibly hex - * \return a new dboard id containing the integer - */ - static mboard_rev_t from_string(const std::string &string); - - /*! - * Get the mboard rev represented as an integer. - * \return a hex string representation with 0x prefix - */ - std::string to_string(void) const; - - /*! - * Get the pretty print representation of this mboard rev. - * \return a string with the mboard name and rev number - */ - std::string to_pp_string(void) const; - - /*! - * Tell you if you're USRP2 or USRP2+ - * \return true if USRP2+, false if USRP2 - */ - bool is_usrp2p(void) const; - - /*! - * Get the major revision number - * \return major revision number - */ - boost::uint8_t major(void) const; - - /*! - * Get the minor revision number - * \return minor revision number - */ - boost::uint8_t minor(void) const; - - private: - boost::uint16_t _rev; //internal representation - }; - - /*! - * Comparator operator overloaded for mboard rev. - * The boost::equality_comparable provides the !=. - * \param lhs the mboard rev to the left of the operator - * \param rhs the mboard rev to the right of the operator - * \return true when the mboard revs are equal - */ - UHD_API bool operator==(const mboard_rev_t &lhs, const mboard_rev_t &rhs); - - /*! - * Comparator operator overloaded for mboard rev. - * The boost::less_than_comparable provides the >, <=, >=. - * \param lhs the mboard rev to the left of the operator - * \param rhs the mboard rev to the right of the operator - * \return true when lhs < rhs - */ - - UHD_API bool operator<(const mboard_rev_t &lhs, const mboard_rev_t &rhs); - -#endif /* INCLUDED_MBOARD_REV_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp index fcfd1e227..d5f80a919 100644 --- a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp @@ -18,23 +18,33 @@ #ifndef INCLUDED_USRP2_CLK_REGS_HPP #define INCLUDED_USRP2_CLK_REGS_HPP -#include "mboard_rev.hpp" #include "usrp2_regs.hpp" class usrp2_clk_regs_t { public: usrp2_clk_regs_t(void) { ; } - usrp2_clk_regs_t(mboard_rev_t hw_rev) { + usrp2_clk_regs_t(boost::uint16_t hw_rev) { test = 0; fpga = 1; - adc = (hw_rev.is_usrp2p()) ? 2 : 4; + adc = (hw_rev >= usrp2_rev_nums(N2XX)) ? 2 : 4; dac = 3; - serdes = (hw_rev.is_usrp2p()) ? 4 : 2; //only used by usrp2+ - tx_db = (hw_rev.is_usrp2p()) ? 5 : 6; + serdes = (hw_rev >= usrp2_rev_nums(N2XX)) ? 4 : 2; //only used by usrp2+ + tx_db = (hw_rev >= usrp2_rev_nums(N2XX)) ? 5 : 6; - if(hw_rev.major() == 3) exp = 2; - else if(hw_rev.major() >= 4) exp = 5; - else if(hw_rev.major() > 10) exp = 6; + switch(hw_rev) { + case usrp2_rev_nums(USRP2_REV3): + exp = 2; + break; + case usrp2_rev_nums(USRP2_REV4): + exp = 5; + break; + case usrp2_rev_nums(N2XX): + exp = 6; + break; + default: + throw std::runtime_error("Unknown hardware revision"); + break; + } rx_db = 7; } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 52adb5373..147b968b4 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -19,7 +19,6 @@ #include "usrp2_iface.hpp" #include #include -#include "mboard_rev.hpp" #include #include #include //used for htonl and ntohl @@ -53,9 +52,8 @@ public: usrp2_iface_impl(udp_simple::sptr ctrl_transport){ _ctrl_transport = ctrl_transport; - //extract the mboard rev numbers - byte_vector_t rev_bytes = read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, 2); - set_hw_rev(mboard_rev_t::from_uint16(rev_bytes.at(0) | (rev_bytes.at(1) << 8))); + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_N100); + regs = usrp2_get_regs(get_hw_rev()); //check the fpga compatibility number const boost::uint32_t fpga_compat_num = this->peek32(this->regs.compat_num_rb); @@ -65,8 +63,6 @@ public: "The fpga build is not compatible with the host code build." ) % int(USRP2_FPGA_COMPAT_NUM) % fpga_compat_num)); } - - mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_N100); } ~usrp2_iface_impl(void){ @@ -263,17 +259,13 @@ public: } throw std::runtime_error("usrp2 no control response"); } - - /*********************************************************************** - * Get/set hardware revision - **********************************************************************/ - void set_hw_rev(mboard_rev_t rev) { - hw_rev = rev; - regs = usrp2_get_regs(rev); //might be a better place to do this + + bool is_usrp2p(void) { + return (get_hw_rev() >= usrp2_rev_nums(N2XX)); } - - mboard_rev_t get_hw_rev(void) { - return hw_rev; + + boost::uint16_t get_hw_rev(void) { + return boost::lexical_cast(mb_eeprom["rev"]); } @@ -313,7 +305,6 @@ private: UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE); return T(ntohl(in_data.data.poke_args.data)); } - }; /*********************************************************************** @@ -322,3 +313,4 @@ private: usrp2_iface::sptr usrp2_iface::make(udp_simple::sptr ctrl_transport){ return usrp2_iface::sptr(new usrp2_iface_impl(ctrl_transport)); } + diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index 88bff5913..d7e5df9f5 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -24,7 +24,6 @@ #include #include #include -#include "mboard_rev.hpp" #include #include "fw_common.h" #include "usrp2_regs.hpp" @@ -109,26 +108,16 @@ public: virtual void write_uart(boost::uint8_t dev, const std::string &buf) = 0; virtual std::string read_uart(boost::uint8_t dev) = 0; - - /*! - * Set the hardware revision number. Also selects the proper register set for the device. - * \param rev the 16-bit revision - */ - virtual void set_hw_rev(mboard_rev_t rev) = 0; - - /*! Return the hardware revision number - * \return hardware revision - */ - virtual mboard_rev_t get_hw_rev(void) = 0; + + virtual boost::uint16_t get_hw_rev(void) = 0; + + virtual bool is_usrp2p(void) = 0; /*! * Register map selected from USRP2/USRP2+. */ usrp2_regs_t regs; - /*! - * Hardware revision as returned by the device. - */ - mboard_rev_t hw_rev; + //motherboard eeprom map structure uhd::usrp::mboard_eeprom_t mb_eeprom; }; diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index 0f0360c95..5853e91e5 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -15,25 +15,23 @@ // along with this program. If not, see . // -#include "mboard_rev.hpp" #include "usrp2_regs.hpp" int sr_addr(int misc_output_base, int sr) { return misc_output_base + 4 * sr; } -usrp2_regs_t usrp2_get_regs(mboard_rev_t hw_rev) { - +usrp2_regs_t usrp2_get_regs(boost::uint16_t hw_rev) { //how about you just make this dependent on hw_rev instead of doing the init before main, and give up the const globals, since the application won't ever need both. - const int misc_output_base = (hw_rev.is_usrp2p()) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, - gpio_base = (hw_rev.is_usrp2p()) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, - atr_base = (hw_rev.is_usrp2p()) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, - bp_base = (hw_rev.is_usrp2p()) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; + const int misc_output_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, + gpio_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, + atr_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, + bp_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; usrp2_regs_t x; x.sr_misc = 0; x.sr_tx_prot_eng = 32; - x.sr_rx_prot_eng = 48; + x.sr_rx_prot_eng = 48; x.sr_buffer_pool_ctrl = 64; x.sr_udp_sm = 96; x.sr_tx_dsp = 208; diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 0d68c65c2..d84106f36 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -18,7 +18,13 @@ #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP -#include "mboard_rev.hpp" +#include + +enum usrp2_rev_nums { + USRP2_REV3 = 0x0003, + USRP2_REV4 = 0x0004, + N2XX = 0x0A00 +}; #define USRP2_MISC_OUTPUT_BASE 0xD400 #define USRP2_GPIO_BASE 0xC800 @@ -30,80 +36,78 @@ #define USRP2P_ATR_BASE 0x3800 #define USRP2P_BP_STATUS_BASE 0x3300 -const mboard_rev_t USRP2P_FIRST_HW_REV(0x0A00); - typedef struct { - int sr_misc; - int sr_tx_prot_eng; - int sr_rx_prot_eng; - int sr_buffer_pool_ctrl; - int sr_udp_sm; - int sr_tx_dsp; - int sr_tx_ctrl; - int sr_rx_dsp; - int sr_rx_ctrl; - int sr_time64; - int sr_simtimer; - int sr_last; - int misc_ctrl_clock; - int misc_ctrl_serdes; - int misc_ctrl_adc; - int misc_ctrl_leds; - int misc_ctrl_phy; - int misc_ctrl_dbg_mux; - int misc_ctrl_ram_page; - int misc_ctrl_flush_icache; - int misc_ctrl_led_src; - int time64_secs; // value to set absolute secs to on next PPS - int time64_ticks; // value to set absolute ticks to on next PPS - int time64_flags; // flags -- see chart below - int time64_imm; // set immediate (0=latch on next pps, 1=latch immediate, default=0) - int time64_tps; // ticks per second rollover count - int time64_secs_rb; - int time64_ticks_rb; - int compat_num_rb; - int dsp_tx_freq; - int dsp_tx_scale_iq; - int dsp_tx_interp_rate; - int dsp_tx_mux; - int dsp_rx_freq; - int dsp_rx_scale_iq; - int dsp_rx_decim_rate; - int dsp_rx_dcoffset_i; - int dsp_rx_dcoffset_q; - int dsp_rx_mux; - int gpio_base; - int gpio_io; - int gpio_ddr; - int gpio_tx_sel; - int gpio_rx_sel; - int atr_base; - int atr_idle_txside; - int atr_idle_rxside; - int atr_intx_txside; - int atr_intx_rxside; - int atr_inrx_txside; - int atr_inrx_rxside; - int atr_full_txside; - int atr_full_rxside; - int rx_ctrl_stream_cmd; - int rx_ctrl_time_secs; - int rx_ctrl_time_ticks; - int rx_ctrl_clear_overrun; - int rx_ctrl_vrt_header; - int rx_ctrl_vrt_stream_id; - int rx_ctrl_vrt_trailer; - int rx_ctrl_nsamps_per_pkt; - int rx_ctrl_nchannels; - int tx_ctrl_num_chan; - int tx_ctrl_clear_state; - int tx_ctrl_report_sid; - int tx_ctrl_policy; + int sr_misc; + int sr_tx_prot_eng; + int sr_rx_prot_eng; + int sr_buffer_pool_ctrl; + int sr_udp_sm; + int sr_tx_dsp; + int sr_tx_ctrl; + int sr_rx_dsp; + int sr_rx_ctrl; + int sr_time64; + int sr_simtimer; + int sr_last; + int misc_ctrl_clock; + int misc_ctrl_serdes; + int misc_ctrl_adc; + int misc_ctrl_leds; + int misc_ctrl_phy; + int misc_ctrl_dbg_mux; + int misc_ctrl_ram_page; + int misc_ctrl_flush_icache; + int misc_ctrl_led_src; + int time64_secs; // value to set absolute secs to on next PPS + int time64_ticks; // value to set absolute ticks to on next PPS + int time64_flags; // flags -- see chart below + int time64_imm; // set immediate (0=latch on next pps, 1=latch immediate, default=0) + int time64_tps; // ticks per second rollover count + int time64_secs_rb; + int time64_ticks_rb; + int compat_num_rb; + int dsp_tx_freq; + int dsp_tx_scale_iq; + int dsp_tx_interp_rate; + int dsp_tx_mux; + int dsp_rx_freq; + int dsp_rx_scale_iq; + int dsp_rx_decim_rate; + int dsp_rx_dcoffset_i; + int dsp_rx_dcoffset_q; + int dsp_rx_mux; + int gpio_base; + int gpio_io; + int gpio_ddr; + int gpio_tx_sel; + int gpio_rx_sel; + int atr_base; + int atr_idle_txside; + int atr_idle_rxside; + int atr_intx_txside; + int atr_intx_rxside; + int atr_inrx_txside; + int atr_inrx_rxside; + int atr_full_txside; + int atr_full_rxside; + int rx_ctrl_stream_cmd; + int rx_ctrl_time_secs; + int rx_ctrl_time_ticks; + int rx_ctrl_clear_overrun; + int rx_ctrl_vrt_header; + int rx_ctrl_vrt_stream_id; + int rx_ctrl_vrt_trailer; + int rx_ctrl_nsamps_per_pkt; + int rx_ctrl_nchannels; + int tx_ctrl_num_chan; + int tx_ctrl_clear_state; + int tx_ctrl_report_sid; + int tx_ctrl_policy; } usrp2_regs_t; extern const usrp2_regs_t usrp2_regs; //the register definitions, set in usrp2_regs.cpp and usrp2p_regs.cpp -usrp2_regs_t usrp2_get_regs(mboard_rev_t hw_rev); +usrp2_regs_t usrp2_get_regs(boost::uint16_t hw_rev); //////////////////////////////////////////////////// // Settings Bus, Slave #7, Not Byte Addressable! -- cgit v1.2.3 From 476afe68f5c37a3e10a1208b0150732d7770a023 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 11 Nov 2010 17:40:01 -0800 Subject: usrp2: made enums for the rev types and implemented in code --- host/README | 2 + host/lib/usrp/README | 12 +++++ host/lib/usrp/usrp2/clock_ctrl.cpp | 2 +- host/lib/usrp/usrp2/codec_ctrl.cpp | 85 +++++++++++++++++++++++----------- host/lib/usrp/usrp2/codec_impl.cpp | 26 +++++------ host/lib/usrp/usrp2/mboard_impl.cpp | 19 +++++--- host/lib/usrp/usrp2/usrp2_clk_regs.hpp | 31 ++++++++----- host/lib/usrp/usrp2/usrp2_iface.cpp | 42 +++++++++++++---- host/lib/usrp/usrp2/usrp2_iface.hpp | 22 +++++++-- host/lib/usrp/usrp2/usrp2_regs.cpp | 12 +++-- host/lib/usrp/usrp2/usrp2_regs.hpp | 8 +--- 11 files changed, 175 insertions(+), 86 deletions(-) create mode 100644 host/lib/usrp/README (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/README b/host/README index cab1e0b10..c4a72cd83 100644 --- a/host/README +++ b/host/README @@ -8,6 +8,7 @@ The hardware driver for Ettus Research products. ######################################################################## USRP1 USRP2 +USRP-N2XX ######################################################################## # Supported USRP Daughterboards @@ -20,6 +21,7 @@ RFX Series XCVR 2450 WBX Series DBSRX +DBSRX2 TVRX ######################################################################## diff --git a/host/lib/usrp/README b/host/lib/usrp/README new file mode 100644 index 000000000..c125d1dad --- /dev/null +++ b/host/lib/usrp/README @@ -0,0 +1,12 @@ +######################################################################## +# lib USRP directories: +######################################################################## + +dboard: + Daughterboard implementation code for all USRP daughterboards + +usrp1: + Implementation code for the USB-based USRP Classic motherboard. + +usrp2: + Implementation code for USRP2 and USRP-N2XX. diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 1f8e65ce6..428d5539b 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -33,7 +33,7 @@ class usrp2_clock_ctrl_impl : public usrp2_clock_ctrl{ public: usrp2_clock_ctrl_impl(usrp2_iface::sptr iface){ _iface = iface; - clk_regs = usrp2_clk_regs_t(_iface->get_hw_rev()); + clk_regs = usrp2_clk_regs_t(_iface->get_rev()); _ad9510_regs.cp_current_setting = ad9510_regs_t::CP_CURRENT_SETTING_3_0MA; this->write_reg(clk_regs.pll_3); diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 8680c285a..ad1ae1acb 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -59,15 +59,23 @@ public: } //power-up adc - if(!_iface->is_usrp2p()) { //if we're on a USRP2 - _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_ON); - } else { //we're on a USRP2+ - _ads62p44_regs.reset = 1; - this->send_ads62p44_reg(0x00); //issue a reset to the ADC - //everything else should be pretty much default, i think -// _ads62p44_regs.decimation = DECIMATION_DECIMATE_1; - _ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_NORMAL; - this->send_ads62p44_reg(0x14); + switch(_iface->get_rev()){ + case usrp2_iface::USRP2_REV3: + case usrp2_iface::USRP2_REV4: + _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_ON); + break; + + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + _ads62p44_regs.reset = 1; + this->send_ads62p44_reg(0x00); //issue a reset to the ADC + //everything else should be pretty much default, i think + //_ads62p44_regs.decimation = DECIMATION_DECIMATE_1; + _ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_NORMAL; + this->send_ads62p44_reg(0x14); + break; + + case usrp2_iface::USRP_NXXX: break; } } @@ -77,34 +85,57 @@ public: this->send_ad9777_reg(0); //power-down adc - if(!_iface->is_usrp2p()) { //if we're on a USRP2 - _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_OFF); - } else { //we're on a USRP2+ - //send a global power-down to the ADC here... it will get lifted on reset - _ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_GLOBAL_PD; - this->send_ads62p44_reg(0x14); + switch(_iface->get_rev()){ + case usrp2_iface::USRP2_REV3: + case usrp2_iface::USRP2_REV4: + _iface->poke32(_iface->regs.misc_ctrl_adc, U2_FLAG_MISC_CTRL_ADC_OFF); + break; + + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + //send a global power-down to the ADC here... it will get lifted on reset + _ads62p44_regs.power_down = ads62p44_regs_t::POWER_DOWN_GLOBAL_PD; + this->send_ads62p44_reg(0x14); + break; + + case usrp2_iface::USRP_NXXX: break; } } void set_rx_digital_gain(float gain) { //fine digital gain - if(_iface->is_usrp2p()) { - _ads62p44_regs.fine_gain = int(gain/0.5); - this->send_ads62p44_reg(0x17); - } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + _ads62p44_regs.fine_gain = int(gain/0.5); + this->send_ads62p44_reg(0x17); + break; + + default: UHD_THROW_INVALID_CODE_PATH(); + } } void set_rx_digital_fine_gain(float gain) { //gain correction - if(_iface->is_usrp2p()) { - _ads62p44_regs.gain_correction = int(gain / 0.05); - this->send_ads62p44_reg(0x1A); - } else UHD_THROW_INVALID_CODE_PATH(); //should never have been called for USRP2 + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + _ads62p44_regs.gain_correction = int(gain / 0.05); + this->send_ads62p44_reg(0x1A); + break; + + default: UHD_THROW_INVALID_CODE_PATH(); + } } void set_rx_analog_gain(bool gain) { //turns on/off analog 3.5dB preamp - if(_iface->is_usrp2p()) { - _ads62p44_regs.coarse_gain = gain ? ads62p44_regs_t::COARSE_GAIN_3_5DB : ads62p44_regs_t::COARSE_GAIN_0DB; - this->send_ads62p44_reg(0x14); - } else UHD_THROW_INVALID_CODE_PATH(); + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + _ads62p44_regs.coarse_gain = gain ? ads62p44_regs_t::COARSE_GAIN_3_5DB : ads62p44_regs_t::COARSE_GAIN_0DB; + this->send_ads62p44_reg(0x14); + break; + + default: UHD_THROW_INVALID_CODE_PATH(); + } } private: diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 1c1f60765..5f4937643 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -32,7 +32,7 @@ using namespace boost::assign; static const uhd::dict codec_rx_gain_ranges = map_list_of ("analog", gain_range_t(0, 3.5, 3.5)) ("digital", gain_range_t(0, 6.0, 0.5)) - ("digital-fine", gain_range_t(0, 0.5, 0.05)); + ("digital-fine", gain_range_t(0, 0.5, 0.05)); /*********************************************************************** @@ -67,9 +67,14 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ return; case CODEC_PROP_GAIN_NAMES: - if(_iface->is_usrp2p()) { - val = prop_names_t(codec_rx_gain_ranges.keys()); - } else val = prop_names_t(); + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + val = prop_names_t(codec_rx_gain_ranges.keys()); + return; + + default: val = prop_names_t(); + } return; case CODEC_PROP_GAIN_I: @@ -89,19 +94,14 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ named_prop_t key = named_prop_t::extract(key_); - float gain; - switch(key.as()) { + switch(key.as()) { case CODEC_PROP_GAIN_I: case CODEC_PROP_GAIN_Q: - if(!_iface->is_usrp2p()) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P - - gain = val.as(); - this->rx_codec_set_gain(gain, key.name); - return; + this->rx_codec_set_gain(val.as(), key.name); + return; - default: - UHD_THROW_PROP_SET_ERROR(); + default: UHD_THROW_PROP_SET_ERROR(); } } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 5b9dd1fa3..5b47045e2 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -147,26 +147,31 @@ void usrp2_mboard_impl::update_clock_config(void){ _iface->poke32(_iface->regs.time64_flags, pps_flags); //clock source ref 10mhz - if(_iface->is_usrp2p()) { + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: switch(_clock_config.ref_source){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x12); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; case clock_config_t::REF_MIMO: _iface->poke32(_iface->regs.misc_ctrl_clock, 0x15); break; default: throw std::runtime_error("usrp2: unhandled clock configuration reference source"); } - } else { + _clock_ctrl->enable_external_ref(true); //USRP2P has an internal 10MHz TCXO + break; + + case usrp2_iface::USRP2_REV3: + case usrp2_iface::USRP2_REV4: switch(_clock_config.ref_source){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x10); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; case clock_config_t::REF_MIMO: _iface->poke32(_iface->regs.misc_ctrl_clock, 0x15); break; default: throw std::runtime_error("usrp2: unhandled clock configuration reference source"); } - } + _clock_ctrl->enable_external_ref(_clock_config.ref_source != clock_config_t::REF_INT); + break; - //clock source ref 10mhz - bool use_external = (_clock_config.ref_source != clock_config_t::REF_INT) - || (_iface->is_usrp2p()); //USRP2P has an internal 10MHz TCXO - _clock_ctrl->enable_external_ref(use_external); + case usrp2_iface::USRP_NXXX: break; + } } void usrp2_mboard_impl::set_time_spec(const time_spec_t &time_spec, bool now){ diff --git a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp index d5f80a919..6c46d0a35 100644 --- a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp @@ -18,31 +18,38 @@ #ifndef INCLUDED_USRP2_CLK_REGS_HPP #define INCLUDED_USRP2_CLK_REGS_HPP -#include "usrp2_regs.hpp" +#include "usrp2_iface.hpp" class usrp2_clk_regs_t { public: usrp2_clk_regs_t(void) { ; } - usrp2_clk_regs_t(boost::uint16_t hw_rev) { + usrp2_clk_regs_t(usrp2_iface::rev_type rev) { test = 0; fpga = 1; - adc = (hw_rev >= usrp2_rev_nums(N2XX)) ? 2 : 4; dac = 3; - serdes = (hw_rev >= usrp2_rev_nums(N2XX)) ? 4 : 2; //only used by usrp2+ - tx_db = (hw_rev >= usrp2_rev_nums(N2XX)) ? 5 : 6; - - switch(hw_rev) { - case usrp2_rev_nums(USRP2_REV3): + + switch(rev) { + case usrp2_iface::USRP2_REV3: exp = 2; + adc = 4; + serdes = 2; + tx_db = 6; break; - case usrp2_rev_nums(USRP2_REV4): + case usrp2_iface::USRP2_REV4: exp = 5; + adc = 4; + serdes = 2; + tx_db = 6; break; - case usrp2_rev_nums(N2XX): + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: exp = 6; + adc = 2; + serdes = 4; + tx_db = 5; break; - default: - throw std::runtime_error("Unknown hardware revision"); + case usrp2_iface::USRP_NXXX: + //dont throw, it may be unitialized break; } diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 10cb86962..01df68010 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -17,6 +17,7 @@ #include "usrp2_regs.hpp" #include "usrp2_iface.hpp" +#include #include #include #include @@ -51,11 +52,22 @@ public: **********************************************************************/ usrp2_iface_impl(udp_simple::sptr ctrl_transport){ _ctrl_transport = ctrl_transport; - + mb_eeprom = mboard_eeprom_t(*this, mboard_eeprom_t::MAP_N100); - regs = usrp2_get_regs(get_hw_rev()); + switch(this->get_rev()){ + case USRP2_REV3: + case USRP2_REV4: + regs = usrp2_get_regs(false); + break; + + case USRP_NXXX: + case USRP_N200: + case USRP_N210: + regs = usrp2_get_regs(true); + break; + } - //check the fpga compatibility number + //check the fpga compatibility number const boost::uint32_t fpga_compat_num = this->peek32(this->regs.compat_num_rb); if (fpga_compat_num != USRP2_FPGA_COMPAT_NUM){ throw std::runtime_error(str(boost::format( @@ -259,15 +271,27 @@ public: } throw std::runtime_error("usrp2 no control response"); } - - bool is_usrp2p(void) { - return (get_hw_rev() >= usrp2_rev_nums(N2XX)); - } - boost::uint16_t get_hw_rev(void) { - return boost::lexical_cast(mb_eeprom["rev"]); + rev_type get_rev(void){ + switch (boost::lexical_cast(mb_eeprom["rev"])){ + case 0x0003: return USRP2_REV3; + case 0x0004: return USRP2_REV4; + case 0x0A00: return USRP_N200; + case 0x0A01: return USRP_N210; + } + return USRP_NXXX; //unknown type } + const std::string get_cname(void){ + switch(this->get_rev()){ + case USRP2_REV3: return "USRP2-REV3"; + case USRP2_REV4: return "USRP2-REV4"; + case USRP_N200: return "USRP-N200"; + case USRP_N210: return "USRP-N210"; + case USRP_NXXX: return "USRP-N???"; + } + UHD_THROW_INVALID_CODE_PATH(); + } private: //this lovely lady makes it all possible diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index d7e5df9f5..af3ed6c9f 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "fw_common.h" #include "usrp2_regs.hpp" @@ -108,16 +109,27 @@ public: virtual void write_uart(boost::uint8_t dev, const std::string &buf) = 0; virtual std::string read_uart(boost::uint8_t dev) = 0; - - virtual boost::uint16_t get_hw_rev(void) = 0; - - virtual bool is_usrp2p(void) = 0; + + //! The list of possible revision types + enum rev_type { + USRP2_REV3 = 3, + USRP2_REV4 = 4, + USRP_N200 = 200, + USRP_N210 = 210, + USRP_NXXX = 0 + }; + + //! Get the revision type for this device + virtual rev_type get_rev(void) = 0; + + //! Get the canonical name for this device + virtual const std::string get_cname(void) = 0; /*! * Register map selected from USRP2/USRP2+. */ usrp2_regs_t regs; - + //motherboard eeprom map structure uhd::usrp::mboard_eeprom_t mb_eeprom; }; diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index 5853e91e5..b24082edb 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -16,17 +16,19 @@ // #include "usrp2_regs.hpp" +#include "usrp2_iface.hpp" int sr_addr(int misc_output_base, int sr) { return misc_output_base + 4 * sr; } -usrp2_regs_t usrp2_get_regs(boost::uint16_t hw_rev) { +usrp2_regs_t usrp2_get_regs(bool use_n2xx_map) { + //how about you just make this dependent on hw_rev instead of doing the init before main, and give up the const globals, since the application won't ever need both. - const int misc_output_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, - gpio_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, - atr_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, - bp_base = (hw_rev >= usrp2_rev_nums(N2XX)) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; + const int misc_output_base = (use_n2xx_map) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, + gpio_base = (use_n2xx_map) ? USRP2P_GPIO_BASE : USRP2_GPIO_BASE, + atr_base = (use_n2xx_map) ? USRP2P_ATR_BASE : USRP2_ATR_BASE, + bp_base = (use_n2xx_map) ? USRP2P_BP_STATUS_BASE : USRP2_BP_STATUS_BASE; usrp2_regs_t x; x.sr_misc = 0; diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index d84106f36..1081ff159 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -20,12 +20,6 @@ #include -enum usrp2_rev_nums { - USRP2_REV3 = 0x0003, - USRP2_REV4 = 0x0004, - N2XX = 0x0A00 -}; - #define USRP2_MISC_OUTPUT_BASE 0xD400 #define USRP2_GPIO_BASE 0xC800 #define USRP2_ATR_BASE 0xE400 @@ -107,7 +101,7 @@ typedef struct { extern const usrp2_regs_t usrp2_regs; //the register definitions, set in usrp2_regs.cpp and usrp2p_regs.cpp -usrp2_regs_t usrp2_get_regs(boost::uint16_t hw_rev); +usrp2_regs_t usrp2_get_regs(bool); //////////////////////////////////////////////////// // Settings Bus, Slave #7, Not Byte Addressable! -- cgit v1.2.3 From 258d9bb45fbe7a0fa246f860eee7bf3e3b978fe3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 11 Nov 2010 17:57:59 -0800 Subject: usrp-n: populated name properties to use the generated cname from iface --- host/lib/usrp/usrp2/codec_impl.cpp | 18 ++++++++++++++++-- host/lib/usrp/usrp2/dboard_impl.cpp | 4 ++-- host/lib/usrp/usrp2/dsp_impl.cpp | 4 ++-- host/lib/usrp/usrp2/mboard_impl.cpp | 10 +++++----- host/lib/usrp/usrp2/usrp2_iface.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 4 ++-- 6 files changed, 28 insertions(+), 14 deletions(-) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 5f4937643..998d55297 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -59,7 +59,21 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case CODEC_PROP_NAME: - val = std::string("usrp2 adc"); + switch(_iface->get_rev()){ + case usrp2_iface::USRP_N200: + case usrp2_iface::USRP_N210: + val = std::string(_iface->get_cname() + " adc - ads62p44"); + break; + + case usrp2_iface::USRP2_REV3: + case usrp2_iface::USRP2_REV4: + val = std::string(_iface->get_cname() + " adc - ltc2284"); + break; + + case usrp2_iface::USRP_NXXX: + val = std::string(_iface->get_cname() + " adc - ??????"); + break; + } return; case CODEC_PROP_OTHERS: @@ -139,7 +153,7 @@ void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case CODEC_PROP_NAME: - val = std::string("usrp2 dac - ad9777"); + val = std::string(_iface->get_cname() + " dac - ad9777"); return; case CODEC_PROP_OTHERS: diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 540c9fefb..f839a4058 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -64,7 +64,7 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string("usrp2 dboard (rx unit)"); + val = std::string(_iface->get_cname() + " dboard (rx unit)"); return; case DBOARD_PROP_SUBDEV: @@ -121,7 +121,7 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string("usrp2 dboard (tx unit)"); + val = std::string(_iface->get_cname() + " dboard (tx unit)"); return; case DBOARD_PROP_SUBDEV: diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index c8da03955..243a8e905 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -61,7 +61,7 @@ void usrp2_mboard_impl::ddc_get(const wax::obj &key_, wax::obj &val){ switch(key.as()){ case DSP_PROP_NAME: - val = std::string("usrp2 ddc0"); + val = std::string(_iface->get_cname() + " ddc0"); return; case DSP_PROP_OTHERS: @@ -144,7 +144,7 @@ void usrp2_mboard_impl::duc_get(const wax::obj &key_, wax::obj &val){ switch(key.as()){ case DSP_PROP_NAME: - val = std::string("usrp2 duc0"); + val = std::string(_iface->get_cname() + " duc0"); return; case DSP_PROP_OTHERS: diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 5b47045e2..3df89d327 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -133,14 +133,14 @@ void usrp2_mboard_impl::update_clock_config(void){ switch(_clock_config.pps_source){ case clock_config_t::PPS_SMA: pps_flags |= U2_FLAG_TIME64_PPS_SMA; break; case clock_config_t::PPS_MIMO: pps_flags |= U2_FLAG_TIME64_PPS_MIMO; break; - default: throw std::runtime_error("usrp2: unhandled clock configuration pps source"); + default: throw std::runtime_error("unhandled clock configuration pps source"); } //translate pps polarity enums switch(_clock_config.pps_polarity){ case clock_config_t::PPS_POS: pps_flags |= U2_FLAG_TIME64_PPS_POSEDGE; break; case clock_config_t::PPS_NEG: pps_flags |= U2_FLAG_TIME64_PPS_NEGEDGE; break; - default: throw std::runtime_error("usrp2: unhandled clock configuration pps polarity"); + default: throw std::runtime_error("unhandled clock configuration pps polarity"); } //set the pps flags @@ -154,7 +154,7 @@ void usrp2_mboard_impl::update_clock_config(void){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x12); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; case clock_config_t::REF_MIMO: _iface->poke32(_iface->regs.misc_ctrl_clock, 0x15); break; - default: throw std::runtime_error("usrp2: unhandled clock configuration reference source"); + default: throw std::runtime_error("unhandled clock configuration reference source"); } _clock_ctrl->enable_external_ref(true); //USRP2P has an internal 10MHz TCXO break; @@ -165,7 +165,7 @@ void usrp2_mboard_impl::update_clock_config(void){ case clock_config_t::REF_INT : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x10); break; case clock_config_t::REF_SMA : _iface->poke32(_iface->regs.misc_ctrl_clock, 0x1C); break; case clock_config_t::REF_MIMO: _iface->poke32(_iface->regs.misc_ctrl_clock, 0x15); break; - default: throw std::runtime_error("usrp2: unhandled clock configuration reference source"); + default: throw std::runtime_error("unhandled clock configuration reference source"); } _clock_ctrl->enable_external_ref(_clock_config.ref_source != clock_config_t::REF_INT); break; @@ -212,7 +212,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case MBOARD_PROP_NAME: - val = str(boost::format("usrp2 mboard%d - rev %s") % _index % _iface->mb_eeprom["rev"]); + val = _iface->get_cname() + " mboard"; return; case MBOARD_PROP_OTHERS: diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 01df68010..7208a47cf 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -269,7 +269,7 @@ public: if (len == 0) break; //timeout //didnt get seq or bad packet, continue looking... } - throw std::runtime_error("usrp2 no control response"); + throw std::runtime_error(this->get_cname() + ": no control response"); } rev_type get_rev(void){ diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 01a753d9e..42fe9c018 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -214,8 +214,8 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DEVICE_PROP_NAME: - if (_mboards.size() > 1) val = std::string("usrp2 mimo device"); - else val = std::string("usrp2 device"); + if (_mboards.size() > 1) val = std::string("USRP-NXXX mimo device"); + else val = std::string("USRP-NXXX device"); return; case DEVICE_PROP_MBOARD: -- cgit v1.2.3 From b08ac6273fa6dd1e757ecaeb0b316592696099f7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 11 Nov 2010 19:13:22 -0800 Subject: uhd: removed windows warnings, added string formatting in usrp-n --- host/lib/usrp/dboard/db_dbsrx2.cpp | 2 +- host/lib/usrp/dboard/db_rfx.cpp | 2 +- host/lib/usrp/usrp2/codec_impl.cpp | 14 +++++++------- host/lib/usrp/usrp2/dboard_impl.cpp | 4 ++-- host/lib/usrp/usrp2/dsp_impl.cpp | 4 ++-- host/lib/usrp/usrp2/usrp2_iface.cpp | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) (limited to 'host/lib/usrp/usrp2/codec_impl.cpp') diff --git a/host/lib/usrp/dboard/db_dbsrx2.cpp b/host/lib/usrp/dboard/db_dbsrx2.cpp index bf5528688..cdafd6a78 100644 --- a/host/lib/usrp/dboard/db_dbsrx2.cpp +++ b/host/lib/usrp/dboard/db_dbsrx2.cpp @@ -203,7 +203,7 @@ dbsrx2::dbsrx2(ctor_args_t args) : rx_dboard_base(args){ set_bandwidth(40e6); // default bandwidth from datasheet get_locked(); - _max2112_write_regs.bbg = dbsrx2_gain_ranges["BBG"].start(); + _max2112_write_regs.bbg = boost::math::iround(dbsrx2_gain_ranges["BBG"].start()); send_reg(0x9, 0x9); } diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 4e73fb3a3..74a9fb37b 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -171,7 +171,7 @@ rfx_xcvr::rfx_xcvr( ): xcvr_dboard_base(args), _freq_range(freq_range), - _rx_gain_ranges((this->get_rx_id() == 0x0024)? + _rx_gain_ranges((get_rx_id() == 0x0024)? rfx400_rx_gain_ranges : rfx_rx_gain_ranges ), _div2(map_list_of diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 998d55297..e417bc340 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -30,9 +30,9 @@ using namespace boost::assign; //this only applies to USRP2P static const uhd::dict codec_rx_gain_ranges = map_list_of - ("analog", gain_range_t(0, 3.5, 3.5)) - ("digital", gain_range_t(0, 6.0, 0.5)) - ("digital-fine", gain_range_t(0, 0.5, 0.05)); + ("analog", gain_range_t(0, float(3.5), float(3.5))) + ("digital", gain_range_t(0, float(6.0), float(0.5))) + ("digital-fine", gain_range_t(0, float(0.5), float(0.05))); /*********************************************************************** @@ -62,16 +62,16 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ switch(_iface->get_rev()){ case usrp2_iface::USRP_N200: case usrp2_iface::USRP_N210: - val = std::string(_iface->get_cname() + " adc - ads62p44"); + val = _iface->get_cname() + " adc - ads62p44"; break; case usrp2_iface::USRP2_REV3: case usrp2_iface::USRP2_REV4: - val = std::string(_iface->get_cname() + " adc - ltc2284"); + val = _iface->get_cname() + " adc - ltc2284"; break; case usrp2_iface::USRP_NXXX: - val = std::string(_iface->get_cname() + " adc - ??????"); + val = _iface->get_cname() + " adc - ??????"; break; } return; @@ -153,7 +153,7 @@ void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case CODEC_PROP_NAME: - val = std::string(_iface->get_cname() + " dac - ad9777"); + val = _iface->get_cname() + " dac - ad9777"; return; case CODEC_PROP_OTHERS: diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index f839a4058..4192c4f78 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -64,7 +64,7 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string(_iface->get_cname() + " dboard (rx unit)"); + val = _iface->get_cname() + " dboard (rx unit)"; return; case DBOARD_PROP_SUBDEV: @@ -121,7 +121,7 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as()){ case DBOARD_PROP_NAME: - val = std::string(_iface->get_cname() + " dboard (tx unit)"); + val = _iface->get_cname() + " dboard (tx unit)"; return; case DBOARD_PROP_SUBDEV: diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 243a8e905..77ed594f5 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -61,7 +61,7 @@ void usrp2_mboard_impl::ddc_get(const wax::obj &key_, wax::obj &val){ switch(key.as()){ case DSP_PROP_NAME: - val = std::string(_iface->get_cname() + " ddc0"); + val = _iface->get_cname() + " ddc0"; return; case DSP_PROP_OTHERS: @@ -144,7 +144,7 @@ void usrp2_mboard_impl::duc_get(const wax::obj &key_, wax::obj &val){ switch(key.as()){ case DSP_PROP_NAME: - val = std::string(_iface->get_cname() + " duc0"); + val = _iface->get_cname() + " duc0"; return; case DSP_PROP_OTHERS: diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 7208a47cf..2b32faffb 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -274,8 +274,8 @@ public: rev_type get_rev(void){ switch (boost::lexical_cast(mb_eeprom["rev"])){ - case 0x0003: return USRP2_REV3; - case 0x0004: return USRP2_REV4; + case 0x0300: return USRP2_REV3; + case 0x0400: return USRP2_REV4; case 0x0A00: return USRP_N200; case 0x0A01: return USRP_N210; } -- cgit v1.2.3