From 101f6ee0332485a6fa59e2a69b1de253304dcee6 Mon Sep 17 00:00:00 2001
From: Ashish Chaudhari <ashish@ettus.com>
Date: Fri, 23 Jan 2015 17:33:23 -0800
Subject: e300: Several bugfixes for E300 clk/pps selection code

---
 host/lib/usrp/e300/e300_defaults.hpp |  2 +-
 host/lib/usrp/e300/e300_impl.cpp     | 27 ++-------------------------
 host/lib/usrp/e300/e300_network.cpp  |  3 +++
 3 files changed, 6 insertions(+), 26 deletions(-)

(limited to 'host')

diff --git a/host/lib/usrp/e300/e300_defaults.hpp b/host/lib/usrp/e300/e300_defaults.hpp
index 9c0e5df1d..8fe8c3a05 100644
--- a/host/lib/usrp/e300/e300_defaults.hpp
+++ b/host/lib/usrp/e300/e300_defaults.hpp
@@ -35,7 +35,7 @@ static const double DEFAULT_FE_GAIN         = 0.0;
 static const double DEFAULT_FE_FREQ         = 1.0e9;
 static const double DEFAULT_FE_BW           = 56e6;
 
-static const std::string DEFAULT_TIME_SRC   = "none";
+static const std::string DEFAULT_TIME_SRC   = "internal";
 static const std::string DEFAULT_CLOCK_SRC  = "internal";
 
 static const size_t DEFAULT_RX_DATA_FRAME_SIZE = 4096;
diff --git a/host/lib/usrp/e300/e300_impl.cpp b/host/lib/usrp/e300/e300_impl.cpp
index c74ce9412..0c112fdb1 100644
--- a/host/lib/usrp/e300/e300_impl.cpp
+++ b/host/lib/usrp/e300/e300_impl.cpp
@@ -494,13 +494,13 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
     //setup time source props
     _tree->create<std::string>(mb_path / "time_source" / "value")
         .subscribe(boost::bind(&e300_impl::_update_time_source, this, _1))
-        .set("internal");
+        .set(e300::DEFAULT_TIME_SRC);
     static const std::vector<std::string> time_sources = boost::assign::list_of("none")("internal")("external")("gpsdo");
     _tree->create<std::vector<std::string> >(mb_path / "time_source" / "options").set(time_sources);
     //setup reference source props
     _tree->create<std::string>(mb_path / "clock_source" / "value")
         .subscribe(boost::bind(&e300_impl::_update_clock_source, this, _1))
-        .set("internal");
+        .set(e300::DEFAULT_CLOCK_SRC);
     static const std::vector<std::string> clock_sources = boost::assign::list_of("internal"); //external,gpsdo not supported
     _tree->create<std::vector<std::string> >(mb_path / "clock_source" / "options").set(clock_sources);
 
@@ -574,29 +574,6 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
     }
     _tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(rx_spec);
     _tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(tx_spec);
-
-    if (_sensor_manager->get_gps_found()) {
-        _tree->access<std::string>(mb_path / "clock_source" / "value").set("gpsdo");
-        _tree->access<std::string>(mb_path / "time_source" / "value").set("gpsdo");
-        UHD_MSG(status) << "References initialized to GPSDO sources" << std::endl;
-        const time_t tp = time_t(_sensor_manager->get_gps_time().to_int());
-        _tree->access<time_spec_t>(mb_path / "time" / "pps").set(time_spec_t(tp));
-        //wait for time to be set (timeout after 1 second)
-        for (int i = 0; i < 10; i++)
-        {
-            boost::this_thread::sleep(boost::posix_time::milliseconds(100));
-            if(tp == (_tree->access<time_spec_t>(mb_path / "time" / "pps").get()).get_full_secs())
-                break;
-        }
-    } else {
-        // init to default time and clock source
-        _tree->access<std::string>(mb_path / "clock_source" / "value").set(
-            e300::DEFAULT_CLOCK_SRC);
-        _tree->access<std::string>(mb_path / "time_source" / "value").set(
-            e300::DEFAULT_TIME_SRC);
-
-            UHD_MSG(status) << "References initialized to internal sources" << std::endl;
-    }
 }
 
 boost::uint8_t e300_impl::_get_internal_gpio(
diff --git a/host/lib/usrp/e300/e300_network.cpp b/host/lib/usrp/e300/e300_network.cpp
index a21c508fe..2c37f2ff1 100644
--- a/host/lib/usrp/e300/e300_network.cpp
+++ b/host/lib/usrp/e300/e300_network.cpp
@@ -332,6 +332,9 @@ static void e300_sensor_tunnel(
             } else if (uhd::ntohx(in->which) == GPS_LOCK) {
                 in->value = uhd::htonx<boost::uint32_t>(
                     sensor_manager->get_gps_lock().to_bool() ? 1 : 0);
+            } else if (uhd::ntohx(in->which) == REF_LOCK) {
+                in->value = uhd::htonx<boost::uint32_t>(
+                    sensor_manager->get_ref_lock().to_bool() ? 1 : 0);
             } else if (uhd::ntohx(in->which) == GPS_TIME) {
                 in->value = uhd::htonx<boost::uint32_t>(
                     sensor_manager->get_gps_time().to_int());
-- 
cgit v1.2.3