summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorPhilip Balister <philip@opensdr.com>2010-10-20 20:00:09 -0400
committerPhilip Balister <philip@opensdr.com>2010-10-20 20:00:09 -0400
commit635440c5990e7a27fdb38f694123258633e85427 (patch)
tree603ff2312dd612ea7759432f51ffb7a6c7db3448 /host/lib
parent6b203950d9583ab882628311402e26cf40838aa0 (diff)
parente0c48ba5cc1033cd330e2ce73ceb03740923e954 (diff)
downloaduhd-635440c5990e7a27fdb38f694123258633e85427.tar.gz
uhd-635440c5990e7a27fdb38f694123258633e85427.tar.bz2
uhd-635440c5990e7a27fdb38f694123258633e85427.zip
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e_mmap_b2
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp192
-rw-r--r--host/lib/types.cpp21
-rw-r--r--host/lib/usrp/CMakeLists.txt4
-rw-r--r--host/lib/usrp/dboard/db_basic_and_lf.cpp14
-rw-r--r--host/lib/usrp/dboard/db_dbsrx.cpp47
-rw-r--r--host/lib/usrp/dboard/db_rfx.cpp14
-rw-r--r--host/lib/usrp/dboard/db_tvrx.cpp124
-rw-r--r--host/lib/usrp/dboard/db_unknown.cpp14
-rw-r--r--host/lib/usrp/dboard/db_wbx.cpp14
-rw-r--r--host/lib/usrp/dboard/db_xcvr2450.cpp161
-rw-r--r--host/lib/usrp/dboard_manager.cpp12
-rw-r--r--host/lib/usrp/mimo_usrp.cpp347
-rw-r--r--host/lib/usrp/misc_utils.cpp17
-rw-r--r--host/lib/usrp/multi_usrp.cpp435
-rw-r--r--host/lib/usrp/simple_usrp.cpp222
-rw-r--r--host/lib/usrp/single_usrp.cpp62
-rw-r--r--host/lib/usrp/subdev_spec.cpp4
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp6
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp21
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp23
-rw-r--r--host/lib/usrp/wrapper_utils.hpp66
-rw-r--r--host/lib/utils/thread_priority.cpp9
22 files changed, 1076 insertions, 753 deletions
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 7e28caf2d..d84aeefdd 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -35,6 +35,14 @@ namespace asio = boost::asio;
/***********************************************************************
* Constants
**********************************************************************/
+//Define this to the the boost async io calls to perform receive.
+//Otherwise, get_recv_buff uses a blocking receive with timeout.
+//#define USE_ASIO_ASYNC_RECV
+
+//Define this to the the boost async io calls to perform send.
+//Otherwise, the commit callback uses a blocking send.
+//#define USE_ASIO_ASYNC_SEND
+
//enough buffering for half a second of samples at full rate on usrp2
static const size_t MIN_RECV_SOCK_BUFF_SIZE = size_t(4 * 25e6 * 0.5);
@@ -43,8 +51,21 @@ static const size_t MIN_RECV_SOCK_BUFF_SIZE = size_t(4 * 25e6 * 0.5);
//but may change with host-based flow control.
static const size_t MIN_SEND_SOCK_BUFF_SIZE = size_t(10e3);
-//the number of async frames to allocate for each send and recv
-static const size_t DEFAULT_NUM_FRAMES = 32;
+//The number of async frames to allocate for each send and recv:
+//The non-async recv can have a very large number of recv frames
+//because the CPU overhead is independent of the number of frames.
+#ifdef USE_ASIO_ASYNC_RECV
+static const size_t DEFAULT_NUM_RECV_FRAMES = 32;
+#else
+static const size_t DEFAULT_NUM_RECV_FRAMES = MIN_RECV_SOCK_BUFF_SIZE/udp_simple::mtu;
+#endif
+//The non-async send only ever requires a single frame
+//because the buffer will be committed before a new get.
+#ifdef USE_ASIO_ASYNC_SEND
+static const size_t DEFAULT_NUM_SEND_FRAMES = 32;
+#else
+static const size_t DEFAULT_NUM_SEND_FRAMES = MIN_SEND_SOCK_BUFF_SIZE/udp_simple::mtu;;
+#endif
//a single concurrent thread for io_service seems to be the fastest
static const size_t CONCURRENCY_HINT = 1;
@@ -67,9 +88,9 @@ public:
):
_io_service(hints.cast<size_t>("concurrency_hint", CONCURRENCY_HINT)),
_recv_frame_size(size_t(hints.cast<double>("recv_frame_size", udp_simple::mtu))),
- _num_recv_frames(size_t(hints.cast<double>("num_recv_frames", DEFAULT_NUM_FRAMES))),
+ _num_recv_frames(size_t(hints.cast<double>("num_recv_frames", DEFAULT_NUM_RECV_FRAMES))),
_send_frame_size(size_t(hints.cast<double>("send_frame_size", udp_simple::mtu))),
- _num_send_frames(size_t(hints.cast<double>("num_send_frames", DEFAULT_NUM_FRAMES)))
+ _num_send_frames(size_t(hints.cast<double>("num_send_frames", DEFAULT_NUM_SEND_FRAMES)))
{
//std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
@@ -82,6 +103,13 @@ public:
_socket = new asio::ip::udp::socket(_io_service);
_socket->open(asio::ip::udp::v4());
_socket->connect(receiver_endpoint);
+ _sock_fd = _socket->native();
+ }
+
+ ~udp_zero_copy_asio_impl(void){
+ delete _work; //allow io_service run to complete
+ _thread_group.join_all(); //wait for service threads to exit
+ delete _socket;
}
void init(void){
@@ -106,10 +134,9 @@ public:
);
}
- ~udp_zero_copy_asio_impl(void){
- delete _work; //allow io_service run to complete
- _thread_group.join_all(); //wait for service threads to exit
- delete _socket;
+ void service(void){
+ set_thread_priority_safe();
+ _io_service.run();
}
//get size for internal socket buffer
@@ -126,6 +153,15 @@ public:
return get_buff_size<Opt>();
}
+ //! handle a recv callback -> push the filled memory into the fifo
+ UHD_INLINE void handle_recv(void *mem, size_t len){
+ boost::this_thread::disable_interruption di; //disable because the wait can throw
+ _pending_recv_buffs->push_with_wait(boost::asio::buffer(mem, len));
+ }
+
+ ////////////////////////////////////////////////////////////////////
+ #ifdef USE_ASIO_ASYNC_RECV
+ ////////////////////////////////////////////////////////////////////
//! pop a filled recv buffer off of the fifo and bind with the release callback
managed_recv_buffer::sptr get_recv_buff(double timeout){
boost::this_thread::disable_interruption di; //disable because the wait can throw
@@ -142,9 +178,74 @@ public:
return managed_recv_buffer::sptr();
}
+ //! release a recv buffer -> start an async recv on the buffer
+ void release(void *mem){
+ _socket->async_receive(
+ boost::asio::buffer(mem, this->get_recv_frame_size()),
+ boost::bind(
+ &udp_zero_copy_asio_impl::handle_recv,
+ shared_from_this(), mem,
+ asio::placeholders::bytes_transferred
+ )
+ );
+ }
+
+ ////////////////////////////////////////////////////////////////////
+ #else /*USE_ASIO_ASYNC_RECV*/
+ ////////////////////////////////////////////////////////////////////
+ managed_recv_buffer::sptr get_recv_buff(double timeout){
+ boost::this_thread::disable_interruption di; //disable because the wait can throw
+ asio::mutable_buffer buff;
+
+ //setup timeval for timeout
+ timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = long(timeout*1e6);
+
+ //setup rset for timeout
+ fd_set rset;
+ FD_ZERO(&rset);
+ FD_SET(_sock_fd, &rset);
+
+ //call select to perform timed wait and grab an available buffer with wait
+ //if the condition is true, call receive and return the managed buffer
+ if (
+ ::select(_sock_fd+1, &rset, NULL, NULL, &tv) > 0 and
+ _pending_recv_buffs->pop_with_timed_wait(buff, timeout)
+ ){
+ return managed_recv_buffer::make_safe(
+ asio::buffer(
+ boost::asio::buffer_cast<void *>(buff),
+ _socket->receive(asio::buffer(buff))
+ ),
+ boost::bind(
+ &udp_zero_copy_asio_impl::release,
+ shared_from_this(),
+ asio::buffer_cast<void*>(buff)
+ )
+ );
+ }
+ return managed_recv_buffer::sptr();
+ }
+
+ void release(void *mem){
+ boost::this_thread::disable_interruption di; //disable because the wait can throw
+ handle_recv(mem, this->get_recv_frame_size());
+ }
+
+ ////////////////////////////////////////////////////////////////////
+ #endif /*USE_ASIO_ASYNC_RECV*/
+ ////////////////////////////////////////////////////////////////////
+
size_t get_num_recv_frames(void) const {return _num_recv_frames;}
size_t get_recv_frame_size(void) const {return _recv_frame_size;}
+ //! handle a send callback -> push the emptied memory into the fifo
+ UHD_INLINE void handle_send(void *mem){
+ boost::this_thread::disable_interruption di; //disable because the wait can throw
+ _pending_send_buffs->push_with_wait(boost::asio::buffer(mem, this->get_send_frame_size()));
+ }
+
//! pop an empty send buffer off of the fifo and bind with the commit callback
managed_send_buffer::sptr get_send_buff(double timeout){
boost::this_thread::disable_interruption di; //disable because the wait can throw
@@ -161,43 +262,9 @@ public:
return managed_send_buffer::sptr();
}
- size_t get_num_send_frames(void) const {return _num_send_frames;}
- size_t get_send_frame_size(void) const {return _send_frame_size;}
-
-private:
- void service(void){
- set_thread_priority_safe();
- _io_service.run();
- }
-
- /*******************************************************************
- * The async send and receive callbacks
- ******************************************************************/
-
- //! handle a recv callback -> push the filled memory into the fifo
- void handle_recv(void *mem, size_t len){
- boost::this_thread::disable_interruption di; //disable because the wait can throw
- _pending_recv_buffs->push_with_wait(boost::asio::buffer(mem, len));
- }
-
- //! release a recv buffer -> start an async recv on the buffer
- void release(void *mem){
- _socket->async_receive(
- boost::asio::buffer(mem, _recv_frame_size),
- boost::bind(
- &udp_zero_copy_asio_impl::handle_recv,
- shared_from_this(), mem,
- asio::placeholders::bytes_transferred
- )
- );
- }
-
- //! handle a send callback -> push the emptied memory into the fifo
- void handle_send(void *mem){
- boost::this_thread::disable_interruption di; //disable because the wait can throw
- _pending_send_buffs->push_with_wait(boost::asio::buffer(mem, _send_frame_size));
- }
-
+ ////////////////////////////////////////////////////////////////////
+ #ifdef USE_ASIO_ASYNC_SEND
+ ////////////////////////////////////////////////////////////////////
//! commit a send buffer -> start an async send on the buffer
void commit(void *mem, size_t len){
_socket->async_send(
@@ -209,10 +276,27 @@ private:
);
}
+ ////////////////////////////////////////////////////////////////////
+ #else /*USE_ASIO_ASYNC_SEND*/
+ ////////////////////////////////////////////////////////////////////
+ void commit(void *mem, size_t len){
+ _socket->send(asio::buffer(mem, len));
+ handle_send(mem);
+ }
+
+ ////////////////////////////////////////////////////////////////////
+ #endif /*USE_ASIO_ASYNC_SEND*/
+ ////////////////////////////////////////////////////////////////////
+
+ size_t get_num_send_frames(void) const {return _num_send_frames;}
+ size_t get_send_frame_size(void) const {return _send_frame_size;}
+
+private:
//asio guts -> socket and service
asio::ip::udp::socket *_socket;
asio::io_service _io_service;
asio::io_service::work *_work;
+ int _sock_fd;
//memory management -> buffers and fifos
boost::thread_group _thread_group;
@@ -235,6 +319,13 @@ template<typename Opt> static void resize_buff_helper(
if (name == "recv") min_sock_buff_size = MIN_RECV_SOCK_BUFF_SIZE;
if (name == "send") min_sock_buff_size = MIN_SEND_SOCK_BUFF_SIZE;
+ std::string help_message;
+ #if defined(UHD_PLATFORM_LINUX)
+ help_message = str(boost::format(
+ "Please run: sudo sysctl -w net.core.%smem_max=%d\n"
+ ) % ((name == "recv")?"r":"w") % min_sock_buff_size);
+ #endif /*defined(UHD_PLATFORM_LINUX)*/
+
//resize the buffer if size was provided
if (target_size > 0){
size_t actual_size = udp_trans->resize_buff<Opt>(target_size);
@@ -246,13 +337,10 @@ template<typename Opt> static void resize_buff_helper(
"Current %s sock buff size: %d bytes"
) % name % actual_size << std::endl;
if (actual_size < target_size) uhd::print_warning(str(boost::format(
- "The %1% buffer is smaller than the requested size.\n"
- "The minimum recommended buffer size is %2% bytes.\n"
- "See the transport application notes on buffer resizing.\n"
- #if defined(UHD_PLATFORM_LINUX)
- "Please run: sudo sysctl -w net.core.rmem_max=%2%\n"
- #endif /*defined(UHD_PLATFORM_LINUX)*/
- ) % name % min_sock_buff_size));
+ "The %s buffer is smaller than the requested size.\n"
+ "The minimum recommended buffer size is %d bytes.\n"
+ "See the transport application notes on buffer resizing.\n%s"
+ ) % name % min_sock_buff_size % help_message));
}
//only enable on platforms that are happy with the large buffer resize
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index f957cd83f..6aa82b012 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -124,14 +124,14 @@ time_spec_t::time_spec_t(time_t full_secs, double frac_secs):
/* NOP */
}
-time_spec_t::time_spec_t(time_t full_secs, size_t tick_count, double tick_rate):
+time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate):
_full_secs(full_secs),
_frac_secs(double(tick_count)/tick_rate)
{
/* NOP */
}
-size_t time_spec_t::get_tick_count(double tick_rate) const{
+long time_spec_t::get_tick_count(double tick_rate) const{
return boost::math::iround(this->get_frac_secs()*tick_rate);
}
@@ -140,7 +140,9 @@ double time_spec_t::get_real_secs(void) const{
}
time_t time_spec_t::get_full_secs(void) const{
- return this->_full_secs + time_t(std::floor(this->_frac_secs));
+ double intpart;
+ std::modf(this->_frac_secs, &intpart);
+ return this->_full_secs + time_t(intpart);
}
double time_spec_t::get_frac_secs(void) const{
@@ -160,13 +162,18 @@ time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
}
bool uhd::operator==(const time_spec_t &lhs, const time_spec_t &rhs){
- return lhs.get_full_secs() == rhs.get_full_secs() and lhs.get_frac_secs() == rhs.get_frac_secs();
+ return
+ lhs.get_full_secs() == rhs.get_full_secs() and
+ lhs.get_frac_secs() == rhs.get_frac_secs()
+ ;
}
bool uhd::operator<(const time_spec_t &lhs, const time_spec_t &rhs){
- if (lhs.get_full_secs() < rhs.get_full_secs()) return true;
- if (lhs.get_full_secs() > rhs.get_full_secs()) return false;
- return lhs.get_frac_secs() < rhs.get_frac_secs();
+ return (
+ (lhs.get_full_secs() < rhs.get_full_secs()) or (
+ (lhs.get_full_secs() == rhs.get_full_secs()) and
+ (lhs.get_frac_secs() < rhs.get_frac_secs())
+ ));
}
/***********************************************************************
diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt
index 73197bca4..c264252e1 100644
--- a/host/lib/usrp/CMakeLists.txt
+++ b/host/lib/usrp/CMakeLists.txt
@@ -23,12 +23,12 @@ 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/mimo_usrp.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/misc_utils.cpp
- ${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp
+ ${CMAKE_SOURCE_DIR}/lib/usrp/multi_usrp.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/single_usrp.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/subdev_spec.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/tune_helper.cpp
+ ${CMAKE_SOURCE_DIR}/lib/usrp/wrapper_utils.hpp
)
INCLUDE(${CMAKE_SOURCE_DIR}/lib/usrp/dboard/CMakeLists.txt)
diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp
index 4b0d8bf27..41f6f8002 100644
--- a/host/lib/usrp/dboard/db_basic_and_lf.cpp
+++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp
@@ -149,6 +149,10 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
val = sd_name_to_conn[get_subdev_name()];
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -178,6 +182,9 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_FREQ:
return; // it wont do you much good, but you can set it
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
@@ -241,6 +248,10 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){
val = sd_name_to_conn[get_subdev_name()];
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -270,6 +281,9 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_FREQ:
return; // it wont do you much good, but you can set it
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp
index 81434f054..939a79e58 100644
--- a/host/lib/usrp/dboard/db_dbsrx.cpp
+++ b/host/lib/usrp/dboard/db_dbsrx.cpp
@@ -69,7 +69,7 @@ public:
private:
double _lo_freq;
- float _bandwidth;
+ double _bandwidth;
uhd::dict<std::string, float> _gains;
max2118_write_regs_t _max2118_write_regs;
max2118_read_regs_t _max2118_read_regs;
@@ -79,7 +79,7 @@ private:
void set_lo_freq(double target_freq);
void set_gain(float gain, const std::string &name);
- void set_bandwidth(float bandwidth);
+ void set_bandwidth(double bandwidth);
void send_reg(boost::uint8_t start_reg, boost::uint8_t stop_reg){
start_reg = boost::uint8_t(std::clip(int(start_reg), 0x0, 0x5));
@@ -239,7 +239,6 @@ void dbsrx::set_lo_freq(double target_freq){
double actual_freq=0.0, pfd_freq=0.0, ref_clock=0.0;
int R=0, N=0, r=0, m=0;
bool update_filter_settings = false;
-
//choose refclock
std::vector<double> clock_rates = this->get_iface()->get_clock_rates(dboard_iface::UNIT_RX);
BOOST_FOREACH(ref_clock, std::reversed(std::sorted(clock_rates))){
@@ -251,7 +250,7 @@ void dbsrx::set_lo_freq(double target_freq){
if(dbsrx_debug) std::cerr << boost::format(
"DBSRX: trying ref_clock %f and m_divider %d"
- ) % (this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX)) % m << std::endl;
+ ) % (ref_clock) % m << std::endl;
if (m >= 32) continue;
@@ -277,15 +276,17 @@ void dbsrx::set_lo_freq(double target_freq){
}
}
- //Assert because we failed to find a suitable combination of ref_clock, R and N
- UHD_ASSERT_THROW(ref_clock/(1 << m) < 1e6 or ref_clock/(1 << m) > 2.5e6);
- UHD_ASSERT_THROW((pfd_freq < dbsrx_pfd_freq_range.min) or (pfd_freq > dbsrx_pfd_freq_range.max));
- UHD_ASSERT_THROW((N < 256) or (N > 32768));
done_loop:
+ //Assert because we failed to find a suitable combination of ref_clock, R and N
+ UHD_ASSERT_THROW(ref_clock <= 27.0e6 and ref_clock >= 0.0);
+ UHD_ASSERT_THROW(ref_clock/m >= 1e6 and ref_clock/m <= 2.5e6);
+ UHD_ASSERT_THROW((pfd_freq >= dbsrx_pfd_freq_range.min) and (pfd_freq <= dbsrx_pfd_freq_range.max));
+ UHD_ASSERT_THROW((N >= 256) and (N <= 32768));
+
if(dbsrx_debug) std::cerr << boost::format(
- "DBSRX: choose ref_clock %f and m_divider %d"
- ) % (this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX)) % m << std::endl;
+ "DBSRX: choose ref_clock (current: %f, new: %f) and m_divider %d"
+ ) % (this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX)) % ref_clock % m << std::endl;
//if ref_clock or m divider changed, we need to update the filter settings
if (ref_clock != this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX) or m != _max2118_write_regs.m_divider) update_filter_settings = true;
@@ -349,7 +350,7 @@ void dbsrx::set_lo_freq(double target_freq){
"DBSRX: Tuning exceeded vco range, _max2118_write_regs.osc_band == %d\n"
) % int(_max2118_write_regs.osc_band))
);
- UHD_ASSERT_THROW(_max2118_read_regs.adc == 0);
+ UHD_ASSERT_THROW(_max2118_read_regs.adc != 0); //just to cause a throw
}
if (_max2118_write_regs.osc_band <= 0) break;
_max2118_write_regs.osc_band -= 1;
@@ -363,7 +364,7 @@ void dbsrx::set_lo_freq(double target_freq){
"DBSRX: Tuning exceeded vco range, _max2118_write_regs.osc_band == %d\n"
) % int(_max2118_write_regs.osc_band))
);
- UHD_ASSERT_THROW(_max2118_read_regs.adc == 0);
+ UHD_ASSERT_THROW(_max2118_read_regs.adc != 7); //just to cause a throw
}
if (_max2118_write_regs.osc_band >= 7) break;
_max2118_write_regs.osc_band += 1;
@@ -401,6 +402,7 @@ void dbsrx::set_lo_freq(double target_freq){
<< boost::format(" Ref Freq=%fMHz\n") % (ref_clock/1e6)
<< boost::format(" Target Freq=%fMHz\n") % (target_freq/1e6)
<< boost::format(" Actual Freq=%fMHz\n") % (_lo_freq/1e6)
+ << boost::format(" VCO Freq=%fMHz\n") % (vco_freq/1e6)
<< std::endl;
if (update_filter_settings) set_bandwidth(_bandwidth);
@@ -480,9 +482,9 @@ void dbsrx::set_gain(float gain, const std::string &name){
/***********************************************************************
* Bandwidth Handling
**********************************************************************/
-void dbsrx::set_bandwidth(float bandwidth){
+void dbsrx::set_bandwidth(double bandwidth){
//clip the input
- bandwidth = std::clip<float>(bandwidth, 4e6, 33e6);
+ bandwidth = std::clip<double>(bandwidth, 4e6, 33e6);
double ref_clock = this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX);
@@ -492,7 +494,7 @@ void dbsrx::set_bandwidth(float bandwidth){
_max2118_write_regs.f_dac = std::clip<int>(int((((bandwidth*_max2118_write_regs.m_divider)/ref_clock) - 4)/0.145),0,127);
//determine actual bandwidth
- _bandwidth = float((ref_clock/(_max2118_write_regs.m_divider))*(4+0.145*_max2118_write_regs.f_dac));
+ _bandwidth = double((ref_clock/(_max2118_write_regs.m_divider))*(4+0.145*_max2118_write_regs.f_dac));
if (dbsrx_debug) std::cerr << boost::format(
"DBSRX Filter Bandwidth: %f MHz, m: %d, f_dac: %d\n"
@@ -551,6 +553,10 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -559,12 +565,6 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){
val = this->get_locked();
return;
-/*
- case SUBDEV_PROP_RSSI:
- val = this->get_rssi();
- return;
-*/
-
case SUBDEV_PROP_BANDWIDTH:
val = _bandwidth;
return;
@@ -587,8 +587,11 @@ void dbsrx::rx_set(const wax::obj &key_, const wax::obj &val){
this->set_gain(val.as<float>(), key.name);
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
case SUBDEV_PROP_BANDWIDTH:
- this->set_bandwidth(val.as<float>());
+ this->set_bandwidth(val.as<double>());
return;
default: UHD_THROW_PROP_SET_ERROR();
diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp
index c3ab96e59..cfc34381e 100644
--- a/host/lib/usrp/dboard/db_rfx.cpp
+++ b/host/lib/usrp/dboard/db_rfx.cpp
@@ -444,6 +444,10 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_QI;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -474,6 +478,9 @@ void rfx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){
this->set_rx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
@@ -524,6 +531,10 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = true;
return;
@@ -554,6 +565,9 @@ void rfx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){
this->set_tx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp
index 41c52fbf5..10be8d1c3 100644
--- a/host/lib/usrp/dboard/db_tvrx.cpp
+++ b/host/lib/usrp/dboard/db_tvrx.cpp
@@ -58,7 +58,7 @@ static const bool tvrx_debug = false;
static const freq_range_t tvrx_freq_range(50e6, 860e6);
-static const prop_names_t tvrx_antennas = list_of(""); //only got one
+static const prop_names_t tvrx_antennas = list_of("RX");
static const uhd::dict<std::string, freq_range_t> tvrx_freq_ranges = map_list_of
("VHFLO", freq_range_t(50e6, 158e6))
@@ -66,25 +66,25 @@ static const uhd::dict<std::string, freq_range_t> tvrx_freq_ranges = map_list_of
("UHF" , freq_range_t(454e6, 860e6))
;
-static const boost::array<float, 17> vhflo_gains_db =
+static const boost::array<double, 17> vhflo_gains_db =
{{-6.00000, -6.00000, -6.00000, -4.00000, 0.00000,
5.00000, 10.00000, 17.40000, 26.30000, 36.00000,
43.00000, 48.00000, 49.50000, 50.10000, 50.30000,
50.30000, 50.30000}};
-
-static const boost::array<float, 17> vhfhi_gains_db =
- {{13.3000, -13.3000, -13.3000, -1.0000, 7.7000,
+
+static const boost::array<double, 17> vhfhi_gains_db =
+ {{-13.3000, -13.3000, -13.3000, -1.0000, 7.7000,
11.0000, 14.7000, 19.3000, 26.1000, 36.0000,
42.7000, 46.0000, 47.0000, 47.8000, 48.2000,
48.2000, 48.2000}};
-
-static const boost::array<float, 17> uhf_gains_db =
+
+static const boost::array<double, 17> uhf_gains_db =
{{-8.0000, -8.0000, -7.0000, 4.0000, 10.2000,
14.5000, 17.5000, 20.0000, 24.5000, 30.8000,
37.0000, 39.8000, 40.7000, 41.6000, 42.6000,
43.2000, 43.8000}};
-
-static const boost::array<float, 17> tvrx_if_gains_db =
+
+static const boost::array<double, 17> tvrx_if_gains_db =
{{-1.50000, -1.50000, -1.50000, -1.00000, 0.20000,
2.10000, 4.30000, 6.40000, 9.00000, 12.00000,
14.80000, 18.20000, 26.10000, 32.50000, 32.50000,
@@ -96,32 +96,32 @@ static const boost::array<float, 17> tvrx_if_gains_db =
//need dang near as many coefficients as to just map it like this and interp.
//these numbers are culled from the 4937DI5 datasheet and are probably totally inaccurate
//but if it's better than the old linear fit i'm happy
-static const uhd::dict<std::string, boost::array<float, 17> > tvrx_rf_gains_db = map_list_of
+static const uhd::dict<std::string, boost::array<double, 17> > tvrx_rf_gains_db = map_list_of
("VHFLO", vhflo_gains_db)
("VHFHI", vhfhi_gains_db)
("UHF" , uhf_gains_db)
;
//sample voltages for the above points
-static const boost::array<float, 17> tvrx_gains_volts =
+static const boost::array<double, 17> tvrx_gains_volts =
{{0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0}};
static uhd::dict<std::string, gain_range_t> get_tvrx_gain_ranges(void) {
- float rfmax = 0.0, rfmin = FLT_MAX;
+ double rfmax = 0.0, rfmin = FLT_MAX;
BOOST_FOREACH(const std::string range, tvrx_rf_gains_db.keys()) {
- float my_max = tvrx_rf_gains_db[range].back(); //we're assuming it's monotonic
- float my_min = tvrx_rf_gains_db[range].front(); //if it's not this is wrong wrong wrong
+ double my_max = tvrx_rf_gains_db[range].back(); //we're assuming it's monotonic
+ double my_min = tvrx_rf_gains_db[range].front(); //if it's not this is wrong wrong wrong
if(my_max > rfmax) rfmax = my_max;
if(my_min < rfmin) rfmin = my_min;
}
-
- float ifmin = tvrx_if_gains_db.front();
- float ifmax = tvrx_if_gains_db.back();
-
+
+ double ifmin = tvrx_if_gains_db.front();
+ double ifmax = tvrx_if_gains_db.back();
+
return map_list_of
- ("RF", gain_range_t(rfmin, rfmax, (rfmax-rfmin)/4096.0))
- ("IF", gain_range_t(ifmin, ifmax, (ifmax-ifmin)/4096.0))
- ;
+ ("RF", gain_range_t(float(rfmin), float(rfmax), float((rfmax-rfmin)/4096.0)))
+ ("IF", gain_range_t(float(ifmin), float(ifmax), float((ifmax-ifmin)/4096.0)))
+ ;
}
static const double opamp_gain = 1.22; //onboard DAC opamp gain
@@ -136,7 +136,7 @@ class tvrx : public rx_dboard_base{
public:
tvrx(ctor_args_t args);
~tvrx(void);
-
+
void rx_get(const wax::obj &key, wax::obj &val);
void rx_set(const wax::obj &key, const wax::obj &val);
@@ -198,11 +198,11 @@ tvrx::tvrx(ctor_args_t args) : rx_dboard_base(args){
}
//send initial register settings if necessary
-
+
//set default freq
_lo_freq = tvrx_freq_range.min + tvrx_if_freq; //init _lo_freq to a sane default
set_freq(tvrx_freq_range.min);
-
+
//set default gains
BOOST_FOREACH(const std::string &name, get_tvrx_gain_ranges().keys()){
set_gain(get_tvrx_gain_ranges()[name].min, name);
@@ -238,33 +238,33 @@ static std::string get_band(double freq) {
* \return a voltage to feed the TVRX analog gain
*/
-static float gain_interp(float gain, boost::array<float, 17> db_vector, boost::array<float, 17> volts_vector) {
- float volts;
- gain = std::clip<float>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
-
+static double gain_interp(double gain, boost::array<double, 17> db_vector, boost::array<double, 17> volts_vector) {
+ double volts;
+ gain = std::clip<double>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
+
boost::uint8_t gain_step = 0;
//find which bin we're in
for(size_t i = 0; i < db_vector.size()-1; i++) {
if(gain >= db_vector[i] && gain <= db_vector[i+1]) gain_step = i;
}
-
+
//find the current slope for linear interpolation
- float slope = (volts_vector[gain_step + 1] - volts_vector[gain_step])
+ double slope = (volts_vector[gain_step + 1] - volts_vector[gain_step])
/ (db_vector[gain_step + 1] - db_vector[gain_step]);
-
+
//the problem here is that for gains approaching the maximum, the voltage slope becomes infinite
//i.e., a small change in gain requires an infinite change in voltage
//to cope, we limit the slope
-
- if(slope == std::numeric_limits<float>::infinity())
+
+ if(slope == std::numeric_limits<double>::infinity())
return volts_vector[gain_step];
//use the volts per dB slope to find the final interpolated voltage
volts = volts_vector[gain_step] + (slope * (gain - db_vector[gain_step]));
-
+
if(tvrx_debug)
std::cout << "Gain interp: gain: " << gain << ", gain_step: " << int(gain_step) << ", slope: " << slope << ", volts: " << volts << std::endl;
-
+
return volts;
}
@@ -283,17 +283,17 @@ static float rf_gain_to_voltage(float gain, double lo_freq){
std::string band = get_band(lo_freq + tvrx_if_freq);
//this is the voltage at the TVRX gain input
- float gain_volts = gain_interp(gain, tvrx_rf_gains_db[band], tvrx_gains_volts);
+ double gain_volts = gain_interp(gain, tvrx_rf_gains_db[band], tvrx_gains_volts);
//this is the voltage at the USRP DAC output
- float dac_volts = gain_volts / opamp_gain;
-
- dac_volts = std::clip<float>(dac_volts, 0.0, 3.3);
+ double dac_volts = gain_volts / opamp_gain;
+
+ dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
if (tvrx_debug) std::cerr << boost::format(
"tvrx RF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
- return dac_volts;
+ return float(dac_volts);
}
/*!
@@ -306,17 +306,17 @@ static float rf_gain_to_voltage(float gain, double lo_freq){
static float if_gain_to_voltage(float gain){
//clip the input
gain = std::clip<float>(gain, get_tvrx_gain_ranges()["IF"].min, get_tvrx_gain_ranges()["IF"].max);
-
- float gain_volts = gain_interp(gain, tvrx_if_gains_db, tvrx_gains_volts);
- float dac_volts = gain_volts / opamp_gain;
-
- dac_volts = std::clip<float>(dac_volts, 0.0, 3.3);
+
+ double gain_volts = gain_interp(gain, tvrx_if_gains_db, tvrx_gains_volts);
+ double dac_volts = gain_volts / opamp_gain;
+
+ dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
if (tvrx_debug) std::cerr << boost::format(
"tvrx IF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
- return dac_volts;
+ return float(dac_volts);
}
void tvrx::set_gain(float gain, const std::string &name){
@@ -337,27 +337,27 @@ void tvrx::set_gain(float gain, const std::string &name){
*/
void tvrx::set_freq(double freq) {
- freq = std::clip<float>(freq, tvrx_freq_range.min, tvrx_freq_range.max);
+ freq = std::clip<double>(freq, tvrx_freq_range.min, tvrx_freq_range.max);
std::string prev_band = get_band(_lo_freq - tvrx_if_freq);
std::string new_band = get_band(freq);
-
+
double target_lo_freq = freq + tvrx_if_freq; //the desired LO freq for high-side mixing
double f_ref = reference_freq / double(reference_divider); //your tuning step size
-
+
int divisor = int((target_lo_freq + (f_ref * 4.0)) / (f_ref * 8)); //the divisor we'll use
double actual_lo_freq = (f_ref * 8 * divisor); //the LO freq we'll actually get
-
+
if((divisor & ~0x7fff)) UHD_THROW_INVALID_CODE_PATH();
-
+
//now we update the registers
_tuner_4937di5_regs.db1 = (divisor >> 8) & 0xff;
_tuner_4937di5_regs.db2 = divisor & 0xff;
-
+
if(new_band == "VHFLO") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_VHFLO;
else if(new_band == "VHFHI") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_VHFHI;
else if(new_band == "UHF") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_UHF;
else UHD_THROW_INVALID_CODE_PATH();
-
+
_tuner_4937di5_regs.power = tuner_4937di5_regs_t::POWER_OFF;
update_regs();
@@ -365,10 +365,10 @@ void tvrx::set_freq(double freq) {
//we do this because the gains are different for different band settings
//not FAR off, but we do this to be consistent
if(prev_band != new_band) set_gain(_gains["RF"], "RF");
-
- if(tvrx_debug)
+
+ if(tvrx_debug)
std::cout << boost::format("set_freq: target LO: %f f_ref: %f divisor: %i actual LO: %f") % target_lo_freq % f_ref % divisor % actual_lo_freq << std::endl;
-
+
_lo_freq = actual_lo_freq; //for rx props
}
@@ -422,7 +422,7 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){
return;
case SUBDEV_PROP_FREQ:
- /*
+ /*
* so here we have to do some magic. because the TVRX uses a relatively high IF,
* we have to watch the sample rate to see if the IF will be aliased
* or if it will fall within Nyquist.
@@ -436,7 +436,7 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){
return;
case SUBDEV_PROP_ANTENNA:
- val = std::string("");
+ val = tvrx_antennas.front(); //there's only one
return;
case SUBDEV_PROP_ANTENNA_NAMES:
@@ -447,6 +447,10 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -467,10 +471,14 @@ void tvrx::rx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_GAIN:
this->set_gain(val.as<float>(), key.name);
return;
+
case SUBDEV_PROP_FREQ:
this->set_freq(val.as<double>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard/db_unknown.cpp b/host/lib/usrp/dboard/db_unknown.cpp
index f6f4f4a61..ec7ab440b 100644
--- a/host/lib/usrp/dboard/db_unknown.cpp
+++ b/host/lib/usrp/dboard/db_unknown.cpp
@@ -122,6 +122,10 @@ void unknown_rx::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -151,6 +155,9 @@ void unknown_rx::rx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_FREQ:
return; // it wont do you much good, but you can set it
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
@@ -211,6 +218,10 @@ void unknown_tx::tx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -240,6 +251,9 @@ void unknown_tx::tx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_FREQ:
return; // it wont do you much good, but you can set it
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard/db_wbx.cpp b/host/lib/usrp/dboard/db_wbx.cpp
index e473ce41e..907268aac 100644
--- a/host/lib/usrp/dboard/db_wbx.cpp
+++ b/host/lib/usrp/dboard/db_wbx.cpp
@@ -513,6 +513,10 @@ void wbx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -543,6 +547,9 @@ void wbx_xcvr::rx_set(const wax::obj &key_, const wax::obj &val){
this->set_rx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
@@ -597,6 +604,10 @@ void wbx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -627,6 +638,9 @@ void wbx_xcvr::tx_set(const wax::obj &key_, const wax::obj &val){
this->set_tx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp
index 798ff74a3..fb1367113 100644
--- a/host/lib/usrp/dboard/db_xcvr2450.cpp
+++ b/host/lib/usrp/dboard/db_xcvr2450.cpp
@@ -51,6 +51,7 @@
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/utils/algorithm.hpp>
+#include <uhd/utils/warning.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/dict.hpp>
#include <uhd/usrp/subdev_props.hpp>
@@ -72,6 +73,7 @@ using namespace boost::assign;
static const bool xcvr2450_debug = false;
static const freq_range_t xcvr_freq_range(2.4e9, 6.0e9);
+static const freq_range_t xcvr_freq_band_seperation(2.5e9, 4.9e9);
static const prop_names_t xcvr_antennas = list_of("J1")("J2");
@@ -100,6 +102,7 @@ public:
private:
double _lo_freq;
+ double _rx_bandwidth, _tx_bandwidth;
uhd::dict<std::string, float> _tx_gains, _rx_gains;
std::string _tx_ant, _rx_ant;
int _ad9515div;
@@ -110,6 +113,8 @@ private:
void set_rx_ant(const std::string &ant);
void set_tx_gain(float gain, const std::string &name);
void set_rx_gain(float gain, const std::string &name);
+ void set_rx_bandwidth(double bandwidth);
+ void set_tx_bandwidth(double bandwidth);
void update_atr(void);
void spi_reset(void);
@@ -176,6 +181,9 @@ xcvr2450::xcvr2450(ctor_args_t args) : xcvr_dboard_base(args){
spi_reset(); //prepare the spi
+ _rx_bandwidth = 9.5e6;
+ _tx_bandwidth = 12.0e6;
+
//setup the misc max2829 registers
_max2829_regs.mimo_select = max2829_regs_t::MIMO_SELECT_MIMO;
_max2829_regs.band_sel_mimo = max2829_regs_t::BAND_SEL_MIMO_MIMO;
@@ -183,7 +191,7 @@ xcvr2450::xcvr2450(ctor_args_t args) : xcvr_dboard_base(args){
_max2829_regs.rssi_high_bw = max2829_regs_t::RSSI_HIGH_BW_6MHZ;
_max2829_regs.tx_lpf_coarse_adj = max2829_regs_t::TX_LPF_COARSE_ADJ_12MHZ;
_max2829_regs.rx_lpf_coarse_adj = max2829_regs_t::RX_LPF_COARSE_ADJ_9_5MHZ;
- _max2829_regs.rx_lpf_fine_adj = max2829_regs_t::RX_LPF_FINE_ADJ_95;
+ _max2829_regs.rx_lpf_fine_adj = max2829_regs_t::RX_LPF_FINE_ADJ_100;
_max2829_regs.rx_vga_gain_spi = max2829_regs_t::RX_VGA_GAIN_SPI_SPI;
_max2829_regs.rssi_output_range = max2829_regs_t::RSSI_OUTPUT_RANGE_HIGH;
_max2829_regs.rssi_op_mode = max2829_regs_t::RSSI_OP_MODE_ENABLED;
@@ -244,15 +252,24 @@ void xcvr2450::update_atr(void){
this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_IDLE, POWER_UP_RXIO | RX_DIS_RXIO);
this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_RX_ONLY, POWER_UP_RXIO | RX_ENB_RXIO);
this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_TX_ONLY, POWER_UP_RXIO | RX_DIS_RXIO);
- this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_FULL_DUPLEX, POWER_UP_RXIO | RX_ENB_RXIO);
+ this->get_iface()->set_atr_reg(dboard_iface::UNIT_RX, dboard_iface::ATR_REG_FULL_DUPLEX, POWER_UP_RXIO | RX_DIS_RXIO);
}
/***********************************************************************
* Tuning
**********************************************************************/
void xcvr2450::set_lo_freq(double target_freq){
+ //clip for highband and lowband
+ if((target_freq > xcvr_freq_band_seperation.min) and (target_freq < xcvr_freq_band_seperation.max)){
+ if(target_freq - xcvr_freq_band_seperation.min < xcvr_freq_band_seperation.max - target_freq){
+ target_freq = xcvr_freq_band_seperation.min;
+ }else{
+ target_freq = xcvr_freq_band_seperation.max;
+ }
+ }
+
+ //clip for max and min
target_freq = std::clip(target_freq, xcvr_freq_range.min, xcvr_freq_range.max);
- //TODO: clip for highband and lowband
//variables used in the calculation below
double scaler = xcvr2450::is_highband(target_freq)? (4.0/5.0) : (4.0/3.0);
@@ -434,6 +451,114 @@ void xcvr2450::set_rx_gain(float gain, const std::string &name){
_rx_gains[name] = gain;
}
+
+/***********************************************************************
+ * Bandwidth Handling
+ **********************************************************************/
+static max2829_regs_t::tx_lpf_coarse_adj_t bandwidth_to_tx_lpf_coarse_reg(double &bandwidth){
+ int reg = std::clip(boost::math::iround((bandwidth-6.0e6)/6.0e6), 1, 3);
+
+ switch(reg){
+ case 1: // bandwidth < 15MHz
+ bandwidth = 12e6;
+ return max2829_regs_t::TX_LPF_COARSE_ADJ_12MHZ;
+ case 2: // 15MHz < bandwidth < 21MHz
+ bandwidth = 18e6;
+ return max2829_regs_t::TX_LPF_COARSE_ADJ_18MHZ;
+ case 3: // bandwidth > 21MHz
+ bandwidth = 24e6;
+ return max2829_regs_t::TX_LPF_COARSE_ADJ_24MHZ;
+ }
+ UHD_THROW_INVALID_CODE_PATH();
+}
+
+static max2829_regs_t::rx_lpf_fine_adj_t bandwidth_to_rx_lpf_fine_reg(double &bandwidth, double requested_bandwidth){
+ int reg = std::clip(boost::math::iround((requested_bandwidth/bandwidth)/0.05), 18, 22);
+
+ switch(reg){
+ case 18: // requested_bandwidth < 92.5%
+ bandwidth = 0.9 * bandwidth;
+ return max2829_regs_t::RX_LPF_FINE_ADJ_90;
+ case 19: // 92.5% < requested_bandwidth < 97.5%
+ bandwidth = 0.95 * bandwidth;
+ return max2829_regs_t::RX_LPF_FINE_ADJ_95;
+ case 20: // 97.5% < requested_bandwidth < 102.5%
+ bandwidth = 1.0 * bandwidth;
+ return max2829_regs_t::RX_LPF_FINE_ADJ_100;
+ case 21: // 102.5% < requested_bandwidth < 107.5%
+ bandwidth = 1.05 * bandwidth;
+ return max2829_regs_t::RX_LPF_FINE_ADJ_105;
+ case 22: // 107.5% < requested_bandwidth
+ bandwidth = 1.1 * bandwidth;
+ return max2829_regs_t::RX_LPF_FINE_ADJ_110;
+ }
+ UHD_THROW_INVALID_CODE_PATH();
+}
+
+static max2829_regs_t::rx_lpf_coarse_adj_t bandwidth_to_rx_lpf_coarse_reg(double &bandwidth){
+ int reg = std::clip(boost::math::iround((bandwidth-7.0e6)/1.0e6), 0, 11);
+
+ switch(reg){
+ case 0: // bandwidth < 7.5MHz
+ case 1: // 7.5MHz < bandwidth < 8.5MHz
+ bandwidth = 7.5e6;
+ return max2829_regs_t::RX_LPF_COARSE_ADJ_7_5MHZ;
+ case 2: // 8.5MHz < bandwidth < 9.5MHz
+ case 3: // 9.5MHz < bandwidth < 10.5MHz
+ case 4: // 10.5MHz < bandwidth < 11.5MHz
+ bandwidth = 9.5e6;
+ return max2829_regs_t::RX_LPF_COARSE_ADJ_9_5MHZ;
+ case 5: // 11.5MHz < bandwidth < 12.5MHz
+ case 6: // 12.5MHz < bandwidth < 13.5MHz
+ case 7: // 13.5MHz < bandwidth < 14.5MHz
+ case 8: // 14.5MHz < bandwidth < 15.5MHz
+ bandwidth = 14e6;
+ return max2829_regs_t::RX_LPF_COARSE_ADJ_14MHZ;
+ case 9: // 15.5MHz < bandwidth < 16.5MHz
+ case 10: // 16.5MHz < bandwidth < 17.5MHz
+ case 11: // 17.5MHz < bandwidth
+ bandwidth = 18e6;
+ return max2829_regs_t::RX_LPF_COARSE_ADJ_18MHZ;
+ }
+ UHD_THROW_INVALID_CODE_PATH();
+}
+
+void xcvr2450::set_rx_bandwidth(double bandwidth){
+ double requested_bandwidth = bandwidth;
+
+ //compute coarse low pass cutoff frequency setting
+ _max2829_regs.rx_lpf_coarse_adj = bandwidth_to_rx_lpf_coarse_reg(bandwidth);
+
+ //compute fine low pass cutoff frequency setting
+ _max2829_regs.rx_lpf_fine_adj = bandwidth_to_rx_lpf_fine_reg(bandwidth, requested_bandwidth);
+
+ //shadow bandwidth setting
+ _rx_bandwidth = bandwidth;
+
+ //update register
+ send_reg(0x7);
+
+ if (xcvr2450_debug) std::cerr << boost::format(
+ "XCVR2450 RX Bandwidth (lp_fc): %f Hz, coarse reg: %d, fine reg: %d"
+ ) % _rx_bandwidth % (int(_max2829_regs.rx_lpf_coarse_adj)) % (int(_max2829_regs.rx_lpf_fine_adj)) << std::endl;
+}
+
+void xcvr2450::set_tx_bandwidth(double bandwidth){
+ //compute coarse low pass cutoff frequency setting
+ _max2829_regs.tx_lpf_coarse_adj = bandwidth_to_tx_lpf_coarse_reg(bandwidth);
+
+ //shadow bandwidth setting
+ _tx_bandwidth = bandwidth;
+
+ //update register
+ send_reg(0x7);
+
+ if (xcvr2450_debug) std::cerr << boost::format(
+ "XCVR2450 TX Bandwidth (lp_fc): %f Hz, coarse reg: %d"
+ ) % _tx_bandwidth % (int(_max2829_regs.tx_lpf_coarse_adj)) << std::endl;
+}
+
+
/***********************************************************************
* RX Get and Set
**********************************************************************/
@@ -484,6 +609,10 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_IQ;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -496,6 +625,10 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){
val = this->get_rssi();
return;
+ case SUBDEV_PROP_BANDWIDTH:
+ val = _rx_bandwidth;
+ return;
+
default: UHD_THROW_PROP_GET_ERROR();
}
}
@@ -518,6 +651,13 @@ void xcvr2450::rx_set(const wax::obj &key_, const wax::obj &val){
this->set_rx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_BANDWIDTH:
+ this->set_rx_bandwidth(val.as<double>());
+ return;
+
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
@@ -572,6 +712,10 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){
val = SUBDEV_CONN_COMPLEX_QI;
return;
+ case SUBDEV_PROP_ENABLED:
+ val = true; //always enabled
+ return;
+
case SUBDEV_PROP_USE_LO_OFFSET:
val = false;
return;
@@ -580,6 +724,10 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){
val = this->get_locked();
return;
+ case SUBDEV_PROP_BANDWIDTH:
+ val = _tx_bandwidth;
+ return;
+
default: UHD_THROW_PROP_GET_ERROR();
}
}
@@ -598,10 +746,17 @@ void xcvr2450::tx_set(const wax::obj &key_, const wax::obj &val){
this->set_tx_gain(val.as<float>(), key.name);
return;
+ case SUBDEV_PROP_BANDWIDTH:
+ this->set_tx_bandwidth(val.as<double>());
+ return;
+
case SUBDEV_PROP_ANTENNA:
this->set_tx_ant(val.as<std::string>());
return;
+ case SUBDEV_PROP_ENABLED:
+ return; //always enabled
+
default: UHD_THROW_PROP_SET_ERROR();
}
}
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 181f843a0..78daa1b4d 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -86,7 +86,7 @@ std::string dboard_id_t::to_pp_string(void) const{
}
/***********************************************************************
- * internal helper classe
+ * internal helper classes
**********************************************************************/
/*!
* A special wax proxy object that forwards calls to a subdev.
@@ -330,4 +330,14 @@ void dboard_manager_impl::set_nice_dboard_if(void){
_iface->set_pin_ctrl(unit, 0x0000); //all gpio
_iface->set_clock_enabled(unit, false); //clock off
}
+
+ //disable all rx subdevices
+ BOOST_FOREACH(const std::string &sd_name, this->get_rx_subdev_names()){
+ this->get_rx_subdev(sd_name)[SUBDEV_PROP_ENABLED] = false;
+ }
+
+ //disable all tx subdevices
+ BOOST_FOREACH(const std::string &sd_name, this->get_tx_subdev_names()){
+ this->get_tx_subdev(sd_name)[SUBDEV_PROP_ENABLED] = false;
+ }
}
diff --git a/host/lib/usrp/mimo_usrp.cpp b/host/lib/usrp/mimo_usrp.cpp
deleted file mode 100644
index 9331c7fbb..000000000
--- a/host/lib/usrp/mimo_usrp.cpp
+++ /dev/null
@@ -1,347 +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 <http://www.gnu.org/licenses/>.
-//
-
-#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/utils/warning.hpp>
-#include <uhd/usrp/subdev_props.hpp>
-#include <uhd/usrp/mboard_props.hpp>
-#include <uhd/usrp/device_props.hpp>
-#include <uhd/usrp/dboard_props.hpp>
-#include <uhd/usrp/dsp_props.hpp>
-#include <boost/foreach.hpp>
-#include <boost/format.hpp>
-#include <boost/thread.hpp>
-#include <stdexcept>
-#include <iostream>
-
-using namespace uhd;
-using namespace uhd::usrp;
-
-static inline freq_range_t add_dsp_shift(const freq_range_t &range, wax::obj dsp){
- double codec_rate = dsp[DSP_PROP_CODEC_RATE].as<double>();
- return freq_range_t(range.min - codec_rate/2.0, range.max + codec_rate/2.0);
-}
-
-/***********************************************************************
- * MIMO USRP Implementation
- **********************************************************************/
-class mimo_usrp_impl : public mimo_usrp{
-public:
- mimo_usrp_impl(const device_addr_t &addr){
- _dev = device::make(addr);
-
- //set the clock config across all mboards (TODO set through api)
- clock_config_t clock_config;
- clock_config.ref_source = clock_config_t::REF_SMA;
- clock_config.pps_source = clock_config_t::PPS_SMA;
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- _mboard(chan)[MBOARD_PROP_CLOCK_CONFIG] = clock_config;
- }
- }
-
- ~mimo_usrp_impl(void){
- /* NOP */
- }
-
- device::sptr get_device(void){
- return _dev;
- }
-
- std::string get_pp_string(void){
- std::string buff = str(boost::format(
- "MIMO USRP:\n"
- " Device: %s\n"
- )
- % (*_dev)[DEVICE_PROP_NAME].as<std::string>()
- );
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- buff += str(boost::format(
- " Channel: %u\n"
- " Mboard: %s\n"
- " RX DSP: %s\n"
- " RX Dboard: %s\n"
- " RX Subdev: %s\n"
- " TX DSP: %s\n"
- " TX Dboard: %s\n"
- " TX Subdev: %s\n"
- ) % chan
- % _mboard(chan)[MBOARD_PROP_NAME].as<std::string>()
- % _rx_dsp(chan)[DSP_PROP_NAME].as<std::string>()
- % _rx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
- % _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
- % _tx_dsp(chan)[DSP_PROP_NAME].as<std::string>()
- % _tx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
- % _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
- );
- }
- return buff;
- }
-
- size_t get_num_channels(void){
- return (*_dev)[DEVICE_PROP_MBOARD_NAMES].as<prop_names_t>().size();
- }
-
- /*******************************************************************
- * Misc
- ******************************************************************/
- time_spec_t get_time_now(void){
- //the time on the first mboard better be the same on all
- return _mboard(0)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
- }
-
- void set_time_next_pps(const time_spec_t &time_spec){
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- _mboard(chan)[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
- }
- }
-
- void set_time_unknown_pps(const time_spec_t &time_spec){
- std::cout << "Set time with unknown pps edge:" << std::endl;
- std::cout << " 1) set times next pps (race condition)" << std::endl;
- set_time_next_pps(time_spec);
- boost::this_thread::sleep(boost::posix_time::seconds(1));
-
- std::cout << " 2) catch seconds rollover at pps edge" << std::endl;
- time_t last_secs = 0, curr_secs = 0;
- while(curr_secs == last_secs){
- last_secs = curr_secs;
- curr_secs = get_time_now().get_full_secs();
- }
-
- std::cout << " 3) set times next pps (synchronously)" << std::endl;
- set_time_next_pps(time_spec);
- boost::this_thread::sleep(boost::posix_time::seconds(1));
-
- //verify that the time registers are read to be within a few RTT
- for (size_t chan = 1; chan < get_num_channels(); chan++){
- time_spec_t time_0 = _mboard(0)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
- time_spec_t time_i = _mboard(chan)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
- if (time_i < time_0 or (time_i - time_0) > time_spec_t(0.01)){ //10 ms: greater than RTT but not too big
- uhd::print_warning(str(boost::format(
- "Detected time deviation between board %d and board 0.\n"
- "Board 0 time is %f seconds.\n"
- "Board %d time is %f seconds.\n"
- ) % chan % time_0.get_real_secs() % chan % time_i.get_real_secs()));
- }
- }
- }
-
- void issue_stream_cmd(const stream_cmd_t &stream_cmd){
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- _mboard(chan)[MBOARD_PROP_STREAM_CMD] = stream_cmd;
- }
- }
-
- /*******************************************************************
- * RX methods
- ******************************************************************/
- void set_rx_subdev_spec(size_t chan, const subdev_spec_t &spec){
- UHD_ASSERT_THROW(spec.size() <= 1);
- _mboard(chan)[MBOARD_PROP_RX_SUBDEV_SPEC] = spec;
- }
-
- subdev_spec_t get_rx_subdev_spec(size_t chan){
- return _mboard(chan)[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
- }
-
- void set_rx_rate_all(double rate){
- std::vector<double> _actual_rates;
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- _rx_dsp(chan)[DSP_PROP_HOST_RATE] = rate;
- _actual_rates.push_back(_rx_dsp(chan)[DSP_PROP_HOST_RATE].as<double>());
- }
- _rx_rate = _actual_rates.front();
- if (std::count(_actual_rates, _rx_rate) != _actual_rates.size()) throw std::runtime_error(
- "MIMO configuratio error: rx rate inconsistent across mboards"
- );
- }
-
- double get_rx_rate_all(void){
- return _rx_rate;
- }
-
- tune_result_t set_rx_freq(size_t chan, double target_freq){
- return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan), 0, target_freq);
- }
-
- tune_result_t set_rx_freq(size_t chan, double target_freq, double lo_off){
- return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan), 0, target_freq, lo_off);
- }
-
- double get_rx_freq(size_t chan){
- return derive_freq_from_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan), 0);
- }
-
- freq_range_t get_rx_freq_range(size_t chan){
- return add_dsp_shift(_rx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _rx_dsp(chan));
- }
-
- void set_rx_gain(size_t chan, float gain){
- return _rx_gain_group(chan)->set_value(gain);
- }
-
- float get_rx_gain(size_t chan){
- return _rx_gain_group(chan)->get_value();
- }
-
- gain_range_t get_rx_gain_range(size_t chan){
- return _rx_gain_group(chan)->get_range();
- }
-
- void set_rx_antenna(size_t chan, const std::string &ant){
- _rx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant;
- }
-
- std::string get_rx_antenna(size_t chan){
- return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>();
- }
-
- std::vector<std::string> get_rx_antennas(size_t chan){
- return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
- }
-
- bool get_rx_lo_locked(size_t chan){
- return _rx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
- }
-
- float read_rssi(size_t chan){
- return _rx_subdev(chan)[SUBDEV_PROP_RSSI].as<float>();
- }
-
- /*******************************************************************
- * TX methods
- ******************************************************************/
- void set_tx_subdev_spec(size_t chan, const subdev_spec_t &spec){
- UHD_ASSERT_THROW(spec.size() <= 1);
- _mboard(chan)[MBOARD_PROP_TX_SUBDEV_SPEC] = spec;
- }
-
- subdev_spec_t get_tx_subdev_spec(size_t chan){
- return _mboard(chan)[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
- }
-
- void set_tx_rate_all(double rate){
- std::vector<double> _actual_rates;
- for (size_t chan = 0; chan < get_num_channels(); chan++){
- _tx_dsp(chan)[DSP_PROP_HOST_RATE] = rate;
- _actual_rates.push_back(_tx_dsp(chan)[DSP_PROP_HOST_RATE].as<double>());
- }
- _tx_rate = _actual_rates.front();
- if (std::count(_actual_rates, _tx_rate) != _actual_rates.size()) throw std::runtime_error(
- "MIMO configuratio error: tx rate inconsistent across mboards"
- );
- }
-
- double get_tx_rate_all(void){
- return _tx_rate;
- }
-
- tune_result_t set_tx_freq(size_t chan, double target_freq){
- return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan), 0, target_freq);
- }
-
- tune_result_t set_tx_freq(size_t chan, double target_freq, double lo_off){
- return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan), 0, target_freq, lo_off);
- }
-
- double get_tx_freq(size_t chan){
- return derive_freq_from_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan), 0);
- }
-
- freq_range_t get_tx_freq_range(size_t chan){
- return add_dsp_shift(_tx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _tx_dsp(chan));
- }
-
- void set_tx_gain(size_t chan, float gain){
- return _tx_gain_group(chan)->set_value(gain);
- }
-
- float get_tx_gain(size_t chan){
- return _tx_gain_group(chan)->get_value();
- }
-
- gain_range_t get_tx_gain_range(size_t chan){
- return _tx_gain_group(chan)->get_range();
- }
-
- void set_tx_antenna(size_t chan, const std::string &ant){
- _tx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant;
- }
-
- std::string get_tx_antenna(size_t chan){
- return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>();
- }
-
- std::vector<std::string> get_tx_antennas(size_t chan){
- return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
- }
-
- bool get_tx_lo_locked(size_t chan){
- return _tx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
- }
-
-private:
- device::sptr _dev;
- wax::obj _mboard(size_t chan){
- prop_names_t names = (*_dev)[DEVICE_PROP_MBOARD_NAMES].as<prop_names_t>();
- return (*_dev)[named_prop_t(DEVICE_PROP_MBOARD, names.at(chan))];
- }
- wax::obj _rx_dsp(size_t chan){
- return _mboard(chan)[MBOARD_PROP_RX_DSP];
- }
- wax::obj _tx_dsp(size_t chan){
- return _mboard(chan)[MBOARD_PROP_TX_DSP];
- }
- wax::obj _rx_dboard(size_t chan){
- std::string db_name = _mboard(chan)[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().db_name;
- return _mboard(chan)[named_prop_t(MBOARD_PROP_RX_DBOARD, db_name)];
- }
- wax::obj _tx_dboard(size_t chan){
- std::string db_name = _mboard(chan)[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().db_name;
- return _mboard(chan)[named_prop_t(MBOARD_PROP_TX_DBOARD, db_name)];
- }
- wax::obj _rx_subdev(size_t chan){
- std::string sd_name = _mboard(chan)[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
- return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
- }
- wax::obj _tx_subdev(size_t chan){
- std::string sd_name = _mboard(chan)[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
- return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
- }
- gain_group::sptr _rx_gain_group(size_t chan){
- std::string sd_name = _mboard(chan)[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
- return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
- }
- gain_group::sptr _tx_gain_group(size_t chan){
- std::string sd_name = _mboard(chan)[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>().front().sd_name;
- return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
- }
-
- //shadows
- double _rx_rate, _tx_rate;
-};
-
-/***********************************************************************
- * The Make Function
- **********************************************************************/
-mimo_usrp::sptr mimo_usrp::make(const device_addr_t &dev_addr){
- return sptr(new mimo_usrp_impl(dev_addr));
-}
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp
index 5cfcdc8d3..05308baba 100644
--- a/host/lib/usrp/misc_utils.cpp
+++ b/host/lib/usrp/misc_utils.cpp
@@ -17,6 +17,7 @@
#include <uhd/usrp/misc_utils.hpp>
#include <uhd/utils/assert.hpp>
+#include <uhd/utils/algorithm.hpp>
#include <uhd/utils/gain_group.hpp>
#include <uhd/usrp/dboard_id.hpp>
#include <uhd/usrp/subdev_props.hpp>
@@ -186,6 +187,22 @@ static void verify_xx_subdev_spec(
"Validate %s subdev spec failed: %s\n %s"
) % xx_type % subdev_spec.to_string() % e.what()));
}
+
+ //now use the subdev spec to enable the subdevices in use and vice-versa
+ BOOST_FOREACH(const std::string &db_name, mboard[dboard_names_prop].as<prop_names_t>()){
+ wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)];
+ BOOST_FOREACH(const std::string &sd_name, dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>()){
+ try{
+ bool enable = std::has(subdev_spec, subdev_spec_pair_t(db_name, sd_name));
+ dboard[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)][SUBDEV_PROP_ENABLED] = enable;
+ }
+ catch(const std::exception &e){
+ throw std::runtime_error(str(boost::format(
+ "Cannot set enabled property on subdevice %s:%s\n %s"
+ ) % db_name % sd_name % e.what()));
+ }
+ }
+ }
}
void usrp::verify_rx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard){
diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp
new file mode 100644
index 000000000..027530f31
--- /dev/null
+++ b/host/lib/usrp/multi_usrp.cpp
@@ -0,0 +1,435 @@
+//
+// 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 "wrapper_utils.hpp"
+#include <uhd/usrp/multi_usrp.hpp>
+#include <uhd/usrp/tune_helper.hpp>
+#include <uhd/utils/assert.hpp>
+#include <uhd/utils/warning.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>
+#include <uhd/usrp/dboard_props.hpp>
+#include <uhd/usrp/dsp_props.hpp>
+#include <boost/thread.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <stdexcept>
+#include <iostream>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/***********************************************************************
+ * Simple USRP Implementation
+ **********************************************************************/
+class multi_usrp_impl : public multi_usrp{
+public:
+ multi_usrp_impl(const device_addr_t &addr){
+ _dev = device::make(addr);
+ }
+
+ device::sptr get_device(void){
+ return _dev;
+ }
+
+ /*******************************************************************
+ * Mboard methods
+ ******************************************************************/
+ std::string get_pp_string(void){
+ std::string buff = str(boost::format(
+ "Multi USRP:\n"
+ " Device: %s\n"
+ )
+ % (*_dev)[DEVICE_PROP_NAME].as<std::string>()
+ );
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ buff += str(boost::format(
+ " Mboard %d: %s\n"
+ ) % m
+ % _mboard(m)[MBOARD_PROP_NAME].as<std::string>()
+ );
+ }
+
+ //----------- rx side of life ----------------------------------
+ for (size_t m = 0, chan = 0; m < get_num_mboards(); m++){
+ buff += str(boost::format(
+ " RX DSP %d: %s\n"
+ ) % m
+ % _rx_dsp(m)[DSP_PROP_NAME].as<std::string>()
+ );
+ for (; chan < (m + 1)*get_rx_subdev_spec(m).size(); chan++){
+ buff += str(boost::format(
+ " RX Channel: %u\n"
+ " RX Dboard: %s\n"
+ " RX Subdev: %s\n"
+ ) % chan
+ % _rx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
+ % _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
+ );
+ }
+ }
+
+ //----------- tx side of life ----------------------------------
+ for (size_t m = 0, chan = 0; m < get_num_mboards(); m++){
+ buff += str(boost::format(
+ " TX DSP %d: %s\n"
+ ) % m
+ % _tx_dsp(m)[DSP_PROP_NAME].as<std::string>()
+ );
+ for (; chan < (m + 1)*get_tx_subdev_spec(m).size(); chan++){
+ buff += str(boost::format(
+ " TX Channel: %u\n"
+ " TX Dboard: %s\n"
+ " TX Subdev: %s\n"
+ ) % chan
+ % _tx_dboard(chan)[DBOARD_PROP_NAME].as<std::string>()
+ % _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>()
+ );
+ }
+ }
+
+ return buff;
+ }
+
+ std::string get_mboard_name(size_t mboard){
+ return _mboard(mboard)[MBOARD_PROP_NAME].as<std::string>();
+ }
+
+ time_spec_t get_time_now(void){
+ return _mboard(0)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
+ }
+
+ void set_time_next_pps(const time_spec_t &time_spec){
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ _mboard(m)[MBOARD_PROP_TIME_NEXT_PPS] = time_spec;
+ }
+ }
+
+ void set_time_unknown_pps(const time_spec_t &time_spec){
+ std::cout << "Set time with unknown pps edge:" << std::endl;
+ std::cout << " 1) set times next pps (race condition)" << std::endl;
+ set_time_next_pps(time_spec);
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+
+ std::cout << " 2) catch seconds rollover at pps edge" << std::endl;
+ time_t last_secs = 0, curr_secs = 0;
+ while(curr_secs == last_secs){
+ last_secs = curr_secs;
+ curr_secs = get_time_now().get_full_secs();
+ }
+
+ std::cout << " 3) set times next pps (synchronously)" << std::endl;
+ set_time_next_pps(time_spec);
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+
+ //verify that the time registers are read to be within a few RTT
+ for (size_t m = 1; m < get_num_mboards(); m++){
+ time_spec_t time_0 = _mboard(0)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
+ time_spec_t time_i = _mboard(m)[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
+ if (time_i < time_0 or (time_i - time_0) > time_spec_t(0.01)){ //10 ms: greater than RTT but not too big
+ uhd::print_warning(str(boost::format(
+ "Detected time deviation between board %d and board 0.\n"
+ "Board 0 time is %f seconds.\n"
+ "Board %d time is %f seconds.\n"
+ ) % m % time_0.get_real_secs() % m % time_i.get_real_secs()));
+ }
+ }
+ }
+
+ void issue_stream_cmd(const stream_cmd_t &stream_cmd){
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ _mboard(m)[MBOARD_PROP_STREAM_CMD] = stream_cmd;
+ }
+ }
+
+ void set_clock_config(const clock_config_t &clock_config, size_t mboard){
+ if (mboard != ALL_MBOARDS){
+ _mboard(mboard)[MBOARD_PROP_CLOCK_CONFIG] = clock_config;
+ return;
+ }
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ set_clock_config(clock_config, m);
+ }
+ }
+
+ size_t get_num_mboards(void){
+ return (*_dev)[DEVICE_PROP_MBOARD_NAMES].as<prop_names_t>().size();
+ }
+
+ /*******************************************************************
+ * RX methods
+ ******************************************************************/
+ void set_rx_subdev_spec(const subdev_spec_t &spec, size_t mboard){
+ if (mboard != ALL_MBOARDS){
+ _mboard(mboard)[MBOARD_PROP_RX_SUBDEV_SPEC] = spec;
+ return;
+ }
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ set_rx_subdev_spec(spec, m);
+ }
+ }
+
+ subdev_spec_t get_rx_subdev_spec(size_t mboard){
+ return _mboard(mboard)[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
+ }
+
+ size_t get_rx_num_channels(void){
+ return rx_cpm()*get_num_mboards(); //total num channels
+ }
+
+ std::string get_rx_subdev_name(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>();
+ }
+
+ void set_rx_rate(double rate){
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ _rx_dsp(m)[DSP_PROP_HOST_RATE] = rate;
+ }
+ do_samp_rate_warning_message(rate, get_rx_rate(), "RX");
+ }
+
+ double get_rx_rate(void){
+ return _rx_dsp(0)[DSP_PROP_HOST_RATE].as<double>();
+ }
+
+ tune_result_t set_rx_freq(double target_freq, size_t chan){
+ tune_result_t r = tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan/rx_cpm()), chan%rx_cpm(), target_freq);
+ do_tune_freq_warning_message(target_freq, get_rx_freq(chan), "RX");
+ return r;
+ }
+
+ tune_result_t set_rx_freq(double target_freq, double lo_off, size_t chan){
+ tune_result_t r = tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan/rx_cpm()), chan%rx_cpm(), target_freq, lo_off);
+ do_tune_freq_warning_message(target_freq, get_rx_freq(chan), "RX");
+ return r;
+ }
+
+ double get_rx_freq(size_t chan){
+ return derive_freq_from_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(chan/rx_cpm()), chan%rx_cpm());
+ }
+
+ freq_range_t get_rx_freq_range(size_t chan){
+ return add_dsp_shift(_rx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _rx_dsp(chan/rx_cpm()));
+ }
+
+ void set_rx_gain(float gain, size_t chan){
+ return _rx_gain_group(chan)->set_value(gain);
+ }
+
+ float get_rx_gain(size_t chan){
+ return _rx_gain_group(chan)->get_value();
+ }
+
+ gain_range_t get_rx_gain_range(size_t chan){
+ return _rx_gain_group(chan)->get_range();
+ }
+
+ void set_rx_antenna(const std::string &ant, size_t chan){
+ _rx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant;
+ }
+
+ std::string get_rx_antenna(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>();
+ }
+
+ std::vector<std::string> get_rx_antennas(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
+ }
+
+ bool get_rx_lo_locked(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
+ }
+
+ void set_rx_bandwidth(double bandwidth, size_t chan){
+ _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth;
+ }
+
+ double get_rx_bandwidth(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH].as<double>();
+ }
+
+ float read_rssi(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_RSSI].as<float>();
+ }
+
+ dboard_iface::sptr get_rx_dboard_iface(size_t chan){
+ return _rx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
+ }
+
+ /*******************************************************************
+ * TX methods
+ ******************************************************************/
+ void set_tx_subdev_spec(const subdev_spec_t &spec, size_t mboard){
+ if (mboard != ALL_MBOARDS){
+ _mboard(mboard)[MBOARD_PROP_TX_SUBDEV_SPEC] = spec;
+ return;
+ }
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ set_tx_subdev_spec(spec, m);
+ }
+ }
+
+ subdev_spec_t get_tx_subdev_spec(size_t mboard){
+ return _mboard(mboard)[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
+ }
+
+ std::string get_tx_subdev_name(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>();
+ }
+
+ size_t get_tx_num_channels(void){
+ return tx_cpm()*get_num_mboards(); //total num channels
+ }
+
+ void set_tx_rate(double rate){
+ for (size_t m = 0; m < get_num_mboards(); m++){
+ _tx_dsp(m)[DSP_PROP_HOST_RATE] = rate;
+ }
+ do_samp_rate_warning_message(rate, get_tx_rate(), "TX");
+ }
+
+ double get_tx_rate(void){
+ return _tx_dsp(0)[DSP_PROP_HOST_RATE].as<double>();
+ }
+
+ tune_result_t set_tx_freq(double target_freq, size_t chan){
+ tune_result_t r = tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan/tx_cpm()), chan%tx_cpm(), target_freq);
+ do_tune_freq_warning_message(target_freq, get_tx_freq(chan), "TX");
+ return r;
+ }
+
+ tune_result_t set_tx_freq(double target_freq, double lo_off, size_t chan){
+ tune_result_t r = tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan/tx_cpm()), chan%tx_cpm(), target_freq, lo_off);
+ do_tune_freq_warning_message(target_freq, get_tx_freq(chan), "TX");
+ return r;
+ }
+
+ double get_tx_freq(size_t chan){
+ return derive_freq_from_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(chan/tx_cpm()), chan%tx_cpm());
+ }
+
+ freq_range_t get_tx_freq_range(size_t chan){
+ return add_dsp_shift(_tx_subdev(chan)[SUBDEV_PROP_FREQ_RANGE].as<freq_range_t>(), _tx_dsp(chan/tx_cpm()));
+ }
+
+ void set_tx_gain(float gain, size_t chan){
+ return _tx_gain_group(chan)->set_value(gain);
+ }
+
+ float get_tx_gain(size_t chan){
+ return _tx_gain_group(chan)->get_value();
+ }
+
+ gain_range_t get_tx_gain_range(size_t chan){
+ return _tx_gain_group(chan)->get_range();
+ }
+
+ void set_tx_antenna(const std::string &ant, size_t chan){
+ _tx_subdev(chan)[SUBDEV_PROP_ANTENNA] = ant;
+ }
+
+ std::string get_tx_antenna(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA].as<std::string>();
+ }
+
+ std::vector<std::string> get_tx_antennas(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>();
+ }
+
+ bool get_tx_lo_locked(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
+ }
+
+ void set_tx_bandwidth(double bandwidth, size_t chan){
+ _tx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth;
+ }
+
+ double get_tx_bandwidth(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_BANDWIDTH].as<double>();
+ }
+
+ dboard_iface::sptr get_tx_dboard_iface(size_t chan){
+ return _tx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
+ }
+
+private:
+ device::sptr _dev;
+
+ size_t rx_cpm(void){ //channels per mboard
+ size_t nchan = get_rx_subdev_spec(0).size();
+ for (size_t m = 1; m < get_num_mboards(); m++){
+ if (nchan != get_rx_subdev_spec(m).size()){
+ throw std::runtime_error("rx subdev spec size inconsistent across all mboards");
+ }
+ }
+ return nchan;
+ }
+
+ size_t tx_cpm(void){ //channels per mboard
+ size_t nchan = get_tx_subdev_spec(0).size();
+ for (size_t m = 1; m < get_num_mboards(); m++){
+ if (nchan != get_tx_subdev_spec(m).size()){
+ throw std::runtime_error("tx subdev spec size inconsistent across all mboards");
+ }
+ }
+ return nchan;
+ }
+
+ wax::obj _mboard(size_t mboard){
+ std::string mb_name = (*_dev)[DEVICE_PROP_MBOARD_NAMES].as<prop_names_t>().at(mboard);
+ return (*_dev)[named_prop_t(DEVICE_PROP_MBOARD, mb_name)];
+ }
+ wax::obj _rx_dsp(size_t mboard){
+ return _mboard(mboard)[MBOARD_PROP_RX_DSP];
+ }
+ wax::obj _tx_dsp(size_t mboard){
+ return _mboard(mboard)[MBOARD_PROP_TX_DSP];
+ }
+ wax::obj _rx_dboard(size_t chan){
+ std::string db_name = get_rx_subdev_spec(chan/rx_cpm()).at(chan%rx_cpm()).db_name;
+ return _mboard(chan/rx_cpm())[named_prop_t(MBOARD_PROP_RX_DBOARD, db_name)];
+ }
+ wax::obj _tx_dboard(size_t chan){
+ std::string db_name = get_tx_subdev_spec(chan/tx_cpm()).at(chan%tx_cpm()).db_name;
+ return _mboard(chan/tx_cpm())[named_prop_t(MBOARD_PROP_TX_DBOARD, db_name)];
+ }
+ wax::obj _rx_subdev(size_t chan){
+ std::string sd_name = get_rx_subdev_spec(chan/rx_cpm()).at(chan%rx_cpm()).sd_name;
+ return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
+ }
+ wax::obj _tx_subdev(size_t chan){
+ std::string sd_name = get_tx_subdev_spec(chan/tx_cpm()).at(chan%tx_cpm()).sd_name;
+ return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)];
+ }
+ gain_group::sptr _rx_gain_group(size_t chan){
+ std::string sd_name = get_rx_subdev_spec(chan/rx_cpm()).at(chan%rx_cpm()).sd_name;
+ return _rx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
+ }
+ gain_group::sptr _tx_gain_group(size_t chan){
+ std::string sd_name = get_tx_subdev_spec(chan/tx_cpm()).at(chan%tx_cpm()).sd_name;
+ return _tx_dboard(chan)[named_prop_t(DBOARD_PROP_GAIN_GROUP, sd_name)].as<gain_group::sptr>();
+ }
+};
+
+/***********************************************************************
+ * The Make Function
+ **********************************************************************/
+multi_usrp::sptr multi_usrp::make(const device_addr_t &dev_addr){
+ return sptr(new multi_usrp_impl(dev_addr));
+}
diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp
deleted file mode 100644
index b89b76eed..000000000
--- a/host/lib/usrp/simple_usrp.cpp
+++ /dev/null
@@ -1,222 +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 <http://www.gnu.org/licenses/>.
-//
-
-#include <uhd/usrp/single_usrp.hpp>
-#include <uhd/usrp/simple_usrp.hpp>
-#include <uhd/utils/warning.hpp>
-
-using namespace uhd;
-using namespace uhd::usrp;
-
-/***********************************************************************
- * Simple USRP Implementation
- **********************************************************************/
-class simple_usrp_impl : public simple_usrp{
-public:
- simple_usrp_impl(const device_addr_t &addr){
- _sdev = single_usrp::make(addr);
- }
-
- ~simple_usrp_impl(void){
- /* NOP */
- }
-
- device::sptr get_device(void){
- return _sdev->get_device();
- }
-
- std::string get_pp_string(void){
- return _sdev->get_pp_string();
- }
-
- /*******************************************************************
- * Misc
- ******************************************************************/
- time_spec_t get_time_now(void){
- return _sdev->get_time_now();
- }
-
- void set_time_now(const time_spec_t &time_spec){
- return _sdev->set_time_now(time_spec);
- }
-
- void set_time_next_pps(const time_spec_t &time_spec){
- return _sdev->set_time_next_pps(time_spec);
- }
-
- void issue_stream_cmd(const stream_cmd_t &stream_cmd){
- return _sdev->issue_stream_cmd(stream_cmd);
- }
-
- void set_clock_config(const clock_config_t &clock_config){
- return _sdev->set_clock_config(clock_config);
- }
-
- /*******************************************************************
- * RX methods
- ******************************************************************/
- void set_rx_subdev_spec(const subdev_spec_t &spec){
- return _sdev->set_rx_subdev_spec(spec);
- }
-
- subdev_spec_t get_rx_subdev_spec(void){
- return _sdev->get_rx_subdev_spec();
- }
-
- void set_rx_rate(double rate){
- return _sdev->set_rx_rate(rate);
- }
-
- double get_rx_rate(void){
- return _sdev->get_rx_rate();
- }
-
- tune_result_t set_rx_freq(double target_freq){
- return _sdev->set_rx_freq(target_freq);
- }
-
- tune_result_t set_rx_freq(double target_freq, double lo_off){
- return _sdev->set_rx_freq(target_freq, lo_off);
- }
-
- double get_rx_freq(void){
- return _sdev->get_rx_freq();
- }
-
- freq_range_t get_rx_freq_range(void){
- return _sdev->get_rx_freq_range();
- }
-
- void set_rx_gain(float gain){
- return _sdev->set_rx_gain(gain);
- }
-
- float get_rx_gain(void){
- return _sdev->get_rx_gain();
- }
-
- gain_range_t get_rx_gain_range(void){
- return _sdev->get_rx_gain_range();
- }
-
- void set_rx_antenna(const std::string &ant){
- return _sdev->set_rx_antenna(ant);
- }
-
- std::string get_rx_antenna(void){
- return _sdev->get_rx_antenna();
- }
-
- std::vector<std::string> get_rx_antennas(void){
- return _sdev->get_rx_antennas();
- }
-
- bool get_rx_lo_locked(void){
- return _sdev->get_rx_lo_locked();
- }
-
- float read_rssi(void){
- return _sdev->read_rssi();
- }
-
- dboard_iface::sptr get_rx_dboard_iface(void){
- return _sdev->get_rx_dboard_iface();
- }
-
- /*******************************************************************
- * TX methods
- ******************************************************************/
- void set_tx_subdev_spec(const subdev_spec_t &spec){
- return _sdev->set_tx_subdev_spec(spec);
- }
-
- subdev_spec_t get_tx_subdev_spec(void){
- return _sdev->get_tx_subdev_spec();
- }
-
- void set_tx_rate(double rate){
- return _sdev->set_tx_rate(rate);
- }
-
- double get_tx_rate(void){
- return _sdev->get_tx_rate();
- }
-
- tune_result_t set_tx_freq(double target_freq){
- return _sdev->set_tx_freq(target_freq);
- }
-
- tune_result_t set_tx_freq(double target_freq, double lo_off){
- return _sdev->set_tx_freq(target_freq, lo_off);
- }
-
- double get_tx_freq(void){
- return _sdev->get_tx_freq();
- }
-
- freq_range_t get_tx_freq_range(void){
- return _sdev->get_tx_freq_range();
- }
-
- void set_tx_gain(float gain){
- return _sdev->set_tx_gain(gain);
- }
-
- float get_tx_gain(void){
- return _sdev->get_tx_gain();
- }
-
- gain_range_t get_tx_gain_range(void){
- return _sdev->get_tx_gain_range();
- }
-
- void set_tx_antenna(const std::string &ant){
- return _sdev->set_tx_antenna(ant);
- }
-
- std::string get_tx_antenna(void){
- return _sdev->get_tx_antenna();
- }
-
- std::vector<std::string> get_tx_antennas(void){
- return _sdev->get_tx_antennas();
- }
-
- bool get_tx_lo_locked(void){
- return _sdev->get_tx_lo_locked();
- }
-
- dboard_iface::sptr get_tx_dboard_iface(void){
- return _sdev->get_tx_dboard_iface();
- }
-
-private:
- single_usrp::sptr _sdev;
-};
-
-/***********************************************************************
- * The Make Function
- **********************************************************************/
-simple_usrp::sptr simple_usrp::make(const device_addr_t &dev_addr){
- uhd::print_warning(
- "The simple USRP interface has been deprecated.\n"
- "Please switch to the single USRP interface.\n"
- "#include <uhd/usrp/single_usrp.hpp>\n"
- "single_usrp::sptr sdev = single_usrp::make(args);\n"
- );
- return sptr(new simple_usrp_impl(dev_addr));
-}
diff --git a/host/lib/usrp/single_usrp.cpp b/host/lib/usrp/single_usrp.cpp
index bb4af44b8..2faa1280c 100644
--- a/host/lib/usrp/single_usrp.cpp
+++ b/host/lib/usrp/single_usrp.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include "wrapper_utils.hpp"
#include <uhd/usrp/single_usrp.hpp>
#include <uhd/usrp/tune_helper.hpp>
#include <uhd/utils/assert.hpp>
@@ -32,11 +33,6 @@
using namespace uhd;
using namespace uhd::usrp;
-static inline freq_range_t add_dsp_shift(const freq_range_t &range, wax::obj dsp){
- double codec_rate = dsp[DSP_PROP_CODEC_RATE].as<double>();
- return freq_range_t(range.min - codec_rate/2.0, range.max + codec_rate/2.0);
-}
-
/***********************************************************************
* Simple USRP Implementation
**********************************************************************/
@@ -46,14 +42,13 @@ public:
_dev = device::make(addr);
}
- ~single_usrp_impl(void){
- /* NOP */
- }
-
device::sptr get_device(void){
return _dev;
}
+ /*******************************************************************
+ * Mboard methods
+ ******************************************************************/
std::string get_pp_string(void){
std::string buff = str(boost::format(
"Single USRP:\n"
@@ -101,9 +96,10 @@ public:
return buff;
}
- /*******************************************************************
- * Misc
- ******************************************************************/
+ std::string get_mboard_name(void){
+ return _mboard()[MBOARD_PROP_NAME].as<std::string>();
+ }
+
time_spec_t get_time_now(void){
return _mboard()[MBOARD_PROP_TIME_NOW].as<time_spec_t>();
}
@@ -135,8 +131,13 @@ public:
return _mboard()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();
}
+ std::string get_rx_subdev_name(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>();
+ }
+
void set_rx_rate(double rate){
_rx_dsp()[DSP_PROP_HOST_RATE] = rate;
+ do_samp_rate_warning_message(rate, get_rx_rate(), "RX");
}
double get_rx_rate(void){
@@ -144,11 +145,15 @@ public:
}
tune_result_t set_rx_freq(double target_freq, size_t chan){
- return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq);
+ tune_result_t r = tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq);
+ do_tune_freq_warning_message(target_freq, get_rx_freq(chan), "RX");
+ return r;
}
tune_result_t set_rx_freq(double target_freq, double lo_off, size_t chan){
- return tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq, lo_off);
+ tune_result_t r = tune_rx_subdev_and_dsp(_rx_subdev(chan), _rx_dsp(), chan, target_freq, lo_off);
+ do_tune_freq_warning_message(target_freq, get_rx_freq(chan), "RX");
+ return r;
}
double get_rx_freq(size_t chan){
@@ -187,6 +192,14 @@ public:
return _rx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
}
+ void set_rx_bandwidth(double bandwidth, size_t chan){
+ _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth;
+ }
+
+ double get_rx_bandwidth(size_t chan){
+ return _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH].as<double>();
+ }
+
float read_rssi(size_t chan){
return _rx_subdev(chan)[SUBDEV_PROP_RSSI].as<float>();
}
@@ -206,8 +219,13 @@ public:
return _mboard()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();
}
+ std::string get_tx_subdev_name(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_NAME].as<std::string>();
+ }
+
void set_tx_rate(double rate){
_tx_dsp()[DSP_PROP_HOST_RATE] = rate;
+ do_samp_rate_warning_message(rate, get_tx_rate(), "TX");
}
double get_tx_rate(void){
@@ -215,11 +233,15 @@ public:
}
tune_result_t set_tx_freq(double target_freq, size_t chan){
- return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq);
+ tune_result_t r = tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq);
+ do_tune_freq_warning_message(target_freq, get_tx_freq(chan), "TX");
+ return r;
}
tune_result_t set_tx_freq(double target_freq, double lo_off, size_t chan){
- return tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq, lo_off);
+ tune_result_t r = tune_tx_subdev_and_dsp(_tx_subdev(chan), _tx_dsp(), chan, target_freq, lo_off);
+ do_tune_freq_warning_message(target_freq, get_tx_freq(chan), "TX");
+ return r;
}
double get_tx_freq(size_t chan){
@@ -258,6 +280,14 @@ public:
return _tx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as<bool>();
}
+ void set_tx_bandwidth(double bandwidth, size_t chan){
+ _tx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth;
+ }
+
+ double get_tx_bandwidth(size_t chan){
+ return _tx_subdev(chan)[SUBDEV_PROP_BANDWIDTH].as<double>();
+ }
+
dboard_iface::sptr get_tx_dboard_iface(size_t chan){
return _tx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as<dboard_iface::sptr>();
}
diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp
index 7a3e72867..95d2cbb12 100644
--- a/host/lib/usrp/subdev_spec.cpp
+++ b/host/lib/usrp/subdev_spec.cpp
@@ -34,6 +34,10 @@ subdev_spec_pair_t::subdev_spec_pair_t(
/* NOP */
}
+bool usrp::operator==(const subdev_spec_pair_t &lhs, const subdev_spec_pair_t &rhs){
+ return (lhs.db_name == rhs.db_name) and (lhs.sd_name == rhs.sd_name);
+}
+
subdev_spec_t::subdev_spec_t(const std::string &markup){
BOOST_FOREACH(const std::string &pair, std::split_string(markup)){
if (pair == "") continue;
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 0a16f7a43..6728d9b15 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -63,6 +63,7 @@ struct usrp1_impl::io_impl{
data_transport(data_transport),
underflow_poll_samp_count(0),
overflow_poll_samp_count(0),
+ curr_buff_committed(true),
curr_buff(offset_send_buffer::make(data_transport->get_send_buff()))
{
/* NOP */
@@ -86,6 +87,7 @@ struct usrp1_impl::io_impl{
//all of this to ensure only aligned lengths are committed
//NOTE: you must commit before getting a new buffer
//since the vrt packet handler obeys this, we are ok
+ bool curr_buff_committed;
offset_send_buffer::sptr curr_buff;
void commit_send_buff(offset_send_buffer::sptr, offset_send_buffer::sptr, size_t);
void flush_send_buff(void);
@@ -121,6 +123,7 @@ void usrp1_impl::io_impl::commit_send_buff(
//commit the current buffer
curr->buff->commit(num_bytes_to_commit);
+ curr_buff_committed = true;
}
/*!
@@ -145,7 +148,7 @@ void usrp1_impl::io_impl::flush_send_buff(void){
bool usrp1_impl::io_impl::get_send_buffs(
vrt_packet_handler::managed_send_buffs_t &buffs, double timeout
){
- UHD_ASSERT_THROW(buffs.size() == 1);
+ UHD_ASSERT_THROW(curr_buff_committed and buffs.size() == 1);
//try to get a new managed buffer with timeout
offset_send_buffer::sptr next_buff(offset_send_buffer::make(data_transport->get_send_buff(timeout)));
@@ -163,6 +166,7 @@ bool usrp1_impl::io_impl::get_send_buffs(
//store the next buffer for the next call
curr_buff = next_buff;
+ curr_buff_committed = false;
return true;
}
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 07eda08c3..bbe9c273f 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -46,7 +46,7 @@ struct usrp2_impl::io_impl{
io_impl(size_t num_frames, size_t width):
packet_handler_recv_state(width),
- recv_pirate_booty(alignment_buffer_type::make(num_frames, width)),
+ recv_pirate_booty(alignment_buffer_type::make(num_frames-3, width)),
async_msg_fifo(bounded_buffer<async_metadata_t>::make(100/*messages deep*/))
{
/* NOP */
@@ -197,6 +197,15 @@ static bool get_send_buffs(
return good;
}
+size_t usrp2_impl::get_max_send_samps_per_packet(void) const{
+ static const size_t hdr_size = 0
+ + vrt::max_if_hdr_words32*sizeof(boost::uint32_t)
+ - sizeof(vrt::if_packet_info_t().cid) //no class id ever used
+ ;
+ const size_t bpp = _data_transports.front()->get_send_frame_size() - hdr_size;
+ return bpp/_tx_otw_type.get_sample_size();
+}
+
size_t usrp2_impl::send(
const std::vector<const void *> &buffs, size_t num_samps,
const tx_metadata_t &metadata, const io_type_t &io_type,
@@ -217,6 +226,16 @@ size_t usrp2_impl::send(
/***********************************************************************
* Receive Data
**********************************************************************/
+size_t usrp2_impl::get_max_recv_samps_per_packet(void) const{
+ static const size_t hdr_size = 0
+ + vrt::max_if_hdr_words32*sizeof(boost::uint32_t)
+ + sizeof(vrt::if_packet_info_t().tlr) //forced to have trailer
+ - sizeof(vrt::if_packet_info_t().cid) //no class id ever used
+ ;
+ const size_t bpp = _data_transports.front()->get_recv_frame_size() - hdr_size;
+ return bpp/_rx_otw_type.get_sample_size();
+}
+
size_t usrp2_impl::recv(
const std::vector<void *> &buffs, size_t num_samps,
rx_metadata_t &metadata, const io_type_t &io_type,
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index e12c4d6d4..558726a2b 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -184,24 +184,18 @@ public:
~usrp2_impl(void);
//the io interface
- size_t get_max_send_samps_per_packet(void) const{
- const size_t bytes_per_packet = _data_transports.front()->get_send_frame_size() - _max_tx_header_bytes;
- return bytes_per_packet/_tx_otw_type.get_sample_size();
- }
size_t send(
const std::vector<const void *> &, size_t,
const uhd::tx_metadata_t &, const uhd::io_type_t &,
uhd::device::send_mode_t, double
);
- size_t get_max_recv_samps_per_packet(void) const{
- const size_t bytes_per_packet = _data_transports.front()->get_recv_frame_size() - _max_rx_header_bytes;
- return bytes_per_packet/_rx_otw_type.get_sample_size();
- }
size_t recv(
const std::vector<void *> &, size_t,
uhd::rx_metadata_t &, const uhd::io_type_t &,
uhd::device::recv_mode_t, double
);
+ size_t get_max_send_samps_per_packet(void) const;
+ size_t get_max_recv_samps_per_packet(void) const;
bool recv_async_msg(uhd::async_metadata_t &, double);
private:
@@ -215,20 +209,9 @@ private:
//io impl methods and members
std::vector<uhd::transport::udp_zero_copy::sptr> _data_transports;
+ uhd::otw_type_t _rx_otw_type, _tx_otw_type;
UHD_PIMPL_DECL(io_impl) _io_impl;
void io_init(void);
-
- //over-the-wire structs and constants
- uhd::otw_type_t _rx_otw_type, _tx_otw_type;
- static const size_t _max_rx_header_bytes = 0
- + uhd::transport::vrt::max_if_hdr_words32*sizeof(boost::uint32_t)
- + sizeof(uhd::transport::vrt::if_packet_info_t().tlr) //forced to have trailer
- - sizeof(uhd::transport::vrt::if_packet_info_t().cid) //no class id ever used
- ;
- static const size_t _max_tx_header_bytes = 0
- + uhd::transport::vrt::max_if_hdr_words32*sizeof(boost::uint32_t)
- - sizeof(uhd::transport::vrt::if_packet_info_t().cid) //no class id ever used
- ;
};
#endif /* INCLUDED_USRP2_IMPL_HPP */
diff --git a/host/lib/usrp/wrapper_utils.hpp b/host/lib/usrp/wrapper_utils.hpp
new file mode 100644
index 000000000..aee230fc0
--- /dev/null
+++ b/host/lib/usrp/wrapper_utils.hpp
@@ -0,0 +1,66 @@
+//
+// 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_WRAPPER_UTILS_HPP
+#define INCLUDED_LIBUHD_USRP_WRAPPER_UTILS_HPP
+
+#include <uhd/wax.hpp>
+#include <uhd/types/ranges.hpp>
+#include <uhd/usrp/dsp_props.hpp>
+#include <uhd/utils/warning.hpp>
+#include <boost/format.hpp>
+#include <cmath>
+
+static inline uhd::freq_range_t add_dsp_shift(
+ const uhd::freq_range_t &range,
+ wax::obj dsp
+){
+ double codec_rate = dsp[uhd::usrp::DSP_PROP_CODEC_RATE].as<double>();
+ return uhd::freq_range_t(range.min - codec_rate/2.0, range.max + codec_rate/2.0);
+}
+
+static inline void do_samp_rate_warning_message(
+ double target_rate,
+ double actual_rate,
+ const std::string &xx
+){
+ static const double max_allowed_error = 1.0; //Sps
+ if (std::abs(target_rate - actual_rate) > max_allowed_error){
+ uhd::print_warning(str(boost::format(
+ "The hardware does not support the requested %s sample rate:\n"
+ "Target sample rate: %f MSps\n"
+ "Actual sample rate: %f MSps\n"
+ ) % xx % (target_rate/1e6) % (actual_rate/1e6)));
+ }
+}
+
+static inline void do_tune_freq_warning_message(
+ double target_freq,
+ double actual_freq,
+ const std::string &xx
+){
+ static const double max_allowed_error = 1.0; //Hz
+ if (std::abs(target_freq - actual_freq) > max_allowed_error){
+ uhd::print_warning(str(boost::format(
+ "The hardware does not support the requested %s frequency:\n"
+ "Target frequency: %f MHz\n"
+ "Actual frequency: %f MHz\n"
+ ) % xx % (target_freq/1e6) % (actual_freq/1e6)));
+ }
+}
+
+#endif /* INCLUDED_LIBUHD_USRP_WRAPPER_UTILS_HPP */
diff --git a/host/lib/utils/thread_priority.cpp b/host/lib/utils/thread_priority.cpp
index c35e5fcb1..f09d1b1d6 100644
--- a/host/lib/utils/thread_priority.cpp
+++ b/host/lib/utils/thread_priority.cpp
@@ -16,6 +16,8 @@
//
#include <uhd/utils/thread_priority.hpp>
+#include <uhd/utils/warning.hpp>
+#include <boost/format.hpp>
#include <stdexcept>
#include <iostream>
@@ -24,7 +26,12 @@ bool uhd::set_thread_priority_safe(float priority, bool realtime){
set_thread_priority(priority, realtime);
return true;
}catch(const std::exception &e){
- std::cerr << "set_thread_priority: " << e.what() << std::endl;
+ uhd::print_warning(str(boost::format(
+ "%s\n"
+ "Failed to set thread priority %d (%s):\n"
+ "Performance may be negatively affected.\n"
+ "See the general application notes.\n"
+ ) % e.what() % priority % (realtime?"realtime":"")));
return false;
}
}