diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-16 19:17:29 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-16 19:17:29 -0800 |
commit | d8d783ce1b1034495dba86dab104a4f52e2fe09a (patch) | |
tree | 5001981fbbbf12f343c2dbb7ac30da487de9fd81 /lib/usrp | |
parent | 6d891fdfbb735f6ee31e0d4f9d786c1a6397965b (diff) | |
download | uhd-d8d783ce1b1034495dba86dab104a4f52e2fe09a.tar.gz uhd-d8d783ce1b1034495dba86dab104a4f52e2fe09a.tar.bz2 uhd-d8d783ce1b1034495dba86dab104a4f52e2fe09a.zip |
Added control code in the txrx.c and dboard interface for usrp2 to handle gpio and atr
Diffstat (limited to 'lib/usrp')
-rw-r--r-- | lib/usrp/mboard/usrp2/dboard_interface.cpp | 111 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2/dboard_interface.hpp | 24 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2/fw_common.h | 30 |
3 files changed, 144 insertions, 21 deletions
diff --git a/lib/usrp/mboard/usrp2/dboard_interface.cpp b/lib/usrp/mboard/usrp2/dboard_interface.cpp new file mode 100644 index 000000000..05d29daef --- /dev/null +++ b/lib/usrp/mboard/usrp2/dboard_interface.cpp @@ -0,0 +1,111 @@ +// +// Copyright 2010 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.hpp> +#include "dboard_interface.hpp" +#include "fw_common.h" + +/*********************************************************************** + * Structors + **********************************************************************/ +dboard_interface::dboard_interface(impl_base *impl){ + _impl = impl; +} + +dboard_interface::~dboard_interface(void){ + /* NOP */ +} + +/*********************************************************************** + * Clock Rates + **********************************************************************/ +double dboard_interface::get_rx_clock_rate(void){ + return _impl->get_master_clock_freq(); +} + +double dboard_interface::get_tx_clock_rate(void){ + return _impl->get_master_clock_freq(); +} + +/*********************************************************************** + * GPIO + **********************************************************************/ +/*! + * Static function to convert a gpio bank enum + * to an over-the-wire value for the usrp2 control. + * \param bank the dboard interface gpio bank enum + * \return an over the wire representation + */ +static uint8_t gpio_bank_to_otw(uhd::usrp::dboard::interface::gpio_bank_t bank){ + switch(bank){ + case uhd::usrp::dboard::interface::GPIO_TX_BANK: return USRP2_GPIO_BANK_TX; + case uhd::usrp::dboard::interface::GPIO_RX_BANK: return USRP2_GPIO_BANK_RX; + } + throw std::runtime_error("unknown gpio bank"); +} + +void dboard_interface::set_gpio_ddr(gpio_bank_t bank, uint16_t value, uint16_t mask){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO); + out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); + out_data.data.gpio_config.value = htons(value); + out_data.data.gpio_config.mask = htons(mask); + + //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_GOT_THE_GPIO_DDR_SETTINGS_DUDE); +} + +void dboard_interface::write_gpio(gpio_bank_t bank, uint16_t value, uint16_t mask){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO); + out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); + out_data.data.gpio_config.value = htons(value); + out_data.data.gpio_config.mask = htons(mask); + + //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_I_SET_THE_GPIO_PIN_OUTS_DUDE); +} + +uint16_t dboard_interface::read_gpio(gpio_bank_t bank){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO); + out_data.data.gpio_config.bank = gpio_bank_to_otw(bank); + + //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_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE); + return ntohs(in_data.data.gpio_config.value); +} + +void dboard_interface::set_atr_reg(gpio_bank_t bank, uint16_t tx_value, uint16_t rx_value, uint16_t mask){ + //setup the out data + usrp2_ctrl_data_t out_data; + out_data.id = htonl(USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO); + out_data.data.atr_config.bank = gpio_bank_to_otw(bank); + out_data.data.atr_config.tx_value = htons(tx_value); + out_data.data.atr_config.rx_value = htons(rx_value); + out_data.data.atr_config.mask = htons(mask); + + //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_GOT_THE_ATR_SETTINGS_DUDE); +} diff --git a/lib/usrp/mboard/usrp2/dboard_interface.hpp b/lib/usrp/mboard/usrp2/dboard_interface.hpp index 5afaeb701..645681f43 100644 --- a/lib/usrp/mboard/usrp2/dboard_interface.hpp +++ b/lib/usrp/mboard/usrp2/dboard_interface.hpp @@ -23,25 +23,21 @@ class dboard_interface : public uhd::usrp::dboard::interface{ public: - dboard_interface(impl_base *impl){ - _impl = impl; - } + dboard_interface(impl_base *impl); - ~dboard_interface(void){ - /* NOP */ - } + ~dboard_interface(void); void write_aux_dac(int, int){} int read_aux_adc(int){return 0;} - void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t){} + void set_atr_reg(gpio_bank_t, uint16_t, uint16_t, uint16_t); - void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t){} + void set_gpio_ddr(gpio_bank_t, uint16_t, uint16_t); - void write_gpio(gpio_bank_t, uint16_t, uint16_t){} + void write_gpio(gpio_bank_t, uint16_t, uint16_t); - uint16_t read_gpio(gpio_bank_t){return 0;} + uint16_t read_gpio(gpio_bank_t); void write_i2c (int, const std::string &){} @@ -51,13 +47,9 @@ public: std::string read_spi (spi_dev_t, spi_latch_t, size_t){return "";} - double get_rx_clock_rate(void){ - return _impl->get_master_clock_freq(); - } + double get_rx_clock_rate(void); - double get_tx_clock_rate(void){ - return _impl->get_master_clock_freq(); - } + double get_tx_clock_rate(void); private: impl_base *_impl; diff --git a/lib/usrp/mboard/usrp2/fw_common.h b/lib/usrp/mboard/usrp2/fw_common.h index de4866d8e..8cd15c7c3 100644 --- a/lib/usrp/mboard/usrp2/fw_common.h +++ b/lib/usrp/mboard/usrp2/fw_common.h @@ -51,6 +51,18 @@ typedef enum{ USRP2_CTRL_ID_HERES_A_NEW_CLOCK_CONFIG_BRO, USRP2_CTRL_ID_GOT_THE_NEW_CLOCK_CONFIG_DUDE, + USRP2_CTRL_ID_USE_THESE_GPIO_DDR_SETTINGS_BRO, + USRP2_CTRL_ID_GOT_THE_GPIO_DDR_SETTINGS_DUDE, + + USRP2_CTRL_ID_SET_YOUR_GPIO_PIN_OUTS_BRO, + USRP2_CTRL_ID_I_SET_THE_GPIO_PIN_OUTS_DUDE, + + USRP2_CTRL_ID_GIVE_ME_YOUR_GPIO_PIN_VALS_BRO, + USRP2_CTRL_ID_HERE_IS_YOUR_GPIO_PIN_VALS_DUDE, + + USRP2_CTRL_ID_USE_THESE_ATR_SETTINGS_BRO, + USRP2_CTRL_ID_GOT_THE_ATR_SETTINGS_DUDE, + USRP2_CTRL_ID_PEACE_OUT } usrp2_ctrl_id_t; @@ -71,6 +83,11 @@ typedef enum{ USRP2_REF_SOURCE_MIMO } usrp2_ref_source_t; +typedef enum{ + USRP2_GPIO_BANK_RX, + USRP2_GPIO_BANK_TX +} usrp2_gpio_bank_t; + typedef struct{ uint32_t id; uint32_t seq; @@ -87,16 +104,19 @@ typedef struct{ uint8_t ref_source; uint8_t _pad; } clock_config; - /*struct { + struct { uint8_t bank; - uint16_t ddr; + uint8_t _pad[3]; + uint16_t value; uint16_t mask; - } gpio_ddr_args; + } gpio_config; struct { uint8_t bank; - uint16_t val; + uint8_t _pad[3]; + uint16_t tx_value; + uint16_t rx_value; uint16_t mask; - } gpio_val_args;*/ + } atr_config; } data; } usrp2_ctrl_data_t; |