aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp2/codec_impl.cpp
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-07-27 13:56:59 -0700
committerNick Foster <nick@nerdnetworks.org>2010-07-27 13:56:59 -0700
commit02f5347c71f53f11162796b70f15fe74adcc3aa0 (patch)
treeda16244b75364320dc99360ceca7c89889b96b75 /host/lib/usrp/usrp2/codec_impl.cpp
parent5196d701384a9986ba6a166a02c6775e83f264f6 (diff)
downloaduhd-02f5347c71f53f11162796b70f15fe74adcc3aa0.tar.gz
uhd-02f5347c71f53f11162796b70f15fe74adcc3aa0.tar.bz2
uhd-02f5347c71f53f11162796b70f15fe74adcc3aa0.zip
Added gain support for USRP2+ ADC.
Diffstat (limited to 'host/lib/usrp/usrp2/codec_impl.cpp')
-rw-r--r--host/lib/usrp/usrp2/codec_impl.cpp63
1 files changed, 60 insertions, 3 deletions
diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp
index b9d51abf5..b246a35f8 100644
--- a/host/lib/usrp/usrp2/codec_impl.cpp
+++ b/host/lib/usrp/usrp2/codec_impl.cpp
@@ -17,10 +17,22 @@
#include "usrp2_impl.hpp"
#include <uhd/usrp/codec_props.hpp>
+#include <uhd/types/dict.hpp>
+#include <uhd/types/ranges.hpp>
#include <boost/bind.hpp>
+#include <boost/assign/list_of.hpp>
+#include <uhd/utils/assert.hpp>
+#include <uhd/utils/exception.hpp>
using namespace uhd;
using namespace uhd::usrp;
+using namespace boost::assign;
+
+//this only applies to USRP2P
+static const uhd::dict<std::string, gain_range_t> codec_rx_gain_ranges = map_list_of
+ ("analog", gain_range_t(0, 3.5, float(3.5)))
+ ("digital", gain_range_t(0, 6.45, float(0.05)));
+
/***********************************************************************
* Helper Methods
@@ -55,18 +67,63 @@ void usrp2_mboard_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){
return;
case CODEC_PROP_GAIN_NAMES:
- val = prop_names_t(); //no gain elements to be controlled
+ if(_iface->get_hw_rev() >= USRP2P_FIRST_HW_REV) {
+ val = prop_names_t(codec_rx_gain_ranges.keys());
+ } else val = prop_names_t();
+ return;
+
+ case CODEC_PROP_GAIN_I:
+ case CODEC_PROP_GAIN_Q:
+ assert_has(_codec_rx_gains.keys(), name, "codec rx gain name");
+ val = _codec_rx_gains[name];
return;
default: UHD_THROW_PROP_GET_ERROR();
}
}
-void usrp2_mboard_impl::rx_codec_set(const wax::obj &, const wax::obj &){
- UHD_THROW_PROP_SET_ERROR();
+void usrp2_mboard_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){
+ wax::obj key; std::string name;
+ boost::tie(key, name) = extract_named_prop(key_);
+
+ float gain;
+
+ switch(key.as<codec_prop_t>()) {
+ case CODEC_PROP_GAIN_I:
+ case CODEC_PROP_GAIN_Q:
+ if(_iface->get_hw_rev() < USRP2P_FIRST_HW_REV) UHD_THROW_PROP_SET_ERROR();//this capability is only found in USRP2P
+
+ gain = val.as<float>();
+ this->rx_codec_set_gain(gain, name); //okay. we can either have ONE gain and let codec_ctrl do the sorting between analog/digital gains, or we can have TWO gains and do the priority somewhere else.
+ return;
+
+ default:
+ UHD_THROW_PROP_SET_ERROR();
+ }
}
/***********************************************************************
+ * Helper function to set RX codec gain
+ ***********************************************************************/
+
+void usrp2_mboard_impl::rx_codec_set_gain(float gain, const std::string &name){
+ assert_has(codec_rx_gain_ranges.keys(), name, "codec rx gain name");
+
+ _codec_rx_gains[name] = gain;
+
+ if(name == "analog") {
+ _codec_ctrl->set_rx_analog_gain(gain > 0); //just turn it on or off
+ return;
+ }
+ if(name == "digital") {
+ _codec_ctrl->set_rx_digital_gain(gain);
+ return;
+ }
+ UHD_THROW_PROP_SET_ERROR();
+}
+
+
+/***********************************************************************
* TX Codec Properties
**********************************************************************/
void usrp2_mboard_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){