aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-07 10:57:06 -0700
committerJosh Blum <josh@joshknows.com>2010-07-07 10:57:06 -0700
commitc36a671dc8b6f89789e92ab93c677156c3bdc190 (patch)
treea1c6689e73694367645a20f7c8c7c5919a4f36d6
parent5c2cccfe8c4a9c6c912a4d18dc1e7a6f84c79609 (diff)
downloaduhd-c36a671dc8b6f89789e92ab93c677156c3bdc190.tar.gz
uhd-c36a671dc8b6f89789e92ab93c677156c3bdc190.tar.bz2
uhd-c36a671dc8b6f89789e92ab93c677156c3bdc190.zip
usrp: moved stream cmd word calculation into common dsp utils
-rw-r--r--host/lib/usrp/dsp_utils.hpp38
-rw-r--r--host/lib/usrp/usrp2/dsp_impl.cpp1
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp26
3 files changed, 41 insertions, 24 deletions
diff --git a/host/lib/usrp/dsp_utils.hpp b/host/lib/usrp/dsp_utils.hpp
index e0ec46184..3fd5f1811 100644
--- a/host/lib/usrp/dsp_utils.hpp
+++ b/host/lib/usrp/dsp_utils.hpp
@@ -19,8 +19,12 @@
#define INCLUDED_LIBUHD_USRP_DSP_UTILS_HPP
#include <uhd/config.hpp>
+#include <uhd/types/dict.hpp>
#include <uhd/utils/assert.hpp>
+#include <uhd/types/stream_cmd.hpp>
#include <boost/cstdint.hpp>
+#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
#include <boost/math/special_functions/round.hpp>
namespace uhd{ namespace usrp{
@@ -142,6 +146,40 @@ namespace dsp_type1{
return calc_iq_scale_word(scale, scale);
}
+ /*!
+ * Calculate the stream command word from the stream command struct.
+ * \param stream_cmd the requested stream command with mode, flags, timestamp
+ * \param num_samps_continuous number of samples to request in continuous mode
+ * \return the 32-bit stream command word
+ */
+ static inline boost::uint32_t calc_stream_cmd_word(
+ const stream_cmd_t &stream_cmd, size_t num_samps_continuous
+ ){
+ UHD_ASSERT_THROW(stream_cmd.num_samps <= 0x3fffffff);
+
+ //setup the mode to instruction flags
+ typedef boost::tuple<bool, bool, bool> inst_t;
+ static const uhd::dict<stream_cmd_t::stream_mode_t, inst_t> mode_to_inst = boost::assign::map_list_of
+ //reload, chain, samps
+ (stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false))
+ (stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false))
+ (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true))
+ (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true))
+ ;
+
+ //setup the instruction flag values
+ bool inst_reload, inst_chain, inst_samps;
+ boost::tie(inst_reload, inst_chain, inst_samps) = mode_to_inst[stream_cmd.stream_mode];
+
+ //calculate the word from flags and length
+ boost::uint32_t word = 0;
+ word |= boost::uint32_t((stream_cmd.stream_now)? 1 : 0) << 31;
+ word |= boost::uint32_t((inst_chain)? 1 : 0) << 30;
+ word |= boost::uint32_t((inst_reload)? 1 : 0) << 29;
+ word |= (inst_samps)? stream_cmd.num_samps : ((inst_chain)? num_samps_continuous : 1);
+ return word;
+ }
+
} //namespace dsp_type1
}} //namespace
diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp
index c315a2eec..7d9cdc441 100644
--- a/host/lib/usrp/usrp2/dsp_impl.cpp
+++ b/host/lib/usrp/usrp2/dsp_impl.cpp
@@ -20,7 +20,6 @@
#include "../dsp_utils.hpp"
#include <uhd/usrp/dsp_props.hpp>
#include <boost/bind.hpp>
-#include <boost/assign/list_of.hpp>
using namespace uhd;
using namespace uhd::usrp;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 952954286..b46832360 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -17,6 +17,7 @@
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
+#include "../dsp_utils.hpp"
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/utils/algorithm.hpp>
@@ -24,7 +25,6 @@
#include <uhd/types/dict.hpp>
#include <boost/bind.hpp>
#include <boost/asio/ip/address_v4.hpp>
-#include <boost/assign/list_of.hpp>
#include <iostream>
using namespace uhd;
@@ -151,28 +151,8 @@ void usrp2_mboard_impl::set_time_spec(const time_spec_t &time_spec, bool now){
}
void usrp2_mboard_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd){
- UHD_ASSERT_THROW(stream_cmd.num_samps <= U2_REG_RX_CTRL_MAX_SAMPS_PER_CMD);
-
- //setup the mode to instruction flags
- typedef boost::tuple<bool, bool, bool> inst_t;
- static const uhd::dict<stream_cmd_t::stream_mode_t, inst_t> mode_to_inst = boost::assign::map_list_of
- //reload, chain, samps
- (stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false))
- (stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false))
- (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true))
- (stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true))
- ;
-
- //setup the instruction flag values
- bool inst_reload, inst_chain, inst_samps;
- boost::tie(inst_reload, inst_chain, inst_samps) = mode_to_inst[stream_cmd.stream_mode];
-
- //issue the stream command
- _iface->poke32(U2_REG_RX_CTRL_STREAM_CMD, U2_REG_RX_CTRL_MAKE_CMD(
- (inst_samps)? stream_cmd.num_samps : ((inst_chain)? _io_helper.get_max_recv_samps_per_packet() : 1),
- (stream_cmd.stream_now)? 1 : 0,
- (inst_chain)? 1 : 0,
- (inst_reload)? 1 : 0
+ _iface->poke32(U2_REG_RX_CTRL_STREAM_CMD, dsp_type1::calc_stream_cmd_word(
+ stream_cmd, _io_helper.get_max_recv_samps_per_packet()
));
_iface->poke32(U2_REG_RX_CTRL_TIME_SECS, boost::uint32_t(stream_cmd.time_spec.get_full_secs()));
_iface->poke32(U2_REG_RX_CTRL_TIME_TICKS, stream_cmd.time_spec.get_tick_count(get_master_clock_freq()));