aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/transport/vrt_packet_handler.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/transport/vrt_packet_handler.hpp')
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp66
1 files changed, 35 insertions, 31 deletions
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index c535edd04..6f3ac0421 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -67,13 +67,16 @@ template <typename T> UHD_INLINE T get_context_code(
std::vector<const boost::uint8_t *> copy_buffs;
size_t size_of_copy_buffs;
size_t fragment_offset_in_samps;
+ std::vector<void *> io_buffs;
+ std::vector<const void *> otw_buffs;
recv_state(size_t width = 1):
width(width),
managed_buffs(width),
copy_buffs(width, NULL),
size_of_copy_buffs(0),
- fragment_offset_in_samps(0)
+ fragment_offset_in_samps(0),
+ io_buffs(0) //resized later
{
/* NOP */
}
@@ -144,7 +147,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t _recv1(
recv_state &state,
- const std::vector<void *> &buffs,
+ const uhd::device::recv_buffs_type &buffs,
size_t offset_bytes,
size_t total_samps,
uhd::rx_metadata_t &metadata,
@@ -192,17 +195,15 @@ template <typename T> UHD_INLINE T get_context_code(
size_t bytes_to_copy = nsamps_to_copy*bytes_per_item;
size_t nsamps_to_copy_per_io_buff = nsamps_to_copy/chans_per_otw_buff;
- std::vector<void *> io_buffs(chans_per_otw_buff);
- for (size_t i = 0; i < state.width; i+=chans_per_otw_buff){
+ for (size_t i = 0; i < buffs.size(); i+=chans_per_otw_buff){
//fill a vector with pointers to the io buffers
for (size_t j = 0; j < chans_per_otw_buff; j++){
- io_buffs[j] = reinterpret_cast<boost::uint8_t *>(buffs[i+j]) + offset_bytes;
+ state.io_buffs[j] = reinterpret_cast<boost::uint8_t *>(buffs[i+j]) + offset_bytes;
}
//copy-convert the samples from the recv buffer
- uhd::convert::input_type otw_buffs(1, state.copy_buffs[i]);
- converter(otw_buffs, io_buffs, nsamps_to_copy_per_io_buff);
+ converter(state.copy_buffs[i], state.io_buffs, nsamps_to_copy_per_io_buff);
//update the rx copy buffer to reflect the bytes copied
state.copy_buffs[i] += bytes_to_copy;
@@ -223,7 +224,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t recv(
recv_state &state,
- const std::vector<void *> &buffs,
+ const uhd::device::recv_buffs_type &buffs,
const size_t total_num_samps,
uhd::rx_metadata_t &metadata,
uhd::device::recv_mode_t recv_mode,
@@ -236,6 +237,8 @@ template <typename T> UHD_INLINE T get_context_code(
size_t vrt_header_offset_words32 = 0,
size_t chans_per_otw_buff = 1
){
+ state.io_buffs.resize(chans_per_otw_buff);
+
uhd::convert::function_type converter(
uhd::convert::get_converter_otw_to_cpu(
io_type, otw_type, 1, chans_per_otw_buff
@@ -300,8 +303,18 @@ template <typename T> UHD_INLINE T get_context_code(
struct send_state{
//init the expected seq number
size_t next_packet_seq;
+ managed_send_buffs_t managed_buffs;
+ const boost::uint64_t zeros;
+ std::vector<const void *> zero_buffs;
+ std::vector<const void *> io_buffs;
- send_state(void) : next_packet_seq(0){
+ send_state(size_t width = 1):
+ next_packet_seq(0),
+ managed_buffs(width),
+ zeros(0),
+ zero_buffs(width, &zeros),
+ io_buffs(0) //resized later
+ {
/* NOP */
}
};
@@ -312,7 +325,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t _send1(
send_state &state,
- const std::vector<const void *> &buffs,
+ const uhd::device::send_buffs_type &buffs,
const size_t offset_bytes,
const size_t num_samps,
uhd::transport::vrt::if_packet_info_t &if_packet_info,
@@ -326,29 +339,26 @@ template <typename T> UHD_INLINE T get_context_code(
if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*OTW_BYTES_PER_SAMP)/sizeof(boost::uint32_t);
if_packet_info.packet_count = state.next_packet_seq;
- //get send buffers for each channel
- managed_send_buffs_t send_buffs(buffs.size()/chans_per_otw_buff);
- if (not get_send_buffs(send_buffs)) return 0;
+ //get send buffers for each otw channel
+ if (not get_send_buffs(state.managed_buffs)) return 0;
- std::vector<const void *> io_buffs(chans_per_otw_buff);
for (size_t i = 0; i < buffs.size(); i+=chans_per_otw_buff){
//calculate pointers with offsets to io and otw memory
for (size_t j = 0; j < chans_per_otw_buff; j++){
- io_buffs[j] = reinterpret_cast<const boost::uint8_t *>(buffs[i+j]) + offset_bytes;
+ state.io_buffs[j] = reinterpret_cast<const boost::uint8_t *>(buffs[i+j]) + offset_bytes;
}
- boost::uint32_t *otw_mem = send_buffs[i]->cast<boost::uint32_t *>() + vrt_header_offset_words32;
+ boost::uint32_t *otw_mem = state.managed_buffs[i]->cast<boost::uint32_t *>() + vrt_header_offset_words32;
//pack metadata into a vrt header
vrt_packer(otw_mem, if_packet_info);
otw_mem += if_packet_info.num_header_words32;
//copy-convert the samples into the send buffer
- uhd::convert::output_type otw_buffs(1, otw_mem);
- converter(io_buffs, otw_buffs, num_samps);
+ converter(state.io_buffs, otw_mem, num_samps);
//commit the samples to the zero-copy interface
size_t num_bytes_total = (vrt_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t);
- send_buffs[i]->commit(num_bytes_total);
+ state.managed_buffs[i]->commit(num_bytes_total);
}
state.next_packet_seq++; //increment sequence after commits
return num_samps;
@@ -359,7 +369,7 @@ template <typename T> UHD_INLINE T get_context_code(
******************************************************************/
static UHD_INLINE size_t send(
send_state &state,
- const std::vector<const void *> &buffs,
+ const uhd::device::send_buffs_type &buffs,
const size_t total_num_samps,
const uhd::tx_metadata_t &metadata,
uhd::device::send_mode_t send_mode,
@@ -372,6 +382,8 @@ template <typename T> UHD_INLINE T get_context_code(
size_t vrt_header_offset_words32 = 0,
size_t chans_per_otw_buff = 1
){
+ state.io_buffs.resize(chans_per_otw_buff);
+
uhd::convert::function_type converter(
uhd::convert::get_converter_cpu_to_otw(
io_type, otw_type, chans_per_otw_buff, 1
@@ -398,19 +410,11 @@ template <typename T> UHD_INLINE T get_context_code(
if_packet_info.sob = metadata.start_of_burst;
if_packet_info.eob = metadata.end_of_burst;
- //TODO remove this code when sample counts of zero are supported by hardware
- std::vector<const void *> buffs_(buffs);
- size_t total_num_samps_(total_num_samps);
- if (total_num_samps == 0){
- static const boost::uint64_t zeros = 0; //max size of a host sample
- buffs_ = std::vector<const void *>(buffs.size(), &zeros);
- total_num_samps_ = 1;
- }
-
return _send1(
state,
- buffs_, 0,
- std::min(total_num_samps_, max_samples_per_packet),
+ //TODO remove this code when sample counts of zero are supported by hardware
+ (total_num_samps)?buffs : state.zero_buffs, 0,
+ std::max<size_t>(1, std::min(total_num_samps, max_samples_per_packet)),
if_packet_info,
converter,
vrt_packer,