From c36a671dc8b6f89789e92ab93c677156c3bdc190 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 7 Jul 2010 10:57:06 -0700 Subject: usrp: moved stream cmd word calculation into common dsp utils --- host/lib/usrp/dsp_utils.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'host/lib/usrp/dsp_utils.hpp') 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 +#include #include +#include #include +#include +#include #include 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 inst_t; + static const uhd::dict 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 -- cgit v1.2.3