From d8f3980e45458cf68c8efaa029e492a1b8d08354 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Mon, 26 Jul 2010 16:33:17 -0700 Subject: Host-side changes to work with the USRP2+. Change summary: Added clock register selection between USRP2/USRP2+ Added memory map selection between USRP2/USRP2+ Added ADS62P44 support for USRP2+ --- host/lib/usrp/usrp2/clock_ctrl.cpp | 105 +++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 34 deletions(-) (limited to 'host/lib/usrp/usrp2/clock_ctrl.cpp') diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index b9be037c0..5ed8ec079 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -18,6 +18,7 @@ #include "clock_ctrl.hpp" #include "ad9510_regs.hpp" #include "usrp2_regs.hpp" //spi slave constants +#include "usrp2_clk_regs.hpp" #include #include @@ -29,10 +30,12 @@ using namespace uhd; class usrp2_clock_ctrl_impl : public usrp2_clock_ctrl{ public: usrp2_clock_ctrl_impl(usrp2_iface::sptr iface){ - _iface = 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()); _ad9510_regs.cp_current_setting = ad9510_regs_t::CP_CURRENT_SETTING_3_0MA; - this->write_reg(0x09); + this->write_reg(clk_regs.pll_3); // Setup the clock registers to 100MHz: // This was already done by the firmware (or the host couldnt communicate). @@ -42,20 +45,20 @@ public: _ad9510_regs.pll_power_down = ad9510_regs_t::PLL_POWER_DOWN_NORMAL; _ad9510_regs.prescaler_value = ad9510_regs_t::PRESCALER_VALUE_DIV2; - this->write_reg(0x0A); + this->write_reg(clk_regs.pll_4); _ad9510_regs.acounter = 0; - this->write_reg(0x04); + this->write_reg(clk_regs.acounter); _ad9510_regs.bcounter_msb = 0; _ad9510_regs.bcounter_lsb = 5; - this->write_reg(0x05); - this->write_reg(0x06); + this->write_reg(clk_regs.bcounter_msb); + this->write_reg(clk_regs.bcounter_lsb); _ad9510_regs.ref_counter_msb = 0; _ad9510_regs.ref_counter_lsb = 1; // r divider = 1 - this->write_reg(0x0B); - this->write_reg(0x0C); + this->write_reg(clk_regs.ref_counter_msb); + this->write_reg(clk_regs.ref_counter_lsb); /* regs will be updated in commands below */ @@ -76,11 +79,12 @@ public: } //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; _ad9510_regs.output_level_lvds_out7 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT7_1_75MA; - this->write_reg(0x43); + this->write_reg(clk_regs.output(clk_regs.rx_db)); this->update_regs(); } @@ -96,8 +100,8 @@ public: _ad9510_regs.divider_low_cycles_out7 = low - 1; _ad9510_regs.divider_high_cycles_out7 = high - 1; //write the registers - this->write_reg(0x56); - this->write_reg(0x57); + this->write_reg(clk_regs.div_lo(clk_regs.rx_db)); + this->write_reg(clk_regs.div_hi(clk_regs.rx_db)); this->update_regs(); } @@ -107,29 +111,50 @@ public: return rates; } - //uses output clock 6 (cmos) + //uses output clock 6 (cmos) on USRP2 and output clock 5 (cmos) on USRP2+ void enable_tx_dboard_clock(bool enb){ - _ad9510_regs.power_down_lvds_cmos_out6 = enb? 0 : 1; - _ad9510_regs.lvds_cmos_select_out6 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT6_CMOS; - _ad9510_regs.output_level_lvds_out6 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT6_1_75MA; - this->write_reg(0x42); + switch(clk_regs.tx_db) { + case 5: //USRP2+ + _ad9510_regs.power_down_lvds_cmos_out5 = enb? 0 : 1; + _ad9510_regs.lvds_cmos_select_out5 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT5_CMOS; + _ad9510_regs.output_level_lvds_out5 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT5_1_75MA; + break; + case 6: //USRP2 + _ad9510_regs.power_down_lvds_cmos_out6 = enb? 0 : 1; + _ad9510_regs.lvds_cmos_select_out6 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT6_CMOS; + _ad9510_regs.output_level_lvds_out6 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT6_1_75MA; + break; + } + + this->write_reg(clk_regs.output(clk_regs.tx_db)); this->update_regs(); } void set_rate_tx_dboard_clock(double rate){ assert_has(get_rates_tx_dboard_clock(), rate, "tx dboard clock rate"); size_t divider = size_t(rate/get_master_clock_rate()); - //bypass when the divider ratio is one - _ad9510_regs.bypass_divider_out6 = (divider == 1)? 1 : 0; //calculate the low and high dividers size_t high = divider/2; size_t low = divider - high; - //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out6 = low - 1; - _ad9510_regs.divider_high_cycles_out6 = high - 1; + + switch(clk_regs.tx_db) { + case 5: //USRP2+ + _ad9510_regs.bypass_divider_out5 = (divider == 1)? 1 : 0; + _ad9510_regs.divider_low_cycles_out5 = low - 1; + _ad9510_regs.divider_high_cycles_out5 = high - 1; + break; + case 6: //USRP2 + //bypass when the divider ratio is one + _ad9510_regs.bypass_divider_out6 = (divider == 1)? 1 : 0; + //set the registers (divider - 1) + _ad9510_regs.divider_low_cycles_out6 = low - 1; + _ad9510_regs.divider_high_cycles_out6 = high - 1; + break; + } + //write the registers - this->write_reg(0x54); - this->write_reg(0x55); + this->write_reg(clk_regs.div_hi(clk_regs.tx_db)); + this->write_reg(clk_regs.div_lo(clk_regs.tx_db)); this->update_regs(); } @@ -147,7 +172,7 @@ public: ad9510_regs_t::CHARGE_PUMP_MODE_3STATE ; _ad9510_regs.pll_mux_control = ad9510_regs_t::PLL_MUX_CONTROL_DLD_HIGH; _ad9510_regs.pfd_polarity = ad9510_regs_t::PFD_POLARITY_POS; - this->write_reg(0x08); + this->write_reg(clk_regs.pll_2); this->update_regs(); } @@ -170,32 +195,44 @@ private: */ void update_regs(void){ _ad9510_regs.update_registers = 1; - this->write_reg(0x5a); + this->write_reg(clk_regs.update); } //uses output clock 3 (pecl) + //this is the same between USRP2 and USRP2+ and doesn't get a switch statement void enable_dac_clock(bool enb){ _ad9510_regs.power_down_lvpecl_out3 = (enb)? ad9510_regs_t::POWER_DOWN_LVPECL_OUT3_NORMAL : ad9510_regs_t::POWER_DOWN_LVPECL_OUT3_SAFE_PD; _ad9510_regs.output_level_lvpecl_out3 = ad9510_regs_t::OUTPUT_LEVEL_LVPECL_OUT3_810MV; _ad9510_regs.bypass_divider_out3 = 1; - this->write_reg(0x3F); - this->write_reg(0x4F); + this->write_reg(clk_regs.output(clk_regs.dac)); + this->write_reg(clk_regs.div_hi(clk_regs.dac)); this->update_regs(); } - //uses output clock 4 (lvds) + //uses output clock 4 (lvds) on USRP2 and output clock 2 (lvpecl) on USRP2+ void enable_adc_clock(bool enb){ - _ad9510_regs.power_down_lvds_cmos_out4 = enb? 0 : 1; - _ad9510_regs.lvds_cmos_select_out4 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT4_LVDS; - _ad9510_regs.output_level_lvds_out4 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT4_1_75MA; - _ad9510_regs.bypass_divider_out4 = 1; - this->write_reg(0x40); - this->write_reg(0x51); + switch(clk_regs.adc) { + case 2: + _ad9510_regs.power_down_lvpecl_out2 = enb? ad9510_regs_t::POWER_DOWN_LVPECL_OUT2_NORMAL : ad9510_regs_t::POWER_DOWN_LVPECL_OUT2_SAFE_PD; + _ad9510_regs.output_level_lvpecl_out2 = ad9510_regs_t::OUTPUT_LEVEL_LVPECL_OUT2_500MV; + _ad9510_regs.bypass_divider_out2 = 1; + break; + case 4: + _ad9510_regs.power_down_lvds_cmos_out4 = enb? 0 : 1; + _ad9510_regs.lvds_cmos_select_out4 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT4_LVDS; + _ad9510_regs.output_level_lvds_out4 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT4_1_75MA; + _ad9510_regs.bypass_divider_out4 = 1; + break; + } + + this->write_reg(clk_regs.output(clk_regs.adc)); + this->write_reg(clk_regs.div_hi(clk_regs.adc)); this->update_regs(); } + usrp2_clk_regs_t clk_regs; usrp2_iface::sptr _iface; ad9510_regs_t _ad9510_regs; }; -- cgit v1.2.3 From b6dae16e5bbddf1fcb9bc77a526f912a15cabbae Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Tue, 5 Oct 2010 16:54:34 -0700 Subject: USRP2P: internal reference selected by default. --- host/lib/usrp/usrp2/clock_ctrl.cpp | 13 +++++++++++++ host/lib/usrp/usrp2/clock_ctrl.hpp | 6 ++++++ host/lib/usrp/usrp2/mboard_impl.cpp | 4 ++-- host/utils/usrp2p_fw_update.py | 12 ++++++------ 4 files changed, 27 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp/usrp2/clock_ctrl.cpp') diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 72f92c081..c3dc4917e 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -212,6 +212,19 @@ public: std::vector get_rates_tx_dboard_clock(void){ return get_rates_rx_dboard_clock(); //same master clock, same dividers... } + + void enable_test_clock(bool enb) { + _ad9510_regs.power_down_lvpecl_out0 = enb? + ad9510_regs_t::POWER_DOWN_LVPECL_OUT0_NORMAL : + ad9510_regs_t::POWER_DOWN_LVPECL_OUT0_SAFE_PD; + _ad9510_regs.output_level_lvpecl_out0 = ad9510_regs_t::OUTPUT_LEVEL_LVPECL_OUT0_810MV; + _ad9510_regs.divider_low_cycles_out0 = 0; + _ad9510_regs.divider_high_cycles_out0 = 0; + _ad9510_regs.bypass_divider_out0 = 1; + this->write_reg(0x3c); + this->write_reg(0x48); + this->write_reg(0x49); + } /*! * If we are to use an external reference, enable the charge pump. diff --git a/host/lib/usrp/usrp2/clock_ctrl.hpp b/host/lib/usrp/usrp2/clock_ctrl.hpp index 70a104a81..db6c52c83 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.hpp +++ b/host/lib/usrp/usrp2/clock_ctrl.hpp @@ -83,6 +83,12 @@ public: * \param enb true to enable */ virtual void enable_external_ref(bool enb) = 0; + + /*! + * Enable/disable test clock output. + * \param enb true to enable + */ + virtual void enable_test_clock(bool enb) = 0; /*! * TODO other clock control api here.... diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 3ae21e621..8c5ef49ed 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -168,7 +168,6 @@ void usrp2_mboard_impl::update_clock_config(void){ default: throw std::runtime_error("usrp2: unhandled clock configuration reference source"); } } else { - 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; @@ -178,7 +177,8 @@ void usrp2_mboard_impl::update_clock_config(void){ } //clock source ref 10mhz - bool use_external = _clock_config.ref_source != clock_config_t::REF_INT; + 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 _clock_ctrl->enable_external_ref(use_external); } diff --git a/host/utils/usrp2p_fw_update.py b/host/utils/usrp2p_fw_update.py index ed3465c0e..1cd735796 100755 --- a/host/utils/usrp2p_fw_update.py +++ b/host/utils/usrp2p_fw_update.py @@ -40,12 +40,12 @@ USRP2_FW_PROTO_VERSION = 6 #from bootloader_utils.h -#define FPGA_IMAGE_SIZE_BYTES 1572864 -#define FW_IMAGE_SIZE_BYTES 31744 -#define SAFE_FPGA_IMAGE_LOCATION_ADDR 0x00000000 -#define SAFE_FW_IMAGE_LOCATION_ADDR 0x003F0000 -#define PROD_FPGA_IMAGE_LOCATION_ADDR 0x00180000 -#define PROD_FW_IMAGE_LOCATION_ADDR 0x00300000 +FPGA_IMAGE_SIZE_BYTES = 1572864 +FW_IMAGE_SIZE_BYTES = 31744 +SAFE_FPGA_IMAGE_LOCATION_ADDR = 0x00000000 +SAFE_FW_IMAGE_LOCATION_ADDR = 0x003F0000 +PROD_FPGA_IMAGE_LOCATION_ADDR = 0x00180000 +PROD_FW_IMAGE_LOCATION_ADDR = 0x00300000 FLASH_DATA_PACKET_SIZE = 256 -- 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/clock_ctrl.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/clock_ctrl.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 8fe1e7b29aacce7f75ae36e81706bbde02749b97 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Wed, 10 Nov 2010 12:02:28 -0800 Subject: 2+: moved mboard_rev to usrp2/ in preparation for merging upstream --- host/include/uhd/usrp/mboard_rev.hpp | 118 --------------------------------- host/lib/usrp/CMakeLists.txt | 1 - host/lib/usrp/mboard_rev.cpp | 91 ------------------------- host/lib/usrp/usrp2/CMakeLists.txt | 2 + host/lib/usrp/usrp2/clock_ctrl.cpp | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 2 +- host/lib/usrp/usrp2/mboard_rev.cpp | 89 +++++++++++++++++++++++++ host/lib/usrp/usrp2/mboard_rev.hpp | 114 +++++++++++++++++++++++++++++++ host/lib/usrp/usrp2/usrp2_clk_regs.hpp | 4 +- host/lib/usrp/usrp2/usrp2_iface.cpp | 8 +-- host/lib/usrp/usrp2/usrp2_iface.hpp | 8 +-- host/lib/usrp/usrp2/usrp2_regs.cpp | 4 +- host/lib/usrp/usrp2/usrp2_regs.hpp | 6 +- host/utils/CMakeLists.txt | 3 - host/utils/usrp2_burn_mb_rev.cpp | 82 ----------------------- 15 files changed, 222 insertions(+), 312 deletions(-) delete mode 100644 host/include/uhd/usrp/mboard_rev.hpp delete mode 100644 host/lib/usrp/mboard_rev.cpp create mode 100644 host/lib/usrp/usrp2/mboard_rev.cpp create mode 100644 host/lib/usrp/usrp2/mboard_rev.hpp delete mode 100644 host/utils/usrp2_burn_mb_rev.cpp (limited to 'host/lib/usrp/usrp2/clock_ctrl.cpp') diff --git a/host/include/uhd/usrp/mboard_rev.hpp b/host/include/uhd/usrp/mboard_rev.hpp deleted file mode 100644 index be968d01d..000000000 --- a/host/include/uhd/usrp/mboard_rev.hpp +++ /dev/null @@ -1,118 +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_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, 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); - -}} //namespace - -#endif /* INCLUDED_UHD_USRP_MBOARD_REV_HPP */ diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 6c7f6adf4..eeb181e0b 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -23,7 +23,6 @@ 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/misc_utils.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/multi_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/single_usrp.cpp diff --git a/host/lib/usrp/mboard_rev.cpp b/host/lib/usrp/mboard_rev.cpp deleted file mode 100644 index 41600951f..000000000 --- a/host/lib/usrp/mboard_rev.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include -#include -#include -#include - -using namespace uhd::usrp; - -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 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/CMakeLists.txt b/host/lib/usrp/usrp2/CMakeLists.txt index f7984fce5..a09c833bd 100644 --- a/host/lib/usrp/usrp2/CMakeLists.txt +++ b/host/lib/usrp/usrp2/CMakeLists.txt @@ -48,6 +48,8 @@ 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 c652b592b..04bbd6ba3 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -17,7 +17,7 @@ #include "clock_ctrl.hpp" #include "ad9510_regs.hpp" -#include +#include "mboard_rev.hpp" #include "usrp2_regs.hpp" //spi slave constants #include "usrp2_clk_regs.hpp" #include diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 805fd23db..9ccf90bbb 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include "mboard_rev.hpp" #include #include #include diff --git a/host/lib/usrp/usrp2/mboard_rev.cpp b/host/lib/usrp/usrp2/mboard_rev.cpp new file mode 100644 index 000000000..9d0ff89f5 --- /dev/null +++ b/host/lib/usrp/usrp2/mboard_rev.cpp @@ -0,0 +1,89 @@ +// +// 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 new file mode 100644 index 000000000..a1b1d9605 --- /dev/null +++ b/host/lib/usrp/usrp2/mboard_rev.hpp @@ -0,0 +1,114 @@ +// +// 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 edbdfa15d..fcfd1e227 100644 --- a/host/lib/usrp/usrp2/usrp2_clk_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_clk_regs.hpp @@ -18,13 +18,13 @@ #ifndef INCLUDED_USRP2_CLK_REGS_HPP #define INCLUDED_USRP2_CLK_REGS_HPP -#include +#include "mboard_rev.hpp" #include "usrp2_regs.hpp" class usrp2_clk_regs_t { public: usrp2_clk_regs_t(void) { ; } - usrp2_clk_regs_t(uhd::usrp::mboard_rev_t hw_rev) { + usrp2_clk_regs_t(mboard_rev_t hw_rev) { test = 0; fpga = 1; adc = (hw_rev.is_usrp2p()) ? 2 : 4; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index a5b39ceed..d5ac14155 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -19,7 +19,7 @@ #include "usrp2_iface.hpp" #include #include -#include +#include "mboard_rev.hpp" #include #include #include //used for htonl and ntohl @@ -54,7 +54,7 @@ public: //extract the mboard rev numbers byte_vector_t rev_bytes = read_eeprom(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, 2); - set_hw_rev(uhd::usrp::mboard_rev_t::from_uint16(rev_bytes.at(0) | (rev_bytes.at(1) << 8))); + set_hw_rev(mboard_rev_t::from_uint16(rev_bytes.at(0) | (rev_bytes.at(1) << 8))); //check the fpga compatibility number const boost::uint32_t fpga_compat_num = this->peek32(this->regs.compat_num_rb); @@ -265,12 +265,12 @@ public: /*********************************************************************** * Get/set hardware revision **********************************************************************/ - void set_hw_rev(uhd::usrp::mboard_rev_t 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 } - uhd::usrp::mboard_rev_t 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 53a8e4bc8..fee3b23af 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include "mboard_rev.hpp" #include #include "fw_common.h" #include "usrp2_regs.hpp" @@ -113,12 +113,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(uhd::usrp::mboard_rev_t rev) = 0; + virtual void set_hw_rev(mboard_rev_t rev) = 0; /*! Return the hardware revision number * \return hardware revision */ - virtual uhd::usrp::mboard_rev_t get_hw_rev(void) = 0; + virtual mboard_rev_t get_hw_rev(void) = 0; /*! * Register map selected from USRP2/USRP2+. @@ -127,7 +127,7 @@ public: /*! * Hardware revision as returned by the device. */ - uhd::usrp::mboard_rev_t hw_rev; + mboard_rev_t hw_rev; }; #endif /* INCLUDED_USRP2_IFACE_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index f9b54b76e..0f0360c95 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -15,14 +15,14 @@ // along with this program. If not, see . // -#include +#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(uhd::usrp::mboard_rev_t hw_rev) { +usrp2_regs_t usrp2_get_regs(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.is_usrp2p()) ? USRP2P_MISC_OUTPUT_BASE : USRP2_MISC_OUTPUT_BASE, diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index bb15ed496..0d68c65c2 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -18,7 +18,7 @@ #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP -#include +#include "mboard_rev.hpp" #define USRP2_MISC_OUTPUT_BASE 0xD400 #define USRP2_GPIO_BASE 0xC800 @@ -30,7 +30,7 @@ #define USRP2P_ATR_BASE 0x3800 #define USRP2P_BP_STATUS_BASE 0x3300 -const uhd::usrp::mboard_rev_t USRP2P_FIRST_HW_REV(0x0A00); +const mboard_rev_t USRP2P_FIRST_HW_REV(0x0A00); typedef struct { int sr_misc; @@ -103,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(uhd::usrp::mboard_rev_t hw_rev); +usrp2_regs_t usrp2_get_regs(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 083c7629c..a95864ca7 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -45,9 +45,6 @@ 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 deleted file mode 100644 index 59b072d17..000000000 --- a/host/utils/usrp2_burn_mb_rev.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - - -#include -#include -#include -#include -#include -#include -#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/clock_ctrl.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/clock_ctrl.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