diff options
53 files changed, 1480 insertions, 1531 deletions
diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst index 88b217f1b..189f937de 100644 --- a/host/docs/usrp2.rst +++ b/host/docs/usrp2.rst @@ -406,11 +406,11 @@ In the single channel case, only one chain is ever used.  To receive from both channels,  the user must set the RX subdevice specification.  This hardware has only one daughterboard slot, -which has been aptly named slot "0". +which has been aptly named slot "A".  In the following example, a TVRX2 is installed.  Channel 0 is sourced from subdevice RX1,  channel 1 is sourced from subdevice RX2:  :: -    usrp->set_rx_subdev_spec("0:RX1 0:RX2"); +    usrp->set_rx_subdev_spec("A:RX1 A:RX2"); diff --git a/host/docs/usrp_e1xx.rst b/host/docs/usrp_e1xx.rst index fcaa57716..4ac9d133a 100644 --- a/host/docs/usrp_e1xx.rst +++ b/host/docs/usrp_e1xx.rst @@ -53,21 +53,6 @@ Example:      uhd_usrp_probe --args="master_clock_rate=52e6" -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Clock rate recovery - unbricking -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -It is possible to set a clock rate such that the UHD can no longer communicate with the FPGA. -When this occurs, it is necessary to use the usrp-e-utility to recover the clock generator. -The recovery utility works by loading a special pass-through FPGA image so the computer -can talk directly to the clock generator over a SPI interface. - -Run the following commands to restore the clock generator to a usable state: -:: - -    cd <install-path>/share/uhd/usrp_e_utilities -    ./usrp-e-utility --fpga=../images/usrp_e100_pt_fpga.bin --reclk - -  ------------------------------------------------------------------------  Clock Synchronization  ------------------------------------------------------------------------ diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 80f4bf45e..45498e3b4 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -38,4 +38,4 @@ INCLUDE_SUBDIRECTORY(fx2)  INCLUDE_SUBDIRECTORY(usrp1)  INCLUDE_SUBDIRECTORY(usrp2)  INCLUDE_SUBDIRECTORY(b100) -INCLUDE_SUBDIRECTORY(usrp_e100) +INCLUDE_SUBDIRECTORY(e100) diff --git a/host/lib/usrp/b100/CMakeLists.txt b/host/lib/usrp/b100/CMakeLists.txt index e1618a49c..28429c186 100644 --- a/host/lib/usrp/b100/CMakeLists.txt +++ b/host/lib/usrp/b100/CMakeLists.txt @@ -1,5 +1,5 @@  # -# Copyright 2010-2011 Ettus Research LLC +# Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/b100_ctrl.cpp b/host/lib/usrp/b100/b100_ctrl.cpp index 40b6435ac..6d415facc 100644 --- a/host/lib/usrp/b100/b100_ctrl.cpp +++ b/host/lib/usrp/b100/b100_ctrl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -195,7 +195,7 @@ void b100_ctrl_impl::viking_marauder_loop(boost::barrier &spawn_barrier) {              const boost::uint32_t *vrt_hdr = rbuf->cast<const boost::uint32_t *>();              vrt::if_hdr_unpack_le(vrt_hdr, if_packet_info); -            if(    if_packet_info.sid == 0  +            if(    if_packet_info.sid == B100_ASYNC_SID                 and if_packet_info.packet_type != vrt::if_packet_info_t::PACKET_TYPE_DATA){                  //fill in the async metadata                  async_metadata_t metadata; @@ -205,21 +205,18 @@ void b100_ctrl_impl::viking_marauder_loop(boost::barrier &spawn_barrier) {                      time_t(if_packet_info.tsi), size_t(if_packet_info.tsf), 64e6 //FIXME get from clock_ctrl                  );                  metadata.event_code = async_metadata_t::event_code_t(sph::get_context_code(vrt_hdr, if_packet_info)); -                //print the famous U, and push the metadata into the message queue -                if (metadata.event_code &  +                async_msg_fifo.push_with_pop_on_full(metadata); +                if (metadata.event_code &                      ( async_metadata_t::EVENT_CODE_UNDERFLOW  -                    | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET) ) -                    UHD_MSG(fastpath) << "U"; -                     -                if (metadata.event_code &  +                    | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET) +                ) UHD_MSG(fastpath) << "U"; +                else if (metadata.event_code &                      ( async_metadata_t::EVENT_CODE_SEQ_ERROR -                    | async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST) ) -                    UHD_MSG(fastpath) << "S"; -                     -                async_msg_fifo.push_with_pop_on_full(metadata); +                    | async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST) +                ) UHD_MSG(fastpath) << "S";                  continue;              } -            throw uhd::runtime_error("Control: unknown async response"); +            UHD_MSG(error) << "Control: unknown async response" << std::endl;          }      }  } diff --git a/host/lib/usrp/b100/b100_ctrl.hpp b/host/lib/usrp/b100/b100_ctrl.hpp index ae706dbb4..17887181d 100644 --- a/host/lib/usrp/b100/b100_ctrl.hpp +++ b/host/lib/usrp/b100/b100_ctrl.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/b100_iface.cpp b/host/lib/usrp/b100/b100_iface.cpp index 17ea2e6ad..402560c33 100644 --- a/host/lib/usrp/b100/b100_iface.cpp +++ b/host/lib/usrp/b100/b100_iface.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -15,7 +15,7 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "b100_iface.hpp" +#include "b100_impl.hpp"  #include "usrp_commands.h"  #include <uhd/exception.hpp>  #include <uhd/utils/byteswap.hpp> @@ -38,8 +38,6 @@ using namespace uhd::transport;   * Constants   **********************************************************************/  static const bool iface_debug = true; -static const boost::uint16_t USRP_B_FW_COMPAT_NUM = 0x02; -static const boost::uint16_t USRP_B_FPGA_COMPAT_NUM = 0x03;  /***********************************************************************   * I2C + FX2 implementation wrapper @@ -117,21 +115,21 @@ public:          const boost::uint16_t fw_compat_num = _fx2_ctrl->usrp_control_read(              VRQ_FW_COMPAT, 0, 0, data, sizeof(data)          ); -        if (fw_compat_num != USRP_B_FW_COMPAT_NUM){ +        if (fw_compat_num != B100_FW_COMPAT_NUM){              throw uhd::runtime_error(str(boost::format(                  "Expected firmware compatibility number 0x%x, but got 0x%x:\n"                  "The firmware build is not compatible with the host code build." -            ) % USRP_B_FW_COMPAT_NUM % fw_compat_num)); +            ) % B100_FW_COMPAT_NUM % fw_compat_num));          }      }      void check_fpga_compat(void){          const boost::uint16_t fpga_compat_num = this->peek16(B100_REG_MISC_COMPAT); -        if (fpga_compat_num != USRP_B_FPGA_COMPAT_NUM){ +        if (fpga_compat_num != B100_FPGA_COMPAT_NUM){              throw uhd::runtime_error(str(boost::format(                  "Expected FPGA compatibility number 0x%x, but got 0x%x:\n"                  "The FPGA build is not compatible with the host code build." -            ) % USRP_B_FPGA_COMPAT_NUM % fpga_compat_num)); +            ) % B100_FPGA_COMPAT_NUM % fpga_compat_num));          }      } diff --git a/host/lib/usrp/b100/b100_iface.hpp b/host/lib/usrp/b100/b100_iface.hpp index 57ed6a45c..a98db98dc 100644 --- a/host/lib/usrp/b100/b100_iface.hpp +++ b/host/lib/usrp/b100/b100_iface.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -45,6 +45,11 @@ public:                       b100_ctrl::sptr fpga_ctrl = b100_ctrl::sptr()      ); +    //! TODO implement this for multiple hardwares revs in the future +    std::string get_cname(void){ +        return "USRP-B100"; +    } +      /*!       * Reset the GPIF interface on the FX2       * \param which endpoint to reset diff --git a/host/lib/usrp/b100/b100_impl.cpp b/host/lib/usrp/b100/b100_impl.cpp index 7e733ddd9..db7c585d7 100644 --- a/host/lib/usrp/b100/b100_impl.cpp +++ b/host/lib/usrp/b100/b100_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -72,7 +72,7 @@ static device_addrs_t b100_find(const device_addr_t &hint)          //extract the firmware path for the b100          std::string b100_fw_image;          try{ -            b100_fw_image = find_image_path(hint.get("fw", "usrp_b100_fw.ihx")); +            b100_fw_image = find_image_path(hint.get("fw", B100_FW_FILE_NAME));          }          catch(...){              UHD_MSG(warning) << boost::format( @@ -132,7 +132,7 @@ static device::sptr b100_make(const device_addr_t &device_addr){      //extract the FPGA path for the B100      std::string b100_fpga_image = find_image_path( -        device_addr.has_key("fpga")? device_addr["fpga"] : "usrp_b100_fpga.bin" +        device_addr.has_key("fpga")? device_addr["fpga"] : B100_FPGA_FILE_NAME      );      //try to match the given device address with something on the USB bus @@ -203,6 +203,14 @@ b100_impl::b100_impl(uhd::transport::usb_zero_copy::sptr data_transport,                           const double master_clock_rate)   : _data_transport(data_transport), _fx2_ctrl(fx2_ctrl)  { +    _recv_otw_type.width = 16; +    _recv_otw_type.shift = 0; +    _recv_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; + +    _send_otw_type.width = 16; +    _send_otw_type.shift = 0; +    _send_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; +      //this is the handler object for FPGA control packets      _fpga_ctrl = b100_ctrl::make(ctrl_transport); @@ -224,10 +232,7 @@ b100_impl::b100_impl(uhd::transport::usb_zero_copy::sptr data_transport,      dboard_init();      //initialize the dsps -    rx_ddc_init(); - -    //initialize the dsps -    tx_duc_init(); +    dsp_init();      //init the subdev specs      this->mboard_set(MBOARD_PROP_RX_SUBDEV_SPEC, subdev_spec_t()); diff --git a/host/lib/usrp/b100/b100_impl.hpp b/host/lib/usrp/b100/b100_impl.hpp index daec70bca..2cea57eb5 100644 --- a/host/lib/usrp/b100/b100_impl.hpp +++ b/host/lib/usrp/b100/b100_impl.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -34,6 +34,15 @@  #ifndef INCLUDED_B100_IMPL_HPP  #define INCLUDED_B100_IMPL_HPP +static const std::string     B100_FW_FILE_NAME = "usrp_b100_fw.bin"; +static const std::string     B100_FPGA_FILE_NAME = "usrp_b100_fpga.bin"; +static const boost::uint16_t B100_FW_COMPAT_NUM = 0x02; +static const boost::uint16_t B100_FPGA_COMPAT_NUM = 0x05; +static const size_t          B100_NUM_RX_DSPS = 2; +static const size_t          B100_NUM_TX_DSPS = 1; +static const boost::uint32_t B100_DSP_SID_BASE = 2; //leave room for other dsp (increments by 1) +static const boost::uint32_t B100_ASYNC_SID = 1; +  /*!   * Make a b100 dboard interface.   * \param iface the b100 interface object @@ -113,9 +122,8 @@ private:      //handle io stuff      uhd::transport::zero_copy_if::sptr _data_transport;      UHD_PIMPL_DECL(io_impl) _io_impl; -    void update_transport_channel_mapping(void); +    void update_xport_channel_mapping(void);      void io_init(void); -    void issue_stream_cmd(const uhd::stream_cmd_t &stream_cmd);      void handle_overrun(size_t);      //otw types @@ -181,19 +189,20 @@ private:      void tx_dboard_set(const wax::obj &, const wax::obj &);      wax_obj_proxy::sptr _tx_dboard_proxy; -    //rx ddc functions and settings -    void rx_ddc_init(void); -    void rx_ddc_get(const wax::obj &, wax::obj &); -    void rx_ddc_set(const wax::obj &, const wax::obj &); -    double _ddc_freq; size_t _ddc_decim; -    wax_obj_proxy::sptr _rx_ddc_proxy; - -    //tx duc functions and settings -    void tx_duc_init(void); -    void tx_duc_get(const wax::obj &, wax::obj &); -    void tx_duc_set(const wax::obj &, const wax::obj &); -    double _duc_freq; size_t _duc_interp; -    wax_obj_proxy::sptr _tx_duc_proxy; +    //methods and shadows for the dsps +    UHD_PIMPL_DECL(dsp_impl) _dsp_impl; +    void dsp_init(void); +    void issue_ddc_stream_cmd(const uhd::stream_cmd_t &, size_t); + +    //properties interface for ddc +    void ddc_get(const wax::obj &, wax::obj &, size_t); +    void ddc_set(const wax::obj &, const wax::obj &, size_t); +    uhd::dict<std::string, wax_obj_proxy::sptr> _rx_dsp_proxies; + +    //properties interface for duc +    void duc_get(const wax::obj &, wax::obj &, size_t); +    void duc_set(const wax::obj &, const wax::obj &, size_t); +    uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dsp_proxies;      //transports      b100_ctrl::sptr _fpga_ctrl; diff --git a/host/lib/usrp/b100/b100_regs.hpp b/host/lib/usrp/b100/b100_regs.hpp index 010df283e..06288e875 100644 --- a/host/lib/usrp/b100/b100_regs.hpp +++ b/host/lib/usrp/b100/b100_regs.hpp @@ -17,7 +17,6 @@  // Slave pointers  #define B100_REG_SLAVE(n) ((n)<<7) -#define B100_REG_SR_ADDR(n) ((B100_REG_SETTINGS_BASE) + (4*(n)))  /////////////////////////////////////////////////////  // Slave 0 -- Misc Regs @@ -164,86 +163,113 @@  // Output-only, no readback, 64 registers total  //  Each register must be written 32 bits at a time  //  First the address xxx_xx00 and then xxx_xx10 +// 64 total regs in address space +#define B100_SR_RX_CTRL0 0       // 9 regs (+0 to +8) +#define B100_SR_RX_DSP0 10       // 4 regs (+0 to +3) +#define B100_SR_RX_CTRL1 16      // 9 regs (+0 to +8) +#define B100_SR_RX_DSP1 26       // 4 regs (+0 to +3) +#define B100_SR_TX_CTRL 32       // 4 regs (+0 to +3) +#define B100_SR_TX_DSP 38        // 3 regs (+0 to +2) -#define B100_REG_SETTINGS_BASE_ADDR(n) (B100_REG_SLAVE(8) + (4*(n))) +#define B100_SR_TIME64 42        // 6 regs (+0 to +5) +#define B100_SR_RX_FRONT 48      // 5 regs (+0 to +4) +#define B100_SR_TX_FRONT 54      // 5 regs (+0 to +4) -#define B100_REG_SR_MISC_TEST32        B100_REG_SETTINGS_BASE_ADDR(52) +#define B100_SR_REG_TEST32 60    // 1 reg +#define B100_SR_CLEAR_RX_FIFO 61 // 1 reg +#define B100_SR_CLEAR_TX_FIFO 62 // 1 reg +#define B100_SR_GLOBAL_RESET 63  // 1 reg + +#define B100_REG_SR_ADDR(n) (B100_REG_SLAVE(8) + (4*(n))) + +#define B100_REG_SR_MISC_TEST32        B100_REG_SR_ADDR(B100_SR_REG_TEST32) + +///////////////////////////////////////////////// +// Magic reset regs +//////////////////////////////////////////////// +#define B100_REG_CLEAR_RX           B100_REG_SR_ADDR(B100_SR_CLEAR_RX_FIFO) +#define B100_REG_CLEAR_TX           B100_REG_SR_ADDR(B100_SR_CLEAR_RX_FIFO) +#define B100_REG_GLOBAL_RESET       B100_REG_SR_ADDR(B100_SR_GLOBAL_RESET)  /////////////////////////////////////////////////  // DSP RX Regs  //////////////////////////////////////////////// -#define B100_REG_DSP_RX_ADDR(n)      (B100_REG_SETTINGS_BASE_ADDR(16) + (4*(n))) -#define B100_REG_DSP_RX_FREQ         B100_REG_DSP_RX_ADDR(0) -#define B100_REG_DSP_RX_SCALE_IQ     B100_REG_DSP_RX_ADDR(1)  // {scale_i,scale_q} -#define B100_REG_DSP_RX_DECIM_RATE   B100_REG_DSP_RX_ADDR(2)  // hb and decim rate -#define B100_REG_DSP_RX_DCOFFSET_I   B100_REG_DSP_RX_ADDR(3) // Bit 31 high sets fixed offset mode, using lower 14 bits, // otherwise it is automatic -#define B100_REG_DSP_RX_DCOFFSET_Q   B100_REG_DSP_RX_ADDR(4) // Bit 31 high sets fixed offset mode, using lower 14 bits -#define B100_REG_DSP_RX_MUX          B100_REG_DSP_RX_ADDR(5) +#define B100_REG_DSP_RX_HELPER(which, offset) ((which == 0)? \ +    (B100_REG_SR_ADDR(B100_SR_RX_DSP0 + offset)) : \ +    (B100_REG_SR_ADDR(B100_SR_RX_DSP1 + offset))) + +#define B100_REG_DSP_RX_FREQ(which)       B100_REG_DSP_RX_HELPER(which, 0) +#define B100_REG_DSP_RX_DECIM(which)      B100_REG_DSP_RX_HELPER(which, 2) +#define B100_REG_DSP_RX_MUX(which)        B100_REG_DSP_RX_HELPER(which, 3) + +#define B100_FLAG_DSP_RX_MUX_SWAP_IQ   (1 << 0) +#define B100_FLAG_DSP_RX_MUX_REAL_MODE (1 << 1)  /////////////////////////////////////////////////// -// VITA RX CTRL regs +// RX CTRL regs  /////////////////////////////////////////////////// -// The following 3 are logically a single command register. -// They are clocked into the underlying fifo when time_ticks is written. -#define B100_REG_CTRL_RX_ADDR(n)           (B100_REG_SETTINGS_BASE_ADDR(0) + (4*(n))) -#define B100_REG_CTRL_RX_STREAM_CMD        B100_REG_CTRL_RX_ADDR(0) // {now, chain, num_samples(30) -#define B100_REG_CTRL_RX_TIME_SECS         B100_REG_CTRL_RX_ADDR(1) -#define B100_REG_CTRL_RX_TIME_TICKS        B100_REG_CTRL_RX_ADDR(2) -#define B100_REG_CTRL_RX_CLEAR_OVERRUN     B100_REG_CTRL_RX_ADDR(3) // write anything to clear overrun -#define B100_REG_CTRL_RX_VRT_HEADER        B100_REG_CTRL_RX_ADDR(4) // word 0 of packet.  FPGA fills in packet counter -#define B100_REG_CTRL_RX_VRT_STREAM_ID     B100_REG_CTRL_RX_ADDR(5) // word 1 of packet. -#define B100_REG_CTRL_RX_VRT_TRAILER       B100_REG_CTRL_RX_ADDR(6) -#define B100_REG_CTRL_RX_NSAMPS_PER_PKT    B100_REG_CTRL_RX_ADDR(7) -#define B100_REG_CTRL_RX_NCHANNELS         B100_REG_CTRL_RX_ADDR(8) // 1 in basic case, up to 4 for vector sources +#define B100_REG_RX_CTRL_HELPER(which, offset) ((which == 0)? \ +    (B100_REG_SR_ADDR(B100_SR_RX_CTRL0 + offset)) : \ +    (B100_REG_SR_ADDR(B100_SR_RX_CTRL1 + offset))) + +#define B100_REG_RX_CTRL_STREAM_CMD(which)     B100_REG_RX_CTRL_HELPER(which, 0) +#define B100_REG_RX_CTRL_TIME_SECS(which)      B100_REG_RX_CTRL_HELPER(which, 1) +#define B100_REG_RX_CTRL_TIME_TICKS(which)     B100_REG_RX_CTRL_HELPER(which, 2) +#define B100_REG_RX_CTRL_CLEAR(which)          B100_REG_RX_CTRL_HELPER(which, 3) +#define B100_REG_RX_CTRL_VRT_HDR(which)        B100_REG_RX_CTRL_HELPER(which, 4) +#define B100_REG_RX_CTRL_VRT_SID(which)        B100_REG_RX_CTRL_HELPER(which, 5) +#define B100_REG_RX_CTRL_VRT_TLR(which)        B100_REG_RX_CTRL_HELPER(which, 6) +#define B100_REG_RX_CTRL_NSAMPS_PP(which)      B100_REG_RX_CTRL_HELPER(which, 7) +#define B100_REG_RX_CTRL_NCHANNELS(which)      B100_REG_RX_CTRL_HELPER(which, 8)  ///////////////////////////////////////////////// -// DSP TX Regs +// RX FE  //////////////////////////////////////////////// -#define B100_REG_DSP_TX_ADDR(n)      (B100_REG_SETTINGS_BASE_ADDR(32) + (4*(n))) -#define B100_REG_DSP_TX_FREQ         B100_REG_DSP_TX_ADDR(0) -#define B100_REG_DSP_TX_SCALE_IQ     B100_REG_DSP_TX_ADDR(1) // {scale_i,scale_q} -#define B100_REG_DSP_TX_INTERP_RATE  B100_REG_DSP_TX_ADDR(2) -#define B100_REG_DSP_TX_UNUSED       B100_REG_DSP_TX_ADDR(3) -#define B100_REG_DSP_TX_MUX          B100_REG_DSP_TX_ADDR(4) +#define B100_REG_RX_FE_SWAP_IQ             B100_REG_SR_ADDR(B100_SR_RX_FRONT + 0) //lower bit +#define B100_REG_RX_FE_MAG_CORRECTION      B100_REG_SR_ADDR(B100_SR_RX_FRONT + 1) //18 bits +#define B100_REG_RX_FE_PHASE_CORRECTION    B100_REG_SR_ADDR(B100_SR_RX_FRONT + 2) //18 bits +#define B100_REG_RX_FE_OFFSET_I            B100_REG_SR_ADDR(B100_SR_RX_FRONT + 3) //18 bits +#define B100_REG_RX_FE_OFFSET_Q            B100_REG_SR_ADDR(B100_SR_RX_FRONT + 4) //18 bits  ///////////////////////////////////////////////// -// VITA TX CTRL regs +// DSP TX Regs  //////////////////////////////////////////////// -#define B100_REG_CTRL_TX_ADDR(n)           (B100_REG_SETTINGS_BASE_ADDR(24) + (4*(n))) -#define B100_REG_CTRL_TX_NCHANNELS         B100_REG_CTRL_TX_ADDR(0) -#define B100_REG_CTRL_TX_CLEAR_UNDERRUN    B100_REG_CTRL_TX_ADDR(1) -#define B100_REG_CTRL_TX_REPORT_SID        B100_REG_CTRL_TX_ADDR(2) -#define B100_REG_CTRL_TX_POLICY            B100_REG_CTRL_TX_ADDR(3) +#define B100_REG_DSP_TX_FREQ          B100_REG_SR_ADDR(B100_SR_TX_DSP + 0) +#define B100_REG_DSP_TX_SCALE_IQ      B100_REG_SR_ADDR(B100_SR_TX_DSP + 1) +#define B100_REG_DSP_TX_INTERP_RATE   B100_REG_SR_ADDR(B100_SR_TX_DSP + 2) -#define B100_FLAG_CTRL_TX_POLICY_WAIT          (0x1 << 0) -#define B100_FLAG_CTRL_TX_POLICY_NEXT_PACKET   (0x1 << 1) -#define B100_FLAG_CTRL_TX_POLICY_NEXT_BURST    (0x1 << 2) +/////////////////////////////////////////////////// +// TX CTRL regs +/////////////////////////////////////////////////// +#define B100_REG_TX_CTRL_NUM_CHAN       B100_REG_SR_ADDR(B100_SR_TX_CTRL + 0) +#define B100_REG_TX_CTRL_CLEAR_STATE    B100_REG_SR_ADDR(B100_SR_TX_CTRL + 1) +#define B100_REG_TX_CTRL_REPORT_SID     B100_REG_SR_ADDR(B100_SR_TX_CTRL + 2) +#define B100_REG_TX_CTRL_POLICY         B100_REG_SR_ADDR(B100_SR_TX_CTRL + 3) +#define B100_REG_TX_CTRL_CYCLES_PER_UP  B100_REG_SR_ADDR(B100_SR_TX_CTRL + 4) +#define B100_REG_TX_CTRL_PACKETS_PER_UP B100_REG_SR_ADDR(B100_SR_TX_CTRL + 5) + +#define B100_FLAG_TX_CTRL_POLICY_WAIT          (0x1 << 0) +#define B100_FLAG_TX_CTRL_POLICY_NEXT_PACKET   (0x1 << 1) +#define B100_FLAG_TX_CTRL_POLICY_NEXT_BURST    (0x1 << 2) + +///////////////////////////////////////////////// +// TX FE +//////////////////////////////////////////////// +#define B100_REG_TX_FE_DC_OFFSET_I         B100_REG_SR_ADDR(B100_SR_TX_FRONT + 0) //24 bits +#define B100_REG_TX_FE_DC_OFFSET_Q         B100_REG_SR_ADDR(B100_SR_TX_FRONT + 1) //24 bits +#define B100_REG_TX_FE_MAC_CORRECTION      B100_REG_SR_ADDR(B100_SR_TX_FRONT + 2) //18 bits +#define B100_REG_TX_FE_PHASE_CORRECTION    B100_REG_SR_ADDR(B100_SR_TX_FRONT + 3) //18 bits +#define B100_REG_TX_FE_MUX                 B100_REG_SR_ADDR(B100_SR_TX_FRONT + 4) //8 bits (std output = 0x10, reversed = 0x01)  /////////////////////////////////////////////////  // VITA49 64 bit time (write only)  //////////////////////////////////////////////// -  /*! -   * \brief Time 64 flags -   * -   * <pre> -   * -   *    3                   2                   1 -   *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 -   * +-----------------------------------------------------------+-+-+ -   * |                                                           |S|P| -   * +-----------------------------------------------------------+-+-+ -   * -   * P - PPS edge selection (0=negedge, 1=posedge, default=0) -   * S - Source (0=sma, 1=mimo, 0=default) -   * -   * </pre> -   */ -#define B100_REG_TIME64_ADDR(n)     (B100_REG_SETTINGS_BASE_ADDR(40) + (4*(n))) -#define B100_REG_TIME64_SECS  B100_REG_TIME64_ADDR(0)  // value to set absolute secs to on next PPS -#define B100_REG_TIME64_TICKS B100_REG_TIME64_ADDR(1)  // value to set absolute ticks to on next PPS -#define B100_REG_TIME64_FLAGS B100_REG_TIME64_ADDR(2)  // flags - see chart above -#define B100_REG_TIME64_IMM   B100_REG_TIME64_ADDR(3)  // set immediate (0=latch on next pps, 1=latch immediate, default=0) -#define B100_REG_TIME64_TPS   B100_REG_TIME64_ADDR(4)  // clock ticks per second (counter rollover) +#define B100_REG_TIME64_SECS      B100_REG_SR_ADDR(B100_SR_TIME64 + 0) +#define B100_REG_TIME64_TICKS     B100_REG_SR_ADDR(B100_SR_TIME64 + 1) +#define B100_REG_TIME64_FLAGS     B100_REG_SR_ADDR(B100_SR_TIME64 + 2) +#define B100_REG_TIME64_IMM       B100_REG_SR_ADDR(B100_SR_TIME64 + 3) +#define B100_REG_TIME64_TPS       B100_REG_SR_ADDR(B100_SR_TIME64 + 4) +#define B100_REG_TIME64_MIMO_SYNC B100_REG_SR_ADDR(B100_SR_TIME64 + 5)  //pps flags (see above)  #define B100_FLAG_TIME64_PPS_NEGEDGE (0 << 0) @@ -254,11 +280,5 @@  #define B100_FLAG_TIME64_LATCH_NOW 1  #define B100_FLAG_TIME64_LATCH_NEXT_PPS 0 -#define B100_REG_CLEAR_RX_FIFO     B100_REG_SETTINGS_BASE_ADDR(48) -#define B100_REG_CLEAR_TX_FIFO     B100_REG_SETTINGS_BASE_ADDR(49) - -#define B100_REG_GLOBAL_RESET      B100_REG_SETTINGS_BASE_ADDR(50) -#define B100_REG_TEST32            B100_REG_SETTINGS_BASE_ADDR(52) -  #endif diff --git a/host/lib/usrp/b100/clock_ctrl.cpp b/host/lib/usrp/b100/clock_ctrl.cpp index e138242d1..02091f00a 100644 --- a/host/lib/usrp/b100/clock_ctrl.cpp +++ b/host/lib/usrp/b100/clock_ctrl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010-2011 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/clock_ctrl.hpp b/host/lib/usrp/b100/clock_ctrl.hpp index 2a2e74024..3a24f2a66 100644 --- a/host/lib/usrp/b100/clock_ctrl.hpp +++ b/host/lib/usrp/b100/clock_ctrl.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/codec_ctrl.cpp b/host/lib/usrp/b100/codec_ctrl.cpp index 4d118b68b..7e9f355d4 100644 --- a/host/lib/usrp/b100/codec_ctrl.cpp +++ b/host/lib/usrp/b100/codec_ctrl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/codec_ctrl.hpp b/host/lib/usrp/b100/codec_ctrl.hpp index 1bd579190..9ef960592 100644 --- a/host/lib/usrp/b100/codec_ctrl.hpp +++ b/host/lib/usrp/b100/codec_ctrl.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/codec_impl.cpp b/host/lib/usrp/b100/codec_impl.cpp index de3ca3a66..a959c9d60 100644 --- a/host/lib/usrp/b100/codec_impl.cpp +++ b/host/lib/usrp/b100/codec_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/ctrl_packet.hpp b/host/lib/usrp/b100/ctrl_packet.hpp index f504fc5aa..bab1f0de1 100644 --- a/host/lib/usrp/b100/ctrl_packet.hpp +++ b/host/lib/usrp/b100/ctrl_packet.hpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/dboard_iface.cpp b/host/lib/usrp/b100/dboard_iface.cpp index ec3da6220..003d86d48 100644 --- a/host/lib/usrp/b100/dboard_iface.cpp +++ b/host/lib/usrp/b100/dboard_iface.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/dboard_impl.cpp b/host/lib/usrp/b100/dboard_impl.cpp index ba3776728..ed1d4bb1d 100644 --- a/host/lib/usrp/b100/dboard_impl.cpp +++ b/host/lib/usrp/b100/dboard_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 diff --git a/host/lib/usrp/b100/dsp_impl.cpp b/host/lib/usrp/b100/dsp_impl.cpp index c1bf6bedd..e27894c1a 100644 --- a/host/lib/usrp/b100/dsp_impl.cpp +++ b/host/lib/usrp/b100/dsp_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -22,36 +22,80 @@  #include <boost/math/special_functions/round.hpp>  #include <boost/bind.hpp> -#define rint boost::math::iround -  using namespace uhd;  using namespace uhd::usrp; -static const double MASTER_CLOCK_RATE = 64e6; //TODO get from clock control +/*********************************************************************** + * DSP impl and methods + **********************************************************************/ +struct b100_impl::dsp_impl{ +    uhd::dict<size_t, size_t> ddc_decim; +    uhd::dict<size_t, double> ddc_freq; +    uhd::dict<size_t, size_t> duc_interp; +    uhd::dict<size_t, double> duc_freq; +};  /***********************************************************************   * RX DDC Initialization   **********************************************************************/ -void b100_impl::rx_ddc_init(void){ -    _rx_ddc_proxy = wax_obj_proxy::make( -        boost::bind(&b100_impl::rx_ddc_get, this, _1, _2), -        boost::bind(&b100_impl::rx_ddc_set, this, _1, _2) -    ); - -    //initial config and update -    rx_ddc_set(DSP_PROP_FREQ_SHIFT, double(0)); -    rx_ddc_set(DSP_PROP_HOST_RATE, double(16e6)); +void b100_impl::dsp_init(void){ +    //create new dsp impl +    _dsp_impl = UHD_PIMPL_MAKE(dsp_impl, ()); + +    //bind and initialize the rx dsps +    for (size_t i = 0; i < B100_NUM_RX_DSPS; i++){ +        _rx_dsp_proxies[str(boost::format("DSP%d")%i)] = wax_obj_proxy::make( +            boost::bind(&b100_impl::ddc_get, this, _1, _2, i), +            boost::bind(&b100_impl::ddc_set, this, _1, _2, i) +        ); + +        //initial config and update +        ddc_set(DSP_PROP_FREQ_SHIFT, double(0), i); +        ddc_set(DSP_PROP_HOST_RATE, double(_clock_ctrl->get_fpga_clock_rate()/16), i); + +        //setup the rx control registers +        _iface->poke32(B100_REG_RX_CTRL_CLEAR(i), 1); //reset +        _iface->poke32(B100_REG_RX_CTRL_NSAMPS_PP(i), this->get_max_recv_samps_per_packet()); +        _iface->poke32(B100_REG_RX_CTRL_NCHANNELS(i), 1); +        _iface->poke32(B100_REG_RX_CTRL_VRT_HDR(i), 0 +            | (0x1 << 28) //if data with stream id +            | (0x1 << 26) //has trailer +            | (0x3 << 22) //integer time other +            | (0x1 << 20) //fractional time sample count +        ); +        _iface->poke32(B100_REG_RX_CTRL_VRT_SID(i), B100_DSP_SID_BASE + i); +        _iface->poke32(B100_REG_RX_CTRL_VRT_TLR(i), 0); +        _iface->poke32(B100_REG_TIME64_TPS, size_t(_clock_ctrl->get_fpga_clock_rate())); +    } + +    //bind and initialize the tx dsps +    for (size_t i = 0; i < B100_NUM_TX_DSPS; i++){ +        _tx_dsp_proxies[str(boost::format("DSP%d")%i)] = wax_obj_proxy::make( +            boost::bind(&b100_impl::duc_get, this, _1, _2, i), +            boost::bind(&b100_impl::duc_set, this, _1, _2, i) +        ); + +        //initial config and update +        duc_set(DSP_PROP_FREQ_SHIFT, double(0), i); +        duc_set(DSP_PROP_HOST_RATE, double(_clock_ctrl->get_fpga_clock_rate()/16), i); + +        //init the tx control registers +        _iface->poke32(B100_REG_TX_CTRL_CLEAR_STATE, 1); //reset +        _iface->poke32(B100_REG_TX_CTRL_NUM_CHAN, 0);    //1 channel +        _iface->poke32(B100_REG_TX_CTRL_REPORT_SID, B100_ASYNC_SID); +        _iface->poke32(B100_REG_TX_CTRL_POLICY, B100_FLAG_TX_CTRL_POLICY_NEXT_PACKET); +    }  }  /***********************************************************************   * RX DDC Get   **********************************************************************/ -void b100_impl::rx_ddc_get(const wax::obj &key_, wax::obj &val){ +void b100_impl::ddc_get(const wax::obj &key_, wax::obj &val, size_t which_dsp){      named_prop_t key = named_prop_t::extract(key_);      switch(key.as<dsp_prop_t>()){      case DSP_PROP_NAME: -        val = std::string("USRP-B100 RX DSP"); +        val = str(boost::format("%s ddc%d") % _iface->get_cname() % which_dsp);          return;      case DSP_PROP_OTHERS: @@ -59,7 +103,7 @@ void b100_impl::rx_ddc_get(const wax::obj &key_, wax::obj &val){          return;      case DSP_PROP_FREQ_SHIFT: -        val = _ddc_freq; +        val = _dsp_impl->ddc_freq[which_dsp];          return;      case DSP_PROP_CODEC_RATE: @@ -67,7 +111,7 @@ void b100_impl::rx_ddc_get(const wax::obj &key_, wax::obj &val){          return;      case DSP_PROP_HOST_RATE: -        val = _clock_ctrl->get_fpga_clock_rate()/_ddc_decim; +        val = _clock_ctrl->get_fpga_clock_rate()/_dsp_impl->ddc_decim[which_dsp];          return;      default: UHD_THROW_PROP_GET_ERROR(); @@ -77,34 +121,31 @@ void b100_impl::rx_ddc_get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * RX DDC Set   **********************************************************************/ -void b100_impl::rx_ddc_set(const wax::obj &key_, const wax::obj &val){ +void b100_impl::ddc_set(const wax::obj &key_, const wax::obj &val, size_t which_dsp){      named_prop_t key = named_prop_t::extract(key_);      switch(key.as<dsp_prop_t>()){ +      case DSP_PROP_STREAM_CMD: -        issue_stream_cmd(val.as<stream_cmd_t>()); +        issue_ddc_stream_cmd(val.as<stream_cmd_t>(), which_dsp);          return;      case DSP_PROP_FREQ_SHIFT:{              double new_freq = val.as<double>(); -            _iface->poke32(B100_REG_DSP_RX_FREQ, +            _iface->poke32(B100_REG_DSP_RX_FREQ(which_dsp),                  dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate())              ); -            _ddc_freq = new_freq; //shadow +            _dsp_impl->ddc_freq[which_dsp] = new_freq; //shadow          }          return;      case DSP_PROP_HOST_RATE:{ -            //set the decimation -            _ddc_decim = rint(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); -            _iface->poke32(B100_REG_DSP_RX_DECIM_RATE, dsp_type1::calc_cic_filter_word(_ddc_decim)); +            _dsp_impl->ddc_decim[which_dsp] = boost::math::iround(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); -            //set the scaling -            static const boost::int16_t default_rx_scale_iq = 1024; -            _iface->poke32(B100_REG_DSP_RX_SCALE_IQ, -                dsp_type1::calc_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq) -            ); +            //set the decimation +            _iface->poke32(B100_REG_DSP_RX_DECIM(which_dsp), dsp_type1::calc_cic_filter_word(_dsp_impl->ddc_decim[which_dsp]));          } +        this->update_xport_channel_mapping(); //rate changed -> update          return;      default: UHD_THROW_PROP_SET_ERROR(); @@ -112,28 +153,14 @@ void b100_impl::rx_ddc_set(const wax::obj &key_, const wax::obj &val){  }  /*********************************************************************** - * TX DUC Initialization - **********************************************************************/ -void b100_impl::tx_duc_init(void){ -    _tx_duc_proxy = wax_obj_proxy::make( -        boost::bind(&b100_impl::tx_duc_get, this, _1, _2), -        boost::bind(&b100_impl::tx_duc_set, this, _1, _2) -    ); - -    //initial config and update -    tx_duc_set(DSP_PROP_FREQ_SHIFT, double(0)); -    tx_duc_set(DSP_PROP_HOST_RATE, double(16e6)); -} - -/***********************************************************************   * TX DUC Get   **********************************************************************/ -void b100_impl::tx_duc_get(const wax::obj &key_, wax::obj &val){ +void b100_impl::duc_get(const wax::obj &key_, wax::obj &val, size_t which_dsp){      named_prop_t key = named_prop_t::extract(key_);      switch(key.as<dsp_prop_t>()){      case DSP_PROP_NAME: -        val = std::string("USRP-B100 TX DSP"); +        val = str(boost::format("%s duc%d") % _iface->get_cname() % which_dsp);          return;      case DSP_PROP_OTHERS: @@ -141,7 +168,7 @@ void b100_impl::tx_duc_get(const wax::obj &key_, wax::obj &val){          return;      case DSP_PROP_FREQ_SHIFT: -        val = _duc_freq; +        val = _dsp_impl->duc_freq[which_dsp];          return;      case DSP_PROP_CODEC_RATE: @@ -149,7 +176,7 @@ void b100_impl::tx_duc_get(const wax::obj &key_, wax::obj &val){          return;      case DSP_PROP_HOST_RATE: -        val = _clock_ctrl->get_fpga_clock_rate()/_duc_interp; +        val = _clock_ctrl->get_fpga_clock_rate()/_dsp_impl->duc_interp[which_dsp];          return;      default: UHD_THROW_PROP_GET_ERROR(); @@ -159,7 +186,7 @@ void b100_impl::tx_duc_get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * TX DUC Set   **********************************************************************/ -void b100_impl::tx_duc_set(const wax::obj &key_, const wax::obj &val){ +void b100_impl::duc_set(const wax::obj &key_, const wax::obj &val, size_t which_dsp){      named_prop_t key = named_prop_t::extract(key_);      switch(key.as<dsp_prop_t>()){ @@ -169,19 +196,20 @@ void b100_impl::tx_duc_set(const wax::obj &key_, const wax::obj &val){              _iface->poke32(B100_REG_DSP_TX_FREQ,                  dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate())              ); -            _duc_freq = new_freq; //shadow +            _dsp_impl->duc_freq[which_dsp] = new_freq; //shadow          }          return;      case DSP_PROP_HOST_RATE:{ -            _duc_interp = rint(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); +            _dsp_impl->duc_interp[which_dsp] = boost::math::iround(_clock_ctrl->get_fpga_clock_rate()/val.as<double>());              //set the interpolation -            _iface->poke32(B100_REG_DSP_TX_INTERP_RATE, dsp_type1::calc_cic_filter_word(_duc_interp)); +            _iface->poke32(B100_REG_DSP_TX_INTERP_RATE, dsp_type1::calc_cic_filter_word(_dsp_impl->duc_interp[which_dsp]));              //set the scaling -            _iface->poke32(B100_REG_DSP_TX_SCALE_IQ, dsp_type1::calc_iq_scale_word(_duc_interp)); +            _iface->poke32(B100_REG_DSP_TX_SCALE_IQ, dsp_type1::calc_iq_scale_word(_dsp_impl->duc_interp[which_dsp]));          } +        this->update_xport_channel_mapping(); //rate changed -> update          return;      default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/b100/io_impl.cpp b/host/lib/usrp/b100/io_impl.cpp index 3978bea75..5377c43d5 100644 --- a/host/lib/usrp/b100/io_impl.cpp +++ b/host/lib/usrp/b100/io_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -45,17 +45,45 @@ struct b100_impl::io_impl{      io_impl(zero_copy_if::sptr data_transport):          data_transport(data_transport)      { -        /* NOP */ +        for (size_t i = 0; i < B100_NUM_RX_DSPS; i++){ +            typedef bounded_buffer<managed_recv_buffer::sptr> buffs_queue_type; +            _buffs_queue.push_back(new buffs_queue_type(data_transport->get_num_recv_frames())); +        }      }      ~io_impl(void){ -        //drain the rx buffs -        //while(data_transport->get_recv_buff().get() != NULL){ -                /* NOP */ -        //} +        for (size_t i = 0; i < _buffs_queue.size(); i++){ +            delete _buffs_queue[i]; +        }      } -    zero_copy_if::sptr &data_transport; +    zero_copy_if::sptr data_transport; + +    std::vector<bounded_buffer<managed_recv_buffer::sptr> *> _buffs_queue; + +    //gets buffer, determines if its the requested index, +    //and either queues the buffer or returns the buffer +    managed_recv_buffer::sptr get_recv_buff(const size_t index, const double timeout){ +        while (true){ +            managed_recv_buffer::sptr buff; + +            //attempt to pop a buffer from the queue +            if (_buffs_queue[index]->pop_with_haste(buff)) return buff; + +            //otherwise, call into the transport +            buff = data_transport->get_recv_buff(timeout); +            if (buff.get() == NULL) return buff; //timeout + +            //check the stream id to know which channel +            const boost::uint32_t *vrt_hdr = buff->cast<const boost::uint32_t *>(); +            const size_t rx_index = uhd::wtohx(vrt_hdr[1]) - B100_DSP_SID_BASE; +            if (rx_index == index) return buff; //got expected message + +            //otherwise queue and try again +            if (rx_index < B100_NUM_RX_DSPS) _buffs_queue[rx_index]->push_with_pop_on_full(buff); +            else UHD_MSG(error) << "Got a data packet with known SID " << uhd::wtohx(vrt_hdr[1]) << std::endl; +        } +    }      sph::recv_packet_handler recv_handler;      sph::send_packet_handler send_handler; @@ -66,46 +94,17 @@ struct b100_impl::io_impl{   * Initialize internals within this file   **********************************************************************/  void b100_impl::io_init(void){ -    _recv_otw_type.width = 16; -    _recv_otw_type.shift = 0; -    _recv_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; - -    _send_otw_type.width = 16; -    _send_otw_type.shift = 0; -    _send_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; -          _iface->reset_gpif(6); -    //reset state machines -    _iface->poke32(B100_REG_CTRL_TX_CLEAR_UNDERRUN, 0); -    _iface->poke32(B100_REG_CTRL_RX_CLEAR_OVERRUN, 0); -      _io_impl = UHD_PIMPL_MAKE(io_impl, (_data_transport)); -     -    //setup rx data path -    _iface->poke32(B100_REG_CTRL_RX_NSAMPS_PER_PKT, get_max_recv_samps_per_packet()); -    UHD_LOGV(always) << "IO: Using " << get_max_recv_samps_per_packet() << " samples per packet" << std::endl; -    _iface->poke32(B100_REG_CTRL_RX_NCHANNELS, 1); -    _iface->poke32(B100_REG_CTRL_RX_VRT_HEADER, 0 -        | (0x1 << 28) //if data with stream id -        | (0x1 << 26) //has trailer -        | (0x3 << 22) //integer time other -        | (0x1 << 20) //fractional time sample count -    ); -    _iface->poke32(B100_REG_CTRL_RX_VRT_TRAILER, 0); -    //set the streamid to reset the seq num -    _iface->poke32(B100_REG_CTRL_TX_REPORT_SID, 0); -    //setup the tx policy -    _iface->poke32(B100_REG_CTRL_TX_POLICY, B100_FLAG_CTRL_TX_POLICY_NEXT_PACKET); -          //set the expected packet size in USB frames      _iface->poke32(B100_REG_MISC_RX_LEN, 4); -    update_transport_channel_mapping(); +    update_xport_channel_mapping();  } -void b100_impl::update_transport_channel_mapping(void){ +void b100_impl::update_xport_channel_mapping(void){      if (_io_impl.get() == NULL) return; //not inited yet      //set all of the relevant properties on the handler @@ -113,10 +112,11 @@ void b100_impl::update_transport_channel_mapping(void){      _io_impl->recv_handler.resize(_rx_subdev_spec.size());      _io_impl->recv_handler.set_vrt_unpacker(&vrt::if_hdr_unpack_le);      _io_impl->recv_handler.set_tick_rate(_clock_ctrl->get_fpga_clock_rate()); -    _io_impl->recv_handler.set_samp_rate(_rx_ddc_proxy->get_link()[DSP_PROP_HOST_RATE].as<double>()); +    //FIXME assumes homogeneous rates across all dsp +    _io_impl->recv_handler.set_samp_rate(_rx_dsp_proxies[_rx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());      for (size_t chan = 0; chan < _io_impl->recv_handler.size(); chan++){          _io_impl->recv_handler.set_xport_chan_get_buff(chan, boost::bind( -            &uhd::transport::zero_copy_if::get_recv_buff, _io_impl->data_transport, _1 +            &b100_impl::io_impl::get_recv_buff, _io_impl.get(), chan, _1          ));          _io_impl->recv_handler.set_overflow_handler(chan, boost::bind(              &b100_impl::handle_overrun, this, chan @@ -129,7 +129,8 @@ void b100_impl::update_transport_channel_mapping(void){      _io_impl->send_handler.resize(_tx_subdev_spec.size());      _io_impl->send_handler.set_vrt_packer(&vrt::if_hdr_pack_le);      _io_impl->send_handler.set_tick_rate(_clock_ctrl->get_fpga_clock_rate()); -    _io_impl->send_handler.set_samp_rate(_tx_duc_proxy->get_link()[DSP_PROP_HOST_RATE].as<double>()); +    //FIXME assumes homogeneous rates across all dsp +    _io_impl->send_handler.set_samp_rate(_tx_dsp_proxies[_tx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());      for (size_t chan = 0; chan < _io_impl->send_handler.size(); chan++){          _io_impl->send_handler.set_xport_chan_get_buff(chan, boost::bind(              &uhd::transport::zero_copy_if::get_send_buff, _io_impl->data_transport, _1 @@ -155,7 +156,7 @@ size_t b100_impl::send(      const send_buffs_type &buffs, size_t nsamps_per_buff,      const tx_metadata_t &metadata, const io_type_t &io_type,      send_mode_t send_mode, double timeout -){     +){      return _io_impl->send_handler.send(          buffs, nsamps_per_buff,          metadata, io_type, @@ -189,13 +190,13 @@ size_t b100_impl::recv(      );  } -void b100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd) +void b100_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd, size_t index)  {      _io_impl->continuous_streaming = (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_START_CONTINUOUS); -    _iface->poke32(B100_REG_CTRL_RX_STREAM_CMD, dsp_type1::calc_stream_cmd_word(stream_cmd)); -    _iface->poke32(B100_REG_CTRL_RX_TIME_SECS,  boost::uint32_t(stream_cmd.time_spec.get_full_secs())); -    _iface->poke32(B100_REG_CTRL_RX_TIME_TICKS, stream_cmd.time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate())); -     +    _iface->poke32(B100_REG_RX_CTRL_STREAM_CMD(index), dsp_type1::calc_stream_cmd_word(stream_cmd)); +    _iface->poke32(B100_REG_RX_CTRL_TIME_SECS(index),  boost::uint32_t(stream_cmd.time_spec.get_full_secs())); +    _iface->poke32(B100_REG_RX_CTRL_TIME_TICKS(index), stream_cmd.time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate())); +      if (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS) {          while(_io_impl->data_transport->get_recv_buff().get() != NULL){              /* NOP */ @@ -203,8 +204,8 @@ void b100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd)      }  } -void b100_impl::handle_overrun(size_t){ +void b100_impl::handle_overrun(size_t index){      if (_io_impl->continuous_streaming){ -        this->issue_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS); +        this->issue_ddc_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS, index);      }  } diff --git a/host/lib/usrp/b100/mboard_impl.cpp b/host/lib/usrp/b100/mboard_impl.cpp index c651ff2a2..4f7dc8fce 100644 --- a/host/lib/usrp/b100/mboard_impl.cpp +++ b/host/lib/usrp/b100/mboard_impl.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2011 Ettus Research 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 @@ -85,11 +85,12 @@ void b100_impl::update_clock_config(void){   **********************************************************************/  void b100_impl::mboard_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_); +    static const std::string dboard_name = "A";      //handle the get request conditioned on the key      switch(key.as<mboard_prop_t>()){      case MBOARD_PROP_NAME: -        val = std::string("USRP-B100 mboard"); +        val = std::string(_iface->get_cname() + " mboard");          return;      case MBOARD_PROP_OTHERS: @@ -97,39 +98,37 @@ void b100_impl::mboard_get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_RX_DBOARD: -        UHD_ASSERT_THROW(key.name == ""); +        UHD_ASSERT_THROW(key.name == dboard_name);          val = _rx_dboard_proxy->get_link();          return;      case MBOARD_PROP_RX_DBOARD_NAMES: -        val = prop_names_t(1, ""); //vector of size 1 with empty string +        val = prop_names_t(1, dboard_name);          return;      case MBOARD_PROP_TX_DBOARD: -        UHD_ASSERT_THROW(key.name == ""); +        UHD_ASSERT_THROW(key.name == dboard_name);          val = _tx_dboard_proxy->get_link();          return;      case MBOARD_PROP_TX_DBOARD_NAMES: -        val = prop_names_t(1, ""); //vector of size 1 with empty string +        val = prop_names_t(1, dboard_name);          return;      case MBOARD_PROP_RX_DSP: -        UHD_ASSERT_THROW(key.name == ""); -        val = _rx_ddc_proxy->get_link(); +        val = _rx_dsp_proxies[key.name]->get_link();          return;      case MBOARD_PROP_RX_DSP_NAMES: -        val = prop_names_t(1, ""); +        val = _rx_dsp_proxies.keys();          return;      case MBOARD_PROP_TX_DSP: -        UHD_ASSERT_THROW(key.name == ""); -        val = _tx_duc_proxy->get_link(); +        val = _tx_dsp_proxies[key.name]->get_link();          return;      case MBOARD_PROP_TX_DSP_NAMES: -        val = prop_names_t(1, ""); +        val = _tx_dsp_proxies.keys();          return;      case MBOARD_PROP_CLOCK_CONFIG: @@ -198,22 +197,59 @@ void b100_impl::mboard_set(const wax::obj &key, const wax::obj &val)          }          return; -    case MBOARD_PROP_RX_SUBDEV_SPEC: +    case MBOARD_PROP_RX_SUBDEV_SPEC:{          _rx_subdev_spec = val.as<subdev_spec_t>();          verify_rx_subdev_spec(_rx_subdev_spec, _mboard_proxy->get_link()); -        UHD_ASSERT_THROW(_rx_subdev_spec.size() == 1); -        //set the mux -        _iface->poke32(B100_REG_DSP_RX_MUX, dsp_type1::calc_rx_mux_word( -            _dboard_manager->get_rx_subdev(_rx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>() -        )); -        return; +        //sanity check +        UHD_ASSERT_THROW(_rx_subdev_spec.size() <= B100_NUM_RX_DSPS); + +        //determine frontend swap IQ from the first channel +        bool fe_swap_iq = false; +        switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(0).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +        case SUBDEV_CONN_COMPLEX_QI: +        case SUBDEV_CONN_REAL_Q: +            fe_swap_iq = true; +            break; +        default: fe_swap_iq = false; +        } +        _iface->poke32(B100_REG_RX_FE_SWAP_IQ, fe_swap_iq? 1 : 0); + +        //set the dsp mux for each channel +        for (size_t i = 0; i < _rx_subdev_spec.size(); i++){ +            bool iq_swap = false, real_mode = false; +            switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(i).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +            case SUBDEV_CONN_COMPLEX_IQ: +                iq_swap = fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_COMPLEX_QI: +                iq_swap = not fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_REAL_I: +                iq_swap = fe_swap_iq; +                real_mode = true; +                break; +            case SUBDEV_CONN_REAL_Q: +                iq_swap = not fe_swap_iq; +                real_mode = true; +                break; +            } +            _iface->poke32(B100_REG_DSP_RX_MUX(i), +                (iq_swap?   B100_FLAG_DSP_RX_MUX_SWAP_IQ   : 0) | +                (real_mode? B100_FLAG_DSP_RX_MUX_REAL_MODE : 0) +            ); +        } +        this->update_xport_channel_mapping(); +    }return;      case MBOARD_PROP_TX_SUBDEV_SPEC:          _tx_subdev_spec = val.as<subdev_spec_t>();          verify_tx_subdev_spec(_tx_subdev_spec, _mboard_proxy->get_link()); -        UHD_ASSERT_THROW(_tx_subdev_spec.size() == 1); -        //set the mux and set the number of tx channels -        _iface->poke32(B100_REG_DSP_TX_MUX, dsp_type1::calc_tx_mux_word( +        //sanity check +        UHD_ASSERT_THROW(_tx_subdev_spec.size() <= B100_NUM_TX_DSPS); +        //set the mux +        _iface->poke32(B100_REG_TX_FE_MUX, dsp_type1::calc_tx_mux_word(              _dboard_manager->get_tx_subdev(_tx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()          ));          return; @@ -238,7 +274,7 @@ void b100_impl::mboard_set(const wax::obj &key, const wax::obj &val)              << "See the application notes for USRP-B100 for further instructions.\n"          ;          _clock_ctrl->set_fpga_clock_rate(val.as<double>()); -        update_transport_channel_mapping(); +        update_xport_channel_mapping();          return;      default: UHD_THROW_PROP_SET_ERROR(); diff --git a/host/lib/usrp/usrp_e100/CMakeLists.txt b/host/lib/usrp/e100/CMakeLists.txt index d0e20a3d8..15133ad5e 100644 --- a/host/lib/usrp/usrp_e100/CMakeLists.txt +++ b/host/lib/usrp/e100/CMakeLists.txt @@ -22,9 +22,9 @@  ########################################################################  # Conditionally configure the USRP-E100 support  ######################################################################## -LIBUHD_REGISTER_COMPONENT("USRP-E100" ENABLE_USRP_E100 OFF "ENABLE_LIBUHD;LINUX" OFF) +LIBUHD_REGISTER_COMPONENT("USRP-E100" ENABLE_E100 OFF "ENABLE_LIBUHD;LINUX" OFF) -IF(ENABLE_USRP_E100) +IF(ENABLE_E100)      INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)      LIBUHD_APPEND_SOURCES( @@ -39,11 +39,11 @@ IF(ENABLE_USRP_E100)          ${CMAKE_CURRENT_SOURCE_DIR}/fpga_downloader.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/io_impl.cpp          ${CMAKE_CURRENT_SOURCE_DIR}/mboard_impl.cpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_impl.cpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_impl.hpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_iface.cpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_iface.hpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_mmap_zero_copy.cpp -        ${CMAKE_CURRENT_SOURCE_DIR}/usrp_e100_regs.hpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_impl.cpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_impl.hpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_iface.cpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_iface.hpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_mmap_zero_copy.cpp +        ${CMAKE_CURRENT_SOURCE_DIR}/e100_regs.hpp      ) -ENDIF(ENABLE_USRP_E100) +ENDIF(ENABLE_E100) diff --git a/host/lib/usrp/usrp_e100/clock_ctrl.cpp b/host/lib/usrp/e100/clock_ctrl.cpp index f1b29840a..ff64d9ca7 100644 --- a/host/lib/usrp/usrp_e100/clock_ctrl.cpp +++ b/host/lib/usrp/e100/clock_ctrl.cpp @@ -21,7 +21,7 @@  #include <uhd/utils/log.hpp>  #include <uhd/utils/assert_has.hpp>  #include <boost/cstdint.hpp> -#include "usrp_e100_regs.hpp" //spi slave constants +#include "e100_regs.hpp" //spi slave constants  #include <boost/assign/list_of.hpp>  #include <boost/foreach.hpp>  #include <boost/format.hpp> @@ -165,13 +165,19 @@ static clock_settings_type get_clock_settings(double rate){  /***********************************************************************   * Clock Control Implementation   **********************************************************************/ -class usrp_e100_clock_ctrl_impl : public usrp_e100_clock_ctrl{ +class e100_clock_ctrl_impl : public e100_clock_ctrl{  public: -    usrp_e100_clock_ctrl_impl(usrp_e100_iface::sptr iface, double master_clock_rate){ +    e100_clock_ctrl_impl(e100_iface::sptr iface, double master_clock_rate){          _iface = iface;          _chan_rate = 0.0;          _out_rate = 0.0; +        //perform soft-reset +        _ad9522_regs.soft_reset = 1; +        this->send_reg(0x000); +        this->latch_regs(); +        _ad9522_regs.soft_reset = 0; +          //init the clock gen registers          //Note: out0 should already be clocking the FPGA or this isnt going to work          _ad9522_regs.sdo_active = ad9522_regs_t::SDO_ACTIVE_SDO_SDIO; @@ -192,7 +198,7 @@ public:          this->enable_tx_dboard_clock(false);      } -    ~usrp_e100_clock_ctrl_impl(void){ +    ~e100_clock_ctrl_impl(void){          this->enable_test_clock(ENABLE_THE_TEST_OUT);          this->enable_rx_dboard_clock(false);          this->enable_tx_dboard_clock(false); @@ -291,7 +297,7 @@ public:          //clock rate changed! update dboard clocks and FPGA ticks per second          set_rx_dboard_clock_rate(rate);          set_tx_dboard_clock_rate(rate); -        _iface->poke32(UE_REG_TIME64_TPS, boost::uint32_t(get_fpga_clock_rate())); +        _iface->poke32(E100_REG_TIME64_TPS, boost::uint32_t(get_fpga_clock_rate()));      }      double get_fpga_clock_rate(void){ @@ -415,7 +421,7 @@ public:      }  private: -    usrp_e100_iface::sptr _iface; +    e100_iface::sptr _iface;      ad9522_regs_t _ad9522_regs;      double _out_rate; //rate at the fpga and codec      double _chan_rate; //rate before final dividers @@ -437,8 +443,6 @@ private:      }      void calibrate_now(void){ -        set_ignore_sync_fpga_plus_codec(false); //want vco cal to sync -          //vco calibration routine:          _ad9522_regs.vco_calibration_now = 0;          this->send_reg(0x18); @@ -467,20 +471,9 @@ private:                  _ad9522_regs.get_read_reg(addr), 24              );              _ad9522_regs.set_reg(addr, reg); -            if (_ad9522_regs.digital_lock_detect) goto finalize; +            if (_ad9522_regs.digital_lock_detect) return;          }          UHD_MSG(error) << "USRP-E100 clock control: lock detection timeout" << std::endl; -        finalize: - -        set_ignore_sync_fpga_plus_codec(true); //never loose sync between these two -    } - -    void set_ignore_sync_fpga_plus_codec(bool enb){ -        _ad9522_regs.divider0_ignore_sync = (enb)?1:0; // master FPGA clock ignores sync (always on, cannot be disabled by sync pulse) -        _ad9522_regs.divider1_ignore_sync = (enb)?1:0; // codec clock ignores sync (always on, cannot be disabled by sync pulse) -        this->send_reg(0x191); -        this->send_reg(0x194); -        this->latch_regs();      }      void soft_sync(void){ @@ -514,6 +507,6 @@ private:  /***********************************************************************   * Clock Control Make   **********************************************************************/ -usrp_e100_clock_ctrl::sptr usrp_e100_clock_ctrl::make(usrp_e100_iface::sptr iface, double master_clock_rate){ -    return sptr(new usrp_e100_clock_ctrl_impl(iface, master_clock_rate)); +e100_clock_ctrl::sptr e100_clock_ctrl::make(e100_iface::sptr iface, double master_clock_rate){ +    return sptr(new e100_clock_ctrl_impl(iface, master_clock_rate));  } diff --git a/host/lib/usrp/usrp_e100/clock_ctrl.hpp b/host/lib/usrp/e100/clock_ctrl.hpp index 6f16bc6ed..f3a6de0fa 100644 --- a/host/lib/usrp/usrp_e100/clock_ctrl.hpp +++ b/host/lib/usrp/e100/clock_ctrl.hpp @@ -18,7 +18,7 @@  #ifndef INCLUDED_USRP_E100_CLOCK_CTRL_HPP  #define INCLUDED_USRP_E100_CLOCK_CTRL_HPP -#include "usrp_e100_iface.hpp" +#include "e100_iface.hpp"  #include <boost/shared_ptr.hpp>  #include <boost/utility.hpp>  #include <vector> @@ -28,9 +28,9 @@   * - Setup system clocks.   * - Disable/enable clock lines.   */ -class usrp_e100_clock_ctrl : boost::noncopyable{ +class e100_clock_ctrl : boost::noncopyable{  public: -    typedef boost::shared_ptr<usrp_e100_clock_ctrl> sptr; +    typedef boost::shared_ptr<e100_clock_ctrl> sptr;      /*!       * Make a new clock control object. @@ -38,7 +38,7 @@ public:       * \param master clock rate the FPGA rate       * \return the clock control object       */ -    static sptr make(usrp_e100_iface::sptr iface, double master_clock_rate); +    static sptr make(e100_iface::sptr iface, double master_clock_rate);      /*!       * Set the rate of the fpga clock line. diff --git a/host/lib/usrp/usrp_e100/codec_ctrl.cpp b/host/lib/usrp/e100/codec_ctrl.cpp index 43ad94a88..a796d5cc5 100644 --- a/host/lib/usrp/usrp_e100/codec_ctrl.cpp +++ b/host/lib/usrp/e100/codec_ctrl.cpp @@ -24,22 +24,22 @@  #include <boost/cstdint.hpp>  #include <boost/tuple/tuple.hpp>  #include <boost/math/special_functions/round.hpp> -#include "usrp_e100_regs.hpp" //spi slave constants +#include "e100_regs.hpp" //spi slave constants  #include <boost/assign/list_of.hpp>  using namespace uhd; -const gain_range_t usrp_e100_codec_ctrl::tx_pga_gain_range(-20, 0, double(0.1)); -const gain_range_t usrp_e100_codec_ctrl::rx_pga_gain_range(0, 20, 1); +const gain_range_t e100_codec_ctrl::tx_pga_gain_range(-20, 0, double(0.1)); +const gain_range_t e100_codec_ctrl::rx_pga_gain_range(0, 20, 1);  /***********************************************************************   * Codec Control Implementation   **********************************************************************/ -class usrp_e100_codec_ctrl_impl : public usrp_e100_codec_ctrl{ +class e100_codec_ctrl_impl : public e100_codec_ctrl{  public:      //structors -    usrp_e100_codec_ctrl_impl(usrp_e100_iface::sptr iface); -    ~usrp_e100_codec_ctrl_impl(void); +    e100_codec_ctrl_impl(e100_iface::sptr iface); +    ~e100_codec_ctrl_impl(void);      //aux adc and dac control      double read_aux_adc(aux_adc_t which); @@ -52,7 +52,7 @@ public:      double get_rx_pga_gain(char);  private: -    usrp_e100_iface::sptr _iface; +    e100_iface::sptr _iface;      ad9862_regs_t _ad9862_regs;      void send_reg(boost::uint8_t addr);      void recv_reg(boost::uint8_t addr); @@ -61,7 +61,7 @@ private:  /***********************************************************************   * Codec Control Structors   **********************************************************************/ -usrp_e100_codec_ctrl_impl::usrp_e100_codec_ctrl_impl(usrp_e100_iface::sptr iface){ +e100_codec_ctrl_impl::e100_codec_ctrl_impl(e100_iface::sptr iface){      _iface = iface;      //soft reset @@ -116,7 +116,7 @@ usrp_e100_codec_ctrl_impl::usrp_e100_codec_ctrl_impl(usrp_e100_iface::sptr iface      this->send_reg(34);  } -usrp_e100_codec_ctrl_impl::~usrp_e100_codec_ctrl_impl(void){ +e100_codec_ctrl_impl::~e100_codec_ctrl_impl(void){      //set aux dacs to zero      this->write_aux_dac(AUX_DAC_A, 0);      this->write_aux_dac(AUX_DAC_B, 0); @@ -136,19 +136,19 @@ usrp_e100_codec_ctrl_impl::~usrp_e100_codec_ctrl_impl(void){   **********************************************************************/  static const int mtpgw = 255; //maximum tx pga gain word -void usrp_e100_codec_ctrl_impl::set_tx_pga_gain(double gain){ +void e100_codec_ctrl_impl::set_tx_pga_gain(double gain){      int gain_word = int(mtpgw*(gain - tx_pga_gain_range.start())/(tx_pga_gain_range.stop() - tx_pga_gain_range.start()));      _ad9862_regs.tx_pga_gain = uhd::clip(gain_word, 0, mtpgw);      this->send_reg(16);  } -double usrp_e100_codec_ctrl_impl::get_tx_pga_gain(void){ +double e100_codec_ctrl_impl::get_tx_pga_gain(void){      return (_ad9862_regs.tx_pga_gain*(tx_pga_gain_range.stop() - tx_pga_gain_range.start())/mtpgw) + tx_pga_gain_range.start();  }  static const int mrpgw = 0x14; //maximum rx pga gain word -void usrp_e100_codec_ctrl_impl::set_rx_pga_gain(double gain, char which){ +void e100_codec_ctrl_impl::set_rx_pga_gain(double gain, char which){      int gain_word = int(mrpgw*(gain - rx_pga_gain_range.start())/(rx_pga_gain_range.stop() - rx_pga_gain_range.start()));      gain_word = uhd::clip(gain_word, 0, mrpgw);      switch(which){ @@ -164,7 +164,7 @@ void usrp_e100_codec_ctrl_impl::set_rx_pga_gain(double gain, char which){      }  } -double usrp_e100_codec_ctrl_impl::get_rx_pga_gain(char which){ +double e100_codec_ctrl_impl::get_rx_pga_gain(char which){      int gain_word;      switch(which){      case 'A': gain_word = _ad9862_regs.rx_pga_a; break; @@ -181,7 +181,7 @@ static double aux_adc_to_volts(boost::uint8_t high, boost::uint8_t low){      return double((boost::uint16_t(high) << 2) | low)*3.3/0x3ff;  } -double usrp_e100_codec_ctrl_impl::read_aux_adc(aux_adc_t which){ +double e100_codec_ctrl_impl::read_aux_adc(aux_adc_t which){      switch(which){      case AUX_ADC_A1:          _ad9862_regs.select_a = ad9862_regs_t::SELECT_A_AUX_ADC1; @@ -217,7 +217,7 @@ double usrp_e100_codec_ctrl_impl::read_aux_adc(aux_adc_t which){  /***********************************************************************   * Codec Control AUX DAC Methods   **********************************************************************/ -void usrp_e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){ +void e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){      //special case for aux dac d (aka sigma delta word)      if (which == AUX_DAC_D){          boost::uint16_t dac_word = uhd::clip(boost::math::iround(volts*0xfff/3.3), 0, 0xfff); @@ -250,7 +250,7 @@ void usrp_e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){  /***********************************************************************   * Codec Control SPI Methods   **********************************************************************/ -void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){ +void e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){      boost::uint32_t reg = _ad9862_regs.get_write_reg(addr);      UHD_LOGV(often) << "codec control write reg: " << std::hex << reg << std::endl;      _iface->write_spi( @@ -260,7 +260,7 @@ void usrp_e100_codec_ctrl_impl::send_reg(boost::uint8_t addr){      );  } -void usrp_e100_codec_ctrl_impl::recv_reg(boost::uint8_t addr){ +void e100_codec_ctrl_impl::recv_reg(boost::uint8_t addr){      boost::uint32_t reg = _ad9862_regs.get_read_reg(addr);      UHD_LOGV(often) << "codec control read reg: " << std::hex << reg << std::endl;      boost::uint32_t ret = _iface->read_spi( @@ -275,6 +275,6 @@ void usrp_e100_codec_ctrl_impl::recv_reg(boost::uint8_t addr){  /***********************************************************************   * Codec Control Make   **********************************************************************/ -usrp_e100_codec_ctrl::sptr usrp_e100_codec_ctrl::make(usrp_e100_iface::sptr iface){ -    return sptr(new usrp_e100_codec_ctrl_impl(iface)); +e100_codec_ctrl::sptr e100_codec_ctrl::make(e100_iface::sptr iface){ +    return sptr(new e100_codec_ctrl_impl(iface));  } diff --git a/host/lib/usrp/usrp_e100/codec_ctrl.hpp b/host/lib/usrp/e100/codec_ctrl.hpp index 05d7aab38..22d0390f5 100644 --- a/host/lib/usrp/usrp_e100/codec_ctrl.hpp +++ b/host/lib/usrp/e100/codec_ctrl.hpp @@ -18,7 +18,7 @@  #ifndef INCLUDED_USRP_E100_CODEC_CTRL_HPP  #define INCLUDED_USRP_E100_CODEC_CTRL_HPP -#include "usrp_e100_iface.hpp" +#include "e100_iface.hpp"  #include <uhd/types/ranges.hpp>  #include <boost/shared_ptr.hpp>  #include <boost/utility.hpp> @@ -28,9 +28,9 @@   * - Init/power down codec.   * - Read aux adc, write aux dac.   */ -class usrp_e100_codec_ctrl : boost::noncopyable{ +class e100_codec_ctrl : boost::noncopyable{  public: -    typedef boost::shared_ptr<usrp_e100_codec_ctrl> sptr; +    typedef boost::shared_ptr<e100_codec_ctrl> sptr;      static const uhd::gain_range_t tx_pga_gain_range;      static const uhd::gain_range_t rx_pga_gain_range; @@ -40,7 +40,7 @@ public:       * \param iface the usrp_e100 iface object       * \return the codec control object       */ -    static sptr make(usrp_e100_iface::sptr iface); +    static sptr make(e100_iface::sptr iface);      //! aux adc identifier constants      enum aux_adc_t{ diff --git a/host/lib/usrp/usrp_e100/codec_impl.cpp b/host/lib/usrp/e100/codec_impl.cpp index ae198aaa5..26743d173 100644 --- a/host/lib/usrp/usrp_e100/codec_impl.cpp +++ b/host/lib/usrp/e100/codec_impl.cpp @@ -15,7 +15,7 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_impl.hpp" +#include "e100_impl.hpp"  #include <uhd/exception.hpp>  #include <uhd/usrp/codec_props.hpp>  #include <boost/bind.hpp> @@ -26,15 +26,15 @@ using namespace uhd::usrp;  /***********************************************************************   * Helper Methods   **********************************************************************/ -void usrp_e100_impl::codec_init(void){ +void e100_impl::codec_init(void){      //make proxies      _rx_codec_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::rx_codec_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::rx_codec_set, this, _1, _2) +        boost::bind(&e100_impl::rx_codec_get, this, _1, _2), +        boost::bind(&e100_impl::rx_codec_set, this, _1, _2)      );      _tx_codec_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::tx_codec_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::tx_codec_set, this, _1, _2) +        boost::bind(&e100_impl::tx_codec_get, this, _1, _2), +        boost::bind(&e100_impl::tx_codec_set, this, _1, _2)      );  } @@ -43,7 +43,7 @@ void usrp_e100_impl::codec_init(void){   **********************************************************************/  static const std::string ad9862_pga_gain_name = "ad9862 pga"; -void usrp_e100_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){ +void e100_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the get request conditioned on the key @@ -62,7 +62,7 @@ void usrp_e100_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){      case CODEC_PROP_GAIN_RANGE:          UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); -        val = usrp_e100_codec_ctrl::rx_pga_gain_range; +        val = e100_codec_ctrl::rx_pga_gain_range;          return;      case CODEC_PROP_GAIN_I: @@ -79,7 +79,7 @@ void usrp_e100_impl::rx_codec_get(const wax::obj &key_, wax::obj &val){      }  } -void usrp_e100_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){ +void e100_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the set request conditioned on the key @@ -101,7 +101,7 @@ void usrp_e100_impl::rx_codec_set(const wax::obj &key_, const wax::obj &val){  /***********************************************************************   * TX Codec Properties   **********************************************************************/ -void usrp_e100_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){ +void e100_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the get request conditioned on the key @@ -120,7 +120,7 @@ void usrp_e100_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){      case CODEC_PROP_GAIN_RANGE:          UHD_ASSERT_THROW(key.name == ad9862_pga_gain_name); -        val = usrp_e100_codec_ctrl::tx_pga_gain_range; +        val = e100_codec_ctrl::tx_pga_gain_range;          return;      case CODEC_PROP_GAIN_I: //only one gain for I and Q @@ -133,7 +133,7 @@ void usrp_e100_impl::tx_codec_get(const wax::obj &key_, wax::obj &val){      }  } -void usrp_e100_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val){ +void e100_impl::tx_codec_set(const wax::obj &key_, const wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the set request conditioned on the key diff --git a/host/lib/usrp/usrp_e100/dboard_iface.cpp b/host/lib/usrp/e100/dboard_iface.cpp index 61b5a1c92..43e05aa57 100644 --- a/host/lib/usrp/usrp_e100/dboard_iface.cpp +++ b/host/lib/usrp/e100/dboard_iface.cpp @@ -15,8 +15,8 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_iface.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_iface.hpp" +#include "e100_regs.hpp"  #include "clock_ctrl.hpp"  #include "codec_ctrl.hpp"  #include <uhd/usrp/dboard_iface.hpp> @@ -33,9 +33,9 @@ class usrp_e100_dboard_iface : public dboard_iface{  public:      usrp_e100_dboard_iface( -        usrp_e100_iface::sptr iface, -        usrp_e100_clock_ctrl::sptr clock, -        usrp_e100_codec_ctrl::sptr codec +        e100_iface::sptr iface, +        e100_clock_ctrl::sptr clock, +        e100_codec_ctrl::sptr codec      ){          _iface = iface;          _clock = clock; @@ -45,8 +45,8 @@ public:          this->set_clock_rate(UNIT_RX, _clock->get_fpga_clock_rate());          this->set_clock_rate(UNIT_TX, _clock->get_fpga_clock_rate()); -        _iface->poke16(UE_REG_GPIO_RX_DBG, 0); -        _iface->poke16(UE_REG_GPIO_TX_DBG, 0); +        _iface->poke16(E100_REG_GPIO_RX_DBG, 0); +        _iface->poke16(E100_REG_GPIO_TX_DBG, 0);      }      ~usrp_e100_dboard_iface(void){ @@ -94,18 +94,18 @@ public:      double get_codec_rate(unit_t);  private: -    usrp_e100_iface::sptr _iface; -    usrp_e100_clock_ctrl::sptr _clock; -    usrp_e100_codec_ctrl::sptr _codec; +    e100_iface::sptr _iface; +    e100_clock_ctrl::sptr _clock; +    e100_codec_ctrl::sptr _codec;  };  /***********************************************************************   * Make Function   **********************************************************************/  dboard_iface::sptr make_usrp_e100_dboard_iface( -    usrp_e100_iface::sptr iface, -    usrp_e100_clock_ctrl::sptr clock, -    usrp_e100_codec_ctrl::sptr codec +    e100_iface::sptr iface, +    e100_clock_ctrl::sptr clock, +    e100_codec_ctrl::sptr codec  ){      return dboard_iface::sptr(new usrp_e100_dboard_iface(iface, clock, codec));  } @@ -153,29 +153,29 @@ double usrp_e100_dboard_iface::get_codec_rate(unit_t){  void usrp_e100_dboard_iface::_set_pin_ctrl(unit_t unit, boost::uint16_t value){      UHD_ASSERT_THROW(GPIO_SEL_ATR == 1); //make this assumption      switch(unit){ -    case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_SEL, value); return; -    case UNIT_TX: _iface->poke16(UE_REG_GPIO_TX_SEL, value); return; +    case UNIT_RX: _iface->poke16(E100_REG_GPIO_RX_SEL, value); return; +    case UNIT_TX: _iface->poke16(E100_REG_GPIO_TX_SEL, value); return;      }  }  void usrp_e100_dboard_iface::_set_gpio_ddr(unit_t unit, boost::uint16_t value){      switch(unit){ -    case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_DDR, value); return; -    case UNIT_TX: _iface->poke16(UE_REG_GPIO_TX_DDR, value); return; +    case UNIT_RX: _iface->poke16(E100_REG_GPIO_RX_DDR, value); return; +    case UNIT_TX: _iface->poke16(E100_REG_GPIO_TX_DDR, value); return;      }  }  void usrp_e100_dboard_iface::_set_gpio_out(unit_t unit, boost::uint16_t value){      switch(unit){ -    case UNIT_RX: _iface->poke16(UE_REG_GPIO_RX_IO, value); return; -    case UNIT_TX: _iface->poke16(UE_REG_GPIO_TX_IO, value); return; +    case UNIT_RX: _iface->poke16(E100_REG_GPIO_RX_IO, value); return; +    case UNIT_TX: _iface->poke16(E100_REG_GPIO_TX_IO, value); return;      }  }  boost::uint16_t usrp_e100_dboard_iface::read_gpio(unit_t unit){      switch(unit){ -    case UNIT_RX: return _iface->peek16(UE_REG_GPIO_RX_IO); -    case UNIT_TX: return _iface->peek16(UE_REG_GPIO_TX_IO); +    case UNIT_RX: return _iface->peek16(E100_REG_GPIO_RX_IO); +    case UNIT_TX: return _iface->peek16(E100_REG_GPIO_TX_IO);      default: UHD_THROW_INVALID_CODE_PATH();      }  } @@ -186,16 +186,16 @@ void usrp_e100_dboard_iface::_set_atr_reg(unit_t unit, atr_reg_t atr, boost::uin          unit_t, uhd::dict<atr_reg_t, boost::uint32_t>      > unit_to_atr_to_addr = map_list_of          (UNIT_RX, map_list_of -            (ATR_REG_IDLE,        UE_REG_ATR_IDLE_RXSIDE) -            (ATR_REG_TX_ONLY,     UE_REG_ATR_INTX_RXSIDE) -            (ATR_REG_RX_ONLY,     UE_REG_ATR_INRX_RXSIDE) -            (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_RXSIDE) +            (ATR_REG_IDLE,        E100_REG_ATR_IDLE_RXSIDE) +            (ATR_REG_TX_ONLY,     E100_REG_ATR_INTX_RXSIDE) +            (ATR_REG_RX_ONLY,     E100_REG_ATR_INRX_RXSIDE) +            (ATR_REG_FULL_DUPLEX, E100_REG_ATR_FULL_RXSIDE)          )          (UNIT_TX, map_list_of -            (ATR_REG_IDLE,        UE_REG_ATR_IDLE_TXSIDE) -            (ATR_REG_TX_ONLY,     UE_REG_ATR_INTX_TXSIDE) -            (ATR_REG_RX_ONLY,     UE_REG_ATR_INRX_TXSIDE) -            (ATR_REG_FULL_DUPLEX, UE_REG_ATR_FULL_TXSIDE) +            (ATR_REG_IDLE,        E100_REG_ATR_IDLE_TXSIDE) +            (ATR_REG_TX_ONLY,     E100_REG_ATR_INTX_TXSIDE) +            (ATR_REG_RX_ONLY,     E100_REG_ATR_INRX_TXSIDE) +            (ATR_REG_FULL_DUPLEX, E100_REG_ATR_FULL_TXSIDE)          )      ;      _iface->poke16(unit_to_atr_to_addr[unit][atr], value); @@ -213,13 +213,13 @@ void usrp_e100_dboard_iface::set_gpio_debug(unit_t unit, int which){      //set the debug on and which debug selection      switch(unit){      case UNIT_RX: -        _iface->poke16(UE_REG_GPIO_RX_DBG, 0xffff); -        _iface->poke16(UE_REG_GPIO_RX_SEL, dbg_sels); +        _iface->poke16(E100_REG_GPIO_RX_DBG, 0xffff); +        _iface->poke16(E100_REG_GPIO_RX_SEL, dbg_sels);          return;      case UNIT_TX: -        _iface->poke16(UE_REG_GPIO_TX_DBG, 0xffff); -        _iface->poke16(UE_REG_GPIO_TX_SEL, dbg_sels); +        _iface->poke16(E100_REG_GPIO_TX_DBG, 0xffff); +        _iface->poke16(E100_REG_GPIO_TX_SEL, dbg_sels);          return;      }  } @@ -274,26 +274,26 @@ byte_vector_t usrp_e100_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_b   **********************************************************************/  void usrp_e100_dboard_iface::write_aux_dac(dboard_iface::unit_t, aux_dac_t which, double value){      //same aux dacs for each unit -    static const uhd::dict<aux_dac_t, usrp_e100_codec_ctrl::aux_dac_t> which_to_aux_dac = map_list_of -        (AUX_DAC_A, usrp_e100_codec_ctrl::AUX_DAC_A) -        (AUX_DAC_B, usrp_e100_codec_ctrl::AUX_DAC_B) -        (AUX_DAC_C, usrp_e100_codec_ctrl::AUX_DAC_C) -        (AUX_DAC_D, usrp_e100_codec_ctrl::AUX_DAC_D) +    static const uhd::dict<aux_dac_t, e100_codec_ctrl::aux_dac_t> which_to_aux_dac = map_list_of +        (AUX_DAC_A, e100_codec_ctrl::AUX_DAC_A) +        (AUX_DAC_B, e100_codec_ctrl::AUX_DAC_B) +        (AUX_DAC_C, e100_codec_ctrl::AUX_DAC_C) +        (AUX_DAC_D, e100_codec_ctrl::AUX_DAC_D)      ;      _codec->write_aux_dac(which_to_aux_dac[which], value);  }  double usrp_e100_dboard_iface::read_aux_adc(dboard_iface::unit_t unit, aux_adc_t which){      static const uhd::dict< -        unit_t, uhd::dict<aux_adc_t, usrp_e100_codec_ctrl::aux_adc_t> +        unit_t, uhd::dict<aux_adc_t, e100_codec_ctrl::aux_adc_t>      > unit_to_which_to_aux_adc = map_list_of          (UNIT_RX, map_list_of -            (AUX_ADC_A, usrp_e100_codec_ctrl::AUX_ADC_A1) -            (AUX_ADC_B, usrp_e100_codec_ctrl::AUX_ADC_B1) +            (AUX_ADC_A, e100_codec_ctrl::AUX_ADC_A1) +            (AUX_ADC_B, e100_codec_ctrl::AUX_ADC_B1)          )          (UNIT_TX, map_list_of -            (AUX_ADC_A, usrp_e100_codec_ctrl::AUX_ADC_A2) -            (AUX_ADC_B, usrp_e100_codec_ctrl::AUX_ADC_B2) +            (AUX_ADC_A, e100_codec_ctrl::AUX_ADC_A2) +            (AUX_ADC_B, e100_codec_ctrl::AUX_ADC_B2)          )      ;      return _codec->read_aux_adc(unit_to_which_to_aux_adc[unit][which]); diff --git a/host/lib/usrp/usrp_e100/dboard_impl.cpp b/host/lib/usrp/e100/dboard_impl.cpp index f6bbbd5e8..86481e70a 100644 --- a/host/lib/usrp/usrp_e100/dboard_impl.cpp +++ b/host/lib/usrp/e100/dboard_impl.cpp @@ -15,8 +15,8 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_impl.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_impl.hpp" +#include "e100_regs.hpp"  #include <uhd/exception.hpp>  #include <uhd/usrp/dboard_props.hpp>  #include <uhd/usrp/subdev_props.hpp> @@ -30,7 +30,7 @@ using namespace uhd::usrp;  /***********************************************************************   * Dboard Initialization   **********************************************************************/ -void usrp_e100_impl::dboard_init(void){ +void e100_impl::dboard_init(void){      //read the dboard eeprom to extract the dboard ids      _rx_db_eeprom.load(*_iface, I2C_ADDR_RX_DB);      _tx_db_eeprom.load(*_iface, I2C_ADDR_TX_DB); @@ -48,19 +48,19 @@ void usrp_e100_impl::dboard_init(void){      //setup the dboard proxies      _rx_dboard_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::rx_dboard_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::rx_dboard_set, this, _1, _2) +        boost::bind(&e100_impl::rx_dboard_get, this, _1, _2), +        boost::bind(&e100_impl::rx_dboard_set, this, _1, _2)      );      _tx_dboard_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::tx_dboard_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::tx_dboard_set, this, _1, _2) +        boost::bind(&e100_impl::tx_dboard_get, this, _1, _2), +        boost::bind(&e100_impl::tx_dboard_set, this, _1, _2)      );  }  /***********************************************************************   * RX Dboard Get   **********************************************************************/ -void usrp_e100_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){ +void e100_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the get request conditioned on the key @@ -105,7 +105,7 @@ void usrp_e100_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * RX Dboard Set   **********************************************************************/ -void usrp_e100_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){ +void e100_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){      switch(key.as<dboard_prop_t>()){      case DBOARD_PROP_DBOARD_EEPROM:          _rx_db_eeprom = val.as<dboard_eeprom_t>(); @@ -119,7 +119,7 @@ void usrp_e100_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val){  /***********************************************************************   * TX Dboard Get   **********************************************************************/ -void usrp_e100_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){ +void e100_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the get request conditioned on the key @@ -168,7 +168,7 @@ void usrp_e100_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * TX Dboard Set   **********************************************************************/ -void usrp_e100_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){ +void e100_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val){      switch(key.as<dboard_prop_t>()){      case DBOARD_PROP_DBOARD_EEPROM:          _tx_db_eeprom = val.as<dboard_eeprom_t>(); diff --git a/host/lib/usrp/e100/dsp_impl.cpp b/host/lib/usrp/e100/dsp_impl.cpp new file mode 100644 index 000000000..fc65609a0 --- /dev/null +++ b/host/lib/usrp/e100/dsp_impl.cpp @@ -0,0 +1,217 @@ +// +// Copyright 2010-2011 Ettus Research 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 <http://www.gnu.org/licenses/>. +// + +#include "e100_impl.hpp" +#include "e100_regs.hpp" +#include <uhd/usrp/dsp_utils.hpp> +#include <uhd/usrp/dsp_props.hpp> +#include <boost/math/special_functions/round.hpp> +#include <boost/bind.hpp> + +using namespace uhd; +using namespace uhd::usrp; + +/*********************************************************************** + * DSP impl and methods + **********************************************************************/ +struct e100_impl::dsp_impl{ +    uhd::dict<size_t, size_t> ddc_decim; +    uhd::dict<size_t, double> ddc_freq; +    uhd::dict<size_t, size_t> duc_interp; +    uhd::dict<size_t, double> duc_freq; +}; + +/*********************************************************************** + * RX DDC Initialization + **********************************************************************/ +void e100_impl::dsp_init(void){ +    //create new dsp impl +    _dsp_impl = UHD_PIMPL_MAKE(dsp_impl, ()); + +    //bind and initialize the rx dsps +    for (size_t i = 0; i < E100_NUM_RX_DSPS; i++){ +        _rx_dsp_proxies[str(boost::format("DSP%d")%i)] = wax_obj_proxy::make( +            boost::bind(&e100_impl::ddc_get, this, _1, _2, i), +            boost::bind(&e100_impl::ddc_set, this, _1, _2, i) +        ); + +        //initial config and update +        ddc_set(DSP_PROP_FREQ_SHIFT, double(0), i); +        ddc_set(DSP_PROP_HOST_RATE, double(_clock_ctrl->get_fpga_clock_rate()/16), i); + +        //setup the rx control registers +        _iface->poke32(E100_REG_RX_CTRL_CLEAR(i), 1); //reset +        _iface->poke32(E100_REG_RX_CTRL_NSAMPS_PP(i), this->get_max_recv_samps_per_packet()); +        _iface->poke32(E100_REG_RX_CTRL_NCHANNELS(i), 1); +        _iface->poke32(E100_REG_RX_CTRL_VRT_HDR(i), 0 +            | (0x1 << 28) //if data with stream id +            | (0x1 << 26) //has trailer +            | (0x3 << 22) //integer time other +            | (0x1 << 20) //fractional time sample count +        ); +        _iface->poke32(E100_REG_RX_CTRL_VRT_SID(i), E100_DSP_SID_BASE + i); +        _iface->poke32(E100_REG_RX_CTRL_VRT_TLR(i), 0); +        _iface->poke32(E100_REG_TIME64_TPS, size_t(_clock_ctrl->get_fpga_clock_rate())); +    } + +    //bind and initialize the tx dsps +    for (size_t i = 0; i < E100_NUM_TX_DSPS; i++){ +        _tx_dsp_proxies[str(boost::format("DSP%d")%i)] = wax_obj_proxy::make( +            boost::bind(&e100_impl::duc_get, this, _1, _2, i), +            boost::bind(&e100_impl::duc_set, this, _1, _2, i) +        ); + +        //initial config and update +        duc_set(DSP_PROP_FREQ_SHIFT, double(0), i); +        duc_set(DSP_PROP_HOST_RATE, double(_clock_ctrl->get_fpga_clock_rate()/16), i); + +        //init the tx control registers +        _iface->poke32(E100_REG_TX_CTRL_CLEAR_STATE, 1); //reset +        _iface->poke32(E100_REG_TX_CTRL_NUM_CHAN, 0);    //1 channel +        _iface->poke32(E100_REG_TX_CTRL_REPORT_SID, E100_ASYNC_SID); +        _iface->poke32(E100_REG_TX_CTRL_POLICY, E100_FLAG_TX_CTRL_POLICY_NEXT_PACKET); +    } +} + +/*********************************************************************** + * RX DDC Get + **********************************************************************/ +void e100_impl::ddc_get(const wax::obj &key_, wax::obj &val, size_t which_dsp){ +    named_prop_t key = named_prop_t::extract(key_); + +    switch(key.as<dsp_prop_t>()){ +    case DSP_PROP_NAME: +        val = str(boost::format("%s ddc%d") % _iface->get_cname() % which_dsp); +        return; + +    case DSP_PROP_OTHERS: +        val = prop_names_t(); //empty +        return; + +    case DSP_PROP_FREQ_SHIFT: +        val = _dsp_impl->ddc_freq[which_dsp]; +        return; + +    case DSP_PROP_CODEC_RATE: +        val = _clock_ctrl->get_fpga_clock_rate(); +        return; + +    case DSP_PROP_HOST_RATE: +        val = _clock_ctrl->get_fpga_clock_rate()/_dsp_impl->ddc_decim[which_dsp]; +        return; + +    default: UHD_THROW_PROP_GET_ERROR(); +    } +} + +/*********************************************************************** + * RX DDC Set + **********************************************************************/ +void e100_impl::ddc_set(const wax::obj &key_, const wax::obj &val, size_t which_dsp){ +    named_prop_t key = named_prop_t::extract(key_); + +    switch(key.as<dsp_prop_t>()){ + +    case DSP_PROP_STREAM_CMD: +        issue_ddc_stream_cmd(val.as<stream_cmd_t>(), which_dsp); +        return; + +    case DSP_PROP_FREQ_SHIFT:{ +            double new_freq = val.as<double>(); +            _iface->poke32(E100_REG_DSP_RX_FREQ(which_dsp), +                dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate()) +            ); +            _dsp_impl->ddc_freq[which_dsp] = new_freq; //shadow +        } +        return; + +    case DSP_PROP_HOST_RATE:{ +            _dsp_impl->ddc_decim[which_dsp] = boost::math::iround(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); + +            //set the decimation +            _iface->poke32(E100_REG_DSP_RX_DECIM(which_dsp), dsp_type1::calc_cic_filter_word(_dsp_impl->ddc_decim[which_dsp])); +        } +        this->update_xport_channel_mapping(); //rate changed -> update +        return; + +    default: UHD_THROW_PROP_SET_ERROR(); +    } +} + +/*********************************************************************** + * TX DUC Get + **********************************************************************/ +void e100_impl::duc_get(const wax::obj &key_, wax::obj &val, size_t which_dsp){ +    named_prop_t key = named_prop_t::extract(key_); + +    switch(key.as<dsp_prop_t>()){ +    case DSP_PROP_NAME: +        val = str(boost::format("%s duc%d") % _iface->get_cname() % which_dsp); +        return; + +    case DSP_PROP_OTHERS: +        val = prop_names_t(); //empty +        return; + +    case DSP_PROP_FREQ_SHIFT: +        val = _dsp_impl->duc_freq[which_dsp]; +        return; + +    case DSP_PROP_CODEC_RATE: +        val = _clock_ctrl->get_fpga_clock_rate(); +        return; + +    case DSP_PROP_HOST_RATE: +        val = _clock_ctrl->get_fpga_clock_rate()/_dsp_impl->duc_interp[which_dsp]; +        return; + +    default: UHD_THROW_PROP_GET_ERROR(); +    } +} + +/*********************************************************************** + * TX DUC Set + **********************************************************************/ +void e100_impl::duc_set(const wax::obj &key_, const wax::obj &val, size_t which_dsp){ +    named_prop_t key = named_prop_t::extract(key_); + +    switch(key.as<dsp_prop_t>()){ + +    case DSP_PROP_FREQ_SHIFT:{ +            double new_freq = val.as<double>(); +            _iface->poke32(E100_REG_DSP_TX_FREQ, +                dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate()) +            ); +            _dsp_impl->duc_freq[which_dsp] = new_freq; //shadow +        } +        return; + +    case DSP_PROP_HOST_RATE:{ +            _dsp_impl->duc_interp[which_dsp] = boost::math::iround(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); + +            //set the interpolation +            _iface->poke32(E100_REG_DSP_TX_INTERP_RATE, dsp_type1::calc_cic_filter_word(_dsp_impl->duc_interp[which_dsp])); + +            //set the scaling +            _iface->poke32(E100_REG_DSP_TX_SCALE_IQ, dsp_type1::calc_iq_scale_word(_dsp_impl->duc_interp[which_dsp])); +        } +        this->update_xport_channel_mapping(); //rate changed -> update +        return; + +    default: UHD_THROW_PROP_SET_ERROR(); +    } +} diff --git a/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp b/host/lib/usrp/e100/e100_iface.cpp index 55446da63..d61ef42ad 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_iface.cpp +++ b/host/lib/usrp/e100/e100_iface.cpp @@ -15,17 +15,20 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_iface.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_iface.hpp" +#include "e100_regs.hpp"  #include <uhd/exception.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/format.hpp>  #include <boost/thread/mutex.hpp>  #include <linux/i2c-dev.h>  #include <linux/i2c.h> -#include <stdexcept> +#include <iostream> +#include <fstream>  using namespace uhd;  using namespace uhd::usrp; @@ -91,19 +94,16 @@ private: int _node_fd;  /***********************************************************************   * USRP-E100 interface implementation   **********************************************************************/ -class usrp_e100_iface_impl : public usrp_e100_iface{ +class e100_iface_impl : public e100_iface{  public:      int get_file_descriptor(void){          return _node_fd;      } -    /******************************************************************* -     * Structors -     ******************************************************************/ -    usrp_e100_iface_impl(const std::string &node): -        _i2c_dev_iface(i2c_dev_iface("/dev/i2c-3")) -    { +    void open(const std::string &node){ +        UHD_MSG(status) << "Opening device node " << node << "..." << std::endl; +          //open the device node and check file descriptor          if ((_node_fd = ::open(node.c_str(), O_RDWR)) < 0){              throw uhd::io_error("Failed to open " + node); @@ -112,18 +112,30 @@ public:          //check the module compatibility number          int module_compat_num = ::ioctl(_node_fd, USRP_E_GET_COMPAT_NUMBER, NULL);          if (module_compat_num != USRP_E_COMPAT_NUMBER){ -        throw uhd::runtime_error(str(boost::format( -            "Expected module compatibility number 0x%x, but got 0x%x:\n" -            "The module build is not compatible with the host code build." -        ) % USRP_E_COMPAT_NUMBER % module_compat_num)); +            throw uhd::runtime_error(str(boost::format( +                "Expected module compatibility number 0x%x, but got 0x%x:\n" +                "The module build is not compatible with the host code build." +            ) % USRP_E_COMPAT_NUMBER % module_compat_num)); +        } +    } + +    void close(void){ +        ::close(_node_fd); +        _node_fd = -1;      } +    /******************************************************************* +     * Structors +     ******************************************************************/ +    e100_iface_impl(void): +        _node_fd(-1), +        _i2c_dev_iface(i2c_dev_iface("/dev/i2c-3")) +    {          mb_eeprom = mboard_eeprom_t(get_i2c_dev_iface(), mboard_eeprom_t::MAP_E100);      } -    ~usrp_e100_iface_impl(void){ -        //close the device node file descriptor -        ::close(_node_fd); +    ~e100_iface_impl(void){ +        if (_node_fd >= 0) this->close();      }      /******************************************************************* @@ -245,6 +257,10 @@ public:          size_t num_bits,          bool readback      ){ +        if (which_slave == UE_SPI_SS_AD9522) return bitbang_spi( +            bits, num_bits, readback +        ); +          //load data struct          usrp_e_spi data;          data.readback = (readback)? UE_SPI_TXRX : UE_SPI_TXONLY; @@ -263,11 +279,101 @@ public:          //unload the data          return data.data;      } -     + +    boost::uint32_t bitbang_spi( +        boost::uint32_t bits, +        size_t num_bits, +        bool readback +    ){ +        boost::uint32_t rb_bits = 0; + +        _spi_bitbanger.spi_sen_gpio_write(0); + +        for (size_t i = 0; i < num_bits; i++){ +            _spi_bitbanger.spi_sclk_gpio_write(0); +            _spi_bitbanger.spi_mosi_gpio_write((bits >> (num_bits-i-1)) & 0x1); +            boost::this_thread::sleep(boost::posix_time::microseconds(10)); +            if (readback) rb_bits = (rb_bits << 1) | _spi_bitbanger.spi_miso_gpio_read(); +            _spi_bitbanger.spi_sclk_gpio_write(1); +            boost::this_thread::sleep(boost::posix_time::microseconds(10)); +        } + +        _spi_bitbanger.spi_sen_gpio_write(1); +        boost::this_thread::sleep(boost::posix_time::microseconds(100)); + +        return rb_bits; +    } + +    class bitbang_spi_guts{ +    public: +        bitbang_spi_guts(void){ +            //setup gpio pin directions +            this->set_gpio_direction(spi_sclk_gpio, "out"); +            this->set_gpio_direction(spi_sen_gpio, "out"); +            this->set_gpio_direction(spi_mosi_gpio, "out"); +            this->set_gpio_direction(spi_miso_gpio, "in"); + +            //open the gpio pin values +            _spi_sclk_gpio_value.open(str(boost::format("/sys/class/gpio/gpio%d/value") % spi_sclk_gpio).c_str()); +            _spi_sen_gpio_value.open(str(boost::format("/sys/class/gpio/gpio%d/value") % spi_sen_gpio).c_str()); +            _spi_mosi_gpio_value.open(str(boost::format("/sys/class/gpio/gpio%d/value") % spi_mosi_gpio).c_str()); +            _spi_miso_gpio_value.open(str(boost::format("/sys/class/gpio/gpio%d/value") % spi_miso_gpio).c_str()); +        } + +        ~bitbang_spi_guts(void){ +            this->set_gpio_direction(spi_sclk_gpio, "in"); +            this->set_gpio_direction(spi_sen_gpio, "in"); +            this->set_gpio_direction(spi_mosi_gpio, "in"); +        } + +        void spi_sclk_gpio_write(int val){ +            _spi_sclk_gpio_value << val << std::endl << std::flush; +        } + +        void spi_sen_gpio_write(int val){ +            _spi_sen_gpio_value << val << std::endl << std::flush; +        } + +        void spi_mosi_gpio_write(int val){ +            _spi_mosi_gpio_value << val << std::endl << std::flush; +        } + +        int spi_miso_gpio_read(void){ +            std::string val; +            std::getline(_spi_miso_gpio_value, val); +            _spi_miso_gpio_value.seekg(0); +            return int(val.at(0) - '0') & 0x1; +        } + +    private: +        enum{ +            spi_sclk_gpio = 65, +            spi_sen_gpio = 186, +            spi_mosi_gpio = 145, +            spi_miso_gpio = 147, +        }; + +        void set_gpio_direction(int gpio_num, const std::string &dir){ +            std::ofstream export_file("/sys/class/gpio/export"); +            export_file << gpio_num << std::endl << std::flush; +            export_file.close(); + +            std::ofstream dir_file(str(boost::format("/sys/class/gpio/gpio%d/direction") % gpio_num).c_str()); +            dir_file << dir << std::endl << std::flush; +            dir_file.close(); +        } + +        std::ofstream _spi_sclk_gpio_value, _spi_sen_gpio_value, _spi_mosi_gpio_value; +        std::ifstream _spi_miso_gpio_value; +    }; + +    /******************************************************************* +     * UART +     ******************************************************************/      void write_uart(boost::uint8_t, const std::string &) {          throw uhd::not_implemented_error("Unhandled command write_uart()");      } -     +      std::string read_uart(boost::uint8_t) {          throw uhd::not_implemented_error("Unhandled command read_uart()");      } @@ -276,11 +382,12 @@ private:      int _node_fd;      i2c_dev_iface _i2c_dev_iface;      boost::mutex _ctrl_mutex; +    bitbang_spi_guts _spi_bitbanger;  };  /***********************************************************************   * Public Make Function   **********************************************************************/ -usrp_e100_iface::sptr usrp_e100_iface::make(const std::string &node){ -    return sptr(new usrp_e100_iface_impl(node)); +e100_iface::sptr e100_iface::make(void){ +    return sptr(new e100_iface_impl());  } diff --git a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp b/host/lib/usrp/e100/e100_iface.hpp index d9fe96db7..a0135a468 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_iface.hpp +++ b/host/lib/usrp/e100/e100_iface.hpp @@ -15,8 +15,8 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#ifndef INCLUDED_USRP_E100_IFACE_HPP -#define INCLUDED_USRP_E100_IFACE_HPP +#ifndef INCLUDED_E100_IFACE_HPP +#define INCLUDED_E100_IFACE_HPP  #include <uhd/transport/udp_simple.hpp>  #include <uhd/usrp/mboard_eeprom.hpp> @@ -40,16 +40,20 @@   * Provides a set of functions to implementation layer.   * Including spi, peek, poke, control...   */ -class usrp_e100_iface : boost::noncopyable, public uhd::usrp::mboard_iface{ +class e100_iface : boost::noncopyable, public uhd::usrp::mboard_iface{  public: -    typedef boost::shared_ptr<usrp_e100_iface> sptr; +    typedef boost::shared_ptr<e100_iface> sptr;      /*!       * Make a new usrp-e interface with the control transport. -     * \param node the device node name       * \return a new usrp-e interface object       */ -    static sptr make(const std::string &node); +    static sptr make(void); + +    //! TODO implement this for multiple hardwares revs in the future +    std::string get_cname(void){ +        return "USRP-E100"; +    }      /*!       * Get the underlying file descriptor. @@ -58,6 +62,17 @@ public:      virtual int get_file_descriptor(void) = 0;      /*! +     * Open a device node into this iface. +     * \param node the device node name +     */ +    virtual void open(const std::string &node) = 0; + +    /*! +     * Close the open device node in this iface. +     */ +    virtual void close(void) = 0; + +    /*!       * Perform an ioctl call on the device node file descriptor.       * This will throw when the internal ioctl call fails.       * \param request the control word @@ -72,4 +87,4 @@ public:      uhd::usrp::mboard_eeprom_t mb_eeprom;  }; -#endif /* INCLUDED_USRP_E100_IFACE_HPP */ +#endif /* INCLUDED_E100_IFACE_HPP */ diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp b/host/lib/usrp/e100/e100_impl.cpp index 5b039aafc..5485388f9 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.cpp +++ b/host/lib/usrp/e100/e100_impl.cpp @@ -15,8 +15,8 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_impl.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_impl.hpp" +#include "e100_regs.hpp"  #include <uhd/utils/msg.hpp>  #include <uhd/usrp/device_props.hpp>  #include <uhd/usrp/mboard_props.hpp> @@ -35,26 +35,26 @@ namespace fs = boost::filesystem;  /***********************************************************************   * Discovery   **********************************************************************/ -static device_addrs_t usrp_e100_find(const device_addr_t &hint){ -    device_addrs_t usrp_e100_addrs; +static device_addrs_t e100_find(const device_addr_t &hint){ +    device_addrs_t e100_addrs;      //return an empty list of addresses when type is set to non-usrp-e -    if (hint.has_key("type") and hint["type"] != "e100") return usrp_e100_addrs; +    if (hint.has_key("type") and hint["type"] != "e100") return e100_addrs;      //device node not provided, assume its 0      if (not hint.has_key("node")){          device_addr_t new_addr = hint;          new_addr["node"] = "/dev/usrp_e0"; -        return usrp_e100_find(new_addr); +        return e100_find(new_addr);      }      //use the given device node name      if (fs::exists(hint["node"])){          device_addr_t new_addr; -        new_addr["type"] = "usrp-e"; +        new_addr["type"] = "e100";          new_addr["node"] = fs::system_complete(fs::path(hint["node"])).string();          try{ -            usrp_e100_iface::sptr iface = usrp_e100_iface::make(new_addr["node"]); +            e100_iface::sptr iface = e100_iface::make();              new_addr["name"] = iface->mb_eeprom["name"];              new_addr["serial"] = iface->mb_eeprom["serial"];          } @@ -66,11 +66,11 @@ static device_addrs_t usrp_e100_find(const device_addr_t &hint){              (not hint.has_key("name")   or hint["name"]   == new_addr["name"]) and              (not hint.has_key("serial") or hint["serial"] == new_addr["serial"])          ){ -            usrp_e100_addrs.push_back(new_addr); +            e100_addrs.push_back(new_addr);          }      } -    return usrp_e100_addrs; +    return e100_addrs;  }  /*********************************************************************** @@ -85,78 +85,89 @@ static size_t hash_fpga_file(const std::string &file_path){      return hash;  } -static device::sptr usrp_e100_make(const device_addr_t &device_addr){ +static device::sptr e100_make(const device_addr_t &device_addr){      //setup the main interface into fpga -    std::string node = device_addr["node"]; -    UHD_MSG(status) << boost::format("Opening USRP-E on %s") % node << std::endl; -    usrp_e100_iface::sptr iface = usrp_e100_iface::make(node); +    const std::string node = device_addr["node"]; +    e100_iface::sptr iface = e100_iface::make(); +    iface->open(node); -    //extract the fpga path for usrp-e -    std::string usrp_e100_fpga_image = find_image_path(device_addr.get("fpga", "usrp_e100_fpga.bin")); +    //setup clock control here to ensure that the FPGA has a good clock before we continue +    const double master_clock_rate = device_addr.cast<double>("master_clock_rate", E100_DEFAULT_CLOCK_RATE); +    e100_clock_ctrl::sptr clock_ctrl = e100_clock_ctrl::make(iface, master_clock_rate); -    //compute a hash of the fpga file -    const boost::uint32_t file_hash = boost::uint32_t(hash_fpga_file(usrp_e100_fpga_image)); +    //extract the fpga path for usrp-e and compute hash +    const std::string e100_fpga_image = find_image_path(device_addr.get("fpga", E100_FPGA_FILE_NAME)); +    const boost::uint32_t file_hash = boost::uint32_t(hash_fpga_file(e100_fpga_image));      //When the hash does not match: -    // - unload the iface to free the node -    // - load the fpga configuration file -    // - re-open the iface on the node -    if (iface->peek32(UE_REG_RB_MISC_TEST32) != file_hash){ -        iface.reset(); -        usrp_e100_load_fpga(usrp_e100_fpga_image); -        sleep(1); ///\todo do this better one day. -        UHD_MSG(status) << boost::format("re-Opening USRP-E on %s") % node << std::endl; -        iface = usrp_e100_iface::make(node); +    // - close the device node +    // - load the fpga bin file +    // - re-open the device node +    if (iface->peek32(E100_REG_RB_MISC_TEST32) != file_hash){ +        iface->close(); +        e100_load_fpga(e100_fpga_image); +        iface->open(node);      } -    //store the hash into the FPGA register -    iface->poke32(UE_REG_SR_MISC_TEST32, file_hash); - -    //check that the hash can be readback correctly -    if (iface->peek32(UE_REG_RB_MISC_TEST32) != file_hash){ -        UHD_MSG(error) << boost::format( -            "The FPGA hash readback failed!\n" -            "The FPGA is either clocked improperly\n" -            "or the FPGA build is not compatible.\n" -        ); +    //Perform wishbone readback tests, these tests also write the hash +    bool test_fail = false; +    UHD_MSG(status) << "Performing wishbone readback test... " << std::flush; +    for (size_t i = 0; i < 100; i++){ +        iface->poke32(E100_REG_SR_MISC_TEST32, file_hash); +        test_fail = iface->peek32(E100_REG_RB_MISC_TEST32) != file_hash; +        if (test_fail) break; //exit loop on any failure      } +    UHD_MSG(status) << ((test_fail)? " fail" : "pass") << std::endl; + +    if (test_fail) UHD_MSG(error) << boost::format( +        "The FPGA is either clocked improperly\n" +        "or the FPGA build is not compatible.\n" +        "Subsequent errors may follow...\n" +    );      //check that the compatibility is correct -    const boost::uint16_t fpga_compat_num = iface->peek16(UE_REG_MISC_COMPAT); -    if (fpga_compat_num != USRP_E_FPGA_COMPAT_NUM){ +    const boost::uint16_t fpga_compat_num = iface->peek16(E100_REG_MISC_COMPAT); +    if (fpga_compat_num != E100_FPGA_COMPAT_NUM){          throw uhd::runtime_error(str(boost::format(              "\nPlease update the FPGA image for your device.\n"              "See the application notes for USRP E-Series for instructions.\n"              "Expected FPGA compatibility number 0x%x, but got 0x%x:\n"              "The FPGA build is not compatible with the host code build." -        ) % USRP_E_FPGA_COMPAT_NUM % fpga_compat_num)); +        ) % E100_FPGA_COMPAT_NUM % fpga_compat_num));      } -    return device::sptr(new usrp_e100_impl(iface, device_addr)); +    return device::sptr(new e100_impl(device_addr, iface, clock_ctrl));  } -UHD_STATIC_BLOCK(register_usrp_e100_device){ -    device::register_device(&usrp_e100_find, &usrp_e100_make); +UHD_STATIC_BLOCK(register_e100_device){ +    device::register_device(&e100_find, &e100_make);  }  /***********************************************************************   * Structors   **********************************************************************/ -usrp_e100_impl::usrp_e100_impl( -    usrp_e100_iface::sptr iface, -    const device_addr_t &device_addr +e100_impl::e100_impl( +    const uhd::device_addr_t &device_addr, +    e100_iface::sptr iface, +    e100_clock_ctrl::sptr clock_ctrl  ):      _iface(iface), -    _data_xport(usrp_e100_make_mmap_zero_copy(_iface)), +    _clock_ctrl(clock_ctrl), +    _codec_ctrl(e100_codec_ctrl::make(_iface)), +    _data_xport(e100_make_mmap_zero_copy(_iface)),      _recv_frame_size(std::min(_data_xport->get_recv_frame_size(), size_t(device_addr.cast<double>("recv_frame_size", 1e9)))),      _send_frame_size(std::min(_data_xport->get_send_frame_size(), size_t(device_addr.cast<double>("send_frame_size", 1e9))))  { -    //setup interfaces into hardware -    const double master_clock_rate = device_addr.cast<double>("master_clock_rate", 64e6); -    _clock_ctrl = usrp_e100_clock_ctrl::make(_iface, master_clock_rate); -    _codec_ctrl = usrp_e100_codec_ctrl::make(_iface); +    //setup otw types +    _send_otw_type.width = 16; +    _send_otw_type.shift = 0; +    _send_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; + +    _recv_otw_type.width = 16; +    _recv_otw_type.shift = 0; +    _recv_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN;      //initialize the mboard      mboard_init(); @@ -165,8 +176,7 @@ usrp_e100_impl::usrp_e100_impl(      dboard_init();      //initialize the dsps -    rx_ddc_init(); -    tx_duc_init(); +    dsp_init();      //init the codec properties      codec_init(); @@ -180,14 +190,14 @@ usrp_e100_impl::usrp_e100_impl(  } -usrp_e100_impl::~usrp_e100_impl(void){ +e100_impl::~e100_impl(void){      /* NOP */  }  /***********************************************************************   * Device Get   **********************************************************************/ -void usrp_e100_impl::get(const wax::obj &key_, wax::obj &val){ +void e100_impl::get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_);      //handle the get request conditioned on the key @@ -212,6 +222,6 @@ void usrp_e100_impl::get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * Device Set   **********************************************************************/ -void usrp_e100_impl::set(const wax::obj &, const wax::obj &){ +void e100_impl::set(const wax::obj &, const wax::obj &){      UHD_THROW_PROP_SET_ERROR();  } diff --git a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp b/host/lib/usrp/e100/e100_impl.hpp index 1c17863fb..1390559a0 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_impl.hpp +++ b/host/lib/usrp/e100/e100_impl.hpp @@ -15,7 +15,7 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_iface.hpp" +#include "e100_iface.hpp"  #include "clock_ctrl.hpp"  #include "codec_ctrl.hpp"  #include <uhd/device.hpp> @@ -28,15 +28,21 @@  #include <uhd/usrp/dboard_manager.hpp>  #include <uhd/transport/zero_copy.hpp> -#ifndef INCLUDED_USRP_E100_IMPL_HPP -#define INCLUDED_USRP_E100_IMPL_HPP +#ifndef INCLUDED_E100_IMPL_HPP +#define INCLUDED_E100_IMPL_HPP -uhd::transport::zero_copy_if::sptr usrp_e100_make_mmap_zero_copy(usrp_e100_iface::sptr iface); +uhd::transport::zero_copy_if::sptr e100_make_mmap_zero_copy(e100_iface::sptr iface); -static const boost::uint16_t USRP_E_FPGA_COMPAT_NUM = 0x04; +static const std::string     E100_FPGA_FILE_NAME = "usrp_e100_fpga5.bin"; +static const boost::uint16_t E100_FPGA_COMPAT_NUM = 0x05; +static const double          E100_DEFAULT_CLOCK_RATE = 64e6; +static const size_t          E100_NUM_RX_DSPS = 2; +static const size_t          E100_NUM_TX_DSPS = 1; +static const boost::uint32_t E100_DSP_SID_BASE = 2; //leave room for other dsp (increments by 1) +static const boost::uint32_t E100_ASYNC_SID = 1;  //! load an fpga image from a bin file into the usrp-e fpga -extern void usrp_e100_load_fpga(const std::string &bin_file); +extern void e100_load_fpga(const std::string &bin_file);  /*!   * Make a usrp-e dboard interface. @@ -46,9 +52,9 @@ extern void usrp_e100_load_fpga(const std::string &bin_file);   * \return a sptr to a new dboard interface   */  uhd::usrp::dboard_iface::sptr make_usrp_e100_dboard_iface( -    usrp_e100_iface::sptr iface, -    usrp_e100_clock_ctrl::sptr clock, -    usrp_e100_codec_ctrl::sptr codec +    e100_iface::sptr iface, +    e100_clock_ctrl::sptr clock, +    e100_codec_ctrl::sptr codec  );  /*! @@ -79,11 +85,15 @@ private:   * The implementation details are encapsulated here.   * Handles properties on the mboard, dboard, dsps...   */ -class usrp_e100_impl : public uhd::device{ +class e100_impl : public uhd::device{  public:      //structors -    usrp_e100_impl(usrp_e100_iface::sptr, const uhd::device_addr_t &); -    ~usrp_e100_impl(void); +    e100_impl( +        const uhd::device_addr_t &, +        e100_iface::sptr, +        e100_clock_ctrl::sptr +    ); +    ~e100_impl(void);      //the io interface      size_t send(const send_buffs_type &, size_t, const uhd::tx_metadata_t &, const uhd::io_type_t &, send_mode_t, double); @@ -94,7 +104,13 @@ public:  private:      //interface to ioctls and file descriptor -    usrp_e100_iface::sptr _iface; +    e100_iface::sptr _iface; + +    //ad9522 clock control +    e100_clock_ctrl::sptr _clock_ctrl; + +    //ad9862 codec control +    e100_codec_ctrl::sptr _codec_ctrl;      //handle io stuff      uhd::transport::zero_copy_if::sptr _data_xport; @@ -102,19 +118,12 @@ private:      size_t _recv_frame_size, _send_frame_size;      uhd::otw_type_t _send_otw_type, _recv_otw_type;      void io_init(void); -    void issue_stream_cmd(const uhd::stream_cmd_t &stream_cmd);      void handle_overrun(size_t);      void update_xport_channel_mapping(void);      //configuration shadows      uhd::clock_config_t _clock_config; -    //ad9522 clock control -    usrp_e100_clock_ctrl::sptr _clock_ctrl; - -    //ad9862 codec control -    usrp_e100_codec_ctrl::sptr _codec_ctrl; -      //device functions and settings      void get(const wax::obj &, wax::obj &);      void set(const wax::obj &, const wax::obj &); @@ -143,19 +152,20 @@ private:      void tx_dboard_set(const wax::obj &, const wax::obj &);      wax_obj_proxy::sptr _tx_dboard_proxy; -    //rx ddc functions and settings -    void rx_ddc_init(void); -    void rx_ddc_get(const wax::obj &, wax::obj &); -    void rx_ddc_set(const wax::obj &, const wax::obj &); -    double _ddc_freq; size_t _ddc_decim; -    wax_obj_proxy::sptr _rx_ddc_proxy; +    //methods and shadows for the dsps +    UHD_PIMPL_DECL(dsp_impl) _dsp_impl; +    void dsp_init(void); +    void issue_ddc_stream_cmd(const uhd::stream_cmd_t &, size_t); + +    //properties interface for ddc +    void ddc_get(const wax::obj &, wax::obj &, size_t); +    void ddc_set(const wax::obj &, const wax::obj &, size_t); +    uhd::dict<std::string, wax_obj_proxy::sptr> _rx_dsp_proxies; -    //tx duc functions and settings -    void tx_duc_init(void); -    void tx_duc_get(const wax::obj &, wax::obj &); -    void tx_duc_set(const wax::obj &, const wax::obj &); -    double _duc_freq; size_t _duc_interp; -    wax_obj_proxy::sptr _tx_duc_proxy; +    //properties interface for duc +    void duc_get(const wax::obj &, wax::obj &, size_t); +    void duc_set(const wax::obj &, const wax::obj &, size_t); +    uhd::dict<std::string, wax_obj_proxy::sptr> _tx_dsp_proxies;      //codec functions and settings      void codec_init(void); @@ -170,4 +180,4 @@ private:      void update_clock_config(void);  }; -#endif /* INCLUDED_USRP_E100_IMPL_HPP */ +#endif /* INCLUDED_E100_IMPL_HPP */ diff --git a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp b/host/lib/usrp/e100/e100_mmap_zero_copy.cpp index bb421507a..5370b7594 100644 --- a/host/lib/usrp/usrp_e100/usrp_e100_mmap_zero_copy.cpp +++ b/host/lib/usrp/e100/e100_mmap_zero_copy.cpp @@ -15,7 +15,7 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_iface.hpp" +#include "e100_iface.hpp"  #include <uhd/transport/zero_copy.hpp>  #include <uhd/utils/log.hpp>  #include <uhd/exception.hpp> @@ -35,9 +35,9 @@ static const size_t poll_breakout = 10; //how many poll timeouts constitute a fu   * Reusable managed receiver buffer:   *  - The buffer knows how to claim and release a frame.   **********************************************************************/ -class usrp_e100_mmap_zero_copy_mrb : public managed_recv_buffer{ +class e100_mmap_zero_copy_mrb : public managed_recv_buffer{  public: -    usrp_e100_mmap_zero_copy_mrb(void *mem, ring_buffer_info *info): +    e100_mmap_zero_copy_mrb(void *mem, ring_buffer_info *info):          _mem(mem), _info(info) { /* NOP */ }      void release(void){ @@ -66,9 +66,9 @@ private:   * Reusable managed send buffer:   *  - The buffer knows how to claim and release a frame.   **********************************************************************/ -class usrp_e100_mmap_zero_copy_msb : public managed_send_buffer{ +class e100_mmap_zero_copy_msb : public managed_send_buffer{  public: -    usrp_e100_mmap_zero_copy_msb(void *mem, ring_buffer_info *info, size_t len, int fd): +    e100_mmap_zero_copy_msb(void *mem, ring_buffer_info *info, size_t len, int fd):          _mem(mem), _info(info), _len(len), _fd(fd) { /* NOP */ }      void commit(size_t len){ @@ -102,9 +102,9 @@ private:  /***********************************************************************   * The zero copy interface implementation   **********************************************************************/ -class usrp_e100_mmap_zero_copy_impl : public zero_copy_if{ +class e100_mmap_zero_copy_impl : public zero_copy_if{  public: -    usrp_e100_mmap_zero_copy_impl(usrp_e100_iface::sptr iface): +    e100_mmap_zero_copy_impl(e100_iface::sptr iface):          _fd(iface->get_file_descriptor()), _recv_index(0), _send_index(0)      {          //get system sizes @@ -162,28 +162,28 @@ public:          //initialize the managed receive buffers          for (size_t i = 0; i < get_num_recv_frames(); i++){ -            _mrb_pool.push_back(usrp_e100_mmap_zero_copy_mrb( +            _mrb_pool.push_back(e100_mmap_zero_copy_mrb(                  recv_buff + get_recv_frame_size()*i, (*recv_info) + i              ));          }          //initialize the managed send buffers          for (size_t i = 0; i < get_num_recv_frames(); i++){ -            _msb_pool.push_back(usrp_e100_mmap_zero_copy_msb( +            _msb_pool.push_back(e100_mmap_zero_copy_msb(                  send_buff + get_send_frame_size()*i, (*send_info) + i,                  get_send_frame_size(), _fd              ));          }      } -    ~usrp_e100_mmap_zero_copy_impl(void){ +    ~e100_mmap_zero_copy_impl(void){          UHD_LOG << "cleanup: munmap" << std::endl;          ::munmap(_mapped_mem, _map_size);      }      managed_recv_buffer::sptr get_recv_buff(double timeout){          if (fp_verbose) UHD_LOGV(always) << "get_recv_buff: " << _recv_index << std::endl; -        usrp_e100_mmap_zero_copy_mrb &mrb = _mrb_pool[_recv_index]; +        e100_mmap_zero_copy_mrb &mrb = _mrb_pool[_recv_index];          //poll/wait for a ready frame          if (not mrb.ready()){ @@ -215,7 +215,7 @@ public:      managed_send_buffer::sptr get_send_buff(double timeout){          if (fp_verbose) UHD_LOGV(always) << "get_send_buff: " << _send_index << std::endl; -        usrp_e100_mmap_zero_copy_msb &msb = _msb_pool[_send_index]; +        e100_mmap_zero_copy_msb &msb = _msb_pool[_send_index];          //poll/wait for a ready frame          if (not msb.ready()){ @@ -254,8 +254,8 @@ private:      size_t _frame_size, _map_size;      //re-usable managed buffers -    std::vector<usrp_e100_mmap_zero_copy_mrb> _mrb_pool; -    std::vector<usrp_e100_mmap_zero_copy_msb> _msb_pool; +    std::vector<e100_mmap_zero_copy_mrb> _mrb_pool; +    std::vector<e100_mmap_zero_copy_msb> _msb_pool;      //indexes into sub-sections of mapped memory      size_t _recv_index, _send_index; @@ -264,6 +264,6 @@ private:  /***********************************************************************   * The zero copy interface make function   **********************************************************************/ -zero_copy_if::sptr usrp_e100_make_mmap_zero_copy(usrp_e100_iface::sptr iface){ -    return zero_copy_if::sptr(new usrp_e100_mmap_zero_copy_impl(iface)); +zero_copy_if::sptr e100_make_mmap_zero_copy(e100_iface::sptr iface){ +    return zero_copy_if::sptr(new e100_mmap_zero_copy_impl(iface));  } diff --git a/host/lib/usrp/e100/e100_regs.hpp b/host/lib/usrp/e100/e100_regs.hpp new file mode 100644 index 000000000..5be607389 --- /dev/null +++ b/host/lib/usrp/e100/e100_regs.hpp @@ -0,0 +1,242 @@ + + +//////////////////////////////////////////////////////////////// +// +//         Memory map for embedded wishbone bus +// +//////////////////////////////////////////////////////////////// + +// All addresses are byte addresses.  All accesses are word (16-bit) accesses. +//  This means that address bit 0 is usually 0. +//  There are 11 bits of address for the control. + +#ifndef INCLUDED_E100_REGS_HPP +#define INCLUDED_E100_REGS_HPP + +///////////////////////////////////////////////////// +// Slave pointers + +#define E100_REG_SLAVE(n) ((n)<<7) + +///////////////////////////////////////////////////// +// Slave 0 -- Misc Regs + +#define E100_REG_MISC_BASE E100_REG_SLAVE(0) + +#define E100_REG_MISC_LED        E100_REG_MISC_BASE + 0 +#define E100_REG_MISC_SW         E100_REG_MISC_BASE + 2 +#define E100_REG_MISC_CGEN_CTRL  E100_REG_MISC_BASE + 4 +#define E100_REG_MISC_CGEN_ST    E100_REG_MISC_BASE + 6 +#define E100_REG_MISC_TEST       E100_REG_MISC_BASE + 8 +#define E100_REG_MISC_RX_LEN     E100_REG_MISC_BASE + 10 +#define E100_REG_MISC_TX_LEN     E100_REG_MISC_BASE + 12 +#define E100_REG_MISC_XFER_RATE  E100_REG_MISC_BASE + 14 +#define E100_REG_MISC_COMPAT     E100_REG_MISC_BASE + 16 + +///////////////////////////////////////////////////// +// Slave 1 -- UART +//   CLKDIV is 16 bits, others are only 8 + +#define E100_REG_UART_BASE E100_REG_SLAVE(1) + +#define E100_REG_UART_CLKDIV  E100_REG_UART_BASE + 0 +#define E100_REG_UART_TXLEVEL E100_REG_UART_BASE + 2 +#define E100_REG_UART_RXLEVEL E100_REG_UART_BASE + 4 +#define E100_REG_UART_TXCHAR  E100_REG_UART_BASE + 6 +#define E100_REG_UART_RXCHAR  E100_REG_UART_BASE + 8 + +///////////////////////////////////////////////////// +// Slave 2 -- SPI Core +//   This should be accessed through the IOCTL +//   Users should not touch directly + +#define E100_REG_SPI_BASE E100_REG_SLAVE(2) + +//spi slave constants +#define UE_SPI_SS_AD9522    (1 << 3) +#define UE_SPI_SS_AD9862    (1 << 2) +#define UE_SPI_SS_TX_DB     (1 << 1) +#define UE_SPI_SS_RX_DB     (1 << 0) + +//////////////////////////////////////////////// +// Slave 3 -- I2C Core +//   This should be accessed through the IOCTL +//   Users should not touch directly + +#define E100_REG_I2C_BASE E100_REG_SLAVE(3) + + +//////////////////////////////////////////////// +// Slave 4 -- GPIO + +#define E100_REG_GPIO_BASE E100_REG_SLAVE(4) + +#define E100_REG_GPIO_RX_IO      E100_REG_GPIO_BASE + 0 +#define E100_REG_GPIO_TX_IO      E100_REG_GPIO_BASE + 2 +#define E100_REG_GPIO_RX_DDR     E100_REG_GPIO_BASE + 4 +#define E100_REG_GPIO_TX_DDR     E100_REG_GPIO_BASE + 6 +#define E100_REG_GPIO_RX_SEL     E100_REG_GPIO_BASE + 8 +#define E100_REG_GPIO_TX_SEL     E100_REG_GPIO_BASE + 10 +#define E100_REG_GPIO_RX_DBG     E100_REG_GPIO_BASE + 12 +#define E100_REG_GPIO_TX_DBG     E100_REG_GPIO_BASE + 14 + +//possible bit values for sel when dbg is 0: +#define GPIO_SEL_SW    0 // if pin is an output, set by software in the io reg +#define GPIO_SEL_ATR   1 // if pin is an output, set by ATR logic + +//possible bit values for sel when dbg is 1: +#define GPIO_SEL_DEBUG_0   0 // if pin is an output, debug lines from FPGA fabric +#define GPIO_SEL_DEBUG_1   1 // if pin is an output, debug lines from FPGA fabric + +/////////////////////////////////////////////////// +// Slave 6 -- ATR Controller +//   16 regs + +#define E100_REG_ATR_BASE  E100_REG_SLAVE(6) + +#define	E100_REG_ATR_IDLE_RXSIDE  E100_REG_ATR_BASE + 0 +#define	E100_REG_ATR_IDLE_TXSIDE  E100_REG_ATR_BASE + 2 +#define E100_REG_ATR_INTX_RXSIDE  E100_REG_ATR_BASE + 4 +#define E100_REG_ATR_INTX_TXSIDE  E100_REG_ATR_BASE + 6 +#define	E100_REG_ATR_INRX_RXSIDE  E100_REG_ATR_BASE + 8 +#define	E100_REG_ATR_INRX_TXSIDE  E100_REG_ATR_BASE + 10 +#define	E100_REG_ATR_FULL_RXSIDE  E100_REG_ATR_BASE + 12 +#define	E100_REG_ATR_FULL_TXSIDE  E100_REG_ATR_BASE + 14 + +/////////////////////////////////////////////////// +// Slave 7 -- Readback Mux 32 + +#define E100_REG_RB_MUX_32_BASE  E100_REG_SLAVE(7) + +#define E100_REG_RB_TIME_NOW_SECS   E100_REG_RB_MUX_32_BASE + 0 +#define E100_REG_RB_TIME_NOW_TICKS  E100_REG_RB_MUX_32_BASE + 4 +#define E100_REG_RB_TIME_PPS_SECS   E100_REG_RB_MUX_32_BASE + 8 +#define E100_REG_RB_TIME_PPS_TICKS  E100_REG_RB_MUX_32_BASE + 12 +#define E100_REG_RB_MISC_TEST32     E100_REG_RB_MUX_32_BASE + 16 + +//////////////////////////////////////////////////// +// Slave 8 -- Settings Bus +// +// Output-only, no readback, 64 registers total +//  Each register must be written 64 bits at a time +//  First the address xxx_xx00 and then xxx_xx10 + +// 64 total regs in address space +#define UE_SR_RX_CTRL0 0       // 9 regs (+0 to +8) +#define UE_SR_RX_DSP0 10       // 4 regs (+0 to +3) +#define UE_SR_RX_CTRL1 16      // 9 regs (+0 to +8) +#define UE_SR_RX_DSP1 26       // 4 regs (+0 to +3) +#define UE_SR_TX_CTRL 32       // 4 regs (+0 to +3) +#define UE_SR_TX_DSP 38        // 3 regs (+0 to +2) + +#define UE_SR_TIME64 42        // 6 regs (+0 to +5) +#define UE_SR_RX_FRONT 48      // 5 regs (+0 to +4) +#define UE_SR_TX_FRONT 54      // 5 regs (+0 to +4) + +#define UE_SR_REG_TEST32 60    // 1 reg +#define UE_SR_CLEAR_RX_FIFO 61 // 1 reg +#define UE_SR_CLEAR_TX_FIFO 62 // 1 reg +#define UE_SR_GLOBAL_RESET 63  // 1 reg + +#define E100_REG_SR_ADDR(n) (E100_REG_SLAVE(8) + (4*(n))) + +#define E100_REG_SR_MISC_TEST32        E100_REG_SR_ADDR(UE_SR_REG_TEST32) + +///////////////////////////////////////////////// +// Magic reset regs +//////////////////////////////////////////////// +#define E100_REG_CLEAR_RX           E100_REG_SR_ADDR(UE_SR_CLEAR_RX_FIFO) +#define E100_REG_CLEAR_TX           E100_REG_SR_ADDR(UE_SR_CLEAR_RX_FIFO) +#define E100_REG_GLOBAL_RESET       E100_REG_SR_ADDR(UE_SR_GLOBAL_RESET) + +///////////////////////////////////////////////// +// DSP RX Regs +//////////////////////////////////////////////// +#define E100_REG_DSP_RX_HELPER(which, offset) ((which == 0)? \ +    (E100_REG_SR_ADDR(UE_SR_RX_DSP0 + offset)) : \ +    (E100_REG_SR_ADDR(UE_SR_RX_DSP1 + offset))) + +#define E100_REG_DSP_RX_FREQ(which)       E100_REG_DSP_RX_HELPER(which, 0) +#define E100_REG_DSP_RX_DECIM(which)      E100_REG_DSP_RX_HELPER(which, 2) +#define E100_REG_DSP_RX_MUX(which)        E100_REG_DSP_RX_HELPER(which, 3) + +#define E100_FLAG_DSP_RX_MUX_SWAP_IQ   (1 << 0) +#define E100_FLAG_DSP_RX_MUX_REAL_MODE (1 << 1) + +/////////////////////////////////////////////////// +// RX CTRL regs +/////////////////////////////////////////////////// +#define E100_REG_RX_CTRL_HELPER(which, offset) ((which == 0)? \ +    (E100_REG_SR_ADDR(UE_SR_RX_CTRL0 + offset)) : \ +    (E100_REG_SR_ADDR(UE_SR_RX_CTRL1 + offset))) + +#define E100_REG_RX_CTRL_STREAM_CMD(which)     E100_REG_RX_CTRL_HELPER(which, 0) +#define E100_REG_RX_CTRL_TIME_SECS(which)      E100_REG_RX_CTRL_HELPER(which, 1) +#define E100_REG_RX_CTRL_TIME_TICKS(which)     E100_REG_RX_CTRL_HELPER(which, 2) +#define E100_REG_RX_CTRL_CLEAR(which)          E100_REG_RX_CTRL_HELPER(which, 3) +#define E100_REG_RX_CTRL_VRT_HDR(which)        E100_REG_RX_CTRL_HELPER(which, 4) +#define E100_REG_RX_CTRL_VRT_SID(which)        E100_REG_RX_CTRL_HELPER(which, 5) +#define E100_REG_RX_CTRL_VRT_TLR(which)        E100_REG_RX_CTRL_HELPER(which, 6) +#define E100_REG_RX_CTRL_NSAMPS_PP(which)      E100_REG_RX_CTRL_HELPER(which, 7) +#define E100_REG_RX_CTRL_NCHANNELS(which)      E100_REG_RX_CTRL_HELPER(which, 8) + +///////////////////////////////////////////////// +// RX FE +//////////////////////////////////////////////// +#define E100_REG_RX_FE_SWAP_IQ             E100_REG_SR_ADDR(UE_SR_RX_FRONT + 0) //lower bit +#define E100_REG_RX_FE_MAG_CORRECTION      E100_REG_SR_ADDR(UE_SR_RX_FRONT + 1) //18 bits +#define E100_REG_RX_FE_PHASE_CORRECTION    E100_REG_SR_ADDR(UE_SR_RX_FRONT + 2) //18 bits +#define E100_REG_RX_FE_OFFSET_I            E100_REG_SR_ADDR(UE_SR_RX_FRONT + 3) //18 bits +#define E100_REG_RX_FE_OFFSET_Q            E100_REG_SR_ADDR(UE_SR_RX_FRONT + 4) //18 bits + +///////////////////////////////////////////////// +// DSP TX Regs +//////////////////////////////////////////////// +#define E100_REG_DSP_TX_FREQ          E100_REG_SR_ADDR(UE_SR_TX_DSP + 0) +#define E100_REG_DSP_TX_SCALE_IQ      E100_REG_SR_ADDR(UE_SR_TX_DSP + 1) +#define E100_REG_DSP_TX_INTERP_RATE   E100_REG_SR_ADDR(UE_SR_TX_DSP + 2) + +/////////////////////////////////////////////////// +// TX CTRL regs +/////////////////////////////////////////////////// +#define E100_REG_TX_CTRL_NUM_CHAN       E100_REG_SR_ADDR(UE_SR_TX_CTRL + 0) +#define E100_REG_TX_CTRL_CLEAR_STATE    E100_REG_SR_ADDR(UE_SR_TX_CTRL + 1) +#define E100_REG_TX_CTRL_REPORT_SID     E100_REG_SR_ADDR(UE_SR_TX_CTRL + 2) +#define E100_REG_TX_CTRL_POLICY         E100_REG_SR_ADDR(UE_SR_TX_CTRL + 3) +#define E100_REG_TX_CTRL_CYCLES_PER_UP  E100_REG_SR_ADDR(UE_SR_TX_CTRL + 4) +#define E100_REG_TX_CTRL_PACKETS_PER_UP E100_REG_SR_ADDR(UE_SR_TX_CTRL + 5) + +#define E100_FLAG_TX_CTRL_POLICY_WAIT          (0x1 << 0) +#define E100_FLAG_TX_CTRL_POLICY_NEXT_PACKET   (0x1 << 1) +#define E100_FLAG_TX_CTRL_POLICY_NEXT_BURST    (0x1 << 2) + +///////////////////////////////////////////////// +// TX FE +//////////////////////////////////////////////// +#define E100_REG_TX_FE_DC_OFFSET_I         E100_REG_SR_ADDR(UE_SR_TX_FRONT + 0) //24 bits +#define E100_REG_TX_FE_DC_OFFSET_Q         E100_REG_SR_ADDR(UE_SR_TX_FRONT + 1) //24 bits +#define E100_REG_TX_FE_MAC_CORRECTION      E100_REG_SR_ADDR(UE_SR_TX_FRONT + 2) //18 bits +#define E100_REG_TX_FE_PHASE_CORRECTION    E100_REG_SR_ADDR(UE_SR_TX_FRONT + 3) //18 bits +#define E100_REG_TX_FE_MUX                 E100_REG_SR_ADDR(UE_SR_TX_FRONT + 4) //8 bits (std output = 0x10, reversed = 0x01) + +///////////////////////////////////////////////// +// VITA49 64 bit time (write only) +//////////////////////////////////////////////// +#define E100_REG_TIME64_SECS      E100_REG_SR_ADDR(UE_SR_TIME64 + 0) +#define E100_REG_TIME64_TICKS     E100_REG_SR_ADDR(UE_SR_TIME64 + 1) +#define E100_REG_TIME64_FLAGS     E100_REG_SR_ADDR(UE_SR_TIME64 + 2) +#define E100_REG_TIME64_IMM       E100_REG_SR_ADDR(UE_SR_TIME64 + 3) +#define E100_REG_TIME64_TPS       E100_REG_SR_ADDR(UE_SR_TIME64 + 4) +#define E100_REG_TIME64_MIMO_SYNC E100_REG_SR_ADDR(UE_SR_TIME64 + 5) + +//pps flags (see above) +#define E100_FLAG_TIME64_PPS_NEGEDGE (0 << 0) +#define E100_FLAG_TIME64_PPS_POSEDGE (1 << 0) +#define E100_FLAG_TIME64_PPS_SMA     (0 << 1) +#define E100_FLAG_TIME64_PPS_MIMO    (1 << 1) + +#define E100_FLAG_TIME64_LATCH_NOW 1 +#define E100_FLAG_TIME64_LATCH_NEXT_PPS 0 + +#endif + diff --git a/host/lib/usrp/usrp_e100/fpga_downloader.cpp b/host/lib/usrp/e100/fpga_downloader.cpp index a7449d3b1..7074c8299 100644 --- a/host/lib/usrp/usrp_e100/fpga_downloader.cpp +++ b/host/lib/usrp/e100/fpga_downloader.cpp @@ -245,7 +245,7 @@ static void send_file_to_fpga(const std::string &file_name, gpio &error, gpio &d  }//namespace usrp_e_fpga_downloader_utility -void usrp_e100_load_fpga(const std::string &bin_file){ +void e100_load_fpga(const std::string &bin_file){  	using namespace usrp_e_fpga_downloader_utility;  	gpio gpio_prog_b(PROG_B, OUT); @@ -254,9 +254,9 @@ void usrp_e100_load_fpga(const std::string &bin_file){  	UHD_MSG(status) << "Loading FPGA image: " << bin_file << "... " << std::flush; -	if(std::system("/sbin/rmmod usrp_e") != 0){ -		UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl; -	} +//	if(std::system("/sbin/rmmod usrp_e") != 0){ +//		UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not unload usrp_e module" << std::endl; +//	}  	prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); @@ -264,9 +264,9 @@ void usrp_e100_load_fpga(const std::string &bin_file){  	send_file_to_fpga(bin_file, gpio_init_b, gpio_done); -	if(std::system("/sbin/modprobe usrp_e") != 0){ -		UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl; -	} +//	if(std::system("/sbin/modprobe usrp_e") != 0){ +//		UHD_MSG(warning) << "USRP-E100 FPGA downloader: could not load usrp_e module" << std::endl; +//	}  } diff --git a/host/lib/usrp/usrp_e100/include/linux/usrp_e.h b/host/lib/usrp/e100/include/linux/usrp_e.h index 4c6a5dd89..4c6a5dd89 100644 --- a/host/lib/usrp/usrp_e100/include/linux/usrp_e.h +++ b/host/lib/usrp/e100/include/linux/usrp_e.h diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/e100/io_impl.cpp index 998a715fe..dc0d959fa 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/e100/io_impl.cpp @@ -17,8 +17,8 @@  #include "../../transport/super_recv_packet_handler.hpp"  #include "../../transport/super_send_packet_handler.hpp" -#include "usrp_e100_impl.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_impl.hpp" +#include "e100_regs.hpp"  #include <uhd/utils/msg.hpp>  #include <uhd/utils/log.hpp>  #include <uhd/usrp/dsp_utils.hpp> @@ -36,12 +36,23 @@ using namespace uhd::usrp;  using namespace uhd::transport;  /*********************************************************************** - * Constants + * Helpers   **********************************************************************/ -static const size_t rx_data_inline_sid = 1; -static const size_t tx_async_report_sid = 2; -static const int underflow_flags = async_metadata_t::EVENT_CODE_UNDERFLOW | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET; -#define fp_recv_debug false +#if 1 +#  define debug_print_buff(...) +#else +static void debug_print_buff(const std::string &what, managed_recv_buffer::sptr buff){ +    std::ostringstream ss; +    ss << boost::format( +        "This is a %s packet, %u bytes.\n" +    ) % what % buff->size(); +    for (size_t i = 0; i < 9; i++){ +        ss << boost::format("    buff[%u] = 0x%08x\n") % i % buff->cast<const boost::uint32_t *>()[i]; +    } +    ss << std::endl << std::endl; +    UHD_MSG(status) << ss.str(); +} +#endif  /***********************************************************************   * io impl details (internal to this file) @@ -50,25 +61,29 @@ static const int underflow_flags = async_metadata_t::EVENT_CODE_UNDERFLOW | asyn   * - thread loop   * - vrt packet handler states   **********************************************************************/ -struct usrp_e100_impl::io_impl{ +struct e100_impl::io_impl{      io_impl(zero_copy_if::sptr &xport):          data_xport(xport), -        recv_pirate_booty(data_xport->get_num_recv_frames()),          async_msg_fifo(100/*messages deep*/)      { -        /* NOP */ +        for (size_t i = 0; i < E100_NUM_RX_DSPS; i++){ +            typedef bounded_buffer<managed_recv_buffer::sptr> booty_type; +            recv_pirate_booty.push_back(new booty_type(data_xport->get_num_recv_frames())); +        }      }      ~io_impl(void){ -        recv_pirate_crew_raiding = false;          recv_pirate_crew.interrupt_all();          recv_pirate_crew.join_all(); +        for (size_t i = 0; i < recv_pirate_booty.size(); i++){ +            delete recv_pirate_booty[i]; +        }      } -    managed_recv_buffer::sptr get_recv_buff(double timeout){ +    managed_recv_buffer::sptr get_recv_buff(const size_t index, double timeout){          boost::this_thread::disable_interruption di; //disable because the wait can throw          managed_recv_buffer::sptr buff; -        recv_pirate_booty.pop_with_timed_wait(buff, timeout); +        recv_pirate_booty[index]->pop_with_timed_wait(buff, timeout);          return buff; //ASSUME buff == NULL when pop times-out      } @@ -83,11 +98,10 @@ struct usrp_e100_impl::io_impl{      bool continuous_streaming;      //a pirate's life is the life for me! -    void recv_pirate_loop(boost::barrier &, usrp_e100_clock_ctrl::sptr); -    bounded_buffer<managed_recv_buffer::sptr> recv_pirate_booty; +    void recv_pirate_loop(boost::barrier &, e100_clock_ctrl::sptr); +    std::vector<bounded_buffer<managed_recv_buffer::sptr> *> recv_pirate_booty;      bounded_buffer<async_metadata_t> async_msg_fifo;      boost::thread_group recv_pirate_crew; -    bool recv_pirate_crew_raiding;  };  /*********************************************************************** @@ -95,112 +109,78 @@ struct usrp_e100_impl::io_impl{   * - while raiding, loot for recv buffers   * - put booty into the alignment buffer   **********************************************************************/ -void usrp_e100_impl::io_impl::recv_pirate_loop( -    boost::barrier &spawn_barrier, usrp_e100_clock_ctrl::sptr clock_ctrl +void e100_impl::io_impl::recv_pirate_loop( +    boost::barrier &spawn_barrier, e100_clock_ctrl::sptr clock_ctrl  ){ -    recv_pirate_crew_raiding = true;      spawn_barrier.wait();      set_thread_priority_safe(); -    while(recv_pirate_crew_raiding){ +    while (not boost::this_thread::interruption_requested()){          managed_recv_buffer::sptr buff = this->data_xport->get_recv_buff(); -        if (not buff.get()) continue; //ignore timeout/error buffers - -        if (fp_recv_debug){ -            std::ostringstream ss; -            ss << "len " << buff->size() << std::endl; -            for (size_t i = 0; i < 9; i++){ -                ss << boost::format("    0x%08x") % buff->cast<const boost::uint32_t *>()[i] << std::endl; -            } -            ss << std::endl << std::endl; -            UHD_LOGV(always) << ss.str(); +        if (buff.get() == NULL) continue; //ignore timeout buffers + +        //handle an rx data packet or inline message +        const boost::uint32_t *vrt_hdr = buff->cast<const boost::uint32_t *>(); +        const size_t rx_index = uhd::wtohx(vrt_hdr[1]) - E100_DSP_SID_BASE; +        if (rx_index < E100_NUM_RX_DSPS){ +            debug_print_buff("data", buff); +            recv_pirate_booty[rx_index]->push_with_wait(buff); +            continue;          } -        try{ -            //extract the vrt header packet info -            vrt::if_packet_info_t if_packet_info; -            if_packet_info.num_packet_words32 = buff->size()/sizeof(boost::uint32_t); -            const boost::uint32_t *vrt_hdr = buff->cast<const boost::uint32_t *>(); - -            //handle an rx data packet or inline message -            if (uhd::wtohx(vrt_hdr[1]) == rx_data_inline_sid){ //ASSUME has_sid -                if (fp_recv_debug) UHD_LOGV(always) << "this is rx_data_inline_sid\n"; -                //same number of frames as the data transport -> always immediate -                recv_pirate_booty.push_with_wait(buff); -                continue; -            } - -            //unpack the vrt header and process below... -            vrt::if_hdr_unpack_le(vrt_hdr, if_packet_info); - -            //handle a tx async report message -            if (if_packet_info.sid == tx_async_report_sid and if_packet_info.packet_type != vrt::if_packet_info_t::PACKET_TYPE_DATA){ -                if (fp_recv_debug) UHD_LOGV(always) << "this is tx_async_report_sid\n"; - -                //fill in the async metadata -                async_metadata_t metadata; -                metadata.channel = 0; -                metadata.has_time_spec = if_packet_info.has_tsi and if_packet_info.has_tsf; -                metadata.time_spec = time_spec_t( -                    time_t(if_packet_info.tsi), size_t(if_packet_info.tsf), clock_ctrl->get_fpga_clock_rate() -                ); -                metadata.event_code = async_metadata_t::event_code_t(sph::get_context_code(vrt_hdr, if_packet_info)); - -                //print the famous U, and push the metadata into the message queue -                if (metadata.event_code & underflow_flags) UHD_MSG(fastpath) << "U"; -                async_msg_fifo.push_with_pop_on_full(metadata); -                continue; -            } - -            //TODO replace this below with a UHD_MSG(error) -            if (fp_recv_debug) UHD_LOGV(always) << "this is unknown packet\n"; +        //otherwise, unpack the vrt header and process below... +        vrt::if_packet_info_t if_packet_info; +        if_packet_info.num_packet_words32 = buff->size()/sizeof(boost::uint32_t); +        try{vrt::if_hdr_unpack_le(vrt_hdr, if_packet_info);} +        catch(const std::exception &e){ +            UHD_MSG(error) << "Error unpacking vrt header:\n" << e.what() << std::endl; +            continue; +        } -        }catch(const std::exception &e){ -            UHD_MSG(error) << "Error (usrp-e recv pirate loop): " << e.what() << std::endl; +        //handle a tx async report message +        if (if_packet_info.sid == E100_ASYNC_SID and if_packet_info.packet_type != vrt::if_packet_info_t::PACKET_TYPE_DATA){ +            debug_print_buff("async", buff); + +            //fill in the async metadata +            async_metadata_t metadata; +            metadata.channel = 0; +            metadata.has_time_spec = if_packet_info.has_tsi and if_packet_info.has_tsf; +            metadata.time_spec = time_spec_t( +                time_t(if_packet_info.tsi), long(if_packet_info.tsf), clock_ctrl->get_fpga_clock_rate() +            ); +            metadata.event_code = async_metadata_t::event_code_t(sph::get_context_code(vrt_hdr, if_packet_info)); +            async_msg_fifo.push_with_pop_on_full(metadata); +            if (metadata.event_code & +                ( async_metadata_t::EVENT_CODE_UNDERFLOW  +                | async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET) +            ) UHD_MSG(fastpath) << "U"; +            else if (metadata.event_code & +                ( async_metadata_t::EVENT_CODE_SEQ_ERROR +                | async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST) +            ) UHD_MSG(fastpath) << "S"; +            continue;          } + +        debug_print_buff("unknown", buff);      }  }  /***********************************************************************   * Helper Functions   **********************************************************************/ -void usrp_e100_impl::io_init(void){ -    //setup otw types -    _send_otw_type.width = 16; -    _send_otw_type.shift = 0; -    _send_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; - -    _recv_otw_type.width = 16; -    _recv_otw_type.shift = 0; -    _recv_otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; +void e100_impl::io_init(void){      //setup before the registers (transport called to calculate max spp)      _io_impl = UHD_PIMPL_MAKE(io_impl, (_data_xport));      //clear state machines -    _iface->poke32(UE_REG_CTRL_RX_CLEAR, 0); -    _iface->poke32(UE_REG_CTRL_TX_CLEAR, 0); - -    //setup rx data path -    _iface->poke32(UE_REG_CTRL_RX_NSAMPS_PER_PKT, get_max_recv_samps_per_packet()); -    _iface->poke32(UE_REG_CTRL_RX_NCHANNELS, 1); -    _iface->poke32(UE_REG_CTRL_RX_VRT_HEADER, 0 -        | (0x1 << 28) //if data with stream id -        | (0x1 << 26) //has trailer -        | (0x3 << 22) //integer time other -        | (0x1 << 20) //fractional time sample count -    ); -    _iface->poke32(UE_REG_CTRL_RX_VRT_STREAM_ID, rx_data_inline_sid); -    _iface->poke32(UE_REG_CTRL_RX_VRT_TRAILER, 0); - -    //setup the tx policy -    _iface->poke32(UE_REG_CTRL_TX_REPORT_SID, tx_async_report_sid); -    _iface->poke32(UE_REG_CTRL_TX_POLICY, UE_FLAG_CTRL_TX_POLICY_NEXT_PACKET); +    _iface->poke32(E100_REG_CLEAR_RX, 0); +    _iface->poke32(E100_REG_CLEAR_TX, 0);      //spawn a pirate, yarrr!      boost::barrier spawn_barrier(2);      _io_impl->recv_pirate_crew.create_thread(boost::bind( -        &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), +        &e100_impl::io_impl::recv_pirate_loop, _io_impl.get(),          boost::ref(spawn_barrier), _clock_ctrl      ));      spawn_barrier.wait(); @@ -208,7 +188,7 @@ void usrp_e100_impl::io_init(void){      update_xport_channel_mapping();  } -void usrp_e100_impl::update_xport_channel_mapping(void){ +void e100_impl::update_xport_channel_mapping(void){      if (_io_impl.get() == NULL) return; //not inited yet      //set all of the relevant properties on the handler @@ -216,13 +196,14 @@ void usrp_e100_impl::update_xport_channel_mapping(void){      _io_impl->recv_handler.resize(_rx_subdev_spec.size());      _io_impl->recv_handler.set_vrt_unpacker(&vrt::if_hdr_unpack_le);      _io_impl->recv_handler.set_tick_rate(_clock_ctrl->get_fpga_clock_rate()); -    _io_impl->recv_handler.set_samp_rate(_rx_ddc_proxy->get_link()[DSP_PROP_HOST_RATE].as<double>()); +    //FIXME assumes homogeneous rates across all dsp +    _io_impl->recv_handler.set_samp_rate(_rx_dsp_proxies[_rx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());      for (size_t chan = 0; chan < _io_impl->recv_handler.size(); chan++){          _io_impl->recv_handler.set_xport_chan_get_buff(chan, boost::bind( -            &usrp_e100_impl::io_impl::get_recv_buff, _io_impl.get(), _1 +            &e100_impl::io_impl::get_recv_buff, _io_impl.get(), chan, _1          ));          _io_impl->recv_handler.set_overflow_handler(chan, boost::bind( -            &usrp_e100_impl::handle_overrun, this, chan +            &e100_impl::handle_overrun, this, chan          ));      }      _io_impl->recv_handler.set_converter(_recv_otw_type); @@ -232,7 +213,8 @@ void usrp_e100_impl::update_xport_channel_mapping(void){      _io_impl->send_handler.resize(_tx_subdev_spec.size());      _io_impl->send_handler.set_vrt_packer(&vrt::if_hdr_pack_le);      _io_impl->send_handler.set_tick_rate(_clock_ctrl->get_fpga_clock_rate()); -    _io_impl->send_handler.set_samp_rate(_tx_duc_proxy->get_link()[DSP_PROP_HOST_RATE].as<double>()); +    //FIXME assumes homogeneous rates across all dsp +    _io_impl->send_handler.set_samp_rate(_tx_dsp_proxies[_tx_dsp_proxies.keys().at(0)]->get_link()[DSP_PROP_HOST_RATE].as<double>());      for (size_t chan = 0; chan < _io_impl->send_handler.size(); chan++){          _io_impl->send_handler.set_xport_chan_get_buff(chan, boost::bind(              &uhd::transport::zero_copy_if::get_send_buff, _io_impl->data_xport, _1 @@ -242,23 +224,23 @@ void usrp_e100_impl::update_xport_channel_mapping(void){      _io_impl->send_handler.set_max_samples_per_packet(get_max_send_samps_per_packet());  } -void usrp_e100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd){ +void e100_impl::issue_ddc_stream_cmd(const stream_cmd_t &stream_cmd, const size_t index){      _io_impl->continuous_streaming = (stream_cmd.stream_mode == stream_cmd_t::STREAM_MODE_START_CONTINUOUS); -    _iface->poke32(UE_REG_CTRL_RX_STREAM_CMD, dsp_type1::calc_stream_cmd_word(stream_cmd)); -    _iface->poke32(UE_REG_CTRL_RX_TIME_SECS,  boost::uint32_t(stream_cmd.time_spec.get_full_secs())); -    _iface->poke32(UE_REG_CTRL_RX_TIME_TICKS, stream_cmd.time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate())); +    _iface->poke32(E100_REG_RX_CTRL_STREAM_CMD(index), dsp_type1::calc_stream_cmd_word(stream_cmd)); +    _iface->poke32(E100_REG_RX_CTRL_TIME_SECS(index),  boost::uint32_t(stream_cmd.time_spec.get_full_secs())); +    _iface->poke32(E100_REG_RX_CTRL_TIME_TICKS(index), stream_cmd.time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate()));  } -void usrp_e100_impl::handle_overrun(size_t /*chan*/){ +void e100_impl::handle_overrun(const size_t index){      if (_io_impl->continuous_streaming){ -        this->issue_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS); +        this->issue_ddc_stream_cmd(stream_cmd_t::STREAM_MODE_START_CONTINUOUS, index);      }  }  /***********************************************************************   * Data Send   **********************************************************************/ -size_t usrp_e100_impl::get_max_send_samps_per_packet(void) const{ +size_t e100_impl::get_max_send_samps_per_packet(void) const{      static const size_t hdr_size = 0          + vrt::max_if_hdr_words32*sizeof(boost::uint32_t)          - sizeof(vrt::if_packet_info_t().cid) //no class id ever used @@ -267,7 +249,7 @@ size_t usrp_e100_impl::get_max_send_samps_per_packet(void) const{      return bpp/_send_otw_type.get_sample_size();  } -size_t usrp_e100_impl::send( +size_t e100_impl::send(      const send_buffs_type &buffs, size_t nsamps_per_buff,      const tx_metadata_t &metadata, const io_type_t &io_type,      send_mode_t send_mode, double timeout @@ -282,7 +264,7 @@ size_t usrp_e100_impl::send(  /***********************************************************************   * Data Recv   **********************************************************************/ -size_t usrp_e100_impl::get_max_recv_samps_per_packet(void) const{ +size_t e100_impl::get_max_recv_samps_per_packet(void) const{      static const size_t hdr_size = 0          + vrt::max_if_hdr_words32*sizeof(boost::uint32_t)          + sizeof(vrt::if_packet_info_t().tlr) //forced to have trailer @@ -292,7 +274,7 @@ size_t usrp_e100_impl::get_max_recv_samps_per_packet(void) const{      return bpp/_recv_otw_type.get_sample_size();  } -size_t usrp_e100_impl::recv( +size_t e100_impl::recv(      const recv_buffs_type &buffs, size_t nsamps_per_buff,      rx_metadata_t &metadata, const io_type_t &io_type,      recv_mode_t recv_mode, double timeout @@ -307,7 +289,7 @@ size_t usrp_e100_impl::recv(  /***********************************************************************   * Async Recv   **********************************************************************/ -bool usrp_e100_impl::recv_async_msg( +bool e100_impl::recv_async_msg(      async_metadata_t &async_metadata, double timeout  ){      boost::this_thread::disable_interruption di; //disable because the wait can throw diff --git a/host/lib/usrp/usrp_e100/mboard_impl.cpp b/host/lib/usrp/e100/mboard_impl.cpp index f4b8d79f6..e7a46fe8e 100644 --- a/host/lib/usrp/usrp_e100/mboard_impl.cpp +++ b/host/lib/usrp/e100/mboard_impl.cpp @@ -15,8 +15,8 @@  // along with this program.  If not, see <http://www.gnu.org/licenses/>.  // -#include "usrp_e100_impl.hpp" -#include "usrp_e100_regs.hpp" +#include "e100_impl.hpp" +#include "e100_regs.hpp"  #include <uhd/utils/msg.hpp>  #include <uhd/exception.hpp>  #include <uhd/usrp/dsp_utils.hpp> @@ -30,10 +30,10 @@ using namespace uhd::usrp;  /***********************************************************************   * Mboard Initialization   **********************************************************************/ -void usrp_e100_impl::mboard_init(void){ +void e100_impl::mboard_init(void){      _mboard_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::mboard_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::mboard_set, this, _1, _2) +        boost::bind(&e100_impl::mboard_get, this, _1, _2), +        boost::bind(&e100_impl::mboard_set, this, _1, _2)      );      //init the clock config @@ -41,18 +41,18 @@ void usrp_e100_impl::mboard_init(void){      update_clock_config();  } -void usrp_e100_impl::update_clock_config(void){ +void e100_impl::update_clock_config(void){      boost::uint32_t pps_flags = 0;      //translate pps polarity enums      switch(_clock_config.pps_polarity){ -    case clock_config_t::PPS_POS: pps_flags |= UE_FLAG_TIME64_PPS_POSEDGE; break; -    case clock_config_t::PPS_NEG: pps_flags |= UE_FLAG_TIME64_PPS_NEGEDGE; break; +    case clock_config_t::PPS_POS: pps_flags |= E100_FLAG_TIME64_PPS_POSEDGE; break; +    case clock_config_t::PPS_NEG: pps_flags |= E100_FLAG_TIME64_PPS_NEGEDGE; break;      default: throw uhd::value_error("unhandled clock configuration pps polarity");      }      //set the pps flags -    _iface->poke32(UE_REG_TIME64_FLAGS, pps_flags); +    _iface->poke32(E100_REG_TIME64_FLAGS, pps_flags);      //clock source ref 10mhz      switch(_clock_config.ref_source){ @@ -66,13 +66,14 @@ void usrp_e100_impl::update_clock_config(void){  /***********************************************************************   * Mboard Get   **********************************************************************/ -void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){ +void e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_); +    static const std::string dboard_name = "A";      //handle the get request conditioned on the key      switch(key.as<mboard_prop_t>()){      case MBOARD_PROP_NAME: -        val = std::string("usrp-e mboard"); +        val = std::string(_iface->get_cname() + " mboard");          return;      case MBOARD_PROP_OTHERS: @@ -80,39 +81,37 @@ void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_RX_DBOARD: -        UHD_ASSERT_THROW(key.name == ""); +        UHD_ASSERT_THROW(key.name == dboard_name);          val = _rx_dboard_proxy->get_link();          return;      case MBOARD_PROP_RX_DBOARD_NAMES: -        val = prop_names_t(1, ""); //vector of size 1 with empty string +        val = prop_names_t(1, dboard_name);          return;      case MBOARD_PROP_TX_DBOARD: -        UHD_ASSERT_THROW(key.name == ""); +        UHD_ASSERT_THROW(key.name == dboard_name);          val = _tx_dboard_proxy->get_link();          return;      case MBOARD_PROP_TX_DBOARD_NAMES: -        val = prop_names_t(1, ""); //vector of size 1 with empty string +        val = prop_names_t(1, dboard_name);          return;      case MBOARD_PROP_RX_DSP: -        UHD_ASSERT_THROW(key.name == ""); -        val = _rx_ddc_proxy->get_link(); +        val = _rx_dsp_proxies[key.name]->get_link();          return;      case MBOARD_PROP_RX_DSP_NAMES: -        val = prop_names_t(1, ""); +        val = _rx_dsp_proxies.keys();          return;      case MBOARD_PROP_TX_DSP: -        UHD_ASSERT_THROW(key.name == ""); -        val = _tx_duc_proxy->get_link(); +        val = _tx_dsp_proxies[key.name]->get_link();          return;      case MBOARD_PROP_TX_DSP_NAMES: -        val = prop_names_t(1, ""); +        val = _tx_dsp_proxies.keys();          return;      case MBOARD_PROP_CLOCK_CONFIG: @@ -132,17 +131,17 @@ void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_TIME_NOW: while(true){ -        uint32_t secs = _iface->peek32(UE_REG_RB_TIME_NOW_SECS); -        uint32_t ticks = _iface->peek32(UE_REG_RB_TIME_NOW_TICKS); -        if (secs != _iface->peek32(UE_REG_RB_TIME_NOW_SECS)) continue; +        uint32_t secs = _iface->peek32(E100_REG_RB_TIME_NOW_SECS); +        uint32_t ticks = _iface->peek32(E100_REG_RB_TIME_NOW_TICKS); +        if (secs != _iface->peek32(E100_REG_RB_TIME_NOW_SECS)) continue;          val = time_spec_t(secs, ticks, _clock_ctrl->get_fpga_clock_rate());          return;      }      case MBOARD_PROP_TIME_PPS: while(true){ -        uint32_t secs = _iface->peek32(UE_REG_RB_TIME_PPS_SECS); -        uint32_t ticks = _iface->peek32(UE_REG_RB_TIME_PPS_TICKS); -        if (secs != _iface->peek32(UE_REG_RB_TIME_PPS_SECS)) continue; +        uint32_t secs = _iface->peek32(E100_REG_RB_TIME_PPS_SECS); +        uint32_t ticks = _iface->peek32(E100_REG_RB_TIME_PPS_TICKS); +        if (secs != _iface->peek32(E100_REG_RB_TIME_PPS_SECS)) continue;          val = time_spec_t(secs, ticks, _clock_ctrl->get_fpga_clock_rate());          return;      } @@ -158,38 +157,73 @@ void usrp_e100_impl::mboard_get(const wax::obj &key_, wax::obj &val){  /***********************************************************************   * Mboard Set   **********************************************************************/ -void usrp_e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){ +void e100_impl::mboard_set(const wax::obj &key, const wax::obj &val){      //handle the get request conditioned on the key      switch(key.as<mboard_prop_t>()){      case MBOARD_PROP_TIME_NOW:      case MBOARD_PROP_TIME_PPS:{              time_spec_t time_spec = val.as<time_spec_t>(); -            _iface->poke32(UE_REG_TIME64_TICKS, time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate())); +            _iface->poke32(E100_REG_TIME64_TICKS, time_spec.get_tick_count(_clock_ctrl->get_fpga_clock_rate()));              boost::uint32_t imm_flags = (key.as<mboard_prop_t>() == MBOARD_PROP_TIME_NOW)? 1 : 0; -            _iface->poke32(UE_REG_TIME64_IMM, imm_flags); -            _iface->poke32(UE_REG_TIME64_SECS, time_spec.get_full_secs()); +            _iface->poke32(E100_REG_TIME64_IMM, imm_flags); +            _iface->poke32(E100_REG_TIME64_SECS, time_spec.get_full_secs());          }          return; -    case MBOARD_PROP_RX_SUBDEV_SPEC: +    case MBOARD_PROP_RX_SUBDEV_SPEC:{          _rx_subdev_spec = val.as<subdev_spec_t>();          verify_rx_subdev_spec(_rx_subdev_spec, _mboard_proxy->get_link());          //sanity check -        UHD_ASSERT_THROW(_rx_subdev_spec.size() == 1); -        //set the mux -        _iface->poke32(UE_REG_DSP_RX_MUX, dsp_type1::calc_rx_mux_word( -            _dboard_manager->get_rx_subdev(_rx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>() -        )); -        return; +        UHD_ASSERT_THROW(_rx_subdev_spec.size() <= E100_NUM_RX_DSPS); + +        //determine frontend swap IQ from the first channel +        bool fe_swap_iq = false; +        switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(0).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +        case SUBDEV_CONN_COMPLEX_QI: +        case SUBDEV_CONN_REAL_Q: +            fe_swap_iq = true; +            break; +        default: fe_swap_iq = false; +        } +        _iface->poke32(E100_REG_RX_FE_SWAP_IQ, fe_swap_iq? 1 : 0); + +        //set the dsp mux for each channel +        for (size_t i = 0; i < _rx_subdev_spec.size(); i++){ +            bool iq_swap = false, real_mode = false; +            switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(i).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +            case SUBDEV_CONN_COMPLEX_IQ: +                iq_swap = fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_COMPLEX_QI: +                iq_swap = not fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_REAL_I: +                iq_swap = fe_swap_iq; +                real_mode = true; +                break; +            case SUBDEV_CONN_REAL_Q: +                iq_swap = not fe_swap_iq; +                real_mode = true; +                break; +            } +            _iface->poke32(E100_REG_DSP_RX_MUX(i), +                (iq_swap?   E100_FLAG_DSP_RX_MUX_SWAP_IQ   : 0) | +                (real_mode? E100_FLAG_DSP_RX_MUX_REAL_MODE : 0) +            ); +        } +        this->update_xport_channel_mapping(); +    }return;      case MBOARD_PROP_TX_SUBDEV_SPEC:          _tx_subdev_spec = val.as<subdev_spec_t>();          verify_tx_subdev_spec(_tx_subdev_spec, _mboard_proxy->get_link());          //sanity check -        UHD_ASSERT_THROW(_tx_subdev_spec.size() == 1); +        UHD_ASSERT_THROW(_tx_subdev_spec.size() <= E100_NUM_TX_DSPS);          //set the mux -        _iface->poke32(UE_REG_DSP_TX_MUX, dsp_type1::calc_tx_mux_word( +        _iface->poke32(E100_REG_TX_FE_MUX, dsp_type1::calc_tx_mux_word(              _dboard_manager->get_tx_subdev(_tx_subdev_spec.front().sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()          ));          return; diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 03cdeae42..d9cde3f13 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -173,12 +173,6 @@ void usrp2_mboard_impl::ddc_set(const wax::obj &key_, const wax::obj &val, size_              //set the decimation              _iface->poke32(U2_REG_DSP_RX_DECIM(which_dsp), dsp_type1::calc_cic_filter_word(_dsp_impl->ddc_decim[which_dsp])); - -            //set the scaling -            static const boost::int16_t default_rx_scale_iq = 1024; -            _iface->poke32(U2_REG_DSP_RX_SCALE_IQ(which_dsp), -                dsp_type1::calc_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq) -            );          }          _device.update_xport_channel_mapping(); //rate changed -> update          return; diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index e5c60f27c..21abc6aed 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -30,7 +30,7 @@ extern "C" {  #endif  //fpga and firmware compatibility numbers -#define USRP2_FPGA_COMPAT_NUM 6 +#define USRP2_FPGA_COMPAT_NUM 7  #define USRP2_FW_COMPAT_NUM 10  //used to differentiate control packets over data port diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 6bf412a3e..197296cf0 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -289,10 +289,10 @@ void usrp2_mboard_impl::set_time_spec(const time_spec_t &time_spec, bool now){  /***********************************************************************   * MBoard Get Properties   **********************************************************************/ -static const std::string dboard_name = "0"; -  void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){      named_prop_t key = named_prop_t::extract(key_); +    static const std::string dboard_name = "A"; +      //handle the get request conditioned on the key      switch(key.as<mboard_prop_t>()){      case MBOARD_PROP_NAME: @@ -304,7 +304,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_RX_DBOARD: -        UHD_ASSERT_THROW(key.name == dboard_name); +        UHD_ASSERT_THROW(key.name == dboard_name or key.name == "0"); //allow for old name to work          val = _rx_dboard_proxy->get_link();          return; @@ -313,7 +313,7 @@ void usrp2_mboard_impl::get(const wax::obj &key_, wax::obj &val){          return;      case MBOARD_PROP_TX_DBOARD: -        UHD_ASSERT_THROW(key.name == dboard_name); +        UHD_ASSERT_THROW(key.name == dboard_name or key.name == "0"); //allow for old name to work          val = _tx_dboard_proxy->get_link();          return; @@ -429,19 +429,51 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){          set_time_spec(val.as<time_spec_t>(), false);          return; -    case MBOARD_PROP_RX_SUBDEV_SPEC: +    case MBOARD_PROP_RX_SUBDEV_SPEC:{          _rx_subdev_spec = val.as<subdev_spec_t>();          verify_rx_subdev_spec(_rx_subdev_spec, this->get_link());          //sanity check          UHD_ASSERT_THROW(_rx_subdev_spec.size() <= NUM_RX_DSPS); -        //set the mux + +        //determine frontend swap IQ from the first channel +        bool fe_swap_iq = false; +        switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(0).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +        case SUBDEV_CONN_COMPLEX_QI: +        case SUBDEV_CONN_REAL_Q: +            fe_swap_iq = true; +            break; +        default: fe_swap_iq = false; +        } +        _iface->poke32(U2_REG_RX_FE_SWAP_IQ, fe_swap_iq? 1 : 0); + +        //set the dsp mux for each channel          for (size_t i = 0; i < _rx_subdev_spec.size(); i++){ -            _iface->poke32(U2_REG_DSP_RX_MUX(i), dsp_type1::calc_rx_mux_word( -                _dboard_manager->get_rx_subdev(_rx_subdev_spec[i].sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>() -            )); +            bool iq_swap = false, real_mode = false; +            switch(_dboard_manager->get_rx_subdev(_rx_subdev_spec.at(i).sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){ +            case SUBDEV_CONN_COMPLEX_IQ: +                iq_swap = fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_COMPLEX_QI: +                iq_swap = not fe_swap_iq; +                real_mode = false; +                break; +            case SUBDEV_CONN_REAL_I: +                iq_swap = fe_swap_iq; +                real_mode = true; +                break; +            case SUBDEV_CONN_REAL_Q: +                iq_swap = not fe_swap_iq; +                real_mode = true; +                break; +            } +            _iface->poke32(U2_REG_DSP_RX_MUX(i), +                (iq_swap?   U2_FLAG_DSP_RX_MUX_SWAP_IQ   : 0) | +                (real_mode? U2_FLAG_DSP_RX_MUX_REAL_MODE : 0) +            );          }          _device.update_xport_channel_mapping(); -        return; +    }return;      case MBOARD_PROP_TX_SUBDEV_SPEC:          _tx_subdev_spec = val.as<subdev_spec_t>(); @@ -450,7 +482,7 @@ void usrp2_mboard_impl::set(const wax::obj &key, const wax::obj &val){          UHD_ASSERT_THROW(_tx_subdev_spec.size() <= NUM_TX_DSPS);          //set the mux          for (size_t i = 0; i < _rx_subdev_spec.size(); i++){ -            _iface->poke32(U2_REG_DSP_TX_MUX, dsp_type1::calc_tx_mux_word( +            _iface->poke32(U2_REG_TX_FE_MUX, dsp_type1::calc_tx_mux_word(                  _dboard_manager->get_tx_subdev(_tx_subdev_spec[i].sd_name)[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()              ));          } diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index dbb78275b..19c1b45f1 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -120,12 +120,29 @@  #define U2_REG_TIME64_TICKS_RB_PPS READBACK_BASE + 4*15  ///////////////////////////////////////////////// +// RX FE +//////////////////////////////////////////////// +#define U2_REG_RX_FE_SWAP_IQ             U2_REG_SR_ADDR(SR_RX_FRONT + 0) //lower bit +#define U2_REG_RX_FE_MAG_CORRECTION      U2_REG_SR_ADDR(SR_RX_FRONT + 1) //18 bits +#define U2_REG_RX_FE_PHASE_CORRECTION    U2_REG_SR_ADDR(SR_RX_FRONT + 2) //18 bits +#define U2_REG_RX_FE_OFFSET_I            U2_REG_SR_ADDR(SR_RX_FRONT + 3) //18 bits +#define U2_REG_RX_FE_OFFSET_Q            U2_REG_SR_ADDR(SR_RX_FRONT + 4) //18 bits + +///////////////////////////////////////////////// +// TX FE +//////////////////////////////////////////////// +#define U2_REG_TX_FE_DC_OFFSET_I         U2_REG_SR_ADDR(SR_TX_FRONT + 0) //24 bits +#define U2_REG_TX_FE_DC_OFFSET_Q         U2_REG_SR_ADDR(SR_TX_FRONT + 1) //24 bits +#define U2_REG_TX_FE_MAC_CORRECTION      U2_REG_SR_ADDR(SR_TX_FRONT + 2) //18 bits +#define U2_REG_TX_FE_PHASE_CORRECTION    U2_REG_SR_ADDR(SR_TX_FRONT + 3) //18 bits +#define U2_REG_TX_FE_MUX                 U2_REG_SR_ADDR(SR_TX_FRONT + 4) //8 bits (std output = 0x10, reversed = 0x01) + +/////////////////////////////////////////////////  // DSP TX Regs  ////////////////////////////////////////////////  #define U2_REG_DSP_TX_FREQ U2_REG_SR_ADDR(SR_TX_DSP + 0)  #define U2_REG_DSP_TX_SCALE_IQ U2_REG_SR_ADDR(SR_TX_DSP + 1)  #define U2_REG_DSP_TX_INTERP_RATE U2_REG_SR_ADDR(SR_TX_DSP + 2) -#define U2_REG_DSP_TX_MUX U2_REG_SR_ADDR(SR_TX_DSP + 4)  /////////////////////////////////////////////////  // DSP RX Regs @@ -135,9 +152,11 @@      (U2_REG_SR_ADDR(SR_RX_DSP1 + offset)))  #define U2_REG_DSP_RX_FREQ(which)       U2_REG_DSP_RX_HELPER(which, 0) -#define U2_REG_DSP_RX_SCALE_IQ(which)   U2_REG_DSP_RX_HELPER(which, 1)  #define U2_REG_DSP_RX_DECIM(which)      U2_REG_DSP_RX_HELPER(which, 2) -#define U2_REG_DSP_RX_MUX(which)        U2_REG_DSP_RX_HELPER(which, 5) +#define U2_REG_DSP_RX_MUX(which)        U2_REG_DSP_RX_HELPER(which, 3) + +#define U2_FLAG_DSP_RX_MUX_SWAP_IQ   (1 << 0) +#define U2_FLAG_DSP_RX_MUX_REAL_MODE (1 << 1)  ////////////////////////////////////////////////  // GPIO diff --git a/host/lib/usrp/usrp_e100/dsp_impl.cpp b/host/lib/usrp/usrp_e100/dsp_impl.cpp deleted file mode 100644 index 93034b5dc..000000000 --- a/host/lib/usrp/usrp_e100/dsp_impl.cpp +++ /dev/null @@ -1,190 +0,0 @@ -// -// Copyright 2010-2011 Ettus Research 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 <http://www.gnu.org/licenses/>. -// - -#include "usrp_e100_impl.hpp" -#include "usrp_e100_regs.hpp" -#include <uhd/usrp/dsp_utils.hpp> -#include <uhd/usrp/dsp_props.hpp> -#include <boost/math/special_functions/round.hpp> -#include <boost/bind.hpp> - -#define rint boost::math::iround - -using namespace uhd; -using namespace uhd::usrp; - -/*********************************************************************** - * RX DDC Initialization - **********************************************************************/ -void usrp_e100_impl::rx_ddc_init(void){ -    _rx_ddc_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::rx_ddc_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::rx_ddc_set, this, _1, _2) -    ); - -    //initial config and update -    rx_ddc_set(DSP_PROP_FREQ_SHIFT, double(0)); -    rx_ddc_set(DSP_PROP_HOST_RATE, double(16e6)); -} - -/*********************************************************************** - * RX DDC Get - **********************************************************************/ -void usrp_e100_impl::rx_ddc_get(const wax::obj &key_, wax::obj &val){ -    named_prop_t key = named_prop_t::extract(key_); - -    switch(key.as<dsp_prop_t>()){ -    case DSP_PROP_NAME: -        val = std::string("usrp-e ddc0"); -        return; - -    case DSP_PROP_OTHERS: -        val = prop_names_t(); //empty -        return; - -    case DSP_PROP_FREQ_SHIFT: -        val = _ddc_freq; -        return; - -    case DSP_PROP_CODEC_RATE: -        val = _clock_ctrl->get_fpga_clock_rate(); -        return; - -    case DSP_PROP_HOST_RATE: -        val = _clock_ctrl->get_fpga_clock_rate()/_ddc_decim; -        return; - -    default: UHD_THROW_PROP_GET_ERROR(); -    } -} - -/*********************************************************************** - * RX DDC Set - **********************************************************************/ -void usrp_e100_impl::rx_ddc_set(const wax::obj &key_, const wax::obj &val){ -    named_prop_t key = named_prop_t::extract(key_); - -    switch(key.as<dsp_prop_t>()){ - -    case DSP_PROP_STREAM_CMD: -        issue_stream_cmd(val.as<stream_cmd_t>()); -        return; - -    case DSP_PROP_FREQ_SHIFT:{ -            double new_freq = val.as<double>(); -            _iface->poke32(UE_REG_DSP_RX_FREQ, -                dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate()) -            ); -            _ddc_freq = new_freq; //shadow -        } -        return; - -    case DSP_PROP_HOST_RATE:{ -            //set the decimation -            _ddc_decim = rint(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); -            _iface->poke32(UE_REG_DSP_RX_DECIM_RATE, dsp_type1::calc_cic_filter_word(_ddc_decim)); - -            //set the scaling -            static const boost::int16_t default_rx_scale_iq = 1024; -            _iface->poke32(UE_REG_DSP_RX_SCALE_IQ, -                dsp_type1::calc_iq_scale_word(default_rx_scale_iq, default_rx_scale_iq) -            ); -        } -        this->update_xport_channel_mapping(); //rate changed -> update -        return; - -    default: UHD_THROW_PROP_SET_ERROR(); -    } -} - -/*********************************************************************** - * TX DUC Initialization - **********************************************************************/ -void usrp_e100_impl::tx_duc_init(void){ -    _tx_duc_proxy = wax_obj_proxy::make( -        boost::bind(&usrp_e100_impl::tx_duc_get, this, _1, _2), -        boost::bind(&usrp_e100_impl::tx_duc_set, this, _1, _2) -    ); - -    //initial config and update -    tx_duc_set(DSP_PROP_FREQ_SHIFT, double(0)); -    tx_duc_set(DSP_PROP_HOST_RATE, double(16e6)); -} - -/*********************************************************************** - * TX DUC Get - **********************************************************************/ -void usrp_e100_impl::tx_duc_get(const wax::obj &key_, wax::obj &val){ -    named_prop_t key = named_prop_t::extract(key_); - -    switch(key.as<dsp_prop_t>()){ -    case DSP_PROP_NAME: -        val = std::string("usrp-e duc0"); -        return; - -    case DSP_PROP_OTHERS: -        val = prop_names_t(); //empty -        return; - -    case DSP_PROP_FREQ_SHIFT: -        val = _duc_freq; -        return; - -    case DSP_PROP_CODEC_RATE: -        val = _clock_ctrl->get_fpga_clock_rate(); -        return; - -    case DSP_PROP_HOST_RATE: -        val = _clock_ctrl->get_fpga_clock_rate()/_duc_interp; -        return; - -    default: UHD_THROW_PROP_GET_ERROR(); -    } -} - -/*********************************************************************** - * TX DUC Set - **********************************************************************/ -void usrp_e100_impl::tx_duc_set(const wax::obj &key_, const wax::obj &val){ -    named_prop_t key = named_prop_t::extract(key_); - -    switch(key.as<dsp_prop_t>()){ - -    case DSP_PROP_FREQ_SHIFT:{ -            double new_freq = val.as<double>(); -            _iface->poke32(UE_REG_DSP_TX_FREQ, -                dsp_type1::calc_cordic_word_and_update(new_freq, _clock_ctrl->get_fpga_clock_rate()) -            ); -            _duc_freq = new_freq; //shadow -        } -        return; - -    case DSP_PROP_HOST_RATE:{ -            _duc_interp = rint(_clock_ctrl->get_fpga_clock_rate()/val.as<double>()); - -            //set the interpolation -            _iface->poke32(UE_REG_DSP_TX_INTERP_RATE, dsp_type1::calc_cic_filter_word(_duc_interp)); - -            //set the scaling -            _iface->poke32(UE_REG_DSP_TX_SCALE_IQ, dsp_type1::calc_iq_scale_word(_duc_interp)); -        } -        this->update_xport_channel_mapping(); //rate changed -> update -        return; - -    default: UHD_THROW_PROP_SET_ERROR(); -    } -} diff --git a/host/lib/usrp/usrp_e100/usrp_e100_regs.hpp b/host/lib/usrp/usrp_e100/usrp_e100_regs.hpp deleted file mode 100644 index 1bcae64c7..000000000 --- a/host/lib/usrp/usrp_e100/usrp_e100_regs.hpp +++ /dev/null @@ -1,221 +0,0 @@ - - -//////////////////////////////////////////////////////////////// -// -//         Memory map for embedded wishbone bus -// -//////////////////////////////////////////////////////////////// - -// All addresses are byte addresses.  All accesses are word (16-bit) accesses. -//  This means that address bit 0 is usually 0. -//  There are 11 bits of address for the control. - -#ifndef INCLUDED_USRP_E100_REGS_HPP -#define INCLUDED_USRP_E100_REGS_HPP - -///////////////////////////////////////////////////// -// Slave pointers - -#define UE_REG_SLAVE(n) ((n)<<7) - -///////////////////////////////////////////////////// -// Slave 0 -- Misc Regs - -#define UE_REG_MISC_BASE UE_REG_SLAVE(0) - -#define UE_REG_MISC_LED        UE_REG_MISC_BASE + 0 -#define UE_REG_MISC_SW         UE_REG_MISC_BASE + 2 -#define UE_REG_MISC_CGEN_CTRL  UE_REG_MISC_BASE + 4 -#define UE_REG_MISC_CGEN_ST    UE_REG_MISC_BASE + 6 -#define UE_REG_MISC_TEST       UE_REG_MISC_BASE + 8 -#define UE_REG_MISC_RX_LEN     UE_REG_MISC_BASE + 10 -#define UE_REG_MISC_TX_LEN     UE_REG_MISC_BASE + 12 -#define UE_REG_MISC_XFER_RATE  UE_REG_MISC_BASE + 14 -#define UE_REG_MISC_COMPAT     UE_REG_MISC_BASE + 16 - -///////////////////////////////////////////////////// -// Slave 1 -- UART -//   CLKDIV is 16 bits, others are only 8 - -#define UE_REG_UART_BASE UE_REG_SLAVE(1) - -#define UE_REG_UART_CLKDIV  UE_REG_UART_BASE + 0 -#define UE_REG_UART_TXLEVEL UE_REG_UART_BASE + 2 -#define UE_REG_UART_RXLEVEL UE_REG_UART_BASE + 4 -#define UE_REG_UART_TXCHAR  UE_REG_UART_BASE + 6 -#define UE_REG_UART_RXCHAR  UE_REG_UART_BASE + 8 - -///////////////////////////////////////////////////// -// Slave 2 -- SPI Core -//   This should be accessed through the IOCTL -//   Users should not touch directly - -#define UE_REG_SPI_BASE UE_REG_SLAVE(2) - -//spi slave constants -#define UE_SPI_SS_AD9522    (1 << 3) -#define UE_SPI_SS_AD9862    (1 << 2) -#define UE_SPI_SS_TX_DB     (1 << 1) -#define UE_SPI_SS_RX_DB     (1 << 0) - -//////////////////////////////////////////////// -// Slave 3 -- I2C Core -//   This should be accessed through the IOCTL -//   Users should not touch directly - -#define UE_REG_I2C_BASE UE_REG_SLAVE(3) - - -//////////////////////////////////////////////// -// Slave 4 -- GPIO - -#define UE_REG_GPIO_BASE UE_REG_SLAVE(4) - -#define UE_REG_GPIO_RX_IO      UE_REG_GPIO_BASE + 0 -#define UE_REG_GPIO_TX_IO      UE_REG_GPIO_BASE + 2 -#define UE_REG_GPIO_RX_DDR     UE_REG_GPIO_BASE + 4 -#define UE_REG_GPIO_TX_DDR     UE_REG_GPIO_BASE + 6 -#define UE_REG_GPIO_RX_SEL     UE_REG_GPIO_BASE + 8 -#define UE_REG_GPIO_TX_SEL     UE_REG_GPIO_BASE + 10 -#define UE_REG_GPIO_RX_DBG     UE_REG_GPIO_BASE + 12 -#define UE_REG_GPIO_TX_DBG     UE_REG_GPIO_BASE + 14 - -//possible bit values for sel when dbg is 0: -#define GPIO_SEL_SW    0 // if pin is an output, set by software in the io reg -#define GPIO_SEL_ATR   1 // if pin is an output, set by ATR logic - -//possible bit values for sel when dbg is 1: -#define GPIO_SEL_DEBUG_0   0 // if pin is an output, debug lines from FPGA fabric -#define GPIO_SEL_DEBUG_1   1 // if pin is an output, debug lines from FPGA fabric - -/////////////////////////////////////////////////// -// Slave 6 -- ATR Controller -//   16 regs - -#define UE_REG_ATR_BASE  UE_REG_SLAVE(6) - -#define	UE_REG_ATR_IDLE_RXSIDE  UE_REG_ATR_BASE + 0 -#define	UE_REG_ATR_IDLE_TXSIDE  UE_REG_ATR_BASE + 2 -#define UE_REG_ATR_INTX_RXSIDE  UE_REG_ATR_BASE + 4 -#define UE_REG_ATR_INTX_TXSIDE  UE_REG_ATR_BASE + 6 -#define	UE_REG_ATR_INRX_RXSIDE  UE_REG_ATR_BASE + 8 -#define	UE_REG_ATR_INRX_TXSIDE  UE_REG_ATR_BASE + 10 -#define	UE_REG_ATR_FULL_RXSIDE  UE_REG_ATR_BASE + 12 -#define	UE_REG_ATR_FULL_TXSIDE  UE_REG_ATR_BASE + 14 - -/////////////////////////////////////////////////// -// Slave 7 -- Readback Mux 32 - -#define UE_REG_RB_MUX_32_BASE  UE_REG_SLAVE(7) - -#define UE_REG_RB_TIME_NOW_SECS   UE_REG_RB_MUX_32_BASE + 0 -#define UE_REG_RB_TIME_NOW_TICKS  UE_REG_RB_MUX_32_BASE + 4 -#define UE_REG_RB_TIME_PPS_SECS   UE_REG_RB_MUX_32_BASE + 8 -#define UE_REG_RB_TIME_PPS_TICKS  UE_REG_RB_MUX_32_BASE + 12 -#define UE_REG_RB_MISC_TEST32     UE_REG_RB_MUX_32_BASE + 16 - -//////////////////////////////////////////////////// -// Slave 8 -- Settings Bus -// -// Output-only, no readback, 64 registers total -//  Each register must be written 64 bits at a time -//  First the address xxx_xx00 and then xxx_xx10 - -#define UE_REG_SETTINGS_BASE_ADDR(n) (UE_REG_SLAVE(8) + (4*(n))) - -#define UE_REG_SR_MISC_TEST32        UE_REG_SETTINGS_BASE_ADDR(52) - -///////////////////////////////////////////////// -// Magic reset regs -//////////////////////////////////////////////// -#define UE_REG_CLEAR_ADDR(n)      (UE_REG_SETTINGS_BASE_ADDR(48) + (4*(n))) -#define UE_REG_CLEAR_RX           UE_REG_CLEAR_ADDR(0) -#define UE_REG_CLEAR_TX           UE_REG_CLEAR_ADDR(1) - -///////////////////////////////////////////////// -// DSP RX Regs -//////////////////////////////////////////////// -#define UE_REG_DSP_RX_ADDR(n)      (UE_REG_SETTINGS_BASE_ADDR(16) + (4*(n))) -#define UE_REG_DSP_RX_FREQ         UE_REG_DSP_RX_ADDR(0) -#define UE_REG_DSP_RX_SCALE_IQ     UE_REG_DSP_RX_ADDR(1) // {scale_i,scale_q} -#define UE_REG_DSP_RX_DECIM_RATE   UE_REG_DSP_RX_ADDR(2) // hb and decim rate -#define UE_REG_DSP_RX_DCOFFSET_I   UE_REG_DSP_RX_ADDR(3) // Bit 31 high sets fixed offset mode, using lower 14 bits, // otherwise it is automatic -#define UE_REG_DSP_RX_DCOFFSET_Q   UE_REG_DSP_RX_ADDR(4) // Bit 31 high sets fixed offset mode, using lower 14 bits -#define UE_REG_DSP_RX_MUX          UE_REG_DSP_RX_ADDR(5) - -/////////////////////////////////////////////////// -// VITA RX CTRL regs -/////////////////////////////////////////////////// -#define UE_REG_CTRL_RX_ADDR(n)           (UE_REG_SETTINGS_BASE_ADDR(0) + (4*(n))) -// The following 3 are logically a single command register. -// They are clocked into the underlying fifo when time_ticks is written. -#define UE_REG_CTRL_RX_STREAM_CMD        UE_REG_CTRL_RX_ADDR(0) // {now, chain, num_samples(30) -#define UE_REG_CTRL_RX_TIME_SECS         UE_REG_CTRL_RX_ADDR(1) -#define UE_REG_CTRL_RX_TIME_TICKS        UE_REG_CTRL_RX_ADDR(2) -#define UE_REG_CTRL_RX_CLEAR             UE_REG_CTRL_RX_ADDR(3) // write anything to clear -#define UE_REG_CTRL_RX_VRT_HEADER        UE_REG_CTRL_RX_ADDR(4) // word 0 of packet.  FPGA fills in packet counter -#define UE_REG_CTRL_RX_VRT_STREAM_ID     UE_REG_CTRL_RX_ADDR(5) // word 1 of packet. -#define UE_REG_CTRL_RX_VRT_TRAILER       UE_REG_CTRL_RX_ADDR(6) -#define UE_REG_CTRL_RX_NSAMPS_PER_PKT    UE_REG_CTRL_RX_ADDR(7) -#define UE_REG_CTRL_RX_NCHANNELS         UE_REG_CTRL_RX_ADDR(8) // 1 in basic case, up to 4 for vector sources - -///////////////////////////////////////////////// -// DSP TX Regs -//////////////////////////////////////////////// -#define UE_REG_DSP_TX_ADDR(n)      (UE_REG_SETTINGS_BASE_ADDR(32) + (4*(n))) -#define UE_REG_DSP_TX_FREQ         UE_REG_DSP_TX_ADDR(0) -#define UE_REG_DSP_TX_SCALE_IQ     UE_REG_DSP_TX_ADDR(1) // {scale_i,scale_q} -#define UE_REG_DSP_TX_INTERP_RATE  UE_REG_DSP_TX_ADDR(2) -#define UE_REG_DSP_TX_UNUSED       UE_REG_DSP_TX_ADDR(3) -#define UE_REG_DSP_TX_MUX          UE_REG_DSP_TX_ADDR(4) - -///////////////////////////////////////////////// -// VITA TX CTRL regs -//////////////////////////////////////////////// -#define UE_REG_CTRL_TX_ADDR(n)           (UE_REG_SETTINGS_BASE_ADDR(24) + (4*(n))) -#define UE_REG_CTRL_TX_NCHANNELS         UE_REG_CTRL_TX_ADDR(0) -#define UE_REG_CTRL_TX_CLEAR             UE_REG_CTRL_TX_ADDR(1) -#define UE_REG_CTRL_TX_REPORT_SID        UE_REG_CTRL_TX_ADDR(2) -#define UE_REG_CTRL_TX_POLICY            UE_REG_CTRL_TX_ADDR(3) - -#define UE_FLAG_CTRL_TX_POLICY_WAIT          (0x1 << 0) -#define UE_FLAG_CTRL_TX_POLICY_NEXT_PACKET   (0x1 << 1) -#define UE_FLAG_CTRL_TX_POLICY_NEXT_BURST    (0x1 << 2) - -///////////////////////////////////////////////// -// VITA49 64 bit time (write only) -//////////////////////////////////////////////// -  /*! -   * \brief Time 64 flags -   * -   * <pre> -   * -   *    3                   2                   1 -   *  1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 -   * +-----------------------------------------------------------+-+-+ -   * |                                                           |S|P| -   * +-----------------------------------------------------------+-+-+ -   * -   * P - PPS edge selection (0=negedge, 1=posedge, default=0) -   * S - Source (0=sma, 1=mimo, 0=default) -   * -   * </pre> -   */ -#define UE_REG_TIME64_ADDR(n)     (UE_REG_SETTINGS_BASE_ADDR(40) + (4*(n))) -#define UE_REG_TIME64_SECS        UE_REG_TIME64_ADDR(0)  // value to set absolute secs to on next PPS -#define UE_REG_TIME64_TICKS       UE_REG_TIME64_ADDR(1)  // value to set absolute ticks to on next PPS -#define UE_REG_TIME64_FLAGS       UE_REG_TIME64_ADDR(2)  // flags - see chart above -#define UE_REG_TIME64_IMM         UE_REG_TIME64_ADDR(3)  // set immediate (0=latch on next pps, 1=latch immediate, default=0) -#define UE_REG_TIME64_TPS         UE_REG_TIME64_ADDR(4)  // clock ticks per second (counter rollover) - -//pps flags (see above) -#define UE_FLAG_TIME64_PPS_NEGEDGE (0 << 0) -#define UE_FLAG_TIME64_PPS_POSEDGE (1 << 0) -#define UE_FLAG_TIME64_PPS_SMA     (0 << 1) -#define UE_FLAG_TIME64_PPS_MIMO    (1 << 1) - -#define UE_FLAG_TIME64_LATCH_NOW 1 -#define UE_FLAG_TIME64_LATCH_NEXT_PPS 0 - -#endif - diff --git a/host/usrp_e_utils/CMakeLists.txt b/host/usrp_e_utils/CMakeLists.txt index e7d6ae4b8..ee3d9da65 100644 --- a/host/usrp_e_utils/CMakeLists.txt +++ b/host/usrp_e_utils/CMakeLists.txt @@ -23,12 +23,10 @@ LIBUHD_REGISTER_COMPONENT("USRP-E Utils" ENABLE_USRP_E_UTILS OFF "LINUX" OFF)  IF(ENABLE_USRP_E_UTILS)      ENABLE_LANGUAGE(C)      INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -    INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/usrp_e100) -    INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/usrp_e100/include) -    INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/lib/ic_reg_maps) +    INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/e100) +    INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/usrp/e100/include)      SET(usrp_e_utils_sources -        usrp-e-utility.cpp          usrp-e-loopback.c          usrp-e-timed.c          usrp-e-wb-test.cpp diff --git a/host/usrp_e_utils/clkgen_config.hpp b/host/usrp_e_utils/clkgen_config.hpp deleted file mode 100644 index f39f8bb19..000000000 --- a/host/usrp_e_utils/clkgen_config.hpp +++ /dev/null @@ -1,305 +0,0 @@ -// -// Copyright 2011 Ettus Research 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 <http://www.gnu.org/licenses/>. -// - -#ifndef USRP_E_UTILS_CLKGEN_CONFIG_HPP -#define USRP_E_UTILS_CLKGEN_CONFIG_HPP - -#include <iostream> -#include <sstream> -#include <fstream> -#include <string> -#include <cstdlib> - -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/ioctl.h> - -#include <linux/spi/spidev.h> - -namespace usrp_e_clkgen_config_utility{ - -// Programming data for clock gen chip -static const unsigned int config_data[] = { -	0x000024, -	0x023201, -	0x000081, -	0x000400, -	0x00104c, -	0x001101, -	0x001200, -	0x001300, -	0x001414, -	0x001500, -	0x001604, -	0x001704, -	0x001807, -	0x001900, -	//0x001a00,//for debug -	0x001a32, -	0x001b12, -	0x001c44, -	0x001d00, -	0x001e00, -	0x00f062, -	0x00f162, -	0x00f262, -	0x00f362, -	0x00f462, -	0x00f562, -	0x00f662, -	0x00f762, -	0x00f862, -	0x00f962, -	0x00fa62, -	0x00fb62, -	0x00fc00, -	0x00fd00, -	0x019021, -	0x019100, -	0x019200, -	0x019321, -	0x019400, -	0x019500, -	0x019611, -	0x019700, -	0x019800, -	0x019900, -	0x019a00, -	0x019b00, -	0x01e003, -	0x01e102, -	0x023000, -	0x023201, -	0x0b0201, -	0x0b0300, -	0x001fff, -	0x0a0000, -	0x0a0100, -	0x0a0200, -	0x0a0302, -	0x0a0400, -	0x0a0504, -	0x0a060e, -	0x0a0700, -	0x0a0810, -	0x0a090e, -	0x0a0a00, -	0x0a0bf0, -	0x0a0c0b, -	0x0a0d01, -	0x0a0e90, -	0x0a0f01, -	0x0a1001, -	0x0a11e0, -	0x0a1201, -	0x0a1302, -	0x0a1430, -	0x0a1580, -	0x0a16ff, -	0x023201, -	0x0b0301, -	0x023201, -}; - - -const unsigned int CLKGEN_SELECT = 145; - - -enum gpio_direction {IN, OUT}; - -class gpio { -	public: - -	gpio(unsigned int gpio_num, gpio_direction pin_direction, bool close_action); -	~gpio(); - -	bool get_value(); -	void set_value(bool state); - -	private: - -	unsigned int gpio_num; - -	std::stringstream base_path; -	std::fstream value_file; -	std::fstream direction_file; -	bool close_action; // True set to input and release, false do nothing -}; - -class spidev { -	public: - -	spidev(std::string dev_name); -	~spidev(); - -	void send(char *wbuf, char *rbuf, unsigned int nbytes); - -	private: - -	int fd; - -}; - -gpio::gpio(unsigned int _gpio_num, gpio_direction pin_direction, bool close_action) -:close_action(close_action) -{ -	std::fstream export_file; - -	gpio_num = _gpio_num; - -	export_file.open("/sys/class/gpio/export", std::ios::out); -	if (!export_file.is_open())  ///\todo Poor error handling -		std::cout << "Failed to open gpio export file." << std::endl; - -	export_file << gpio_num << std::endl; - -	base_path << "/sys/class/gpio/gpio" << gpio_num << std::flush; - -	std::string direction_file_name; - -	direction_file_name = base_path.str() + "/direction"; - -	direction_file.open(direction_file_name.c_str());  -	if (!direction_file.is_open()) -		std::cout << "Failed to open direction file." << std::endl; -	if (pin_direction == OUT) -		direction_file << "out" << std::endl; -	else -		direction_file << "in" << std::endl; - -	std::string value_file_name; - -	value_file_name = base_path.str() + "/value"; - -	value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out); -	if (!value_file.is_open()) -		std::cout << "Failed to open value file." << std::endl; -} - -bool gpio::get_value() -{ - -	std::string val; - -	std::getline(value_file, val); -	value_file.seekg(0); - -	if (val == "0") -		return false; -	else if (val == "1") -		return true; -	else -		std::cout << "Data read from value file|" << val << "|" << std::endl; - -	return false; -} - -void gpio::set_value(bool state) -{ - -	if (state) -		value_file << "1" << std::endl; -	else -		value_file << "0" << std::endl; -} - -gpio::~gpio() -{ -	if (close_action) { -		std::fstream unexport_file; - -		direction_file << "in" << std::endl; - -		unexport_file.open("/sys/class/gpio/unexport", std::ios::out); -		if (!unexport_file.is_open())  ///\todo Poor error handling -			std::cout << "Failed to open gpio export file." << std::endl; - -		unexport_file << gpio_num << std::endl; -		 -	 } - -} - -spidev::spidev(std::string fname) -{ -	int ret; -	int mode = 0; -	int speed = 12000; -	int bits = 24; - -	fd = open(fname.c_str(), O_RDWR); - -	ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); -	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); -	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); -} -	 - -spidev::~spidev() -{ -	close(fd); -} - -void spidev::send(char *buf, char *rbuf, unsigned int nbytes) -{ -	int ret; - -	struct spi_ioc_transfer tr; -	tr.tx_buf = (unsigned long) buf; -	tr.rx_buf = (unsigned long) rbuf; -	tr.len = nbytes; -	tr.delay_usecs = 0; -	tr.speed_hz = 12000; -	tr.bits_per_word = 24; - -	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); - -} - -static void send_config_to_clkgen(gpio &chip_select, const unsigned int data[], unsigned int data_size) -{ -	spidev spi("/dev/spidev1.0"); -	unsigned int rbuf; - -	for (unsigned int i = 0; i < data_size; i++) { - -		//std::cout << "sending " << std::hex << data[i] << std::endl; -		chip_select.set_value(0); -		spi.send((char *)&data[i], (char *)&rbuf, 4); -		chip_select.set_value(1); -		unsigned int addr = (data[i] >> 8) & 0xfff; -		if (addr == 0x232 || addr == 0x000){ -			std::cout << "." << std::flush; -			sleep(1); -		} -	}; -	std::cout << std::endl; -} - -}//namespace usrp_e_clkgen_config_utility - -//int main(int argc, char *argv[]) -static void clock_genconfig_main(void) -{ -	using namespace usrp_e_clkgen_config_utility; -	gpio clkgen_select(CLKGEN_SELECT, OUT, true); - -	send_config_to_clkgen(clkgen_select, config_data, sizeof(config_data)/sizeof(config_data[0])); -} - -#endif /*USRP_E_UTILS_CLKGEN_CONFIG_HPP*/ diff --git a/host/usrp_e_utils/usrp-e-debug-pins.c b/host/usrp_e_utils/usrp-e-debug-pins.c index 94f898b67..570ae63d8 100644 --- a/host/usrp_e_utils/usrp-e-debug-pins.c +++ b/host/usrp_e_utils/usrp-e-debug-pins.c @@ -7,7 +7,7 @@  #include <sys/ioctl.h>  #include <linux/usrp_e.h> -#include "usrp_e100_regs.hpp" +#include "e100_regs.hpp"  // Usage: usrp_e_gpio <string> @@ -54,24 +54,24 @@ int main(int argc, char *argv[])  	if (strcmp(argv[1], "0") == 0) {  		printf("Selected 0 based on %s\n", argv[1]); -		write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF); -		write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF); -		write_reg(UE_REG_GPIO_TX_SEL, 0x0); -		write_reg(UE_REG_GPIO_RX_SEL, 0x0); -		write_reg(UE_REG_GPIO_TX_DBG, 0xFFFF); -		write_reg(UE_REG_GPIO_RX_DBG, 0xFFFF); +		write_reg(E100_REG_GPIO_TX_DDR, 0xFFFF); +		write_reg(E100_REG_GPIO_RX_DDR, 0xFFFF); +		write_reg(E100_REG_GPIO_TX_SEL, 0x0); +		write_reg(E100_REG_GPIO_RX_SEL, 0x0); +		write_reg(E100_REG_GPIO_TX_DBG, 0xFFFF); +		write_reg(E100_REG_GPIO_RX_DBG, 0xFFFF);  	} else if (strcmp(argv[1], "1") == 0) {  		printf("Selected 1 based on %s\n", argv[1]); -		write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF); -		write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF); -		write_reg(UE_REG_GPIO_TX_SEL, 0xFFFF); -		write_reg(UE_REG_GPIO_RX_SEL, 0xFFFF); -		write_reg(UE_REG_GPIO_TX_DBG, 0xFFFF); -		write_reg(UE_REG_GPIO_RX_DBG, 0xFFFF); +		write_reg(E100_REG_GPIO_TX_DDR, 0xFFFF); +		write_reg(E100_REG_GPIO_RX_DDR, 0xFFFF); +		write_reg(E100_REG_GPIO_TX_SEL, 0xFFFF); +		write_reg(E100_REG_GPIO_RX_SEL, 0xFFFF); +		write_reg(E100_REG_GPIO_TX_DBG, 0xFFFF); +		write_reg(E100_REG_GPIO_RX_DBG, 0xFFFF);  	} else {  		printf("Selected off based on %s\n", argv[1]); -		write_reg(UE_REG_GPIO_TX_DDR, 0x0); -		write_reg(UE_REG_GPIO_RX_DDR, 0x0); +		write_reg(E100_REG_GPIO_TX_DDR, 0x0); +		write_reg(E100_REG_GPIO_RX_DDR, 0x0);  	}  	return 0; diff --git a/host/usrp_e_utils/usrp-e-gpio.c b/host/usrp_e_utils/usrp-e-gpio.c index 7e4bc4e13..4b788e945 100644 --- a/host/usrp_e_utils/usrp-e-gpio.c +++ b/host/usrp_e_utils/usrp-e-gpio.c @@ -7,7 +7,7 @@  #include <sys/ioctl.h>  #include "linux/usrp_e.h" -#include "usrp_e100_regs.hpp" +#include "e100_regs.hpp"  // Usage: usrp_e_gpio <string> @@ -46,38 +46,38 @@ int main(int argc, char *argv[])  	fp = open("/dev/usrp_e0", O_RDWR);  	printf("fp = %d\n", fp); -	write_reg(UE_REG_GPIO_TX_DDR, 0x0); -	write_reg(UE_REG_GPIO_RX_DDR, 0xFFFF); +	write_reg(E100_REG_GPIO_TX_DDR, 0x0); +	write_reg(E100_REG_GPIO_RX_DDR, 0xFFFF);  	for (i=0; i < 16; i++) { -		write_reg(UE_REG_GPIO_RX_IO, 1 << i); +		write_reg(E100_REG_GPIO_RX_IO, 1 << i);  		sleep(1);  		if (test) { -			data_in = read_reg(UE_REG_GPIO_TX_IO); +			data_in = read_reg(E100_REG_GPIO_TX_IO);  			if (data_in != (1 << i))  				printf("Read failed, wrote: %X read: %X\n", \  					1 << i, data_in);  		}  	} -	write_reg(UE_REG_GPIO_RX_DDR, 0x0); -	write_reg(UE_REG_GPIO_TX_DDR, 0xFFFF); +	write_reg(E100_REG_GPIO_RX_DDR, 0x0); +	write_reg(E100_REG_GPIO_TX_DDR, 0xFFFF);  	sleep(1);  	for (i=0; i < 16; i++) { -		write_reg(UE_REG_GPIO_TX_IO, 1 << i); +		write_reg(E100_REG_GPIO_TX_IO, 1 << i);  		sleep(1);  		if (test) { -			data_in = read_reg(UE_REG_GPIO_RX_IO); +			data_in = read_reg(E100_REG_GPIO_RX_IO);  			if (data_in != (1 << i))  				printf("Read failed, wrote: %X read: %X\n", \  					1 << i, data_in);  		}  	} -	write_reg(UE_REG_GPIO_RX_DDR, 0x0); -	write_reg(UE_REG_GPIO_TX_DDR, 0x0); +	write_reg(E100_REG_GPIO_RX_DDR, 0x0); +	write_reg(E100_REG_GPIO_TX_DDR, 0x0);  	return 0;  } diff --git a/host/usrp_e_utils/usrp-e-utility.cpp b/host/usrp_e_utils/usrp-e-utility.cpp deleted file mode 100644 index 47a2c0900..000000000 --- a/host/usrp_e_utils/usrp-e-utility.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// -// Copyright 2011 Ettus Research 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 <http://www.gnu.org/licenses/>. -// - -#include <uhd/utils/safe_main.hpp> -#include <boost/program_options.hpp> -#include <boost/format.hpp> -#include <stdexcept> -#include <iostream> - -#include "fpga_downloader.cpp" -#include "clkgen_config.hpp" - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - -    //variables to be set by po -    std::string fpga_path; - -    //setup the program options -    po::options_description desc("Allowed options"); -    desc.add_options() -        ("help", "help message") -        ("fpga", po::value<std::string>(&fpga_path), "loads the specified FPGA file") -        ("reclk",                                    "runs the clock recovery") -    ; -    po::variables_map vm; -    po::store(po::parse_command_line(argc, argv, desc), vm); -    po::notify(vm); - -    //print the help message -    if (vm.count("help")){ -        std::cout << boost::format("UHD USRP-E Utility %s") % desc << std::endl; -        return ~0; -    } - -    bool loaded_fpga_image = false; -    if (vm.count("fpga") != 0){ -        std::cout << "USRP-E Utility loading the FPGA..." << std::endl << std::endl; -        usrp_e100_load_fpga(fpga_path); -        loaded_fpga_image = true; -        sleep(1); -    } - -    if (vm.count("reclk") != 0){ -        std::cout << "USRP-E Utility running the clock recovery..." << std::flush; -        //if an image was not loaded or specified, we load pass-through -        if (fpga_path.empty()) throw std::runtime_error( -            "Please specify the path to the pass-though FPGA image for your device.\n" -            "  usrp-e-utility --reclk --fpga=/usr/share/uhd/images/usrp_e1xx_pt_fpga.bin" -        ); -        clock_genconfig_main(); -    } - -    std::cout << "Done!" << std::endl; - -    return 0; -} diff --git a/host/usrp_e_utils/usrp-e-wb-test.cpp b/host/usrp_e_utils/usrp-e-wb-test.cpp index 3d6a8d101..efd9312c1 100644 --- a/host/usrp_e_utils/usrp-e-wb-test.cpp +++ b/host/usrp_e_utils/usrp-e-wb-test.cpp @@ -24,7 +24,7 @@  #include <fcntl.h> //open, close  #include <linux/usrp_e.h> -#include "usrp_e100_regs.hpp" +#include "e100_regs.hpp"  static const size_t num_test_iters = 10000000; @@ -91,18 +91,18 @@ int main(int, char *[]){          int random_secs = ::random();          //set a bunch of registers -        poke16(UE_REG_MISC_TEST, random_test16); -        poke32(UE_REG_SR_MISC_TEST32, random_test32); -        poke32(UE_REG_TIME64_TICKS, 0); -        poke32(UE_REG_TIME64_IMM, 1); //immediate -        poke32(UE_REG_TIME64_SECS, random_secs); +        poke16(E100_REG_MISC_TEST, random_test16); +        poke32(E100_REG_SR_MISC_TEST32, random_test32); +        poke32(E100_REG_TIME64_TICKS, 0); +        poke32(E100_REG_TIME64_IMM, 1); //immediate +        poke32(E100_REG_TIME64_SECS, random_secs);          //read a bunch of registers          if ( -            (peek16(UE_REG_MISC_TEST) == random_test16) and -            (peek32(UE_REG_RB_MISC_TEST32) == random_test32) and -            (peek32(UE_REG_RB_TIME_NOW_SECS) == random_secs) and -//            (peek32(UE_REG_RB_TIME_NOW_TICKS) < 1000000) and +            (peek16(E100_REG_MISC_TEST) == random_test16) and +            (peek32(E100_REG_RB_MISC_TEST32) == random_test32) and +            (peek32(E100_REG_RB_TIME_NOW_SECS) == random_secs) and +//            (peek32(E100_REG_RB_TIME_NOW_TICKS) < 1000000) and          true) num_pass++;          else  num_fail++;      }  | 
