diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/device.cpp | 13 | ||||
-rw-r--r-- | host/lib/transport/nirio/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | host/lib/transport/nirio/lvbitx/process-lvbitx.py | 28 | ||||
-rw-r--r-- | host/lib/transport/nirio/nirio_driver_iface_linux.cpp | 11 | ||||
-rw-r--r-- | host/lib/transport/nirio/nirio_resource_manager.cpp | 33 | ||||
-rw-r--r-- | host/lib/transport/nirio/niriok_proxy.cpp | 290 | ||||
-rw-r--r-- | host/lib/transport/nirio/niriok_proxy_impl_v1.cpp | 494 | ||||
-rw-r--r-- | host/lib/transport/nirio/niriok_proxy_impl_v2.cpp | 647 | ||||
-rw-r--r-- | host/lib/transport/nirio/niusrprio_session.cpp | 36 | ||||
-rw-r--r-- | host/lib/transport/nirio_zero_copy.cpp | 30 | ||||
-rw-r--r-- | host/lib/usrp/common/adf435x_common.cpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_fw_ctrl.cpp | 22 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.cpp | 13 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.hpp | 2 |
14 files changed, 1280 insertions, 344 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 453781510..006ea6ec8 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -47,9 +47,16 @@ static size_t hash_device_addr( ){ //combine the hashes of sorted keys/value pairs size_t hash = 0; - BOOST_FOREACH(const std::string &key, uhd::sorted(dev_addr.keys())){ - boost::hash_combine(hash, key); - boost::hash_combine(hash, dev_addr[key]); + + if(dev_addr.has_key("resource")) { + boost::hash_combine(hash, "resource"); + boost::hash_combine(hash, dev_addr["resource"]); + } + else { + BOOST_FOREACH(const std::string &key, uhd::sorted(dev_addr.keys())){ + boost::hash_combine(hash, key); + boost::hash_combine(hash, dev_addr[key]); + } } return hash; } diff --git a/host/lib/transport/nirio/CMakeLists.txt b/host/lib/transport/nirio/CMakeLists.txt index 5f12e91df..99beda056 100644 --- a/host/lib/transport/nirio/CMakeLists.txt +++ b/host/lib/transport/nirio/CMakeLists.txt @@ -33,6 +33,8 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/nifpga_lvbitx.cpp ${CMAKE_CURRENT_SOURCE_DIR}/niusrprio_session.cpp ${CMAKE_CURRENT_SOURCE_DIR}/niriok_proxy.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/niriok_proxy_impl_v1.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/niriok_proxy_impl_v2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nirio_resource_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/status.cpp ) diff --git a/host/lib/transport/nirio/lvbitx/process-lvbitx.py b/host/lib/transport/nirio/lvbitx/process-lvbitx.py index a3d88d0bb..ab9625608 100755 --- a/host/lib/transport/nirio/lvbitx/process-lvbitx.py +++ b/host/lib/transport/nirio/lvbitx/process-lvbitx.py @@ -101,6 +101,31 @@ codegen_transform['control_list'] = control_list codegen_transform['indicator_list'] = indicator_list # Enumerate FIFOs + +# This function takes a SubType string as specified in an lvbitx file and finds the +# corresponding nirio_scalar_type_t value. +def map_SubType_to_ScalarType(SubType): + if SubType == 'I8': + ScalarType = 'RIO_SCALAR_TYPE_IB' + elif SubType == 'I16': + ScalarType = 'RIO_SCALAR_TYPE_IW' + elif SubType == 'I32': + ScalarType = 'RIO_SCALAR_TYPE_IL' + elif SubType == 'I64': + ScalarType = 'RIO_SCALAR_TYPE_IQ' + elif SubType == 'U8': + ScalarType = 'RIO_SCALAR_TYPE_UB' + elif SubType == 'U16': + ScalarType = 'RIO_SCALAR_TYPE_UW' + elif SubType == 'U32': + ScalarType = 'RIO_SCALAR_TYPE_UL' + elif SubType == 'U64': + ScalarType = 'RIO_SCALAR_TYPE_UQ' + else: + print 'ERROR: No corresponding nirio_scalar_type_t value for SubType ' + SubType + ' .' + sys.exit(1) + return ScalarType; + nifpga_metadata = root.find('Project').find('CompilationResultsTree').find('CompilationResults').find('NiFpga') dma_channel_list = nifpga_metadata.find('DmaChannelAllocationList') reg_block_list = nifpga_metadata.find('RegisterBlockList') @@ -133,8 +158,9 @@ for dma_channel in dma_channel_list: fifo_init_seq += direction + ', ' fifo_init_seq += str.lower(base_addr) + ', ' fifo_init_seq += dma_channel.find('NumberOfElements').text + ', ' - fifo_init_seq += 'SCALAR_' + dma_channel.find('DataType').find('SubType').text + ', ' + fifo_init_seq += map_SubType_to_ScalarType(dma_channel.find('DataType').find('SubType').text) + ', ' fifo_init_seq += dma_channel.find('DataType').find('WordLength').text + ', ' + fifo_init_seq += dma_channel.find('DataType').find('IntegerWordLength').text + ', ' fifo_init_seq += bitstream_version fifo_init_seq += ')); //' + fifo_name diff --git a/host/lib/transport/nirio/nirio_driver_iface_linux.cpp b/host/lib/transport/nirio/nirio_driver_iface_linux.cpp index b1f4bb49f..cccf4f8f9 100644 --- a/host/lib/transport/nirio/nirio_driver_iface_linux.cpp +++ b/host/lib/transport/nirio/nirio_driver_iface_linux.cpp @@ -25,6 +25,17 @@ namespace nirio_driver_iface { +struct nirio_ioctl_block_t +{ + uint64_t inBuf; + uint64_t outBuf; + uint32_t inBufLength; + uint32_t outBufLength; + uint32_t bytesReturned; + uint32_t padding; +}; + + nirio_status rio_open( const std::string& device_path, rio_dev_handle_t& device_handle) diff --git a/host/lib/transport/nirio/nirio_resource_manager.cpp b/host/lib/transport/nirio/nirio_resource_manager.cpp index 85e789087..e56670de0 100644 --- a/host/lib/transport/nirio/nirio_resource_manager.cpp +++ b/host/lib/transport/nirio/nirio_resource_manager.cpp @@ -27,11 +27,16 @@ namespace uhd { namespace niusrprio { -nirio_resource_manager::nirio_resource_manager( - niriok_proxy& proxy) : _kernel_proxy(proxy), _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; +} + + nirio_resource_manager::~nirio_resource_manager() { finalize(); @@ -78,32 +83,12 @@ nirio_status nirio_resource_manager::get_register_offset( nirio_status nirio_resource_manager::_add_fifo_resource( const nirio_fifo_info_t& fifo_info) { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::ADD_RESOURCE; - in.subfunction = (fifo_info.direction == OUTPUT_FIFO) ? - nirio_driver_iface::NIRIO_RESOURCE::OUTPUT_FIFO : - nirio_driver_iface::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 = fifo_info.scalar_type; - in.params.add.fifoWithDataType.bitWidth = fifo_info.width; - in.params.add.fifoWithDataType.version = fifo_info.version; - - return _kernel_proxy.sync_operation(&in, sizeof(in), &out, sizeof(out)); + return _kernel_proxy->add_fifo_resource(fifo_info); } nirio_status nirio_resource_manager::_set_driver_config() { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - in.function = nirio_driver_iface::NIRIO_FUNC::SET_DRIVER_CONFIG; - in.subfunction = 0; - - return _kernel_proxy.sync_operation(&in, sizeof(in), &out, sizeof(out)); + return _kernel_proxy->set_device_config(); } nirio_fifo_info_t* nirio_resource_manager::_lookup_fifo_info(const char* fifo_name) { diff --git a/host/lib/transport/nirio/niriok_proxy.cpp b/host/lib/transport/nirio/niriok_proxy.cpp index ac8faf0a4..cc2daba22 100644 --- a/host/lib/transport/nirio/niriok_proxy.cpp +++ b/host/lib/transport/nirio/niriok_proxy.cpp @@ -15,25 +15,11 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // - #include <uhd/transport/nirio/niriok_proxy.h> +#include <uhd/transport/nirio/niriok_proxy_impl_v1.h> +#include <uhd/transport/nirio/niriok_proxy_impl_v2.h> #include <cstring> -#define NI_VENDOR_NUM 0x1093 - -#define VERSION_BUILD_SHIFT 0 -#define VERSION_PHASE_SHIFT 14 -#define VERSION_MAINT_SHIFT 16 -#define VERSION_UPGRD_SHIFT 20 -#define VERSION_MAJOR_SHIFT 24 -#define VERSION_BUILD_MASK 0x00003FFF -#define VERSION_PHASE_MASK 0x0000C000 -#define VERSION_MAINT_MASK 0x000F0000 -#define VERSION_UPGRD_MASK 0x00F00000 -#define VERSION_MAJOR_MASK 0xFF000000 - -#define GET_FIFO_MEMORY_TYPE(fifo_inst) (static_cast<uint16_t>(0x0100 | static_cast<uint16_t>(fifo_inst))) - #ifdef __clang__ #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" #elif defined(__GNUC__) @@ -42,6 +28,9 @@ namespace uhd { namespace niusrprio { + // initialization of static members + boost::shared_mutex niriok_proxy::_synchronization; + //------------------------------------------------------- // niriok_proxy //------------------------------------------------------- @@ -51,258 +40,37 @@ namespace uhd { namespace niusrprio niriok_proxy::~niriok_proxy() { - close(); - } - - nirio_status niriok_proxy::open(const std::string& interface_path) - { - if (interface_path.empty()) return NiRio_Status_ResourceNotFound; - - //close if already open. - 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_driver_iface::NIRIO_IOCTL_POST_OPEN, - NULL, 0, NULL, 0), status); - nirio_driver_iface::nirio_ioctl_packet_t out(&_interface_num, sizeof(_interface_num), 0); - nirio_status_chain(nirio_driver_iface::rio_ioctl(_device_handle, - nirio_driver_iface::NIRIO_IOCTL_GET_IFACE_NUM, - NULL, 0, - &out, sizeof(out)), status); - - if (nirio_status_fatal(status)) close(); - } - return status; - } - - void niriok_proxy::close(void) - { - if(nirio_driver_iface::rio_isopen(_device_handle)) - { - nirio_driver_iface::rio_ioctl( - _device_handle, nirio_driver_iface::NIRIO_IOCTL_PRE_CLOSE, NULL, 0, NULL, 0); - nirio_driver_iface::rio_close(_device_handle); - } - } - - nirio_status niriok_proxy::reset() - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::RESET; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy::get_cached_session( - uint32_t& session) - { - nirio_driver_iface::nirio_ioctl_packet_t out(&session, sizeof(session), 0); - return nirio_driver_iface::rio_ioctl(_device_handle, - nirio_driver_iface::NIRIO_IOCTL_GET_SESSION, - NULL, 0, - &out, sizeof(out)); } + + 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 - nirio_status niriok_proxy::get_version( - nirio_version_t type, - uint32_t& major, - uint32_t& upgrade, - uint32_t& maintenance, - char& phase, - uint32_t& build) - { - nirio_device_attr_32_t version_attr = (type==CURRENT)?CURRENT_VERSION: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; - } + 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. + */ - nirio_status niriok_proxy::sync_operation( - const void *writeBuffer, - size_t writeBufferLength, - void *readBuffer, - size_t readBufferLength) - { - nirio_driver_iface::nirio_ioctl_packet_t out(readBuffer, readBufferLength, 0); - nirio_status ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, - nirio_driver_iface::NIRIO_IOCTL_SYNCOP, - writeBuffer, writeBufferLength, - &out, sizeof(out)); - if (nirio_status_fatal(ioctl_status)) return ioctl_status; - - return out.statusCode; - } - - nirio_status niriok_proxy::get_attribute( - const nirio_device_attr_32_t attribute, - uint32_t& attrValue) - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; + sptr proxy_v1(new niriok_proxy_impl_v1); + status = proxy_v1->open(interface_path); - in.function = nirio_driver_iface::NIRIO_FUNC::GET32; - in.params.attribute32.attribute = attribute; + if (nirio_status_not_fatal(status)) + return proxy_v1; - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - - attrValue = out.params.attribute32.value; - return status; - } - - nirio_status niriok_proxy::get_attribute( - const nirio_device_attr_str_t attribute, - char *buf, - const uint32_t bufLen, - uint32_t& stringLen) - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - nirio_driver_iface::init_syncop_out_params(out, buf, bufLen); - - in.function = nirio_driver_iface::NIRIO_FUNC::GET_STRING; - in.params.attributeStr.attribute = attribute; - - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - - stringLen = out.params.stringLength; - return status; - } - - nirio_status niriok_proxy::set_attribute( - const nirio_device_attr_32_t attribute, - const uint32_t value) - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; + sptr proxy_v2(new niriok_proxy_impl_v2); + status = proxy_v2->open(interface_path); - in.function = nirio_driver_iface::NIRIO_FUNC::SET32; - in.params.attribute32.attribute = attribute; - in.params.attribute32.value = value; + if (nirio_status_not_fatal(status)) + return proxy_v2; - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy::set_attribute( - const nirio_device_attr_str_t attribute, - const char* const buffer) - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::init_syncop_in_params(in, buffer, strlen(buffer) + 1); - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::SET_STRING; - in.params.attributeStr.attribute = attribute; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy::peek(uint32_t offset, uint32_t& value) - { - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; - - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::IO; - in.subfunction = nirio_driver_iface::NIRIO_IO::PEEK32; - in.params.io.offset = offset; - - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - value = out.params.io.value.value32; - return status; - } - - nirio_status niriok_proxy::peek(uint32_t offset, uint64_t& value) - { - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; - - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::IO; - in.subfunction = nirio_driver_iface::NIRIO_IO::PEEK64; - in.params.io.offset = offset; - - nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); - value = out.params.io.value.value64; - return status; - } - - nirio_status niriok_proxy::poke(uint32_t offset, const uint32_t& value) - { - if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; - - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::IO; - in.subfunction = nirio_driver_iface::NIRIO_IO::POKE32; - in.params.io.offset = offset; - in.params.io.value.value32 = value; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy::poke(uint32_t offset, const uint64_t& value) - { - if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; - - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::IO; - in.subfunction = nirio_driver_iface::NIRIO_IO::POKE64; - in.params.io.offset = offset; - in.params.io.value.value64 = value; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } - - nirio_status niriok_proxy::map_fifo_memory( - uint32_t fifo_instance, - size_t size, - nirio_driver_iface::rio_mmap_t& map) - { - return nirio_driver_iface::rio_mmap(_device_handle, - GET_FIFO_MEMORY_TYPE(fifo_instance), - size, true, map); - } - - nirio_status niriok_proxy::unmap_fifo_memory( - nirio_driver_iface::rio_mmap_t& map) - { - return nirio_driver_iface::rio_munmap(map); - } - - nirio_status niriok_proxy::stop_all_fifos() - { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO_STOP_ALL; - - return sync_operation(&in, sizeof(in), &out, sizeof(out)); - } + throw uhd::runtime_error("Unable to detect a supported version of the NI-RIO kernel interface."); + + } }} #ifdef __GNUC__ diff --git a/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp new file mode 100644 index 000000000..7ef0e3645 --- /dev/null +++ b/host/lib/transport/nirio/niriok_proxy_impl_v1.cpp @@ -0,0 +1,494 @@ +// +// Copyright 2013-2014 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + + +#include <uhd/transport/nirio/niriok_proxy_impl_v1.h> +#include <cstring> + +#ifdef __clang__ + #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" +#elif defined(__GNUC__) + #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +namespace uhd { namespace niusrprio +{ + //------------------------------------------------------- + // niriok_proxy_impl_v1 + //------------------------------------------------------- + niriok_proxy_impl_v1::niriok_proxy_impl_v1() + { + } + + niriok_proxy_impl_v1::~niriok_proxy_impl_v1() + { + close(); + } + + 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_driver_iface::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_driver_iface::NIRIO_IOCTL_GET_IFACE_NUM, + NULL, 0, + &out, sizeof(out)), status); + + if (nirio_status_fatal(status)) _close(); + } + return status; + } + + void niriok_proxy_impl_v1::close(void) + { + WRITER_LOCK + + _close(); + } + + // 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_driver_iface::NIRIO_IOCTL_PRE_CLOSE, NULL, 0, NULL, 0); + nirio_driver_iface::rio_close(_device_handle); + } + } + + nirio_status niriok_proxy_impl_v1::reset() + { + READER_LOCK + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::RESET; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); + } + + nirio_status niriok_proxy_impl_v1::get_cached_session( + uint32_t& session) + { + READER_LOCK + + nirio_ioctl_packet_t out(&session, sizeof(session), 0); + return nirio_driver_iface::rio_ioctl(_device_handle, + nirio_driver_iface::NIRIO_IOCTL_GET_SESSION, + NULL, 0, + &out, sizeof(out)); + } + + 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; + } + + return status; + } + + 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_driver_iface::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 = {}; + + in.function = NIRIO_FUNC::GET32; + in.params.attribute32.attribute = static_cast <uint32_t> (attribute); + + nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + + attrValue = out.params.attribute32.value; + return status; + } + + 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 = {}; + + in.function = NIRIO_FUNC::SET32; + in.params.attribute32.attribute = static_cast <uint32_t> (attribute); + in.params.attribute32.value = value; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); + } + + nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint32_t& value) + { + if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::PEEK32; + in.params.io.offset = offset; + + nirio_status status = sync_operation(&in, sizeof(in), &out, sizeof(out)); + value = out.params.io.value.value32; + return status; + } + + nirio_status niriok_proxy_impl_v1::peek(uint32_t offset, uint64_t& value) + { + if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::PEEK64; + in.params.io.offset = offset; + + 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; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::POKE32; + in.params.io.offset = offset; + in.params.io.value.value32 = value; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); + } + + nirio_status niriok_proxy_impl_v1::poke(uint32_t offset, const uint64_t& value) + { + if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::IO; + in.subfunction = NIRIO_IO::POKE64; + in.params.io.offset = offset; + in.params.io.value.value64 = value; + + return sync_operation(&in, sizeof(in), &out, sizeof(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 + + return nirio_driver_iface::rio_mmap(_device_handle, + GET_FIFO_MEMORY_TYPE(fifo_instance), + size, true, map); + } + + nirio_status niriok_proxy_impl_v1::unmap_fifo_memory( + nirio_driver_iface::rio_mmap_t& map) + { + READER_LOCK + + return nirio_driver_iface::rio_munmap(map); + } + + nirio_status niriok_proxy_impl_v1::stop_all_fifos() + { + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::FIFO_STOP_ALL; + + 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) + { + niriok_proxy_impl_v1::nirio_syncop_in_params_t in = {}; + niriok_proxy_impl_v1::nirio_syncop_out_params_t out = {}; + + in.function = niriok_proxy_impl_v1::NIRIO_FUNC::ADD_RESOURCE; + in.subfunction = (fifo_info.direction == OUTPUT_FIFO) ? + niriok_proxy_impl_v1::NIRIO_RESOURCE::OUTPUT_FIFO : + niriok_proxy_impl_v1::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 = {}; + + in.function = niriok_proxy_impl_v1::NIRIO_FUNC::SET_DRIVER_CONFIG; + in.subfunction = 0; + + return sync_operation(&in, sizeof(in), &out, sizeof(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::FIFO; + in.subfunction = NIRIO_FIFO::START; + + in.params.fifo.channel = channel; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); + } + + nirio_status niriok_proxy_impl_v1::stop_fifo( + uint32_t channel) + { + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::STOP; + + in.params.fifo.channel = channel; + + return sync_operation(&in, sizeof(in), &out, sizeof(out)); + } + + 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; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::CONFIGURE; + + 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; + + 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; + + 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; + + 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; + + data_pointer = out.params.fifo.op.wait.elements.pointer; + elements_acquired = stuffed[0]; + elements_remaining = stuffed[1]; + + 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; + + nirio_syncop_in_params_t in = {}; + nirio_syncop_out_params_t out = {}; + init_syncop_out_params(out, buffer, elements_to_read * buffer_datatype_width); + + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::READ; + + 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; + + number_read = out.params.fifo.op.read.numberRead; + number_remaining = out.params.fifo.op.read.numberRemaining; + + 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; + + nirio_syncop_in_params_t in = {}; + init_syncop_in_params(in, buffer, elements_to_write * buffer_datatype_width); + nirio_syncop_out_params_t out = {}; + + in.function = NIRIO_FUNC::FIFO; + in.subfunction = NIRIO_FIFO::WRITE; + + 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; + } + +}} + +#ifdef __GNUC__ + #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 new file mode 100644 index 000000000..09daa7862 --- /dev/null +++ b/host/lib/transport/nirio/niriok_proxy_impl_v2.cpp @@ -0,0 +1,647 @@ +// +// Copyright 2013-2014 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + + +#include <uhd/transport/nirio/niriok_proxy_impl_v2.h> +#include <cstring> + +#ifdef __clang__ + #pragma GCC diagnostic push ignored "-Wmissing-field-initializers" +#elif defined(__GNUC__) + #pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +namespace uhd { namespace niusrprio +{ + //------------------------------------------------------- + // niriok_proxy_impl_v2 + //------------------------------------------------------- + niriok_proxy_impl_v2::niriok_proxy_impl_v2() + { + } + + niriok_proxy_impl_v2::~niriok_proxy_impl_v2() + { + 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; + } + + void niriok_proxy_impl_v2::close(void) + { + WRITER_LOCK + + _close(); + } + + // 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 + + in_transport_reset_t in = {}; + out_transport_reset_t out = {}; + + 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; + + return out.status; + } + + nirio_status niriok_proxy_impl_v2::get_cached_session( + uint32_t& session) + { + READER_LOCK + + nirio_ioctl_packet_t out(&session, sizeof(session), 0); + return nirio_driver_iface::rio_ioctl(_device_handle, + nirio_driver_iface::NIRIO_IOCTL_GET_SESSION, + NULL, 0, + &out, sizeof(out)); + } + + 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; + } + + 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.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; + + attrValue = out.retVal__; + + return out.status; + } + + 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.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; + + return out.status; + } + + nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint32_t& value) + { + READER_LOCK + + 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; + + 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; + + value = out.retVal__; + + return out.status; + } + + nirio_status niriok_proxy_impl_v2::peek(uint32_t offset, uint64_t& value) + { + READER_LOCK + + if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + in_transport_peek64_t in = {}; + out_transport_peek64_t out = {}; + + in.offset = offset; + in.status = NiRio_Status_Success; + + 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; + + value = out.retVal__; + + return out.status; + } + + nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint32_t& value) + { + READER_LOCK + + if (offset % 4 != 0) return NiRio_Status_MisalignedAccess; + + in_transport_poke32_t in = {}; + out_transport_poke32_t out = {}; + + in.offset = offset; + in.value = value; + in.status = NiRio_Status_Success; + + 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; + + return out.status; + } + + nirio_status niriok_proxy_impl_v2::poke(uint32_t offset, const uint64_t& value) + { + READER_LOCK + + if (offset % 8 != 0) return NiRio_Status_MisalignedAccess; + + in_transport_poke64_t in = {}; + out_transport_poke64_t out = {}; + + in.offset = offset; + in.value = value; + in.status = NiRio_Status_Success; + + 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; + + return out.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 nirio_driver_iface::rio_mmap(_device_handle, + GET_FIFO_MEMORY_TYPE(fifo_instance), + size, true, map); + } + + nirio_status niriok_proxy_impl_v2::unmap_fifo_memory( + nirio_driver_iface::rio_mmap_t& map) + { + READER_LOCK + + return nirio_driver_iface::rio_munmap(map); + } + + nirio_status niriok_proxy_impl_v2::stop_all_fifos() + { + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_stop_all_t in = {}; + out_transport_fifo_stop_all_t out = {}; + + in.status = NiRio_Status_Success; + + 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; + + 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; + + ioctl_status = nirio_driver_iface::rio_ioctl(_device_handle, + 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 = {}; + 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.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_OUTPUT_FIFO_RESOURCE, + &in, sizeof(in), + &out, sizeof(out)); + + status = nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; + break; + } + 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 nirio_status_fatal(ioctl_status) ? ioctl_status : out.status; + } + + nirio_status niriok_proxy_impl_v2::start_fifo( + uint32_t channel) + { + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_start_t in = {}; + out_transport_fifo_start_t out = {}; + + in.channel = channel; + 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; + } + + nirio_status niriok_proxy_impl_v2::stop_fifo( + uint32_t channel) + { + READER_LOCK + + nirio_status ioctl_status = NiRio_Status_Success; + in_transport_fifo_stop_t in = {}; + out_transport_fifo_stop_t out = {}; + + in.channel = channel; + in.status = NiRio_Status_Success; + + 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; + } + + nirio_status niriok_proxy_impl_v2::configure_fifo( + uint32_t channel, + uint32_t requested_depth, + uint8_t requires_actuals, + 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, + 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<tAlignedU64>(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, + 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<tAlignedU64>(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; + + number_remaining = out.remaining; + return out.status; + } + +}} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif diff --git a/host/lib/transport/nirio/niusrprio_session.cpp b/host/lib/transport/nirio/niusrprio_session.cpp index 97d764736..5463e3502 100644 --- a/host/lib/transport/nirio/niusrprio_session.cpp +++ b/host/lib/transport/nirio/niusrprio_session.cpp @@ -32,9 +32,11 @@ namespace uhd { namespace niusrprio { niusrprio_session::niusrprio_session(const std::string& resource_name, const std::string& rpc_port_name) : _resource_name(resource_name), _session_open(false), - _resource_manager(_riok_proxy), + _resource_manager(), _rpc_client("localhost", rpc_port_name) { + _riok_proxy = create_kernel_proxy(resource_name,rpc_port_name); + _resource_manager.set_proxy(_riok_proxy); } niusrprio_session::~niusrprio_session() @@ -66,7 +68,7 @@ nirio_status niusrprio_session::open( nirio_status_chain(_rpc_client.get_ctor_status(), status); //Get a handle to the kernel driver nirio_status_chain(_rpc_client.niusrprio_get_interface_path(_resource_name, _interface_path), status); - nirio_status_chain(_riok_proxy.open(_interface_path), status); + nirio_status_chain(_riok_proxy->open(_interface_path), status); if (nirio_status_not_fatal(status)) { //Bitfile build for a particular LVFPGA interface will have the same signature @@ -132,12 +134,8 @@ niriok_proxy::sptr niusrprio_session::create_kernel_proxy( std::string interface_path; nirio_status_chain(temp_rpc_client.niusrprio_get_interface_path(resource_name, interface_path), status); - niriok_proxy::sptr proxy; - if (nirio_status_not_fatal(status)) { - proxy.reset(new niriok_proxy()); - if (proxy) nirio_status_chain(proxy->open(interface_path), status); - } - + niriok_proxy::sptr proxy = niriok_proxy::make_and_open(interface_path); + return proxy; } @@ -146,12 +144,12 @@ nirio_status niusrprio_session::_verify_signature() //Validate the signature using the kernel proxy nirio_status status = NiRio_Status_Success; boost::uint32_t sig_offset = 0; - nirio_status_chain(_riok_proxy.get_attribute(DEFAULT_FPGA_SIGNATURE_OFFSET, sig_offset), status); + nirio_status_chain(_riok_proxy->get_attribute(RIO_FPGA_DEFAULT_SIGNATURE_OFFSET, sig_offset), status); niriok_scoped_addr_space(_riok_proxy, FPGA, status); std::string signature; for (boost::uint32_t i = 0; i < 8; i++) { boost::uint32_t quarter_sig; - nirio_status_chain(_riok_proxy.peek(sig_offset, quarter_sig), status); + nirio_status_chain(_riok_proxy->peek(sig_offset, quarter_sig), status); signature += boost::str(boost::format("%08x") % quarter_sig); } @@ -172,7 +170,7 @@ std::string niusrprio_session::_read_bitstream_checksum() std::string usr_signature; for (boost::uint32_t i = 0; i < FPGA_USR_SIG_REG_SIZE; i+=4) { boost::uint32_t quarter_sig; - nirio_status_chain(_riok_proxy.peek(FPGA_USR_SIG_REG_BASE + i, quarter_sig), status); + nirio_status_chain(_riok_proxy->peek(FPGA_USR_SIG_REG_BASE + i, quarter_sig), status); usr_signature += boost::str(boost::format("%08x") % quarter_sig); } boost::to_upper(usr_signature); @@ -193,7 +191,7 @@ nirio_status niusrprio_session::_write_bitstream_checksum(const std::string& che } catch (std::exception&) { quarter_sig = 0; } - nirio_status_chain(_riok_proxy.poke(FPGA_USR_SIG_REG_BASE + i, quarter_sig), status); + nirio_status_chain(_riok_proxy->poke(FPGA_USR_SIG_REG_BASE + i, quarter_sig), status); } return status; } @@ -206,14 +204,14 @@ nirio_status niusrprio_session::_ensure_fpga_ready() //Verify that the Ettus FPGA loaded in the device. This may not be true if the //user is switching to UHD after using LabVIEW FPGA. In that case skip this check. boost::uint32_t pcie_fpga_signature = 0; - nirio_status_chain(_riok_proxy.peek(FPGA_PCIE_SIG_REG, pcie_fpga_signature), status); + nirio_status_chain(_riok_proxy->peek(FPGA_PCIE_SIG_REG, pcie_fpga_signature), status); //@TODO: Remove X300 specific constants for future products if (pcie_fpga_signature != FPGA_X3xx_SIG_VALUE) { return status; } boost::uint32_t reg_data = 0xffffffff; - nirio_status_chain(_riok_proxy.peek(FPGA_STATUS_REG, reg_data), status); + nirio_status_chain(_riok_proxy->peek(FPGA_STATUS_REG, reg_data), status); if (nirio_status_not_fatal(status) && (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK)) { //In case this session was re-initialized *immediately* after the previous @@ -224,27 +222,27 @@ nirio_status niusrprio_session::_ensure_fpga_ready() //Disable all FIFOs in the FPGA for (size_t i = 0; i < _lvbitx->get_input_fifo_count(); i++) { - _riok_proxy.poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, i), DMA_CTRL_DISABLED); + _riok_proxy->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, i), DMA_CTRL_DISABLED); } for (size_t i = 0; i < _lvbitx->get_output_fifo_count(); i++) { - _riok_proxy.poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, i), DMA_CTRL_DISABLED); + _riok_proxy->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, i), DMA_CTRL_DISABLED); } //Disable all FIFOs in the kernel driver - _riok_proxy.stop_all_fifos(); + _riok_proxy->stop_all_fifos(); boost::posix_time::ptime start_time = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration elapsed; do { boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //Avoid flooding the bus elapsed = boost::posix_time::microsec_clock::local_time() - start_time; - nirio_status_chain(_riok_proxy.peek(FPGA_STATUS_REG, reg_data), status); + nirio_status_chain(_riok_proxy->peek(FPGA_STATUS_REG, reg_data), status); } while ( nirio_status_not_fatal(status) && (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK) && elapsed.total_milliseconds() < FPGA_READY_TIMEOUT_IN_MS); - nirio_status_chain(_riok_proxy.peek(FPGA_STATUS_REG, reg_data), status); + nirio_status_chain(_riok_proxy->peek(FPGA_STATUS_REG, reg_data), status); if (nirio_status_not_fatal(status) && (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK)) { return NiRio_Status_FifoReserved; } diff --git a/host/lib/transport/nirio_zero_copy.cpp b/host/lib/transport/nirio_zero_copy.cpp index 3bb822720..7ba8cb4c8 100644 --- a/host/lib/transport/nirio_zero_copy.cpp +++ b/host/lib/transport/nirio_zero_copy.cpp @@ -145,27 +145,27 @@ public: size_t actual_depth = 0, actual_size = 0; //Disable DMA streams in case last shutdown was unclean (cleanup, so don't status chain) - _proxy().poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); - _proxy().poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); + _proxy()->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); + _proxy()->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); _wait_until_stream_ready(); //Configure frame width nirio_status_chain( - _proxy().poke(PCIE_TX_DMA_REG(DMA_FRAME_SIZE_REG, _fifo_instance), + _proxy()->poke(PCIE_TX_DMA_REG(DMA_FRAME_SIZE_REG, _fifo_instance), static_cast<uint32_t>(_xport_params.send_frame_size/sizeof(fifo_data_t))), status); nirio_status_chain( - _proxy().poke(PCIE_RX_DMA_REG(DMA_FRAME_SIZE_REG, _fifo_instance), + _proxy()->poke(PCIE_RX_DMA_REG(DMA_FRAME_SIZE_REG, _fifo_instance), static_cast<uint32_t>(_xport_params.recv_frame_size/sizeof(fifo_data_t))), status); //Config 32-bit word flipping and enable DMA streams nirio_status_chain( - _proxy().poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), + _proxy()->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_SW_BUF_U32 | DMA_CTRL_ENABLED), status); nirio_status_chain( - _proxy().poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), + _proxy()->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_SW_BUF_U32 | DMA_CTRL_ENABLED), status); @@ -190,7 +190,7 @@ public: actual_depth, actual_size), status); - _proxy().get_rio_quirks().add_tx_fifo(_fifo_instance); + _proxy()->get_rio_quirks().add_tx_fifo(_fifo_instance); nirio_status_chain(_recv_fifo->start(), status); nirio_status_chain(_send_fifo->start(), status); @@ -217,11 +217,11 @@ public: virtual ~nirio_zero_copy_impl() { - _proxy().get_rio_quirks().remove_tx_fifo(_fifo_instance); + _proxy()->get_rio_quirks().remove_tx_fifo(_fifo_instance); //Disable DMA streams (cleanup, so don't status chain) - _proxy().poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); - _proxy().poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); + _proxy()->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); + _proxy()->poke(PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), DMA_CTRL_DISABLED); _flush_rx_buff(); @@ -259,7 +259,7 @@ public: private: - UHD_INLINE niriok_proxy& _proxy() { return _fpga_session->get_kernel_proxy(); } + UHD_INLINE niriok_proxy::sptr _proxy() { return _fpga_session->get_kernel_proxy(); } UHD_INLINE void _flush_rx_buff() { @@ -297,10 +297,10 @@ private: boost::posix_time::time_duration elapsed; nirio_status status = NiRio_Status_Success; - nirio_status_chain(_proxy().peek( + nirio_status_chain(_proxy()->peek( PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), reg_data), status); tx_busy = (reg_data & DMA_STATUS_BUSY); - nirio_status_chain(_proxy().peek( + nirio_status_chain(_proxy()->peek( PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), reg_data), status); rx_busy = (reg_data & DMA_STATUS_BUSY); @@ -309,10 +309,10 @@ private: do { boost::this_thread::sleep(boost::posix_time::microsec(50)); //Avoid flooding the bus elapsed = boost::posix_time::microsec_clock::local_time() - start_time; - nirio_status_chain(_proxy().peek( + nirio_status_chain(_proxy()->peek( PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), reg_data), status); tx_busy = (reg_data & DMA_STATUS_BUSY); - nirio_status_chain(_proxy().peek( + nirio_status_chain(_proxy()->peek( PCIE_RX_DMA_REG(DMA_CTRL_STATUS_REG, _fifo_instance), reg_data), status); rx_busy = (reg_data & DMA_STATUS_BUSY); } while ( diff --git a/host/lib/usrp/common/adf435x_common.cpp b/host/lib/usrp/common/adf435x_common.cpp index 972a69388..9b362a4d9 100644 --- a/host/lib/usrp/common/adf435x_common.cpp +++ b/host/lib/usrp/common/adf435x_common.cpp @@ -17,6 +17,7 @@ #include "adf435x_common.hpp" +#include <boost/math/special_functions/round.hpp> #include <uhd/types/tune_request.hpp> #include <uhd/utils/log.hpp> #include <cmath> @@ -96,7 +97,7 @@ adf435x_tuning_settings tune_adf435x_synth( //Fractional-N calculation MOD = 4095; //max fractional accuracy - FRAC = static_cast<boost::uint16_t>((feedback_freq/pfd_freq - N)*MOD); + FRAC = static_cast<boost::uint16_t>(boost::math::round((feedback_freq/pfd_freq - N)*MOD)); if (constraints.force_frac0) { if (FRAC > (MOD / 2)) { //Round integer such that actual freq is closest to target N++; diff --git a/host/lib/usrp/x300/x300_fw_ctrl.cpp b/host/lib/usrp/x300/x300_fw_ctrl.cpp index 804d23f51..3a8d984fb 100644 --- a/host/lib/usrp/x300/x300_fw_ctrl.cpp +++ b/host/lib/usrp/x300/x300_fw_ctrl.cpp @@ -187,16 +187,16 @@ private: class x300_ctrl_iface_pcie : public x300_ctrl_iface { public: - x300_ctrl_iface_pcie(niriok_proxy& drv_proxy): + x300_ctrl_iface_pcie(niriok_proxy::sptr drv_proxy): _drv_proxy(drv_proxy) { nirio_status status = 0; - nirio_status_chain(_drv_proxy.set_attribute(ADDRESS_SPACE, BUS_INTERFACE), status); + nirio_status_chain(_drv_proxy->set_attribute(RIO_ADDRESS_SPACE, BUS_INTERFACE), status); //Verify that the Ettus FPGA loaded in the device. This may not be true if the //user is switching to UHD after using LabVIEW FPGA. boost::uint32_t pcie_fpga_signature = 0; - _drv_proxy.peek(FPGA_PCIE_SIG_REG, pcie_fpga_signature); + _drv_proxy->peek(FPGA_PCIE_SIG_REG, pcie_fpga_signature); if (pcie_fpga_signature != FPGA_X3xx_SIG_VALUE) throw uhd::io_error("cannot create x300_ctrl_iface_pcie. incorrect/no fpga image"); @@ -209,7 +209,7 @@ public: do { boost::this_thread::sleep(boost::posix_time::microsec(500)); //Avoid flooding the bus elapsed = boost::posix_time::microsec_clock::local_time() - start_time; - nirio_status_chain(_drv_proxy.peek(PCIE_ZPU_STATUS_REG(0), reg_data), status); + nirio_status_chain(_drv_proxy->peek(PCIE_ZPU_STATUS_REG(0), reg_data), status); } while ( nirio_status_not_fatal(status) && (reg_data & PCIE_ZPU_STATUS_SUSPENDED) && @@ -232,12 +232,12 @@ protected: boost::posix_time::ptime start_time = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration elapsed; - nirio_status_chain(_drv_proxy.poke(PCIE_ZPU_DATA_REG(addr), data), status); + nirio_status_chain(_drv_proxy->poke(PCIE_ZPU_DATA_REG(addr), data), status); if (nirio_status_not_fatal(status)) { do { boost::this_thread::sleep(boost::posix_time::microsec(50)); //Avoid flooding the bus elapsed = boost::posix_time::microsec_clock::local_time() - start_time; - nirio_status_chain(_drv_proxy.peek(PCIE_ZPU_STATUS_REG(addr), reg_data), status); + nirio_status_chain(_drv_proxy->peek(PCIE_ZPU_STATUS_REG(addr), reg_data), status); } while ( nirio_status_not_fatal(status) && ((reg_data & (PCIE_ZPU_STATUS_BUSY | PCIE_ZPU_STATUS_SUSPENDED)) != 0) && @@ -257,18 +257,18 @@ protected: boost::posix_time::ptime start_time = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration elapsed; - nirio_status_chain(_drv_proxy.poke(PCIE_ZPU_READ_REG(addr), PCIE_ZPU_READ_START), status); + nirio_status_chain(_drv_proxy->poke(PCIE_ZPU_READ_REG(addr), PCIE_ZPU_READ_START), status); if (nirio_status_not_fatal(status)) { do { boost::this_thread::sleep(boost::posix_time::microsec(50)); //Avoid flooding the bus elapsed = boost::posix_time::microsec_clock::local_time() - start_time; - nirio_status_chain(_drv_proxy.peek(PCIE_ZPU_STATUS_REG(addr), reg_data), status); + nirio_status_chain(_drv_proxy->peek(PCIE_ZPU_STATUS_REG(addr), reg_data), status); } while ( nirio_status_not_fatal(status) && ((reg_data & (PCIE_ZPU_STATUS_BUSY | PCIE_ZPU_STATUS_SUSPENDED)) != 0) && elapsed.total_milliseconds() < READ_TIMEOUT_IN_MS); } - nirio_status_chain(_drv_proxy.peek(PCIE_ZPU_DATA_REG(addr), reg_data), status); + nirio_status_chain(_drv_proxy->peek(PCIE_ZPU_DATA_REG(addr), reg_data), status); if (nirio_status_fatal(status)) throw uhd::io_error("x300 fw peek32 - hardware IO error"); @@ -284,7 +284,7 @@ protected: } private: - niriok_proxy& _drv_proxy; + niriok_proxy::sptr _drv_proxy; static const boost::uint32_t READ_TIMEOUT_IN_MS = 10; static const boost::uint32_t INIT_TIMEOUT_IN_MS = 5000; }; @@ -294,7 +294,7 @@ wb_iface::sptr x300_make_ctrl_iface_enet(uhd::transport::udp_simple::sptr udp) return wb_iface::sptr(new x300_ctrl_iface_enet(udp)); } -wb_iface::sptr x300_make_ctrl_iface_pcie(niriok_proxy& drv_proxy) +wb_iface::sptr x300_make_ctrl_iface_pcie(niriok_proxy::sptr drv_proxy) { return wb_iface::sptr(new x300_ctrl_iface_pcie(drv_proxy)); } diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index 1494a100e..b4286ee79 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -171,8 +171,8 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu default: continue; } - - niriok_proxy kernel_proxy; + + niriok_proxy::sptr kernel_proxy = niriok_proxy::make_and_open(dev_info.interface_path); //Attempt to read the name from the EEPROM and perform filtering. //This operation can throw due to compatibility mismatch. @@ -192,7 +192,6 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu if (get_pcie_zpu_iface_registry().has_key(resource_d)) { zpu_ctrl = get_pcie_zpu_iface_registry()[resource_d].lock(); } else { - kernel_proxy.open(dev_info.interface_path); zpu_ctrl = x300_make_ctrl_iface_pcie(kernel_proxy); //We don't put this zpu_ctrl in the registry because we need //a persistent niriok_proxy associated with the object @@ -220,7 +219,6 @@ static device_addrs_t x300_find_pcie(const device_addr_t &hint, bool explicit_qu new_addr["name"] = ""; new_addr["serial"] = ""; } - kernel_proxy.close(); //filter the discovered device below by matching optional keys std::string resource_i = hint.has_key("resource") ? hint["resource"] : ""; @@ -403,7 +401,6 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) have a valid USRP X3x0, NI USRP-294xR or NI USRP-295xR device and that all the device \ driver have been loaded."); } - //Load the lvbitx onto the device UHD_MSG(status) << boost::format("Using LVBITX bitfile %s...\n") % lvbitx->get_bitfile_path(); mb.rio_fpga_interface.reset(new niusrprio_session(dev_addr["resource"], rpc_port_name)); @@ -412,7 +409,7 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t &dev_addr) //Tell the quirks object which FIFOs carry TX stream data const boost::uint32_t tx_data_fifos[2] = {X300_RADIO_DEST_PREFIX_TX, X300_RADIO_DEST_PREFIX_TX + 3}; - mb.rio_fpga_interface->get_kernel_proxy().get_rio_quirks().register_tx_streams(tx_data_fifos); + mb.rio_fpga_interface->get_kernel_proxy()->get_rio_quirks().register_tx_streams(tx_data_fifos); _tree->create<double>(mb_path / "link_max_rate").set(X300_MAX_RATE_PCIE); } @@ -1303,7 +1300,7 @@ boost::uint32_t x300_impl::allocate_sid(mboard_members_t &mb, const sid_config_t if (xport_path == "nirio") { boost::uint32_t router_config_word = ((_sid_framer & 0xff) << 16) | //Return SID get_pcie_dma_channel(config.router_dst_there, config.dst_prefix); //Dest - mb.rio_fpga_interface->get_kernel_proxy().poke(PCIE_ROUTER_REG(0), router_config_word); + mb.rio_fpga_interface->get_kernel_proxy()->poke(PCIE_ROUTER_REG(0), router_config_word); } UHD_LOG << std::hex @@ -1683,7 +1680,7 @@ x300_impl::x300_mboard_t x300_impl::get_mb_type_from_pcie(const std::string& res niriok_proxy::sptr discovery_proxy = niusrprio_session::create_kernel_proxy(resource, rpc_port); if (discovery_proxy) { - nirio_status_chain(discovery_proxy->get_attribute(PRODUCT_NUMBER, pid), status); + nirio_status_chain(discovery_proxy->get_attribute(RIO_PRODUCT_NUMBER, pid), status); discovery_proxy->close(); if (nirio_status_not_fatal(status)) { //The PCIe ID -> MB mapping may be different from the EEPROM -> MB mapping diff --git a/host/lib/usrp/x300/x300_impl.hpp b/host/lib/usrp/x300/x300_impl.hpp index 8abdee48c..924cb61a4 100644 --- a/host/lib/usrp/x300/x300_impl.hpp +++ b/host/lib/usrp/x300/x300_impl.hpp @@ -137,7 +137,7 @@ uhd::usrp::dboard_iface::sptr x300_make_dboard_iface(const x300_dboard_iface_con uhd::uart_iface::sptr x300_make_uart_iface(uhd::wb_iface::sptr iface); uhd::wb_iface::sptr x300_make_ctrl_iface_enet(uhd::transport::udp_simple::sptr udp); -uhd::wb_iface::sptr x300_make_ctrl_iface_pcie(uhd::niusrprio::niriok_proxy& drv_proxy); +uhd::wb_iface::sptr x300_make_ctrl_iface_pcie(uhd::niusrprio::niriok_proxy::sptr drv_proxy); class x300_impl : public uhd::device { |