diff options
| author | Josh Blum <josh@joshknows.com> | 2010-11-10 16:48:02 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2010-11-10 16:48:02 -0800 | 
| commit | a724f4b7262c6da6d24dccdbd64e08da61cb87fc (patch) | |
| tree | 6141d1215d36fc94d1deef0ec26d9ef532ea2e30 /host/lib/usrp/usrp_e100 | |
| parent | 123de6dad521ca3dbc44a5d9fc70ff754f1196e3 (diff) | |
| download | uhd-a724f4b7262c6da6d24dccdbd64e08da61cb87fc.tar.gz uhd-a724f4b7262c6da6d24dccdbd64e08da61cb87fc.tar.bz2 uhd-a724f4b7262c6da6d24dccdbd64e08da61cb87fc.zip  | |
usrp-e100: implemented wrapper for i2c device node + ioctls, implemented e100 eeprom map
Diffstat (limited to 'host/lib/usrp/usrp_e100')
| -rw-r--r-- | host/lib/usrp/usrp_e100/mboard_impl.cpp | 10 | ||||
| -rw-r--r-- | host/lib/usrp/usrp_e100/usrp_e100_iface.cpp | 82 | ||||
| -rw-r--r-- | host/lib/usrp/usrp_e100/usrp_e100_iface.hpp | 7 | 
3 files changed, 93 insertions, 6 deletions
diff --git a/host/lib/usrp/usrp_e100/mboard_impl.cpp b/host/lib/usrp/usrp_e100/mboard_impl.cpp index e45d7c5a0..9c6317b94 100644 --- a/host/lib/usrp/usrp_e100/mboard_impl.cpp +++ b/host/lib/usrp/usrp_e100/mboard_impl.cpp @@ -21,7 +21,6 @@  #include <uhd/usrp/misc_utils.hpp>  #include <uhd/utils/assert.hpp>  #include <uhd/usrp/mboard_props.hpp> -#include <uhd/usrp/mboard_eeprom.hpp>  #include <boost/bind.hpp>  #include <iostream> @@ -109,7 +108,7 @@ void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_EEPROM_MAP: -        val = mboard_eeprom_t(); +        val = _iface->mb_eeprom;          return;      default: UHD_THROW_PROP_GET_ERROR(); @@ -159,6 +158,13 @@ void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){          ));          return; +    case MBOARD_PROP_EEPROM_MAP: +        // Step1: commit the map, writing only those values set. +        // Step2: readback the entire eeprom map into the iface. +        val.as<mboard_eeprom_t>().commit(_iface->get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100); +        _iface->mb_eeprom = mboard_eeprom_t(_iface->get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100); +        return; +      default: UHD_THROW_PROP_SET_ERROR();      }  } diff --git a/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp b/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp index ad623777e..40c7afabb 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp @@ -22,10 +22,74 @@  #include <linux/usrp_e.h> //ioctl structures and constants  #include <boost/format.hpp>  #include <boost/thread.hpp> //mutex +#include <linux/i2c-dev.h> +#include <linux/i2c.h>  #include <stdexcept>  using namespace uhd; +using namespace uhd::usrp; +/*********************************************************************** + * I2C device node implementation wrapper + **********************************************************************/ +class i2c_dev_iface : public i2c_iface{ +public: +    i2c_dev_iface(const std::string &node){ +        if ((_node_fd = ::open(node.c_str(), O_RDWR)) < 0){ +            throw std::runtime_error("Failed to open " + node); +        } +    } + +    ~i2c_dev_iface(void){ +        ::close(_node_fd); +    } + +    void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes){ +        byte_vector_t rw_bytes(bytes); + +        //setup the message +        i2c_msg msg; +        msg.addr = addr; +        msg.flags = 0; +        msg.len = bytes.size(); +        msg.buf = &rw_bytes.front(); + +        //setup the data +        i2c_rdwr_ioctl_data data; +        data.msgs = &msg; +        data.nmsgs = 1; + +        //call the ioctl +        UHD_ASSERT_THROW(::ioctl(_node_fd, I2C_RDWR, &data) >= 0); +    } + +    byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes){ +        byte_vector_t bytes(num_bytes); + +        //setup the message +        i2c_msg msg; +        msg.addr = addr; +        msg.flags = I2C_M_RD; +        msg.len = bytes.size(); +        msg.buf = &bytes.front(); + +        //setup the data +        i2c_rdwr_ioctl_data data; +        data.msgs = &msg; +        data.nmsgs = 1; + +        //call the ioctl +        UHD_ASSERT_THROW(::ioctl(_node_fd, I2C_RDWR, &data) >= 0); + +        return bytes; +    } + +private: int _node_fd; +}; + +/*********************************************************************** + * USRP-E100 interface implementation + **********************************************************************/  class usrp_e100_iface_impl : public usrp_e100_iface{  public: @@ -36,13 +100,15 @@ public:      /*******************************************************************       * Structors       ******************************************************************/ -    usrp_e100_iface_impl(const std::string &node){ +    usrp_e100_iface_impl(const std::string &node): +        _i2c_dev_iface(i2c_dev_iface("/dev/i2c-3")) +    {          //open the device node and check file descriptor          if ((_node_fd = ::open(node.c_str(), O_RDWR)) < 0){ -            throw std::runtime_error(str( -                boost::format("Failed to open %s") % node -            )); +            throw std::runtime_error("Failed to open " + node);          } + +        mb_eeprom = mboard_eeprom_t(get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100);      }      ~usrp_e100_iface_impl(void){ @@ -64,6 +130,13 @@ public:      }      /******************************************************************* +     * I2C device node interface +     ******************************************************************/ +    i2c_iface &get_i2c_dev_iface(void){ +        return _i2c_dev_iface; +    } + +    /*******************************************************************       * Peek and Poke       ******************************************************************/      void poke32(boost::uint32_t addr, boost::uint32_t value){ @@ -183,6 +256,7 @@ public:  private:      int _node_fd; +    i2c_dev_iface _i2c_dev_iface;      boost::mutex _ctrl_mutex;  }; diff --git a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp b/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp index b52209a42..12283fb52 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp +++ b/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp @@ -19,6 +19,7 @@  #define INCLUDED_USRP_E100_IFACE_HPP  #include <uhd/transport/udp_simple.hpp> +#include <uhd/usrp/mboard_eeprom.hpp>  #include <uhd/types/serial.hpp>  #include <boost/shared_ptr.hpp>  #include <boost/utility.hpp> @@ -63,6 +64,9 @@ public:       */      virtual void ioctl(int request, void *mem) = 0; +    //! Get the I2C interface for the I2C device node +    virtual uhd::i2c_iface &get_i2c_dev_iface(void) = 0; +      /*!       * Write a register (32 bits)       * \param addr the address @@ -107,6 +111,9 @@ public:          size_t num_bits,          bool readback      ) = 0; + +    //motherboard eeprom map structure +    uhd::usrp::mboard_eeprom_t mb_eeprom;  };  #endif /* INCLUDED_USRP_E100_IFACE_HPP */  | 
