diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt
index 09a94958..8b7dc0e3 100644
--- a/host/CMakeLists.txt
+++ b/host/CMakeLists.txt
@@ -58,6 +58,7 @@ list(APPEND UMTRX_SOURCES
cores/time64_core_200.cpp
cores/validate_subdev_spec.cpp
cores/apply_corrections.cpp
+ umsel2_ctrl.cpp
)
########################################################################
diff --git a/host/umsel2_ctrl.cpp b/host/umsel2_ctrl.cpp
new file mode 100644
index 00000000..cc91c1f4
--- /dev/null
+++ b/host/umsel2_ctrl.cpp
@@ -0,0 +1,67 @@
+// Copyright 2015-2015 Fairwaves LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+
+#include "umsel2_ctrl.hpp"
+#include "umtrx_regs.hpp"
+
+class umsel2_ctrl_impl : public umsel2_ctrl
+{
+public:
+
+ umsel2_ctrl_impl(uhd::wb_iface::sptr ctrl, uhd::spi_iface::sptr spiface):
+ _ctrl(ctrl), _spiface(spiface)
+ {
+ //TODO init stuff?
+ return;
+ }
+
+ ~umsel2_ctrl_impl(void)
+ {
+ //TODO shutdown
+ return;
+ }
+
+ uhd::freq_range_t get_rx_freq_range(const int which)
+ {
+ //TODO range
+ }
+
+ double set_rx_freq(const int which, const double freq)
+ {
+ const int slaveno = (which == 1)?SPI_SS_AUX1 : SPI_SS_AUX2;
+ //TODO tune...
+
+ return freq;
+ }
+
+ uhd::sensor_value_t get_locked(const int which)
+ {
+ boost::uint32_t irq = _ctrl->peek32(U2_REG_IRQ_RB);
+ bool locked = false;
+ if (which == 1) locked = (irq & AUX_LD1_IRQ_BIT) != 0;
+ if (which == 2) locked = (irq & AUX_LD2_IRQ_BIT) != 0;
+ return uhd::sensor_value_t("LO", locked, "locked", "unlocked");
+ }
+
+private:
+ uhd::wb_iface::sptr _ctrl;
+ uhd::spi_iface::sptr _spiface;
+};
+
+umsel2_ctrl::sptr umsel2_ctrl::make(uhd::wb_iface::sptr ctrl, uhd::spi_iface::sptr spiface)
+{
+ return umsel2_ctrl::sptr(new umsel2_ctrl_impl(ctrl, spiface));
+}
diff --git a/host/umsel2_ctrl.hpp b/host/umsel2_ctrl.hpp
new file mode 100644
index 00000000..e2b239e4
--- /dev/null
+++ b/host/umsel2_ctrl.hpp
@@ -0,0 +1,58 @@
+// Copyright 2015-2015 Fairwaves LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+
+#ifndef INCLUDED_UMSEL2_CTRL_HPP
+#define INCLUDED_UMSEL2_CTRL_HPP
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*!
+ * Control UmSEL2 board.
+ */
+class umsel2_ctrl
+{
+public:
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(uhd::wb_iface::sptr ctrl, uhd::spi_iface::sptr spiface);
+
+ /*!
+ * Query the tune range.
+ * \param which values 1 or 2
+ */
+ virtual uhd::freq_range_t get_rx_freq_range(const int which) = 0;
+
+ /*!
+ * Tune the synthesizer
+ * \param which values 1 or 2
+ * \param freq the freq in Hz
+ * \return the actual freq in Hz
+ */
+ virtual double set_rx_freq(const int which, const double freq) = 0;
+
+ /*!
+ * Query lock detect.
+ * \param which values 1 or 2
+ */
+ virtual uhd::sensor_value_t get_locked(const int which) = 0;
+};
+
+#endif /* INCLUDED_UMSEL2_CTRL_HPP */
diff --git a/host/umtrx_impl.cpp b/host/umtrx_impl.cpp
index 0b31d09a..f770920a 100644
--- a/host/umtrx_impl.cpp
+++ b/host/umtrx_impl.cpp
@@ -270,6 +270,22 @@ umtrx_impl::umtrx_impl(const device_addr_t &device_addr)
_tree->create(mb_path / "hwrev").set(get_hw_rev());
UHD_MSG(status) << "Detected UmTRX " << get_hw_rev() << std::endl;
+ ////////////////////////////////////////////////////////////////////////
+ // setup umsel2 control when present
+ ////////////////////////////////////////////////////////////////////////
+ //TODO delect umsel2 and setup _umsel2 sptr...
+ //will be null when not available
+ _umsel2 = umsel2_ctrl::make(_ctrl/*peek*/, _ctrl/*spi*/);
+
+ //register lock detect for umsel2
+ if (_umsel2)
+ {
+ _tree->create(mb_path / "dboards" / "A" / "rx_frontends" / "0" / "sensors" / "aux_lo_locked")
+ .publish(boost::bind(&umsel2_ctrl::get_locked, _umsel2, 1));
+ _tree->create(mb_path / "dboards" / "B" / "rx_frontends" / "0" / "sensors" / "aux_lo_locked")
+ .publish(boost::bind(&umsel2_ctrl::get_locked, _umsel2, 2));
+ }
+
////////////////////////////////////////////////////////////////////////
// configure diversity switches
////////////////////////////////////////////////////////////////////////
@@ -570,9 +586,17 @@ umtrx_impl::umtrx_impl(const device_addr_t &device_addr)
//rx freq
_tree->create(rx_rf_fe_path / "freq" / "value")
- .coerce(boost::bind(&lms6002d_ctrl::set_rx_freq, ctrl, _1));
- _tree->create(rx_rf_fe_path / "freq" / "range")
- .publish(boost::bind(&lms6002d_ctrl::get_rx_freq_range, ctrl));
+ .coerce(boost::bind(&umtrx_impl::set_rx_freq, this, fe_name, _1));
+ if (_umsel2)
+ {
+ _tree->create(rx_rf_fe_path / "freq" / "range")
+ .publish(boost::bind(&umsel2_ctrl::get_rx_freq_range, _umsel2, (fe_name=="A")?1:2));
+ }
+ else
+ {
+ _tree->create(rx_rf_fe_path / "freq" / "range")
+ .publish(boost::bind(&lms6002d_ctrl::get_rx_freq_range, ctrl));
+ }
_tree->create(rx_rf_fe_path / "use_lo_offset").set(false);
//tx freq
@@ -871,6 +895,19 @@ uint8_t umtrx_impl::dc_offset_double2int(double corr)
return (int)(corr*128 + 128.5);
}
+double umtrx_impl::set_rx_freq(const std::string &which, const double freq)
+{
+ if (_umsel2)
+ {
+ //TODO _lms_ctrl[which]->set_rx_freq(freq);360Mhz and 400MHz
+ return _umsel2->set_rx_freq((which=="A")?1:2, freq);
+ }
+ else
+ {
+ return _lms_ctrl[which]->set_rx_freq(freq);
+ }
+}
+
uhd::sensor_value_t umtrx_impl::read_temp_c(const std::string &which)
{
boost::recursive_mutex::scoped_lock l(_i2c_mutex);
diff --git a/host/umtrx_impl.hpp b/host/umtrx_impl.hpp
index b9a5f2fd..55e39fd9 100644
--- a/host/umtrx_impl.hpp
+++ b/host/umtrx_impl.hpp
@@ -31,6 +31,7 @@
#include "ads1015_ctrl.hpp"
#include "tmp102_ctrl.hpp"
#include "power_amp.hpp"
+#include "umsel2_ctrl.hpp"
#include
#include
#include
@@ -152,6 +153,7 @@ private:
std::string _device_ip_addr;
umtrx_iface::sptr _iface;
umtrx_fifo_ctrl::sptr _ctrl;
+ umsel2_ctrl::sptr _umsel2;
//controls for perifs
uhd::dict _lms_ctrl;
@@ -195,6 +197,7 @@ private:
uhd::transport::zero_copy_if::sptr make_xport(const size_t which, const uhd::device_addr_t &args);
std::complex get_dc_offset_correction(const std::string &which) const;
void set_dc_offset_correction(const std::string &which, const std::complex &corr);
+ double set_rx_freq(const std::string &which, const double freq);
static double dc_offset_int2double(uint8_t corr);
static uint8_t dc_offset_double2int(double corr);
diff --git a/host/umtrx_regs.hpp b/host/umtrx_regs.hpp
index b870aa0b..e16b11db 100644
--- a/host/umtrx_regs.hpp
+++ b/host/umtrx_regs.hpp
@@ -104,6 +104,9 @@ localparam SR_SPI_CORE = 185; // 3
#define U2_REG_TIME64_HI_RB_PPS READBACK_BASE + 4*14
#define U2_REG_TIME64_LO_RB_PPS READBACK_BASE + 4*15
+#define AUX_LD1_IRQ_BIT (1 << 14)
+#define AUX_LD2_IRQ_BIT (1 << 15)
+
/////////////////////////////////////////////////
// LMS regs
////////////////////////////////////////////////