diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-26 12:19:00 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-26 12:19:00 -0700 |
commit | f040d79d256bcdfcd931ab93e00b66f6af881a14 (patch) | |
tree | 0bb82963278a64caaa04b1c5360f0d3e48059d42 /host/include | |
parent | 15befa19de40fb82f30d71bf21a767e7d8054ba1 (diff) | |
parent | 1217b8d67c3bef98195836fe10ab39576642b340 (diff) | |
download | uhd-f040d79d256bcdfcd931ab93e00b66f6af881a14.tar.gz uhd-f040d79d256bcdfcd931ab93e00b66f6af881a14.tar.bz2 uhd-f040d79d256bcdfcd931ab93e00b66f6af881a14.zip |
Merge branch 'eeprom' of git@ettus.sourcerepo.com:ettus/uhdpriv
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/types/serial.hpp | 61 | ||||
-rw-r--r-- | host/include/uhd/usrp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_eeprom.hpp | 60 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_iface.hpp | 10 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_manager.hpp | 1 | ||||
-rw-r--r-- | host/include/uhd/usrp/dboard_props.hpp | 3 | ||||
-rw-r--r-- | host/include/uhd/utils/assert.hpp | 33 | ||||
-rw-r--r-- | host/include/uhd/utils/props.hpp | 54 | ||||
-rw-r--r-- | host/include/uhd/utils/safe_main.hpp | 3 |
9 files changed, 194 insertions, 32 deletions
diff --git a/host/include/uhd/types/serial.hpp b/host/include/uhd/types/serial.hpp index b0fe5d7bd..c134725f5 100644 --- a/host/include/uhd/types/serial.hpp +++ b/host/include/uhd/types/serial.hpp @@ -30,6 +30,67 @@ namespace uhd{ typedef std::vector<boost::uint8_t> byte_vector_t; /*! + * The i2c interface class: + * Provides i2c and eeprom functionality. + * A subclass should only have to implement the i2c routines. + * An eeprom implementation comes for free with the interface. + * + * The eeprom routines are implemented on top of i2c. + * The built in eeprom implementation only does single + * byte reads and byte writes over the i2c interface, + * so it should be portable across multiple eeproms. + * Override the eeprom routines if this is not acceptable. + */ + class UHD_API i2c_iface{ + public: + /*! + * Write bytes over the i2c. + * \param addr the address + * \param buf the vector of bytes + */ + virtual void write_i2c( + boost::uint8_t addr, + const byte_vector_t &buf + ) = 0; + + /*! + * Read bytes over the i2c. + * \param addr the address + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual byte_vector_t read_i2c( + boost::uint8_t addr, + size_t num_bytes + ) = 0; + + /*! + * Write bytes to an eeprom. + * \param addr the address + * \param offset byte offset + * \param buf the vector of bytes + */ + virtual void write_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + const byte_vector_t &buf + ); + + /*! + * Read bytes from an eeprom. + * \param addr the address + * \param offset byte offset + * \param num_bytes number of bytes to read + * \return a vector of bytes + */ + virtual byte_vector_t read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes + ); + }; + + /*! * The SPI configuration struct: * Used to configure a SPI transaction interface. */ diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index 23758041c..bbd124ed8 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -26,6 +26,7 @@ INSTALL(FILES #### dboard headers ### dboard_base.hpp + dboard_eeprom.hpp dboard_id.hpp dboard_iface.hpp dboard_manager.hpp diff --git a/host/include/uhd/usrp/dboard_eeprom.hpp b/host/include/uhd/usrp/dboard_eeprom.hpp new file mode 100644 index 000000000..108027b46 --- /dev/null +++ b/host/include/uhd/usrp/dboard_eeprom.hpp @@ -0,0 +1,60 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_USRP_DBOARD_EEPROM_HPP +#define INCLUDED_UHD_USRP_DBOARD_EEPROM_HPP + +#include <uhd/config.hpp> +#include <uhd/usrp/dboard_id.hpp> +#include <uhd/types/serial.hpp> +#include <string> + +namespace uhd{ namespace usrp{ + +struct UHD_API dboard_eeprom_t{ + /*! + * The dboard id that was read from eeprom or will be set to eeprom. + */ + dboard_id_t id; + + /*! + * Create a dboard eeprom struct from the bytes read out of eeprom. + * The constructor will parse out the dboard id from a vector of bytes. + * To be valid, the bytes vector should be at least num_bytes() long. + * If the parsing fails due to bad checksum or incomplete length, + * the dboard id in this struct will be set to dboard_id::NONE. + * \param bytes the vector of bytes + */ + dboard_eeprom_t(const uhd::byte_vector_t &bytes = uhd::byte_vector_t(0)); + + /*! + * Get the bytes that would be written to dboard eeprom. + * \return a vector of bytes + */ + uhd::byte_vector_t get_eeprom_bytes(void); + + /*! + * Get the number of bytes in the dboard eeprom segment. + * Use this value when reading out of the dboard eeprom. + * \return the number of bytes used by dboard eeprom + */ + static size_t num_bytes(void); +}; + +}} //namespace + +#endif /* INCLUDED_UHD_USRP_DBOARD_EEPROM_HPP */ diff --git a/host/include/uhd/usrp/dboard_iface.hpp b/host/include/uhd/usrp/dboard_iface.hpp index 79b8ee664..1214a1a2f 100644 --- a/host/include/uhd/usrp/dboard_iface.hpp +++ b/host/include/uhd/usrp/dboard_iface.hpp @@ -95,19 +95,19 @@ public: /*! * Write to an I2C peripheral. * - * \param i2c_addr I2C bus address (7-bits) - * \param buf the data to write + * \param addr I2C bus address (7-bits) + * \param bytes the data to write */ - virtual void write_i2c(int i2c_addr, const byte_vector_t &buf) = 0; + virtual void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes) = 0; /*! * Read from an I2C peripheral. * - * \param i2c_addr I2C bus address (7-bits) + * \param addr I2C bus address (7-bits) * \param num_bytes number of bytes to read * \return the data read if successful, else a zero length string. */ - virtual byte_vector_t read_i2c(int i2c_addr, size_t num_bytes) = 0; + virtual byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes) = 0; /*! * Write data to SPI bus peripheral. diff --git a/host/include/uhd/usrp/dboard_manager.hpp b/host/include/uhd/usrp/dboard_manager.hpp index 6de64b02d..007d85bb4 100644 --- a/host/include/uhd/usrp/dboard_manager.hpp +++ b/host/include/uhd/usrp/dboard_manager.hpp @@ -33,7 +33,6 @@ namespace uhd{ namespace usrp{ * Provide wax::obj access to the subdevs inside. */ class UHD_API dboard_manager : boost::noncopyable{ - public: typedef boost::shared_ptr<dboard_manager> sptr; diff --git a/host/include/uhd/usrp/dboard_props.hpp b/host/include/uhd/usrp/dboard_props.hpp index 3b290319f..0208a6c2c 100644 --- a/host/include/uhd/usrp/dboard_props.hpp +++ b/host/include/uhd/usrp/dboard_props.hpp @@ -29,7 +29,8 @@ namespace uhd{ namespace usrp{ DBOARD_PROP_NAME = 'n', //ro, std::string DBOARD_PROP_SUBDEV = 's', //ro, wax::obj DBOARD_PROP_SUBDEV_NAMES = 'S', //ro, prop_names_t - DBOARD_PROP_USED_SUBDEVS = 'u' //ro, prop_names_t + DBOARD_PROP_USED_SUBDEVS = 'u', //ro, prop_names_t + DBOARD_PROP_DBOARD_ID = 'i' //rw, dboard_id_t //DBOARD_PROP_CODEC //ro, wax::obj //----> not sure, dont have to deal with yet }; diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 842ed8dfa..773acd634 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -18,27 +18,27 @@ #ifndef INCLUDED_UHD_UTILS_ASSERT_HPP #define INCLUDED_UHD_UTILS_ASSERT_HPP +#include <uhd/config.hpp> #include <uhd/utils/algorithm.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> #include <boost/lexical_cast.hpp> -#include <boost/current_function.hpp> +#include <boost/throw_exception.hpp> +#include <boost/exception/info.hpp> #include <stdexcept> +#include <string> namespace uhd{ - class assert_error : public std::logic_error{ - public: - explicit assert_error(const std::string& what_arg) : logic_error(what_arg){ - /* NOP */ - } - }; + //! The exception to throw when assertions fail + struct UHD_API assert_error : virtual std::exception, virtual boost::exception{}; - #define ASSERT_THROW(_x) if (not (_x)) { \ - throw uhd::assert_error(str(boost::format( \ - "Assertion Failed:\n %s:%d\n %s\n ---> %s <---" \ - ) % __FILE__ % __LINE__ % BOOST_CURRENT_FUNCTION % std::string(#_x))); \ - } + //! The assertion info, the code that failed + typedef boost::error_info<struct tag_assert_info, std::string> assert_info; + + //! Throw an assert error with throw-site information + #define ASSERT_THROW(_x) if (not (_x)) \ + BOOST_THROW_EXCEPTION(uhd::assert_error() << uhd::assert_info(#_x)) /*! * Check that an element is found in a container. @@ -58,17 +58,18 @@ namespace uhd{ ){ if (std::has(iterable, elem)) return; std::string possible_values = ""; - BOOST_FOREACH(T e, iterable){ - if (e != iterable.begin()[0]) possible_values += ", "; + size_t i = 0; + BOOST_FOREACH(const T &e, iterable){ + if (i++ > 0) possible_values += ", "; possible_values += boost::lexical_cast<std::string>(e); } - throw uhd::assert_error(str(boost::format( + boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format( "Error: %s is not a valid %s. " "Possible values are: [%s]." ) % boost::lexical_cast<std::string>(elem) % what % possible_values - )); + ))); } }//namespace uhd diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index 6be0b2ce5..768655e36 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -21,27 +21,63 @@ #include <uhd/config.hpp> #include <uhd/wax.hpp> #include <boost/tuple/tuple.hpp> +#include <boost/throw_exception.hpp> +#include <boost/exception/info.hpp> +#include <stdexcept> #include <vector> #include <string> namespace uhd{ - //typedef for handling named properties + //! The type for a vector of property names typedef std::vector<std::string> prop_names_t; - typedef boost::tuple<wax::obj, std::string> named_prop_t; + + /*! + * A named prop struct holds a key and a name. + * Allows properties to be sub-sectioned by name. + */ + struct UHD_API named_prop_t{ + wax::obj key; + std::string name; + + /*! + * Create a new named prop from key and name. + * \param key the property key + * \param name the string name + */ + named_prop_t(const wax::obj &key, const std::string &name); + }; /*! * Utility function to separate a named property into its components. * \param key a reference to the prop object * \param name a reference to the name object + * \return a tuple that can be used with boost::tie + */ + UHD_API boost::tuple<wax::obj, std::string> extract_named_prop( + const wax::obj &key, + const std::string &name = "" + ); + + //! The exception to throw for property errors + struct UHD_API prop_error : virtual std::exception, virtual boost::exception{}; + + //! The property error info (verbose or message) + typedef boost::error_info<struct tag_prop_info, std::string> prop_info; + + /*! + * Throw an error when trying to get a write only property. + * Throw-site information will be included with this error. + */ + #define UHD_THROW_PROP_WRITE_ONLY() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot get write-only property")) + + /*! + * Throw an error when trying to set a read only property. + * Throw-site information will be included with this error. */ - inline UHD_API named_prop_t //must be exported as part of the api to work (TODO move guts to cpp file) - extract_named_prop(const wax::obj &key, const std::string &name = ""){ - if (key.type() == typeid(named_prop_t)){ - return key.as<named_prop_t>(); - } - return named_prop_t(key, name); - } + #define UHD_THROW_PROP_READ_ONLY() \ + BOOST_THROW_EXCEPTION(uhd::prop_error() << uhd::prop_info("cannot set read-only property")) } //namespace uhd diff --git a/host/include/uhd/utils/safe_main.hpp b/host/include/uhd/utils/safe_main.hpp index b682aa540..a4e4e06e8 100644 --- a/host/include/uhd/utils/safe_main.hpp +++ b/host/include/uhd/utils/safe_main.hpp @@ -19,6 +19,7 @@ #define INCLUDED_UHD_UTILS_SAFE_MAIN_HPP #include <uhd/config.hpp> +#include <boost/exception/diagnostic_information.hpp> #include <iostream> #include <stdexcept> @@ -33,6 +34,8 @@ int main(int argc, char *argv[]){ \ try { \ return _main(argc, argv); \ + } catch(const boost::exception &e){ \ + std::cerr << "Error: " << boost::diagnostic_information(e) << std::endl; \ } catch(const std::exception &e) { \ std::cerr << "Error: " << e.what() << std::endl; \ } catch(...) { \ |