summaryrefslogtreecommitdiffstats
path: root/host/lib/usrp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-24 00:02:10 -0700
committerJosh Blum <josh@joshknows.com>2010-07-24 00:02:10 -0700
commit707b103ce5f3b9cc299e741c968c35bd4038b610 (patch)
tree4c8543785bc3eb0f49ab0b5b7ccfc635e7392c40 /host/lib/usrp
parent4a6543bd481370ae924ca90c325d5cd5b2dfe692 (diff)
downloaduhd-707b103ce5f3b9cc299e741c968c35bd4038b610.tar.gz
uhd-707b103ce5f3b9cc299e741c968c35bd4038b610.tar.bz2
uhd-707b103ce5f3b9cc299e741c968c35bd4038b610.zip
usrp: added gain group support usrp2 dboard and to wrapper implementations
Diffstat (limited to 'host/lib/usrp')
-rw-r--r--host/lib/usrp/CMakeLists.txt2
-rw-r--r--host/lib/usrp/mimo_usrp.cpp17
-rw-r--r--host/lib/usrp/misc_utils.cpp71
-rw-r--r--host/lib/usrp/misc_utils.hpp35
-rw-r--r--host/lib/usrp/simple_usrp.cpp17
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp18
6 files changed, 145 insertions, 15 deletions
diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt
index 814affdd0..4f0710b20 100644
--- a/host/lib/usrp/CMakeLists.txt
+++ b/host/lib/usrp/CMakeLists.txt
@@ -24,6 +24,8 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_SOURCE_DIR}/lib/usrp/dboard_manager.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.hpp
${CMAKE_SOURCE_DIR}/lib/usrp/mimo_usrp.cpp
+ ${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.cpp
+ ${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.hpp
${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/tune_helper.cpp
)
diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp
index ec0f1dcc8..6b9318c39 100644
--- a/host/lib/usrp/mimo_usrp.cpp
+++ b/host/lib/usrp/mimo_usrp.cpp
@@ -18,6 +18,7 @@
#include <uhd/usrp/mimo_usrp.hpp>
#include <uhd/usrp/tune_helper.hpp>
#include <uhd/utils/assert.hpp>
+#include <uhd/utils/gain_group.hpp>
#include <uhd/utils/algorithm.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
@@ -56,11 +57,13 @@ public:
_rx_dboards.push_back(_mboards.back()[MBOARD_PROP_RX_DBOARD]);
std::string rx_subdev_in_use = _rx_dboards.back()[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
_rx_subdevs.push_back(_rx_dboards.back()[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)]);
+ _rx_gain_groups.push_back(_rx_dboards.back()[named_prop_t(DBOARD_PROP_GAIN_GROUP, rx_subdev_in_use)].as<gain_group::sptr>());
//extract tx subdevice
_tx_dboards.push_back(_mboards.back()[MBOARD_PROP_TX_DBOARD]);
std::string tx_subdev_in_use = _tx_dboards.back()[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
_tx_subdevs.push_back(_tx_dboards.back()[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)]);
+ _tx_gain_groups.push_back(_tx_dboards.back()[named_prop_t(DBOARD_PROP_GAIN_GROUP, tx_subdev_in_use)].as<gain_group::sptr>());
}
//set the clock config across all mboards (TODO set through api)
@@ -201,15 +204,15 @@ public:
}
void set_rx_gain(size_t chan, float gain){
- _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN] = gain;
+ _rx_gain_groups.at(chan)->set_value(gain);
}
float get_rx_gain(size_t chan){
- return _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN].as<float>();
+ return _rx_gain_groups.at(chan)->get_value();
}
gain_range_t get_rx_gain_range(size_t chan){
- return _rx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ return _rx_gain_groups.at(chan)->get_range();
}
void set_rx_antenna(size_t chan, const std::string &ant){
@@ -268,15 +271,15 @@ public:
}
void set_tx_gain(size_t chan, float gain){
- _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN] = gain;
+ _tx_gain_groups.at(chan)->set_value(gain);
}
float get_tx_gain(size_t chan){
- return _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN].as<float>();
+ return _tx_gain_groups.at(chan)->get_value();
}
gain_range_t get_tx_gain_range(size_t chan){
- return _tx_subdevs.at(chan)[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ return _tx_gain_groups.at(chan)->get_range();
}
void set_tx_antenna(size_t chan, const std::string &ant){
@@ -304,6 +307,8 @@ private:
std::vector<wax::obj> _tx_dboards;
std::vector<wax::obj> _rx_subdevs;
std::vector<wax::obj> _tx_subdevs;
+ std::vector<gain_group::sptr> _rx_gain_groups;
+ std::vector<gain_group::sptr> _tx_gain_groups;
//shadows
double _rx_rate, _tx_rate;
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp
new file mode 100644
index 000000000..2e94e9d47
--- /dev/null
+++ b/host/lib/usrp/misc_utils.cpp
@@ -0,0 +1,71 @@
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+#include "misc_utils.hpp"
+#include <uhd/utils/gain_group.hpp>
+#include <uhd/usrp/subdev_props.hpp>
+#include <uhd/usrp/codec_props.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/***********************************************************************
+ * gain group functions
+ **********************************************************************/
+static void gg_set_iq_value(wax::obj codec, const std::string &name, float gain){
+ codec[named_prop_t(CODEC_PROP_GAIN_I, name)] = gain;
+ codec[named_prop_t(CODEC_PROP_GAIN_Q, name)] = gain;
+}
+
+gain_group::sptr usrp::make_gain_group(wax::obj subdev, wax::obj codec){
+ gain_group::sptr gg = gain_group::make();
+ gain_fcns_t fcns;
+ //add all the subdev gains first (antenna to dsp order)
+ BOOST_FOREACH(const std::string &name, subdev[SUBDEV_PROP_GAIN_NAMES].as<prop_names_t>()){
+ fcns.get_range = boost::bind(&wax::obj::as<gain_range_t>, subdev[named_prop_t(SUBDEV_PROP_GAIN_RANGE, name)]);
+ fcns.get_value = boost::bind(&wax::obj::as<float>, subdev[named_prop_t(SUBDEV_PROP_GAIN, name)]);
+ fcns.set_value = boost::bind(&wax::obj::operator[], subdev[named_prop_t(SUBDEV_PROP_GAIN, name)], _1);
+ gg->register_fcns(fcns);
+ }
+ //add all the codec gains last (antenna to dsp order)
+ BOOST_FOREACH(const std::string &name, codec[CODEC_PROP_GAIN_NAMES].as<prop_names_t>()){
+ fcns.get_range = boost::bind(&wax::obj::as<gain_range_t>, codec[named_prop_t(CODEC_PROP_GAIN_RANGE, name)]);
+
+ //register the value functions depending upon the connection type
+ switch(subdev[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){
+ case SUBDEV_CONN_COMPLEX_IQ:
+ case SUBDEV_CONN_COMPLEX_QI:
+ fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_I, name)]); //same as Q
+ fcns.set_value = boost::bind(&gg_set_iq_value, codec, name, _1); //sets both
+ break;
+
+ case SUBDEV_CONN_REAL_I:
+ fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_I, name)]);
+ fcns.set_value = boost::bind(&wax::obj::operator[], codec[named_prop_t(CODEC_PROP_GAIN_I, name)], _1);
+ break;
+
+ case SUBDEV_CONN_REAL_Q:
+ fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_Q, name)]);
+ fcns.set_value = boost::bind(&wax::obj::operator[], codec[named_prop_t(CODEC_PROP_GAIN_Q, name)], _1);
+ break;
+ }
+ gg->register_fcns(fcns);
+ }
+ return gg;
+}
diff --git a/host/lib/usrp/misc_utils.hpp b/host/lib/usrp/misc_utils.hpp
new file mode 100644
index 000000000..7fe3c899d
--- /dev/null
+++ b/host/lib/usrp/misc_utils.hpp
@@ -0,0 +1,35 @@
+//
+// 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 <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP
+#define INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP
+
+#include <uhd/config.hpp>
+#include <uhd/wax.hpp>
+#include <uhd/utils/gain_group.hpp>
+
+namespace uhd{ namespace usrp{
+
+ /*!
+ * Create a gain group that represents the subdevice and its codec.
+ */
+ gain_group::sptr make_gain_group(wax::obj subdev, wax::obj codec);
+
+}} //namespace
+
+#endif /* INCLUDED_LIBUHD_USRP_MISC_UTILS_HPP */
+
diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp
index 5cb9511f4..704232782 100644
--- a/host/lib/usrp/simple_usrp.cpp
+++ b/host/lib/usrp/simple_usrp.cpp
@@ -18,6 +18,7 @@
#include <uhd/usrp/simple_usrp.hpp>
#include <uhd/usrp/tune_helper.hpp>
#include <uhd/utils/assert.hpp>
+#include <uhd/utils/gain_group.hpp>
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/usrp/device_props.hpp>
@@ -50,11 +51,13 @@ public:
_rx_dboard = _mboard[MBOARD_PROP_RX_DBOARD];
std::string rx_subdev_in_use = _rx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
_rx_subdev = _rx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, rx_subdev_in_use)];
+ _rx_gain_group = _rx_dboard[named_prop_t(DBOARD_PROP_GAIN_GROUP, rx_subdev_in_use)].as<gain_group::sptr>();
//extract tx subdevice
_tx_dboard = _mboard[MBOARD_PROP_TX_DBOARD];
std::string tx_subdev_in_use = _tx_dboard[DBOARD_PROP_USED_SUBDEVS].as<prop_names_t>().at(0);
_tx_subdev = _tx_dboard[named_prop_t(DBOARD_PROP_SUBDEV, tx_subdev_in_use)];
+ _tx_gain_group = _tx_dboard[named_prop_t(DBOARD_PROP_GAIN_GROUP, tx_subdev_in_use)].as<gain_group::sptr>();
}
~simple_usrp_impl(void){
@@ -139,15 +142,15 @@ public:
}
void set_rx_gain(float gain){
- _rx_subdev[SUBDEV_PROP_GAIN] = gain;
+ _rx_gain_group->set_value(gain);
}
float get_rx_gain(void){
- return _rx_subdev[SUBDEV_PROP_GAIN].as<float>();
+ return _rx_gain_group->get_value();
}
gain_range_t get_rx_gain_range(void){
- return _rx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ return _rx_gain_group->get_range();
}
void set_rx_antenna(const std::string &ant){
@@ -198,15 +201,15 @@ public:
}
void set_tx_gain(float gain){
- _tx_subdev[SUBDEV_PROP_GAIN] = gain;
+ _tx_gain_group->set_value(gain);
}
float get_tx_gain(void){
- return _tx_subdev[SUBDEV_PROP_GAIN].as<float>();
+ return _tx_gain_group->get_value();
}
gain_range_t get_tx_gain_range(void){
- return _tx_subdev[SUBDEV_PROP_GAIN_RANGE].as<gain_range_t>();
+ return _tx_gain_group->get_range();
}
void set_tx_antenna(const std::string &ant){
@@ -234,6 +237,8 @@ private:
wax::obj _tx_dboard;
wax::obj _rx_subdev;
wax::obj _tx_subdev;
+ gain_group::sptr _rx_gain_group;
+ gain_group::sptr _tx_gain_group;
};
/***********************************************************************
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index de091fcdc..e0d6beafc 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -15,10 +15,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
#include "../dsp_utils.hpp"
+#include "../misc_utils.hpp"
#include <uhd/usrp/subdev_props.hpp>
#include <uhd/usrp/dboard_props.hpp>
#include <uhd/utils/assert.hpp>
@@ -93,7 +93,13 @@ void usrp2_mboard_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){
return;
case DBOARD_PROP_CODEC:
- val = _rx_codec_proxy;
+ val = _rx_codec_proxy->get_link();
+ return;
+
+ case DBOARD_PROP_GAIN_GROUP:
+ val = make_gain_group(
+ _dboard_manager->get_rx_subdev(name), _rx_codec_proxy->get_link()
+ );
return;
default: UHD_THROW_PROP_GET_ERROR();
@@ -156,7 +162,13 @@ void usrp2_mboard_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){
return;
case DBOARD_PROP_CODEC:
- val = _tx_codec_proxy;
+ val = _tx_codec_proxy->get_link();
+ return;
+
+ case DBOARD_PROP_GAIN_GROUP:
+ val = make_gain_group(
+ _dboard_manager->get_tx_subdev(name), _tx_codec_proxy->get_link()
+ );
return;
default: UHD_THROW_PROP_GET_ERROR();