From 29809e9697b052fa1d0cd2109c8bd5f9af178cfa Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 8 May 2010 01:58:10 +0000 Subject: moved open/close into iface, work on codec tx --- host/lib/usrp/usrp_e/codec_ctrl.cpp | 35 ++++++++++++++++++++++++++++++++--- host/lib/usrp/usrp_e/usrp_e_iface.cpp | 17 ++++++++++++----- host/lib/usrp/usrp_e/usrp_e_iface.hpp | 4 ++-- host/lib/usrp/usrp_e/usrp_e_impl.cpp | 13 ++----------- host/lib/usrp/usrp_e/usrp_e_impl.hpp | 1 - 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/host/lib/usrp/usrp_e/codec_ctrl.cpp b/host/lib/usrp/usrp_e/codec_ctrl.cpp index a430f2c6f..3f3523ddf 100644 --- a/host/lib/usrp/usrp_e/codec_ctrl.cpp +++ b/host/lib/usrp/usrp_e/codec_ctrl.cpp @@ -29,6 +29,8 @@ using namespace uhd; +static const bool codec_debug = true; + /*********************************************************************** * Codec Control Implementation **********************************************************************/ @@ -56,6 +58,9 @@ private: codec_ctrl_impl::codec_ctrl_impl(usrp_e_iface::sptr iface){ _iface = iface; + //FIXME temp poke !!! + _iface->poke16(UE_REG_MISC_TEST, 0x0f00); + //soft reset _ad9862_regs.soft_reset = 1; this->send_reg(0); @@ -65,6 +70,28 @@ codec_ctrl_impl::codec_ctrl_impl(usrp_e_iface::sptr iface){ _ad9862_regs.lsb_first = ad9862_regs_t::LSB_FIRST_MSB; _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.rx_pga_a = 0x1f; //TODO bring under api control + _ad9862_regs.rx_pga_b = 0x1f; //TODO bring under api control + _ad9862_regs.rx_twos_comp = 1; + _ad9862_regs.rx_hilbert = ad9862_regs_t::RX_HILBERT_DIS; + + //setup tx side of codec + _ad9862_regs.two_data_paths = ad9862_regs_t::TWO_DATA_PATHS_BOTH; + _ad9862_regs.interleaved = ad9862_regs_t::INTERLEAVED_SINGLE; //FIXME should be interleaved + _ad9862_regs.tx_pga_gain = 199; //TODO bring under api control + _ad9862_regs.tx_hilbert = ad9862_regs_t::TX_HILBERT_DIS; + _ad9862_regs.interp = ad9862_regs_t::INTERP_4; + _ad9862_regs.tx_twos_comp = 1; + _ad9862_regs.fine_mode = ad9862_regs_t::FINE_MODE_BYPASS; + _ad9862_regs.coarse_mod = ad9862_regs_t::COARSE_MOD_BYPASS; + _ad9862_regs.dac_a_coarse_gain = 0x3; + _ad9862_regs.dac_b_coarse_gain = 0x3; + //write the register settings to the codec for (uint8_t addr = 0; addr <= 50; addr++){ this->send_reg(addr); @@ -72,6 +99,8 @@ codec_ctrl_impl::codec_ctrl_impl(usrp_e_iface::sptr iface){ } codec_ctrl_impl::~codec_ctrl_impl(void){ + return; //FIXME remove this later + //set aux dacs to zero this->write_aux_dac(AUX_DAC_A, 0); this->write_aux_dac(AUX_DAC_B, 0); @@ -181,7 +210,7 @@ void codec_ctrl_impl::write_aux_dac(aux_dac_t which, float volts){ **********************************************************************/ void codec_ctrl_impl::send_reg(boost::uint8_t addr){ boost::uint32_t reg = _ad9862_regs.get_write_reg(addr); - //std::cout << "codec control write reg: " << std::hex << reg << std::endl; + if (codec_debug) std::cout << "codec control write reg: " << std::hex << reg << std::endl; _iface->transact_spi( UE_SPI_SS_AD9862, spi_config_t::EDGE_RISE, @@ -191,13 +220,13 @@ void codec_ctrl_impl::send_reg(boost::uint8_t addr){ void codec_ctrl_impl::recv_reg(boost::uint8_t addr){ boost::uint32_t reg = _ad9862_regs.get_read_reg(addr); - //std::cout << "codec control read reg: " << std::hex << reg << std::endl; + if (codec_debug) std::cout << "codec control read reg: " << std::hex << reg << std::endl; boost::uint32_t ret = _iface->transact_spi( UE_SPI_SS_AD9862, spi_config_t::EDGE_RISE, reg, 16, true /*rb*/ ); - //std::cout << "codec control read ret: " << std::hex << ret << std::endl; + if (codec_debug) std::cout << "codec control read ret: " << std::hex << ret << std::endl; _ad9862_regs.set_reg(addr, boost::uint16_t(ret)); } diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.cpp b/host/lib/usrp/usrp_e/usrp_e_iface.cpp index 1dbe383fa..98d8ef478 100644 --- a/host/lib/usrp/usrp_e/usrp_e_iface.cpp +++ b/host/lib/usrp/usrp_e/usrp_e_iface.cpp @@ -18,6 +18,7 @@ #include "usrp_e_iface.hpp" #include #include //ioctl +#include //open, close #include //ioctl structures and constants #include #include //mutex @@ -31,12 +32,18 @@ public: /******************************************************************* * Structors ******************************************************************/ - usrp_e_iface_impl(int node_fd){ - _node_fd = node_fd; + usrp_e_iface_impl(const std::string &node){ + //open the device node and check file descriptor + if ((_node_fd = ::open(node.c_str(), O_RDWR)) < 0){ + throw std::runtime_error(str( + boost::format("Failed to open %s") % node + )); + } } ~usrp_e_iface_impl(void){ - /* NOP */ + //close the device node file descriptor + ::close(_node_fd); } /******************************************************************* @@ -178,6 +185,6 @@ private: /*********************************************************************** * Public Make Function **********************************************************************/ -usrp_e_iface::sptr usrp_e_iface::make(int node_fd){ - return sptr(new usrp_e_iface_impl(node_fd)); +usrp_e_iface::sptr usrp_e_iface::make(const std::string &node){ + return sptr(new usrp_e_iface_impl(node)); } diff --git a/host/lib/usrp/usrp_e/usrp_e_iface.hpp b/host/lib/usrp/usrp_e/usrp_e_iface.hpp index 016d7448f..6363a24b2 100644 --- a/host/lib/usrp/usrp_e/usrp_e_iface.hpp +++ b/host/lib/usrp/usrp_e/usrp_e_iface.hpp @@ -44,10 +44,10 @@ public: /*! * Make a new usrp-e interface with the control transport. - * \param node_fd the file descriptor for the kernel module node + * \param node the device node name * \return a new usrp-e interface object */ - static sptr make(int node_fd); + static sptr make(const std::string &node); /*! * Perform an ioctl call on the device node file descriptor. diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.cpp b/host/lib/usrp/usrp_e/usrp_e_impl.cpp index 5861be102..4f7361eca 100644 --- a/host/lib/usrp/usrp_e/usrp_e_impl.cpp +++ b/host/lib/usrp/usrp_e/usrp_e_impl.cpp @@ -22,7 +22,6 @@ #include #include #include -#include //open using namespace uhd; using namespace uhd::usrp; @@ -76,15 +75,8 @@ device::sptr usrp_e::make(const device_addr_t &device_addr){ usrp_e_impl::usrp_e_impl(const std::string &node){ std::cout << boost::format("Opening USRP-E on %s") % node << std::endl; - //open the device node and check file descriptor - if ((_node_fd = ::open(node.c_str(), O_RDWR)) < 0){ - throw std::runtime_error(str( - boost::format("Failed to open %s") % node - )); - } - //setup various interfaces into hardware - _iface = usrp_e_iface::make(_node_fd); + _iface = usrp_e_iface::make(node); _clock_ctrl = clock_ctrl::make(_iface); _codec_ctrl = codec_ctrl::make(_iface); @@ -100,8 +92,7 @@ usrp_e_impl::usrp_e_impl(const std::string &node){ } usrp_e_impl::~usrp_e_impl(void){ - //close the device node file descriptor - ::close(_node_fd); + /* NOP */ } /*********************************************************************** diff --git a/host/lib/usrp/usrp_e/usrp_e_impl.hpp b/host/lib/usrp/usrp_e/usrp_e_impl.hpp index bde0f87c3..59f80c70c 100644 --- a/host/lib/usrp/usrp_e/usrp_e_impl.hpp +++ b/host/lib/usrp/usrp_e/usrp_e_impl.hpp @@ -95,7 +95,6 @@ public: private: static const size_t _max_num_samples = 2048/sizeof(boost::uint32_t); usrp_e_iface::sptr _iface; - int _node_fd; uhd::clock_config_t _clock_config; -- cgit v1.2.3