diff options
author | Josh Blum <josh@joshknows.com> | 2011-05-01 17:26:15 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-05-01 17:26:15 -0700 |
commit | 5c6c179689ef76ccd25d09ac4faeb9a836a066c8 (patch) | |
tree | 28c23bb2ec6c70abbe9d5c18d77902d822cf56d2 /host/lib/usrp/mboard_eeprom.cpp | |
parent | 4b18ab84921a88f0448632355e8165ecaff4ed6f (diff) | |
download | uhd-5c6c179689ef76ccd25d09ac4faeb9a836a066c8.tar.gz uhd-5c6c179689ef76ccd25d09ac4faeb9a836a066c8.tar.bz2 uhd-5c6c179689ef76ccd25d09ac4faeb9a836a066c8.zip |
usrp-e100: add ability to set/get default master clock rate from EEPROM
Mboard eeprom map class can parse the setting (4 byte float).
The clock control will try to set the eeprom rate if present,
otherwise or under failure condition, it sets the default.
Updated docs, example, and provided helpful verbose.
I would prefer that users burn the desired rate to the eeprom (and they may too).
Diffstat (limited to 'host/lib/usrp/mboard_eeprom.cpp')
-rw-r--r-- | host/lib/usrp/mboard_eeprom.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/host/lib/usrp/mboard_eeprom.cpp b/host/lib/usrp/mboard_eeprom.cpp index 869a38478..03096691e 100644 --- a/host/lib/usrp/mboard_eeprom.cpp +++ b/host/lib/usrp/mboard_eeprom.cpp @@ -223,6 +223,7 @@ struct e100_eeprom_map{ unsigned char env_setting[64]; unsigned char serial[10]; unsigned char name[NAME_MAX_LEN]; + float master_clock_rate; }; template <typename T> static const byte_vector_t to_bytes(const T &item){ @@ -254,6 +255,19 @@ static void load_e100(mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ load_e100_string_xx(env_setting); load_e100_string_xx(serial); load_e100_string_xx(name); + + //extract the master clock rate + float master_clock_rate = 0; + const byte_vector_t rate_bytes = iface.read_eeprom( + E100_EEPROM_ADDR, offsetof(e100_eeprom_map, master_clock_rate), sizeof(master_clock_rate) + ); + std::copy( + rate_bytes.begin(), rate_bytes.end(), //source + reinterpret_cast<boost::uint8_t *>(&master_clock_rate) //destination + ); + if (master_clock_rate > 1e6 and master_clock_rate < 1e9){ + mb_eeprom["master_clock_rate"] = boost::lexical_cast<std::string>(master_clock_rate); + } } static void store_e100(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ @@ -289,6 +303,17 @@ static void store_e100(const mboard_eeprom_t &mb_eeprom, i2c_iface &iface){ store_e100_string_xx(serial); store_e100_string_xx(name); + //store the master clock rate + if (mb_eeprom.has_key("master_clock_rate")){ + const float master_clock_rate = float(boost::lexical_cast<double>(mb_eeprom["master_clock_rate"])); + const byte_vector_t rate_bytes( + reinterpret_cast<const boost::uint8_t *>(&master_clock_rate), + reinterpret_cast<const boost::uint8_t *>(&master_clock_rate) + sizeof(master_clock_rate) + ); + iface.write_eeprom( + E100_EEPROM_ADDR, offsetof(e100_eeprom_map, master_clock_rate), rate_bytes + ); + } } /*********************************************************************** |