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 | |
parent | 259f5babf1e1bc1595ad54c6588c1ff5117dc2e3 (diff) | |
download | uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.gz uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.tar.bz2 uhd-51e5396079d8af7cf8287b586ff2351a19ae8381.zip |
Reading the dboard ids from the usrp2.
-rw-r--r-- | apps/discover_usrps.cpp | 2 | ||||
-rw-r--r-- | firmware/microblaze/apps/txrx.c | 7 | ||||
-rw-r--r-- | firmware/microblaze/lib/db.h | 2 | ||||
-rw-r--r-- | firmware/microblaze/lib/db_init.c | 1 | ||||
-rw-r--r-- | include/uhd/usrp/mboard/usrp2.hpp | 9 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 43 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_fw_common.h | 8 |
7 files changed, 66 insertions, 6 deletions
diff --git a/apps/discover_usrps.cpp b/apps/discover_usrps.cpp index 52eb85b0a..92c90f89a 100644 --- a/apps/discover_usrps.cpp +++ b/apps/discover_usrps.cpp @@ -57,6 +57,8 @@ int main(int argc, char *argv[]){ std::cout << "-- USRP Device " << i << std::endl; std::cout << "--------------------------------------------------" << std::endl; std::cout << device_addrs[i] << std::endl << std::endl; + //make each device just to test (TODO: remove this) + device::make(device_addrs[i]); } return 0; diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 2cc414f02..8e71f2d8e 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -43,6 +43,7 @@ #include "clocks.h" #include <vrt/bits.h> #include "usrp2_fw_common.h" +#include <db.h> #define FW_SETS_SEQNO 1 // define to 0 or 1 (FIXME must be 1 for now) @@ -187,6 +188,12 @@ void handle_udp_ctrl_packet( memcpy(&ctrl_data_out.data.mac_addr, &mac_addr, sizeof(mac_addr)); break; + case USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO: + ctrl_data_out.id = USRP2_CTRL_ID_THESE_ARE_MY_DBOARD_IDS_DUDE; + ctrl_data_out.data.dboard_ids.tx_id = read_dboard_eeprom(I2C_ADDR_TX_A); + ctrl_data_out.data.dboard_ids.rx_id = read_dboard_eeprom(I2C_ADDR_RX_A); + break; + default: ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT; diff --git a/firmware/microblaze/lib/db.h b/firmware/microblaze/lib/db.h index cec960267..9cd0b379a 100644 --- a/firmware/microblaze/lib/db.h +++ b/firmware/microblaze/lib/db.h @@ -24,7 +24,9 @@ #define INCLUDED_DB_H #include <usrp2_types.h> +#include <usrp2_i2c_addr.h> +int read_dboard_eeprom(int i2c_addr); struct db_base; diff --git a/firmware/microblaze/lib/db_init.c b/firmware/microblaze/lib/db_init.c index 537078fb6..4d6081cbc 100644 --- a/firmware/microblaze/lib/db_init.c +++ b/firmware/microblaze/lib/db_init.c @@ -21,7 +21,6 @@ #include <memory_map.h> #include <i2c.h> -#include <usrp2_i2c_addr.h> #include <string.h> #include <stdio.h> #include <db.h> diff --git a/include/uhd/usrp/mboard/usrp2.hpp b/include/uhd/usrp/mboard/usrp2.hpp index 91f729f6f..709dbc1cc 100644 --- a/include/uhd/usrp/mboard/usrp2.hpp +++ b/include/uhd/usrp/mboard/usrp2.hpp @@ -22,7 +22,6 @@ #include <uhd/device_addr.hpp> #include <uhd/usrp/dboard/manager.hpp> #include <uhd/transport/udp.hpp> -#include <uhd/dict.hpp> namespace uhd{ namespace usrp{ namespace mboard{ @@ -46,9 +45,15 @@ private: void get(const wax::obj &, wax::obj &); void set(const wax::obj &, const wax::obj &); - uhd::dict<std::string, dboard::manager::sptr> _dboard_managers; + dboard::manager::sptr _dboard_manager; + uhd::transport::udp::sptr _udp_ctrl_transport; uhd::transport::udp::sptr _udp_data_transport; + + uint32_t _ctrl_seq_num; + //use this template for send/recv so this header + //does not need to know about internal structs + template <class T> T _ctrl_send_and_recv(const T &); }; }}} //namespace 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; |