summaryrefslogtreecommitdiff
path: root/gr-uhd
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd')
-rw-r--r--gr-uhd/.gitignore1
-rw-r--r--gr-uhd/grc/Makefile.am1
-rw-r--r--gr-uhd/grc/gen_uhd_usrp_blocks.py65
-rw-r--r--gr-uhd/grc/uhd_amsg_source.xml24
-rw-r--r--gr-uhd/grc/uhd_block_tree.xml1
-rw-r--r--gr-uhd/include/Makefile.am3
-rw-r--r--gr-uhd/include/gr_uhd_amsg_source.h39
-rw-r--r--gr-uhd/include/gr_uhd_usrp_source.h1
-rw-r--r--gr-uhd/lib/Makefile.am3
-rw-r--r--gr-uhd/lib/gr_uhd_amsg_source.cc88
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc34
-rw-r--r--gr-uhd/swig/__init__.py2
-rw-r--r--gr-uhd/swig/uhd_swig.i4
13 files changed, 227 insertions, 39 deletions
diff --git a/gr-uhd/.gitignore b/gr-uhd/.gitignore
index b336cc7ce..a37fc0c1a 100644
--- a/gr-uhd/.gitignore
+++ b/gr-uhd/.gitignore
@@ -1,2 +1,3 @@
/Makefile
/Makefile.in
+/*.pc
diff --git a/gr-uhd/grc/Makefile.am b/gr-uhd/grc/Makefile.am
index 7e73a5b39..42a35b1c1 100644
--- a/gr-uhd/grc/Makefile.am
+++ b/gr-uhd/grc/Makefile.am
@@ -31,6 +31,7 @@ BUILT_SOURCES += $(generated_uhd_usrp_blocks)
dist_grcblocks_DATA = \
uhd_block_tree.xml \
+ uhd_amsg_source.xml \
$(BUILT_SOURCES)
########################################################################
diff --git a/gr-uhd/grc/gen_uhd_usrp_blocks.py b/gr-uhd/grc/gen_uhd_usrp_blocks.py
index 82b6aa964..c77df6c97 100644
--- a/gr-uhd/grc/gen_uhd_usrp_blocks.py
+++ b/gr-uhd/grc/gen_uhd_usrp_blocks.py
@@ -29,20 +29,34 @@ MAIN_TMPL = """\
io_type=uhd.io_type.\$type.type,
num_channels=\$nchan,
)
-\#if \$ref_clk()
-self.\$(id).set_clock_config(uhd.clock_config.external(), uhd.ALL_MBOARDS)
-\#end if
-\#if \$sync()
-self.\$(id).set_time_unknown_pps(uhd.time_spec())
-\#end if
\#if \$clock_rate()
self.\$(id).set_clock_rate(\$clock_rate, uhd.ALL_MBOARDS)
\#end if
#for $m in range($max_mboards)
+########################################################################
+\#if \$num_mboards() > $m and \$ref_source$(m)() == 'external'
+self.\$(id).set_clock_config(uhd.clock_config.external(), $m)
+\#end if
+########################################################################
+\#if \$num_mboards() > $m and \$ref_source$(m)() == 'internal'
+self.\$(id).set_clock_config(uhd.clock_config.internal(), $m)
+\#end if
+########################################################################
+\#if \$num_mboards() > $m and \$ref_source$(m)() == 'mimo'
+_config = uhd.clock_config()
+_config.ref_source = uhd.clock_config.REF_MIMO
+_config.pps_source = uhd.clock_config.PPS_MIMO
+self.\$(id).set_clock_config(_config, $m)
+\#end if
+########################################################################
\#if \$num_mboards() > $m and \$sd_spec$(m)()
self.\$(id).set_subdev_spec(\$sd_spec$(m), $m)
\#end if
+########################################################################
#end for
+\#if \$sync()
+self.\$(id).set_time_unknown_pps(uhd.time_spec())
+\#end if
self.\$(id).set_samp_rate(\$samp_rate)
#for $n in range($max_nchan)
\#if \$nchan() > $n
@@ -95,21 +109,6 @@ self.\$(id).set_bandwidth(\$bw$(n), $n)
</hide>
</param>
<param>
- <name>Ref Clock</name>
- <key>ref_clk</key>
- <value></value>
- <type>enum</type>
- <hide>\#if \$ref_clk() then 'none' else 'part'#</hide>
- <option>
- <name>External</name>
- <key>ext</key>
- </option>
- <option>
- <name>Internal</name>
- <key></key>
- </option>
- </param>
- <param>
<name>Sync</name>
<key>sync</key>
<value></value>
@@ -150,6 +149,25 @@ self.\$(id).set_bandwidth(\$bw$(n), $n)
</param>
#for $m in range($max_mboards)
<param>
+ <name>Mb$(m): Ref Source</name>
+ <key>ref_source$(m)</key>
+ <value></value>
+ <type>enum</type>
+ <hide>
+ \#if not \$num_mboards() > $m
+ all
+ \#elif \$ref_source$(m)()
+ none
+ \#else
+ part
+ \#end if
+ </hide>
+ <option><name>Default</name><key></key></option>
+ <option><name>Internal</name><key>internal</key></option>
+ <option><name>External</name><key>external</key></option>
+ <option><name>MIMO Cable</name><key>mimo</key></option>
+ </param>
+ <param>
<name>Mb$(m): Subdev Spec</name>
<key>sd_spec$(m)</key>
<value></value>
@@ -209,6 +227,11 @@ USRP2 Example: addr0=192.168.10.2, addr1=192.168.10.3
Num Motherboards:
Selects the number of USRP motherboards in this device configuration.
+Reference Source:
+Where the motherboard should sync its time and clock references.
+If source and sink blocks reference the same device,
+it is only necessary to set the reference source on one of the blocks.
+
Subdevice specification:
Each motherboard should have its own subdevice specification \\
and all subdevice specifications should be the same length. \\
diff --git a/gr-uhd/grc/uhd_amsg_source.xml b/gr-uhd/grc/uhd_amsg_source.xml
new file mode 100644
index 000000000..78c9d7b58
--- /dev/null
+++ b/gr-uhd/grc/uhd_amsg_source.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<block>
+ <name>UHD: USRP Async Msg Source</name>
+ <key>uhd_amsg_source</key>
+ <import>from gnuradio import uhd</import>
+ <make>uhd.amsg_source(device_addr=$dev_addr, msgq=$(id)_msgq_out)</make>
+ <param>
+ <name>Device Addr</name>
+ <key>dev_addr</key>
+ <value></value>
+ <type>string</type>
+ <hide>
+ #if $dev_addr()
+ none
+ #else
+ part
+ #end if
+ </hide>
+ </param>
+ <source>
+ <name>out</name>
+ <type>msg</type>
+ </source>
+</block>
diff --git a/gr-uhd/grc/uhd_block_tree.xml b/gr-uhd/grc/uhd_block_tree.xml
index 8a9f62f7c..5d3b49393 100644
--- a/gr-uhd/grc/uhd_block_tree.xml
+++ b/gr-uhd/grc/uhd_block_tree.xml
@@ -10,5 +10,6 @@
<name>UHD</name>
<block>uhd_usrp_source</block>
<block>uhd_usrp_sink</block>
+ <block>uhd_amsg_source</block>
</cat>
</cat>
diff --git a/gr-uhd/include/Makefile.am b/gr-uhd/include/Makefile.am
index 4a04c98c1..70b80681b 100644
--- a/gr-uhd/include/Makefile.am
+++ b/gr-uhd/include/Makefile.am
@@ -24,4 +24,5 @@ include $(top_srcdir)/Makefile.common
grinclude_HEADERS = \
gr_uhd_api.h \
gr_uhd_usrp_source.h \
- gr_uhd_usrp_sink.h
+ gr_uhd_usrp_sink.h \
+ gr_uhd_amsg_source.h
diff --git a/gr-uhd/include/gr_uhd_amsg_source.h b/gr-uhd/include/gr_uhd_amsg_source.h
new file mode 100644
index 000000000..bc0feb438
--- /dev/null
+++ b/gr-uhd/include/gr_uhd_amsg_source.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_UHD_AMSG_SOURCE_H
+#define INCLUDED_GR_UHD_AMSG_SOURCE_H
+
+#include <gr_uhd_api.h>
+#include <uhd/usrp/multi_usrp.hpp>
+#include <gr_msg_queue.h>
+
+class uhd_amsg_source;
+
+GR_UHD_API boost::shared_ptr<uhd_amsg_source> uhd_make_amsg_source(
+ const uhd::device_addr_t &device_addr,
+ gr_msg_queue_sptr msgq
+);
+
+class GR_UHD_API uhd_amsg_source{
+};
+
+#endif /* INCLUDED_GR_UHD_AMSG_SOURCE_H */
diff --git a/gr-uhd/include/gr_uhd_usrp_source.h b/gr-uhd/include/gr_uhd_usrp_source.h
index 36331f782..6e51a1423 100644
--- a/gr-uhd/include/gr_uhd_usrp_source.h
+++ b/gr-uhd/include/gr_uhd_usrp_source.h
@@ -125,7 +125,6 @@ public:
/*!
* Get the actual dboard gain setting of named stage.
- * \param name the name of the gain stage
* \param chan the channel index 0 to N-1
* \return the actual gain in dB
*/
diff --git a/gr-uhd/lib/Makefile.am b/gr-uhd/lib/Makefile.am
index c27682f7f..c322c6124 100644
--- a/gr-uhd/lib/Makefile.am
+++ b/gr-uhd/lib/Makefile.am
@@ -31,7 +31,8 @@ lib_LTLIBRARIES = libgnuradio-uhd.la
libgnuradio_uhd_la_SOURCES = \
gr_uhd_usrp_source.cc \
- gr_uhd_usrp_sink.cc
+ gr_uhd_usrp_sink.cc \
+ gr_uhd_amsg_source.cc
libgnuradio_uhd_la_LIBADD = \
$(GNURADIO_CORE_LA) \
diff --git a/gr-uhd/lib/gr_uhd_amsg_source.cc b/gr-uhd/lib/gr_uhd_amsg_source.cc
new file mode 100644
index 000000000..f2958f115
--- /dev/null
+++ b/gr-uhd/lib/gr_uhd_amsg_source.cc
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gr_uhd_amsg_source.h>
+#include <boost/bind.hpp>
+#include <gruel/thread.h>
+
+/***********************************************************************
+ * UHD Asynchronous Message Source Impl
+ **********************************************************************/
+class uhd_amsg_source_impl : public uhd_amsg_source{
+public:
+ uhd_amsg_source_impl(
+ const uhd::device_addr_t &device_addr,
+ gr_msg_queue_sptr msgq
+ ):
+ _msgq(msgq), _running(true)
+ {
+ _dev = uhd::usrp::multi_usrp::make(device_addr);
+ _amsg_thread =
+ gruel::thread(boost::bind(&uhd_amsg_source_impl::recv_loop, this));
+ }
+
+ ~uhd_amsg_source_impl()
+ {
+ _running = false;
+ _amsg_thread.join();
+ }
+
+ void recv_loop()
+ {
+ gr_message_sptr msg;
+ uhd::async_metadata_t *md;
+
+ while (_running) {
+ msg = gr_make_message(0, 0.0, 0.0, sizeof(uhd::async_metadata_t));
+ md = (uhd::async_metadata_t *) msg->msg();
+
+ while (!_dev->get_device()->recv_async_msg(*md, 0.1)) {
+ if (!_running)
+ return;
+ }
+
+ post(msg);
+ }
+ }
+
+ void post(gr_message_sptr msg)
+ {
+ _msgq->insert_tail(msg);
+ }
+
+protected:
+ uhd::usrp::multi_usrp::sptr _dev;
+ gruel::thread _amsg_thread;
+ gr_msg_queue_sptr _msgq;
+ bool _running;
+};
+
+/***********************************************************************
+ * Make UHD Asynchronous Message Source
+ **********************************************************************/
+boost::shared_ptr<uhd_amsg_source> uhd_make_amsg_source(
+ const uhd::device_addr_t &device_addr,
+ gr_msg_queue_sptr msgq
+){
+ return boost::shared_ptr<uhd_amsg_source>(
+ new uhd_amsg_source_impl(device_addr, msgq)
+ );
+}
diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc
index 9983489c3..669f890ea 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -182,19 +182,37 @@ public:
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items
){
- //wait for a packet to become available
+ //In order to allow for low-latency:
+ //We receive all available packets without timeout.
+ //This call can timeout under regular operation...
size_t num_samps = _dev->get_device()->recv(
output_items, noutput_items, _metadata,
- _type, uhd::device::RECV_MODE_ONE_PACKET, 1.0
+ _type, uhd::device::RECV_MODE_FULL_BUFF, 0.0
);
+ //If receive resulted in a timeout condition:
+ //We now receive a single packet with a large timeout.
+ if (_metadata.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT){
+ num_samps = _dev->get_device()->recv(
+ output_items, noutput_items, _metadata,
+ _type, uhd::device::RECV_MODE_ONE_PACKET, 1.0
+ );
+ }
+
//handle possible errors conditions
switch(_metadata.error_code){
case uhd::rx_metadata_t::ERROR_CODE_NONE:
+ //TODO insert tag for time stamp
break;
+ case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
+ //Assume that the user called stop() on the flow graph.
+ //However, a timeout can occur under error conditions.
+ return WORK_DONE;
+
case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW:
//ignore overflows and try work again
+ //TODO insert tag for overflow
return work(noutput_items, input_items, output_items);
default:
@@ -204,18 +222,6 @@ public:
return num_samps;
}
- //advance the pointers and count by num_samps
- noutput_items -= num_samps;
- for (size_t i = 0; i < _nchan; i++){
- _tmp_buffs[i] = static_cast<char *>(output_items[i]) + num_samps*_type.size;
- }
-
- //receive all available packets without timeout
- num_samps += _dev->get_device()->recv(
- _tmp_buffs, noutput_items, _metadata,
- _type, uhd::device::RECV_MODE_FULL_BUFF, 0.0
- );
-
return num_samps;
}
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py
index 7ed689ec0..5c0c011b7 100644
--- a/gr-uhd/swig/__init__.py
+++ b/gr-uhd/swig/__init__.py
@@ -60,7 +60,7 @@ def _prepare_uhd_swig():
if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj)
#Cast constructor args (FIXME swig handle overloads?)
- for attr in ('usrp_source', 'usrp_sink'):
+ for attr in ('usrp_source', 'usrp_sink', 'amsg_source'):
def constructor_factory(old_constructor):
def constructor_interceptor(*args, **kwargs):
args = list(args)
diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i
index 9bdb962c9..b58fe9e18 100644
--- a/gr-uhd/swig/uhd_swig.i
+++ b/gr-uhd/swig/uhd_swig.i
@@ -55,6 +55,7 @@
%{
#include <gr_uhd_usrp_source.h>
#include <gr_uhd_usrp_sink.h>
+#include <gr_uhd_amsg_source.h>
%}
////////////////////////////////////////////////////////////////////////
@@ -114,6 +115,9 @@ GR_SWIG_BLOCK_MAGIC(uhd,usrp_source)
GR_SWIG_BLOCK_MAGIC(uhd,usrp_sink)
%include <gr_uhd_usrp_sink.h>
+GR_SWIG_BLOCK_MAGIC(uhd,amsg_source)
+%include <gr_uhd_amsg_source.h>
+
////////////////////////////////////////////////////////////////////////
// helpful constants
////////////////////////////////////////////////////////////////////////