diff options
29 files changed, 1859 insertions, 1905 deletions
diff --git a/host/lib/rfnoc/async_msg_handler.cpp b/host/lib/rfnoc/async_msg_handler.cpp index b412eec9d..6b7d7d057 100644 --- a/host/lib/rfnoc/async_msg_handler.cpp +++ b/host/lib/rfnoc/async_msg_handler.cpp @@ -5,12 +5,12 @@ // #include <uhd/exception.hpp> -#include <uhd/utils/tasks.hpp> -#include <uhd/utils/byteswap.hpp> -#include <uhd/utils/log.hpp> +#include <uhd/transport/bounded_buffer.hpp> #include <uhd/transport/chdr.hpp> #include <uhd/transport/zero_copy.hpp> -#include <uhd/transport/bounded_buffer.hpp> +#include <uhd/utils/byteswap.hpp> +#include <uhd/utils/log.hpp> +#include <uhd/utils/tasks.hpp> #include <uhdlib/rfnoc/async_msg_handler.hpp> #include <boost/make_shared.hpp> #include <mutex> @@ -30,19 +30,13 @@ public: /************************************************************************ * Structors ***********************************************************************/ - async_msg_handler_impl( - uhd::transport::zero_copy_if::sptr recv, - uhd::transport::zero_copy_if::sptr send, - uhd::sid_t sid - ) : _rx_xport(recv), - _tx_xport(send), - _sid(sid) + async_msg_handler_impl(uhd::transport::zero_copy_if::sptr recv, + uhd::transport::zero_copy_if::sptr send, + uhd::sid_t sid) + : _rx_xport(recv), _tx_xport(send), _sid(sid) { // Launch receive thread - _recv_msg_task = task::make([=](){ - this->handle_async_msgs(); - } - ); + _recv_msg_task = task::make([=]() { this->handle_async_msgs(); }); } ~async_msg_handler_impl() {} @@ -51,23 +45,21 @@ public: * API calls ***********************************************************************/ int register_event_handler( - const async_msg_t::event_code_t event_code, - async_handler_type handler - ) { - _event_handlers.insert(std::pair<async_msg_t::event_code_t, async_handler_type>(event_code, handler)); + const async_msg_t::event_code_t event_code, async_handler_type handler) + { + _event_handlers.insert(std::pair<async_msg_t::event_code_t, async_handler_type>( + event_code, handler)); return _event_handlers.count(event_code); } - void post_async_msg( - const async_msg_t &metadata - ) { + void post_async_msg(const async_msg_t& metadata) + { std::lock_guard<std::mutex> lock(_mutex); for (auto const event_handler : _event_handlers) { // If the event code in the message matches the event code used at // registration time, call the event handler - if ((metadata.event_code & event_handler.first) - == event_handler.first) { + if ((metadata.event_code & event_handler.first) == event_handler.first) { event_handler.second(metadata); } } @@ -75,15 +67,13 @@ public: // Print if (metadata.event_code & async_msg_t::EVENT_CODE_UNDERFLOW) { UHD_LOG_FASTPATH("U") - } else if (metadata.event_code & - ( async_msg_t::EVENT_CODE_SEQ_ERROR - | async_msg_t::EVENT_CODE_SEQ_ERROR_IN_BURST) - ) { + } else if (metadata.event_code + & (async_msg_t::EVENT_CODE_SEQ_ERROR + | async_msg_t::EVENT_CODE_SEQ_ERROR_IN_BURST)) { UHD_LOG_FASTPATH("S") - } else if (metadata.event_code & - ( async_msg_t::EVENT_CODE_LATE_CMD_ERROR - | async_msg_t::EVENT_CODE_LATE_DATA_ERROR) - ) { + } else if (metadata.event_code + & (async_msg_t::EVENT_CODE_LATE_CMD_ERROR + | async_msg_t::EVENT_CODE_LATE_DATA_ERROR)) { UHD_LOG_FASTPATH("L") } else if (metadata.event_code & async_msg_t::EVENT_CODE_OVERRUN) { UHD_LOG_FASTPATH("O") @@ -96,7 +86,7 @@ private: // methods ***********************************************************************/ /*! Packet receiver thread call. */ - void handle_async_msgs( ) + void handle_async_msgs() { using namespace uhd::transport; managed_recv_buffer::sptr buff = _rx_xport->get_recv_buff(); @@ -105,10 +95,10 @@ private: // methods // Get packet info vrt::if_packet_info_t if_packet_info; - if_packet_info.num_packet_words32 = buff->size()/sizeof(uint32_t); - const uint32_t *packet_buff = buff->cast<const uint32_t *>(); + if_packet_info.num_packet_words32 = buff->size() / sizeof(uint32_t); + const uint32_t* packet_buff = buff->cast<const uint32_t*>(); - //unpacking can fail + // unpacking can fail uint32_t (*endian_conv)(uint32_t) = uhd::ntohx; try { if (_endianness == ENDIANNESS_BIG) { @@ -118,31 +108,30 @@ private: // methods vrt::chdr::if_hdr_unpack_le(packet_buff, if_packet_info); endian_conv = uhd::wtohx; } - } - catch (const uhd::value_error &ex) { - UHD_LOGGER_ERROR("RFNOC") << "[async message handler] Error parsing async message packet: " << ex.what() << std::endl; + } catch (const uhd::value_error& ex) { + UHD_LOGGER_ERROR("RFNOC") + << "[async message handler] Error parsing async message packet: " + << ex.what() << std::endl; return; } // We discard anything that's not actually a command or response packet. - if (not (if_packet_info.packet_type & vrt::if_packet_info_t::PACKET_TYPE_CMD) - or if_packet_info.num_packet_words32 == 0) { + if (not(if_packet_info.packet_type & vrt::if_packet_info_t::PACKET_TYPE_CMD) + or if_packet_info.num_packet_words32 == 0) { return; } - const uint32_t *payload = packet_buff + if_packet_info.num_header_words32; + const uint32_t* payload = packet_buff + if_packet_info.num_header_words32; async_msg_t metadata(if_packet_info.num_payload_words32 - 1); metadata.has_time_spec = if_packet_info.has_tsf; // FIXME: not hardcoding tick rate - metadata.time_spec = time_spec_t::from_ticks(if_packet_info.tsf, 1); - metadata.event_code = async_msg_t::event_code_t( - endian_conv(payload[0]) & 0xFFFF - ); - metadata.sid = if_packet_info.sid; + metadata.time_spec = time_spec_t::from_ticks(if_packet_info.tsf, 1); + metadata.event_code = async_msg_t::event_code_t(endian_conv(payload[0]) & 0xFFFF); + metadata.sid = if_packet_info.sid; - //load user payload + // load user payload for (size_t i = 1; i < if_packet_info.num_payload_words32; i++) { - metadata.payload[i-1] = endian_conv(payload[i]); + metadata.payload[i - 1] = endian_conv(payload[i]); } this->post_async_msg(metadata); @@ -152,16 +141,15 @@ private: // methods { return _sid.get_src(); } - -private: // members +private: // members std::mutex _mutex; //! Store event handlers std::multimap<async_msg_t::event_code_t, async_handler_type> _event_handlers; //! port that receive messge uhd::transport::zero_copy_if::sptr _rx_xport; - //!port that send out respond + //! port that send out respond uhd::transport::zero_copy_if::sptr _tx_xport; //! The source part of \p _sid is the address of this async message handler. @@ -171,20 +159,16 @@ private: // members task::sptr _recv_msg_task; }; -async_msg_handler::sptr async_msg_handler::make( - uhd::transport::zero_copy_if::sptr recv, +async_msg_handler::sptr async_msg_handler::make(uhd::transport::zero_copy_if::sptr recv, uhd::transport::zero_copy_if::sptr send, uhd::sid_t sid, - endianness_t endianness -) { + endianness_t endianness) +{ if (endianness == ENDIANNESS_BIG) { - return boost::make_shared< async_msg_handler_impl<ENDIANNESS_BIG> >( - recv, send, sid - ); + return boost::make_shared<async_msg_handler_impl<ENDIANNESS_BIG>>( + recv, send, sid); } else { - return boost::make_shared< async_msg_handler_impl<ENDIANNESS_LITTLE> >( - recv, send, sid - ); + return boost::make_shared<async_msg_handler_impl<ENDIANNESS_LITTLE>>( + recv, send, sid); } } - diff --git a/host/lib/rfnoc/block_ctrl_base.cpp b/host/lib/rfnoc/block_ctrl_base.cpp index dd89433a9..ed9ab11d4 100644 --- a/host/lib/rfnoc/block_ctrl_base.cpp +++ b/host/lib/rfnoc/block_ctrl_base.cpp @@ -9,19 +9,18 @@ // See block_ctrl_base_factory.cpp for discovery and factory functions. #include "nocscript/block_iface.hpp" - -#include <uhd/utils/log.hpp> #include <uhd/convert.hpp> #include <uhd/rfnoc/block_ctrl_base.hpp> #include <uhd/rfnoc/constants.hpp> -#include <uhdlib/utils/compat_check.hpp> +#include <uhd/utils/log.hpp> +#include <uhd/utils/safe_call.hpp> #include <uhdlib/rfnoc/ctrl_iface.hpp> #include <uhdlib/rfnoc/wb_iface_adapter.hpp> -#include <boost/format.hpp> +#include <uhdlib/utils/compat_check.hpp> #include <boost/bind.hpp> +#include <boost/format.hpp> #include <chrono> #include <thread> -#include <uhd/utils/safe_call.hpp> using namespace uhd; using namespace uhd::rfnoc; using std::string; @@ -29,13 +28,12 @@ using std::string; /*********************************************************************** * Structors **********************************************************************/ -block_ctrl_base::block_ctrl_base( - const make_args_t &make_args -) : _tree(make_args.tree), - _ctrl_ifaces(make_args.ctrl_ifaces), - _base_address(make_args.base_address & 0xFFF0), - _noc_id(sr_read64(SR_READBACK_REG_ID)), - _compat_num(sr_read64(SR_READBACK_COMPAT)) +block_ctrl_base::block_ctrl_base(const make_args_t& make_args) + : _tree(make_args.tree) + , _ctrl_ifaces(make_args.ctrl_ifaces) + , _base_address(make_args.base_address & 0xFFF0) + , _noc_id(sr_read64(SR_READBACK_REG_ID)) + , _compat_num(sr_read64(SR_READBACK_COMPAT)) { /*** Identify this block (NoC-ID, block-ID, and block definition) *******/ // Read NoC-ID (name is passed in through make_args): @@ -43,8 +41,8 @@ block_ctrl_base::block_ctrl_base( if (not _block_def) { UHD_LOG_DEBUG("RFNOC", "No block definition found, using default block configuration " - "for block with NOC ID: " + str(boost::format("0x%08X") % _noc_id) - ); + "for block with NOC ID: " + + str(boost::format("0x%08X") % _noc_id)); _block_def = blockdef::make_from_noc_id(DEFAULT_NOC_ID); } UHD_ASSERT_THROW(_block_def); @@ -54,19 +52,16 @@ block_ctrl_base::block_ctrl_base( while (_tree->exists("xbar/" + _block_id.get_local())) { _block_id++; } - UHD_LOG_INFO(unique_id(), str( - boost::format("Initializing block control (NOC ID: 0x%016X)") - % _noc_id - )); + UHD_LOG_INFO(unique_id(), + str(boost::format("Initializing block control (NOC ID: 0x%016X)") % _noc_id)); /*** Check compat number ************************************************/ - assert_fpga_compat( - NOC_SHELL_COMPAT_MAJOR, - NOC_SHELL_COMPAT_MINOR, - _compat_num, - "noc_shell", - unique_id(), - false /* fail_on_minor_behind */ + assert_fpga_compat(NOC_SHELL_COMPAT_MAJOR, + NOC_SHELL_COMPAT_MINOR, + _compat_num, + "noc_shell", + unique_id(), + false /* fail_on_minor_behind */ ); /*** Initialize property tree *******************************************/ @@ -101,8 +96,10 @@ block_ctrl_base::block_ctrl_base( // Set sink buffer sizes: settingsbus_reg_t reg = SR_READBACK_REG_FIFOSIZE; size_t buf_size_bytes = size_t(sr_read64(reg, ctrl_port)); - if (buf_size_bytes > 0) n_valid_input_buffers++; - _tree->create<size_t>(_root_path / "input_buffer_size" / ctrl_port).set(buf_size_bytes); + if (buf_size_bytes > 0) + n_valid_input_buffers++; + _tree->create<size_t>(_root_path / "input_buffer_size" / ctrl_port) + .set(buf_size_bytes); // Set default destination SIDs // Otherwise, the default is someone else's SID, which we don't want sr_write(SR_RESP_IN_DST_SID, 0xFFFF, ctrl_port); @@ -111,27 +108,25 @@ block_ctrl_base::block_ctrl_base( /*** Register names *****************************************************/ blockdef::registers_t sregs = _block_def->get_settings_registers(); - for(const std::string ®_name: sregs.keys()) { + for (const std::string& reg_name : sregs.keys()) { if (DEFAULT_NAMED_SR.has_key(reg_name)) { - throw uhd::runtime_error(str( - boost::format("Register name %s is already defined!") - % reg_name - )); + throw uhd::runtime_error( + str(boost::format("Register name %s is already defined!") % reg_name)); } _tree->create<size_t>(_root_path / "registers" / "sr" / reg_name) .set(sregs.get(reg_name)); } blockdef::registers_t rbacks = _block_def->get_readback_registers(); - for(const std::string ®_name: rbacks.keys()) { - _tree->create<size_t>(_root_path / "registers"/ "rb" / reg_name) + for (const std::string& reg_name : rbacks.keys()) { + _tree->create<size_t>(_root_path / "registers" / "rb" / reg_name) .set(rbacks.get(reg_name)); } /*** Init I/O port definitions ******************************************/ - _init_port_defs("in", _block_def->get_input_ports()); + _init_port_defs("in", _block_def->get_input_ports()); _init_port_defs("out", _block_def->get_output_ports()); // FIXME this warning always fails until the input buffer code above is fixed - //if (_tree->list(_root_path / "ports/in").size() != n_valid_input_buffers) { + // if (_tree->list(_root_path / "ports/in").size() != n_valid_input_buffers) { // UHD_LOGGER_WARNING(unique_id()) << // boost::format("[%s] defines %d input buffer sizes, but %d input ports") // % get_block_id().get() @@ -147,27 +142,22 @@ block_ctrl_base::block_ctrl_base( block_ctrl_base::~block_ctrl_base() { - UHD_SAFE_CALL( - if (get_ctrl_ports().size() > 0) { - // Notify the data-path gatekeeper in noc_shell that we are done - // with this block. This operation disconnects the noc_block - // data-path from noc_shell which dumps all input and output - // packets that are in flight, for now and until the setting is - // disabled. This prevents long-running blocks without a tear-down - // mechanism to gracefully flush. - _start_drain(get_ctrl_ports().front()); - } - _tree->remove(_root_path); - ) + UHD_SAFE_CALL(if (get_ctrl_ports().size() > 0) { + // Notify the data-path gatekeeper in noc_shell that we are done + // with this block. This operation disconnects the noc_block + // data-path from noc_shell which dumps all input and output + // packets that are in flight, for now and until the setting is + // disabled. This prevents long-running blocks without a tear-down + // mechanism to gracefully flush. + _start_drain(get_ctrl_ports().front()); + } _tree->remove(_root_path);) } void block_ctrl_base::_init_port_defs( - const std::string &direction, - blockdef::ports_t ports, - const size_t first_port_index -) { + const std::string& direction, blockdef::ports_t ports, const size_t first_port_index) +{ size_t port_index = first_port_index; - for(const blockdef::port_t &port_def: ports) { + for (const blockdef::port_t& port_def : ports) { fs_path port_path = _root_path / "ports" / direction / port_index; if (not _tree->exists(port_path)) { _tree->create<blockdef::port_t>(port_path); @@ -175,10 +165,7 @@ void block_ctrl_base::_init_port_defs( UHD_LOGGER_TRACE(unique_id()) << "Adding port definition at " << port_path << boost::format(": type = '%s' pkt_size = '%s' vlen = '%s'") - % port_def["type"] - % port_def["pkt_size"] - % port_def["vlen"] - ; + % port_def["type"] % port_def["pkt_size"] % port_def["vlen"]; _tree->access<blockdef::port_t>(port_path).set(port_def); port_index++; } @@ -187,7 +174,7 @@ void block_ctrl_base::_init_port_defs( void block_ctrl_base::_init_block_args() { blockdef::args_t args = _block_def->get_args(); - fs_path arg_path = _root_path / "args"; + fs_path arg_path = _root_path / "args"; for (const size_t port : get_ctrl_ports()) { _tree->create<std::string>(arg_path / port); } @@ -196,32 +183,54 @@ void block_ctrl_base::_init_block_args() for (const auto& arg : args) { fs_path arg_type_path = arg_path / arg["port"] / arg["name"] / "type"; _tree->create<std::string>(arg_type_path).set(arg["type"]); - fs_path arg_val_path = arg_path / arg["port"] / arg["name"] / "value"; - if (arg["type"] == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } - else if (arg["type"] == "int") { _tree->create<int>(arg_val_path); } - else if (arg["type"] == "double") { _tree->create<double>(arg_val_path); } - else if (arg["type"] == "string") { _tree->create<string>(arg_val_path); } - else { UHD_THROW_INVALID_CODE_PATH(); } + fs_path arg_val_path = arg_path / arg["port"] / arg["name"] / "value"; + if (arg["type"] == "int_vector") { + throw uhd::runtime_error("not yet implemented: int_vector"); + } else if (arg["type"] == "int") { + _tree->create<int>(arg_val_path); + } else if (arg["type"] == "double") { + _tree->create<double>(arg_val_path); + } else if (arg["type"] == "string") { + _tree->create<string>(arg_val_path); + } else { + UHD_THROW_INVALID_CODE_PATH(); + } } // Next: Create all the subscribers and coercers. // TODO: Add coercer -#define _SUBSCRIBE_CHECK_AND_RUN(type, arg_tag, error_message) \ - _tree->access<type>(arg_val_path).add_coerced_subscriber(boost::bind((&nocscript::block_iface::run_and_check), _nocscript_iface, arg[#arg_tag], error_message)) +#define _SUBSCRIBE_CHECK_AND_RUN(type, arg_tag, error_message) \ + _tree->access<type>(arg_val_path) \ + .add_coerced_subscriber(boost::bind((&nocscript::block_iface::run_and_check), \ + _nocscript_iface, \ + arg[#arg_tag], \ + error_message)) for (const auto& arg : args) { fs_path arg_val_path = arg_path / arg["port"] / arg["name"] / "value"; if (not arg["check"].empty()) { - if (arg["type"] == "string") { _SUBSCRIBE_CHECK_AND_RUN(string, check, arg["check_message"]); } - else if (arg["type"] == "int") { _SUBSCRIBE_CHECK_AND_RUN(int, check, arg["check_message"]); } - else if (arg["type"] == "double") { _SUBSCRIBE_CHECK_AND_RUN(double, check, arg["check_message"]); } - else if (arg["type"] == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } - else { UHD_THROW_INVALID_CODE_PATH(); } + if (arg["type"] == "string") { + _SUBSCRIBE_CHECK_AND_RUN(string, check, arg["check_message"]); + } else if (arg["type"] == "int") { + _SUBSCRIBE_CHECK_AND_RUN(int, check, arg["check_message"]); + } else if (arg["type"] == "double") { + _SUBSCRIBE_CHECK_AND_RUN(double, check, arg["check_message"]); + } else if (arg["type"] == "int_vector") { + throw uhd::runtime_error("not yet implemented: int_vector"); + } else { + UHD_THROW_INVALID_CODE_PATH(); + } } if (not arg["action"].empty()) { - if (arg["type"] == "string") { _SUBSCRIBE_CHECK_AND_RUN(string, action, ""); } - else if (arg["type"] == "int") { _SUBSCRIBE_CHECK_AND_RUN(int, action, ""); } - else if (arg["type"] == "double") { _SUBSCRIBE_CHECK_AND_RUN(double, action, ""); } - else if (arg["type"] == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } - else { UHD_THROW_INVALID_CODE_PATH(); } + if (arg["type"] == "string") { + _SUBSCRIBE_CHECK_AND_RUN(string, action, ""); + } else if (arg["type"] == "int") { + _SUBSCRIBE_CHECK_AND_RUN(int, action, ""); + } else if (arg["type"] == "double") { + _SUBSCRIBE_CHECK_AND_RUN(double, action, ""); + } else if (arg["type"] == "int_vector") { + throw uhd::runtime_error("not yet implemented: int_vector"); + } else { + UHD_THROW_INVALID_CODE_PATH(); + } } } @@ -229,11 +238,17 @@ void block_ctrl_base::_init_block_args() for (const auto& arg : args) { fs_path arg_val_path = arg_path / arg["port"] / arg["name"] / "value"; if (not arg["value"].empty()) { - if (arg["type"] == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } - else if (arg["type"] == "int") { _tree->access<int>(arg_val_path).set(std::stoi(arg["value"])); } - else if (arg["type"] == "double") { _tree->access<double>(arg_val_path).set(std::stod(arg["value"])); } - else if (arg["type"] == "string") { _tree->access<string>(arg_val_path).set(arg["value"]); } - else { UHD_THROW_INVALID_CODE_PATH(); } + if (arg["type"] == "int_vector") { + throw uhd::runtime_error("not yet implemented: int_vector"); + } else if (arg["type"] == "int") { + _tree->access<int>(arg_val_path).set(std::stoi(arg["value"])); + } else if (arg["type"] == "double") { + _tree->access<double>(arg_val_path).set(std::stod(arg["value"])); + } else if (arg["type"] == "string") { + _tree->access<string>(arg_val_path).set(arg["value"]); + } else { + UHD_THROW_INVALID_CODE_PATH(); + } } } } @@ -243,12 +258,10 @@ void block_ctrl_base::_init_block_args() **********************************************************************/ timed_wb_iface::sptr block_ctrl_base::get_ctrl_iface(const size_t block_port) { - return boost::make_shared<wb_iface_adapter>( - _ctrl_ifaces[block_port], + return boost::make_shared<wb_iface_adapter>(_ctrl_ifaces[block_port], boost::bind(&block_ctrl_base::get_command_tick_rate, this, block_port), boost::bind(&block_ctrl_base::set_command_time, this, _1, block_port), - boost::bind(&block_ctrl_base::get_command_time, this, block_port) - ); + boost::bind(&block_ctrl_base::get_command_time, this, block_port)); } std::vector<size_t> block_ctrl_base::get_ctrl_ports() const @@ -256,7 +269,7 @@ std::vector<size_t> block_ctrl_base::get_ctrl_ports() const std::vector<size_t> ctrl_ports; ctrl_ports.reserve(_ctrl_ifaces.size()); std::pair<size_t, ctrl_iface::sptr> it; - for(auto it: _ctrl_ifaces) { + for (auto it : _ctrl_ifaces) { ctrl_ports.push_back(it.first); } return ctrl_ports; @@ -265,32 +278,31 @@ std::vector<size_t> block_ctrl_base::get_ctrl_ports() const void block_ctrl_base::sr_write(const uint32_t reg, const uint32_t data, const size_t port) { if (not _ctrl_ifaces.count(port)) { - throw uhd::key_error(str(boost::format("[%s] sr_write(): No such port: %d") % get_block_id().get() % port)); + throw uhd::key_error(str(boost::format("[%s] sr_write(): No such port: %d") + % get_block_id().get() % port)); } try { _ctrl_ifaces[port]->send_cmd_pkt( - reg, data, false, - _cmd_timespecs[port].to_ticks(_cmd_tickrates[port]) - ); - } - catch(const std::exception &ex) { - throw uhd::io_error(str(boost::format("[%s] sr_write() failed: %s") % get_block_id().get() % ex.what())); + reg, data, false, _cmd_timespecs[port].to_ticks(_cmd_tickrates[port])); + } catch (const std::exception& ex) { + throw uhd::io_error(str(boost::format("[%s] sr_write() failed: %s") + % get_block_id().get() % ex.what())); } } -void block_ctrl_base::sr_write(const std::string ®, const uint32_t data, const size_t port) +void block_ctrl_base::sr_write( + const std::string& reg, const uint32_t data, const size_t port) { uint32_t reg_addr = 255; if (DEFAULT_NAMED_SR.has_key(reg)) { reg_addr = DEFAULT_NAMED_SR[reg]; } else { if (not _tree->exists(_root_path / "registers" / "sr" / reg)) { - throw uhd::key_error(str( - boost::format("Unknown settings register name: %s") - % reg - )); + throw uhd::key_error( + str(boost::format("Unknown settings register name: %s") % reg)); } - reg_addr = uint32_t(_tree->access<size_t>(_root_path / "registers" / "sr" / reg).get()); + reg_addr = + uint32_t(_tree->access<size_t>(_root_path / "registers" / "sr" / reg).get()); } return sr_write(reg_addr, data, port); } @@ -298,34 +310,30 @@ void block_ctrl_base::sr_write(const std::string ®, const uint32_t data, cons uint64_t block_ctrl_base::sr_read64(const settingsbus_reg_t reg, const size_t port) { if (not _ctrl_ifaces.count(port)) { - throw uhd::key_error(str(boost::format("[%s] sr_read64(): No such port: %d") % get_block_id().get() % port)); + throw uhd::key_error(str(boost::format("[%s] sr_read64(): No such port: %d") + % get_block_id().get() % port)); } try { return _ctrl_ifaces[port]->send_cmd_pkt( - SR_READBACK, reg, - true, - _cmd_timespecs[port].to_ticks(_cmd_tickrates[port]) - ); - } - catch(const std::exception &ex) { - throw uhd::io_error(str(boost::format("[%s] sr_read64() failed: %s") % get_block_id().get() % ex.what())); + SR_READBACK, reg, true, _cmd_timespecs[port].to_ticks(_cmd_tickrates[port])); + } catch (const std::exception& ex) { + throw uhd::io_error(str(boost::format("[%s] sr_read64() failed: %s") + % get_block_id().get() % ex.what())); } } uint32_t block_ctrl_base::sr_read32(const settingsbus_reg_t reg, const size_t port) { if (not _ctrl_ifaces.count(port)) { - throw uhd::key_error(str(boost::format("[%s] sr_read32(): No such port: %d") % get_block_id().get() % port)); + throw uhd::key_error(str(boost::format("[%s] sr_read32(): No such port: %d") + % get_block_id().get() % port)); } try { return uint32_t(_ctrl_ifaces[port]->send_cmd_pkt( - SR_READBACK, reg, - true, - _cmd_timespecs[port].to_ticks(_cmd_tickrates[port]) - )); - } - catch(const std::exception &ex) { - throw uhd::io_error(str(boost::format("[%s] sr_read32() failed: %s") % get_block_id().get() % ex.what())); + SR_READBACK, reg, true, _cmd_timespecs[port].to_ticks(_cmd_tickrates[port]))); + } catch (const std::exception& ex) { + throw uhd::io_error(str(boost::format("[%s] sr_read32() failed: %s") + % get_block_id().get() % ex.what())); } } @@ -337,23 +345,21 @@ uint64_t block_ctrl_base::user_reg_read64(const uint32_t addr, const size_t port sr_write(SR_READBACK_ADDR, addr, port); // Read readback register via RFNoC return sr_read64(SR_READBACK_REG_USER, port); - } - catch(const std::exception &ex) { - throw uhd::io_error(str(boost::format("%s user_reg_read64() failed: %s") % get_block_id().get() % ex.what())); + } catch (const std::exception& ex) { + throw uhd::io_error(str(boost::format("%s user_reg_read64() failed: %s") + % get_block_id().get() % ex.what())); } } -uint64_t block_ctrl_base::user_reg_read64(const std::string ®, const size_t port) +uint64_t block_ctrl_base::user_reg_read64(const std::string& reg, const size_t port) { if (not _tree->exists(_root_path / "registers" / "rb" / reg)) { - throw uhd::key_error(str( - boost::format("Invalid readback register name: %s") - % reg - )); - } - return user_reg_read64(uint32_t( - _tree->access<size_t>(_root_path / "registers" / "rb" / reg).get() - ), port); + throw uhd::key_error( + str(boost::format("Invalid readback register name: %s") % reg)); + } + return user_reg_read64( + uint32_t(_tree->access<size_t>(_root_path / "registers" / "rb" / reg).get()), + port); } uint32_t block_ctrl_base::user_reg_read32(const uint32_t addr, const size_t port) @@ -363,31 +369,27 @@ uint32_t block_ctrl_base::user_reg_read32(const uint32_t addr, const size_t port sr_write(SR_READBACK_ADDR, addr, port); // Read readback register via RFNoC return sr_read32(SR_READBACK_REG_USER, port); - } - catch(const std::exception &ex) { - throw uhd::io_error(str(boost::format("[%s] user_reg_read32() failed: %s") % get_block_id().get() % ex.what())); + } catch (const std::exception& ex) { + throw uhd::io_error(str(boost::format("[%s] user_reg_read32() failed: %s") + % get_block_id().get() % ex.what())); } } -uint32_t block_ctrl_base::user_reg_read32(const std::string ®, const size_t port) +uint32_t block_ctrl_base::user_reg_read32(const std::string& reg, const size_t port) { if (not _tree->exists(_root_path / "registers" / "rb" / reg)) { - throw uhd::key_error(str( - boost::format("Invalid readback register name: %s") - % reg - )); - } - return user_reg_read32(uint32_t( - _tree->access<size_t>(_root_path / "registers" / "rb" / reg).get() - ), port); + throw uhd::key_error( + str(boost::format("Invalid readback register name: %s") % reg)); + } + return user_reg_read32( + uint32_t(_tree->access<size_t>(_root_path / "registers" / "rb" / reg).get()), + port); } -void block_ctrl_base::set_command_time( - const time_spec_t &time_spec, - const size_t port -) { +void block_ctrl_base::set_command_time(const time_spec_t& time_spec, const size_t port) +{ if (port == ANY_PORT) { - for(const size_t specific_port: get_ctrl_ports()) { + for (const size_t specific_port : get_ctrl_ports()) { set_command_time(time_spec, specific_port); } return; @@ -397,18 +399,15 @@ void block_ctrl_base::set_command_time( _set_command_time(time_spec, port); } -time_spec_t block_ctrl_base::get_command_time( - const size_t port -) { +time_spec_t block_ctrl_base::get_command_time(const size_t port) +{ return _cmd_timespecs[port]; } -void block_ctrl_base::set_command_tick_rate( - const double tick_rate, - const size_t port -) { +void block_ctrl_base::set_command_tick_rate(const double tick_rate, const size_t port) +{ if (port == ANY_PORT) { - for(const size_t specific_port: get_ctrl_ports()) { + for (const size_t specific_port : get_ctrl_ports()) { set_command_tick_rate(tick_rate, specific_port); } return; @@ -438,7 +437,8 @@ void block_ctrl_base::clear() } } -uint32_t block_ctrl_base::get_address(size_t block_port) { +uint32_t block_ctrl_base::get_address(size_t block_port) +{ UHD_ASSERT_THROW(block_port < 16); return (_base_address & 0xFFF0) | (block_port & 0xF); } @@ -446,97 +446,88 @@ uint32_t block_ctrl_base::get_address(size_t block_port) { /*********************************************************************** * Argument handling **********************************************************************/ -void block_ctrl_base::set_args(const uhd::device_addr_t &args, const size_t port) +void block_ctrl_base::set_args(const uhd::device_addr_t& args, const size_t port) { - for(const std::string &key: args.keys()) { + for (const std::string& key : args.keys()) { if (_tree->exists(get_arg_path(key, port))) { set_arg(key, args.get(key), port); } } } -void block_ctrl_base::set_arg(const std::string &key, const std::string &val, const size_t port) +void block_ctrl_base::set_arg( + const std::string& key, const std::string& val, const size_t port) { fs_path arg_path = get_arg_path(key, port); if (not _tree->exists(arg_path / "value")) { throw uhd::runtime_error(str( - boost::format("Attempting to set uninitialized argument '%s' on block '%s'") - % key % unique_id() - )); + boost::format("Attempting to set uninitialized argument '%s' on block '%s'") + % key % unique_id())); } - std::string type = _tree->access<std::string>(arg_path / "type").get(); + std::string type = _tree->access<std::string>(arg_path / "type").get(); fs_path arg_val_path = arg_path / "value"; try { if (type == "string") { _tree->access<std::string>(arg_val_path).set(val); - } - else if (type == "int") { + } else if (type == "int") { _tree->access<int>(arg_val_path).set(std::stoi(val)); - } - else if (type == "double") { + } else if (type == "double") { _tree->access<double>(arg_val_path).set(std::stod(val)); - } - else if (type == "int_vector") { + } else if (type == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } - } catch (const boost::bad_lexical_cast &) { - throw uhd::value_error(str( - boost::format("Error trying to cast value %s == '%s' to type '%s'") - % key % val % type - )); + } catch (const boost::bad_lexical_cast&) { + throw uhd::value_error( + str(boost::format("Error trying to cast value %s == '%s' to type '%s'") % key + % val % type)); } } device_addr_t block_ctrl_base::get_args(const size_t port) const { device_addr_t args; - for(const std::string &key: _tree->list(_root_path / "args" / port)) { + for (const std::string& key : _tree->list(_root_path / "args" / port)) { args[key] = get_arg(key); } return args; } -std::string block_ctrl_base::get_arg(const std::string &key, const size_t port) const +std::string block_ctrl_base::get_arg(const std::string& key, const size_t port) const { fs_path arg_path = get_arg_path(key, port); if (not _tree->exists(arg_path / "value")) { throw uhd::runtime_error(str( - boost::format("Attempting to get uninitialized argument '%s' on block '%s'") - % key % unique_id() - )); + boost::format("Attempting to get uninitialized argument '%s' on block '%s'") + % key % unique_id())); } - std::string type = _tree->access<std::string>(arg_path / "type").get(); + std::string type = _tree->access<std::string>(arg_path / "type").get(); fs_path arg_val_path = arg_path / "value"; if (type == "string") { return _tree->access<std::string>(arg_val_path).get(); - } - else if (type == "int") { + } else if (type == "int") { return std::to_string(_tree->access<int>(arg_val_path).get()); - } - else if (type == "double") { + } else if (type == "double") { return std::to_string(_tree->access<double>(arg_val_path).get()); - } - else if (type == "int_vector") { + } else if (type == "int_vector") { throw uhd::runtime_error("not yet implemented: int_vector"); } UHD_THROW_INVALID_CODE_PATH(); } -std::string block_ctrl_base::get_arg_type(const std::string &key, const size_t port) const +std::string block_ctrl_base::get_arg_type(const std::string& key, const size_t port) const { fs_path arg_type_path = _root_path / "args" / port / key / "type"; return _tree->access<std::string>(arg_type_path).get(); } -stream_sig_t block_ctrl_base::_resolve_port_def(const blockdef::port_t &port_def) const +stream_sig_t block_ctrl_base::_resolve_port_def(const blockdef::port_t& port_def) const { if (not port_def.is_valid()) { - throw uhd::runtime_error(str( - boost::format("Invalid port definition: %s") % port_def.to_string() - )); + throw uhd::runtime_error( + str(boost::format("Invalid port definition: %s") % port_def.to_string())); } // TODO this entire section is pretty dumb at this point. Needs better @@ -556,7 +547,7 @@ stream_sig_t block_ctrl_base::_resolve_port_def(const blockdef::port_t &port_def // Vector length if (port_def.is_variable("vlen")) { std::string var_name = port_def["vlen"].substr(1); - stream_sig.vlen = boost::lexical_cast<size_t>(get_arg(var_name)); + stream_sig.vlen = boost::lexical_cast<size_t>(get_arg(var_name)); } else if (port_def.is_keyword("vlen")) { throw uhd::runtime_error("keywords resolution for vlen not yet implemented"); } else { @@ -565,17 +556,19 @@ stream_sig_t block_ctrl_base::_resolve_port_def(const blockdef::port_t &port_def // Packet size if (port_def.is_variable("pkt_size")) { - std::string var_name = port_def["pkt_size"].substr(1); + std::string var_name = port_def["pkt_size"].substr(1); stream_sig.packet_size = boost::lexical_cast<size_t>(get_arg(var_name)); } else if (port_def.is_keyword("pkt_size")) { if (port_def["pkt_size"] != "%vlen") { - throw uhd::runtime_error("generic keywords resolution for pkt_size not yet implemented"); + throw uhd::runtime_error( + "generic keywords resolution for pkt_size not yet implemented"); } if (stream_sig.vlen == 0) { stream_sig.packet_size = 0; } else { if (stream_sig.item_type.empty()) { - throw uhd::runtime_error("cannot resolve pkt_size if item type is not given"); + throw uhd::runtime_error( + "cannot resolve pkt_size if item type is not given"); } size_t bpi = uhd::convert::get_bytes_per_item(stream_sig.item_type); stream_sig.packet_size = stream_sig.vlen * bpi; @@ -607,9 +600,11 @@ bool block_ctrl_base::_flush(const size_t port) // we want to make sure that the counts are not changing i.e. no data is // streaming. So we just look at the two counters together as a single // 32-bit quantity. - auto old_cnts = static_cast<uint32_t>(this->sr_read64(SR_READBACK_REG_GLOBAL_PARAMS) >> 32); + auto old_cnts = + static_cast<uint32_t>(this->sr_read64(SR_READBACK_REG_GLOBAL_PARAMS) >> 32); std::this_thread::sleep_for(std::chrono::milliseconds(time_ms)); - auto new_cnts = static_cast<uint32_t>(this->sr_read64(SR_READBACK_REG_GLOBAL_PARAMS) >> 32); + auto new_cnts = + static_cast<uint32_t>(this->sr_read64(SR_READBACK_REG_GLOBAL_PARAMS) >> 32); return (new_cnts != old_cnts); }; @@ -625,26 +620,28 @@ bool block_ctrl_base::_flush(const size_t port) // A timeout of 2s is chosen to be conservative. It needs to account for: // - Upstream blocks that weren't terminated to run out of FC credits // - This block which might be finishing up with its data output - constexpr int FLUSH_TIMEOUT_MS = 2000; // This is approximate - bool success = false; + constexpr int FLUSH_TIMEOUT_MS = 2000; // This is approximate + bool success = false; _start_drain(port); - for (int i = 0; i < FLUSH_TIMEOUT_MS/10; i++) { + for (int i = 0; i < FLUSH_TIMEOUT_MS / 10; i++) { if (not is_data_streaming(10)) { success = true; break; } } // Stop flushing - sr_write(SR_CLEAR_TX_FC, 0x0, port); // Enable TX data-path - sr_write(SR_CLEAR_RX_FC, 0x0, port); // Enable RX data-path + sr_write(SR_CLEAR_TX_FC, 0x0, port); // Enable TX data-path + sr_write(SR_CLEAR_RX_FC, 0x0, port); // Enable RX data-path if (not success) { // Print a warning only if data was still flushing // after the timeout elapsed - UHD_LOGGER_WARNING(unique_id()) << - "This block seems to be busy most likely due to the abnormal termination of a previous " - "session. Attempted recovery but it may not have worked depending on the behavior of " - "other blocks in the design. Please restart the application."; + UHD_LOGGER_WARNING(unique_id()) + << "This block seems to be busy most likely due to the abnormal termination " + "of a previous " + "session. Attempted recovery but it may not have worked depending on the " + "behavior of " + "other blocks in the design. Please restart the application."; } return success; } @@ -656,13 +653,14 @@ bool block_ctrl_base::_flush(const size_t port) void block_ctrl_base::_clear(const size_t port) { UHD_LOG_TRACE(unique_id(), "block_ctrl_base::_clear()"); - sr_write(SR_CLEAR_TX_FC, 0x1, port); // Write 1 to trigger a single cycle clear event - sr_write(SR_CLEAR_TX_FC, 0x0, port); // Write 0 to reset the clear flag - sr_write(SR_CLEAR_RX_FC, 0x1, port); // Write 1 to trigger a single cycle clear event - sr_write(SR_CLEAR_RX_FC, 0x0, port); // Write 0 to reset the clear flag + sr_write(SR_CLEAR_TX_FC, 0x1, port); // Write 1 to trigger a single cycle clear event + sr_write(SR_CLEAR_TX_FC, 0x0, port); // Write 0 to reset the clear flag + sr_write(SR_CLEAR_RX_FC, 0x1, port); // Write 1 to trigger a single cycle clear event + sr_write(SR_CLEAR_RX_FC, 0x0, port); // Write 0 to reset the clear flag } -void block_ctrl_base::_set_command_time(const time_spec_t & /*time_spec*/, const size_t /*port*/) +void block_ctrl_base::_set_command_time( + const time_spec_t& /*time_spec*/, const size_t /*port*/) { UHD_LOG_TRACE(unique_id(), "block_ctrl_base::_set_command_time()"); } diff --git a/host/lib/rfnoc/block_ctrl_base_factory.cpp b/host/lib/rfnoc/block_ctrl_base_factory.cpp index 554db5acf..6f3e9d9f7 100644 --- a/host/lib/rfnoc/block_ctrl_base_factory.cpp +++ b/host/lib/rfnoc/block_ctrl_base_factory.cpp @@ -5,11 +5,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/format.hpp> - -#include <uhd/utils/log.hpp> -#include <uhd/rfnoc/blockdef.hpp> #include <uhd/rfnoc/block_ctrl_base.hpp> +#include <uhd/rfnoc/blockdef.hpp> +#include <uhd/utils/log.hpp> +#include <boost/format.hpp> using namespace uhd; using namespace uhd::rfnoc; @@ -18,14 +17,13 @@ typedef uhd::dict<std::string, block_ctrl_base::make_t> block_fcn_reg_t; // Instantiate the block function registry container UHD_SINGLETON_FCN(block_fcn_reg_t, get_block_fcn_regs); -void block_ctrl_base::register_block( - const make_t &make, - const std::string &key -) { +void block_ctrl_base::register_block(const make_t& make, const std::string& key) +{ if (get_block_fcn_regs().has_key(key)) { - throw uhd::runtime_error( - str(boost::format("Attempting to register an RFNoC block with key %s for the second time.") % key) - ); + throw uhd::runtime_error(str( + boost::format( + "Attempting to register an RFNoC block with key %s for the second time.") + % key)); } get_block_fcn_regs().set(key, make); @@ -33,7 +31,7 @@ void block_ctrl_base::register_block( /*! Look up names for blocks in XML files using NoC ID. */ -static void lookup_block_key(uint64_t noc_id, make_args_t &make_args) +static void lookup_block_key(uint64_t noc_id, make_args_t& make_args) { try { blockdef::sptr bd = blockdef::make_from_noc_id(noc_id); @@ -46,8 +44,10 @@ static void lookup_block_key(uint64_t noc_id, make_args_t &make_args) make_args.block_key = bd->get_key(); make_args.block_name = bd->get_name(); return; - } catch (std::exception &e) { - UHD_LOGGER_WARNING("RFNOC") << str(boost::format("Error while looking up name for NoC-ID %016X.\n%s") % noc_id % e.what()) ; + } catch (std::exception& e) { + UHD_LOGGER_WARNING("RFNOC") + << str(boost::format("Error while looking up name for NoC-ID %016X.\n%s") + % noc_id % e.what()); } make_args.block_key = DEFAULT_BLOCK_NAME; @@ -56,9 +56,8 @@ static void lookup_block_key(uint64_t noc_id, make_args_t &make_args) block_ctrl_base::sptr block_ctrl_base::make( - const make_args_t &make_args_, - uint64_t noc_id -) { + const make_args_t& make_args_, uint64_t noc_id) +{ UHD_LOGGER_TRACE("RFNOC") << "[RFNoC Factory] block_ctrl_base::make()"; make_args_t make_args = make_args_; @@ -68,22 +67,21 @@ block_ctrl_base::sptr block_ctrl_base::make( lookup_block_key(noc_id, make_args); } else if (not get_block_fcn_regs().has_key(make_args.block_key)) { throw uhd::runtime_error( - str(boost::format("No block controller class registered for key '%s'.") % make_args.block_key) - ); + str(boost::format("No block controller class registered for key '%s'.") + % make_args.block_key)); } if (not get_block_fcn_regs().has_key(make_args.block_key)) { UHD_LOG_WARNING("RFNOC", - "Can't find a block controller for key " << make_args.block_key - << ", using default block controller!"); + "Can't find a block controller for key " + << make_args.block_key << ", using default block controller!"); make_args.block_key = DEFAULT_BLOCK_NAME; } if (make_args.block_name.empty()) { make_args.block_name = make_args.block_key; } - UHD_LOGGER_TRACE("RFNOC") - << "[RFNoC Factory] Using controller key '" << make_args.block_key - << "' and block name '" << make_args.block_name << "'"; + UHD_LOGGER_TRACE("RFNOC") << "[RFNoC Factory] Using controller key '" + << make_args.block_key << "' and block name '" + << make_args.block_name << "'"; return get_block_fcn_regs()[make_args.block_key](make_args); } - diff --git a/host/lib/rfnoc/block_id.cpp b/host/lib/rfnoc/block_id.cpp index 9d966904b..c33e1464c 100644 --- a/host/lib/rfnoc/block_id.cpp +++ b/host/lib/rfnoc/block_id.cpp @@ -5,29 +5,21 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/format.hpp> -#include <boost/regex.hpp> -#include <boost/lexical_cast.hpp> #include <uhd/exception.hpp> #include <uhd/property_tree.hpp> -#include <uhd/rfnoc/constants.hpp> #include <uhd/rfnoc/block_id.hpp> - +#include <uhd/rfnoc/constants.hpp> +#include <boost/format.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/regex.hpp> #include <iostream> using namespace uhd::rfnoc; -block_id_t::block_id_t() : - _device_no(0), - _block_name(""), - _block_ctr(0) -{ -} +block_id_t::block_id_t() : _device_no(0), _block_name(""), _block_ctr(0) {} -block_id_t::block_id_t(const std::string &block_str) - : _device_no(0), - _block_name(""), - _block_ctr(0) +block_id_t::block_id_t(const std::string& block_str) + : _device_no(0), _block_name(""), _block_ctr(0) { if (not set(block_str)) { throw uhd::value_error("block_id_t: Invalid block ID string."); @@ -35,92 +27,80 @@ block_id_t::block_id_t(const std::string &block_str) } block_id_t::block_id_t( - const size_t device_no, - const std::string &block_name, - const size_t block_ctr -) : _device_no(device_no), - _block_name(block_name), - _block_ctr(block_ctr) + const size_t device_no, const std::string& block_name, const size_t block_ctr) + : _device_no(device_no), _block_name(block_name), _block_ctr(block_ctr) { if (not is_valid_blockname(block_name)) { throw uhd::value_error("block_id_t: Invalid block name."); } } -bool block_id_t::is_valid_blockname(const std::string &block_name) +bool block_id_t::is_valid_blockname(const std::string& block_name) { return boost::regex_match(block_name, boost::regex(VALID_BLOCKNAME_REGEX)); } -bool block_id_t::is_valid_block_id(const std::string &block_name) +bool block_id_t::is_valid_block_id(const std::string& block_name) { return boost::regex_match(block_name, boost::regex(VALID_BLOCKID_REGEX)); } std::string block_id_t::to_string() const { - return str(boost::format("%d/%s") - % get_device_no() - % get_local() - ); + return str(boost::format("%d/%s") % get_device_no() % get_local()); } std::string block_id_t::get_local() const { - return str(boost::format("%s_%d") - % get_block_name() - % get_block_count() - ); + return str(boost::format("%s_%d") % get_block_name() % get_block_count()); } uhd::fs_path block_id_t::get_tree_root() const { - return str(boost::format("/mboards/%d/xbar/%s") - % get_device_no() - % get_local() - ); + return str(boost::format("/mboards/%d/xbar/%s") % get_device_no() % get_local()); } -bool block_id_t::match(const std::string &block_str) +bool block_id_t::match(const std::string& block_str) { boost::cmatch matches; - if (not boost::regex_match(block_str.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) { + if (not boost::regex_match( + block_str.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) { return false; } try { - return (matches[1] == "" or boost::lexical_cast<size_t>(matches[1]) == _device_no) - and (matches[2] == "" or matches[2] == _block_name) - and (matches[3] == "" or boost::lexical_cast<size_t>(matches[3]) == _block_ctr) - and not (matches[1] == "" and matches[2] == "" and matches[3] == ""); - } catch (const std::bad_cast &e) { + return (matches[1] == "" or boost::lexical_cast<size_t>(matches[1]) == _device_no) + and (matches[2] == "" or matches[2] == _block_name) + and (matches[3] == "" + or boost::lexical_cast<size_t>(matches[3]) == _block_ctr) + and not(matches[1] == "" and matches[2] == "" and matches[3] == ""); + } catch (const std::bad_cast& e) { return false; } return false; } -bool block_id_t::set(const std::string &new_name) +bool block_id_t::set(const std::string& new_name) { boost::cmatch matches; - if (not boost::regex_match(new_name.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) { + if (not boost::regex_match( + new_name.c_str(), matches, boost::regex(VALID_BLOCKID_REGEX))) { return false; } - if (not (matches[1] == "")) { + if (not(matches[1] == "")) { _device_no = boost::lexical_cast<size_t>(matches[1]); } - if (not (matches[2] == "")) { + if (not(matches[2] == "")) { _block_name = matches[2]; } - if (not (matches[3] == "")) { + if (not(matches[3] == "")) { _block_ctr = boost::lexical_cast<size_t>(matches[3]); } return true; } bool block_id_t::set( - const size_t device_no, - const std::string &block_name, - const size_t block_ctr -) { + const size_t device_no, const std::string& block_name, const size_t block_ctr) +{ if (not set_block_name(block_name)) { return false; } @@ -129,7 +109,7 @@ bool block_id_t::set( return true; } -bool block_id_t::set_block_name(const std::string &block_name) +bool block_id_t::set_block_name(const std::string& block_name) { if (not is_valid_blockname(block_name)) { return false; @@ -137,4 +117,3 @@ bool block_id_t::set_block_name(const std::string &block_name) _block_name = block_name; return true; } - diff --git a/host/lib/rfnoc/blockdef_xml_impl.cpp b/host/lib/rfnoc/blockdef_xml_impl.cpp index 26622d649..db491922c 100644 --- a/host/lib/rfnoc/blockdef_xml_impl.cpp +++ b/host/lib/rfnoc/blockdef_xml_impl.cpp @@ -6,14 +6,14 @@ // #include <uhd/exception.hpp> -#include <uhd/rfnoc/constants.hpp> #include <uhd/rfnoc/blockdef.hpp> +#include <uhd/rfnoc/constants.hpp> #include <uhd/utils/log.hpp> #include <uhd/utils/paths.hpp> -#include <boost/format.hpp> -#include <boost/lexical_cast.hpp> #include <boost/algorithm/string.hpp> #include <boost/filesystem/operations.hpp> +#include <boost/format.hpp> +#include <boost/lexical_cast.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> #include <cstdlib> @@ -31,41 +31,39 @@ static const fs::path XML_EXTENSION(".xml"); /**************************************************************************** * port_t stuff ****************************************************************************/ -const device_addr_t blockdef::port_t::PORT_ARGS( - "name," - "type," - "vlen=0," - "pkt_size=0," - "optional=0," - "bursty=0," - "port," -); +const device_addr_t blockdef::port_t::PORT_ARGS("name," + "type," + "vlen=0," + "pkt_size=0," + "optional=0," + "bursty=0," + "port,"); blockdef::port_t::port_t() { // This guarantees that we can access these keys // even if they were never initialized: - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { set(key, PORT_ARGS[key]); } } -bool blockdef::port_t::is_variable(const std::string &key) const +bool blockdef::port_t::is_variable(const std::string& key) const { - const std::string &val = get(key); + const std::string& val = get(key); return (val[0] == '$'); } -bool blockdef::port_t::is_keyword(const std::string &key) const +bool blockdef::port_t::is_keyword(const std::string& key) const { - const std::string &val = get(key); + const std::string& val = get(key); return (val[0] == '%'); } bool blockdef::port_t::is_valid() const { // Check we have all the keys: - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { if (not has_key(key)) { return false; } @@ -78,7 +76,7 @@ bool blockdef::port_t::is_valid() const std::string blockdef::port_t::to_string() const { std::string result; - for(const std::string &key: PORT_ARGS.keys()) { + for (const std::string& key : PORT_ARGS.keys()) { if (has_key(key)) { result += str(boost::format("%s=%s,") % key % get(key)); } @@ -92,28 +90,26 @@ std::string blockdef::port_t::to_string() const ****************************************************************************/ const device_addr_t blockdef::arg_t::ARG_ARGS( // List all tags/args an <arg> can have here: - "name," - "type," - "value," - "check," - "check_message," - "action," - "port=0," -); + "name," + "type," + "value," + "check," + "check_message," + "action," + "port=0,"); const std::set<std::string> blockdef::arg_t::VALID_TYPES = { // List all tags/args a <type> can have here: "string", "int", "int_vector", - "double" -}; + "double"}; blockdef::arg_t::arg_t() { // This guarantees that we can access these keys // even if they were never initialized: - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { set(key, ARG_ARGS[key]); } } @@ -121,7 +117,7 @@ blockdef::arg_t::arg_t() bool blockdef::arg_t::is_valid() const { // 1. Check we have all the keys: - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { if (not has_key(key)) { return false; } @@ -139,7 +135,7 @@ bool blockdef::arg_t::is_valid() const std::string blockdef::arg_t::to_string() const { std::string result; - for(const std::string &key: ARG_ARGS.keys()) { + for (const std::string& key : ARG_ARGS.keys()) { if (has_key(key)) { result += str(boost::format("%s=%s,") % key % get(key)); } @@ -154,10 +150,7 @@ std::string blockdef::arg_t::to_string() const class blockdef_xml_impl : public blockdef { public: - enum xml_repr_t { - DESCRIBES_BLOCK, - DESCRIBES_COMPONENT - }; + enum xml_repr_t { DESCRIBES_BLOCK, DESCRIBES_COMPONENT }; //! Returns a list of base paths for the XML files. // It is assumed that block definitions are in a subdir with name @@ -180,7 +173,7 @@ public: } //! Matches a NoC ID through substring matching - static bool match_noc_id(const std::string &lhs_, uint64_t rhs_) + static bool match_noc_id(const std::string& lhs_, uint64_t rhs_) { // Sanitize input: Make both values strings with all uppercase // characters and no leading 0x. Check inputs are valid. @@ -191,9 +184,10 @@ public: } UHD_ASSERT_THROW(rhs.size() == 16); if (lhs.size() < 4 or lhs.size() > 16) { - throw uhd::value_error(str(boost::format( - "%s is not a valid NoC ID (must be hexadecimal, min 4 and max 16 characters)" - ) % lhs_)); + throw uhd::value_error( + str(boost::format("%s is not a valid NoC ID (must be hexadecimal, min 4 " + "and max 16 characters)") + % lhs_)); } // OK, all good now. Next, we try and match the substring lhs in rhs: @@ -201,34 +195,31 @@ public: } //! Open the file at filename and see if it's a block definition for the given NoC ID - static bool has_noc_id(uint64_t noc_id, const fs::path &filename) + static bool has_noc_id(uint64_t noc_id, const fs::path& filename) { pt::ptree propt; try { read_xml(filename.string(), propt); - for(pt::ptree::value_type &v: propt.get_child("nocblock.ids")) { + for (pt::ptree::value_type& v : propt.get_child("nocblock.ids")) { if (v.first == "id" and match_noc_id(v.second.data(), noc_id)) { return true; } } - } catch (std::exception &e) { - UHD_LOGGER_WARNING("RFNOC") - << "has_noc_id(): caught exception " << e.what() - << " while parsing file: " << filename.string(); + } catch (std::exception& e) { + UHD_LOGGER_WARNING("RFNOC") << "has_noc_id(): caught exception " << e.what() + << " while parsing file: " << filename.string(); return false; } return false; } - blockdef_xml_impl(const fs::path &filename, uint64_t noc_id, xml_repr_t type=DESCRIBES_BLOCK) : - _type(type), - _noc_id(noc_id) + blockdef_xml_impl( + const fs::path& filename, uint64_t noc_id, xml_repr_t type = DESCRIBES_BLOCK) + : _type(type), _noc_id(noc_id) { - UHD_LOGGER_DEBUG("RFNOC") << - boost::format("Reading XML file %s for NOC ID 0x%08X") - % filename.string().c_str() - % noc_id - ; + UHD_LOGGER_DEBUG("RFNOC") + << boost::format("Reading XML file %s for NOC ID 0x%08X") + % filename.string().c_str() % noc_id; read_xml(filename.string(), _pt); try { // Check key is valid @@ -236,7 +227,7 @@ public: // Check name is valid get_name(); // Check there's at least one port - ports_t in = get_input_ports(); + ports_t in = get_input_ports(); ports_t out = get_output_ports(); if (in.empty() and out.empty()) { throw uhd::runtime_error("Block does not define inputs or outputs."); @@ -244,11 +235,10 @@ public: // Check args are valid get_args(); // TODO any more checks? - } catch (const std::exception &e) { - throw uhd::runtime_error(str( - boost::format("Invalid block definition in %s: %s") - % filename.string() % e.what() - )); + } catch (const std::exception& e) { + throw uhd::runtime_error( + str(boost::format("Invalid block definition in %s: %s") + % filename.string() % e.what())); } } @@ -266,7 +256,7 @@ public: { try { return _pt.get<std::string>("nocblock.key"); - } catch (const pt::ptree_bad_path &) { + } catch (const pt::ptree_bad_path&) { return _pt.get<std::string>("nocblock.blockname"); } } @@ -291,16 +281,17 @@ public: return _get_ports("source"); } - ports_t _get_ports(const std::string &port_type) + ports_t _get_ports(const std::string& port_type) { std::set<size_t> port_numbers; size_t n_ports = 0; ports_t ports; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.ports")) { - if (v.first != port_type) continue; + for (pt::ptree::value_type& v : _pt.get_child("nocblock.ports")) { + if (v.first != port_type) + continue; // Now we have the correct sink or source node: port_t port; - for(const std::string &key: port_t::PORT_ARGS.keys()) { + for (const std::string& key : port_t::PORT_ARGS.keys()) { port[key] = v.second.get(key, port_t::PORT_ARGS[key]); } // We have to be extra-careful with the port numbers: @@ -310,17 +301,15 @@ public: size_t new_port_number; try { new_port_number = boost::lexical_cast<size_t>(port["port"]); - } catch (const boost::bad_lexical_cast &e) { - throw uhd::value_error(str( - boost::format("Invalid port number '%s' on port '%s'") - % port["port"] % port["name"] - )); + } catch (const boost::bad_lexical_cast& e) { + throw uhd::value_error( + str(boost::format("Invalid port number '%s' on port '%s'") + % port["port"] % port["name"])); } if (port_numbers.count(new_port_number) or new_port_number > MAX_NUM_PORTS) { - throw uhd::value_error(str( - boost::format("Port '%s' has invalid port number %d!") - % port["name"] % new_port_number - )); + throw uhd::value_error( + str(boost::format("Port '%s' has invalid port number %d!") + % port["name"] % new_port_number)); } port_numbers.insert(new_port_number); n_ports++; @@ -332,10 +321,10 @@ public: std::vector<size_t> get_all_port_numbers() { std::set<size_t> set_ports; - for(const port_t &port: get_input_ports()) { + for (const port_t& port : get_input_ports()) { set_ports.insert(boost::lexical_cast<size_t>(port["port"])); } - for(const port_t &port: get_output_ports()) { + for (const port_t& port : get_output_ports()) { set_ports.insert(boost::lexical_cast<size_t>(port["port"])); } return std::vector<size_t>(set_ports.begin(), set_ports.end()); @@ -347,10 +336,11 @@ public: args_t args; bool is_valid = true; pt::ptree def; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.args", def)) { + for (pt::ptree::value_type& v : _pt.get_child("nocblock.args", def)) { arg_t arg; - if (v.first != "arg") continue; - for(const std::string &key: arg_t::ARG_ARGS.keys()) { + if (v.first != "arg") + continue; + for (const std::string& key : arg_t::ARG_ARGS.keys()) { arg[key] = v.second.get(key, arg_t::ARG_ARGS[key]); } if (arg["type"].empty()) { @@ -364,10 +354,8 @@ public: args.push_back(arg); } if (not is_valid) { - throw uhd::runtime_error(str( - boost::format("Found invalid arguments for block %s.") - % get_name() - )); + throw uhd::runtime_error( + str(boost::format("Found invalid arguments for block %s.") % get_name())); } return args; } @@ -382,12 +370,13 @@ public: return _get_regs("readback"); } - registers_t _get_regs(const std::string ®_type) + registers_t _get_regs(const std::string& reg_type) { registers_t registers; pt::ptree def; - for(pt::ptree::value_type &v: _pt.get_child("nocblock.registers", def)) { - if (v.first != reg_type) continue; + for (pt::ptree::value_type& v : _pt.get_child("nocblock.registers", def)) { + if (v.first != reg_type) + continue; registers[v.second.get<std::string>("name")] = boost::lexical_cast<size_t>(v.second.get<size_t>("address")); } @@ -396,7 +385,6 @@ public: private: - //! Tells us if is this for a NoC block, or a component. const xml_repr_t _type; //! The NoC-ID as reported (there may be several valid NoC IDs, this is the one used) @@ -405,7 +393,6 @@ private: //! This is a boost property tree, not the same as // our property tree. pt::ptree _pt; - }; blockdef::sptr blockdef::make_from_noc_id(uint64_t noc_id) @@ -422,11 +409,9 @@ blockdef::sptr blockdef::make_from_noc_id(uint64_t noc_id) } if (valid.empty()) { - throw uhd::assertion_error( - "Failed to find a valid XML path for RFNoC blocks.\n" - "Try setting the enviroment variable UHD_RFNOC_DIR " - "to the correct location" - ); + throw uhd::assertion_error("Failed to find a valid XML path for RFNoC blocks.\n" + "Try setting the enviroment variable UHD_RFNOC_DIR " + "to the correct location"); } // Iterate over all paths diff --git a/host/lib/rfnoc/ctrl_iface.cpp b/host/lib/rfnoc/ctrl_iface.cpp index 29e18fc3a..0b71aebbb 100644 --- a/host/lib/rfnoc/ctrl_iface.cpp +++ b/host/lib/rfnoc/ctrl_iface.cpp @@ -6,75 +6,65 @@ // #include <uhd/exception.hpp> -#include <uhd/utils/byteswap.hpp> -#include <uhd/utils/safe_call.hpp> +#include <uhd/rfnoc/constants.hpp> #include <uhd/transport/bounded_buffer.hpp> -#include <uhd/types/sid.hpp> -#include <uhd/types/endianness.hpp> #include <uhd/transport/chdr.hpp> -#include <uhd/rfnoc/constants.hpp> +#include <uhd/types/endianness.hpp> +#include <uhd/types/sid.hpp> +#include <uhd/utils/byteswap.hpp> +#include <uhd/utils/safe_call.hpp> #include <uhdlib/rfnoc/ctrl_iface.hpp> -#include <boost/thread/mutex.hpp> -#include <boost/thread/thread.hpp> -#include <boost/format.hpp> #include <boost/bind.hpp> +#include <boost/format.hpp> #include <boost/make_shared.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> #include <queue> using namespace uhd; using namespace uhd::rfnoc; using namespace uhd::transport; -static const double ACK_TIMEOUT = 2.0; //supposed to be worst case practical timeout -static const double MASSIVE_TIMEOUT = 10.0; //for when we wait on a timed command +static const double ACK_TIMEOUT = 2.0; // supposed to be worst case practical timeout +static const double MASSIVE_TIMEOUT = 10.0; // for when we wait on a timed command -template <uhd::endianness_t _endianness> -class ctrl_iface_impl: public ctrl_iface +template <uhd::endianness_t _endianness> class ctrl_iface_impl : public ctrl_iface { public: - - ctrl_iface_impl( - const both_xports_t &xports, - const std::string &name - ) : _xports(xports), - _name(name), - _seq_out(0), - _max_outstanding_acks( - std::min( - uhd::rfnoc::CMD_FIFO_SIZE / 3, // Max command packet size is 3 lines - _xports.recv->get_num_recv_frames() - ) - ) + ctrl_iface_impl(const both_xports_t& xports, const std::string& name) + : _xports(xports) + , _name(name) + , _seq_out(0) + , _max_outstanding_acks(std::min( + uhd::rfnoc::CMD_FIFO_SIZE / 3, // Max command packet size is 3 lines + _xports.recv->get_num_recv_frames())) { UHD_ASSERT_THROW(bool(_xports.send)); UHD_ASSERT_THROW(bool(_xports.recv)); // Flush the response transport in case we have something over: - while (_xports.recv->get_recv_buff(0.0)) {} + while (_xports.recv->get_recv_buff(0.0)) { + } } virtual ~ctrl_iface_impl(void) { UHD_SAFE_CALL( // dummy peek with the purpose of ack'ing all packets - this->send_cmd_pkt(0, 0, true); - ) + this->send_cmd_pkt(0, 0, true);) } /******************************************************************* * Get and set register implementation ******************************************************************/ - uint64_t send_cmd_pkt( - const size_t addr, - const size_t data, - const bool readback, - const uint64_t timestamp=0 - ) { + uint64_t send_cmd_pkt(const size_t addr, + const size_t data, + const bool readback, + const uint64_t timestamp = 0) + { boost::mutex::scoped_lock lock(_mutex); this->send_pkt(addr, data, timestamp); return this->wait_for_ack( - readback, - bool(timestamp) ? MASSIVE_TIMEOUT : ACK_TIMEOUT - ); + readback, bool(timestamp) ? MASSIVE_TIMEOUT : ACK_TIMEOUT); } private: @@ -88,66 +78,64 @@ private: * Primary control and interaction private methods ******************************************************************/ inline void send_pkt( - const uint32_t addr, - const uint32_t data, - const uint64_t timestamp - ) { + const uint32_t addr, const uint32_t data, const uint64_t timestamp) + { managed_send_buffer::sptr buff = _xports.send->get_send_buff(0.0); if (not buff) { throw uhd::runtime_error("fifo ctrl timed out getting a send buffer"); } - uint32_t *pkt = buff->cast<uint32_t *>(); + uint32_t* pkt = buff->cast<uint32_t*>(); - //load packet info + // load packet info vrt::if_packet_info_t packet_info; - packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; - packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_CMD; + packet_info.link_type = vrt::if_packet_info_t::LINK_TYPE_CHDR; + packet_info.packet_type = vrt::if_packet_info_t::PACKET_TYPE_CMD; packet_info.num_payload_words32 = 2; - packet_info.num_payload_bytes = packet_info.num_payload_words32*sizeof(uint32_t); + packet_info.num_payload_bytes = + packet_info.num_payload_words32 * sizeof(uint32_t); packet_info.packet_count = _seq_out; - packet_info.tsf = timestamp; - packet_info.sob = false; - packet_info.eob = false; - packet_info.fc_ack = false; - packet_info.sid = _xports.send_sid; - packet_info.has_sid = true; - packet_info.has_cid = false; - packet_info.has_tsi = false; - packet_info.has_tsf = bool(timestamp); - packet_info.has_tlr = false; + packet_info.tsf = timestamp; + packet_info.sob = false; + packet_info.eob = false; + packet_info.fc_ack = false; + packet_info.sid = _xports.send_sid; + packet_info.has_sid = true; + packet_info.has_cid = false; + packet_info.has_tsi = false; + packet_info.has_tsf = bool(timestamp); + packet_info.has_tlr = false; // Unpack header and load payload if (_endianness == uhd::ENDIANNESS_BIG) { // This if statement gets compiled out vrt::if_hdr_pack_be(pkt, packet_info); - pkt[packet_info.num_header_words32+0] = uhd::htonx(addr); - pkt[packet_info.num_header_words32+1] = uhd::htonx(data); + pkt[packet_info.num_header_words32 + 0] = uhd::htonx(addr); + pkt[packet_info.num_header_words32 + 1] = uhd::htonx(data); } else { vrt::if_hdr_pack_le(pkt, packet_info); - pkt[packet_info.num_header_words32+0] = uhd::htowx(addr); - pkt[packet_info.num_header_words32+1] = uhd::htowx(data); + pkt[packet_info.num_header_words32 + 0] = uhd::htowx(addr); + pkt[packet_info.num_header_words32 + 1] = uhd::htowx(data); } - //UHD_LOGGER_TRACE("RFNOC") << boost::format("0x%08x, 0x%08x\n") % addr % data; - //send the buffer over the interface + // UHD_LOGGER_TRACE("RFNOC") << boost::format("0x%08x, 0x%08x\n") % addr % data; + // send the buffer over the interface _outstanding_seqs.push(_seq_out); - buff->commit(sizeof(uint32_t)*(packet_info.num_packet_words32)); + buff->commit(sizeof(uint32_t) * (packet_info.num_packet_words32)); - _seq_out++;//inc seq for next call + _seq_out++; // inc seq for next call } inline uint64_t wait_for_ack(const bool readback, const double timeout) { - while (readback or (_outstanding_seqs.size() >= _max_outstanding_acks)) - { - //get seq to ack from outstanding packets list + while (readback or (_outstanding_seqs.size() >= _max_outstanding_acks)) { + // get seq to ack from outstanding packets list UHD_ASSERT_THROW(not _outstanding_seqs.empty()); const size_t seq_to_ack = _outstanding_seqs.front(); - //parse the packet + // parse the packet vrt::if_packet_info_t packet_info; resp_buff_type resp_buff; memset(&resp_buff, 0x00, sizeof(resp_buff)); - uint32_t const *pkt = NULL; + uint32_t const* pkt = NULL; managed_recv_buffer::sptr buff; buff = _xports.recv->get_recv_buff(timeout); @@ -155,81 +143,68 @@ private: UHD_ASSERT_THROW(bool(buff)); UHD_ASSERT_THROW(buff->size() > 0); _outstanding_seqs.pop(); + } catch (const std::exception& ex) { + throw uhd::io_error( + str(boost::format("Block ctrl (%s) no response packet - %s") % _name + % ex.what())); } - catch(const std::exception &ex) { - throw uhd::io_error(str( - boost::format("Block ctrl (%s) no response packet - %s") - % _name - % ex.what() - )); - } - pkt = buff->cast<const uint32_t *>(); - packet_info.num_packet_words32 = buff->size()/sizeof(uint32_t); + pkt = buff->cast<const uint32_t*>(); + packet_info.num_packet_words32 = buff->size() / sizeof(uint32_t); - //parse the buffer + // parse the buffer try { if (_endianness == uhd::ENDIANNESS_BIG) { vrt::chdr::if_hdr_unpack_be(pkt, packet_info); } else { vrt::chdr::if_hdr_unpack_le(pkt, packet_info); } - } - catch(const std::exception &ex) - { - UHD_LOGGER_ERROR("RFNOC") << "[" << _name << "] Block ctrl bad VITA packet: " << ex.what() ; - if (buff){ - UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[0] ; - UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[1] ; - UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[2] ; - UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[3] ; - } - else{ - UHD_LOGGER_INFO("RFNOC") << "buff is NULL" ; + } catch (const std::exception& ex) { + UHD_LOGGER_ERROR("RFNOC") + << "[" << _name << "] Block ctrl bad VITA packet: " << ex.what(); + if (buff) { + UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[0]; + UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[1]; + UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[2]; + UHD_LOGGER_INFO("RFNOC") << boost::format("%08X") % pkt[3]; + } else { + UHD_LOGGER_INFO("RFNOC") << "buff is NULL"; } } - //check the buffer + // check the buffer try { UHD_ASSERT_THROW(packet_info.has_sid); if (packet_info.sid != _xports.recv_sid.get()) { throw uhd::io_error( - str( - boost::format("Expected SID: %s Received SID: %s") + str(boost::format("Expected SID: %s Received SID: %s") % _xports.recv_sid.to_pp_string_hex() - % uhd::sid_t(packet_info.sid).to_pp_string_hex() - ) - ); + % uhd::sid_t(packet_info.sid).to_pp_string_hex())); } if (packet_info.packet_count != (seq_to_ack & 0xfff)) { throw uhd::io_error( - str( - boost::format("Expected packet index: %d " \ + str(boost::format("Expected packet index: %d " "Received index: %d") - % (seq_to_ack & 0xfff) - % packet_info.packet_count - ) - ); + % (seq_to_ack & 0xfff) % packet_info.packet_count)); } UHD_ASSERT_THROW(packet_info.num_payload_words32 == 2); - } - catch (const std::exception &ex) { - throw uhd::io_error(str( - boost::format("Block ctrl (%s) packet parse error - %s") - % _name - % ex.what() - )); + } catch (const std::exception& ex) { + throw uhd::io_error( + str(boost::format("Block ctrl (%s) packet parse error - %s") % _name + % ex.what())); } - //return the readback value + // return the readback value if (readback and _outstanding_seqs.empty()) { - const uint64_t hi = (_endianness == uhd::ENDIANNESS_BIG) ? - uhd::ntohx(pkt[packet_info.num_header_words32+0]) - : uhd::wtohx(pkt[packet_info.num_header_words32+0]); - const uint64_t lo = (_endianness == uhd::ENDIANNESS_BIG) ? - uhd::ntohx(pkt[packet_info.num_header_words32+1]) - : uhd::wtohx(pkt[packet_info.num_header_words32+1]); + const uint64_t hi = + (_endianness == uhd::ENDIANNESS_BIG) + ? uhd::ntohx(pkt[packet_info.num_header_words32 + 0]) + : uhd::wtohx(pkt[packet_info.num_header_words32 + 0]); + const uint64_t lo = + (_endianness == uhd::ENDIANNESS_BIG) + ? uhd::ntohx(pkt[packet_info.num_header_words32 + 1]) + : uhd::wtohx(pkt[packet_info.num_header_words32 + 1]); return ((hi << 32) | lo); } } @@ -247,17 +222,11 @@ private: boost::mutex _mutex; }; -ctrl_iface::sptr ctrl_iface::make( - const both_xports_t &xports, - const std::string &name -) { +ctrl_iface::sptr ctrl_iface::make(const both_xports_t& xports, const std::string& name) +{ if (xports.endianness == uhd::ENDIANNESS_BIG) { - return boost::make_shared<ctrl_iface_impl<uhd::ENDIANNESS_BIG>>( - xports, name - ); + return boost::make_shared<ctrl_iface_impl<uhd::ENDIANNESS_BIG>>(xports, name); } else { - return boost::make_shared<ctrl_iface_impl<uhd::ENDIANNESS_LITTLE>>( - xports, name - ); + return boost::make_shared<ctrl_iface_impl<uhd::ENDIANNESS_LITTLE>>(xports, name); } } diff --git a/host/lib/rfnoc/ddc_block_ctrl_impl.cpp b/host/lib/rfnoc/ddc_block_ctrl_impl.cpp index 7ea81e255..f115a876b 100644 --- a/host/lib/rfnoc/ddc_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/ddc_block_ctrl_impl.cpp @@ -4,14 +4,14 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/ddc_block_ctrl.hpp> -#include <uhd/utils/log.hpp> #include <uhd/convert.hpp> +#include <uhd/rfnoc/ddc_block_ctrl.hpp> #include <uhd/types/ranges.hpp> +#include <uhd/utils/log.hpp> +#include <uhdlib/usrp/cores/dsp_core_utils.hpp> +#include <uhdlib/utils/compat_check.hpp> #include <uhdlib/utils/math.hpp> #include <uhdlib/utils/narrow.hpp> -#include <uhdlib/utils/compat_check.hpp> -#include <uhdlib/usrp/cores/dsp_core_utils.hpp> #include <boost/math/special_functions/round.hpp> #include <cmath> @@ -21,20 +21,20 @@ class ddc_block_ctrl_impl : public ddc_block_ctrl { public: UHD_RFNOC_BLOCK_CONSTRUCTOR(ddc_block_ctrl) - , _fpga_compat(user_reg_read64(RB_REG_COMPAT_NUM)) - , _num_halfbands(uhd::narrow_cast<size_t>( - user_reg_read64(RB_REG_NUM_HALFBANDS))) - , _cic_max_decim(uhd::narrow_cast<size_t>( - user_reg_read64(RB_REG_CIC_MAX_DECIM))) + , _fpga_compat(user_reg_read64(RB_REG_COMPAT_NUM)), + _num_halfbands(uhd::narrow_cast<size_t>(user_reg_read64(RB_REG_NUM_HALFBANDS))), + _cic_max_decim(uhd::narrow_cast<size_t>(user_reg_read64(RB_REG_CIC_MAX_DECIM))) { UHD_LOG_DEBUG(unique_id(), - "Loading DDC with " << get_num_halfbands() << " halfbands and " - "max CIC decimation " << get_cic_max_decim() - ); - uhd::assert_fpga_compat( - MAJOR_COMP, MINOR_COMP, + "Loading DDC with " << get_num_halfbands() + << " halfbands and " + "max CIC decimation " + << get_cic_max_decim()); + uhd::assert_fpga_compat(MAJOR_COMP, + MINOR_COMP, _fpga_compat, - "DDC", "DDC", + "DDC", + "DDC", false /* Let it slide if minors mismatch */ ); @@ -42,76 +42,64 @@ public: for (size_t chan = 0; chan < get_input_ports().size(); chan++) { const double default_freq = get_arg<double>("freq", chan); _tree->access<double>(get_arg_path("freq/value", chan)) - .set_coercer([this, chan](const double value){ + .set_coercer([this, chan](const double value) { return this->set_freq(value, chan); }) .set(default_freq); ; - const double default_output_rate = - get_arg<double>("output_rate", chan); + const double default_output_rate = get_arg<double>("output_rate", chan); _tree->access<double>(get_arg_path("output_rate/value", chan)) - .set_coercer([this, chan](const double value){ + .set_coercer([this, chan](const double value) { return this->set_output_rate(value, chan); }) - .set(default_output_rate) - ; + .set(default_output_rate); _tree->access<double>(get_arg_path("input_rate/value", chan)) - .add_coerced_subscriber([this, chan](const double rate){ + .add_coerced_subscriber([this, chan](const double rate) { this->set_input_rate(rate, chan); - }) - ; + }); // Legacy properties (for backward compat w/ multi_usrp) const uhd::fs_path dsp_base_path = _root_path / "legacy_api" / chan; // Legacy properties simply forward to the block args properties _tree->create<double>(dsp_base_path / "rate/value") - .set_coercer([this, chan](const double value){ - return this->_tree->access<double>( - this->get_arg_path("output_rate/value", chan) - ).set(value).get(); + .set_coercer([this, chan](const double value) { + return this->_tree + ->access<double>(this->get_arg_path("output_rate/value", chan)) + .set(value) + .get(); }) - .set_publisher([this, chan](){ - return this->_tree->access<double>( - this->get_arg_path("output_rate/value", chan) - ).get(); - }) - ; + .set_publisher([this, chan]() { + return this->_tree + ->access<double>(this->get_arg_path("output_rate/value", chan)) + .get(); + }); _tree->create<uhd::meta_range_t>(dsp_base_path / "rate/range") - .set_publisher([this](){ - return get_output_rates(); - }) - ; + .set_publisher([this]() { return get_output_rates(); }); _tree->create<double>(dsp_base_path / "freq/value") - .set_coercer([this, chan](const double value){ - return this->_tree->access<double>( - this->get_arg_path("freq/value", chan) - ).set(value).get(); - }) - .set_publisher([this, chan](){ - return this->_tree->access<double>( - this->get_arg_path("freq/value", chan) - ).get(); + .set_coercer([this, chan](const double value) { + return this->_tree + ->access<double>(this->get_arg_path("freq/value", chan)) + .set(value) + .get(); }) - ; + .set_publisher([this, chan]() { + return this->_tree + ->access<double>(this->get_arg_path("freq/value", chan)) + .get(); + }); _tree->create<uhd::meta_range_t>(dsp_base_path / "freq/range") - .set_publisher([this](){ - return get_freq_range(); - }) - ; + .set_publisher([this]() { return get_freq_range(); }); _tree->access<uhd::time_spec_t>("time/cmd") - .add_coerced_subscriber([this, chan](const uhd::time_spec_t time_spec){ + .add_coerced_subscriber([this, chan](const uhd::time_spec_t time_spec) { this->set_command_time(time_spec, chan); - }) - ; + }); if (_tree->exists("tick_rate")) { - const double tick_rate = - _tree->access<double>("tick_rate").get(); + const double tick_rate = _tree->access<double>("tick_rate").get(); set_command_tick_rate(tick_rate, chan); _tree->access<double>("tick_rate") - .add_coerced_subscriber([this, chan](const double rate){ + .add_coerced_subscriber([this, chan](const double rate) { this->set_command_tick_rate(rate, chan); - }) - ; + }); } // Rate 1:1 by default @@ -123,25 +111,25 @@ public: virtual ~ddc_block_ctrl_impl() {} - double get_output_scale_factor(size_t port=ANY_PORT) + double get_output_scale_factor(size_t port = ANY_PORT) { port = port == ANY_PORT ? 0 : port; - if (not (_rx_streamer_active.count(port) and _rx_streamer_active.at(port))) { + if (not(_rx_streamer_active.count(port) and _rx_streamer_active.at(port))) { return SCALE_UNDEFINED; } return get_arg<double>("scalar_correction", port); } - double get_input_samp_rate(size_t port=ANY_PORT) + double get_input_samp_rate(size_t port = ANY_PORT) { port = port == ANY_PORT ? 0 : port; - if (not (_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { + if (not(_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { return RATE_UNDEFINED; } return get_arg<double>("input_rate", port); } - double get_output_samp_rate(size_t port=ANY_PORT) + double get_output_samp_rate(size_t port = ANY_PORT) { if (port == ANY_PORT) { port = 0; @@ -161,28 +149,28 @@ public: set_command_tick_rate(tick_rate, port); } - if (not (_rx_streamer_active.count(port) and _rx_streamer_active.at(port))) { + if (not(_rx_streamer_active.count(port) and _rx_streamer_active.at(port))) { return RATE_UNDEFINED; } return get_arg<double>("output_rate", port); } - void issue_stream_cmd( - const uhd::stream_cmd_t &stream_cmd_, - const size_t chan - ) { - UHD_RFNOC_BLOCK_TRACE() << "ddc_block_ctrl_base::issue_stream_cmd()" ; + void issue_stream_cmd(const uhd::stream_cmd_t& stream_cmd_, const size_t chan) + { + UHD_RFNOC_BLOCK_TRACE() << "ddc_block_ctrl_base::issue_stream_cmd()"; if (list_upstream_nodes().count(chan) == 0) { - UHD_LOGGER_INFO("RFNOC") << "No upstream blocks." ; + UHD_LOGGER_INFO("RFNOC") << "No upstream blocks."; return; } uhd::stream_cmd_t stream_cmd = stream_cmd_; - if (stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE or - stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE) { - size_t decimation = get_arg<double>("input_rate", chan) / get_arg<double>("output_rate", chan); + if (stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE + or stream_cmd.stream_mode + == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE) { + size_t decimation = get_arg<double>("input_rate", chan) + / get_arg<double>("output_rate", chan); stream_cmd.num_samps *= decimation; } @@ -190,9 +178,9 @@ public: } private: - static constexpr size_t MAJOR_COMP = 2; - static constexpr size_t MINOR_COMP = 0; - static constexpr size_t RB_REG_COMPAT_NUM = 0; + static constexpr size_t MAJOR_COMP = 2; + static constexpr size_t MINOR_COMP = 0; + static constexpr size_t RB_REG_COMPAT_NUM = 0; static constexpr size_t RB_REG_NUM_HALFBANDS = 1; static constexpr size_t RB_REG_CIC_MAX_DECIM = 2; @@ -216,10 +204,7 @@ private: { const double input_rate = get_arg<double>("input_rate"); return uhd::meta_range_t( - -input_rate/2, - +input_rate/2, - input_rate/std::pow(2.0, 32) - ); + -input_rate / 2, +input_rate / 2, input_rate / std::pow(2.0, 32)); } uhd::meta_range_t get_output_rates(void) @@ -227,11 +212,11 @@ private: uhd::meta_range_t range; const double input_rate = get_arg<double>("input_rate"); for (int hb = _num_halfbands; hb >= 0; hb--) { - const size_t decim_offset = _cic_max_decim<<(hb-1); - for(size_t decim = _cic_max_decim; decim > 0; decim--) { - const size_t hb_cic_decim = decim*(1<<hb); - if(hb == 0 || hb_cic_decim > decim_offset) { - range.push_back(uhd::range_t(input_rate/hb_cic_decim)); + const size_t decim_offset = _cic_max_decim << (hb - 1); + for (size_t decim = _cic_max_decim; decim > 0; decim--) { + const size_t hb_cic_decim = decim * (1 << hb); + if (hb == 0 || hb_cic_decim > decim_offset) { + range.push_back(uhd::range_t(input_rate / hb_cic_decim)); } } } @@ -241,8 +226,8 @@ private: double set_output_rate(const double requested_rate, const size_t chan) { const double input_rate = get_arg<double>("input_rate"); - const size_t decim_rate = - boost::math::iround(input_rate/this->get_output_rates().clip(requested_rate, true)); + const size_t decim_rate = boost::math::iround( + input_rate / this->get_output_rates().clip(requested_rate, true)); size_t decim = decim_rate; // The FPGA knows which halfbands to enable for any given value of hb_enable. uint32_t hb_enable = 0; @@ -268,54 +253,69 @@ private: } if (decim > 1 and hb_enable == 0) { - UHD_LOGGER_WARNING("RFNOC") << boost::format( - "The requested decimation is odd; the user should expect passband CIC rolloff.\n" - "Select an even decimation to ensure that a halfband filter is enabled.\n" - "Decimations factorable by 4 will enable 2 halfbands, those factorable by 8 will enable 3 halfbands.\n" - "decimation = dsp_rate/samp_rate -> %d = (%f MHz)/(%f MHz)\n" - ) % decim_rate % (input_rate/1e6) % (requested_rate/1e6); + UHD_LOGGER_WARNING("RFNOC") + << boost::format( + "The requested decimation is odd; the user should expect passband " + "CIC rolloff.\n" + "Select an even decimation to ensure that a halfband filter is " + "enabled.\n" + "Decimations factorable by 4 will enable 2 halfbands, those " + "factorable by 8 will enable 3 halfbands.\n" + "decimation = dsp_rate/samp_rate -> %d = (%f MHz)/(%f MHz)\n") + % decim_rate % (input_rate / 1e6) % (requested_rate / 1e6); } // Calculate algorithmic gain of CIC for a given decimation. // For Ettus CIC R=decim, M=1, N=4. Gain = (R * M) ^ N const double rate_pow = std::pow(double(decim & 0xff), 4); - // Calculate compensation gain values for algorithmic gain of DDS and CIC taking into account - // gain compensation blocks already hardcoded in place in DDC (that provide simple 1/2^n gain compensation). + // Calculate compensation gain values for algorithmic gain of DDS and CIC taking + // into account gain compensation blocks already hardcoded in place in DDC (that + // provide simple 1/2^n gain compensation). static const double DDS_GAIN = 2.0; // - // The polar rotation of [I,Q] = [1,1] by Pi/8 also yields max magnitude of SQRT(2) (~1.4142) however - // input to the DDS thats outside the unit circle can only be sourced from a saturated RF frontend. - // To provide additional dynamic range head room accordingly using scale factor applied at egress from DDC would - // cost us small signal performance, thus we do no provide compensation gain for a saturated front end and allow - // the signal to clip in the H/W as needed. If we wished to avoid the signal clipping in these circumstances then adjust code to read: + // The polar rotation of [I,Q] = [1,1] by Pi/8 also yields max magnitude of + // SQRT(2) (~1.4142) however input to the DDS thats outside the unit circle can + // only be sourced from a saturated RF frontend. To provide additional dynamic + // range head room accordingly using scale factor applied at egress from DDC would + // cost us small signal performance, thus we do no provide compensation gain for a + // saturated front end and allow the signal to clip in the H/W as needed. If we + // wished to avoid the signal clipping in these circumstances then adjust code to + // read: const double scaling_adjustment = - std::pow(2, uhd::math::ceil_log2(rate_pow))/(DDS_GAIN*rate_pow); + std::pow(2, uhd::math::ceil_log2(rate_pow)) / (DDS_GAIN * rate_pow); update_scalar(scaling_adjustment, chan); - return input_rate/decim_rate; + return input_rate / decim_rate; } //! Set frequency and decimation again void set_input_rate(const double /* rate */, const size_t chan) { - const double desired_freq = _tree->access<double>(get_arg_path("freq", chan) / "value").get_desired(); + const double desired_freq = + _tree->access<double>(get_arg_path("freq", chan) / "value").get_desired(); set_arg<double>("freq", desired_freq, chan); - const double desired_output_rate = _tree->access<double>(get_arg_path("output_rate", chan) / "value").get_desired(); + const double desired_output_rate = + _tree->access<double>(get_arg_path("output_rate", chan) / "value") + .get_desired(); set_arg<double>("output_rate", desired_output_rate, chan); } - // Calculate compensation gain values for algorithmic gain of DDS and CIC taking into account - // gain compensation blocks already hardcoded in place in DDC (that provide simple 1/2^n gain compensation). - // Further more factor in OTW format which adds further gain factor to weight output samples correctly. + // Calculate compensation gain values for algorithmic gain of DDS and CIC taking into + // account gain compensation blocks already hardcoded in place in DDC (that provide + // simple 1/2^n gain compensation). Further more factor in OTW format which adds + // further gain factor to weight output samples correctly. void update_scalar(const double scalar, const size_t chan) { - const double target_scalar = (1 << 15) * scalar; + const double target_scalar = (1 << 15) * scalar; const int32_t actual_scalar = boost::math::iround(target_scalar); - // Calculate the error introduced by using integer representation for the scalar, can be corrected in host later. + // Calculate the error introduced by using integer representation for the scalar, + // can be corrected in host later. const double scalar_correction = - target_scalar / actual_scalar / double(1 << 15) // Rounding error, normalized to 1.0 + target_scalar / actual_scalar + / double(1 << 15) // Rounding error, normalized to 1.0 * get_arg<double>("fullscale"); // Scaling requested by host set_arg<double>("scalar_correction", scalar_correction, chan); - // Write DDC with scaling correction for CIC and DDS that maximizes dynamic range in 32/16/12/8bits. + // Write DDC with scaling correction for CIC and DDS that maximizes dynamic range + // in 32/16/12/8bits. sr_write("SCALE_IQ", actual_scalar, chan); } diff --git a/host/lib/rfnoc/dma_fifo_block_ctrl_impl.cpp b/host/lib/rfnoc/dma_fifo_block_ctrl_impl.cpp index 16ad7db6f..a80e2ef53 100644 --- a/host/lib/rfnoc/dma_fifo_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/dma_fifo_block_ctrl_impl.cpp @@ -5,15 +5,15 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/dma_fifo_block_ctrl.hpp> #include <uhd/convert.hpp> -#include <uhd/utils/log.hpp> +#include <uhd/rfnoc/dma_fifo_block_ctrl.hpp> #include <uhd/types/wb_iface.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/wb_iface_adapter.hpp> #include <uhdlib/usrp/cores/dma_fifo_core_3000.hpp> +#include <boost/format.hpp> #include <boost/make_shared.hpp> #include <boost/thread/mutex.hpp> -#include <boost/format.hpp> using namespace uhd; using namespace uhd::rfnoc; @@ -21,27 +21,31 @@ using namespace uhd::rfnoc; class dma_fifo_block_ctrl_impl : public dma_fifo_block_ctrl { public: - static const uint32_t DEFAULT_SIZE = 32*1024*1024; + static const uint32_t DEFAULT_SIZE = 32 * 1024 * 1024; UHD_RFNOC_BLOCK_CONSTRUCTOR(dma_fifo_block_ctrl) { _perifs.resize(get_input_ports().size()); - for(size_t i = 0; i < _perifs.size(); i++) { - _perifs[i].ctrl = this->get_ctrl_iface(i); - static const uint32_t USER_SR_BASE = 128*4; - static const uint32_t USER_RB_BASE = 0; //Don't care - _perifs[i].base_addr = DEFAULT_SIZE*i; - _perifs[i].depth = DEFAULT_SIZE; - _perifs[i].core = dma_fifo_core_3000::make(_perifs[i].ctrl, USER_SR_BASE, USER_RB_BASE); + for (size_t i = 0; i < _perifs.size(); i++) { + _perifs[i].ctrl = this->get_ctrl_iface(i); + static const uint32_t USER_SR_BASE = 128 * 4; + static const uint32_t USER_RB_BASE = 0; // Don't care + _perifs[i].base_addr = DEFAULT_SIZE * i; + _perifs[i].depth = DEFAULT_SIZE; + _perifs[i].core = + dma_fifo_core_3000::make(_perifs[i].ctrl, USER_SR_BASE, USER_RB_BASE); _perifs[i].core->resize(_perifs[i].base_addr, _perifs[i].depth); UHD_LOG_DEBUG(unique_id(), "Running BIST for FIFO " << i); if (_perifs[i].core->ext_bist_supported()) { uint32_t bisterr = _perifs[i].core->run_bist(); if (bisterr != 0) { - throw uhd::runtime_error(str(boost::format("BIST failed! (code: %d)\n") % bisterr)); + throw uhd::runtime_error( + str(boost::format("BIST failed! (code: %d)\n") % bisterr)); } else { double throughput = _perifs[i].core->get_bist_throughput(); - UHD_LOGGER_INFO(unique_id()) << (boost::format("BIST passed (Throughput: %.0f MB/s)") % (throughput/1e6)) ; + UHD_LOGGER_INFO(unique_id()) + << (boost::format("BIST passed (Throughput: %.0f MB/s)") + % (throughput / 1e6)); } } else { if (_perifs[i].core->run_bist() == 0) { @@ -52,38 +56,47 @@ public: } } _tree->access<int>(get_arg_path("base_addr/value", i)) - .add_coerced_subscriber(boost::bind(&dma_fifo_block_ctrl_impl::resize, this, _1, boost::ref(_perifs[i].depth), i)) - .set(_perifs[i].base_addr) - ; + .add_coerced_subscriber(boost::bind(&dma_fifo_block_ctrl_impl::resize, + this, + _1, + boost::ref(_perifs[i].depth), + i)) + .set(_perifs[i].base_addr); _tree->access<int>(get_arg_path("depth/value", i)) - .add_coerced_subscriber(boost::bind(&dma_fifo_block_ctrl_impl::resize, this, boost::ref(_perifs[i].base_addr), _1, i)) - .set(_perifs[i].depth) - ; + .add_coerced_subscriber(boost::bind(&dma_fifo_block_ctrl_impl::resize, + this, + boost::ref(_perifs[i].base_addr), + _1, + i)) + .set(_perifs[i].depth); } } - void resize(const uint32_t base_addr, const uint32_t depth, const size_t chan) { + void resize(const uint32_t base_addr, const uint32_t depth, const size_t chan) + { boost::lock_guard<boost::mutex> lock(_config_mutex); _perifs[chan].base_addr = base_addr; - _perifs[chan].depth = depth; + _perifs[chan].depth = depth; _perifs[chan].core->resize(base_addr, depth); } - uint32_t get_base_addr(const size_t chan) const { + uint32_t get_base_addr(const size_t chan) const + { return _perifs[chan].base_addr; } - uint32_t get_depth(const size_t chan) const { + uint32_t get_depth(const size_t chan) const + { return _perifs[chan].depth; } private: struct fifo_perifs_t { - wb_iface::sptr ctrl; + wb_iface::sptr ctrl; dma_fifo_core_3000::sptr core; - uint32_t base_addr; - uint32_t depth; + uint32_t base_addr; + uint32_t depth; }; std::vector<fifo_perifs_t> _perifs; diff --git a/host/lib/rfnoc/duc_block_ctrl_impl.cpp b/host/lib/rfnoc/duc_block_ctrl_impl.cpp index cf22ab7da..44825bfd0 100644 --- a/host/lib/rfnoc/duc_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/duc_block_ctrl_impl.cpp @@ -4,14 +4,14 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/duc_block_ctrl.hpp> -#include <uhd/utils/log.hpp> #include <uhd/convert.hpp> +#include <uhd/rfnoc/duc_block_ctrl.hpp> #include <uhd/types/ranges.hpp> +#include <uhd/utils/log.hpp> +#include <uhdlib/usrp/cores/dsp_core_utils.hpp> #include <uhdlib/utils/compat_check.hpp> #include <uhdlib/utils/math.hpp> #include <uhdlib/utils/narrow.hpp> -#include <uhdlib/usrp/cores/dsp_core_utils.hpp> #include <boost/math/special_functions/round.hpp> #include <cmath> @@ -21,20 +21,20 @@ class duc_block_ctrl_impl : public duc_block_ctrl { public: UHD_RFNOC_BLOCK_CONSTRUCTOR(duc_block_ctrl) - , _fpga_compat(user_reg_read64(RB_REG_COMPAT_NUM)) - , _num_halfbands(uhd::narrow_cast<size_t>( - user_reg_read64(RB_REG_NUM_HALFBANDS))) - , _cic_max_interp(uhd::narrow_cast<size_t>( - user_reg_read64(RB_REG_CIC_MAX_INTERP))) + , _fpga_compat(user_reg_read64(RB_REG_COMPAT_NUM)), + _num_halfbands(uhd::narrow_cast<size_t>(user_reg_read64(RB_REG_NUM_HALFBANDS))), + _cic_max_interp(uhd::narrow_cast<size_t>(user_reg_read64(RB_REG_CIC_MAX_INTERP))) { UHD_LOG_DEBUG(unique_id(), - "Loading DUC with " << get_num_halfbands() << " halfbands and " - "max CIC interpolation " << get_cic_max_interp() - ); - uhd::assert_fpga_compat( - MAJOR_COMP, MINOR_COMP, + "Loading DUC with " << get_num_halfbands() + << " halfbands and " + "max CIC interpolation " + << get_cic_max_interp()); + uhd::assert_fpga_compat(MAJOR_COMP, + MINOR_COMP, _fpga_compat, - "DUC", "DUC", + "DUC", + "DUC", false /* Let it slide if minors mismatch */ ); @@ -42,77 +42,65 @@ public: for (size_t chan = 0; chan < get_input_ports().size(); chan++) { const double default_freq = get_arg<double>("freq", chan); _tree->access<double>(get_arg_path("freq/value", chan)) - .set_coercer([this, chan](const double value){ + .set_coercer([this, chan](const double value) { return this->set_freq(value, chan); }) .set(default_freq); ; - const double default_input_rate = - get_arg<double>("input_rate", chan); + const double default_input_rate = get_arg<double>("input_rate", chan); _tree->access<double>(get_arg_path("input_rate/value", chan)) - .set_coercer([this, chan](const double value){ + .set_coercer([this, chan](const double value) { return this->set_input_rate(value, chan); }) - .set(default_input_rate) - ; + .set(default_input_rate); _tree->access<double>(get_arg_path("output_rate/value", chan)) - .add_coerced_subscriber([this, chan](const double rate){ + .add_coerced_subscriber([this, chan](const double rate) { this->set_output_rate(rate, chan); - }) - ; + }); // Legacy properties (for backward compat w/ multi_usrp) const uhd::fs_path dsp_base_path = _root_path / "legacy_api" / chan; // Legacy properties _tree->create<double>(dsp_base_path / "rate/value") - .set_coercer([this, chan](const double value){ - return this->_tree->access<double>( - this->get_arg_path("input_rate/value", chan) - ).set(value).get(); - }) - .set_publisher([this, chan](){ - return this->_tree->access<double>( - this->get_arg_path("input_rate/value", chan) - ).get(); + .set_coercer([this, chan](const double value) { + return this->_tree + ->access<double>(this->get_arg_path("input_rate/value", chan)) + .set(value) + .get(); }) - ; + .set_publisher([this, chan]() { + return this->_tree + ->access<double>(this->get_arg_path("input_rate/value", chan)) + .get(); + }); _tree->create<uhd::meta_range_t>(dsp_base_path / "rate/range") - .set_publisher([this](){ - return get_input_rates(); - }) - ; + .set_publisher([this]() { return get_input_rates(); }); _tree->create<double>(dsp_base_path / "freq/value") - .set_coercer([this, chan](const double value){ - return this->_tree->access<double>( - this->get_arg_path("freq/value", chan) - ).set(value).get(); - }) - .set_publisher([this, chan](){ - return this->_tree->access<double>( - this->get_arg_path("freq/value", chan) - ).get(); + .set_coercer([this, chan](const double value) { + return this->_tree + ->access<double>(this->get_arg_path("freq/value", chan)) + .set(value) + .get(); }) - ; + .set_publisher([this, chan]() { + return this->_tree + ->access<double>(this->get_arg_path("freq/value", chan)) + .get(); + }); _tree->create<uhd::meta_range_t>(dsp_base_path / "freq/range") - .set_publisher([this](){ - return get_freq_range(); - }) - ; + .set_publisher([this]() { return get_freq_range(); }); _tree->access<uhd::time_spec_t>("time/cmd") - .add_coerced_subscriber([this, chan](const uhd::time_spec_t time_spec){ + .add_coerced_subscriber([this, chan](const uhd::time_spec_t time_spec) { this->set_command_time(time_spec, chan); - }) - ; + }); if (_tree->exists("tick_rate")) { - const double tick_rate = - _tree->access<double>("tick_rate").get(); + const double tick_rate = _tree->access<double>("tick_rate").get(); set_command_tick_rate(tick_rate, chan); _tree->access<double>("tick_rate") - .add_coerced_subscriber([this, chan](const double rate){ + .add_coerced_subscriber([this, chan](const double rate) { this->set_command_tick_rate(rate, chan); - }) - ; + }); } // Rate 1:1 by default @@ -124,16 +112,16 @@ public: virtual ~duc_block_ctrl_impl() {} - double get_input_scale_factor(size_t port=ANY_PORT) + double get_input_scale_factor(size_t port = ANY_PORT) { port = (port == ANY_PORT) ? 0 : port; - if (not (_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { + if (not(_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { return SCALE_UNDEFINED; } return get_arg<double>("scalar_correction", port); } - double get_input_samp_rate(size_t port=ANY_PORT) + double get_input_samp_rate(size_t port = ANY_PORT) { port = (port == ANY_PORT) ? 0 : port; @@ -145,31 +133,31 @@ public: set_command_tick_rate(tick_rate, port); } - if (not (_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { + if (not(_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { return RATE_UNDEFINED; } return get_arg<double>("input_rate", port); } - double get_output_samp_rate(size_t port=ANY_PORT) + double get_output_samp_rate(size_t port = ANY_PORT) { port = (port == ANY_PORT) ? 0 : port; - if (not (_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { + if (not(_tx_streamer_active.count(port) and _tx_streamer_active.at(port))) { return RATE_UNDEFINED; } return get_arg<double>("output_rate", port == ANY_PORT ? 0 : port); } - void issue_stream_cmd( - const uhd::stream_cmd_t &stream_cmd_, - const size_t chan - ) { - UHD_RFNOC_BLOCK_TRACE() << "duc_block_ctrl_base::issue_stream_cmd()" ; + void issue_stream_cmd(const uhd::stream_cmd_t& stream_cmd_, const size_t chan) + { + UHD_RFNOC_BLOCK_TRACE() << "duc_block_ctrl_base::issue_stream_cmd()"; uhd::stream_cmd_t stream_cmd = stream_cmd_; - if (stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE or - stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE) { - size_t interpolation = get_arg<double>("output_rate", chan) / get_arg<double>("input_rate", chan); + if (stream_cmd.stream_mode == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE + or stream_cmd.stream_mode + == uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE) { + size_t interpolation = get_arg<double>("output_rate", chan) + / get_arg<double>("input_rate", chan); stream_cmd.num_samps *= interpolation; } @@ -177,11 +165,10 @@ public: } private: - - static constexpr size_t MAJOR_COMP = 2; - static constexpr size_t MINOR_COMP = 0; - static constexpr size_t RB_REG_COMPAT_NUM = 0; - static constexpr size_t RB_REG_NUM_HALFBANDS = 1; + static constexpr size_t MAJOR_COMP = 2; + static constexpr size_t MINOR_COMP = 0; + static constexpr size_t RB_REG_COMPAT_NUM = 0; + static constexpr size_t RB_REG_NUM_HALFBANDS = 1; static constexpr size_t RB_REG_CIC_MAX_INTERP = 2; const uint64_t _fpga_compat; @@ -204,10 +191,7 @@ private: { const double output_rate = get_arg<double>("output_rate"); return uhd::meta_range_t( - -output_rate/2, - +output_rate/2, - output_rate/std::pow(2.0, 32) - ); + -output_rate / 2, +output_rate / 2, output_rate / std::pow(2.0, 32)); } uhd::meta_range_t get_input_rates(void) @@ -215,11 +199,11 @@ private: uhd::meta_range_t range; const double output_rate = get_arg<double>("output_rate"); for (int hb = _num_halfbands; hb >= 0; hb--) { - const size_t interp_offset = _cic_max_interp<<(hb-1); - for(size_t interp = _cic_max_interp; interp > 0; interp--) { - const size_t hb_cic_interp = interp*(1<<hb); - if(hb == 0 || hb_cic_interp > interp_offset) { - range.push_back(uhd::range_t(output_rate/hb_cic_interp)); + const size_t interp_offset = _cic_max_interp << (hb - 1); + for (size_t interp = _cic_max_interp; interp > 0; interp--) { + const size_t hb_cic_interp = interp * (1 << hb); + if (hb == 0 || hb_cic_interp > interp_offset) { + range.push_back(uhd::range_t(output_rate / hb_cic_interp)); } } } @@ -229,7 +213,8 @@ private: double set_input_rate(const double requested_rate, const size_t chan) { const double output_rate = get_arg<double>("output_rate", chan); - const size_t interp_rate = boost::math::iround(output_rate/get_input_rates().clip(requested_rate, true)); + const size_t interp_rate = boost::math::iround( + output_rate / get_input_rates().clip(requested_rate, true)); size_t interp = interp_rate; uint32_t hb_enable = 0; @@ -247,47 +232,56 @@ private: sr_write("M", std::pow(2.0, double(hb_enable)) * (interp & 0xff), chan); if (interp > 1 and hb_enable == 0) { - UHD_LOGGER_WARNING("RFNOC") << boost::format( - "The requested interpolation is odd; the user should expect passband CIC rolloff.\n" - "Select an even interpolation to ensure that a halfband filter is enabled.\n" - "interpolation = dsp_rate/samp_rate -> %d = (%f MHz)/(%f MHz)\n" - ) % interp_rate % (output_rate/1e6) % (requested_rate/1e6); + UHD_LOGGER_WARNING("RFNOC") + << boost::format( + "The requested interpolation is odd; the user should expect " + "passband CIC rolloff.\n" + "Select an even interpolation to ensure that a halfband filter is " + "enabled.\n" + "interpolation = dsp_rate/samp_rate -> %d = (%f MHz)/(%f MHz)\n") + % interp_rate % (output_rate / 1e6) % (requested_rate / 1e6); } // Calculate algorithmic gain of CIC for a given interpolation // For Ettus CIC R=interp, M=1, N=4. Gain = (R * M) ^ (N - 1) - const int CIC_N = 4; - const double rate_pow = std::pow(double(interp & 0xff), CIC_N - 1); + const int CIC_N = 4; + const double rate_pow = std::pow(double(interp & 0xff), CIC_N - 1); const double CONSTANT_GAIN = 1.0; const double scaling_adjustment = - std::pow(2, uhd::math::ceil_log2(rate_pow))/(CONSTANT_GAIN*rate_pow); + std::pow(2, uhd::math::ceil_log2(rate_pow)) / (CONSTANT_GAIN * rate_pow); update_scalar(scaling_adjustment, chan); - return output_rate/interp_rate; + return output_rate / interp_rate; } //! Set frequency and interpolation again void set_output_rate(const double /* rate */, const size_t chan) { - const double desired_freq = _tree->access<double>(get_arg_path("freq", chan) / "value").get_desired(); + const double desired_freq = + _tree->access<double>(get_arg_path("freq", chan) / "value").get_desired(); set_arg<double>("freq", desired_freq, chan); - const double desired_input_rate = _tree->access<double>(get_arg_path("input_rate", chan) / "value").get_desired(); + const double desired_input_rate = + _tree->access<double>(get_arg_path("input_rate", chan) / "value") + .get_desired(); set_arg<double>("input_rate", desired_input_rate, chan); } - // Calculate compensation gain values for algorithmic gain of DDS and CIC taking into account - // gain compensation blocks already hardcoded in place in DUC (that provide simple 1/2^n gain compensation). - // Further more factor in OTW format which adds further gain factor to weight output samples correctly. + // Calculate compensation gain values for algorithmic gain of DDS and CIC taking into + // account gain compensation blocks already hardcoded in place in DUC (that provide + // simple 1/2^n gain compensation). Further more factor in OTW format which adds + // further gain factor to weight output samples correctly. void update_scalar(const double scalar, const size_t chan) { - const double target_scalar = (1 << 15) * scalar; + const double target_scalar = (1 << 15) * scalar; const int32_t actual_scalar = boost::math::iround(target_scalar); // Calculate the error introduced by using integer representation for the scalar const double scalar_correction = - actual_scalar / target_scalar * (double(1 << 15) - 1.0) // Rounding error, normalized to 1.0 + actual_scalar / target_scalar + * (double(1 << 15) - 1.0) // Rounding error, normalized to 1.0 * get_arg<double>("fullscale"); // Scaling requested by host set_arg<double>("scalar_correction", scalar_correction, chan); - // Write DUC with scaling correction for CIC and CORDIC that maximizes dynamic range in 32/16/12/8bits. + // Write DUC with scaling correction for CIC and CORDIC that maximizes dynamic + // range in 32/16/12/8bits. sr_write("SCALE_IQ", actual_scalar, chan); } @@ -297,13 +291,13 @@ private: return _fpga_compat; } - //Get cached value of _num_halfbands + // Get cached value of _num_halfbands size_t get_num_halfbands() const { return _num_halfbands; } - //Get cached value of _cic_max_decim readback + // Get cached value of _cic_max_decim readback size_t get_cic_max_interp() const { return _cic_max_interp; diff --git a/host/lib/rfnoc/fir_block_ctrl_impl.cpp b/host/lib/rfnoc/fir_block_ctrl_impl.cpp index 4267e0b22..a4106111e 100644 --- a/host/lib/rfnoc/fir_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/fir_block_ctrl_impl.cpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/fir_block_ctrl.hpp> #include <uhd/convert.hpp> +#include <uhd/rfnoc/fir_block_ctrl.hpp> #include <uhd/utils/log.hpp> using namespace uhd::rfnoc; @@ -31,20 +31,21 @@ public: set_taps(default_taps); } - void set_taps(const std::vector<int> &taps_) + void set_taps(const std::vector<int>& taps_) { UHD_LOGGER_TRACE(unique_id()) << "fir_block::set_taps()" << std::endl; if (taps_.size() > _n_taps) { - throw uhd::value_error(str( - boost::format("FIR block: Too many filter coefficients! Provided %d, FIR allows %d.\n") - % taps_.size() % _n_taps - )); + throw uhd::value_error( + str(boost::format("FIR block: Too many filter coefficients! Provided %d, " + "FIR allows %d.\n") + % taps_.size() % _n_taps)); } for (size_t i = 0; i < taps_.size(); i++) { if (taps_[i] > 32767 || taps_[i] < -32768) { - throw uhd::value_error(str( - boost::format("FIR block: Coefficient %d out of range! Value %d, Allowed range [-32768,32767].\n") - % i % taps_[i])); + throw uhd::value_error( + str(boost::format("FIR block: Coefficient %d out of range! Value %d, " + "Allowed range [-32768,32767].\n") + % i % taps_[i])); } } std::vector<int> taps = taps_; @@ -58,8 +59,8 @@ public: } // Assert tlast when sending the spinal tap (haha, it's actually the final tap). sr_write(SR_RELOAD_TLAST, uint32_t(taps.back())); - // Send the configuration word to replace the existing coefficients with the new ones. - // Note: This configuration bus does not require tlast + // Send the configuration word to replace the existing coefficients with the new + // ones. Note: This configuration bus does not require tlast sr_write(SR_CONFIG, 0); } diff --git a/host/lib/rfnoc/graph_impl.cpp b/host/lib/rfnoc/graph_impl.cpp index 0d90150c1..989bcb0c4 100644 --- a/host/lib/rfnoc/graph_impl.cpp +++ b/host/lib/rfnoc/graph_impl.cpp @@ -5,8 +5,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/source_block_ctrl_base.hpp> #include <uhd/rfnoc/sink_block_ctrl_base.hpp> +#include <uhd/rfnoc/source_block_ctrl_base.hpp> #include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/graph_impl.hpp> @@ -15,13 +15,10 @@ using namespace uhd::rfnoc; /**************************************************************************** * Structors ***************************************************************************/ -graph_impl::graph_impl( - const std::string &name, - boost::weak_ptr<uhd::device3> device_ptr, - async_msg_handler::sptr msg_handler -) : _name(name) - , _device_ptr(device_ptr) - , _msg_handler(msg_handler) +graph_impl::graph_impl(const std::string& name, + boost::weak_ptr<uhd::device3> device_ptr, + async_msg_handler::sptr msg_handler) + : _name(name), _device_ptr(device_ptr), _msg_handler(msg_handler) { UHD_LOG_TRACE("RFNOC", "Instantiating RFNoC graph " << _name); } @@ -29,13 +26,12 @@ graph_impl::graph_impl( /**************************************************************************** * Connection API ***************************************************************************/ -void graph_impl::connect( - const block_id_t &src_block, - size_t src_block_port, - const block_id_t &dst_block, - size_t dst_block_port, - const size_t pkt_size_ -) { +void graph_impl::connect(const block_id_t& src_block, + size_t src_block_port, + const block_id_t& dst_block, + size_t dst_block_port, + const size_t pkt_size_) +{ device3::sptr device_ptr = _device_ptr.lock(); if (not device_ptr) { throw uhd::runtime_error("Invalid device"); @@ -45,62 +41,51 @@ void graph_impl::connect( device_ptr->get_block_ctrl<rfnoc::source_block_ctrl_base>(src_block); uhd::rfnoc::sink_block_ctrl_base::sptr dst = device_ptr->get_block_ctrl<rfnoc::sink_block_ctrl_base>(dst_block); - UHD_LOGGER_TRACE("RFNOC") - << "[" << _name << "] Attempting to connect " - << src_block << ":" << src_block_port << " --> " - << dst_block << ":" << dst_block_port - ; + UHD_LOGGER_TRACE("RFNOC") << "[" << _name << "] Attempting to connect " << src_block + << ":" << src_block_port << " --> " << dst_block << ":" + << dst_block_port; /******************************************************************** * 1. Draw the edges (logically connect the nodes) ********************************************************************/ size_t actual_src_block_port = src->connect_downstream( - boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(dst), - src_block_port - ); + boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(dst), src_block_port); if (src_block_port == uhd::rfnoc::ANY_PORT) { src_block_port = actual_src_block_port; } else if (src_block_port != actual_src_block_port) { - throw uhd::runtime_error(str( - boost::format("Can't connect to port %d on block %s.") - % src_block_port % src->unique_id() - )); + throw uhd::runtime_error( + str(boost::format("Can't connect to port %d on block %s.") % src_block_port + % src->unique_id())); } size_t actual_dst_block_port = dst->connect_upstream( - boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(src), - dst_block_port - ); + boost::dynamic_pointer_cast<uhd::rfnoc::node_ctrl_base>(src), dst_block_port); if (dst_block_port == uhd::rfnoc::ANY_PORT) { dst_block_port = actual_dst_block_port; } else if (dst_block_port != actual_dst_block_port) { - throw uhd::runtime_error(str( - boost::format("Can't connect to port %d on block %s.") - % dst_block_port % dst->unique_id() - )); + throw uhd::runtime_error( + str(boost::format("Can't connect to port %d on block %s.") % dst_block_port + % dst->unique_id())); } src->set_downstream_port(actual_src_block_port, actual_dst_block_port); dst->set_upstream_port(actual_dst_block_port, actual_src_block_port); // At this point, ports are locked and no one else can simply connect // into them. - UHD_LOGGER_TRACE("RFNOC") - << "[" << _name << "] Connecting " - << src_block << ":" << actual_src_block_port << " --> " - << dst_block << ":" << actual_dst_block_port - ; + UHD_LOGGER_TRACE("RFNOC") << "[" << _name << "] Connecting " << src_block << ":" + << actual_src_block_port << " --> " << dst_block << ":" + << actual_dst_block_port; /******************************************************************** * 2. Check IO signatures match ********************************************************************/ if (not rfnoc::stream_sig_t::is_compatible( - src->get_output_signature(actual_src_block_port), - dst->get_input_signature(actual_dst_block_port) - )) { - throw uhd::runtime_error(str( - boost::format("Can't connect block %s to %s: IO signature mismatch\n(%s is incompatible with %s).") - % src->get_block_id().get() % dst->get_block_id().get() - % src->get_output_signature(actual_src_block_port) - % dst->get_input_signature(actual_dst_block_port) - )); + src->get_output_signature(actual_src_block_port), + dst->get_input_signature(actual_dst_block_port))) { + throw uhd::runtime_error( + str(boost::format("Can't connect block %s to %s: IO signature mismatch\n(%s " + "is incompatible with %s).") + % src->get_block_id().get() % dst->get_block_id().get() + % src->get_output_signature(actual_src_block_port) + % dst->get_input_signature(actual_dst_block_port))); } UHD_LOG_TRACE("RFNOC", "IO signatures match."); @@ -117,38 +102,37 @@ void graph_impl::connect( /******************************************************************** * 4. Configure flow control ********************************************************************/ - size_t pkt_size = (pkt_size_ != 0) ? pkt_size_ : src->get_output_signature(src_block_port).packet_size; + size_t pkt_size = (pkt_size_ != 0) + ? pkt_size_ + : src->get_output_signature(src_block_port).packet_size; if (pkt_size == 0) { // Unspecified packet rate. Assume max packet size. - UHD_LOGGER_WARNING("RFNOC") << "Assuming max packet size for " << src->get_block_id() ; + UHD_LOGGER_WARNING("RFNOC") + << "Assuming max packet size for " << src->get_block_id(); pkt_size = uhd::rfnoc::MAX_PACKET_SIZE; } // FC window (in bytes) depends on FIFO size. size_t buf_size_bytes = dst->get_fifo_size(dst_block_port); if (buf_size_bytes < pkt_size) { - throw uhd::runtime_error(str( - boost::format("Input FIFO for block %s is too small (%d kiB) for packets of size %d kiB\n" - "coming from block %s.") - % dst->get_block_id().get() % (dst->get_fifo_size(dst_block_port) / 1024) - % (pkt_size / 1024) % src->get_block_id().get() - )); + throw uhd::runtime_error( + str(boost::format("Input FIFO for block %s is too small (%d kiB) for packets " + "of size %d kiB\n" + "coming from block %s.") + % dst->get_block_id().get() % (dst->get_fifo_size(dst_block_port) / 1024) + % (pkt_size / 1024) % src->get_block_id().get())); } - src->configure_flow_control_out( - true, /* enable output */ - buf_size_bytes, - 0, /* no packet limit. We need to revisit this at some point. */ - src_block_port - ); + src->configure_flow_control_out(true, /* enable output */ + buf_size_bytes, + 0, /* no packet limit. We need to revisit this at some point. */ + src_block_port); // On the same crossbar, use lots of FC packets - size_t bytes_per_response = buf_size_bytes / uhd::rfnoc::DEFAULT_FC_XBAR_RESPONSE_FREQ; + size_t bytes_per_response = + buf_size_bytes / uhd::rfnoc::DEFAULT_FC_XBAR_RESPONSE_FREQ; // Over the network, use less or we'd flood the transport if (sid.get_src_addr() != sid.get_dst_addr()) { bytes_per_response = buf_size_bytes / uhd::rfnoc::DEFAULT_FC_TX_RESPONSE_FREQ; } UHD_ASSERT_THROW(bytes_per_response != 0); - dst->configure_flow_control_in( - bytes_per_response, - dst_block_port - ); + dst->configure_flow_control_in(bytes_per_response, dst_block_port); /******************************************************************** * 5. Configure error policy @@ -158,33 +142,30 @@ void graph_impl::connect( /******************************************************************** * 6. Set async message handling ********************************************************************/ - src->sr_write(uhd::rfnoc::SR_RESP_OUT_DST_SID, _msg_handler->get_local_addr(), src_block_port); - dst->sr_write(uhd::rfnoc::SR_RESP_IN_DST_SID, _msg_handler->get_local_addr(), dst_block_port); + src->sr_write( + uhd::rfnoc::SR_RESP_OUT_DST_SID, _msg_handler->get_local_addr(), src_block_port); + dst->sr_write( + uhd::rfnoc::SR_RESP_IN_DST_SID, _msg_handler->get_local_addr(), dst_block_port); } -void graph_impl::connect( - const block_id_t &src_block, - const block_id_t &dst_block -) { +void graph_impl::connect(const block_id_t& src_block, const block_id_t& dst_block) +{ connect(src_block, ANY_PORT, dst_block, ANY_PORT); } -void graph_impl::connect_src( - const block_id_t &src_block, +void graph_impl::connect_src(const block_id_t& src_block, const size_t src_block_port, const uhd::sid_t dst_sid, const size_t buf_size_dst_bytes, - const size_t pkt_size_ -) { + const size_t pkt_size_) +{ device3::sptr device_ptr = _device_ptr.lock(); if (not device_ptr) { throw uhd::runtime_error("Invalid device"); } - UHD_LOGGER_DEBUG("RFNOC") - << "[" << _name << "] Connecting " - << src_block << ":" << src_block_port << " --> " - << dst_sid.to_pp_string_hex(); + UHD_LOGGER_DEBUG("RFNOC") << "[" << _name << "] Connecting " << src_block << ":" + << src_block_port << " --> " << dst_sid.to_pp_string_hex(); uhd::rfnoc::source_block_ctrl_base::sptr src = device_ptr->get_block_ctrl<rfnoc::source_block_ctrl_base>(src_block); @@ -192,8 +173,8 @@ void graph_impl::connect_src( src->set_destination(dst_sid.get(), src_block_port); size_t pkt_size = (pkt_size_ != 0) - ? pkt_size_ - : src->get_output_signature(src_block_port).packet_size; + ? pkt_size_ + : src->get_output_signature(src_block_port).packet_size; if (pkt_size == 0) { // Unspecified packet rate. Assume max packet size. UHD_LOGGER_WARNING("RFNOC") << "Assuming max packet size for " << src->get_block_id(); @@ -201,32 +182,26 @@ void graph_impl::connect_src( } size_t buf_size_pkts = buf_size_dst_bytes / pkt_size; if (buf_size_pkts == 0) { - throw uhd::runtime_error(str( - boost::format("Input FIFO for unknown destination is too small " - "(%d kiB) for packets of size %d kiB\n coming from " - "block %s.") - % (buf_size_dst_bytes / 1024) - % (pkt_size / 1024) - % src->get_block_id().get() - )); + throw uhd::runtime_error( + str(boost::format("Input FIFO for unknown destination is too small " + "(%d kiB) for packets of size %d kiB\n coming from " + "block %s.") + % (buf_size_dst_bytes / 1024) % (pkt_size / 1024) + % src->get_block_id().get())); } src->configure_flow_control_out(buf_size_pkts, src_block_port); - } void graph_impl::connect_sink( - const block_id_t &sink_block, - const size_t dst_block_port, - const size_t bytes_per_ack -) { + const block_id_t& sink_block, const size_t dst_block_port, const size_t bytes_per_ack) +{ device3::sptr device_ptr = _device_ptr.lock(); if (not device_ptr) { throw uhd::runtime_error("Invalid device"); } - UHD_LOGGER_DEBUG("RFNOC") - << "[" << _name << "] Connecting unknown source to" - << sink_block << ":" << dst_block_port; + UHD_LOGGER_DEBUG("RFNOC") << "[" << _name << "] Connecting unknown source to" + << sink_block << ":" << dst_block_port; uhd::rfnoc::sink_block_ctrl_base::sptr dst = device_ptr->get_block_ctrl<rfnoc::sink_block_ctrl_base>(sink_block); @@ -237,4 +212,3 @@ void graph_impl::connect_sink( ********************************************************************/ dst->set_error_policy("next_burst"); } - diff --git a/host/lib/rfnoc/legacy_compat.cpp b/host/lib/rfnoc/legacy_compat.cpp index c5bd7891a..f794b1c5a 100644 --- a/host/lib/rfnoc/legacy_compat.cpp +++ b/host/lib/rfnoc/legacy_compat.cpp @@ -7,26 +7,26 @@ #include "../usrp/device3/device3_impl.hpp" #include <uhd/property_tree.hpp> -#include <uhd/rfnoc/radio_ctrl.hpp> #include <uhd/rfnoc/ddc_block_ctrl.hpp> #include <uhd/rfnoc/graph.hpp> -#include <uhd/usrp/subdev_spec.hpp> +#include <uhd/rfnoc/radio_ctrl.hpp> #include <uhd/stream.hpp> -#include <uhd/types/stream_cmd.hpp> +#include <uhd/transport/chdr.hpp> #include <uhd/types/direction.hpp> #include <uhd/types/ranges.hpp> -#include <uhd/utils/log.hpp> -#include <uhd/transport/chdr.hpp> +#include <uhd/types/stream_cmd.hpp> #include <uhd/usrp/multi_usrp.hpp> +#include <uhd/usrp/subdev_spec.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/legacy_compat.hpp> #include <boost/make_shared.hpp> #define UHD_LEGACY_LOG() UHD_LOGGER_TRACE("RFNOC") using namespace uhd::rfnoc; -using uhd::usrp::subdev_spec_t; -using uhd::usrp::subdev_spec_pair_t; using uhd::stream_cmd_t; +using uhd::usrp::subdev_spec_pair_t; +using uhd::usrp::subdev_spec_t; /************************************************************************ * Constants and globals @@ -34,24 +34,18 @@ using uhd::stream_cmd_t; static const std::string RADIO_BLOCK_NAME = "Radio"; static const std::string DFIFO_BLOCK_NAME = "DmaFIFO"; static const std::string SFIFO_BLOCK_NAME = "FIFO"; -static const std::string DDC_BLOCK_NAME = "DDC"; -static const std::string DUC_BLOCK_NAME = "DUC"; +static const std::string DDC_BLOCK_NAME = "DDC"; +static const std::string DUC_BLOCK_NAME = "DUC"; static const size_t MAX_BYTES_PER_HEADER = - uhd::transport::vrt::chdr::max_if_hdr_words64 * sizeof(uint64_t); + uhd::transport::vrt::chdr::max_if_hdr_words64 * sizeof(uint64_t); static const size_t BYTES_PER_SAMPLE = 4; // We currently only support sc16 static boost::mutex _make_mutex; -static const std::vector<std::string> - LEGACY_BLOCKS_LIST = - { - RADIO_BLOCK_NAME, - DFIFO_BLOCK_NAME, - SFIFO_BLOCK_NAME, - DDC_BLOCK_NAME, - DUC_BLOCK_NAME - }; +static const std::vector<std::string> LEGACY_BLOCKS_LIST = { + RADIO_BLOCK_NAME, DFIFO_BLOCK_NAME, SFIFO_BLOCK_NAME, DDC_BLOCK_NAME, DUC_BLOCK_NAME}; typedef std::vector<source_block_ctrl_base::sptr> source_block_list_t; typedef std::vector<sink_block_ctrl_base::sptr> sink_block_list_t; -typedef std::map<std::string, std::pair<source_block_list_t, sink_block_list_t>> block_name_to_block_map_t; +typedef std::map<std::string, std::pair<source_block_list_t, sink_block_list_t>> + block_name_to_block_map_t; typedef std::pair<source_block_ctrl_base::sptr, size_t> source_port_t; typedef std::pair<sink_block_ctrl_base::sptr, size_t> sink_port_t; /************************************************************************ @@ -62,46 +56,42 @@ static uhd::fs_path mb_root(const size_t mboard) return uhd::fs_path("/mboards") / mboard; } -size_t num_ports(const uhd::property_tree::sptr &tree, const std::string &block_name, const std::string &in_out) +size_t num_ports(const uhd::property_tree::sptr& tree, + const std::string& block_name, + const std::string& in_out) { - return tree->list( - uhd::fs_path("/mboards/0/xbar") / - str(boost::format("%s_0") % block_name) / - "ports" / in_out - ).size(); + return tree + ->list(uhd::fs_path("/mboards/0/xbar") / str(boost::format("%s_0") % block_name) + / "ports" / in_out) + .size(); } -size_t calc_num_tx_chans_per_radio( - const uhd::property_tree::sptr &tree, +size_t calc_num_tx_chans_per_radio(const uhd::property_tree::sptr& tree, const size_t num_radios_per_board, const bool has_ducs, - const bool has_dmafifo -) { + const bool has_dmafifo) +{ const size_t num_radio_ports = num_ports(tree, RADIO_BLOCK_NAME, "in"); if (has_ducs) { - return std::min( - num_radio_ports, - num_ports(tree, DUC_BLOCK_NAME, "in") - ); + return std::min(num_radio_ports, num_ports(tree, DUC_BLOCK_NAME, "in")); } if (not has_dmafifo) { return num_radio_ports; } - const size_t num_dmafifo_ports_per_radio = num_ports(tree, DFIFO_BLOCK_NAME, "in") / num_radios_per_board; + const size_t num_dmafifo_ports_per_radio = + num_ports(tree, DFIFO_BLOCK_NAME, "in") / num_radios_per_board; UHD_ASSERT_THROW(num_dmafifo_ports_per_radio); - return std::min( - num_radio_ports, - num_dmafifo_ports_per_radio - ); + return std::min(num_radio_ports, num_dmafifo_ports_per_radio); } /*! Recreate passed property without bound subscribers. Maintains current property value. -*/ + */ template <typename T> -static void recreate_property(const uhd::fs_path &path, uhd::property_tree::sptr &tree) { +static void recreate_property(const uhd::fs_path& path, uhd::property_tree::sptr& tree) +{ T temp = tree->access<T>(path).get(); tree->remove(path); tree->create<T>(path).set(temp); @@ -116,95 +106,110 @@ public: /************************************************************************ * Structors and Initialization ***********************************************************************/ - legacy_compat_impl( - uhd::device3::sptr device, - const uhd::device_addr_t &args - ) : _device(device), - _tree(device->get_tree()), - _has_ducs(not args.has_key("skip_duc") and not device->find_blocks(DUC_BLOCK_NAME).empty()), - _has_ddcs(not args.has_key("skip_ddc") and not device->find_blocks(DDC_BLOCK_NAME).empty()), - _has_dmafifo(not args.has_key("skip_dram") and not device->find_blocks(DFIFO_BLOCK_NAME).empty()), - _has_sramfifo(not args.has_key("skip_sram") and not device->find_blocks(SFIFO_BLOCK_NAME).empty()), - _num_mboards(_tree->list("/mboards").size()), - _num_radios_per_board(device->find_blocks<radio_ctrl>("0/Radio").size()), // These might throw, maybe we catch that and provide a nicer error message. - _num_tx_chans_per_radio( - calc_num_tx_chans_per_radio(_tree, _num_radios_per_board, _has_ducs, _has_dmafifo) - ), - _num_rx_chans_per_radio(_has_ddcs ? - std::min(num_ports(_tree, RADIO_BLOCK_NAME, "out"), num_ports(_tree, DDC_BLOCK_NAME, "out")) - : num_ports(_tree, RADIO_BLOCK_NAME, "out")), - _rx_spp(get_block_ctrl<radio_ctrl>(0, RADIO_BLOCK_NAME, 0)->get_arg<int>("spp")), - _tx_spp(_rx_spp), - _rx_channel_map(_num_mboards, std::vector<radio_port_pair_t>()), - _tx_channel_map(_num_mboards, std::vector<radio_port_pair_t>()) + legacy_compat_impl(uhd::device3::sptr device, const uhd::device_addr_t& args) + : _device(device) + , _tree(device->get_tree()) + , _has_ducs(not args.has_key("skip_duc") + and not device->find_blocks(DUC_BLOCK_NAME).empty()) + , _has_ddcs(not args.has_key("skip_ddc") + and not device->find_blocks(DDC_BLOCK_NAME).empty()) + , _has_dmafifo(not args.has_key("skip_dram") + and not device->find_blocks(DFIFO_BLOCK_NAME).empty()) + , _has_sramfifo(not args.has_key("skip_sram") + and not device->find_blocks(SFIFO_BLOCK_NAME).empty()) + , _num_mboards(_tree->list("/mboards").size()) + , _num_radios_per_board(device->find_blocks<radio_ctrl>("0/Radio").size()) + , // These might throw, maybe we catch that and provide a nicer error message. + _num_tx_chans_per_radio(calc_num_tx_chans_per_radio( + _tree, _num_radios_per_board, _has_ducs, _has_dmafifo)) + , _num_rx_chans_per_radio( + _has_ddcs ? std::min(num_ports(_tree, RADIO_BLOCK_NAME, "out"), + num_ports(_tree, DDC_BLOCK_NAME, "out")) + : num_ports(_tree, RADIO_BLOCK_NAME, "out")) + , _rx_spp(get_block_ctrl<radio_ctrl>(0, RADIO_BLOCK_NAME, 0)->get_arg<int>("spp")) + , _tx_spp(_rx_spp) + , _rx_channel_map(_num_mboards, std::vector<radio_port_pair_t>()) + , _tx_channel_map(_num_mboards, std::vector<radio_port_pair_t>()) { _device->clear(); check_available_periphs(); // Throws if invalid configuration. setup_prop_tree(); if (_tree->exists("/mboards/0/mtu/send")) { - _tx_spp = (_tree->access<size_t>("/mboards/0/mtu/send").get() - MAX_BYTES_PER_HEADER) / BYTES_PER_SAMPLE; + _tx_spp = (_tree->access<size_t>("/mboards/0/mtu/send").get() + - MAX_BYTES_PER_HEADER) + / BYTES_PER_SAMPLE; } connect_blocks(); if (args.has_key("skip_ddc")) { - UHD_LEGACY_LOG() << "[legacy_compat] Skipping DDCs by user request." ; + UHD_LEGACY_LOG() << "[legacy_compat] Skipping DDCs by user request."; } else if (not _has_ddcs) { UHD_LOGGER_WARNING("RFNOC") - << "[legacy_compat] No DDCs detected. You will only be able to receive at the radio frontend rate." - ; + << "[legacy_compat] No DDCs detected. You will only be able to receive " + "at the radio frontend rate."; } if (args.has_key("skip_duc")) { - UHD_LEGACY_LOG() << "[legacy_compat] Skipping DUCs by user request." ; + UHD_LEGACY_LOG() << "[legacy_compat] Skipping DUCs by user request."; } else if (not _has_ducs) { - UHD_LOGGER_WARNING("RFNOC") << "[legacy_compat] No DUCs detected. You will only be able to transmit at the radio frontend rate." ; + UHD_LOGGER_WARNING("RFNOC") + << "[legacy_compat] No DUCs detected. You will only be able to transmit " + "at the radio frontend rate."; } if (args.has_key("skip_dram")) { - UHD_LEGACY_LOG() << "[legacy_compat] Skipping DRAM by user request." ; + UHD_LEGACY_LOG() << "[legacy_compat] Skipping DRAM by user request."; } if (args.has_key("skip_sram")) { UHD_LEGACY_LOG() << "[legacy_compat] Skipping SRAM by user request."; } if (not _has_dmafifo and not _has_sramfifo) { - UHD_LOGGER_WARNING("RFNOC") << "[legacy_compat] No FIFO detected. Higher transmit rates may encounter errors."; + UHD_LOGGER_WARNING("RFNOC") << "[legacy_compat] No FIFO detected. Higher " + "transmit rates may encounter errors."; } for (size_t mboard = 0; mboard < _num_mboards; mboard++) { for (size_t radio = 0; radio < _num_radios_per_board; radio++) { - auto radio_block_ctrl = get_block_ctrl<radio_ctrl>(mboard, "Radio", radio); + auto radio_block_ctrl = + get_block_ctrl<radio_ctrl>(mboard, "Radio", radio); for (size_t port = 0; port < _num_rx_chans_per_radio; port++) { - if (!radio_block_ctrl->get_dboard_fe_from_chan(port, uhd::RX_DIRECTION).empty()) { + if (!radio_block_ctrl->get_dboard_fe_from_chan( + port, uhd::RX_DIRECTION) + .empty()) { _rx_channel_map[mboard].push_back({radio, port}); - } + } } for (size_t port = 0; port < _num_tx_chans_per_radio; port++) { - if (!radio_block_ctrl->get_dboard_fe_from_chan(port, uhd::TX_DIRECTION).empty()) { + if (!radio_block_ctrl->get_dboard_fe_from_chan( + port, uhd::TX_DIRECTION) + .empty()) { _tx_channel_map[mboard].push_back({radio, port}); } } } - const double tick_rate = _tree->access<double>(mb_root(mboard) / "tick_rate").get(); + const double tick_rate = + _tree->access<double>(mb_root(mboard) / "tick_rate").get(); update_tick_rate_on_blocks(tick_rate, mboard); } } ~legacy_compat_impl() { - remove_prop_subscribers(); + remove_prop_subscribers(); } /************************************************************************ * API Calls ***********************************************************************/ - inline uhd::fs_path rx_dsp_root(const size_t mboard_idx, const size_t dsp_index, const size_t port_index) + inline uhd::fs_path rx_dsp_root( + const size_t mboard_idx, const size_t dsp_index, const size_t port_index) { - return mb_root(mboard_idx) / "xbar" / - str(boost::format("%s_%d") % DDC_BLOCK_NAME % dsp_index) / - "legacy_api" / port_index; + return mb_root(mboard_idx) / "xbar" + / str(boost::format("%s_%d") % DDC_BLOCK_NAME % dsp_index) / "legacy_api" + / port_index; } uhd::fs_path rx_dsp_root(const size_t mboard_idx, const size_t chan) { // The DSP index is the same as the radio index - size_t dsp_index = _rx_channel_map[mboard_idx][chan].radio_index; + size_t dsp_index = _rx_channel_map[mboard_idx][chan].radio_index; size_t port_index = _rx_channel_map[mboard_idx][chan].port_index; if (not _has_ddcs) { @@ -214,17 +219,18 @@ public: return rx_dsp_root(mboard_idx, dsp_index, port_index); } - inline uhd::fs_path tx_dsp_root(const size_t mboard_idx, const size_t dsp_index, const size_t port_index) + inline uhd::fs_path tx_dsp_root( + const size_t mboard_idx, const size_t dsp_index, const size_t port_index) { - return mb_root(mboard_idx) / "xbar" / - str(boost::format("%s_%d") % DUC_BLOCK_NAME % dsp_index) / - "legacy_api" / port_index; + return mb_root(mboard_idx) / "xbar" + / str(boost::format("%s_%d") % DUC_BLOCK_NAME % dsp_index) / "legacy_api" + / port_index; } uhd::fs_path tx_dsp_root(const size_t mboard_idx, const size_t chan) { // The DSP index is the same as the radio index - size_t dsp_index = _tx_channel_map[mboard_idx][chan].radio_index; + size_t dsp_index = _tx_channel_map[mboard_idx][chan].radio_index; size_t port_index = _tx_channel_map[mboard_idx][chan].port_index; if (not _has_ducs) { @@ -237,33 +243,31 @@ public: uhd::fs_path rx_fe_root(const size_t mboard_idx, const size_t chan) { size_t radio_index = _rx_channel_map[mboard_idx][chan].radio_index; - size_t port_index = _rx_channel_map[mboard_idx][chan].port_index; - return uhd::fs_path(str( - boost::format("/mboards/%d/xbar/%s_%d/rx_fe_corrections/%d/") - % mboard_idx % RADIO_BLOCK_NAME % radio_index % port_index - )); + size_t port_index = _rx_channel_map[mboard_idx][chan].port_index; + return uhd::fs_path( + str(boost::format("/mboards/%d/xbar/%s_%d/rx_fe_corrections/%d/") % mboard_idx + % RADIO_BLOCK_NAME % radio_index % port_index)); } uhd::fs_path tx_fe_root(const size_t mboard_idx, const size_t chan) { size_t radio_index = _tx_channel_map[mboard_idx][chan].radio_index; - size_t port_index = _tx_channel_map[mboard_idx][chan].port_index; - return uhd::fs_path(str( - boost::format("/mboards/%d/xbar/%s_%d/tx_fe_corrections/%d/") - % mboard_idx % RADIO_BLOCK_NAME % radio_index % port_index - )); + size_t port_index = _tx_channel_map[mboard_idx][chan].port_index; + return uhd::fs_path( + str(boost::format("/mboards/%d/xbar/%s_%d/tx_fe_corrections/%d/") % mboard_idx + % RADIO_BLOCK_NAME % radio_index % port_index)); } //! Get all legacy blocks from the LEGACY_BLOCK_LIST return in a form of // {BLOCK_NAME: <{source_block_pointer},{sink_block_pointer}>} block_name_to_block_map_t get_legacy_blocks(uhd::device3::sptr _device) { - block_name_to_block_map_t result ; - for(auto each_block_name: LEGACY_BLOCKS_LIST){ + block_name_to_block_map_t result; + for (auto each_block_name : LEGACY_BLOCKS_LIST) { std::vector<block_id_t> block_list = _device->find_blocks(each_block_name); std::pair<source_block_list_t, sink_block_list_t> ss_pair; source_block_list_t src_list; sink_block_list_t snk_list; - for(auto each_block: block_list){ + for (auto each_block : block_list) { uhd::rfnoc::source_block_ctrl_base::sptr src = _device->get_block_ctrl<source_block_ctrl_base>(each_block); src_list.push_back(src); @@ -271,78 +275,82 @@ public: _device->get_block_ctrl<sink_block_ctrl_base>(each_block); snk_list.push_back(snk); } - ss_pair = std::make_pair(src_list, snk_list); + ss_pair = std::make_pair(src_list, snk_list); result[each_block_name] = ss_pair; } return result; } - void issue_stream_cmd(const stream_cmd_t &stream_cmd, size_t mboard, size_t chan) + void issue_stream_cmd(const stream_cmd_t& stream_cmd, size_t mboard, size_t chan) { - UHD_LEGACY_LOG() << "[legacy_compat] issue_stream_cmd() " ; - const size_t &radio_index = _rx_channel_map[mboard][chan].radio_index; - const size_t &port_index = _rx_channel_map[mboard][chan].port_index; + UHD_LEGACY_LOG() << "[legacy_compat] issue_stream_cmd() "; + const size_t& radio_index = _rx_channel_map[mboard][chan].radio_index; + const size_t& port_index = _rx_channel_map[mboard][chan].port_index; if (_has_ddcs) { - get_block_ctrl<ddc_block_ctrl>(mboard, DDC_BLOCK_NAME, radio_index)->issue_stream_cmd(stream_cmd, port_index); + get_block_ctrl<ddc_block_ctrl>(mboard, DDC_BLOCK_NAME, radio_index) + ->issue_stream_cmd(stream_cmd, port_index); } else { - get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio_index)->issue_stream_cmd(stream_cmd, port_index); + get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio_index) + ->issue_stream_cmd(stream_cmd, port_index); } } - //! Sets block_id<N> and block_port<N> in the streamer args, otherwise forwards the call - uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &args_) + //! Sets block_id<N> and block_port<N> in the streamer args, otherwise forwards the + //! call + uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t& args_) { uhd::stream_args_t args(args_); if (args.otw_format.empty()) { args.otw_format = "sc16"; } _update_stream_args_for_streaming<uhd::RX_DIRECTION>(args, _rx_channel_map); - UHD_LEGACY_LOG() << "[legacy_compat] rx stream args: " << args.args.to_string() ; + UHD_LEGACY_LOG() << "[legacy_compat] rx stream args: " << args.args.to_string(); uhd::rx_streamer::sptr streamer = _device->get_rx_stream(args); - for(const size_t chan: args.channels) { + for (const size_t chan : args.channels) { _rx_stream_cache[chan] = streamer; } return streamer; } - //! Sets block_id<N> and block_port<N> in the streamer args, otherwise forwards the call. - // If spp is in the args, update the radios. If it's not set, copy the value from the radios. - uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &args_) + //! Sets block_id<N> and block_port<N> in the streamer args, otherwise forwards the + //! call. + // If spp is in the args, update the radios. If it's not set, copy the value from the + // radios. + uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t& args_) { uhd::stream_args_t args(args_); if (args.otw_format.empty()) { args.otw_format = "sc16"; } _update_stream_args_for_streaming<uhd::TX_DIRECTION>(args, _tx_channel_map); - UHD_LEGACY_LOG() << "[legacy_compat] tx stream args: " << args.args.to_string() ; + UHD_LEGACY_LOG() << "[legacy_compat] tx stream args: " << args.args.to_string(); uhd::tx_streamer::sptr streamer = _device->get_tx_stream(args); - for(const size_t chan: args.channels) { + for (const size_t chan : args.channels) { _tx_stream_cache[chan] = streamer; } return streamer; } - double get_tick_rate(const size_t mboard_idx=0) + double get_tick_rate(const size_t mboard_idx = 0) { return _tree->access<double>(mb_root(mboard_idx) / "tick_rate").get(); } - uhd::meta_range_t lambda_get_samp_rate_range( - const size_t mboard_idx, - const size_t radio_idx, - const size_t chan, - uhd::direction_t dir - ) { - radio_ctrl::sptr radio_sptr = get_block_ctrl<radio_ctrl>(mboard_idx, RADIO_BLOCK_NAME, radio_idx); - const double samp_rate = (dir == uhd::TX_DIRECTION) ? - radio_sptr->get_input_samp_rate(chan) : - radio_sptr->get_output_samp_rate(chan) - ; + uhd::meta_range_t lambda_get_samp_rate_range(const size_t mboard_idx, + const size_t radio_idx, + const size_t chan, + uhd::direction_t dir) + { + radio_ctrl::sptr radio_sptr = + get_block_ctrl<radio_ctrl>(mboard_idx, RADIO_BLOCK_NAME, radio_idx); + const double samp_rate = (dir == uhd::TX_DIRECTION) + ? radio_sptr->get_input_samp_rate(chan) + : radio_sptr->get_output_samp_rate(chan); return uhd::meta_range_t(samp_rate, samp_rate, 0.0); } - void set_tick_rate(const double tick_rate, const size_t mboard_idx=0) + void set_tick_rate(const double tick_rate, const size_t mboard_idx = 0) { _tree->access<double>(mb_root(mboard_idx) / "tick_rate").set(tick_rate); update_tick_rate_on_blocks(tick_rate, mboard_idx); @@ -356,13 +364,18 @@ public: // Set DDC values: if (chan == uhd::usrp::multi_usrp::ALL_CHANS) { - for (size_t mboard_idx = 0; mboard_idx < _rx_channel_map.size(); mboard_idx++) { - for (size_t chan_idx = 0; chan_idx < _rx_channel_map[mboard_idx].size(); chan_idx++) { - const size_t dsp_index = _rx_channel_map[mboard_idx][chan_idx].radio_index; - const size_t port_index = _rx_channel_map[mboard_idx][chan_idx].port_index; - _tree->access<double>(rx_dsp_root(mboard_idx, dsp_index, port_index) / "rate/value") - .set(rate) - ; + for (size_t mboard_idx = 0; mboard_idx < _rx_channel_map.size(); + mboard_idx++) { + for (size_t chan_idx = 0; chan_idx < _rx_channel_map[mboard_idx].size(); + chan_idx++) { + const size_t dsp_index = + _rx_channel_map[mboard_idx][chan_idx].radio_index; + const size_t port_index = + _rx_channel_map[mboard_idx][chan_idx].port_index; + _tree + ->access<double>( + rx_dsp_root(mboard_idx, dsp_index, port_index) / "rate/value") + .set(rate); } } } else { @@ -370,25 +383,29 @@ public: if (_rx_stream_cache.count(chan)) { uhd::rx_streamer::sptr str_ptr = _rx_stream_cache[chan].lock(); if (str_ptr) { - for(const rx_stream_map_type::value_type &chan_streamer_pair: _rx_stream_cache) { + for (const rx_stream_map_type::value_type& chan_streamer_pair : + _rx_stream_cache) { if (chan_streamer_pair.second.lock() == str_ptr) { chans_to_change.insert(chan_streamer_pair.first); } } } } - for(const size_t this_chan: chans_to_change) { + for (const size_t this_chan : chans_to_change) { size_t mboard, mb_chan; - chan_to_mcp<uhd::RX_DIRECTION>(this_chan, _rx_channel_map, mboard, mb_chan); + chan_to_mcp<uhd::RX_DIRECTION>( + this_chan, _rx_channel_map, mboard, mb_chan); const size_t dsp_index = _rx_channel_map[mboard][mb_chan].radio_index; const size_t port_index = _rx_channel_map[mboard][mb_chan].port_index; - _tree->access<double>(rx_dsp_root(mboard, dsp_index, port_index) / "rate/value") - .set(rate) - ; + _tree + ->access<double>( + rx_dsp_root(mboard, dsp_index, port_index) / "rate/value") + .set(rate); } } // Update streamers: - boost::dynamic_pointer_cast<uhd::usrp::device3_impl>(_device)->update_rx_streamers(rate); + boost::dynamic_pointer_cast<uhd::usrp::device3_impl>(_device) + ->update_rx_streamers(rate); } void set_tx_rate(const double rate, const size_t chan) @@ -399,13 +416,18 @@ public: // Set DUC values: if (chan == uhd::usrp::multi_usrp::ALL_CHANS) { - for (size_t mboard_idx = 0; mboard_idx < _tx_channel_map.size(); mboard_idx++) { - for (size_t chan_idx = 0; chan_idx < _tx_channel_map[mboard_idx].size(); chan_idx++) { - const size_t dsp_index = _tx_channel_map[mboard_idx][chan_idx].radio_index; - const size_t port_index = _tx_channel_map[mboard_idx][chan_idx].port_index; - _tree->access<double>(tx_dsp_root(mboard_idx, dsp_index, port_index) / "rate/value") - .set(rate) - ; + for (size_t mboard_idx = 0; mboard_idx < _tx_channel_map.size(); + mboard_idx++) { + for (size_t chan_idx = 0; chan_idx < _tx_channel_map[mboard_idx].size(); + chan_idx++) { + const size_t dsp_index = + _tx_channel_map[mboard_idx][chan_idx].radio_index; + const size_t port_index = + _tx_channel_map[mboard_idx][chan_idx].port_index; + _tree + ->access<double>( + tx_dsp_root(mboard_idx, dsp_index, port_index) / "rate/value") + .set(rate); } } } else { @@ -413,37 +435,45 @@ public: if (_tx_stream_cache.count(chan)) { uhd::tx_streamer::sptr str_ptr = _tx_stream_cache[chan].lock(); if (str_ptr) { - for(const tx_stream_map_type::value_type &chan_streamer_pair: _tx_stream_cache) { + for (const tx_stream_map_type::value_type& chan_streamer_pair : + _tx_stream_cache) { if (chan_streamer_pair.second.lock() == str_ptr) { chans_to_change.insert(chan_streamer_pair.first); } } } } - for(const size_t this_chan: chans_to_change) { + for (const size_t this_chan : chans_to_change) { size_t mboard, mb_chan; - chan_to_mcp<uhd::TX_DIRECTION>(this_chan, _tx_channel_map, mboard, mb_chan); + chan_to_mcp<uhd::TX_DIRECTION>( + this_chan, _tx_channel_map, mboard, mb_chan); const size_t dsp_index = _tx_channel_map[mboard][mb_chan].radio_index; const size_t port_index = _tx_channel_map[mboard][mb_chan].port_index; - _tree->access<double>(tx_dsp_root(mboard, dsp_index, port_index) / "rate/value") - .set(rate) - ; + _tree + ->access<double>( + tx_dsp_root(mboard, dsp_index, port_index) / "rate/value") + .set(rate); } } // Update streamers: - boost::dynamic_pointer_cast<uhd::usrp::device3_impl>(_device)->update_tx_streamers(rate); + boost::dynamic_pointer_cast<uhd::usrp::device3_impl>(_device) + ->update_tx_streamers(rate); } private: // types - struct radio_port_pair_t { - radio_port_pair_t(const size_t radio=0, const size_t port=0) : radio_index(radio), port_index(port) {} + struct radio_port_pair_t + { + radio_port_pair_t(const size_t radio = 0, const size_t port = 0) + : radio_index(radio), port_index(port) + { + } size_t radio_index; size_t port_index; }; //! Map: _rx_channel_map[mboard_idx][chan_idx] => (Radio, Port) // Container is not a std::map because we need to guarantee contiguous // ports and correct order anyway. - typedef std::vector< std::vector<radio_port_pair_t> > chan_map_t; + typedef std::vector<std::vector<radio_port_pair_t>> chan_map_t; private: // methods /************************************************************************ @@ -451,71 +481,70 @@ private: // methods ***********************************************************************/ std::string get_slot_name(const size_t radio_index) { - if (radio_index == 0){ + if (radio_index == 0) { return "A"; - }else if (radio_index == 1){ + } else if (radio_index == 1) { return "B"; - }else if (radio_index == 2){ + } else if (radio_index == 2) { return "C"; - }else if (radio_index == 3){ + } else if (radio_index == 3) { return "D"; - }else{ + } else { throw uhd::index_error(str( boost::format("[legacy_compat]: radio index %u out of supported range.") - % radio_index - )); + % radio_index)); } } size_t get_radio_index(const std::string slot_name) { - if (slot_name == "A"){ + if (slot_name == "A") { return 0; - }else if (slot_name == "B"){ + } else if (slot_name == "B") { return 1; - }else if (slot_name == "C"){ + } else if (slot_name == "C") { return 2; - }else if (slot_name == "D"){ - return 3; - }else { - throw uhd::key_error(str( - boost::format("[legacy_compat]: radio slot name %s out of supported range.") - % slot_name - )); + } else if (slot_name == "D") { + return 3; + } else { + throw uhd::key_error( + str(boost::format( + "[legacy_compat]: radio slot name %s out of supported range.") + % slot_name)); } } template <typename block_type> - inline typename block_type::sptr get_block_ctrl(const size_t mboard_idx, const std::string &name, const size_t block_count) + inline typename block_type::sptr get_block_ctrl( + const size_t mboard_idx, const std::string& name, const size_t block_count) { block_id_t block_id(mboard_idx, name, block_count); return _device->get_block_ctrl<block_type>(block_id); } template <uhd::direction_t dir> - inline void chan_to_mcp( - const size_t chan, const chan_map_t &chan_map, - size_t &mboard_idx, size_t &mb_chan_idx - ) { - mboard_idx = 0; + inline void chan_to_mcp(const size_t chan, + const chan_map_t& chan_map, + size_t& mboard_idx, + size_t& mb_chan_idx) + { + mboard_idx = 0; mb_chan_idx = chan; while (mb_chan_idx >= chan_map[mboard_idx].size()) { - mb_chan_idx -= chan_map[mboard_idx++].size(); + mb_chan_idx -= chan_map[mboard_idx++].size(); } if (mboard_idx >= chan_map.size()) { - throw uhd::index_error(str( - boost::format("[legacy_compat]: %s channel %u out of range for given frontend configuration.") - % (dir == uhd::TX_DIRECTION ? "TX" : "RX") - % chan - )); + throw uhd::index_error( + str(boost::format("[legacy_compat]: %s channel %u out of range for given " + "frontend configuration.") + % (dir == uhd::TX_DIRECTION ? "TX" : "RX") % chan)); } } template <uhd::direction_t dir> void _update_stream_args_for_streaming( - uhd::stream_args_t &args, - const chan_map_t &chan_map - ) { + uhd::stream_args_t& args, const chan_map_t& chan_map) + { // If the user provides spp, that value is always applied. If it's // different from what we thought it was, we need to update the blocks. // If it's not provided, we provide our own spp value. @@ -528,17 +557,20 @@ private: // methods } else { for (size_t mboard = 0; mboard < _num_mboards; mboard++) { for (size_t radio = 0; radio < _num_radios_per_board; radio++) { - const size_t this_spp = get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio)->get_arg<int>("spp"); + const size_t this_spp = + get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio) + ->get_arg<int>("spp"); target_spp = std::min(this_spp, target_spp); } } } for (size_t mboard = 0; mboard < _num_mboards; mboard++) { for (size_t radio = 0; radio < _num_radios_per_board; radio++) { - get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio)->set_arg<int>("spp", target_spp); + get_block_ctrl<radio_ctrl>(mboard, RADIO_BLOCK_NAME, radio) + ->set_arg<int>("spp", target_spp); } } - _rx_spp = target_spp; + _rx_spp = target_spp; args.args["spp"] = str(boost::format("%d") % _rx_spp); } else { if (args.args.has_key("spp") and args_spp != _tx_spp) { @@ -556,81 +588,107 @@ private: // methods const size_t stream_arg_chan_idx = args.channels[i]; // Determine which mboard, and on that mboard, which channel this is: size_t mboard_idx, this_mboard_chan_idx; - chan_to_mcp<dir>(stream_arg_chan_idx, chan_map, mboard_idx, this_mboard_chan_idx); + chan_to_mcp<dir>( + stream_arg_chan_idx, chan_map, mboard_idx, this_mboard_chan_idx); // Map that mboard and channel to a block: - const size_t radio_index = chan_map[mboard_idx][this_mboard_chan_idx].radio_index; + const size_t radio_index = + chan_map[mboard_idx][this_mboard_chan_idx].radio_index; size_t port_index = chan_map[mboard_idx][this_mboard_chan_idx].port_index; - auto block_and_port = _get_streamer_block_id_and_port<dir>(mboard_idx, radio_index, port_index); + auto block_and_port = + _get_streamer_block_id_and_port<dir>(mboard_idx, radio_index, port_index); auto block_name = block_and_port.first.to_string(); - port_index = block_and_port.second; - args.args[str(boost::format("block_id%d") % stream_arg_chan_idx)] = block_name; - args.args[str(boost::format("block_port%d") % stream_arg_chan_idx)] = str(boost::format("%d") % port_index); + port_index = block_and_port.second; + args.args[str(boost::format("block_id%d") % stream_arg_chan_idx)] = + block_name; + args.args[str(boost::format("block_port%d") % stream_arg_chan_idx)] = + str(boost::format("%d") % port_index); // Map radio to channel (for in-band response) - args.args[str(boost::format("radio_id%d") % stream_arg_chan_idx)] = block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(); - args.args[str(boost::format("radio_port%d") % stream_arg_chan_idx)] = str(boost::format("%d") % chan_map[mboard_idx][this_mboard_chan_idx].port_index); + args.args[str(boost::format("radio_id%d") % stream_arg_chan_idx)] = + block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(); + args.args[str(boost::format("radio_port%d") % stream_arg_chan_idx)] = + str(boost::format("%d") + % chan_map[mboard_idx][this_mboard_chan_idx].port_index); } } //! Given mboard_index(m), radio_index(r), and port_index(p), - // this function returns the index of a block on the input block list that match m,r,p + // this function returns the index of a block on the input block list that match + // m,r,p template <typename T> - size_t find_block(const std::vector<T> &port_list, const size_t &m, const size_t &r, const size_t &p) + size_t find_block(const std::vector<T>& port_list, + const size_t& m, + const size_t& r, + const size_t& p) { - size_t index = 0; - for (auto port : port_list) - { + size_t index = 0; + for (auto port : port_list) { auto block_id = (port.first)->get_block_id(); - if (p == port.second && r == block_id.get_block_count() && m == block_id.get_device_no()) - { + if (p == port.second && r == block_id.get_block_count() + && m == block_id.get_device_no()) { return index; } index++; } - throw uhd::runtime_error((boost::format("Could not find block in list for device %d, radio %d, and port %d") % m % r % p).str()); + throw uhd::runtime_error( + (boost::format( + "Could not find block in list for device %d, radio %d, and port %d") + % m % r % p) + .str()); } template <uhd::direction_t dir> std::pair<block_id_t, size_t> _get_streamer_block_id_and_port( - const size_t &mboard_idx, - const size_t &radio_index, - const size_t &port_index) + const size_t& mboard_idx, const size_t& radio_index, const size_t& port_index) { block_name_to_block_map_t legacy_block_map = get_legacy_blocks(_device); - if (dir == uhd::TX_DIRECTION){ - auto radio_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].second); - size_t index_snk = find_block<sink_port_t>(radio_snk_flat, mboard_idx, radio_index, port_index); - if (_has_sramfifo){ - auto sfifo_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[SFIFO_BLOCK_NAME].second); + if (dir == uhd::TX_DIRECTION) { + auto radio_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].second); + size_t index_snk = find_block<sink_port_t>( + radio_snk_flat, mboard_idx, radio_index, port_index); + if (_has_sramfifo) { + auto sfifo_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[SFIFO_BLOCK_NAME].second); UHD_ASSERT_THROW(index_snk < sfifo_snk_flat.size()); auto sfifo_block = sfifo_snk_flat[index_snk].first->get_block_id(); return std::make_pair(sfifo_block, sfifo_snk_flat[index_snk].second); - }else if (_has_dmafifo){ - auto dfifo_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[DFIFO_BLOCK_NAME].second); + } else if (_has_dmafifo) { + auto dfifo_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DFIFO_BLOCK_NAME].second); UHD_ASSERT_THROW(index_snk < dfifo_snk_flat.size()); auto dfifo_block = dfifo_snk_flat[index_snk].first->get_block_id(); return std::make_pair(dfifo_block, dfifo_snk_flat[index_snk].second); - }else{ - if (_has_ducs){ - return std::make_pair(block_id_t(mboard_idx, DUC_BLOCK_NAME, radio_index).to_string(),port_index); - auto duc_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[DUC_BLOCK_NAME].second); + } else { + if (_has_ducs) { + return std::make_pair( + block_id_t(mboard_idx, DUC_BLOCK_NAME, radio_index).to_string(), + port_index); + auto duc_snk_flat = _flatten_blocks_by_n_ports( + legacy_block_map[DUC_BLOCK_NAME].second); UHD_ASSERT_THROW(index_snk < duc_snk_flat.size()); auto duc_block = duc_snk_flat[index_snk].first->get_block_id(); return std::make_pair(duc_block, duc_snk_flat[index_snk].second); - }else{ - return std::make_pair(block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(),port_index); + } else { + return std::make_pair( + block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(), + port_index); } } - }else{ - auto radio_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].first); - size_t index_src = find_block<source_port_t>(radio_src_flat, mboard_idx, radio_index, port_index); - if (_has_ddcs){ - auto ddc_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[DDC_BLOCK_NAME].first); + } else { + auto radio_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].first); + size_t index_src = find_block<source_port_t>( + radio_src_flat, mboard_idx, radio_index, port_index); + if (_has_ddcs) { + auto ddc_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DDC_BLOCK_NAME].first); UHD_ASSERT_THROW(index_src < ddc_src_flat.size()); auto ddc_block = ddc_src_flat[index_src].first->get_block_id(); return std::make_pair(ddc_block, ddc_src_flat[index_src].second); - } - else{ - return std::make_pair(block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(),port_index); + } else { + return std::make_pair( + block_id_t(mboard_idx, RADIO_BLOCK_NAME, radio_index).to_string(), + port_index); } } } @@ -649,7 +707,8 @@ private: // methods void check_available_periphs() { if (_num_radios_per_board == 0) { - throw uhd::runtime_error("For legacy APIs, all devices require at least one radio."); + throw uhd::runtime_error( + "For legacy APIs, all devices require at least one radio."); } block_id_t radio_block_id(0, RADIO_BLOCK_NAME); block_id_t duc_block_id(0, DUC_BLOCK_NAME); @@ -668,17 +727,20 @@ private: // methods if (not _device->has_block(radio_block_id) or (_has_ducs and not _device->has_block(duc_block_id)) or (_has_ddcs and not _device->has_block(ddc_block_id)) - or (_has_dmafifo and not _device->has_block(fifo_block_id)) - ) { - throw uhd::runtime_error("For legacy APIs, all devices require the same number of radios, DDCs and DUCs."); + or (_has_dmafifo and not _device->has_block(fifo_block_id))) { + throw uhd::runtime_error("For legacy APIs, all devices require the " + "same number of radios, DDCs and DUCs."); } - const size_t this_spp = get_block_ctrl<radio_ctrl>(i, RADIO_BLOCK_NAME, k)->get_arg<int>("spp"); + const size_t this_spp = get_block_ctrl<radio_ctrl>(i, RADIO_BLOCK_NAME, k) + ->get_arg<int>("spp"); if (this_spp != _rx_spp) { UHD_LOGGER_WARNING("RFNOC") << str( - boost::format("[legacy compat] Radios have differing spp values: %s has %d, others have %d. UHD will use smaller spp value for all connections. Performance might be not optimal.") - % radio_block_id.to_string() % this_spp % _rx_spp - ); + boost::format( + "[legacy compat] Radios have differing spp values: %s has " + "%d, others have %d. UHD will use smaller spp value for all " + "connections. Performance might be not optimal.") + % radio_block_id.to_string() % this_spp % _rx_spp); } } } @@ -693,89 +755,111 @@ private: // methods // Subdev specs if (_tree->exists(root / "tx_subdev_spec")) { _tree->access<subdev_spec_t>(root / "tx_subdev_spec") - .add_coerced_subscriber(boost::bind(&legacy_compat_impl::set_subdev_spec, this, _1, mboard_idx, uhd::TX_DIRECTION)) + .add_coerced_subscriber( + boost::bind(&legacy_compat_impl::set_subdev_spec, + this, + _1, + mboard_idx, + uhd::TX_DIRECTION)) .update() - .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, this, mboard_idx, uhd::TX_DIRECTION)); + .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, + this, + mboard_idx, + uhd::TX_DIRECTION)); } else { _tree->create<subdev_spec_t>(root / "tx_subdev_spec") - .add_coerced_subscriber(boost::bind(&legacy_compat_impl::set_subdev_spec, this, _1, mboard_idx, uhd::TX_DIRECTION)) - .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, this, mboard_idx, uhd::TX_DIRECTION)); + .add_coerced_subscriber( + boost::bind(&legacy_compat_impl::set_subdev_spec, + this, + _1, + mboard_idx, + uhd::TX_DIRECTION)) + .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, + this, + mboard_idx, + uhd::TX_DIRECTION)); } if (_tree->exists(root / "rx_subdev_spec")) { _tree->access<subdev_spec_t>(root / "rx_subdev_spec") - .add_coerced_subscriber(boost::bind(&legacy_compat_impl::set_subdev_spec, this, _1, mboard_idx, uhd::RX_DIRECTION)) + .add_coerced_subscriber( + boost::bind(&legacy_compat_impl::set_subdev_spec, + this, + _1, + mboard_idx, + uhd::RX_DIRECTION)) .update() - .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, this, mboard_idx, uhd::RX_DIRECTION)); + .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, + this, + mboard_idx, + uhd::RX_DIRECTION)); } else { - _tree->create<subdev_spec_t>(root / "rx_subdev_spec") - .add_coerced_subscriber(boost::bind(&legacy_compat_impl::set_subdev_spec, this, _1, mboard_idx, uhd::RX_DIRECTION)) - .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, this, mboard_idx, uhd::RX_DIRECTION)); + _tree->create<subdev_spec_t>(root / "rx_subdev_spec") + .add_coerced_subscriber( + boost::bind(&legacy_compat_impl::set_subdev_spec, + this, + _1, + mboard_idx, + uhd::RX_DIRECTION)) + .set_publisher(boost::bind(&legacy_compat_impl::get_subdev_spec, + this, + mboard_idx, + uhd::RX_DIRECTION)); } if (not _has_ddcs) { - for (size_t radio_idx = 0; radio_idx < _num_radios_per_board; radio_idx++) { + for (size_t radio_idx = 0; radio_idx < _num_radios_per_board; + radio_idx++) { for (size_t chan = 0; chan < _num_rx_chans_per_radio; chan++) { - const uhd::fs_path rx_dsp_base_path(mb_root(mboard_idx) / "rx_dsps" / radio_idx / chan); + const uhd::fs_path rx_dsp_base_path( + mb_root(mboard_idx) / "rx_dsps" / radio_idx / chan); _tree->create<double>(rx_dsp_base_path / "rate/value") .set(0.0) - .set_publisher( - boost::bind( - &radio_ctrl::get_output_samp_rate, - get_block_ctrl<radio_ctrl>(mboard_idx, RADIO_BLOCK_NAME, radio_idx), - chan - ) - ) - ; + .set_publisher(boost::bind(&radio_ctrl::get_output_samp_rate, + get_block_ctrl<radio_ctrl>( + mboard_idx, RADIO_BLOCK_NAME, radio_idx), + chan)); _tree->create<uhd::meta_range_t>(rx_dsp_base_path / "rate/range") - .set_publisher( - boost::bind( - &legacy_compat_impl::lambda_get_samp_rate_range, - this, - mboard_idx, radio_idx, chan, - uhd::RX_DIRECTION - ) - ) - ; + .set_publisher(boost::bind( + &legacy_compat_impl::lambda_get_samp_rate_range, + this, + mboard_idx, + radio_idx, + chan, + uhd::RX_DIRECTION)); _tree->create<double>(rx_dsp_base_path / "freq/value") - .set_publisher([](){ return 0.0; }) - ; + .set_publisher([]() { return 0.0; }); _tree->create<uhd::meta_range_t>(rx_dsp_base_path / "freq/range") - .set_publisher([](){ return uhd::meta_range_t(0.0, 0.0, 0.0); }) - ; + .set_publisher( + []() { return uhd::meta_range_t(0.0, 0.0, 0.0); }); } } } /* if not _has_ddcs */ if (not _has_ducs) { - for (size_t radio_idx = 0; radio_idx < _num_radios_per_board; radio_idx++) { + for (size_t radio_idx = 0; radio_idx < _num_radios_per_board; + radio_idx++) { for (size_t chan = 0; chan < _num_tx_chans_per_radio; chan++) { - const uhd::fs_path tx_dsp_base_path(mb_root(mboard_idx) / "tx_dsps" / radio_idx / chan); + const uhd::fs_path tx_dsp_base_path( + mb_root(mboard_idx) / "tx_dsps" / radio_idx / chan); _tree->create<double>(tx_dsp_base_path / "rate/value") .set(0.0) - .set_publisher( - boost::bind( - &radio_ctrl::get_output_samp_rate, - get_block_ctrl<radio_ctrl>(mboard_idx, RADIO_BLOCK_NAME, radio_idx), - chan - ) - ) - ; + .set_publisher(boost::bind(&radio_ctrl::get_output_samp_rate, + get_block_ctrl<radio_ctrl>( + mboard_idx, RADIO_BLOCK_NAME, radio_idx), + chan)); _tree->create<uhd::meta_range_t>(tx_dsp_base_path / "rate/range") - .set_publisher( - boost::bind( - &legacy_compat_impl::lambda_get_samp_rate_range, - this, - mboard_idx, radio_idx, chan, - uhd::TX_DIRECTION - ) - ) - ; + .set_publisher(boost::bind( + &legacy_compat_impl::lambda_get_samp_rate_range, + this, + mboard_idx, + radio_idx, + chan, + uhd::TX_DIRECTION)); _tree->create<double>(tx_dsp_base_path / "freq/value") - .set_publisher([](){ return 0.0; }) - ; + .set_publisher([]() { return 0.0; }); _tree->create<uhd::meta_range_t>(tx_dsp_base_path / "freq/range") - .set_publisher([](){ return uhd::meta_range_t(0.0, 0.0, 0.0); }) - ; + .set_publisher( + []() { return uhd::meta_range_t(0.0, 0.0, 0.0); }); } } } /* if not _has_ducs */ @@ -791,11 +875,11 @@ private: // methods uhd::fs_path root = mb_root(mboard_idx); // Subdev specs if (_tree->exists(root / "tx_subdev_spec")) { - recreate_property<subdev_spec_t>(root / "tx_subdev_spec", _tree); + recreate_property<subdev_spec_t>(root / "tx_subdev_spec", _tree); } if (_tree->exists(root / "rx_subdev_spec")) { - recreate_property<subdev_spec_t>(root / "rx_subdev_spec", _tree); + recreate_property<subdev_spec_t>(root / "rx_subdev_spec", _tree); } } } @@ -805,24 +889,22 @@ private: // methods std::vector<source_port_t> _flatten_blocks_by_n_ports(source_block_list_t block_list) { std::vector<source_port_t> result; - for (auto block: block_list ){ - for(auto port: block->get_output_ports()){ - - result.push_back(std::make_pair(block,port)); + for (auto block : block_list) { + for (auto port : block->get_output_ports()) { + result.push_back(std::make_pair(block, port)); } } - //assign to block prior ports + // assign to block prior ports size_t port = 0; - size_t i = 0; - for (size_t j=0; j<result.size(); j++){ - auto block = block_list[j%block_list.size()]; + size_t i = 0; + for (size_t j = 0; j < result.size(); j++) { + auto block = block_list[j % block_list.size()]; UHD_ASSERT_THROW(port < block->get_output_ports().size()); - if (i == block_list.size()) - { + if (i == block_list.size()) { i = 0; - port ++; + port++; } - result[j] = std::make_pair(block,port); + result[j] = std::make_pair(block, port); i++; } return result; @@ -834,23 +916,22 @@ private: // methods std::vector<sink_port_t> _flatten_blocks_by_n_ports(sink_block_list_t block_list) { std::vector<sink_port_t> result; - for (auto block: block_list ){ - for(auto port: block->get_input_ports()){ - result.push_back(std::make_pair(block,port)); + for (auto block : block_list) { + for (auto port : block->get_input_ports()) { + result.push_back(std::make_pair(block, port)); } } - //assign to block prior ports + // assign to block prior ports size_t port = 0; - size_t i = 0; - for (size_t j=0; j<result.size(); j++){ - auto block = block_list[j%block_list.size()]; + size_t i = 0; + for (size_t j = 0; j < result.size(); j++) { + auto block = block_list[j % block_list.size()]; UHD_ASSERT_THROW(port < block->get_input_ports().size()); - if (i == block_list.size()) - { + if (i == block_list.size()) { i = 0; - port ++; + port++; } - result[j] = std::make_pair(block,port); + result[j] = std::make_pair(block, port); i++; } return result; @@ -872,34 +953,41 @@ private: // methods */ void connect_blocks() { - _graph = _device->create_graph("legacy"); + _graph = _device->create_graph("legacy"); const size_t rx_bpp = _rx_spp * BYTES_PER_SAMPLE + MAX_BYTES_PER_HEADER; const size_t tx_bpp = _tx_spp * BYTES_PER_SAMPLE + MAX_BYTES_PER_HEADER; - block_name_to_block_map_t legacy_block_map = get_legacy_blocks(_device); + block_name_to_block_map_t legacy_block_map = get_legacy_blocks(_device); size_t index = 0, sram_fifo_index = 0, dma_fifo_index = 0; - auto ddc_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[DDC_BLOCK_NAME].second); - auto duc_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[DUC_BLOCK_NAME].first); - auto duc_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[DUC_BLOCK_NAME].second); - auto radio_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].first); - auto radio_snk_flat = _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].second); - auto sfifo_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[SFIFO_BLOCK_NAME].first); - auto dfifo_src_flat = _flatten_blocks_by_n_ports(legacy_block_map[DFIFO_BLOCK_NAME].first); - for(auto each_src_radio_block:radio_src_flat){ + auto ddc_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DDC_BLOCK_NAME].second); + auto duc_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DUC_BLOCK_NAME].first); + auto duc_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DUC_BLOCK_NAME].second); + auto radio_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].first); + auto radio_snk_flat = + _flatten_blocks_by_n_ports(legacy_block_map[RADIO_BLOCK_NAME].second); + auto sfifo_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[SFIFO_BLOCK_NAME].first); + auto dfifo_src_flat = + _flatten_blocks_by_n_ports(legacy_block_map[DFIFO_BLOCK_NAME].first); + for (auto each_src_radio_block : radio_src_flat) { auto radio_block = each_src_radio_block.first->get_block_id(); if (_has_ddcs) { UHD_ASSERT_THROW(index < ddc_snk_flat.size()); auto ddc_block = ddc_snk_flat[index].first->get_block_id(); - _graph->connect( - radio_block, each_src_radio_block.second, - ddc_block, ddc_snk_flat[index].second, - rx_bpp - ); + _graph->connect(radio_block, + each_src_radio_block.second, + ddc_block, + ddc_snk_flat[index].second, + rx_bpp); } index++; } index = 0; - for(auto each_snk_radio_block:radio_snk_flat){ - auto radio_block = each_snk_radio_block.first->get_block_id(); + for (auto each_snk_radio_block : radio_snk_flat) { + auto radio_block = each_snk_radio_block.first->get_block_id(); auto down_stream_block = radio_block; auto down_stream_port = each_snk_radio_block.second; if (_has_ducs) { @@ -907,36 +995,41 @@ private: // methods UHD_ASSERT_THROW(index < duc_src_flat.size()); auto duc_snk_block = duc_snk_flat[index].first->get_block_id(); auto duc_src_block = duc_src_flat[index].first->get_block_id(); - _graph->connect( - duc_src_block, duc_src_flat[index].second, - radio_block, each_snk_radio_block.second, + _graph->connect(duc_src_block, + duc_src_flat[index].second, + radio_block, + each_snk_radio_block.second, rx_bpp); down_stream_block = duc_snk_block; - down_stream_port = duc_snk_flat[index].second; + down_stream_port = duc_snk_flat[index].second; } if (_has_sramfifo) { - if(sram_fifo_index < sfifo_src_flat.size()){ - auto sfifo_block = sfifo_src_flat[sram_fifo_index].first->get_block_id(); - _graph->connect( - sfifo_block, sfifo_src_flat[sram_fifo_index].second, - down_stream_block, down_stream_port, - tx_bpp - ); + if (sram_fifo_index < sfifo_src_flat.size()) { + auto sfifo_block = + sfifo_src_flat[sram_fifo_index].first->get_block_id(); + _graph->connect(sfifo_block, + sfifo_src_flat[sram_fifo_index].second, + down_stream_block, + down_stream_port, + tx_bpp); sram_fifo_index++; - }else { - UHD_LOGGER_WARNING("RFNOC") << "[legacy compat] Running out of SRAM FIFO ports to connect."; + } else { + UHD_LOGGER_WARNING("RFNOC") + << "[legacy compat] Running out of SRAM FIFO ports to connect."; } - }else if (_has_dmafifo) { - if(dma_fifo_index < dfifo_src_flat.size()){ - auto dfifo_block = dfifo_src_flat[dma_fifo_index].first->get_block_id(); - _graph->connect( - dfifo_block, dfifo_src_flat[dma_fifo_index].second, - down_stream_block, down_stream_port, - tx_bpp - ); + } else if (_has_dmafifo) { + if (dma_fifo_index < dfifo_src_flat.size()) { + auto dfifo_block = + dfifo_src_flat[dma_fifo_index].first->get_block_id(); + _graph->connect(dfifo_block, + dfifo_src_flat[dma_fifo_index].second, + down_stream_block, + down_stream_port, + tx_bpp); dma_fifo_index++; - }else { - UHD_LOGGER_WARNING("RFNOC") << "[legacy compat] Running out of DRAM FIFO ports to connect."; + } else { + UHD_LOGGER_WARNING("RFNOC") + << "[legacy compat] Running out of DRAM FIFO ports to connect."; } } index++; @@ -953,18 +1046,25 @@ private: // methods * Then we map to ((0, 0), (1, 0)). I.e., zero-th port on radio 0 and * radio 1, respectively. */ - void set_subdev_spec(const subdev_spec_t &spec, const size_t mboard, const uhd::direction_t dir) + void set_subdev_spec( + const subdev_spec_t& spec, const size_t mboard, const uhd::direction_t dir) { UHD_ASSERT_THROW(mboard < _num_mboards); - chan_map_t &chan_map = (dir == uhd::TX_DIRECTION) ? _tx_channel_map : _rx_channel_map; + chan_map_t& chan_map = (dir == uhd::TX_DIRECTION) ? _tx_channel_map + : _rx_channel_map; std::vector<radio_port_pair_t> new_mapping(spec.size()); for (size_t i = 0; i < spec.size(); i++) { const size_t new_radio_index = get_radio_index(spec[i].db_name); - radio_ctrl::sptr radio = get_block_ctrl<radio_ctrl>(mboard, "Radio", new_radio_index); + radio_ctrl::sptr radio = + get_block_ctrl<radio_ctrl>(mboard, "Radio", new_radio_index); size_t new_port_index = radio->get_chan_from_dboard_fe(spec[i].sd_name, dir); - auto port_size = (dir == uhd::TX_DIRECTION) ? radio->get_input_ports().size() :radio->get_output_ports().size(); - auto default_index = (dir == uhd::TX_DIRECTION)? radio->get_input_ports().at(0) : radio->get_output_ports().at(0); + auto port_size = (dir == uhd::TX_DIRECTION) + ? radio->get_input_ports().size() + : radio->get_output_ports().size(); + auto default_index = (dir == uhd::TX_DIRECTION) + ? radio->get_input_ports().at(0) + : radio->get_output_ports().at(0); if (new_port_index >= port_size) { new_port_index = default_index; } @@ -979,13 +1079,15 @@ private: // methods { UHD_ASSERT_THROW(mboard < _num_mboards); subdev_spec_t subdev_spec; - chan_map_t &chan_map = (dir == uhd::TX_DIRECTION) ? _tx_channel_map : _rx_channel_map; + chan_map_t& chan_map = (dir == uhd::TX_DIRECTION) ? _tx_channel_map + : _rx_channel_map; for (size_t chan_idx = 0; chan_idx < chan_map[mboard].size(); chan_idx++) { - const size_t radio_index = chan_map[mboard][chan_idx].radio_index; - const size_t port_index = chan_map[mboard][chan_idx].port_index; + const size_t radio_index = chan_map[mboard][chan_idx].radio_index; + const size_t port_index = chan_map[mboard][chan_idx].port_index; const std::string new_db_name = get_slot_name(radio_index); const std::string new_sd_name = - get_block_ctrl<radio_ctrl>(mboard, "Radio", radio_index)->get_dboard_fe_from_chan(port_index, dir); + get_block_ctrl<radio_ctrl>(mboard, "Radio", radio_index) + ->get_dboard_fe_from_chan(port_index, dir); subdev_spec_pair_t new_pair(new_db_name, new_sd_name); subdev_spec.push_back(new_pair); } @@ -1003,15 +1105,18 @@ private: // methods radio_block_id.set_block_count(radio); duc_block_id.set_block_count(radio); ddc_block_id.set_block_count(radio); - radio_ctrl::sptr radio_sptr = _device->get_block_ctrl<radio_ctrl>(radio_block_id); + radio_ctrl::sptr radio_sptr = + _device->get_block_ctrl<radio_ctrl>(radio_block_id); radio_sptr->set_rate(tick_rate); for (size_t chan = 0; chan < _num_rx_chans_per_radio and _has_ddcs; chan++) { const double radio_output_rate = radio_sptr->get_output_samp_rate(chan); - _device->get_block_ctrl(ddc_block_id)->set_arg<double>("input_rate", radio_output_rate, chan); + _device->get_block_ctrl(ddc_block_id) + ->set_arg<double>("input_rate", radio_output_rate, chan); } for (size_t chan = 0; chan < _num_tx_chans_per_radio and _has_ducs; chan++) { const double radio_input_rate = radio_sptr->get_input_samp_rate(chan); - _device->get_block_ctrl(duc_block_id)->set_arg<double>("output_rate", radio_input_rate, chan); + _device->get_block_ctrl(duc_block_id) + ->set_arg<double>("output_rate", radio_input_rate, chan); } } } @@ -1036,31 +1141,32 @@ private: // attributes //! Stores a weak pointer for every streamer that's generated through this API. // Key is the channel number (same format as e.g. the set_rx_rate() call). - typedef std::map< size_t, boost::weak_ptr<uhd::rx_streamer> > rx_stream_map_type; + typedef std::map<size_t, boost::weak_ptr<uhd::rx_streamer>> rx_stream_map_type; rx_stream_map_type _rx_stream_cache; - typedef std::map< size_t, boost::weak_ptr<uhd::tx_streamer> > tx_stream_map_type; + typedef std::map<size_t, boost::weak_ptr<uhd::tx_streamer>> tx_stream_map_type; tx_stream_map_type _tx_stream_cache; graph::sptr _graph; }; legacy_compat::sptr legacy_compat::make( - uhd::device3::sptr device, - const uhd::device_addr_t &args -) { + uhd::device3::sptr device, const uhd::device_addr_t& args) +{ boost::lock_guard<boost::mutex> lock(_make_mutex); UHD_ASSERT_THROW(bool(device)); - static std::map<void *, boost::weak_ptr<legacy_compat> > legacy_cache; + static std::map<void*, boost::weak_ptr<legacy_compat>> legacy_cache; - if (legacy_cache.count(device.get()) and not legacy_cache.at(device.get()).expired()) { + if (legacy_cache.count(device.get()) + and not legacy_cache.at(device.get()).expired()) { legacy_compat::sptr legacy_compat_copy = legacy_cache.at(device.get()).lock(); UHD_ASSERT_THROW(bool(legacy_compat_copy)); - UHD_LEGACY_LOG() << "[legacy_compat] Using existing legacy compat object for this device." ; + UHD_LEGACY_LOG() + << "[legacy_compat] Using existing legacy compat object for this device."; return legacy_compat_copy; } - legacy_compat::sptr new_legacy_compat = boost::make_shared<legacy_compat_impl>(device, args); + legacy_compat::sptr new_legacy_compat = + boost::make_shared<legacy_compat_impl>(device, args); legacy_cache[device.get()] = new_legacy_compat; return new_legacy_compat; } - diff --git a/host/lib/rfnoc/node_ctrl_base.cpp b/host/lib/rfnoc/node_ctrl_base.cpp index 46a804ab9..a6ee80f8b 100644 --- a/host/lib/rfnoc/node_ctrl_base.cpp +++ b/host/lib/rfnoc/node_ctrl_base.cpp @@ -26,68 +26,59 @@ void node_ctrl_base::clear() _downstream_nodes.clear(); } -void node_ctrl_base::_register_downstream_node( - node_ctrl_base::sptr, - size_t -) { - throw uhd::runtime_error("Attempting to register a downstream block on a non-source node."); +void node_ctrl_base::_register_downstream_node(node_ctrl_base::sptr, size_t) +{ + throw uhd::runtime_error( + "Attempting to register a downstream block on a non-source node."); } -void node_ctrl_base::_register_upstream_node( - node_ctrl_base::sptr, - size_t -) { - throw uhd::runtime_error("Attempting to register an upstream block on a non-sink node."); +void node_ctrl_base::_register_upstream_node(node_ctrl_base::sptr, size_t) +{ + throw uhd::runtime_error( + "Attempting to register an upstream block on a non-sink node."); } -void node_ctrl_base::set_downstream_port( - const size_t this_port, - const size_t remote_port -) { +void node_ctrl_base::set_downstream_port(const size_t this_port, const size_t remote_port) +{ if (not _downstream_nodes.count(this_port) and remote_port != ANY_PORT) { - throw uhd::value_error(str( - boost::format("[%s] Cannot set remote downstream port: Port %d not connected.") - % unique_id() % this_port - )); + throw uhd::value_error( + str(boost::format( + "[%s] Cannot set remote downstream port: Port %d not connected.") + % unique_id() % this_port)); } _downstream_ports[this_port] = remote_port; } size_t node_ctrl_base::get_downstream_port(const size_t this_port) { - if (not _downstream_ports.count(this_port) - or not _downstream_nodes.count(this_port) + if (not _downstream_ports.count(this_port) or not _downstream_nodes.count(this_port) or _downstream_ports[this_port] == ANY_PORT) { - throw uhd::value_error(str( - boost::format("[%s] Cannot retrieve remote downstream port: Port %d not connected.") - % unique_id() % this_port - )); + throw uhd::value_error( + str(boost::format( + "[%s] Cannot retrieve remote downstream port: Port %d not connected.") + % unique_id() % this_port)); } return _downstream_ports[this_port]; } -void node_ctrl_base::set_upstream_port( - const size_t this_port, - const size_t remote_port -) { +void node_ctrl_base::set_upstream_port(const size_t this_port, const size_t remote_port) +{ if (not _upstream_nodes.count(this_port) and remote_port != ANY_PORT) { throw uhd::value_error(str( boost::format("[%s] Cannot set remote upstream port: Port %d not connected.") - % unique_id() % this_port - )); + % unique_id() % this_port)); } _upstream_ports[this_port] = remote_port; } size_t node_ctrl_base::get_upstream_port(const size_t this_port) { - if (not _upstream_ports.count(this_port) - or not _upstream_nodes.count(this_port) + if (not _upstream_ports.count(this_port) or not _upstream_nodes.count(this_port) or _upstream_ports[this_port] == ANY_PORT) { - throw uhd::value_error(str( - boost::format("[%s] Cannot retrieve remote upstream port: Port %d not connected.") - % unique_id() % this_port - )); + throw uhd::value_error( + str(boost::format( + "[%s] Cannot retrieve remote upstream port: Port %d not connected.") + % unique_id() % this_port)); } return _upstream_ports[this_port]; } @@ -95,7 +86,8 @@ size_t node_ctrl_base::get_upstream_port(const size_t this_port) void node_ctrl_base::disconnect() { // Notify neighbours: - for (node_map_t::iterator i = _downstream_nodes.begin(); i != _downstream_nodes.end(); ++i) { + for (node_map_t::iterator i = _downstream_nodes.begin(); i != _downstream_nodes.end(); + ++i) { sptr downstream_node = i->second.lock(); if (not downstream_node) { // Actually this is not OK @@ -103,7 +95,8 @@ void node_ctrl_base::disconnect() } downstream_node->disconnect_input_port(_downstream_ports[i->first]); } - for (node_map_t::iterator i = _upstream_nodes.begin(); i != _upstream_nodes.end(); ++i) { + for (node_map_t::iterator i = _upstream_nodes.begin(); i != _upstream_nodes.end(); + ++i) { sptr upstream_node = i->second.lock(); if (not upstream_node) { // Actually this is not OK @@ -120,9 +113,12 @@ void node_ctrl_base::disconnect() void node_ctrl_base::disconnect_output_port(const size_t output_port) { - if (_downstream_nodes.count(output_port) == 0 or - _downstream_ports.count(output_port) == 0) { - throw uhd::assertion_error(str(boost::format("[%s] Attempting to disconnect output port %u, which is not registered as connected!") % unique_id() % output_port)); + if (_downstream_nodes.count(output_port) == 0 + or _downstream_ports.count(output_port) == 0) { + throw uhd::assertion_error( + str(boost::format("[%s] Attempting to disconnect output port %u, which is " + "not registered as connected!") + % unique_id() % output_port)); } _downstream_nodes.erase(output_port); _downstream_ports.erase(output_port); @@ -130,11 +126,13 @@ void node_ctrl_base::disconnect_output_port(const size_t output_port) void node_ctrl_base::disconnect_input_port(const size_t input_port) { - if (_upstream_nodes.count(input_port) == 0 or - _upstream_ports.count(input_port) == 0) { - throw uhd::assertion_error(str(boost::format("[%s] Attempting to disconnect input port %u, which is not registered as connected!") % unique_id() % input_port)); + if (_upstream_nodes.count(input_port) == 0 + or _upstream_ports.count(input_port) == 0) { + throw uhd::assertion_error( + str(boost::format("[%s] Attempting to disconnect input port %u, which is not " + "registered as connected!") + % unique_id() % input_port)); } _upstream_nodes.erase(input_port); _upstream_ports.erase(input_port); } - diff --git a/host/lib/rfnoc/null_block_ctrl_impl.cpp b/host/lib/rfnoc/null_block_ctrl_impl.cpp index 568933e7a..1de41d256 100644 --- a/host/lib/rfnoc/null_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/null_block_ctrl_impl.cpp @@ -4,10 +4,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/utils/log.hpp> -#include <uhd/types/ranges.hpp> #include <uhd/rfnoc/null_block_ctrl.hpp> #include <uhd/rfnoc/traffic_counter.hpp> +#include <uhd/types/ranges.hpp> +#include <uhd/utils/log.hpp> #include <boost/format.hpp> using namespace uhd::rfnoc; @@ -18,34 +18,29 @@ public: UHD_RFNOC_BLOCK_CONSTRUCTOR(null_block_ctrl) { // Register hooks for line_rate: - _tree->access<int>(_root_path / "args" / 0 / "line_rate" / "value") - .add_coerced_subscriber([this](const int delay){ - this->set_line_delay_cycles(delay); - }) - .update() - ; + _tree->access<int>(_root_path / "args" / 0 / "line_rate" / "value") + .add_coerced_subscriber( + [this](const int delay) { this->set_line_delay_cycles(delay); }) + .update(); // Register hooks for bpp: - _tree->access<int>(_root_path / "args" / 0 / "bpp" / "value") - .add_coerced_subscriber([this](const int bpp){ - this->set_bytes_per_packet(bpp); - }) - .update() - ; - - traffic_counter::write_reg_fn_t write = - [this](const uint32_t addr, const uint32_t data) { - const uint64_t traffic_counter_sr_base = 192; - sr_write(addr+traffic_counter_sr_base, data); - }; - - traffic_counter::read_reg_fn_t read = - [this](const uint32_t addr) { - const uint64_t traffic_counter_rb_base = 64; - return user_reg_read64(addr+traffic_counter_rb_base); - }; - - _traffic_counter = std::make_shared<traffic_counter>( - _tree, _root_path, write, read); + _tree->access<int>(_root_path / "args" / 0 / "bpp" / "value") + .add_coerced_subscriber( + [this](const int bpp) { this->set_bytes_per_packet(bpp); }) + .update(); + + traffic_counter::write_reg_fn_t write = [this](const uint32_t addr, + const uint32_t data) { + const uint64_t traffic_counter_sr_base = 192; + sr_write(addr + traffic_counter_sr_base, data); + }; + + traffic_counter::read_reg_fn_t read = [this](const uint32_t addr) { + const uint64_t traffic_counter_rb_base = 64; + return user_reg_read64(addr + traffic_counter_rb_base); + }; + + _traffic_counter = + std::make_shared<traffic_counter>(_tree, _root_path, write, read); } void set_line_delay_cycles(int cycles) @@ -84,10 +79,11 @@ public: return clock_rate / (reg_val + 1); } - void issue_stream_cmd(const uhd::stream_cmd_t &stream_cmd, const size_t) + void issue_stream_cmd(const uhd::stream_cmd_t& stream_cmd, const size_t) { if (not stream_cmd.stream_now) { - throw uhd::not_implemented_error("null_block does not support timed commands."); + throw uhd::not_implemented_error( + "null_block does not support timed commands."); } switch (stream_cmd.stream_mode) { case uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: @@ -100,17 +96,16 @@ public: case uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE: case uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE: - throw uhd::not_implemented_error("null_block does not support streaming modes other than CONTINUOUS"); + throw uhd::not_implemented_error( + "null_block does not support streaming modes other than CONTINUOUS"); default: UHD_THROW_INVALID_CODE_PATH(); } } - void set_destination( - uint32_t next_address, - size_t output_block_port - ) { + void set_destination(uint32_t next_address, size_t output_block_port) + { uhd::sid_t sid(next_address); if (sid.get_src() == 0) { sid.set_src(get_address()); @@ -123,4 +118,3 @@ private: }; UHD_RFNOC_BLOCK_REGISTER(null_block_ctrl, "NullSrcSink"); - diff --git a/host/lib/rfnoc/radio_ctrl_impl.cpp b/host/lib/rfnoc/radio_ctrl_impl.cpp index f3d6cd049..94c3e6ae0 100644 --- a/host/lib/rfnoc/radio_ctrl_impl.cpp +++ b/host/lib/rfnoc/radio_ctrl_impl.cpp @@ -5,20 +5,20 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/format.hpp> +#include "../../transport/super_recv_packet_handler.hpp" #include <uhd/convert.hpp> -#include <uhd/utils/log.hpp> -#include <uhd/types/ranges.hpp> #include <uhd/types/direction.hpp> -#include <uhdlib/rfnoc/wb_iface_adapter.hpp> +#include <uhd/types/ranges.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/radio_ctrl_impl.hpp> -#include "../../transport/super_recv_packet_handler.hpp" +#include <uhdlib/rfnoc/wb_iface_adapter.hpp> +#include <boost/format.hpp> #include <tuple> using namespace uhd; using namespace uhd::rfnoc; -static const size_t BYTES_PER_SAMPLE = 4; +static const size_t BYTES_PER_SAMPLE = 4; const std::string radio_ctrl::ALL_LOS = "all"; /**************************************************************************** @@ -26,11 +26,10 @@ const std::string radio_ctrl::ALL_LOS = "all"; ***************************************************************************/ // Note: block_ctrl_base must be called before this, but has to be called by // the derived class because of virtual inheritance -radio_ctrl_impl::radio_ctrl_impl() : - _tick_rate(rfnoc::rate_node_ctrl::RATE_UNDEFINED) +radio_ctrl_impl::radio_ctrl_impl() : _tick_rate(rfnoc::rate_node_ctrl::RATE_UNDEFINED) { - _num_rx_channels = get_output_ports().size(); - _num_tx_channels = get_input_ports().size(); + _num_rx_channels = get_output_ports().size(); + _num_tx_channels = get_input_ports().size(); _continuous_streaming = std::vector<bool>(2, false); for (size_t i = 0; i < _num_rx_channels; i++) { @@ -52,11 +51,12 @@ radio_ctrl_impl::radio_ctrl_impl() : time_core_3000::readback_bases_type time64_rb_bases; time64_rb_bases.rb_now = regs::rb_addr(regs::RB_TIME_NOW); time64_rb_bases.rb_pps = regs::rb_addr(regs::RB_TIME_PPS); - _time64 = time_core_3000::make(_perifs[i].ctrl, regs::sr_addr(regs::TIME), time64_rb_bases); + _time64 = time_core_3000::make( + _perifs[i].ctrl, regs::sr_addr(regs::TIME), time64_rb_bases); this->set_time_now(0.0); } - //Reset the RX control engine + // Reset the RX control engine sr_write(regs::RX_CTRL_HALT, 1, i); } @@ -64,59 +64,48 @@ radio_ctrl_impl::radio_ctrl_impl() : // Register the time keeper //////////////////////////////////////////////////////////////////// if (not _tree->exists(fs_path("time") / "now")) { - _tree->create<time_spec_t>(fs_path("time") / "now") - .set_publisher([this](){ return this->get_time_now(); }) - ; + _tree->create<time_spec_t>(fs_path("time") / "now").set_publisher([this]() { + return this->get_time_now(); + }); } if (not _tree->exists(fs_path("time") / "pps")) { - _tree->create<time_spec_t>(fs_path("time") / "pps") - .set_publisher([this](){ return this->get_time_last_pps(); }) - ; + _tree->create<time_spec_t>(fs_path("time") / "pps").set_publisher([this]() { + return this->get_time_last_pps(); + }); } if (not _tree->exists(fs_path("time") / "cmd")) { _tree->create<time_spec_t>(fs_path("time") / "cmd"); } _tree->access<time_spec_t>(fs_path("time") / "now") - .add_coerced_subscriber([this](const time_spec_t& time_spec){ - this->set_time_now(time_spec); - }) - ; + .add_coerced_subscriber( + [this](const time_spec_t& time_spec) { this->set_time_now(time_spec); }); _tree->access<time_spec_t>(fs_path("time") / "pps") - .add_coerced_subscriber([this](const time_spec_t& time_spec){ - this->set_time_next_pps(time_spec); - }) - ; + .add_coerced_subscriber( + [this](const time_spec_t& time_spec) { this->set_time_next_pps(time_spec); }); for (size_t i = 0; i < _get_num_radios(); i++) { _tree->access<time_spec_t>("time/cmd") - .add_coerced_subscriber([this, i](const time_spec_t& time_spec){ + .add_coerced_subscriber([this, i](const time_spec_t& time_spec) { this->set_command_tick_rate(this->_tick_rate, i); this->set_command_time(time_spec, i); - }) - ; + }); } // spp gets created in the XML file _tree->access<int>(get_arg_path("spp") / "value") - .add_coerced_subscriber([this](const int spp){ - this->_update_spp(spp); - }) - .update() - ; + .add_coerced_subscriber([this](const int spp) { this->_update_spp(spp); }) + .update(); } void radio_ctrl_impl::_register_loopback_self_test(size_t chan) { size_t hash = size_t(time(NULL)); - for (size_t i = 0; i < 100; i++) - { + for (size_t i = 0; i < 100; i++) { boost::hash_combine(hash, i); sr_write(regs::TEST, uint32_t(hash), chan); uint32_t result = user_reg_read32(regs::RB_TEST, chan); if (result != uint32_t(hash)) { UHD_LOGGER_ERROR("RFNOC RADIO") << "Register loopback test failed"; UHD_LOGGER_ERROR("RFNOC RADIO") - << boost::format("expected: %x result: %x") - % uint32_t(hash) % result - ; + << boost::format("expected: %x result: %x") % uint32_t(hash) % result; return; // exit on any failure } } @@ -137,12 +126,12 @@ double radio_ctrl_impl::set_rate(double rate) return _tick_rate; } -void radio_ctrl_impl::set_tx_antenna(const std::string &ant, const size_t chan) +void radio_ctrl_impl::set_tx_antenna(const std::string& ant, const size_t chan) { _tx_antenna[chan] = ant; } -void radio_ctrl_impl::set_rx_antenna(const std::string &ant, const size_t chan) +void radio_ctrl_impl::set_rx_antenna(const std::string& ant, const size_t chan) { _rx_antenna[chan] = ant; } @@ -167,10 +156,8 @@ double radio_ctrl_impl::set_rx_gain(const double gain, const size_t chan) return _rx_gain[chan] = gain; } -double radio_ctrl_impl::set_tx_bandwidth( - const double bandwidth, - const size_t chan -) { +double radio_ctrl_impl::set_tx_bandwidth(const double bandwidth, const size_t chan) +{ return _tx_bandwidth[chan] = bandwidth; } @@ -179,7 +166,7 @@ double radio_ctrl_impl::set_rx_bandwidth(const double bandwidth, const size_t ch return _rx_bandwidth[chan] = bandwidth; } -void radio_ctrl_impl::set_time_sync(const uhd::time_spec_t &time) +void radio_ctrl_impl::set_time_sync(const uhd::time_spec_t& time) { _time64->set_time_sync(time); } @@ -237,117 +224,119 @@ std::vector<std::string> radio_ctrl_impl::get_rx_lo_names(const size_t /* chan * return std::vector<std::string>(); } -std::vector<std::string> radio_ctrl_impl::get_rx_lo_sources(const std::string & /* name */, const size_t /* chan */) +std::vector<std::string> radio_ctrl_impl::get_rx_lo_sources( + const std::string& /* name */, const size_t /* chan */) { return std::vector<std::string>(); } -freq_range_t radio_ctrl_impl::get_rx_lo_freq_range(const std::string & /* name */, const size_t /* chan */) +freq_range_t radio_ctrl_impl::get_rx_lo_freq_range( + const std::string& /* name */, const size_t /* chan */) { return freq_range_t(); } -void radio_ctrl_impl::set_rx_lo_source(const std::string & /* src */, const std::string & /* name */, const size_t /* chan */) +void radio_ctrl_impl::set_rx_lo_source( + const std::string& /* src */, const std::string& /* name */, const size_t /* chan */) { throw uhd::not_implemented_error("set_rx_lo_source is not supported on this radio"); } -const std::string radio_ctrl_impl::get_rx_lo_source(const std::string & /* name */, const size_t /* chan */) +const std::string radio_ctrl_impl::get_rx_lo_source( + const std::string& /* name */, const size_t /* chan */) { return "internal"; } -void radio_ctrl_impl::set_rx_lo_export_enabled(bool /* enabled */, const std::string & /* name */, const size_t /* chan */) +void radio_ctrl_impl::set_rx_lo_export_enabled( + bool /* enabled */, const std::string& /* name */, const size_t /* chan */) { - throw uhd::not_implemented_error("set_rx_lo_export_enabled is not supported on this radio"); + throw uhd::not_implemented_error( + "set_rx_lo_export_enabled is not supported on this radio"); } -bool radio_ctrl_impl::get_rx_lo_export_enabled(const std::string & /* name */, const size_t /* chan */) +bool radio_ctrl_impl::get_rx_lo_export_enabled( + const std::string& /* name */, const size_t /* chan */) { return false; // Not exporting non-existant LOs } -double radio_ctrl_impl::set_rx_lo_freq(double /* freq */, const std::string & /* name */, const size_t /* chan */) +double radio_ctrl_impl::set_rx_lo_freq( + double /* freq */, const std::string& /* name */, const size_t /* chan */) { throw uhd::not_implemented_error("set_rx_lo_freq is not supported on this radio"); } -double radio_ctrl_impl::get_rx_lo_freq(const std::string & /* name */, const size_t /* chan */) +double radio_ctrl_impl::get_rx_lo_freq( + const std::string& /* name */, const size_t /* chan */) { return 0; } -std::vector<std::string> radio_ctrl_impl::get_tx_lo_names( - const size_t /* chan */ -) { +std::vector<std::string> radio_ctrl_impl::get_tx_lo_names(const size_t /* chan */ +) +{ return std::vector<std::string>(); } std::vector<std::string> radio_ctrl_impl::get_tx_lo_sources( - const std::string & /* name */, - const size_t /* chan */ -) { + const std::string& /* name */, const size_t /* chan */ +) +{ return std::vector<std::string>(); } freq_range_t radio_ctrl_impl::get_tx_lo_freq_range( - const std::string & /* name */, - const size_t /* chan */ -) { + const std::string& /* name */, const size_t /* chan */ +) +{ return freq_range_t(); } void radio_ctrl_impl::set_tx_lo_source( - const std::string & /* src */, - const std::string & /* name */, - const size_t /* chan */ -) { + const std::string& /* src */, const std::string& /* name */, const size_t /* chan */ +) +{ throw uhd::not_implemented_error("set_tx_lo_source is not supported on this radio"); } const std::string radio_ctrl_impl::get_tx_lo_source( - const std::string & /* name */, - const size_t /* chan */ -) { + const std::string& /* name */, const size_t /* chan */ +) +{ return "internal"; } void radio_ctrl_impl::set_tx_lo_export_enabled( - const bool /* enabled */, - const std::string & /* name */, - const size_t /* chan */ -) { - throw uhd::not_implemented_error("set_tx_lo_export_enabled is not supported on this radio"); + const bool /* enabled */, const std::string& /* name */, const size_t /* chan */ +) +{ + throw uhd::not_implemented_error( + "set_tx_lo_export_enabled is not supported on this radio"); } bool radio_ctrl_impl::get_tx_lo_export_enabled( - const std::string & /* name */, - const size_t /* chan */ -) { + const std::string& /* name */, const size_t /* chan */ +) +{ return false; // Not exporting non-existant LOs } double radio_ctrl_impl::set_tx_lo_freq( - const double /* freq */, - const std::string & /* name */, - const size_t /* chan */ -) { - throw uhd::not_implemented_error( - "set_tx_lo_freq is not supported on this radio"); + const double /* freq */, const std::string& /* name */, const size_t /* chan */ +) +{ + throw uhd::not_implemented_error("set_tx_lo_freq is not supported on this radio"); } -double radio_ctrl_impl::get_tx_lo_freq( - const std::string & /* name */, - const size_t chan -) { +double radio_ctrl_impl::get_tx_lo_freq(const std::string& /* name */, const size_t chan) +{ return get_tx_frequency(chan); } void radio_ctrl_impl::enable_rx_timestamps(const bool enable, const size_t chan) { - const uint32_t output_format = 0 - | (enable ? 0x01 : 0x00) - ; + const uint32_t output_format = 0 | (enable ? 0x01 : 0x00); sr_write(regs::RX_CTRL_OUTPUT_FORMAT, output_format, chan); } @@ -356,13 +345,11 @@ void radio_ctrl_impl::enable_rx_timestamps(const bool enable, const size_t chan) **********************************************************************/ //! Pass stream commands to the radio void radio_ctrl_impl::issue_stream_cmd( - const uhd::stream_cmd_t &stream_cmd, - const size_t chan -) { + const uhd::stream_cmd_t& stream_cmd, const size_t chan) +{ std::lock_guard<std::mutex> lock(_mutex); - UHD_RFNOC_BLOCK_TRACE() - << "radio_ctrl_impl::issue_stream_cmd() " << chan - << " " << char(stream_cmd.stream_mode) ; + UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::issue_stream_cmd() " << chan << " " + << char(stream_cmd.stream_mode); if (not _is_streamer_active(uhd::RX_DIRECTION, chan)) { UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::issue_stream_cmd() called on inactive " @@ -373,8 +360,11 @@ void radio_ctrl_impl::issue_stream_cmd( if (stream_cmd.num_samps > max_num_samps) { UHD_LOG_ERROR("RFNOC RADIO", "Requesting too many samples in a single burst! " - "Requested " + std::to_string(stream_cmd.num_samps) + ", maximum " - "is " + std::to_string(max_num_samps) + "."); + "Requested " + + std::to_string(stream_cmd.num_samps) + + ", maximum " + "is " + + std::to_string(max_num_samps) + "."); UHD_LOG_INFO("RFNOC RADIO", "Note that a decimation block will increase the number of samples " "per burst by the decimation factor. Your application may have " @@ -384,43 +374,40 @@ void radio_ctrl_impl::issue_stream_cmd( _continuous_streaming[chan] = (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_START_CONTINUOUS); - //setup the mode to instruction flags + // setup the mode to instruction flags typedef std::tuple<bool, bool, bool, bool> inst_t; static const std::map<stream_cmd_t::stream_mode_t, inst_t> mode_to_inst{ - //reload, chain, samps, stop - {stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false, false)}, - {stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false, true)}, - {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true, false)}, - {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true, false)} - } - ; + // reload, chain, samps, stop + {stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false, false)}, + {stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false, true)}, + {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true, false)}, + {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true, false)}}; - //setup the instruction flag values + // setup the instruction flag values bool inst_reload, inst_chain, inst_samps, inst_stop; std::tie(inst_reload, inst_chain, inst_samps, inst_stop) = mode_to_inst.at(stream_cmd.stream_mode); - //calculate the word from flags and length - const uint32_t cmd_word = 0 - | (uint32_t((stream_cmd.stream_now)? 1 : 0) << 31) - | (uint32_t((inst_chain)? 1 : 0) << 30) - | (uint32_t((inst_reload)? 1 : 0) << 29) - | (uint32_t((inst_stop)? 1 : 0) << 28) - | ((inst_samps) ? stream_cmd.num_samps : ((inst_stop)? 0 : 1)); + // calculate the word from flags and length + const uint32_t cmd_word = + 0 | (uint32_t((stream_cmd.stream_now) ? 1 : 0) << 31) + | (uint32_t((inst_chain) ? 1 : 0) << 30) | (uint32_t((inst_reload) ? 1 : 0) << 29) + | (uint32_t((inst_stop) ? 1 : 0) << 28) + | ((inst_samps) ? stream_cmd.num_samps : ((inst_stop) ? 0 : 1)); - //issue the stream command + // issue the stream command const uint64_t ticks = - (stream_cmd.stream_now)? 0 : stream_cmd.time_spec.to_ticks(get_rate()); + (stream_cmd.stream_now) ? 0 : stream_cmd.time_spec.to_ticks(get_rate()); sr_write(regs::RX_CTRL_CMD, cmd_word, chan); sr_write(regs::RX_CTRL_TIME_HI, uint32_t(ticks >> 32), chan); - sr_write(regs::RX_CTRL_TIME_LO, uint32_t(ticks >> 0), chan); //latches the command + sr_write(regs::RX_CTRL_TIME_LO, uint32_t(ticks >> 0), chan); // latches the command } std::vector<size_t> radio_ctrl_impl::get_active_rx_ports() { std::vector<size_t> active_rx_ports; typedef std::map<size_t, bool> map_t; - for(map_t::value_type &m: _rx_streamer_active) { + for (map_t::value_type& m : _rx_streamer_active) { if (m.second) { active_rx_ports.push_back(m.first); } @@ -433,37 +420,33 @@ std::vector<size_t> radio_ctrl_impl::get_active_rx_ports() **********************************************************************/ void radio_ctrl_impl::set_rx_streamer(bool active, const size_t port) { - UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::set_rx_streamer() " << port << " -> " << active ; + UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::set_rx_streamer() " << port << " -> " + << active; if (port > _num_rx_channels) { throw uhd::value_error(str( boost::format("[%s] Can't (un)register RX streamer on port %d (invalid port)") - % unique_id() % port - )); + % unique_id() % port)); } _rx_streamer_active[port] = active; if (not check_radio_config()) { - throw std::runtime_error(str( - boost::format("[%s]: Invalid radio configuration.") - % unique_id() - )); + throw std::runtime_error( + str(boost::format("[%s]: Invalid radio configuration.") % unique_id())); } } void radio_ctrl_impl::set_tx_streamer(bool active, const size_t port) { - UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::set_tx_streamer() " << port << " -> " << active ; + UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::set_tx_streamer() " << port << " -> " + << active; if (port > _num_tx_channels) { throw uhd::value_error(str( boost::format("[%s] Can't (un)register TX streamer on port %d (invalid port)") - % unique_id() % port - )); + % unique_id() % port)); } _tx_streamer_active[port] = active; if (not check_radio_config()) { - throw std::runtime_error(str( - boost::format("[%s]: Invalid radio configuration.") - % unique_id() - )); + throw std::runtime_error( + str(boost::format("[%s]: Invalid radio configuration.") % unique_id())); } } @@ -472,22 +455,22 @@ void radio_ctrl_impl::set_tx_streamer(bool active, const size_t port) void radio_ctrl_impl::_update_spp(int spp) { std::lock_guard<std::mutex> lock(_mutex); - UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::_update_spp(): Requested spp: " << spp ; + UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::_update_spp(): Requested spp: " << spp; if (spp == 0) { spp = DEFAULT_PACKET_SIZE / BYTES_PER_SAMPLE; } - UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::_update_spp(): Setting spp to: " << spp ; + UHD_RFNOC_BLOCK_TRACE() << "radio_ctrl_impl::_update_spp(): Setting spp to: " << spp; for (size_t i = 0; i < _num_rx_channels; i++) { sr_write(regs::RX_CTRL_MAXLEN, uint32_t(spp), i); } } -void radio_ctrl_impl::set_time_now(const time_spec_t &time_spec) +void radio_ctrl_impl::set_time_now(const time_spec_t& time_spec) { _time64->set_time_now(time_spec); } -void radio_ctrl_impl::set_time_next_pps(const time_spec_t &time_spec) +void radio_ctrl_impl::set_time_next_pps(const time_spec_t& time_spec) { _time64->set_time_next_pps(time_spec); } @@ -502,7 +485,7 @@ time_spec_t radio_ctrl_impl::get_time_last_pps() return _time64->get_time_last_pps(); } -void radio_ctrl_impl::set_time_source(const std::string &source) +void radio_ctrl_impl::set_time_source(const std::string& source) { _tree->access<std::string>("time_source/value").set(source); } @@ -517,7 +500,7 @@ std::vector<std::string> radio_ctrl_impl::get_time_sources() return _tree->access<std::vector<std::string>>("time_source/options").get(); } -void radio_ctrl_impl::set_clock_source(const std::string &source) +void radio_ctrl_impl::set_clock_source(const std::string& source) { _tree->access<std::string>("clock_source/value").set(source); } @@ -539,15 +522,12 @@ std::vector<std::string> radio_ctrl_impl::get_gpio_banks() const } void radio_ctrl_impl::set_gpio_attr( - const std::string &, - const std::string &, - const uint32_t, - const uint32_t -) { + const std::string&, const std::string&, const uint32_t, const uint32_t) +{ throw uhd::not_implemented_error("set_gpio_attr was not defined for this radio"); } -uint32_t radio_ctrl_impl::get_gpio_attr(const std::string &, const std::string &) +uint32_t radio_ctrl_impl::get_gpio_attr(const std::string&, const std::string&) { throw uhd::not_implemented_error("get_gpio_attr was not defined for this radio"); } diff --git a/host/lib/rfnoc/rate_node_ctrl.cpp b/host/lib/rfnoc/rate_node_ctrl.cpp index 2ec8fd81a..08abf4f78 100644 --- a/host/lib/rfnoc/rate_node_ctrl.cpp +++ b/host/lib/rfnoc/rate_node_ctrl.cpp @@ -24,34 +24,28 @@ static double _get_output_samp_rate(rate_node_ctrl::sptr node, size_t port) // FIXME add recursion limiters (i.e. list of explored nodes) -double rate_node_ctrl::get_input_samp_rate( - size_t /* port */ -) { +double rate_node_ctrl::get_input_samp_rate(size_t /* port */ +) +{ try { return find_downstream_unique_property<rate_node_ctrl, double>( - boost::bind(_get_input_samp_rate, _1, _2), - RATE_UNDEFINED - ); - } catch (const uhd::runtime_error &ex) { - throw uhd::runtime_error(str( - boost::format("Multiple sampling rates downstream of %s: %s.") - % unique_id() % ex.what() - )); + boost::bind(_get_input_samp_rate, _1, _2), RATE_UNDEFINED); + } catch (const uhd::runtime_error& ex) { + throw uhd::runtime_error( + str(boost::format("Multiple sampling rates downstream of %s: %s.") + % unique_id() % ex.what())); } } -double rate_node_ctrl::get_output_samp_rate( - size_t /* port */ -) { +double rate_node_ctrl::get_output_samp_rate(size_t /* port */ +) +{ try { return find_upstream_unique_property<rate_node_ctrl, double>( - boost::bind(_get_output_samp_rate, _1, _2), - RATE_UNDEFINED - ); - } catch (const uhd::runtime_error &ex) { - throw uhd::runtime_error(str( - boost::format("Multiple sampling rates upstream of %s: %s.") - % unique_id() % ex.what() - )); + boost::bind(_get_output_samp_rate, _1, _2), RATE_UNDEFINED); + } catch (const uhd::runtime_error& ex) { + throw uhd::runtime_error( + str(boost::format("Multiple sampling rates upstream of %s: %s.") % unique_id() + % ex.what())); } } diff --git a/host/lib/rfnoc/replay_block_ctrl_impl.cpp b/host/lib/rfnoc/replay_block_ctrl_impl.cpp index e9b119085..db3721d37 100644 --- a/host/lib/rfnoc/replay_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/replay_block_ctrl_impl.cpp @@ -14,10 +14,10 @@ using namespace uhd::rfnoc; class replay_block_ctrl_impl : public replay_block_ctrl { public: - static const uint32_t REPLAY_WORD_SIZE = 8; // In bytes + static const uint32_t REPLAY_WORD_SIZE = 8; // In bytes static const uint32_t SAMPLES_PER_WORD = 2; static const uint32_t BYTES_PER_SAMPLE = 4; - static const uint32_t DEFAULT_BUFFER_SIZE = 32*1024*1024; + static const uint32_t DEFAULT_BUFFER_SIZE = 32 * 1024 * 1024; static const uint32_t DEFAULT_WPP = 182; static const uint32_t DEFAULT_SPP = DEFAULT_WPP * SAMPLES_PER_WORD; @@ -26,13 +26,13 @@ public: { _num_channels = get_input_ports().size(); _params.resize(_num_channels); - for(size_t chan = 0; chan < _params.size(); chan++) { + for (size_t chan = 0; chan < _params.size(); chan++) { _params[chan].words_per_packet = DEFAULT_WPP; sr_write("RX_CTRL_MAXLEN", DEFAULT_WPP, chan); // Configure replay channels to be adjacent DEFAULT_BUFFER_SIZE'd blocks - _params[chan].rec_base_addr = chan*DEFAULT_BUFFER_SIZE; - _params[chan].play_base_addr = chan*DEFAULT_BUFFER_SIZE; + _params[chan].rec_base_addr = chan * DEFAULT_BUFFER_SIZE; + _params[chan].play_base_addr = chan * DEFAULT_BUFFER_SIZE; _params[chan].rec_buffer_size = DEFAULT_BUFFER_SIZE; _params[chan].play_buffer_size = DEFAULT_BUFFER_SIZE; sr_write("REC_BASE_ADDR", _params[chan].rec_base_addr, chan); @@ -42,144 +42,159 @@ public: } } - - /************************************************************************** - * API Calls - **************************************************************************/ - - void config_record(const uint32_t base_addr, const uint32_t size, const size_t chan) { + + /************************************************************************** + * API Calls + **************************************************************************/ + + void config_record(const uint32_t base_addr, const uint32_t size, const size_t chan) + { std::lock_guard<std::mutex> lock(_mutex); - _params[chan].rec_base_addr = base_addr; + _params[chan].rec_base_addr = base_addr; _params[chan].rec_buffer_size = size; sr_write("REC_BASE_ADDR", base_addr, chan); sr_write("REC_BUFFER_SIZE", size, chan); sr_write("REC_RESTART", 0, chan); } - - void config_play(const uint32_t base_addr, const uint32_t size, const size_t chan) { + + void config_play(const uint32_t base_addr, const uint32_t size, const size_t chan) + { std::lock_guard<std::mutex> lock(_mutex); - _params[chan].play_base_addr = base_addr; + _params[chan].play_base_addr = base_addr; _params[chan].play_buffer_size = size; sr_write("PLAY_BASE_ADDR", base_addr, chan); sr_write("PLAY_BUFFER_SIZE", size, chan); } - void record_restart(const size_t chan) { + void record_restart(const size_t chan) + { std::lock_guard<std::mutex> lock(_mutex); sr_write("REC_RESTART", 0, chan); } - - uint32_t get_record_addr(const size_t chan) { + + uint32_t get_record_addr(const size_t chan) + { return _params[chan].rec_base_addr; } - - uint32_t get_record_size(const size_t chan) { + + uint32_t get_record_size(const size_t chan) + { return _params[chan].rec_buffer_size; } - uint32_t get_record_fullness(const size_t chan) { + uint32_t get_record_fullness(const size_t chan) + { return user_reg_read32("REC_FULLNESS", chan); } - uint32_t get_play_addr(const size_t chan) { + uint32_t get_play_addr(const size_t chan) + { return _params[chan].play_base_addr; } - - uint32_t get_play_size(const size_t chan) { + + uint32_t get_play_size(const size_t chan) + { return _params[chan].play_buffer_size; } - void set_words_per_packet(const uint32_t num_words, const size_t chan) { + void set_words_per_packet(const uint32_t num_words, const size_t chan) + { std::lock_guard<std::mutex> lock(_mutex); _params[chan].words_per_packet = num_words; sr_write("RX_CTRL_MAXLEN", num_words, chan); } - uint32_t get_words_per_packet(const size_t chan) { + uint32_t get_words_per_packet(const size_t chan) + { return _params[chan].words_per_packet; } - void play_halt(const size_t chan) { + void play_halt(const size_t chan) + { sr_write("RX_CTRL_HALT", 1, chan); } - - - /*************************************************************************** - * Radio-like Streamer - **************************************************************************/ - - void issue_stream_cmd( - const uhd::stream_cmd_t &stream_cmd, - const size_t chan - ) { + + + /*************************************************************************** + * Radio-like Streamer + **************************************************************************/ + + void issue_stream_cmd(const uhd::stream_cmd_t& stream_cmd, const size_t chan) + { std::lock_guard<std::mutex> lock(_mutex); - UHD_RFNOC_BLOCK_TRACE() - << "replay_block_ctrl_impl::issue_stream_cmd() " << chan - << " " << char(stream_cmd.stream_mode) ; - - if (not (_rx_streamer_active.count(chan) and _rx_streamer_active.at(chan))) { + UHD_RFNOC_BLOCK_TRACE() << "replay_block_ctrl_impl::issue_stream_cmd() " << chan + << " " << char(stream_cmd.stream_mode); + + if (not(_rx_streamer_active.count(chan) and _rx_streamer_active.at(chan))) { UHD_RFNOC_BLOCK_TRACE() << "replay_block_ctrl_impl::issue_stream_cmd() called on inactive " "channel. Skipping."; return; } - + constexpr size_t max_num_samps = 0x0fffffff; if (stream_cmd.num_samps > max_num_samps) { UHD_LOG_ERROR("REPLAY", "Requesting too many samples in a single burst! " - "Requested " + std::to_string(stream_cmd.num_samps) + ", maximum " - "is " + std::to_string(max_num_samps) + "."); + "Requested " + + std::to_string(stream_cmd.num_samps) + + ", maximum " + "is " + + std::to_string(max_num_samps) + "."); throw uhd::value_error("Requested too many samples in a single burst."); } - + // Setup the mode to instruction flags typedef std::tuple<bool, bool, bool, bool> inst_t; - static const std::map<stream_cmd_t::stream_mode_t, inst_t> mode_to_inst { - // reload, chain, samps, stop - {stream_cmd_t::STREAM_MODE_START_CONTINUOUS, inst_t(true, true, false, false)}, - {stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, inst_t(false, false, false, true)}, - {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, inst_t(false, false, true, false)}, - {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, inst_t(false, true, true, false)} - }; - + static const std::map<stream_cmd_t::stream_mode_t, inst_t> mode_to_inst{ + // reload, chain, samps, stop + {stream_cmd_t::STREAM_MODE_START_CONTINUOUS, + inst_t(true, true, false, false)}, + {stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, + inst_t(false, false, false, true)}, + {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE, + inst_t(false, false, true, false)}, + {stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE, + inst_t(false, true, true, false)}}; + // Setup the instruction flag values bool inst_reload, inst_chain, inst_samps, inst_stop; std::tie(inst_reload, inst_chain, inst_samps, inst_stop) = mode_to_inst.at(stream_cmd.stream_mode); - + // Calculate how many words to transfer at a time in CONTINUOUS mode uint32_t cont_burst_size = - (_params[chan].play_buffer_size > _params[chan].words_per_packet) ? - _params[chan].words_per_packet : _params[chan].play_buffer_size; - + (_params[chan].play_buffer_size > _params[chan].words_per_packet) + ? _params[chan].words_per_packet + : _params[chan].play_buffer_size; + // Calculate the number of words to transfer in NUM_SAMPS mode uint32_t num_words = stream_cmd.num_samps / SAMPLES_PER_WORD; - + // Calculate the word from flags and length - const uint32_t cmd_word = 0 - | (uint32_t(stream_cmd.stream_now ? 1 : 0) << 31) - | (uint32_t(inst_chain ? 1 : 0) << 30) - | (uint32_t(inst_reload ? 1 : 0) << 29) - | (uint32_t(inst_stop ? 1 : 0) << 28) + const uint32_t cmd_word = + 0 | (uint32_t(stream_cmd.stream_now ? 1 : 0) << 31) + | (uint32_t(inst_chain ? 1 : 0) << 30) | (uint32_t(inst_reload ? 1 : 0) << 29) + | (uint32_t(inst_stop ? 1 : 0) << 28) | (inst_samps ? num_words : (inst_stop ? 0 : cont_burst_size)); - + // Issue the stream command sr_write("RX_CTRL_COMMAND", cmd_word, chan); } - + private: - struct replay_params_t { + struct replay_params_t + { size_t words_per_packet; uint32_t rec_base_addr; uint32_t rec_buffer_size; uint32_t play_base_addr; uint32_t play_buffer_size; }; - + size_t _num_channels; std::vector<replay_params_t> _params; - + std::mutex _mutex; }; diff --git a/host/lib/rfnoc/rx_stream_terminator.cpp b/host/lib/rfnoc/rx_stream_terminator.cpp index 83c0420e2..18ecb4974 100644 --- a/host/lib/rfnoc/rx_stream_terminator.cpp +++ b/host/lib/rfnoc/rx_stream_terminator.cpp @@ -6,20 +6,20 @@ // #include "../transport/super_recv_packet_handler.hpp" -#include <uhd/utils/log.hpp> #include <uhd/rfnoc/source_node_ctrl.hpp> -#include <uhdlib/rfnoc/rx_stream_terminator.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/radio_ctrl_impl.hpp> +#include <uhdlib/rfnoc/rx_stream_terminator.hpp> #include <boost/format.hpp> using namespace uhd::rfnoc; size_t rx_stream_terminator::_count = 0; -rx_stream_terminator::rx_stream_terminator() : - _term_index(_count), - _samp_rate(rate_node_ctrl::RATE_UNDEFINED), - _tick_rate(tick_node_ctrl::RATE_UNDEFINED) +rx_stream_terminator::rx_stream_terminator() + : _term_index(_count) + , _samp_rate(rate_node_ctrl::RATE_UNDEFINED) + , _tick_rate(tick_node_ctrl::RATE_UNDEFINED) { _count++; } @@ -38,20 +38,19 @@ void rx_stream_terminator::set_rx_streamer(bool active, const size_t) { // TODO this is identical to source_node_ctrl::set_rx_streamer() -> factor out UHD_RFNOC_BLOCK_TRACE() << "rx_stream_terminator::set_rx_streamer() " << active; - for(const node_ctrl_base::node_map_pair_t upstream_node: _upstream_nodes) { + for (const node_ctrl_base::node_map_pair_t upstream_node : _upstream_nodes) { source_node_ctrl::sptr curr_upstream_block_ctrl = boost::dynamic_pointer_cast<source_node_ctrl>(upstream_node.second.lock()); if (curr_upstream_block_ctrl) { curr_upstream_block_ctrl->set_rx_streamer( - active, - get_upstream_port(upstream_node.first) - ); + active, get_upstream_port(upstream_node.first)); } _rx_streamer_active[upstream_node.first] = active; } } -void rx_stream_terminator::handle_overrun(boost::weak_ptr<uhd::rx_streamer> streamer, const size_t) +void rx_stream_terminator::handle_overrun( + boost::weak_ptr<uhd::rx_streamer> streamer, const size_t) { std::unique_lock<std::mutex> l(_overrun_handler_mutex, std::defer_lock); if (!l.try_lock()) { @@ -59,24 +58,28 @@ void rx_stream_terminator::handle_overrun(boost::weak_ptr<uhd::rx_streamer> stre return; } - std::vector<boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl> > upstream_radio_nodes = + std::vector<boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl>> upstream_radio_nodes = find_upstream_node<uhd::rfnoc::radio_ctrl_impl>(); const size_t n_radios = upstream_radio_nodes.size(); if (n_radios == 0) { return; } - UHD_RFNOC_BLOCK_TRACE() << "rx_stream_terminator::handle_overrun()" ; + UHD_RFNOC_BLOCK_TRACE() << "rx_stream_terminator::handle_overrun()"; boost::shared_ptr<uhd::transport::sph::recv_packet_streamer> my_streamer = - boost::dynamic_pointer_cast<uhd::transport::sph::recv_packet_streamer>(streamer.lock()); - if (not my_streamer) return; //If the rx_streamer has expired then overflow handling makes no sense. + boost::dynamic_pointer_cast<uhd::transport::sph::recv_packet_streamer>( + streamer.lock()); + if (not my_streamer) + return; // If the rx_streamer has expired then overflow handling makes no sense. bool in_continuous_streaming_mode = true; - int num_channels = 0; - for(const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl> &node: upstream_radio_nodes) { + int num_channels = 0; + for (const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl>& node : + upstream_radio_nodes) { num_channels += node->get_active_rx_ports().size(); - for(const size_t port: node->get_active_rx_ports()) { - in_continuous_streaming_mode = in_continuous_streaming_mode && node->in_continuous_streaming_mode(port); + for (const size_t port : node->get_active_rx_ports()) { + in_continuous_streaming_mode = in_continuous_streaming_mode + && node->in_continuous_streaming_mode(port); } } if (num_channels == 0) { @@ -84,35 +87,40 @@ void rx_stream_terminator::handle_overrun(boost::weak_ptr<uhd::rx_streamer> stre } if (num_channels == 1 and in_continuous_streaming_mode) { - std::vector<size_t> active_rx_ports = upstream_radio_nodes[0]->get_active_rx_ports(); + std::vector<size_t> active_rx_ports = + upstream_radio_nodes[0]->get_active_rx_ports(); if (active_rx_ports.empty()) { return; } const size_t port = active_rx_ports[0]; - upstream_radio_nodes[0]->issue_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS, port); + upstream_radio_nodes[0]->issue_stream_cmd( + stream_cmd_t::STREAM_MODE_START_CONTINUOUS, port); return; } ///////////////////////////////////////////////////////////// // MIMO overflow recovery time ///////////////////////////////////////////////////////////// - for(const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl> &node: upstream_radio_nodes) { - for(const size_t port: node->get_active_rx_ports()) { + for (const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl>& node : + upstream_radio_nodes) { + for (const size_t port : node->get_active_rx_ports()) { // check all the ports on all the radios node->rx_ctrl_clear_cmds(port); node->issue_stream_cmd(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS, port); } } - //flush transports + // flush transports my_streamer->flush_all(0.001); // TODO flushing will probably have to go away. - //restart streaming on all channels + // restart streaming on all channels if (in_continuous_streaming_mode) { stream_cmd_t stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS); stream_cmd.stream_now = false; - stream_cmd.time_spec = upstream_radio_nodes[0]->get_time_now() + time_spec_t(0.05); + stream_cmd.time_spec = + upstream_radio_nodes[0]->get_time_now() + time_spec_t(0.05); - for(const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl> &node: upstream_radio_nodes) { - for(const size_t port: node->get_active_rx_ports()) { + for (const boost::shared_ptr<uhd::rfnoc::radio_ctrl_impl>& node : + upstream_radio_nodes) { + for (const size_t port : node->get_active_rx_ports()) { node->issue_stream_cmd(stream_cmd, port); } } @@ -121,7 +129,6 @@ void rx_stream_terminator::handle_overrun(boost::weak_ptr<uhd::rx_streamer> stre rx_stream_terminator::~rx_stream_terminator() { - UHD_RFNOC_BLOCK_TRACE() << "rx_stream_terminator::~rx_stream_terminator() " ; + UHD_RFNOC_BLOCK_TRACE() << "rx_stream_terminator::~rx_stream_terminator() "; set_rx_streamer(false, 0); } - diff --git a/host/lib/rfnoc/scalar_node_ctrl.cpp b/host/lib/rfnoc/scalar_node_ctrl.cpp index ffce0d9cf..f197da0b5 100644 --- a/host/lib/rfnoc/scalar_node_ctrl.cpp +++ b/host/lib/rfnoc/scalar_node_ctrl.cpp @@ -23,34 +23,28 @@ static double _get_output_factor(scalar_node_ctrl::sptr node, size_t port) } // FIXME add recursion limiters (i.e. list of explored nodes) -double scalar_node_ctrl::get_input_scale_factor( - size_t /* port */ -) { +double scalar_node_ctrl::get_input_scale_factor(size_t /* port */ +) +{ try { return find_downstream_unique_property<scalar_node_ctrl, double>( - boost::bind(_get_input_factor, _1, _2), - SCALE_UNDEFINED - ); - } catch (const uhd::runtime_error &ex) { - throw uhd::runtime_error(str( - boost::format("Multiple scaling factors rates downstream of %s: %s.") - % unique_id() % ex.what() - )); + boost::bind(_get_input_factor, _1, _2), SCALE_UNDEFINED); + } catch (const uhd::runtime_error& ex) { + throw uhd::runtime_error( + str(boost::format("Multiple scaling factors rates downstream of %s: %s.") + % unique_id() % ex.what())); } } -double scalar_node_ctrl::get_output_scale_factor( - size_t /* port */ -) { +double scalar_node_ctrl::get_output_scale_factor(size_t /* port */ +) +{ try { return find_upstream_unique_property<scalar_node_ctrl, double>( - boost::bind(_get_output_factor, _1, _2), - SCALE_UNDEFINED - ); - } catch (const uhd::runtime_error &ex) { - throw uhd::runtime_error(str( - boost::format("Multiple scaling factors rates upstream of %s: %s.") - % unique_id() % ex.what() - )); + boost::bind(_get_output_factor, _1, _2), SCALE_UNDEFINED); + } catch (const uhd::runtime_error& ex) { + throw uhd::runtime_error( + str(boost::format("Multiple scaling factors rates upstream of %s: %s.") + % unique_id() % ex.what())); } } diff --git a/host/lib/rfnoc/siggen_block_ctrl_impl.cpp b/host/lib/rfnoc/siggen_block_ctrl_impl.cpp index b876cf715..dc4035962 100644 --- a/host/lib/rfnoc/siggen_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/siggen_block_ctrl_impl.cpp @@ -4,9 +4,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <boost/format.hpp> -#include <uhd/utils/log.hpp> #include <uhd/rfnoc/siggen_block_ctrl.hpp> +#include <uhd/utils/log.hpp> +#include <boost/format.hpp> using namespace uhd::rfnoc; @@ -18,7 +18,7 @@ public: // nop } - void issue_stream_cmd(const uhd::stream_cmd_t &stream_cmd, const size_t) + void issue_stream_cmd(const uhd::stream_cmd_t& stream_cmd, const size_t) { UHD_LOGGER_TRACE(unique_id()) << "issue_stream_cmd()" << std::endl; if (not stream_cmd.stream_now) { @@ -36,14 +36,13 @@ public: case uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE: case uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE: - throw uhd::not_implemented_error( - "siggen_block does not support streaming modes other than CONTINUOUS"); + throw uhd::not_implemented_error("siggen_block does not support " + "streaming modes other than CONTINUOUS"); default: UHD_THROW_INVALID_CODE_PATH(); } } - }; UHD_RFNOC_BLOCK_REGISTER(siggen_block_ctrl, "SigGen"); diff --git a/host/lib/rfnoc/sink_block_ctrl_base.cpp b/host/lib/rfnoc/sink_block_ctrl_base.cpp index d14fe2f38..bb81706f9 100644 --- a/host/lib/rfnoc/sink_block_ctrl_base.cpp +++ b/host/lib/rfnoc/sink_block_ctrl_base.cpp @@ -5,8 +5,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/sink_block_ctrl_base.hpp> #include <uhd/rfnoc/constants.hpp> +#include <uhd/rfnoc/sink_block_ctrl_base.hpp> #include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/utils.hpp> @@ -20,22 +20,19 @@ using namespace uhd::rfnoc; stream_sig_t sink_block_ctrl_base::get_input_signature(size_t block_port) const { if (not _tree->exists(_root_path / "ports" / "in" / block_port)) { - throw uhd::runtime_error(str( - boost::format("Invalid port number %d for block %s") - % block_port % unique_id() - )); + throw uhd::runtime_error(str(boost::format("Invalid port number %d for block %s") + % block_port % unique_id())); } return _resolve_port_def( - _tree->access<blockdef::port_t>(_root_path / "ports" / "in" / block_port).get() - ); + _tree->access<blockdef::port_t>(_root_path / "ports" / "in" / block_port).get()); } std::vector<size_t> sink_block_ctrl_base::get_input_ports() const { std::vector<size_t> input_ports; input_ports.reserve(_tree->list(_root_path / "ports" / "in").size()); - for(const std::string port: _tree->list(_root_path / "ports" / "in")) { + for (const std::string port : _tree->list(_root_path / "ports" / "in")) { input_ports.push_back(boost::lexical_cast<size_t>(port)); } return input_ports; @@ -44,57 +41,57 @@ std::vector<size_t> sink_block_ctrl_base::get_input_ports() const /*********************************************************************** * FPGA Configuration **********************************************************************/ -size_t sink_block_ctrl_base::get_fifo_size(size_t block_port) const { - if (_tree->exists(_root_path / "input_buffer_size" / str(boost::format("%d") % block_port))) { - return _tree->access<size_t>(_root_path / "input_buffer_size" / str(boost::format("%d") % block_port)).get(); +size_t sink_block_ctrl_base::get_fifo_size(size_t block_port) const +{ + if (_tree->exists( + _root_path / "input_buffer_size" / str(boost::format("%d") % block_port))) { + return _tree + ->access<size_t>( + _root_path / "input_buffer_size" / str(boost::format("%d") % block_port)) + .get(); } return 0; } void sink_block_ctrl_base::configure_flow_control_in( - const size_t bytes, - const size_t block_port -) { - UHD_RFNOC_BLOCK_TRACE() << boost::format("sink_block_ctrl_base::configure_flow_control_in(bytes=%d)") % bytes; + const size_t bytes, const size_t block_port) +{ + UHD_RFNOC_BLOCK_TRACE() + << boost::format("sink_block_ctrl_base::configure_flow_control_in(bytes=%d)") + % bytes; uint32_t bytes_word = 0; if (bytes) { // Bit 32 enables flow control - bytes_word = (1<<31) | bytes; + bytes_word = (1 << 31) | bytes; } sr_write(SR_FLOW_CTRL_BYTES_PER_ACK, bytes_word, block_port); } -void sink_block_ctrl_base::set_error_policy( - const std::string &policy -) { - if (policy == "next_packet") - { +void sink_block_ctrl_base::set_error_policy(const std::string& policy) +{ + if (policy == "next_packet") { sr_write(SR_ERROR_POLICY, (1 << 2) | 1); - } - else if (policy == "next_burst") - { + } else if (policy == "next_burst") { sr_write(SR_ERROR_POLICY, (1 << 3) | 1); - } - else if (policy == "continue") - { + } else if (policy == "continue") { sr_write(SR_ERROR_POLICY, (1 << 1) | 1); - } - else if (policy == "wait") - { + } else if (policy == "wait") { sr_write(SR_ERROR_POLICY, 1); - } - else throw uhd::value_error("Block input cannot handle requested error policy: " + policy); + } else + throw uhd::value_error( + "Block input cannot handle requested error policy: " + policy); } /*********************************************************************** * Hooks **********************************************************************/ size_t sink_block_ctrl_base::_request_input_port( - const size_t suggested_port, - const uhd::device_addr_t & -) const { - const std::set<size_t> valid_input_ports = utils::str_list_to_set<size_t>(_tree->list(_root_path / "ports" / "in")); - return utils::node_map_find_first_free(_upstream_nodes, suggested_port, valid_input_ports); + const size_t suggested_port, const uhd::device_addr_t&) const +{ + const std::set<size_t> valid_input_ports = + utils::str_list_to_set<size_t>(_tree->list(_root_path / "ports" / "in")); + return utils::node_map_find_first_free( + _upstream_nodes, suggested_port, valid_input_ports); } // vim: sw=4 et: diff --git a/host/lib/rfnoc/sink_node_ctrl.cpp b/host/lib/rfnoc/sink_node_ctrl.cpp index 03e259783..53a26d7ed 100644 --- a/host/lib/rfnoc/sink_node_ctrl.cpp +++ b/host/lib/rfnoc/sink_node_ctrl.cpp @@ -5,18 +5,16 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/utils/log.hpp> #include <uhd/rfnoc/sink_node_ctrl.hpp> #include <uhd/rfnoc/source_node_ctrl.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/utils.hpp> using namespace uhd::rfnoc; size_t sink_node_ctrl::connect_upstream( - node_ctrl_base::sptr upstream_node, - size_t port, - const uhd::device_addr_t &args -) { + node_ctrl_base::sptr upstream_node, size_t port, const uhd::device_addr_t& args) +{ boost::mutex::scoped_lock lock(_input_mutex); port = _request_input_port(port, args); _register_upstream_node(upstream_node, port); @@ -25,7 +23,8 @@ size_t sink_node_ctrl::connect_upstream( void sink_node_ctrl::set_tx_streamer(bool active, const size_t port) { - UHD_RFNOC_BLOCK_TRACE() << "sink_node_ctrl::set_tx_streamer() " << active << " " << port ; + UHD_RFNOC_BLOCK_TRACE() << "sink_node_ctrl::set_tx_streamer() " << active << " " + << port; /* Enable all downstream connections: for(const node_ctrl_base::node_map_pair_t downstream_node: list_downstream_nodes()) { @@ -43,12 +42,11 @@ void sink_node_ctrl::set_tx_streamer(bool active, const size_t port) // Only enable 1:1 if (list_downstream_nodes().count(port)) { sink_node_ctrl::sptr this_downstream_block_ctrl = - boost::dynamic_pointer_cast<sink_node_ctrl>(list_downstream_nodes().at(port).lock()); + boost::dynamic_pointer_cast<sink_node_ctrl>( + list_downstream_nodes().at(port).lock()); if (this_downstream_block_ctrl) { this_downstream_block_ctrl->set_tx_streamer( - active, - get_downstream_port(port) - ); + active, get_downstream_port(port)); } } @@ -56,22 +54,22 @@ void sink_node_ctrl::set_tx_streamer(bool active, const size_t port) } size_t sink_node_ctrl::_request_input_port( - const size_t suggested_port, - const uhd::device_addr_t & -) const { + const size_t suggested_port, const uhd::device_addr_t&) const +{ return utils::node_map_find_first_free(_upstream_nodes, suggested_port); } void sink_node_ctrl::_register_upstream_node( - node_ctrl_base::sptr upstream_node, - size_t port -) { + node_ctrl_base::sptr upstream_node, size_t port) +{ // Do all the checks: if (port == ANY_PORT) { throw uhd::type_error("Invalid input port number."); } if (_upstream_nodes.count(port) and not _upstream_nodes[port].expired()) { - throw uhd::runtime_error(str(boost::format("On node %s, input port %d is already connected.") % unique_id() % port)); + throw uhd::runtime_error( + str(boost::format("On node %s, input port %d is already connected.") + % unique_id() % port)); } if (not boost::dynamic_pointer_cast<source_node_ctrl>(upstream_node)) { throw uhd::type_error("Attempting to register a non-source block as upstream."); diff --git a/host/lib/rfnoc/source_block_ctrl_base.cpp b/host/lib/rfnoc/source_block_ctrl_base.cpp index 58cf63eef..4097f3d7b 100644 --- a/host/lib/rfnoc/source_block_ctrl_base.cpp +++ b/host/lib/rfnoc/source_block_ctrl_base.cpp @@ -5,9 +5,9 @@ // SPDX-License-Identifier: GPL-3.0-or-later // +#include <uhd/rfnoc/constants.hpp> #include <uhd/rfnoc/source_block_ctrl_base.hpp> #include <uhd/utils/log.hpp> -#include <uhd/rfnoc/constants.hpp> #include <uhdlib/rfnoc/utils.hpp> #include <chrono> #include <thread> @@ -19,31 +19,30 @@ using namespace uhd::rfnoc; * Streaming operations **********************************************************************/ void source_block_ctrl_base::issue_stream_cmd( - const uhd::stream_cmd_t &stream_cmd, - const size_t chan -) { - UHD_RFNOC_BLOCK_TRACE() << "source_block_ctrl_base::issue_stream_cmd()" ; + const uhd::stream_cmd_t& stream_cmd, const size_t chan) +{ + UHD_RFNOC_BLOCK_TRACE() << "source_block_ctrl_base::issue_stream_cmd()"; if (_upstream_nodes.empty()) { - UHD_LOGGER_WARNING("RFNOC") << "issue_stream_cmd() not implemented for " << get_block_id() ; + UHD_LOGGER_WARNING("RFNOC") + << "issue_stream_cmd() not implemented for " << get_block_id(); return; } - for(const node_ctrl_base::node_map_pair_t upstream_node: _upstream_nodes) { + for (const node_ctrl_base::node_map_pair_t upstream_node : _upstream_nodes) { // FIXME: Need proper mapping from input port to output port // The code below assumes the input port and output port are the same // if the number of upstream and downstream connections are the same. // The stream command is limited to only that port to prevent issuing // it on the wrong block and port. - if (_upstream_nodes.size() == _downstream_nodes.size() and - upstream_node.first != chan) - { + if (_upstream_nodes.size() == _downstream_nodes.size() + and upstream_node.first != chan) { continue; } source_node_ctrl::sptr this_upstream_block_ctrl = boost::dynamic_pointer_cast<source_node_ctrl>(upstream_node.second.lock()); - if (this_upstream_block_ctrl) - { - this_upstream_block_ctrl->issue_stream_cmd(stream_cmd, get_upstream_port(upstream_node.first)); + if (this_upstream_block_ctrl) { + this_upstream_block_ctrl->issue_stream_cmd( + stream_cmd, get_upstream_port(upstream_node.first)); } } } @@ -54,22 +53,19 @@ void source_block_ctrl_base::issue_stream_cmd( stream_sig_t source_block_ctrl_base::get_output_signature(size_t block_port) const { if (not _tree->exists(_root_path / "ports" / "out" / block_port)) { - throw uhd::runtime_error(str( - boost::format("Invalid port number %d for block %s") - % block_port % unique_id() - )); + throw uhd::runtime_error(str(boost::format("Invalid port number %d for block %s") + % block_port % unique_id())); } return _resolve_port_def( - _tree->access<blockdef::port_t>(_root_path / "ports" / "out" / block_port).get() - ); + _tree->access<blockdef::port_t>(_root_path / "ports" / "out" / block_port).get()); } std::vector<size_t> source_block_ctrl_base::get_output_ports() const { std::vector<size_t> output_ports; output_ports.reserve(_tree->list(_root_path / "ports" / "out").size()); - for(const std::string port: _tree->list(_root_path / "ports" / "out")) { + for (const std::string port : _tree->list(_root_path / "ports" / "out")) { output_ports.push_back(boost::lexical_cast<size_t>(port)); } return output_ports; @@ -79,57 +75,60 @@ std::vector<size_t> source_block_ctrl_base::get_output_ports() const * FPGA Configuration **********************************************************************/ void source_block_ctrl_base::set_destination( - uint32_t next_address, - size_t output_block_port -) { - UHD_RFNOC_BLOCK_TRACE() << "source_block_ctrl_base::set_destination() " << uhd::sid_t(next_address) ; + uint32_t next_address, size_t output_block_port) +{ + UHD_RFNOC_BLOCK_TRACE() << "source_block_ctrl_base::set_destination() " + << uhd::sid_t(next_address); sid_t new_sid(next_address); new_sid.set_src(get_address(output_block_port)); - UHD_RFNOC_BLOCK_TRACE() << " Setting SID: " << new_sid << " "; - sr_write(SR_NEXT_DST_SID, (1<<16) | next_address, output_block_port); + UHD_RFNOC_BLOCK_TRACE() << " Setting SID: " << new_sid << " "; + sr_write(SR_NEXT_DST_SID, (1 << 16) | next_address, output_block_port); } -void source_block_ctrl_base::configure_flow_control_out( - const bool enable_fc_output, - const size_t buf_size_bytes, - const size_t pkt_limit, - const size_t block_port, - UHD_UNUSED(const uhd::sid_t &sid) -) { - UHD_RFNOC_BLOCK_TRACE() << "source_block_ctrl_base::configure_flow_control_out() buf_size_bytes==" << buf_size_bytes; +void source_block_ctrl_base::configure_flow_control_out(const bool enable_fc_output, + const size_t buf_size_bytes, + const size_t pkt_limit, + const size_t block_port, + UHD_UNUSED(const uhd::sid_t& sid)) +{ + UHD_RFNOC_BLOCK_TRACE() + << "source_block_ctrl_base::configure_flow_control_out() buf_size_bytes==" + << buf_size_bytes; if (buf_size_bytes == 0) { - throw uhd::runtime_error(str( - boost::format("Invalid window size %d for block %s. Window size cannot be 0 bytes.") - % buf_size_bytes % unique_id() - )); + throw uhd::runtime_error( + str(boost::format( + "Invalid window size %d for block %s. Window size cannot be 0 bytes.") + % buf_size_bytes % unique_id())); } - //Disable flow control entirely and let all upstream data flush out - //We need to do this every time the window is changed because - //a) We don't know what state the flow-control module was left in + // Disable flow control entirely and let all upstream data flush out + // We need to do this every time the window is changed because + // a) We don't know what state the flow-control module was left in // in the previous run (it should still be enabled) - //b) Changing the window size where data is buffered upstream may + // b) Changing the window size where data is buffered upstream may // result in stale packets entering the stream. sr_write(SR_FLOW_CTRL_EN, 0, block_port); - //Wait for data to flush out. - //In the FPGA we are guaranteed that all buffered packets are more-or-less consecutive. - //1ms@200MHz = 200,000 cycles of "flush time". - //200k cycles = 200k * 8 bytes (64 bits) = 1.6MB of data that can be flushed. - //Typically in the FPGA we have buffering in the order of kilobytes so waiting for 1MB - //to flush is more than enough time. - //TODO: Enhancement. We should get feedback from the FPGA about when the source_flow_control + // Wait for data to flush out. + // In the FPGA we are guaranteed that all buffered packets are more-or-less + // consecutive. 1ms@200MHz = 200,000 cycles of "flush time". 200k cycles = 200k * 8 + // bytes (64 bits) = 1.6MB of data that can be flushed. Typically in the FPGA we have + // buffering in the order of kilobytes so waiting for 1MB to flush is more than enough + // time. + // TODO: Enhancement. We should get feedback from the FPGA about when the + // source_flow_control // module is done flushing. std::this_thread::sleep_for(std::chrono::milliseconds(1)); - //Enable source flow control module and conditionally enable byte based and/or packet count - //based flow control - const bool enable_byte_fc = (buf_size_bytes != 0); + // Enable source flow control module and conditionally enable byte based and/or packet + // count based flow control + const bool enable_byte_fc = (buf_size_bytes != 0); const bool enable_pkt_cnt_fc = (pkt_limit != 0); - const uint32_t config = (enable_fc_output ? 1 : 0) | (enable_byte_fc << 1) | (enable_pkt_cnt_fc << 2); + const uint32_t config = (enable_fc_output ? 1 : 0) | (enable_byte_fc << 1) + | (enable_pkt_cnt_fc << 2); - //Resize the FC window. - //Precondition: No data can be buffered upstream. + // Resize the FC window. + // Precondition: No data can be buffered upstream. if (enable_byte_fc) { sr_write(SR_FLOW_CTRL_WINDOW_SIZE, buf_size_bytes, block_port); } @@ -137,8 +136,8 @@ void source_block_ctrl_base::configure_flow_control_out( sr_write(SR_FLOW_CTRL_PKT_LIMIT, pkt_limit, block_port); } - //Enable the FC window. - //Precondition: The window size and/or packet limit must be set. + // Enable the FC window. + // Precondition: The window size and/or packet limit must be set. sr_write(SR_FLOW_CTRL_EN, config, block_port); } @@ -146,10 +145,11 @@ void source_block_ctrl_base::configure_flow_control_out( * Hooks **********************************************************************/ size_t source_block_ctrl_base::_request_output_port( - const size_t suggested_port, - const uhd::device_addr_t & -) const { - const std::set<size_t> valid_output_ports = utils::str_list_to_set<size_t>(_tree->list(_root_path / "ports" / "out")); - return utils::node_map_find_first_free(_downstream_nodes, suggested_port, valid_output_ports); + const size_t suggested_port, const uhd::device_addr_t&) const +{ + const std::set<size_t> valid_output_ports = + utils::str_list_to_set<size_t>(_tree->list(_root_path / "ports" / "out")); + return utils::node_map_find_first_free( + _downstream_nodes, suggested_port, valid_output_ports); } // vim: sw=4 et: diff --git a/host/lib/rfnoc/source_node_ctrl.cpp b/host/lib/rfnoc/source_node_ctrl.cpp index 54e65b16c..23a17a463 100644 --- a/host/lib/rfnoc/source_node_ctrl.cpp +++ b/host/lib/rfnoc/source_node_ctrl.cpp @@ -5,18 +5,16 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/utils/log.hpp> -#include <uhd/rfnoc/source_node_ctrl.hpp> #include <uhd/rfnoc/sink_node_ctrl.hpp> +#include <uhd/rfnoc/source_node_ctrl.hpp> +#include <uhd/utils/log.hpp> #include <uhdlib/rfnoc/utils.hpp> using namespace uhd::rfnoc; size_t source_node_ctrl::connect_downstream( - node_ctrl_base::sptr downstream_node, - size_t port, - const uhd::device_addr_t &args -) { + node_ctrl_base::sptr downstream_node, size_t port, const uhd::device_addr_t& args) +{ boost::mutex::scoped_lock lock(_output_mutex); port = _request_output_port(port, args); _register_downstream_node(downstream_node, port); @@ -25,7 +23,8 @@ size_t source_node_ctrl::connect_downstream( void source_node_ctrl::set_rx_streamer(bool active, const size_t port) { - UHD_RFNOC_BLOCK_TRACE() << "source_node_ctrl::set_rx_streamer() " << port << " -> " << active ; + UHD_RFNOC_BLOCK_TRACE() << "source_node_ctrl::set_rx_streamer() " << port << " -> " + << active; /* This will enable all upstream blocks: for(const node_ctrl_base::node_map_pair_t upstream_node: list_upstream_nodes()) { @@ -43,12 +42,10 @@ void source_node_ctrl::set_rx_streamer(bool active, const size_t port) // This only enables 1:1 (if output 1 is enabled, enable what's connected to input 1) if (list_upstream_nodes().count(port)) { source_node_ctrl::sptr this_upstream_block_ctrl = - boost::dynamic_pointer_cast<source_node_ctrl>(list_upstream_nodes().at(port).lock()); + boost::dynamic_pointer_cast<source_node_ctrl>( + list_upstream_nodes().at(port).lock()); if (this_upstream_block_ctrl) { - this_upstream_block_ctrl->set_rx_streamer( - active, - get_upstream_port(port) - ); + this_upstream_block_ctrl->set_rx_streamer(active, get_upstream_port(port)); } } @@ -56,25 +53,23 @@ void source_node_ctrl::set_rx_streamer(bool active, const size_t port) } size_t source_node_ctrl::_request_output_port( - const size_t suggested_port, - const uhd::device_addr_t & -) const { + const size_t suggested_port, const uhd::device_addr_t&) const +{ return utils::node_map_find_first_free(_downstream_nodes, suggested_port); } void source_node_ctrl::_register_downstream_node( - node_ctrl_base::sptr downstream_node, - size_t port -) { + node_ctrl_base::sptr downstream_node, size_t port) +{ // Do all the checks: if (port == ANY_PORT) { - throw uhd::type_error(str( - boost::format("[%s] Invalid output port number (ANY).") - % unique_id() - )); + throw uhd::type_error( + str(boost::format("[%s] Invalid output port number (ANY).") % unique_id())); } if (_downstream_nodes.count(port) and not _downstream_nodes[port].expired()) { - throw uhd::runtime_error(str(boost::format("On node %s, output port %d is already connected.") % unique_id() % port)); + throw uhd::runtime_error( + str(boost::format("On node %s, output port %d is already connected.") + % unique_id() % port)); } if (not boost::dynamic_pointer_cast<sink_node_ctrl>(downstream_node)) { throw uhd::type_error("Attempting to register a non-sink block as downstream."); @@ -83,4 +78,3 @@ void source_node_ctrl::_register_downstream_node( _downstream_nodes[port] = boost::weak_ptr<node_ctrl_base>(downstream_node); } - diff --git a/host/lib/rfnoc/stream_sig.cpp b/host/lib/rfnoc/stream_sig.cpp index af8a2169b..55d1cb005 100644 --- a/host/lib/rfnoc/stream_sig.cpp +++ b/host/lib/rfnoc/stream_sig.cpp @@ -5,17 +5,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/stream_sig.hpp> #include <uhd/convert.hpp> +#include <uhd/rfnoc/stream_sig.hpp> #include <boost/format.hpp> using namespace uhd::rfnoc; -stream_sig_t::stream_sig_t() : - item_type(""), - vlen(0), - packet_size(0), - is_bursty(false) +stream_sig_t::stream_sig_t() : item_type(""), vlen(0), packet_size(0), is_bursty(false) { // nop } @@ -23,19 +19,13 @@ stream_sig_t::stream_sig_t() : std::string stream_sig_t::to_string() { return str( - boost::format( - "%s,vlen=%d,packet_size=%d" - ) % item_type % vlen % packet_size - ); + boost::format("%s,vlen=%d,packet_size=%d") % item_type % vlen % packet_size); } std::string stream_sig_t::to_pp_string() { - return str( - boost::format( - "Data type: %s | Vector Length: %d | Packet size: %d" - ) % item_type % vlen % packet_size - ); + return str(boost::format("Data type: %s | Vector Length: %d | Packet size: %d") + % item_type % vlen % packet_size); } size_t stream_sig_t::get_bytes_per_item() const @@ -47,10 +37,11 @@ size_t stream_sig_t::get_bytes_per_item() const return uhd::convert::get_bytes_per_item(item_type); } -bool stream_sig_t::is_compatible(const stream_sig_t &output_sig, const stream_sig_t &input_sig) +bool stream_sig_t::is_compatible( + const stream_sig_t& output_sig, const stream_sig_t& input_sig) { /// Item types: - if (not (input_sig.item_type.empty() or output_sig.item_type.empty()) + if (not(input_sig.item_type.empty() or output_sig.item_type.empty()) and input_sig.item_type != output_sig.item_type) { return false; } diff --git a/host/lib/rfnoc/tick_node_ctrl.cpp b/host/lib/rfnoc/tick_node_ctrl.cpp index f8e422a51..84edd92db 100644 --- a/host/lib/rfnoc/tick_node_ctrl.cpp +++ b/host/lib/rfnoc/tick_node_ctrl.cpp @@ -12,8 +12,8 @@ using namespace uhd::rfnoc; const double tick_node_ctrl::RATE_UNDEFINED = 0; double tick_node_ctrl::get_tick_rate( - const std::set< node_ctrl_base::sptr > &_explored_nodes -) { + const std::set<node_ctrl_base::sptr>& _explored_nodes) +{ // First, see if we've implemented _get_tick_rate() { double my_tick_rate = _get_tick_rate(); @@ -24,20 +24,20 @@ double tick_node_ctrl::get_tick_rate( // If not, we ask all our neighbours for the tick rate. // This will fail if we get different values. - std::set< node_ctrl_base::sptr > explored_nodes(_explored_nodes); + std::set<node_ctrl_base::sptr> explored_nodes(_explored_nodes); explored_nodes.insert(shared_from_this()); // Here, we need all up- and downstream nodes - std::vector< sptr > neighbouring_tick_nodes = find_downstream_node<tick_node_ctrl>(true); + std::vector<sptr> neighbouring_tick_nodes = + find_downstream_node<tick_node_ctrl>(true); { - std::vector< sptr > upstream_neighbouring_tick_nodes = find_upstream_node<tick_node_ctrl>(true); - neighbouring_tick_nodes.insert( - neighbouring_tick_nodes.end(), - upstream_neighbouring_tick_nodes.begin(), - upstream_neighbouring_tick_nodes.end() - ); + std::vector<sptr> upstream_neighbouring_tick_nodes = + find_upstream_node<tick_node_ctrl>(true); + neighbouring_tick_nodes.insert(neighbouring_tick_nodes.end(), + upstream_neighbouring_tick_nodes.begin(), + upstream_neighbouring_tick_nodes.end()); } // neighbouring_tick_nodes is now initialized double ret_val = RATE_UNDEFINED; - for(const sptr &node: neighbouring_tick_nodes) { + for (const sptr& node : neighbouring_tick_nodes) { if (_explored_nodes.count(node)) { continue; } @@ -47,19 +47,17 @@ double tick_node_ctrl::get_tick_rate( } if (ret_val == RATE_UNDEFINED) { ret_val = tick_rate; - // TODO: Remember name of this node so we can make the throw message more descriptive. + // TODO: Remember name of this node so we can make the throw message more + // descriptive. continue; } if (tick_rate != ret_val) { - throw uhd::runtime_error( - str( - // TODO add node names - boost::format("Conflicting tick rates: One neighbouring block specifies %d MHz, another %d MHz.") - % tick_rate % ret_val - ) - ); + throw uhd::runtime_error(str( + // TODO add node names + boost::format("Conflicting tick rates: One neighbouring block specifies " + "%d MHz, another %d MHz.") + % tick_rate % ret_val)); } } return ret_val; } - diff --git a/host/lib/rfnoc/tx_stream_terminator.cpp b/host/lib/rfnoc/tx_stream_terminator.cpp index 14e800a1c..fa4148fbb 100644 --- a/host/lib/rfnoc/tx_stream_terminator.cpp +++ b/host/lib/rfnoc/tx_stream_terminator.cpp @@ -13,10 +13,10 @@ using namespace uhd::rfnoc; size_t tx_stream_terminator::_count = 0; -tx_stream_terminator::tx_stream_terminator() : - _term_index(_count), - _samp_rate(rate_node_ctrl::RATE_UNDEFINED), - _tick_rate(tick_node_ctrl::RATE_UNDEFINED) +tx_stream_terminator::tx_stream_terminator() + : _term_index(_count) + , _samp_rate(rate_node_ctrl::RATE_UNDEFINED) + , _tick_rate(tick_node_ctrl::RATE_UNDEFINED) { _count++; } @@ -35,23 +35,19 @@ void tx_stream_terminator::set_tx_streamer(bool active, const size_t /* port */) { // TODO this is identical to sink_node_ctrl::set_tx_streamer() -> factor out UHD_RFNOC_BLOCK_TRACE() << "tx_stream_terminator::set_tx_streamer() " << active; - for(const node_ctrl_base::node_map_pair_t downstream_node: _downstream_nodes) { + for (const node_ctrl_base::node_map_pair_t downstream_node : _downstream_nodes) { sink_node_ctrl::sptr curr_downstream_block_ctrl = boost::dynamic_pointer_cast<sink_node_ctrl>(downstream_node.second.lock()); if (curr_downstream_block_ctrl) { curr_downstream_block_ctrl->set_tx_streamer( - active, - get_downstream_port(downstream_node.first) - ); + active, get_downstream_port(downstream_node.first)); } _tx_streamer_active[downstream_node.first] = active; } - } tx_stream_terminator::~tx_stream_terminator() { - UHD_RFNOC_BLOCK_TRACE() << "tx_stream_terminator::~tx_stream_terminator() " ; + UHD_RFNOC_BLOCK_TRACE() << "tx_stream_terminator::~tx_stream_terminator() "; set_tx_streamer(false, 0); } - diff --git a/host/lib/rfnoc/wb_iface_adapter.cpp b/host/lib/rfnoc/wb_iface_adapter.cpp index 64b41d6d2..d035ce881 100644 --- a/host/lib/rfnoc/wb_iface_adapter.cpp +++ b/host/lib/rfnoc/wb_iface_adapter.cpp @@ -5,20 +5,19 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhdlib/rfnoc/wb_iface_adapter.hpp> #include <uhd/rfnoc/constants.hpp> +#include <uhdlib/rfnoc/wb_iface_adapter.hpp> using namespace uhd::rfnoc; -wb_iface_adapter::wb_iface_adapter( - ctrl_iface::sptr iface, - const gettickrate_type & gettickrate_functor_, - const settime_type & settime_functor_, - const gettime_type & gettime_functor_ -) : _iface(iface) - , gettickrate_functor(gettickrate_functor_) - , settime_functor(settime_functor_) - , gettime_functor(gettime_functor_) +wb_iface_adapter::wb_iface_adapter(ctrl_iface::sptr iface, + const gettickrate_type& gettickrate_functor_, + const settime_type& settime_functor_, + const gettime_type& gettime_functor_) + : _iface(iface) + , gettickrate_functor(gettickrate_functor_) + , settime_functor(settime_functor_) + , gettime_functor(gettime_functor_) { // nop } @@ -32,9 +31,8 @@ void wb_iface_adapter::poke32(const wb_addr_type addr, const uint32_t data) uint32_t wb_iface_adapter::peek32(const wb_addr_type addr) { const uint64_t reg_value = peek64(addr); - return ((addr/4) & 0x1) ? - uint32_t(reg_value >> 32) : - uint32_t(reg_value & 0xffffffff); + return ((addr / 4) & 0x1) ? uint32_t(reg_value >> 32) + : uint32_t(reg_value & 0xffffffff); } uint64_t wb_iface_adapter::peek64(const wb_addr_type addr) @@ -44,4 +42,3 @@ uint64_t wb_iface_adapter::peek64(const wb_addr_type addr) _iface->send_cmd_pkt(SR_READBACK_ADDR, addr / 8, false, timestamp); return _iface->send_cmd_pkt(SR_READBACK, SR_READBACK_REG_USER, true, timestamp); } - diff --git a/host/lib/rfnoc/window_block_ctrl_impl.cpp b/host/lib/rfnoc/window_block_ctrl_impl.cpp index 74ebd146d..c1a814706 100644 --- a/host/lib/rfnoc/window_block_ctrl_impl.cpp +++ b/host/lib/rfnoc/window_block_ctrl_impl.cpp @@ -4,8 +4,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include <uhd/rfnoc/window_block_ctrl.hpp> #include <uhd/convert.hpp> +#include <uhd/rfnoc/window_block_ctrl.hpp> #include <uhd/utils/log.hpp> using namespace uhd::rfnoc; @@ -22,21 +22,20 @@ public: << "window_block::window_block() max_len ==" << _max_len << std::endl; UHD_ASSERT_THROW(_max_len); - // TODO we need a coercer to check that spp on the prop tree doesn't get set to anything invalid + // TODO we need a coercer to check that spp on the prop tree doesn't get set to + // anything invalid _set_default_window(std::min<size_t>(get_arg<int>("spp"), _max_len)); } //! Set window coefficients and length - void set_window(const std::vector<int> &coeffs) + void set_window(const std::vector<int>& coeffs) { - UHD_LOGGER_TRACE(unique_id()) - << "window_block::set_window()" << std::endl; + UHD_LOGGER_TRACE(unique_id()) << "window_block::set_window()" << std::endl; if (coeffs.size() > _max_len) { - throw uhd::value_error(str( - boost::format("window_block::set_window(): Too many window " - "coefficients! Provided %d, window allows up to %d.\n") - % coeffs.size() % _max_len - )); + throw uhd::value_error( + str(boost::format("window_block::set_window(): Too many window " + "coefficients! Provided %d, window allows up to %d.\n") + % coeffs.size() % _max_len)); } size_t window_len = coeffs.size(); @@ -46,10 +45,11 @@ public: std::vector<uint32_t> coeffs_; for (size_t i = 0; i < window_len - 1; i++) { if (coeffs[i] > 32767 || coeffs[i] < -32768) { - throw uhd::value_error(str( - boost::format("window_block::set_window(): Coefficient %d " - "(index %d) outside coefficient range [-32768,32767].\n") - % coeffs[i] % i)); + throw uhd::value_error( + str(boost::format( + "window_block::set_window(): Coefficient %d " + "(index %d) outside coefficient range [-32768,32767].\n") + % coeffs[i] % i)); } coeffs_.push_back(coeffs[i]); } @@ -85,8 +85,9 @@ private: size_t _max_len; //! Default is a rectangular window - void _set_default_window(size_t window_len) { - std::vector<int> default_coeffs(window_len, (1 << 15)-1); + void _set_default_window(size_t window_len) + { + std::vector<int> default_coeffs(window_len, (1 << 15) - 1); set_window(default_coeffs); } }; |