From d49ca2cf0fca954fc033cf4ddf3cd3502cc39548 Mon Sep 17 00:00:00 2001 From: Ashish Chaudhari Date: Tue, 4 Aug 2015 16:09:40 -0500 Subject: uhd: Added APIs to multi_usrp to read/write device registers - Added regmap object to soft_register library - Added a regmap_db object to hold multiple regmaps/dbs - Multiple soft_register enhancements --- host/lib/usrp/multi_usrp.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'host/lib/usrp') diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 1866255c9..285799674 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -1371,6 +1372,95 @@ public: return 0; } + void write_register(const std::string &path, const boost::uint32_t field, const boost::uint64_t value, const size_t mboard) + { + if (_tree->exists(mb_root(mboard) / "registers")) + { + uhd::soft_regmap_accessor_t::sptr accessor = + _tree->access(mb_root(mboard) / "registers").get(); + uhd::soft_register_base& reg = accessor->lookup(path); + + switch (reg.get_bitwidth()) { + case 16: + if (reg.is_readable()) + uhd::soft_register_base::cast(reg).write(field, static_cast(value)); + else + uhd::soft_register_base::cast(reg).write(field, static_cast(value)); + break; + + case 32: + if (reg.is_readable()) + uhd::soft_register_base::cast(reg).write(field, static_cast(value)); + else + uhd::soft_register_base::cast(reg).write(field, static_cast(value)); + break; + + case 64: + if (reg.is_readable()) + uhd::soft_register_base::cast(reg).write(field, value); + else + uhd::soft_register_base::cast(reg).write(field, value); + break; + + default: + throw uhd::assertion_error("register has invalid bitwidth"); + } + + } else { + throw uhd::not_implemented_error("register IO not supported for this device"); + } + } + + boost::uint64_t read_register(const std::string &path, const boost::uint32_t field, const size_t mboard) + { + if (_tree->exists(mb_root(mboard) / "registers")) + { + uhd::soft_regmap_accessor_t::sptr accessor = + _tree->access(mb_root(mboard) / "registers").get(); + uhd::soft_register_base& reg = accessor->lookup(path); + + switch (reg.get_bitwidth()) { + case 16: + if (reg.is_writable()) + return static_cast(uhd::soft_register_base::cast(reg).read(field)); + else + return static_cast(uhd::soft_register_base::cast(reg).read(field)); + break; + + case 32: + if (reg.is_writable()) + return static_cast(uhd::soft_register_base::cast(reg).read(field)); + else + return static_cast(uhd::soft_register_base::cast(reg).read(field)); + break; + + case 64: + if (reg.is_writable()) + return uhd::soft_register_base::cast(reg).read(field); + else + return uhd::soft_register_base::cast(reg).read(field); + break; + + default: + throw uhd::assertion_error("register has invalid bitwidth: " + path); + } + } else { + throw uhd::not_implemented_error("register IO not supported for this device"); + } + } + + std::vector enumerate_registers(const size_t mboard) + { + if (_tree->exists(mb_root(mboard) / "registers")) + { + uhd::soft_regmap_accessor_t::sptr accessor = + _tree->access(mb_root(mboard) / "registers").get(); + return accessor->enumerate(); + } else { + return std::vector(); + } + } + private: device::sptr _dev; property_tree::sptr _tree; -- cgit v1.2.3