diff options
| author | Josh Blum <josh@joshknows.com> | 2010-04-12 16:52:18 -0700 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2010-04-12 16:52:18 -0700 | 
| commit | 389a72ef592d9826eac67ab001da5734909dbfcd (patch) | |
| tree | f0652d894debe00d1e5b688dd6c8b2ab0c2c0427 | |
| parent | 237279419d14a2a19545dd7311b244108edf9dc5 (diff) | |
| download | uhd-389a72ef592d9826eac67ab001da5734909dbfcd.tar.gz uhd-389a72ef592d9826eac67ab001da5734909dbfcd.tar.bz2 uhd-389a72ef592d9826eac67ab001da5734909dbfcd.zip | |
merged unit type and gpio bank for dboard interface into one type, expanded dboard clock config api
| -rw-r--r-- | host/include/uhd/usrp/dboard_interface.hpp | 79 | ||||
| -rw-r--r-- | host/lib/usrp/dboard/db_rfx.cpp | 2 | ||||
| -rw-r--r-- | host/lib/usrp/dboard_manager.cpp | 8 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/dboard_interface.cpp | 93 | ||||
| -rw-r--r-- | host/lib/usrp/usrp2/io_impl.cpp | 1 | 
5 files changed, 98 insertions, 85 deletions
| diff --git a/host/include/uhd/usrp/dboard_interface.hpp b/host/include/uhd/usrp/dboard_interface.hpp index 43fd1f143..2fa05c09d 100644 --- a/host/include/uhd/usrp/dboard_interface.hpp +++ b/host/include/uhd/usrp/dboard_interface.hpp @@ -56,7 +56,7 @@ struct UHD_API spi_config_t{   * The daughter board dboard_interface to be subclassed.   * A dboard instance dboard_interfaces with the mboard though this api.    * This dboard_interface provides i2c, spi, gpio, atr, aux dac/adc access. - * Each mboard should have a specially tailored dboard dboard_interface. + * Each mboard should have a specially tailored interface for its dboard.   */  class UHD_API dboard_interface{  public: @@ -64,15 +64,9 @@ public:      typedef std::vector<boost::uint8_t> byte_vector_t;      //tells the host which unit to use -    enum unit_type_t{ -        UNIT_TYPE_RX = 'r', -        UNIT_TYPE_TX = 't' -    }; - -    //tell the host which gpio bank -    enum gpio_bank_t{ -        GPIO_BANK_RX = 'r', -        GPIO_BANK_TX = 't' +    enum unit_t{ +        UNIT_RX = 'r', +        UNIT_TX = 't'      };      //possible atr registers @@ -85,54 +79,58 @@ public:      /*!       * Write to an aux dac. +     *       * \param unit which unit rx or tx       * \param which_dac the dac index 0, 1, 2, 3...       * \param value the value to write       */ -    virtual void write_aux_dac(unit_type_t unit, int which_dac, int value) = 0; +    virtual void write_aux_dac(unit_t unit, int which_dac, int value) = 0;      /*!       * Read from an aux adc. +     *       * \param unit which unit rx or tx       * \param which_adc the adc index 0, 1, 2, 3...       * \return the value that was read       */ -    virtual int read_aux_adc(unit_type_t unit, int which_adc) = 0; +    virtual int read_aux_adc(unit_t unit, int which_adc) = 0;      /*!       * Set a daughterboard ATR register.       * -     * \param bank   GPIO_TX_BANK or GPIO_RX_BANK -     * \param reg    which ATR register to set -     * \param value  16-bits, 0=FPGA output low, 1=FPGA output high +     * \param unit which unit rx or tx +     * \param reg which ATR register to set +     * \param value 16-bits, 0=FPGA output low, 1=FPGA output high       */ -    virtual void set_atr_reg(gpio_bank_t bank, atr_reg_t reg, boost::uint16_t value) = 0; +    virtual void set_atr_reg(unit_t unit, atr_reg_t reg, boost::uint16_t value) = 0;      /*!       * Set daughterboard GPIO data direction register.       * -     * \param bank      GPIO_TX_BANK or GPIO_RX_BANK -     * \param value     16-bits, 0=FPGA input, 1=FPGA output +     * \param unit which unit rx or tx +     * \param value 16-bits, 0=FPGA input, 1=FPGA output       */ -    virtual void set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value) = 0; +    virtual void set_gpio_ddr(unit_t unit, boost::uint16_t value) = 0;      /*! -     * Read daughterboard GPIO pin values +     * Read daughterboard GPIO pin values.       * -     * \param bank GPIO_TX_BANK or GPIO_RX_BANK -     * \return the value of the gpio bank +     * \param unit which unit rx or tx +     * \return the value of the gpio unit       */ -    virtual boost::uint16_t read_gpio(gpio_bank_t bank) = 0; +    virtual boost::uint16_t read_gpio(unit_t unit) = 0;      /*! -     * \brief Write to I2C peripheral +     * Write to an I2C peripheral. +     *       * \param i2c_addr I2C bus address (7-bits)       * \param buf the data to write       */      virtual void write_i2c(int i2c_addr, const byte_vector_t &buf) = 0;      /*! -     * \brief Read from I2C peripheral +     * Read from an I2C peripheral. +     *       * \param i2c_addr I2C bus address (7-bits)       * \param num_bytes number of bytes to read       * \return the data read if successful, else a zero length string. @@ -140,7 +138,7 @@ public:      virtual byte_vector_t read_i2c(int i2c_addr, size_t num_bytes) = 0;      /*! -     * \brief Write data to SPI bus peripheral. +     * Write data to SPI bus peripheral.       *       * \param unit which unit, rx or tx       * \param config configuration settings @@ -148,15 +146,14 @@ public:       * \param num_bits the number of bits in data       */      virtual void write_spi( -        unit_type_t unit, +        unit_t unit,          const spi_config_t &config,          boost::uint32_t data,          size_t num_bits      ) = 0;      /*! -     * \brief Read and write data to SPI bus peripheral. -     * The data read back will be the same length as the input buffer. +     * Read and write data to SPI bus peripheral.       *       * \param unit which unit, rx or tx       * \param config configuration settings @@ -165,23 +162,35 @@ public:       * \return the data that was read       */      virtual boost::uint32_t read_write_spi( -        unit_type_t unit, +        unit_t unit,          const spi_config_t &config,          boost::uint32_t data,          size_t num_bits      ) = 0;      /*! -     * \brief Get the rate of the rx dboard clock. +     * Get the rate of a dboard clock. +     * +     * \param unit which unit rx or tx       * \return the clock rate in Hz       */ -    virtual double get_rx_clock_rate(void) = 0; +    virtual double get_clock_rate(unit_t unit) = 0;      /*! -     * \brief Get the rate of the tx dboard clock. -     * \return the clock rate in Hz +     * Enable or disable a dboard clock. +     * +     * \param unit which unit rx or tx +     * \param enb true for enabled +     */ +    virtual void set_clock_enabled(unit_t unit, bool enb) = 0; + +    /*! +     * Get the enabled status of a dboard block. +     * +     * \param unit which unit rx or tx +     * \return true for enabled       */ -    virtual double get_tx_clock_rate(void) = 0; +    virtual bool get_clock_enabled(unit_t unit) = 0;  };  }} //namespace diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 4bf931660..60f6b1a60 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -137,7 +137,7 @@ void rfx_xcvr::reload_adf4360_regs(void){      ;      BOOST_FOREACH(adf4360_regs_t::addr_t addr, addrs){          this->get_interface()->write_spi( -            dboard_interface::UNIT_TYPE_TX, +            dboard_interface::UNIT_TX,              spi_config_t::EDGE_RISE,              _adf4360_regs.get_reg(addr), 24          ); diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 4cf2e5820..f8ff38c39 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -276,9 +276,9 @@ wax::obj dboard_manager_impl::get_tx_subdev(const std::string &subdev_name){  void dboard_manager_impl::set_nice_gpio_pins(void){      //std::cout << "Set nice GPIO pins" << std::endl; -    _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_RX, 0x0000); //all inputs -    _interface->set_atr_reg(dboard_interface::GPIO_BANK_RX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low +    _interface->set_gpio_ddr(dboard_interface::UNIT_RX, 0x0000); //all inputs +    _interface->set_atr_reg(dboard_interface::UNIT_RX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low -    _interface->set_gpio_ddr(dboard_interface::GPIO_BANK_TX, 0x0000); //all inputs -    _interface->set_atr_reg(dboard_interface::GPIO_BANK_TX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low +    _interface->set_gpio_ddr(dboard_interface::UNIT_TX, 0x0000); //all inputs +    _interface->set_atr_reg(dboard_interface::UNIT_TX, dboard_interface::ATR_REG_IDLE, 0x0000); //all low  } diff --git a/host/lib/usrp/usrp2/dboard_interface.cpp b/host/lib/usrp/usrp2/dboard_interface.cpp index d10cfa37e..db8679b9b 100644 --- a/host/lib/usrp/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/usrp2/dboard_interface.cpp @@ -29,28 +29,29 @@ public:      usrp2_dboard_interface(usrp2_impl *impl);      ~usrp2_dboard_interface(void); -    void write_aux_dac(unit_type_t, int, int); -    int read_aux_adc(unit_type_t, int); +    void write_aux_dac(unit_t, int, int); +    int read_aux_adc(unit_t, int); -    void set_atr_reg(gpio_bank_t, atr_reg_t, boost::uint16_t); -    void set_gpio_ddr(gpio_bank_t, boost::uint16_t); -    boost::uint16_t read_gpio(gpio_bank_t); +    void set_atr_reg(unit_t, atr_reg_t, boost::uint16_t); +    void set_gpio_ddr(unit_t, boost::uint16_t); +    boost::uint16_t read_gpio(unit_t);      void write_i2c(int, const byte_vector_t &);      byte_vector_t read_i2c(int, size_t); -    double get_rx_clock_rate(void); -    double get_tx_clock_rate(void); +    double get_clock_rate(unit_t); +    void set_clock_enabled(unit_t, bool); +    bool get_clock_enabled(unit_t);      void write_spi( -        unit_type_t unit, +        unit_t unit,          const spi_config_t &config,          boost::uint32_t data,          size_t num_bits      );      boost::uint32_t read_write_spi( -        unit_type_t unit, +        unit_t unit,          const spi_config_t &config,          boost::uint32_t data,          size_t num_bits @@ -89,57 +90,61 @@ usrp2_dboard_interface::~usrp2_dboard_interface(void){  }  /*********************************************************************** - * Clock Rates + * Clocks   **********************************************************************/ -double usrp2_dboard_interface::get_rx_clock_rate(void){ +double usrp2_dboard_interface::get_clock_rate(unit_t){      return _impl->get_master_clock_freq();  } -double usrp2_dboard_interface::get_tx_clock_rate(void){ -    return _impl->get_master_clock_freq(); +void usrp2_dboard_interface::set_clock_enabled(unit_t, bool){ +    //TODO +} + +bool usrp2_dboard_interface::get_clock_enabled(unit_t){ +    return false; //TODO  }  /***********************************************************************   * GPIO   **********************************************************************/ -static int bank_to_shift(dboard_interface::gpio_bank_t bank){ -    switch(bank){ -    case dboard_interface::GPIO_BANK_RX: return 0; -    case dboard_interface::GPIO_BANK_TX: return 16; +static int unit_to_shift(dboard_interface::unit_t unit){ +    switch(unit){ +    case dboard_interface::UNIT_RX: return 0; +    case dboard_interface::UNIT_TX: return 16;      } -    throw std::runtime_error("unknown gpio bank type"); +    throw std::runtime_error("unknown unit type");  } -void usrp2_dboard_interface::set_gpio_ddr(gpio_bank_t bank, boost::uint16_t value){ +void usrp2_dboard_interface::set_gpio_ddr(unit_t unit, boost::uint16_t value){      _ddr_shadow = \ -        (_ddr_shadow & ~(0xffff << bank_to_shift(bank))) | -        (boost::uint32_t(value) << bank_to_shift(bank)); +        (_ddr_shadow & ~(0xffff << unit_to_shift(unit))) | +        (boost::uint32_t(value) << unit_to_shift(unit));      _impl->poke32(FR_GPIO_DDR, _ddr_shadow);  } -boost::uint16_t usrp2_dboard_interface::read_gpio(gpio_bank_t bank){ -    return boost::uint16_t(_impl->peek32(FR_GPIO_IO) >> bank_to_shift(bank)); +boost::uint16_t usrp2_dboard_interface::read_gpio(unit_t unit){ +    return boost::uint16_t(_impl->peek32(FR_GPIO_IO) >> unit_to_shift(unit));  } -void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t atr, boost::uint16_t value){ -    //define mapping of bank to atr regs to register address +void usrp2_dboard_interface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ +    //define mapping of unit to atr regs to register address      static const uhd::dict< -        gpio_bank_t, uhd::dict<atr_reg_t, boost::uint32_t> -    > bank_to_atr_to_addr = boost::assign::map_list_of -        (GPIO_BANK_RX, boost::assign::map_list_of +        unit_t, uhd::dict<atr_reg_t, boost::uint32_t> +    > unit_to_atr_to_addr = boost::assign::map_list_of +        (UNIT_RX, boost::assign::map_list_of              (ATR_REG_IDLE,        FR_ATR_IDLE_RXSIDE)              (ATR_REG_TX_ONLY,     FR_ATR_INTX_RXSIDE)              (ATR_REG_RX_ONLY,     FR_ATR_INRX_RXSIDE)              (ATR_REG_FULL_DUPLEX, FR_ATR_FULL_RXSIDE)          ) -        (GPIO_BANK_TX, boost::assign::map_list_of +        (UNIT_TX, boost::assign::map_list_of              (ATR_REG_IDLE,        FR_ATR_IDLE_TXSIDE)              (ATR_REG_TX_ONLY,     FR_ATR_INTX_TXSIDE)              (ATR_REG_RX_ONLY,     FR_ATR_INRX_TXSIDE)              (ATR_REG_FULL_DUPLEX, FR_ATR_FULL_TXSIDE)          )      ; -    _impl->poke16(bank_to_atr_to_addr[bank][atr], value); +    _impl->poke16(unit_to_atr_to_addr[unit][atr], value);  }  /*********************************************************************** @@ -151,30 +156,30 @@ void usrp2_dboard_interface::set_atr_reg(gpio_bank_t bank, atr_reg_t atr, boost:   * \param unit the dboard interface unit type enum   * \return an over the wire representation   */ -static boost::uint8_t unit_to_otw_dev(dboard_interface::unit_type_t unit){ +static boost::uint8_t unit_to_otw_spi_dev(dboard_interface::unit_t unit){      switch(unit){ -    case dboard_interface::UNIT_TYPE_TX: return SPI_SS_TX_DB; -    case dboard_interface::UNIT_TYPE_RX: return SPI_SS_RX_DB; +    case dboard_interface::UNIT_TX: return SPI_SS_TX_DB; +    case dboard_interface::UNIT_RX: return SPI_SS_RX_DB;      } -    throw std::invalid_argument("unknown unit type type"); +    throw std::invalid_argument("unknown unit type");  }  void usrp2_dboard_interface::write_spi( -    unit_type_t unit, +    unit_t unit,      const spi_config_t &config,      boost::uint32_t data,      size_t num_bits  ){ -    _impl->transact_spi(unit_to_otw_dev(unit), config, data, num_bits, false /*no rb*/); +    _impl->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, false /*no rb*/);  }  boost::uint32_t usrp2_dboard_interface::read_write_spi( -    unit_type_t unit, +    unit_t unit,      const spi_config_t &config,      boost::uint32_t data,      size_t num_bits  ){ -    return _impl->transact_spi(unit_to_otw_dev(unit), config, data, num_bits, true /*rb*/); +    return _impl->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, true /*rb*/);  }  /*********************************************************************** @@ -228,15 +233,15 @@ dboard_interface::byte_vector_t usrp2_dboard_interface::read_i2c(int i2c_addr, s   * \param unit the dboard interface unit type enum   * \return an over the wire representation   */ -static boost::uint8_t unit_to_otw(dboard_interface::unit_type_t unit){ +static boost::uint8_t unit_to_otw(dboard_interface::unit_t unit){      switch(unit){ -    case dboard_interface::UNIT_TYPE_TX: return USRP2_DIR_TX; -    case dboard_interface::UNIT_TYPE_RX: return USRP2_DIR_RX; +    case dboard_interface::UNIT_TX: return USRP2_DIR_TX; +    case dboard_interface::UNIT_RX: return USRP2_DIR_RX;      } -    throw std::invalid_argument("unknown unit type type"); +    throw std::invalid_argument("unknown unit type");  } -void usrp2_dboard_interface::write_aux_dac(unit_type_t unit, int which, int value){ +void usrp2_dboard_interface::write_aux_dac(unit_t unit, int which, int value){      //setup the out data      usrp2_ctrl_data_t out_data;      out_data.id = htonl(USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO); @@ -249,7 +254,7 @@ void usrp2_dboard_interface::write_aux_dac(unit_type_t unit, int which, int valu      ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE);  } -int usrp2_dboard_interface::read_aux_adc(unit_type_t unit, int which){ +int usrp2_dboard_interface::read_aux_adc(unit_t unit, int which){      //setup the out data      usrp2_ctrl_data_t out_data;      out_data.id = htonl(USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO); diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index a760cbe3d..87fc88ceb 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -18,7 +18,6 @@  #include "usrp2_impl.hpp"  #include <uhd/transport/convert_types.hpp>  #include <boost/format.hpp> -#include <complex>  #include <iostream>  using namespace uhd; | 
