diff options
author | Ashish Chaudhari <ashish@ettus.com> | 2014-10-10 17:24:40 -0700 |
---|---|---|
committer | Ashish Chaudhari <ashish@ettus.com> | 2014-10-10 17:24:40 -0700 |
commit | cca10287170e8ad50740791e7cbe715b642c2a87 (patch) | |
tree | c2ba1fe383b94a1f49d9a79f5301582567330dcf /host/include | |
parent | f30c5fee2a8d05f424ae1d733d0d99006eff930c (diff) | |
download | uhd-cca10287170e8ad50740791e7cbe715b642c2a87.tar.gz uhd-cca10287170e8ad50740791e7cbe715b642c2a87.tar.bz2 uhd-cca10287170e8ad50740791e7cbe715b642c2a87.zip |
x300,nirio: Added support for NI-RIO 14.0
- Split niriok_proxy interfaces to support NI-RIO <=13.0 and >=14.0 kernel interfaces
- Fixed multi-session race conditions by synchronizing niriok_proxy access
- Fixed bug switching from NI LV-FPGA access to UHD access by changing how devices are hashed into a reservation table
- Fixed calculation of FRAC values for CBX and SBX LO tuning by rounding instead of truncating
- Fixed bug that was not setting two MSBs for band select configuration of CBX LO
- Submitting on behalf of Patrick Sisterhen, Matthew Crymble
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/transport/nirio/nirio_driver_iface.h | 364 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/nirio_fifo.h | 24 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/nirio_fifo.ipp | 170 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/nirio_resource_manager.h | 33 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/niriok_proxy.h | 288 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h | 485 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h | 410 | ||||
-rw-r--r-- | host/include/uhd/transport/nirio/niusrprio_session.h | 4 |
8 files changed, 1184 insertions, 594 deletions
diff --git a/host/include/uhd/transport/nirio/nirio_driver_iface.h b/host/include/uhd/transport/nirio/nirio_driver_iface.h index 5b430b43d..83afd816a 100644 --- a/host/include/uhd/transport/nirio/nirio_driver_iface.h +++ b/host/include/uhd/transport/nirio/nirio_driver_iface.h @@ -76,370 +76,6 @@ const uint32_t NIRIO_IOCTL_PRE_CLOSE = FILE_READ_ACCESS); ///< Called before closing a session -// ------------------------------- -// Function Codes: defined as integers rather than enums because they -// are going to be carried accross boundaries so size matters - -namespace NIRIO_FUNC -{ - const uint32_t GET32 = 0x00000001; - const uint32_t SET32 = 0x00000002; - const uint32_t SET_DRIVER_CONFIG = 0x00000007; - const uint32_t FIFO = 0x00000008; - const uint32_t IO = 0x0000000A; - const uint32_t FIFO_STOP_ALL = 0x0000000C; - const uint32_t ADD_RESOURCE = 0x0000000D; - const uint32_t GET_STRING = 0x0000000E; - const uint32_t SET_STRING = 0x0000000F; - const uint32_t DOWNLOAD = 0x00000013; - const uint32_t RESET = 0x00000014; -} - -namespace NIRIO_RESOURCE -{ - const uint32_t INPUT_FIFO = 0xD0000001; - const uint32_t OUTPUT_FIFO = 0xD0000002; -} - -namespace NIRIO_FIFO -{ - const uint32_t CONFIGURE = 0x80000001; - const uint32_t START = 0x80000002; - const uint32_t STOP = 0x80000003; - const uint32_t READ = 0x80000004; - const uint32_t WRITE = 0x80000005; - const uint32_t WAIT = 0x80000006; - const uint32_t GRANT = 0x80000007; -} - -namespace NIRIO_IO -{ - const uint32_t POKE64 = 0xA0000005; - const uint32_t POKE32 = 0xA0000006; - const uint32_t POKE16 = 0xA0000007; - const uint32_t POKE8 = 0xA0000008; - const uint32_t PEEK64 = 0xA0000009; - const uint32_t PEEK32 = 0xA000000A; - const uint32_t PEEK16 = 0xA000000B; - const uint32_t PEEK8 = 0xA000000C; - const uint32_t READ_BLOCK = 0xA000000D; - const uint32_t WRITE_BLOCK = 0xA000000E; - const uint32_t GET_IO_WINDOW = 0xA000000F; - 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) - { - outBuf._64BitField = 0; - outBuf.pointer = _outBuf; - outSize = _outSize; - statusCode = _statusCode; - }; - - union { - void* pointer; - uint64_t _64BitField; - } outBuf; - - uint32_t outSize; - int32_t statusCode; -}; - -struct nirio_ioctl_block_t -{ - uint64_t inBuf; - uint64_t outBuf; - uint32_t inBufLength; - uint32_t outBufLength; - uint32_t bytesReturned; - uint32_t padding; -}; - -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 - { - uint32_t reserved_field_0_0_0; - } reserved_field_0_0; - struct - { - uint32_t reserved_field_0_1_0; - uint32_t reserved_field_0_1_1; - } reserved_field_0_1; - struct - { - uint32_t reserved_field_0_2_0; - } reserved_field_0_2; - } reserved_field_0; - - union - { - struct - { - uint32_t channel; - uint32_t baseAddress; - uint32_t depthInSamples; - uint32_t version; - } fifo; - struct - { - uint32_t channel; - uint32_t baseAddress; - uint32_t depthInSamples; - uint32_t version; - uint32_t scalarType; - uint32_t bitWidth; - } fifoWithDataType; - struct - { - uint64_t rangeBaseAddress; - uint32_t rangeSizeInBytes; - uint32_t rangeAttribute; - } atomic; // obsolete - } add; - - struct - { - uint32_t channel; - - union - { - struct - { - uint32_t requestedDepth; - uint8_t requiresActuals; - } config; - struct - { - uint32_t timeout; - } read; - struct - { - uint32_t timeout; - uint32_t scalarType; - uint32_t bitWidth; - } readWithDataType; - struct - { - uint32_t timeout; - } write; - struct - { - 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; - } wait; - struct - { - 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 - { - 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 - { - uint32_t reserved_field_4_0; - int32_t reserved_field_4_1; - } wait; - } reserved_field_4; - - } params; - - uint32_t inbufByteLen; - - 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; -} - - -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; - - struct - { - union - { - struct - { - uint32_t actualDepth; - uint32_t actualSize; - } config; - struct - { - uint32_t numberRead; - uint32_t numberRemaining; - } read; - struct - { - uint32_t numberRemaining; - } write; - struct - { - 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; - } value; - union - { - void* memoryMappedAddress; - uint64_t _64BitField; - } memoryMappedIoWindow; - union - { - uint32_t size; - } memoryMappedIoWindowSize; - }; - } io; - - uint32_t stringLength; - - struct - { - uint32_t reserved_field_1_0; - } reserved_field_1; - - } params; - - uint32_t outbufByteLen; - - 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; -} - - - //Device handle definition #if defined(UHD_PLATFORM_LINUX) typedef int rio_dev_handle_t; diff --git a/host/include/uhd/transport/nirio/nirio_fifo.h b/host/include/uhd/transport/nirio/nirio_fifo.h index 14ebeeff9..c424275fc 100644 --- a/host/include/uhd/transport/nirio/nirio_fifo.h +++ b/host/include/uhd/transport/nirio/nirio_fifo.h @@ -31,25 +31,9 @@ namespace uhd { namespace niusrprio { -enum fifo_direction_t { - INPUT_FIFO, - OUTPUT_FIFO -}; - -enum nirio_scalar_t { - SCALAR_I8 = 1UL, - SCALAR_I16 = 2UL, - SCALAR_I32 = 3UL, - SCALAR_I64 = 4UL, - SCALAR_U8 = 5UL, - SCALAR_U16 = 6UL, - SCALAR_U32 = 7UL, - SCALAR_U64 = 8UL -}; - struct datatype_info_t { - datatype_info_t(nirio_scalar_t t, uint32_t w):scalar_type(t),width(w) {} - nirio_scalar_t scalar_type; + datatype_info_t(nirio_scalar_type_t t, uint32_t w):scalar_type(t),width(w) {} + nirio_scalar_type_t scalar_type; uint32_t width; }; @@ -60,7 +44,7 @@ public: typedef boost::shared_ptr< nirio_fifo<data_t> > sptr; nirio_fifo( - niriok_proxy& riok_proxy, + niriok_proxy::sptr riok_proxy, fifo_direction_t direction, const std::string& name, uint32_t fifo_instance); @@ -122,7 +106,7 @@ private: //Members size_t _acquired_pending; nirio_driver_iface::rio_mmap_t _mem_map; boost::recursive_mutex _mutex; - niriok_proxy* _riok_proxy_ptr; + niriok_proxy::sptr _riok_proxy_ptr; uint64_t _expected_xfer_count; uint32_t _dma_base_addr; diff --git a/host/include/uhd/transport/nirio/nirio_fifo.ipp b/host/include/uhd/transport/nirio/nirio_fifo.ipp index 437e3a1fc..ca6486e30 100644 --- a/host/include/uhd/transport/nirio/nirio_fifo.ipp +++ b/host/include/uhd/transport/nirio/nirio_fifo.ipp @@ -23,7 +23,7 @@ template <typename data_t> nirio_fifo<data_t>::nirio_fifo( - niriok_proxy& riok_proxy, + niriok_proxy::sptr riok_proxy, fifo_direction_t direction, const std::string& name, uint32_t fifo_instance) : @@ -34,12 +34,12 @@ nirio_fifo<data_t>::nirio_fifo( _state(UNMAPPED), _acquired_pending(0), _mem_map(), - _riok_proxy_ptr(&riok_proxy), + _riok_proxy_ptr(riok_proxy), _expected_xfer_count(0), _dma_base_addr(0) { nirio_status status = 0; - nirio_status_chain(_riok_proxy_ptr->set_attribute(ADDRESS_SPACE, BUS_INTERFACE), status); + nirio_status_chain(_riok_proxy_ptr->set_attribute(RIO_ADDRESS_SPACE, BUS_INTERFACE), status); uint32_t base_addr, addr_space_word; nirio_status_chain(_riok_proxy_ptr->peek(0x1C, base_addr), status); nirio_status_chain(_riok_proxy_ptr->peek(0xC, addr_space_word), status); @@ -63,27 +63,24 @@ nirio_status nirio_fifo<data_t>::initialize( boost::unique_lock<boost::recursive_mutex> lock(_mutex); if (_state == UNMAPPED) { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; + + uint32_t actual_depth_u32 = 0; + uint32_t actual_size_u32 = 0; //Forcefully stop the fifo if it is running - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::STOP; - in.params.fifo.channel = _fifo_channel; - _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); //Cleanup operation. Ignore status. + _riok_proxy_ptr->stop_fifo(_fifo_channel); //Cleanup operation. Ignore status. //Configure the FIFO now that we know it is stopped - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::CONFIGURE; - in.params.fifo.channel = _fifo_channel; - in.params.fifo.op.config.requestedDepth = static_cast<uint32_t>(requested_depth); - in.params.fifo.op.config.requiresActuals = 1; - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); - + status = _riok_proxy_ptr->configure_fifo( + _fifo_channel, + static_cast<uint32_t>(requested_depth), + 1, + actual_depth_u32, + actual_size_u32); if (nirio_status_fatal(status)) return status; - actual_depth = out.params.fifo.op.config.actualDepth; - actual_size = out.params.fifo.op.config.actualSize; + actual_depth = static_cast<size_t>(actual_depth_u32); + actual_size = static_cast<size_t>(actual_size_u32); status = _riok_proxy_ptr->map_fifo_memory(_fifo_channel, actual_size, _mem_map); @@ -121,15 +118,8 @@ nirio_status nirio_fifo<data_t>::start() if (_state == STARTED) { //Do nothing. Already started. } else if (_state == MAPPED) { - 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; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::START; - in.params.fifo.channel = _fifo_channel; - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); + status = _riok_proxy_ptr->start_fifo(_fifo_channel); if (nirio_status_not_fatal(status)) { _state = STARTED; _acquired_pending = 0; @@ -152,15 +142,7 @@ nirio_status nirio_fifo<data_t>::stop() if (_state == STARTED) { if (_acquired_pending > 0) release(_acquired_pending); - 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; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::STOP; - - in.params.fifo.channel = _fifo_channel; - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); + status = _riok_proxy_ptr->stop_fifo(_fifo_channel); _state = MAPPED; //Assume teardown succeeded } @@ -182,27 +164,24 @@ nirio_status nirio_fifo<data_t>::acquire( boost::unique_lock<boost::recursive_mutex> lock(_mutex); if (_state == STARTED) { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - uint32_t stuffed[2]; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - init_syncop_out_params(out, stuffed, sizeof(stuffed)); - - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::WAIT; - - in.params.fifo.channel = _fifo_channel; - in.params.fifo.op.wait.elementsRequested = static_cast<uint32_t>(elements_requested); - in.params.fifo.op.wait.scalarType = static_cast<uint32_t>(_datatype_info.scalar_type); - in.params.fifo.op.wait.bitWidth = _datatype_info.width * 8; - in.params.fifo.op.wait.output = _fifo_direction == OUTPUT_FIFO; - in.params.fifo.op.wait.timeout = timeout; - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); + uint32_t elements_acquired_u32 = 0; + uint32_t elements_remaining_u32 = 0; + void* elements_buffer = static_cast<void*>(elements); + status = _riok_proxy_ptr->wait_on_fifo( + _fifo_channel, + static_cast<uint32_t>(elements_requested), + static_cast<uint32_t>(_datatype_info.scalar_type), + _datatype_info.width * 8, + timeout, + _fifo_direction == OUTPUT_FIFO, + elements_buffer, + elements_acquired_u32, + elements_remaining_u32); if (nirio_status_not_fatal(status)) { - elements = static_cast<data_t*>(out.params.fifo.op.wait.elements.pointer); - elements_acquired = stuffed[0]; - elements_remaining = stuffed[1]; + elements = static_cast<data_t*>(elements_buffer); + elements_acquired = static_cast<size_t>(elements_acquired_u32); + elements_remaining = static_cast<size_t>(elements_remaining_u32); _acquired_pending = elements_acquired; if (UHD_NIRIO_RX_FIFO_XFER_CHECK_EN && @@ -229,16 +208,9 @@ nirio_status nirio_fifo<data_t>::release(const size_t elements) boost::unique_lock<boost::recursive_mutex> lock(_mutex); if (_state == STARTED) { - 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; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::GRANT; - - in.params.fifo.channel = _fifo_channel; - in.params.fifo.op.grant.elements = static_cast<uint32_t>(elements); - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); + status = _riok_proxy_ptr->grant_fifo( + _fifo_channel, + static_cast<uint32_t>(elements)); _acquired_pending = 0; } else { status = NiRio_Status_ResourceNotInitialized; @@ -261,24 +233,16 @@ nirio_status nirio_fifo<data_t>::read( boost::unique_lock<boost::recursive_mutex> lock(_mutex); if (_state == STARTED) { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - init_syncop_out_params(out, buf, num_elements * _datatype_info.width); - - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::READ; - - in.params.fifo.channel = _fifo_channel; - in.params.fifo.op.readWithDataType.timeout = timeout; - in.params.fifo.op.readWithDataType.scalarType = static_cast<uint32_t>(_datatype_info.scalar_type); - in.params.fifo.op.readWithDataType.bitWidth = _datatype_info.width * 8; - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); - - if (nirio_status_not_fatal(status) || status == NiRio_Status_FifoTimeout) { - num_read = out.params.fifo.op.read.numberRead; - num_remaining = out.params.fifo.op.read.numberRemaining; - } + status = _riok_proxy_ptr->read_fifo( + _fifo_channel, + num_elements, + static_cast<void*>(buf), + _datatype_info.width, + static_cast<uint32_t>(_datatype_info.scalar_type), + _datatype_info.width * 8, + timeout, + num_read, + num_remaining); } else { status = NiRio_Status_ResourceNotInitialized; } @@ -299,23 +263,15 @@ nirio_status nirio_fifo<data_t>::write( boost::unique_lock<boost::recursive_mutex> lock(_mutex); if (_state == STARTED) { - nirio_driver_iface::nirio_syncop_in_params_t in = {}; - init_syncop_in_params(in, buf, num_elements * _datatype_info.width); - nirio_driver_iface::nirio_syncop_out_params_t out = {}; - - in.function = nirio_driver_iface::NIRIO_FUNC::FIFO; - in.subfunction = nirio_driver_iface::NIRIO_FIFO::WRITE; - - in.params.fifo.channel = _fifo_channel; - in.params.fifo.op.writeWithDataType.timeout = timeout; - in.params.fifo.op.readWithDataType.scalarType = static_cast<uint32_t>(_datatype_info.scalar_type); - in.params.fifo.op.readWithDataType.bitWidth = _datatype_info.width * 8; - - status = _riok_proxy_ptr->sync_operation(&in, sizeof(in), &out, sizeof(out)); - - if (nirio_status_not_fatal(status) || status == NiRio_Status_FifoTimeout) { - num_remaining = out.params.fifo.op.write.numberRemaining; - } + status = _riok_proxy_ptr->write_fifo( + _fifo_channel, + num_elements, + buf, + _datatype_info.width, + static_cast<uint32_t>(_datatype_info.scalar_type), + _datatype_info.width * 8, + timeout, + num_remaining); } else { status = NiRio_Status_ResourceNotInitialized; } @@ -374,49 +330,49 @@ nirio_status nirio_fifo<data_t>::_ensure_transfer_completed(uint32_t timeout_ms) template <> inline datatype_info_t nirio_fifo<int8_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_I8, 1); + return datatype_info_t(RIO_SCALAR_TYPE_IB, 1); } template <> inline datatype_info_t nirio_fifo<int16_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_I16, 2); + return datatype_info_t(RIO_SCALAR_TYPE_IW, 2); } template <> inline datatype_info_t nirio_fifo<int32_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_I32, 4); + return datatype_info_t(RIO_SCALAR_TYPE_IL, 4); } template <> inline datatype_info_t nirio_fifo<int64_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_I64, 8); + return datatype_info_t(RIO_SCALAR_TYPE_IQ, 8); } template <> inline datatype_info_t nirio_fifo<uint8_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_U8, 1); + return datatype_info_t(RIO_SCALAR_TYPE_UB, 1); } template <> inline datatype_info_t nirio_fifo<uint16_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_U16, 2); + return datatype_info_t(RIO_SCALAR_TYPE_UW, 2); } template <> inline datatype_info_t nirio_fifo<uint32_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_U32, 4); + return datatype_info_t(RIO_SCALAR_TYPE_UL, 4); } template <> inline datatype_info_t nirio_fifo<uint64_t>::_get_datatype_info() { - return datatype_info_t(SCALAR_U64, 8); + return datatype_info_t(RIO_SCALAR_TYPE_UQ, 8); } #ifdef __GNUC__ diff --git a/host/include/uhd/transport/nirio/nirio_resource_manager.h b/host/include/uhd/transport/nirio/nirio_resource_manager.h index 8c0e373d7..c71f1c8aa 100644 --- a/host/include/uhd/transport/nirio/nirio_resource_manager.h +++ b/host/include/uhd/transport/nirio/nirio_resource_manager.h @@ -50,35 +50,7 @@ struct nirio_register_info_t { typedef std::vector<nirio_register_info_t> nirio_register_info_vtr; -struct nirio_fifo_info_t { - nirio_fifo_info_t( - uint32_t arg_channel, - const char* arg_name, - fifo_direction_t arg_direction, - uint32_t arg_base_addr, - uint32_t arg_depth, - nirio_scalar_t arg_scalar_type, - uint32_t arg_width, - uint32_t arg_version) : - channel(arg_channel), - name(arg_name), - direction(arg_direction), - base_addr(arg_base_addr), - depth(arg_depth), - scalar_type(arg_scalar_type), - width(arg_width), - version(arg_version) - {} - uint32_t channel; - std::string name; - fifo_direction_t direction; - uint32_t base_addr; - uint32_t depth; - nirio_scalar_t scalar_type; - uint32_t width; - uint32_t version; -}; typedef std::vector<nirio_fifo_info_t> nirio_fifo_info_vtr; @@ -86,7 +58,8 @@ typedef std::vector<nirio_fifo_info_t> nirio_fifo_info_vtr; class nirio_resource_manager { public: - nirio_resource_manager(niriok_proxy& proxy); + nirio_resource_manager(); + void set_proxy(niriok_proxy::sptr proxy); virtual ~nirio_resource_manager(); nirio_status initialize(const nirio_register_info_vtr& reg_info_vtr, const nirio_fifo_info_vtr& fifo_info_vtr); @@ -137,7 +110,7 @@ private: nirio_status _set_driver_config(); nirio_fifo_info_t* _lookup_fifo_info(const char* fifo_name); - niriok_proxy& _kernel_proxy; + niriok_proxy::sptr _kernel_proxy; fifo_info_map_t _fifo_info_map; register_info_map_t _reg_info_map; }; diff --git a/host/include/uhd/transport/nirio/niriok_proxy.h b/host/include/uhd/transport/nirio/niriok_proxy.h index 85eaf3167..5ea796dec 100644 --- a/host/include/uhd/transport/nirio/niriok_proxy.h +++ b/host/include/uhd/transport/nirio/niriok_proxy.h @@ -21,38 +21,38 @@ #include <stdint.h> #include <boost/smart_ptr.hpp> #include <boost/noncopyable.hpp> +#include <boost/thread/shared_mutex.hpp> +#include <boost/thread/locks.hpp> +#include <boost/thread/shared_lock_guard.hpp> #include <uhd/transport/nirio/nirio_driver_iface.h> #include <uhd/transport/nirio/nirio_quirks.h> +#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))) + +#define READER_LOCK \ + boost::shared_lock_guard<boost::shared_mutex> reader_lock(_synchronization); + +#define WRITER_LOCK \ + boost::lock_guard<boost::shared_mutex> writer_lock(_synchronization); + + namespace uhd { namespace niusrprio { enum nirio_version_t { CURRENT, OLDEST_COMPATIBLE }; - enum nirio_device_attr_32_t { - INTERFACE_NUMBER = 1UL, - PRODUCT_NUMBER = 2UL, - VENDOR_NUMBER = 3UL, - SERIAL_NUMBER = 4UL, - BUS_NUMBER = 10UL, - DEVICE_NUMBER = 11UL, - FUNCTION_NUMBER = 12UL, - CURRENT_VERSION = 14UL, - OLDEST_COMPATIBLE_VERSION = 15UL, - ADDRESS_SPACE = 25UL, - IS_FPGA_PROGRAMMED = 48UL, - DEFAULT_FPGA_SIGNATURE_OFFSET = 53UL, - DEFAULT_FPGA_RESET_OFFSET = 54UL, - DEFAULT_FPGA_RESET_SIZE = 55UL, - DEFAULT_FPGA_CONTROL_OFFSET = 56UL, - DEFAULT_FPGA_INTERRUPT_OFFSET = 57UL, - }; - - enum nirio_device_attr_str_t { - PRODUCT_NAME = 0UL, - FPGA_TARGET_CLASS = 6UL, - SAVED_BITFILE = 7UL, - }; - enum nirio_addr_space_t { INVALID = 0, BUS_INTERFACE = 1, @@ -60,101 +60,247 @@ namespace uhd { namespace niusrprio BAR_WINDOW = 3, }; + typedef uint64_t nirio_u64_t; + typedef uint32_t nirio_u32_t; + typedef uint16_t nirio_u16_t; + typedef uint8_t nirio_u8_t; + typedef int32_t nirio_i32_t; + + typedef enum { + RIO_PRODUCT_NUMBER = 2UL, // 200 + RIO_CURRENT_VERSION = 14UL, // 220 + RIO_OLDEST_COMPATIBLE_VERSION = 15UL, // 220 + RIO_ADDRESS_SPACE = 25UL, // 230 + RIO_IS_FPGA_PROGRAMMED = 48UL, // 300 + RIO_FPGA_DEFAULT_SIGNATURE_OFFSET = 53UL, // 300 Default Offsets for FPGA + // registers. Supplied by + // the board driver on device + // start. + } nirio_device_attribute32_t; + + typedef enum { + RIO_SCALAR_TYPE_IB = 1UL, + RIO_SCALAR_TYPE_IW = 2UL, + RIO_SCALAR_TYPE_IL = 3UL, + RIO_SCALAR_TYPE_IQ = 4UL, + RIO_SCALAR_TYPE_UB = 5UL, + RIO_SCALAR_TYPE_UW = 6UL, + RIO_SCALAR_TYPE_UL = 7UL, + RIO_SCALAR_TYPE_UQ = 8UL, + } nirio_scalar_type_t; + + static inline nirio_scalar_type_t map_int_to_scalar_type(uint32_t scalar_type_as_int) + { + switch (scalar_type_as_int) + { + case 1: return RIO_SCALAR_TYPE_IB; + case 2: return RIO_SCALAR_TYPE_IW; + case 3: return RIO_SCALAR_TYPE_IL; + case 4: return RIO_SCALAR_TYPE_IQ; + case 5: return RIO_SCALAR_TYPE_UB; + case 6: return RIO_SCALAR_TYPE_UW; + case 7: return RIO_SCALAR_TYPE_UL; + case 8: return RIO_SCALAR_TYPE_UQ; + default: UHD_ASSERT_THROW(false); return RIO_SCALAR_TYPE_UL; + } + } + + enum fifo_direction_t { + INPUT_FIFO, + OUTPUT_FIFO + }; + + struct nirio_fifo_info_t { + nirio_fifo_info_t( + uint32_t arg_channel, + const char* arg_name, + fifo_direction_t arg_direction, + uint32_t arg_base_addr, + uint32_t arg_depth, + nirio_scalar_type_t arg_scalar_type, + uint32_t arg_bitWidth, + int32_t arg_integerWordLength, + uint32_t arg_version) : + channel(arg_channel), + name(arg_name), + direction(arg_direction), + base_addr(arg_base_addr), + depth(arg_depth), + scalar_type(arg_scalar_type), + bitWidth(arg_bitWidth), + integerWordLength(arg_integerWordLength), + version(arg_version) + {} + + uint32_t channel; + std::string name; + fifo_direction_t direction; + uint32_t base_addr; + uint32_t depth; + nirio_scalar_type_t scalar_type; + uint32_t bitWidth; + int32_t integerWordLength; + uint32_t version; + }; class UHD_API niriok_proxy : public boost::noncopyable { public: - typedef boost::shared_ptr<niriok_proxy> sptr; + struct nirio_ioctl_packet_t { + nirio_ioctl_packet_t( + void* const _outBuf, + const uint32_t _outSize, + const int32_t _statusCode) + { + outBuf._64BitField = 0; + outBuf.pointer = _outBuf; + outSize = _outSize; + statusCode = _statusCode; + }; + + union { + void* pointer; + uint64_t _64BitField; + } outBuf; + + uint32_t outSize; + int32_t statusCode; + }; + typedef boost::shared_ptr<niriok_proxy> sptr; + + static sptr make_and_open(const std::string& interface_path); niriok_proxy(); virtual ~niriok_proxy(); //File operations - nirio_status open(const std::string& interface_path); - void close(void); + virtual nirio_status open(const std::string& interface_path) = 0; + virtual void close(void) = 0; - nirio_status reset(); + virtual nirio_status reset() = 0; - inline uint32_t get_interface_num() { return _interface_num; } + uint32_t get_interface_num() { return _interface_num; } - nirio_status get_cached_session( - uint32_t& session); + virtual nirio_status get_cached_session( + uint32_t& session) = 0; - nirio_status get_version( + virtual nirio_status get_version( nirio_version_t type, uint32_t& major, uint32_t& upgrade, uint32_t& maintenance, char& phase, - uint32_t& build); - - nirio_status sync_operation( - const void *writeBuffer, - size_t writeBufferLength, - void *readBuffer, - size_t readBufferLength); - - nirio_status get_attribute( - const nirio_device_attr_32_t attribute, - uint32_t& attrValue); + uint32_t& build) = 0; - nirio_status get_attribute( - const nirio_device_attr_str_t attribute, - char* buf, - const uint32_t bufLen, - uint32_t& stringLen); + virtual nirio_status get_attribute( + const nirio_device_attribute32_t attribute, + uint32_t& attrValue) = 0; - nirio_status set_attribute( - const nirio_device_attr_32_t attribute, - const uint32_t value); + virtual nirio_status set_attribute( + const nirio_device_attribute32_t attribute, + const uint32_t value) = 0; - nirio_status set_attribute( - const nirio_device_attr_str_t attribute, - const char* const buffer); + virtual nirio_status peek(uint32_t offset, uint32_t& value) = 0; - nirio_status peek(uint32_t offset, uint32_t& value); + virtual nirio_status peek(uint32_t offset, uint64_t& value) = 0; - nirio_status peek(uint32_t offset, uint64_t& value); + virtual nirio_status poke(uint32_t offset, const uint32_t& value) = 0; - nirio_status poke(uint32_t offset, const uint32_t& value); + virtual nirio_status poke(uint32_t offset, const uint64_t& value) = 0; - nirio_status poke(uint32_t offset, const uint64_t& value); - - nirio_status map_fifo_memory( + virtual nirio_status map_fifo_memory( uint32_t fifo_instance, size_t size, - nirio_driver_iface::rio_mmap_t& map); + nirio_driver_iface::rio_mmap_t& map) = 0; - nirio_status unmap_fifo_memory( - nirio_driver_iface::rio_mmap_t& map); + virtual nirio_status unmap_fifo_memory( + nirio_driver_iface::rio_mmap_t& map) = 0; - nirio_status stop_all_fifos(); + virtual nirio_status stop_all_fifos() = 0; nirio_quirks& get_rio_quirks() { return _rio_quirks; } - private: //Members + virtual nirio_status add_fifo_resource(const nirio_fifo_info_t& fifo_info) = 0; + + virtual nirio_status set_device_config() = 0; + + virtual nirio_status start_fifo( + uint32_t channel) = 0; + + virtual nirio_status stop_fifo( + uint32_t channel) = 0; + + virtual nirio_status configure_fifo( + uint32_t channel, + uint32_t requested_depth, + uint8_t requires_actuals, + uint32_t& actual_depth, + uint32_t& actual_size) = 0; + + virtual nirio_status 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) = 0; + + virtual nirio_status grant_fifo( + uint32_t channel, + uint32_t elements_to_grant) = 0; + + virtual nirio_status 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) = 0; + + virtual nirio_status 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) = 0; + + protected: //Members nirio_driver_iface::rio_dev_handle_t _device_handle; uint32_t _interface_num; nirio_quirks _rio_quirks; + + static boost::shared_mutex _synchronization; + + // protected close function that doesn't acquire synchronization lock + virtual void _close() = 0; }; class niriok_scoped_addr_space : public boost::noncopyable { public: - explicit niriok_scoped_addr_space(niriok_proxy& proxy, nirio_addr_space_t addr_space, nirio_status& status) : + explicit niriok_scoped_addr_space(niriok_proxy::sptr proxy, nirio_addr_space_t addr_space, nirio_status& status) : driver_proxy(proxy) { - cache_status = driver_proxy.get_attribute(ADDRESS_SPACE, cached_addr_space); - nirio_status_chain(driver_proxy.set_attribute(ADDRESS_SPACE, addr_space), status); + cache_status = driver_proxy->get_attribute(RIO_ADDRESS_SPACE, cached_addr_space); + nirio_status_chain(driver_proxy->set_attribute(RIO_ADDRESS_SPACE, addr_space), status); } ~niriok_scoped_addr_space() { if (nirio_status_not_fatal(cache_status)) - driver_proxy.set_attribute(ADDRESS_SPACE, cached_addr_space); + driver_proxy->set_attribute(RIO_ADDRESS_SPACE, cached_addr_space); } private: - niriok_proxy& driver_proxy; + niriok_proxy::sptr driver_proxy; uint32_t cached_addr_space; nirio_status cache_status; }; diff --git a/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h b/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h new file mode 100644 index 000000000..173d43ed6 --- /dev/null +++ b/host/include/uhd/transport/nirio/niriok_proxy_impl_v1.h @@ -0,0 +1,485 @@ +// +// 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/>. +// + +#ifndef INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V1_H +#define INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V1_H + +#include <boost/smart_ptr.hpp> +#include <boost/noncopyable.hpp> +#include <uhd/transport/nirio/nirio_driver_iface.h> +#include <uhd/transport/nirio/nirio_quirks.h> +#include <uhd/transport/nirio/niriok_proxy.h> + +namespace uhd { namespace niusrprio +{ + /* + This file defines the types, enumerations, and classes needed to + directly access a subset of the NI-RIO kernel interface. + These definitions are specific to NI-RIO versions < 14.0. These + are not compatible with NI-RIO 14.0 and later. + */ + + class UHD_API niriok_proxy_impl_v1 : virtual public niriok_proxy { + public: + + // ------------------------------- + // 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_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_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 + { + uint32_t reserved_field_0_0_0; + } reserved_field_0_0; + struct + { + uint32_t reserved_field_0_1_0; + uint32_t reserved_field_0_1_1; + } reserved_field_0_1; + struct + { + uint32_t reserved_field_0_2_0; + } reserved_field_0_2; + } reserved_field_0; + + union + { + struct + { + uint32_t channel; + uint32_t baseAddress; + uint32_t depthInSamples; + uint32_t version; + } fifo; + struct + { + uint32_t channel; + uint32_t baseAddress; + uint32_t depthInSamples; + uint32_t version; + uint32_t scalarType; + uint32_t bitWidth; + } fifoWithDataType; + struct + { + uint64_t rangeBaseAddress; + uint32_t rangeSizeInBytes; + uint32_t rangeAttribute; + } atomic; // obsolete + } add; + + struct + { + uint32_t channel; + + union + { + struct + { + uint32_t requestedDepth; + uint8_t requiresActuals; + } config; + struct + { + uint32_t timeout; + } read; + struct + { + uint32_t timeout; + uint32_t scalarType; + uint32_t bitWidth; + } readWithDataType; + struct + { + uint32_t timeout; + } write; + struct + { + 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; + } wait; + struct + { + 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 + { + 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 + { + uint32_t reserved_field_4_0; + int32_t reserved_field_4_1; + } wait; + } reserved_field_4; + + } params; + + uint32_t inbufByteLen; + + 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; + } + + + 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; + + struct + { + union + { + struct + { + uint32_t actualDepth; + uint32_t actualSize; + } config; + struct + { + uint32_t numberRead; + uint32_t numberRemaining; + } read; + struct + { + uint32_t numberRemaining; + } write; + struct + { + 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; + } value; + union + { + void* memoryMappedAddress; + uint64_t _64BitField; + } memoryMappedIoWindow; + union + { + uint32_t size; + } memoryMappedIoWindowSize; + }; + } io; + + uint32_t stringLength; + + struct + { + uint32_t reserved_field_1_0; + } reserved_field_1; + + } params; + + uint32_t outbufByteLen; + + 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; + } + + niriok_proxy_impl_v1(); + virtual ~niriok_proxy_impl_v1(); + + //File operations + virtual nirio_status open(const std::string& interface_path); + virtual void close(void); + + virtual nirio_status reset(); + + virtual nirio_status get_cached_session( + uint32_t& session); + + virtual nirio_status get_version( + nirio_version_t type, + uint32_t& major, + uint32_t& upgrade, + uint32_t& maintenance, + char& phase, + uint32_t& build); + + virtual nirio_status get_attribute( + const nirio_device_attribute32_t attribute, + uint32_t& attrValue); + + virtual nirio_status set_attribute( + const nirio_device_attribute32_t attribute, + const uint32_t value); + + virtual nirio_status peek(uint32_t offset, uint32_t& value); + + virtual nirio_status peek(uint32_t offset, uint64_t& value); + + virtual nirio_status poke(uint32_t offset, const uint32_t& value); + + virtual nirio_status poke(uint32_t offset, const uint64_t& value); + + virtual nirio_status map_fifo_memory( + uint32_t fifo_instance, + size_t size, + nirio_driver_iface::rio_mmap_t& map); + + virtual nirio_status unmap_fifo_memory( + nirio_driver_iface::rio_mmap_t& map); + + virtual nirio_status stop_all_fifos(); + + virtual nirio_status add_fifo_resource(const nirio_fifo_info_t& fifo_info); + + virtual nirio_status set_device_config(); + + virtual nirio_status start_fifo( + uint32_t channel); + + virtual nirio_status stop_fifo( + uint32_t channel); + + virtual nirio_status configure_fifo( + uint32_t channel, + uint32_t requested_depth, + uint8_t requires_actuals, + uint32_t& actual_depth, + uint32_t& actual_size); + + virtual nirio_status 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); + + virtual nirio_status grant_fifo( + uint32_t channel, + uint32_t elements_to_grant); + + virtual nirio_status 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); + + virtual nirio_status 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); + + protected: + // protected close function that doesn't acquire synchronization lock + virtual void _close(); + + private: + nirio_status sync_operation( + const void *writeBuffer, + size_t writeBufferLength, + void *readBuffer, + size_t readBufferLength); + + }; + +}} + +#endif /* INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V1_H */ diff --git a/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h b/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h new file mode 100644 index 000000000..333ab4348 --- /dev/null +++ b/host/include/uhd/transport/nirio/niriok_proxy_impl_v2.h @@ -0,0 +1,410 @@ +// +// 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/>. +// + +#ifndef INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V2_H +#define INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V2_H + +#include <boost/smart_ptr.hpp> +#include <boost/noncopyable.hpp> +#include <uhd/transport/nirio/nirio_driver_iface.h> +#include <uhd/transport/nirio/nirio_quirks.h> +#include <uhd/transport/nirio/niriok_proxy.h> + +#if __GNUC__ + typedef uint64_t tAlignedU64 __attribute__ ((aligned(8))); +#else + typedef uint64_t tAlignedU64; +#endif + +namespace uhd { namespace niusrprio +{ + /* + This file defines the types, enumerations, and classes needed to + directly access a subset of the NI-RIO kernel interface. + These definitions are specific to NI-RIO versions >= 14.0. These + are not compatible with NI-RIO versions older than 14.0. + */ + + #define IOCTL(type, function, access) \ + CTL_CODE((0x8000+type), (0x800+function), METHOD_BUFFERED, access) + + #define IOCTL_ACCESS_ANY (FILE_ANY_ACCESS) + #define IOCTL_ACCESS_READ (FILE_READ_ACCESS) + #define IOCTL_ACCESS_WRITE (FILE_WRITE_ACCESS) + #define IOCTL_ACCESS_RW (FILE_READ_ACCESS | FILE_WRITE_ACCESS) + + #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) + + typedef struct { + nirio_scalar_type_t scalarType; + nirio_u32_t bitWidth; + nirio_i32_t integerWordLength; + } nirio_fifo_data_type_t; + + class UHD_API niriok_proxy_impl_v2 : virtual public niriok_proxy { + public: + 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; + tAlignedU64 requestedDepth; + int32_t status; + } in_transport_fifo_config_t; + typedef struct out_transport_fifo_config + { + tAlignedU64 actualDepth; + tAlignedU64 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; + tAlignedU64 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; + tAlignedU64 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; + tAlignedU64 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 + { + tAlignedU64 elements; + tAlignedU64 elementsAcquired; + tAlignedU64 elementsRemaining; + int32_t status; + } out_transport_fifo_wait_t; + typedef struct in_transport_fifo_grant + { + uint32_t channel; + tAlignedU64 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 + { + tAlignedU64 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; + tAlignedU64 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(); + virtual ~niriok_proxy_impl_v2(); + + //File operations + virtual nirio_status open(const std::string& interface_path); + virtual void close(void); + + virtual nirio_status reset(); + + virtual nirio_status get_cached_session( + uint32_t& session); + + virtual nirio_status get_version( + nirio_version_t type, + uint32_t& major, + uint32_t& upgrade, + uint32_t& maintenance, + char& phase, + uint32_t& build); + + virtual nirio_status get_attribute( + const nirio_device_attribute32_t attribute, + uint32_t& attrValue); + + virtual nirio_status set_attribute( + const nirio_device_attribute32_t attribute, + const uint32_t value); + + virtual nirio_status peek(uint32_t offset, uint32_t& value); + + virtual nirio_status peek(uint32_t offset, uint64_t& value); + + virtual nirio_status poke(uint32_t offset, const uint32_t& value); + + virtual nirio_status poke(uint32_t offset, const uint64_t& value); + + virtual nirio_status map_fifo_memory( + uint32_t fifo_instance, + size_t size, + nirio_driver_iface::rio_mmap_t& map); + + virtual nirio_status unmap_fifo_memory( + nirio_driver_iface::rio_mmap_t& map); + + virtual nirio_status stop_all_fifos(); + + virtual nirio_status add_fifo_resource(const nirio_fifo_info_t& fifo_info); + + virtual nirio_status set_device_config(); + + virtual nirio_status start_fifo( + uint32_t channel); + + virtual nirio_status stop_fifo( + uint32_t channel); + + virtual nirio_status configure_fifo( + uint32_t channel, + uint32_t requested_depth, + uint8_t requires_actuals, + uint32_t& actual_depth, + uint32_t& actual_size); + + virtual nirio_status 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); + + virtual nirio_status grant_fifo( + uint32_t channel, + uint32_t elements_to_grant); + + virtual nirio_status 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); + + virtual nirio_status 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); + + protected: + // protected close function that doesn't acquire synchronization lock + virtual void _close(); + + }; + +}} + +#endif /* INCLUDED_UHD_TRANSPORT_NIRIO_NIRIO_PROXY_IMPL_V2_H */ diff --git a/host/include/uhd/transport/nirio/niusrprio_session.h b/host/include/uhd/transport/nirio/niusrprio_session.h index a684d98ae..246888175 100644 --- a/host/include/uhd/transport/nirio/niusrprio_session.h +++ b/host/include/uhd/transport/nirio/niusrprio_session.h @@ -91,7 +91,7 @@ public: return create_rx_fifo(_lvbitx->get_input_fifo_names()[fifo_instance], fifo); } - niriok_proxy& get_kernel_proxy() { + UHD_INLINE niriok_proxy::sptr get_kernel_proxy() { return _riok_proxy; } @@ -112,7 +112,7 @@ private: nifpga_lvbitx::sptr _lvbitx; std::string _interface_path; bool _session_open; - niriok_proxy _riok_proxy; + niriok_proxy::sptr _riok_proxy; nirio_resource_manager _resource_manager; usrprio_rpc::usrprio_rpc_client _rpc_client; boost::recursive_mutex _session_mutex; |