diff options
author | Ashish Chaudhari <ashish@ettus.com> | 2015-08-06 10:23:10 -0500 |
---|---|---|
committer | Ashish Chaudhari <ashish@ettus.com> | 2015-08-06 10:23:10 -0500 |
commit | cc6853bd475238012a97743891854194efc26862 (patch) | |
tree | 9ab9fc47e2e0f60248e5c7cae0ada0407f0298c0 /host | |
parent | c7f24e49db47aec2008b072bb6fb9b6dddc36797 (diff) | |
download | uhd-cc6853bd475238012a97743891854194efc26862.tar.gz uhd-cc6853bd475238012a97743891854194efc26862.tar.bz2 uhd-cc6853bd475238012a97743891854194efc26862.zip |
uhd: Register API enhancements
- Added get_register_info function to get bitwidth and R/W access for a registers
- Better error reporting
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/usrp/multi_usrp.hpp | 27 | ||||
-rw-r--r-- | host/lib/usrp/multi_usrp.cpp | 34 |
2 files changed, 50 insertions, 11 deletions
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 0c1e73895..80501e489 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -977,6 +977,26 @@ public: /******************************************************************* * Register IO methods ******************************************************************/ + struct register_info_t { + size_t bitwidth; + bool readable; + bool writable; + }; + + /*! + * Enumerate the full paths of all low-level USRP register accessible to read/write + * \param mboard the motherboard index 0 to M-1 + * \return a vector of register paths + */ + virtual std::vector<std::string> enumerate_registers(const size_t mboard = 0) = 0; + + /*! + * Get more information about a low-level device register + * \param path the full path to the register + * \param mboard the motherboard index 0 to M-1 + * \return the info struct which contains the bitwidth and read-write access information + */ + virtual register_info_t get_register_info(const std::string &path, const size_t mboard = 0) = 0; /*! * Write a low-level register field for a register in the USRP hardware @@ -996,13 +1016,6 @@ public: */ virtual boost::uint64_t read_register(const std::string &path, const boost::uint32_t field, const size_t mboard = 0) = 0; - /*! - * Enumerate the full paths of all low-level USRP register accessible to read/write - * \param mboard the motherboard index 0 to M-1 - * \return a vector of register paths - */ - virtual std::vector<std::string> enumerate_registers(const size_t mboard = 0) = 0; - /******************************************************************* * Filter API methods ******************************************************************/ diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 285799674..f27d0ca03 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -1380,6 +1380,10 @@ public: _tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get(); uhd::soft_register_base& reg = accessor->lookup(path); + if (not reg.is_writable()) { + throw uhd::runtime_error("multi_usrp::write_register - register not writable: " + path); + } + switch (reg.get_bitwidth()) { case 16: if (reg.is_readable()) @@ -1403,11 +1407,11 @@ public: break; default: - throw uhd::assertion_error("register has invalid bitwidth"); + throw uhd::assertion_error("multi_usrp::write_register - register has invalid bitwidth"); } } else { - throw uhd::not_implemented_error("register IO not supported for this device"); + throw uhd::not_implemented_error("multi_usrp::write_register - register IO not supported for this device"); } } @@ -1419,6 +1423,10 @@ public: _tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get(); uhd::soft_register_base& reg = accessor->lookup(path); + if (not reg.is_readable()) { + throw uhd::runtime_error("multi_usrp::read_register - register not readable: " + path); + } + switch (reg.get_bitwidth()) { case 16: if (reg.is_writable()) @@ -1442,10 +1450,10 @@ public: break; default: - throw uhd::assertion_error("register has invalid bitwidth: " + path); + throw uhd::assertion_error("multi_usrp::read_register - register has invalid bitwidth: " + path); } } else { - throw uhd::not_implemented_error("register IO not supported for this device"); + throw uhd::not_implemented_error("multi_usrp::read_register - register IO not supported for this device"); } } @@ -1461,6 +1469,24 @@ public: } } + register_info_t get_register_info(const std::string &path, const size_t mboard = 0) + { + if (_tree->exists(mb_root(mboard) / "registers")) + { + uhd::soft_regmap_accessor_t::sptr accessor = + _tree->access<uhd::soft_regmap_accessor_t::sptr>(mb_root(mboard) / "registers").get(); + uhd::soft_register_base& reg = accessor->lookup(path); + + register_info_t info; + info.bitwidth = reg.get_bitwidth(); + info.readable = reg.is_readable(); + info.writable = reg.is_writable(); + return info; + } else { + throw uhd::not_implemented_error("multi_usrp::read_register - register IO not supported for this device"); + } + } + private: device::sptr _dev; property_tree::sptr _tree; |