aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp
diff options
context:
space:
mode:
authorBen Hilburn <ben.hilburn@ettus.com>2014-03-27 17:41:13 -0700
committerBen Hilburn <ben.hilburn@ettus.com>2014-03-27 17:41:13 -0700
commitf8753a3d7f3616a49f6c0a1ae661f286a4f20c66 (patch)
treec88bee6725422d1fd4ead1f52cf63c119a3c723c /host/lib/usrp
parent89d36657a177ba3405ffb7a537a3e2f744a1e7ce (diff)
parentda99b7edc2d1cfedd9c8acf36630d799782ee455 (diff)
downloaduhd-f8753a3d7f3616a49f6c0a1ae661f286a4f20c66.tar.gz
uhd-f8753a3d7f3616a49f6c0a1ae661f286a4f20c66.tar.bz2
uhd-f8753a3d7f3616a49f6c0a1ae661f286a4f20c66.zip
Merge branch adding warning regarding MCR on the B2xx.
Diffstat (limited to 'host/lib/usrp')
-rw-r--r--host/lib/usrp/b200/b200_iface.cpp30
-rw-r--r--host/lib/usrp/b200/b200_impl.cpp39
-rw-r--r--host/lib/usrp/b200/b200_impl.hpp11
-rw-r--r--host/lib/usrp/b200/b200_io_impl.cpp44
-rw-r--r--host/lib/usrp/common/ad9361_ctrl.cpp2
-rw-r--r--host/lib/usrp/common/ad9361_ctrl.hpp23
-rw-r--r--host/lib/usrp/common/ad9361_transaction.h5
7 files changed, 129 insertions, 25 deletions
diff --git a/host/lib/usrp/b200/b200_iface.cpp b/host/lib/usrp/b200/b200_iface.cpp
index 6296b6d2d..efb9b3a35 100644
--- a/host/lib/usrp/b200/b200_iface.cpp
+++ b/host/lib/usrp/b200/b200_iface.cpp
@@ -19,6 +19,7 @@
#include <uhd/config.hpp>
#include <uhd/utils/msg.hpp>
+#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/functional/hash.hpp>
#include <boost/thread/thread.hpp>
@@ -304,10 +305,10 @@ public:
}
}
- void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64]) {
- const int bytes_to_write = 64;
- const int bytes_to_read = 64;
- const size_t read_retries = 30;
+ void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE]) {
+ const int bytes_to_write = AD9361_DISPATCH_PACKET_SIZE;
+ const int bytes_to_read = AD9361_DISPATCH_PACKET_SIZE;
+ const size_t read_retries = 5;
int ret = fx3_control_write(B200_VREQ_AD9361_CTRL_WRITE, 0x00, 0x00, (unsigned char *)in_buff, bytes_to_write);
if (ret < 0)
@@ -317,9 +318,26 @@ public:
for (size_t i = 0; i < read_retries; i++)
{
- ret = fx3_control_read(B200_VREQ_AD9361_CTRL_READ, 0x00, 0x00, out_buff, bytes_to_read, 1000);
+ ret = fx3_control_read(B200_VREQ_AD9361_CTRL_READ, 0x00, 0x00, out_buff, bytes_to_read, 3000);
if (ret < 0)
- throw uhd::io_error((boost::format("Failed to read AD9361 (%d: %s)") % ret % libusb_error_name(ret)).str());
+ {
+ if (ret == LIBUSB_ERROR_TIMEOUT)
+ {
+ UHD_LOG << (boost::format("Failed to read AD9361 (%d: %s). Retrying (%d of %d)...")
+ % ret
+ % libusb_error_name(ret)
+ % (i+1)
+ % read_retries
+ ) << std::endl;
+ }
+ else
+ {
+ throw uhd::io_error((boost::format("Failed to read AD9361 (%d: %s)")
+ % ret
+ % libusb_error_name(ret)
+ ).str());
+ }
+ }
if (ret == bytes_to_read)
return;
diff --git a/host/lib/usrp/b200/b200_impl.cpp b/host/lib/usrp/b200/b200_impl.cpp
index a7f9b11bd..9dd3a424d 100644
--- a/host/lib/usrp/b200/b200_impl.cpp
+++ b/host/lib/usrp/b200/b200_impl.cpp
@@ -157,12 +157,12 @@ b200_impl::b200_impl(const device_addr_t &device_addr)
const fs_path mb_path = "/mboards/0";
//try to match the given device address with something on the USB bus
- uint16_t vid = B200_VENDOR_ID;
- uint16_t pid = B200_PRODUCT_ID;
+ boost::uint16_t vid = B200_VENDOR_ID;
+ boost::uint16_t pid = B200_PRODUCT_ID;
if (device_addr.has_key("vid"))
- sscanf(device_addr.get("vid").c_str(), "%x", &vid);
+ sscanf(device_addr.get("vid").c_str(), "%hx", &vid);
if (device_addr.has_key("pid"))
- sscanf(device_addr.get("pid").c_str(), "%x", &pid);
+ sscanf(device_addr.get("pid").c_str(), "%hx", &pid);
std::vector<usb_device_handle::sptr> device_list =
usb_device_handle::get_device_list(vid, pid);
@@ -663,9 +663,40 @@ void b200_impl::codec_loopback_self_test(wb_iface::sptr iface)
/***********************************************************************
* Sample and tick rate comprehension below
**********************************************************************/
+void b200_impl::enforce_tick_rate_limits(size_t chan_count, double tick_rate, const char* direction /*= NULL*/)
+{
+ const size_t max_chans = 2;
+ if (chan_count > max_chans)
+ {
+ throw uhd::value_error(boost::str(
+ boost::format("cannot not setup %d %s channels (maximum is %d)")
+ % chan_count
+ % (direction ? direction : "data")
+ % max_chans
+ ));
+ }
+ else
+ {
+ const double max_tick_rate = ((chan_count <= 1) ? AD9361_1_CHAN_CLOCK_RATE_MAX : AD9361_2_CHAN_CLOCK_RATE_MAX);
+ if (tick_rate > max_tick_rate)
+ {
+ throw uhd::value_error(boost::str(
+ boost::format("current master clock rate (%.2f MHz) exceeds maximum possible master clock rate (%.2f MHz) when using %d %s channels")
+ % (tick_rate/1e6)
+ % (max_tick_rate/1e6)
+ % chan_count
+ % (direction ? direction : "data")
+ ));
+ }
+ }
+}
+
double b200_impl::set_tick_rate(const double rate)
{
UHD_MSG(status) << "Asking for clock rate " << rate/1e6 << " MHz\n";
+
+ check_tick_rate_with_current_streamers(rate); // Defined in b200_io_impl.cpp
+
_tick_rate = _codec_ctrl->set_clock_rate(rate);
UHD_MSG(status) << "Actually got clock rate " << _tick_rate/1e6 << " MHz\n";
diff --git a/host/lib/usrp/b200/b200_impl.hpp b/host/lib/usrp/b200/b200_impl.hpp
index a370e54f9..7d98a8f8d 100644
--- a/host/lib/usrp/b200/b200_impl.hpp
+++ b/host/lib/usrp/b200/b200_impl.hpp
@@ -91,6 +91,7 @@ public:
uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &args);
uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args);
bool recv_async_msg(uhd::async_metadata_t &, double);
+ void check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const char* direction = NULL);
private:
//controllers
@@ -177,13 +178,15 @@ private:
void update_enables(void);
void update_atrs(void);
- void update_tick_rate(const double);
- void update_rx_samp_rate(const size_t, const double);
- void update_tx_samp_rate(const size_t, const double);
-
double _tick_rate;
double get_tick_rate(void){return _tick_rate;}
double set_tick_rate(const double rate);
+ void update_tick_rate(const double);
+ void enforce_tick_rate_limits(size_t chan_count, double tick_rate, const char* direction = NULL);
+ void check_tick_rate_with_current_streamers(double rate);
+
+ void update_rx_samp_rate(const size_t, const double);
+ void update_tx_samp_rate(const size_t, const double);
};
#endif /* INCLUDED_B200_IMPL_HPP */
diff --git a/host/lib/usrp/b200/b200_io_impl.cpp b/host/lib/usrp/b200/b200_io_impl.cpp
index 4f072c4d4..9f6d593fe 100644
--- a/host/lib/usrp/b200/b200_io_impl.cpp
+++ b/host/lib/usrp/b200/b200_io_impl.cpp
@@ -23,6 +23,7 @@
#include "async_packet_handler.hpp"
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
+#include <set>
using namespace uhd;
using namespace uhd::usrp;
@@ -31,8 +32,47 @@ using namespace uhd::transport;
/***********************************************************************
* update streamer rates
**********************************************************************/
+void b200_impl::check_tick_rate_with_current_streamers(double rate)
+{
+ size_t max_tx_chan_count = 0, max_rx_chan_count = 0;
+ BOOST_FOREACH(radio_perifs_t &perif, _radio_perifs)
+ {
+ {
+ boost::shared_ptr<sph::recv_packet_streamer> rx_streamer =
+ boost::dynamic_pointer_cast<sph::recv_packet_streamer>(perif.rx_streamer.lock());
+ if (rx_streamer)
+ max_rx_chan_count = std::max(max_rx_chan_count, rx_streamer->get_num_channels());
+ }
+
+ {
+ boost::shared_ptr<sph::send_packet_streamer> tx_streamer =
+ boost::dynamic_pointer_cast<sph::send_packet_streamer>(perif.tx_streamer.lock());
+ if (tx_streamer)
+ max_tx_chan_count = std::max(max_tx_chan_count, tx_streamer->get_num_channels());
+ }
+ }
+
+ // Defined in b200_impl.cpp
+ enforce_tick_rate_limits(max_rx_chan_count, rate, "RX");
+ enforce_tick_rate_limits(max_tx_chan_count, rate, "TX");
+}
+
+void b200_impl::check_streamer_args(const uhd::stream_args_t &args, double tick_rate, const char* direction /*= NULL*/)
+{
+ std::set<size_t> chans_set;
+ for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++)
+ {
+ const size_t chan = args.channels[stream_i];
+ chans_set.insert(chan);
+ }
+
+ enforce_tick_rate_limits(chans_set.size(), tick_rate, direction); // Defined in b200_impl.cpp
+}
+
void b200_impl::update_tick_rate(const double rate)
{
+ check_tick_rate_with_current_streamers(rate);
+
BOOST_FOREACH(radio_perifs_t &perif, _radio_perifs)
{
boost::shared_ptr<sph::recv_packet_streamer> my_streamer =
@@ -222,6 +262,8 @@ rx_streamer::sptr b200_impl::get_rx_stream(const uhd::stream_args_t &args_)
if (args.otw_format.empty()) args.otw_format = "sc16";
args.channels = args.channels.empty()? std::vector<size_t>(1, 0) : args.channels;
+ check_streamer_args(args, this->get_tick_rate(), "RX");
+
boost::shared_ptr<sph::recv_packet_streamer> my_streamer;
for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++)
{
@@ -325,6 +367,8 @@ tx_streamer::sptr b200_impl::get_tx_stream(const uhd::stream_args_t &args_)
if (args.otw_format.empty()) args.otw_format = "sc16";
args.channels = args.channels.empty()? std::vector<size_t>(1, 0) : args.channels;
+ check_streamer_args(args, this->get_tick_rate(), "TX");
+
boost::shared_ptr<sph::send_packet_streamer> my_streamer;
for (size_t stream_i = 0; stream_i < args.channels.size(); stream_i++)
{
diff --git a/host/lib/usrp/common/ad9361_ctrl.cpp b/host/lib/usrp/common/ad9361_ctrl.cpp
index 1afa2fbb7..10496f2a9 100644
--- a/host/lib/usrp/common/ad9361_ctrl.cpp
+++ b/host/lib/usrp/common/ad9361_ctrl.cpp
@@ -151,7 +151,7 @@ struct ad9361_ctrl_impl : public ad9361_ctrl
//handle errors
const size_t len = my_strnlen(out->error_msg, AD9361_TRANSACTION_MAX_ERROR_MSG);
const std::string error_msg(out->error_msg, len);
- if (not error_msg.empty()) throw uhd::runtime_error("ad9361 do transaction: " + error_msg);
+ if (not error_msg.empty()) throw uhd::runtime_error("[ad9361_ctrl::do_transaction] firmware reported: \"" + error_msg + "\"");
//return result done!
return *out;
diff --git a/host/lib/usrp/common/ad9361_ctrl.hpp b/host/lib/usrp/common/ad9361_ctrl.hpp
index fd8012764..098b5dae8 100644
--- a/host/lib/usrp/common/ad9361_ctrl.hpp
+++ b/host/lib/usrp/common/ad9361_ctrl.hpp
@@ -27,10 +27,17 @@
#include <vector>
#include <string>
+#include "ad9361_transaction.h"
+
+
+static const double AD9361_CLOCK_RATE_MAX = 61.44e6;
+static const double AD9361_1_CHAN_CLOCK_RATE_MAX = AD9361_CLOCK_RATE_MAX;
+static const double AD9361_2_CHAN_CLOCK_RATE_MAX = (AD9361_1_CHAN_CLOCK_RATE_MAX / 2);
+
struct ad9361_ctrl_iface_type
{
- virtual void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64]) = 0;
+ virtual void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE]) = 0;
};
typedef boost::shared_ptr<ad9361_ctrl_iface_type> ad9361_ctrl_iface_sptr;
@@ -42,18 +49,18 @@ struct ad9361_ctrl_over_zc : ad9361_ctrl_iface_type
_xport = xport;
}
- void ad9361_transact(const unsigned char in_buff[64], unsigned char out_buff[64])
+ void ad9361_transact(const unsigned char in_buff[AD9361_DISPATCH_PACKET_SIZE], unsigned char out_buff[AD9361_DISPATCH_PACKET_SIZE])
{
{
uhd::transport::managed_send_buffer::sptr buff = _xport->get_send_buff(10.0);
- if (not buff or buff->size() < 64) throw std::runtime_error("ad9361_ctrl_over_zc send timeout");
- std::memcpy(buff->cast<void *>(), in_buff, 64);
- buff->commit(64);
+ if (not buff or buff->size() < AD9361_DISPATCH_PACKET_SIZE) throw std::runtime_error("ad9361_ctrl_over_zc send timeout");
+ std::memcpy(buff->cast<void *>(), in_buff, AD9361_DISPATCH_PACKET_SIZE);
+ buff->commit(AD9361_DISPATCH_PACKET_SIZE);
}
{
uhd::transport::managed_recv_buffer::sptr buff = _xport->get_recv_buff(10.0);
- if (not buff or buff->size() < 64) throw std::runtime_error("ad9361_ctrl_over_zc recv timeout");
- std::memcpy(out_buff, buff->cast<const void *>(), 64);
+ if (not buff or buff->size() < AD9361_DISPATCH_PACKET_SIZE) throw std::runtime_error("ad9361_ctrl_over_zc recv timeout");
+ std::memcpy(out_buff, buff->cast<const void *>(), AD9361_DISPATCH_PACKET_SIZE);
}
}
@@ -100,7 +107,7 @@ public:
static uhd::meta_range_t get_clock_rate_range(void)
{
//return uhd::meta_range_t(220e3, 61.44e6);
- return uhd::meta_range_t(5e6, 61.44e6); //5 MHz DCM low end
+ return uhd::meta_range_t(5e6, AD9361_CLOCK_RATE_MAX); //5 MHz DCM low end
}
//! set the filter bandwidth for the frontend
diff --git a/host/lib/usrp/common/ad9361_transaction.h b/host/lib/usrp/common/ad9361_transaction.h
index 7cbad5908..693f32e41 100644
--- a/host/lib/usrp/common/ad9361_transaction.h
+++ b/host/lib/usrp/common/ad9361_transaction.h
@@ -25,8 +25,8 @@ extern "C" {
#endif
//various constants
-#define AD9361_TRANSACTION_VERSION 0x4
-#define AD9361_TRANSACTION_MAX_ERROR_MSG 40
+#define AD9361_TRANSACTION_VERSION 0x4
+#define AD9361_DISPATCH_PACKET_SIZE 64
//action types
#define AD9361_ACTION_ECHO 0
@@ -100,6 +100,7 @@ typedef struct
} ad9361_transaction_t;
+#define AD9361_TRANSACTION_MAX_ERROR_MSG (AD9361_DISPATCH_PACKET_SIZE - (sizeof(ad9361_transaction_t)-4)-1) // -4 for 'error_msg' alignment padding, -1 for terminating \0
#ifdef __cplusplus
}