aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/dboard_eeprom.cpp
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 /host/lib/usrp/dboard_eeprom.cpp
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).
Diffstat (limited to 'host/lib/usrp/dboard_eeprom.cpp')
-rw-r--r--host/lib/usrp/dboard_eeprom.cpp21
1 files changed, 17 insertions, 4 deletions
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);