From f991d3dc751e110425d4a0eed722f6de0fef4261 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 14 May 2011 19:57:03 -0700 Subject: usrp1: apply conditional disables/enables to rx and tx Scapped the old gnuradio code for information about VRQ_FPGA_SET_XX_ENABLE. It turns out that we should disabled + restore state when changing muxes or rates. The USRP seems to stream properly when receiving single and dual channel. Prior to this commit, tx was accicentally always disabled from a few commits ago. --- host/lib/usrp/usrp1/dsp_impl.cpp | 4 ++++ host/lib/usrp/usrp1/io_impl.cpp | 3 ++- host/lib/usrp/usrp1/mboard_impl.cpp | 12 ++++++++---- host/lib/usrp/usrp1/usrp1_ctrl.cpp | 4 ---- host/lib/usrp/usrp1/usrp1_ctrl.hpp | 5 +++++ host/lib/usrp/usrp1/usrp1_impl.cpp | 2 ++ host/lib/usrp/usrp1/usrp1_impl.hpp | 39 +++++++++++++++++++++++++++++++++++++ 7 files changed, 60 insertions(+), 9 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp index 9f1e4975a..1679c0470 100644 --- a/host/lib/usrp/usrp1/dsp_impl.cpp +++ b/host/lib/usrp/usrp1/dsp_impl.cpp @@ -113,7 +113,9 @@ void usrp1_impl::rx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh //TODO Poll every 100ms. Make it selectable? _rx_samps_per_poll_interval = size_t(0.1 * _clock_ctrl->get_master_clock_freq() / rate); + bool s = this->disable_rx(); _iface->poke32(FR_DECIM_RATE, _rx_dsp_decim/2 - 1); + this->restore_rx(s); } return; @@ -212,7 +214,9 @@ void usrp1_impl::tx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh //TODO Poll every 100ms. Make it selectable? _tx_samps_per_poll_interval = size_t(0.1 * _clock_ctrl->get_master_clock_freq() * 2 / rate); + bool s = this->disable_tx(); _iface->poke32(FR_INTERP_RATE, _tx_dsp_interp / 4 - 1); + this->restore_tx(s); return; } default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 22d078e70..7252ac587 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -240,12 +240,13 @@ void usrp1_impl::io_init(void){ boost::bind(&usrp1_impl::rx_stream_on_off, this, _1) ); + this->enable_tx(true); //always enabled rx_stream_on_off(false); _io_impl->flush_send_buff(); } void usrp1_impl::rx_stream_on_off(bool enb){ - return _iface->write_firmware_cmd(VRQ_FPGA_SET_RX_ENABLE, enb, 0, 0, 0); + this->enable_rx(enb); //drain any junk in the receive transport after stop streaming command while(not enb and _data_transport->get_recv_buff().get() != NULL){ /* NOP */ diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index cd04e7351..d6f6832a4 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -339,7 +339,7 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) //handle the get request conditioned on the key switch(key.as()){ - case MBOARD_PROP_RX_SUBDEV_SPEC: + case MBOARD_PROP_RX_SUBDEV_SPEC:{ _rx_subdev_spec = val.as(); if (_rx_subdev_spec.size() > this->get_num_ddcs()){ throw uhd::value_error(str(boost::format( @@ -349,10 +349,12 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) } verify_rx_subdev_spec(_rx_subdev_spec, _mboard_proxy->get_link()); //set the mux and set the number of rx channels + bool s = this->disable_rx(); _iface->poke32(FR_RX_MUX, calc_rx_mux(_rx_subdev_spec, _mboard_proxy->get_link())); - return; + this->restore_rx(s); + }return; - case MBOARD_PROP_TX_SUBDEV_SPEC: + case MBOARD_PROP_TX_SUBDEV_SPEC:{ _tx_subdev_spec = val.as(); if (_tx_subdev_spec.size() > this->get_num_ducs()){ throw uhd::value_error(str(boost::format( @@ -362,8 +364,10 @@ void usrp1_impl::mboard_set(const wax::obj &key, const wax::obj &val) } verify_tx_subdev_spec(_tx_subdev_spec, _mboard_proxy->get_link()); //set the mux and set the number of tx channels + bool s = this->disable_tx(); _iface->poke32(FR_TX_MUX, calc_tx_mux(_tx_subdev_spec, _mboard_proxy->get_link())); - return; + this->restore_tx(s); + }return; case MBOARD_PROP_EEPROM_MAP: // Step1: commit the map, writing only those values set. diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.cpp b/host/lib/usrp/usrp1/usrp1_ctrl.cpp index 96dc5d80c..2e6f6e014 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.cpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.cpp @@ -210,10 +210,6 @@ public: usrp_tx_reset(true); usrp_rx_reset(false); usrp_tx_reset(false); - - //enable - //usrp_rx_enable(true); //dont enable, enable means dont work - //usrp_tx_enable(true); } void usrp_load_fpga(std::string filestring) diff --git a/host/lib/usrp/usrp1/usrp1_ctrl.hpp b/host/lib/usrp/usrp1/usrp1_ctrl.hpp index 970ca2951..a6e4ffba7 100644 --- a/host/lib/usrp/usrp1/usrp1_ctrl.hpp +++ b/host/lib/usrp/usrp1/usrp1_ctrl.hpp @@ -108,6 +108,11 @@ public: unsigned char *buf, boost::uint16_t len) = 0; + //! enable/disable the rx path + virtual void usrp_rx_enable(bool on) = 0; + + //! enable/disable the tx path + virtual void usrp_tx_enable(bool on) = 0; }; #endif /* INCLUDED_USRP_CTRL_HPP */ diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index 57aae1b58..b1fa986d1 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -209,6 +209,8 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, } usrp1_impl::~usrp1_impl(void){ + UHD_SAFE_CALL(this->enable_rx(false);) + UHD_SAFE_CALL(this->enable_tx(false);) //Safely destruct all RAII objects in a device. //This prevents the mboard deconstructor from throwing, //which allows the device to be safely deconstructed. diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index f53894b29..69ad9b0a0 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -205,6 +205,45 @@ private: size_t get_num_ddcs(void); bool has_rx_halfband(void); bool has_tx_halfband(void); + + //handle the enables + bool _rx_enabled, _tx_enabled; + void enable_rx(bool enb){ + _rx_enabled = enb; + _ctrl_transport->usrp_rx_enable(enb); + } + void enable_tx(bool enb){ + _tx_enabled = enb; + _ctrl_transport->usrp_tx_enable(enb); + } + + //conditionally disable and enable rx + bool disable_rx(void){ + if (_rx_enabled){ + enable_rx(false); + return true; + } + return false; + } + void restore_rx(bool last){ + if (last != _rx_enabled){ + enable_rx(last); + } + } + + //conditionally disable and enable tx + bool disable_tx(void){ + if (_tx_enabled){ + enable_tx(false); + return true; + } + return false; + } + void restore_tx(bool last){ + if (last != _tx_enabled){ + enable_tx(last); + } + } }; #endif /* INCLUDED_USRP1_IMPL_HPP */ -- cgit v1.2.3 From 4b772ff4f3b1e388e150402beaf6567f3ea29e1c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 14 May 2011 20:25:52 -0700 Subject: usrp1: correct TX codec rate, it should also read 64e6 when probed We were using clock_rate*2 to simulate a codec rate of 128MHz. This reflected the old gnuradio API, but the rate between FPGA and codec is really 64MHz for both rx and tx directions. --- host/lib/usrp/usrp1/dsp_impl.cpp | 24 +++++++++--------------- host/lib/usrp/usrp1/mboard_impl.cpp | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/dsp_impl.cpp b/host/lib/usrp/usrp1/dsp_impl.cpp index 1679c0470..66b11b989 100644 --- a/host/lib/usrp/usrp1/dsp_impl.cpp +++ b/host/lib/usrp/usrp1/dsp_impl.cpp @@ -103,11 +103,8 @@ void usrp1_impl::rx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh { size_t rate = size_t(_clock_ctrl->get_master_clock_freq() / val.as()); - if ((rate & 0x01) || (rate < 4) || (rate > 256)) { - UHD_MSG(error) << "Decimation must be even and between 4 and 256" - << std::endl; - return; - } + //clip the rate to something in range: + rate = std::min(std::max(rate, 4), 256); _rx_dsp_decim = rate; //TODO Poll every 100ms. Make it selectable? @@ -166,11 +163,11 @@ void usrp1_impl::tx_dsp_get(const wax::obj &key_, wax::obj &val, size_t which_ds return; case DSP_PROP_CODEC_RATE: - val = _clock_ctrl->get_master_clock_freq() * 2; + val = _clock_ctrl->get_master_clock_freq(); return; case DSP_PROP_HOST_RATE: - val = _clock_ctrl->get_master_clock_freq() * 2 / _tx_dsp_interp; + val = _clock_ctrl->get_master_clock_freq() / _tx_dsp_interp; return; default: UHD_THROW_PROP_GET_ERROR(); @@ -201,21 +198,18 @@ void usrp1_impl::tx_dsp_set(const wax::obj &key_, const wax::obj &val, size_t wh case DSP_PROP_HOST_RATE: if (which_dsp != 0) return; //only for dsp[0] as this is vectorized { - size_t rate = size_t(_clock_ctrl->get_master_clock_freq() * 2 / val.as()); + size_t rate = size_t(_clock_ctrl->get_master_clock_freq() / val.as()); - if ((rate & 0x01) || (rate < 8) || (rate > 512)) { - UHD_MSG(error) << "Interpolation rate must be even and between 8 and 512" - << std::endl; - return; - } + //clip the rate to something in range: + rate = std::min(std::max(rate, 4), 256); _tx_dsp_interp = rate; //TODO Poll every 100ms. Make it selectable? - _tx_samps_per_poll_interval = size_t(0.1 * _clock_ctrl->get_master_clock_freq() * 2 / rate); + _tx_samps_per_poll_interval = size_t(0.1 * _clock_ctrl->get_master_clock_freq() / rate); bool s = this->disable_tx(); - _iface->poke32(FR_INTERP_RATE, _tx_dsp_interp / 4 - 1); + _iface->poke32(FR_INTERP_RATE, _tx_dsp_interp/2 - 1); this->restore_tx(s); return; } diff --git a/host/lib/usrp/usrp1/mboard_impl.cpp b/host/lib/usrp/usrp1/mboard_impl.cpp index d6f6832a4..e9108e4f1 100644 --- a/host/lib/usrp/usrp1/mboard_impl.cpp +++ b/host/lib/usrp/usrp1/mboard_impl.cpp @@ -214,8 +214,8 @@ void usrp1_impl::mboard_init(void) // Normal mode with no loopback or Rx counting _iface->poke32(FR_MODE, 0x00000000); _iface->poke32(FR_DEBUG_EN, 0x00000000); - _iface->poke32(FR_RX_SAMPLE_RATE_DIV, 0x00000001); - _iface->poke32(FR_TX_SAMPLE_RATE_DIV, 0x00000003); + _iface->poke32(FR_RX_SAMPLE_RATE_DIV, 0x00000001); //divide by 2 + _iface->poke32(FR_TX_SAMPLE_RATE_DIV, 0x00000001); //divide by 2 _iface->poke32(FR_DC_OFFSET_CL_EN, 0x0000000f); // Reset offset correction registers -- cgit v1.2.3 From ea5ce50a465e714c63196f52df97fb3e927e701c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 14 May 2011 17:11:05 -0700 Subject: uhd: replace managed buffer shared pointer w/ intrusive pointer to reduce overhead --- host/include/uhd/transport/zero_copy.hpp | 31 ++++++++++++++++++++-- host/lib/CMakeLists.txt | 4 --- host/lib/transport/libusb1_zero_copy.cpp | 12 ++------- host/lib/transport/udp_zero_copy.cpp | 12 ++------- host/lib/usrp/usrp1/io_impl.cpp | 19 +++---------- .../usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp | 12 ++------- 6 files changed, 39 insertions(+), 51 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp index 092028d09..f80c738aa 100644 --- a/host/include/uhd/transport/zero_copy.hpp +++ b/host/include/uhd/transport/zero_copy.hpp @@ -21,9 +21,16 @@ #include #include #include +#include namespace uhd{ namespace transport{ + //! Create smart pointer to a reusable managed buffer + template UHD_INLINE boost::intrusive_ptr make_managed_buffer(T *p){ + p->_ref_count = 1; //reset the count to 1 reference + return boost::intrusive_ptr(p, false); + } + /*! * A managed receive buffer: * Contains a reference to transport-managed memory, @@ -31,7 +38,7 @@ namespace uhd{ namespace transport{ */ class UHD_API managed_recv_buffer{ public: - typedef boost::shared_ptr sptr; + typedef boost::intrusive_ptr sptr; /*! * Signal to the transport that we are done with the buffer. @@ -59,8 +66,18 @@ namespace uhd{ namespace transport{ private: virtual const void *get_buff(void) const = 0; virtual size_t get_size(void) const = 0; + + public: int _ref_count; }; + UHD_INLINE void intrusive_ptr_add_ref(managed_recv_buffer *p){ + ++(p->_ref_count); + } + + UHD_INLINE void intrusive_ptr_release(managed_recv_buffer *p){ + if (--(p->_ref_count) == 0) p->release(); + } + /*! * A managed send buffer: * Contains a reference to transport-managed memory, @@ -68,7 +85,7 @@ namespace uhd{ namespace transport{ */ class UHD_API managed_send_buffer{ public: - typedef boost::shared_ptr sptr; + typedef boost::intrusive_ptr sptr; /*! * Signal to the transport that we are done with the buffer. @@ -97,8 +114,18 @@ namespace uhd{ namespace transport{ private: virtual void *get_buff(void) const = 0; virtual size_t get_size(void) const = 0; + + public: int _ref_count; }; + UHD_INLINE void intrusive_ptr_add_ref(managed_send_buffer *p){ + ++(p->_ref_count); + } + + UHD_INLINE void intrusive_ptr_release(managed_send_buffer *p){ + if (--(p->_ref_count) == 0) p->commit(0); + } + /*! * A zero-copy interface for transport objects. * Provides a way to get send and receive buffers diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index fca4730d8..ebb211566 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -15,10 +15,6 @@ # along with this program. If not, see . # -#Creating a shared pointer itself has allocation overhead. -#Define the quick allocator to reduce fast-path overhead. -ADD_DEFINITIONS(-DBOOST_SP_USE_QUICK_ALLOCATOR) - ######################################################################## # Helpful Macros ######################################################################## diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index d4cfab422..28bea978b 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -73,14 +73,10 @@ public: sptr get_new(void){ _expired = false; - return sptr(this, &libusb_zero_copy_mrb::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *obj){ - static_cast(obj)->release(); - } - const void *get_buff(void) const{return _lut->buffer;} size_t get_size(void) const{return _lut->actual_length;} @@ -108,14 +104,10 @@ public: sptr get_new(void){ _expired = false; - return sptr(this, &libusb_zero_copy_msb::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *obj){ - static_cast(obj)->commit(0); - } - void *get_buff(void) const{return _lut->buffer;} size_t get_size(void) const{return _lut->length;} diff --git a/host/lib/transport/udp_zero_copy.cpp b/host/lib/transport/udp_zero_copy.cpp index c3ba085bf..8c97e1e99 100644 --- a/host/lib/transport/udp_zero_copy.cpp +++ b/host/lib/transport/udp_zero_copy.cpp @@ -52,16 +52,12 @@ public: sptr get_new(size_t len){ _len = len; - return sptr(this, &udp_zero_copy_asio_mrb::fake_deleter); + return make_managed_buffer(this); } template T cast(void) const{return static_cast(_mem);} private: - static void fake_deleter(void *obj){ - static_cast(obj)->release(); - } - const void *get_buff(void) const{return _mem;} size_t get_size(void) const{return _len;} @@ -90,14 +86,10 @@ public: sptr get_new(size_t len){ _len = len; - return sptr(this, &udp_zero_copy_asio_msb::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *obj){ - static_cast(obj)->commit(0); - } - void *get_buff(void) const{return _mem;} size_t get_size(void) const{return _len;} diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 7252ac587..8ac2696eb 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -61,39 +61,28 @@ class offset_managed_send_buffer : public managed_send_buffer{ public: typedef boost::function commit_cb_type; offset_managed_send_buffer(const commit_cb_type &commit_cb): - _expired(true), _commit_cb(commit_cb) + _commit_cb(commit_cb) { /* NOP */ } - bool expired(void){return _expired;} - void commit(size_t size){ - if (_expired) return; - this->_commit_cb(_curr_buff, _next_buff, size); - _expired = true; + if (size != 0) this->_commit_cb(_curr_buff, _next_buff, size); } sptr get_new( offset_send_buffer &curr_buff, offset_send_buffer &next_buff ){ - _expired = false; _curr_buff = curr_buff; _next_buff = next_buff; - return sptr(this, &offset_managed_send_buffer::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *){ - //dont do anything and assume the bastard committed it - //static_cast(obj)->commit(0); - } - void *get_buff(void) const{return _curr_buff.buff->cast() + _curr_buff.offset;} size_t get_size(void) const{return _curr_buff.buff->size() - _curr_buff.offset;} - bool _expired; offset_send_buffer _curr_buff, _next_buff; commit_cb_type _commit_cb; }; @@ -210,7 +199,7 @@ void usrp1_impl::io_impl::flush_send_buff(void){ bool usrp1_impl::io_impl::get_send_buffs( vrt_packet_handler::managed_send_buffs_t &buffs ){ - UHD_ASSERT_THROW(omsb.expired() and buffs.size() == 1); + UHD_ASSERT_THROW(buffs.size() == 1); //try to get a new managed buffer with timeout offset_send_buffer next_buff(data_transport->get_send_buff(send_timeout)); 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 26774aeda..bb421507a 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 @@ -51,14 +51,10 @@ public: sptr get_new(void){ if (fp_verbose) UHD_LOGV(always) << " make_recv_buff: " << get_size() << std::endl; _info->flags = RB_USER_PROCESS; //claim the frame - return sptr(this, &usrp_e100_mmap_zero_copy_mrb::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *obj){ - static_cast(obj)->release(); - } - const void *get_buff(void) const{return _mem;} size_t get_size(void) const{return _info->len;} @@ -90,14 +86,10 @@ public: sptr get_new(void){ if (fp_verbose) UHD_LOGV(always) << " make_send_buff: " << get_size() << std::endl; _info->flags = RB_USER_PROCESS; //claim the frame - return sptr(this, &usrp_e100_mmap_zero_copy_msb::fake_deleter); + return make_managed_buffer(this); } private: - static void fake_deleter(void *obj){ - static_cast(obj)->commit(0); - } - void *get_buff(void) const{return _mem;} size_t get_size(void) const{return _len;} -- cgit v1.2.3