diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-12 19:46:09 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-12 19:46:09 -0800 |
commit | 51e5396079d8af7cf8287b586ff2351a19ae8381 (patch) | |
tree | 166c580e317aff50cb00eb840cc05124aad04161 /lib/usrp/mboard | |
parent | 259f5babf1e1bc1595ad54c6588c1ff5117dc2e3 (diff) | |
download | uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.gz uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.bz2 uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.zip |
Reading the dboard ids from the usrp2.
Diffstat (limited to 'lib/usrp/mboard')
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 43 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_fw_common.h | 8 |
2 files changed, 48 insertions, 3 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp index 9de478672..f744dce59 100644 --- a/lib/usrp/mboard/usrp2.cpp +++ b/lib/usrp/mboard/usrp2.cpp @@ -16,12 +16,12 @@ // #include <uhd/usrp/mboard/usrp2.hpp> -#include "usrp2_fw_common.h" #include <uhd/device.hpp> -#include <boost/thread.hpp> #include <boost/lexical_cast.hpp> +#include <boost/format.hpp> #include <boost/thread.hpp> #include <netinet/in.h> +#include "usrp2_fw_common.h" using namespace uhd::usrp::mboard; @@ -74,6 +74,7 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ * Structors **********************************************************************/ usrp2::usrp2(const device_addr_t &device_addr){ + //initialize the transports for udp _udp_ctrl_transport = uhd::transport::udp::sptr( new uhd::transport::udp( device_addr["addr"], @@ -86,6 +87,15 @@ usrp2::usrp2(const device_addr_t &device_addr){ boost::lexical_cast<std::string>(USRP2_UDP_DATA_PORT) ) ); + //grab the dboard ids over the control line + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO); + usrp2_ctrl_data_t in_data = _ctrl_send_and_recv(out_data); + //TODO assert the control data id response + std::cout << boost::format("rx id 0x%.2x, tx id 0x%.2x") + % ntohs(in_data.data.dboard_ids.rx_id) + % ntohs(in_data.data.dboard_ids.tx_id) << std::endl; + //TODO setup the dboard manager with the dboard ids } usrp2::~usrp2(void){ @@ -93,6 +103,35 @@ usrp2::~usrp2(void){ } /*********************************************************************** + * Transactions + **********************************************************************/ +template <class T> T usrp2::_ctrl_send_and_recv(const T &out_data){ + //fill in the seq number and send + T out_copy = out_data; + out_copy.seq = htonl(++_ctrl_seq_num); + _udp_ctrl_transport->send(boost::asio::buffer(&out_copy, sizeof(T))); + + //loop and recieve until the time is up + size_t num_timeouts = 0; + while(true){ + uhd::shared_iovec iov = _udp_ctrl_transport->recv(); + if (iov.len < sizeof(T)){ + //sleep a little so we dont burn cpu + if (num_timeouts++ > 50) break; + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + }else{ + //handle the received data + T in_data = *reinterpret_cast<const T *>(iov.base); + if (ntohl(in_data.seq) == _ctrl_seq_num){ + return in_data; + } + //didnt get seq, continue on... + } + } + throw std::runtime_error("usrp2 no control response"); +} + +/*********************************************************************** * Get Properties **********************************************************************/ void usrp2::get(const wax::obj &, wax::obj &){ diff --git a/lib/usrp/mboard/usrp2_fw_common.h b/lib/usrp/mboard/usrp2_fw_common.h index 4ea9d5467..c98220d84 100644 --- a/lib/usrp/mboard/usrp2_fw_common.h +++ b/lib/usrp/mboard/usrp2_fw_common.h @@ -41,7 +41,9 @@ typedef enum{ USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO, USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO, USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE, - USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO + USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO, + USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO, + USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE } usrp2_ctrl_id_t; typedef struct{ @@ -50,6 +52,10 @@ typedef struct{ union{ uint32_t ip_addr; uint8_t mac_addr[6]; + struct { + uint16_t rx_id; + uint16_t tx_id; + } dboard_ids; /*struct { uint8_t bank; uint16_t ddr; |