diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-08-19 12:17:50 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:11 -0800 |
commit | 0eb760f4db92dc0a97ea4924fa044e7a48820a54 (patch) | |
tree | e007dffed2cdabf506de6a39c632c51d704a5d92 /host/lib/transport | |
parent | 01d71420eff77336c23ef70459d17b44810e3a99 (diff) | |
download | uhd-0eb760f4db92dc0a97ea4924fa044e7a48820a54.tar.gz uhd-0eb760f4db92dc0a97ea4924fa044e7a48820a54.tar.bz2 uhd-0eb760f4db92dc0a97ea4924fa044e7a48820a54.zip |
niusrpio: Apply formatting
Diffstat (limited to 'host/lib/transport')
-rw-r--r-- | host/lib/transport/nirio/niusrprio_session.cpp | 128 |
1 files changed, 69 insertions, 59 deletions
diff --git a/host/lib/transport/nirio/niusrprio_session.cpp b/host/lib/transport/nirio/niusrprio_session.cpp index bda0ec1c1..b2ea659df 100644 --- a/host/lib/transport/nirio/niusrprio_session.cpp +++ b/host/lib/transport/nirio/niusrprio_session.cpp @@ -8,30 +8,31 @@ //@TODO: Move the register defs required by the class to a common location #include "../../usrp/x300/x300_regs.hpp" -#include <uhd/transport/nirio/niusrprio_session.h> #include <uhd/transport/nirio/nirio_fifo.h> +#include <uhd/transport/nirio/niusrprio_session.h> #include <uhd/transport/nirio/status.h> -#include <boost/format.hpp> +#include <stdio.h> #include <boost/algorithm/string.hpp> -#include <fstream> +#include <boost/format.hpp> #include <chrono> +#include <fstream> #include <thread> -#include <stdio.h> namespace { - constexpr uint32_t FPGA_READY_TIMEOUT_IN_MS = 1000; +constexpr uint32_t FPGA_READY_TIMEOUT_IN_MS = 1000; } 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(), - _rpc_client("localhost", rpc_port_name) +niusrprio_session::niusrprio_session( + const std::string& resource_name, const std::string& rpc_port_name) + : _resource_name(resource_name) + , _session_open(false) + , _resource_manager() + , _rpc_client("localhost", rpc_port_name) { - _riok_proxy = create_kernel_proxy(resource_name,rpc_port_name); - _resource_manager.set_proxy(_riok_proxy); + _riok_proxy = create_kernel_proxy(resource_name, rpc_port_name); + _resource_manager.set_proxy(_riok_proxy); } niusrprio_session::~niusrprio_session() @@ -39,7 +40,8 @@ niusrprio_session::~niusrprio_session() close(); } -nirio_status niusrprio_session::enumerate(const std::string& rpc_port_name, device_info_vtr& device_info_vtr) +nirio_status niusrprio_session::enumerate( + const std::string& rpc_port_name, device_info_vtr& device_info_vtr) { usrprio_rpc::usrprio_rpc_client temp_rpc_client("localhost", rpc_port_name); nirio_status status = temp_rpc_client.get_ctor_status(); @@ -47,9 +49,7 @@ nirio_status niusrprio_session::enumerate(const std::string& rpc_port_name, devi return status; } -nirio_status niusrprio_session::open( - nifpga_lvbitx::sptr lvbitx, - bool force_download) +nirio_status niusrprio_session::open(nifpga_lvbitx::sptr lvbitx, bool force_download) { boost::unique_lock<boost::recursive_mutex> lock(_session_mutex); @@ -59,25 +59,29 @@ nirio_status niusrprio_session::open( std::string bitfile_path(_lvbitx->get_bitfile_path()); std::string signature(_lvbitx->get_signature()); - //Make sure that the RPC client connected to the server properly + // Make sure that the RPC client connected to the server properly 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); + // 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); if (nirio_status_not_fatal(status)) { - //Bitfile build for a particular LVFPGA interface will have the same signature - //because the API of the bitfile does not change. Two files with the same signature - //can however have different bitstreams because of non-LVFPGA code differences. - //That is why we need another identifier to qualify the signature. The BIN - //checksum is a good candidate. + // Bitfile build for a particular LVFPGA interface will have the same signature + // because the API of the bitfile does not change. Two files with the same + // signature can however have different bitstreams because of non-LVFPGA code + // differences. That is why we need another identifier to qualify the signature. + // The BIN checksum is a good candidate. std::string lvbitx_checksum(_lvbitx->get_bitstream_checksum()); - uint16_t download_fpga = (force_download || (_read_bitstream_checksum() != lvbitx_checksum)) ? 1 : 0; + uint16_t download_fpga = + (force_download || (_read_bitstream_checksum() != lvbitx_checksum)) ? 1 : 0; nirio_status_chain(_ensure_fpga_ready(), status); nirio_status_chain(_rpc_client.niusrprio_open_session( - _resource_name, bitfile_path, signature, download_fpga), status); + _resource_name, bitfile_path, signature, download_fpga), + status); _session_open = nirio_status_not_fatal(status); if (nirio_status_not_fatal(status)) { @@ -101,7 +105,8 @@ void niusrprio_session::close(bool skip_reset) if (_session_open) { nirio_status status = NiRio_Status_Success; - if (!skip_reset) reset(); + if (!skip_reset) + reset(); nirio_status_chain(_rpc_client.niusrprio_close_session(_resource_name), status); _session_open = false; } @@ -113,33 +118,37 @@ nirio_status niusrprio_session::reset() return _rpc_client.niusrprio_reset_device(_resource_name); } -nirio_status niusrprio_session::download_bitstream_to_flash(const std::string& bitstream_path) +nirio_status niusrprio_session::download_bitstream_to_flash( + const std::string& bitstream_path) { boost::unique_lock<boost::recursive_mutex> lock(_session_mutex); return _rpc_client.niusrprio_download_fpga_to_flash(_resource_name, bitstream_path); } niriok_proxy::sptr niusrprio_session::create_kernel_proxy( - const std::string& resource_name, - const std::string& rpc_port_name) + const std::string& resource_name, const std::string& rpc_port_name) { usrprio_rpc::usrprio_rpc_client temp_rpc_client("localhost", rpc_port_name); nirio_status status = temp_rpc_client.get_ctor_status(); std::string interface_path; - nirio_status_chain(temp_rpc_client.niusrprio_get_interface_path(resource_name, interface_path), status); + nirio_status_chain( + temp_rpc_client.niusrprio_get_interface_path(resource_name, interface_path), + status); niriok_proxy::sptr proxy = niriok_proxy::make_and_open(interface_path); - + return proxy; } nirio_status niusrprio_session::_verify_signature() { - //Validate the signature using the kernel proxy + // Validate the signature using the kernel proxy nirio_status status = NiRio_Status_Success; uint32_t sig_offset = 0; - nirio_status_chain(_riok_proxy->get_attribute(RIO_FPGA_DEFAULT_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 (uint32_t i = 0; i < 8; i++) { @@ -163,9 +172,10 @@ std::string niusrprio_session::_read_bitstream_checksum() nirio_status status = NiRio_Status_Success; niriok_scoped_addr_space(_riok_proxy, BUS_INTERFACE, status); std::string usr_signature; - for (uint32_t i = 0; i < FPGA_USR_SIG_REG_SIZE; i+=4) { + for (uint32_t i = 0; i < FPGA_USR_SIG_REG_SIZE; i += 4) { 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); @@ -177,16 +187,17 @@ nirio_status niusrprio_session::_write_bitstream_checksum(const std::string& che { nirio_status status = NiRio_Status_Success; niriok_scoped_addr_space(_riok_proxy, BUS_INTERFACE, status); - for (uint32_t i = 0; i < FPGA_USR_SIG_REG_SIZE; i+=4) { + for (uint32_t i = 0; i < FPGA_USR_SIG_REG_SIZE; i += 4) { uint32_t quarter_sig; try { std::stringstream ss; - ss << std::hex << checksum.substr(i*2,8); + ss << std::hex << checksum.substr(i * 2, 8); ss >> quarter_sig; } 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; } @@ -196,8 +207,8 @@ nirio_status niusrprio_session::_ensure_fpga_ready() nirio_status status = NiRio_Status_Success; niriok_scoped_addr_space(_riok_proxy, 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. In that case skip this check. + // 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. uint32_t pcie_fpga_signature = 0; nirio_status_chain(_riok_proxy->peek(FPGA_PCIE_SIG_REG, pcie_fpga_signature), status); //@TODO: Remove X300 specific constants for future products @@ -207,16 +218,14 @@ nirio_status niusrprio_session::_ensure_fpga_ready() uint32_t reg_data = 0xffffffff; 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 - //there is a small chance that the server is still finishing up cleaning up - //the DMA FIFOs. We currently don't have any feedback from the driver regarding - //this state so just wait. - std::this_thread::sleep_for( - std::chrono::milliseconds(FPGA_READY_TIMEOUT_IN_MS)); - - //Disable all FIFOs in the FPGA + if (nirio_status_not_fatal(status) && (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK)) { + // In case this session was re-initialized *immediately* after the previous + // there is a small chance that the server is still finishing up cleaning up + // the DMA FIFOs. We currently don't have any feedback from the driver regarding + // this state so just wait. + std::this_thread::sleep_for(std::chrono::milliseconds(FPGA_READY_TIMEOUT_IN_MS)); + + // 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); } @@ -224,19 +233,20 @@ nirio_status niusrprio_session::_ensure_fpga_ready() _riok_proxy->poke(PCIE_TX_DMA_REG(DMA_CTRL_STATUS_REG, i), DMA_CTRL_DISABLED); } - //Disable all FIFOs in the kernel driver + // Disable all FIFOs in the kernel driver _riok_proxy->stop_all_fifos(); - boost::posix_time::ptime start_time = boost::posix_time::microsec_clock::local_time(); + boost::posix_time::ptime start_time = + boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration elapsed; do { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); //Avoid flooding the bus + std::this_thread::sleep_for( + std::chrono::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); - } while ( - nirio_status_not_fatal(status) && - (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK) && - elapsed.total_milliseconds() < FPGA_READY_TIMEOUT_IN_MS); + } 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); if (nirio_status_not_fatal(status) && (reg_data & FPGA_STATUS_DMA_ACTIVE_MASK)) { @@ -247,4 +257,4 @@ nirio_status niusrprio_session::_ensure_fpga_ready() return status; } -}} +}} // namespace uhd::niusrprio |