2010-02-24 00:27:49 +00:00
|
|
|
//
|
2012-02-02 23:15:54 +00:00
|
|
|
// Copyright 2010-2012 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2010-02-24 00:27:49 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2010-02-24 00:27:49 +00:00
|
|
|
//
|
|
|
|
|
|
2011-06-13 02:54:09 +00:00
|
|
|
#include "../../transport/super_recv_packet_handler.hpp"
|
|
|
|
|
#include "../../transport/super_send_packet_handler.hpp"
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include "fw_common.h"
|
2010-02-24 00:27:49 +00:00
|
|
|
#include "usrp2_impl.hpp"
|
2010-04-28 23:35:22 +00:00
|
|
|
#include "usrp2_regs.hpp"
|
2011-02-25 00:35:29 +00:00
|
|
|
#include <uhd/exception.hpp>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <uhd/transport/bounded_buffer.hpp>
|
2010-10-09 00:41:19 +00:00
|
|
|
#include <uhd/utils/byteswap.hpp>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <uhd/utils/log.hpp>
|
|
|
|
|
#include <uhd/utils/tasks.hpp>
|
2017-04-18 23:46:44 +00:00
|
|
|
#include <uhd/utils/thread.hpp>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <uhdlib/usrp/common/async_packet_handler.hpp>
|
|
|
|
|
#include <uhdlib/usrp/common/validate_subdev_spec.hpp>
|
2012-02-25 00:56:31 +00:00
|
|
|
#include <boost/asio.hpp>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <boost/format.hpp>
|
2011-06-13 02:54:09 +00:00
|
|
|
#include <boost/thread/mutex.hpp>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <boost/thread/thread.hpp>
|
2018-04-26 16:30:48 +00:00
|
|
|
#include <chrono>
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
#include <functional>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <memory>
|
2018-04-26 16:30:48 +00:00
|
|
|
#include <thread>
|
2010-02-24 00:27:49 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
using namespace uhd::usrp;
|
2010-03-03 09:19:00 +00:00
|
|
|
using namespace uhd::transport;
|
2010-03-01 19:50:14 +00:00
|
|
|
namespace asio = boost::asio;
|
2020-03-02 23:25:13 +00:00
|
|
|
namespace pt = boost::posix_time;
|
2011-02-10 03:56:45 +00:00
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* helpers
|
|
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
static UHD_INLINE pt::time_duration to_time_dur(double timeout)
|
|
|
|
|
{
|
|
|
|
|
return pt::microseconds(long(timeout * 1e6));
|
2011-02-10 03:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-11 23:31:51 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* constants
|
|
|
|
|
**********************************************************************/
|
2010-10-09 00:41:19 +00:00
|
|
|
static const size_t vrt_send_header_offset_words32 = 1;
|
2010-07-26 22:31:03 +00:00
|
|
|
|
2010-10-11 23:31:51 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* flow control monitor for a single tx channel
|
|
|
|
|
* - the pirate thread calls update
|
|
|
|
|
* - the get send buffer calls check
|
|
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
class flow_control_monitor
|
|
|
|
|
{
|
2010-10-11 23:31:51 +00:00
|
|
|
public:
|
2016-10-31 21:30:52 +00:00
|
|
|
typedef uint32_t seq_type;
|
2019-09-28 09:18:57 +00:00
|
|
|
typedef std::shared_ptr<flow_control_monitor> sptr;
|
2010-10-11 23:31:51 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Make a new flow control monitor.
|
|
|
|
|
* \param max_seqs_out num seqs before throttling
|
|
|
|
|
*/
|
2020-03-02 23:25:13 +00:00
|
|
|
flow_control_monitor(seq_type max_seqs_out) : _max_seqs_out(max_seqs_out)
|
|
|
|
|
{
|
2011-12-05 21:04:23 +00:00
|
|
|
this->clear();
|
uhd: Replace all occurrences of boost::bind with std::bind
Note: Replacing everything with a lambda would be even better, but that
can't be easily scripted so we'll do this as a first step to reduce the
Boost footprint.
This also removes occurences of #include <boost/bind.hpp>, and makes
sure all usages of std::bind have an #include <functional>. clang-format
wasn't always applied to minimize the changeset in this commit, however,
it was applied to the blocks of #includes.
Due to conflicts with other Boost libraries, the placeholders _1, _2,
etc. could not be directly used, but had to be explicitly called out
(as std::placeholders::_1, etc.). This makes the use of std::bind even
uglier, which serves as another reminder that using std::bind (and even
more so, boost::bind) should be avoided.
nirio/rpc/rpc_client.cpp still contains a reference to boost::bind. It
was not possible to remove it by simply doing a search and replace, so
it will be removed in a separate commit.
2019-10-16 23:21:19 +00:00
|
|
|
_ready_fcn = std::bind(&flow_control_monitor::ready, this);
|
2011-12-05 21:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Clear the monitor, Ex: when a streamer is created
|
2020-03-02 23:25:13 +00:00
|
|
|
void clear(void)
|
|
|
|
|
{
|
2010-10-11 23:31:51 +00:00
|
|
|
_last_seq_out = 0;
|
|
|
|
|
_last_seq_ack = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-13 02:54:09 +00:00
|
|
|
/*!
|
|
|
|
|
* Gets the current sequence number to go out.
|
|
|
|
|
* Increments the sequence for the next call
|
|
|
|
|
* \return the sequence to be sent to the dsp
|
|
|
|
|
*/
|
2020-03-02 23:25:13 +00:00
|
|
|
UHD_INLINE seq_type get_curr_seq_out(void)
|
|
|
|
|
{
|
2011-06-13 02:54:09 +00:00
|
|
|
return _last_seq_out++;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 23:31:51 +00:00
|
|
|
/*!
|
|
|
|
|
* Check the flow control condition.
|
|
|
|
|
* \param timeout the timeout in seconds
|
|
|
|
|
* \return false on timeout
|
|
|
|
|
*/
|
2020-03-02 23:25:13 +00:00
|
|
|
UHD_INLINE bool check_fc_condition(double timeout)
|
|
|
|
|
{
|
uhd: Replace Boost mutexes and locks with standard options
This is a very mechanical task that could almost have been done with
sed. Boost versions of mutexes and locks were removed, and replaced with
std:: versions. The replacement tables are as follows:
== Mutexes ==
- boost::mutex -> std::mutex
- boost::recursive_mutex -> std::recursive_mutex
Mutexes behave identically between Boost and std:: and have the same
API.
== Locks ==
C++11 has only two types of lock that we use/need in UHD:
- std::lock_guard: Identical to boost::lock_guard
- std::unique_lock: Identical to boost::unique_lock
Boost also has boost::mutex::scoped_lock, which is a typedef for
boost::unique_lock<>. However, we often have used scoped_lock where we
meant to use lock_guard<>. The name is a bit misleading, "scoped lock"
sounding a bit like an RAII mechanism. Therefore, some previous
boost::mutex::scoped_lock are now std::lock_guard<>.
std::unique_lock is required when doing more than RAII locking (i.e.,
unlocking, relocking, usage with condition variables, etc.).
== Condition Variables ==
Condition variables were out of the scope of this lock/mutex change, but
in UHD, we inconsistently use boost::condition vs.
boost::condition_variable. The former is a templated version of the
latter, and thus works fine with std::mutex'es. Therefore, some
boost::condition_variable where changed to boost::condition.
All locks and mutexes use `#include <mutex>`. The corresponding Boost
includes were removed. In some cases, this exposed issues with implicit
Boost includes elsewhere. The missing explicit includes were added.
2021-07-06 14:51:55 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_fc_mutex);
|
2020-03-02 23:25:13 +00:00
|
|
|
if (this->ready())
|
|
|
|
|
return true;
|
|
|
|
|
boost::this_thread::disable_interruption di; // disable because the wait can throw
|
2011-02-10 03:56:45 +00:00
|
|
|
return _fc_cond.timed_wait(lock, to_time_dur(timeout), _ready_fcn);
|
2010-10-11 23:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Update the flow control condition.
|
|
|
|
|
* \param seq the last sequence number to be ACK'd
|
|
|
|
|
*/
|
2020-03-02 23:25:13 +00:00
|
|
|
UHD_INLINE void update_fc_condition(seq_type seq)
|
|
|
|
|
{
|
uhd: Replace Boost mutexes and locks with standard options
This is a very mechanical task that could almost have been done with
sed. Boost versions of mutexes and locks were removed, and replaced with
std:: versions. The replacement tables are as follows:
== Mutexes ==
- boost::mutex -> std::mutex
- boost::recursive_mutex -> std::recursive_mutex
Mutexes behave identically between Boost and std:: and have the same
API.
== Locks ==
C++11 has only two types of lock that we use/need in UHD:
- std::lock_guard: Identical to boost::lock_guard
- std::unique_lock: Identical to boost::unique_lock
Boost also has boost::mutex::scoped_lock, which is a typedef for
boost::unique_lock<>. However, we often have used scoped_lock where we
meant to use lock_guard<>. The name is a bit misleading, "scoped lock"
sounding a bit like an RAII mechanism. Therefore, some previous
boost::mutex::scoped_lock are now std::lock_guard<>.
std::unique_lock is required when doing more than RAII locking (i.e.,
unlocking, relocking, usage with condition variables, etc.).
== Condition Variables ==
Condition variables were out of the scope of this lock/mutex change, but
in UHD, we inconsistently use boost::condition vs.
boost::condition_variable. The former is a templated version of the
latter, and thus works fine with std::mutex'es. Therefore, some
boost::condition_variable where changed to boost::condition.
All locks and mutexes use `#include <mutex>`. The corresponding Boost
includes were removed. In some cases, this exposed issues with implicit
Boost includes elsewhere. The missing explicit includes were added.
2021-07-06 14:51:55 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_fc_mutex);
|
2010-10-11 23:31:51 +00:00
|
|
|
_last_seq_ack = seq;
|
|
|
|
|
lock.unlock();
|
|
|
|
|
_fc_cond.notify_one();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2020-03-02 23:25:13 +00:00
|
|
|
bool ready(void)
|
|
|
|
|
{
|
|
|
|
|
return seq_type(_last_seq_out - _last_seq_ack) < _max_seqs_out;
|
2010-10-11 23:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
uhd: Replace Boost mutexes and locks with standard options
This is a very mechanical task that could almost have been done with
sed. Boost versions of mutexes and locks were removed, and replaced with
std:: versions. The replacement tables are as follows:
== Mutexes ==
- boost::mutex -> std::mutex
- boost::recursive_mutex -> std::recursive_mutex
Mutexes behave identically between Boost and std:: and have the same
API.
== Locks ==
C++11 has only two types of lock that we use/need in UHD:
- std::lock_guard: Identical to boost::lock_guard
- std::unique_lock: Identical to boost::unique_lock
Boost also has boost::mutex::scoped_lock, which is a typedef for
boost::unique_lock<>. However, we often have used scoped_lock where we
meant to use lock_guard<>. The name is a bit misleading, "scoped lock"
sounding a bit like an RAII mechanism. Therefore, some previous
boost::mutex::scoped_lock are now std::lock_guard<>.
std::unique_lock is required when doing more than RAII locking (i.e.,
unlocking, relocking, usage with condition variables, etc.).
== Condition Variables ==
Condition variables were out of the scope of this lock/mutex change, but
in UHD, we inconsistently use boost::condition vs.
boost::condition_variable. The former is a templated version of the
latter, and thus works fine with std::mutex'es. Therefore, some
boost::condition_variable where changed to boost::condition.
All locks and mutexes use `#include <mutex>`. The corresponding Boost
includes were removed. In some cases, this exposed issues with implicit
Boost includes elsewhere. The missing explicit includes were added.
2021-07-06 14:51:55 +00:00
|
|
|
std::mutex _fc_mutex;
|
2010-10-11 23:31:51 +00:00
|
|
|
boost::condition _fc_cond;
|
2011-12-05 21:04:23 +00:00
|
|
|
seq_type _last_seq_out, _last_seq_ack;
|
|
|
|
|
const seq_type _max_seqs_out;
|
2019-09-28 10:54:27 +00:00
|
|
|
std::function<bool(void)> _ready_fcn;
|
2010-10-11 23:31:51 +00:00
|
|
|
};
|
2010-07-26 22:31:03 +00:00
|
|
|
|
2010-06-02 00:51:26 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* io impl details (internal to this file)
|
2010-07-01 22:38:06 +00:00
|
|
|
* - pirate crew
|
|
|
|
|
* - alignment buffer
|
|
|
|
|
* - thread loop
|
|
|
|
|
* - vrt packet handler states
|
2010-06-02 00:51:26 +00:00
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
struct usrp2_impl::io_impl
|
|
|
|
|
{
|
|
|
|
|
io_impl(void)
|
|
|
|
|
: async_msg_fifo(1000 /*messages deep*/), tick_rate(1 /*non-zero default*/)
|
2010-07-01 22:38:06 +00:00
|
|
|
{
|
2011-06-29 21:00:22 +00:00
|
|
|
/* NOP */
|
2010-07-01 22:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
~io_impl(void)
|
|
|
|
|
{
|
|
|
|
|
// Manually deconstuct the tasks, since this was not happening automatically.
|
2011-08-25 22:26:57 +00:00
|
|
|
pirate_tasks.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
managed_send_buffer::sptr get_send_buff(size_t chan, double timeout)
|
|
|
|
|
{
|
|
|
|
|
flow_control_monitor& fc_mon = *fc_mons[chan];
|
2010-10-09 00:41:19 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// wait on flow control w/ timeout
|
|
|
|
|
if (not fc_mon.check_fc_condition(timeout))
|
|
|
|
|
return managed_send_buffer::sptr();
|
2010-10-09 00:41:19 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// get a buffer from the transport w/ timeout
|
2011-06-29 21:00:22 +00:00
|
|
|
managed_send_buffer::sptr buff = tx_xports[chan]->get_send_buff(timeout);
|
2011-06-13 02:54:09 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// write the flow control word into the buffer
|
|
|
|
|
if (buff.get())
|
|
|
|
|
buff->cast<uint32_t*>()[0] = uhd::htonx(fc_mon.get_curr_seq_out());
|
2010-10-09 00:41:19 +00:00
|
|
|
|
2011-06-13 02:54:09 +00:00
|
|
|
return buff;
|
|
|
|
|
}
|
2010-12-16 22:38:06 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// tx dsp: xports and flow control monitors
|
2011-06-29 21:00:22 +00:00
|
|
|
std::vector<zero_copy_if::sptr> tx_xports;
|
2010-10-11 23:31:51 +00:00
|
|
|
std::vector<flow_control_monitor::sptr> fc_mons;
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// methods and variables for the pirate crew
|
|
|
|
|
void recv_pirate_loop(zero_copy_if::sptr, size_t, const std::atomic<bool>&);
|
2011-07-14 00:25:40 +00:00
|
|
|
std::list<task::sptr> pirate_tasks;
|
2011-02-05 20:37:20 +00:00
|
|
|
bounded_buffer<async_metadata_t> async_msg_fifo;
|
2011-06-29 21:00:22 +00:00
|
|
|
double tick_rate;
|
2010-06-02 00:51:26 +00:00
|
|
|
};
|
|
|
|
|
|
2010-07-01 22:38:06 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Receive Pirate Loop
|
2010-12-16 22:38:06 +00:00
|
|
|
* - while raiding, loot for message packet
|
|
|
|
|
* - update flow control condition count
|
|
|
|
|
* - put async message packets into queue
|
2010-07-01 22:38:06 +00:00
|
|
|
**********************************************************************/
|
|
|
|
|
void usrp2_impl::io_impl::recv_pirate_loop(
|
2020-03-02 23:25:13 +00:00
|
|
|
zero_copy_if::sptr err_xport, size_t index, const std::atomic<bool>& exit_loop)
|
|
|
|
|
{
|
2010-06-17 01:40:44 +00:00
|
|
|
set_thread_priority_safe();
|
2010-07-10 06:24:41 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// store a reference to the flow control monitor (offset by max dsps)
|
|
|
|
|
flow_control_monitor& fc_mon = *(this->fc_mons[index]);
|
2011-02-22 22:53:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
while (not exit_loop) {
|
2011-02-21 03:57:04 +00:00
|
|
|
managed_recv_buffer::sptr buff = err_xport->get_recv_buff();
|
2020-03-02 23:25:13 +00:00
|
|
|
if (not buff.get())
|
|
|
|
|
continue; // ignore timeout/error buffers
|
2010-07-01 22:38:06 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
try {
|
|
|
|
|
// extract the vrt header packet info
|
2010-07-01 22:38:06 +00:00
|
|
|
vrt::if_packet_info_t if_packet_info;
|
2020-03-02 23:25:13 +00:00
|
|
|
if_packet_info.num_packet_words32 = buff->size() / sizeof(uint32_t);
|
|
|
|
|
const uint32_t* vrt_hdr = buff->cast<const uint32_t*>();
|
2010-07-21 01:51:36 +00:00
|
|
|
vrt::if_hdr_unpack_be(vrt_hdr, if_packet_info);
|
2010-07-01 22:38:06 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// handle a tx async report message
|
|
|
|
|
if (if_packet_info.sid == USRP2_TX_ASYNC_SID
|
|
|
|
|
and if_packet_info.packet_type
|
|
|
|
|
!= vrt::if_packet_info_t::PACKET_TYPE_DATA) {
|
|
|
|
|
// fill in the async metadata
|
2010-07-21 01:51:36 +00:00
|
|
|
async_metadata_t metadata;
|
2020-03-02 23:25:13 +00:00
|
|
|
load_metadata_from_buff(uhd::ntohx<uint32_t>,
|
|
|
|
|
metadata,
|
|
|
|
|
if_packet_info,
|
|
|
|
|
vrt_hdr,
|
|
|
|
|
tick_rate,
|
|
|
|
|
index);
|
|
|
|
|
|
|
|
|
|
// catch the flow control packets and react
|
|
|
|
|
if (metadata.event_code == 0) {
|
2016-10-31 21:30:52 +00:00
|
|
|
uint32_t fc_word32 = (vrt_hdr + if_packet_info.num_header_words32)[1];
|
2011-02-22 22:53:47 +00:00
|
|
|
fc_mon.update_fc_condition(uhd::ntohx(fc_word32));
|
2010-10-11 23:31:51 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
// else UHD_LOGGER_DEBUG("USRP2") << "metadata.event_code " <<
|
|
|
|
|
// metadata.event_code;
|
2011-02-05 20:37:20 +00:00
|
|
|
async_msg_fifo.push_with_pop_on_full(metadata);
|
2011-07-01 21:03:04 +00:00
|
|
|
|
2012-02-15 02:26:03 +00:00
|
|
|
standard_async_msg_prints(metadata);
|
2020-03-02 23:25:13 +00:00
|
|
|
} else {
|
|
|
|
|
// TODO unknown received packet, may want to print error...
|
2010-07-20 01:56:33 +00:00
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
UHD_LOGGER_ERROR("USRP2") << "Error in recv pirate loop: " << e.what();
|
2010-07-01 22:38:06 +00:00
|
|
|
}
|
2010-06-02 00:51:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-24 00:27:49 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Helper Functions
|
|
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::io_init(void)
|
|
|
|
|
{
|
|
|
|
|
// create new io impl
|
2011-06-29 21:00:22 +00:00
|
|
|
_io_impl = UHD_PIMPL_MAKE(io_impl, ());
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// init first so we dont have an access race
|
|
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
|
|
|
|
// init the tx xport and flow control monitor
|
2011-07-18 06:54:19 +00:00
|
|
|
_io_impl->tx_xports.push_back(_mbc[mb].tx_dsp_xport);
|
2020-03-02 23:25:13 +00:00
|
|
|
_io_impl->fc_mons.push_back(flow_control_monitor::sptr(
|
|
|
|
|
new flow_control_monitor(device_addr.cast("send_buff_size", USRP2_SRAM_BYTES)
|
|
|
|
|
/ _mbc[mb].tx_dsp_xport->get_send_frame_size())));
|
2011-06-29 21:00:22 +00:00
|
|
|
}
|
2010-07-01 22:38:06 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// allocate streamer weak ptrs containers
|
|
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
2011-10-05 01:08:47 +00:00
|
|
|
_mbc[mb].rx_streamers.resize(_mbc[mb].rx_dsps.size());
|
2020-03-02 23:25:13 +00:00
|
|
|
_mbc[mb].tx_streamers.resize(1 /*known to be 1 dsp*/);
|
2011-10-05 01:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// create a new pirate thread for each zc if (yarr!!)
|
2011-06-29 21:00:22 +00:00
|
|
|
size_t index = 0;
|
2020-03-02 23:25:13 +00:00
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
|
|
|
|
// spawn a new pirate to plunder the recv booty
|
|
|
|
|
_io_impl->pirate_tasks.push_back(
|
|
|
|
|
task::make(std::bind(&usrp2_impl::io_impl::recv_pirate_loop,
|
|
|
|
|
_io_impl.get(),
|
|
|
|
|
_mbc[mb].tx_dsp_xport,
|
|
|
|
|
index++,
|
|
|
|
|
std::ref(_pirate_task_exit))));
|
2010-07-01 22:38:06 +00:00
|
|
|
}
|
2011-02-19 18:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_tick_rate(const double rate)
|
|
|
|
|
{
|
|
|
|
|
_io_impl->tick_rate = rate; // shadow for async msg
|
2011-10-05 01:08:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// update the tick rate on all existing streamers -> thread safe
|
|
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
|
|
|
|
for (size_t i = 0; i < _mbc[mb].rx_streamers.size(); i++) {
|
2019-09-28 09:18:57 +00:00
|
|
|
std::shared_ptr<sph::recv_packet_streamer> my_streamer =
|
2020-03-02 23:25:13 +00:00
|
|
|
std::dynamic_pointer_cast<sph::recv_packet_streamer>(
|
|
|
|
|
_mbc[mb].rx_streamers[i].lock());
|
|
|
|
|
if (my_streamer.get() == NULL)
|
|
|
|
|
continue;
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_tick_rate(rate);
|
|
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
for (size_t i = 0; i < _mbc[mb].tx_streamers.size(); i++) {
|
2019-09-28 09:18:57 +00:00
|
|
|
std::shared_ptr<sph::send_packet_streamer> my_streamer =
|
2020-03-02 23:25:13 +00:00
|
|
|
std::dynamic_pointer_cast<sph::send_packet_streamer>(
|
|
|
|
|
_mbc[mb].tx_streamers[i].lock());
|
|
|
|
|
if (my_streamer.get() == NULL)
|
|
|
|
|
continue;
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_tick_rate(rate);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-29 21:00:22 +00:00
|
|
|
}
|
2011-02-19 18:30:50 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_rx_samp_rate(
|
|
|
|
|
const std::string& mb, const size_t dsp, const double rate)
|
|
|
|
|
{
|
2019-09-28 09:18:57 +00:00
|
|
|
std::shared_ptr<sph::recv_packet_streamer> my_streamer =
|
2020-03-02 23:25:13 +00:00
|
|
|
std::dynamic_pointer_cast<sph::recv_packet_streamer>(
|
|
|
|
|
_mbc[mb].rx_streamers[dsp].lock());
|
|
|
|
|
if (my_streamer.get() == NULL)
|
|
|
|
|
return;
|
2011-10-05 01:08:47 +00:00
|
|
|
|
|
|
|
|
my_streamer->set_samp_rate(rate);
|
|
|
|
|
const double adj = _mbc[mb].rx_dsps[dsp]->get_scaling_adjustment();
|
2011-10-08 00:30:42 +00:00
|
|
|
my_streamer->set_scale_factor(adj);
|
2011-06-29 21:00:22 +00:00
|
|
|
}
|
2011-02-21 03:57:04 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_tx_samp_rate(
|
|
|
|
|
const std::string& mb, const size_t dsp, const double rate)
|
|
|
|
|
{
|
2019-09-28 09:18:57 +00:00
|
|
|
std::shared_ptr<sph::send_packet_streamer> my_streamer =
|
2020-03-02 23:25:13 +00:00
|
|
|
std::dynamic_pointer_cast<sph::send_packet_streamer>(
|
|
|
|
|
_mbc[mb].tx_streamers[dsp].lock());
|
|
|
|
|
if (my_streamer.get() == NULL)
|
|
|
|
|
return;
|
2011-10-05 01:08:47 +00:00
|
|
|
|
|
|
|
|
my_streamer->set_samp_rate(rate);
|
2012-01-29 00:08:17 +00:00
|
|
|
const double adj = _mbc[mb].tx_dsp->get_scaling_adjustment();
|
|
|
|
|
my_streamer->set_scale_factor(adj);
|
2011-06-29 21:00:22 +00:00
|
|
|
}
|
2011-02-19 18:30:50 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_rates(void)
|
|
|
|
|
{
|
|
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
2011-10-05 01:08:47 +00:00
|
|
|
fs_path root = "/mboards/" + mb;
|
|
|
|
|
_tree->access<double>(root / "tick_rate").update();
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// and now that the tick rate is set, init the host rates to something
|
|
|
|
|
for (const std::string& name : _tree->list(root / "rx_dsps")) {
|
2011-10-05 01:08:47 +00:00
|
|
|
_tree->access<double>(root / "rx_dsps" / name / "rate" / "value").update();
|
|
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
for (const std::string& name : _tree->list(root / "tx_dsps")) {
|
2011-10-05 01:08:47 +00:00
|
|
|
_tree->access<double>(root / "tx_dsps" / name / "rate" / "value").update();
|
2011-07-03 19:22:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_rx_subdev_spec(
|
|
|
|
|
const std::string& which_mb, const subdev_spec_t& spec)
|
|
|
|
|
{
|
2011-07-22 08:19:03 +00:00
|
|
|
fs_path root = "/mboards/" + which_mb + "/dboards";
|
2011-02-19 18:30:50 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// sanity checking
|
2011-07-01 22:07:38 +00:00
|
|
|
validate_subdev_spec(_tree, spec, "rx", which_mb);
|
2011-02-19 18:30:50 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// setup mux for this spec
|
2011-07-04 14:21:53 +00:00
|
|
|
bool fe_swapped = false;
|
2020-03-02 23:25:13 +00:00
|
|
|
for (size_t i = 0; i < spec.size(); i++) {
|
|
|
|
|
const std::string conn =
|
|
|
|
|
_tree
|
|
|
|
|
->access<std::string>(root / spec[i].db_name / "rx_frontends"
|
|
|
|
|
/ spec[i].sd_name / "connection")
|
|
|
|
|
.get();
|
|
|
|
|
if (i == 0 and (conn == "QI" or conn == "Q"))
|
|
|
|
|
fe_swapped = true;
|
2011-07-04 14:21:53 +00:00
|
|
|
_mbc[which_mb].rx_dsps[i]->set_mux(conn, fe_swapped);
|
2011-02-19 18:30:50 +00:00
|
|
|
}
|
2011-07-04 14:21:53 +00:00
|
|
|
_mbc[which_mb].rx_fe->set_mux(fe_swapped);
|
2011-02-21 03:57:04 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// compute the new occupancy and resize
|
2011-06-29 21:00:22 +00:00
|
|
|
_mbc[which_mb].rx_chan_occ = spec.size();
|
|
|
|
|
}
|
2011-06-13 02:54:09 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
void usrp2_impl::update_tx_subdev_spec(
|
|
|
|
|
const std::string& which_mb, const subdev_spec_t& spec)
|
|
|
|
|
{
|
2011-07-22 08:19:03 +00:00
|
|
|
fs_path root = "/mboards/" + which_mb + "/dboards";
|
2011-06-29 21:00:22 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// sanity checking
|
2011-07-01 22:07:38 +00:00
|
|
|
validate_subdev_spec(_tree, spec, "tx", which_mb);
|
2011-06-29 21:00:22 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// set the mux for this spec
|
|
|
|
|
const std::string conn =
|
|
|
|
|
_tree
|
|
|
|
|
->access<std::string>(
|
|
|
|
|
root / spec[0].db_name / "tx_frontends" / spec[0].sd_name / "connection")
|
|
|
|
|
.get();
|
2011-06-29 21:00:22 +00:00
|
|
|
_mbc[which_mb].tx_fe->set_mux(conn);
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// compute the new occupancy and resize
|
2011-06-29 21:00:22 +00:00
|
|
|
_mbc[which_mb].tx_chan_occ = spec.size();
|
2010-03-02 00:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-21 01:51:36 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Async Data
|
|
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
bool usrp2_impl::recv_async_msg(async_metadata_t& async_metadata, double timeout)
|
|
|
|
|
{
|
|
|
|
|
boost::this_thread::disable_interruption di; // disable because the wait can throw
|
2011-02-05 20:37:20 +00:00
|
|
|
return _io_impl->async_msg_fifo.pop_with_timed_wait(async_metadata, timeout);
|
2010-07-21 01:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-25 00:56:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Stream destination programmer
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
void usrp2_impl::program_stream_dest(
|
2020-03-02 23:25:13 +00:00
|
|
|
zero_copy_if::sptr& xport, const uhd::stream_args_t& args)
|
|
|
|
|
{
|
|
|
|
|
// perform an initial flush of transport
|
|
|
|
|
while (xport->get_recv_buff(0.0)) {
|
|
|
|
|
}
|
2012-02-25 00:56:31 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// program the stream command
|
2012-02-25 00:56:31 +00:00
|
|
|
usrp2_stream_ctrl_t stream_ctrl = usrp2_stream_ctrl_t();
|
2020-03-02 23:25:13 +00:00
|
|
|
stream_ctrl.sequence = uhd::htonx(uint32_t(0 /* don't care seq num */));
|
|
|
|
|
stream_ctrl.vrt_hdr = uhd::htonx(uint32_t(USRP2_INVALID_VRT_HEADER));
|
2012-02-25 00:56:31 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// user has provided an alternative address and port for destination
|
|
|
|
|
if (args.args.has_key("addr") and args.args.has_key("port")) {
|
|
|
|
|
UHD_LOGGER_INFO("USRP2")
|
|
|
|
|
<< boost::format("Programming streaming destination for custom address. "
|
|
|
|
|
"IPv4 Address: %s, UDP Port: %s")
|
|
|
|
|
% args.args["addr"] % args.args["port"];
|
2012-02-25 00:56:31 +00:00
|
|
|
|
2024-12-03 11:05:50 +00:00
|
|
|
asio::io_context io_context;
|
|
|
|
|
asio::ip::udp::resolver resolver(io_context);
|
|
|
|
|
asio::ip::udp::endpoint endpoint =
|
|
|
|
|
*resolver.resolve(asio::ip::udp::v4(), args.args["addr"], args.args["port"])
|
|
|
|
|
.begin();
|
|
|
|
|
stream_ctrl.ip_addr = uhd::htonx(uint32_t(endpoint.address().to_v4().to_uint()));
|
2016-10-31 21:30:52 +00:00
|
|
|
stream_ctrl.udp_port = uhd::htonx(uint32_t(endpoint.port()));
|
2012-02-25 00:56:31 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
for (size_t i = 0; i < 3; i++) {
|
2017-02-08 00:37:25 +00:00
|
|
|
UHD_LOGGER_INFO("USRP2") << "ARP attempt " << i;
|
2012-02-25 00:56:31 +00:00
|
|
|
managed_send_buffer::sptr send_buff = xport->get_send_buff();
|
2020-03-02 23:25:13 +00:00
|
|
|
std::memcpy(send_buff->cast<void*>(), &stream_ctrl, sizeof(stream_ctrl));
|
2012-02-25 00:56:31 +00:00
|
|
|
send_buff->commit(sizeof(stream_ctrl));
|
2012-08-14 20:47:48 +00:00
|
|
|
send_buff.reset();
|
2018-04-26 16:30:48 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
2012-02-25 00:56:31 +00:00
|
|
|
managed_recv_buffer::sptr recv_buff = xport->get_recv_buff(0.0);
|
2020-03-02 23:25:13 +00:00
|
|
|
if (recv_buff and recv_buff->size() >= sizeof(uint32_t)) {
|
|
|
|
|
const uint32_t result = uhd::ntohx(recv_buff->cast<const uint32_t*>()[0]);
|
|
|
|
|
if (result == 0) {
|
2017-02-08 00:37:25 +00:00
|
|
|
UHD_LOGGER_INFO("USRP2") << "Success! ";
|
2012-02-25 00:56:31 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
throw uhd::runtime_error(
|
|
|
|
|
"Device failed to ARP when programming alternative streaming destination.");
|
2012-02-25 00:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
else {
|
|
|
|
|
// send the partial stream control without destination
|
2012-02-25 00:56:31 +00:00
|
|
|
managed_send_buffer::sptr send_buff = xport->get_send_buff();
|
2020-03-02 23:25:13 +00:00
|
|
|
std::memcpy(send_buff->cast<void*>(), &stream_ctrl, sizeof(stream_ctrl));
|
|
|
|
|
send_buff->commit(sizeof(stream_ctrl) / 2);
|
2012-02-25 00:56:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-24 00:27:49 +00:00
|
|
|
/***********************************************************************
|
2011-10-05 01:08:47 +00:00
|
|
|
* Receive streamer
|
2010-02-24 00:27:49 +00:00
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
rx_streamer::sptr usrp2_impl::get_rx_stream(const uhd::stream_args_t& args_)
|
|
|
|
|
{
|
2011-10-11 03:55:01 +00:00
|
|
|
stream_args_t args = args_;
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// setup defaults for unspecified values
|
|
|
|
|
args.otw_format = args.otw_format.empty() ? "sc16" : args.otw_format;
|
|
|
|
|
args.channels = args.channels.empty() ? std::vector<size_t>(1, 0) : args.channels;
|
|
|
|
|
|
|
|
|
|
// calculate packet size
|
|
|
|
|
static const size_t hdr_size =
|
|
|
|
|
0 + vrt::max_if_hdr_words32 * sizeof(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
|
|
|
|
|
- sizeof(vrt::if_packet_info_t().tsi) // no int time ever used
|
|
|
|
|
;
|
|
|
|
|
const size_t bpp =
|
|
|
|
|
_mbc[_mbc.keys().front()].rx_dsp_xports[0]->get_recv_frame_size() - hdr_size;
|
2012-01-17 07:04:53 +00:00
|
|
|
const size_t bpi = convert::get_bytes_per_item(args.otw_format);
|
2020-03-02 23:25:13 +00:00
|
|
|
const size_t spp = args.args.cast<size_t>("spp", bpp / bpi);
|
2011-10-05 01:08:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// make the new streamer given the samples per packet
|
|
|
|
|
std::shared_ptr<sph::recv_packet_streamer> my_streamer =
|
|
|
|
|
std::make_shared<sph::recv_packet_streamer>(spp);
|
2011-10-05 01:08:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// init some streamer stuff
|
2011-10-11 03:55:01 +00:00
|
|
|
my_streamer->resize(args.channels.size());
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_vrt_unpacker(&vrt::if_hdr_unpack_be);
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// set the converter
|
2011-10-05 01:08:47 +00:00
|
|
|
uhd::convert::id_type id;
|
2020-03-02 23:25:13 +00:00
|
|
|
id.input_format = args.otw_format + "_item32_be";
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = args.cpu_format;
|
2020-03-02 23:25:13 +00:00
|
|
|
id.num_outputs = 1;
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_converter(id);
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// bind callbacks for the handler
|
|
|
|
|
for (size_t chan_i = 0; chan_i < args.channels.size(); chan_i++) {
|
|
|
|
|
const size_t chan = args.channels[chan_i];
|
2011-10-05 01:08:47 +00:00
|
|
|
size_t num_chan_so_far = 0;
|
2020-03-02 23:25:13 +00:00
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
2011-10-05 01:08:47 +00:00
|
|
|
num_chan_so_far += _mbc[mb].rx_chan_occ;
|
2020-03-02 23:25:13 +00:00
|
|
|
if (chan < num_chan_so_far) {
|
2011-11-07 23:10:19 +00:00
|
|
|
const size_t dsp = chan + _mbc[mb].rx_chan_occ - num_chan_so_far;
|
2020-03-02 23:25:13 +00:00
|
|
|
_mbc[mb].rx_dsps[dsp]->set_nsamps_per_packet(
|
|
|
|
|
spp); // seems to be a good place to set this
|
2012-01-29 00:08:17 +00:00
|
|
|
_mbc[mb].rx_dsps[dsp]->setup(args);
|
2012-02-25 00:56:31 +00:00
|
|
|
this->program_stream_dest(_mbc[mb].rx_dsp_xports[dsp], args);
|
2020-03-02 23:25:13 +00:00
|
|
|
my_streamer->set_xport_chan_get_buff(chan_i,
|
|
|
|
|
std::bind(&zero_copy_if::get_recv_buff,
|
|
|
|
|
_mbc[mb].rx_dsp_xports[dsp],
|
|
|
|
|
std::placeholders::_1),
|
|
|
|
|
true /*flush*/);
|
|
|
|
|
my_streamer->set_issue_stream_cmd(chan_i,
|
|
|
|
|
std::bind(&rx_dsp_core_200::issue_stream_command,
|
|
|
|
|
_mbc[mb].rx_dsps[dsp],
|
|
|
|
|
std::placeholders::_1));
|
|
|
|
|
_mbc[mb].rx_streamers[dsp] = my_streamer; // store weak pointer
|
2011-10-05 01:08:47 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-07 17:43:58 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// set the packet threshold to be an entire socket buffer's worth
|
|
|
|
|
const size_t packets_per_sock_buff =
|
|
|
|
|
size_t(50e6 / _mbc[_mbc.keys().front()].rx_dsp_xports[0]->get_recv_frame_size());
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_alignment_failure_threshold(packets_per_sock_buff);
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// sets all tick and samp rates on this streamer
|
2011-10-05 01:08:47 +00:00
|
|
|
this->update_rates();
|
|
|
|
|
|
|
|
|
|
return my_streamer;
|
2010-12-16 22:38:06 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-24 00:27:49 +00:00
|
|
|
/***********************************************************************
|
2011-10-05 01:08:47 +00:00
|
|
|
* Transmit streamer
|
2010-02-24 00:27:49 +00:00
|
|
|
**********************************************************************/
|
2020-03-02 23:25:13 +00:00
|
|
|
tx_streamer::sptr usrp2_impl::get_tx_stream(const uhd::stream_args_t& args_)
|
|
|
|
|
{
|
2011-10-11 03:55:01 +00:00
|
|
|
stream_args_t args = args_;
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// setup defaults for unspecified values
|
|
|
|
|
args.otw_format = args.otw_format.empty() ? "sc16" : args.otw_format;
|
|
|
|
|
args.channels = args.channels.empty() ? std::vector<size_t>(1, 0) : args.channels;
|
|
|
|
|
|
|
|
|
|
// calculate packet size
|
|
|
|
|
static const size_t hdr_size =
|
|
|
|
|
0 + vrt_send_header_offset_words32 * sizeof(uint32_t)
|
|
|
|
|
+ vrt::max_if_hdr_words32 * sizeof(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
|
|
|
|
|
- sizeof(vrt::if_packet_info_t().sid) // no stream id ever used
|
|
|
|
|
- sizeof(vrt::if_packet_info_t().tsi) // no int time ever used
|
|
|
|
|
;
|
|
|
|
|
const size_t bpp =
|
|
|
|
|
_mbc[_mbc.keys().front()].tx_dsp_xport->get_send_frame_size() - hdr_size;
|
|
|
|
|
const size_t spp = bpp / convert::get_bytes_per_item(args.otw_format);
|
|
|
|
|
|
|
|
|
|
// make the new streamer given the samples per packet
|
|
|
|
|
std::shared_ptr<sph::send_packet_streamer> my_streamer =
|
|
|
|
|
std::make_shared<sph::send_packet_streamer>(spp);
|
|
|
|
|
|
|
|
|
|
// init some streamer stuff
|
2011-10-11 03:55:01 +00:00
|
|
|
my_streamer->resize(args.channels.size());
|
2011-10-05 18:54:36 +00:00
|
|
|
my_streamer->set_vrt_packer(&vrt::if_hdr_pack_be, vrt_send_header_offset_words32);
|
2011-10-05 01:08:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// set the converter
|
2011-10-05 01:08:47 +00:00
|
|
|
uhd::convert::id_type id;
|
2020-03-02 23:25:13 +00:00
|
|
|
id.input_format = args.cpu_format;
|
|
|
|
|
id.num_inputs = 1;
|
2011-10-12 07:39:04 +00:00
|
|
|
id.output_format = args.otw_format + "_item32_be";
|
2020-03-02 23:25:13 +00:00
|
|
|
id.num_outputs = 1;
|
2011-10-05 01:08:47 +00:00
|
|
|
my_streamer->set_converter(id);
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// bind callbacks for the handler
|
|
|
|
|
for (size_t chan_i = 0; chan_i < args.channels.size(); chan_i++) {
|
|
|
|
|
const size_t chan = args.channels[chan_i];
|
2011-10-05 01:08:47 +00:00
|
|
|
size_t num_chan_so_far = 0;
|
2020-03-02 23:25:13 +00:00
|
|
|
size_t abs = 0;
|
|
|
|
|
for (const std::string& mb : _mbc.keys()) {
|
2011-10-05 01:08:47 +00:00
|
|
|
num_chan_so_far += _mbc[mb].tx_chan_occ;
|
2020-03-02 23:25:13 +00:00
|
|
|
if (chan < num_chan_so_far) {
|
2011-11-07 23:10:19 +00:00
|
|
|
const size_t dsp = chan + _mbc[mb].tx_chan_occ - num_chan_so_far;
|
2020-03-02 23:25:13 +00:00
|
|
|
if (not args.args.has_key("noclear")) {
|
2011-12-05 21:04:23 +00:00
|
|
|
_io_impl->fc_mons[abs]->clear();
|
|
|
|
|
}
|
2012-01-29 00:08:17 +00:00
|
|
|
_mbc[mb].tx_dsp->setup(args);
|
2020-03-02 23:25:13 +00:00
|
|
|
my_streamer->set_xport_chan_get_buff(chan_i,
|
|
|
|
|
std::bind(&usrp2_impl::io_impl::get_send_buff,
|
|
|
|
|
_io_impl.get(),
|
|
|
|
|
abs,
|
|
|
|
|
std::placeholders::_1));
|
|
|
|
|
my_streamer->set_async_receiver(
|
|
|
|
|
std::bind(&bounded_buffer<async_metadata_t>::pop_with_timed_wait,
|
|
|
|
|
&(_io_impl->async_msg_fifo),
|
|
|
|
|
std::placeholders::_1,
|
|
|
|
|
std::placeholders::_2));
|
|
|
|
|
_mbc[mb].tx_streamers[dsp] = my_streamer; // store weak pointer
|
2011-10-05 01:08:47 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2020-03-02 23:25:13 +00:00
|
|
|
abs += 1; // assume 1 tx dsp
|
2011-10-05 01:08:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-10-07 17:43:58 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// sets all tick and samp rates on this streamer
|
2011-10-05 01:08:47 +00:00
|
|
|
this->update_rates();
|
|
|
|
|
|
|
|
|
|
return my_streamer;
|
2010-02-24 00:27:49 +00:00
|
|
|
}
|