From da8a6ff1ee9ac9eb14cb290a8fed9a95f5232a21 Mon Sep 17 00:00:00 2001
From: Josh Blum <josh@joshknows.com>
Date: Mon, 10 Oct 2011 17:18:14 -0700
Subject: usrp: added revision field to the dboard id class

---
 host/lib/usrp/dboard_eeprom.cpp | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

(limited to 'host/lib/usrp')

diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp
index b3cb54c1c..f2bee47a9 100644
--- a/host/lib/usrp/dboard_eeprom.cpp
+++ b/host/lib/usrp/dboard_eeprom.cpp
@@ -20,6 +20,7 @@
 #include <uhd/utils/log.hpp>
 #include <boost/foreach.hpp>
 #include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
 #include <algorithm>
 #include <sstream>
 
@@ -68,8 +69,8 @@ static const byte_vector_t string_to_bytes(const std::string &string, size_t max
 #define DB_EEPROM_MAGIC_VALUE   0xDB
 #define DB_EEPROM_ID_LSB        0x01
 #define DB_EEPROM_ID_MSB        0x02
-#define DB_EEPROM_OE_LSB        0x03
-#define DB_EEPROM_OE_MSB        0x04
+#define DB_EEPROM_REV_LSB       0x03
+#define DB_EEPROM_REV_MSB       0x04
 #define DB_EEPROM_OFFSET_0_LSB  0x05 // offset correction for ADC or DAC 0
 #define DB_EEPROM_OFFSET_0_MSB  0x06
 #define DB_EEPROM_OFFSET_1_LSB  0x07 // offset correction for ADC or DAC 1
@@ -127,6 +128,15 @@ void dboard_eeprom_t::load(i2c_iface &iface, boost::uint8_t addr){
             &bytes.at(DB_EEPROM_SERIAL+DB_EEPROM_SERIAL_LEN))
         );
 
+        //parse the revision
+        const boost::uint16_t rev_num = 0
+            | (boost::uint16_t(bytes[DB_EEPROM_REV_LSB]) << 0)
+            | (boost::uint16_t(bytes[DB_EEPROM_REV_MSB]) << 8)
+        ;
+        if (rev_num != 0 and rev_num != 0xffff){
+            revision = boost::lexical_cast<std::string>(rev_num);
+        }
+
     }catch(const uhd::assertion_error &){
         id = dboard_id_t::none();
         serial = "";
@@ -145,6 +155,13 @@ void dboard_eeprom_t::store(i2c_iface &iface, boost::uint8_t addr) const{
     byte_vector_t ser_bytes = string_to_bytes(serial, DB_EEPROM_SERIAL_LEN);
     std::copy(ser_bytes.begin(), ser_bytes.end(), &bytes.at(DB_EEPROM_SERIAL));
 
+    //load the revision bytes
+    if (not revision.empty()){
+        const boost::uint16_t rev_num = boost::lexical_cast<boost::uint16_t>(revision);
+        bytes[DB_EEPROM_REV_LSB] = boost::uint8_t(rev_num >> 0);
+        bytes[DB_EEPROM_REV_MSB] = boost::uint8_t(rev_num >> 8);
+    }
+
     //load the checksum
     bytes[DB_EEPROM_CHKSUM] = checksum(bytes);
 
-- 
cgit v1.2.3