summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/types.cpp27
-rw-r--r--host/lib/usrp/usrp2/fw_common.h10
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp50
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.hpp7
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp4
5 files changed, 38 insertions, 60 deletions
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index ec9c8ac01..33eb550a1 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include <uhd/utils/assert.hpp>
#include <uhd/types/ranges.hpp>
#include <uhd/types/tune_result.hpp>
#include <uhd/types/clock_config.hpp>
@@ -164,17 +165,19 @@ std::string device_addr_t::to_string(void) const{
/***********************************************************************
* mac addr
**********************************************************************/
-mac_addr_t::mac_addr_t(const boost::uint8_t *bytes){
- std::copy(bytes, bytes+hlen, _bytes);
+mac_addr_t::mac_addr_t(const byte_vector_t &bytes){
+ UHD_ASSERT_THROW(bytes.size() == 6);
+ _bytes = bytes;
}
-mac_addr_t mac_addr_t::from_bytes(const boost::uint8_t *bytes){
+mac_addr_t mac_addr_t::from_bytes(const byte_vector_t &bytes){
return mac_addr_t(bytes);
}
mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){
- boost::uint8_t p[hlen] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB
+ byte_vector_t bytes = boost::assign::list_of
+ (0x00)(0x50)(0xC2)(0x85)(0x30)(0x00); // Matt's IAB
try{
//only allow patterns of xx:xx or xx:xx:xx:xx:xx:xx
@@ -189,7 +192,7 @@ mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){
int hex_num;
std::istringstream iss(hex_strs[i]);
iss >> std::hex >> hex_num;
- p[i] = boost::uint8_t(hex_num);
+ bytes[i] = boost::uint8_t(hex_num);
}
}
@@ -199,19 +202,19 @@ mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){
));
}
- return from_bytes(p);
+ return mac_addr_t::from_bytes(bytes);
}
-const boost::uint8_t *mac_addr_t::to_bytes(void) const{
+byte_vector_t mac_addr_t::to_bytes(void) const{
return _bytes;
}
std::string mac_addr_t::to_string(void) const{
- return str(
- boost::format("%02x:%02x:%02x:%02x:%02x:%02x")
- % int(to_bytes()[0]) % int(to_bytes()[1]) % int(to_bytes()[2])
- % int(to_bytes()[3]) % int(to_bytes()[4]) % int(to_bytes()[5])
- );
+ std::string addr = "";
+ BOOST_FOREACH(boost::uint8_t byte, this->to_bytes()){
+ addr += str(boost::format("%s%02x") % ((addr == "")?"":":") % int(byte));
+ }
+ return addr;
}
/***********************************************************************
diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h
index f28013cf6..75f5b1779 100644
--- a/host/lib/usrp/usrp2/fw_common.h
+++ b/host/lib/usrp/usrp2/fw_common.h
@@ -53,13 +53,8 @@ typedef enum{
//USRP2_CTRL_ID_FOR_SURE, //TODO error condition enums
//USRP2_CTRL_ID_SUX_MAN,
- USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO = 'a',
- USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE = 'A',
- USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO = 'b',
-
- USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO = 'm',
- USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE = 'M',
- USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO = 'n',
+ USRP2_CTRL_ID_WAZZUP_BRO = 'a',
+ USRP2_CTRL_ID_WAZZUP_DUDE = 'A',
USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO = 's',
USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE = 'S',
@@ -96,7 +91,6 @@ typedef struct{
_SINS_ uint32_t seq;
union{
_SINS_ uint32_t ip_addr;
- _SINS_ uint8_t mac_addr[6];
struct {
_SINS_ uint8_t dev;
_SINS_ uint8_t miso_edge;
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 7e62bedf0..9ae68d158 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -19,10 +19,11 @@
#include "usrp2_regs.hpp"
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/utils/assert.hpp>
+#include <uhd/utils/algorithm.hpp>
#include <uhd/types/mac_addr.hpp>
#include <uhd/types/dict.hpp>
#include <boost/bind.hpp>
-#include <boost/asio.hpp> //htonl and ntohl
+#include <boost/asio/ip/address_v4.hpp>
#include <boost/assign/list_of.hpp>
using namespace uhd;
@@ -129,30 +130,15 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){
//handle the other props
if (key.type() == typeid(std::string)){
if (key.as<std::string>() == "mac-addr"){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO);
-
- //send and recv
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE);
-
- //extract the address
- val = mac_addr_t::from_bytes(in_data.data.mac_addr).to_string();
+ byte_vector_t bytes = _iface->read_eeprom(I2C_ADDR_MBOARD, EE_MBOARD_MAC_ADDR, 6);
+ val = mac_addr_t::from_bytes(bytes).to_string();
return;
}
if (key.as<std::string>() == "ip-addr"){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO);
-
- //send and recv
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE);
-
- //extract the address
- val = boost::asio::ip::address_v4(ntohl(in_data.data.ip_addr)).to_string();
+ boost::asio::ip::address_v4::bytes_type bytes;
+ std::copy(_iface->read_eeprom(I2C_ADDR_MBOARD, EE_MBOARD_IP_ADDR, 4), bytes);
+ val = boost::asio::ip::address_v4(bytes).to_string();
return;
}
}
@@ -223,27 +209,15 @@ void usrp2_impl::mboard_set(const wax::obj &key, const wax::obj &val){
//handle the other props
if (key.type() == typeid(std::string)){
if (key.as<std::string>() == "mac-addr"){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO);
- mac_addr_t mac_addr = mac_addr_t::from_string(val.as<std::string>());
- std::copy(mac_addr.to_bytes(), mac_addr.to_bytes()+mac_addr_t::hlen, out_data.data.mac_addr);
-
- //send and recv
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE);
+ byte_vector_t bytes = mac_addr_t::from_string(val.as<std::string>()).to_bytes();
+ _iface->write_eeprom(I2C_ADDR_MBOARD, EE_MBOARD_MAC_ADDR, bytes);
return;
}
if (key.as<std::string>() == "ip-addr"){
- //setup the out data
- usrp2_ctrl_data_t out_data;
- out_data.id = htonl(USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO);
- out_data.data.ip_addr = htonl(boost::asio::ip::address_v4::from_string(val.as<std::string>()).to_ulong());
-
- //send and recv
- usrp2_ctrl_data_t in_data = _iface->ctrl_send_and_recv(out_data);
- UHD_ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE);
+ byte_vector_t bytes(4);
+ std::copy(boost::asio::ip::address_v4::from_string(val.as<std::string>()).to_bytes(), bytes);
+ _iface->write_eeprom(I2C_ADDR_MBOARD, EE_MBOARD_IP_ADDR, bytes);
return;
}
}
diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp
index 7158c58d0..caf6623e2 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.hpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.hpp
@@ -32,7 +32,14 @@
#define I2C_ADDR_MBOARD (I2C_DEV_EEPROM | 0x0)
#define I2C_ADDR_TX_DB (I2C_DEV_EEPROM | 0x4)
#define I2C_ADDR_RX_DB (I2C_DEV_EEPROM | 0x5)
+
+////////////////////////////////////////////////////////////////////////
+// EEPROM Layout
////////////////////////////////////////////////////////////////////////
+#define EE_MBOARD_REV_LSB 0x00 //1 byte
+#define EE_MBOARD_REV_MSB 0x01 //1 byte
+#define EE_MBOARD_MAC_ADDR 0x02 //6 bytes
+#define EE_MBOARD_IP_ADDR 0x0C //uint32, big-endian
/*!
* The usrp2 interface class:
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 5c1d7f9e3..2b7bdeea2 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -72,7 +72,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){
//send a hello control packet
usrp2_ctrl_data_t ctrl_data_out;
ctrl_data_out.proto_ver = htonl(USRP2_PROTO_VERSION);
- ctrl_data_out.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO);
+ ctrl_data_out.id = htonl(USRP2_CTRL_ID_WAZZUP_BRO);
udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out)));
//loop and recieve until the timeout
@@ -83,7 +83,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){
if (len >= sizeof(usrp2_ctrl_data_t)){
//handle the received data
switch(ntohl(ctrl_data_in.id)){
- case USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE:
+ 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));
device_addr_t new_addr;