From dbc65d928362b983d8f6113319db87841a5b159d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 4 Jun 2010 12:00:23 -0700 Subject: recv discovery packets with max size buffer (we dont know what to expect) --- host/lib/usrp/usrp2/usrp2_impl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index af3ec216a..1e6e02dd1 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -76,16 +76,17 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); //loop and recieve until the timeout + boost::uint8_t usrp2_ctrl_data_in_mem[1500]; //allocate MTU bytes for recv + usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast(usrp2_ctrl_data_in_mem); while(true){ - usrp2_ctrl_data_t ctrl_data_in; - size_t len = udp_transport->recv(asio::buffer(&ctrl_data_in, sizeof(ctrl_data_in))); + size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem)); //std::cout << len << "\n"; if (len >= sizeof(usrp2_ctrl_data_t)){ //handle the received data - switch(ntohl(ctrl_data_in.id)){ + switch(ntohl(ctrl_data_in->id)){ case USRP2_CTRL_ID_WAZZUP_DUDE: //make a boost asio ipv4 with the raw addr in host byte order - boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in.data.ip_addr)); + boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); device_addr_t new_addr; new_addr["name"] = "USRP2"; new_addr["addr"] = ip_addr.to_string(); -- cgit v1.2.3 From f2b560d5f8d19bf6bbd86802e03f061ecede78ec Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 4 Jun 2010 12:16:09 -0700 Subject: Prepend usrp2 onto the helper classes in usrp2 impl to avoid symbol conflicts. --- host/lib/usrp/usrp2/clock_ctrl.cpp | 10 +++++----- host/lib/usrp/usrp2/clock_ctrl.hpp | 4 ++-- host/lib/usrp/usrp2/codec_ctrl.cpp | 10 +++++----- host/lib/usrp/usrp2/codec_ctrl.hpp | 4 ++-- host/lib/usrp/usrp2/dboard_iface.cpp | 11 +++++++---- host/lib/usrp/usrp2/serdes_ctrl.cpp | 10 +++++----- host/lib/usrp/usrp2/serdes_ctrl.hpp | 4 ++-- host/lib/usrp/usrp2/usrp2_impl.cpp | 6 +++--- host/lib/usrp/usrp2/usrp2_impl.hpp | 8 ++++---- 9 files changed, 35 insertions(+), 32 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 4c5207203..94920143d 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -25,9 +25,9 @@ using namespace uhd; /*! * A usrp2 clock control specific to the ad9510 ic. */ -class clock_ctrl_impl : public clock_ctrl{ +class usrp2_clock_ctrl_impl : public usrp2_clock_ctrl{ public: - clock_ctrl_impl(usrp2_iface::sptr iface){ + usrp2_clock_ctrl_impl(usrp2_iface::sptr iface){ _iface = iface; _ad9510_regs.cp_current_setting = ad9510_regs_t::CP_CURRENT_SETTING_3_0MA; @@ -68,7 +68,7 @@ public: } - ~clock_ctrl_impl(void){ + ~usrp2_clock_ctrl_impl(void){ /* private clock enables, must be set here */ this->enable_dac_clock(false); this->enable_adc_clock(false); @@ -158,6 +158,6 @@ private: /*********************************************************************** * Public make function for the ad9510 clock control **********************************************************************/ -clock_ctrl::sptr clock_ctrl::make(usrp2_iface::sptr iface){ - return sptr(new clock_ctrl_impl(iface)); +usrp2_clock_ctrl::sptr usrp2_clock_ctrl::make(usrp2_iface::sptr iface){ + return sptr(new usrp2_clock_ctrl_impl(iface)); } diff --git a/host/lib/usrp/usrp2/clock_ctrl.hpp b/host/lib/usrp/usrp2/clock_ctrl.hpp index 706bf4246..122b5e633 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.hpp +++ b/host/lib/usrp/usrp2/clock_ctrl.hpp @@ -22,9 +22,9 @@ #include #include -class clock_ctrl : boost::noncopyable{ +class usrp2_clock_ctrl : boost::noncopyable{ public: - typedef boost::shared_ptr sptr; + typedef boost::shared_ptr sptr; /*! * Make a clock config for the ad9510 ic. diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index d698216ba..abd840027 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -29,9 +29,9 @@ using namespace uhd; /*! * A usrp2 codec control specific to the ad9777 ic. */ -class codec_ctrl_impl : public codec_ctrl{ +class usrp2_codec_ctrl_impl : public usrp2_codec_ctrl{ public: - codec_ctrl_impl(usrp2_iface::sptr iface){ + usrp2_codec_ctrl_impl(usrp2_iface::sptr iface){ _iface = iface; //setup the ad9777 dac @@ -60,7 +60,7 @@ public: _iface->poke32(FR_MISC_CTRL_ADC, FRF_MISC_CTRL_ADC_ON); } - ~codec_ctrl_impl(void){ + ~usrp2_codec_ctrl_impl(void){ //power-down dac _ad9777_regs.power_down_mode = 1; this->send_ad9777_reg(0); @@ -86,6 +86,6 @@ private: /*********************************************************************** * Public make function for the usrp2 codec control **********************************************************************/ -codec_ctrl::sptr codec_ctrl::make(usrp2_iface::sptr iface){ - return sptr(new codec_ctrl_impl(iface)); +usrp2_codec_ctrl::sptr usrp2_codec_ctrl::make(usrp2_iface::sptr iface){ + return sptr(new usrp2_codec_ctrl_impl(iface)); } diff --git a/host/lib/usrp/usrp2/codec_ctrl.hpp b/host/lib/usrp/usrp2/codec_ctrl.hpp index 0ee52f476..ad014e0e1 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.hpp +++ b/host/lib/usrp/usrp2/codec_ctrl.hpp @@ -22,9 +22,9 @@ #include #include -class codec_ctrl : boost::noncopyable{ +class usrp2_codec_ctrl : boost::noncopyable{ public: - typedef boost::shared_ptr sptr; + typedef boost::shared_ptr sptr; /*! * Make a codec control for the DAC and ADC. diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 2621d43b4..5933f8e40 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -33,7 +33,7 @@ using namespace boost::assign; class usrp2_dboard_iface : public dboard_iface{ public: - usrp2_dboard_iface(usrp2_iface::sptr iface, clock_ctrl::sptr clock_ctrl); + usrp2_dboard_iface(usrp2_iface::sptr iface, usrp2_clock_ctrl::sptr clock_ctrl); ~usrp2_dboard_iface(void); void write_aux_dac(unit_t, int, float); @@ -68,7 +68,7 @@ public: private: usrp2_iface::sptr _iface; - clock_ctrl::sptr _clock_ctrl; + usrp2_clock_ctrl::sptr _clock_ctrl; boost::uint32_t _ddr_shadow; boost::uint32_t _gpio_shadow; @@ -81,7 +81,7 @@ private: **********************************************************************/ dboard_iface::sptr make_usrp2_dboard_iface( usrp2_iface::sptr iface, - clock_ctrl::sptr clock_ctrl + usrp2_clock_ctrl::sptr clock_ctrl ){ return dboard_iface::sptr(new usrp2_dboard_iface(iface, clock_ctrl)); } @@ -89,7 +89,10 @@ dboard_iface::sptr make_usrp2_dboard_iface( /*********************************************************************** * Structors **********************************************************************/ -usrp2_dboard_iface::usrp2_dboard_iface(usrp2_iface::sptr iface, clock_ctrl::sptr clock_ctrl){ +usrp2_dboard_iface::usrp2_dboard_iface( + usrp2_iface::sptr iface, + usrp2_clock_ctrl::sptr clock_ctrl +){ _iface = iface; _clock_ctrl = clock_ctrl; _ddr_shadow = 0; diff --git a/host/lib/usrp/usrp2/serdes_ctrl.cpp b/host/lib/usrp/usrp2/serdes_ctrl.cpp index dde22b499..31708d377 100644 --- a/host/lib/usrp/usrp2/serdes_ctrl.cpp +++ b/host/lib/usrp/usrp2/serdes_ctrl.cpp @@ -23,14 +23,14 @@ using namespace uhd; /*! * A usrp2 serdes control implementation */ -class serdes_ctrl_impl : public serdes_ctrl{ +class usrp2_serdes_ctrl_impl : public usrp2_serdes_ctrl{ public: - serdes_ctrl_impl(usrp2_iface::sptr iface){ + usrp2_serdes_ctrl_impl(usrp2_iface::sptr iface){ _iface = iface; _iface->poke32(FR_MISC_CTRL_SERDES, FRF_MISC_CTRL_SERDES_ENABLE | FRF_MISC_CTRL_SERDES_RXEN); } - ~serdes_ctrl_impl(void){ + ~usrp2_serdes_ctrl_impl(void){ _iface->poke32(FR_MISC_CTRL_SERDES, 0); //power-down } @@ -41,6 +41,6 @@ private: /*********************************************************************** * Public make function for the usrp2 serdes control **********************************************************************/ -serdes_ctrl::sptr serdes_ctrl::make(usrp2_iface::sptr iface){ - return sptr(new serdes_ctrl_impl(iface)); +usrp2_serdes_ctrl::sptr usrp2_serdes_ctrl::make(usrp2_iface::sptr iface){ + return sptr(new usrp2_serdes_ctrl_impl(iface)); } diff --git a/host/lib/usrp/usrp2/serdes_ctrl.hpp b/host/lib/usrp/usrp2/serdes_ctrl.hpp index 586238739..3c909c531 100644 --- a/host/lib/usrp/usrp2/serdes_ctrl.hpp +++ b/host/lib/usrp/usrp2/serdes_ctrl.hpp @@ -22,9 +22,9 @@ #include #include -class serdes_ctrl : boost::noncopyable{ +class usrp2_serdes_ctrl : boost::noncopyable{ public: - typedef boost::shared_ptr sptr; + typedef boost::shared_ptr sptr; /*! * Make a serdes control object for the usrp2 serdes port. diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 1e6e02dd1..58f0696b5 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -148,9 +148,9 @@ usrp2_impl::usrp2_impl( //make a new interface for usrp2 stuff _iface = usrp2_iface::make(ctrl_transport); - _clock_ctrl = clock_ctrl::make(_iface); - _codec_ctrl = codec_ctrl::make(_iface); - _serdes_ctrl = serdes_ctrl::make(_iface); + _clock_ctrl = usrp2_clock_ctrl::make(_iface); + _codec_ctrl = usrp2_codec_ctrl::make(_iface); + _serdes_ctrl = usrp2_serdes_ctrl::make(_iface); //load the allowed decim/interp rates //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4) diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 40c193866..90306a85f 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -43,7 +43,7 @@ */ uhd::usrp::dboard_iface::sptr make_usrp2_dboard_iface( usrp2_iface::sptr iface, - clock_ctrl::sptr clk_ctrl + usrp2_clock_ctrl::sptr clk_ctrl ); /*! @@ -134,9 +134,9 @@ private: //interfaces usrp2_iface::sptr _iface; - clock_ctrl::sptr _clock_ctrl; - codec_ctrl::sptr _codec_ctrl; - serdes_ctrl::sptr _serdes_ctrl; + usrp2_clock_ctrl::sptr _clock_ctrl; + usrp2_codec_ctrl::sptr _codec_ctrl; + usrp2_serdes_ctrl::sptr _serdes_ctrl; /******************************************************************* * Deal with the rx and tx packet sizes -- cgit v1.2.3 From 89541d92664b98d8763492d4585eb2528df9e1f3 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 4 Jun 2010 12:23:20 -0700 Subject: also use an mtu size recv buffer for the control packet recv --- host/lib/usrp/usrp2/usrp2_iface.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index e43b9678e..e12c84d45 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -146,18 +146,19 @@ public: _ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(usrp2_ctrl_data_t))); //loop until we get the packet or timeout + boost::uint8_t usrp2_ctrl_data_in_mem[1500]; //allocate MTU bytes for recv + usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast(usrp2_ctrl_data_in_mem); while(true){ - usrp2_ctrl_data_t in_data; - size_t len = _ctrl_transport->recv(boost::asio::buffer(&in_data, sizeof(in_data))); - if(len >= sizeof(boost::uint32_t) and ntohl(in_data.proto_ver) != USRP2_PROTO_VERSION){ + size_t len = _ctrl_transport->recv(boost::asio::buffer(usrp2_ctrl_data_in_mem)); + if(len >= sizeof(boost::uint32_t) and ntohl(ctrl_data_in->proto_ver) != USRP2_PROTO_VERSION){ throw std::runtime_error(str( boost::format("Expected protocol version %d, but got %d\n" "The firmware build does not match the host code build." - ) % int(USRP2_PROTO_VERSION) % ntohl(in_data.proto_ver) + ) % int(USRP2_PROTO_VERSION) % ntohl(ctrl_data_in->proto_ver) )); } - if (len >= sizeof(usrp2_ctrl_data_t) and ntohl(in_data.seq) == _ctrl_seq_num){ - return in_data; + if (len >= sizeof(usrp2_ctrl_data_t) and ntohl(ctrl_data_in->seq) == _ctrl_seq_num){ + return *ctrl_data_in; } if (len == 0) break; //timeout //didnt get seq or bad packet, continue looking... -- cgit v1.2.3 From 4f0736ef7ce93d58f0768d99257b2624d5711490 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 4 Jun 2010 12:32:06 -0700 Subject: move get clock rate into clock control --- host/lib/usrp/usrp2/clock_ctrl.cpp | 4 ++++ host/lib/usrp/usrp2/clock_ctrl.hpp | 6 ++++++ host/lib/usrp/usrp2/dboard_iface.cpp | 2 +- host/lib/usrp/usrp2/usrp2_iface.cpp | 7 ------- host/lib/usrp/usrp2/usrp2_iface.hpp | 6 ------ host/lib/usrp/usrp2/usrp2_impl.hpp | 4 ++-- 6 files changed, 13 insertions(+), 16 deletions(-) (limited to 'host/lib/usrp/usrp2') diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index 94920143d..d9baa66cf 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -110,6 +110,10 @@ public: this->update_regs(); } + double get_master_clock_rate(void){ + return 100e6; + } + private: /*! * Write a single register to the spi regs. diff --git a/host/lib/usrp/usrp2/clock_ctrl.hpp b/host/lib/usrp/usrp2/clock_ctrl.hpp index 122b5e633..0ad8d9532 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.hpp +++ b/host/lib/usrp/usrp2/clock_ctrl.hpp @@ -33,6 +33,12 @@ public: */ static sptr make(usrp2_iface::sptr iface); + /*! + * Get the master clock frequency for the fpga. + * \return the clock frequency in Hz + */ + virtual double get_master_clock_rate(void) = 0; + /*! * Enable/disable the rx dboard clock. * \param enb true to enable diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 5933f8e40..feee0a970 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -117,7 +117,7 @@ usrp2_dboard_iface::~usrp2_dboard_iface(void){ * Clocks **********************************************************************/ double usrp2_dboard_iface::get_clock_rate(unit_t){ - return _iface->get_master_clock_freq(); + return _clock_ctrl->get_master_clock_rate(); } void usrp2_dboard_iface::set_clock_enabled(unit_t unit, bool enb){ diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index e12c84d45..6e0d3266a 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -166,13 +166,6 @@ public: throw std::runtime_error("usrp2 no control response"); } -/*********************************************************************** - * Master Clock! Ahhhhh - **********************************************************************/ - double get_master_clock_freq(void){ - return 100e6; - } - private: //this lovely lady makes it all possible transport::udp_simple::sptr _ctrl_transport; diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index caf6623e2..7b2a3a89d 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -108,12 +108,6 @@ public: size_t num_bits, bool readback ) = 0; - - /*! - * Get the master clock frequency. - * \return the frequency in Hz - */ - virtual double get_master_clock_freq(void) = 0; }; #endif /* INCLUDED_USRP2_IFACE_HPP */ diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 90306a85f..6ad151a0a 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -124,8 +124,8 @@ public: ); private: - double get_master_clock_freq(void){ - return _iface->get_master_clock_freq(); + inline double get_master_clock_freq(void){ + return _clock_ctrl->get_master_clock_rate(); } //device properties interface -- cgit v1.2.3