aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-04-26 12:16:37 -0700
committerJosh Blum <josh@joshknows.com>2010-04-26 12:16:37 -0700
commit1217b8d67c3bef98195836fe10ab39576642b340 (patch)
tree97c8e964b38a27db66fcb2f68a646e483b3de436
parent0c609b96574095affe12d9aaa53bead98faba4f3 (diff)
downloaduhd-1217b8d67c3bef98195836fe10ab39576642b340.tar.gz
uhd-1217b8d67c3bef98195836fe10ab39576642b340.tar.bz2
uhd-1217b8d67c3bef98195836fe10ab39576642b340.zip
Got eeprom read/write dboard ids working.
Moved named prop implementation into cpp, and made named prop a struct (tuples are trouble).
-rw-r--r--host/include/uhd/utils/props.hpp29
-rw-r--r--host/lib/CMakeLists.txt1
-rw-r--r--host/lib/types.cpp8
-rw-r--r--host/lib/usrp/dboard_eeprom.cpp21
-rw-r--r--host/lib/usrp/dboard_manager.cpp5
-rw-r--r--host/lib/usrp/usrp2/dboard_impl.cpp2
-rw-r--r--host/lib/utils.cpp44
7 files changed, 91 insertions, 19 deletions
diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp
index bfbca4273..768655e36 100644
--- a/host/include/uhd/utils/props.hpp
+++ b/host/include/uhd/utils/props.hpp
@@ -29,24 +29,35 @@
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
*/
- inline UHD_API named_prop_t extract_named_prop(
+ UHD_API boost::tuple<wax::obj, std::string> 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);
- }
+ );
//! The exception to throw for property errors
struct UHD_API prop_error : virtual std::exception, virtual boost::exception{};
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index ffbf15484..5252eda8f 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -50,6 +50,7 @@ SET(libuhd_sources
gain_handler.cpp
load_modules.cpp
types.cpp
+ utils.cpp
wax.cpp
transport/convert_types.cpp
transport/if_addrs.cpp
diff --git a/host/lib/types.cpp b/host/lib/types.cpp
index a1b9b21a9..08e41b62f 100644
--- a/host/lib/types.cpp
+++ b/host/lib/types.cpp
@@ -32,6 +32,7 @@
#include <boost/format.hpp>
#include <boost/cstdint.hpp>
#include <boost/assign/list_of.hpp>
+#include <boost/thread.hpp>
#include <stdexcept>
#include <complex>
@@ -257,10 +258,11 @@ void i2c_iface::write_eeprom(
boost::uint8_t offset,
const byte_vector_t &bytes
){
- BOOST_FOREACH(boost::uint8_t byte, bytes){
+ for (size_t i = 0; i < bytes.size(); i++){
//write a byte at a time, its easy that way
- byte_vector_t cmd = boost::assign::list_of(offset)(byte);
+ byte_vector_t cmd = boost::assign::list_of(offset+i)(bytes[i]);
this->write_i2c(addr, cmd);
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write
}
}
@@ -272,7 +274,7 @@ byte_vector_t i2c_iface::read_eeprom(
byte_vector_t bytes;
for (size_t i = 0; i < num_bytes; i++){
//do a zero byte write to start read cycle
- this->write_i2c(addr, byte_vector_t(1, offset));
+ this->write_i2c(addr, byte_vector_t(1, offset+i));
bytes.push_back(this->read_i2c(addr, 1).at(0));
}
return bytes;
diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp
index 5ce0b2328..00236c337 100644
--- a/host/lib/usrp/dboard_eeprom.cpp
+++ b/host/lib/usrp/dboard_eeprom.cpp
@@ -17,10 +17,14 @@
#include <uhd/usrp/dboard_eeprom.hpp>
#include <uhd/utils/assert.hpp>
+#include <boost/format.hpp>
+#include <iostream>
using namespace uhd;
using namespace uhd::usrp;
+static const bool _dboard_eeprom_debug = false;
+
////////////////////////////////////////////////////////////////////////
// format of daughterboard EEPROM
// 00: 0xDB code for ``I'm a daughterboard''
@@ -55,14 +59,23 @@ using namespace uhd::usrp;
//negative sum of bytes excluding checksum byte
static boost::uint8_t checksum(const byte_vector_t &bytes){
- int sum;
- for (size_t i = 0; i < DB_EEPROM_CHKSUM; i++){
- sum += int(bytes.at(i));
+ int sum = 0;
+ for (size_t i = 0; i < std::min(bytes.size(), size_t(DB_EEPROM_CHKSUM)); i++){
+ sum -= int(bytes.at(i));
}
- return (-sum) & 0xff;
+ if (_dboard_eeprom_debug)
+ std::cout << boost::format("sum: 0x%02x") % sum << std::endl;
+ return boost::uint8_t(sum);
}
dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){
+ if (_dboard_eeprom_debug){
+ for (size_t i = 0; i < bytes.size(); i++){
+ std::cout << boost::format(
+ "eeprom byte[0x%02x] = 0x%02x") % i % int(bytes.at(i)
+ ) << std::endl;
+ }
+ }
try{
ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN);
ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE);
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 06f8c55b6..34b635934 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -177,10 +177,11 @@ static args_t get_dboard_args(
//verify that there is a registered constructor for this id
if (not get_id_to_args_map().has_key(dboard_id)){
- throw std::runtime_error(str(
+ /*throw std::runtime_error(str(
boost::format("Unregistered %s dboard id: %s")
% xx_type % dboard_id::to_string(dboard_id)
- ));
+ ));*/
+ return get_dboard_args(dboard_id::NONE, xx_type);
}
//return the dboard args for this id
diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp
index 043609458..a68ae240e 100644
--- a/host/lib/usrp/usrp2/dboard_impl.cpp
+++ b/host/lib/usrp/usrp2/dboard_impl.cpp
@@ -136,7 +136,7 @@ void usrp2_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){
case DBOARD_PROP_DBOARD_ID:
_rx_db_eeprom.id = val.as<dboard_id_t>();
- _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _tx_db_eeprom.get_eeprom_bytes());
+ _iface->write_eeprom(I2C_ADDR_RX_DB, 0, _rx_db_eeprom.get_eeprom_bytes());
return;
default: UHD_THROW_PROP_READ_ONLY();
diff --git a/host/lib/utils.cpp b/host/lib/utils.cpp
new file mode 100644
index 000000000..3a1e5aa3f
--- /dev/null
+++ b/host/lib/utils.cpp
@@ -0,0 +1,44 @@
+//
+// 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/>.
+//
+
+#include <uhd/utils/props.hpp>
+
+using namespace uhd;
+
+/***********************************************************************
+ * Props
+ **********************************************************************/
+named_prop_t::named_prop_t(
+ const wax::obj &key_,
+ const std::string &name_
+){
+ key = key_;
+ name = name_;
+}
+
+typedef boost::tuple<wax::obj, std::string> named_prop_tuple;
+
+named_prop_tuple uhd::extract_named_prop(
+ const wax::obj &key,
+ const std::string &name
+){
+ if (key.type() == typeid(named_prop_t)){
+ named_prop_t np = key.as<named_prop_t>();
+ return named_prop_tuple(np.key, np.name);
+ }
+ return named_prop_tuple(key, name);
+}