diff options
| -rw-r--r-- | firmware/microblaze/apps/txrx_uhd.c | 23 | ||||
| -rw-r--r-- | host/include/uhd/types/mac_addr.hpp | 16 | ||||
| -rw-r--r-- | host/include/uhd/utils/algorithm.hpp | 5 | ||||
| -rw-r--r-- | host/lib/types.cpp | 27 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/fw_common.h | 10 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/mboard_impl.cpp | 50 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.hpp | 7 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 4 | 
8 files changed, 53 insertions, 89 deletions
| diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index db830fa51..7ad4ab110 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -185,7 +185,7 @@ void handle_udp_ctrl_packet(          printf("!Error in control packet handler: Expected protocol version %d, but got %d\n",              USRP2_PROTO_VERSION, ctrl_data_in->proto_ver          ); -        ctrl_data_in_id = USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO; +        ctrl_data_in_id = USRP2_CTRL_ID_WAZZUP_BRO;      }      //ensure that this is not a short packet @@ -209,28 +209,11 @@ void handle_udp_ctrl_packet(      /*******************************************************************       * Addressing       ******************************************************************/ -    case USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO: -        ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE; +    case USRP2_CTRL_ID_WAZZUP_BRO: +        ctrl_data_out.id = USRP2_CTRL_ID_WAZZUP_DUDE;          memcpy(&ctrl_data_out.data.ip_addr, get_ip_addr(), sizeof(struct ip_addr));          break; -    case USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO: -        ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE; -        set_ip_addr((struct ip_addr *)&ctrl_data_in->data.ip_addr); -        memcpy(&ctrl_data_out.data.ip_addr, get_ip_addr(), sizeof(struct ip_addr)); -        break; - -    case USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO: -        ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE; -        memcpy(&ctrl_data_out.data.mac_addr, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); -        break; - -    case USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO: -        ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE; -        ethernet_set_mac_addr((eth_mac_addr_t *)&ctrl_data_in->data.mac_addr); -        memcpy(&ctrl_data_out.data.mac_addr, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); -        break; -      /*******************************************************************       * SPI       ******************************************************************/ diff --git a/host/include/uhd/types/mac_addr.hpp b/host/include/uhd/types/mac_addr.hpp index 3cd1fe86b..034b6a348 100644 --- a/host/include/uhd/types/mac_addr.hpp +++ b/host/include/uhd/types/mac_addr.hpp @@ -19,7 +19,7 @@  #define INCLUDED_UHD_TYPES_MAC_ADDR_HPP  #include <uhd/config.hpp> -#include <boost/cstdint.hpp> +#include <uhd/types/serial.hpp>  #include <string>  namespace uhd{ @@ -30,14 +30,12 @@ namespace uhd{      */      class UHD_API mac_addr_t{      public: -        static const size_t hlen = 6; -          /*!           * Create a mac address a byte array. -         * \param bytes a pointer for the byte array +         * \param bytes a vector of bytes           * \return a new mac address           */ -        static mac_addr_t from_bytes(const boost::uint8_t *bytes); +        static mac_addr_t from_bytes(const byte_vector_t &bytes);          /*!           * Create a mac address from a string. @@ -48,9 +46,9 @@ namespace uhd{          /*!           * Get the byte representation of the mac address. -         * \return a pointer to the internal byte array +         * \return a vector of bytes           */ -        const boost::uint8_t *to_bytes(void) const; +        byte_vector_t to_bytes(void) const;          /*!           * Get the string representation of this mac address. @@ -59,8 +57,8 @@ namespace uhd{          std::string to_string(void) const;      private: -        mac_addr_t(const boost::uint8_t *bytes); //private constructor -        boost::uint8_t _bytes[hlen]; //internal representation +        mac_addr_t(const byte_vector_t &bytes); //private constructor +        byte_vector_t _bytes; //internal representation      };  } //namespace uhd diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 72b655745..146b56c63 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -26,6 +26,11 @@   */  namespace std{ +    template<typename RangeSrc, typename RangeDst> inline +    void copy(const RangeSrc &src, RangeDst &dst){ +        std::copy(boost::begin(src), boost::end(src), boost::begin(dst)); +    } +      template<typename Range, typename T> inline      bool has(const Range &range, const T &value){          return boost::end(range) != std::find(boost::begin(range), boost::end(range), value); 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; | 
