summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2011-09-22 20:03:47 -0700
committerJosh Blum2011-09-24 10:26:46 -0700
commit91ace5a39a171ec7367c4030a1739d2f709eaed6 (patch)
tree6bf8c9948c48a1b1335051b521a3af3406a2ccc0
parentbe67ead62f6c5d9abcb319cf2e6f1727fe4618d8 (diff)
downloadgnuradio-91ace5a39a171ec7367c4030a1739d2f709eaed6.tar.gz
gnuradio-91ace5a39a171ec7367c4030a1739d2f709eaed6.tar.bz2
gnuradio-91ace5a39a171ec7367c4030a1739d2f709eaed6.zip
uhd: added documentation and tag implementations
-rw-r--r--gr-uhd/grc/gen_uhd_usrp_blocks.py5
-rw-r--r--gr-uhd/include/gr_uhd_usrp_sink.h27
-rw-r--r--gr-uhd/include/gr_uhd_usrp_source.h23
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_sink.cc85
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc24
5 files changed, 153 insertions, 11 deletions
diff --git a/gr-uhd/grc/gen_uhd_usrp_blocks.py b/gr-uhd/grc/gen_uhd_usrp_blocks.py
index c77df6c97..b6bc5fb79 100644
--- a/gr-uhd/grc/gen_uhd_usrp_blocks.py
+++ b/gr-uhd/grc/gen_uhd_usrp_blocks.py
@@ -256,6 +256,8 @@ The center frequency is the overall frequency of the RF chain. \\
For greater control of how the UHD tunes elements in the RF chain, \\
pass a tune_request object rather than a simple target frequency.
Tuning with an LO offset example: uhd.tune_request(freq, lo_off)
+Tuning without DSP: uhd.tune_request(target_freq, dsp_freq=0, \\
+dsp_freq_policy=uhd.tune_request.POLICY_MANUAL)
Antenna:
For subdevices with only one antenna, this may be left blank. \\
@@ -266,6 +268,9 @@ Bandwidth:
To use the default bandwidth filter setting, this should be zero. \\
Only certain subdevices have configurable bandwidth filters. \\
See the daughterboard application notes for possible configurations.
+
+See the UHD manual for more detailed documentation:
+http://code.ettus.com/redmine/ettus/projects/uhd/wiki
</doc>
</block>
"""
diff --git a/gr-uhd/include/gr_uhd_usrp_sink.h b/gr-uhd/include/gr_uhd_usrp_sink.h
index 2adc5f1bf..df30a3668 100644
--- a/gr-uhd/include/gr_uhd_usrp_sink.h
+++ b/gr-uhd/include/gr_uhd_usrp_sink.h
@@ -28,6 +28,33 @@
class uhd_usrp_sink;
+/*!
+ * \brief Make a new USRP sink block.
+ *
+ * The USRP sink block reads a stream and transmits the samples.
+ * The sink block also provides API calls for transmitter settings.
+ *
+ * Stream tagging:
+ *
+ * The following tag keys will be consumed by the work function:
+ * - pmt::pmt_string_to_symbol("tx_sob")
+ * - pmt::pmt_string_to_symbol("tx_eob")
+ * - pmt::pmt_string_to_symbol("tx_time")
+ *
+ * The sob and eob (start and end of burst) tag values are pmt booleans.
+ * When present, burst tags should be set to true (pmt::PMT_T).
+ *
+ * The timstamp tag value is a pmt tuple of the following:
+ * (uint64 seconds, and double fractional seconds).
+ *
+ * See the UHD manual for more detailed documentation:
+ * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
+ *
+ * \param device_addr the address to identify the hardware
+ * \param io_type the desired input data type
+ * \param num_channels number of stream from the device
+ * \return a new USRP sink block object
+ */
GR_UHD_API boost::shared_ptr<uhd_usrp_sink> uhd_make_usrp_sink(
const uhd::device_addr_t &device_addr,
const uhd::io_type_t &io_type,
diff --git a/gr-uhd/include/gr_uhd_usrp_source.h b/gr-uhd/include/gr_uhd_usrp_source.h
index 6e51a1423..432cbee15 100644
--- a/gr-uhd/include/gr_uhd_usrp_source.h
+++ b/gr-uhd/include/gr_uhd_usrp_source.h
@@ -28,6 +28,29 @@
class uhd_usrp_source;
+/*!
+ * \brief Make a new USRP source block.
+ *
+ * The USRP source block receives samples and writes to a stream.
+ * The source block also provides API calls for receiver settings.
+ *
+ * Stream tagging:
+ *
+ * The following tag keys will be produced by the work function:
+ * - pmt::pmt_string_to_symbol("rx_time")
+ *
+ * The timstamp tag value is a pmt tuple of the following:
+ * (uint64 seconds, and double fractional seconds).
+ * A timestamp tag is produced at start() and after overflows.
+ *
+ * See the UHD manual for more detailed documentation:
+ * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
+ *
+ * \param device_addr the address to identify the hardware
+ * \param io_type the desired output data type
+ * \param num_channels number of stream from the device
+ * \return a new USRP source block object
+ */
GR_UHD_API boost::shared_ptr<uhd_usrp_source> uhd_make_usrp_source(
const uhd::device_addr_t &device_addr,
const uhd::io_type_t &io_type,
diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc
index ce9d89d8d..56b2800c1 100644
--- a/gr-uhd/lib/gr_uhd_usrp_sink.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc
@@ -21,8 +21,13 @@
#include <gr_uhd_usrp_sink.h>
#include <gr_io_signature.h>
+#include <gr_tag_info.h>
#include <stdexcept>
+static const pmt::pmt_t SOB_KEY = pmt::pmt_string_to_symbol("tx_sob");
+static const pmt::pmt_t EOB_KEY = pmt::pmt_string_to_symbol("tx_eob");
+static const pmt::pmt_t TIME_KEY = pmt::pmt_string_to_symbol("tx_time");
+
/***********************************************************************
* UHD Multi USRP Sink Impl
**********************************************************************/
@@ -39,8 +44,7 @@ public:
gr_make_io_signature(0, 0, 0)
),
_type(io_type),
- _nchan(num_channels),
- _has_time_spec(_nchan > 1)
+ _nchan(num_channels)
{
_dev = uhd::usrp::multi_usrp::make(device_addr);
}
@@ -176,17 +180,22 @@ public:
* Work
**********************************************************************/
int work(
- int noutput_items,
+ int ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items
){
//send a mid-burst packet with time spec
_metadata.start_of_burst = false;
_metadata.end_of_burst = false;
- _metadata.has_time_spec = _has_time_spec;
- size_t num_sent = _dev->get_device()->send(
- input_items, noutput_items, _metadata,
+ //collect tags in this work()
+ const uint64_t samp0_count = nitems_read(0);
+ get_tags_in_range(_tags, 0, samp0_count, samp0_count + ninput_items);
+ if (not _tags.empty()) tag_work(ninput_items);
+
+ //send all ninput_items with metadata
+ const size_t num_sent = _dev->get_device()->send(
+ input_items, ninput_items, _metadata,
_type, uhd::device::SEND_MODE_FULL_BUFF, 1.0
);
@@ -195,12 +204,68 @@ public:
return num_sent;
}
+/***********************************************************************
+ * Tag Work
+ **********************************************************************/
+ inline void tag_work(int &ninput_items){
+ //the for loop below assumes tags sorted by count low -> high
+ std::sort(_tags.begin(), _tags.end(), gr_tags::nitems_compare);
+
+ //extract absolute sample counts
+ const pmt::pmt_t &tag0 = _tags.front();
+ const uint64_t tag0_count = gr_tags::get_nitems(tag0);
+ const uint64_t samp0_count = nitems_read(0);
+
+ //only transmit nsamples from 0 to the first tag
+ //this ensures that the next work starts on a tag
+ if (samp0_count != tag0_count){
+ ninput_items = tag0_count - samp0_count;
+ return;
+ }
+
+ //time will not be set unless a time tag is found
+ _metadata.has_time_spec = false;
+
+ //process all of the tags found with the same count as tag0
+ BOOST_FOREACH(const pmt::pmt_t &my_tag, _tags){
+ const uint64_t my_tag_count = gr_tags::get_nitems(my_tag);
+
+ //determine how many samples to send...
+ //from zero until the next tag or end of work
+ if (my_tag_count != tag0_count){
+ ninput_items = my_tag_count - samp0_count;
+ break;
+ }
+
+ //handle end of burst with a mini end of burst packet
+ else if (pmt::pmt_equal(gr_tags::get_key(my_tag), EOB_KEY)){
+ _metadata.end_of_burst = pmt::pmt_to_bool(my_tag);
+ ninput_items = 1;
+ return;
+ }
+
+ //set the start of burst flag in the metadata
+ else if (pmt::pmt_equal(gr_tags::get_key(my_tag), SOB_KEY)){
+ _metadata.start_of_burst = pmt::pmt_to_bool(my_tag);
+ }
+
+ //set the time specification in the metadata
+ else if (pmt::pmt_equal(gr_tags::get_key(my_tag), TIME_KEY)){
+ _metadata.has_time_spec = true;
+ _metadata.time_spec = uhd::time_spec_t(
+ pmt::pmt_to_uint64(pmt_tuple_ref(my_tag, 0)),
+ pmt::pmt_to_double(pmt_tuple_ref(my_tag, 1))
+ );
+ }
+ }
+ }
+
//Send an empty start-of-burst packet to begin streaming.
//Set at a time in the near future to avoid late packets.
bool start(void){
_metadata.start_of_burst = true;
_metadata.end_of_burst = false;
- _metadata.has_time_spec = _has_time_spec;
+ _metadata.has_time_spec = _nchan > 1;
_metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01);
_dev->get_device()->send(
@@ -224,13 +289,15 @@ public:
return true;
}
-protected:
+private:
uhd::usrp::multi_usrp::sptr _dev;
const uhd::io_type_t _type;
size_t _nchan;
- bool _has_time_spec;
uhd::tx_metadata_t _metadata;
double _sample_rate;
+
+ //stream tags related stuff
+ std::vector<pmt::pmt_t> _tags;
};
/***********************************************************************
diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc
index 979d4858b..4c13db14e 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -25,6 +25,8 @@
#include <iostream>
#include <boost/format.hpp>
+static const pmt::pmt_t TIME_KEY = pmt::pmt_string_to_symbol("rx_time");
+
/***********************************************************************
* UHD Multi USRP Source Impl
**********************************************************************/
@@ -43,7 +45,11 @@ public:
_type(io_type),
_nchan(num_channels),
_stream_now(_nchan == 1),
+ _tag_now(false)
{
+ std::stringstream str;
+ str << name() << unique_id();
+ _id = pmt::pmt_string_to_symbol(str.str());
_dev = uhd::usrp::multi_usrp::make(device_addr);
}
@@ -201,7 +207,18 @@ public:
//handle possible errors conditions
switch(_metadata.error_code){
case uhd::rx_metadata_t::ERROR_CODE_NONE:
- //TODO insert tag for time stamp
+ if (_tag_now){
+ _tag_now = false;
+ //create a timestamp pmt for the first sample
+ const pmt::pmt_t val = pmt::pmt_make_tuple(
+ pmt::pmt_from_uint64(_metadata.time_spec.get_full_secs()),
+ pmt::pmt_from_double(_metadata.time_spec.get_frac_secs())
+ );
+ //create a timestamp tag for each channel
+ for (size_t i = 0; i < _nchan; i++){
+ this->add_item_tag(i, nitems_written(0), TIME_KEY, val, _id);
+ }
+ }
break;
case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
@@ -210,6 +227,7 @@ public:
return WORK_DONE;
case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW:
+ _tag_now = true;
//ignore overflows and try work again
//TODO insert tag for overflow
return work(noutput_items, input_items, output_items);
@@ -231,6 +249,7 @@ public:
stream_cmd.stream_now = _stream_now;
stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
_dev->issue_stream_cmd(stream_cmd);
+ _tag_now = true;
return true;
}
@@ -243,8 +262,9 @@ private:
uhd::usrp::multi_usrp::sptr _dev;
const uhd::io_type_t _type;
size_t _nchan;
- bool _stream_now;
+ bool _stream_now, _tag_now;
uhd::rx_metadata_t _metadata;
+ pmt::pmt_t _id;
};