diff options
Diffstat (limited to 'host/lib/transport')
27 files changed, 1791 insertions, 1771 deletions
diff --git a/host/lib/transport/adapter.cpp b/host/lib/transport/adapter.cpp index 247b33868..f5717c954 100644 --- a/host/lib/transport/adapter.cpp +++ b/host/lib/transport/adapter.cpp @@ -21,4 +21,3 @@ adapter_id_t adapter_ctx::register_adapter(adapter_info& info) return id; } } - diff --git a/host/lib/transport/dpdk_simple.cpp b/host/lib/transport/dpdk_simple.cpp index 50855f36a..d93d73b56 100644 --- a/host/lib/transport/dpdk_simple.cpp +++ b/host/lib/transport/dpdk_simple.cpp @@ -21,13 +21,13 @@ namespace { constexpr double SEND_TIMEOUT_MS = 500; // seconds } -class dpdk_simple_impl : public dpdk_simple { +class dpdk_simple_impl : public dpdk_simple +{ public: dpdk_simple_impl(const std::string& addr, const std::string& port) { link_params_t link_params = _get_default_link_params(); - _link = - uhd::transport::udp_dpdk_link::make(addr, port, link_params); + _link = uhd::transport::udp_dpdk_link::make(addr, port, link_params); UHD_LOG_TRACE("DPDK::SIMPLE", "Creating simple UDP object for " << addr << ":" << port << ", DPDK port index " @@ -37,7 +37,7 @@ public: UHD_ASSERT_THROW(ctx->is_init_done()); // Init I/O service - _port_id = _link->get_port()->get_port_id(); + _port_id = _link->get_port()->get_port_id(); _io_service = ctx->get_io_service(_port_id); // This is normally done by the I/O service manager, but with DPDK, this // is all it does so we skip that step @@ -120,7 +120,7 @@ public: size_t recv(const boost::asio::mutable_buffer& user_buff, double timeout) { size_t user_buff_size = boost::asio::buffer_size(user_buff); - uint8_t* user_data = boost::asio::buffer_cast<uint8_t*>(user_buff); + uint8_t* user_data = boost::asio::buffer_cast<uint8_t*>(user_buff); auto buff = _recv_io->get_recv_buff(static_cast<int32_t>(timeout * 1e3)); if (!buff) { @@ -218,4 +218,3 @@ udp_simple::sptr dpdk_simple::make_broadcast( return udp_simple::sptr(new dpdk_simple_impl(addr, port)); } }} // namespace uhd::transport - diff --git a/host/lib/transport/inline_io_service.cpp b/host/lib/transport/inline_io_service.cpp index 1438699b7..8206c145f 100644 --- a/host/lib/transport/inline_io_service.cpp +++ b/host/lib/transport/inline_io_service.cpp @@ -387,8 +387,14 @@ send_io_if::sptr inline_io_service::make_send_client(send_link_if::sptr send_lin UHD_ASSERT_THROW(send_cb); connect_sender(send_link.get(), num_send_frames); sptr io_srv = shared_from_this(); - auto send_io = std::make_shared<inline_send_io>( - io_srv, send_link, num_send_frames, send_cb, recv_link, num_recv_frames, recv_cb, fc_cb); + auto send_io = std::make_shared<inline_send_io>(io_srv, + send_link, + num_send_frames, + send_cb, + recv_link, + num_recv_frames, + recv_cb, + fc_cb); if (recv_link) { UHD_ASSERT_THROW(recv_cb); UHD_ASSERT_THROW(fc_cb); diff --git a/host/lib/transport/libusb1_base.cpp b/host/lib/transport/libusb1_base.cpp index 3362de712..60481bc6a 100644 --- a/host/lib/transport/libusb1_base.cpp +++ b/host/lib/transport/libusb1_base.cpp @@ -15,8 +15,8 @@ #include <cstdlib> #include <functional> #include <iostream> -#include <mutex> #include <memory> +#include <mutex> using namespace uhd; using namespace uhd::transport; diff --git a/host/lib/transport/libusb1_base.hpp b/host/lib/transport/libusb1_base.hpp index 5d909a664..7c70ab5d0 100644 --- a/host/lib/transport/libusb1_base.hpp +++ b/host/lib/transport/libusb1_base.hpp @@ -10,9 +10,9 @@ #include <uhd/config.hpp> #include <uhd/transport/usb_device_handle.hpp> +#include <uhd/utils/noncopyable.hpp> #include <libusb.h> #include <memory> -#include <uhd/utils/noncopyable.hpp> //! Define LIBUSB_CALL when its missing (non-windows) #ifndef LIBUSB_CALL diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index d02f90217..f918912d0 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -252,7 +252,9 @@ public: _mb_pool.push_back(std::make_shared<libusb_zero_copy_mb>(lut, this->get_frame_size(), - std::bind(&libusb_zero_copy_single::enqueue_buffer, this, std::placeholders::_1), + std::bind(&libusb_zero_copy_single::enqueue_buffer, + this, + std::placeholders::_1), is_recv, name)); diff --git a/host/lib/transport/muxed_zero_copy_if.cpp b/host/lib/transport/muxed_zero_copy_if.cpp index 054d74e0c..2602d8596 100644 --- a/host/lib/transport/muxed_zero_copy_if.cpp +++ b/host/lib/transport/muxed_zero_copy_if.cpp @@ -67,12 +67,11 @@ public: } // Only allocate a portion of the base transport's frames to each stream // to prevent all streams from attempting to use all the frames. - stream_impl::sptr stream = - std::make_shared<stream_impl>(this->shared_from_this(), - stream_num, - _base_xport->get_num_send_frames(), - _base_xport->get_num_recv_frames()); - _streams[stream_num] = stream; + stream_impl::sptr stream = std::make_shared<stream_impl>(this->shared_from_this(), + stream_num, + _base_xport->get_num_send_frames(), + _base_xport->get_num_recv_frames()); + _streams[stream_num] = stream; return stream; } diff --git a/host/lib/transport/nirio/lvbitx/process-lvbitx.py b/host/lib/transport/nirio/lvbitx/process-lvbitx.py index dfa94bb59..dbf9ff654 100755 --- a/host/lib/transport/nirio/lvbitx/process-lvbitx.py +++ b/host/lib/transport/nirio/lvbitx/process-lvbitx.py @@ -1,7 +1,7 @@ -#!/usr/bin/python -# +#!/usr/bin/pyBrand # Copyright 2013-2015 Ettus Research LLC # Copyright 2018 Ettus Research, a National Instruments Company +# Copyright 2020 Ettus Research, a National Instruments Brand # # SPDX-License-Identifier: GPL-3.0-or-later # diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp index 015344710..ed7c3f852 100644 --- a/host/lib/transport/nirio/nifpga_lvbitx.cpp +++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp @@ -6,20 +6,19 @@ // #include <uhd/transport/nirio/nifpga_lvbitx.h> +#include <boost/algorithm/string.hpp> #include <cstdlib> -#include <string> #include <fstream> -#include <streambuf> -#include <boost/algorithm/string.hpp> #include <regex> +#include <streambuf> +#include <string> namespace uhd { namespace niusrprio { std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path) { const std::regex md5_regex( - "<BitstreamMD5>([a-fA-F0-9]{32})<\\/BitstreamMD5>", - std::regex::icase); + "<BitstreamMD5>([a-fA-F0-9]{32})<\\/BitstreamMD5>", std::regex::icase); std::ifstream lvbitx_stream(file_path.c_str()); if (!lvbitx_stream.is_open()) { @@ -27,25 +26,21 @@ std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path) } std::string checksum, line; - while (std::getline(lvbitx_stream, line)) - { + while (std::getline(lvbitx_stream, line)) { try { // short-circuiting the regex search with a simple find is faster // for cases where the tag doesn't exist std::smatch md5_match; - if (line.find("<BitstreamMD5>") != std::string::npos && - std::regex_search(line, md5_match, md5_regex)) - { + if (line.find("<BitstreamMD5>") != std::string::npos + && std::regex_search(line, md5_match, md5_regex)) { checksum = std::string(md5_match[1].first, md5_match[1].second); break; } - } - catch (boost::exception&) { - + } catch (boost::exception&) { } } boost::to_upper(checksum); return checksum; } -}} +}} // namespace uhd::niusrprio diff --git a/host/lib/transport/nirio/nirio_driver_iface_linux.cpp b/host/lib/transport/nirio/nirio_driver_iface_linux.cpp index b66f6413e..40dc8b199 100644 --- a/host/lib/transport/nirio/nirio_driver_iface_linux.cpp +++ b/host/lib/transport/nirio/nirio_driver_iface_linux.cpp @@ -6,18 +6,16 @@ // #include <uhd/transport/nirio/nirio_driver_iface.h> -#include <stdio.h> #include <errno.h> #include <fcntl.h> -#include <unistd.h> +#include <stdio.h> #include <sys/ioctl.h> #include <sys/mman.h> +#include <unistd.h> namespace nirio_driver_iface { -nirio_status rio_open( - const std::string& device_path, - rio_dev_handle_t& device_handle) +nirio_status rio_open(const std::string& device_path, rio_dev_handle_t& device_handle) { device_handle = ::open(device_path.c_str(), O_RDWR | O_CLOEXEC); return (device_handle < 0) ? NiRio_Status_InvalidParameter : NiRio_Status_Success; @@ -34,59 +32,69 @@ bool rio_isopen(rio_dev_handle_t device_handle) return (device_handle >= 0); } -nirio_status rio_ioctl( - rio_dev_handle_t device_handle, +nirio_status rio_ioctl(rio_dev_handle_t device_handle, uint32_t ioctl_code, - const void *write_buf, + const void* write_buf, size_t write_buf_len, - void *read_buf, + void* read_buf, size_t read_buf_len) { - nirio_ioctl_block_t ioctl_block = {0,0,0,0,0,0}; + nirio_ioctl_block_t ioctl_block = {0, 0, 0, 0, 0, 0}; // two-casts necessary to prevent pointer sign-extension - ioctl_block.in_buf = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(write_buf)); - ioctl_block.in_buf_len = write_buf_len; - ioctl_block.out_buf = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(read_buf)); + ioctl_block.in_buf = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(write_buf)); + ioctl_block.in_buf_len = write_buf_len; + ioctl_block.out_buf = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(read_buf)); ioctl_block.out_buf_len = read_buf_len; int status = ::ioctl(device_handle, ioctl_code, &ioctl_block); if (status == -1) { switch (errno) { - case EINVAL: return NiRio_Status_InvalidParameter; - case EFAULT: return NiRio_Status_MemoryFull; - default: return NiRio_Status_SoftwareFault; + case EINVAL: + return NiRio_Status_InvalidParameter; + case EFAULT: + return NiRio_Status_MemoryFull; + default: + return NiRio_Status_SoftwareFault; } } else { return NiRio_Status_Success; } } -nirio_status rio_mmap( - rio_dev_handle_t device_handle, +nirio_status rio_mmap(rio_dev_handle_t device_handle, uint16_t memory_type, size_t size, bool writable, - rio_mmap_t &map) + rio_mmap_t& map) { - int access_mode = PROT_READ; //Write-only mode not supported - if (writable) access_mode |= PROT_WRITE; - map.addr = ::mmap(NULL, size, access_mode, MAP_SHARED, device_handle, (off_t) memory_type * sysconf(_SC_PAGESIZE)); + int access_mode = PROT_READ; // Write-only mode not supported + if (writable) + access_mode |= PROT_WRITE; + map.addr = ::mmap(NULL, + size, + access_mode, + MAP_SHARED, + device_handle, + (off_t)memory_type * sysconf(_SC_PAGESIZE)); map.size = size; - if (map.addr == MAP_FAILED) { + if (map.addr == MAP_FAILED) { map.addr = NULL; map.size = 0; switch (errno) { - case EINVAL: return NiRio_Status_InvalidParameter; - case EFAULT: return NiRio_Status_MemoryFull; - default: return NiRio_Status_SoftwareFault; + case EINVAL: + return NiRio_Status_InvalidParameter; + case EFAULT: + return NiRio_Status_MemoryFull; + default: + return NiRio_Status_SoftwareFault; } } return NiRio_Status_Success; } -nirio_status rio_munmap(rio_mmap_t &map) +nirio_status rio_munmap(rio_mmap_t& map) { nirio_status status = 0; if (map.addr != NULL) { @@ -98,4 +106,4 @@ nirio_status rio_munmap(rio_mmap_t &map) return status; } -} +} // namespace nirio_driver_iface diff --git a/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp b/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp index 548f3b7f4..855301147 100644 --- a/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp +++ b/host/lib/transport/nirio/nirio_driver_iface_unsupported.cpp @@ -8,46 +8,41 @@ namespace nirio_driver_iface { -nirio_status rio_open( - UHD_UNUSED(const std::string& device_path), +nirio_status rio_open(UHD_UNUSED(const std::string& device_path), UHD_UNUSED(rio_dev_handle_t& device_handle)) { return NiRio_Status_FeatureNotSupported; } -void rio_close(UHD_UNUSED(rio_dev_handle_t& device_handle)) -{ -} +void rio_close(UHD_UNUSED(rio_dev_handle_t& device_handle)) {} bool rio_isopen(UHD_UNUSED(rio_dev_handle_t device_handle)) { return false; } -nirio_status rio_ioctl( - UHD_UNUSED(rio_dev_handle_t device_handle), +nirio_status rio_ioctl(UHD_UNUSED(rio_dev_handle_t device_handle), UHD_UNUSED(uint32_t ioctl_code), - UHD_UNUSED(const void *write_buf), + UHD_UNUSED(const void* write_buf), UHD_UNUSED(size_t write_buf_len), - UHD_UNUSED(void *read_buf), + UHD_UNUSED(void* read_buf), UHD_UNUSED(size_t read_buf_len)) { return NiRio_Status_FeatureNotSupported; } -nirio_status rio_mmap( - UHD_UNUSED(rio_dev_handle_t device_handle), +nirio_status rio_mmap(UHD_UNUSED(rio_dev_handle_t device_handle), UHD_UNUSED(uint16_t memory_type), UHD_UNUSED(size_t size), UHD_UNUSED(bool writable), - UHD_UNUSED(rio_mmap_t &map)) + UHD_UNUSED(rio_mmap_t& map)) { return NiRio_Status_FeatureNotSupported; } -nirio_status rio_munmap(UHD_UNUSED(rio_mmap_t &map)) +nirio_status rio_munmap(UHD_UNUSED(rio_mmap_t& map)) { return NiRio_Status_FeatureNotSupported; } -} +} // namespace nirio_driver_iface diff --git a/host/lib/transport/nirio/nirio_driver_iface_win.cpp b/host/lib/transport/nirio/nirio_driver_iface_win.cpp index 6a5513ebe..e50473e99 100644 --- a/host/lib/transport/nirio/nirio_driver_iface_win.cpp +++ b/host/lib/transport/nirio/nirio_driver_iface_win.cpp @@ -8,20 +8,31 @@ #include <uhd/transport/nirio/nirio_driver_iface.h> #include <process.h> -#define NIRIO_IOCTL_MAP_MEMORY CTL_CODE(FILE_DEVICE_UNKNOWN, 0xF00, METHOD_BUFFERED, (FILE_READ_ACCESS | FILE_WRITE_ACCESS)) -#define NIRIO_IOCTL_UNMAP_MEMORY CTL_CODE(FILE_DEVICE_UNKNOWN, 0xF01, METHOD_BUFFERED, (FILE_READ_ACCESS | FILE_WRITE_ACCESS)) +#define NIRIO_IOCTL_MAP_MEMORY \ + CTL_CODE(FILE_DEVICE_UNKNOWN, \ + 0xF00, \ + METHOD_BUFFERED, \ + (FILE_READ_ACCESS | FILE_WRITE_ACCESS)) +#define NIRIO_IOCTL_UNMAP_MEMORY \ + CTL_CODE(FILE_DEVICE_UNKNOWN, \ + 0xF01, \ + METHOD_BUFFERED, \ + (FILE_READ_ACCESS | FILE_WRITE_ACCESS)) namespace nirio_driver_iface { -nirio_status rio_open( - const std::string& device_path, - rio_dev_handle_t& device_handle) +nirio_status rio_open(const std::string& device_path, rio_dev_handle_t& device_handle) { - device_handle = CreateFileA(device_path.c_str(), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, /* default security */ - OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL /* template file */); - - return (device_handle == INVALID_HANDLE_VALUE) ? NiRio_Status_InvalidParameter : NiRio_Status_Success; + device_handle = CreateFileA(device_path.c_str(), + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, /* default security */ + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL /* template file */); + + return (device_handle == INVALID_HANDLE_VALUE) ? NiRio_Status_InvalidParameter + : NiRio_Status_Success; } void rio_close(rio_dev_handle_t& device_handle) @@ -35,27 +46,30 @@ bool rio_isopen(rio_dev_handle_t device_handle) return (device_handle != INVALID_HANDLE_VALUE); } -nirio_status rio_ioctl( - rio_dev_handle_t device_handle, +nirio_status rio_ioctl(rio_dev_handle_t device_handle, uint32_t ioctl_code, - const void *write_buf, + const void* write_buf, size_t write_buf_len, - void *read_buf, + void* read_buf, size_t read_buf_len) { - if (!rio_isopen(device_handle)) return NiRio_Status_ResourceNotInitialized; + if (!rio_isopen(device_handle)) + return NiRio_Status_ResourceNotInitialized; /* Note, if the file handle was opened with the OVERLAPPED flag, you must - * supply an OVERLAPPED structure to ReadFile, WriteFile, and - * DeviceIoControl, even when doing synchronous IO. */ + * supply an OVERLAPPED structure to ReadFile, WriteFile, and + * DeviceIoControl, even when doing synchronous IO. */ OVERLAPPED zeroedOverlapped = {0}; - DWORD outLen = 0; - - if (!(DeviceIoControl(device_handle, ioctl_code, - const_cast<void*>(write_buf), static_cast<DWORD>(write_buf_len), - read_buf, static_cast<DWORD>(read_buf_len), - &outLen, &zeroedOverlapped ))) - { + DWORD outLen = 0; + + if (!(DeviceIoControl(device_handle, + ioctl_code, + const_cast<void*>(write_buf), + static_cast<DWORD>(write_buf_len), + read_buf, + static_cast<DWORD>(read_buf_len), + &outLen, + &zeroedOverlapped))) { UHD_UNUSED(int_fast32_t lastError) = GetLastError(); return NiRio_Status_SoftwareFault; } @@ -63,42 +77,48 @@ nirio_status rio_ioctl( return NiRio_Status_Success; } -unsigned int __stdcall memory_map_thread_routine(void *context) +unsigned int __stdcall memory_map_thread_routine(void* context) { - rio_mmap_threadargs_t *args = (rio_mmap_threadargs_t*)context; - args->status = rio_ioctl(args->device_handle, NIRIO_IOCTL_MAP_MEMORY, &(args->params), sizeof(args->params), NULL, 0); - if (nirio_status_fatal(args->status)) - { + rio_mmap_threadargs_t* args = (rio_mmap_threadargs_t*)context; + args->status = rio_ioctl(args->device_handle, + NIRIO_IOCTL_MAP_MEMORY, + &(args->params), + sizeof(args->params), + NULL, + 0); + if (nirio_status_fatal(args->status)) { SetEvent(reinterpret_cast<HANDLE>(args->params.map_ready_event_handle)); } return 0; } -nirio_status rio_mmap( - rio_dev_handle_t device_handle, +nirio_status rio_mmap(rio_dev_handle_t device_handle, uint16_t memory_type, size_t size, bool writable, - rio_mmap_t &map) + rio_mmap_t& map) { - if (!rio_isopen(device_handle)) return NiRio_Status_ResourceNotInitialized; + if (!rio_isopen(device_handle)) + return NiRio_Status_ResourceNotInitialized; access_mode_t access_mode = writable ? ACCESS_MODE_WRITE : ACCESS_MODE_READ; - uint64_t mapped_addr = 0; - map.map_thread_args.device_handle = device_handle; - map.map_thread_args.status = NiRio_Status_Success; - map.map_thread_args.params.memoryType = memory_type; - map.map_thread_args.params.size = (uint32_t)size; + uint64_t mapped_addr = 0; + map.map_thread_args.device_handle = device_handle; + map.map_thread_args.status = NiRio_Status_Success; + map.map_thread_args.params.memoryType = memory_type; + map.map_thread_args.params.size = (uint32_t)size; map.map_thread_args.params.mapped_va_ptr = reinterpret_cast<uintptr_t>(&mapped_addr); - map.map_thread_args.params.access_mode = (uint8_t)access_mode; - HANDLE map_ready_event_handle = CreateEventA(NULL, TRUE, FALSE, NULL); + map.map_thread_args.params.access_mode = (uint8_t)access_mode; + HANDLE map_ready_event_handle = CreateEventA(NULL, TRUE, FALSE, NULL); if (map_ready_event_handle == NULL) { map.addr = NULL; return NiRio_Status_SoftwareFault; } - map.map_thread_args.params.map_ready_event_handle = reinterpret_cast<uint64_t>(map_ready_event_handle); - map.map_thread_handle = (HANDLE) _beginthreadex(NULL, 0, memory_map_thread_routine, &(map.map_thread_args), 0, NULL); + map.map_thread_args.params.map_ready_event_handle = + reinterpret_cast<uint64_t>(map_ready_event_handle); + map.map_thread_handle = (HANDLE)_beginthreadex( + NULL, 0, memory_map_thread_routine, &(map.map_thread_args), 0, NULL); nirio_status status = NiRio_Status_Success; if (map.map_thread_handle == NULL) { @@ -117,14 +137,20 @@ nirio_status rio_mmap( return status; } -nirio_status rio_munmap(rio_mmap_t &map) +nirio_status rio_munmap(rio_mmap_t& map) { - if (!rio_isopen(map.map_thread_args.device_handle)) return NiRio_Status_ResourceNotInitialized; + if (!rio_isopen(map.map_thread_args.device_handle)) + return NiRio_Status_ResourceNotInitialized; nirio_status status = NiRio_Status_Success; if (map.addr != NULL) { uint64_t mapped_addr = reinterpret_cast<uintptr_t>(map.addr); - status = rio_ioctl(map.map_thread_args.device_handle, NIRIO_IOCTL_UNMAP_MEMORY, &mapped_addr, sizeof(mapped_addr), NULL, 0); + status = rio_ioctl(map.map_thread_args.device_handle, + NIRIO_IOCTL_UNMAP_MEMORY, + &mapped_addr, + sizeof(mapped_addr), + NULL, + 0); if (nirio_status_not_fatal(status)) { WaitForSingleObject(map.map_thread_handle, INFINITE); } @@ -134,4 +160,4 @@ nirio_status rio_munmap(rio_mmap_t &map) return status; } -} +} // namespace nirio_driver_iface diff --git a/host/lib/transport/nirio/nirio_resource_manager.cpp b/host/lib/transport/nirio/nirio_resource_manager.cpp index 42e85d7c1..4650e83a2 100644 --- a/host/lib/transport/nirio/nirio_resource_manager.cpp +++ b/host/lib/transport/nirio/nirio_resource_manager.cpp @@ -9,22 +9,19 @@ // "push" and "pop" introduced in GCC 4.6; works with all clang #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic push +# pragma GCC diagnostic push #endif #if defined(__clang__) || defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -namespace uhd { namespace niusrprio -{ +namespace uhd { namespace niusrprio { -nirio_resource_manager::nirio_resource_manager():_fifo_info_map(), _reg_info_map() -{ -} +nirio_resource_manager::nirio_resource_manager() : _fifo_info_map(), _reg_info_map() {} void nirio_resource_manager::set_proxy(niriok_proxy::sptr proxy) { - _kernel_proxy = proxy; + _kernel_proxy = proxy; } @@ -34,18 +31,22 @@ nirio_resource_manager::~nirio_resource_manager() } nirio_status nirio_resource_manager::initialize( - const nirio_register_info_vtr& reg_info_vtr, - const nirio_fifo_info_vtr& fifo_info_vtr) + const nirio_register_info_vtr& reg_info_vtr, const nirio_fifo_info_vtr& fifo_info_vtr) { nirio_status status = 0; - for (nirio_fifo_info_vtr::const_iterator it = fifo_info_vtr.begin(); it != fifo_info_vtr.end(); it++) { + for (nirio_fifo_info_vtr::const_iterator it = fifo_info_vtr.begin(); + it != fifo_info_vtr.end(); + it++) { const nirio_fifo_info_t& fifo_info = *it; - status = _add_fifo_resource(fifo_info); - if (nirio_status_fatal(status)) return status; + status = _add_fifo_resource(fifo_info); + if (nirio_status_fatal(status)) + return status; _fifo_info_map.insert(fifo_info_map_t::value_type(fifo_info.name, fifo_info)); } - for (nirio_register_info_vtr::const_iterator it = reg_info_vtr.begin(); it != reg_info_vtr.end(); it++) { + for (nirio_register_info_vtr::const_iterator it = reg_info_vtr.begin(); + it != reg_info_vtr.end(); + it++) { const nirio_register_info_t& reg_info = *it; _reg_info_map.insert(register_info_map_t::value_type(reg_info.name, reg_info)); @@ -59,11 +60,12 @@ void nirio_resource_manager::finalize() } nirio_status nirio_resource_manager::get_register_offset( - const char* register_name, - uint32_t& offset) + const char* register_name, uint32_t& offset) { - register_info_map_t::const_iterator it = _reg_info_map.find(fifo_info_map_t::key_type(register_name)); - if (it == _reg_info_map.end()) return NiRio_Status_InvalidParameter; + register_info_map_t::const_iterator it = + _reg_info_map.find(fifo_info_map_t::key_type(register_name)); + if (it == _reg_info_map.end()) + return NiRio_Status_InvalidParameter; offset = (*it).second.offset; @@ -82,15 +84,18 @@ nirio_status nirio_resource_manager::_set_driver_config() return _kernel_proxy->set_device_config(); } -nirio_fifo_info_t* nirio_resource_manager::_lookup_fifo_info(const char* fifo_name) { - fifo_info_map_t::iterator it = _fifo_info_map.find(fifo_info_map_t::key_type(fifo_name)); - if (it == _fifo_info_map.end()) return NULL; +nirio_fifo_info_t* nirio_resource_manager::_lookup_fifo_info(const char* fifo_name) +{ + fifo_info_map_t::iterator it = + _fifo_info_map.find(fifo_info_map_t::key_type(fifo_name)); + if (it == _fifo_info_map.end()) + return NULL; return &((*it).second); } -}} +}} // namespace uhd::niusrprio #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy.cpp b/host/lib/transport/nirio/niriok_proxy.cpp index ee177c371..4d413bedb 100644 --- a/host/lib/transport/nirio/niriok_proxy.cpp +++ b/host/lib/transport/nirio/niriok_proxy.cpp @@ -12,59 +12,54 @@ // "push" and "pop" introduced in GCC 4.6; works with all clang #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic push +# pragma GCC diagnostic push #endif #if defined(__clang__) || defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -namespace uhd { namespace niusrprio -{ - // initialization of static members - boost::shared_mutex niriok_proxy::_synchronization; +namespace uhd { namespace niusrprio { +// initialization of static members +boost::shared_mutex niriok_proxy::_synchronization; + +//------------------------------------------------------- +// niriok_proxy +//------------------------------------------------------- +niriok_proxy::niriok_proxy() : _device_handle(nirio_driver_iface::INVALID_RIO_HANDLE) {} - //------------------------------------------------------- - // niriok_proxy - //------------------------------------------------------- - niriok_proxy::niriok_proxy(): _device_handle(nirio_driver_iface::INVALID_RIO_HANDLE) - { - } +niriok_proxy::~niriok_proxy() {} + +niriok_proxy::sptr niriok_proxy::make_and_open(const std::string& interface_path) +{ + nirio_status status; - niriok_proxy::~niriok_proxy() - { - } - - niriok_proxy::sptr niriok_proxy::make_and_open(const std::string& interface_path) - { - nirio_status status; - - /* - niriok_proxy_impl_v1 supports NI-RIO 13.0 - niriok_proxy_impl_v2 supports NI-RIO 14.0 and later + /* + niriok_proxy_impl_v1 supports NI-RIO 13.0 + niriok_proxy_impl_v2 supports NI-RIO 14.0 and later - We must dynamically determine which version of the RIO kernel we are - interfacing to. Opening the interface will fail if there is a version - incompatibility, so we try to open successively newer interface - proxies until it succeeds. - */ + We must dynamically determine which version of the RIO kernel we are + interfacing to. Opening the interface will fail if there is a version + incompatibility, so we try to open successively newer interface + proxies until it succeeds. + */ - sptr proxy_v1(new niriok_proxy_impl_v1); - status = proxy_v1->open(interface_path); + sptr proxy_v1(new niriok_proxy_impl_v1); + status = proxy_v1->open(interface_path); - if (nirio_status_not_fatal(status)) - return proxy_v1; + if (nirio_status_not_fatal(status)) + return proxy_v1; - sptr proxy_v2(new niriok_proxy_impl_v2); - status = proxy_v2->open(interface_path); + sptr proxy_v2(new niriok_proxy_impl_v2); + status = proxy_v2->open(interface_path); - if (nirio_status_not_fatal(status)) - return proxy_v2; + if (nirio_status_not_fatal(status)) + return proxy_v2; - throw uhd::runtime_error("Unable to detect a supported version of the NI-RIO kernel interface."); - - } -}} + throw uhd::runtime_error( + "Unable to detect a supported version of the NI-RIO kernel interface."); +} +}} // namespace uhd::niusrprio #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp index ae69cb470..673b5f98b 100644 --- a/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp +++ b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp @@ -10,854 +10,840 @@ // "push" and "pop" introduced in GCC 4.6; works with all clang #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic push +# pragma GCC diagnostic push #endif #if defined(__clang__) || defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif // CTL_CODE macro for non-win OSes #ifndef UHD_PLATFORM_WIN32 - #define CTL_CODE(a,controlCode,b,c) (controlCode) +# define CTL_CODE(a, controlCode, b, c) (controlCode) #endif const uint32_t NIRIO_IOCTL_BASE = 0x800; -const uint32_t NIRIO_IOCTL_SYNCOP = - CTL_CODE(FILE_DEVICE_UNKNOWN, - NIRIO_IOCTL_BASE + 4, - METHOD_OUT_DIRECT, - FILE_READ_DATA | FILE_WRITE_DATA); - ///< The synchronous operation code. Note: We - /// must use METHOD_OUT_DIRECT on the syncOp() - /// IOCTL to ensure the contents of the output - /// block are available in the kernel. - -const uint32_t NIRIO_IOCTL_GET_IFACE_NUM = - CTL_CODE(FILE_DEVICE_UNKNOWN, - NIRIO_IOCTL_BASE + 6, - METHOD_BUFFERED, - FILE_READ_DATA); ///< Get the interface number for a device - -//const uint32_t NIRIO_IOCTL_GET_SESSION = - //CTL_CODE(FILE_DEVICE_UNKNOWN, - //NIRIO_IOCTL_BASE + 8, - //METHOD_BUFFERED, - //FILE_READ_ACCESS); ///< Gets a previously opened session to a device - -const uint32_t NIRIO_IOCTL_POST_OPEN = - CTL_CODE(FILE_DEVICE_UNKNOWN, - NIRIO_IOCTL_BASE + 9, - METHOD_BUFFERED, - FILE_READ_ACCESS); ///< Called after opening a session - -const uint32_t NIRIO_IOCTL_PRE_CLOSE = - CTL_CODE(FILE_DEVICE_UNKNOWN, - NIRIO_IOCTL_BASE + 10, - METHOD_BUFFERED, - FILE_READ_ACCESS); ///< Called before closing a session - -namespace uhd { namespace niusrprio -{ - // ------------------------------- - // Function Codes: defined as integers rather than enums because they - // are going to be carried accross boundaries so size matters - - struct NIRIO_FUNC - { - static const uint32_t GET32 = 0x00000001; - static const uint32_t SET32 = 0x00000002; - static const uint32_t SET_DRIVER_CONFIG = 0x00000007; - static const uint32_t FIFO = 0x00000008; - static const uint32_t IO = 0x0000000A; - static const uint32_t FIFO_STOP_ALL = 0x0000000C; - static const uint32_t ADD_RESOURCE = 0x0000000D; - static const uint32_t GET_STRING = 0x0000000E; - static const uint32_t SET_STRING = 0x0000000F; - static const uint32_t DOWNLOAD = 0x00000013; - static const uint32_t RESET = 0x00000014; - }; +const uint32_t NIRIO_IOCTL_SYNCOP = CTL_CODE(FILE_DEVICE_UNKNOWN, + NIRIO_IOCTL_BASE + 4, + METHOD_OUT_DIRECT, + FILE_READ_DATA | FILE_WRITE_DATA); +///< The synchronous operation code. Note: We +/// must use METHOD_OUT_DIRECT on the syncOp() +/// IOCTL to ensure the contents of the output +/// block are available in the kernel. + +const uint32_t NIRIO_IOCTL_GET_IFACE_NUM = CTL_CODE(FILE_DEVICE_UNKNOWN, + NIRIO_IOCTL_BASE + 6, + METHOD_BUFFERED, + FILE_READ_DATA); ///< Get the interface number for a device + +// const uint32_t NIRIO_IOCTL_GET_SESSION = +// CTL_CODE(FILE_DEVICE_UNKNOWN, +// NIRIO_IOCTL_BASE + 8, +// METHOD_BUFFERED, +// FILE_READ_ACCESS); ///< Gets a previously opened session to a device + +const uint32_t NIRIO_IOCTL_POST_OPEN = CTL_CODE(FILE_DEVICE_UNKNOWN, + NIRIO_IOCTL_BASE + 9, + METHOD_BUFFERED, + FILE_READ_ACCESS); ///< Called after opening a session + +const uint32_t NIRIO_IOCTL_PRE_CLOSE = CTL_CODE(FILE_DEVICE_UNKNOWN, + NIRIO_IOCTL_BASE + 10, + METHOD_BUFFERED, + FILE_READ_ACCESS); ///< Called before closing a session + +namespace uhd { namespace niusrprio { +// ------------------------------- +// Function Codes: defined as integers rather than enums because they +// are going to be carried accross boundaries so size matters + +struct NIRIO_FUNC +{ + static const uint32_t GET32 = 0x00000001; + static const uint32_t SET32 = 0x00000002; + static const uint32_t SET_DRIVER_CONFIG = 0x00000007; + static const uint32_t FIFO = 0x00000008; + static const uint32_t IO = 0x0000000A; + static const uint32_t FIFO_STOP_ALL = 0x0000000C; + static const uint32_t ADD_RESOURCE = 0x0000000D; + static const uint32_t GET_STRING = 0x0000000E; + static const uint32_t SET_STRING = 0x0000000F; + static const uint32_t DOWNLOAD = 0x00000013; + static const uint32_t RESET = 0x00000014; +}; + +struct NIRIO_RESOURCE +{ + static const uint32_t INPUT_FIFO = 0xD0000001; + static const uint32_t OUTPUT_FIFO = 0xD0000002; +}; - struct NIRIO_RESOURCE +struct NIRIO_FIFO +{ + static const uint32_t CONFIGURE = 0x80000001; + static const uint32_t START = 0x80000002; + static const uint32_t STOP = 0x80000003; + static const uint32_t READ = 0x80000004; + static const uint32_t WRITE = 0x80000005; + static const uint32_t WAIT = 0x80000006; + static const uint32_t GRANT = 0x80000007; +}; + +struct NIRIO_IO +{ + static const uint32_t POKE64 = 0xA0000005; + static const uint32_t POKE32 = 0xA0000006; + static const uint32_t POKE16 = 0xA0000007; + static const uint32_t POKE8 = 0xA0000008; + static const uint32_t PEEK64 = 0xA0000009; + static const uint32_t PEEK32 = 0xA000000A; + static const uint32_t PEEK16 = 0xA000000B; + static const uint32_t PEEK8 = 0xA000000C; + static const uint32_t READ_BLOCK = 0xA000000D; + static const uint32_t WRITE_BLOCK = 0xA000000E; + static const uint32_t GET_IO_WINDOW = 0xA000000F; + static const uint32_t GET_IO_WINDOW_SIZE = 0xA0000010; +}; + +struct nirio_ioctl_packet_t +{ + nirio_ioctl_packet_t( + void* const _outBuf, const uint32_t _outSize, const int32_t _statusCode) { - static const uint32_t INPUT_FIFO = 0xD0000001; - static const uint32_t OUTPUT_FIFO = 0xD0000002; + outBuf._64BitField = 0; + outBuf.pointer = _outBuf; + outSize = _outSize; + statusCode = _statusCode; }; - struct NIRIO_FIFO - { - static const uint32_t CONFIGURE = 0x80000001; - static const uint32_t START = 0x80000002; - static const uint32_t STOP = 0x80000003; - static const uint32_t READ = 0x80000004; - static const uint32_t WRITE = 0x80000005; - static const uint32_t WAIT = 0x80000006; - static const uint32_t GRANT = 0x80000007; - }; + union { + void* pointer; + uint64_t _64BitField; + } outBuf; - struct NIRIO_IO - { - static const uint32_t POKE64 = 0xA0000005; - static const uint32_t POKE32 = 0xA0000006; - static const uint32_t POKE16 = 0xA0000007; - static const uint32_t POKE8 = 0xA0000008; - static const uint32_t PEEK64 = 0xA0000009; - static const uint32_t PEEK32 = 0xA000000A; - static const uint32_t PEEK16 = 0xA000000B; - static const uint32_t PEEK8 = 0xA000000C; - static const uint32_t READ_BLOCK = 0xA000000D; - static const uint32_t WRITE_BLOCK = 0xA000000E; - static const uint32_t GET_IO_WINDOW = 0xA000000F; - static const uint32_t GET_IO_WINDOW_SIZE = 0xA0000010; - }; + uint32_t outSize; + int32_t statusCode; +}; + +struct nirio_syncop_in_params_t +{ + uint32_t function; + uint32_t subfunction; - struct nirio_ioctl_packet_t { - nirio_ioctl_packet_t(void* const _outBuf, const uint32_t _outSize, const int32_t _statusCode) + union { + struct { - outBuf._64BitField = 0; - outBuf.pointer = _outBuf; - outSize = _outSize; - statusCode = _statusCode; - }; + uint32_t attribute; + uint32_t value; + } attribute32; - union { - void* pointer; - uint64_t _64BitField; - } outBuf; + struct + { + uint32_t attribute; + uint64_t value; + } attribute64; - uint32_t outSize; - int32_t statusCode; - }; + struct + { + uint32_t attribute; + } attributeStr; - struct nirio_syncop_in_params_t - { - uint32_t function; - uint32_t subfunction; - - union - { - struct - { - uint32_t attribute; - uint32_t value; - } attribute32; - - struct - { - uint32_t attribute; - uint64_t value; - } attribute64; - - struct - { - uint32_t attribute; - } attributeStr; - - struct - { - uint32_t attribute; - } download; - - union - { - struct - { + struct + { + uint32_t attribute; + } download; + + union { + struct + { uint32_t reserved_field_0_0_0; - } reserved_field_0_0; - struct - { + } reserved_field_0_0; + struct + { uint32_t reserved_field_0_1_0; uint32_t reserved_field_0_1_1; - } reserved_field_0_1; - struct - { + } reserved_field_0_1; + struct + { uint32_t reserved_field_0_2_0; - } reserved_field_0_2; - } reserved_field_0; + } reserved_field_0_2; + } reserved_field_0; - union - { - struct - { + union { + struct + { uint32_t channel; uint32_t baseAddress; uint32_t depthInSamples; uint32_t version; - } fifo; - struct - { + } fifo; + struct + { uint32_t channel; uint32_t baseAddress; uint32_t depthInSamples; uint32_t version; uint32_t scalarType; uint32_t bitWidth; - } fifoWithDataType; - struct - { + } fifoWithDataType; + struct + { uint64_t rangeBaseAddress; uint32_t rangeSizeInBytes; uint32_t rangeAttribute; - } atomic; // obsolete - } add; + } atomic; // obsolete + } add; - struct - { - uint32_t channel; + struct + { + uint32_t channel; - union - { + union { struct { - uint32_t requestedDepth; - uint8_t requiresActuals; + uint32_t requestedDepth; + uint8_t requiresActuals; } config; struct { - uint32_t timeout; + uint32_t timeout; } read; struct { - uint32_t timeout; - uint32_t scalarType; - uint32_t bitWidth; + uint32_t timeout; + uint32_t scalarType; + uint32_t bitWidth; } readWithDataType; struct { - uint32_t timeout; + uint32_t timeout; } write; struct { - uint32_t timeout; - uint32_t scalarType; - uint32_t bitWidth; + uint32_t timeout; + uint32_t scalarType; + uint32_t bitWidth; } writeWithDataType; struct { - uint32_t elementsRequested; - uint32_t scalarType; - uint32_t bitWidth; - uint32_t timeout; - uint8_t output; + uint32_t elementsRequested; + uint32_t scalarType; + uint32_t bitWidth; + uint32_t timeout; + uint8_t output; } wait; struct { - uint32_t elements; + uint32_t elements; } grant; - } op; - } fifo; - - struct - { - uint64_t reserved_field_1_0; - uint32_t reserved_field_1_1; - uint32_t reserved_field_1_2; - } reserved_field_1; // Obsolete - - struct - { - uint32_t offset; - union - { + } op; + } fifo; + + struct + { + uint64_t reserved_field_1_0; + uint32_t reserved_field_1_1; + uint32_t reserved_field_1_2; + } reserved_field_1; // Obsolete + + struct + { + uint32_t offset; + union { uint64_t value64; uint32_t value32; uint16_t value16; - uint8_t value8; - } value; - union - { - uint32_t sizeToMap; - } memoryMappedIoWindow; - } io; - - struct - { - uint32_t reserved_field_2_0; - uint32_t reserved_field_2_1; - } reserved_field_2; - - struct - { - uint32_t reserved_field_3_0; - } reserved_field_3; - - union - { - struct - { + uint8_t value8; + } value; + union { + uint32_t sizeToMap; + } memoryMappedIoWindow; + } io; + + struct + { + uint32_t reserved_field_2_0; + uint32_t reserved_field_2_1; + } reserved_field_2; + + struct + { + uint32_t reserved_field_3_0; + } reserved_field_3; + + union { + struct + { uint32_t reserved_field_4_0; - int32_t reserved_field_4_1; - } wait; - } reserved_field_4; + int32_t reserved_field_4_1; + } wait; + } reserved_field_4; - } params; + } params; - uint32_t inbufByteLen; + uint32_t inbufByteLen; - union - { - const void* pointer; - uint64_t _64BitField; - } inbuf; - }; + union { + const void* pointer; + uint64_t _64BitField; + } inbuf; +}; - static inline void init_syncop_in_params(nirio_syncop_in_params_t& param, const void* const buf, const uint32_t len) - { - param.inbuf._64BitField = 0; - param.inbuf.pointer = buf; - param.inbufByteLen = len; - } +static inline void init_syncop_in_params( + nirio_syncop_in_params_t& param, const void* const buf, const uint32_t len) +{ + param.inbuf._64BitField = 0; + param.inbuf.pointer = buf; + param.inbufByteLen = len; +} - struct nirio_syncop_out_params_t - { - union - { - struct - { - uint32_t value; - } attribute32; - - struct - { - uint64_t value; - } attribute64; - - union - { - struct - { +struct nirio_syncop_out_params_t +{ + union { + struct + { + uint32_t value; + } attribute32; + + struct + { + uint64_t value; + } attribute64; + + union { + struct + { uint32_t reserved_field_0_0; - } enable; - } reserved_field_0; + } enable; + } reserved_field_0; - struct - { - union - { + struct + { + union { struct { - uint32_t actualDepth; - uint32_t actualSize; + uint32_t actualDepth; + uint32_t actualSize; } config; struct { - uint32_t numberRead; - uint32_t numberRemaining; + uint32_t numberRead; + uint32_t numberRemaining; } read; struct { - uint32_t numberRemaining; + uint32_t numberRemaining; } write; struct { - union - { - void* pointer; - uint64_t _64BitField; - } elements; + union { + void* pointer; + uint64_t _64BitField; + } elements; } wait; - } op; - } fifo; - - struct - { - union - { - union - { - uint64_t value64; - uint32_t value32; - uint16_t value16; - uint8_t value8; + } op; + } fifo; + + struct + { + union { + union { + uint64_t value64; + uint32_t value32; + uint16_t value16; + uint8_t value8; } value; - union - { - void* memoryMappedAddress; - uint64_t _64BitField; + union { + void* memoryMappedAddress; + uint64_t _64BitField; } memoryMappedIoWindow; - union - { - uint32_t size; + union { + uint32_t size; } memoryMappedIoWindowSize; - }; - } io; - - uint32_t stringLength; - - struct - { - uint32_t reserved_field_1_0; - } reserved_field_1; - - } params; + }; + } io; - uint32_t outbufByteLen; + uint32_t stringLength; - union - { - void* pointer; - uint64_t _64BitField; - } outbuf; - }; - - static inline void init_syncop_out_params(nirio_syncop_out_params_t& param, void* buf, uint32_t len) - { - param.outbuf._64BitField = 0; - param.outbuf.pointer = buf; - param.outbufByteLen = len; - } + struct + { + uint32_t reserved_field_1_0; + } reserved_field_1; - //------------------------------------------------------- - // niriok_proxy_impl_v1 - //------------------------------------------------------- - niriok_proxy_impl_v1::niriok_proxy_impl_v1() - { - } + } params; - niriok_proxy_impl_v1::~niriok_proxy_impl_v1() - { - close(); - } + uint32_t outbufByteLen; - nirio_status niriok_proxy_impl_v1::open(const std::string& interface_path) - { - WRITER_LOCK - - if (interface_path.empty()) return NiRio_Status_ResourceNotFound; - - //close if already open. - // use non-locking _close since we already have the lock - _close(); - - nirio_status status = NiRio_Status_Success; - nirio_status_chain(nirio_driver_iface::rio_open( - interface_path, _device_handle), status); - if (nirio_status_not_fatal(status)) { - nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle, - NIRIO_IOCTL_POST_OPEN, - NULL, 0, NULL, 0), status); - nirio_ioctl_packet_t out(&_interface_num, sizeof(_interface_num), 0); - nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle, - NIRIO_IOCTL_GET_IFACE_NUM, - NULL, 0, - &out, sizeof(out)), status); - - if (nirio_status_fatal(status)) _close(); - } - return status; - } + union { + void* pointer; + uint64_t _64BitField; + } outbuf; +}; - void niriok_proxy_impl_v1::close(void) - { - WRITER_LOCK +static inline void init_syncop_out_params( + nirio_syncop_out_params_t& param, void* buf, uint32_t len) +{ + param.outbuf._64BitField = 0; + param.outbuf.pointer = buf; + param.outbufByteLen = len; +} - _close(); - } +//------------------------------------------------------- +// niriok_proxy_impl_v1 +//------------------------------------------------------- +niriok_proxy_impl_v1::niriok_proxy_impl_v1() {} - // this protected _close doesn't acquire the lock, so it can be used in methods - // that already have the lock - void niriok_proxy_impl_v1::_close() - { +niriok_proxy_impl_v1::~niriok_proxy_impl_v1() +{ + close(); +} - if(nirio_driver_iface::rio_isopen(_device_handle)) - { +nirio_status niriok_proxy_impl_v1::open(const std::string& interface_path) +{ + WRITER_LOCK + + if (interface_path.empty()) + return NiRio_Status_ResourceNotFound; + + // close if already open. + // use non-locking _close since we already have the lock + _close(); + + nirio_status status = NiRio_Status_Success; + nirio_status_chain( + nirio_driver_iface::rio_open(interface_path, _device_handle), status); + if (nirio_status_not_fatal(status)) { + nirio_status_chain(nirio_driver_iface::rio_ioctl( + _device_handle, NIRIO_IOCTL_POST_OPEN, NULL, 0, NULL, 0), + status); + nirio_ioctl_packet_t out(&_interface_num, sizeof(_interface_num), 0); + nirio_status_chain( nirio_driver_iface::rio_ioctl( - _device_handle, NIRIO_IOCTL_PRE_CLOSE, NULL, 0, NULL, 0); - nirio_driver_iface::rio_close(_device_handle); - } - } + _device_handle, NIRIO_IOCTL_GET_IFACE_NUM, NULL, 0, &out, sizeof(out)), + status); - nirio_status niriok_proxy_impl_v1::reset() - { - READER_LOCK + if (nirio_status_fatal(status)) + _close(); + } + return status; +} - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; +void niriok_proxy_impl_v1::close(void) +{ + WRITER_LOCK - in.function = NIRIO_FUNC::RESET; + _close(); +} - return sync_operation(&in, sizeof(in), &out, sizeof(out)); +// this protected _close doesn't acquire the lock, so it can be used in methods +// that already have the lock +void niriok_proxy_impl_v1::_close() +{ + if (nirio_driver_iface::rio_isopen(_device_handle)) { + nirio_driver_iface::rio_ioctl( + _device_handle, NIRIO_IOCTL_PRE_CLOSE, NULL, 0, NULL, 0); + nirio_driver_iface::rio_close(_device_handle); } +} - nirio_status niriok_proxy_impl_v1::get_version( - nirio_version_t type, - uint32_t& major, - uint32_t& upgrade, - uint32_t& maintenance, - char& phase, - uint32_t& build) - { - nirio_device_attribute32_t version_attr = (type==CURRENT)?RIO_CURRENT_VERSION:RIO_OLDEST_COMPATIBLE_VERSION; - uint32_t raw_version = 0; - nirio_status status = get_attribute(version_attr, raw_version); - - major = (raw_version & VERSION_MAJOR_MASK) >> VERSION_MAJOR_SHIFT; - upgrade = (raw_version & VERSION_UPGRD_MASK) >> VERSION_UPGRD_SHIFT; - maintenance = (raw_version & VERSION_MAINT_MASK) >> VERSION_MAINT_SHIFT; - build = (raw_version & VERSION_BUILD_MASK) >> VERSION_BUILD_SHIFT; - - uint32_t phase_num = (raw_version & VERSION_PHASE_MASK) >> VERSION_PHASE_SHIFT; - switch (phase_num) { - case 0: phase = 'd'; break; - case 1: phase = 'a'; break; - case 2: phase = 'b'; break; - case 3: phase = 'f'; break; - } +nirio_status niriok_proxy_impl_v1::reset() +{ + READER_LOCK - return status; - } + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status niriok_proxy_impl_v1::sync_operation( - const void *writeBuffer, - size_t writeBufferLength, - void *readBuffer, - size_t readBufferLength) - { - READER_LOCK + in.function = NIRIO_FUNC::RESET; - nirio_ioctl_packet_t out(readBuffer, readBufferLength, 0); - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - NIRIO_IOCTL_SYNCOP, - writeBuffer, writeBufferLength, - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - return out.statusCode; +nirio_status niriok_proxy_impl_v1::get_version(nirio_version_t type, + uint32_t& major, + uint32_t& upgrade, + uint32_t& maintenance, + char& phase, + uint32_t& build) +{ + nirio_device_attribute32_t version_attr = + (type == CURRENT) ? RIO_CURRENT_VERSION : RIO_OLDEST_COMPATIBLE_VERSION; + uint32_t raw_version = 0; + nirio_status status = get_attribute(version_attr, raw_version); + + major = (raw_version & VERSION_MAJOR_MASK) >> VERSION_MAJOR_SHIFT; + upgrade = (raw_version & VERSION_UPGRD_MASK) >> VERSION_UPGRD_SHIFT; + maintenance = (raw_version & VERSION_MAINT_MASK) >> VERSION_MAINT_SHIFT; + build = (raw_version & VERSION_BUILD_MASK) >> VERSION_BUILD_SHIFT; + + uint32_t phase_num = (raw_version & VERSION_PHASE_MASK) >> VERSION_PHASE_SHIFT; + switch (phase_num) { + case 0: + phase = 'd'; + break; + case 1: + phase = 'a'; + break; + case 2: + phase = 'b'; + break; + case 3: + phase = 'f'; + break; } - nirio_status niriok_proxy_impl_v1::get_attribute( - const nirio_device_attribute32_t attribute, - uint32_t& attrValue) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + return status; +} - in.function = NIRIO_FUNC::GET32; - in.params.attribute32.attribute = static_cast <uint32_t> (attribute); +nirio_status niriok_proxy_impl_v1::sync_operation(const void* writeBuffer, + size_t writeBufferLength, + void* readBuffer, + size_t readBufferLength) +{ + READER_LOCK + + nirio_ioctl_packet_t out(readBuffer, readBufferLength, 0); + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, + NIRIO_IOCTL_SYNCOP, + writeBuffer, + writeBufferLength, + &out, + sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + return out.statusCode; +} + +nirio_status niriok_proxy_impl_v1::get_attribute( + const nirio_device_attribute32_t attribute, uint32_t& attrValue) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + in.function = NIRIO_FUNC::GET32; + in.params.attribute32.attribute = static_cast<uint32_t>(attribute); - attrValue = out.params.attribute32.value; - return status; - } + nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - nirio_status niriok_proxy_impl_v1::set_attribute( - const nirio_device_attribute32_t attribute, - const uint32_t value) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + attrValue = out.params.attribute32.value; + return status; +} - in.function = NIRIO_FUNC::SET32; - in.params.attribute32.attribute = static_cast <uint32_t> (attribute); - in.params.attribute32.value = value; +nirio_status niriok_proxy_impl_v1::set_attribute( + const nirio_device_attribute32_t attribute, const uint32_t value) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + in.function = NIRIO_FUNC::SET32; + in.params.attribute32.attribute = static_cast<uint32_t>(attribute); + in.params.attribute32.value = value; - nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint32_t& value) - { - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; +nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint32_t& value) +{ + if (offset % 4 != 0) + return NiRio_Status_MisalignedAccess; - in.function = NIRIO_FUNC::IO; - in.subfunction = NIRIO_IO::PEEK32; - in.params.io.offset = offset; + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - value = out.params.io.value.value32; - return status; - } + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::PEEK32; + in.params.io.offset = offset; - nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint64_t& value) - { - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + value = out.params.io.value.value32; + return status; +} - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; +nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint64_t& value) +{ + if (offset % 8 != 0) + return NiRio_Status_MisalignedAccess; - in.function = NIRIO_FUNC::IO; - in.subfunction = NIRIO_IO::PEEK64; - in.params.io.offset = offset; + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - value = out.params.io.value.value64; - return status; - } - - nirio_status niriok_proxy_impl_v1::poke(uint32_t offset, const uint32_t& value) - { - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::PEEK64; + in.params.io.offset = offset; - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + value = out.params.io.value.value64; + return status; +} - in.function = NIRIO_FUNC::IO; - in.subfunction = NIRIO_IO::POKE32; - in.params.io.offset = offset; - in.params.io.value.value32 = value; +nirio_status niriok_proxy_impl_v1::poke(uint32_t offset, const uint32_t& value) +{ + if (offset % 4 != 0) + return NiRio_Status_MisalignedAccess; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status niriok_proxy_impl_v1::poke(uint32_t offset, const uint64_t& value) - { - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::POKE32; + in.params.io.offset = offset; + in.params.io.value.value32 = value; - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - in.function = NIRIO_FUNC::IO; - in.subfunction = NIRIO_IO::POKE64; - in.params.io.offset = offset; - in.params.io.value.value64 = value; +nirio_status niriok_proxy_impl_v1::poke(uint32_t offset, const uint64_t& value) +{ + if (offset % 8 != 0) + return NiRio_Status_MisalignedAccess; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status niriok_proxy_impl_v1::map_fifo_memory( - uint32_t fifo_instance, - size_t size, - nirio_driver_iface::rio_mmap_t& map) - { - READER_LOCK + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::POKE64; + in.params.io.offset = offset; + in.params.io.value.value64 = value; - return nirio_driver_iface::rio_mmap(_device_handle, - GET_FIFO_MEMORY_TYPE(fifo_instance), - size, true, map); - } + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - nirio_status niriok_proxy_impl_v1::unmap_fifo_memory( - nirio_driver_iface::rio_mmap_t& map) - { - READER_LOCK +nirio_status niriok_proxy_impl_v1::map_fifo_memory( + uint32_t fifo_instance, size_t size, nirio_driver_iface::rio_mmap_t& map) +{ + READER_LOCK - return nirio_driver_iface::rio_munmap(map); - } + return nirio_driver_iface::rio_mmap( + _device_handle, GET_FIFO_MEMORY_TYPE(fifo_instance), size, true, map); +} - nirio_status niriok_proxy_impl_v1::stop_all_fifos() - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; +nirio_status niriok_proxy_impl_v1::unmap_fifo_memory(nirio_driver_iface::rio_mmap_t& map) +{ + READER_LOCK - in.function = NIRIO_FUNC::FIFO_STOP_ALL; + return nirio_driver_iface::rio_munmap(map); +} - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy_impl_v1::add_fifo_resource(const nirio_fifo_info_t& fifo_info) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; - - in.function = NIRIO_FUNC::ADD_RESOURCE; - if (fifo_info.direction == OUTPUT_FIFO) - in.subfunction = NIRIO_RESOURCE::OUTPUT_FIFO; - else - in.subfunction = NIRIO_RESOURCE::INPUT_FIFO; - - in.params.add.fifoWithDataType.channel = fifo_info.channel; - in.params.add.fifoWithDataType.baseAddress = fifo_info.base_addr; - in.params.add.fifoWithDataType.depthInSamples = fifo_info.depth; - in.params.add.fifoWithDataType.scalarType = static_cast <uint32_t> (fifo_info.scalar_type); - in.params.add.fifoWithDataType.bitWidth = fifo_info.bitWidth; - in.params.add.fifoWithDataType.version = fifo_info.version; - //fifo_info.integerWordLength is not needed by the v1 kernel interface - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } +nirio_status niriok_proxy_impl_v1::stop_all_fifos() +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status niriok_proxy_impl_v1::set_device_config() - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + in.function = NIRIO_FUNC::FIFO_STOP_ALL; - in.function = NIRIO_FUNC::SET_DRIVER_CONFIG; - in.subfunction = 0; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } +nirio_status niriok_proxy_impl_v1::add_fifo_resource(const nirio_fifo_info_t& fifo_info) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::ADD_RESOURCE; + if (fifo_info.direction == OUTPUT_FIFO) + in.subfunction = NIRIO_RESOURCE::OUTPUT_FIFO; + else + in.subfunction = NIRIO_RESOURCE::INPUT_FIFO; + + in.params.add.fifoWithDataType.channel = fifo_info.channel; + in.params.add.fifoWithDataType.baseAddress = fifo_info.base_addr; + in.params.add.fifoWithDataType.depthInSamples = fifo_info.depth; + in.params.add.fifoWithDataType.scalarType = + static_cast<uint32_t>(fifo_info.scalar_type); + in.params.add.fifoWithDataType.bitWidth = fifo_info.bitWidth; + in.params.add.fifoWithDataType.version = fifo_info.version; + // fifo_info.integerWordLength is not needed by the v1 kernel interface + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} + +nirio_status niriok_proxy_impl_v1::set_device_config() +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - nirio_status niriok_proxy_impl_v1::start_fifo( - uint32_t channel) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + in.function = NIRIO_FUNC::SET_DRIVER_CONFIG; + in.subfunction = 0; - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::START; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - in.params.fifo.channel = channel; +nirio_status niriok_proxy_impl_v1::start_fifo(uint32_t channel) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::START; - nirio_status niriok_proxy_impl_v1::stop_fifo( - uint32_t channel) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + in.params.fifo.channel = channel; - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::STOP; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - in.params.fifo.channel = channel; +nirio_status niriok_proxy_impl_v1::stop_fifo(uint32_t channel) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::STOP; - nirio_status niriok_proxy_impl_v1::configure_fifo( - uint32_t channel, - uint32_t requested_depth, - uint8_t requires_actuals, - uint32_t& actual_depth, - uint32_t& actual_size) - { - nirio_status status = NiRio_Status_Success; + in.params.fifo.channel = channel; - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::CONFIGURE; +nirio_status niriok_proxy_impl_v1::configure_fifo(uint32_t channel, + uint32_t requested_depth, + uint8_t requires_actuals, + uint32_t& actual_depth, + uint32_t& actual_size) +{ + nirio_status status = NiRio_Status_Success; - in.params.fifo.channel = channel; - in.params.fifo.op.config.requestedDepth = requested_depth; - in.params.fifo.op.config.requiresActuals = requires_actuals; + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; - status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - if (nirio_status_fatal(status)) return status; + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::CONFIGURE; - actual_depth = out.params.fifo.op.config.actualDepth; - actual_size = out.params.fifo.op.config.actualSize; + in.params.fifo.channel = channel; + in.params.fifo.op.config.requestedDepth = requested_depth; + in.params.fifo.op.config.requiresActuals = requires_actuals; + status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(status)) return status; - } - - nirio_status niriok_proxy_impl_v1::wait_on_fifo( - uint32_t channel, - uint32_t elements_requested, - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint8_t output, - void*& data_pointer, - uint32_t& elements_acquired, - uint32_t& elements_remaining) - { - nirio_status status = NiRio_Status_Success; - nirio_syncop_in_params_t in = {}; - uint32_t stuffed[2]; - nirio_syncop_out_params_t out = {}; - init_syncop_out_params(out, stuffed, sizeof(stuffed)); - - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::WAIT; + actual_depth = out.params.fifo.op.config.actualDepth; + actual_size = out.params.fifo.op.config.actualSize; + + return status; +} + +nirio_status niriok_proxy_impl_v1::wait_on_fifo(uint32_t channel, + uint32_t elements_requested, + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint8_t output, + void*& data_pointer, + uint32_t& elements_acquired, + uint32_t& elements_remaining) +{ + nirio_status status = NiRio_Status_Success; - in.params.fifo.channel = channel; - in.params.fifo.op.wait.elementsRequested = elements_requested; - in.params.fifo.op.wait.scalarType = scalar_type; - in.params.fifo.op.wait.bitWidth = bit_width; - in.params.fifo.op.wait.output = output; - in.params.fifo.op.wait.timeout = timeout; + nirio_syncop_in_params_t in = {}; + uint32_t stuffed[2]; + nirio_syncop_out_params_t out = {}; + init_syncop_out_params(out, stuffed, sizeof(stuffed)); - status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - if (nirio_status_fatal(status)) return status; + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::WAIT; - data_pointer = out.params.fifo.op.wait.elements.pointer; - elements_acquired = stuffed[0]; - elements_remaining = stuffed[1]; + in.params.fifo.channel = channel; + in.params.fifo.op.wait.elementsRequested = elements_requested; + in.params.fifo.op.wait.scalarType = scalar_type; + in.params.fifo.op.wait.bitWidth = bit_width; + in.params.fifo.op.wait.output = output; + in.params.fifo.op.wait.timeout = timeout; + status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(status)) return status; - } - - nirio_status niriok_proxy_impl_v1::grant_fifo( - uint32_t channel, - uint32_t elements_to_grant) - { - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; - - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::GRANT; - - in.params.fifo.channel = channel; - in.params.fifo.op.grant.elements = elements_to_grant; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - nirio_status niriok_proxy_impl_v1::read_fifo( - uint32_t channel, - uint32_t elements_to_read, - void* buffer, - uint32_t buffer_datatype_width, - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint32_t& number_read, - uint32_t& number_remaining) - { - nirio_status status = NiRio_Status_Success; + data_pointer = out.params.fifo.op.wait.elements.pointer; + elements_acquired = stuffed[0]; + elements_remaining = stuffed[1]; - nirio_syncop_in_params_t in = {}; - nirio_syncop_out_params_t out = {}; - init_syncop_out_params(out, buffer, elements_to_read * buffer_datatype_width); + return status; +} - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::READ; +nirio_status niriok_proxy_impl_v1::grant_fifo( + uint32_t channel, uint32_t elements_to_grant) +{ + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::GRANT; + + in.params.fifo.channel = channel; + in.params.fifo.op.grant.elements = elements_to_grant; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); +} + +nirio_status niriok_proxy_impl_v1::read_fifo(uint32_t channel, + uint32_t elements_to_read, + void* buffer, + uint32_t buffer_datatype_width, + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint32_t& number_read, + uint32_t& number_remaining) +{ + nirio_status status = NiRio_Status_Success; - in.params.fifo.channel = channel; - in.params.fifo.op.readWithDataType.timeout = timeout; - in.params.fifo.op.readWithDataType.scalarType = scalar_type; - in.params.fifo.op.readWithDataType.bitWidth = bit_width; + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + init_syncop_out_params(out, buffer, elements_to_read * buffer_datatype_width); - status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - if (nirio_status_fatal(status) && (status != NiRio_Status_FifoTimeout)) return status; + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::READ; - number_read = out.params.fifo.op.read.numberRead; - number_remaining = out.params.fifo.op.read.numberRemaining; + in.params.fifo.channel = channel; + in.params.fifo.op.readWithDataType.timeout = timeout; + in.params.fifo.op.readWithDataType.scalarType = scalar_type; + in.params.fifo.op.readWithDataType.bitWidth = bit_width; + status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(status) && (status != NiRio_Status_FifoTimeout)) return status; - } - nirio_status niriok_proxy_impl_v1::write_fifo( - uint32_t channel, - uint32_t elements_to_write, - void* buffer, - uint32_t buffer_datatype_width, - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint32_t& number_remaining) - { - nirio_status status = NiRio_Status_Success; + number_read = out.params.fifo.op.read.numberRead; + number_remaining = out.params.fifo.op.read.numberRemaining; - nirio_syncop_in_params_t in = {}; - init_syncop_in_params(in, buffer, elements_to_write * buffer_datatype_width); - nirio_syncop_out_params_t out = {}; + return status; +} - in.function = NIRIO_FUNC::FIFO; - in.subfunction = NIRIO_FIFO::WRITE; +nirio_status niriok_proxy_impl_v1::write_fifo(uint32_t channel, + uint32_t elements_to_write, + void* buffer, + uint32_t buffer_datatype_width, + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint32_t& number_remaining) +{ + nirio_status status = NiRio_Status_Success; - in.params.fifo.channel = channel; - in.params.fifo.op.writeWithDataType.timeout = timeout; - in.params.fifo.op.writeWithDataType.scalarType = scalar_type; - in.params.fifo.op.writeWithDataType.bitWidth = bit_width; + nirio_syncop_in_params_t in = {}; + init_syncop_in_params(in, buffer, elements_to_write * buffer_datatype_width); + nirio_syncop_out_params_t out = {}; - status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - if (nirio_status_fatal(status) && (status != NiRio_Status_FifoTimeout)) return status; + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::WRITE; - number_remaining = out.params.fifo.op.write.numberRemaining; + in.params.fifo.channel = channel; + in.params.fifo.op.writeWithDataType.timeout = timeout; + in.params.fifo.op.writeWithDataType.scalarType = scalar_type; + in.params.fifo.op.writeWithDataType.bitWidth = bit_width; + status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(status) && (status != NiRio_Status_FifoTimeout)) return status; - } -}} + number_remaining = out.params.fifo.op.write.numberRemaining; + + return status; +} + +}} // namespace uhd::niusrprio #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp b/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp index 7e442eef1..cbc264dfc 100644 --- a/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp +++ b/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp @@ -11,871 +11,840 @@ // "push" and "pop" introduced in GCC 4.6; works with all clang #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic push +# pragma GCC diagnostic push #endif #if defined(__clang__) || defined(__GNUC__) - #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif -#define IOCTL_TRANSPORT_GET32 IOCTL(0, 0, IOCTL_ACCESS_READ) -#define IOCTL_TRANSPORT_SET32 IOCTL(0, 1, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_GET_STRING IOCTL(0, 2, IOCTL_ACCESS_READ) -#define IOCTL_TRANSPORT_SET_STRING IOCTL(0, 3, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_RESET IOCTL(1, 1, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE IOCTL(2, 0, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE IOCTL(2, 1, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_SET_DEVICE_CONFIG IOCTL(2, 3, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_FIFO_CONFIG IOCTL(4, 0, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_FIFO_START IOCTL(4, 1, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_FIFO_STOP IOCTL(4, 2, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_FIFO_READ IOCTL(4, 3, IOCTL_ACCESS_READ) -#define IOCTL_TRANSPORT_FIFO_WRITE IOCTL(4, 4, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_FIFO_WAIT IOCTL(4, 5, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_FIFO_GRANT IOCTL(4, 6, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_FIFO_STOP_ALL IOCTL(4, 7, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_PEEK64 IOCTL(5, 2, IOCTL_ACCESS_READ) -#define IOCTL_TRANSPORT_PEEK32 IOCTL(5, 3, IOCTL_ACCESS_READ) -#define IOCTL_TRANSPORT_POKE64 IOCTL(5, 6, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_POKE32 IOCTL(5, 7, IOCTL_ACCESS_WRITE) -#define IOCTL_TRANSPORT_POST_OPEN IOCTL(8, 0, IOCTL_ACCESS_ANY) -#define IOCTL_TRANSPORT_PRE_CLOSE IOCTL(8, 1, IOCTL_ACCESS_ANY) - -namespace uhd { namespace niusrprio -{ - //------------------------------------------------------- - // ioctl param typedefs - //------------------------------------------------------- - typedef struct { - nirio_scalar_type_t scalarType; - nirio_u32_t bitWidth; - nirio_i32_t integerWordLength; - } nirio_fifo_data_type_t; - - typedef struct in_transport_get32 - { - nirio_device_attribute32_t attribute; - int32_t status; - } in_transport_get32_t; - typedef struct out_transport_get32 - { - uint32_t retVal__; - int32_t status; - } out_transport_get32_t; - typedef struct in_transport_set32 - { - nirio_device_attribute32_t attribute; - uint32_t value; - int32_t status; - } in_transport_set32_t; - typedef struct out_transport_set32 - { - int32_t status; - } out_transport_set32_t; - typedef struct out_transport_get_string - { - uint32_t stringLen; - int32_t status; - } out_transport_get_string_t; - typedef struct out_transport_set_string - { - int32_t status; - } out_transport_set_string_t; - typedef struct in_transport_reset - { - int32_t status; - } in_transport_reset_t; - typedef struct out_transport_reset - { - int32_t status; - } out_transport_reset_t; - typedef struct in_transport_add_input_fifo_resource - { - uint32_t channel; - uint32_t baseAddress; - uint32_t depthInSamples; - nirio_fifo_data_type_t dataType; - uint32_t version; - int32_t status; - } in_transport_add_input_fifo_resource_t; - typedef struct out_transport_addInputFifo_resource - { - int32_t status; - } out_transport_add_input_fifo_resource_t; - typedef struct in_transport_addOutputFifo_resource - { - uint32_t channel; - uint32_t baseAddress; - uint32_t depthInSamples; - nirio_fifo_data_type_t dataType; - uint32_t version; - int32_t status; - } in_transport_add_output_fifo_resource_t; - typedef struct out_transport_addOutputFifo_resource - { - int32_t status; - } out_transport_add_output_fifo_resource_t; - typedef struct in_transport_setDevice_config - { - uint32_t attribute; - int32_t status; - } in_transport_set_device_config_t; - typedef struct out_transport_setDevice_config - { - int32_t status; - } out_transport_set_device_config_t; - typedef struct in_transport_fifo_config - { - uint32_t channel; - aligned_uint64_t requestedDepth; - int32_t status; - } in_transport_fifo_config_t; - typedef struct out_transport_fifo_config - { - aligned_uint64_t actualDepth; - aligned_uint64_t actualSize; - int32_t status; - } out_transport_fifo_config_t; - typedef struct in_transport_fifo_start - { - uint32_t channel; - int32_t status; - } in_transport_fifo_start_t; - typedef struct out_transport_fifo_start - { - int32_t status; - } out_transport_fifo_start_t; - typedef struct in_transport_fifo_stop - { - uint32_t channel; - int32_t status; - } in_transport_fifo_stop_t; - typedef struct out_transport_fifo_stop - { - int32_t status; - } out_transport_fifo_stop_t; - typedef struct in_transport_fifo_read - { - uint32_t channel; - aligned_uint64_t buf; - uint32_t numberElements; - nirio_fifo_data_type_t dataType; - uint32_t timeout; - int32_t status; - } in_transport_fifo_read_t; - typedef struct out_transport_fifo_read - { - uint32_t read; - uint32_t remaining; - int32_t status; - } out_transport_fifo_read_t; - typedef struct in_transport_fifo_write - { - uint32_t channel; - aligned_uint64_t buf; - uint32_t numberElements; - nirio_fifo_data_type_t dataType; - uint32_t timeout; - int32_t status; - } in_transport_fifo_write_t; - typedef struct out_transport_fifo_write - { - uint32_t remaining; - int32_t status; - } out_transport_fifo_write_t; - typedef struct in_transport_fifo_wait - { - uint32_t channel; - aligned_uint64_t elementsRequested; - nirio_fifo_data_type_t dataType; - bool output; - uint32_t timeout; - int32_t status; - } in_transport_fifo_wait_t; - typedef struct out_transport_fifo_wait - { - aligned_uint64_t elements; - aligned_uint64_t elementsAcquired; - aligned_uint64_t elementsRemaining; - int32_t status; - } out_transport_fifo_wait_t; - typedef struct in_transport_fifo_grant - { - uint32_t channel; - aligned_uint64_t elements; - int32_t status; - } in_transport_fifo_grant_t; - typedef struct out_transport_fifo_grant - { - int32_t status; - } out_transport_fifo_grant_t; - typedef struct in_transport_fifoStop_all - { - int32_t status; - } in_transport_fifo_stop_all_t; - typedef struct out_transport_fifoStop_all - { - int32_t status; - } out_transport_fifo_stop_all_t; - typedef struct in_transport_peek64 - { - uint32_t offset; - int32_t status; - } in_transport_peek64_t; - typedef struct out_transport_peek64 - { - aligned_uint64_t retVal__; - int32_t status; - } out_transport_peek64_t; - typedef struct in_transport_peek32 - { - uint32_t offset; - int32_t status; - } in_transport_peek32_t; - typedef struct out_transport_peek32 - { - uint32_t retVal__; - int32_t status; - } out_transport_peek32_t; - typedef struct in_transport_poke64 - { - uint32_t offset; - aligned_uint64_t value; - int32_t status; - } in_transport_poke64_t; - typedef struct out_transport_poke64 - { - int32_t status; - } out_transport_poke64_t; - typedef struct in_transport_poke32 - { - uint32_t offset; - uint32_t value; - int32_t status; - } in_transport_poke32_t; - typedef struct out_transport_poke32 - { - int32_t status; - } out_transport_poke32_t; - typedef struct in_transport_post_open - { - int32_t status; - } in_transport_post_open_t; - typedef struct out_transport_post_open - { - int32_t status; - } out_transport_post_open_t; - typedef struct in_transport_pre_close - { - int32_t status; - } in_transport_pre_close_t; - typedef struct out_transport_pre_close - { - int32_t status; - } out_transport_pre_close_t; - - //------------------------------------------------------- - // niriok_proxy_impl_v2 - //------------------------------------------------------- - niriok_proxy_impl_v2::niriok_proxy_impl_v2() - { - } +#define IOCTL_TRANSPORT_GET32 IOCTL(0, 0, IOCTL_ACCESS_READ) +#define IOCTL_TRANSPORT_SET32 IOCTL(0, 1, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_GET_STRING IOCTL(0, 2, IOCTL_ACCESS_READ) +#define IOCTL_TRANSPORT_SET_STRING IOCTL(0, 3, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_RESET IOCTL(1, 1, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE IOCTL(2, 0, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE IOCTL(2, 1, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_SET_DEVICE_CONFIG IOCTL(2, 3, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_FIFO_CONFIG IOCTL(4, 0, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_FIFO_START IOCTL(4, 1, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_FIFO_STOP IOCTL(4, 2, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_FIFO_READ IOCTL(4, 3, IOCTL_ACCESS_READ) +#define IOCTL_TRANSPORT_FIFO_WRITE IOCTL(4, 4, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_FIFO_WAIT IOCTL(4, 5, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_FIFO_GRANT IOCTL(4, 6, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_FIFO_STOP_ALL IOCTL(4, 7, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_PEEK64 IOCTL(5, 2, IOCTL_ACCESS_READ) +#define IOCTL_TRANSPORT_PEEK32 IOCTL(5, 3, IOCTL_ACCESS_READ) +#define IOCTL_TRANSPORT_POKE64 IOCTL(5, 6, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_POKE32 IOCTL(5, 7, IOCTL_ACCESS_WRITE) +#define IOCTL_TRANSPORT_POST_OPEN IOCTL(8, 0, IOCTL_ACCESS_ANY) +#define IOCTL_TRANSPORT_PRE_CLOSE IOCTL(8, 1, IOCTL_ACCESS_ANY) + +namespace uhd { namespace niusrprio { +//------------------------------------------------------- +// ioctl param typedefs +//------------------------------------------------------- +typedef struct +{ + nirio_scalar_type_t scalarType; + nirio_u32_t bitWidth; + nirio_i32_t integerWordLength; +} nirio_fifo_data_type_t; - niriok_proxy_impl_v2::~niriok_proxy_impl_v2() - { - close(); - } +typedef struct in_transport_get32 +{ + nirio_device_attribute32_t attribute; + int32_t status; +} in_transport_get32_t; +typedef struct out_transport_get32 +{ + uint32_t retVal__; + int32_t status; +} out_transport_get32_t; +typedef struct in_transport_set32 +{ + nirio_device_attribute32_t attribute; + uint32_t value; + int32_t status; +} in_transport_set32_t; +typedef struct out_transport_set32 +{ + int32_t status; +} out_transport_set32_t; +typedef struct out_transport_get_string +{ + uint32_t stringLen; + int32_t status; +} out_transport_get_string_t; +typedef struct out_transport_set_string +{ + int32_t status; +} out_transport_set_string_t; +typedef struct in_transport_reset +{ + int32_t status; +} in_transport_reset_t; +typedef struct out_transport_reset +{ + int32_t status; +} out_transport_reset_t; +typedef struct in_transport_add_input_fifo_resource +{ + uint32_t channel; + uint32_t baseAddress; + uint32_t depthInSamples; + nirio_fifo_data_type_t dataType; + uint32_t version; + int32_t status; +} in_transport_add_input_fifo_resource_t; +typedef struct out_transport_addInputFifo_resource +{ + int32_t status; +} out_transport_add_input_fifo_resource_t; +typedef struct in_transport_addOutputFifo_resource +{ + uint32_t channel; + uint32_t baseAddress; + uint32_t depthInSamples; + nirio_fifo_data_type_t dataType; + uint32_t version; + int32_t status; +} in_transport_add_output_fifo_resource_t; +typedef struct out_transport_addOutputFifo_resource +{ + int32_t status; +} out_transport_add_output_fifo_resource_t; +typedef struct in_transport_setDevice_config +{ + uint32_t attribute; + int32_t status; +} in_transport_set_device_config_t; +typedef struct out_transport_setDevice_config +{ + int32_t status; +} out_transport_set_device_config_t; +typedef struct in_transport_fifo_config +{ + uint32_t channel; + aligned_uint64_t requestedDepth; + int32_t status; +} in_transport_fifo_config_t; +typedef struct out_transport_fifo_config +{ + aligned_uint64_t actualDepth; + aligned_uint64_t actualSize; + int32_t status; +} out_transport_fifo_config_t; +typedef struct in_transport_fifo_start +{ + uint32_t channel; + int32_t status; +} in_transport_fifo_start_t; +typedef struct out_transport_fifo_start +{ + int32_t status; +} out_transport_fifo_start_t; +typedef struct in_transport_fifo_stop +{ + uint32_t channel; + int32_t status; +} in_transport_fifo_stop_t; +typedef struct out_transport_fifo_stop +{ + int32_t status; +} out_transport_fifo_stop_t; +typedef struct in_transport_fifo_read +{ + uint32_t channel; + aligned_uint64_t buf; + uint32_t numberElements; + nirio_fifo_data_type_t dataType; + uint32_t timeout; + int32_t status; +} in_transport_fifo_read_t; +typedef struct out_transport_fifo_read +{ + uint32_t read; + uint32_t remaining; + int32_t status; +} out_transport_fifo_read_t; +typedef struct in_transport_fifo_write +{ + uint32_t channel; + aligned_uint64_t buf; + uint32_t numberElements; + nirio_fifo_data_type_t dataType; + uint32_t timeout; + int32_t status; +} in_transport_fifo_write_t; +typedef struct out_transport_fifo_write +{ + uint32_t remaining; + int32_t status; +} out_transport_fifo_write_t; +typedef struct in_transport_fifo_wait +{ + uint32_t channel; + aligned_uint64_t elementsRequested; + nirio_fifo_data_type_t dataType; + bool output; + uint32_t timeout; + int32_t status; +} in_transport_fifo_wait_t; +typedef struct out_transport_fifo_wait +{ + aligned_uint64_t elements; + aligned_uint64_t elementsAcquired; + aligned_uint64_t elementsRemaining; + int32_t status; +} out_transport_fifo_wait_t; +typedef struct in_transport_fifo_grant +{ + uint32_t channel; + aligned_uint64_t elements; + int32_t status; +} in_transport_fifo_grant_t; +typedef struct out_transport_fifo_grant +{ + int32_t status; +} out_transport_fifo_grant_t; +typedef struct in_transport_fifoStop_all +{ + int32_t status; +} in_transport_fifo_stop_all_t; +typedef struct out_transport_fifoStop_all +{ + int32_t status; +} out_transport_fifo_stop_all_t; +typedef struct in_transport_peek64 +{ + uint32_t offset; + int32_t status; +} in_transport_peek64_t; +typedef struct out_transport_peek64 +{ + aligned_uint64_t retVal__; + int32_t status; +} out_transport_peek64_t; +typedef struct in_transport_peek32 +{ + uint32_t offset; + int32_t status; +} in_transport_peek32_t; +typedef struct out_transport_peek32 +{ + uint32_t retVal__; + int32_t status; +} out_transport_peek32_t; +typedef struct in_transport_poke64 +{ + uint32_t offset; + aligned_uint64_t value; + int32_t status; +} in_transport_poke64_t; +typedef struct out_transport_poke64 +{ + int32_t status; +} out_transport_poke64_t; +typedef struct in_transport_poke32 +{ + uint32_t offset; + uint32_t value; + int32_t status; +} in_transport_poke32_t; +typedef struct out_transport_poke32 +{ + int32_t status; +} out_transport_poke32_t; +typedef struct in_transport_post_open +{ + int32_t status; +} in_transport_post_open_t; +typedef struct out_transport_post_open +{ + int32_t status; +} out_transport_post_open_t; +typedef struct in_transport_pre_close +{ + int32_t status; +} in_transport_pre_close_t; +typedef struct out_transport_pre_close +{ + int32_t status; +} out_transport_pre_close_t; - nirio_status niriok_proxy_impl_v2::open(const std::string& interface_path) - { - WRITER_LOCK +//------------------------------------------------------- +// niriok_proxy_impl_v2 +//------------------------------------------------------- +niriok_proxy_impl_v2::niriok_proxy_impl_v2() {} - if (interface_path.empty()) return NiRio_Status_ResourceNotFound; +niriok_proxy_impl_v2::~niriok_proxy_impl_v2() +{ + close(); +} - //close if already open. - // use non-locking _close since we already have the lock - _close(); +nirio_status niriok_proxy_impl_v2::open(const std::string& interface_path) +{ + WRITER_LOCK + + if (interface_path.empty()) + return NiRio_Status_ResourceNotFound; + + // close if already open. + // use non-locking _close since we already have the lock + _close(); + + in_transport_post_open_t in = {}; + out_transport_post_open_t out = {}; + + in.status = NiRio_Status_Success; + + nirio_status status = NiRio_Status_Success; + nirio_status_chain( + nirio_driver_iface::rio_open(interface_path, _device_handle), status); + if (nirio_status_not_fatal(status)) { + nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle, + IOCTL_TRANSPORT_POST_OPEN, + &in, + sizeof(in), + &out, + sizeof(out)), + status); + if (nirio_status_fatal(status)) + _close(); + } + return status; +} - in_transport_post_open_t in = {}; - out_transport_post_open_t out = {}; +void niriok_proxy_impl_v2::close(void) +{ + WRITER_LOCK - in.status = NiRio_Status_Success; + _close(); +} - nirio_status status = NiRio_Status_Success; - nirio_status_chain(nirio_driver_iface::rio_open( - interface_path, _device_handle), status); - if (nirio_status_not_fatal(status)) - { - nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_POST_OPEN, - &in, sizeof(in), &out, sizeof(out)), status); - if (nirio_status_fatal(status)) _close(); - } - return status; - } +// this protected _close doesn't acquire the lock, so it can be used in methods +// that already have the lock +void niriok_proxy_impl_v2::_close() +{ + if (nirio_driver_iface::rio_isopen(_device_handle)) { + in_transport_pre_close_t in = {}; + out_transport_pre_close_t out = {}; - void niriok_proxy_impl_v2::close(void) - { - WRITER_LOCK + in.status = NiRio_Status_Success; - _close(); + nirio_driver_iface::rio_ioctl(_device_handle, + IOCTL_TRANSPORT_PRE_CLOSE, + &in, + sizeof(in), + &out, + sizeof(out)); + nirio_driver_iface::rio_close(_device_handle); } +} - // this protected _close doesn't acquire the lock, so it can be used in methods - // that already have the lock - void niriok_proxy_impl_v2::_close() - { - if(nirio_driver_iface::rio_isopen(_device_handle)) - { - in_transport_pre_close_t in = {}; - out_transport_pre_close_t out = {}; - - in.status = NiRio_Status_Success; - - nirio_driver_iface::rio_ioctl( - _device_handle, IOCTL_TRANSPORT_PRE_CLOSE, &in, sizeof(in), &out, sizeof(out)); - nirio_driver_iface::rio_close(_device_handle); - } - } +nirio_status niriok_proxy_impl_v2::reset() +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::reset() - { - READER_LOCK + in_transport_reset_t in = {}; + out_transport_reset_t out = {}; - in_transport_reset_t in = {}; - out_transport_reset_t out = {}; + in.status = NiRio_Status_Success; - in.status = NiRio_Status_Success; + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_RESET, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_RESET, - &in, sizeof(in), &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + return out.status; +} - return out.status; +nirio_status niriok_proxy_impl_v2::get_version(nirio_version_t type, + uint32_t& major, + uint32_t& upgrade, + uint32_t& maintenance, + char& phase, + uint32_t& build) +{ + nirio_device_attribute32_t version_attr = + (type == CURRENT) ? RIO_CURRENT_VERSION : RIO_OLDEST_COMPATIBLE_VERSION; + uint32_t raw_version = 0; + nirio_status status = get_attribute(version_attr, raw_version); + + major = (raw_version & VERSION_MAJOR_MASK) >> VERSION_MAJOR_SHIFT; + upgrade = (raw_version & VERSION_UPGRD_MASK) >> VERSION_UPGRD_SHIFT; + maintenance = (raw_version & VERSION_MAINT_MASK) >> VERSION_MAINT_SHIFT; + build = (raw_version & VERSION_BUILD_MASK) >> VERSION_BUILD_SHIFT; + + uint32_t phase_num = (raw_version & VERSION_PHASE_MASK) >> VERSION_PHASE_SHIFT; + switch (phase_num) { + case 0: + phase = 'd'; + break; + case 1: + phase = 'a'; + break; + case 2: + phase = 'b'; + break; + case 3: + phase = 'f'; + break; } - nirio_status niriok_proxy_impl_v2::get_version( - nirio_version_t type, - uint32_t& major, - uint32_t& upgrade, - uint32_t& maintenance, - char& phase, - uint32_t& build) - { - nirio_device_attribute32_t version_attr = (type==CURRENT)?RIO_CURRENT_VERSION:RIO_OLDEST_COMPATIBLE_VERSION; - uint32_t raw_version = 0; - nirio_status status = get_attribute(version_attr, raw_version); - - major = (raw_version & VERSION_MAJOR_MASK) >> VERSION_MAJOR_SHIFT; - upgrade = (raw_version & VERSION_UPGRD_MASK) >> VERSION_UPGRD_SHIFT; - maintenance = (raw_version & VERSION_MAINT_MASK) >> VERSION_MAINT_SHIFT; - build = (raw_version & VERSION_BUILD_MASK) >> VERSION_BUILD_SHIFT; - - uint32_t phase_num = (raw_version & VERSION_PHASE_MASK) >> VERSION_PHASE_SHIFT; - switch (phase_num) { - case 0: phase = 'd'; break; - case 1: phase = 'a'; break; - case 2: phase = 'b'; break; - case 3: phase = 'f'; break; - } + return status; +} - return status; - } +nirio_status niriok_proxy_impl_v2::get_attribute( + const nirio_device_attribute32_t attribute, uint32_t& attrValue) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::get_attribute( - const nirio_device_attribute32_t attribute, - uint32_t& attrValue) - { - READER_LOCK + in_transport_get32_t in = {}; + out_transport_get32_t out = {}; - in_transport_get32_t in = {}; - out_transport_get32_t out = {}; + in.attribute = attribute; + in.status = NiRio_Status_Success; - in.attribute = attribute; - in.status = NiRio_Status_Success; + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_GET32, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_GET32, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + attrValue = out.retVal__; - attrValue = out.retVal__; + return out.status; +} - return out.status; - } +nirio_status niriok_proxy_impl_v2::set_attribute( + const nirio_device_attribute32_t attribute, const uint32_t value) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::set_attribute( - const nirio_device_attribute32_t attribute, - const uint32_t value) - { - READER_LOCK + in_transport_set32_t in = {}; + out_transport_set32_t out = {}; - in_transport_set32_t in = {}; - out_transport_set32_t out = {}; + in.attribute = attribute; + in.value = value; + in.status = NiRio_Status_Success; - in.attribute = attribute; - in.value = value; - in.status = NiRio_Status_Success; + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_SET32, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_SET32, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + return out.status; +} - return out.status; - } +nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint32_t& value) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint32_t& value) - { - READER_LOCK + if (offset % 4 != 0) + return NiRio_Status_MisalignedAccess; - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; - - in_transport_peek32_t in = {}; - out_transport_peek32_t out = {}; - - in.offset = offset; - in.status = NiRio_Status_Success; + in_transport_peek32_t in = {}; + out_transport_peek32_t out = {}; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_PEEK32, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + in.offset = offset; + in.status = NiRio_Status_Success; - value = out.retVal__; + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_PEEK32, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - return out.status; - } + value = out.retVal__; - nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint64_t& value) - { - READER_LOCK + return out.status; +} - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; - in_transport_peek64_t in = {}; - out_transport_peek64_t out = {}; +nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint64_t& value) +{ + READER_LOCK - in.offset = offset; - in.status = NiRio_Status_Success; + if (offset % 8 != 0) + return NiRio_Status_MisalignedAccess; + in_transport_peek64_t in = {}; + out_transport_peek64_t out = {}; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_PEEK64, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + in.offset = offset; + in.status = NiRio_Status_Success; - value = out.retVal__; + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_PEEK64, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - return out.status; - } + value = out.retVal__; - nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint32_t& value) - { - READER_LOCK + return out.status; +} - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; +nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint32_t& value) +{ + READER_LOCK - in_transport_poke32_t in = {}; - out_transport_poke32_t out = {}; + if (offset % 4 != 0) + return NiRio_Status_MisalignedAccess; - in.offset = offset; - in.value = value; - in.status = NiRio_Status_Success; + in_transport_poke32_t in = {}; + out_transport_poke32_t out = {}; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_POKE32, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + in.offset = offset; + in.value = value; + in.status = NiRio_Status_Success; - return out.status; - } + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_POKE32, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint64_t& value) - { - READER_LOCK + return out.status; +} - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; +nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint64_t& value) +{ + READER_LOCK - in_transport_poke64_t in = {}; - out_transport_poke64_t out = {}; + if (offset % 8 != 0) + return NiRio_Status_MisalignedAccess; - in.offset = offset; - in.value = value; - in.status = NiRio_Status_Success; + in_transport_poke64_t in = {}; + out_transport_poke64_t out = {}; - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_POKE64, - &in, sizeof(in), - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; + in.offset = offset; + in.value = value; + in.status = NiRio_Status_Success; - return out.status; - } + nirio_status ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_POKE64, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - nirio_status niriok_proxy_impl_v2::map_fifo_memory( - uint32_t fifo_instance, - size_t size, - nirio_driver_iface::rio_mmap_t& map) - { - READER_LOCK + return out.status; +} - return nirio_driver_iface::rio_mmap(_device_handle, - GET_FIFO_MEMORY_TYPE(fifo_instance), - size, true, map); - } +nirio_status niriok_proxy_impl_v2::map_fifo_memory( + uint32_t fifo_instance, size_t size, nirio_driver_iface::rio_mmap_t& map) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::unmap_fifo_memory( - nirio_driver_iface::rio_mmap_t& map) - { - READER_LOCK + return nirio_driver_iface::rio_mmap( + _device_handle, GET_FIFO_MEMORY_TYPE(fifo_instance), size, true, map); +} - return nirio_driver_iface::rio_munmap(map); - } +nirio_status niriok_proxy_impl_v2::unmap_fifo_memory(nirio_driver_iface::rio_mmap_t& map) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::stop_all_fifos() - { - READER_LOCK + return nirio_driver_iface::rio_munmap(map); +} - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_stop_all_t in = {}; - out_transport_fifo_stop_all_t out = {}; +nirio_status niriok_proxy_impl_v2::stop_all_fifos() +{ + READER_LOCK - in.status = NiRio_Status_Success; + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_stop_all_t in = {}; + out_transport_fifo_stop_all_t out = {}; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_STOP_ALL, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - return out.status; - } + in.status = NiRio_Status_Success; - nirio_status niriok_proxy_impl_v2::add_fifo_resource(const nirio_fifo_info_t& fifo_info) - { - READER_LOCK + ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, + IOCTL_TRANSPORT_FIFO_STOP_ALL, + &in, + sizeof(in), + &out, + sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + return out.status; +} + +nirio_status niriok_proxy_impl_v2::add_fifo_resource(const nirio_fifo_info_t& fifo_info) +{ + READER_LOCK - nirio_status status = NiRio_Status_Success; - nirio_status ioctl_status = NiRio_Status_Success; + nirio_status status = NiRio_Status_Success; + nirio_status ioctl_status = NiRio_Status_Success; - switch(fifo_info.direction) - { - case INPUT_FIFO: - { - in_transport_add_input_fifo_resource_t in = {}; + switch (fifo_info.direction) { + case INPUT_FIFO: { + in_transport_add_input_fifo_resource_t in = {}; out_transport_add_input_fifo_resource_t out = {}; - in.channel = fifo_info.channel; - in.baseAddress = fifo_info.base_addr; - in.depthInSamples = fifo_info.depth; - in.dataType.scalarType = fifo_info.scalar_type; - in.dataType.bitWidth = fifo_info.bitWidth; - in.dataType.integerWordLength = fifo_info.integerWordLength; - in.version = fifo_info.version; - in.status = NiRio_Status_Success; + in.channel = fifo_info.channel; + in.baseAddress = fifo_info.base_addr; + in.depthInSamples = fifo_info.depth; + in.dataType.scalarType = fifo_info.scalar_type; + in.dataType.bitWidth = fifo_info.bitWidth; + in.dataType.integerWordLength = fifo_info.integerWordLength; + in.version = fifo_info.version; + in.status = NiRio_Status_Success; ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE, - &in, sizeof(in), - &out, sizeof(out)); + IOCTL_TRANSPORT_ADD_INPUT_FIFO_RESOURCE, + &in, + sizeof(in), + &out, + sizeof(out)); status = nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; break; - } - case OUTPUT_FIFO: - { - in_transport_add_output_fifo_resource_t in = {}; + } + case OUTPUT_FIFO: { + in_transport_add_output_fifo_resource_t in = {}; out_transport_add_output_fifo_resource_t out = {}; - in.channel = fifo_info.channel; - in.baseAddress = fifo_info.base_addr; - in.depthInSamples = fifo_info.depth; - in.dataType.scalarType = fifo_info.scalar_type; - in.dataType.bitWidth = fifo_info.bitWidth; + in.channel = fifo_info.channel; + in.baseAddress = fifo_info.base_addr; + in.depthInSamples = fifo_info.depth; + in.dataType.scalarType = fifo_info.scalar_type; + in.dataType.bitWidth = fifo_info.bitWidth; in.dataType.integerWordLength = fifo_info.integerWordLength; - in.version = fifo_info.version; - in.status = NiRio_Status_Success; - + in.version = fifo_info.version; + in.status = NiRio_Status_Success; + ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE, - &in, sizeof(in), - &out, sizeof(out)); + IOCTL_TRANSPORT_ADD_OUTPUT_FIFO_RESOURCE, + &in, + sizeof(in), + &out, + sizeof(out)); status = nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; break; - } - default: + } + default: status = NiRio_Status_SoftwareFault; - } - - return status; } - nirio_status niriok_proxy_impl_v2::set_device_config() - { - READER_LOCK - - nirio_status ioctl_status = NiRio_Status_Success; - - in_transport_set_device_config_t in = {}; - out_transport_set_device_config_t out = {}; - - in.attribute = 0; //this is unused in the kernel - in.status = NiRio_Status_Success; - - ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - IOCTL_TRANSPORT_SET_DEVICE_CONFIG, - &in, sizeof(in), - &out, sizeof(out)); + return status; +} - return nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; - } +nirio_status niriok_proxy_impl_v2::set_device_config() +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::start_fifo( - uint32_t channel) - { - READER_LOCK + nirio_status ioctl_status = NiRio_Status_Success; - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_start_t in = {}; - out_transport_fifo_start_t out = {}; + in_transport_set_device_config_t in = {}; + out_transport_set_device_config_t out = {}; - in.channel = channel; - in.status = NiRio_Status_Success; + in.attribute = 0; // this is unused in the kernel + in.status = NiRio_Status_Success; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_START, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - return out.status; - } + ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, + IOCTL_TRANSPORT_SET_DEVICE_CONFIG, + &in, + sizeof(in), + &out, + sizeof(out)); - nirio_status niriok_proxy_impl_v2::stop_fifo( - uint32_t channel) - { - READER_LOCK + return nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; +} - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_stop_t in = {}; - out_transport_fifo_stop_t out = {}; +nirio_status niriok_proxy_impl_v2::start_fifo(uint32_t channel) +{ + READER_LOCK - in.channel = channel; - in.status = NiRio_Status_Success; + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_start_t in = {}; + out_transport_fifo_start_t out = {}; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_STOP, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - return out.status; - } + in.channel = channel; + in.status = NiRio_Status_Success; - nirio_status niriok_proxy_impl_v2::configure_fifo( - uint32_t channel, - uint32_t requested_depth, - uint8_t /*requires_actuals*/, //Unused - uint32_t& actual_depth, - uint32_t& actual_size) - { - READER_LOCK - - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_config_t in = {}; - out_transport_fifo_config_t out = {}; - - in.channel = channel; - in.requestedDepth = requested_depth; - in.status = NiRio_Status_Success; + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_START, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_CONFIG, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - UHD_ASSERT_THROW(out.actualDepth <= std::numeric_limits<uint32_t>::max()); - actual_depth = static_cast<uint32_t>(out.actualDepth); - UHD_ASSERT_THROW(out.actualSize <= std::numeric_limits<uint32_t>::max()); - actual_size = static_cast<uint32_t>(out.actualSize); - return out.status; - } + return out.status; +} - nirio_status niriok_proxy_impl_v2::wait_on_fifo( - uint32_t channel, - uint32_t elements_requested, - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint8_t output, - void*& data_pointer, - uint32_t& elements_acquired, - uint32_t& elements_remaining) - { - READER_LOCK - - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_wait_t in = {}; - out_transport_fifo_wait_t out = {}; - - in.channel = channel; - in.elementsRequested = elements_requested; - in.dataType.scalarType = map_int_to_scalar_type(scalar_type); - in.dataType.bitWidth = bit_width; - in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported - in.output = (output != 0); - in.timeout = timeout; - in.status = NiRio_Status_Success; +nirio_status niriok_proxy_impl_v2::stop_fifo(uint32_t channel) +{ + READER_LOCK - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_WAIT, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - data_pointer = reinterpret_cast<void*>(out.elements); - UHD_ASSERT_THROW(out.elementsAcquired <= std::numeric_limits<uint32_t>::max()); - elements_acquired = static_cast<uint32_t>(out.elementsAcquired); - UHD_ASSERT_THROW(out.elementsRemaining <= std::numeric_limits<uint32_t>::max()); - elements_remaining = static_cast<uint32_t>(out.elementsRemaining); - return out.status; - } + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_stop_t in = {}; + out_transport_fifo_stop_t out = {}; - nirio_status niriok_proxy_impl_v2::grant_fifo( - uint32_t channel, - uint32_t elements_to_grant) - { - READER_LOCK + in.channel = channel; + in.status = NiRio_Status_Success; - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_grant_t in = {}; - out_transport_fifo_grant_t out = {}; + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_STOP, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - in.channel = channel; - in.elements = elements_to_grant; - in.status = NiRio_Status_Success; + return out.status; +} - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_GRANT, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - return out.status; - } +nirio_status niriok_proxy_impl_v2::configure_fifo(uint32_t channel, + uint32_t requested_depth, + uint8_t /*requires_actuals*/, // Unused + uint32_t& actual_depth, + uint32_t& actual_size) +{ + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_config_t in = {}; + out_transport_fifo_config_t out = {}; + + in.channel = channel; + in.requestedDepth = requested_depth; + in.status = NiRio_Status_Success; + + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_CONFIG, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + UHD_ASSERT_THROW(out.actualDepth <= std::numeric_limits<uint32_t>::max()); + actual_depth = static_cast<uint32_t>(out.actualDepth); + UHD_ASSERT_THROW(out.actualSize <= std::numeric_limits<uint32_t>::max()); + actual_size = static_cast<uint32_t>(out.actualSize); + return out.status; +} + +nirio_status niriok_proxy_impl_v2::wait_on_fifo(uint32_t channel, + uint32_t elements_requested, + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint8_t output, + void*& data_pointer, + uint32_t& elements_acquired, + uint32_t& elements_remaining) +{ + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_wait_t in = {}; + out_transport_fifo_wait_t out = {}; + + in.channel = channel; + in.elementsRequested = elements_requested; + in.dataType.scalarType = map_int_to_scalar_type(scalar_type); + in.dataType.bitWidth = bit_width; + in.dataType.integerWordLength = bit_width; // same as bit_width for all types except + // fixed point, which is not supported + in.output = (output != 0); + in.timeout = timeout; + in.status = NiRio_Status_Success; + + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_WAIT, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + data_pointer = reinterpret_cast<void*>(out.elements); + UHD_ASSERT_THROW(out.elementsAcquired <= std::numeric_limits<uint32_t>::max()); + elements_acquired = static_cast<uint32_t>(out.elementsAcquired); + UHD_ASSERT_THROW(out.elementsRemaining <= std::numeric_limits<uint32_t>::max()); + elements_remaining = static_cast<uint32_t>(out.elementsRemaining); + return out.status; +} + +nirio_status niriok_proxy_impl_v2::grant_fifo( + uint32_t channel, uint32_t elements_to_grant) +{ + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_grant_t in = {}; + out_transport_fifo_grant_t out = {}; + + in.channel = channel; + in.elements = elements_to_grant; + in.status = NiRio_Status_Success; + + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_GRANT, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + return out.status; +} + +nirio_status niriok_proxy_impl_v2::read_fifo(uint32_t channel, + uint32_t elements_to_read, + void* buffer, + uint32_t /*buffer_datatype_width*/, // Unused + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint32_t& number_read, + uint32_t& number_remaining) +{ + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_read_t in = {}; + out_transport_fifo_read_t out = {}; + + in.channel = channel; + in.buf = reinterpret_cast<aligned_uint64_t>(buffer); + in.numberElements = elements_to_read; + in.dataType.scalarType = map_int_to_scalar_type(scalar_type); + in.dataType.bitWidth = bit_width; + in.dataType.integerWordLength = bit_width; // same as bit_width for all types except + // fixed point, which is not supported + in.timeout = timeout; + in.status = NiRio_Status_Success; + + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_READ, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; + + number_read = out.read; + number_remaining = out.remaining; + return out.status; +} + +nirio_status niriok_proxy_impl_v2::write_fifo(uint32_t channel, + uint32_t elements_to_write, + void* buffer, + uint32_t /*buffer_datatype_width*/, // Unused + uint32_t scalar_type, + uint32_t bit_width, + uint32_t timeout, + uint32_t& number_remaining) +{ + READER_LOCK - nirio_status niriok_proxy_impl_v2::read_fifo( - uint32_t channel, - uint32_t elements_to_read, - void* buffer, - uint32_t /*buffer_datatype_width*/, //Unused - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint32_t& number_read, - uint32_t& number_remaining) - { - READER_LOCK - - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_read_t in = {}; - out_transport_fifo_read_t out = {}; - - in.channel = channel; - in.buf = reinterpret_cast<aligned_uint64_t>(buffer); - in.numberElements = elements_to_read; - in.dataType.scalarType = map_int_to_scalar_type(scalar_type); - in.dataType.bitWidth = bit_width; - in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported - in.timeout = timeout; - in.status = NiRio_Status_Success; + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_write_t in = {}; + out_transport_fifo_write_t out = {}; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_READ, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - number_read = out.read; - number_remaining = out.remaining; - return out.status; - } + in.channel = channel; + in.buf = reinterpret_cast<aligned_uint64_t>(buffer); + in.numberElements = elements_to_write; + in.dataType.scalarType = map_int_to_scalar_type(scalar_type); + in.dataType.bitWidth = bit_width; + in.dataType.integerWordLength = bit_width; // same as bit_width for all types except + // fixed point, which is not supported + in.timeout = timeout; + in.status = NiRio_Status_Success; - nirio_status niriok_proxy_impl_v2::write_fifo( - uint32_t channel, - uint32_t elements_to_write, - void* buffer, - uint32_t /*buffer_datatype_width*/, //Unused - uint32_t scalar_type, - uint32_t bit_width, - uint32_t timeout, - uint32_t& number_remaining) - { - READER_LOCK - - nirio_status ioctl_status = NiRio_Status_Success; - in_transport_fifo_write_t in = {}; - out_transport_fifo_write_t out = {}; - - in.channel = channel; - in.buf = reinterpret_cast<aligned_uint64_t>(buffer); - in.numberElements = elements_to_write; - in.dataType.scalarType = map_int_to_scalar_type(scalar_type); - in.dataType.bitWidth = bit_width; - in.dataType.integerWordLength = bit_width; // same as bit_width for all types except fixed point, which is not supported - in.timeout = timeout; - in.status = NiRio_Status_Success; + ioctl_status = nirio_driver_iface::rio_ioctl( + _device_handle, IOCTL_TRANSPORT_FIFO_WRITE, &in, sizeof(in), &out, sizeof(out)); + if (nirio_status_fatal(ioctl_status)) + return ioctl_status; - ioctl_status = - nirio_driver_iface::rio_ioctl( - _device_handle, - IOCTL_TRANSPORT_FIFO_WRITE, - &in, - sizeof(in), - &out, - sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - number_remaining = out.remaining; - return out.status; - } + number_remaining = out.remaining; + return out.status; +} -}} +}} // namespace uhd::niusrprio #if defined(__clang__) || defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) - #pragma GCC diagnostic pop +# pragma GCC diagnostic pop #endif diff --git a/host/lib/transport/nirio/rpc/rpc_client.cpp b/host/lib/transport/nirio/rpc/rpc_client.cpp index e9bf4bbb4..efc802e89 100644 --- a/host/lib/transport/nirio/rpc/rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/rpc_client.cpp @@ -12,35 +12,36 @@ #include <boost/version.hpp> -#define CHAIN_BLOCKING_XFER(func, exp, status) \ - if (status) { \ - status = (static_cast<size_t>((func)) == exp); \ - } else { \ +#define CHAIN_BLOCKING_XFER(func, exp, status) \ + if (status) { \ + status = (static_cast<size_t>((func)) == exp); \ + } else { \ UHD_LOGGER_DEBUG("NIRIO") << "rpc_client operation skipped: " #func "\n"; \ - } \ + } namespace uhd { namespace usrprio_rpc { using boost::asio::ip::tcp; -rpc_client::rpc_client ( - const std::string& server, +rpc_client::rpc_client(const std::string& server, const std::string& port, uint32_t process_id, - uint32_t host_id -) : _socket(_io_service) + uint32_t host_id) + : _socket(_io_service) { - //Fill in handshake info - _hshake_args_client.version = CURRENT_VERSION; + // Fill in handshake info + _hshake_args_client.version = CURRENT_VERSION; _hshake_args_client.oldest_comp_version = OLDEST_COMPATIBLE_VERSION; - _hshake_args_client.client_id = build_client_id(host_id, process_id); - _hshake_args_client.boost_archive_version = boost_serialization_archive_utils::get_version(); + _hshake_args_client.client_id = build_client_id(host_id, process_id); + _hshake_args_client.boost_archive_version = + boost_serialization_archive_utils::get_version(); try { - //Synchronous resolve + connect + // Synchronous resolve + connect tcp::resolver resolver(_io_service); - //Create flags object with all special flags disabled. Especially the following: - //- address_configured: Only return addresses if a non-loopback address is configured for the system. + // Create flags object with all special flags disabled. Especially the following: + //- address_configured: Only return addresses if a non-loopback address is + // configured for the system. //- numeric_host: No name resolution should be attempted for host //- numeric_service: No name resolution should be attempted for service tcp::resolver::query::flags query_flags(tcp::resolver::query::passive); @@ -48,56 +49,64 @@ rpc_client::rpc_client ( tcp::resolver::iterator iterator = resolver.resolve(query); boost::asio::connect(_socket, iterator); - UHD_LOGGER_TRACE("NIRIO") << "rpc_client connected to server." ; + UHD_LOGGER_TRACE("NIRIO") << "rpc_client connected to server."; try { - //Perform handshake + // Perform handshake bool status = true; - CHAIN_BLOCKING_XFER( - boost::asio::write(_socket, boost::asio::buffer(&_hshake_args_client, sizeof(_hshake_args_client))), - sizeof(_hshake_args_client), status); - CHAIN_BLOCKING_XFER( - boost::asio::read(_socket, boost::asio::buffer(&_hshake_args_server, sizeof(_hshake_args_server))), - sizeof(_hshake_args_server), status); + CHAIN_BLOCKING_XFER(boost::asio::write(_socket, + boost::asio::buffer(&_hshake_args_client, + sizeof(_hshake_args_client))), + sizeof(_hshake_args_client), + status); + CHAIN_BLOCKING_XFER(boost::asio::read(_socket, + boost::asio::buffer(&_hshake_args_server, + sizeof(_hshake_args_server))), + sizeof(_hshake_args_server), + status); _request.header.client_id = _hshake_args_server.client_id; - if (_hshake_args_server.version >= _hshake_args_client.oldest_comp_version && - _hshake_args_client.version >= _hshake_args_server.oldest_comp_version && - status) - { - UHD_LOGGER_TRACE("NIRIO") << "rpc_client bound to server." ; + if (_hshake_args_server.version >= _hshake_args_client.oldest_comp_version + && _hshake_args_client.version >= _hshake_args_server.oldest_comp_version + && status) { + UHD_LOGGER_TRACE("NIRIO") << "rpc_client bound to server."; _wait_for_next_response_header(); - //Spawn a thread for the io_service callback handler. This thread will run until rpc_client is destroyed. - _io_service_thread.reset(new boost::thread(boost::bind(&boost::asio::io_service::run, &_io_service))); + // Spawn a thread for the io_service callback handler. This thread will + // run until rpc_client is destroyed. + _io_service_thread.reset(new boost::thread( + boost::bind(&boost::asio::io_service::run, &_io_service))); } else { - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client handshake failed." ; - _exec_err.assign(boost::asio::error::connection_refused, boost::asio::error::get_system_category()); + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client handshake failed."; + _exec_err.assign(boost::asio::error::connection_refused, + boost::asio::error::get_system_category()); } - UHD_LOGGER_TRACE("NIRIO") << boost::format("rpc_client archive = %d, rpc_server archive = %d\n.") % - _hshake_args_client.boost_archive_version % - _hshake_args_server.boost_archive_version; + UHD_LOGGER_TRACE("NIRIO") + << boost::format("rpc_client archive = %d, rpc_server archive = %d\n.") + % _hshake_args_client.boost_archive_version + % _hshake_args_server.boost_archive_version; } catch (boost::exception&) { - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client handshake aborted." ; - _exec_err.assign(boost::asio::error::connection_refused, boost::asio::error::get_system_category()); + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client handshake aborted."; + _exec_err.assign(boost::asio::error::connection_refused, + boost::asio::error::get_system_category()); } } catch (boost::exception&) { - UHD_LOGGER_TRACE("NIRIO") << "rpc_client connection request cancelled/aborted." ; - _exec_err.assign(boost::asio::error::connection_aborted, boost::asio::error::get_system_category()); + UHD_LOGGER_TRACE("NIRIO") << "rpc_client connection request cancelled/aborted."; + _exec_err.assign(boost::asio::error::connection_aborted, + boost::asio::error::get_system_category()); } } -rpc_client::~rpc_client () { +rpc_client::~rpc_client() +{ _stop_io_service(); } -const boost::system::error_code& rpc_client::call( - func_id_t func_id, +const boost::system::error_code& rpc_client::call(func_id_t func_id, const func_args_writer_t& in_args, - func_args_reader_t &out_args, - boost::posix_time::milliseconds timeout -) + func_args_reader_t& out_args, + boost::posix_time::milliseconds timeout) { boost::mutex::scoped_lock lock(_mutex); @@ -108,61 +117,70 @@ const boost::system::error_code& rpc_client::call( _exec_err.clear(); - //Send function call header and args + // Send function call header and args bool status = true; try { CHAIN_BLOCKING_XFER( - boost::asio::write(_socket, boost::asio::buffer(&_request.header, sizeof(_request.header))), - sizeof(_request.header), status); - if (not _request.data.empty()) - { - CHAIN_BLOCKING_XFER( - boost::asio::write(_socket, boost::asio::buffer(&(*_request.data.begin()), _request.data.size())), - _request.data.size(), status); + boost::asio::write(_socket, + boost::asio::buffer(&_request.header, sizeof(_request.header))), + sizeof(_request.header), + status); + if (not _request.data.empty()) { + CHAIN_BLOCKING_XFER(boost::asio::write(_socket, + boost::asio::buffer(&(*_request.data.begin()), + _request.data.size())), + _request.data.size(), + status); } } catch (boost::exception&) { status = false; } - //Wait for response using condition variable + // Wait for response using condition variable if (status) { if (!_exec_gate.timed_wait(lock, timeout)) { - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client function timed out." ; - _exec_err.assign(boost::asio::error::timed_out, boost::asio::error::get_system_category()); + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client function timed out."; + _exec_err.assign(boost::asio::error::timed_out, + boost::asio::error::get_system_category()); } } else { - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client connection dropped." ; - _exec_err.assign(boost::asio::error::connection_aborted, boost::asio::error::get_system_category()); + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client connection dropped."; + _exec_err.assign(boost::asio::error::connection_aborted, + boost::asio::error::get_system_category()); _stop_io_service(); } - //Verify that we are talking to the correct endpoint + // Verify that we are talking to the correct endpoint if ((_request.header.client_id != _response.header.client_id) && !_exec_err) { - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client confused about who its talking to." ; - _exec_err.assign(boost::asio::error::operation_aborted, boost::asio::error::get_system_category()); + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client confused about who its talking to."; + _exec_err.assign(boost::asio::error::operation_aborted, + boost::asio::error::get_system_category()); } - if (!_exec_err) out_args.load(_response.data); + if (!_exec_err) + out_args.load(_response.data); } return _exec_err; } -void rpc_client::_handle_response_hdr(const boost::system::error_code& err, size_t transferred, size_t expected) +void rpc_client::_handle_response_hdr( + const boost::system::error_code& err, size_t transferred, size_t expected) { boost::mutex::scoped_lock lock(_mutex); _exec_err = err; if (!_exec_err && (transferred == expected)) { - //Response header received. Verify that it is expected + // Response header received. Verify that it is expected if (func_args_header_t::match_function(_request.header, _response.header)) { - if (_response.header.func_args_size) - { + if (_response.header.func_args_size) { _response.data.resize(_response.header.func_args_size); - //Wait for response data + // Wait for response data boost::asio::async_read(_socket, - boost::asio::buffer(&(*_response.data.begin()), _response.data.size()), - boost::bind(&rpc_client::_handle_response_data, this, + boost::asio::buffer( + &(*_response.data.begin()), _response.data.size()), + boost::bind(&rpc_client::_handle_response_data, + this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, _response.data.size())); @@ -170,23 +188,27 @@ void rpc_client::_handle_response_hdr(const boost::system::error_code& err, size _handle_response_data(err, 0, 0); } } else { - //Unexpected response. Ignore it. - UHD_LOGGER_DEBUG("NIRIO") << "rpc_client received garbage responses." ; - _exec_err.assign(boost::asio::error::operation_aborted, boost::asio::error::get_system_category()); + // Unexpected response. Ignore it. + UHD_LOGGER_DEBUG("NIRIO") << "rpc_client received garbage responses."; + _exec_err.assign(boost::asio::error::operation_aborted, + boost::asio::error::get_system_category()); _wait_for_next_response_header(); } } - if (_exec_err) _exec_gate.notify_all(); + if (_exec_err) + _exec_gate.notify_all(); } -void rpc_client::_handle_response_data(const boost::system::error_code& err, size_t transferred, size_t expected) +void rpc_client::_handle_response_data( + const boost::system::error_code& err, size_t transferred, size_t expected) { boost::mutex::scoped_lock lock(_mutex); _exec_err = err; if (transferred != expected) { - _exec_err.assign(boost::asio::error::operation_aborted, boost::asio::error::get_system_category()); + _exec_err.assign(boost::asio::error::operation_aborted, + boost::asio::error::get_system_category()); } _exec_gate.notify_all(); @@ -194,15 +216,16 @@ void rpc_client::_handle_response_data(const boost::system::error_code& err, siz _wait_for_next_response_header(); } -void rpc_client::_wait_for_next_response_header() { +void rpc_client::_wait_for_next_response_header() +{ //_mutex must be locked when this call is made - boost::asio::async_read( - _socket, + boost::asio::async_read(_socket, boost::asio::buffer(&_response.header, sizeof(_response.header)), - boost::bind(&rpc_client::_handle_response_hdr, this, + boost::bind(&rpc_client::_handle_response_hdr, + this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, sizeof(_response.header))); } -}} +}} // namespace uhd::usrprio_rpc diff --git a/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp b/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp index af79cfb7c..718ff7c05 100644 --- a/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp +++ b/host/lib/transport/nirio/rpc/usrprio_rpc_client.cpp @@ -9,24 +9,21 @@ #include <uhd/utils/platform.hpp> namespace { - constexpr int64_t DEFAULT_TIMEOUT_IN_MS = 5000; +constexpr int64_t DEFAULT_TIMEOUT_IN_MS = 5000; } namespace uhd { namespace usrprio_rpc { -usrprio_rpc_client::usrprio_rpc_client( - std::string server, - std::string port -) : _rpc_client(server, port, uhd::get_process_id(), uhd::get_host_id()), - _timeout(boost::posix_time::milliseconds(long(DEFAULT_TIMEOUT_IN_MS))) +usrprio_rpc_client::usrprio_rpc_client(std::string server, std::string port) + : _rpc_client(server, port, uhd::get_process_id(), uhd::get_host_id()) + , _timeout(boost::posix_time::milliseconds(long(DEFAULT_TIMEOUT_IN_MS))) { - _ctor_status = _rpc_client.status() ? NiRio_Status_RpcConnectionError : NiRio_Status_Success; + _ctor_status = _rpc_client.status() ? NiRio_Status_RpcConnectionError + : NiRio_Status_Success; } -usrprio_rpc_client::~usrprio_rpc_client() -{ -} +usrprio_rpc_client::~usrprio_rpc_client() {} nirio_status usrprio_rpc_client::niusrprio_enumerate(NIUSRPRIO_ENUMERATE_ARGS) /* @@ -37,7 +34,7 @@ nirio_status usrprio_rpc_client::niusrprio_enumerate(NIUSRPRIO_ENUMERATE_ARGS) usrprio_rpc::func_args_writer_t in_args; usrprio_rpc::func_args_reader_t out_args; nirio_status status = NiRio_Status_Success; - uint32_t vtr_size = 0; + uint32_t vtr_size = 0; status = _boost_error_to_nirio_status( _rpc_client.call(NIUSRPRIO_ENUMERATE, in_args, out_args, _timeout)); @@ -75,10 +72,13 @@ nirio_status usrprio_rpc_client::niusrprio_open_session(NIUSRPRIO_OPEN_SESSION_A in_args << signature; in_args << download_fpga; - //Open needs a longer timeout because the FPGA download can take upto 6 secs and the NiFpga libload can take 4. + // Open needs a longer timeout because the FPGA download can take upto 6 secs and the + // NiFpga libload can take 4. static const uint32_t OPEN_TIMEOUT = 15000; - status = _boost_error_to_nirio_status( - _rpc_client.call(NIUSRPRIO_OPEN_SESSION, in_args, out_args, boost::posix_time::milliseconds(OPEN_TIMEOUT))); + status = _boost_error_to_nirio_status(_rpc_client.call(NIUSRPRIO_OPEN_SESSION, + in_args, + out_args, + boost::posix_time::milliseconds(OPEN_TIMEOUT))); if (nirio_status_not_fatal(status)) { out_args >> status; @@ -131,7 +131,8 @@ nirio_status usrprio_rpc_client::niusrprio_reset_device(NIUSRPRIO_RESET_SESSION_ return status; } -nirio_status usrprio_rpc_client::niusrprio_get_interface_path(NIUSRPRIO_GET_INTERFACE_PATH_ARGS) +nirio_status usrprio_rpc_client::niusrprio_get_interface_path( + NIUSRPRIO_GET_INTERFACE_PATH_ARGS) /* #define NIUSRPRIO_GET_INTERFACE_PATH_ARGS \ const std::string& resource, \ @@ -155,7 +156,8 @@ nirio_status usrprio_rpc_client::niusrprio_get_interface_path(NIUSRPRIO_GET_INTE return status; } -nirio_status usrprio_rpc_client::niusrprio_download_fpga_to_flash(NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH_ARGS) +nirio_status usrprio_rpc_client::niusrprio_download_fpga_to_flash( + NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH_ARGS) /* #define NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH_ARGS \ const uint32_t& interface_num, \ @@ -170,8 +172,10 @@ nirio_status usrprio_rpc_client::niusrprio_download_fpga_to_flash(NIUSRPRIO_DOWN in_args << bitstream_path; static const uint32_t DOWNLOAD_FPGA_TIMEOUT = 1200000; - status = _boost_error_to_nirio_status( - _rpc_client.call(NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH, in_args, out_args, + status = + _boost_error_to_nirio_status(_rpc_client.call(NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH, + in_args, + out_args, boost::posix_time::milliseconds(DOWNLOAD_FPGA_TIMEOUT))); if (nirio_status_not_fatal(status)) { @@ -181,7 +185,8 @@ nirio_status usrprio_rpc_client::niusrprio_download_fpga_to_flash(NIUSRPRIO_DOWN return status; } -nirio_status usrprio_rpc_client::niusrprio_download_bitstream_to_fpga(NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA_ARGS) +nirio_status usrprio_rpc_client::niusrprio_download_bitstream_to_fpga( + NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA_ARGS) /* #define NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA_ARGS \ const std::string& resource @@ -193,8 +198,8 @@ nirio_status usrprio_rpc_client::niusrprio_download_bitstream_to_fpga(NIUSRPRIO_ in_args << resource; - status = _boost_error_to_nirio_status( - _rpc_client.call(NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA, in_args, out_args, _timeout)); + status = _boost_error_to_nirio_status(_rpc_client.call( + NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA, in_args, out_args, _timeout)); if (nirio_status_not_fatal(status)) { out_args >> status; @@ -203,7 +208,9 @@ nirio_status usrprio_rpc_client::niusrprio_download_bitstream_to_fpga(NIUSRPRIO_ return status; } -nirio_status usrprio_rpc_client::_boost_error_to_nirio_status(const boost::system::error_code& err) { +nirio_status usrprio_rpc_client::_boost_error_to_nirio_status( + const boost::system::error_code& err) +{ if (err) { switch (err.value()) { case boost::asio::error::connection_aborted: @@ -221,4 +228,4 @@ nirio_status usrprio_rpc_client::_boost_error_to_nirio_status(const boost::syste } } -}} +}} // namespace uhd::usrprio_rpc diff --git a/host/lib/transport/nirio/status.cpp b/host/lib/transport/nirio/status.cpp index 4dd63f5c6..9d6c020c0 100644 --- a/host/lib/transport/nirio/status.cpp +++ b/host/lib/transport/nirio/status.cpp @@ -11,35 +11,38 @@ namespace uhd { namespace niusrprio { -#define NIRIO_ERR_INFO(CONST_NAME, ERR_CODE, ERR_MSG) \ - nirio_err_info(ERR_CODE, ERR_MSG), +#define NIRIO_ERR_INFO(CONST_NAME, ERR_CODE, ERR_MSG) nirio_err_info(ERR_CODE, ERR_MSG), const nirio_err_info nirio_err_info::NIRIO_ERROR_TABLE[] = { - #include "../../../include/uhd/transport/nirio/nirio_err_template.h" +#include "../../../include/uhd/transport/nirio/nirio_err_template.h" }; #undef NIRIO_ERR_INFO -const size_t nirio_err_info::NIRIO_ERROR_TABLE_SIZE = sizeof(NIRIO_ERROR_TABLE)/sizeof(*NIRIO_ERROR_TABLE); +const size_t nirio_err_info::NIRIO_ERROR_TABLE_SIZE = + sizeof(NIRIO_ERROR_TABLE) / sizeof(*NIRIO_ERROR_TABLE); -const std::string lookup_err_msg(nirio_status code) { - std::string error_msg = (boost::format("Unknown error. (Error code %d)") % code).str(); +const std::string lookup_err_msg(nirio_status code) +{ + std::string error_msg = + (boost::format("Unknown error. (Error code %d)") % code).str(); for (size_t i = 0; i < nirio_err_info::NIRIO_ERROR_TABLE_SIZE; i++) { if (nirio_err_info::NIRIO_ERROR_TABLE[i].code == code) { - error_msg = (boost::format("%s (Error code %d)") % nirio_err_info::NIRIO_ERROR_TABLE[i].msg % code).str(); + error_msg = (boost::format("%s (Error code %d)") + % nirio_err_info::NIRIO_ERROR_TABLE[i].msg % code) + .str(); break; } } return error_msg; } -void nirio_status_to_exception(const nirio_status& status, const std::string& message) { +void nirio_status_to_exception(const nirio_status& status, const std::string& message) +{ if (nirio_status_fatal(status)) { - throw uhd::runtime_error((boost::format("%s %s") % message % lookup_err_msg(status)).str()); + throw uhd::runtime_error( + (boost::format("%s %s") % message % lookup_err_msg(status)).str()); } } -}} - - - +}} // namespace uhd::niusrprio diff --git a/host/lib/transport/nirio_link.cpp b/host/lib/transport/nirio_link.cpp index c6183001f..adef8b5a0 100644 --- a/host/lib/transport/nirio_link.cpp +++ b/host/lib/transport/nirio_link.cpp @@ -88,14 +88,12 @@ nirio_link::nirio_link(uhd::niusrprio::niusrprio_session::sptr fpga_session, static_cast<uint32_t>(_link_params.recv_frame_size / sizeof(fifo_data_t))), status); - // Config 64-bit word flipping and enable DMA streams - nirio_status_chain( - PROXY->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), - DMA_CTRL_SW_BUF_U64 | DMA_CTRL_ENABLED), + // Config 64-bit word flipping and enable DMA streams + nirio_status_chain(PROXY->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), + DMA_CTRL_SW_BUF_U64 | DMA_CTRL_ENABLED), status); - nirio_status_chain( - PROXY->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), - DMA_CTRL_SW_BUF_U64 | DMA_CTRL_ENABLED), + nirio_status_chain(PROXY->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), + DMA_CTRL_SW_BUF_U64 | DMA_CTRL_ENABLED), status); // Create FIFOs diff --git a/host/lib/transport/nirio_zero_copy.cpp b/host/lib/transport/nirio_zero_copy.cpp index f54e5a8ed..8600b10d1 100644 --- a/host/lib/transport/nirio_zero_copy.cpp +++ b/host/lib/transport/nirio_zero_copy.cpp @@ -13,9 +13,9 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/format.hpp> #include <boost/interprocess/mapped_region.hpp> //get_page_size() -#include <memory> #include <algorithm> // std::max #include <chrono> +#include <memory> #include <thread> #include <vector> diff --git a/host/lib/transport/offload_io_service.cpp b/host/lib/transport/offload_io_service.cpp index ba95c843b..b92543587 100644 --- a/host/lib/transport/offload_io_service.cpp +++ b/host/lib/transport/offload_io_service.cpp @@ -28,17 +28,16 @@ constexpr int32_t blocking_timeout_ms = 10; // Fixed-size queue that supports blocking semantics template <typename queue_item_t> -class offload_thread_queue { +class offload_thread_queue +{ public: - offload_thread_queue(size_t size) - : _buffer(new queue_item_t[size]) - , _capacity(size) + offload_thread_queue(size_t size) : _buffer(new queue_item_t[size]), _capacity(size) { } ~offload_thread_queue() { - delete [] _buffer; + delete[] _buffer; } void push(const queue_item_t& item) @@ -475,7 +474,8 @@ recv_io_if::sptr offload_io_service_impl::make_recv_client(recv_link_if::sptr re // Create a request to create a new receiver in the offload thread auto req_fn = [this, recv_link, num_recv_frames, cb, fc_link, num_send_frames, fc_cb, port]() { - frame_reservation_t frames = {recv_link, num_recv_frames, fc_link, num_send_frames}; + frame_reservation_t frames = { + recv_link, num_recv_frames, fc_link, num_send_frames}; _reservation_mgr.reserve_frames(frames); auto inline_recv_io = _io_srv->make_recv_client( @@ -529,13 +529,19 @@ send_io_if::sptr offload_io_service_impl::make_send_client(send_link_if::sptr se recv_link, num_recv_frames, recv_cb, - fc_cb, + fc_cb, port]() { - frame_reservation_t frames = {recv_link, num_recv_frames, send_link, num_send_frames}; + frame_reservation_t frames = { + recv_link, num_recv_frames, send_link, num_send_frames}; _reservation_mgr.reserve_frames(frames); - auto inline_send_io = _io_srv->make_send_client( - send_link, num_send_frames, send_cb, recv_link, num_recv_frames, recv_cb, fc_cb); + auto inline_send_io = _io_srv->make_send_client(send_link, + num_send_frames, + send_cb, + recv_link, + num_recv_frames, + recv_cb, + fc_cb); send_client_info_t client_info; client_info.inline_io = inline_send_io; @@ -599,7 +605,8 @@ void offload_io_service_impl::_get_send_buff(send_client_info_t& info) } // Release a single recv buffer and update client info -void offload_io_service_impl::_release_recv_buff(recv_client_info_t& info, frame_buff* buff) +void offload_io_service_impl::_release_recv_buff( + recv_client_info_t& info, frame_buff* buff) { info.inline_io->release_recv_buff(frame_buff::uptr(buff)); assert(info.num_frames_in_use > 0); @@ -607,7 +614,8 @@ void offload_io_service_impl::_release_recv_buff(recv_client_info_t& info, frame } // Release a single send info -void offload_io_service_impl::_release_send_buff(send_client_info_t& info, frame_buff* buff) +void offload_io_service_impl::_release_send_buff( + send_client_info_t& info, frame_buff* buff) { info.inline_io->release_send_buff(frame_buff::uptr(buff)); assert(info.num_frames_in_use > 0); @@ -728,7 +736,8 @@ void offload_io_service_impl::_do_work_blocking() if (it->num_frames_in_use == it->frames_reserved.num_recv_frames) { // If all buffers are in use, block to avoid excessive CPU usage - std::tie(buff, disconnect) = it->port->offload_thread_pop(blocking_timeout_ms); + std::tie(buff, disconnect) = + it->port->offload_thread_pop(blocking_timeout_ms); } else { // Otherwise, just check current status std::tie(buff, disconnect) = it->port->offload_thread_pop(); @@ -758,7 +767,8 @@ void offload_io_service_impl::_do_work_blocking() bool disconnect; std::tie(buff, disconnect) = it->port->offload_thread_peek(); if (buff) { - if (it->inline_io->wait_for_dest_ready(buff->packet_size(), blocking_timeout_ms)) { + if (it->inline_io->wait_for_dest_ready( + buff->packet_size(), blocking_timeout_ms)) { _release_send_buff(*it, buff); it->port->offload_thread_pop(); } diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index b19b50b38..f428f01f1 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -21,8 +21,8 @@ #include <boost/dynamic_bitset.hpp> #include <boost/format.hpp> #include <functional> -#include <memory> #include <iostream> +#include <memory> #include <vector> namespace uhd { namespace transport { namespace sph { @@ -670,9 +670,9 @@ private: curr_info.metadata.time_spec = prev_info.metadata.time_spec + time_spec_t::from_ticks( - prev_info[index].ifpi.num_payload_words32 * sizeof(uint32_t) - / _bytes_per_otw_item, - _samp_rate); + prev_info[index].ifpi.num_payload_words32 * sizeof(uint32_t) + / _bytes_per_otw_item, + _samp_rate); curr_info.metadata.out_of_sequence = true; curr_info.metadata.error_code = rx_metadata_t::ERROR_CODE_OVERFLOW; UHD_LOG_FASTPATH("D"); @@ -797,7 +797,6 @@ private: const rx_streamer::buffs_type* _convert_buffs; size_t _convert_buffer_offset_bytes; size_t _convert_bytes_to_copy; - }; class recv_packet_streamer : public recv_packet_handler, public rx_streamer diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index 21f7357c3..556530f81 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -18,8 +18,8 @@ #include <uhd/utils/byteswap.hpp> #include <uhd/utils/tasks.hpp> #include <uhd/utils/thread.hpp> -#include <functional> #include <chrono> +#include <functional> #include <iostream> #include <thread> #include <vector> diff --git a/host/lib/transport/tcp_zero_copy.cpp b/host/lib/transport/tcp_zero_copy.cpp index 555dd238e..0927a08ee 100644 --- a/host/lib/transport/tcp_zero_copy.cpp +++ b/host/lib/transport/tcp_zero_copy.cpp @@ -8,11 +8,11 @@ #include <uhd/transport/buffer_pool.hpp> #include <uhd/transport/tcp_zero_copy.hpp> #include <uhd/utils/log.hpp> -#include <uhdlib/utils/atomic.hpp> #include <uhdlib/transport/udp_common.hpp> +#include <uhdlib/utils/atomic.hpp> #include <boost/format.hpp> -#include <memory> #include <chrono> +#include <memory> #include <thread> #include <vector> diff --git a/host/lib/transport/udp_zero_copy.cpp b/host/lib/transport/udp_zero_copy.cpp index 883b2a68a..1a6f55259 100644 --- a/host/lib/transport/udp_zero_copy.cpp +++ b/host/lib/transport/udp_zero_copy.cpp @@ -11,8 +11,8 @@ #include <uhdlib/transport/udp_common.hpp> #include <uhdlib/utils/atomic.hpp> #include <boost/format.hpp> -#include <memory> #include <chrono> +#include <memory> #include <thread> #include <vector> @@ -303,10 +303,8 @@ udp_zero_copy::sptr udp_zero_copy::make(const std::string& addr, xport_params.send_frame_size = UDP_DEFAULT_FRAME_SIZE; } - UHD_LOG_TRACE("UDP", - "send_frame_size: " << xport_params.send_frame_size); - UHD_LOG_TRACE("UDP", - "recv_frame_size: " << xport_params.recv_frame_size); + UHD_LOG_TRACE("UDP", "send_frame_size: " << xport_params.send_frame_size); + UHD_LOG_TRACE("UDP", "recv_frame_size: " << xport_params.recv_frame_size); if (xport_params.recv_buff_size == 0) { UHD_LOG_TRACE("UDP", "Using default value for recv_buff_size"); diff --git a/host/lib/transport/zero_copy_flow_ctrl.cpp b/host/lib/transport/zero_copy_flow_ctrl.cpp index 610d93281..05907c209 100644 --- a/host/lib/transport/zero_copy_flow_ctrl.cpp +++ b/host/lib/transport/zero_copy_flow_ctrl.cpp @@ -10,11 +10,11 @@ #include <uhd/transport/zero_copy_flow_ctrl.hpp> #include <uhd/utils/log.hpp> #include <uhd/utils/safe_call.hpp> -#include <functional> #include <boost/format.hpp> -#include <memory> #include <boost/thread/mutex.hpp> #include <boost/thread/thread.hpp> +#include <functional> +#include <memory> using namespace uhd; using namespace uhd::transport; @@ -113,12 +113,10 @@ public: UHD_LOG_TRACE("TRANSPORT", "Created zero_copy_flow_ctrl"); for (size_t i = 0; i < transport->get_num_send_frames(); i++) { - _send_buffers[i] = - std::make_shared<zero_copy_flow_ctrl_msb>(_send_flow_ctrl); + _send_buffers[i] = std::make_shared<zero_copy_flow_ctrl_msb>(_send_flow_ctrl); } for (size_t i = 0; i < transport->get_num_recv_frames(); i++) { - _recv_buffers[i] = - std::make_shared<zero_copy_flow_ctrl_mrb>(_recv_flow_ctrl); + _recv_buffers[i] = std::make_shared<zero_copy_flow_ctrl_mrb>(_recv_flow_ctrl); } } |