diff options
Diffstat (limited to 'host/lib/usrp/e100')
-rw-r--r-- | host/lib/usrp/e100/codec_ctrl.cpp | 16 | ||||
-rw-r--r-- | host/lib/usrp/e100/e100_ctrl.cpp | 69 | ||||
-rw-r--r-- | host/lib/usrp/e100/e100_ctrl.hpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/e100/e100_impl.cpp | 25 | ||||
-rw-r--r-- | host/lib/usrp/e100/e100_impl.hpp | 3 |
5 files changed, 112 insertions, 4 deletions
diff --git a/host/lib/usrp/e100/codec_ctrl.cpp b/host/lib/usrp/e100/codec_ctrl.cpp index 6efeb10e8..f3d2a04b5 100644 --- a/host/lib/usrp/e100/codec_ctrl.cpp +++ b/host/lib/usrp/e100/codec_ctrl.cpp @@ -74,14 +74,15 @@ e100_codec_ctrl_impl::e100_codec_ctrl_impl(spi_iface::sptr iface){ _ad9862_regs.soft_reset = 0; //setup rx side of codec - _ad9862_regs.byp_buffer_a = 1; - _ad9862_regs.byp_buffer_b = 1; - _ad9862_regs.buffer_a_pd = 1; - _ad9862_regs.buffer_b_pd = 1; + _ad9862_regs.byp_buffer_a = 0; + _ad9862_regs.byp_buffer_b = 0; + _ad9862_regs.buffer_a_pd = 0; + _ad9862_regs.buffer_b_pd = 0; _ad9862_regs.rx_pga_a = 0;//0x1f; //TODO bring under api control _ad9862_regs.rx_pga_b = 0;//0x1f; //TODO bring under api control _ad9862_regs.rx_twos_comp = 1; _ad9862_regs.rx_hilbert = ad9862_regs_t::RX_HILBERT_DIS; + _ad9862_regs.shared_ref = 1; //setup tx side of codec _ad9862_regs.two_data_paths = ad9862_regs_t::TWO_DATA_PATHS_BOTH; @@ -101,6 +102,12 @@ e100_codec_ctrl_impl::e100_codec_ctrl_impl(spi_iface::sptr iface){ _ad9862_regs.input_clk_ctrl = ad9862_regs_t::INPUT_CLK_CTRL_EXTERNAL; _ad9862_regs.dll_mult = ad9862_regs_t::DLL_MULT_2; _ad9862_regs.dll_mode = ad9862_regs_t::DLL_MODE_FAST; + _ad9862_regs.hs_duty_cycle = 1; + _ad9862_regs.clk_duty = 1; + + //disable clkout1 and clkout2 + _ad9862_regs.dis1 = ad9862_regs_t::DIS1_DIS; + _ad9862_regs.dis2 = ad9862_regs_t::DIS2_DIS; //write the register settings to the codec for (uint8_t addr = 0; addr <= 25; addr++){ @@ -114,6 +121,7 @@ e100_codec_ctrl_impl::e100_codec_ctrl_impl(spi_iface::sptr iface){ //aux adc clock _ad9862_regs.clk_4 = ad9862_regs_t::CLK_4_1_4; this->send_reg(34); + this->send_reg(35); } e100_codec_ctrl_impl::~e100_codec_ctrl_impl(void){ diff --git a/host/lib/usrp/e100/e100_ctrl.cpp b/host/lib/usrp/e100/e100_ctrl.cpp index 87f7855d3..eb529c9c1 100644 --- a/host/lib/usrp/e100/e100_ctrl.cpp +++ b/host/lib/usrp/e100/e100_ctrl.cpp @@ -18,12 +18,14 @@ #include "e100_ctrl.hpp" #include "e100_regs.hpp" #include <uhd/exception.hpp> +#include <uhd/utils/log.hpp> #include <uhd/utils/msg.hpp> #include <sys/ioctl.h> //ioctl #include <fcntl.h> //open, close #include <linux/usrp_e.h> //ioctl structures and constants #include <boost/thread/thread.hpp> //sleep #include <boost/thread/mutex.hpp> +#include <boost/foreach.hpp> #include <boost/format.hpp> #include <fstream> @@ -175,6 +177,73 @@ uhd::i2c_iface::sptr e100_ctrl::make_dev_i2c_iface(const std::string &node){ } /*********************************************************************** + * UART control implementation + **********************************************************************/ +#include <termios.h> +#include <cstring> +class uart_dev_iface : public uart_iface{ +public: + uart_dev_iface(const std::string &node){ + if ((_node_fd = ::open(node.c_str(), O_RDWR | O_NONBLOCK)) < 0){ + throw uhd::io_error("Failed to open " + node); + } + + //init the tty settings w/ termios + termios tio; + std::memset(&tio,0,sizeof(tio)); + tio.c_iflag = IGNCR; //Ignore CR + tio.c_oflag = OPOST | ONLCR; //Map NL to CR-NL on output + tio.c_cflag = CS8 | CREAD | CLOCAL; // 8n1 + tio.c_lflag = 0; + + cfsetospeed(&tio, B115200); // 115200 baud + cfsetispeed(&tio, B115200); // 115200 baud + + tcsetattr(_node_fd, TCSANOW, &tio); + } + + void write_uart(const std::string &buf){ + const ssize_t ret = ::write(_node_fd, buf.c_str(), buf.size()); + if (size_t(ret) != buf.size()) UHD_LOG << ret; + } + + std::string read_uart(double timeout){ + const boost::system_time exit_time = boost::get_system_time() + boost::posix_time::milliseconds(long(timeout*1000)); + + std::string line; + while(true){ + char ch; + const ssize_t ret = ::read(_node_fd, &ch, 1); + + //got a character -> process it + if (ret == 1){ + const bool flush = ch == '\n' or ch == '\r'; + if (flush and line.empty()) continue; //avoid flushing on empty lines + line += std::string(1, ch); + if (flush) break; + } + + //didnt get a character, check the timeout + else if (boost::get_system_time() > exit_time){ + break; + } + + //otherwise sleep for a bit + else{ + boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + } + } + return line; + } + +private: int _node_fd; +}; + +uhd::uart_iface::sptr e100_ctrl::make_gps_uart_iface(const std::string &node){ + return uhd::uart_iface::sptr(new uart_dev_iface(node)); +} + +/*********************************************************************** * USRP-E100 control implementation **********************************************************************/ class e100_ctrl_impl : public e100_ctrl{ diff --git a/host/lib/usrp/e100/e100_ctrl.hpp b/host/lib/usrp/e100/e100_ctrl.hpp index 8520ea595..fd66791d4 100644 --- a/host/lib/usrp/e100/e100_ctrl.hpp +++ b/host/lib/usrp/e100/e100_ctrl.hpp @@ -36,6 +36,9 @@ public: //! Make an i2c iface for the i2c device node static uhd::spi_iface::sptr make_aux_spi_iface(void); + //! Make a uart iface for the uart device node + static uhd::uart_iface::sptr make_gps_uart_iface(const std::string &node); + virtual void ioctl(int request, void *mem) = 0; virtual int get_file_descriptor(void) = 0; diff --git a/host/lib/usrp/e100/e100_impl.cpp b/host/lib/usrp/e100/e100_impl.cpp index b988de9a1..564a05a7e 100644 --- a/host/lib/usrp/e100/e100_impl.cpp +++ b/host/lib/usrp/e100/e100_impl.cpp @@ -230,6 +230,22 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ .publish(boost::bind(&e100_impl::get_ref_locked, this)); //////////////////////////////////////////////////////////////////// + // Create the GPSDO control + //////////////////////////////////////////////////////////////////// + try{ + _gps = gps_ctrl::make(e100_ctrl::make_gps_uart_iface(E100_UART_DEV_NODE)); + } + catch(std::exception &e){ + UHD_MSG(error) << "An error occurred making GPSDO control: " << e.what() << std::endl; + } + if (_gps.get() != NULL and _gps->gps_detected()){ + BOOST_FOREACH(const std::string &name, _gps->get_sensors()){ + _tree->create<sensor_value_t>(mb_path / "sensors" / name) + .publish(boost::bind(&gps_ctrl::get_sensor, _gps, name)); + } + } + + //////////////////////////////////////////////////////////////////// // create frontend control objects //////////////////////////////////////////////////////////////////// _rx_fe = rx_frontend_core_200::make(_fpga_ctrl, E100_REG_SR_ADDR(UE_SR_RX_FRONT)); @@ -376,6 +392,15 @@ e100_impl::e100_impl(const uhd::device_addr_t &device_addr){ _tree->access<std::string>(mb_path / "clock_source/value").set("internal"); _tree->access<std::string>(mb_path / "time_source/value").set("none"); + //GPS installed: use external ref, time, and init time spec + if (_gps.get() != NULL and _gps->gps_detected()){ + UHD_MSG(status) << "Setting references to the internal GPSDO" << std::endl; + _tree->access<std::string>(mb_path / "time_source/value").set("external"); + _tree->access<std::string>(mb_path / "clock_source/value").set("external"); + UHD_MSG(status) << "Initializing time to the internal GPSDO" << std::endl; + _time64->set_time_next_pps(time_spec_t(time_t(_gps->get_sensor("gps_time").to_int()+1))); + } + } e100_impl::~e100_impl(void){ diff --git a/host/lib/usrp/e100/e100_impl.hpp b/host/lib/usrp/e100/e100_impl.hpp index 99c8481e3..4b2ec5ee0 100644 --- a/host/lib/usrp/e100/e100_impl.hpp +++ b/host/lib/usrp/e100/e100_impl.hpp @@ -31,6 +31,7 @@ #include <uhd/usrp/subdev_spec.hpp> #include <uhd/usrp/dboard_eeprom.hpp> #include <uhd/usrp/mboard_eeprom.hpp> +#include <uhd/usrp/gps_ctrl.hpp> #include <uhd/types/sensors.hpp> #include <uhd/types/otw_type.hpp> #include <uhd/types/clock_config.hpp> @@ -47,6 +48,7 @@ uhd::transport::zero_copy_if::sptr e100_make_mmap_zero_copy(e100_ctrl::sptr ifac static const double E100_RX_LINK_RATE_BPS = 166e6/3/2*2; static const double E100_TX_LINK_RATE_BPS = 166e6/3/1*2; static const std::string E100_I2C_DEV_NODE = "/dev/i2c-3"; +static const std::string E100_UART_DEV_NODE = "/dev/ttyO0"; static const boost::uint16_t E100_FPGA_COMPAT_NUM = 0x06; static const boost::uint32_t E100_RX_SID_BASE = 2; static const boost::uint32_t E100_TX_ASYNC_SID = 1; @@ -98,6 +100,7 @@ private: e100_ctrl::sptr _fpga_ctrl; uhd::i2c_iface::sptr _dev_i2c_iface; uhd::spi_iface::sptr _aux_spi_iface; + uhd::gps_ctrl::sptr _gps; //transports uhd::transport::zero_copy_if::sptr _data_transport; |