diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-17 18:29:16 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-17 18:29:16 -0800 |
commit | f439fe8218b05a67148332ffefd2053ba3c0c19d (patch) | |
tree | 6fcc768397dac3266649557cbb33bdd7091856bd /host | |
parent | b9497ba5b8ff66856e13100160275ddc4a884db0 (diff) | |
download | uhd-f439fe8218b05a67148332ffefd2053ba3c0c19d.tar.gz uhd-f439fe8218b05a67148332ffefd2053ba3c0c19d.tar.bz2 uhd-f439fe8218b05a67148332ffefd2053ba3c0c19d.zip |
Added control for usrp2 aux dac and adc control.
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/usrp/dboard/interface.hpp | 12 | ||||
-rw-r--r-- | host/lib/usrp/mboard/usrp2/dboard_interface.cpp | 43 | ||||
-rw-r--r-- | host/lib/usrp/mboard/usrp2/dboard_interface.hpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/mboard/usrp2/fw_common.h | 12 |
4 files changed, 67 insertions, 4 deletions
diff --git a/host/include/uhd/usrp/dboard/interface.hpp b/host/include/uhd/usrp/dboard/interface.hpp index 495304338..7c48f4d2b 100644 --- a/host/include/uhd/usrp/dboard/interface.hpp +++ b/host/include/uhd/usrp/dboard/interface.hpp @@ -35,6 +35,12 @@ public: typedef boost::shared_ptr<interface> sptr; typedef std::vector<uint8_t> byte_vector_t; + //tells the host which unit to use + enum unit_type_t{ + UNIT_TYPE_RX, + UNIT_TYPE_TX + }; + //tells the host which device to use enum spi_dev_t{ SPI_TX_DEV, @@ -65,17 +71,19 @@ 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(int which_dac, int value) = 0; + virtual void write_aux_dac(unit_type_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(int which_adc) = 0; + virtual int read_aux_adc(unit_type_t unit, int which_adc) = 0; /*! * Set daughterboard ATR register. diff --git a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp b/host/lib/usrp/mboard/usrp2/dboard_interface.cpp index fd51558f2..597654b3c 100644 --- a/host/lib/usrp/mboard/usrp2/dboard_interface.cpp +++ b/host/lib/usrp/mboard/usrp2/dboard_interface.cpp @@ -239,3 +239,46 @@ interface::byte_vector_t dboard_interface::read_i2c(int i2c_addr, size_t num_byt } return result; } + +/*********************************************************************** + * Aux DAX/ADC + **********************************************************************/ +/*! + * Static function to convert a unit type enum + * to an over-the-wire value for the usrp2 control. + * \param unit the dboard interface unit type enum + * \return an over the wire representation + */ +static uint8_t spi_dev_to_otw(interface::unit_type_t unit){ + switch(unit){ + case uhd::usrp::dboard::interface::UNIT_TYPE_TX: return USRP2_DIR_TX; + case uhd::usrp::dboard::interface::UNIT_TYPE_RX: return USRP2_DIR_RX; + } + throw std::invalid_argument("unknown unit type type"); +} + +void dboard_interface::write_aux_dac(interface::unit_type_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); + out_data.data.aux_args.dir = spi_dev_to_otw(unit); + out_data.data.aux_args.which = which; + out_data.data.aux_args.dir = htonl(value); + + //send and recv + usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE); +} + +int dboard_interface::read_aux_adc(interface::unit_type_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); + out_data.data.aux_args.dir = spi_dev_to_otw(unit); + out_data.data.aux_args.which = which; + + //send and recv + usrp2_ctrl_data_t in_data = _impl->ctrl_send_and_recv(out_data); + ASSERT_THROW(htonl(in_data.id) == USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE); + return ntohl(in_data.data.aux_args.value); +} diff --git a/host/lib/usrp/mboard/usrp2/dboard_interface.hpp b/host/lib/usrp/mboard/usrp2/dboard_interface.hpp index fb197a87a..0f78dec17 100644 --- a/host/lib/usrp/mboard/usrp2/dboard_interface.hpp +++ b/host/lib/usrp/mboard/usrp2/dboard_interface.hpp @@ -27,9 +27,9 @@ public: ~dboard_interface(void); - void write_aux_dac(int, int){} + void write_aux_dac(unit_type_t, int, int); - int read_aux_adc(int){return 0;} + int read_aux_adc(unit_type_t, int); void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t); diff --git a/host/lib/usrp/mboard/usrp2/fw_common.h b/host/lib/usrp/mboard/usrp2/fw_common.h index 91cb88c53..ede19d45f 100644 --- a/host/lib/usrp/mboard/usrp2/fw_common.h +++ b/host/lib/usrp/mboard/usrp2/fw_common.h @@ -72,6 +72,12 @@ typedef enum{ USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO, USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE, + USRP2_CTRL_ID_WRITE_THIS_TO_THE_AUX_DAC_BRO, + USRP2_CTRL_ID_DONE_WITH_THAT_AUX_DAC_DUDE, + + USRP2_CTRL_ID_READ_FROM_THIS_AUX_ADC_BRO, + USRP2_CTRL_ID_DONE_WITH_THAT_AUX_ADC_DUDE, + USRP2_CTRL_ID_PEACE_OUT } usrp2_ctrl_id_t; @@ -144,6 +150,12 @@ typedef struct{ uint8_t bytes; uint8_t data[sizeof(uint32_t)]; } i2c_args; + struct { + uint8_t dir; + uint8_t which; + uint8_t _pad[2]; + uint32_t value; + } aux_args; } data; } usrp2_ctrl_data_t; |