diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-24 10:46:12 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-24 10:46:12 -0700 |
commit | 300ddf7807e5dd7662b09023ab80da26dd878626 (patch) | |
tree | 6d1f6c31bf9db0ff67ef7e96e1a99c087a57a117 /host/lib/usrp/dboard_eeprom.cpp | |
parent | 039eceb4b208b2ca5a3465d2f16c8d5a7c7276c7 (diff) | |
download | uhd-300ddf7807e5dd7662b09023ab80da26dd878626.tar.gz uhd-300ddf7807e5dd7662b09023ab80da26dd878626.tar.bz2 uhd-300ddf7807e5dd7662b09023ab80da26dd878626.zip |
set dboard eeprom from dboard properties
Diffstat (limited to 'host/lib/usrp/dboard_eeprom.cpp')
-rw-r--r-- | host/lib/usrp/dboard_eeprom.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index a8fac602a..5ce0b2328 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -53,26 +53,37 @@ using namespace uhd::usrp; // daughterboard specific use //////////////////////////////////////////////////////////////////////// -dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &buf){ +//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)); + } + return (-sum) & 0xff; +} + +dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ try{ - ASSERT_THROW(buf.size() >= num_bytes()); - ASSERT_THROW(buf[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); + ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); + ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); id = \ - (boost::uint16_t(buf[DB_EEPROM_ID_LSB]) << 0) | - (boost::uint16_t(buf[DB_EEPROM_ID_MSB]) << 8) ; + (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) | + (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ; }catch(const uhd::assert_error &e){ id = dboard_id::NONE; } } byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ - byte_vector_t bytes(3); + byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0); bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8); + bytes[DB_EEPROM_CHKSUM] = checksum(bytes); return bytes; } size_t dboard_eeprom_t::num_bytes(void){ - return 3; + return DB_EEPROM_CLEN; } |