From 05c2b1b544b76babbdb0210ae6a8d5de19e247bb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Feb 2011 00:05:30 -0800 Subject: udp: simplfy zero copy asio overhead with less shared_from_this, and timed waits when not needed --- host/include/uhd/transport/bounded_buffer.hpp | 9 ++++++++- host/include/uhd/transport/bounded_buffer.ipp | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index aca93b071..33ded8cfd 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -65,6 +65,13 @@ namespace uhd{ namespace transport{ */ virtual bool push_with_timed_wait(const elem_type &elem, double timeout) = 0; + /*! + * Pop an element from the bounded_buffer immediately. + * \param elem the element reference pop to + * \return false when the bounded_buffer is empty + */ + virtual bool pop_with_haste(elem_type &elem) = 0; + /*! * Pop an element from the bounded_buffer. * Wait until the bounded_buffer becomes non-empty. diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp index 4fbe3f085..7bf182ee3 100644 --- a/host/include/uhd/transport/bounded_buffer.ipp +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -72,6 +72,15 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ return true; } + UHD_INLINE bool pop_with_haste(elem_type &elem){ + boost::mutex::scoped_lock lock(_mutex); + if(_buffer.empty()) return false; + elem = this->pop_back(); + lock.unlock(); + _full_cond.notify_one(); + return true; + } + UHD_INLINE void pop_with_wait(elem_type &elem){ boost::mutex::scoped_lock lock(_mutex); _empty_cond.wait(lock, _not_empty_fcn); -- cgit v1.2.3 From 5d10aa397f044ea6781b4977c14171abfb4a727d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 5 Feb 2011 12:37:20 -0800 Subject: uhd: change bounded_buffer implementation and code using it The bounded buffer now uses the detail idiom to hide implementation to inline better. The whole sptr/make idiom was removed from bounded buffer to just construct directly. The code using bounded buffer was changed for the new api: replaces access operators and calls to the factory function. --- host/include/uhd/transport/bounded_buffer.hpp | 43 ++++++++++++++++----------- host/include/uhd/transport/bounded_buffer.ipp | 30 +++++-------------- host/lib/transport/gen_vrt_if_packet.py | 2 +- host/lib/transport/libusb1_zero_copy.cpp | 15 +++++----- host/lib/transport/udp_zero_copy_asio.cpp | 32 ++++++++++---------- host/lib/usrp/usrp1/soft_time_ctrl.cpp | 8 ++--- host/lib/usrp/usrp2/io_impl.cpp | 8 ++--- host/lib/usrp/usrp_e100/io_impl.cpp | 19 ++++++------ host/tests/buffer_test.cpp | 36 +++++++++++----------- 9 files changed, 92 insertions(+), 101 deletions(-) mode change 100755 => 100644 host/lib/transport/gen_vrt_if_packet.py (limited to 'host/include') diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index 33ded8cfd..412d73f17 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -18,8 +18,7 @@ #ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP #define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP -#include -#include +#include //detail namespace uhd{ namespace transport{ @@ -32,13 +31,16 @@ namespace uhd{ namespace transport{ */ template class bounded_buffer{ public: - typedef boost::shared_ptr > sptr; /*! - * Make a new bounded buffer object. + * Create a new bounded buffer object. * \param capacity the bounded_buffer capacity */ - static sptr make(size_t capacity); + bounded_buffer(size_t capacity): + _detail(capacity) + { + /* NOP */ + } /*! * Push a new element into the bounded buffer. @@ -47,14 +49,18 @@ namespace uhd{ namespace transport{ * \param elem the new element to push * \return true if the element fit without popping for space */ - virtual bool push_with_pop_on_full(const elem_type &elem) = 0; + bool push_with_pop_on_full(const elem_type &elem){ + return _detail.push_with_pop_on_full(elem); + } /*! * Push a new element into the bounded_buffer. * Wait until the bounded_buffer becomes non-full. * \param elem the new element to push */ - virtual void push_with_wait(const elem_type &elem) = 0; + void push_with_wait(const elem_type &elem){ + return _detail.push_with_wait(elem); + } /*! * Push a new element into the bounded_buffer. @@ -63,21 +69,27 @@ namespace uhd{ namespace transport{ * \param timeout the timeout in seconds * \return false when the operation times out */ - virtual bool push_with_timed_wait(const elem_type &elem, double timeout) = 0; + bool push_with_timed_wait(const elem_type &elem, double timeout){ + return _detail.push_with_timed_wait(elem, timeout); + } /*! * Pop an element from the bounded_buffer immediately. * \param elem the element reference pop to * \return false when the bounded_buffer is empty */ - virtual bool pop_with_haste(elem_type &elem) = 0; + bool pop_with_haste(elem_type &elem){ + return _detail.pop_with_haste(elem); + } /*! * Pop an element from the bounded_buffer. * Wait until the bounded_buffer becomes non-empty. * \param elem the element reference pop to */ - virtual void pop_with_wait(elem_type &elem) = 0; + void pop_with_wait(elem_type &elem){ + return _detail.pop_with_wait(elem); + } /*! * Pop an element from the bounded_buffer. @@ -86,16 +98,13 @@ namespace uhd{ namespace transport{ * \param timeout the timeout in seconds * \return false when the operation times out */ - virtual bool pop_with_timed_wait(elem_type &elem, double timeout) = 0; + bool pop_with_timed_wait(elem_type &elem, double timeout){ + return _detail.pop_with_timed_wait(elem, timeout); + } - /*! - * Clear all elements from the bounded_buffer. - */ - virtual void clear(void) = 0; + private: bounded_buffer_detail _detail; }; }} //namespace -#include - #endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP */ diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp index 7bf182ee3..466c7a306 100644 --- a/host/include/uhd/transport/bounded_buffer.ipp +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -18,22 +18,24 @@ #ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP #define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP +#include #include #include #include #include #include -#include namespace uhd{ namespace transport{ namespace{ /*anon*/ - template - class bounded_buffer_impl : public bounded_buffer{ + template class bounded_buffer_detail{ public: - bounded_buffer_impl(size_t capacity) : _buffer(capacity){ - _not_full_fcn = boost::bind(&bounded_buffer_impl::not_full, this); - _not_empty_fcn = boost::bind(&bounded_buffer_impl::not_empty, this); + bounded_buffer_detail(size_t capacity): + _buffer(capacity), + _not_full_fcn(boost::bind(&bounded_buffer_detail::not_full, this)), + _not_empty_fcn(boost::bind(&bounded_buffer_detail::not_empty, this)) + { + /* NOP */ } UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ @@ -100,13 +102,6 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ return true; } - UHD_INLINE void clear(void){ - boost::mutex::scoped_lock lock(_mutex); - while (not_empty()) this->pop_back(); - lock.unlock(); - _full_cond.notify_one(); - } - private: boost::mutex _mutex; boost::condition _empty_cond, _full_cond; @@ -137,13 +132,4 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ }; }}} //namespace -namespace uhd{ namespace transport{ - - template typename bounded_buffer::sptr - bounded_buffer::make(size_t capacity){ - return typename bounded_buffer::sptr(new bounded_buffer_impl(capacity)); - } - -}} //namespace - #endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP */ diff --git a/host/lib/transport/gen_vrt_if_packet.py b/host/lib/transport/gen_vrt_if_packet.py old mode 100755 new mode 100644 index bf740ffa9..3ba562d68 --- a/host/lib/transport/gen_vrt_if_packet.py +++ b/host/lib/transport/gen_vrt_if_packet.py @@ -205,7 +205,7 @@ void vrt::if_hdr_unpack_$(suffix)( if_packet_info.has_tsf = true; if_packet_info.tsf = boost::uint64_t($(XE_MACRO)(packet_buff[$num_header_words])) << 32; #set $num_header_words += 1 - if_packet_info.tsf |= boost::uint64_t($(XE_MACRO)(packet_buff[$num_header_words])) << 0; + if_packet_info.tsf |= $(XE_MACRO)(packet_buff[$num_header_words]); #set $num_header_words += 1 #else if_packet_info.has_tsf = false; diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 311a8953b..d4c82617c 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -99,8 +99,7 @@ private: bool _input; //! hold a bounded buffer of completed transfers - typedef bounded_buffer lut_buff_type; - lut_buff_type::sptr _completed_list; + bounded_buffer _completed_list; //! a list of all transfer structs we allocated std::vector _all_luts; @@ -134,7 +133,7 @@ static void callback(libusb_transfer *lut){ * \param pointer to libusb_transfer */ void usb_endpoint::callback_handle_transfer(libusb_transfer *lut){ - _completed_list->push_with_wait(lut); + _completed_list.push_with_wait(lut); } @@ -153,9 +152,9 @@ usb_endpoint::usb_endpoint( ): _handle(handle), _endpoint(endpoint), - _input(input) + _input(input), + _completed_list(num_transfers) { - _completed_list = lut_buff_type::make(num_transfers); _buffer_pool = buffer_pool::make(num_transfers, transfer_size); for (size_t i = 0; i < num_transfers; i++){ _all_luts.push_back(allocate_transfer(_buffer_pool->at(i), transfer_size)); @@ -163,7 +162,7 @@ usb_endpoint::usb_endpoint( //input luts are immediately submitted to be filled //output luts go into the completed list as free buffers if (_input) this->submit(_all_luts.back()); - else _completed_list->push_with_wait(_all_luts.back()); + else _completed_list.push_with_wait(_all_luts.back()); } } @@ -272,8 +271,8 @@ void usb_endpoint::print_transfer_status(libusb_transfer *lut){ libusb_transfer *usb_endpoint::get_lut_with_wait(double timeout){ boost::this_thread::disable_interruption di; //disable because the wait can throw - libusb_transfer *lut; - if (_completed_list->pop_with_timed_wait(lut, timeout)) return lut; + libusb_transfer *lut = NULL; + if (_completed_list.pop_with_timed_wait(lut, timeout)) return lut; return NULL; } diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index f083b97d8..0f16e7d14 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -72,6 +72,9 @@ public: _num_recv_frames(size_t(hints.cast("num_recv_frames", DEFAULT_NUM_FRAMES))), _send_frame_size(size_t(hints.cast("send_frame_size", udp_simple::mtu))), _num_send_frames(size_t(hints.cast("num_send_frames", DEFAULT_NUM_FRAMES))), + _recv_buffer_pool(buffer_pool::make(_num_recv_frames, _recv_frame_size)), + _send_buffer_pool(buffer_pool::make(_num_send_frames, _send_frame_size)), + _pending_recv_buffs(_num_recv_frames), _pending_send_buffs(_num_send_frames), _concurrency_hint(hints.cast("concurrency_hint", CONCURRENCY_HINT)), _io_service(_concurrency_hint) { @@ -96,17 +99,13 @@ public: } void init(void){ - //allocate all recv frames and release them to begin xfers - _pending_recv_buffs = pending_buffs_type::make(_num_recv_frames); - _recv_buffer_pool = buffer_pool::make(_num_recv_frames, _recv_frame_size); - for (size_t i = 0; i < _num_recv_frames; i++){ + //release recv frames for use + for (size_t i = 0; i < get_num_recv_frames(); i++){ release(_recv_buffer_pool->at(i)); } - //allocate all send frames and push them into the fifo - _pending_send_buffs = pending_buffs_type::make(_num_send_frames); - _send_buffer_pool = buffer_pool::make(_num_send_frames, _send_frame_size); - for (size_t i = 0; i < _num_send_frames; i++){ + //push send frames into the fifo + for (size_t i = 0; i < get_num_send_frames(); i++){ handle_send(_send_buffer_pool->at(i)); } @@ -138,7 +137,7 @@ public: //! handle a recv callback -> push the filled memory into the fifo UHD_INLINE void handle_recv(void *mem, size_t len){ - _pending_recv_buffs->push_with_pop_on_full(boost::asio::buffer(mem, len)); + _pending_recv_buffs.push_with_pop_on_full(boost::asio::buffer(mem, len)); } //////////////////////////////////////////////////////////////////// @@ -148,7 +147,7 @@ public: managed_recv_buffer::sptr get_recv_buff(double timeout){ boost::this_thread::disable_interruption di; //disable because the wait can throw asio::mutable_buffer buff; - if (_pending_recv_buffs->pop_with_timed_wait(buff, timeout)){ + if (_pending_recv_buffs.pop_with_timed_wait(buff, timeout)){ return managed_recv_buffer::make_safe( buff, boost::bind( &udp_zero_copy_asio_impl::release, this, @@ -191,7 +190,7 @@ public: //if the condition is true, call receive and return the managed buffer if ( ::select(_sock_fd+1, &rset, NULL, NULL, &tv) > 0 - and _pending_recv_buffs->pop_with_haste(buff) + and _pending_recv_buffs.pop_with_haste(buff) ){ return managed_recv_buffer::make_safe( asio::buffer( @@ -220,7 +219,7 @@ public: //! handle a send callback -> push the emptied memory into the fifo UHD_INLINE void handle_send(void *mem){ - _pending_send_buffs->push_with_pop_on_full(boost::asio::buffer(mem, this->get_send_frame_size())); + _pending_send_buffs.push_with_pop_on_full(boost::asio::buffer(mem, this->get_send_frame_size())); } //////////////////////////////////////////////////////////////////// @@ -230,7 +229,7 @@ public: managed_send_buffer::sptr get_send_buff(double timeout){ boost::this_thread::disable_interruption di; //disable because the wait can throw asio::mutable_buffer buff; - if (_pending_send_buffs->pop_with_timed_wait(buff, timeout)){ + if (_pending_send_buffs.pop_with_timed_wait(buff, timeout)){ return managed_send_buffer::make_safe( buff, boost::bind( &udp_zero_copy_asio_impl::commit, this, @@ -257,7 +256,7 @@ public: //////////////////////////////////////////////////////////////////// managed_send_buffer::sptr get_send_buff(double){ asio::mutable_buffer buff; - if (_pending_send_buffs->pop_with_haste(buff)){ + if (_pending_send_buffs.pop_with_haste(buff)){ return managed_send_buffer::make_safe( buff, boost::bind( &udp_zero_copy_asio_impl::commit, this, @@ -283,11 +282,10 @@ public: private: //memory management -> buffers and fifos boost::thread_group _thread_group; - buffer_pool::sptr _send_buffer_pool, _recv_buffer_pool; - typedef bounded_buffer pending_buffs_type; - pending_buffs_type::sptr _pending_recv_buffs, _pending_send_buffs; const size_t _recv_frame_size, _num_recv_frames; const size_t _send_frame_size, _num_send_frames; + buffer_pool::sptr _recv_buffer_pool, _send_buffer_pool; + bounded_buffer _pending_recv_buffs, _pending_send_buffs; //asio guts -> socket and service size_t _concurrency_hint; diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index 246df93eb..e1b671811 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -39,7 +39,7 @@ public: soft_time_ctrl_impl(const cb_fcn_type &stream_on_off): _nsamps_remaining(0), _stream_mode(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS), - _cmd_queue(bounded_buffer::make(2)), + _cmd_queue(2), _stream_on_off(stream_on_off) { //synchronously spawn a new thread @@ -112,7 +112,7 @@ public: } void issue_stream_cmd(const stream_cmd_t &cmd){ - _cmd_queue->push_with_wait(cmd); + _cmd_queue.push_with_wait(cmd); } void stream_on_off(bool enb){ @@ -180,7 +180,7 @@ public: try{ boost::any cmd; while (true){ - _cmd_queue->pop_with_wait(cmd); + _cmd_queue.pop_with_wait(cmd); recv_cmd_handle_cmd(boost::any_cast(cmd)); } } catch(const boost::thread_interrupted &){} @@ -191,7 +191,7 @@ private: size_t _nsamps_remaining; stream_cmd_t::stream_mode_t _stream_mode; time_spec_t _time_offset; - bounded_buffer::sptr _cmd_queue; + bounded_buffer _cmd_queue; const cb_fcn_type _stream_on_off; boost::thread_group _thread_group; }; diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 4d8074e70..36012bcfb 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -114,7 +114,7 @@ struct usrp2_impl::io_impl{ xports(xports), packet_handler_recv_state(xports.size()), packet_handler_send_state(xports.size()), - async_msg_fifo(bounded_buffer::make(100/*messages deep*/)) + async_msg_fifo(100/*messages deep*/) { for (size_t i = 0; i < xports.size(); i++){ fc_mons.push_back(flow_control_monitor::sptr( @@ -177,7 +177,7 @@ struct usrp2_impl::io_impl{ void recv_pirate_loop(zero_copy_if::sptr, usrp2_mboard_impl::sptr, size_t); boost::thread_group recv_pirate_crew; bool recv_pirate_crew_raiding; - bounded_buffer::sptr async_msg_fifo; + bounded_buffer async_msg_fifo; boost::mutex spawn_mutex; }; @@ -230,7 +230,7 @@ void usrp2_impl::io_impl::recv_pirate_loop( //print the famous U, and push the metadata into the message queue if (metadata.event_code & underflow_flags) std::cerr << "U" << std::flush; //else std::cout << "metadata.event_code " << metadata.event_code << std::endl; - async_msg_fifo->push_with_pop_on_full(metadata); + async_msg_fifo.push_with_pop_on_full(metadata); } else{ //TODO unknown received packet, may want to print error... @@ -276,7 +276,7 @@ bool usrp2_impl::recv_async_msg( async_metadata_t &async_metadata, double timeout ){ boost::this_thread::disable_interruption di; //disable because the wait can throw - return _io_impl->async_msg_fifo->pop_with_timed_wait(async_metadata, timeout); + return _io_impl->async_msg_fifo.pop_with_timed_wait(async_metadata, timeout); } /*********************************************************************** diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index 2388482c7..c8b9e03d9 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -54,8 +54,8 @@ struct usrp_e100_impl::io_impl{ bool continuous_streaming; io_impl(usrp_e100_iface::sptr iface): data_xport(usrp_e100_make_mmap_zero_copy(iface)), - recv_pirate_booty(recv_booty_type::make(data_xport->get_num_recv_frames())), - async_msg_fifo(bounded_buffer::make(100/*messages deep*/)) + recv_pirate_booty(data_xport->get_num_recv_frames()), + async_msg_fifo(100/*messages deep*/) { /* NOP */ } @@ -69,14 +69,13 @@ struct usrp_e100_impl::io_impl{ bool get_recv_buffs(vrt_packet_handler::managed_recv_buffs_t &buffs, double timeout){ UHD_ASSERT_THROW(buffs.size() == 1); boost::this_thread::disable_interruption di; //disable because the wait can throw - return recv_pirate_booty->pop_with_timed_wait(buffs.front(), timeout); + return recv_pirate_booty.pop_with_timed_wait(buffs.front(), timeout); } //a pirate's life is the life for me! void recv_pirate_loop(usrp_e100_clock_ctrl::sptr); - typedef bounded_buffer recv_booty_type; - recv_booty_type::sptr recv_pirate_booty; - bounded_buffer::sptr async_msg_fifo; + bounded_buffer recv_pirate_booty; + bounded_buffer async_msg_fifo; boost::thread_group recv_pirate_crew; bool recv_pirate_crew_raiding; }; @@ -124,12 +123,12 @@ void usrp_e100_impl::io_impl::recv_pirate_loop(usrp_e100_clock_ctrl::sptr clock_ //print the famous U, and push the metadata into the message queue if (metadata.event_code & underflow_flags) std::cerr << "U" << std::flush; - async_msg_fifo->push_with_pop_on_full(metadata); + async_msg_fifo.push_with_pop_on_full(metadata); continue; } //same number of frames as the data transport -> always immediate - recv_pirate_booty->push_with_wait(buff); + recv_pirate_booty.push_with_wait(buff); }catch(const std::exception &e){ std::cerr << "Error (usrp-e recv pirate loop): " << e.what() << std::endl; @@ -266,5 +265,5 @@ bool usrp_e100_impl::recv_async_msg( async_metadata_t &async_metadata, double timeout ){ boost::this_thread::disable_interruption di; //disable because the wait can throw - return _io_impl->async_msg_fifo->pop_with_timed_wait(async_metadata, timeout); + return _io_impl->async_msg_fifo.pop_with_timed_wait(async_metadata, timeout); } diff --git a/host/tests/buffer_test.cpp b/host/tests/buffer_test.cpp index e7bc88699..23b52a9bf 100644 --- a/host/tests/buffer_test.cpp +++ b/host/tests/buffer_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -25,40 +25,40 @@ using namespace uhd::transport; static const double timeout = 0.01/*secs*/; BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_timed_wait){ - bounded_buffer::sptr bb(bounded_buffer::make(3)); + bounded_buffer bb(3); //push elements, check for timeout - BOOST_CHECK(bb->push_with_timed_wait(0, timeout)); - BOOST_CHECK(bb->push_with_timed_wait(1, timeout)); - BOOST_CHECK(bb->push_with_timed_wait(2, timeout)); - BOOST_CHECK(not bb->push_with_timed_wait(3, timeout)); + BOOST_CHECK(bb.push_with_timed_wait(0, timeout)); + BOOST_CHECK(bb.push_with_timed_wait(1, timeout)); + BOOST_CHECK(bb.push_with_timed_wait(2, timeout)); + BOOST_CHECK(not bb.push_with_timed_wait(3, timeout)); int val; //pop elements, check for timeout and check values - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 0); - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 1); - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 2); - BOOST_CHECK(not bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(not bb.pop_with_timed_wait(val, timeout)); } BOOST_AUTO_TEST_CASE(test_bounded_buffer_with_pop_on_full){ - bounded_buffer::sptr bb(bounded_buffer::make(3)); + bounded_buffer bb(3); //push elements, check for timeout - BOOST_CHECK(bb->push_with_pop_on_full(0)); - BOOST_CHECK(bb->push_with_pop_on_full(1)); - BOOST_CHECK(bb->push_with_pop_on_full(2)); - BOOST_CHECK(not bb->push_with_pop_on_full(3)); + BOOST_CHECK(bb.push_with_pop_on_full(0)); + BOOST_CHECK(bb.push_with_pop_on_full(1)); + BOOST_CHECK(bb.push_with_pop_on_full(2)); + BOOST_CHECK(not bb.push_with_pop_on_full(3)); int val; //pop elements, check for timeout and check values - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 1); - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 2); - BOOST_CHECK(bb->pop_with_timed_wait(val, timeout)); + BOOST_CHECK(bb.pop_with_timed_wait(val, timeout)); BOOST_CHECK_EQUAL(val, 3); } -- cgit v1.2.3 From ef351624eeb898e17662000a40b50076133118c7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 7 Feb 2011 12:32:12 -0800 Subject: uhd: replace asio buffer in make safe w/ memory and length, makes things simpler --- host/include/uhd/transport/zero_copy.hpp | 63 ++++++++++------------ host/lib/transport/libusb1_zero_copy.cpp | 4 +- host/lib/transport/udp_zero_copy_asio.cpp | 15 +++--- host/lib/transport/zero_copy.cpp | 40 ++++++++------ host/lib/usrp/usrp1/io_impl.cpp | 6 +-- .../usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp | 4 +- 6 files changed, 64 insertions(+), 68 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp index 7d8fb4b83..d5a536b27 100644 --- a/host/include/uhd/transport/zero_copy.hpp +++ b/host/include/uhd/transport/zero_copy.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,7 +19,6 @@ #define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP #include -#include #include #include #include @@ -40,13 +39,13 @@ namespace uhd{ namespace transport{ * Make a safe managed receive buffer: * A safe managed buffer ensures that release is called once, * either by the user or automatically upon deconstruction. - * \param buff a reference to the constant buffer + * \param buff a pointer into read-only memory + * \param size the length of the buffer in bytes * \param release_fcn callback to release the memory * \return a new managed receive buffer */ static sptr make_safe( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ); /*! @@ -56,29 +55,25 @@ namespace uhd{ namespace transport{ */ virtual void release(void) = 0; - /*! - * Get the size of the underlying buffer. - * \return the number of bytes - */ - inline size_t size(void) const{ - return boost::asio::buffer_size(this->get()); - } - /*! * Get a pointer to the underlying buffer. * \return a pointer into memory */ template inline T cast(void) const{ - return boost::asio::buffer_cast(this->get()); + return static_cast(this->get_buff()); } - private: /*! - * Get a reference to the internal const buffer. - * The buffer has a reference to memory and a size. - * \return a boost asio const buffer + * Get the size of the underlying buffer. + * \return the number of bytes */ - virtual const boost::asio::const_buffer &get(void) const = 0; + inline size_t size(void) const{ + return this->get_size(); + } + + private: + virtual const void *get_buff(void) const = 0; + virtual size_t get_size(void) const = 0; }; /*! @@ -96,13 +91,13 @@ namespace uhd{ namespace transport{ * A safe managed buffer ensures that commit is called once, * either by the user or automatically upon deconstruction. * In the later case, the deconstructor will call commit(0). - * \param buff a reference to the mutable buffer + * \param buff a pointer into writable memory + * \param size the length of the buffer in bytes * \param commit_fcn callback to commit the memory * \return a new managed send buffer */ static sptr make_safe( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ); /*! @@ -113,29 +108,25 @@ namespace uhd{ namespace transport{ */ virtual void commit(size_t num_bytes) = 0; - /*! - * Get the size of the underlying buffer. - * \return the number of bytes - */ - inline size_t size(void) const{ - return boost::asio::buffer_size(this->get()); - } - /*! * Get a pointer to the underlying buffer. * \return a pointer into memory */ template inline T cast(void) const{ - return boost::asio::buffer_cast(this->get()); + return static_cast(this->get_buff()); } - private: /*! - * Get a reference to the internal mutable buffer. - * The buffer has a reference to memory and a size. - * \return a boost asio mutable buffer + * Get the size of the underlying buffer. + * \return the number of bytes */ - virtual const boost::asio::mutable_buffer &get(void) const = 0; + inline size_t size(void) const{ + return this->get_size(); + } + + private: + virtual void *get_buff(void) const = 0; + virtual size_t get_size(void) const = 0; }; /*! diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 5ae6db39e..ca37f351f 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -398,7 +398,7 @@ managed_recv_buffer::sptr libusb_zero_copy_impl::get_recv_buff(double timeout){ } else { return managed_recv_buffer::make_safe( - boost::asio::const_buffer(lut->buffer, lut->actual_length), + lut->buffer, lut->actual_length, boost::bind(&libusb_zero_copy_impl::release, this, lut) ); } @@ -418,7 +418,7 @@ managed_send_buffer::sptr libusb_zero_copy_impl::get_send_buff(double timeout){ } else { return managed_send_buffer::make_safe( - boost::asio::mutable_buffer(lut->buffer, this->get_send_frame_size()), + lut->buffer, this->get_send_frame_size(), boost::bind(&libusb_zero_copy_impl::commit, this, lut, _1) ); } diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 0f16e7d14..90cd2a9ce 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -149,7 +149,8 @@ public: asio::mutable_buffer buff; if (_pending_recv_buffs.pop_with_timed_wait(buff, timeout)){ return managed_recv_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::release, this, asio::buffer_cast(buff) ) @@ -193,10 +194,8 @@ public: and _pending_recv_buffs.pop_with_haste(buff) ){ return managed_recv_buffer::make_safe( - asio::buffer( - boost::asio::buffer_cast(buff), - _socket->receive(asio::buffer(buff)) - ), + boost::asio::buffer_cast(buff), + _socket->receive(asio::buffer(buff)), boost::bind( &udp_zero_copy_asio_impl::release, this, asio::buffer_cast(buff) @@ -231,7 +230,8 @@ public: asio::mutable_buffer buff; if (_pending_send_buffs.pop_with_timed_wait(buff, timeout)){ return managed_send_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::commit, this, asio::buffer_cast(buff), _1 ) @@ -258,7 +258,8 @@ public: asio::mutable_buffer buff; if (_pending_send_buffs.pop_with_haste(buff)){ return managed_send_buffer::make_safe( - buff, boost::bind( + asio::buffer_cast(buff), + asio::buffer_size(buff), boost::bind( &udp_zero_copy_asio_impl::commit, this, asio::buffer_cast(buff), _1 ) diff --git a/host/lib/transport/zero_copy.cpp b/host/lib/transport/zero_copy.cpp index a5a864a04..b91eaae1d 100644 --- a/host/lib/transport/zero_copy.cpp +++ b/host/lib/transport/zero_copy.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,10 +29,9 @@ static void release_nop(void){ class safe_managed_receive_buffer : public managed_recv_buffer{ public: safe_managed_receive_buffer( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ): - _buff(buff), _release_fcn(release_fcn) + _buff(buff), _size(size), _release_fcn(release_fcn) { /* NOP */ } @@ -48,19 +47,23 @@ public: } private: - const boost::asio::const_buffer &get(void) const{ + const void *get_buff(void) const{ return _buff; } - const boost::asio::const_buffer _buff; + size_t get_size(void) const{ + return _size; + } + + const void *_buff; + size_t _size; release_fcn_t _release_fcn; }; managed_recv_buffer::sptr managed_recv_buffer::make_safe( - const boost::asio::const_buffer &buff, - const release_fcn_t &release_fcn + const void *buff, size_t size, const release_fcn_t &release_fcn ){ - return sptr(new safe_managed_receive_buffer(buff, release_fcn)); + return sptr(new safe_managed_receive_buffer(buff, size, release_fcn)); } /*********************************************************************** @@ -73,10 +76,9 @@ static void commit_nop(size_t){ class safe_managed_send_buffer : public managed_send_buffer{ public: safe_managed_send_buffer( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ): - _buff(buff), _commit_fcn(commit_fcn) + _buff(buff), _size(size), _commit_fcn(commit_fcn) { /* NOP */ } @@ -92,17 +94,21 @@ public: } private: - const boost::asio::mutable_buffer &get(void) const{ + void *get_buff(void) const{ return _buff; } - const boost::asio::mutable_buffer _buff; + size_t get_size(void) const{ + return _size; + } + + void *_buff; + size_t _size; commit_fcn_t _commit_fcn; }; safe_managed_send_buffer::sptr managed_send_buffer::make_safe( - const boost::asio::mutable_buffer &buff, - const commit_fcn_t &commit_fcn + void *buff, size_t size, const commit_fcn_t &commit_fcn ){ - return sptr(new safe_managed_send_buffer(buff, commit_fcn)); + return sptr(new safe_managed_send_buffer(buff, size, commit_fcn)); } diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 52a7c6650..7953447d1 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -159,10 +159,8 @@ bool usrp1_impl::io_impl::get_send_buffs( //calculate the buffer pointer and size given the offset //references to the buffers are held in the bound function buffs[0] = managed_send_buffer::make_safe( - boost::asio::buffer( - curr_buff->buff->cast() + curr_buff->offset, - curr_buff->buff->size() - curr_buff->offset - ), + curr_buff->buff->cast() + curr_buff->offset, + curr_buff->buff->size() - curr_buff->offset, boost::bind(&usrp1_impl::io_impl::commit_send_buff, this, curr_buff, next_buff, _1) ); diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp index c07e6e011..4e0137fdb 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp @@ -124,7 +124,7 @@ public: //return the managed buffer for this frame if (fp_verbose) std::cout << " make_recv_buff: " << info->len << std::endl; return managed_recv_buffer::make_safe( - boost::asio::const_buffer(mem, info->len), + mem, info->len, boost::bind(&usrp_e100_mmap_zero_copy_impl::release, this, info) ); } @@ -160,7 +160,7 @@ public: //return the managed buffer for this frame if (fp_verbose) std::cout << " make_send_buff: " << _frame_size << std::endl; return managed_send_buffer::make_safe( - boost::asio::mutable_buffer(mem, _frame_size), + mem, _frame_size, boost::bind(&usrp_e100_mmap_zero_copy_impl::commit, this, info, _1) ); } -- cgit v1.2.3 From fb7e8a09a58f4c08f70ba0e088710a0e011ea01d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 9 Feb 2011 19:01:28 -0800 Subject: uhd: replaced std::vector for buffer arguments in send/recv Created new type ref_vector for representing a vector of pointers. Can be created from std::vector or a pointer. Removes the convenience constrcutors for send/recv, its not needed. Removes malloc/free overhead when using send/recv with pointer. --- host/examples/test_async_messages.cpp | 8 ++-- host/examples/tx_waveforms.cpp | 2 +- host/include/uhd/CMakeLists.txt | 1 - host/include/uhd/device.hpp | 40 +++++------------ host/include/uhd/device.ipp | 55 ------------------------ host/include/uhd/types/CMakeLists.txt | 1 + host/include/uhd/types/ref_vector.hpp | 69 ++++++++++++++++++++++++++++++ host/lib/transport/vrt_packet_handler.hpp | 8 ++-- host/lib/usrp/usrp1/io_impl.cpp | 4 +- host/lib/usrp/usrp1/usrp1_impl.hpp | 4 +- host/lib/usrp/usrp2/io_impl.cpp | 4 +- host/lib/usrp/usrp2/usrp2_impl.hpp | 4 +- host/lib/usrp/usrp_e100/io_impl.cpp | 4 +- host/lib/usrp/usrp_e100/usrp_e100_impl.hpp | 6 +-- 14 files changed, 101 insertions(+), 109 deletions(-) delete mode 100644 host/include/uhd/device.ipp create mode 100644 host/include/uhd/types/ref_vector.hpp (limited to 'host/include') diff --git a/host/examples/test_async_messages.cpp b/host/examples/test_async_messages.cpp index 7f1094ee0..7f922ed35 100644 --- a/host/examples/test_async_messages.cpp +++ b/host/examples/test_async_messages.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -91,8 +91,7 @@ bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp){ md.end_of_burst = false; md.has_time_spec = false; - usrp->get_device()->send( - NULL, 0, md, + usrp->get_device()->send("", 0, md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); @@ -139,8 +138,7 @@ bool test_time_error_message(uhd::usrp::multi_usrp::sptr usrp){ usrp->set_time_now(uhd::time_spec_t(200.0)); //time at 200s - usrp->get_device()->send( - NULL, 0, md, + usrp->get_device()->send("", 0, md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp index dd18d3174..05d49a8b3 100644 --- a/host/examples/tx_waveforms.cpp +++ b/host/examples/tx_waveforms.cpp @@ -171,7 +171,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //send a mini EOB packet md.start_of_burst = false; md.end_of_burst = true; - usrp->get_device()->send(NULL, 0, md, + usrp->get_device()->send("", 0, md, uhd::io_type_t::COMPLEX_FLOAT32, uhd::device::SEND_MODE_FULL_BUFF ); diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index fee1270e9..b7a22cf0b 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,7 +25,6 @@ INSTALL(FILES config.hpp convert.hpp device.hpp - device.ipp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 992276928..50237472b 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -22,11 +22,11 @@ #include #include #include +#include #include #include #include #include -#include namespace uhd{ @@ -96,6 +96,12 @@ public: RECV_MODE_ONE_PACKET = 1 }; + //! Typedef for a pointer to a single, or a collection of send buffers + typedef ref_vector send_buffs_type; + + //! Typedef for a pointer to a single, or a collection of recv buffers + typedef ref_vector recv_buffs_type; + /*! * Send buffers containing IF data described by the metadata. * @@ -121,7 +127,7 @@ public: * \return the number of samples sent */ virtual size_t send( - const std::vector &buffs, + const send_buffs_type &buffs, size_t nsamps_per_buff, const tx_metadata_t &metadata, const io_type_t &io_type, @@ -129,18 +135,6 @@ public: double timeout = 0.1 ) = 0; - /*! - * Convenience wrapper for send that takes a single buffer. - */ - size_t send( - const void *buff, - size_t nsamps_per_buff, - const tx_metadata_t &metadata, - const io_type_t &io_type, - send_mode_t send_mode, - double timeout = 0.1 - ); - /*! * Receive buffers containing IF data described by the metadata. * @@ -173,7 +167,7 @@ public: * \return the number of samples received or 0 on error */ virtual size_t recv( - const std::vector &buffs, + const recv_buffs_type &buffs, size_t nsamps_per_buff, rx_metadata_t &metadata, const io_type_t &io_type, @@ -181,18 +175,6 @@ public: double timeout = 0.1 ) = 0; - /*! - * Convenience wrapper for recv that takes a single buffer. - */ - size_t recv( - void *buff, - size_t nsamps_per_buff, - rx_metadata_t &metadata, - const io_type_t &io_type, - recv_mode_t recv_mode, - double timeout = 0.1 - ); - /*! * Get the maximum number of samples per packet on send. * \return the number of samples @@ -219,6 +201,4 @@ public: } //namespace uhd -#include - #endif /* INCLUDED_UHD_DEVICE_HPP */ diff --git a/host/include/uhd/device.ipp b/host/include/uhd/device.ipp deleted file mode 100644 index e2e51ecd0..000000000 --- a/host/include/uhd/device.ipp +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#ifndef INCLUDED_UHD_DEVICE_IPP -#define INCLUDED_UHD_DEVICE_IPP - -namespace uhd{ - - UHD_INLINE size_t device::send( - const void *buff, - size_t nsamps_per_buff, - const tx_metadata_t &metadata, - const io_type_t &io_type, - send_mode_t send_mode, - double timeout - ){ - return this->send( - std::vector(1, buff), - nsamps_per_buff, metadata, - io_type, send_mode, timeout - ); - } - - UHD_INLINE size_t device::recv( - void *buff, - size_t nsamps_per_buff, - rx_metadata_t &metadata, - const io_type_t &io_type, - recv_mode_t recv_mode, - double timeout - ){ - return this->recv( - std::vector(1, buff), - nsamps_per_buff, metadata, - io_type, recv_mode, timeout - ); - } - -} //namespace uhd - -#endif /* INCLUDED_UHD_DEVICE_IPP */ diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 51be164aa..c856e5568 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES metadata.hpp otw_type.hpp ranges.hpp + ref_vector.hpp sensors.hpp serial.hpp stream_cmd.hpp diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp new file mode 100644 index 000000000..ef970802f --- /dev/null +++ b/host/include/uhd/types/ref_vector.hpp @@ -0,0 +1,69 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_REF_VECTOR_HPP +#define INCLUDED_UHD_TYPES_REF_VECTOR_HPP + +#include + +namespace uhd{ + +/*! + * Reference vector: + * - Provides a std::vector-like interface for an array. + * - Statically sized, and does not manage the memory. + */ +template class ref_vector{ +public: + //! Create a reference vector of length one from a pointer + template ref_vector(Ptr *ptr): + _mem(memp_t(&ptr)), _size(1) + { + /* NOP */ + } + + //! Create a reference vector from a std::vector container + template ref_vector(const Range &range): + _mem(memp_t(&range[0])), _size(range.size()) + { + /* NOP */ + } + + //! Create a reference vector from a memory pointer and size + ref_vector(T *mem, size_t size): + _mem(mem), _size(size) + { + /* NOP */ + } + + T &operator[](size_t index) const{ + return _mem[index]; + } + + size_t size(void) const{ + return _size; + } + +private: + typedef T* memp_t; + const memp_t _mem; + const size_t _size; +}; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */ diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index 02f65000f..11c70dd07 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -148,7 +148,7 @@ template UHD_INLINE T get_context_code( ******************************************************************/ static UHD_INLINE size_t _recv1( recv_state &state, - const std::vector &buffs, + const uhd::device::recv_buffs_type &buffs, size_t offset_bytes, size_t total_samps, uhd::rx_metadata_t &metadata, @@ -227,7 +227,7 @@ template UHD_INLINE T get_context_code( ******************************************************************/ static UHD_INLINE size_t recv( recv_state &state, - const std::vector &buffs, + const uhd::device::recv_buffs_type &buffs, const size_t total_num_samps, uhd::rx_metadata_t &metadata, uhd::device::recv_mode_t recv_mode, @@ -328,7 +328,7 @@ template UHD_INLINE T get_context_code( ******************************************************************/ static UHD_INLINE size_t _send1( send_state &state, - const std::vector &buffs, + const uhd::device::send_buffs_type &buffs, const size_t offset_bytes, const size_t num_samps, uhd::transport::vrt::if_packet_info_t &if_packet_info, @@ -374,7 +374,7 @@ template UHD_INLINE T get_context_code( ******************************************************************/ static UHD_INLINE size_t send( send_state &state, - const std::vector &buffs, + const uhd::device::send_buffs_type &buffs, const size_t total_num_samps, const uhd::tx_metadata_t &metadata, uhd::device::send_mode_t send_mode, diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 7953447d1..88cbab073 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -220,7 +220,7 @@ size_t usrp1_impl::get_max_send_samps_per_packet(void) const { } size_t usrp1_impl::send( - const std::vector &buffs, size_t num_samps, + const send_buffs_type &buffs, size_t num_samps, const tx_metadata_t &metadata, const io_type_t &io_type, send_mode_t send_mode, double timeout ){ @@ -298,7 +298,7 @@ size_t usrp1_impl::get_max_recv_samps_per_packet(void) const { } size_t usrp1_impl::recv( - const std::vector &buffs, size_t num_samps, + const recv_buffs_type &buffs, size_t num_samps, rx_metadata_t &metadata, const io_type_t &io_type, recv_mode_t recv_mode, double timeout ){ diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index 28199ebe3..1d9f6709f 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -80,13 +80,13 @@ public: ~usrp1_impl(void); //the io interface - size_t send(const std::vector &, + size_t send(const send_buffs_type &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double); - size_t recv(const std::vector &, + size_t recv(const recv_buffs_type &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, recv_mode_t, double); diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 56c20934b..0376ebdae 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -297,7 +297,7 @@ size_t usrp2_impl::get_max_send_samps_per_packet(void) const{ } size_t usrp2_impl::send( - const std::vector &buffs, size_t num_samps, + const send_buffs_type &buffs, size_t num_samps, const tx_metadata_t &metadata, const io_type_t &io_type, send_mode_t send_mode, double timeout ){ @@ -459,7 +459,7 @@ static void handle_overflow(std::vector &mboards, size_ } size_t usrp2_impl::recv( - const std::vector &buffs, size_t num_samps, + const recv_buffs_type &buffs, size_t num_samps, rx_metadata_t &metadata, const io_type_t &io_type, recv_mode_t recv_mode, double timeout ){ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index ad95b2a4a..337f842d6 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -200,12 +200,12 @@ public: //the io interface size_t send( - const std::vector &, size_t, + const send_buffs_type &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, uhd::device::send_mode_t, double ); size_t recv( - const std::vector &, size_t, + const recv_buffs_type &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, uhd::device::recv_mode_t, double ); diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index c8b9e03d9..cf2410e4f 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -212,7 +212,7 @@ size_t usrp_e100_impl::get_max_send_samps_per_packet(void) const{ } size_t usrp_e100_impl::send( - const std::vector &buffs, size_t num_samps, + const send_buffs_type &buffs, size_t num_samps, const tx_metadata_t &metadata, const io_type_t &io_type, send_mode_t send_mode, double timeout ){ @@ -242,7 +242,7 @@ size_t usrp_e100_impl::get_max_recv_samps_per_packet(void) const{ } size_t usrp_e100_impl::recv( - const std::vector &buffs, size_t num_samps, + const recv_buffs_type &buffs, size_t num_samps, rx_metadata_t &metadata, const io_type_t &io_type, recv_mode_t recv_mode, double timeout ){ diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp b/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp index df8e5dc9f..2dc401305 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -83,8 +83,8 @@ public: ~usrp_e100_impl(void); //the io interface - size_t send(const std::vector &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double); - size_t recv(const std::vector &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, recv_mode_t, double); + size_t send(const send_buffs_type &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double); + size_t recv(const recv_buffs_type &, size_t, uhd::rx_metadata_t &, const uhd::io_type_t &, recv_mode_t, double); bool recv_async_msg(uhd::async_metadata_t &, double); size_t get_max_send_samps_per_packet(void) const; size_t get_max_recv_samps_per_packet(void) const; -- cgit v1.2.3 From a72e29ca1de5b484bedcb1cfa8be6cd2216dc54e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 9 Feb 2011 19:23:36 -0800 Subject: uhd: tweaks for windows warnings and errors --- host/include/uhd/transport/bounded_buffer.ipp | 7 +++---- host/lib/transport/udp_zero_copy_asio.cpp | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp index 466c7a306..7be2f987c 100644 --- a/host/include/uhd/transport/bounded_buffer.ipp +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -31,11 +31,10 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ public: bounded_buffer_detail(size_t capacity): - _buffer(capacity), - _not_full_fcn(boost::bind(&bounded_buffer_detail::not_full, this)), - _not_empty_fcn(boost::bind(&bounded_buffer_detail::not_empty, this)) + _buffer(capacity) { - /* NOP */ + _not_full_fcn = boost::bind(&bounded_buffer_detail::not_full, this); + _not_empty_fcn = boost::bind(&bounded_buffer_detail::not_empty, this); } UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 33c7dd94e..48b0941eb 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -58,7 +58,7 @@ public: return sptr(this, &udp_zero_copy_asio_mrb::fake_deleter); } - void *get(void) const{return _mem;} + template T cast(void) const{return static_cast(_mem);} private: static void fake_deleter(void *obj){ @@ -210,7 +210,7 @@ public: ::select(_sock_fd+1, &rset, NULL, NULL, &tv) > 0 and _pending_recv_buffs.pop_with_haste(mrb) ){ - return mrb->get_new(::recv(_sock_fd, mrb->get(), _recv_frame_size, 0)); + return mrb->get_new(::recv(_sock_fd, mrb->cast(), _recv_frame_size, 0)); } return managed_recv_buffer::sptr(); } @@ -235,7 +235,7 @@ public: } void commit(udp_zero_copy_asio_msb *msb, size_t len){ - ::send(_sock_fd, msb->cast(), len, 0); + ::send(_sock_fd, msb->cast(), len, 0); handle_send(msb); } -- cgit v1.2.3 From 1be2590962669f307dce24ccb0b0011b3f3f25f5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 13:58:38 -0800 Subject: uhd: tweaks to bounded buffer Added push with haste. Call with haste first in the wait methods to avoid time compare/wait when not needed. Added new calls to the libusb and udp zero copy impls tests pass --- host/include/uhd/transport/bounded_buffer.hpp | 15 +++++++++++++-- host/include/uhd/transport/bounded_buffer.ipp | 17 +++++++++++++++-- host/lib/transport/libusb1_zero_copy.cpp | 4 ++-- host/lib/transport/udp_zero_copy_asio.cpp | 10 +++++----- 4 files changed, 35 insertions(+), 11 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp index 412d73f17..6aa92c2e6 100644 --- a/host/include/uhd/transport/bounded_buffer.hpp +++ b/host/include/uhd/transport/bounded_buffer.hpp @@ -42,6 +42,16 @@ namespace uhd{ namespace transport{ /* NOP */ } + /*! + * Push a new element into the bounded buffer immediately. + * The element will not be pushed when the buffer is full. + * \param elem the element reference pop to + * \return false when the buffer is full + */ + bool push_with_haste(const elem_type &elem){ + return _detail.push_with_haste(elem); + } + /*! * Push a new element into the bounded buffer. * If the buffer is full prior to the push, @@ -74,9 +84,10 @@ namespace uhd{ namespace transport{ } /*! - * Pop an element from the bounded_buffer immediately. + * Pop an element from the bounded buffer immediately. + * The element will not be popped when the buffer is empty. * \param elem the element reference pop to - * \return false when the bounded_buffer is empty + * \return false when the buffer is empty */ bool pop_with_haste(elem_type &elem){ return _detail.pop_with_haste(elem); diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp index 7be2f987c..0d393ad64 100644 --- a/host/include/uhd/transport/bounded_buffer.ipp +++ b/host/include/uhd/transport/bounded_buffer.ipp @@ -37,9 +37,18 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ _not_empty_fcn = boost::bind(&bounded_buffer_detail::not_empty, this); } + UHD_INLINE bool push_with_haste(const elem_type &elem){ + boost::mutex::scoped_lock lock(_mutex); + if (_buffer.full()) return false; + _buffer.push_front(elem); + lock.unlock(); + _empty_cond.notify_one(); + return true; + } + UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){ boost::mutex::scoped_lock lock(_mutex); - if(_buffer.full()){ + if (_buffer.full()){ _buffer.pop_back(); _buffer.push_front(elem); lock.unlock(); @@ -55,6 +64,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE void push_with_wait(const elem_type &elem){ + if (this->push_with_haste(elem)) return; boost::mutex::scoped_lock lock(_mutex); _full_cond.wait(lock, _not_full_fcn); _buffer.push_front(elem); @@ -63,6 +73,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE bool push_with_timed_wait(const elem_type &elem, double timeout){ + if (this->push_with_haste(elem)) return true; boost::mutex::scoped_lock lock(_mutex); if (not _full_cond.timed_wait( lock, to_time_dur(timeout), _not_full_fcn @@ -75,7 +86,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ UHD_INLINE bool pop_with_haste(elem_type &elem){ boost::mutex::scoped_lock lock(_mutex); - if(_buffer.empty()) return false; + if (_buffer.empty()) return false; elem = this->pop_back(); lock.unlock(); _full_cond.notify_one(); @@ -83,6 +94,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE void pop_with_wait(elem_type &elem){ + if (this->pop_with_haste(elem)) return; boost::mutex::scoped_lock lock(_mutex); _empty_cond.wait(lock, _not_empty_fcn); elem = this->pop_back(); @@ -91,6 +103,7 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/ } UHD_INLINE bool pop_with_timed_wait(elem_type &elem, double timeout){ + if (this->pop_with_haste(elem)) return true; boost::mutex::scoped_lock lock(_mutex); if (not _empty_cond.timed_wait( lock, to_time_dur(timeout), _not_empty_fcn diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index ca37f351f..6fab5ae6f 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -132,7 +132,7 @@ static void callback(libusb_transfer *lut){ * \param pointer to libusb_transfer */ void usb_endpoint::callback_handle_transfer(libusb_transfer *lut){ - _completed_list.push_with_wait(lut); + _completed_list.push_with_haste(lut); } @@ -161,7 +161,7 @@ usb_endpoint::usb_endpoint( //input luts are immediately submitted to be filled //output luts go into the completed list as free buffers if (_input) this->submit(_all_luts.back()); - else _completed_list.push_with_wait(_all_luts.back()); + else _completed_list.push_with_haste(_all_luts.back()); } } diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 87c5ec823..c45b196cf 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -216,14 +216,14 @@ public: managed_recv_buffer::sptr get_recv_buff(double timeout){ udp_zero_copy_asio_mrb *mrb = NULL; - if (is_recv_socket_ready(timeout) and _pending_recv_buffs.pop_with_haste(mrb)){ + if (is_recv_socket_ready(timeout) and _pending_recv_buffs.pop_with_timed_wait(mrb, timeout)){ return mrb->get_new(::recv(_sock_fd, mrb->cast(), _recv_frame_size, 0)); } return managed_recv_buffer::sptr(); } UHD_INLINE void handle_recv(udp_zero_copy_asio_mrb *mrb){ - _pending_recv_buffs.push_with_pop_on_full(mrb); + _pending_recv_buffs.push_with_haste(mrb); } void release(udp_zero_copy_asio_mrb *mrb){ @@ -245,16 +245,16 @@ public: * - A managed buffer is always available. * - The queue can never be over-filled. ******************************************************************/ - managed_send_buffer::sptr get_send_buff(double){ + managed_send_buffer::sptr get_send_buff(double timeout){ udp_zero_copy_asio_msb *msb = NULL; - if (_pending_send_buffs.pop_with_haste(msb)){ + if (_pending_send_buffs.pop_with_timed_wait(msb, timeout)){ return msb->get_new(_send_frame_size); } return managed_send_buffer::sptr(); } UHD_INLINE void handle_send(udp_zero_copy_asio_msb *msb){ - _pending_send_buffs.push_with_pop_on_full(msb); + _pending_send_buffs.push_with_haste(msb); } void commit(udp_zero_copy_asio_msb *msb, size_t len){ -- cgit v1.2.3 From 08bad571b7e535bf665aec78d4468dbb231474a7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 14:24:51 -0800 Subject: uhd: use ref vector class for the conversion routines I/O --- host/include/uhd/convert.hpp | 8 ++++---- host/lib/convert/convert_common.hpp | 8 ++++---- host/lib/transport/vrt_packet_handler.hpp | 4 ++-- host/tests/convert_test.cpp | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp index bfe8c8267..8fc2f38db 100644 --- a/host/include/uhd/convert.hpp +++ b/host/include/uhd/convert.hpp @@ -21,15 +21,15 @@ #include #include #include +#include #include #include -#include namespace uhd{ namespace convert{ - typedef std::vector output_type; - typedef std::vector input_type; - typedef boost::function function_type; + typedef uhd::ref_vector output_type; + typedef uhd::ref_vector input_type; + typedef boost::function function_type; /*! * Describe the priority of a converter function. diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp index c6ba1fcf9..c2ca233d9 100644 --- a/host/lib/convert/convert_common.hpp +++ b/host/lib/convert/convert_common.hpp @@ -25,16 +25,16 @@ #define DECLARE_CONVERTER(fcn, prio) \ static void fcn( \ - uhd::convert::input_type &inputs, \ - uhd::convert::output_type &outputs, \ + const uhd::convert::input_type &inputs, \ + const uhd::convert::output_type &outputs, \ size_t nsamps \ ); \ UHD_STATIC_BLOCK(register_##fcn##_##prio){ \ uhd::convert::register_converter(#fcn, fcn, prio); \ } \ static void fcn( \ - uhd::convert::input_type &inputs, \ - uhd::convert::output_type &outputs, \ + const uhd::convert::input_type &inputs, \ + const uhd::convert::output_type &outputs, \ size_t nsamps \ ) diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index 795d5bc62..6cb70cfac 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -68,7 +68,7 @@ template UHD_INLINE T get_context_code( size_t size_of_copy_buffs; size_t fragment_offset_in_samps; std::vector io_buffs; - uhd::convert::input_type otw_buffs; + std::vector otw_buffs; recv_state(size_t width = 1): width(width), @@ -309,7 +309,7 @@ template UHD_INLINE T get_context_code( const boost::uint64_t zeros; std::vector zero_buffs; std::vector io_buffs; - uhd::convert::output_type otw_buffs; + std::vector otw_buffs; send_state(size_t width = 1): next_packet_seq(0), diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index d3c235e9b..d1c2b7625 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -49,8 +49,8 @@ template static void loopback( //item32 is largest device type std::vector interm(nsamps); - convert::input_type input0(1, &input[0]), input1(1, &interm[0]); - convert::output_type output0(1, &interm[0]), output1(1, &output[0]); + std::vector input0(1, &input[0]), input1(1, &interm[0]); + std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert to intermediate type convert::get_converter_cpu_to_otw( @@ -201,8 +201,8 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ std::vector interm(nsamps); std::vector output(nsamps); - convert::input_type input0(1, &input[0]), input1(1, &interm[0]); - convert::output_type output0(1, &interm[0]), output1(1, &output[0]); + std::vector input0(1, &input[0]), input1(1, &interm[0]); + std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert float to intermediate convert::get_converter_cpu_to_otw( @@ -241,8 +241,8 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ std::vector interm(nsamps); std::vector output(nsamps); - convert::input_type input0(1, &input[0]), input1(1, &interm[0]); - convert::output_type output0(1, &interm[0]), output1(1, &output[0]); + std::vector input0(1, &input[0]), input1(1, &interm[0]); + std::vector output0(1, &interm[0]), output1(1, &output[0]); //convert short to intermediate convert::get_converter_cpu_to_otw( -- cgit v1.2.3 From 4addf2a48646f5b0faa5f42b35a5735d40d8b4f0 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Feb 2011 16:16:40 -0800 Subject: uhd: reference vector fix revealed when building w/ debug --- host/include/uhd/types/ref_vector.hpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp index ef970802f..efd4b8f89 100644 --- a/host/include/uhd/types/ref_vector.hpp +++ b/host/include/uhd/types/ref_vector.hpp @@ -29,29 +29,22 @@ namespace uhd{ */ template class ref_vector{ public: - //! Create a reference vector of length one from a pointer - template ref_vector(Ptr *ptr): - _mem(memp_t(&ptr)), _size(1) + //! Create a reference vector from a pointer and size + template ref_vector(Ptr *ptr, size_t size = 1): + _mem(T(ptr)), _size(size) { /* NOP */ } //! Create a reference vector from a std::vector container template ref_vector(const Range &range): - _mem(memp_t(&range[0])), _size(range.size()) + _mem(T(range.front())), _size(range.size()) { /* NOP */ } - //! Create a reference vector from a memory pointer and size - ref_vector(T *mem, size_t size): - _mem(mem), _size(size) - { - /* NOP */ - } - - T &operator[](size_t index) const{ - return _mem[index]; + const T &operator[](size_t index) const{ + return (&_mem)[index]; } size_t size(void) const{ @@ -59,8 +52,7 @@ public: } private: - typedef T* memp_t; - const memp_t _mem; + const T _mem; const size_t _size; }; -- cgit v1.2.3 From 24c626a1476895a6cb7dbb26b438778c61e52fc2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 10:29:59 -0800 Subject: usrp: added mboard param to get time now and last pps --- host/include/uhd/usrp/multi_usrp.hpp | 6 ++++-- host/lib/usrp/multi_usrp.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index c77b5d6d2..60b757f50 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -141,15 +141,17 @@ public: /*! * Get the current time in the usrp time registers. + * \param mboard which motherboard to query * \return a timespec representing current usrp time */ - virtual time_spec_t get_time_now(void) = 0; + virtual time_spec_t get_time_now(size_t mboard = 0) = 0; /*! * Get the time when the last pps pulse occured. + * \param mboard which motherboard to query * \return a timespec representing the last pps */ - virtual time_spec_t get_time_last_pps(void) = 0; + virtual time_spec_t get_time_last_pps(size_t mboard = 0) = 0; /*! * Sets the time registers on the usrp immediately. diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 817d7b085..4bdb2bf2e 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -128,12 +128,12 @@ public: return _mboard(mboard)[MBOARD_PROP_NAME].as(); } - time_spec_t get_time_now(void){ - return _mboard(0)[MBOARD_PROP_TIME_NOW].as(); + time_spec_t get_time_now(size_t mboard = 0){ + return _mboard(mboard)[MBOARD_PROP_TIME_NOW].as(); } - time_spec_t get_time_last_pps(void){ - return _mboard(0)[MBOARD_PROP_TIME_PPS].as(); + time_spec_t get_time_last_pps(size_t mboard = 0){ + return _mboard(mboard)[MBOARD_PROP_TIME_PPS].as(); } void set_time_now(const time_spec_t &time_spec, size_t mboard){ -- cgit v1.2.3 From 4d6ae6a8d39e97a7dba53dfd4150ba93ddb470fa Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 12:35:48 -0800 Subject: uhd: third iteration of the reference vector Hope we get it right this time. Reference vector now has its own pointer for the pointer/size 1 constuction case. In this case, the memory is initialized to the value of its own pointer. The previous two iterations were functionally wrong because it takes two pointers and size to accomplish this. --- host/include/uhd/types/ref_vector.hpp | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp index efd4b8f89..0ae301647 100644 --- a/host/include/uhd/types/ref_vector.hpp +++ b/host/include/uhd/types/ref_vector.hpp @@ -29,30 +29,54 @@ namespace uhd{ */ template class ref_vector{ public: - //! Create a reference vector from a pointer and size - template ref_vector(Ptr *ptr, size_t size = 1): - _mem(T(ptr)), _size(size) + /*! + * Create a reference vector of size 1 from a pointer. + * Therefore: rv[0] == ptr and rv.size() == 1 + * \param ptr a pointer to a chunk of memory + */ + template ref_vector(Ptr *ptr): + _ptr(T(ptr)), _mem(_mem_t(&_ptr)), _size(1) { /* NOP */ } - //! Create a reference vector from a std::vector container - template ref_vector(const Range &range): - _mem(T(range.front())), _size(range.size()) + /*! + * Create a reference vector from a std::vector container. + * Therefore: rv[n] == vec[n] and rv.size() == vec.size() + * \param range a const reference to an std::vector + */ + template ref_vector(const Vector &vec): + _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size()) { /* NOP */ } + /*! + * Create a reference vector from a pointer and a length + * Therefore: rv[n] == mem[n] and rv.size() == len + * \param mem a pointer to an array of pointers + * \param len the length of the array of pointers + */ + ref_vector(const T *mem, size_t len): + _ptr(T()), _mem(_mem_t(mem)), _size(len) + { + /* NOP */ + } + + //! Index operator gets the value of rv[index] const T &operator[](size_t index) const{ - return (&_mem)[index]; + return _mem[index]; } + //! The number of elements in this container size_t size(void) const{ return _size; } private: - const T _mem; + const T _ptr; + typedef T* _mem_t; + const _mem_t _mem; const size_t _size; }; -- cgit v1.2.3 From ad31ba63c1005221550fce77488b6080ba166cfe Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 17:31:59 -0800 Subject: usrp: added sensors props to mboard and subdev (removed stupid = 'char' thing) --- host/include/uhd/types/ref_vector.hpp | 2 +- host/include/uhd/usrp/codec_props.hpp | 12 +++++----- host/include/uhd/usrp/dboard_props.hpp | 16 +++++++------- host/include/uhd/usrp/device_props.hpp | 8 +++---- host/include/uhd/usrp/dsp_props.hpp | 14 ++++++------ host/include/uhd/usrp/mboard_props.hpp | 40 ++++++++++++++++++---------------- host/include/uhd/usrp/subdev_props.hpp | 32 ++++++++++++++------------- 7 files changed, 64 insertions(+), 60 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp index 0ae301647..2928cb150 100644 --- a/host/include/uhd/types/ref_vector.hpp +++ b/host/include/uhd/types/ref_vector.hpp @@ -43,7 +43,7 @@ public: /*! * Create a reference vector from a std::vector container. * Therefore: rv[n] == vec[n] and rv.size() == vec.size() - * \param range a const reference to an std::vector + * \param vec a const reference to an std::vector */ template ref_vector(const Vector &vec): _ptr(T()), _mem(_mem_t(&vec.front())), _size(vec.size()) diff --git a/host/include/uhd/usrp/codec_props.hpp b/host/include/uhd/usrp/codec_props.hpp index 5d0a2913c..b0a79e3f6 100644 --- a/host/include/uhd/usrp/codec_props.hpp +++ b/host/include/uhd/usrp/codec_props.hpp @@ -28,12 +28,12 @@ namespace uhd{ namespace usrp{ * Other properties can be discovered through the others prop. */ enum codec_prop_t{ - CODEC_PROP_NAME = 'n', //ro, std::string - CODEC_PROP_OTHERS = 'o', //ro, prop_names_t - CODEC_PROP_GAIN_I = 'i', //rw, double - CODEC_PROP_GAIN_Q = 'q', //rw, double - CODEC_PROP_GAIN_RANGE = 'r', //ro, gain_range_t - CODEC_PROP_GAIN_NAMES = 'G' //ro, prop_names_t + CODEC_PROP_NAME, //ro, std::string + CODEC_PROP_OTHERS, //ro, prop_names_t + CODEC_PROP_GAIN_I, //rw, double + CODEC_PROP_GAIN_Q , //rw, double + CODEC_PROP_GAIN_RANGE, //ro, gain_range_t + CODEC_PROP_GAIN_NAMES //ro, prop_names_t }; diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp index aab6c31ce..32ec1c1bf 100644 --- a/host/include/uhd/usrp/dboard_props.hpp +++ b/host/include/uhd/usrp/dboard_props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -28,13 +28,13 @@ namespace uhd{ namespace usrp{ * A dboard is considered to be unidirectional (RX or TX). */ enum dboard_prop_t{ - DBOARD_PROP_NAME = 'n', //ro, std::string - DBOARD_PROP_SUBDEV = 's', //ro, wax::obj - DBOARD_PROP_SUBDEV_NAMES = 'S', //ro, prop_names_t - DBOARD_PROP_DBOARD_ID = 'i', //rw, dboard_id_t - DBOARD_PROP_DBOARD_IFACE = 'f', //ro, dboard_iface::sptr - DBOARD_PROP_CODEC = 'c', //ro, wax::obj - DBOARD_PROP_GAIN_GROUP = 'g' //ro, gain_group + DBOARD_PROP_NAME, //ro, std::string + DBOARD_PROP_SUBDEV, //ro, wax::obj + DBOARD_PROP_SUBDEV_NAMES, //ro, prop_names_t + DBOARD_PROP_DBOARD_ID, //rw, dboard_id_t + DBOARD_PROP_DBOARD_IFACE, //ro, dboard_iface::sptr + DBOARD_PROP_CODEC, //ro, wax::obj + DBOARD_PROP_GAIN_GROUP //ro, gain_group }; }} //namespace diff --git a/host/include/uhd/usrp/device_props.hpp b/host/include/uhd/usrp/device_props.hpp index 346eec179..3c8f7e225 100644 --- a/host/include/uhd/usrp/device_props.hpp +++ b/host/include/uhd/usrp/device_props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,9 +29,9 @@ namespace uhd{ namespace usrp{ * will be present in the interface for configuration. */ enum device_prop_t{ - DEVICE_PROP_NAME = 'n', //ro, std::string - DEVICE_PROP_MBOARD = 'm', //ro, wax::obj - DEVICE_PROP_MBOARD_NAMES = 'M' //ro, prop_names_t + DEVICE_PROP_NAME, //ro, std::string + DEVICE_PROP_MBOARD, //ro, wax::obj + DEVICE_PROP_MBOARD_NAMES, //ro, prop_names_t }; }} //namespace diff --git a/host/include/uhd/usrp/dsp_props.hpp b/host/include/uhd/usrp/dsp_props.hpp index 54ea5666b..3e1690317 100644 --- a/host/include/uhd/usrp/dsp_props.hpp +++ b/host/include/uhd/usrp/dsp_props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -37,12 +37,12 @@ namespace uhd{ namespace usrp{ * Set the shift property and read it back to get actual shift. */ enum dsp_prop_t{ - DSP_PROP_NAME = 'n', //ro, std::string - DSP_PROP_OTHERS = 'o', //ro, prop_names_t - DSP_PROP_FREQ_SHIFT = 'f', //rw, double Hz - DSP_PROP_FREQ_SHIFT_NAMES = 'F', //ro, prop_names_t - DSP_PROP_CODEC_RATE = 'c', //ro, double Sps - DSP_PROP_HOST_RATE = 'h' //rw, double Sps + DSP_PROP_NAME, //ro, std::string + DSP_PROP_OTHERS, //ro, prop_names_t + DSP_PROP_FREQ_SHIFT, //rw, double Hz + DSP_PROP_FREQ_SHIFT_NAMES, //ro, prop_names_t + DSP_PROP_CODEC_RATE, //ro, double Sps + DSP_PROP_HOST_RATE //rw, double Sps }; }} //namespace diff --git a/host/include/uhd/usrp/mboard_props.hpp b/host/include/uhd/usrp/mboard_props.hpp index d04ad012c..559c96ecb 100644 --- a/host/include/uhd/usrp/mboard_props.hpp +++ b/host/include/uhd/usrp/mboard_props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -29,24 +29,26 @@ namespace uhd{ namespace usrp{ * and discovered though the others property. */ enum mboard_prop_t{ - MBOARD_PROP_NAME = 'n', //ro, std::string - MBOARD_PROP_OTHERS = 'o', //ro, prop_names_t - MBOARD_PROP_CLOCK_RATE = 'c', //rw, double - MBOARD_PROP_RX_DSP = 'd', //ro, wax::obj - MBOARD_PROP_RX_DSP_NAMES = 'D', //ro, prop_names_t - MBOARD_PROP_TX_DSP = 'u', //ro, wax::obj - MBOARD_PROP_TX_DSP_NAMES = 'U', //ro, prop_names_t - MBOARD_PROP_RX_DBOARD = 'e', //ro, wax::obj - MBOARD_PROP_RX_DBOARD_NAMES = 'E', //ro, prop_names_t - MBOARD_PROP_TX_DBOARD = 'v', //ro, wax::obj - MBOARD_PROP_TX_DBOARD_NAMES = 'V', //ro, prop_names_t - MBOARD_PROP_RX_SUBDEV_SPEC = 'r', //rw, subdev_spec_t - MBOARD_PROP_TX_SUBDEV_SPEC = 'R', //rw, subdev_spec_t - MBOARD_PROP_CLOCK_CONFIG = 'C', //rw, clock_config_t - MBOARD_PROP_TIME_NOW = 't', //rw, time_spec_t - MBOARD_PROP_TIME_PPS = 'T', //wo, time_spec_t - MBOARD_PROP_STREAM_CMD = 's', //wo, stream_cmd_t - MBOARD_PROP_EEPROM_MAP = 'M' //wr, mboard_eeprom_t::sptr + MBOARD_PROP_NAME, //ro, std::string + MBOARD_PROP_OTHERS, //ro, prop_names_t + MBOARD_PROP_SENSOR, //ro, sensor_value_t + MBOARD_PROP_SENSOR_NAMES, //ro, prop_names_t + MBOARD_PROP_CLOCK_RATE, //rw, double + MBOARD_PROP_RX_DSP, //ro, wax::obj + MBOARD_PROP_RX_DSP_NAMES, //ro, prop_names_t + MBOARD_PROP_TX_DSP, //ro, wax::obj + MBOARD_PROP_TX_DSP_NAMES, //ro, prop_names_t + MBOARD_PROP_RX_DBOARD, //ro, wax::obj + MBOARD_PROP_RX_DBOARD_NAMES, //ro, prop_names_t + MBOARD_PROP_TX_DBOARD, //ro, wax::obj + MBOARD_PROP_TX_DBOARD_NAMES, //ro, prop_names_t + MBOARD_PROP_RX_SUBDEV_SPEC, //rw, subdev_spec_t + MBOARD_PROP_TX_SUBDEV_SPEC, //rw, subdev_spec_t + MBOARD_PROP_CLOCK_CONFIG, //rw, clock_config_t + MBOARD_PROP_TIME_NOW, //rw, time_spec_t + MBOARD_PROP_TIME_PPS, //wo, time_spec_t + MBOARD_PROP_STREAM_CMD, //wo, stream_cmd_t + MBOARD_PROP_EEPROM_MAP //wr, mboard_eeprom_t::sptr }; }} //namespace diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp index 8d05f4c27..87628fadc 100644 --- a/host/include/uhd/usrp/subdev_props.hpp +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -42,21 +42,23 @@ namespace uhd{ namespace usrp{ * Possible device subdev properties */ enum subdev_prop_t{ - SUBDEV_PROP_NAME = 'n', //ro, std::string - SUBDEV_PROP_OTHERS = 'o', //ro, prop_names_t - SUBDEV_PROP_GAIN = 'g', //rw, double - SUBDEV_PROP_GAIN_RANGE = 'r', //ro, gain_range_t - SUBDEV_PROP_GAIN_NAMES = 'G', //ro, prop_names_t - SUBDEV_PROP_FREQ = 'f', //rw, double - SUBDEV_PROP_FREQ_RANGE = 'F', //ro, freq_range_t - SUBDEV_PROP_ANTENNA = 'a', //rw, std::string - SUBDEV_PROP_ANTENNA_NAMES = 'A', //ro, prop_names_t - SUBDEV_PROP_LO_LOCKED = 'L', //ro, bool - SUBDEV_PROP_CONNECTION = 'c', //ro, subdev_conn_t - SUBDEV_PROP_ENABLED = 'e', //rw, bool - SUBDEV_PROP_USE_LO_OFFSET = 'l', //ro, bool - SUBDEV_PROP_RSSI = 'R', //ro, double - SUBDEV_PROP_BANDWIDTH = 'B' //rw, double + SUBDEV_PROP_NAME, //ro, std::string + SUBDEV_PROP_OTHERS, //ro, prop_names_t + SUBDEV_PROP_SENSOR, //ro, sensor_value_t + SUBDEV_PROP_SENSOR_NAMES, //ro, prop_names_t + SUBDEV_PROP_GAIN, //rw, double + SUBDEV_PROP_GAIN_RANGE, //ro, gain_range_t + SUBDEV_PROP_GAIN_NAMES, //ro, prop_names_t + SUBDEV_PROP_FREQ, //rw, double + SUBDEV_PROP_FREQ_RANGE, //ro, freq_range_t + SUBDEV_PROP_ANTENNA, //rw, std::string + SUBDEV_PROP_ANTENNA_NAMES, //ro, prop_names_t + SUBDEV_PROP_LO_LOCKED, //ro, bool //TODO deprecate for sensors + SUBDEV_PROP_CONNECTION, //ro, subdev_conn_t + SUBDEV_PROP_ENABLED, //rw, bool + SUBDEV_PROP_USE_LO_OFFSET, //ro, bool + SUBDEV_PROP_RSSI, //ro, double //TODO deprecate for sensors + SUBDEV_PROP_BANDWIDTH //rw, double }; }} //namespace -- cgit v1.2.3 From e4b45cca1b99d92baab061d36b6c0ceaebdfe5b7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 18:07:24 -0800 Subject: usrp: added get sensors api to multi usrp for rx/tx subdevs and mboard --- host/include/uhd/usrp/multi_usrp.hpp | 46 ++++++++++++++++++++++++++++++++++++ host/lib/usrp/multi_usrp.cpp | 24 +++++++++++++++++++ 2 files changed, 70 insertions(+) (limited to 'host/include') diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 60b757f50..28c1860d6 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,21 @@ public: */ virtual size_t get_num_mboards(void) = 0; + /*! + * Get a motherboard sensor value. + * \param name the name of the sensor + * \param mboard the motherboard index 0 to M-1 + * \return a sensor value object + */ + virtual sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0; + + /*! + * Get a list of possible motherboard sensor names. + * \param mboard the motherboard index 0 to M-1 + * \return a vector of sensor names + */ + virtual std::vector get_mboard_sensor_names(size_t mboard = 0) = 0; + /******************************************************************* * RX methods ******************************************************************/ @@ -410,6 +426,21 @@ public: */ virtual dboard_iface::sptr get_rx_dboard_iface(size_t chan = 0) = 0; + /*! + * Get an RX subdevice sensor value. + * \param name the name of the sensor + * \param chan the channel index 0 to N-1 + * \return a sensor value object + */ + virtual sensor_value_t get_rx_sensor(const std::string &name, size_t chan = 0) = 0; + + /*! + * Get a list of possible RX subdevice sensor names. + * \param chan the channel index 0 to N-1 + * \return a vector of sensor names + */ + virtual std::vector get_rx_sensor_names(size_t chan = 0) = 0; + /******************************************************************* * TX methods ******************************************************************/ @@ -580,6 +611,21 @@ public: * \return the dboard interface sptr */ virtual dboard_iface::sptr get_tx_dboard_iface(size_t chan = 0) = 0; + + /*! + * Get an TX subdevice sensor value. + * \param name the name of the sensor + * \param chan the channel index 0 to N-1 + * \return a sensor value object + */ + virtual sensor_value_t get_tx_sensor(const std::string &name, size_t chan = 0) = 0; + + /*! + * Get a list of possible TX subdevice sensor names. + * \param chan the channel index 0 to N-1 + * \return a vector of sensor names + */ + virtual std::vector get_tx_sensor_names(size_t chan = 0) = 0; }; }} diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 4bdb2bf2e..e4e70b594 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -214,6 +214,14 @@ public: return (*_dev)[DEVICE_PROP_MBOARD_NAMES].as().size(); } + sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard){ + return _mboard(mboard)[named_prop_t(MBOARD_PROP_SENSOR, name)].as(); + } + + std::vector get_mboard_sensor_names(size_t mboard){ + return _mboard(mboard)[MBOARD_PROP_SENSOR_NAMES].as(); + } + /******************************************************************* * RX methods ******************************************************************/ @@ -312,6 +320,14 @@ public: return _rx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as(); } + sensor_value_t get_rx_sensor(const std::string &name, size_t chan){ + return _rx_subdev(chan)[named_prop_t(SUBDEV_PROP_SENSOR, name)].as(); + } + + std::vector get_rx_sensor_names(size_t chan){ + return _rx_subdev(chan)[SUBDEV_PROP_SENSOR_NAMES].as(); + } + /******************************************************************* * TX methods ******************************************************************/ @@ -406,6 +422,14 @@ public: return _tx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as(); } + sensor_value_t get_tx_sensor(const std::string &name, size_t chan){ + return _tx_subdev(chan)[named_prop_t(SUBDEV_PROP_SENSOR, name)].as(); + } + + std::vector get_tx_sensor_names(size_t chan){ + return _tx_subdev(chan)[SUBDEV_PROP_SENSOR_NAMES].as(); + } + private: device::sptr _dev; -- cgit v1.2.3 From 9de6f36bc5d9f5d9d602547166c92b53b278b428 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 18:43:20 -0800 Subject: usrp: implement sensors in all the dboards, deprecated read rssi and get lo locked --- host/examples/rx_samples_to_file.cpp | 1 - host/examples/rx_samples_to_udp.cpp | 1 - host/include/uhd/usrp/multi_usrp.hpp | 13 ++++++++++--- host/include/uhd/usrp/subdev_props.hpp | 2 -- host/lib/usrp/dboard/db_basic_and_lf.cpp | 8 -------- host/lib/usrp/dboard/db_dbsrx.cpp | 10 ++++++++-- host/lib/usrp/dboard/db_dbsrx2.cpp | 10 ++++++++-- host/lib/usrp/dboard/db_rfx.cpp | 19 +++++++++++++++---- host/lib/usrp/dboard/db_tvrx.cpp | 5 +---- host/lib/usrp/dboard/db_unknown.cpp | 8 -------- host/lib/usrp/dboard/db_wbx.cpp | 19 +++++++++++++++---- host/lib/usrp/dboard/db_xcvr2450.cpp | 25 +++++++++++++++++++------ host/lib/usrp/multi_usrp.cpp | 12 ------------ 13 files changed, 76 insertions(+), 57 deletions(-) (limited to 'host/include') diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index 296f480b0..e202fcb1c 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -78,7 +78,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time - std::cout << "LO Locked = " << usrp->get_rx_lo_locked() << std::endl; //setup streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); diff --git a/host/examples/rx_samples_to_udp.cpp b/host/examples/rx_samples_to_udp.cpp index 801d8e361..7ea775764 100644 --- a/host/examples/rx_samples_to_udp.cpp +++ b/host/examples/rx_samples_to_udp.cpp @@ -80,7 +80,6 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); //allow for some setup time - std::cout << "LO Locked = " << usrp->get_rx_lo_locked() << std::endl; //setup streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 28c1860d6..da52e6dce 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -28,6 +28,7 @@ #include #include #include +#include //needed until deprecated routines removed #include #include #include @@ -393,7 +394,9 @@ public: * \param chan the channel index 0 to N-1 * \return true for locked */ - virtual bool get_rx_lo_locked(size_t chan = 0) = 0; + UHD_DEPRECATED bool get_rx_lo_locked(size_t chan = 0){ + return this->get_rx_sensor("lo_locked", chan).value == "true"; + } /*! * Set the RX bandwidth on the subdevice. @@ -415,7 +418,9 @@ public: * \return the rssi in dB * \throw exception if RSSI readback not supported */ - virtual double read_rssi(size_t chan = 0) = 0; + UHD_DEPRECATED double read_rssi(size_t chan = 0){ + return boost::lexical_cast(this->get_rx_sensor("rssi", chan).value); + } /*! * Get the dboard interface object for the RX subdevice. @@ -587,7 +592,9 @@ public: * \param chan the channel index 0 to N-1 * \return true for locked */ - virtual bool get_tx_lo_locked(size_t chan = 0) = 0; + UHD_DEPRECATED bool get_tx_lo_locked(size_t chan = 0){ + return this->get_tx_sensor("lo_locked", chan).value == "true"; + } /*! * Set the TX bandwidth on the subdevice. diff --git a/host/include/uhd/usrp/subdev_props.hpp b/host/include/uhd/usrp/subdev_props.hpp index 87628fadc..40b339703 100644 --- a/host/include/uhd/usrp/subdev_props.hpp +++ b/host/include/uhd/usrp/subdev_props.hpp @@ -53,11 +53,9 @@ namespace uhd{ namespace usrp{ SUBDEV_PROP_FREQ_RANGE, //ro, freq_range_t SUBDEV_PROP_ANTENNA, //rw, std::string SUBDEV_PROP_ANTENNA_NAMES, //ro, prop_names_t - SUBDEV_PROP_LO_LOCKED, //ro, bool //TODO deprecate for sensors SUBDEV_PROP_CONNECTION, //ro, subdev_conn_t SUBDEV_PROP_ENABLED, //rw, bool SUBDEV_PROP_USE_LO_OFFSET, //ro, bool - SUBDEV_PROP_RSSI, //ro, double //TODO deprecate for sensors SUBDEV_PROP_BANDWIDTH //rw, double }; diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index b311576d2..b319289db 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -173,10 +173,6 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = true; //there is no LO, so it must be true! - return; - case SUBDEV_PROP_BANDWIDTH: val = subdev_bandwidth_scalar[get_subdev_name()]*_max_freq; return; @@ -284,10 +280,6 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = true; //there is no LO, so it must be true! - return; - case SUBDEV_PROP_BANDWIDTH: val = subdev_bandwidth_scalar[get_subdev_name()]*_max_freq; return; diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp index 3ea9cea80..98d9479fc 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -561,8 +562,13 @@ void dbsrx::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/dboard/db_dbsrx2.cpp b/host/lib/usrp/dboard/db_dbsrx2.cpp index defb70ff5..f4b797995 100644 --- a/host/lib/usrp/dboard/db_dbsrx2.cpp +++ b/host/lib/usrp/dboard/db_dbsrx2.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -400,8 +401,13 @@ void dbsrx2::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index cd25ee9b7..3b0c562ee 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -451,8 +452,13 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(dboard_iface::UNIT_RX); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(dboard_iface::UNIT_RX), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: @@ -548,8 +554,13 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ val = true; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(dboard_iface::UNIT_TX); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(dboard_iface::UNIT_TX), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp index a9ce38000..578999432 100644 --- a/host/lib/usrp/dboard/db_tvrx.cpp +++ b/host/lib/usrp/dboard/db_tvrx.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -463,10 +464,6 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = true; - return; - case SUBDEV_PROP_BANDWIDTH: val = 6.0e6; return; diff --git a/host/lib/usrp/dboard/db_unknown.cpp b/host/lib/usrp/dboard/db_unknown.cpp index d91d58409..f0a4c000e 100644 --- a/host/lib/usrp/dboard/db_unknown.cpp +++ b/host/lib/usrp/dboard/db_unknown.cpp @@ -154,10 +154,6 @@ void unknown_rx::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = true; //there is no LO, so it must be true! - return; - case SUBDEV_PROP_BANDWIDTH: val = 0.0; return; @@ -256,10 +252,6 @@ void unknown_tx::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = true; //there is no LO, so it must be true! - return; - case SUBDEV_PROP_BANDWIDTH: val = 0.0; return; diff --git a/host/lib/usrp/dboard/db_wbx.cpp b/host/lib/usrp/dboard/db_wbx.cpp index 135997789..0bc2d0ca1 100644 --- a/host/lib/usrp/dboard/db_wbx.cpp +++ b/host/lib/usrp/dboard/db_wbx.cpp @@ -68,6 +68,7 @@ #include #include #include +#include #include #include #include @@ -521,8 +522,13 @@ void wbx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(dboard_iface::UNIT_RX); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(dboard_iface::UNIT_RX), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: @@ -622,8 +628,13 @@ void wbx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(dboard_iface::UNIT_TX); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(dboard_iface::UNIT_TX), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 6fb5a26a8..f4f74eb86 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -616,12 +617,19 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(); + case SUBDEV_PROP_SENSOR: + if (key.name == "lo_locked") + val = sensor_value_t("LO", this->get_locked(), "locked", "unlocked"); + else if (key.name == "rssi") + val = sensor_value_t("RSSI", this->get_rssi(), "dB"); + else + UHD_THROW_INVALID_CODE_PATH(); return; - case SUBDEV_PROP_RSSI: - val = this->get_rssi(); + case SUBDEV_PROP_SENSOR_NAMES:{ + prop_names_t names = list_of("lo_locked")("rssi"); + val = names; + } return; case SUBDEV_PROP_BANDWIDTH: @@ -719,8 +727,13 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ val = false; return; - case SUBDEV_PROP_LO_LOCKED: - val = this->get_locked(); + case SUBDEV_PROP_SENSOR: + UHD_ASSERT_THROW(key.name == "lo_locked"); + val = sensor_value_t("LO", this->get_locked(), "locked", "unlocked"); + return; + + case SUBDEV_PROP_SENSOR_NAMES: + val = prop_names_t(1, "lo_locked"); return; case SUBDEV_PROP_BANDWIDTH: diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index e4e70b594..73bac029d 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -300,10 +300,6 @@ public: return _rx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as(); } - bool get_rx_lo_locked(size_t chan){ - return _rx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as(); - } - void set_rx_bandwidth(double bandwidth, size_t chan){ _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth; } @@ -312,10 +308,6 @@ public: return _rx_subdev(chan)[SUBDEV_PROP_BANDWIDTH].as(); } - double read_rssi(size_t chan){ - return _rx_subdev(chan)[SUBDEV_PROP_RSSI].as(); - } - dboard_iface::sptr get_rx_dboard_iface(size_t chan){ return _rx_dboard(chan)[DBOARD_PROP_DBOARD_IFACE].as(); } @@ -406,10 +398,6 @@ public: return _tx_subdev(chan)[SUBDEV_PROP_ANTENNA_NAMES].as(); } - bool get_tx_lo_locked(size_t chan){ - return _tx_subdev(chan)[SUBDEV_PROP_LO_LOCKED].as(); - } - void set_tx_bandwidth(double bandwidth, size_t chan){ _tx_subdev(chan)[SUBDEV_PROP_BANDWIDTH] = bandwidth; } -- cgit v1.2.3 From 4613f454c781d258d6d9b210ff1b9043a2125981 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 11 Feb 2011 21:52:13 -0800 Subject: uhd: added to_ calls to sensors to make it easy --- host/include/uhd/types/sensors.hpp | 19 +++++++++++-------- host/include/uhd/usrp/multi_usrp.hpp | 7 +++---- host/lib/types/sensors.cpp | 17 +++++++++++++++-- 3 files changed, 29 insertions(+), 14 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/types/sensors.hpp b/host/include/uhd/types/sensors.hpp index 6f003bb40..b6215367f 100644 --- a/host/include/uhd/types/sensors.hpp +++ b/host/include/uhd/types/sensors.hpp @@ -37,12 +37,6 @@ namespace uhd{ */ struct UHD_API sensor_value_t{ - //! typedef for the signed integer type - typedef signed int_type; - - //! typedef for the real number type - typedef double real_type; - /*! * Create a sensor value from a boolean. * \param name the name of the sensor @@ -66,7 +60,7 @@ namespace uhd{ */ sensor_value_t( const std::string &name, - int_type value, + signed value, const std::string &unit, const std::string &formatter = "%d" ); @@ -80,7 +74,7 @@ namespace uhd{ */ sensor_value_t( const std::string &name, - real_type value, + double value, const std::string &unit, const std::string &formatter = "%f" ); @@ -97,6 +91,15 @@ namespace uhd{ const std::string &unit ); + //! convert the sensor value to a boolean + bool to_bool(void) const; + + //! convert the sensor value to an integer + signed to_int(void) const; + + //! convert the sensor value to real number + double to_real(void) const; + //! The name of the sensor value const std::string name; diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index da52e6dce..3c8dd5fac 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -28,7 +28,6 @@ #include #include #include -#include //needed until deprecated routines removed #include #include #include @@ -395,7 +394,7 @@ public: * \return true for locked */ UHD_DEPRECATED bool get_rx_lo_locked(size_t chan = 0){ - return this->get_rx_sensor("lo_locked", chan).value == "true"; + return this->get_rx_sensor("lo_locked", chan).to_bool(); } /*! @@ -419,7 +418,7 @@ public: * \throw exception if RSSI readback not supported */ UHD_DEPRECATED double read_rssi(size_t chan = 0){ - return boost::lexical_cast(this->get_rx_sensor("rssi", chan).value); + return this->get_rx_sensor("rssi", chan).to_real(); } /*! @@ -593,7 +592,7 @@ public: * \return true for locked */ UHD_DEPRECATED bool get_tx_lo_locked(size_t chan = 0){ - return this->get_tx_sensor("lo_locked", chan).value == "true"; + return this->get_tx_sensor("lo_locked", chan).to_bool(); } /*! diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp index 2bff136a4..5f7115d70 100644 --- a/host/lib/types/sensors.cpp +++ b/host/lib/types/sensors.cpp @@ -17,6 +17,7 @@ #include #include +#include #include using namespace uhd; @@ -35,7 +36,7 @@ sensor_value_t::sensor_value_t( sensor_value_t::sensor_value_t( const std::string &name, - int_type value, + signed value, const std::string &unit, const std::string &formatter ): @@ -47,7 +48,7 @@ sensor_value_t::sensor_value_t( sensor_value_t::sensor_value_t( const std::string &name, - real_type value, + double value, const std::string &unit, const std::string &formatter ): @@ -79,3 +80,15 @@ std::string sensor_value_t::to_pp_string(void) const{ } UHD_THROW_INVALID_CODE_PATH(); } + +bool sensor_value_t::to_bool(void) const{ + return value == "true"; +} + +signed sensor_value_t::to_int(void) const{ + return boost::lexical_cast(value); +} + +double sensor_value_t::to_real(void) const{ + return boost::lexical_cast(value); +} -- cgit v1.2.3