From 00b33d97487602960f70506ea59cc504d31d91f6 Mon Sep 17 00:00:00 2001 From: Jason Abele Date: Tue, 1 Jun 2010 16:33:45 -0700 Subject: Refactor WBX and RFX to use conventions more like XCVR --- host/lib/usrp/dboard/db_rfx.cpp | 48 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'host/lib/usrp/dboard/db_rfx.cpp') diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 89e707718..5b90bbbad 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -91,7 +91,7 @@ private: uhd::dict _div2; double _rx_lo_freq, _tx_lo_freq; std::string _rx_ant; - float _rx_pga0_gain; + uhd::dict _rx_gains; void set_rx_lo_freq(double freq); void set_tx_lo_freq(double freq); @@ -100,8 +100,6 @@ private: void set_rx_gain(float gain, const std::string &name); void set_tx_gain(float gain, const std::string &name); - void set_rx_pga0_gain(float gain); - /*! * Set the LO frequency for the particular dboard unit. * \param unit which unit rx or tx @@ -198,7 +196,10 @@ rfx_xcvr::rfx_xcvr( set_rx_lo_freq((_freq_range.min + _freq_range.max)/2.0); set_tx_lo_freq((_freq_range.min + _freq_range.max)/2.0); set_rx_ant("RX2"); - set_rx_pga0_gain(0); + + BOOST_FOREACH(const std::string &name, rfx_rx_gain_ranges.keys()){ + set_rx_gain(rfx_rx_gain_ranges[name].min, name); + } } rfx_xcvr::~rfx_xcvr(void){ @@ -230,6 +231,20 @@ void rfx_xcvr::set_tx_ant(const std::string &ant){ /*********************************************************************** * Gain Handling **********************************************************************/ +static float rx_pga0_gain_to_dac_volts(float &gain){ + //voltage level constants (negative slope) + static const float max_volts = float(.2), min_volts = float(1.2); + static const float slope = (max_volts-min_volts)/45; + + //calculate the voltage for the aux dac + float dac_volts = std::clip(gain*slope + min_volts, max_volts, min_volts); + + //the actual gain setting + gain = (dac_volts - min_volts)/slope; + + return dac_volts; +} + void rfx_xcvr::set_tx_gain(float, const std::string &name){ assert_has(rfx_tx_gain_ranges.keys(), name, "rfx tx gain name"); UHD_ASSERT_THROW(false); //no gains to set @@ -238,26 +253,15 @@ void rfx_xcvr::set_tx_gain(float, const std::string &name){ void rfx_xcvr::set_rx_gain(float gain, const std::string &name){ assert_has(rfx_rx_gain_ranges.keys(), name, "rfx rx gain name"); if(name == "PGA0"){ - this->set_rx_pga0_gain(gain); + float dac_volts = rx_pga0_gain_to_dac_volts(gain); + _rx_gains[name] = gain; + + //write the new voltage to the aux dac + this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, 1, dac_volts); } else UHD_ASSERT_THROW(false); } -void rfx_xcvr::set_rx_pga0_gain(float gain){ - //voltage level constants (negative slope) - static const float max_volts = float(.2), min_volts = float(1.2); - static const float slope = (max_volts-min_volts)/45; - - //calculate the voltage for the aux dac - float dac_volts = std::clip(gain*slope + min_volts, max_volts, min_volts); - - //write the new voltage to the aux dac - this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, 1, dac_volts); - - //shadow the actual gain setting - _rx_pga0_gain = (dac_volts - min_volts)/slope; -} - /*********************************************************************** * Tuning **********************************************************************/ @@ -397,8 +401,8 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - UHD_ASSERT_THROW(name == "PGA0"); - val = _rx_pga0_gain; + assert_has(_rx_gains.keys(), name, "rfx rx gain name"); + val = _rx_gains[name]; return; case SUBDEV_PROP_GAIN_RANGE: -- cgit v1.2.3 From 33193a06c1bc197a603f831109533230dc14b4c9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 2 Jun 2010 15:49:53 -0700 Subject: replaced the assert falses with an invalid code path exception --- host/include/uhd/utils/exception.hpp | 7 +++++++ host/lib/usrp/dboard/db_rfx.cpp | 4 ++-- host/lib/usrp/dboard/db_wbx.cpp | 4 ++-- host/lib/usrp/dboard/db_xcvr2450.cpp | 6 +++--- host/lib/usrp/dboard_manager.cpp | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) (limited to 'host/lib/usrp/dboard/db_rfx.cpp') diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp index 40e81fae0..e74c19b9c 100644 --- a/host/include/uhd/utils/exception.hpp +++ b/host/include/uhd/utils/exception.hpp @@ -35,4 +35,11 @@ " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ ) +/*! + * Throws an invalid code path exception with throw-site information. + * Use this macro in places that code execution is not supposed to go. + */ +#define UHD_THROW_INVALID_CODE_PATH() \ + throw std::runtime_error(UHD_THROW_SITE_INFO("invalid code path")) + #endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 5b90bbbad..17fc00d24 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -247,7 +247,7 @@ static float rx_pga0_gain_to_dac_volts(float &gain){ void rfx_xcvr::set_tx_gain(float, const std::string &name){ assert_has(rfx_tx_gain_ranges.keys(), name, "rfx tx gain name"); - UHD_ASSERT_THROW(false); //no gains to set + UHD_THROW_INVALID_CODE_PATH(); //no gains to set } void rfx_xcvr::set_rx_gain(float gain, const std::string &name){ @@ -259,7 +259,7 @@ void rfx_xcvr::set_rx_gain(float gain, const std::string &name){ //write the new voltage to the aux dac this->get_iface()->write_aux_dac(dboard_iface::UNIT_RX, 1, dac_volts); } - else UHD_ASSERT_THROW(false); + else UHD_THROW_INVALID_CODE_PATH(); } /*********************************************************************** diff --git a/host/lib/usrp/dboard/db_wbx.cpp b/host/lib/usrp/dboard/db_wbx.cpp index 4cf168c6b..95dcb3802 100644 --- a/host/lib/usrp/dboard/db_wbx.cpp +++ b/host/lib/usrp/dboard/db_wbx.cpp @@ -248,7 +248,7 @@ void wbx_xcvr::set_tx_gain(float gain, const std::string &name){ //write the new voltage to the aux dac this->get_iface()->write_aux_dac(dboard_iface::UNIT_TX, 0, dac_volts); } - else UHD_ASSERT_THROW(false); + else UHD_THROW_INVALID_CODE_PATH(); } void wbx_xcvr::set_rx_gain(float gain, const std::string &name){ @@ -260,7 +260,7 @@ void wbx_xcvr::set_rx_gain(float gain, const std::string &name){ //write the new gain to atr regs update_atr(); } - else UHD_ASSERT_THROW(false); + else UHD_THROW_INVALID_CODE_PATH(); } /*********************************************************************** diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index d4d5f184e..974a378bd 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -375,7 +375,7 @@ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(float &gain){ gain = 5; return max2829_regs_t::TX_BASEBAND_GAIN_5DB; } - UHD_ASSERT_THROW(false); + UHD_THROW_INVALID_CODE_PATH(); } /*! @@ -417,7 +417,7 @@ void xcvr2450::set_tx_gain(float gain, const std::string &name){ _max2829_regs.tx_baseband_gain = gain_to_tx_bb_reg(gain); send_reg(0x9); } - else UHD_ASSERT_THROW(false); + else UHD_THROW_INVALID_CODE_PATH(); _tx_gains[name] = gain; } @@ -431,7 +431,7 @@ void xcvr2450::set_rx_gain(float gain, const std::string &name){ _max2829_regs.rx_lna_gain = gain_to_rx_lna_reg(gain); send_reg(0xB); } - else UHD_ASSERT_THROW(false); + else UHD_THROW_INVALID_CODE_PATH(); _rx_gains[name] = gain; } diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 01352039e..35ddfc4ee 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -181,7 +181,7 @@ static args_t get_dboard_args( switch(unit){ case dboard_iface::UNIT_RX: return get_dboard_args(unit, 0x0001); case dboard_iface::UNIT_TX: return get_dboard_args(unit, 0x0000); - default: UHD_ASSERT_THROW(false); + default: UHD_THROW_INVALID_CODE_PATH(); } } -- cgit v1.2.3