diff options
Diffstat (limited to 'host/lib/usrp/usrp2')
| -rw-r--r-- | host/lib/usrp/usrp2/codec_ctrl.cpp | 6 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 16 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/mboard_impl.cpp | 11 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 38 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 12 | 
5 files changed, 59 insertions, 24 deletions
| diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 0fdcedf62..796888b8f 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -19,12 +19,10 @@  #include "ad9777_regs.hpp"  #include "ads62p44_regs.hpp"  #include "usrp2_regs.hpp" +#include <uhd/utils/log.hpp>  #include <uhd/exception.hpp>  #include <boost/cstdint.hpp>  #include <boost/foreach.hpp> -#include <iostream> - -static const bool codec_ctrl_debug = false;  using namespace uhd; @@ -167,7 +165,7 @@ private:      void send_ad9777_reg(boost::uint8_t addr){          boost::uint16_t reg = _ad9777_regs.get_write_reg(addr); -        if (codec_ctrl_debug) std::cout << "send_ad9777_reg: " << std::hex << reg << std::endl; +        UHD_LOGV(always) << "send_ad9777_reg: " << std::hex << reg << std::endl;          _iface->write_spi(              SPI_SS_AD9777, spi_config_t::EDGE_RISE,              reg, 16 diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 005be7ce4..33f249599 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -18,6 +18,8 @@  #include "../../transport/vrt_packet_handler.hpp"  #include "usrp2_impl.hpp"  #include "usrp2_regs.hpp" +#include <uhd/utils/log.hpp> +#include <uhd/utils/msg.hpp>  #include <uhd/exception.hpp>  #include <uhd/usrp/mboard_props.hpp>  #include <uhd/utils/byteswap.hpp> @@ -266,15 +268,15 @@ 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; +                if (metadata.event_code & underflow_flags) UHD_MSG(fastpath) << "U"; +                //else UHD_MSG(often) << "metadata.event_code " << metadata.event_code << std::endl;                  async_msg_fifo.push_with_pop_on_full(metadata);              }              else{                  //TODO unknown received packet, may want to print error...              }          }catch(const std::exception &e){ -            std::cerr << "Error (usrp2 recv pirate loop): " << e.what() << std::endl; +            UHD_MSG(error) << "Error (usrp2 recv pirate loop): " << e.what() << std::endl;          }      }  } @@ -314,13 +316,13 @@ void usrp2_impl::update_xport_channel_mapping(void){          subdev_spec_t rx_subdev_spec = _mboards[i]->get_link()[MBOARD_PROP_RX_SUBDEV_SPEC].as<subdev_spec_t>();          for (size_t j = 0; j < rx_subdev_spec.size(); j++){              _io_impl->recv_map.push_back(i*usrp2_mboard_impl::MAX_NUM_DSPS+j); -            //std::cout << "recv_map.back() " << _io_impl->recv_map.back() << std::endl; +            UHD_LOG << "recv_map.back() " << _io_impl->recv_map.back() << std::endl;          }          subdev_spec_t tx_subdev_spec = _mboards[i]->get_link()[MBOARD_PROP_TX_SUBDEV_SPEC].as<subdev_spec_t>();          for (size_t j = 0; j < tx_subdev_spec.size(); j++){              _io_impl->send_map.push_back(i*usrp2_mboard_impl::MAX_NUM_DSPS+j); -            //std::cout << "send_map.back() " << _io_impl->send_map.back() << std::endl; +            UHD_LOG << "send_map.back() " << _io_impl->send_map.back() << std::endl;          }      } @@ -395,7 +397,7 @@ static UHD_INLINE void extract_packet_info(      //handle the packet count / sequence number      if ((prev_info.packet_count+1)%16 != next_info.packet_count){ -        std::cerr << "O" << std::flush; //report overflow (drops in the kernel) +        UHD_MSG(fastpath) << "O"; //report overflow (drops in the kernel)      }      time = extract_time_spec(next_info); @@ -504,7 +506,7 @@ size_t usrp2_impl::get_max_recv_samps_per_packet(void) const{  }  void usrp2_impl::handle_overflow(size_t chan){ -    std::cerr << "O" << std::flush; +    UHD_MSG(fastpath) << "O";      ldiv_t indexes = ldiv(chan, usrp2_mboard_impl::NUM_RX_DSPS);      _mboards.at(indexes.quot)->handle_overflow(indexes.rem);  } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 8582fca38..bb4d90dd6 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -18,6 +18,8 @@  #include "usrp2_impl.hpp"  #include "usrp2_regs.hpp"  #include "fw_common.h" +#include <uhd/utils/log.hpp> +#include <uhd/utils/msg.hpp>  #include <uhd/utils/safe_call.hpp>  #include <uhd/exception.hpp>  #include <uhd/usrp/gps_ctrl.hpp> @@ -29,7 +31,6 @@  #include <uhd/types/sensors.hpp>  #include <boost/assign/list_of.hpp>  #include <boost/bind.hpp> -#include <iostream>  static const double mimo_clock_delay_usrp2_rev4 = 4.18e-9;  static const double mimo_clock_delay_usrp_n2xx = 3.55e-9; @@ -84,19 +85,19 @@ usrp2_mboard_impl::usrp2_mboard_impl(      _iface->lock_device(true);      //construct transports for dsp and async errors -    std::cout << "Making transport for DSP0..." << std::endl; +    UHD_LOG << "Making transport for DSP0..." << std::endl;      device.dsp_xports.push_back(udp_zero_copy::make(          device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_DSP0_PORT), device_addr      ));      init_xport(device.dsp_xports.back()); -    std::cout << "Making transport for DSP1..." << std::endl; +    UHD_LOG << "Making transport for DSP1..." << std::endl;      device.dsp_xports.push_back(udp_zero_copy::make(          device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_DSP1_PORT), device_addr      ));      init_xport(device.dsp_xports.back()); -    std::cout << "Making transport for ERR0..." << std::endl; +    UHD_LOG << "Making transport for ERR0..." << std::endl;      device.err_xports.push_back(udp_zero_copy::make(          device_addr["addr"], BOOST_STRINGIZE(USRP2_UDP_ERR0_PORT), device_addr_t()      )); @@ -144,7 +145,7 @@ usrp2_mboard_impl::usrp2_mboard_impl(      else {          _mimo_clocking_mode_is_master = (_iface->peek32(_iface->regs.status) & (1 << 8)) != 0;      } -    std::cout << boost::format("mboard%d MIMO %s") % _index % +    UHD_MSG(status) << boost::format("mboard%d is MIMO %s") % _index %          (_mimo_clocking_mode_is_master?"master":"slave") << std::endl;      //init the clock config diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 4bcc61444..2d80f145a 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -28,6 +28,7 @@  #include <boost/tokenizer.hpp>  #include <boost/thread/thread.hpp>  #include <boost/thread/barrier.hpp> +#include <boost/functional/hash.hpp>  #include <algorithm>  #include <iostream> @@ -46,6 +47,34 @@ static const boost::uint32_t MIN_PROTO_COMPAT_UART = 7;  // Map for virtual firmware regs (not very big so we can keep it here for now)  #define U2_FW_REG_LOCK_TIME 0 +#define U2_FW_REG_LOCK_GPID 1 + +//Define get_gpid() to get a globally unique identifier for this process. +//The gpid is implemented as a hash of the pid and a unique machine identifier. +#ifdef UHD_PLATFORM_WIN32 +#include <Windows.h> +static inline size_t get_gpid(void){ +    //extract volume serial number +    char szVolName[MAX_PATH+1], szFileSysName[MAX_PATH+1]; +    DWORD dwSerialNumber, dwMaxComponentLen, dwFileSysFlags; +    GetVolumeInformation("C:\\", szVolName, MAX_PATH, +        &dwSerialNumber, &dwMaxComponentLen, +        &dwFileSysFlags, szFileSysName, sizeof(szFileSysName)); + +    size_t hash = 0; +    boost::hash_combine(hash, GetCurrentProcessId()); +    boost::hash_combine(hash, dwSerialNumber); +    return hash; +} +#else +#include <unistd.h> +static inline size_t get_gpid(void){ +    size_t hash = 0; +    boost::hash_combine(hash, getpid()); +    boost::hash_combine(hash, gethostid()); +    return hash; +} +#endif  class usrp2_iface_impl : public usrp2_iface{  public: @@ -93,14 +122,21 @@ public:      bool is_device_locked(void){          boost::uint32_t lock_secs = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_TIME); +        boost::uint32_t lock_gpid = this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_PEEK32>(U2_FW_REG_LOCK_GPID);          boost::uint32_t curr_secs = this->peek32(this->regs.time64_secs_rb_imm); -        return (curr_secs - lock_secs < 3); //if the difference is larger, assume not locked anymore + +        //if the difference is larger, assume not locked anymore +        if (curr_secs - lock_secs >= 3) return false; + +        //otherwise only lock if the device hash is different that ours +        return lock_gpid != boost::uint32_t(get_gpid());      }      void lock_loop(boost::barrier &spawn_barrier){          spawn_barrier.wait();          try{ +            this->get_reg<boost::uint32_t, USRP2_REG_ACTION_FW_POKE32>(U2_FW_REG_LOCK_GPID, boost::uint32_t(get_gpid()));              while(true){                  //re-lock in loop                  boost::uint32_t curr_secs = this->peek32(this->regs.time64_secs_rb_imm); diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9c3fb9268..9947e71e7 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -17,13 +17,14 @@  #include "usrp2_impl.hpp"  #include "fw_common.h" +#include <uhd/utils/log.hpp> +#include <uhd/utils/msg.hpp>  #include <uhd/exception.hpp>  #include <uhd/transport/if_addrs.hpp>  #include <uhd/transport/udp_zero_copy.hpp>  #include <uhd/usrp/device_props.hpp>  #include <uhd/exception.hpp>  #include <uhd/utils/static.hpp> -#include <uhd/utils/warning.hpp>  #include <uhd/utils/byteswap.hpp>  #include <boost/assign/list_of.hpp>  #include <boost/format.hpp> @@ -32,7 +33,6 @@  #include <boost/bind.hpp>  #include <boost/asio/ip/address_v4.hpp>  #include <boost/asio.hpp> //used for htonl and ntohl -#include <iostream>  #include <vector>  using namespace uhd; @@ -103,7 +103,6 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){      const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);      while(true){          size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem)); -        //std::cout << len << "\n";          if (len > offsetof(usrp2_ctrl_data_t, data) and ntohl(ctrl_data_in->id) == USRP2_CTRL_ID_WAZZUP_DUDE){              //make a boost asio ipv4 with the raw addr in host byte order @@ -192,7 +191,6 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u      while (min_recv_mtu < max_recv_mtu){          size_t test_mtu = (max_recv_mtu/2 + min_recv_mtu/2 + 3) & ~3; -        //std::cout << "recv_mtu " << mtu.recv_mtu << std::endl;          ctrl_data->id = htonl(USRP2_CTRL_ID_HOLLER_AT_ME_BRO);          ctrl_data->proto_ver = htonl(USRP2_FW_COMPAT_NUM); @@ -209,7 +207,6 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u      while (min_send_mtu < max_send_mtu){          size_t test_mtu = (max_send_mtu/2 + min_send_mtu/2 + 3) & ~3; -        //std::cout << "send_mtu " << mtu.send_mtu << std::endl;          ctrl_data->id = htonl(USRP2_CTRL_ID_HOLLER_AT_ME_BRO);          ctrl_data->proto_ver = htonl(USRP2_FW_COMPAT_NUM); @@ -233,6 +230,7 @@ static mtu_result_t determine_mtu(const std::string &addr, const mtu_result_t &u   * Structors   **********************************************************************/  usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){ +    UHD_MSG(status) << "Opening a USRP2/N-Series device..." << std::endl;      device_addr_t device_addr = _device_addr;      //setup the dsp transport hints (default to a large recv buff) @@ -265,8 +263,8 @@ usrp2_impl::usrp2_impl(const device_addr_t &_device_addr){          device_addr["recv_frame_size"] = boost::lexical_cast<std::string>(mtu.recv_mtu);          device_addr["send_frame_size"] = boost::lexical_cast<std::string>(mtu.send_mtu); -        std::cout << boost::format("Current recv frame size: %d bytes") % mtu.recv_mtu << std::endl; -        std::cout << boost::format("Current send frame size: %d bytes") % mtu.send_mtu << std::endl; +        UHD_MSG(status) << boost::format("Current recv frame size: %d bytes") % mtu.recv_mtu << std::endl; +        UHD_MSG(status) << boost::format("Current send frame size: %d bytes") % mtu.send_mtu << std::endl;      }      catch(const uhd::not_implemented_error &){          //just ignore this error, makes older fw work... | 
